diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2023-06-09 13:41:28 -0400 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2023-06-09 20:33:03 -0400 |
commit | 29dbd7ef69fe1375055ada081af88e3a8919fff0 (patch) | |
tree | c7dc22136fd6a0fc3ae6849e2d4fe07262d66f47 /gcc/range-op-float.cc | |
parent | 6a4ac393e199a63f39063daa28827f39dab49a07 (diff) | |
download | gcc-29dbd7ef69fe1375055ada081af88e3a8919fff0.zip gcc-29dbd7ef69fe1375055ada081af88e3a8919fff0.tar.gz gcc-29dbd7ef69fe1375055ada081af88e3a8919fff0.tar.bz2 |
Unify PLUS_EXPR range operator
Move the declaration of the class to the range-op-mixed header, add the
floating point prototypes as well, and use it in the new unified table.
* range-op-float.cc (foperator_plus): Remove. Move prototypes
to range-op-mixed.h
(operator_plus::fold_range): Rename from foperator_plus.
(operator_plus::op1_range): Ditto.
(operator_plus::op2_range): Ditto.
(operator_plus::rv_fold): Ditto.
(float_table::float_table): Remove PLUS_EXPR.
* range-op-mixed.h (class operator_plus): Combined from integer
and float files.
* range-op.cc (op_plus): New object.
(unified_table::unified_table): Add PLUS_EXPR.
(class operator_plus): Move to range-op-mixed.h.
(integral_table::integral_table): Remove PLUS_EXPR.
(pointer_table::pointer_table): Remove PLUS_EXPR.
Diffstat (limited to 'gcc/range-op-float.cc')
-rw-r--r-- | gcc/range-op-float.cc | 94 |
1 files changed, 44 insertions, 50 deletions
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 11d76f2..bd1b792 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -2254,54 +2254,49 @@ float_widen_lhs_range (tree type, const frange &lhs) return ret; } -class foperator_plus : public range_operator +bool +operator_plus::op1_range (frange &r, tree type, const frange &lhs, + const frange &op2, relation_trio) const { - using range_operator::op1_range; - using range_operator::op2_range; -public: - virtual bool op1_range (frange &r, tree type, - const frange &lhs, - const frange &op2, - relation_trio = TRIO_VARYING) const final override - { - if (lhs.undefined_p ()) - return false; - range_op_handler minus (MINUS_EXPR, type); - if (!minus) - return false; - frange wlhs = float_widen_lhs_range (type, lhs); - return float_binary_op_range_finish (minus.fold_range (r, type, wlhs, op2), - r, type, wlhs); - } - virtual bool op2_range (frange &r, tree type, - const frange &lhs, - const frange &op1, - relation_trio = TRIO_VARYING) const final override - { - return op1_range (r, type, lhs, op1); - } -private: - void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan, - tree type, - const REAL_VALUE_TYPE &lh_lb, - const REAL_VALUE_TYPE &lh_ub, - const REAL_VALUE_TYPE &rh_lb, - const REAL_VALUE_TYPE &rh_ub, - relation_kind) const final override - { - frange_arithmetic (PLUS_EXPR, type, lb, lh_lb, rh_lb, dconstninf); - frange_arithmetic (PLUS_EXPR, type, ub, lh_ub, rh_ub, dconstinf); + if (lhs.undefined_p ()) + return false; + range_op_handler minus (MINUS_EXPR, type); + if (!minus) + return false; + frange wlhs = float_widen_lhs_range (type, lhs); + return float_binary_op_range_finish (minus.fold_range (r, type, wlhs, op2), + r, type, wlhs); +} - // [-INF] + [+INF] = NAN - if (real_isinf (&lh_lb, true) && real_isinf (&rh_ub, false)) - maybe_nan = true; - // [+INF] + [-INF] = NAN - else if (real_isinf (&lh_ub, false) && real_isinf (&rh_lb, true)) - maybe_nan = true; - else - maybe_nan = false; - } -} fop_plus; +bool +operator_plus::op2_range (frange &r, tree type, + const frange &lhs, const frange &op1, + relation_trio) const +{ + return op1_range (r, type, lhs, op1); +} + +void +operator_plus::rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, + bool &maybe_nan, tree type, + const REAL_VALUE_TYPE &lh_lb, + const REAL_VALUE_TYPE &lh_ub, + const REAL_VALUE_TYPE &rh_lb, + const REAL_VALUE_TYPE &rh_ub, + relation_kind) const +{ + frange_arithmetic (PLUS_EXPR, type, lb, lh_lb, rh_lb, dconstninf); + frange_arithmetic (PLUS_EXPR, type, ub, lh_ub, rh_ub, dconstinf); + + // [-INF] + [+INF] = NAN + if (real_isinf (&lh_lb, true) && real_isinf (&rh_ub, false)) + maybe_nan = true; + // [+INF] + [-INF] = NAN + else if (real_isinf (&lh_ub, false) && real_isinf (&rh_lb, true)) + maybe_nan = true; + else + maybe_nan = false; +} class foperator_minus : public range_operator @@ -2317,9 +2312,9 @@ public: if (lhs.undefined_p ()) return false; frange wlhs = float_widen_lhs_range (type, lhs); - return float_binary_op_range_finish (fop_plus.fold_range (r, type, wlhs, - op2), - r, type, wlhs); + return float_binary_op_range_finish ( + range_op_handler (PLUS_EXPR).fold_range (r, type, wlhs, op2), + r, type, wlhs); } virtual bool op2_range (frange &r, tree type, const frange &lhs, @@ -2698,7 +2693,6 @@ float_table::float_table () { set (ABS_EXPR, fop_abs); set (NEGATE_EXPR, fop_negate); - set (PLUS_EXPR, fop_plus); set (MINUS_EXPR, fop_minus); set (MULT_EXPR, fop_mult); } |