Module: Mesa
Branch: main
Commit: d200916ca2f656a5f81d6713a9073d7f66a5fa7a
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=d200916ca2f656a5f81d6713a9073d7f66a5fa7a

Author: Rhys Perry <pendingchao...@gmail.com>
Date:   Wed Oct  4 17:28:38 2023 +0100

aco: add VALU/SALU/VMEM/SMEM statistics

This lets us measure optimizations without interference of waitcnt
instructions.

Signed-off-by: Rhys Perry <pendingchao...@gmail.com>
Reviewed-by: Daniel Schürmann <dan...@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25559>

---

 src/amd/compiler/aco_interface.cpp  |  4 ++++
 src/amd/compiler/aco_shader_info.h  |  4 ++++
 src/amd/compiler/aco_statistics.cpp | 14 +++++++++++---
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/amd/compiler/aco_interface.cpp 
b/src/amd/compiler/aco_interface.cpp
index 8b4950823e4..bdf74ca5dd1 100644
--- a/src/amd/compiler/aco_interface.cpp
+++ b/src/amd/compiler/aco_interface.cpp
@@ -55,6 +55,10 @@ static const std::array<aco_compiler_statistic_info, 
aco_num_statistics> statist
       aco_compiler_statistic_info{"Pre-Sched SGPRs", "SGPR usage before 
scheduling"};
    ret[aco_statistic_vgpr_presched] =
       aco_compiler_statistic_info{"Pre-Sched VGPRs", "VGPR usage before 
scheduling"};
+   ret[aco_statistic_valu] = aco_compiler_statistic_info{"VALU", "Number of 
VALU instructions"};
+   ret[aco_statistic_salu] = aco_compiler_statistic_info{"SALU", "Number of 
SALU instructions"};
+   ret[aco_statistic_vmem] = aco_compiler_statistic_info{"VMEM", "Number of 
VMEM instructions"};
+   ret[aco_statistic_smem] = aco_compiler_statistic_info{"SMEM", "Number of 
SMEM instructions"};
    return ret;
 }();
 
diff --git a/src/amd/compiler/aco_shader_info.h 
b/src/amd/compiler/aco_shader_info.h
index a9559f9d783..2664fdae3f8 100644
--- a/src/amd/compiler/aco_shader_info.h
+++ b/src/amd/compiler/aco_shader_info.h
@@ -226,6 +226,10 @@ enum aco_statistic {
    aco_statistic_smem_clauses,
    aco_statistic_sgpr_presched,
    aco_statistic_vgpr_presched,
+   aco_statistic_valu,
+   aco_statistic_salu,
+   aco_statistic_vmem,
+   aco_statistic_smem,
    aco_num_statistics
 };
 
diff --git a/src/amd/compiler/aco_statistics.cpp 
b/src/amd/compiler/aco_statistics.cpp
index 89303a43809..e454c2de93b 100644
--- a/src/amd/compiler/aco_statistics.cpp
+++ b/src/amd/compiler/aco_statistics.cpp
@@ -531,11 +531,15 @@ collect_preasm_stats(Program* program)
       program->statistics[aco_statistic_instructions] += 
block.instructions.size();
 
       for (aco_ptr<Instruction>& instr : block.instructions) {
-         if (instr->isSOPP() && instr->sopp().block != -1)
+         bool is_branch = instr->isSOPP() && instr->sopp().block != -1;
+         if (is_branch)
             program->statistics[aco_statistic_branches]++;
 
-         if (instr->opcode == aco_opcode::p_constaddr)
-            program->statistics[aco_statistic_instructions] += 2;
+         if (instr->isVALU() || instr->isVINTRP())
+            program->statistics[aco_statistic_valu]++;
+         if (instr->isSALU() && !instr->isSOPP() &&
+             instr_info.classes[(int)instr->opcode] != instr_class::waitcnt)
+            program->statistics[aco_statistic_salu]++;
 
          if ((instr->isVMEM() || instr->isScratch() || instr->isGlobal()) &&
              !instr->operands.empty()) {
@@ -544,6 +548,8 @@ collect_preasm_stats(Program* program)
                              { return should_form_clause(instr.get(), other); 
}))
                program->statistics[aco_statistic_vmem_clauses]++;
             vmem_clause.insert(instr.get());
+
+            program->statistics[aco_statistic_vmem]++;
          } else {
             vmem_clause.clear();
          }
@@ -554,6 +560,8 @@ collect_preasm_stats(Program* program)
                              { return should_form_clause(instr.get(), other); 
}))
                program->statistics[aco_statistic_smem_clauses]++;
             smem_clause.insert(instr.get());
+
+            program->statistics[aco_statistic_smem]++;
          } else {
             smem_clause.clear();
          }

Reply via email to