LLVM 24.0.0git
LoopVersioningLICM.cpp
Go to the documentation of this file.
1//===- LoopVersioningLICM.cpp - LICM Loop Versioning ----------------------===//
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// When alias analysis is uncertain about the aliasing between any two accesses,
10// it will return MayAlias. This uncertainty from alias analysis restricts LICM
11// from proceeding further. In cases where alias analysis is uncertain we might
12// use loop versioning as an alternative.
13//
14// Loop Versioning will create a version of the loop with aggressive aliasing
15// assumptions in addition to the original with conservative (default) aliasing
16// assumptions. The version of the loop making aggressive aliasing assumptions
17// will have all the memory accesses marked as no-alias. These two versions of
18// loop will be preceded by a memory runtime check. This runtime check consists
19// of bound checks for all unique memory accessed in loop, and it ensures the
20// lack of memory aliasing. The result of the runtime check determines which of
21// the loop versions is executed: If the runtime check detects any memory
22// aliasing, then the original loop is executed. Otherwise, the version with
23// aggressive aliasing assumptions is used.
24//
25// Following are the top level steps:
26//
27// a) Perform LoopVersioningLICM's feasibility check.
28// b) If loop is a candidate for versioning then create a memory bound check,
29// by considering all the memory accesses in loop body.
30// c) Clone original loop and set all memory accesses as no-alias in new loop.
31// d) Set original loop & versioned loop as a branch target of the runtime check
32// result.
33//
34// It transforms loop as shown below:
35//
36// +----------------+
37// |Runtime Memcheck|
38// +----------------+
39// |
40// +----------+----------------+----------+
41// | |
42// +---------+----------+ +-----------+----------+
43// |Orig Loop Preheader | |Cloned Loop Preheader |
44// +--------------------+ +----------------------+
45// | |
46// +--------------------+ +----------------------+
47// |Orig Loop Body | |Cloned Loop Body |
48// +--------------------+ +----------------------+
49// | |
50// +--------------------+ +----------------------+
51// |Orig Loop Exit Block| |Cloned Loop Exit Block|
52// +--------------------+ +-----------+----------+
53// | |
54// +----------+--------------+-----------+
55// |
56// +-----+----+
57// |Join Block|
58// +----------+
59//
60//===----------------------------------------------------------------------===//
61
64#include "llvm/ADT/StringRef.h"
73#include "llvm/IR/Dominators.h"
74#include "llvm/IR/Instruction.h"
76#include "llvm/IR/LLVMContext.h"
77#include "llvm/IR/MDBuilder.h"
78#include "llvm/IR/Metadata.h"
79#include "llvm/IR/Value.h"
82#include "llvm/Support/Debug.h"
86#include <cassert>
87
88using namespace llvm;
89
90#define DEBUG_TYPE "loop-versioning-licm"
91
92static const char *LICMVersioningMetaData = "llvm.loop.licm_versioning.disable";
93
94/// Threshold minimum allowed percentage for possible
95/// invariant instructions in a loop.
96static cl::opt<float>
97 LVInvarThreshold("licm-versioning-invariant-threshold",
98 cl::desc("LoopVersioningLICM's minimum allowed percentage "
99 "of possible invariant instructions per loop"),
100 cl::init(25), cl::Hidden);
101
102/// Threshold for maximum allowed loop nest/depth
104 "licm-versioning-max-depth-threshold",
105 cl::desc(
106 "LoopVersioningLICM's threshold for maximum allowed loop nest/depth"),
107 cl::init(2), cl::Hidden);
108
109namespace {
110
111struct LoopVersioningLICM {
112 // We don't explicitly pass in LoopAccessInfo to the constructor since the
113 // loop versioning might return early due to instructions that are not safe
114 // for versioning. By passing the proxy instead the construction of
115 // LoopAccessInfo will take place only when it's necessary.
116 LoopVersioningLICM(AliasAnalysis *AA, ScalarEvolution *SE,
119 Loop *CurLoop)
120 : AA(AA), SE(SE), LAIs(LAIs), LI(LI), CurLoop(CurLoop),
121 LoopDepthThreshold(LVLoopDepthThreshold),
122 InvariantThreshold(LVInvarThreshold), ORE(ORE) {}
123
124 bool run(DominatorTree *DT);
125
126private:
127 // Current AliasAnalysis information
128 AliasAnalysis *AA;
129
130 // Current ScalarEvolution
131 ScalarEvolution *SE;
132
133 // Current Loop's LoopAccessInfo
134 const LoopAccessInfo *LAI = nullptr;
135
136 // Proxy for retrieving LoopAccessInfo.
137 LoopAccessInfoManager &LAIs;
138
139 LoopInfo &LI;
140
141 // The current loop we are working on.
142 Loop *CurLoop;
143
144 // Maximum loop nest threshold
145 unsigned LoopDepthThreshold;
146
147 // Minimum invariant threshold
148 float InvariantThreshold;
149
150 // Counter to track num of load & store
151 unsigned LoadAndStoreCounter = 0;
152
153 // Counter to track num of invariant
154 unsigned InvariantCounter = 0;
155
156 // Read only loop marker.
157 bool IsReadOnlyLoop = true;
158
159 // OptimizationRemarkEmitter
160 OptimizationRemarkEmitter *ORE;
161
162 bool isLegalForVersioning();
163 bool legalLoopStructure();
164 bool legalLoopInstructions();
165 bool legalLoopMemoryAccesses();
166 bool isLoopAlreadyVisited();
167 bool instructionSafeForVersioning(Instruction *I);
168};
169
170} // end anonymous namespace
171
172/// Check loop structure and confirms it's good for LoopVersioningLICM.
173bool LoopVersioningLICM::legalLoopStructure() {
174 // Loop must be in loop simplify form.
175 if (!CurLoop->isLoopSimplifyForm()) {
176 LLVM_DEBUG(dbgs() << " loop is not in loop-simplify form.\n");
177 return false;
178 }
179 // Loop should be innermost loop, if not return false.
180 if (!CurLoop->getSubLoops().empty()) {
181 LLVM_DEBUG(dbgs() << " loop is not innermost\n");
182 return false;
183 }
184 // Loop should have a single backedge, if not return false.
185 if (CurLoop->getNumBackEdges() != 1) {
186 LLVM_DEBUG(dbgs() << " loop has multiple backedges\n");
187 return false;
188 }
189 // Loop must have a single exiting block, if not return false.
190 if (!CurLoop->getExitingBlock()) {
191 LLVM_DEBUG(dbgs() << " loop has multiple exiting block\n");
192 return false;
193 }
194 // We only handle bottom-tested loop, i.e. loop in which the condition is
195 // checked at the end of each iteration. With that we can assume that all
196 // instructions in the loop are executed the same number of times.
197 if (CurLoop->getExitingBlock() != CurLoop->getLoopLatch()) {
198 LLVM_DEBUG(dbgs() << " loop is not bottom tested\n");
199 return false;
200 }
201 // Parallel loops must not have aliasing loop-invariant memory accesses.
202 // Hence we don't need to version anything in this case.
203 if (CurLoop->isAnnotatedParallel()) {
204 LLVM_DEBUG(dbgs() << " Parallel loop is not worth versioning\n");
205 return false;
206 }
207 // Loop depth more then LoopDepthThreshold are not allowed
208 if (CurLoop->getLoopDepth() > LoopDepthThreshold) {
209 LLVM_DEBUG(dbgs() << " loop depth is more than threshold\n");
210 return false;
211 }
212 // We need to be able to compute the loop trip count in order
213 // to generate the bound checks.
214 const SCEV *ExitCount = SE->getBackedgeTakenCount(CurLoop);
215 if (isa<SCEVCouldNotCompute>(ExitCount)) {
216 LLVM_DEBUG(dbgs() << " loop does not have trip count\n");
217 return false;
218 }
219 return true;
220}
221
222/// Check memory accesses in loop and confirms it's good for
223/// LoopVersioningLICM.
224bool LoopVersioningLICM::legalLoopMemoryAccesses() {
225 // Loop over the body of this loop, construct AST.
226 BatchAAResults BAA(*AA);
227 AliasSetTracker AST(BAA);
228 for (auto *Block : CurLoop->getBlocks()) {
229 // Ignore blocks in subloops.
230 if (LI.getLoopFor(Block) == CurLoop)
231 AST.add(*Block);
232 }
233
234 // Memory check:
235 // Transform phase will generate a versioned loop and also a runtime check to
236 // ensure the pointers are independent and they don’t alias.
237 // In version variant of loop, alias meta data asserts that all access are
238 // mutually independent.
239 //
240 // Pointers aliasing in alias domain are avoided because with multiple
241 // aliasing domains we may not be able to hoist potential loop invariant
242 // access out of the loop.
243 //
244 // Iterate over alias tracker sets, and confirm AliasSets doesn't have any
245 // must alias set.
246 bool HasMayAlias = false;
247 bool TypeSafety = false;
248 bool HasMod = false;
249 for (const auto &I : AST) {
250 const AliasSet &AS = I;
251 // Skip Forward Alias Sets, as this should be ignored as part of
252 // the AliasSetTracker object.
253 if (AS.isForwardingAliasSet())
254 continue;
255 // With MustAlias its not worth adding runtime bound check.
256 if (AS.isMustAlias())
257 return false;
258 const Value *SomePtr = AS.begin()->Ptr;
259 bool TypeCheck = true;
260 // Check for Mod & MayAlias
261 HasMayAlias |= AS.isMayAlias();
262 HasMod |= AS.isMod();
263 for (const auto &MemLoc : AS) {
264 const Value *Ptr = MemLoc.Ptr;
265 // Alias tracker should have pointers of same data type.
266 //
267 // FIXME: check no longer effective since opaque pointers?
268 // If the intent is to check that the memory accesses use the
269 // same data type (such that LICM can promote them), then we
270 // can no longer see this from the pointer value types.
271 TypeCheck = (TypeCheck && (SomePtr->getType() == Ptr->getType()));
272 }
273 // At least one alias tracker should have pointers of same data type.
274 TypeSafety |= TypeCheck;
275 }
276 // Ensure types should be of same type.
277 if (!TypeSafety) {
278 LLVM_DEBUG(dbgs() << " Alias tracker type safety failed!\n");
279 return false;
280 }
281 // Ensure loop body shouldn't be read only.
282 if (!HasMod) {
283 LLVM_DEBUG(dbgs() << " No memory modified in loop body\n");
284 return false;
285 }
286 // Make sure alias set has may alias case.
287 // If there no alias memory ambiguity, return false.
288 if (!HasMayAlias) {
289 LLVM_DEBUG(dbgs() << " No ambiguity in memory access.\n");
290 return false;
291 }
292 return true;
293}
294
295/// Check loop instructions safe for Loop versioning.
296/// It returns true if it's safe else returns false.
297/// Consider following:
298/// 1) Check all load store in loop body are non atomic & non volatile.
299/// 2) Check function call safety, by ensuring its not accessing memory.
300/// 3) Loop body shouldn't have any may throw instruction.
301/// 4) Loop body shouldn't have any convergent or noduplicate instructions.
302bool LoopVersioningLICM::instructionSafeForVersioning(Instruction *I) {
303 assert(I != nullptr && "Null instruction found!");
304 // Check function call safety
305 if (auto *Call = dyn_cast<CallBase>(I)) {
306 if (Call->isConvergent() || Call->cannotDuplicate()) {
307 LLVM_DEBUG(dbgs() << " Convergent call site found.\n");
308 return false;
309 }
310 if (!Call->willReturn()) {
311 LLVM_DEBUG(dbgs() << " Call site that may not return found.\n");
312 return false;
313 }
314
315 // Calls that only access inaccessible memory cannot alias loop memory and
316 // are safe to duplicate during loop versioning. This covers
317 // llvm.pseudoprobe (used for sample-based profiling under
318 // -fpseudo-probe-for-profiling).
319 if (Call->mayThrow() ||
321 LLVM_DEBUG(dbgs() << " Unsafe call site found.\n");
322 return false;
323 }
324 return true;
325 }
326
327 // Avoid loops with possiblity of throw
328 if (I->mayThrow()) {
329 LLVM_DEBUG(dbgs() << " May throw instruction found in loop body\n");
330 return false;
331 }
332 // If current instruction is load instructions
333 // make sure it's a simple load (non atomic & non volatile)
334 if (I->mayReadFromMemory()) {
335 LoadInst *Ld = dyn_cast<LoadInst>(I);
336 if (!Ld || !Ld->isSimple()) {
337 LLVM_DEBUG(dbgs() << " Found a non-simple load.\n");
338 return false;
339 }
340 LoadAndStoreCounter++;
341 Value *Ptr = Ld->getPointerOperand();
342 // Check loop invariant.
343 if (SE->isLoopInvariant(SE->getSCEV(Ptr), CurLoop))
344 InvariantCounter++;
345 }
346 // If current instruction is store instruction
347 // make sure it's a simple store (non atomic & non volatile)
348 else if (I->mayWriteToMemory()) {
349 StoreInst *St = dyn_cast<StoreInst>(I);
350 if (!St || !St->isSimple()) {
351 LLVM_DEBUG(dbgs() << " Found a non-simple store.\n");
352 return false;
353 }
354 LoadAndStoreCounter++;
355 Value *Ptr = St->getPointerOperand();
356 // Don't allow stores that we don't have runtime checks for, as we won't be
357 // able to mark them noalias meaning they would prevent any code motion.
358 auto &Pointers = LAI->getRuntimePointerChecking()->Pointers;
359 if (!any_of(Pointers, [&](auto &P) { return P.PointerValue == Ptr; })) {
360 LLVM_DEBUG(dbgs() << " Found a store without a runtime check.\n");
361 return false;
362 }
363 // Check loop invariant.
364 if (SE->isLoopInvariant(SE->getSCEV(Ptr), CurLoop))
365 InvariantCounter++;
366
367 IsReadOnlyLoop = false;
368 }
369 return true;
370}
371
372/// Check loop instructions and confirms it's good for
373/// LoopVersioningLICM.
374bool LoopVersioningLICM::legalLoopInstructions() {
375 // Resetting counters.
376 LoadAndStoreCounter = 0;
377 InvariantCounter = 0;
378 IsReadOnlyLoop = true;
379 using namespace ore;
380 // Get LoopAccessInfo from current loop via the proxy.
381 LAI = &LAIs.getInfo(*CurLoop, /*AllowPartial=*/true);
382 // Check LoopAccessInfo for need of runtime check.
383 if (LAI->getRuntimePointerChecking()->getChecks().empty()) {
384 LLVM_DEBUG(dbgs() << " LAA: Runtime check not found !!\n");
385 return false;
386 }
387 // Iterate over loop blocks and instructions of each block and check
388 // instruction safety.
389 for (auto *Block : CurLoop->getBlocks())
390 for (auto &Inst : *Block) {
391 // If instruction is unsafe just return false.
392 if (!instructionSafeForVersioning(&Inst)) {
393 ORE->emit([&]() {
394 return OptimizationRemarkMissed(DEBUG_TYPE, "IllegalLoopInst", &Inst)
395 << " Unsafe Loop Instruction";
396 });
397 return false;
398 }
399 }
400 // Number of runtime-checks should be less then RuntimeMemoryCheckThreshold
401 if (LAI->getNumRuntimePointerChecks() >
404 dbgs() << " LAA: Runtime checks are more than threshold !!\n");
405 ORE->emit([&]() {
406 return OptimizationRemarkMissed(DEBUG_TYPE, "RuntimeCheck",
407 CurLoop->getStartLoc(),
408 CurLoop->getHeader())
409 << "Number of runtime checks "
410 << NV("RuntimeChecks", LAI->getNumRuntimePointerChecks())
411 << " exceeds threshold "
413 });
414 return false;
415 }
416 // Loop should have at least one invariant load or store instruction.
417 if (!InvariantCounter) {
418 LLVM_DEBUG(dbgs() << " Invariant not found !!\n");
419 return false;
420 }
421 // Read only loop not allowed.
422 if (IsReadOnlyLoop) {
423 LLVM_DEBUG(dbgs() << " Found a read-only loop!\n");
424 return false;
425 }
426 // Profitability check:
427 // Check invariant threshold, should be in limit.
428 if (InvariantCounter * 100 < InvariantThreshold * LoadAndStoreCounter) {
430 dbgs()
431 << " Invariant load & store are less then defined threshold\n");
432 LLVM_DEBUG(dbgs() << " Invariant loads & stores: "
433 << ((InvariantCounter * 100) / LoadAndStoreCounter)
434 << "%\n");
435 LLVM_DEBUG(dbgs() << " Invariant loads & store threshold: "
436 << InvariantThreshold << "%\n");
437 ORE->emit([&]() {
438 return OptimizationRemarkMissed(DEBUG_TYPE, "InvariantThreshold",
439 CurLoop->getStartLoc(),
440 CurLoop->getHeader())
441 << "Invariant load & store "
442 << NV("LoadAndStoreCounter",
443 ((InvariantCounter * 100) / LoadAndStoreCounter))
444 << " are less then defined threshold "
445 << NV("Threshold", InvariantThreshold);
446 });
447 return false;
448 }
449 return true;
450}
451
452/// It checks loop is already visited or not.
453/// check loop meta data, if loop revisited return true
454/// else false.
455bool LoopVersioningLICM::isLoopAlreadyVisited() {
456 // Check LoopVersioningLICM metadata into loop
458 return true;
459 }
460 return false;
461}
462
463/// Checks legality for LoopVersioningLICM by considering following:
464/// a) loop structure legality b) loop instruction legality
465/// c) loop memory access legality.
466/// Return true if legal else returns false.
467bool LoopVersioningLICM::isLegalForVersioning() {
468 using namespace ore;
469 LLVM_DEBUG(dbgs() << "Loop: " << *CurLoop);
470 // Make sure not re-visiting same loop again.
471 if (isLoopAlreadyVisited()) {
473 dbgs() << " Revisiting loop in LoopVersioningLICM not allowed.\n\n");
474 return false;
475 }
476 // Check loop structure leagality.
477 if (!legalLoopStructure()) {
479 dbgs() << " Loop structure not suitable for LoopVersioningLICM\n\n");
480 ORE->emit([&]() {
481 return OptimizationRemarkMissed(DEBUG_TYPE, "IllegalLoopStruct",
482 CurLoop->getStartLoc(),
483 CurLoop->getHeader())
484 << " Unsafe Loop structure";
485 });
486 return false;
487 }
488 // Check loop instruction leagality.
489 if (!legalLoopInstructions()) {
491 dbgs()
492 << " Loop instructions not suitable for LoopVersioningLICM\n\n");
493 return false;
494 }
495 // Check loop memory access leagality.
496 if (!legalLoopMemoryAccesses()) {
498 dbgs()
499 << " Loop memory access not suitable for LoopVersioningLICM\n\n");
500 ORE->emit([&]() {
501 return OptimizationRemarkMissed(DEBUG_TYPE, "IllegalLoopMemoryAccess",
502 CurLoop->getStartLoc(),
503 CurLoop->getHeader())
504 << " Unsafe Loop memory access";
505 });
506 return false;
507 }
508 // Loop versioning is feasible, return true.
509 LLVM_DEBUG(dbgs() << " Loop Versioning found to be beneficial\n\n");
510 ORE->emit([&]() {
511 return OptimizationRemark(DEBUG_TYPE, "IsLegalForVersioning",
512 CurLoop->getStartLoc(), CurLoop->getHeader())
513 << " Versioned loop for LICM."
514 << " Number of runtime checks we had to insert "
515 << NV("RuntimeChecks", LAI->getNumRuntimePointerChecks());
516 });
517 return true;
518}
519
520bool LoopVersioningLICM::run(DominatorTree *DT) {
521 // Do not do the transformation if disabled by metadata.
523 return false;
524
525 bool Changed = false;
526
527 // Check feasiblity of LoopVersioningLICM.
528 // If versioning found to be feasible and beneficial then proceed
529 // else simply return, by cleaning up memory.
530 if (isLegalForVersioning()) {
531 // Do loop versioning.
532 // Create memcheck for memory accessed inside loop.
533 // Clone original loop, and set blocks properly.
534 LoopVersioning LVer(*LAI, LAI->getRuntimePointerChecking()->getChecks(),
535 CurLoop, &LI, DT, SE);
536 LVer.versionLoop();
537 // Set Loop Versioning metaData for original loop.
538 addStringMetadataToLoop(LVer.getNonVersionedLoop(), LICMVersioningMetaData);
539 // Set Loop Versioning metaData for version loop.
540 addStringMetadataToLoop(LVer.getVersionedLoop(), LICMVersioningMetaData);
541 // Set "llvm.mem.parallel_loop_access" metaData to versioned loop.
542 // FIXME: "llvm.mem.parallel_loop_access" annotates memory access
543 // instructions, not loops.
544 addStringMetadataToLoop(LVer.getVersionedLoop(),
545 "llvm.mem.parallel_loop_access");
546 // Update version loop with aggressive aliasing assumption.
547 LVer.annotateLoopWithNoAlias();
548 Changed = true;
549 }
550 return Changed;
551}
552
555 LPMUpdater &U) {
556 AliasAnalysis *AA = &LAR.AA;
557 ScalarEvolution *SE = &LAR.SE;
558 DominatorTree *DT = &LAR.DT;
559 const Function *F = L.getHeader()->getParent();
561
562 LoopAccessInfoManager LAIs(*SE, *AA, *DT, LAR.LI, nullptr, nullptr, &LAR.AC);
563 if (!LoopVersioningLICM(AA, SE, &ORE, LAIs, LAR.LI, &L).run(DT))
564 return PreservedAnalyses::all();
566}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define DEBUG_TYPE
This is the interface for a simple mod/ref and alias analysis over globals.
static const char * LICMVersioningMetaData
static cl::opt< unsigned > LVLoopDepthThreshold("licm-versioning-max-depth-threshold", cl::desc("LoopVersioningLICM's threshold for maximum allowed loop nest/depth"), cl::init(2), cl::Hidden)
Threshold for maximum allowed loop nest/depth.
static cl::opt< float > LVInvarThreshold("licm-versioning-invariant-threshold", cl::desc("LoopVersioningLICM's minimum allowed percentage " "of possible invariant instructions per loop"), cl::init(25), cl::Hidden)
Threshold minimum allowed percentage for possible invariant instructions in a loop.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
#define P(N)
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:119
LLVM_ABI MemoryEffects getMemoryEffects(const CallBase *Call)
Return the behavior of the given call site.
iterator begin() const
bool isMayAlias() const
bool isForwardingAliasSet() const
Return true if this alias set should be ignored as part of the AliasSetTracker object.
bool isMustAlias() const
bool isMod() const
bool cannotDuplicate() const
Determine if the invoke cannot be duplicated.
bool isConvergent() const
Determine if the invoke is convergent.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:151
LLVM_ABI bool mayThrow(bool IncludePhaseOneUnwind=false) const LLVM_READONLY
Return true if this instruction may throw an exception.
LLVM_ABI bool willReturn() const LLVM_READONLY
Return true if the instruction will return (unwinding is considered as a form of returning control fl...
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
Value * getPointerOperand()
bool isSimple() const
LLVM_ABI const LoopAccessInfo & getInfo(Loop &L, bool AllowPartial=false)
const RuntimePointerChecking * getRuntimePointerChecking() const
unsigned getNumRuntimePointerChecks() const
Number of memchecks required to prove independence of otherwise may-alias pointers.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
unsigned getNumBackEdges() const
Calculate the number of back edges to the loop header.
const std::vector< LoopT * > & getSubLoops() const
Return the loops contained entirely within this loop.
BlockT * getHeader() const
unsigned getLoopDepth() const
Return the nesting level of this loop.
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
BlockT * getExitingBlock() const
If getExitingBlocks would return exactly one block, return that block.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
LLVM_ABI PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &LAR, LPMUpdater &U)
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
bool isAnnotatedParallel() const
Returns true if the loop is annotated parallel.
Definition LoopInfo.cpp:602
DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
Definition LoopInfo.cpp:669
bool isLoopSimplifyForm() const
Return true if the Loop is in the form that the LoopSimplify form transforms loops to,...
Definition LoopInfo.cpp:511
bool onlyAccessesInaccessibleMem() const
Whether this function only (at most) accesses inaccessible memory.
Definition ModRef.h:265
The optimization diagnostic interface.
LLVM_ABI void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file.
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
SmallVector< PointerInfo, 2 > Pointers
Information about the pointers that may require checking.
const SmallVectorImpl< RuntimePointerCheck > & getChecks() const
Returns the checks that generateChecks created.
The main scalar evolution driver.
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 const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
LLVM_ABI bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
bool isSimple() const
Value * getPointerOperand()
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
CallInst * Call
Changed
Abstract Attribute helper functions.
Definition Attributor.h:165
initializer< Ty > init(const Ty &Val)
DXILDebugInfoMap run(Module &M)
DiagnosticInfoOptimizationBase::Argument NV
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 std::optional< const MDOperand * > findStringMetadataForLoop(const Loop *TheLoop, StringRef Name)
Find string metadata for loop.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI void addStringMetadataToLoop(Loop *TheLoop, const char *MDString, unsigned V=0)
Set input string into loop metadata by keeping other values intact.
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:1746
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 TransformationMode hasLICMVersioningTransformation(const Loop *L)
@ TM_Disable
The transformation should not be applied.
Definition LoopUtils.h:292
LLVM_ABI PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
static LLVM_ABI unsigned RuntimeMemoryCheckThreshold
\When performing memory disambiguation checks at runtime do not make more than this number of compari...