1 /* Support routines for Value Range Propagation (VRP).
2 Copyright (C) 2016-2019 Free Software Foundation, Inc.
4 This file is part of GCC.
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)
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.
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/>. */
20 #ifndef GCC_TREE_VRP_H
21 #define GCC_TREE_VRP_H
23 /* Types of value ranges. */
28 /* Range spans the entire domain. */
30 /* Range is [MIN, MAX]. */
32 /* Range is ~[MIN, MAX]. */
34 /* Range is a nice guy. */
39 /* Range of values that can be associated with an SSA_NAME after VRP
41 class GTY((for_user
)) value_range_base
45 value_range_base (value_range_kind
, tree
, tree
);
47 void set (value_range_kind
, tree
, tree
);
49 void set_nonzero (tree
);
52 enum value_range_kind
kind () const;
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 (tree type
);
62 void set_undefined ();
64 void union_ (const value_range_base
*);
65 void intersect (const value_range_base
*);
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;
73 bool may_contain_p (tree
) const;
75 bool nonzero_p () const;
76 bool singleton_p (tree
*result
= NULL
) const;
77 void dump (FILE *) const;
80 static bool supports_type_p (tree
);
81 value_range_base
normalize_symbolics () const;
85 static value_range_base
union_helper (const value_range_base
*,
86 const value_range_base
*);
87 static value_range_base
intersect_helper (const value_range_base
*,
88 const value_range_base
*);
90 enum value_range_kind m_kind
;
95 friend void gt_ggc_mx_value_range_base (void *);
96 friend void gt_pch_p_16value_range_base (void *, void *,
97 gt_pointer_operator
, void *);
98 friend void gt_pch_nx_value_range_base (void *);
99 friend void gt_ggc_mx (value_range_base
&);
100 friend void gt_ggc_mx (value_range_base
*&);
101 friend void gt_pch_nx (value_range_base
&);
102 friend void gt_pch_nx (value_range_base
*, gt_pointer_operator
, void *);
105 int value_inside_range (tree
) const;
108 /* Note value_range cannot currently be used with GC memory, only
109 value_range_base is fully set up for this. */
110 class GTY((user
)) value_range
: public value_range_base
114 value_range (const value_range_base
&);
115 /* Deep-copies equiv bitmap argument. */
116 value_range (value_range_kind
, tree
, tree
, bitmap
= NULL
);
118 /* Shallow-copies equiv bitmap. */
119 value_range (const value_range
&) /* = delete */;
120 /* Shallow-copies equiv bitmap. */
121 value_range
& operator=(const value_range
&) /* = delete */;
123 /* Move equiv bitmap from source range. */
124 void move (value_range
*);
126 /* Leaves equiv bitmap alone. */
127 void update (value_range_kind
, tree
, tree
);
128 /* Deep-copies equiv bitmap argument. */
129 void set (value_range_kind
, tree
, tree
, bitmap
= NULL
);
132 bool operator== (const value_range
&) const /* = delete */;
133 bool operator!= (const value_range
&) const /* = delete */;
134 void intersect (const value_range
*);
135 void union_ (const value_range
*);
136 bool equal_p (const value_range
&, bool ignore_equivs
) const;
138 /* Types of value ranges. */
139 void set_undefined ();
140 void set_varying (tree
);
142 /* Equivalence bitmap methods. */
143 bitmap
equiv () const;
145 void equiv_add (const_tree
, const value_range
*, bitmap_obstack
* = NULL
);
148 void deep_copy (const value_range
*);
149 void dump (FILE *) const;
153 /* Deep-copies bitmap argument. */
154 void set_equiv (bitmap
);
157 /* Set of SSA names whose value ranges are equivalent to this one.
158 This set is only valid when TYPE is VR_RANGE or VR_ANTI_RANGE. */
163 value_range_base::value_range_base ()
165 m_kind
= VR_UNDEFINED
;
166 m_min
= m_max
= NULL
;
170 value_range::value_range ()
171 : value_range_base ()
176 /* Return the kind of this range. */
178 inline value_range_kind
179 value_range_base::kind () const
185 value_range::equiv () const
190 /* Return the lower bound. */
193 value_range_base::min () const
198 /* Return the upper bound. */
201 value_range_base::max () const
206 /* Return TRUE if range spans the entire possible domain. */
209 value_range_base::varying_p () const
211 return m_kind
== VR_VARYING
;
214 /* Return TRUE if range is undefined (essentially the empty set). */
217 value_range_base::undefined_p () const
219 return m_kind
== VR_UNDEFINED
;
222 /* Return TRUE if range is the constant zero. */
225 value_range_base::zero_p () const
227 return (m_kind
== VR_RANGE
228 && integer_zerop (m_min
)
229 && integer_zerop (m_max
));
232 /* Return TRUE if range is nonzero. */
235 value_range_base::nonzero_p () const
237 return (m_kind
== VR_ANTI_RANGE
238 && integer_zerop (m_min
)
239 && integer_zerop (m_max
));
242 extern void dump_value_range (FILE *, const value_range
*);
243 extern void dump_value_range (FILE *, const value_range_base
*);
247 /* Predicate code for the ASSERT_EXPR. Must be COMPARISON_CLASS_P. */
248 enum tree_code comp_code
;
250 /* Name to register the assert for. */
253 /* Value being compared against. */
256 /* Expression to compare. */
260 // Return true if TYPE is a valid type for value_range to operate on.
261 // Otherwise return FALSE.
264 value_range_base::supports_type_p (tree type
)
266 if (type
&& (INTEGRAL_TYPE_P (type
) || POINTER_TYPE_P (type
)))
271 extern void register_edge_assert_for (tree
, edge
, enum tree_code
,
272 tree
, tree
, vec
<assert_info
> &);
273 extern bool stmt_interesting_for_vrp (gimple
*);
274 extern bool infer_value_range (gimple
*, tree
, tree_code
*, tree
*);
276 extern bool vrp_bitmap_equal_p (const_bitmap
, const_bitmap
);
278 extern bool range_int_cst_p (const value_range_base
*);
279 extern bool range_int_cst_singleton_p (const value_range_base
*);
281 extern int compare_values (tree
, tree
);
282 extern int compare_values_warnv (tree
, tree
, bool *);
283 extern int operand_less_p (tree
, tree
);
284 extern bool vrp_val_is_min (const_tree
);
285 extern bool vrp_val_is_max (const_tree
);
287 extern tree
vrp_val_min (const_tree
, bool handle_pointers
= false);
288 extern tree
vrp_val_max (const_tree
, bool handle_pointers
= false);
290 extern void extract_range_from_unary_expr (value_range_base
*vr
,
293 const value_range_base
*vr0_
,
295 extern void extract_range_from_binary_expr (value_range_base
*,
297 tree
, const value_range_base
*,
298 const value_range_base
*);
300 extern bool vrp_operand_equal_p (const_tree
, const_tree
);
301 extern enum value_range_kind intersect_range_with_nonzero_bits
302 (enum value_range_kind
, wide_int
*, wide_int
*, const wide_int
&, signop
);
303 extern bool vrp_set_zero_nonzero_bits (const tree
, const value_range_base
*,
304 wide_int
*, wide_int
*);
306 extern bool find_case_label_range (gswitch
*, tree
, tree
, size_t *, size_t *);
307 extern bool find_case_label_index (gswitch
*, size_t, tree
, size_t *);
308 extern bool overflow_comparison_p (tree_code
, tree
, tree
, bool, tree
*);
309 extern tree
get_single_symbol (tree
, bool *, tree
*);
310 extern void maybe_set_nonzero_bits (edge
, tree
);
311 extern value_range_kind
determine_value_range (tree
, wide_int
*, wide_int
*);
313 /* Return TRUE if *VR includes the value zero. */
316 range_includes_zero_p (const value_range_base
*vr
)
318 if (vr
->undefined_p ())
321 if (vr
->varying_p ())
324 return vr
->may_contain_p (build_zero_cst (vr
->type ()));
327 #endif /* GCC_TREE_VRP_H */