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 --- 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.h b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h @@ -64,7 +64,8 @@ const SnippetRepetitor &Repetitor) const; Expected runConfiguration(RunnableConfiguration &&RC, - bool DumpObjectToDisk) const; + bool DumpObjectToDisk, + StringRef DumpFileName) const; // Scratch space to run instructions that touch memory. struct ScratchSpace { @@ -109,7 +110,8 @@ unsigned MinInstructions, unsigned LoopBodySize) const; - Expected writeObjectFile(StringRef Buffer) const; + Expected writeObjectFile(StringRef Buffer, + StringRef FileName) const; const std::unique_ptr Scratch; }; diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -198,13 +198,15 @@ Expected BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC, - bool DumpObjectToDisk) const { + bool DumpObjectToDisk, + StringRef DumpFileName) const { Benchmark &InstrBenchmark = RC.InstrBenchmark; object::OwningBinary &ObjectFile = RC.ObjectFile; if (DumpObjectToDisk && BenchmarkPhaseSelector > BenchmarkPhaseSelectorE::PrepareAndAssembleSnippet) { - auto ObjectFilePath = writeObjectFile(ObjectFile.getBinary()->getData()); + auto ObjectFilePath = + writeObjectFile(ObjectFile.getBinary()->getData(), DumpFileName); if (Error E = ObjectFilePath.takeError()) { InstrBenchmark.Error = toString(std::move(E)); return std::move(InstrBenchmark); @@ -241,11 +243,16 @@ return std::move(InstrBenchmark); } -Expected BenchmarkRunner::writeObjectFile(StringRef Buffer) const { +Expected +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/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -236,11 +236,11 @@ 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 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 + 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: "); @@ -375,8 +375,9 @@ Repetitors) { auto RC = ExitOnErr(Runner.getRunnableConfiguration( Conf, NumRepetitions, LoopBodySize, *Repetitor)); - AllResults.emplace_back( - ExitOnErr(Runner.runConfiguration(std::move(RC), DumpObjectToDisk))); + AllResults.emplace_back(ExitOnErr(Runner.runConfiguration( + std::move(RC), DumpObjectToDisk.getNumOccurrences(), + DumpObjectToDisk))); } Benchmark &Result = AllResults.front();