LLVM 19.0.0git
Classes | Macros | Functions | Variables
LoopUtils.cpp File Reference
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/PriorityWorklist.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/InstSimplifyFolder.h"
#include "llvm/Analysis/LoopAccessAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/MemorySSA.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"

Go to the source code of this file.

Classes

struct  RewritePhi
 
struct  PointerBounds
 IR Values for the lower and upper bounds of a pointer evolution. More...
 

Macros

#define DEBUG_TYPE   "loop-utils"
 

Functions

static MDNodecreateStringMetadata (Loop *TheLoop, StringRef Name, unsigned V)
 Create MDNode for input string.
 
static BranchInstgetExpectedExitLoopLatchBranch (Loop *L)
 Checks if L has an exiting latch branch.
 
static std::optional< uint64_tgetEstimatedTripCount (BranchInst *ExitingBranch, Loop *L, uint64_t &OrigExitWeight)
 Return the estimated trip count for any exiting branch which dominates the loop latch.
 
static bool hasHardUserWithinLoop (const Loop *L, const Instruction *I)
 
static bool canLoopBeDeleted (Loop *L, SmallVector< RewritePhi, 8 > &RewritePhiSet)
 
static bool checkIsIndPhi (PHINode *Phi, Loop *L, ScalarEvolution *SE, InductionDescriptor &ID)
 Checks if it is safe to call InductionDescriptor::isInductionPHI for Phi, and returns true if this Phi is an induction phi in the loop.
 
static PointerBounds expandBounds (const RuntimeCheckingPtrGroup *CG, Loop *TheLoop, Instruction *Loc, SCEVExpander &Exp, bool HoistRuntimeChecks)
 Expand code for the lower and upper bound of the pointer group CG in TheLoop.
 
static SmallVector< std::pair< PointerBounds, PointerBounds >, 4 > expandBounds (const SmallVectorImpl< RuntimePointerCheck > &PointerChecks, Loop *L, Instruction *Loc, SCEVExpander &Exp, bool HoistRuntimeChecks)
 Turns a collection of checks into a collection of expanded upper and lower bounds for both pointers in the check.
 

Variables

static const charLLVMLoopDisableNonforced = "llvm.loop.disable_nonforced"
 
static const charLLVMLoopDisableLICM = "llvm.licm.disable"
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "loop-utils"

Definition at line 52 of file LoopUtils.cpp.

Function Documentation

◆ canLoopBeDeleted()

static bool canLoopBeDeleted ( Loop L,
SmallVector< RewritePhi, 8 > &  RewritePhiSet 
)
static

◆ checkIsIndPhi()

static bool checkIsIndPhi ( PHINode Phi,
Loop L,
ScalarEvolution SE,
InductionDescriptor ID 
)
static

Checks if it is safe to call InductionDescriptor::isInductionPHI for Phi, and returns true if this Phi is an induction phi in the loop.

When isInductionPHI returns true, ID will be also be set by isInductionPHI.

Definition at line 1405 of file LoopUtils.cpp.

References llvm::InductionDescriptor::isInductionPHI().

Referenced by llvm::rewriteLoopExitValues().

◆ createStringMetadata()

static MDNode * createStringMetadata ( Loop TheLoop,
StringRef  Name,
unsigned  V 
)
static

◆ expandBounds() [1/2]

static PointerBounds expandBounds ( const RuntimeCheckingPtrGroup CG,
Loop TheLoop,
Instruction Loc,
SCEVExpander Exp,
bool  HoistRuntimeChecks 
)
static

◆ expandBounds() [2/2]

static SmallVector< std::pair< PointerBounds, PointerBounds >, 4 > expandBounds ( const SmallVectorImpl< RuntimePointerCheck > &  PointerChecks,
Loop L,
Instruction Loc,
SCEVExpander Exp,
bool  HoistRuntimeChecks 
)
static

Turns a collection of checks into a collection of expanded upper and lower bounds for both pointers in the check.

Definition at line 1802 of file LoopUtils.cpp.

References Check, expandBounds(), llvm::First, HoistRuntimeChecks, and llvm::transform().

◆ getEstimatedTripCount()

static std::optional< uint64_t > getEstimatedTripCount ( BranchInst ExitingBranch,
Loop L,
uint64_t OrigExitWeight 
)
static

Return the estimated trip count for any exiting branch which dominates the loop latch.

Definition at line 822 of file LoopUtils.cpp.

References llvm::divideNearest(), llvm::extractBranchWeights(), llvm::BranchInst::getSuccessor(), and std::swap().

Referenced by llvm::getLoopEstimatedTripCount().

◆ getExpectedExitLoopLatchBranch()

static BranchInst * getExpectedExitLoopLatchBranch ( Loop L)
static

Checks if L has an exiting latch branch.

There may also be other exiting blocks. Returns branch instruction terminating the loop latch if above check is successful, nullptr otherwise.

Definition at line 804 of file LoopUtils.cpp.

References assert(), llvm::BranchInst::getNumSuccessors(), llvm::BranchInst::getSuccessor(), and llvm::BasicBlock::getTerminator().

Referenced by llvm::getLoopEstimatedTripCount(), and llvm::setLoopEstimatedTripCount().

◆ hasHardUserWithinLoop()

static bool hasHardUserWithinLoop ( const Loop L,
const Instruction I 
)
static

Variable Documentation

◆ LLVMLoopDisableLICM

const char* LLVMLoopDisableLICM = "llvm.licm.disable"
static

Definition at line 55 of file LoopUtils.cpp.

Referenced by llvm::hasDisableLICMTransformsHint().

◆ LLVMLoopDisableNonforced

const char* LLVMLoopDisableNonforced = "llvm.loop.disable_nonforced"
static

Definition at line 54 of file LoopUtils.cpp.

Referenced by llvm::hasDisableAllTransformsHint().