From: Guillaume Chatelet Date: Fri, 5 Apr 2019 15:18:59 +0000 (+0000) Subject: Add an option do not dump the generated object on disk X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99e08856aef1012c1b1662f5527d6c74bbbf7720;p=llvm Add an option do not dump the generated object on disk Reviewers: courbet Subscribers: llvm-commits, bdb Tags: #llvm Differential Revision: https://reviews.llvm.org/D60317 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357769 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/CommandGuide/llvm-exegesis.rst b/docs/CommandGuide/llvm-exegesis.rst index 29f2cec2688..cbb900914cf 100644 --- a/docs/CommandGuide/llvm-exegesis.rst +++ b/docs/CommandGuide/llvm-exegesis.rst @@ -247,10 +247,16 @@ OPTIONS If set, ignore instructions that do not have a sched class (class idx = 0). - .. option:: -mcpu= +.. option:: -mcpu= - If set, measure the cpu characteristics using the counters for this CPU. This - is useful when creating new sched models (the host CPU is unknown to LLVM). + If set, measure the cpu characteristics using the counters for this CPU. This + is useful when creating new sched models (the host CPU is unknown to LLVM). + +.. option:: --dump-object-to-disk=true + + By default, llvm-exegesis will dump the generated code to a temporary file to + enable code inspection. You may disable it to speed up the execution and save + disk space. EXIT STATUS ----------- diff --git a/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 32b68a5c23d..18ce4ccad28 100644 --- a/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -66,8 +66,9 @@ private: CounterName = CounterName.trim(); pfm::PerfEvent PerfEvent(CounterName); if (!PerfEvent.valid()) - llvm::report_fatal_error( - llvm::Twine("invalid perf event '").concat(CounterName).concat("'")); + llvm::report_fatal_error(llvm::Twine("invalid perf event '") + .concat(CounterName) + .concat("'")); pfm::Counter Counter(PerfEvent); Scratch->clear(); { @@ -96,7 +97,8 @@ private: InstructionBenchmark BenchmarkRunner::runConfiguration(const BenchmarkCode &BC, - unsigned NumRepetitions) const { + unsigned NumRepetitions, + bool DumpObjectToDisk) const { InstructionBenchmark InstrBenchmark; InstrBenchmark.Mode = Mode; InstrBenchmark.CpuName = State.getTargetMachine().getTargetCPU(); @@ -129,15 +131,27 @@ BenchmarkRunner::runConfiguration(const BenchmarkCode &BC, // Assemble NumRepetitions instructions repetitions of the snippet for // measurements. - auto ObjectFilePath = writeObjectFile( - BC, GenerateInstructions(BC, InstrBenchmark.NumRepetitions)); - if (llvm::Error E = ObjectFilePath.takeError()) { - InstrBenchmark.Error = llvm::toString(std::move(E)); - return InstrBenchmark; + const auto Code = GenerateInstructions(BC, InstrBenchmark.NumRepetitions); + + llvm::object::OwningBinary ObjectFile; + if (DumpObjectToDisk) { + auto ObjectFilePath = writeObjectFile(BC, Code); + if (llvm::Error E = ObjectFilePath.takeError()) { + InstrBenchmark.Error = llvm::toString(std::move(E)); + return InstrBenchmark; + } + llvm::outs() << "Check generated assembly with: /usr/bin/objdump -d " + << *ObjectFilePath << "\n"; + ObjectFile = getObjectFromFile(*ObjectFilePath); + } else { + llvm::SmallString<0> Buffer; + llvm::raw_svector_ostream OS(Buffer); + assembleToStream(State.getExegesisTarget(), State.createTargetMachine(), + BC.LiveIns, BC.RegisterInitialValues, Code, OS); + ObjectFile = getObjectFromBuffer(OS.str()); } - llvm::outs() << "Check generated assembly with: /usr/bin/objdump -d " - << *ObjectFilePath << "\n"; - const FunctionExecutorImpl Executor(State, getObjectFromFile(*ObjectFilePath), + + const FunctionExecutorImpl Executor(State, std::move(ObjectFile), Scratch.get()); auto Measurements = runMeasurements(Executor); if (llvm::Error E = Measurements.takeError()) { diff --git a/tools/llvm-exegesis/lib/BenchmarkRunner.h b/tools/llvm-exegesis/lib/BenchmarkRunner.h index 4387bc8456e..395c0f8e32d 100644 --- a/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ b/tools/llvm-exegesis/lib/BenchmarkRunner.h @@ -45,7 +45,8 @@ public: virtual ~BenchmarkRunner(); InstructionBenchmark runConfiguration(const BenchmarkCode &Configuration, - unsigned NumRepetitions) const; + unsigned NumRepetitions, + bool DumpObjectToDisk) const; // Scratch space to run instructions that touch memory. struct ScratchSpace { @@ -85,7 +86,6 @@ private: writeObjectFile(const BenchmarkCode &Configuration, llvm::ArrayRef Code) const; - const std::unique_ptr Scratch; }; diff --git a/tools/llvm-exegesis/llvm-exegesis.cpp b/tools/llvm-exegesis/llvm-exegesis.cpp index fb2f2ff0eef..7339baf8f8e 100644 --- a/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/tools/llvm-exegesis/llvm-exegesis.cpp @@ -137,6 +137,12 @@ static cl::opt CpuName( cl::desc("cpu name to use for pfm counters, leave empty to autodetect"), cl::cat(Options), cl::init("")); +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::cat(BenchmarkOptions), cl::init(true)); + static ExitOnError ExitOnErr; #ifdef LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET @@ -406,7 +412,7 @@ void benchmarkMain() { for (const BenchmarkCode &Conf : Configurations) { InstructionBenchmark Result = - Runner->runConfiguration(Conf, NumRepetitions); + Runner->runConfiguration(Conf, NumRepetitions, DumpObjectToDisk); ExitOnErr(Result.writeYaml(State, BenchmarkFile)); } exegesis::pfm::pfmTerminate();