From 9017229ecda119e7977739dcab125e455289ade6 Mon Sep 17 00:00:00 2001 From: Clement Courbet Date: Fri, 8 Dec 2023 13:01:01 +0100 Subject: =?UTF-8?q?[llvm-exegesis]Allow=20clients=20to=20do=20their=20own?= =?UTF-8?q?=20snippet=20running=20error=20ha=E2=80=A6=20(#74711)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …ndling. Returns an error *and* a benchmark rather than an error *or* a benchmark. This allows users to have custom error handling while still being able to inspect the benchmark. Apart from this small API change, this is an NFC. This is an alternative to #74211. --- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 16 ++++++---------- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h | 2 +- llvm/tools/llvm-exegesis/llvm-exegesis.cpp | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 8e242cd..6c34446 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -572,7 +572,7 @@ BenchmarkRunner::createFunctionExecutor( llvm_unreachable("ExecutionMode is outside expected range"); } -Expected BenchmarkRunner::runConfiguration( +std::pair BenchmarkRunner::runConfiguration( RunnableConfiguration &&RC, const std::optional &DumpFile) const { Benchmark &InstrBenchmark = RC.InstrBenchmark; @@ -583,8 +583,7 @@ Expected BenchmarkRunner::runConfiguration( auto ObjectFilePath = writeObjectFile(ObjectFile.getBinary()->getData(), *DumpFile); if (Error E = ObjectFilePath.takeError()) { - InstrBenchmark.Error = toString(std::move(E)); - return std::move(InstrBenchmark); + return {std::move(E), std::move(InstrBenchmark)}; } outs() << "Check generated assembly with: /usr/bin/objdump -d " << *ObjectFilePath << "\n"; @@ -592,20 +591,17 @@ Expected BenchmarkRunner::runConfiguration( if (BenchmarkPhaseSelector < BenchmarkPhaseSelectorE::Measure) { InstrBenchmark.Error = "actual measurements skipped."; - return std::move(InstrBenchmark); + return {Error::success(), std::move(InstrBenchmark)}; } Expected> Executor = createFunctionExecutor(std::move(ObjectFile), RC.InstrBenchmark.Key); if (!Executor) - return Executor.takeError(); + return {Executor.takeError(), std::move(InstrBenchmark)}; auto NewMeasurements = runMeasurements(**Executor); if (Error E = NewMeasurements.takeError()) { - if (!E.isA()) - return std::move(E); - InstrBenchmark.Error = toString(std::move(E)); - return std::move(InstrBenchmark); + return {std::move(E), std::move(InstrBenchmark)}; } assert(InstrBenchmark.NumRepetitions > 0 && "invalid NumRepetitions"); for (BenchmarkMeasure &BM : *NewMeasurements) { @@ -618,7 +614,7 @@ Expected BenchmarkRunner::runConfiguration( } InstrBenchmark.Measurements = std::move(*NewMeasurements); - return std::move(InstrBenchmark); + return {Error::success(), std::move(InstrBenchmark)}; } Expected diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h index 24f2086..2c48d07 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h @@ -65,7 +65,7 @@ public: unsigned NumRepetitions, unsigned LoopUnrollFactor, const SnippetRepetitor &Repetitor) const; - Expected + std::pair runConfiguration(RunnableConfiguration &&RC, const std::optional &DumpFile) const; diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp index 4e46630..148891a 100644 --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -410,8 +410,18 @@ static void runBenchmarkConfigurations( std::optional DumpFile; if (DumpObjectToDisk.getNumOccurrences()) DumpFile = DumpObjectToDisk; - AllResults.emplace_back( - ExitOnErr(Runner.runConfiguration(std::move(RC), DumpFile))); + auto [Err, InstrBenchmark] = + Runner.runConfiguration(std::move(RC), DumpFile); + if (Err) { + // Errors from executing the snippets are fine. + // All other errors are a framework issue and should fail. + if (!Err.isA()) { + llvm::errs() << "llvm-exegesis error: " << toString(std::move(Err)); + exit(1); + } + InstrBenchmark.Error = toString(std::move(Err)); + } + AllResults.push_back(std::move(InstrBenchmark)); } Benchmark &Result = AllResults.front(); -- cgit v1.1