LLVM  3.7.0
Public Member Functions | Friends | List of all members
llvm::Loop Class Reference

#include <LoopInfo.h>

Inheritance diagram for llvm::Loop:
[legend]
Collaboration diagram for llvm::Loop:
[legend]

Public Member Functions

 Loop ()
 
bool isLoopInvariant (const Value *V) const
 isLoopInvariant - Return true if the specified value is loop invariant More...
 
bool hasLoopInvariantOperands (const Instruction *I) const
 hasLoopInvariantOperands - Return true if all the operands of the specified instruction are loop invariant. More...
 
bool makeLoopInvariant (Value *V, bool &Changed, Instruction *InsertPt=nullptr) const
 makeLoopInvariant - If the given value is an instruction inside of the loop and it can be hoisted, do so to make it trivially loop-invariant. More...
 
bool makeLoopInvariant (Instruction *I, bool &Changed, Instruction *InsertPt=nullptr) const
 makeLoopInvariant - If the given instruction is inside of the loop and it can be hoisted, do so to make it trivially loop-invariant. More...
 
PHINodegetCanonicalInductionVariable () const
 getCanonicalInductionVariable - Check to see if the loop has a canonical induction variable: an integer recurrence that starts at 0 and increments by one each time through the loop. More...
 
bool isLCSSAForm (DominatorTree &DT) const
 isLCSSAForm - Return true if the Loop is in LCSSA form More...
 
bool isLoopSimplifyForm () const
 isLoopSimplifyForm - Return true if the Loop is in the form that the LoopSimplify form transforms loops to, which is sometimes called normal form. More...
 
bool isSafeToClone () const
 isSafeToClone - Return true if the loop body is safe to clone in practice. More...
 
bool isAnnotatedParallel () const
 Returns true if the loop is annotated parallel. More...
 
MDNodegetLoopID () const
 Return the llvm.loop loop id metadata node for this loop if it is present. More...
 
void setLoopID (MDNode *LoopID) const
 Set the llvm.loop loop id metadata for this loop. More...
 
bool hasDedicatedExits () const
 hasDedicatedExits - Return true if no exit block for the loop has a predecessor that is outside the loop. More...
 
void getUniqueExitBlocks (SmallVectorImpl< BasicBlock * > &ExitBlocks) const
 getUniqueExitBlocks - Return all unique successor blocks of this loop. More...
 
BasicBlockgetUniqueExitBlock () const
 getUniqueExitBlock - If getUniqueExitBlocks would return exactly one block, return that block. More...
 
void dump () const
 
DebugLoc getStartLoc () const
 Return the debug location of the start of this loop. More...
 
- Public Member Functions inherited from llvm::LoopBase< N, M >
 LoopBase ()
 Loop ctor - This creates an empty loop. More...
 
 ~LoopBase ()
 
unsigned getLoopDepth () const
 getLoopDepth - Return the nesting level of this loop. More...
 
BlockT * getHeader () const
 
LoopT * getParentLoop () const
 
void setParentLoop (LoopT *L)
 setParentLoop is a raw interface for bypassing addChildLoop. More...
 
bool contains (const LoopT *L) const
 contains - Return true if the specified loop is contained within in this loop. More...
 
bool contains (const BlockT *BB) const
 contains - Return true if the specified basic block is in this loop. More...
 
template<class InstT >
bool contains (const InstT *Inst) const
 contains - Return true if the specified instruction is in this loop. More...
 
const std::vector< LoopT * > & getSubLoops () const
 iterator/begin/end - Return the loops contained entirely within this loop. More...
 
std::vector< LoopT * > & getSubLoopsVector ()
 
iterator begin () const
 
iterator end () const
 
reverse_iterator rbegin () const
 
reverse_iterator rend () const
 
bool empty () const
 
const std::vector< BlockT * > & getBlocks () const
 getBlocks - Get a list of the basic blocks which make up this loop. More...
 
block_iterator block_begin () const
 
block_iterator block_end () const
 
unsigned getNumBlocks () const
 getNumBlocks - Get the number of blocks in this loop in constant time. More...
 
bool isLoopExiting (const BlockT *BB) const
 isLoopExiting - True if terminator in the block can branch to another block that is outside of the current loop. More...
 
