mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 22:49:13 +02:00
nak: remove boxing of instructions
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com> Reviewed-by: Mel Henning <mhenning@darkrefraction.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37315>
This commit is contained in:
parent
52e02c2b0b
commit
74696758a2
19 changed files with 99 additions and 110 deletions
|
|
@ -1006,14 +1006,14 @@ impl AssignRegsBlock {
|
|||
|
||||
fn assign_regs_instr(
|
||||
&mut self,
|
||||
mut instr: Box<Instr>,
|
||||
mut instr: Instr,
|
||||
ip: usize,
|
||||
sum: &SSAUseMap,
|
||||
phi_webs: &mut PhiWebs,
|
||||
srcs_killed: &KillSet,
|
||||
dsts_killed: &KillSet,
|
||||
pcopy: &mut OpParCopy,
|
||||
) -> Option<Box<Instr>> {
|
||||
) -> Option<Instr> {
|
||||
match &mut instr.op {
|
||||
Op::Undef(undef) => {
|
||||
if let Dst::SSA(ssa) = &undef.dst {
|
||||
|
|
@ -1187,7 +1187,7 @@ impl AssignRegsBlock {
|
|||
self.ra.free_killed(srcs_killed);
|
||||
self.ra.free_killed(dsts_killed);
|
||||
|
||||
Some(Instr::new_boxed(pin_copy))
|
||||
Some(Instr::new(pin_copy))
|
||||
}
|
||||
}
|
||||
Op::ParCopy(pcopy) => {
|
||||
|
|
@ -1345,7 +1345,7 @@ impl AssignRegsBlock {
|
|||
|
||||
if !pcopy.is_empty() {
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(OpAnnotate {
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation: "generated by assign_regs".into(),
|
||||
}));
|
||||
}
|
||||
|
|
@ -1356,7 +1356,7 @@ impl AssignRegsBlock {
|
|||
}
|
||||
}
|
||||
}
|
||||
instrs.push(Instr::new_boxed(pcopy));
|
||||
instrs.push(Instr::new(pcopy));
|
||||
}
|
||||
|
||||
if let Some(instr) = instr {
|
||||
|
|
@ -1400,11 +1400,11 @@ impl AssignRegsBlock {
|
|||
annotation: "generated by assign_regs".into(),
|
||||
};
|
||||
if b.branch().is_some() {
|
||||
b.instrs.insert(b.instrs.len() - 1, Instr::new_boxed(ann));
|
||||
b.instrs.insert(b.instrs.len() - 1, Instr::new_boxed(pcopy));
|
||||
b.instrs.insert(b.instrs.len() - 1, Instr::new(ann));
|
||||
b.instrs.insert(b.instrs.len() - 1, Instr::new(pcopy));
|
||||
} else {
|
||||
b.instrs.push(Instr::new_boxed(ann));
|
||||
b.instrs.push(Instr::new_boxed(pcopy));
|
||||
b.instrs.push(Instr::new(ann));
|
||||
b.instrs.push(Instr::new(pcopy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
use crate::ir::*;
|
||||
|
||||
pub trait Builder {
|
||||
fn push_instr(&mut self, instr: Box<Instr>) -> &mut Instr;
|
||||
fn push_instr(&mut self, instr: Instr) -> &mut Instr;
|
||||
|
||||
fn sm(&self) -> u8;
|
||||
|
||||
fn push_op(&mut self, op: impl Into<Op>) -> &mut Instr {
|
||||
self.push_instr(Instr::new_boxed(op))
|
||||
self.push_instr(Instr::new(op))
|
||||
}
|
||||
|
||||
fn predicate(&mut self, pred: Pred) -> PredicatedBuilder<'_, Self>
|
||||
|
|
@ -902,7 +902,7 @@ impl<'a> InstrBuilder<'a> {
|
|||
}
|
||||
|
||||
impl InstrBuilder<'_> {
|
||||
pub fn into_vec(self) -> Vec<Box<Instr>> {
|
||||
pub fn into_vec(self) -> Vec<Instr> {
|
||||
match self.instrs {
|
||||
MappedInstrs::None => Vec::new(),
|
||||
MappedInstrs::One(i) => vec![i],
|
||||
|
|
@ -916,9 +916,9 @@ impl InstrBuilder<'_> {
|
|||
}
|
||||
|
||||
impl Builder for InstrBuilder<'_> {
|
||||
fn push_instr(&mut self, instr: Box<Instr>) -> &mut Instr {
|
||||
fn push_instr(&mut self, instr: Instr) -> &mut Instr {
|
||||
self.instrs.push(instr);
|
||||
self.instrs.last_mut().unwrap().as_mut()
|
||||
self.instrs.last_mut().unwrap()
|
||||
}
|
||||
|
||||
fn sm(&self) -> u8 {
|
||||
|
|
@ -944,7 +944,7 @@ impl<'a> SSAInstrBuilder<'a> {
|
|||
}
|
||||
|
||||
impl SSAInstrBuilder<'_> {
|
||||
pub fn into_vec(self) -> Vec<Box<Instr>> {
|
||||
pub fn into_vec(self) -> Vec<Instr> {
|
||||
self.b.into_vec()
|
||||
}
|
||||
|
||||
|
|
@ -955,7 +955,7 @@ impl SSAInstrBuilder<'_> {
|
|||
}
|
||||
|
||||
impl Builder for SSAInstrBuilder<'_> {
|
||||
fn push_instr(&mut self, instr: Box<Instr>) -> &mut Instr {
|
||||
fn push_instr(&mut self, instr: Instr) -> &mut Instr {
|
||||
self.b.push_instr(instr)
|
||||
}
|
||||
|
||||
|
|
@ -980,7 +980,7 @@ pub struct PredicatedBuilder<'a, T: Builder> {
|
|||
}
|
||||
|
||||
impl<T: Builder> Builder for PredicatedBuilder<'_, T> {
|
||||
fn push_instr(&mut self, instr: Box<Instr>) -> &mut Instr {
|
||||
fn push_instr(&mut self, instr: Instr) -> &mut Instr {
|
||||
let mut instr = instr;
|
||||
assert!(instr.pred.is_true());
|
||||
instr.pred = self.pred;
|
||||
|
|
@ -1014,7 +1014,7 @@ impl<'a, T: Builder> UniformBuilder<'a, T> {
|
|||
}
|
||||
|
||||
impl<T: Builder> Builder for UniformBuilder<'_, T> {
|
||||
fn push_instr(&mut self, instr: Box<Instr>) -> &mut Instr {
|
||||
fn push_instr(&mut self, instr: Instr) -> &mut Instr {
|
||||
self.b.push_instr(instr)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ fn insert_texture_barriers(f: &mut Function, sm: &dyn ShaderModel) {
|
|||
for (block, mut sim) in f.blocks.iter_mut().zip(state_in.into_iter()) {
|
||||
block.map_instrs(|instr| {
|
||||
if let Some(textures_left) = sim.visit_instr(&instr) {
|
||||
let bar = Instr::new_boxed(OpTexDepBar { textures_left });
|
||||
let bar = Instr::new(OpTexDepBar { textures_left });
|
||||
MappedInstrs::Many(vec![bar, instr])
|
||||
} else {
|
||||
MappedInstrs::One(instr)
|
||||
|
|
@ -799,7 +799,7 @@ fn calc_delays(f: &mut Function, sm: &dyn ShaderModel) -> u64 {
|
|||
instr.deps.set_delay(max_instr_delay);
|
||||
let mut instrs = vec![instr];
|
||||
while delay > 0 {
|
||||
let mut nop = Instr::new_boxed(OpNop { label: None });
|
||||
let mut nop = Instr::new(OpNop { label: None });
|
||||
nop.deps.set_delay(delay.min(max_instr_delay));
|
||||
delay -= nop.deps.delay;
|
||||
instrs.push(nop);
|
||||
|
|
@ -813,7 +813,7 @@ fn calc_delays(f: &mut Function, sm: &dyn ShaderModel) -> u64 {
|
|||
// of 2 after every instruction which has an exec latency. Perhaps
|
||||
// it has something to do with .yld? In any case, the extra 2
|
||||
// cycles aren't worth the chance of weird bugs.
|
||||
let mut nop = Instr::new_boxed(OpNop { label: None });
|
||||
let mut nop = Instr::new(OpNop { label: None });
|
||||
nop.deps.set_delay(2);
|
||||
MappedInstrs::Many(vec![instr, nop])
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ impl<'a> TestShaderBuilder<'a> {
|
|||
}
|
||||
|
||||
impl Builder for TestShaderBuilder<'_> {
|
||||
fn push_instr(&mut self, instr: Box<Instr>) -> &mut Instr {
|
||||
fn push_instr(&mut self, instr: Instr) -> &mut Instr {
|
||||
self.b.push_instr(instr)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8404,18 +8404,14 @@ pub struct Instr {
|
|||
}
|
||||
|
||||
impl Instr {
|
||||
pub fn new(op: impl Into<Op>) -> Instr {
|
||||
Instr {
|
||||
pub fn new(op: impl Into<Op>) -> Self {
|
||||
Self {
|
||||
op: op.into(),
|
||||
pred: true.into(),
|
||||
deps: InstrDeps::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_boxed(op: impl Into<Op>) -> Box<Self> {
|
||||
Box::new(Instr::new(op))
|
||||
}
|
||||
|
||||
pub fn dsts(&self) -> &[Dst] {
|
||||
self.op.dsts_as_slice()
|
||||
}
|
||||
|
|
@ -8580,7 +8576,7 @@ impl<T: Into<Op>> From<T> for Instr {
|
|||
}
|
||||
}
|
||||
|
||||
pub type MappedInstrs = SmallVec<Box<Instr>>;
|
||||
pub type MappedInstrs = SmallVec<Instr>;
|
||||
|
||||
pub struct BasicBlock {
|
||||
pub label: Label,
|
||||
|
|
@ -8591,14 +8587,11 @@ pub struct BasicBlock {
|
|||
/// are guaranteed to execute it together
|
||||
pub uniform: bool,
|
||||
|
||||
pub instrs: Vec<Box<Instr>>,
|
||||
pub instrs: Vec<Instr>,
|
||||
}
|
||||
|
||||
impl BasicBlock {
|
||||
pub fn map_instrs(
|
||||
&mut self,
|
||||
mut map: impl FnMut(Box<Instr>) -> MappedInstrs,
|
||||
) {
|
||||
pub fn map_instrs(&mut self, mut map: impl FnMut(Instr) -> MappedInstrs) {
|
||||
let mut instrs = Vec::new();
|
||||
for i in self.instrs.drain(..) {
|
||||
match map(i) {
|
||||
|
|
@ -8720,7 +8713,7 @@ pub struct Function {
|
|||
impl Function {
|
||||
pub fn map_instrs(
|
||||
&mut self,
|
||||
mut map: impl FnMut(Box<Instr>, &mut SSAValueAllocator) -> MappedInstrs,
|
||||
mut map: impl FnMut(Instr, &mut SSAValueAllocator) -> MappedInstrs,
|
||||
) {
|
||||
let alloc = &mut self.ssa_alloc;
|
||||
for b in &mut self.blocks {
|
||||
|
|
@ -9228,7 +9221,7 @@ impl Shader<'_> {
|
|||
|
||||
pub fn map_instrs(
|
||||
&mut self,
|
||||
mut map: impl FnMut(Box<Instr>, &mut SSAValueAllocator) -> MappedInstrs,
|
||||
mut map: impl FnMut(Instr, &mut SSAValueAllocator) -> MappedInstrs,
|
||||
) {
|
||||
for f in &mut self.functions {
|
||||
f.map_instrs(&mut map);
|
||||
|
|
@ -9237,7 +9230,7 @@ impl Shader<'_> {
|
|||
|
||||
/// Remove all annotations, presumably before encoding the shader.
|
||||
pub fn remove_annotations(&mut self) {
|
||||
self.map_instrs(|instr: Box<Instr>, _| -> MappedInstrs {
|
||||
self.map_instrs(|instr: Instr, _| -> MappedInstrs {
|
||||
if matches!(instr.op, Op::Annotate(_)) {
|
||||
MappedInstrs::None
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ pub trait LegalizeBuildHelpers: SSABuilder {
|
|||
};
|
||||
|
||||
if DEBUG.annotate() {
|
||||
self.push_instr(Instr::new_boxed(OpAnnotate {
|
||||
self.push_instr(Instr::new(OpAnnotate {
|
||||
annotation: "copy generated by legalizer".into(),
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -249,13 +249,13 @@ impl LowerCopySwap {
|
|||
|
||||
fn run(&mut self, s: &mut Shader) {
|
||||
let sm = s.sm;
|
||||
s.map_instrs(|instr: Box<Instr>, _| -> MappedInstrs {
|
||||
s.map_instrs(|instr: Instr, _| -> MappedInstrs {
|
||||
match instr.op {
|
||||
Op::R2UR(r2ur) => {
|
||||
debug_assert!(instr.pred.is_true());
|
||||
let mut b = InstrBuilder::new(sm);
|
||||
if DEBUG.annotate() {
|
||||
b.push_instr(Instr::new_boxed(OpAnnotate {
|
||||
b.push_instr(Instr::new(OpAnnotate {
|
||||
annotation: "r2ur lowered by lower_copy_swap"
|
||||
.into(),
|
||||
}));
|
||||
|
|
@ -267,7 +267,7 @@ impl LowerCopySwap {
|
|||
debug_assert!(instr.pred.is_true());
|
||||
let mut b = InstrBuilder::new(sm);
|
||||
if DEBUG.annotate() {
|
||||
b.push_instr(Instr::new_boxed(OpAnnotate {
|
||||
b.push_instr(Instr::new(OpAnnotate {
|
||||
annotation: "copy lowered by lower_copy_swap"
|
||||
.into(),
|
||||
}));
|
||||
|
|
@ -279,7 +279,7 @@ impl LowerCopySwap {
|
|||
debug_assert!(instr.pred.is_true());
|
||||
let mut b = InstrBuilder::new(sm);
|
||||
if DEBUG.annotate() {
|
||||
b.push_instr(Instr::new_boxed(OpAnnotate {
|
||||
b.push_instr(Instr::new(OpAnnotate {
|
||||
annotation: "swap lowered by lower_copy_swap"
|
||||
.into(),
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -258,9 +258,9 @@ impl Shader<'_> {
|
|||
match instr.op {
|
||||
Op::ParCopy(pc) => {
|
||||
assert!(instr.pred.is_true());
|
||||
let mut instrs = vec![];
|
||||
let mut instrs = Vec::new();
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(OpAnnotate {
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation: "par_copy lowered by lower_par_copy"
|
||||
.into(),
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ fn run_nvdisasm(s: &Shader) -> String {
|
|||
stdout.into()
|
||||
}
|
||||
|
||||
fn disassemble_instrs(instrs: Vec<Box<Instr>>, sm: u8) -> Vec<String> {
|
||||
fn disassemble_instrs(instrs: Vec<Instr>, sm: u8) -> Vec<String> {
|
||||
let mut label_alloc = LabelAllocator::new();
|
||||
let block = BasicBlock {
|
||||
label: label_alloc.alloc(),
|
||||
|
|
@ -116,7 +116,7 @@ fn disassemble_instrs(instrs: Vec<Box<Instr>>, sm: u8) -> Vec<String> {
|
|||
}
|
||||
|
||||
struct DisasmCheck {
|
||||
instrs: Vec<Box<Instr>>,
|
||||
instrs: Vec<Instr>,
|
||||
expected: Vec<String>,
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ impl DisasmCheck {
|
|||
}
|
||||
|
||||
fn push(&mut self, instr: impl Into<Instr>, expected: impl Into<String>) {
|
||||
self.instrs.push(Box::new(instr.into()));
|
||||
self.instrs.push(instr.into());
|
||||
self.expected.push(expected.into());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ impl BarPropPass {
|
|||
// GPR version of this barrier, insert an OpBMov to
|
||||
// copy into the GPR. DCE will clean it up if it's
|
||||
// never used.
|
||||
bmovs.push(Instr::new_boxed(OpBMov {
|
||||
bmovs.push(Instr::new(OpBMov {
|
||||
dst: ssa.into(),
|
||||
src: bar.into(),
|
||||
clear: false,
|
||||
|
|
@ -237,7 +237,7 @@ impl BarPropPass {
|
|||
if DEBUG.annotate() {
|
||||
bmovs.insert(
|
||||
0,
|
||||
Instr::new_boxed(OpAnnotate {
|
||||
Instr::new(OpAnnotate {
|
||||
annotation: "generated by opt_bar_prop"
|
||||
.into(),
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ impl DeadCodePass {
|
|||
}
|
||||
}
|
||||
|
||||
fn map_instr(&self, mut instr: Box<Instr>) -> MappedInstrs {
|
||||
fn map_instr(&self, mut instr: Instr) -> MappedInstrs {
|
||||
let is_live = match &mut instr.op {
|
||||
Op::PhiSrcs(phi) => {
|
||||
phi.srcs.retain(|phi, _| self.is_phi_live(*phi));
|
||||
|
|
@ -144,7 +144,7 @@ impl DeadCodePass {
|
|||
MappedInstrs::One(instr)
|
||||
} else {
|
||||
if DEBUG.annotate() {
|
||||
MappedInstrs::One(Instr::new_boxed(OpAnnotate {
|
||||
MappedInstrs::One(Instr::new(OpAnnotate {
|
||||
annotation: "killed by dce".into(),
|
||||
}))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ impl<T: Clone> RegUse<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn generate_dep_graph(sm: &dyn ShaderModel, instrs: &[Box<Instr>]) -> DepGraph {
|
||||
fn generate_dep_graph(sm: &dyn ShaderModel, instrs: &[Instr]) -> DepGraph {
|
||||
let mut g = DepGraph::new((0..instrs.len()).map(|_| Default::default()));
|
||||
|
||||
// Maps registers to RegUse<ip, src_dst_idx>. Predicates are
|
||||
|
|
@ -203,8 +203,8 @@ fn generate_order(
|
|||
|
||||
fn sched_buffer(
|
||||
sm: &dyn ShaderModel,
|
||||
instrs: Vec<Box<Instr>>,
|
||||
) -> (impl Iterator<Item = Box<Instr>> + use<>, u64) {
|
||||
instrs: Vec<Instr>,
|
||||
) -> (impl Iterator<Item = Instr> + use<>, u64) {
|
||||
let mut g = generate_dep_graph(sm, &instrs);
|
||||
let init_ready_list = calc_statistics(&mut g);
|
||||
// save_graphviz(&instrs, &g).unwrap();
|
||||
|
|
@ -212,7 +212,7 @@ fn sched_buffer(
|
|||
let (new_order, cycle_count) = generate_order(&mut g, init_ready_list);
|
||||
|
||||
// Apply the new instruction order
|
||||
let mut instrs: Vec<Option<Box<Instr>>> =
|
||||
let mut instrs: Vec<Option<Instr>> =
|
||||
instrs.into_iter().map(|instr| Some(instr)).collect();
|
||||
let instrs = new_order.into_iter().rev().map(move |i| {
|
||||
std::mem::take(&mut instrs[i]).expect("Instruction scheduled twice")
|
||||
|
|
|
|||
|
|
@ -45,12 +45,12 @@ impl Shader<'_> {
|
|||
|
||||
for f in &mut self.functions {
|
||||
for b in &mut f.blocks {
|
||||
let mut instrs: Vec<Box<Instr>> = Vec::new();
|
||||
let mut instrs = Vec::new();
|
||||
for instr in b.instrs.drain(..) {
|
||||
if let Some(prev) = instrs.last_mut() {
|
||||
if try_combine_outs(prev, &instr) {
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(OpAnnotate {
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation: "combined by opt_out".into(),
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ impl Shader<'_> {
|
|||
target: bra.target,
|
||||
cond: instr.pred.into(),
|
||||
};
|
||||
MappedInstrs::One(Instr::new_boxed(bra_u))
|
||||
MappedInstrs::One(Instr::new(bra_u))
|
||||
}
|
||||
_ => MappedInstrs::One(instr),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ fn get_or_insert_phi_dsts(bb: &mut BasicBlock) -> &mut OpPhiDsts {
|
|||
let ip = if let Some(ip) = bb.phi_dsts_ip() {
|
||||
ip
|
||||
} else {
|
||||
bb.instrs.insert(0, Instr::new_boxed(OpPhiDsts::new()));
|
||||
bb.instrs.insert(0, Instr::new(OpPhiDsts::new()));
|
||||
0
|
||||
};
|
||||
match &mut bb.instrs[ip].op {
|
||||
|
|
@ -128,10 +128,10 @@ fn get_or_insert_phi_srcs(bb: &mut BasicBlock) -> &mut OpPhiSrcs {
|
|||
let ip = if let Some(ip) = bb.phi_srcs_ip() {
|
||||
ip
|
||||
} else if let Some(ip) = bb.branch_ip() {
|
||||
bb.instrs.insert(ip, Instr::new_boxed(OpPhiSrcs::new()));
|
||||
bb.instrs.insert(ip, Instr::new(OpPhiSrcs::new()));
|
||||
ip
|
||||
} else {
|
||||
bb.instrs.push(Instr::new_boxed(OpPhiSrcs::new()));
|
||||
bb.instrs.push(Instr::new(OpPhiSrcs::new()));
|
||||
bb.instrs.len() - 1
|
||||
};
|
||||
match &mut bb.instrs[ip].op {
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ where
|
|||
let mut instr_iter = func
|
||||
.blocks
|
||||
.iter()
|
||||
.flat_map(|b| b.instrs.iter().map(|x| &**x))
|
||||
.flat_map(|b| b.instrs.iter().map(|x| &*x))
|
||||
.peekable();
|
||||
let mut filling_instr = Instr {
|
||||
pred: true.into(),
|
||||
|
|
|
|||
|
|
@ -3360,7 +3360,7 @@ fn as_sm50_op_mut(op: &mut Op) -> &mut dyn SM50Op {
|
|||
|
||||
fn encode_instr(
|
||||
instr_index: usize,
|
||||
instr: Option<&Box<Instr>>,
|
||||
instr: Option<&Instr>,
|
||||
sm: &ShaderModel50,
|
||||
labels: &FxHashMap<Label, usize>,
|
||||
ip: &mut usize,
|
||||
|
|
|
|||
|
|
@ -85,8 +85,8 @@ impl PhiSrcMap {
|
|||
|
||||
trait Spill {
|
||||
fn spill_file(&self, file: RegFile) -> RegFile;
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Box<Instr>;
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Box<Instr>;
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Instr;
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Instr;
|
||||
}
|
||||
|
||||
struct SpillUniform<'a> {
|
||||
|
|
@ -105,17 +105,17 @@ impl Spill for SpillUniform<'_> {
|
|||
file.to_warp()
|
||||
}
|
||||
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Box<Instr> {
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Instr {
|
||||
self.info.num_spills_to_reg += 1;
|
||||
Instr::new_boxed(OpCopy {
|
||||
Instr::new(OpCopy {
|
||||
dst: dst.into(),
|
||||
src: src,
|
||||
})
|
||||
}
|
||||
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Box<Instr> {
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Instr {
|
||||
self.info.num_fills_from_reg += 1;
|
||||
Instr::new_boxed(OpR2UR {
|
||||
Instr::new(OpR2UR {
|
||||
dst: dst,
|
||||
src: src.into(),
|
||||
})
|
||||
|
|
@ -141,17 +141,17 @@ impl Spill for SpillPred<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Box<Instr> {
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Instr {
|
||||
assert!(matches!(dst.file(), RegFile::GPR | RegFile::UGPR));
|
||||
self.info.num_spills_to_reg += 1;
|
||||
if let Some(b) = src.as_bool() {
|
||||
let u32_src = Src::from(if b { !0 } else { 0 });
|
||||
Instr::new_boxed(OpCopy {
|
||||
Instr::new(OpCopy {
|
||||
dst: dst.into(),
|
||||
src: u32_src,
|
||||
})
|
||||
} else {
|
||||
Instr::new_boxed(OpSel {
|
||||
Instr::new(OpSel {
|
||||
dst: dst.into(),
|
||||
cond: src.bnot(),
|
||||
srcs: [0.into(), (!0).into()],
|
||||
|
|
@ -159,10 +159,10 @@ impl Spill for SpillPred<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Box<Instr> {
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Instr {
|
||||
assert!(matches!(src.file(), RegFile::GPR | RegFile::UGPR));
|
||||
self.info.num_fills_from_reg += 1;
|
||||
Instr::new_boxed(OpISetP {
|
||||
Instr::new(OpISetP {
|
||||
dst: dst,
|
||||
set_op: PredSetOp::And,
|
||||
cmp_op: IntCmpOp::Ne,
|
||||
|
|
@ -191,20 +191,20 @@ impl Spill for SpillBar<'_> {
|
|||
RegFile::GPR
|
||||
}
|
||||
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Box<Instr> {
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Instr {
|
||||
assert!(dst.file() == RegFile::GPR);
|
||||
self.info.num_spills_to_reg += 1;
|
||||
Instr::new_boxed(OpBMov {
|
||||
Instr::new(OpBMov {
|
||||
dst: dst.into(),
|
||||
src: src,
|
||||
clear: false,
|
||||
})
|
||||
}
|
||||
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Box<Instr> {
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Instr {
|
||||
assert!(src.file() == RegFile::GPR);
|
||||
self.info.num_fills_from_reg += 1;
|
||||
Instr::new_boxed(OpBMov {
|
||||
Instr::new(OpBMov {
|
||||
dst: dst,
|
||||
src: src.into(),
|
||||
clear: false,
|
||||
|
|
@ -228,12 +228,12 @@ impl Spill for SpillGPR<'_> {
|
|||
RegFile::Mem
|
||||
}
|
||||
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Box<Instr> {
|
||||
fn spill(&mut self, dst: SSAValue, src: Src) -> Instr {
|
||||
assert!(dst.file() == RegFile::Mem);
|
||||
self.info.num_spills_to_mem += 1;
|
||||
if let Some(ssa) = src.as_ssa() {
|
||||
assert!(ssa.file() == RegFile::GPR);
|
||||
Instr::new_boxed(OpCopy {
|
||||
Instr::new(OpCopy {
|
||||
dst: dst.into(),
|
||||
src: src,
|
||||
})
|
||||
|
|
@ -241,14 +241,14 @@ impl Spill for SpillGPR<'_> {
|
|||
// We use parallel copies for spilling non-GPR things to Mem
|
||||
let mut pcopy = OpParCopy::new();
|
||||
pcopy.push(dst.into(), src);
|
||||
Instr::new_boxed(pcopy)
|
||||
Instr::new(pcopy)
|
||||
}
|
||||
}
|
||||
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Box<Instr> {
|
||||
fn fill(&mut self, dst: Dst, src: SSAValue) -> Instr {
|
||||
assert!(src.file() == RegFile::Mem);
|
||||
self.info.num_fills_from_mem += 1;
|
||||
Instr::new_boxed(OpCopy {
|
||||
Instr::new(OpCopy {
|
||||
dst: dst,
|
||||
src: src.into(),
|
||||
})
|
||||
|
|
@ -319,12 +319,12 @@ impl<'a, S: Spill> SpillCache<'a, S> {
|
|||
})
|
||||
}
|
||||
|
||||
fn spill_src(&mut self, ssa: SSAValue, src: Src) -> Box<Instr> {
|
||||
fn spill_src(&mut self, ssa: SSAValue, src: Src) -> Instr {
|
||||
let dst = self.get_spill(ssa);
|
||||
self.spill.spill(dst, src)
|
||||
}
|
||||
|
||||
fn spill(&mut self, ssa: SSAValue) -> Box<Instr> {
|
||||
fn spill(&mut self, ssa: SSAValue) -> Instr {
|
||||
if let Some(c) = self.const_tracker.get(&ssa) {
|
||||
self.spill_src(ssa, c.clone().into())
|
||||
} else {
|
||||
|
|
@ -332,14 +332,14 @@ impl<'a, S: Spill> SpillCache<'a, S> {
|
|||
}
|
||||
}
|
||||
|
||||
fn fill_dst(&mut self, dst: Dst, ssa: SSAValue) -> Box<Instr> {
|
||||
fn fill_dst(&mut self, dst: Dst, ssa: SSAValue) -> Instr {
|
||||
let src = self.get_spill(ssa);
|
||||
self.spill.fill(dst, src)
|
||||
}
|
||||
|
||||
fn fill(&mut self, ssa: SSAValue) -> Box<Instr> {
|
||||
fn fill(&mut self, ssa: SSAValue) -> Instr {
|
||||
if let Some(c) = self.const_tracker.get(&ssa) {
|
||||
Instr::new_boxed(OpCopy {
|
||||
Instr::new(OpCopy {
|
||||
dst: ssa.into(),
|
||||
src: c.clone().into(),
|
||||
})
|
||||
|
|
@ -800,13 +800,11 @@ fn spill_values<S: Spill>(
|
|||
if spills.contains(dst_ssa) {
|
||||
if b.s.insert(*src_ssa) {
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(
|
||||
OpAnnotate {
|
||||
annotation:
|
||||
"generated by spill_values"
|
||||
.into(),
|
||||
},
|
||||
));
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation:
|
||||
"generated by spill_values"
|
||||
.into(),
|
||||
}));
|
||||
}
|
||||
instrs.push(spill.spill(*src_ssa));
|
||||
}
|
||||
|
|
@ -863,7 +861,7 @@ fn spill_values<S: Spill>(
|
|||
instr.for_each_ssa_use_mut(|ssa| {
|
||||
if ssa.file() == file && !b.w.contains(ssa) {
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(OpAnnotate {
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation: "generated by spill_values"
|
||||
.into(),
|
||||
}));
|
||||
|
|
@ -908,13 +906,11 @@ fn spill_values<S: Spill>(
|
|||
b.w.remove(&ssa);
|
||||
if !spill.is_const(&ssa) {
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(
|
||||
OpAnnotate {
|
||||
annotation:
|
||||
"generated by spill_values"
|
||||
.into(),
|
||||
},
|
||||
));
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation:
|
||||
"generated by spill_values"
|
||||
.into(),
|
||||
}));
|
||||
}
|
||||
instrs.push(spill.spill(ssa));
|
||||
b.s.insert(ssa);
|
||||
|
|
@ -923,7 +919,7 @@ fn spill_values<S: Spill>(
|
|||
}
|
||||
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(OpAnnotate {
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation: "generated by spill_values".into(),
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -339,11 +339,11 @@ impl Function {
|
|||
instrs.push(instr);
|
||||
if !pcopy.is_empty() {
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(OpAnnotate {
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation: "generated by to_cssa".into(),
|
||||
}));
|
||||
}
|
||||
instrs.push(Instr::new_boxed(pcopy));
|
||||
instrs.push(Instr::new(pcopy));
|
||||
}
|
||||
}
|
||||
Op::PhiSrcs(phi) => {
|
||||
|
|
@ -374,12 +374,12 @@ impl Function {
|
|||
// parallel copy.
|
||||
let tmp = self.ssa_alloc.alloc(file);
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(OpAnnotate {
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation: "generated by to_cssa".into(),
|
||||
}));
|
||||
}
|
||||
let old_src = std::mem::replace(src, tmp.into());
|
||||
instrs.push(Instr::new_boxed(OpCopy {
|
||||
instrs.push(Instr::new(OpCopy {
|
||||
dst: tmp.into(),
|
||||
src: old_src,
|
||||
}));
|
||||
|
|
@ -387,11 +387,11 @@ impl Function {
|
|||
|
||||
if !pcopy.is_empty() {
|
||||
if DEBUG.annotate() {
|
||||
instrs.push(Instr::new_boxed(OpAnnotate {
|
||||
instrs.push(Instr::new(OpAnnotate {
|
||||
annotation: "generated by to_cssa".into(),
|
||||
}));
|
||||
}
|
||||
instrs.push(Instr::new_boxed(pcopy));
|
||||
instrs.push(Instr::new(pcopy));
|
||||
}
|
||||
instrs.push(instr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue