LLVM 24.0.0git
LoopDeletion.cpp
Go to the documentation of this file.
1//===- LoopDeletion.cpp - Dead Loop Deletion Pass ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Dead Loop Deletion Pass. This pass is responsible
10// for eliminating loops with non-infinite computable trip counts that have no
11// side effects or volatile instructions, and do not contribute to the
12// computation of the function's return value.
13//
14//===----------------------------------------------------------------------===//
15
17#include "ScalarOptions.h"
19#include "llvm/ADT/Statistic.h"
20#include "llvm/Analysis/CFG.h"
28#include "llvm/IR/Dominators.h"
29
33
34using namespace llvm;
35
36#define DEBUG_TYPE "loop-delete"
37
38STATISTIC(NumDeleted, "Number of loops deleted");
39STATISTIC(NumBackedgesBroken,
40 "Number of loops for which we managed to break the backedge");
41
47
55
56/// Determines if a loop is dead.
57///
58/// This assumes that we've already checked for unique exit and exiting blocks,
59/// and that the code is in LCSSA form.
60static bool isLoopDead(Loop *L, ScalarEvolution &SE,
61 SmallVectorImpl<BasicBlock *> &ExitingBlocks,
62 BasicBlock *ExitBlock, bool &Changed,
63 BasicBlock *Preheader, LoopInfo &LI) {
64 // Make sure that all PHI entries coming from the loop are loop invariant.
65 // Because the code is in LCSSA form, any values used outside of the loop
66 // must pass through a PHI in the exit block, meaning that this check is
67 // sufficient to guarantee that no loop-variant values are used outside
68 // of the loop.
69 bool AllEntriesInvariant = true;
70 bool AllOutgoingValuesSame = true;
71 if (ExitBlock) {
72 for (PHINode &P : ExitBlock->phis()) {
73 Value *incoming = P.getIncomingValueForBlock(ExitingBlocks[0]);
74
75 // Make sure all exiting blocks produce the same incoming value for the
76 // block. If there are different incoming values for different exiting
77 // blocks, then it is impossible to statically determine which value
78 // should be used.
79 AllOutgoingValuesSame =
80 all_of(ArrayRef(ExitingBlocks).slice(1), [&](BasicBlock *BB) {
81 return incoming == P.getIncomingValueForBlock(BB);
82 });
83
84 if (!AllOutgoingValuesSame)
85 break;
86
87 if (Instruction *I = dyn_cast<Instruction>(incoming)) {
88 if (!L->makeLoopInvariant(I, Changed, Preheader->getTerminator(),
89 /*MSSAU=*/nullptr, &SE)) {
90 AllEntriesInvariant = false;
91 break;
92 }
93 }
94 }
95 }
96
97 if (!AllEntriesInvariant || !AllOutgoingValuesSame)
98 return false;
99
100 // Make sure that no instructions in the block have potential side-effects.
101 // This includes instructions that could write to memory, and loads that are
102 // marked volatile.
103 for (const auto &I : L->blocks())
104 if (any_of(*I, [](Instruction &I) {
105 return I.mayHaveSideEffects() && !I.isDroppable();
106 }))
107 return false;
108
109 // Calls that may not return were rejected above.
110 return isLoopNestFinite(L, SE, LI);
111}
112
113/// This function returns true if there is no viable path from the
114/// entry block to the header of \p L. Right now, it only does
115/// a local search to save compile time.
116static bool isLoopNeverExecuted(Loop *L) {
117 using namespace PatternMatch;
118
119 auto *Preheader = L->getLoopPreheader();
120 // TODO: We can relax this constraint, since we just need a loop
121 // predecessor.
122 assert(Preheader && "Needs preheader!");
123
124 if (Preheader->isEntryBlock())
125 return false;
126 // All predecessors of the preheader should have a constant conditional
127 // branch, with the loop's preheader as not-taken.
128 for (auto *Pred: predecessors(Preheader)) {
129 BasicBlock *Taken, *NotTaken;
131 if (!match(Pred->getTerminator(),
132 m_Br(m_ConstantInt(Cond), Taken, NotTaken)))
133 return false;
134 if (!Cond->getZExtValue())
135 std::swap(Taken, NotTaken);
136 if (Taken == Preheader)
137 return false;
138 }
139 assert(!pred_empty(Preheader) &&
140 "Preheader should have predecessors at this point!");
141 // All the predecessors have the loop preheader as not-taken target.
142 return true;
143}
144
145static Value *
147 const SimplifyQuery &SQ) {
148 // Quick hack: do not flood cache with non-instruction values.
149 if (!isa<Instruction>(V))
150 return V;
151 // Do we already know cached result?
152 auto Existing = FirstIterValue.find(V);
153 if (Existing != FirstIterValue.end())
154 return Existing->second;
155 Value *FirstIterV = nullptr;
156 if (auto *BO = dyn_cast<BinaryOperator>(V)) {
157 Value *LHS =
158 getValueOnFirstIteration(BO->getOperand(0), FirstIterValue, SQ);
159 Value *RHS =
160 getValueOnFirstIteration(BO->getOperand(1), FirstIterValue, SQ);
161 FirstIterV = simplifyBinOp(BO->getOpcode(), LHS, RHS, SQ);
162 } else if (auto *Cmp = dyn_cast<ICmpInst>(V)) {
163 Value *LHS =
164 getValueOnFirstIteration(Cmp->getOperand(0), FirstIterValue, SQ);
165 Value *RHS =
166 getValueOnFirstIteration(Cmp->getOperand(1), FirstIterValue, SQ);
167 FirstIterV = simplifyICmpInst(Cmp->getPredicate(), LHS, RHS, SQ);
168 } else if (auto *Select = dyn_cast<SelectInst>(V)) {
169 Value *Cond =
170 getValueOnFirstIteration(Select->getCondition(), FirstIterValue, SQ);
171 if (auto *C = dyn_cast<ConstantInt>(Cond)) {
172 auto *Selected = C->isAllOnesValue() ? Select->getTrueValue()
173 : Select->getFalseValue();
174 FirstIterV = getValueOnFirstIteration(Selected, FirstIterValue, SQ);
175 }
176 }
177 if (!FirstIterV)
178 FirstIterV = V;
179 FirstIterValue[V] = FirstIterV;
180 return FirstIterV;
181}
182
183// Try to prove that one of conditions that dominates the latch must exit on 1st
184// iteration.
186 LoopInfo &LI) {
187 // Disabled by option.
188 if (!getScalarOptions(*L).loop_deletion_enable_symbolic_execution)
189 return false;
190
191 BasicBlock *Predecessor = L->getLoopPredecessor();
192 BasicBlock *Latch = L->getLoopLatch();
193
194 if (!Predecessor || !Latch)
195 return false;
196
197 LoopBlocksRPO RPOT(L);
198 RPOT.perform(&LI);
199
200 // For the optimization to be correct, we need RPOT to have a property that
201 // each block is processed after all its predecessors, which may only be
202 // violated for headers of the current loop and all nested loops. Irreducible
203 // CFG provides multiple ways to break this assumption, so we do not want to
204 // deal with it.
206 return false;
207
208 BasicBlock *Header = L->getHeader();
209 // Blocks that are reachable on the 1st iteration.
211 // Edges that are reachable on the 1st iteration.
212 DenseSet<BasicBlockEdge> LiveEdges;
213 LiveBlocks.insert(Header);
214
216 auto MarkLiveEdge = [&](BasicBlock *From, BasicBlock *To) {
217 assert(LiveBlocks.count(From) && "Must be live!");
218 assert((LI.isLoopHeader(To) || !Visited.count(To)) &&
219 "Only canonical backedges are allowed. Irreducible CFG?");
220 assert((LiveBlocks.count(To) || !Visited.count(To)) &&
221 "We already discarded this block as dead!");
222 LiveBlocks.insert(To);
223 LiveEdges.insert({ From, To });
224 };
225
226 auto MarkAllSuccessorsLive = [&](BasicBlock *BB) {
227 for (auto *Succ : successors(BB))
228 MarkLiveEdge(BB, Succ);
229 };
230
231 // Check if there is only one value coming from all live predecessor blocks.
232 // Note that because we iterate in RPOT, we have already visited all its
233 // (non-latch) predecessors.
234 auto GetSoleInputOnFirstIteration = [&](PHINode & PN)->Value * {
235 BasicBlock *BB = PN.getParent();
236 bool HasLivePreds = false;
237 (void)HasLivePreds;
238 if (BB == Header)
239 return PN.getIncomingValueForBlock(Predecessor);
240 Value *OnlyInput = nullptr;
241 for (auto *Pred : predecessors(BB))
242 if (LiveEdges.count({ Pred, BB })) {
243 HasLivePreds = true;
244 Value *Incoming = PN.getIncomingValueForBlock(Pred);
245 // Skip poison. If they are present, we can assume they are equal to
246 // the non-poison input.
247 if (isa<PoisonValue>(Incoming))
248 continue;
249 // Two inputs.
250 if (OnlyInput && OnlyInput != Incoming)
251 return nullptr;
252 OnlyInput = Incoming;
253 }
254
255 assert(HasLivePreds && "No live predecessors?");
256 // If all incoming live value were poison, return poison.
257 return OnlyInput ? OnlyInput : PoisonValue::get(PN.getType());
258 };
259 DenseMap<Value *, Value *> FirstIterValue;
260
261 // Use the following algorithm to prove we never take the latch on the 1st
262 // iteration:
263 // 1. Traverse in topological order, so that whenever we visit a block, all
264 // its predecessors are already visited.
265 // 2. If we can prove that the block may have only 1 predecessor on the 1st
266 // iteration, map all its phis onto input from this predecessor.
267 // 3a. If we can prove which successor of out block is taken on the 1st
268 // iteration, mark this successor live.
269 // 3b. If we cannot prove it, conservatively assume that all successors are
270 // live.
271 auto &DL = Header->getDataLayout();
272 const SimplifyQuery SQ(DL);
273 for (auto *BB : RPOT) {
274 Visited.insert(BB);
275
276 // This block is not reachable on the 1st iterations.
277 if (!LiveBlocks.count(BB))
278 continue;
279
280 // Skip inner loops.
281 if (LI.getLoopFor(BB) != L) {
282 MarkAllSuccessorsLive(BB);
283 continue;
284 }
285
286 // If Phi has only one input from all live input blocks, use it.
287 for (auto &PN : BB->phis()) {
288 if (!PN.getType()->isIntegerTy())
289 continue;
290 auto *Incoming = GetSoleInputOnFirstIteration(PN);
291 if (Incoming && DT.dominates(Incoming, BB->getTerminator())) {
292 Value *FirstIterV =
293 getValueOnFirstIteration(Incoming, FirstIterValue, SQ);
294 FirstIterValue[&PN] = FirstIterV;
295 }
296 }
297
298 using namespace PatternMatch;
299 Value *Cond;
300 BasicBlock *IfTrue, *IfFalse;
301 auto *Term = BB->getTerminator();
302 if (match(Term, m_Br(m_Value(Cond),
303 m_BasicBlock(IfTrue), m_BasicBlock(IfFalse)))) {
304 auto *ICmp = dyn_cast<ICmpInst>(Cond);
305 if (!ICmp || !ICmp->getType()->isIntegerTy()) {
306 MarkAllSuccessorsLive(BB);
307 continue;
308 }
309
310 // Can we prove constant true or false for this condition?
311 auto *KnownCondition = getValueOnFirstIteration(ICmp, FirstIterValue, SQ);
312 if (KnownCondition == ICmp) {
313 // Failed to simplify.
314 MarkAllSuccessorsLive(BB);
315 continue;
316 }
317 if (isa<UndefValue>(KnownCondition)) {
318 // TODO: According to langref, branching by undef is undefined behavior.
319 // It means that, theoretically, we should be able to just continue
320 // without marking any successors as live. However, we are not certain
321 // how correct our compiler is at handling such cases. So we are being
322 // very conservative here.
323 //
324 // If there is a non-loop successor, always assume this branch leaves the
325 // loop. Otherwise, arbitrarily take IfTrue.
326 //
327 // Once we are certain that branching by undef is handled correctly by
328 // other transforms, we should not mark any successors live here.
329 if (L->contains(IfTrue) && L->contains(IfFalse))
330 MarkLiveEdge(BB, IfTrue);
331 continue;
332 }
333 auto *ConstCondition = dyn_cast<ConstantInt>(KnownCondition);
334 if (!ConstCondition) {
335 // Non-constant condition, cannot analyze any further.
336 MarkAllSuccessorsLive(BB);
337 continue;
338 }
339 if (ConstCondition->isAllOnesValue())
340 MarkLiveEdge(BB, IfTrue);
341 else
342 MarkLiveEdge(BB, IfFalse);
343 } else if (SwitchInst *SI = dyn_cast<SwitchInst>(Term)) {
344 auto *SwitchValue = SI->getCondition();
345 auto *SwitchValueOnFirstIter =
346 getValueOnFirstIteration(SwitchValue, FirstIterValue, SQ);
347 auto *ConstSwitchValue = dyn_cast<ConstantInt>(SwitchValueOnFirstIter);
348 if (!ConstSwitchValue) {
349 MarkAllSuccessorsLive(BB);
350 continue;
351 }
352 auto CaseIterator = SI->findCaseValue(ConstSwitchValue);
353 MarkLiveEdge(BB, CaseIterator->getCaseSuccessor());
354 } else {
355 MarkAllSuccessorsLive(BB);
356 continue;
357 }
358 }
359
360 // We can break the latch if it wasn't live.
361 return !LiveEdges.count({ Latch, Header });
362}
363
364/// If we can prove the backedge is untaken, remove it. This destroys the
365/// loop, but leaves the (now trivially loop invariant) control flow and
366/// side effects (if any) in place.
369 LoopInfo &LI, MemorySSA *MSSA,
371 assert(L->isLCSSAForm(DT) && "Expected LCSSA!");
372
373 if (!L->getLoopLatch())
375
376 const SCEV *BTCMax = SE.getConstantMaxBackedgeTakenCount(L);
377 if (!BTCMax->isZero()) {
378 const SCEV *BTC = SE.getBackedgeTakenCount(L);
379 if (!BTC->isZero()) {
380 if (!isa<SCEVCouldNotCompute>(BTC) && SE.isKnownNonZero(BTC))
382 if (!canProveExitOnFirstIteration(L, DT, LI))
384 }
385 }
386 ++NumBackedgesBroken;
387 breakLoopBackedge(L, DT, SE, LI, MSSA);
389}
390
391/// Remove a loop if it is dead.
392///
393/// A loop is considered dead either if it does not impact the observable
394/// behavior of the program other than finite running time, or if it is
395/// required to make progress by an attribute such as 'mustprogress' or
396/// 'llvm.loop.mustprogress' and does not make any. This may remove
397/// infinite loops that have been required to make progress.
398///
399/// This entire process relies pretty heavily on LoopSimplify form and LCSSA in
400/// order to make various safety checks work.
401///
402/// \returns true if any changes were made. This may mutate the loop even if it
403/// is unable to delete it due to hoisting trivially loop invariant
404/// instructions out of the loop.
406 ScalarEvolution &SE, LoopInfo &LI,
407 MemorySSA *MSSA,
409 assert(L->isLCSSAForm(DT) && "Expected LCSSA!");
410
411 // We can only remove the loop if there is a preheader that we can branch from
412 // after removing it. Also, if LoopSimplify form is not available, stay out
413 // of trouble.
414 BasicBlock *Preheader = L->getLoopPreheader();
415 if (!Preheader || !L->hasDedicatedExits()) {
417 dbgs()
418 << "Deletion requires Loop with preheader and dedicated exits.\n");
420 }
421
422 BasicBlock *ExitBlock = L->getUniqueExitBlock();
423
424 // We can't directly branch to an EH pad. Don't bother handling this edge
425 // case.
426 if (ExitBlock && ExitBlock->isEHPad()) {
427 LLVM_DEBUG(dbgs() << "Cannot delete loop exiting to EH pad.\n");
429 }
430
431 if (ExitBlock && isLoopNeverExecuted(L)) {
432 LLVM_DEBUG(dbgs() << "Loop is proven to never execute, delete it!\n");
433 // We need to forget the loop before setting the incoming values of the exit
434 // phis to poison, so we properly invalidate the SCEV expressions for those
435 // phis.
436 SE.forgetLoop(L);
437 // Set incoming value to poison for phi nodes in the exit block.
438 for (PHINode &P : ExitBlock->phis()) {
439 llvm::fill(P.incoming_values(), PoisonValue::get(P.getType()));
440 }
441 ORE.emit([&]() {
442 return OptimizationRemark(DEBUG_TYPE, "NeverExecutes", L->getStartLoc(),
443 L->getHeader())
444 << "Loop deleted because it never executes";
445 });
446 deleteDeadLoop(L, &DT, &SE, &LI, MSSA);
447 ++NumDeleted;
449 }
450
451 // The remaining checks below are for a loop being dead because all statements
452 // in the loop are invariant.
453 SmallVector<BasicBlock *, 4> ExitingBlocks;
454 L->getExitingBlocks(ExitingBlocks);
455
456 // We require that the loop has at most one exit block. Otherwise, we'd be in
457 // the situation of needing to be able to solve statically which exit block
458 // will be branched to, or trying to preserve the branching logic in a loop
459 // invariant manner.
460 if (!ExitBlock && !LI.hasNoExitBlocks(*L)) {
461 LLVM_DEBUG(dbgs() << "Deletion requires at most one exit block.\n");
463 }
464
465 // Finally, we have to check that the loop really is dead.
466 bool Changed = false;
467 if (!isLoopDead(L, SE, ExitingBlocks, ExitBlock, Changed, Preheader, LI)) {
468 LLVM_DEBUG(dbgs() << "Loop is not invariant, cannot delete.\n");
471 }
472
473 LLVM_DEBUG(dbgs() << "Loop is invariant, delete it!\n");
474 ORE.emit([&]() {
475 return OptimizationRemark(DEBUG_TYPE, "Invariant", L->getStartLoc(),
476 L->getHeader())
477 << "Loop deleted because it is invariant";
478 });
479 deleteDeadLoop(L, &DT, &SE, &LI, MSSA);
480 ++NumDeleted;
481
483}
484
487 LPMUpdater &Updater) {
488
489 LLVM_DEBUG(dbgs() << "Analyzing Loop for deletion: ");
490 LLVM_DEBUG(L.dump());
491 std::string LoopName = std::string(L.getName());
492 // For the new PM, we can't use OptimizationRemarkEmitter as an analysis
493 // pass. Function analyses need to be preserved across loop transformations
494 // but ORE cannot be preserved (see comment before the pass definition).
495 OptimizationRemarkEmitter ORE(L.getHeader()->getParent());
496 auto Result = deleteLoopIfDead(&L, AR.DT, AR.SE, AR.LI, AR.MSSA, ORE);
497
498 // If we can prove the backedge isn't taken, just break it and be done. This
499 // leaves the loop structure in place which means it can handle dispatching
500 // to the right exit based on whatever loop invariant structure remains.
501 if (Result != LoopDeletionResult::Deleted)
502 Result = merge(Result, breakBackedgeIfNotTaken(&L, AR.DT, AR.SE, AR.LI,
503 AR.MSSA, ORE));
504
505 if (Result == LoopDeletionResult::Unmodified)
506 return PreservedAnalyses::all();
507
508 if (Result == LoopDeletionResult::Deleted)
509 Updater.markLoopAsDeleted(L, LoopName);
510
512 if (AR.MSSA)
513 PA.preserve<MemorySSAAnalysis>();
514 return PA;
515}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define DEBUG_TYPE
LoopDeletionResult
static LoopDeletionResult breakBackedgeIfNotTaken(Loop *L, DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI, MemorySSA *MSSA, OptimizationRemarkEmitter &ORE)
If we can prove the backedge is untaken, remove it.
static Value * getValueOnFirstIteration(Value *V, DenseMap< Value *, Value * > &FirstIterValue, const SimplifyQuery &SQ)
static LoopDeletionResult deleteLoopIfDead(Loop *L, DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI, MemorySSA *MSSA, OptimizationRemarkEmitter &ORE)
Remove a loop if it is dead.
static LoopDeletionResult merge(LoopDeletionResult A, LoopDeletionResult B)
static bool isLoopNeverExecuted(Loop *L)
This function returns true if there is no viable path from the entry block to the header of L.
static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT, LoopInfo &LI)
static bool isLoopDead(Loop *L, ScalarEvolution &SE, SmallVectorImpl< BasicBlock * > &ExitingBlocks, BasicBlock *ExitBlock, bool &Changed, BasicBlock *Preheader, LoopInfo &LI)
Determines if a loop is dead.
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
#define I(x, y, z)
Definition MD5.cpp:57
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
#define P(N)
SmallVector< MachineOperand, 4 > Cond
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)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
Value * RHS
Value * LHS
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition BasicBlock.h:509
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
bool isEHPad() const
Return true if this basic block is an exception handling block.
Definition BasicBlock.h:683
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
This is the shared class of boolean and integer constants.
Definition Constants.h:87
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:766
iterator end()
Definition DenseMap.h:686
Implements a dense probed hash-table based set.
Definition DenseSet.h:281
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
void markLoopAsDeleted(Loop &L, llvm::StringRef Name)
Loop passes should use this method to indicate they have deleted a loop from the nest.
Wrapper class to LoopBlocksDFS that provides a standard begin()/end() interface for the DFS reverse p...
void perform(const LoopInfo *LI)
Traverse the loop blocks and store the DFS result.
LLVM_ABI PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
bool hasNoExitBlocks(const LoopT &L) const
Return true if L does not have any exit blocks.
bool isLoopHeader(const BlockT *BB) const
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
An analysis that produces MemorySSA for a function.
Definition MemorySSA.h:917
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition MemorySSA.h:696
The optimization diagnostic interface.
LLVM_ABI void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file.
Diagnostic information for applied optimization remarks.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
This class represents an analyzed expression in the program.
LLVM_ABI bool isZero() const
Return true if the expression is a constant zero.
The main scalar evolution driver.
const SCEV * getConstantMaxBackedgeTakenCount(const Loop *L)
When successful, this returns a SCEVConstant that is greater than or equal to (i.e.
LLVM_ABI bool isKnownNonZero(const SCEV *S)
Test if the given expression is known to be non-zero.
LLVM_ABI const SCEV * getBackedgeTakenCount(const Loop *L, ExitCountKind Kind=Exact)
If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCould...
LLVM_ABI void forgetLoop(const Loop *L)
This method should be called by the client when it has changed a loop in a way that may effect Scalar...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Multiway switch.
LLVM Value Representation.
Definition Value.h:75
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:209
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition DenseSet.h:187
bool match(Val *V, const Pattern &P)
auto m_BasicBlock()
Match an arbitrary basic block value and ignore it.
auto m_Value()
Match an arbitrary value and ignore it.
brc_match< Cond_t, match_bind< BasicBlock >, match_bind< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
This is an optimization pass for GlobalISel generic memory operations.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1775
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1755
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto successors(const MachineBasicBlock *BB)
const ScalarOptions & getScalarOptions(const LLVMContext &C)
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
bool containsIrreducibleCFG(RPOTraversalT &RPOTraversal, const LoopInfoT &LI)
Return true if the control flow in RPOTraversal is irreducible.
Definition CFG.h:154
LLVM_ABI void deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE, LoopInfo *LI, MemorySSA *MSSA=nullptr)
This function deletes dead loops.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI Value * simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an ICmpInst, fold the result or return null.
@ Unmodified
The loop was not modified.
Definition UnrollLoop.h:60
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...
Definition Casting.h:547
LLVM_ABI bool isLoopNestFinite(Loop *L, ScalarEvolution &SE, const LoopInfo &LI)
Return true if every cycle in the loop nest rooted at L is finite.
LLVM_ABI Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
auto predecessors(const MachineBasicBlock *BB)
bool pred_empty(const BasicBlock *BB)
Definition CFG.h:107
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:880
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...