diff options
-rw-r--r-- | llvm/include/llvm/CodeGen/AsmPrinter.h | 18 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCCodePadder.h | 1 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 31 | ||||
-rw-r--r-- | llvm/test/CodeGen/AArch64/O0-pipeline.ll | 2 | ||||
-rw-r--r-- | llvm/test/CodeGen/AArch64/O3-pipeline.ll | 2 | ||||
-rw-r--r-- | llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll | 6 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/O0-pipeline.ll | 2 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/O3-pipeline.ll | 2 |
8 files changed, 39 insertions, 25 deletions
diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h index 3d3bd3affcc..92e6b643a5f 100644 --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -50,6 +50,7 @@ class GlobalValue; class GlobalVariable; class MachineBasicBlock; class MachineConstantPoolValue; +class MachineDominatorTree; class MachineFunction; class MachineInstr; class MachineJumpTableInfo; @@ -92,11 +93,17 @@ public: std::unique_ptr<MCStreamer> OutStreamer; /// The current machine function. - const MachineFunction *MF = nullptr; + MachineFunction *MF = nullptr; /// This is a pointer to the current MachineModuleInfo. MachineModuleInfo *MMI = nullptr; + /// This is a pointer to the current MachineLoopInfo. + MachineDominatorTree *MDT = nullptr; + + /// This is a pointer to the current MachineLoopInfo. + MachineLoopInfo *MLI = nullptr; + /// Optimization remark emitter. MachineOptimizationRemarkEmitter *ORE; @@ -130,9 +137,6 @@ private: static char ID; - /// If VerboseAsm is set, a pointer to the loop info for this function. - MachineLoopInfo *LI = nullptr; - struct HandlerInfo { AsmPrinterHandler *Handler; const char *TimerName; @@ -161,6 +165,12 @@ public: }; private: + /// If generated on the fly this own the instance. + std::unique_ptr<MachineDominatorTree> OwnedMDT; + + /// If generated on the fly this own the instance. + std::unique_ptr<MachineLoopInfo> OwnedMLI; + /// Structure for generating diagnostics for inline assembly. Only initialised /// when necessary. mutable std::unique_ptr<SrcMgrDiagInfo> DiagInfo; diff --git a/llvm/include/llvm/MC/MCCodePadder.h b/llvm/include/llvm/MC/MCCodePadder.h index b7772b64a27..4dde6bf5927 100644 --- a/llvm/include/llvm/MC/MCCodePadder.h +++ b/llvm/include/llvm/MC/MCCodePadder.h @@ -28,7 +28,6 @@ typedef SmallVector<const MCPaddingFragment *, 8> MCPFRange; struct MCCodePaddingContext { bool IsPaddingActive; - bool IsBasicBlockInsideInnermostLoop; bool IsBasicBlockReachableViaFallthrough; bool IsBasicBlockReachableViaBranch; }; 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. diff --git a/llvm/test/CodeGen/AArch64/O0-pipeline.ll b/llvm/test/CodeGen/AArch64/O0-pipeline.ll index 051410a579c..dd0d08e68e9 100644 --- a/llvm/test/CodeGen/AArch64/O0-pipeline.ll +++ b/llvm/test/CodeGen/AArch64/O0-pipeline.ll @@ -59,8 +59,6 @@ ; CHECK-NEXT: Implement the 'patchable-function' attribute ; CHECK-NEXT: Lazy Machine Block Frequency Analysis ; CHECK-NEXT: Machine Optimization Remark Emitter -; CHECK-NEXT: MachineDominator Tree Construction -; CHECK-NEXT: Machine Natural Loop Construction ; CHECK-NEXT: AArch64 Assembly Printer ; CHECK-NEXT: Free MachineFunction diff --git a/llvm/test/CodeGen/AArch64/O3-pipeline.ll b/llvm/test/CodeGen/AArch64/O3-pipeline.ll index 701cb370338..36ce0270609 100644 --- a/llvm/test/CodeGen/AArch64/O3-pipeline.ll +++ b/llvm/test/CodeGen/AArch64/O3-pipeline.ll @@ -156,8 +156,6 @@ ; CHECK-NEXT: Implement the 'patchable-function' attribute ; CHECK-NEXT: Lazy Machine Block Frequency Analysis ; CHECK-NEXT: Machine Optimization Remark Emitter -; CHECK-NEXT: MachineDominator Tree Construction -; CHECK-NEXT: Machine Natural Loop Construction ; CHECK-NEXT: AArch64 Assembly Printer ; CHECK-NEXT: Free MachineFunction ; CHECK-NEXT: Pass Arguments: -domtree diff --git a/llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll b/llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll index f61f98a4d51..7efb4bf6d59 100644 --- a/llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll +++ b/llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll @@ -36,9 +36,7 @@ ; HOTNESS-NOT: Executing Pass ; HOTNESS: block-frequency: empty_func ; HOTNESS-NOT: Executing Pass -; HOTNESS: Executing Pass 'MachineDominator Tree Construction' -; HOTNESS-NEXT: Executing Pass 'Machine Natural Loop Construction' -; HOTNESS-NEXT: Executing Pass 'AArch64 Assembly Printer' +; HOTNESS: Executing Pass 'AArch64 Assembly Printer' ; HOTNESS: arm64-summary-remarks.ll:5:0: 1 instructions in function (hotness: 33) @@ -47,8 +45,6 @@ ; NO_HOTNESS-NEXT: Freeing Pass 'Implement the 'patchable-function' attribute' ; NO_HOTNESS-NEXT: Executing Pass 'Lazy Machine Block Frequency Analysis' ; NO_HOTNESS-NEXT: Executing Pass 'Machine Optimization Remark Emitter' -; NO_HOTNESS-NEXT: Executing Pass 'MachineDominator Tree Construction' -; NO_HOTNESS-NEXT: Executing Pass 'Machine Natural Loop Construction' ; NO_HOTNESS-NEXT: Executing Pass 'AArch64 Assembly Printer' ; NO_HOTNESS: arm64-summary-remarks.ll:5:0: 1 instructions in function{{$}} diff --git a/llvm/test/CodeGen/X86/O0-pipeline.ll b/llvm/test/CodeGen/X86/O0-pipeline.ll index 3c0a626e9c6..6dab866a751 100644 --- a/llvm/test/CodeGen/X86/O0-pipeline.ll +++ b/llvm/test/CodeGen/X86/O0-pipeline.ll @@ -61,8 +61,6 @@ ; CHECK-NEXT: X86 Retpoline Thunks ; CHECK-NEXT: Lazy Machine Block Frequency Analysis ; CHECK-NEXT: Machine Optimization Remark Emitter -; CHECK-NEXT: MachineDominator Tree Construction -; CHECK-NEXT: Machine Natural Loop Construction ; CHECK-NEXT: X86 Assembly Printer ; CHECK-NEXT: Free MachineFunction diff --git a/llvm/test/CodeGen/X86/O3-pipeline.ll b/llvm/test/CodeGen/X86/O3-pipeline.ll index 42e5f391938..9c69628091b 100644 --- a/llvm/test/CodeGen/X86/O3-pipeline.ll +++ b/llvm/test/CodeGen/X86/O3-pipeline.ll @@ -160,8 +160,6 @@ ; CHECK-NEXT: X86 Retpoline Thunks ; CHECK-NEXT: Lazy Machine Block Frequency Analysis ; CHECK-NEXT: Machine Optimization Remark Emitter -; CHECK-NEXT: MachineDominator Tree Construction -; CHECK-NEXT: Machine Natural Loop Construction ; CHECK-NEXT: X86 Assembly Printer ; CHECK-NEXT: Free MachineFunction |