1 /* Support routines for Value Range Propagation (VRP).
2 Copyright (C) 2016-2018 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. */
38 /* Range of values that can be associated with an SSA_NAME after VRP
40 class GTY((for_user
)) value_range
44 value_range (value_range_kind
, tree
, tree
, bitmap
= NULL
);
45 void update (value_range_kind
, tree
, tree
);
46 bool operator== (const value_range
&) const;
47 bool operator!= (const value_range
&) const;
48 void intersect (const value_range
*);
49 void union_ (const value_range
*);
51 /* Types of value ranges. */
52 bool undefined_p () const;
53 bool varying_p () const;
54 bool symbolic_p () const;
55 bool constant_p () const;
56 void set_undefined ();
59 /* Equivalence bitmap methods. */
60 bitmap
equiv () const;
62 void equiv_add (const_tree
, const value_range
*, bitmap_obstack
* = NULL
);
67 bool may_contain_p (tree
) const;
68 bool singleton_p (tree
*result
= NULL
) const;
69 void deep_copy (const value_range
*);
70 bool ignore_equivs_equal_p (const value_range
&) const;
71 void set_and_canonicalize (enum value_range_kind
, tree
, tree
, bitmap
);
72 void dump (FILE *) const;
75 enum value_range_kind
kind () const;
80 void set (value_range_kind
, tree
, tree
, bitmap
);
82 bool equal_p (const value_range
&, bool ignore_equivs
) const;
83 void intersect_helper (value_range
*, const value_range
*);
84 void union_helper (value_range
*, const value_range
*);
86 enum value_range_kind m_kind
;
88 /* These should be private, but GTY is a piece of crap. */
91 /* Set of SSA names whose value ranges are equivalent to this one.
92 This set is only valid when TYPE is VR_RANGE or VR_ANTI_RANGE. */
97 value_range::value_range ()
99 m_kind
= VR_UNDEFINED
;
100 m_min
= m_max
= NULL
;
104 /* Return the kind of this range. */
106 inline value_range_kind
107 value_range::kind () const
113 value_range::equiv () const
118 /* Return the lower bound. */
121 value_range::min () const
126 /* Return the upper bound. */
129 value_range::max () const
134 /* Return TRUE if range spans the entire possible domain. */
137 value_range::varying_p () const
139 return m_kind
== VR_VARYING
;
142 /* Return TRUE if range is undefined (essentially the empty set). */
145 value_range::undefined_p () const
147 return m_kind
== VR_UNDEFINED
;
150 /* Return TRUE if range is the constant zero. */
153 value_range::null_p () const
155 return (m_kind
== VR_RANGE
156 && integer_zerop (m_min
)
157 && integer_zerop (m_max
));
160 extern void dump_value_range (FILE *, const value_range
*);
161 extern void extract_range_from_unary_expr (value_range
*vr
,
164 const value_range
*vr0_
,
167 extern bool vrp_operand_equal_p (const_tree
, const_tree
);
168 extern enum value_range_kind intersect_range_with_nonzero_bits
169 (enum value_range_kind
, wide_int
*, wide_int
*, const wide_int
&, signop
);
173 /* Predicate code for the ASSERT_EXPR. Must be COMPARISON_CLASS_P. */
174 enum tree_code comp_code
;
176 /* Name to register the assert for. */
179 /* Value being compared against. */
182 /* Expression to compare. */
186 extern void register_edge_assert_for (tree
, edge
, enum tree_code
,
187 tree
, tree
, vec
<assert_info
> &);
188 extern bool stmt_interesting_for_vrp (gimple
*);
189 extern void set_value_range_to_varying (value_range
*);
190 extern bool range_includes_zero_p (const value_range
*);
191 extern bool infer_value_range (gimple
*, tree
, tree_code
*, tree
*);
193 extern void set_value_range_to_nonnull (value_range
*, tree
);
194 extern void set_value_range (value_range
*, enum value_range_kind
, tree
,
196 extern bool vrp_bitmap_equal_p (const_bitmap
, const_bitmap
);
197 extern tree
value_range_constant_singleton (const value_range
*);
198 extern int compare_values (tree
, tree
);
199 extern int compare_values_warnv (tree
, tree
, bool *);
200 extern bool vrp_val_is_min (const_tree
);
201 extern bool vrp_val_is_max (const_tree
);
202 extern void set_value_range_to_value (value_range
*, tree
, bitmap
);
203 extern void extract_range_from_binary_expr_1 (value_range
*, enum tree_code
,
204 tree
, const value_range
*,
205 const value_range
*);
206 extern tree
vrp_val_min (const_tree
);
207 extern tree
vrp_val_max (const_tree
);
208 extern void set_value_range_to_null (value_range
*, tree
);
209 extern bool range_int_cst_p (const value_range
*);
210 extern int operand_less_p (tree
, tree
);
211 extern bool find_case_label_range (gswitch
*, tree
, tree
, size_t *, size_t *);
212 extern bool find_case_label_index (gswitch
*, size_t, tree
, size_t *);
213 extern bool vrp_set_zero_nonzero_bits (const tree
, const value_range
*,
214 wide_int
*, wide_int
*);
215 extern bool overflow_comparison_p (tree_code
, tree
, tree
, bool, tree
*);
216 extern bool range_int_cst_singleton_p (const value_range
*);
217 extern int value_inside_range (tree
, tree
, tree
);
218 extern tree
get_single_symbol (tree
, bool *, tree
*);
219 extern void maybe_set_nonzero_bits (edge
, tree
);
220 extern value_range_kind
determine_value_range (tree
, wide_int
*, wide_int
*);
221 #endif /* GCC_TREE_VRP_H */