unsigned getNumBackEdges () const
 getNumBackEdges - Calculate the number of back edges to the loop header More...
 
void getExitingBlocks (SmallVectorImpl< BlockT * > &ExitingBlocks) const
 getExitingBlocks - Return all blocks inside the loop that have successors outside of the loop. More...
 
BlockT * getExitingBlock () const
 getExitingBlock - If getExitingBlocks would return exactly one block, return that block. More...
 
void getExitBlocks (SmallVectorImpl< BlockT * > &ExitBlocks) const
 getExitBlocks - Return all of the successor blocks of this loop. More...
 
BlockT * getExitBlock () const
 getExitBlock - If getExitBlocks would return exactly one block, return that block. More...
 
void getExitEdges (SmallVectorImpl< Edge > &ExitEdges) const
 getExitEdges - Return all pairs of (inside_block,outside_block). More...
 
BlockT * getLoopPreheader () const
 getLoopPreheader - If there is a preheader for this loop, return it. More...
 
BlockT * getLoopPredecessor () const
 getLoopPredecessor - If the given loop's header has exactly one unique predecessor outside the loop, return it. More...
 
BlockT * getLoopLatch () const
 getLoopLatch - If there is a single latch block for this loop, return it. More...
 
void getLoopLatches (SmallVectorImpl< BlockT * > &LoopLatches) const
 getLoopLatches - Return all loop latch blocks of this loop. More...
 
