aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.c
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2020-06-18 10:37:14 +0200
committerAldy Hernandez <aldyh@redhat.com>2020-06-27 14:11:41 +0200
commitfc36b97af05ef74b0889ba49090c2f52f00e0e77 (patch)
tree56791637843a2bcbb21cd928008a014f163e7a12 /gcc/tree-vrp.c
parentaed3ab253dada2b7d2ed63cc6a8e15e263d5dd35 (diff)
downloadgcc-fc36b97af05ef74b0889ba49090c2f52f00e0e77.zip
gcc-fc36b97af05ef74b0889ba49090c2f52f00e0e77.tar.gz
gcc-fc36b97af05ef74b0889ba49090c2f52f00e0e77.tar.bz2
Move simplification of statements using ranges into its own class.
This moves all the simplification code from vr_values into a separate class (simplify_using_ranges). In doing so, we get rid of a bunch of dependencies on the internals of vr_values. The goal is to (a) remove unnecessary interdependendcies (b) be able to use this engine with any range infrastructure, as all it needs is a method to get the range for an SSA name (get_value_range). I also removed as many dependencies on value_range_equiv as possible, preferring value_range. A few value_range_equiv uses remain, but for cases where equivalences are actually used (folding conditionals, etc). gcc/ChangeLog: * gimple-ssa-evrp-analyze.h (vrp_visit_cond_stmt): Use simplify_using_ranges class. * gimple-ssa-evrp.c (class evrp_folder): New simplify_using_ranges field. Adjust all methods to use new field. * tree-ssa-dom.c (simplify_stmt_for_jump_threading): Use simplify_using_ranges class. * tree-vrp.c (class vrp_folder): New simplify_using_ranges field. Adjust all methods to use new field. (simplify_stmt_for_jump_threading): Use simplify_using_ranges class. (vrp_prop::vrp_finalize): New vrp_folder argument. (execute_vrp): Pass folder to vrp_finalize. Use simplify_using_ranges class. Remove cleanup_edges_and_switches call. * vr-values.c (vr_values::op_with_boolean_value_range_p): Change value_range_equiv uses to value_range. (simplify_using_ranges::op_with_boolean_value_range_p): Use simplify_using_ranges class. (check_for_binary_op_overflow): Make static. (vr_values::extract_range_basic): Pass this to check_for_binary_op_overflow. (compare_range_with_value): Change value_range_equiv uses to value_range. (vr_values::vr_values): Initialize simplifier field. Remove uses of to_remove_edges and to_update_switch_stmts. (vr_values::~vr_values): Remove uses of to_remove_edges and to_update_switch_stmts. (vr_values::get_vr_for_comparison): Move to simplify_using_ranges class. (vr_values::compare_name_with_value): Same. (vr_values::compare_names): Same. (vr_values::vrp_evaluate_conditional_warnv_with_ops): Same. (vr_values::vrp_evaluate_conditional): Same. (vr_values::vrp_visit_cond_stmt): Same. (find_case_label_ranges): Change value_range_equiv uses to value_range. (vr_values::extract_range_from_stmt): Use simplify_using_ranges class. (vr_values::simplify_truth_ops_using_ranges): Move to simplify_using_ranges class. (vr_values::simplify_div_or_mod_using_ranges): Same. (vr_values::simplify_min_or_max_using_ranges): Same. (vr_values::simplify_abs_using_ranges): Same. (vr_values::simplify_bit_ops_using_ranges): Same. (test_for_singularity): Change value_range_equiv uses to value_range. (range_fits_type_p): Same. (vr_values::simplify_cond_using_ranges_1): Same. (vr_values::simplify_cond_using_ranges_2): Make extern. (vr_values::fold_cond): Move to simplify_using_ranges class. (vr_values::simplify_switch_using_ranges): Same. (vr_values::cleanup_edges_and_switches): Same. (vr_values::simplify_float_conversion_using_ranges): Same. (vr_values::simplify_internal_call_using_ranges): Same. (vr_values::two_valued_val_range_p): Same. (vr_values::simplify_stmt_using_ranges): Move to... (simplify_using_ranges::simplify): ...here. * vr-values.h (class vr_values): Move all the simplification of statements using ranges methods and code from here... (class simplify_using_ranges): ...to here. (simplify_cond_using_ranges_2): New extern prototype.
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r--gcc/tree-vrp.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index c39a6f5..7193ca4 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -3373,7 +3373,7 @@ public:
struct function *fun;
void vrp_initialize (struct function *);
- void vrp_finalize (bool);
+ void vrp_finalize (class vrp_folder *, bool);
class vr_values vr_values;
@@ -3938,23 +3938,28 @@ vrp_prop::visit_phi (gphi *phi)
class vrp_folder : public substitute_and_fold_engine
{
-public:
- vrp_folder () : substitute_and_fold_engine (/* Fold all stmts. */ true) { }
+ public:
+ vrp_folder (vr_values *v)
+ : substitute_and_fold_engine (/* Fold all stmts. */ true),
+ m_vr_values (v), simplifier (v)
+ { }
tree get_value (tree, gimple *stmt) FINAL OVERRIDE;
bool fold_stmt (gimple_stmt_iterator *) FINAL OVERRIDE;
- class vr_values *vr_values;
+ class vr_values *m_vr_values;
private:
bool fold_predicate_in (gimple_stmt_iterator *);
/* Delegators. */
tree vrp_evaluate_conditional (tree_code code, tree op0,
tree op1, gimple *stmt)
- { return vr_values->vrp_evaluate_conditional (code, op0, op1, stmt); }
+ { return simplifier.vrp_evaluate_conditional (code, op0, op1, stmt); }
bool simplify_stmt_using_ranges (gimple_stmt_iterator *gsi)
- { return vr_values->simplify_stmt_using_ranges (gsi); }
+ { return simplifier.simplify (gsi); }
tree op_with_constant_singleton_value_range (tree op)
- { return vr_values->op_with_constant_singleton_value_range (op); }
+ { return m_vr_values->op_with_constant_singleton_value_range (op); }
+
+ simplify_using_ranges simplifier;
};
/* If the statement pointed by SI has a predicate whose value can be
@@ -4096,7 +4101,8 @@ simplify_stmt_for_jump_threading (gimple *stmt, gimple *within_stmt,
tree op1 = gimple_cond_rhs (cond_stmt);
op1 = lhs_of_dominating_assert (op1, bb, stmt);
- return vr_values->vrp_evaluate_conditional (gimple_cond_code (cond_stmt),
+ simplify_using_ranges simplifier (vr_values);
+ return simplifier.vrp_evaluate_conditional (gimple_cond_code (cond_stmt),
op0, op1, within_stmt);
}
@@ -4332,7 +4338,7 @@ identify_jump_threads (struct function *fun, class vr_values *vr_values)
/* Traverse all the blocks folding conditionals with known ranges. */
void
-vrp_prop::vrp_finalize (bool warn_array_bounds_p)
+vrp_prop::vrp_finalize (vrp_folder *folder, bool warn_array_bounds_p)
{
size_t i;
@@ -4376,9 +4382,7 @@ vrp_prop::vrp_finalize (bool warn_array_bounds_p)
if (warn_array_bounds && warn_array_bounds_p)
set_all_edges_as_executable (fun);
- class vrp_folder vrp_folder;
- vrp_folder.vr_values = &vr_values;
- vrp_folder.substitute_and_fold ();
+ folder->substitute_and_fold ();
if (warn_array_bounds && warn_array_bounds_p)
{
@@ -4453,7 +4457,10 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
class vrp_prop vrp_prop;
vrp_prop.vrp_initialize (fun);
vrp_prop.ssa_propagate ();
- vrp_prop.vrp_finalize (warn_array_bounds_p);
+ /* Instantiate the folder here, so that edge cleanups happen at the
+ end of this function. */
+ vrp_folder folder (&vrp_prop.vr_values);
+ vrp_prop.vrp_finalize (&folder, warn_array_bounds_p);
/* We must identify jump threading opportunities before we release
the datastructures built by VRP. */
@@ -4471,7 +4478,8 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
{
gimple *last = last_stmt (bb);
if (last && gimple_code (last) == GIMPLE_COND)
- vrp_prop.vr_values.simplify_cond_using_ranges_2 (as_a <gcond *> (last));
+ simplify_cond_using_ranges_2 (&vrp_prop.vr_values,
+ as_a <gcond *> (last));
}
free_numbers_of_iterations_estimates (fun);
@@ -4496,7 +4504,6 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
processing by the pass manager. */
thread_through_all_blocks (false);
- vrp_prop.vr_values.cleanup_edges_and_switches ();
threadedge_finalize_values ();
scev_finalize ();