|
LLVM
4.0.0
|
#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>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 Instruction * | CloneInstructionInExitBlock (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< bool > | DisablePromotion ("disable-licm-promotion", cl::Hidden, cl::desc("Disable memory promotion in LICM pass")) |
| licm | |
| Loop Invariant Code | Motion |
| Loop Invariant Code | false |
| #define DEBUG_TYPE "licm" |
Definition at line 72 of file LICM.cpp.
Referenced by llvm::canSinkOrHoistInst(), hoist(), isSafeToExecuteUnconditionally(), llvm::promoteLoopAccessesToScalars(), and sink().
|
static |
Definition at line 641 of file LICM.cpp.
References llvm::PHINode::addIncoming(), assert(), llvm::LoopSafetyInfo::BlockColors, llvm::Instruction::clone(), llvm::CallInst::Create(), llvm::PHINode::Create(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::StringRef::empty(), llvm::TinyPtrVector< EltTy >::front(), llvm::BasicBlock::front(), llvm::BasicBlock::getFirstInsertionPt(), llvm::PHINode::getIncomingBlock(), llvm::BasicBlock::getInstList(), llvm::LoopInfoBase< N, M >::getLoopFor(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::OperandBundleUse::getTagID(), i, llvm::iplist_impl< IntrusiveListT, TraitsT >::insert(), llvm::Instruction::isEHPad(), llvm::LLVMContext::OB_funclet, llvm::User::op_begin(), llvm::User::op_end(), llvm::Value::setName(), and llvm::TinyPtrVector< EltTy >::size().
Referenced by sink().
|
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 778 of file LICM.cpp.
References llvm::dbgs(), DEBUG, DEBUG_TYPE, llvm::Instruction::dropUnknownNonDebugMetadata(), llvm::OptimizationRemarkEmitter::emit(), llvm::LoopBase< N, M >::getLoopPreheader(), llvm::Value::getName(), llvm::BasicBlock::getTerminator(), llvm::Instruction::hasMetadataOtherThanDebugLoc(), llvm::isGuaranteedToExecute(), llvm::Instruction::moveBefore(), and llvm::Instruction::setDebugLoc().
Referenced by llvm::hoistRegion().
|
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 |
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 |
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 |
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 |
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 |
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 706 of file LICM.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T >::begin(), CloneInstructionInExitBlock(), llvm::dbgs(), DEBUG, DEBUG_TYPE, llvm::AliasSetTracker::deleteValue(), llvm::OptimizationRemarkEmitter::emit(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SmallPtrSetImpl< PtrType >::end(), llvm::Instruction::eraseFromParent(), llvm::SmallPtrSetImpl< PtrType >::find(), 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" | |||
| ) |
|
static |
1.8.6