]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Move bitmask routines to vrange base class.
authorAldy Hernandez <aldyh@redhat.com>
Thu, 22 Feb 2024 08:18:46 +0000 (09:18 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Sun, 28 Apr 2024 19:03:00 +0000 (21:03 +0200)
Any range can theoretically have a bitmask of set bits.  This patch
moves the bitmask accessors to the base class.  This cleans up some
users in IPA*, and will provide a cleaner interface when prange is in
place.

gcc/ChangeLog:

* ipa-cp.cc (propagate_bits_across_jump_function): Access bitmask
through base class.
(ipcp_store_vr_results): Same.
* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Same.
(ipcp_get_parm_bits): Same.
(ipcp_update_vr): Same.
* range-op-mixed.h (update_known_bitmask): Change argument to vrange.
* range-op.cc (update_known_bitmask): Same.
* value-range.cc (vrange::update_bitmask):  New.
(irange::set_nonzero_bits): Move to vrange class.
(irange::get_nonzero_bits): Same.
* value-range.h (class vrange): Add update_bitmask, get_bitmask,
get_nonzero_bits, and set_nonzero_bits.
(class irange): Make bitmask methods virtual overrides.
(class Value_Range): Add get_bitmask and update_bitmask.

gcc/ipa-cp.cc
gcc/ipa-prop.cc
gcc/range-op-mixed.h
gcc/range-op.cc
gcc/value-range.cc
gcc/value-range.h

index b7add455bd5d78b84dbd737bb5ff68c47e990335..a688dced5c99fcee44ec40c0423b2157eefbe303 100644 (file)
@@ -2485,8 +2485,7 @@ propagate_bits_across_jump_function (cgraph_edge *cs, int idx,
       jfunc->m_vr->get_vrange (vr);
       if (!vr.undefined_p () && !vr.varying_p ())
        {
-         irange &r = as_a <irange> (vr);
-         irange_bitmask bm = r.get_bitmask ();
+         irange_bitmask bm = vr.get_bitmask ();
          widest_int mask
            = widest_int::from (bm.mask (), TYPE_SIGN (parm_type));
          widest_int value
@@ -6346,14 +6345,13 @@ ipcp_store_vr_results (void)
                {
                  Value_Range tmp = plats->m_value_range.m_vr;
                  tree type = ipa_get_type (info, i);
-                 irange &r = as_a<irange> (tmp);
                  irange_bitmask bm (wide_int::from (bits->get_value (),
                                                     TYPE_PRECISION (type),
                                                     TYPE_SIGN (type)),
                                     wide_int::from (bits->get_mask (),
                                                     TYPE_PRECISION (type),
                                                     TYPE_SIGN (type)));
-                 r.update_bitmask (bm);
+                 tmp.update_bitmask (bm);
                  ipa_vr vr (tmp);
                  ts->m_vr->quick_push (vr);
                }
@@ -6368,14 +6366,13 @@ ipcp_store_vr_results (void)
              tree type = ipa_get_type (info, i);
              Value_Range tmp;
              tmp.set_varying (type);
-             irange &r = as_a<irange> (tmp);
              irange_bitmask bm (wide_int::from (bits->get_value (),
                                                 TYPE_PRECISION (type),
                                                 TYPE_SIGN (type)),
                                 wide_int::from (bits->get_mask (),
                                                 TYPE_PRECISION (type),
                                                 TYPE_SIGN (type)));
-             r.update_bitmask (bm);
+             tmp.update_bitmask (bm);
              ipa_vr vr (tmp);
              ts->m_vr->quick_push (vr);
            }
index 374e998aa64bc49227ee32a4d4c5a91427039472..b57f9750431195114e6e1d0ca2cceacd97e01eed 100644 (file)
@@ -2381,8 +2381,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
              irange_bitmask bm (value, mask);
              if (!addr_nonzero)
                vr.set_varying (TREE_TYPE (arg));
-             irange &r = as_a <irange> (vr);
-             r.update_bitmask (bm);
+             vr.update_bitmask (bm);
              ipa_set_jfunc_vr (jfunc, vr);
            }
          else if (addr_nonzero)
@@ -5785,8 +5784,8 @@ ipcp_get_parm_bits (tree parm, tree *value, widest_int *mask)
   vr[i].get_vrange (tmp);
   if (tmp.undefined_p () || tmp.varying_p ())
     return false;
-  irange &r = as_a <irange> (tmp);
-  irange_bitmask bm = r.get_bitmask ();
+  irange_bitmask bm;
+  bm = tmp.get_bitmask ();
   *mask = widest_int::from (bm.mask (), TYPE_SIGN (TREE_TYPE (parm)));
   *value = wide_int_to_tree (TREE_TYPE (parm), bm.value ());
   return true;
@@ -5857,8 +5856,7 @@ ipcp_update_vr (struct cgraph_node *node, ipcp_transformation *ts)
              if (POINTER_TYPE_P (TREE_TYPE (parm))
                  && opt_for_fn (node->decl, flag_ipa_bit_cp))
                {
-                 irange &r = as_a<irange> (tmp);
-                 irange_bitmask bm = r.get_bitmask ();
+                 irange_bitmask bm = tmp.get_bitmask ();
                  unsigned tem = bm.mask ().to_uhwi ();
                  unsigned HOST_WIDE_INT bitpos = bm.value ().to_uhwi ();
                  unsigned align = tem & -tem;
index 1b4708118291295ca61e7695b7cb6c3afad8b780..3ee7c9d6e0d1aa49319cc2f20605bbe38bb156da 100644 (file)
@@ -22,7 +22,7 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_RANGE_OP_MIXED_H
 #define GCC_RANGE_OP_MIXED_H
 
-void update_known_bitmask (irange &, tree_code, const irange &, const irange &);
+void update_known_bitmask (vrange &, tree_code, const vrange &, const vrange &);
 bool minus_op1_op2_relation_effect (irange &lhs_range, tree type,
                                    const irange &, const irange &,
                                    relation_kind rel);
index 4ccb86ef0ba89b907c5b45f7a8ea5c8147edb963..aeff55cfd78dd48b5fea595f110a8dc50ae9064f 100644 (file)
@@ -415,8 +415,8 @@ range_op_handler::operand_check_p (tree t1, tree t2, tree t3) const
 // LH and RH.
 
 void
-update_known_bitmask (irange &r, tree_code code,
-                     const irange &lh, const irange &rh)
+update_known_bitmask (vrange &r, tree_code code,
+                     const vrange &lh, const vrange &rh)
 {
   if (r.undefined_p () || lh.undefined_p () || rh.undefined_p ()
       || r.singleton_p ())
index ccac517d4c408af8578daf188954abc8c40b346e..926f7b707eaea1880ad74038bc3532dc828e565e 100644 (file)
@@ -68,6 +68,18 @@ unsupported_range::accept (const vrange_visitor &v) const
   v.visit (*this);
 }
 
+void
+vrange::update_bitmask (const class irange_bitmask &)
+{
+}
+
+irange_bitmask
+vrange::get_bitmask () const
+{
+  // Return all unknown bits for the given precision.
+  return irange_bitmask (TYPE_PRECISION (type ()));
+}
+
 bool
 unsupported_range::contains_p (tree) const
 {
@@ -2010,7 +2022,7 @@ irange::get_bitmask () const
 // normalize the range if anything changed.
 
 void
-irange::set_nonzero_bits (const wide_int &bits)
+vrange::set_nonzero_bits (const wide_int &bits)
 {
   gcc_checking_assert (!undefined_p ());
   irange_bitmask bm (wi::zero (TYPE_PRECISION (type ())), bits);
@@ -2020,7 +2032,7 @@ irange::set_nonzero_bits (const wide_int &bits)
 // Return the nonzero bits in R.
 
 wide_int
-irange::get_nonzero_bits () const
+vrange::get_nonzero_bits () const
 {
   gcc_checking_assert (!undefined_p ());
   irange_bitmask bm = get_bitmask ();
index f216f1b82c1088481b336ff5155badaf37297ca0..991ffeafcb8a0dcde02e9e0f1fecf59e8b8dd87b 100644 (file)
@@ -98,6 +98,10 @@ public:
   virtual ~vrange () { }
   virtual tree lbound () const = 0;
   virtual tree ubound () const = 0;
+  virtual void update_bitmask (const class irange_bitmask &);
+  virtual irange_bitmask get_bitmask () const;
+  wide_int get_nonzero_bits () const;
+  void set_nonzero_bits (const wide_int &bits);
 
   bool varying_p () const;
   bool undefined_p () const;
@@ -326,11 +330,8 @@ public:
   virtual bool fits_p (const vrange &r) const override;
   virtual void accept (const vrange_visitor &v) const override;
 
-  void update_bitmask (const irange_bitmask &);
-  irange_bitmask get_bitmask () const;
-  // Nonzero masks.
-  wide_int get_nonzero_bits () const;
-  void set_nonzero_bits (const wide_int &bits);
+  virtual void update_bitmask (const class irange_bitmask &) override;
+  virtual irange_bitmask get_bitmask () const override;
 
 protected:
   void maybe_resize (int needed);
@@ -735,6 +736,9 @@ public:
   bool zero_p () const { return m_vrange->zero_p (); }
   tree lbound () const { return m_vrange->lbound (); }
   tree ubound () const { return m_vrange->ubound (); }
+  irange_bitmask get_bitmask () const { return m_vrange->get_bitmask (); }
+  void update_bitmask (const class irange_bitmask &bm)
+  { return m_vrange->update_bitmask (bm); }
   void accept (const vrange_visitor &v) const { m_vrange->accept (v); }
 private:
   void init (tree type);