]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/tree-vrp.h
Update libbid according to the latest Intel Decimal Floating-Point Math Library.
[thirdparty/gcc.git] / gcc / tree-vrp.h
1 /* Support routines for Value Range Propagation (VRP).
2 Copyright (C) 2016-2019 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #ifndef GCC_TREE_VRP_H
21 #define GCC_TREE_VRP_H
22
23 /* Types of value ranges. */
24 enum value_range_kind
25 {
26 /* Empty range. */
27 VR_UNDEFINED,
28 /* Range spans the entire domain. */
29 VR_VARYING,
30 /* Range is [MIN, MAX]. */
31 VR_RANGE,
32 /* Range is ~[MIN, MAX]. */
33 VR_ANTI_RANGE,
34 /* Range is a nice guy. */
35 VR_LAST
36 };
37
38
39 /* Range of values that can be associated with an SSA_NAME after VRP
40 has executed. */
41 class GTY((for_user)) value_range_base
42 {
43 public:
44 value_range_base ();
45 value_range_base (value_range_kind, tree, tree);
46
47 void set (value_range_kind, tree, tree);
48 void set (tree);
49 void set_nonzero (tree);
50 void set_zero (tree);
51
52 enum value_range_kind kind () const;
53 tree min () const;
54 tree max () const;
55
56 /* Types of value ranges. */
57 bool symbolic_p () const;
58 bool constant_p () const;
59 bool undefined_p () const;
60 bool varying_p () const;
61 void set_varying ();
62 void set_undefined ();
63
64 void union_ (const value_range_base *);
65 void intersect (const value_range_base *);
66
67 bool operator== (const value_range_base &) const /* = delete */;
68 bool operator!= (const value_range_base &) const /* = delete */;
69 bool equal_p (const value_range_base &) const;
70
71 /* Misc methods. */
72 tree type () const;
73 bool may_contain_p (tree) const;
74 void set_and_canonicalize (enum value_range_kind, tree, tree);
75 bool zero_p () const;
76 bool nonzero_p () const;
77 bool singleton_p (tree *result = NULL) const;
78 void dump (FILE *) const;
79
80 protected:
81 void check ();
82 static value_range_base union_helper (const value_range_base *,
83 const value_range_base *);
84 static value_range_base intersect_helper (const value_range_base *,
85 const value_range_base *);
86
87 enum value_range_kind m_kind;
88
89 tree m_min;
90 tree m_max;
91
92 friend void gt_ggc_mx_value_range_base (void *);
93 friend void gt_pch_p_16value_range_base (void *, void *,
94 gt_pointer_operator, void *);
95 friend void gt_pch_nx_value_range_base (void *);
96 friend void gt_ggc_mx (value_range_base &);
97 friend void gt_ggc_mx (value_range_base *&);
98 friend void gt_pch_nx (value_range_base &);
99 friend void gt_pch_nx (value_range_base *, gt_pointer_operator, void *);
100
101 private:
102 int value_inside_range (tree) const;
103 };
104
105 /* Note value_range cannot currently be used with GC memory, only
106 value_range_base is fully set up for this. */
107 class GTY((user)) value_range : public value_range_base
108 {
109 public:
110 value_range ();
111 value_range (const value_range_base &);
112 /* Deep-copies equiv bitmap argument. */
113 value_range (value_range_kind, tree, tree, bitmap = NULL);
114
115 /* Shallow-copies equiv bitmap. */
116 value_range (const value_range &) /* = delete */;
117 /* Shallow-copies equiv bitmap. */
118 value_range& operator=(const value_range&) /* = delete */;
119
120 /* Move equiv bitmap from source range. */
121 void move (value_range *);
122
123 /* Leaves equiv bitmap alone. */
124 void update (value_range_kind, tree, tree);
125 /* Deep-copies equiv bitmap argument. */
126 void set (value_range_kind, tree, tree, bitmap = NULL);
127 void set (tree);
128
129 bool operator== (const value_range &) const /* = delete */;
130 bool operator!= (const value_range &) const /* = delete */;
131 void intersect (const value_range *);
132 void union_ (const value_range *);
133 bool equal_p (const value_range &, bool ignore_equivs) const;
134
135 /* Types of value ranges. */
136 void set_undefined ();
137 void set_varying ();
138
139 /* Equivalence bitmap methods. */
140 bitmap equiv () const;
141 void equiv_clear ();
142 void equiv_add (const_tree, const value_range *, bitmap_obstack * = NULL);
143
144 /* Misc methods. */
145 void deep_copy (const value_range *);
146 void set_and_canonicalize (enum value_range_kind, tree, tree, bitmap = NULL);
147 void dump (FILE *) const;
148
149 private:
150 /* Deep-copies bitmap argument. */
151 void set_equiv (bitmap);
152 void check ();
153
154 /* Set of SSA names whose value ranges are equivalent to this one.
155 This set is only valid when TYPE is VR_RANGE or VR_ANTI_RANGE. */
156 bitmap m_equiv;
157 };
158
159 inline
160 value_range_base::value_range_base ()
161 {
162 m_kind = VR_UNDEFINED;
163 m_min = m_max = NULL;
164 }
165
166 inline
167 value_range::value_range ()
168 : value_range_base ()
169 {
170 m_equiv = NULL;
171 }
172
173 /* Return the kind of this range. */
174
175 inline value_range_kind
176 value_range_base::kind () const
177 {
178 return m_kind;
179 }
180
181 inline bitmap
182 value_range::equiv () const
183 {
184 return m_equiv;
185 }
186
187 /* Return the lower bound. */
188
189 inline tree
190 value_range_base::min () const
191 {
192 return m_min;
193 }
194
195 /* Return the upper bound. */
196
197 inline tree
198 value_range_base::max () const
199 {
200 return m_max;
201 }
202
203 /* Return TRUE if range spans the entire possible domain. */
204
205 inline bool
206 value_range_base::varying_p () const
207 {
208 return m_kind == VR_VARYING;
209 }
210
211 /* Return TRUE if range is undefined (essentially the empty set). */
212
213 inline bool
214 value_range_base::undefined_p () const
215 {
216 return m_kind == VR_UNDEFINED;
217 }
218
219 /* Return TRUE if range is the constant zero. */
220
221 inline bool
222 value_range_base::zero_p () const
223 {
224 return (m_kind == VR_RANGE
225 && integer_zerop (m_min)
226 && integer_zerop (m_max));
227 }
228
229 /* Return TRUE if range is nonzero. */
230
231 inline bool
232 value_range_base::nonzero_p () const
233 {
234 return (m_kind == VR_ANTI_RANGE
235 && integer_zerop (m_min)
236 && integer_zerop (m_max));
237 }
238
239 extern void dump_value_range (FILE *, const value_range *);
240 extern void dump_value_range (FILE *, const value_range_base *);
241
242 struct assert_info
243 {
244 /* Predicate code for the ASSERT_EXPR. Must be COMPARISON_CLASS_P. */
245 enum tree_code comp_code;
246
247 /* Name to register the assert for. */
248 tree name;
249
250 /* Value being compared against. */
251 tree val;
252
253 /* Expression to compare. */
254 tree expr;
255 };
256
257 extern void register_edge_assert_for (tree, edge, enum tree_code,
258 tree, tree, vec<assert_info> &);
259 extern bool stmt_interesting_for_vrp (gimple *);
260 extern bool infer_value_range (gimple *, tree, tree_code *, tree *);
261
262 extern bool vrp_bitmap_equal_p (const_bitmap, const_bitmap);
263
264 extern bool range_int_cst_p (const value_range_base *);
265 extern bool range_int_cst_singleton_p (const value_range_base *);
266
267 extern int compare_values (tree, tree);
268 extern int compare_values_warnv (tree, tree, bool *);
269 extern int operand_less_p (tree, tree);
270 extern bool vrp_val_is_min (const_tree);
271 extern bool vrp_val_is_max (const_tree);
272
273 extern tree vrp_val_min (const_tree);
274 extern tree vrp_val_max (const_tree);
275
276 extern void extract_range_from_unary_expr (value_range_base *vr,
277 enum tree_code code,
278 tree type,
279 const value_range_base *vr0_,
280 tree op0_type);
281 extern void extract_range_from_binary_expr (value_range_base *,
282 enum tree_code,
283 tree, const value_range_base *,
284 const value_range_base *);
285
286 extern bool vrp_operand_equal_p (const_tree, const_tree);
287 extern enum value_range_kind intersect_range_with_nonzero_bits
288 (enum value_range_kind, wide_int *, wide_int *, const wide_int &, signop);
289 extern bool vrp_set_zero_nonzero_bits (const tree, const value_range_base *,
290 wide_int *, wide_int *);
291
292 extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *);
293 extern bool find_case_label_index (gswitch *, size_t, tree, size_t *);
294 extern bool overflow_comparison_p (tree_code, tree, tree, bool, tree *);
295 extern tree get_single_symbol (tree, bool *, tree *);
296 extern void maybe_set_nonzero_bits (edge, tree);
297 extern value_range_kind determine_value_range (tree, wide_int *, wide_int *);
298
299 /* Return TRUE if *VR includes the value zero. */
300
301 inline bool
302 range_includes_zero_p (const value_range_base *vr)
303 {
304 if (vr->undefined_p ())
305 return false;
306
307 if (vr->varying_p ())
308 return true;
309
310 return vr->may_contain_p (build_zero_cst (vr->type ()));
311 }
312
313 #endif /* GCC_TREE_VRP_H */