xref: /llvm-project/llvm/tools/llvm-exegesis/lib/ValidationEvent.cpp (revision 8b84de26dfc1ba742b427e45bc900bc233fd58e1)
1 
2 #include "ValidationEvent.h"
3 #include "llvm/ADT/StringRef.h"
4 #include "llvm/Support/Errc.h"
5 #include "llvm/Support/Error.h"
6 
7 namespace llvm {
8 namespace exegesis {
9 
10 namespace {
11 
12 struct ValidationEventInfo {
13   const char *const Name;
14   const char *const Description;
15 };
16 
17 // Information about validation events, indexed by `ValidationEvent` enum
18 // value.
19 static 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 
30 static_assert(sizeof(ValidationEventInfos) ==
31                   NumValidationEvents * sizeof(ValidationEventInfo),
32               "please update ValidationEventInfos");
33 
34 } // namespace
35 
getValidationEventName(ValidationEvent VE)36 const char *getValidationEventName(ValidationEvent VE) {
37   return ValidationEventInfos[VE].Name;
38 }
getValidationEventDescription(ValidationEvent VE)39 const char *getValidationEventDescription(ValidationEvent VE) {
40   return ValidationEventInfos[VE].Description;
41 }
42 
getValidationEventByName(StringRef Name)43 Expected<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 exegesis
56 } // namespace llvm
57