Followup to D74085.
Replace the use of `report_fatal_error()` with returning the error to
`llvm-exegesis.cpp` and handling it there.
To facilitate this, a new `Error` type has been added which is only used
to log errors to the yaml output.
Differential Revision: https://reviews.llvm.org/D74215
CounterName = CounterName.trim();
pfm::PerfEvent PerfEvent(CounterName);
if (!PerfEvent.valid())
- report_fatal_error(
+ return make_error<Failure>(
Twine("invalid perf event '").concat(CounterName).concat("'"));
pfm::Counter Counter(PerfEvent);
Scratch->clear();
CrashRecoveryContext::Disable();
// FIXME: Better diagnosis.
if (Crashed)
- return make_error<Failure>("snippet crashed while running");
+ return make_error<SnippetCrash>("snippet crashed while running");
}
CounterValue += Counter.read();
}
};
} // namespace
-InstructionBenchmark BenchmarkRunner::runConfiguration(
+Expected<InstructionBenchmark> BenchmarkRunner::runConfiguration(
const BenchmarkCode &BC, unsigned NumRepetitions,
const SnippetRepetitor &Repetitor, bool DumpObjectToDisk) const {
InstructionBenchmark InstrBenchmark;
Scratch.get());
auto Measurements = runMeasurements(Executor);
if (Error E = Measurements.takeError()) {
+ if (!E.isA<SnippetCrash>())
+ return std::move(E);
InstrBenchmark.Error = toString(std::move(E));
return InstrBenchmark;
}
virtual ~BenchmarkRunner();
- InstructionBenchmark runConfiguration(const BenchmarkCode &Configuration,
- unsigned NumRepetitions,
- const SnippetRepetitor &Repetitor,
- bool DumpObjectToDisk) const;
+ Expected<InstructionBenchmark>
+ runConfiguration(const BenchmarkCode &Configuration, unsigned NumRepetitions,
+ const SnippetRepetitor &Repetitor,
+ bool DumpObjectToDisk) const;
// Scratch space to run instructions that touch memory.
struct ScratchSpace {
char ClusteringError::ID;
-void ClusteringError::log(raw_ostream &OS) const {
- OS << Msg;
-}
+void ClusteringError::log(raw_ostream &OS) const { OS << Msg; }
std::error_code ClusteringError::convertToErrorCode() const {
return inconvertibleErrorCode();
}
+char SnippetCrash::ID;
+
+void SnippetCrash::log(raw_ostream &OS) const { OS << Msg; }
+
+std::error_code SnippetCrash::convertToErrorCode() const {
+ return inconvertibleErrorCode();
+}
+
} // namespace exegesis
} // namespace llvm
class ClusteringError : public ErrorInfo<ClusteringError> {
public:
static char ID;
- ClusteringError(const Twine&S) : Msg(S.str()) {}
+ ClusteringError(const Twine &S) : Msg(S.str()) {}
void log(raw_ostream &OS) const override;
std::error_code convertToErrorCode() const override;
+
+private:
+ std::string Msg;
+};
+
+// A class representing failures that happened during snippet execution.
+// Instead of terminating the program crashes are logged into the output.
+class SnippetCrash : public ErrorInfo<SnippetCrash> {
+public:
+ static char ID;
+ SnippetCrash(const Twine &S) : Msg(S.str()) {}
+
+ void log(raw_ostream &OS) const override;
+
+ std::error_code convertToErrorCode() const override;
+
private:
- std::string Msg;
+ std::string Msg;
};
} // namespace exegesis
BenchmarkFile = "-";
for (const BenchmarkCode &Conf : Configurations) {
- InstructionBenchmark Result = Runner->runConfiguration(
- Conf, NumRepetitions, *Repetitor, DumpObjectToDisk);
+ InstructionBenchmark Result = ExitOnErr(Runner->runConfiguration(
+ Conf, NumRepetitions, *Repetitor, DumpObjectToDisk));
ExitOnFileError(BenchmarkFile, Result.writeYaml(State, BenchmarkFile));
}
exegesis::pfm::pfmTerminate();