diff --git a/llvm/tools/llvm-exegesis/lib/CMakeLists.txt b/llvm/tools/llvm-exegesis/lib/CMakeLists.txt --- a/llvm/tools/llvm-exegesis/lib/CMakeLists.txt +++ b/llvm/tools/llvm-exegesis/lib/CMakeLists.txt @@ -27,6 +27,7 @@ BenchmarkRunner.cpp Clustering.cpp CodeTemplate.cpp + Error.cpp LatencyBenchmarkRunner.cpp LlvmState.cpp MCInstrDescView.cpp diff --git a/llvm/tools/llvm-exegesis/lib/Clustering.cpp b/llvm/tools/llvm-exegesis/lib/Clustering.cpp --- a/llvm/tools/llvm-exegesis/lib/Clustering.cpp +++ b/llvm/tools/llvm-exegesis/lib/Clustering.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "Clustering.h" +#include "Error.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" @@ -106,14 +107,13 @@ const auto *CurMeasurement = &Point.Measurements; if (LastMeasurement) { if (LastMeasurement->size() != CurMeasurement->size()) { - return make_error("inconsistent measurement dimensions", - inconvertibleErrorCode()); + return make_error( + "inconsistent measurement dimensions"); } for (size_t I = 0, E = LastMeasurement->size(); I < E; ++I) { if (LastMeasurement->at(I).Key != CurMeasurement->at(I).Key) { - return make_error( - "inconsistent measurement dimensions keys", - inconvertibleErrorCode()); + return make_error( + "inconsistent measurement dimensions keys"); } } } @@ -333,7 +333,7 @@ Clustering.stabilize(NumOpcodes.getValue()); } else /*if(Mode == ModeE::Naive)*/ { if (!NumOpcodes.hasValue()) - report_fatal_error( + return make_error( "'naive' clustering mode requires opcode count to be specified"); Clustering.clusterizeNaive(NumOpcodes.getValue()); } diff --git a/llvm/tools/llvm-exegesis/lib/Error.h b/llvm/tools/llvm-exegesis/lib/Error.h --- a/llvm/tools/llvm-exegesis/lib/Error.h +++ b/llvm/tools/llvm-exegesis/lib/Error.h @@ -22,6 +22,19 @@ Failure(const Twine &S) : StringError(S, inconvertibleErrorCode()) {} }; +// A class representing failures that happened during clustering calculations. +class ClusteringError : public ErrorInfo { +public: + static char ID; + ClusteringError(const Twine&S) : Msg(S.str()) {} + + void log(raw_ostream &OS) const override; + + std::error_code convertToErrorCode() const override; +private: + std::string Msg; +}; + } // namespace exegesis } // namespace llvm diff --git a/llvm/tools/llvm-exegesis/lib/Error.cpp b/llvm/tools/llvm-exegesis/lib/Error.cpp new file mode 100644 --- /dev/null +++ b/llvm/tools/llvm-exegesis/lib/Error.cpp @@ -0,0 +1,25 @@ +//===-- Error.cpp -----------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "Error.h" + +namespace llvm { +namespace exegesis { + +char ClusteringError::ID; + +void ClusteringError::log(raw_ostream &OS) const { + OS << Msg; +} + +std::error_code ClusteringError::convertToErrorCode() const { + return inconvertibleErrorCode(); +} + +} // namespace exegesis +} // namespace llvm diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -373,7 +373,7 @@ cl::ParseCommandLineOptions(Argc, Argv, ""); exegesis::ExitOnErr.setExitCodeMapper([](const Error &Err) { - if (Err.isA()) + if (Err.isA()) return EXIT_SUCCESS; return EXIT_FAILURE; });