diff options
| author | Clement Courbet <courbet@google.com> | 2018-10-17 15:04:15 +0000 |
|---|---|---|
| committer | Clement Courbet <courbet@google.com> | 2018-10-17 15:04:15 +0000 |
| commit | f973c2df9d21e82b169c88138bf9fafe75fa8e7d (patch) | |
| tree | 8f58b70e56c30eb12dbe0002e813f29588658857 /llvm/tools/llvm-exegesis/lib/Uops.cpp | |
| parent | c0daf2a9780c0c2e9a0ea56125a746f60a8d1775 (diff) | |
| download | bcm5719-llvm-f973c2df9d21e82b169c88138bf9fafe75fa8e7d.tar.gz bcm5719-llvm-f973c2df9d21e82b169c88138bf9fafe75fa8e7d.zip | |
[llvm-exegesis] Allow measuring several instructions in a single run.
Summary:
We try to recover gracefully on instructions that would crash the
program.
This includes some refactoring of runMeasurement() implementations.
Reviewers: gchatelet
Subscribers: tschuett, llvm-commits
Differential Revision: https://reviews.llvm.org/D53371
llvm-svn: 344695
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/Uops.cpp')
| -rw-r--r-- | llvm/tools/llvm-exegesis/lib/Uops.cpp | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/Uops.cpp b/llvm/tools/llvm-exegesis/lib/Uops.cpp index d8065adbdb2..50be707feb2 100644 --- a/llvm/tools/llvm-exegesis/lib/Uops.cpp +++ b/llvm/tools/llvm-exegesis/lib/Uops.cpp @@ -12,7 +12,6 @@ #include "Assembler.h" #include "BenchmarkRunner.h" #include "MCInstrDescView.h" -#include "PerfHelper.h" #include "Target.h" // FIXME: Load constants into registers (e.g. with fld1) to not break @@ -221,33 +220,10 @@ UopsSnippetGenerator::generateCodeTemplates(const Instruction &Instr) const { return getSingleton(std::move(CT)); } -std::vector<BenchmarkMeasure> -UopsBenchmarkRunner::runMeasurements(const ExecutableFunction &Function, - ScratchSpace &Scratch) const { +llvm::Expected<std::vector<BenchmarkMeasure>> +UopsBenchmarkRunner::runMeasurements(const FunctionExecutor &Executor) const { const auto &SchedModel = State.getSubtargetInfo().getSchedModel(); - const auto RunMeasurement = [&Function, - &Scratch](const char *const Counters) { - // We sum counts when there are several counters for a single ProcRes - // (e.g. P23 on SandyBridge). - int64_t CounterValue = 0; - llvm::SmallVector<llvm::StringRef, 2> CounterNames; - llvm::StringRef(Counters).split(CounterNames, ','); - for (const auto &CounterName : CounterNames) { - pfm::PerfEvent UopPerfEvent(CounterName); - if (!UopPerfEvent.valid()) - llvm::report_fatal_error( - llvm::Twine("invalid perf event ").concat(Counters)); - pfm::Counter Counter(UopPerfEvent); - Scratch.clear(); - Counter.start(); - Function(Scratch.ptr()); - Counter.stop(); - CounterValue += Counter.read(); - } - return CounterValue; - }; - std::vector<BenchmarkMeasure> Result; const auto &PfmCounters = SchedModel.getExtraProcessorInfo().PfmCounters; // Uops per port. @@ -256,16 +232,21 @@ UopsBenchmarkRunner::runMeasurements(const ExecutableFunction &Function, const char *const Counters = PfmCounters.IssueCounters[ProcResIdx]; if (!Counters) continue; - const double CounterValue = RunMeasurement(Counters); + auto ExpectedCounterValue = Executor.runAndMeasure(Counters); + if (!ExpectedCounterValue) + return ExpectedCounterValue.takeError(); Result.push_back(BenchmarkMeasure::Create( - SchedModel.getProcResource(ProcResIdx)->Name, CounterValue)); + SchedModel.getProcResource(ProcResIdx)->Name, *ExpectedCounterValue)); } // NumMicroOps. if (const char *const UopsCounter = PfmCounters.UopsCounter) { - const double CounterValue = RunMeasurement(UopsCounter); - Result.push_back(BenchmarkMeasure::Create("NumMicroOps", CounterValue)); + auto ExpectedCounterValue = Executor.runAndMeasure(UopsCounter); + if (!ExpectedCounterValue) + return ExpectedCounterValue.takeError(); + Result.push_back( + BenchmarkMeasure::Create("NumMicroOps", *ExpectedCounterValue)); } - return Result; + return std::move(Result); } constexpr const size_t UopsSnippetGenerator::kMinNumDifferentAddresses; |

