diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2024-02-22 09:18:46 +0100 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2024-04-28 21:03:00 +0200 |
commit | fd4cf7a092bb2ce21c0d8246c17c0b7f82de440c (patch) | |
tree | 65905f542f5a027c19b8923e348f5f0744671469 /gcc | |
parent | ba1a8e8eed963c0253c6e5550c8bccc264c5d469 (diff) | |
download | gcc-fd4cf7a092bb2ce21c0d8246c17c0b7f82de440c.zip gcc-fd4cf7a092bb2ce21c0d8246c17c0b7f82de440c.tar.gz gcc-fd4cf7a092bb2ce21c0d8246c17c0b7f82de440c.tar.bz2 |
Move bitmask routines to vrange base class.
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ipa-cp.cc | 9 | ||||
-rw-r--r-- | gcc/ipa-prop.cc | 10 | ||||
-rw-r--r-- | gcc/range-op-mixed.h | 2 | ||||
-rw-r--r-- | gcc/range-op.cc | 4 | ||||
-rw-r--r-- | gcc/value-range.cc | 16 | ||||
-rw-r--r-- | gcc/value-range.h | 14 |
6 files changed, 33 insertions, 22 deletions
diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index b7add45..a688dce 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -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); } diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 374e998..b57f975 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -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; diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 1b47081..3ee7c9d 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -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); diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 4ccb86e..aeff55c 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -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 ()) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index ccac517..926f7b7 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -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 (); diff --git a/gcc/value-range.h b/gcc/value-range.h index f216f1b..991ffea 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -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); |