LLVM
8.0.1
|
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, Loop *L, LoopInfo *LI, DominatorTree *DT, ScalarEvolution *SE, bool UseLAIChecks=true) | |
Expects LoopAccessInfo, Loop, LoopInfo, DominatorTree as input. More... | |
void | versionLoop () |
Performs the CFG manipulation part of versioning the loop including the DominatorTree and LoopInfo updates. More... | |
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. More... | |
Loop * | getVersionedLoop () |
Returns the versioned loop. More... | |
Loop * | getNonVersionedLoop () |
Returns the fall-back loop. More... | |
void | setAliasChecks (SmallVector< RuntimePointerChecking::PointerCheck, 4 > Checks) |
Sets the runtime alias checks for versioning the loop. More... | |
void | setSCEVChecks (SCEVUnionPredicate Check) |
Sets the runtime SCEV checks for versioning the loop. More... | |
void | annotateLoopWithNoAlias () |
Annotate memory instructions in the versioned loop with no-alias metadata based on the memchecks issued. More... | |
void | prepareNoAliasMetadata () |
Set up the aliasing scopes based on the memchecks. More... | |
void | annotateInstWithNoAlias (Instruction *VersionedInst, const Instruction *OrigInst) |
Add the noalias annotations to VersionedInst . More... | |
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 36 of file LoopVersioning.h.
LoopVersioning::LoopVersioning | ( | const LoopAccessInfo & | LAI, |
Loop * | L, | ||
LoopInfo * | LI, | ||
DominatorTree * | DT, | ||
ScalarEvolution * | SE, | ||
bool | UseLAIChecks = true |
||
) |
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 33 of file LoopVersioning.cpp.
References assert(), llvm::RuntimePointerChecking::getChecks(), llvm::LoopBase< BlockT, LoopT >::getExitBlock(), llvm::LoopAccessInfo::getPSE(), llvm::LoopAccessInfo::getRuntimePointerChecking(), llvm::PredicatedScalarEvolution::getUnionPredicate(), llvm::Loop::isLoopSimplifyForm(), setAliasChecks(), and setSCEVChecks().
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 223 of file LoopVersioning.cpp.
References llvm::AnalysisUsage::addPreserved(), llvm::AnalysisUsage::addRequired(), annotateLoopWithNoAlias(), AnnotateNoAlias, llvm::MDNode::concatenate(), Context, llvm::depth_first(), F(), llvm::MDNode::get(), llvm::BasicBlock::getContext(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::Instruction::getMetadata(), llvm::LoopAccessInfo::getNumRuntimePointerChecks(), llvm::PassRegistry::getPassRegistry(), llvm::getPointerOperand(), llvm::LoopAccessInfo::getPSE(), llvm::PredicatedScalarEvolution::getUnionPredicate(), llvm::initializeLoopVersioningPassPass(), llvm::SCEVUnionPredicate::isAlwaysTrue(), llvm::LLVMContext::MD_alias_scope, llvm::LLVMContext::MD_noalias, llvm::SmallVectorTemplateBase< T >::push_back(), runOnFunction(), llvm::Instruction::setMetadata(), and versionLoop().
Referenced by annotateLoopWithNoAlias(), and getNonVersionedLoop().
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 210 of file LoopVersioning.cpp.
References annotateInstWithNoAlias(), AnnotateNoAlias, llvm::LoopAccessInfo::getDepChecker(), llvm::MemoryDepChecker::getMemoryInstructions(), I, and prepareNoAliasMetadata().
Referenced by annotateInstWithNoAlias(), and getNonVersionedLoop().
|
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 72 of file LoopVersioning.h.
References annotateInstWithNoAlias(), annotateLoopWithNoAlias(), Check(), I, prepareNoAliasMetadata(), setAliasChecks(), and setSCEVChecks().
|
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 68 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 168 of file LoopVersioning.cpp.
References Check(), llvm::RuntimePointerChecking::CheckingGroups, Context, llvm::MDBuilder::createAnonymousAliasScope(), llvm::MDBuilder::createAnonymousAliasScopeDomain(), llvm::MDNode::get(), llvm::BasicBlock::getContext(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::RuntimePointerChecking::getPointerInfo(), llvm::LoopAccessInfo::getRuntimePointerChecking(), llvm::RuntimePointerChecking::PointerInfo::PointerValue, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by annotateLoopWithNoAlias(), and getNonVersionedLoop().
void LoopVersioning::setAliasChecks | ( | SmallVector< RuntimePointerChecking::PointerCheck, 4 > | Checks | ) |
Sets the runtime alias checks for versioning the loop.
Definition at line 46 of file LoopVersioning.cpp.
Referenced by getNonVersionedLoop(), isLoadConditional(), and LoopVersioning().
void LoopVersioning::setSCEVChecks | ( | SCEVUnionPredicate | Check | ) |
Sets the runtime SCEV checks for versioning the loop.
Definition at line 51 of file LoopVersioning.cpp.
Referenced by getNonVersionedLoop(), and LoopVersioning().
|
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 59 of file LoopVersioning.h.
References llvm::findDefsUsedOutsideOfLoop(), and versionLoop().
Referenced by annotateInstWithNoAlias(), 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 55 of file LoopVersioning.cpp.
References llvm::PHINode::addIncoming(), llvm::LoopAccessInfo::addRuntimeChecks(), assert(), llvm::BasicBlock::begin(), llvm::DominatorTreeBase< NodeT, IsPostDom >::changeImmediateDominator(), llvm::cloneLoopWithPreheader(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::BinaryOperator::Create(), llvm::PHINode::Create(), llvm::BranchInst::Create(), llvm::dyn_cast(), llvm::ValueMap< KeyT, ValueT, Config >::end(), llvm::Instruction::eraseFromParent(), llvm::ValueMap< KeyT, ValueT, Config >::find(), llvm::BasicBlock::front(), llvm::Module::getDataLayout(), llvm::LoopBase< BlockT, LoopT >::getExitBlock(), llvm::LoopBase< BlockT, LoopT >::getExitingBlock(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::PHINode::getIncomingValue(), llvm::LoopBase< BlockT, LoopT >::getLoopPreheader(), llvm::BasicBlock::getModule(), llvm::Value::getName(), llvm::User::getNumOperands(), llvm::LoopAccessInfo::getPSE(), llvm::BasicBlock::getTerminator(), llvm::PredicatedScalarEvolution::getUnionPredicate(), I, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::remapInstructionsInBlocks(), llvm::ValueMapIterator< DenseMapT, KeyT >::ValueTypeProxy::second, llvm::Value::setName(), llvm::SplitBlock(), and llvm::Value::users().