From 384f4448e12f90f4b9de738f8c5d3a672d0f31a1 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 30 Jan 2023 20:53:18 -0600 Subject: [PATCH] nak: Get rid of meta instructions They're mostly in the way at this point. Instead, make map_instrs return a Vec. We can reaplace that with a None, One, Some enum type later if we want. Part-of: --- src/nouveau/compiler/nak_ir.rs | 69 +++++++---------------------- src/nouveau/compiler/nak_opt_dce.rs | 6 +-- 2 files changed, 19 insertions(+), 56 deletions(-) diff --git a/src/nouveau/compiler/nak_ir.rs b/src/nouveau/compiler/nak_ir.rs index 532ee613447..b9ced8c331b 100644 --- a/src/nouveau/compiler/nak_ir.rs +++ b/src/nouveau/compiler/nak_ir.rs @@ -793,10 +793,6 @@ impl Instr { Instr::new(Opcode::NOOP, &[], &[]) } - pub fn new_meta(instrs: Vec) -> Instr { - Instr::new(Opcode::META(MetaInstr::new(instrs)), &[], &[]) - } - pub fn new_fadd(dst: Dst, x: Src, y: Src) -> Instr { Instr::new(Opcode::FADD, slice::from_ref(&dst), &[x, y]) } @@ -965,38 +961,15 @@ impl Instr { Opcode::LD(_) => None, Opcode::ST(_) => None, Opcode::EXIT => Some(15), - Opcode::NOOP - | Opcode::META(_) - | Opcode::VEC - | Opcode::SPLIT - | Opcode::FS_OUT => panic!("Not a hardware opcode"), + Opcode::NOOP | Opcode::VEC | Opcode::SPLIT | Opcode::FS_OUT => { + panic!("Not a hardware opcode") + } } } } -pub struct MetaInstr { - instrs: Vec, -} - -impl MetaInstr { - pub fn new(instrs: Vec) -> MetaInstr { - MetaInstr { instrs: instrs } - } -} - -impl fmt::Display for MetaInstr { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{{\n")?; - for i in &self.instrs { - write!(f, "{}\n", i)?; - } - write!(f, "}}") - } -} - pub enum Opcode { NOOP, - META(MetaInstr), FADD, FFMA, FMNMX, @@ -1028,7 +1001,6 @@ impl fmt::Display for Opcode { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Opcode::NOOP => write!(f, "NOOP"), - Opcode::META(m) => write!(f, "META {}", m), Opcode::FADD => write!(f, "FADD"), Opcode::FFMA => write!(f, "FFMA"), Opcode::FMNMX => write!(f, "FMNMX"), @@ -1093,19 +1065,10 @@ impl BasicBlock { } } - pub fn map_instrs Instr>(&mut self, map: &F) { + pub fn map_instrs Vec>(&mut self, map: &F) { let mut instrs = Vec::new(); for i in self.instrs.drain(..) { - let new_instr = map(i); - match new_instr.op { - Opcode::NOOP => {} - Opcode::META(mut meta) => { - instrs.append(&mut meta.instrs); - } - _ => { - instrs.push(new_instr); - } - } + instrs.append(&mut map(i)); } self.instrs = instrs; } @@ -1142,7 +1105,7 @@ impl Function { Ref::new_ssa(file, idx, comps) } - pub fn map_instrs Instr>(&mut self, map: &F) { + pub fn map_instrs Vec>(&mut self, map: &F) { for b in &mut self.blocks { b.map_instrs(map); } @@ -1171,23 +1134,23 @@ impl Shader { } } - pub fn map_instrs Instr>(&mut self, map: &F) { + pub fn map_instrs Vec>(&mut self, map: &F) { for f in &mut self.functions { f.map_instrs(map); } } pub fn lower_vec_split(&mut self) { - self.map_instrs(&|instr: Instr| -> Instr { + self.map_instrs(&|instr: Instr| -> Vec { match instr.op { Opcode::VEC => { + let mut instrs = Vec::new(); let comps = u8::try_from(instr.num_srcs()).unwrap(); if comps == 1 { let src = instr.src(0); let dst = instr.dst(0); - Instr::new_mov(*dst, *src) + instrs.push(Instr::new_mov(*dst, *src)); } else { - let mut instrs = Vec::new(); let vec_dst = instr.dst(0).as_reg().unwrap(); assert!(comps == vec_dst.comps()); for i in 0..comps { @@ -1195,17 +1158,17 @@ impl Shader { let dst = Dst::Reg(vec_dst.as_comp(i).unwrap()); instrs.push(Instr::new_mov(dst, *src)); } - Instr::new_meta(instrs) } + instrs } Opcode::SPLIT => { + let mut instrs = Vec::new(); let comps = u8::try_from(instr.num_dsts()).unwrap(); if comps == 1 { let src = instr.src(0); let dst = instr.dst(0); - Instr::new_mov(*dst, *src) + instrs.push(Instr::new_mov(*dst, *src)); } else { - let mut instrs = Vec::new(); let vec_src = instr.src(0).as_reg().unwrap(); assert!(comps == vec_src.comps()); for i in 0..comps { @@ -1216,8 +1179,8 @@ impl Shader { } instrs.push(Instr::new_mov(*dst, src)); } - Instr::new_meta(instrs) } + instrs } Opcode::FS_OUT => { let mut instrs = Vec::new(); @@ -1229,9 +1192,9 @@ impl Shader { ); instrs.push(Instr::new_mov(dst, *src)); } - Instr::new_meta(instrs) + instrs } - _ => instr, + _ => vec![instr], } }) } diff --git a/src/nouveau/compiler/nak_opt_dce.rs b/src/nouveau/compiler/nak_opt_dce.rs index 02674606e90..d745f422058 100644 --- a/src/nouveau/compiler/nak_opt_dce.rs +++ b/src/nouveau/compiler/nak_opt_dce.rs @@ -70,11 +70,11 @@ impl DeadCodePass { } if has_any_dead { - f.map_instrs(&|instr: Instr| -> Instr { + f.map_instrs(&|instr: Instr| -> Vec { if self.is_instr_live(&instr) { - instr + vec![instr] } else { - Instr::new_noop() + Vec::new() } }) }