Line data Source code
1 : /* Header file for the SSA backward jump threader.
2 : Copyright (C) 2026 Free Software Foundation, Inc.
3 : Contributed by Aldy Hernandez <aldy@quesejoda.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #ifndef GCC_TREE_SSA_THREADBACKWARD_H
22 : #define GCC_TREE_SSA_THREADBACKWARD_H
23 :
24 : class gimple_ranger;
25 : class path_range_query;
26 : class back_threader_profitability;
27 :
28 : // Path registry for the backwards threader. After all paths have been
29 : // registered with register_path(), thread_through_all_blocks() is called
30 : // to modify the CFG.
31 :
32 13046582 : class back_threader_registry : public back_jt_path_registry
33 : {
34 : public:
35 : bool register_path (const vec<basic_block> &, edge taken);
36 : };
37 :
38 : // Back threader flags.
39 : #define BT_NONE 0
40 : // Generate fast code at the expense of code size.
41 : #define BT_SPEED 1
42 : // Resolve unknown SSAs on entry to a threading path. If set, use the
43 : // ranger. If not, assume all ranges on entry to a path are VARYING.
44 : #define BT_RESOLVE 2
45 :
46 : class back_threader
47 : {
48 : public:
49 : back_threader (function *fun, unsigned flags, bool first);
50 : virtual ~back_threader ();
51 : unsigned thread_blocks ();
52 : void search ();
53 : unsigned apply ();
54 : protected:
55 : // The path solver for the search.
56 : virtual path_range_query *make_solver (gimple_ranger &);
57 : private:
58 : void maybe_thread_block (basic_block bb);
59 : bool debug_counter ();
60 : edge maybe_register_path (back_threader_profitability &);
61 : void maybe_register_path_dump (edge taken_edge);
62 : void find_paths_to_names (basic_block bb, bitmap imports, unsigned,
63 : back_threader_profitability &);
64 : edge find_taken_edge (const vec<basic_block> &path);
65 : edge find_taken_edge_cond (const vec<basic_block> &path, gcond *);
66 : edge find_taken_edge_switch (const vec<basic_block> &path, gswitch *);
67 : edge find_taken_edge_goto (const vec<basic_block> &path, ggoto *);
68 : virtual void debug ();
69 : virtual void dump (FILE *out);
70 :
71 : back_threader_registry m_registry;
72 :
73 : // Current path being analyzed.
74 : auto_vec<basic_block> m_path;
75 : // Flag to mark visited BBs while analyzing a path.
76 : auto_bb_flag m_visited_flag;
77 : // The set of SSA names, any of which could potentially change the
78 : // value of the final conditional in a path.
79 : auto_bitmap m_imports;
80 : // The last statement in the path.
81 : gimple *m_last_stmt;
82 : // Marker to differentiate unreachable edges.
83 : static const edge UNREACHABLE_EDGE;
84 : // Set to TRUE if unknown SSA names along a path should be resolved
85 : // with the ranger. Otherwise, unknown SSA names are assumed to be
86 : // VARYING. Setting to true is more precise but slower.
87 : function *m_fun;
88 : // Ranger for the path solver.
89 : gimple_ranger *m_ranger;
90 : // Path solver, reused across all candidate paths.
91 : path_range_query *m_solver;
92 : unsigned m_flags;
93 : // Set to TRUE for the first of each thread[12] pass or the first of
94 : // each threadfull[12] pass. This is used to differentiate between
95 : // the different threading passes so we can set up debug counters.
96 : bool m_first;
97 : };
98 :
99 : #endif // GCC_TREE_SSA_THREADBACKWARD_H
|