[Ada] Do not perform useless work in Check_No_Parts_Violations
[official-gcc.git] / gcc / gimple-range.h
blob9ac779a720c5a82092060cd496e23954a15aff89
1 /* Header file for the GIMPLE range interface.
2 Copyright (C) 2019-2021 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>
4 and Aldy Hernandez <aldyh@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_GIMPLE_RANGE_STMT_H
23 #define GCC_GIMPLE_RANGE_STMT_H
26 #include "range.h"
27 #include "range-op.h"
28 #include "value-query.h"
29 #include "gimple-range-edge.h"
30 #include "gimple-range-gori.h"
31 #include "gimple-range-cache.h"
33 // This file is the main include point for gimple ranges.
34 // There are two fold_range routines of interest:
35 // bool fold_range (irange &r, gimple *s, range_query *q)
36 // bool fold_range (irange &r, gimple *s, edge on_edge, range_query *q)
37 // These routines will fold stmt S into the result irange R.
38 // Any ssa_names on the stmt will be calculated using the range_query
39 // parameter via a call to range_of_expr.
40 // If no range_query is provided, current global range info will be used.
41 // The second variation specifies an edge, and stmt S is recalculated as if
42 // it appeared on that edge.
45 // This is the basic range generator interface.
47 // This base class provides all the API entry points, but only provides
48 // functionality at the statement level. Ie, it can calculate ranges on
49 // statements, but does no additonal lookup.
51 // All the range_of_* methods will return a range if the types is
52 // supported by the range engine. It may be the full range for the
53 // type, AKA varying_p or it may be a refined range. If the range
54 // type is not supported, then false is returned. Non-statement
55 // related methods return whatever the current global value is.
58 class gimple_ranger : public range_query
60 public:
61 gimple_ranger () : m_cache (*this) { }
62 virtual bool range_of_stmt (irange &r, gimple *, tree name = NULL) OVERRIDE;
63 virtual bool range_of_expr (irange &r, tree name, gimple * = NULL) OVERRIDE;
64 virtual bool range_on_edge (irange &r, edge e, tree name) OVERRIDE;
65 virtual void range_on_entry (irange &r, basic_block bb, tree name);
66 virtual void range_on_exit (irange &r, basic_block bb, tree name);
67 void export_global_ranges ();
68 inline gori_compute &gori () { return m_cache.m_gori; }
69 virtual void dump (FILE *f) OVERRIDE;
70 void dump_bb (FILE *f, basic_block bb);
71 protected:
72 bool fold_range_internal (irange &r, gimple *s, tree name);
73 ranger_cache m_cache;
76 // Source of all operands for fold_using_range and gori_compute.
77 // It abstracts out the source of an operand so it can come from a stmt or
78 // and edge or anywhere a derived classof fur_source wants.
80 class fur_source
82 public:
83 virtual bool get_operand (irange &r, tree expr);
84 virtual bool get_phi_operand (irange &r, tree expr, edge e);
85 virtual void register_dependency (tree lhs, tree rhs);
86 virtual range_query *query ();
89 // fur_stmt is the specification for drawing an operand from range_query Q
90 // via a range_of_Expr call on stmt S.
92 class fur_stmt : public fur_source
94 public:
95 fur_stmt (gimple *s, range_query *q = NULL);
96 virtual bool get_operand (irange &r, tree expr) OVERRIDE;
97 virtual bool get_phi_operand (irange &r, tree expr, edge e) OVERRIDE;
98 virtual range_query *query () OVERRIDE;
99 private:
100 range_query *m_query;
101 gimple *m_stmt;
105 // Fold stmt S into range R using range query Q.
106 bool fold_range (irange &r, gimple *s, range_query *q = NULL);
107 // Recalculate stmt S into R using range query Q as if it were on edge ON_EDGE.
108 bool fold_range (irange &r, gimple *s, edge on_edge, range_query *q = NULL);
109 // These routines allow you to specify the operands to use when folding.
110 // Any excess queries will be drawn from the current range_query.
111 bool fold_range (irange &r, gimple *s, irange &r1);
112 bool fold_range (irange &r, gimple *s, irange &r1, irange &r2);
113 bool fold_range (irange &r, gimple *s, unsigned num_elements, irange *vector);
115 // This class uses ranges to fold a gimple statement producinf a range for
116 // the LHS. The source of all operands is supplied via the fur_source class
117 // which provides a range_query as well as a source location and any other
118 // required information.
120 class fold_using_range
122 public:
123 bool fold_stmt (irange &r, gimple *s, class fur_source &src,
124 tree name = NULL_TREE);
125 protected:
126 bool range_of_range_op (irange &r, gimple *s, fur_source &src);
127 bool range_of_call (irange &r, gcall *call, fur_source &src);
128 bool range_of_cond_expr (irange &r, gassign* cond, fur_source &src);
129 bool range_of_address (irange &r, gimple *s, fur_source &src);
130 bool range_of_builtin_call (irange &r, gcall *call, fur_source &src);
131 void range_of_builtin_ubsan_call (irange &r, gcall *call, tree_code code,
132 fur_source &src);
133 bool range_of_phi (irange &r, gphi *phi, fur_source &src);
134 void range_of_ssa_name_with_loop_info (irange &, tree, class loop *, gphi *,
135 fur_source &src);
139 // These routines provide a GIMPLE interface to the range-ops code.
140 extern tree gimple_range_operand1 (const gimple *s);
141 extern tree gimple_range_operand2 (const gimple *s);
142 extern bool gimple_range_calc_op1 (irange &r, const gimple *s,
143 const irange &lhs_range);
144 extern bool gimple_range_calc_op1 (irange &r, const gimple *s,
145 const irange &lhs_range,
146 const irange &op2_range);
147 extern bool gimple_range_calc_op2 (irange &r, const gimple *s,
148 const irange &lhs_range,
149 const irange &op1_range);
152 // Return the range_operator pointer for this statement. This routine
153 // can also be used to gate whether a routine is range-ops enabled.
155 static inline range_operator *
156 gimple_range_handler (const gimple *s)
158 if (const gassign *ass = dyn_cast<const gassign *> (s))
159 return range_op_handler (gimple_assign_rhs_code (ass),
160 TREE_TYPE (gimple_assign_lhs (ass)));
161 if (const gcond *cond = dyn_cast<const gcond *> (s))
162 return range_op_handler (gimple_cond_code (cond),
163 TREE_TYPE (gimple_cond_lhs (cond)));
164 return NULL;
167 // Return EXP if it is an SSA_NAME with a type supported by gimple ranges.
169 static inline tree
170 gimple_range_ssa_p (tree exp)
172 if (exp && TREE_CODE (exp) == SSA_NAME &&
173 !SSA_NAME_IS_VIRTUAL_OPERAND (exp) &&
174 irange::supports_type_p (TREE_TYPE (exp)))
175 return exp;
176 return NULL_TREE;
179 // Return true if TYPE1 and TYPE2 are compatible range types.
181 static inline bool
182 range_compatible_p (tree type1, tree type2)
184 // types_compatible_p requires conversion in both directions to be useless.
185 // GIMPLE only requires a cast one way in order to be compatible.
186 // Ranges really only need the sign and precision to be the same.
187 return (TYPE_PRECISION (type1) == TYPE_PRECISION (type2)
188 && TYPE_SIGN (type1) == TYPE_SIGN (type2));
191 // This class overloads the ranger routines to provide tracing facilties
192 // Entry and exit values to each of the APIs is placed in the dumpfile.
194 class trace_ranger : public gimple_ranger
196 public:
197 trace_ranger ();
198 virtual bool range_of_stmt (irange &r, gimple *s, tree name = NULL_TREE);
199 virtual bool range_of_expr (irange &r, tree name, gimple *s = NULL);
200 virtual bool range_on_edge (irange &r, edge e, tree name);
201 virtual void range_on_entry (irange &r, basic_block bb, tree name);
202 virtual void range_on_exit (irange &r, basic_block bb, tree name);
203 private:
204 static const unsigned bump = 2;
205 unsigned indent;
206 unsigned trace_count; // Current trace index count.
208 bool dumping (unsigned counter, bool trailing = false);
209 bool trailer (unsigned counter, const char *caller, bool result, tree name,
210 const irange &r);
213 // Flag to enable debugging the various internal Caches.
214 #define DEBUG_RANGE_CACHE (dump_file && (param_evrp_mode & EVRP_MODE_DEBUG))
216 extern gimple_ranger *enable_ranger (struct function *);
217 extern void disable_ranger (struct function *);
219 #endif // GCC_GIMPLE_RANGE_STMT_H