LLVM 24.0.0git
LoopBoundSplit.cpp
Go to the documentation of this file.
1//===------- LoopBoundSplit.cpp - Split Loop Bound --------------*- C++ -*-===//
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
10#include "llvm/ADT/Sequence.h"
21
22#define DEBUG_TYPE "loop-bound-split"
23
24using namespace llvm;
25using namespace PatternMatch;
26
27namespace {
28struct ConditionInfo {
29 /// Branch instruction with this condition
30 CondBrInst *BI = nullptr;
31 /// ICmp instruction with this condition
32 ICmpInst *ICmp = nullptr;
33 /// Preciate info
35 /// AddRec llvm value
36 Value *AddRecValue = nullptr;
37 /// Non PHI AddRec llvm value
38 Value *NonPHIAddRecValue = nullptr;
39 /// Bound llvm value
40 Value *BoundValue = nullptr;
41 /// AddRec SCEV
42 const SCEVAddRecExpr *AddRecSCEV = nullptr;
43 /// Bound SCEV
44 const SCEV *BoundSCEV = nullptr;
45
46 ConditionInfo() = default;
47};
48} // namespace
49
50static bool calculateUpperBound(const Loop &L, ScalarEvolution &SE,
51 ConditionInfo &Cond, bool IsExitCond) {
52 if (IsExitCond) {
53 const SCEV *ExitCount = SE.getExitCount(&L, Cond.ICmp->getParent());
54 if (isa<SCEVCouldNotCompute>(ExitCount))
55 return false;
56
57 Cond.BoundSCEV = ExitCount;
58 return true;
59 }
60
61 // For non-exit condtion, if pred is LT, keep existing bound.
62 if (Cond.Pred == ICmpInst::ICMP_SLT || Cond.Pred == ICmpInst::ICMP_ULT)
63 return true;
64
65 // For non-exit condition, if pre is LE, try to convert it to LT.
66 // Range Range
67 // AddRec <= Bound --> AddRec < Bound + 1
68 if (Cond.Pred != ICmpInst::ICMP_ULE && Cond.Pred != ICmpInst::ICMP_SLE)
69 return false;
70
71 if (IntegerType *BoundSCEVIntType =
72 dyn_cast<IntegerType>(Cond.BoundSCEV->getType())) {
73 unsigned BitWidth = BoundSCEVIntType->getBitWidth();
74 APInt Max = ICmpInst::isSigned(Cond.Pred)
77 const SCEV *MaxSCEV = SE.getConstant(Max);
78 // Check Bound < INT_MAX
81 if (SE.isKnownPredicate(Pred, Cond.BoundSCEV, MaxSCEV)) {
82 const SCEV *BoundPlusOneSCEV =
83 SE.getAddExpr(Cond.BoundSCEV, SE.getOne(BoundSCEVIntType));
84 Cond.BoundSCEV = BoundPlusOneSCEV;
85 Cond.Pred = Pred;
86 return true;
87 }
88 }
89
90 // ToDo: Support ICMP_NE/EQ.
91
92 return false;
93}
94
95/// Check whether \p ICmp compares an induction variable of \p L against a
96/// bound this pass can split on, and describe it in \p Cond if so.
98 ICmpInst *ICmp, ConditionInfo &Cond,
99 bool IsExitCond) {
100 Cond.ICmp = ICmp;
101 if (!match(ICmp, m_ICmp(Cond.Pred, m_Value(Cond.AddRecValue),
102 m_Value(Cond.BoundValue))))
103 return false;
104
105 const SCEV *AddRecSCEV = SE.getSCEV(Cond.AddRecValue);
106 const SCEV *BoundSCEV = SE.getSCEV(Cond.BoundValue);
107 // Locate the recurrence in AddRecSCEV and the bound in BoundSCEV.
108 if (!isa<SCEVAddRecExpr>(AddRecSCEV) && isa<SCEVAddRecExpr>(BoundSCEV)) {
109 std::swap(Cond.AddRecValue, Cond.BoundValue);
110 std::swap(AddRecSCEV, BoundSCEV);
112 }
113
114 // Allowed AddRec as induction variable.
115 Cond.AddRecSCEV = dyn_cast<SCEVAddRecExpr>(AddRecSCEV);
116 if (!Cond.AddRecSCEV)
117 return false;
118
119 // If the induction variable is a PHI node, the value from the backedge is
120 // used instead.
121 Cond.NonPHIAddRecValue = Cond.AddRecValue;
122 if (auto *PN = dyn_cast<PHINode>(Cond.AddRecValue))
123 Cond.NonPHIAddRecValue = PN->getIncomingValueForBlock(L.getLoopLatch());
124
125 // The BoundSCEV should be evaluated at loop entry.
126 Cond.BoundSCEV = BoundSCEV;
127 if (!SE.isAvailableAtLoopEntry(Cond.BoundSCEV, &L))
128 return false;
129
130 if (!Cond.AddRecSCEV->isAffine())
131 return false;
132
133 // Allowed constant step.
134 const auto *StepRecSCEV =
135 dyn_cast<SCEVConstant>(Cond.AddRecSCEV->getStepRecurrence(SE));
136 if (!StepRecSCEV)
137 return false;
138
139 // Allowed positive step for now.
140 // TODO: Support negative step.
141 ConstantInt *StepCI = StepRecSCEV->getValue();
142 if (StepCI->isNegative() || StepCI->isZero())
143 return false;
144
145 // Calculate upper bound.
146 if (!calculateUpperBound(L, SE, Cond, IsExitCond))
147 return false;
148
149 return true;
150}
151
153 const CondBrInst *BI) {
154 BasicBlock *TrueSucc = nullptr;
155 BasicBlock *FalseSucc = nullptr;
156 Value *LHS, *RHS;
157 if (!match(BI, m_Br(m_ICmp(m_Value(LHS), m_Value(RHS)),
158 m_BasicBlock(TrueSucc), m_BasicBlock(FalseSucc))))
159 return false;
160
161 if (!SE.isSCEVable(LHS->getType()))
162 return false;
163 assert(SE.isSCEVable(RHS->getType()) && "Expected RHS's type is SCEVable");
164
165 if (TrueSucc == FalseSucc)
166 return false;
167
168 return true;
169}
170
171static bool canSplitLoopBound(const Loop &L, const DominatorTree &DT,
172 ScalarEvolution &SE, ConditionInfo &Cond) {
173 // Skip function with optsize.
174 if (L.getHeader()->getParent()->hasOptSize())
175 return false;
176
177 // Split only innermost loop.
178 if (!L.isInnermost())
179 return false;
180
181 // Check loop is in simplified form.
182 if (!L.isLoopSimplifyForm())
183 return false;
184
185 // Check loop is in LCSSA form.
186 if (!L.isLCSSAForm(DT))
187 return false;
188
189 // Skip loop that cannot be cloned.
190 if (!L.isSafeToClone())
191 return false;
192
193 BasicBlock *ExitingBB = L.getExitingBlock();
194 // Assumed only one exiting block.
195 if (!ExitingBB)
196 return false;
197
198 CondBrInst *ExitingBI = dyn_cast<CondBrInst>(ExitingBB->getTerminator());
199 if (!ExitingBI)
200 return false;
201
202 // Allowed only conditional branch with ICmp.
203 if (!isProcessableCondBI(SE, ExitingBI))
204 return false;
205
206 // Check the condition is processable.
207 ICmpInst *ICmp = cast<ICmpInst>(ExitingBI->getCondition());
208 if (!hasProcessableCondition(L, SE, ICmp, Cond, /*IsExitCond*/ true))
209 return false;
210
211 Cond.BI = ExitingBI;
212 return true;
213}
214
215static bool isProfitableToTransform(const Loop &L, const CondBrInst *BI) {
216 // If the conditional branch splits a loop into two halves, we could
217 // generally say it is profitable.
218 //
219 // ToDo: Add more profitable cases here.
220
221 // Check this branch causes diamond CFG.
222 BasicBlock *Succ0 = BI->getSuccessor(0);
223 BasicBlock *Succ1 = BI->getSuccessor(1);
224
225 BasicBlock *Succ0Succ = Succ0->getSingleSuccessor();
226 BasicBlock *Succ1Succ = Succ1->getSingleSuccessor();
227 if (!Succ0Succ || !Succ1Succ || Succ0Succ != Succ1Succ)
228 return false;
229
230 // ToDo: Calculate each successor's instruction cost.
231
232 return true;
233}
234
236 ConditionInfo &ExitingCond,
237 ConditionInfo &SplitCandidateCond) {
238 for (auto *BB : L.blocks()) {
239 // Skip condition of backedge.
240 if (L.getLoopLatch() == BB)
241 continue;
242
243 auto *BI = dyn_cast<CondBrInst>(BB->getTerminator());
244 if (!BI)
245 continue;
246
247 // Check conditional branch with ICmp.
248 if (!isProcessableCondBI(SE, BI))
249 continue;
250
251 // Skip loop invariant condition.
252 if (L.isLoopInvariant(BI->getCondition()))
253 continue;
254
255 // Check the condition is processable.
256 ICmpInst *ICmp = cast<ICmpInst>(BI->getCondition());
257 if (!hasProcessableCondition(L, SE, ICmp, SplitCandidateCond,
258 /*IsExitCond*/ false))
259 continue;
260
261 if (ExitingCond.BoundSCEV->getType() !=
262 SplitCandidateCond.BoundSCEV->getType())
263 continue;
264
265 // After transformation, we assume the split condition of the pre-loop is
266 // always true. In order to guarantee it, we need to check the start value
267 // of the split cond AddRec satisfies the split condition.
268 if (!SE.isLoopEntryGuardedByCond(&L, SplitCandidateCond.Pred,
269 SplitCandidateCond.AddRecSCEV->getStart(),
270 SplitCandidateCond.BoundSCEV))
271 continue;
272
273 SplitCandidateCond.BI = BI;
274 return BI;
275 }
276
277 return nullptr;
278}
279
280static bool splitLoopBound(Loop &L, DominatorTree &DT, LoopInfo &LI,
281 ScalarEvolution &SE, LPMUpdater &U) {
282 ConditionInfo SplitCandidateCond;
283 ConditionInfo ExitingCond;
284
285 // Check we can split this loop's bound.
286 if (!canSplitLoopBound(L, DT, SE, ExitingCond))
287 return false;
288
289 if (!findSplitCandidate(L, SE, ExitingCond, SplitCandidateCond))
290 return false;
291
292 if (!isProfitableToTransform(L, SplitCandidateCond.BI))
293 return false;
294
295 // Now, we have a split candidate. Let's build a form as below.
296 // +--------------------+
297 // | preheader |
298 // | set up newbound |
299 // +--------------------+
300 // | /----------------\
301 // +--------v----v------+ |
302 // | header |---\ |
303 // | with true condition| | |
304 // +--------------------+ | |
305 // | | |
306 // +--------v-----------+ | |
307 // | if.then.BB | | |
308 // +--------------------+ | |
309 // | | |
310 // +--------v-----------<---/ |
311 // | latch >----------/
312 // | with newbound |
313 // +--------------------+
314 // |
315 // +--------v-----------+
316 // | preheader2 |--------------\
317 // | if (AddRec i != | |
318 // | org bound) | |
319 // +--------------------+ |
320 // | /----------------\ |
321 // +--------v----v------+ | |
322 // | header2 |---\ | |
323 // | conditional branch | | | |
324 // |with false condition| | | |
325 // +--------------------+ | | |
326 // | | | |
327 // +--------v-----------+ | | |
328 // | if.then.BB2 | | | |
329 // +--------------------+ | | |
330 // | | | |
331 // +--------v-----------<---/ | |
332 // | latch2 >----------/ |
333 // | with org bound | |
334 // +--------v-----------+ |
335 // | |
336 // | +---------------+ |
337 // +--> exit <-------/
338 // +---------------+
339
340 // Let's create post loop.
341 SmallVector<BasicBlock *, 8> PostLoopBlocks;
342 Loop *PostLoop;
344 BasicBlock *PreHeader = L.getLoopPreheader();
345 BasicBlock *SplitLoopPH = SplitEdge(PreHeader, L.getHeader(), &DT, &LI);
346 PostLoop = cloneLoopWithPreheader(L.getExitBlock(), SplitLoopPH, &L, VMap,
347 ".split", &LI, &DT, PostLoopBlocks);
348 remapInstructionsInBlocks(PostLoopBlocks, VMap);
349
350 BasicBlock *PostLoopPreHeader = PostLoop->getLoopPreheader();
351 IRBuilder<> Builder(&PostLoopPreHeader->front());
352
353 // Replace exit branch target of pre-loop by post-loop's preheader.
354 // Note: update the branch here after calling cloneLoopWithPreheader()
355 // to keep the IR valid.
356 if (L.getExitBlock() == ExitingCond.BI->getSuccessor(0))
357 ExitingCond.BI->setSuccessor(0, PostLoopPreHeader);
358 else
359 ExitingCond.BI->setSuccessor(1, PostLoopPreHeader);
360
361 // Update dominator tree.
362 DT.changeImmediateDominator(PostLoopPreHeader, L.getExitingBlock());
363#ifndef NDEBUG
364 LI.verify();
365#endif
366 // Update phi nodes in header of post-loop.
367 bool isExitingLatch = L.getExitingBlock() == L.getLoopLatch();
368 Value *ExitingCondLCSSAPhi = nullptr;
369 for (PHINode &PN : L.getHeader()->phis()) {
370 // Create LCSSA phi node in preheader of post-loop.
371 PHINode *LCSSAPhi =
372 Builder.CreatePHI(PN.getType(), 1, PN.getName() + ".lcssa");
373 LCSSAPhi->setDebugLoc(PN.getDebugLoc());
374 // If the exiting block is loop latch, the phi does not have the update at
375 // last iteration. In this case, update lcssa phi with value from backedge.
376 LCSSAPhi->addIncoming(
377 isExitingLatch ? PN.getIncomingValueForBlock(L.getLoopLatch()) : &PN,
378 L.getExitingBlock());
379
380 // Update the start value of phi node in post-loop with the LCSSA phi node.
381 PHINode *PostLoopPN = cast<PHINode>(VMap[&PN]);
382 PostLoopPN->setIncomingValueForBlock(PostLoopPreHeader, LCSSAPhi);
383
384 // Find PHI with exiting condition from pre-loop. The PHI should be
385 // SCEVAddRecExpr and have same incoming value from backedge with
386 // ExitingCond.
387 //
388 // TODO: Separate SCEV queries from PHI node updates.
389 if (!SE.isSCEVable(PN.getType()))
390 continue;
391
392 const SCEVAddRecExpr *PhiSCEV = dyn_cast<SCEVAddRecExpr>(SE.getSCEV(&PN));
393 if (PhiSCEV && ExitingCond.NonPHIAddRecValue ==
394 PN.getIncomingValueForBlock(L.getLoopLatch()))
395 ExitingCondLCSSAPhi = LCSSAPhi;
396 }
397
398 // Add conditional branch to check we can skip post-loop in its preheader,
399 // and update DT.
400 Instruction *OrigBI = PostLoopPreHeader->getTerminator();
402 Value *Cond =
403 Builder.CreateICmp(Pred, ExitingCondLCSSAPhi, ExitingCond.BoundValue);
404 Builder.CreateCondBr(Cond, PostLoop->getHeader(), PostLoop->getExitBlock());
405 OrigBI->eraseFromParent();
406 DT.changeImmediateDominator(PostLoop->getExitBlock(), PostLoopPreHeader);
407#ifdef EXPENSIVE_CHECKS
408 assert(DT.verify(DominatorTree::VerificationLevel::Full) &&
409 "DT broken during transformation!");
410#else
411 assert(DT.verify(DominatorTree::VerificationLevel::Fast) &&
412 "DT broken during transformation!");
413#endif
414
415 // Create new loop bound and add it into preheader of pre-loop.
416 const SCEV *NewBoundSCEV = ExitingCond.BoundSCEV;
417 const SCEV *SplitBoundSCEV = SplitCandidateCond.BoundSCEV;
418 NewBoundSCEV = ICmpInst::isSigned(ExitingCond.Pred)
419 ? SE.getSMinExpr(NewBoundSCEV, SplitBoundSCEV)
420 : SE.getUMinExpr(NewBoundSCEV, SplitBoundSCEV);
421
422 SCEVExpander Expander(SE, "split");
423 Instruction *InsertPt = SplitLoopPH->getTerminator();
424 Value *NewBoundValue =
425 Expander.expandCodeFor(NewBoundSCEV, NewBoundSCEV->getType(), InsertPt);
426 NewBoundValue->setName("new.bound");
427
428 // Replace exiting bound value of pre-loop NewBound.
429 ExitingCond.ICmp->setOperand(1, NewBoundValue);
430
431 // Replace SplitCandidateCond.BI's condition of pre-loop by True.
432 LLVMContext &Context = PreHeader->getContext();
433 SplitCandidateCond.BI->setCondition(ConstantInt::getTrue(Context));
434
435 // Replace cloned SplitCandidateCond.BI's condition in post-loop by False.
436 CondBrInst *ClonedSplitCandidateBI =
437 cast<CondBrInst>(VMap[SplitCandidateCond.BI]);
438 ClonedSplitCandidateBI->setCondition(ConstantInt::getFalse(Context));
439
440 // Update phi node in exit block of post-loop.
441 Builder.SetInsertPoint(PostLoopPreHeader, PostLoopPreHeader->begin());
442 for (PHINode &PN : PostLoop->getExitBlock()->phis()) {
443 for (auto i : seq<int>(0, PN.getNumOperands())) {
444 // Check incoming block is pre-loop's exiting block.
445 if (PN.getIncomingBlock(i) == L.getExitingBlock()) {
446 Value *IncomingValue = PN.getIncomingValue(i);
447
448 // Create LCSSA phi node for incoming value.
449 PHINode *LCSSAPhi =
450 Builder.CreatePHI(PN.getType(), 1, PN.getName() + ".lcssa");
451 LCSSAPhi->setDebugLoc(PN.getDebugLoc());
452 LCSSAPhi->addIncoming(IncomingValue, PN.getIncomingBlock(i));
453
454 // Replace pre-loop's exiting block by post-loop's preheader.
455 PN.setIncomingBlock(i, PostLoopPreHeader);
456 // Replace incoming value by LCSSAPhi.
457 PN.setIncomingValue(i, LCSSAPhi);
458 // Add a new incoming value with post-loop's exiting block.
459 PN.addIncoming(VMap[IncomingValue], PostLoop->getExitingBlock());
460 }
461 }
462 }
463
464 // Invalidate cached SE information.
465 SE.forgetLoop(&L);
466
467 // Canonicalize loops.
468 simplifyLoop(&L, &DT, &LI, &SE, nullptr, nullptr, true);
469 simplifyLoop(PostLoop, &DT, &LI, &SE, nullptr, nullptr, true);
470
471 // Add new post-loop to loop pass manager.
472 U.addSiblingLoops(PostLoop);
473
474 return true;
475}
476
479 LPMUpdater &U) {
480 [[maybe_unused]] Function &F = *L.getHeader()->getParent();
481
482 LLVM_DEBUG(dbgs() << "Spliting bound of loop in " << F.getName() << ": " << L
483 << "\n");
484
485 if (!splitLoopBound(L, AR.DT, AR.LI, AR.SE, U))
486 return PreservedAnalyses::all();
487
488 assert(AR.DT.verify(DominatorTree::VerificationLevel::Fast));
489 AR.LI.verify();
490
492}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This header provides classes for managing per-loop analyses.
static bool canSplitLoopBound(const Loop &L, const DominatorTree &DT, ScalarEvolution &SE, ConditionInfo &Cond)
static bool isProfitableToTransform(const Loop &L, const CondBrInst *BI)
static bool isProcessableCondBI(const ScalarEvolution &SE, const CondBrInst *BI)
static bool splitLoopBound(Loop &L, DominatorTree &DT, LoopInfo &LI, ScalarEvolution &SE, LPMUpdater &U)
static bool hasProcessableCondition(const Loop &L, ScalarEvolution &SE, ICmpInst *ICmp, ConditionInfo &Cond, bool IsExitCond)
Check whether ICmp compares an induction variable of L against a bound this pass can split on,...
static CondBrInst * findSplitCandidate(const Loop &L, ScalarEvolution &SE, ConditionInfo &ExitingCond, ConditionInfo &SplitCandidateCond)
static bool calculateUpperBound(const Loop &L, ScalarEvolution &SE, ConditionInfo &Cond, bool IsExitCond)
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
#define F(x, y, z)
Definition MD5.cpp:54
const SmallVectorImpl< MachineOperand > & Cond
Provides some synthesis utilities to produce sequences of values.
#define LLVM_DEBUG(...)
Definition Debug.h:119
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition APInt.h:202
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition APInt.h:205
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator begin()
Instruction iterator methods.
Definition BasicBlock.h:446
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition BasicBlock.h:515
const Instruction & front() const
Definition BasicBlock.h:469
LLVM_ABI const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ ICMP_SLT
signed less than
Definition InstrTypes.h:769
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:766
bool isSigned() const
Definition InstrTypes.h:993
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition InstrTypes.h:890
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Conditional Branch instruction.
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
void setCondition(Value *V)
Value * getCondition() const
BasicBlock * getSuccessor(unsigned i) const
This is the shared class of boolean and integer constants.
Definition Constants.h:87
bool isNegative() const
Definition Constants.h:214
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition Constants.h:219
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition Constants.h:159
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...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
This instruction compares its operands according to the predicate given to the constructor.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2908
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.
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
BlockT * getHeader() const
BlockT * getExitBlock() const
If getExitBlocks would return exactly one block, return that block.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
BlockT * getExitingBlock() const
If getExitingBlocks would return exactly one block, return that block.
LLVM_ABI PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
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.
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 node represents a polynomial recurrence on the trip count of the specified loop.
This class uses information about analyze scalars to rewrite expressions in canonical form.
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 bool isLoopEntryGuardedByCond(const Loop *L, CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
Test whether entry to the loop is protected by a conditional between LHS and RHS.
LLVM_ABI const SCEV * getSMinExpr(SCEVUse LHS, SCEVUse RHS)
LLVM_ABI const SCEV * getConstant(ConstantInt *V)
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
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...
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI bool isAvailableAtLoopEntry(const SCEV *S, const Loop *L)
Determine if the SCEV can be evaluated at loop's entry.
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 bool isKnownPredicate(CmpPredicate Pred, SCEVUse LHS, SCEVUse RHS)
Test if the given expression is known to satisfy the condition described by Pred, LHS,...
LLVM_ABI const SCEV * getUMinExpr(SCEVUse LHS, SCEVUse RHS, bool Sequential=false)
LLVM_ABI SCEVUse getAddExpr(SmallVectorImpl< SCEVUse > &Ops, SCEVFlags Flags={}, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void setOperand(unsigned i, Value *Val)
Definition User.h:212
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
Definition Value.cpp:394
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.
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
brc_match< Cond_t, match_bind< BasicBlock >, match_bind< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, AssumptionCache *AC, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
Simplify each loop in a loop nest recursively.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
LLVM_ABI Loop * cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB, Loop *OrigLoop, ValueToValueMapTy &VMap, const Twine &NameSuffix, LoopInfo *LI, DominatorTree *DT, SmallVectorImpl< BasicBlock * > &Blocks)
Clones a loop OrigLoop.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
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 void remapInstructionsInBlocks(ArrayRef< BasicBlock * > Blocks, ValueToValueMapTy &VMap)
Remaps instructions in Blocks using the mapping in VMap.
constexpr unsigned BitWidth
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
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...
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...