@@ -653,13 +653,14 @@ class MemoryInstructionDependences {
653653class LoopDistributeForLoop {
654654public:
655655 LoopDistributeForLoop (Loop *L, Function *F, LoopInfo *LI, DominatorTree *DT,
656- ScalarEvolution *SE, OptimizationRemarkEmitter *ORE)
657- : L(L), F(F), LI(LI), DT(DT), SE(SE), ORE(ORE) {
656+ ScalarEvolution *SE, LoopAccessInfoManager &LAIs,
657+ OptimizationRemarkEmitter *ORE)
658+ : L(L), F(F), LI(LI), DT(DT), SE(SE), LAIs(LAIs), ORE(ORE) {
658659 setForced ();
659660 }
660661
661662 // / Try to distribute an inner-most loop.
662- bool processLoop (std::function< const LoopAccessInfo &(Loop &)> &GetLAA ) {
663+ bool processLoop () {
663664 assert (L->isInnermost () && " Only process inner loops." );
664665
665666 LLVM_DEBUG (dbgs () << " \n LDist: In \" "
@@ -677,7 +678,7 @@ class LoopDistributeForLoop {
677678
678679 BasicBlock *PH = L->getLoopPreheader ();
679680
680- LAI = &GetLAA (*L);
681+ LAI = &LAIs. getInfo (*L);
681682
682683 // Currently, we only distribute to isolate the part of the loop with
683684 // dependence cycles to enable partial vectorization.
@@ -953,6 +954,7 @@ class LoopDistributeForLoop {
953954 const LoopAccessInfo *LAI = nullptr ;
954955 DominatorTree *DT;
955956 ScalarEvolution *SE;
957+ LoopAccessInfoManager &LAIs;
956958 OptimizationRemarkEmitter *ORE;
957959
958960 // / Indicates whether distribution is forced to be enabled/disabled for
@@ -969,7 +971,7 @@ class LoopDistributeForLoop {
969971// / Shared implementation between new and old PMs.
970972static bool runImpl (Function &F, LoopInfo *LI, DominatorTree *DT,
971973 ScalarEvolution *SE, OptimizationRemarkEmitter *ORE,
972- std::function< const LoopAccessInfo &(Loop &)> &GetLAA ) {
974+ LoopAccessInfoManager &LAIs ) {
973975 // Build up a worklist of inner-loops to vectorize. This is necessary as the
974976 // act of distributing a loop creates new loops and can invalidate iterators
975977 // across the loops.
@@ -984,12 +986,12 @@ static bool runImpl(Function &F, LoopInfo *LI, DominatorTree *DT,
984986 // Now walk the identified inner loops.
985987 bool Changed = false ;
986988 for (Loop *L : Worklist) {
987- LoopDistributeForLoop LDL (L, &F, LI, DT, SE, ORE);
989+ LoopDistributeForLoop LDL (L, &F, LI, DT, SE, LAIs, ORE);
988990
989991 // If distribution was forced for the specific loop to be
990992 // enabled/disabled, follow that. Otherwise use the global flag.
991993 if (LDL.isForced ().value_or (EnableLoopDistribute))
992- Changed |= LDL.processLoop (GetLAA );
994+ Changed |= LDL.processLoop ();
993995 }
994996
995997 // Process each loop nest in the function.
@@ -1013,14 +1015,12 @@ class LoopDistributeLegacy : public FunctionPass {
10131015 return false ;
10141016
10151017 auto *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo ();
1016- auto *LAA = &getAnalysis<LoopAccessLegacyAnalysis>();
10171018 auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree ();
10181019 auto *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE ();
10191020 auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE ();
1020- std::function<const LoopAccessInfo &(Loop &)> GetLAA =
1021- [&](Loop &L) -> const LoopAccessInfo & { return LAA->getInfo (&L); };
1021+ auto &LAIs = getAnalysis<LoopAccessLegacyAnalysis>().getLAIs ();
10221022
1023- return runImpl (F, LI, DT, SE, ORE, GetLAA );
1023+ return runImpl (F, LI, DT, SE, ORE, LAIs );
10241024 }
10251025
10261026 void getAnalysisUsage (AnalysisUsage &AU) const override {
@@ -1045,10 +1045,7 @@ PreservedAnalyses LoopDistributePass::run(Function &F,
10451045 auto &ORE = AM.getResult <OptimizationRemarkEmitterAnalysis>(F);
10461046
10471047 LoopAccessInfoManager &LAIs = AM.getResult <LoopAccessAnalysis>(F);
1048- std::function<const LoopAccessInfo &(Loop &)> GetLAA =
1049- [&](Loop &L) -> const LoopAccessInfo & { return LAIs.getInfo (L); };
1050-
1051- bool Changed = runImpl (F, &LI, &DT, &SE, &ORE, GetLAA);
1048+ bool Changed = runImpl (F, &LI, &DT, &SE, &ORE, LAIs);
10521049 if (!Changed)
10531050 return PreservedAnalyses::all ();
10541051 PreservedAnalyses PA;
0 commit comments