2018-11-12 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / tree-vrp.h
blob8130cb85f278dbf1e761f5a7157779c11eb3e2d7
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)
9 any later version.
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. */
24 enum value_range_kind
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
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
43 public:
44 value_range_base ();
45 value_range_base (value_range_kind, tree, tree);
47 enum value_range_kind kind () const;
48 tree min () const;
49 tree max () const;
51 /* Types of value ranges. */
52 bool symbolic_p () const;
53 bool constant_p () const;
54 bool undefined_p () const;
55 bool varying_p () const;
56 void set_varying ();
57 void set_undefined ();
59 void union_ (const value_range_base *);
61 bool ignore_equivs_equal_p (const value_range_base &) const;
63 /* Misc methods. */
64 tree type () const;
65 bool may_contain_p (tree) const;
66 void set_and_canonicalize (enum value_range_kind, tree, tree);
67 bool zero_p () const;
68 bool singleton_p (tree *result = NULL) const;
70 void dump (FILE *) const;
71 void dump () const;
73 protected:
74 void set (value_range_kind, tree, tree);
75 void check ();
77 enum value_range_kind m_kind;
79 tree m_min;
80 tree m_max;
82 friend void gt_ggc_mx_value_range_base (void *);
83 friend void gt_pch_p_16value_range_base (void *, void *,
84 gt_pointer_operator, void *);
85 friend void gt_pch_nx_value_range_base (void *);
86 friend void gt_ggc_mx (value_range_base &);
87 friend void gt_ggc_mx (value_range_base *&);
88 friend void gt_pch_nx (value_range_base &);
89 friend void gt_pch_nx (value_range_base *, gt_pointer_operator, void *);
92 /* Note value_range cannot currently be used with GC memory, only
93 value_range_base is fully set up for this. */
94 class GTY((user)) value_range : public value_range_base
96 public:
97 value_range ();
98 value_range (const value_range_base &);
99 value_range (value_range_kind, tree, tree, bitmap = NULL);
100 void update (value_range_kind, tree, tree);
101 bool operator== (const value_range &) const;
102 bool operator!= (const value_range &) const;
103 void intersect (const value_range *);
104 void union_ (const value_range *);
106 /* Types of value ranges. */
107 void set_undefined ();
108 void set_varying ();
110 /* Equivalence bitmap methods. */
111 bitmap equiv () const;
112 void equiv_clear ();
113 void equiv_add (const_tree, const value_range *, bitmap_obstack * = NULL);
115 /* Misc methods. */
116 void deep_copy (const value_range *);
117 void set_and_canonicalize (enum value_range_kind, tree, tree, bitmap);
118 void dump (FILE *) const;
119 void dump () const;
121 private:
122 void set (value_range_kind, tree, tree, bitmap);
123 void set_equiv (bitmap);
124 void check ();
125 bool equal_p (const value_range &, bool ignore_equivs) const;
126 void intersect_helper (value_range *, const value_range *);
127 void union_helper (value_range *, const value_range *);
129 /* Set of SSA names whose value ranges are equivalent to this one.
130 This set is only valid when TYPE is VR_RANGE or VR_ANTI_RANGE. */
131 bitmap m_equiv;
134 inline
135 value_range_base::value_range_base ()
137 m_kind = VR_UNDEFINED;
138 m_min = m_max = NULL;
141 inline
142 value_range::value_range ()
143 : value_range_base ()
145 m_equiv = NULL;
148 /* Return the kind of this range. */
150 inline value_range_kind
151 value_range_base::kind () const
153 return m_kind;
156 inline bitmap
157 value_range::equiv () const
159 return m_equiv;
162 /* Return the lower bound. */
164 inline tree
165 value_range_base::min () const
167 return m_min;
170 /* Return the upper bound. */
172 inline tree
173 value_range_base::max () const
175 return m_max;
178 /* Return TRUE if range spans the entire possible domain. */
180 inline bool
181 value_range_base::varying_p () const
183 return m_kind == VR_VARYING;
186 /* Return TRUE if range is undefined (essentially the empty set). */
188 inline bool
189 value_range_base::undefined_p () const
191 return m_kind == VR_UNDEFINED;
194 /* Return TRUE if range is the constant zero. */
196 inline bool
197 value_range_base::zero_p () const
199 return (m_kind == VR_RANGE
200 && integer_zerop (m_min)
201 && integer_zerop (m_max));
204 extern void dump_value_range (FILE *, const value_range *);
205 extern void dump_value_range (FILE *, const value_range_base *);
207 struct assert_info
209 /* Predicate code for the ASSERT_EXPR. Must be COMPARISON_CLASS_P. */
210 enum tree_code comp_code;
212 /* Name to register the assert for. */
213 tree name;
215 /* Value being compared against. */
216 tree val;
218 /* Expression to compare. */
219 tree expr;
222 extern void register_edge_assert_for (tree, edge, enum tree_code,
223 tree, tree, vec<assert_info> &);
224 extern bool stmt_interesting_for_vrp (gimple *);
225 extern bool range_includes_zero_p (const value_range_base *);
226 extern bool infer_value_range (gimple *, tree, tree_code *, tree *);
228 extern void set_value_range_to_nonnull (value_range *, tree);
229 extern void set_value_range_to_null (value_range *, tree);
230 extern void set_value_range (value_range *, enum value_range_kind, tree,
231 tree, bitmap);
232 extern void set_value_range_to_value (value_range *, tree, bitmap);
234 extern bool vrp_bitmap_equal_p (const_bitmap, const_bitmap);
236 extern tree value_range_constant_singleton (const value_range_base *);
237 extern bool range_int_cst_p (const value_range_base *);
238 extern bool range_int_cst_singleton_p (const value_range_base *);
240 extern int compare_values (tree, tree);
241 extern int compare_values_warnv (tree, tree, bool *);
242 extern int operand_less_p (tree, tree);
243 extern bool vrp_val_is_min (const_tree);
244 extern bool vrp_val_is_max (const_tree);
245 extern int value_inside_range (tree, tree, tree);
247 extern tree vrp_val_min (const_tree);
248 extern tree vrp_val_max (const_tree);
250 extern void extract_range_from_unary_expr (value_range *vr,
251 enum tree_code code,
252 tree type,
253 const value_range *vr0_,
254 tree op0_type);
255 extern void extract_range_from_binary_expr_1 (value_range *, enum tree_code,
256 tree, const value_range *,
257 const value_range *);
259 extern bool vrp_operand_equal_p (const_tree, const_tree);
260 extern enum value_range_kind intersect_range_with_nonzero_bits
261 (enum value_range_kind, wide_int *, wide_int *, const wide_int &, signop);
262 extern bool vrp_set_zero_nonzero_bits (const tree, const value_range_base *,
263 wide_int *, wide_int *);
265 extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *);
266 extern bool find_case_label_index (gswitch *, size_t, tree, size_t *);
267 extern bool overflow_comparison_p (tree_code, tree, tree, bool, tree *);
268 extern tree get_single_symbol (tree, bool *, tree *);
269 extern void maybe_set_nonzero_bits (edge, tree);
270 extern value_range_kind determine_value_range (tree, wide_int *, wide_int *);
272 #endif /* GCC_TREE_VRP_H */