[llvm] [llvm-exegesis] Simplify validation event string conversion functions (PR #82092)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 16 20:34:53 PST 2024
https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/82092
Currently, there are two string conversion functions that convert between strings and validation events. This patch changes the logic to search through a single array of pairs rather than manually reimplementing each function to make development slightly easier.
>From 961f390668f3782aefa3355d923e00754df6da3c Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Fri, 16 Feb 2024 20:33:01 -0800
Subject: [PATCH] [llvm-exegesis] Simplify validation event string conversion
functions
Currently, there are two string conversion functions that convert
between strings and validation events. This patch changes the logic to
search through a single array of pairs rather than manually
reimplementing each function to make development slightly easier.
---
.../llvm-exegesis/lib/BenchmarkResult.cpp | 61 +++++++++----------
1 file changed, 29 insertions(+), 32 deletions(-)
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index c193a8e5027713..49df206e946932 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -24,6 +24,24 @@ static constexpr const char kIntegerPrefix[] = "i_0x";
static constexpr const char kDoublePrefix[] = "f_";
static constexpr const char kInvalidOperand[] = "INVALID";
+// When adding a new validation counter, a new event type needs to be added
+// to llvm::exegesis::ValidationEvent, a mapping needs to be added below,
+// a command line option needs to be added in llvm-exegesis.cpp, and the
+// event type needs to be added (with matching naming) in TargetPfmCounters.td
+// and appropriate mappings need to be added in the relevant architecture
+// Pfm descriptions.
+static constexpr const std::pair<llvm::exegesis::ValidationEvent,
+ llvm::StringRef>
+ kValidationEventNames[] = {
+ {llvm::exegesis::InstructionRetired, "instructions-retired"},
+ {llvm::exegesis::L1DCacheLoadMiss, "l1d-cache-load-misses"},
+ {llvm::exegesis::L1DCacheStoreMiss, "l1d-cache-store-misses"},
+ {llvm::exegesis::L1ICacheLoadMiss, "l1i-cache-load-misses"},
+ {llvm::exegesis::DataTLBLoadMiss, "data-tlb-load-misses"},
+ {llvm::exegesis::DataTLBStoreMiss, "data-tlb-store-misses"},
+ {llvm::exegesis::InstructionTLBLoadMiss,
+ "instruction-tlb-load-misses"}};
+
namespace llvm {
namespace {
@@ -194,43 +212,22 @@ template <> struct SequenceElementTraits<exegesis::BenchmarkMeasure> {
};
const char *validationEventToString(exegesis::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";
+ for (const auto [ValidationEventType, ValidationEventName] :
+ kValidationEventNames) {
+ if (VE == ValidationEventType)
+ return ValidationEventName.data();
}
llvm_unreachable("Unhandled exegesis::ValidationEvent enum");
}
Expected<exegesis::ValidationEvent> 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
- return make_error<StringError>("Invalid validation event string",
- errc::invalid_argument);
+ for (const auto [ValidationEventType, ValidationEventName] :
+ kValidationEventNames) {
+ if (Input == ValidationEventName)
+ return ValidationEventType;
+ }
+ return make_error<StringError>("Invalid validation event string",
+ errc::invalid_argument);
}
template <>
More information about the llvm-commits
mailing list