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/llvm-mca.cpp | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'llvm/tools/llvm-mca/llvm-mca.cpp') diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp index 59b78ff1545..9ad761e6665 100644 --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -35,6 +35,7 @@ #include "Views/TimelineView.h" #include "include/Context.h" #include "include/Pipeline.h" +#include "include/Support.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCObjectFileInfo.h" @@ -326,6 +327,30 @@ static void processViewOptions() { processOptionImpl(PrintRetireStats, Default); } +// Returns true on success. +static bool runPipeline(mca::Pipeline &P, MCInstPrinter &MCIP, + const MCSubtargetInfo &STI) { + // Handle pipeline errors here. + if (auto Err = P.run()) { + if (auto NewE = handleErrors( + std::move(Err), + [&MCIP, &STI](const mca::InstructionError &IE) { + std::string InstructionStr; + raw_string_ostream SS(InstructionStr); + WithColor::error() << IE.Message << '\n'; + MCIP.printInst(&IE.Inst, SS, "", STI); + SS.flush(); + WithColor::note() << "instruction: " << InstructionStr << '\n'; + })) { + // Default case. + WithColor::error() << toString(std::move(NewE)); + } + return false; + } + + return true; +} + int main(int argc, char **argv) { InitLLVM X(argc, argv); @@ -462,7 +487,7 @@ int main(int argc, char **argv) { Width = DispatchWidth; // Create an instruction builder. - mca::InstrBuilder IB(*STI, *MCII, *MRI, *MCIA, *IP); + mca::InstrBuilder IB(*STI, *MCII, *MRI, *MCIA); // Create a context to control ownership of the pipeline hardware. mca::Context MCA(*MRI, *STI); @@ -504,9 +529,10 @@ int main(int argc, char **argv) { } Printer.addView( llvm::make_unique(*STI, *IP, S)); - auto Err = P->run(); - if (Err) - report_fatal_error(toString(std::move(Err))); + + if (!runPipeline(*P, *IP, *STI)) + return 1; + Printer.printReport(TOF->os()); continue; } @@ -543,9 +569,9 @@ int main(int argc, char **argv) { *STI, *IP, S, TimelineMaxIterations, TimelineMaxCycles)); } - auto Err = P->run(); - if (Err) - report_fatal_error(toString(std::move(Err))); + if (!runPipeline(*P, *IP, *STI)) + return 1; + Printer.printReport(TOF->os()); // Clear the InstrBuilder internal state in preparation for another round. -- cgit v1.2.3