From 8d052a0dd23f1fd9e3fba1912bd514d2fd687871 Mon Sep 17 00:00:00 2001 From: Michael Zolotukhin Date: Mon, 9 Apr 2018 00:54:47 +0000 Subject: Remove MachineLoopInfo dependency from AsmPrinter. Summary: Currently MachineLoopInfo is used in only two places: 1) for computing IsBasicBlockInsideInnermostLoop field of MCCodePaddingContext, and it is never used. 2) in emitBasicBlockLoopComments, which is called only if `isVerbose()` is true. Despite that, we currently have a dependency on MachineLoopInfo, which makes pass manager to compute it and MachineDominator Tree. This patch removes the use (1) and makes the use (2) lazy, thus avoiding some redundant recomputations. Reviewers: opaparo, gadi.haber, rafael, craig.topper, zvi Subscribers: rengolin, javed.absar, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D44812 llvm-svn: 329542 --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 31 +++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'llvm/lib/CodeGen/AsmPrinter') diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 2926ea64b85..1375662c8ae 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -39,6 +39,7 @@ #include "llvm/CodeGen/GCStrategy.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineConstantPool.h" +#include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" @@ -238,7 +239,6 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); AU.addRequired(); AU.addRequired(); - AU.addRequired(); } bool AsmPrinter::doInitialization(Module &M) { @@ -1009,6 +1009,24 @@ void AsmPrinter::EmitFunctionBody() { bool ShouldPrintDebugScopes = MMI->hasDebugInfo(); + if (isVerbose()) { + // Get MachineDominatorTree or compute it on the fly if it's unavailable + MDT = getAnalysisIfAvailable(); + if (!MDT) { + OwnedMDT = make_unique(); + OwnedMDT->getBase().recalculate(*MF); + MDT = OwnedMDT.get(); + } + + // Get MachineLoopInfo or compute it on the fly if it's unavailable + MLI = getAnalysisIfAvailable(); + if (!MLI) { + OwnedMLI = make_unique(); + OwnedMLI->getBase().analyze(MDT->getBase()); + MLI = OwnedMLI.get(); + } + } + // Print out code for the function. bool HasAnyRealCode = false; int NumInstsInFunction = 0; @@ -1489,6 +1507,8 @@ bool AsmPrinter::doFinalization(Module &M) { OutStreamer->Finish(); OutStreamer->reset(); + OwnedMLI.reset(); + OwnedMDT.reset(); return false; } @@ -1515,7 +1535,6 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { } ORE = &getAnalysis().getORE(); - LI = &getAnalysis(); const TargetSubtargetInfo &STI = MF.getSubtarget(); EnablePrintSchedInfo = PrintSchedule.getNumOccurrences() @@ -2697,13 +2716,9 @@ static void emitBasicBlockLoopComments(const MachineBasicBlock &MBB, void AsmPrinter::setupCodePaddingContext(const MachineBasicBlock &MBB, MCCodePaddingContext &Context) const { assert(MF != nullptr && "Machine function must be valid"); - assert(LI != nullptr && "Loop info must be valid"); Context.IsPaddingActive = !MF->hasInlineAsm() && !MF->getFunction().optForSize() && TM.getOptLevel() != CodeGenOpt::None; - const MachineLoop *CurrentLoop = LI->getLoopFor(&MBB); - Context.IsBasicBlockInsideInnermostLoop = - CurrentLoop != nullptr && CurrentLoop->getSubLoops().empty(); Context.IsBasicBlockReachableViaFallthrough = std::find(MBB.pred_begin(), MBB.pred_end(), MBB.getPrevNode()) != MBB.pred_end(); @@ -2755,7 +2770,9 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock &MBB) const { OutStreamer->GetCommentOS() << '\n'; } } - emitBasicBlockLoopComments(MBB, LI, *this); + + assert(MLI != nullptr && "MachineLoopInfo should has been computed"); + emitBasicBlockLoopComments(MBB, MLI, *this); } // Print the main label for the block. -- cgit v1.2.3