https://gcc.gnu.org/g:8f1f2f851bdc46bfcfa49877a9ae08d3ca7744ef
commit r17-5248-g8f1f2f851bdc46bfcfa49877a9ae08d3ca7744ef Author: Aldy Hernandez <[email protected]> Date: Fri Oct 16 07:52:19 2026 +0000 backward threader: make the path solver for each search The path solver is created in the threader and lives until the threader is destroyed, even though it is no longer needed after the search is done. Create it at the start of the search and delete it at the end. Make the new method a virtual, so a later patch can subclass back_threader with a path solver of its own. No functional change. Tested on ppc64le Linux. gcc/ChangeLog: * tree-ssa-threadbackward.h (back_threader::make_solver): New. * tree-ssa-threadbackward.cc (back_threader::back_threader): Do not create the solver. (back_threader::~back_threader): Nor delete it. (back_threader::make_solver): New. (back_threader::search): Create the solver for the search. Diff: --- gcc/tree-ssa-threadbackward.cc | 17 +++++++++++++++-- gcc/tree-ssa-threadbackward.h | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gcc/tree-ssa-threadbackward.cc b/gcc/tree-ssa-threadbackward.cc index 8f81446c4e7b..c9902d0dc687 100644 --- a/gcc/tree-ssa-threadbackward.cc +++ b/gcc/tree-ssa-threadbackward.cc @@ -207,12 +207,11 @@ back_threader::back_threader (function *fun, unsigned flags, bool first) mark_dfs_back_edges (); m_ranger = new gimple_ranger; - m_solver = new path_range_query (*m_ranger, flags & BT_RESOLVE); + m_solver = NULL; } back_threader::~back_threader () { - delete m_solver; delete m_ranger; loop_optimizer_finalize (); } @@ -920,15 +919,29 @@ back_threader_registry::register_path (const vec<basic_block> &m_path, return register_jump_thread (jump_thread_path); } +// Return a new path solver for the search. + +path_range_query * +back_threader::make_solver (gimple_ranger &ranger) +{ + return new path_range_query (ranger, m_flags & BT_RESOLVE); +} + // Find the paths to thread in the current function. void back_threader::search () { + m_solver = make_solver (*m_ranger); + basic_block bb; FOR_EACH_BB_FN (bb, m_fun) if (EDGE_COUNT (bb->succs) > 1) maybe_thread_block (bb); + + // The solver lives as long as the search: the IL changes after it. + delete m_solver; + m_solver = NULL; } // Thread the paths found. Return TODO_flags. diff --git a/gcc/tree-ssa-threadbackward.h b/gcc/tree-ssa-threadbackward.h index 12a1f3bb387a..81ff5ed43751 100644 --- a/gcc/tree-ssa-threadbackward.h +++ b/gcc/tree-ssa-threadbackward.h @@ -51,6 +51,9 @@ public: unsigned thread_blocks (); void search (); unsigned apply (); +protected: + // The path solver for the search. + virtual path_range_query *make_solver (gimple_ranger &); private: void maybe_thread_block (basic_block bb); bool debug_counter ();
