13#ifndef POLLY_SUPPORT_IRHELPER_H
14#define POLLY_SUPPORT_IRHELPER_H
16#include "llvm/ADT/SetVector.h"
17#include "llvm/IR/Instructions.h"
18#include "llvm/IR/IntrinsicInst.h"
19#include "llvm/IR/ValueHandle.h"
40using LoopToScevMapT = llvm::DenseMap<const llvm::Loop *, const llvm::SCEV *>;
105using ValueMapT = llvm::DenseMap<llvm::AssertingVH<llvm::Value>,
106 llvm::AssertingVH<llvm::Value>>;
142 llvm::Instruction *
I;
156 static bool isa(
const llvm::Value &V) {
157 return llvm::isa<llvm::LoadInst>(V) || llvm::isa<llvm::StoreInst>(V) ||
158 llvm::isa<llvm::CallInst>(V) || llvm::isa<llvm::MemIntrinsic>(V);
160 static bool isa(
const llvm::Value *V) {
161 return llvm::isa<llvm::LoadInst>(V) || llvm::isa<llvm::StoreInst>(V) ||
162 llvm::isa<llvm::CallInst>(V) || llvm::isa<llvm::MemIntrinsic>(V);
165 return MemAccInst(llvm::cast<llvm::Instruction>(V));
168 return MemAccInst(llvm::cast<llvm::Instruction>(V));
171 return MemAccInst(llvm::cast<llvm::Instruction>(V));
176 return MemAccInst(llvm::cast<llvm::Instruction>(V));
180 return MemAccInst(llvm::cast<llvm::Instruction>(V));
186 return MemAccInst(llvm::cast<llvm::Instruction>(V));
227 llvm::Instruction *
get()
const {
228 assert(
I &&
"Unexpected nullptr!");
241 return asStore()->getValueOperand();
246 llvm_unreachable(
"Operation not supported on nullptr");
250 return asLoad()->getPointerOperand();
252 return asStore()->getPointerOperand();
257 llvm_unreachable(
"Operation not supported on nullptr");
261 return asLoad()->isVolatile();
263 return asStore()->isVolatile();
268 llvm_unreachable(
"Operation not supported on nullptr");
272 return asLoad()->isSimple();
279 llvm_unreachable(
"Operation not supported on nullptr");
283 return asLoad()->getOrdering();
285 return asStore()->getOrdering();
287 return llvm::AtomicOrdering::NotAtomic;
289 return llvm::AtomicOrdering::NotAtomic;
290 llvm_unreachable(
"Operation not supported on nullptr");
294 return asLoad()->isUnordered();
296 return asStore()->isUnordered();
302 llvm_unreachable(
"Operation not supported on nullptr");
310 bool isLoad()
const {
return I && llvm::isa<llvm::LoadInst>(
I); }
311 bool isStore()
const {
return I && llvm::isa<llvm::StoreInst>(
I); }
316 return I && llvm::isa<llvm::MemTransferInst>(
I);
319 llvm::LoadInst *
asLoad()
const {
return llvm::cast<llvm::LoadInst>(
I); }
320 llvm::StoreInst *
asStore()
const {
return llvm::cast<llvm::StoreInst>(
I); }
321 llvm::CallInst *
asCallInst()
const {
return llvm::cast<llvm::CallInst>(
I); }
323 return llvm::cast<llvm::MemIntrinsic>(
I);
326 return llvm::cast<llvm::MemSetInst>(
I);
329 return llvm::cast<llvm::MemTransferInst>(
I);
337template <>
struct simplify_type<
polly::MemAccInst> {
359 llvm::LoopInfo *LI, llvm::RegionInfo *RI);
376 llvm::DominatorTree *DT, llvm::LoopInfo *LI,
377 llvm::RegionInfo *RI);
402 llvm::Function *GenFn, llvm::ScalarEvolution &GenSE,
403 const llvm::DataLayout &DL,
const char *Name,
404 const llvm::SCEV *E, llvm::Type *Ty,
449 llvm::ScalarEvolution &SE,
const llvm::DominatorTree &DT,
470 llvm::ScalarEvolution *SE, llvm::Loop *Scope);
534 llvm::StringRef Name);
542 llvm::StringRef Name);
Utility proxy to wrap the common members of LoadInst and StoreInst.
llvm::Instruction * asInstruction() const
bool isMemIntrinsic() const
MemAccInst(llvm::LoadInst *LI)
static MemAccInst cast_or_null(llvm::Value &V)
MemAccInst & operator=(llvm::MemIntrinsic *MI)
llvm::MemSetInst * asMemSetInst() const
static bool isa(const llvm::Value *V)
static MemAccInst dyn_cast(llvm::Value *V)
llvm::CallInst * asCallInst() const
MemAccInst(llvm::StoreInst *SI)
MemAccInst & operator=(llvm::CallInst *CI)
llvm::StoreInst * asStore() const
MemAccInst(llvm::MemIntrinsic *MI)
llvm::Instruction * get() const
llvm::MemTransferInst * asMemTransferInst() const
llvm::LoadInst * asLoad() const
MemAccInst & operator=(llvm::StoreInst *SI)
MemAccInst(llvm::Instruction &I)
static MemAccInst cast(llvm::Value *V)
llvm::AtomicOrdering getOrdering() const
llvm::Instruction * operator->() const
llvm::Value * getValueOperand() const
MemAccInst & operator=(llvm::CallInst &CI)
MemAccInst(const MemAccInst &Inst)
static MemAccInst dyn_cast(llvm::Value &V)
MemAccInst & operator=(llvm::LoadInst &LI)
MemAccInst(llvm::LoadInst &LI)
MemAccInst & operator=(llvm::StoreInst &SI)
bool isMemTransferInst() const
llvm::MemIntrinsic * asMemIntrinsic() const
MemAccInst & operator=(llvm::LoadInst *LI)
static MemAccInst cast(llvm::Value &V)
MemAccInst & operator=(const MemAccInst &Inst)
MemAccInst(llvm::Instruction *I)
MemAccInst & operator=(llvm::MemIntrinsic &MI)
static bool isa(const llvm::Value &V)
static MemAccInst cast_or_null(llvm::Value *V)
bool isMemSetInst() const
MemAccInst(llvm::CallInst *CI)
llvm::Value * getPointerOperand() const
bool isInstruction() const
MemAccInst(llvm::StoreInst &SI)
This file contains the declaration of the PolyhedralInfo class, which will provide an interface to ex...
llvm::Loop * getRegionNodeLoop(llvm::RegionNode *RN, llvm::LoopInfo &LI)
Return the smallest loop surrounding RN.
llvm::Value * getConditionFromTerminator(llvm::Instruction *TI)
Return the condition for the terminator TI.
bool isLoopAttr(const isl::id &Id)
Is Id representing a loop?
std::optional< llvm::Metadata * > findMetadataOperand(llvm::MDNode *LoopMD, llvm::StringRef Name)
Find a property value in a LoopID.
unsigned getNumBlocksInRegionNode(llvm::RegionNode *RN)
Get the number of blocks in RN.
llvm::Loop * getFirstNonBoxedLoopFor(llvm::Loop *L, llvm::LoopInfo &LI, const BoxedLoopsSetTy &BoxedLoops)
AssumptionSign
Enum to distinguish between assumptions and restrictions.
bool hasDisableAllTransformsHint(llvm::Loop *L)
Does the loop's LoopID contain a 'llvm.loop.disable_heuristics' property?
std::optional< int > getOptionalIntLoopAttribute(llvm::MDNode *LoopID, llvm::StringRef Name)
Find an integers property value in a LoopID.
llvm::SmallVector< Assumption, 8 > RecordedAssumptionsTy
bool isDebugCall(llvm::Instruction *Inst)
Is the given instruction a call to a debug function?
bool hasDebugCall(ScopStmt *Stmt)
Does the statement contain a call to a debug function?
BandAttr * getLoopAttr(const isl::id &Id)
Return the BandAttr of a loop's isl::id.
llvm::BasicBlock * getUseBlock(const llvm::Use &U)
Return the block in which a value is used.
llvm::Value * expandCodeFor(Scop &S, llvm::ScalarEvolution &SE, llvm::Function *GenFn, llvm::ScalarEvolution &GenSE, const llvm::DataLayout &DL, const char *Name, const llvm::SCEV *E, llvm::Type *Ty, llvm::Instruction *IP, ValueMapT *VMap, LoopToScevMapT *LoopMap, llvm::BasicBlock *RTCBB)
Wrapper for SCEVExpander extended to all Polly features.
llvm::Loop * getLoopSurroundingScop(Scop &S, llvm::LoopInfo &LI)
Get the smallest loop that contains S but is not in S.
llvm::SetVector< llvm::AssertingVH< llvm::LoadInst > > InvariantLoadsSetTy
Type for a set of invariant loads.
void recordAssumption(RecordedAssumptionsTy *RecordedAssumptions, AssumptionKind Kind, isl::set Set, llvm::DebugLoc Loc, AssumptionSign Sign, llvm::BasicBlock *BB=nullptr, bool RTC=true)
Record an assumption for later addition to the assumed context.
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.
isl::id getIslLoopAttr(isl::ctx Ctx, BandAttr *Attr)
Get an isl::id representing a loop.
bool isHoistableLoad(llvm::LoadInst *LInst, llvm::Region &R, llvm::LoopInfo &LI, llvm::ScalarEvolution &SE, const llvm::DominatorTree &DT, const InvariantLoadsSetTy &KnownInvariantLoads)
Check if LInst can be hoisted in R.
void splitEntryBlockForAlloca(llvm::BasicBlock *EntryBlock, llvm::Pass *P)
Split the entry block of a function to store the newly inserted allocations outside of all Scops.
isl::id createIslLoopAttr(isl::ctx Ctx, llvm::Loop *L)
Create an isl::id that identifies an original loop.
llvm::DenseMap< llvm::AssertingVH< llvm::Value >, llvm::AssertingVH< llvm::Value > > ValueMapT
Type to remap values.
AssumptionKind
Enumeration of assumptions Polly can take.
llvm::DenseMap< const llvm::Loop *, const llvm::SCEV * > LoopToScevMapT
Same as llvm/Analysis/ScalarEvolutionExpressions.h.
bool isIgnoredIntrinsic(const llvm::Value *V)
Return true iff V is an intrinsic that we ignore during code generation.
void simplifyRegion(llvm::Region *R, llvm::DominatorTree *DT, llvm::LoopInfo *LI, llvm::RegionInfo *RI)
Simplify the region to have a single unconditional entry edge and a single exit edge.
bool canSynthesize(const llvm::Value *V, const Scop &S, llvm::ScalarEvolution *SE, llvm::Loop *Scope)
Check whether a value an be synthesized by the code generator.
bool getBooleanLoopAttribute(llvm::MDNode *LoopID, llvm::StringRef Name)
Find a boolean property value in a LoopID.
unsigned getNumBlocksInLoop(llvm::Loop *L)
Get the number of blocks in L.
static SimpleType getSimplifiedValue(polly::MemAccInst &I)
Helper struct to remember assumptions.
llvm::DebugLoc Loc
The location that caused this assumption.
AssumptionKind Kind
The kind of the assumption (e.g., WRAPPING).
llvm::BasicBlock * BB
An optional block whose domain can simplify the assumption.
AssumptionSign Sign
Flag to distinguish assumptions and restrictions.
isl::set Set
The valid/invalid context if this is an assumption/restriction.
Represent the attributes of a loop.
llvm::MDNode * Metadata
LoopID which stores the properties of the loop, such as transformations to apply and the metadata of ...
llvm::Loop * OriginalLoop
The LoopInfo reference for this loop.