15 #ifndef LLVM_ANALYSIS_LOOPACCESSANALYSIS_H 16 #define LLVM_ANALYSIS_LOOPACCESSANALYSIS_H 34 class ScalarEvolution;
37 class SCEVUnionPredicate;
39 class OptimizationRemarkEmitter;
108 PossiblySafeWithRtChecks,
140 BackwardVectorizableButPreventsForwarding
144 static const char *DepName[];
154 : Source(Source), Destination(Destination), Type(Type) {}
165 bool isForward()
const;
167 bool isBackward()
const;
170 bool isPossiblyBackward()
const;
179 : PSE(PSE), InnermostLoop(L), AccessIdx(0), MaxSafeRegisterWidth(-1U),
180 FoundNonConstantDistanceDependence(
false),
187 Accesses[MemAccessInfo(Ptr,
true)].push_back(AccessIdx);
188 InstMap.push_back(SI);
196 Accesses[MemAccessInfo(Ptr,
false)].push_back(AccessIdx);
197 InstMap.push_back(LI);
204 bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoList &CheckDeps,
210 return Status == VectorizationSafetyStatus::Safe;
224 return FoundNonConstantDistanceDependence &&
225 Status == VectorizationSafetyStatus::PossiblySafeWithRtChecks;
232 return RecordDependences ? &Dependences :
nullptr;
248 for (
unsigned I = 0;
I < InstMap.size(); ++
I)
249 OrderMap[InstMap[
I]] =
I;
266 const Loop *InnermostLoop;
278 uint64_t MaxSafeDepDistBytes;
284 uint64_t MaxSafeRegisterWidth;
288 bool FoundNonConstantDistanceDependence;
298 bool RecordDependences;
317 const MemAccessInfo &
B,
unsigned BIdx,
325 bool couldPreventStoreLoadForward(uint64_t Distance, uint64_t TypeByteSize);
357 bool IsWritePtr,
unsigned DependencySetId,
unsigned AliasSetId,
359 : PointerValue(PointerValue), Start(Start), End(End),
360 IsWritePtr(IsWritePtr), DependencySetId(DependencySetId),
361 AliasSetId(AliasSetId), Expr(Expr) {}
378 void insert(
Loop *Lp,
Value *Ptr,
bool WritePtr,
unsigned DepSetId,
383 bool empty()
const {
return Pointers.empty(); }
391 : RtCheck(RtCheck),
High(RtCheck.Pointers[Index].End),
392 Low(RtCheck.Pointers[Index].Start) {
393 Members.push_back(Index);
401 bool addPointer(
unsigned Index);
423 typedef std::pair<const CheckingPtrGroup *, const CheckingPtrGroup *>
429 bool UseDependencies);
448 unsigned Depth = 0)
const;
465 unsigned PtrIdx1,
unsigned PtrIdx2);
469 bool needsChecking(
unsigned I,
unsigned J)
const;
473 return Pointers[PtrIdx];
482 bool UseDependencies);
486 generateChecks()
const;
527 return PtrRtChecking.get();
533 return PtrRtChecking->getNumberOfChecks();
542 bool isUniform(
Value *V)
const;
553 std::pair<Instruction *, Instruction *>
561 std::pair<Instruction *, Instruction *>
564 &PointerChecks)
const;
577 bool isWrite)
const {
578 return DepChecker->getInstructionsForAccess(Ptr, isWrite);
594 return HasDependenceInvolvingLoopInvariantAddress;
611 bool canAnalyzeLoop();
625 void collectStridedAccess(
Value *LoadOrStoreInst);
627 std::unique_ptr<PredicatedScalarEvolution> PSE;
631 std::unique_ptr<RuntimePointerChecking> PtrRtChecking;
635 std::unique_ptr<MemoryDepChecker> DepChecker;
642 uint64_t MaxSafeDepDistBytes;
648 bool HasDependenceInvolvingLoopInvariantAddress;
652 std::unique_ptr<OptimizationRemarkAnalysis> Report;
690 bool Assume =
false,
bool ShouldCheckWrap =
true);
737 LoopAccessInfoMap.clear();
unsigned getNumLoads() const
bool shouldRetryWithRuntimeCheck() const
In same cases when the dependency check fails we can still vectorize the loop with a dynamic array ac...
static unsigned RuntimeMemoryCheckThreshold
performing memory disambiguation checks at runtime do not make more than this number of comparisons...
TrackingVH< Value > PointerValue
Holds the pointer value that we need to check.
A parsed version of the target data layout string in and methods for querying it. ...
SmallVector< CheckingPtrGroup, 2 > CheckingGroups
Holds a partitioning of pointers into "check groups".
const MemoryDepChecker & getDepChecker() const
the Memory Dependence Checker which can determine the loop-independent and loop-carried dependences b...
DenseMap< Instruction *, unsigned > generateInstructionOrderMap() const
Generate a mapping between the memory instructions and their indices according to program order...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void initializeLoopAccessLegacyAnalysisPass(PassRegistry &)
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
DepType Type
The type of the dependence.
const RuntimePointerChecking * getRuntimePointerChecking() const
The main scalar evolution driver.
int64_t getPtrStride(PredicatedScalarEvolution &PSE, Value *Ptr, const Loop *Lp, const ValueToValueMap &StridesMap=ValueToValueMap(), bool Assume=false, bool ShouldCheckWrap=true)
If the pointer has a constant stride return it in units of its element size.
const ValueToValueMap & getSymbolicStrides() const
If an access has a symbolic strides, this maps the pointer value to the stride symbol.
bool IsWritePtr
Holds the information if this pointer is used for writing to memory.
void reset()
Reset the state of the pointer runtime information.
SmallVector< Instruction *, 4 > getInstructionsForAccess(Value *Ptr, bool isWrite) const
Return the list of instructions that use Ptr to read or write memory.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
block Block Frequency true
An instruction for reading from memory.
Checks memory dependences among accesses to the same underlying object to determine whether there vec...
static unsigned VectorizationFactor
VF as overridden by the user.
uint64_t getMaxSafeDepDistBytes() const
uint64_t getMaxSafeDepDistBytes()
The maximum number of bytes of a vector register we can vectorize the accesses safely with...
const OptimizationRemarkAnalysis * getReport() const
The diagnostics report generated for the analysis.
static const unsigned MaxVectorWidth
Maximum SIMD width.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Instruction * getDestination(const LoopAccessInfo &LAI) const
Return the destination instruction of the dependence.
unsigned getNumRuntimePointerChecks() const
Number of memchecks required to prove independence of otherwise may-alias pointers.
unsigned getNumberOfChecks() const
Returns the number of run-time checks required according to needsChecking.
bool isSafeForVectorization() const
No memory dependence was encountered that would inhibit vectorization.
const SmallVectorImpl< Instruction * > & getMemoryInstructions() const
The vector of memory access instructions.
unsigned getNumStores() const
Instruction * getSource(const LoopAccessInfo &LAI) const
Return the source instruction of the dependence.
unsigned Source
Index of the source of the dependence in the InstMap vector.
RuntimePointerChecking(ScalarEvolution *SE)
This header provides classes for managing per-loop analyses.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
An instruction for storing to memory.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
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.
static bool runOnFunction(Function &F, bool PostInlining)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM Basic Block Representation.
Value handle that tracks a Value across RAUW.
PointerInfo(Value *PointerValue, const SCEV *Start, const SCEV *End, bool IsWritePtr, unsigned DependencySetId, unsigned AliasSetId, const SCEV *Expr)
This analysis provides dependence information for the memory accesses of a loop.
const SCEV * End
Holds the largest byte address accessed by the pointer throughout all iterations of the loop...
A CRTP mix-in that provides informational APIs needed for analysis passes.
EquivalenceClasses - This represents a collection of equivalence classes and supports three efficient...
Represent the analysis usage information of a pass.
VectorizationSafetyStatus
Type to keep track of the status of the dependence check.
void addAccess(StoreInst *SI)
Register the location (instructions are given increasing numbers) of a write access.
FunctionPass class - This class is used to implement most global optimizations.
const SCEV * replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE, const ValueToValueMap &PtrToStride, Value *Ptr, Value *OrigPtr=nullptr)
Return the SCEV corresponding to a pointer with the symbolic stride replaced with constant one...
Value * getPointerOperand()
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
const PredicatedScalarEvolution & getPSE() const
Used to add runtime SCEV checks.
std::pair< const CheckingPtrGroup *, const CheckingPtrGroup * > PointerCheck
A memcheck which made up of a pair of grouped pointers.
Value * stripIntegerCast(Value *V)
unsigned AliasSetId
Holds the id of the disjoint alias set to which this pointer belongs.
DepType
The type of the dependence.
SmallVector< unsigned, 2 > Members
Indices of all the pointers that constitute this grouping.
const SmallVectorImpl< Dependence > * getDependences() const
Returns the memory dependences.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Dependence(unsigned Source, unsigned Destination, DepType Type)
DenseMap< const Value *, Value * > ValueToValueMap
const PointerInfo & getPointerInfo(unsigned PtrIdx) const
Return PointerInfo for pointer at index PtrIdx.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Provides information about what library functions are available for the current target.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
const SCEV * Low
The SCEV expression which represents the lower bound of all the pointers in this group.
Drive the analysis of memory accesses in the loop.
Holds information about the memory runtime legality checks to verify that a group of pointers do not ...
SmallVector< MemAccessInfo, 8 > MemAccessInfoList
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void addAccess(LoadInst *LI)
Register the location (instructions are given increasing numbers) of a write access.
bool hasStride(Value *V) const
Pointer has a symbolic stride.
This analysis provides dependence information for the memory accesses of a loop.
Dependece between memory access instructions.
const SCEV * Start
Holds the smallest byte address accessed by the pointer throughout all iterations of the loop...
This class represents an analyzed expression in the program.
const SCEV * High
The SCEV expression which represents the upper bound of all the pointers in this group.
Represents a single loop in the control flow graph.
bool empty() const
No run-time memory checking is necessary.
SmallVector< PointerInfo, 2 > Pointers
Information about the pointers that may require checking.
PointerIntPair< Value *, 1, bool > MemAccessInfo
Collection of parameters shared beetween the Loop Vectorizer and the Loop Access Analysis.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
RuntimePointerChecking & RtCheck
Constitutes the context of this pointer checking group.
bool hasDependenceInvolvingLoopInvariantAddress() const
If the loop has memory dependence involving an invariant address, i.e.
LLVM Value Representation.
LoopAccessLegacyAnalysis()
CheckingPtrGroup(unsigned Index, RuntimePointerChecking &RtCheck)
Create a new pointer checking group containing a single pointer, with index Index in RtCheck...
This class implements an extremely fast bulk output stream that can only output to a stream...
static unsigned VectorizationInterleave
Interleave factor as overridden by the user.
MemoryDepChecker(PredicatedScalarEvolution &PSE, const Loop *L)
StringRef - Represent a constant reference to a string, i.e.
A container for analyses that lazily runs them and caches their results.
static bool isInterleaveForced()
True if force-vector-interleave was specified by the user.
const SmallVector< PointerCheck, 4 > & getChecks() const
Returns the checks that generateChecks created.
bool sortPtrAccesses(ArrayRef< Value *> VL, const DataLayout &DL, ScalarEvolution &SE, SmallVectorImpl< unsigned > &SortedIndices)
Attempt to sort the pointers in VL and return the sorted indices in SortedIndices, if reordering is required.
Value * getPointerOperand()
bool canVectorizeMemory() const
Return true we can analyze the memory accesses in the loop and there are no memory dependence cycles...
uint64_t getMaxSafeRegisterWidth() const
Return the number of elements that are safe to operate on simultaneously, multiplied by the size of t...
A special type used by analysis passes to provide an address that identifies that particular analysis...
EquivalenceClasses< MemAccessInfo > DepCandidates
Set of potential dependent memory accesses.
unsigned DependencySetId
Holds the id of the set of pointers that could be dependent because of a shared underlying object...
const SCEV * Expr
SCEV for the access.
unsigned Destination
Index of the destination of the dependence in the InstMap vector.
bool Need
This flag indicates if we need to add the runtime check.