nak/sm50: sprinkle OpAnnotate in optimization passes

Not only do we want to know where an Op originated from, but also how it got
transformed along the way if possible. Preferably all the way to the final
machine code emitted.

This commit inserts OpAnnotates in some of the optimization passes when
map_instr() or Instr::new_boxed is used.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27158>
This commit is contained in:
Daniel Almeida 2024-01-16 17:50:24 -03:00 committed by Marge Bot
parent feb2d3e1da
commit efc4ac0d27
9 changed files with 130 additions and 7 deletions

View file

@ -1,6 +1,7 @@
// Copyright © 2022 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use crate::api::{GetDebugFlags, DEBUG};
use crate::bitset::BitSet;
use crate::ir::*;
use crate::liveness::{BlockLiveness, Liveness, SimpleLiveness};
@ -1138,6 +1139,11 @@ impl AssignRegsBlock {
);
if !pcopy.is_empty() {
if DEBUG.annotate() {
instrs.push(Instr::new_boxed(OpAnnotate {
annotation: "generated by assign_regs".into(),
}));
}
instrs.push(Instr::new_boxed(pcopy));
}
@ -1170,6 +1176,11 @@ impl AssignRegsBlock {
pcopy.push(dst.into(), src.into());
}
if DEBUG.annotate() {
b.instrs.push(Instr::new_boxed(OpAnnotate {
annotation: "generated by assign_regs".into(),
}));
}
if b.branch().is_some() {
b.instrs.insert(b.instrs.len() - 1, Instr::new_boxed(pcopy));
} else {

View file

@ -1,6 +1,7 @@
// Copyright © 2022 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use crate::api::{GetDebugFlags, DEBUG};
use crate::ir::*;
use crate::liveness::{BlockLiveness, Liveness, SimpleLiveness};
@ -54,6 +55,12 @@ fn copy_alu_src(b: &mut impl SSABuilder, src: &mut Src, src_type: SrcType) {
_ => panic!("Unknown source type"),
};
if DEBUG.annotate() {
b.push_instr(Instr::new_boxed(OpAnnotate {
annotation: "copy generated by legalizer".into(),
}));
}
if val.comps() == 1 {
b.copy_to(val.into(), src.src_ref.into());
} else {

View file

@ -1,7 +1,10 @@
// Copyright © 2022 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use crate::ir::*;
use crate::{
api::{GetDebugFlags, DEBUG},
ir::*,
};
use std::cmp::max;
@ -179,12 +182,24 @@ impl LowerCopySwap {
Op::Copy(copy) => {
debug_assert!(instr.pred.is_true());
let mut b = InstrBuilder::new(sm);
if DEBUG.annotate() {
b.push_instr(Instr::new_boxed(OpAnnotate {
annotation: "copy lowered by lower_copy_swap"
.into(),
}));
}
self.lower_copy(&mut b, copy);
b.as_mapped_instrs()
}
Op::Swap(swap) => {
debug_assert!(instr.pred.is_true());
let mut b = InstrBuilder::new(sm);
if DEBUG.annotate() {
b.push_instr(Instr::new_boxed(OpAnnotate {
annotation: "swap lowered by lower_copy_swap"
.into(),
}));
}
self.lower_swap(&mut b, swap);
b.as_mapped_instrs()
}

View file

@ -1,7 +1,10 @@
// Copyright © 2022 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use crate::ir::*;
use crate::{
api::{GetDebugFlags, DEBUG},
ir::*,
};
use std::collections::HashMap;
@ -254,7 +257,30 @@ impl Shader {
match instr.op {
Op::ParCopy(pc) => {
assert!(instr.pred.is_true());
lower_par_copy(pc, sm)
let mut instrs = vec![];
if DEBUG.annotate() {
instrs.push(Instr::new_boxed(OpAnnotate {
annotation: "par_copy lowered by lower_par_copy"
.into(),
}));
}
match lower_par_copy(pc, sm) {
MappedInstrs::None => {
if let Some(instr) = instrs.pop() {
MappedInstrs::One(instr)
} else {
MappedInstrs::None
}
}
MappedInstrs::One(i) => {
instrs.push(i);
MappedInstrs::Many(instrs)
}
MappedInstrs::Many(i) => {
instrs.extend(i);
MappedInstrs::Many(instrs)
}
}
}
_ => MappedInstrs::One(instr),
}

View file

@ -1,6 +1,7 @@
// Copyright © 2023 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use crate::api::{GetDebugFlags, DEBUG};
use crate::bitset::BitSet;
use crate::ir::*;
@ -236,7 +237,16 @@ impl BarPropPass {
if bmovs.is_empty() {
MappedInstrs::One(instr)
} else {
bmovs.insert(0, instr);
if DEBUG.annotate() {
bmovs.insert(
0,
Instr::new_boxed(OpAnnotate {
annotation: "generated by opt_bar_prop"
.into(),
}),
);
}
bmovs.insert(1, instr);
MappedInstrs::Many(bmovs)
}
}

View file

@ -1,7 +1,10 @@
// Copyright © 2022 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use crate::ir::*;
use crate::{
api::{GetDebugFlags, DEBUG},
ir::*,
};
use std::collections::HashSet;
@ -143,7 +146,13 @@ impl DeadCodePass {
if is_live {
MappedInstrs::One(instr)
} else {
MappedInstrs::None
if DEBUG.annotate() {
MappedInstrs::One(Instr::new_boxed(OpAnnotate {
annotation: "killed by dce".into(),
}))
} else {
MappedInstrs::None
}
}
}

View file

@ -1,7 +1,10 @@
// Copyright © 2023 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use crate::ir::*;
use crate::{
api::{GetDebugFlags, DEBUG},
ir::*,
};
fn try_combine_outs(emit: &mut Instr, cut: &Instr) -> bool {
let Op::Out(emit) = &mut emit.op else {
@ -46,6 +49,11 @@ impl Shader {
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 {
annotation: "combined by opt_out".into(),
}));
}
continue;
}
}

View file

@ -666,6 +666,15 @@ fn spill_values<S: Spill>(
let src_ssa = &src.src_ref.as_ssa().unwrap()[0];
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(spill.spill(*src_ssa));
}
b.s.insert(*dst_ssa);
@ -710,11 +719,22 @@ fn spill_values<S: Spill>(
for ssa in spills {
debug_assert!(ssa.file() == file);
b.w.remove(&ssa);
if DEBUG.annotate() {
instrs.push(Instr::new_boxed(OpAnnotate {
annotation: "generated by spill_values"
.into(),
}));
}
instrs.push(spill.spill(ssa));
b.s.insert(ssa);
}
}
if DEBUG.annotate() {
instrs.push(Instr::new_boxed(OpAnnotate {
annotation: "generated by spill_values".into(),
}));
}
instrs.append(&mut fills);
instr.for_each_ssa_use(|ssa| {

View file

@ -1,6 +1,7 @@
// Copyright © 2023 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use crate::api::{GetDebugFlags, DEBUG};
use crate::cfg::CFG;
use crate::ir::*;
use crate::liveness::{BlockLiveness, Liveness, SimpleLiveness};
@ -338,6 +339,11 @@ impl Function {
instrs.push(instr);
if !pcopy.is_empty() {
if DEBUG.annotate() {
instrs.push(Instr::new_boxed(OpAnnotate {
annotation: "generated by to_cssa".into(),
}));
}
instrs.push(Instr::new_boxed(pcopy));
}
}
@ -362,6 +368,12 @@ impl Function {
// and are not considered part of the parallel
// copy.
let tmp = self.ssa_alloc.alloc(file);
if DEBUG.annotate() {
instrs.push(Instr::new_boxed(OpAnnotate {
annotation: "generated by to_cssa"
.into(),
}));
}
instrs.push(Instr::new_boxed(OpCopy {
dst: tmp.into(),
src: *src,
@ -371,6 +383,11 @@ impl Function {
}
if !pcopy.is_empty() {
if DEBUG.annotate() {
instrs.push(Instr::new_boxed(OpAnnotate {
annotation: "generated by to_cssa".into(),
}));
}
instrs.push(Instr::new_boxed(pcopy));
}
instrs.push(instr);