17#ifndef POLLY_SCOPINFO_H
18#define POLLY_SCOPINFO_H
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/MapVector.h"
25#include "llvm/ADT/SetVector.h"
26#include "llvm/Analysis/RegionPass.h"
27#include "llvm/IR/DebugLoc.h"
28#include "llvm/IR/Instruction.h"
29#include "llvm/IR/Instructions.h"
30#include "llvm/IR/PassManager.h"
31#include "llvm/IR/ValueHandle.h"
36#include <forward_list>
40using llvm::AnalysisInfoMixin;
42using llvm::AssertingVH;
43using llvm::AssumptionCache;
45using llvm::DataLayout;
48using llvm::function_ref;
50using llvm::iterator_range;
52using llvm::make_range;
54using llvm::MemIntrinsic;
55using llvm::PassInfoMixin;
57using llvm::RegionNode;
58using llvm::RegionPass;
59using llvm::RGPassManager;
61using llvm::SmallPtrSetImpl;
62using llvm::SmallVector;
63using llvm::SmallVectorImpl;
68using llvm::ValueToValueMap;
233 const DataLayout &
DL,
Scop *
S,
const char *BaseName =
nullptr);
260 bool updateSizes(ArrayRef<const SCEV *> Sizes,
bool CheckConsistency =
true);
351#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
359 void print(raw_ostream &OS,
bool SizeAsPwAff =
false)
const;
424 const DataLayout &
DL;
572 SmallVector<std::pair<BasicBlock *, Value *>, 4>
Incoming;
711 Value *BaseAddress, Type *ElemType,
bool Affine,
736 void addIncoming(BasicBlock *IncomingBlock, Value *IncomingValue) {
739 Incoming.emplace_back(std::make_pair(IncomingBlock, IncomingValue));
888 iterator_range<SubscriptsTy::const_iterator>
subscripts()
const {
1077 void print(raw_ostream &OS)
const;
1079#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1158 std::vector<Instruction *> EntryBlockInstructions);
1248 BasicBlock *
BB =
nullptr;
1251 Region *
R =
nullptr;
1383 "No surrounding loop for artificially created statements");
1401 if (It->second.empty())
1418 for (
auto Access : It->getSecond()) {
1419 if (!Access->isArrayKind())
1422 assert(!ArrayAccess &&
"More then one array access for instruction");
1424 ArrayAccess = Access;
1437 assert(ArrayAccess &&
"No array access found for instruction!");
1438 return *ArrayAccess;
1478 if (isa<PHINode>(Val))
1481 "statement cannot read a .s2a and "
1482 ".phiops simultaneously");
1545 std::vector<Instruction *>::const_iterator
insts_end()
const {
1550 iterator_range<std::vector<Instruction *>::const_iterator>
insts()
const {
1586 void print(raw_ostream &OS,
bool PrintInstructions)
const;
1604#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1611raw_ostream &
operator<<(raw_ostream &OS,
const ScopStmt &
S);
1704 OptimizationRemarkEmitter &
ORE;
1708 DenseMap<BasicBlock *, std::vector<ScopStmt *>>
StmtMap;
1723 std::map<std::pair<AssertingVH<const Value>,
MemoryKind>,
1724 std::unique_ptr<ScopArrayInfo>>;
1862 DenseMap<const ScopArrayInfo *, SmallVector<MemoryAccess *, 4>>
ValueUseAccs;
1866 DenseMap<const ScopArrayInfo *, SmallVector<MemoryAccess *, 4>>
1870 Scop(Region &
R, ScalarEvolution &
SE, LoopInfo &LI, DominatorTree &
DT,
1901 void addScopStmt(BasicBlock *BB, StringRef Name, Loop *SurroundingLoop,
1902 std::vector<Instruction *> Instructions);
1915 void addScopStmt(Region *
R, StringRef Name, Loop *SurroundingLoop,
1916 std::vector<Instruction *> EntryBlockInstructions);
1978 "there can be just one definition per value");
1983 "there can be just one PHI read per PHINode");
2007 ScalarEvolution *
getSE()
const;
2049 name =
R.getNameStr();
2095 bool contains(
const Loop *L)
const {
return R.contains(L); }
2098 bool contains(
const BasicBlock *BB)
const {
return R.contains(BB); }
2101 bool contains(
const Instruction *I)
const {
return R.contains(I); }
2119 Region::block_range
blocks()
const {
return R.blocks(); }
2300 bool AfterHoisting =
true);
2390 ArrayRef<const SCEV *> Sizes,
2392 const char *BaseName =
nullptr);
2400 const std::string &BaseName,
2401 const std::vector<unsigned> &Sizes);
2467 void print(raw_ostream &OS,
bool PrintInstructions)
const;
2469#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2495 bool NonNegative =
false,
2681 std::unique_ptr<Scop>
S;
2699 bool runOnRegion(Region *R, RGPassManager &RGM)
override;
2703 void print(raw_ostream &O,
const Module *
M =
nullptr)
const override;
2729 OptimizationRemarkEmitter &
ORE;
2733 LoopInfo &
LI, AAResults &
AA, DominatorTree &
DT, AssumptionCache &
AC,
2734 OptimizationRemarkEmitter &
ORE);
2745 return MapIt->second.get();
2755 bool invalidate(Function &F,
const PreservedAnalyses &PA,
2756 FunctionAnalysisManager::Invalidator &Inv);
2774 Result run(Function &, FunctionAnalysisManager &);
2780 PreservedAnalyses
run(Function &, FunctionAnalysisManager &);
2810 void print(raw_ostream &O,
const Module *
M =
nullptr)
const override;
polly dump Polly Dump Function
static RegisterPass< ScopPrinterWrapperPass > M("dot-scops", "Polly - Print Scops of function")
polly scop functions based on how much of the function is a scop
isl::set subtract(isl::set set2) const
isl::set intersect_params(isl::set params) const
Represent memory accesses in statements.
const ScopArrayInfo * getLatestScopArrayInfo() const
Get the ScopArrayInfo object for the base address, or the one set by setNewAccessRelation().
std::string getAccessRelationStr() const
Get an isl string representing the latest access relation.
void addIncoming(BasicBlock *IncomingBlock, Value *IncomingValue)
Add a new incoming block/value pairs for this PHI/ExitPHI access.
isl::map getNewAccessRelation() const
Get the new access function imported or set by a pass.
void dump() const
Print the MemoryAccess to stderr.
isl::set assumeNoOutOfBound()
isl::id getArrayId() const
Old name of getOriginalArrayId().
SmallVector< const SCEV *, 4 > Sizes
Size of each dimension of the accessed array.
bool isOriginalArrayKind() const
Whether this is an access of an explicit load or store in the IR.
void foldAccessRelation()
Fold the memory access to consider parametric offsets.
AssertingVH< Value > AccessValue
The value associated with this memory access.
bool isOriginalValueKind() const
Was this MemoryAccess detected as a scalar dependences?
MemoryAccess & operator=(const MemoryAccess &)=delete
bool isLatestPHIKind() const
Is this MemoryAccess modeling special PHI node accesses, also considering a potential change by setNe...
isl::space getOriginalAccessRelationSpace() const
Return the space in which the access relation lives in.
bool isAnyPHIKind() const
Old name of isOriginalAnyPHIKind().
AccessType
The access type of a memory access.
void markAsReductionLike(ReductionType RT)
Mark this a reduction like access.
ReductionType
Reduction access type.
@ RT_BOTTOM
Pseudo type for the data flow analysis.
@ RT_NONE
Indicate no reduction at all.
isl::basic_map createBasicAccessMap(ScopStmt *Statement)
SubscriptsTy Subscripts
Subscript expression for each dimension.
isl::map getLatestAccessRelation() const
Return the newest access relation of this access.
isl::id getOriginalArrayId() const
Get the detection-time base array isl::id for this access.
MemoryAccess(const MemoryAccess &)=delete
isl::pw_aff getPwAff(const SCEV *E)
Compute the isl representation for the SCEV E wrt.
Instruction * AccessInstruction
The access instruction of this memory access.
void computeBoundsOnAccessRelation(unsigned ElementSize)
Compute bounds on an over approximated access relation.
ReductionType RedType
Reduction type for reduction like accesses, RT_NONE otherwise.
bool isValueKind() const
Old name of isOriginalValueKind().
bool hasNewAccessRelation() const
Check if a new access relation was imported or set by a pass.
isl::id Id
A unique identifier for this memory access.
bool isOriginalExitPHIKind() const
Was this MemoryAccess detected as the accesses of a PHI node in the SCoP's exit block?
bool isLatestArrayKind() const
Whether storage memory is either an custom .s2a/.phiops alloca (false) or an existing pointer into an...
bool isPHIKind() const
Old name of isOriginalPHIKind.
bool isWrite() const
Is this a write memory access?
bool IsAffine
Are all the subscripts affine expression?
ReductionType getReductionType() const
Get the reduction type of this access.
MemoryKind getLatestKind() const
Return the kind considering a potential setNewAccessRelation.
const ScopArrayInfo * getOriginalScopArrayInfo() const
Get the detection-time ScopArrayInfo object for the base address.
AssertingVH< Value > BaseAddr
The base address (e.g., A for A[i+j]).
bool isOriginalAnyPHIKind() const
Was this access detected as one of the two PHI types?
void updateDimensionality()
Update the dimensionality of the memory access.
Instruction * getAccessInstruction() const
Return the access instruction of this memory access.
iterator_range< SubscriptsTy::const_iterator > subscripts() const
Return an iterator range containing the subscripts.
bool isStrideZero(isl::map Schedule) const
Is always the same memory accessed for a given statement instance set? Schedule is a map from the sta...
bool isLatestPartialAccess() const
Return whether the MemoryyAccess is a partial access.
std::string getOriginalAccessRelationStr() const
Get an isl string representing the access function read from IR.
bool isExitPHIKind() const
Old name of isOriginalExitPHIKind().
Value * tryGetValueStored()
Return llvm::Value that is stored by this access, if available.
isl::set InvalidDomain
The domain under which this access is not modeled precisely.
enum AccessType getType()
Get the type of a memory access.
bool isLatestScalarKind() const
Whether this access is an array to a scalar memory object, also considering changes by setNewAccessRe...
bool isRead() const
Is this a read memory access?
void buildAccessRelation(const ScopArrayInfo *SAI)
Assemble the access relation from all available information.
isl::id getId() const
Get identifier for the memory access.
isl::map NewAccessRelation
Updated access relation read from JSCOP file.
SmallVector< const SCEV *, 4 > SubscriptsTy
unsigned getNumSubscripts() const
Return the number of access function subscript.
isl::map getAddressFunction() const
Get an isl map describing the memory address accessed.
void setAccessRelation(isl::map AccessRelation)
Update the original access relation.
bool isMustWrite() const
Is this a must-write memory access?
bool isScalarKind() const
Old name of isOriginalScalarKind.
isl::map AccessRelation
Relation from statement instances to the accessed array elements.
void realignParams()
Align the parameters in the access relation to the scop context.
Type * getElementType() const
Return the element type of the accessed array wrt. this access.
const SCEV * getSubscript(unsigned Dim) const
Return the access function subscript in the dimension Dim.
bool isReductionLike() const
Is this a reduction like access?
bool isOriginalPHIKind() const
Was this MemoryAccess detected as a special PHI node access?
isl::set getInvalidContext() const
Get the invalid context for this access.
void print(raw_ostream &OS) const
Print the MemoryAccess.
const ScopArrayInfo * getScopArrayInfo() const
Legacy name of getOriginalScopArrayInfo().
void wrapConstantDimensions()
Carry index overflows of dimensions with constant size to the next higher dimension.
bool isOriginalScalarKind() const
Whether this access is an array to a scalar memory object, without considering changes by setNewAcces...
ScopStmt * Statement
Parent ScopStmt of this access.
bool isStrideX(isl::map Schedule, int StrideWidth) const
Is the stride of the access equal to a certain width? Schedule is a map from the statement to a sched...
bool isStrideOne(isl::map Schedule) const
Is consecutive memory accessed for a given statement instance set? Schedule is a map from the stateme...
Type * ElementType
Type a single array element wrt. this access.
enum AccessType AccType
Whether it a reading or writing access, and if writing, whether it is conditional (MAY_WRITE).
std::string getNewAccessRelationStr() const
Get an isl string representing a new access function, if available.
void buildMemIntrinsicAccessRelation()
Create the access relation for the underlying memory intrinsic.
isl::set getInvalidDomain() const
Get the invalid domain for this access.
ArrayRef< std::pair< BasicBlock *, Value * > > getIncoming() const
Return the list of possible PHI/ExitPHI values.
Value * getOriginalBaseAddr() const
Get the original base address of this access (e.g.
ScopStmt * getStatement() const
Get the statement that contains this memory access.
bool isLatestExitPHIKind() const
Is this MemoryAccess modeling the accesses of a PHI node in the SCoP's exit block?...
bool isAffine() const
Is the memory access affine?
isl::set getStride(isl::map Schedule) const
Get the stride of this memory access in the specified Schedule.
bool isMayWrite() const
Is this a may-write memory access?
isl::id getLatestArrayId() const
Get the base array isl::id for this access, modifiable through setNewAccessRelation().
MemoryKind Kind
What is modeled by this MemoryAccess.
bool isLatestAnyPHIKind() const
Does this access originate from one of the two PHI types? Can be changed to an array access using set...
bool isLatestValueKind() const
Is this MemoryAccess currently modeling scalar dependences?
isl::pw_multi_aff applyScheduleToAccessRelation(isl::union_map Schedule) const
Return the access relation after the schedule was applied.
SmallVector< std::pair< BasicBlock *, Value * >, 4 > Incoming
Incoming block and value of a PHINode.
isl::map getAccessRelation() const
Old name of getLatestAccessRelation().
Value * getAccessValue() const
Return the access value of this memory access.
isl::map getOriginalAccessRelation() const
Get the original access function as read from IR.
void setNewAccessRelation(isl::map NewAccessRelation)
Set the updated access relation read from JSCOP file.
bool isArrayKind() const
Old name of isOriginalArrayKind.
bool isMemoryIntrinsic() const
Is this a memory intrinsic access (memcpy, memset, memmove)?
MemoryKind getOriginalKind() const
Return the kind when this access was first detected.
const std::string getReductionOperatorStr() const
Return a string representation of the access's reduction type.
Translate a SCEV to an isl::pw_aff and the domain on which it is invalid.
bool hasNSWAddRecForLoop(llvm::Loop *L) const
Check an <nsw> AddRec for the loop L is cached.
llvm::LoopInfo * getLI() const
Return the LoopInfo used by thi object.
A class to store information about arrays in the SCoP.
const SCEV * getDimensionSize(unsigned Dim) const
Return the size of dimension dim as SCEV*.
Type * ElementType
The canonical element type of this array.
isl::space getSpace() const
Get the space of this array access.
const SmallSetVector< ScopArrayInfo *, 2 > & getDerivedSAIs() const
The set of derived indirect SAIs for this origin SAI.
SmallSetVector< ScopArrayInfo *, 2 > DerivedSAIs
For origin SAIs the set of derived indirect SAIs.
isl::id Id
The isl id for the base pointer.
SmallVector< isl::pw_aff, 4 > DimensionSizesPw
The sizes of each dimension as isl::pw_aff.
bool isExitPHIKind() const
Is this array info modeling an MemoryKind::ExitPHI?
bool isReadOnly()
If the array is read only.
bool updateSizes(ArrayRef< const SCEV * > Sizes, bool CheckConsistency=true)
Update the sizes of the ScopArrayInfo object.
~ScopArrayInfo()
Destructor to free the isl id of the base pointer.
bool isArrayKind() const
Is this array info modeling an array?
MemoryKind getKind() const
Return what kind of memory this represents.
bool isValueKind() const
Is this array info modeling an llvm::Value?
bool IsOnHeap
True if the newly allocated array is on heap.
static const ScopArrayInfo * getFromId(isl::id Id)
Access the ScopArrayInfo associated with an isl Id.
void setIsOnHeap(bool value)
std::string getName() const
Get the name of this memory reference.
bool isPHIKind() const
Is this array info modeling special PHI node memory?
Value * getBasePtr() const
Return the base pointer.
int getElemSizeInBytes() const
Get element size in bytes.
isl::pw_aff getDimensionSizePw(unsigned Dim) const
Return the size of dimension dim as isl::pw_aff.
AssertingVH< Value > BasePtr
The base pointer.
bool isCompatibleWith(const ScopArrayInfo *Array) const
Verify that Array is compatible to this ScopArrayInfo.
void addDerivedSAI(ScopArrayInfo *DerivedSAI)
bool isOnHeap() const
Is this array allocated on heap.
void updateElementType(Type *NewElementType)
Update the element type of the ScopArrayInfo object.
const ScopArrayInfo * BasePtrOriginSAI
For indirect accesses this is the SAI of the BP origin.
const DataLayout & DL
The data layout of the module.
void setBasePtr(Value *BP)
Set the base pointer to BP.
isl::id getBasePtrId() const
Return the isl id for the base pointer.
Scop & S
The scop this SAI object belongs to.
static const ScopArrayInfo * getFromAccessFunction(isl::pw_multi_aff PMA)
Access the ScopArrayInfo associated with an access function.
unsigned getNumberOfDimensions() const
Return the number of dimensions.
void print(raw_ostream &OS, bool SizeAsPwAff=false) const
Print a readable representation to OS.
Type * getElementType() const
Get the canonical element type of this array.
SmallVector< const SCEV *, 4 > DimensionSizes
The sizes of each dimension as SCEV*.
MemoryKind Kind
The type of this scop array info object.
void dump() const
Dump a readable representation to stderr.
const ScopArrayInfo * getBasePtrOriginSAI() const
For indirect accesses return the origin SAI of the BP, else null.
Build the Polly IR (Scop and ScopStmt) on a Region.
Pass to detect the maximal static control parts (Scops) of a function.
The legacy pass manager's analysis pass to compute scop information for a region.
std::unique_ptr< Scop > S
The Scop pointer which is used to construct a Scop.
void print(raw_ostream &O, const Module *M=nullptr) const override
Scop * getScop()
Build Scop object, the Polly IR of static control part for the current SESE-Region.
~ScopInfoRegionPass() override=default
void getAnalysisUsage(AnalysisUsage &AU) const override
bool runOnRegion(Region *R, RGPassManager &RGM) override
Calculate the polyhedral scop information for a given Region.
const Scop * getScop() const
void releaseMemory() override
The legacy pass manager's analysis pass to compute scop information for the whole function.
void getAnalysisUsage(AnalysisUsage &AU) const override
void print(raw_ostream &O, const Module *M=nullptr) const override
bool runOnFunction(Function &F) override
Calculate all the polyhedral scops for a given function.
const ScopInfo * getSI() const
~ScopInfoWrapperPass() override=default
std::unique_ptr< ScopInfo > Result
void releaseMemory() override
RegionToScopMapTy::const_reverse_iterator const_reverse_iterator
const_iterator end() const
RegionToScopMapTy::const_iterator const_iterator
RegionToScopMapTy::iterator iterator
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation explicitly.
ScopInfo(const DataLayout &DL, ScopDetection &SD, ScalarEvolution &SE, LoopInfo &LI, AAResults &AA, DominatorTree &DT, AssumptionCache &AC, OptimizationRemarkEmitter &ORE)
MapVector< Region *, std::unique_ptr< Scop > > RegionToScopMapTy
const_reverse_iterator rend() const
Scop * getScop(Region *R) const
Get the Scop object for the given Region.
const_iterator begin() const
const_reverse_iterator rbegin() const
reverse_iterator rbegin()
void recompute()
Recompute the Scop-Information for a function.
OptimizationRemarkEmitter & ORE
RegionToScopMapTy::reverse_iterator reverse_iterator
RegionToScopMapTy RegionToScopMap
A map of Region to its Scop object containing Polly IR of static control part.
void addAccess(MemoryAccess *Access, bool Preprend=false)
Add Access to this statement's list of accesses.
llvm::SmallVector< MemoryAccess *, 8 > MemoryAccessVec
MemoryAccess & getArrayAccessFor(const Instruction *Inst) const
Return the only array access for Inst.
BasicBlock * getEntryBlock() const
Return a BasicBlock from this statement.
void dump() const
Print the ScopStmt to stderr.
bool isEmpty() const
Return true if this statement does not contain any accesses.
std::vector< Instruction * > Instructions
Vector for Instructions in this statement.
void print(raw_ostream &OS, bool PrintInstructions) const
Print the ScopStmt.
Region * R
The region represented by this statement (in the non-affine case).
DenseMap< PHINode *, MemoryAccess * > PHIWrites
Map from PHI nodes to its incoming value when coming from this statement.
const Scop * getParent() const
std::vector< Instruction * >::const_iterator insts_end() const
isl::set Domain
The iteration domain describes the set of iterations for which this statement is executed.
const std::vector< Instruction * > & getInstructions() const
bool isBlockStmt() const
Return true if this statement represents a single basic block.
void removeSingleMemoryAccess(MemoryAccess *MA, bool AfterHoisting=true)
Remove MA from this statement.
MemoryAccess * ensureValueRead(Value *V)
Check whether there is a value read access for V in this statement, and if not, create one.
void setInstructions(ArrayRef< Instruction * > Range)
Set the list of instructions for this statement.
Loop * SurroundingLoop
The closest loop that contains this statement.
MemoryAccess * lookupInputAccessOf(Value *Val) const
Return the input access of the value, or null if no such MemoryAccess exists.
MemoryAccessVec::const_iterator const_iterator
std::string getScheduleStr() const
Get an isl string representing this schedule.
const_iterator end() const
void prependInstruction(Instruction *Inst)
Insert an instruction before all other instructions in this statement.
const ScopStmt & operator=(const ScopStmt &)=delete
std::string getDomainStr() const
Get an isl string representing this domain.
const MemoryAccessList * lookupArrayAccessesFor(const Instruction *Inst) const
Find all array accesses for Inst.
std::vector< Instruction * >::const_iterator insts_begin() const
isl::set getInvalidContext() const
Get the invalid context for this statement.
void realignParams()
Align the parameters in the statement to the scop context.
void removeAccessData(MemoryAccess *MA)
Remove MA from dictionaries pointing to them.
ScopStmt(const ScopStmt &)=delete
isl::map getSchedule() const
Get the schedule function of this ScopStmt.
isl::set getInvalidDomain() const
Get the invalid domain for this statement.
SmallVector< Loop *, 4 > NestLoops
MemoryAccessVec::iterator iterator
DenseMap< const Instruction *, MemoryAccessList > InstructionToAccess
Mapping from instructions to (scalar) memory accesses.
Scop & Parent
Polyhedral description.
void restrictDomain(isl::set NewDomain)
Restrict the domain of the statement.
isl::ctx getIslCtx() const
Get an isl_ctx pointer.
Region * getRegion() const
Get the region represented by this ScopStmt (if any).
bool represents(BasicBlock *BB) const
Return whether this statement represents BB.
DenseMap< Instruction *, MemoryAccess * > ValueWrites
The set of values defined in this ScopStmt that are required elsewhere, mapped to their MemoryKind::V...
iterator_range< std::vector< Instruction * >::const_iterator > insts() const
The range of instructions in this statement.
MemoryAccess * lookupPHIReadOf(PHINode *PHI) const
Return the MemoryAccess that loads a PHINode value, or nullptr if not existing, respectively not yet ...
BasicBlock * getBasicBlock() const
Get the BasicBlock represented by this ScopStmt (if any).
void removeMemoryAccess(MemoryAccess *MA)
Remove a MemoryAccess from this statement.
MemoryAccessVec MemAccs
The memory accesses of this statement.
const char * getBaseName() const
bool contains(const Loop *L) const
Return whether L is boxed within this statement.
bool isCopyStmt() const
Return true if this is a copy statement.
DenseMap< Value *, MemoryAccess * > ValueReads
The set of values defined elsewhere required in this ScopStmt and their MemoryKind::Value READ Memory...
isl::ast_build getAstBuild() const
Get the isl AST build.
isl::set InvalidDomain
The domain under which this statement is not modeled precisely.
DenseMap< PHINode *, MemoryAccess * > PHIReads
Map from PHI nodes to its read access in this statement.
MemoryAccess * getArrayAccessOrNULLFor(const Instruction *Inst) const
Return the only array access for Inst, if existing.
isl::id getDomainId() const
Get the id of the iteration domain space.
bool isRegionStmt() const
Return true if this statement represents a whole region.
void setInvalidDomain(isl::set ID)
Set the invalid context for this statement to ID.
unsigned getNumIterators() const
Loop * getLoopForDimension(unsigned Dimension) const
Get the loop for a dimension.
isl::set getDomain() const
Get the iteration domain of this ScopStmt.
const_iterator begin() const
void setAstBuild(isl::ast_build B)
Set the isl AST build.
MemoryAccess * lookupValueWriteOf(Instruction *Inst) const
Return the MemoryAccess that writes the value of an instruction defined in this statement,...
Loop * getSurroundingLoop() const
Return the closest innermost loop that contains this statement, but is not contained in it.
BasicBlock * BB
A SCoP statement represents either a basic block (affine/precise case) or a whole region (non-affine ...
isl::space getDomainSpace() const
Get the space of the iteration domain.
MemoryAccess * lookupPHIWriteOf(PHINode *PHI) const
Return the PHI write MemoryAccess for the incoming values from any basic block in this ScopStmt,...
void printInstructions(raw_ostream &OS) const
Print the instructions in ScopStmt.
MemoryAccess * lookupValueReadOf(Value *Inst) const
Return the MemoryAccess that reloads a value, or nullptr if not existing, respectively not yet added.
bool contains(Instruction *Inst) const
Return whether this statement contains Inst.
InvariantEquivClassTy * lookupInvariantEquivClass(Value *Val)
Return the invariant equivalence class for Val if any.
isl::schedule getScheduleTree() const
Get a schedule tree describing the schedule of all statements.
isl::set InvalidContext
The restrictions under which this SCoP was built.
bool IsOptimized
Flag to indicate that the scheduler actually optimized the SCoP.
bool HasErrorBlock
Flag to remember if the SCoP contained an error block or not.
void intersectDefinedBehavior(isl::set Set, AssumptionSign Sign)
Add the conditions from Set (or subtract them if Sign is AS_RESTRICTION) to the defined behaviour con...
isl::space getFullParamSpace() const
Return the full space of parameters.
ArrayRef< MemoryAccess * > getValueUses(const ScopArrayInfo *SAI) const
Return all MemoryAccesses that us an llvm::Value, represented by a ScopArrayInfo.
bool isParam(const SCEV *Param) const
Return whether given SCEV is used as the parameter in this Scop.
DenseMap< const ScopArrayInfo *, SmallVector< MemoryAccess *, 4 > > ValueUseAccs
List of all uses (i.e.
isl::union_map getMayWrites()
Get a union map of all may-writes performed in the SCoP.
void printContext(raw_ostream &OS) const
const MinMaxVectorPairVectorTy & getAliasGroups() const
Return all alias groups for this SCoP.
isl::set getInvalidContext() const
Get the invalid context for this Scop.
void invalidateScopArrayInfo(Value *BasePtr, MemoryKind Kind)
Invalidate ScopArrayInfo object for base address.
void dump() const
Print the ScopStmt to stderr.
isl::union_map getSchedule() const
Get the schedule of all the statements in the SCoP.
void invalidate(AssumptionKind Kind, DebugLoc Loc, BasicBlock *BB=nullptr)
Mark the scop as invalid.
MemoryAccess * getValueDef(const ScopArrayInfo *SAI) const
Return the MemoryAccess that writes an llvm::Value, represented by a ScopArrayInfo.
ScalarEvolution * getSE() const
Return the scalar evolution.
DominatorTree * getDT() const
Return the dominator tree.
unsigned getMaxLoopDepth() const
Get the maximum depth of the loop.
void printAliasAssumptions(raw_ostream &OS) const
ArrayRef< MemoryAccess * > getPHIIncomings(const ScopArrayInfo *SAI) const
Return all MemoryAccesses for all incoming statements of a PHINode, represented by a ScopArrayInfo.
bool hasInvariantAccesses()
Check if the scop has any invariant access.
ScopStmt * getStmtFor(Instruction *Inst) const
Return the ScopStmt an instruction belongs to, or nullptr if it does not belong to any statement in t...
void setDomain(BasicBlock *BB, isl::set &Domain)
Set domain for BB.
ScopArrayInfo * getScopArrayInfo(Value *BasePtr, MemoryKind Kind)
Return the cached ScopArrayInfo object for BasePtr.
ParameterSetTy Parameters
Parameters of this Scop.
bool hasDisableHeuristicsHint() const
Is this Scop marked as not to be transformed by an optimization heuristic? In this case,...
bool hasTrivialInvalidContext() const
Return true if and only if the InvalidContext is trivial (=empty).
ArrayInfoSetTy ScopArrayInfoSet
A set to remember ScopArrayInfo objects.
ValueToValueMap InvEquivClassVMap
Mapping from invariant loads to the representing invariant load of their equivalence class.
iterator_range< AccFuncVector::iterator > access_functions()
Return an iterator range containing all the MemoryAccess objects of the Scop.
isl::union_map getReads()
Get a union map of all reads performed in the SCoP.
unsigned getCopyStmtsNum()
Get the count of copy statements added to this Scop.
bool isDomainDefined(BasicBlock *BB) const
Check if domain is determined for BB.
unsigned CopyStmtsNum
Number of copy statements.
bool HasDisableHeuristicsHint
Is this Scop marked as not to be transformed by an optimization heuristic?
std::map< std::pair< AssertingVH< const Value >, MemoryKind >, std::unique_ptr< ScopArrayInfo > > ArrayInfoMapTy
DenseMap< BasicBlock *, std::vector< ScopStmt * > > StmtMap
A map from basic blocks to vector of SCoP statements.
const MapInsnToMemAcc & getInsnToMemAccMap() const
void addParams(const ParameterSetTy &NewParameters)
Take a list of parameters and add the new ones to the scop.
isl::set getAssumedContext() const
Get the assumed context for this Scop.
Scop & operator=(const Scop &)=delete
void addScopStmt(BasicBlock *BB, StringRef Name, Loop *SurroundingLoop, std::vector< Instruction * > Instructions)
Create a new SCoP statement for BB.
SCEVAffinator Affinator
The affinator used to translate SCEVs to isl expressions.
ScopArrayInfo * getOrCreateScopArrayInfo(Value *BasePtr, Type *ElementType, ArrayRef< const SCEV * > Sizes, MemoryKind Kind, const char *BaseName=nullptr)
Return the (possibly new) ScopArrayInfo object for Access.
const InvariantLoadsSetTy & getRequiredInvariantLoads() const
Return the set of required invariant loads.
void addAccessFunction(MemoryAccess *Access)
Add the access function to all MemoryAccess objects of the Scop created in this pass.
isl::schedule Schedule
The schedule of the SCoP.
isl::set getBestKnownDefinedBehaviorContext() const
Return the define behavior context, or if not available, its approximation from all other contexts.
bool contains(const Instruction *I) const
Check if I is contained in the SCoP.
SmallVector< MinMaxVectorPairTy, 4 > MinMaxVectorPairVectorTy
Vector of pair of minimal/maximal access vectors representing non read only and read only accesses fo...
isl::set Context
Constraints on parameters.
unsigned MaxLoopDepth
Max loop depth.
isl::union_set getDomains() const
Get a union set containing the iteration domains of all statements.
const BoxedLoopsSetTy & getBoxedLoops() const
Return the set of boxed (thus overapproximated) loops.
std::shared_ptr< isl_ctx > IslCtx
Isl context.
void addAliasGroup(MinMaxVectorTy &MinMaxAccessesReadWrite, MinMaxVectorTy &MinMaxAccessesReadOnly)
int getID() const
Return the ID of the Scop.
void markAsOptimized()
Mark the SCoP as optimized by the scheduler.
bool isOriginalSchedule() const
Whether the schedule is the original schedule as derived from the CFG by ScopBuilder.
ArrayInfoSetTy::iterator array_iterator
std::string getAssumedContextStr() const
Get an isl string representing the assumed context.
bool isProfitable(bool ScalarsAreUnprofitable) const
Return true if this SCoP can be profitably optimized.
array_iterator array_begin()
bool isDominatedBy(const DominatorTree &DT, BasicBlock *BB) const
Return true if and only if BB dominates the SCoP.
ScopArrayInfo * getArrayInfoByName(const std::string BaseName)
Find the ScopArrayInfo associated with an isl Id that has name Name.
void addAccessData(MemoryAccess *Access)
Add metadata for Access.
isl::set getDomainConditions(const ScopStmt *Stmt) const
Return the domain of Stmt.
void addInvariantEquivClass(const InvariantEquivClassTy &InvariantEquivClass)
Add new invariant access equivalence class.
AccFuncVector AccessFunctions
PWACtx getPwAff(const SCEV *E, BasicBlock *BB=nullptr, bool NonNegative=false, RecordedAssumptionsTy *RecordedAssumptions=nullptr)
Compute the isl representation for the SCEV E.
DenseMap< Value *, MemoryAccess * > ValueDefAccs
Map of values to the MemoryAccess that writes its definition.
isl::union_map getMustWrites()
Get a union map of all must-writes performed in the SCoP.
reverse_iterator rbegin()
std::pair< std::string, std::string > getEntryExitStr() const
Get the name of the entry and exit blocks of this Scop.
isl::pw_aff getPwAffOnly(const SCEV *E, BasicBlock *BB=nullptr, RecordedAssumptionsTy *RecordedAssumptions=nullptr)
Compute the isl representation for the SCEV E.
ScopStatistics getStatistics() const
Collect statistic about this SCoP.
std::string getContextStr() const
Get an isl string representing the context.
std::pair< MinMaxVectorTy, MinMaxVectorTy > MinMaxVectorPairTy
Pair of minimal/maximal access vectors representing read write and read only accesses.
DenseMap< BasicBlock *, isl::set > DomainMap
A map from basic blocks to their domains.
isl::union_map getAccessesOfType(std::function< bool(MemoryAccess &)> Predicate)
Collect all memory access relations of a given type.
void removeStmts(function_ref< bool(ScopStmt &)> ShouldDelete, bool AfterHoisting=true)
Remove statements from the list of scop statements.
void buildContext()
Build the Context of the Scop.
void addInvariantLoadMapping(const Value *LoadInst, Value *ClassRep)
Add mapping from invariant loads to the representing invariant load of their equivalence class.
int getRelativeLoopDepth(const Loop *L) const
Get the depth of a loop relative to the outermost loop in the Scop.
isl::ctx getIslCtx() const
Get the isl context of this static control part.
LoopInfo * getLI() const
Return the LoopInfo used for this Scop.
std::string getInvalidContextStr() const
Get an isl string representing the invalid context.
iterator_range< ArrayInfoSetTy::iterator > array_range
bool HasSingleExitEdge
True if the underlying region has a single exiting block.
DenseMap< Instruction *, ScopStmt * > InstStmtMap
A map from instructions to SCoP statements.
bool isEscaping(Instruction *Inst)
Return whether Inst has a use outside of this SCoP.
void removeStmtNotInDomainMap()
Removes all statements where the entry block of the statement does not have a corresponding domain in...
bool hasNSWAddRecForLoop(Loop *L)
Check if an <nsw> AddRec for the loop L is cached.
void updateMaxLoopDepth(unsigned Depth)
Update maximal loop depth.
ScopDetection::DetectionContext & DC
The context of the SCoP created during SCoP detection.
void print(raw_ostream &OS, bool PrintInstructions) const
Print the static control part.
const_iterator end() const
void printStatements(raw_ostream &OS, bool PrintInstructions) const
isl::union_map getWrites()
Get a union map of all writes performed in the SCoP.
void setSchedule(isl::union_map NewSchedule)
Update the current schedule.
bool hasErrorBlock() const
Return true if the SCoP contained at least one error block.
void setContext(isl::set NewContext)
Set new isl context.
bool hasFeasibleRuntimeContext() const
Return true if the optimized SCoP can be executed.
DenseMap< const SCEV *, isl::id > ParameterIds
Mapping from parameters to their ids.
isl::space getParamSpace() const
Return space of isl context parameters.
bool isExit(BasicBlock *BB) const
Return true if BB is the exit block of the SCoP.
void addRequiredInvariantLoad(LoadInst *LI)
Add LI to the set of required invariant loads.
const std::shared_ptr< isl_ctx > & getSharedIslCtx() const
Directly return the shared_ptr of the context.
SmallVector< MinMaxAccessTy, 4 > MinMaxVectorTy
Vector of minimal/maximal accesses to different arrays.
isl::set getDefinedBehaviorContext() const
Return the context where execution behavior is defined.
Region::block_range blocks() const
Return a range of all basic blocks in the SCoP.
const_iterator begin() const
isl::set & getOrInitEmptyDomain(BasicBlock *BB)
Return the domain of BB. If it does not exist, create an empty one.
StmtSet::const_reverse_iterator const_reverse_iterator
std::string getNameStr() const
Get the name of this Scop.
DenseMap< PHINode *, MemoryAccess * > PHIReadAccs
Map of values to the MemoryAccess that reads a PHI.
static void incrementNumberOfAliasingAssumptions(unsigned Step)
Increment actual number of aliasing assumptions taken.
long StmtIdx
The smallest statement index not yet assigned.
std::pair< isl::pw_multi_aff, isl::pw_multi_aff > MinMaxAccessTy
Type to represent a pair of minimal/maximal access to an array.
iterator_range< ArrayInfoSetTy::const_iterator > const_array_range
std::optional< std::string > name
The name of the SCoP (identical to the regions name)
size_t getSize() const
Return the number of statements in the SCoP.
void createParameterId(const SCEV *Param)
Create an id for Param and store it in the ParameterIds map.
const_reverse_iterator rbegin() const
BasicBlock * getEnteringBlock() const
Return the unique entering block of the SCoP if any.
ArrayNameMapTy ScopArrayNameMap
A map to remember ScopArrayInfo objects for all names of memory references.
isl::set DefinedBehaviorContext
The context under which the SCoP must have defined behavior.
iterator_range< ParameterSetTy::iterator > parameters() const
Return an iterator range containing the scop parameters.
bool isEmpty() const
Return whether this scop is empty, i.e.
DenseMap< const ScopArrayInfo *, SmallVector< MemoryAccess *, 4 > > PHIIncomingAccs
List of all incoming values (write MemoryAccess) of a MemoryKind::PHI or MemoryKind::ExitPHI scalar.
void markDisableHeuristics()
Mark this Scop to not apply an optimization heuristic.
isl::id getIdForParam(const SCEV *Parameter) const
Return the isl_id that represents a certain parameter.
iterator_range< InvariantEquivClassesTy::iterator > invariantEquivClasses()
Return an iterator range containing invariant accesses.
bool isOptimized() const
Check if the SCoP has been optimized by the scheduler.
InvariantEquivClassesTy InvariantEquivClasses
List of invariant accesses.
StmtSet::iterator iterator
BasicBlock * getExitingBlock() const
Return the unique exiting block of the SCoP if any.
Region & R
The underlying Region.
OptimizationRemarkEmitter & ORE
OptimizationRemarkEmitter object for displaying diagnostic remarks.
ArrayInfoSetTy::const_iterator const_array_iterator
bool ScheduleModified
Whether the schedule has been modified after derived from the CFG by ScopBuilder.
size_t getNumParams() const
Get the count of parameters used in this Scop.
void addParameterBounds()
Add the bounds of the parameters to the context.
bool restrictDomains(isl::union_set Domain)
Intersects the domains of all statements in the SCoP.
const_array_iterator array_begin() const
isl::union_map getAccesses()
Get a union map of all memory accesses performed in the SCoP.
ScopArrayInfo * createScopArrayInfo(Type *ElementType, const std::string &BaseName, const std::vector< unsigned > &Sizes)
Create an array and return the corresponding ScopArrayInfo object.
BasicBlock * getExit() const
Return the unique exit block of the SCoP.
long getNextStmtIdx()
Get the next free statement index.
void notifyErrorBlock()
Notify SCoP that it contains an error block.
StmtSet Stmts
The statements in this Scop.
SetVector< ScopArrayInfo * > ArrayInfoSetTy
StmtSet::reverse_iterator reverse_iterator
void removeAccessData(MemoryAccess *Access)
Remove the metadata stored for Access.
ArrayRef< ScopStmt * > getStmtListFor(BasicBlock *BB) const
Return the list of ScopStmts that represent the given BB.
MemoryAccess * getPHIRead(const ScopArrayInfo *SAI) const
Return the MemoryAccess that represents an llvm::PHINode.
bool contains(const Loop *L) const
Check if L is contained in the SCoP.
void realignParams()
Align the parameters in the statement to the scop context.
array_iterator array_end()
Function & getFunction() const
Return the function this SCoP is in.
ArrayInfoMapTy ScopArrayInfoMap
A map to remember ScopArrayInfo objects for all base pointers.
StmtSet::const_iterator const_iterator
void printArrayInfo(raw_ostream &OS) const
bool isNonAffineSubRegion(const Region *R)
Return true if and only if R is a non-affine subregion.
StringMap< std::unique_ptr< ScopArrayInfo > > ArrayNameMapTy
const SCEV * getRepresentingInvariantLoadSCEV(const SCEV *S) const
Get the representing SCEV for S if applicable, otherwise S.
long getNextArrayIdx()
Get the next free array index.
void simplifyContexts()
Simplify the assumed and invalid context.
bool hasSingleExitEdge() const
Return true if the underlying region has a single exiting block.
const_array_iterator array_end() const
ScopArrayInfo * getScopArrayInfoOrNull(Value *BasePtr, MemoryKind Kind)
Return the cached ScopArrayInfo object for BasePtr.
const_reverse_iterator rend() const
MemoryAccess * lookupBasePtrAccess(MemoryAccess *MA)
Return the access for the base ptr of MA if any.
InvariantEquivClassesTy & getInvariantAccesses()
Return the set of invariant accesses.
isl::set AssumedContext
The assumptions under which this scop was built.
Scop(const Scop &)=delete
void addAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB, bool RTC=true)
Add assumptions to assumed context.
MinMaxVectorPairVectorTy MinMaxAliasGroups
The set of minimal/maximal accesses for each alias group.
std::list< ScopStmt > StmtSet
const Region & getRegion() const
Get the maximum region of this static control part.
bool isEffectiveAssumption(isl::set Set, AssumptionSign Sign)
Check if the assumption in Set is trivial or not.
void simplifySCoP(bool AfterHoisting)
Simplify the SCoP representation.
ScopStmt * getIncomingStmtFor(const Use &U) const
Get the statement to put a PHI WRITE into.
bool trackAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB)
Track and report an assumption.
isl::set getContext() const
Get the constraint on parameter of this Scop.
long ArrayIdx
The smallest array index not yet assigned.
void setScheduleTree(isl::schedule NewSchedule)
Update the current schedule.
BasicBlock * getEntry() const
Return the unique entry block of the SCoP.
const_array_range arrays() const
const int ID
A number that uniquely represents a Scop within its function.
ScopStmt * getLastStmtFor(BasicBlock *BB) const
Return the last statement representing BB.
void removeFromStmtMap(ScopStmt &Stmt)
Removes Stmt from the StmtMap.
bool contains(const BasicBlock *BB) const
Check if BB is contained in the SCoP.
This file contains the declaration of the PolyhedralInfo class, which will provide an interface to ex...
void initializeScopInfoPrinterLegacyRegionPassPass(llvm::PassRegistry &)
void initializeScopInfoRegionPassPass(PassRegistry &)
void initializeScopInfoPrinterLegacyFunctionPassPass(PassRegistry &)
void initializeScopInfoWrapperPassPass(PassRegistry &)
std::pair< isl::pw_aff, isl::set > PWACtx
The result type of the SCEVAffinator.
unsigned const MaxDisjunctsInDomain
std::map< const Loop *, const SCEV * > LoopBoundMapType
Maps from a loop to the affine function expressing its backedge taken count.
AssumptionSign
Enum to distinguish between assumptions and restrictions.
MemoryKind
The different memory kinds used in Polly.
@ Array
MemoryKind::Array: Models a one or multi-dimensional array.
@ Value
MemoryKind::Value: Models an llvm::Value.
@ PHI
MemoryKind::PHI: Models PHI nodes within the SCoP.
@ ExitPHI
MemoryKind::ExitPHI: Models PHI nodes in the SCoP's exit block.
raw_ostream & operator<<(raw_ostream &OS, MemoryAccess::ReductionType RT)
llvm::SmallVector< Assumption, 8 > RecordedAssumptionsTy
llvm::Pass * createScopInfoPrinterLegacyRegionPass(llvm::raw_ostream &OS)
llvm::SetVector< llvm::AssertingVH< llvm::LoadInst > > InvariantLoadsSetTy
Type for a set of invariant loads.
llvm::SetVector< const llvm::Loop * > BoxedLoopsSetTy
Set of loops (used to remember loops in non-affine subregions).
llvm::SetVector< const llvm::SCEV * > ParameterSetTy
Set type for parameters.
std::map< const Instruction *, MemAcc > MapInsnToMemAcc
SmallVector< InvariantEquivClassTy, 8 > InvariantEquivClassesTy
Type for invariant accesses equivalence classes.
llvm::Pass * createScopInfoPrinterLegacyFunctionPass(llvm::raw_ostream &OS)
AssumptionKind
Enumeration of assumptions Polly can take.
SmallVector< InvariantAccess, 8 > InvariantAccessesTy
Ordered container type to hold invariant accesses.
std::forward_list< MemoryAccess * > MemoryAccessList
Ordered list type to hold accesses.
std::vector< std::unique_ptr< MemoryAccess > > AccFuncVector
Helper structure for invariant memory accesses.
MemoryAccess * MA
The memory access that is (partially) invariant.
isl::set NonHoistableCtx
The context under which the access is not invariant.
Type for equivalent invariant accesses and their domain context.
MemoryAccessList InvariantAccesses
Memory accesses now treated invariant.
Type * AccessType
The type of the invariant access.
isl::set ExecutionContext
The execution context under which the memory location is accessed.
const SCEV * IdentifyingPointer
The pointer that identifies this equivalence class.
Context variables for SCoP detection.
InvariantLoadsSetTy RequiredILS
Loads that need to be invariant during execution.
BoxedLoopsSetTy BoxedLoopsSet
The set of loops contained in non-affine regions.
MapInsnToMemAcc InsnToMemAcc
Map to memory access description for the corresponding LLVM instructions.
RegionSet NonAffineSubRegionSet
The set of non-affine subregions in the region we analyze.
Result run(Function &, FunctionAnalysisManager &)
PreservedAnalyses run(Function &, FunctionAnalysisManager &)
ScopInfoPrinterPass(raw_ostream &OS)
int NumValueWritesInLoops
int NumSingletonWritesInLoops
static TupleKindPtr Domain("Domain")
static TupleKindPtr Range("Range")