diff --git a/src/nouveau/compiler/nak/assign_regs.rs b/src/nouveau/compiler/nak/assign_regs.rs index bc4e5c071f2..8929ff1a3cb 100644 --- a/src/nouveau/compiler/nak/assign_regs.rs +++ b/src/nouveau/compiler/nak/assign_regs.rs @@ -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 { diff --git a/src/nouveau/compiler/nak/legalize.rs b/src/nouveau/compiler/nak/legalize.rs index 9a5acafc412..473dc5933a2 100644 --- a/src/nouveau/compiler/nak/legalize.rs +++ b/src/nouveau/compiler/nak/legalize.rs @@ -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 { diff --git a/src/nouveau/compiler/nak/lower_copy_swap.rs b/src/nouveau/compiler/nak/lower_copy_swap.rs index d4cfa153e2f..2a44cf1ff1c 100644 --- a/src/nouveau/compiler/nak/lower_copy_swap.rs +++ b/src/nouveau/compiler/nak/lower_copy_swap.rs @@ -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() } diff --git a/src/nouveau/compiler/nak/lower_par_copies.rs b/src/nouveau/compiler/nak/lower_par_copies.rs index e45c85ab68d..6540a6ce60e 100644 --- a/src/nouveau/compiler/nak/lower_par_copies.rs +++ b/src/nouveau/compiler/nak/lower_par_copies.rs @@ -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), } diff --git a/src/nouveau/compiler/nak/opt_bar_prop.rs b/src/nouveau/compiler/nak/opt_bar_prop.rs index 8716e9a056e..e3da9c2d977 100644 --- a/src/nouveau/compiler/nak/opt_bar_prop.rs +++ b/src/nouveau/compiler/nak/opt_bar_prop.rs @@ -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) } } diff --git a/src/nouveau/compiler/nak/opt_dce.rs b/src/nouveau/compiler/nak/opt_dce.rs index 8b690672058..c6793e6321a 100644 --- a/src/nouveau/compiler/nak/opt_dce.rs +++ b/src/nouveau/compiler/nak/opt_dce.rs @@ -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 + } } } diff --git a/src/nouveau/compiler/nak/opt_out.rs b/src/nouveau/compiler/nak/opt_out.rs index 559472c3119..df173c224af 100644 --- a/src/nouveau/compiler/nak/opt_out.rs +++ b/src/nouveau/compiler/nak/opt_out.rs @@ -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; } } diff --git a/src/nouveau/compiler/nak/spill_values.rs b/src/nouveau/compiler/nak/spill_values.rs index 2fbc0090c1f..788de4d8a6c 100644 --- a/src/nouveau/compiler/nak/spill_values.rs +++ b/src/nouveau/compiler/nak/spill_values.rs @@ -666,6 +666,15 @@ fn spill_values( 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( 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| { diff --git a/src/nouveau/compiler/nak/to_cssa.rs b/src/nouveau/compiler/nak/to_cssa.rs index 7ba736a70b9..2e01a9dae2a 100644 --- a/src/nouveau/compiler/nak/to_cssa.rs +++ b/src/nouveau/compiler/nak/to_cssa.rs @@ -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);