2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Daniel Berlin <dan@dberlin.org> and Steven Bosscher
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
28 #include "basic-block.h"
29 #include "gimple-pretty-print.h"
30 #include "tree-inline.h"
31 #include "tree-flow.h"
33 #include "hash-table.h"
34 #include "tree-iterator.h"
35 #include "alloc-pool.h"
37 #include "tree-pass.h"
40 #include "langhooks.h"
42 #include "tree-ssa-sccvn.h"
43 #include "tree-scalar-evolution.h"
50 1. Avail sets can be shared by making an avail_find_leader that
51 walks up the dominator tree and looks in those avail sets.
52 This might affect code optimality, it's unclear right now.
53 2. Strength reduction can be performed by anticipating expressions
54 we can repair later on.
55 3. We can do back-substitution or smarter value numbering to catch
56 commutative expressions split up over multiple statements.
59 /* For ease of terminology, "expression node" in the below refers to
60 every expression node but GIMPLE_ASSIGN, because GIMPLE_ASSIGNs
61 represent the actual statement containing the expressions we care about,
62 and we cache the value number by putting it in the expression. */
66 First we walk the statements to generate the AVAIL sets, the
67 EXP_GEN sets, and the tmp_gen sets. EXP_GEN sets represent the
68 generation of values/expressions by a given block. We use them
69 when computing the ANTIC sets. The AVAIL sets consist of
70 SSA_NAME's that represent values, so we know what values are
71 available in what blocks. AVAIL is a forward dataflow problem. In
72 SSA, values are never killed, so we don't need a kill set, or a
73 fixpoint iteration, in order to calculate the AVAIL sets. In
74 traditional parlance, AVAIL sets tell us the downsafety of the
77 Next, we generate the ANTIC sets. These sets represent the
78 anticipatable expressions. ANTIC is a backwards dataflow
79 problem. An expression is anticipatable in a given block if it could
80 be generated in that block. This means that if we had to perform
81 an insertion in that block, of the value of that expression, we
82 could. Calculating the ANTIC sets requires phi translation of
83 expressions, because the flow goes backwards through phis. We must
84 iterate to a fixpoint of the ANTIC sets, because we have a kill
85 set. Even in SSA form, values are not live over the entire
86 function, only from their definition point onwards. So we have to
87 remove values from the ANTIC set once we go past the definition
88 point of the leaders that make them up.
89 compute_antic/compute_antic_aux performs this computation.
91 Third, we perform insertions to make partially redundant
92 expressions fully redundant.
94 An expression is partially redundant (excluding partial
97 1. It is AVAIL in some, but not all, of the predecessors of a
99 2. It is ANTIC in all the predecessors.
101 In order to make it fully redundant, we insert the expression into
102 the predecessors where it is not available, but is ANTIC.
104 For the partial anticipation case, we only perform insertion if it
105 is partially anticipated in some block, and fully available in all
108 insert/insert_aux/do_regular_insertion/do_partial_partial_insertion
109 performs these steps.
111 Fourth, we eliminate fully redundant expressions.
112 This is a simple statement walk that replaces redundant
113 calculations with the now available values. */
115 /* Representations of value numbers:
117 Value numbers are represented by a representative SSA_NAME. We
118 will create fake SSA_NAME's in situations where we need a
119 representative but do not have one (because it is a complex
120 expression). In order to facilitate storing the value numbers in
121 bitmaps, and keep the number of wasted SSA_NAME's down, we also
122 associate a value_id with each value number, and create full blown
123 ssa_name's only where we actually need them (IE in operands of
124 existing expressions).
126 Theoretically you could replace all the value_id's with
127 SSA_NAME_VERSION, but this would allocate a large number of
128 SSA_NAME's (which are each > 30 bytes) just to get a 4 byte number.
129 It would also require an additional indirection at each point we
132 /* Representation of expressions on value numbers:
134 Expressions consisting of value numbers are represented the same
135 way as our VN internally represents them, with an additional
136 "pre_expr" wrapping around them in order to facilitate storing all
137 of the expressions in the same sets. */
139 /* Representation of sets:
141 The dataflow sets do not need to be sorted in any particular order
142 for the majority of their lifetime, are simply represented as two
143 bitmaps, one that keeps track of values present in the set, and one
144 that keeps track of expressions present in the set.
146 When we need them in topological order, we produce it on demand by
147 transforming the bitmap into an array and sorting it into topo
150 /* Type of expression, used to know which member of the PRE_EXPR union
161 typedef union pre_expr_union_d
166 vn_reference_t reference
;
169 typedef struct pre_expr_d
: typed_noop_remove
<pre_expr_d
>
171 enum pre_expr_kind kind
;
175 /* hash_table support. */
176 typedef pre_expr_d value_type
;
177 typedef pre_expr_d compare_type
;
178 static inline hashval_t
hash (const pre_expr_d
*);
179 static inline int equal (const pre_expr_d
*, const pre_expr_d
*);
182 #define PRE_EXPR_NAME(e) (e)->u.name
183 #define PRE_EXPR_NARY(e) (e)->u.nary
184 #define PRE_EXPR_REFERENCE(e) (e)->u.reference
185 #define PRE_EXPR_CONSTANT(e) (e)->u.constant
187 /* Compare E1 and E1 for equality. */
190 pre_expr_d::equal (const value_type
*e1
, const compare_type
*e2
)
192 if (e1
->kind
!= e2
->kind
)
198 return vn_constant_eq_with_type (PRE_EXPR_CONSTANT (e1
),
199 PRE_EXPR_CONSTANT (e2
));
201 return PRE_EXPR_NAME (e1
) == PRE_EXPR_NAME (e2
);
203 return vn_nary_op_eq (PRE_EXPR_NARY (e1
), PRE_EXPR_NARY (e2
));
205 return vn_reference_eq (PRE_EXPR_REFERENCE (e1
),
206 PRE_EXPR_REFERENCE (e2
));
215 pre_expr_d::hash (const value_type
*e
)
220 return vn_hash_constant_with_type (PRE_EXPR_CONSTANT (e
));
222 return SSA_NAME_VERSION (PRE_EXPR_NAME (e
));
224 return PRE_EXPR_NARY (e
)->hashcode
;
226 return PRE_EXPR_REFERENCE (e
)->hashcode
;
232 /* Next global expression id number. */
233 static unsigned int next_expression_id
;
235 /* Mapping from expression to id number we can use in bitmap sets. */
236 static vec
<pre_expr
> expressions
;
237 static hash_table
<pre_expr_d
> expression_to_id
;
238 static vec
<unsigned> name_to_id
;
240 /* Allocate an expression id for EXPR. */
242 static inline unsigned int
243 alloc_expression_id (pre_expr expr
)
245 struct pre_expr_d
**slot
;
246 /* Make sure we won't overflow. */
247 gcc_assert (next_expression_id
+ 1 > next_expression_id
);
248 expr
->id
= next_expression_id
++;
249 expressions
.safe_push (expr
);
250 if (expr
->kind
== NAME
)
252 unsigned version
= SSA_NAME_VERSION (PRE_EXPR_NAME (expr
));
253 /* vec::safe_grow_cleared allocates no headroom. Avoid frequent
254 re-allocations by using vec::reserve upfront. There is no
255 vec::quick_grow_cleared unfortunately. */
256 unsigned old_len
= name_to_id
.length ();
257 name_to_id
.reserve (num_ssa_names
- old_len
);
258 name_to_id
.safe_grow_cleared (num_ssa_names
);
259 gcc_assert (name_to_id
[version
] == 0);
260 name_to_id
[version
] = expr
->id
;
264 slot
= expression_to_id
.find_slot (expr
, INSERT
);
268 return next_expression_id
- 1;
271 /* Return the expression id for tree EXPR. */
273 static inline unsigned int
274 get_expression_id (const pre_expr expr
)
279 static inline unsigned int
280 lookup_expression_id (const pre_expr expr
)
282 struct pre_expr_d
**slot
;
284 if (expr
->kind
== NAME
)
286 unsigned version
= SSA_NAME_VERSION (PRE_EXPR_NAME (expr
));
287 if (name_to_id
.length () <= version
)
289 return name_to_id
[version
];
293 slot
= expression_to_id
.find_slot (expr
, NO_INSERT
);
296 return ((pre_expr
)*slot
)->id
;
300 /* Return the existing expression id for EXPR, or create one if one
301 does not exist yet. */
303 static inline unsigned int
304 get_or_alloc_expression_id (pre_expr expr
)
306 unsigned int id
= lookup_expression_id (expr
);
308 return alloc_expression_id (expr
);
309 return expr
->id
= id
;
312 /* Return the expression that has expression id ID */
314 static inline pre_expr
315 expression_for_id (unsigned int id
)
317 return expressions
[id
];
320 /* Free the expression id field in all of our expressions,
321 and then destroy the expressions array. */
324 clear_expression_ids (void)
326 expressions
.release ();
329 static alloc_pool pre_expr_pool
;
331 /* Given an SSA_NAME NAME, get or create a pre_expr to represent it. */
334 get_or_alloc_expr_for_name (tree name
)
336 struct pre_expr_d expr
;
338 unsigned int result_id
;
342 PRE_EXPR_NAME (&expr
) = name
;
343 result_id
= lookup_expression_id (&expr
);
345 return expression_for_id (result_id
);
347 result
= (pre_expr
) pool_alloc (pre_expr_pool
);
349 PRE_EXPR_NAME (result
) = name
;
350 alloc_expression_id (result
);
354 /* An unordered bitmap set. One bitmap tracks values, the other,
356 typedef struct bitmap_set
358 bitmap_head expressions
;
362 #define FOR_EACH_EXPR_ID_IN_SET(set, id, bi) \
363 EXECUTE_IF_SET_IN_BITMAP(&(set)->expressions, 0, (id), (bi))
365 #define FOR_EACH_VALUE_ID_IN_SET(set, id, bi) \
366 EXECUTE_IF_SET_IN_BITMAP(&(set)->values, 0, (id), (bi))
368 /* Mapping from value id to expressions with that value_id. */
369 static vec
<bitmap
> value_expressions
;
371 /* Sets that we need to keep track of. */
372 typedef struct bb_bitmap_sets
374 /* The EXP_GEN set, which represents expressions/values generated in
376 bitmap_set_t exp_gen
;
378 /* The PHI_GEN set, which represents PHI results generated in a
380 bitmap_set_t phi_gen
;
382 /* The TMP_GEN set, which represents results/temporaries generated
383 in a basic block. IE the LHS of an expression. */
384 bitmap_set_t tmp_gen
;
386 /* The AVAIL_OUT set, which represents which values are available in
387 a given basic block. */
388 bitmap_set_t avail_out
;
390 /* The ANTIC_IN set, which represents which values are anticipatable
391 in a given basic block. */
392 bitmap_set_t antic_in
;
394 /* The PA_IN set, which represents which values are
395 partially anticipatable in a given basic block. */
398 /* The NEW_SETS set, which is used during insertion to augment the
399 AVAIL_OUT set of blocks with the new insertions performed during
400 the current iteration. */
401 bitmap_set_t new_sets
;
403 /* A cache for value_dies_in_block_x. */
406 /* True if we have visited this block during ANTIC calculation. */
407 unsigned int visited
: 1;
409 /* True we have deferred processing this block during ANTIC
410 calculation until its successor is processed. */
411 unsigned int deferred
: 1;
413 /* True when the block contains a call that might not return. */
414 unsigned int contains_may_not_return_call
: 1;
417 #define EXP_GEN(BB) ((bb_value_sets_t) ((BB)->aux))->exp_gen
418 #define PHI_GEN(BB) ((bb_value_sets_t) ((BB)->aux))->phi_gen
419 #define TMP_GEN(BB) ((bb_value_sets_t) ((BB)->aux))->tmp_gen
420 #define AVAIL_OUT(BB) ((bb_value_sets_t) ((BB)->aux))->avail_out
421 #define ANTIC_IN(BB) ((bb_value_sets_t) ((BB)->aux))->antic_in
422 #define PA_IN(BB) ((bb_value_sets_t) ((BB)->aux))->pa_in
423 #define NEW_SETS(BB) ((bb_value_sets_t) ((BB)->aux))->new_sets
424 #define EXPR_DIES(BB) ((bb_value_sets_t) ((BB)->aux))->expr_dies
425 #define BB_VISITED(BB) ((bb_value_sets_t) ((BB)->aux))->visited
426 #define BB_DEFERRED(BB) ((bb_value_sets_t) ((BB)->aux))->deferred
427 #define BB_MAY_NOTRETURN(BB) ((bb_value_sets_t) ((BB)->aux))->contains_may_not_return_call
430 /* Basic block list in postorder. */
431 static int *postorder
;
432 static int postorder_num
;
434 /* This structure is used to keep track of statistics on what
435 optimization PRE was able to perform. */
438 /* The number of RHS computations eliminated by PRE. */
441 /* The number of new expressions/temporaries generated by PRE. */
444 /* The number of inserts found due to partial anticipation */
447 /* The number of new PHI nodes added by PRE. */
450 /* The number of values found constant. */
455 static bool do_partial_partial
;
456 static pre_expr
bitmap_find_leader (bitmap_set_t
, unsigned int);
457 static void bitmap_value_insert_into_set (bitmap_set_t
, pre_expr
);
458 static void bitmap_value_replace_in_set (bitmap_set_t
, pre_expr
);
459 static void bitmap_set_copy (bitmap_set_t
, bitmap_set_t
);
460 static bool bitmap_set_contains_value (bitmap_set_t
, unsigned int);
461 static void bitmap_insert_into_set (bitmap_set_t
, pre_expr
);
462 static void bitmap_insert_into_set_1 (bitmap_set_t
, pre_expr
,
464 static bitmap_set_t
bitmap_set_new (void);
465 static tree
create_expression_by_pieces (basic_block
, pre_expr
, gimple_seq
*,
467 static tree
find_or_generate_expression (basic_block
, tree
, gimple_seq
*);
468 static unsigned int get_expr_value_id (pre_expr
);
470 /* We can add and remove elements and entries to and from sets
471 and hash tables, so we use alloc pools for them. */
473 static alloc_pool bitmap_set_pool
;
474 static bitmap_obstack grand_bitmap_obstack
;
476 /* Set of blocks with statements that have had their EH properties changed. */
477 static bitmap need_eh_cleanup
;
479 /* Set of blocks with statements that have had their AB properties changed. */
480 static bitmap need_ab_cleanup
;
482 /* A three tuple {e, pred, v} used to cache phi translations in the
483 phi_translate_table. */
485 typedef struct expr_pred_trans_d
: typed_free_remove
<expr_pred_trans_d
>
487 /* The expression. */
490 /* The predecessor block along which we translated the expression. */
493 /* The value that resulted from the translation. */
496 /* The hashcode for the expression, pred pair. This is cached for
500 /* hash_table support. */
501 typedef expr_pred_trans_d value_type
;
502 typedef expr_pred_trans_d compare_type
;
503 static inline hashval_t
hash (const value_type
*);
504 static inline int equal (const value_type
*, const compare_type
*);
505 } *expr_pred_trans_t
;
506 typedef const struct expr_pred_trans_d
*const_expr_pred_trans_t
;
509 expr_pred_trans_d::hash (const expr_pred_trans_d
*e
)
515 expr_pred_trans_d::equal (const value_type
*ve1
,
516 const compare_type
*ve2
)
518 basic_block b1
= ve1
->pred
;
519 basic_block b2
= ve2
->pred
;
521 /* If they are not translations for the same basic block, they can't
525 return pre_expr_d::equal (ve1
->e
, ve2
->e
);
528 /* The phi_translate_table caches phi translations for a given
529 expression and predecessor. */
530 static hash_table
<expr_pred_trans_d
> phi_translate_table
;
532 /* Search in the phi translation table for the translation of
533 expression E in basic block PRED.
534 Return the translated value, if found, NULL otherwise. */
536 static inline pre_expr
537 phi_trans_lookup (pre_expr e
, basic_block pred
)
539 expr_pred_trans_t
*slot
;
540 struct expr_pred_trans_d ept
;
544 ept
.hashcode
= iterative_hash_hashval_t (pre_expr_d::hash (e
), pred
->index
);
545 slot
= phi_translate_table
.find_slot_with_hash (&ept
, ept
.hashcode
,
554 /* Add the tuple mapping from {expression E, basic block PRED} to
555 value V, to the phi translation table. */
558 phi_trans_add (pre_expr e
, pre_expr v
, basic_block pred
)
560 expr_pred_trans_t
*slot
;
561 expr_pred_trans_t new_pair
= XNEW (struct expr_pred_trans_d
);
563 new_pair
->pred
= pred
;
565 new_pair
->hashcode
= iterative_hash_hashval_t (pre_expr_d::hash (e
),
568 slot
= phi_translate_table
.find_slot_with_hash (new_pair
,
569 new_pair
->hashcode
, INSERT
);
575 /* Add expression E to the expression set of value id V. */
578 add_to_value (unsigned int v
, pre_expr e
)
582 gcc_checking_assert (get_expr_value_id (e
) == v
);
584 if (v
>= value_expressions
.length ())
586 value_expressions
.safe_grow_cleared (v
+ 1);
589 set
= value_expressions
[v
];
592 set
= BITMAP_ALLOC (&grand_bitmap_obstack
);
593 value_expressions
[v
] = set
;
596 bitmap_set_bit (set
, get_or_alloc_expression_id (e
));
599 /* Create a new bitmap set and return it. */
602 bitmap_set_new (void)
604 bitmap_set_t ret
= (bitmap_set_t
) pool_alloc (bitmap_set_pool
);
605 bitmap_initialize (&ret
->expressions
, &grand_bitmap_obstack
);
606 bitmap_initialize (&ret
->values
, &grand_bitmap_obstack
);
610 /* Return the value id for a PRE expression EXPR. */
613 get_expr_value_id (pre_expr expr
)
619 id
= get_constant_value_id (PRE_EXPR_CONSTANT (expr
));
622 id
= VN_INFO (PRE_EXPR_NAME (expr
))->value_id
;
625 id
= PRE_EXPR_NARY (expr
)->value_id
;
628 id
= PRE_EXPR_REFERENCE (expr
)->value_id
;
633 /* ??? We cannot assert that expr has a value-id (it can be 0), because
634 we assign value-ids only to expressions that have a result
635 in set_hashtable_value_ids. */
639 /* Return a SCCVN valnum (SSA name or constant) for the PRE value-id VAL. */
642 sccvn_valnum_from_value_id (unsigned int val
)
646 bitmap exprset
= value_expressions
[val
];
647 EXECUTE_IF_SET_IN_BITMAP (exprset
, 0, i
, bi
)
649 pre_expr vexpr
= expression_for_id (i
);
650 if (vexpr
->kind
== NAME
)
651 return VN_INFO (PRE_EXPR_NAME (vexpr
))->valnum
;
652 else if (vexpr
->kind
== CONSTANT
)
653 return PRE_EXPR_CONSTANT (vexpr
);
658 /* Remove an expression EXPR from a bitmapped set. */
661 bitmap_remove_from_set (bitmap_set_t set
, pre_expr expr
)
663 unsigned int val
= get_expr_value_id (expr
);
664 if (!value_id_constant_p (val
))
666 bitmap_clear_bit (&set
->values
, val
);
667 bitmap_clear_bit (&set
->expressions
, get_expression_id (expr
));
672 bitmap_insert_into_set_1 (bitmap_set_t set
, pre_expr expr
,
673 unsigned int val
, bool allow_constants
)
675 if (allow_constants
|| !value_id_constant_p (val
))
677 /* We specifically expect this and only this function to be able to
678 insert constants into a set. */
679 bitmap_set_bit (&set
->values
, val
);
680 bitmap_set_bit (&set
->expressions
, get_or_alloc_expression_id (expr
));
684 /* Insert an expression EXPR into a bitmapped set. */
687 bitmap_insert_into_set (bitmap_set_t set
, pre_expr expr
)
689 bitmap_insert_into_set_1 (set
, expr
, get_expr_value_id (expr
), false);
692 /* Copy a bitmapped set ORIG, into bitmapped set DEST. */
695 bitmap_set_copy (bitmap_set_t dest
, bitmap_set_t orig
)
697 bitmap_copy (&dest
->expressions
, &orig
->expressions
);
698 bitmap_copy (&dest
->values
, &orig
->values
);
702 /* Free memory used up by SET. */
704 bitmap_set_free (bitmap_set_t set
)
706 bitmap_clear (&set
->expressions
);
707 bitmap_clear (&set
->values
);
711 /* Generate an topological-ordered array of bitmap set SET. */
714 sorted_array_from_bitmap_set (bitmap_set_t set
)
717 bitmap_iterator bi
, bj
;
718 vec
<pre_expr
> result
;
720 /* Pre-allocate roughly enough space for the array. */
721 result
.create (bitmap_count_bits (&set
->values
));
723 FOR_EACH_VALUE_ID_IN_SET (set
, i
, bi
)
725 /* The number of expressions having a given value is usually
726 relatively small. Thus, rather than making a vector of all
727 the expressions and sorting it by value-id, we walk the values
728 and check in the reverse mapping that tells us what expressions
729 have a given value, to filter those in our set. As a result,
730 the expressions are inserted in value-id order, which means
733 If this is somehow a significant lose for some cases, we can
734 choose which set to walk based on the set size. */
735 bitmap exprset
= value_expressions
[i
];
736 EXECUTE_IF_SET_IN_BITMAP (exprset
, 0, j
, bj
)
738 if (bitmap_bit_p (&set
->expressions
, j
))
739 result
.safe_push (expression_for_id (j
));
746 /* Perform bitmapped set operation DEST &= ORIG. */
749 bitmap_set_and (bitmap_set_t dest
, bitmap_set_t orig
)
757 bitmap_initialize (&temp
, &grand_bitmap_obstack
);
759 bitmap_and_into (&dest
->values
, &orig
->values
);
760 bitmap_copy (&temp
, &dest
->expressions
);
761 EXECUTE_IF_SET_IN_BITMAP (&temp
, 0, i
, bi
)
763 pre_expr expr
= expression_for_id (i
);
764 unsigned int value_id
= get_expr_value_id (expr
);
765 if (!bitmap_bit_p (&dest
->values
, value_id
))
766 bitmap_clear_bit (&dest
->expressions
, i
);
768 bitmap_clear (&temp
);
772 /* Subtract all values and expressions contained in ORIG from DEST. */
775 bitmap_set_subtract (bitmap_set_t dest
, bitmap_set_t orig
)
777 bitmap_set_t result
= bitmap_set_new ();
781 bitmap_and_compl (&result
->expressions
, &dest
->expressions
,
784 FOR_EACH_EXPR_ID_IN_SET (result
, i
, bi
)
786 pre_expr expr
= expression_for_id (i
);
787 unsigned int value_id
= get_expr_value_id (expr
);
788 bitmap_set_bit (&result
->values
, value_id
);
794 /* Subtract all the values in bitmap set B from bitmap set A. */
797 bitmap_set_subtract_values (bitmap_set_t a
, bitmap_set_t b
)
803 bitmap_initialize (&temp
, &grand_bitmap_obstack
);
805 bitmap_copy (&temp
, &a
->expressions
);
806 EXECUTE_IF_SET_IN_BITMAP (&temp
, 0, i
, bi
)
808 pre_expr expr
= expression_for_id (i
);
809 if (bitmap_set_contains_value (b
, get_expr_value_id (expr
)))
810 bitmap_remove_from_set (a
, expr
);
812 bitmap_clear (&temp
);
816 /* Return true if bitmapped set SET contains the value VALUE_ID. */
819 bitmap_set_contains_value (bitmap_set_t set
, unsigned int value_id
)
821 if (value_id_constant_p (value_id
))
824 if (!set
|| bitmap_empty_p (&set
->expressions
))
827 return bitmap_bit_p (&set
->values
, value_id
);
831 bitmap_set_contains_expr (bitmap_set_t set
, const pre_expr expr
)
833 return bitmap_bit_p (&set
->expressions
, get_expression_id (expr
));
836 /* Replace an instance of value LOOKFOR with expression EXPR in SET. */
839 bitmap_set_replace_value (bitmap_set_t set
, unsigned int lookfor
,
846 if (value_id_constant_p (lookfor
))
849 if (!bitmap_set_contains_value (set
, lookfor
))
852 /* The number of expressions having a given value is usually
853 significantly less than the total number of expressions in SET.
854 Thus, rather than check, for each expression in SET, whether it
855 has the value LOOKFOR, we walk the reverse mapping that tells us
856 what expressions have a given value, and see if any of those
857 expressions are in our set. For large testcases, this is about
858 5-10x faster than walking the bitmap. If this is somehow a
859 significant lose for some cases, we can choose which set to walk
860 based on the set size. */
861 exprset
= value_expressions
[lookfor
];
862 EXECUTE_IF_SET_IN_BITMAP (exprset
, 0, i
, bi
)
864 if (bitmap_clear_bit (&set
->expressions
, i
))
866 bitmap_set_bit (&set
->expressions
, get_expression_id (expr
));
872 /* Return true if two bitmap sets are equal. */
875 bitmap_set_equal (bitmap_set_t a
, bitmap_set_t b
)
877 return bitmap_equal_p (&a
->values
, &b
->values
);
880 /* Replace an instance of EXPR's VALUE with EXPR in SET if it exists,
881 and add it otherwise. */
884 bitmap_value_replace_in_set (bitmap_set_t set
, pre_expr expr
)
886 unsigned int val
= get_expr_value_id (expr
);
888 if (bitmap_set_contains_value (set
, val
))
889 bitmap_set_replace_value (set
, val
, expr
);
891 bitmap_insert_into_set (set
, expr
);
894 /* Insert EXPR into SET if EXPR's value is not already present in
898 bitmap_value_insert_into_set (bitmap_set_t set
, pre_expr expr
)
900 unsigned int val
= get_expr_value_id (expr
);
902 gcc_checking_assert (expr
->id
== get_or_alloc_expression_id (expr
));
904 /* Constant values are always considered to be part of the set. */
905 if (value_id_constant_p (val
))
908 /* If the value membership changed, add the expression. */
909 if (bitmap_set_bit (&set
->values
, val
))
910 bitmap_set_bit (&set
->expressions
, expr
->id
);
913 /* Print out EXPR to outfile. */
916 print_pre_expr (FILE *outfile
, const pre_expr expr
)
921 print_generic_expr (outfile
, PRE_EXPR_CONSTANT (expr
), 0);
924 print_generic_expr (outfile
, PRE_EXPR_NAME (expr
), 0);
929 vn_nary_op_t nary
= PRE_EXPR_NARY (expr
);
930 fprintf (outfile
, "{%s,", tree_code_name
[nary
->opcode
]);
931 for (i
= 0; i
< nary
->length
; i
++)
933 print_generic_expr (outfile
, nary
->op
[i
], 0);
934 if (i
!= (unsigned) nary
->length
- 1)
935 fprintf (outfile
, ",");
937 fprintf (outfile
, "}");
943 vn_reference_op_t vro
;
945 vn_reference_t ref
= PRE_EXPR_REFERENCE (expr
);
946 fprintf (outfile
, "{");
948 ref
->operands
.iterate (i
, &vro
);
951 bool closebrace
= false;
952 if (vro
->opcode
!= SSA_NAME
953 && TREE_CODE_CLASS (vro
->opcode
) != tcc_declaration
)
955 fprintf (outfile
, "%s", tree_code_name
[vro
->opcode
]);
958 fprintf (outfile
, "<");
964 print_generic_expr (outfile
, vro
->op0
, 0);
967 fprintf (outfile
, ",");
968 print_generic_expr (outfile
, vro
->op1
, 0);
972 fprintf (outfile
, ",");
973 print_generic_expr (outfile
, vro
->op2
, 0);
977 fprintf (outfile
, ">");
978 if (i
!= ref
->operands
.length () - 1)
979 fprintf (outfile
, ",");
981 fprintf (outfile
, "}");
984 fprintf (outfile
, "@");
985 print_generic_expr (outfile
, ref
->vuse
, 0);
991 void debug_pre_expr (pre_expr
);
993 /* Like print_pre_expr but always prints to stderr. */
995 debug_pre_expr (pre_expr e
)
997 print_pre_expr (stderr
, e
);
998 fprintf (stderr
, "\n");
1001 /* Print out SET to OUTFILE. */
1004 print_bitmap_set (FILE *outfile
, bitmap_set_t set
,
1005 const char *setname
, int blockindex
)
1007 fprintf (outfile
, "%s[%d] := { ", setname
, blockindex
);
1014 FOR_EACH_EXPR_ID_IN_SET (set
, i
, bi
)
1016 const pre_expr expr
= expression_for_id (i
);
1019 fprintf (outfile
, ", ");
1021 print_pre_expr (outfile
, expr
);
1023 fprintf (outfile
, " (%04d)", get_expr_value_id (expr
));
1026 fprintf (outfile
, " }\n");
1029 void debug_bitmap_set (bitmap_set_t
);
1032 debug_bitmap_set (bitmap_set_t set
)
1034 print_bitmap_set (stderr
, set
, "debug", 0);
1037 void debug_bitmap_sets_for (basic_block
);
1040 debug_bitmap_sets_for (basic_block bb
)
1042 print_bitmap_set (stderr
, AVAIL_OUT (bb
), "avail_out", bb
->index
);
1043 print_bitmap_set (stderr
, EXP_GEN (bb
), "exp_gen", bb
->index
);
1044 print_bitmap_set (stderr
, PHI_GEN (bb
), "phi_gen", bb
->index
);
1045 print_bitmap_set (stderr
, TMP_GEN (bb
), "tmp_gen", bb
->index
);
1046 print_bitmap_set (stderr
, ANTIC_IN (bb
), "antic_in", bb
->index
);
1047 if (do_partial_partial
)
1048 print_bitmap_set (stderr
, PA_IN (bb
), "pa_in", bb
->index
);
1049 print_bitmap_set (stderr
, NEW_SETS (bb
), "new_sets", bb
->index
);
1052 /* Print out the expressions that have VAL to OUTFILE. */
1055 print_value_expressions (FILE *outfile
, unsigned int val
)
1057 bitmap set
= value_expressions
[val
];
1062 sprintf (s
, "%04d", val
);
1063 x
.expressions
= *set
;
1064 print_bitmap_set (outfile
, &x
, s
, 0);
1070 debug_value_expressions (unsigned int val
)
1072 print_value_expressions (stderr
, val
);
1075 /* Given a CONSTANT, allocate a new CONSTANT type PRE_EXPR to
1079 get_or_alloc_expr_for_constant (tree constant
)
1081 unsigned int result_id
;
1082 unsigned int value_id
;
1083 struct pre_expr_d expr
;
1086 expr
.kind
= CONSTANT
;
1087 PRE_EXPR_CONSTANT (&expr
) = constant
;
1088 result_id
= lookup_expression_id (&expr
);
1090 return expression_for_id (result_id
);
1092 newexpr
= (pre_expr
) pool_alloc (pre_expr_pool
);
1093 newexpr
->kind
= CONSTANT
;
1094 PRE_EXPR_CONSTANT (newexpr
) = constant
;
1095 alloc_expression_id (newexpr
);
1096 value_id
= get_or_alloc_constant_value_id (constant
);
1097 add_to_value (value_id
, newexpr
);
1101 /* Given a value id V, find the actual tree representing the constant
1102 value if there is one, and return it. Return NULL if we can't find
1106 get_constant_for_value_id (unsigned int v
)
1108 if (value_id_constant_p (v
))
1112 bitmap exprset
= value_expressions
[v
];
1114 EXECUTE_IF_SET_IN_BITMAP (exprset
, 0, i
, bi
)
1116 pre_expr expr
= expression_for_id (i
);
1117 if (expr
->kind
== CONSTANT
)
1118 return PRE_EXPR_CONSTANT (expr
);
1124 /* Get or allocate a pre_expr for a piece of GIMPLE, and return it.
1125 Currently only supports constants and SSA_NAMES. */
1127 get_or_alloc_expr_for (tree t
)
1129 if (TREE_CODE (t
) == SSA_NAME
)
1130 return get_or_alloc_expr_for_name (t
);
1131 else if (is_gimple_min_invariant (t
))
1132 return get_or_alloc_expr_for_constant (t
);
1135 /* More complex expressions can result from SCCVN expression
1136 simplification that inserts values for them. As they all
1137 do not have VOPs the get handled by the nary ops struct. */
1138 vn_nary_op_t result
;
1139 unsigned int result_id
;
1140 vn_nary_op_lookup (t
, &result
);
1143 pre_expr e
= (pre_expr
) pool_alloc (pre_expr_pool
);
1145 PRE_EXPR_NARY (e
) = result
;
1146 result_id
= lookup_expression_id (e
);
1149 pool_free (pre_expr_pool
, e
);
1150 e
= expression_for_id (result_id
);
1153 alloc_expression_id (e
);
1160 /* Return the folded version of T if T, when folded, is a gimple
1161 min_invariant. Otherwise, return T. */
1164 fully_constant_expression (pre_expr e
)
1172 vn_nary_op_t nary
= PRE_EXPR_NARY (e
);
1173 switch (TREE_CODE_CLASS (nary
->opcode
))
1176 case tcc_comparison
:
1178 /* We have to go from trees to pre exprs to value ids to
1180 tree naryop0
= nary
->op
[0];
1181 tree naryop1
= nary
->op
[1];
1183 if (!is_gimple_min_invariant (naryop0
))
1185 pre_expr rep0
= get_or_alloc_expr_for (naryop0
);
1186 unsigned int vrep0
= get_expr_value_id (rep0
);
1187 tree const0
= get_constant_for_value_id (vrep0
);
1189 naryop0
= fold_convert (TREE_TYPE (naryop0
), const0
);
1191 if (!is_gimple_min_invariant (naryop1
))
1193 pre_expr rep1
= get_or_alloc_expr_for (naryop1
);
1194 unsigned int vrep1
= get_expr_value_id (rep1
);
1195 tree const1
= get_constant_for_value_id (vrep1
);
1197 naryop1
= fold_convert (TREE_TYPE (naryop1
), const1
);
1199 result
= fold_binary (nary
->opcode
, nary
->type
,
1201 if (result
&& is_gimple_min_invariant (result
))
1202 return get_or_alloc_expr_for_constant (result
);
1203 /* We might have simplified the expression to a
1204 SSA_NAME for example from x_1 * 1. But we cannot
1205 insert a PHI for x_1 unconditionally as x_1 might
1206 not be available readily. */
1210 if (nary
->opcode
!= REALPART_EXPR
1211 && nary
->opcode
!= IMAGPART_EXPR
1212 && nary
->opcode
!= VIEW_CONVERT_EXPR
)
1217 /* We have to go from trees to pre exprs to value ids to
1219 tree naryop0
= nary
->op
[0];
1220 tree const0
, result
;
1221 if (is_gimple_min_invariant (naryop0
))
1225 pre_expr rep0
= get_or_alloc_expr_for (naryop0
);
1226 unsigned int vrep0
= get_expr_value_id (rep0
);
1227 const0
= get_constant_for_value_id (vrep0
);
1232 tree type1
= TREE_TYPE (nary
->op
[0]);
1233 const0
= fold_convert (type1
, const0
);
1234 result
= fold_unary (nary
->opcode
, nary
->type
, const0
);
1236 if (result
&& is_gimple_min_invariant (result
))
1237 return get_or_alloc_expr_for_constant (result
);
1246 vn_reference_t ref
= PRE_EXPR_REFERENCE (e
);
1248 if ((folded
= fully_constant_vn_reference_p (ref
)))
1249 return get_or_alloc_expr_for_constant (folded
);
1258 /* Translate the VUSE backwards through phi nodes in PHIBLOCK, so that
1259 it has the value it would have in BLOCK. Set *SAME_VALID to true
1260 in case the new vuse doesn't change the value id of the OPERANDS. */
1263 translate_vuse_through_block (vec
<vn_reference_op_s
> operands
,
1264 alias_set_type set
, tree type
, tree vuse
,
1265 basic_block phiblock
,
1266 basic_block block
, bool *same_valid
)
1268 gimple phi
= SSA_NAME_DEF_STMT (vuse
);
1275 if (gimple_bb (phi
) != phiblock
)
1278 use_oracle
= ao_ref_init_from_vn_reference (&ref
, set
, type
, operands
);
1280 /* Use the alias-oracle to find either the PHI node in this block,
1281 the first VUSE used in this block that is equivalent to vuse or
1282 the first VUSE which definition in this block kills the value. */
1283 if (gimple_code (phi
) == GIMPLE_PHI
)
1284 e
= find_edge (block
, phiblock
);
1285 else if (use_oracle
)
1286 while (!stmt_may_clobber_ref_p_1 (phi
, &ref
))
1288 vuse
= gimple_vuse (phi
);
1289 phi
= SSA_NAME_DEF_STMT (vuse
);
1290 if (gimple_bb (phi
) != phiblock
)
1292 if (gimple_code (phi
) == GIMPLE_PHI
)
1294 e
= find_edge (block
, phiblock
);
1305 bitmap visited
= NULL
;
1307 /* Try to find a vuse that dominates this phi node by skipping
1308 non-clobbering statements. */
1309 vuse
= get_continuation_for_phi (phi
, &ref
, &cnt
, &visited
, false);
1311 BITMAP_FREE (visited
);
1317 /* If we didn't find any, the value ID can't stay the same,
1318 but return the translated vuse. */
1319 *same_valid
= false;
1320 vuse
= PHI_ARG_DEF (phi
, e
->dest_idx
);
1322 /* ??? We would like to return vuse here as this is the canonical
1323 upmost vdef that this reference is associated with. But during
1324 insertion of the references into the hash tables we only ever
1325 directly insert with their direct gimple_vuse, hence returning
1326 something else would make us not find the other expression. */
1327 return PHI_ARG_DEF (phi
, e
->dest_idx
);
1333 /* Like bitmap_find_leader, but checks for the value existing in SET1 *or*
1334 SET2. This is used to avoid making a set consisting of the union
1335 of PA_IN and ANTIC_IN during insert. */
1337 static inline pre_expr
1338 find_leader_in_sets (unsigned int val
, bitmap_set_t set1
, bitmap_set_t set2
)
1342 result
= bitmap_find_leader (set1
, val
);
1343 if (!result
&& set2
)
1344 result
= bitmap_find_leader (set2
, val
);
1348 /* Get the tree type for our PRE expression e. */
1351 get_expr_type (const pre_expr e
)
1356 return TREE_TYPE (PRE_EXPR_NAME (e
));
1358 return TREE_TYPE (PRE_EXPR_CONSTANT (e
));
1360 return PRE_EXPR_REFERENCE (e
)->type
;
1362 return PRE_EXPR_NARY (e
)->type
;
1367 /* Get a representative SSA_NAME for a given expression.
1368 Since all of our sub-expressions are treated as values, we require
1369 them to be SSA_NAME's for simplicity.
1370 Prior versions of GVNPRE used to use "value handles" here, so that
1371 an expression would be VH.11 + VH.10 instead of d_3 + e_6. In
1372 either case, the operands are really values (IE we do not expect
1373 them to be usable without finding leaders). */
1376 get_representative_for (const pre_expr e
)
1379 unsigned int value_id
= get_expr_value_id (e
);
1384 return PRE_EXPR_NAME (e
);
1386 return PRE_EXPR_CONSTANT (e
);
1390 /* Go through all of the expressions representing this value
1391 and pick out an SSA_NAME. */
1394 bitmap exprs
= value_expressions
[value_id
];
1395 EXECUTE_IF_SET_IN_BITMAP (exprs
, 0, i
, bi
)
1397 pre_expr rep
= expression_for_id (i
);
1398 if (rep
->kind
== NAME
)
1399 return PRE_EXPR_NAME (rep
);
1404 /* If we reached here we couldn't find an SSA_NAME. This can
1405 happen when we've discovered a value that has never appeared in
1406 the program as set to an SSA_NAME, most likely as the result of
1411 "Could not find SSA_NAME representative for expression:");
1412 print_pre_expr (dump_file
, e
);
1413 fprintf (dump_file
, "\n");
1416 /* Build and insert the assignment of the end result to the temporary
1417 that we will return. */
1418 name
= make_temp_ssa_name (get_expr_type (e
), gimple_build_nop (), "pretmp");
1419 VN_INFO_GET (name
)->value_id
= value_id
;
1420 VN_INFO (name
)->valnum
= sccvn_valnum_from_value_id (value_id
);
1421 if (VN_INFO (name
)->valnum
== NULL_TREE
)
1422 VN_INFO (name
)->valnum
= name
;
1423 add_to_value (value_id
, get_or_alloc_expr_for_name (name
));
1426 fprintf (dump_file
, "Created SSA_NAME representative ");
1427 print_generic_expr (dump_file
, name
, 0);
1428 fprintf (dump_file
, " for expression:");
1429 print_pre_expr (dump_file
, e
);
1430 fprintf (dump_file
, "\n");
1439 phi_translate (pre_expr expr
, bitmap_set_t set1
, bitmap_set_t set2
,
1440 basic_block pred
, basic_block phiblock
);
1442 /* Translate EXPR using phis in PHIBLOCK, so that it has the values of
1443 the phis in PRED. Return NULL if we can't find a leader for each part
1444 of the translated expression. */
1447 phi_translate_1 (pre_expr expr
, bitmap_set_t set1
, bitmap_set_t set2
,
1448 basic_block pred
, basic_block phiblock
)
1455 bool changed
= false;
1456 vn_nary_op_t nary
= PRE_EXPR_NARY (expr
);
1457 vn_nary_op_t newnary
= XALLOCAVAR (struct vn_nary_op_s
,
1458 sizeof_vn_nary_op (nary
->length
));
1459 memcpy (newnary
, nary
, sizeof_vn_nary_op (nary
->length
));
1461 for (i
= 0; i
< newnary
->length
; i
++)
1463 if (TREE_CODE (newnary
->op
[i
]) != SSA_NAME
)
1467 pre_expr leader
, result
;
1468 unsigned int op_val_id
= VN_INFO (newnary
->op
[i
])->value_id
;
1469 leader
= find_leader_in_sets (op_val_id
, set1
, set2
);
1470 result
= phi_translate (leader
, set1
, set2
, pred
, phiblock
);
1471 if (result
&& result
!= leader
)
1473 tree name
= get_representative_for (result
);
1476 newnary
->op
[i
] = name
;
1481 changed
|= newnary
->op
[i
] != nary
->op
[i
];
1487 unsigned int new_val_id
;
1489 tree result
= vn_nary_op_lookup_pieces (newnary
->length
,
1494 if (result
&& is_gimple_min_invariant (result
))
1495 return get_or_alloc_expr_for_constant (result
);
1497 expr
= (pre_expr
) pool_alloc (pre_expr_pool
);
1502 PRE_EXPR_NARY (expr
) = nary
;
1503 constant
= fully_constant_expression (expr
);
1504 if (constant
!= expr
)
1507 new_val_id
= nary
->value_id
;
1508 get_or_alloc_expression_id (expr
);
1512 new_val_id
= get_next_value_id ();
1513 value_expressions
.safe_grow_cleared (get_max_value_id() + 1);
1514 nary
= vn_nary_op_insert_pieces (newnary
->length
,
1518 result
, new_val_id
);
1519 PRE_EXPR_NARY (expr
) = nary
;
1520 constant
= fully_constant_expression (expr
);
1521 if (constant
!= expr
)
1523 get_or_alloc_expression_id (expr
);
1525 add_to_value (new_val_id
, expr
);
1533 vn_reference_t ref
= PRE_EXPR_REFERENCE (expr
);
1534 vec
<vn_reference_op_s
> operands
= ref
->operands
;
1535 tree vuse
= ref
->vuse
;
1536 tree newvuse
= vuse
;
1537 vec
<vn_reference_op_s
> newoperands
= vNULL
;
1538 bool changed
= false, same_valid
= true;
1539 unsigned int i
, j
, n
;
1540 vn_reference_op_t operand
;
1541 vn_reference_t newref
;
1544 operands
.iterate (i
, &operand
); i
++, j
++)
1549 tree type
= operand
->type
;
1550 vn_reference_op_s newop
= *operand
;
1551 op
[0] = operand
->op0
;
1552 op
[1] = operand
->op1
;
1553 op
[2] = operand
->op2
;
1554 for (n
= 0; n
< 3; ++n
)
1556 unsigned int op_val_id
;
1559 if (TREE_CODE (op
[n
]) != SSA_NAME
)
1561 /* We can't possibly insert these. */
1563 && !is_gimple_min_invariant (op
[n
]))
1567 op_val_id
= VN_INFO (op
[n
])->value_id
;
1568 leader
= find_leader_in_sets (op_val_id
, set1
, set2
);
1571 /* Make sure we do not recursively translate ourselves
1572 like for translating a[n_1] with the leader for
1573 n_1 being a[n_1]. */
1574 if (get_expression_id (leader
) != get_expression_id (expr
))
1576 opresult
= phi_translate (leader
, set1
, set2
,
1580 if (opresult
!= leader
)
1582 tree name
= get_representative_for (opresult
);
1585 changed
|= name
!= op
[n
];
1592 newoperands
.release ();
1595 if (!newoperands
.exists ())
1596 newoperands
= operands
.copy ();
1597 /* We may have changed from an SSA_NAME to a constant */
1598 if (newop
.opcode
== SSA_NAME
&& TREE_CODE (op
[0]) != SSA_NAME
)
1599 newop
.opcode
= TREE_CODE (op
[0]);
1604 /* If it transforms a non-constant ARRAY_REF into a constant
1605 one, adjust the constant offset. */
1606 if (newop
.opcode
== ARRAY_REF
1608 && TREE_CODE (op
[0]) == INTEGER_CST
1609 && TREE_CODE (op
[1]) == INTEGER_CST
1610 && TREE_CODE (op
[2]) == INTEGER_CST
)
1612 double_int off
= tree_to_double_int (op
[0]);
1613 off
+= -tree_to_double_int (op
[1]);
1614 off
*= tree_to_double_int (op
[2]);
1615 if (off
.fits_shwi ())
1616 newop
.off
= off
.low
;
1618 newoperands
[j
] = newop
;
1619 /* If it transforms from an SSA_NAME to an address, fold with
1620 a preceding indirect reference. */
1621 if (j
> 0 && op
[0] && TREE_CODE (op
[0]) == ADDR_EXPR
1622 && newoperands
[j
- 1].opcode
== MEM_REF
)
1623 vn_reference_fold_indirect (&newoperands
, &j
);
1625 if (i
!= operands
.length ())
1627 newoperands
.release ();
1633 newvuse
= translate_vuse_through_block (newoperands
,
1634 ref
->set
, ref
->type
,
1635 vuse
, phiblock
, pred
,
1637 if (newvuse
== NULL_TREE
)
1639 newoperands
.release ();
1644 if (changed
|| newvuse
!= vuse
)
1646 unsigned int new_val_id
;
1649 tree result
= vn_reference_lookup_pieces (newvuse
, ref
->set
,
1654 newoperands
.release ();
1656 /* We can always insert constants, so if we have a partial
1657 redundant constant load of another type try to translate it
1658 to a constant of appropriate type. */
1659 if (result
&& is_gimple_min_invariant (result
))
1662 if (!useless_type_conversion_p (ref
->type
, TREE_TYPE (result
)))
1664 tem
= fold_unary (VIEW_CONVERT_EXPR
, ref
->type
, result
);
1665 if (tem
&& !is_gimple_min_invariant (tem
))
1669 return get_or_alloc_expr_for_constant (tem
);
1672 /* If we'd have to convert things we would need to validate
1673 if we can insert the translated expression. So fail
1674 here for now - we cannot insert an alias with a different
1675 type in the VN tables either, as that would assert. */
1677 && !useless_type_conversion_p (ref
->type
, TREE_TYPE (result
)))
1679 else if (!result
&& newref
1680 && !useless_type_conversion_p (ref
->type
, newref
->type
))
1682 newoperands
.release ();
1686 expr
= (pre_expr
) pool_alloc (pre_expr_pool
);
1687 expr
->kind
= REFERENCE
;
1692 PRE_EXPR_REFERENCE (expr
) = newref
;
1693 constant
= fully_constant_expression (expr
);
1694 if (constant
!= expr
)
1697 new_val_id
= newref
->value_id
;
1698 get_or_alloc_expression_id (expr
);
1702 if (changed
|| !same_valid
)
1704 new_val_id
= get_next_value_id ();
1705 value_expressions
.safe_grow_cleared(get_max_value_id() + 1);
1708 new_val_id
= ref
->value_id
;
1709 newref
= vn_reference_insert_pieces (newvuse
, ref
->set
,
1712 result
, new_val_id
);
1713 newoperands
.create (0);
1714 PRE_EXPR_REFERENCE (expr
) = newref
;
1715 constant
= fully_constant_expression (expr
);
1716 if (constant
!= expr
)
1718 get_or_alloc_expression_id (expr
);
1720 add_to_value (new_val_id
, expr
);
1722 newoperands
.release ();
1729 tree name
= PRE_EXPR_NAME (expr
);
1730 gimple def_stmt
= SSA_NAME_DEF_STMT (name
);
1731 /* If the SSA name is defined by a PHI node in this block,
1733 if (gimple_code (def_stmt
) == GIMPLE_PHI
1734 && gimple_bb (def_stmt
) == phiblock
)
1736 edge e
= find_edge (pred
, gimple_bb (def_stmt
));
1737 tree def
= PHI_ARG_DEF (def_stmt
, e
->dest_idx
);
1739 /* Handle constant. */
1740 if (is_gimple_min_invariant (def
))
1741 return get_or_alloc_expr_for_constant (def
);
1743 return get_or_alloc_expr_for_name (def
);
1745 /* Otherwise return it unchanged - it will get cleaned if its
1746 value is not available in PREDs AVAIL_OUT set of expressions. */
1755 /* Wrapper around phi_translate_1 providing caching functionality. */
1758 phi_translate (pre_expr expr
, bitmap_set_t set1
, bitmap_set_t set2
,
1759 basic_block pred
, basic_block phiblock
)
1766 /* Constants contain no values that need translation. */
1767 if (expr
->kind
== CONSTANT
)
1770 if (value_id_constant_p (get_expr_value_id (expr
)))
1773 if (expr
->kind
!= NAME
)
1775 phitrans
= phi_trans_lookup (expr
, pred
);
1781 phitrans
= phi_translate_1 (expr
, set1
, set2
, pred
, phiblock
);
1783 /* Don't add empty translations to the cache. Neither add
1784 translations of NAMEs as those are cheap to translate. */
1786 && expr
->kind
!= NAME
)
1787 phi_trans_add (expr
, phitrans
, pred
);
1793 /* For each expression in SET, translate the values through phi nodes
1794 in PHIBLOCK using edge PHIBLOCK->PRED, and store the resulting
1795 expressions in DEST. */
1798 phi_translate_set (bitmap_set_t dest
, bitmap_set_t set
, basic_block pred
,
1799 basic_block phiblock
)
1801 vec
<pre_expr
> exprs
;
1805 if (gimple_seq_empty_p (phi_nodes (phiblock
)))
1807 bitmap_set_copy (dest
, set
);
1811 exprs
= sorted_array_from_bitmap_set (set
);
1812 FOR_EACH_VEC_ELT (exprs
, i
, expr
)
1814 pre_expr translated
;
1815 translated
= phi_translate (expr
, set
, NULL
, pred
, phiblock
);
1819 /* We might end up with multiple expressions from SET being
1820 translated to the same value. In this case we do not want
1821 to retain the NARY or REFERENCE expression but prefer a NAME
1822 which would be the leader. */
1823 if (translated
->kind
== NAME
)
1824 bitmap_value_replace_in_set (dest
, translated
);
1826 bitmap_value_insert_into_set (dest
, translated
);
1831 /* Find the leader for a value (i.e., the name representing that
1832 value) in a given set, and return it. If STMT is non-NULL it
1833 makes sure the defining statement for the leader dominates it.
1834 Return NULL if no leader is found. */
1837 bitmap_find_leader (bitmap_set_t set
, unsigned int val
)
1839 if (value_id_constant_p (val
))
1843 bitmap exprset
= value_expressions
[val
];
1845 EXECUTE_IF_SET_IN_BITMAP (exprset
, 0, i
, bi
)
1847 pre_expr expr
= expression_for_id (i
);
1848 if (expr
->kind
== CONSTANT
)
1852 if (bitmap_set_contains_value (set
, val
))
1854 /* Rather than walk the entire bitmap of expressions, and see
1855 whether any of them has the value we are looking for, we look
1856 at the reverse mapping, which tells us the set of expressions
1857 that have a given value (IE value->expressions with that
1858 value) and see if any of those expressions are in our set.
1859 The number of expressions per value is usually significantly
1860 less than the number of expressions in the set. In fact, for
1861 large testcases, doing it this way is roughly 5-10x faster
1862 than walking the bitmap.
1863 If this is somehow a significant lose for some cases, we can
1864 choose which set to walk based on which set is smaller. */
1867 bitmap exprset
= value_expressions
[val
];
1869 EXECUTE_IF_AND_IN_BITMAP (exprset
, &set
->expressions
, 0, i
, bi
)
1870 return expression_for_id (i
);
1875 /* Determine if EXPR, a memory expression, is ANTIC_IN at the top of
1876 BLOCK by seeing if it is not killed in the block. Note that we are
1877 only determining whether there is a store that kills it. Because
1878 of the order in which clean iterates over values, we are guaranteed
1879 that altered operands will have caused us to be eliminated from the
1880 ANTIC_IN set already. */
1883 value_dies_in_block_x (pre_expr expr
, basic_block block
)
1885 tree vuse
= PRE_EXPR_REFERENCE (expr
)->vuse
;
1886 vn_reference_t refx
= PRE_EXPR_REFERENCE (expr
);
1888 gimple_stmt_iterator gsi
;
1889 unsigned id
= get_expression_id (expr
);
1896 /* Lookup a previously calculated result. */
1897 if (EXPR_DIES (block
)
1898 && bitmap_bit_p (EXPR_DIES (block
), id
* 2))
1899 return bitmap_bit_p (EXPR_DIES (block
), id
* 2 + 1);
1901 /* A memory expression {e, VUSE} dies in the block if there is a
1902 statement that may clobber e. If, starting statement walk from the
1903 top of the basic block, a statement uses VUSE there can be no kill
1904 inbetween that use and the original statement that loaded {e, VUSE},
1905 so we can stop walking. */
1906 ref
.base
= NULL_TREE
;
1907 for (gsi
= gsi_start_bb (block
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1909 tree def_vuse
, def_vdef
;
1910 def
= gsi_stmt (gsi
);
1911 def_vuse
= gimple_vuse (def
);
1912 def_vdef
= gimple_vdef (def
);
1914 /* Not a memory statement. */
1918 /* Not a may-def. */
1921 /* A load with the same VUSE, we're done. */
1922 if (def_vuse
== vuse
)
1928 /* Init ref only if we really need it. */
1929 if (ref
.base
== NULL_TREE
1930 && !ao_ref_init_from_vn_reference (&ref
, refx
->set
, refx
->type
,
1936 /* If the statement may clobber expr, it dies. */
1937 if (stmt_may_clobber_ref_p_1 (def
, &ref
))
1944 /* Remember the result. */
1945 if (!EXPR_DIES (block
))
1946 EXPR_DIES (block
) = BITMAP_ALLOC (&grand_bitmap_obstack
);
1947 bitmap_set_bit (EXPR_DIES (block
), id
* 2);
1949 bitmap_set_bit (EXPR_DIES (block
), id
* 2 + 1);
1955 /* Determine if OP is valid in SET1 U SET2, which it is when the union
1956 contains its value-id. */
1959 op_valid_in_sets (bitmap_set_t set1
, bitmap_set_t set2
, tree op
)
1961 if (op
&& TREE_CODE (op
) == SSA_NAME
)
1963 unsigned int value_id
= VN_INFO (op
)->value_id
;
1964 if (!(bitmap_set_contains_value (set1
, value_id
)
1965 || (set2
&& bitmap_set_contains_value (set2
, value_id
))))
1971 /* Determine if the expression EXPR is valid in SET1 U SET2.
1972 ONLY SET2 CAN BE NULL.
1973 This means that we have a leader for each part of the expression
1974 (if it consists of values), or the expression is an SSA_NAME.
1975 For loads/calls, we also see if the vuse is killed in this block. */
1978 valid_in_sets (bitmap_set_t set1
, bitmap_set_t set2
, pre_expr expr
,
1984 return bitmap_set_contains_expr (AVAIL_OUT (block
), expr
);
1988 vn_nary_op_t nary
= PRE_EXPR_NARY (expr
);
1989 for (i
= 0; i
< nary
->length
; i
++)
1990 if (!op_valid_in_sets (set1
, set2
, nary
->op
[i
]))
1997 vn_reference_t ref
= PRE_EXPR_REFERENCE (expr
);
1998 vn_reference_op_t vro
;
2001 FOR_EACH_VEC_ELT (ref
->operands
, i
, vro
)
2003 if (!op_valid_in_sets (set1
, set2
, vro
->op0
)
2004 || !op_valid_in_sets (set1
, set2
, vro
->op1
)
2005 || !op_valid_in_sets (set1
, set2
, vro
->op2
))
2015 /* Clean the set of expressions that are no longer valid in SET1 or
2016 SET2. This means expressions that are made up of values we have no
2017 leaders for in SET1 or SET2. This version is used for partial
2018 anticipation, which means it is not valid in either ANTIC_IN or
2022 dependent_clean (bitmap_set_t set1
, bitmap_set_t set2
, basic_block block
)
2024 vec
<pre_expr
> exprs
= sorted_array_from_bitmap_set (set1
);
2028 FOR_EACH_VEC_ELT (exprs
, i
, expr
)
2030 if (!valid_in_sets (set1
, set2
, expr
, block
))
2031 bitmap_remove_from_set (set1
, expr
);
2036 /* Clean the set of expressions that are no longer valid in SET. This
2037 means expressions that are made up of values we have no leaders for
2041 clean (bitmap_set_t set
, basic_block block
)
2043 vec
<pre_expr
> exprs
= sorted_array_from_bitmap_set (set
);
2047 FOR_EACH_VEC_ELT (exprs
, i
, expr
)
2049 if (!valid_in_sets (set
, NULL
, expr
, block
))
2050 bitmap_remove_from_set (set
, expr
);
2055 /* Clean the set of expressions that are no longer valid in SET because
2056 they are clobbered in BLOCK or because they trap and may not be executed. */
2059 prune_clobbered_mems (bitmap_set_t set
, basic_block block
)
2064 FOR_EACH_EXPR_ID_IN_SET (set
, i
, bi
)
2066 pre_expr expr
= expression_for_id (i
);
2067 if (expr
->kind
== REFERENCE
)
2069 vn_reference_t ref
= PRE_EXPR_REFERENCE (expr
);
2072 gimple def_stmt
= SSA_NAME_DEF_STMT (ref
->vuse
);
2073 if (!gimple_nop_p (def_stmt
)
2074 && ((gimple_bb (def_stmt
) != block
2075 && !dominated_by_p (CDI_DOMINATORS
,
2076 block
, gimple_bb (def_stmt
)))
2077 || (gimple_bb (def_stmt
) == block
2078 && value_dies_in_block_x (expr
, block
))))
2079 bitmap_remove_from_set (set
, expr
);
2082 else if (expr
->kind
== NARY
)
2084 vn_nary_op_t nary
= PRE_EXPR_NARY (expr
);
2085 /* If the NARY may trap make sure the block does not contain
2086 a possible exit point.
2087 ??? This is overly conservative if we translate AVAIL_OUT
2088 as the available expression might be after the exit point. */
2089 if (BB_MAY_NOTRETURN (block
)
2090 && vn_nary_may_trap (nary
))
2091 bitmap_remove_from_set (set
, expr
);
2096 static sbitmap has_abnormal_preds
;
2098 /* List of blocks that may have changed during ANTIC computation and
2099 thus need to be iterated over. */
2101 static sbitmap changed_blocks
;
2103 /* Decide whether to defer a block for a later iteration, or PHI
2104 translate SOURCE to DEST using phis in PHIBLOCK. Return false if we
2105 should defer the block, and true if we processed it. */
2108 defer_or_phi_translate_block (bitmap_set_t dest
, bitmap_set_t source
,
2109 basic_block block
, basic_block phiblock
)
2111 if (!BB_VISITED (phiblock
))
2113 bitmap_set_bit (changed_blocks
, block
->index
);
2114 BB_VISITED (block
) = 0;
2115 BB_DEFERRED (block
) = 1;
2119 phi_translate_set (dest
, source
, block
, phiblock
);
2123 /* Compute the ANTIC set for BLOCK.
2125 If succs(BLOCK) > 1 then
2126 ANTIC_OUT[BLOCK] = intersection of ANTIC_IN[b] for all succ(BLOCK)
2127 else if succs(BLOCK) == 1 then
2128 ANTIC_OUT[BLOCK] = phi_translate (ANTIC_IN[succ(BLOCK)])
2130 ANTIC_IN[BLOCK] = clean(ANTIC_OUT[BLOCK] U EXP_GEN[BLOCK] - TMP_GEN[BLOCK])
2134 compute_antic_aux (basic_block block
, bool block_has_abnormal_pred_edge
)
2136 bool changed
= false;
2137 bitmap_set_t S
, old
, ANTIC_OUT
;
2143 old
= ANTIC_OUT
= S
= NULL
;
2144 BB_VISITED (block
) = 1;
2146 /* If any edges from predecessors are abnormal, antic_in is empty,
2148 if (block_has_abnormal_pred_edge
)
2149 goto maybe_dump_sets
;
2151 old
= ANTIC_IN (block
);
2152 ANTIC_OUT
= bitmap_set_new ();
2154 /* If the block has no successors, ANTIC_OUT is empty. */
2155 if (EDGE_COUNT (block
->succs
) == 0)
2157 /* If we have one successor, we could have some phi nodes to
2158 translate through. */
2159 else if (single_succ_p (block
))
2161 basic_block succ_bb
= single_succ (block
);
2163 /* We trade iterations of the dataflow equations for having to
2164 phi translate the maximal set, which is incredibly slow
2165 (since the maximal set often has 300+ members, even when you
2166 have a small number of blocks).
2167 Basically, we defer the computation of ANTIC for this block
2168 until we have processed it's successor, which will inevitably
2169 have a *much* smaller set of values to phi translate once
2170 clean has been run on it.
2171 The cost of doing this is that we technically perform more
2172 iterations, however, they are lower cost iterations.
2174 Timings for PRE on tramp3d-v4:
2175 without maximal set fix: 11 seconds
2176 with maximal set fix/without deferring: 26 seconds
2177 with maximal set fix/with deferring: 11 seconds
2180 if (!defer_or_phi_translate_block (ANTIC_OUT
, ANTIC_IN (succ_bb
),
2184 goto maybe_dump_sets
;
2187 /* If we have multiple successors, we take the intersection of all of
2188 them. Note that in the case of loop exit phi nodes, we may have
2189 phis to translate through. */
2192 vec
<basic_block
> worklist
;
2194 basic_block bprime
, first
= NULL
;
2196 worklist
.create (EDGE_COUNT (block
->succs
));
2197 FOR_EACH_EDGE (e
, ei
, block
->succs
)
2200 && BB_VISITED (e
->dest
))
2202 else if (BB_VISITED (e
->dest
))
2203 worklist
.quick_push (e
->dest
);
2206 /* Of multiple successors we have to have visited one already. */
2209 bitmap_set_bit (changed_blocks
, block
->index
);
2210 BB_VISITED (block
) = 0;
2211 BB_DEFERRED (block
) = 1;
2213 worklist
.release ();
2214 goto maybe_dump_sets
;
2217 if (!gimple_seq_empty_p (phi_nodes (first
)))
2218 phi_translate_set (ANTIC_OUT
, ANTIC_IN (first
), block
, first
);
2220 bitmap_set_copy (ANTIC_OUT
, ANTIC_IN (first
));
2222 FOR_EACH_VEC_ELT (worklist
, i
, bprime
)
2224 if (!gimple_seq_empty_p (phi_nodes (bprime
)))
2226 bitmap_set_t tmp
= bitmap_set_new ();
2227 phi_translate_set (tmp
, ANTIC_IN (bprime
), block
, bprime
);
2228 bitmap_set_and (ANTIC_OUT
, tmp
);
2229 bitmap_set_free (tmp
);
2232 bitmap_set_and (ANTIC_OUT
, ANTIC_IN (bprime
));
2234 worklist
.release ();
2237 /* Prune expressions that are clobbered in block and thus become
2238 invalid if translated from ANTIC_OUT to ANTIC_IN. */
2239 prune_clobbered_mems (ANTIC_OUT
, block
);
2241 /* Generate ANTIC_OUT - TMP_GEN. */
2242 S
= bitmap_set_subtract (ANTIC_OUT
, TMP_GEN (block
));
2244 /* Start ANTIC_IN with EXP_GEN - TMP_GEN. */
2245 ANTIC_IN (block
) = bitmap_set_subtract (EXP_GEN (block
),
2248 /* Then union in the ANTIC_OUT - TMP_GEN values,
2249 to get ANTIC_OUT U EXP_GEN - TMP_GEN */
2250 FOR_EACH_EXPR_ID_IN_SET (S
, bii
, bi
)
2251 bitmap_value_insert_into_set (ANTIC_IN (block
),
2252 expression_for_id (bii
));
2254 clean (ANTIC_IN (block
), block
);
2256 if (!bitmap_set_equal (old
, ANTIC_IN (block
)))
2259 bitmap_set_bit (changed_blocks
, block
->index
);
2260 FOR_EACH_EDGE (e
, ei
, block
->preds
)
2261 bitmap_set_bit (changed_blocks
, e
->src
->index
);
2264 bitmap_clear_bit (changed_blocks
, block
->index
);
2267 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2269 if (!BB_DEFERRED (block
) || BB_VISITED (block
))
2272 print_bitmap_set (dump_file
, ANTIC_OUT
, "ANTIC_OUT", block
->index
);
2274 print_bitmap_set (dump_file
, ANTIC_IN (block
), "ANTIC_IN",
2278 print_bitmap_set (dump_file
, S
, "S", block
->index
);
2283 "Block %d was deferred for a future iteration.\n",
2288 bitmap_set_free (old
);
2290 bitmap_set_free (S
);
2292 bitmap_set_free (ANTIC_OUT
);
2296 /* Compute PARTIAL_ANTIC for BLOCK.
2298 If succs(BLOCK) > 1 then
2299 PA_OUT[BLOCK] = value wise union of PA_IN[b] + all ANTIC_IN not
2300 in ANTIC_OUT for all succ(BLOCK)
2301 else if succs(BLOCK) == 1 then
2302 PA_OUT[BLOCK] = phi_translate (PA_IN[succ(BLOCK)])
2304 PA_IN[BLOCK] = dependent_clean(PA_OUT[BLOCK] - TMP_GEN[BLOCK]
2309 compute_partial_antic_aux (basic_block block
,
2310 bool block_has_abnormal_pred_edge
)
2312 bool changed
= false;
2313 bitmap_set_t old_PA_IN
;
2314 bitmap_set_t PA_OUT
;
2317 unsigned long max_pa
= PARAM_VALUE (PARAM_MAX_PARTIAL_ANTIC_LENGTH
);
2319 old_PA_IN
= PA_OUT
= NULL
;
2321 /* If any edges from predecessors are abnormal, antic_in is empty,
2323 if (block_has_abnormal_pred_edge
)
2324 goto maybe_dump_sets
;
2326 /* If there are too many partially anticipatable values in the
2327 block, phi_translate_set can take an exponential time: stop
2328 before the translation starts. */
2330 && single_succ_p (block
)
2331 && bitmap_count_bits (&PA_IN (single_succ (block
))->values
) > max_pa
)
2332 goto maybe_dump_sets
;
2334 old_PA_IN
= PA_IN (block
);
2335 PA_OUT
= bitmap_set_new ();
2337 /* If the block has no successors, ANTIC_OUT is empty. */
2338 if (EDGE_COUNT (block
->succs
) == 0)
2340 /* If we have one successor, we could have some phi nodes to
2341 translate through. Note that we can't phi translate across DFS
2342 back edges in partial antic, because it uses a union operation on
2343 the successors. For recurrences like IV's, we will end up
2344 generating a new value in the set on each go around (i + 3 (VH.1)
2345 VH.1 + 1 (VH.2), VH.2 + 1 (VH.3), etc), forever. */
2346 else if (single_succ_p (block
))
2348 basic_block succ
= single_succ (block
);
2349 if (!(single_succ_edge (block
)->flags
& EDGE_DFS_BACK
))
2350 phi_translate_set (PA_OUT
, PA_IN (succ
), block
, succ
);
2352 /* If we have multiple successors, we take the union of all of
2356 vec
<basic_block
> worklist
;
2360 worklist
.create (EDGE_COUNT (block
->succs
));
2361 FOR_EACH_EDGE (e
, ei
, block
->succs
)
2363 if (e
->flags
& EDGE_DFS_BACK
)
2365 worklist
.quick_push (e
->dest
);
2367 if (worklist
.length () > 0)
2369 FOR_EACH_VEC_ELT (worklist
, i
, bprime
)
2374 FOR_EACH_EXPR_ID_IN_SET (ANTIC_IN (bprime
), i
, bi
)
2375 bitmap_value_insert_into_set (PA_OUT
,
2376 expression_for_id (i
));
2377 if (!gimple_seq_empty_p (phi_nodes (bprime
)))
2379 bitmap_set_t pa_in
= bitmap_set_new ();
2380 phi_translate_set (pa_in
, PA_IN (bprime
), block
, bprime
);
2381 FOR_EACH_EXPR_ID_IN_SET (pa_in
, i
, bi
)
2382 bitmap_value_insert_into_set (PA_OUT
,
2383 expression_for_id (i
));
2384 bitmap_set_free (pa_in
);
2387 FOR_EACH_EXPR_ID_IN_SET (PA_IN (bprime
), i
, bi
)
2388 bitmap_value_insert_into_set (PA_OUT
,
2389 expression_for_id (i
));
2392 worklist
.release ();
2395 /* Prune expressions that are clobbered in block and thus become
2396 invalid if translated from PA_OUT to PA_IN. */
2397 prune_clobbered_mems (PA_OUT
, block
);
2399 /* PA_IN starts with PA_OUT - TMP_GEN.
2400 Then we subtract things from ANTIC_IN. */
2401 PA_IN (block
) = bitmap_set_subtract (PA_OUT
, TMP_GEN (block
));
2403 /* For partial antic, we want to put back in the phi results, since
2404 we will properly avoid making them partially antic over backedges. */
2405 bitmap_ior_into (&PA_IN (block
)->values
, &PHI_GEN (block
)->values
);
2406 bitmap_ior_into (&PA_IN (block
)->expressions
, &PHI_GEN (block
)->expressions
);
2408 /* PA_IN[block] = PA_IN[block] - ANTIC_IN[block] */
2409 bitmap_set_subtract_values (PA_IN (block
), ANTIC_IN (block
));
2411 dependent_clean (PA_IN (block
), ANTIC_IN (block
), block
);
2413 if (!bitmap_set_equal (old_PA_IN
, PA_IN (block
)))
2416 bitmap_set_bit (changed_blocks
, block
->index
);
2417 FOR_EACH_EDGE (e
, ei
, block
->preds
)
2418 bitmap_set_bit (changed_blocks
, e
->src
->index
);
2421 bitmap_clear_bit (changed_blocks
, block
->index
);
2424 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2427 print_bitmap_set (dump_file
, PA_OUT
, "PA_OUT", block
->index
);
2429 print_bitmap_set (dump_file
, PA_IN (block
), "PA_IN", block
->index
);
2432 bitmap_set_free (old_PA_IN
);
2434 bitmap_set_free (PA_OUT
);
2438 /* Compute ANTIC and partial ANTIC sets. */
2441 compute_antic (void)
2443 bool changed
= true;
2444 int num_iterations
= 0;
2448 /* If any predecessor edges are abnormal, we punt, so antic_in is empty.
2449 We pre-build the map of blocks with incoming abnormal edges here. */
2450 has_abnormal_preds
= sbitmap_alloc (last_basic_block
);
2451 bitmap_clear (has_abnormal_preds
);
2458 FOR_EACH_EDGE (e
, ei
, block
->preds
)
2460 e
->flags
&= ~EDGE_DFS_BACK
;
2461 if (e
->flags
& EDGE_ABNORMAL
)
2463 bitmap_set_bit (has_abnormal_preds
, block
->index
);
2468 BB_VISITED (block
) = 0;
2469 BB_DEFERRED (block
) = 0;
2471 /* While we are here, give empty ANTIC_IN sets to each block. */
2472 ANTIC_IN (block
) = bitmap_set_new ();
2473 PA_IN (block
) = bitmap_set_new ();
2476 /* At the exit block we anticipate nothing. */
2477 BB_VISITED (EXIT_BLOCK_PTR
) = 1;
2479 changed_blocks
= sbitmap_alloc (last_basic_block
+ 1);
2480 bitmap_ones (changed_blocks
);
2483 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2484 fprintf (dump_file
, "Starting iteration %d\n", num_iterations
);
2485 /* ??? We need to clear our PHI translation cache here as the
2486 ANTIC sets shrink and we restrict valid translations to
2487 those having operands with leaders in ANTIC. Same below
2488 for PA ANTIC computation. */
2491 for (i
= postorder_num
- 1; i
>= 0; i
--)
2493 if (bitmap_bit_p (changed_blocks
, postorder
[i
]))
2495 basic_block block
= BASIC_BLOCK (postorder
[i
]);
2496 changed
|= compute_antic_aux (block
,
2497 bitmap_bit_p (has_abnormal_preds
,
2501 /* Theoretically possible, but *highly* unlikely. */
2502 gcc_checking_assert (num_iterations
< 500);
2505 statistics_histogram_event (cfun
, "compute_antic iterations",
2508 if (do_partial_partial
)
2510 bitmap_ones (changed_blocks
);
2511 mark_dfs_back_edges ();
2516 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2517 fprintf (dump_file
, "Starting iteration %d\n", num_iterations
);
2520 for (i
= postorder_num
- 1 ; i
>= 0; i
--)
2522 if (bitmap_bit_p (changed_blocks
, postorder
[i
]))
2524 basic_block block
= BASIC_BLOCK (postorder
[i
]);
2526 |= compute_partial_antic_aux (block
,
2527 bitmap_bit_p (has_abnormal_preds
,
2531 /* Theoretically possible, but *highly* unlikely. */
2532 gcc_checking_assert (num_iterations
< 500);
2534 statistics_histogram_event (cfun
, "compute_partial_antic iterations",
2537 sbitmap_free (has_abnormal_preds
);
2538 sbitmap_free (changed_blocks
);
2542 /* Inserted expressions are placed onto this worklist, which is used
2543 for performing quick dead code elimination of insertions we made
2544 that didn't turn out to be necessary. */
2545 static bitmap inserted_exprs
;
2547 /* The actual worker for create_component_ref_by_pieces. */
2550 create_component_ref_by_pieces_1 (basic_block block
, vn_reference_t ref
,
2551 unsigned int *operand
, gimple_seq
*stmts
)
2553 vn_reference_op_t currop
= &ref
->operands
[*operand
];
2556 switch (currop
->opcode
)
2560 tree folded
, sc
= NULL_TREE
;
2561 unsigned int nargs
= 0;
2563 if (TREE_CODE (currop
->op0
) == FUNCTION_DECL
)
2566 fn
= find_or_generate_expression (block
, currop
->op0
, stmts
);
2568 sc
= find_or_generate_expression (block
, currop
->op1
, stmts
);
2569 args
= XNEWVEC (tree
, ref
->operands
.length () - 1);
2570 while (*operand
< ref
->operands
.length ())
2572 args
[nargs
] = create_component_ref_by_pieces_1 (block
, ref
,
2576 folded
= build_call_array (currop
->type
,
2577 (TREE_CODE (fn
) == FUNCTION_DECL
2578 ? build_fold_addr_expr (fn
) : fn
),
2582 CALL_EXPR_STATIC_CHAIN (folded
) = sc
;
2588 tree baseop
= create_component_ref_by_pieces_1 (block
, ref
, operand
,
2590 tree offset
= currop
->op0
;
2591 if (TREE_CODE (baseop
) == ADDR_EXPR
2592 && handled_component_p (TREE_OPERAND (baseop
, 0)))
2596 base
= get_addr_base_and_unit_offset (TREE_OPERAND (baseop
, 0),
2599 offset
= int_const_binop (PLUS_EXPR
, offset
,
2600 build_int_cst (TREE_TYPE (offset
),
2602 baseop
= build_fold_addr_expr (base
);
2604 return fold_build2 (MEM_REF
, currop
->type
, baseop
, offset
);
2607 case TARGET_MEM_REF
:
2609 tree genop0
= NULL_TREE
, genop1
= NULL_TREE
;
2610 vn_reference_op_t nextop
= &ref
->operands
[++*operand
];
2611 tree baseop
= create_component_ref_by_pieces_1 (block
, ref
, operand
,
2614 genop0
= find_or_generate_expression (block
, currop
->op0
, stmts
);
2616 genop1
= find_or_generate_expression (block
, nextop
->op0
, stmts
);
2617 return build5 (TARGET_MEM_REF
, currop
->type
,
2618 baseop
, currop
->op2
, genop0
, currop
->op1
, genop1
);
2624 gcc_assert (is_gimple_min_invariant (currop
->op0
));
2630 case VIEW_CONVERT_EXPR
:
2632 tree genop0
= create_component_ref_by_pieces_1 (block
, ref
,
2634 return fold_build1 (currop
->opcode
, currop
->type
, genop0
);
2637 case WITH_SIZE_EXPR
:
2639 tree genop0
= create_component_ref_by_pieces_1 (block
, ref
, operand
,
2641 tree genop1
= find_or_generate_expression (block
, currop
->op0
, stmts
);
2642 return fold_build2 (currop
->opcode
, currop
->type
, genop0
, genop1
);
2647 tree genop0
= create_component_ref_by_pieces_1 (block
, ref
, operand
,
2649 tree op1
= currop
->op0
;
2650 tree op2
= currop
->op1
;
2651 return fold_build3 (BIT_FIELD_REF
, currop
->type
, genop0
, op1
, op2
);
2654 /* For array ref vn_reference_op's, operand 1 of the array ref
2655 is op0 of the reference op and operand 3 of the array ref is
2657 case ARRAY_RANGE_REF
:
2661 tree genop1
= currop
->op0
;
2662 tree genop2
= currop
->op1
;
2663 tree genop3
= currop
->op2
;
2664 genop0
= create_component_ref_by_pieces_1 (block
, ref
, operand
, stmts
);
2665 genop1
= find_or_generate_expression (block
, genop1
, stmts
);
2668 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (genop0
));
2669 /* Drop zero minimum index if redundant. */
2670 if (integer_zerop (genop2
)
2672 || integer_zerop (TYPE_MIN_VALUE (domain_type
))))
2675 genop2
= find_or_generate_expression (block
, genop2
, stmts
);
2679 tree elmt_type
= TREE_TYPE (TREE_TYPE (genop0
));
2680 /* We can't always put a size in units of the element alignment
2681 here as the element alignment may be not visible. See
2682 PR43783. Simply drop the element size for constant
2684 if (tree_int_cst_equal (genop3
, TYPE_SIZE_UNIT (elmt_type
)))
2688 genop3
= size_binop (EXACT_DIV_EXPR
, genop3
,
2689 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
2690 genop3
= find_or_generate_expression (block
, genop3
, stmts
);
2693 return build4 (currop
->opcode
, currop
->type
, genop0
, genop1
,
2700 tree genop2
= currop
->op1
;
2701 op0
= create_component_ref_by_pieces_1 (block
, ref
, operand
, stmts
);
2702 /* op1 should be a FIELD_DECL, which are represented by themselves. */
2705 genop2
= find_or_generate_expression (block
, genop2
, stmts
);
2706 return fold_build3 (COMPONENT_REF
, TREE_TYPE (op1
), op0
, op1
, genop2
);
2711 genop
= find_or_generate_expression (block
, currop
->op0
, stmts
);
2732 /* For COMPONENT_REF's and ARRAY_REF's, we can't have any intermediates for the
2733 COMPONENT_REF or MEM_REF or ARRAY_REF portion, because we'd end up with
2734 trying to rename aggregates into ssa form directly, which is a no no.
2736 Thus, this routine doesn't create temporaries, it just builds a
2737 single access expression for the array, calling
2738 find_or_generate_expression to build the innermost pieces.
2740 This function is a subroutine of create_expression_by_pieces, and
2741 should not be called on it's own unless you really know what you
2745 create_component_ref_by_pieces (basic_block block
, vn_reference_t ref
,
2748 unsigned int op
= 0;
2749 return create_component_ref_by_pieces_1 (block
, ref
, &op
, stmts
);
2752 /* Find a leader for an expression, or generate one using
2753 create_expression_by_pieces if it's ANTIC but
2755 BLOCK is the basic_block we are looking for leaders in.
2756 OP is the tree expression to find a leader for or generate.
2757 STMTS is the statement list to put the inserted expressions on.
2758 Returns the SSA_NAME of the LHS of the generated expression or the
2760 DOMSTMT if non-NULL is a statement that should be dominated by
2761 all uses in the generated expression. If DOMSTMT is non-NULL this
2762 routine can fail and return NULL_TREE. Otherwise it will assert
2766 find_or_generate_expression (basic_block block
, tree op
, gimple_seq
*stmts
)
2768 pre_expr expr
= get_or_alloc_expr_for (op
);
2769 unsigned int lookfor
= get_expr_value_id (expr
);
2770 pre_expr leader
= bitmap_find_leader (AVAIL_OUT (block
), lookfor
);
2773 if (leader
->kind
== NAME
)
2774 return PRE_EXPR_NAME (leader
);
2775 else if (leader
->kind
== CONSTANT
)
2776 return PRE_EXPR_CONSTANT (leader
);
2779 /* It must be a complex expression, so generate it recursively. */
2780 bitmap exprset
= value_expressions
[lookfor
];
2783 EXECUTE_IF_SET_IN_BITMAP (exprset
, 0, i
, bi
)
2785 pre_expr temp
= expression_for_id (i
);
2786 if (temp
->kind
!= NAME
)
2787 return create_expression_by_pieces (block
, temp
, stmts
,
2788 get_expr_type (expr
));
2794 #define NECESSARY GF_PLF_1
2796 /* Create an expression in pieces, so that we can handle very complex
2797 expressions that may be ANTIC, but not necessary GIMPLE.
2798 BLOCK is the basic block the expression will be inserted into,
2799 EXPR is the expression to insert (in value form)
2800 STMTS is a statement list to append the necessary insertions into.
2802 This function will die if we hit some value that shouldn't be
2803 ANTIC but is (IE there is no leader for it, or its components).
2804 This function may also generate expressions that are themselves
2805 partially or fully redundant. Those that are will be either made
2806 fully redundant during the next iteration of insert (for partially
2807 redundant ones), or eliminated by eliminate (for fully redundant
2810 If DOMSTMT is non-NULL then we make sure that all uses in the
2811 expressions dominate that statement. In this case the function
2812 can return NULL_TREE to signal failure. */
2815 create_expression_by_pieces (basic_block block
, pre_expr expr
,
2816 gimple_seq
*stmts
, tree type
)
2820 gimple_seq forced_stmts
= NULL
;
2821 unsigned int value_id
;
2822 gimple_stmt_iterator gsi
;
2823 tree exprtype
= type
? type
: get_expr_type (expr
);
2829 /* We may hit the NAME/CONSTANT case if we have to convert types
2830 that value numbering saw through. */
2832 folded
= PRE_EXPR_NAME (expr
);
2835 folded
= PRE_EXPR_CONSTANT (expr
);
2839 vn_reference_t ref
= PRE_EXPR_REFERENCE (expr
);
2840 folded
= create_component_ref_by_pieces (block
, ref
, stmts
);
2845 vn_nary_op_t nary
= PRE_EXPR_NARY (expr
);
2846 tree
*genop
= XALLOCAVEC (tree
, nary
->length
);
2848 for (i
= 0; i
< nary
->length
; ++i
)
2850 genop
[i
] = find_or_generate_expression (block
, nary
->op
[i
], stmts
);
2851 /* Ensure genop[] is properly typed for POINTER_PLUS_EXPR. It
2852 may have conversions stripped. */
2853 if (nary
->opcode
== POINTER_PLUS_EXPR
)
2856 genop
[i
] = fold_convert (nary
->type
, genop
[i
]);
2858 genop
[i
] = convert_to_ptrofftype (genop
[i
]);
2861 genop
[i
] = fold_convert (TREE_TYPE (nary
->op
[i
]), genop
[i
]);
2863 if (nary
->opcode
== CONSTRUCTOR
)
2865 vec
<constructor_elt
, va_gc
> *elts
= NULL
;
2866 for (i
= 0; i
< nary
->length
; ++i
)
2867 CONSTRUCTOR_APPEND_ELT (elts
, NULL_TREE
, genop
[i
]);
2868 folded
= build_constructor (nary
->type
, elts
);
2872 switch (nary
->length
)
2875 folded
= fold_build1 (nary
->opcode
, nary
->type
,
2879 folded
= fold_build2 (nary
->opcode
, nary
->type
,
2880 genop
[0], genop
[1]);
2883 folded
= fold_build3 (nary
->opcode
, nary
->type
,
2884 genop
[0], genop
[1], genop
[3]);
2896 if (!useless_type_conversion_p (exprtype
, TREE_TYPE (folded
)))
2897 folded
= fold_convert (exprtype
, folded
);
2899 /* Force the generated expression to be a sequence of GIMPLE
2901 We have to call unshare_expr because force_gimple_operand may
2902 modify the tree we pass to it. */
2903 folded
= force_gimple_operand (unshare_expr (folded
), &forced_stmts
,
2906 /* If we have any intermediate expressions to the value sets, add them
2907 to the value sets and chain them in the instruction stream. */
2910 gsi
= gsi_start (forced_stmts
);
2911 for (; !gsi_end_p (gsi
); gsi_next (&gsi
))
2913 gimple stmt
= gsi_stmt (gsi
);
2914 tree forcedname
= gimple_get_lhs (stmt
);
2917 if (TREE_CODE (forcedname
) == SSA_NAME
)
2919 bitmap_set_bit (inserted_exprs
, SSA_NAME_VERSION (forcedname
));
2920 VN_INFO_GET (forcedname
)->valnum
= forcedname
;
2921 VN_INFO (forcedname
)->value_id
= get_next_value_id ();
2922 nameexpr
= get_or_alloc_expr_for_name (forcedname
);
2923 add_to_value (VN_INFO (forcedname
)->value_id
, nameexpr
);
2924 bitmap_value_replace_in_set (NEW_SETS (block
), nameexpr
);
2925 bitmap_value_replace_in_set (AVAIL_OUT (block
), nameexpr
);
2928 gimple_seq_add_seq (stmts
, forced_stmts
);
2931 name
= make_temp_ssa_name (exprtype
, NULL
, "pretmp");
2932 newstmt
= gimple_build_assign (name
, folded
);
2933 gimple_set_plf (newstmt
, NECESSARY
, false);
2935 gimple_seq_add_stmt (stmts
, newstmt
);
2936 bitmap_set_bit (inserted_exprs
, SSA_NAME_VERSION (name
));
2938 /* Fold the last statement. */
2939 gsi
= gsi_last (*stmts
);
2940 if (fold_stmt_inplace (&gsi
))
2941 update_stmt (gsi_stmt (gsi
));
2943 /* Add a value number to the temporary.
2944 The value may already exist in either NEW_SETS, or AVAIL_OUT, because
2945 we are creating the expression by pieces, and this particular piece of
2946 the expression may have been represented. There is no harm in replacing
2948 value_id
= get_expr_value_id (expr
);
2949 VN_INFO_GET (name
)->value_id
= value_id
;
2950 VN_INFO (name
)->valnum
= sccvn_valnum_from_value_id (value_id
);
2951 if (VN_INFO (name
)->valnum
== NULL_TREE
)
2952 VN_INFO (name
)->valnum
= name
;
2953 gcc_assert (VN_INFO (name
)->valnum
!= NULL_TREE
);
2954 nameexpr
= get_or_alloc_expr_for_name (name
);
2955 add_to_value (value_id
, nameexpr
);
2956 if (NEW_SETS (block
))
2957 bitmap_value_replace_in_set (NEW_SETS (block
), nameexpr
);
2958 bitmap_value_replace_in_set (AVAIL_OUT (block
), nameexpr
);
2960 pre_stats
.insertions
++;
2961 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2963 fprintf (dump_file
, "Inserted ");
2964 print_gimple_stmt (dump_file
, newstmt
, 0, 0);
2965 fprintf (dump_file
, " in predecessor %d\n", block
->index
);
2972 /* Returns true if we want to inhibit the insertions of PHI nodes
2973 for the given EXPR for basic block BB (a member of a loop).
2974 We want to do this, when we fear that the induction variable we
2975 create might inhibit vectorization. */
2978 inhibit_phi_insertion (basic_block bb
, pre_expr expr
)
2980 vn_reference_t vr
= PRE_EXPR_REFERENCE (expr
);
2981 vec
<vn_reference_op_s
> ops
= vr
->operands
;
2982 vn_reference_op_t op
;
2985 /* If we aren't going to vectorize we don't inhibit anything. */
2986 if (!flag_tree_vectorize
)
2989 /* Otherwise we inhibit the insertion when the address of the
2990 memory reference is a simple induction variable. In other
2991 cases the vectorizer won't do anything anyway (either it's
2992 loop invariant or a complicated expression). */
2993 FOR_EACH_VEC_ELT (ops
, i
, op
)
2998 /* Calls are not a problem. */
3002 case ARRAY_RANGE_REF
:
3003 if (TREE_CODE (op
->op0
) != SSA_NAME
)
3008 basic_block defbb
= gimple_bb (SSA_NAME_DEF_STMT (op
->op0
));
3010 /* Default defs are loop invariant. */
3013 /* Defined outside this loop, also loop invariant. */
3014 if (!flow_bb_inside_loop_p (bb
->loop_father
, defbb
))
3016 /* If it's a simple induction variable inhibit insertion,
3017 the vectorizer might be interested in this one. */
3018 if (simple_iv (bb
->loop_father
, bb
->loop_father
,
3019 op
->op0
, &iv
, true))
3021 /* No simple IV, vectorizer can't do anything, hence no
3022 reason to inhibit the transformation for this operand. */
3032 /* Insert the to-be-made-available values of expression EXPRNUM for each
3033 predecessor, stored in AVAIL, into the predecessors of BLOCK, and
3034 merge the result with a phi node, given the same value number as
3035 NODE. Return true if we have inserted new stuff. */
3038 insert_into_preds_of_block (basic_block block
, unsigned int exprnum
,
3039 vec
<pre_expr
> avail
)
3041 pre_expr expr
= expression_for_id (exprnum
);
3043 unsigned int val
= get_expr_value_id (expr
);
3045 bool insertions
= false;
3050 tree type
= get_expr_type (expr
);
3054 /* Make sure we aren't creating an induction variable. */
3055 if (bb_loop_depth (block
) > 0 && EDGE_COUNT (block
->preds
) == 2)
3057 bool firstinsideloop
= false;
3058 bool secondinsideloop
= false;
3059 firstinsideloop
= flow_bb_inside_loop_p (block
->loop_father
,
3060 EDGE_PRED (block
, 0)->src
);
3061 secondinsideloop
= flow_bb_inside_loop_p (block
->loop_father
,
3062 EDGE_PRED (block
, 1)->src
);
3063 /* Induction variables only have one edge inside the loop. */
3064 if ((firstinsideloop
^ secondinsideloop
)
3065 && (expr
->kind
!= REFERENCE
3066 || inhibit_phi_insertion (block
, expr
)))
3068 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3069 fprintf (dump_file
, "Skipping insertion of phi for partial redundancy: Looks like an induction variable\n");
3074 /* Make the necessary insertions. */
3075 FOR_EACH_EDGE (pred
, ei
, block
->preds
)
3077 gimple_seq stmts
= NULL
;
3080 eprime
= avail
[pred
->dest_idx
];
3082 if (eprime
->kind
!= NAME
&& eprime
->kind
!= CONSTANT
)
3084 builtexpr
= create_expression_by_pieces (bprime
, eprime
,
3086 gcc_assert (!(pred
->flags
& EDGE_ABNORMAL
));
3087 gsi_insert_seq_on_edge (pred
, stmts
);
3088 avail
[pred
->dest_idx
] = get_or_alloc_expr_for_name (builtexpr
);
3091 else if (eprime
->kind
== CONSTANT
)
3093 /* Constants may not have the right type, fold_convert
3094 should give us back a constant with the right type. */
3095 tree constant
= PRE_EXPR_CONSTANT (eprime
);
3096 if (!useless_type_conversion_p (type
, TREE_TYPE (constant
)))
3098 tree builtexpr
= fold_convert (type
, constant
);
3099 if (!is_gimple_min_invariant (builtexpr
))
3101 tree forcedexpr
= force_gimple_operand (builtexpr
,
3104 if (!is_gimple_min_invariant (forcedexpr
))
3106 if (forcedexpr
!= builtexpr
)
3108 VN_INFO_GET (forcedexpr
)->valnum
= PRE_EXPR_CONSTANT (eprime
);
3109 VN_INFO (forcedexpr
)->value_id
= get_expr_value_id (eprime
);
3113 gimple_stmt_iterator gsi
;
3114 gsi
= gsi_start (stmts
);
3115 for (; !gsi_end_p (gsi
); gsi_next (&gsi
))
3117 gimple stmt
= gsi_stmt (gsi
);
3118 tree lhs
= gimple_get_lhs (stmt
);
3119 if (TREE_CODE (lhs
) == SSA_NAME
)
3120 bitmap_set_bit (inserted_exprs
,
3121 SSA_NAME_VERSION (lhs
));
3122 gimple_set_plf (stmt
, NECESSARY
, false);
3124 gsi_insert_seq_on_edge (pred
, stmts
);
3126 avail
[pred
->dest_idx
]
3127 = get_or_alloc_expr_for_name (forcedexpr
);
3131 avail
[pred
->dest_idx
]
3132 = get_or_alloc_expr_for_constant (builtexpr
);
3135 else if (eprime
->kind
== NAME
)
3137 /* We may have to do a conversion because our value
3138 numbering can look through types in certain cases, but
3139 our IL requires all operands of a phi node have the same
3141 tree name
= PRE_EXPR_NAME (eprime
);
3142 if (!useless_type_conversion_p (type
, TREE_TYPE (name
)))
3146 builtexpr
= fold_convert (type
, name
);
3147 forcedexpr
= force_gimple_operand (builtexpr
,
3151 if (forcedexpr
!= name
)
3153 VN_INFO_GET (forcedexpr
)->valnum
= VN_INFO (name
)->valnum
;
3154 VN_INFO (forcedexpr
)->value_id
= VN_INFO (name
)->value_id
;
3159 gimple_stmt_iterator gsi
;
3160 gsi
= gsi_start (stmts
);
3161 for (; !gsi_end_p (gsi
); gsi_next (&gsi
))
3163 gimple stmt
= gsi_stmt (gsi
);
3164 tree lhs
= gimple_get_lhs (stmt
);
3165 if (TREE_CODE (lhs
) == SSA_NAME
)
3166 bitmap_set_bit (inserted_exprs
, SSA_NAME_VERSION (lhs
));
3167 gimple_set_plf (stmt
, NECESSARY
, false);
3169 gsi_insert_seq_on_edge (pred
, stmts
);
3171 avail
[pred
->dest_idx
] = get_or_alloc_expr_for_name (forcedexpr
);
3175 /* If we didn't want a phi node, and we made insertions, we still have
3176 inserted new stuff, and thus return true. If we didn't want a phi node,
3177 and didn't make insertions, we haven't added anything new, so return
3179 if (nophi
&& insertions
)
3181 else if (nophi
&& !insertions
)
3184 /* Now build a phi for the new variable. */
3185 temp
= make_temp_ssa_name (type
, NULL
, "prephitmp");
3186 phi
= create_phi_node (temp
, block
);
3188 gimple_set_plf (phi
, NECESSARY
, false);
3189 VN_INFO_GET (temp
)->value_id
= val
;
3190 VN_INFO (temp
)->valnum
= sccvn_valnum_from_value_id (val
);
3191 if (VN_INFO (temp
)->valnum
== NULL_TREE
)
3192 VN_INFO (temp
)->valnum
= temp
;
3193 bitmap_set_bit (inserted_exprs
, SSA_NAME_VERSION (temp
));
3194 FOR_EACH_EDGE (pred
, ei
, block
->preds
)
3196 pre_expr ae
= avail
[pred
->dest_idx
];
3197 gcc_assert (get_expr_type (ae
) == type
3198 || useless_type_conversion_p (type
, get_expr_type (ae
)));
3199 if (ae
->kind
== CONSTANT
)
3200 add_phi_arg (phi
, PRE_EXPR_CONSTANT (ae
), pred
, UNKNOWN_LOCATION
);
3202 add_phi_arg (phi
, PRE_EXPR_NAME (ae
), pred
, UNKNOWN_LOCATION
);
3205 newphi
= get_or_alloc_expr_for_name (temp
);
3206 add_to_value (val
, newphi
);
3208 /* The value should *not* exist in PHI_GEN, or else we wouldn't be doing
3209 this insertion, since we test for the existence of this value in PHI_GEN
3210 before proceeding with the partial redundancy checks in insert_aux.
3212 The value may exist in AVAIL_OUT, in particular, it could be represented
3213 by the expression we are trying to eliminate, in which case we want the
3214 replacement to occur. If it's not existing in AVAIL_OUT, we want it
3217 Similarly, to the PHI_GEN case, the value should not exist in NEW_SETS of
3218 this block, because if it did, it would have existed in our dominator's
3219 AVAIL_OUT, and would have been skipped due to the full redundancy check.
3222 bitmap_insert_into_set (PHI_GEN (block
), newphi
);
3223 bitmap_value_replace_in_set (AVAIL_OUT (block
),
3225 bitmap_insert_into_set (NEW_SETS (block
),
3228 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3230 fprintf (dump_file
, "Created phi ");
3231 print_gimple_stmt (dump_file
, phi
, 0, 0);
3232 fprintf (dump_file
, " in block %d\n", block
->index
);
3240 /* Perform insertion of partially redundant values.
3241 For BLOCK, do the following:
3242 1. Propagate the NEW_SETS of the dominator into the current block.
3243 If the block has multiple predecessors,
3244 2a. Iterate over the ANTIC expressions for the block to see if
3245 any of them are partially redundant.
3246 2b. If so, insert them into the necessary predecessors to make
3247 the expression fully redundant.
3248 2c. Insert a new PHI merging the values of the predecessors.
3249 2d. Insert the new PHI, and the new expressions, into the
3251 3. Recursively call ourselves on the dominator children of BLOCK.
3253 Steps 1, 2a, and 3 are done by insert_aux. 2b, 2c and 2d are done by
3254 do_regular_insertion and do_partial_insertion.
3259 do_regular_insertion (basic_block block
, basic_block dom
)
3261 bool new_stuff
= false;
3262 vec
<pre_expr
> exprs
;
3264 vec
<pre_expr
> avail
= vNULL
;
3267 exprs
= sorted_array_from_bitmap_set (ANTIC_IN (block
));
3268 avail
.safe_grow (EDGE_COUNT (block
->preds
));
3270 FOR_EACH_VEC_ELT (exprs
, i
, expr
)
3272 if (expr
->kind
!= NAME
)
3275 bool by_some
= false;
3276 bool cant_insert
= false;
3277 bool all_same
= true;
3278 pre_expr first_s
= NULL
;
3281 pre_expr eprime
= NULL
;
3283 pre_expr edoubleprime
= NULL
;
3284 bool do_insertion
= false;
3286 val
= get_expr_value_id (expr
);
3287 if (bitmap_set_contains_value (PHI_GEN (block
), val
))
3289 if (bitmap_set_contains_value (AVAIL_OUT (dom
), val
))
3291 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3292 fprintf (dump_file
, "Found fully redundant value\n");
3296 FOR_EACH_EDGE (pred
, ei
, block
->preds
)
3298 unsigned int vprime
;
3300 /* We should never run insertion for the exit block
3301 and so not come across fake pred edges. */
3302 gcc_assert (!(pred
->flags
& EDGE_FAKE
));
3304 eprime
= phi_translate (expr
, ANTIC_IN (block
), NULL
,
3307 /* eprime will generally only be NULL if the
3308 value of the expression, translated
3309 through the PHI for this predecessor, is
3310 undefined. If that is the case, we can't
3311 make the expression fully redundant,
3312 because its value is undefined along a
3313 predecessor path. We can thus break out
3314 early because it doesn't matter what the
3315 rest of the results are. */
3318 avail
[pred
->dest_idx
] = NULL
;
3323 eprime
= fully_constant_expression (eprime
);
3324 vprime
= get_expr_value_id (eprime
);
3325 edoubleprime
= bitmap_find_leader (AVAIL_OUT (bprime
),
3327 if (edoubleprime
== NULL
)
3329 avail
[pred
->dest_idx
] = eprime
;
3334 avail
[pred
->dest_idx
] = edoubleprime
;
3336 /* We want to perform insertions to remove a redundancy on
3337 a path in the CFG we want to optimize for speed. */
3338 if (optimize_edge_for_speed_p (pred
))
3339 do_insertion
= true;
3340 if (first_s
== NULL
)
3341 first_s
= edoubleprime
;
3342 else if (!pre_expr_d::equal (first_s
, edoubleprime
))
3346 /* If we can insert it, it's not the same value
3347 already existing along every predecessor, and
3348 it's defined by some predecessor, it is
3349 partially redundant. */
3350 if (!cant_insert
&& !all_same
&& by_some
)
3354 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3356 fprintf (dump_file
, "Skipping partial redundancy for "
3358 print_pre_expr (dump_file
, expr
);
3359 fprintf (dump_file
, " (%04d), no redundancy on to be "
3360 "optimized for speed edge\n", val
);
3363 else if (dbg_cnt (treepre_insert
))
3365 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3367 fprintf (dump_file
, "Found partial redundancy for "
3369 print_pre_expr (dump_file
, expr
);
3370 fprintf (dump_file
, " (%04d)\n",
3371 get_expr_value_id (expr
));
3373 if (insert_into_preds_of_block (block
,
3374 get_expression_id (expr
),
3379 /* If all edges produce the same value and that value is
3380 an invariant, then the PHI has the same value on all
3381 edges. Note this. */
3382 else if (!cant_insert
&& all_same
&& eprime
3383 && (edoubleprime
->kind
== CONSTANT
3384 || edoubleprime
->kind
== NAME
)
3385 && !value_id_constant_p (val
))
3389 bitmap exprset
= value_expressions
[val
];
3391 unsigned int new_val
= get_expr_value_id (edoubleprime
);
3392 EXECUTE_IF_SET_IN_BITMAP (exprset
, 0, j
, bi
)
3394 pre_expr expr
= expression_for_id (j
);
3396 if (expr
->kind
== NAME
)
3398 vn_ssa_aux_t info
= VN_INFO (PRE_EXPR_NAME (expr
));
3399 /* Just reset the value id and valnum so it is
3400 the same as the constant we have discovered. */
3401 if (edoubleprime
->kind
== CONSTANT
)
3403 info
->valnum
= PRE_EXPR_CONSTANT (edoubleprime
);
3404 pre_stats
.constified
++;
3407 info
->valnum
= VN_INFO (PRE_EXPR_NAME (edoubleprime
))->valnum
;
3408 info
->value_id
= new_val
;
3421 /* Perform insertion for partially anticipatable expressions. There
3422 is only one case we will perform insertion for these. This case is
3423 if the expression is partially anticipatable, and fully available.
3424 In this case, we know that putting it earlier will enable us to
3425 remove the later computation. */
3429 do_partial_partial_insertion (basic_block block
, basic_block dom
)
3431 bool new_stuff
= false;
3432 vec
<pre_expr
> exprs
;
3434 vec
<pre_expr
> avail
= vNULL
;
3437 exprs
= sorted_array_from_bitmap_set (PA_IN (block
));
3438 avail
.safe_grow (EDGE_COUNT (block
->preds
));
3440 FOR_EACH_VEC_ELT (exprs
, i
, expr
)
3442 if (expr
->kind
!= NAME
)
3446 bool cant_insert
= false;
3449 pre_expr eprime
= NULL
;
3452 val
= get_expr_value_id (expr
);
3453 if (bitmap_set_contains_value (PHI_GEN (block
), val
))
3455 if (bitmap_set_contains_value (AVAIL_OUT (dom
), val
))
3458 FOR_EACH_EDGE (pred
, ei
, block
->preds
)
3460 unsigned int vprime
;
3461 pre_expr edoubleprime
;
3463 /* We should never run insertion for the exit block
3464 and so not come across fake pred edges. */
3465 gcc_assert (!(pred
->flags
& EDGE_FAKE
));
3467 eprime
= phi_translate (expr
, ANTIC_IN (block
),
3471 /* eprime will generally only be NULL if the
3472 value of the expression, translated
3473 through the PHI for this predecessor, is
3474 undefined. If that is the case, we can't
3475 make the expression fully redundant,
3476 because its value is undefined along a
3477 predecessor path. We can thus break out
3478 early because it doesn't matter what the
3479 rest of the results are. */
3482 avail
[pred
->dest_idx
] = NULL
;
3487 eprime
= fully_constant_expression (eprime
);
3488 vprime
= get_expr_value_id (eprime
);
3489 edoubleprime
= bitmap_find_leader (AVAIL_OUT (bprime
), vprime
);
3490 avail
[pred
->dest_idx
] = edoubleprime
;
3491 if (edoubleprime
== NULL
)
3498 /* If we can insert it, it's not the same value
3499 already existing along every predecessor, and
3500 it's defined by some predecessor, it is
3501 partially redundant. */
3502 if (!cant_insert
&& by_all
)
3505 bool do_insertion
= false;
3507 /* Insert only if we can remove a later expression on a path
3508 that we want to optimize for speed.
3509 The phi node that we will be inserting in BLOCK is not free,
3510 and inserting it for the sake of !optimize_for_speed successor
3511 may cause regressions on the speed path. */
3512 FOR_EACH_EDGE (succ
, ei
, block
->succs
)
3514 if (bitmap_set_contains_value (PA_IN (succ
->dest
), val
)
3515 || bitmap_set_contains_value (ANTIC_IN (succ
->dest
), val
))
3517 if (optimize_edge_for_speed_p (succ
))
3518 do_insertion
= true;
3524 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3526 fprintf (dump_file
, "Skipping partial partial redundancy "
3528 print_pre_expr (dump_file
, expr
);
3529 fprintf (dump_file
, " (%04d), not (partially) anticipated "
3530 "on any to be optimized for speed edges\n", val
);
3533 else if (dbg_cnt (treepre_insert
))
3535 pre_stats
.pa_insert
++;
3536 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3538 fprintf (dump_file
, "Found partial partial redundancy "
3540 print_pre_expr (dump_file
, expr
);
3541 fprintf (dump_file
, " (%04d)\n",
3542 get_expr_value_id (expr
));
3544 if (insert_into_preds_of_block (block
,
3545 get_expression_id (expr
),
3559 insert_aux (basic_block block
)
3562 bool new_stuff
= false;
3567 dom
= get_immediate_dominator (CDI_DOMINATORS
, block
);
3572 bitmap_set_t newset
= NEW_SETS (dom
);
3575 /* Note that we need to value_replace both NEW_SETS, and
3576 AVAIL_OUT. For both the case of NEW_SETS, the value may be
3577 represented by some non-simple expression here that we want
3578 to replace it with. */
3579 FOR_EACH_EXPR_ID_IN_SET (newset
, i
, bi
)
3581 pre_expr expr
= expression_for_id (i
);
3582 bitmap_value_replace_in_set (NEW_SETS (block
), expr
);
3583 bitmap_value_replace_in_set (AVAIL_OUT (block
), expr
);
3586 if (!single_pred_p (block
))
3588 new_stuff
|= do_regular_insertion (block
, dom
);
3589 if (do_partial_partial
)
3590 new_stuff
|= do_partial_partial_insertion (block
, dom
);
3594 for (son
= first_dom_son (CDI_DOMINATORS
, block
);
3596 son
= next_dom_son (CDI_DOMINATORS
, son
))
3598 new_stuff
|= insert_aux (son
);
3604 /* Perform insertion of partially redundant values. */
3609 bool new_stuff
= true;
3611 int num_iterations
= 0;
3614 NEW_SETS (bb
) = bitmap_set_new ();
3619 if (dump_file
&& dump_flags
& TDF_DETAILS
)
3620 fprintf (dump_file
, "Starting insert iteration %d\n", num_iterations
);
3621 new_stuff
= insert_aux (ENTRY_BLOCK_PTR
);
3623 statistics_histogram_event (cfun
, "insert iterations", num_iterations
);
3627 /* Compute the AVAIL set for all basic blocks.
3629 This function performs value numbering of the statements in each basic
3630 block. The AVAIL sets are built from information we glean while doing
3631 this value numbering, since the AVAIL sets contain only one entry per
3634 AVAIL_IN[BLOCK] = AVAIL_OUT[dom(BLOCK)].
3635 AVAIL_OUT[BLOCK] = AVAIL_IN[BLOCK] U PHI_GEN[BLOCK] U TMP_GEN[BLOCK]. */
3638 compute_avail (void)
3641 basic_block block
, son
;
3642 basic_block
*worklist
;
3646 /* We pretend that default definitions are defined in the entry block.
3647 This includes function arguments and the static chain decl. */
3648 for (i
= 1; i
< num_ssa_names
; ++i
)
3650 tree name
= ssa_name (i
);
3653 || !SSA_NAME_IS_DEFAULT_DEF (name
)
3654 || has_zero_uses (name
)
3655 || virtual_operand_p (name
))
3658 e
= get_or_alloc_expr_for_name (name
);
3659 add_to_value (get_expr_value_id (e
), e
);
3660 bitmap_insert_into_set (TMP_GEN (ENTRY_BLOCK_PTR
), e
);
3661 bitmap_value_insert_into_set (AVAIL_OUT (ENTRY_BLOCK_PTR
), e
);
3664 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3666 print_bitmap_set (dump_file
, TMP_GEN (ENTRY_BLOCK_PTR
),
3667 "tmp_gen", ENTRY_BLOCK
);
3668 print_bitmap_set (dump_file
, AVAIL_OUT (ENTRY_BLOCK_PTR
),
3669 "avail_out", ENTRY_BLOCK
);
3672 /* Allocate the worklist. */
3673 worklist
= XNEWVEC (basic_block
, n_basic_blocks
);
3675 /* Seed the algorithm by putting the dominator children of the entry
3676 block on the worklist. */
3677 for (son
= first_dom_son (CDI_DOMINATORS
, ENTRY_BLOCK_PTR
);
3679 son
= next_dom_son (CDI_DOMINATORS
, son
))
3680 worklist
[sp
++] = son
;
3682 /* Loop until the worklist is empty. */
3685 gimple_stmt_iterator gsi
;
3689 /* Pick a block from the worklist. */
3690 block
= worklist
[--sp
];
3692 /* Initially, the set of available values in BLOCK is that of
3693 its immediate dominator. */
3694 dom
= get_immediate_dominator (CDI_DOMINATORS
, block
);
3696 bitmap_set_copy (AVAIL_OUT (block
), AVAIL_OUT (dom
));
3698 /* Generate values for PHI nodes. */
3699 for (gsi
= gsi_start_phis (block
); !gsi_end_p (gsi
); gsi_next (&gsi
))
3701 tree result
= gimple_phi_result (gsi_stmt (gsi
));
3703 /* We have no need for virtual phis, as they don't represent
3704 actual computations. */
3705 if (virtual_operand_p (result
))
3708 pre_expr e
= get_or_alloc_expr_for_name (result
);
3709 add_to_value (get_expr_value_id (e
), e
);
3710 bitmap_value_insert_into_set (AVAIL_OUT (block
), e
);
3711 bitmap_insert_into_set (PHI_GEN (block
), e
);
3714 BB_MAY_NOTRETURN (block
) = 0;
3716 /* Now compute value numbers and populate value sets with all
3717 the expressions computed in BLOCK. */
3718 for (gsi
= gsi_start_bb (block
); !gsi_end_p (gsi
); gsi_next (&gsi
))
3723 stmt
= gsi_stmt (gsi
);
3725 /* Cache whether the basic-block has any non-visible side-effect
3727 If this isn't a call or it is the last stmt in the
3728 basic-block then the CFG represents things correctly. */
3729 if (is_gimple_call (stmt
) && !stmt_ends_bb_p (stmt
))
3731 /* Non-looping const functions always return normally.
3732 Otherwise the call might not return or have side-effects
3733 that forbids hoisting possibly trapping expressions
3735 int flags
= gimple_call_flags (stmt
);
3736 if (!(flags
& ECF_CONST
)
3737 || (flags
& ECF_LOOPING_CONST_OR_PURE
))
3738 BB_MAY_NOTRETURN (block
) = 1;
3741 FOR_EACH_SSA_TREE_OPERAND (op
, stmt
, iter
, SSA_OP_DEF
)
3743 pre_expr e
= get_or_alloc_expr_for_name (op
);
3745 add_to_value (get_expr_value_id (e
), e
);
3746 bitmap_insert_into_set (TMP_GEN (block
), e
);
3747 bitmap_value_insert_into_set (AVAIL_OUT (block
), e
);
3750 if (gimple_has_side_effects (stmt
)
3751 || stmt_could_throw_p (stmt
)
3752 || is_gimple_debug (stmt
))
3755 FOR_EACH_SSA_TREE_OPERAND (op
, stmt
, iter
, SSA_OP_USE
)
3757 if (ssa_undefined_value_p (op
))
3759 pre_expr e
= get_or_alloc_expr_for_name (op
);
3760 bitmap_value_insert_into_set (EXP_GEN (block
), e
);
3763 switch (gimple_code (stmt
))
3771 pre_expr result
= NULL
;
3772 vec
<vn_reference_op_s
> ops
= vNULL
;
3774 /* We can value number only calls to real functions. */
3775 if (gimple_call_internal_p (stmt
))
3778 copy_reference_ops_from_call (stmt
, &ops
);
3779 vn_reference_lookup_pieces (gimple_vuse (stmt
), 0,
3780 gimple_expr_type (stmt
),
3781 ops
, &ref
, VN_NOWALK
);
3786 /* If the value of the call is not invalidated in
3787 this block until it is computed, add the expression
3789 if (!gimple_vuse (stmt
)
3791 (SSA_NAME_DEF_STMT (gimple_vuse (stmt
))) == GIMPLE_PHI
3792 || gimple_bb (SSA_NAME_DEF_STMT
3793 (gimple_vuse (stmt
))) != block
)
3795 result
= (pre_expr
) pool_alloc (pre_expr_pool
);
3796 result
->kind
= REFERENCE
;
3798 PRE_EXPR_REFERENCE (result
) = ref
;
3800 get_or_alloc_expression_id (result
);
3801 add_to_value (get_expr_value_id (result
), result
);
3802 bitmap_value_insert_into_set (EXP_GEN (block
), result
);
3809 pre_expr result
= NULL
;
3810 switch (vn_get_stmt_kind (stmt
))
3814 enum tree_code code
= gimple_assign_rhs_code (stmt
);
3817 /* COND_EXPR and VEC_COND_EXPR are awkward in
3818 that they contain an embedded complex expression.
3819 Don't even try to shove those through PRE. */
3820 if (code
== COND_EXPR
3821 || code
== VEC_COND_EXPR
)
3824 vn_nary_op_lookup_stmt (stmt
, &nary
);
3828 /* If the NARY traps and there was a preceding
3829 point in the block that might not return avoid
3830 adding the nary to EXP_GEN. */
3831 if (BB_MAY_NOTRETURN (block
)
3832 && vn_nary_may_trap (nary
))
3835 result
= (pre_expr
) pool_alloc (pre_expr_pool
);
3836 result
->kind
= NARY
;
3838 PRE_EXPR_NARY (result
) = nary
;
3845 vn_reference_lookup (gimple_assign_rhs1 (stmt
),
3851 /* If the value of the reference is not invalidated in
3852 this block until it is computed, add the expression
3854 if (gimple_vuse (stmt
))
3858 def_stmt
= SSA_NAME_DEF_STMT (gimple_vuse (stmt
));
3859 while (!gimple_nop_p (def_stmt
)
3860 && gimple_code (def_stmt
) != GIMPLE_PHI
3861 && gimple_bb (def_stmt
) == block
)
3863 if (stmt_may_clobber_ref_p
3864 (def_stmt
, gimple_assign_rhs1 (stmt
)))
3870 = SSA_NAME_DEF_STMT (gimple_vuse (def_stmt
));
3876 result
= (pre_expr
) pool_alloc (pre_expr_pool
);
3877 result
->kind
= REFERENCE
;
3879 PRE_EXPR_REFERENCE (result
) = ref
;
3887 get_or_alloc_expression_id (result
);
3888 add_to_value (get_expr_value_id (result
), result
);
3889 bitmap_value_insert_into_set (EXP_GEN (block
), result
);
3897 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3899 print_bitmap_set (dump_file
, EXP_GEN (block
),
3900 "exp_gen", block
->index
);
3901 print_bitmap_set (dump_file
, PHI_GEN (block
),
3902 "phi_gen", block
->index
);
3903 print_bitmap_set (dump_file
, TMP_GEN (block
),
3904 "tmp_gen", block
->index
);
3905 print_bitmap_set (dump_file
, AVAIL_OUT (block
),
3906 "avail_out", block
->index
);
3909 /* Put the dominator children of BLOCK on the worklist of blocks
3910 to compute available sets for. */
3911 for (son
= first_dom_son (CDI_DOMINATORS
, block
);
3913 son
= next_dom_son (CDI_DOMINATORS
, son
))
3914 worklist
[sp
++] = son
;
3921 /* Local state for the eliminate domwalk. */
3922 static vec
<gimple
> el_to_remove
;
3923 static vec
<gimple
> el_to_update
;
3924 static unsigned int el_todo
;
3925 static vec
<tree
> el_avail
;
3926 static vec
<tree
> el_avail_stack
;
3928 /* Return a leader for OP that is available at the current point of the
3929 eliminate domwalk. */
3932 eliminate_avail (tree op
)
3934 tree valnum
= VN_INFO (op
)->valnum
;
3935 if (TREE_CODE (valnum
) == SSA_NAME
)
3937 if (SSA_NAME_IS_DEFAULT_DEF (valnum
))
3939 if (el_avail
.length () > SSA_NAME_VERSION (valnum
))
3940 return el_avail
[SSA_NAME_VERSION (valnum
)];
3942 else if (is_gimple_min_invariant (valnum
))
3947 /* At the current point of the eliminate domwalk make OP available. */
3950 eliminate_push_avail (tree op
)
3952 tree valnum
= VN_INFO (op
)->valnum
;
3953 if (TREE_CODE (valnum
) == SSA_NAME
)
3955 if (el_avail
.length () <= SSA_NAME_VERSION (valnum
))
3956 el_avail
.safe_grow_cleared (SSA_NAME_VERSION (valnum
) + 1);
3957 el_avail
[SSA_NAME_VERSION (valnum
)] = op
;
3958 el_avail_stack
.safe_push (op
);
3962 /* Insert the expression recorded by SCCVN for VAL at *GSI. Returns
3963 the leader for the expression if insertion was successful. */
3966 eliminate_insert (gimple_stmt_iterator
*gsi
, tree val
)
3968 tree expr
= vn_get_expr_for (val
);
3969 if (!CONVERT_EXPR_P (expr
)
3970 && TREE_CODE (expr
) != VIEW_CONVERT_EXPR
)
3973 tree op
= TREE_OPERAND (expr
, 0);
3974 tree leader
= TREE_CODE (op
) == SSA_NAME
? eliminate_avail (op
) : op
;
3978 tree res
= make_temp_ssa_name (TREE_TYPE (val
), NULL
, "pretmp");
3979 gimple tem
= gimple_build_assign (res
,
3980 fold_build1 (TREE_CODE (expr
),
3981 TREE_TYPE (expr
), leader
));
3982 gsi_insert_before (gsi
, tem
, GSI_SAME_STMT
);
3983 VN_INFO_GET (res
)->valnum
= val
;
3985 if (TREE_CODE (leader
) == SSA_NAME
)
3986 gimple_set_plf (SSA_NAME_DEF_STMT (leader
), NECESSARY
, true);
3988 pre_stats
.insertions
++;
3989 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3991 fprintf (dump_file
, "Inserted ");
3992 print_gimple_stmt (dump_file
, tem
, 0, 0);
3998 /* Perform elimination for the basic-block B during the domwalk. */
4001 eliminate_bb (dom_walk_data
*, basic_block b
)
4003 gimple_stmt_iterator gsi
;
4007 el_avail_stack
.safe_push (NULL_TREE
);
4009 for (gsi
= gsi_start_phis (b
); !gsi_end_p (gsi
);)
4011 gimple stmt
, phi
= gsi_stmt (gsi
);
4012 tree sprime
= NULL_TREE
, res
= PHI_RESULT (phi
);
4013 gimple_stmt_iterator gsi2
;
4015 /* We want to perform redundant PHI elimination. Do so by
4016 replacing the PHI with a single copy if possible.
4017 Do not touch inserted, single-argument or virtual PHIs. */
4018 if (gimple_phi_num_args (phi
) == 1
4019 || virtual_operand_p (res
))
4025 sprime
= eliminate_avail (res
);
4029 eliminate_push_avail (res
);
4033 else if (is_gimple_min_invariant (sprime
))
4035 if (!useless_type_conversion_p (TREE_TYPE (res
),
4036 TREE_TYPE (sprime
)))
4037 sprime
= fold_convert (TREE_TYPE (res
), sprime
);
4040 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4042 fprintf (dump_file
, "Replaced redundant PHI node defining ");
4043 print_generic_expr (dump_file
, res
, 0);
4044 fprintf (dump_file
, " with ");
4045 print_generic_expr (dump_file
, sprime
, 0);
4046 fprintf (dump_file
, "\n");
4049 remove_phi_node (&gsi
, false);
4052 && !bitmap_bit_p (inserted_exprs
, SSA_NAME_VERSION (res
))
4053 && TREE_CODE (sprime
) == SSA_NAME
)
4054 gimple_set_plf (SSA_NAME_DEF_STMT (sprime
), NECESSARY
, true);
4056 if (!useless_type_conversion_p (TREE_TYPE (res
), TREE_TYPE (sprime
)))
4057 sprime
= fold_convert (TREE_TYPE (res
), sprime
);
4058 stmt
= gimple_build_assign (res
, sprime
);
4059 SSA_NAME_DEF_STMT (res
) = stmt
;
4060 gimple_set_plf (stmt
, NECESSARY
, gimple_plf (phi
, NECESSARY
));
4062 gsi2
= gsi_after_labels (b
);
4063 gsi_insert_before (&gsi2
, stmt
, GSI_NEW_STMT
);
4064 /* Queue the copy for eventual removal. */
4065 el_to_remove
.safe_push (stmt
);
4066 /* If we inserted this PHI node ourself, it's not an elimination. */
4068 && bitmap_bit_p (inserted_exprs
, SSA_NAME_VERSION (res
)))
4071 pre_stats
.eliminations
++;
4074 for (gsi
= gsi_start_bb (b
); !gsi_end_p (gsi
); gsi_next (&gsi
))
4076 tree lhs
= NULL_TREE
;
4077 tree rhs
= NULL_TREE
;
4079 stmt
= gsi_stmt (gsi
);
4081 if (gimple_has_lhs (stmt
))
4082 lhs
= gimple_get_lhs (stmt
);
4084 if (gimple_assign_single_p (stmt
))
4085 rhs
= gimple_assign_rhs1 (stmt
);
4087 /* Lookup the RHS of the expression, see if we have an
4088 available computation for it. If so, replace the RHS with
4089 the available computation.
4092 We don't replace global register variable when it is a the RHS of
4093 a single assign. We do replace local register variable since gcc
4094 does not guarantee local variable will be allocated in register. */
4095 if (gimple_has_lhs (stmt
)
4096 && TREE_CODE (lhs
) == SSA_NAME
4097 && !gimple_assign_ssa_name_copy_p (stmt
)
4098 && (!gimple_assign_single_p (stmt
)
4099 || (!is_gimple_min_invariant (rhs
)
4100 && (gimple_assign_rhs_code (stmt
) != VAR_DECL
4101 || !is_global_var (rhs
)
4102 || !DECL_HARD_REGISTER (rhs
))))
4103 && !gimple_has_volatile_ops (stmt
))
4106 gimple orig_stmt
= stmt
;
4108 sprime
= eliminate_avail (lhs
);
4111 /* If there is no existing usable leader but SCCVN thinks
4112 it has an expression it wants to use as replacement,
4114 tree val
= VN_INFO (lhs
)->valnum
;
4116 && TREE_CODE (val
) == SSA_NAME
4117 && VN_INFO (val
)->needs_insertion
4118 && (sprime
= eliminate_insert (&gsi
, val
)) != NULL_TREE
)
4119 eliminate_push_avail (sprime
);
4121 else if (is_gimple_min_invariant (sprime
))
4123 /* If there is no existing leader but SCCVN knows this
4124 value is constant, use that constant. */
4125 if (!useless_type_conversion_p (TREE_TYPE (lhs
),
4126 TREE_TYPE (sprime
)))
4127 sprime
= fold_convert (TREE_TYPE (lhs
), sprime
);
4129 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4131 fprintf (dump_file
, "Replaced ");
4132 print_gimple_expr (dump_file
, stmt
, 0, 0);
4133 fprintf (dump_file
, " with ");
4134 print_generic_expr (dump_file
, sprime
, 0);
4135 fprintf (dump_file
, " in ");
4136 print_gimple_stmt (dump_file
, stmt
, 0, 0);
4138 pre_stats
.eliminations
++;
4139 propagate_tree_value_into_stmt (&gsi
, sprime
);
4140 stmt
= gsi_stmt (gsi
);
4143 /* If we removed EH side-effects from the statement, clean
4144 its EH information. */
4145 if (maybe_clean_or_replace_eh_stmt (orig_stmt
, stmt
))
4147 bitmap_set_bit (need_eh_cleanup
,
4148 gimple_bb (stmt
)->index
);
4149 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4150 fprintf (dump_file
, " Removed EH side-effects.\n");
4155 /* If there is no usable leader mark lhs as leader for its value. */
4157 eliminate_push_avail (lhs
);
4161 && (rhs
== NULL_TREE
4162 || TREE_CODE (rhs
) != SSA_NAME
4163 || may_propagate_copy (rhs
, sprime
)))
4165 bool can_make_abnormal_goto
4166 = is_gimple_call (stmt
)
4167 && stmt_can_make_abnormal_goto (stmt
);
4169 gcc_assert (sprime
!= rhs
);
4171 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4173 fprintf (dump_file
, "Replaced ");
4174 print_gimple_expr (dump_file
, stmt
, 0, 0);
4175 fprintf (dump_file
, " with ");
4176 print_generic_expr (dump_file
, sprime
, 0);
4177 fprintf (dump_file
, " in ");
4178 print_gimple_stmt (dump_file
, stmt
, 0, 0);
4181 if (TREE_CODE (sprime
) == SSA_NAME
)
4182 gimple_set_plf (SSA_NAME_DEF_STMT (sprime
),
4184 /* We need to make sure the new and old types actually match,
4185 which may require adding a simple cast, which fold_convert
4187 if ((!rhs
|| TREE_CODE (rhs
) != SSA_NAME
)
4188 && !useless_type_conversion_p (gimple_expr_type (stmt
),
4189 TREE_TYPE (sprime
)))
4190 sprime
= fold_convert (gimple_expr_type (stmt
), sprime
);
4192 pre_stats
.eliminations
++;
4193 propagate_tree_value_into_stmt (&gsi
, sprime
);
4194 stmt
= gsi_stmt (gsi
);
4197 /* If we removed EH side-effects from the statement, clean
4198 its EH information. */
4199 if (maybe_clean_or_replace_eh_stmt (orig_stmt
, stmt
))
4201 bitmap_set_bit (need_eh_cleanup
,
4202 gimple_bb (stmt
)->index
);
4203 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4204 fprintf (dump_file
, " Removed EH side-effects.\n");
4207 /* Likewise for AB side-effects. */
4208 if (can_make_abnormal_goto
4209 && !stmt_can_make_abnormal_goto (stmt
))
4211 bitmap_set_bit (need_ab_cleanup
,
4212 gimple_bb (stmt
)->index
);
4213 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4214 fprintf (dump_file
, " Removed AB side-effects.\n");
4218 /* If the statement is a scalar store, see if the expression
4219 has the same value number as its rhs. If so, the store is
4221 else if (gimple_assign_single_p (stmt
)
4222 && !gimple_has_volatile_ops (stmt
)
4223 && !is_gimple_reg (gimple_assign_lhs (stmt
))
4224 && (TREE_CODE (rhs
) == SSA_NAME
4225 || is_gimple_min_invariant (rhs
)))
4228 val
= vn_reference_lookup (gimple_assign_lhs (stmt
),
4229 gimple_vuse (stmt
), VN_WALK
, NULL
);
4230 if (TREE_CODE (rhs
) == SSA_NAME
)
4231 rhs
= VN_INFO (rhs
)->valnum
;
4233 && operand_equal_p (val
, rhs
, 0))
4235 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4237 fprintf (dump_file
, "Deleted redundant store ");
4238 print_gimple_stmt (dump_file
, stmt
, 0, 0);
4241 /* Queue stmt for removal. */
4242 el_to_remove
.safe_push (stmt
);
4245 /* Visit COND_EXPRs and fold the comparison with the
4246 available value-numbers. */
4247 else if (gimple_code (stmt
) == GIMPLE_COND
)
4249 tree op0
= gimple_cond_lhs (stmt
);
4250 tree op1
= gimple_cond_rhs (stmt
);
4253 if (TREE_CODE (op0
) == SSA_NAME
)
4254 op0
= VN_INFO (op0
)->valnum
;
4255 if (TREE_CODE (op1
) == SSA_NAME
)
4256 op1
= VN_INFO (op1
)->valnum
;
4257 result
= fold_binary (gimple_cond_code (stmt
), boolean_type_node
,
4259 if (result
&& TREE_CODE (result
) == INTEGER_CST
)
4261 if (integer_zerop (result
))
4262 gimple_cond_make_false (stmt
);
4264 gimple_cond_make_true (stmt
);
4266 el_todo
= TODO_cleanup_cfg
;
4269 /* Visit indirect calls and turn them into direct calls if
4271 if (is_gimple_call (stmt
))
4273 tree orig_fn
= gimple_call_fn (stmt
);
4277 if (TREE_CODE (orig_fn
) == SSA_NAME
)
4278 fn
= VN_INFO (orig_fn
)->valnum
;
4279 else if (TREE_CODE (orig_fn
) == OBJ_TYPE_REF
4280 && TREE_CODE (OBJ_TYPE_REF_EXPR (orig_fn
)) == SSA_NAME
)
4281 fn
= VN_INFO (OBJ_TYPE_REF_EXPR (orig_fn
))->valnum
;
4284 if (gimple_call_addr_fndecl (fn
) != NULL_TREE
4285 && useless_type_conversion_p (TREE_TYPE (orig_fn
),
4288 bool can_make_abnormal_goto
4289 = stmt_can_make_abnormal_goto (stmt
);
4290 bool was_noreturn
= gimple_call_noreturn_p (stmt
);
4292 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4294 fprintf (dump_file
, "Replacing call target with ");
4295 print_generic_expr (dump_file
, fn
, 0);
4296 fprintf (dump_file
, " in ");
4297 print_gimple_stmt (dump_file
, stmt
, 0, 0);
4300 gimple_call_set_fn (stmt
, fn
);
4301 el_to_update
.safe_push (stmt
);
4303 /* When changing a call into a noreturn call, cfg cleanup
4304 is needed to fix up the noreturn call. */
4305 if (!was_noreturn
&& gimple_call_noreturn_p (stmt
))
4306 el_todo
|= TODO_cleanup_cfg
;
4308 /* If we removed EH side-effects from the statement, clean
4309 its EH information. */
4310 if (maybe_clean_or_replace_eh_stmt (stmt
, stmt
))
4312 bitmap_set_bit (need_eh_cleanup
,
4313 gimple_bb (stmt
)->index
);
4314 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4315 fprintf (dump_file
, " Removed EH side-effects.\n");
4318 /* Likewise for AB side-effects. */
4319 if (can_make_abnormal_goto
4320 && !stmt_can_make_abnormal_goto (stmt
))
4322 bitmap_set_bit (need_ab_cleanup
,
4323 gimple_bb (stmt
)->index
);
4324 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4325 fprintf (dump_file
, " Removed AB side-effects.\n");
4328 /* Changing an indirect call to a direct call may
4329 have exposed different semantics. This may
4330 require an SSA update. */
4331 el_todo
|= TODO_update_ssa_only_virtuals
;
4337 /* Make no longer available leaders no longer available. */
4340 eliminate_leave_block (dom_walk_data
*, basic_block
)
4343 while ((entry
= el_avail_stack
.pop ()) != NULL_TREE
)
4344 el_avail
[SSA_NAME_VERSION (VN_INFO (entry
)->valnum
)] = NULL_TREE
;
4347 /* Eliminate fully redundant computations. */
4352 struct dom_walk_data walk_data
;
4353 gimple_stmt_iterator gsi
;
4357 need_eh_cleanup
= BITMAP_ALLOC (NULL
);
4358 need_ab_cleanup
= BITMAP_ALLOC (NULL
);
4360 el_to_remove
.create (0);
4361 el_to_update
.create (0);
4363 el_avail
.create (0);
4364 el_avail_stack
.create (0);
4366 walk_data
.dom_direction
= CDI_DOMINATORS
;
4367 walk_data
.initialize_block_local_data
= NULL
;
4368 walk_data
.before_dom_children
= eliminate_bb
;
4369 walk_data
.after_dom_children
= eliminate_leave_block
;
4370 walk_data
.global_data
= NULL
;
4371 walk_data
.block_local_data_size
= 0;
4372 init_walk_dominator_tree (&walk_data
);
4373 walk_dominator_tree (&walk_data
, ENTRY_BLOCK_PTR
);
4374 fini_walk_dominator_tree (&walk_data
);
4376 el_avail
.release ();
4377 el_avail_stack
.release ();
4379 /* We cannot remove stmts during BB walk, especially not release SSA
4380 names there as this confuses the VN machinery. The stmts ending
4381 up in el_to_remove are either stores or simple copies. */
4382 FOR_EACH_VEC_ELT (el_to_remove
, i
, stmt
)
4384 tree lhs
= gimple_assign_lhs (stmt
);
4385 tree rhs
= gimple_assign_rhs1 (stmt
);
4386 use_operand_p use_p
;
4389 /* If there is a single use only, propagate the equivalency
4390 instead of keeping the copy. */
4391 if (TREE_CODE (lhs
) == SSA_NAME
4392 && TREE_CODE (rhs
) == SSA_NAME
4393 && single_imm_use (lhs
, &use_p
, &use_stmt
)
4394 && may_propagate_copy (USE_FROM_PTR (use_p
), rhs
))
4396 SET_USE (use_p
, rhs
);
4397 update_stmt (use_stmt
);
4399 && bitmap_bit_p (inserted_exprs
, SSA_NAME_VERSION (lhs
))
4400 && TREE_CODE (rhs
) == SSA_NAME
)
4401 gimple_set_plf (SSA_NAME_DEF_STMT (rhs
), NECESSARY
, true);
4404 /* If this is a store or a now unused copy, remove it. */
4405 if (TREE_CODE (lhs
) != SSA_NAME
4406 || has_zero_uses (lhs
))
4408 basic_block bb
= gimple_bb (stmt
);
4409 gsi
= gsi_for_stmt (stmt
);
4410 unlink_stmt_vdef (stmt
);
4411 if (gsi_remove (&gsi
, true))
4412 bitmap_set_bit (need_eh_cleanup
, bb
->index
);
4414 && TREE_CODE (lhs
) == SSA_NAME
)
4415 bitmap_clear_bit (inserted_exprs
, SSA_NAME_VERSION (lhs
));
4416 release_defs (stmt
);
4419 el_to_remove
.release ();
4421 /* We cannot update call statements with virtual operands during
4422 SSA walk. This might remove them which in turn makes our
4423 VN lattice invalid. */
4424 FOR_EACH_VEC_ELT (el_to_update
, i
, stmt
)
4426 el_to_update
.release ();
4431 /* Perform CFG cleanups made necessary by elimination. */
4434 fini_eliminate (void)
4436 bool do_eh_cleanup
= !bitmap_empty_p (need_eh_cleanup
);
4437 bool do_ab_cleanup
= !bitmap_empty_p (need_ab_cleanup
);
4440 gimple_purge_all_dead_eh_edges (need_eh_cleanup
);
4443 gimple_purge_all_dead_abnormal_call_edges (need_ab_cleanup
);
4445 BITMAP_FREE (need_eh_cleanup
);
4446 BITMAP_FREE (need_ab_cleanup
);
4448 if (do_eh_cleanup
|| do_ab_cleanup
)
4449 return TODO_cleanup_cfg
;
4453 /* Borrow a bit of tree-ssa-dce.c for the moment.
4454 XXX: In 4.1, we should be able to just run a DCE pass after PRE, though
4455 this may be a bit faster, and we may want critical edges kept split. */
4457 /* If OP's defining statement has not already been determined to be necessary,
4458 mark that statement necessary. Return the stmt, if it is newly
4461 static inline gimple
4462 mark_operand_necessary (tree op
)
4468 if (TREE_CODE (op
) != SSA_NAME
)
4471 stmt
= SSA_NAME_DEF_STMT (op
);
4474 if (gimple_plf (stmt
, NECESSARY
)
4475 || gimple_nop_p (stmt
))
4478 gimple_set_plf (stmt
, NECESSARY
, true);
4482 /* Because we don't follow exactly the standard PRE algorithm, and decide not
4483 to insert PHI nodes sometimes, and because value numbering of casts isn't
4484 perfect, we sometimes end up inserting dead code. This simple DCE-like
4485 pass removes any insertions we made that weren't actually used. */
4488 remove_dead_inserted_code (void)
4495 worklist
= BITMAP_ALLOC (NULL
);
4496 EXECUTE_IF_SET_IN_BITMAP (inserted_exprs
, 0, i
, bi
)
4498 t
= SSA_NAME_DEF_STMT (ssa_name (i
));
4499 if (gimple_plf (t
, NECESSARY
))
4500 bitmap_set_bit (worklist
, i
);
4502 while (!bitmap_empty_p (worklist
))
4504 i
= bitmap_first_set_bit (worklist
);
4505 bitmap_clear_bit (worklist
, i
);
4506 t
= SSA_NAME_DEF_STMT (ssa_name (i
));
4508 /* PHI nodes are somewhat special in that each PHI alternative has
4509 data and control dependencies. All the statements feeding the
4510 PHI node's arguments are always necessary. */
4511 if (gimple_code (t
) == GIMPLE_PHI
)
4515 for (k
= 0; k
< gimple_phi_num_args (t
); k
++)
4517 tree arg
= PHI_ARG_DEF (t
, k
);
4518 if (TREE_CODE (arg
) == SSA_NAME
)
4520 gimple n
= mark_operand_necessary (arg
);
4522 bitmap_set_bit (worklist
, SSA_NAME_VERSION (arg
));
4528 /* Propagate through the operands. Examine all the USE, VUSE and
4529 VDEF operands in this statement. Mark all the statements
4530 which feed this statement's uses as necessary. */
4534 /* The operands of VDEF expressions are also needed as they
4535 represent potential definitions that may reach this
4536 statement (VDEF operands allow us to follow def-def
4539 FOR_EACH_SSA_TREE_OPERAND (use
, t
, iter
, SSA_OP_ALL_USES
)
4541 gimple n
= mark_operand_necessary (use
);
4543 bitmap_set_bit (worklist
, SSA_NAME_VERSION (use
));
4548 EXECUTE_IF_SET_IN_BITMAP (inserted_exprs
, 0, i
, bi
)
4550 t
= SSA_NAME_DEF_STMT (ssa_name (i
));
4551 if (!gimple_plf (t
, NECESSARY
))
4553 gimple_stmt_iterator gsi
;
4555 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4557 fprintf (dump_file
, "Removing unnecessary insertion:");
4558 print_gimple_stmt (dump_file
, t
, 0, 0);
4561 gsi
= gsi_for_stmt (t
);
4562 if (gimple_code (t
) == GIMPLE_PHI
)
4563 remove_phi_node (&gsi
, true);
4566 gsi_remove (&gsi
, true);
4571 BITMAP_FREE (worklist
);
4575 /* Initialize data structures used by PRE. */
4582 next_expression_id
= 1;
4583 expressions
.create (0);
4584 expressions
.safe_push (NULL
);
4585 value_expressions
.create (get_max_value_id () + 1);
4586 value_expressions
.safe_grow_cleared (get_max_value_id() + 1);
4587 name_to_id
.create (0);
4589 inserted_exprs
= BITMAP_ALLOC (NULL
);
4591 connect_infinite_loops_to_exit ();
4592 memset (&pre_stats
, 0, sizeof (pre_stats
));
4594 postorder
= XNEWVEC (int, n_basic_blocks
);
4595 postorder_num
= inverted_post_order_compute (postorder
);
4597 alloc_aux_for_blocks (sizeof (struct bb_bitmap_sets
));
4599 calculate_dominance_info (CDI_POST_DOMINATORS
);
4600 calculate_dominance_info (CDI_DOMINATORS
);
4602 bitmap_obstack_initialize (&grand_bitmap_obstack
);
4603 phi_translate_table
.create (5110);
4604 expression_to_id
.create (num_ssa_names
* 3);
4605 bitmap_set_pool
= create_alloc_pool ("Bitmap sets",
4606 sizeof (struct bitmap_set
), 30);
4607 pre_expr_pool
= create_alloc_pool ("pre_expr nodes",
4608 sizeof (struct pre_expr_d
), 30);
4611 EXP_GEN (bb
) = bitmap_set_new ();
4612 PHI_GEN (bb
) = bitmap_set_new ();
4613 TMP_GEN (bb
) = bitmap_set_new ();
4614 AVAIL_OUT (bb
) = bitmap_set_new ();
4619 /* Deallocate data structures used by PRE. */
4625 value_expressions
.release ();
4626 BITMAP_FREE (inserted_exprs
);
4627 bitmap_obstack_release (&grand_bitmap_obstack
);
4628 free_alloc_pool (bitmap_set_pool
);
4629 free_alloc_pool (pre_expr_pool
);
4630 phi_translate_table
.dispose ();
4631 expression_to_id
.dispose ();
4632 name_to_id
.release ();
4634 free_aux_for_blocks ();
4636 free_dominance_info (CDI_POST_DOMINATORS
);
4639 /* Gate and execute functions for PRE. */
4644 unsigned int todo
= 0;
4646 do_partial_partial
=
4647 flag_tree_partial_pre
&& optimize_function_for_speed_p (cfun
);
4649 /* This has to happen before SCCVN runs because
4650 loop_optimizer_init may create new phis, etc. */
4651 loop_optimizer_init (LOOPS_NORMAL
);
4653 if (!run_scc_vn (VN_WALK
))
4655 loop_optimizer_finalize ();
4662 /* Collect and value number expressions computed in each basic block. */
4665 /* Insert can get quite slow on an incredibly large number of basic
4666 blocks due to some quadratic behavior. Until this behavior is
4667 fixed, don't run it when he have an incredibly large number of
4668 bb's. If we aren't going to run insert, there is no point in
4669 computing ANTIC, either, even though it's plenty fast. */
4670 if (n_basic_blocks
< 4000)
4676 /* Make sure to remove fake edges before committing our inserts.
4677 This makes sure we don't end up with extra critical edges that
4678 we would need to split. */
4679 remove_fake_exit_edges ();
4680 gsi_commit_edge_inserts ();
4682 /* Remove all the redundant expressions. */
4683 todo
|= eliminate ();
4685 statistics_counter_event (cfun
, "Insertions", pre_stats
.insertions
);
4686 statistics_counter_event (cfun
, "PA inserted", pre_stats
.pa_insert
);
4687 statistics_counter_event (cfun
, "New PHIs", pre_stats
.phis
);
4688 statistics_counter_event (cfun
, "Eliminated", pre_stats
.eliminations
);
4689 statistics_counter_event (cfun
, "Constified", pre_stats
.constified
);
4691 clear_expression_ids ();
4692 remove_dead_inserted_code ();
4693 todo
|= TODO_verify_flow
;
4697 todo
|= fini_eliminate ();
4698 loop_optimizer_finalize ();
4700 /* TODO: tail_merge_optimize may merge all predecessors of a block, in which
4701 case we can merge the block with the remaining predecessor of the block.
4703 - call merge_blocks after each tail merge iteration
4704 - call merge_blocks after all tail merge iterations
4705 - mark TODO_cleanup_cfg when necessary
4706 - share the cfg cleanup with fini_pre. */
4707 todo
|= tail_merge_optimize (todo
);
4711 /* Tail merging invalidates the virtual SSA web, together with
4712 cfg-cleanup opportunities exposed by PRE this will wreck the
4713 SSA updating machinery. So make sure to run update-ssa
4714 manually, before eventually scheduling cfg-cleanup as part of
4716 update_ssa (TODO_update_ssa_only_virtuals
);
4724 return flag_tree_pre
!= 0;
4727 struct gimple_opt_pass pass_pre
=
4732 OPTGROUP_NONE
, /* optinfo_flags */
4733 gate_pre
, /* gate */
4734 do_pre
, /* execute */
4737 0, /* static_pass_number */
4738 TV_TREE_PRE
, /* tv_id */
4739 PROP_no_crit_edges
| PROP_cfg
4740 | PROP_ssa
, /* properties_required */
4741 0, /* properties_provided */
4742 0, /* properties_destroyed */
4743 TODO_rebuild_alias
, /* todo_flags_start */
4744 TODO_ggc_collect
| TODO_verify_ssa
/* todo_flags_finish */
4749 /* Gate and execute functions for FRE. */
4754 unsigned int todo
= 0;
4756 if (!run_scc_vn (VN_WALKREWRITE
))
4759 memset (&pre_stats
, 0, sizeof (pre_stats
));
4761 /* Remove all the redundant expressions. */
4762 todo
|= eliminate ();
4764 todo
|= fini_eliminate ();
4768 statistics_counter_event (cfun
, "Insertions", pre_stats
.insertions
);
4769 statistics_counter_event (cfun
, "Eliminated", pre_stats
.eliminations
);
4770 statistics_counter_event (cfun
, "Constified", pre_stats
.constified
);
4778 return flag_tree_fre
!= 0;
4781 struct gimple_opt_pass pass_fre
=
4786 OPTGROUP_NONE
, /* optinfo_flags */
4787 gate_fre
, /* gate */
4788 execute_fre
, /* execute */
4791 0, /* static_pass_number */
4792 TV_TREE_FRE
, /* tv_id */
4793 PROP_cfg
| PROP_ssa
, /* properties_required */
4794 0, /* properties_provided */
4795 0, /* properties_destroyed */
4796 0, /* todo_flags_start */
4797 TODO_ggc_collect
| TODO_verify_ssa
/* todo_flags_finish */