]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Unify PLUS_EXPR range operator
authorAndrew MacLeod <amacleod@redhat.com>
Fri, 9 Jun 2023 17:41:28 +0000 (13:41 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Sat, 10 Jun 2023 00:33:03 +0000 (20:33 -0400)
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.

gcc/range-op-float.cc
gcc/range-op-mixed.h
gcc/range-op.cc

index 11d76f2ef2546a5872673928b01f82c14744ca46..bd1b79281d06d7e7b6cd4ff29e68fe120aadec42 100644 (file)
@@ -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);
 }
index 9de8479cd2462bab6025ca65ff9742be7a735498..fbfe3f825a3570bfa8821bde47669ed213729187 100644 (file)
@@ -328,4 +328,43 @@ private:
                           const irange &outer) const;
 };
 
+class operator_plus : public range_operator
+{
+public:
+  using range_operator::op1_range;
+  using range_operator::op2_range;
+  using range_operator::lhs_op1_relation;
+  using range_operator::lhs_op2_relation;
+  bool op1_range (irange &r, tree type,
+                 const irange &lhs, const irange &op2,
+                 relation_trio) const final override;
+  bool op1_range (frange &r, tree type,
+                 const frange &lhs, const frange &op2,
+                 relation_trio = TRIO_VARYING) const final override;
+
+  bool op2_range (irange &r, tree type,
+                 const irange &lhs, const irange &op1,
+                 relation_trio) const final override;
+  bool op2_range (frange &r, tree type,
+                 const frange &lhs, const frange &op1,
+                 relation_trio = TRIO_VARYING) const final override;
+
+  relation_kind lhs_op1_relation (const irange &lhs, const irange &op1,
+                                 const irange &op2,
+                                 relation_kind rel) const final override;
+  relation_kind lhs_op2_relation (const irange &lhs, const irange &op1,
+                                 const irange &op2,
+                                 relation_kind rel) const final override;
+  void update_bitmask (irange &r, const irange &lh,
+                      const irange &rh) const final override;
+private:
+  void wi_fold (irange &r, tree type, const wide_int &lh_lb,
+               const wide_int &lh_ub, const wide_int &rh_lb,
+               const wide_int &rh_ub) const final override;
+  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;
+};
 #endif // GCC_RANGE_OP_MIXED_H
index 7d89b633da3b168349a0fa84785eced1c31a8c82..1dc5c38ef633f17733ddc70e6fd29b31975f19bb 100644 (file)
@@ -71,6 +71,7 @@ operator_ge op_ge;
 operator_identity op_ident;
 operator_cst op_cst;
 operator_cast op_cast;
+operator_plus op_plus;
 
 // Invoke the initialization routines for each class of range.
 
@@ -93,7 +94,7 @@ unified_table::unified_table ()
   set (INTEGER_CST, op_cst);
   set (NOP_EXPR, op_cast);
   set (CONVERT_EXPR, op_cast);
-
+  set (PLUS_EXPR, op_plus);
 }
 
 // The tables are hidden and accessed via a simple extern function.
@@ -1498,35 +1499,12 @@ operator_ge::op2_range (irange &r, tree type,
 }
 
 
-class operator_plus : public range_operator
+void
+operator_plus::update_bitmask (irange &r, const irange &lh,
+                              const irange &rh) const
 {
-  using range_operator::op1_range;
-  using range_operator::op2_range;
-  using range_operator::lhs_op1_relation;
-  using range_operator::lhs_op2_relation;
-public:
-  virtual bool op1_range (irange &r, tree type,
-                         const irange &lhs,
-                         const irange &op2,
-                         relation_trio) const;
-  virtual bool op2_range (irange &r, tree type,
-                         const irange &lhs,
-                         const irange &op1,
-                         relation_trio) const;
-  virtual void wi_fold (irange &r, tree type,
-                       const wide_int &lh_lb,
-                       const wide_int &lh_ub,
-                       const wide_int &rh_lb,
-                       const wide_int &rh_ub) const;
-  virtual relation_kind lhs_op1_relation (const irange &lhs, const irange &op1,
-                                         const irange &op2,
-                                         relation_kind rel) const;
-  virtual relation_kind lhs_op2_relation (const irange &lhs, const irange &op1,
-                                         const irange &op2,
-                                         relation_kind rel) const;
-  void update_bitmask (irange &r, const irange &lh, const irange &rh) const
-    { update_known_bitmask (r, PLUS_EXPR, lh, rh); }
-} op_plus;
+  update_known_bitmask (r, PLUS_EXPR, lh, rh);
+}
 
 // Check to see if the range of OP2 indicates anything about the relation
 // between LHS and OP1.
@@ -4717,7 +4695,6 @@ pointer_or_operator::wi_fold (irange &r, tree type,
 \f
 integral_table::integral_table ()
 {
-  set (PLUS_EXPR, op_plus);
   set (MINUS_EXPR, op_minus);
   set (MIN_EXPR, op_min);
   set (MAX_EXPR, op_max);