OSDN Git Service

* cp-tree.h (struct tinst_level): Add chain_next GTY
[pf3gnuchains/gcc-fork.git] / gcc / lto-streamer.c
1 /* Miscellaneous utilities for GIMPLE streaming.  Things that are used
2    in both input and output are here.
3
4    Copyright 2009, 2010 Free Software Foundation, Inc.
5    Contributed by Doug Kwan <dougkwan@google.com>
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "toplev.h"
28 #include "flags.h"
29 #include "tree.h"
30 #include "gimple.h"
31 #include "tree-flow.h"
32 #include "diagnostic-core.h"
33 #include "bitmap.h"
34 #include "vec.h"
35 #include "lto-streamer.h"
36
37 /* Statistics gathered during LTO, WPA and LTRANS.  */
38 struct lto_stats_d lto_stats;
39
40 /* Streamer hooks.  */
41 struct streamer_hooks streamer_hooks;
42
43 /* LTO uses bitmaps with different life-times.  So use a seperate
44    obstack for all LTO bitmaps.  */
45 static bitmap_obstack lto_obstack;
46 static bool lto_obstack_initialized;
47
48
49 /* Return a string representing LTO tag TAG.  */
50
51 const char *
52 lto_tag_name (enum LTO_tags tag)
53 {
54   if (lto_tag_is_tree_code_p (tag))
55     {
56       /* For tags representing tree nodes, return the name of the
57          associated tree code.  */
58       return tree_code_name[lto_tag_to_tree_code (tag)];
59     }
60
61   if (lto_tag_is_gimple_code_p (tag))
62     {
63       /* For tags representing gimple statements, return the name of
64          the associated gimple code.  */
65       return gimple_code_name[lto_tag_to_gimple_code (tag)];
66     }
67
68   switch (tag)
69     {
70     case LTO_null:
71       return "LTO_null";
72     case LTO_bb0:
73       return "LTO_bb0";
74     case LTO_bb1:
75       return "LTO_bb1";
76     case LTO_eh_region:
77       return "LTO_eh_region";
78     case LTO_function:
79       return "LTO_function";
80     case LTO_eh_table:
81       return "LTO_eh_table";
82     case LTO_ert_cleanup:
83       return "LTO_ert_cleanup";
84     case LTO_ert_try:
85       return "LTO_ert_try";
86     case LTO_ert_allowed_exceptions:
87       return "LTO_ert_allowed_exceptions";
88     case LTO_ert_must_not_throw:
89       return "LTO_ert_must_not_throw";
90     case LTO_tree_pickle_reference:
91       return "LTO_tree_pickle_reference";
92     case LTO_field_decl_ref:
93       return "LTO_field_decl_ref";
94     case LTO_function_decl_ref:
95       return "LTO_function_decl_ref";
96     case LTO_label_decl_ref:
97       return "LTO_label_decl_ref";
98     case LTO_namespace_decl_ref:
99       return "LTO_namespace_decl_ref";
100     case LTO_result_decl_ref:
101       return "LTO_result_decl_ref";
102     case LTO_ssa_name_ref:
103       return "LTO_ssa_name_ref";
104     case LTO_type_decl_ref:
105       return "LTO_type_decl_ref";
106     case LTO_type_ref:
107       return "LTO_type_ref";
108     case LTO_global_decl_ref:
109       return "LTO_global_decl_ref";
110     default:
111       return "LTO_UNKNOWN";
112     }
113 }
114
115
116 /* Allocate a bitmap from heap.  Initializes the LTO obstack if necessary.  */
117
118 bitmap
119 lto_bitmap_alloc (void)
120 {
121   if (!lto_obstack_initialized)
122     {
123       bitmap_obstack_initialize (&lto_obstack);
124       lto_obstack_initialized = true;
125     }
126   return BITMAP_ALLOC (&lto_obstack);
127 }
128
129 /* Free bitmap B.  */
130
131 void
132 lto_bitmap_free (bitmap b)
133 {
134   BITMAP_FREE (b);
135 }
136
137
138 /* Get a section name for a particular type or name.  The NAME field
139    is only used if SECTION_TYPE is LTO_section_function_body. For all
140    others it is ignored.  The callee of this function is responsible
141    to free the returned name.  */
142
143 char *
144 lto_get_section_name (int section_type, const char *name, struct lto_file_decl_data *f)
145 {
146   const char *add;
147   char post[32];
148   const char *sep;
149
150   if (section_type == LTO_section_function_body)
151     {
152       gcc_assert (name != NULL);
153       if (name[0] == '*')
154         name++;
155       add = name;
156       sep = "";
157     }
158   else if (section_type < LTO_N_SECTION_TYPES)
159     {
160       add = lto_section_name[section_type];
161       sep = ".";
162     }
163   else
164     internal_error ("bytecode stream: unexpected LTO section %s", name);
165
166   /* Make the section name unique so that ld -r combining sections
167      doesn't confuse the reader with merged sections.
168
169      For options don't add a ID, the option reader cannot deal with them
170      and merging should be ok here.
171
172      XXX: use crc64 to minimize collisions? */
173   if (section_type == LTO_section_opts)
174     strcpy (post, "");
175   else
176     sprintf (post, ".%x", f ? f->id : crc32_string(0, get_random_seed (false)));
177   return concat (LTO_SECTION_NAME_PREFIX, sep, add, post, NULL);
178 }
179
180
181 /* Show various memory usage statistics related to LTO.  */
182
183 void
184 print_lto_report (void)
185 {
186   const char *s = (flag_lto) ? "LTO" : (flag_wpa) ? "WPA" : "LTRANS";
187   unsigned i;
188
189   fprintf (stderr, "%s statistics\n", s);
190   fprintf (stderr, "[%s] # of input files: "
191            HOST_WIDE_INT_PRINT_UNSIGNED "\n", s, lto_stats.num_input_files);
192
193   fprintf (stderr, "[%s] # of input cgraph nodes: "
194            HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
195            lto_stats.num_input_cgraph_nodes);
196
197   fprintf (stderr, "[%s] # of function bodies: "
198            HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
199            lto_stats.num_function_bodies);
200
201   fprintf (stderr, "[%s] ", s);
202   print_gimple_types_stats ();
203
204   for (i = 0; i < NUM_TREE_CODES; i++)
205     if (lto_stats.num_trees[i])
206       fprintf (stderr, "[%s] # of '%s' objects read: "
207                HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
208                tree_code_name[i], lto_stats.num_trees[i]);
209
210   if (flag_lto)
211     {
212       fprintf (stderr, "[%s] Compression: "
213                HOST_WIDE_INT_PRINT_UNSIGNED " output bytes, "
214                HOST_WIDE_INT_PRINT_UNSIGNED " compressed bytes", s,
215                lto_stats.num_output_il_bytes,
216                lto_stats.num_compressed_il_bytes);
217       if (lto_stats.num_output_il_bytes > 0)
218         {
219           const float dividend = (float) lto_stats.num_compressed_il_bytes;
220           const float divisor = (float) lto_stats.num_output_il_bytes;
221           fprintf (stderr, " (ratio: %f)", dividend / divisor);
222         }
223       fprintf (stderr, "\n");
224     }
225
226   if (flag_wpa)
227     {
228       fprintf (stderr, "[%s] # of output files: "
229                HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
230                lto_stats.num_output_files);
231
232       fprintf (stderr, "[%s] # of output cgraph nodes: "
233                HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
234                lto_stats.num_output_cgraph_nodes);
235
236       fprintf (stderr, "[%s] # callgraph partitions: "
237                HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
238                lto_stats.num_cgraph_partitions);
239
240       fprintf (stderr, "[%s] Compression: "
241                HOST_WIDE_INT_PRINT_UNSIGNED " input bytes, "
242                HOST_WIDE_INT_PRINT_UNSIGNED " uncompressed bytes", s,
243                lto_stats.num_input_il_bytes,
244                lto_stats.num_uncompressed_il_bytes);
245       if (lto_stats.num_input_il_bytes > 0)
246         {
247           const float dividend = (float) lto_stats.num_uncompressed_il_bytes;
248           const float divisor = (float) lto_stats.num_input_il_bytes;
249           fprintf (stderr, " (ratio: %f)", dividend / divisor);
250         }
251       fprintf (stderr, "\n");
252     }
253
254   for (i = 0; i < LTO_N_SECTION_TYPES; i++)
255     fprintf (stderr, "[%s] Size of mmap'd section %s: "
256              HOST_WIDE_INT_PRINT_UNSIGNED " bytes\n", s,
257              lto_section_name[i], lto_stats.section_size[i]);
258 }
259
260
261 /* Check that all the TS_* structures handled by the lto_output_* and
262    lto_input_* routines are exactly ALL the structures defined in
263    treestruct.def.  */
264
265 static void
266 check_handled_ts_structures (void)
267 {
268   bool handled_p[LAST_TS_ENUM];
269   unsigned i;
270
271   memset (&handled_p, 0, sizeof (handled_p));
272
273   /* These are the TS_* structures that are either handled or
274      explicitly ignored by the streamer routines.  */
275   handled_p[TS_BASE] = true;
276   handled_p[TS_TYPED] = true;
277   handled_p[TS_COMMON] = true;
278   handled_p[TS_INT_CST] = true;
279   handled_p[TS_REAL_CST] = true;
280   handled_p[TS_FIXED_CST] = true;
281   handled_p[TS_VECTOR] = true;
282   handled_p[TS_STRING] = true;
283   handled_p[TS_COMPLEX] = true;
284   handled_p[TS_IDENTIFIER] = true;
285   handled_p[TS_DECL_MINIMAL] = true;
286   handled_p[TS_DECL_COMMON] = true;
287   handled_p[TS_DECL_WRTL] = true;
288   handled_p[TS_DECL_NON_COMMON] = true;
289   handled_p[TS_DECL_WITH_VIS] = true;
290   handled_p[TS_FIELD_DECL] = true;
291   handled_p[TS_VAR_DECL] = true;
292   handled_p[TS_PARM_DECL] = true;
293   handled_p[TS_LABEL_DECL] = true;
294   handled_p[TS_RESULT_DECL] = true;
295   handled_p[TS_CONST_DECL] = true;
296   handled_p[TS_TYPE_DECL] = true;
297   handled_p[TS_FUNCTION_DECL] = true;
298   handled_p[TS_TYPE_COMMON] = true;
299   handled_p[TS_TYPE_WITH_LANG_SPECIFIC] = true;
300   handled_p[TS_TYPE_NON_COMMON] = true;
301   handled_p[TS_LIST] = true;
302   handled_p[TS_VEC] = true;
303   handled_p[TS_EXP] = true;
304   handled_p[TS_SSA_NAME] = true;
305   handled_p[TS_BLOCK] = true;
306   handled_p[TS_BINFO] = true;
307   handled_p[TS_STATEMENT_LIST] = true;
308   handled_p[TS_CONSTRUCTOR] = true;
309   handled_p[TS_OMP_CLAUSE] = true;
310   handled_p[TS_OPTIMIZATION] = true;
311   handled_p[TS_TARGET_OPTION] = true;
312   handled_p[TS_TRANSLATION_UNIT_DECL] = true;
313
314   /* Anything not marked above will trigger the following assertion.
315      If this assertion triggers, it means that there is a new TS_*
316      structure that should be handled by the streamer.  */
317   for (i = 0; i < LAST_TS_ENUM; i++)
318     gcc_assert (handled_p[i]);
319 }
320
321
322 /* Helper for lto_streamer_cache_insert_1.  Add T to CACHE->NODES at
323    slot IX.  */
324
325 static void
326 lto_streamer_cache_add_to_node_array (struct lto_streamer_cache_d *cache,
327                                       unsigned ix, tree t)
328 {
329   /* Make sure we're either replacing an old element or
330      appending consecutively.  */
331   gcc_assert (ix <= VEC_length (tree, cache->nodes));
332
333   if (ix == VEC_length (tree, cache->nodes))
334     VEC_safe_push (tree, heap, cache->nodes, t);
335   else
336     VEC_replace (tree, cache->nodes, ix, t);
337 }
338
339
340 /* Helper for lto_streamer_cache_insert and lto_streamer_cache_insert_at.
341    CACHE, T, and IX_P are as in lto_streamer_cache_insert.
342
343    If INSERT_AT_NEXT_SLOT_P is true, T is inserted at the next available
344    slot in the cache.  Otherwise, T is inserted at the position indicated
345    in *IX_P.
346
347    If T already existed in CACHE, return true.  Otherwise,
348    return false.  */
349
350 static bool
351 lto_streamer_cache_insert_1 (struct lto_streamer_cache_d *cache,
352                              tree t, unsigned *ix_p,
353                              bool insert_at_next_slot_p)
354 {
355   void **slot;
356   unsigned ix;
357   bool existed_p;
358
359   gcc_assert (t);
360
361   slot = pointer_map_insert (cache->node_map, t);
362   if (!*slot)
363     {
364       /* Determine the next slot to use in the cache.  */
365       if (insert_at_next_slot_p)
366         ix = VEC_length (tree, cache->nodes);
367       else
368         ix = *ix_p;
369        *slot = (void *)(size_t) (ix + 1);
370
371       lto_streamer_cache_add_to_node_array (cache, ix, t);
372
373       /* Indicate that the item was not present in the cache.  */
374       existed_p = false;
375     }
376   else
377     {
378       ix = (size_t) *slot - 1;
379
380       if (!insert_at_next_slot_p && ix != *ix_p)
381         {
382           /* If the caller wants to insert T at a specific slot
383              location, and ENTRY->TO does not match *IX_P, add T to
384              the requested location slot.  */
385           ix = *ix_p;
386           lto_streamer_cache_add_to_node_array (cache, ix, t);
387         }
388
389       /* Indicate that T was already in the cache.  */
390       existed_p = true;
391     }
392
393   if (ix_p)
394     *ix_p = ix;
395
396   return existed_p;
397 }
398
399
400 /* Insert tree node T in CACHE.  If T already existed in the cache
401    return true.  Otherwise, return false.
402
403    If IX_P is non-null, update it with the index into the cache where
404    T has been stored.  */
405
406 bool
407 lto_streamer_cache_insert (struct lto_streamer_cache_d *cache, tree t,
408                            unsigned *ix_p)
409 {
410   return lto_streamer_cache_insert_1 (cache, t, ix_p, true);
411 }
412
413
414 /* Insert tree node T in CACHE at slot IX.  If T already
415    existed in the cache return true.  Otherwise, return false.  */
416
417 bool
418 lto_streamer_cache_insert_at (struct lto_streamer_cache_d *cache,
419                               tree t, unsigned ix)
420 {
421   return lto_streamer_cache_insert_1 (cache, t, &ix, false);
422 }
423
424
425 /* Appends tree node T to CACHE, even if T already existed in it.  */
426
427 void
428 lto_streamer_cache_append (struct lto_streamer_cache_d *cache, tree t)
429 {
430   unsigned ix = VEC_length (tree, cache->nodes);
431   lto_streamer_cache_insert_1 (cache, t, &ix, false);
432 }
433
434 /* Return true if tree node T exists in CACHE, otherwise false.  If IX_P is
435    not NULL, write to *IX_P the index into the cache where T is stored
436    ((unsigned)-1 if T is not found).  */
437
438 bool
439 lto_streamer_cache_lookup (struct lto_streamer_cache_d *cache, tree t,
440                            unsigned *ix_p)
441 {
442   void **slot;
443   bool retval;
444   unsigned ix;
445
446   gcc_assert (t);
447
448   slot = pointer_map_contains  (cache->node_map, t);
449   if (slot == NULL)
450     {
451       retval = false;
452       ix = -1;
453     }
454   else
455     {
456       retval = true;
457       ix = (size_t) *slot - 1;
458     }
459
460   if (ix_p)
461     *ix_p = ix;
462
463   return retval;
464 }
465
466
467 /* Return the tree node at slot IX in CACHE.  */
468
469 tree
470 lto_streamer_cache_get (struct lto_streamer_cache_d *cache, unsigned ix)
471 {
472   gcc_assert (cache);
473
474   /* Make sure we're not requesting something we don't have.  */
475   gcc_assert (ix < VEC_length (tree, cache->nodes));
476
477   return VEC_index (tree, cache->nodes, ix);
478 }
479
480
481 /* Record NODE in CACHE.  */
482
483 static void
484 lto_record_common_node (struct lto_streamer_cache_d *cache, tree node)
485 {
486   /* We have to make sure to fill exactly the same number of
487      elements for all frontends.  That can include NULL trees.
488      As our hash table can't deal with zero entries we'll simply stream
489      a random other tree.  A NULL tree never will be looked up so it
490      doesn't matter which tree we replace it with, just to be sure
491      use error_mark_node.  */
492   if (!node)
493     node = error_mark_node;
494
495   lto_streamer_cache_append (cache, node);
496
497   if (POINTER_TYPE_P (node)
498       || TREE_CODE (node) == COMPLEX_TYPE
499       || TREE_CODE (node) == ARRAY_TYPE)
500     lto_record_common_node (cache, TREE_TYPE (node));
501   else if (TREE_CODE (node) == RECORD_TYPE)
502     {
503       /* The FIELD_DECLs of structures should be shared, so that every
504          COMPONENT_REF uses the same tree node when referencing a field.
505          Pointer equality between FIELD_DECLs is used by the alias
506          machinery to compute overlapping memory references (See
507          nonoverlapping_component_refs_p).  */
508       tree f;
509       for (f = TYPE_FIELDS (node); f; f = TREE_CHAIN (f))
510         lto_record_common_node (cache, f);
511     }
512 }
513
514 /* Preload common nodes into CACHE and make sure they are merged
515    properly according to the gimple type table.  */
516
517 static void
518 lto_preload_common_nodes (struct lto_streamer_cache_d *cache)
519 {
520   unsigned i;
521
522   /* The MAIN_IDENTIFIER_NODE is normally set up by the front-end, but the
523      LTO back-end must agree. Currently, the only languages that set this
524      use the name "main".  */
525   if (main_identifier_node)
526     {
527       const char *main_name = IDENTIFIER_POINTER (main_identifier_node);
528       gcc_assert (strcmp (main_name, "main") == 0);
529     }
530   else
531     main_identifier_node = get_identifier ("main");
532
533   gcc_assert (ptrdiff_type_node == integer_type_node);
534
535   /* FIXME lto.  In the C++ front-end, fileptr_type_node is defined as a
536      variant copy of of ptr_type_node, rather than ptr_node itself.  The
537      distinction should only be relevant to the front-end, so we always
538      use the C definition here in lto1.
539
540      These should be assured in pass_ipa_free_lang_data.  */
541   gcc_assert (fileptr_type_node == ptr_type_node);
542   gcc_assert (TYPE_MAIN_VARIANT (fileptr_type_node) == ptr_type_node);
543
544   for (i = 0; i < itk_none; i++)
545     /* Skip itk_char.  char_type_node is dependent on -f[un]signed-char.  */
546     if (i != itk_char)
547       lto_record_common_node (cache, integer_types[i]);
548
549   for (i = 0; i < TYPE_KIND_LAST; i++)
550     lto_record_common_node (cache, sizetype_tab[i]);
551
552   for (i = 0; i < TI_MAX; i++)
553     /* Skip boolean type and constants, they are frontend dependent.  */
554     if (i != TI_BOOLEAN_TYPE
555         && i != TI_BOOLEAN_FALSE
556         && i != TI_BOOLEAN_TRUE)
557       lto_record_common_node (cache, global_trees[i]);
558 }
559
560 /* Create a cache of pickled nodes.  */
561
562 struct lto_streamer_cache_d *
563 lto_streamer_cache_create (void)
564 {
565   struct lto_streamer_cache_d *cache;
566
567   cache = XCNEW (struct lto_streamer_cache_d);
568
569   cache->node_map = pointer_map_create ();
570
571   /* Load all the well-known tree nodes that are always created by
572      the compiler on startup.  This prevents writing them out
573      unnecessarily.  */
574   streamer_hooks.preload_common_nodes (cache);
575
576   return cache;
577 }
578
579
580 /* Delete the streamer cache C.  */
581
582 void
583 lto_streamer_cache_delete (struct lto_streamer_cache_d *c)
584 {
585   if (c == NULL)
586     return;
587
588   pointer_map_destroy (c->node_map);
589   VEC_free (tree, heap, c->nodes);
590   free (c);
591 }
592
593
594 #ifdef LTO_STREAMER_DEBUG
595 static htab_t tree_htab;
596
597 struct tree_hash_entry
598 {
599   tree key;
600   intptr_t value;
601 };
602
603 static hashval_t
604 hash_tree (const void *p)
605 {
606   const struct tree_hash_entry *e = (const struct tree_hash_entry *) p;
607   return htab_hash_pointer (e->key);
608 }
609
610 static int
611 eq_tree (const void *p1, const void *p2)
612 {
613   const struct tree_hash_entry *e1 = (const struct tree_hash_entry *) p1;
614   const struct tree_hash_entry *e2 = (const struct tree_hash_entry *) p2;
615   return (e1->key == e2->key);
616 }
617 #endif
618
619 /* Initialization common to the LTO reader and writer.  */
620
621 void
622 lto_streamer_init (void)
623 {
624   /* Check that all the TS_* handled by the reader and writer routines
625      match exactly the structures defined in treestruct.def.  When a
626      new TS_* astructure is added, the streamer should be updated to
627      handle it.  */
628   check_handled_ts_structures ();
629
630 #ifdef LTO_STREAMER_DEBUG
631   tree_htab = htab_create (31, hash_tree, eq_tree, NULL);
632 #endif
633 }
634
635
636 /* Gate function for all LTO streaming passes.  */
637
638 bool
639 gate_lto_out (void)
640 {
641   return ((flag_generate_lto || in_lto_p)
642           /* Don't bother doing anything if the program has errors.  */
643           && !seen_error ());
644 }
645
646
647 #ifdef LTO_STREAMER_DEBUG
648 /* Add a mapping between T and ORIG_T, which is the numeric value of
649    the original address of T as it was seen by the LTO writer.  This
650    mapping is useful when debugging streaming problems.  A debugging
651    session can be started on both reader and writer using ORIG_T
652    as a breakpoint value in both sessions.
653
654    Note that this mapping is transient and only valid while T is
655    being reconstructed.  Once T is fully built, the mapping is
656    removed.  */
657
658 void
659 lto_orig_address_map (tree t, intptr_t orig_t)
660 {
661   struct tree_hash_entry ent;
662   struct tree_hash_entry **slot;
663
664   ent.key = t;
665   ent.value = orig_t;
666   slot
667     = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, INSERT);
668   gcc_assert (!*slot);
669   *slot = XNEW (struct tree_hash_entry);
670   **slot = ent;
671 }
672
673
674 /* Get the original address of T as it was seen by the writer.  This
675    is only valid while T is being reconstructed.  */
676
677 intptr_t
678 lto_orig_address_get (tree t)
679 {
680   struct tree_hash_entry ent;
681   struct tree_hash_entry **slot;
682
683   ent.key = t;
684   slot
685     = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, NO_INSERT);
686   return (slot ? (*slot)->value : 0);
687 }
688
689
690 /* Clear the mapping of T to its original address.  */
691
692 void
693 lto_orig_address_remove (tree t)
694 {
695   struct tree_hash_entry ent;
696   struct tree_hash_entry **slot;
697
698   ent.key = t;
699   slot
700     = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, NO_INSERT);
701   gcc_assert (slot);
702   free (*slot);
703   htab_clear_slot (tree_htab, (PTR *)slot);
704 }
705 #endif
706
707
708 /* Check that the version MAJOR.MINOR is the correct version number.  */
709
710 void
711 lto_check_version (int major, int minor)
712 {
713   if (major != LTO_major_version || minor != LTO_minor_version)
714     fatal_error ("bytecode stream generated with LTO version %d.%d instead "
715                  "of the expected %d.%d",
716                  major, minor,
717                  LTO_major_version, LTO_minor_version);
718 }
719
720
721 /* Return true if EXPR is a tree node that can be written to disk.  */
722 static inline bool
723 lto_is_streamable (tree expr)
724 {
725   enum tree_code code = TREE_CODE (expr);
726
727   /* Notice that we reject SSA_NAMEs as well.  We only emit the SSA
728      name version in lto_output_tree_ref (see output_ssa_names).  */
729   return !is_lang_specific (expr)
730          && code != SSA_NAME
731          && code != CALL_EXPR
732          && code != LANG_TYPE
733          && code != MODIFY_EXPR
734          && code != INIT_EXPR
735          && code != TARGET_EXPR
736          && code != BIND_EXPR
737          && code != WITH_CLEANUP_EXPR
738          && code != STATEMENT_LIST
739          && code != OMP_CLAUSE
740          && code != OPTIMIZATION_NODE
741          && (code == CASE_LABEL_EXPR
742              || code == DECL_EXPR
743              || TREE_CODE_CLASS (code) != tcc_statement);
744 }
745
746
747 /* Initialize all the streamer hooks used for streaming GIMPLE.  */
748
749 void
750 lto_streamer_hooks_init (void)
751 {
752   streamer_hooks_init ();
753   streamer_hooks.name = "gimple";
754   streamer_hooks.preload_common_nodes = lto_preload_common_nodes;
755   streamer_hooks.is_streamable = lto_is_streamable;
756   streamer_hooks.write_tree = lto_streamer_write_tree;
757   streamer_hooks.read_tree = lto_streamer_read_tree;
758 }
759
760
761 /* Initialize the current set of streamer hooks.  */
762
763 void
764 streamer_hooks_init (void)
765 {
766   memset (&streamer_hooks, 0, sizeof (streamer_hooks));
767 }