nak: Add an SSAComp struct

This is useful in RA for referring to a single component of an SSA
value.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
This commit is contained in:
Faith Ekstrand 2023-04-10 17:23:26 -05:00 committed by Marge Bot
parent 552faf2864
commit ef45379bfa

View file

@ -105,6 +105,16 @@ impl SSAValue {
pub fn comps(&self) -> u8 {
(((self.packed >> 27) & 0x7) + 1).try_into().unwrap()
}
pub fn comp(&self, comp: u8) -> SSAComp {
assert!(comp < self.comps());
SSAComp::new(self.file(), self.idx(), comp)
}
pub fn as_comp(&self) -> SSAComp {
assert!(self.comps() == 1);
SSAComp::new(self.file(), self.idx(), 0)
}
}
impl HasRegFile for SSAValue {
@ -123,6 +133,33 @@ impl fmt::Display for SSAValue {
}
}
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct SSAComp {
v: SSAValue,
}
impl SSAComp {
pub fn new(file: RegFile, idx: u32, comp: u8) -> SSAComp {
SSAComp {
v: SSAValue::new(file, idx, comp + 1),
}
}
pub fn idx(&self) -> u32 {
self.v.idx()
}
pub fn comp(&self) -> u8 {
self.v.comps() - 1
}
}
impl HasRegFile for SSAComp {
fn file(&self) -> RegFile {
self.v.file()
}
}
pub struct SSAValueAllocator {
count: u32,
}