Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa-copy.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 |
---|---|
35 #include "tree-dump.h" | 35 #include "tree-dump.h" |
36 #include "tree-flow.h" | 36 #include "tree-flow.h" |
37 #include "tree-pass.h" | 37 #include "tree-pass.h" |
38 #include "tree-ssa-propagate.h" | 38 #include "tree-ssa-propagate.h" |
39 #include "langhooks.h" | 39 #include "langhooks.h" |
40 #include "cfgloop.h" | |
40 | 41 |
41 /* This file implements the copy propagation pass and provides a | 42 /* This file implements the copy propagation pass and provides a |
42 handful of interfaces for performing const/copy propagation and | 43 handful of interfaces for performing const/copy propagation and |
43 simple expression replacement which keep variable annotations | 44 simple expression replacement which keep variable annotations |
44 up-to-date. | 45 up-to-date. |
71 cannot be replaced. */ | 72 cannot be replaced. */ |
72 if (TREE_CODE (dest) == SSA_NAME | 73 if (TREE_CODE (dest) == SSA_NAME |
73 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest)) | 74 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest)) |
74 return false; | 75 return false; |
75 | 76 |
76 /* For memory partitions, copies are OK as long as the memory symbol | |
77 belongs to the partition. */ | |
78 if (TREE_CODE (dest) == SSA_NAME | |
79 && TREE_CODE (SSA_NAME_VAR (dest)) == MEMORY_PARTITION_TAG) | |
80 return (TREE_CODE (orig) == SSA_NAME | |
81 && !is_gimple_reg (orig) | |
82 && (SSA_NAME_VAR (dest) == SSA_NAME_VAR (orig) | |
83 || bitmap_bit_p (MPT_SYMBOLS (SSA_NAME_VAR (dest)), | |
84 DECL_UID (SSA_NAME_VAR (orig))))); | |
85 | |
86 if (TREE_CODE (orig) == SSA_NAME | |
87 && TREE_CODE (SSA_NAME_VAR (orig)) == MEMORY_PARTITION_TAG) | |
88 return (TREE_CODE (dest) == SSA_NAME | |
89 && !is_gimple_reg (dest) | |
90 && (SSA_NAME_VAR (dest) == SSA_NAME_VAR (orig) | |
91 || bitmap_bit_p (MPT_SYMBOLS (SSA_NAME_VAR (orig)), | |
92 DECL_UID (SSA_NAME_VAR (dest))))); | |
93 | |
94 /* Do not copy between types for which we *do* need a conversion. */ | 77 /* Do not copy between types for which we *do* need a conversion. */ |
95 if (!useless_type_conversion_p (type_d, type_o)) | 78 if (!useless_type_conversion_p (type_d, type_o)) |
96 return false; | 79 return false; |
97 | 80 |
98 /* FIXME. GIMPLE is allowing pointer assignments and comparisons of | 81 /* Propagating virtual operands is always ok. */ |
99 pointers that have different alias sets. This means that these | |
100 pointers will have different memory tags associated to them. | |
101 | |
102 If we allow copy propagation in these cases, statements de-referencing | |
103 the new pointer will now have a reference to a different memory tag | |
104 with potentially incorrect SSA information. | |
105 | |
106 This was showing up in libjava/java/util/zip/ZipFile.java with code | |
107 like: | |
108 | |
109 struct java.io.BufferedInputStream *T.660; | |
110 struct java.io.BufferedInputStream *T.647; | |
111 struct java.io.InputStream *is; | |
112 struct java.io.InputStream *is.662; | |
113 [ ... ] | |
114 T.660 = T.647; | |
115 is = T.660; <-- This ought to be type-casted | |
116 is.662 = is; | |
117 | |
118 Also, f/name.c exposed a similar problem with a COND_EXPR predicate | |
119 that was causing DOM to generate and equivalence with two pointers of | |
120 alias-incompatible types: | |
121 | |
122 struct _ffename_space *n; | |
123 struct _ffename *ns; | |
124 [ ... ] | |
125 if (n == ns) | |
126 goto lab; | |
127 ... | |
128 lab: | |
129 return n; | |
130 | |
131 I think that GIMPLE should emit the appropriate type-casts. For the | |
132 time being, blocking copy-propagation in these cases is the safe thing | |
133 to do. */ | |
134 if (TREE_CODE (dest) == SSA_NAME | |
135 && TREE_CODE (orig) == SSA_NAME | |
136 && POINTER_TYPE_P (type_d) | |
137 && POINTER_TYPE_P (type_o)) | |
138 { | |
139 tree mt_dest = symbol_mem_tag (SSA_NAME_VAR (dest)); | |
140 tree mt_orig = symbol_mem_tag (SSA_NAME_VAR (orig)); | |
141 if (mt_dest && mt_orig && mt_dest != mt_orig) | |
142 return false; | |
143 else if (get_alias_set (TREE_TYPE (type_d)) != | |
144 get_alias_set (TREE_TYPE (type_o))) | |
145 return false; | |
146 else if (!MTAG_P (SSA_NAME_VAR (dest)) | |
147 && !MTAG_P (SSA_NAME_VAR (orig)) | |
148 && (DECL_NO_TBAA_P (SSA_NAME_VAR (dest)) | |
149 != DECL_NO_TBAA_P (SSA_NAME_VAR (orig)))) | |
150 return false; | |
151 | |
152 /* Also verify flow-sensitive information is compatible. */ | |
153 if (SSA_NAME_PTR_INFO (orig) && SSA_NAME_PTR_INFO (dest)) | |
154 { | |
155 struct ptr_info_def *orig_ptr_info = SSA_NAME_PTR_INFO (orig); | |
156 struct ptr_info_def *dest_ptr_info = SSA_NAME_PTR_INFO (dest); | |
157 | |
158 if (orig_ptr_info->name_mem_tag | |
159 && dest_ptr_info->name_mem_tag | |
160 && orig_ptr_info->pt_vars | |
161 && dest_ptr_info->pt_vars | |
162 && !bitmap_intersect_p (dest_ptr_info->pt_vars, | |
163 orig_ptr_info->pt_vars)) | |
164 return false; | |
165 } | |
166 } | |
167 | |
168 /* If the destination is a SSA_NAME for a virtual operand, then we have | |
169 some special cases to handle. */ | |
170 if (TREE_CODE (dest) == SSA_NAME && !is_gimple_reg (dest)) | 82 if (TREE_CODE (dest) == SSA_NAME && !is_gimple_reg (dest)) |
171 { | 83 { |
172 /* If both operands are SSA_NAMEs referring to virtual operands, then | 84 /* But only between virtual operands. */ |
173 we can always propagate. */ | 85 gcc_assert (TREE_CODE (orig) == SSA_NAME && !is_gimple_reg (orig)); |
174 if (TREE_CODE (orig) == SSA_NAME | 86 |
175 && !is_gimple_reg (orig)) | 87 return true; |
176 return true; | |
177 | |
178 /* We have a "copy" from something like a constant into a virtual | |
179 operand. Reject these. */ | |
180 return false; | |
181 } | 88 } |
182 | 89 |
183 /* Anything else is OK. */ | 90 /* Anything else is OK. */ |
184 return true; | 91 return true; |
185 } | 92 } |
209 is no destination to pass to may_propagate_copy. On the other | 116 is no destination to pass to may_propagate_copy. On the other |
210 hand, the expression cannot be an SSA_NAME, so the analysis | 117 hand, the expression cannot be an SSA_NAME, so the analysis |
211 is much simpler. */ | 118 is much simpler. */ |
212 | 119 |
213 if (TREE_CODE (orig) == SSA_NAME | 120 if (TREE_CODE (orig) == SSA_NAME |
214 && (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig) | 121 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig)) |
215 || TREE_CODE (SSA_NAME_VAR (orig)) == MEMORY_PARTITION_TAG)) | |
216 return false; | 122 return false; |
217 | 123 |
218 if (is_gimple_assign (dest)) | 124 if (is_gimple_assign (dest)) |
219 type_d = TREE_TYPE (gimple_assign_lhs (dest)); | 125 type_d = TREE_TYPE (gimple_assign_lhs (dest)); |
220 else if (gimple_code (dest) == GIMPLE_COND) | 126 else if (gimple_code (dest) == GIMPLE_COND) |
243 && TREE_CODE (SSA_NAME_VAR (dest)) == VAR_DECL | 149 && TREE_CODE (SSA_NAME_VAR (dest)) == VAR_DECL |
244 && DECL_HARD_REGISTER (SSA_NAME_VAR (dest))); | 150 && DECL_HARD_REGISTER (SSA_NAME_VAR (dest))); |
245 } | 151 } |
246 | 152 |
247 | 153 |
248 /* Given two SSA_NAMEs pointers ORIG and NEW such that we are copy | |
249 propagating NEW into ORIG, consolidate aliasing information so that | |
250 they both share the same memory tags. */ | |
251 | |
252 void | |
253 merge_alias_info (tree orig_name, tree new_name) | |
254 { | |
255 tree new_sym = SSA_NAME_VAR (new_name); | |
256 tree orig_sym = SSA_NAME_VAR (orig_name); | |
257 var_ann_t new_ann = var_ann (new_sym); | |
258 var_ann_t orig_ann = var_ann (orig_sym); | |
259 | |
260 /* No merging necessary when memory partitions are involved. */ | |
261 if (factoring_name_p (new_name)) | |
262 { | |
263 gcc_assert (!is_gimple_reg (orig_sym)); | |
264 return; | |
265 } | |
266 else if (factoring_name_p (orig_name)) | |
267 { | |
268 gcc_assert (!is_gimple_reg (new_sym)); | |
269 return; | |
270 } | |
271 | |
272 gcc_assert (POINTER_TYPE_P (TREE_TYPE (orig_name)) | |
273 && POINTER_TYPE_P (TREE_TYPE (new_name))); | |
274 | |
275 #if defined ENABLE_CHECKING | |
276 gcc_assert (useless_type_conversion_p (TREE_TYPE (orig_name), | |
277 TREE_TYPE (new_name))); | |
278 | |
279 /* Check that flow-sensitive information is compatible. Notice that | |
280 we may not merge flow-sensitive information here. This function | |
281 is called when propagating equivalences dictated by the IL, like | |
282 a copy operation P_i = Q_j, and from equivalences dictated by | |
283 control-flow, like if (P_i == Q_j). | |
284 | |
285 In the former case, P_i and Q_j are equivalent in every block | |
286 dominated by the assignment, so their flow-sensitive information | |
287 is always the same. However, in the latter case, the pointers | |
288 P_i and Q_j are only equivalent in one of the sub-graphs out of | |
289 the predicate, so their flow-sensitive information is not the | |
290 same in every block dominated by the predicate. | |
291 | |
292 Since we cannot distinguish one case from another in this | |
293 function, we can only make sure that if P_i and Q_j have | |
294 flow-sensitive information, they should be compatible. | |
295 | |
296 As callers of merge_alias_info are supposed to call may_propagate_copy | |
297 first, the following check is redundant. Thus, only do it if checking | |
298 is enabled. */ | |
299 if (SSA_NAME_PTR_INFO (orig_name) && SSA_NAME_PTR_INFO (new_name)) | |
300 { | |
301 struct ptr_info_def *orig_ptr_info = SSA_NAME_PTR_INFO (orig_name); | |
302 struct ptr_info_def *new_ptr_info = SSA_NAME_PTR_INFO (new_name); | |
303 | |
304 /* Note that pointer NEW and ORIG may actually have different | |
305 pointed-to variables (e.g., PR 18291 represented in | |
306 testsuite/gcc.c-torture/compile/pr18291.c). However, since | |
307 NEW is being copy-propagated into ORIG, it must always be | |
308 true that the pointed-to set for pointer NEW is the same, or | |
309 a subset, of the pointed-to set for pointer ORIG. If this | |
310 isn't the case, we shouldn't have been able to do the | |
311 propagation of NEW into ORIG. */ | |
312 if (orig_ptr_info->name_mem_tag | |
313 && new_ptr_info->name_mem_tag | |
314 && orig_ptr_info->pt_vars | |
315 && new_ptr_info->pt_vars) | |
316 gcc_assert (bitmap_intersect_p (new_ptr_info->pt_vars, | |
317 orig_ptr_info->pt_vars)); | |
318 } | |
319 #endif | |
320 | |
321 /* Synchronize the symbol tags. If both pointers had a tag and they | |
322 are different, then something has gone wrong. Symbol tags can | |
323 always be merged because they are flow insensitive, all the SSA | |
324 names of the same base DECL share the same symbol tag. */ | |
325 if (new_ann->symbol_mem_tag == NULL_TREE) | |
326 new_ann->symbol_mem_tag = orig_ann->symbol_mem_tag; | |
327 else if (orig_ann->symbol_mem_tag == NULL_TREE) | |
328 orig_ann->symbol_mem_tag = new_ann->symbol_mem_tag; | |
329 else | |
330 gcc_assert (new_ann->symbol_mem_tag == orig_ann->symbol_mem_tag); | |
331 | |
332 /* Copy flow-sensitive alias information in case that NEW_NAME | |
333 didn't get a NMT but was set to pt_anything for optimization | |
334 purposes. In case ORIG_NAME has a NMT we can safely use its | |
335 flow-sensitive alias information as a conservative estimate. */ | |
336 if (SSA_NAME_PTR_INFO (orig_name) | |
337 && SSA_NAME_PTR_INFO (orig_name)->name_mem_tag | |
338 && (!SSA_NAME_PTR_INFO (new_name) | |
339 || !SSA_NAME_PTR_INFO (new_name)->name_mem_tag)) | |
340 { | |
341 struct ptr_info_def *orig_ptr_info = SSA_NAME_PTR_INFO (orig_name); | |
342 struct ptr_info_def *new_ptr_info = get_ptr_info (new_name); | |
343 memcpy (new_ptr_info, orig_ptr_info, sizeof (struct ptr_info_def)); | |
344 } | |
345 } | |
346 | |
347 | |
348 /* Common code for propagate_value and replace_exp. | 154 /* Common code for propagate_value and replace_exp. |
349 | 155 |
350 Replace use operand OP_P with VAL. FOR_PROPAGATION indicates if the | 156 Replace use operand OP_P with VAL. FOR_PROPAGATION indicates if the |
351 replacement is done to propagate a value or not. */ | 157 replacement is done to propagate a value or not. */ |
352 | 158 |
353 static void | 159 static void |
354 replace_exp_1 (use_operand_p op_p, tree val, | 160 replace_exp_1 (use_operand_p op_p, tree val, |
355 bool for_propagation ATTRIBUTE_UNUSED) | 161 bool for_propagation ATTRIBUTE_UNUSED) |
356 { | 162 { |
163 #if defined ENABLE_CHECKING | |
357 tree op = USE_FROM_PTR (op_p); | 164 tree op = USE_FROM_PTR (op_p); |
358 | 165 |
359 #if defined ENABLE_CHECKING | |
360 gcc_assert (!(for_propagation | 166 gcc_assert (!(for_propagation |
361 && TREE_CODE (op) == SSA_NAME | 167 && TREE_CODE (op) == SSA_NAME |
362 && TREE_CODE (val) == SSA_NAME | 168 && TREE_CODE (val) == SSA_NAME |
363 && !may_propagate_copy (op, val))); | 169 && !may_propagate_copy (op, val))); |
364 #endif | 170 #endif |
365 | 171 |
366 if (TREE_CODE (val) == SSA_NAME) | 172 if (TREE_CODE (val) == SSA_NAME) |
367 { | 173 SET_USE (op_p, val); |
368 if (TREE_CODE (op) == SSA_NAME && POINTER_TYPE_P (TREE_TYPE (op))) | |
369 merge_alias_info (op, val); | |
370 SET_USE (op_p, val); | |
371 } | |
372 else | 174 else |
373 SET_USE (op_p, unsave_expr_now (val)); | 175 SET_USE (op_p, unsave_expr_now (val)); |
374 } | 176 } |
375 | 177 |
376 | 178 |
416 && TREE_CODE (*op_p) == SSA_NAME | 218 && TREE_CODE (*op_p) == SSA_NAME |
417 && !may_propagate_copy (*op_p, val))); | 219 && !may_propagate_copy (*op_p, val))); |
418 #endif | 220 #endif |
419 | 221 |
420 if (TREE_CODE (val) == SSA_NAME) | 222 if (TREE_CODE (val) == SSA_NAME) |
421 { | 223 *op_p = val; |
422 if (*op_p && TREE_CODE (*op_p) == SSA_NAME && POINTER_TYPE_P (TREE_TYPE (*op_p))) | |
423 merge_alias_info (*op_p, val); | |
424 *op_p = val; | |
425 } | |
426 else | 224 else |
427 *op_p = unsave_expr_now (val); | 225 *op_p = unsave_expr_now (val); |
428 } | 226 } |
429 | 227 |
430 | 228 |
462 { | 260 { |
463 gimple new_stmt; | 261 gimple new_stmt; |
464 | 262 |
465 tree expr = NULL_TREE; | 263 tree expr = NULL_TREE; |
466 propagate_tree_value (&expr, val); | 264 propagate_tree_value (&expr, val); |
467 new_stmt = gimple_build_assign (gimple_call_lhs (stmt), expr); | 265 new_stmt = gimple_build_assign (gimple_call_lhs (stmt), expr); |
468 copy_virtual_operands (new_stmt, stmt); | |
469 move_ssa_defining_stmt_for_defs (new_stmt, stmt); | 266 move_ssa_defining_stmt_for_defs (new_stmt, stmt); |
470 gsi_replace (gsi, new_stmt, false); | 267 gsi_replace (gsi, new_stmt, false); |
471 } | 268 } |
472 else if (gimple_code (stmt) == GIMPLE_SWITCH) | 269 else if (gimple_code (stmt) == GIMPLE_SWITCH) |
473 propagate_tree_value (gimple_switch_index_ptr (stmt), val); | 270 propagate_tree_value (gimple_switch_index_ptr (stmt), val); |
511 useful copy. */ | 308 useful copy. */ |
512 if (gimple_has_volatile_ops (stmt)) | 309 if (gimple_has_volatile_ops (stmt)) |
513 return false; | 310 return false; |
514 | 311 |
515 /* Statements with loads and/or stores will never generate a useful copy. */ | 312 /* Statements with loads and/or stores will never generate a useful copy. */ |
516 if (!ZERO_SSA_OPERANDS (stmt, SSA_OP_ALL_VIRTUALS)) | 313 if (gimple_vuse (stmt)) |
517 return false; | 314 return false; |
518 | 315 |
519 /* Otherwise, the only statements that generate useful copies are | 316 /* Otherwise, the only statements that generate useful copies are |
520 assignments whose RHS is just an SSA name that doesn't flow | 317 assignments whose RHS is just an SSA name that doesn't flow |
521 through abnormal edges. */ | 318 through abnormal edges. */ |
552 int i; | 349 int i; |
553 | 350 |
554 /* Traverse COPY_OF starting at VAR until we get to the last | 351 /* Traverse COPY_OF starting at VAR until we get to the last |
555 link in the chain. Since it is possible to have cycles in PHI | 352 link in the chain. Since it is possible to have cycles in PHI |
556 nodes, the copy-of chain may also contain cycles. | 353 nodes, the copy-of chain may also contain cycles. |
557 | 354 |
558 To avoid infinite loops and to avoid traversing lengthy copy-of | 355 To avoid infinite loops and to avoid traversing lengthy copy-of |
559 chains, we artificially limit the maximum number of chains we are | 356 chains, we artificially limit the maximum number of chains we are |
560 willing to traverse. | 357 willing to traverse. |
561 | 358 |
562 The value 5 was taken from a compiler and runtime library | 359 The value 5 was taken from a compiler and runtime library |
591 static inline bool | 388 static inline bool |
592 set_copy_of_val (tree dest, tree first) | 389 set_copy_of_val (tree dest, tree first) |
593 { | 390 { |
594 unsigned int dest_ver = SSA_NAME_VERSION (dest); | 391 unsigned int dest_ver = SSA_NAME_VERSION (dest); |
595 tree old_first, old_last, new_last; | 392 tree old_first, old_last, new_last; |
596 | 393 |
597 /* Set FIRST to be the first link in COPY_OF[DEST]. If that | 394 /* Set FIRST to be the first link in COPY_OF[DEST]. If that |
598 changed, return true. */ | 395 changed, return true. */ |
599 old_first = copy_of[dest_ver].value; | 396 old_first = copy_of[dest_ver].value; |
600 copy_of[dest_ver].value = first; | 397 copy_of[dest_ver].value = first; |
601 | 398 |
631 | 428 |
632 print_generic_expr (file, var, dump_flags); | 429 print_generic_expr (file, var, dump_flags); |
633 | 430 |
634 if (TREE_CODE (var) != SSA_NAME) | 431 if (TREE_CODE (var) != SSA_NAME) |
635 return; | 432 return; |
636 | 433 |
637 visited = sbitmap_alloc (num_ssa_names); | 434 visited = sbitmap_alloc (num_ssa_names); |
638 sbitmap_zero (visited); | 435 sbitmap_zero (visited); |
639 SET_BIT (visited, SSA_NAME_VERSION (var)); | 436 SET_BIT (visited, SSA_NAME_VERSION (var)); |
640 | 437 |
641 fprintf (file, " copy-of chain: "); | 438 fprintf (file, " copy-of chain: "); |
642 | 439 |
643 val = var; | 440 val = var; |
644 print_generic_expr (file, val, 0); | 441 print_generic_expr (file, val, 0); |
645 fprintf (file, " "); | 442 fprintf (file, " "); |
659 fprintf (file, "[UNDEFINED]"); | 456 fprintf (file, "[UNDEFINED]"); |
660 else if (val != var) | 457 else if (val != var) |
661 fprintf (file, "[COPY]"); | 458 fprintf (file, "[COPY]"); |
662 else | 459 else |
663 fprintf (file, "[NOT A COPY]"); | 460 fprintf (file, "[NOT A COPY]"); |
664 | 461 |
665 sbitmap_free (visited); | 462 sbitmap_free (visited); |
666 } | 463 } |
667 | 464 |
668 | 465 |
669 /* Evaluate the RHS of STMT. If it produces a valid copy, set the LHS | 466 /* Evaluate the RHS of STMT. If it produces a valid copy, set the LHS |
678 tree lhs, rhs; | 475 tree lhs, rhs; |
679 prop_value_t *rhs_val; | 476 prop_value_t *rhs_val; |
680 | 477 |
681 lhs = gimple_assign_lhs (stmt); | 478 lhs = gimple_assign_lhs (stmt); |
682 rhs = gimple_assign_rhs1 (stmt); | 479 rhs = gimple_assign_rhs1 (stmt); |
683 | 480 |
684 | 481 |
685 gcc_assert (gimple_assign_rhs_code (stmt) == SSA_NAME); | 482 gcc_assert (gimple_assign_rhs_code (stmt) == SSA_NAME); |
686 | 483 |
687 rhs_val = get_copy_of_val (rhs); | 484 rhs_val = get_copy_of_val (rhs); |
688 | 485 |
695 | 492 |
696 /* Notice that in the case of assignments, we make the LHS be a | 493 /* Notice that in the case of assignments, we make the LHS be a |
697 copy of RHS's value, not of RHS itself. This avoids keeping | 494 copy of RHS's value, not of RHS itself. This avoids keeping |
698 unnecessary copy-of chains (assignments cannot be in a cycle | 495 unnecessary copy-of chains (assignments cannot be in a cycle |
699 like PHI nodes), speeding up the propagation process. | 496 like PHI nodes), speeding up the propagation process. |
700 This is different from what we do in copy_prop_visit_phi_node. | 497 This is different from what we do in copy_prop_visit_phi_node. |
701 In those cases, we are interested in the copy-of chains. */ | 498 In those cases, we are interested in the copy-of chains. */ |
702 *result_p = lhs; | 499 *result_p = lhs; |
703 if (set_copy_of_val (*result_p, rhs_val->value)) | 500 if (set_copy_of_val (*result_p, rhs_val->value)) |
704 return SSA_PROP_INTERESTING; | 501 return SSA_PROP_INTERESTING; |
705 else | 502 else |
716 | 513 |
717 static enum ssa_prop_result | 514 static enum ssa_prop_result |
718 copy_prop_visit_cond_stmt (gimple stmt, edge *taken_edge_p) | 515 copy_prop_visit_cond_stmt (gimple stmt, edge *taken_edge_p) |
719 { | 516 { |
720 enum ssa_prop_result retval = SSA_PROP_VARYING; | 517 enum ssa_prop_result retval = SSA_PROP_VARYING; |
518 location_t loc = gimple_location (stmt); | |
721 | 519 |
722 tree op0 = gimple_cond_lhs (stmt); | 520 tree op0 = gimple_cond_lhs (stmt); |
723 tree op1 = gimple_cond_rhs (stmt); | 521 tree op1 = gimple_cond_rhs (stmt); |
724 | 522 |
725 /* The only conditionals that we may be able to compute statically | 523 /* The only conditionals that we may be able to compute statically |
739 | 537 |
740 /* We can fold COND and get a useful result only when we have | 538 /* We can fold COND and get a useful result only when we have |
741 the same SSA_NAME on both sides of a comparison operator. */ | 539 the same SSA_NAME on both sides of a comparison operator. */ |
742 if (op0 == op1) | 540 if (op0 == op1) |
743 { | 541 { |
744 tree folded_cond = fold_binary (gimple_cond_code (stmt), | 542 tree folded_cond = fold_binary_loc (loc, gimple_cond_code (stmt), |
745 boolean_type_node, op0, op1); | 543 boolean_type_node, op0, op1); |
746 if (folded_cond) | 544 if (folded_cond) |
747 { | 545 { |
748 basic_block bb = gimple_bb (stmt); | 546 basic_block bb = gimple_bb (stmt); |
749 *taken_edge_p = find_taken_edge (bb, folded_cond); | 547 *taken_edge_p = find_taken_edge (bb, folded_cond); |
862 | 660 |
863 /* Avoid copy propagation from an inner into an outer loop. | 661 /* Avoid copy propagation from an inner into an outer loop. |
864 Otherwise, this may move loop variant variables outside of | 662 Otherwise, this may move loop variant variables outside of |
865 their loops and prevent coalescing opportunities. If the | 663 their loops and prevent coalescing opportunities. If the |
866 value was loop invariant, it will be hoisted by LICM and | 664 value was loop invariant, it will be hoisted by LICM and |
867 exposed for copy propagation. */ | 665 exposed for copy propagation. Not a problem for virtual |
868 if (loop_depth_of_name (arg) > loop_depth_of_name (lhs)) | 666 operands though. */ |
667 if (is_gimple_reg (lhs) | |
668 && loop_depth_of_name (arg) > loop_depth_of_name (lhs)) | |
869 { | 669 { |
870 phi_val.value = lhs; | 670 phi_val.value = lhs; |
871 break; | 671 break; |
872 } | 672 } |
873 | 673 |
890 a copy of the argument itself, we take the memory reference | 690 a copy of the argument itself, we take the memory reference |
891 from the argument's value so that we can compare it to the | 691 from the argument's value so that we can compare it to the |
892 memory reference of all the other arguments. */ | 692 memory reference of all the other arguments. */ |
893 if (phi_val.value == NULL_TREE) | 693 if (phi_val.value == NULL_TREE) |
894 { | 694 { |
895 phi_val.value = arg; | 695 phi_val.value = arg_val->value ? arg_val->value : arg; |
896 continue; | 696 continue; |
897 } | 697 } |
898 | 698 |
899 /* If PHI_VAL and ARG don't have a common copy-of chain, then | 699 /* If PHI_VAL and ARG don't have a common copy-of chain, then |
900 this PHI node cannot be a copy operation. Also, if we are | 700 this PHI node cannot be a copy operation. Also, if we are |
990 { | 790 { |
991 gimple phi = gsi_stmt (si); | 791 gimple phi = gsi_stmt (si); |
992 tree def; | 792 tree def; |
993 | 793 |
994 def = gimple_phi_result (phi); | 794 def = gimple_phi_result (phi); |
995 if (!is_gimple_reg (def)) | 795 if (!is_gimple_reg (def) |
796 /* In loop-closed SSA form do not copy-propagate through | |
797 PHI nodes. Technically this is only needed for loop | |
798 exit PHIs, but this is difficult to query. */ | |
799 || (current_loops | |
800 && gimple_phi_num_args (phi) == 1 | |
801 && loops_state_satisfies_p (LOOP_CLOSED_SSA))) | |
996 prop_set_simulate_again (phi, false); | 802 prop_set_simulate_again (phi, false); |
997 else | 803 else |
998 prop_set_simulate_again (phi, true); | 804 prop_set_simulate_again (phi, true); |
999 | 805 |
1000 if (!prop_simulate_again_p (phi)) | 806 if (!prop_simulate_again_p (phi)) |
1012 static void | 818 static void |
1013 fini_copy_prop (void) | 819 fini_copy_prop (void) |
1014 { | 820 { |
1015 size_t i; | 821 size_t i; |
1016 prop_value_t *tmp; | 822 prop_value_t *tmp; |
1017 | 823 |
1018 /* Set the final copy-of value for each variable by traversing the | 824 /* Set the final copy-of value for each variable by traversing the |
1019 copy-of chains. */ | 825 copy-of chains. */ |
1020 tmp = XCNEWVEC (prop_value_t, num_ssa_names); | 826 tmp = XCNEWVEC (prop_value_t, num_ssa_names); |
1021 for (i = 1; i < num_ssa_names; i++) | 827 for (i = 1; i < num_ssa_names; i++) |
1022 { | 828 { |
1023 tree var = ssa_name (i); | 829 tree var = ssa_name (i); |
1024 if (var && copy_of[i].value && copy_of[i].value != var) | 830 if (!var |
1025 tmp[i].value = get_last_copy_of (var); | 831 || !copy_of[i].value |
1026 } | 832 || copy_of[i].value == var) |
1027 | 833 continue; |
1028 substitute_and_fold (tmp, false); | 834 |
835 tmp[i].value = get_last_copy_of (var); | |
836 | |
837 /* In theory the points-to solution of all members of the | |
838 copy chain is their intersection. For now we do not bother | |
839 to compute this but only make sure we do not lose points-to | |
840 information completely by setting the points-to solution | |
841 of the representative to the first solution we find if | |
842 it doesn't have one already. */ | |
843 if (tmp[i].value != var | |
844 && POINTER_TYPE_P (TREE_TYPE (var)) | |
845 && SSA_NAME_PTR_INFO (var) | |
846 && !SSA_NAME_PTR_INFO (tmp[i].value)) | |
847 duplicate_ssa_name_ptr_info (tmp[i].value, SSA_NAME_PTR_INFO (var)); | |
848 } | |
849 | |
850 substitute_and_fold (tmp, NULL); | |
1029 | 851 |
1030 free (cached_last_copy_of); | 852 free (cached_last_copy_of); |
1031 free (copy_of); | 853 free (copy_of); |
1032 free (tmp); | 854 free (tmp); |
1033 } | 855 } |
1034 | 856 |
1035 | 857 |
1036 /* Main entry point to the copy propagator. | 858 /* Main entry point to the copy propagator. |
1037 | 859 |
1038 PHIS_ONLY is true if we should only consider PHI nodes as generating | 860 PHIS_ONLY is true if we should only consider PHI nodes as generating |
1039 copy propagation opportunities. | 861 copy propagation opportunities. |
1040 | 862 |
1041 The algorithm propagates the value COPY-OF using ssa_propagate. For | 863 The algorithm propagates the value COPY-OF using ssa_propagate. For |
1042 every variable X_i, COPY-OF(X_i) indicates which variable is X_i created | 864 every variable X_i, COPY-OF(X_i) indicates which variable is X_i created |
1043 from. The following example shows how the algorithm proceeds at a | 865 from. The following example shows how the algorithm proceeds at a |
1044 high level: | 866 high level: |
1057 Visit #4: x_1 is copy-of x_298. Value changed. | 879 Visit #4: x_1 is copy-of x_298. Value changed. |
1058 Visit #1: a_24 is copy-of x_298. Value changed. | 880 Visit #1: a_24 is copy-of x_298. Value changed. |
1059 Visit #2: a_2 is copy-of x_298. Value changed. | 881 Visit #2: a_2 is copy-of x_298. Value changed. |
1060 Visit #3: a_5 is copy-of x_298. Value changed. | 882 Visit #3: a_5 is copy-of x_298. Value changed. |
1061 Visit #4: x_1 is copy-of x_298. Stable state reached. | 883 Visit #4: x_1 is copy-of x_298. Stable state reached. |
1062 | 884 |
1063 When visiting PHI nodes, we only consider arguments that flow | 885 When visiting PHI nodes, we only consider arguments that flow |
1064 through edges marked executable by the propagation engine. So, | 886 through edges marked executable by the propagation engine. So, |
1065 when visiting statement #2 for the first time, we will only look at | 887 when visiting statement #2 for the first time, we will only look at |
1066 the first argument (a_24) and optimistically assume that its value | 888 the first argument (a_24) and optimistically assume that its value |
1067 is the copy of a_24 (x_1). | 889 is the copy of a_24 (x_1). |
1094 following PHI cycle, such that x_52 is already considered a copy of | 916 following PHI cycle, such that x_52 is already considered a copy of |
1095 x_53: | 917 x_53: |
1096 | 918 |
1097 1 x_54 = PHI <x_53, x_52> | 919 1 x_54 = PHI <x_53, x_52> |
1098 2 x_53 = PHI <x_898, x_54> | 920 2 x_53 = PHI <x_898, x_54> |
1099 | 921 |
1100 Visit #1: x_54 is copy-of x_53 (because x_52 is copy-of x_53) | 922 Visit #1: x_54 is copy-of x_53 (because x_52 is copy-of x_53) |
1101 Visit #2: x_53 is copy-of x_898 (because x_54 is a copy of x_53, | 923 Visit #2: x_53 is copy-of x_898 (because x_54 is a copy of x_53, |
1102 so it is considered irrelevant | 924 so it is considered irrelevant |
1103 as a copy). | 925 as a copy). |
1104 Visit #1: x_54 is copy-of nothing (x_53 is a copy-of x_898 and | 926 Visit #1: x_54 is copy-of nothing (x_53 is a copy-of x_898 and |
1111 element of a variable's copy-of chain. When visiting PHI nodes, | 933 element of a variable's copy-of chain. When visiting PHI nodes, |
1112 arguments are considered equal if their copy-of chains end in the | 934 arguments are considered equal if their copy-of chains end in the |
1113 same variable. So, as long as their copy-of chains overlap, we | 935 same variable. So, as long as their copy-of chains overlap, we |
1114 know that they will be a copy of the same variable, regardless of | 936 know that they will be a copy of the same variable, regardless of |
1115 which variable that may be). | 937 which variable that may be). |
1116 | 938 |
1117 Propagation would then proceed as follows (the notation a -> b | 939 Propagation would then proceed as follows (the notation a -> b |
1118 means that a is a copy-of b): | 940 means that a is a copy-of b): |
1119 | 941 |
1120 Visit #1: x_54 = PHI <x_53, x_52> | 942 Visit #1: x_54 = PHI <x_53, x_52> |
1121 x_53 -> x_53 | 943 x_53 -> x_53 |