14#ifndef LLVM_ANALYSIS_LOOPCACHEANALYSIS_H
15#define LLVM_ANALYSIS_LOOPCACHEANALYSIS_H
62 return Subscripts[SubNum];
65 assert(!Subscripts.empty() &&
"Expecting non-empty container");
66 return Subscripts.front();
69 assert(!Subscripts.empty() &&
"Expecting non-empty container");
70 return Subscripts.back();
105 bool isLoopInvariant(
const Loop &L)
const;
112 bool isConsecutive(
const Loop &L,
const SCEV *&Stride,
unsigned CLS)
const;
119 int getSubscriptIndex(
const Loop &L)
const;
122 const SCEV *getLastCoefficient()
const;
126 bool isCoeffForLoopZeroOrInvariant(
const SCEV &Subscript,
127 const Loop &L)
const;
131 bool isSimpleAddRecurrence(
const SCEV &Subscript,
const Loop &L)
const;
139 bool IsValid =
false;
145 const SCEV *BasePointer =
nullptr;
189 using LoopTripCountTy = std::pair<const Loop *, unsigned>;
190 using LoopCacheCostTy = std::pair<const Loop *, CacheCostTy>;
200 std::optional<unsigned> TRT = std::nullopt);
206 LLVM_ABI static std::unique_ptr<CacheCost>
208 std::optional<unsigned> TRT = std::nullopt);
213 auto IT =
llvm::find_if(LoopCosts, [&L](
const LoopCacheCostTy &LCC) {
214 return LCC.first == &L;
216 return (IT != LoopCosts.end()) ? (*IT).second : -1;
225 void calculateCacheFootprint();
248 const Loop &L)
const;
251 void sortLoopCosts() {
253 [](
const LoopCacheCostTy &
A,
const LoopCacheCostTy &
B) {
254 return A.second >
B.second;
263 SmallVector<LoopTripCountTy, 3> TripCounts;
266 SmallVector<LoopCacheCostTy, 3> LoopCosts;
270 std::optional<unsigned> TRT;
274 TargetTransformInfo &TTI;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This header defines various interfaces for pass management in LLVM.
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
This header provides classes for managing per-loop analyses.
FunctionAnalysisManager FAM
Represent a constant reference to an array (0 or more elements consecutively in memory),...
CacheCost represents the estimated cost of a inner loop as the number of cache lines used by the memo...
LLVM_ABI CacheCost(const LoopVectorTy &Loops, const LoopInfo &LI, ScalarEvolution &SE, TargetTransformInfo &TTI, AAResults &AA, DependenceInfo &DI, std::optional< unsigned > TRT=std::nullopt)
Construct a CacheCost object for the loop nest described by Loops.
friend LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const CacheCost &CC)
ArrayRef< LoopCacheCostTy > getLoopCosts() const
Return the estimated ordered loop costs.
static LLVM_ABI std::unique_ptr< CacheCost > getCacheCost(Loop &Root, LoopStandardAnalysisResults &AR, DependenceInfo &DI, std::optional< unsigned > TRT=std::nullopt)
Create a CacheCost for the loop nest rooted by Root.
CacheCostTy getLoopCost(const Loop &L) const
Return the estimated cost of loop L if the given loop is part of the loop nest associated with this o...
DependenceInfo - This class is the main dependence-analysis driver.
Represents a memory reference as a base pointer and a set of indexing operations.
const SCEV * getBasePointer() const
LLVM_ABI CacheCostTy computeRefCost(const Loop &L, unsigned CLS) const
Compute the cost of the reference w.r.t.
const SCEV * getSubscript(unsigned SubNum) const
const SCEV * getFirstSubscript() const
LLVM_ABI std::optional< bool > hasSpacialReuse(const IndexedReference &Other, unsigned CLS, AAResults &AA) const
Return true/false if the current object and the indexed reference Other are/aren't in the same cache ...
LLVM_ABI std::optional< bool > hasTemporalReuse(const IndexedReference &Other, unsigned MaxDistance, const Loop &L, DependenceInfo &DI, AAResults &AA) const
Return true if the current object and the indexed reference Other have distance smaller than MaxDista...
LLVM_ABI IndexedReference(Instruction &StoreOrLoadInst, const LoopInfo &LI, ScalarEvolution &SE)
Construct an indexed reference given a StoreOrLoadInst instruction.
const SCEV * getLastSubscript() const
friend LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const IndexedReference &R)
size_t getNumSubscripts() const
LoopCachePrinterPass(raw_ostream &OS)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
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 an analyzed expression in the program.
The main scalar evolution driver.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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 stable_sort(R &&Range)
InstructionCost CacheCostTy
SmallVector< std::unique_ptr< IndexedReference >, 8 > ReferenceGroupTy
A reference group represents a set of memory references that exhibit temporal or spacial reuse.
SmallVector< Loop *, 8 > LoopVectorTy
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
LLVM_ABI void delinearize(ScalarEvolution &SE, const SCEV *Expr, SmallVectorImpl< const SCEV * > &Subscripts, SmallVectorImpl< const SCEV * > &Sizes, const SCEV *ElementSize)
Split this SCEVAddRecExpr into two vectors of SCEVs representing the subscripts and sizes of an array...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
SmallVector< ReferenceGroupTy, 8 > ReferenceGroupsTy
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
A CRTP mix-in for passes that should not be skipped.