nak/liveness: Use typed bitsets

Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34994>
This commit is contained in:
Faith Ekstrand
2025-05-15 04:49:43 -04:00
parent afb11a5a9e
commit fc54e6e1d2
2 changed files with 17 additions and 9 deletions
+9 -9
View File
@@ -229,11 +229,11 @@ pub trait Liveness {
#[derive(Default)]
pub struct SimpleBlockLiveness {
defs: BitSet,
uses: BitSet,
defs: BitSet<SSAValue>,
uses: BitSet<SSAValue>,
last_use: FxHashMap<SSAValue, usize>,
live_in: BitSet,
live_out: BitSet,
live_in: BitSet<SSAValue>,
live_out: BitSet<SSAValue>,
}
impl SimpleBlockLiveness {
@@ -242,18 +242,18 @@ impl SimpleBlockLiveness {
}
fn add_def(&mut self, ssa: SSAValue) {
self.defs.insert(ssa.idx().try_into().unwrap());
self.defs.insert(ssa);
}
fn add_use(&mut self, ssa: SSAValue, ip: usize) {
self.uses.insert(ssa.idx().try_into().unwrap());
self.uses.insert(ssa);
self.last_use.insert(ssa, ip);
}
}
impl BlockLiveness for SimpleBlockLiveness {
fn is_live_after_ip(&self, val: &SSAValue, ip: usize) -> bool {
if self.live_out.contains(val.idx().try_into().unwrap()) {
if self.live_out.contains(*val) {
true
} else if let Some(last_use_ip) = self.last_use.get(val) {
*last_use_ip > ip
@@ -263,11 +263,11 @@ impl BlockLiveness for SimpleBlockLiveness {
}
fn is_live_in(&self, val: &SSAValue) -> bool {
self.live_in.contains(val.idx().try_into().unwrap())
self.live_in.contains(*val)
}
fn is_live_out(&self, val: &SSAValue) -> bool {
self.live_out.contains(val.idx().try_into().unwrap())
self.live_out.contains(*val)
}
}
+8
View File
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: MIT
use crate::ir::{HasRegFile, RegFile};
use compiler::bitset::IntoBitIndex;
use std::array;
use std::fmt;
use std::num::NonZeroU32;
@@ -53,6 +54,13 @@ impl HasRegFile for SSAValue {
}
}
impl IntoBitIndex for SSAValue {
fn into_bit_index(self) -> usize {
// Indices are guaranteed unique by the allocator
self.idx().try_into().unwrap()
}
}
impl fmt::Display for SSAValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "%{}{}", self.file().fmt_prefix(), self.idx())