LLVM  4.0.0
LoopVersioningLICM.cpp
Go to the documentation of this file.
1 //===----------- LoopVersioningLICM.cpp - LICM Loop Versioning ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // When alias analysis is uncertain about the aliasing between any two accesses,
11 // it will return MayAlias. This uncertainty from alias analysis restricts LICM
12 // from proceeding further. In cases where alias analysis is uncertain we might
13 // use loop versioning as an alternative.
14 //
15 // Loop Versioning will create a version of the loop with aggressive aliasing
16 // assumptions in addition to the original with conservative (default) aliasing
17 // assumptions. The version of the loop making aggressive aliasing assumptions
18 // will have all the memory accesses marked as no-alias. These two versions of
19 // loop will be preceded by a memory runtime check. This runtime check consists
20 // of bound checks for all unique memory accessed in loop, and it ensures the
21 // lack of memory aliasing. The result of the runtime check determines which of
22 // the loop versions is executed: If the runtime check detects any memory
23 // aliasing, then the original loop is executed. Otherwise, the version with
24 // aggressive aliasing assumptions is used.
25 //
26 // Following are the top level steps:
27 //
28 // a) Perform LoopVersioningLICM's feasibility check.
29 // b) If loop is a candidate for versioning then create a memory bound check,
30 // by considering all the memory accesses in loop body.
31 // c) Clone original loop and set all memory accesses as no-alias in new loop.
32 // d) Set original loop & versioned loop as a branch target of the runtime check
33 // result.
34 //
35 // It transforms loop as shown below:
36 //
37 // +----------------+
38 // |Runtime Memcheck|
39 // +----------------+
40 // |
41 // +----------+----------------+----------+
42 // | |
43 // +---------+----------+ +-----------+----------+
44 // |Orig Loop Preheader | |Cloned Loop Preheader |
45 // +--------------------+ +----------------------+
46 // | |
47 // +--------------------+ +----------------------+
48 // |Orig Loop Body | |Cloned Loop Body |
49 // +--------------------+ +----------------------+
50 // | |
51 // +--------------------+ +----------------------+
52 // |Orig Loop Exit Block| |Cloned Loop Exit Block|
53 // +--------------------+ +-----------+----------+
54 // | |
55 // +----------+--------------+-----------+
56 // |
57 // +-----+----+
58 // |Join Block|
59 // +----------+
60 //
61 //===----------------------------------------------------------------------===//
62 
63 #include "llvm/ADT/MapVector.h"
64 #include "llvm/ADT/SmallPtrSet.h"
65 #include "llvm/ADT/Statistic.h"
66 #include "llvm/ADT/StringExtras.h"
72 #include "llvm/Analysis/LoopInfo.h"
73 #include "llvm/Analysis/LoopPass.h"
79 #include "llvm/IR/Dominators.h"
80 #include "llvm/IR/IntrinsicInst.h"
81 #include "llvm/IR/MDBuilder.h"
82 #include "llvm/IR/PatternMatch.h"
84 #include "llvm/IR/Type.h"
85 #include "llvm/Support/Debug.h"
87 #include "llvm/Transforms/Scalar.h"
93 
94 #define DEBUG_TYPE "loop-versioning-licm"
95 static const char *LICMVersioningMetaData = "llvm.loop.licm_versioning.disable";
96 
97 using namespace llvm;
98 
99 /// Threshold minimum allowed percentage for possible
100 /// invariant instructions in a loop.
101 static cl::opt<float>
102  LVInvarThreshold("licm-versioning-invariant-threshold",
103  cl::desc("LoopVersioningLICM's minimum allowed percentage"
104  "of possible invariant instructions per loop"),
105  cl::init(25), cl::Hidden);
106 
107 /// Threshold for maximum allowed loop nest/depth
109  "licm-versioning-max-depth-threshold",
110  cl::desc(
111  "LoopVersioningLICM's threshold for maximum allowed loop nest/depth"),
112  cl::init(2), cl::Hidden);
113 
114 /// \brief Create MDNode for input string.
115 static MDNode *createStringMetadata(Loop *TheLoop, StringRef Name, unsigned V) {
116  LLVMContext &Context = TheLoop->getHeader()->getContext();
117  Metadata *MDs[] = {
118  MDString::get(Context, Name),
120  return MDNode::get(Context, MDs);
121 }
122 
123 /// \brief Set input string into loop metadata by keeping other values intact.
124 void llvm::addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
125  unsigned V) {
127  // If the loop already has metadata, retain it.
128  MDNode *LoopID = TheLoop->getLoopID();
129  if (LoopID) {
130  for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
131  MDNode *Node = cast<MDNode>(LoopID->getOperand(i));
132  MDs.push_back(Node);
133  }
134  }
135  // Add new metadata.
136  MDs.push_back(createStringMetadata(TheLoop, MDString, V));
137  // Replace current metadata node with new one.
138  LLVMContext &Context = TheLoop->getHeader()->getContext();
139  MDNode *NewLoopID = MDNode::get(Context, MDs);
140  // Set operand 0 to refer to the loop id itself.
141  NewLoopID->replaceOperandWith(0, NewLoopID);
142  TheLoop->setLoopID(NewLoopID);
143 }
144 
145 namespace {
146 struct LoopVersioningLICM : public LoopPass {
147  static char ID;
148 
149  bool runOnLoop(Loop *L, LPPassManager &LPM) override;
150 
151  void getAnalysisUsage(AnalysisUsage &AU) const override {
152  AU.setPreservesCFG();
162  }
163 
164  LoopVersioningLICM()
165  : LoopPass(ID), AA(nullptr), SE(nullptr), LAA(nullptr), LAI(nullptr),
166  CurLoop(nullptr), LoopDepthThreshold(LVLoopDepthThreshold),
167  InvariantThreshold(LVInvarThreshold), LoadAndStoreCounter(0),
168  InvariantCounter(0), IsReadOnlyLoop(true) {
170  }
171  StringRef getPassName() const override { return "Loop Versioning for LICM"; }
172 
173  void reset() {
174  AA = nullptr;
175  SE = nullptr;
176  LAA = nullptr;
177  CurLoop = nullptr;
178  LoadAndStoreCounter = 0;
179  InvariantCounter = 0;
180  IsReadOnlyLoop = true;
181  CurAST.reset();
182  }
183 
184  class AutoResetter {
185  public:
186  AutoResetter(LoopVersioningLICM &LVLICM) : LVLICM(LVLICM) {}
187  ~AutoResetter() { LVLICM.reset(); }
188 
189  private:
190  LoopVersioningLICM &LVLICM;
191  };
192 
193 private:
194  AliasAnalysis *AA; // Current AliasAnalysis information
195  ScalarEvolution *SE; // Current ScalarEvolution
196  LoopAccessLegacyAnalysis *LAA; // Current LoopAccessAnalysis
197  const LoopAccessInfo *LAI; // Current Loop's LoopAccessInfo
198 
199  Loop *CurLoop; // The current loop we are working on.
200  std::unique_ptr<AliasSetTracker>
201  CurAST; // AliasSet information for the current loop.
202 
203  unsigned LoopDepthThreshold; // Maximum loop nest threshold
204  float InvariantThreshold; // Minimum invariant threshold
205  unsigned LoadAndStoreCounter; // Counter to track num of load & store
206  unsigned InvariantCounter; // Counter to track num of invariant
207  bool IsReadOnlyLoop; // Read only loop marker.
208 
209  bool isLegalForVersioning();
210  bool legalLoopStructure();
211  bool legalLoopInstructions();
212  bool legalLoopMemoryAccesses();
213  bool isLoopAlreadyVisited();
214  void setNoAliasToLoop(Loop *);
215  bool instructionSafeForVersioning(Instruction *);
216 };
217 }
218 
219 /// \brief Check loop structure and confirms it's good for LoopVersioningLICM.
220 bool LoopVersioningLICM::legalLoopStructure() {
221  // Loop must be in loop simplify form.
222  if (!CurLoop->isLoopSimplifyForm()) {
223  DEBUG(
224  dbgs() << " loop is not in loop-simplify form.\n");
225  return false;
226  }
227  // Loop should be innermost loop, if not return false.
228  if (CurLoop->getSubLoops().size()) {
229  DEBUG(dbgs() << " loop is not innermost\n");
230  return false;
231  }
232  // Loop should have a single backedge, if not return false.
233  if (CurLoop->getNumBackEdges() != 1) {
234  DEBUG(dbgs() << " loop has multiple backedges\n");
235  return false;
236  }
237  // Loop must have a single exiting block, if not return false.
238  if (!CurLoop->getExitingBlock()) {
239  DEBUG(dbgs() << " loop has multiple exiting block\n");
240  return false;
241  }
242  // We only handle bottom-tested loop, i.e. loop in which the condition is
243  // checked at the end of each iteration. With that we can assume that all
244  // instructions in the loop are executed the same number of times.
245  if (CurLoop->getExitingBlock() != CurLoop->getLoopLatch()) {
246  DEBUG(dbgs() << " loop is not bottom tested\n");
247  return false;
248  }
249  // Parallel loops must not have aliasing loop-invariant memory accesses.
250  // Hence we don't need to version anything in this case.
251  if (CurLoop->isAnnotatedParallel()) {
252  DEBUG(dbgs() << " Parallel loop is not worth versioning\n");
253  return false;
254  }
255  // Loop depth more then LoopDepthThreshold are not allowed
256  if (CurLoop->getLoopDepth() > LoopDepthThreshold) {
257  DEBUG(dbgs() << " loop depth is more then threshold\n");
258  return false;
259  }
260  // We need to be able to compute the loop trip count in order
261  // to generate the bound checks.
262  const SCEV *ExitCount = SE->getBackedgeTakenCount(CurLoop);
263  if (ExitCount == SE->getCouldNotCompute()) {
264  DEBUG(dbgs() << " loop does not has trip count\n");
265  return false;
266  }
267  return true;
268 }
269 
270 /// \brief Check memory accesses in loop and confirms it's good for
271 /// LoopVersioningLICM.
272 bool LoopVersioningLICM::legalLoopMemoryAccesses() {
273  bool HasMayAlias = false;
274  bool TypeSafety = false;
275  bool HasMod = false;
276  // Memory check:
277  // Transform phase will generate a versioned loop and also a runtime check to
278  // ensure the pointers are independent and they don’t alias.
279  // In version variant of loop, alias meta data asserts that all access are
280  // mutually independent.
281  //
282  // Pointers aliasing in alias domain are avoided because with multiple
283  // aliasing domains we may not be able to hoist potential loop invariant
284  // access out of the loop.
285  //
286  // Iterate over alias tracker sets, and confirm AliasSets doesn't have any
287  // must alias set.
288  for (const auto &I : *CurAST) {
289  const AliasSet &AS = I;
290  // Skip Forward Alias Sets, as this should be ignored as part of
291  // the AliasSetTracker object.
292  if (AS.isForwardingAliasSet())
293  continue;
294  // With MustAlias its not worth adding runtime bound check.
295  if (AS.isMustAlias())
296  return false;
297  Value *SomePtr = AS.begin()->getValue();
298  bool TypeCheck = true;
299  // Check for Mod & MayAlias
300  HasMayAlias |= AS.isMayAlias();
301  HasMod |= AS.isMod();
302  for (const auto &A : AS) {
303  Value *Ptr = A.getValue();
304  // Alias tracker should have pointers of same data type.
305  TypeCheck = (TypeCheck && (SomePtr->getType() == Ptr->getType()));
306  }
307  // At least one alias tracker should have pointers of same data type.
308  TypeSafety |= TypeCheck;
309  }
310  // Ensure types should be of same type.
311  if (!TypeSafety) {
312  DEBUG(dbgs() << " Alias tracker type safety failed!\n");
313  return false;
314  }
315  // Ensure loop body shouldn't be read only.
316  if (!HasMod) {
317  DEBUG(dbgs() << " No memory modified in loop body\n");
318  return false;
319  }
320  // Make sure alias set has may alias case.
321  // If there no alias memory ambiguity, return false.
322  if (!HasMayAlias) {
323  DEBUG(dbgs() << " No ambiguity in memory access.\n");
324  return false;
325  }
326  return true;
327 }
328 
329 /// \brief Check loop instructions safe for Loop versioning.
330 /// It returns true if it's safe else returns false.
331 /// Consider following:
332 /// 1) Check all load store in loop body are non atomic & non volatile.
333 /// 2) Check function call safety, by ensuring its not accessing memory.
334 /// 3) Loop body shouldn't have any may throw instruction.
335 bool LoopVersioningLICM::instructionSafeForVersioning(Instruction *I) {
336  assert(I != nullptr && "Null instruction found!");
337  // Check function call safety
338  if (isa<CallInst>(I) && !AA->doesNotAccessMemory(CallSite(I))) {
339  DEBUG(dbgs() << " Unsafe call site found.\n");
340  return false;
341  }
342  // Avoid loops with possiblity of throw
343  if (I->mayThrow()) {
344  DEBUG(dbgs() << " May throw instruction found in loop body\n");
345  return false;
346  }
347  // If current instruction is load instructions
348  // make sure it's a simple load (non atomic & non volatile)
349  if (I->mayReadFromMemory()) {
350  LoadInst *Ld = dyn_cast<LoadInst>(I);
351  if (!Ld || !Ld->isSimple()) {
352  DEBUG(dbgs() << " Found a non-simple load.\n");
353  return false;
354  }
355  LoadAndStoreCounter++;
356  Value *Ptr = Ld->getPointerOperand();
357  // Check loop invariant.
358  if (SE->isLoopInvariant(SE->getSCEV(Ptr), CurLoop))
359  InvariantCounter++;
360  }
361  // If current instruction is store instruction
362  // make sure it's a simple store (non atomic & non volatile)
363  else if (I->mayWriteToMemory()) {
364  StoreInst *St = dyn_cast<StoreInst>(I);
365  if (!St || !St->isSimple()) {
366  DEBUG(dbgs() << " Found a non-simple store.\n");
367  return false;
368  }
369  LoadAndStoreCounter++;
370  Value *Ptr = St->getPointerOperand();
371  // Check loop invariant.
372  if (SE->isLoopInvariant(SE->getSCEV(Ptr), CurLoop))
373  InvariantCounter++;
374 
375  IsReadOnlyLoop = false;
376  }
377  return true;
378 }
379 
380 /// \brief Check loop instructions and confirms it's good for
381 /// LoopVersioningLICM.
382 bool LoopVersioningLICM::legalLoopInstructions() {
383  // Resetting counters.
384  LoadAndStoreCounter = 0;
385  InvariantCounter = 0;
386  IsReadOnlyLoop = true;
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  return false;
394  }
395  // Get LoopAccessInfo from current loop.
396  LAI = &LAA->getInfo(CurLoop);
397  // Check LoopAccessInfo for need of runtime check.
398  if (LAI->getRuntimePointerChecking()->getChecks().empty()) {
399  DEBUG(dbgs() << " LAA: Runtime check not found !!\n");
400  return false;
401  }
402  // Number of runtime-checks should be less then RuntimeMemoryCheckThreshold
403  if (LAI->getNumRuntimePointerChecks() >
405  DEBUG(dbgs() << " LAA: Runtime checks are more than threshold !!\n");
406  return false;
407  }
408  // Loop should have at least one invariant load or store instruction.
409  if (!InvariantCounter) {
410  DEBUG(dbgs() << " Invariant not found !!\n");
411  return false;
412  }
413  // Read only loop not allowed.
414  if (IsReadOnlyLoop) {
415  DEBUG(dbgs() << " Found a read-only loop!\n");
416  return false;
417  }
418  // Profitablity check:
419  // Check invariant threshold, should be in limit.
420  if (InvariantCounter * 100 < InvariantThreshold * LoadAndStoreCounter) {
421  DEBUG(dbgs()
422  << " Invariant load & store are less then defined threshold\n");
423  DEBUG(dbgs() << " Invariant loads & stores: "
424  << ((InvariantCounter * 100) / LoadAndStoreCounter) << "%\n");
425  DEBUG(dbgs() << " Invariant loads & store threshold: "
426  << InvariantThreshold << "%\n");
427  return false;
428  }
429  return true;
430 }
431 
432 /// \brief It checks loop is already visited or not.
433 /// check loop meta data, if loop revisited return true
434 /// else false.
435 bool LoopVersioningLICM::isLoopAlreadyVisited() {
436  // Check LoopVersioningLICM metadata into loop
438  return true;
439  }
440  return false;
441 }
442 
443 /// \brief Checks legality for LoopVersioningLICM by considering following:
444 /// a) loop structure legality b) loop instruction legality
445 /// c) loop memory access legality.
446 /// Return true if legal else returns false.
447 bool LoopVersioningLICM::isLegalForVersioning() {
448  DEBUG(dbgs() << "Loop: " << *CurLoop);
449  // Make sure not re-visiting same loop again.
450  if (isLoopAlreadyVisited()) {
451  DEBUG(
452  dbgs() << " Revisiting loop in LoopVersioningLICM not allowed.\n\n");
453  return false;
454  }
455  // Check loop structure leagality.
456  if (!legalLoopStructure()) {
457  DEBUG(
458  dbgs() << " Loop structure not suitable for LoopVersioningLICM\n\n");
459  return false;
460  }
461  // Check loop instruction leagality.
462  if (!legalLoopInstructions()) {
463  DEBUG(dbgs()
464  << " Loop instructions not suitable for LoopVersioningLICM\n\n");
465  return false;
466  }
467  // Check loop memory access leagality.
468  if (!legalLoopMemoryAccesses()) {
469  DEBUG(dbgs()
470  << " Loop memory access not suitable for LoopVersioningLICM\n\n");
471  return false;
472  }
473  // Loop versioning is feasible, return true.
474  DEBUG(dbgs() << " Loop Versioning found to be beneficial\n\n");
475  return true;
476 }
477 
478 /// \brief Update loop with aggressive aliasing assumptions.
479 /// It marks no-alias to any pairs of memory operations by assuming
480 /// loop should not have any must-alias memory accesses pairs.
481 /// During LoopVersioningLICM legality we ignore loops having must
482 /// aliasing memory accesses.
483 void LoopVersioningLICM::setNoAliasToLoop(Loop *VerLoop) {
484  // Get latch terminator instruction.
485  Instruction *I = VerLoop->getLoopLatch()->getTerminator();
486  // Create alias scope domain.
487  MDBuilder MDB(I->getContext());
488  MDNode *NewDomain = MDB.createAnonymousAliasScopeDomain("LVDomain");
489  StringRef Name = "LVAliasScope";
490  SmallVector<Metadata *, 4> Scopes, NoAliases;
491  MDNode *NewScope = MDB.createAnonymousAliasScope(NewDomain, Name);
492  // Iterate over each instruction of loop.
493  // set no-alias for all load & store instructions.
494  for (auto *Block : CurLoop->getBlocks()) {
495  for (auto &Inst : *Block) {
496  // Only interested in instruction that may modify or read memory.
497  if (!Inst.mayReadFromMemory() && !Inst.mayWriteToMemory())
498  continue;
499  Scopes.push_back(NewScope);
500  NoAliases.push_back(NewScope);
501  // Set no-alias for current instruction.
502  Inst.setMetadata(
505  MDNode::get(Inst.getContext(), NoAliases)));
506  // set alias-scope for current instruction.
507  Inst.setMetadata(
510  MDNode::get(Inst.getContext(), Scopes)));
511  }
512  }
513 }
514 
515 bool LoopVersioningLICM::runOnLoop(Loop *L, LPPassManager &LPM) {
516  // This will automatically release all resources hold by the current
517  // LoopVersioningLICM object.
518  AutoResetter Resetter(*this);
519 
520  if (skipLoop(L))
521  return false;
522  // Get Analysis information.
523  AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
524  SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
525  LAA = &getAnalysis<LoopAccessLegacyAnalysis>();
526  LAI = nullptr;
527  // Set Current Loop
528  CurLoop = L;
529  CurAST.reset(new AliasSetTracker(*AA));
530 
531  // Loop over the body of this loop, construct AST.
532  LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
533  for (auto *Block : L->getBlocks()) {
534  if (LI->getLoopFor(Block) == L) // Ignore blocks in subloop.
535  CurAST->add(*Block); // Incorporate the specified basic block
536  }
537 
538  bool Changed = false;
539 
540  // Check feasiblity of LoopVersioningLICM.
541  // If versioning found to be feasible and beneficial then proceed
542  // else simply return, by cleaning up memory.
543  if (isLegalForVersioning()) {
544  // Do loop versioning.
545  // Create memcheck for memory accessed inside loop.
546  // Clone original loop, and set blocks properly.
547  DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
548  LoopVersioning LVer(*LAI, CurLoop, LI, DT, SE, true);
549  LVer.versionLoop();
550  // Set Loop Versioning metaData for original loop.
551  addStringMetadataToLoop(LVer.getNonVersionedLoop(), LICMVersioningMetaData);
552  // Set Loop Versioning metaData for version loop.
553  addStringMetadataToLoop(LVer.getVersionedLoop(), LICMVersioningMetaData);
554  // Set "llvm.mem.parallel_loop_access" metaData to versioned loop.
555  addStringMetadataToLoop(LVer.getVersionedLoop(),
556  "llvm.mem.parallel_loop_access");
557  // Update version loop with aggressive aliasing assumption.
558  setNoAliasToLoop(LVer.getVersionedLoop());
559  Changed = true;
560  }
561  return Changed;
562 }
563 
564 char LoopVersioningLICM::ID = 0;
565 INITIALIZE_PASS_BEGIN(LoopVersioningLICM, "loop-versioning-licm",
566  "Loop Versioning For LICM", false, false)
570 INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
573 INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
575 INITIALIZE_PASS_END(LoopVersioningLICM, "loop-versioning-licm",
576  "Loop Versioning For LICM", false, false)
577 
578 Pass *llvm::createLoopVersioningLICMPass() { return new LoopVersioningLICM(); }
Legacy wrapper pass to provide the GlobalsAAResult object.
MachineLoop * L
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
static unsigned RuntimeMemoryCheckThreshold
\brief When performing memory disambiguation checks at runtime do not make more than this number of c...
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool isForwardingAliasSet() const
Return true if this alias set should be ignored as part of the AliasSetTracker object.
LLVMContext & Context
size_t i
This is the interface for a simple mod/ref and alias analysis over globals.
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
Definition: Metadata.cpp:819
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:414
iterator begin() const
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1040
The main scalar evolution driver.
bool isSimple() const
Definition: Instructions.h:384
Metadata node.
Definition: Metadata.h:830
An instruction for reading from memory.
Definition: Instructions.h:164
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Definition: LoopInfo.h:575
bool isSimple() const
Definition: Instructions.h:263
const std::vector< BlockT * > & getBlocks() const
Get a list of the basic blocks which make up this loop.
Definition: LoopInfo.h:139
BlockT * getHeader() const
Definition: LoopInfo.h:102
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
Definition: LoopInfoImpl.h:157
bool isMustAlias() const
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:53
static const char * LICMVersioningMetaData
bool mayReadFromMemory() const
Return true if this instruction may read memory.
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.
An instruction for storing to memory.
Definition: Instructions.h:300
bool isMod() const
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:392
void addStringMetadataToLoop(Loop *TheLoop, const char *MDString, unsigned V=0)
Set input string into loop metadata by keeping other values intact.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:96
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:395
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
This analysis provides dependence information for the memory accesses of a loop.
char & LCSSAID
Definition: LCSSA.cpp:379
MDNode * getLoopID() const
Return the llvm.loop loop id metadata node for this loop if it is present.
Definition: LoopInfo.cpp:212
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
Value * getPointerOperand()
Definition: Instructions.h:270
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.
Pass * createLoopVersioningLICMPass()
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:654
Optional< const MDOperand * > findStringMetadataForLoop(Loop *TheLoop, StringRef Name)
Find string metadata for loop.
Definition: LoopUtils.cpp:1001
bool isMayAlias() const
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
char & LoopSimplifyID
void initializeLoopVersioningLICMPass(PassRegistry &)
void setLoopID(MDNode *LoopID) const
Set the llvm.loop loop id metadata for this loop.
Definition: LoopInfo.cpp:246
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1034
AnalysisUsage & addRequiredID(const void *ID)
Definition: Pass.cpp:289
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
loop versioning licm
Drive the analysis of memory accesses in the loop.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:558
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:276
This class emits a version of the loop where run-time checks ensure that may-alias pointers can't ove...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
bool mayThrow() const
Return true if this instruction may throw an exception.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1132
Basic Alias true
This class represents an analyzed expression in the program.
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:169
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:368
static MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
Definition: Metadata.cpp:856
#define I(x, y, z)
Definition: MD5.cpp:54
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:287
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static MDNode * createStringMetadata(Loop *TheLoop, StringRef Name, unsigned V)
Create MDNode for input string.
LLVM Value Representation.
Definition: Value.h:71
INITIALIZE_PASS_BEGIN(LoopVersioningLICM,"loop-versioning-licm","Loop Versioning For LICM", false, false) INITIALIZE_PASS_END(LoopVersioningLICM
#define DEBUG(X)
Definition: Debug.h:100
The legacy pass manager's analysis pass to compute loop information.
Definition: LoopInfo.h:831
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
A single uniqued string.
Definition: Metadata.h:586
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:217
int * Ptr
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
Root of the metadata hierarchy.
Definition: Metadata.h:55
Value * getPointerOperand()
Definition: Instructions.h:394
loop versioning Loop Versioning For false
loop versioning Loop Versioning For LICM