Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa-coalesce.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
34 #include "toplev.h" | 34 #include "toplev.h" |
35 | 35 |
36 | 36 |
37 /* This set of routines implements a coalesce_list. This is an object which | 37 /* This set of routines implements a coalesce_list. This is an object which |
38 is used to track pairs of ssa_names which are desirable to coalesce | 38 is used to track pairs of ssa_names which are desirable to coalesce |
39 together to avoid copies. Costs are associated with each pair, and when | 39 together to avoid copies. Costs are associated with each pair, and when |
40 all desired information has been collected, the object can be used to | 40 all desired information has been collected, the object can be used to |
41 order the pairs for processing. */ | 41 order the pairs for processing. */ |
42 | 42 |
43 /* This structure defines a pair entry. */ | 43 /* This structure defines a pair entry. */ |
44 | 44 |
45 typedef struct coalesce_pair | 45 typedef struct coalesce_pair |
57 struct cost_one_pair_d *next; | 57 struct cost_one_pair_d *next; |
58 } * cost_one_pair_p; | 58 } * cost_one_pair_p; |
59 | 59 |
60 /* This structure maintains the list of coalesce pairs. */ | 60 /* This structure maintains the list of coalesce pairs. */ |
61 | 61 |
62 typedef struct coalesce_list_d | 62 typedef struct coalesce_list_d |
63 { | 63 { |
64 htab_t list; /* Hash table. */ | 64 htab_t list; /* Hash table. */ |
65 coalesce_pair_p *sorted; /* List when sorted. */ | 65 coalesce_pair_p *sorted; /* List when sorted. */ |
66 int num_sorted; /* Number in the sorted list. */ | 66 int num_sorted; /* Number in the sorted list. */ |
67 cost_one_pair_p cost_one_list;/* Single use coalesces with cost 1. */ | 67 cost_one_pair_p cost_one_list;/* Single use coalesces with cost 1. */ |
69 | 69 |
70 #define NO_BEST_COALESCE -1 | 70 #define NO_BEST_COALESCE -1 |
71 #define MUST_COALESCE_COST INT_MAX | 71 #define MUST_COALESCE_COST INT_MAX |
72 | 72 |
73 | 73 |
74 /* Return cost of execution of copy instruction with FREQUENCY | 74 /* Return cost of execution of copy instruction with FREQUENCY. */ |
75 possibly on CRITICAL edge and in HOT basic block. */ | |
76 | 75 |
77 static inline int | 76 static inline int |
78 coalesce_cost (int frequency, bool optimize_for_size, bool critical) | 77 coalesce_cost (int frequency, bool optimize_for_size) |
79 { | 78 { |
80 /* Base costs on BB frequencies bounded by 1. */ | 79 /* Base costs on BB frequencies bounded by 1. */ |
81 int cost = frequency; | 80 int cost = frequency; |
82 | 81 |
83 if (!cost) | 82 if (!cost) |
84 cost = 1; | 83 cost = 1; |
85 | 84 |
86 if (optimize_for_size) | 85 if (optimize_for_size) |
87 cost = 1; | 86 cost = 1; |
88 | 87 |
88 return cost; | |
89 } | |
90 | |
91 | |
92 /* Return the cost of executing a copy instruction in basic block BB. */ | |
93 | |
94 static inline int | |
95 coalesce_cost_bb (basic_block bb) | |
96 { | |
97 return coalesce_cost (bb->frequency, optimize_bb_for_size_p (bb)); | |
98 } | |
99 | |
100 | |
101 /* Return the cost of executing a copy instruction on edge E. */ | |
102 | |
103 static inline int | |
104 coalesce_cost_edge (edge e) | |
105 { | |
106 int mult = 1; | |
107 | |
89 /* Inserting copy on critical edge costs more than inserting it elsewhere. */ | 108 /* Inserting copy on critical edge costs more than inserting it elsewhere. */ |
90 if (critical) | 109 if (EDGE_CRITICAL_P (e)) |
91 cost *= 2; | 110 mult = 2; |
92 return cost; | |
93 } | |
94 | |
95 | |
96 /* Return the cost of executing a copy instruction in basic block BB. */ | |
97 | |
98 static inline int | |
99 coalesce_cost_bb (basic_block bb) | |
100 { | |
101 return coalesce_cost (bb->frequency, optimize_bb_for_size_p (bb), false); | |
102 } | |
103 | |
104 | |
105 /* Return the cost of executing a copy instruction on edge E. */ | |
106 | |
107 static inline int | |
108 coalesce_cost_edge (edge e) | |
109 { | |
110 if (e->flags & EDGE_ABNORMAL) | 111 if (e->flags & EDGE_ABNORMAL) |
111 return MUST_COALESCE_COST; | 112 return MUST_COALESCE_COST; |
112 | 113 if (e->flags & EDGE_EH) |
113 return coalesce_cost (EDGE_FREQUENCY (e), | 114 { |
114 optimize_edge_for_size_p (e), | 115 edge e2; |
115 EDGE_CRITICAL_P (e)); | 116 edge_iterator ei; |
116 } | 117 FOR_EACH_EDGE (e2, ei, e->dest->preds) |
117 | 118 if (e2 != e) |
118 | 119 { |
119 /* Retrieve a pair to coalesce from the cost_one_list in CL. Returns the | 120 /* Putting code on EH edge that leads to BB |
121 with multiple predecestors imply splitting of | |
122 edge too. */ | |
123 if (mult < 2) | |
124 mult = 2; | |
125 /* If there are multiple EH predecestors, we | |
126 also copy EH regions and produce separate | |
127 landing pad. This is expensive. */ | |
128 if (e2->flags & EDGE_EH) | |
129 { | |
130 mult = 5; | |
131 break; | |
132 } | |
133 } | |
134 } | |
135 | |
136 return coalesce_cost (EDGE_FREQUENCY (e), | |
137 optimize_edge_for_size_p (e)) * mult; | |
138 } | |
139 | |
140 | |
141 /* Retrieve a pair to coalesce from the cost_one_list in CL. Returns the | |
120 2 elements via P1 and P2. 1 is returned by the function if there is a pair, | 142 2 elements via P1 and P2. 1 is returned by the function if there is a pair, |
121 NO_BEST_COALESCE is returned if there aren't any. */ | 143 NO_BEST_COALESCE is returned if there aren't any. */ |
122 | 144 |
123 static inline int | 145 static inline int |
124 pop_cost_one_pair (coalesce_list_p cl, int *p1, int *p2) | 146 pop_cost_one_pair (coalesce_list_p cl, int *p1, int *p2) |
136 free (ptr); | 158 free (ptr); |
137 | 159 |
138 return 1; | 160 return 1; |
139 } | 161 } |
140 | 162 |
141 /* Retrieve the most expensive remaining pair to coalesce from CL. Returns the | 163 /* Retrieve the most expensive remaining pair to coalesce from CL. Returns the |
142 2 elements via P1 and P2. Their calculated cost is returned by the function. | 164 2 elements via P1 and P2. Their calculated cost is returned by the function. |
143 NO_BEST_COALESCE is returned if the coalesce list is empty. */ | 165 NO_BEST_COALESCE is returned if the coalesce list is empty. */ |
144 | 166 |
145 static inline int | 167 static inline int |
146 pop_best_coalesce (coalesce_list_p cl, int *p1, int *p2) | 168 pop_best_coalesce (coalesce_list_p cl, int *p1, int *p2) |
166 | 188 |
167 #define COALESCE_HASH_FN(R1, R2) ((R2) * ((R2) - 1) / 2 + (R1)) | 189 #define COALESCE_HASH_FN(R1, R2) ((R2) * ((R2) - 1) / 2 + (R1)) |
168 | 190 |
169 /* Hash function for coalesce list. Calculate hash for PAIR. */ | 191 /* Hash function for coalesce list. Calculate hash for PAIR. */ |
170 | 192 |
171 static unsigned int | 193 static unsigned int |
172 coalesce_pair_map_hash (const void *pair) | 194 coalesce_pair_map_hash (const void *pair) |
173 { | 195 { |
174 hashval_t a = (hashval_t)(((const_coalesce_pair_p)pair)->first_element); | 196 hashval_t a = (hashval_t)(((const_coalesce_pair_p)pair)->first_element); |
175 hashval_t b = (hashval_t)(((const_coalesce_pair_p)pair)->second_element); | 197 hashval_t b = (hashval_t)(((const_coalesce_pair_p)pair)->second_element); |
176 | 198 |
179 | 201 |
180 | 202 |
181 /* Equality function for coalesce list hash table. Compare PAIR1 and PAIR2, | 203 /* Equality function for coalesce list hash table. Compare PAIR1 and PAIR2, |
182 returning TRUE if the two pairs are equivalent. */ | 204 returning TRUE if the two pairs are equivalent. */ |
183 | 205 |
184 static int | 206 static int |
185 coalesce_pair_map_eq (const void *pair1, const void *pair2) | 207 coalesce_pair_map_eq (const void *pair1, const void *pair2) |
186 { | 208 { |
187 const_coalesce_pair_p const p1 = (const_coalesce_pair_p) pair1; | 209 const_coalesce_pair_p const p1 = (const_coalesce_pair_p) pair1; |
188 const_coalesce_pair_p const p2 = (const_coalesce_pair_p) pair2; | 210 const_coalesce_pair_p const p2 = (const_coalesce_pair_p) pair2; |
189 | 211 |
192 } | 214 } |
193 | 215 |
194 | 216 |
195 /* Create a new empty coalesce list object and return it. */ | 217 /* Create a new empty coalesce list object and return it. */ |
196 | 218 |
197 static inline coalesce_list_p | 219 static inline coalesce_list_p |
198 create_coalesce_list (void) | 220 create_coalesce_list (void) |
199 { | 221 { |
200 coalesce_list_p list; | 222 coalesce_list_p list; |
201 unsigned size = num_ssa_names * 3; | 223 unsigned size = num_ssa_names * 3; |
202 | 224 |
203 if (size < 40) | 225 if (size < 40) |
204 size = 40; | 226 size = 40; |
205 | 227 |
206 list = (coalesce_list_p) xmalloc (sizeof (struct coalesce_list_d)); | 228 list = (coalesce_list_p) xmalloc (sizeof (struct coalesce_list_d)); |
207 list->list = htab_create (size, coalesce_pair_map_hash, | 229 list->list = htab_create (size, coalesce_pair_map_hash, |
208 coalesce_pair_map_eq, NULL); | 230 coalesce_pair_map_eq, NULL); |
213 } | 235 } |
214 | 236 |
215 | 237 |
216 /* Delete coalesce list CL. */ | 238 /* Delete coalesce list CL. */ |
217 | 239 |
218 static inline void | 240 static inline void |
219 delete_coalesce_list (coalesce_list_p cl) | 241 delete_coalesce_list (coalesce_list_p cl) |
220 { | 242 { |
221 gcc_assert (cl->cost_one_list == NULL); | 243 gcc_assert (cl->cost_one_list == NULL); |
222 htab_delete (cl->list); | 244 htab_delete (cl->list); |
223 if (cl->sorted) | 245 if (cl->sorted) |
225 gcc_assert (cl->num_sorted == 0); | 247 gcc_assert (cl->num_sorted == 0); |
226 free (cl); | 248 free (cl); |
227 } | 249 } |
228 | 250 |
229 | 251 |
230 /* Find a matching coalesce pair object in CL for the pair P1 and P2. If | 252 /* Find a matching coalesce pair object in CL for the pair P1 and P2. If |
231 one isn't found, return NULL if CREATE is false, otherwise create a new | 253 one isn't found, return NULL if CREATE is false, otherwise create a new |
232 coalesce pair object and return it. */ | 254 coalesce pair object and return it. */ |
233 | 255 |
234 static coalesce_pair_p | 256 static coalesce_pair_p |
235 find_coalesce_pair (coalesce_list_p cl, int p1, int p2, bool create) | 257 find_coalesce_pair (coalesce_list_p cl, int p1, int p2, bool create) |
236 { | 258 { |
237 struct coalesce_pair p, *pair; | 259 struct coalesce_pair p, *pair; |
238 void **slot; | 260 void **slot; |
239 unsigned int hash; | 261 unsigned int hash; |
240 | 262 |
241 /* Normalize so that p1 is the smaller value. */ | 263 /* Normalize so that p1 is the smaller value. */ |
242 if (p2 < p1) | 264 if (p2 < p1) |
243 { | 265 { |
244 p.first_element = p2; | 266 p.first_element = p2; |
245 p.second_element = p1; | 267 p.second_element = p1; |
247 else | 269 else |
248 { | 270 { |
249 p.first_element = p1; | 271 p.first_element = p1; |
250 p.second_element = p2; | 272 p.second_element = p2; |
251 } | 273 } |
252 | 274 |
253 | 275 |
254 hash = coalesce_pair_map_hash (&p); | 276 hash = coalesce_pair_map_hash (&p); |
255 pair = (struct coalesce_pair *) htab_find_with_hash (cl->list, &p, hash); | 277 pair = (struct coalesce_pair *) htab_find_with_hash (cl->list, &p, hash); |
256 | 278 |
257 if (create && !pair) | 279 if (create && !pair) |
258 { | 280 { |
281 } | 303 } |
282 | 304 |
283 | 305 |
284 /* Add a coalesce between P1 and P2 in list CL with a cost of VALUE. */ | 306 /* Add a coalesce between P1 and P2 in list CL with a cost of VALUE. */ |
285 | 307 |
286 static inline void | 308 static inline void |
287 add_coalesce (coalesce_list_p cl, int p1, int p2, int value) | 309 add_coalesce (coalesce_list_p cl, int p1, int p2, int value) |
288 { | 310 { |
289 coalesce_pair_p node; | 311 coalesce_pair_p node; |
290 | 312 |
291 gcc_assert (cl->sorted == NULL); | 313 gcc_assert (cl->sorted == NULL); |
305 } | 327 } |
306 | 328 |
307 | 329 |
308 /* Comparison function to allow qsort to sort P1 and P2 in Ascending order. */ | 330 /* Comparison function to allow qsort to sort P1 and P2 in Ascending order. */ |
309 | 331 |
310 static int | 332 static int |
311 compare_pairs (const void *p1, const void *p2) | 333 compare_pairs (const void *p1, const void *p2) |
312 { | 334 { |
313 const_coalesce_pair_p const *const pp1 = (const_coalesce_pair_p const *) p1; | 335 const_coalesce_pair_p const *const pp1 = (const_coalesce_pair_p const *) p1; |
314 const_coalesce_pair_p const *const pp2 = (const_coalesce_pair_p const *) p2; | 336 const_coalesce_pair_p const *const pp2 = (const_coalesce_pair_p const *) p2; |
315 int result; | 337 int result; |
316 | 338 |
317 result = (* pp2)->cost - (* pp1)->cost; | 339 result = (* pp1)->cost - (* pp2)->cost; |
318 /* Since qsort does not guarantee stability we use the elements | 340 /* Since qsort does not guarantee stability we use the elements |
319 as a secondary key. This provides us with independence from | 341 as a secondary key. This provides us with independence from |
320 the host's implementation of the sorting algorithm. */ | 342 the host's implementation of the sorting algorithm. */ |
321 if (result == 0) | 343 if (result == 0) |
322 { | 344 { |
434 } | 456 } |
435 | 457 |
436 | 458 |
437 /* Send debug info for coalesce list CL to file F. */ | 459 /* Send debug info for coalesce list CL to file F. */ |
438 | 460 |
439 static void | 461 static void |
440 dump_coalesce_list (FILE *f, coalesce_list_p cl) | 462 dump_coalesce_list (FILE *f, coalesce_list_p cl) |
441 { | 463 { |
442 coalesce_pair_p node; | 464 coalesce_pair_p node; |
443 coalesce_pair_iterator ppi; | 465 coalesce_pair_iterator ppi; |
444 int x; | 466 int x; |
474 } | 496 } |
475 } | 497 } |
476 } | 498 } |
477 | 499 |
478 | 500 |
479 /* This represents a conflict graph. Implemented as an array of bitmaps. | 501 /* This represents a conflict graph. Implemented as an array of bitmaps. |
480 A full matrix is used for conflicts rather than just upper triangular form. | 502 A full matrix is used for conflicts rather than just upper triangular form. |
481 this make sit much simpler and faster to perform conflict merges. */ | 503 this make sit much simpler and faster to perform conflict merges. */ |
482 | 504 |
483 typedef struct ssa_conflicts_d | 505 typedef struct ssa_conflicts_d |
484 { | 506 { |
615 dump_bitmap (file, ptr->conflicts[x]); | 637 dump_bitmap (file, ptr->conflicts[x]); |
616 } | 638 } |
617 } | 639 } |
618 | 640 |
619 | 641 |
620 /* This structure is used to efficiently record the current status of live | 642 /* This structure is used to efficiently record the current status of live |
621 SSA_NAMES when building a conflict graph. | 643 SSA_NAMES when building a conflict graph. |
622 LIVE_BASE_VAR has a bit set for each base variable which has at least one | 644 LIVE_BASE_VAR has a bit set for each base variable which has at least one |
623 ssa version live. | 645 ssa version live. |
624 LIVE_BASE_PARTITIONS is an array of bitmaps using the basevar table as an | 646 LIVE_BASE_PARTITIONS is an array of bitmaps using the basevar table as an |
625 index, and is used to track what partitions of each base variable are | 647 index, and is used to track what partitions of each base variable are |
626 live. This makes it easy to add conflicts between just live partitions | 648 live. This makes it easy to add conflicts between just live partitions |
627 with the same base variable. | 649 with the same base variable. |
628 The values in LIVE_BASE_PARTITIONS are only valid if the base variable is | 650 The values in LIVE_BASE_PARTITIONS are only valid if the base variable is |
629 marked as being live. This delays clearing of these bitmaps until | 651 marked as being live. This delays clearing of these bitmaps until |
630 they are actually needed again. */ | 652 they are actually needed again. */ |
631 | 653 |
632 typedef struct live_track_d | 654 typedef struct live_track_d |
633 { | 655 { |
697 live_track_add_partition (live_track_p ptr, int partition) | 719 live_track_add_partition (live_track_p ptr, int partition) |
698 { | 720 { |
699 int root; | 721 int root; |
700 | 722 |
701 root = basevar_index (ptr->map, partition); | 723 root = basevar_index (ptr->map, partition); |
702 /* If this base var wasn't live before, it is now. Clear the element list | 724 /* If this base var wasn't live before, it is now. Clear the element list |
703 since it was delayed until needed. */ | 725 since it was delayed until needed. */ |
704 if (!bitmap_bit_p (ptr->live_base_var, root)) | 726 if (!bitmap_bit_p (ptr->live_base_var, root)) |
705 { | 727 { |
706 bitmap_set_bit (ptr->live_base_var, root); | 728 bitmap_set_bit (ptr->live_base_var, root); |
707 bitmap_clear (ptr->live_base_partitions[root]); | 729 bitmap_clear (ptr->live_base_partitions[root]); |
708 } | 730 } |
709 bitmap_set_bit (ptr->live_base_partitions[root], partition); | 731 bitmap_set_bit (ptr->live_base_partitions[root], partition); |
710 | 732 |
711 } | 733 } |
712 | 734 |
713 | 735 |
714 /* Clear the live bit for VAR in PTR. */ | 736 /* Clear the live bit for VAR in PTR. */ |
715 | 737 |
740 } | 762 } |
741 return false; | 763 return false; |
742 } | 764 } |
743 | 765 |
744 | 766 |
745 /* This routine will add USE to PTR. USE will be marked as live in both the | 767 /* This routine will add USE to PTR. USE will be marked as live in both the |
746 ssa live map and the live bitmap for the root of USE. */ | 768 ssa live map and the live bitmap for the root of USE. */ |
747 | 769 |
748 static inline void | 770 static inline void |
749 live_track_process_use (live_track_p ptr, tree use) | 771 live_track_process_use (live_track_p ptr, tree use) |
750 { | 772 { |
758 live_track_add_partition (ptr, p); | 780 live_track_add_partition (ptr, p); |
759 } | 781 } |
760 | 782 |
761 | 783 |
762 /* This routine will process a DEF in PTR. DEF will be removed from the live | 784 /* This routine will process a DEF in PTR. DEF will be removed from the live |
763 lists, and if there are any other live partitions with the same base | 785 lists, and if there are any other live partitions with the same base |
764 variable, conflicts will be added to GRAPH. */ | 786 variable, conflicts will be added to GRAPH. */ |
765 | 787 |
766 static inline void | 788 static inline void |
767 live_track_process_def (live_track_p ptr, tree def, ssa_conflicts_p graph) | 789 live_track_process_def (live_track_p ptr, tree def, ssa_conflicts_p graph) |
768 { | 790 { |
814 bitmap_clear (ptr->live_base_var); | 836 bitmap_clear (ptr->live_base_var); |
815 } | 837 } |
816 | 838 |
817 | 839 |
818 /* Build a conflict graph based on LIVEINFO. Any partitions which are in the | 840 /* Build a conflict graph based on LIVEINFO. Any partitions which are in the |
819 partition view of the var_map liveinfo is based on get entries in the | 841 partition view of the var_map liveinfo is based on get entries in the |
820 conflict graph. Only conflicts between ssa_name partitions with the same | 842 conflict graph. Only conflicts between ssa_name partitions with the same |
821 base variable are added. */ | 843 base variable are added. */ |
822 | 844 |
823 static ssa_conflicts_p | 845 static ssa_conflicts_p |
824 build_ssa_conflict_graph (tree_live_info_p liveinfo) | 846 build_ssa_conflict_graph (tree_live_info_p liveinfo) |
825 { | 847 { |
844 for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi)) | 866 for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi)) |
845 { | 867 { |
846 tree var; | 868 tree var; |
847 gimple stmt = gsi_stmt (gsi); | 869 gimple stmt = gsi_stmt (gsi); |
848 | 870 |
849 /* A copy between 2 partitions does not introduce an interference | 871 /* A copy between 2 partitions does not introduce an interference |
850 by itself. If they did, you would never be able to coalesce | 872 by itself. If they did, you would never be able to coalesce |
851 two things which are copied. If the two variables really do | 873 two things which are copied. If the two variables really do |
852 conflict, they will conflict elsewhere in the program. | 874 conflict, they will conflict elsewhere in the program. |
853 | 875 |
854 This is handled by simply removing the SRC of the copy from the | 876 This is handled by simply removing the SRC of the copy from the |
855 live list, and processing the stmt normally. */ | 877 live list, and processing the stmt normally. */ |
856 if (is_gimple_assign (stmt)) | 878 if (is_gimple_assign (stmt)) |
857 { | 879 { |
858 tree lhs = gimple_assign_lhs (stmt); | 880 tree lhs = gimple_assign_lhs (stmt); |
859 tree rhs1 = gimple_assign_rhs1 (stmt); | 881 tree rhs1 = gimple_assign_rhs1 (stmt); |
860 if (gimple_assign_copy_p (stmt) | 882 if (gimple_assign_copy_p (stmt) |
861 && TREE_CODE (lhs) == SSA_NAME | 883 && TREE_CODE (lhs) == SSA_NAME |
862 && TREE_CODE (rhs1) == SSA_NAME) | 884 && TREE_CODE (rhs1) == SSA_NAME) |
863 live_track_clear_var (live, rhs1); | 885 live_track_clear_var (live, rhs1); |
864 } | 886 } |
887 else if (is_gimple_debug (stmt)) | |
888 continue; | |
865 | 889 |
866 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF) | 890 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF) |
867 live_track_process_def (live, var, graph); | 891 live_track_process_def (live, var, graph); |
868 | 892 |
869 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE) | 893 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE) |
870 live_track_process_use (live, var); | 894 live_track_process_use (live, var); |
871 } | 895 } |
872 | 896 |
873 /* If result of a PHI is unused, looping over the statements will not | 897 /* If result of a PHI is unused, looping over the statements will not |
874 record any conflicts since the def was never live. Since the PHI node | 898 record any conflicts since the def was never live. Since the PHI node |
875 is going to be translated out of SSA form, it will insert a copy. | 899 is going to be translated out of SSA form, it will insert a copy. |
876 There must be a conflict recorded between the result of the PHI and | 900 There must be a conflict recorded between the result of the PHI and |
877 any variables that are live. Otherwise the out-of-ssa translation | 901 any variables that are live. Otherwise the out-of-ssa translation |
878 may create incorrect code. */ | 902 may create incorrect code. */ |
879 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | 903 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
880 { | 904 { |
881 gimple phi = gsi_stmt (gsi); | 905 gimple phi = gsi_stmt (gsi); |
882 tree result = PHI_RESULT (phi); | 906 tree result = PHI_RESULT (phi); |
906 fprintf (f, "%s", str3); | 930 fprintf (f, "%s", str3); |
907 } | 931 } |
908 | 932 |
909 | 933 |
910 /* Called if a coalesce across and abnormal edge cannot be performed. PHI is | 934 /* Called if a coalesce across and abnormal edge cannot be performed. PHI is |
911 the phi node at fault, I is the argument index at fault. A message is | 935 the phi node at fault, I is the argument index at fault. A message is |
912 printed and compilation is then terminated. */ | 936 printed and compilation is then terminated. */ |
913 | 937 |
914 static inline void | 938 static inline void |
915 abnormal_corrupt (gimple phi, int i) | 939 abnormal_corrupt (gimple phi, int i) |
916 { | 940 { |
972 | 996 |
973 used_in_real_ops = BITMAP_ALLOC (NULL); | 997 used_in_real_ops = BITMAP_ALLOC (NULL); |
974 used_in_virtual_ops = BITMAP_ALLOC (NULL); | 998 used_in_virtual_ops = BITMAP_ALLOC (NULL); |
975 #endif | 999 #endif |
976 | 1000 |
977 map = init_var_map (num_ssa_names + 1); | 1001 map = init_var_map (num_ssa_names); |
978 | 1002 |
979 FOR_EACH_BB (bb) | 1003 FOR_EACH_BB (bb) |
980 { | 1004 { |
981 tree arg; | 1005 tree arg; |
982 | 1006 |
990 | 1014 |
991 res = gimple_phi_result (phi); | 1015 res = gimple_phi_result (phi); |
992 ver = SSA_NAME_VERSION (res); | 1016 ver = SSA_NAME_VERSION (res); |
993 register_ssa_partition (map, res); | 1017 register_ssa_partition (map, res); |
994 | 1018 |
995 /* Register ssa_names and coalesces between the args and the result | 1019 /* Register ssa_names and coalesces between the args and the result |
996 of all PHI. */ | 1020 of all PHI. */ |
997 for (i = 0; i < gimple_phi_num_args (phi); i++) | 1021 for (i = 0; i < gimple_phi_num_args (phi); i++) |
998 { | 1022 { |
999 edge e = gimple_phi_arg_edge (phi, i); | 1023 edge e = gimple_phi_arg_edge (phi, i); |
1000 arg = PHI_ARG_DEF (phi, i); | 1024 arg = PHI_ARG_DEF (phi, i); |
1001 if (TREE_CODE (arg) == SSA_NAME) | 1025 if (TREE_CODE (arg) == SSA_NAME) |
1002 register_ssa_partition (map, arg); | 1026 register_ssa_partition (map, arg); |
1003 if (TREE_CODE (arg) == SSA_NAME | 1027 if (TREE_CODE (arg) == SSA_NAME |
1004 && SSA_NAME_VAR (arg) == SSA_NAME_VAR (res)) | 1028 && SSA_NAME_VAR (arg) == SSA_NAME_VAR (res)) |
1005 { | 1029 { |
1006 saw_copy = true; | 1030 saw_copy = true; |
1007 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (arg)); | 1031 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (arg)); |
1008 if ((e->flags & EDGE_ABNORMAL) == 0) | 1032 if ((e->flags & EDGE_ABNORMAL) == 0) |
1024 | 1048 |
1025 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | 1049 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
1026 { | 1050 { |
1027 stmt = gsi_stmt (gsi); | 1051 stmt = gsi_stmt (gsi); |
1028 | 1052 |
1053 if (is_gimple_debug (stmt)) | |
1054 continue; | |
1055 | |
1029 /* Register USE and DEF operands in each statement. */ | 1056 /* Register USE and DEF operands in each statement. */ |
1030 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, (SSA_OP_DEF|SSA_OP_USE)) | 1057 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, (SSA_OP_DEF|SSA_OP_USE)) |
1031 register_ssa_partition (map, var); | 1058 register_ssa_partition (map, var); |
1032 | 1059 |
1033 /* Check for copy coalesces. */ | 1060 /* Check for copy coalesces. */ |
1091 v1 = SSA_NAME_VERSION (outputs[match]); | 1118 v1 = SSA_NAME_VERSION (outputs[match]); |
1092 v2 = SSA_NAME_VERSION (input); | 1119 v2 = SSA_NAME_VERSION (input); |
1093 | 1120 |
1094 if (SSA_NAME_VAR (outputs[match]) == SSA_NAME_VAR (input)) | 1121 if (SSA_NAME_VAR (outputs[match]) == SSA_NAME_VAR (input)) |
1095 { | 1122 { |
1096 cost = coalesce_cost (REG_BR_PROB_BASE, | 1123 cost = coalesce_cost (REG_BR_PROB_BASE, |
1097 optimize_bb_for_size_p (bb), | 1124 optimize_bb_for_size_p (bb)); |
1098 false); | |
1099 add_coalesce (cl, v1, v2, cost); | 1125 add_coalesce (cl, v1, v2, cost); |
1100 bitmap_set_bit (used_in_copy, v1); | 1126 bitmap_set_bit (used_in_copy, v1); |
1101 bitmap_set_bit (used_in_copy, v2); | 1127 bitmap_set_bit (used_in_copy, v2); |
1102 } | 1128 } |
1103 } | 1129 } |
1105 } | 1131 } |
1106 | 1132 |
1107 default: | 1133 default: |
1108 break; | 1134 break; |
1109 } | 1135 } |
1110 | 1136 |
1111 #ifdef ENABLE_CHECKING | 1137 #ifdef ENABLE_CHECKING |
1112 /* Mark real uses and defs. */ | 1138 /* Mark real uses and defs. */ |
1113 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, (SSA_OP_DEF|SSA_OP_USE)) | 1139 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, (SSA_OP_DEF|SSA_OP_USE)) |
1114 bitmap_set_bit (used_in_real_ops, DECL_UID (SSA_NAME_VAR (var))); | 1140 bitmap_set_bit (used_in_real_ops, DECL_UID (SSA_NAME_VAR (var))); |
1115 | 1141 |
1116 /* Validate that virtual ops don't get used in funny ways. */ | 1142 /* Validate that virtual ops don't get used in funny ways. */ |
1117 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_ALL_VIRTUALS) | 1143 if (gimple_vuse (stmt)) |
1118 { | 1144 bitmap_set_bit (used_in_virtual_ops, |
1119 bitmap_set_bit (used_in_virtual_ops, | 1145 DECL_UID (SSA_NAME_VAR (gimple_vuse (stmt)))); |
1120 DECL_UID (SSA_NAME_VAR (var))); | |
1121 } | |
1122 | |
1123 #endif /* ENABLE_CHECKING */ | 1146 #endif /* ENABLE_CHECKING */ |
1124 } | 1147 } |
1125 } | 1148 } |
1126 | 1149 |
1127 /* Now process result decls and live on entry variables for entry into | 1150 /* Now process result decls and live on entry variables for entry into |
1128 the coalesce list. */ | 1151 the coalesce list. */ |
1129 first = NULL_TREE; | 1152 first = NULL_TREE; |
1130 for (i = 1; i < num_ssa_names; i++) | 1153 for (i = 1; i < num_ssa_names; i++) |
1131 { | 1154 { |
1132 var = map->partition_to_var[i]; | 1155 var = ssa_name (i); |
1133 if (var != NULL_TREE) | 1156 if (var != NULL_TREE && is_gimple_reg (var)) |
1134 { | 1157 { |
1135 /* Add coalesces between all the result decls. */ | 1158 /* Add coalesces between all the result decls. */ |
1136 if (TREE_CODE (SSA_NAME_VAR (var)) == RESULT_DECL) | 1159 if (TREE_CODE (SSA_NAME_VAR (var)) == RESULT_DECL) |
1137 { | 1160 { |
1138 if (first == NULL_TREE) | 1161 if (first == NULL_TREE) |
1149 } | 1172 } |
1150 } | 1173 } |
1151 /* Mark any default_def variables as being in the coalesce list | 1174 /* Mark any default_def variables as being in the coalesce list |
1152 since they will have to be coalesced with the base variable. If | 1175 since they will have to be coalesced with the base variable. If |
1153 not marked as present, they won't be in the coalesce view. */ | 1176 not marked as present, they won't be in the coalesce view. */ |
1154 if (gimple_default_def (cfun, SSA_NAME_VAR (var)) == var) | 1177 if (gimple_default_def (cfun, SSA_NAME_VAR (var)) == var |
1178 && !has_zero_uses (var)) | |
1155 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (var)); | 1179 bitmap_set_bit (used_in_copy, SSA_NAME_VERSION (var)); |
1156 } | 1180 } |
1157 } | 1181 } |
1158 | 1182 |
1159 #if defined ENABLE_CHECKING | 1183 #if defined ENABLE_CHECKING |
1202 print_generic_expr (debug, partition_to_var (map, p1), TDF_SLIM); | 1226 print_generic_expr (debug, partition_to_var (map, p1), TDF_SLIM); |
1203 fprintf (debug, " & (%d)", y); | 1227 fprintf (debug, " & (%d)", y); |
1204 print_generic_expr (debug, partition_to_var (map, p2), TDF_SLIM); | 1228 print_generic_expr (debug, partition_to_var (map, p2), TDF_SLIM); |
1205 } | 1229 } |
1206 | 1230 |
1207 if (p1 == p2) | 1231 if (p1 == p2) |
1208 { | 1232 { |
1209 if (debug) | 1233 if (debug) |
1210 fprintf (debug, ": Already Coalesced.\n"); | 1234 fprintf (debug, ": Already Coalesced.\n"); |
1211 return true; | 1235 return true; |
1212 } | 1236 } |
1225 if (debug) | 1249 if (debug) |
1226 fprintf (debug, ": Unable to perform partition union.\n"); | 1250 fprintf (debug, ": Unable to perform partition union.\n"); |
1227 return false; | 1251 return false; |
1228 } | 1252 } |
1229 | 1253 |
1230 /* z is the new combined partition. Remove the other partition from | 1254 /* z is the new combined partition. Remove the other partition from |
1231 the list, and merge the conflicts. */ | 1255 the list, and merge the conflicts. */ |
1232 if (z == p1) | 1256 if (z == p1) |
1233 ssa_conflicts_merge (graph, p1, p2); | 1257 ssa_conflicts_merge (graph, p1, p2); |
1234 else | 1258 else |
1235 ssa_conflicts_merge (graph, p2, p1); | 1259 ssa_conflicts_merge (graph, p2, p1); |
1244 | 1268 |
1245 return false; | 1269 return false; |
1246 } | 1270 } |
1247 | 1271 |
1248 | 1272 |
1249 /* Attempt to Coalesce partitions in MAP which occur in the list CL using | 1273 /* Attempt to Coalesce partitions in MAP which occur in the list CL using |
1250 GRAPH. Debug output is sent to DEBUG if it is non-NULL. */ | 1274 GRAPH. Debug output is sent to DEBUG if it is non-NULL. */ |
1251 | 1275 |
1252 static void | 1276 static void |
1253 coalesce_partitions (var_map map, ssa_conflicts_p graph, coalesce_list_p cl, | 1277 coalesce_partitions (var_map map, ssa_conflicts_p graph, coalesce_list_p cl, |
1254 FILE *debug) | 1278 FILE *debug) |
1255 { | 1279 { |
1256 int x = 0, y = 0; | 1280 int x = 0, y = 0; |
1257 tree var1, var2; | 1281 tree var1, var2; |
1258 int cost; | 1282 int cost; |
1259 basic_block bb; | 1283 basic_block bb; |
1260 edge e; | 1284 edge e; |
1261 edge_iterator ei; | 1285 edge_iterator ei; |
1262 | 1286 |
1263 /* First, coalesce all the copies across abnormal edges. These are not placed | 1287 /* First, coalesce all the copies across abnormal edges. These are not placed |
1264 in the coalesce list because they do not need to be sorted, and simply | 1288 in the coalesce list because they do not need to be sorted, and simply |
1265 consume extra memory/compilation time in large programs. */ | 1289 consume extra memory/compilation time in large programs. */ |
1266 | 1290 |
1267 FOR_EACH_BB (bb) | 1291 FOR_EACH_BB (bb) |
1268 { | 1292 { |
1269 FOR_EACH_EDGE (e, ei, bb->preds) | 1293 FOR_EACH_EDGE (e, ei, bb->preds) |
1330 a partition map with the resulting coalesces. */ | 1354 a partition map with the resulting coalesces. */ |
1331 | 1355 |
1332 extern var_map | 1356 extern var_map |
1333 coalesce_ssa_name (void) | 1357 coalesce_ssa_name (void) |
1334 { | 1358 { |
1335 unsigned num, x; | |
1336 tree_live_info_p liveinfo; | 1359 tree_live_info_p liveinfo; |
1337 ssa_conflicts_p graph; | 1360 ssa_conflicts_p graph; |
1338 coalesce_list_p cl; | 1361 coalesce_list_p cl; |
1339 bitmap used_in_copies = BITMAP_ALLOC (NULL); | 1362 bitmap used_in_copies = BITMAP_ALLOC (NULL); |
1340 var_map map; | 1363 var_map map; |
1352 eq_ssa_name_by_var, NULL); | 1375 eq_ssa_name_by_var, NULL); |
1353 for (i = 1; i < num_ssa_names; i++) | 1376 for (i = 1; i < num_ssa_names; i++) |
1354 { | 1377 { |
1355 tree a = ssa_name (i); | 1378 tree a = ssa_name (i); |
1356 | 1379 |
1357 if (a && SSA_NAME_VAR (a) && !DECL_ARTIFICIAL (SSA_NAME_VAR (a))) | 1380 if (a |
1381 && SSA_NAME_VAR (a) | |
1382 && !DECL_ARTIFICIAL (SSA_NAME_VAR (a)) | |
1383 && (!has_zero_uses (a) || !SSA_NAME_IS_DEFAULT_DEF (a))) | |
1358 { | 1384 { |
1359 tree *slot = (tree *) htab_find_slot (ssa_name_hash, a, INSERT); | 1385 tree *slot = (tree *) htab_find_slot (ssa_name_hash, a, INSERT); |
1360 | 1386 |
1361 if (!*slot) | 1387 if (!*slot) |
1362 *slot = a; | 1388 *slot = a; |
1404 { | 1430 { |
1405 fprintf (dump_file, "\nAfter sorting:\n"); | 1431 fprintf (dump_file, "\nAfter sorting:\n"); |
1406 dump_coalesce_list (dump_file, cl); | 1432 dump_coalesce_list (dump_file, cl); |
1407 } | 1433 } |
1408 | 1434 |
1409 /* First, coalesce all live on entry variables to their base variable. | 1435 /* First, coalesce all live on entry variables to their base variable. |
1410 This will ensure the first use is coming from the correct location. */ | 1436 This will ensure the first use is coming from the correct location. */ |
1411 | |
1412 num = num_var_partitions (map); | |
1413 for (x = 0 ; x < num; x++) | |
1414 { | |
1415 tree var = partition_to_var (map, x); | |
1416 tree root; | |
1417 | |
1418 if (TREE_CODE (var) != SSA_NAME) | |
1419 continue; | |
1420 | |
1421 root = SSA_NAME_VAR (var); | |
1422 if (gimple_default_def (cfun, root) == var) | |
1423 { | |
1424 /* This root variable should have not already been assigned | |
1425 to another partition which is not coalesced with this one. */ | |
1426 gcc_assert (!var_ann (root)->out_of_ssa_tag); | |
1427 | |
1428 if (dump_file && (dump_flags & TDF_DETAILS)) | |
1429 { | |
1430 print_exprs (dump_file, "Must coalesce ", var, | |
1431 " with the root variable ", root, ".\n"); | |
1432 } | |
1433 change_partition_var (map, root, x); | |
1434 } | |
1435 } | |
1436 | 1437 |
1437 if (dump_file && (dump_flags & TDF_DETAILS)) | 1438 if (dump_file && (dump_flags & TDF_DETAILS)) |
1438 dump_var_map (dump_file, map); | 1439 dump_var_map (dump_file, map); |
1439 | 1440 |
1440 /* Now coalesce everything in the list. */ | 1441 /* Now coalesce everything in the list. */ |
1441 coalesce_partitions (map, graph, cl, | 1442 coalesce_partitions (map, graph, cl, |
1442 ((dump_flags & TDF_DETAILS) ? dump_file | 1443 ((dump_flags & TDF_DETAILS) ? dump_file |
1443 : NULL)); | 1444 : NULL)); |
1444 | 1445 |
1445 delete_coalesce_list (cl); | 1446 delete_coalesce_list (cl); |
1446 ssa_conflicts_delete (graph); | 1447 ssa_conflicts_delete (graph); |