mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 16:08:04 +02:00
compiler/rust/bitset: Take a stream in union_with
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
This commit is contained in:
parent
47da213e19
commit
86e5cb7c2d
2 changed files with 27 additions and 6 deletions
|
|
@ -166,11 +166,22 @@ impl BitSet {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn union_with(&mut self, other: &BitSet) -> bool {
|
||||
/// Calculate the union of self and an expression, and store the result in
|
||||
/// self.
|
||||
///
|
||||
/// Returns true if the value of self changes, or false otherwise. If you
|
||||
/// don't need the return value of this function, consider using the `|=`
|
||||
/// operator instead.
|
||||
pub fn union_with<B>(&mut self, other: BitSetStream<B>) -> bool
|
||||
where
|
||||
B: BitSetStreamTrait,
|
||||
{
|
||||
let mut other = other.0;
|
||||
let mut added_bits = false;
|
||||
self.reserve_words(other.words.len());
|
||||
for w in 0..other.words.len() {
|
||||
let uw = self.words[w] | other.words[w];
|
||||
let other_len = other.len();
|
||||
self.reserve_words(other_len);
|
||||
for w in 0..other_len {
|
||||
let uw = self.words[w] | other.next();
|
||||
if uw != self.words[w] {
|
||||
added_bits = true;
|
||||
self.words[w] = uw;
|
||||
|
|
@ -480,6 +491,16 @@ mod tests {
|
|||
let mut actual_2 = b.clone();
|
||||
actual_2 |= a.s(..);
|
||||
assert_eq!(to_vec(&actual_2), &expected[..]);
|
||||
|
||||
let mut actual_3 = a.clone();
|
||||
assert_eq!(actual_3.union_with(a.s(..)), false);
|
||||
assert_eq!(actual_3.union_with(b.s(..)), true);
|
||||
assert_eq!(to_vec(&actual_3), &expected[..]);
|
||||
|
||||
let mut actual_4 = b.clone();
|
||||
assert_eq!(actual_4.union_with(b.s(..)), false);
|
||||
assert_eq!(actual_4.union_with(a.s(..)), true);
|
||||
assert_eq!(to_vec(&actual_4), &expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ impl SimpleLiveness {
|
|||
for (b_idx, bl) in l.blocks.iter_mut().enumerate().rev() {
|
||||
// Compute live-out
|
||||
for sb_idx in func.blocks.succ_indices(b_idx) {
|
||||
to_do |= bl.live_out.union_with(&live_in[*sb_idx]);
|
||||
to_do |= bl.live_out.union_with(live_in[*sb_idx].s(..));
|
||||
}
|
||||
|
||||
tmp.clear();
|
||||
|
|
@ -329,7 +329,7 @@ impl SimpleLiveness {
|
|||
& !bl.defs.get_word(w)
|
||||
});
|
||||
|
||||
to_do |= live_in[b_idx].union_with(&tmp);
|
||||
to_do |= live_in[b_idx].union_with(tmp.s(..));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue