https://github.com/legrosbuffle updated
https://github.com/llvm/llvm-project/pull/82617
>From 9b93c8bf0614e64352de8e210adf6ff316c0133e Mon Sep 17 00:00:00 2001
From: Clement Courbet
Date: Mon, 19 Feb 2024 14:58:27 +
Subject: [PATCH 1/5] [llvm-exegesis][NFC] Refactor all `ValidationEvent` info
in a single table.
All data is derived from a single table rather than being spread out
over an enum, a table and the main entry point.
---
llvm/include/llvm/Target/TargetPfmCounters.td | 1 +
.../llvm-exegesis/lib/BenchmarkResult.cpp | 49 +--
.../tools/llvm-exegesis/lib/BenchmarkResult.h | 15 +
llvm/tools/llvm-exegesis/lib/CMakeLists.txt | 1 +
.../lib/LatencyBenchmarkRunner.cpp| 4 +-
llvm/tools/llvm-exegesis/lib/Target.h | 1 +
.../llvm-exegesis/lib/ValidationEvent.cpp | 53
.../tools/llvm-exegesis/lib/ValidationEvent.h | 60 +++
llvm/tools/llvm-exegesis/llvm-exegesis.cpp| 20 +--
9 files changed, 124 insertions(+), 80 deletions(-)
create mode 100644 llvm/tools/llvm-exegesis/lib/ValidationEvent.cpp
create mode 100644 llvm/tools/llvm-exegesis/lib/ValidationEvent.h
diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td
b/llvm/include/llvm/Target/TargetPfmCounters.td
index 8c4d5f50c63a24..cfe432a992b71f 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -35,6 +35,7 @@ class ValidationEvent {
int EventNumber = event_number;
}
+// TableGen names for events defined in `llvm::exegesis::ValidationEvent`.
def InstructionRetired : ValidationEvent<0>;
def L1DCacheLoadMiss : ValidationEvent<1>;
def L1DCacheStoreMiss : ValidationEvent<2>;
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 189add6464173f..f84ebd2a4e68ef 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -9,6 +9,7 @@
#include "BenchmarkResult.h"
#include "BenchmarkRunner.h"
#include "Error.h"
+#include "ValidationEvent.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringRef.h"
@@ -198,7 +199,7 @@ struct
CustomMappingTraits> {
static void inputOne(IO , StringRef KeyStr,
std::map ) {
Expected Key =
-exegesis::stringToValidationEvent(KeyStr);
+exegesis::getValidationEventByName(KeyStr);
if (!Key) {
Io.setError("Key is not a valid validation event");
return;
@@ -208,7 +209,7 @@ struct
CustomMappingTraits> {
static void output(IO , std::map )
{
for (auto : VI) {
- Io.mapRequired(exegesis::validationEventToString(IndividualVI.first),
+ Io.mapRequired(exegesis::getValidationEventName(IndividualVI.first),
IndividualVI.second);
}
}
@@ -441,49 +442,5 @@ bool operator==(const BenchmarkMeasure , const
BenchmarkMeasure ) {
std::tie(B.Key, B.PerInstructionValue, B.PerSnippetValue);
}
-const char *validationEventToString(ValidationEvent VE) {
- switch (VE) {
- case exegesis::ValidationEvent::InstructionRetired:
-return "instructions-retired";
- case exegesis::ValidationEvent::L1DCacheLoadMiss:
-return "l1d-cache-load-misses";
- case exegesis::ValidationEvent::L1DCacheStoreMiss:
-return "l1d-cache-store-misses";
- case exegesis::ValidationEvent::L1ICacheLoadMiss:
-return "l1i-cache-load-misses";
- case exegesis::ValidationEvent::DataTLBLoadMiss:
-return "data-tlb-load-misses";
- case exegesis::ValidationEvent::DataTLBStoreMiss:
-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");
-}
-
-Expected stringToValidationEvent(StringRef Input) {
- if (Input == "instructions-retired")
-return exegesis::ValidationEvent::InstructionRetired;
- else if (Input == "l1d-cache-load-misses")
-return exegesis::ValidationEvent::L1DCacheLoadMiss;
- else if (Input == "l1d-cache-store-misses")
-return exegesis::ValidationEvent::L1DCacheStoreMiss;
- else if (Input == "l1i-cache-load-misses")
-return exegesis::ValidationEvent::L1ICacheLoadMiss;
- else if (Input == "data-tlb-load-misses")
-return exegesis::ValidationEvent::DataTLBLoadMiss;
- else if (Input == "data-tlb-store-misses")
-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("Invalid validation event string",
- errc::invalid_argument);
-}
-
} // namespace