GCC Middle and Back End API Reference
gimple-range-path.h
Go to the documentation of this file.
1/* Header file for jump threading path solver.
2 Copyright (C) 2021-2026 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_TREE_SSA_THREADSOLVER_H
22#define GCC_TREE_SSA_THREADSOLVER_H
23
24// Internal construct to help facilitate debugging of the path solver.
25#define DEBUG_PATH_RANGER \
26 (dump_file && (param_threader_debug == THREADER_DEBUG_ALL))
27
28// This class is a basic block path solver. Given a set of BBs
29// indicating a path through the CFG, range_of_expr and range_of_stmt
30// will calculate the range of an SSA or STMT as if the BBs in the
31// path would have been executed in order.
32//
33// Note that the blocks are in reverse order, thus the exit block is
34// path[0].
35
37{
38public:
39 path_range_query (class gimple_ranger &ranger,
40 const vec<basic_block> &path,
41 const bitmap_head *dependencies = NULL,
42 bool resolve = true);
43 path_range_query (gimple_ranger &ranger, bool resolve = true);
44 virtual ~path_range_query ();
45 void reset_path (const vec<basic_block> &, const bitmap_head *dependencies);
46 bool range_of_expr (vrange &r, tree name, gimple * = NULL) override;
47 bool range_of_stmt (vrange &r, gimple *, tree name = NULL) override;
48 bool unreachable_path_p ();
49 // Path ranger should not be an active query.
50 virtual bool active_query_compatible_p () override { return false; }
51 void dump (FILE *) override;
52 void debug ();
53
54private:
55 bool internal_range_of_expr (vrange &r, tree name, gimple *);
56 void compute_ranges (const bitmap_head *dependencies);
57 void compute_exit_dependencies (bitmap_head *dependencies);
58 bool defined_outside_path (tree name);
59 void range_on_path_entry (vrange &r, tree name);
61
62 // Cache manipulation.
63 bool get_cache (vrange &r, tree name);
64
65 // Methods to compute ranges for the given path.
70 void ssa_range_in_phi (vrange &r, gphi *phi);
74 bool add_to_exit_dependencies (tree name, bitmap dependencies);
75 bool exit_dependency_p (tree name);
76 bool ssa_defined_in_bb (tree name, basic_block bb);
78
79 // Path navigation.
80 basic_block entry_bb () { return m_path[m_path.length () - 1]; }
81 basic_block exit_bb () { return m_path[0]; }
83 basic_block prev_bb () { return m_path[m_pos + 1]; }
84 basic_block next_bb () { return m_path[m_pos - 1]; }
85 bool at_entry () { return m_pos == m_path.length () - 1; }
86 bool at_exit () { return m_pos == 0; }
87 void move_next () { --m_pos; }
88
89 // Range cache for SSA names.
91
92 // All the pointer typed exit dependencies in the path.
94
95 // Path being analyzed.
97
98 // This is a list of SSA names that may have relevant context
99 // information for solving the final conditional along the path.
100 // Ranges for these SSA names are pre-calculated and cached during a
101 // top-down traversal of the path, and are then used to answer
102 // questions at the path exit.
104
105 // A ranger used to resolve ranges for SSA names whose values come
106 // from outside the path.
108
109 // Current path position.
110 unsigned m_pos;
111
112 // Use ranger to resolve anything not known on entry.
114
115 // Set if there were any undefined expressions while pre-calculating path.
117};
118
119#endif // GCC_TREE_SSA_THREADSOLVER_H
Definition bitmap.h:950
Definition vec.h:1667
Definition bitmap.h:327
Definition gimple-range.h:48
Definition value-relation.h:359
bool defined_outside_path(tree name)
Definition gimple-range-path.cc:120
void compute_ranges(const bitmap_head *dependencies)
Definition gimple-range-path.cc:569
bool exit_dependency_p(tree name)
Definition gimple-range-path.cc:70
path_oracle * get_path_oracle()
Definition gimple-range-path.h:60
void range_on_path_entry(vrange &r, tree name)
Definition gimple-range-path.cc:131
auto_vec< tree > m_pointer_exit_dependencies
Definition gimple-range-path.h:93
virtual bool active_query_compatible_p() override
Definition gimple-range-path.h:50
void adjust_for_non_null_uses(basic_block bb)
Definition gimple-range-path.cc:463
auto_bitmap m_exit_dependencies
Definition gimple-range-path.h:103
unsigned m_pos
Definition gimple-range-path.h:110
bool ssa_defined_in_bb(tree name, basic_block bb)
Definition gimple-range-path.cc:218
path_range_query(class gimple_ranger &ranger, const vec< basic_block > &path, const bitmap_head *dependencies=NULL, bool resolve=true)
Definition gimple-range-path.cc:36
bool m_undefined_path
Definition gimple-range-path.h:116
basic_block next_bb()
Definition gimple-range-path.h:84
gimple_ranger & m_ranger
Definition gimple-range-path.h:107
bool range_defined_in_block(vrange &, tree name, basic_block bb)
Definition gimple-range-path.cc:297
bool add_to_exit_dependencies(tree name, bitmap dependencies)
Definition gimple-range-path.cc:491
basic_block entry_bb()
Definition gimple-range-path.h:80
bool get_cache(vrange &r, tree name)
Definition gimple-range-path.cc:79
void dump(FILE *) override
Definition gimple-range-path.cc:88
ssa_lazy_cache m_cache
Definition gimple-range-path.h:90
basic_block curr_bb()
Definition gimple-range-path.h:82
void maybe_register_phi_relation(gphi *, edge e)
Definition gimple-range-path.cc:722
bool internal_range_of_expr(vrange &r, tree name, gimple *)
Definition gimple-range-path.cc:141
bool relations_may_be_invalidated(edge)
Definition gimple-range-path.cc:366
void compute_phi_relations(basic_block bb, basic_block prev)
Definition gimple-range-path.cc:754
bool range_of_expr(vrange &r, tree name, gimple *=NULL) override
Definition gimple-range-path.cc:180
void compute_ranges_in_block(basic_block bb)
Definition gimple-range-path.cc:380
basic_block exit_bb()
Definition gimple-range-path.h:81
bool m_resolve
Definition gimple-range-path.h:113
bool at_exit()
Definition gimple-range-path.h:86
auto_vec< basic_block > m_path
Definition gimple-range-path.h:96
bool unreachable_path_p()
Definition gimple-range-path.cc:193
bool range_of_stmt(vrange &r, gimple *, tree name=NULL) override
Definition gimple-range-path.cc:696
void compute_outgoing_relations(basic_block bb, basic_block next)
Definition gimple-range-path.cc:783
void compute_exit_dependencies(bitmap_head *dependencies)
Definition gimple-range-path.cc:503
void ssa_range_in_phi(vrange &r, gphi *phi)
Definition gimple-range-path.cc:233
bool at_entry()
Definition gimple-range-path.h:85
void move_next()
Definition gimple-range-path.h:87
basic_block prev_bb()
Definition gimple-range-path.h:83
void compute_ranges_in_phis(basic_block bb)
Definition gimple-range-path.cc:342
void reset_path(const vec< basic_block > &, const bitmap_head *dependencies)
Definition gimple-range-path.cc:201
relation_oracle * m_relation
Definition value-query.h:109
range_query()
Definition value-query.cc:320
Definition gimple-range-cache.h:80
Definition value-range.h:88
bool debug
Definition collect-utils.cc:34
struct basic_block_def * basic_block
Definition coretypes.h:351
class edge_def * edge
Definition coretypes.h:348
class bitmap_head * bitmap
Definition coretypes.h:51
union tree_node * tree
Definition coretypes.h:97
poly_int< N, C > r
Definition poly-int.h:774
Definition gimple.h:224
Definition gimple.h:464
Definition vec.h:450
#define NULL
Definition system.h:58