LLVM: llvm::Loop::LoopBounds Struct Reference (original) (raw)

Below are some utilities to get the loop guard, loop bounds and induction variable, and to check if a given phinode is an auxiliary induction variable, if the loop is guarded, and if the loop is canonical. More...

#include "[llvm/Analysis/LoopInfo.h](LoopInfo%5F8h%5Fsource.html)"

Public Types
enum class Direction { Increasing, Decreasing, Unknown }
An enum for the direction of the loop. More...
Public Member Functions
Value & getInitialIVValue () const
Get the initial value of the loop induction variable.
Instruction & getStepInst () const
Get the instruction that updates the loop induction variable.
Value * getStepValue () const
Get the step that the loop induction variable gets updated by in each loop iteration.
Value & getFinalIVValue () const
Get the final value of the loop induction variable.
LLVM_ABI ICmpInst::Predicate getCanonicalPredicate () const
Return the canonical predicate for the latch compare instruction, if able to be calcuated.
LLVM_ABI Direction getDirection () const
Get the direction of the loop.

Below are some utilities to get the loop guard, loop bounds and induction variable, and to check if a given phinode is an auxiliary induction variable, if the loop is guarded, and if the loop is canonical.

Here is an example:

for (int i = lb; i < ub; i+=step)

beforeloop:

guardcmp = (lb < ub)

if (guardcmp) goto preheader; else goto afterloop

loop:

i_1 = phi[{lb, preheader}, {i_2, latch}]

i_2 = i_1 + step

latch:

cmp = (i_2 < ub)

if (cmp) goto loop

exit:

afterloop:

static BasicBlock * preheader(DominatorTree *DT, Loop *L)

Definition at line 153 of file LoopInfo.h.

Direction

An enum for the direction of the loop.

Enumerator
Increasing
Decreasing
Unknown

Definition at line 216 of file LoopInfo.h.

getBounds()

getCanonicalPredicate()

Return the canonical predicate for the latch compare instruction, if able to be calcuated.

Else BAD_ICMP_PREDICATE.

A predicate is considered as canonical if requirements below are all satisfied:

  1. The first successor of the latch branch is the loop header If not, inverse the predicate.
  2. One of the operands of the latch comparison is StepInst If not, and
    • if the current calcuated predicate is not ne or eq, flip the predicate.
    • else if the loop is increasing, return slt (notice that it is safe to change from ne or eq to sign compare)
    • else if the loop is decreasing, return sgt (notice that it is safe to change from ne or eq to sign compare)

Here is an example when both (1) and (2) are not satisfied:

loop.header:

%iv = phi [%initialiv, %loop.preheader], [%inc, %loop.header]

%inc = add %iv, %step

%cmp = slt %iv, %finaliv

br %cmp, %loop.exit, %loop.header

loop.exit:

The predicate would be sgt if both (1) and (2) are satisfied. getCanonicalPredicate() returns sgt for this example. Note: The IR is not changed.

Definition at line 233 of file LoopInfo.cpp.

References assert(), llvm::CmpInst::BAD_ICMP_PREDICATE, D(), llvm::dyn_cast(), llvm::dyn_cast_or_null(), llvm::BranchInst::getCondition(), getDirection(), getFinalIVValue(), llvm::CmpInst::getFlippedStrictnessPredicate(), llvm::CmpInst::getInversePredicate(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), getStepInst(), llvm::BranchInst::getSuccessor(), llvm::CmpInst::getSwappedPredicate(), llvm::BasicBlock::getTerminator(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, and llvm::BranchInst::isConditional().

getDirection()

Direction Loop::LoopBounds::getDirection ( ) const

getFinalIVValue()

Value & llvm::Loop::LoopBounds::getFinalIVValue ( ) const inline

getInitialIVValue()

Value & llvm::Loop::LoopBounds::getInitialIVValue ( ) const inline

Get the initial value of the loop induction variable.

Definition at line 165 of file LoopInfo.h.

getStepInst()

Instruction & llvm::Loop::LoopBounds::getStepInst ( ) const inline

getStepValue()

Value * llvm::Loop::LoopBounds::getStepValue ( ) const inline

Get the step that the loop induction variable gets updated by in each loop iteration.

Return nullptr if not found.

Definition at line 172 of file LoopInfo.h.


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