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 | {.Name: "instructions-retired" , .Description: "Count retired instructions" }, |
21 | {.Name: "l1d-cache-load-misses" , .Description: "Count L1D load cache misses" }, |
22 | {.Name: "l1d-cache-store-misses" , .Description: "Count L1D store cache misses" }, |
23 | {.Name: "l1i-cache-load-misses" , .Description: "Count L1I load cache misses" }, |
24 | {.Name: "data-tlb-load-misses" , .Description: "Count DTLB load misses" }, |
25 | {.Name: "data-tlb-store-misses" , .Description: "Count DTLB store misses" }, |
26 | {.Name: "instruction-tlb-load-misses" , .Description: "Count ITLB load misses" }, |
27 | {.Name: "branch-prediction-misses" , .Description: "Branch prediction misses" }, |
28 | }; |
29 | |
30 | static_assert(sizeof(ValidationEventInfos) == |
31 | NumValidationEvents * sizeof(ValidationEventInfo), |
32 | "please update ValidationEventInfos" ); |
33 | |
34 | } // namespace |
35 | |
36 | const char *getValidationEventName(ValidationEvent VE) { |
37 | return ValidationEventInfos[VE].Name; |
38 | } |
39 | const char *getValidationEventDescription(ValidationEvent VE) { |
40 | return ValidationEventInfos[VE].Description; |
41 | } |
42 | |
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>(Args: "Invalid validation event string" , |
52 | Args: errc::invalid_argument); |
53 | } |
54 | |
55 | } // namespace exegesis |
56 | } // namespace llvm |
57 | |