]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gimple-range-gori.h
check undefine_p for one more vr
[thirdparty/gcc.git] / gcc / gimple-range-gori.h
CommitLineData
90e88fd3 1/* Header file for gimple range GORI structures.
aeee4812 2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
90e88fd3
AM
3 Contributed by Andrew MacLeod <amacleod@redhat.com>
4 and Aldy Hernandez <aldyh@redhat.com>.
5
6This file is part of GCC.
7
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
11version.
12
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.
17
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/>. */
21
22#ifndef GCC_GIMPLE_RANGE_GORI_H
23#define GCC_GIMPLE_RANGE_GORI_H
24
28ceee1b
AM
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.
28
29class range_def_chain
30{
31public:
32 range_def_chain ();
33 ~range_def_chain ();
c2164470
AM
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);
40protected:
28ceee1b 41 bool has_def_chain (tree name);
c2164470
AM
42 bool def_chain_in_bitmap_p (tree name, bitmap b);
43 void add_def_chain_to_bitmap (bitmap b, tree name);
28ceee1b 44 bitmap get_def_chain (tree name);
c2164470
AM
45 bitmap get_imports (tree name);
46 bitmap_obstack m_bitmaps;
28ceee1b 47private:
c2164470 48 struct rdc {
40c7f943
AM
49 unsigned int ssa1; // First direct dependency
50 unsigned int ssa2; // Second direct dependency
c2164470
AM
51 bitmap bm; // All dependencies
52 bitmap m_import;
53 };
54 vec<rdc> m_def_chain; // SSA_NAME : def chain components.
55 void set_import (struct rdc &data, tree imp, bitmap b);
28ceee1b
AM
56 int m_logical_depth;
57};
58
c2164470 59// Return the first direct dependency for NAME, if there is one.
c46b5b0a 60// Direct dependencies are those which occur on the definition statement.
c2164470
AM
61// Only the first 2 such names are cached.
62
63inline tree
64range_def_chain::depend1 (tree name) const
65{
66 unsigned v = SSA_NAME_VERSION (name);
67 if (v >= m_def_chain.length ())
68 return NULL_TREE;
40c7f943
AM
69 unsigned v1 = m_def_chain[v].ssa1;
70 if (!v1)
71 return NULL_TREE;
72 return ssa_name (v1);
c2164470
AM
73}
74
75// Return the second direct dependency for NAME, if there is one.
76
77inline tree
78range_def_chain::depend2 (tree name) const
79{
80 unsigned v = SSA_NAME_VERSION (name);
81 if (v >= m_def_chain.length ())
82 return NULL_TREE;
40c7f943
AM
83 unsigned v2 = m_def_chain[v].ssa2;
84 if (!v2)
85 return NULL_TREE;
86 return ssa_name (v2);
c2164470
AM
87}
88
28ceee1b
AM
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.
92
93class gori_map : public range_def_chain
94{
95public:
96 gori_map ();
97 ~gori_map ();
98
99 bool is_export_p (tree name, basic_block bb = NULL);
c2164470 100 bool is_import_p (tree name, basic_block bb);
28ceee1b 101 bitmap exports (basic_block bb);
c2164470 102 bitmap imports (basic_block bb);
6c849e2f 103 void set_range_invariant (tree name, bool invariant = true);
28ceee1b
AM
104
105 void dump (FILE *f);
c2164470 106 void dump (FILE *f, basic_block bb, bool verbose = true);
28ceee1b 107private:
c46b5b0a 108 vec<bitmap> m_outgoing; // BB: Outgoing ranges calculable on edges
c2164470 109 vec<bitmap> m_incoming; // BB: Incoming ranges which can affect exports.
28ceee1b
AM
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);
113};
114
90e88fd3
AM
115
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.
119//
120// There are 2 primary entry points:
121//
7f359556 122// has_edge_range_p (tree name, edge e)
90e88fd3
AM
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.
7f359556
AM
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.
90e88fd3 129//
45c8523d 130// outgoing_edge_range_p (vrange &range, edge e, tree name)
90e88fd3
AM
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.
134
135// There are also some internal APIs
136//
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.
146//
147// If there is any known range for b_4 coming into this block, it can refine
c46b5b0a 148// the results. This allows for cascading results to be propagated.
90e88fd3
AM
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.
152//
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.
155//
053e1d64
AM
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.
159//
90e88fd3
AM
160// The remaining routines are internal use only.
161
431cdfbe
AM
162class value_relation;
163
28ceee1b 164class gori_compute : public gori_map
90e88fd3
AM
165{
166public:
053e1d64 167 gori_compute (int not_executable_flag = 0);
45c8523d
AH
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,
e15425e8 170 tree op2, fur_source &src);
ed4a5f57
AM
171 bool has_edge_range_p (tree name, basic_block bb = NULL);
172 bool has_edge_range_p (tree name, edge e);
90e88fd3 173 void dump (FILE *f);
53e6d7a3
AM
174 bool compute_operand_range (vrange &r, gimple *stmt, const vrange &lhs,
175 tree name, class fur_source &src,
176 value_relation *rel = NULL);
90e88fd3 177private:
67166c9e
AM
178 bool refine_using_relation (tree op1, vrange &op1_range,
179 tree op2, vrange &op2_range,
180 fur_source &src, relation_kind k);
429a7a88
AM
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);
45c8523d 183 bool compute_operand_range_switch (vrange &r, gswitch *s, const vrange &lhs,
47ea02bb 184 tree name, fur_source &src);
51ce0638 185 bool compute_operand1_range (vrange &r, gimple_range_op_handler &handler,
018e7f16 186 const vrange &lhs, fur_source &src,
431cdfbe 187 value_relation *rel = NULL);
51ce0638 188 bool compute_operand2_range (vrange &r, gimple_range_op_handler &handler,
988b07a6 189 const vrange &lhs, fur_source &src,
431cdfbe 190 value_relation *rel = NULL);
51ce0638
AM
191 bool compute_operand1_and_operand2_range (vrange &r,
192 gimple_range_op_handler &handler,
45c8523d 193 const vrange &lhs, tree name,
431cdfbe
AM
194 fur_source &src,
195 value_relation *rel = NULL);
45c8523d 196 void compute_logical_operands (vrange &true_range, vrange &false_range,
51ce0638
AM
197 gimple_range_op_handler &handler,
198 const irange &lhs, tree name, fur_source &src,
199 tree op, bool op_in_chain);
45c8523d
AH
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);
47ea02bb
AM
203 int_range<2> m_bool_zero; // Boolean false cached.
204 int_range<2> m_bool_one; // Boolean true cached.
90e88fd3 205
12f0a54b 206 gimple_outgoing_range outgoing; // Edge values for COND_EXPR & SWITCH_EXPR.
4759e1e0 207 range_tracer tracer;
053e1d64 208 int m_not_executable_flag;
90e88fd3
AM
209};
210
c2164470
AM
211// For each name that is an import into BB's exports..
212#define FOR_EACH_GORI_IMPORT_NAME(gori, bb, name) \
213 for (gori_export_iterator iter ((gori).imports ((bb))); \
214 ((name) = iter.get_name ()); \
215 iter.next ())
216
217// For each name possibly exported from block BB.
218#define FOR_EACH_GORI_EXPORT_NAME(gori, bb, name) \
219 for (gori_export_iterator iter ((gori).exports ((bb))); \
220 ((name) = iter.get_name ()); \
221 iter.next ())
222
223// Used to assist with iterating over the GORI export list in various ways
224class gori_export_iterator {
225public:
226 gori_export_iterator (bitmap b);
227 void next ();
228 tree get_name ();
229protected:
230 bitmap bm;
231 bitmap_iterator bi;
232 unsigned y;
233};
234
90e88fd3 235#endif // GCC_GIMPLE_RANGE_GORI_H