diff options
author | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2018-10-24 10:56:47 +0000 |
---|---|---|
committer | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2018-10-24 10:56:47 +0000 |
commit | 083addf75192ff07eccd002eceeeacd085054217 (patch) | |
tree | 724d9216029784e31e31e21542d39ee6d7b99de5 /llvm/tools/llvm-mca/llvm-mca.cpp | |
parent | 5a74a9cf5f9eb012d97075e3d85f7a8698a97a3e (diff) | |
download | bcm5719-llvm-083addf75192ff07eccd002eceeeacd085054217.tar.gz bcm5719-llvm-083addf75192ff07eccd002eceeeacd085054217.zip |
[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
Diffstat (limited to 'llvm/tools/llvm-mca/llvm-mca.cpp')
-rw-r--r-- | llvm/tools/llvm-mca/llvm-mca.cpp | 40 |
1 files changed, 33 insertions, 7 deletions
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<MCInst> &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<mca::ResourcePressureView>(*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. |