1 //===- llvm/Analysis/LoopAccessAnalysis.h -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interface for the loop memory dependence framework that
11 // was originally developed for the Loop Vectorizer.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
16 #define LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
18 #include "llvm/ADT/EquivalenceClasses.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/SetVector.h"
21 #include "llvm/Analysis/AliasAnalysis.h"
22 #include "llvm/Analysis/AliasSetTracker.h"
23 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
24 #include "llvm/IR/ValueHandle.h"
25 #include "llvm/Pass.h"
26 #include "llvm/Support/raw_ostream.h"
32 class ScalarEvolution;
35 class SCEVUnionPredicate;
38 /// Optimization analysis message produced during vectorization. Messages inform
39 /// the user why vectorization did not occur.
40 class LoopAccessReport {
42 const Instruction *Instr;
45 LoopAccessReport(const Twine &Message, const Instruction *I)
46 : Message(Message.str()), Instr(I) {}
49 LoopAccessReport(const Instruction *I = nullptr) : Instr(I) {}
51 template <typename A> LoopAccessReport &operator<<(const A &Value) {
52 raw_string_ostream Out(Message);
57 const Instruction *getInstr() const { return Instr; }
59 std::string &str() { return Message; }
60 const std::string &str() const { return Message; }
61 operator Twine() { return Message; }
63 /// \brief Emit an analysis note for \p PassName with the debug location from
64 /// the instruction in \p Message if available. Otherwise use the location of
66 static void emitAnalysis(const LoopAccessReport &Message,
67 const Function *TheFunction,
69 const char *PassName);
72 /// \brief Collection of parameters shared beetween the Loop Vectorizer and the
73 /// Loop Access Analysis.
74 struct VectorizerParams {
75 /// \brief Maximum SIMD width.
76 static const unsigned MaxVectorWidth;
78 /// \brief VF as overridden by the user.
79 static unsigned VectorizationFactor;
80 /// \brief Interleave factor as overridden by the user.
81 static unsigned VectorizationInterleave;
82 /// \brief True if force-vector-interleave was specified by the user.
83 static bool isInterleaveForced();
85 /// \\brief When performing memory disambiguation checks at runtime do not
86 /// make more than this number of comparisons.
87 static unsigned RuntimeMemoryCheckThreshold;
90 /// \brief Checks memory dependences among accesses to the same underlying
91 /// object to determine whether there vectorization is legal or not (and at
92 /// which vectorization factor).
94 /// Note: This class will compute a conservative dependence for access to
95 /// different underlying pointers. Clients, such as the loop vectorizer, will
96 /// sometimes deal these potential dependencies by emitting runtime checks.
98 /// We use the ScalarEvolution framework to symbolically evalutate access
99 /// functions pairs. Since we currently don't restructure the loop we can rely
100 /// on the program order of memory accesses to determine their safety.
101 /// At the moment we will only deem accesses as safe for:
102 /// * A negative constant distance assuming program order.
104 /// Safe: tmp = a[i + 1]; OR a[i + 1] = x;
105 /// a[i] = tmp; y = a[i];
107 /// The latter case is safe because later checks guarantuee that there can't
108 /// be a cycle through a phi node (that is, we check that "x" and "y" is not
109 /// the same variable: a header phi can only be an induction or a reduction, a
110 /// reduction can't have a memory sink, an induction can't have a memory
111 /// source). This is important and must not be violated (or we have to
112 /// resort to checking for cycles through memory).
114 /// * A positive constant distance assuming program order that is bigger
115 /// than the biggest memory access.
117 /// tmp = a[i] OR b[i] = x
118 /// a[i+2] = tmp y = b[i+2];
120 /// Safe distance: 2 x sizeof(a[0]), and 2 x sizeof(b[0]), respectively.
122 /// * Zero distances and all accesses have the same size.
124 class MemoryDepChecker {
126 typedef PointerIntPair<Value *, 1, bool> MemAccessInfo;
127 typedef SmallPtrSet<MemAccessInfo, 8> MemAccessInfoSet;
128 /// \brief Set of potential dependent memory accesses.
129 typedef EquivalenceClasses<MemAccessInfo> DepCandidates;
131 /// \brief Dependece between memory access instructions.
133 /// \brief The type of the dependence.
137 // We couldn't determine the direction or the distance.
139 // Lexically forward.
141 // FIXME: If we only have loop-independent forward dependences (e.g. a
142 // read and write of A[i]), LAA will locally deem the dependence "safe"
143 // without querying the MemoryDepChecker. Therefore we can miss
144 // enumerating loop-independent forward dependences in
145 // getDependences. Note that as soon as there are different
146 // indices used to access the same array, the MemoryDepChecker *is*
147 // queried and the dependence list is complete.
149 // Forward, but if vectorized, is likely to prevent store-to-load
151 ForwardButPreventsForwarding,
152 // Lexically backward.
154 // Backward, but the distance allows a vectorization factor of
155 // MaxSafeDepDistBytes.
156 BackwardVectorizable,
157 // Same, but may prevent store-to-load forwarding.
158 BackwardVectorizableButPreventsForwarding
161 /// \brief String version of the types.
162 static const char *DepName[];
164 /// \brief Index of the source of the dependence in the InstMap vector.
166 /// \brief Index of the destination of the dependence in the InstMap vector.
167 unsigned Destination;
168 /// \brief The type of the dependence.
171 Dependence(unsigned Source, unsigned Destination, DepType Type)
172 : Source(Source), Destination(Destination), Type(Type) {}
174 /// \brief Return the source instruction of the dependence.
175 Instruction *getSource(const LoopAccessInfo &LAI) const;
176 /// \brief Return the destination instruction of the dependence.
177 Instruction *getDestination(const LoopAccessInfo &LAI) const;
179 /// \brief Dependence types that don't prevent vectorization.
180 static bool isSafeForVectorization(DepType Type);
182 /// \brief Lexically forward dependence.
183 bool isForward() const;
184 /// \brief Lexically backward dependence.
185 bool isBackward() const;
187 /// \brief May be a lexically backward dependence type (includes Unknown).
188 bool isPossiblyBackward() const;
190 /// \brief Print the dependence. \p Instr is used to map the instruction
191 /// indices to instructions.
192 void print(raw_ostream &OS, unsigned Depth,
193 const SmallVectorImpl<Instruction *> &Instrs) const;
196 MemoryDepChecker(PredicatedScalarEvolution &PSE, const Loop *L)
197 : PSE(PSE), InnermostLoop(L), AccessIdx(0),
198 ShouldRetryWithRuntimeCheck(false), SafeForVectorization(true),
199 RecordDependences(true) {}
201 /// \brief Register the location (instructions are given increasing numbers)
202 /// of a write access.
203 void addAccess(StoreInst *SI) {
204 Value *Ptr = SI->getPointerOperand();
205 Accesses[MemAccessInfo(Ptr, true)].push_back(AccessIdx);
206 InstMap.push_back(SI);
210 /// \brief Register the location (instructions are given increasing numbers)
211 /// of a write access.
212 void addAccess(LoadInst *LI) {
213 Value *Ptr = LI->getPointerOperand();
214 Accesses[MemAccessInfo(Ptr, false)].push_back(AccessIdx);
215 InstMap.push_back(LI);
219 /// \brief Check whether the dependencies between the accesses are safe.
221 /// Only checks sets with elements in \p CheckDeps.
222 bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoSet &CheckDeps,
223 const ValueToValueMap &Strides);
225 /// \brief No memory dependence was encountered that would inhibit
227 bool isSafeForVectorization() const { return SafeForVectorization; }
229 /// \brief The maximum number of bytes of a vector register we can vectorize
230 /// the accesses safely with.
231 unsigned getMaxSafeDepDistBytes() { return MaxSafeDepDistBytes; }
233 /// \brief In same cases when the dependency check fails we can still
234 /// vectorize the loop with a dynamic array access check.
235 bool shouldRetryWithRuntimeCheck() { return ShouldRetryWithRuntimeCheck; }
237 /// \brief Returns the memory dependences. If null is returned we exceeded
238 /// the MaxDependences threshold and this information is not
240 const SmallVectorImpl<Dependence> *getDependences() const {
241 return RecordDependences ? &Dependences : nullptr;
244 void clearDependences() { Dependences.clear(); }
246 /// \brief The vector of memory access instructions. The indices are used as
247 /// instruction identifiers in the Dependence class.
248 const SmallVectorImpl<Instruction *> &getMemoryInstructions() const {
252 /// \brief Generate a mapping between the memory instructions and their
253 /// indices according to program order.
254 DenseMap<Instruction *, unsigned> generateInstructionOrderMap() const {
255 DenseMap<Instruction *, unsigned> OrderMap;
257 for (unsigned I = 0; I < InstMap.size(); ++I)
258 OrderMap[InstMap[I]] = I;
263 /// \brief Find the set of instructions that read or write via \p Ptr.
264 SmallVector<Instruction *, 4> getInstructionsForAccess(Value *Ptr,
268 /// A wrapper around ScalarEvolution, used to add runtime SCEV checks, and
269 /// applies dynamic knowledge to simplify SCEV expressions and convert them
270 /// to a more usable form. We need this in case assumptions about SCEV
271 /// expressions need to be made in order to avoid unknown dependences. For
272 /// example we might assume a unit stride for a pointer in order to prove
273 /// that a memory access is strided and doesn't wrap.
274 PredicatedScalarEvolution &PSE;
275 const Loop *InnermostLoop;
277 /// \brief Maps access locations (ptr, read/write) to program order.
278 DenseMap<MemAccessInfo, std::vector<unsigned> > Accesses;
280 /// \brief Memory access instructions in program order.
281 SmallVector<Instruction *, 16> InstMap;
283 /// \brief The program order index to be used for the next instruction.
286 // We can access this many bytes in parallel safely.
287 unsigned MaxSafeDepDistBytes;
289 /// \brief If we see a non-constant dependence distance we can still try to
290 /// vectorize this loop with runtime checks.
291 bool ShouldRetryWithRuntimeCheck;
293 /// \brief No memory dependence was encountered that would inhibit
295 bool SafeForVectorization;
297 //// \brief True if Dependences reflects the dependences in the
298 //// loop. If false we exceeded MaxDependences and
299 //// Dependences is invalid.
300 bool RecordDependences;
302 /// \brief Memory dependences collected during the analysis. Only valid if
303 /// RecordDependences is true.
304 SmallVector<Dependence, 8> Dependences;
306 /// \brief Check whether there is a plausible dependence between the two
309 /// Access \p A must happen before \p B in program order. The two indices
310 /// identify the index into the program order map.
312 /// This function checks whether there is a plausible dependence (or the
313 /// absence of such can't be proved) between the two accesses. If there is a
314 /// plausible dependence but the dependence distance is bigger than one
315 /// element access it records this distance in \p MaxSafeDepDistBytes (if this
316 /// distance is smaller than any other distance encountered so far).
317 /// Otherwise, this function returns true signaling a possible dependence.
318 Dependence::DepType isDependent(const MemAccessInfo &A, unsigned AIdx,
319 const MemAccessInfo &B, unsigned BIdx,
320 const ValueToValueMap &Strides);
322 /// \brief Check whether the data dependence could prevent store-load
324 bool couldPreventStoreLoadForward(unsigned Distance, unsigned TypeByteSize);
327 /// \brief Holds information about the memory runtime legality checks to verify
328 /// that a group of pointers do not overlap.
329 class RuntimePointerChecking {
332 /// Holds the pointer value that we need to check.
333 TrackingVH<Value> PointerValue;
334 /// Holds the pointer value at the beginning of the loop.
336 /// Holds the pointer value at the end of the loop.
338 /// Holds the information if this pointer is used for writing to memory.
340 /// Holds the id of the set of pointers that could be dependent because of a
341 /// shared underlying object.
342 unsigned DependencySetId;
343 /// Holds the id of the disjoint alias set to which this pointer belongs.
345 /// SCEV for the access.
348 PointerInfo(Value *PointerValue, const SCEV *Start, const SCEV *End,
349 bool IsWritePtr, unsigned DependencySetId, unsigned AliasSetId,
351 : PointerValue(PointerValue), Start(Start), End(End),
352 IsWritePtr(IsWritePtr), DependencySetId(DependencySetId),
353 AliasSetId(AliasSetId), Expr(Expr) {}
356 RuntimePointerChecking(ScalarEvolution *SE) : Need(false), SE(SE) {}
358 /// Reset the state of the pointer runtime information.
365 /// Insert a pointer and calculate the start and end SCEVs.
366 /// \p We need Preds in order to compute the SCEV expression of the pointer
367 /// according to the assumptions that we've made during the analysis.
368 /// The method might also version the pointer stride according to \p Strides,
369 /// and change \p Preds.
370 void insert(Loop *Lp, Value *Ptr, bool WritePtr, unsigned DepSetId,
371 unsigned ASId, const ValueToValueMap &Strides,
372 PredicatedScalarEvolution &PSE);
374 /// \brief No run-time memory checking is necessary.
375 bool empty() const { return Pointers.empty(); }
377 /// A grouping of pointers. A single memcheck is required between
379 struct CheckingPtrGroup {
380 /// \brief Create a new pointer checking group containing a single
381 /// pointer, with index \p Index in RtCheck.
382 CheckingPtrGroup(unsigned Index, RuntimePointerChecking &RtCheck)
383 : RtCheck(RtCheck), High(RtCheck.Pointers[Index].End),
384 Low(RtCheck.Pointers[Index].Start) {
385 Members.push_back(Index);
388 /// \brief Tries to add the pointer recorded in RtCheck at index
389 /// \p Index to this pointer checking group. We can only add a pointer
390 /// to a checking group if we will still be able to get
391 /// the upper and lower bounds of the check. Returns true in case
392 /// of success, false otherwise.
393 bool addPointer(unsigned Index);
395 /// Constitutes the context of this pointer checking group. For each
396 /// pointer that is a member of this group we will retain the index
397 /// at which it appears in RtCheck.
398 RuntimePointerChecking &RtCheck;
399 /// The SCEV expression which represents the upper bound of all the
400 /// pointers in this group.
402 /// The SCEV expression which represents the lower bound of all the
403 /// pointers in this group.
405 /// Indices of all the pointers that constitute this grouping.
406 SmallVector<unsigned, 2> Members;
409 /// \brief A memcheck which made up of a pair of grouped pointers.
411 /// These *have* to be const for now, since checks are generated from
412 /// CheckingPtrGroups in LAI::addRuntimeChecks which is a const member
413 /// function. FIXME: once check-generation is moved inside this class (after
414 /// the PtrPartition hack is removed), we could drop const.
415 typedef std::pair<const CheckingPtrGroup *, const CheckingPtrGroup *>
418 /// \brief Generate the checks and store it. This also performs the grouping
419 /// of pointers to reduce the number of memchecks necessary.
420 void generateChecks(MemoryDepChecker::DepCandidates &DepCands,
421 bool UseDependencies);
423 /// \brief Returns the checks that generateChecks created.
424 const SmallVector<PointerCheck, 4> &getChecks() const { return Checks; }
426 /// \brief Decide if we need to add a check between two groups of pointers,
427 /// according to needsChecking.
428 bool needsChecking(const CheckingPtrGroup &M,
429 const CheckingPtrGroup &N) const;
431 /// \brief Returns the number of run-time checks required according to
433 unsigned getNumberOfChecks() const { return Checks.size(); }
435 /// \brief Print the list run-time memory checks necessary.
436 void print(raw_ostream &OS, unsigned Depth = 0) const;
439 void printChecks(raw_ostream &OS, const SmallVectorImpl<PointerCheck> &Checks,
440 unsigned Depth = 0) const;
442 /// This flag indicates if we need to add the runtime check.
445 /// Information about the pointers that may require checking.
446 SmallVector<PointerInfo, 2> Pointers;
448 /// Holds a partitioning of pointers into "check groups".
449 SmallVector<CheckingPtrGroup, 2> CheckingGroups;
451 /// \brief Check if pointers are in the same partition
453 /// \p PtrToPartition contains the partition number for pointers (-1 if the
454 /// pointer belongs to multiple partitions).
456 arePointersInSamePartition(const SmallVectorImpl<int> &PtrToPartition,
457 unsigned PtrIdx1, unsigned PtrIdx2);
459 /// \brief Decide whether we need to issue a run-time check for pointer at
460 /// index \p I and \p J to prove their independence.
461 bool needsChecking(unsigned I, unsigned J) const;
463 /// \brief Return PointerInfo for pointer at index \p PtrIdx.
464 const PointerInfo &getPointerInfo(unsigned PtrIdx) const {
465 return Pointers[PtrIdx];
469 /// \brief Groups pointers such that a single memcheck is required
470 /// between two different groups. This will clear the CheckingGroups vector
471 /// and re-compute it. We will only group dependecies if \p UseDependencies
472 /// is true, otherwise we will create a separate group for each pointer.
473 void groupChecks(MemoryDepChecker::DepCandidates &DepCands,
474 bool UseDependencies);
476 /// Generate the checks and return them.
477 SmallVector<PointerCheck, 4>
478 generateChecks() const;
480 /// Holds a pointer to the ScalarEvolution analysis.
483 /// \brief Set of run-time checks required to establish independence of
484 /// otherwise may-aliasing pointers in the loop.
485 SmallVector<PointerCheck, 4> Checks;
488 /// \brief Drive the analysis of memory accesses in the loop
490 /// This class is responsible for analyzing the memory accesses of a loop. It
491 /// collects the accesses and then its main helper the AccessAnalysis class
492 /// finds and categorizes the dependences in buildDependenceSets.
494 /// For memory dependences that can be analyzed at compile time, it determines
495 /// whether the dependence is part of cycle inhibiting vectorization. This work
496 /// is delegated to the MemoryDepChecker class.
498 /// For memory dependences that cannot be determined at compile time, it
499 /// generates run-time checks to prove independence. This is done by
500 /// AccessAnalysis::canCheckPtrAtRT and the checks are maintained by the
501 /// RuntimePointerCheck class.
503 /// If pointers can wrap or can't be expressed as affine AddRec expressions by
504 /// ScalarEvolution, we will generate run-time checks by emitting a
505 /// SCEVUnionPredicate.
507 /// Checks for both memory dependences and the SCEV predicates contained in the
508 /// PSE must be emitted in order for the results of this analysis to be valid.
509 class LoopAccessInfo {
511 LoopAccessInfo(Loop *L, ScalarEvolution *SE, const DataLayout &DL,
512 const TargetLibraryInfo *TLI, AliasAnalysis *AA,
513 DominatorTree *DT, LoopInfo *LI,
514 const ValueToValueMap &Strides);
516 /// Return true we can analyze the memory accesses in the loop and there are
517 /// no memory dependence cycles.
518 bool canVectorizeMemory() const { return CanVecMem; }
520 const RuntimePointerChecking *getRuntimePointerChecking() const {
521 return &PtrRtChecking;
524 /// \brief Number of memchecks required to prove independence of otherwise
525 /// may-alias pointers.
526 unsigned getNumRuntimePointerChecks() const {
527 return PtrRtChecking.getNumberOfChecks();
530 /// Return true if the block BB needs to be predicated in order for the loop
531 /// to be vectorized.
532 static bool blockNeedsPredication(BasicBlock *BB, Loop *TheLoop,
535 /// Returns true if the value V is uniform within the loop.
536 bool isUniform(Value *V) const;
538 unsigned getMaxSafeDepDistBytes() const { return MaxSafeDepDistBytes; }
539 unsigned getNumStores() const { return NumStores; }
540 unsigned getNumLoads() const { return NumLoads;}
542 /// \brief Add code that checks at runtime if the accessed arrays overlap.
544 /// Returns a pair of instructions where the first element is the first
545 /// instruction generated in possibly a sequence of instructions and the
546 /// second value is the final comparator value or NULL if no check is needed.
547 std::pair<Instruction *, Instruction *>
548 addRuntimeChecks(Instruction *Loc) const;
550 /// \brief Generete the instructions for the checks in \p PointerChecks.
552 /// Returns a pair of instructions where the first element is the first
553 /// instruction generated in possibly a sequence of instructions and the
554 /// second value is the final comparator value or NULL if no check is needed.
555 std::pair<Instruction *, Instruction *>
556 addRuntimeChecks(Instruction *Loc,
557 const SmallVectorImpl<RuntimePointerChecking::PointerCheck>
558 &PointerChecks) const;
560 /// \brief The diagnostics report generated for the analysis. E.g. why we
561 /// couldn't analyze the loop.
562 const Optional<LoopAccessReport> &getReport() const { return Report; }
564 /// \brief the Memory Dependence Checker which can determine the
565 /// loop-independent and loop-carried dependences between memory accesses.
566 const MemoryDepChecker &getDepChecker() const { return DepChecker; }
568 /// \brief Return the list of instructions that use \p Ptr to read or write
570 SmallVector<Instruction *, 4> getInstructionsForAccess(Value *Ptr,
571 bool isWrite) const {
572 return DepChecker.getInstructionsForAccess(Ptr, isWrite);
575 /// \brief Print the information about the memory accesses in the loop.
576 void print(raw_ostream &OS, unsigned Depth = 0) const;
578 /// \brief Used to ensure that if the analysis was run with speculating the
579 /// value of symbolic strides, the client queries it with the same assumption.
580 /// Only used in DEBUG build but we don't want NDEBUG-dependent ABI.
581 unsigned NumSymbolicStrides;
583 /// \brief Checks existence of store to invariant address inside loop.
584 /// If the loop has any store to invariant address, then it returns true,
585 /// else returns false.
586 bool hasStoreToLoopInvariantAddress() const {
587 return StoreToLoopInvariantAddress;
590 /// Used to add runtime SCEV checks. Simplifies SCEV expressions and converts
591 /// them to a more usable form. All SCEV expressions during the analysis
592 /// should be re-written (and therefore simplified) according to PSE.
593 /// A user of LoopAccessAnalysis will need to emit the runtime checks
594 /// associated with this predicate.
595 PredicatedScalarEvolution PSE;
598 /// \brief Analyze the loop. Substitute symbolic strides using Strides.
599 void analyzeLoop(const ValueToValueMap &Strides);
601 /// \brief Check if the structure of the loop allows it to be analyzed by this
603 bool canAnalyzeLoop();
605 void emitAnalysis(LoopAccessReport &Message);
607 /// We need to check that all of the pointers in this list are disjoint
609 RuntimePointerChecking PtrRtChecking;
611 /// \brief the Memory Dependence Checker which can determine the
612 /// loop-independent and loop-carried dependences between memory accesses.
613 MemoryDepChecker DepChecker;
616 const DataLayout &DL;
617 const TargetLibraryInfo *TLI;
625 unsigned MaxSafeDepDistBytes;
627 /// \brief Cache the result of analyzeLoop.
630 /// \brief Indicator for storing to uniform addresses.
631 /// If a loop has write to a loop invariant address then it should be true.
632 bool StoreToLoopInvariantAddress;
634 /// \brief The diagnostics report generated for the analysis. E.g. why we
635 /// couldn't analyze the loop.
636 Optional<LoopAccessReport> Report;
639 Value *stripIntegerCast(Value *V);
641 ///\brief Return the SCEV corresponding to a pointer with the symbolic stride
642 /// replaced with constant one, assuming \p Preds is true.
644 /// If necessary this method will version the stride of the pointer according
645 /// to \p PtrToStride and therefore add a new predicate to \p Preds.
647 /// If \p OrigPtr is not null, use it to look up the stride value instead of \p
648 /// Ptr. \p PtrToStride provides the mapping between the pointer value and its
649 /// stride as collected by LoopVectorizationLegality::collectStridedAccess.
650 const SCEV *replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE,
651 const ValueToValueMap &PtrToStride,
652 Value *Ptr, Value *OrigPtr = nullptr);
654 /// \brief Check the stride of the pointer and ensure that it does not wrap in
655 /// the address space, assuming \p Preds is true.
657 /// If necessary this method will version the stride of the pointer according
658 /// to \p PtrToStride and therefore add a new predicate to \p Preds.
659 int isStridedPtr(PredicatedScalarEvolution &PSE, Value *Ptr, const Loop *Lp,
660 const ValueToValueMap &StridesMap);
662 /// \brief This analysis provides dependence information for the memory accesses
665 /// It runs the analysis for a loop on demand. This can be initiated by
666 /// querying the loop access info via LAA::getInfo. getInfo return a
667 /// LoopAccessInfo object. See this class for the specifics of what information
669 class LoopAccessAnalysis : public FunctionPass {
673 LoopAccessAnalysis() : FunctionPass(ID) {
674 initializeLoopAccessAnalysisPass(*PassRegistry::getPassRegistry());
677 bool runOnFunction(Function &F) override;
679 void getAnalysisUsage(AnalysisUsage &AU) const override;
681 /// \brief Query the result of the loop access information for the loop \p L.
683 /// If the client speculates (and then issues run-time checks) for the values
684 /// of symbolic strides, \p Strides provides the mapping (see
685 /// replaceSymbolicStrideSCEV). If there is no cached result available run
687 const LoopAccessInfo &getInfo(Loop *L, const ValueToValueMap &Strides);
689 void releaseMemory() override {
690 // Invalidate the cache when the pass is freed.
691 LoopAccessInfoMap.clear();
694 /// \brief Print the result of the analysis when invoked with -analyze.
695 void print(raw_ostream &OS, const Module *M = nullptr) const override;
698 /// \brief The cache.
699 DenseMap<Loop *, std::unique_ptr<LoopAccessInfo>> LoopAccessInfoMap;
701 // The used analysis passes.
703 const TargetLibraryInfo *TLI;
709 inline Instruction *MemoryDepChecker::Dependence::getSource(
710 const LoopAccessInfo &LAI) const {
711 return LAI.getDepChecker().getMemoryInstructions()[Source];
714 inline Instruction *MemoryDepChecker::Dependence::getDestination(
715 const LoopAccessInfo &LAI) const {
716 return LAI.getDepChecker().getMemoryInstructions()[Destination];
719 } // End llvm namespace