comparison gcc/lto-streamer.c @ 63:b7f97abdc517 gcc-4.6-20100522

update gcc from gcc-4.5.0 to gcc-4.6
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 24 May 2010 12:47:05 +0900
parents 77e2b8dfacca
children f6334be47118
comparison
equal deleted inserted replaced
56:3c8a44c06a95 63:b7f97abdc517
1 /* Miscellaneous utilities for GIMPLE streaming. Things that are used 1 /* Miscellaneous utilities for GIMPLE streaming. Things that are used
2 in both input and output are here. 2 in both input and output are here.
3 3
4 Copyright 2009 Free Software Foundation, Inc. 4 Copyright 2009, 2010 Free Software Foundation, Inc.
5 Contributed by Doug Kwan <dougkwan@google.com> 5 Contributed by Doug Kwan <dougkwan@google.com>
6 6
7 This file is part of GCC. 7 This file is part of GCC.
8 8
9 GCC is free software; you can redistribute it and/or modify it under 9 GCC is free software; you can redistribute it and/or modify it under
141 lto_get_section_name (int section_type, const char *name) 141 lto_get_section_name (int section_type, const char *name)
142 { 142 {
143 switch (section_type) 143 switch (section_type)
144 { 144 {
145 case LTO_section_function_body: 145 case LTO_section_function_body:
146 gcc_assert (name != NULL);
147 if (name[0] == '*')
148 name++;
146 return concat (LTO_SECTION_NAME_PREFIX, name, NULL); 149 return concat (LTO_SECTION_NAME_PREFIX, name, NULL);
147 150
148 case LTO_section_static_initializer: 151 case LTO_section_static_initializer:
149 return concat (LTO_SECTION_NAME_PREFIX, ".statics", NULL); 152 return concat (LTO_SECTION_NAME_PREFIX, ".statics", NULL);
150 153
155 return concat (LTO_SECTION_NAME_PREFIX, ".decls", NULL); 158 return concat (LTO_SECTION_NAME_PREFIX, ".decls", NULL);
156 159
157 case LTO_section_cgraph: 160 case LTO_section_cgraph:
158 return concat (LTO_SECTION_NAME_PREFIX, ".cgraph", NULL); 161 return concat (LTO_SECTION_NAME_PREFIX, ".cgraph", NULL);
159 162
163 case LTO_section_varpool:
164 return concat (LTO_SECTION_NAME_PREFIX, ".vars", NULL);
165
166 case LTO_section_refs:
167 return concat (LTO_SECTION_NAME_PREFIX, ".refs", NULL);
168
160 case LTO_section_jump_functions: 169 case LTO_section_jump_functions:
161 return concat (LTO_SECTION_NAME_PREFIX, ".jmpfuncs", NULL); 170 return concat (LTO_SECTION_NAME_PREFIX, ".jmpfuncs", NULL);
162 171
163 case LTO_section_ipa_pure_const: 172 case LTO_section_ipa_pure_const:
164 return concat (LTO_SECTION_NAME_PREFIX, ".pureconst", NULL); 173 return concat (LTO_SECTION_NAME_PREFIX, ".pureconst", NULL);
165 174
166 case LTO_section_ipa_reference: 175 case LTO_section_ipa_reference:
167 return concat (LTO_SECTION_NAME_PREFIX, ".reference", NULL); 176 return concat (LTO_SECTION_NAME_PREFIX, ".reference", NULL);
168 177
169 case LTO_section_wpa_fixup:
170 return concat (LTO_SECTION_NAME_PREFIX, ".wpa_fixup", NULL);
171
172 case LTO_section_opts: 178 case LTO_section_opts:
173 return concat (LTO_SECTION_NAME_PREFIX, ".opts", NULL); 179 return concat (LTO_SECTION_NAME_PREFIX, ".opts", NULL);
180
181 case LTO_section_cgraph_opt_sum:
182 return concat (LTO_SECTION_NAME_PREFIX, ".cgraphopt", NULL);
174 183
175 default: 184 default:
176 internal_error ("bytecode stream: unexpected LTO section %s", name); 185 internal_error ("bytecode stream: unexpected LTO section %s", name);
177 } 186 }
178 } 187 }
450 459
451 /* Grow the array of nodes and offsets to accomodate T at IX. */ 460 /* Grow the array of nodes and offsets to accomodate T at IX. */
452 if (ix >= (int) VEC_length (tree, cache->nodes)) 461 if (ix >= (int) VEC_length (tree, cache->nodes))
453 { 462 {
454 size_t sz = ix + (20 + ix) / 4; 463 size_t sz = ix + (20 + ix) / 4;
455 VEC_safe_grow_cleared (tree, gc, cache->nodes, sz); 464 VEC_safe_grow_cleared (tree, heap, cache->nodes, sz);
456 VEC_safe_grow_cleared (unsigned, heap, cache->offsets, sz); 465 VEC_safe_grow_cleared (unsigned, heap, cache->offsets, sz);
457 } 466 }
458 467
459 VEC_replace (tree, cache->nodes, ix, t); 468 VEC_replace (tree, cache->nodes, ix, t);
460 VEC_replace (unsigned, cache->offsets, ix, offset); 469 VEC_replace (unsigned, cache->offsets, ix, offset);
492 if (insert_at_next_slot_p) 501 if (insert_at_next_slot_p)
493 ix = cache->next_slot++; 502 ix = cache->next_slot++;
494 else 503 else
495 ix = *ix_p; 504 ix = *ix_p;
496 505
497 entry = XCNEW (struct tree_int_map); 506 entry = (struct tree_int_map *)pool_alloc (cache->node_map_entries);
498 entry->base.from = t; 507 entry->base.from = t;
499 entry->to = (unsigned) ix; 508 entry->to = (unsigned) ix;
500 *slot = entry; 509 *slot = entry;
501 510
502 /* If no offset was given, store the invalid offset -1. */ 511 /* If no offset was given, store the invalid offset -1. */
754 763
755 cache = XCNEW (struct lto_streamer_cache_d); 764 cache = XCNEW (struct lto_streamer_cache_d);
756 765
757 cache->node_map = htab_create (101, tree_int_map_hash, tree_int_map_eq, NULL); 766 cache->node_map = htab_create (101, tree_int_map_hash, tree_int_map_eq, NULL);
758 767
768 cache->node_map_entries = create_alloc_pool ("node map",
769 sizeof (struct tree_int_map),
770 100);
771
759 /* Load all the well-known tree nodes that are always created by 772 /* Load all the well-known tree nodes that are always created by
760 the compiler on startup. This prevents writing them out 773 the compiler on startup. This prevents writing them out
761 unnecessarily. */ 774 unnecessarily. */
762 common_nodes = lto_get_common_nodes (); 775 common_nodes = lto_get_common_nodes ();
763 776
777 { 790 {
778 if (c == NULL) 791 if (c == NULL)
779 return; 792 return;
780 793
781 htab_delete (c->node_map); 794 htab_delete (c->node_map);
782 VEC_free (tree, gc, c->nodes); 795 free_alloc_pool (c->node_map_entries);
796 VEC_free (tree, heap, c->nodes);
783 VEC_free (unsigned, heap, c->offsets); 797 VEC_free (unsigned, heap, c->offsets);
784 free (c); 798 free (c);
785 } 799 }
786 800
801
802 #ifdef LTO_STREAMER_DEBUG
803 static htab_t tree_htab;
804
805 struct tree_hash_entry
806 {
807 tree key;
808 intptr_t value;
809 };
810
811 static hashval_t
812 hash_tree (const void *p)
813 {
814 const struct tree_hash_entry *e = (const struct tree_hash_entry *) p;
815 return htab_hash_pointer (e->key);
816 }
817
818 static int
819 eq_tree (const void *p1, const void *p2)
820 {
821 const struct tree_hash_entry *e1 = (const struct tree_hash_entry *) p1;
822 const struct tree_hash_entry *e2 = (const struct tree_hash_entry *) p2;
823 return (e1->key == e2->key);
824 }
825 #endif
787 826
788 /* Initialization common to the LTO reader and writer. */ 827 /* Initialization common to the LTO reader and writer. */
789 828
790 void 829 void
791 lto_streamer_init (void) 830 lto_streamer_init (void)
793 /* Check that all the TS_* handled by the reader and writer routines 832 /* Check that all the TS_* handled by the reader and writer routines
794 match exactly the structures defined in treestruct.def. When a 833 match exactly the structures defined in treestruct.def. When a
795 new TS_* astructure is added, the streamer should be updated to 834 new TS_* astructure is added, the streamer should be updated to
796 handle it. */ 835 handle it. */
797 check_handled_ts_structures (); 836 check_handled_ts_structures ();
837
838 #ifdef LTO_STREAMER_DEBUG
839 tree_htab = htab_create (31, hash_tree, eq_tree, NULL);
840 #endif
798 } 841 }
799 842
800 843
801 /* Gate function for all LTO streaming passes. */ 844 /* Gate function for all LTO streaming passes. */
802 845
821 removed. */ 864 removed. */
822 865
823 void 866 void
824 lto_orig_address_map (tree t, intptr_t orig_t) 867 lto_orig_address_map (tree t, intptr_t orig_t)
825 { 868 {
826 /* FIXME lto. Using the annotation field is quite hacky as it relies 869 struct tree_hash_entry ent;
827 on the GC not running while T is being rematerialized. It would 870 struct tree_hash_entry **slot;
828 be cleaner to use a hash table here. */ 871
829 t->base.ann = (union tree_ann_d *) orig_t; 872 ent.key = t;
873 ent.value = orig_t;
874 slot
875 = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, INSERT);
876 gcc_assert (!*slot);
877 *slot = XNEW (struct tree_hash_entry);
878 **slot = ent;
830 } 879 }
831 880
832 881
833 /* Get the original address of T as it was seen by the writer. This 882 /* Get the original address of T as it was seen by the writer. This
834 is only valid while T is being reconstructed. */ 883 is only valid while T is being reconstructed. */
835 884
836 intptr_t 885 intptr_t
837 lto_orig_address_get (tree t) 886 lto_orig_address_get (tree t)
838 { 887 {
839 return (intptr_t) t->base.ann; 888 struct tree_hash_entry ent;
889 struct tree_hash_entry **slot;
890
891 ent.key = t;
892 slot
893 = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, NO_INSERT);
894 return (slot ? (*slot)->value : 0);
840 } 895 }
841 896
842 897
843 /* Clear the mapping of T to its original address. */ 898 /* Clear the mapping of T to its original address. */
844 899
845 void 900 void
846 lto_orig_address_remove (tree t) 901 lto_orig_address_remove (tree t)
847 { 902 {
848 t->base.ann = NULL; 903 struct tree_hash_entry ent;
904 struct tree_hash_entry **slot;
905
906 ent.key = t;
907 slot
908 = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, NO_INSERT);
909 gcc_assert (slot);
910 free (*slot);
911 htab_clear_slot (tree_htab, (PTR *)slot);
849 } 912 }
850 #endif 913 #endif
851 914
852 915
853 /* Check that the version MAJOR.MINOR is the correct version number. */ 916 /* Check that the version MAJOR.MINOR is the correct version number. */