72 #define DEBUG_TYPE "licm"
74 STATISTIC(NumSunk,
"Number of instructions sunk out of loop");
75 STATISTIC(NumHoisted,
"Number of instructions hoisted out of loop");
76 STATISTIC(NumMovedLoads,
"Number of load insts hoisted or sunk");
77 STATISTIC(NumMovedCalls,
"Number of call insts hoisted or sunk");
78 STATISTIC(NumPromoted,
"Number of memory locations promoted to registers");
82 cl::desc(
"Disable memory promotion in LICM pass"));
109 struct LoopInvariantCodeMotion {
115 return LoopToAliasSetMap;
125 struct LegacyLICMPass :
public LoopPass {
136 for (
auto <AS :
LICM.getLoopToAliasSetMap())
138 LICM.getLoopToAliasSetMap().clear();
142 auto *SE = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
147 return LICM.runOnLoop(L,
148 &getAnalysis<AAResultsWrapperPass>().getAAResults(),
149 &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(),
150 &getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
151 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(),
152 SE ? &SE->getSE() :
nullptr, &ORE,
false);
166 bool doFinalization()
override {
168 "Didn't free loop alias sets");
173 LoopInvariantCodeMotion
LICM;
181 void deleteAnalysisValue(
Value *V,
Loop *L)
override;
184 void deleteAnalysisLoop(
Loop *L)
override;
192 Function *
F = L.getHeader()->getParent();
198 "cached at a higher level");
200 LoopInvariantCodeMotion
LICM;
201 if (!LICM.runOnLoop(&L, &AR.
AA, &AR.
LI, &AR.
DT, &AR.
TLI, &AR.
SE, ORE,
true))
231 bool Changed =
false;
256 CurAST, &SafetyInfo, ORE);
259 CurAST, &SafetyInfo, ORE);
278 if (!HasCatchSwitch) {
282 InsertPts.
push_back(&*ExitBlock->getFirstInsertionPt());
286 bool Promoted =
false;
292 TLI, L, CurAST, &SafetyInfo, ORE);
312 "Parent loop not left in LCSSA form after LICM!");
317 LoopToAliasSetMap[L] = CurAST;
337 assert(N !=
nullptr && AA !=
nullptr && LI !=
nullptr && DT !=
nullptr &&
338 CurLoop !=
nullptr && CurAST !=
nullptr && SafetyInfo !=
nullptr &&
339 "Unexpected input to sinkRegion");
347 bool Changed =
false;
348 const std::vector<DomTreeNode *> &Children = N->
getChildren();
351 sinkRegion(Child, AA, LI, DT, TLI, CurLoop, CurAST, SafetyInfo, ORE);
364 DEBUG(
dbgs() <<
"LICM deleting dead inst: " << I <<
'\n');
380 Changed |=
sink(I, LI, DT, CurLoop, CurAST, SafetyInfo, ORE);
396 assert(N !=
nullptr && AA !=
nullptr && LI !=
nullptr && DT !=
nullptr &&
397 CurLoop !=
nullptr && CurAST !=
nullptr && SafetyInfo !=
nullptr &&
398 "Unexpected input to hoistRegion");
408 bool Changed =
false;
417 DEBUG(
dbgs() <<
"LICM folding inst: " << I <<
" --> " << *
C <<
'\n');
435 I, DT, CurLoop, SafetyInfo, ORE,
437 Changed |=
hoist(I, DT, CurLoop, SafetyInfo, ORE);
440 const std::vector<DomTreeNode *> &Children = N->
getChildren();
443 hoistRegion(Child, AA, LI, DT, TLI, CurLoop, CurAST, SafetyInfo, ORE);
451 assert(CurLoop !=
nullptr &&
"CurLoop cant be null");
466 (BB != BBE) && !SafetyInfo->
MayThrow; ++BB)
485 if (
LoadInst *LI = dyn_cast<LoadInst>(&I)) {
486 if (!LI->isUnordered())
498 if (LI->getType()->isSized())
502 LI->getAAMetadata(AAInfo);
508 if (ORE && Invalidated && CurLoop->
isLoopInvariant(LI->getPointerOperand()))
510 DEBUG_TYPE,
"LoadWithLoopInvariantAddressInvalidated", LI)
511 <<
"failed to move load with loop-invariant address "
512 "because the loop may invalidate its value");
515 }
else if (
CallInst *CI = dyn_cast<CallInst>(&I)) {
517 if (isa<DbgInfoIntrinsic>(I))
533 for (
Value *
Op : CI->arg_operands())
534 if (
Op->getType()->isPointerTy() &&
542 bool FoundMod =
false;
544 if (!AS.isForwardingAliasSet() && AS.isMod()) {
560 if (!isa<BinaryOperator>(I) && !isa<CastInst>(
I) && !isa<SelectInst>(I) &&
561 !isa<GetElementPtrInst>(
I) && !isa<CmpInst>(I) &&
562 !isa<InsertElementInst>(
I) && !isa<ExtractElementInst>(I) &&
563 !isa<ShuffleVectorInst>(
I) && !isa<ExtractValueInst>(I) &&
564 !isa<InsertValueInst>(
I))
600 if (
const PHINode *PN = dyn_cast<PHINode>(UI)) {
608 if (isa<CallInst>(I))
609 if (!BlockColors.empty() &&
610 BlockColors.find(const_cast<BasicBlock *>(BB))->second.size() != 1)
626 for (
unsigned i = 0, e = PN->getNumIncomingValues();
i != e; ++
i)
627 if (PN->getIncomingValue(
i) == &
I)
628 if (CurLoop->
contains(PN->getIncomingBlock(
i)))
645 if (
auto *CI = dyn_cast<CallInst>(&I)) {
652 for (
unsigned BundleIdx = 0, BundleEnd = CI->getNumOperandBundles();
653 BundleIdx != BundleEnd; ++BundleIdx) {
661 if (!BlockColors.empty()) {
662 const ColorVector &CV = BlockColors.find(&ExitBlock)->second;
663 assert(CV.
size() == 1 &&
"non-unique color for exit block!");
688 if (
Instruction *OInst = dyn_cast<Instruction>(*OI))
690 if (!OLoop->contains(&PN)) {
693 OInst->getName() +
".lcssa", &ExitBlock.
front());
710 DEBUG(
dbgs() <<
"LICM sinking instruction: " << I <<
"\n");
712 <<
"sinking " <<
ore::NV(
"Inst", &I));
713 bool Changed =
false;
714 if (isa<LoadInst>(I))
716 else if (isa<CallInst>(I))
736 auto *
User = cast<Instruction>(*UI);
747 Use &U = UI.getUse();
755 assert(ExitBlockSet.count(ExitBlock) &&
756 "The LCSSA PHI is not in an exit block!");
759 auto It = SunkCopies.
find(ExitBlock);
760 if (It != SunkCopies.
end())
763 New = SunkCopies[ExitBlock] =
785 <<
"hosting " <<
ore::NV(
"Inst", &I));
806 if (!isa<CallInst>(I))
809 if (isa<LoadInst>(I))
811 else if (isa<CallInst>(I))
829 bool GuaranteedToExecute =
832 if (!GuaranteedToExecute) {
836 DEBUG_TYPE,
"LoadWithLoopInvariantAddressCondExecuted", LI)
837 <<
"failed to hoist load with loop-invariant address "
838 "because load is conditionally executed");
841 return GuaranteedToExecute;
864 I->getName() +
".lcssa", &BB->
front());
880 LoopExitBlocks(LEB), LoopInsertPts(LIP), PredCache(PIC), AST(ast),
881 LI(li),
DL(std::move(dl)), Alignment(alignment), AATags(AATags) {}
886 if (
LoadInst *LI = dyn_cast<LoadInst>(I))
887 Ptr = LI->getOperand(0);
890 return PointerMustAliases.count(Ptr);
893 void doExtraRewritesBeforeFinalDeletion()
const override {
898 for (
unsigned i = 0, e = LoopExitBlocks.size();
i != e; ++
i) {
900 Value *LiveInValue =
SSA.GetValueInMiddleOfBlock(ExitBlock);
901 LiveInValue = maybeInsertLCSSAPHI(LiveInValue, ExitBlock);
902 Value *Ptr = maybeInsertLCSSAPHI(SomePtr, ExitBlock);
912 void replaceLoadWithValue(
LoadInst *LI,
Value *V)
const override {
914 AST.copyValue(LI, V);
916 void instructionDeleted(
Instruction *I)
const override { AST.deleteValue(I); }
932 assert(LI !=
nullptr && DT !=
nullptr && CurLoop !=
nullptr &&
933 CurAST !=
nullptr && SafetyInfo !=
nullptr &&
934 "Unexpected Input to promoteLoopAccessesToScalars");
944 "Must alias set should have at least one pointer element in it!");
986 bool DereferenceableInPH =
false;
987 bool SafeToInsertStore =
false;
994 unsigned Alignment = 1;
1012 for (
const auto &ASI : AS) {
1013 Value *ASIV = ASI.getValue();
1014 PointerMustAliases.
insert(ASIV);
1019 if (SomePtr->getType() != ASIV->
getType())
1032 if (!
Load->isSimple())
1035 if (!DereferenceableInPH)
1044 if (!
Store->isSimple())
1052 unsigned InstAlignment =
Store->getAlignment();
1057 if (!DereferenceableInPH || !SafeToInsertStore ||
1058 (InstAlignment > Alignment)) {
1060 DereferenceableInPH =
true;
1061 SafeToInsertStore =
true;
1062 Alignment = std::max(Alignment, InstAlignment);
1072 if (!SafeToInsertStore)
1079 if (!DereferenceableInPH) {
1081 Store->getPointerOperand(),
Store->getAlignment(), MDL,
1088 if (LoopUses.
empty()) {
1091 }
else if (AATags) {
1101 if (!DereferenceableInPH)
1108 if (!SafeToInsertStore) {
1116 if (!SafeToInsertStore)
1120 DEBUG(
dbgs() <<
"LICM: Promoting value stored to in loop: " << *SomePtr
1124 <<
"Moving accesses to memory location out of the loop");
1131 DebugLoc DL = LoopUses[0]->getDebugLoc();
1136 LoopPromoter Promoter(SomePtr, LoopUses, SSA, PointerMustAliases, ExitBlocks,
1137 InsertPts, PIC, *CurAST, *LI, DL, Alignment, AATags);
1142 SomePtr, SomePtr->getName() +
".promoted", Preheader->
getTerminator());
1151 Promoter.run(LoopUses);
1167 LoopInvariantCodeMotion::collectAliasInfoForLoop(
Loop *L,
LoopInfo *LI,
1172 auto MapI = LoopToAliasSetMap.find(InnerL);
1176 if (MapI == LoopToAliasSetMap.end()) {
1182 if (CurAST !=
nullptr) {
1184 CurAST->
add(*InnerAST);
1192 LoopToAliasSetMap.erase(MapI);
1194 if (CurAST ==
nullptr)
1197 auto mergeLoop = [&](
Loop *
L) {
1204 for (
Loop *InnerL : RecomputeLoops)
1226 void LegacyLICMPass::deleteAnalysisValue(
Value *V,
Loop *L) {
1236 void LegacyLICMPass::deleteAnalysisLoop(
Loop *L) {
1242 LICM.getLoopToAliasSetMap().erase(L);
1259 assert(CurLoop->
contains(BB) &&
"Only valid if BB is IN the loop");
Pass interface - Implemented by all 'passes'.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
Helper class for SSA formation on a set of values defined in multiple blocks.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool isForwardingAliasSet() const
Return true if this alias set should be ignored as part of the AliasSetTracker object.
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
const std::vector< DomTreeNodeBase< NodeT > * > & getChildren() const
STATISTIC(NumFunctions,"Total number of functions")
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
This is the interface for a simple mod/ref and alias analysis over globals.
void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs)
Drop all unknown metadata except for debug locations.
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
The main scalar evolution driver.
This class represents a function call, abstracting a target machine's calling convention.
bool onlyReadsMemory(ImmutableCallSite CS)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
static cl::opt< bool > DisablePromotion("disable-licm-promotion", cl::Hidden, cl::desc("Disable memory promotion in LICM pass"))
LoopT * getParentLoop() const
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & front() const
bool hasLoopInvariantOperands(const Instruction *I) const
Return true if all the operands of the specified instruction are loop invariant.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
An instruction for reading from memory.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
void reserve(size_type N)
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
BlockT * getHeader() const
static bool isTriviallyReplacablePHI(const PHINode &PN, const Instruction &I)
Returns true if a PHINode is a trivially replaceable with an Instruction.
DenseMap< BasicBlock *, ColorVector > BlockColors
StringRef getName() const
Return a constant reference to the value's name.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
Loop Invariant Code Motion
bool formLCSSARecursively(Loop &L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution *SE)
Put a loop nest into LCSSA form.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
This is the interface for a SCEV-based alias analysis.
static Value * getPointerOperand(Instruction &Inst)
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.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
A Use represents the edge between a Value definition and its users.
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Constant * getPersonalityFn() const
Get the personality function associated with this function.
void setName(const Twine &Name)
Change the name of the value.
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
LLVM_NODISCARD bool empty() const
void computeLoopSafetyInfo(LoopSafetyInfo *, Loop *)
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
user_iterator_impl< User > user_iterator
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...
PredIteratorCache - This class is an extremely trivial cache for predecessor iterator queries...
FunctionModRefBehavior
Summary of how a function affects memory in the program.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
Base class for the actual dominator tree node.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
void forgetLoopDispositions(const Loop *L)
Called when the client has changed the disposition of values in this loop.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
unsigned getNumIncomingValues() const
Return the number of incoming edges.
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
iterator_range< block_iterator > blocks() const
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
Checks whether the given location points to constant memory, or if OrLocal is true whether it points ...
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
A set of analyses that are preserved following a run of a transformation pass.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
void setAAMetadata(const AAMDNodes &N)
Sets the metadata on this instruction from the AAMDNodes structure.
LLVM Basic Block Representation.
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
bool isVolatile() const
Return true if this alias set contains volatile loads or stores.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
bool hasPersonalityFn() const
Check whether this function has a personality function.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
Return the behavior of the given call site.
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
const InstListType & getInstList() const
Return the underlying instruction list container.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
Value * getOperand(unsigned i) const
iterator find(PtrType Ptr) const
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 ...
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
void setAlignment(unsigned Align)
Used in the streaming interface as the general argument type.
bool promoteLoopAccessesToScalars(AliasSet &, SmallVectorImpl< BasicBlock * > &, SmallVectorImpl< Instruction * > &, PredIteratorCache &, LoopInfo *, DominatorTree *, const TargetLibraryInfo *, Loop *, AliasSetTracker *, LoopSafetyInfo *, OptimizationRemarkEmitter *)
Try to promote memory values to scalars by sinking stores out of the loop and moving loads to before ...
bool hasDedicatedExits() const
Return true if no exit block for the loop has a predecessor that is outside the loop.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void getUniqueExitBlocks(SmallVectorImpl< BasicBlock * > &ExitBlocks) const
Return all unique successor blocks of this loop.
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
This function does not perform any non-local loads or stores to memory.
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
void copyValue(Value *From, Value *To)
This method should be used whenever a preexisting value in the program is copied or cloned...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
bool isLCSSAForm(DominatorTree &DT) const
Return true if the Loop is in LCSSA form.
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
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.
bool hoistRegion(DomTreeNode *, AliasAnalysis *, LoopInfo *, DominatorTree *, TargetLibraryInfo *, Loop *, AliasSetTracker *, LoopSafetyInfo *, OptimizationRemarkEmitter *ORE)
Walk the specified region of the CFG (defined by all blocks dominated by the specified block...
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
void add(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo)
These methods are used to add different types of instructions to the alias sets.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool sinkRegion(DomTreeNode *, AliasAnalysis *, LoopInfo *, DominatorTree *, TargetLibraryInfo *, Loop *, AliasSetTracker *, LoopSafetyInfo *, OptimizationRemarkEmitter *ORE)
Walk the specified region of the CFG (defined by all blocks dominated by the specified block...
A lightweight accessor for an operand bundle meant to be passed around by value.
iterator_range< user_iterator > users()
static bool isSafeToExecuteUnconditionally(Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo, OptimizationRemarkEmitter *ORE, const Instruction *CtxI=nullptr)
Only sink or hoist an instruction if it is not a trapping instruction, or if the instruction is known...
std::vector< BlockT * >::const_iterator block_iterator
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
block_iterator block_end() const
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
static bool onlyAccessesArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from objects poin...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
iterator insert(iterator where, pointer New)
Captures loop safety information.
void emplace_back(ArgTypes &&...Args)
AliasSet & getAliasSetForPointer(Value *P, uint64_t Size, const AAMDNodes &AAInfo)
Return the alias set that the specified pointer lives in.
static Instruction * CloneInstructionInExitBlock(Instruction &I, BasicBlock &ExitBlock, PHINode &PN, const LoopInfo *LI, const LoopSafetyInfo *SafetyInfo)
Represents a single loop in the control flow graph.
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc...
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Loop Invariant Code false
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
LLVM Value Representation.
void setAlignment(unsigned Align)
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
void initializeLegacyLICMPassPass(PassRegistry &)
const std::vector< LoopT * > & getSubLoops() const
Return the loops contained entirely within this loop.
block_iterator block_begin() const
This is the interface for LLVM's primary stateless and local alias analysis.
A container for analyses that lazily runs them and caches their results.
bool isDereferenceableAndAlignedPointer(const Value *V, unsigned Align, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested...
bool canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT, Loop *CurLoop, AliasSetTracker *CurAST, LoopSafetyInfo *SafetyInfo, OptimizationRemarkEmitter *ORE=nullptr)
Returns true if the hoister and sinker can handle this instruction.
iterator getFirstInsertionPt()
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
DomTreeNodeBase< NodeT > * getNode(NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
op_range incoming_values()
bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo)
Returns true if the instruction in a loop is guaranteed to execute at least once. ...
const BasicBlock * getParent() const
void deleteValue(Value *PtrVal)
This method is used to remove a pointer value from the AliasSetTracker entirely.
loop versioning Loop Versioning For LICM
INITIALIZE_PASS_BEGIN(LegacyLICMPass,"licm","Loop Invariant Code Motion", false, false) INITIALIZE_PASS_END(LegacyLICMPass