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

This class is used to constrain loops to run within a given iteration space. More...

#include "llvm/Transforms/Utils/LoopConstrainer.h"

Classes

struct  SubRanges
 

Public Member Functions

 LoopConstrainer (Loop &L, LoopInfo &LI, function_ref< void(Loop *, bool)> LPMAddNewLoop, const LoopStructure &LS, ScalarEvolution &SE, DominatorTree &DT, Type *T, SubRanges SR)
 
bool run ()
 

Detailed Description

This class is used to constrain loops to run within a given iteration space.

The algorithm this class implements is given a Loop and a range [Begin, End). The algorithm then tries to break out a "main loop" out of the loop it is given in a way that the "main loop" runs with the induction variable in a subset of [Begin, End). The algorithm emits appropriate pre and post loops to run any remaining iterations. The pre loop runs any iterations in which the induction variable is < Begin, and the post loop runs any iterations in which the induction variable is >= End.

Definition at line 95 of file LoopConstrainer.h.

Constructor & Destructor Documentation

◆ LoopConstrainer()

LoopConstrainer::LoopConstrainer ( Loop L,
LoopInfo LI,
function_ref< void(Loop *, bool)>  LPMAddNewLoop,
const LoopStructure LS,
ScalarEvolution SE,
DominatorTree DT,
Type T,
SubRanges  SR 
)

Definition at line 454 of file LoopConstrainer.cpp.

Member Function Documentation

◆ run()

bool LoopConstrainer::run ( )

At this point:

  • We've broken a "main loop" out of the loop in a way that the "main loop" runs with the induction variable in a subset of [Begin, End).
  • There is no overflow when computing "main loop" exit limit.
  • Max latch taken count of the loop is limited. It guarantees that induction variable will not overflow iterating in the "main loop".

TODO: support unsigned predicate. To add NUW flag we need to prove that both operands of BO are non-negative. E.g: ... iv.next = add nsw i32 iv, -1 cmp = icmp ult i32 iv.next, n br i1 cmp, label loopexit, label loop

-1 is MAX_UINT in terms of unsigned int. Adding anything but zero will overflow, therefore NUW flag is not legal here.

Definition at line 720 of file LoopConstrainer.cpp.

References assert(), llvm::cannotBeMinInLoop(), llvm::dbgs(), DisableAllLoopOptsOnLoop(), llvm::SCEVExpander::expandCodeFor(), llvm::formLCSSARecursively(), llvm::ScalarEvolution::getAddExpr(), llvm::ScalarEvolution::getConstant(), llvm::Module::getDataLayout(), llvm::LoopBase< BlockT, LoopT >::getLoopPreheader(), llvm::Value::getName(), llvm::GlobalValue::getParent(), llvm::Instruction::getParent(), llvm::LoopBase< BlockT, LoopT >::getParentLoop(), llvm::BasicBlock::getTerminator(), llvm::LoopStructure::Header, llvm::LoopConstrainer::SubRanges::HighLimit, llvm::LoopStructure::IndVarBase, llvm::LoopStructure::IndVarIncreasing, llvm::SCEVExpander::isSafeToExpandAt(), llvm::LoopStructure::IsSignedPredicate, LLVM_DEBUG, llvm::LoopConstrainer::SubRanges::LowLimit, llvm::DominatorTreeBase< NodeT, IsPostDom >::recalculate(), llvm::User::replaceUsesOfWith(), llvm::Value::setName(), and llvm::simplifyLoop().


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