2 #include "ValidationEvent.h"
3 #include "llvm/ADT/StringRef.h"
4 #include "llvm/Support/Errc.h"
5 #include "llvm/Support/Error.h"
12 struct ValidationEventInfo
{
13 const char *const Name
;
14 const char *const Description
;
17 // Information about validation events, indexed by `ValidationEvent` enum
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"},
30 static_assert(sizeof(ValidationEventInfos
) ==
31 NumValidationEvents
* sizeof(ValidationEventInfo
),
32 "please update ValidationEventInfos");
36 const char *getValidationEventName(ValidationEvent VE
) {
37 return ValidationEventInfos
[VE
].Name
;
39 const char *getValidationEventDescription(ValidationEvent VE
) {
40 return ValidationEventInfos
[VE
].Description
;
43 Expected
<ValidationEvent
> getValidationEventByName(StringRef Name
) {
45 for (const ValidationEventInfo
&Info
: ValidationEventInfos
) {
46 if (Name
== Info
.Name
)
47 return static_cast<ValidationEvent
>(VE
);
51 return make_error
<StringError
>("Invalid validation event string",
52 errc::invalid_argument
);
55 } // namespace exegesis