]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add inchash support for vrange.
authorAldy Hernandez <aldyh@redhat.com>
Thu, 23 Feb 2023 07:48:28 +0000 (08:48 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Tue, 18 Apr 2023 12:49:07 +0000 (14:49 +0200)
This patch provides inchash support for vrange.  It is along the lines
of the streaming support I just posted and will be used for IPA
hashing of ranges.

gcc/ChangeLog:

* inchash.cc (hash::add_real_value): New.
* inchash.h (class hash): Add add_real_value.
* value-range.cc (add_vrange): New.
* value-range.h (inchash::add_vrange): New.

gcc/inchash.cc
gcc/inchash.h
gcc/value-range.cc
gcc/value-range.h

index a30662b97fe7cf781aebdeed0634ac0e65bcebd9..7890db042024eb824c72c901dcd2d5abcb9ad847 100644 (file)
@@ -24,3 +24,39 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 #include "system.h"
 #include "coretypes.h"
+#include "real.h"
+#include "inchash.h"
+
+namespace inchash
+{
+
+/* This is here instead of inchash.h to keep us from having to put
+   real.h in coretypes.h.  */
+void
+hash::add_real_value (const real_value &v)
+{
+  add_int (v.cl);
+  add_int (v.sign);
+  switch (v.cl)
+    {
+    case rvc_zero:
+    case rvc_inf:
+      return;
+    case rvc_normal:
+      add_int (v.decimal);
+      add_int (REAL_EXP (&v));
+      break;
+    case rvc_nan:
+      add_int (v.signalling);
+      add_int (v.canonical);
+      if (v.canonical)
+       return;
+      break;
+    default:
+      gcc_unreachable ();
+    }
+  for (unsigned i = 0; i < SIGSZ; ++i)
+    add_hwi (v.sig[i]);
+}
+
+} // namespace inchash
index bf76308431d931e3f1283b69f613178e7f1c2b10..41ae153d1c59f2c9bc25a569ebaf47d14dfd16c0 100644 (file)
@@ -88,6 +88,8 @@ class hash
       add_hwi (x.sext_elt (i));
   }
 
+  void add_real_value (const class real_value &v);
+
   /* Hash in pointer PTR.  */
   void add_ptr (const void *ptr)
   {
index ec826c2fe1bb3f8f5adc1d817475915ee0594362..c14a27e23af90449a7459e3c18de4ee031a9b7e5 100644 (file)
@@ -232,6 +232,58 @@ vrange::dump (FILE *file) const
   pp_flush (&buffer);
 }
 
+namespace inchash
+{
+
+void
+add_vrange (const vrange &v, inchash::hash &hstate,
+            unsigned int)
+{
+  if (v.undefined_p ())
+    {
+      hstate.add_int (VR_UNDEFINED);
+      return;
+    }
+  // Types are ignored throughout to inhibit two ranges being equal
+  // but having different hash values.  This can happen when two
+  // ranges are equal and their types are different (but
+  // types_compatible_p is true).
+  if (is_a <irange> (v))
+    {
+      const irange &r = as_a <irange> (v);
+      if (r.varying_p ())
+       hstate.add_int (VR_VARYING);
+      else
+       hstate.add_int (VR_RANGE);
+      for (unsigned i = 0; i < r.num_pairs (); ++i)
+       {
+         hstate.add_wide_int (r.lower_bound (i));
+         hstate.add_wide_int (r.upper_bound (i));
+       }
+      hstate.add_wide_int (r.get_nonzero_bits ());
+      return;
+    }
+  if (is_a <frange> (v))
+    {
+      const frange &r = as_a <frange> (v);
+      if (r.varying_p ())
+       hstate.add_int (VR_VARYING);
+      else
+       hstate.add_int (VR_RANGE);
+
+      hstate.add_real_value (r.lower_bound ());
+      hstate.add_real_value (r.upper_bound ());
+
+      nan_state nan = r.get_nan_state ();
+      hstate.add_int (nan.pos_p ());
+      hstate.add_int (nan.neg_p ());
+      return;
+    }
+  gcc_unreachable ();
+}
+
+} //namespace inchash
+
 bool
 irange::supports_type_p (const_tree type) const
 {
index f8aa0ca7bec277ce9c38cde1724611fca7225d24..5545cce50242a948937b692b4f0919231859ef59 100644 (file)
@@ -109,6 +109,11 @@ protected:
   const ENUM_BITFIELD(value_range_discriminator) m_discriminator : 4;
 };
 
+namespace inchash
+{
+  extern void add_vrange (const vrange &, hash &, unsigned flags = 0);
+}
+
 // An integer range without any storage.
 
 class GTY((user)) irange : public vrange