[llvm] 8e0ee5a - [llvm-exegesis] Allow setting dump file name
Pavel Kosov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 19 00:59:31 PDT 2023
Author: Pavel Kosov
Date: 2023-04-19T10:59:07+03:00
New Revision: 8e0ee5ab9f34cc98e4f4b62bbceed45a71281e45
URL: https://github.com/llvm/llvm-project/commit/8e0ee5ab9f34cc98e4f4b62bbceed45a71281e45
DIFF: https://github.com/llvm/llvm-project/commit/8e0ee5ab9f34cc98e4f4b62bbceed45a71281e45.diff
LOG: [llvm-exegesis] Allow setting dump file name
This will be used for writing test cases.
~~
Huawei RRI, OS Lab
Reviewed By: courbet
Differential Revision: https://reviews.llvm.org/D147700
Added:
Modified:
llvm/test/tools/llvm-exegesis/X86/latency/dump-object-to-disk.s
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
llvm/tools/llvm-exegesis/llvm-exegesis.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-exegesis/X86/latency/dump-object-to-disk.s b/llvm/test/tools/llvm-exegesis/X86/latency/dump-object-to-disk.s
index 5f8bab4ac6229..c65751a1745af 100644
--- a/llvm/test/tools/llvm-exegesis/X86/latency/dump-object-to-disk.s
+++ b/llvm/test/tools/llvm-exegesis/X86/latency/dump-object-to-disk.s
@@ -1,23 +1,24 @@
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=duplicate -dump-object-to-disk=1 2>&1 | FileCheck %s --check-prefix=CHECK-ON
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=loop -dump-object-to-disk=1 2>&1 | FileCheck %s --check-prefix=CHECK-ON
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=duplicate -dump-object-to-disk=0 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=loop -dump-object-to-disk=0 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=duplicate -dump-object-to-disk 2>&1 | FileCheck %s --check-prefix=CHECK-ON
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=loop -dump-object-to-disk 2>&1 | FileCheck %s --check-prefix=CHECK-ON
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=duplicate 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=loop 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=duplicate 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=loop 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-and-assemble-snippet -opcode-name=ADDPSrr -repetition-mode=duplicate -dump-object-to-disk=1 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-and-assemble-snippet -opcode-name=ADDPSrr -repetition-mode=loop -dump-object-to-disk=1 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-and-assemble-snippet -opcode-name=ADDPSrr -repetition-mode=duplicate -dump-object-to-disk=0 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-and-assemble-snippet -opcode-name=ADDPSrr -repetition-mode=loop -dump-object-to-disk=0 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-and-assemble-snippet -opcode-name=ADDPSrr -repetition-mode=duplicate 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-and-assemble-snippet -opcode-name=ADDPSrr -repetition-mode=loop 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-and-assemble-snippet -opcode-name=ADDPSrr -repetition-mode=duplicate 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-and-assemble-snippet -opcode-name=ADDPSrr -repetition-mode=loop 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-snippet -opcode-name=ADDPSrr -repetition-mode=duplicate -dump-object-to-disk=1 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-snippet -opcode-name=ADDPSrr -repetition-mode=loop -dump-object-to-disk=1 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-snippet -opcode-name=ADDPSrr -repetition-mode=duplicate -dump-object-to-disk=0 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
-# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-snippet -opcode-name=ADDPSrr -repetition-mode=loop -dump-object-to-disk=0 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-snippet -opcode-name=ADDPSrr -repetition-mode=duplicate 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-snippet -opcode-name=ADDPSrr -repetition-mode=loop 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-snippet -opcode-name=ADDPSrr -repetition-mode=duplicate 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=prepare-snippet -opcode-name=ADDPSrr -repetition-mode=loop 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
+# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADDPSrr -repetition-mode=duplicate -dump-object-to-disk=%t.mydmpfile.o 2>&1 | FileCheck %s --check-prefix=DUMP-FILE-NAME
+# RUN: llvm-objdump -d %t.mydmpfile.o | FileCheck %s --check-prefix=ASM
CHECK-ON: Check generated assembly with
CHECK-OFF-NOT: Check generated assembly with
+DUMP-FILE-NAME: Check generated assembly with: {{.*}}objdump -d {{.*}}mydmpfile
+ASM: addps
+ASM: retq
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index fd4ce6b287970..e1df2940a9b7e 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -193,15 +193,16 @@ BenchmarkRunner::getRunnableConfiguration(
return std::move(RC);
}
-Expected<Benchmark>
-BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC,
- bool DumpObjectToDisk) const {
+Expected<Benchmark> BenchmarkRunner::runConfiguration(
+ RunnableConfiguration &&RC,
+ const std::optional<StringRef> &DumpFile) const {
Benchmark &InstrBenchmark = RC.InstrBenchmark;
object::OwningBinary<object::ObjectFile> &ObjectFile = RC.ObjectFile;
- if (DumpObjectToDisk &&
- BenchmarkPhaseSelector > BenchmarkPhaseSelectorE::PrepareAndAssembleSnippet) {
- auto ObjectFilePath = writeObjectFile(ObjectFile.getBinary()->getData());
+ if (DumpFile && BenchmarkPhaseSelector >
+ BenchmarkPhaseSelectorE::PrepareAndAssembleSnippet) {
+ auto ObjectFilePath =
+ writeObjectFile(ObjectFile.getBinary()->getData(), *DumpFile);
if (Error E = ObjectFilePath.takeError()) {
InstrBenchmark.Error = toString(std::move(E));
return std::move(InstrBenchmark);
@@ -238,11 +239,16 @@ BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC,
return std::move(InstrBenchmark);
}
-Expected<std::string> BenchmarkRunner::writeObjectFile(StringRef Buffer) const {
+Expected<std::string>
+BenchmarkRunner::writeObjectFile(StringRef Buffer, StringRef FileName) const {
int ResultFD = 0;
- SmallString<256> ResultPath;
+ SmallString<256> ResultPath = FileName;
if (Error E = errorCodeToError(
- sys::fs::createTemporaryFile("snippet", "o", ResultFD, ResultPath)))
+ FileName.empty() ? sys::fs::createTemporaryFile("snippet", "o",
+ ResultFD, ResultPath)
+ : sys::fs::openFileForReadWrite(
+ FileName, ResultFD, sys::fs::CD_CreateAlways,
+ sys::fs::OF_None)))
return std::move(E);
raw_fd_ostream OFS(ResultFD, true /*ShouldClose*/);
OFS.write(Buffer.data(), Buffer.size());
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
index 730735a462908..eece929ae8c55 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
@@ -63,8 +63,9 @@ class BenchmarkRunner {
unsigned NumRepetitions, unsigned LoopUnrollFactor,
const SnippetRepetitor &Repetitor) const;
- Expected<Benchmark> runConfiguration(RunnableConfiguration &&RC,
- bool DumpObjectToDisk) const;
+ Expected<Benchmark>
+ runConfiguration(RunnableConfiguration &&RC,
+ const std::optional<StringRef> &DumpFile) const;
// Scratch space to run instructions that touch memory.
struct ScratchSpace {
@@ -114,7 +115,8 @@ class BenchmarkRunner {
unsigned MinInstructions,
unsigned LoopBodySize) const;
- Expected<std::string> writeObjectFile(StringRef Buffer) const;
+ Expected<std::string> writeObjectFile(StringRef Buffer,
+ StringRef FileName) const;
const std::unique_ptr<ScratchSpace> Scratch;
};
diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index ce028eb008929..0973f7bb721f1 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -242,11 +242,11 @@ static cl::opt<std::string>
cl::desc("Target a specific cpu type (-mcpu=help for details)"),
cl::value_desc("cpu-name"), cl::cat(Options), cl::init("native"));
-static cl::opt<bool> DumpObjectToDisk(
- "dump-object-to-disk",
- cl::desc("dumps the generated benchmark object to disk "
- "and prints a message to access it (default = false)"),
- cl::cat(BenchmarkOptions), cl::init(false));
+static cl::opt<std::string>
+ DumpObjectToDisk("dump-object-to-disk",
+ cl::desc("dumps the generated benchmark object to disk "
+ "and prints a message to access it"),
+ cl::ValueOptional, cl::cat(BenchmarkOptions));
static ExitOnError ExitOnErr("llvm-exegesis error: ");
@@ -381,8 +381,11 @@ static void runBenchmarkConfigurations(
Repetitors) {
auto RC = ExitOnErr(Runner.getRunnableConfiguration(
Conf, NumRepetitions, LoopBodySize, *Repetitor));
+ std::optional<StringRef> DumpFile;
+ if (DumpObjectToDisk.getNumOccurrences())
+ DumpFile = DumpObjectToDisk;
AllResults.emplace_back(
- ExitOnErr(Runner.runConfiguration(std::move(RC), DumpObjectToDisk)));
+ ExitOnErr(Runner.runConfiguration(std::move(RC), DumpFile)));
}
Benchmark &Result = AllResults.front();
More information about the llvm-commits
mailing list