GCC Middle and Back End API Reference
Go to the documentation of this file.
1/* Header file for gimple range GORI structures.
2 Copyright (C) 2017-2024 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>
4 and Aldy Hernandez <aldyh@redhat.com>.
6This file is part of GCC.
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
25// RANGE_DEF_CHAIN is used to determine which SSA names in a block can
26// have range information calculated for them, and what the
27// dependencies on each other are.
34 tree depend1 (tree name) const;
35 tree depend2 (tree name) const;
36 bool in_chain_p (tree name, tree def);
37 bool chain_import_p (tree name, tree import);
38 void register_dependency (tree name, tree ssa1, basic_block bb = NULL);
39 void dump (FILE *f, basic_block bb, const char *prefix = NULL);
41 bool has_def_chain (tree name);
45 bitmap get_imports (tree name);
48 struct rdc {
49 unsigned int ssa1; // First direct dependency
50 unsigned int ssa2; // Second direct dependency
51 bitmap bm; // All dependencies
53 };
54 vec<rdc> m_def_chain; // SSA_NAME : def chain components.
55 void set_import (struct rdc &data, tree imp, bitmap b);
59// Return the first direct dependency for NAME, if there is one.
60// Direct dependencies are those which occur on the definition statement.
61// Only the first 2 such names are cached.
63inline tree
66 unsigned v = SSA_NAME_VERSION (name);
67 if (v >= m_def_chain.length ())
68 return NULL_TREE;
69 unsigned v1 = m_def_chain[v].ssa1;
70 if (!v1)
71 return NULL_TREE;
72 return ssa_name (v1);
75// Return the second direct dependency for NAME, if there is one.
77inline tree
80 unsigned v = SSA_NAME_VERSION (name);
81 if (v >= m_def_chain.length ())
82 return NULL_TREE;
83 unsigned v2 = m_def_chain[v].ssa2;
84 if (!v2)
85 return NULL_TREE;
86 return ssa_name (v2);
89// GORI_MAP is used to accumulate what SSA names in a block can
90// generate range information, and provides tools for the block ranger
91// to enable it to efficiently calculate these ranges.
96 gori_map ();
97 ~gori_map ();
99 bool is_export_p (tree name, basic_block bb = NULL);
100 bool is_import_p (tree name, basic_block bb);
103 void set_range_invariant (tree name, bool invariant = true);
105 void dump (FILE *f);
106 void dump (FILE *f, basic_block bb, bool verbose = true);
108 vec<bitmap> m_outgoing; // BB: Outgoing ranges calculable on edges
109 vec<bitmap> m_incoming; // BB: Incoming ranges which can affect exports.
110 bitmap m_maybe_variant; // Names which might have outgoing ranges.
111 void maybe_add_gori (tree name, basic_block bb);
112 void calculate_gori (basic_block bb);
116// This class is used to determine which SSA_NAMES can have ranges
117// calculated for them on outgoing edges from basic blocks. This represents
118// ONLY the effect of the basic block edge->src on a range.
120// There are 2 primary entry points:
122// has_edge_range_p (tree name, edge e)
123// returns true if the outgoing edge *may* be able to produce range
124// information for ssa_name NAME on edge E.
125// FALSE is returned if this edge does not affect the range of NAME.
126// if no edge is specified, return TRUE if name may have a value calculated
127// on *ANY* edge that has been seen. FALSE indicates that the global value
128// is applicable everywhere that has been processed.
130// outgoing_edge_range_p (vrange &range, edge e, tree name)
131// Actually does the calculation of RANGE for name on E
132// This represents application of whatever static range effect edge E
133// may have on NAME, not any cumulative effect.
135// There are also some internal APIs
137// ssa_range_in_bb () is an internal routine which is used to start any
138// calculation chain using SSA_NAMES which come from outside the block. ie
139// a_2 = b_4 - 8
140// if (a_2 < 30)
141// on the true edge, a_2 is known to be [0, 29]
142// b_4 can be calculated as [8, 37]
143// during this calculation, b_4 is considered an "import" and ssa_range_in_bb
144// is queried for a starting range which is used in the calculation.
145// A default value of VARYING provides the raw static info for the edge.
147// If there is any known range for b_4 coming into this block, it can refine
148// the results. This allows for cascading results to be propagated.
149// if b_4 is [100, 200] on entry to the block, feeds into the calculation
150// of a_2 = [92, 192], and finally on the true edge the range would be
151// an empty range [] because it is not possible for the true edge to be taken.
153// expr_range_in_bb is simply a wrapper which calls ssa_range_in_bb for
154// SSA_NAMES and otherwise simply calculates the range of the expression.
156// The constructor takes a flag value to use on edges to check for the
157// NON_EXECUTABLE_EDGE property. The zero default means no flag is checked.
158// All value requests from NON_EXECUTABLE_EDGE edges are returned UNDEFINED.
160// The remaining routines are internal use only.
162class value_relation;
164class gori_compute : public gori_map
168 bool outgoing_edge_range_p (vrange &r, edge e, tree name, range_query &q);
169 bool condexpr_adjust (vrange &r1, vrange &r2, gimple *s, tree cond, tree op1,
170 tree op2, fur_source &src);
171 bool has_edge_range_p (tree name, basic_block bb = NULL);
172 bool has_edge_range_p (tree name, edge e);
173 void dump (FILE *f);
174 bool compute_operand_range (vrange &r, gimple *stmt, const vrange &lhs,
175 tree name, class fur_source &src,
178 bool refine_using_relation (tree op1, vrange &op1_range,
179 tree op2, vrange &op2_range,
181 bool may_recompute_p (tree name, edge e, int depth = -1);
182 bool may_recompute_p (tree name, basic_block bb = NULL, int depth = -1);
183 bool compute_operand_range_switch (vrange &r, gswitch *s, const vrange &lhs,
184 tree name, fur_source &src);
186 const vrange &lhs, fur_source &src,
189 const vrange &lhs, fur_source &src,
193 const vrange &lhs, tree name,
194 fur_source &src,
196 void compute_logical_operands (vrange &true_range, vrange &false_range,
198 const irange &lhs, tree name, fur_source &src,
199 tree op, bool op_in_chain);
200 bool logical_combine (vrange &r, enum tree_code code, const irange &lhs,
201 const vrange &op1_true, const vrange &op1_false,
202 const vrange &op2_true, const vrange &op2_false);
203 int_range<2> m_bool_zero; // Boolean false cached.
204 int_range<2> m_bool_one; // Boolean true cached.
206 gimple_outgoing_range outgoing; // Edge values for COND_EXPR & SWITCH_EXPR.
211// These APIs are used to query GORI if there are ranges generated on an edge.
212// GORI_ON_EDGE is used to get all the ranges at once (returned in an
213// ssa_cache structure).
214// GORI_NAME_ON_EDGE is used to simply ask if NAME has a range on edge E
216// Fill ssa-cache R with any outgoing ranges on edge E, using OGR and QUERY.
217bool gori_on_edge (class ssa_cache &r, edge e,
218 range_query *query = NULL,
221// Query if NAME has an outgoing range on edge E, and return it in R if so.
222// Note this doesnt use ranger, its a static GORI analysis of the range in
223// block e->src and is based on any branch at the exit of that block.
224bool gori_name_on_edge (vrange &r, tree name, edge e, range_query *q = NULL);
226// For each name that is an import into BB's exports..
227#define FOR_EACH_GORI_IMPORT_NAME(gori, bb, name) \
228 for (gori_export_iterator iter ((gori).imports ((bb))); \
229 ((name) = iter.get_name ()); \
230 iter.next ())
232// For each name possibly exported from block BB.
233#define FOR_EACH_GORI_EXPORT_NAME(gori, bb, name) \
234 for (gori_export_iterator iter ((gori).exports ((bb))); \
235 ((name) = iter.get_name ()); \
236 iter.next ())
238// Used to assist with iterating over the GORI export list in various ways
242 void next ();
243 tree get_name ();
247 unsigned y;
Definition genoutput.cc:147
Definition gimple-range-fold.h:98
Definition gimple-range-edge.h:39
Definition gimple-range-op.h:29
Definition gimple-range-gori.h:165
int_range< 2 > m_bool_zero
Definition gimple-range-gori.h:203
void dump(FILE *f)
Definition gimple-range-gori.cc:1556
bool outgoing_edge_range_p(vrange &r, edge e, tree name, range_query &q)
Definition gimple-range-gori.cc:1382
int_range< 2 > m_bool_one
Definition gimple-range-gori.h:204
bool compute_operand1_and_operand2_range(vrange &r, gimple_range_op_handler &handler, const vrange &lhs, tree name, fur_source &src, value_relation *rel=NULL)
Definition gimple-range-gori.cc:1266
bool may_recompute_p(tree name, edge e, int depth=-1)
Definition gimple-range-gori.cc:1347
bool condexpr_adjust(vrange &r1, vrange &r2, gimple *s, tree cond, tree op1, tree op2, fur_source &src)
Definition gimple-range-gori.cc:1458
int m_not_executable_flag
Definition gimple-range-gori.h:208
bool compute_operand1_range(vrange &r, gimple_range_op_handler &handler, const vrange &lhs, fur_source &src, value_relation *rel=NULL)
Definition gimple-range-gori.cc:1118
bool compute_operand_range_switch(vrange &r, gswitch *s, const vrange &lhs, tree name, fur_source &src)
Definition gimple-range-gori.cc:576
void compute_logical_operands(vrange &true_range, vrange &false_range, gimple_range_op_handler &handler, const irange &lhs, tree name, fur_source &src, tree op, bool op_in_chain)
Definition gimple-range-gori.cc:950
gimple_outgoing_range outgoing
Definition gimple-range-gori.h:206
bool refine_using_relation(tree op1, vrange &op1_range, tree op2, vrange &op2_range, fur_source &src, relation_kind k)
Definition gimple-range-gori.cc:1010
bool compute_operand_range(vrange &r, gimple *stmt, const vrange &lhs, tree name, class fur_source &src, value_relation *rel=NULL)
Definition gimple-range-gori.cc:604
bool has_edge_range_p(tree name, basic_block bb=NULL)
Definition gimple-range-gori.cc:1358
bool compute_operand2_range(vrange &r, gimple_range_op_handler &handler, const vrange &lhs, fur_source &src, value_relation *rel=NULL)
Definition gimple-range-gori.cc:1199
gori_compute(int not_executable_flag=0)
Definition gimple-range-gori.cc:560
range_tracer tracer
Definition gimple-range-gori.h:207
bool logical_combine(vrange &r, enum tree_code code, const irange &lhs, const vrange &op1_true, const vrange &op1_false, const vrange &op2_true, const vrange &op2_false)
Definition gimple-range-gori.cc:783
Definition gimple-range-gori.h:239
bitmap_iterator bi
Definition gimple-range-gori.h:246
tree get_name()
Definition gimple-range-gori.cc:1588
gori_export_iterator(bitmap b)
Definition gimple-range-gori.cc:1567
void next()
Definition gimple-range-gori.cc:1578
bitmap bm
Definition gimple-range-gori.h:245
unsigned y
Definition gimple-range-gori.h:247
Definition gimple-range-gori.h:94
void maybe_add_gori(tree name, basic_block bb)
Definition gimple-range-gori.cc:433
bitmap m_maybe_variant
Definition gimple-range-gori.h:110
vec< bitmap > m_incoming
Definition gimple-range-gori.h:109
bool is_import_p(tree name, basic_block bb)
Definition gimple-range-gori.cc:423
Definition gimple-range-gori.cc:359
Definition gimple-range-gori.cc:370
vec< bitmap > m_outgoing
Definition gimple-range-gori.h:108
void dump(FILE *f)
Definition gimple-range-gori.cc:543
bitmap imports(basic_block bb)
Definition gimple-range-gori.cc:389
bitmap exports(basic_block bb)
Definition gimple-range-gori.cc:379
void calculate_gori(basic_block bb)
Definition gimple-range-gori.cc:457
void set_range_invariant(tree name, bool invariant=true)
Definition gimple-range-gori.cc:412
bool is_export_p(tree name, basic_block bb=NULL)
Definition gimple-range-gori.cc:400
Definition value-range.h:377
Definition value-range.h:276
Definition gimple-range-gori.h:30
tree depend1(tree name) const
Definition gimple-range-gori.h:64
bool in_chain_p(tree name, tree def)
Definition gimple-range-gori.cc:116
void dump(FILE *f, basic_block bb, const char *prefix=NULL)
Definition gimple-range-gori.cc:301
void set_import(struct rdc &data, tree imp, bitmap b)
Definition gimple-range-gori.cc:132
void register_dependency(tree name, tree ssa1, basic_block bb=NULL)
Definition gimple-range-gori.cc:170
bitmap get_def_chain(tree name)
Definition gimple-range-gori.cc:255
bool has_def_chain(tree name)
Definition gimple-range-gori.cc:238
vec< rdc > m_def_chain
Definition gimple-range-gori.h:54
Definition gimple-range-gori.cc:96
bool def_chain_in_bitmap_p(tree name, bitmap b)
Definition gimple-range-gori.cc:218
Definition gimple-range-gori.cc:106
bool chain_import_p(tree name, tree import)
Definition gimple-range-gori.cc:159
bitmap get_imports(tree name)
Definition gimple-range-gori.cc:148
bitmap_obstack m_bitmaps
Definition gimple-range-gori.h:46
void add_def_chain_to_bitmap(bitmap b, tree name)
Definition gimple-range-gori.cc:227
int m_logical_depth
Definition gimple-range-gori.h:56
tree depend2(tree name) const
Definition gimple-range-gori.h:78
Definition value-query.h:55
Definition gimple-range-trace.h:30
Definition gimple-range-cache.h:57
Definition value-relation.h:423
Definition value-range.h:76
bool verbose
Definition collect-utils.cc:35
class edge_def * edge
Definition coretypes.h:342
class bitmap_head * bitmap
Definition coretypes.h:51
union tree_node * tree
Definition coretypes.h:97
Definition genmatch.cc:347
Definition ggc.h:184
bool gori_name_on_edge(vrange &r, tree name, edge e, range_query *q=NULL)
Definition gimple-range-gori.cc:1806
bool gori_on_edge(class ssa_cache &r, edge e, range_query *query=NULL, gimple_outgoing_range *ogr=NULL)
Definition gimple-range-gori.cc:1731
poly_int< N, C > r
Definition poly-int.h:770
Ca const poly_int< N, Cb > & b
Definition poly-int.h:767
Definition basic-block.h:117
Definition bitmap.h:519
Definition bitmap.h:294
Definition loop-invariant.cc:88
Definition gimple.h:225
Definition gimple.h:894
Definition loop-invariant.cc:101
Definition gimple-range-gori.h:48
bitmap m_import
Definition gimple-range-gori.h:52
unsigned int ssa1
Definition gimple-range-gori.h:49
unsigned int ssa2
Definition gimple-range-gori.h:50
bitmap bm
Definition gimple-range-gori.h:51
Definition vec.h:450
#define NULL
Definition system.h:50
#define ssa_name(i)
Definition tree-ssanames.h:53
Definition tree.h:2101
#define NULL_TREE
Definition tree.h:317
enum relation_kind_t relation_kind