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