llvm-project/llvm/tools/llvm-exegesis/lib/ValidationEvent.cpp
Clement Courbet 8b84de26df
[llvm-exegesis][NFC] Refactor all ValidationEvent info in a single … (#82256)
…table.

All data is derived from a single table rather than being spread out
over an enum, a table and the main entry point.

This is intended as a replacement for #82092.
2024-02-21 09:48:20 +01:00

57 lines
1.7 KiB
C++

#include "ValidationEvent.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
namespace llvm {
namespace exegesis {
namespace {
struct ValidationEventInfo {
const char *const Name;
const char *const Description;
};
// Information about validation events, indexed by `ValidationEvent` enum
// value.
static constexpr ValidationEventInfo ValidationEventInfos[] = {
{"instructions-retired", "Count retired instructions"},
{"l1d-cache-load-misses", "Count L1D load cache misses"},
{"l1d-cache-store-misses", "Count L1D store cache misses"},
{"l1i-cache-load-misses", "Count L1I load cache misses"},
{"data-tlb-load-misses", "Count DTLB load misses"},
{"data-tlb-store-misses", "Count DTLB store misses"},
{"instruction-tlb-load-misses", "Count ITLB load misses"},
{"branch-prediction-misses", "Branch prediction misses"},
};
static_assert(sizeof(ValidationEventInfos) ==
NumValidationEvents * sizeof(ValidationEventInfo),
"please update ValidationEventInfos");
} // namespace
const char *getValidationEventName(ValidationEvent VE) {
return ValidationEventInfos[VE].Name;
}
const char *getValidationEventDescription(ValidationEvent VE) {
return ValidationEventInfos[VE].Description;
}
Expected<ValidationEvent> getValidationEventByName(StringRef Name) {
int VE = 0;
for (const ValidationEventInfo &Info : ValidationEventInfos) {
if (Name == Info.Name)
return static_cast<ValidationEvent>(VE);
++VE;
}
return make_error<StringError>("Invalid validation event string",
errc::invalid_argument);
}
} // namespace exegesis
} // namespace llvm