class LoopVersioning
Declaration
class LoopVersioning { /* full declaration omitted */ };
Description
This class emits a version of the loop where run-time checks ensure that may-alias pointers can't overlap. It currently only supports single-exit loops and assumes that the loop already has a preheader.
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:41
Member Variables
- private llvm::Loop* VersionedLoop
- The original loop. This becomes the "versioned" one. I.e., control flows here if pointers in the loop don't alias.
- private llvm::Loop* NonVersionedLoop = nullptr
- The fall-back loop. I.e. control flows here if pointers in the loop may alias (memchecks failed).
- private llvm::ValueToValueMapTy VMap
- This maps the instructions from VersionedLoop to their counterpart in NonVersionedLoop.
- private SmallVector<llvm::RuntimePointerCheck, 4> AliasChecks
- The set of alias checks that we are versioning for.
- private const llvm::SCEVPredicate& Preds
- The set of SCEV checks that we are versioning for.
- private DenseMap<const llvm::Value*, const llvm::RuntimeCheckingPtrGroup*> PtrToGroup
- Maps a pointer to the pointer checking group that the pointer belongs to.
- private DenseMap<const llvm::RuntimeCheckingPtrGroup*, llvm::MDNode*> GroupToScope
- The alias scope corresponding to a pointer checking group.
- private DenseMap<const llvm::RuntimeCheckingPtrGroup*, llvm::MDNode*> GroupToNonAliasingScopeList
- The list of alias scopes that a pointer checking group can't alias.
- private const llvm::LoopAccessInfo& LAI
- Analyses used.
- private llvm::LoopInfo* LI
- private llvm::DominatorTree* DT
- private llvm::ScalarEvolution* SE
Method Overview
- public LoopVersioning(const llvm::LoopAccessInfo & LAI, ArrayRef<llvm::RuntimePointerCheck> Checks, llvm::Loop * L, llvm::LoopInfo * LI, llvm::DominatorTree * DT, llvm::ScalarEvolution * SE)
- private void addPHINodes(const SmallVectorImpl<llvm::Instruction *> & DefsUsedOutside)
- public void annotateInstWithNoAlias(llvm::Instruction * VersionedInst, const llvm::Instruction * OrigInst)
- private void annotateInstWithNoAlias(llvm::Instruction * I)
- public void annotateLoopWithNoAlias()
- public llvm::Loop * getNonVersionedLoop()
- public llvm::Loop * getVersionedLoop()
- public void prepareNoAliasMetadata()
- public void versionLoop()
- public void versionLoop(const SmallVectorImpl<llvm::Instruction *> & DefsUsedOutside)
Methods
¶LoopVersioning(
const llvm::LoopAccessInfo& LAI,
ArrayRef<llvm::RuntimePointerCheck> Checks,
llvm::Loop* L,
llvm::LoopInfo* LI,
llvm::DominatorTree* DT,
llvm::ScalarEvolution* SE)
LoopVersioning(
const llvm::LoopAccessInfo& LAI,
ArrayRef<llvm::RuntimePointerCheck> Checks,
llvm::Loop* L,
llvm::LoopInfo* LI,
llvm::DominatorTree* DT,
llvm::ScalarEvolution* SE)
Description
Expects LoopAccessInfo, Loop, LoopInfo, DominatorTree as input. It uses runtime check provided by the user. If \p UseLAIChecks is true, we will retain the default checks made by LAI. Otherwise, construct an object having no checks and we expect the user to add them.
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:47
Parameters
- const llvm::LoopAccessInfo& LAI
- ArrayRef<llvm::RuntimePointerCheck> Checks
- llvm::Loop* L
- llvm::LoopInfo* LI
- llvm::DominatorTree* DT
- llvm::ScalarEvolution* SE
¶void addPHINodes(
const SmallVectorImpl<llvm::Instruction*>&
DefsUsedOutside)
void addPHINodes(
const SmallVectorImpl<llvm::Instruction*>&
DefsUsedOutside)
Description
Adds the necessary PHI nodes for the versioned loops based on the loop-defined values used outside of the loop. This needs to be called after versionLoop if there are defs in the loop that are used outside the loop.
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:104
Parameters
- const SmallVectorImpl<llvm::Instruction*>& DefsUsedOutside
¶void annotateInstWithNoAlias(
llvm::Instruction* VersionedInst,
const llvm::Instruction* OrigInst)
void annotateInstWithNoAlias(
llvm::Instruction* VersionedInst,
const llvm::Instruction* OrigInst)
Description
Add the noalias annotations to \p VersionedInst. \p OrigInst is the instruction corresponding to \p VersionedInst in the original loop. Initialize the aliasing scopes with prepareNoAliasMetadata once before this can be called.
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:95
Parameters
- llvm::Instruction* VersionedInst
- const llvm::Instruction* OrigInst
¶void annotateInstWithNoAlias(llvm::Instruction* I)
void annotateInstWithNoAlias(llvm::Instruction* I)
Description
Add the noalias annotations to \p I. Initialize the aliasing scopes with prepareNoAliasMetadata once before this can be called.
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:108
Parameters
¶void annotateLoopWithNoAlias()
void annotateLoopWithNoAlias()
Description
Annotate memory instructions in the versioned loop with no-alias metadata based on the memchecks issued. This is just wrapper that calls prepareNoAliasMetadata and annotateInstWithNoAlias on the instructions of the versioned loop.
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:84
¶llvm::Loop* getNonVersionedLoop()
llvm::Loop* getNonVersionedLoop()
Description
Returns the fall-back loop. Control flows here if pointers in the loop may alias (i.e. one of the memchecks failed).
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:77
¶llvm::Loop* getVersionedLoop()
llvm::Loop* getVersionedLoop()
Description
Returns the versioned loop. Control flows here if pointers in the loop don't alias (i.e. all memchecks passed). (This loop is actually the same as the original loop that we got constructed with.)
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:73
¶void prepareNoAliasMetadata()
void prepareNoAliasMetadata()
Description
Set up the aliasing scopes based on the memchecks. This needs to be called before the first call to annotateInstWithNoAlias.
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:88
¶void versionLoop()
void versionLoop()
Description
Performs the CFG manipulation part of versioning the loop including the DominatorTree and LoopInfo updates. The loop that was used to construct the class will be the "versioned" loop i.e. the loop that will receive control if all the memchecks pass. This allows the loop transform pass to operate on the same loop regardless of whether versioning was necessary or not: for each loop L: analyze L if versioning is necessary version L transform L
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:64
¶void versionLoop(
const SmallVectorImpl<llvm::Instruction*>&
DefsUsedOutside)
void versionLoop(
const SmallVectorImpl<llvm::Instruction*>&
DefsUsedOutside)
Description
Same but if the client has already precomputed the set of values used outside the loop, this API will allows passing that.
Declared at: llvm/include/llvm/Transforms/Utils/LoopVersioning.h:68
Parameters
- const SmallVectorImpl<llvm::Instruction*>& DefsUsedOutside