From c7dc4734d23f45f576ba5af2aae5be9dfa2d3643 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Milo=C5=A1=20Stojanovi=C4=87?= Date: Tue, 31 Dec 2019 14:14:41 +0100 Subject: [PATCH] [llvm-exegesis] Check counters before running Check if the appropriate counters for the specified mode are defined on the target. This is checked before any other work is done. Differential Revision: https://reviews.llvm.org/D71927 --- llvm/tools/llvm-exegesis/lib/Latency.cpp | 2 -- llvm/tools/llvm-exegesis/lib/Target.cpp | 11 +++++++++++ llvm/tools/llvm-exegesis/llvm-exegesis.cpp | 13 +++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/Latency.cpp b/llvm/tools/llvm-exegesis/lib/Latency.cpp index 7030658..9c1c087 100644 --- a/llvm/tools/llvm-exegesis/lib/Latency.cpp +++ b/llvm/tools/llvm-exegesis/lib/Latency.cpp @@ -186,8 +186,6 @@ Expected> LatencyBenchmarkRunner::runMeasurements( constexpr const int NumMeasurements = 30; int64_t MinValue = std::numeric_limits::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) diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp index 57de701..2974195 100644 --- a/llvm/tools/llvm-exegesis/lib/Target.cpp +++ b/llvm/tools/llvm-exegesis/lib/Target.cpp @@ -54,13 +54,24 @@ std::unique_ptr ExegesisTarget::createSnippetGenerator( std::unique_ptr 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; diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp index a02d999..c4574d3 100644 --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -242,6 +242,13 @@ void benchmarkMain() { InitializeNativeExegesisTarget(); const LLVMState State(CpuName); + + const std::unique_ptr 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 @@ void benchmarkMain() { Configurations = ExitOnErr(readSnippets(State, SnippetsFile)); } - const std::unique_ptr 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"); -- 2.7.4