Daily bump.
[gcc.git] / gcc / gimple-range.h
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>.
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>. */
21
22 #ifndef GCC_GIMPLE_RANGE_STMT_H
23 #define GCC_GIMPLE_RANGE_STMT_H
24
25
26 #include "range.h"
27 #include "range-op.h"
28 #include "gimple-range-edge.h"
29 #include "gimple-range-gori.h"
30 #include "gimple-range-cache.h"
31 #include "value-query.h"
32
33 // This is the basic range generator interface.
34 //
35 // This base class provides all the API entry points, but only provides
36 // functionality at the statement level. Ie, it can calculate ranges on
37 // statements, but does no additonal lookup.
38 //
39 // All the range_of_* methods will return a range if the types is
40 // supported by the range engine. It may be the full range for the
41 // type, AKA varying_p or it may be a refined range. If the range
42 // type is not supported, then false is returned. Non-statement
43 // related methods return whatever the current global value is.
44
45
46 class gimple_ranger : public range_query
47 {
48 public:
49 gimple_ranger () : m_cache (*this) { }
50 virtual bool range_of_stmt (irange &r, gimple *, tree name = NULL) OVERRIDE;
51 virtual bool range_of_expr (irange &r, tree name, gimple * = NULL) OVERRIDE;
52 virtual bool range_on_edge (irange &r, edge e, tree name) OVERRIDE;
53 virtual void range_on_entry (irange &r, basic_block bb, tree name);
54 virtual void range_on_exit (irange &r, basic_block bb, tree name);
55 void export_global_ranges ();
56 void dump (FILE *f);
57 protected:
58 bool calc_stmt (irange &r, gimple *s, tree name = NULL_TREE);
59 bool range_of_range_op (irange &r, gimple *s);
60 bool range_of_call (irange &r, gcall *call);
61 bool range_of_cond_expr (irange &r, gassign* cond);
62 ranger_cache m_cache;
63 private:
64 bool range_of_phi (irange &r, gphi *phi);
65 bool range_of_address (irange &r, gimple *s);
66 bool range_of_builtin_call (irange &r, gcall *call);
67 bool range_with_loop_info (irange &r, tree name);
68 void range_of_ssa_name_with_loop_info (irange &, tree, class loop *,
69 gphi *);
70 };
71
72 // Calculate a basic range for a tree expression.
73 extern bool get_tree_range (irange &r, tree expr);
74
75 // These routines provide a GIMPLE interface to the range-ops code.
76 extern tree gimple_range_operand1 (const gimple *s);
77 extern tree gimple_range_operand2 (const gimple *s);
78 extern tree gimple_range_base_of_assignment (const gimple *s);
79 extern bool gimple_range_fold (irange &res, const gimple *s,
80 const irange &r1);
81 extern bool gimple_range_fold (irange &res, const gimple *s,
82 const irange &r1,
83 const irange &r2);
84 extern bool gimple_range_calc_op1 (irange &r, const gimple *s,
85 const irange &lhs_range);
86 extern bool gimple_range_calc_op1 (irange &r, const gimple *s,
87 const irange &lhs_range,
88 const irange &op2_range);
89 extern bool gimple_range_calc_op2 (irange &r, const gimple *s,
90 const irange &lhs_range,
91 const irange &op1_range);
92
93
94 // Return the range_operator pointer for this statement. This routine
95 // can also be used to gate whether a routine is range-ops enabled.
96
97 static inline range_operator *
98 gimple_range_handler (const gimple *s)
99 {
100 if (const gassign *ass = dyn_cast<const gassign *> (s))
101 return range_op_handler (gimple_assign_rhs_code (ass),
102 TREE_TYPE (gimple_assign_lhs (ass)));
103 if (const gcond *cond = dyn_cast<const gcond *> (s))
104 return range_op_handler (gimple_cond_code (cond),
105 TREE_TYPE (gimple_cond_lhs (cond)));
106 return NULL;
107 }
108
109 // Return EXP if it is an SSA_NAME with a type supported by gimple ranges.
110
111 static inline tree
112 gimple_range_ssa_p (tree exp)
113 {
114 if (exp && TREE_CODE (exp) == SSA_NAME &&
115 !SSA_NAME_IS_VIRTUAL_OPERAND (exp) &&
116 irange::supports_type_p (TREE_TYPE (exp)))
117 return exp;
118 return NULL_TREE;
119 }
120
121 // Return true if TYPE1 and TYPE2 are compatible range types.
122
123 static inline bool
124 range_compatible_p (tree type1, tree type2)
125 {
126 // types_compatible_p requires conversion in both directions to be useless.
127 // GIMPLE only requires a cast one way in order to be compatible.
128 // Ranges really only need the sign and precision to be the same.
129 return (TYPE_PRECISION (type1) == TYPE_PRECISION (type2)
130 && TYPE_SIGN (type1) == TYPE_SIGN (type2));
131 }
132
133 // Return the legacy GCC global range for NAME if it has one, otherwise
134 // return VARYING.
135
136 static inline value_range
137 gimple_range_global (tree name)
138 {
139 gcc_checking_assert (gimple_range_ssa_p (name));
140 tree type = TREE_TYPE (name);
141 #if 0
142 // Reenable picking up global ranges when we are OK failing tests that look
143 // for builtin_unreachable in the code, like
144 // RUNTESTFLAGS=dg.exp=pr61034.C check-g++
145 // pre-optimizations (inlining) set a global range which causes the ranger
146 // to remove the condition which leads to builtin_unreachable.
147 if (!POINTER_TYPE_P (type) && SSA_NAME_RANGE_INFO (name))
148 {
149 // Return a range from an SSA_NAME's available range.
150 wide_int min, max;
151 enum value_range_kind kind = get_range_info (name, &min, &max);
152 return value_range (type, min, max, kind);
153 }
154 #endif
155 // Otherwise return range for the type.
156 return value_range (type);
157 }
158
159
160 // This class overloads the ranger routines to provide tracing facilties
161 // Entry and exit values to each of the APIs is placed in the dumpfile.
162
163 class trace_ranger : public gimple_ranger
164 {
165 public:
166 trace_ranger ();
167 virtual bool range_of_stmt (irange &r, gimple *s, tree name = NULL_TREE);
168 virtual bool range_of_expr (irange &r, tree name, gimple *s = NULL);
169 virtual bool range_on_edge (irange &r, edge e, tree name);
170 virtual void range_on_entry (irange &r, basic_block bb, tree name);
171 virtual void range_on_exit (irange &r, basic_block bb, tree name);
172 private:
173 static const unsigned bump = 2;
174 unsigned indent;
175 unsigned trace_count; // Current trace index count.
176
177 bool dumping (unsigned counter, bool trailing = false);
178 bool trailer (unsigned counter, const char *caller, bool result, tree name,
179 const irange &r);
180 };
181
182 // Flag to enable debugging the various internal Caches.
183 #define DEBUG_RANGE_CACHE (dump_file && (param_evrp_mode & EVRP_MODE_DEBUG))
184
185 // Temporary external interface to share with vr_values.
186 bool range_of_builtin_call (range_query &query, irange &r, gcall *call);
187
188 #endif // GCC_GIMPLE_RANGE_STMT_H