diff --git a/crates/victory-shader/src/ir.rs b/crates/victory-shader/src/ir.rs index d32861a..0084c30 100644 --- a/crates/victory-shader/src/ir.rs +++ b/crates/victory-shader/src/ir.rs @@ -211,12 +211,11 @@ pub fn build_bounded( } let m0 = m0_max.get(&machine.offset).copied(); if let Some((reads, writes)) = effects(&machine, &fields, name, lanes, vgprs, m0)? { - let unset = |regs: Vec| regs.into_iter().map(|r| (r, NONE)).collect(); blocks[b].insts.push(Inst { machine, fields, - reads: unset(reads), - writes: unset(writes), + reads, + writes, }); } } @@ -700,8 +699,9 @@ const DROPPED: &[&str] = &[ "v_clrexcp", ]; -/// Registers read, registers written. -type Effects = (Vec, Vec); +/// Registers read, registers written, each with a placeholder value the +/// SSA pass fills in. +type Effects = (Vec<(Reg, Value)>, Vec<(Reg, Value)>); /// Registers an instruction reads and writes, one per dword, or `None` if /// the IR drops it. @@ -720,9 +720,9 @@ fn effects( offset: inst.offset, what: name, }; - let mask = |code: u8| (0..lanes).map(move |i| Reg::S(code + i)); + let mask = |code: u8| (0..lanes).map(move |i| (Reg::S(code + i), NONE)); let (mut r, mut w) = (Vec::new(), Vec::new()); - let regs = |op: &Operand, out: &mut Vec| { + let regs = |op: &Operand, out: &mut Vec<(Reg, Value)>| { add_regs(op, lanes, out).map_err(|_| ShaderError::Isa { offset: inst.offset, reason: "register range out of bounds", @@ -757,21 +757,21 @@ fn effects( || name.starts_with("s_cselect_") || name.starts_with("s_cmov_") { - r.push(Reg::Scc); + r.push((Reg::Scc, NONE)); } if name.contains("saveexec") || name.contains("wrexec") { r.extend(mask(EXEC)); w.extend(mask(EXEC)); } if writes_scc(inst.encoding, name) { - w.push(Reg::Scc); + w.push((Reg::Scc, NONE)); } } Fields::Sopp { .. } => match name { - "s_cbranch_scc0" | "s_cbranch_scc1" => r.push(Reg::Scc), + "s_cbranch_scc0" | "s_cbranch_scc1" => r.push((Reg::Scc, NONE)), "s_cbranch_vccz" | "s_cbranch_vccnz" => r.extend(mask(VCC)), "s_cbranch_execz" | "s_cbranch_execnz" => r.extend(mask(EXEC)), - "s_sendmsg" | "s_sendmsghalt" => r.push(Reg::S(M0)), + "s_sendmsg" | "s_sendmsghalt" => r.push((Reg::S(M0), NONE)), "s_endpgm" | "s_endpgm_saved" | "s_endpgm_ordered_ps_done" @@ -818,10 +818,10 @@ fn effects( }; // v[reg + M0] for any M0 that stays inside the program's VGPRs // (and below the proven bound). - let indexed = |op: &Operand, out: &mut Vec| match *op { + let indexed = |op: &Operand, out: &mut Vec<(Reg, Value)>| match *op { Operand::Vector { reg, .. } if u16::from(reg) < vgprs => { let end = m0_max.map_or(vgprs, |m| vgprs.min(u16::from(reg) + u16::from(m) + 1)); - out.extend((u16::from(reg)..end).map(|r| Reg::V(r as u8))); + out.extend((u16::from(reg)..end).map(|r| (Reg::V(r as u8), NONE))); Ok(()) } _ => Err(ShaderError::Isa { @@ -865,12 +865,12 @@ fn effects( _ => {} } if name.starts_with("v_interp_") || src_indexed || dst_indexed { - r.push(Reg::S(M0)); + r.push((Reg::S(M0), NONE)); } } Fields::Vintrp { dst, src, .. } => { regs(src, &mut r)?; - r.push(Reg::S(M0)); + r.push((Reg::S(M0), NONE)); regs(dst, &mut w)?; } Fields::Ds { @@ -891,7 +891,7 @@ fn effects( || name.contains("addtid") || matches!(name, "ds_ordered_count" | "ds_append" | "ds_consume") { - r.push(Reg::S(M0)); + r.push((Reg::S(M0), NONE)); } } Fields::Buffer { @@ -911,7 +911,7 @@ fn effects( regs(rsrc, &mut r)?; regs(soffset, &mut r)?; if *lds { - r.push(Reg::S(M0)); + r.push((Reg::S(M0), NONE)); } if let Some(d) = data { if name.contains("_load_") { @@ -975,7 +975,7 @@ fn effects( if vector { r.extend(mask(EXEC)); // Lanes disabled in EXEC keep the old value. - r.extend(w.iter().filter(|w| matches!(w, Reg::V(_)))); + r.extend(w.iter().filter(|(w, _)| matches!(w, Reg::V(_))).cloned()); } let mut seen = Vec::with_capacity(r.len()); r.retain(|reg| { @@ -1047,7 +1047,7 @@ fn atomic_result(data: &Operand, name: &str) -> Operand { /// Appends the register dwords an operand names; reading `vccz`, `execz`, /// `scc` or `lds_direct` reads the register behind it. -fn add_regs(op: &Operand, lanes: u8, out: &mut Vec) -> Result<(), ()> { +fn add_regs(op: &Operand, lanes: u8, out: &mut Vec<(Reg, Value)>) -> Result<(), ()> { match *op { Operand::Scalar { code, .. } if code == gfx10::NULL => {} Operand::Scalar { code, dwords } => { @@ -1055,18 +1055,18 @@ fn add_regs(op: &Operand, lanes: u8, out: &mut Vec) -> Result<(), ()> { if end > 128 { return Err(()); } - out.extend((code..end as u8).map(Reg::S)); + out.extend((code..end as u8).map(|c| (Reg::S(c), NONE))); } Operand::Vector { reg, dwords } => { if u16::from(reg) + u16::from(dwords) > 256 { return Err(()); } - out.extend((0..dwords).map(|i| Reg::V(reg + i))); + out.extend((0..dwords).map(|i| (Reg::V(reg + i), NONE))); } - Operand::Const(251) => out.extend((0..lanes).map(|i| Reg::S(VCC + i))), - Operand::Const(252) => out.extend((0..lanes).map(|i| Reg::S(EXEC + i))), - Operand::Const(253) => out.push(Reg::Scc), - Operand::Const(254) => out.push(Reg::S(M0)), + Operand::Const(251) => out.extend((0..lanes).map(|i| (Reg::S(VCC + i), NONE))), + Operand::Const(252) => out.extend((0..lanes).map(|i| (Reg::S(EXEC + i), NONE))), + Operand::Const(253) => out.push((Reg::Scc, NONE)), + Operand::Const(254) => out.push((Reg::S(M0), NONE)), Operand::Const(_) | Operand::Literal(_) | Operand::Attr { .. } => {} } Ok(())