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,
282 LPMUpdater &U) {
283 ConditionInfo SplitCandidateCond;
284 ConditionInfo ExitingCond;
285
286 // Check we can split this loop's bound.
287 if (!canSplitLoopBound(L, DT, SE, ExitingCond))
288 return false;
289
290 if (!findSplitCandidate(L, SE, ExitingCond, SplitCandidateCond))
291 return false;
292
293 if (!isProfitableToTransform(L, SplitCandidateCond.BI))
294 return false;
295
296 // Now, we have a split candidate. Let's build a form as below.
297 // +--------------------+
298 // | preheader |
299 // | set up newbound |
300 // +--------------------+
301 // | /----------------\
302 // +--------v----v------+ |
303 // | header |---\ |
304 // | with true condition| | |
305 // +--------------------+ | |
306 // | | |
307 // +--------v-----------+ | |
308 // | if.then.BB | | |
309 // +--------------------+ | |
310 // | | |
311 // +--------v-----------<---/ |
312 // | latch >----------/
313 // | with newbound |
314 // +--------------------+
315 // |
316 // +--------v-----------+
317 // | preheader2 |--------------\
318 // | if (AddRec i != | |
319 // | org bound) | |
320 // +--------------------+ |
321 // | /----------------\ |
322 // +--------v----v------+ | |
323 // | header2 |---\ | |
324 // | conditional branch | | | |
325 // |with false condition| | | |
326 // +--------------------+ | | |
327 // | | | |
328 // +--------v-----------+ | | |
329 // | if.then.BB2 | | | |
330 // +--------------------+ | | |
331 // | | | |
332 // +--------v-----------<---/ | |
333 // | latch2 >----------/ |
334 // | with org bound | |
335 // +--------v-----------+ |
336 // | |
337 // | +---------------+ |
338 // +--> exit <-------/
339 // +---------------+
340
341 // Let's create post loop.
342 SmallVector<BasicBlock *, 8> PostLoopBlocks;
343 Loop *PostLoop;
345 BasicBlock *PreHeader = L.getLoopPreheader();
346 BasicBlock *SplitLoopPH = SplitEdge(PreHeader, L.getHeader(), &DT, &LI);
347 PostLoop = cloneLoopWithPreheader(L.getExitBlock(), SplitLoopPH, &L, VMap,
348 ".split", &LI, &DT, PostLoopBlocks);
349 remapInstructionsInBlocks(PostLoopBlocks, VMap, &AC);
350
351 BasicBlock *PostLoopPreHeader = PostLoop->getLoopPreheader();
352 IRBuilder<> Builder(&PostLoopPreHeader->front());
353
354 // Replace exit branch target of pre-loop by post-loop's preheader.
355 // Note: update the branch here after calling cloneLoopWithPreheader()
356 // to keep the IR valid.
357 if (L.getExitBlock() == ExitingCond.BI->getSuccessor(0))
358 ExitingCond.BI->setSuccessor(0, PostLoopPreHeader);
359 else
360 ExitingCond.BI->setSuccessor(1, PostLoopPreHeader);
361
362 // Update dominator tree.
363 DT.changeImmediateDominator(PostLoopPreHeader, L.getExitingBlock());
364#ifndef NDEBUG
365 LI.verify();
366#endif
367 // Update phi nodes in header of post-loop.
368 bool isExitingLatch = L.getExitingBlock() == L.getLoopLatch();
369 Value *ExitingCondLCSSAPhi = nullptr;
370 for (PHINode &PN : L.getHeader()->phis()) {
371 // Create LCSSA phi node in preheader of post-loop.
372 PHINode *LCSSAPhi =
373 Builder.CreatePHI(PN.getType(), 1, PN.getName() + ".lcssa");
374 LCSSAPhi->setDebugLoc(PN.getDebugLoc());
375 // If the exiting block is loop latch, the phi does not have the update at
376 // last iteration. In this case, update lcssa phi with value from backedge.
377 LCSSAPhi->addIncoming(
378 isExitingLatch ? PN.getIncomingValueForBlock(L.getLoopLatch()) : &PN,
379 L.getExitingBlock());
380
381 // Update the start value of phi node in post-loop with the LCSSA phi node.
382 PHINode *PostLoopPN = cast<PHINode>(VMap[&PN]);
383 PostLoopPN->setIncomingValueForBlock(PostLoopPreHeader, LCSSAPhi);
384
385 // Find PHI with exiting condition from pre-loop. The PHI should be
386 // SCEVAddRecExpr and have same incoming value from backedge with
387 // ExitingCond.
388 //
389 // TODO: Separate SCEV queries from PHI node updates.
390 if (!SE.isSCEVable(PN.getType()))
391 continue;
392
393 const SCEVAddRecExpr *PhiSCEV = dyn_cast<SCEVAddRecExpr>(SE.getSCEV(&PN));
394 if (PhiSCEV && ExitingCond.NonPHIAddRecValue ==
395 PN.getIncomingValueForBlock(L.getLoopLatch()))
396 ExitingCondLCSSAPhi = LCSSAPhi;
397 }
398
399 // Add conditional branch to check we can skip post-loop in its preheader,
400 // and update DT.
401 Instruction *OrigBI = PostLoopPreHeader->getTerminator();
403 Value *Cond =
404 Builder.CreateICmp(Pred, ExitingCondLCSSAPhi, ExitingCond.BoundValue);
405 Builder.CreateCondBr(Cond, PostLoop->getHeader(), PostLoop->getExitBlock());
406 OrigBI->eraseFromParent();
407 DT.changeImmediateDominator(PostLoop->getExitBlock(), PostLoopPreHeader);
408#ifdef EXPENSIVE_CHECKS
409 assert(DT.verify(DominatorTree::VerificationLevel::Full) &&
410 "DT broken during transformation!");
411#else
412 assert(DT.verify(DominatorTree::VerificationLevel::Fast) &&
413 "DT broken during transformation!");
414#endif
415
416 // Create new loop bound and add it into preheader of pre-loop.
417 const SCEV *NewBoundSCEV = ExitingCond.BoundSCEV;
418 const SCEV *SplitBoundSCEV = SplitCandidateCond.BoundSCEV;
419 NewBoundSCEV = ICmpInst::isSigned(ExitingCond.Pred)
420 ? SE.getSMinExpr(NewBoundSCEV, SplitBoundSCEV)
421 : SE.getUMinExpr(NewBoundSCEV, SplitBoundSCEV);
422
423 SCEVExpander Expander(SE, "split");
424 Instruction *InsertPt = SplitLoopPH->getTerminator();
425 Value *NewBoundValue =
426 Expander.expandCodeFor(NewBoundSCEV, NewBoundSCEV->getType(), InsertPt);
427 NewBoundValue->setName("new.bound");
428
429 // Replace exiting bound value of pre-loop NewBound.
430 ExitingCond.ICmp->setOperand(1, NewBoundValue);
431
432 // Replace SplitCandidateCond.BI's condition of pre-loop by True.
433 LLVMContext &Context = PreHeader->getContext();
434 SplitCandidateCond.BI->setCondition(ConstantInt::getTrue(Context));
435
436 // Replace cloned SplitCandidateCond.BI's condition in post-loop by False.
437 CondBrInst *ClonedSplitCandidateBI =
438 cast<CondBrInst>(VMap[SplitCandidateCond.BI]);
439 ClonedSplitCandidateBI->setCondition(ConstantInt::getFalse(Context));
440
441 // Update phi node in exit block of post-loop.
442 Builder.SetInsertPoint(PostLoopPreHeader->begin());
443 for (PHINode &PN : PostLoop->getExitBlock()->phis()) {
444 for (auto i : seq<int>(0, PN.getNumOperands())) {
445 // Check incoming block is pre-loop's exiting block.
446 if (PN.getIncomingBlock(i) == L.getExitingBlock()) {
447 Value *IncomingValue = PN.getIncomingValue(i);
448
449 // Create LCSSA phi node for incoming value.
450 PHINode *LCSSAPhi =
451 Builder.CreatePHI(PN.getType(), 1, PN.getName() + ".lcssa");
452 LCSSAPhi->setDebugLoc(PN.getDebugLoc());
453 LCSSAPhi->addIncoming(IncomingValue, PN.getIncomingBlock(i));
454
455 // Replace pre-loop's exiting block by post-loop's preheader.
456 PN.setIncomingBlock(i, PostLoopPreHeader);
457 // Replace incoming value by LCSSAPhi.
458 PN.setIncomingValue(i, LCSSAPhi);
459 // Add a new incoming value with post-loop's exiting block.
460 PN.addIncoming(VMap[IncomingValue], PostLoop->getExitingBlock());
461 }
462 }
463 }
464
465 // Invalidate cached SE information.
466 SE.forgetLoop(&L);
467
468 // Canonicalize loops.
469 simplifyLoop(&L, &DT, &LI, &SE, nullptr, nullptr, true);
470 simplifyLoop(PostLoop, &DT, &LI, &SE, nullptr, nullptr, true);
471
472 // Add new post-loop to loop pass manager.
473 U.addSiblingLoops(PostLoop);
474
475 return true;
476}
477
480 LPMUpdater &U) {
481 [[maybe_unused]] Function &F = *L.getHeader()->getParent();
482
483 LLVM_DEBUG(dbgs() << "Spliting bound of loop in " << F.getName() << ": " << L
484 << "\n");
485
486 if (!splitLoopBound(L, AR.DT, AR.LI, AR.SE, AR.AC, U))
487 return PreservedAnalyses::all();
488
489 assert(AR.DT.verify(DominatorTree::VerificationLevel::Fast));
490 AR.LI.verify();
491
493}
SDValue Pred
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 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 bool splitLoopBound(Loop &L, DominatorTree &DT, LoopInfo &LI, ScalarEvolution &SE, AssumptionCache &AC, LPMUpdater &U)
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
SmallVector< MachineOperand, 4 > 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
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:61
iterator begin()
Instruction iterator methods.
Definition BasicBlock.h:439
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition BasicBlock.h:508
const Instruction & front() const
Definition BasicBlock.h:462
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:236
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:2990
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:76
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 SCEVUse getAddExpr(SmallVectorImpl< SCEVUse > &Ops, SCEVFlagsPair Flags={}, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
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, unsigned Depth=0)
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)
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:389
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI void remapInstructionsInBlocks(ArrayRef< BasicBlock * > Blocks, ValueToValueMapTy &VMap, AssumptionCache *AC=nullptr)
Remaps instructions in Blocks using the mapping in VMap.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
LLVM_ABI bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, AssumptionCache *AC, MemorySSAUpdater *MSSAU, bool PreserveLCSSA, const TargetTransformInfo *TTI=nullptr)
Simplify each loop in a loop nest recursively.
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
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:881
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...