Fix error when selecting number of memory pools
[official-gcc.git] / gcc / tree-vrp.h
blob287860399c4d19521cd9ab6793b085d06ac1c3c5
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 void set (value_range_kind, tree, tree);
48 void set (tree);
49 void set_nonnull (tree);
50 void set_null (tree);
52 enum value_range_kind kind () const;
53 tree min () const;
54 tree max () 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 ();
62 void set_undefined ();
64 void union_ (const value_range_base *);
66 bool ignore_equivs_equal_p (const value_range_base &) const;
68 /* Misc methods. */
69 tree type () const;
70 bool may_contain_p (tree) const;
71 void set_and_canonicalize (enum value_range_kind, tree, tree);
72 bool zero_p () const;
73 bool singleton_p (tree *result = NULL) const;
74 void dump (FILE *) const;
76 protected:
77 void check ();
78 static value_range_base union_helper (const value_range_base *,
79 const value_range_base *);
81 enum value_range_kind m_kind;
83 tree m_min;
84 tree m_max;
86 friend void gt_ggc_mx_value_range_base (void *);
87 friend void gt_pch_p_16value_range_base (void *, void *,
88 gt_pointer_operator, void *);
89 friend void gt_pch_nx_value_range_base (void *);
90 friend void gt_ggc_mx (value_range_base &);
91 friend void gt_ggc_mx (value_range_base *&);
92 friend void gt_pch_nx (value_range_base &);
93 friend void gt_pch_nx (value_range_base *, gt_pointer_operator, void *);
96 /* Note value_range cannot currently be used with GC memory, only
97 value_range_base is fully set up for this. */
98 class GTY((user)) value_range : public value_range_base
100 public:
101 value_range ();
102 value_range (const value_range_base &);
103 /* Deep-copies equiv bitmap argument. */
104 value_range (value_range_kind, tree, tree, bitmap = NULL);
106 /* Shallow-copies equiv bitmap. */
107 value_range (const value_range &) /* = delete */;
108 /* Shallow-copies equiv bitmap. */
109 value_range& operator=(const value_range&) /* = delete */;
111 /* Move equiv bitmap from source range. */
112 void move (value_range *);
114 /* Leaves equiv bitmap alone. */
115 void update (value_range_kind, tree, tree);
116 /* Deep-copies equiv bitmap argument. */
117 void set (value_range_kind, tree, tree, bitmap = NULL);
118 void set (tree);
119 void set_nonnull (tree);
120 void set_null (tree);
122 bool operator== (const value_range &) const;
123 bool operator!= (const value_range &) const;
124 void intersect (const value_range *);
125 void union_ (const value_range *);
127 /* Types of value ranges. */
128 void set_undefined ();
129 void set_varying ();
131 /* Equivalence bitmap methods. */
132 bitmap equiv () const;
133 void equiv_clear ();
134 void equiv_add (const_tree, const value_range *, bitmap_obstack * = NULL);
136 /* Misc methods. */
137 void deep_copy (const value_range *);
138 void set_and_canonicalize (enum value_range_kind, tree, tree, bitmap = NULL);
139 void dump (FILE *) const;
141 private:
142 /* Deep-copies bitmap argument. */
143 void set_equiv (bitmap);
144 void check ();
145 bool equal_p (const value_range &, bool ignore_equivs) const;
146 void intersect_helper (value_range *, const value_range *);
148 /* Set of SSA names whose value ranges are equivalent to this one.
149 This set is only valid when TYPE is VR_RANGE or VR_ANTI_RANGE. */
150 bitmap m_equiv;
153 inline
154 value_range_base::value_range_base ()
156 m_kind = VR_UNDEFINED;
157 m_min = m_max = NULL;
160 inline
161 value_range::value_range ()
162 : value_range_base ()
164 m_equiv = NULL;
167 /* Return the kind of this range. */
169 inline value_range_kind
170 value_range_base::kind () const
172 return m_kind;
175 inline bitmap
176 value_range::equiv () const
178 return m_equiv;
181 /* Return the lower bound. */
183 inline tree
184 value_range_base::min () const
186 return m_min;
189 /* Return the upper bound. */
191 inline tree
192 value_range_base::max () const
194 return m_max;
197 /* Return TRUE if range spans the entire possible domain. */
199 inline bool
200 value_range_base::varying_p () const
202 return m_kind == VR_VARYING;
205 /* Return TRUE if range is undefined (essentially the empty set). */
207 inline bool
208 value_range_base::undefined_p () const
210 return m_kind == VR_UNDEFINED;
213 /* Return TRUE if range is the constant zero. */
215 inline bool
216 value_range_base::zero_p () const
218 return (m_kind == VR_RANGE
219 && integer_zerop (m_min)
220 && integer_zerop (m_max));
223 extern void dump_value_range (FILE *, const value_range *);
224 extern void dump_value_range (FILE *, const value_range_base *);
226 struct assert_info
228 /* Predicate code for the ASSERT_EXPR. Must be COMPARISON_CLASS_P. */
229 enum tree_code comp_code;
231 /* Name to register the assert for. */
232 tree name;
234 /* Value being compared against. */
235 tree val;
237 /* Expression to compare. */
238 tree expr;
241 extern void register_edge_assert_for (tree, edge, enum tree_code,
242 tree, tree, vec<assert_info> &);
243 extern bool stmt_interesting_for_vrp (gimple *);
244 extern bool range_includes_zero_p (const value_range_base *);
245 extern bool infer_value_range (gimple *, tree, tree_code *, tree *);
247 extern bool vrp_bitmap_equal_p (const_bitmap, const_bitmap);
249 extern tree value_range_constant_singleton (const value_range_base *);
250 extern bool range_int_cst_p (const value_range_base *);
251 extern bool range_int_cst_singleton_p (const value_range_base *);
253 extern int compare_values (tree, tree);
254 extern int compare_values_warnv (tree, tree, bool *);
255 extern int operand_less_p (tree, tree);
256 extern bool vrp_val_is_min (const_tree);
257 extern bool vrp_val_is_max (const_tree);
258 extern int value_inside_range (tree, tree, tree);
260 extern tree vrp_val_min (const_tree);
261 extern tree vrp_val_max (const_tree);
263 extern void extract_range_from_unary_expr (value_range_base *vr,
264 enum tree_code code,
265 tree type,
266 const value_range_base *vr0_,
267 tree op0_type);
268 extern void extract_range_from_binary_expr (value_range_base *,
269 enum tree_code,
270 tree, const value_range_base *,
271 const value_range_base *);
273 extern bool vrp_operand_equal_p (const_tree, const_tree);
274 extern enum value_range_kind intersect_range_with_nonzero_bits
275 (enum value_range_kind, wide_int *, wide_int *, const wide_int &, signop);
276 extern bool vrp_set_zero_nonzero_bits (const tree, const value_range_base *,
277 wide_int *, wide_int *);
279 extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *);
280 extern bool find_case_label_index (gswitch *, size_t, tree, size_t *);
281 extern bool overflow_comparison_p (tree_code, tree, tree, bool, tree *);
282 extern tree get_single_symbol (tree, bool *, tree *);
283 extern void maybe_set_nonzero_bits (edge, tree);
284 extern value_range_kind determine_value_range (tree, wide_int *, wide_int *);
286 #endif /* GCC_TREE_VRP_H */