39#ifndef LLVM_ANALYSIS_DEPENDENCEANALYSIS_H
40#define LLVM_ANALYSIS_DEPENDENCEANALYSIS_H
52struct AnalysisOptions;
81 :
Src(Source),
Dst(Destination), Assumptions(
A) {}
98 enum :
unsigned char {
124 bool isOutput()
const;
156 virtual unsigned getDirection(
unsigned Level,
bool SameSD =
false)
const {
188 virtual bool isScalar(
unsigned Level,
bool SameSD =
false)
const;
212 void dumpImp(
raw_ostream &OS,
bool IsSameSD =
false)
const;
219 const Dependence *NextPredecessor =
nullptr, *NextSuccessor =
nullptr;
235 bool PossiblyLoopIndependent,
unsigned Levels);
258 assert(0 < Level && Level <= Levels &&
"Level out of range");
259 return DV[Level - 1];
262 Level <=
static_cast<unsigned>(Levels) + SameSDLevels &&
263 "isSameSD level out of range");
264 return DVSameSD[Level - Levels - 1];
270 unsigned getDirection(
unsigned Level,
bool SameSD =
false)
const override;
274 const SCEV *getDistance(
unsigned Level,
bool SameSD =
false)
const override;
278 bool isDirectionNegative()
const override;
291 bool inSameSDLoops(
unsigned Level)
const override;
296 bool isScalar(
unsigned Level,
bool SameSD =
false)
const override;
299 unsigned short Levels;
300 unsigned short SameSDLevels;
301 bool LoopIndependent;
302 std::unique_ptr<DVEntry[]> DV;
303 std::unique_ptr<DVEntry[]> DVSameSD;
315 FunctionAnalysisManager::Invalidator &Inv);
324 LLVM_ABI std::unique_ptr<Dependence>
326 bool UnderRuntimeAssumptions =
false);
331 const AnalysisOptions &Opts;
340 void updateLoopAliasScopes(
const Loop *L);
348 enum ClassificationKind { ZIV, SIV, RDIV, MIV, NonLinear } Classification;
349 SmallBitVector
Loops;
352 struct CoefficientInfo {
353 const SCEV *SrcCoeff;
354 const SCEV *DstCoeff;
355 const SCEV *MaxIterIndex;
359 const SCEV *Upper[8];
360 const SCEV *Lower[8];
361 unsigned char Direction;
362 unsigned char DirSet;
369 bool haveSameSD(
const Loop *SrcLoop,
const Loop *DstLoop)
const;
433 void establishNestingLevels(
const Instruction *Src,
const Instruction *Dst);
435 unsigned CommonLevels, SrcLevels, MaxLevels, SameSDLevels;
439 unsigned mapSrcLoop(
const Loop *SrcLoop)
const;
443 unsigned mapDstLoop(
const Loop *DstLoop)
const;
447 bool isLoopInvariant(
const SCEV *Expression,
const Loop *LoopNest)
const;
451 void collectCommonLoops(
const SCEV *Expression,
const Loop *LoopNest,
452 SmallBitVector &
Loops)
const;
456 bool checkSrcSubscript(
const SCEV *Src,
const Loop *LoopNest,
457 SmallBitVector &
Loops);
461 bool checkDstSubscript(
const SCEV *Dst,
const Loop *LoopNest,
462 SmallBitVector &
Loops);
469 const SCEV *collectUpperBound(
const Loop *l,
Type *
T)
const;
474 std::optional<APInt> collectNonNegativeConstantUpperBound(
const Loop *L,
480 Subscript::ClassificationKind
481 classifyPair(
const SCEV *Src,
const Loop *SrcLoopNest,
const SCEV *Dst,
482 const Loop *DstLoopNest, SmallBitVector &
Loops);
488 bool testZIV(
const SCEV *Src,
const SCEV *Dst, FullDependence &Result)
const;
499 bool testSIV(
const SCEV *Src,
const SCEV *Dst,
unsigned &Level,
500 FullDependence &Result,
bool UnderRuntimeAssumptions);
510 bool testRDIV(
const SCEV *Src,
const SCEV *Dst, FullDependence &Result)
const;
515 bool testMIV(
const SCEV *Src,
const SCEV *Dst,
const SmallBitVector &
Loops,
516 FullDependence &Result)
const;
526 bool strongSIVtest(
const SCEVAddRecExpr *Src,
const SCEVAddRecExpr *Dst,
527 unsigned Level, FullDependence &Result,
528 bool UnderRuntimeAssumptions);
538 bool weakCrossingSIVtest(
const SCEVAddRecExpr *Src,
const SCEVAddRecExpr *Dst,
539 unsigned Level, FullDependence &Result)
const;
549 bool exactSIVtest(
const SCEVAddRecExpr *Src,
const SCEVAddRecExpr *Dst,
550 unsigned Level, FullDependence &Result)
const;
554 bool weakZeroSIVtestImpl(
const SCEVAddRecExpr *AR,
const SCEV *Const,
555 unsigned Level, FullDependence &Result)
const;
565 bool weakZeroSrcSIVtest(
const SCEV *SrcConst,
const SCEVAddRecExpr *Dst,
566 unsigned Level, FullDependence &Result)
const;
576 bool weakZeroDstSIVtest(
const SCEVAddRecExpr *Src,
const SCEV *DstConst,
577 unsigned Level, FullDependence &Result)
const;
586 bool exactRDIVtest(
const SCEVAddRecExpr *Src,
const SCEVAddRecExpr *Dst,
587 FullDependence &Result)
const;
593 bool exactTestImpl(
const SCEVAddRecExpr *Src,
const SCEVAddRecExpr *Dst,
594 FullDependence &Result,
595 std::optional<unsigned> Level)
const;
602 bool gcdMIVtest(
const SCEV *Src,
const SCEV *Dst,
603 FullDependence &Result)
const;
608 bool banerjeeMIVtest(
const SCEV *Src,
const SCEV *Dst,
609 const SmallBitVector &
Loops,
610 FullDependence &Result)
const;
615 const SCEV *collectCoeffInfo(
const SCEV *Subscript,
bool SrcFlag,
634 const SCEV *accumulateCoefficientsGCD(
const SCEV *Expr,
const Loop *CurLoop,
635 const SCEV *&CurLoopCoeff,
636 APInt &RunningGCD)
const;
654 const SmallBitVector &
Loops,
const SCEV *Delta,
655 const FullDependence &Result)
const;
659 bool testBounds(
unsigned char DirKind,
unsigned Level,
684 bool tryDelinearize(Instruction *Src, Instruction *Dst,
685 SmallVectorImpl<Subscript> &Pair);
690 bool tryDelinearizeFixedSize(Instruction *Src, Instruction *Dst,
691 const SCEV *SrcAccessFn,
const SCEV *DstAccessFn,
692 SmallVectorImpl<const SCEV *> &SrcSubscripts,
693 SmallVectorImpl<const SCEV *> &DstSubscripts);
699 tryDelinearizeParametricSize(Instruction *Src, Instruction *Dst,
700 const SCEV *SrcAccessFn,
const SCEV *DstAccessFn,
701 SmallVectorImpl<const SCEV *> &SrcSubscripts,
702 SmallVectorImpl<const SCEV *> &DstSubscripts);
706 bool checkSubscript(
const SCEV *Expr,
const Loop *LoopNest,
707 SmallBitVector &
Loops,
bool IsSrc);
725 : OS(OS), NormalizeResults(NormalizeResults) {}
734 bool NormalizeResults;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This header defines various interfaces for pass management in LLVM.
static bool isInput(const ArrayRef< StringRef > &Prefixes, StringRef Arg)
FunctionAnalysisManager FAM
This file implements the SmallBitVector class.
This file defines the SmallPtrSet class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
AnalysisPass to compute dependence information in a function.
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &FAM)
DependenceInfo - This class is the main dependence-analysis driver.
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle transitive invalidation when the cached analysis results go away.
Function * getFunction() const
LLVM_ABI DependenceInfo(Function *F, AAResults *AA, ScalarEvolution *SE, LoopInfo *LI)
LLVM_ABI std::unique_ptr< Dependence > depends(Instruction *Src, Instruction *Dst, bool UnderRuntimeAssumptions=false)
depends - Tests for a dependence between the Src and Dst instructions.
Instruction * getDst() const
getDst - Returns the destination instruction for this dependence.
Dependence & operator=(Dependence &&)=default
bool isOrdered() const
isOrdered - Returns true if dependence is Output, Flow, or Anti
void setNextSuccessor(const Dependence *succ)
setNextSuccessor - Sets the value of the NextSuccessor field.
friend class DependenceInfo
Dependence(Instruction *Source, Instruction *Destination, const SCEVUnionPredicate &A)
Dependence(Dependence &&)=default
bool isUnordered() const
isUnordered - Returns true if dependence is Input
SCEVUnionPredicate getRuntimeAssumptions() const
getRuntimeAssumptions - Returns the runtime assumptions under which this Dependence relation is valid...
virtual bool isConfused() const
isConfused - Returns true if this dependence is confused (the compiler understands nothing and makes ...
virtual unsigned getSameSDLevels() const
getSameSDLevels - Returns the number of separate SameSD loops surrounding the source and destination ...
virtual const SCEV * getDistance(unsigned Level, bool SameSD=false) const
getDistance - Returns the distance (or NULL) associated with a particular common or SameSD level.
virtual void negate(ScalarEvolution &SE)
Negate the dependence by swapping the source and destination, and reversing the direction and distanc...
virtual unsigned getLevels() const
getLevels - Returns the number of common loops surrounding the source and destination of the dependen...
const Dependence * getNextPredecessor() const
getNextPredecessor - Returns the value of the NextPredecessor field.
virtual unsigned getDirection(unsigned Level, bool SameSD=false) const
getDirection - Returns the direction associated with a particular common or SameSD level.
bool isFlow() const
isFlow - Returns true if this is a flow (aka true) dependence.
virtual ~Dependence()=default
virtual bool normalize(ScalarEvolution *SE)
If the direction vector is negative, normalize the direction vector to make it non-negative.
bool isAnti() const
isAnti - Returns true if this is an anti dependence.
const Dependence * getNextSuccessor() const
getNextSuccessor - Returns the value of the NextSuccessor field.
virtual bool isDirectionNegative() const
Check if the direction vector is negative.
Instruction * getSrc() const
getSrc - Returns the source instruction for this dependence.
virtual bool isLoopIndependent() const
isLoopIndependent - Returns true if this is a loop-independent dependence.
bool isOutput() const
isOutput - Returns true if this is an output dependence.
void setNextPredecessor(const Dependence *pred)
setNextPredecessor - Sets the value of the NextPredecessor field.
virtual bool inSameSDLoops(unsigned Level) const
inSameSDLoops - Returns true if this level is an SameSD level, i.e., performed across two separate lo...
FullDependence(Instruction *Source, Instruction *Destination, const SCEVUnionPredicate &Assumes, bool PossiblyLoopIndependent, unsigned Levels)
bool isConfused() const override
isConfused - Returns true if this dependence is confused (the compiler understands nothing and makes ...
friend class DependenceInfo
DVEntry getDVEntry(unsigned Level, bool IsSameSD) const
getDVEntry - Returns the DV entry associated with a regular or a SameSD level.
bool isLoopIndependent() const override
isLoopIndependent - Returns true if this is a loop-independent dependence.
unsigned getSameSDLevels() const override
getSameSDLevels - Returns the number of separate SameSD loops surrounding the source and destination ...
unsigned getLevels() const override
getLevels - Returns the number of common loops surrounding the source and destination of the dependen...
Represents a single loop in the control flow graph.
A set of analyses that are preserved following a run of a transformation pass.
This class represents a composition of other SCEV predicates, and is the class that most clients will...
This class represents an analyzed expression in the program.
The main scalar evolution driver.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Represent a constant reference to a string, i.e.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Abstract Attribute helper functions.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
ArrayRef(const T &OneElt) -> ArrayRef< T >
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
DependenceAnalysisPrinterPass(raw_ostream &OS, bool NormalizeResults=false)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
Dependence::DVEntry - Each level in the distance/direction vector has a direction (or perhaps a union...
A CRTP mix-in for passes that should not be skipped.