LLVM 20.0.0git
|
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"
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. | |
ICmpInst::Predicate | getCanonicalPredicate () const |
Return the canonical predicate for the latch compare instruction, if able to be calcuated. | |
Direction | getDirection () const |
Get the direction of the loop. | |
Static Public Member Functions | |
static std::optional< Loop::LoopBounds > | getBounds (const Loop &L, PHINode &IndVar, ScalarEvolution &SE) |
Return the LoopBounds object if. | |
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:
if (guardcmp) goto preheader; else goto afterloop
Definition at line 152 of file LoopInfo.h.
|
strong |
An enum for the direction of the loop.
Enumerator | |
---|---|
Increasing | |
Decreasing | |
Unknown |
Definition at line 215 of file LoopInfo.h.
|
static |
Return the LoopBounds object if.
IndVar
is an induction variableElse std::nullopt.
Definition at line 203 of file LoopInfo.cpp.
References findFinalIVValue(), llvm::InductionDescriptor::getInductionBinOp(), llvm::User::getOperand(), llvm::ScalarEvolution::getSCEV(), llvm::InductionDescriptor::getStartValue(), llvm::InductionDescriptor::getStep(), and llvm::InductionDescriptor::isInductionPHI().
Referenced by llvm::Loop::getBounds().
ICmpInst::Predicate Loop::LoopBounds::getCanonicalPredicate | ( | ) | const |
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:
Here is an example when both (1) and (2) are not satisfied:
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::BranchInst::getCondition(), llvm::CmpInst::getFlippedStrictnessPredicate(), llvm::CmpInst::getInversePredicate(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), 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().
Direction Loop::LoopBounds::getDirection | ( | ) | const |
Get the direction of the loop.
Definition at line 275 of file LoopInfo.cpp.
|
inline |
Get the final value of the loop induction variable.
Definition at line 174 of file LoopInfo.h.
|
inline |
Get the initial value of the loop induction variable.
Definition at line 164 of file LoopInfo.h.
|
inline |
Get the instruction that updates the loop induction variable.
Definition at line 167 of file LoopInfo.h.
|
inline |
Get the step that the loop induction variable gets updated by in each loop iteration.
Return nullptr if not found.
Definition at line 171 of file LoopInfo.h.