From 57fdb210373a847f6da107d00d0936aa1a9ec0bc Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Thu, 8 Aug 2019 10:30:58 +0000 Subject: [PATCH] [MCA] Remove dependency from InstrBuilder in mca::Context. NFC InstrBuilder is not required to construct the default pipeline. llvm-svn: 368275 --- include/llvm/MCA/Context.h | 5 ++-- lib/MCA/Context.cpp | 3 +-- tools/llvm-mca/llvm-mca.cpp | 50 ++++++++++++++++++++----------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/include/llvm/MCA/Context.h b/include/llvm/MCA/Context.h index 503d780d494..af3cb8e1e83 100644 --- a/include/llvm/MCA/Context.h +++ b/include/llvm/MCA/Context.h @@ -20,7 +20,6 @@ #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MCA/HardwareUnits/HardwareUnit.h" -#include "llvm/MCA/InstrBuilder.h" #include "llvm/MCA/Pipeline.h" #include "llvm/MCA/SourceMgr.h" #include @@ -58,6 +57,9 @@ public: Context(const Context &C) = delete; Context &operator=(const Context &C) = delete; + const MCRegisterInfo &getMCRegisterInfo() const { return MRI; } + const MCSubtargetInfo &getMCSubtargetInfo() const { return STI; } + void addHardwareUnit(std::unique_ptr H) { Hardware.push_back(std::move(H)); } @@ -65,7 +67,6 @@ public: /// Construct a basic pipeline for simulating an out-of-order pipeline. /// This pipeline consists of Fetch, Dispatch, Execute, and Retire stages. std::unique_ptr createDefaultPipeline(const PipelineOptions &Opts, - InstrBuilder &IB, SourceMgr &SrcMgr); }; diff --git a/lib/MCA/Context.cpp b/lib/MCA/Context.cpp index f0e8dfab868..3bcabb6a235 100644 --- a/lib/MCA/Context.cpp +++ b/lib/MCA/Context.cpp @@ -28,8 +28,7 @@ namespace llvm { namespace mca { std::unique_ptr -Context::createDefaultPipeline(const PipelineOptions &Opts, InstrBuilder &IB, - SourceMgr &SrcMgr) { +Context::createDefaultPipeline(const PipelineOptions &Opts, SourceMgr &SrcMgr) { const MCSchedModel &SM = STI.getSchedModel(); // Create the hardware units defining the backend. diff --git a/tools/llvm-mca/llvm-mca.cpp b/tools/llvm-mca/llvm-mca.cpp index a6acca4e678..63a748c3212 100644 --- a/tools/llvm-mca/llvm-mca.cpp +++ b/tools/llvm-mca/llvm-mca.cpp @@ -34,9 +34,12 @@ #include "Views/TimelineView.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MCA/Context.h" +#include "llvm/MCA/InstrBuilder.h" #include "llvm/MCA/Pipeline.h" #include "llvm/MCA/Stages/EntryStage.h" #include "llvm/MCA/Stages/InstructionTables.h" @@ -307,28 +310,6 @@ int main(int argc, char **argv) { // Apply overrides to llvm-mca specific options. processViewOptions(); - SourceMgr SrcMgr; - - // Tell SrcMgr about this buffer, which is what the parser will pick up. - SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc()); - - std::unique_ptr MRI(TheTarget->createMCRegInfo(TripleName)); - assert(MRI && "Unable to create target register info!"); - - std::unique_ptr MAI(TheTarget->createMCAsmInfo(*MRI, TripleName)); - assert(MAI && "Unable to create target asm info!"); - - MCObjectFileInfo MOFI; - MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr); - MOFI.InitMCObjectFileInfo(TheTriple, /* PIC= */ false, Ctx); - - std::unique_ptr BOS; - - std::unique_ptr MCII(TheTarget->createMCInstrInfo()); - - std::unique_ptr MCIA( - TheTarget->createMCInstrAnalysis(MCII.get())); - if (!MCPU.compare("native")) MCPU = llvm::sys::getHostCPUName(); @@ -356,6 +337,29 @@ int main(int argc, char **argv) { return 1; } + std::unique_ptr MRI(TheTarget->createMCRegInfo(TripleName)); + assert(MRI && "Unable to create target register info!"); + + std::unique_ptr MAI(TheTarget->createMCAsmInfo(*MRI, TripleName)); + assert(MAI && "Unable to create target asm info!"); + + MCObjectFileInfo MOFI; + SourceMgr SrcMgr; + + // Tell SrcMgr about this buffer, which is what the parser will pick up. + SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc()); + + MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr); + + MOFI.InitMCObjectFileInfo(TheTriple, /* PIC= */ false, Ctx); + + std::unique_ptr BOS; + + std::unique_ptr MCII(TheTarget->createMCInstrInfo()); + + std::unique_ptr MCIA( + TheTarget->createMCInstrAnalysis(MCII.get())); + // Parse the input and create CodeRegions that llvm-mca can analyze. mca::AsmCodeRegionGenerator CRG(*TheTarget, SrcMgr, Ctx, *MAI, *STI, *MCII); Expected RegionsOrErr = CRG.parseCodeRegions(); @@ -487,7 +491,7 @@ int main(int argc, char **argv) { } // Create a basic pipeline simulating an out-of-order backend. - auto P = MCA.createDefaultPipeline(PO, IB, S); + auto P = MCA.createDefaultPipeline(PO, S); mca::PipelinePrinter Printer(*P); if (PrintSummaryView)