57 lines · cpp
1 2#include "ValidationEvent.h"3#include "llvm/ADT/StringRef.h"4#include "llvm/Support/Errc.h"5#include "llvm/Support/Error.h"6 7namespace llvm {8namespace exegesis {9 10namespace {11 12struct ValidationEventInfo {13 const char *const Name;14 const char *const Description;15};16 17// Information about validation events, indexed by `ValidationEvent` enum18// value.19static constexpr ValidationEventInfo ValidationEventInfos[] = {20 {"instructions-retired", "Count retired instructions"},21 {"l1d-cache-load-misses", "Count L1D load cache misses"},22 {"l1d-cache-store-misses", "Count L1D store cache misses"},23 {"l1i-cache-load-misses", "Count L1I load cache misses"},24 {"data-tlb-load-misses", "Count DTLB load misses"},25 {"data-tlb-store-misses", "Count DTLB store misses"},26 {"instruction-tlb-load-misses", "Count ITLB load misses"},27 {"branch-prediction-misses", "Branch prediction misses"},28};29 30static_assert(sizeof(ValidationEventInfos) ==31 NumValidationEvents * sizeof(ValidationEventInfo),32 "please update ValidationEventInfos");33 34} // namespace35 36const char *getValidationEventName(ValidationEvent VE) {37 return ValidationEventInfos[VE].Name;38}39const char *getValidationEventDescription(ValidationEvent VE) {40 return ValidationEventInfos[VE].Description;41}42 43Expected<ValidationEvent> getValidationEventByName(StringRef Name) {44 int VE = 0;45 for (const ValidationEventInfo &Info : ValidationEventInfos) {46 if (Name == Info.Name)47 return static_cast<ValidationEvent>(VE);48 ++VE;49 }50 51 return make_error<StringError>("Invalid validation event string",52 errc::invalid_argument);53}54 55} // namespace exegesis56} // namespace llvm57