From 61abcb2bc8577d22575ae5c53d52d25a38bd4059 Mon Sep 17 00:00:00 2001 From: Mel Henning Date: Thu, 30 Oct 2025 17:44:48 -0400 Subject: [PATCH] nak: Split LegalizeBuilder into its own type Reviewed-by: Mary Guillemard Part-of: --- src/nouveau/compiler/nak/legalize.rs | 45 ++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/nouveau/compiler/nak/legalize.rs b/src/nouveau/compiler/nak/legalize.rs index 98a4153138b..3070121b86a 100644 --- a/src/nouveau/compiler/nak/legalize.rs +++ b/src/nouveau/compiler/nak/legalize.rs @@ -7,8 +7,6 @@ use crate::liveness::{BlockLiveness, Liveness, SimpleLiveness}; use rustc_hash::{FxHashMap, FxHashSet}; -pub type LegalizeBuilder<'a> = SSAInstrBuilder<'a>; - pub fn src_is_upred_reg(src: &Src) -> bool { match &src.src_ref { SrcRef::True | SrcRef::False => false, @@ -377,6 +375,47 @@ pub trait LegalizeBuildHelpers: SSABuilder { } } +pub struct LegalizeBuilder<'a> { + b: SSAInstrBuilder<'a>, +} + +impl<'a> LegalizeBuilder<'a> { + fn new(sm: &'a dyn ShaderModel, alloc: &'a mut SSAValueAllocator) -> Self { + LegalizeBuilder { + b: SSAInstrBuilder::new(sm, alloc), + } + } + + pub fn into_vec(self) -> Vec { + self.b.into_vec() + } + + #[allow(dead_code)] + pub fn into_mapped_instrs(self) -> MappedInstrs { + self.b.into_mapped_instrs() + } +} + +impl<'a> Builder for LegalizeBuilder<'a> { + fn push_instr(&mut self, instr: Instr) -> &mut Instr { + self.b.push_instr(instr) + } + + fn sm(&self) -> u8 { + self.b.sm() + } +} + +impl<'a> SSABuilder for LegalizeBuilder<'a> { + fn alloc_ssa(&mut self, file: RegFile) -> SSAValue { + self.b.alloc_ssa(file) + } + + fn alloc_ssa_vec(&mut self, file: RegFile, comps: u8) -> SSARef { + self.b.alloc_ssa_vec(file, comps) + } +} + impl LegalizeBuildHelpers for LegalizeBuilder<'_> {} fn legalize_instr( @@ -532,7 +571,7 @@ impl Shader<'_> { } } - let mut b = SSAInstrBuilder::new(sm, &mut f.ssa_alloc); + let mut b = LegalizeBuilder::new(sm, &mut f.ssa_alloc); legalize_instr(sm, &mut b, bl, bu, &pinned, ip, &mut instr); b.push_instr(instr); instrs.append(&mut b.into_vec());