Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 1 | //===- LoopVersioning.cpp - Utility to version a loop ---------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines a utility class to perform loop versioning. The versioned |
| 10 | // loop speculates that otherwise may-aliasing memory accesses don't overlap and |
| 11 | // emits checks to prove this. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
David Blaikie | 94c8337 | 2015-10-26 18:40:56 +0000 | [diff] [blame] | 15 | #include "llvm/Transforms/Utils/LoopVersioning.h" |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 16 | #include "llvm/Analysis/LoopAccessAnalysis.h" |
| 17 | #include "llvm/Analysis/LoopInfo.h" |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/ScalarEvolutionExpander.h" |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Dominators.h" |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 20 | #include "llvm/IR/MDBuilder.h" |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 21 | #include "llvm/Transforms/Utils/BasicBlockUtils.h" |
| 22 | #include "llvm/Transforms/Utils/Cloning.h" |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace llvm; |
| 25 | |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 26 | static cl::opt<bool> |
| 27 | AnnotateNoAlias("loop-version-annotate-no-alias", cl::init(true), |
| 28 | cl::Hidden, |
| 29 | cl::desc("Add no-alias annotation for instructions that " |
| 30 | "are disambiguated by memchecks")); |
| 31 | |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 32 | LoopVersioning::LoopVersioning(const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI, |
| 33 | DominatorTree *DT, ScalarEvolution *SE, |
| 34 | bool UseLAIChecks) |
| 35 | : VersionedLoop(L), NonVersionedLoop(nullptr), LAI(LAI), LI(LI), DT(DT), |
| 36 | SE(SE) { |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 37 | assert(L->getExitBlock() && "No single exit block"); |
Florian Hahn | 2e03213 | 2016-12-19 17:13:37 +0000 | [diff] [blame] | 38 | assert(L->isLoopSimplifyForm() && "Loop is not in loop-simplify form"); |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 39 | if (UseLAIChecks) { |
| 40 | setAliasChecks(LAI.getRuntimePointerChecking()->getChecks()); |
Xinliang David Li | 94734ee | 2016-07-01 05:59:55 +0000 | [diff] [blame] | 41 | setSCEVChecks(LAI.getPSE().getUnionPredicate()); |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 42 | } |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 45 | void LoopVersioning::setAliasChecks( |
Benjamin Kramer | 728f444 | 2016-05-29 10:46:35 +0000 | [diff] [blame] | 46 | SmallVector<RuntimePointerChecking::PointerCheck, 4> Checks) { |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 47 | AliasChecks = std::move(Checks); |
| 48 | } |
| 49 | |
| 50 | void LoopVersioning::setSCEVChecks(SCEVUnionPredicate Check) { |
| 51 | Preds = std::move(Check); |
Adam Nemet | dfaeb33 | 2015-08-12 16:51:19 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Adam Nemet | e481340 | 2015-08-20 17:22:29 +0000 | [diff] [blame] | 54 | void LoopVersioning::versionLoop( |
| 55 | const SmallVectorImpl<Instruction *> &DefsUsedOutside) { |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 56 | Instruction *FirstCheckInst; |
| 57 | Instruction *MemRuntimeCheck; |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 58 | Value *SCEVRuntimeCheck; |
| 59 | Value *RuntimeCheck = nullptr; |
| 60 | |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 61 | // Add the memcheck in the original preheader (this is empty initially). |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 62 | BasicBlock *RuntimeCheckBB = VersionedLoop->getLoopPreheader(); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 63 | std::tie(FirstCheckInst, MemRuntimeCheck) = |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 64 | LAI.addRuntimeChecks(RuntimeCheckBB->getTerminator(), AliasChecks); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 65 | |
Xinliang David Li | 94734ee | 2016-07-01 05:59:55 +0000 | [diff] [blame] | 66 | const SCEVUnionPredicate &Pred = LAI.getPSE().getUnionPredicate(); |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 67 | SCEVExpander Exp(*SE, RuntimeCheckBB->getModule()->getDataLayout(), |
| 68 | "scev.check"); |
| 69 | SCEVRuntimeCheck = |
| 70 | Exp.expandCodeForPredicate(&Pred, RuntimeCheckBB->getTerminator()); |
| 71 | auto *CI = dyn_cast<ConstantInt>(SCEVRuntimeCheck); |
| 72 | |
| 73 | // Discard the SCEV runtime check if it is always true. |
| 74 | if (CI && CI->isZero()) |
| 75 | SCEVRuntimeCheck = nullptr; |
| 76 | |
| 77 | if (MemRuntimeCheck && SCEVRuntimeCheck) { |
| 78 | RuntimeCheck = BinaryOperator::Create(Instruction::Or, MemRuntimeCheck, |
Vikram TV | 299abc1 | 2016-06-13 10:49:28 +0000 | [diff] [blame] | 79 | SCEVRuntimeCheck, "lver.safe"); |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 80 | if (auto *I = dyn_cast<Instruction>(RuntimeCheck)) |
| 81 | I->insertBefore(RuntimeCheckBB->getTerminator()); |
| 82 | } else |
| 83 | RuntimeCheck = MemRuntimeCheck ? MemRuntimeCheck : SCEVRuntimeCheck; |
| 84 | |
| 85 | assert(RuntimeCheck && "called even though we don't need " |
| 86 | "any runtime checks"); |
| 87 | |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 88 | // Rename the block to make the IR more readable. |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 89 | RuntimeCheckBB->setName(VersionedLoop->getHeader()->getName() + |
| 90 | ".lver.check"); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 91 | |
| 92 | // Create empty preheader for the loop (and after cloning for the |
| 93 | // non-versioned loop). |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 94 | BasicBlock *PH = |
| 95 | SplitBlock(RuntimeCheckBB, RuntimeCheckBB->getTerminator(), DT, LI); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 96 | PH->setName(VersionedLoop->getHeader()->getName() + ".ph"); |
| 97 | |
| 98 | // Clone the loop including the preheader. |
| 99 | // |
| 100 | // FIXME: This does not currently preserve SimplifyLoop because the exit |
| 101 | // block is a join between the two loops. |
| 102 | SmallVector<BasicBlock *, 8> NonVersionedLoopBlocks; |
| 103 | NonVersionedLoop = |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 104 | cloneLoopWithPreheader(PH, RuntimeCheckBB, VersionedLoop, VMap, |
| 105 | ".lver.orig", LI, DT, NonVersionedLoopBlocks); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 106 | remapInstructionsInBlocks(NonVersionedLoopBlocks, VMap); |
| 107 | |
| 108 | // Insert the conditional branch based on the result of the memchecks. |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 109 | Instruction *OrigTerm = RuntimeCheckBB->getTerminator(); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 110 | BranchInst::Create(NonVersionedLoop->getLoopPreheader(), |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 111 | VersionedLoop->getLoopPreheader(), RuntimeCheck, OrigTerm); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 112 | OrigTerm->eraseFromParent(); |
| 113 | |
| 114 | // The loops merge in the original exit block. This is now dominated by the |
| 115 | // memchecking block. |
Silviu Baranga | 2910a4f | 2015-11-09 13:26:09 +0000 | [diff] [blame] | 116 | DT->changeImmediateDominator(VersionedLoop->getExitBlock(), RuntimeCheckBB); |
Adam Nemet | e481340 | 2015-08-20 17:22:29 +0000 | [diff] [blame] | 117 | |
| 118 | // Adds the necessary PHI nodes for the versioned loops based on the |
| 119 | // loop-defined values used outside of the loop. |
| 120 | addPHINodes(DefsUsedOutside); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void LoopVersioning::addPHINodes( |
| 124 | const SmallVectorImpl<Instruction *> &DefsUsedOutside) { |
| 125 | BasicBlock *PHIBlock = VersionedLoop->getExitBlock(); |
| 126 | assert(PHIBlock && "No single successor to loop exit block"); |
Adam Nemet | 73a2695 | 2016-06-14 09:38:54 +0000 | [diff] [blame] | 127 | PHINode *PN; |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 128 | |
Adam Nemet | 73a2695 | 2016-06-14 09:38:54 +0000 | [diff] [blame] | 129 | // First add a single-operand PHI for each DefsUsedOutside if one does not |
| 130 | // exists yet. |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 131 | for (auto *Inst : DefsUsedOutside) { |
Adam Nemet | 73a2695 | 2016-06-14 09:38:54 +0000 | [diff] [blame] | 132 | // See if we have a single-operand PHI with the value defined by the |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 133 | // original loop. |
| 134 | for (auto I = PHIBlock->begin(); (PN = dyn_cast<PHINode>(I)); ++I) { |
Adam Nemet | 57fb898 | 2016-06-14 09:39:01 +0000 | [diff] [blame] | 135 | if (PN->getIncomingValue(0) == Inst) |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 136 | break; |
| 137 | } |
| 138 | // If not create it. |
| 139 | if (!PN) { |
| 140 | PN = PHINode::Create(Inst->getType(), 2, Inst->getName() + ".lver", |
Duncan P. N. Exon Smith | 5b4c837 | 2015-10-13 02:39:05 +0000 | [diff] [blame] | 141 | &PHIBlock->front()); |
Bjorn Pettersson | fecef6b | 2018-05-22 08:33:02 +0000 | [diff] [blame] | 142 | SmallVector<User*, 8> UsersToUpdate; |
| 143 | for (User *U : Inst->users()) |
| 144 | if (!VersionedLoop->contains(cast<Instruction>(U)->getParent())) |
| 145 | UsersToUpdate.push_back(U); |
| 146 | for (User *U : UsersToUpdate) |
| 147 | U->replaceUsesOfWith(Inst, PN); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 148 | PN->addIncoming(Inst, VersionedLoop->getExitingBlock()); |
| 149 | } |
Adam Nemet | 73a2695 | 2016-06-14 09:38:54 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | // Then for each PHI add the operand for the edge from the cloned loop. |
| 153 | for (auto I = PHIBlock->begin(); (PN = dyn_cast<PHINode>(I)); ++I) { |
| 154 | assert(PN->getNumOperands() == 1 && |
| 155 | "Exit block should only have on predecessor"); |
| 156 | |
| 157 | // If the definition was cloned used that otherwise use the same value. |
| 158 | Value *ClonedValue = PN->getIncomingValue(0); |
| 159 | auto Mapped = VMap.find(ClonedValue); |
| 160 | if (Mapped != VMap.end()) |
| 161 | ClonedValue = Mapped->second; |
| 162 | |
| 163 | PN->addIncoming(ClonedValue, NonVersionedLoop->getExitingBlock()); |
Adam Nemet | 215746b | 2015-07-10 18:55:13 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
Adam Nemet | d52ed84 | 2016-02-03 00:06:10 +0000 | [diff] [blame] | 166 | |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 167 | void LoopVersioning::prepareNoAliasMetadata() { |
| 168 | // We need to turn the no-alias relation between pointer checking groups into |
| 169 | // no-aliasing annotations between instructions. |
| 170 | // |
| 171 | // We accomplish this by mapping each pointer checking group (a set of |
| 172 | // pointers memchecked together) to an alias scope and then also mapping each |
| 173 | // group to the list of scopes it can't alias. |
| 174 | |
| 175 | const RuntimePointerChecking *RtPtrChecking = LAI.getRuntimePointerChecking(); |
| 176 | LLVMContext &Context = VersionedLoop->getHeader()->getContext(); |
| 177 | |
| 178 | // First allocate an aliasing scope for each pointer checking group. |
| 179 | // |
| 180 | // While traversing through the checking groups in the loop, also create a |
| 181 | // reverse map from pointers to the pointer checking group they were assigned |
| 182 | // to. |
| 183 | MDBuilder MDB(Context); |
| 184 | MDNode *Domain = MDB.createAnonymousAliasScopeDomain("LVerDomain"); |
| 185 | |
| 186 | for (const auto &Group : RtPtrChecking->CheckingGroups) { |
| 187 | GroupToScope[&Group] = MDB.createAnonymousAliasScope(Domain); |
| 188 | |
| 189 | for (unsigned PtrIdx : Group.Members) |
| 190 | PtrToGroup[RtPtrChecking->getPointerInfo(PtrIdx).PointerValue] = &Group; |
| 191 | } |
| 192 | |
| 193 | // Go through the checks and for each pointer group, collect the scopes for |
| 194 | // each non-aliasing pointer group. |
| 195 | DenseMap<const RuntimePointerChecking::CheckingPtrGroup *, |
| 196 | SmallVector<Metadata *, 4>> |
| 197 | GroupToNonAliasingScopes; |
| 198 | |
| 199 | for (const auto &Check : AliasChecks) |
| 200 | GroupToNonAliasingScopes[Check.first].push_back(GroupToScope[Check.second]); |
| 201 | |
| 202 | // Finally, transform the above to actually map to scope list which is what |
| 203 | // the metadata uses. |
| 204 | |
| 205 | for (auto Pair : GroupToNonAliasingScopes) |
| 206 | GroupToNonAliasingScopeList[Pair.first] = MDNode::get(Context, Pair.second); |
| 207 | } |
| 208 | |
| 209 | void LoopVersioning::annotateLoopWithNoAlias() { |
| 210 | if (!AnnotateNoAlias) |
| 211 | return; |
| 212 | |
| 213 | // First prepare the maps. |
| 214 | prepareNoAliasMetadata(); |
| 215 | |
| 216 | // Add the scope and no-alias metadata to the instructions. |
| 217 | for (Instruction *I : LAI.getDepChecker().getMemoryInstructions()) { |
| 218 | annotateInstWithNoAlias(I); |
| 219 | } |
| 220 | } |
| 221 | |
Adam Nemet | b0c4eae | 2016-03-17 20:32:37 +0000 | [diff] [blame] | 222 | void LoopVersioning::annotateInstWithNoAlias(Instruction *VersionedInst, |
| 223 | const Instruction *OrigInst) { |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 224 | if (!AnnotateNoAlias) |
| 225 | return; |
| 226 | |
| 227 | LLVMContext &Context = VersionedLoop->getHeader()->getContext(); |
Adam Nemet | b0c4eae | 2016-03-17 20:32:37 +0000 | [diff] [blame] | 228 | const Value *Ptr = isa<LoadInst>(OrigInst) |
| 229 | ? cast<LoadInst>(OrigInst)->getPointerOperand() |
| 230 | : cast<StoreInst>(OrigInst)->getPointerOperand(); |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 231 | |
| 232 | // Find the group for the pointer and then add the scope metadata. |
| 233 | auto Group = PtrToGroup.find(Ptr); |
| 234 | if (Group != PtrToGroup.end()) { |
Adam Nemet | b0c4eae | 2016-03-17 20:32:37 +0000 | [diff] [blame] | 235 | VersionedInst->setMetadata( |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 236 | LLVMContext::MD_alias_scope, |
Adam Nemet | b0c4eae | 2016-03-17 20:32:37 +0000 | [diff] [blame] | 237 | MDNode::concatenate( |
| 238 | VersionedInst->getMetadata(LLVMContext::MD_alias_scope), |
| 239 | MDNode::get(Context, GroupToScope[Group->second]))); |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 240 | |
| 241 | // Add the no-alias metadata. |
| 242 | auto NonAliasingScopeList = GroupToNonAliasingScopeList.find(Group->second); |
| 243 | if (NonAliasingScopeList != GroupToNonAliasingScopeList.end()) |
Adam Nemet | b0c4eae | 2016-03-17 20:32:37 +0000 | [diff] [blame] | 244 | VersionedInst->setMetadata( |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 245 | LLVMContext::MD_noalias, |
Adam Nemet | b0c4eae | 2016-03-17 20:32:37 +0000 | [diff] [blame] | 246 | MDNode::concatenate( |
| 247 | VersionedInst->getMetadata(LLVMContext::MD_noalias), |
| 248 | NonAliasingScopeList->second)); |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Adam Nemet | d52ed84 | 2016-02-03 00:06:10 +0000 | [diff] [blame] | 252 | namespace { |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 253 | /// Also expose this is a pass. Currently this is only used for |
Adam Nemet | d52ed84 | 2016-02-03 00:06:10 +0000 | [diff] [blame] | 254 | /// unit-testing. It adds all memchecks necessary to remove all may-aliasing |
| 255 | /// array accesses from the loop. |
| 256 | class LoopVersioningPass : public FunctionPass { |
| 257 | public: |
| 258 | LoopVersioningPass() : FunctionPass(ID) { |
| 259 | initializeLoopVersioningPassPass(*PassRegistry::getPassRegistry()); |
| 260 | } |
| 261 | |
| 262 | bool runOnFunction(Function &F) override { |
| 263 | auto *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
Xinliang David Li | 7853c1d | 2016-07-08 20:55:26 +0000 | [diff] [blame] | 264 | auto *LAA = &getAnalysis<LoopAccessLegacyAnalysis>(); |
Adam Nemet | d52ed84 | 2016-02-03 00:06:10 +0000 | [diff] [blame] | 265 | auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
| 266 | auto *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); |
| 267 | |
| 268 | // Build up a worklist of inner-loops to version. This is necessary as the |
| 269 | // act of versioning a loop creates new loops and can invalidate iterators |
| 270 | // across the loops. |
| 271 | SmallVector<Loop *, 8> Worklist; |
| 272 | |
| 273 | for (Loop *TopLevelLoop : *LI) |
| 274 | for (Loop *L : depth_first(TopLevelLoop)) |
| 275 | // We only handle inner-most loops. |
| 276 | if (L->empty()) |
| 277 | Worklist.push_back(L); |
| 278 | |
| 279 | // Now walk the identified inner loops. |
| 280 | bool Changed = false; |
| 281 | for (Loop *L : Worklist) { |
Adam Nemet | bdbc522 | 2016-06-16 08:26:56 +0000 | [diff] [blame] | 282 | const LoopAccessInfo &LAI = LAA->getInfo(L); |
Florian Hahn | 2e03213 | 2016-12-19 17:13:37 +0000 | [diff] [blame] | 283 | if (L->isLoopSimplifyForm() && (LAI.getNumRuntimePointerChecks() || |
| 284 | !LAI.getPSE().getUnionPredicate().isAlwaysTrue())) { |
Adam Nemet | d52ed84 | 2016-02-03 00:06:10 +0000 | [diff] [blame] | 285 | LoopVersioning LVer(LAI, L, LI, DT, SE); |
| 286 | LVer.versionLoop(); |
Adam Nemet | 5eccf07 | 2016-03-17 20:32:32 +0000 | [diff] [blame] | 287 | LVer.annotateLoopWithNoAlias(); |
Adam Nemet | d52ed84 | 2016-02-03 00:06:10 +0000 | [diff] [blame] | 288 | Changed = true; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | return Changed; |
| 293 | } |
| 294 | |
| 295 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 296 | AU.addRequired<LoopInfoWrapperPass>(); |
| 297 | AU.addPreserved<LoopInfoWrapperPass>(); |
Xinliang David Li | 7853c1d | 2016-07-08 20:55:26 +0000 | [diff] [blame] | 298 | AU.addRequired<LoopAccessLegacyAnalysis>(); |
Adam Nemet | d52ed84 | 2016-02-03 00:06:10 +0000 | [diff] [blame] | 299 | AU.addRequired<DominatorTreeWrapperPass>(); |
| 300 | AU.addPreserved<DominatorTreeWrapperPass>(); |
| 301 | AU.addRequired<ScalarEvolutionWrapperPass>(); |
| 302 | } |
| 303 | |
| 304 | static char ID; |
| 305 | }; |
| 306 | } |
| 307 | |
| 308 | #define LVER_OPTION "loop-versioning" |
| 309 | #define DEBUG_TYPE LVER_OPTION |
| 310 | |
| 311 | char LoopVersioningPass::ID; |
| 312 | static const char LVer_name[] = "Loop Versioning"; |
| 313 | |
| 314 | INITIALIZE_PASS_BEGIN(LoopVersioningPass, LVER_OPTION, LVer_name, false, false) |
| 315 | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) |
Xinliang David Li | 7853c1d | 2016-07-08 20:55:26 +0000 | [diff] [blame] | 316 | INITIALIZE_PASS_DEPENDENCY(LoopAccessLegacyAnalysis) |
Adam Nemet | d52ed84 | 2016-02-03 00:06:10 +0000 | [diff] [blame] | 317 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
| 318 | INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass) |
| 319 | INITIALIZE_PASS_END(LoopVersioningPass, LVER_OPTION, LVer_name, false, false) |
| 320 | |
| 321 | namespace llvm { |
| 322 | FunctionPass *createLoopVersioningPass() { |
| 323 | return new LoopVersioningPass(); |
| 324 | } |
| 325 | } |