aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-threadbackward.c
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2021-11-11 11:57:26 +0100
committerAldy Hernandez <aldyh@redhat.com>2021-11-11 15:42:00 +0100
commitbfa04d0ec958ebff38ea9d2340a3f4f8e4c04a2d (patch)
tree39bfee50b549cc94b5df41139295f8ea4a420455 /gcc/tree-ssa-threadbackward.c
parent1ea781a8657cdbecffa14b5bce960738087e58f3 (diff)
downloadgcc-bfa04d0ec958ebff38ea9d2340a3f4f8e4c04a2d.zip
gcc-bfa04d0ec958ebff38ea9d2340a3f4f8e4c04a2d.tar.gz
gcc-bfa04d0ec958ebff38ea9d2340a3f4f8e4c04a2d.tar.bz2
Move import population from threader to path solver.
Imports are our nomenclature for external SSA names to a block that are used to calculate the outgoing edges for said block. For example, in the following snippet: <bb 2> : _1 = b_10 == block_11; _2 = b_10 != -1; _3 = _1 & _2; if (_3 != 0) goto <bb 3>; [INV] else goto <bb 5>; [INV] ...the imports to the block are b_10 and block_11 since they are both needed to calculate _3. The path solver takes a bitmap of imports in addition to the path itself. This sets up the number of SSA names to be on the lookout for, while resolving the final conditional. Calculating these imports was initially done in the threader, since it was the only user of the path solver. With new clients, it has become obvious that populating the imports should be a task for the path solver, so it can be shared among the clients. This patch moves the import code to the solver, making both the solver and the threader simpler in the process. This is because intent is clearer and some duplicate code was removed. This reshuffling had the net effect of giving us a handful of new threads through my suite of .ii files (125). This was unexpected, but welcome nevertheless. There is no performance difference in callgrind over the same suite. Regstrapped on x86-64 Linux. gcc/ChangeLog: * gimple-range-path.cc (path_range_query::add_copies_to_imports): Rename to... (path_range_query::compute_imports): ...this. Adapt it so it can be passed the imports bitmap instead of working on m_imports. (path_range_query::compute_ranges): Call compute_imports in all cases unless an imports bitmap is passed. * gimple-range-path.h (path_range_query::compute_imports): New. (path_range_query::add_copies_to_imports): Remove. * tree-ssa-threadbackward.c (back_threader::resolve_def): Remove. (back_threader::find_paths_to_names): Inline resolve_def. (back_threader::find_paths): Call compute_imports. (back_threader::resolve_phi): Adjust comment.
Diffstat (limited to 'gcc/tree-ssa-threadbackward.c')
-rw-r--r--gcc/tree-ssa-threadbackward.c47
1 files changed, 8 insertions, 39 deletions
diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c
index 0f7b4a7..d067c47 100644
--- a/gcc/tree-ssa-threadbackward.c
+++ b/gcc/tree-ssa-threadbackward.c
@@ -91,7 +91,6 @@ private:
edge maybe_register_path ();
void maybe_register_path_dump (edge taken_edge);
void find_paths_to_names (basic_block bb, bitmap imports);
- bool resolve_def (tree name, bitmap interesting, vec<tree> &worklist);
void resolve_phi (gphi *phi, bitmap imports);
edge find_taken_edge (const vec<basic_block> &path);
edge find_taken_edge_cond (const vec<basic_block> &path, gcond *);
@@ -363,12 +362,8 @@ back_threader::resolve_phi (gphi *phi, bitmap interesting)
edge e = gimple_phi_arg_edge (phi, i);
// This is like path_crosses_loops in profitable_path_p but more
- // restrictive, since profitable_path_p allows threading the
- // first block because it would be redirected anyhow.
- //
- // If we loosened the restriction and used profitable_path_p()
- // here instead, we would peel off the first iterations of loops
- // in places like tree-ssa/pr14341.c.
+ // restrictive to avoid peeling off loop iterations (see
+ // tree-ssa/pr14341.c for an example).
bool profitable_p = m_path[0]->loop_father == e->src->loop_father;
if (!profitable_p)
{
@@ -404,33 +399,6 @@ back_threader::resolve_phi (gphi *phi, bitmap interesting)
}
}
-// If the definition of NAME causes the final conditional of the
-// current path to be constant, register the path, and return TRUE.
-
-bool
-back_threader::resolve_def (tree name, bitmap interesting, vec<tree> &worklist)
-{
- gimple *def_stmt = SSA_NAME_DEF_STMT (name);
-
- // Handle PHIs.
- if (is_a<gphi *> (def_stmt))
- {
- resolve_phi (as_a<gphi *> (def_stmt), interesting);
- return true;
- }
-
- // Defer copies of SSAs by adding the source to the worklist.
- if (gimple_assign_single_p (def_stmt)
- && TREE_CODE (gimple_assign_rhs1 (def_stmt)) == SSA_NAME)
- {
- tree rhs = gimple_assign_rhs1 (def_stmt);
- bitmap_set_bit (m_imports, SSA_NAME_VERSION (rhs));
- bitmap_set_bit (interesting, SSA_NAME_VERSION (rhs));
- worklist.safe_push (rhs);
- }
- return false;
-}
-
// Find jump threading paths to any of the SSA names in the
// INTERESTING bitmap, and register any such paths.
//
@@ -464,13 +432,15 @@ back_threader::find_paths_to_names (basic_block bb, bitmap interesting)
{
tree name = worklist.pop ();
unsigned i = SSA_NAME_VERSION (name);
- basic_block def_bb = gimple_bb (SSA_NAME_DEF_STMT (name));
+ gimple *def_stmt = SSA_NAME_DEF_STMT (name);
+ basic_block def_bb = gimple_bb (def_stmt);
- // Process any names defined in this block.
+ // Process any PHIs defined in this block.
if (def_bb == bb
&& bitmap_set_bit (processed, i)
- && resolve_def (name, interesting, worklist))
+ && gimple_code (def_stmt) == GIMPLE_PHI)
{
+ resolve_phi (as_a<gphi *> (def_stmt), interesting);
done = true;
break;
}
@@ -515,10 +485,9 @@ back_threader::find_paths (basic_block bb, tree name)
m_visited_bbs.empty ();
m_path.truncate (0);
m_name = name;
- bitmap_clear (m_imports);
+ m_solver->compute_imports (m_imports, bb);
auto_bitmap interesting;
- bitmap_copy (m_imports, m_ranger->gori ().imports (bb));
bitmap_copy (interesting, m_imports);
find_paths_to_names (bb, interesting);
}