[MC][TableGen] Add optional libpfm counter names for ProcResUnits.
Summary:
Subtargets can define the libpfm counter names that can be used to
measure cycles and uops issued on ProcResUnits.
This allows making llvm-exegesis available on more targets.
Fixes PR36984.
Reviewers: gchatelet, RKSimon, andreadb, craig.topper
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D45360
llvm-svn: 329675
diff --git a/llvm/tools/llvm-exegesis/lib/Latency.cpp b/llvm/tools/llvm-exegesis/lib/Latency.cpp
index 770b928..4a2632c 100644
--- a/llvm/tools/llvm-exegesis/lib/Latency.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Latency.cpp
@@ -76,10 +76,15 @@
// measure several times and take the minimum value.
constexpr const int NumMeasurements = 30;
int64_t MinLatency = std::numeric_limits<int64_t>::max();
- // FIXME: Read the perf event from the MCSchedModel (see PR36984).
- const pfm::PerfEvent CyclesPerfEvent("UNHALTED_CORE_CYCLES");
+ const char *CounterName = State.getSubtargetInfo()
+ .getSchedModel()
+ .getExtraProcessorInfo()
+ .PfmCounters.CycleCounter;
+ if (!CounterName)
+ llvm::report_fatal_error("sched model does not define a cycle counter");
+ const pfm::PerfEvent CyclesPerfEvent(CounterName);
if (!CyclesPerfEvent.valid())
- llvm::report_fatal_error("invalid perf event 'UNHALTED_CORE_CYCLES'");
+ llvm::report_fatal_error("invalid perf event");
for (size_t I = 0; I < NumMeasurements; ++I) {
pfm::Counter Counter(CyclesPerfEvent);
Counter.start();