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");
83 cl::desc(
"Disable memory promotion in LICM pass"));
87 cl::desc(
"Max num uses visited for identifying load "
88 "invariance in loop using invariant start (default = 8)"));
115 struct LoopInvariantCodeMotion {
121 return LoopToAliasSetMap;
131 struct LegacyLICMPass :
public LoopPass {
142 for (
auto <AS :
LICM.getLoopToAliasSetMap())
144 LICM.getLoopToAliasSetMap().clear();
148 auto *SE = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
153 return LICM.runOnLoop(L,
154 &getAnalysis<AAResultsWrapperPass>().getAAResults(),
155 &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(),
156 &getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
157 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(),
158 SE ? &SE->getSE() :
nullptr, &ORE,
false);
172 bool doFinalization()
override {
174 "Didn't free loop alias sets");
179 LoopInvariantCodeMotion
LICM;
187 void deleteAnalysisValue(
Value *V,
Loop *L)
override;
190 void deleteAnalysisLoop(
Loop *L)
override;
198 Function *
F = L.getHeader()->getParent();
204 "cached at a higher level");
206 LoopInvariantCodeMotion
LICM;
207 if (!LICM.runOnLoop(&L, &AR.
AA, &AR.
LI, &AR.
DT, &AR.
TLI, &AR.
SE, ORE,
true))
237 bool Changed =
false;
262 CurAST, &SafetyInfo, ORE);
265 CurAST, &SafetyInfo, ORE);
284 if (!HasCatchSwitch) {
288 InsertPts.
push_back(&*ExitBlock->getFirstInsertionPt());
292 bool Promoted =
false;
298 TLI, L, CurAST, &SafetyInfo, ORE);
318 "Parent loop not left in LCSSA form after LICM!");
323 LoopToAliasSetMap[L] = CurAST;
343 assert(N !=
nullptr && AA !=
nullptr && LI !=
nullptr && DT !=
nullptr &&
344 CurLoop !=
nullptr && CurAST !=
nullptr && SafetyInfo !=
nullptr &&
345 "Unexpected input to sinkRegion");
353 bool Changed =
false;
354 const std::vector<DomTreeNode *> &Children = N->
getChildren();
357 sinkRegion(Child, AA, LI, DT, TLI, CurLoop, CurAST, SafetyInfo, ORE);
370 DEBUG(
dbgs() <<
"LICM deleting dead inst: " << I <<
'\n');
386 Changed |=
sink(I, LI, DT, CurLoop, CurAST, SafetyInfo, ORE);
402 assert(N !=
nullptr && AA !=
nullptr && LI !=
nullptr && DT !=
nullptr &&
403 CurLoop !=
nullptr && CurAST !=
nullptr && SafetyInfo !=
nullptr &&
404 "Unexpected input to hoistRegion");
414 bool Changed =
false;
423 DEBUG(
dbgs() <<
"LICM folding inst: " << I <<
" --> " << *
C <<
'\n');
436 if (I.
getOpcode() == Instruction::FDiv &&
441 auto ReciprocalDivisor = BinaryOperator::CreateFDiv(One, Divisor);
443 ReciprocalDivisor->insertBefore(&I);
445 auto Product = BinaryOperator::CreateFMul(I.
getOperand(0),
448 Product->insertAfter(&I);
452 hoist(*ReciprocalDivisor, DT, CurLoop, SafetyInfo, ORE);
464 I, DT, CurLoop, SafetyInfo, ORE,
466 Changed |=
hoist(I, DT, CurLoop, SafetyInfo, ORE);
469 const std::vector<DomTreeNode *> &Children = N->
getChildren();
472 hoistRegion(Child, AA, LI, DT, TLI, CurLoop, CurAST, SafetyInfo, ORE);
480 assert(CurLoop !=
nullptr &&
"CurLoop cant be null");
495 assert(Header == *CurLoop->
getBlocks().begin() &&
"First block must be header");
498 (BB != BBE) && !SafetyInfo->
MayThrow; ++BB)
521 cast<PointerType>(Addr->
getType())->getElementType());
527 unsigned BitcastsVisited = 0;
530 while (Addr->
getType() != PtrInt8Ty) {
535 Addr = BC->getOperand(0);
538 unsigned UsesVisited = 0;
541 for (
auto *U : Addr->
users()) {
551 unsigned InvariantSizeInBits =
557 if (LocSizeInBits <= InvariantSizeInBits &&
570 if (
LoadInst *LI = dyn_cast<LoadInst>(&I)) {
571 if (!LI->isUnordered())
587 if (LI->getType()->isSized())
591 LI->getAAMetadata(AAInfo);
597 if (ORE && Invalidated && CurLoop->
isLoopInvariant(LI->getPointerOperand()))
599 DEBUG_TYPE,
"LoadWithLoopInvariantAddressInvalidated", LI)
600 <<
"failed to move load with loop-invariant address "
601 "because the loop may invalidate its value");
604 }
else if (
CallInst *CI = dyn_cast<CallInst>(&I)) {
606 if (isa<DbgInfoIntrinsic>(I))
622 for (
Value *
Op : CI->arg_operands())
623 if (
Op->getType()->isPointerTy() &&
631 bool FoundMod =
false;
633 if (!AS.isForwardingAliasSet() && AS.isMod()) {
649 if (!isa<BinaryOperator>(I) && !isa<CastInst>(
I) && !isa<SelectInst>(I) &&
650 !isa<GetElementPtrInst>(
I) && !isa<CmpInst>(I) &&
651 !isa<InsertElementInst>(
I) && !isa<ExtractElementInst>(I) &&
652 !isa<ShuffleVectorInst>(
I) && !isa<ExtractValueInst>(I) &&
653 !isa<InsertValueInst>(
I))
689 if (
const PHINode *PN = dyn_cast<PHINode>(UI)) {
697 if (isa<CallInst>(I))
698 if (!BlockColors.empty() &&
699 BlockColors.find(const_cast<BasicBlock *>(BB))->second.size() != 1)
715 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
716 if (PN->getIncomingValue(i) == &
I)
717 if (CurLoop->
contains(PN->getIncomingBlock(i)))
734 if (
auto *CI = dyn_cast<CallInst>(&I)) {
741 for (
unsigned BundleIdx = 0, BundleEnd = CI->getNumOperandBundles();
742 BundleIdx != BundleEnd; ++BundleIdx) {
750 if (!BlockColors.empty()) {
751 const ColorVector &CV = BlockColors.find(&ExitBlock)->second;
752 assert(CV.
size() == 1 &&
"non-unique color for exit block!");
777 if (
Instruction *OInst = dyn_cast<Instruction>(*OI))
779 if (!OLoop->contains(&PN)) {
782 OInst->getName() +
".lcssa", &ExitBlock.
front());
799 DEBUG(
dbgs() <<
"LICM sinking instruction: " << I <<
"\n");
801 <<
"sinking " <<
ore::NV(
"Inst", &I));
802 bool Changed =
false;
803 if (isa<LoadInst>(I))
805 else if (isa<CallInst>(I))
825 auto *
User = cast<Instruction>(*UI);
836 Use &U = UI.getUse();
844 assert(ExitBlockSet.count(ExitBlock) &&
845 "The LCSSA PHI is not in an exit block!");
848 auto It = SunkCopies.
find(ExitBlock);
849 if (It != SunkCopies.
end())
852 New = SunkCopies[ExitBlock] =
874 <<
"hoisting " <<
ore::NV(
"Inst", &I));
895 if (!isa<CallInst>(I))
898 if (isa<LoadInst>(I))
900 else if (isa<CallInst>(I))
918 bool GuaranteedToExecute =
921 if (!GuaranteedToExecute) {
925 DEBUG_TYPE,
"LoadWithLoopInvariantAddressCondExecuted", LI)
926 <<
"failed to hoist load with loop-invariant address "
927 "because load is conditionally executed");
930 return GuaranteedToExecute;
944 bool UnorderedAtomic;
954 I->getName() +
".lcssa", &BB->
front());
968 bool UnorderedAtomic,
const AAMDNodes &AATags)
970 LoopExitBlocks(LEB), LoopInsertPts(LIP), PredCache(PIC), AST(ast),
971 LI(li),
DL(std::move(dl)), Alignment(alignment),
972 UnorderedAtomic(UnorderedAtomic),AATags(AATags) {}
977 if (
LoadInst *LI = dyn_cast<LoadInst>(I))
978 Ptr = LI->getOperand(0);
981 return PointerMustAliases.count(Ptr);
984 void doExtraRewritesBeforeFinalDeletion()
const override {
989 for (
unsigned i = 0, e = LoopExitBlocks.size(); i != e; ++i) {
991 Value *LiveInValue =
SSA.GetValueInMiddleOfBlock(ExitBlock);
992 LiveInValue = maybeInsertLCSSAPHI(LiveInValue, ExitBlock);
993 Value *Ptr = maybeInsertLCSSAPHI(SomePtr, ExitBlock);
1005 void replaceLoadWithValue(
LoadInst *LI,
Value *V)
const override {
1007 AST.copyValue(LI, V);
1009 void instructionDeleted(
Instruction *I)
const override { AST.deleteValue(I); }
1025 assert(LI !=
nullptr && DT !=
nullptr && CurLoop !=
nullptr &&
1026 CurAST !=
nullptr && SafetyInfo !=
nullptr &&
1027 "Unexpected Input to promoteLoopAccessesToScalars");
1037 "Must alias set should have at least one pointer element in it!");
1079 bool DereferenceableInPH =
false;
1080 bool SafeToInsertStore =
false;
1087 unsigned Alignment = 1;
1089 bool SawUnorderedAtomic =
false;
1090 bool SawNotAtomic =
false;
1096 bool IsKnownNonEscapingObject =
false;
1109 if (!isa<AllocaInst>(Object)) {
1121 IsKnownNonEscapingObject =
true;
1128 for (
const auto &ASI : AS) {
1129 Value *ASIV = ASI.getValue();
1130 PointerMustAliases.
insert(ASIV);
1135 if (SomePtr->getType() != ASIV->
getType())
1148 if (!
Load->isUnordered())
1151 SawUnorderedAtomic |=
Load->isAtomic();
1152 SawNotAtomic |= !
Load->isAtomic();
1154 if (!DereferenceableInPH)
1163 if (!
Store->isUnordered())
1166 SawUnorderedAtomic |=
Store->isAtomic();
1167 SawNotAtomic |= !
Store->isAtomic();
1174 unsigned InstAlignment =
Store->getAlignment();
1179 if (!DereferenceableInPH || !SafeToInsertStore ||
1180 (InstAlignment > Alignment)) {
1182 DereferenceableInPH =
true;
1183 SafeToInsertStore =
true;
1184 Alignment =
std::max(Alignment, InstAlignment);
1194 if (!SafeToInsertStore)
1201 if (!DereferenceableInPH) {
1203 Store->getPointerOperand(),
Store->getAlignment(), MDL,
1210 if (LoopUses.
empty()) {
1213 }
else if (AATags) {
1225 if (SawUnorderedAtomic && SawNotAtomic)
1229 if (!DereferenceableInPH)
1236 if (!SafeToInsertStore) {
1238 if (IsKnownNonEscapingObject)
1239 SafeToInsertStore =
true;
1249 if (!SafeToInsertStore)
1253 DEBUG(
dbgs() <<
"LICM: Promoting value stored to in loop: " << *SomePtr
1257 <<
"Moving accesses to memory location out of the loop");
1269 LoopPromoter Promoter(SomePtr, LoopUses, SSA, PointerMustAliases, ExitBlocks,
1270 InsertPts, PIC, *CurAST, *LI, DL, Alignment,
1271 SawUnorderedAtomic, AATags);
1276 SomePtr, SomePtr->getName() +
".promoted", Preheader->
getTerminator());
1277 if (SawUnorderedAtomic)
1287 Promoter.run(LoopUses);
1303 LoopInvariantCodeMotion::collectAliasInfoForLoop(
Loop *L,
LoopInfo *LI,
1308 auto MapI = LoopToAliasSetMap.find(InnerL);
1312 if (MapI == LoopToAliasSetMap.end()) {
1318 if (CurAST !=
nullptr) {
1320 CurAST->
add(*InnerAST);
1328 LoopToAliasSetMap.erase(MapI);
1330 if (CurAST ==
nullptr)
1333 auto mergeLoop = [&](
Loop *
L) {
1340 for (
Loop *InnerL : RecomputeLoops)
1362 void LegacyLICMPass::deleteAnalysisValue(
Value *V,
Loop *L) {
1372 void LegacyLICMPass::deleteAnalysisLoop(
Loop *L) {
1378 LICM.getLoopToAliasSetMap().erase(L);
1395 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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
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.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
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.
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this load instruction.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
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...
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
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...
const std::vector< BlockT * > & getBlocks() const
Get a list of the basic blocks which make up this loop.
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.
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.
const std::vector< DomTreeNodeBase * > & getChildren() const
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...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
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...
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.
This class represents a no-op cast from one type to another.
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.
static cl::opt< bool > DisablePromotion("disable-licm-promotion", cl::Hidden, cl::init(false), cl::desc("Disable memory promotion in LICM pass"))
Memory promotion is enabled by default.
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.
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 ...
initializer< Ty > init(const Ty &Val)
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.
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...
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
static cl::opt< uint32_t > MaxNumUsesTraversed("licm-max-num-uses-traversed", cl::Hidden, cl::init(8), cl::desc("Max num uses visited for identifying load ""invariance in loop using invariant start (default = 8)"))
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
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...
static bool isLoadInvariantInLoop(LoadInst *LI, DominatorTree *DT, Loop *CurLoop)
LLVMContext & getContext() const
All values hold a context through their type.
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:
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
void add(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo)
These methods are used to add different types of instructions to the alias sets.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
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...
iterator find(ConstPtrType Ptr) const
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...
DomTreeNodeBase< NodeT > * getNode(NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
std::vector< BlockT * >::const_iterator block_iterator
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Represents analyses that only rely on functions' control flow.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
block_iterator block_end() const
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this store instruction.
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
user_iterator_impl< User > user_iterator
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)
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
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.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
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. ...
static IntegerType * getInt8Ty(LLVMContext &C)
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
A wrapper class for inspecting calls to intrinsic functions.
bool properlyDominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
properlyDominates - Returns true iff A dominates B and A != B.