Line data Source code
1 : /* Support routines for value ranges.
2 : Copyright (C) 2019-2026 Free Software Foundation, Inc.
3 : Contributed by Aldy Hernandez <aldyh@redhat.com> and
4 : Andrew Macleod <amacleod@redhat.com>.
5 :
6 : This file is part of GCC.
7 :
8 : GCC is free software; you can redistribute it and/or modify
9 : it under the terms of the GNU General Public License as published by
10 : the Free Software Foundation; either version 3, or (at your option)
11 : any later version.
12 :
13 : GCC is distributed in the hope that it will be useful,
14 : but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : GNU General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with GCC; see the file COPYING3. If not see
20 : <http://www.gnu.org/licenses/>. */
21 :
22 : #ifndef GCC_VALUE_RANGE_H
23 : #define GCC_VALUE_RANGE_H
24 :
25 : class irange;
26 :
27 : // Types of value ranges.
28 : enum value_range_kind
29 : {
30 : /* Empty range. */
31 : VR_UNDEFINED,
32 : /* Range spans the entire domain. */
33 : VR_VARYING,
34 : /* Range is [MIN, MAX]. */
35 : VR_RANGE,
36 : /* Range is ~[MIN, MAX]. */
37 : VR_ANTI_RANGE,
38 : /* Range is a NAN. */
39 : VR_NAN,
40 : /* Range is a nice guy. */
41 : VR_LAST
42 : };
43 :
44 : // Discriminator between different vrange types.
45 :
46 : enum value_range_discriminator
47 : {
48 : // Range holds an integer or pointer.
49 : VR_IRANGE,
50 : // Pointer range.
51 : VR_PRANGE,
52 : // Floating point range.
53 : VR_FRANGE,
54 : // Range holds an unsupported type.
55 : VR_UNKNOWN
56 : };
57 :
58 : // Abstract class for representing subsets of values for various
59 : // supported types, such as the possible values of a variable.
60 : //
61 : // There are subclasses for each of integer, floating point, and pointer
62 : // types, each with their own strategies for efficiently representing
63 : // subsets of values.
64 : //
65 : // For efficiency, we can't precisely represent any arbitrary subset
66 : // of values of a type (which could require 2^N bits for a type of size N)
67 : // Hence operations on the subclasses may introduce imprecision
68 : // due to over-approximating the possible subsets.
69 : //
70 : // To query what types ranger and the entire ecosystem can support,
71 : // use value_range::supports_type_p(tree type). This is a static
72 : // method available independently of any vrange object.
73 : //
74 : // To query what a given vrange variant can support, use:
75 : // irange::supports_p ()
76 : // frange::supports_p ()
77 : // etc
78 : //
79 : // To query what a range object can support, use:
80 : // void foo (vrange &v, irange &i, frange &f)
81 : // {
82 : // if (v.supports_type_p (type)) ...
83 : // if (i.supports_type_p (type)) ...
84 : // if (f.supports_type_p (type)) ...
85 : // }
86 :
87 : class vrange
88 : {
89 : template <typename T> friend bool is_a (vrange &);
90 : friend class value_range;
91 : friend void streamer_write_vrange (struct output_block *, const vrange &);
92 : friend class range_op_handler;
93 : public:
94 : virtual void accept (const class vrange_visitor &v) const = 0;
95 : virtual void set (tree, tree, value_range_kind = VR_RANGE) = 0;
96 : virtual tree type () const = 0;
97 : virtual bool supports_type_p (const_tree type) const = 0;
98 : virtual void set_varying (tree type) = 0;
99 : virtual void set_undefined () = 0;
100 : virtual bool union_ (const vrange &) = 0;
101 : virtual bool intersect (const vrange &) = 0;
102 : virtual bool singleton_p (tree *result = NULL) const = 0;
103 : virtual bool contains_p (tree cst) const = 0;
104 : virtual bool zero_p () const = 0;
105 : // True if val == 0 may hold for some value in the range; for a float
106 : // range that means +0.0 or -0.0.
107 : virtual bool contains_zero_p () const = 0;
108 : virtual void set_nonzero (tree type) = 0;
109 : virtual void set_zero (tree type) = 0;
110 : virtual void set_nonnegative (tree type) = 0;
111 : virtual bool fits_p (const vrange &r) const = 0;
112 6296743219 : virtual ~vrange () { }
113 : virtual tree lbound () const = 0;
114 : virtual tree ubound () const = 0;
115 : virtual void update_bitmask (const class irange_bitmask &);
116 : virtual irange_bitmask get_bitmask () const;
117 : wide_int get_nonzero_bits () const;
118 : void set_nonzero_bits (const wide_int &bits);
119 :
120 : bool varying_p () const;
121 : bool undefined_p () const;
122 : vrange& operator= (const vrange &);
123 : bool operator== (const vrange &) const;
124 14374526 : bool operator!= (const vrange &r) const { return !(*this == r); }
125 : void dump (FILE *) const;
126 0 : virtual void verify_range () const { }
127 : protected:
128 7856226291 : vrange (enum value_range_discriminator d) : m_discriminator (d) { }
129 : enum value_range_kind m_kind : 8;
130 : const enum value_range_discriminator m_discriminator : 4;
131 : };
132 :
133 : namespace inchash
134 : {
135 : extern void add_vrange (const vrange &, hash &, unsigned flags = 0);
136 : }
137 :
138 : // A pair of values representing the known bits of a value. Zero bits
139 : // in MASK cover constant values. Set bits in MASK cover unknown
140 : // values. VALUE are the known bits for the bits where MASK is zero,
141 : // and must be zero for the unknown bits where MASK is set (needed as an
142 : // optimization of union and intersect)
143 : // For example:
144 : // VALUE: [..., 0, 1, 0]
145 : // MASK: [..., 1, 0, 0]
146 : // ^ ^ ^
147 : // | | known bit: {0}
148 : // | known bit: {1}
149 : // unknown bit: {0, 1}
150 :
151 : class irange_bitmask
152 : {
153 : public:
154 7621898433 : irange_bitmask () { /* uninitialized */ }
155 85823234 : irange_bitmask (unsigned prec) { set_unknown (prec); }
156 : irange_bitmask (const wide_int &value, const wide_int &mask);
157 : irange_bitmask (tree type, const wide_int &min, const wide_int &max);
158 :
159 1820421229 : wide_int value () const { return m_value; }
160 2200857973 : wide_int mask () const { return m_mask; }
161 : void set_unknown (unsigned prec);
162 : bool unknown_p () const;
163 : unsigned get_precision () const;
164 : void union_ (const irange_bitmask &src);
165 : bool intersect (const irange_bitmask &src);
166 : bool operator== (const irange_bitmask &src) const;
167 4274704 : bool operator!= (const irange_bitmask &src) const { return !(*this == src); }
168 : void verify_mask () const;
169 : void dump (FILE *) const;
170 : bool range_from_mask (irange &r, tree type) const;
171 :
172 : bool member_p (const wide_int &val) const;
173 :
174 : // Convenience functions for nonzero bitmask compatibility.
175 : wide_int get_nonzero_bits () const;
176 : void set_nonzero_bits (const wide_int &bits);
177 : private:
178 : wide_int m_value;
179 : wide_int m_mask;
180 : };
181 :
182 : inline void
183 4441524946 : irange_bitmask::set_unknown (unsigned prec)
184 : {
185 4441524946 : m_value = wi::zero (prec);
186 4441524946 : m_mask = wi::minus_one (prec);
187 4441524946 : if (flag_checking)
188 4441511956 : verify_mask ();
189 4441524946 : }
190 :
191 : // Return TRUE if THIS does not have any meaningful information.
192 :
193 : inline bool
194 6210581528 : irange_bitmask::unknown_p () const
195 : {
196 4343721911 : return m_mask == -1;
197 : }
198 :
199 : inline
200 1333228105 : irange_bitmask::irange_bitmask (const wide_int &value, const wide_int &mask)
201 : {
202 1333228105 : m_value = value;
203 1333228105 : m_mask = mask;
204 1333228105 : if (flag_checking)
205 1333224452 : verify_mask ();
206 1333228105 : }
207 :
208 : inline unsigned
209 : irange_bitmask::get_precision () const
210 : {
211 : return m_mask.get_precision ();
212 : }
213 :
214 : // The following two functions are meant for backwards compatibility
215 : // with the nonzero bitmask. A cleared bit means the value must be 0.
216 : // A set bit means we have no information for the bit.
217 :
218 : // Return the nonzero bits.
219 : inline wide_int
220 45681602 : irange_bitmask::get_nonzero_bits () const
221 : {
222 45681602 : return m_value | m_mask;
223 : }
224 :
225 : // Set the bitmask to the nonzero bits in BITS.
226 : inline void
227 : irange_bitmask::set_nonzero_bits (const wide_int &bits)
228 : {
229 : m_value = wi::zero (bits.get_precision ());
230 : m_mask = bits;
231 : if (flag_checking)
232 : verify_mask ();
233 : }
234 :
235 : // Return TRUE if val could be a valid value with this bitmask.
236 :
237 : inline bool
238 311032472 : irange_bitmask::member_p (const wide_int &val) const
239 : {
240 311032472 : if (unknown_p ())
241 : return true;
242 37611187 : wide_int res = m_mask & val;
243 37611187 : if (m_value != 0)
244 1475598 : res |= ~m_mask & m_value;
245 37611187 : return res == val;
246 37611187 : }
247 :
248 : inline bool
249 1477383102 : irange_bitmask::operator== (const irange_bitmask &src) const
250 : {
251 1477383102 : bool unknown1 = unknown_p ();
252 1477383102 : bool unknown2 = src.unknown_p ();
253 1477383102 : if (unknown1 || unknown2)
254 1132752633 : return unknown1 == unknown2;
255 344630469 : return m_value == src.m_value && m_mask == src.m_mask;
256 : }
257 :
258 : inline void
259 22319890 : irange_bitmask::union_ (const irange_bitmask &src)
260 : {
261 22320476 : m_mask = (m_mask | src.m_mask) | (m_value ^ src.m_value);
262 22319890 : m_value = m_value & src.m_value;
263 22319890 : if (flag_checking)
264 22319890 : verify_mask ();
265 22319890 : }
266 :
267 : // Return FALSE if the bitmask intersection is undefined.
268 :
269 : inline bool
270 958390601 : irange_bitmask::intersect (const irange_bitmask &src)
271 : {
272 : // If we have two known bits that are incompatible, the resulting
273 : // bit and therefore entire range is undefined. Return FALSE.
274 1916921336 : if (wi::bit_and (~(m_mask | src.m_mask),
275 2875171803 : m_value ^ src.m_value) != 0)
276 : return false;
277 : else
278 : {
279 958336537 : m_mask = m_mask & src.m_mask;
280 958336537 : m_value = m_value | src.m_value;
281 : }
282 958336537 : if (flag_checking)
283 958333902 : verify_mask ();
284 : return true;
285 : }
286 :
287 : // A subset of possible values for an integer type, leaving
288 : // allocation of storage to subclasses.
289 :
290 12535834874 : class irange : public vrange
291 : {
292 : friend class irange_storage;
293 : friend class vrange_printer;
294 : public:
295 : // In-place setters.
296 : void set (tree type, const wide_int &, const wide_int &,
297 : value_range_kind = VR_RANGE);
298 : virtual void set_nonzero (tree type) override;
299 : virtual void set_zero (tree type) override;
300 : virtual void set_nonnegative (tree type) override;
301 : virtual void set_varying (tree type) override;
302 : virtual void set_undefined () override;
303 :
304 : // Range types.
305 : static bool supports_p (const_tree type);
306 : virtual bool supports_type_p (const_tree type) const override;
307 : virtual tree type () const override;
308 :
309 : // Iteration over sub-ranges.
310 : unsigned num_pairs () const;
311 : wide_int lower_bound (unsigned = 0) const;
312 : wide_int upper_bound (unsigned) const;
313 : wide_int upper_bound () const;
314 : virtual tree lbound () const override;
315 : virtual tree ubound () const override;
316 :
317 : // Predicates.
318 : virtual bool zero_p () const override;
319 : virtual bool contains_zero_p () const override;
320 : virtual bool singleton_p (tree *result = NULL) const override;
321 : bool singleton_p (wide_int &) const;
322 : bool contains_p (const wide_int &) const;
323 : bool nonnegative_p () const;
324 : bool nonpositive_p () const;
325 :
326 : // In-place operators.
327 : virtual bool union_ (const vrange &) override;
328 : virtual bool intersect (const vrange &) override;
329 : bool invert ();
330 :
331 : // Operator overloads.
332 : irange& operator= (const irange &);
333 : bool operator== (const irange &) const;
334 : bool operator!= (const irange &r) const { return !(*this == r); }
335 :
336 : // Misc methods.
337 : virtual bool fits_p (const vrange &r) const override;
338 : virtual void accept (const vrange_visitor &v) const override;
339 :
340 : virtual void update_bitmask (const class irange_bitmask &) override;
341 : virtual irange_bitmask get_bitmask () const override;
342 :
343 : virtual void verify_range () const override;
344 : protected:
345 : void maybe_resize (int needed);
346 : virtual void set (tree, tree, value_range_kind = VR_RANGE) override;
347 : virtual bool contains_p (tree cst) const override;
348 : irange (wide_int *, unsigned nranges, bool resizable);
349 :
350 : // In-place operators.
351 : bool irange_contains_p (const irange &) const;
352 : bool irange_single_pair_union (const irange &r);
353 :
354 : void normalize_kind ();
355 :
356 :
357 : // Hard limit on max ranges allowed.
358 : static const int HARD_MAX_RANGES = 255;
359 : private:
360 : bool varying_compatible_p () const;
361 : bool intersect_bitmask (const irange &r);
362 : bool union_bitmask (const irange &r);
363 : bool set_range_from_bitmask ();
364 : bool snap_subranges ();
365 : bool snap (const wide_int &, const wide_int &, wide_int &, wide_int &,
366 : bool &);
367 :
368 : bool intersect (const wide_int& lb, const wide_int& ub);
369 : bool union_append (const irange &r);
370 : unsigned char m_num_ranges;
371 : bool m_resizable;
372 : unsigned char m_max_ranges;
373 : tree m_type;
374 : irange_bitmask m_bitmask;
375 : protected:
376 : wide_int *m_base;
377 : };
378 :
379 : // Here we describe an irange with N pairs of ranges. The storage for
380 : // the pairs is embedded in the class as an array.
381 : //
382 : // If RESIZABLE is true, the storage will be resized on the heap when
383 : // the number of ranges needed goes past N up to a max of
384 : // HARD_MAX_RANGES. This new storage is freed upon destruction.
385 :
386 : template<unsigned N, bool RESIZABLE = false>
387 : class int_range final : public irange
388 : {
389 : public:
390 : int_range ();
391 : int_range (tree type, const wide_int &, const wide_int &,
392 : value_range_kind = VR_RANGE);
393 : int_range (tree type);
394 : int_range (const int_range &);
395 : int_range (const irange &);
396 : ~int_range () final override;
397 : int_range& operator= (const int_range &);
398 : protected:
399 : int_range (tree, tree, value_range_kind = VR_RANGE);
400 : private:
401 : wide_int m_ranges[N*2];
402 : };
403 :
404 : class prange final : public vrange
405 : {
406 : friend class prange_storage;
407 : friend class vrange_printer;
408 : public:
409 : prange ();
410 : prange (const prange &);
411 : prange (tree type);
412 : prange (tree type, const wide_int &, const wide_int &,
413 : value_range_kind = VR_RANGE);
414 : static bool supports_p (const_tree type);
415 : virtual bool supports_type_p (const_tree type) const final override;
416 : virtual void accept (const vrange_visitor &v) const final override;
417 : virtual void set_undefined () final override;
418 : virtual void set_varying (tree type) final override;
419 : virtual void set_nonzero (tree type) final override;
420 : virtual void set_zero (tree type) final override;
421 : virtual void set_nonnegative (tree type) final override;
422 : virtual bool contains_p (tree cst) const final override;
423 : virtual bool fits_p (const vrange &v) const final override;
424 : virtual bool singleton_p (tree *result = NULL) const final override;
425 : virtual bool zero_p () const final override;
426 : virtual bool contains_zero_p () const final override;
427 : virtual void set (tree, tree, value_range_kind = VR_RANGE) final override;
428 : virtual tree type () const final override;
429 : virtual bool union_ (const vrange &v) final override;
430 : virtual bool intersect (const vrange &v) final override;
431 : virtual tree lbound () const final override;
432 : virtual tree ubound () const final override;
433 :
434 : prange& operator= (const prange &);
435 : bool operator== (const prange &) const;
436 : void set (tree type, const wide_int &, const wide_int &,
437 : value_range_kind = VR_RANGE);
438 : bool invert ();
439 : bool contains_p (const wide_int &) const;
440 : wide_int lower_bound () const;
441 : wide_int upper_bound () const;
442 : virtual void verify_range () const final override;
443 : irange_bitmask get_bitmask () const final override;
444 : void update_bitmask (const irange_bitmask &) final override;
445 :
446 : // prange interface to address information.
447 : // It can be known to be a particular address, or exclude that address.
448 : // This represents both sides of a conditional. ie:
449 : // if (p == &foo)
450 : // // p known to be foo.
451 : // else
452 : // // p excludes foo.
453 :
454 : // The address is is_gimple_min_invariant, which is relative to the
455 : // current function -- it is NOT is_gimple_ip_invariant, and may name a
456 : // local. Any consumer crossing a function boundary must re-check.
457 :
458 : // Set this address to the same as R, if any.
459 : void set_addr (const prange &r);
460 : void set_addr (tree addr, bool known_p = true);
461 :
462 : void set_addr_unknown ();
463 : bool addr_unknown_p () const;
464 :
465 : // If addr is local to a function, clear it.
466 : bool clear_function_local_addr ();
467 :
468 : // Return expression or NULL_TREE for known or excluded.
469 : tree addr_known () const;
470 : tree addr_excluded () const;
471 :
472 : // Return true if THIS and R are known to be the same address.
473 : bool addr_same_known_p (const prange &r) const;
474 : // Return true if THIS and R both exclude the same address.
475 : bool addr_same_excluded_p (const prange &r) const;
476 :
477 : // If either known or excluded, invert and return TRUE.
478 : bool addr_invert ();
479 : // Return true if THIS and R refer to the same address, and one is inverted
480 : // from the other, Ie, both known and excluded
481 : bool addr_inverted_p (const prange &r) const;
482 :
483 : // These routines decompose addr to its component parts for a known address.
484 :
485 : // addr_base () - object/allocation the pointer refers into.
486 : tree addr_base () const;
487 : // addr_offset () - possible byte offset range from BASE.
488 : void addr_offset (irange &) const;
489 : // addr_size () - possible size range of the referenced object.
490 : void addr_size (irange &) const;
491 :
492 : protected:
493 : bool varying_compatible_p () const;
494 :
495 : tree m_type;
496 : wide_int m_min;
497 : wide_int m_max;
498 : irange_bitmask m_bitmask;
499 :
500 : // A prange can be known to be a particular address, or known to exclude
501 : // one.
502 : tree m_addr; // Address referred to.
503 : bool m_known_p; // Is it known (TRUE), or excluded (FALSE).
504 : // Return TRUE if P has the same address fields as THIS.
505 : bool addr_equal_p (const class prange &p) const;
506 : };
507 :
508 : // Unsupported temporaries may be created by ranger before it's known
509 : // they're unsupported, or by vr_values::get_value_range.
510 :
511 0 : class unsupported_range : public vrange
512 : {
513 : public:
514 74987030 : unsupported_range ()
515 74987030 : : vrange (VR_UNKNOWN)
516 : {
517 74987030 : set_undefined ();
518 : }
519 656269 : unsupported_range (const unsupported_range &src)
520 656269 : : vrange (VR_UNKNOWN)
521 : {
522 656269 : unsupported_range::operator= (src);
523 : }
524 : void set (tree min, tree, value_range_kind = VR_RANGE) final override;
525 : tree type () const final override;
526 : bool supports_type_p (const_tree) const final override;
527 : void set_varying (tree) final override;
528 : void set_undefined () final override;
529 : void accept (const vrange_visitor &v) const final override;
530 : bool union_ (const vrange &r) final override;
531 : bool intersect (const vrange &r) final override;
532 : bool singleton_p (tree * = NULL) const final override;
533 : bool contains_p (tree) const final override;
534 : bool zero_p () const final override;
535 : bool contains_zero_p () const final override;
536 : void set_nonzero (tree type) final override;
537 : void set_zero (tree type) final override;
538 : void set_nonnegative (tree type) final override;
539 : bool fits_p (const vrange &) const final override;
540 : unsupported_range& operator= (const unsupported_range &r);
541 : tree lbound () const final override;
542 : tree ubound () const final override;
543 : };
544 :
545 : // The possible NAN state of a floating point value as an opaque object.
546 : // This represents one of the four subsets of { -NaN, +NaN },
547 : // i.e. one of {}, { -NaN }, { +NaN}, or { -NaN, +NaN }.
548 :
549 : class nan_state
550 : {
551 : public:
552 : nan_state (bool);
553 : nan_state (bool pos_nan, bool neg_nan);
554 : bool neg_p () const;
555 : bool pos_p () const;
556 : private:
557 : bool m_pos_nan;
558 : bool m_neg_nan;
559 : };
560 :
561 : // Set NAN state to +-NAN if NAN_P is true. Otherwise set NAN state
562 : // to false.
563 :
564 : inline
565 36847384 : nan_state::nan_state (bool nan_p)
566 : {
567 36847384 : m_pos_nan = nan_p;
568 32578727 : m_neg_nan = nan_p;
569 : }
570 :
571 : // Constructor initializing the object to +NAN if POS_NAN is set, -NAN
572 : // if NEG_NAN is set, or +-NAN if both are set. Otherwise POS_NAN and
573 : // NEG_NAN are clear, and the object cannot be a NAN.
574 :
575 : inline
576 3497160 : nan_state::nan_state (bool pos_nan, bool neg_nan)
577 : {
578 3497160 : m_pos_nan = pos_nan;
579 3486160 : m_neg_nan = neg_nan;
580 : }
581 :
582 : // Return if +NAN is possible.
583 :
584 : inline bool
585 39851854 : nan_state::pos_p () const
586 : {
587 39747852 : return m_pos_nan;
588 : }
589 :
590 : // Return if -NAN is possible.
591 :
592 : inline bool
593 39590587 : nan_state::neg_p () const
594 : {
595 39538542 : return m_neg_nan;
596 : }
597 :
598 : // A sub-range in an frange.
599 :
600 : struct frange_pair
601 : {
602 : REAL_VALUE_TYPE min;
603 : REAL_VALUE_TYPE max;
604 : };
605 :
606 : // A subset of possible values for a floating point type.
607 : //
608 : // The representation is a handful of disjoint intervals, unioned with a
609 : // subset of { -NaN, +NaN }.
610 :
611 27788810 : class frange final : public vrange
612 : {
613 : friend class frange_storage;
614 : friend class vrange_printer;
615 : public:
616 : frange ();
617 : frange (const frange &);
618 : frange (tree, tree, value_range_kind = VR_RANGE);
619 : frange (tree type);
620 : frange (tree type, const REAL_VALUE_TYPE &min, const REAL_VALUE_TYPE &max,
621 : value_range_kind = VR_RANGE);
622 540322436 : static bool supports_p (const_tree type)
623 : {
624 : // ?? Decimal floats can have multiple representations for the
625 : // same number. Supporting them may be as simple as just
626 : // disabling them in singleton_p. No clue.
627 540322436 : return SCALAR_FLOAT_TYPE_P (type) && !DECIMAL_FLOAT_TYPE_P (type);
628 : }
629 : virtual tree type () const override;
630 : void set (tree type, const REAL_VALUE_TYPE &, const REAL_VALUE_TYPE &,
631 : value_range_kind = VR_RANGE);
632 : void set (tree type, const REAL_VALUE_TYPE &, const REAL_VALUE_TYPE &,
633 : const nan_state &, value_range_kind = VR_RANGE);
634 : void set_nan (tree type);
635 : void set_nan (tree type, bool sign);
636 : void set_nan (tree type, const nan_state &);
637 : virtual void set_varying (tree type) override;
638 : virtual void set_undefined () override;
639 : virtual bool union_ (const vrange &) override;
640 : virtual bool intersect (const vrange &) override;
641 : bool contains_p (const REAL_VALUE_TYPE &) const;
642 : virtual bool singleton_p (tree *result = NULL) const override;
643 : bool singleton_p (REAL_VALUE_TYPE &r) const;
644 : virtual bool supports_type_p (const_tree type) const override;
645 : virtual void accept (const vrange_visitor &v) const override;
646 : virtual bool zero_p () const override;
647 : virtual bool contains_zero_p () const override;
648 : virtual void set_nonzero (tree type) override;
649 : virtual void set_zero (tree type) override;
650 : virtual void set_nonnegative (tree type) override;
651 : virtual bool fits_p (const vrange &) const override;
652 : frange& operator= (const frange &);
653 : bool operator== (const frange &) const;
654 10828393 : bool operator!= (const frange &r) const { return !(*this == r); }
655 : const REAL_VALUE_TYPE &lower_bound () const;
656 : const REAL_VALUE_TYPE &upper_bound () const;
657 : virtual tree lbound () const override;
658 : virtual tree ubound () const override;
659 : nan_state get_nan_state () const;
660 : void update_nan ();
661 : void update_nan (bool sign);
662 : void update_nan (tree) = delete; // Disallow silent conversion to bool.
663 : void update_nan (const nan_state &);
664 : void clear_nan ();
665 : void flush_denormals_to_zero ();
666 :
667 : // fpclassify like API
668 : bool known_isfinite () const;
669 : bool known_isnan () const;
670 : bool known_isinf () const;
671 : bool maybe_isnan () const;
672 : bool maybe_isnan (bool sign) const;
673 : bool maybe_isinf () const;
674 : bool signbit_p (bool &signbit) const;
675 : bool nan_signbit_p (bool &signbit) const;
676 : bool known_isnormal () const;
677 : bool known_isdenormal_or_zero () const;
678 : virtual void verify_range () const override;
679 :
680 : static const unsigned int MAX_PAIRS = 2;
681 35592883 : unsigned num_pairs () const { return m_num_ranges; }
682 : const REAL_VALUE_TYPE &lower_bound (unsigned pair) const;
683 : const REAL_VALUE_TYPE &upper_bound (unsigned pair) const;
684 :
685 : void widen (tree);
686 : protected:
687 : virtual bool contains_p (tree cst) const override;
688 : virtual void set (tree, tree, value_range_kind = VR_RANGE) override;
689 :
690 : private:
691 : bool internal_singleton_p (REAL_VALUE_TYPE * = NULL) const;
692 : bool normalize_kind ();
693 : bool union_nans (const frange &);
694 : bool intersect_nans (const frange &);
695 : void set_pairs (frange_pair *, unsigned);
696 : void canonicalize_zeros (frange_pair &);
697 : void set_excluding (tree type, const REAL_VALUE_TYPE &,
698 : const REAL_VALUE_TYPE &, const nan_state &);
699 :
700 : tree m_type;
701 : frange_pair m_pairs[MAX_PAIRS];
702 : unsigned char m_num_ranges;
703 : bool m_pos_nan;
704 : bool m_neg_nan;
705 : };
706 :
707 : inline const REAL_VALUE_TYPE &
708 7032822 : frange::lower_bound () const
709 : {
710 7032822 : gcc_checking_assert (!undefined_p () && !known_isnan ());
711 7032822 : return m_pairs[0].min;
712 : }
713 :
714 : inline const REAL_VALUE_TYPE &
715 5189576 : frange::upper_bound () const
716 : {
717 5189576 : gcc_checking_assert (!undefined_p () && !known_isnan ());
718 5189576 : return m_pairs[m_num_ranges - 1].max;
719 : }
720 :
721 : inline const REAL_VALUE_TYPE &
722 14429462 : frange::lower_bound (unsigned pair) const
723 : {
724 14429462 : gcc_checking_assert (!undefined_p () && !known_isnan ());
725 14429462 : gcc_checking_assert (pair < m_num_ranges);
726 14429462 : return m_pairs[pair].min;
727 : }
728 :
729 : inline const REAL_VALUE_TYPE &
730 14429462 : frange::upper_bound (unsigned pair) const
731 : {
732 14429462 : gcc_checking_assert (!undefined_p () && !known_isnan ());
733 14429462 : gcc_checking_assert (pair < m_num_ranges);
734 14429462 : return m_pairs[pair].max;
735 : }
736 :
737 : // Return the NAN state.
738 :
739 : inline nan_state
740 1143448 : frange::get_nan_state () const
741 : {
742 1143448 : return nan_state (m_pos_nan, m_neg_nan);
743 : }
744 :
745 : // is_a<> and as_a<> implementation for vrange.
746 :
747 : // Anything we haven't specialized is a hard fail.
748 : template <typename T>
749 : inline bool
750 : is_a (vrange &)
751 : {
752 : gcc_unreachable ();
753 : return false;
754 : }
755 :
756 : template <typename T>
757 : inline bool
758 5086286872 : is_a (const vrange &v)
759 : {
760 : // Reuse is_a <vrange> to implement the const version.
761 5282036072 : const T &derived = static_cast<const T &> (v);
762 2437643349 : return is_a <T> (const_cast<T &> (derived));
763 : }
764 :
765 : template <typename T>
766 : inline T &
767 3089759623 : as_a (vrange &v)
768 : {
769 0 : gcc_checking_assert (is_a <T> (v));
770 3089759623 : return static_cast <T &> (v);
771 : }
772 :
773 : template <typename T>
774 : inline const T &
775 4464831228 : as_a (const vrange &v)
776 : {
777 0 : gcc_checking_assert (is_a <T> (v));
778 4464831228 : return static_cast <const T &> (v);
779 : }
780 :
781 : // Specializations for the different range types.
782 :
783 : template <>
784 : inline bool
785 6646709673 : is_a <irange> (vrange &v)
786 : {
787 6508841323 : return v.m_discriminator == VR_IRANGE;
788 : }
789 :
790 : template <>
791 : inline bool
792 1712202297 : is_a <prange> (vrange &v)
793 : {
794 1567260398 : return v.m_discriminator == VR_PRANGE;
795 : }
796 :
797 : template <>
798 : inline bool
799 227304287 : is_a <frange> (vrange &v)
800 : {
801 227304287 : return v.m_discriminator == VR_FRANGE;
802 : }
803 :
804 : template <>
805 : inline bool
806 656269 : is_a <unsupported_range> (vrange &v)
807 : {
808 656269 : return v.m_discriminator == VR_UNKNOWN;
809 : }
810 :
811 : // For resizable ranges, resize the range up to HARD_MAX_RANGES if the
812 : // NEEDED pairs is greater than the current capacity of the range.
813 :
814 : inline void
815 1625211172 : irange::maybe_resize (int needed)
816 : {
817 1625211172 : if (!m_resizable || m_max_ranges == HARD_MAX_RANGES)
818 : return;
819 :
820 1097647462 : if (needed > m_max_ranges)
821 : {
822 78152823 : m_max_ranges = HARD_MAX_RANGES;
823 39936092553 : wide_int *newmem = new wide_int[m_max_ranges * 2];
824 78152823 : unsigned n = num_pairs () * 2;
825 438322741 : for (unsigned i = 0; i < n; ++i)
826 360169918 : newmem[i] = m_base[i];
827 78152823 : m_base = newmem;
828 : }
829 : }
830 :
831 : template<unsigned N, bool RESIZABLE>
832 : inline
833 6267917437 : int_range<N, RESIZABLE>::~int_range ()
834 : {
835 4788603332 : if (RESIZABLE && m_base != m_ranges)
836 39867953258 : delete[] m_base;
837 39293720995 : }
838 :
839 : // This is an "infinite" precision irange for use in temporary
840 : // calculations. It starts with a sensible default covering 99% of
841 : // uses, and goes up to HARD_MAX_RANGES when needed. Any allocated
842 : // storage is freed upon destruction.
843 : typedef int_range<3, /*RESIZABLE=*/true> int_range_max;
844 :
845 43580 : class vrange_visitor
846 : {
847 : public:
848 0 : virtual void visit (const irange &) const { }
849 0 : virtual void visit (const prange &) const { }
850 0 : virtual void visit (const frange &) const { }
851 0 : virtual void visit (const unsupported_range &) const { }
852 : };
853 :
854 : // This is an "infinite" precision range object for use in temporary
855 : // calculations for any of the handled types. The object can be
856 : // transparently used as a vrange.
857 : //
858 : // Using any of the various constructors initializes the object
859 : // appropriately, but the default constructor is uninitialized and
860 : // must be initialized either with set_range_class() or by assigning into it.
861 : //
862 : // Assigning between incompatible types is allowed. For example if a
863 : // temporary holds an irange, you can assign an frange into it, and
864 : // all the right things will happen. However, before passing this
865 : // object to a function accepting a vrange, the correct type must be
866 : // set. If it isn't, you can do so with set_range_class().
867 :
868 : class value_range
869 : {
870 : public:
871 : value_range ();
872 : value_range (const vrange &r);
873 : value_range (tree type);
874 : value_range (tree, tree, value_range_kind kind = VR_RANGE);
875 : value_range (const value_range &);
876 : ~value_range ();
877 : void set_range_class (tree type);
878 : vrange& operator= (const vrange &);
879 : value_range& operator= (const value_range &);
880 : bool operator== (const value_range &r) const;
881 : bool operator!= (const value_range &r) const;
882 : operator vrange &();
883 : operator const vrange &() const;
884 : void dump (FILE *) const;
885 : void print (pretty_printer *) const;
886 : static bool supports_type_p (const_tree type);
887 :
888 3594489 : tree type () { return m_vrange->type (); }
889 165303788 : bool varying_p () const { return m_vrange->varying_p (); }
890 189922995 : bool undefined_p () const { return m_vrange->undefined_p (); }
891 371992656 : void set_varying (tree type) { init (type); m_vrange->set_varying (type); }
892 23622912 : void set_undefined () { m_vrange->set_undefined (); }
893 19192281 : bool union_ (const vrange &r) { return m_vrange->union_ (r); }
894 110401920 : bool intersect (const vrange &r) { return m_vrange->intersect (r); }
895 1459715 : bool contains_p (tree cst) const { return m_vrange->contains_p (cst); }
896 425719899 : bool singleton_p (tree *result = NULL) const
897 425719899 : { return m_vrange->singleton_p (result); }
898 1029 : void set_zero (tree type) { init (type); return m_vrange->set_zero (type); }
899 0 : void set_nonzero (tree type)
900 0 : { init (type); return m_vrange->set_nonzero (type); }
901 261884 : bool contains_zero_p () const { return m_vrange->contains_zero_p (); }
902 4489 : bool zero_p () const { return m_vrange->zero_p (); }
903 11147598 : tree lbound () const { return m_vrange->lbound (); }
904 357566 : tree ubound () const { return m_vrange->ubound (); }
905 504375 : irange_bitmask get_bitmask () const { return m_vrange->get_bitmask (); }
906 1485012 : void update_bitmask (const class irange_bitmask &bm)
907 1485012 : { return m_vrange->update_bitmask (bm); }
908 3078 : void accept (const vrange_visitor &v) const { m_vrange->accept (v); }
909 : void verify_range () const { m_vrange->verify_range (); }
910 : private:
911 : void init (tree type);
912 : void init (const vrange &);
913 :
914 : vrange *m_vrange;
915 : union buffer_type {
916 : int_range_max ints;
917 : frange floats;
918 : unsupported_range unsupported;
919 : prange pointers;
920 7451090374 : buffer_type () { }
921 7620604601 : ~buffer_type () { }
922 : } m_buffer;
923 : };
924 :
925 : // The default constructor is uninitialized and must be initialized
926 : // with either set_range_class() or with an assignment into it.
927 :
928 : inline
929 4075548828 : value_range::value_range ()
930 4075548828 : : m_buffer ()
931 : {
932 4075548828 : m_vrange = NULL;
933 : }
934 :
935 : // Copy constructor.
936 :
937 : inline
938 12857603 : value_range::value_range (const value_range &r)
939 : {
940 12857603 : init (*r.m_vrange);
941 : }
942 :
943 : // Copy constructor from a vrange.
944 :
945 : inline
946 89259948 : value_range::value_range (const vrange &r)
947 : {
948 90332774 : init (r);
949 : }
950 :
951 : // Construct an UNDEFINED range that can hold ranges of TYPE. If TYPE
952 : // is not supported, default to unsupported_range.
953 :
954 : inline
955 3272278675 : value_range::value_range (tree type)
956 : {
957 3064099801 : init (type);
958 : }
959 :
960 : // Construct a range that can hold a range of [MIN, MAX], where MIN
961 : // and MAX are trees.
962 :
963 : inline
964 72494 : value_range::value_range (tree min, tree max, value_range_kind kind)
965 : {
966 72494 : init (TREE_TYPE (min));
967 72494 : m_vrange->set (min, max, kind);
968 72494 : }
969 :
970 : inline
971 7620604601 : value_range::~value_range ()
972 : {
973 7620604601 : if (m_vrange)
974 3777970631 : m_vrange->~vrange ();
975 7620604601 : }
976 :
977 : // Initialize object to an UNDEFINED range that can hold ranges of
978 : // TYPE. Clean-up memory if there was a previous object.
979 : // Note that this does *not* set the type of the underlying vrange.
980 :
981 : inline void
982 143359490 : value_range::set_range_class (tree type)
983 : {
984 143359490 : if (m_vrange)
985 9775240 : m_vrange->~vrange ();
986 143359490 : init (type);
987 143359490 : }
988 :
989 : // Initialize object to an UNDEFINED range that can hold ranges of
990 : // TYPE.
991 : // Note that this does *not* set the type of the underlying vrange.
992 :
993 : inline void
994 3787704344 : value_range::init (tree type)
995 : {
996 3787704344 : gcc_checking_assert (TYPE_P (type));
997 :
998 3787704344 : if (irange::supports_p (type))
999 2771877806 : m_vrange = new (&m_buffer.ints) int_range_max ();
1000 1015826538 : else if (prange::supports_p (type))
1001 829513098 : m_vrange = new (&m_buffer.pointers) prange ();
1002 186313440 : else if (frange::supports_p (type))
1003 111326410 : m_vrange = new (&m_buffer.floats) frange ();
1004 : else
1005 74987030 : m_vrange = new (&m_buffer.unsupported) unsupported_range ();
1006 3787704344 : }
1007 :
1008 : // Initialize object with a copy of R.
1009 :
1010 : inline void
1011 137425351 : value_range::init (const vrange &r)
1012 : {
1013 137425351 : if (is_a <irange> (r))
1014 83245674 : m_vrange = new (&m_buffer.ints) int_range_max (as_a <irange> (r));
1015 54179677 : else if (is_a <prange> (r))
1016 106617598 : m_vrange = new (&m_buffer.pointers) prange (as_a <prange> (r));
1017 870878 : else if (is_a <frange> (r))
1018 429218 : m_vrange = new (&m_buffer.floats) frange (as_a <frange> (r));
1019 : else
1020 1312538 : m_vrange = new (&m_buffer.unsupported)
1021 656269 : unsupported_range (as_a <unsupported_range> (r));
1022 137425351 : }
1023 :
1024 : // Assignment operator. Copying incompatible types is allowed. That
1025 : // is, assigning an frange to an object holding an irange does the
1026 : // right thing.
1027 :
1028 : inline vrange &
1029 34234974 : value_range::operator= (const vrange &r)
1030 : {
1031 34234974 : if (m_vrange)
1032 10265701 : m_vrange->~vrange ();
1033 34234974 : init (r);
1034 34234974 : return *m_vrange;
1035 : }
1036 :
1037 : inline value_range &
1038 10335944 : value_range::operator= (const value_range &r)
1039 : {
1040 : // No need to call the m_vrange destructor here, as we will do so in
1041 : // the assignment below.
1042 1589363 : *this = *r.m_vrange;
1043 10335944 : return *this;
1044 : }
1045 :
1046 : inline bool
1047 28366361 : value_range::operator== (const value_range &r) const
1048 : {
1049 28366361 : return *m_vrange == *r.m_vrange;
1050 : }
1051 :
1052 : inline bool
1053 13875387 : value_range::operator!= (const value_range &r) const
1054 : {
1055 13875387 : return *m_vrange != *r.m_vrange;
1056 : }
1057 :
1058 : inline
1059 5108445093 : value_range::operator vrange &()
1060 : {
1061 4771722503 : return *m_vrange;
1062 : }
1063 :
1064 : inline
1065 43728559 : value_range::operator const vrange &() const
1066 : {
1067 43728559 : return *m_vrange;
1068 : }
1069 :
1070 : // Return TRUE if TYPE is supported by the vrange infrastructure.
1071 :
1072 : inline bool
1073 7176696246 : value_range::supports_type_p (const_tree type)
1074 : {
1075 7176696246 : return irange::supports_p (type)
1076 1674134563 : || prange::supports_p (type)
1077 255097129 : || frange::supports_p (type);
1078 : }
1079 :
1080 : extern value_range_kind get_legacy_range (const vrange &, tree &min, tree &max);
1081 : extern void dump_value_range (FILE *, const vrange *);
1082 : extern bool vrp_operand_equal_p (const_tree, const_tree);
1083 : inline REAL_VALUE_TYPE frange_val_min (const_tree type);
1084 : inline REAL_VALUE_TYPE frange_val_max (const_tree type);
1085 :
1086 : // Number of sub-ranges in a range.
1087 :
1088 : inline unsigned
1089 40733877169 : irange::num_pairs () const
1090 : {
1091 6737343437 : return m_num_ranges;
1092 : }
1093 :
1094 : inline tree
1095 14135931096 : irange::type () const
1096 : {
1097 14135931096 : gcc_checking_assert (m_num_ranges > 0);
1098 14135931096 : return m_type;
1099 : }
1100 :
1101 : inline bool
1102 6053760164 : irange::varying_compatible_p () const
1103 : {
1104 6053760164 : if (m_num_ranges != 1)
1105 : return false;
1106 :
1107 4473603978 : const wide_int &l = m_base[0];
1108 4473603978 : const wide_int &u = m_base[1];
1109 4473603978 : tree t = m_type;
1110 :
1111 4473603978 : if (m_kind == VR_VARYING)
1112 : return true;
1113 :
1114 4198472373 : unsigned prec = TYPE_PRECISION (t);
1115 4198472373 : signop sign = TYPE_SIGN (t);
1116 4198472373 : if (INTEGRAL_TYPE_P (t) || POINTER_TYPE_P (t))
1117 8396944746 : return (l == wi::min_value (prec, sign)
1118 5476815576 : && u == wi::max_value (prec, sign)
1119 4206807739 : && m_bitmask.unknown_p ());
1120 : return true;
1121 : }
1122 :
1123 : inline bool
1124 1150241576 : vrange::varying_p () const
1125 : {
1126 1145159448 : return m_kind == VR_VARYING;
1127 : }
1128 :
1129 : inline bool
1130 26135908282 : vrange::undefined_p () const
1131 : {
1132 14556382980 : return m_kind == VR_UNDEFINED;
1133 : }
1134 :
1135 : inline bool
1136 298451572 : irange::zero_p () const
1137 : {
1138 284820341 : return (m_kind == VR_RANGE && m_num_ranges == 1
1139 548197614 : && lower_bound (0) == 0
1140 583271932 : && upper_bound (0) == 0);
1141 : }
1142 :
1143 : inline bool
1144 52692105 : irange::contains_zero_p () const
1145 : {
1146 52692105 : if (undefined_p ())
1147 : return false;
1148 :
1149 52692105 : wide_int zero = wi::zero (TYPE_PRECISION (type ()));
1150 52692105 : return contains_p (zero);
1151 52692105 : }
1152 :
1153 : inline bool
1154 18137672910 : irange::supports_p (const_tree type)
1155 : {
1156 17064653302 : return INTEGRAL_TYPE_P (type);
1157 : }
1158 :
1159 : inline bool
1160 92912507 : irange::contains_p (tree cst) const
1161 : {
1162 92912507 : return contains_p (wi::to_wide (cst));
1163 : }
1164 :
1165 : inline bool
1166 38157131 : range_includes_zero_p (const vrange &vr)
1167 : {
1168 38157131 : if (vr.undefined_p ())
1169 : return false;
1170 :
1171 38157131 : if (vr.varying_p ())
1172 : return true;
1173 :
1174 28923290 : return vr.contains_p (build_zero_cst (vr.type ()));
1175 : }
1176 :
1177 : // Constructors for irange
1178 :
1179 : inline
1180 6361881043 : irange::irange (wide_int *base, unsigned nranges, bool resizable)
1181 : : vrange (VR_IRANGE),
1182 6361881043 : m_resizable (resizable),
1183 6361881043 : m_max_ranges (nranges)
1184 : {
1185 6361881043 : m_base = base;
1186 6361881043 : set_undefined ();
1187 : }
1188 :
1189 : // Constructors for int_range<>.
1190 :
1191 : template<unsigned N, bool RESIZABLE>
1192 : inline
1193 4813942216 : int_range<N, RESIZABLE>::int_range ()
1194 32983477310 : : irange (m_ranges, N, RESIZABLE)
1195 : {
1196 4813942216 : }
1197 :
1198 : template<unsigned N, bool RESIZABLE>
1199 565848 : int_range<N, RESIZABLE>::int_range (const int_range &other)
1200 3960928 : : irange (m_ranges, N, RESIZABLE)
1201 : {
1202 565848 : irange::operator= (other);
1203 565848 : }
1204 :
1205 : template<unsigned N, bool RESIZABLE>
1206 : int_range<N, RESIZABLE>::int_range (tree min, tree max, value_range_kind kind)
1207 : : irange (m_ranges, N, RESIZABLE)
1208 : {
1209 : irange::set (min, max, kind);
1210 : }
1211 :
1212 : template<unsigned N, bool RESIZABLE>
1213 174726890 : int_range<N, RESIZABLE>::int_range (tree type)
1214 685065624 : : irange (m_ranges, N, RESIZABLE)
1215 : {
1216 174726890 : set_varying (type);
1217 174726890 : }
1218 :
1219 : template<unsigned N, bool RESIZABLE>
1220 916506269 : int_range<N, RESIZABLE>::int_range (tree type, const wide_int &wmin, const wide_int &wmax,
1221 : value_range_kind kind)
1222 3242965987 : : irange (m_ranges, N, RESIZABLE)
1223 : {
1224 916506269 : set (type, wmin, wmax, kind);
1225 916506269 : }
1226 :
1227 : template<unsigned N, bool RESIZABLE>
1228 456139820 : int_range<N, RESIZABLE>::int_range (const irange &other)
1229 2957976910 : : irange (m_ranges, N, RESIZABLE)
1230 : {
1231 456139820 : irange::operator= (other);
1232 456139820 : }
1233 :
1234 : template<unsigned N, bool RESIZABLE>
1235 : int_range<N, RESIZABLE>&
1236 72669327 : int_range<N, RESIZABLE>::operator= (const int_range &src)
1237 : {
1238 72661771 : irange::operator= (src);
1239 0 : return *this;
1240 : }
1241 :
1242 : inline void
1243 6788851031 : irange::set_undefined ()
1244 : {
1245 6788851031 : m_kind = VR_UNDEFINED;
1246 6684511449 : m_num_ranges = 0;
1247 421984191 : }
1248 :
1249 : inline void
1250 1405599482 : irange::set_varying (tree type)
1251 : {
1252 1405599482 : m_kind = VR_VARYING;
1253 1405599482 : m_num_ranges = 1;
1254 1405599482 : m_bitmask.set_unknown (TYPE_PRECISION (type));
1255 :
1256 1405599482 : if (INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type))
1257 : {
1258 1405599482 : m_type = type;
1259 : // Strict enum's require varying to be not TYPE_MIN/MAX, but rather
1260 : // min_value and max_value.
1261 1405599482 : m_base[0] = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
1262 1405616895 : m_base[1] = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
1263 : }
1264 : else
1265 0 : m_type = error_mark_node;
1266 1405599482 : }
1267 :
1268 : // Return the lower bound of a sub-range. PAIR is the sub-range in
1269 : // question.
1270 :
1271 : inline wide_int
1272 14020440654 : irange::lower_bound (unsigned pair) const
1273 : {
1274 14020440654 : gcc_checking_assert (m_num_ranges > 0);
1275 14020440654 : gcc_checking_assert (pair + 1 <= num_pairs ());
1276 14020440654 : return m_base[pair * 2];
1277 : }
1278 :
1279 : // Return the upper bound of a sub-range. PAIR is the sub-range in
1280 : // question.
1281 :
1282 : inline wide_int
1283 16093860531 : irange::upper_bound (unsigned pair) const
1284 : {
1285 16093860531 : gcc_checking_assert (m_num_ranges > 0);
1286 16093860531 : gcc_checking_assert (pair + 1 <= num_pairs ());
1287 16093860531 : return m_base[pair * 2 + 1];
1288 : }
1289 :
1290 : // Return the highest bound of a range.
1291 :
1292 : inline wide_int
1293 4240153990 : irange::upper_bound () const
1294 : {
1295 4240153990 : unsigned pairs = num_pairs ();
1296 4240153990 : gcc_checking_assert (pairs > 0);
1297 4240153990 : return upper_bound (pairs - 1);
1298 : }
1299 :
1300 : // Set value range VR to a nonzero range of type TYPE.
1301 :
1302 : inline void
1303 4344850 : irange::set_nonzero (tree type)
1304 : {
1305 4344850 : unsigned prec = TYPE_PRECISION (type);
1306 :
1307 4344850 : if (TYPE_UNSIGNED (type))
1308 : {
1309 3664279 : m_type = type;
1310 3664279 : m_kind = VR_RANGE;
1311 3664279 : m_base[0] = wi::one (prec);
1312 3664279 : m_base[1] = wi::minus_one (prec);
1313 3664279 : m_bitmask.set_unknown (prec);
1314 3664279 : m_num_ranges = 1;
1315 :
1316 3664279 : if (flag_checking)
1317 3664279 : verify_range ();
1318 : }
1319 : else
1320 : {
1321 680571 : wide_int zero = wi::zero (prec);
1322 680571 : set (type, zero, zero, VR_ANTI_RANGE);
1323 680571 : }
1324 4344850 : }
1325 :
1326 : // Set value range VR to a ZERO range of type TYPE.
1327 :
1328 : inline void
1329 3941885 : irange::set_zero (tree type)
1330 : {
1331 3941885 : wide_int zero = wi::zero (TYPE_PRECISION (type));
1332 3941885 : set (type, zero, zero);
1333 3941885 : }
1334 :
1335 : // Normalize a range to VARYING or UNDEFINED if possible.
1336 :
1337 : inline void
1338 692260053 : irange::normalize_kind ()
1339 : {
1340 692260053 : if (m_num_ranges == 0)
1341 20127 : set_undefined ();
1342 692239926 : else if (varying_compatible_p ())
1343 : {
1344 29123117 : if (m_kind == VR_RANGE)
1345 8176035 : m_kind = VR_VARYING;
1346 20947082 : else if (m_kind == VR_ANTI_RANGE)
1347 0 : set_undefined ();
1348 : }
1349 692260053 : if (flag_checking)
1350 692259208 : verify_range ();
1351 692260053 : }
1352 :
1353 : inline wide_int
1354 115590407 : irange_val_min (const_tree type)
1355 : {
1356 115590407 : gcc_checking_assert (irange::supports_p (type));
1357 115590407 : return wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
1358 : }
1359 :
1360 : inline wide_int
1361 117252105 : irange_val_max (const_tree type)
1362 : {
1363 117252105 : gcc_checking_assert (irange::supports_p (type));
1364 117252105 : return wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
1365 : }
1366 :
1367 : inline
1368 891598796 : prange::prange ()
1369 891598796 : : vrange (VR_PRANGE)
1370 : {
1371 1783197592 : set_undefined ();
1372 891598796 : }
1373 :
1374 : inline
1375 150019498 : prange::prange (const prange &r)
1376 150019498 : : vrange (VR_PRANGE)
1377 : {
1378 150019498 : *this = r;
1379 : }
1380 :
1381 : inline
1382 217952851 : prange::prange (tree type)
1383 217952851 : : vrange (VR_PRANGE)
1384 : {
1385 217952851 : set_varying (type);
1386 : }
1387 :
1388 : inline
1389 3985064 : prange::prange (tree type, const wide_int &lb, const wide_int &ub,
1390 : value_range_kind kind)
1391 3985064 : : vrange (VR_PRANGE)
1392 : {
1393 3985064 : set (type, lb, ub, kind);
1394 : }
1395 :
1396 : inline bool
1397 4447894117 : prange::supports_p (const_tree type)
1398 : {
1399 4447894117 : return POINTER_TYPE_P (type);
1400 : }
1401 :
1402 : inline bool
1403 614151228 : prange::supports_type_p (const_tree type) const
1404 : {
1405 614151228 : return POINTER_TYPE_P (type);
1406 : }
1407 :
1408 : inline void
1409 1035152988 : prange::set_undefined ()
1410 : {
1411 1035152988 : m_kind = VR_UNDEFINED;
1412 1035152988 : set_addr_unknown ();
1413 142211562 : }
1414 :
1415 : inline void
1416 676960298 : prange::set_varying (tree type)
1417 : {
1418 676960298 : m_kind = VR_VARYING;
1419 676960298 : m_type = type;
1420 676960298 : m_min = wi::zero (TYPE_PRECISION (type));
1421 676960298 : m_max = wi::max_value (TYPE_PRECISION (type), UNSIGNED);
1422 676960298 : m_bitmask.set_unknown (TYPE_PRECISION (type));
1423 676960298 : set_addr_unknown ();
1424 :
1425 676960298 : if (flag_checking)
1426 676960115 : verify_range ();
1427 676960298 : }
1428 :
1429 : inline void
1430 402096620 : prange::set_nonzero (tree type)
1431 : {
1432 402096620 : m_kind = VR_RANGE;
1433 402096620 : m_type = type;
1434 402096620 : m_min = wi::one (TYPE_PRECISION (type));
1435 402096620 : m_max = wi::max_value (TYPE_PRECISION (type), UNSIGNED);
1436 402096620 : m_bitmask.set_unknown (TYPE_PRECISION (type));
1437 402096620 : set_addr_unknown ();
1438 :
1439 402096620 : if (flag_checking)
1440 402096239 : verify_range ();
1441 402096620 : }
1442 :
1443 : inline void
1444 793468 : prange::set_zero (tree type)
1445 : {
1446 793468 : m_kind = VR_RANGE;
1447 793468 : m_type = type;
1448 793468 : wide_int zero = wi::zero (TYPE_PRECISION (type));
1449 793468 : m_min = m_max = zero;
1450 793468 : m_bitmask = irange_bitmask (zero, zero);
1451 793468 : set_addr_unknown ();
1452 :
1453 793468 : if (flag_checking)
1454 793468 : verify_range ();
1455 793468 : }
1456 :
1457 : inline bool
1458 568745 : prange::contains_p (tree cst) const
1459 : {
1460 568745 : return contains_p (wi::to_wide (cst));
1461 : }
1462 :
1463 : inline bool
1464 293330938 : prange::zero_p () const
1465 : {
1466 293330938 : bool ret = m_kind == VR_RANGE && m_min == 0 && m_max == 0;
1467 293330938 : return ret;
1468 : }
1469 :
1470 : inline bool
1471 28912141 : prange::contains_zero_p () const
1472 : {
1473 28912141 : if (undefined_p ())
1474 : return false;
1475 :
1476 28011536 : wide_int zero = wi::zero (TYPE_PRECISION (type ()));
1477 28011536 : return contains_p (zero);
1478 28011536 : }
1479 :
1480 : inline tree
1481 2948354340 : prange::type () const
1482 : {
1483 2948354340 : gcc_checking_assert (!undefined_p ());
1484 2948354340 : return m_type;
1485 : }
1486 :
1487 : inline wide_int
1488 732772190 : prange::lower_bound () const
1489 : {
1490 732772190 : gcc_checking_assert (!undefined_p ());
1491 732772190 : return m_min;
1492 : }
1493 :
1494 : inline wide_int
1495 688557088 : prange::upper_bound () const
1496 : {
1497 688557088 : gcc_checking_assert (!undefined_p ());
1498 688557088 : return m_max;
1499 : }
1500 :
1501 : inline bool
1502 2467083353 : prange::varying_compatible_p () const
1503 : {
1504 2467083278 : return (!undefined_p () && m_min == 0 && m_max == -1
1505 4041536373 : && get_bitmask ().unknown_p () && addr_unknown_p ());
1506 : }
1507 :
1508 : inline irange_bitmask
1509 1057842833 : prange::get_bitmask () const
1510 : {
1511 1057842833 : return m_bitmask;
1512 : }
1513 :
1514 : inline bool
1515 0 : prange::fits_p (const vrange &) const
1516 : {
1517 0 : return true;
1518 : }
1519 :
1520 : // Copy the address information from R, if it has any.
1521 :
1522 : inline void
1523 236588456 : prange::set_addr (const prange &r)
1524 : {
1525 : // Do not set address info if this is zero or undefined.
1526 12446425 : if (!r.addr_unknown_p () && (undefined_p () || zero_p()))
1527 : return;
1528 :
1529 236588381 : m_addr = r.m_addr;
1530 236588381 : m_known_p = r.m_known_p;
1531 :
1532 236588381 : if (r.undefined_p ())
1533 : return;
1534 : // Check whether this is now VARYING or not.
1535 236521556 : if (varying_compatible_p ())
1536 26134729 : set_varying (type ());
1537 : else
1538 210386827 : m_kind = VR_RANGE;
1539 : }
1540 :
1541 : // prange_pt methods.
1542 : // ------------------------------------------------------------------
1543 :
1544 : inline void
1545 2160858315 : prange::set_addr_unknown ()
1546 : {
1547 2160858315 : m_addr = NULL_TREE;
1548 2160858315 : m_known_p = false;
1549 : // If this is a transition from a range, check for varying compatibility.
1550 2160858315 : if (m_kind == VR_RANGE && varying_compatible_p ())
1551 506 : m_kind = VR_VARYING;
1552 2160858315 : }
1553 :
1554 : inline bool
1555 2123135751 : prange::addr_unknown_p () const
1556 : {
1557 2046923492 : return (m_addr == NULL_TREE);
1558 : }
1559 :
1560 : inline bool
1561 90373585 : prange::addr_equal_p (const prange &p) const
1562 : {
1563 : // A prange object invokes vrp_operand_equal_p as we want ranges to compare
1564 : // equal to each other if they refer to the same object, even if the
1565 : // tree has become unshared.
1566 90373585 : return (m_known_p == p.m_known_p
1567 90373585 : && vrp_operand_equal_p (m_addr, p.m_addr));
1568 : }
1569 :
1570 : inline bool
1571 93659873 : prange::addr_inverted_p (const prange &r) const
1572 : {
1573 2194264 : return m_addr && vrp_operand_equal_p (m_addr, r.m_addr)
1574 94242275 : && m_known_p != r.m_known_p;
1575 : }
1576 :
1577 : inline bool
1578 2775444 : prange::addr_invert ()
1579 : {
1580 2775444 : if (m_addr)
1581 : {
1582 0 : m_known_p = !m_known_p;
1583 0 : return true;
1584 : }
1585 : return false;
1586 : }
1587 :
1588 : inline tree
1589 83105550 : prange::addr_known () const
1590 : {
1591 83105550 : if (m_addr && m_known_p)
1592 1314671 : return m_addr;
1593 : return NULL_TREE;
1594 : }
1595 :
1596 : inline tree
1597 4226303 : prange::addr_excluded () const
1598 : {
1599 4226303 : if (m_addr && !m_known_p)
1600 1024758 : return m_addr;
1601 : return NULL_TREE;
1602 : }
1603 :
1604 : inline bool
1605 18438894 : prange::addr_same_known_p (const prange &r) const
1606 : {
1607 409950 : if (m_addr && m_known_p && vrp_operand_equal_p (r.m_addr, m_addr)
1608 18458121 : && m_known_p == r.m_known_p)
1609 17633 : return true;
1610 : return false;
1611 : }
1612 :
1613 : inline bool
1614 : prange::addr_same_excluded_p (const prange &r) const
1615 : {
1616 : if (m_addr && !m_known_p && vrp_operand_equal_p (r.m_addr, m_addr)
1617 : && m_known_p == r.m_known_p)
1618 : return true;
1619 : return false;
1620 : }
1621 :
1622 :
1623 : // -----------------------------------------------------------------------
1624 :
1625 : inline
1626 122118039 : frange::frange ()
1627 122118039 : : vrange (VR_FRANGE)
1628 : {
1629 122117975 : set_undefined ();
1630 : }
1631 :
1632 : inline
1633 13947286 : frange::frange (const frange &src)
1634 13947286 : : vrange (VR_FRANGE)
1635 : {
1636 13522172 : *this = src;
1637 : }
1638 :
1639 : inline
1640 795495 : frange::frange (tree type)
1641 795495 : : vrange (VR_FRANGE)
1642 : {
1643 795495 : set_varying (type);
1644 : }
1645 :
1646 : // frange constructor from REAL_VALUE_TYPE endpoints.
1647 :
1648 : inline
1649 18284920 : frange::frange (tree type,
1650 : const REAL_VALUE_TYPE &min, const REAL_VALUE_TYPE &max,
1651 : value_range_kind kind)
1652 18284920 : : vrange (VR_FRANGE)
1653 : {
1654 18284920 : set (type, min, max, kind);
1655 : }
1656 :
1657 : // frange constructor from trees.
1658 :
1659 : inline
1660 : frange::frange (tree min, tree max, value_range_kind kind)
1661 : : vrange (VR_FRANGE)
1662 : {
1663 : set (min, max, kind);
1664 : }
1665 :
1666 : inline tree
1667 73130496 : frange::type () const
1668 : {
1669 73130496 : gcc_checking_assert (!undefined_p ());
1670 73130496 : return m_type;
1671 : }
1672 :
1673 : inline void
1674 73865382 : frange::set_varying (tree type)
1675 : {
1676 73865382 : m_kind = VR_VARYING;
1677 73865382 : m_type = type;
1678 73865382 : m_num_ranges = 1;
1679 73865382 : m_pairs[0].min = frange_val_min (type);
1680 73865382 : m_pairs[0].max = frange_val_max (type);
1681 73865382 : if (HONOR_NANS (m_type))
1682 : {
1683 : m_pos_nan = true;
1684 : m_neg_nan = true;
1685 : }
1686 : else
1687 : {
1688 4312960 : m_pos_nan = false;
1689 4312960 : m_neg_nan = false;
1690 : }
1691 73865382 : }
1692 :
1693 : inline void
1694 163501873 : frange::set_undefined ()
1695 : {
1696 163501873 : m_kind = VR_UNDEFINED;
1697 163501873 : m_type = NULL;
1698 163501873 : m_num_ranges = 1;
1699 163501873 : m_pos_nan = false;
1700 163501873 : m_neg_nan = false;
1701 : // Leave the rest undefined; as it speeds up initializing undefined ranges.
1702 163501873 : if (flag_checking)
1703 163501873 : verify_range ();
1704 163501873 : }
1705 :
1706 : // Set the NAN bits to NAN and adjust the range.
1707 :
1708 : inline void
1709 6380745 : frange::update_nan (const nan_state &nan)
1710 : {
1711 6380745 : gcc_checking_assert (!undefined_p ());
1712 6380745 : if (HONOR_NANS (m_type))
1713 : {
1714 6378631 : m_pos_nan = nan.pos_p ();
1715 6378631 : m_neg_nan = nan.neg_p ();
1716 6378631 : normalize_kind ();
1717 6378631 : if (flag_checking)
1718 6378631 : verify_range ();
1719 : }
1720 6380745 : }
1721 :
1722 : // Set the NAN bit to +-NAN.
1723 :
1724 : inline void
1725 4218457 : frange::update_nan ()
1726 : {
1727 4218457 : gcc_checking_assert (!undefined_p ());
1728 4218457 : nan_state nan (true);
1729 4218457 : update_nan (nan);
1730 4218457 : }
1731 :
1732 : // Like above, but set the sign of the NAN.
1733 :
1734 : inline void
1735 2162288 : frange::update_nan (bool sign)
1736 : {
1737 2162288 : gcc_checking_assert (!undefined_p ());
1738 2162288 : nan_state nan (/*pos=*/!sign, /*neg=*/sign);
1739 2162288 : update_nan (nan);
1740 2162288 : }
1741 :
1742 : inline bool
1743 0 : frange::contains_p (tree cst) const
1744 : {
1745 0 : return contains_p (*TREE_REAL_CST_PTR (cst));
1746 : }
1747 :
1748 : // Clear the NAN bit and adjust the range.
1749 :
1750 : inline void
1751 14029180 : frange::clear_nan ()
1752 : {
1753 14029180 : gcc_checking_assert (!undefined_p ());
1754 14029180 : m_pos_nan = false;
1755 14029180 : m_neg_nan = false;
1756 14029180 : normalize_kind ();
1757 14029180 : if (flag_checking)
1758 14029180 : verify_range ();
1759 14029180 : }
1760 :
1761 : // Set R to maximum representable value for TYPE.
1762 :
1763 : inline REAL_VALUE_TYPE
1764 15687360 : real_max_representable (const_tree type)
1765 : {
1766 15687360 : REAL_VALUE_TYPE r;
1767 15687360 : char buf[128];
1768 15687360 : get_max_float (REAL_MODE_FORMAT (TYPE_MODE (type)),
1769 : buf, sizeof (buf), false);
1770 15687360 : int res = real_from_string (&r, buf);
1771 15687360 : gcc_checking_assert (!res);
1772 15687360 : return r;
1773 : }
1774 :
1775 : // Return the minimum representable value for TYPE.
1776 :
1777 : inline REAL_VALUE_TYPE
1778 8288438 : real_min_representable (const_tree type)
1779 : {
1780 8288438 : REAL_VALUE_TYPE r = real_max_representable (type);
1781 8288438 : r = real_value_negate (&r);
1782 8288438 : return r;
1783 : }
1784 :
1785 : // Return the minimum value for TYPE.
1786 :
1787 : inline REAL_VALUE_TYPE
1788 175235513 : frange_val_min (const_tree type)
1789 : {
1790 175235513 : if (HONOR_INFINITIES (type))
1791 167613718 : return dconstninf;
1792 : else
1793 7621795 : return real_min_representable (type);
1794 : }
1795 :
1796 : // Return the maximum value for TYPE.
1797 :
1798 : inline REAL_VALUE_TYPE
1799 113833997 : frange_val_max (const_tree type)
1800 : {
1801 113833997 : if (HONOR_INFINITIES (type))
1802 107198009 : return dconstinf;
1803 : else
1804 6635988 : return real_max_representable (type);
1805 : }
1806 :
1807 : // Return TRUE if R is the minimum value for TYPE.
1808 :
1809 : inline bool
1810 97671835 : frange_val_is_min (const REAL_VALUE_TYPE &r, const_tree type)
1811 : {
1812 97671835 : REAL_VALUE_TYPE min = frange_val_min (type);
1813 97671835 : return real_identical (&min, &r);
1814 : }
1815 :
1816 : // Return TRUE if R is the max value for TYPE.
1817 :
1818 : inline bool
1819 35869657 : frange_val_is_max (const REAL_VALUE_TYPE &r, const_tree type)
1820 : {
1821 35869657 : REAL_VALUE_TYPE max = frange_val_max (type);
1822 35869657 : return real_identical (&max, &r);
1823 : }
1824 :
1825 : // Build a NAN with a state of NAN.
1826 :
1827 : inline void
1828 427744 : frange::set_nan (tree type, const nan_state &nan)
1829 : {
1830 427744 : gcc_checking_assert (nan.pos_p () || nan.neg_p ());
1831 427744 : if (HONOR_NANS (type))
1832 : {
1833 427743 : m_kind = VR_NAN;
1834 427743 : m_type = type;
1835 427743 : m_num_ranges = 1;
1836 427743 : m_neg_nan = nan.neg_p ();
1837 427743 : m_pos_nan = nan.pos_p ();
1838 427743 : if (flag_checking)
1839 427743 : verify_range ();
1840 : }
1841 : else
1842 1 : set_undefined ();
1843 427744 : }
1844 :
1845 : // Build a signless NAN of type TYPE.
1846 :
1847 : inline void
1848 157259 : frange::set_nan (tree type)
1849 : {
1850 157259 : nan_state nan (true);
1851 157247 : set_nan (type, nan);
1852 : }
1853 :
1854 : // Build a NAN of type TYPE with SIGN.
1855 :
1856 : inline void
1857 189235 : frange::set_nan (tree type, bool sign)
1858 : {
1859 189235 : nan_state nan (/*pos=*/!sign, /*neg=*/sign);
1860 189231 : set_nan (type, nan);
1861 : }
1862 :
1863 : // Return TRUE if range is known to be finite.
1864 :
1865 : inline bool
1866 0 : frange::known_isfinite () const
1867 : {
1868 0 : if (undefined_p () || varying_p () || m_kind == VR_ANTI_RANGE)
1869 : return false;
1870 0 : return (!maybe_isnan ()
1871 0 : && !real_isinf (&lower_bound ())
1872 0 : && !real_isinf (&upper_bound ()));
1873 : }
1874 :
1875 : // Return TRUE if range is known to be normal.
1876 :
1877 : inline bool
1878 0 : frange::known_isnormal () const
1879 : {
1880 0 : if (!known_isfinite ())
1881 : return false;
1882 :
1883 0 : machine_mode mode = TYPE_MODE (type ());
1884 0 : const REAL_VALUE_TYPE &min = lower_bound ();
1885 0 : const REAL_VALUE_TYPE &max = upper_bound ();
1886 0 : return (!real_isdenormal (&min, mode) && !real_isdenormal (&max, mode)
1887 0 : && !real_iszero (&min) && !real_iszero (&max)
1888 0 : && (!real_isneg (&min) || real_isneg (&max)));
1889 : }
1890 :
1891 : // Return TRUE if range is known to be denormal.
1892 :
1893 : inline bool
1894 0 : frange::known_isdenormal_or_zero () const
1895 : {
1896 0 : if (!known_isfinite ())
1897 : return false;
1898 :
1899 0 : machine_mode mode = TYPE_MODE (type ());
1900 0 : const REAL_VALUE_TYPE &min = lower_bound ();
1901 0 : const REAL_VALUE_TYPE &max = upper_bound ();
1902 0 : return ((real_isdenormal (&min, mode) || real_iszero (&min))
1903 0 : && (real_isdenormal (&max, mode) || real_iszero (&max)));
1904 : }
1905 :
1906 : // Return TRUE if range may be infinite.
1907 :
1908 : inline bool
1909 41654 : frange::maybe_isinf () const
1910 : {
1911 41654 : if (undefined_p () || m_kind == VR_ANTI_RANGE || m_kind == VR_NAN)
1912 : return false;
1913 41654 : if (varying_p ())
1914 : return true;
1915 39133 : return real_isinf (&lower_bound ()) || real_isinf (&upper_bound ());
1916 : }
1917 :
1918 : // Return TRUE if range is known to be the [-INF,-INF] or [+INF,+INF].
1919 :
1920 : inline bool
1921 6071288 : frange::known_isinf () const
1922 : {
1923 6071288 : return (m_kind == VR_RANGE
1924 1682374 : && m_num_ranges == 1
1925 8732796 : && !maybe_isnan ()
1926 1330748 : && real_identical (&m_pairs[0].min, &m_pairs[0].max)
1927 6108711 : && real_isinf (&m_pairs[0].min));
1928 : }
1929 :
1930 : // Return TRUE if range is possibly a NAN.
1931 :
1932 : inline bool
1933 20688449 : frange::maybe_isnan () const
1934 : {
1935 18861858 : if (undefined_p ())
1936 : return false;
1937 20683963 : return m_pos_nan || m_neg_nan;
1938 : }
1939 :
1940 : // Return TRUE if range is possibly a NAN with SIGN.
1941 :
1942 : inline bool
1943 158026 : frange::maybe_isnan (bool sign) const
1944 : {
1945 158026 : if (undefined_p ())
1946 : return false;
1947 158026 : if (sign)
1948 158026 : return m_neg_nan;
1949 : return m_pos_nan;
1950 : }
1951 :
1952 : // Return TRUE if range is a +NAN or -NAN.
1953 :
1954 : inline bool
1955 30030314 : frange::known_isnan () const
1956 : {
1957 25685097 : return m_kind == VR_NAN;
1958 : }
1959 :
1960 : // If the signbit for the range is known, set it in SIGNBIT and return
1961 : // TRUE.
1962 :
1963 : inline bool
1964 1712106 : frange::signbit_p (bool &signbit) const
1965 : {
1966 1712106 : if (undefined_p ())
1967 : return false;
1968 :
1969 : // NAN with unknown sign.
1970 1712092 : if (m_pos_nan && m_neg_nan)
1971 : return false;
1972 : // No NAN.
1973 118670 : if (!m_pos_nan && !m_neg_nan)
1974 : {
1975 97117 : if (lower_bound ().sign == upper_bound ().sign)
1976 : {
1977 19979 : signbit = lower_bound ().sign;
1978 19979 : return true;
1979 : }
1980 : return false;
1981 : }
1982 : // NAN with known sign.
1983 21553 : bool nan_sign = m_neg_nan;
1984 21553 : if (known_isnan ()
1985 21553 : || (nan_sign == lower_bound ().sign
1986 20216 : && nan_sign == upper_bound ().sign))
1987 : {
1988 20353 : signbit = nan_sign;
1989 20353 : return true;
1990 : }
1991 : return false;
1992 : }
1993 :
1994 : // If range has a NAN with a known sign, set it in SIGNBIT and return
1995 : // TRUE.
1996 :
1997 : inline bool
1998 49729 : frange::nan_signbit_p (bool &signbit) const
1999 : {
2000 49729 : if (undefined_p ())
2001 : return false;
2002 :
2003 49729 : if (m_pos_nan == m_neg_nan)
2004 : return false;
2005 :
2006 2245 : signbit = m_neg_nan;
2007 2245 : return true;
2008 : }
2009 :
2010 : void frange_nextafter (enum machine_mode, REAL_VALUE_TYPE &,
2011 : const REAL_VALUE_TYPE &);
2012 : void frange_arithmetic (enum tree_code, tree, REAL_VALUE_TYPE &,
2013 : const REAL_VALUE_TYPE &, const REAL_VALUE_TYPE &,
2014 : const REAL_VALUE_TYPE &);
2015 :
2016 : // Return true if TYPE1 and TYPE2 are compatible range types.
2017 :
2018 : inline bool
2019 1928349776 : range_compatible_p (tree type1, tree type2)
2020 : {
2021 : // types_compatible_p requires conversion in both directions to be useless.
2022 : // GIMPLE only requires a cast one way in order to be compatible.
2023 : // Ranges really only need the sign and precision to be the same.
2024 1928349776 : return (TYPE_PRECISION (type1) == TYPE_PRECISION (type2)
2025 1928349776 : && TYPE_SIGN (type1) == TYPE_SIGN (type2));
2026 : }
2027 : #endif // GCC_VALUE_RANGE_H
|