LLVM  14.0.0git
Classes | Macros | Functions | Variables
LoopUtils.cpp File Reference
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/Optional.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/InstructionSimplify.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/MustExecute.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.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/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
Include dependency graph for LoopUtils.cpp:

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. More...
 
static LoopgetOutermostLoop (Loop *L)
 
static BranchInstgetExpectedExitLoopLatchBranch (Loop *L)
 Checks if L has an exiting latch branch. More...
 
static Optional< uint64_tgetEstimatedTripCount (BranchInst *ExitingBranch, Loop *L, uint64_t &OrigExitWeight)
 Return the estimated trip count for any exiting branch which dominates the loop latch. More...
 
static bool hasHardUserWithinLoop (const Loop *L, const Instruction *I)
 
static bool canLoopBeDeleted (Loop *L, SmallVector< RewritePhi, 8 > &RewritePhiSet)
 
static PointerBounds expandBounds (const RuntimeCheckingPtrGroup *CG, Loop *TheLoop, Instruction *Loc, SCEVExpander &Exp)
 Expand code for the lower and upper bound of the pointer group CG in TheLoop. More...
 
static SmallVector< std::pair< PointerBounds, PointerBounds >, 4 > expandBounds (const SmallVectorImpl< RuntimePointerCheck > &PointerChecks, Loop *L, Instruction *Loc, SCEVExpander &Exp)
 Turns a collection of checks into a collection of expanded upper and lower bounds for both pointers in the check. More...
 

Variables

static const char * LLVMLoopDisableNonforced = "llvm.loop.disable_nonforced"
 
static const char * LLVMLoopDisableLICM = "llvm.licm.disable"
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "loop-utils"

Definition at line 58 of file LoopUtils.cpp.

Function Documentation

◆ canLoopBeDeleted()

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

◆ 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 
)
static

Expand code for the lower and upper bound of the pointer group CG in TheLoop.

Returns
the values for the bounds.

Definition at line 1529 of file LoopUtils.cpp.

References llvm::RuntimeCheckingPtrGroup::AddressSpace, llvm::Value::getContext(), and llvm::Type::getInt8PtrTy().

Referenced by llvm::addRuntimeChecks(), and expandBounds().

◆ expandBounds() [2/2]

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

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

Definition at line 1546 of file LoopUtils.cpp.

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

◆ getEstimatedTripCount()

static 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 799 of file LoopUtils.cpp.

References llvm::LoopBase< BlockT, LoopT >::contains(), llvm::divideNearest(), llvm::Instruction::extractProfMetadata(), llvm::BranchInst::getSuccessor(), llvm::None, 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 780 of file LoopUtils.cpp.

References assert(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::LoopBase< BlockT, LoopT >::getLoopLatch(), llvm::BranchInst::getNumSuccessors(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), and llvm::LoopBase< BlockT, LoopT >::isLoopExiting().

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

◆ getOutermostLoop()

static Loop* getOutermostLoop ( Loop L)
static

Definition at line 695 of file LoopUtils.cpp.

References llvm::LoopBase< BlockT, LoopT >::getParentLoop().

Referenced by llvm::breakLoopBackedge().

◆ hasHardUserWithinLoop()

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

Variable Documentation

◆ LLVMLoopDisableLICM

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

Definition at line 61 of file LoopUtils.cpp.

Referenced by llvm::hasDisableLICMTransformsHint().

◆ LLVMLoopDisableNonforced

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

Definition at line 60 of file LoopUtils.cpp.

Referenced by llvm::hasDisableAllTransformsHint().