LLVM 19.0.0git
Public Member Functions | List of all members
llvm::LoopVersioning Class Reference

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.
 
LoopgetVersionedLoop ()
 Returns the versioned loop.
 
LoopgetNonVersionedLoop ()
 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.
 

Detailed 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.

Definition at line 41 of file LoopVersioning.h.

Constructor & Destructor Documentation

◆ LoopVersioning()

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 41 of file LoopVersioning.cpp.

Member Function Documentation

◆ annotateInstWithNoAlias()

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 229 of file LoopVersioning.cpp.

References AnnotateNoAlias, llvm::MDNode::concatenate(), Context, 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().

◆ 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 216 of file LoopVersioning.cpp.

References annotateInstWithNoAlias(), AnnotateNoAlias, llvm::LoopAccessInfo::getDepChecker(), llvm::MemoryDepChecker::getMemoryInstructions(), I, and prepareNoAliasMetadata().

◆ getNonVersionedLoop()

Loop * llvm::LoopVersioning::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 77 of file LoopVersioning.h.

◆ getVersionedLoop()

Loop * llvm::LoopVersioning::getVersionedLoop ( )
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.

◆ prepareNoAliasMetadata()

void LoopVersioning::prepareNoAliasMetadata ( )

◆ versionLoop() [1/2]

void llvm::LoopVersioning::versionLoop ( )
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().

◆ versionLoop() [2/2]

void LoopVersioning::versionLoop ( const SmallVectorImpl< Instruction * > &  DefsUsedOutside)

The documentation for this class was generated from the following files: