struct Loop::LoopBounds

Declaration

struct Loop::LoopBounds { /* full declaration omitted */ };

Description

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: - getBounds - getInitialIVValue --> lb - getStepInst --> i_2 = i_1 + step - getStepValue --> step - getFinalIVValue --> ub - getCanonicalPredicate --> ' < ' - getDirection --> Increasing - getInductionVariable --> i_1 - isAuxiliaryInductionVariable(x) --> true if x == i_1 - getLoopGuardBranch() --> `if (guardcmp) goto preheader; else goto afterloop` - isGuarded() --> true - isCanonical --> false

Declared at: llvm/include/llvm/Analysis/LoopInfo.h:657

Member Variables

private const llvm::Loop& L
private llvm::Value& InitialIVValue
private llvm::Instruction& StepInst
private llvm::Value* StepValue
private llvm::Value& FinalIVValue
private llvm::ScalarEvolution& SE

Method Overview

  • private LoopBounds(const llvm::Loop & Loop, llvm::Value & I, llvm::Instruction & SI, llvm::Value * SV, llvm::Value & F, llvm::ScalarEvolution & SE)
  • public static Optional<Loop::LoopBounds> getBounds(const llvm::Loop & L, llvm::PHINode & IndVar, llvm::ScalarEvolution & SE)
  • public ICmpInst::Predicate getCanonicalPredicate() const
  • public llvm::Loop::LoopBounds::Direction getDirection() const
  • public llvm::Value & getFinalIVValue() const
  • public llvm::Value & getInitialIVValue() const
  • public llvm::Instruction & getStepInst() const
  • public llvm::Value * getStepValue() const

Methods

LoopBounds(const llvm::Loop& Loop,
           llvm::Value& I,
           llvm::Instruction& SI,
           llvm::Value* SV,
           llvm::Value& F,
           llvm::ScalarEvolution& SE)

Declared at: llvm/include/llvm/Analysis/LoopInfo.h:726

Parameters

const llvm::Loop& Loop
llvm::Value& I
llvm::Instruction& SI
llvm::Value* SV
llvm::Value& F
llvm::ScalarEvolution& SE

static Optional<Loop::LoopBounds> getBounds(
    const llvm::Loop& L,
    llvm::PHINode& IndVar,
    llvm::ScalarEvolution& SE)

Description

Return the LoopBounds object if - the given \p IndVar is an induction variable - the initial value of the induction variable can be found - the step instruction of the induction variable can be found - the final value of the induction variable can be found Else None.

Declared at: llvm/include/llvm/Analysis/LoopInfo.h:665

Parameters

const llvm::Loop& L
llvm::PHINode& IndVar
llvm::ScalarEvolution& SE

ICmpInst::Predicate getCanonicalPredicate() const

Description

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: - The second successor of the latch branch is the loop header instead of the first successor (slt -> sge) - The first operand of the latch comparison (%cmp) is the IndVar (%iv) instead of the StepInst (%inc) (sge -> sgt) The predicate would be sgt if both (1) and (2) are satisfied. getCanonicalPredicate() returns sgt for this example. Note: The IR is not changed.

Declared at: llvm/include/llvm/Analysis/LoopInfo.h:714

llvm::Loop::LoopBounds::Direction getDirection()
    const

Description

Get the direction of the loop.

Declared at: llvm/include/llvm/Analysis/LoopInfo.h:723

llvm::Value& getFinalIVValue() const

Description

Get the final value of the loop induction variable.

Declared at: llvm/include/llvm/Analysis/LoopInfo.h:679

llvm::Value& getInitialIVValue() const

Description

Get the initial value of the loop induction variable.

Declared at: llvm/include/llvm/Analysis/LoopInfo.h:669

llvm::Instruction& getStepInst() const

Description

Get the instruction that updates the loop induction variable.

Declared at: llvm/include/llvm/Analysis/LoopInfo.h:672

llvm::Value* getStepValue() const

Description

Get the step that the loop induction variable gets updated by in each loop iteration. Return nullptr if not found.

Declared at: llvm/include/llvm/Analysis/LoopInfo.h:676