15 #ifndef LLVM_ANALYSIS_LOOPACCESSANALYSIS_H 16 #define LLVM_ANALYSIS_LOOPACCESSANALYSIS_H 34 class ScalarEvolution;
37 class SCEVUnionPredicate;
39 class OptimizationRemarkEmitter;
127 BackwardVectorizableButPreventsForwarding
131 static const char *DepName[];
141 : Source(Source), Destination(Destination), Type(Type) {}
149 static bool isSafeForVectorization(
DepType Type);
152 bool isForward()
const;
154 bool isBackward()
const;
157 bool isPossiblyBackward()
const;
166 : PSE(PSE), InnermostLoop(L), AccessIdx(0), MaxSafeRegisterWidth(-1U),
167 ShouldRetryWithRuntimeCheck(
false), SafeForVectorization(
true),
168 RecordDependences(
true) {}
174 Accesses[MemAccessInfo(Ptr,
true)].push_back(AccessIdx);
175 InstMap.push_back(SI);
183 Accesses[MemAccessInfo(Ptr,
false)].push_back(AccessIdx);
184 InstMap.push_back(LI);
191 bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoList &CheckDeps,
214 return RecordDependences ? &Dependences :
nullptr;
230 for (
unsigned I = 0;
I < InstMap.size(); ++
I)
231 OrderMap[InstMap[
I]] =
I;
248 const Loop *InnermostLoop;
260 uint64_t MaxSafeDepDistBytes;
266 uint64_t MaxSafeRegisterWidth;
270 bool ShouldRetryWithRuntimeCheck;
274 bool SafeForVectorization;
279 bool RecordDependences;
298 const MemAccessInfo &
B,
unsigned BIdx,
306 bool couldPreventStoreLoadForward(uint64_t Distance, uint64_t TypeByteSize);
333 bool IsWritePtr,
unsigned DependencySetId,
unsigned AliasSetId,
335 : PointerValue(PointerValue), Start(Start), End(End),
336 IsWritePtr(IsWritePtr), DependencySetId(DependencySetId),
337 AliasSetId(AliasSetId), Expr(Expr) {}
354 void insert(
Loop *Lp,
Value *
Ptr,
bool WritePtr,
unsigned DepSetId,
359 bool empty()
const {
return Pointers.empty(); }
367 : RtCheck(RtCheck),
High(RtCheck.Pointers[Index].End),
368 Low(RtCheck.Pointers[Index].Start) {
369 Members.push_back(Index);
377 bool addPointer(
unsigned Index);
399 typedef std::pair<const CheckingPtrGroup *, const CheckingPtrGroup *>
405 bool UseDependencies);
424 unsigned Depth = 0)
const;
441 unsigned PtrIdx1,
unsigned PtrIdx2);
445 bool needsChecking(
unsigned I,
unsigned J)
const;
449 return Pointers[PtrIdx];
458 bool UseDependencies);
462 generateChecks()
const;
503 return PtrRtChecking.get();
509 return PtrRtChecking->getNumberOfChecks();
518 bool isUniform(
Value *V)
const;
529 std::pair<Instruction *, Instruction *>
537 std::pair<Instruction *, Instruction *>
540 &PointerChecks)
const;
553 bool isWrite)
const {
554 return DepChecker->getInstructionsForAccess(Ptr, isWrite);
571 return StoreToLoopInvariantAddress;
588 bool canAnalyzeLoop();
602 void collectStridedAccess(
Value *LoadOrStoreInst);
604 std::unique_ptr<PredicatedScalarEvolution> PSE;
608 std::unique_ptr<RuntimePointerChecking> PtrRtChecking;
612 std::unique_ptr<MemoryDepChecker> DepChecker;
619 uint64_t MaxSafeDepDistBytes;
626 bool StoreToLoopInvariantAddress;
630 std::unique_ptr<OptimizationRemarkAnalysis> Report;
668 bool Assume =
false,
bool ShouldCheckWrap =
true);
715 LoopAccessInfoMap.clear();
unsigned getNumLoads() const
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 &)
Compute iterated dominance frontiers using a linear time algorithm.
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.
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.
bool hasStoreToLoopInvariantAddress() const
Checks existence of store to invariant address inside loop.
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.
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.
bool shouldRetryWithRuntimeCheck()
In same cases when the dependency check fails we can still vectorize the loop with a dynamic array ac...
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.