#include "bitmap.h"
#include "langhooks.h"
#include "cfgloop.h"
+#include "params.h"
#include "tree-ssa-propagate.h"
#include "tree-ssa-sccvn.h"
typedef struct vn_tables_s
{
- htab_t unary;
- htab_t binary;
+ htab_t nary;
htab_t phis;
htab_t references;
- alloc_pool unary_op_pool;
- alloc_pool binary_op_pool;
+ struct obstack nary_obstack;
alloc_pool phis_pool;
alloc_pool references_pool;
} *vn_tables_t;
-/* Binary operations in the hashtable consist of two operands, an
+/* Nary operations in the hashtable consist of length operands, an
opcode, and a type. Result is the value number of the operation,
and hashcode is stored to avoid having to calculate it
repeatedly. */
-typedef struct vn_binary_op_s
+typedef struct vn_nary_op_s
{
- enum tree_code opcode;
- tree type;
- tree op0;
- tree op1;
+ ENUM_BITFIELD(tree_code) opcode : 16;
+ unsigned length : 16;
hashval_t hashcode;
tree result;
-} *vn_binary_op_t;
-typedef const struct vn_binary_op_s *const_vn_binary_op_t;
-
-/* Unary operations in the hashtable consist of a single operand, an
- opcode, and a type. Result is the value number of the operation,
- and hashcode is stored to avoid having to calculate it repeatedly. */
-
-typedef struct vn_unary_op_s
-{
- enum tree_code opcode;
tree type;
- tree op0;
- hashval_t hashcode;
- tree result;
-} *vn_unary_op_t;
-typedef const struct vn_unary_op_s *const_vn_unary_op_t;
+ tree op[4];
+} *vn_nary_op_t;
+typedef const struct vn_nary_op_s *const_vn_nary_op_t;
/* Phi nodes in the hashtable consist of their non-VN_TOP phi
arguments, and the basic block the phi is in. Result is the value
tree type;
tree op0;
tree op1;
- tree op2;
} vn_reference_op_s;
typedef vn_reference_op_s *vn_reference_op_t;
typedef const vn_reference_op_s *const_vn_reference_op_t;
DEF_VEC_P(vn_ssa_aux_t);
DEF_VEC_ALLOC_P(vn_ssa_aux_t, heap);
-/* Table of vn_ssa_aux_t's, one per ssa_name. */
+/* Table of vn_ssa_aux_t's, one per ssa_name. The vn_ssa_aux_t objects
+ are allocated on an obstack for locality reasons, and to free them
+ without looping over the VEC. */
static VEC (vn_ssa_aux_t, heap) *vn_ssa_aux_table;
+static struct obstack vn_ssa_aux_obstack;
/* Return the value numbering information for a given SSA name. */
SSA_NAME_VERSION (name), value);
}
-/* Get the value numbering info for a given SSA name, creating it if
- it does not exist. */
+/* Initialize the value numbering info for a given SSA name.
+ This should be called just once for every SSA name. */
vn_ssa_aux_t
VN_INFO_GET (tree name)
{
- vn_ssa_aux_t newinfo = XCNEW (struct vn_ssa_aux);
+ vn_ssa_aux_t newinfo;
+
+ newinfo = obstack_alloc (&vn_ssa_aux_obstack, sizeof (struct vn_ssa_aux));
+ memset (newinfo, 0, sizeof (struct vn_ssa_aux));
if (SSA_NAME_VERSION (name) >= VEC_length (vn_ssa_aux_t, vn_ssa_aux_table))
VEC_safe_grow (vn_ssa_aux_t, heap, vn_ssa_aux_table,
SSA_NAME_VERSION (name) + 1);
}
+/* Free a phi operation structure VP. */
+
+static void
+free_phi (void *vp)
+{
+ vn_phi_t phi = vp;
+ VEC_free (tree, heap, phi->phiargs);
+}
+
+/* Free a reference operation structure VP. */
+
+static void
+free_reference (void *vp)
+{
+ vn_reference_t vr = vp;
+ VEC_free (vn_reference_op_s, heap, vr->operands);
+}
+
/* Compare two reference operands P1 and P2 for equality. return true if
they are equal, and false otherwise. */
return vro1->opcode == vro2->opcode
&& vro1->type == vro2->type
&& expressions_equal_p (vro1->op0, vro2->op0)
- && expressions_equal_p (vro1->op1, vro2->op1)
- && expressions_equal_p (vro1->op2, vro2->op2);
+ && expressions_equal_p (vro1->op1, vro2->op1);
}
/* Compute the hash for a reference operand VRO1 */
vn_reference_op_compute_hash (const vn_reference_op_t vro1)
{
return iterative_hash_expr (vro1->op0, vro1->opcode)
- + iterative_hash_expr (vro1->op1, vro1->opcode)
- + iterative_hash_expr (vro1->op2, vro1->opcode);
+ + iterative_hash_expr (vro1->op1, vro1->opcode);
}
/* Return the hashcode for a given reference operation P1. */
if (!stmt)
return;
- FOR_EACH_SSA_TREE_OPERAND (vuse, stmt, iter, SSA_OP_VIRTUAL_USES)
- VEC_safe_push (tree, gc, *result, vuse);
+ VEC_reserve_exact (tree, gc, *result,
+ num_ssa_operands (stmt, SSA_OP_VIRTUAL_USES));
- if (VEC_length (tree, *result) > 1)
- sort_vuses (*result);
+ FOR_EACH_SSA_TREE_OPERAND (vuse, stmt, iter, SSA_OP_VIRTUAL_USES)
+ VEC_quick_push (tree, *result, vuse);
}
if (!stmt)
return;
- FOR_EACH_SSA_TREE_OPERAND (vdef, stmt, iter, SSA_OP_VIRTUAL_DEFS)
- VEC_safe_push (tree, gc, *result, vdef);
+ *result = VEC_alloc (tree, gc, num_ssa_operands (stmt, SSA_OP_VIRTUAL_DEFS));
- if (VEC_length (tree, *result) > 1)
- sort_vuses (*result);
+ FOR_EACH_SSA_TREE_OPERAND (vdef, stmt, iter, SSA_OP_VIRTUAL_DEFS)
+ VEC_quick_push (tree, *result, vdef);
}
/* Copy the names of vdef results in STMT into a vector, and return
case COMPLEX_CST:
case VECTOR_CST:
case REAL_CST:
+ case CONSTRUCTOR:
case VALUE_HANDLE:
case VAR_DECL:
case PARM_DECL:
vr1.hashcode = vn_reference_compute_hash (&vr1);
slot = htab_find_slot_with_hash (current_info->references, &vr1, vr1.hashcode,
NO_INSERT);
+ if (!slot && current_info == optimistic_info)
+ slot = htab_find_slot_with_hash (valid_info->references, &vr1, vr1.hashcode,
+ NO_INSERT);
if (!slot)
return NULL_TREE;
the other lookup functions, you cannot gcc_assert (!*slot)
here. */
+ /* But free the old slot in case of a collision. */
+ if (*slot)
+ free_reference (*slot);
*slot = vr1;
}
-
-/* Return the stored hashcode for a unary operation. */
-
-static hashval_t
-vn_unary_op_hash (const void *p1)
-{
- const_vn_unary_op_t const vuo1 = (const_vn_unary_op_t) p1;
- return vuo1->hashcode;
-}
-
-/* Hash a unary operation P1 and return the result. */
+/* Compute and return the hash value for nary operation VBO1. */
static inline hashval_t
-vn_unary_op_compute_hash (const vn_unary_op_t vuo1)
+vn_nary_op_compute_hash (const vn_nary_op_t vno1)
{
- return iterative_hash_expr (vuo1->op0, vuo1->opcode);
-}
-
-/* Return true if P1 and P2, two unary operations, are equivalent. */
-
-static int
-vn_unary_op_eq (const void *p1, const void *p2)
-{
- const_vn_unary_op_t const vuo1 = (const_vn_unary_op_t) p1;
- const_vn_unary_op_t const vuo2 = (const_vn_unary_op_t) p2;
- return vuo1->opcode == vuo2->opcode
- && vuo1->type == vuo2->type
- && expressions_equal_p (vuo1->op0, vuo2->op0);
-}
-
-/* Lookup OP in the current hash table, and return the resulting
- value number if it exists in the hash table. Return NULL_TREE if
- it does not exist in the hash table. */
-
-tree
-vn_unary_op_lookup (tree op)
-{
- void **slot;
- struct vn_unary_op_s vuo1;
-
- vuo1.opcode = TREE_CODE (op);
- vuo1.type = TREE_TYPE (op);
- vuo1.op0 = TREE_OPERAND (op, 0);
-
- if (TREE_CODE (vuo1.op0) == SSA_NAME)
- vuo1.op0 = SSA_VAL (vuo1.op0);
-
- vuo1.hashcode = vn_unary_op_compute_hash (&vuo1);
- slot = htab_find_slot_with_hash (current_info->unary, &vuo1, vuo1.hashcode,
- NO_INSERT);
- if (!slot)
- return NULL_TREE;
- return ((vn_unary_op_t)*slot)->result;
-}
-
-/* Insert OP into the current hash table with a value number of
- RESULT. */
-
-void
-vn_unary_op_insert (tree op, tree result)
-{
- void **slot;
- vn_unary_op_t vuo1 = (vn_unary_op_t) pool_alloc (current_info->unary_op_pool);
+ hashval_t hash = 0;
+ unsigned i;
- vuo1->opcode = TREE_CODE (op);
- vuo1->type = TREE_TYPE (op);
- vuo1->op0 = TREE_OPERAND (op, 0);
- vuo1->result = result;
+ for (i = 0; i < vno1->length; ++i)
+ if (TREE_CODE (vno1->op[i]) == SSA_NAME)
+ vno1->op[i] = SSA_VAL (vno1->op[i]);
- if (TREE_CODE (vuo1->op0) == SSA_NAME)
- vuo1->op0 = SSA_VAL (vuo1->op0);
-
- vuo1->hashcode = vn_unary_op_compute_hash (vuo1);
- slot = htab_find_slot_with_hash (current_info->unary, vuo1, vuo1->hashcode,
- INSERT);
- gcc_assert (!*slot);
- *slot = vuo1;
-}
+ if (vno1->length == 2
+ && commutative_tree_code (vno1->opcode)
+ && tree_swap_operands_p (vno1->op[0], vno1->op[1], false))
+ {
+ tree temp = vno1->op[0];
+ vno1->op[0] = vno1->op[1];
+ vno1->op[1] = temp;
+ }
-/* Compute and return the hash value for binary operation VBO1. */
+ for (i = 0; i < vno1->length; ++i)
+ hash += iterative_hash_expr (vno1->op[i], vno1->opcode);
-static inline hashval_t
-vn_binary_op_compute_hash (const vn_binary_op_t vbo1)
-{
- return iterative_hash_expr (vbo1->op0, vbo1->opcode)
- + iterative_hash_expr (vbo1->op1, vbo1->opcode);
+ return hash;
}
-/* Return the computed hashcode for binary operation P1. */
+/* Return the computed hashcode for nary operation P1. */
static hashval_t
-vn_binary_op_hash (const void *p1)
+vn_nary_op_hash (const void *p1)
{
- const_vn_binary_op_t const vbo1 = (const_vn_binary_op_t) p1;
- return vbo1->hashcode;
+ const_vn_nary_op_t const vno1 = (const_vn_nary_op_t) p1;
+ return vno1->hashcode;
}
-/* Compare binary operations P1 and P2 and return true if they are
+/* Compare nary operations P1 and P2 and return true if they are
equivalent. */
static int
-vn_binary_op_eq (const void *p1, const void *p2)
+vn_nary_op_eq (const void *p1, const void *p2)
{
- const_vn_binary_op_t const vbo1 = (const_vn_binary_op_t) p1;
- const_vn_binary_op_t const vbo2 = (const_vn_binary_op_t) p2;
- return vbo1->opcode == vbo2->opcode
- && vbo1->type == vbo2->type
- && expressions_equal_p (vbo1->op0, vbo2->op0)
- && expressions_equal_p (vbo1->op1, vbo2->op1);
+ const_vn_nary_op_t const vno1 = (const_vn_nary_op_t) p1;
+ const_vn_nary_op_t const vno2 = (const_vn_nary_op_t) p2;
+ unsigned i;
+
+ if (vno1->opcode != vno2->opcode
+ || vno1->type != vno2->type)
+ return false;
+
+ for (i = 0; i < vno1->length; ++i)
+ if (!expressions_equal_p (vno1->op[i], vno2->op[i]))
+ return false;
+
+ return true;
}
/* Lookup OP in the current hash table, and return the resulting
it does not exist in the hash table. */
tree
-vn_binary_op_lookup (tree op)
+vn_nary_op_lookup (tree op)
{
void **slot;
- struct vn_binary_op_s vbo1;
-
- vbo1.opcode = TREE_CODE (op);
- vbo1.type = TREE_TYPE (op);
- vbo1.op0 = TREE_OPERAND (op, 0);
- vbo1.op1 = TREE_OPERAND (op, 1);
-
- if (TREE_CODE (vbo1.op0) == SSA_NAME)
- vbo1.op0 = SSA_VAL (vbo1.op0);
- if (TREE_CODE (vbo1.op1) == SSA_NAME)
- vbo1.op1 = SSA_VAL (vbo1.op1);
-
- if (tree_swap_operands_p (vbo1.op0, vbo1.op1, false)
- && commutative_tree_code (vbo1.opcode))
- {
- tree temp = vbo1.op0;
- vbo1.op0 = vbo1.op1;
- vbo1.op1 = temp;
- }
-
- vbo1.hashcode = vn_binary_op_compute_hash (&vbo1);
- slot = htab_find_slot_with_hash (current_info->binary, &vbo1, vbo1.hashcode,
+ struct vn_nary_op_s vno1;
+ unsigned i;
+
+ vno1.opcode = TREE_CODE (op);
+ vno1.length = TREE_CODE_LENGTH (TREE_CODE (op));
+ vno1.type = TREE_TYPE (op);
+ for (i = 0; i < vno1.length; ++i)
+ vno1.op[i] = TREE_OPERAND (op, i);
+ vno1.hashcode = vn_nary_op_compute_hash (&vno1);
+ slot = htab_find_slot_with_hash (current_info->nary, &vno1, vno1.hashcode,
NO_INSERT);
+ if (!slot && current_info == optimistic_info)
+ slot = htab_find_slot_with_hash (valid_info->nary, &vno1, vno1.hashcode,
+ NO_INSERT);
if (!slot)
return NULL_TREE;
- return ((vn_binary_op_t)*slot)->result;
+ return ((vn_nary_op_t)*slot)->result;
}
/* Insert OP into the current hash table with a value number of
RESULT. */
void
-vn_binary_op_insert (tree op, tree result)
+vn_nary_op_insert (tree op, tree result)
{
+ unsigned length = TREE_CODE_LENGTH (TREE_CODE (op));
void **slot;
- vn_binary_op_t vbo1;
- vbo1 = (vn_binary_op_t) pool_alloc (current_info->binary_op_pool);
-
- vbo1->opcode = TREE_CODE (op);
- vbo1->type = TREE_TYPE (op);
- vbo1->op0 = TREE_OPERAND (op, 0);
- vbo1->op1 = TREE_OPERAND (op, 1);
- vbo1->result = result;
-
- if (TREE_CODE (vbo1->op0) == SSA_NAME)
- vbo1->op0 = SSA_VAL (vbo1->op0);
- if (TREE_CODE (vbo1->op1) == SSA_NAME)
- vbo1->op1 = SSA_VAL (vbo1->op1);
-
- if (tree_swap_operands_p (vbo1->op0, vbo1->op1, false)
- && commutative_tree_code (vbo1->opcode))
- {
- tree temp = vbo1->op0;
- vbo1->op0 = vbo1->op1;
- vbo1->op1 = temp;
- }
- vbo1->hashcode = vn_binary_op_compute_hash (vbo1);
- slot = htab_find_slot_with_hash (current_info->binary, vbo1, vbo1->hashcode,
+ vn_nary_op_t vno1;
+ unsigned i;
+
+ vno1 = obstack_alloc (¤t_info->nary_obstack,
+ (sizeof (struct vn_nary_op_s)
+ - sizeof (tree) * (4 - length)));
+ vno1->opcode = TREE_CODE (op);
+ vno1->length = length;
+ vno1->type = TREE_TYPE (op);
+ for (i = 0; i < vno1->length; ++i)
+ vno1->op[i] = TREE_OPERAND (op, i);
+ vno1->result = result;
+ vno1->hashcode = vn_nary_op_compute_hash (vno1);
+ slot = htab_find_slot_with_hash (current_info->nary, vno1, vno1->hashcode,
INSERT);
gcc_assert (!*slot);
- *slot = vbo1;
+ *slot = vno1;
}
/* Compute a hashcode for PHI operation VP1 and return it. */
vp1.hashcode = vn_phi_compute_hash (&vp1);
slot = htab_find_slot_with_hash (current_info->phis, &vp1, vp1.hashcode,
NO_INSERT);
+ if (!slot && current_info == optimistic_info)
+ slot = htab_find_slot_with_hash (valid_info->phis, &vp1, vp1.hashcode,
+ NO_INSERT);
if (!slot)
return NULL_TREE;
return ((vn_phi_t)*slot)->result;
{
tree currval;
+ if (from != to
+ && TREE_CODE (to) == SSA_NAME
+ && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (to))
+ to = from;
+
/* The only thing we allow as value numbers are VN_TOP, ssa_names
and invariants. So assert that here. */
gcc_assert (to != NULL_TREE
visit_unary_op (tree lhs, tree op)
{
bool changed = false;
- tree result = vn_unary_op_lookup (op);
+ tree result = vn_nary_op_lookup (op);
if (result)
{
else
{
changed = set_ssa_val_to (lhs, lhs);
- vn_unary_op_insert (op, lhs);
+ vn_nary_op_insert (op, lhs);
}
return changed;
visit_binary_op (tree lhs, tree op)
{
bool changed = false;
- tree result = vn_binary_op_lookup (op);
+ tree result = vn_nary_op_lookup (op);
if (result)
{
else
{
changed = set_ssa_val_to (lhs, lhs);
- vn_binary_op_insert (op, lhs);
+ vn_nary_op_insert (op, lhs);
}
return changed;
{
if (TREE_CODE (result) == SSA_NAME)
result = SSA_VAL (result);
+ if (TREE_CODE (op) == SSA_NAME)
+ op = SSA_VAL (op);
resultsame = expressions_equal_p (result, op);
}
changed |= set_ssa_val_to (vdef, vdef);
}
- vn_reference_insert (lhs, op, vdefs);
+ /* Do not insert structure copies into the tables. */
+ if (is_gimple_min_invariant (op)
+ || is_gimple_reg (op))
+ vn_reference_insert (lhs, op, vdefs);
}
else
{
simplified. */
static tree
-simplify_binary_expression (tree rhs)
+simplify_binary_expression (tree stmt, tree rhs)
{
tree result = NULL_TREE;
tree op0 = TREE_OPERAND (rhs, 0);
op1 = SSA_VAL (op1);
}
+ /* Avoid folding if nothing changed. */
+ if (op0 == TREE_OPERAND (rhs, 0)
+ && op1 == TREE_OPERAND (rhs, 1))
+ return NULL_TREE;
+
+ fold_defer_overflow_warnings ();
+
result = fold_binary (TREE_CODE (rhs), TREE_TYPE (rhs), op0, op1);
+ fold_undefer_overflow_warnings (result && valid_gimple_expression_p (result),
+ stmt, 0);
+
/* Make sure result is not a complex expression consisting
of operators of operators (IE (a + b) + (a + c))
Otherwise, we will end up with unbounded expressions if
return NULL_TREE;
}
+/* Simplify the unary expression RHS, and return the result if
+ simplified. */
+
+static tree
+simplify_unary_expression (tree rhs)
+{
+ tree result = NULL_TREE;
+ tree op0 = TREE_OPERAND (rhs, 0);
+
+ if (TREE_CODE (op0) != SSA_NAME)
+ return NULL_TREE;
+
+ if (VN_INFO (op0)->has_constants)
+ op0 = valueize_expr (VN_INFO (op0)->expr);
+ else if (TREE_CODE (rhs) == NOP_EXPR
+ || TREE_CODE (rhs) == CONVERT_EXPR
+ || TREE_CODE (rhs) == REALPART_EXPR
+ || TREE_CODE (rhs) == IMAGPART_EXPR
+ || TREE_CODE (rhs) == VIEW_CONVERT_EXPR)
+ {
+ /* We want to do tree-combining on conversion-like expressions.
+ Make sure we feed only SSA_NAMEs or constants to fold though. */
+ tree tem = valueize_expr (VN_INFO (op0)->expr);
+ if (UNARY_CLASS_P (tem)
+ || BINARY_CLASS_P (tem)
+ || TREE_CODE (tem) == VIEW_CONVERT_EXPR
+ || TREE_CODE (tem) == SSA_NAME
+ || is_gimple_min_invariant (tem))
+ op0 = tem;
+ }
+
+ /* Avoid folding if nothing changed, but remember the expression. */
+ if (op0 == TREE_OPERAND (rhs, 0))
+ return rhs;
+
+ result = fold_unary (TREE_CODE (rhs), TREE_TYPE (rhs), op0);
+ if (result)
+ {
+ STRIP_USELESS_TYPE_CONVERSION (result);
+ if (valid_gimple_expression_p (result))
+ return result;
+ }
+
+ return rhs;
+}
+
/* Try to simplify RHS using equivalences and constant folding. */
static tree
try_to_simplify (tree stmt, tree rhs)
{
+ /* For stores we can end up simplifying a SSA_NAME rhs. Just return
+ in this case, there is no point in doing extra work. */
if (TREE_CODE (rhs) == SSA_NAME)
- {
- if (is_gimple_min_invariant (SSA_VAL (rhs)))
- return SSA_VAL (rhs);
- else if (VN_INFO (rhs)->has_constants)
- return VN_INFO (rhs)->expr;
- }
+ return rhs;
else
{
switch (TREE_CODE_CLASS (TREE_CODE (rhs)))
/* Fallthrough. */
case tcc_reference:
- {
- tree result = vn_reference_lookup (rhs,
- shared_vuses_from_stmt (stmt));
- if (result)
- return result;
- }
- break;
+ /* Do not do full-blown reference lookup here.
+ ??? But like for tcc_declaration, we should simplify
+ from constant initializers. */
+
+ /* Fallthrough for some codes that can operate on registers. */
+ if (!(TREE_CODE (rhs) == REALPART_EXPR
+ || TREE_CODE (rhs) == IMAGPART_EXPR
+ || TREE_CODE (rhs) == VIEW_CONVERT_EXPR))
+ break;
/* We could do a little more with unary ops, if they expand
into binary ops, but it's debatable whether it is worth it. */
case tcc_unary:
- {
- tree result = NULL_TREE;
- tree op0 = TREE_OPERAND (rhs, 0);
- if (TREE_CODE (op0) == SSA_NAME && VN_INFO (op0)->has_constants)
- op0 = VN_INFO (op0)->expr;
- else if (TREE_CODE (op0) == SSA_NAME && SSA_VAL (op0) != op0)
- op0 = SSA_VAL (op0);
- result = fold_unary (TREE_CODE (rhs), TREE_TYPE (rhs), op0);
- if (result)
- return result;
- }
+ return simplify_unary_expression (rhs);
break;
case tcc_comparison:
case tcc_binary:
- return simplify_binary_expression (rhs);
+ return simplify_binary_expression (stmt, rhs);
break;
default:
break;
changed = visit_phi (stmt);
}
else if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT
- || (ann && ann->has_volatile_ops))
+ || (ann && ann->has_volatile_ops)
+ || tree_could_throw_p (stmt))
{
changed = defs_to_varying (stmt);
}
{
changed = false;
iterations++;
+ htab_empty (optimistic_info->nary);
+ htab_empty (optimistic_info->phis);
+ htab_empty (optimistic_info->references);
+ obstack_free (&optimistic_info->nary_obstack, NULL);
+ gcc_obstack_init (&optimistic_info->nary_obstack);
+ empty_alloc_pool (optimistic_info->phis_pool);
+ empty_alloc_pool (optimistic_info->references_pool);
for (i = 0; VEC_iterate (tree, scc, i, var); i++)
changed |= visit_use (var);
}
/* Depth first search on NAME to discover and process SCC's in the SSA
graph.
Execution of this algorithm relies on the fact that the SCC's are
- popped off the stack in topological order. */
+ popped off the stack in topological order.
+ Returns true if successful, false if we stopped processing SCC's due
+ to ressource constraints. */
-static void
+static bool
DFS (tree name)
{
ssa_op_iter iter;
if (! (VN_INFO (use)->visited))
{
- DFS (use);
+ if (!DFS (use))
+ return false;
VN_INFO (name)->low = MIN (VN_INFO (name)->low,
VN_INFO (use)->low);
}
VEC_safe_push (tree, heap, scc, x);
} while (x != name);
+ /* Bail out of SCCVN in case a SCC turns out to be incredibly large. */
+ if (VEC_length (tree, scc)
+ > (unsigned)PARAM_VALUE (PARAM_SCCVN_MAX_SCC_SIZE))
+ {
+ if (dump_file)
+ fprintf (dump_file, "WARNING: Giving up with SCCVN due to "
+ "SCC size %u exceeding %u\n", VEC_length (tree, scc),
+ (unsigned)PARAM_VALUE (PARAM_SCCVN_MAX_SCC_SIZE));
+ return false;
+ }
+
if (VEC_length (tree, scc) > 1)
sort_scc (scc);
VEC_free (tree, heap, scc);
}
-}
-
-static void
-free_phi (void *vp)
-{
- vn_phi_t phi = vp;
- VEC_free (tree, heap, phi->phiargs);
-}
-
-/* Free a reference operation structure VP. */
-
-static void
-free_reference (void *vp)
-{
- vn_reference_t vr = vp;
- VEC_free (vn_reference_op_s, heap, vr->operands);
+ return true;
}
/* Allocate a value number table. */
allocate_vn_table (vn_tables_t table)
{
table->phis = htab_create (23, vn_phi_hash, vn_phi_eq, free_phi);
- table->unary = htab_create (23, vn_unary_op_hash, vn_unary_op_eq, NULL);
- table->binary = htab_create (23, vn_binary_op_hash, vn_binary_op_eq, NULL);
+ table->nary = htab_create (23, vn_nary_op_hash, vn_nary_op_eq, NULL);
table->references = htab_create (23, vn_reference_hash, vn_reference_eq,
free_reference);
- table->unary_op_pool = create_alloc_pool ("VN unary operations",
- sizeof (struct vn_unary_op_s),
- 30);
- table->binary_op_pool = create_alloc_pool ("VN binary operations",
- sizeof (struct vn_binary_op_s),
- 30);
+ gcc_obstack_init (&table->nary_obstack);
table->phis_pool = create_alloc_pool ("VN phis",
sizeof (struct vn_phi_s),
30);
free_vn_table (vn_tables_t table)
{
htab_delete (table->phis);
- htab_delete (table->unary);
- htab_delete (table->binary);
+ htab_delete (table->nary);
htab_delete (table->references);
- free_alloc_pool (table->unary_op_pool);
- free_alloc_pool (table->binary_op_pool);
+ obstack_free (&table->nary_obstack, NULL);
free_alloc_pool (table->phis_pool);
free_alloc_pool (table->references_pool);
}
/* VEC_alloc doesn't actually grow it to the right size, it just
preallocates the space to do so. */
VEC_safe_grow (vn_ssa_aux_t, heap, vn_ssa_aux_table, num_ssa_names + 1);
+ gcc_obstack_init (&vn_ssa_aux_obstack);
+
shared_lookup_phiargs = NULL;
shared_lookup_vops = NULL;
shared_lookup_references = NULL;
for (j = 0; j < n_basic_blocks - NUM_FIXED_BLOCKS; j++)
rpo_numbers[rpo_numbers_temp[j]] = j;
- free (rpo_numbers_temp);
+ XDELETE (rpo_numbers_temp);
VN_TOP = create_tmp_var_raw (void_type_node, "vn_top");
VEC_free (tree, gc, shared_lookup_vops);
VEC_free (vn_reference_op_s, heap, shared_lookup_references);
XDELETEVEC (rpo_numbers);
+
for (i = 0; i < num_ssa_names; i++)
{
tree name = ssa_name (i);
- if (name)
- {
- XDELETE (VN_INFO (name));
- if (SSA_NAME_VALUE (name) &&
- TREE_CODE (SSA_NAME_VALUE (name)) == VALUE_HANDLE)
- SSA_NAME_VALUE (name) = NULL;
- }
+ if (name
+ && SSA_NAME_VALUE (name)
+ && TREE_CODE (SSA_NAME_VALUE (name)) == VALUE_HANDLE)
+ SSA_NAME_VALUE (name) = NULL;
}
-
+ obstack_free (&vn_ssa_aux_obstack, NULL);
VEC_free (vn_ssa_aux_t, heap, vn_ssa_aux_table);
+
VEC_free (tree, heap, sccstack);
free_vn_table (valid_info);
XDELETE (valid_info);
}
}
-void
+/* Do SCCVN. Returns true if it finished, false if we bailed out
+ due to ressource constraints. */
+
+bool
run_scc_vn (void)
{
size_t i;
if (name
&& VN_INFO (name)->visited == false
&& !has_zero_uses (name))
- DFS (name);
+ if (!DFS (name))
+ {
+ free_scc_vn ();
+ return false;
+ }
}
if (dump_file && (dump_flags & TDF_DETAILS))
}
}
}
+
+ return true;
}