From 5c469442e833ae7ad7ea5276deb885b28d131df2 Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Sun, 8 Apr 2018 15:10:19 +0000 Subject: [llvm-mca] Simplify code. NFC llvm-svn: 329532 --- llvm/tools/llvm-mca/llvm-mca.cpp | 59 ++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 33 deletions(-) (limited to 'llvm/tools') diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp index efd0d1957fd..91bcb90b3a4 100644 --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -137,7 +137,9 @@ static cl::opt cl::desc("Print the instruction info view"), cl::init(true)); -static const Target *getTarget(const char *ProgName) { +namespace { + +const Target *getTarget(const char *ProgName) { TripleName = Triple::normalize(TripleName); if (TripleName.empty()) TripleName = Triple::normalize(sys::getDefaultTargetTriple()); @@ -156,13 +158,11 @@ static const Target *getTarget(const char *ProgName) { return TheTarget; } -static int AssembleInput(const char *ProgName, const Target *TheTarget, - SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str, - MCAsmInfo &MAI, MCSubtargetInfo &STI, - MCInstrInfo &MCII, MCTargetOptions &MCOptions) { - std::unique_ptr Parser(createMCAsmParser(SrcMgr, Ctx, Str, MAI)); +int AssembleInput(const char *ProgName, MCAsmParser &Parser, + const Target *TheTarget, MCSubtargetInfo &STI, + MCInstrInfo &MCII, MCTargetOptions &MCOptions) { std::unique_ptr TAP( - TheTarget->createMCAsmParser(STI, *Parser, MCII, MCOptions)); + TheTarget->createMCAsmParser(STI, Parser, MCII, MCOptions)); if (!TAP) { errs() << ProgName @@ -170,11 +170,11 @@ static int AssembleInput(const char *ProgName, const Target *TheTarget, return 1; } - Parser->setTargetParser(*TAP); - return Parser->Run(false); + Parser.setTargetParser(*TAP); + return Parser.Run(false); } -static ErrorOr> getOutputStream() { +ErrorOr> getOutputStream() { if (OutputFilename == "") OutputFilename = "-"; std::error_code EC; @@ -185,8 +185,6 @@ static ErrorOr> getOutputStream() { return EC; } -namespace { - class MCStreamerWrapper final : public MCStreamer { using InstVec = std::vector>; InstVec &Insts; @@ -311,10 +309,9 @@ int main(int argc, char **argv) { return 1; } - int Res = AssembleInput(ProgName, TheTarget, SrcMgr, Ctx, Str, *MAI, *STI, - *MCII, MCOptions); - if (Res) - return Res; + std::unique_ptr P(createMCAsmParser(SrcMgr, Ctx, Str, *MAI)); + if (AssembleInput(ProgName, *P, TheTarget, *STI, *MCII, MCOptions)) + return 1; if (S->isEmpty()) { errs() << "error: no assembly instructions found.\n"; @@ -337,11 +334,10 @@ int main(int argc, char **argv) { Width = DispatchWidth; // Create an instruction builder. - std::unique_ptr IB = - llvm::make_unique(*STI, *MCII); + mca::InstrBuilder IB(*STI, *MCII); if (PrintInstructionTables) { - mca::InstructionTables IT(STI->getSchedModel(), *IB, *S); + mca::InstructionTables IT(STI->getSchedModel(), IB, *S); if (PrintInstructionInfoView) { IT.addView( @@ -355,36 +351,33 @@ int main(int argc, char **argv) { return 0; } - std::unique_ptr B = llvm::make_unique( - *STI, *MRI, *IB, *S, Width, RegisterFileSize, LoadQueueSize, - StoreQueueSize, AssumeNoAlias); - - std::unique_ptr Printer = - llvm::make_unique(*B); + mca::Backend B(*STI, *MRI, IB, *S, Width, RegisterFileSize, LoadQueueSize, + StoreQueueSize, AssumeNoAlias); + mca::BackendPrinter Printer(B); - Printer->addView(llvm::make_unique(*S, Width)); + Printer.addView(llvm::make_unique(*S, Width)); if (PrintInstructionInfoView) - Printer->addView( + Printer.addView( llvm::make_unique(*STI, *MCII, *S, *IP)); if (PrintModeVerbose) - Printer->addView(llvm::make_unique(*STI)); + Printer.addView(llvm::make_unique(*STI)); if (PrintRegisterFileStats) - Printer->addView(llvm::make_unique(*STI)); + Printer.addView(llvm::make_unique(*STI)); if (PrintResourcePressureView) - Printer->addView( + Printer.addView( llvm::make_unique(*STI, *IP, *S)); if (PrintTimelineView) { - Printer->addView(llvm::make_unique( + Printer.addView(llvm::make_unique( *STI, *IP, *S, TimelineMaxIterations, TimelineMaxCycles)); } - B->run(); - Printer->printReport(TOF->os()); + B.run(); + Printer.printReport(TOF->os()); TOF->keep(); return 0; -- cgit v1.2.3