From 083addf75192ff07eccd002eceeeacd085054217 Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Wed, 24 Oct 2018 10:56:47 +0000 Subject: [llvm-mca] [llvm-mca] Improved error handling and error reporting from class InstrBuilder. A new class named InstructionError has been added to Support.h in order to improve the error reporting from class InstrBuilder. The llvm-mca driver is responsible for handling InstructionError objects, and printing them out to stderr. The goal of this patch is to remove all the remaining error handling logic from the library code. In particular, this allows us to: - Simplify the logic in InstrBuilder by removing a needless dependency from MCInstrPrinter. - Centralize all the error halding logic in a new function named 'runPipeline' (see llvm-mca.cpp). This is also a first step towards generalizing class InstrBuilder, so that in future, we will be able to reuse its logic to also "lower" MachineInstr to mca::Instruction objects. Differential Revision: https://reviews.llvm.org/D53585 llvm-svn: 345129 --- llvm/tools/llvm-mca/include/Support.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'llvm/tools/llvm-mca/include/Support.h') diff --git a/llvm/tools/llvm-mca/include/Support.h b/llvm/tools/llvm-mca/include/Support.h index 91c8e1b4177..9371394542d 100644 --- a/llvm/tools/llvm-mca/include/Support.h +++ b/llvm/tools/llvm-mca/include/Support.h @@ -18,9 +18,29 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/MC/MCSchedule.h" +#include "llvm/Support/Error.h" namespace mca { +template +class InstructionError : public llvm::ErrorInfo> { +public: + static char ID; + std::string Message; + const T &Inst; + + InstructionError(std::string M, const T &MCI) + : Message(std::move(M)), Inst(MCI) {} + + void log(llvm::raw_ostream &OS) const override { OS << Message; } + + std::error_code convertToErrorCode() const override { + return llvm::inconvertibleErrorCode(); + } +}; + +template char InstructionError::ID; + /// This class represents the number of cycles per resource (fractions of /// cycles). That quantity is managed here as a ratio, and accessed via the /// double cast-operator below. The two quantities, number of cycles and -- cgit v1.2.3