From 0db620aa30c9b45086add91a7202ca473bb50907 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sat, 17 Dec 2022 20:51:37 +0300 Subject: [PATCH] [NFC][llvm-exegesis] `BenchmarkRunner::runConfiguration()`: reformat --- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 128 +++++++++++------------ 1 file changed, 63 insertions(+), 65 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index f8da149..2b4e6b7 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -150,80 +150,78 @@ Expected BenchmarkRunner::runConfiguration( InstrBenchmark.Key = BC.Key; + // Assemble at least kMinInstructionsForSnippet instructions by repeating + // the snippet for debug/analysis. This is so that the user clearly + // understands that the inside instructions are repeated. + const int MinInstructionsForSnippet = 4 * Instructions.size(); + const int LoopBodySizeForSnippet = 2 * Instructions.size(); { - // Assemble at least kMinInstructionsForSnippet instructions by repeating - // the snippet for debug/analysis. This is so that the user clearly - // understands that the inside instructions are repeated. - const int MinInstructionsForSnippet = 4 * Instructions.size(); - const int LoopBodySizeForSnippet = 2 * Instructions.size(); - { - SmallString<0> Buffer; - raw_svector_ostream OS(Buffer); - if (Error E = assembleToStream( - State.getExegesisTarget(), State.createTargetMachine(), - BC.LiveIns, BC.Key.RegisterInitialValues, - Repetitor.Repeat(Instructions, MinInstructionsForSnippet, - LoopBodySizeForSnippet), - OS)) { - return std::move(E); - } - const ExecutableFunction EF(State.createTargetMachine(), - getObjectFromBuffer(OS.str())); - const auto FnBytes = EF.getFunctionBytes(); - llvm::append_range(InstrBenchmark.AssembledSnippet, FnBytes); + SmallString<0> Buffer; + raw_svector_ostream OS(Buffer); + if (Error E = assembleToStream( + State.getExegesisTarget(), State.createTargetMachine(), BC.LiveIns, + BC.Key.RegisterInitialValues, + Repetitor.Repeat(Instructions, MinInstructionsForSnippet, + LoopBodySizeForSnippet), + OS)) { + return std::move(E); } + const ExecutableFunction EF(State.createTargetMachine(), + getObjectFromBuffer(OS.str())); + const auto FnBytes = EF.getFunctionBytes(); + llvm::append_range(InstrBenchmark.AssembledSnippet, FnBytes); + } - // Assemble NumRepetitions instructions repetitions of the snippet for - // measurements. - const auto Filler = Repetitor.Repeat( - Instructions, InstrBenchmark.NumRepetitions, LoopBodySize); - - object::OwningBinary ObjectFile; - if (DumpObjectToDisk) { - auto ObjectFilePath = writeObjectFile(BC, Filler); - if (Error E = ObjectFilePath.takeError()) { - InstrBenchmark.Error = toString(std::move(E)); - return InstrBenchmark; - } - outs() << "Check generated assembly with: /usr/bin/objdump -d " - << *ObjectFilePath << "\n"; - ObjectFile = getObjectFromFile(*ObjectFilePath); - } else { - SmallString<0> Buffer; - raw_svector_ostream OS(Buffer); - if (Error E = assembleToStream( - State.getExegesisTarget(), State.createTargetMachine(), - BC.LiveIns, BC.Key.RegisterInitialValues, Filler, OS)) { - return std::move(E); - } - ObjectFile = getObjectFromBuffer(OS.str()); - } + // Assemble NumRepetitions instructions repetitions of the snippet for + // measurements. + const auto Filler = Repetitor.Repeat( + Instructions, InstrBenchmark.NumRepetitions, LoopBodySize); - if (BenchmarkSkipMeasurements) { - InstrBenchmark.Error = - "in --skip-measurements mode, actual measurements skipped."; - return InstrBenchmark; - } - - const FunctionExecutorImpl Executor(State, std::move(ObjectFile), - Scratch.get()); - auto NewMeasurements = runMeasurements(Executor); - if (Error E = NewMeasurements.takeError()) { - if (!E.isA()) - return std::move(E); + object::OwningBinary ObjectFile; + if (DumpObjectToDisk) { + auto ObjectFilePath = writeObjectFile(BC, Filler); + if (Error E = ObjectFilePath.takeError()) { InstrBenchmark.Error = toString(std::move(E)); return InstrBenchmark; } - assert(InstrBenchmark.NumRepetitions > 0 && "invalid NumRepetitions"); - for (BenchmarkMeasure &BM : *NewMeasurements) { - // Scale the measurements by instruction. - BM.PerInstructionValue /= InstrBenchmark.NumRepetitions; - // Scale the measurements by snippet. - BM.PerSnippetValue *= static_cast(Instructions.size()) / - InstrBenchmark.NumRepetitions; + outs() << "Check generated assembly with: /usr/bin/objdump -d " + << *ObjectFilePath << "\n"; + ObjectFile = getObjectFromFile(*ObjectFilePath); + } else { + SmallString<0> Buffer; + raw_svector_ostream OS(Buffer); + if (Error E = assembleToStream(State.getExegesisTarget(), + State.createTargetMachine(), BC.LiveIns, + BC.Key.RegisterInitialValues, Filler, OS)) { + return std::move(E); } - InstrBenchmark.Measurements = std::move(*NewMeasurements); + ObjectFile = getObjectFromBuffer(OS.str()); + } + + if (BenchmarkSkipMeasurements) { + InstrBenchmark.Error = + "in --skip-measurements mode, actual measurements skipped."; + return InstrBenchmark; + } + + const FunctionExecutorImpl Executor(State, std::move(ObjectFile), + Scratch.get()); + auto NewMeasurements = runMeasurements(Executor); + if (Error E = NewMeasurements.takeError()) { + if (!E.isA()) + return std::move(E); + InstrBenchmark.Error = toString(std::move(E)); + return InstrBenchmark; + } + assert(InstrBenchmark.NumRepetitions > 0 && "invalid NumRepetitions"); + for (BenchmarkMeasure &BM : *NewMeasurements) { + // Scale the measurements by instruction. + BM.PerInstructionValue /= InstrBenchmark.NumRepetitions; + // Scale the measurements by snippet. + BM.PerSnippetValue *= static_cast(Instructions.size()) / + InstrBenchmark.NumRepetitions; } + InstrBenchmark.Measurements = std::move(*NewMeasurements); return InstrBenchmark; } -- 2.7.4