111
|
1 /* Support routines for Value Range Propagation (VRP).
|
131
|
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
|
111
|
3
|
|
4 This file is part of GCC.
|
|
5
|
|
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.
|
|
10
|
|
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.
|
|
15
|
|
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/>. */
|
|
19
|
|
20 #ifndef GCC_TREE_VRP_H
|
|
21 #define GCC_TREE_VRP_H
|
|
22
|
131
|
23 /* Types of value ranges. */
|
|
24 enum 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 };
|
111
|
37
|
|
38 /* Range of values that can be associated with an SSA_NAME after VRP
|
|
39 has executed. */
|
131
|
40 class GTY((for_user)) value_range
|
111
|
41 {
|
131
|
42 public:
|
|
43 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 *);
|
111
|
50
|
131
|
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 ();
|
|
57 void set_varying ();
|
|
58
|
|
59 /* Equivalence bitmap methods. */
|
|
60 bitmap equiv () const;
|
|
61 void equiv_clear ();
|
|
62 void equiv_add (const_tree, const value_range *, bitmap_obstack * = NULL);
|
111
|
63
|
131
|
64 /* Misc methods. */
|
|
65 tree type () const;
|
|
66 bool null_p () const;
|
|
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;
|
|
73 void dump () const;
|
111
|
74
|
131
|
75 enum value_range_kind kind () const;
|
|
76 tree min () const;
|
|
77 tree max () const;
|
111
|
78
|
131
|
79 private:
|
|
80 void set (value_range_kind, tree, tree, bitmap);
|
|
81 void check ();
|
|
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 *);
|
|
85
|
|
86 enum value_range_kind m_kind;
|
|
87 public:
|
|
88 /* These should be private, but GTY is a piece of crap. */
|
|
89 tree m_min;
|
|
90 tree m_max;
|
111
|
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. */
|
131
|
93 bitmap m_equiv;
|
111
|
94 };
|
|
95
|
131
|
96 inline
|
|
97 value_range::value_range ()
|
|
98 {
|
|
99 m_kind = VR_UNDEFINED;
|
|
100 m_min = m_max = NULL;
|
|
101 m_equiv = NULL;
|
|
102 }
|
|
103
|
|
104 /* Return the kind of this range. */
|
|
105
|
|
106 inline value_range_kind
|
|
107 value_range::kind () const
|
|
108 {
|
|
109 return m_kind;
|
|
110 }
|
|
111
|
|
112 inline bitmap
|
|
113 value_range::equiv () const
|
|
114 {
|
|
115 return m_equiv;
|
|
116 }
|
|
117
|
|
118 /* Return the lower bound. */
|
|
119
|
|
120 inline tree
|
|
121 value_range::min () const
|
|
122 {
|
|
123 return m_min;
|
|
124 }
|
|
125
|
|
126 /* Return the upper bound. */
|
|
127
|
|
128 inline tree
|
|
129 value_range::max () const
|
|
130 {
|
|
131 return m_max;
|
|
132 }
|
|
133
|
|
134 /* Return TRUE if range spans the entire possible domain. */
|
|
135
|
|
136 inline bool
|
|
137 value_range::varying_p () const
|
|
138 {
|
|
139 return m_kind == VR_VARYING;
|
|
140 }
|
|
141
|
|
142 /* Return TRUE if range is undefined (essentially the empty set). */
|
|
143
|
|
144 inline bool
|
|
145 value_range::undefined_p () const
|
|
146 {
|
|
147 return m_kind == VR_UNDEFINED;
|
|
148 }
|
|
149
|
|
150 /* Return TRUE if range is the constant zero. */
|
|
151
|
|
152 inline bool
|
|
153 value_range::null_p () const
|
|
154 {
|
|
155 return (m_kind == VR_RANGE
|
|
156 && integer_zerop (m_min)
|
|
157 && integer_zerop (m_max));
|
|
158 }
|
|
159
|
111
|
160 extern void dump_value_range (FILE *, const value_range *);
|
|
161 extern void extract_range_from_unary_expr (value_range *vr,
|
|
162 enum tree_code code,
|
|
163 tree type,
|
131
|
164 const value_range *vr0_,
|
111
|
165 tree op0_type);
|
|
166
|
131
|
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);
|
|
170
|
|
171 struct assert_info
|
|
172 {
|
|
173 /* Predicate code for the ASSERT_EXPR. Must be COMPARISON_CLASS_P. */
|
|
174 enum tree_code comp_code;
|
|
175
|
|
176 /* Name to register the assert for. */
|
|
177 tree name;
|
|
178
|
|
179 /* Value being compared against. */
|
|
180 tree val;
|
|
181
|
|
182 /* Expression to compare. */
|
|
183 tree expr;
|
|
184 };
|
|
185
|
|
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 *);
|
|
192
|
|
193 extern void set_value_range_to_nonnull (value_range *, tree);
|
|
194 extern void set_value_range (value_range *, enum value_range_kind, tree,
|
|
195 tree, bitmap);
|
|
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 *);
|
111
|
221 #endif /* GCC_TREE_VRP_H */
|