LLVM  3.7.0
Macros | Functions | Variables
LICM.cpp File Reference
#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/PredIteratorCache.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
#include <algorithm>
Include dependency graph for LICM.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "licm"
 

Functions

 STATISTIC (NumSunk,"Number of instructions sunk out of loop")
 
 STATISTIC (NumHoisted,"Number of instructions hoisted out of loop")
 
 STATISTIC (NumMovedLoads,"Number of load insts hoisted or sunk")
 
 STATISTIC (NumMovedCalls,"Number of call insts hoisted or sunk")
 
 STATISTIC (NumPromoted,"Number of memory locations promoted to registers")
 
static bool inSubLoop (BasicBlock *BB, Loop *CurLoop, LoopInfo *LI)
 Little predicate that returns true if the specified basic block is in a subloop of the current one, not the current one itself. More...
 
static bool isNotUsedInLoop (const Instruction &I, const Loop *CurLoop)
 Return true if the only users of this instruction are outside of the loop. More...
 
static bool hoist (Instruction &I, BasicBlock *Preheader)
 When an instruction is found to only use loop invariant operands that is safe to hoist, this instruction is called to do the dirty work. More...
 
static bool sink (Instruction &I, const LoopInfo *LI, const DominatorTree *DT, const Loop *CurLoop, AliasSetTracker *CurAST)
 When an instruction is found to only be used outside of the loop, this function moves it to the exit blocks and patches up SSA form as needed. More...
 
static bool isGuaranteedToExecute (const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop, const LICMSafetyInfo *SafetyInfo)
 
static bool isSafeToExecuteUnconditionally (const Instruction &Inst, const DominatorTree *DT, const TargetLibraryInfo *TLI, const Loop *CurLoop, const LICMSafetyInfo *SafetyInfo, const Instruction *CtxI)
 Only sink or hoist an instruction if it is not a trapping instruction, or if the instruction is known not to trap when moved to the preheader. More...
 
static bool pointerInvalidatedByLoop (Value *V, uint64_t Size, const AAMDNodes &AAInfo, AliasSetTracker *CurAST)
 Return true if the body of this loop may store into the memory location pointed to by V. More...
 
static InstructionCloneInstructionInExitBlock (const Instruction &I, BasicBlock &ExitBlock, PHINode &PN, const LoopInfo *LI)
 
static bool canSinkOrHoistInst (Instruction &I, AliasAnalysis *AA, DominatorTree *DT, TargetLibraryInfo *TLI, Loop *CurLoop, AliasSetTracker *CurAST, LICMSafetyInfo *SafetyInfo)
 canSinkOrHoistInst - Return true if the hoister and sinker can handle this instruction. More...
 
static bool isTriviallyReplacablePHI (const PHINode &PN, const Instruction &I)
 Returns true if a PHINode is a trivially replaceable with an Instruction. More...
 

Variables

static cl::opt< boolDisablePromotion ("disable-licm-promotion", cl::Hidden, cl::desc("Disable memory promotion in LICM pass"))
 

Macro Definition Documentation

#define DEBUG_TYPE   "licm"

Definition at line 62 of file LICM.cpp.

Function Documentation

bool canSinkOrHoistInst ( Instruction I,
AliasAnalysis AA,
DominatorTree DT,
TargetLibraryInfo TLI,
Loop CurLoop,
AliasSetTracker CurAST,
LICMSafetyInfo SafetyInfo 
)
static
static Instruction * CloneInstructionInExitBlock ( const Instruction I,
BasicBlock ExitBlock,
PHINode PN,
const LoopInfo LI 
)
static
static bool hoist ( Instruction I,
BasicBlock Preheader 
)
static

When an instruction is found to only use loop invariant operands that is safe to hoist, this instruction is called to do the dirty work.

Definition at line 648 of file LICM.cpp.

References llvm::dbgs(), DEBUG, llvm::Value::getName(), llvm::BasicBlock::getTerminator(), and llvm::Instruction::moveBefore().

Referenced by llvm::hoistRegion().

static bool inSubLoop ( BasicBlock BB,
Loop CurLoop,
LoopInfo LI 
)
static

