aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.c
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2021-07-15 15:06:36 +0200
committerAldy Hernandez <aldyh@redhat.com>2021-07-27 17:58:14 +0200
commit573e20aaca836029b309a053c8ef19367f27bdc1 (patch)
tree03319e23c9e231bbe65ed6e6eaa43af98c8c2970 /gcc/tree-vrp.c
parentbee2f80b901d73f50275f2b44932067ffcf616ca (diff)
downloadgcc-573e20aaca836029b309a053c8ef19367f27bdc1.zip
gcc-573e20aaca836029b309a053c8ef19367f27bdc1.tar.gz
gcc-573e20aaca836029b309a053c8ef19367f27bdc1.tar.bz2
Abstract out (forward) jump threader state handling.
The *forward* jump threader has multiple places where it pushes and pops state, and where it sets context up for the jump threading simplifier callback. Not only are the idioms repetitive, but the only reason for passing const_and_copies, avail_exprs_stack, and the evrp engine around are so we can set up context. As part of my jump threading work, I will divorce the evrp engine from the DOM jump threader, replacing it with a subset of the path solver I have just contributed. Since this will entail passing even more context around, I've abstracted out the state handling so it can be passed around in one object. This cleans up the code, and also makes it trivial to set up context with another engine in the future. FWIW, I've used these cleanups and the path solver in a POC to improve DOM's threaded edges by an additional 5%, and the overall threading opportunities in the compiler by 1%. This is in addition to the gains I have documented in the backwards threader rewrite. There are no functional changes with this patch. Tested on x86-64 Linux. gcc/ChangeLog: * tree-ssa-dom.c (dom_jump_threader_simplifier): Put avail_exprs_stack in the class, instead of passing it to jump_threader_simplifier. (dom_jump_threader_simplifier::simplify): Add state argument. (dom_opt_dom_walker): Add state. (pass_dominator::execute): Pass state to threader. (dom_opt_dom_walker::before_dom_children): Use state. * tree-ssa-threadedge.c (jump_threader::jump_threader): Replace arguments by state. (jump_threader::record_temporary_equivalences_from_phis): Register equivalences through the state variable. (jump_threader::record_temporary_equivalences_from_stmts_at_dest): Record ranges in a statement through the state variable. (jump_threader::simplify_control_stmt_condition): Pass state to simplify. (jump_threader::simplify_control_stmt_condition_1): Same. (jump_threader::thread_around_empty_blocks): Remove obsolete comment. (jump_threader::thread_through_normal_block): Record equivalences on edge through the state variable. (jump_threader::thread_across_edge): Abstract state pushing. (jt_state::jt_state): New. (jt_state::push): New. (jt_state::pop): New. (jt_state::register_equiv): New. (jt_state::record_ranges_from_stmt): New. (jt_state::register_equivs_on_edge): New. (jump_threader_simplifier::jump_threader_simplifier): Move from header. (jump_threader_simplifier::simplify): Add state argument. * tree-ssa-threadedge.h (class jt_state): New. (class jump_threader): Add state to constructor. (class jump_threader_simplifier): Add state to simplify. Remove avail_exprs_stack from class. * tree-vrp.c (vrp_jump_threader_simplifier::simplify): Add state argument. (vrp_jump_threader::vrp_jump_threader): Add state. (vrp_jump_threader::~vrp_jump_threader): Cleanup state.
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r--gcc/tree-vrp.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 58111f8..d1b6910 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4165,16 +4165,18 @@ class vrp_jump_threader_simplifier : public jump_threader_simplifier
{
public:
vrp_jump_threader_simplifier (vr_values *v, avail_exprs_stack *avails)
- : jump_threader_simplifier (v, avails) {}
+ : jump_threader_simplifier (v), m_avail_exprs_stack (avails) { }
private:
- tree simplify (gimple *, gimple *, basic_block) OVERRIDE;
+ tree simplify (gimple *, gimple *, basic_block, jt_state *) OVERRIDE;
+ avail_exprs_stack *m_avail_exprs_stack;
};
tree
vrp_jump_threader_simplifier::simplify (gimple *stmt,
gimple *within_stmt,
- basic_block bb)
+ basic_block bb,
+ jt_state *state)
{
/* First see if the conditional is in the hash table. */
tree cached_lhs = m_avail_exprs_stack->lookup_avail_expr (stmt, false, true);
@@ -4206,7 +4208,7 @@ vrp_jump_threader_simplifier::simplify (gimple *stmt,
return find_case_label_range (switch_stmt, vr);
}
- return jump_threader_simplifier::simplify (stmt, within_stmt, bb);
+ return jump_threader_simplifier::simplify (stmt, within_stmt, bb, state);
}
/* Blocks which have more than one predecessor and more than
@@ -4257,6 +4259,7 @@ private:
hash_table<expr_elt_hasher> *m_avail_exprs;
vrp_jump_threader_simplifier *m_simplifier;
jump_threader *m_threader;
+ jt_state *m_state;
};
vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
@@ -4282,11 +4285,11 @@ vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
m_vr_values = v;
m_avail_exprs = new hash_table<expr_elt_hasher> (1024);
m_avail_exprs_stack = new avail_exprs_stack (m_avail_exprs);
+ m_state = new jt_state (m_const_and_copies, m_avail_exprs_stack, NULL);
m_simplifier = new vrp_jump_threader_simplifier (m_vr_values,
m_avail_exprs_stack);
- m_threader = new jump_threader (m_const_and_copies, m_avail_exprs_stack,
- m_simplifier);
+ m_threader = new jump_threader (m_simplifier, m_state);
}
vrp_jump_threader::~vrp_jump_threader ()
@@ -4299,6 +4302,7 @@ vrp_jump_threader::~vrp_jump_threader ()
delete m_avail_exprs_stack;
delete m_simplifier;
delete m_threader;
+ delete m_state;
}
/* Called before processing dominator children of BB. We want to look