Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa-ter.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 | 34 |
35 | 35 |
36 /* Temporary Expression Replacement (TER) | 36 /* Temporary Expression Replacement (TER) |
37 | 37 |
38 Replace SSA version variables during out-of-ssa with their defining | 38 Replace SSA version variables during out-of-ssa with their defining |
39 expression if there is only one use of the variable. | 39 expression if there is only one use of the variable. |
40 | 40 |
41 This pass is required in order for the RTL expansion pass to see larger | 41 This pass is required in order for the RTL expansion pass to see larger |
42 chunks of code. This allows it to make better choices on RTL pattern | 42 chunks of code. This allows it to make better choices on RTL pattern |
43 selection. When expand is rewritten and merged with out-of-ssa, and | 43 selection. When expand is rewritten and merged with out-of-ssa, and |
44 understands SSA, this should be eliminated. | 44 understands SSA, this should be eliminated. |
45 | 45 |
46 A pass is made through the function, one block at a time. No cross block | 46 A pass is made through the function, one block at a time. No cross block |
47 information is tracked. | 47 information is tracked. |
48 | 48 |
49 Variables which only have one use, and whose defining stmt is considered | 49 Variables which only have one use, and whose defining stmt is considered |
50 a replaceable expression (see is_replaceable_p) are tracked to see whether | 50 a replaceable expression (see is_replaceable_p) are tracked to see whether |
51 they can be replaced at their use location. | 51 they can be replaced at their use location. |
52 | 52 |
53 n_12 = C * 10 | 53 n_12 = C * 10 |
54 a_2 = b_5 + 6 | 54 a_2 = b_5 + 6 |
55 v_9 = a_2 * n_12 | 55 v_9 = a_2 * n_12 |
56 | 56 |
57 if there are the only use of n_12 and a_2, TER will substitute in their | 57 if there are the only use of n_12 and a_2, TER will substitute in their |
62 which will then have the ssa_name assigned to regular variables, and the | 62 which will then have the ssa_name assigned to regular variables, and the |
63 resulting code which will be passed to the expander looks something like: | 63 resulting code which will be passed to the expander looks something like: |
64 | 64 |
65 v = (b + 6) * (C * 10) | 65 v = (b + 6) * (C * 10) |
66 | 66 |
67 | 67 |
68 This requires ensuring that none of the variables used by the expression | 68 This requires ensuring that none of the variables used by the expression |
69 change between the def point and where it is used. Furthermore, if any | 69 change between the def point and where it is used. Furthermore, if any |
70 of the ssa_names used in this expression are themselves replaceable, we | 70 of the ssa_names used in this expression are themselves replaceable, we |
71 have to ensure none of that expressions' arguments change either. | 71 have to ensure none of that expressions' arguments change either. |
72 Although SSA_NAMES themselves don't change, this pass is performed after | 72 Although SSA_NAMES themselves don't change, this pass is performed after |
73 coalescing has coalesced different SSA_NAMES together, so there could be a | 73 coalescing has coalesced different SSA_NAMES together, so there could be a |
74 definition of an SSA_NAME which is coalesced with a use that causes a | 74 definition of an SSA_NAME which is coalesced with a use that causes a |
75 problem, i.e., | 75 problem, i.e., |
76 | 76 |
77 PHI b_5 = <b_8(2), b_14(1)> | 77 PHI b_5 = <b_8(2), b_14(1)> |
78 <...> | 78 <...> |
79 a_2 = b_5 + 6 | 79 a_2 = b_5 + 6 |
80 b_8 = c_4 + 4 | 80 b_8 = c_4 + 4 |
81 v_9 = a_2 * n_12 | 81 v_9 = a_2 * n_12 |
83 | 83 |
84 If b_5, b_8 and b_14 are all coalesced together... | 84 If b_5, b_8 and b_14 are all coalesced together... |
85 The expression b_5 + 6 CANNOT replace the use in the statement defining v_9 | 85 The expression b_5 + 6 CANNOT replace the use in the statement defining v_9 |
86 because b_8 is in fact killing the value of b_5 since they share a partition | 86 because b_8 is in fact killing the value of b_5 since they share a partition |
87 and will be assigned the same memory or register location. | 87 and will be assigned the same memory or register location. |
88 | 88 |
89 TER implements this but stepping through the instructions in a block and | 89 TER implements this but stepping through the instructions in a block and |
90 tracking potential expressions for replacement, and the partitions they are | 90 tracking potential expressions for replacement, and the partitions they are |
91 dependent on. Expressions are represented by the SSA_NAME_VERSION of the | 91 dependent on. Expressions are represented by the SSA_NAME_VERSION of the |
92 DEF on the LHS of a GIMPLE_ASSIGN and the expression is the RHS. | 92 DEF on the LHS of a GIMPLE_ASSIGN and the expression is the RHS. |
93 | 93 |
94 When a stmt is determined to be a possible replacement expression, the | 94 When a stmt is determined to be a possible replacement expression, the |
95 following steps are taken: | 95 following steps are taken: |
96 | 96 |
97 EXPR_DECL_UID bitmap is allocated and set to the base variable UID of the | 97 EXPR_DECL_UID bitmap is allocated and set to the base variable UID of the |
98 def and any uses in the expression. non-NULL means the expression is being | 98 def and any uses in the expression. non-NULL means the expression is being |
99 tracked. The UID's themselves are used to prevent TER substitution into | 99 tracked. The UID's themselves are used to prevent TER substitution into |
100 accumulating sequences, i.e., | 100 accumulating sequences, i.e., |
101 | 101 |
102 x = x + y | 102 x = x + y |
103 x = x + z | 103 x = x + z |
104 x = x + w | 104 x = x + w |
105 etc. | 105 etc. |
106 this can result in very large expressions which don't accomplish anything | 106 this can result in very large expressions which don't accomplish anything |
107 see PR tree-optimization/17549. | 107 see PR tree-optimization/17549. |
108 | 108 |
109 PARTITION_DEPENDENCIES is another bitmap array, and it has a bit set for any | 109 PARTITION_DEPENDENCIES is another bitmap array, and it has a bit set for any |
110 partition which is used in the expression. This is primarily used to remove | 110 partition which is used in the expression. This is primarily used to remove |
111 an expression from the partition kill lists when a decision is made whether | 111 an expression from the partition kill lists when a decision is made whether |
112 to replace it or not. This is indexed by ssa version number as well, and | 112 to replace it or not. This is indexed by ssa version number as well, and |
113 indicates a partition number. virtual operands are not tracked individually, | 113 indicates a partition number. virtual operands are not tracked individually, |
114 but they are summarized by an artificial partition called VIRTUAL_PARTITION. | 114 but they are summarized by an artificial partition called VIRTUAL_PARTITION. |
115 This means a MAY or MUST def will kill *ALL* expressions that are dependent | 115 This means a MAY or MUST def will kill *ALL* expressions that are dependent |
116 on a virtual operand. | 116 on a virtual operand. |
117 Note that the EXPR_DECL_UID and this bitmap represent very similar | 117 Note that the EXPR_DECL_UID and this bitmap represent very similar |
118 information, but the info in one is not easy to obtain from the other. | 118 information, but the info in one is not easy to obtain from the other. |
119 | 119 |
120 KILL_LIST is yet another bitmap array, this time it is indexed by partition | 120 KILL_LIST is yet another bitmap array, this time it is indexed by partition |
121 number, and represents a list of active expressions which will will no | 121 number, and represents a list of active expressions which will will no |
122 longer be valid if a definition into this partition takes place. | 122 longer be valid if a definition into this partition takes place. |
123 | 123 |
124 PARTITION_IN_USE is simply a bitmap which is used to track which partitions | 124 PARTITION_IN_USE is simply a bitmap which is used to track which partitions |
125 currently have something in their kill list. This is used at the end of | 125 currently have something in their kill list. This is used at the end of |
126 a block to clear out the KILL_LIST bitmaps at the end of each block. | 126 a block to clear out the KILL_LIST bitmaps at the end of each block. |
127 | 127 |
128 NEW_REPLACEABLE_DEPENDENCIES is used as a temporary place to store | 128 NEW_REPLACEABLE_DEPENDENCIES is used as a temporary place to store |
129 dependencies which will be reused by the current definition. All the uses | 129 dependencies which will be reused by the current definition. All the uses |
130 on an expression are processed before anything else is done. If a use is | 130 on an expression are processed before anything else is done. If a use is |
131 determined to be a replaceable expression AND the current stmt is also going | 131 determined to be a replaceable expression AND the current stmt is also going |
132 to be replaceable, all the dependencies of this replaceable use will be | 132 to be replaceable, all the dependencies of this replaceable use will be |
133 picked up by the current stmt's expression. Rather than recreate them, they | 133 picked up by the current stmt's expression. Rather than recreate them, they |
135 processed. | 135 processed. |
136 | 136 |
137 a_2 = b_5 + 6 | 137 a_2 = b_5 + 6 |
138 v_8 = a_2 + c_4 | 138 v_8 = a_2 + c_4 |
139 | 139 |
140 a_2's expression 'b_5 + 6' is determined to be replaceable at the use | 140 a_2's expression 'b_5 + 6' is determined to be replaceable at the use |
141 location. It is dependent on the partition 'b_5' is in. This is cached into | 141 location. It is dependent on the partition 'b_5' is in. This is cached into |
142 the NEW_REPLACEABLE_DEPENDENCIES bitmap, and when v_8 is examined for | 142 the NEW_REPLACEABLE_DEPENDENCIES bitmap, and when v_8 is examined for |
143 replaceability, it is a candidate, and it is dependent on the partition | 143 replaceability, it is a candidate, and it is dependent on the partition |
144 b_5 is in *NOT* a_2, as well as c_4's partition. | 144 b_5 is in *NOT* a_2, as well as c_4's partition. |
145 | 145 |
146 if v_8 is also replaceable: | 146 if v_8 is also replaceable: |
147 | 147 |
148 x_9 = v_8 * 5 | 148 x_9 = v_8 * 5 |
149 | 149 |
150 x_9 is dependent on partitions b_5, and c_4 | 150 x_9 is dependent on partitions b_5, and c_4 |
151 | 151 |
152 if a statement is found which has either of those partitions written to | 152 if a statement is found which has either of those partitions written to |
153 before x_9 is used, then x_9 itself is NOT replaceable. */ | 153 before x_9 is used, then x_9 itself is NOT replaceable. */ |
154 | 154 |
155 | 155 |
156 /* Temporary Expression Replacement (TER) table information. */ | 156 /* Temporary Expression Replacement (TER) table information. */ |
157 | 157 |
158 typedef struct temp_expr_table_d | 158 typedef struct temp_expr_table_d |
159 { | 159 { |
160 var_map map; | 160 var_map map; |
161 bitmap *partition_dependencies; /* Partitions expr is dependent on. */ | 161 bitmap *partition_dependencies; /* Partitions expr is dependent on. */ |
162 gimple *replaceable_expressions; /* Replacement expression table. */ | 162 bitmap replaceable_expressions; /* Replacement expression table. */ |
163 bitmap *expr_decl_uids; /* Base uids of exprs. */ | 163 bitmap *expr_decl_uids; /* Base uids of exprs. */ |
164 bitmap *kill_list; /* Expr's killed by a partition. */ | 164 bitmap *kill_list; /* Expr's killed by a partition. */ |
165 int virtual_partition; /* Pseudo partition for virtual ops. */ | 165 int virtual_partition; /* Pseudo partition for virtual ops. */ |
166 bitmap partition_in_use; /* Partitions with kill entries. */ | 166 bitmap partition_in_use; /* Partitions with kill entries. */ |
167 bitmap new_replaceable_dependencies; /* Holding place for pending dep's. */ | 167 bitmap new_replaceable_dependencies; /* Holding place for pending dep's. */ |
211 | 211 |
212 return t; | 212 return t; |
213 } | 213 } |
214 | 214 |
215 | 215 |
216 /* Free TER table T. If there are valid replacements, return the expression | 216 /* Free TER table T. If there are valid replacements, return the expression |
217 vector. */ | 217 vector. */ |
218 | 218 |
219 static gimple * | 219 static bitmap |
220 free_temp_expr_table (temp_expr_table_p t) | 220 free_temp_expr_table (temp_expr_table_p t) |
221 { | 221 { |
222 gimple *ret = NULL; | 222 bitmap ret = NULL; |
223 | 223 |
224 #ifdef ENABLE_CHECKING | 224 #ifdef ENABLE_CHECKING |
225 unsigned x; | 225 unsigned x; |
226 for (x = 0; x <= num_var_partitions (t->map); x++) | 226 for (x = 0; x <= num_var_partitions (t->map); x++) |
227 gcc_assert (!t->kill_list[x]); | 227 gcc_assert (!t->kill_list[x]); |
228 for (x = 0; x < num_ssa_names + 1; x++) | 228 for (x = 0; x < num_ssa_names; x++) |
229 { | 229 { |
230 gcc_assert (t->expr_decl_uids[x] == NULL); | 230 gcc_assert (t->expr_decl_uids[x] == NULL); |
231 gcc_assert (t->partition_dependencies[x] == NULL); | 231 gcc_assert (t->partition_dependencies[x] == NULL); |
232 } | 232 } |
233 #endif | 233 #endif |
253 static inline bool | 253 static inline bool |
254 version_to_be_replaced_p (temp_expr_table_p tab, int version) | 254 version_to_be_replaced_p (temp_expr_table_p tab, int version) |
255 { | 255 { |
256 if (!tab->replaceable_expressions) | 256 if (!tab->replaceable_expressions) |
257 return false; | 257 return false; |
258 return tab->replaceable_expressions[version] != NULL; | 258 return bitmap_bit_p (tab->replaceable_expressions, version); |
259 } | 259 } |
260 | 260 |
261 | 261 |
262 /* Add partition P to the list if partitions VERSION is dependent on. TAB is | 262 /* Add partition P to the list if partitions VERSION is dependent on. TAB is |
263 the expression table */ | 263 the expression table */ |
264 | 264 |
265 static inline void | 265 static inline void |
266 make_dependent_on_partition (temp_expr_table_p tab, int version, int p) | 266 make_dependent_on_partition (temp_expr_table_p tab, int version, int p) |
267 { | 267 { |
284 } | 284 } |
285 bitmap_set_bit (tab->kill_list[p], ver); | 285 bitmap_set_bit (tab->kill_list[p], ver); |
286 } | 286 } |
287 | 287 |
288 | 288 |
289 /* Remove VER from the partition kill list for P. TAB is the expression | 289 /* Remove VER from the partition kill list for P. TAB is the expression |
290 table. */ | 290 table. */ |
291 | 291 |
292 static inline void | 292 static inline void |
293 remove_from_partition_kill_list (temp_expr_table_p tab, int p, int version) | 293 remove_from_partition_kill_list (temp_expr_table_p tab, int p, int version) |
294 { | 294 { |
295 #ifdef ENABLE_CHECKING | 295 #ifdef ENABLE_CHECKING |
296 gcc_assert (tab->kill_list[p]); | 296 gcc_assert (tab->kill_list[p]); |
297 #endif | 297 #endif |
302 BITMAP_FREE (tab->kill_list[p]); | 302 BITMAP_FREE (tab->kill_list[p]); |
303 } | 303 } |
304 } | 304 } |
305 | 305 |
306 | 306 |
307 /* Add a dependency between the def of ssa VERSION and VAR. If VAR is | 307 /* Add a dependency between the def of ssa VERSION and VAR. If VAR is |
308 replaceable by an expression, add a dependence each of the elements of the | 308 replaceable by an expression, add a dependence each of the elements of the |
309 expression. These are contained in the new_replaceable list. TAB is the | 309 expression. These are contained in the new_replaceable list. TAB is the |
310 expression table. */ | 310 expression table. */ |
311 | 311 |
312 static void | 312 static void |
313 add_dependence (temp_expr_table_p tab, int version, tree var) | 313 add_dependence (temp_expr_table_p tab, int version, tree var) |
319 i = SSA_NAME_VERSION (var); | 319 i = SSA_NAME_VERSION (var); |
320 if (version_to_be_replaced_p (tab, i)) | 320 if (version_to_be_replaced_p (tab, i)) |
321 { | 321 { |
322 if (!bitmap_empty_p (tab->new_replaceable_dependencies)) | 322 if (!bitmap_empty_p (tab->new_replaceable_dependencies)) |
323 { | 323 { |
324 /* Version will now be killed by a write to any partition the | 324 /* Version will now be killed by a write to any partition the |
325 substituted expression would have been killed by. */ | 325 substituted expression would have been killed by. */ |
326 EXECUTE_IF_SET_IN_BITMAP (tab->new_replaceable_dependencies, 0, x, bi) | 326 EXECUTE_IF_SET_IN_BITMAP (tab->new_replaceable_dependencies, 0, x, bi) |
327 add_to_partition_kill_list (tab, x, version); | 327 add_to_partition_kill_list (tab, x, version); |
328 | 328 |
329 /* Rather than set partition_dependencies and in_use lists bit by | 329 /* Rather than set partition_dependencies and in_use lists bit by |
330 bit, simply OR in the new_replaceable_dependencies bits. */ | 330 bit, simply OR in the new_replaceable_dependencies bits. */ |
331 if (!tab->partition_dependencies[version]) | 331 if (!tab->partition_dependencies[version]) |
332 tab->partition_dependencies[version] = BITMAP_ALLOC (NULL); | 332 tab->partition_dependencies[version] = BITMAP_ALLOC (NULL); |
333 bitmap_ior_into (tab->partition_dependencies[version], | 333 bitmap_ior_into (tab->partition_dependencies[version], |
334 tab->new_replaceable_dependencies); | 334 tab->new_replaceable_dependencies); |
335 bitmap_ior_into (tab->partition_in_use, | 335 bitmap_ior_into (tab->partition_in_use, |
336 tab->new_replaceable_dependencies); | 336 tab->new_replaceable_dependencies); |
337 /* It is only necessary to add these once. */ | 337 /* It is only necessary to add these once. */ |
338 bitmap_clear (tab->new_replaceable_dependencies); | 338 bitmap_clear (tab->new_replaceable_dependencies); |
339 } | 339 } |
340 } | 340 } |
410 /* Used in this block, but at the TOP of the block, not the end. */ | 410 /* Used in this block, but at the TOP of the block, not the end. */ |
411 if (gimple_code (use_stmt) == GIMPLE_PHI) | 411 if (gimple_code (use_stmt) == GIMPLE_PHI) |
412 return false; | 412 return false; |
413 | 413 |
414 /* There must be no VDEFs. */ | 414 /* There must be no VDEFs. */ |
415 if (!(ZERO_SSA_OPERANDS (stmt, SSA_OP_VDEF))) | 415 if (gimple_vdef (stmt)) |
416 return false; | 416 return false; |
417 | 417 |
418 /* Without alias info we can't move around loads. */ | 418 /* Without alias info we can't move around loads. */ |
419 if (gimple_references_memory_p (stmt) && !optimize) | 419 if (gimple_references_memory_p (stmt) && !optimize) |
420 return false; | 420 return false; |
421 | 421 |
422 /* Float expressions must go through memory if float-store is on. */ | 422 /* Float expressions must go through memory if float-store is on. */ |
423 if (flag_float_store | 423 if (flag_float_store |
424 && FLOAT_TYPE_P (gimple_expr_type (stmt))) | 424 && FLOAT_TYPE_P (gimple_expr_type (stmt))) |
425 return false; | 425 return false; |
426 | 426 |
427 /* An assignment with a register variable on the RHS is not | 427 /* An assignment with a register variable on the RHS is not |
428 replaceable. */ | 428 replaceable. */ |
440 | 440 |
441 return true; | 441 return true; |
442 } | 442 } |
443 | 443 |
444 | 444 |
445 /* This function will remove the expression for VERSION from replacement | 445 /* This function will remove the expression for VERSION from replacement |
446 consideration in table TAB. If FREE_EXPR is true, then remove the | 446 consideration in table TAB. If FREE_EXPR is true, then remove the |
447 expression from consideration as well by freeing the decl uid bitmap. */ | 447 expression from consideration as well by freeing the decl uid bitmap. */ |
448 | 448 |
449 static void | 449 static void |
450 finished_with_expr (temp_expr_table_p tab, int version, bool free_expr) | 450 finished_with_expr (temp_expr_table_p tab, int version, bool free_expr) |
451 { | 451 { |
465 } | 465 } |
466 | 466 |
467 | 467 |
468 /* Create an expression entry for a replaceable expression. */ | 468 /* Create an expression entry for a replaceable expression. */ |
469 | 469 |
470 static void | 470 static void |
471 process_replaceable (temp_expr_table_p tab, gimple stmt) | 471 process_replaceable (temp_expr_table_p tab, gimple stmt) |
472 { | 472 { |
473 tree var, def, basevar; | 473 tree var, def, basevar; |
474 int version; | 474 int version; |
475 ssa_op_iter iter; | 475 ssa_op_iter iter; |
502 bitmap_set_bit (def_vars, DECL_UID (SSA_NAME_VAR (var))); | 502 bitmap_set_bit (def_vars, DECL_UID (SSA_NAME_VAR (var))); |
503 } | 503 } |
504 tab->expr_decl_uids[version] = def_vars; | 504 tab->expr_decl_uids[version] = def_vars; |
505 | 505 |
506 /* If there are VUSES, add a dependence on virtual defs. */ | 506 /* If there are VUSES, add a dependence on virtual defs. */ |
507 if (!ZERO_SSA_OPERANDS (stmt, SSA_OP_VUSE)) | 507 if (gimple_vuse (stmt)) |
508 { | 508 { |
509 make_dependent_on_partition (tab, version, VIRTUAL_PARTITION (tab)); | 509 make_dependent_on_partition (tab, version, VIRTUAL_PARTITION (tab)); |
510 add_to_partition_kill_list (tab, VIRTUAL_PARTITION (tab), version); | 510 add_to_partition_kill_list (tab, VIRTUAL_PARTITION (tab), version); |
511 } | 511 } |
512 } | 512 } |
518 static inline void | 518 static inline void |
519 kill_expr (temp_expr_table_p tab, int partition) | 519 kill_expr (temp_expr_table_p tab, int partition) |
520 { | 520 { |
521 unsigned version; | 521 unsigned version; |
522 | 522 |
523 /* Mark every active expr dependent on this var as not replaceable. | 523 /* Mark every active expr dependent on this var as not replaceable. |
524 finished_with_expr can modify the bitmap, so we can't execute over it. */ | 524 finished_with_expr can modify the bitmap, so we can't execute over it. */ |
525 while (tab->kill_list[partition]) | 525 while (tab->kill_list[partition]) |
526 { | 526 { |
527 version = bitmap_first_set_bit (tab->kill_list[partition]); | 527 version = bitmap_first_set_bit (tab->kill_list[partition]); |
528 finished_with_expr (tab, version, true); | 528 finished_with_expr (tab, version, true); |
532 gcc_assert (!tab->kill_list[partition]); | 532 gcc_assert (!tab->kill_list[partition]); |
533 #endif | 533 #endif |
534 } | 534 } |
535 | 535 |
536 | 536 |
537 /* This function kills all expressions in TAB which are dependent on virtual | 537 /* This function kills all expressions in TAB which are dependent on virtual |
538 partitions. */ | 538 partitions. */ |
539 | 539 |
540 static inline void | 540 static inline void |
541 kill_virtual_exprs (temp_expr_table_p tab) | 541 kill_virtual_exprs (temp_expr_table_p tab) |
542 { | 542 { |
553 { | 553 { |
554 int version = SSA_NAME_VERSION (var); | 554 int version = SSA_NAME_VERSION (var); |
555 | 555 |
556 /* Move the dependence list to the pending listpending. */ | 556 /* Move the dependence list to the pending listpending. */ |
557 if (more_replacing && tab->partition_dependencies[version]) | 557 if (more_replacing && tab->partition_dependencies[version]) |
558 bitmap_ior_into (tab->new_replaceable_dependencies, | 558 bitmap_ior_into (tab->new_replaceable_dependencies, |
559 tab->partition_dependencies[version]); | 559 tab->partition_dependencies[version]); |
560 | 560 |
561 finished_with_expr (tab, version, !more_replacing); | 561 finished_with_expr (tab, version, !more_replacing); |
562 | 562 |
563 /* Set the replaceable expression. */ | 563 /* Set the replaceable expression. */ |
564 if (!tab->replaceable_expressions) | 564 if (!tab->replaceable_expressions) |
565 tab->replaceable_expressions = XCNEWVEC (gimple, num_ssa_names + 1); | 565 tab->replaceable_expressions = BITMAP_ALLOC (NULL); |
566 tab->replaceable_expressions[version] = SSA_NAME_DEF_STMT (var); | 566 bitmap_set_bit (tab->replaceable_expressions, version); |
567 } | 567 } |
568 | 568 |
569 | 569 |
570 /* This function processes basic block BB, and looks for variables which can | 570 /* This function processes basic block BB, and looks for variables which can |
571 be replaced by their expressions. Results are stored in the table TAB. */ | 571 be replaced by their expressions. Results are stored in the table TAB. */ |
582 bool stmt_replaceable; | 582 bool stmt_replaceable; |
583 | 583 |
584 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi)) | 584 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi)) |
585 { | 585 { |
586 stmt = gsi_stmt (bsi); | 586 stmt = gsi_stmt (bsi); |
587 | |
588 if (is_gimple_debug (stmt)) | |
589 continue; | |
587 | 590 |
588 stmt_replaceable = is_replaceable_p (stmt); | 591 stmt_replaceable = is_replaceable_p (stmt); |
589 | 592 |
590 /* Determine if this stmt finishes an existing expression. */ | 593 /* Determine if this stmt finishes an existing expression. */ |
591 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE) | 594 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE) |
610 same_root_var = true; | 613 same_root_var = true; |
611 break; | 614 break; |
612 } | 615 } |
613 } | 616 } |
614 | 617 |
615 /* Mark expression as replaceable unless stmt is volatile or the | 618 /* Mark expression as replaceable unless stmt is volatile or the |
616 def variable has the same root variable as something in the | 619 def variable has the same root variable as something in the |
617 substitution list. */ | 620 substitution list. */ |
618 if (gimple_has_volatile_ops (stmt) || same_root_var) | 621 if (gimple_has_volatile_ops (stmt) || same_root_var) |
619 finished_with_expr (tab, ver, true); | 622 finished_with_expr (tab, ver, true); |
620 else | 623 else |
621 mark_replaceable (tab, use, stmt_replaceable); | 624 mark_replaceable (tab, use, stmt_replaceable); |
622 } | 625 } |
623 } | 626 } |
624 | 627 |
625 /* Next, see if this stmt kills off an active expression. */ | 628 /* Next, see if this stmt kills off an active expression. */ |
626 FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF) | 629 FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF) |
627 { | 630 { |
628 partition = var_to_partition (map, def); | 631 partition = var_to_partition (map, def); |
629 if (partition != NO_PARTITION && tab->kill_list[partition]) | 632 if (partition != NO_PARTITION && tab->kill_list[partition]) |
637 /* Free any unused dependency lists. */ | 640 /* Free any unused dependency lists. */ |
638 bitmap_clear (tab->new_replaceable_dependencies); | 641 bitmap_clear (tab->new_replaceable_dependencies); |
639 | 642 |
640 /* A V_{MAY,MUST}_DEF kills any expression using a virtual operand, | 643 /* A V_{MAY,MUST}_DEF kills any expression using a virtual operand, |
641 including the current stmt. */ | 644 including the current stmt. */ |
642 if (!ZERO_SSA_OPERANDS (stmt, SSA_OP_VIRTUAL_DEFS)) | 645 if (gimple_vdef (stmt)) |
643 kill_virtual_exprs (tab); | 646 kill_virtual_exprs (tab); |
644 } | 647 } |
645 } | 648 } |
646 | 649 |
647 | 650 |
648 /* This function is the driver routine for replacement of temporary expressions | 651 /* This function is the driver routine for replacement of temporary expressions |
649 in the SSA->normal phase, operating on MAP. If there are replaceable | 652 in the SSA->normal phase, operating on MAP. If there are replaceable |
650 expressions, a table is returned which maps SSA versions to the | 653 expressions, a table is returned which maps SSA versions to the |
651 expressions they should be replaced with. A NULL_TREE indicates no | 654 expressions they should be replaced with. A NULL_TREE indicates no |
652 replacement should take place. If there are no replacements at all, | 655 replacement should take place. If there are no replacements at all, |
653 NULL is returned by the function, otherwise an expression vector indexed | 656 NULL is returned by the function, otherwise an expression vector indexed |
654 by SSA_NAME version numbers. */ | 657 by SSA_NAME version numbers. */ |
655 | 658 |
656 extern gimple * | 659 extern bitmap |
657 find_replaceable_exprs (var_map map) | 660 find_replaceable_exprs (var_map map) |
658 { | 661 { |
659 basic_block bb; | 662 basic_block bb; |
660 temp_expr_table_p table; | 663 temp_expr_table_p table; |
661 gimple *ret; | 664 bitmap ret; |
662 | 665 |
663 table = new_temp_expr_table (map); | 666 table = new_temp_expr_table (map); |
664 FOR_EACH_BB (bb) | 667 FOR_EACH_BB (bb) |
665 { | 668 { |
666 find_replaceable_in_bb (table, bb); | 669 find_replaceable_in_bb (table, bb); |
669 #endif | 672 #endif |
670 } | 673 } |
671 | 674 |
672 ret = free_temp_expr_table (table); | 675 ret = free_temp_expr_table (table); |
673 return ret; | 676 return ret; |
674 } | 677 } |
675 | 678 |
676 /* Dump TER expression table EXPR to file F. */ | 679 /* Dump TER expression table EXPR to file F. */ |
677 | 680 |
678 void | 681 void |
679 dump_replaceable_exprs (FILE *f, gimple *expr) | 682 dump_replaceable_exprs (FILE *f, bitmap expr) |
680 { | 683 { |
681 tree var; | 684 tree var; |
682 unsigned x; | 685 unsigned x; |
683 | 686 |
684 fprintf (f, "\nReplacing Expressions\n"); | 687 fprintf (f, "\nReplacing Expressions\n"); |
685 for (x = 0; x < num_ssa_names; x++) | 688 for (x = 0; x < num_ssa_names; x++) |
686 if (expr[x]) | 689 if (bitmap_bit_p (expr, x)) |
687 { | 690 { |
688 var = ssa_name (x); | 691 var = ssa_name (x); |
689 print_generic_expr (f, var, TDF_SLIM); | 692 print_generic_expr (f, var, TDF_SLIM); |
690 fprintf (f, " replace with --> "); | 693 fprintf (f, " replace with --> "); |
691 print_gimple_stmt (f, expr[x], 0, TDF_SLIM); | 694 print_gimple_stmt (f, SSA_NAME_DEF_STMT (var), 0, TDF_SLIM); |
692 fprintf (f, "\n"); | 695 fprintf (f, "\n"); |
693 } | 696 } |
694 fprintf (f, "\n"); | 697 fprintf (f, "\n"); |
695 } | 698 } |
696 | 699 |
704 debug_ter (FILE *f, temp_expr_table_p t) | 707 debug_ter (FILE *f, temp_expr_table_p t) |
705 { | 708 { |
706 unsigned x, y; | 709 unsigned x, y; |
707 bitmap_iterator bi; | 710 bitmap_iterator bi; |
708 | 711 |
709 fprintf (f, "\nDumping current state of TER\n virtual partition = %d\n", | 712 fprintf (f, "\nDumping current state of TER\n virtual partition = %d\n", |
710 VIRTUAL_PARTITION (t)); | 713 VIRTUAL_PARTITION (t)); |
711 if (t->replaceable_expressions) | 714 if (t->replaceable_expressions) |
712 dump_replaceable_exprs (f, t->replaceable_expressions); | 715 dump_replaceable_exprs (f, t->replaceable_expressions); |
713 fprintf (f, "Currently tracking the following expressions:\n"); | 716 fprintf (f, "Currently tracking the following expressions:\n"); |
714 | 717 |
715 for (x = 1; x < num_ssa_names; x++) | 718 for (x = 1; x < num_ssa_names; x++) |
716 if (t->expr_decl_uids[x]) | 719 if (t->expr_decl_uids[x]) |
717 { | 720 { |
718 print_generic_expr (stderr, ssa_name (x), TDF_SLIM); | 721 print_generic_expr (stderr, ssa_name (x), TDF_SLIM); |
719 fprintf (f, " dep-parts : "); | 722 fprintf (f, " dep-parts : "); |
720 if (t->partition_dependencies[x] | 723 if (t->partition_dependencies[x] |
721 && !bitmap_empty_p (t->partition_dependencies[x])) | 724 && !bitmap_empty_p (t->partition_dependencies[x])) |
722 { | 725 { |
723 EXECUTE_IF_SET_IN_BITMAP (t->partition_dependencies[x], 0, y, bi) | 726 EXECUTE_IF_SET_IN_BITMAP (t->partition_dependencies[x], 0, y, bi) |
724 fprintf (f, "P%d ",y); | 727 fprintf (f, "P%d ",y); |
725 } | 728 } |
727 EXECUTE_IF_SET_IN_BITMAP (t->expr_decl_uids[x], 0, y, bi) | 730 EXECUTE_IF_SET_IN_BITMAP (t->expr_decl_uids[x], 0, y, bi) |
728 fprintf (f, "%d ",y); | 731 fprintf (f, "%d ",y); |
729 fprintf (stderr, "\n"); | 732 fprintf (stderr, "\n"); |
730 } | 733 } |
731 | 734 |
732 bitmap_print (f, t->partition_in_use, "Partitions in use ", | 735 bitmap_print (f, t->partition_in_use, "Partitions in use ", |
733 "\npartition KILL lists:\n"); | 736 "\npartition KILL lists:\n"); |
734 | 737 |
735 for (x = 0; x <= num_var_partitions (t->map); x++) | 738 for (x = 0; x <= num_var_partitions (t->map); x++) |
736 if (t->kill_list[x]) | 739 if (t->kill_list[x]) |
737 { | 740 { |