* jvspec.c (jvgenmain_spec): Don't handle -fnew-verifier.
[gcc.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 /* LTO uses bitmaps with different life-times. So use a seperate
41 obstack for all LTO bitmaps. */
42 static bitmap_obstack lto_obstack;
43 static bool lto_obstack_initialized;
44
45
46 /* Return a string representing LTO tag TAG. */
47
48 const char *
49 lto_tag_name (enum LTO_tags tag)
50 {
51 if (lto_tag_is_tree_code_p (tag))
52 {
53 /* For tags representing tree nodes, return the name of the
54 associated tree code. */
55 return tree_code_name[lto_tag_to_tree_code (tag)];
56 }
57
58 if (lto_tag_is_gimple_code_p (tag))
59 {
60 /* For tags representing gimple statements, return the name of
61 the associated gimple code. */
62 return gimple_code_name[lto_tag_to_gimple_code (tag)];
63 }
64
65 switch (tag)
66 {
67 case LTO_null:
68 return "LTO_null";
69 case LTO_bb0:
70 return "LTO_bb0";
71 case LTO_bb1:
72 return "LTO_bb1";
73 case LTO_eh_region:
74 return "LTO_eh_region";
75 case LTO_function:
76 return "LTO_function";
77 case LTO_eh_table:
78 return "LTO_eh_table";
79 case LTO_ert_cleanup:
80 return "LTO_ert_cleanup";
81 case LTO_ert_try:
82 return "LTO_ert_try";
83 case LTO_ert_allowed_exceptions:
84 return "LTO_ert_allowed_exceptions";
85 case LTO_ert_must_not_throw:
86 return "LTO_ert_must_not_throw";
87 case LTO_tree_pickle_reference:
88 return "LTO_tree_pickle_reference";
89 case LTO_field_decl_ref:
90 return "LTO_field_decl_ref";
91 case LTO_function_decl_ref:
92 return "LTO_function_decl_ref";
93 case LTO_label_decl_ref:
94 return "LTO_label_decl_ref";
95 case LTO_namespace_decl_ref:
96 return "LTO_namespace_decl_ref";
97 case LTO_result_decl_ref:
98 return "LTO_result_decl_ref";
99 case LTO_ssa_name_ref:
100 return "LTO_ssa_name_ref";
101 case LTO_type_decl_ref:
102 return "LTO_type_decl_ref";
103 case LTO_type_ref:
104 return "LTO_type_ref";
105 case LTO_global_decl_ref:
106 return "LTO_global_decl_ref";
107 default:
108 return "LTO_UNKNOWN";
109 }
110 }
111
112
113 /* Allocate a bitmap from heap. Initializes the LTO obstack if necessary. */
114
115 bitmap
116 lto_bitmap_alloc (void)
117 {
118 if (!lto_obstack_initialized)
119 {
120 bitmap_obstack_initialize (&lto_obstack);
121 lto_obstack_initialized = true;
122 }
123 return BITMAP_ALLOC (&lto_obstack);
124 }
125
126 /* Free bitmap B. */
127
128 void
129 lto_bitmap_free (bitmap b)
130 {
131 BITMAP_FREE (b);
132 }
133
134
135 /* Get a section name for a particular type or name. The NAME field
136 is only used if SECTION_TYPE is LTO_section_function_body. For all
137 others it is ignored. The callee of this function is responsible
138 to free the returned name. */
139
140 char *
141 lto_get_section_name (int section_type, const char *name, struct lto_file_decl_data *f)
142 {
143 const char *add;
144 char post[32];
145 const char *sep;
146
147 if (section_type == LTO_section_function_body)
148 {
149 gcc_assert (name != NULL);
150 if (name[0] == '*')
151 name++;
152 add = name;
153 sep = "";
154 }
155 else if (section_type < LTO_N_SECTION_TYPES)
156 {
157 add = lto_section_name[section_type];
158 sep = ".";
159 }
160 else
161 internal_error ("bytecode stream: unexpected LTO section %s", name);
162
163 /* Make the section name unique so that ld -r combining sections
164 doesn't confuse the reader with merged sections.
165
166 For options don't add a ID, the option reader cannot deal with them
167 and merging should be ok here.
168
169 XXX: use crc64 to minimize collisions? */
170 if (section_type == LTO_section_opts)
171 strcpy (post, "");
172 else
173 sprintf (post, ".%x", f ? f->id : crc32_string(0, get_random_seed (false)));
174 return concat (LTO_SECTION_NAME_PREFIX, sep, add, post, NULL);
175 }
176
177
178 /* Show various memory usage statistics related to LTO. */
179
180 void
181 print_lto_report (void)
182 {
183 const char *s = (flag_lto) ? "LTO" : (flag_wpa) ? "WPA" : "LTRANS";
184 unsigned i;
185
186 fprintf (stderr, "%s statistics\n", s);
187 fprintf (stderr, "[%s] # of input files: "
188 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s, lto_stats.num_input_files);
189
190 fprintf (stderr, "[%s] # of input cgraph nodes: "
191 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
192 lto_stats.num_input_cgraph_nodes);
193
194 fprintf (stderr, "[%s] # of function bodies: "
195 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
196 lto_stats.num_function_bodies);
197
198 fprintf (stderr, "[%s] ", s);
199 print_gimple_types_stats ();
200
201 for (i = 0; i < NUM_TREE_CODES; i++)
202 if (lto_stats.num_trees[i])
203 fprintf (stderr, "[%s] # of '%s' objects read: "
204 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
205 tree_code_name[i], lto_stats.num_trees[i]);
206
207 if (flag_lto)
208 {
209 fprintf (stderr, "[%s] Compression: "
210 HOST_WIDE_INT_PRINT_UNSIGNED " output bytes, "
211 HOST_WIDE_INT_PRINT_UNSIGNED " compressed bytes", s,
212 lto_stats.num_output_il_bytes,
213 lto_stats.num_compressed_il_bytes);
214 if (lto_stats.num_output_il_bytes > 0)
215 {
216 const float dividend = (float) lto_stats.num_compressed_il_bytes;
217 const float divisor = (float) lto_stats.num_output_il_bytes;
218 fprintf (stderr, " (ratio: %f)", dividend / divisor);
219 }
220 fprintf (stderr, "\n");
221 }
222
223 if (flag_wpa)
224 {
225 fprintf (stderr, "[%s] # of output files: "
226 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
227 lto_stats.num_output_files);
228
229 fprintf (stderr, "[%s] # of output cgraph nodes: "
230 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
231 lto_stats.num_output_cgraph_nodes);
232
233 fprintf (stderr, "[%s] # callgraph partitions: "
234 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
235 lto_stats.num_cgraph_partitions);
236
237 fprintf (stderr, "[%s] Compression: "
238 HOST_WIDE_INT_PRINT_UNSIGNED " input bytes, "
239 HOST_WIDE_INT_PRINT_UNSIGNED " uncompressed bytes", s,
240 lto_stats.num_input_il_bytes,
241 lto_stats.num_uncompressed_il_bytes);
242 if (lto_stats.num_input_il_bytes > 0)
243 {
244 const float dividend = (float) lto_stats.num_uncompressed_il_bytes;
245 const float divisor = (float) lto_stats.num_input_il_bytes;
246 fprintf (stderr, " (ratio: %f)", dividend / divisor);
247 }
248 fprintf (stderr, "\n");
249 }
250
251 for (i = 0; i < LTO_N_SECTION_TYPES; i++)
252 fprintf (stderr, "[%s] Size of mmap'd section %s: "
253 HOST_WIDE_INT_PRINT_UNSIGNED " bytes\n", s,
254 lto_section_name[i], lto_stats.section_size[i]);
255 }
256
257
258 /* Check that all the TS_* structures handled by the lto_output_* and
259 lto_input_* routines are exactly ALL the structures defined in
260 treestruct.def. */
261
262 static void
263 check_handled_ts_structures (void)
264 {
265 bool handled_p[LAST_TS_ENUM];
266 unsigned i;
267
268 memset (&handled_p, 0, sizeof (handled_p));
269
270 /* These are the TS_* structures that are either handled or
271 explicitly ignored by the streamer routines. */
272 handled_p[TS_BASE] = true;
273 handled_p[TS_COMMON] = true;
274 handled_p[TS_INT_CST] = true;
275 handled_p[TS_REAL_CST] = true;
276 handled_p[TS_FIXED_CST] = true;
277 handled_p[TS_VECTOR] = true;
278 handled_p[TS_STRING] = true;
279 handled_p[TS_COMPLEX] = true;
280 handled_p[TS_IDENTIFIER] = true;
281 handled_p[TS_DECL_MINIMAL] = true;
282 handled_p[TS_DECL_COMMON] = true;
283 handled_p[TS_DECL_WRTL] = true;
284 handled_p[TS_DECL_NON_COMMON] = true;
285 handled_p[TS_DECL_WITH_VIS] = true;
286 handled_p[TS_FIELD_DECL] = true;
287 handled_p[TS_VAR_DECL] = true;
288 handled_p[TS_PARM_DECL] = true;
289 handled_p[TS_LABEL_DECL] = true;
290 handled_p[TS_RESULT_DECL] = true;
291 handled_p[TS_CONST_DECL] = true;
292 handled_p[TS_TYPE_DECL] = true;
293 handled_p[TS_FUNCTION_DECL] = true;
294 handled_p[TS_TYPE] = true;
295 handled_p[TS_LIST] = true;
296 handled_p[TS_VEC] = true;
297 handled_p[TS_EXP] = true;
298 handled_p[TS_SSA_NAME] = true;
299 handled_p[TS_BLOCK] = true;
300 handled_p[TS_BINFO] = true;
301 handled_p[TS_STATEMENT_LIST] = true;
302 handled_p[TS_CONSTRUCTOR] = true;
303 handled_p[TS_OMP_CLAUSE] = true;
304 handled_p[TS_OPTIMIZATION] = true;
305 handled_p[TS_TARGET_OPTION] = true;
306
307 /* Anything not marked above will trigger the following assertion.
308 If this assertion triggers, it means that there is a new TS_*
309 structure that should be handled by the streamer. */
310 for (i = 0; i < LAST_TS_ENUM; i++)
311 gcc_assert (handled_p[i]);
312 }
313
314
315 /* Helper for lto_streamer_cache_insert_1. Add T to CACHE->NODES at
316 slot IX. Add OFFSET to CACHE->OFFSETS at slot IX. */
317
318 static void
319 lto_streamer_cache_add_to_node_array (struct lto_streamer_cache_d *cache,
320 int ix, tree t, unsigned offset)
321 {
322 gcc_assert (ix >= 0);
323
324 /* Grow the array of nodes and offsets to accomodate T at IX. */
325 if (ix >= (int) VEC_length (tree, cache->nodes))
326 {
327 size_t sz = ix + (20 + ix) / 4;
328 VEC_safe_grow_cleared (tree, heap, cache->nodes, sz);
329 VEC_safe_grow_cleared (unsigned, heap, cache->offsets, sz);
330 }
331
332 VEC_replace (tree, cache->nodes, ix, t);
333 VEC_replace (unsigned, cache->offsets, ix, offset);
334 }
335
336
337 /* Helper for lto_streamer_cache_insert and lto_streamer_cache_insert_at.
338 CACHE, T, IX_P and OFFSET_P are as in lto_streamer_cache_insert.
339
340 If INSERT_AT_NEXT_SLOT_P is true, T is inserted at the next available
341 slot in the cache. Otherwise, T is inserted at the position indicated
342 in *IX_P.
343
344 If T already existed in CACHE, return true. Otherwise,
345 return false. */
346
347 static bool
348 lto_streamer_cache_insert_1 (struct lto_streamer_cache_d *cache,
349 tree t, int *ix_p, unsigned *offset_p,
350 bool insert_at_next_slot_p)
351 {
352 void **slot;
353 struct tree_int_map d_entry, *entry;
354 int ix;
355 unsigned offset;
356 bool existed_p;
357
358 gcc_assert (t);
359
360 d_entry.base.from = t;
361 slot = htab_find_slot (cache->node_map, &d_entry, INSERT);
362 if (*slot == NULL)
363 {
364 /* Determine the next slot to use in the cache. */
365 if (insert_at_next_slot_p)
366 ix = cache->next_slot++;
367 else
368 ix = *ix_p;
369
370 entry = (struct tree_int_map *)pool_alloc (cache->node_map_entries);
371 entry->base.from = t;
372 entry->to = (unsigned) ix;
373 *slot = entry;
374
375 /* If no offset was given, store the invalid offset -1. */
376 offset = (offset_p) ? *offset_p : (unsigned) -1;
377
378 lto_streamer_cache_add_to_node_array (cache, ix, t, offset);
379
380 /* Indicate that the item was not present in the cache. */
381 existed_p = false;
382 }
383 else
384 {
385 entry = (struct tree_int_map *) *slot;
386 ix = (int) entry->to;
387 offset = VEC_index (unsigned, cache->offsets, ix);
388
389 if (!insert_at_next_slot_p && ix != *ix_p)
390 {
391 /* If the caller wants to insert T at a specific slot
392 location, and ENTRY->TO does not match *IX_P, add T to
393 the requested location slot. This situation arises when
394 streaming builtin functions.
395
396 For instance, on the writer side we could have two
397 FUNCTION_DECLS T1 and T2 that are represented by the same
398 builtin function. The reader will only instantiate the
399 canonical builtin, but since T1 and T2 had been
400 originally stored in different cache slots (S1 and S2),
401 the reader must be able to find the canonical builtin
402 function at slots S1 and S2. */
403 gcc_assert (lto_stream_as_builtin_p (t));
404 ix = *ix_p;
405
406 /* Since we are storing a builtin, the offset into the
407 stream is not necessary as we will not need to read
408 forward in the stream. */
409 lto_streamer_cache_add_to_node_array (cache, ix, t, -1);
410 }
411
412 /* Indicate that T was already in the cache. */
413 existed_p = true;
414 }
415
416 if (ix_p)
417 *ix_p = ix;
418
419 if (offset_p)
420 *offset_p = offset;
421
422 return existed_p;
423 }
424
425
426 /* Insert tree node T in CACHE. If T already existed in the cache
427 return true. Otherwise, return false.
428
429 If IX_P is non-null, update it with the index into the cache where
430 T has been stored.
431
432 *OFFSET_P represents the offset in the stream where T is physically
433 written out. The first time T is added to the cache, *OFFSET_P is
434 recorded in the cache together with T. But if T already existed
435 in the cache, *OFFSET_P is updated with the value that was recorded
436 the first time T was added to the cache.
437
438 If OFFSET_P is NULL, it is ignored. */
439
440 bool
441 lto_streamer_cache_insert (struct lto_streamer_cache_d *cache, tree t,
442 int *ix_p, unsigned *offset_p)
443 {
444 return lto_streamer_cache_insert_1 (cache, t, ix_p, offset_p, true);
445 }
446
447
448 /* Insert tree node T in CACHE at slot IX. If T already
449 existed in the cache return true. Otherwise, return false. */
450
451 bool
452 lto_streamer_cache_insert_at (struct lto_streamer_cache_d *cache,
453 tree t, int ix)
454 {
455 return lto_streamer_cache_insert_1 (cache, t, &ix, NULL, false);
456 }
457
458
459 /* Return true if tree node T exists in CACHE. If IX_P is
460 not NULL, write to *IX_P the index into the cache where T is stored
461 (-1 if T is not found). */
462
463 bool
464 lto_streamer_cache_lookup (struct lto_streamer_cache_d *cache, tree t,
465 int *ix_p)
466 {
467 void **slot;
468 struct tree_int_map d_slot;
469 bool retval;
470 int ix;
471
472 gcc_assert (t);
473
474 d_slot.base.from = t;
475 slot = htab_find_slot (cache->node_map, &d_slot, NO_INSERT);
476 if (slot == NULL)
477 {
478 retval = false;
479 ix = -1;
480 }
481 else
482 {
483 retval = true;
484 ix = (int) ((struct tree_int_map *) *slot)->to;
485 }
486
487 if (ix_p)
488 *ix_p = ix;
489
490 return retval;
491 }
492
493
494 /* Return the tree node at slot IX in CACHE. */
495
496 tree
497 lto_streamer_cache_get (struct lto_streamer_cache_d *cache, int ix)
498 {
499 gcc_assert (cache);
500
501 /* If the reader is requesting an index beyond the length of the
502 cache, it will need to read ahead. Return NULL_TREE to indicate
503 that. */
504 if ((unsigned) ix >= VEC_length (tree, cache->nodes))
505 return NULL_TREE;
506
507 return VEC_index (tree, cache->nodes, (unsigned) ix);
508 }
509
510
511 /* Record NODE in COMMON_NODES if it is not NULL and is not already in
512 SEEN_NODES. */
513
514 static void
515 lto_record_common_node (tree *nodep, VEC(tree, heap) **common_nodes,
516 struct pointer_set_t *seen_nodes)
517 {
518 tree node = *nodep;
519
520 if (node == NULL_TREE)
521 return;
522
523 if (TYPE_P (node))
524 {
525 /* Type merging will get confused by the canonical types as they
526 are set by the middle-end. */
527 if (in_lto_p)
528 TYPE_CANONICAL (node) = NULL_TREE;
529 *nodep = node = gimple_register_type (node);
530 }
531
532 /* Return if node is already seen. */
533 if (pointer_set_insert (seen_nodes, node))
534 return;
535
536 VEC_safe_push (tree, heap, *common_nodes, node);
537
538 if (tree_node_can_be_shared (node))
539 {
540 if (POINTER_TYPE_P (node)
541 || TREE_CODE (node) == COMPLEX_TYPE
542 || TREE_CODE (node) == ARRAY_TYPE)
543 lto_record_common_node (&TREE_TYPE (node), common_nodes, seen_nodes);
544 }
545 }
546
547
548 /* Generate a vector of common nodes and make sure they are merged
549 properly according to the the gimple type table. */
550
551 static VEC(tree,heap) *
552 lto_get_common_nodes (void)
553 {
554 unsigned i;
555 VEC(tree,heap) *common_nodes = NULL;
556 struct pointer_set_t *seen_nodes;
557
558 /* The MAIN_IDENTIFIER_NODE is normally set up by the front-end, but the
559 LTO back-end must agree. Currently, the only languages that set this
560 use the name "main". */
561 if (main_identifier_node)
562 {
563 const char *main_name = IDENTIFIER_POINTER (main_identifier_node);
564 gcc_assert (strcmp (main_name, "main") == 0);
565 }
566 else
567 main_identifier_node = get_identifier ("main");
568
569 gcc_assert (ptrdiff_type_node == integer_type_node);
570
571 /* FIXME lto. In the C++ front-end, fileptr_type_node is defined as a
572 variant copy of of ptr_type_node, rather than ptr_node itself. The
573 distinction should only be relevant to the front-end, so we always
574 use the C definition here in lto1.
575
576 These should be assured in pass_ipa_free_lang_data. */
577 gcc_assert (fileptr_type_node == ptr_type_node);
578 gcc_assert (TYPE_MAIN_VARIANT (fileptr_type_node) == ptr_type_node);
579
580 seen_nodes = pointer_set_create ();
581
582 /* Skip itk_char. char_type_node is shared with the appropriately
583 signed variant. */
584 for (i = itk_signed_char; i < itk_none; i++)
585 lto_record_common_node (&integer_types[i], &common_nodes, seen_nodes);
586
587 for (i = 0; i < TYPE_KIND_LAST; i++)
588 lto_record_common_node (&sizetype_tab[i], &common_nodes, seen_nodes);
589
590 for (i = 0; i < TI_MAX; i++)
591 lto_record_common_node (&global_trees[i], &common_nodes, seen_nodes);
592
593 pointer_set_destroy (seen_nodes);
594
595 return common_nodes;
596 }
597
598
599 /* Assign an index to tree node T and enter it in the streamer cache
600 CACHE. */
601
602 static void
603 preload_common_node (struct lto_streamer_cache_d *cache, tree t)
604 {
605 gcc_assert (t);
606
607 lto_streamer_cache_insert (cache, t, NULL, NULL);
608
609 /* The FIELD_DECLs of structures should be shared, so that every
610 COMPONENT_REF uses the same tree node when referencing a field.
611 Pointer equality between FIELD_DECLs is used by the alias
612 machinery to compute overlapping memory references (See
613 nonoverlapping_component_refs_p). */
614 if (TREE_CODE (t) == RECORD_TYPE)
615 {
616 tree f;
617
618 for (f = TYPE_FIELDS (t); f; f = TREE_CHAIN (f))
619 preload_common_node (cache, f);
620 }
621 }
622
623
624 /* Create a cache of pickled nodes. */
625
626 struct lto_streamer_cache_d *
627 lto_streamer_cache_create (void)
628 {
629 struct lto_streamer_cache_d *cache;
630 VEC(tree, heap) *common_nodes;
631 unsigned i;
632 tree node;
633
634 cache = XCNEW (struct lto_streamer_cache_d);
635
636 cache->node_map = htab_create (101, tree_int_map_hash, tree_int_map_eq, NULL);
637
638 cache->node_map_entries = create_alloc_pool ("node map",
639 sizeof (struct tree_int_map),
640 100);
641
642 /* Load all the well-known tree nodes that are always created by
643 the compiler on startup. This prevents writing them out
644 unnecessarily. */
645 common_nodes = lto_get_common_nodes ();
646
647 FOR_EACH_VEC_ELT (tree, common_nodes, i, node)
648 preload_common_node (cache, node);
649
650 VEC_free(tree, heap, common_nodes);
651
652 return cache;
653 }
654
655
656 /* Delete the streamer cache C. */
657
658 void
659 lto_streamer_cache_delete (struct lto_streamer_cache_d *c)
660 {
661 if (c == NULL)
662 return;
663
664 htab_delete (c->node_map);
665 free_alloc_pool (c->node_map_entries);
666 VEC_free (tree, heap, c->nodes);
667 VEC_free (unsigned, heap, c->offsets);
668 free (c);
669 }
670
671
672 #ifdef LTO_STREAMER_DEBUG
673 static htab_t tree_htab;
674
675 struct tree_hash_entry
676 {
677 tree key;
678 intptr_t value;
679 };
680
681 static hashval_t
682 hash_tree (const void *p)
683 {
684 const struct tree_hash_entry *e = (const struct tree_hash_entry *) p;
685 return htab_hash_pointer (e->key);
686 }
687
688 static int
689 eq_tree (const void *p1, const void *p2)
690 {
691 const struct tree_hash_entry *e1 = (const struct tree_hash_entry *) p1;
692 const struct tree_hash_entry *e2 = (const struct tree_hash_entry *) p2;
693 return (e1->key == e2->key);
694 }
695 #endif
696
697 /* Initialization common to the LTO reader and writer. */
698
699 void
700 lto_streamer_init (void)
701 {
702 /* Check that all the TS_* handled by the reader and writer routines
703 match exactly the structures defined in treestruct.def. When a
704 new TS_* astructure is added, the streamer should be updated to
705 handle it. */
706 check_handled_ts_structures ();
707
708 #ifdef LTO_STREAMER_DEBUG
709 tree_htab = htab_create (31, hash_tree, eq_tree, NULL);
710 #endif
711 }
712
713
714 /* Gate function for all LTO streaming passes. */
715
716 bool
717 gate_lto_out (void)
718 {
719 return ((flag_generate_lto || in_lto_p)
720 /* Don't bother doing anything if the program has errors. */
721 && !seen_error ());
722 }
723
724
725 #ifdef LTO_STREAMER_DEBUG
726 /* Add a mapping between T and ORIG_T, which is the numeric value of
727 the original address of T as it was seen by the LTO writer. This
728 mapping is useful when debugging streaming problems. A debugging
729 session can be started on both reader and writer using ORIG_T
730 as a breakpoint value in both sessions.
731
732 Note that this mapping is transient and only valid while T is
733 being reconstructed. Once T is fully built, the mapping is
734 removed. */
735
736 void
737 lto_orig_address_map (tree t, intptr_t orig_t)
738 {
739 struct tree_hash_entry ent;
740 struct tree_hash_entry **slot;
741
742 ent.key = t;
743 ent.value = orig_t;
744 slot
745 = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, INSERT);
746 gcc_assert (!*slot);
747 *slot = XNEW (struct tree_hash_entry);
748 **slot = ent;
749 }
750
751
752 /* Get the original address of T as it was seen by the writer. This
753 is only valid while T is being reconstructed. */
754
755 intptr_t
756 lto_orig_address_get (tree t)
757 {
758 struct tree_hash_entry ent;
759 struct tree_hash_entry **slot;
760
761 ent.key = t;
762 slot
763 = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, NO_INSERT);
764 return (slot ? (*slot)->value : 0);
765 }
766
767
768 /* Clear the mapping of T to its original address. */
769
770 void
771 lto_orig_address_remove (tree t)
772 {
773 struct tree_hash_entry ent;
774 struct tree_hash_entry **slot;
775
776 ent.key = t;
777 slot
778 = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, NO_INSERT);
779 gcc_assert (slot);
780 free (*slot);
781 htab_clear_slot (tree_htab, (PTR *)slot);
782 }
783 #endif
784
785
786 /* Check that the version MAJOR.MINOR is the correct version number. */
787
788 void
789 lto_check_version (int major, int minor)
790 {
791 if (major != LTO_major_version || minor != LTO_minor_version)
792 fatal_error ("bytecode stream generated with LTO version %d.%d instead "
793 "of the expected %d.%d",
794 major, minor,
795 LTO_major_version, LTO_minor_version);
796 }