[PATCH] D71927: [llvm-exegesis] Check counters before running

Miloš Stojanović via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 31 05:22:54 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7dc4734d23f: [llvm-exegesis] Check counters before running (authored by mstojanovic).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71927/new/

https://reviews.llvm.org/D71927

Files:
  llvm/tools/llvm-exegesis/lib/Latency.cpp
  llvm/tools/llvm-exegesis/lib/Target.cpp
  llvm/tools/llvm-exegesis/llvm-exegesis.cpp


Index: llvm/tools/llvm-exegesis/llvm-exegesis.cpp
===================================================================
--- llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -242,6 +242,13 @@
   InitializeNativeExegesisTarget();
 
   const LLVMState State(CpuName);
+
+  const std::unique_ptr<BenchmarkRunner> Runner =
+      State.getExegesisTarget().createBenchmarkRunner(BenchmarkMode, State);
+  if (!Runner) {
+    report_fatal_error("cannot create benchmark runner");
+  }
+
   const auto Opcodes = getOpcodesOrDie(State.getInstrInfo());
 
   const auto Repetitor = SnippetRepetitor::Create(RepetitionMode, State);
@@ -272,12 +279,6 @@
     Configurations = ExitOnErr(readSnippets(State, SnippetsFile));
   }
 
-  const std::unique_ptr<BenchmarkRunner> Runner =
-      State.getExegesisTarget().createBenchmarkRunner(BenchmarkMode, State);
-  if (!Runner) {
-    report_fatal_error("cannot create benchmark runner");
-  }
-
   if (NumRepetitions == 0)
     report_fatal_error("--num-repetitions must be greater than zero");
 
Index: llvm/tools/llvm-exegesis/lib/Target.cpp
===================================================================
--- llvm/tools/llvm-exegesis/lib/Target.cpp
+++ llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -54,13 +54,24 @@
 std::unique_ptr<BenchmarkRunner>
 ExegesisTarget::createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
                                       const LLVMState &State) const {
+  PfmCountersInfo PfmCounters = State.getPfmCounters();
   switch (Mode) {
   case InstructionBenchmark::Unknown:
     return nullptr;
   case InstructionBenchmark::Latency:
   case InstructionBenchmark::InverseThroughput:
+    if (!PfmCounters.CycleCounter) {
+      const char *ModeName = Mode == InstructionBenchmark::Latency
+                                 ? "latency"
+                                 : "inverse_throughput";
+      report_fatal_error(Twine("can't run '").concat(ModeName).concat("' mode, "
+                               "sched model does not define a cycle counter."));
+    }
     return createLatencyBenchmarkRunner(State, Mode);
   case InstructionBenchmark::Uops:
+    if (!PfmCounters.UopsCounter && !PfmCounters.IssueCounters)
+      report_fatal_error("can't run 'uops' mode, sched model does not define "
+                         "uops or issue counters.");
     return createUopsBenchmarkRunner(State);
   }
   return nullptr;
Index: llvm/tools/llvm-exegesis/lib/Latency.cpp
===================================================================
--- llvm/tools/llvm-exegesis/lib/Latency.cpp
+++ llvm/tools/llvm-exegesis/lib/Latency.cpp
@@ -186,8 +186,6 @@
   constexpr const int NumMeasurements = 30;
   int64_t MinValue = std::numeric_limits<int64_t>::max();
   const char *CounterName = State.getPfmCounters().CycleCounter;
-  if (!CounterName)
-    report_fatal_error("sched model does not define a cycle counter");
   for (size_t I = 0; I < NumMeasurements; ++I) {
     auto ExpectedCounterValue = Executor.runAndMeasure(CounterName);
     if (!ExpectedCounterValue)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71927.235708.patch
Type: text/x-patch
Size: 3080 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191231/3891a8e4/attachment.bin>


More information about the llvm-commits mailing list