15 #ifndef LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
16 #define LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
33 class ScalarEvolution;
45 : Message(Message.
str()), Instr(I) {}
58 std::string &
str() {
return Message; }
59 const std::string &
str()
const {
return Message; }
60 operator Twine() {
return Message; }
68 const char *PassName);
163 : Source(Source), Destination(Destination), Type(Type) {}
181 : SE(Se), InnermostLoop(L), AccessIdx(0),
182 ShouldRetryWithRuntimeCheck(
false), SafeForVectorization(
true),
183 RecordInterestingDependences(
true) {}
190 InstMap.push_back(SI);
199 InstMap.push_back(LI);
225 return RecordInterestingDependences ? &InterestingDependences :
nullptr;
242 const Loop *InnermostLoop;
254 unsigned MaxSafeDepDistBytes;
258 bool ShouldRetryWithRuntimeCheck;
262 bool SafeForVectorization;
267 bool RecordInterestingDependences;
292 bool couldPreventStoreLoadForward(
unsigned Distance,
unsigned TypeByteSize);
319 : PointerValue(PointerValue), Start(Start), End(End),
320 IsWritePtr(IsWritePtr), DependencySetId(DependencySetId),
321 AliasSetId(AliasSetId), Expr(Expr) {}
376 bool UseDependencies);
448 return &PtrRtChecking;
479 std::pair<Instruction *, Instruction *>
494 bool isWrite)
const {
510 return StoreToLoopInvariantAddress;
519 bool canAnalyzeLoop();
542 unsigned MaxSafeDepDistBytes;
549 bool StoreToLoopInvariantAddress;
566 Value *Ptr, Value *OrigPtr =
nullptr);
570 int isStridedPtr(ScalarEvolution *SE, Value *Ptr,
const Loop *Lp,
602 LoopAccessInfoMap.clear();
bool isPossiblyBackward() const
Lexically backward dependence types.
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)
void insert(Loop *Lp, Value *Ptr, bool WritePtr, unsigned DepSetId, unsigned ASId, const ValueToValueMap &Strides)
Insert a pointer and calculate the start and end SCEVs.
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".
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
ScalarEvolution - This class is the main scalar evolution driver.
bool IsWritePtr
Holds the information if this pointer is used for writing to memory.
void reset()
Reset the state of the pointer runtime information.
LoadInst - 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.
const SCEV * replaceSymbolicStrideSCEV(ScalarEvolution *SE, const ValueToValueMap &PtrToStride, Value *Ptr, Value *OrigPtr=nullptr)
Return the SCEV corresponding to a pointer with the symbolic stride replaced with constant one...
DenseMap< const Value *, Value * > ValueToValueMap
MemoryDepChecker(ScalarEvolution *Se, const Loop *L)
bool empty() const
No run-time memory checking is necessary.
static const unsigned MaxVectorWidth
Maximum SIMD width.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LoopAccessReport(const Twine &Message, const Instruction *I)
const Optional< LoopAccessReport > & getReport() const
The diagnostics report generated for the analysis.
const std::string & str() const
void initializeLoopAccessAnalysisPass(PassRegistry &)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
const SmallVectorImpl< Dependence > * getInterestingDependences() const
Returns the interesting dependences.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
const Instruction * getInstr() const
static const char * DepName[]
String version of the types.
LoopAccessInfo(Loop *L, ScalarEvolution *SE, const DataLayout &DL, const TargetLibraryInfo *TLI, AliasAnalysis *AA, DominatorTree *DT, LoopInfo *LI, const ValueToValueMap &Strides)
void print(raw_ostream &OS, unsigned Depth=0, const SmallVectorImpl< int > *PtrPartition=nullptr) const
Print the list run-time memory checks necessary.
const RuntimePointerChecking * getRuntimePointerChecking() const
unsigned Source
Index of the source of the dependence in the InstMap vector.
RuntimePointerChecking(ScalarEvolution *SE)
StoreInst - an instruction for storing to memory.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Optimization analysis message produced during vectorization.
LLVM Basic Block Representation.
PointerIntPair - This class implements a pair of a pointer and small integer.
bool needsChecking(const CheckingPtrGroup &M, const CheckingPtrGroup &N, const SmallVectorImpl< int > *PtrPartition) const
Decide if we need to add a check between two groups of pointers, according to needsChecking.
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)
unsigned getNumRuntimePointerChecks(const SmallVectorImpl< int > *PtrPartition=nullptr) const
Number of memchecks required to prove independence of otherwise may-alias pointers.
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 pointer value at the end of the loop.
unsigned NumSymbolicStrides
Used to ensure that if the analysis was run with speculating the value of symbolic strides...
bool addPointer(unsigned Index)
Tries to add the pointer recorded in RtCheck at index Index to this pointer checking group...
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.
FunctionPass class - This class is used to implement most global optimizations.
Value * getPointerOperand()
int isStridedPtr(ScalarEvolution *SE, Value *Ptr, const Loop *Lp, const ValueToValueMap &StridesMap)
Check the stride of the pointer and ensure that it does not wrap in the address space.
void groupChecks(MemoryDepChecker::DepCandidates &DepCands, bool UseDependencies)
Groups pointers such that a single memcheck is required between two different groups.
Value * stripIntegerCast(Value *V)
static void emitAnalysis(const LoopAccessReport &Message, const Function *TheFunction, const Loop *TheLoop, const char *PassName)
Emit an analysis note for PassName with the debug location from the instruction in Message if availab...
LoopAccessReport & operator<<(const A &Value)
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.
unsigned getNumberOfChecks(const SmallVectorImpl< int > *PtrPartition) const
Returns the number of run-time checks required according to needsChecking.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
LoopAccessReport(const Instruction *I=nullptr)
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.
const LoopAccessInfo & getInfo(Loop *L, const ValueToValueMap &Strides)
Query the result of the loop access information for the loop L.
const SCEV * Low
The SCEV expression which represents the lower bound of all the pointers in this group.
void print(raw_ostream &OS, const Module *M=nullptr) const override
Print the result of the analysis when invoked with -analyze.
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.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool needsAnyChecking(const SmallVectorImpl< int > *PtrPartition) const
Return true if any pointer requires run-time checking according to needsChecking. ...
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.
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 pointer value at the beginning of the loop.
SCEV - 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.
SmallPtrSet< MemAccessInfo, 8 > MemAccessInfoSet
SmallVector< PointerInfo, 2 > Pointers
Information about the pointers that may require checking.
PointerIntPair< Value *, 1, bool > MemAccessInfo
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Collection of parameters shared beetween the Loop Vectorizer and the Loop Access Analysis.
bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoSet &CheckDeps, const ValueToValueMap &Strides)
Check whether the dependencies between the accesses are safe.
RuntimePointerChecking & RtCheck
Constitutes the context of this pointer checking group.
A raw_ostream that writes to an std::string.
LLVM Value Representation.
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...
void clearInterestingDependences()
bool canVectorizeMemory() const
Return true we can analyze the memory accesses in the loop and there are no memory dependence cycles...
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.
std::pair< Instruction *, Instruction * > addRuntimeCheck(Instruction *Loc, const SmallVectorImpl< int > *PtrPartition=nullptr) const
Add code that checks at runtime if the accessed arrays overlap.
static bool isInterestingDependence(DepType Type)
Dependence types that can be queried from the analysis.
static bool isInterleaveForced()
True if force-vector-interleave was specified by the user.
unsigned getMaxSafeDepDistBytes()
The maximum number of bytes of a vector register we can vectorize the accesses safely with...
Value * getPointerOperand()
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 getMaxSafeDepDistBytes() const
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.