From 6d98f3a6dfa392b2c87a0e55d0d2aa4685faba0d Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 14 Nov 2022 15:28:09 +0100 Subject: [PATCH] [LoopVersioningLICM] Clarify scope of AST (NFC) Make it clearer that the AST is only temporarily used during the legality check, and does not have to survive into the transformation phase. --- llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp | 45 +++++++++++------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp b/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp index 65df1aa..38ebfe5 100644 --- a/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp +++ b/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp @@ -147,13 +147,13 @@ struct LoopVersioningLICM { // LoopAccessInfo will take place only when it's necessary. LoopVersioningLICM(AliasAnalysis *AA, ScalarEvolution *SE, OptimizationRemarkEmitter *ORE, - LoopAccessInfoManager &LAIs, + LoopAccessInfoManager &LAIs, LoopInfo &LI, Loop *CurLoop) - : AA(AA), SE(SE), LAIs(LAIs), CurLoop(CurLoop), AST(*AA), + : AA(AA), SE(SE), LAIs(LAIs), LI(LI), CurLoop(CurLoop), LoopDepthThreshold(LVLoopDepthThreshold), InvariantThreshold(LVInvarThreshold), ORE(ORE) {} - bool run(LoopInfo *LI, DominatorTree *DT); + bool run(DominatorTree *DT); private: // Current AliasAnalysis information @@ -168,12 +168,11 @@ private: // Proxy for retrieving LoopAccessInfo. LoopAccessInfoManager &LAIs; + LoopInfo &LI; + // The current loop we are working on. Loop *CurLoop; - // AliasSet information for the current loop. - AliasSetTracker AST; - // Maximum loop nest threshold unsigned LoopDepthThreshold; @@ -256,9 +255,14 @@ bool LoopVersioningLICM::legalLoopStructure() { /// Check memory accesses in loop and confirms it's good for /// LoopVersioningLICM. bool LoopVersioningLICM::legalLoopMemoryAccesses() { - bool HasMayAlias = false; - bool TypeSafety = false; - bool HasMod = false; + // Loop over the body of this loop, construct AST. + AliasSetTracker AST(*AA); + for (auto *Block : CurLoop->getBlocks()) { + // Ignore blocks in subloops. + if (LI.getLoopFor(Block) == CurLoop) + AST.add(*Block); + } + // Memory check: // Transform phase will generate a versioned loop and also a runtime check to // ensure the pointers are independent and they don’t alias. @@ -271,6 +275,9 @@ bool LoopVersioningLICM::legalLoopMemoryAccesses() { // // Iterate over alias tracker sets, and confirm AliasSets doesn't have any // must alias set. + bool HasMayAlias = false; + bool TypeSafety = false; + bool HasMod = false; for (const auto &I : AST) { const AliasSet &AS = I; // Skip Forward Alias Sets, as this should be ignored as part of @@ -563,25 +570,18 @@ bool LoopVersioningLICMLegacyPass::runOnLoop(Loop *L, LPPassManager &LPM) { ScalarEvolution *SE = &getAnalysis().getSE(); OptimizationRemarkEmitter *ORE = &getAnalysis().getORE(); - LoopInfo *LI = &getAnalysis().getLoopInfo(); + LoopInfo &LI = getAnalysis().getLoopInfo(); DominatorTree *DT = &getAnalysis().getDomTree(); auto &LAIs = getAnalysis().getLAIs(); - return LoopVersioningLICM(AA, SE, ORE, LAIs, L).run(LI, DT); + return LoopVersioningLICM(AA, SE, ORE, LAIs, LI, L).run(DT); } -bool LoopVersioningLICM::run(LoopInfo *LI, DominatorTree *DT) { +bool LoopVersioningLICM::run(DominatorTree *DT) { // Do not do the transformation if disabled by metadata. if (hasLICMVersioningTransformation(CurLoop) & TM_Disable) return false; - // Loop over the body of this loop, construct AST. - for (auto *Block : CurLoop->getBlocks()) { - // Ignore blocks in subloops. - if (LI->getLoopFor(Block) == CurLoop) - AST.add(*Block); // Incorporate the specified basic block - } - bool Changed = false; // Check feasiblity of LoopVersioningLICM. @@ -592,7 +592,7 @@ bool LoopVersioningLICM::run(LoopInfo *LI, DominatorTree *DT) { // Create memcheck for memory accessed inside loop. // Clone original loop, and set blocks properly. LoopVersioning LVer(*LAI, LAI->getRuntimePointerChecking()->getChecks(), - CurLoop, LI, DT, SE); + CurLoop, &LI, DT, SE); LVer.versionLoop(); // Set Loop Versioning metaData for original loop. addStringMetadataToLoop(LVer.getNonVersionedLoop(), LICMVersioningMetaData); @@ -638,12 +638,11 @@ PreservedAnalyses LoopVersioningLICMPass::run(Loop &L, LoopAnalysisManager &AM, AliasAnalysis *AA = &LAR.AA; ScalarEvolution *SE = &LAR.SE; DominatorTree *DT = &LAR.DT; - LoopInfo *LI = &LAR.LI; const Function *F = L.getHeader()->getParent(); OptimizationRemarkEmitter ORE(F); - LoopAccessInfoManager LAIs(*SE, *AA, *DT, *LI, nullptr); - if (!LoopVersioningLICM(AA, SE, &ORE, LAIs, &L).run(LI, DT)) + LoopAccessInfoManager LAIs(*SE, *AA, *DT, LAR.LI, nullptr); + if (!LoopVersioningLICM(AA, SE, &ORE, LAIs, LAR.LI, &L).run(DT)) return PreservedAnalyses::all(); return getLoopPassPreservedAnalyses(); } -- 2.7.4