Index: include/llvm/Transforms/Utils/LoopVersioning.h =================================================================== --- include/llvm/Transforms/Utils/LoopVersioning.h +++ include/llvm/Transforms/Utils/LoopVersioning.h @@ -56,11 +56,17 @@ /// analyze L /// if versioning is necessary version L /// transform L - void versionLoop() { versionLoop(findDefsUsedOutsideOfLoop(VersionedLoop)); } + /// + /// \return BasicBlock which contains runtime checks. + BasicBlock *versionLoop() { + return versionLoop(findDefsUsedOutsideOfLoop(VersionedLoop)); + } /// \brief Same but if the client has already precomputed the set of values /// used outside the loop, this API will allows passing that. - void versionLoop(const SmallVectorImpl &DefsUsedOutside); + /// + /// \return BasicBlock which contains runtime checks. + BasicBlock *versionLoop(const SmallVectorImpl &DefsUsedOutside); /// \brief Returns the versioned loop. Control flows here if pointers in the /// loop don't alias (i.e. all memchecks passed). (This loop is actually the @@ -83,11 +89,13 @@ /// /// This is just wrapper that calls prepareNoAliasMetadata and /// annotateInstWithNoAlias on the instructions of the versioned loop. - void annotateLoopWithNoAlias(); + void annotateLoopWithNoAlias( + const RuntimePointerChecking *RtPtrChecking = nullptr); /// \brief Set up the aliasing scopes based on the memchecks. This needs to /// be called before the first call to annotateInstWithNoAlias. - void prepareNoAliasMetadata(); + void + prepareNoAliasMetadata(const RuntimePointerChecking *RtPtrChecking = nullptr); /// \brief Add the noalias annotations to \p VersionedInst. /// Index: lib/Transforms/Utils/LoopVersioning.cpp =================================================================== --- lib/Transforms/Utils/LoopVersioning.cpp +++ lib/Transforms/Utils/LoopVersioning.cpp @@ -52,7 +52,7 @@ Preds = std::move(Check); } -void LoopVersioning::versionLoop( +BasicBlock* LoopVersioning::versionLoop( const SmallVectorImpl &DefsUsedOutside) { Instruction *FirstCheckInst; Instruction *MemRuntimeCheck; @@ -119,6 +119,8 @@ // Adds the necessary PHI nodes for the versioned loops based on the // loop-defined values used outside of the loop. addPHINodes(DefsUsedOutside); + + return RuntimeCheckBB; } void LoopVersioning::addPHINodes( @@ -162,7 +164,8 @@ } } -void LoopVersioning::prepareNoAliasMetadata() { +void LoopVersioning::prepareNoAliasMetadata( + const RuntimePointerChecking *RtPtrChecking) { // We need to turn the no-alias relation between pointer checking groups into // no-aliasing annotations between instructions. // @@ -170,7 +173,9 @@ // pointers memchecked together) to an alias scope and then also mapping each // group to the list of scopes it can't alias. - const RuntimePointerChecking *RtPtrChecking = LAI.getRuntimePointerChecking(); + if (!RtPtrChecking) + RtPtrChecking = LAI.getRuntimePointerChecking(); + LLVMContext &Context = VersionedLoop->getHeader()->getContext(); // First allocate an aliasing scope for each pointer checking group. @@ -204,12 +209,13 @@ GroupToNonAliasingScopeList[Pair.first] = MDNode::get(Context, Pair.second); } -void LoopVersioning::annotateLoopWithNoAlias() { +void LoopVersioning::annotateLoopWithNoAlias( + const RuntimePointerChecking *RtPtrChecking) { if (!AnnotateNoAlias) return; // First prepare the maps. - prepareNoAliasMetadata(); + prepareNoAliasMetadata(RtPtrChecking); // Add the scope and no-alias metadata to the instructions. for (Instruction *I : LAI.getDepChecker().getMemoryInstructions()) {