80#define DEBUG_TYPE "loop-unroll"
83STATISTIC(NumCompletelyUnrolled,
"Number of loops completely unrolled");
84STATISTIC(NumUnrolled,
"Number of loops unrolled (completely or otherwise)");
85STATISTIC(NumUnrolledNotLatch,
"Number of loops unrolled without a conditional "
86 "latch (completely or otherwise)");
90 cl::desc(
"Allow runtime unrolled loops to be unrolled "
91 "with epilog instead of prolog."));
95 cl::desc(
"Verify domtree after unrolling"),
96#ifdef EXPENSIVE_CHECKS
105 cl::desc(
"Verify loopinfo after unrolling"),
106#ifdef EXPENSIVE_CHECKS
124 const std::vector<BasicBlock *> &
Blocks,
130 for (
Use &U :
I.operands()) {
131 if (
const auto *Def = dyn_cast<Instruction>(U)) {
153 assert(OldLoop &&
"Should (at least) be in the loop being unrolled!");
155 Loop *&NewLoop = NewLoops[OldLoop];
159 "Header should be first in RPO");
203 BasicBlock *PreHeader = L->getLoopPreheader();
205 assert(PreHeader && Header);
206 for (
const PHINode &PN : Header->phis()) {
207 if (isa<ConstantInt>(PN.getIncomingValueForBlock(PreHeader)))
223 if (SE && SimplifyIVs) {
229 while (!DeadInsts.
empty()) {
231 if (
Instruction *Inst = dyn_cast_or_null<Instruction>(V))
238 const DataLayout &
DL = L->getHeader()->getModule()->getDataLayout();
244 Inst.replaceAllUsesWith(V);
254 const APInt *C1, *C2;
256 auto *InnerI = dyn_cast<Instruction>(Inst.getOperand(0));
257 auto *InnerOBO = cast<OverflowingBinaryOperator>(Inst.getOperand(0));
260 Inst.setOperand(0,
X);
262 Inst.setHasNoUnsignedWrap(Inst.hasNoUnsignedWrap() &&
263 InnerOBO->hasNoUnsignedWrap());
264 Inst.setHasNoSignedWrap(Inst.hasNoSignedWrap() &&
265 InnerOBO->hasNoSignedWrap() &&
301 bool PreserveLCSSA,
Loop **RemainderLoop) {
302 assert(DT &&
"DomTree is required");
304 if (!L->getLoopPreheader()) {
305 LLVM_DEBUG(
dbgs() <<
" Can't unroll; loop preheader-insertion failed.\n");
309 if (!L->getLoopLatch()) {
310 LLVM_DEBUG(
dbgs() <<
" Can't unroll; loop exit-block-insertion failed.\n");
315 if (!L->isSafeToClone()) {
316 LLVM_DEBUG(
dbgs() <<
" Can't unroll; Loop body cannot be cloned.\n");
320 if (L->getHeader()->hasAddressTaken()) {
323 dbgs() <<
" Won't unroll loop: address of header block is taken.\n");
331 BasicBlock *Preheader = L->getLoopPreheader();
335 L->getExitBlocks(ExitBlocks);
336 std::vector<BasicBlock *> OriginalLoopBlocks = L->getBlocks();
340 unsigned EstimatedLoopInvocationWeight = 0;
341 std::optional<unsigned> OriginalTripCount =
346 if (MaxTripCount && ULO.
Count > MaxTripCount)
347 ULO.
Count = MaxTripCount;
351 unsigned TripMultiple;
352 unsigned BreakoutTrip;
359 L->getExitingBlocks(ExitingBlocks);
360 for (
auto *ExitingBlock : ExitingBlocks) {
363 auto *BI = dyn_cast<BranchInst>(ExitingBlock->getTerminator());
370 if (
Info.TripCount != 0) {
372 Info.TripMultiple = 0;
374 Info.BreakoutTrip =
Info.TripMultiple =
377 Info.ExitOnTrue = !L->contains(BI->getSuccessor(0));
378 Info.ExitingBlocks.push_back(ExitingBlock);
379 LLVM_DEBUG(
dbgs() <<
" Exiting block %" << ExitingBlock->getName()
380 <<
": TripCount=" <<
Info.TripCount
381 <<
", TripMultiple=" <<
Info.TripMultiple
382 <<
", BreakoutTrip=" <<
Info.BreakoutTrip <<
"\n");
388 const bool CompletelyUnroll = ULO.
Count == MaxTripCount;
390 const bool PreserveOnlyFirst = CompletelyUnroll && MaxOrZero;
394 if (CompletelyUnroll)
403 bool NeedToFixLCSSA =
404 PreserveLCSSA && CompletelyUnroll &&
418 bool LatchIsExiting = L->isLoopExiting(LatchBlock);
419 if (!LatchBI || (LatchBI->isConditional() && !LatchIsExiting)) {
421 dbgs() <<
"Can't unroll; a conditional latch must exit the loop");
422 return LoopUnrollResult::Unmodified;
430 bool HasConvergent =
false;
431 for (
auto &BB : L->blocks())
433 if (
auto *CB = dyn_cast<CallBase>(&
I))
434 HasConvergent |= CB->isConvergent();
436 "Can't runtime unroll if loop contains a convergent operation.");
439 bool EpilogProfitability =
447 PreserveLCSSA, RemainderLoop)) {
452 "generated when assuming runtime trip count\n");
453 return LoopUnrollResult::Unmodified;
459 if (CompletelyUnroll) {
460 LLVM_DEBUG(
dbgs() <<
"COMPLETELY UNROLLING loop %" << Header->getName()
461 <<
" with trip count " << ULO.
Count <<
"!\n");
466 <<
"completely unrolled loop with "
467 << NV(
"UnrollCount", ULO.
Count) <<
" iterations";
470 LLVM_DEBUG(
dbgs() <<
"UNROLLING loop %" << Header->getName() <<
" by "
480 Diag <<
"unrolled loop by a factor of " << NV(
"UnrollCount", ULO.
Count);
482 Diag <<
" with run-time trip count";
505 ++NumUnrolledNotLatch;
510 std::vector<PHINode*> OrigPHINode;
512 OrigPHINode.push_back(cast<PHINode>(
I));
515 std::vector<BasicBlock *> Headers;
516 std::vector<BasicBlock *> Latches;
517 Headers.push_back(Header);
518 Latches.push_back(LatchBlock);
530 std::vector<BasicBlock*> UnrolledLoopBlocks = L->getBlocks();
537 for (
Loop *SubLoop : *L)
538 LoopsToSimplify.
insert(SubLoop);
542 if (Header->getParent()->shouldEmitDebugInfoForProfiling() &&
546 if (!
I.isDebugOrPseudoInst())
548 auto NewDIL = DIL->cloneByMultiplyingDuplicationFactor(ULO.
Count);
550 I.setDebugLoc(*NewDIL);
553 <<
"Failed to create new discriminator: "
554 << DIL->getFilename() <<
" Line: " << DIL->getLine());
565 auto BlockInsertPt = std::next(LatchBlock->
getIterator());
566 for (
unsigned It = 1; It != ULO.
Count; ++It) {
574 Header->getParent()->insert(BlockInsertPt, New);
577 "Header should not be in a sub-loop");
581 LoopsToSimplify.
insert(NewLoops[OldLoop]);
586 for (
PHINode *OrigPHI : OrigPHINode) {
587 PHINode *NewPHI = cast<PHINode>(VMap[OrigPHI]);
589 if (
Instruction *InValI = dyn_cast<Instruction>(InVal))
590 if (It > 1 && L->contains(InValI))
591 InVal = LastValueMap[InValI];
592 VMap[OrigPHI] = InVal;
597 LastValueMap[*BB] = New;
600 LastValueMap[VI->first] = VI->second;
604 if (L->contains(Succ))
607 Value *Incoming =
PHI.getIncomingValueForBlock(*BB);
609 if (It != LastValueMap.
end())
611 PHI.addIncoming(Incoming, New);
618 Headers.push_back(New);
619 if (*BB == LatchBlock)
620 Latches.push_back(New);
624 auto ExitInfoIt = ExitInfos.
find(*BB);
625 if (ExitInfoIt != ExitInfos.
end())
626 ExitInfoIt->second.ExitingBlocks.push_back(New);
629 UnrolledLoopBlocks.push_back(New);
638 auto BBDomNode = DT->
getNode(*BB);
639 auto BBIDom = BBDomNode->
getIDom();
640 BasicBlock *OriginalBBIDom = BBIDom->getBlock();
642 New, cast<BasicBlock>(LastValueMap[cast<Value>(OriginalBBIDom)]));
650 if (
auto *II = dyn_cast<AssumeInst>(&
I))
657 std::string ext = (
Twine(
"It") +
Twine(It)).str();
659 Header->getContext(), ext);
664 for (
PHINode *PN : OrigPHINode) {
665 if (CompletelyUnroll) {
666 PN->replaceAllUsesWith(PN->getIncomingValueForBlock(Preheader));
667 PN->eraseFromParent();
668 }
else if (ULO.
Count > 1) {
669 Value *InVal = PN->removeIncomingValue(LatchBlock,
false);
672 if (
Instruction *InValI = dyn_cast<Instruction>(InVal)) {
673 if (L->contains(InValI))
674 InVal = LastValueMap[InVal];
676 assert(Latches.back() == LastValueMap[LatchBlock] &&
"bad last latch");
677 PN->addIncoming(InVal, Latches.back());
683 for (
unsigned i = 0, e = Latches.size(); i != e; ++i) {
684 unsigned j = (i + 1) % e;
685 Latches[i]->getTerminator()->replaceSuccessorWith(Headers[i], Headers[j]);
693 for (
auto *BB : OriginalLoopBlocks) {
694 auto *BBDomNode = DT->
getNode(BB);
696 for (
auto *ChildDomNode : BBDomNode->children()) {
697 auto *ChildBB = ChildDomNode->getBlock();
698 if (!L->contains(ChildBB))
706 for (
auto *ChildBB : ChildrenToUpdate)
712 DT->
verify(DominatorTree::VerificationLevel::Fast));
715 auto SetDest = [&](
BasicBlock *Src,
bool WillExit,
bool ExitOnTrue) {
716 auto *Term = cast<BranchInst>(Src->getTerminator());
717 const unsigned Idx = ExitOnTrue ^ WillExit;
726 Term->eraseFromParent();
728 DTUpdates.
emplace_back(DominatorTree::Delete, Src, DeadSucc);
731 auto WillExit = [&](
const ExitInfo &
Info,
unsigned i,
unsigned j,
732 bool IsLatch) -> std::optional<bool> {
733 if (CompletelyUnroll) {
734 if (PreserveOnlyFirst) {
742 if (
Info.TripCount && j !=
Info.TripCount)
750 if (IsLatch && j != 0)
755 if (j !=
Info.BreakoutTrip &&
756 (
Info.TripMultiple == 0 || j %
Info.TripMultiple != 0)) {
766 for (
auto &Pair : ExitInfos) {
767 ExitInfo &
Info = Pair.second;
768 for (
unsigned i = 0, e =
Info.ExitingBlocks.size(); i != e; ++i) {
770 unsigned j = (i + 1) % e;
771 bool IsLatch = Pair.first == LatchBlock;
772 std::optional<bool> KnownWillExit = WillExit(
Info, i, j, IsLatch);
773 if (!KnownWillExit) {
774 if (!
Info.FirstExitingBlock)
775 Info.FirstExitingBlock =
Info.ExitingBlocks[i];
784 if (*KnownWillExit && !IsLatch) {
785 if (!
Info.FirstExitingBlock)
786 Info.FirstExitingBlock =
Info.ExitingBlocks[i];
790 SetDest(
Info.ExitingBlocks[i], *KnownWillExit,
Info.ExitOnTrue);
796 if (ExitingBlocks.
size() == 1 && ExitInfos.
size() == 1) {
804 auto &[OriginalExit,
Info] = *ExitInfos.
begin();
805 if (!
Info.FirstExitingBlock)
806 Info.FirstExitingBlock =
Info.ExitingBlocks.back();
808 if (L->contains(
C->getBlock()))
817 if (!LatchIsExiting && CompletelyUnroll) {
827 BranchInst *Term = dyn_cast<BranchInst>(Latch->getTerminator());
829 (CompletelyUnroll && !LatchIsExiting && Latch == Latches.back())) &&
830 "Need a branch as terminator, except when fully unrolling with "
831 "unconditional latch");
832 if (Term && Term->isUnconditional()) {
838 DTUToUse ?
nullptr : DT)) {
840 std::replace(Latches.begin(), Latches.end(), Dest, Fold);
851 DT->
verify(DominatorTree::VerificationLevel::Fast));
858 NumCompletelyUnrolled += CompletelyUnroll;
861 Loop *OuterL = L->getParentLoop();
863 if (CompletelyUnroll) {
867 }
else if (OriginalTripCount) {
871 EstimatedLoopInvocationWeight);
886 if (PreserveLCSSA && OuterL && CompletelyUnroll && !NeedToFixLCSSA)
896 if (NeedToFixLCSSA) {
901 Loop *FixLCSSALoop = OuterL;
902 if (!FixLCSSALoop->
contains(LatchLoop))
907 }
else if (PreserveLCSSA) {
909 "Loops should be in LCSSA form after loop-unroll.");
914 simplifyLoop(OuterL, DT, LI, SE, AC,
nullptr, PreserveLCSSA);
917 for (
Loop *SubLoop : LoopsToSimplify)
918 simplifyLoop(SubLoop, DT, LI, SE, AC,
nullptr, PreserveLCSSA);
921 return CompletelyUnroll ? LoopUnrollResult::FullyUnrolled
922 : LoopUnrollResult::PartiallyUnrolled;
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
DenseMap< Block *, BlockRelaxAux > Blocks
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file defines a set of templates that efficiently compute a dominator tree over a generic graph.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
static bool needToInsertPhisForLCSSA(Loop *L, const std::vector< BasicBlock * > &Blocks, LoopInfo *LI)
Check if unrolling created a situation where we need to insert phi nodes to preserve LCSSA form.
static bool isEpilogProfitable(Loop *L)
The function chooses which type of unroll (epilog or prolog) is more profitabale.
static cl::opt< bool > UnrollRuntimeEpilog("unroll-runtime-epilog", cl::init(false), cl::Hidden, cl::desc("Allow runtime unrolled loops to be unrolled " "with epilog instead of prolog."))
static cl::opt< bool > UnrollVerifyLoopInfo("unroll-verify-loopinfo", cl::Hidden, cl::desc("Verify loopinfo after unrolling"), cl::init(false))
static cl::opt< bool > UnrollVerifyDomtree("unroll-verify-domtree", cl::Hidden, cl::desc("Verify domtree after unrolling"), cl::init(false))
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This defines the Use class.
Class for arbitrary precision integers.
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
A cache of @llvm.assume calls within a function.
void registerAssumption(AssumeInst *CI)
Add an @llvm.assume intrinsic to this function's cache.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
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 if the block is well formed or null if the block is not well forme...
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
A parsed version of the target data layout string in and methods for querying it.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
iterator_range< iterator > children()
DomTreeNodeBase * getIDom() const
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
DominatorTree & getDomTree()
Flush DomTree updates and return DomTree.
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.
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...
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
BlockT * getHeader() const
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
void addChildLoop(LoopT *NewChild)
Add the specified loop to be a child of this loop.
LoopT * getParentLoop() const
Return the parent loop if it exists or nullptr for top level loops.
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
void perform(const LoopInfo *LI)
Traverse the loop blocks and store the DFS result.
RPOIterator endRPO() const
void verify(const DominatorTreeBase< BlockT, false > &DomTree) const
void addTopLevelLoop(LoopT *New)
This adds the specified loop to the collection of top-level loops.
LoopT * AllocateLoop(ArgsTy &&...Args)
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.
void erase(Loop *L)
Update LoopInfo after removing the last backedge from a loop.
Represents a single loop in the control flow graph.
bool isLCSSAForm(const DominatorTree &DT, bool IgnoreTokens=true) const
Return true if the Loop is in LCSSA form.
const MDOperand & getOperand(unsigned I) const
unsigned getNumOperands() const
Return number of MDNode operands.
StringRef getString() const
Value * getIncomingValueForBlock(const BasicBlock *BB) const
The main scalar evolution driver.
unsigned getSmallConstantTripMultiple(const Loop *L, const SCEV *ExitCount)
Returns the largest constant divisor of the trip count as a normal unsigned value,...
unsigned getSmallConstantMaxTripCount(const Loop *L)
Returns the upper bound of the loop trip count as a normal unsigned value.
bool isBackedgeTakenCountMaxOrZero(const Loop *L)
Return true if the backedge taken count is either the value returned by getConstantMaxBackedgeTakenCo...
void forgetTopmostLoop(const Loop *L)
void forgetValue(Value *V)
This method should be called by the client when it has changed a value in a way that may effect its v...
void forgetBlockAndLoopDispositions(Value *V=nullptr)
Called when the client has changed the disposition of values in a loop or block.
unsigned getSmallConstantTripCount(const Loop *L)
Returns the exact trip count of the loop if we can compute it, and the result is a small constant.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
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.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A Use represents the edge between a Value definition and its users.
iterator find(const KeyT &Val)
LLVM Value Representation.
self_iterator getIterator()
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
bool match(Val *V, const Pattern &P)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, AssumptionCache *AC, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
Simplify each loop in a loop nest recursively.
std::optional< unsigned > getLoopEstimatedTripCount(Loop *L, unsigned *EstimatedLoopInvocationWeight=nullptr)
Returns a loop's estimated trip count based on branch weight metadata.
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.
auto successors(const MachineBasicBlock *BB)
bool formLCSSARecursively(Loop &L, const DominatorTree &DT, const LoopInfo *LI, ScalarEvolution *SE)
Put a loop nest into LCSSA form.
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...
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
cl::opt< bool > EnableFSDiscriminator
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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.
BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, DebugInfoFinder *DIFinder=nullptr)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT, LoopInfo *LI, const TargetTransformInfo *TTI, SmallVectorImpl< WeakTrackingVH > &Dead)
SimplifyLoopIVs - Simplify users of induction variables within this loop.
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
LoopUnrollResult
Represents the result of a UnrollLoop invocation.
@ Unmodified
The loop was not modified.
unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
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.
void erase_value(Container &C, ValueType V)
Wrapper function to remove a value from a container:
bool setLoopEstimatedTripCount(Loop *L, unsigned EstimatedTripCount, unsigned EstimatedLoopInvocationWeight)
Set a loop's branch weight metadata to reflect that loop has EstimatedTripCount iterations and Estima...
void cloneAndAdaptNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, ArrayRef< BasicBlock * > NewBlocks, LLVMContext &Context, StringRef Ext)
Clone the specified noalias decl scopes.
void remapInstructionsInBlocks(ArrayRef< BasicBlock * > Blocks, ValueToValueMapTy &VMap)
Remaps instructions in Blocks using the mapping in VMap.
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...
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)
Unroll the given loop by Count.
void identifyNoAliasScopesToClone(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< MDNode * > &NoAliasDeclScopes)
Find the 'llvm.experimental.noalias.scope.decl' intrinsics in the specified basic blocks and extract ...
void simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, const TargetTransformInfo *TTI)
Perform some cleanup and simplifications on loops after unrolling.
MDNode * GetUnrollMetadata(MDNode *LoopID, StringRef Name)
Given an llvm.loop loop id metadata node, returns the loop hint metadata node with the given name (fo...
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, Loop **ResultLoop=nullptr)
Insert code in the prolog/epilog code when unrolling a loop with a run-time trip-count.
bool AllowExpensiveTripCount