]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Unify EQ_EXPR range operator
authorAndrew MacLeod <amacleod@redhat.com>
Fri, 9 Jun 2023 17:18:39 +0000 (13:18 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Sat, 10 Jun 2023 00:33:02 +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_equal): Remove.  Move prototypes
to range-op-mixed.h
(operator_equal::fold_range): Rename from foperator_equal.
(operator_equal::op1_range): Ditto.
(float_table::float_table): Remove EQ_EXPR.
* range-op-mixed.h (class operator_equal): Combined from integer
and float files.
* range-op.cc (op_equal): New object.
(unified_table::unified_table): Add EQ_EXPR.
(class operator_equal): Move to range-op-mixed.h.
(equal_op1_op2_relation): Fold into
operator_equal::op1_op2_relation.
(integral_table::integral_table): Remove EQ_EXPR.
(pointer_table::pointer_table): Remove EQ_EXPR.
* range-op.h (equal_op1_op2_relation): Delete.

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

index 8659217659cb2d1cb76f0fa012af2ae03469207c..98636cec8cfd6a7af66091f368617569bc1549ab 100644 (file)
@@ -563,35 +563,18 @@ public:
 public:
 } fop_identity;
 
-class foperator_equal : public range_operator
+bool
+operator_equal::op2_range (frange &r, tree type,
+                          const irange &lhs, const frange &op1,
+                          relation_trio rel) const
 {
-  using range_operator::fold_range;
-  using range_operator::op1_range;
-  using range_operator::op2_range;
-  using range_operator::op1_op2_relation;
-public:
-  bool fold_range (irange &r, tree type,
-                  const frange &op1, const frange &op2,
-                  relation_trio = TRIO_VARYING) const final override;
-  relation_kind op1_op2_relation (const irange &lhs) const final override
-  {
-    return equal_op1_op2_relation (lhs);
-  }
-  bool op1_range (frange &r, tree type,
-                 const irange &lhs, const frange &op2,
-                 relation_trio = TRIO_VARYING) const final override;
-  bool op2_range (frange &r, tree type,
-                 const irange &lhs, const frange &op1,
-                 relation_trio rel = TRIO_VARYING) const final override
-  {
-    return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
-  }
-} fop_equal;
+  return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
+}
 
 bool
-foperator_equal::fold_range (irange &r, tree type,
-                            const frange &op1, const frange &op2,
-                            relation_trio rel) const
+operator_equal::fold_range (irange &r, tree type,
+                           const frange &op1, const frange &op2,
+                           relation_trio rel) const
 {
   if (frelop_early_resolve (r, type, op1, op2, rel, VREL_EQ))
     return true;
@@ -644,7 +627,7 @@ foperator_equal::fold_range (irange &r, tree type,
 }
 
 bool
-foperator_equal::op1_range (frange &r, tree type,
+operator_equal::op1_range (frange &r, tree type,
                            const irange &lhs,
                            const frange &op2,
                            relation_trio trio) const
@@ -2021,7 +2004,8 @@ public:
       op1_no_nan.clear_nan ();
     if (op2.maybe_isnan ())
       op2_no_nan.clear_nan ();
-    if (!fop_equal.fold_range (r, type, op1_no_nan, op2_no_nan, rel))
+    if (!range_op_handler (EQ_EXPR).fold_range (r, type, op1_no_nan,
+                                               op2_no_nan, rel))
       return false;
     // The result is the same as the ordered version when the
     // comparison is true or when the operands cannot be NANs.
@@ -2819,7 +2803,6 @@ float_table::float_table ()
   // All the relational operators are expected to work, because the
   // calculation of ranges on outgoing edges expect the handlers to be
   // present.
-  set (EQ_EXPR, fop_equal);
   set (NE_EXPR, fop_not_equal);
   set (LT_EXPR, fop_lt);
   set (LE_EXPR, fop_le);
index a78bc2ba59c2ae4bcd380f6f21ed53c106642718..79e2cbd8532ee4e904c3fb363383589c22f78ce5 100644 (file)
@@ -75,4 +75,41 @@ relop_early_resolve (irange &r, tree type, const vrange &op1,
   return false;
 }
 
+// ----------------------------------------------------------------------
+//                          Mixed Mode Operators.
+// ----------------------------------------------------------------------
+
+class operator_equal : public range_operator
+{
+public:
+  using range_operator::fold_range;
+  using range_operator::op1_range;
+  using range_operator::op2_range;
+  using range_operator::op1_op2_relation;
+  bool fold_range (irange &r, tree type,
+                  const irange &op1, const irange &op2,
+                  relation_trio = TRIO_VARYING) const final override;
+  bool fold_range (irange &r, tree type,
+                  const frange &op1, const frange &op2,
+                  relation_trio = TRIO_VARYING) const final override;
+
+  bool op1_range (irange &r, tree type,
+                 const irange &lhs, const irange &val,
+                 relation_trio = TRIO_VARYING) const final override;
+  bool op1_range (frange &r, tree type,
+                 const irange &lhs, const frange &op2,
+                 relation_trio = TRIO_VARYING) const final override;
+
+  bool op2_range (irange &r, tree type,
+                 const irange &lhs, const irange &val,
+                 relation_trio = TRIO_VARYING) const final override;
+  bool op2_range (frange &r, tree type,
+                 const irange &lhs, const frange &op1,
+                 relation_trio rel = TRIO_VARYING) const final override;
+
+  relation_kind op1_op2_relation (const irange &lhs) const final override;
+  void update_bitmask (irange &r, const irange &lh,
+                      const irange &rh) const final override;
+};
+
 #endif // GCC_RANGE_OP_MIXED_H
index 4e00c9f439e3cd7f2b5b9741e390629f31227e60..e85560a6ab50a449c0ca2ec14e069e5c6cc7a25d 100644 (file)
@@ -60,6 +60,10 @@ class unified_table : public range_op_table
     unified_table ();
 } unified_tree_table;
 
+// Instantiate the operators which apply to multiple types here.
+
+operator_equal op_equal;
+
 // Invoke the initialization routines for each class of range.
 
 unified_table::unified_table ()
@@ -67,6 +71,8 @@ unified_table::unified_table ()
   initialize_integral_ops ();
   initialize_pointer_ops ();
   initialize_float_ops ();
+
+  set (EQ_EXPR, op_equal);
 }
 
 // The tables are hidden and accessed via a simple extern function.
