LLVM 20.0.0git
|
This class emits a version of the loop where run-time checks ensure that may-alias pointers can't overlap. More...
#include "llvm/Transforms/Utils/LoopVersioning.h"
Public Member Functions | |
LoopVersioning (const LoopAccessInfo &LAI, ArrayRef< RuntimePointerCheck > Checks, Loop *L, LoopInfo *LI, DominatorTree *DT, ScalarEvolution *SE) | |
Expects LoopAccessInfo, Loop, LoopInfo, DominatorTree as input. | |
void | versionLoop () |
Performs the CFG manipulation part of versioning the loop including the DominatorTree and LoopInfo updates. | |
void | versionLoop (const SmallVectorImpl< Instruction * > &DefsUsedOutside) |
Same but if the client has already precomputed the set of values used outside the loop, this API will allows passing that. | |
Loop * | getVersionedLoop () |
Returns the versioned loop. | |
Loop * | getNonVersionedLoop () |
Returns the fall-back loop. | |
void | annotateLoopWithNoAlias () |
Annotate memory instructions in the versioned loop with no-alias metadata based on the memchecks issued. | |
void | prepareNoAliasMetadata () |
Set up the aliasing scopes based on the memchecks. | |
void | annotateInstWithNoAlias (Instruction *VersionedInst, const Instruction *OrigInst) |
Add the noalias annotations to VersionedInst . | |
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.
Definition at line 41 of file LoopVersioning.h.
LoopVersioning::LoopVersioning | ( | const LoopAccessInfo & | LAI, |
ArrayRef< RuntimePointerCheck > | Checks, | ||
Loop * | L, | ||
LoopInfo * | LI, | ||
DominatorTree * | DT, | ||
ScalarEvolution * | SE | ||
) |
Expects LoopAccessInfo, Loop, LoopInfo, DominatorTree as input.
It uses runtime check provided by the user. If 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.
Definition at line 42 of file LoopVersioning.cpp.
void LoopVersioning::annotateInstWithNoAlias | ( | Instruction * | VersionedInst, |
const Instruction * | OrigInst | ||
) |
Add the noalias annotations to VersionedInst
.
OrigInst
is the instruction corresponding to VersionedInst
in the original loop. Initialize the aliasing scopes with prepareNoAliasMetadata once before this can be called.
Definition at line 228 of file LoopVersioning.cpp.
References AnnotateNoAlias, llvm::MDNode::concatenate(), llvm::MDNode::get(), llvm::BasicBlock::getContext(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::Instruction::getMetadata(), Ptr, and llvm::Instruction::setMetadata().
Referenced by llvm::VPTransformState::addNewMetadata(), and annotateLoopWithNoAlias().
void LoopVersioning::annotateLoopWithNoAlias | ( | ) |
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.
Definition at line 215 of file LoopVersioning.cpp.
References annotateInstWithNoAlias(), AnnotateNoAlias, llvm::LoopAccessInfo::getDepChecker(), llvm::MemoryDepChecker::getMemoryInstructions(), I, and prepareNoAliasMetadata().
|
inline |
Returns the fall-back loop.
Control flows here if pointers in the loop may alias (i.e. one of the memchecks failed).
Definition at line 77 of file LoopVersioning.h.
|
inline |
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.)
Definition at line 73 of file LoopVersioning.h.
void LoopVersioning::prepareNoAliasMetadata | ( | ) |
Set up the aliasing scopes based on the memchecks.
This needs to be called before the first call to annotateInstWithNoAlias.
Definition at line 174 of file LoopVersioning.cpp.
References Check, llvm::RuntimePointerChecking::CheckingGroups, llvm::MDBuilder::createAnonymousAliasScope(), llvm::MDBuilder::createAnonymousAliasScopeDomain(), llvm::MDNode::get(), llvm::BasicBlock::getContext(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::RuntimePointerChecking::getPointerInfo(), llvm::LoopAccessInfo::getRuntimePointerChecking(), and llvm::RuntimePointerChecking::PointerInfo::PointerValue.
Referenced by annotateLoopWithNoAlias(), and llvm::LoopVectorizationPlanner::executePlan().
|
inline |
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
Definition at line 64 of file LoopVersioning.h.
References llvm::findDefsUsedOutsideOfLoop(), and versionLoop().
Referenced by FlattenLoopPair(), and versionLoop().
void LoopVersioning::versionLoop | ( | const SmallVectorImpl< Instruction * > & | DefsUsedOutside | ) |
Same but if the client has already precomputed the set of values used outside the loop, this API will allows passing that.
Definition at line 49 of file LoopVersioning.cpp.
References llvm::addRuntimeChecks(), assert(), llvm::DominatorTreeBase< NodeT, IsPostDom >::changeImmediateDominator(), llvm::cloneLoopWithPreheader(), llvm::IRBuilderBase::CreateCondBr(), llvm::IRBuilderBase::CreateOr(), llvm::Instruction::eraseFromParent(), llvm::formDedicatedExitBlocks(), llvm::BasicBlock::getContext(), llvm::BasicBlock::getDataLayout(), llvm::LoopBase< BlockT, LoopT >::getExitBlock(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::LoopBase< BlockT, LoopT >::getLoopPreheader(), llvm::Value::getName(), llvm::LoopAccessInfo::getRuntimePointerChecking(), llvm::BasicBlock::getTerminator(), llvm::LoopBase< BlockT, LoopT >::getUniqueExitBlock(), llvm::Loop::isLoopSimplifyForm(), llvm::remapInstructionsInBlocks(), llvm::IRBuilderBase::SetInsertPoint(), llvm::Value::setName(), and llvm::SplitBlock().