]>
Commit | Line | Data |
---|---|---|
c296f633 | 1 | /* Support routines for Value Range Propagation (VRP). |
8e8f6434 | 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. |
c296f633 | 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 | ||
b7e72cd7 | 20 | #ifndef GCC_TREE_VRP_H |
21 | #define GCC_TREE_VRP_H | |
22 | ||
be44111e | 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 | }; | |
c296f633 | 37 | |
a1054504 | 38 | |
c296f633 | 39 | /* Range of values that can be associated with an SSA_NAME after VRP |
40 | has executed. */ | |
a1054504 | 41 | class GTY((for_user)) value_range_base |
42 | { | |
43 | public: | |
44 | value_range_base (); | |
45 | value_range_base (value_range_kind, tree, tree); | |
46 | ||
47 | enum value_range_kind kind () const; | |
48 | tree min () const; | |
49 | tree max () const; | |
50 | ||
51 | /* Types of value ranges. */ | |
5a780b31 | 52 | bool symbolic_p () const; |
53 | bool constant_p () const; | |
a1054504 | 54 | bool undefined_p () const; |
55 | bool varying_p () const; | |
5a780b31 | 56 | void set_varying (); |
57 | void set_undefined (); | |
a1054504 | 58 | |
59 | void union_ (const value_range_base *); | |
60 | ||
61 | bool ignore_equivs_equal_p (const value_range_base &) const; | |
62 | ||
a1054504 | 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); | |
5a780b31 | 67 | bool zero_p () const; |
68 | bool singleton_p (tree *result = NULL) const; | |
a1054504 | 69 | |
70 | void dump (FILE *) const; | |
5a780b31 | 71 | void dump () const; |
a1054504 | 72 | |
73 | protected: | |
74 | void set (value_range_kind, tree, tree); | |
75 | void check (); | |
76 | ||
77 | enum value_range_kind m_kind; | |
78 | ||
79 | tree m_min; | |
80 | tree m_max; | |
81 | ||
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 *); | |
90 | }; | |
91 | ||
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 | |
c296f633 | 95 | { |
be44111e | 96 | public: |
97 | value_range (); | |
a1054504 | 98 | value_range (const value_range_base &); |
be44111e | 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 *); | |
105 | ||
106 | /* Types of value ranges. */ | |
be44111e | 107 | void set_undefined (); |
108 | void set_varying (); | |
109 | ||
110 | /* Equivalence bitmap methods. */ | |
111 | bitmap equiv () const; | |
112 | void equiv_clear (); | |
113 | void equiv_add (const_tree, const value_range *, bitmap_obstack * = NULL); | |
114 | ||
115 | /* Misc methods. */ | |
be44111e | 116 | void deep_copy (const value_range *); |
be44111e | 117 | void set_and_canonicalize (enum value_range_kind, tree, tree, bitmap); |
118 | void dump (FILE *) const; | |
119 | void dump () const; | |
120 | ||
be44111e | 121 | private: |
122 | void set (value_range_kind, tree, tree, bitmap); | |
a1054504 | 123 | void set_equiv (bitmap); |
be44111e | 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 *); | |
128 | ||
be44111e | 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; | |
132 | }; | |
c296f633 | 133 | |
be44111e | 134 | inline |
a1054504 | 135 | value_range_base::value_range_base () |
be44111e | 136 | { |
137 | m_kind = VR_UNDEFINED; | |
138 | m_min = m_max = NULL; | |
a1054504 | 139 | } |
140 | ||
141 | inline | |
142 | value_range::value_range () | |
143 | : value_range_base () | |
144 | { | |
be44111e | 145 | m_equiv = NULL; |
146 | } | |
c296f633 | 147 | |
be44111e | 148 | /* Return the kind of this range. */ |
c296f633 | 149 | |
be44111e | 150 | inline value_range_kind |
a1054504 | 151 | value_range_base::kind () const |
be44111e | 152 | { |
153 | return m_kind; | |
154 | } | |
c296f633 | 155 | |
be44111e | 156 | inline bitmap |
157 | value_range::equiv () const | |
158 | { | |
159 | return m_equiv; | |
160 | } | |
c296f633 | 161 | |
be44111e | 162 | /* Return the lower bound. */ |
11822fb2 | 163 | |
be44111e | 164 | inline tree |
a1054504 | 165 | value_range_base::min () const |
be44111e | 166 | { |
167 | return m_min; | |
168 | } | |
169 | ||
170 | /* Return the upper bound. */ | |
171 | ||
172 | inline tree | |
a1054504 | 173 | value_range_base::max () const |
be44111e | 174 | { |
175 | return m_max; | |
176 | } | |
177 | ||
178 | /* Return TRUE if range spans the entire possible domain. */ | |
179 | ||
180 | inline bool | |
a1054504 | 181 | value_range_base::varying_p () const |
be44111e | 182 | { |
183 | return m_kind == VR_VARYING; | |
184 | } | |
185 | ||
186 | /* Return TRUE if range is undefined (essentially the empty set). */ | |
187 | ||
188 | inline bool | |
a1054504 | 189 | value_range_base::undefined_p () const |
be44111e | 190 | { |
191 | return m_kind == VR_UNDEFINED; | |
192 | } | |
193 | ||
194 | /* Return TRUE if range is the constant zero. */ | |
195 | ||
196 | inline bool | |
5a780b31 | 197 | value_range_base::zero_p () const |
be44111e | 198 | { |
199 | return (m_kind == VR_RANGE | |
200 | && integer_zerop (m_min) | |
201 | && integer_zerop (m_max)); | |
202 | } | |
c296f633 | 203 | |
c296f633 | 204 | extern void dump_value_range (FILE *, const value_range *); |
5a780b31 | 205 | extern void dump_value_range (FILE *, const value_range_base *); |
9c015ccf | 206 | |
207 | struct assert_info | |
208 | { | |
209 | /* Predicate code for the ASSERT_EXPR. Must be COMPARISON_CLASS_P. */ | |
210 | enum tree_code comp_code; | |
211 | ||
212 | /* Name to register the assert for. */ | |
213 | tree name; | |
214 | ||
215 | /* Value being compared against. */ | |
216 | tree val; | |
217 | ||
218 | /* Expression to compare. */ | |
219 | tree expr; | |
220 | }; | |
221 | ||
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 *); | |
a1054504 | 225 | extern bool range_includes_zero_p (const value_range_base *); |
9c015ccf | 226 | extern bool infer_value_range (gimple *, tree, tree_code *, tree *); |
227 | ||
94d86adc | 228 | extern void set_value_range_to_nonnull (value_range *, tree); |
5a780b31 | 229 | extern void set_value_range_to_null (value_range *, tree); |
be44111e | 230 | extern void set_value_range (value_range *, enum value_range_kind, tree, |
94d86adc | 231 | tree, bitmap); |
5a780b31 | 232 | extern void set_value_range_to_value (value_range *, tree, bitmap); |
233 | ||
94d86adc | 234 | extern bool vrp_bitmap_equal_p (const_bitmap, const_bitmap); |
5a780b31 | 235 | |
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 *); | |
239 | ||
94d86adc | 240 | extern int compare_values (tree, tree); |
241 | extern int compare_values_warnv (tree, tree, bool *); | |
5a780b31 | 242 | extern int operand_less_p (tree, tree); |
94d86adc | 243 | extern bool vrp_val_is_min (const_tree); |
244 | extern bool vrp_val_is_max (const_tree); | |
5a780b31 | 245 | extern int value_inside_range (tree, tree, tree); |
246 | ||
247 | extern tree vrp_val_min (const_tree); | |
248 | extern tree vrp_val_max (const_tree); | |
249 | ||
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); | |
94d86adc | 255 | extern void extract_range_from_binary_expr_1 (value_range *, enum tree_code, |
3278521b | 256 | tree, const value_range *, |
257 | const value_range *); | |
5a780b31 | 258 | |
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 *); | |
264 | ||
94d86adc | 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 *); | |
94d86adc | 267 | extern bool overflow_comparison_p (tree_code, tree, tree, bool, tree *); |
94d86adc | 268 | extern tree get_single_symbol (tree, bool *, tree *); |
dd435793 | 269 | extern void maybe_set_nonzero_bits (edge, tree); |
be44111e | 270 | extern value_range_kind determine_value_range (tree, wide_int *, wide_int *); |
5a780b31 | 271 | |
b7e72cd7 | 272 | #endif /* GCC_TREE_VRP_H */ |