void addBasicBlockToLoop (BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
 addBasicBlockToLoop - This method is used by other analyses to update loop information. More...
 
void replaceChildLoopWith (LoopT *OldChild, LoopT *NewChild)
 replaceChildLoopWith - This is used when splitting loops up. More...
 
void addChildLoop (LoopT *NewChild)
 addChildLoop - Add the specified loop to be a child of this loop. More...
 
LoopT * removeChildLoop (iterator I)
 removeChildLoop - This removes the specified child from being a subloop of this loop. More...
 
void addBlockEntry (BlockT *BB)
 addBlockEntry - This adds a basic block directly to the basic block list. More...
 
void reverseBlock (unsigned from)
 reverseBlocks - interface to reverse Blocks[from, end of loop] in this loop More...
 
void reserveBlocks (unsigned size)
 reserveBlocks- interface to do reserve() for Blocks More...
 
void moveToHeader (BlockT *BB)
 moveToHeader - This method is used to move BB (which must be part of this loop) to be the loop header of the loop (the block that dominates all others). More...
 
void removeBlockFromLoop (BlockT *BB)
 removeBlockFromLoop - This removes the specified basic block from the current loop, updating the Blocks as appropriate. More...
 
void verifyLoop () const
 verifyLoop - Verify loop structure More...
 
void verifyLoopNest (DenseSet< const LoopT * > *Loops) const
 verifyLoop - Verify loop structure of this loop and all nested loops. More...
 
void print (raw_ostream &OS, unsigned Depth=0) const
 

Friends

class LoopInfoBase< BasicBlock, Loop >
 

Additional Inherited Members

- Public Types inherited from llvm::LoopBase< N, M >
typedef std::vector< LoopT * >
::const_iterator 
iterator
 
typedef std::vector< LoopT * >
::const_reverse_iterator 
reverse_iterator
 
typedef std::vector< BlockT * >
::const_iterator 
block_iterator
 
typedef std::pair< const
BlockT *, const BlockT * > 
Edge
 Edge type. More...
 
- Protected Member Functions inherited from llvm::LoopBase< N, M >
 LoopBase (BlockT *BB)
 

Detailed Description

Definition at line 352 of file LoopInfo.h.

Constructor & Destructor Documentation

llvm::Loop::Loop ( )
inline

Definition at line 354 of file LoopInfo.h.

Member Function Documentation

void Loop::dump ( ) const

Definition at line 404 of file LoopInfo.cpp.

References llvm::dbgs(), and llvm::LoopBase< N, M >::print().

PHINode * Loop::getCanonicalInductionVariable ( ) const

getCanonicalInductionVariable - Check to see if the loop has a canonical induction variable: an integer recurrence that starts at 0 and increments by one each time through the loop.

If so, return the phi node that corresponds to it.

The IndVarSimplify pass transforms loops to have a canonical induction variable.

Definition at line 135 of file LoopInfo.cpp.

References llvm::BasicBlock::begin(), llvm::LoopBase< N, M >::contains(), llvm::LoopBase< N, M >::getHeader(), llvm::PHINode::getIncomingValueForBlock(), H, I, llvm::pred_begin(), llvm::pred_end(), and std::swap().

MDNode * Loop::getLoopID ( ) const

Return the llvm.loop loop id metadata node for this loop if it is present.

If this loop contains the same llvm.loop metadata on each branch to the header then the node is returned. If any latch instruction does not contain llvm.loop or or if multiple latches contain different nodes then 0 is returned.

Definition at line 228 of file LoopInfo.cpp.

References llvm::LoopBase< N, M >::block_begin(), llvm::LoopBase< N, M >::block_end(), llvm::LoopBase< N, M >::getHeader(), llvm::LoopBase< N, M >::getLoopLatch(), llvm::Instruction::getMetadata(), llvm::MDNode::getNumOperands(), llvm::TerminatorInst::getNumSuccessors(), llvm::MDNode::getOperand(), llvm::TerminatorInst::getSuccessor(), H, I, llvm::ARM_PROC::IE, isLoopSimplifyForm(), and LoopMDName.

Referenced by CloneLoopBlocks(), GetUnrollMetadataForLoop(), isAnnotatedParallel(), and SetLoopAlreadyUnrolled().

DebugLoc llvm::Loop::getStartLoc ( ) const
inline

Return the debug location of the start of this loop.

This looks for a BB terminating instruction with a known debug location by looking at the preheader and header blocks. If it cannot find a terminating instruction with location information, it returns an unknown location.

Definition at line 460 of file LoopInfo.h.

References llvm::DL, llvm::Instruction::getDebugLoc(), and llvm::BasicBlock::getTerminator().

Referenced by llvm::LoopAccessReport::emitAnalysis(), and llvm::UnrollLoop().

BasicBlock * Loop::getUniqueExitBlock ( ) const

getUniqueExitBlock - If getUniqueExitBlocks would return exactly one block, return that block.

Otherwise return null.

Definition at line 395 of file LoopInfo.cpp.

References getUniqueExitBlocks(), and llvm::SmallVectorTemplateCommon< T >::size().

Referenced by ConnectProlog(), and llvm::UnrollRuntimeLoopProlog().

void Loop::getUniqueExitBlocks ( SmallVectorImpl< BasicBlock * > &  ExitBlocks) const
bool Loop::hasDedicatedExits ( ) const

hasDedicatedExits - Return true if no exit block for the loop has a predecessor that is outside the loop.

Definition at line 328 of file LoopInfo.cpp.

References llvm::LoopBase< N, M >::contains(), llvm::LoopBase< N, M >::getExitBlocks(), llvm::pred_begin(), llvm::pred_end(), and llvm::SmallVectorTemplateCommon< T >::size().

Referenced by getUniqueExitBlocks(), isLoopSimplifyForm(), and llvm::promoteLoopAccessesToScalars().

bool Loop::hasLoopInvariantOperands ( const Instruction I) const

hasLoopInvariantOperands - Return true if all the operands of the specified instruction are loop invariant.

Definition at line 67 of file LoopInfo.cpp.

References llvm::all_of(), isLoopInvariant(), and llvm::User::operands().

Referenced by llvm::hoistRegion().

bool Loop::isAnnotatedParallel ( ) const

Returns true if the loop is annotated parallel.

A parallel loop can be assumed to not contain any dependencies between iterations by the compiler. That is, any loop-carried dependency checking can be skipped completely when parallelizing the loop on the target machine. Thus, if the parallel loop information originates from the programmer, e.g. via the OpenMP parallel for pragma, it is the programmer's responsibility to ensure there are no loop-carried dependencies. The final execution order of the instructions across iterations is not guaranteed, thus, the end result might or might not implement actual concurrent execution of instructions across multiple iterations.

Definition at line 282 of file LoopInfo.cpp.

References llvm::LoopBase< N, M >::block_begin(), llvm::LoopBase< N, M >::block_end(), getLoopID(), llvm::MDNode::getNumOperands(), llvm::MDNode::getOperand(), and llvm::LLVMContext::MD_mem_parallel_loop_access.

bool Loop::isLCSSAForm ( DominatorTree DT) const
bool Loop::isLoopInvariant ( const Value V) const

isLoopInvariant - Return true if the specified value is loop invariant

Definition at line 59 of file LoopInfo.cpp.

References llvm::LoopBase< N, M >::contains(), and I.

Referenced by llvm::getStrideFromPointer(), hasLoopInvariantOperands(), isSameUnderlyingObjectInLoop(), makeLoopInvariant(), and llvm::promoteLoopAccessesToScalars().

bool Loop::isLoopSimplifyForm ( ) const

isLoopSimplifyForm - Return true if the Loop is in the form that the LoopSimplify form transforms loops to, which is sometimes called normal form.

Definition at line 199 of file LoopInfo.cpp.

References llvm::LoopBase< N, M >::getLoopLatch(), llvm::LoopBase< N, M >::getLoopPreheader(), and hasDedicatedExits().

Referenced by getLoopID(), isSimplifiedLoopNest(), setLoopID(), and llvm::UnrollRuntimeLoopProlog().

bool Loop::isSafeToClone ( ) const

isSafeToClone - Return true if the loop body is safe to clone in practice.

Routines that reform the loop CFG and split edges often fail on indirectbr.

Definition at line 207 of file LoopInfo.cpp.

References llvm::LoopBase< N, M >::block_begin(), llvm::LoopBase< N, M >::block_end(), and I.

Referenced by llvm::UnrollLoop().

bool Loop::makeLoopInvariant ( Value V,
bool Changed,
Instruction InsertPt = nullptr 
) const

makeLoopInvariant - If the given value is an instruction inside of the loop and it can be hoisted, do so to make it trivially loop-invariant.

makeLoopInvariant - If the given value is an instruciton inside of the loop and it can be hoisted, do so to make it trivially loop-invariant.

Return true if the value after any hoisting is loop invariant. This function can be used as a slightly more aggressive replacement for isLoopInvariant.

If InsertPt is specified, it is the point to hoist instructions to. If null, the terminator of the loop preheader is used.

Definition at line 80 of file LoopInfo.cpp.

References I.

Referenced by FindLIVLoopCondition(), makeLoopInvariant(), and simplifyOneLoop().

bool Loop::makeLoopInvariant ( Instruction I,
bool Changed,
Instruction InsertPt = nullptr 
) const

makeLoopInvariant - If the given instruction is inside of the loop and it can be hoisted, do so to make it trivially loop-invariant.

Return true if the instruction after any hoisting is loop invariant. This function can be used as a slightly more aggressive replacement for isLoopInvariant.

If InsertPt is specified, it is the point to hoist instructions to. If null, the terminator of the loop preheader is used.

Definition at line 96 of file LoopInfo.cpp.

References llvm::LoopBase< N, M >::getLoopPreheader(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::BasicBlock::getTerminator(), isLoopInvariant(), llvm::isSafeToSpeculativelyExecute(), makeLoopInvariant(), llvm::Instruction::mayReadFromMemory(), and llvm::Instruction::moveBefore().

void Loop::setLoopID ( MDNode LoopID) const

Set the llvm.loop loop id metadata for this loop.

The LoopID metadata node will be added to each terminator instruction in the loop that branches to the loop header.

The LoopID metadata node should have one or more operands and the first operand should should be the node itself.

Definition at line 262 of file LoopInfo.cpp.

References llvm::LoopBase< N, M >::block_begin(), llvm::LoopBase< N, M >::block_end(), llvm::LoopBase< N, M >::getHeader(), llvm::LoopBase< N, M >::getLoopLatch(), llvm::MDNode::getNumOperands(), llvm::TerminatorInst::getNumSuccessors(), llvm::MDNode::getOperand(), llvm::TerminatorInst::getSuccessor(), H, I, llvm::ARM_PROC::IE, isLoopSimplifyForm(), LoopMDName, and llvm::Instruction::setMetadata().

Referenced by CloneLoopBlocks(), and SetLoopAlreadyUnrolled().

Friends And Related Function Documentation

friend class LoopInfoBase< BasicBlock, Loop >
friend

Definition at line 478 of file LoopInfo.h.


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