Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1 | //===- LoopAccessAnalysis.cpp - Loop Access Analysis Implementation --------==// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // The implementation for the loop memory dependence that was originally |
| 11 | // developed for the loop vectorizer. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Analysis/LoopAccessAnalysis.h" |
| 16 | #include "llvm/Analysis/LoopInfo.h" |
Adam Nemet | 7206d7a | 2015-02-06 18:31:04 +0000 | [diff] [blame] | 17 | #include "llvm/Analysis/ScalarEvolutionExpander.h" |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/ValueTracking.h" |
| 19 | #include "llvm/IR/DiagnosticInfo.h" |
| 20 | #include "llvm/IR/Dominators.h" |
Adam Nemet | 7206d7a | 2015-02-06 18:31:04 +0000 | [diff] [blame] | 21 | #include "llvm/IR/IRBuilder.h" |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Debug.h" |
| 23 | #include "llvm/Transforms/Utils/VectorUtils.h" |
| 24 | using namespace llvm; |
| 25 | |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 26 | #define DEBUG_TYPE "loop-accesses" |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 27 | |
Adam Nemet | f219c64 | 2015-02-19 19:14:52 +0000 | [diff] [blame] | 28 | static cl::opt<unsigned, true> |
| 29 | VectorizationFactor("force-vector-width", cl::Hidden, |
| 30 | cl::desc("Sets the SIMD width. Zero is autoselect."), |
| 31 | cl::location(VectorizerParams::VectorizationFactor)); |
Adam Nemet | 1d862af | 2015-02-26 04:39:09 +0000 | [diff] [blame] | 32 | unsigned VectorizerParams::VectorizationFactor; |
Adam Nemet | f219c64 | 2015-02-19 19:14:52 +0000 | [diff] [blame] | 33 | |
| 34 | static cl::opt<unsigned, true> |
| 35 | VectorizationInterleave("force-vector-interleave", cl::Hidden, |
| 36 | cl::desc("Sets the vectorization interleave count. " |
| 37 | "Zero is autoselect."), |
| 38 | cl::location( |
| 39 | VectorizerParams::VectorizationInterleave)); |
Adam Nemet | 1d862af | 2015-02-26 04:39:09 +0000 | [diff] [blame] | 40 | unsigned VectorizerParams::VectorizationInterleave; |
Adam Nemet | f219c64 | 2015-02-19 19:14:52 +0000 | [diff] [blame] | 41 | |
Adam Nemet | 1d862af | 2015-02-26 04:39:09 +0000 | [diff] [blame] | 42 | static cl::opt<unsigned, true> RuntimeMemoryCheckThreshold( |
| 43 | "runtime-memory-check-threshold", cl::Hidden, |
| 44 | cl::desc("When performing memory disambiguation checks at runtime do not " |
| 45 | "generate more than this number of comparisons (default = 8)."), |
| 46 | cl::location(VectorizerParams::RuntimeMemoryCheckThreshold), cl::init(8)); |
| 47 | unsigned VectorizerParams::RuntimeMemoryCheckThreshold; |
Adam Nemet | f219c64 | 2015-02-19 19:14:52 +0000 | [diff] [blame] | 48 | |
| 49 | /// Maximum SIMD width. |
| 50 | const unsigned VectorizerParams::MaxVectorWidth = 64; |
| 51 | |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 52 | /// \brief We collect interesting dependences up to this threshold. |
| 53 | static cl::opt<unsigned> MaxInterestingDependence( |
| 54 | "max-interesting-dependences", cl::Hidden, |
| 55 | cl::desc("Maximum number of interesting dependences collected by " |
| 56 | "loop-access analysis (default = 100)"), |
| 57 | cl::init(100)); |
| 58 | |
Adam Nemet | f219c64 | 2015-02-19 19:14:52 +0000 | [diff] [blame] | 59 | bool VectorizerParams::isInterleaveForced() { |
| 60 | return ::VectorizationInterleave.getNumOccurrences() > 0; |
| 61 | } |
| 62 | |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 63 | void LoopAccessReport::emitAnalysis(const LoopAccessReport &Message, |
| 64 | const Function *TheFunction, |
| 65 | const Loop *TheLoop, |
| 66 | const char *PassName) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 67 | DebugLoc DL = TheLoop->getStartLoc(); |
Adam Nemet | 3e87634 | 2015-02-19 19:15:13 +0000 | [diff] [blame] | 68 | if (const Instruction *I = Message.getInstr()) |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 69 | DL = I->getDebugLoc(); |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 70 | emitOptimizationRemarkAnalysis(TheFunction->getContext(), PassName, |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 71 | *TheFunction, DL, Message.str()); |
| 72 | } |
| 73 | |
| 74 | Value *llvm::stripIntegerCast(Value *V) { |
| 75 | if (CastInst *CI = dyn_cast<CastInst>(V)) |
| 76 | if (CI->getOperand(0)->getType()->isIntegerTy()) |
| 77 | return CI->getOperand(0); |
| 78 | return V; |
| 79 | } |
| 80 | |
| 81 | const SCEV *llvm::replaceSymbolicStrideSCEV(ScalarEvolution *SE, |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 82 | const ValueToValueMap &PtrToStride, |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 83 | Value *Ptr, Value *OrigPtr) { |
| 84 | |
| 85 | const SCEV *OrigSCEV = SE->getSCEV(Ptr); |
| 86 | |
| 87 | // If there is an entry in the map return the SCEV of the pointer with the |
| 88 | // symbolic stride replaced by one. |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 89 | ValueToValueMap::const_iterator SI = |
| 90 | PtrToStride.find(OrigPtr ? OrigPtr : Ptr); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 91 | if (SI != PtrToStride.end()) { |
| 92 | Value *StrideVal = SI->second; |
| 93 | |
| 94 | // Strip casts. |
| 95 | StrideVal = stripIntegerCast(StrideVal); |
| 96 | |
| 97 | // Replace symbolic stride by one. |
| 98 | Value *One = ConstantInt::get(StrideVal->getType(), 1); |
| 99 | ValueToValueMap RewriteMap; |
| 100 | RewriteMap[StrideVal] = One; |
| 101 | |
| 102 | const SCEV *ByOne = |
| 103 | SCEVParameterRewriter::rewrite(OrigSCEV, *SE, RewriteMap, true); |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 104 | DEBUG(dbgs() << "LAA: Replacing SCEV: " << *OrigSCEV << " by: " << *ByOne |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 105 | << "\n"); |
| 106 | return ByOne; |
| 107 | } |
| 108 | |
| 109 | // Otherwise, just return the SCEV of the original pointer. |
| 110 | return SE->getSCEV(Ptr); |
| 111 | } |
| 112 | |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 113 | void LoopAccessInfo::RuntimePointerCheck::insert( |
| 114 | ScalarEvolution *SE, Loop *Lp, Value *Ptr, bool WritePtr, unsigned DepSetId, |
| 115 | unsigned ASId, const ValueToValueMap &Strides) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 116 | // Get the stride replaced scev. |
| 117 | const SCEV *Sc = replaceSymbolicStrideSCEV(SE, Strides, Ptr); |
| 118 | const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Sc); |
| 119 | assert(AR && "Invalid addrec expression"); |
| 120 | const SCEV *Ex = SE->getBackedgeTakenCount(Lp); |
| 121 | const SCEV *ScEnd = AR->evaluateAtIteration(Ex, *SE); |
| 122 | Pointers.push_back(Ptr); |
| 123 | Starts.push_back(AR->getStart()); |
| 124 | Ends.push_back(ScEnd); |
| 125 | IsWritePtr.push_back(WritePtr); |
| 126 | DependencySetId.push_back(DepSetId); |
| 127 | AliasSetId.push_back(ASId); |
| 128 | } |
| 129 | |
Adam Nemet | a8945b7 | 2015-02-18 03:43:58 +0000 | [diff] [blame] | 130 | bool LoopAccessInfo::RuntimePointerCheck::needsChecking(unsigned I, |
| 131 | unsigned J) const { |
| 132 | // No need to check if two readonly pointers intersect. |
| 133 | if (!IsWritePtr[I] && !IsWritePtr[J]) |
| 134 | return false; |
| 135 | |
| 136 | // Only need to check pointers between two different dependency sets. |
| 137 | if (DependencySetId[I] == DependencySetId[J]) |
| 138 | return false; |
| 139 | |
| 140 | // Only need to check pointers in the same alias set. |
| 141 | if (AliasSetId[I] != AliasSetId[J]) |
| 142 | return false; |
| 143 | |
| 144 | return true; |
| 145 | } |
| 146 | |
Adam Nemet | e91cc6e | 2015-02-19 19:15:19 +0000 | [diff] [blame] | 147 | void LoopAccessInfo::RuntimePointerCheck::print(raw_ostream &OS, |
| 148 | unsigned Depth) const { |
| 149 | unsigned NumPointers = Pointers.size(); |
| 150 | if (NumPointers == 0) |
| 151 | return; |
| 152 | |
| 153 | OS.indent(Depth) << "Run-time memory checks:\n"; |
| 154 | unsigned N = 0; |
| 155 | for (unsigned I = 0; I < NumPointers; ++I) |
| 156 | for (unsigned J = I + 1; J < NumPointers; ++J) |
| 157 | if (needsChecking(I, J)) { |
| 158 | OS.indent(Depth) << N++ << ":\n"; |
| 159 | OS.indent(Depth + 2) << *Pointers[I] << "\n"; |
| 160 | OS.indent(Depth + 2) << *Pointers[J] << "\n"; |
| 161 | } |
| 162 | } |
| 163 | |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 164 | namespace { |
| 165 | /// \brief Analyses memory accesses in a loop. |
| 166 | /// |
| 167 | /// Checks whether run time pointer checks are needed and builds sets for data |
| 168 | /// dependence checking. |
| 169 | class AccessAnalysis { |
| 170 | public: |
| 171 | /// \brief Read or write access location. |
| 172 | typedef PointerIntPair<Value *, 1, bool> MemAccessInfo; |
| 173 | typedef SmallPtrSet<MemAccessInfo, 8> MemAccessInfoSet; |
| 174 | |
Adam Nemet | dee666b | 2015-03-10 17:40:34 +0000 | [diff] [blame] | 175 | AccessAnalysis(const DataLayout &Dl, AliasAnalysis *AA, |
| 176 | MemoryDepChecker::DepCandidates &DA) |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 177 | : DL(Dl), AST(*AA), DepCands(DA), IsRTCheckNeeded(false) {} |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 178 | |
| 179 | /// \brief Register a load and whether it is only read from. |
| 180 | void addLoad(AliasAnalysis::Location &Loc, bool IsReadOnly) { |
| 181 | Value *Ptr = const_cast<Value*>(Loc.Ptr); |
| 182 | AST.add(Ptr, AliasAnalysis::UnknownSize, Loc.AATags); |
| 183 | Accesses.insert(MemAccessInfo(Ptr, false)); |
| 184 | if (IsReadOnly) |
| 185 | ReadOnlyPtr.insert(Ptr); |
| 186 | } |
| 187 | |
| 188 | /// \brief Register a store. |
| 189 | void addStore(AliasAnalysis::Location &Loc) { |
| 190 | Value *Ptr = const_cast<Value*>(Loc.Ptr); |
| 191 | AST.add(Ptr, AliasAnalysis::UnknownSize, Loc.AATags); |
| 192 | Accesses.insert(MemAccessInfo(Ptr, true)); |
| 193 | } |
| 194 | |
| 195 | /// \brief Check whether we can check the pointers at runtime for |
| 196 | /// non-intersection. |
Adam Nemet | 30f16e1 | 2015-02-18 03:42:35 +0000 | [diff] [blame] | 197 | bool canCheckPtrAtRT(LoopAccessInfo::RuntimePointerCheck &RtCheck, |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 198 | unsigned &NumComparisons, ScalarEvolution *SE, |
| 199 | Loop *TheLoop, const ValueToValueMap &Strides, |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 200 | bool ShouldCheckStride = false); |
| 201 | |
| 202 | /// \brief Goes over all memory accesses, checks whether a RT check is needed |
| 203 | /// and builds sets of dependent accesses. |
| 204 | void buildDependenceSets() { |
| 205 | processMemAccesses(); |
| 206 | } |
| 207 | |
| 208 | bool isRTCheckNeeded() { return IsRTCheckNeeded; } |
| 209 | |
| 210 | bool isDependencyCheckNeeded() { return !CheckDeps.empty(); } |
| 211 | void resetDepChecks() { CheckDeps.clear(); } |
| 212 | |
| 213 | MemAccessInfoSet &getDependenciesToCheck() { return CheckDeps; } |
| 214 | |
| 215 | private: |
| 216 | typedef SetVector<MemAccessInfo> PtrAccessSet; |
| 217 | |
| 218 | /// \brief Go over all memory access and check whether runtime pointer checks |
| 219 | /// are needed /// and build sets of dependency check candidates. |
| 220 | void processMemAccesses(); |
| 221 | |
| 222 | /// Set of all accesses. |
| 223 | PtrAccessSet Accesses; |
| 224 | |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 225 | const DataLayout &DL; |
| 226 | |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 227 | /// Set of accesses that need a further dependence check. |
| 228 | MemAccessInfoSet CheckDeps; |
| 229 | |
| 230 | /// Set of pointers that are read only. |
| 231 | SmallPtrSet<Value*, 16> ReadOnlyPtr; |
| 232 | |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 233 | /// An alias set tracker to partition the access set by underlying object and |
| 234 | //intrinsic property (such as TBAA metadata). |
| 235 | AliasSetTracker AST; |
| 236 | |
| 237 | /// Sets of potentially dependent accesses - members of one set share an |
| 238 | /// underlying pointer. The set "CheckDeps" identfies which sets really need a |
| 239 | /// dependence check. |
Adam Nemet | dee666b | 2015-03-10 17:40:34 +0000 | [diff] [blame] | 240 | MemoryDepChecker::DepCandidates &DepCands; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 241 | |
| 242 | bool IsRTCheckNeeded; |
| 243 | }; |
| 244 | |
| 245 | } // end anonymous namespace |
| 246 | |
| 247 | /// \brief Check whether a pointer can participate in a runtime bounds check. |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 248 | static bool hasComputableBounds(ScalarEvolution *SE, |
| 249 | const ValueToValueMap &Strides, Value *Ptr) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 250 | const SCEV *PtrScev = replaceSymbolicStrideSCEV(SE, Strides, Ptr); |
| 251 | const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrScev); |
| 252 | if (!AR) |
| 253 | return false; |
| 254 | |
| 255 | return AR->isAffine(); |
| 256 | } |
| 257 | |
| 258 | /// \brief Check the stride of the pointer and ensure that it does not wrap in |
| 259 | /// the address space. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 260 | static int isStridedPtr(ScalarEvolution *SE, Value *Ptr, const Loop *Lp, |
| 261 | const ValueToValueMap &StridesMap); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 262 | |
| 263 | bool AccessAnalysis::canCheckPtrAtRT( |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 264 | LoopAccessInfo::RuntimePointerCheck &RtCheck, unsigned &NumComparisons, |
| 265 | ScalarEvolution *SE, Loop *TheLoop, const ValueToValueMap &StridesMap, |
| 266 | bool ShouldCheckStride) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 267 | // Find pointers with computable bounds. We are going to use this information |
| 268 | // to place a runtime bound check. |
| 269 | bool CanDoRT = true; |
| 270 | |
| 271 | bool IsDepCheckNeeded = isDependencyCheckNeeded(); |
| 272 | NumComparisons = 0; |
| 273 | |
| 274 | // We assign a consecutive id to access from different alias sets. |
| 275 | // Accesses between different groups doesn't need to be checked. |
| 276 | unsigned ASId = 1; |
| 277 | for (auto &AS : AST) { |
| 278 | unsigned NumReadPtrChecks = 0; |
| 279 | unsigned NumWritePtrChecks = 0; |
| 280 | |
| 281 | // We assign consecutive id to access from different dependence sets. |
| 282 | // Accesses within the same set don't need a runtime check. |
| 283 | unsigned RunningDepId = 1; |
| 284 | DenseMap<Value *, unsigned> DepSetId; |
| 285 | |
| 286 | for (auto A : AS) { |
| 287 | Value *Ptr = A.getValue(); |
| 288 | bool IsWrite = Accesses.count(MemAccessInfo(Ptr, true)); |
| 289 | MemAccessInfo Access(Ptr, IsWrite); |
| 290 | |
| 291 | if (IsWrite) |
| 292 | ++NumWritePtrChecks; |
| 293 | else |
| 294 | ++NumReadPtrChecks; |
| 295 | |
| 296 | if (hasComputableBounds(SE, StridesMap, Ptr) && |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 297 | // When we run after a failing dependency check we have to make sure |
| 298 | // we don't have wrapping pointers. |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 299 | (!ShouldCheckStride || |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 300 | isStridedPtr(SE, Ptr, TheLoop, StridesMap) == 1)) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 301 | // The id of the dependence set. |
| 302 | unsigned DepId; |
| 303 | |
| 304 | if (IsDepCheckNeeded) { |
| 305 | Value *Leader = DepCands.getLeaderValue(Access).getPointer(); |
| 306 | unsigned &LeaderId = DepSetId[Leader]; |
| 307 | if (!LeaderId) |
| 308 | LeaderId = RunningDepId++; |
| 309 | DepId = LeaderId; |
| 310 | } else |
| 311 | // Each access has its own dependence set. |
| 312 | DepId = RunningDepId++; |
| 313 | |
| 314 | RtCheck.insert(SE, TheLoop, Ptr, IsWrite, DepId, ASId, StridesMap); |
| 315 | |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 316 | DEBUG(dbgs() << "LAA: Found a runtime check ptr:" << *Ptr << '\n'); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 317 | } else { |
| 318 | CanDoRT = false; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | if (IsDepCheckNeeded && CanDoRT && RunningDepId == 2) |
| 323 | NumComparisons += 0; // Only one dependence set. |
| 324 | else { |
| 325 | NumComparisons += (NumWritePtrChecks * (NumReadPtrChecks + |
| 326 | NumWritePtrChecks - 1)); |
| 327 | } |
| 328 | |
| 329 | ++ASId; |
| 330 | } |
| 331 | |
| 332 | // If the pointers that we would use for the bounds comparison have different |
| 333 | // address spaces, assume the values aren't directly comparable, so we can't |
| 334 | // use them for the runtime check. We also have to assume they could |
| 335 | // overlap. In the future there should be metadata for whether address spaces |
| 336 | // are disjoint. |
| 337 | unsigned NumPointers = RtCheck.Pointers.size(); |
| 338 | for (unsigned i = 0; i < NumPointers; ++i) { |
| 339 | for (unsigned j = i + 1; j < NumPointers; ++j) { |
| 340 | // Only need to check pointers between two different dependency sets. |
| 341 | if (RtCheck.DependencySetId[i] == RtCheck.DependencySetId[j]) |
| 342 | continue; |
| 343 | // Only need to check pointers in the same alias set. |
| 344 | if (RtCheck.AliasSetId[i] != RtCheck.AliasSetId[j]) |
| 345 | continue; |
| 346 | |
| 347 | Value *PtrI = RtCheck.Pointers[i]; |
| 348 | Value *PtrJ = RtCheck.Pointers[j]; |
| 349 | |
| 350 | unsigned ASi = PtrI->getType()->getPointerAddressSpace(); |
| 351 | unsigned ASj = PtrJ->getType()->getPointerAddressSpace(); |
| 352 | if (ASi != ASj) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 353 | DEBUG(dbgs() << "LAA: Runtime check would require comparison between" |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 354 | " different address spaces\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 355 | return false; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | return CanDoRT; |
| 361 | } |
| 362 | |
| 363 | void AccessAnalysis::processMemAccesses() { |
| 364 | // We process the set twice: first we process read-write pointers, last we |
| 365 | // process read-only pointers. This allows us to skip dependence tests for |
| 366 | // read-only pointers. |
| 367 | |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 368 | DEBUG(dbgs() << "LAA: Processing memory accesses...\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 369 | DEBUG(dbgs() << " AST: "; AST.dump()); |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 370 | DEBUG(dbgs() << "LAA: Accesses(" << Accesses.size() << "):\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 371 | DEBUG({ |
| 372 | for (auto A : Accesses) |
| 373 | dbgs() << "\t" << *A.getPointer() << " (" << |
| 374 | (A.getInt() ? "write" : (ReadOnlyPtr.count(A.getPointer()) ? |
| 375 | "read-only" : "read")) << ")\n"; |
| 376 | }); |
| 377 | |
| 378 | // The AliasSetTracker has nicely partitioned our pointers by metadata |
| 379 | // compatibility and potential for underlying-object overlap. As a result, we |
| 380 | // only need to check for potential pointer dependencies within each alias |
| 381 | // set. |
| 382 | for (auto &AS : AST) { |
| 383 | // Note that both the alias-set tracker and the alias sets themselves used |
| 384 | // linked lists internally and so the iteration order here is deterministic |
| 385 | // (matching the original instruction order within each set). |
| 386 | |
| 387 | bool SetHasWrite = false; |
| 388 | |
| 389 | // Map of pointers to last access encountered. |
| 390 | typedef DenseMap<Value*, MemAccessInfo> UnderlyingObjToAccessMap; |
| 391 | UnderlyingObjToAccessMap ObjToLastAccess; |
| 392 | |
| 393 | // Set of access to check after all writes have been processed. |
| 394 | PtrAccessSet DeferredAccesses; |
| 395 | |
| 396 | // Iterate over each alias set twice, once to process read/write pointers, |
| 397 | // and then to process read-only pointers. |
| 398 | for (int SetIteration = 0; SetIteration < 2; ++SetIteration) { |
| 399 | bool UseDeferred = SetIteration > 0; |
| 400 | PtrAccessSet &S = UseDeferred ? DeferredAccesses : Accesses; |
| 401 | |
| 402 | for (auto AV : AS) { |
| 403 | Value *Ptr = AV.getValue(); |
| 404 | |
| 405 | // For a single memory access in AliasSetTracker, Accesses may contain |
| 406 | // both read and write, and they both need to be handled for CheckDeps. |
| 407 | for (auto AC : S) { |
| 408 | if (AC.getPointer() != Ptr) |
| 409 | continue; |
| 410 | |
| 411 | bool IsWrite = AC.getInt(); |
| 412 | |
| 413 | // If we're using the deferred access set, then it contains only |
| 414 | // reads. |
| 415 | bool IsReadOnlyPtr = ReadOnlyPtr.count(Ptr) && !IsWrite; |
| 416 | if (UseDeferred && !IsReadOnlyPtr) |
| 417 | continue; |
| 418 | // Otherwise, the pointer must be in the PtrAccessSet, either as a |
| 419 | // read or a write. |
| 420 | assert(((IsReadOnlyPtr && UseDeferred) || IsWrite || |
| 421 | S.count(MemAccessInfo(Ptr, false))) && |
| 422 | "Alias-set pointer not in the access set?"); |
| 423 | |
| 424 | MemAccessInfo Access(Ptr, IsWrite); |
| 425 | DepCands.insert(Access); |
| 426 | |
| 427 | // Memorize read-only pointers for later processing and skip them in |
| 428 | // the first round (they need to be checked after we have seen all |
| 429 | // write pointers). Note: we also mark pointer that are not |
| 430 | // consecutive as "read-only" pointers (so that we check |
| 431 | // "a[b[i]] +="). Hence, we need the second check for "!IsWrite". |
| 432 | if (!UseDeferred && IsReadOnlyPtr) { |
| 433 | DeferredAccesses.insert(Access); |
| 434 | continue; |
| 435 | } |
| 436 | |
| 437 | // If this is a write - check other reads and writes for conflicts. If |
| 438 | // this is a read only check other writes for conflicts (but only if |
| 439 | // there is no other write to the ptr - this is an optimization to |
| 440 | // catch "a[i] = a[i] + " without having to do a dependence check). |
| 441 | if ((IsWrite || IsReadOnlyPtr) && SetHasWrite) { |
| 442 | CheckDeps.insert(Access); |
| 443 | IsRTCheckNeeded = true; |
| 444 | } |
| 445 | |
| 446 | if (IsWrite) |
| 447 | SetHasWrite = true; |
| 448 | |
| 449 | // Create sets of pointers connected by a shared alias set and |
| 450 | // underlying object. |
| 451 | typedef SmallVector<Value *, 16> ValueVector; |
| 452 | ValueVector TempObjects; |
| 453 | GetUnderlyingObjects(Ptr, TempObjects, DL); |
| 454 | for (Value *UnderlyingObj : TempObjects) { |
| 455 | UnderlyingObjToAccessMap::iterator Prev = |
| 456 | ObjToLastAccess.find(UnderlyingObj); |
| 457 | if (Prev != ObjToLastAccess.end()) |
| 458 | DepCands.unionSets(Access, Prev->second); |
| 459 | |
| 460 | ObjToLastAccess[UnderlyingObj] = Access; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 468 | static bool isInBoundsGep(Value *Ptr) { |
| 469 | if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) |
| 470 | return GEP->isInBounds(); |
| 471 | return false; |
| 472 | } |
| 473 | |
| 474 | /// \brief Check whether the access through \p Ptr has a constant stride. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 475 | static int isStridedPtr(ScalarEvolution *SE, Value *Ptr, const Loop *Lp, |
| 476 | const ValueToValueMap &StridesMap) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 477 | const Type *Ty = Ptr->getType(); |
| 478 | assert(Ty->isPointerTy() && "Unexpected non-ptr"); |
| 479 | |
| 480 | // Make sure that the pointer does not point to aggregate types. |
| 481 | const PointerType *PtrTy = cast<PointerType>(Ty); |
| 482 | if (PtrTy->getElementType()->isAggregateType()) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 483 | DEBUG(dbgs() << "LAA: Bad stride - Not a pointer to a scalar type" |
| 484 | << *Ptr << "\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | const SCEV *PtrScev = replaceSymbolicStrideSCEV(SE, StridesMap, Ptr); |
| 489 | |
| 490 | const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrScev); |
| 491 | if (!AR) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 492 | DEBUG(dbgs() << "LAA: Bad stride - Not an AddRecExpr pointer " |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 493 | << *Ptr << " SCEV: " << *PtrScev << "\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | // The accesss function must stride over the innermost loop. |
| 498 | if (Lp != AR->getLoop()) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 499 | DEBUG(dbgs() << "LAA: Bad stride - Not striding over innermost loop " << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 500 | *Ptr << " SCEV: " << *PtrScev << "\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | // The address calculation must not wrap. Otherwise, a dependence could be |
| 504 | // inverted. |
| 505 | // An inbounds getelementptr that is a AddRec with a unit stride |
| 506 | // cannot wrap per definition. The unit stride requirement is checked later. |
| 507 | // An getelementptr without an inbounds attribute and unit stride would have |
| 508 | // to access the pointer value "0" which is undefined behavior in address |
| 509 | // space 0, therefore we can also vectorize this case. |
| 510 | bool IsInBoundsGEP = isInBoundsGep(Ptr); |
| 511 | bool IsNoWrapAddRec = AR->getNoWrapFlags(SCEV::NoWrapMask); |
| 512 | bool IsInAddressSpaceZero = PtrTy->getAddressSpace() == 0; |
| 513 | if (!IsNoWrapAddRec && !IsInBoundsGEP && !IsInAddressSpaceZero) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 514 | DEBUG(dbgs() << "LAA: Bad stride - Pointer may wrap in the address space " |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 515 | << *Ptr << " SCEV: " << *PtrScev << "\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | // Check the step is constant. |
| 520 | const SCEV *Step = AR->getStepRecurrence(*SE); |
| 521 | |
| 522 | // Calculate the pointer stride and check if it is consecutive. |
| 523 | const SCEVConstant *C = dyn_cast<SCEVConstant>(Step); |
| 524 | if (!C) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 525 | DEBUG(dbgs() << "LAA: Bad stride - Not a constant strided " << *Ptr << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 526 | " SCEV: " << *PtrScev << "\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 527 | return 0; |
| 528 | } |
| 529 | |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 530 | auto &DL = Lp->getHeader()->getModule()->getDataLayout(); |
| 531 | int64_t Size = DL.getTypeAllocSize(PtrTy->getElementType()); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 532 | const APInt &APStepVal = C->getValue()->getValue(); |
| 533 | |
| 534 | // Huge step value - give up. |
| 535 | if (APStepVal.getBitWidth() > 64) |
| 536 | return 0; |
| 537 | |
| 538 | int64_t StepVal = APStepVal.getSExtValue(); |
| 539 | |
| 540 | // Strided access. |
| 541 | int64_t Stride = StepVal / Size; |
| 542 | int64_t Rem = StepVal % Size; |
| 543 | if (Rem) |
| 544 | return 0; |
| 545 | |
| 546 | // If the SCEV could wrap but we have an inbounds gep with a unit stride we |
| 547 | // know we can't "wrap around the address space". In case of address space |
| 548 | // zero we know that this won't happen without triggering undefined behavior. |
| 549 | if (!IsNoWrapAddRec && (IsInBoundsGEP || IsInAddressSpaceZero) && |
| 550 | Stride != 1 && Stride != -1) |
| 551 | return 0; |
| 552 | |
| 553 | return Stride; |
| 554 | } |
| 555 | |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 556 | bool MemoryDepChecker::Dependence::isSafeForVectorization(DepType Type) { |
| 557 | switch (Type) { |
| 558 | case NoDep: |
| 559 | case Forward: |
| 560 | case BackwardVectorizable: |
| 561 | return true; |
| 562 | |
| 563 | case Unknown: |
| 564 | case ForwardButPreventsForwarding: |
| 565 | case Backward: |
| 566 | case BackwardVectorizableButPreventsForwarding: |
| 567 | return false; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | bool MemoryDepChecker::Dependence::isInterestingDependence(DepType Type) { |
| 572 | switch (Type) { |
| 573 | case NoDep: |
| 574 | case Forward: |
| 575 | return false; |
| 576 | |
| 577 | case BackwardVectorizable: |
| 578 | case Unknown: |
| 579 | case ForwardButPreventsForwarding: |
| 580 | case Backward: |
| 581 | case BackwardVectorizableButPreventsForwarding: |
| 582 | return true; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | bool MemoryDepChecker::Dependence::isPossiblyBackward() const { |
| 587 | switch (Type) { |
| 588 | case NoDep: |
| 589 | case Forward: |
| 590 | case ForwardButPreventsForwarding: |
| 591 | return false; |
| 592 | |
| 593 | case Unknown: |
| 594 | case BackwardVectorizable: |
| 595 | case Backward: |
| 596 | case BackwardVectorizableButPreventsForwarding: |
| 597 | return true; |
| 598 | } |
| 599 | } |
| 600 | |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 601 | bool MemoryDepChecker::couldPreventStoreLoadForward(unsigned Distance, |
| 602 | unsigned TypeByteSize) { |
| 603 | // If loads occur at a distance that is not a multiple of a feasible vector |
| 604 | // factor store-load forwarding does not take place. |
| 605 | // Positive dependences might cause troubles because vectorizing them might |
| 606 | // prevent store-load forwarding making vectorized code run a lot slower. |
| 607 | // a[i] = a[i-3] ^ a[i-8]; |
| 608 | // The stores to a[i:i+1] don't align with the stores to a[i-3:i-2] and |
| 609 | // hence on your typical architecture store-load forwarding does not take |
| 610 | // place. Vectorizing in such cases does not make sense. |
| 611 | // Store-load forwarding distance. |
| 612 | const unsigned NumCyclesForStoreLoadThroughMemory = 8*TypeByteSize; |
| 613 | // Maximum vector factor. |
Adam Nemet | f219c64 | 2015-02-19 19:14:52 +0000 | [diff] [blame] | 614 | unsigned MaxVFWithoutSLForwardIssues = |
| 615 | VectorizerParams::MaxVectorWidth * TypeByteSize; |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 616 | if(MaxSafeDepDistBytes < MaxVFWithoutSLForwardIssues) |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 617 | MaxVFWithoutSLForwardIssues = MaxSafeDepDistBytes; |
| 618 | |
| 619 | for (unsigned vf = 2*TypeByteSize; vf <= MaxVFWithoutSLForwardIssues; |
| 620 | vf *= 2) { |
| 621 | if (Distance % vf && Distance / vf < NumCyclesForStoreLoadThroughMemory) { |
| 622 | MaxVFWithoutSLForwardIssues = (vf >>=1); |
| 623 | break; |
| 624 | } |
| 625 | } |
| 626 | |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 627 | if (MaxVFWithoutSLForwardIssues< 2*TypeByteSize) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 628 | DEBUG(dbgs() << "LAA: Distance " << Distance << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 629 | " that could cause a store-load forwarding conflict\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 630 | return true; |
| 631 | } |
| 632 | |
| 633 | if (MaxVFWithoutSLForwardIssues < MaxSafeDepDistBytes && |
Adam Nemet | f219c64 | 2015-02-19 19:14:52 +0000 | [diff] [blame] | 634 | MaxVFWithoutSLForwardIssues != |
| 635 | VectorizerParams::MaxVectorWidth * TypeByteSize) |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 636 | MaxSafeDepDistBytes = MaxVFWithoutSLForwardIssues; |
| 637 | return false; |
| 638 | } |
| 639 | |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 640 | MemoryDepChecker::Dependence::DepType |
| 641 | MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, |
| 642 | const MemAccessInfo &B, unsigned BIdx, |
| 643 | const ValueToValueMap &Strides) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 644 | assert (AIdx < BIdx && "Must pass arguments in program order"); |
| 645 | |
| 646 | Value *APtr = A.getPointer(); |
| 647 | Value *BPtr = B.getPointer(); |
| 648 | bool AIsWrite = A.getInt(); |
| 649 | bool BIsWrite = B.getInt(); |
| 650 | |
| 651 | // Two reads are independent. |
| 652 | if (!AIsWrite && !BIsWrite) |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 653 | return Dependence::NoDep; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 654 | |
| 655 | // We cannot check pointers in different address spaces. |
| 656 | if (APtr->getType()->getPointerAddressSpace() != |
| 657 | BPtr->getType()->getPointerAddressSpace()) |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 658 | return Dependence::Unknown; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 659 | |
| 660 | const SCEV *AScev = replaceSymbolicStrideSCEV(SE, Strides, APtr); |
| 661 | const SCEV *BScev = replaceSymbolicStrideSCEV(SE, Strides, BPtr); |
| 662 | |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 663 | int StrideAPtr = isStridedPtr(SE, APtr, InnermostLoop, Strides); |
| 664 | int StrideBPtr = isStridedPtr(SE, BPtr, InnermostLoop, Strides); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 665 | |
| 666 | const SCEV *Src = AScev; |
| 667 | const SCEV *Sink = BScev; |
| 668 | |
| 669 | // If the induction step is negative we have to invert source and sink of the |
| 670 | // dependence. |
| 671 | if (StrideAPtr < 0) { |
| 672 | //Src = BScev; |
| 673 | //Sink = AScev; |
| 674 | std::swap(APtr, BPtr); |
| 675 | std::swap(Src, Sink); |
| 676 | std::swap(AIsWrite, BIsWrite); |
| 677 | std::swap(AIdx, BIdx); |
| 678 | std::swap(StrideAPtr, StrideBPtr); |
| 679 | } |
| 680 | |
| 681 | const SCEV *Dist = SE->getMinusSCEV(Sink, Src); |
| 682 | |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 683 | DEBUG(dbgs() << "LAA: Src Scev: " << *Src << "Sink Scev: " << *Sink |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 684 | << "(Induction step: " << StrideAPtr << ")\n"); |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 685 | DEBUG(dbgs() << "LAA: Distance for " << *InstMap[AIdx] << " to " |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 686 | << *InstMap[BIdx] << ": " << *Dist << "\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 687 | |
| 688 | // Need consecutive accesses. We don't want to vectorize |
| 689 | // "A[B[i]] += ..." and similar code or pointer arithmetic that could wrap in |
| 690 | // the address space. |
| 691 | if (!StrideAPtr || !StrideBPtr || StrideAPtr != StrideBPtr){ |
| 692 | DEBUG(dbgs() << "Non-consecutive pointer access\n"); |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 693 | return Dependence::Unknown; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist); |
| 697 | if (!C) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 698 | DEBUG(dbgs() << "LAA: Dependence because of non-constant distance\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 699 | ShouldRetryWithRuntimeCheck = true; |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 700 | return Dependence::Unknown; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | Type *ATy = APtr->getType()->getPointerElementType(); |
| 704 | Type *BTy = BPtr->getType()->getPointerElementType(); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 705 | auto &DL = InnermostLoop->getHeader()->getModule()->getDataLayout(); |
| 706 | unsigned TypeByteSize = DL.getTypeAllocSize(ATy); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 707 | |
| 708 | // Negative distances are not plausible dependencies. |
| 709 | const APInt &Val = C->getValue()->getValue(); |
| 710 | if (Val.isNegative()) { |
| 711 | bool IsTrueDataDependence = (AIsWrite && !BIsWrite); |
| 712 | if (IsTrueDataDependence && |
| 713 | (couldPreventStoreLoadForward(Val.abs().getZExtValue(), TypeByteSize) || |
| 714 | ATy != BTy)) |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 715 | return Dependence::ForwardButPreventsForwarding; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 716 | |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 717 | DEBUG(dbgs() << "LAA: Dependence is negative: NoDep\n"); |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 718 | return Dependence::Forward; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | // Write to the same location with the same size. |
| 722 | // Could be improved to assert type sizes are the same (i32 == float, etc). |
| 723 | if (Val == 0) { |
| 724 | if (ATy == BTy) |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 725 | return Dependence::NoDep; |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 726 | DEBUG(dbgs() << "LAA: Zero dependence difference but different types\n"); |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 727 | return Dependence::Unknown; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | assert(Val.isStrictlyPositive() && "Expect a positive value"); |
| 731 | |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 732 | if (ATy != BTy) { |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 733 | DEBUG(dbgs() << |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 734 | "LAA: ReadWrite-Write positive dependency with different types\n"); |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 735 | return Dependence::Unknown; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | unsigned Distance = (unsigned) Val.getZExtValue(); |
| 739 | |
| 740 | // Bail out early if passed-in parameters make vectorization not feasible. |
Adam Nemet | f219c64 | 2015-02-19 19:14:52 +0000 | [diff] [blame] | 741 | unsigned ForcedFactor = (VectorizerParams::VectorizationFactor ? |
| 742 | VectorizerParams::VectorizationFactor : 1); |
| 743 | unsigned ForcedUnroll = (VectorizerParams::VectorizationInterleave ? |
| 744 | VectorizerParams::VectorizationInterleave : 1); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 745 | |
| 746 | // The distance must be bigger than the size needed for a vectorized version |
| 747 | // of the operation and the size of the vectorized operation must not be |
| 748 | // bigger than the currrent maximum size. |
| 749 | if (Distance < 2*TypeByteSize || |
| 750 | 2*TypeByteSize > MaxSafeDepDistBytes || |
| 751 | Distance < TypeByteSize * ForcedUnroll * ForcedFactor) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 752 | DEBUG(dbgs() << "LAA: Failure because of Positive distance " |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 753 | << Val.getSExtValue() << '\n'); |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 754 | return Dependence::Backward; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Adam Nemet | 9cc0c39 | 2015-02-26 17:58:48 +0000 | [diff] [blame] | 757 | // Positive distance bigger than max vectorization factor. |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 758 | MaxSafeDepDistBytes = Distance < MaxSafeDepDistBytes ? |
| 759 | Distance : MaxSafeDepDistBytes; |
| 760 | |
| 761 | bool IsTrueDataDependence = (!AIsWrite && BIsWrite); |
| 762 | if (IsTrueDataDependence && |
| 763 | couldPreventStoreLoadForward(Distance, TypeByteSize)) |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 764 | return Dependence::BackwardVectorizableButPreventsForwarding; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 765 | |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 766 | DEBUG(dbgs() << "LAA: Positive distance " << Val.getSExtValue() << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 767 | " with max VF = " << MaxSafeDepDistBytes / TypeByteSize << '\n'); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 768 | |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 769 | return Dependence::BackwardVectorizable; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 770 | } |
| 771 | |
Adam Nemet | dee666b | 2015-03-10 17:40:34 +0000 | [diff] [blame] | 772 | bool MemoryDepChecker::areDepsSafe(DepCandidates &AccessSets, |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 773 | MemAccessInfoSet &CheckDeps, |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 774 | const ValueToValueMap &Strides) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 775 | |
| 776 | MaxSafeDepDistBytes = -1U; |
| 777 | while (!CheckDeps.empty()) { |
| 778 | MemAccessInfo CurAccess = *CheckDeps.begin(); |
| 779 | |
| 780 | // Get the relevant memory access set. |
| 781 | EquivalenceClasses<MemAccessInfo>::iterator I = |
| 782 | AccessSets.findValue(AccessSets.getLeaderValue(CurAccess)); |
| 783 | |
| 784 | // Check accesses within this set. |
| 785 | EquivalenceClasses<MemAccessInfo>::member_iterator AI, AE; |
| 786 | AI = AccessSets.member_begin(I), AE = AccessSets.member_end(); |
| 787 | |
| 788 | // Check every access pair. |
| 789 | while (AI != AE) { |
| 790 | CheckDeps.erase(*AI); |
| 791 | EquivalenceClasses<MemAccessInfo>::member_iterator OI = std::next(AI); |
| 792 | while (OI != AE) { |
| 793 | // Check every accessing instruction pair in program order. |
| 794 | for (std::vector<unsigned>::iterator I1 = Accesses[*AI].begin(), |
| 795 | I1E = Accesses[*AI].end(); I1 != I1E; ++I1) |
| 796 | for (std::vector<unsigned>::iterator I2 = Accesses[*OI].begin(), |
| 797 | I2E = Accesses[*OI].end(); I2 != I2E; ++I2) { |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 798 | auto A = std::make_pair(&*AI, *I1); |
| 799 | auto B = std::make_pair(&*OI, *I2); |
| 800 | |
| 801 | assert(*I1 != *I2); |
| 802 | if (*I1 > *I2) |
| 803 | std::swap(A, B); |
| 804 | |
| 805 | Dependence::DepType Type = |
| 806 | isDependent(*A.first, A.second, *B.first, B.second, Strides); |
| 807 | SafeForVectorization &= Dependence::isSafeForVectorization(Type); |
| 808 | |
| 809 | // Gather dependences unless we accumulated MaxInterestingDependence |
| 810 | // dependences. In that case return as soon as we find the first |
| 811 | // unsafe dependence. This puts a limit on this quadratic |
| 812 | // algorithm. |
| 813 | if (RecordInterestingDependences) { |
| 814 | if (Dependence::isInterestingDependence(Type)) |
| 815 | InterestingDependences.push_back( |
| 816 | Dependence(A.second, B.second, Type)); |
| 817 | |
| 818 | if (InterestingDependences.size() >= MaxInterestingDependence) { |
| 819 | RecordInterestingDependences = false; |
| 820 | InterestingDependences.clear(); |
| 821 | DEBUG(dbgs() << "Too many dependences, stopped recording\n"); |
| 822 | } |
| 823 | } |
| 824 | if (!RecordInterestingDependences && !SafeForVectorization) |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 825 | return false; |
| 826 | } |
| 827 | ++OI; |
| 828 | } |
| 829 | AI++; |
| 830 | } |
| 831 | } |
Adam Nemet | 9c92657 | 2015-03-10 17:40:37 +0000 | [diff] [blame] | 832 | |
| 833 | DEBUG(dbgs() << "Total Interesting Dependences: " |
| 834 | << InterestingDependences.size() << "\n"); |
| 835 | return SafeForVectorization; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Adam Nemet | 58913d6 | 2015-03-10 17:40:43 +0000 | [diff] [blame] | 838 | const char *MemoryDepChecker::Dependence::DepName[] = { |
| 839 | "NoDep", "Unknown", "Forward", "ForwardButPreventsForwarding", "Backward", |
| 840 | "BackwardVectorizable", "BackwardVectorizableButPreventsForwarding"}; |
| 841 | |
| 842 | void MemoryDepChecker::Dependence::print( |
| 843 | raw_ostream &OS, unsigned Depth, |
| 844 | const SmallVectorImpl<Instruction *> &Instrs) const { |
| 845 | OS.indent(Depth) << DepName[Type] << ":\n"; |
| 846 | OS.indent(Depth + 2) << *Instrs[Source] << " -> \n"; |
| 847 | OS.indent(Depth + 2) << *Instrs[Destination] << "\n"; |
| 848 | } |
| 849 | |
Adam Nemet | 929c38e | 2015-02-19 19:15:10 +0000 | [diff] [blame] | 850 | bool LoopAccessInfo::canAnalyzeLoop() { |
| 851 | // We can only analyze innermost loops. |
| 852 | if (!TheLoop->empty()) { |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 853 | emitAnalysis(LoopAccessReport() << "loop is not the innermost loop"); |
Adam Nemet | 929c38e | 2015-02-19 19:15:10 +0000 | [diff] [blame] | 854 | return false; |
| 855 | } |
| 856 | |
| 857 | // We must have a single backedge. |
| 858 | if (TheLoop->getNumBackEdges() != 1) { |
| 859 | emitAnalysis( |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 860 | LoopAccessReport() << |
Adam Nemet | 929c38e | 2015-02-19 19:15:10 +0000 | [diff] [blame] | 861 | "loop control flow is not understood by analyzer"); |
| 862 | return false; |
| 863 | } |
| 864 | |
| 865 | // We must have a single exiting block. |
| 866 | if (!TheLoop->getExitingBlock()) { |
| 867 | emitAnalysis( |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 868 | LoopAccessReport() << |
Adam Nemet | 929c38e | 2015-02-19 19:15:10 +0000 | [diff] [blame] | 869 | "loop control flow is not understood by analyzer"); |
| 870 | return false; |
| 871 | } |
| 872 | |
| 873 | // We only handle bottom-tested loops, i.e. loop in which the condition is |
| 874 | // checked at the end of each iteration. With that we can assume that all |
| 875 | // instructions in the loop are executed the same number of times. |
| 876 | if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) { |
| 877 | emitAnalysis( |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 878 | LoopAccessReport() << |
Adam Nemet | 929c38e | 2015-02-19 19:15:10 +0000 | [diff] [blame] | 879 | "loop control flow is not understood by analyzer"); |
| 880 | return false; |
| 881 | } |
| 882 | |
| 883 | // We need to have a loop header. |
| 884 | DEBUG(dbgs() << "LAA: Found a loop: " << |
| 885 | TheLoop->getHeader()->getName() << '\n'); |
| 886 | |
| 887 | // ScalarEvolution needs to be able to find the exit count. |
| 888 | const SCEV *ExitCount = SE->getBackedgeTakenCount(TheLoop); |
| 889 | if (ExitCount == SE->getCouldNotCompute()) { |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 890 | emitAnalysis(LoopAccessReport() << |
Adam Nemet | 929c38e | 2015-02-19 19:15:10 +0000 | [diff] [blame] | 891 | "could not determine number of loop iterations"); |
| 892 | DEBUG(dbgs() << "LAA: SCEV could not compute the loop exit count.\n"); |
| 893 | return false; |
| 894 | } |
| 895 | |
| 896 | return true; |
| 897 | } |
| 898 | |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 899 | void LoopAccessInfo::analyzeLoop(const ValueToValueMap &Strides) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 900 | |
| 901 | typedef SmallVector<Value*, 16> ValueVector; |
| 902 | typedef SmallPtrSet<Value*, 16> ValueSet; |
| 903 | |
| 904 | // Holds the Load and Store *instructions*. |
| 905 | ValueVector Loads; |
| 906 | ValueVector Stores; |
| 907 | |
| 908 | // Holds all the different accesses in the loop. |
| 909 | unsigned NumReads = 0; |
| 910 | unsigned NumReadWrites = 0; |
| 911 | |
| 912 | PtrRtCheck.Pointers.clear(); |
| 913 | PtrRtCheck.Need = false; |
| 914 | |
| 915 | const bool IsAnnotatedParallel = TheLoop->isAnnotatedParallel(); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 916 | |
| 917 | // For each block. |
| 918 | for (Loop::block_iterator bb = TheLoop->block_begin(), |
| 919 | be = TheLoop->block_end(); bb != be; ++bb) { |
| 920 | |
| 921 | // Scan the BB and collect legal loads and stores. |
| 922 | for (BasicBlock::iterator it = (*bb)->begin(), e = (*bb)->end(); it != e; |
| 923 | ++it) { |
| 924 | |
| 925 | // If this is a load, save it. If this instruction can read from memory |
| 926 | // but is not a load, then we quit. Notice that we don't handle function |
| 927 | // calls that read or write. |
| 928 | if (it->mayReadFromMemory()) { |
| 929 | // Many math library functions read the rounding mode. We will only |
| 930 | // vectorize a loop if it contains known function calls that don't set |
| 931 | // the flag. Therefore, it is safe to ignore this read from memory. |
| 932 | CallInst *Call = dyn_cast<CallInst>(it); |
| 933 | if (Call && getIntrinsicIDForCall(Call, TLI)) |
| 934 | continue; |
| 935 | |
| 936 | LoadInst *Ld = dyn_cast<LoadInst>(it); |
| 937 | if (!Ld || (!Ld->isSimple() && !IsAnnotatedParallel)) { |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 938 | emitAnalysis(LoopAccessReport(Ld) |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 939 | << "read with atomic ordering or volatile read"); |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 940 | DEBUG(dbgs() << "LAA: Found a non-simple load.\n"); |
Adam Nemet | 436018c | 2015-02-19 19:15:00 +0000 | [diff] [blame] | 941 | CanVecMem = false; |
| 942 | return; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 943 | } |
| 944 | NumLoads++; |
| 945 | Loads.push_back(Ld); |
| 946 | DepChecker.addAccess(Ld); |
| 947 | continue; |
| 948 | } |
| 949 | |
| 950 | // Save 'store' instructions. Abort if other instructions write to memory. |
| 951 | if (it->mayWriteToMemory()) { |
| 952 | StoreInst *St = dyn_cast<StoreInst>(it); |
| 953 | if (!St) { |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 954 | emitAnalysis(LoopAccessReport(it) << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 955 | "instruction cannot be vectorized"); |
Adam Nemet | 436018c | 2015-02-19 19:15:00 +0000 | [diff] [blame] | 956 | CanVecMem = false; |
| 957 | return; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 958 | } |
| 959 | if (!St->isSimple() && !IsAnnotatedParallel) { |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 960 | emitAnalysis(LoopAccessReport(St) |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 961 | << "write with atomic ordering or volatile write"); |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 962 | DEBUG(dbgs() << "LAA: Found a non-simple store.\n"); |
Adam Nemet | 436018c | 2015-02-19 19:15:00 +0000 | [diff] [blame] | 963 | CanVecMem = false; |
| 964 | return; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 965 | } |
| 966 | NumStores++; |
| 967 | Stores.push_back(St); |
| 968 | DepChecker.addAccess(St); |
| 969 | } |
| 970 | } // Next instr. |
| 971 | } // Next block. |
| 972 | |
| 973 | // Now we have two lists that hold the loads and the stores. |
| 974 | // Next, we find the pointers that they use. |
| 975 | |
| 976 | // Check if we see any stores. If there are no stores, then we don't |
| 977 | // care if the pointers are *restrict*. |
| 978 | if (!Stores.size()) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 979 | DEBUG(dbgs() << "LAA: Found a read-only loop!\n"); |
Adam Nemet | 436018c | 2015-02-19 19:15:00 +0000 | [diff] [blame] | 980 | CanVecMem = true; |
| 981 | return; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Adam Nemet | dee666b | 2015-03-10 17:40:34 +0000 | [diff] [blame] | 984 | MemoryDepChecker::DepCandidates DependentAccesses; |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 985 | AccessAnalysis Accesses(TheLoop->getHeader()->getModule()->getDataLayout(), |
| 986 | AA, DependentAccesses); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 987 | |
| 988 | // Holds the analyzed pointers. We don't want to call GetUnderlyingObjects |
| 989 | // multiple times on the same object. If the ptr is accessed twice, once |
| 990 | // for read and once for write, it will only appear once (on the write |
| 991 | // list). This is okay, since we are going to check for conflicts between |
| 992 | // writes and between reads and writes, but not between reads and reads. |
| 993 | ValueSet Seen; |
| 994 | |
| 995 | ValueVector::iterator I, IE; |
| 996 | for (I = Stores.begin(), IE = Stores.end(); I != IE; ++I) { |
| 997 | StoreInst *ST = cast<StoreInst>(*I); |
| 998 | Value* Ptr = ST->getPointerOperand(); |
| 999 | |
| 1000 | if (isUniform(Ptr)) { |
| 1001 | emitAnalysis( |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 1002 | LoopAccessReport(ST) |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1003 | << "write to a loop invariant address could not be vectorized"); |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1004 | DEBUG(dbgs() << "LAA: We don't allow storing to uniform addresses\n"); |
Adam Nemet | 436018c | 2015-02-19 19:15:00 +0000 | [diff] [blame] | 1005 | CanVecMem = false; |
| 1006 | return; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | // If we did *not* see this pointer before, insert it to the read-write |
| 1010 | // list. At this phase it is only a 'write' list. |
| 1011 | if (Seen.insert(Ptr).second) { |
| 1012 | ++NumReadWrites; |
| 1013 | |
| 1014 | AliasAnalysis::Location Loc = AA->getLocation(ST); |
| 1015 | // The TBAA metadata could have a control dependency on the predication |
| 1016 | // condition, so we cannot rely on it when determining whether or not we |
| 1017 | // need runtime pointer checks. |
Adam Nemet | 01abb2c | 2015-02-18 03:43:19 +0000 | [diff] [blame] | 1018 | if (blockNeedsPredication(ST->getParent(), TheLoop, DT)) |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1019 | Loc.AATags.TBAA = nullptr; |
| 1020 | |
| 1021 | Accesses.addStore(Loc); |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | if (IsAnnotatedParallel) { |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 1026 | DEBUG(dbgs() |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1027 | << "LAA: A loop annotated parallel, ignore memory dependency " |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 1028 | << "checks.\n"); |
Adam Nemet | 436018c | 2015-02-19 19:15:00 +0000 | [diff] [blame] | 1029 | CanVecMem = true; |
| 1030 | return; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | for (I = Loads.begin(), IE = Loads.end(); I != IE; ++I) { |
| 1034 | LoadInst *LD = cast<LoadInst>(*I); |
| 1035 | Value* Ptr = LD->getPointerOperand(); |
| 1036 | // If we did *not* see this pointer before, insert it to the |
| 1037 | // read list. If we *did* see it before, then it is already in |
| 1038 | // the read-write list. This allows us to vectorize expressions |
| 1039 | // such as A[i] += x; Because the address of A[i] is a read-write |
| 1040 | // pointer. This only works if the index of A[i] is consecutive. |
| 1041 | // If the address of i is unknown (for example A[B[i]]) then we may |
| 1042 | // read a few words, modify, and write a few words, and some of the |
| 1043 | // words may be written to the same address. |
| 1044 | bool IsReadOnlyPtr = false; |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 1045 | if (Seen.insert(Ptr).second || !isStridedPtr(SE, Ptr, TheLoop, Strides)) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1046 | ++NumReads; |
| 1047 | IsReadOnlyPtr = true; |
| 1048 | } |
| 1049 | |
| 1050 | AliasAnalysis::Location Loc = AA->getLocation(LD); |
| 1051 | // The TBAA metadata could have a control dependency on the predication |
| 1052 | // condition, so we cannot rely on it when determining whether or not we |
| 1053 | // need runtime pointer checks. |
Adam Nemet | 01abb2c | 2015-02-18 03:43:19 +0000 | [diff] [blame] | 1054 | if (blockNeedsPredication(LD->getParent(), TheLoop, DT)) |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1055 | Loc.AATags.TBAA = nullptr; |
| 1056 | |
| 1057 | Accesses.addLoad(Loc, IsReadOnlyPtr); |
| 1058 | } |
| 1059 | |
| 1060 | // If we write (or read-write) to a single destination and there are no |
| 1061 | // other reads in this loop then is it safe to vectorize. |
| 1062 | if (NumReadWrites == 1 && NumReads == 0) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1063 | DEBUG(dbgs() << "LAA: Found a write-only loop!\n"); |
Adam Nemet | 436018c | 2015-02-19 19:15:00 +0000 | [diff] [blame] | 1064 | CanVecMem = true; |
| 1065 | return; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | // Build dependence sets and check whether we need a runtime pointer bounds |
| 1069 | // check. |
| 1070 | Accesses.buildDependenceSets(); |
| 1071 | bool NeedRTCheck = Accesses.isRTCheckNeeded(); |
| 1072 | |
| 1073 | // Find pointers with computable bounds. We are going to use this information |
| 1074 | // to place a runtime bound check. |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1075 | bool CanDoRT = false; |
| 1076 | if (NeedRTCheck) |
| 1077 | CanDoRT = Accesses.canCheckPtrAtRT(PtrRtCheck, NumComparisons, SE, TheLoop, |
| 1078 | Strides); |
| 1079 | |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1080 | DEBUG(dbgs() << "LAA: We need to do " << NumComparisons << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 1081 | " pointer comparisons.\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1082 | |
| 1083 | // If we only have one set of dependences to check pointers among we don't |
| 1084 | // need a runtime check. |
| 1085 | if (NumComparisons == 0 && NeedRTCheck) |
| 1086 | NeedRTCheck = false; |
| 1087 | |
Adam Nemet | b6dc76f | 2015-03-10 18:54:19 +0000 | [diff] [blame] | 1088 | // Check that we did not find an unsizeable pointer. |
| 1089 | if (CanDoRT) |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1090 | DEBUG(dbgs() << "LAA: We can perform a memory runtime check if needed.\n"); |
Adam Nemet | b6dc76f | 2015-03-10 18:54:19 +0000 | [diff] [blame] | 1091 | else if (NeedRTCheck) { |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 1092 | emitAnalysis(LoopAccessReport() << "cannot identify array bounds"); |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1093 | DEBUG(dbgs() << "LAA: We can't vectorize because we can't find " << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 1094 | "the array bounds.\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1095 | PtrRtCheck.reset(); |
Adam Nemet | 436018c | 2015-02-19 19:15:00 +0000 | [diff] [blame] | 1096 | CanVecMem = false; |
| 1097 | return; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | PtrRtCheck.Need = NeedRTCheck; |
| 1101 | |
Adam Nemet | 436018c | 2015-02-19 19:15:00 +0000 | [diff] [blame] | 1102 | CanVecMem = true; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1103 | if (Accesses.isDependencyCheckNeeded()) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1104 | DEBUG(dbgs() << "LAA: Checking memory dependencies\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1105 | CanVecMem = DepChecker.areDepsSafe( |
| 1106 | DependentAccesses, Accesses.getDependenciesToCheck(), Strides); |
| 1107 | MaxSafeDepDistBytes = DepChecker.getMaxSafeDepDistBytes(); |
| 1108 | |
| 1109 | if (!CanVecMem && DepChecker.shouldRetryWithRuntimeCheck()) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1110 | DEBUG(dbgs() << "LAA: Retrying with memory checks\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1111 | NeedRTCheck = true; |
| 1112 | |
| 1113 | // Clear the dependency checks. We assume they are not needed. |
| 1114 | Accesses.resetDepChecks(); |
| 1115 | |
| 1116 | PtrRtCheck.reset(); |
| 1117 | PtrRtCheck.Need = true; |
| 1118 | |
| 1119 | CanDoRT = Accesses.canCheckPtrAtRT(PtrRtCheck, NumComparisons, SE, |
| 1120 | TheLoop, Strides, true); |
Adam Nemet | b6dc76f | 2015-03-10 18:54:19 +0000 | [diff] [blame] | 1121 | // Check that we didn't find an unsizeable pointer. |
| 1122 | if (!CanDoRT && NumComparisons > 0) { |
| 1123 | emitAnalysis(LoopAccessReport() |
| 1124 | << "cannot check memory dependencies at runtime"); |
| 1125 | DEBUG(dbgs() << "LAA: Can't vectorize with memory checks\n"); |
| 1126 | PtrRtCheck.reset(); |
| 1127 | CanVecMem = false; |
| 1128 | return; |
| 1129 | } |
| 1130 | |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1131 | CanVecMem = true; |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | if (!CanVecMem) |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 1136 | emitAnalysis(LoopAccessReport() << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 1137 | "unsafe dependent memory operations in loop"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1138 | |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1139 | DEBUG(dbgs() << "LAA: We" << (NeedRTCheck ? "" : " don't") << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 1140 | " need a runtime memory check.\n"); |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
Adam Nemet | 01abb2c | 2015-02-18 03:43:19 +0000 | [diff] [blame] | 1143 | bool LoopAccessInfo::blockNeedsPredication(BasicBlock *BB, Loop *TheLoop, |
| 1144 | DominatorTree *DT) { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1145 | assert(TheLoop->contains(BB) && "Unknown block used"); |
| 1146 | |
| 1147 | // Blocks that do not dominate the latch need predication. |
| 1148 | BasicBlock* Latch = TheLoop->getLoopLatch(); |
| 1149 | return !DT->dominates(BB, Latch); |
| 1150 | } |
| 1151 | |
Adam Nemet | 2bd6e98 | 2015-02-19 19:15:15 +0000 | [diff] [blame] | 1152 | void LoopAccessInfo::emitAnalysis(LoopAccessReport &Message) { |
Adam Nemet | c922853 | 2015-02-19 19:14:56 +0000 | [diff] [blame] | 1153 | assert(!Report && "Multiple reports generated"); |
| 1154 | Report = Message; |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Adam Nemet | 57ac766 | 2015-02-19 19:15:21 +0000 | [diff] [blame] | 1157 | bool LoopAccessInfo::isUniform(Value *V) const { |
Adam Nemet | 0456327 | 2015-02-01 16:56:15 +0000 | [diff] [blame] | 1158 | return (SE->isLoopInvariant(SE->getSCEV(V), TheLoop)); |
| 1159 | } |
Adam Nemet | 7206d7a | 2015-02-06 18:31:04 +0000 | [diff] [blame] | 1160 | |
| 1161 | // FIXME: this function is currently a duplicate of the one in |
| 1162 | // LoopVectorize.cpp. |
| 1163 | static Instruction *getFirstInst(Instruction *FirstInst, Value *V, |
| 1164 | Instruction *Loc) { |
| 1165 | if (FirstInst) |
| 1166 | return FirstInst; |
| 1167 | if (Instruction *I = dyn_cast<Instruction>(V)) |
| 1168 | return I->getParent() == Loc->getParent() ? I : nullptr; |
| 1169 | return nullptr; |
| 1170 | } |
| 1171 | |
| 1172 | std::pair<Instruction *, Instruction *> |
Adam Nemet | 57ac766 | 2015-02-19 19:15:21 +0000 | [diff] [blame] | 1173 | LoopAccessInfo::addRuntimeCheck(Instruction *Loc) const { |
Adam Nemet | 7206d7a | 2015-02-06 18:31:04 +0000 | [diff] [blame] | 1174 | Instruction *tnullptr = nullptr; |
| 1175 | if (!PtrRtCheck.Need) |
| 1176 | return std::pair<Instruction *, Instruction *>(tnullptr, tnullptr); |
| 1177 | |
| 1178 | unsigned NumPointers = PtrRtCheck.Pointers.size(); |
| 1179 | SmallVector<TrackingVH<Value> , 2> Starts; |
| 1180 | SmallVector<TrackingVH<Value> , 2> Ends; |
| 1181 | |
| 1182 | LLVMContext &Ctx = Loc->getContext(); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 1183 | SCEVExpander Exp(*SE, DL, "induction"); |
Adam Nemet | 7206d7a | 2015-02-06 18:31:04 +0000 | [diff] [blame] | 1184 | Instruction *FirstInst = nullptr; |
| 1185 | |
| 1186 | for (unsigned i = 0; i < NumPointers; ++i) { |
| 1187 | Value *Ptr = PtrRtCheck.Pointers[i]; |
| 1188 | const SCEV *Sc = SE->getSCEV(Ptr); |
| 1189 | |
| 1190 | if (SE->isLoopInvariant(Sc, TheLoop)) { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1191 | DEBUG(dbgs() << "LAA: Adding RT check for a loop invariant ptr:" << |
Adam Nemet | 04d4163 | 2015-02-19 19:14:34 +0000 | [diff] [blame] | 1192 | *Ptr <<"\n"); |
Adam Nemet | 7206d7a | 2015-02-06 18:31:04 +0000 | [diff] [blame] | 1193 | Starts.push_back(Ptr); |
| 1194 | Ends.push_back(Ptr); |
| 1195 | } else { |
Adam Nemet | 339f42b | 2015-02-19 19:15:07 +0000 | [diff] [blame] | 1196 | DEBUG(dbgs() << "LAA: Adding RT check for range:" << *Ptr << '\n'); |
Adam Nemet | 7206d7a | 2015-02-06 18:31:04 +0000 | [diff] [blame] | 1197 | unsigned AS = Ptr->getType()->getPointerAddressSpace(); |
| 1198 | |
| 1199 | // Use this type for pointer arithmetic. |
| 1200 | Type *PtrArithTy = Type::getInt8PtrTy(Ctx, AS); |
| 1201 | |
| 1202 | Value *Start = Exp.expandCodeFor(PtrRtCheck.Starts[i], PtrArithTy, Loc); |
| 1203 | Value *End = Exp.expandCodeFor(PtrRtCheck.Ends[i], PtrArithTy, Loc); |
| 1204 | Starts.push_back(Start); |
| 1205 | Ends.push_back(End); |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | IRBuilder<> ChkBuilder(Loc); |
| 1210 | // Our instructions might fold to a constant. |
| 1211 | Value *MemoryRuntimeCheck = nullptr; |
| 1212 | for (unsigned i = 0; i < NumPointers; ++i) { |
| 1213 | for (unsigned j = i+1; j < NumPointers; ++j) { |
Adam Nemet | a8945b7 | 2015-02-18 03:43:58 +0000 | [diff] [blame] | 1214 | if (!PtrRtCheck.needsChecking(i, j)) |
Adam Nemet | 7206d7a | 2015-02-06 18:31:04 +0000 | [diff] [blame] | 1215 | continue; |
| 1216 | |
| 1217 | unsigned AS0 = Starts[i]->getType()->getPointerAddressSpace(); |
| 1218 | unsigned AS1 = Starts[j]->getType()->getPointerAddressSpace(); |
| 1219 | |
| 1220 | assert((AS0 == Ends[j]->getType()->getPointerAddressSpace()) && |
| 1221 | (AS1 == Ends[i]->getType()->getPointerAddressSpace()) && |
| 1222 | "Trying to bounds check pointers with different address spaces"); |
| 1223 | |
| 1224 | Type *PtrArithTy0 = Type::getInt8PtrTy(Ctx, AS0); |
| 1225 | Type *PtrArithTy1 = Type::getInt8PtrTy(Ctx, AS1); |
| 1226 | |
| 1227 | Value *Start0 = ChkBuilder.CreateBitCast(Starts[i], PtrArithTy0, "bc"); |
| 1228 | Value *Start1 = ChkBuilder.CreateBitCast(Starts[j], PtrArithTy1, "bc"); |
| 1229 | Value *End0 = ChkBuilder.CreateBitCast(Ends[i], PtrArithTy1, "bc"); |
| 1230 | Value *End1 = ChkBuilder.CreateBitCast(Ends[j], PtrArithTy0, "bc"); |
| 1231 | |
| 1232 | Value *Cmp0 = ChkBuilder.CreateICmpULE(Start0, End1, "bound0"); |
| 1233 | FirstInst = getFirstInst(FirstInst, Cmp0, Loc); |
| 1234 | Value *Cmp1 = ChkBuilder.CreateICmpULE(Start1, End0, "bound1"); |
| 1235 | FirstInst = getFirstInst(FirstInst, Cmp1, Loc); |
| 1236 | Value *IsConflict = ChkBuilder.CreateAnd(Cmp0, Cmp1, "found.conflict"); |
| 1237 | FirstInst = getFirstInst(FirstInst, IsConflict, Loc); |
| 1238 | if (MemoryRuntimeCheck) { |
| 1239 | IsConflict = ChkBuilder.CreateOr(MemoryRuntimeCheck, IsConflict, |
| 1240 | "conflict.rdx"); |
| 1241 | FirstInst = getFirstInst(FirstInst, IsConflict, Loc); |
| 1242 | } |
| 1243 | MemoryRuntimeCheck = IsConflict; |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | // We have to do this trickery because the IRBuilder might fold the check to a |
| 1248 | // constant expression in which case there is no Instruction anchored in a |
| 1249 | // the block. |
| 1250 | Instruction *Check = BinaryOperator::CreateAnd(MemoryRuntimeCheck, |
| 1251 | ConstantInt::getTrue(Ctx)); |
| 1252 | ChkBuilder.Insert(Check, "memcheck.conflict"); |
| 1253 | FirstInst = getFirstInst(FirstInst, Check, Loc); |
| 1254 | return std::make_pair(FirstInst, Check); |
| 1255 | } |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 1256 | |
| 1257 | LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 1258 | const DataLayout &DL, |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 1259 | const TargetLibraryInfo *TLI, AliasAnalysis *AA, |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 1260 | DominatorTree *DT, |
| 1261 | const ValueToValueMap &Strides) |
Adam Nemet | 98c4c5d | 2015-03-10 18:54:23 +0000 | [diff] [blame^] | 1262 | : DepChecker(SE, L), NumComparisons(0), TheLoop(L), SE(SE), DL(DL), |
| 1263 | TLI(TLI), AA(AA), DT(DT), NumLoads(0), NumStores(0), |
| 1264 | MaxSafeDepDistBytes(-1U), CanVecMem(false) { |
Adam Nemet | 929c38e | 2015-02-19 19:15:10 +0000 | [diff] [blame] | 1265 | if (canAnalyzeLoop()) |
| 1266 | analyzeLoop(Strides); |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Adam Nemet | e91cc6e | 2015-02-19 19:15:19 +0000 | [diff] [blame] | 1269 | void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const { |
| 1270 | if (CanVecMem) { |
| 1271 | if (PtrRtCheck.empty()) |
| 1272 | OS.indent(Depth) << "Memory dependences are safe\n"; |
| 1273 | else |
| 1274 | OS.indent(Depth) << "Memory dependences are safe with run-time checks\n"; |
| 1275 | } |
| 1276 | |
| 1277 | if (Report) |
| 1278 | OS.indent(Depth) << "Report: " << Report->str() << "\n"; |
| 1279 | |
Adam Nemet | 58913d6 | 2015-03-10 17:40:43 +0000 | [diff] [blame] | 1280 | if (auto *InterestingDependences = DepChecker.getInterestingDependences()) { |
| 1281 | OS.indent(Depth) << "Interesting Dependences:\n"; |
| 1282 | for (auto &Dep : *InterestingDependences) { |
| 1283 | Dep.print(OS, Depth + 2, DepChecker.getMemoryInstructions()); |
| 1284 | OS << "\n"; |
| 1285 | } |
| 1286 | } else |
| 1287 | OS.indent(Depth) << "Too many interesting dependences, not recorded\n"; |
Adam Nemet | e91cc6e | 2015-02-19 19:15:19 +0000 | [diff] [blame] | 1288 | |
| 1289 | // List the pair of accesses need run-time checks to prove independence. |
| 1290 | PtrRtCheck.print(OS, Depth); |
| 1291 | OS << "\n"; |
| 1292 | } |
| 1293 | |
Adam Nemet | 8bc61df | 2015-02-24 00:41:59 +0000 | [diff] [blame] | 1294 | const LoopAccessInfo & |
| 1295 | LoopAccessAnalysis::getInfo(Loop *L, const ValueToValueMap &Strides) { |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 1296 | auto &LAI = LoopAccessInfoMap[L]; |
| 1297 | |
| 1298 | #ifndef NDEBUG |
| 1299 | assert((!LAI || LAI->NumSymbolicStrides == Strides.size()) && |
| 1300 | "Symbolic strides changed for loop"); |
| 1301 | #endif |
| 1302 | |
| 1303 | if (!LAI) { |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 1304 | const DataLayout &DL = L->getHeader()->getModule()->getDataLayout(); |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 1305 | LAI = llvm::make_unique<LoopAccessInfo>(L, SE, DL, TLI, AA, DT, Strides); |
| 1306 | #ifndef NDEBUG |
| 1307 | LAI->NumSymbolicStrides = Strides.size(); |
| 1308 | #endif |
| 1309 | } |
| 1310 | return *LAI.get(); |
| 1311 | } |
| 1312 | |
Adam Nemet | e91cc6e | 2015-02-19 19:15:19 +0000 | [diff] [blame] | 1313 | void LoopAccessAnalysis::print(raw_ostream &OS, const Module *M) const { |
| 1314 | LoopAccessAnalysis &LAA = *const_cast<LoopAccessAnalysis *>(this); |
| 1315 | |
| 1316 | LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
| 1317 | ValueToValueMap NoSymbolicStrides; |
| 1318 | |
| 1319 | for (Loop *TopLevelLoop : *LI) |
| 1320 | for (Loop *L : depth_first(TopLevelLoop)) { |
| 1321 | OS.indent(2) << L->getHeader()->getName() << ":\n"; |
| 1322 | auto &LAI = LAA.getInfo(L, NoSymbolicStrides); |
| 1323 | LAI.print(OS, 4); |
| 1324 | } |
| 1325 | } |
| 1326 | |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 1327 | bool LoopAccessAnalysis::runOnFunction(Function &F) { |
| 1328 | SE = &getAnalysis<ScalarEvolution>(); |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 1329 | auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>(); |
| 1330 | TLI = TLIP ? &TLIP->getTLI() : nullptr; |
| 1331 | AA = &getAnalysis<AliasAnalysis>(); |
| 1332 | DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
| 1333 | |
| 1334 | return false; |
| 1335 | } |
| 1336 | |
| 1337 | void LoopAccessAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { |
| 1338 | AU.addRequired<ScalarEvolution>(); |
| 1339 | AU.addRequired<AliasAnalysis>(); |
| 1340 | AU.addRequired<DominatorTreeWrapperPass>(); |
Adam Nemet | e91cc6e | 2015-02-19 19:15:19 +0000 | [diff] [blame] | 1341 | AU.addRequired<LoopInfoWrapperPass>(); |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 1342 | |
| 1343 | AU.setPreservesAll(); |
| 1344 | } |
| 1345 | |
| 1346 | char LoopAccessAnalysis::ID = 0; |
| 1347 | static const char laa_name[] = "Loop Access Analysis"; |
| 1348 | #define LAA_NAME "loop-accesses" |
| 1349 | |
| 1350 | INITIALIZE_PASS_BEGIN(LoopAccessAnalysis, LAA_NAME, laa_name, false, true) |
| 1351 | INITIALIZE_AG_DEPENDENCY(AliasAnalysis) |
| 1352 | INITIALIZE_PASS_DEPENDENCY(ScalarEvolution) |
| 1353 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
Adam Nemet | e91cc6e | 2015-02-19 19:15:19 +0000 | [diff] [blame] | 1354 | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) |
Adam Nemet | 3bfd93d | 2015-02-19 19:15:04 +0000 | [diff] [blame] | 1355 | INITIALIZE_PASS_END(LoopAccessAnalysis, LAA_NAME, laa_name, false, true) |
| 1356 | |
| 1357 | namespace llvm { |
| 1358 | Pass *createLAAPass() { |
| 1359 | return new LoopAccessAnalysis(); |
| 1360 | } |
| 1361 | } |