summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2018-04-04 11:37:06 +0000
committerClement Courbet <courbet@google.com>2018-04-04 11:37:06 +0000
commitac74acdefed9af2751d323bacef7ac47982957e8 (patch)
tree86fa1d51e6ad1bcf64c29d899c085e49f88ccf39 /llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
parentd152d55ab25be21ec8e5a162fce74f3bf7f8ed5c (diff)
downloadbcm5719-llvm-ac74acdefed9af2751d323bacef7ac47982957e8.tar.gz
bcm5719-llvm-ac74acdefed9af2751d323bacef7ac47982957e8.zip
Re-land r329156 "Add llvm-exegesis tool."
Fixed to depend on and initialize the native target instead of X86. llvm-svn: 329169
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp')
-rw-r--r--llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
new file mode 100644
index 00000000000..bdce72c1c11
--- /dev/null
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -0,0 +1,79 @@
+//===-- BenchmarkRunner.cpp -------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "BenchmarkRunner.h"
+#include "InMemoryAssembler.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include <string>
+
+namespace exegesis {
+
+BenchmarkRunner::InstructionFilter::~InstructionFilter() = default;
+
+BenchmarkRunner::~BenchmarkRunner() = default;
+
+InstructionBenchmark
+BenchmarkRunner::run(const LLVMState &State, const unsigned Opcode,
+ unsigned NumRepetitions,
+ const InstructionFilter &Filter) const {
+ InstructionBenchmark InstrBenchmark;
+
+ InstrBenchmark.AsmTmpl.Name =
+ llvm::Twine(getDisplayName())
+ .concat(" ")
+ .concat(State.getInstrInfo().getName(Opcode))
+ .str();
+ InstrBenchmark.CpuName = State.getCpuName();
+ InstrBenchmark.LLVMTriple = State.getTriple();
+ InstrBenchmark.NumRepetitions = NumRepetitions;
+
+ // Ignore instructions that we cannot run.
+ if (State.getInstrInfo().get(Opcode).isPseudo()) {
+ InstrBenchmark.Error = "Unsupported opcode: isPseudo";
+ return InstrBenchmark;
+ }
+ if (llvm::Error E = Filter.shouldRun(State, Opcode)) {
+ InstrBenchmark.Error = llvm::toString(std::move(E));
+ return InstrBenchmark;
+ }
+
+ JitFunctionContext Context(State.createTargetMachine());
+ auto ExpectedInstructions =
+ createCode(State, Opcode, NumRepetitions, Context);
+ if (llvm::Error E = ExpectedInstructions.takeError()) {
+ InstrBenchmark.Error = llvm::toString(std::move(E));
+ return InstrBenchmark;
+ }
+
+ const std::vector<llvm::MCInst> Instructions = *ExpectedInstructions;
+ const JitFunction Function(std::move(Context), Instructions);
+ const llvm::StringRef CodeBytes = Function.getFunctionBytes();
+
+ std::string AsmExcerpt;
+ constexpr const int ExcerptSize = 100;
+ constexpr const int ExcerptTailSize = 10;
+ if (CodeBytes.size() <= ExcerptSize) {
+ AsmExcerpt = llvm::toHex(CodeBytes);
+ } else {
+ AsmExcerpt =
+ llvm::toHex(CodeBytes.take_front(ExcerptSize - ExcerptTailSize + 3));
+ AsmExcerpt += "...";
+ AsmExcerpt += llvm::toHex(CodeBytes.take_back(ExcerptTailSize));
+ }
+ llvm::outs() << "# Asm excerpt: " << AsmExcerpt << "\n";
+ llvm::outs().flush(); // In case we crash.
+
+ InstrBenchmark.Measurements =
+ runMeasurements(State, Function, NumRepetitions);
+ return InstrBenchmark;
+}
+
+} // namespace exegesis
OpenPOWER on IntegriCloud