llvm.org GIT mirror llvm / de5df29
[PM] Split the LoopInfo object apart from the legacy pass, creating a LoopInfoWrapperPass to wire the object up to the legacy pass manager. This switches all the clients of LoopInfo over and paves the way to port LoopInfo to the new pass manager. No functionality change is intended with this iteration. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226373 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 5 years ago
39 changed file(s) with 188 addition(s) and 166 deletion(s). Raw diff Collapse all Expand all
852852 // This example modifies the program, but does not modify the CFG
853853 void LICM::getAnalysisUsage(AnalysisUsage &AU) const {
854854 AU.setPreservesCFG();
855 AU.addRequired>();
855 AU.addRequiredWrapperPass>();
856856 }
857857
858858 .. _writing-an-llvm-pass-getAnalysis:
869869 .. code-block:: c++
870870
871871 bool LICM::runOnFunction(Function &F) {
872 LoopInfo &LI = getAnalysis>();
872 LoopInfo &LI = getAnalysisWrapperPass>().getLoopInfo();
873873 //...
874874 }
875875
494494 std::vector TopLevelLoops;
495495 friend class LoopBase;
496496 friend class LoopInfo;
497 friend class LoopInfoWrapperPass;
497498
498499 void operator=(const LoopInfoBase &) LLVM_DELETED_FUNCTION;
499500 LoopInfoBase(const LoopInfo &) LLVM_DELETED_FUNCTION;
625626 __extension__ extern template class LoopInfoBase;
626627 #endif
627628
628 class LoopInfo : public FunctionPass {
629 class LoopInfo {
629630 LoopInfoBase LI;
630631 friend class LoopBase;
632 friend class LoopInfoWrapperPass;
631633
632634 void operator=(const LoopInfo &) LLVM_DELETED_FUNCTION;
633635 LoopInfo(const LoopInfo &) LLVM_DELETED_FUNCTION;
634636 public:
635 static char ID; // Pass identification, replacement for typeid
636
637 LoopInfo() : FunctionPass(ID) {
638 initializeLoopInfoPass(*PassRegistry::getPassRegistry());
639 }
637 LoopInfo() {}
640638
641639 LoopInfoBase& getBase() { return LI; }
642640
676674 return LI.isLoopHeader(BB);
677675 }
678676
679 /// runOnFunction - Calculate the natural loop information.
680 ///
681 bool runOnFunction(Function &F) override;
682
683 void verifyAnalysis() const override;
684
685 void releaseMemory() override { LI.releaseMemory(); }
686
687 void print(raw_ostream &O, const Module* M = nullptr) const override;
688
689 void getAnalysisUsage(AnalysisUsage &AU) const override;
690
691677 /// removeLoop - This removes the specified top-level loop from this loop info
692678 /// object. The loop is not deleted, as it will presumably be inserted into
693679 /// another loop.
718704 void removeBlock(BasicBlock *BB) {
719705 LI.removeBlock(BB);
720706 }
707
708 void releaseMemory() { LI.releaseMemory(); }
721709
722710 /// updateUnloop - Update LoopInfo after removing the last backedge from a
723711 /// loop--now the "unloop". This updates the loop forest and parent loops for
747735 }
748736 };
749737
750
751738 // Allow clients to walk the list of nested loops...
752739 template <> struct GraphTraits {
753740 typedef const Loop NodeType;
775762 }
776763 };
777764
765 /// \brief The legacy pass manager's analysis pass to compute loop information.
766 class LoopInfoWrapperPass : public FunctionPass {
767 LoopInfo LI;
768
769 public:
770 static char ID; // Pass identification, replacement for typeid
771
772 LoopInfoWrapperPass() : FunctionPass(ID) {
773 initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry());
774 }
775
776 LoopInfo &getLoopInfo() { return LI; }
777 const LoopInfo &getLoopInfo() const { return LI; }
778
779 /// \brief Calculate the natural loop information for a given function.
780 bool runOnFunction(Function &F) override;
781
782 void verifyAnalysis() const override;
783
784 void releaseMemory() override { LI.releaseMemory(); }
785
786 void print(raw_ostream &O, const Module *M = nullptr) const override;
787
788 void getAnalysisUsage(AnalysisUsage &AU) const override;
789 };
790
778791 } // End llvm namespace
779792
780793 #endif
166166 void initializeLocalStackSlotPassPass(PassRegistry&);
167167 void initializeLoopDeletionPass(PassRegistry&);
168168 void initializeLoopExtractorPass(PassRegistry&);
169 void initializeLoopInfoPass(PassRegistry&);
169 void initializeLoopInfoWrapperPassPass(PassRegistry&);
170170 void initializeLoopInstSimplifyPass(PassRegistry&);
171171 void initializeLoopRotatePass(PassRegistry&);
172172 void initializeLoopSimplifyPass(PassRegistry&);
5252 initializeLazyValueInfoPass(Registry);
5353 initializeLibCallAliasAnalysisPass(Registry);
5454 initializeLintPass(Registry);
55 initializeLoopInfoPass(Registry);
55 initializeLoopInfoWrapperPassPass(Registry);
5656 initializeMemDepPrinterPass(Registry);
5757 initializeMemoryDependenceAnalysisPass(Registry);
5858 initializeModuleDebugInfoPrinterPass(Registry);
14351435 DominatorTreeWrapperPass *DTWP =
14361436 getAnalysisIfAvailable();
14371437 DominatorTree *DT = DTWP ? &DTWP->getDomTree() : nullptr;
1438 LoopInfo *LI = getAnalysisIfAvailable>();
1438 auto *LIWP = getAnalysisIfAvailable>();
1439 LoopInfo *LI = LIWP ? &LIWP->getLoopInfo() : nullptr;
14391440
14401441 // Make sure that the visited phis cannot reach the Value. This ensures that
14411442 // the Values cannot come from different iterations of a potential cycle the
107107 INITIALIZE_PASS_BEGIN(BlockFrequencyInfo, "block-freq",
108108 "Block Frequency Analysis", true, true)
109109 INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfo)
110 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
110 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
111111 INITIALIZE_PASS_END(BlockFrequencyInfo, "block-freq",
112112 "Block Frequency Analysis", true, true)
113113
122122
123123 void BlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
124124 AU.addRequired();
125 AU.addRequired>();
125 AU.addRequiredWrapperPass>();
126126 AU.setPreservesAll();
127127 }
128128
129129 bool BlockFrequencyInfo::runOnFunction(Function &F) {
130130 BranchProbabilityInfo &BPI = getAnalysis();
131 LoopInfo &LI = getAnalysis>();
131 LoopInfo &LI = getAnalysisWrapperPass>().getLoopInfo();
132132 if (!BFI)
133133 BFI.reset(new ImplType);
134134 BFI->doFunction(&F, &BPI, &LI);
2727
2828 INITIALIZE_PASS_BEGIN(BranchProbabilityInfo, "branch-prob",
2929 "Branch Probability Analysis", false, true)
30 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
30 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
3131 INITIALIZE_PASS_END(BranchProbabilityInfo, "branch-prob",
3232 "Branch Probability Analysis", false, true)
3333
483483 }
484484
485485 void BranchProbabilityInfo::getAnalysisUsage(AnalysisUsage &AU) const {
486 AU.addRequired>();
486 AU.addRequiredWrapperPass>();
487487 AU.setPreservesAll();
488488 }
489489
491491 DEBUG(dbgs() << "---- Branch Probability Info : " << F.getName()
492492 << " ----\n\n");
493493 LastF = &F; // Store the last function we ran on for printing.
494 LI = &getAnalysis>();
494 LI = &getAnalysisWrapperPass>().getLoopInfo();
495495 assert(PostDominatedByUnreachable.empty());
496496 assert(PostDominatedByColdCall.empty());
497497
5858
5959 void Delinearization::getAnalysisUsage(AnalysisUsage &AU) const {
6060 AU.setPreservesAll();
61 AU.addRequired>();
61 AU.addRequiredWrapperPass>();
6262 AU.addRequired();
6363 }
6464
6565 bool Delinearization::runOnFunction(Function &F) {
6666 this->F = &F;
6767 SE = &getAnalysis();
68 LI = &getAnalysis>();
68 LI = &getAnalysisWrapperPass>().getLoopInfo();
6969 return false;
7070 }
7171
140140 static const char delinearization_name[] = "Delinearization";
141141 INITIALIZE_PASS_BEGIN(Delinearization, DL_NAME, delinearization_name, true,
142142 true)
143 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
143 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
144144 INITIALIZE_PASS_END(Delinearization, DL_NAME, delinearization_name, true, true)
145145
146146 FunctionPass *llvm::createDelinearizationPass() { return new Delinearization; }
113113
114114 INITIALIZE_PASS_BEGIN(DependenceAnalysis, "da",
115115 "Dependence Analysis", true, true)
116 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
116 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
117117 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
118118 INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
119119 INITIALIZE_PASS_END(DependenceAnalysis, "da",
131131 this->F = &F;
132132 AA = &getAnalysis();
133133 SE = &getAnalysis();
134 LI = &getAnalysis>();
134 LI = &getAnalysisWrapperPass>().getLoopInfo();
135135 return false;
136136 }
137137
144144 AU.setPreservesAll();
145145 AU.addRequiredTransitive();
146146 AU.addRequiredTransitive();
147 AU.addRequiredTransitive>();
147 AU.addRequiredTransitiveWrapperPass>();
148148 }
149149
150150
3232 char IVUsers::ID = 0;
3333 INITIALIZE_PASS_BEGIN(IVUsers, "iv-users",
3434 "Induction Variable Users", false, true)
35 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
35 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
3636 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
3737 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
3838 INITIALIZE_PASS_END(IVUsers, "iv-users",
240240 }
241241
242242 void IVUsers::getAnalysisUsage(AnalysisUsage &AU) const {
243 AU.addRequired>();
243 AU.addRequiredWrapperPass>();
244244 AU.addRequired();
245245 AU.addRequired();
246246 AU.setPreservesAll();
249249 bool IVUsers::runOnLoop(Loop *l, LPPassManager &LPM) {
250250
251251 L = l;
252 LI = &getAnalysis>();
252 LI = &getAnalysisWrapperPass>().getLoopInfo();
253253 DT = &getAnalysis().getDomTree();
254254 SE = &getAnalysis();
255255 DataLayoutPass *DLP = getAnalysisIfAvailable();
4343 static cl::opt
4444 VerifyLoopInfoX("verify-loop-info", cl::location(VerifyLoopInfo),
4545 cl::desc("Verify loop info (time consuming)"));
46
47 char LoopInfo::ID = 0;
48 INITIALIZE_PASS_BEGIN(LoopInfo, "loops", "Natural Loop Information", true, true)
49 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
50 INITIALIZE_PASS_END(LoopInfo, "loops", "Natural Loop Information", true, true)
5146
5247 // Loop identifier metadata name.
5348 static const char *const LoopMDName = "llvm.loop";
608603 return NearLoop;
609604 }
610605
611 //===----------------------------------------------------------------------===//
612 // LoopInfo implementation
613 //
614 bool LoopInfo::runOnFunction(Function &) {
615 releaseMemory();
616 LI.Analyze(getAnalysis().getDomTree());
617 return false;
618 }
619
620606 /// updateUnloop - The last backedge has been removed from a loop--now the
621607 /// "unloop". Find a new parent for the blocks contained within unloop and
622608 /// update the loop tree. We don't necessarily have valid dominators at this
679665 }
680666 }
681667
682 void LoopInfo::verifyAnalysis() const {
683 // LoopInfo is a FunctionPass, but verifying every loop in the function
684 // each time verifyAnalysis is called is very expensive. The
668 //===----------------------------------------------------------------------===//
669 // LoopInfo implementation
670 //
671
672 char LoopInfoWrapperPass::ID = 0;
673 INITIALIZE_PASS_BEGIN(LoopInfoWrapperPass, "loops", "Natural Loop Information",
674 true, true)
675 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
676 INITIALIZE_PASS_END(LoopInfoWrapperPass, "loops", "Natural Loop Information",
677 true, true)
678
679 bool LoopInfoWrapperPass::runOnFunction(Function &) {
680 releaseMemory();
681 LI.getBase().Analyze(getAnalysis().getDomTree());
682 return false;
683 }
684
685 void LoopInfoWrapperPass::verifyAnalysis() const {
686 // LoopInfoWrapperPass is a FunctionPass, but verifying every loop in the
687 // function each time verifyAnalysis is called is very expensive. The
685688 // -verify-loop-info option can enable this. In order to perform some
686 // checking by default, LoopPass has been taught to call verifyLoop
687 // manually during loop pass sequences.
689 // checking by default, LoopPass has been taught to call verifyLoop manually
690 // during loop pass sequences.
688691
689692 if (!VerifyLoopInfo) return;
690693
691694 DenseSet Loops;
692 for (iterator I = begin(), E = end(); I != E; ++I) {
695 for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I) {
693696 assert(!(*I)->getParentLoop() && "Top-level loop has a parent!");
694697 (*I)->verifyLoopNest(&Loops);
695698 }
696699
697700 // Verify that blocks are mapped to valid loops.
698 for (DenseMap::const_iterator I = LI.BBMap.begin(),
699 E = LI.BBMap.end(); I != E; ++I) {
700 assert(Loops.count(I->second) && "orphaned loop");
701 assert(I->second->contains(I->first) && "orphaned block");
702 }
703 }
704
705 void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
701 for (auto &Entry : LI.LI.BBMap) {
702 BasicBlock *BB = Entry.first;
703 Loop *L = Entry.second;
704 assert(Loops.count(L) && "orphaned loop");
705 assert(L->contains(BB) && "orphaned block");
706 }
707 }
708
709 void LoopInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
706710 AU.setPreservesAll();
707711 AU.addRequired();
708712 }
709713
710 void LoopInfo::print(raw_ostream &OS, const Module*) const {
711 LI.print(OS);
714 void LoopInfoWrapperPass::print(raw_ostream &OS, const Module *) const {
715 LI.LI.print(OS);
712716 }
713717
714718 //===----------------------------------------------------------------------===//
186186 void LPPassManager::getAnalysisUsage(AnalysisUsage &Info) const {
187187 // LPPassManager needs LoopInfo. In the long term LoopInfo class will
188188 // become part of LPPassManager.
189 Info.addRequired>();
189 Info.addRequiredWrapperPass>();
190190 Info.setPreservesAll();
191191 }
192192
193193 /// run - Execute all of the passes scheduled for execution. Keep track of
194194 /// whether any of the passes modifies the function, and if so, return true.
195195 bool LPPassManager::runOnFunction(Function &F) {
196 LI = &getAnalysis>();
196 auto &LIWP = getAnalysis>();
197 LI = &LIWP.getLoopInfo();
197198 bool Changed = false;
198199
199200 // Collect inherited analysis from Module level pass manager.
261262 // loop in the function every time. That level of checking can be
262263 // enabled with the -verify-loop-info option.
263264 {
264 TimeRegion PassTimer(getPassTimer(LI));
265 TimeRegion PassTimer(getPassTimer(&LIWP));
265266 CurrentLoop->verifyLoop();
266267 }
267268
116116 INITIALIZE_PASS_BEGIN(ScalarEvolution, "scalar-evolution",
117117 "Scalar Evolution Analysis", false, true)
118118 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
119 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
119 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
120120 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
121121 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
122122 INITIALIZE_PASS_END(ScalarEvolution, "scalar-evolution",
78667866 bool ScalarEvolution::runOnFunction(Function &F) {
78677867 this->F = &F;
78687868 AC = &getAnalysis().getAssumptionCache(F);
7869 LI = &getAnalysis>();
7869 LI = &getAnalysisWrapperPass>().getLoopInfo();
78707870 DataLayoutPass *DLP = getAnalysisIfAvailable();
78717871 DL = DLP ? &DLP->getDataLayout() : nullptr;
78727872 TLI = &getAnalysis().getTLI();
79077907 void ScalarEvolution::getAnalysisUsage(AnalysisUsage &AU) const {
79087908 AU.setPreservesAll();
79097909 AU.addRequired();
7910 AU.addRequiredTransitive>();
7910 AU.addRequiredTransitiveWrapperPass>();
79117911 AU.addRequiredTransitive();
79127912 AU.addRequired();
79137913 }
9393 bool runOnFunction(Function &F) override;
9494
9595 void getAnalysisUsage(AnalysisUsage &AU) const override {
96 AU.addRequired();
97 AU.addPreserved>();
96 AU.addRequired>();
97 AU.addPreserved();
9898 AU.addRequired();
9999 AU.addPreserved();
100100 AU.addRequired();
145145 INITIALIZE_PASS_BEGIN(PPCCTRLoops, "ppc-ctr-loops", "PowerPC CTR Loops",
146146 false, false)
147147 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
148 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
148 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
149149 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
150150 INITIALIZE_PASS_END(PPCCTRLoops, "ppc-ctr-loops", "PowerPC CTR Loops",
151151 false, false)
167167 #endif // NDEBUG
168168
169169 bool PPCCTRLoops::runOnFunction(Function &F) {
170 LI = &getAnalysis>();
170 LI = &getAnalysisWrapperPass>().getLoopInfo();
171171 SE = &getAnalysis();
172172 DT = &getAnalysis().getDomTree();
173173 DataLayoutPass *DLP = getAnalysisIfAvailable();
798798 // If the incoming non-constant value is in I's block, we will remove one
799799 // instruction, but insert another equivalent one, leading to infinite
800800 // instcombine.
801 auto *LIWP = getAnalysisIfAvailable();
801802 if (isPotentiallyReachable(I.getParent(), NonConstBB, DT,
802 getAnalysisIfAvailable()))
803 LIWP ? &LIWP->getLoopInfo() : nullptr))
803804 return nullptr;
804805 }
805806
5757 AU.addRequired();
5858
5959 AU.setPreservesCFG();
60 AU.addPreserved>();
60 AU.addPreservedWrapperPass>();
6161 AU.addPreserved();
6262 AU.addPreserved();
6363 }
9090
9191 void getAnalysisUsage(AnalysisUsage &AU) const override {
9292 AU.addRequired();
93 AU.addRequired>();
93 AU.addRequiredWrapperPass>();
9494 AU.addRequired();
9595 AU.addRequiredID(LoopSimplifyID);
9696 AU.addRequiredID(LCSSAID);
125125 INITIALIZE_PASS_BEGIN(IndVarSimplify, "indvars",
126126 "Induction Variable Simplification", false, false)
127127 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
128 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
128 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
129129 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
130130 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
131131 INITIALIZE_PASS_DEPENDENCY(LCSSA)
19281928 if (!L->isLoopSimplifyForm())
19291929 return false;
19301930
1931 LI = &getAnalysis>();
1931 LI = &getAnalysisWrapperPass>().getLoopInfo();
19321932 SE = &getAnalysis();
19331933 DT = &getAnalysis().getDomTree();
19341934 DataLayoutPass *DLP = getAnalysisIfAvailable();
168168 }
169169
170170 void getAnalysisUsage(AnalysisUsage &AU) const override {
171 AU.addRequired>();
171 AU.addRequiredWrapperPass>();
172172 AU.addRequiredID(LoopSimplifyID);
173173 AU.addRequiredID(LCSSAID);
174174 AU.addRequired();
11751175 if (!SafeIterRange.hasValue())
11761176 return false;
11771177
1178 LoopConstrainer LC(*L, getAnalysis>(), SE, SafeIterRange.getValue());
1178 LoopConstrainer LC(*L, getAnalysisWrapperPass>().getLoopInfo(), SE,
1179 SafeIterRange.getValue());
11791180 bool Changed = LC.run();
11801181
11811182 if (Changed) {
8585 void getAnalysisUsage(AnalysisUsage &AU) const override {
8686 AU.setPreservesCFG();
8787 AU.addRequired();
88 AU.addRequired>();
88 AU.addRequiredWrapperPass>();
8989 AU.addRequiredID(LoopSimplifyID);
9090 AU.addPreservedID(LoopSimplifyID);
9191 AU.addRequiredID(LCSSAID);
209209 char LICM::ID = 0;
210210 INITIALIZE_PASS_BEGIN(LICM, "licm", "Loop Invariant Code Motion", false, false)
211211 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
212 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
212 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
213213 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
214214 INITIALIZE_PASS_DEPENDENCY(LCSSA)
215215 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
230230 Changed = false;
231231
232232 // Get our Loop and Alias Analysis information...
233 LI = &getAnalysis>();
233 LI = &getAnalysisWrapperPass>().getLoopInfo();
234234 AA = &getAnalysis();
235235 DT = &getAnalysis().getDomTree();
236236
3838
3939 void getAnalysisUsage(AnalysisUsage &AU) const override {
4040 AU.addRequired();
41 AU.addRequired>();
41 AU.addRequiredWrapperPass>();
4242 AU.addRequired();
4343 AU.addRequiredID(LoopSimplifyID);
4444 AU.addRequiredID(LCSSAID);
4545
4646 AU.addPreserved();
4747 AU.addPreserved();
48 AU.addPreserved>();
48 AU.addPreservedWrapperPass>();
4949 AU.addPreservedID(LoopSimplifyID);
5050 AU.addPreservedID(LCSSAID);
5151 }
6262 INITIALIZE_PASS_BEGIN(LoopDeletion, "loop-deletion",
6363 "Delete dead loops", false, false)
6464 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
65 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
65 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
6666 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
6767 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
6868 INITIALIZE_PASS_DEPENDENCY(LCSSA)
235235
236236 // Finally, the blocks from loopinfo. This has to happen late because
237237 // otherwise our loop iterators won't work.
238 LoopInfo &loopInfo = getAnalysis>();
238 LoopInfo &loopInfo = getAnalysisWrapperPass>().getLoopInfo();
239239 SmallPtrSet blocks;
240240 blocks.insert(L->block_begin(), L->block_end());
241241 for (BasicBlock *BB : blocks)
162162 /// loop preheaders be inserted into the CFG.
163163 ///
164164 void getAnalysisUsage(AnalysisUsage &AU) const override {
165 AU.addRequired();
166 AU.addPreserved>();
165 AU.addRequired>();
166 AU.addPreserved();
167167 AU.addRequiredID(LoopSimplifyID);
168168 AU.addPreservedID(LoopSimplifyID);
169169 AU.addRequiredID(LCSSAID);
217217 char LoopIdiomRecognize::ID = 0;
218218 INITIALIZE_PASS_BEGIN(LoopIdiomRecognize, "loop-idiom", "Recognize loop idioms",
219219 false, false)
220 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
220 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
221221 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
222222 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
223223 INITIALIZE_PASS_DEPENDENCY(LCSSA)
668668 // set DT
669669 (void)getDominatorTree();
670670
671 LoopInfo &LI = getAnalysis>();
671 LoopInfo &LI = getAnalysisWrapperPass>().getLoopInfo();
672672 TLI = &getAnalysis().getTLI();
673673
674674 // set TLI
4242 void getAnalysisUsage(AnalysisUsage &AU) const override {
4343 AU.setPreservesCFG();
4444 AU.addRequired();
45 AU.addRequired>();
45 AU.addRequiredWrapperPass>();
4646 AU.addRequiredID(LoopSimplifyID);
4747 AU.addPreservedID(LoopSimplifyID);
4848 AU.addPreservedID(LCSSAID);
5858 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
5959 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
6060 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
61 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
61 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
6262 INITIALIZE_PASS_DEPENDENCY(LCSSA)
6363 INITIALIZE_PASS_END(LoopInstSimplify, "loop-instsimplify",
6464 "Simplify instructions in loops", false, false)
7474 DominatorTreeWrapperPass *DTWP =
7575 getAnalysisIfAvailable();
7676 DominatorTree *DT = DTWP ? &DTWP->getDomTree() : nullptr;
77 LoopInfo *LI = &getAnalysis>();
77 LoopInfo *LI = &getAnalysisWrapperPass>().getLoopInfo();
7878 DataLayoutPass *DLP = getAnalysisIfAvailable();
7979 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
8080 const TargetLibraryInfo *TLI =
129129
130130 void getAnalysisUsage(AnalysisUsage &AU) const override {
131131 AU.addRequired();
132 AU.addRequired();
133 AU.addPreserved>();
132 AU.addRequired>();
133 AU.addPreserved();
134134 AU.addRequired();
135135 AU.addPreserved();
136136 AU.addRequired();
338338 char LoopReroll::ID = 0;
339339 INITIALIZE_PASS_BEGIN(LoopReroll, "loop-reroll", "Reroll loops", false, false)
340340 INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
341 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
341 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
342342 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
343343 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
344344 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
11281128 return false;
11291129
11301130 AA = &getAnalysis();
1131 LI = &getAnalysis>();
1131 LI = &getAnalysisWrapperPass>().getLoopInfo();
11321132 SE = &getAnalysis();
11331133 TLI = &getAnalysis().getTLI();
11341134 DataLayoutPass *DLP = getAnalysisIfAvailable();
5555 void getAnalysisUsage(AnalysisUsage &AU) const override {
5656 AU.addRequired();
5757 AU.addPreserved();
58 AU.addRequired();
59 AU.addPreserved>();
58 AU.addRequired>();
59 AU.addPreserved();
6060 AU.addRequiredID(LoopSimplifyID);
6161 AU.addPreservedID(LoopSimplifyID);
6262 AU.addRequiredID(LCSSAID);
8181 INITIALIZE_PASS_BEGIN(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
8282 INITIALIZE_AG_DEPENDENCY(TargetTransformInfo)
8383 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
84 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
84 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
8585 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
8686 INITIALIZE_PASS_DEPENDENCY(LCSSA)
8787 INITIALIZE_PASS_END(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
9999 // Save the loop metadata.
100100 MDNode *LoopMD = L->getLoopID();
101101
102 LI = &getAnalysis>();
102 LI = &getAnalysisWrapperPass>().getLoopInfo();
103103 TTI = &getAnalysis();
104104 AC = &getAnalysis().getAssumptionCache(
105105 *L->getHeader()->getParent());
48624862 LSRInstance::LSRInstance(Loop *L, Pass *P)
48634863 : IU(P->getAnalysis()), SE(P->getAnalysis()),
48644864 DT(P->getAnalysis().getDomTree()),
4865 LI(P->getAnalysis>()),
4865 LI(P->getAnalysisWrapperPass>().getLoopInfo()),
48664866 TTI(P->getAnalysis()), L(L), Changed(false),
48674867 IVIncInsertPos(nullptr) {
48684868 // If LoopSimplify form is not available, stay out of trouble.
50445044 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
50455045 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
50465046 INITIALIZE_PASS_DEPENDENCY(IVUsers)
5047 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
5047 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
50485048 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
50495049 INITIALIZE_PASS_END(LoopStrengthReduce, "loop-reduce",
50505050 "Loop Strength Reduction", false, false)
50635063 // many analyses if they are around.
50645064 AU.addPreservedID(LoopSimplifyID);
50655065
5066 AU.addRequired();
5067 AU.addPreserved>();
5066 AU.addRequired>();
5067 AU.addPreserved();
50685068 AU.addRequiredID(LoopSimplifyID);
50695069 AU.addRequired();
50705070 AU.addPreserved();
104104 ///
105105 void getAnalysisUsage(AnalysisUsage &AU) const override {
106106 AU.addRequired();
107 AU.addRequired();
108 AU.addPreserved>();
107 AU.addRequired>();
108 AU.addPreserved();
109109 AU.addRequiredID(LoopSimplifyID);
110110 AU.addPreservedID(LoopSimplifyID);
111111 AU.addRequiredID(LCSSAID);
187187 INITIALIZE_AG_DEPENDENCY(TargetTransformInfo)
188188 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
189189 INITIALIZE_PASS_DEPENDENCY(FunctionTargetTransformInfo)
190 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
190 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
191191 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
192192 INITIALIZE_PASS_DEPENDENCY(LCSSA)
193193 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
362362 if (skipOptnoneFunction(L))
363363 return false;
364364
365 LoopInfo *LI = &getAnalysis>();
365 LoopInfo *LI = &getAnalysisWrapperPass>().getLoopInfo();
366366 ScalarEvolution *SE = &getAnalysis();
367367 const TargetTransformInfo &TTI = getAnalysis();
368368 const FunctionTargetTransformInfo &FTTI =
169169 AU.addRequired();
170170 AU.addRequiredID(LoopSimplifyID);
171171 AU.addPreservedID(LoopSimplifyID);
172 AU.addRequired();
173 AU.addPreserved>();
172 AU.addRequired>();
173 AU.addPreserved();
174174 AU.addRequiredID(LCSSAID);
175175 AU.addPreservedID(LCSSAID);
176176 AU.addPreserved();
335335 INITIALIZE_AG_DEPENDENCY(TargetTransformInfo)
336336 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
337337 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
338 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
338 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
339339 INITIALIZE_PASS_DEPENDENCY(LCSSA)
340340 INITIALIZE_PASS_END(LoopUnswitch, "loop-unswitch", "Unswitch loops",
341341 false, false)
386386
387387 AC = &getAnalysis().getAssumptionCache(
388388 *L->getHeader()->getParent());
389 LI = &getAnalysis>();
389 LI = &getAnalysisWrapperPass>().getLoopInfo();
390390 LPM = &LPM_Ref;
391391 DominatorTreeWrapperPass *DTWP =
392392 getAnalysisIfAvailable();
9494
9595 void getAnalysisUsage(AnalysisUsage &AU) const override {
9696 AU.setPreservesCFG();
97 AU.addRequired>();
97 AU.addRequiredWrapperPass>();
9898 AU.addRequired();
9999 AU.addRequired();
100100 }
730730 "Sample Profile loader", false, false)
731731 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
732732 INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
733 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
733 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
734734 INITIALIZE_PASS_DEPENDENCY(AddDiscriminators)
735735 INITIALIZE_PASS_END(SampleProfileLoader, "sample-profile",
736736 "Sample Profile loader", false, false)
761761
762762 DT = &getAnalysis().getDomTree();
763763 PDT = &getAnalysis();
764 LI = &getAnalysis>();
764 LI = &getAnalysisWrapperPass>().getLoopInfo();
765765 Ctx = &F.getParent()->getContext();
766766 Samples = Reader->getSamplesFor(F);
767767 if (!Samples->empty())
4949 FunctionPass::getAnalysisUsage(AU);
5050 AU.addRequired();
5151 AU.addRequired();
52 AU.addRequired>();
52 AU.addRequiredWrapperPass>();
5353 AU.addPreserved();
54 AU.addPreserved>();
54 AU.addPreservedWrapperPass>();
5555 }
5656 private:
5757 bool ProcessBlock(BasicBlock &BB);
6363
6464 char Sinking::ID = 0;
6565 INITIALIZE_PASS_BEGIN(Sinking, "sink", "Code sinking", false, false)
66 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
66 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
6767 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
6868 INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
6969 INITIALIZE_PASS_END(Sinking, "sink", "Code sinking", false, false)
9797
9898 bool Sinking::runOnFunction(Function &F) {
9999 DT = &getAnalysis().getDomTree();
100 LI = &getAnalysis>();
100 LI = &getAnalysisWrapperPass>().getLoopInfo();
101101 AA = &getAnalysis();
102102 DataLayoutPass *DLP = getAnalysisIfAvailable();
103103 DL = DLP ? &DLP->getDataLayout() : nullptr;
248248 void getAnalysisUsage(AnalysisUsage &AU) const override {
249249 AU.addRequiredID(LowerSwitchID);
250250 AU.addRequired();
251 AU.addRequired>();
251 AU.addRequiredWrapperPass>();
252252 AU.addPreserved();
253253 RegionPass::getAnalysisUsage(AU);
254254 }
865865 ParentRegion = R;
866866
867867 DT = &getAnalysis().getDomTree();
868 LI = &getAnalysis>();
868 LI = &getAnalysisWrapperPass>().getLoopInfo();
869869
870870 orderNodes();
871871 collectInfos();
179179 DT.eraseNode(BB);
180180 }
181181
182 if (LoopInfo *LI = P->getAnalysisIfAvailable())
183 LI->removeBlock(BB);
182 if (auto *LIWP = P->getAnalysisIfAvailable())
183 LIWP->getLoopInfo().removeBlock(BB);
184184
185185 if (MemoryDependenceAnalysis *MD =
186186 P->getAnalysisIfAvailable())
289289
290290 // The new block lives in whichever loop the old one did. This preserves
291291 // LCSSA as well, because we force the split point to be after any PHI nodes.
292 if (LoopInfo *LI = P->getAnalysisIfAvailable())
293 if (Loop *L = LI->getLoopFor(Old))
294 L->addBasicBlockToLoop(New, LI->getBase());
292 if (auto *LIWP = P->getAnalysisIfAvailable()) {
293 LoopInfo &LI = LIWP->getLoopInfo();
294 if (Loop *L = LI.getLoopFor(Old))
295 L->addBasicBlockToLoop(New, LI.getBase());
296 }
295297
296298 if (DominatorTreeWrapperPass *DTWP =
297299 P->getAnalysisIfAvailable()) {
320322 Pass *P, bool &HasLoopExit) {
321323 if (!P) return;
322324
323 LoopInfo *LI = P->getAnalysisIfAvailable>();
325 auto *LIWP = P->getAnalysisIfAvailable>();
326 LoopInfo *LI = LIWP ? &LIWP->getLoopInfo() : nullptr;
324327 Loop *L = LI ? LI->getLoopFor(OldBB) : nullptr;
325328
326329 // If we need to preserve loop analyses, collect some information about how
4747
4848 void getAnalysisUsage(AnalysisUsage &AU) const override {
4949 AU.addPreserved();
50 AU.addPreserved>();
50 AU.addPreservedWrapperPass>();
5151
5252 // No loop canonicalization guarantees are broken by this pass.
5353 AU.addPreservedID(LoopSimplifyID);
198198 DominatorTreeWrapperPass *DTWP =
199199 P->getAnalysisIfAvailable();
200200 DominatorTree *DT = DTWP ? &DTWP->getDomTree() : nullptr;
201 LoopInfo *LI = P->getAnalysisIfAvailable>();
201 auto *LIWP = P->getAnalysisIfAvailable>();
202 LoopInfo *LI = LIWP ? &LIWP->getLoopInfo() : nullptr;
202203
203204 // If we have nothing to update, just return.
204205 if (!DT && !LI)
293293 AU.setPreservesCFG();
294294
295295 AU.addRequired();
296 AU.addRequired>();
296 AU.addRequiredWrapperPass>();
297297 AU.addPreservedID(LoopSimplifyID);
298298 AU.addPreserved();
299299 AU.addPreserved();
307307 char LCSSA::ID = 0;
308308 INITIALIZE_PASS_BEGIN(LCSSA, "lcssa", "Loop-Closed SSA Form Pass", false, false)
309309 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
310 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
310 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
311311 INITIALIZE_PASS_END(LCSSA, "lcssa", "Loop-Closed SSA Form Pass", false, false)
312312
313313 Pass *llvm::createLCSSAPass() { return new LCSSA(); }
317317 /// Process all loops in the function, inner-most out.
318318 bool LCSSA::runOnFunction(Function &F) {
319319 bool Changed = false;
320 LI = &getAnalysis>();
320 LI = &getAnalysisWrapperPass>().getLoopInfo();
321321 DT = &getAnalysis().getDomTree();
322322 SE = getAnalysisIfAvailable();
323323
761761 AU.addRequired();
762762 AU.addPreserved();
763763
764 AU.addRequired();
765 AU.addPreserved>();
764 AU.addRequired>();
765 AU.addPreserved();
766766
767767 AU.addPreserved();
768768 AU.addPreserved();
780780 "Canonicalize natural loops", false, false)
781781 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
782782 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
783 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
783 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
784784 INITIALIZE_PASS_END(LoopSimplify, "loop-simplify",
785785 "Canonicalize natural loops", false, false)
786786
794794 bool LoopSimplify::runOnFunction(Function &F) {
795795 bool Changed = false;
796796 AA = getAnalysisIfAvailable();
797 LI = &getAnalysis>();
797 LI = &getAnalysisWrapperPass>().getLoopInfo();
798798 DT = &getAnalysis().getDomTree();
799799 SE = getAnalysisIfAvailable();
800800 DataLayoutPass *DLP = getAnalysisIfAvailable();
5454 bool Changed;
5555
5656 public:
57 SimplifyIndvar(Loop *Loop, ScalarEvolution *SE, LPPassManager *LPM,
58 SmallVectorImpl &Dead, IVUsers *IVU = nullptr) :
59 L(Loop),
60 LI(LPM->getAnalysisIfAvailable()),
61 SE(SE),
62 DeadInsts(Dead),
63 Changed(false) {
64 DataLayoutPass *DLP = LPM->getAnalysisIfAvailable();
65 DL = DLP ? &DLP->getDataLayout() : nullptr;
57 SimplifyIndvar(Loop *Loop, ScalarEvolution *SE, LoopInfo *LI,
58 const DataLayout *DL, SmallVectorImpl &Dead,
59 IVUsers *IVU = nullptr)
60 : L(Loop), LI(LI), SE(SE), DL(DL), DeadInsts(Dead), Changed(false) {
6661 assert(LI && "IV simplification requires LoopInfo");
6762 }
6863
561556 bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, LPPassManager *LPM,
562557 SmallVectorImpl &Dead, IVVisitor *V)
563558 {
564 LoopInfo *LI = &LPM->getAnalysis();
565 SimplifyIndvar SIV(LI->getLoopFor(CurrIV->getParent()), SE, LPM, Dead);
559 DataLayoutPass *DLP = LPM->getAnalysisIfAvailable();
560 LoopInfo *LI = &LPM->getAnalysis().getLoopInfo();
561 SimplifyIndvar SIV(LI->getLoopFor(CurrIV->getParent()), SE, LI,
562 DLP ? &DLP->getDataLayout() : nullptr, Dead);
566563 SIV.simplifyUsers(CurrIV, V);
567564 return SIV.hasChanged();
568565 }
12761276 SE = &getAnalysis();
12771277 DataLayoutPass *DLP = getAnalysisIfAvailable();
12781278 DL = DLP ? &DLP->getDataLayout() : nullptr;
1279 LI = &getAnalysis>();
1279 LI = &getAnalysisWrapperPass>().getLoopInfo();
12801280 TTI = &getAnalysis();
12811281 DT = &getAnalysis().getDomTree();
12821282 BFI = &getAnalysis();
14951495 AU.addRequiredID(LCSSAID);
14961496 AU.addRequired();
14971497 AU.addRequired();
1498 AU.addRequired>();
1498 AU.addRequiredWrapperPass>();
14991499 AU.addRequired();
15001500 AU.addRequired();
15011501 AU.addRequired();
1502 AU.addPreserved>();
1502 AU.addPreservedWrapperPass>();
15031503 AU.addPreserved();
15041504 AU.addPreserved();
15051505 }
61596159 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
61606160 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
61616161 INITIALIZE_PASS_DEPENDENCY(LCSSA)
6162 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
6162 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
61636163 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
61646164 INITIALIZE_PASS_END(LoopVectorize, LV_NAME, lv_name, false, false)
61656165
28922892 auto *TLIP = getAnalysisIfAvailable();
28932893 TLI = TLIP ? &TLIP->getTLI() : nullptr;
28942894 AA = &getAnalysis();
2895 LI = &getAnalysis>();
2895 LI = &getAnalysisWrapperPass>().getLoopInfo();
28962896 DT = &getAnalysis().getDomTree();
28972897 AC = &getAnalysis().getAssumptionCache(F);
28982898
29512951 AU.addRequired();
29522952 AU.addRequired();
29532953 AU.addRequired();
2954 AU.addRequired>();
2954 AU.addRequiredWrapperPass>();
29552955 AU.addRequired();
2956 AU.addPreserved>();
2956 AU.addPreservedWrapperPass>();
29572957 AU.addPreserved();
29582958 AU.setPreservesCFG();
29592959 }
7171 PassInfo *PI = new PassInfo("isPotentiallyReachable testing pass",
7272 "", &ID, nullptr, true, true);
7373 PassRegistry::getPassRegistry()->registerPass(*PI, false);
74 initializeLoopInfoPass(*PassRegistry::getPassRegistry());
74 initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry());
7575 initializeDominatorTreeWrapperPassPass(
7676 *PassRegistry::getPassRegistry());
7777 return 0;
7979
8080 void getAnalysisUsage(AnalysisUsage &AU) const {
8181 AU.setPreservesAll();
82 AU.addRequired>();
82 AU.addRequiredWrapperPass>();
8383 AU.addRequired();
8484 }
8585
8787 if (!F.hasName() || F.getName() != "test")
8888 return false;
8989
90 LoopInfo *LI = &getAnalysis>();
90 LoopInfo *LI = &getAnalysisWrapperPass>().getLoopInfo();
9191 DominatorTree *DT =
9292 &getAnalysis().getDomTree();
9393 EXPECT_EQ(isPotentiallyReachable(A, B, nullptr, nullptr),
553553 INITIALIZE_PASS_END(CGPass, "cgp","cgp", false, false)
554554 INITIALIZE_PASS(FPass, "fp","fp", false, false)
555555 INITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false)
556 INITIALIZE_PASS_DEPENDENCY(LoopInfo)
556 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
557557 INITIALIZE_PASS_END(LPass, "lp","lp", false, false)
558558 INITIALIZE_PASS(BPass, "bp","bp", false, false)