Index: lib/Transforms/Scalar/LoopVersioningLICM.cpp =================================================================== --- lib/Transforms/Scalar/LoopVersioningLICM.cpp +++ lib/Transforms/Scalar/LoopVersioningLICM.cpp @@ -158,34 +158,29 @@ AU.addRequired(); AU.addRequiredID(LoopSimplifyID); AU.addRequired(); - AU.addRequired(); AU.addPreserved(); AU.addPreserved(); } LoopVersioningLICM() - : LoopPass(ID), AA(nullptr), SE(nullptr), LI(nullptr), DT(nullptr), - TLI(nullptr), LAA(nullptr), LAI(nullptr), Changed(false), - Preheader(nullptr), CurLoop(nullptr), CurAST(nullptr), + : LoopPass(ID), AA(nullptr), SE(nullptr), + LAA(nullptr), LAI(nullptr), + CurLoop(nullptr), LoopDepthThreshold(LVLoopDepthThreshold), InvariantThreshold(LVInvarThreshold), LoadAndStoreCounter(0), InvariantCounter(0), IsReadOnlyLoop(true) { initializeLoopVersioningLICMPass(*PassRegistry::getPassRegistry()); } + StringRef getPassName() const override { return "Loop Versioning for LICM"; } +private: AliasAnalysis *AA; // Current AliasAnalysis information ScalarEvolution *SE; // Current ScalarEvolution - LoopInfo *LI; // Current LoopInfo - DominatorTree *DT; // Dominator Tree for the current Loop. - TargetLibraryInfo *TLI; // TargetLibraryInfo for constant folding. LoopAccessLegacyAnalysis *LAA; // Current LoopAccessAnalysis const LoopAccessInfo *LAI; // Current Loop's LoopAccessInfo - bool Changed; // Set to true when we change anything. - BasicBlock *Preheader; // The preheader block of the current loop. Loop *CurLoop; // The current loop we are working on. - AliasSetTracker *CurAST; // AliasSet information for the current loop. - ValueToValueMap Strides; + std::unique_ptr CurAST; // AliasSet information for the current loop. unsigned LoopDepthThreshold; // Maximum loop nest threshold float InvariantThreshold; // Minimum invariant threshold @@ -200,7 +195,6 @@ bool isLoopAlreadyVisited(); void setNoAliasToLoop(Loop *); bool instructionSafeForVersioning(Instruction *); - StringRef getPassName() const override { return "Loop Versioning"; } }; } @@ -263,7 +257,6 @@ /// LoopVersioningLICM. bool LoopVersioningLICM::legalLoopMemoryAccesses() { bool HasMayAlias = false; - bool TypeSafety = false; bool HasMod = false; // Memory check: // Transform phase will generate a versioned loop and also a runtime check to @@ -286,23 +279,9 @@ // With MustAlias its not worth adding runtime bound check. if (AS.isMustAlias()) return false; - Value *SomePtr = AS.begin()->getValue(); - bool TypeCheck = true; // Check for Mod & MayAlias HasMayAlias |= AS.isMayAlias(); HasMod |= AS.isMod(); - for (const auto &A : AS) { - Value *Ptr = A.getValue(); - // Alias tracker should have pointers of same data type. - TypeCheck = (TypeCheck && (SomePtr->getType() == Ptr->getType())); - } - // At least one alias tracker should have pointers of same data type. - TypeSafety |= TypeCheck; - } - // Ensure types should be of same type. - if (!TypeSafety) { - DEBUG(dbgs() << " Alias tracker type safety failed!\n"); - return false; } // Ensure loop body shouldn't be read only. if (!HasMod) { @@ -507,27 +486,24 @@ bool LoopVersioningLICM::runOnLoop(Loop *L, LPPassManager &LPM) { if (skipLoop(L)) return false; - Changed = false; // Get Analysis information. - LI = &getAnalysis().getLoopInfo(); AA = &getAnalysis().getAAResults(); SE = &getAnalysis().getSE(); - DT = &getAnalysis().getDomTree(); - TLI = &getAnalysis().getTLI(); LAA = &getAnalysis(); LAI = nullptr; // Set Current Loop CurLoop = L; - // Get the preheader block. - Preheader = L->getLoopPreheader(); - // Initial allocation - CurAST = new AliasSetTracker(*AA); + CurAST.reset(new AliasSetTracker(*AA)); // Loop over the body of this loop, construct AST. + LoopInfo *LI = &getAnalysis().getLoopInfo(); for (auto *Block : L->getBlocks()) { if (LI->getLoopFor(Block) == L) // Ignore blocks in subloop. CurAST->add(*Block); // Incorporate the specified basic block } + + bool Changed = false; + // Check feasiblity of LoopVersioningLICM. // If versioning found to be feasible and beneficial then proceed // else simply return, by cleaning up memory. @@ -535,6 +511,7 @@ // Do loop versioning. // Create memcheck for memory accessed inside loop. // Clone original loop, and set blocks properly. + DominatorTree *DT = &getAnalysis().getDomTree(); LoopVersioning LVer(*LAI, CurLoop, LI, DT, SE, true); LVer.versionLoop(); // Set Loop Versioning metaData for original loop. @@ -548,8 +525,6 @@ setNoAliasToLoop(LVer.getVersionedLoop()); Changed = true; } - // Delete allocated memory. - delete CurAST; return Changed; } @@ -564,7 +539,6 @@ INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(LoopSimplify) INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass) -INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) INITIALIZE_PASS_END(LoopVersioningLICM, "loop-versioning-licm", "Loop Versioning For LICM", false, false)