diff options
author | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-04-09 00:54:47 +0000 |
---|---|---|
committer | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-04-09 00:54:47 +0000 |
commit | 8d052a0dd23f1fd9e3fba1912bd514d2fd687871 (patch) | |
tree | ad81c20e7d446571f2f0c4427a501c6b6d7495b8 /llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | |
parent | ba0543b32bf0c9a32b0f0d2dfbb7d31de7962570 (diff) | |
download | bcm5719-llvm-8d052a0dd23f1fd9e3fba1912bd514d2fd687871.tar.gz bcm5719-llvm-8d052a0dd23f1fd9e3fba1912bd514d2fd687871.zip |
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
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
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<MachineModuleInfo>(); AU.addRequired<MachineOptimizationRemarkEmitterPass>(); AU.addRequired<GCModuleInfo>(); - AU.addRequired<MachineLoopInfo>(); } 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<MachineDominatorTree>(); + if (!MDT) { + OwnedMDT = make_unique<MachineDominatorTree>(); + OwnedMDT->getBase().recalculate(*MF); + MDT = OwnedMDT.get(); + } + + // Get MachineLoopInfo or compute it on the fly if it's unavailable + MLI = getAnalysisIfAvailable<MachineLoopInfo>(); + if (!MLI) { + OwnedMLI = make_unique<MachineLoopInfo>(); + 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<MachineOptimizationRemarkEmitterPass>().getORE(); - LI = &getAnalysis<MachineLoopInfo>(); 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. |