30 cl::desc(
"Add no-alias annotation for instructions that " 31 "are disambiguated by memchecks"));
36 : VersionedLoop(L), NonVersionedLoop(nullptr), LAI(LAI), LI(LI), DT(DT),
48 AliasChecks = std::move(Checks);
52 Preds = std::move(Check);
59 Value *SCEVRuntimeCheck;
60 Value *RuntimeCheck =
nullptr;
64 std::tie(FirstCheckInst, MemRuntimeCheck) =
71 Exp.expandCodeForPredicate(&Pred, RuntimeCheckBB->
getTerminator());
75 if (CI && CI->isZero())
76 SCEVRuntimeCheck =
nullptr;
78 if (MemRuntimeCheck && SCEVRuntimeCheck) {
80 SCEVRuntimeCheck,
"lver.safe");
81 if (
auto *
I = dyn_cast<Instruction>(RuntimeCheck))
84 RuntimeCheck = MemRuntimeCheck ? MemRuntimeCheck : SCEVRuntimeCheck;
86 assert(RuntimeCheck &&
"called even though we don't need " 87 "any runtime checks");
106 ".lver.orig", LI, DT, NonVersionedLoopBlocks);
121 addPHINodes(DefsUsedOutside);
124 void LoopVersioning::addPHINodes(
127 assert(PHIBlock &&
"No single successor to loop exit block");
132 for (
auto *Inst : DefsUsedOutside) {
145 if (!VersionedLoop->
contains(cast<Instruction>(U)->getParent()))
147 for (
User *U : UsersToUpdate)
148 U->replaceUsesOfWith(Inst, PN);
156 "Exit block should only have on predecessor");
160 auto Mapped = VMap.
find(ClonedValue);
161 if (Mapped != VMap.
end())
162 ClonedValue = Mapped->
second;
190 for (
unsigned PtrIdx : Group.Members)
198 GroupToNonAliasingScopes;
200 for (
const auto &
Check : AliasChecks)
206 for (
auto Pair : GroupToNonAliasingScopes)
207 GroupToNonAliasingScopeList[Pair.first] =
MDNode::get(Context, Pair.second);
229 const Value *Ptr = isa<LoadInst>(OrigInst)
230 ? cast<LoadInst>(OrigInst)->getPointerOperand()
234 auto Group = PtrToGroup.find(Ptr);
235 if (Group != PtrToGroup.end()) {
240 MDNode::get(Context, GroupToScope[Group->second])));
243 auto NonAliasingScopeList = GroupToNonAliasingScopeList.find(Group->second);
244 if (NonAliasingScopeList != GroupToNonAliasingScopeList.end())
249 NonAliasingScopeList->second));
264 auto *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
265 auto *LAA = &getAnalysis<LoopAccessLegacyAnalysis>();
266 auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
267 auto *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
274 for (
Loop *TopLevelLoop : *LI)
281 bool Changed =
false;
282 for (
Loop *L : Worklist) {
309 #define LVER_OPTION "loop-versioning" 310 #define DEBUG_TYPE LVER_OPTION 324 return new LoopVersioningPass();
static bool Check(DecodeStatus &Out, DecodeStatus In)
TrackingVH< Value > PointerValue
Holds the pointer value that we need to check.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
SmallVector< CheckingPtrGroup, 2 > CheckingGroups
Holds a partitioning of pointers into "check groups".
const MemoryDepChecker & getDepChecker() const
the Memory Dependence Checker which can determine the loop-independent and loop-carried dependences b...
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Value * getPointerOperand(Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
This class represents lattice values for constants.
MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())
Return metadata appropriate for an alias scope root node.
void push_back(const T &Elt)
const RuntimePointerChecking * getRuntimePointerChecking() const
The main scalar evolution driver.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
LLVMContext & getContext() const
Get the context in which this basic block lives.
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
#define INITIALIZE_PASS_DEPENDENCY(depName)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
unsigned getNumRuntimePointerChecks() const
Number of memchecks required to prove independence of otherwise may-alias pointers.
void setName(const Twine &Name)
Change the name of the value.
static cl::opt< bool > AnnotateNoAlias("loop-version-annotate-no-alias", cl::init(true), cl::Hidden, cl::desc("Add no-alias annotation for instructions that " "are disambiguated by memchecks"))
BlockT * getHeader() const
static const char LVer_name[]
const SmallVectorImpl< Instruction * > & getMemoryInstructions() const
The vector of memory access instructions.
iterator find(const KeyT &Val)
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void versionLoop()
Performs the CFG manipulation part of versioning the loop including the DominatorTree and LoopInfo up...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
std::pair< Instruction *, Instruction * > addRuntimeChecks(Instruction *Loc) const
Add code that checks at runtime if the accessed arrays overlap.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
This analysis provides dependence information for the memory accesses of a loop.
const Instruction & front() const
Represent the analysis usage information of a pass.
void annotateLoopWithNoAlias()
Annotate memory instructions in the versioned loop with no-alias metadata based on the memchecks issu...
FunctionPass class - This class is used to implement most global optimizations.
const PredicatedScalarEvolution & getPSE() const
Used to add runtime SCEV checks.
BlockT * getExitBlock() const
If getExitBlocks would return exactly one block, return that block.
void setAliasChecks(SmallVector< RuntimePointerChecking::PointerCheck, 4 > Checks)
Sets the runtime alias checks for versioning the loop.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
void setSCEVChecks(SCEVUnionPredicate Check)
Sets the runtime SCEV checks for versioning the loop.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
MDNode * createAnonymousAliasScopeDomain(StringRef Name=StringRef())
Return metadata appropriate for an alias scope domain node.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
unsigned getNumOperands() const
FunctionPass * createLoopVersioningPass()
This is the shared class of boolean and integer constants.
bool isAlwaysTrue() const override
Implementation of the SCEVPredicate interface.
const SCEVUnionPredicate & getUnionPredicate() const
const PointerInfo & getPointerInfo(unsigned PtrIdx) const
Return PointerInfo for pointer at index PtrIdx.
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Drive the analysis of memory accesses in the loop.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
This class emits a version of the loop where run-time checks ensure that may-alias pointers can't ove...
void annotateInstWithNoAlias(Instruction *VersionedInst, const Instruction *OrigInst)
Add the noalias annotations to VersionedInst.
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
iterator_range< user_iterator > users()
This class uses information about analyze scalars to rewrite expressions in canonical form...
Holds information about the memory runtime legality checks to verify that a group of pointers do not ...
bool isLoopSimplifyForm() const
Return true if the Loop is in the form that the LoopSimplify form transforms loops to...
void initializeLoopVersioningPassPass(PassRegistry &)
void prepareNoAliasMetadata()
Set up the aliasing scopes based on the memchecks.
Represents a single loop in the control flow graph.
StringRef getName() const
Return a constant reference to the value's name.
static MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
iterator_range< df_iterator< T > > depth_first(const T &G)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents a composition of other SCEV predicates, and is the class that most clients will...
LLVM Value Representation.
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Split the specified block at the specified instruction - everything before SplitPt stays in Old and e...
Loop * cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB, Loop *OrigLoop, ValueToValueMapTy &VMap, const Twine &NameSuffix, LoopInfo *LI, DominatorTree *DT, SmallVectorImpl< BasicBlock *> &Blocks)
Clones a loop OrigLoop.
The legacy pass manager's analysis pass to compute loop information.
Legacy analysis pass which computes a DominatorTree.
const SmallVector< PointerCheck, 4 > & getChecks() const
Returns the checks that generateChecks created.
BlockT * getExitingBlock() const
If getExitingBlocks would return exactly one block, return that block.
LoopVersioning(const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI, DominatorTree *DT, ScalarEvolution *SE, bool UseLAIChecks=true)
Expects LoopAccessInfo, Loop, LoopInfo, DominatorTree as input.
void remapInstructionsInBlocks(const SmallVectorImpl< BasicBlock *> &Blocks, ValueToValueMapTy &VMap)
Remaps instructions in Blocks using the mapping in VMap.