17#include "llvm/ADT/SmallVector.h"
18#include "llvm/IR/Metadata.h"
32static MDNode *
getID(LLVMContext &
Ctx, Metadata *arg0 =
nullptr,
33 Metadata *
arg1 =
nullptr) {
35 SmallVector<Metadata *, 3> Args;
37 Args.push_back(
nullptr);
44 ID = MDNode::getDistinct(
Ctx, Args);
45 ID->replaceOperandWith(0, ID);
62 LLVMContext &
Ctx =
SE->getContext();
70 SmallVector<ScopArrayInfo *, 10> Arrays;
72 if (
Array->isArrayKind())
73 Arrays.push_back(
Array);
81 std::string AliasScopeStr =
"polly.alias.scope.";
83 assert(
Array->getBasePtr() &&
"Base pointer must be present");
86 MDString::get(
Ctx, (AliasScopeStr +
Array->getName()).c_str()));
90 MDNode *AliasScopeList = MDNode::get(
Ctx, {});
92 if (
Array->getBasePtr() == AliasScopePair.first)
95 Metadata *Args = {AliasScopePair.second};
97 MDNode::concatenate(AliasScopeList, MDNode::get(
Ctx, Args));
108 LLVMContext &
Ctx =
SE->getContext();
109 MDNode *AccessGroup = MDNode::getDistinct(
Ctx, {});
133 LLVMContext &
Ctx =
SE->getContext();
134 SmallVector<Metadata *, 3> Args;
137 Args.push_back(
nullptr);
142 MDNode *MData =
nullptr;
144 MData = AttrEnv->Metadata;
146 llvm::append_range(Args, drop_begin(MData->operands(), 1));
150 MDString *PropName = MDString::get(
Ctx,
"llvm.loop.vectorize.enable");
151 ConstantInt *FalseValue = ConstantInt::get(Type::getInt1Ty(
Ctx), 0);
152 ValueAsMetadata *PropValue = ValueAsMetadata::get(FalseValue);
153 Args.push_back(MDNode::get(
Ctx, {PropName, PropValue}));
157 MDString *PropName = MDString::get(
Ctx,
"llvm.loop.parallel_accesses");
159 Args.push_back(MDNode::get(
Ctx, {PropName, AccGroup}));
163 if (!MData && Args.size() <= 1)
169 if (!MData || Args.size() > MData->getNumOperands()) {
170 MData = MDNode::getDistinct(
Ctx, Args);
171 MData->replaceOperandWith(0, MData);
173 B->setMetadata(LLVMContext::MD_loop, MData);
186 return MemInst.getPointerOperand();
196 if (
auto *Gep = dyn_cast<GEPOperator>(Val)) {
197 Val = Gep->getPointerOperand();
200 if (
auto *Cast = dyn_cast<BitCastOperator>(Val)) {
201 Val = Cast->getOperand(0);
212 if (!Inst->mayReadOrWriteMemory())
221 Inst->setMetadata(LLVMContext::MD_access_group,
226 Inst->setMetadata(LLVMContext::MD_access_group,
227 MDNode::get(
SE->getContext(),
228 ArrayRef<Metadata *>(
241 if (isa<CallInst>(Inst) && !isa<MemSetInst>(Inst))
265 "BasePtr either expected in AliasScopeMap and OtherAlias...Map");
268 Inst->setMetadata(
"alias.scope", MDNode::get(
SE->getContext(), AliasScope));
269 Inst->setMetadata(
"noalias", OtherAliasScopeList);
static MDNode * getID(LLVMContext &Ctx, Metadata *arg0=nullptr, Metadata *arg1=nullptr)
Get a self referencing id metadata node.
static Value * findBasePtr(Value *Val)
Find the base pointer of an array access.
static llvm::Value * getMemAccInstPointerOperand(Instruction *Inst)
Get the pointer operand.
static const int MaxArraysInAliasScops
static bool IsLoopVectorizerDisabled(isl::ast_node_for Node)
Restore the initial ordering of dimensions of the band node.
static MemAccInst dyn_cast(llvm::Value &V)
llvm::SmallVector< BandAttr *, 8 > LoopAttrEnv
Stack for surrounding BandAttr annotations.
llvm::SmallVector< llvm::MDNode *, 8 > ParallelLoops
Access groups for the parallel loops currently under construction.
llvm::DenseMap< llvm::AssertingVH< llvm::Value >, llvm::MDNode * > OtherAliasScopeListMap
A map from base pointers to an alias scope list of other pointers.
BandAttr *& getStagingAttrEnv()
void buildAliasScopes(Scop &S)
Build all alias scopes for the given SCoP.
void annotate(llvm::Instruction *I)
Annotate the new instruction I for all parallel loops.
llvm::MapVector< llvm::AssertingVH< llvm::Value >, llvm::MDNode * > AliasScopeMap
A map from base pointers to its alias scope.
llvm::ScalarEvolution * SE
The ScalarEvolution analysis we use to find base pointers.
void annotateLoopLatch(llvm::BranchInst *B, llvm::Loop *L, bool IsParallel, bool IsLoopVectorizerDisabled) const
Annotate the loop latch B wrt. L.
llvm::DenseMap< llvm::AssertingVH< llvm::Value >, llvm::AssertingVH< llvm::Value > > AlternativeAliasBases
void pushLoop(llvm::Loop *L, bool IsParallel)
Add a new loop L which is parallel if IsParallel is true.
llvm::SmallVector< llvm::Loop *, 8 > ActiveLoops
All loops currently under construction.
void popLoop(bool isParallel)
Remove the last added loop.
BandAttr * getActiveAttrEnv() const
llvm::MDNode * AliasScopeDomain
The alias scope domain for the current SCoP.
A class to store information about arrays in the SCoP.
This file contains the declaration of the PolyhedralInfo class, which will provide an interface to ex...
@ Array
MemoryKind::Array: Models a one or multi-dimensional array.
@ Value
MemoryKind::Value: Models an llvm::Value.
Represent the attributes of a loop.