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