[llvm] [llvm-exegesis] Add branch miss validation counter (PR #81094)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 23:02:54 PST 2024


https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/81094

This patch adds a branch miss validation counter so that it is easy to quantify the number of missed branches when using the loop repetition mode.

>From 3d8cdf163b7e69b7538ac28fc7a62b373783fbf7 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Wed, 7 Feb 2024 23:00:25 -0800
Subject: [PATCH] [llvm-exegesis] Add branch miss validation counter

This patch adds a branch miss validation counter so that it is easy to
quantify the number of missed branches when using the loop repetition
mode.
---
 llvm/include/llvm/Target/TargetPfmCounters.td    | 1 +
 llvm/lib/Target/X86/X86PfmCounters.td            | 6 ++++--
 llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | 4 ++++
 llvm/tools/llvm-exegesis/lib/BenchmarkResult.h   | 3 ++-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp       | 4 +++-
 5 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td b/llvm/include/llvm/Target/TargetPfmCounters.td
index c56f388fbd94b0..8c4d5f50c63a24 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -42,6 +42,7 @@ def L1ICacheLoadMiss : ValidationEvent<3>;
 def DataTLBLoadMiss : ValidationEvent<4>;
 def DataTLBStoreMiss : ValidationEvent<5>;
 def InstructionTLBLoadMiss : ValidationEvent<6>;
+def BranchPredictionMiss : ValidationEvent<7>;
 
 
 // PfmValidationCounter provides a mapping between the events that are
diff --git a/llvm/lib/Target/X86/X86PfmCounters.td b/llvm/lib/Target/X86/X86PfmCounters.td
index da3acc5bbf56f7..d87a559aa353b1 100644
--- a/llvm/lib/Target/X86/X86PfmCounters.td
+++ b/llvm/lib/Target/X86/X86PfmCounters.td
@@ -24,7 +24,8 @@ defvar DefaultIntelPfmValidationCounters = [
   PfmValidationCounter<L1ICacheLoadMiss, "L1-ICACHE-LOAD-MISSES">,
   PfmValidationCounter<DataTLBLoadMiss, "DTLB_LOAD_MISSES:MISS_CAUSES_A_WALK">,
   PfmValidationCounter<DataTLBStoreMiss, "DTLB_STORE_MISSES:MISS_CAUSES_A_WALK">,
-  PfmValidationCounter<InstructionTLBLoadMiss, "ITLB_MISSES:MISS_CAUSES_A_WALK">
+  PfmValidationCounter<InstructionTLBLoadMiss, "ITLB_MISSES:MISS_CAUSES_A_WALK">,
+  PfmValidationCounter<BranchPredictionMiss, "BRANCH-MISSES">
 ];
 
 def PentiumPfmCounters : ProcPfmCounters {
@@ -210,7 +211,8 @@ defvar DefaultAMDPfmValidationCounters = [
   PfmValidationCounter<L1DCacheStoreMiss, "L1-DCACHE-STORE-MISSES">,
   PfmValidationCounter<L1ICacheLoadMiss, "L1-ICACHE-LOAD-MISSES">,
   PfmValidationCounter<DataTLBLoadMiss, "DTLB-LOAD-MISSES">,
-  PfmValidationCounter<InstructionTLBLoadMiss, "ITLB-LOAD-MISSES">
+  PfmValidationCounter<InstructionTLBLoadMiss, "ITLB-LOAD-MISSES">,
+  PfmValidationCounter<BranchPredictionMiss, "BRANCH-MISSES">
 ];
 
 // Set basic counters for AMD cpus that we know libpfm4 supports.
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index c193a8e5027713..570af6eafb5857 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -209,6 +209,8 @@ const char *validationEventToString(exegesis::ValidationEvent VE) {
     return "data-tlb-store-misses";
   case exegesis::ValidationEvent::InstructionTLBLoadMiss:
     return "instruction-tlb-load-misses";
+  case exegesis::ValidationEvent::BranchPredictionMiss:
+    return "branch-prediction-misses";
   }
   llvm_unreachable("Unhandled exegesis::ValidationEvent enum");
 }
@@ -228,6 +230,8 @@ Expected<exegesis::ValidationEvent> stringToValidationEvent(StringRef Input) {
     return exegesis::ValidationEvent::DataTLBStoreMiss;
   else if (Input == "instruction-tlb-load-misses")
     return exegesis::ValidationEvent::InstructionTLBLoadMiss;
+  else if (Input == "branch-prediction-misses")
+    return exegesis::ValidationEvent::BranchPredictionMiss;
   else
     return make_error<StringError>("Invalid validation event string",
                                    errc::invalid_argument);
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 43f03ff5413388..c5d7bd23a41d42 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -39,7 +39,8 @@ enum ValidationEvent {
   L1ICacheLoadMiss,
   DataTLBLoadMiss,
   DataTLBStoreMiss,
-  InstructionTLBLoadMiss
+  InstructionTLBLoadMiss,
+  BranchPredictionMiss
 };
 
 enum class BenchmarkPhaseSelectorE {
diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index 90de3e5bcf1db6..ac279029e6b004 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -293,7 +293,9 @@ static cl::list<ValidationEvent> ValidationCounters(
         clEnumValN(ValidationEvent::DataTLBStoreMiss, "data-tlb-store-misses",
                    "Count DTLB store misses"),
         clEnumValN(ValidationEvent::InstructionTLBLoadMiss,
-                   "instruction-tlb-load-misses", "Count ITLB load misses")));
+                   "instruction-tlb-load-misses", "Count ITLB load misses"),
+        clEnumValN(ValidationEvent::BranchPredictionMiss,
+                   "branch-prediction-misses", "Branch prediction misses")));
 
 static ExitOnError ExitOnErr("llvm-exegesis error: ");
 



More information about the llvm-commits mailing list