Skip to content

[llvm-exegesis]Allow clients to do their own snippet running error ha… #74711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ BenchmarkRunner::createFunctionExecutor(
llvm_unreachable("ExecutionMode is outside expected range");
}

Expected<Benchmark> BenchmarkRunner::runConfiguration(
std::pair<Error, Benchmark> BenchmarkRunner::runConfiguration(
RunnableConfiguration &&RC,
const std::optional<StringRef> &DumpFile) const {
Benchmark &InstrBenchmark = RC.InstrBenchmark;
Expand All @@ -583,29 +583,25 @@ Expected<Benchmark> 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";
}

if (BenchmarkPhaseSelector < BenchmarkPhaseSelectorE::Measure) {
InstrBenchmark.Error = "actual measurements skipped.";
return std::move(InstrBenchmark);
return {Error::success(), std::move(InstrBenchmark)};
}

Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>> 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<SnippetCrash>())
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) {
Expand All @@ -618,7 +614,7 @@ Expected<Benchmark> BenchmarkRunner::runConfiguration(
}
InstrBenchmark.Measurements = std::move(*NewMeasurements);

return std::move(InstrBenchmark);
return {Error::success(), std::move(InstrBenchmark)};
}

Expected<std::string>
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class BenchmarkRunner {
unsigned NumRepetitions, unsigned LoopUnrollFactor,
const SnippetRepetitor &Repetitor) const;

Expected<Benchmark>
std::pair<Error, Benchmark>
runConfiguration(RunnableConfiguration &&RC,
const std::optional<StringRef> &DumpFile) const;

Expand Down
14 changes: 12 additions & 2 deletions llvm/tools/llvm-exegesis/llvm-exegesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,18 @@ static void runBenchmarkConfigurations(
std::optional<StringRef> 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<SnippetCrash>()) {
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();

Expand Down