Little predicate that returns true if the specified basic block is in a subloop of the current one, not the current one itself.

Definition at line 1021 of file LICM.cpp.

References llvm::LoopBase< N, M >::contains(), and llvm::LoopInfoBase< N, M >::getLoopFor().

Referenced by llvm::hoistRegion(), and llvm::sinkRegion().

static bool isGuaranteedToExecute ( const Instruction Inst,
const DominatorTree DT,
const Loop CurLoop,
const LICMSafetyInfo SafetyInfo 
)
static
static bool isNotUsedInLoop ( const Instruction I,
const Loop CurLoop 
)
static

Return true if the only users of this instruction are outside of the loop.

If this is true, we can sink the instruction to the exit blocks of the loop.

Definition at line 516 of file LICM.cpp.

References llvm::LoopBase< N, M >::contains(), I, isTriviallyReplacablePHI(), and llvm::Value::users().

Referenced by llvm::sinkRegion().

static bool isSafeToExecuteUnconditionally ( const Instruction Inst,
const DominatorTree DT,
const TargetLibraryInfo TLI,
const Loop CurLoop,
const LICMSafetyInfo SafetyInfo,
const Instruction CtxI 
)
static

Only sink or hoist an instruction if it is not a trapping instruction, or if the instruction is known not to trap when moved to the preheader.

or if it is a trapping instruction and is guaranteed to execute.

Definition at line 663 of file LICM.cpp.

References isGuaranteedToExecute(), and llvm::isSafeToSpeculativelyExecute().

Referenced by canSinkOrHoistInst(), and llvm::hoistRegion().

static bool isTriviallyReplacablePHI ( const PHINode PN,
const Instruction I 
)
static

Returns true if a PHINode is a trivially replaceable with an Instruction.

This is true when all incoming values are that instruction. This pattern occurs most often with LCSSA PHI nodes.

Definition at line 504 of file LICM.cpp.

References llvm::PHINode::incoming_values().

Referenced by isNotUsedInLoop().

static bool pointerInvalidatedByLoop ( Value V,
uint64_t  Size,
const AAMDNodes AAInfo,
AliasSetTracker CurAST 
)
static

Return true if the body of this loop may store into the memory location pointed to by V.

Definition at line 1011 of file LICM.cpp.

References llvm::AliasSetTracker::getAliasSetForPointer(), and llvm::AliasSet::isMod().

Referenced by canSinkOrHoistInst().

static bool sink ( Instruction I,
const LoopInfo LI,
const DominatorTree DT,
const Loop CurLoop,
AliasSetTracker CurAST 
)
static

When an instruction is found to only be used outside of the loop, this function moves it to the exit blocks and patches up SSA form as needed.

This method is guaranteed to remove the original instruction from its position, and may either delete it or move it to outside of the loop.

Definition at line 582 of file LICM.cpp.

References llvm::SmallVectorTemplateCommon< T >::begin(), CloneInstructionInExitBlock(), llvm::dbgs(), DEBUG, llvm::AliasSetTracker::deleteValue(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SmallPtrSetImpl< PtrType >::end(), llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::PHINode::getIncomingBlock(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::Loop::getUniqueExitBlocks(), llvm::DominatorTree::isReachableFromEntry(), llvm::Value::replaceAllUsesWith(), llvm::User::replaceUsesOfWith(), llvm::Value::use_empty(), and llvm::Value::user_begin().

Referenced by llvm::sinkRegion().

STATISTIC ( NumSunk  ,
"Number of instructions sunk out of loop"   
)
STATISTIC ( NumHoisted  ,
"Number of instructions hoisted out of loop"   
)
STATISTIC ( NumMovedLoads  ,
"Number of load insts hoisted or sunk"   
)
STATISTIC ( NumMovedCalls  ,
"Number of call insts hoisted or sunk"   
)
STATISTIC ( NumPromoted  ,
"Number of memory locations promoted to registers"   
)

Variable Documentation

cl::opt<bool> DisablePromotion("disable-licm-promotion", cl::Hidden, cl::desc("Disable memory promotion in LICM pass"))
static