46#define DEBUG_TYPE "loop-unroll"
49 "Number of loops unrolled with run-time trip counts");
52 cl::desc(
"Allow runtime unrolling for loops with multiple exits, when "
53 "epilog is generated"));
56 cl::desc(
"Assume the non latch exit block to be predictable"));
101 assert(Latch &&
"Loop must have a latch");
110 for (
PHINode &PN : Succ->phis()) {
122 if (L->contains(&PN)) {
124 NewPN->
addIncoming(PN.getIncomingValueForBlock(NewPreHeader),
131 Value *V = PN.getIncomingValueForBlock(Latch);
133 if (L->contains(
I)) {
144 if (L->contains(&PN))
145 PN.setIncomingValueForBlock(NewPreHeader, NewPN);
147 PN.addIncoming(NewPN, PrologExit);
161 nullptr, PreserveLCSSA);
176 B.CreateICmpULT(BECount, ConstantInt::get(BECount->
getType(),
Count - 1));
180 nullptr, PreserveLCSSA);
182 MDNode *BranchWeights =
nullptr;
188 B.CreateCondBr(BrLoopExit, OriginalLoopLatchExit, NewPreHeader,
222 if (OriginalLoopProb.
isOne())
223 return OriginalLoopProb;
231 return ProbOneNotTooMany / ProbNotTooMany;
263 assert(Latch &&
"Loop must have a latch");
296 assert(PN.hasOneUse() &&
"The phi should have 1 use");
298 assert(EpilogPN->
getParent() == Exit &&
"EpilogPN should be in Exit block");
300 Value *V = PN.getIncomingValueForBlock(Latch);
302 if (
I && L->contains(
I))
310 "EpilogPN should have EpilogPreHeader incoming block");
327 if (!L->contains(Succ))
334 assert(Succ == L->getHeader() &&
335 "Expect the only in-loop successor of latch to be the loop header");
337 for (
PHINode &PN : Succ->phis()) {
340 PN.getName() +
".unr");
343 NewPN0->
addIncoming(PN.getIncomingValueForBlock(Latch), Latch);
347 PN.getName() +
".epil.init");
350 NewPN1->
addIncoming(PN.getIncomingValueForBlock(NewPreHeader), PreHeader);
364 Value *BrLoopExit =
B.CreateIsNotNull(ModVal,
"lcmp.mod");
365 assert(Exit &&
"Loop must have a single exit block only");
371 MDNode *BranchWeights =
nullptr;
379 B.CreateCondBr(BrLoopExit, EpilogPreHeader, Exit, BranchWeights);
393 Value *ModIsNotNull = B2.CreateIsNotNull(ModVal,
"lcmp.mod");
405 const bool UseEpilogRemainder,
406 const bool UnrollRemainder,
BasicBlock *InsertTop,
408 std::vector<BasicBlock *> &NewBlocks,
411 std::optional<unsigned> OriginalTripCount,
413 StringRef suffix = UseEpilogRemainder ?
"epil" :
"prol";
419 Loop *ParentLoop = L->getParentLoop();
421 NewLoops[ParentLoop] = ParentLoop;
427 NewBlocks.push_back(NewBB);
451 VMap.
erase((*BB)->getTerminator());
461 auto *Zero = ConstantInt::get(NewIdx->
getType(), 0);
462 auto *One = ConstantInt::get(NewIdx->
getType(), 1);
464 Builder.CreateAdd(NewIdx, One, NewIdx->
getName() +
".next");
465 Value *IdxCmp = Builder.CreateICmpNE(IdxNext, NewIter, NewIdx->
getName() +
".cmp");
466 MDNode *BranchWeights =
nullptr;
467 if ((OriginalLoopProb.
isUnknown() || !UseEpilogRemainder) &&
476 BackEdgeWeight = (
Count - 2) / 2;
487 Builder.CreateCondBr(IdxCmp, FirstLoopBB, InsertBot, BranchWeights);
488 if (!OriginalLoopProb.
isUnknown() && UseEpilogRemainder) {
492 double FreqRemIters = 1;
495 for (
unsigned N =
Count - 2;
N >= 1; --
N) {
497 FreqRemIters += ProbReaching.
toDouble();
526 Loop *NewLoop = NewLoops[L];
527 assert(NewLoop &&
"L should have been cloned");
529 if (OriginalTripCount && UseEpilogRemainder)
533 if (!UnrollRemainder)
542 bool UseEpilogRemainder) {
560 L->getExitingBlocks(ExitingBlocks);
561 if (ExitingBlocks.
size() > 2)
565 if (OtherExits.
size() == 0)
568 if (OtherExits.
size() != 1)
580 assert(LatchBB &&
"Expected loop to have a latch");
582 (ExitingBlocks[0] == LatchBB) ? ExitingBlocks[1] : ExitingBlocks[0];
587 if (!BranchProb.isUnknown()) {
588 auto Threshold =
TTI->getPredictableBranchThreshold().getCompl();
589 return BranchProb < Threshold;
595 return OtherExits[0]->getPostdominatingDeoptimizeCall();
620 return B.CreateAnd(TripCount,
Count - 1,
"xtraiter");
625 Value *ModValTmp =
B.CreateURem(BECount, CountC);
626 Value *ModValAdd =
B.CreateAdd(ModValTmp,
627 ConstantInt::get(ModValTmp->
getType(), 1));
630 return B.CreateURem(ModValAdd, CountC,
"xtraiter");
673 Loop *L,
unsigned Count,
bool AllowExpensiveTripCount,
674 bool UseEpilogRemainder,
bool UnrollRemainder,
bool ForgetAllSCEV,
677 unsigned SCEVExpansionBudget,
bool RuntimeUnrollMultiExit,
678 Loop **ResultLoop, std::optional<unsigned> OriginalTripCount,
682 LLVM_DEBUG(UseEpilogRemainder ?
dbgs() <<
"Using epilog remainder.\n"
683 :
dbgs() <<
"Using prolog remainder.\n");
686 if (!L->isLoopSimplifyForm()) {
701 <<
"Loop latch not terminated by a conditional branch.\n");
705 unsigned ExitIndex = LatchBR->
getSuccessor(0) == Header ? 1 : 0;
708 if (L->contains(LatchExit)) {
713 <<
"One of the loop latch successors must be the exit block.\n");
719 L->getUniqueNonLatchExitBlocks(OtherExits);
722 if (!L->getExitingBlock() || OtherExits.
size()) {
735 if (!RuntimeUnrollMultiExit &&
737 L,
TTI, OtherExits, LatchExit, UseEpilogRemainder)) {
739 "multi-exit unrolling not enabled!\n");
764 const SCEV *TripCountSC =
771 BasicBlock *PreHeader = L->getLoopPreheader();
774 if (!AllowExpensiveTripCount &&
777 LLVM_DEBUG(
dbgs() <<
"High cost for expanding trip count scev!\n");
786 <<
"Count failed constraint on overflow trip count calculation.\n");
804 if (UseEpilogRemainder) {
811 nullptr, PreserveLCSSA);
816 NewExitTerminator->
setDebugLoc(Header->getTerminator()->getDebugLoc());
818 EpilogPreHeader =
SplitBlock(NewExit, NewExitTerminator, DT, LI);
819 EpilogPreHeader->
setName(Header->getName() +
".epil.preheader");
827 if (
auto *ParentL = L->getParentLoop())
828 if (LI->getLoopFor(LatchExit) != ParentL) {
829 LI->removeBlock(NewExit);
830 ParentL->addBasicBlockToLoop(NewExit, *LI);
831 LI->removeBlock(EpilogPreHeader);
832 ParentL->addBasicBlockToLoop(EpilogPreHeader, *LI);
838 PrologPreHeader =
SplitEdge(PreHeader, Header, DT, LI);
839 PrologPreHeader->
setName(Header->getName() +
".prol.preheader");
842 PrologExit->
setName(Header->getName() +
".prol.loopexit");
876 TripCount =
B.CreateFreeze(TripCount);
889 UseEpilogRemainder ?
B.CreateICmpULT(BECount,
890 ConstantInt::get(BECount->
getType(),
892 B.CreateIsNotNull(ModVal,
"lcmp.mod");
894 UseEpilogRemainder ? EpilogPreHeader : PrologPreHeader;
895 BasicBlock *UnrollingLoop = UseEpilogRemainder ? NewPreHeader : PrologExit;
897 MDNode *BranchWeights =
nullptr;
898 if ((OriginalLoopProb.
isUnknown() || !UseEpilogRemainder) &&
905 B.CreateCondBr(BranchVal, RemainderLoop, UnrollingLoop, BranchWeights);
906 if (!OriginalLoopProb.
isUnknown() && UseEpilogRemainder) {
917 if (UseEpilogRemainder)
933 std::vector<BasicBlock *> NewBlocks;
939 BasicBlock *InsertBot = UseEpilogRemainder ? LatchExit : PrologExit;
940 BasicBlock *InsertTop = UseEpilogRemainder ? EpilogPreHeader : PrologPreHeader;
941 Loop *remainderLoop =
942 CloneLoopBlocks(L, ModVal, UseEpilogRemainder, UnrollRemainder, InsertTop,
943 InsertBot, NewPreHeader, NewBlocks, LoopBlocks, VMap, DT,
944 LI,
Count, OriginalTripCount, OriginalLoopProb);
947 F->splice(InsertBot->
getIterator(),
F, NewBlocks[0]->getIterator(),
F->end());
953 for (
auto *BB : OtherExits) {
957 for (
PHINode &PN : BB->phis()) {
958 unsigned oldNumOperands = PN.getNumIncomingValues();
961 for (
unsigned i = 0; i < oldNumOperands; i++){
962 auto *PredBB =PN.getIncomingBlock(i);
966 if (!L->contains(PredBB))
971 auto *V = PN.getIncomingValue(i);
978#if defined(EXPENSIVE_CHECKS) && !defined(NDEBUG)
981 "Breaks the definition of dedicated exits!");
993 if (DT && !L->getExitingBlock()) {
999 for (
auto *BB : L->blocks()) {
1000 auto *DomNodeBB = DT->
getNode(BB);
1001 for (
auto *DomChild : DomNodeBB->children()) {
1002 auto *DomChildBB = DomChild->getBlock();
1003 if (!L->contains(LI->
getLoopFor(DomChildBB)) &&
1004 DomChildBB->getUniquePredecessor() != BB)
1008 for (
auto *BB : ChildrenToUpdate)
1030 Module *M = BB->getModule();
1039 if (UseEpilogRemainder) {
1042 ConnectEpilog(L, ModVal, NewExit, LatchExit, PreHeader, EpilogPreHeader,
1043 NewPreHeader, VMap, DT, LI, PreserveLCSSA, *SE,
Count, *AC,
1051 Value *TestVal = B2.CreateSub(TripCount, ModVal,
"unroll_iter");
1055 B2.SetInsertPoint(LatchBR);
1056 auto *Zero = ConstantInt::get(NewIdx->
getType(), 0);
1057 auto *One = ConstantInt::get(NewIdx->
getType(), 1);
1058 Value *IdxNext = B2.CreateAdd(NewIdx, One, NewIdx->
getName() +
".next");
1060 Value *IdxCmp = B2.CreateICmp(Pred, IdxNext, TestVal, NewIdx->
getName() +
".ncmp");
1068 NewPreHeader, VMap, DT, LI, PreserveLCSSA, *SE);
1076#if defined(EXPENSIVE_CHECKS) && !defined(NDEBUG)
1078 assert(DT->
verify(DominatorTree::VerificationLevel::Full));
1084 if (
Count == 2 && DT && LI && SE) {
1091 remainderLoop =
nullptr;
1094 const DataLayout &
DL = L->getHeader()->getDataLayout();
1100 Inst.replaceAllUsesWith(V);
1112 assert(ExitBB &&
"required after breaking cond br backedge");
1120 if (OtherExits.
size() > 0) {
1131 if (remainderLoop && UnrollRemainder) {
1141 "A loop with a convergence heart does not allow runtime unrolling.");
1142 UnrollResult =
UnrollLoop(remainderLoop, ULO, LI, SE, DT, AC,
TTI,
1143 nullptr, PreserveLCSSA);
1147 *ResultLoop = remainderLoop;
1148 NumRuntimeUnrolled++;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Module.h This file contains the declarations for the Module class.
static void ConnectEpilog(Loop *L, Value *ModVal, BasicBlock *NewExit, BasicBlock *Exit, BasicBlock *PreHeader, BasicBlock *EpilogPreHeader, BasicBlock *NewPreHeader, ValueToValueMapTy &VMap, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA, ScalarEvolution &SE, unsigned Count, AssumptionCache &AC, BranchProbability OriginalLoopProb)
Connect the unrolling epilog code to the original loop.
static const uint32_t UnrolledLoopHeaderWeights[]
static Value * CreateTripRemainder(IRBuilder<> &B, Value *BECount, Value *TripCount, unsigned Count)
Calculate ModVal = (BECount + 1) % Count on the abstract integer domain accounting for the possibilit...
static Loop * CloneLoopBlocks(Loop *L, Value *NewIter, const bool UseEpilogRemainder, const bool UnrollRemainder, BasicBlock *InsertTop, BasicBlock *InsertBot, BasicBlock *Preheader, std::vector< BasicBlock * > &NewBlocks, LoopBlocksDFS &LoopBlocks, ValueToValueMapTy &VMap, DominatorTree *DT, LoopInfo *LI, unsigned Count, std::optional< unsigned > OriginalTripCount, BranchProbability OriginalLoopProb)
Create a clone of the blocks in a loop and connect them together.
static cl::opt< bool > UnrollRuntimeOtherExitPredictable("unroll-runtime-other-exit-predictable", cl::init(false), cl::Hidden, cl::desc("Assume the non latch exit block to be predictable"))
static bool canProfitablyRuntimeUnrollMultiExitLoop(Loop *L, const TargetTransformInfo *TTI, SmallVectorImpl< BasicBlock * > &OtherExits, BasicBlock *LatchExit, bool UseEpilogRemainder)
Returns true if we can profitably unroll the multi-exit loop L.
static const uint32_t EpilogHeaderWeights[]
static cl::opt< bool > UnrollRuntimeMultiExit("unroll-runtime-multi-exit", cl::init(false), cl::Hidden, cl::desc("Allow runtime unrolling for loops with multiple exits, when " "epilog is generated"))
static BranchProbability probOfNextInRemainder(BranchProbability OriginalLoopProb, unsigned N)
Assume, due to our position in the remainder loop or its guard, anywhere from 0 to N more iterations ...
static void ConnectProlog(Loop *L, Value *BECount, unsigned Count, BasicBlock *PrologExit, BasicBlock *OriginalLoopLatchExit, BasicBlock *PreHeader, BasicBlock *NewPreHeader, ValueToValueMapTy &VMap, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA, ScalarEvolution &SE)
Connect the unrolling prolog code to the original loop.
This file contains the declarations for profiling metadata utility functions.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This represents the llvm.assume intrinsic.
A cache of @llvm.assume calls within a function.
LLVM_ABI void registerAssumption(AssumeInst *CI)
Add an @llvm.assume intrinsic to this function's cache.
LLVM Basic Block Representation.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
static LLVM_ABI BranchProbability getBranchProbability(uint64_t Numerator, uint64_t Denominator)
static constexpr BranchProbability getOne()
LLVM_ABI BranchProbability pow(unsigned N) const
Compute pow(Probability, N).
BranchProbability getCompl() const
Conditional Branch instruction.
void setCondition(Value *V)
BasicBlock * getSuccessor(unsigned i) const
This is an important base class in LLVM.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
A parsed version of the target data layout string in and methods for querying it.
DomTreeNodeBase * getIDom() const
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI Instruction * findNearestCommonDominator(Instruction *I1, Instruction *I2) const
Find the nearest instruction I that dominates both I1 and I2, in the sense that a result produced bef...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within this loop.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
Store the result of a depth first search within basic blocks contained by a single loop.
RPOIterator beginRPO() const
Reverse iterate over the cached postorder blocks.
std::vector< BasicBlock * >::const_reverse_iterator RPOIterator
LLVM_ABI void perform(const LoopInfo *LI)
Traverse the loop blocks and store the DFS result.
RPOIterator endRPO() const
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
bool replacementPreservesLCSSAForm(Instruction *From, Value *To)
Returns true if replacing From with To everywhere is guaranteed to preserve LCSSA form.
Represents a single loop in the control flow graph.
void setLoopAlreadyUnrolled()
Add llvm.loop.unroll.disable to this loop's loop id metadata.
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
A Module instance is used to store all the information related to an LLVM module.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
void setIncomingValueForBlock(const BasicBlock *BB, Value *V)
Set every incoming value(s) for block BB to V.
void setIncomingBlock(unsigned i, BasicBlock *BB)
void setIncomingValue(unsigned i, Value *V)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This class uses information about analyze scalars to rewrite expressions in canonical form.
bool isHighCostExpansion(ArrayRef< const SCEV * > Exprs, Loop *L, unsigned Budget, const TargetTransformInfo *TTI, const Instruction *At)
Return true for expressions that can't be evaluated at runtime within given Budget.
LLVM_ABI Value * expandCodeFor(SCEVUse SH, Type *Ty, BasicBlock::iterator I)
Insert code to directly compute the specified SCEV expression into the program.
This class represents an analyzed expression in the program.
Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
LLVM_ABI const SCEV * getConstant(ConstantInt *V)
bool loopHasNoAbnormalExits(const Loop *L)
Return true if the loop has no abnormal exits.
LLVM_ABI void forgetTopmostLoop(const Loop *L)
LLVM_ABI void forgetLcssaPhiWithNewPredecessor(Loop *L, PHINode *V)
Forget LCSSA phi node V of loop L to which a new predecessor was added, such that it may no longer be...
LLVM_ABI const SCEV * getExitCount(const Loop *L, const BasicBlock *ExitingBlock, ExitCountKind Kind=Exact)
Return the number of times the backedge executes before the given exit would be taken; if not exactly...
LLVM_ABI const SCEV * getAddExpr(SmallVectorImpl< SCEVUse > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
bool erase(const KeyT &Val)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
const ParentTy * getParent() const
self_iterator getIterator()
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI BranchProbability getBranchProbability(CondBrInst *B, bool ForFirstTarget)
Based on branch weight metadata, return either:
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
LLVM_ABI BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, bool MapAtoms=true)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
SmallDenseMap< const Loop *, Loop *, 4 > NewLoopsMap
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
LLVM_ABI bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
void RemapDbgRecordRange(Module *M, iterator_range< DbgRecordIterator > Range, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataPredicate *IdentityMD=nullptr)
Remap the Values used in the DbgRecords Range using the value map VM.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI void setBranchProbability(CondBrInst *B, BranchProbability P, bool ForFirstTarget)
Set branch weight metadata for B to indicate that P and 1 - P are the probabilities of control flowin...
LLVM_ABI CallBase * getLoopConvergenceHeart(const Loop *TheLoop)
Find the convergence heart of the loop.
@ RF_IgnoreMissingLocals
If this flag is set, the remapper ignores missing function-local entries (Argument,...
@ RF_NoModuleLevelChanges
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ Unmodified
The loop was not modified.
@ FullyUnrolled
The loop was fully unrolled into straight-line code.
LLVM_ABI void breakLoopBackedge(Loop *L, DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI, MemorySSA *MSSA)
Remove the backedge of the specified loop.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
LLVM_ABI bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, MemoryDependenceResults *MemDep=nullptr, bool PredecessorWithTwoSuccessors=false, DominatorTree *DT=nullptr)
Attempts to merge a block into its predecessor, if possible.
LLVM_ABI BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the specified block at the specified instruction.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
LLVM_ABI bool formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
Ensure that all exit blocks of the loop are dedicated exits.
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataPredicate *IdentityMD=nullptr)
Convert the instruction operands from referencing the current values into those specified by VM.
LLVM_ABI bool isGuaranteedNotToBeUndefOrPoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Return true if this function can prove that V does not have undef bits and is never poison.
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
LLVM_ABI bool setLoopEstimatedTripCount(Loop *L, unsigned EstimatedTripCount, std::optional< unsigned > EstimatedLoopInvocationWeight=std::nullopt)
Set llvm.loop.estimated_trip_count with the value EstimatedTripCount in the loop metadata of L.
LLVM_ABI const Loop * addClonedBlockToLoopInfo(BasicBlock *OriginalBB, BasicBlock *ClonedBB, LoopInfo *LI, NewLoopsMap &NewLoops)
Adds ClonedBB to LoopInfo, creates a new loop for ClonedBB if necessary and adds a mapping from the o...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI bool hasBranchWeightMD(const Instruction &I)
Checks if an instructions has Branch Weight Metadata.
LLVM_ABI BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the edge connecting the specified blocks, and return the newly created basic block between From...
LLVM_ABI bool UnrollRuntimeLoopRemainder(Loop *L, unsigned Count, bool AllowExpensiveTripCount, bool UseEpilogRemainder, bool UnrollRemainder, bool ForgetAllSCEV, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, const TargetTransformInfo *TTI, bool PreserveLCSSA, unsigned SCEVExpansionBudget, bool RuntimeUnrollMultiExit, Loop **ResultLoop=nullptr, std::optional< unsigned > OriginalTripCount=std::nullopt, BranchProbability OriginalLoopProb=BranchProbability::getUnknown())
Insert code in the prolog/epilog code when unrolling a loop with a run-time trip-count.
LLVM_ABI LoopUnrollResult UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, const llvm::TargetTransformInfo *TTI, OptimizationRemarkEmitter *ORE, bool PreserveLCSSA, Loop **RemainderLoop=nullptr, AAResults *AA=nullptr)
Unroll the given loop by Count.
bool AllowExpensiveTripCount