diff options
author | Aldy Hernandez <aldyh@gcc.gnu.org> | 2019-06-26 17:07:35 +0000 |
---|---|---|
committer | Aldy Hernandez <aldyh@gcc.gnu.org> | 2019-06-26 17:07:35 +0000 |
commit | 2be2b98da0f3031622962d145b906a8f9ee1c28f (patch) | |
tree | 7f40a01e7f0a44bb317596f3e558189521e1aaa9 | |
parent | 926261fd2c3f669b889f9a60042452c72c47f62b (diff) | |
download | gcc-2be2b98da0f3031622962d145b906a8f9ee1c28f.zip gcc-2be2b98da0f3031622962d145b906a8f9ee1c28f.tar.gz gcc-2be2b98da0f3031622962d145b906a8f9ee1c28f.tar.bz2 |
Remove irange_kind in favor of one global value_range_kind.
From-SVN: r272702
-rw-r--r-- | gcc/calls.c | 4 | ||||
-rw-r--r-- | gcc/coretypes.h | 18 | ||||
-rw-r--r-- | gcc/gimple-ssa-warn-alloca.c | 2 | ||||
-rw-r--r-- | gcc/range-op.c | 11 | ||||
-rw-r--r-- | gcc/range.c | 35 | ||||
-rw-r--r-- | gcc/range.h | 13 | ||||
-rw-r--r-- | gcc/ssa-range.cc | 4 | ||||
-rw-r--r-- | gcc/tree-vrp.c | 12 | ||||
-rw-r--r-- | gcc/tree-vrp.h | 15 | ||||
-rw-r--r-- | gcc/wide-int-range.cc | 16 | ||||
-rw-r--r-- | gcc/wide-int-range.h | 8 |
11 files changed, 64 insertions, 74 deletions
diff --git a/gcc/calls.c b/gcc/calls.c index dc624eb..79cb8d0 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -1292,7 +1292,7 @@ get_size_range (tree exp, tree range[2], bool allow_zero /* = false */, if (allow_zero) r = range_zero (exptype); else - r.intersect (irange (IRANGE_INVERSE, exptype, + r.intersect (irange (VR_ANTI_RANGE, exptype, r.lower_bound (0), r.upper_bound (0))); range[0] = wide_int_to_tree (exptype, r.lower_bound ()); @@ -1315,7 +1315,7 @@ get_size_range (tree exp, tree range[2], bool allow_zero /* = false */, } /* This will transform [5,10][20,MAX] into [5,10]. */ else if (r.upper_bound () == wi::to_wide (TYPE_MAX_VALUE (exptype))) - r.intersect (irange (IRANGE_INVERSE, exptype, + r.intersect (irange (VR_ANTI_RANGE, exptype, r.lower_bound (r.num_pairs () - 1), r.upper_bound (r.num_pairs () - 1))); } diff --git a/gcc/coretypes.h b/gcc/coretypes.h index 2f6b859..4bb1282 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -202,6 +202,24 @@ enum profile_update { PROFILE_UPDATE_PREFER_ATOMIC }; +/* Types of ranges. + + This is still prefixed with VR_*, even though it is more general + purpose, to avoid having to replace everything across the compiler. + Perhaps we should change it later. */ +enum value_range_kind { + /* Empty range. */ + VR_UNDEFINED, + /* Range spans the entire domain. */ + VR_VARYING, + /* Range is [MIN, MAX]. */ + VR_RANGE, + /* Range is ~[MIN, MAX]. */ + VR_ANTI_RANGE, + /* Range is a nice guy. */ + VR_LAST +}; + /* Types of unwind/exception handling info that can be generated. */ enum unwind_info_type diff --git a/gcc/gimple-ssa-warn-alloca.c b/gcc/gimple-ssa-warn-alloca.c index 4b028aa..469b099 100644 --- a/gcc/gimple-ssa-warn-alloca.c +++ b/gcc/gimple-ssa-warn-alloca.c @@ -235,7 +235,7 @@ alloca_call_type (global_ranger &ranger, gimple *stmt, bool is_vla) && !r.varying_p ()) { // The invalid bits are anything outside of [0, MAX_SIZE]. - static irange invalid_range (IRANGE_INVERSE, + static irange invalid_range (VR_ANTI_RANGE, build_int_cst (size_type_node, 0), build_int_cst (size_type_node, max_size)); diff --git a/gcc/range-op.c b/gcc/range-op.c index d64be6d..750c82b 100644 --- a/gcc/range-op.c +++ b/gcc/range-op.c @@ -176,18 +176,17 @@ accumulate_range (irange &r, const wide_int &ub, wi::overflow_type ov_ub, bool overflow_wraps = false) { - wide_int_range_kind kind; + value_range_kind kind; wide_int min = lb, max = ub; tree type = r.type (); adjust_range_for_overflow (kind, min, max, type, ov_lb, ov_ub, overflow_wraps); - if (kind == WIDE_INT_RANGE_VARYING) + if (kind == VR_VARYING) { r.set_varying (type); return; } - irange tmp (kind == WIDE_INT_RANGE_PLAIN ? IRANGE_PLAIN : IRANGE_INVERSE, - type, min, max); + irange tmp (kind, type, min, max); r.union_ (tmp); return; } @@ -1531,10 +1530,10 @@ operator_cast::op1_range (irange& r, const irange& lhs, which implies the only value *not* in the RHS is 0 or -1. */ unsigned prec = TYPE_PRECISION (op2_type); if (lhs.zero_p ()) - r = irange (IRANGE_INVERSE, op2_type, + r = irange (VR_ANTI_RANGE, op2_type, wi::minus_one (prec), wi::minus_one (prec)); else - r = irange (IRANGE_INVERSE, op2_type, + r = irange (VR_ANTI_RANGE, op2_type, wi::zero (prec), wi::zero (prec)); /* And intersect it with what we know about op2. */ r.intersect (op2); diff --git a/gcc/range.c b/gcc/range.c index 4b2c68d..7ff2475 100644 --- a/gcc/range.c +++ b/gcc/range.c @@ -183,7 +183,7 @@ range_zero (tree type) irange range_nonzero (tree type) { - return irange (IRANGE_INVERSE, + return irange (VR_ANTI_RANGE, build_zero_cst (type), build_zero_cst (type)); } @@ -229,14 +229,18 @@ subtract_one (const wide_int &x, tree type, wi::overflow_type &overflow) void irange::init (tree type, const wide_int &lbound, const wide_int &ubound, - irange_kind rt) + value_range_kind rt) { + // Even though we accept a full value_range_kind, we *ONLY* use it to + // distinguish a plain range from an inverse range. + gcc_checking_assert (rt == VR_RANGE || rt == VR_ANTI_RANGE); + gcc_checking_assert (irange::supports_type_p (type)); gcc_checking_assert (TYPE_PRECISION (type) == lbound.get_precision ()); gcc_checking_assert (lbound.get_precision () == ubound.get_precision ()); m_type = type; gcc_checking_assert (wi::le_p (lbound, ubound, TYPE_SIGN (type))); - if (rt == IRANGE_INVERSE) + if (rt == VR_ANTI_RANGE) { // Calculate INVERSE([I,J]) as [-MIN, I-1][J+1, +MAX]. wi::overflow_type ovf; @@ -280,19 +284,21 @@ irange::irange (tree type) set_varying (type); } -irange::irange (irange_kind rt, tree type, +irange::irange (value_range_kind rt, tree type, const wide_int &lbound, const wide_int &ubound) { + gcc_checking_assert (rt == VR_RANGE || rt == VR_ANTI_RANGE); init (type, lbound, ubound, rt); } irange::irange (tree type, const wide_int &lbound, const wide_int &ubound) { - init (type, lbound, ubound, IRANGE_PLAIN); + init (type, lbound, ubound, VR_RANGE); } -irange::irange (irange_kind rt, tree lbound, tree ubound) +irange::irange (value_range_kind rt, tree lbound, tree ubound) { + gcc_checking_assert (rt == VR_RANGE || rt == VR_ANTI_RANGE); tree type = TREE_TYPE (lbound); init (type, wi::to_wide (lbound), wi::to_wide (ubound), rt); } @@ -300,7 +306,7 @@ irange::irange (irange_kind rt, tree lbound, tree ubound) irange::irange (tree lbound, tree ubound) { tree type = TREE_TYPE (lbound); - init (type, wi::to_wide (lbound), wi::to_wide (ubound), IRANGE_PLAIN); + init (type, wi::to_wide (lbound), wi::to_wide (ubound), VR_RANGE); } // Mark pair [i, j] to empty. This is done by building a non-sensical pair. @@ -397,7 +403,7 @@ irange::cast (tree new_type) { // Don't use range_nonzero because it will recurse into cast(). unsigned prec = TYPE_PRECISION (new_type); - irange nz (IRANGE_INVERSE, new_type, + irange nz (VR_ANTI_RANGE, new_type, wi::zero (prec), wi::zero (prec)); *this = nz; } @@ -1046,8 +1052,7 @@ value_range_to_irange (tree type, enum value_range_kind kind, if (kind == VR_VARYING || kind == VR_UNDEFINED) r.set_varying (type); else - r = irange (kind == VR_ANTI_RANGE ? IRANGE_INVERSE : IRANGE_PLAIN, - type, min, max); + r = irange (kind, type, min, max); return r; } @@ -1106,7 +1111,7 @@ irange_tests () irange r0, r1, rold; // Test that NOT(255) is [0..254] in 8-bit land. - irange not_255 (IRANGE_INVERSE, UCHAR (255), UCHAR (255)); + irange not_255 (VR_ANTI_RANGE, UCHAR (255), UCHAR (255)); ASSERT_TRUE (not_255 == irange (UCHAR (0), UCHAR (254))); // Test that NOT(0) is [1..255] in 8-bit land. @@ -1147,17 +1152,17 @@ irange_tests () ASSERT_TRUE (r0 == irange (UINT(6), maxuint)); // Check that ~[10,MAX] => [0,9] for unsigned int. - r0 = irange (IRANGE_PLAIN, UINT(10), maxuint); + r0 = irange (VR_RANGE, UINT(10), maxuint); r0.invert (); ASSERT_TRUE (r0 == irange (UINT (0), UINT (9))); // Check that ~[0,5] => [6,MAX] for unsigned 128-bit numbers. - r0 = irange (IRANGE_INVERSE, UINT128 (0), UINT128 (5)); + r0 = irange (VR_ANTI_RANGE, UINT128 (0), UINT128 (5)); r1 = irange (UINT128(6), build_minus_one_cst (u128_type)); ASSERT_TRUE (r0 == r1); // Check that [~5] is really [-MIN,4][6,MAX]. - r0 = irange (IRANGE_INVERSE, INT (5), INT (5)); + r0 = irange (VR_ANTI_RANGE, INT (5), INT (5)); r1 = irange (minint, INT (4)); r1.union_ (irange (INT (6), maxint)); ASSERT_FALSE (r1.undefined_p ()); @@ -1570,7 +1575,7 @@ irange_tests () ASSERT_TRUE (r0.nonzero_p ()); // Test irange / value_range conversion functions. - r0 = irange (IRANGE_INVERSE, INT (10), INT (20)); + r0 = irange (VR_ANTI_RANGE, INT (10), INT (20)); value_range_base vr = irange_to_value_range (r0); ASSERT_TRUE (vr.kind () == VR_ANTI_RANGE); ASSERT_TRUE (wi::eq_p (10, wi::to_wide (vr.min ())) diff --git a/gcc/range.h b/gcc/range.h index 281be4e..ec13c40 100644 --- a/gcc/range.h +++ b/gcc/range.h @@ -25,11 +25,8 @@ along with GCC; see the file COPYING3. If not see #define IRANGE_WITH_VALUE_RANGE 0 #if IRANGE_WITH_VALUE_RANGE -#include "tree-vrp.h" typedef value_range_base irange; typedef value_range_storage irange_storage; -#define IRANGE_PLAIN VR_RANGE -#define IRANGE_INVERSE VR_ANTI_RANGE #else // This is the standalone irange implementation. @@ -57,8 +54,6 @@ class irange_storage; // Consequently, there are no GTY markers. For long term storage, use // the irange_storage class described later. -enum irange_kind { IRANGE_PLAIN, IRANGE_INVERSE }; - class irange { friend class irange_storage; @@ -67,9 +62,9 @@ class irange public: irange (); irange (tree type); - irange (irange_kind, tree type, const wide_int &, const wide_int &); + irange (value_range_kind, tree type, const wide_int &, const wide_int &); irange (tree type, const wide_int &, const wide_int &); - irange (irange_kind, tree, tree); + irange (value_range_kind, tree, tree); irange (tree, tree); irange (tree type, const irange_storage *); @@ -110,7 +105,7 @@ class irange private: void init (tree type, const wide_int &, const wide_int &, - irange_kind = IRANGE_PLAIN); + value_range_kind = VR_RANGE); void canonicalize (); void set_lower_bound (unsigned pair, const wide_int &); void set_upper_bound (unsigned pair, const wide_int &); @@ -193,7 +188,7 @@ inline bool irange::nonzero_p () const { unsigned prec = TYPE_PRECISION (m_type); - return *this == irange (IRANGE_INVERSE, m_type, + return *this == irange (VR_ANTI_RANGE, m_type, wi::zero (prec), wi::zero (prec)); } diff --git a/gcc/ssa-range.cc b/gcc/ssa-range.cc index 14328d7..3691988 100644 --- a/gcc/ssa-range.cc +++ b/gcc/ssa-range.cc @@ -188,7 +188,7 @@ switch_edge_manager::calc_switch_ranges (gswitch *sw) if (!high) high = low; - irange def_case_range (IRANGE_INVERSE, low, high); + irange def_case_range (VR_ANTI_RANGE, low, high); def_case_range.cast (type); default_slot->intersect (def_case_range); @@ -253,7 +253,7 @@ switch_edge_manager::calc_single_range (irange &r, gswitch *sw, edge e) tree high = CASE_HIGH (gimple_switch_label (sw, x)); if (!high) high = low; - irange case_range (IRANGE_INVERSE, low, high); + irange case_range (VR_ANTI_RANGE, low, high); r.intersect (case_range); } } diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index aeaa8fd..9f36407 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1630,21 +1630,15 @@ extract_range_from_plus_expr (value_range_base *vr, return; } - wide_int_range_kind wi_kind; - adjust_range_for_overflow (wi_kind, wmin, wmax, expr_type, + adjust_range_for_overflow (type, wmin, wmax, expr_type, min_ovf, max_ovf, TYPE_OVERFLOW_WRAPS (expr_type)); - if (wi_kind == WIDE_INT_RANGE_VARYING) + if (type == VR_VARYING) { vr->set_varying (expr_type); return; } - if (wi_kind == WIDE_INT_RANGE_PLAIN) - type = VR_RANGE; - else if (wi_kind == WIDE_INT_RANGE_INVERSE) - type = VR_ANTI_RANGE; - else - gcc_unreachable (); + gcc_assert (type != VR_UNDEFINED); min = wide_int_to_tree (expr_type, wmin); max = wide_int_to_tree (expr_type, wmax); diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h index 875c506..189b896 100644 --- a/gcc/tree-vrp.h +++ b/gcc/tree-vrp.h @@ -20,21 +20,6 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_TREE_VRP_H #define GCC_TREE_VRP_H -/* Types of value ranges. */ -enum value_range_kind -{ - /* Empty range. */ - VR_UNDEFINED, - /* Range spans the entire domain. */ - VR_VARYING, - /* Range is [MIN, MAX]. */ - VR_RANGE, - /* Range is ~[MIN, MAX]. */ - VR_ANTI_RANGE, - /* Range is a nice guy. */ - VR_LAST -}; - class value_range_storage; /* Range of values that can be associated with an SSA_NAME after VRP diff --git a/gcc/wide-int-range.cc b/gcc/wide-int-range.cc index 36a4c70..5f81f21 100644 --- a/gcc/wide-int-range.cc +++ b/gcc/wide-int-range.cc @@ -873,7 +873,7 @@ wide_int_range_div (wide_int &wmin, wide_int &wmax, occurred while originally calculating WMIN or WMAX. */ void -adjust_range_for_overflow (wide_int_range_kind &kind, +adjust_range_for_overflow (value_range_kind &kind, wide_int &wmin, wide_int &wmax, tree type, wi::overflow_type min_ovf, @@ -887,7 +887,7 @@ adjust_range_for_overflow (wide_int_range_kind &kind, range covers all values. */ if (prec == 1 && wi::lt_p (wmax, wmin, sgn)) { - kind = WIDE_INT_RANGE_VARYING; + kind = VR_VARYING; return; } @@ -903,10 +903,10 @@ adjust_range_for_overflow (wide_int_range_kind &kind, the entire range. We have a similar check at the end of extract_range_from_binary_expr. */ if (wi::gt_p (tmin, tmax, sgn)) - kind = WIDE_INT_RANGE_VARYING; + kind = VR_VARYING; else { - kind = WIDE_INT_RANGE_PLAIN; + kind = VR_RANGE; /* No overflow or both overflow or underflow. The range kind stays VR_RANGE. */ wmin = tmin; @@ -932,10 +932,10 @@ adjust_range_for_overflow (wide_int_range_kind &kind, types values. */ if (covers || wi::cmp (tmin, tmax, sgn) > 0) { - kind = WIDE_INT_RANGE_VARYING; + kind = VR_VARYING; return; } - kind = WIDE_INT_RANGE_INVERSE; + kind = VR_ANTI_RANGE; wmin = tmin; wmax = tmax; return; @@ -943,7 +943,7 @@ adjust_range_for_overflow (wide_int_range_kind &kind, else { /* Other underflow and/or overflow, drop to VR_VARYING. */ - kind = WIDE_INT_RANGE_VARYING; + kind = VR_VARYING; return; } } @@ -953,7 +953,7 @@ adjust_range_for_overflow (wide_int_range_kind &kind, value. */ wide_int type_min = wi::min_value (prec, sgn); wide_int type_max = wi::max_value (prec, sgn); - kind = WIDE_INT_RANGE_PLAIN; + kind = VR_RANGE; if (min_ovf == wi::OVF_UNDERFLOW) wmin = type_min; else if (min_ovf == wi::OVF_OVERFLOW) diff --git a/gcc/wide-int-range.h b/gcc/wide-int-range.h index fd1013b..2592f9c 100644 --- a/gcc/wide-int-range.h +++ b/gcc/wide-int-range.h @@ -185,14 +185,8 @@ wide_int_range_zero_p (const wide_int &wmin, const wide_int &wmax, return wmin == wmax && wi::eq_p (wmin, wi::zero (prec)); } -enum wide_int_range_kind { - WIDE_INT_RANGE_PLAIN, - WIDE_INT_RANGE_INVERSE, - WIDE_INT_RANGE_VARYING -}; - void -adjust_range_for_overflow (wide_int_range_kind &, +adjust_range_for_overflow (value_range_kind &, wide_int &, wide_int &, tree type, wi::overflow_type, wi::overflow_type, |