https://gcc.gnu.org/g:44662397eb4a7abfd38f4486becaadf1c56e20eb
commit r17-5223-g44662397eb4a7abfd38f4486becaadf1c56e20eb Author: Aldy Hernandez <[email protected]> Date: Tue Oct 13 16:52:30 2026 +0000 backward threader: declare class back_threader in a header The plan is to run the backthreader from within FRE to make use of its value numbers. Since this will happen in a subclass of back_threader, that will be visible from outside of tree-ssa-threadbackward.cc, move it into a header file. Tested on ppc64le Linux. gcc/ChangeLog: * tree-ssa-threadbackward.h: New file. * tree-ssa-threadbackward.cc: Include it. (class back_threader_registry): Move to tree-ssa-threadbackward.h. (BT_NONE, BT_SPEED, BT_RESOLVE): Likewise. (class back_threader): Likewise. Diff: --- gcc/tree-ssa-threadbackward.cc | 69 +----------------------------- gcc/tree-ssa-threadbackward.h | 96 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 68 deletions(-) diff --git a/gcc/tree-ssa-threadbackward.cc b/gcc/tree-ssa-threadbackward.cc index 1a3a4e361957..339b390c43dc 100644 --- a/gcc/tree-ssa-threadbackward.cc +++ b/gcc/tree-ssa-threadbackward.cc @@ -40,22 +40,13 @@ along with GCC; see the file COPYING3. If not see #include "gimple-range.h" #include "tree-ssa-threadedge.h" #include "gimple-range-path.h" +#include "tree-ssa-threadbackward.h" #include "ssa.h" #include "tree-cfgcleanup.h" #include "tree-pretty-print.h" #include "cfghooks.h" #include "dbgcnt.h" -// Path registry for the backwards threader. After all paths have been -// registered with register_path(), thread_through_all_blocks() is called -// to modify the CFG. - -class back_threader_registry : public back_jt_path_registry -{ -public: - bool register_path (const vec<basic_block> &, edge taken); -}; - // Class to abstract the profitability code for the backwards threader. class back_threader_profitability @@ -195,64 +186,6 @@ back_threader_profitability::pop_bb () m_stats = m_unwind.pop ().stats; } -// Back threader flags. -#define BT_NONE 0 -// Generate fast code at the expense of code size. -#define BT_SPEED 1 -// Resolve unknown SSAs on entry to a threading path. If set, use the -// ranger. If not, assume all ranges on entry to a path are VARYING. -#define BT_RESOLVE 2 - -class back_threader -{ -public: - back_threader (function *fun, unsigned flags, bool first); - virtual ~back_threader (); - unsigned thread_blocks (); - void search (); - unsigned apply (); -private: - void maybe_thread_block (basic_block bb); - bool debug_counter (); - edge maybe_register_path (back_threader_profitability &); - void maybe_register_path_dump (edge taken_edge); - void find_paths_to_names (basic_block bb, bitmap imports, unsigned, - back_threader_profitability &); - edge find_taken_edge (const vec<basic_block> &path); - edge find_taken_edge_cond (const vec<basic_block> &path, gcond *); - edge find_taken_edge_switch (const vec<basic_block> &path, gswitch *); - edge find_taken_edge_goto (const vec<basic_block> &path, ggoto *); - virtual void debug (); - virtual void dump (FILE *out); - - back_threader_registry m_registry; - - // Current path being analyzed. - auto_vec<basic_block> m_path; - // Flag to mark visited BBs while analyzing a path. - auto_bb_flag m_visited_flag; - // The set of SSA names, any of which could potentially change the - // value of the final conditional in a path. - auto_bitmap m_imports; - // The last statement in the path. - gimple *m_last_stmt; - // Marker to differentiate unreachable edges. - static const edge UNREACHABLE_EDGE; - // Set to TRUE if unknown SSA names along a path should be resolved - // with the ranger. Otherwise, unknown SSA names are assumed to be - // VARYING. Setting to true is more precise but slower. - function *m_fun; - // Ranger for the path solver. - gimple_ranger *m_ranger; - // Path solver, reused across all candidate paths. - path_range_query *m_solver; - unsigned m_flags; - // Set to TRUE for the first of each thread[12] pass or the first of - // each threadfull[12] pass. This is used to differentiate between - // the different threading passes so we can set up debug counters. - bool m_first; -}; - // Used to differentiate unreachable edges, so we may stop the search // in a the given direction. const edge back_threader::UNREACHABLE_EDGE = (edge) -1; diff --git a/gcc/tree-ssa-threadbackward.h b/gcc/tree-ssa-threadbackward.h new file mode 100644 index 000000000000..12a1f3bb387a --- /dev/null +++ b/gcc/tree-ssa-threadbackward.h @@ -0,0 +1,96 @@ +/* Header file for the SSA backward jump threader. + Copyright (C) 2026 Free Software Foundation, Inc. + Contributed by Aldy Hernandez <[email protected]>. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#ifndef GCC_TREE_SSA_THREADBACKWARD_H +#define GCC_TREE_SSA_THREADBACKWARD_H + +class gimple_ranger; +class path_range_query; +class back_threader_profitability; + +// Path registry for the backwards threader. After all paths have been +// registered with register_path(), thread_through_all_blocks() is called +// to modify the CFG. + +class back_threader_registry : public back_jt_path_registry +{ +public: + bool register_path (const vec<basic_block> &, edge taken); +}; + +// Back threader flags. +#define BT_NONE 0 +// Generate fast code at the expense of code size. +#define BT_SPEED 1 +// Resolve unknown SSAs on entry to a threading path. If set, use the +// ranger. If not, assume all ranges on entry to a path are VARYING. +#define BT_RESOLVE 2 + +class back_threader +{ +public: + back_threader (function *fun, unsigned flags, bool first); + virtual ~back_threader (); + unsigned thread_blocks (); + void search (); + unsigned apply (); +private: + void maybe_thread_block (basic_block bb); + bool debug_counter (); + edge maybe_register_path (back_threader_profitability &); + void maybe_register_path_dump (edge taken_edge); + void find_paths_to_names (basic_block bb, bitmap imports, unsigned, + back_threader_profitability &); + edge find_taken_edge (const vec<basic_block> &path); + edge find_taken_edge_cond (const vec<basic_block> &path, gcond *); + edge find_taken_edge_switch (const vec<basic_block> &path, gswitch *); + edge find_taken_edge_goto (const vec<basic_block> &path, ggoto *); + virtual void debug (); + virtual void dump (FILE *out); + + back_threader_registry m_registry; + + // Current path being analyzed. + auto_vec<basic_block> m_path; + // Flag to mark visited BBs while analyzing a path. + auto_bb_flag m_visited_flag; + // The set of SSA names, any of which could potentially change the + // value of the final conditional in a path. + auto_bitmap m_imports; + // The last statement in the path. + gimple *m_last_stmt; + // Marker to differentiate unreachable edges. + static const edge UNREACHABLE_EDGE; + // Set to TRUE if unknown SSA names along a path should be resolved + // with the ranger. Otherwise, unknown SSA names are assumed to be + // VARYING. Setting to true is more precise but slower. + function *m_fun; + // Ranger for the path solver. + gimple_ranger *m_ranger; + // Path solver, reused across all candidate paths. + path_range_query *m_solver; + unsigned m_flags; + // Set to TRUE for the first of each thread[12] pass or the first of + // each threadfull[12] pass. This is used to differentiate between + // the different threading passes so we can set up debug counters. + bool m_first; +}; + +#endif // GCC_TREE_SSA_THREADBACKWARD_H
