/* Conditional constant propagation pass for the GNU compiler.
- Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
Adapted from original RTL SSA-CCP by Daniel Berlin <dberlin@dberlin.org>
Adapted to GIMPLE trees by Diego Novillo <dnovillo@redhat.com>
static bool replace_uses_in (tree, bool *);
static latticevalue likely_value (tree);
static tree get_rhs (tree);
-static void set_rhs (tree *, tree);
+static bool set_rhs (tree *, tree);
static value *get_value (tree);
static value get_default_value (tree);
static tree ccp_fold_builtin (tree, tree);
0, /* properties_destroyed */
0, /* todo_flags_start */
TODO_dump_func | TODO_rename_vars
- | TODO_ggc_collect | TODO_verify_ssa /* todo_flags_finish */
+ | TODO_ggc_collect | TODO_verify_ssa
+ | TODO_verify_stmts /* todo_flags_finish */
};
/* If we folded a builtin function, we'll likely
need to rename VDEFs. */
if (replaced_address || changed)
- mark_new_vars_to_rename (stmt, vars_to_rename);
+ {
+ mark_new_vars_to_rename (stmt, vars_to_rename);
+ if (maybe_clean_eh_stmt (stmt))
+ tree_purge_dead_eh_edges (bb);
+ }
}
if (dump_file && (dump_flags & TDF_DETAILS))
/* Strip away useless type conversions. Both the NON_LVALUE_EXPR that
may have been added by fold, and "useless" type conversions that might
now be apparent due to propagation. */
- STRIP_MAIN_TYPE_NOPS (result);
STRIP_USELESS_TYPE_CONVERSION (result);
if (result != rhs)
- {
- changed = true;
- set_rhs (stmt_p, result);
- }
+ changed |= set_rhs (stmt_p, result);
return changed;
}
/* Set the main expression of *STMT_P to EXPR. */
-static void
+static bool
set_rhs (tree *stmt_p, tree expr)
{
tree stmt = *stmt_p;
- enum tree_code code = TREE_CODE (stmt);
+ enum tree_code code = TREE_CODE (expr);
+ /* Verify the constant folded result is valid gimple. */
+ if (TREE_CODE_CLASS (code) == '2')
+ {
+ if (!is_gimple_val (TREE_OPERAND (expr, 0))
+ || !is_gimple_val (TREE_OPERAND (expr, 1)))
+ return false;
+ }
+ else if (TREE_CODE_CLASS (code) == '1')
+ {
+ if (!is_gimple_val (TREE_OPERAND (expr, 0)))
+ return false;
+ }
+
+ code = TREE_CODE (stmt);
if (code == MODIFY_EXPR)
TREE_OPERAND (stmt, 1) = expr;
else if (code == COND_EXPR)
}
}
}
+
+ return true;
}
print_generic_stmt (dump_file, *stmtp, dump_flags);
}
- set_rhs (stmtp, result);
- modify_stmt (*stmtp);
+ if (set_rhs (stmtp, result))
+ modify_stmt (*stmtp);
if (dump_file && (dump_flags & TDF_DETAILS))
{