nak: impl HasRegFile for SSARef and &[SSAValue]

Reviewed-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37130>
This commit is contained in:
Mel Henning 2025-09-01 19:10:29 -04:00 committed by Marge Bot
parent 603d7f9413
commit d21a4d9e50
2 changed files with 19 additions and 43 deletions

View file

@ -236,6 +236,19 @@ pub trait HasRegFile {
}
}
impl HasRegFile for &[SSAValue] {
fn file(&self) -> RegFile {
let comps = self.len();
let file = self[0].file();
for i in 1..comps {
if self[i].file() != file {
panic!("Illegal mix of RegFiles")
}
}
file
}
}
#[derive(Clone)]
pub struct RegFileSet {
bits: u8,

View file

@ -204,49 +204,6 @@ impl SSARef {
}
}
/// Returns the register file for this SSA reference, assuming all SSA
/// values have the same register file.
pub fn file(&self) -> RegFile {
let comps = usize::from(self.comps());
let file = self[0].file();
for i in 1..comps {
if self[i].file() != file {
panic!("SSARef mixes RegFiles")
}
}
file
}
/// Returns true if this SSA reference is known to be uniform.
pub fn is_uniform(&self) -> bool {
for ssa in &self[..] {
if !ssa.is_uniform() {
return false;
}
}
true
}
pub fn is_gpr(&self) -> bool {
for ssa in &self[..] {
if !ssa.is_gpr() {
return false;
}
}
true
}
pub fn is_predicate(&self) -> bool {
if self[0].is_predicate() {
true
} else {
for ssa in &self[..] {
debug_assert!(!ssa.is_predicate());
}
false
}
}
#[cold]
#[inline]
fn cold() {}
@ -337,6 +294,12 @@ impl fmt::Display for SSARef {
}
}
impl HasRegFile for SSARef {
fn file(&self) -> RegFile {
(&self[..]).file()
}
}
#[test]
fn test_ssa_ref_round_trip() {
for len in 1..16 {