LLVM  4.0.0
Macros | Functions | Variables
LICM.cpp File Reference
#include "llvm/Transforms/Scalar/LICM.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/CaptureTracking.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.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/Scalar.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
#include <algorithm>
#include <utility>
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, const LoopSafetyInfo *SafetyInfo)
 Return true if the only users of this instruction are outside of the loop. More...
 
static bool hoist (Instruction &I, const DominatorTree *DT, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo, OptimizationRemarkEmitter *ORE)
 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, const LoopSafetyInfo *SafetyInfo, OptimizationRemarkEmitter *ORE)
 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 isSafeToExecuteUnconditionally (Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo, OptimizationRemarkEmitter *ORE, 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 (Instruction &I, BasicBlock &ExitBlock, PHINode &PN, const LoopInfo *LI, const LoopSafetyInfo *SafetyInfo)
 
 INITIALIZE_PASS_BEGIN (LegacyLICMPass,"licm","Loop Invariant Code Motion", false, false) INITIALIZE_PASS_END(LegacyLICMPass
 
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"))
 
 licm
 
Loop Invariant Code Motion
 
Loop Invariant Code false
 

Macro Definition Documentation

#define DEBUG_TYPE   "licm"

Function Documentation

static Instruction * CloneInstructionInExitBlock ( Instruction I,
BasicBlock ExitBlock,
PHINode PN,
const LoopInfo LI,
const LoopSafetyInfo SafetyInfo 
)
static
static bool hoist ( Instruction I,
const DominatorTree DT,
const Loop CurLoop,
const LoopSafetyInfo SafetyInfo,
OptimizationRemarkEmitter ORE 
)
static
INITIALIZE_PASS_BEGIN ( LegacyLICMPass  ,
"licm"  ,
"Loop Invariant Code Motion ,
false  ,
false   
)
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 1258 of file LICM.cpp.

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

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

static bool isNotUsedInLoop ( const Instruction I,
const Loop CurLoop,
const LoopSafetyInfo SafetyInfo 
)
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 595 of file LICM.cpp.

References llvm::LoopSafetyInfo::BlockColors, llvm::LoopBase< N, M >::contains(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), I, i, isTriviallyReplacablePHI(), and llvm::Value::users().

Referenced by llvm::sinkRegion().

static bool isSafeToExecuteUnconditionally ( Instruction Inst,
const DominatorTree DT,
const Loop CurLoop,
const LoopSafetyInfo SafetyInfo,
OptimizationRemarkEmitter ORE,
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 820 of file LICM.cpp.

References DEBUG_TYPE, llvm::dyn_cast(), llvm::OptimizationRemarkEmitter::emit(), llvm::isGuaranteedToExecute(), llvm::Loop::isLoopInvariant(), and llvm::isSafeToSpeculativelyExecute().

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

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 583 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 1248 of file LICM.cpp.

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

Referenced by llvm::canSinkOrHoistInst().

static bool sink ( Instruction I,
const LoopInfo LI,
const DominatorTree DT,
const Loop CurLoop,
AliasSetTracker CurAST,
const LoopSafetyInfo SafetyInfo,
OptimizationRemarkEmitter ORE 
)
static
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
Loop Invariant Code false

Definition at line 214 of file LICM.cpp.

licm

Definition at line 214 of file LICM.cpp.

Loop Invariant Code Motion

Definition at line 214 of file LICM.cpp.