Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa-threadedge.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 "function.h" | 34 #include "function.h" |
35 #include "diagnostic.h" | 35 #include "diagnostic.h" |
36 #include "timevar.h" | 36 #include "timevar.h" |
37 #include "tree-dump.h" | 37 #include "tree-dump.h" |
38 #include "tree-flow.h" | 38 #include "tree-flow.h" |
39 #include "domwalk.h" | |
40 #include "real.h" | 39 #include "real.h" |
41 #include "tree-pass.h" | 40 #include "tree-pass.h" |
42 #include "tree-ssa-propagate.h" | 41 #include "tree-ssa-propagate.h" |
43 #include "langhooks.h" | 42 #include "langhooks.h" |
44 #include "params.h" | 43 #include "params.h" |
46 /* To avoid code explosion due to jump threading, we limit the | 45 /* To avoid code explosion due to jump threading, we limit the |
47 number of statements we are going to copy. This variable | 46 number of statements we are going to copy. This variable |
48 holds the number of statements currently seen that we'll have | 47 holds the number of statements currently seen that we'll have |
49 to copy as part of the jump threading process. */ | 48 to copy as part of the jump threading process. */ |
50 static int stmt_count; | 49 static int stmt_count; |
50 | |
51 /* Array to record value-handles per SSA_NAME. */ | |
52 VEC(tree,heap) *ssa_name_values; | |
53 | |
54 /* Set the value for the SSA name NAME to VALUE. */ | |
55 | |
56 void | |
57 set_ssa_name_value (tree name, tree value) | |
58 { | |
59 if (SSA_NAME_VERSION (name) >= VEC_length (tree, ssa_name_values)) | |
60 VEC_safe_grow_cleared (tree, heap, ssa_name_values, | |
61 SSA_NAME_VERSION (name) + 1); | |
62 VEC_replace (tree, ssa_name_values, SSA_NAME_VERSION (name), value); | |
63 } | |
64 | |
65 /* Initialize the per SSA_NAME value-handles array. Returns it. */ | |
66 void | |
67 threadedge_initialize_values (void) | |
68 { | |
69 gcc_assert (ssa_name_values == NULL); | |
70 ssa_name_values = VEC_alloc(tree, heap, num_ssa_names); | |
71 } | |
72 | |
73 /* Free the per SSA_NAME value-handle array. */ | |
74 void | |
75 threadedge_finalize_values (void) | |
76 { | |
77 VEC_free(tree, heap, ssa_name_values); | |
78 } | |
51 | 79 |
52 /* Return TRUE if we may be able to thread an incoming edge into | 80 /* Return TRUE if we may be able to thread an incoming edge into |
53 BB to an outgoing edge from BB. Return FALSE otherwise. */ | 81 BB to an outgoing edge from BB. Return FALSE otherwise. */ |
54 | 82 |
55 bool | 83 bool |
124 pop off the next entry as they're recorded in pairs. */ | 152 pop off the next entry as they're recorded in pairs. */ |
125 if (dest == NULL) | 153 if (dest == NULL) |
126 break; | 154 break; |
127 | 155 |
128 prev_value = VEC_pop (tree, *stack); | 156 prev_value = VEC_pop (tree, *stack); |
129 SSA_NAME_VALUE (dest) = prev_value; | 157 set_ssa_name_value (dest, prev_value); |
130 } | 158 } |
131 } | 159 } |
132 | 160 |
133 /* Record a temporary equivalence, saving enough information so that | 161 /* Record a temporary equivalence, saving enough information so that |
134 we can restore the state of recorded equivalences when we're | 162 we can restore the state of recorded equivalences when we're |
143 { | 171 { |
144 tree tmp = SSA_NAME_VALUE (y); | 172 tree tmp = SSA_NAME_VALUE (y); |
145 y = tmp ? tmp : y; | 173 y = tmp ? tmp : y; |
146 } | 174 } |
147 | 175 |
148 SSA_NAME_VALUE (x) = y; | 176 set_ssa_name_value (x, y); |
149 VEC_reserve (tree, heap, *stack, 2); | 177 VEC_reserve (tree, heap, *stack, 2); |
150 VEC_quick_push (tree, *stack, prev_x); | 178 VEC_quick_push (tree, *stack, prev_x); |
151 VEC_quick_push (tree, *stack, x); | 179 VEC_quick_push (tree, *stack, x); |
152 } | 180 } |
153 | 181 |
154 /* Record temporary equivalences created by PHIs at the target of the | 182 /* Record temporary equivalences created by PHIs at the target of the |
155 edge E. Record unwind information for the equivalences onto STACK. | 183 edge E. Record unwind information for the equivalences onto STACK. |
156 | 184 |
157 If a PHI which prevents threading is encountered, then return FALSE | 185 If a PHI which prevents threading is encountered, then return FALSE |
158 indicating we should not thread this edge, else return TRUE. */ | 186 indicating we should not thread this edge, else return TRUE. */ |
159 | 187 |
160 static bool | 188 static bool |
169 { | 197 { |
170 gimple phi = gsi_stmt (gsi); | 198 gimple phi = gsi_stmt (gsi); |
171 tree src = PHI_ARG_DEF_FROM_EDGE (phi, e); | 199 tree src = PHI_ARG_DEF_FROM_EDGE (phi, e); |
172 tree dst = gimple_phi_result (phi); | 200 tree dst = gimple_phi_result (phi); |
173 | 201 |
174 /* If the desired argument is not the same as this PHI's result | 202 /* If the desired argument is not the same as this PHI's result |
175 and it is set by a PHI in E->dest, then we can not thread | 203 and it is set by a PHI in E->dest, then we can not thread |
176 through E->dest. */ | 204 through E->dest. */ |
177 if (src != dst | 205 if (src != dst |
178 && TREE_CODE (src) == SSA_NAME | 206 && TREE_CODE (src) == SSA_NAME |
179 && gimple_code (SSA_NAME_DEF_STMT (src)) == GIMPLE_PHI | 207 && gimple_code (SSA_NAME_DEF_STMT (src)) == GIMPLE_PHI |
244 a simplification of the COND_EXPR at the end of E->dest. | 272 a simplification of the COND_EXPR at the end of E->dest. |
245 | 273 |
246 Record unwind information for temporary equivalences onto STACK. | 274 Record unwind information for temporary equivalences onto STACK. |
247 | 275 |
248 Use SIMPLIFY (a pointer to a callback function) to further simplify | 276 Use SIMPLIFY (a pointer to a callback function) to further simplify |
249 statements using pass specific information. | 277 statements using pass specific information. |
250 | 278 |
251 We might consider marking just those statements which ultimately | 279 We might consider marking just those statements which ultimately |
252 feed the COND_EXPR. It's not clear if the overhead of bookkeeping | 280 feed the COND_EXPR. It's not clear if the overhead of bookkeeping |
253 would be recovered by trying to simplify fewer statements. | 281 would be recovered by trying to simplify fewer statements. |
254 | 282 |
278 tree cached_lhs = NULL; | 306 tree cached_lhs = NULL; |
279 | 307 |
280 stmt = gsi_stmt (gsi); | 308 stmt = gsi_stmt (gsi); |
281 | 309 |
282 /* Ignore empty statements and labels. */ | 310 /* Ignore empty statements and labels. */ |
283 if (gimple_code (stmt) == GIMPLE_NOP || gimple_code (stmt) == GIMPLE_LABEL) | 311 if (gimple_code (stmt) == GIMPLE_NOP |
312 || gimple_code (stmt) == GIMPLE_LABEL | |
313 || is_gimple_debug (stmt)) | |
284 continue; | 314 continue; |
285 | 315 |
286 /* If the statement has volatile operands, then we assume we | 316 /* If the statement has volatile operands, then we assume we |
287 can not thread through this block. This is overly | 317 can not thread through this block. This is overly |
288 conservative in some ways. */ | 318 conservative in some ways. */ |
340 } | 370 } |
341 | 371 |
342 /* At this point we have a statement which assigns an RHS to an | 372 /* At this point we have a statement which assigns an RHS to an |
343 SSA_VAR on the LHS. We want to try and simplify this statement | 373 SSA_VAR on the LHS. We want to try and simplify this statement |
344 to expose more context sensitive equivalences which in turn may | 374 to expose more context sensitive equivalences which in turn may |
345 allow us to simplify the condition at the end of the loop. | 375 allow us to simplify the condition at the end of the loop. |
346 | 376 |
347 Handle simple copy operations as well as implied copies from | 377 Handle simple copy operations as well as implied copies from |
348 ASSERT_EXPRs. */ | 378 ASSERT_EXPRs. */ |
349 if (gimple_assign_single_p (stmt) | 379 if (gimple_assign_single_p (stmt) |
350 && TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME) | 380 && TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME) |
388 | 418 |
389 if (!cached_lhs | 419 if (!cached_lhs |
390 || (TREE_CODE (cached_lhs) != SSA_NAME | 420 || (TREE_CODE (cached_lhs) != SSA_NAME |
391 && !is_gimple_min_invariant (cached_lhs))) | 421 && !is_gimple_min_invariant (cached_lhs))) |
392 cached_lhs = (*simplify) (stmt, stmt); | 422 cached_lhs = (*simplify) (stmt, stmt); |
393 | 423 |
394 /* Restore the statement's original uses/defs. */ | 424 /* Restore the statement's original uses/defs. */ |
395 i = 0; | 425 i = 0; |
396 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE | SSA_OP_VUSE) | 426 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE | SSA_OP_VUSE) |
397 SET_USE (use_p, copy[i++]); | 427 SET_USE (use_p, copy[i++]); |
398 | 428 |
547 | 577 |
548 return cached_lhs; | 578 return cached_lhs; |
549 } | 579 } |
550 | 580 |
551 /* We are exiting E->src, see if E->dest ends with a conditional | 581 /* We are exiting E->src, see if E->dest ends with a conditional |
552 jump which has a known value when reached via E. | 582 jump which has a known value when reached via E. |
553 | 583 |
554 Special care is necessary if E is a back edge in the CFG as we | 584 Special care is necessary if E is a back edge in the CFG as we |
555 may have already recorded equivalences for E->dest into our | 585 may have already recorded equivalences for E->dest into our |
556 various tables, including the result of the conditional at | 586 various tables, including the result of the conditional at |
557 the end of E->dest. Threading opportunities are severely | 587 the end of E->dest. Threading opportunities are severely |
560 | 590 |
561 Note it is quite common for the first block inside a loop to | 591 Note it is quite common for the first block inside a loop to |
562 end with a conditional which is either always true or always | 592 end with a conditional which is either always true or always |
563 false when reached via the loop backedge. Thus we do not want | 593 false when reached via the loop backedge. Thus we do not want |
564 to blindly disable threading across a loop backedge. | 594 to blindly disable threading across a loop backedge. |
565 | 595 |
566 DUMMY_COND is a shared cond_expr used by condition simplification as scratch, | 596 DUMMY_COND is a shared cond_expr used by condition simplification as scratch, |
567 to avoid allocating memory. | 597 to avoid allocating memory. |
568 | 598 |
569 HANDLE_DOMINATING_ASSERTS is true if we should try to replace operands of | 599 HANDLE_DOMINATING_ASSERTS is true if we should try to replace operands of |
570 the simplified condition with left-hand sides of ASSERT_EXPRs they are | 600 the simplified condition with left-hand sides of ASSERT_EXPRs they are |
571 used in. | 601 used in. |
572 | 602 |
573 STACK is used to undo temporary equivalences created during the walk of | 603 STACK is used to undo temporary equivalences created during the walk of |
574 E->dest. | 604 E->dest. |
575 | 605 |
576 SIMPLIFY is a pass-specific function used to simplify statements. */ | 606 SIMPLIFY is a pass-specific function used to simplify statements. */ |
577 | 607 |
602 && gimple_code (SSA_NAME_DEF_STMT (use)) != GIMPLE_PHI | 632 && gimple_code (SSA_NAME_DEF_STMT (use)) != GIMPLE_PHI |
603 && gimple_bb (SSA_NAME_DEF_STMT (use)) == e->dest) | 633 && gimple_bb (SSA_NAME_DEF_STMT (use)) == e->dest) |
604 goto fail; | 634 goto fail; |
605 } | 635 } |
606 } | 636 } |
607 | 637 |
608 stmt_count = 0; | 638 stmt_count = 0; |
609 | 639 |
610 /* PHIs create temporary equivalences. */ | 640 /* PHIs create temporary equivalences. */ |
611 if (!record_temporary_equivalences_from_phis (e, stack)) | 641 if (!record_temporary_equivalences_from_phis (e, stack)) |
612 goto fail; | 642 goto fail; |