Skip to content

Commit 8e0ee5a

Browse files
committed
[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
1 parent 752bd78 commit 8e0ee5a

File tree

4 files changed

+42
-30
lines changed

4 files changed

+42
-30
lines changed
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
# 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
2-
# 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
3-
# 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
4-
# 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
1+
# 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
2+
# 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
3+
# 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
4+
# 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
55
# 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
66
# 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
77

8-
# 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
9-
# 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
10-
# 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
11-
# 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
8+
# 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
9+
# 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
1210
# 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
1311
# 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
1412

15-
# 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
16-
# 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
17-
# 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
18-
# 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
13+
# 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
14+
# 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
1915
# 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
2016
# 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
2117

18+
# 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
19+
# RUN: llvm-objdump -d %t.mydmpfile.o | FileCheck %s --check-prefix=ASM
2220
CHECK-ON: Check generated assembly with
2321
CHECK-OFF-NOT: Check generated assembly with
22+
DUMP-FILE-NAME: Check generated assembly with: {{.*}}objdump -d {{.*}}mydmpfile
23+
ASM: addps
24+
ASM: retq

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,16 @@ BenchmarkRunner::getRunnableConfiguration(
193193
return std::move(RC);
194194
}
195195

196-
Expected<Benchmark>
197-
BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC,
198-
bool DumpObjectToDisk) const {
196+
Expected<Benchmark> BenchmarkRunner::runConfiguration(
197+
RunnableConfiguration &&RC,
198+
const std::optional<StringRef> &DumpFile) const {
199199
Benchmark &InstrBenchmark = RC.InstrBenchmark;
200200
object::OwningBinary<object::ObjectFile> &ObjectFile = RC.ObjectFile;
201201

202-
if (DumpObjectToDisk &&
203-
BenchmarkPhaseSelector > BenchmarkPhaseSelectorE::PrepareAndAssembleSnippet) {
204-
auto ObjectFilePath = writeObjectFile(ObjectFile.getBinary()->getData());
202+
if (DumpFile && BenchmarkPhaseSelector >
203+
BenchmarkPhaseSelectorE::PrepareAndAssembleSnippet) {
204+
auto ObjectFilePath =
205+
writeObjectFile(ObjectFile.getBinary()->getData(), *DumpFile);
205206
if (Error E = ObjectFilePath.takeError()) {
206207
InstrBenchmark.Error = toString(std::move(E));
207208
return std::move(InstrBenchmark);
@@ -238,11 +239,16 @@ BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC,
238239
return std::move(InstrBenchmark);
239240
}
240241

241-
Expected<std::string> BenchmarkRunner::writeObjectFile(StringRef Buffer) const {
242+
Expected<std::string>
243+
BenchmarkRunner::writeObjectFile(StringRef Buffer, StringRef FileName) const {
242244
int ResultFD = 0;
243-
SmallString<256> ResultPath;
245+
SmallString<256> ResultPath = FileName;
244246
if (Error E = errorCodeToError(
245-
sys::fs::createTemporaryFile("snippet", "o", ResultFD, ResultPath)))
247+
FileName.empty() ? sys::fs::createTemporaryFile("snippet", "o",
248+
ResultFD, ResultPath)
249+
: sys::fs::openFileForReadWrite(
250+
FileName, ResultFD, sys::fs::CD_CreateAlways,
251+
sys::fs::OF_None)))
246252
return std::move(E);
247253
raw_fd_ostream OFS(ResultFD, true /*ShouldClose*/);
248254
OFS.write(Buffer.data(), Buffer.size());

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class BenchmarkRunner {
6363
unsigned NumRepetitions, unsigned LoopUnrollFactor,
6464
const SnippetRepetitor &Repetitor) const;
6565

66-
Expected<Benchmark> runConfiguration(RunnableConfiguration &&RC,
67-
bool DumpObjectToDisk) const;
66+
Expected<Benchmark>
67+
runConfiguration(RunnableConfiguration &&RC,
68+
const std::optional<StringRef> &DumpFile) const;
6869

6970
// Scratch space to run instructions that touch memory.
7071
struct ScratchSpace {
@@ -114,7 +115,8 @@ class BenchmarkRunner {
114115
unsigned MinInstructions,
115116
unsigned LoopBodySize) const;
116117

117-
Expected<std::string> writeObjectFile(StringRef Buffer) const;
118+
Expected<std::string> writeObjectFile(StringRef Buffer,
119+
StringRef FileName) const;
118120

119121
const std::unique_ptr<ScratchSpace> Scratch;
120122
};

llvm/tools/llvm-exegesis/llvm-exegesis.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ static cl::opt<std::string>
242242
cl::desc("Target a specific cpu type (-mcpu=help for details)"),
243243
cl::value_desc("cpu-name"), cl::cat(Options), cl::init("native"));
244244

245-
static cl::opt<bool> DumpObjectToDisk(
246-
"dump-object-to-disk",
247-
cl::desc("dumps the generated benchmark object to disk "
248-
"and prints a message to access it (default = false)"),
249-
cl::cat(BenchmarkOptions), cl::init(false));
245+
static cl::opt<std::string>
246+
DumpObjectToDisk("dump-object-to-disk",
247+
cl::desc("dumps the generated benchmark object to disk "
248+
"and prints a message to access it"),
249+
cl::ValueOptional, cl::cat(BenchmarkOptions));
250250

251251
static ExitOnError ExitOnErr("llvm-exegesis error: ");
252252

@@ -381,8 +381,11 @@ static void runBenchmarkConfigurations(
381381
Repetitors) {
382382
auto RC = ExitOnErr(Runner.getRunnableConfiguration(
383383
Conf, NumRepetitions, LoopBodySize, *Repetitor));
384+
std::optional<StringRef> DumpFile;
385+
if (DumpObjectToDisk.getNumOccurrences())
386+
DumpFile = DumpObjectToDisk;
384387
AllResults.emplace_back(
385-
ExitOnErr(Runner.runConfiguration(std::move(RC), DumpObjectToDisk)));
388+
ExitOnErr(Runner.runConfiguration(std::move(RC), DumpFile)));
386389
}
387390
Benchmark &Result = AllResults.front();
388391

0 commit comments

Comments
 (0)