[llvm] r357769 - Add an option do not dump the generated object on disk
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 5 08:18:59 PDT 2019
Author: gchatelet
Date: Fri Apr 5 08:18:59 2019
New Revision: 357769
URL: http://llvm.org/viewvc/llvm-project?rev=357769&view=rev
Log:
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
Modified:
llvm/trunk/docs/CommandGuide/llvm-exegesis.rst
llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h
llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp
Modified: llvm/trunk/docs/CommandGuide/llvm-exegesis.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-exegesis.rst?rev=357769&r1=357768&r2=357769&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-exegesis.rst (original)
+++ llvm/trunk/docs/CommandGuide/llvm-exegesis.rst Fri Apr 5 08:18:59 2019
@@ -247,10 +247,16 @@ OPTIONS
If set, ignore instructions that do not have a sched class (class idx = 0).
- .. option:: -mcpu=<cpu name>
+.. option:: -mcpu=<cpu name>
- 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
-----------
Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp?rev=357769&r1=357768&r2=357769&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp Fri Apr 5 08:18:59 2019
@@ -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
// 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<llvm::object::ObjectFile> 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()) {
Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h?rev=357769&r1=357768&r2=357769&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h Fri Apr 5 08:18:59 2019
@@ -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<llvm::MCInst> Code) const;
-
const std::unique_ptr<ScratchSpace> Scratch;
};
Modified: llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp?rev=357769&r1=357768&r2=357769&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp Fri Apr 5 08:18:59 2019
@@ -137,6 +137,12 @@ static cl::opt<std::string> CpuName(
cl::desc("cpu name to use for pfm counters, leave empty to autodetect"),
cl::cat(Options), cl::init(""));
+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"),
+ 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();
More information about the llvm-commits
mailing list