summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2018-09-13 07:40:53 +0000
committerClement Courbet <courbet@google.com>2018-09-13 07:40:53 +0000
commitd939f6d01396201d1b8fb5dba652e9528276e79e (patch)
treea6a1ce6223ee509273ef8b3f6d7c9a080ee6034a /llvm/tools/llvm-exegesis/llvm-exegesis.cpp
parent58c3dee3b3cdf103680d80b61167dda9612d3e0d (diff)
downloadbcm5719-llvm-d939f6d01396201d1b8fb5dba652e9528276e79e.tar.gz
bcm5719-llvm-d939f6d01396201d1b8fb5dba652e9528276e79e.zip
[llvm-exegesis][NFC] Split BenchmarkRunner class
Summary: The snippet-generation part goes to the SnippetGenerator class. This will allow benchmarking arbitrary code (see PR38437). Reviewers: gchatelet Subscribers: mgorny, tschuett, llvm-commits Differential Revision: https://reviews.llvm.org/D51979 llvm-svn: 342117
Diffstat (limited to 'llvm/tools/llvm-exegesis/llvm-exegesis.cpp')
-rw-r--r--llvm/tools/llvm-exegesis/llvm-exegesis.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index 6b626b0eaa3..1465d142379 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -119,6 +119,30 @@ getBenchmarkResultContext(const LLVMState &State) {
return Ctx;
}
+// Generates code snippets for opcode `Opcode`.
+llvm::Expected<std::vector<BenchmarkCode>>
+generateSnippets(const LLVMState &State, unsigned Opcode,
+ unsigned NumRepetitions) {
+ const std::unique_ptr<SnippetGenerator> Generator =
+ State.getExegesisTarget().createSnippetGenerator(BenchmarkMode, State);
+ if (!Generator) {
+ llvm::report_fatal_error("cannot create snippet generator");
+ }
+
+ const llvm::MCInstrDesc &InstrDesc = State.getInstrInfo().get(Opcode);
+ // Ignore instructions that we cannot run.
+ if (InstrDesc.isPseudo())
+ return llvm::make_error<BenchmarkFailure>("Unsupported opcode: isPseudo");
+ if (InstrDesc.isBranch() || InstrDesc.isIndirectBranch())
+ return llvm::make_error<BenchmarkFailure>(
+ "Unsupported opcode: isBranch/isIndirectBranch");
+ if (InstrDesc.isCall() || InstrDesc.isReturn())
+ return llvm::make_error<BenchmarkFailure>(
+ "Unsupported opcode: isCall/isReturn");
+
+ return Generator->generateConfigurations(Opcode);
+}
+
void benchmarkMain() {
if (exegesis::pfm::pfmInitialize())
llvm::report_fatal_error("cannot initialize libpfm");
@@ -140,6 +164,10 @@ void benchmarkMain() {
return;
}
+ // FIXME: Allow arbitrary code.
+ const std::vector<BenchmarkCode> Configurations =
+ ExitOnErr(generateSnippets(State, Opcode, NumRepetitions));
+
const std::unique_ptr<BenchmarkRunner> Runner =
State.getExegesisTarget().createBenchmarkRunner(BenchmarkMode, State);
if (!Runner) {
@@ -154,11 +182,12 @@ void benchmarkMain() {
BenchmarkFile = "-";
const BenchmarkResultContext Context = getBenchmarkResultContext(State);
- std::vector<InstructionBenchmark> Results =
- ExitOnErr(Runner->run(Opcode, NumRepetitions));
- for (InstructionBenchmark &Result : Results)
- ExitOnErr(Result.writeYaml(Context, BenchmarkFile));
+ for (const BenchmarkCode &Conf : Configurations) {
+ InstructionBenchmark Result =
+ Runner->runConfiguration(Conf, NumRepetitions);
+ ExitOnErr(Result.writeYaml(Context, BenchmarkFile));
+ }
exegesis::pfm::pfmTerminate();
}
OpenPOWER on IntegriCloud