15 #ifndef LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
16 #define LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
34 class ScalarEvolution;
37 class SCEVUnionPredicate;
39 class OptimizationRemarkEmitter;
141 : Source(Source), Destination(Destination), Type(Type) {}
166 : PSE(PSE), InnermostLoop(L), AccessIdx(0),
167 ShouldRetryWithRuntimeCheck(
false), SafeForVectorization(
true),
168 RecordDependences(
true) {}
175 InstMap.push_back(SI);
184 InstMap.push_back(LI);
210 return RecordDependences ? &Dependences :
nullptr;
226 for (
unsigned I = 0;
I < InstMap.size(); ++
I)
227 OrderMap[InstMap[
I]] =
I;
244 const Loop *InnermostLoop;
256 uint64_t MaxSafeDepDistBytes;
260 bool ShouldRetryWithRuntimeCheck;
264 bool SafeForVectorization;
269 bool RecordDependences;
296 bool couldPreventStoreLoadForward(uint64_t Distance, uint64_t TypeByteSize);
325 : PointerValue(PointerValue), Start(Start), End(End),
326 IsWritePtr(IsWritePtr), DependencySetId(DependencySetId),
327 AliasSetId(AliasSetId), Expr(Expr) {}
389 typedef std::pair<const CheckingPtrGroup *, const CheckingPtrGroup *>
395 bool UseDependencies);
403 const CheckingPtrGroup &
N)
const;
414 unsigned Depth = 0)
const;
431 unsigned PtrIdx1,
unsigned PtrIdx2);
448 bool UseDependencies);
452 generateChecks()
const;
493 return PtrRtChecking.get();
499 return PtrRtChecking->getNumberOfChecks();
519 std::pair<Instruction *, Instruction *>
527 std::pair<Instruction *, Instruction *>
530 &PointerChecks)
const;
543 bool isWrite)
const {
544 return DepChecker->getInstructionsForAccess(Ptr, isWrite);
561 return StoreToLoopInvariantAddress;
578 bool canAnalyzeLoop();
592 void collectStridedAccess(
Value *LoadOrStoreInst);
594 std::unique_ptr<PredicatedScalarEvolution> PSE;
598 std::unique_ptr<RuntimePointerChecking> PtrRtChecking;
602 std::unique_ptr<MemoryDepChecker> DepChecker;
609 uint64_t MaxSafeDepDistBytes;
616 bool StoreToLoopInvariantAddress;
620 std::unique_ptr<OptimizationRemarkAnalysis> Report;
644 Value *
Ptr, Value *OrigPtr =
nullptr);
656 int64_t
getPtrStride(PredicatedScalarEvolution &PSE, Value *
Ptr,
const Loop *Lp,
658 bool Assume =
false,
bool ShouldCheckWrap =
true);
663 ScalarEvolution &SE,
bool CheckType =
true);
691 LoopAccessInfoMap.clear();
bool isPossiblyBackward() const
May be a lexically backward dependence type (includes Unknown).
void print(raw_ostream &OS, unsigned Depth, const SmallVectorImpl< Instruction * > &Instrs) const
Print the dependence.
void print(raw_ostream &OS, unsigned Depth=0) const
Print the information about the memory accesses in the loop.
static unsigned RuntimeMemoryCheckThreshold
\brief When performing memory disambiguation checks at runtime do not make more than this number of c...
TrackingVH< Value > PointerValue
Holds the pointer value that we need to check.
void push_back(const T &Elt)
SmallVector< CheckingPtrGroup, 2 > CheckingGroups
Holds a partitioning of pointers into "check groups".
void print(raw_ostream &OS, unsigned Depth=0) const
Print the list run-time memory checks necessary.
uint64_t getMaxSafeDepDistBytes() const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool hasStride(Value *V) const
Pointer has a symbolic stride.
void initializeLoopAccessLegacyAnalysisPass(PassRegistry &)
unsigned getNumLoads() const
const SmallVectorImpl< Instruction * > & getMemoryInstructions() const
The vector of memory access instructions.
A Module instance is used to store all the information related to an LLVM module. ...
DepType Type
The type of the dependence.
bool isSafeForVectorization() const
No memory dependence was encountered that would inhibit vectorization.
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.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool IsWritePtr
Holds the information if this pointer is used for writing to memory.
std::pair< Instruction *, Instruction * > addRuntimeChecks(Instruction *Loc) const
Add code that checks at runtime if the accessed arrays overlap.
void reset()
Reset the state of the pointer runtime information.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
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.
DenseMap< const Value *, Value * > ValueToValueMap
void printChecks(raw_ostream &OS, const SmallVectorImpl< PointerCheck > &Checks, unsigned Depth=0) const
Print Checks.
void insert(Loop *Lp, Value *Ptr, bool WritePtr, unsigned DepSetId, unsigned ASId, const ValueToValueMap &Strides, PredicatedScalarEvolution &PSE)
Insert a pointer and calculate the start and end SCEVs.
bool empty() const
No run-time memory checking is necessary.
uint64_t getMaxSafeDepDistBytes()
The maximum number of bytes of a vector register we can vectorize the accesses safely with...
static const unsigned MaxVectorWidth
Maximum SIMD width.
static bool arePointersInSamePartition(const SmallVectorImpl< int > &PtrToPartition, unsigned PtrIdx1, unsigned PtrIdx2)
Check if pointers are in the same partition.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
const PredicatedScalarEvolution & getPSE() const
Used to add runtime SCEV checks.
static const char * DepName[]
String version of the types.
const RuntimePointerChecking * getRuntimePointerChecking() const
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.
An instruction for storing to memory.
Instruction * getDestination(const LoopAccessInfo &LAI) const
Return the destination instruction of the dependence.
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.
Instruction * getSource(const LoopAccessInfo &LAI) const
Return the source instruction of the dependence.
Function Alias Analysis false
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
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.
SmallVector< Instruction *, 4 > getInstructionsForAccess(Value *Ptr, bool isWrite) const
Return the list of instructions that use Ptr to read or write memory.
const SCEV * End
Holds the largest byte address accessed by the pointer throughout all iterations of the loop...
const PointerInfo & getPointerInfo(unsigned PtrIdx) const
Return PointerInfo for pointer at index PtrIdx.
bool addPointer(unsigned Index)
Tries to add the pointer recorded in RtCheck at index Index to this pointer checking group...
Result run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR)
A CRTP mix-in that provides informational APIs needed for analysis passes.
SmallVector< Instruction *, 4 > getInstructionsForAccess(Value *Ptr, bool isWrite) const
Find the set of instructions that read or write via Ptr.
EquivalenceClasses - This represents a collection of equivalence classes and supports three efficient...
Represent the analysis usage information of a pass.
unsigned getNumStores() const
void addAccess(StoreInst *SI)
Register the location (instructions are given increasing numbers) of a write access.
const SmallVector< PointerCheck, 4 > & getChecks() const
Returns the checks that generateChecks created.
static const unsigned End
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()
std::pair< const CheckingPtrGroup *, const CheckingPtrGroup * > PointerCheck
A memcheck which made up of a pair of grouped pointers.
const OptimizationRemarkAnalysis * getReport() const
The diagnostics report generated for the analysis.
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.
bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoList &CheckDeps, const ValueToValueMap &Strides)
Check whether the dependencies between the accesses are safe.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
const ValueToValueMap & getSymbolicStrides() const
If an access has a symbolic strides, this maps the pointer value to the stride symbol.
bool isBackward() const
Lexically backward dependence.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
bool isUniform(Value *V) const
Returns true if the value V is uniform within the loop.
Dependence(unsigned Source, unsigned Destination, DepType Type)
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 ...
bool isForward() const
Lexically forward dependence.
const SCEV * Low
The SCEV expression which represents the lower bound of all the pointers in this group.
const MemoryDepChecker & getDepChecker() const
the Memory Dependence Checker which can determine the loop-independent and loop-carried dependences b...
Drive the analysis of memory accesses in the loop.
const SmallVectorImpl< Dependence > * getDependences() const
Returns the memory dependences.
const LoopAccessInfo & getInfo(Loop *L)
Query the result of the loop access information for the loop L.
void generateChecks(MemoryDepChecker::DepCandidates &DepCands, bool UseDependencies)
Generate the checks and store it.
Holds information about the memory runtime legality checks to verify that a group of pointers do not ...
bool hasStoreToLoopInvariantAddress() const
Checks existence of store to invariant address inside loop.
static bool isSafeForVectorization(DepType Type)
Dependence types that don't prevent vectorization.
unsigned getNumberOfChecks() const
Returns the number of run-time checks required according to needsChecking.
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...
unsigned getNumRuntimePointerChecks() const
Number of memchecks required to prove independence of otherwise may-alias pointers.
void addAccess(LoadInst *LI)
Register the location (instructions are given increasing numbers) of a write access.
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
SmallVector< PointerInfo, 2 > Pointers
Information about the pointers that may require checking.
PointerIntPair< Value *, 1, bool > MemAccessInfo
DenseMap< Instruction *, unsigned > generateInstructionOrderMap() const
Generate a mapping between the memory instructions and their indices according to program order...
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()
static bool blockNeedsPredication(BasicBlock *BB, Loop *TheLoop, DominatorTree *DT)
Return true if the block BB needs to be predicated in order for the loop to be vectorized.
CheckingPtrGroup(unsigned Index, RuntimePointerChecking &RtCheck)
Create a new pointer checking group containing a single pointer, with index Index in RtCheck...
bool canVectorizeMemory() const
Return true we can analyze the memory accesses in the loop and there are no memory dependence cycles...
bool needsChecking(const CheckingPtrGroup &M, const CheckingPtrGroup &N) const
Decide if we need to add a check between two groups of pointers, according to needsChecking.
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.
Value * getPointerOperand()
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.
void print(raw_ostream &OS, const Module *M=nullptr) const override
Print the result of the analysis when invoked with -analyze.
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.
LoopAccessInfo(Loop *L, ScalarEvolution *SE, const TargetLibraryInfo *TLI, AliasAnalysis *AA, DominatorTree *DT, LoopInfo *LI)