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 (!L->getHeader()
189 ->getContext()
190 .getLibraryOptions()
191 .get<ScalarOptions>()
192 .loop_deletion_enable_symbolic_execution)
193 return false;
194
195 BasicBlock *Predecessor = L->getLoopPredecessor();
196 BasicBlock *Latch = L->getLoopLatch();
197
198 if (!Predecessor || !Latch)
199 return false;
200
201 LoopBlocksRPO RPOT(L);
202 RPOT.perform(&LI);
203
204 // For the optimization to be correct, we need RPOT to have a property that
205 // each block is processed after all its predecessors, which may only be
206 // violated for headers of the current loop and all nested loops. Irreducible
207 // CFG provides multiple ways to break this assumption, so we do not want to
208 // deal with it.
210 return false;
211
212 BasicBlock *Header = L->getHeader();
213 // Blocks that are reachable on the 1st iteration.
215 // Edges that are reachable on the 1st iteration.
216 DenseSet<BasicBlockEdge> LiveEdges;
217 LiveBlocks.insert(Header);
218
220 auto MarkLiveEdge = [&](BasicBlock *From, BasicBlock *To) {
221 assert(LiveBlocks.count(From) && "Must be live!");
222 assert((LI.isLoopHeader(To) || !Visited.count(To)) &&
223 "Only canonical backedges are allowed. Irreducible CFG?");
224 assert((LiveBlocks.count(To) || !Visited.count(To)) &&
225 "We already discarded this block as dead!");
226 LiveBlocks.insert(To);
227 LiveEdges.insert({ From, To });
228 };
229
230 auto MarkAllSuccessorsLive = [&](BasicBlock *BB) {
231 for (auto *Succ : successors(BB))
232 MarkLiveEdge(BB, Succ);
233 };
234
235 // Check if there is only one value coming from all live predecessor blocks.
236 // Note that because we iterate in RPOT, we have already visited all its
237 // (non-latch) predecessors.
238 auto GetSoleInputOnFirstIteration = [&](PHINode & PN)->Value * {
239 BasicBlock *BB = PN.getParent();
240 bool HasLivePreds = false;
241 (void)HasLivePreds;
242 if (BB == Header)
243 return PN.getIncomingValueForBlock(Predecessor);
244 Value *OnlyInput = nullptr;
245 for (auto *Pred : predecessors(BB))
246 if (LiveEdges.count({ Pred, BB })) {
247 HasLivePreds = true;
248 Value *Incoming = PN.getIncomingValueForBlock(Pred);
249 // Skip poison. If they are present, we can assume they are equal to
250 // the non-poison input.
251 if (isa<PoisonValue>(Incoming))
252 continue;
253 // Two inputs.
254 if (OnlyInput && OnlyInput != Incoming)
255 return nullptr;
256 OnlyInput = Incoming;
257 }
258
259 assert(HasLivePreds && "No live predecessors?");
260 // If all incoming live value were poison, return poison.
261 return OnlyInput ? OnlyInput : PoisonValue::get(PN.getType());
262 };
263 DenseMap<Value *, Value *> FirstIterValue;
264
265 // Use the following algorithm to prove we never take the latch on the 1st
266 // iteration:
267 // 1. Traverse in topological order, so that whenever we visit a block, all
268 // its predecessors are already visited.
269 // 2. If we can prove that the block may have only 1 predecessor on the 1st
270 // iteration, map all its phis onto input from this predecessor.
271 // 3a. If we can prove which successor of out block is taken on the 1st
272 // iteration, mark this successor live.
273 // 3b. If we cannot prove it, conservatively assume that all successors are
274 // live.
275 auto &DL = Header->getDataLayout();
276 const SimplifyQuery SQ(DL);
277 for (auto *BB : RPOT) {
278 Visited.insert(BB);
279
280 // This block is not reachable on the 1st iterations.
281 if (!LiveBlocks.count(BB))
282 continue;
283
284 // Skip inner loops.
285 if (LI.getLoopFor(BB) != L) {
286 MarkAllSuccessorsLive(BB);
287 continue;
288 }
289
290 // If Phi has only one input from all live input blocks, use it.
291 for (auto &PN : BB->phis()) {
292 if (!PN.getType()->isIntegerTy())
293 continue;
294 auto *Incoming = GetSoleInputOnFirstIteration(PN);
295 if (Incoming && DT.dominates(Incoming, BB->getTerminator())) {
296 Value *FirstIterV =
297 getValueOnFirstIteration(Incoming, FirstIterValue, SQ);
298 FirstIterValue[&PN] = FirstIterV;
299 }
300 }
301
302 using namespace PatternMatch;
303 Value *Cond;
304 BasicBlock *IfTrue, *IfFalse;
305 auto *Term = BB->getTerminator();
306 if (match(Term, m_Br(m_Value(Cond),
307 m_BasicBlock(IfTrue), m_BasicBlock(IfFalse)))) {
308 auto *ICmp = dyn_cast<ICmpInst>(Cond);
309 if (!ICmp || !ICmp->getType()->isIntegerTy()) {
310 MarkAllSuccessorsLive(BB);
311 continue;
312 }
313
314 // Can we prove constant true or false for this condition?
315 auto *KnownCondition = getValueOnFirstIteration(ICmp, FirstIterValue, SQ);
316 if (KnownCondition == ICmp) {
317 // Failed to simplify.
318 MarkAllSuccessorsLive(BB);
319 continue;
320 }
321 if (isa<UndefValue>(KnownCondition)) {
322 // TODO: According to langref, branching by undef is undefined behavior.
323 // It means that, theoretically, we should be able to just continue
324 // without marking any successors as live. However, we are not certain
325 // how correct our compiler is at handling such cases. So we are being
326 // very conservative here.
327 //
328 // If there is a non-loop successor, always assume this branch leaves the
329 // loop. Otherwise, arbitrarily take IfTrue.
330 //
331 // Once we are certain that branching by undef is handled correctly by
332 // other transforms, we should not mark any successors live here.
333 if (L->contains(IfTrue) && L->contains(IfFalse))
334 MarkLiveEdge(BB, IfTrue);
335 continue;
336 }
337 auto *ConstCondition = dyn_cast<ConstantInt>(KnownCondition);
338 if (!ConstCondition) {
339 // Non-constant condition, cannot analyze any further.
340 MarkAllSuccessorsLive(BB);
341 continue;
342 }
343 if (ConstCondition->isAllOnesValue())
344 MarkLiveEdge(BB, IfTrue);
345 else
346 MarkLiveEdge(BB, IfFalse);
347 } else if (SwitchInst *SI = dyn_cast<SwitchInst>(Term)) {
348 auto *SwitchValue = SI->getCondition();
349 auto *SwitchValueOnFirstIter =
350 getValueOnFirstIteration(SwitchValue, FirstIterValue, SQ);
351 auto *ConstSwitchValue = dyn_cast<ConstantInt>(SwitchValueOnFirstIter);
352 if (!ConstSwitchValue) {
353 MarkAllSuccessorsLive(BB);
354 continue;
355 }
356 auto CaseIterator = SI->findCaseValue(ConstSwitchValue);
357 MarkLiveEdge(BB, CaseIterator->getCaseSuccessor());
358 } else {
359 MarkAllSuccessorsLive(BB);
360 continue;
361 }
362 }
363
364 // We can break the latch if it wasn't live.
365 return !LiveEdges.count({ Latch, Header });
366}
367
368/// If we can prove the backedge is untaken, remove it. This destroys the
369/// loop, but leaves the (now trivially loop invariant) control flow and
370/// side effects (if any) in place.
373 LoopInfo &LI, MemorySSA *MSSA,
375 assert(L->isLCSSAForm(DT) && "Expected LCSSA!");
376
377 if (!L->getLoopLatch())
379
380 const SCEV *BTCMax = SE.getConstantMaxBackedgeTakenCount(L);
381 if (!BTCMax->isZero()) {
382 const SCEV *BTC = SE.getBackedgeTakenCount(L);
383 if (!BTC->isZero()) {
384 if (!isa<SCEVCouldNotCompute>(BTC) && SE.isKnownNonZero(BTC))
386 if (!canProveExitOnFirstIteration(L, DT, LI))
388 }
389 }
390 ++NumBackedgesBroken;
391 breakLoopBackedge(L, DT, SE, LI, MSSA);
393}
394
395/// Remove a loop if it is dead.
396///
397/// A loop is considered dead either if it does not impact the observable
398/// behavior of the program other than finite running time, or if it is
399/// required to make progress by an attribute such as 'mustprogress' or
400/// 'llvm.loop.mustprogress' and does not make any. This may remove
401/// infinite loops that have been required to make progress.
402///
403/// This entire process relies pretty heavily on LoopSimplify form and LCSSA in
404/// order to make various safety checks work.
405///
406/// \returns true if any changes were made. This may mutate the loop even if it
407/// is unable to delete it due to hoisting trivially loop invariant
408/// instructions out of the loop.
410 ScalarEvolution &SE, LoopInfo &LI,
411 MemorySSA *MSSA,
413 assert(L->isLCSSAForm(DT) && "Expected LCSSA!");
414
415 // We can only remove the loop if there is a preheader that we can branch from
416 // after removing it. Also, if LoopSimplify form is not available, stay out
417 // of trouble.
418 BasicBlock *Preheader = L->getLoopPreheader();
419 if (!Preheader || !L->hasDedicatedExits()) {
421 dbgs()
422 << "Deletion requires Loop with preheader and dedicated exits.\n");
424 }
425
426 BasicBlock *ExitBlock = L->getUniqueExitBlock();
427
428 // We can't directly branch to an EH pad. Don't bother handling this edge
429 // case.
430 if (ExitBlock && ExitBlock->isEHPad()) {
431 LLVM_DEBUG(dbgs() << "Cannot delete loop exiting to EH pad.\n");
433 }
434
435 if (ExitBlock && isLoopNeverExecuted(L)) {
436 LLVM_DEBUG(dbgs() << "Loop is proven to never execute, delete it!\n");
437 // We need to forget the loop before setting the incoming values of the exit
438 // phis to poison, so we properly invalidate the SCEV expressions for those
439 // phis.
440 SE.forgetLoop(L);
441 // Set incoming value to poison for phi nodes in the exit block.
442 for (PHINode &P : ExitBlock->phis()) {
443 llvm::fill(P.incoming_values(), PoisonValue::get(P.getType()));
444 }
445 ORE.emit([&]() {
446 return OptimizationRemark(DEBUG_TYPE, "NeverExecutes", L->getStartLoc(),
447 L->getHeader())
448 << "Loop deleted because it never executes";
449 });
450 deleteDeadLoop(L, &DT, &SE, &LI, MSSA);
451 ++NumDeleted;
453 }
454
455 // The remaining checks below are for a loop being dead because all statements
456 // in the loop are invariant.
457 SmallVector<BasicBlock *, 4> ExitingBlocks;
458 L->getExitingBlocks(ExitingBlocks);
459
460 // We require that the loop has at most one exit block. Otherwise, we'd be in
461 // the situation of needing to be able to solve statically which exit block
462 // will be branched to, or trying to preserve the branching logic in a loop
463 // invariant manner.
464 if (!ExitBlock && !LI.hasNoExitBlocks(*L)) {
465 LLVM_DEBUG(dbgs() << "Deletion requires at most one exit block.\n");
467 }
468
469 // Finally, we have to check that the loop really is dead.
470 bool Changed = false;
471 if (!isLoopDead(L, SE, ExitingBlocks, ExitBlock, Changed, Preheader, LI)) {
472 LLVM_DEBUG(dbgs() << "Loop is not invariant, cannot delete.\n");
475 }
476
477 LLVM_DEBUG(dbgs() << "Loop is invariant, delete it!\n");
478 ORE.emit([&]() {
479 return OptimizationRemark(DEBUG_TYPE, "Invariant", L->getStartLoc(),
480 L->getHeader())
481 << "Loop deleted because it is invariant";
482 });
483 deleteDeadLoop(L, &DT, &SE, &LI, MSSA);
484 ++NumDeleted;
485
487}
488
491 LPMUpdater &Updater) {
492
493 LLVM_DEBUG(dbgs() << "Analyzing Loop for deletion: ");
494 LLVM_DEBUG(L.dump());
495 std::string LoopName = std::string(L.getName());
496 // For the new PM, we can't use OptimizationRemarkEmitter as an analysis
497 // pass. Function analyses need to be preserved across loop transformations
498 // but ORE cannot be preserved (see comment before the pass definition).
499 OptimizationRemarkEmitter ORE(L.getHeader()->getParent());
500 auto Result = deleteLoopIfDead(&L, AR.DT, AR.SE, AR.LI, AR.MSSA, ORE);
501
502 // If we can prove the backedge isn't taken, just break it and be done. This
503 // leaves the loop structure in place which means it can handle dispatching
504 // to the right exit based on whatever loop invariant structure remains.
505 if (Result != LoopDeletionResult::Deleted)
506 Result = merge(Result, breakBackedgeIfNotTaken(&L, AR.DT, AR.SE, AR.LI,
507 AR.MSSA, ORE));
508
509 if (Result == LoopDeletionResult::Unmodified)
510 return PreservedAnalyses::all();
511
512 if (Result == LoopDeletionResult::Deleted)
513 Updater.markLoopAsDeleted(L, LoopName);
514
516 if (AR.MSSA)
517 PA.preserve<MemorySSAAnalysis>();
518 return PA;
519}
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)
const SmallVectorImpl< MachineOperand > & 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:922
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition MemorySSA.h:702
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
Changed
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)
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...