@@ -819,35 +825,19 @@ get_bool_state (vrange &r, const vrange &lhs, tree val_type)
   return BRS_TRUE;
 }
 
+// ------------------------------------------------------------------------
 
-class operator_equal : public range_operator
+void
+operator_equal::update_bitmask (irange &r, const irange &lh,
+                               const irange &rh) const
 {
-  using range_operator::fold_range;
-  using range_operator::op1_range;
-  using range_operator::op2_range;
-  using range_operator::op1_op2_relation;
-public:
-  virtual bool fold_range (irange &r, tree type,
-                          const irange &op1,
-                          const irange &op2,
-                          relation_trio = TRIO_VARYING) const;
-  virtual bool op1_range (irange &r, tree type,
-                         const irange &lhs,
-                         const irange &val,
-                         relation_trio = TRIO_VARYING) const;
-  virtual bool op2_range (irange &r, tree type,
-                         const irange &lhs,
-                         const irange &val,
-                         relation_trio = TRIO_VARYING) const;
-  virtual relation_kind op1_op2_relation (const irange &lhs) const;
-  void update_bitmask (irange &r, const irange &lh, const irange &rh) const
-    { update_known_bitmask (r, EQ_EXPR, lh, rh); }
-} op_equal;
+  update_known_bitmask (r, EQ_EXPR, lh, rh);
+}
 
 // Check if the LHS range indicates a relation between OP1 and OP2.
 
 relation_kind
-equal_op1_op2_relation (const irange &lhs)
+operator_equal::op1_op2_relation (const irange &lhs) const
 {
   if (lhs.undefined_p ())
     return VREL_UNDEFINED;
@@ -862,13 +852,6 @@ equal_op1_op2_relation (const irange &lhs)
   return VREL_VARYING;
 }
 
-relation_kind
-operator_equal::op1_op2_relation (const irange &lhs) const
-{
-  return equal_op1_op2_relation (lhs);
-}
-
-
 bool
 operator_equal::fold_range (irange &r, tree type,
                            const irange &op1,
@@ -4883,7 +4866,6 @@ pointer_or_operator::wi_fold (irange &r, tree type,
 \f
 integral_table::integral_table ()
 {
-  set (EQ_EXPR, op_equal);
   set (NE_EXPR, op_not_equal);
   set (LT_EXPR, op_lt);
   set (LE_EXPR, op_le);
@@ -4937,7 +4919,6 @@ pointer_table::pointer_table ()
   set (MIN_EXPR, op_ptr_min_max);
   set (MAX_EXPR, op_ptr_min_max);
 
-  set (EQ_EXPR, op_equal);
   set (NE_EXPR, op_not_equal);
   set (LT_EXPR, op_lt);
   set (LE_EXPR, op_le);
index 0721d4a302d36b881ff94d754e265b385e223b53..61f2ac16643bf853df788c37fd28d3fbe32f6901 100644 (file)
@@ -266,7 +266,6 @@ extern void wi_set_zero_nonzero_bits (tree type,
                                      wide_int &mustbe_nonzero);
 
 // op1_op2_relation methods that are the same across irange and frange.
-relation_kind equal_op1_op2_relation (const irange &lhs);
 relation_kind not_equal_op1_op2_relation (const irange &lhs);
 relation_kind lt_op1_op2_relation (const irange &lhs);
 relation_kind le_op1_op2_relation (const irange &lhs);