-/* Return true if VAR is an SSA variable with no defining statement in
- this procedure, *AND* isn't a live-on-entry parameter. */
-
-static bool
-is_undefined_value (tree expr)
-{
- return (TREE_CODE (expr) == SSA_NAME
- && IS_EMPTY_STMT (SSA_NAME_DEF_STMT (expr))
- /* PARM_DECLs and hard registers are always defined. */
- && TREE_CODE (SSA_NAME_VAR (expr)) != PARM_DECL);
-}
-
-
-/* Given an SSA variable VAR and an expression EXPR, compute the value
- number for EXPR and create a value handle (VAL) for it. If VAR and
- EXPR are not the same, associate VAL with VAR. Finally, add VAR to
- S1 and its value handle to S2, and to the maximal set if
- ADD_TO_MAXIMAL is true.
-
- VUSES represent the virtual use operands associated with EXPR (if
- any). */
-
-static inline void
-add_to_sets (tree var, tree expr, tree stmt, bitmap_set_t s1,
- bitmap_set_t s2)
-{
- tree val = vn_lookup_or_add (expr, stmt);
-
- /* VAR and EXPR may be the same when processing statements for which
- we are not computing value numbers (e.g., non-assignments, or
- statements that make aliased stores). In those cases, we are
- only interested in making VAR available as its own value. */
- if (var != expr)
- vn_add (var, val);
-
- if (s1)
- bitmap_insert_into_set (s1, var);
-
- /* PHI nodes can't go in the maximal sets because they are not in
- TMP_GEN, so it is possible to get into non-monotonic situations
- during ANTIC calculation, because it will *add* bits. */
- if (!in_fre && TREE_CODE (SSA_NAME_DEF_STMT (var)) != PHI_NODE)
- bitmap_value_insert_into_set (maximal_set, var);
- bitmap_value_insert_into_set (s2, var);
-}
-
-/* Find existing value expression that is the same as T,
- and return it if it exists. */
-
-static inline tree
-find_existing_value_expr (tree t, tree stmt)
-{
- bitmap_iterator bi;
- unsigned int bii;
- tree vh;
- bitmap_set_t exprset;
-
- if (REFERENCE_CLASS_P (t))
- vh = vn_lookup (t, stmt);
- else
- vh = vn_lookup (t, NULL);
-
- if (!vh)
- return NULL;
- exprset = VALUE_HANDLE_EXPR_SET (vh);
- FOR_EACH_EXPR_ID_IN_SET (exprset, bii, bi)
- {
- tree efi = expression_for_id (bii);
- if (expressions_equal_p (t, efi))
- return efi;
- }
- return NULL;
-}
-
-/* Given a unary or binary expression EXPR, create and return a new
- expression with the same structure as EXPR but with its operands
- replaced with the value handles of each of the operands of EXPR.
-
- VUSES represent the virtual use operands associated with EXPR (if
- any). Insert EXPR's operands into the EXP_GEN set for BLOCK. */
-
-static inline tree
-create_value_expr_from (tree expr, basic_block block, tree stmt)
-{
- int i;
- enum tree_code code = TREE_CODE (expr);
- tree vexpr;
- alloc_pool pool = NULL;
- tree efi;
-
- gcc_assert (TREE_CODE_CLASS (code) == tcc_unary
- || TREE_CODE_CLASS (code) == tcc_binary
- || TREE_CODE_CLASS (code) == tcc_comparison
- || TREE_CODE_CLASS (code) == tcc_reference
- || TREE_CODE_CLASS (code) == tcc_expression
- || TREE_CODE_CLASS (code) == tcc_vl_exp
- || TREE_CODE_CLASS (code) == tcc_exceptional
- || TREE_CODE_CLASS (code) == tcc_declaration);
-
- if (TREE_CODE_CLASS (code) == tcc_unary)
- pool = unary_node_pool;
- else if (TREE_CODE_CLASS (code) == tcc_reference)
- pool = reference_node_pool;
- else if (TREE_CODE_CLASS (code) == tcc_binary)
- pool = binary_node_pool;
- else if (TREE_CODE_CLASS (code) == tcc_comparison)
- pool = comparison_node_pool;
- else
- gcc_assert (code == CALL_EXPR);
-
- if (code == CALL_EXPR)
- vexpr = temp_copy_call_expr (expr);
- else
- {
- vexpr = (tree) pool_alloc (pool);
- memcpy (vexpr, expr, tree_size (expr));
- }
-
- for (i = 0; i < TREE_OPERAND_LENGTH (expr); i++)
- {
- tree val, op;
-
- op = TREE_OPERAND (expr, i);
- if (op == NULL_TREE)
- continue;
-
- /* Recursively value-numberize reference ops and tree lists. */
- if (REFERENCE_CLASS_P (op))
- {
- tree tempop = create_value_expr_from (op, block, stmt);
- op = tempop ? tempop : op;
- val = vn_lookup_or_add (op, stmt);
- }
- else
- /* Create a value handle for OP and add it to VEXPR. */
- val = vn_lookup_or_add (op, NULL);
-
- if (!is_undefined_value (op) && TREE_CODE (op) != TREE_LIST)
- bitmap_value_insert_into_set (EXP_GEN (block), op);
-
- if (TREE_CODE (val) == VALUE_HANDLE)
- TREE_TYPE (val) = TREE_TYPE (TREE_OPERAND (vexpr, i));
-
- TREE_OPERAND (vexpr, i) = val;
- }
- efi = find_existing_value_expr (vexpr, stmt);
- if (efi)
- return efi;
- get_or_alloc_expression_id (vexpr);
- return vexpr;
-}
-
-/* Given a statement STMT and its right hand side which is a load, try
- to look for the expression stored in the location for the load, and
- return true if a useful equivalence was recorded for LHS. */
-
-static bool
-try_look_through_load (tree lhs, tree mem_ref, tree stmt, basic_block block)
-{
- tree store_stmt = NULL;
- tree rhs;
- ssa_op_iter i;
- tree vuse;
-
- FOR_EACH_SSA_TREE_OPERAND (vuse, stmt, i, SSA_OP_VIRTUAL_USES)
- {
- tree def_stmt;
-
- gcc_assert (TREE_CODE (vuse) == SSA_NAME);
- def_stmt = SSA_NAME_DEF_STMT (vuse);
-
- /* If there is no useful statement for this VUSE, we'll not find a
- useful expression to return either. Likewise, if there is a
- statement but it is not a simple assignment or it has virtual
- uses, we can stop right here. Note that this means we do
- not look through PHI nodes, which is intentional. */
- if (!def_stmt
- || TREE_CODE (def_stmt) != GIMPLE_MODIFY_STMT
- || !ZERO_SSA_OPERANDS (def_stmt, SSA_OP_VIRTUAL_USES))
- return false;
-
- /* If this is not the same statement as one we have looked at for
- another VUSE of STMT already, we have two statements producing
- something that reaches our STMT. */
- if (store_stmt && store_stmt != def_stmt)
- return false;
- else
- {
- /* Is this a store to the exact same location as the one we are
- loading from in STMT? */
- if (!operand_equal_p (GIMPLE_STMT_OPERAND (def_stmt, 0), mem_ref, 0))
- return false;
-
- /* Otherwise remember this statement and see if all other VUSEs
- come from the same statement. */
- store_stmt = def_stmt;
- }
- }
-
- /* Alright then, we have visited all VUSEs of STMT and we've determined
- that all of them come from the same statement STORE_STMT. See if there
- is a useful expression we can deduce from STORE_STMT. */
- rhs = GIMPLE_STMT_OPERAND (store_stmt, 1);
- if ((TREE_CODE (rhs) == SSA_NAME
- && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs))
- || is_gimple_min_invariant (rhs)
- || TREE_CODE (rhs) == ADDR_EXPR
- || TREE_INVARIANT (rhs))
- {
-
- /* Yay! Compute a value number for the RHS of the statement and
- add its value to the AVAIL_OUT set for the block. Add the LHS
- to TMP_GEN. */
- add_to_sets (lhs, rhs, store_stmt, TMP_GEN (block), AVAIL_OUT (block));
- if (TREE_CODE (rhs) == SSA_NAME
- && !is_undefined_value (rhs))
- bitmap_value_insert_into_set (EXP_GEN (block), rhs);
- return true;
- }
-
- return false;
-}
-
-/* Return a copy of NODE that is stored in the temporary alloc_pool's.
- This is made recursively true, so that the operands are stored in
- the pool as well. */