LLVM 23.0.0git
LoopAccessAnalysis.h
Go to the documentation of this file.
1//===- llvm/Analysis/LoopAccessAnalysis.h -----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the interface for the loop memory dependence framework that
10// was originally developed for the Loop Vectorizer.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
15#define LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
16
22#include <optional>
23#include <variant>
24
25namespace llvm {
26
27class AAResults;
28class DataLayout;
29class Loop;
30class raw_ostream;
32
33/// Collection of parameters shared beetween the Loop Vectorizer and the
34/// Loop Access Analysis.
36 /// Maximum SIMD width.
37 LLVM_ABI static const unsigned MaxVectorWidth;
38
39 /// VF as overridden by the user.
41 /// Interleave factor as overridden by the user.
43 /// True if force-vector-interleave was specified by the user.
44 LLVM_ABI static bool isInterleaveForced();
45
46 /// \When performing memory disambiguation checks at runtime do not
47 /// make more than this number of comparisons.
49
50 // When creating runtime checks for nested loops, where possible try to
51 // write the checks in a form that allows them to be easily hoisted out of
52 // the outermost loop. For example, we can do this by expanding the range of
53 // addresses considered to include the entire nested loop so that they are
54 // loop invariant.
56};
57
58/// Checks memory dependences among accesses to the same underlying
59/// object to determine whether there vectorization is legal or not (and at
60/// which vectorization factor).
61///
62/// Note: This class will compute a conservative dependence for access to
63/// different underlying pointers. Clients, such as the loop vectorizer, will
64/// sometimes deal these potential dependencies by emitting runtime checks.
65///
66/// We use the ScalarEvolution framework to symbolically evalutate access
67/// functions pairs. Since we currently don't restructure the loop we can rely
68/// on the program order of memory accesses to determine their safety.
69/// At the moment we will only deem accesses as safe for:
70/// * A negative constant distance assuming program order.
71///
72/// Safe: tmp = a[i + 1]; OR a[i + 1] = x;
73/// a[i] = tmp; y = a[i];
74///
75/// The latter case is safe because later checks guarantuee that there can't
76/// be a cycle through a phi node (that is, we check that "x" and "y" is not
77/// the same variable: a header phi can only be an induction or a reduction, a
78/// reduction can't have a memory sink, an induction can't have a memory
79/// source). This is important and must not be violated (or we have to
80/// resort to checking for cycles through memory).
81///
82/// * A positive constant distance assuming program order that is bigger
83/// than the biggest memory access.
84///
85/// tmp = a[i] OR b[i] = x
86/// a[i+2] = tmp y = b[i+2];
87///
88/// Safe distance: 2 x sizeof(a[0]), and 2 x sizeof(b[0]), respectively.
89///
90/// * Zero distances and all accesses have the same size.
91///
93public:
95 PointerIntPair<Value * /* AccessPtr */, 1, bool /* IsWrite */>;
96 /// Set of potential dependent memory accesses.
98
99 /// Type to keep track of the status of the dependence check. The order of
100 /// the elements is important and has to be from most permissive to least
101 /// permissive.
103 // Can vectorize safely without RT checks. All dependences are known to be
104 // safe.
106 // Can possibly vectorize with RT checks to overcome unknown dependencies.
108 // Cannot vectorize due to known unsafe dependencies.
110 };
111
112 /// Dependece between memory access instructions.
113 struct Dependence {
114 /// The type of the dependence.
115 enum DepType {
116 // No dependence.
118 // We couldn't determine the direction or the distance.
120 // At least one of the memory access instructions may access a loop
121 // varying object, e.g. the address of underlying object is loaded inside
122 // the loop, like A[B[i]]. We cannot determine direction or distance in
123 // those cases, and also are unable to generate any runtime checks.
125 // Both accesses to the same loop-invariant address and at least one is a
126 // write. Vectorization is unsafe because different vector lanes would
127 // read/write the same memory location, and the ordering of accesses
128 // across lanes matters.
130
131 // Lexically forward.
132 //
133 // FIXME: If we only have loop-independent forward dependences (e.g. a
134 // read and write of A[i]), LAA will locally deem the dependence "safe"
135 // without querying the MemoryDepChecker. Therefore we can miss
136 // enumerating loop-independent forward dependences in
137 // getDependences. Note that as soon as there are different
138 // indices used to access the same array, the MemoryDepChecker *is*
139 // queried and the dependence list is complete.
141 // Forward, but if vectorized, is likely to prevent store-to-load
142 // forwarding.
144 // Lexically backward.
146 // Backward, but the distance allows a vectorization factor of dependent
147 // on MinDepDistBytes.
149 // Same, but may prevent store-to-load forwarding.
151 };
152
153 /// String version of the types.
154 LLVM_ABI static const char *DepName[];
155
156 /// Index of the source of the dependence in the InstMap vector.
157 unsigned Source;
158 /// Index of the destination of the dependence in the InstMap vector.
159 unsigned Destination;
160 /// The type of the dependence.
162
165
166 /// Return the source instruction of the dependence.
167 Instruction *getSource(const MemoryDepChecker &DepChecker) const;
168 /// Return the destination instruction of the dependence.
169 Instruction *getDestination(const MemoryDepChecker &DepChecker) const;
170
171 /// Dependence types that don't prevent vectorization.
174
175 /// Lexically forward dependence.
176 LLVM_ABI bool isForward() const;
177 /// Lexically backward dependence.
178 LLVM_ABI bool isBackward() const;
179
180 /// May be a lexically backward dependence type (includes Unknown).
181 LLVM_ABI bool isPossiblyBackward() const;
182
183 /// Print the dependence. \p Instr is used to map the instruction
184 /// indices to instructions.
185 LLVM_ABI void print(raw_ostream &OS, unsigned Depth,
186 const SmallVectorImpl<Instruction *> &Instrs) const;
187 };
188
190 DominatorTree *DT, const Loop *L,
191 const DenseMap<Value *, const SCEV *> &SymbolicStrides,
192 unsigned MaxTargetVectorWidthInBits,
193 std::optional<ScalarEvolution::LoopGuards> &LoopGuards)
194 : PSE(PSE), AC(AC), DT(DT), InnermostLoop(L),
195 SymbolicStrides(SymbolicStrides),
196 MaxTargetVectorWidthInBits(MaxTargetVectorWidthInBits),
197 LoopGuards(LoopGuards) {}
198
199 /// Register the location (instructions are given increasing numbers)
200 /// of a write access.
202
203 /// Register the location (instructions are given increasing numbers)
204 /// of a write access.
205 LLVM_ABI void addAccess(LoadInst *LI);
206
207 /// Check whether the dependencies between the accesses are safe, and records
208 /// the dependence information in Dependences if so.
209 ///
210 /// Only checks sets with elements in \p CheckDeps.
211 LLVM_ABI bool areDepsSafe(const DepCandidates &AccessSets,
212 ArrayRef<MemAccessInfo> CheckDeps);
213
214 /// No memory dependence was encountered that would inhibit
215 /// vectorization.
217 return Status == VectorizationSafetyStatus::Safe;
218 }
219
220 /// Return true if the number of elements that are safe to operate on
221 /// simultaneously is not bounded.
223 return MaxSafeVectorWidthInBits == UINT_MAX;
224 }
225
226 /// Return the number of elements that are safe to operate on
227 /// simultaneously, multiplied by the size of the element in bits.
229 return MaxSafeVectorWidthInBits;
230 }
231
232 /// Return true if there are no store-load forwarding dependencies.
234 return MaxStoreLoadForwardSafeDistanceInBits ==
235 std::numeric_limits<uint64_t>::max();
236 }
237
238 /// Return safe power-of-2 number of elements, which do not prevent store-load
239 /// forwarding, multiplied by the size of the elements in bits.
242 "Expected the distance, that prevent store-load forwarding, to be "
243 "set.");
244 return MaxStoreLoadForwardSafeDistanceInBits;
245 }
246
247 /// In same cases when the dependency check fails we can still
248 /// vectorize the loop with a dynamic array access check.
250 return ShouldRetryWithRuntimeChecks &&
252 }
253
254 /// Returns the memory dependences. If null is returned we exceeded
255 /// the MaxDependences threshold and this information is not
256 /// available.
258 return RecordDependences ? &Dependences : nullptr;
259 }
260
261 void clearDependences() { Dependences.clear(); }
262
263 /// The vector of memory access instructions. The indices are used as
264 /// instruction identifiers in the Dependence class.
266 return InstMap;
267 }
268
269 /// Generate a mapping between the memory instructions and their
270 /// indices according to program order.
273
274 for (unsigned I = 0; I < InstMap.size(); ++I)
275 OrderMap[InstMap[I]] = I;
276
277 return OrderMap;
278 }
279
280 /// Find the set of instructions that read or write via \p Ptr.
282 getInstructionsForAccess(Value *Ptr, bool isWrite) const;
283
284 /// Return the program order indices for the access location (Ptr, IsWrite).
285 /// Returns an empty ArrayRef if there are no accesses for the location.
286 ArrayRef<unsigned> getOrderForAccess(Value *Ptr, bool IsWrite) const {
287 auto I = Accesses.find({Ptr, IsWrite});
288 if (I != Accesses.end())
289 return I->second;
290 return {};
291 }
292
293 const Loop *getInnermostLoop() const { return InnermostLoop; }
294
296 std::pair<const SCEV *, const SCEV *>> &
298 return PointerBounds;
299 }
300
302 assert(DT && "requested DT, but it is not available");
303 return DT;
304 }
306 assert(AC && "requested AC, but it is not available");
307 return AC;
308 }
309
310private:
311 /// A wrapper around ScalarEvolution, used to add runtime SCEV checks, and
312 /// applies dynamic knowledge to simplify SCEV expressions and convert them
313 /// to a more usable form. We need this in case assumptions about SCEV
314 /// expressions need to be made in order to avoid unknown dependences. For
315 /// example we might assume a unit stride for a pointer in order to prove
316 /// that a memory access is strided and doesn't wrap.
318
319 AssumptionCache *AC;
320 DominatorTree *DT;
321
322 const Loop *InnermostLoop;
323
324 /// Reference to map of pointer values to
325 /// their stride symbols, if they have a symbolic stride.
326 const DenseMap<Value *, const SCEV *> &SymbolicStrides;
327
328 /// Maps access locations (ptr, read/write) to program order.
330
331 /// Memory access instructions in program order.
333
334 /// The program order index to be used for the next instruction.
335 unsigned AccessIdx = 0;
336
337 /// The smallest dependence distance in bytes in the loop. This may not be
338 /// the same as the maximum number of bytes that are safe to operate on
339 /// simultaneously.
340 uint64_t MinDepDistBytes = 0;
341
342 /// Number of elements (from consecutive iterations) that are safe to
343 /// operate on simultaneously, multiplied by the size of the element in bits.
344 /// The size of the element is taken from the memory access that is most
345 /// restrictive.
346 uint64_t MaxSafeVectorWidthInBits = -1U;
347
348 /// Maximum power-of-2 number of elements, which do not prevent store-load
349 /// forwarding, multiplied by the size of the elements in bits.
350 uint64_t MaxStoreLoadForwardSafeDistanceInBits =
351 std::numeric_limits<uint64_t>::max();
352
353 /// Whether we should try to vectorize the loop with runtime checks, if the
354 /// dependencies are not safe.
355 bool ShouldRetryWithRuntimeChecks = false;
356
357 /// Result of the dependence checks, indicating whether the checked
358 /// dependences are safe for vectorization, require RT checks or are known to
359 /// be unsafe.
360 VectorizationSafetyStatus Status = VectorizationSafetyStatus::Safe;
361
362 //// True if Dependences reflects the dependences in the
363 //// loop. If false we exceeded MaxDependences and
364 //// Dependences is invalid.
365 bool RecordDependences = true;
366
367 /// Memory dependences collected during the analysis. Only valid if
368 /// RecordDependences is true.
369 SmallVector<Dependence, 8> Dependences;
370
371 /// The maximum width of a target's vector registers multiplied by 2 to also
372 /// roughly account for additional interleaving. Is used to decide if a
373 /// backwards dependence with non-constant stride should be classified as
374 /// backwards-vectorizable or unknown (triggering a runtime check).
375 unsigned MaxTargetVectorWidthInBits = 0;
376
377 /// Mapping of SCEV expressions to their expanded pointer bounds (pair of
378 /// start and end pointer expressions).
380 std::pair<const SCEV *, const SCEV *>>
382
383 /// Cache for the loop guards of InnermostLoop.
384 std::optional<ScalarEvolution::LoopGuards> &LoopGuards;
385
386 /// Check whether there is a plausible dependence between the two
387 /// accesses.
388 ///
389 /// Access \p A must happen before \p B in program order. The two indices
390 /// identify the index into the program order map.
391 ///
392 /// This function checks whether there is a plausible dependence (or the
393 /// absence of such can't be proved) between the two accesses. If there is a
394 /// plausible dependence but the dependence distance is bigger than one
395 /// element access it records this distance in \p MinDepDistBytes (if this
396 /// distance is smaller than any other distance encountered so far).
397 /// Otherwise, this function returns true signaling a possible dependence.
398 Dependence::DepType isDependent(const MemAccessInfo &A, unsigned AIdx,
399 const MemAccessInfo &B, unsigned BIdx);
400
401 /// Check whether the data dependence could prevent store-load
402 /// forwarding.
403 ///
404 /// \return false if we shouldn't vectorize at all or avoid larger
405 /// vectorization factors by limiting MinDepDistBytes.
406 bool couldPreventStoreLoadForward(uint64_t Distance, uint64_t TypeByteSize,
407 unsigned CommonStride = 0);
408
409 /// Updates the current safety status with \p S. We can go from Safe to
410 /// either PossiblySafeWithRtChecks or Unsafe and from
411 /// PossiblySafeWithRtChecks to Unsafe.
412 void mergeInStatus(VectorizationSafetyStatus S);
413
414 struct DepDistanceStrideAndSizeInfo {
415 const SCEV *Dist;
416
417 /// Strides here are scaled; i.e. in bytes, taking the size of the
418 /// underlying type into account.
419 uint64_t MaxStride;
420 std::optional<uint64_t> CommonStride;
421
422 /// TypeByteSize is either the common store size of both accesses, or 0 when
423 /// store sizes mismatch.
424 uint64_t TypeByteSize;
425
426 bool AIsWrite;
427 bool BIsWrite;
428
429 DepDistanceStrideAndSizeInfo(const SCEV *Dist, uint64_t MaxStride,
430 std::optional<uint64_t> CommonStride,
431 uint64_t TypeByteSize, bool AIsWrite,
432 bool BIsWrite)
433 : Dist(Dist), MaxStride(MaxStride), CommonStride(CommonStride),
434 TypeByteSize(TypeByteSize), AIsWrite(AIsWrite), BIsWrite(BIsWrite) {}
435 };
436
437 /// Get the dependence distance, strides, type size and whether it is a write
438 /// for the dependence between A and B. Returns a DepType, if we can prove
439 /// there's no dependence or the analysis fails. Outlined to lambda to limit
440 /// he scope of various temporary variables, like A/BPtr, StrideA/BPtr and
441 /// others. Returns either the dependence result, if it could already be
442 /// determined, or a DepDistanceStrideAndSizeInfo struct, noting that
443 /// TypeByteSize could be 0 when store sizes mismatch, and this should be
444 /// checked in the caller.
445 std::variant<Dependence::DepType, DepDistanceStrideAndSizeInfo>
446 getDependenceDistanceStrideAndSize(const MemAccessInfo &A, Instruction *AInst,
447 const MemAccessInfo &B,
448 Instruction *BInst);
449
450 // Return true if we can prove that \p Sink only accesses memory after \p
451 // Src's end or vice versa.
452 bool areAccessesCompletelyBeforeOrAfter(const SCEV *Src, Type *SrcTy,
453 const SCEV *Sink, Type *SinkTy);
454};
455
457/// A grouping of pointers. A single memcheck is required between
458/// two groups.
460 /// Create a new pointer checking group containing a single
461 /// pointer, with index \p Index in RtCheck.
462 LLVM_ABI RuntimeCheckingPtrGroup(unsigned Index,
463 const RuntimePointerChecking &RtCheck);
464
465 /// Tries to add the pointer recorded in RtCheck at index
466 /// \p Index to this pointer checking group. We can only add a pointer
467 /// to a checking group if we will still be able to get
468 /// the upper and lower bounds of the check. Returns true in case
469 /// of success, false otherwise.
470 LLVM_ABI bool addPointer(unsigned Index,
471 const RuntimePointerChecking &RtCheck);
472 LLVM_ABI bool addPointer(unsigned Index, const SCEV *Start, const SCEV *End,
473 unsigned AS, bool NeedsFreeze, ScalarEvolution &SE);
474
475 /// The SCEV expression which represents the upper bound of all the
476 /// pointers in this group.
477 const SCEV *High;
478 /// The SCEV expression which represents the lower bound of all the
479 /// pointers in this group.
480 const SCEV *Low;
481 /// Indices of all the pointers that constitute this grouping.
483 /// Address space of the involved pointers.
484 unsigned AddressSpace;
485 /// Whether the pointer needs to be frozen after expansion, e.g. because it
486 /// may be poison outside the loop.
487 bool NeedsFreeze = false;
488};
489
490/// A memcheck which made up of a pair of grouped pointers.
492 std::pair<const RuntimeCheckingPtrGroup *, const RuntimeCheckingPtrGroup *>;
493
505
506/// Holds information about the memory runtime legality checks to verify
507/// that a group of pointers do not overlap.
510
511public:
512 struct PointerInfo {
513 /// Holds the pointer value that we need to check.
515 /// Holds the smallest byte address accessed by the pointer throughout all
516 /// iterations of the loop.
517 const SCEV *Start;
518 /// Holds the largest byte address accessed by the pointer throughout all
519 /// iterations of the loop, plus 1.
520 const SCEV *End;
521 /// Holds the information if this pointer is used for writing to memory.
523 /// Holds the id of the set of pointers that could be dependent because of a
524 /// shared underlying object.
526 /// Holds the id of the disjoint alias set to which this pointer belongs.
527 unsigned AliasSetId;
528 /// SCEV for the access.
529 const SCEV *Expr;
530 /// True if the pointer expressions needs to be frozen after expansion.
532
539 };
540
542 std::optional<ScalarEvolution::LoopGuards> &LoopGuards)
543 : DC(DC), SE(SE), LoopGuards(LoopGuards) {}
544
545 /// Reset the state of the pointer runtime information.
546 void reset() {
547 Need = false;
548 CanUseDiffCheck = true;
549 Pointers.clear();
550 Checks.clear();
551 DiffChecks.clear();
552 CheckingGroups.clear();
553 }
554
555 /// Insert a pointer and calculate the start and end SCEVs.
556 /// We need \p PSE in order to compute the SCEV expression of the pointer
557 /// according to the assumptions that we've made during the analysis.
558 /// The method might also version the pointer stride according to \p Strides,
559 /// and add new predicates to \p PSE.
560 LLVM_ABI void insert(Loop *Lp, Value *Ptr, const SCEV *PtrExpr,
561 Type *AccessTy, bool WritePtr, unsigned DepSetId,
562 unsigned ASId, PredicatedScalarEvolution &PSE,
563 bool NeedsFreeze);
564
565 /// No run-time memory checking is necessary.
566 bool empty() const { return Pointers.empty(); }
567
568 /// Generate the checks and store it. This also performs the grouping
569 /// of pointers to reduce the number of memchecks necessary.
571
572 /// Returns the checks that generateChecks created. They can be used to ensure
573 /// no read/write accesses overlap across all loop iterations.
575 return Checks;
576 }
577
578 // Returns an optional list of (pointer-difference expressions, access size)
579 // pairs that can be used to prove that there are no vectorization-preventing
580 // dependencies at runtime. There are is a vectorization-preventing dependency
581 // if any pointer-difference is <u VF * InterleaveCount * access size. Returns
582 // std::nullopt if pointer-difference checks cannot be used.
583 std::optional<ArrayRef<PointerDiffInfo>> getDiffChecks() const {
584 if (!CanUseDiffCheck)
585 return std::nullopt;
586 return {DiffChecks};
587 }
588
589 /// Decide if we need to add a check between two groups of pointers,
590 /// according to needsChecking.
592 const RuntimeCheckingPtrGroup &N) const;
593
594 /// Returns the number of run-time checks required according to
595 /// needsChecking.
596 unsigned getNumberOfChecks() const { return Checks.size(); }
597
598 /// Print the list run-time memory checks necessary.
599 LLVM_ABI void print(raw_ostream &OS, unsigned Depth = 0) const;
600
601 /// Print \p Checks.
604 unsigned Depth = 0) const;
605
606 /// This flag indicates if we need to add the runtime check.
607 bool Need = false;
608
609 /// Information about the pointers that may require checking.
611
612 /// Holds a partitioning of pointers into "check groups".
614
615 /// Check if pointers are in the same partition
616 ///
617 /// \p PtrToPartition contains the partition number for pointers (-1 if the
618 /// pointer belongs to multiple partitions).
619 LLVM_ABI static bool
621 unsigned PtrIdx1, unsigned PtrIdx2);
622
623 /// Decide whether we need to issue a run-time check for pointer at
624 /// index \p I and \p J to prove their independence.
625 LLVM_ABI bool needsChecking(unsigned I, unsigned J) const;
626
627 /// Return PointerInfo for pointer at index \p PtrIdx.
628 const PointerInfo &getPointerInfo(unsigned PtrIdx) const {
629 return Pointers[PtrIdx];
630 }
631
632 ScalarEvolution *getSE() const { return SE; }
633
634private:
635 /// Groups pointers such that a single memcheck is required
636 /// between two different groups. This will clear the CheckingGroups vector
637 /// and re-compute it.
638 void groupChecks(MemoryDepChecker::DepCandidates &DepCands);
639
640 /// Generate the checks and return them.
642
643 /// Try to create add a new (pointer-difference, access size) pair to
644 /// DiffCheck for checking groups \p CGI and \p CGJ. If pointer-difference
645 /// checks cannot be used for the groups, set CanUseDiffCheck to false.
646 bool tryToCreateDiffCheck(const RuntimeCheckingPtrGroup &CGI,
647 const RuntimeCheckingPtrGroup &CGJ);
648
650
651 /// Holds a pointer to the ScalarEvolution analysis.
652 ScalarEvolution *SE;
653
654 /// Cache for the loop guards of the loop.
655 std::optional<ScalarEvolution::LoopGuards> &LoopGuards;
656
657 /// Set of run-time checks required to establish independence of
658 /// otherwise may-aliasing pointers in the loop.
660
661 /// Flag indicating if pointer-difference checks can be used
662 bool CanUseDiffCheck = true;
663
664 /// A list of (pointer-difference, access size) pairs that can be used to
665 /// prove that there are no vectorization-preventing dependencies.
667};
668
669/// Drive the analysis of memory accesses in the loop
670///
671/// This class is responsible for analyzing the memory accesses of a loop. It
672/// collects the accesses and then its main helper the AccessAnalysis class
673/// finds and categorizes the dependences in buildDependenceSets.
674///
675/// For memory dependences that can be analyzed at compile time, it determines
676/// whether the dependence is part of cycle inhibiting vectorization. This work
677/// is delegated to the MemoryDepChecker class.
678///
679/// For memory dependences that cannot be determined at compile time, it
680/// generates run-time checks to prove independence. This is done by
681/// AccessAnalysis::canCheckPtrAtRT and the checks are maintained by the
682/// RuntimePointerCheck class. \p AllowPartial determines whether partial checks
683/// are generated when not all pointers could be analyzed.
684///
685/// If pointers can wrap or can't be expressed as affine AddRec expressions by
686/// ScalarEvolution, we will generate run-time checks by emitting a
687/// SCEVUnionPredicate.
688///
689/// Checks for both memory dependences and the SCEV predicates contained in the
690/// PSE must be emitted in order for the results of this analysis to be valid.
692public:
695 const TargetLibraryInfo *TLI, AAResults *AA,
697 bool AllowPartial = false);
698
699 /// Return true we can analyze the memory accesses in the loop and there are
700 /// no memory dependence cycles. Note that for dependences between loads &
701 /// stores with uniform addresses,
702 /// hasStoreStoreDependenceInvolvingLoopInvariantAddress and
703 /// hasLoadStoreDependenceInvolvingLoopInvariantAddress also need to be
704 /// checked.
705 bool canVectorizeMemory() const { return CanVecMem; }
706
707 /// Return true if there is a convergent operation in the loop. There may
708 /// still be reported runtime pointer checks that would be required, but it is
709 /// not legal to insert them.
710 bool hasConvergentOp() const { return HasConvergentOp; }
711
712 /// Return true if, when runtime pointer checking does not have complete
713 /// results, it instead has partial results for those memory accesses that
714 /// could be analyzed.
715 bool hasAllowPartial() const { return AllowPartial; }
716
718 return PtrRtChecking.get();
719 }
720
721 /// Number of memchecks required to prove independence of otherwise
722 /// may-alias pointers.
723 unsigned getNumRuntimePointerChecks() const {
724 return PtrRtChecking->getNumberOfChecks();
725 }
726
727 /// Return true if the block BB needs to be predicated in order for the loop
728 /// to be vectorized.
729 /// \pre \p TheLoop has a unique latch.
730 LLVM_ABI static bool blockNeedsPredication(const BasicBlock *BB,
731 const Loop *TheLoop,
732 const DominatorTree *DT);
733
734 /// Returns true if value \p V is loop invariant.
735 LLVM_ABI bool isInvariant(Value *V) const;
736
737 unsigned getNumStores() const { return NumStores; }
738 unsigned getNumLoads() const { return NumLoads;}
739
740 /// The diagnostics report generated for the analysis. E.g. why we
741 /// couldn't analyze the loop.
742 const OptimizationRemarkAnalysis *getReport() const { return Report.get(); }
743
744 /// the Memory Dependence Checker which can determine the
745 /// loop-independent and loop-carried dependences between memory accesses.
746 const MemoryDepChecker &getDepChecker() const { return *DepChecker; }
747
748 /// Return the list of instructions that use \p Ptr to read or write
749 /// memory.
751 bool isWrite) const {
752 return DepChecker->getInstructionsForAccess(Ptr, isWrite);
753 }
754
755 /// If an access has a symbolic strides, this maps the pointer value to
756 /// the stride symbol.
758 return SymbolicStrides;
759 }
760
761 /// Print the information about the memory accesses in the loop.
762 LLVM_ABI void print(raw_ostream &OS, unsigned Depth = 0) const;
763
764 /// Return true if the loop has memory dependence involving two stores to an
765 /// invariant address, else return false.
767 return HasStoreStoreDependenceInvolvingLoopInvariantAddress;
768 }
769
770 /// Return true if the loop has memory dependence involving a load and a store
771 /// to an invariant address, else return false.
773 return HasLoadStoreDependenceInvolvingLoopInvariantAddress;
774 }
775
776 /// Return the list of stores to invariant addresses.
778 return StoresToInvariantAddresses;
779 }
780
781 /// Used to add runtime SCEV checks. Simplifies SCEV expressions and converts
782 /// them to a more usable form. All SCEV expressions during the analysis
783 /// should be re-written (and therefore simplified) according to PSE.
784 /// A user of LoopAccessAnalysis will need to emit the runtime checks
785 /// associated with this predicate.
786 const PredicatedScalarEvolution &getPSE() const { return *PSE; }
787
788private:
789 /// Analyze the loop. Returns true if all memory access in the loop can be
790 /// vectorized.
791 bool analyzeLoop(AAResults *AA, const LoopInfo *LI,
792 const TargetLibraryInfo *TLI, DominatorTree *DT);
793
794 /// Check if the structure of the loop allows it to be analyzed by this
795 /// pass.
796 bool canAnalyzeLoop();
797
798 /// Save the analysis remark.
799 ///
800 /// LAA does not directly emits the remarks. Instead it stores it which the
801 /// client can retrieve and presents as its own analysis
802 /// (e.g. -Rpass-analysis=loop-vectorize).
804 recordAnalysis(StringRef RemarkName, const Instruction *Instr = nullptr);
805
806 /// Collect memory access with loop invariant strides.
807 ///
808 /// Looks for accesses like "a[i * StrideA]" where "StrideA" is loop
809 /// invariant.
810 void collectStridedAccess(Value *LoadOrStoreInst);
811
812 // Emits the first unsafe memory dependence in a loop.
813 // Emits nothing if there are no unsafe dependences
814 // or if the dependences were not recorded.
815 void emitUnsafeDependenceRemark();
816
817 std::unique_ptr<PredicatedScalarEvolution> PSE;
818
819 /// We need to check that all of the pointers in this list are disjoint
820 /// at runtime. Using std::unique_ptr to make using move ctor simpler.
821 /// If AllowPartial is true then this list may contain only partial
822 /// information when we've failed to analyze all the memory accesses in the
823 /// loop, in which case HasCompletePtrRtChecking will be false.
824 std::unique_ptr<RuntimePointerChecking> PtrRtChecking;
825
826 /// The Memory Dependence Checker which can determine the
827 /// loop-independent and loop-carried dependences between memory accesses.
828 /// This will be empty if we've failed to analyze all the memory access in the
829 /// loop (i.e. CanVecMem is false).
830 std::unique_ptr<MemoryDepChecker> DepChecker;
831
832 Loop *TheLoop;
833
834 /// Cache for the loop guards of TheLoop.
835 std::optional<ScalarEvolution::LoopGuards> LoopGuards;
836
837 /// Determines whether we should generate partial runtime checks when not all
838 /// memory accesses could be analyzed.
839 bool AllowPartial;
840
841 unsigned NumLoads = 0;
842 unsigned NumStores = 0;
843
844 /// Cache the result of analyzeLoop.
845 bool CanVecMem = false;
846 bool HasConvergentOp = false;
847 bool HasCompletePtrRtChecking = false;
848
849 /// Indicator that there are two non vectorizable stores to the same uniform
850 /// address.
851 bool HasStoreStoreDependenceInvolvingLoopInvariantAddress = false;
852 /// Indicator that there is non vectorizable load and store to the same
853 /// uniform address.
854 bool HasLoadStoreDependenceInvolvingLoopInvariantAddress = false;
855
856 /// List of stores to invariant addresses.
857 SmallVector<StoreInst *> StoresToInvariantAddresses;
858
859 /// The diagnostics report generated for the analysis. E.g. why we
860 /// couldn't analyze the loop.
861 std::unique_ptr<OptimizationRemarkAnalysis> Report;
862
863 /// If an access has a symbolic strides, this maps the pointer value to
864 /// the stride symbol.
865 DenseMap<Value *, const SCEV *> SymbolicStrides;
866};
867
868/// Return the SCEV corresponding to a pointer with the symbolic stride
869/// replaced with constant one, assuming the SCEV predicate associated with
870/// \p PSE is true.
871///
872/// If necessary this method will version the stride of the pointer according
873/// to \p PtrToStride and therefore add further predicates to \p PSE.
874///
875/// \p PtrToStride provides the mapping between the pointer value and its
876/// stride as collected by LoopVectorizationLegality::collectStridedAccess.
877LLVM_ABI const SCEV *
878replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE,
879 const DenseMap<Value *, const SCEV *> &PtrToStride,
880 Value *Ptr);
881
882/// If the pointer has a constant stride return it in units of the access type
883/// size. If the pointer is loop-invariant, return 0. Otherwise return
884/// std::nullopt.
885///
886/// Ensure that it does not wrap in the address space, assuming the predicate
887/// associated with \p PSE is true.
888///
889/// If necessary this method will version the stride of the pointer according
890/// to \p PtrToStride and therefore add further predicates to \p PSE.
891/// The \p Assume parameter indicates if we are allowed to make additional
892/// run-time assumptions.
893///
894/// Note that the analysis results are defined if-and-only-if the original
895/// memory access was defined. If that access was dead, or UB, then the
896/// result of this function is undefined.
897LLVM_ABI std::optional<int64_t>
898getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
899 const Loop *Lp, const DominatorTree &DT,
900 const DenseMap<Value *, const SCEV *> &StridesMap =
901 DenseMap<Value *, const SCEV *>(),
902 bool Assume = false, bool ShouldCheckWrap = true);
903
904/// Returns the distance between the pointers \p PtrA and \p PtrB iff they are
905/// compatible and it is possible to calculate the distance between them. This
906/// is a simple API that does not depend on the analysis pass.
907/// \param StrictCheck Ensure that the calculated distance matches the
908/// type-based one after all the bitcasts removal in the provided pointers.
909LLVM_ABI std::optional<int64_t>
910getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB, Value *PtrB,
911 const DataLayout &DL, ScalarEvolution &SE,
912 bool StrictCheck = false, bool CheckType = true);
913
914/// Attempt to sort the pointers in \p VL and return the sorted indices
915/// in \p SortedIndices, if reordering is required.
916///
917/// Returns 'true' if sorting is legal, otherwise returns 'false'.
918///
919/// For example, for a given \p VL of memory accesses in program order, a[i+4],
920/// a[i+0], a[i+1] and a[i+7], this function will sort the \p VL and save the
921/// sorted indices in \p SortedIndices as a[i+0], a[i+1], a[i+4], a[i+7] and
922/// saves the mask for actual memory accesses in program order in
923/// \p SortedIndices as <1,2,0,3>
924LLVM_ABI bool sortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
925 const DataLayout &DL, ScalarEvolution &SE,
926 SmallVectorImpl<unsigned> &SortedIndices);
927
928/// Returns true if the memory operations \p A and \p B are consecutive.
929/// This is a simple API that does not depend on the analysis pass.
930LLVM_ABI bool isConsecutiveAccess(Value *A, Value *B, const DataLayout &DL,
931 ScalarEvolution &SE, bool CheckType = true);
932
933/// Calculate Start and End points of memory access using exact backedge taken
934/// count \p BTC if computable or maximum backedge taken count \p MaxBTC
935/// otherwise.
936///
937/// Let's assume A is the first access and B is a memory access on N-th loop
938/// iteration. Then B is calculated as:
939/// B = A + Step*N .
940/// Step value may be positive or negative.
941/// N is a calculated back-edge taken count:
942/// N = (TripCount > 0) ? RoundDown(TripCount -1 , VF) : 0
943/// Start and End points are calculated in the following way:
944/// Start = UMIN(A, B) ; End = UMAX(A, B) + SizeOfElt,
945/// where SizeOfElt is the size of single memory access in bytes.
946///
947/// There is no conflict when the intervals are disjoint:
948/// NoConflict = (P2.Start >= P1.End) || (P1.Start >= P2.End)
949LLVM_ABI std::pair<const SCEV *, const SCEV *> getStartAndEndForAccess(
950 const Loop *Lp, const SCEV *PtrExpr, Type *AccessTy, const SCEV *BTC,
951 const SCEV *MaxBTC, ScalarEvolution *SE,
952 DenseMap<std::pair<const SCEV *, const SCEV *>,
953 std::pair<const SCEV *, const SCEV *>> *PointerBounds,
954 DominatorTree *DT, AssumptionCache *AC,
955 std::optional<ScalarEvolution::LoopGuards> &LoopGuards);
956LLVM_ABI std::pair<const SCEV *, const SCEV *> getStartAndEndForAccess(
957 const Loop *Lp, const SCEV *PtrExpr, const SCEV *EltSizeSCEV,
958 const SCEV *BTC, const SCEV *MaxBTC, ScalarEvolution *SE,
959 DenseMap<std::pair<const SCEV *, const SCEV *>,
960 std::pair<const SCEV *, const SCEV *>> *PointerBounds,
961 DominatorTree *DT, AssumptionCache *AC,
962 std::optional<ScalarEvolution::LoopGuards> &LoopGuards);
963
965 /// The cache.
967
968 // The used analysis passes.
969 ScalarEvolution &SE;
970 AAResults &AA;
971 DominatorTree &DT;
972 LoopInfo &LI;
974 const TargetLibraryInfo *TLI = nullptr;
975 AssumptionCache *AC;
976
977public:
980 const TargetLibraryInfo *TLI, AssumptionCache *AC)
981 : SE(SE), AA(AA), DT(DT), LI(LI), TTI(TTI), TLI(TLI), AC(AC) {}
982
983 LLVM_ABI const LoopAccessInfo &getInfo(Loop &L, bool AllowPartial = false);
984
985 LLVM_ABI void clear();
986
988 FunctionAnalysisManager::Invalidator &Inv);
989};
990
991/// This analysis provides dependence information for the memory
992/// accesses of a loop.
993///
994/// It runs the analysis for a loop on demand. This can be initiated by
995/// querying the loop access info via AM.getResult<LoopAccessAnalysis>.
996/// getResult return a LoopAccessInfo object. See this class for the
997/// specifics of what information is provided.
999 : public AnalysisInfoMixin<LoopAccessAnalysis> {
1001 LLVM_ABI static AnalysisKey Key;
1002
1003public:
1005
1007};
1008
1010 const MemoryDepChecker &DepChecker) const {
1011 return DepChecker.getMemoryInstructions()[Source];
1012}
1013
1015 const MemoryDepChecker &DepChecker) const {
1016 return DepChecker.getMemoryInstructions()[Destination];
1017}
1018
1019} // End llvm namespace
1020
1021#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
DXIL Forward Handle Accesses
Generic implementation of equivalence classes through the use Tarjan's efficient union-find algorithm...
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckType(MVT::SimpleValueType VT, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:151
This represents a collection of equivalence classes and supports three efficient operations: insert a...
An instruction for reading from memory.
This analysis provides dependence information for the memory accesses of a loop.
LoopAccessInfoManager Result
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
LoopAccessInfoManager(ScalarEvolution &SE, AAResults &AA, DominatorTree &DT, LoopInfo &LI, TargetTransformInfo *TTI, const TargetLibraryInfo *TLI, AssumptionCache *AC)
LLVM_ABI const LoopAccessInfo & getInfo(Loop &L, bool AllowPartial=false)
Drive the analysis of memory accesses in the loop.
const MemoryDepChecker & getDepChecker() const
the Memory Dependence Checker which can determine the loop-independent and loop-carried dependences b...
ArrayRef< StoreInst * > getStoresToInvariantAddresses() const
Return the list of stores to invariant addresses.
const OptimizationRemarkAnalysis * getReport() const
The diagnostics report generated for the analysis.
const RuntimePointerChecking * getRuntimePointerChecking() const
bool canVectorizeMemory() const
Return true we can analyze the memory accesses in the loop and there are no memory dependence cycles.
unsigned getNumLoads() const
unsigned getNumRuntimePointerChecks() const
Number of memchecks required to prove independence of otherwise may-alias pointers.
LLVM_ABI bool isInvariant(Value *V) const
Returns true if value V is loop invariant.
bool hasLoadStoreDependenceInvolvingLoopInvariantAddress() const
Return true if the loop has memory dependence involving a load and a store to an invariant address,...
LLVM_ABI void print(raw_ostream &OS, unsigned Depth=0) const
Print the information about the memory accesses in the loop.
static LLVM_ABI bool blockNeedsPredication(const BasicBlock *BB, const Loop *TheLoop, const DominatorTree *DT)
Return true if the block BB needs to be predicated in order for the loop to be vectorized.
const PredicatedScalarEvolution & getPSE() const
Used to add runtime SCEV checks.
LLVM_ABI LoopAccessInfo(Loop *L, ScalarEvolution *SE, const TargetTransformInfo *TTI, const TargetLibraryInfo *TLI, AAResults *AA, DominatorTree *DT, LoopInfo *LI, AssumptionCache *AC, bool AllowPartial=false)
unsigned getNumStores() const
SmallVector< Instruction *, 4 > getInstructionsForAccess(Value *Ptr, bool isWrite) const
Return the list of instructions that use Ptr to read or write memory.
const DenseMap< Value *, const SCEV * > & getSymbolicStrides() const
If an access has a symbolic strides, this maps the pointer value to the stride symbol.
bool hasAllowPartial() const
Return true if, when runtime pointer checking does not have complete results, it instead has partial ...
bool hasStoreStoreDependenceInvolvingLoopInvariantAddress() const
Return true if the loop has memory dependence involving two stores to an invariant address,...
bool hasConvergentOp() const
Return true if there is a convergent operation in the loop.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Checks memory dependences among accesses to the same underlying object to determine whether there vec...
DominatorTree * getDT() const
ArrayRef< unsigned > getOrderForAccess(Value *Ptr, bool IsWrite) const
Return the program order indices for the access location (Ptr, IsWrite).
bool isSafeForAnyStoreLoadForwardDistances() const
Return true if there are no store-load forwarding dependencies.
LLVM_ABI bool areDepsSafe(const DepCandidates &AccessSets, ArrayRef< MemAccessInfo > CheckDeps)
Check whether the dependencies between the accesses are safe, and records the dependence information ...
bool isSafeForAnyVectorWidth() const
Return true if the number of elements that are safe to operate on simultaneously is not bounded.
DenseMap< std::pair< const SCEV *, const SCEV * >, std::pair< const SCEV *, const SCEV * > > & getPointerBounds()
MemoryDepChecker(PredicatedScalarEvolution &PSE, AssumptionCache *AC, DominatorTree *DT, const Loop *L, const DenseMap< Value *, const SCEV * > &SymbolicStrides, unsigned MaxTargetVectorWidthInBits, std::optional< ScalarEvolution::LoopGuards > &LoopGuards)
PointerIntPair< Value *, 1, bool > MemAccessInfo
const SmallVectorImpl< Instruction * > & getMemoryInstructions() const
The vector of memory access instructions.
EquivalenceClasses< MemAccessInfo > DepCandidates
Set of potential dependent memory accesses.
bool shouldRetryWithRuntimeChecks() const
In same cases when the dependency check fails we can still vectorize the loop with a dynamic array ac...
const Loop * getInnermostLoop() const
uint64_t getMaxSafeVectorWidthInBits() const
Return the number of elements that are safe to operate on simultaneously, multiplied by the size of t...
bool isSafeForVectorization() const
No memory dependence was encountered that would inhibit vectorization.
AssumptionCache * getAC() const
const SmallVectorImpl< Dependence > * getDependences() const
Returns the memory dependences.
LLVM_ABI SmallVector< Instruction *, 4 > getInstructionsForAccess(Value *Ptr, bool isWrite) const
Find the set of instructions that read or write via Ptr.
VectorizationSafetyStatus
Type to keep track of the status of the dependence check.
LLVM_ABI void addAccess(StoreInst *SI)
Register the location (instructions are given increasing numbers) of a write access.
uint64_t getStoreLoadForwardSafeDistanceInBits() const
Return safe power-of-2 number of elements, which do not prevent store-load forwarding,...
DenseMap< Instruction *, unsigned > generateInstructionOrderMap() const
Generate a mapping between the memory instructions and their indices according to program order.
Diagnostic information for optimization analysis remarks.
PointerIntPair - This class implements a pair of a pointer and small integer.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Holds information about the memory runtime legality checks to verify that a group of pointers do not ...
RuntimePointerChecking(MemoryDepChecker &DC, ScalarEvolution *SE, std::optional< ScalarEvolution::LoopGuards > &LoopGuards)
bool Need
This flag indicates if we need to add the runtime check.
void reset()
Reset the state of the pointer runtime information.
unsigned getNumberOfChecks() const
Returns the number of run-time checks required according to needsChecking.
LLVM_ABI void printChecks(raw_ostream &OS, const SmallVectorImpl< RuntimePointerCheck > &Checks, unsigned Depth=0) const
Print Checks.
LLVM_ABI bool needsChecking(const RuntimeCheckingPtrGroup &M, const RuntimeCheckingPtrGroup &N) const
Decide if we need to add a check between two groups of pointers, according to needsChecking.
LLVM_ABI void print(raw_ostream &OS, unsigned Depth=0) const
Print the list run-time memory checks necessary.
std::optional< ArrayRef< PointerDiffInfo > > getDiffChecks() const
SmallVector< RuntimeCheckingPtrGroup, 2 > CheckingGroups
Holds a partitioning of pointers into "check groups".
static LLVM_ABI bool arePointersInSamePartition(const SmallVectorImpl< int > &PtrToPartition, unsigned PtrIdx1, unsigned PtrIdx2)
Check if pointers are in the same partition.
LLVM_ABI void generateChecks(MemoryDepChecker::DepCandidates &DepCands)
Generate the checks and store it.
bool empty() const
No run-time memory checking is necessary.
SmallVector< PointerInfo, 2 > Pointers
Information about the pointers that may require checking.
ScalarEvolution * getSE() const
LLVM_ABI void insert(Loop *Lp, Value *Ptr, const SCEV *PtrExpr, Type *AccessTy, bool WritePtr, unsigned DepSetId, unsigned ASId, PredicatedScalarEvolution &PSE, bool NeedsFreeze)
Insert a pointer and calculate the start and end SCEVs.
const SmallVectorImpl< RuntimePointerCheck > & getChecks() const
Returns the checks that generateChecks created.
const PointerInfo & getPointerInfo(unsigned PtrIdx) const
Return PointerInfo for pointer at index PtrIdx.
This class represents an analyzed expression in the program.
The main scalar evolution driver.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Value handle that tracks a Value across RAUW.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
Abstract Attribute helper functions.
Definition Attributor.h:165
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::pair< const SCEV *, const SCEV * > getStartAndEndForAccess(const Loop *Lp, const SCEV *PtrExpr, Type *AccessTy, const SCEV *BTC, const SCEV *MaxBTC, ScalarEvolution *SE, DenseMap< std::pair< const SCEV *, const SCEV * >, std::pair< const SCEV *, const SCEV * > > *PointerBounds, DominatorTree *DT, AssumptionCache *AC, std::optional< ScalarEvolution::LoopGuards > &LoopGuards)
Calculate Start and End points of memory access using exact backedge taken count BTC if computable or...
std::pair< const RuntimeCheckingPtrGroup *, const RuntimeCheckingPtrGroup * > RuntimePointerCheck
A memcheck which made up of a pair of grouped pointers.
LLVM_ABI std::optional< int64_t > getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB, Value *PtrB, const DataLayout &DL, ScalarEvolution &SE, bool StrictCheck=false, bool CheckType=true)
Returns the distance between the pointers PtrA and PtrB iff they are compatible and it is possible to...
LLVM_ABI bool sortPtrAccesses(ArrayRef< Value * > VL, Type *ElemTy, const DataLayout &DL, ScalarEvolution &SE, SmallVectorImpl< unsigned > &SortedIndices)
Attempt to sort the pointers in VL and return the sorted indices in SortedIndices,...
TargetTransformInfo TTI
LLVM_ABI const SCEV * replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE, const DenseMap< Value *, const SCEV * > &PtrToStride, Value *Ptr)
Return the SCEV corresponding to a pointer with the symbolic stride replaced with constant one,...
LLVM_ABI bool isConsecutiveAccess(Value *A, Value *B, const DataLayout &DL, ScalarEvolution &SE, bool CheckType=true)
Returns true if the memory operations A and B are consecutive.
ArrayRef(const T &OneElt) -> ArrayRef< T >
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI std::optional< int64_t > getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr, const Loop *Lp, const DominatorTree &DT, const DenseMap< Value *, const SCEV * > &StridesMap=DenseMap< Value *, const SCEV * >(), bool Assume=false, bool ShouldCheckWrap=true)
If the pointer has a constant stride return it in units of the access type size.
#define N
IR Values for the lower and upper bounds of a pointer evolution.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
Instruction * getDestination(const MemoryDepChecker &DepChecker) const
Return the destination instruction of the dependence.
DepType Type
The type of the dependence.
unsigned Destination
Index of the destination of the dependence in the InstMap vector.
Dependence(unsigned Source, unsigned Destination, DepType Type)
LLVM_ABI bool isPossiblyBackward() const
May be a lexically backward dependence type (includes Unknown).
Instruction * getSource(const MemoryDepChecker &DepChecker) const
Return the source instruction of the dependence.
LLVM_ABI bool isForward() const
Lexically forward dependence.
LLVM_ABI bool isBackward() const
Lexically backward dependence.
LLVM_ABI void print(raw_ostream &OS, unsigned Depth, const SmallVectorImpl< Instruction * > &Instrs) const
Print the dependence.
unsigned Source
Index of the source of the dependence in the InstMap vector.
DepType
The type of the dependence.
static LLVM_ABI const char * DepName[]
String version of the types.
PointerDiffInfo(const SCEV *SrcStart, const SCEV *SinkStart, unsigned AccessSize, bool NeedsFreeze)
unsigned AddressSpace
Address space of the involved pointers.
LLVM_ABI bool addPointer(unsigned Index, const RuntimePointerChecking &RtCheck)
Tries to add the pointer recorded in RtCheck at index Index to this pointer checking group.
bool NeedsFreeze
Whether the pointer needs to be frozen after expansion, e.g.
LLVM_ABI RuntimeCheckingPtrGroup(unsigned Index, const RuntimePointerChecking &RtCheck)
Create a new pointer checking group containing a single pointer, with index Index in RtCheck.
const SCEV * High
The SCEV expression which represents the upper bound of all the pointers in this group.
SmallVector< unsigned, 2 > Members
Indices of all the pointers that constitute this grouping.
const SCEV * Low
The SCEV expression which represents the lower bound of all the pointers in this group.
PointerInfo(Value *PointerValue, const SCEV *Start, const SCEV *End, bool IsWritePtr, unsigned DependencySetId, unsigned AliasSetId, const SCEV *Expr, bool NeedsFreeze)
const SCEV * Start
Holds the smallest byte address accessed by the pointer throughout all iterations of the loop.
const SCEV * Expr
SCEV for the access.
bool NeedsFreeze
True if the pointer expressions needs to be frozen after expansion.
bool IsWritePtr
Holds the information if this pointer is used for writing to memory.
unsigned DependencySetId
Holds the id of the set of pointers that could be dependent because of a shared underlying object.
unsigned AliasSetId
Holds the id of the disjoint alias set to which this pointer belongs.
const SCEV * End
Holds the largest byte address accessed by the pointer throughout all iterations of the loop,...
TrackingVH< Value > PointerValue
Holds the pointer value that we need to check.
Collection of parameters shared beetween the Loop Vectorizer and the Loop Access Analysis.
static LLVM_ABI const unsigned MaxVectorWidth
Maximum SIMD width.
static LLVM_ABI unsigned RuntimeMemoryCheckThreshold
\When performing memory disambiguation checks at runtime do not make more than this number of compari...
static LLVM_ABI bool isInterleaveForced()
True if force-vector-interleave was specified by the user.
static LLVM_ABI unsigned VectorizationInterleave
Interleave factor as overridden by the user.
static LLVM_ABI ElementCount VectorizationFactor
VF as overridden by the user.
static LLVM_ABI bool HoistRuntimeChecks