15 #ifndef LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
16 #define LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
34 class ScalarEvolution;
37 class SCEVUnionPredicate;
39 class OptimizationRemarkEmitter;
49 : Message(Message.
str()), Instr(I) {}
62 std::string &
str() {
return Message; }
63 const std::string &
str()
const {
return Message; }
64 operator Twine() {
return Message; }
174 : Source(Source), Destination(Destination), Type(Type) {}
199 : PSE(PSE), InnermostLoop(L), AccessIdx(0),
200 ShouldRetryWithRuntimeCheck(
false), SafeForVectorization(
true),
201 RecordDependences(
true) {}
208 InstMap.push_back(SI);
217 InstMap.push_back(LI);
243 return RecordDependences ? &Dependences :
nullptr;
259 for (
unsigned I = 0;
I < InstMap.size(); ++
I)
260 OrderMap[InstMap[
I]] =
I;
277 const Loop *InnermostLoop;
289 uint64_t MaxSafeDepDistBytes;
293 bool ShouldRetryWithRuntimeCheck;
297 bool SafeForVectorization;
302 bool RecordDependences;
329 bool couldPreventStoreLoadForward(uint64_t Distance, uint64_t TypeByteSize);
358 : PointerValue(PointerValue), Start(Start), End(End),
359 IsWritePtr(IsWritePtr), DependencySetId(DependencySetId),
360 AliasSetId(AliasSetId), Expr(Expr) {}
422 typedef std::pair<const CheckingPtrGroup *, const CheckingPtrGroup *>
428 bool UseDependencies);
436 const CheckingPtrGroup &
N)
const;
447 unsigned Depth = 0)
const;
464 unsigned PtrIdx1,
unsigned PtrIdx2);
481 bool UseDependencies);
485 generateChecks()
const;
526 return PtrRtChecking.get();
532 return PtrRtChecking->getNumberOfChecks();
552 std::pair<Instruction *, Instruction *>
560 std::pair<Instruction *, Instruction *>
563 &PointerChecks)
const;
576 bool isWrite)
const {
577 return DepChecker->getInstructionsForAccess(Ptr, isWrite);
594 return StoreToLoopInvariantAddress;
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;
649 bool StoreToLoopInvariantAddress;
653 std::unique_ptr<OptimizationRemarkAnalysis> Report;
677 Value *
Ptr, Value *OrigPtr =
nullptr);
689 int64_t
getPtrStride(PredicatedScalarEvolution &PSE, Value *
Ptr,
const Loop *Lp,
691 bool Assume =
false,
bool ShouldCheckWrap =
true);
696 ScalarEvolution &SE,
bool CheckType =
true);
724 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...
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LoopAccessReport(const Twine &Message, const Instruction *I)
const std::string & str() const
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.
const Instruction * getInstr() const
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.
Function Alias Analysis false
RuntimePointerChecking(ScalarEvolution *SE)
This header provides classes for managing per-loop analyses.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
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...
Optimization analysis message produced during vectorization.
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.
LLVM Basic Block Representation.
PointerIntPair - This class implements a pair of a pointer and small integer.
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)
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.
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.
LoopAccessReport(const Instruction *I=nullptr)
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.
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.
SmallPtrSet< MemAccessInfo, 8 > MemAccessInfoSet
Represents a single loop in the control flow graph.
static void emitAnalysis(const LoopAccessReport &Message, const Loop *TheLoop, const char *PassName, OptimizationRemarkEmitter &ORE)
Emit an analysis note for PassName with the debug location from the instruction in Message if availab...
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.
bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoSet &CheckDeps, const ValueToValueMap &Strides)
Check whether the dependencies between the accesses are safe.
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.
A raw_ostream that writes to an std::string.
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.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
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)