2 Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Daniel Berlin <dan@dberlin.org> and Steven Bosscher
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "coretypes.h"
30 /* These RTL headers are needed for basic-block.h. */
33 #include "hard-reg-set.h"
34 #include "basic-block.h"
35 #include "diagnostic.h"
36 #include "tree-inline.h"
37 #include "tree-flow.h"
38 #include "tree-gimple.h"
39 #include "tree-dump.h"
43 #include "tree-iterator.h"
45 #include "alloc-pool.h"
46 #include "tree-pass.h"
48 #include "splay-tree.h"
50 #include "langhooks.h"
53 1. Implement load value numbering.
54 2. Speed up insert_aux so that we can use it all the time. It
55 spends most of it's time in quadratic value replacement.
56 3. Avail sets can be shared by making an avail_find_leader that
57 walks up the dominator tree and looks in those avail sets.
58 This might affect code optimality, it's unclear right now.
59 4. Load motion can be performed by value numbering the loads the
60 same as we do other expressions. This requires iterative
61 hashing the vuses into the values. Right now we simply assign
62 a new value every time we see a statement with a vuse.
63 5. Strength reduction can be performed by anticipating expressions
64 we can repair later on.
67 /* For ease of terminology, "expression node" in the below refers to
68 every expression node but MODIFY_EXPR, because MODIFY_EXPR's represent
69 the actual statement containing the expressions we care about, and
70 we cache the value number by putting it in the expression. */
74 First we walk the statements to generate the AVAIL sets, the EXP_GEN
75 sets, and the tmp_gen sets. AVAIL is a forward dataflow
76 problem. EXP_GEN sets represent the generation of
77 values/expressions by a given block. We use them when computing
78 the ANTIC sets. The AVAIL sets consist of SSA_NAME's that
79 represent values, so we know what values are available in what
80 blocks. In SSA, values are never killed, so we don't need a kill
81 set, or a fixpoint iteration, in order to calculate the AVAIL sets.
82 In traditional parlance, AVAIL sets tell us the downsafety of the
85 Next, we generate the ANTIC sets. ANTIC is a backwards dataflow
86 problem. These sets represent the anticipatable expressions. An
87 expression is anticipatable in a given block if it could be
88 generated in that block. This means that if we had to perform an
89 insertion in that block, of the value of that expression, we could.
90 Calculating the ANTIC sets requires phi translation of expressions,
91 because the flow goes backwards through phis. We must iterate to a
92 fixpoint of the ANTIC sets, because we have a kill set.
93 Even in SSA form, values are not live over the entire function,
94 only from their definition point onwards. So we have to remove
95 values from the ANTIC set once we go past the definition point of
96 the leaders that make them up. compute_antic/compute_antic_aux
97 performs this computation.
99 Third, we perform insertions to make partially redundant
100 expressions fully redundant.
102 An expression is partially redundant (excluding partial
105 1. It is AVAIL in some, but not all, of the predecessors of a
107 2. It is ANTIC in all the predecessors.
109 In order to make it fully redundant, we insert the expression into
110 the predecessors where it is not available, but is ANTIC.
111 insert/insert_aux performs this insertion.
113 Fourth, we eliminate fully redundant expressions.
114 This is a simple statement walk that replaces redundant
115 calculations with the now available values. */
117 /* Representations of value numbers:
119 Value numbers are represented using the "value handle" approach.
120 This means that each SSA_NAME (and for other reasons to be
121 disclosed in a moment, expression nodes and constant nodes) has a
122 value handle that can be retrieved through get_value_handle. This
123 value handle, *is* the value number of the SSA_NAME. You can
124 pointer compare the value handles for equivalence purposes.
126 For debugging reasons, the value handle is internally more than
127 just a number, it is a VAR_DECL named "value.x", where x is a
128 unique number for each value number in use. This allows
129 expressions with SSA_NAMES replaced by value handles to still be
130 pretty printed in a sane way. They simply print as "value.3 *
133 Expression nodes have value handles associated with them as a
134 cache. Otherwise, we'd have to look them up again in the hash
135 table This makes significant difference (factor of two or more) on
136 some test cases. They can be thrown away after the Constants have
137 value handles associated with them so that they aren't special
138 cased everywhere, and for consistency sake. This may be changed
139 depending on memory usage vs code maintenance tradeoff. */
141 /* Representation of expressions on value numbers:
143 In some portions of this code, you will notice we allocate "fake"
144 analogues to the expression we are value numbering, and replace the
145 operands with the values of the expression. Since we work on
146 values, and not just names, we canonicalize expressions to value
147 expressions for use in the ANTIC sets, the EXP_GEN set, etc.
149 This is theoretically unnecessary, it just saves a bunch of
150 repeated get_value_handle and find_leader calls in the remainder of
151 the code, trading off temporary memory usage for speed. The tree
152 nodes aren't actually creating more garbage, since they are
153 allocated in a special pools which are thrown away at the end of
156 All of this also means that if you print the EXP_GEN or ANTIC sets,
157 you will see "value.5 + value.7" in the set, instead of "a_55 +
158 b_66" or something. The only thing that actually cares about
159 seeing the value leaders is phi translation, and it needs to be
160 able to find the leader for a value in an arbitrary block, so this
161 "value expression" form is perfect for it (otherwise you'd do
162 get_value_handle->find_leader->translate->get_value_handle->find_leader).*/
165 /* Representation of sets:
167 Sets are represented as doubly linked lists kept in topological
168 order, with an optional supporting bitmap of values present in the
169 set. The sets represent values, and the elements can be constants,
170 values, or expressions. The elements can appear in different sets,
171 but each element can only appear once in each set.
173 Since each node in the set represents a value, we also want to be
174 able to map expression, set pairs to something that tells us
175 whether the value is present is a set. We use a per-set bitmap for
176 that. The value handles also point to a linked list of the
177 expressions they represent via a tree annotation. This is mainly
178 useful only for debugging, since we don't do identity lookups. */
181 /* A value set element. Basically a single linked list of
182 expressions/constants/values. */
183 typedef struct value_set_node
186 struct value_set_node
*next
;
190 /* A value set, which is the head of the linked list, and we also keep
191 the tail because we have to append for the topolofical sort. */
192 typedef struct value_set
194 value_set_node_t head
;
195 value_set_node_t tail
;
202 /* All of the following sets, except for TMP_GEN, are indexed.
203 TMP_GEN is only ever iterated over, we never check what values
205 typedef struct bb_value_sets
210 value_set_t avail_out
;
211 value_set_t antic_in
;
212 value_set_t new_sets
;
215 #define EXP_GEN(BB) ((bb_value_sets_t) ((BB)->aux))->exp_gen
216 #define PHI_GEN(BB) ((bb_value_sets_t) ((BB)->aux))->phi_gen
217 #define TMP_GEN(BB) ((bb_value_sets_t) ((BB)->aux))->tmp_gen
218 #define AVAIL_OUT(BB) ((bb_value_sets_t) ((BB)->aux))->avail_out
219 #define ANTIC_IN(BB) ((bb_value_sets_t) ((BB)->aux))->antic_in
220 #define NEW_SETS(BB) ((bb_value_sets_t) ((BB)->aux))->new_sets
229 static tree
find_leader (value_set_t
, tree
);
230 static void value_insert_into_set (value_set_t
, tree
);
231 static void insert_into_set (value_set_t
, tree
);
232 static void add_to_value (tree
, tree
);
233 static value_set_t
set_new (bool);
234 static bool is_undefined_value (tree
);
236 /* We can add and remove elements and entries to and from sets
237 and hash tables, so we use alloc pools for them. */
239 static alloc_pool value_set_pool
;
240 static alloc_pool value_set_node_pool
;
241 static alloc_pool binary_node_pool
;
242 static alloc_pool unary_node_pool
;
244 /* The value table that maps expressions to values. */
245 static htab_t value_table
;
247 /* The phi_translate_table caches phi translations for a given
248 expression and predecessor. */
249 static htab_t phi_translate_table
;
252 /* Map expressions to values. These are simple pairs of expressions
253 and the values they represent. To find the value represented by
254 an expression, we use a hash table where the elements are {e,v}
255 pairs, and the expression is the key. */
257 typedef struct val_expr_pair_d
264 /* Hash a {v,e} pair. We really only hash the expression. */
267 val_expr_pair_hash (const void *p
)
269 const val_expr_pair_t ve
= (val_expr_pair_t
) p
;
274 /* Are {e2,v2} and {e1,v1} the same? Again, only the expression
278 val_expr_pair_expr_eq (const void *p1
, const void *p2
)
280 const val_expr_pair_t ve1
= (val_expr_pair_t
) p1
;
281 const val_expr_pair_t ve2
= (val_expr_pair_t
) p2
;
289 te1
= TREE_TYPE (e1
);
290 te2
= TREE_TYPE (e2
);
291 if (TREE_CODE (e1
) == TREE_CODE (e2
)
292 && (te1
== te2
|| lang_hooks
.types_compatible_p (te1
, te2
))
293 && operand_equal_p (e1
, e2
, 0))
300 /* Get the value handle of EXPR. This is the only correct way to get
301 the value handle for a "thing". */
304 get_value_handle (tree expr
)
306 /* We should never see these. */
309 else if (TREE_CODE (expr
) == SSA_NAME
)
311 return SSA_NAME_VALUE (expr
);
313 else if (TREE_CODE_CLASS (TREE_CODE (expr
)) == 'c')
315 cst_ann_t ann
= cst_ann (expr
);
317 return ann
->common
.value_handle
;
320 else if (EXPR_P (expr
))
322 expr_ann_t ann
= expr_ann (expr
);
324 return ann
->common
.value_handle
;
331 /* Set the value handle for E to V */
334 set_value_handle (tree e
, tree v
)
338 else if (TREE_CODE (e
) == SSA_NAME
)
339 SSA_NAME_VALUE (e
) = v
;
340 else if (TREE_CODE_CLASS (TREE_CODE (e
)) == 'c')
341 get_cst_ann (e
)->common
.value_handle
= v
;
343 get_expr_ann (e
)->common
.value_handle
= v
;
346 /* A three tuple {e, pred, v} used to cache phi translations in the
347 phi_translate_table. */
349 typedef struct expr_pred_trans_d
355 } *expr_pred_trans_t
;
357 /* Return the hash value for a phi translation table entry. */
360 expr_pred_trans_hash (const void *p
)
362 const expr_pred_trans_t ve
= (expr_pred_trans_t
) p
;
366 /* Return true if two phi translation table entries are the same. */
369 expr_pred_trans_eq (const void *p1
, const void *p2
)
371 const expr_pred_trans_t ve1
= (expr_pred_trans_t
) p1
;
372 const expr_pred_trans_t ve2
= (expr_pred_trans_t
) p2
;
375 basic_block b1
= ve1
->pred
;
376 basic_block b2
= ve2
->pred
;
386 te1
= TREE_TYPE (e1
);
387 te2
= TREE_TYPE (e2
);
389 if (TREE_CODE (e1
) == TREE_CODE (e2
)
390 && (te1
== te2
|| lang_hooks
.types_compatible_p (te1
, te2
))
391 && operand_equal_p (e1
, e2
, 0))
397 /* Search in the phi translation table for the translation of E in
398 PRED. Return the translated value, if found, NULL otherwise. */
401 phi_trans_lookup (tree e
, basic_block pred
)
404 struct expr_pred_trans_d ugly
;
407 ugly
.hashcode
= iterative_hash_expr (e
, (unsigned long) pred
);
408 slot
= htab_find_slot_with_hash (phi_translate_table
, &ugly
, ugly
.hashcode
,
413 return ((expr_pred_trans_t
) *slot
)->v
;
417 /* Add the tuple mapping {e, pred}->v to the phi translation table. */
420 phi_trans_add (tree e
, tree v
, basic_block pred
)
423 expr_pred_trans_t new_pair
= xmalloc (sizeof (*new_pair
));
425 new_pair
->pred
= pred
;
427 new_pair
->hashcode
= iterative_hash_expr (e
, (unsigned long) pred
);
428 slot
= htab_find_slot_with_hash (phi_translate_table
, new_pair
,
429 new_pair
->hashcode
, INSERT
);
432 *slot
= (void *) new_pair
;
435 /* Search in TABLE for an existing instance of expression E,
436 and return its value, or NULL if none has been set. */
439 lookup (htab_t table
, tree e
)
442 struct val_expr_pair_d ugly
= {NULL
, NULL
, 0};
444 ugly
.hashcode
= iterative_hash_expr (e
,0);
445 slot
= htab_find_slot_with_hash (table
, &ugly
, ugly
.hashcode
, NO_INSERT
);
449 return ((val_expr_pair_t
) *slot
)->v
;
452 /* Add E to the expression set of V. */
455 add_to_value (tree v
, tree e
)
457 #if DEBUG_VALUE_EXPRESSIONS
458 var_ann_t va
= var_ann (v
);
460 /* For values representing numerical constants, we mark
461 TREE_CONSTANT as true and set the tree chain to the actual
462 constant. This is because unlike values involving expressions,
463 which are only available to use where the expressions are live, a
464 constant can be remade anywhere, and thus, is available
466 if (TREE_CODE_CLASS (TREE_CODE (e
)) == 'c')
468 TREE_CONSTANT (v
) = true;
471 #if DEBUG_VALUE_EXPRESSIONS
472 if (va
->expr_set
== NULL
)
473 va
->expr_set
= set_new (false);
474 insert_into_set (va
->expr_set
, e
);
478 /* Insert E into TABLE with value V, and add E to the value set for V. */
481 add (htab_t table
, tree e
, tree v
)
485 val_expr_pair_t new_pair
= xmalloc (sizeof (struct val_expr_pair_d
));
488 new_pair
->hashcode
= iterative_hash_expr (e
, 0);
489 slot
= htab_find_slot_with_hash (table
, new_pair
, new_pair
->hashcode
,
493 *slot
= (void *) new_pair
;
494 set_value_handle (e
, v
);
502 /* Create a new value handle for EXPR. */
504 create_new_value (tree expr
)
506 tree a
= create_tmp_var_raw (TREE_TYPE (expr
), "value");
508 var_ann (a
)->uid
= pre_uid
++;
510 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
512 fprintf (dump_file
, "Created value ");
513 print_generic_expr (dump_file
, a
, dump_flags
);
514 fprintf (dump_file
, " for ");
515 print_generic_expr (dump_file
, expr
, dump_flags
);
516 fprintf (dump_file
, "\n");
521 /* Like lookup, but adds V as the value for E if E does not have a value. */
523 lookup_or_add (htab_t table
, tree e
)
525 tree x
= lookup (table
, e
);
529 v
= create_new_value (e
);
533 set_value_handle (e
, x
);
538 /* Search in the bitmap for SET to see if E exists. */
541 value_exists_in_set_bitmap (value_set_t set
, tree e
)
543 if (TREE_CODE (e
) != VAR_DECL
)
548 return bitmap_bit_p (set
->values
, get_var_ann (e
)->uid
);
551 /* Remove E from the bitmap for SET. */
554 value_remove_from_set_bitmap (value_set_t set
, tree e
)
556 if (TREE_CODE (e
) != VAR_DECL
)
558 #ifdef ENABLE_CHECKING
564 bitmap_clear_bit (set
->values
, get_var_ann (e
)->uid
);
568 /* Insert the value number E into the bitmap of values existing in
572 value_insert_into_set_bitmap (value_set_t set
, tree e
)
574 if (TREE_CODE (e
) != VAR_DECL
)
576 #ifdef ENABLE_CHECKING
580 if (set
->values
== NULL
)
582 set
->values
= BITMAP_GGC_ALLOC ();
583 bitmap_clear (set
->values
);
585 bitmap_set_bit (set
->values
, get_var_ann (e
)->uid
);
588 /* Create a new set. */
591 set_new (bool indexed
)
594 ret
= pool_alloc (value_set_pool
);
595 ret
->head
= ret
->tail
= NULL
;
597 ret
->indexed
= indexed
;
603 /* Insert EXPR into SET. */
606 insert_into_set (value_set_t set
, tree expr
)
608 value_set_node_t newnode
= pool_alloc (value_set_node_pool
);
609 tree val
= get_value_handle (expr
);
616 /* For indexed sets, insert the value into the set value bitmap.
617 For all sets, add it to the linked list and increment the list
620 value_insert_into_set_bitmap (set
, val
);
622 newnode
->next
= NULL
;
623 newnode
->expr
= expr
;
625 if (set
->head
== NULL
)
627 set
->head
= set
->tail
= newnode
;
631 set
->tail
->next
= newnode
;
636 /* Copy the set ORIG to the set DEST. */
639 set_copy (value_set_t dest
, value_set_t orig
)
641 value_set_node_t node
;
643 if (!orig
|| !orig
->head
)
646 for (node
= orig
->head
;
650 insert_into_set (dest
, node
->expr
);
654 /* Remove EXPR from SET. */
657 set_remove (value_set_t set
, tree expr
)
659 value_set_node_t node
, prev
;
661 /* Remove the value of EXPR from the bitmap, decrement the set
662 length, and remove it from the actual double linked list. */
663 value_remove_from_set_bitmap (set
, get_value_handle (expr
));
666 for (node
= set
->head
;
668 prev
= node
, node
= node
->next
)
670 if (node
->expr
== expr
)
673 set
->head
= node
->next
;
675 prev
->next
= node
->next
;
677 if (node
== set
->tail
)
679 pool_free (value_set_node_pool
, node
);
685 /* Return true if SET contains the value VAL. */
688 set_contains_value (value_set_t set
, tree val
)
690 /* This is only referring to the flag above that we set on
691 values referring to numerical constants, because we know that we
692 are dealing with one of the value handles we created. */
693 if (TREE_CONSTANT (val
))
696 if (set
->length
== 0)
699 return value_exists_in_set_bitmap (set
, val
);
702 /* Replace the leader for the value LOOKFOR in SET with EXPR. */
705 set_replace_value (value_set_t set
, tree lookfor
, tree expr
)
707 value_set_node_t node
= set
->head
;
709 /* The lookup is probably more expensive than walking the linked
710 list when we have only a small number of nodes. */
711 if (!set_contains_value (set
, lookfor
))
714 for (node
= set
->head
;
718 if (get_value_handle (node
->expr
) == lookfor
)
726 /* Return true if the set contains expression (not value) EXPR. */
729 set_contains (value_set_t set
, tree expr
)
731 value_set_node_t node
;
733 for (node
= set
->head
;
737 if (operand_equal_p (node
->expr
, expr
, 0))
743 /* Subtract set B from set A, and return the new set. */
746 set_subtract (value_set_t a
, value_set_t b
, bool indexed
)
748 value_set_t ret
= set_new (indexed
);
749 value_set_node_t node
;
754 if (!set_contains (b
, node
->expr
))
755 insert_into_set (ret
, node
->expr
);
760 /* Return true if two sets are equal. */
763 set_equal (value_set_t a
, value_set_t b
)
765 value_set_node_t node
;
767 if (a
->length
!= b
->length
)
773 if (!set_contains_value (b
, get_value_handle (node
->expr
)))
779 /* Replace the value for EXPR in SET with EXPR. */
781 value_replace_in_set (value_set_t set
, tree expr
)
783 tree val
= get_value_handle (expr
);
785 if (set
->length
== 0)
788 set_replace_value (set
, val
, expr
);
791 /* Insert the value for EXPR into SET, if it doesn't exist already. */
794 value_insert_into_set (value_set_t set
, tree expr
)
796 tree val
= get_value_handle (expr
);
798 /* Constant values exist everywhere. */
799 if (TREE_CONSTANT (val
))
802 if (!set_contains_value (set
, val
))
803 insert_into_set (set
, expr
);
807 /* Print out the value_set SET to OUTFILE. */
810 print_value_set (FILE *outfile
, value_set_t set
,
811 const char *setname
, int blockindex
)
813 value_set_node_t node
;
814 fprintf (outfile
, "%s[%d] := { ", setname
, blockindex
);
817 for (node
= set
->head
;
821 print_generic_expr (outfile
, node
->expr
, 0);
823 fprintf (outfile
, ", ");
827 fprintf (outfile
, " }\n");
830 /* Print out the expressions that have VAL to OUTFILE. */
832 print_value_expressions (FILE *outfile
, tree val
)
834 var_ann_t va
= var_ann (val
);
835 if (va
&& va
->expr_set
)
836 print_value_set (outfile
, va
->expr_set
,
837 IDENTIFIER_POINTER (DECL_NAME (val
)), 0);
842 debug_value_expressions (tree val
)
844 print_value_expressions (stderr
, val
);
848 void debug_value_set (value_set_t
, const char *, int);
851 debug_value_set (value_set_t set
, const char *setname
, int blockindex
)
853 print_value_set (stderr
, set
, setname
, blockindex
);
856 /* Translate EXPR using phis in PHIBLOCK, so that it has the values of
857 the phis in PRED. Return NULL if we can't find a leader for each
858 part of the translated expression. */
861 phi_translate (tree expr
, value_set_t set
, basic_block pred
,
862 basic_block phiblock
)
864 tree phitrans
= NULL
;
870 /* Phi translations of a given expression don't change, */
871 phitrans
= phi_trans_lookup (expr
, pred
);
876 switch (TREE_CODE_CLASS (TREE_CODE (expr
)))
880 tree oldop1
= TREE_OPERAND (expr
, 0);
881 tree oldop2
= TREE_OPERAND (expr
, 1);
886 newop1
= phi_translate (find_leader (set
, oldop1
),
887 set
, pred
, phiblock
);
890 newop2
= phi_translate (find_leader (set
, oldop2
),
891 set
, pred
, phiblock
);
894 if (newop1
!= oldop1
|| newop2
!= oldop2
)
896 newexpr
= pool_alloc (binary_node_pool
);
897 memcpy (newexpr
, expr
, tree_size (expr
));
898 create_expr_ann (newexpr
);
899 TREE_OPERAND (newexpr
, 0) = newop1
== oldop1
? oldop1
: get_value_handle (newop1
);
900 TREE_OPERAND (newexpr
, 1) = newop2
== oldop2
? oldop2
: get_value_handle (newop2
);
901 lookup_or_add (value_table
, newexpr
);
903 phi_trans_add (oldexpr
, newexpr
, pred
);
909 tree oldop1
= TREE_OPERAND (expr
, 0);
913 newop1
= phi_translate (find_leader (set
, oldop1
),
914 set
, pred
, phiblock
);
917 if (newop1
!= oldop1
)
919 newexpr
= pool_alloc (unary_node_pool
);
920 memcpy (newexpr
, expr
, tree_size (expr
));
921 create_expr_ann (newexpr
);
922 TREE_OPERAND (newexpr
, 0) = get_value_handle (newop1
);
923 lookup_or_add (value_table
, newexpr
);
925 phi_trans_add (oldexpr
, newexpr
, pred
);
935 if (TREE_CODE (expr
) != SSA_NAME
)
937 if (TREE_CODE (SSA_NAME_DEF_STMT (expr
)) == PHI_NODE
)
938 phi
= SSA_NAME_DEF_STMT (expr
);
942 for (i
= 0; i
< PHI_NUM_ARGS (phi
); i
++)
943 if (PHI_ARG_EDGE (phi
, i
)->src
== pred
)
946 if (is_undefined_value (PHI_ARG_DEF (phi
, i
)))
948 val
= lookup_or_add (value_table
, PHI_ARG_DEF (phi
, i
));
949 return PHI_ARG_DEF (phi
, i
);
958 phi_translate_set (value_set_t dest
, value_set_t set
, basic_block pred
,
959 basic_block phiblock
)
961 value_set_node_t node
;
962 for (node
= set
->head
;
967 translated
= phi_translate (node
->expr
, set
, pred
, phiblock
);
968 phi_trans_add (node
->expr
, translated
, pred
);
970 if (translated
!= NULL
)
971 value_insert_into_set (dest
, translated
);
975 /* Find the leader for a value (IE the name representing that
976 value) in a given set, and return it. Return NULL if no leader is
980 find_leader (value_set_t set
, tree val
)
982 value_set_node_t node
;
987 if (TREE_CONSTANT (val
))
988 return TREE_CHAIN (val
);
990 if (set
->length
== 0)
993 if (value_exists_in_set_bitmap (set
, val
))
995 for (node
= set
->head
;
999 if (get_value_handle (node
->expr
) == val
)
1006 /* Determine if the expression EXPR is valid in SET. This means that
1007 we have a leader for each part of the expression (if it consists of
1008 values), or the expression is an SSA_NAME.
1010 NB: We never should run into a case where we have SSA_NAME +
1011 SSA_NAME or SSA_NAME + value. The sets valid_in_set is called on,
1012 the ANTIC sets, will only ever have SSA_NAME's or binary value
1013 expression (IE VALUE1 + VALUE2) */
1016 valid_in_set (value_set_t set
, tree expr
)
1018 switch (TREE_CODE_CLASS (TREE_CODE (expr
)))
1022 tree op1
= TREE_OPERAND (expr
, 0);
1023 tree op2
= TREE_OPERAND (expr
, 1);
1024 return set_contains_value (set
, op1
) && set_contains_value (set
, op2
);
1029 tree op1
= TREE_OPERAND (expr
, 0);
1030 return set_contains_value (set
, op1
);
1035 if (TREE_CODE (expr
) == SSA_NAME
)
1045 /* Clean the set of expressions that are no longer valid in the
1046 specified set. This means expressions that are made up of values
1047 we have no leaders for in the current set, etc. */
1050 clean (value_set_t set
)
1052 value_set_node_t node
;
1053 value_set_node_t next
;
1058 if (!valid_in_set (set
, node
->expr
))
1059 set_remove (set
, node
->expr
);
1064 /* Compute the ANTIC set for BLOCK.
1066 ANTIC_OUT[BLOCK] = intersection of ANTIC_IN[b] for all succ(BLOCK), if
1068 ANTIC_OUT[BLOCK] = phi_translate (ANTIC_IN[succ(BLOCK)]) if
1071 ANTIC_IN[BLOCK] = clean(ANTIC_OUT[BLOCK] U EXP_GEN[BLOCK] -
1074 Iterate until fixpointed.
1076 XXX: It would be nice to either write a set_clear, and use it for
1077 antic_out, or to mark the antic_out set as deleted at the end
1078 of this routine, so that the pool can hand the same memory back out
1079 again for the next antic_out. */
1083 compute_antic_aux (basic_block block
)
1087 bool changed
= false;
1088 value_set_t S
, old
, ANTIC_OUT
;
1089 value_set_node_t node
;
1091 ANTIC_OUT
= S
= NULL
;
1092 /* If any edges from predecessors are abnormal, antic_in is empty, so
1093 punt. Remember that the block has an incoming abnormal edge by
1094 setting the BB_VISITED flag. */
1095 if (! (block
->flags
& BB_VISITED
))
1097 for (e
= block
->pred
; e
; e
= e
->pred_next
)
1098 if (e
->flags
& EDGE_ABNORMAL
)
1100 block
->flags
|= BB_VISITED
;
1104 if (block
->flags
& BB_VISITED
)
1111 old
= set_new (false);
1112 set_copy (old
, ANTIC_IN (block
));
1113 ANTIC_OUT
= set_new (true);
1115 /* If the block has no successors, ANTIC_OUT is empty, because it is
1117 if (block
->succ
== NULL
);
1119 /* If we have one successor, we could have some phi nodes to
1120 translate through. */
1121 else if (block
->succ
->succ_next
== NULL
)
1123 phi_translate_set (ANTIC_OUT
, ANTIC_IN(block
->succ
->dest
),
1124 block
, block
->succ
->dest
);
1126 /* If we have multiple successors, we take the intersection of all of
1130 varray_type worklist
;
1133 basic_block bprime
, first
;
1135 VARRAY_BB_INIT (worklist
, 1, "succ");
1139 VARRAY_PUSH_BB (worklist
, e
->dest
);
1142 first
= VARRAY_BB (worklist
, 0);
1143 set_copy (ANTIC_OUT
, ANTIC_IN (first
));
1145 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (worklist
); i
++)
1147 bprime
= VARRAY_BB (worklist
, i
);
1148 node
= ANTIC_OUT
->head
;
1152 value_set_node_t next
= node
->next
;
1153 val
= get_value_handle (node
->expr
);
1154 if (!set_contains_value (ANTIC_IN (bprime
), val
))
1155 set_remove (ANTIC_OUT
, node
->expr
);
1159 VARRAY_CLEAR (worklist
);
1162 /* Generate ANTIC_OUT - TMP_GEN */
1163 S
= set_subtract (ANTIC_OUT
, TMP_GEN (block
), false);
1165 /* Start ANTIC_IN with EXP_GEN - TMP_GEN */
1166 ANTIC_IN (block
) = set_subtract (EXP_GEN (block
),TMP_GEN (block
), true);
1168 /* Then union in the ANTIC_OUT - TMP_GEN values, to get ANTIC_OUT U
1169 EXP_GEN - TMP_GEN */
1170 for (node
= S
->head
;
1174 value_insert_into_set (ANTIC_IN (block
), node
->expr
);
1176 clean (ANTIC_IN (block
));
1178 if (!set_equal (old
, ANTIC_IN (block
)))
1182 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1185 print_value_set (dump_file
, ANTIC_OUT
, "ANTIC_OUT", block
->index
);
1186 print_value_set (dump_file
, ANTIC_IN (block
), "ANTIC_IN", block
->index
);
1188 print_value_set (dump_file
, S
, "S", block
->index
);
1192 for (son
= first_dom_son (CDI_POST_DOMINATORS
, block
);
1194 son
= next_dom_son (CDI_POST_DOMINATORS
, son
))
1196 changed
|= compute_antic_aux (son
);
1201 /* Compute ANTIC sets. */
1204 compute_antic (void)
1206 bool changed
= true;
1208 int num_iterations
= 0;
1211 ANTIC_IN (bb
) = set_new (true);
1212 bb
->flags
&= ~BB_VISITED
;
1219 changed
= compute_antic_aux (EXIT_BLOCK_PTR
);
1221 if (num_iterations
> 2 && dump_file
&& (dump_flags
& TDF_STATS
))
1222 fprintf (dump_file
, "compute_antic required %d iterations\n", num_iterations
);
1225 /* Perform insertion of partially redundant values.
1226 For BLOCK, do the following:
1227 1. Propagate the NEW_SETS of the dominator into the current block.
1228 If the block has multiple predecessors,
1229 2a. Iterate over the ANTIC expressions for the block to see if
1230 any of them are partially redundant.
1231 2b. If so, insert them into the necessary predecessors to make
1232 the expression fully redundant.
1233 2c. Insert a new PHI merging the values of the predecessors.
1234 2d. Insert the new PHI, and the new expressions, into the
1236 3. Recursively call ourselves on the dominator children of BLOCK.
1240 insert_aux (basic_block block
)
1243 bool new_stuff
= false;
1249 dom
= get_immediate_dominator (CDI_DOMINATORS
, block
);
1252 e
= NEW_SETS (dom
)->head
;
1255 insert_into_set (NEW_SETS (block
), e
->expr
);
1256 value_replace_in_set (AVAIL_OUT (block
), e
->expr
);
1259 if (block
->pred
->pred_next
)
1261 value_set_node_t node
;
1262 for (node
= ANTIC_IN (block
)->head
;
1266 if (TREE_CODE_CLASS (TREE_CODE (node
->expr
)) == '2'
1267 || TREE_CODE_CLASS (TREE_CODE (node
->expr
)) == '1')
1271 bool by_some
= false;
1272 bool all_same
= true;
1273 tree first_s
= NULL
;
1277 val
= get_value_handle (node
->expr
);
1278 if (set_contains_value (PHI_GEN (block
), val
))
1280 if (set_contains_value (AVAIL_OUT (dom
), val
))
1282 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1283 fprintf (dump_file
, "Found fully redundant value\n");
1288 avail
= xcalloc (last_basic_block
, sizeof (tree
));
1289 for (pred
= block
->pred
;
1291 pred
= pred
->pred_next
)
1296 eprime
= phi_translate (node
->expr
,
1302 vprime
= get_value_handle (eprime
);
1305 edoubleprime
= find_leader (AVAIL_OUT (bprime
),
1307 if (edoubleprime
== NULL
)
1309 avail
[bprime
->index
] = eprime
;
1314 avail
[bprime
->index
] = edoubleprime
;
1316 if (first_s
== NULL
)
1317 first_s
= edoubleprime
;
1318 else if (first_s
!= edoubleprime
)
1320 if (first_s
!= edoubleprime
1321 && operand_equal_p (first_s
, edoubleprime
, 0))
1326 if (!all_same
&& by_some
)
1329 tree type
= TREE_TYPE (avail
[block
->pred
->src
->index
]);
1332 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1334 fprintf (dump_file
, "Found partial redundancy for expression ");
1335 print_generic_expr (dump_file
, node
->expr
, 0);
1336 fprintf (dump_file
, "\n");
1339 /* Make the necessary insertions. */
1340 for (pred
= block
->pred
;
1342 pred
= pred
->pred_next
)
1345 eprime
= avail
[bprime
->index
];
1346 if (TREE_CODE_CLASS (TREE_CODE (eprime
)) == '2')
1350 s1
= find_leader (AVAIL_OUT (bprime
),
1351 TREE_OPERAND (eprime
, 0));
1352 /* Depending on the order we process
1353 DOM branches in, the value may
1354 not have propagated to all the
1355 dom children yet during this
1356 iteration. In this case, the
1357 value will always be in the
1358 NEW_SETS for *our* dominator */
1360 s1
= find_leader (NEW_SETS (dom
),
1361 TREE_OPERAND (eprime
, 0));
1365 s2
= find_leader (AVAIL_OUT (bprime
),
1366 TREE_OPERAND (eprime
, 1));
1368 s2
= find_leader (NEW_SETS (dom
),
1369 TREE_OPERAND (eprime
, 1));
1373 temp
= create_tmp_var (TREE_TYPE (eprime
),
1375 add_referenced_tmp_var (temp
);
1376 newexpr
= build (TREE_CODE (eprime
),
1379 newexpr
= build (MODIFY_EXPR
,
1382 temp
= make_ssa_name (temp
, newexpr
);
1383 TREE_OPERAND (newexpr
, 0) = temp
;
1384 bsi_insert_on_edge (pred
, newexpr
);
1385 bsi_commit_edge_inserts (NULL
);
1387 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1389 fprintf (dump_file
, "Inserted ");
1390 print_generic_expr (dump_file
, newexpr
, 0);
1391 fprintf (dump_file
, " in predecessor %d\n", pred
->src
->index
);
1393 pre_stats
.insertions
++;
1394 v
= lookup_or_add (value_table
, eprime
);
1395 add (value_table
, temp
, v
);
1396 insert_into_set (NEW_SETS (bprime
), temp
);
1397 value_insert_into_set (AVAIL_OUT (bprime
),
1399 avail
[bprime
->index
] = temp
;
1401 else if (TREE_CODE_CLASS (TREE_CODE (eprime
)) == '1')
1405 s1
= find_leader (AVAIL_OUT (bprime
),
1406 TREE_OPERAND (eprime
, 0));
1407 /* Depending on the order we process
1408 DOM branches in, the value may not have
1409 propagated to all the dom
1410 children yet in the current
1411 iteration, but it will be in
1412 NEW_SETS if it is not yet
1416 s1
= find_leader (NEW_SETS (dom
),
1417 TREE_OPERAND (eprime
, 0));
1421 temp
= create_tmp_var (TREE_TYPE (eprime
),
1423 add_referenced_tmp_var (temp
);
1424 newexpr
= build (TREE_CODE (eprime
),
1427 newexpr
= build (MODIFY_EXPR
,
1430 temp
= make_ssa_name (temp
, newexpr
);
1431 TREE_OPERAND (newexpr
, 0) = temp
;
1432 bsi_insert_on_edge (pred
, newexpr
);
1433 bsi_commit_edge_inserts (NULL
);
1435 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1437 fprintf (dump_file
, "Inserted ");
1438 print_generic_expr (dump_file
, newexpr
, 0);
1439 fprintf (dump_file
, " in predecessor %d\n", pred
->src
->index
);
1441 pre_stats
.insertions
++;
1442 v
= lookup_or_add (value_table
, eprime
);
1443 add (value_table
, temp
, v
);
1444 insert_into_set (NEW_SETS (bprime
), temp
);
1445 value_insert_into_set (AVAIL_OUT (bprime
),
1447 avail
[bprime
->index
] = temp
;
1450 /* Now build a phi for the new variable. */
1451 temp
= create_tmp_var (type
, "prephitmp");
1452 add_referenced_tmp_var (temp
);
1453 temp
= create_phi_node (temp
, block
);
1454 add (value_table
, PHI_RESULT (temp
), val
);
1457 if (!set_contains_value (AVAIL_OUT (block
), val
))
1458 insert_into_set (AVAIL_OUT (block
),
1462 value_replace_in_set (AVAIL_OUT (block
),
1464 for (pred
= block
->pred
;
1466 pred
= pred
->pred_next
)
1468 add_phi_arg (&temp
, avail
[pred
->src
->index
],
1471 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1473 fprintf (dump_file
, "Created phi ");
1474 print_generic_expr (dump_file
, temp
, 0);
1475 fprintf (dump_file
, " in block %d\n", block
->index
);
1479 insert_into_set (NEW_SETS (block
),
1481 insert_into_set (PHI_GEN (block
),
1491 for (son
= first_dom_son (CDI_DOMINATORS
, block
);
1493 son
= next_dom_son (CDI_DOMINATORS
, son
))
1495 new_stuff
|= insert_aux (son
);
1501 /* Perform insertion of partially redundant values. */
1506 bool new_stuff
= true;
1508 int num_iterations
= 0;
1511 NEW_SETS (bb
) = set_new (true);
1517 new_stuff
= insert_aux (ENTRY_BLOCK_PTR
);
1519 if (num_iterations
> 2 && dump_file
&& (dump_flags
& TDF_STATS
))
1520 fprintf (dump_file
, "insert required %d iterations\n", num_iterations
);
1523 /* Return true if EXPR has no defining statement in this procedure,
1524 *AND* isn't a live-on-entry parameter. */
1526 is_undefined_value (tree expr
)
1529 #ifdef ENABLE_CHECKING
1530 /* We should never be handed DECL's */
1534 if (TREE_CODE (expr
) == SSA_NAME
)
1536 /* XXX: Is this the correct test? */
1537 if (TREE_CODE (SSA_NAME_VAR (expr
)) == PARM_DECL
)
1539 if (IS_EMPTY_STMT (SSA_NAME_DEF_STMT (expr
)))
1545 /* Compute the AVAIL set for BLOCK.
1546 This function performs value numbering of the statements in BLOCK.
1547 The AVAIL sets are built from information we glean while doing this
1548 value numbering, since the AVAIL sets contain only entry per
1552 AVAIL_IN[BLOCK] = AVAIL_OUT[dom(BLOCK)].
1553 AVAIL_OUT[BLOCK] = AVAIL_IN[BLOCK] U PHI_GEN[BLOCK] U
1558 compute_avail (basic_block block
)
1562 /* For arguments with default definitions, we pretend they are
1563 defined in the entry block. */
1564 if (block
== ENTRY_BLOCK_PTR
)
1567 for (param
= DECL_ARGUMENTS (current_function_decl
);
1569 param
= TREE_CHAIN (param
))
1571 if (default_def (param
) != NULL
)
1574 tree def
= default_def (param
);
1575 val
= lookup_or_add (value_table
, def
);
1576 insert_into_set (TMP_GEN (block
), def
);
1577 value_insert_into_set (AVAIL_OUT (block
), def
);
1583 block_stmt_iterator bsi
;
1587 dom
= get_immediate_dominator (CDI_DOMINATORS
, block
);
1589 set_copy (AVAIL_OUT (block
), AVAIL_OUT (dom
));
1590 for (phi
= phi_nodes (block
); phi
; phi
= TREE_CHAIN (phi
))
1592 /* Ignore virtual PHIs until we can do PRE on expressions
1593 with virtual operands. */
1594 if (!is_gimple_reg (SSA_NAME_VAR (PHI_RESULT (phi
))))
1597 lookup_or_add (value_table
, PHI_RESULT (phi
));
1598 value_insert_into_set (AVAIL_OUT (block
), PHI_RESULT (phi
));
1599 insert_into_set (PHI_GEN (block
), PHI_RESULT (phi
));
1602 for (bsi
= bsi_start (block
); !bsi_end_p (bsi
); bsi_next (&bsi
))
1605 stmt
= bsi_stmt (bsi
);
1606 get_stmt_operands (stmt
);
1608 if (NUM_VUSES (STMT_VUSE_OPS (stmt
))
1609 || NUM_V_MUST_DEFS (STMT_V_MUST_DEF_OPS (stmt
))
1610 || NUM_V_MAY_DEFS (STMT_V_MAY_DEF_OPS (stmt
))
1611 || stmt_ann (stmt
)->has_volatile_ops
)
1614 for (j
= 0; j
< NUM_DEFS (STMT_DEF_OPS (stmt
)); j
++)
1616 tree def
= DEF_OP (STMT_DEF_OPS (stmt
), j
);
1617 lookup_or_add (value_table
, def
);
1618 insert_into_set (TMP_GEN (block
), def
);
1619 value_insert_into_set (AVAIL_OUT (block
), def
);
1623 else if (TREE_CODE (stmt
) == RETURN_EXPR
1624 && TREE_OPERAND (stmt
, 0)
1625 && TREE_CODE (TREE_OPERAND (stmt
, 0)) == MODIFY_EXPR
)
1626 stmt
= TREE_OPERAND (stmt
, 0);
1628 if (TREE_CODE (stmt
) == MODIFY_EXPR
)
1630 op0
= TREE_OPERAND (stmt
, 0);
1631 if (TREE_CODE (op0
) != SSA_NAME
)
1633 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (op0
))
1635 op1
= TREE_OPERAND (stmt
, 1);
1636 if (TREE_CODE_CLASS (TREE_CODE (op1
)) == 'c')
1638 add (value_table
, op0
, lookup_or_add (value_table
, op1
));
1639 insert_into_set (TMP_GEN (block
), op0
);
1640 value_insert_into_set (AVAIL_OUT (block
), op0
);
1642 else if (TREE_CODE_CLASS (TREE_CODE (op1
)) == '2')
1645 tree val
, val1
, val2
;
1647 bop1
= TREE_OPERAND (op1
, 0);
1648 bop2
= TREE_OPERAND (op1
, 1);
1649 val1
= lookup_or_add (value_table
, bop1
);
1650 val2
= lookup_or_add (value_table
, bop2
);
1652 newt
= pool_alloc (binary_node_pool
);
1653 memcpy (newt
, op1
, tree_size (op1
));
1654 TREE_OPERAND (newt
, 0) = val1
;
1655 TREE_OPERAND (newt
, 1) = val2
;
1656 val
= lookup_or_add (value_table
, newt
);
1657 add (value_table
, op0
, val
);
1658 if (!is_undefined_value (bop1
))
1659 value_insert_into_set (EXP_GEN (block
), bop1
);
1660 if (!is_undefined_value (bop2
))
1661 value_insert_into_set (EXP_GEN (block
), bop2
);
1662 value_insert_into_set (EXP_GEN (block
), newt
);
1663 insert_into_set (TMP_GEN (block
), op0
);
1664 value_insert_into_set (AVAIL_OUT (block
), op0
);
1666 else if (TREE_CODE_CLASS (TREE_CODE (op1
)) == '1')
1671 uop
= TREE_OPERAND (op1
, 0);
1672 val1
= lookup_or_add (value_table
, uop
);
1673 newt
= pool_alloc (unary_node_pool
);
1674 memcpy (newt
, op1
, tree_size (op1
));
1675 TREE_OPERAND (newt
, 0) = val1
;
1676 val
= lookup_or_add (value_table
, newt
);
1677 add (value_table
, op0
, val
);
1678 if (!is_undefined_value (uop
))
1679 value_insert_into_set (EXP_GEN (block
), uop
);
1680 value_insert_into_set (EXP_GEN (block
), newt
);
1681 insert_into_set (TMP_GEN (block
), op0
);
1682 value_insert_into_set (AVAIL_OUT (block
), op0
);
1684 else if (TREE_CODE (op1
) == SSA_NAME
)
1686 tree val
= lookup_or_add (value_table
, op1
);
1687 add (value_table
, op0
, val
);
1688 if (!is_undefined_value (op1
))
1689 value_insert_into_set (EXP_GEN (block
), op1
);
1690 insert_into_set (TMP_GEN (block
), op0
);
1691 value_insert_into_set (AVAIL_OUT (block
), op0
);
1696 for (j
= 0; j
< NUM_DEFS (STMT_DEF_OPS (stmt
)); j
++)
1698 tree def
= DEF_OP (STMT_DEF_OPS (stmt
), j
);
1699 lookup_or_add (value_table
, def
);
1700 insert_into_set (TMP_GEN (block
), def
);
1701 value_insert_into_set (AVAIL_OUT (block
), def
);
1702 value_insert_into_set (AVAIL_OUT (block
), op0
);
1709 for (j
= 0; j
< NUM_DEFS (STMT_DEF_OPS (stmt
)); j
++)
1711 tree def
= DEF_OP (STMT_DEF_OPS (stmt
), j
);
1712 lookup_or_add (value_table
, def
);
1713 insert_into_set (TMP_GEN (block
), def
);
1714 value_insert_into_set (AVAIL_OUT (block
), def
);
1719 for (son
= first_dom_son (CDI_DOMINATORS
, block
);
1721 son
= next_dom_son (CDI_DOMINATORS
, son
))
1722 compute_avail (son
);
1726 /* Eliminate fully redundant computations. */
1735 block_stmt_iterator i
;
1737 for (i
= bsi_start (b
); !bsi_end_p (i
); bsi_next (&i
))
1739 tree stmt
= bsi_stmt (i
);
1741 if (NUM_VUSES (STMT_VUSE_OPS (stmt
))
1742 || NUM_V_MUST_DEFS (STMT_V_MUST_DEF_OPS (stmt
))
1743 || NUM_V_MAY_DEFS (STMT_V_MAY_DEF_OPS (stmt
))
1744 || stmt_ann (stmt
)->has_volatile_ops
)
1746 /* Lookup the RHS of the expression, see if we have an
1747 available computation for it. If so, replace the RHS with
1748 the available computation. */
1749 if (TREE_CODE (stmt
) == MODIFY_EXPR
)
1751 tree t
= TREE_OPERAND (stmt
, 0);
1752 tree expr
= TREE_OPERAND (stmt
, 1);
1754 /* There is no point in eliminating NOP_EXPR, it isn't
1755 supposed to generate any code. */
1756 if (TREE_CODE (expr
) == NOP_EXPR
1757 || (TREE_CODE_CLASS (TREE_CODE (expr
)) != '2'
1758 && TREE_CODE_CLASS (TREE_CODE (expr
)) != '1'))
1760 sprime
= find_leader (AVAIL_OUT (b
),
1761 lookup (value_table
, t
));
1764 && may_propagate_copy (sprime
, TREE_OPERAND (stmt
, 1)))
1766 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1768 fprintf (dump_file
, "Replaced ");
1769 print_generic_expr (dump_file
, expr
, 0);
1770 fprintf (dump_file
, " with ");
1771 print_generic_expr (dump_file
, sprime
, 0);
1772 fprintf (dump_file
, " in ");
1773 print_generic_stmt (dump_file
, stmt
, 0);
1775 pre_stats
.eliminations
++;
1776 propagate_value (&TREE_OPERAND (stmt
, 1), sprime
);
1785 /* Main entry point to the SSA-PRE pass.
1787 PHASE indicates which dump file from the DUMP_FILES array to use when
1788 dumping debugging information. */
1795 pre_uid
= num_referenced_vars
;
1796 memset (&pre_stats
, 0, sizeof (pre_stats
));
1799 bb
->aux
= xcalloc (1, sizeof (struct bb_value_sets
));
1801 phi_translate_table
= htab_create (511, expr_pred_trans_hash
,
1804 value_table
= htab_create (511, val_expr_pair_hash
,
1805 val_expr_pair_expr_eq
, free
);
1806 value_set_pool
= create_alloc_pool ("Value sets",
1807 sizeof (struct value_set
), 30);
1808 value_set_node_pool
= create_alloc_pool ("Value set nodes",
1809 sizeof (struct value_set_node
), 30);
1810 calculate_dominance_info (CDI_POST_DOMINATORS
);
1811 calculate_dominance_info (CDI_DOMINATORS
);
1812 tsize
= tree_size (build (PLUS_EXPR
, void_type_node
, NULL_TREE
,
1814 binary_node_pool
= create_alloc_pool ("Binary tree nodes", tsize
, 30);
1815 tsize
= tree_size (build1 (NEGATE_EXPR
, void_type_node
, NULL_TREE
));
1816 unary_node_pool
= create_alloc_pool ("Unary tree nodes", tsize
, 30);
1820 EXP_GEN (bb
) = set_new (true);
1821 PHI_GEN (bb
) = set_new (true);
1822 TMP_GEN (bb
) = set_new (false);
1823 AVAIL_OUT (bb
) = set_new (true);
1826 compute_avail (ENTRY_BLOCK_PTR
);
1828 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1832 print_value_set (dump_file
, EXP_GEN (bb
), "exp_gen", bb
->index
);
1833 print_value_set (dump_file
, TMP_GEN (bb
), "tmp_gen", bb
->index
);
1834 print_value_set (dump_file
, AVAIL_OUT (bb
), "avail_out", bb
->index
);
1838 /* Insert can get quite slow on an incredibly large number of basic
1839 blocks due to some quadratic behavior. Until this behavior is
1840 fixed, don't run it when he have an incredibly large number of
1841 bb's. If we aren't going to run insert, there is no point in
1842 computing ANTIC, either, even though it's plenty fast. */
1844 if (n_basic_blocks
< 4000)
1852 if (dump_file
&& (dump_flags
& TDF_STATS
))
1854 fprintf (dump_file
, "Insertions:%d\n", pre_stats
.insertions
);
1855 fprintf (dump_file
, "New PHIs:%d\n", pre_stats
.phis
);
1856 fprintf (dump_file
, "Eliminated:%d\n", pre_stats
.eliminations
);
1859 free_alloc_pool (value_set_pool
);
1860 free_alloc_pool (value_set_node_pool
);
1861 free_alloc_pool (binary_node_pool
);
1862 free_alloc_pool (unary_node_pool
);
1863 htab_delete (value_table
);
1864 htab_delete (phi_translate_table
);
1871 free_dominance_info (CDI_POST_DOMINATORS
);
1877 return flag_tree_pre
!= 0;
1880 struct tree_opt_pass pass_pre
=
1883 gate_pre
, /* gate */
1884 execute_pre
, /* execute */
1887 0, /* static_pass_number */
1888 TV_TREE_PRE
, /* tv_id */
1889 PROP_no_crit_edges
| PROP_cfg
| PROP_ssa
,/* properties_required */
1890 0, /* properties_provided */
1891 0, /* properties_destroyed */
1892 0, /* todo_flags_start */
1893 TODO_dump_func
| TODO_ggc_collect
| TODO_verify_ssa
/* todo_flags_finish */