LLVM  6.0.0svn
LoopInfo.h
Go to the documentation of this file.
1 //===- llvm/Analysis/LoopInfo.h - Natural Loop Calculator -------*- C++ -*-===//
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 // This file defines the LoopInfo class that is used to identify natural loops
11 // and determine the loop depth of various nodes of the CFG. A natural loop
12 // has exactly one entry-point, which is called the header. Note that natural
13 // loops may actually be several loops that share the same header node.
14 //
15 // This analysis calculates the nesting structure of loops in a function. For
16 // each natural loop identified, this analysis identifies natural loops
17 // contained entirely within the loop and the basic blocks the make up the loop.
18 //
19 // It can calculate on the fly various bits of information, for example:
20 //
21 // * whether there is a preheader for the loop
22 // * the number of back edges to the header
23 // * whether or not a particular block branches out of the loop
24 // * the successor blocks of the loop
25 // * the loop depth
26 // * etc...
27 //
28 // Note that this analysis specifically identifies *Loops* not cycles or SCCs
29 // in the CFG. There can be strongly connected components in the CFG which
30 // this analysis will not recognize and that will not be represented by a Loop
31 // instance. In particular, a Loop might be inside such a non-loop SCC, or a
32 // non-loop SCC might contain a sub-SCC which is a Loop.
33 //
34 //===----------------------------------------------------------------------===//
35 
36 #ifndef LLVM_ANALYSIS_LOOPINFO_H
37 #define LLVM_ANALYSIS_LOOPINFO_H
38 
39 #include "llvm/ADT/DenseMap.h"
40 #include "llvm/ADT/DenseSet.h"
41 #include "llvm/ADT/GraphTraits.h"
42 #include "llvm/ADT/SmallPtrSet.h"
43 #include "llvm/ADT/SmallVector.h"
44 #include "llvm/IR/CFG.h"
45 #include "llvm/IR/Instruction.h"
46 #include "llvm/IR/Instructions.h"
47 #include "llvm/IR/PassManager.h"
48 #include "llvm/Pass.h"
49 #include <algorithm>
50 
51 namespace llvm {
52 
53 class DominatorTree;
54 class LoopInfo;
55 class Loop;
56 class MDNode;
57 class PHINode;
58 class raw_ostream;
59 template <class N, bool IsPostDom> class DominatorTreeBase;
60 template <class N, class M> class LoopInfoBase;
61 template <class N, class M> class LoopBase;
62 
63 //===----------------------------------------------------------------------===//
64 /// Instances of this class are used to represent loops that are detected in the
65 /// flow graph.
66 ///
67 template <class BlockT, class LoopT> class LoopBase {
68  LoopT *ParentLoop;
69  // Loops contained entirely within this one.
70  std::vector<LoopT *> SubLoops;
71 
72  // The list of blocks in this loop. First entry is the header node.
73  std::vector<BlockT *> Blocks;
74 
75  SmallPtrSet<const BlockT *, 8> DenseBlockSet;
76 
77  /// Indicator that this loop is no longer a valid loop.
78  bool IsInvalid = false;
79 
80  LoopBase(const LoopBase<BlockT, LoopT> &) = delete;
82  operator=(const LoopBase<BlockT, LoopT> &) = delete;
83 
84  void clear() {
85  IsInvalid = true;
86  SubLoops.clear();
87  Blocks.clear();
88  DenseBlockSet.clear();
89  ParentLoop = nullptr;
90  }
91 
92 public:
93  /// This creates an empty loop.
94  LoopBase() : ParentLoop(nullptr) {}
95 
96  /// Return the nesting level of this loop. An outer-most loop has depth 1,
97  /// for consistency with loop depth values used for basic blocks, where depth
98  /// 0 is used for blocks not inside any loops.
99  unsigned getLoopDepth() const {
100  assert(!isInvalid() && "Loop not in a valid state!");
101  unsigned D = 1;
102  for (const LoopT *CurLoop = ParentLoop; CurLoop;
103  CurLoop = CurLoop->ParentLoop)
104  ++D;
105  return D;
106  }
107  BlockT *getHeader() const { return getBlocks().front(); }
108  LoopT *getParentLoop() const { return ParentLoop; }
109 
110  /// This is a raw interface for bypassing addChildLoop.
111  void setParentLoop(LoopT *L) {
112  assert(!isInvalid() && "Loop not in a valid state!");
113  ParentLoop = L;
114  }
115 
116  /// Return true if the specified loop is contained within in this loop.
117  bool contains(const LoopT *L) const {
118  assert(!isInvalid() && "Loop not in a valid state!");
119  if (L == this)
120  return true;
121  if (!L)
122  return false;
123  return contains(L->getParentLoop());
124  }
125 
126  /// Return true if the specified basic block is in this loop.
127  bool contains(const BlockT *BB) const {
128  assert(!isInvalid() && "Loop not in a valid state!");
129  return DenseBlockSet.count(BB);
130  }
131 
132  /// Return true if the specified instruction is in this loop.
133  template <class InstT> bool contains(const InstT *Inst) const {
134  return contains(Inst->getParent());
135  }
136 
137  /// Return the loops contained entirely within this loop.
138  const std::vector<LoopT *> &getSubLoops() const {
139  assert(!isInvalid() && "Loop not in a valid state!");
140  return SubLoops;
141  }
142  std::vector<LoopT *> &getSubLoopsVector() {
143  assert(!isInvalid() && "Loop not in a valid state!");
144  return SubLoops;
145  }
146  typedef typename std::vector<LoopT *>::const_iterator iterator;
147  typedef
148  typename std::vector<LoopT *>::const_reverse_iterator reverse_iterator;
149  iterator begin() const { return getSubLoops().begin(); }
150  iterator end() const { return getSubLoops().end(); }
151  reverse_iterator rbegin() const { return getSubLoops().rbegin(); }
152  reverse_iterator rend() const { return getSubLoops().rend(); }
153  bool empty() const { return getSubLoops().empty(); }
154 
155  /// Get a list of the basic blocks which make up this loop.
156  const std::vector<BlockT *> &getBlocks() const {
157  assert(!isInvalid() && "Loop not in a valid state!");
158  return Blocks;
159  }
160  typedef typename std::vector<BlockT *>::const_iterator block_iterator;
161  block_iterator block_begin() const { return getBlocks().begin(); }
162  block_iterator block_end() const { return getBlocks().end(); }
164  assert(!isInvalid() && "Loop not in a valid state!");
165  return make_range(block_begin(), block_end());
166  }
167 
168  /// Get the number of blocks in this loop in constant time.
169  /// Invalidate the loop, indicating that it is no longer a loop.
170  unsigned getNumBlocks() const {
171  assert(!isInvalid() && "Loop not in a valid state!");
172  return Blocks.size();
173  }
174 
175  /// Return true if this loop is no longer valid.
176  bool isInvalid() const { return IsInvalid; }
177 
178  /// True if terminator in the block can branch to another block that is
179  /// outside of the current loop.
180  bool isLoopExiting(const BlockT *BB) const {
181  assert(!isInvalid() && "Loop not in a valid state!");
182  for (const auto &Succ : children<const BlockT *>(BB)) {
183  if (!contains(Succ))
184  return true;
185  }
186  return false;
187  }
188 
189  /// Returns true if \p BB is a loop-latch.
190  /// A latch block is a block that contains a branch back to the header.
191  /// This function is useful when there are multiple latches in a loop
192  /// because \fn getLoopLatch will return nullptr in that case.
193  bool isLoopLatch(const BlockT *BB) const {
194  assert(!isInvalid() && "Loop not in a valid state!");
195  assert(contains(BB) && "block does not belong to the loop");
196 
197  BlockT *Header = getHeader();
198  auto PredBegin = GraphTraits<Inverse<BlockT *>>::child_begin(Header);
199  auto PredEnd = GraphTraits<Inverse<BlockT *>>::child_end(Header);
200  return std::find(PredBegin, PredEnd, BB) != PredEnd;
201  }
202 
203  /// Calculate the number of back edges to the loop header.
204  unsigned getNumBackEdges() const {
205  assert(!isInvalid() && "Loop not in a valid state!");
206  unsigned NumBackEdges = 0;
207  BlockT *H = getHeader();
208 
209  for (const auto Pred : children<Inverse<BlockT *>>(H))
210  if (contains(Pred))
211  ++NumBackEdges;
212 
213  return NumBackEdges;
214  }
215 
216  //===--------------------------------------------------------------------===//
217  // APIs for simple analysis of the loop.
218  //
219  // Note that all of these methods can fail on general loops (ie, there may not
220  // be a preheader, etc). For best success, the loop simplification and
221  // induction variable canonicalization pass should be used to normalize loops
222  // for easy analysis. These methods assume canonical loops.
223 
224  /// Return all blocks inside the loop that have successors outside of the
225  /// loop. These are the blocks _inside of the current loop_ which branch out.
226  /// The returned list is always unique.
227  void getExitingBlocks(SmallVectorImpl<BlockT *> &ExitingBlocks) const;
228 
229  /// If getExitingBlocks would return exactly one block, return that block.
230  /// Otherwise return null.
231  BlockT *getExitingBlock() const;
232 
233  /// Return all of the successor blocks of this loop. These are the blocks
234  /// _outside of the current loop_ which are branched to.
235  void getExitBlocks(SmallVectorImpl<BlockT *> &ExitBlocks) const;
236 
237  /// If getExitBlocks would return exactly one block, return that block.
238  /// Otherwise return null.
239  BlockT *getExitBlock() const;
240 
241  /// Edge type.
242  typedef std::pair<const BlockT *, const BlockT *> Edge;
243 
244  /// Return all pairs of (_inside_block_,_outside_block_).
245  void getExitEdges(SmallVectorImpl<Edge> &ExitEdges) const;
246 
247  /// If there is a preheader for this loop, return it. A loop has a preheader
248  /// if there is only one edge to the header of the loop from outside of the
249  /// loop. If this is the case, the block branching to the header of the loop
250  /// is the preheader node.
251  ///
252  /// This method returns null if there is no preheader for the loop.
253  BlockT *getLoopPreheader() const;
254 
255  /// If the given loop's header has exactly one unique predecessor outside the
256  /// loop, return it. Otherwise return null.
257  /// This is less strict that the loop "preheader" concept, which requires
258  /// the predecessor to have exactly one successor.
259  BlockT *getLoopPredecessor() const;
260 
261  /// If there is a single latch block for this loop, return it.
262  /// A latch block is a block that contains a branch back to the header.
263  BlockT *getLoopLatch() const;
264 
265  /// Return all loop latch blocks of this loop. A latch block is a block that
266  /// contains a branch back to the header.
267  void getLoopLatches(SmallVectorImpl<BlockT *> &LoopLatches) const {
268  assert(!isInvalid() && "Loop not in a valid state!");
269  BlockT *H = getHeader();
270  for (const auto Pred : children<Inverse<BlockT *>>(H))
271  if (contains(Pred))
272  LoopLatches.push_back(Pred);
273  }
274 
275  //===--------------------------------------------------------------------===//
276  // APIs for updating loop information after changing the CFG
277  //
278 
279  /// This method is used by other analyses to update loop information.
280  /// NewBB is set to be a new member of the current loop.
281  /// Because of this, it is added as a member of all parent loops, and is added
282  /// to the specified LoopInfo object as being in the current basic block. It
283  /// is not valid to replace the loop header with this method.
284  void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase<BlockT, LoopT> &LI);
285 
286  /// This is used when splitting loops up. It replaces the OldChild entry in
287  /// our children list with NewChild, and updates the parent pointer of
288  /// OldChild to be null and the NewChild to be this loop.
289  /// This updates the loop depth of the new child.
290  void replaceChildLoopWith(LoopT *OldChild, LoopT *NewChild);
291 
292  /// Add the specified loop to be a child of this loop.
293  /// This updates the loop depth of the new child.
294  void addChildLoop(LoopT *NewChild) {
295  assert(!isInvalid() && "Loop not in a valid state!");
296  assert(!NewChild->ParentLoop && "NewChild already has a parent!");
297  NewChild->ParentLoop = static_cast<LoopT *>(this);
298  SubLoops.push_back(NewChild);
299  }
300 
301  /// This removes the specified child from being a subloop of this loop. The
302  /// loop is not deleted, as it will presumably be inserted into another loop.
303  LoopT *removeChildLoop(iterator I) {
304  assert(!isInvalid() && "Loop not in a valid state!");
305  assert(I != SubLoops.end() && "Cannot remove end iterator!");
306  LoopT *Child = *I;
307  assert(Child->ParentLoop == this && "Child is not a child of this loop!");
308  SubLoops.erase(SubLoops.begin() + (I - begin()));
309  Child->ParentLoop = nullptr;
310  return Child;
311  }
312 
313  /// This adds a basic block directly to the basic block list.
314  /// This should only be used by transformations that create new loops. Other
315  /// transformations should use addBasicBlockToLoop.
316  void addBlockEntry(BlockT *BB) {
317  assert(!isInvalid() && "Loop not in a valid state!");
318  Blocks.push_back(BB);
319  DenseBlockSet.insert(BB);
320  }
321 
322  /// interface to reverse Blocks[from, end of loop] in this loop
323  void reverseBlock(unsigned from) {
324  assert(!isInvalid() && "Loop not in a valid state!");
325  std::reverse(Blocks.begin() + from, Blocks.end());
326  }
327 
328  /// interface to do reserve() for Blocks
329  void reserveBlocks(unsigned size) {
330  assert(!isInvalid() && "Loop not in a valid state!");
331  Blocks.reserve(size);
332  }
333 
334  /// This method is used to move BB (which must be part of this loop) to be the
335  /// loop header of the loop (the block that dominates all others).
336  void moveToHeader(BlockT *BB) {
337  assert(!isInvalid() && "Loop not in a valid state!");
338  if (Blocks[0] == BB)
339  return;
340  for (unsigned i = 0;; ++i) {
341  assert(i != Blocks.size() && "Loop does not contain BB!");
342  if (Blocks[i] == BB) {
343  Blocks[i] = Blocks[0];
344  Blocks[0] = BB;
345  return;
346  }
347  }
348  }
349 
350  /// This removes the specified basic block from the current loop, updating the
351  /// Blocks as appropriate. This does not update the mapping in the LoopInfo
352  /// class.
353  void removeBlockFromLoop(BlockT *BB) {
354  assert(!isInvalid() && "Loop not in a valid state!");
355  auto I = find(Blocks, BB);
356  assert(I != Blocks.end() && "N is not in this list!");
357  Blocks.erase(I);
358 
359  DenseBlockSet.erase(BB);
360  }
361 
362  /// Verify loop structure
363  void verifyLoop() const;
364 
365  /// Verify loop structure of this loop and all nested loops.
367 
368  /// Print loop with all the BBs inside it.
369  void print(raw_ostream &OS, unsigned Depth = 0, bool Verbose = false) const;
370 
371 protected:
372  friend class LoopInfoBase<BlockT, LoopT>;
373  explicit LoopBase(BlockT *BB) : ParentLoop(nullptr) {
374  Blocks.push_back(BB);
375  DenseBlockSet.insert(BB);
376  }
377 
378  // Since loop passes like SCEV are allowed to key analysis results off of
379  // `Loop` pointers, we cannot re-use pointers within a loop pass manager.
380  // This means loop passes should not be `delete` ing `Loop` objects directly
381  // (and risk a later `Loop` allocation re-using the address of a previous one)
382  // but should be using LoopInfo::markAsRemoved, which keeps around the `Loop`
383  // pointer till the end of the lifetime of the `LoopInfo` object.
384  //
385  // To make it easier to follow this rule, we mark the destructor as
386  // non-public.
388  for (auto *SubLoop : SubLoops)
389  delete SubLoop;
390  }
391 };
392 
393 template <class BlockT, class LoopT>
394 raw_ostream &operator<<(raw_ostream &OS, const LoopBase<BlockT, LoopT> &Loop) {
395  Loop.print(OS);
396  return OS;
397 }
398 
399 // Implementation in LoopInfoImpl.h
400 extern template class LoopBase<BasicBlock, Loop>;
401 
402 /// Represents a single loop in the control flow graph. Note that not all SCCs
403 /// in the CFG are necessarily loops.
405 public:
406  /// \brief A range representing the start and end location of a loop.
407  class LocRange {
408  DebugLoc Start;
409  DebugLoc End;
410 
411  public:
412  LocRange() {}
413  LocRange(DebugLoc Start) : Start(std::move(Start)), End(std::move(Start)) {}
415  : Start(std::move(Start)), End(std::move(End)) {}
416 
417  const DebugLoc &getStart() const { return Start; }
418  const DebugLoc &getEnd() const { return End; }
419 
420  /// \brief Check for null.
421  ///
422  explicit operator bool() const { return Start && End; }
423  };
424 
425  Loop() {}
426 
427  /// Return true if the specified value is loop invariant.
428  bool isLoopInvariant(const Value *V) const;
429 
430  /// Return true if all the operands of the specified instruction are loop
431  /// invariant.
432  bool hasLoopInvariantOperands(const Instruction *I) const;
433 
434  /// If the given value is an instruction inside of the loop and it can be
435  /// hoisted, do so to make it trivially loop-invariant.
436  /// Return true if the value after any hoisting is loop invariant. This
437  /// function can be used as a slightly more aggressive replacement for
438  /// isLoopInvariant.
439  ///
440  /// If InsertPt is specified, it is the point to hoist instructions to.
441  /// If null, the terminator of the loop preheader is used.
442  bool makeLoopInvariant(Value *V, bool &Changed,
443  Instruction *InsertPt = nullptr) const;
444 
445  /// If the given instruction is inside of the loop and it can be hoisted, do
446  /// so to make it trivially loop-invariant.
447  /// Return true if the instruction after any hoisting is loop invariant. This
448  /// function can be used as a slightly more aggressive replacement for
449  /// isLoopInvariant.
450  ///
451  /// If InsertPt is specified, it is the point to hoist instructions to.
452  /// If null, the terminator of the loop preheader is used.
453  ///
454  bool makeLoopInvariant(Instruction *I, bool &Changed,
455  Instruction *InsertPt = nullptr) const;
456 
457  /// Check to see if the loop has a canonical induction variable: an integer
458  /// recurrence that starts at 0 and increments by one each time through the
459  /// loop. If so, return the phi node that corresponds to it.
460  ///
461  /// The IndVarSimplify pass transforms loops to have a canonical induction
462  /// variable.
463  ///
464  PHINode *getCanonicalInductionVariable() const;
465 
466  /// Return true if the Loop is in LCSSA form.
467  bool isLCSSAForm(DominatorTree &DT) const;
468 
469  /// Return true if this Loop and all inner subloops are in LCSSA form.
470  bool isRecursivelyLCSSAForm(DominatorTree &DT, const LoopInfo &LI) const;
471 
472  /// Return true if the Loop is in the form that the LoopSimplify form
473  /// transforms loops to, which is sometimes called normal form.
474  bool isLoopSimplifyForm() const;
475 
476  /// Return true if the loop body is safe to clone in practice.
477  bool isSafeToClone() const;
478 
479  /// Returns true if the loop is annotated parallel.
480  ///
481  /// A parallel loop can be assumed to not contain any dependencies between
482  /// iterations by the compiler. That is, any loop-carried dependency checking
483  /// can be skipped completely when parallelizing the loop on the target
484  /// machine. Thus, if the parallel loop information originates from the
485  /// programmer, e.g. via the OpenMP parallel for pragma, it is the
486  /// programmer's responsibility to ensure there are no loop-carried
487  /// dependencies. The final execution order of the instructions across
488  /// iterations is not guaranteed, thus, the end result might or might not
489  /// implement actual concurrent execution of instructions across multiple
490  /// iterations.
491  bool isAnnotatedParallel() const;
492 
493  /// Return the llvm.loop loop id metadata node for this loop if it is present.
494  ///
495  /// If this loop contains the same llvm.loop metadata on each branch to the
496  /// header then the node is returned. If any latch instruction does not
497  /// contain llvm.loop or or if multiple latches contain different nodes then
498  /// 0 is returned.
499  MDNode *getLoopID() const;
500  /// Set the llvm.loop loop id metadata for this loop.
501  ///
502  /// The LoopID metadata node will be added to each terminator instruction in
503  /// the loop that branches to the loop header.
504  ///
505  /// The LoopID metadata node should have one or more operands and the first
506  /// operand should be the node itself.
507  void setLoopID(MDNode *LoopID) const;
508 
509  /// Return true if no exit block for the loop has a predecessor that is
510  /// outside the loop.
511  bool hasDedicatedExits() const;
512 
513  /// Return all unique successor blocks of this loop.
514  /// These are the blocks _outside of the current loop_ which are branched to.
515  /// This assumes that loop exits are in canonical form, i.e. all exits are
516  /// dedicated exits.
517  void getUniqueExitBlocks(SmallVectorImpl<BasicBlock *> &ExitBlocks) const;
518 
519  /// If getUniqueExitBlocks would return exactly one block, return that block.
520  /// Otherwise return null.
521  BasicBlock *getUniqueExitBlock() const;
522 
523  void dump() const;
524  void dumpVerbose() const;
525 
526  /// Return the debug location of the start of this loop.
527  /// This looks for a BB terminating instruction with a known debug
528  /// location by looking at the preheader and header blocks. If it
529  /// cannot find a terminating instruction with location information,
530  /// it returns an unknown location.
531  DebugLoc getStartLoc() const;
532 
533  /// Return the source code span of the loop.
534  LocRange getLocRange() const;
535 
536  StringRef getName() const {
537  if (isInvalid())
538  return "<invalidated loop>";
539  if (BasicBlock *Header = getHeader())
540  if (Header->hasName())
541  return Header->getName();
542  return "<unnamed loop>";
543  }
544 
545 private:
548  explicit Loop(BasicBlock *BB) : LoopBase<BasicBlock, Loop>(BB) {}
549  ~Loop() = default;
550 };
551 
552 //===----------------------------------------------------------------------===//
553 /// This class builds and contains all of the top-level loop
554 /// structures in the specified function.
555 ///
556 
557 template <class BlockT, class LoopT> class LoopInfoBase {
558  // BBMap - Mapping of basic blocks to the inner most loop they occur in
560  std::vector<LoopT *> TopLevelLoops;
561  std::vector<LoopT *> RemovedLoops;
562 
564  friend class LoopInfo;
565 
566  void operator=(const LoopInfoBase &) = delete;
567  LoopInfoBase(const LoopInfoBase &) = delete;
568 
569 public:
571  ~LoopInfoBase() { releaseMemory(); }
572 
574  : BBMap(std::move(Arg.BBMap)),
575  TopLevelLoops(std::move(Arg.TopLevelLoops)) {
576  // We have to clear the arguments top level loops as we've taken ownership.
577  Arg.TopLevelLoops.clear();
578  }
580  BBMap = std::move(RHS.BBMap);
581 
582  for (auto *L : TopLevelLoops)
583  delete L;
584  TopLevelLoops = std::move(RHS.TopLevelLoops);
585  RHS.TopLevelLoops.clear();
586  return *this;
587  }
588 
589  void releaseMemory() {
590  BBMap.clear();
591 
592  for (auto *L : TopLevelLoops)
593  delete L;
594  TopLevelLoops.clear();
595  for (auto *L : RemovedLoops)
596  delete L;
597  RemovedLoops.clear();
598  }
599 
600  /// iterator/begin/end - The interface to the top-level loops in the current
601  /// function.
602  ///
603  typedef typename std::vector<LoopT *>::const_iterator iterator;
604  typedef
605  typename std::vector<LoopT *>::const_reverse_iterator reverse_iterator;
606  iterator begin() const { return TopLevelLoops.begin(); }
607  iterator end() const { return TopLevelLoops.end(); }
608  reverse_iterator rbegin() const { return TopLevelLoops.rbegin(); }
609  reverse_iterator rend() const { return TopLevelLoops.rend(); }
610  bool empty() const { return TopLevelLoops.empty(); }
611 
612  /// Return all of the loops in the function in preorder across the loop
613  /// nests, with siblings in forward program order.
614  ///
615  /// Note that because loops form a forest of trees, preorder is equivalent to
616  /// reverse postorder.
617  SmallVector<LoopT *, 4> getLoopsInPreorder();
618 
619  /// Return all of the loops in the function in preorder across the loop
620  /// nests, with siblings in *reverse* program order.
621  ///
622  /// Note that because loops form a forest of trees, preorder is equivalent to
623  /// reverse postorder.
624  ///
625  /// Also note that this is *not* a reverse preorder. Only the siblings are in
626  /// reverse program order.
627  SmallVector<LoopT *, 4> getLoopsInReverseSiblingPreorder();
628 
629  /// Return the inner most loop that BB lives in. If a basic block is in no
630  /// loop (for example the entry node), null is returned.
631  LoopT *getLoopFor(const BlockT *BB) const { return BBMap.lookup(BB); }
632 
633  /// Same as getLoopFor.
634  const LoopT *operator[](const BlockT *BB) const { return getLoopFor(BB); }
635 
636  /// Return the loop nesting level of the specified block. A depth of 0 means
637  /// the block is not inside any loop.
638  unsigned getLoopDepth(const BlockT *BB) const {
639  const LoopT *L = getLoopFor(BB);
640  return L ? L->getLoopDepth() : 0;
641  }
642 
643  // True if the block is a loop header node
644  bool isLoopHeader(const BlockT *BB) const {
645  const LoopT *L = getLoopFor(BB);
646  return L && L->getHeader() == BB;
647  }
648 
649  /// This removes the specified top-level loop from this loop info object.
650  /// The loop is not deleted, as it will presumably be inserted into
651  /// another loop.
652  LoopT *removeLoop(iterator I) {
653  assert(I != end() && "Cannot remove end iterator!");
654  LoopT *L = *I;
655  assert(!L->getParentLoop() && "Not a top-level loop!");
656  TopLevelLoops.erase(TopLevelLoops.begin() + (I - begin()));
657  return L;
658  }
659 
660  /// Change the top-level loop that contains BB to the specified loop.
661  /// This should be used by transformations that restructure the loop hierarchy
662  /// tree.
663  void changeLoopFor(BlockT *BB, LoopT *L) {
664  if (!L) {
665  BBMap.erase(BB);
666  return;
667  }
668  BBMap[BB] = L;
669  }
670 
671  /// Replace the specified loop in the top-level loops list with the indicated
672  /// loop.
673  void changeTopLevelLoop(LoopT *OldLoop, LoopT *NewLoop) {
674  auto I = find(TopLevelLoops, OldLoop);
675  assert(I != TopLevelLoops.end() && "Old loop not at top level!");
676  *I = NewLoop;
677  assert(!NewLoop->ParentLoop && !OldLoop->ParentLoop &&
678  "Loops already embedded into a subloop!");
679  }
680 
681  /// This adds the specified loop to the collection of top-level loops.
682  void addTopLevelLoop(LoopT *New) {
683  assert(!New->getParentLoop() && "Loop already in subloop!");
684  TopLevelLoops.push_back(New);
685  }
686 
687  /// This method completely removes BB from all data structures,
688  /// including all of the Loop objects it is nested in and our mapping from
689  /// BasicBlocks to loops.
690  void removeBlock(BlockT *BB) {
691  auto I = BBMap.find(BB);
692  if (I != BBMap.end()) {
693  for (LoopT *L = I->second; L; L = L->getParentLoop())
694  L->removeBlockFromLoop(BB);
695 
696  BBMap.erase(I);
697  }
698  }
699 
700  // Internals
701 
702  static bool isNotAlreadyContainedIn(const LoopT *SubLoop,
703  const LoopT *ParentLoop) {
704  if (!SubLoop)
705  return true;
706  if (SubLoop == ParentLoop)
707  return false;
708  return isNotAlreadyContainedIn(SubLoop->getParentLoop(), ParentLoop);
709  }
710 
711  /// Create the loop forest using a stable algorithm.
712  void analyze(const DominatorTreeBase<BlockT, false> &DomTree);
713 
714  // Debugging
715  void print(raw_ostream &OS) const;
716 
717  void verify(const DominatorTreeBase<BlockT, false> &DomTree) const;
718 
719 protected:
720  static void clearLoop(LoopT &L) { L.clear(); }
721 };
722 
723 // Implementation in LoopInfoImpl.h
724 extern template class LoopInfoBase<BasicBlock, Loop>;
725 
728 
730 
731  void operator=(const LoopInfo &) = delete;
732  LoopInfo(const LoopInfo &) = delete;
733 
734 public:
735  LoopInfo() {}
736  explicit LoopInfo(const DominatorTreeBase<BasicBlock, false> &DomTree);
737 
738  LoopInfo(LoopInfo &&Arg) : BaseT(std::move(static_cast<BaseT &>(Arg))) {}
740  BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
741  return *this;
742  }
743 
744  /// Handle invalidation explicitly.
745  bool invalidate(Function &F, const PreservedAnalyses &PA,
747 
748  // Most of the public interface is provided via LoopInfoBase.
749 
750  /// Update LoopInfo after removing the last backedge from a loop. This updates
751  /// the loop forest and parent loops for each block so that \c L is no longer
752  /// referenced, but does not actually delete \c L immediately. The pointer
753  /// will remain valid until this LoopInfo's memory is released.
754  void erase(Loop *L);
755 
756  /// Returns true if replacing From with To everywhere is guaranteed to
757  /// preserve LCSSA form.
759  // Preserving LCSSA form is only problematic if the replacing value is an
760  // instruction.
762  if (!I)
763  return true;
764  // If both instructions are defined in the same basic block then replacement
765  // cannot break LCSSA form.
766  if (I->getParent() == From->getParent())
767  return true;
768  // If the instruction is not defined in a loop then it can safely replace
769  // anything.
770  Loop *ToLoop = getLoopFor(I->getParent());
771  if (!ToLoop)
772  return true;
773  // If the replacing instruction is defined in the same loop as the original
774  // instruction, or in a loop that contains it as an inner loop, then using
775  // it as a replacement will not break LCSSA form.
776  return ToLoop->contains(getLoopFor(From->getParent()));
777  }
778 
779  /// Checks if moving a specific instruction can break LCSSA in any loop.
780  ///
781  /// Return true if moving \p Inst to before \p NewLoc will break LCSSA,
782  /// assuming that the function containing \p Inst and \p NewLoc is currently
783  /// in LCSSA form.
785  assert(Inst->getFunction() == NewLoc->getFunction() &&
786  "Can't reason about IPO!");
787 
788  auto *OldBB = Inst->getParent();
789  auto *NewBB = NewLoc->getParent();
790 
791  // Movement within the same loop does not break LCSSA (the equality check is
792  // to avoid doing a hashtable lookup in case of intra-block movement).
793  if (OldBB == NewBB)
794  return true;
795 
796  auto *OldLoop = getLoopFor(OldBB);
797  auto *NewLoop = getLoopFor(NewBB);
798 
799  if (OldLoop == NewLoop)
800  return true;
801 
802  // Check if Outer contains Inner; with the null loop counting as the
803  // "outermost" loop.
804  auto Contains = [](const Loop *Outer, const Loop *Inner) {
805  return !Outer || Outer->contains(Inner);
806  };
807 
808  // To check that the movement of Inst to before NewLoc does not break LCSSA,
809  // we need to check two sets of uses for possible LCSSA violations at
810  // NewLoc: the users of NewInst, and the operands of NewInst.
811 
812  // If we know we're hoisting Inst out of an inner loop to an outer loop,
813  // then the uses *of* Inst don't need to be checked.
814 
815  if (!Contains(NewLoop, OldLoop)) {
816  for (Use &U : Inst->uses()) {
817  auto *UI = cast<Instruction>(U.getUser());
818  auto *UBB = isa<PHINode>(UI) ? cast<PHINode>(UI)->getIncomingBlock(U)
819  : UI->getParent();
820  if (UBB != NewBB && getLoopFor(UBB) != NewLoop)
821  return false;
822  }
823  }
824 
825  // If we know we're sinking Inst from an outer loop into an inner loop, then
826  // the *operands* of Inst don't need to be checked.
827 
828  if (!Contains(OldLoop, NewLoop)) {
829  // See below on why we can't handle phi nodes here.
830  if (isa<PHINode>(Inst))
831  return false;
832 
833  for (Use &U : Inst->operands()) {
834  auto *DefI = dyn_cast<Instruction>(U.get());
835  if (!DefI)
836  return false;
837 
838  // This would need adjustment if we allow Inst to be a phi node -- the
839  // new use block won't simply be NewBB.
840 
841  auto *DefBlock = DefI->getParent();
842  if (DefBlock != NewBB && getLoopFor(DefBlock) != NewLoop)
843  return false;
844  }
845  }
846 
847  return true;
848  }
849 };
850 
851 // Allow clients to walk the list of nested loops...
852 template <> struct GraphTraits<const Loop *> {
853  typedef const Loop *NodeRef;
855 
856  static NodeRef getEntryNode(const Loop *L) { return L; }
857  static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
858  static ChildIteratorType child_end(NodeRef N) { return N->end(); }
859 };
860 
861 template <> struct GraphTraits<Loop *> {
862  typedef Loop *NodeRef;
864 
865  static NodeRef getEntryNode(Loop *L) { return L; }
866  static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
867  static ChildIteratorType child_end(NodeRef N) { return N->end(); }
868 };
869 
870 /// \brief Analysis pass that exposes the \c LoopInfo for a function.
871 class LoopAnalysis : public AnalysisInfoMixin<LoopAnalysis> {
873  static AnalysisKey Key;
874 
875 public:
876  typedef LoopInfo Result;
877 
879 };
880 
881 /// \brief Printer pass for the \c LoopAnalysis results.
882 class LoopPrinterPass : public PassInfoMixin<LoopPrinterPass> {
883  raw_ostream &OS;
884 
885 public:
886  explicit LoopPrinterPass(raw_ostream &OS) : OS(OS) {}
888 };
889 
890 /// \brief Verifier pass for the \c LoopAnalysis results.
891 struct LoopVerifierPass : public PassInfoMixin<LoopVerifierPass> {
893 };
894 
895 /// \brief The legacy pass manager's analysis pass to compute loop information.
897  LoopInfo LI;
898 
899 public:
900  static char ID; // Pass identification, replacement for typeid
901 
904  }
905 
906  LoopInfo &getLoopInfo() { return LI; }
907  const LoopInfo &getLoopInfo() const { return LI; }
908 
909  /// \brief Calculate the natural loop information for a given function.
910  bool runOnFunction(Function &F) override;
911 
912  void verifyAnalysis() const override;
913 
914  void releaseMemory() override { LI.releaseMemory(); }
915 
916  void print(raw_ostream &O, const Module *M = nullptr) const override;
917 
918  void getAnalysisUsage(AnalysisUsage &AU) const override;
919 };
920 
921 /// Function to print a loop's contents as LLVM's text IR assembly.
922 void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner = "");
923 
924 } // End llvm namespace
925 
926 #endif
LoopInfo::iterator ChildIteratorType
Definition: LoopInfo.h:854
void push_back(const T &Elt)
Definition: SmallVector.h:212
LoopInfo Result
Definition: LoopInfo.h:876
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
Definition: GraphTraits.h:102
iterator_range< use_iterator > uses()
Definition: Value.h:350
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
Definition: LoopInfoImpl.h:157
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool empty() const
Definition: LoopInfo.h:610
static bool isLoopInvariant(Value *V, const Loop *L, const DominatorTree *DT)
Perform a quick domtree based check for loop invariance assuming that V is used within the loop...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void setParentLoop(LoopT *L)
This is a raw interface for bypassing addChildLoop.
Definition: LoopInfo.h:111
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
unsigned getLoopDepth(const BlockT *BB) const
Return the loop nesting level of the specified block.
Definition: LoopInfo.h:638
Implements a dense probed hash-table based set.
Definition: DenseSet.h:221
unsigned getLoopDepth() const
Return the nesting level of this loop.
Definition: LoopInfo.h:99
void moveToHeader(BlockT *BB)
This method is used to move BB (which must be part of this loop) to be the loop header of the loop (t...
Definition: LoopInfo.h:336
void reserveBlocks(unsigned size)
interface to do reserve() for Blocks
Definition: LoopInfo.h:329
LoopT * removeChildLoop(iterator I)
This removes the specified child from being a subloop of this loop.
Definition: LoopInfo.h:303
std::pair< const BlockT *, const BlockT * > Edge
Edge type.
Definition: LoopInfo.h:242
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
Definition: LoopInfoImpl.h:106
void replaceChildLoopWith(LoopT *OldChild, LoopT *NewChild)
This is used when splitting loops up.
Definition: LoopInfoImpl.h:213
std::vector< LoopT * > & getSubLoopsVector()
Definition: LoopInfo.h:142
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:862
F(f)
LoopBase()
This creates an empty loop.
Definition: LoopInfo.h:94
Instances of this class are used to represent loops that are detected in the flow graph...
Definition: LoopInfo.h:61
bool isInvalid() const
Return true if this loop is no longer valid.
Definition: LoopInfo.h:176
void print(raw_ostream &OS, unsigned Depth=0, bool Verbose=false) const
Print loop with all the BBs inside it.
Definition: LoopInfoImpl.h:325
Hexagon Hardware Loops
Definition: BitVector.h:920
unsigned getNumBackEdges() const
Calculate the number of back edges to the loop header.
Definition: LoopInfo.h:204
void initializeLoopInfoWrapperPassPass(PassRegistry &)
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Definition: LoopInfo.h:631
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
void addBlockEntry(BlockT *BB)
This adds a basic block directly to the basic block list.
Definition: LoopInfo.h:316
static bool isNotAlreadyContainedIn(const LoopT *SubLoop, const LoopT *ParentLoop)
Definition: LoopInfo.h:702
std::vector< LoopT * >::const_iterator iterator
iterator/begin/end - The interface to the top-level loops in the current function.
Definition: LoopInfo.h:603
void getLoopLatches(SmallVectorImpl< BlockT *> &LoopLatches) const
Return all loop latch blocks of this loop.
Definition: LoopInfo.h:267
Printer pass for the LoopAnalysis results.
Definition: LoopInfo.h:882
Analysis pass that exposes the LoopInfo for a function.
Definition: LoopInfo.h:871
BlockT * getHeader() const
Definition: LoopInfo.h:107
void getExitBlocks(SmallVectorImpl< BlockT *> &ExitBlocks) const
Return all of the successor blocks of this loop.
Definition: LoopInfoImpl.h:63
const LoopInfo & getLoopInfo() const
Definition: LoopInfo.h:907
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Definition: STLExtras.h:248
std::vector< LoopT * >::const_iterator iterator
Definition: LoopInfo.h:146
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
Definition: LoopInfoImpl.h:183
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:365
void addTopLevelLoop(LoopT *New)
This adds the specified loop to the collection of top-level loops.
Definition: LoopInfo.h:682
LoopInfo & operator=(LoopInfo &&RHS)
Definition: LoopInfo.h:739
LocRange(DebugLoc Start, DebugLoc End)
Definition: LoopInfo.h:414
const DebugLoc & getEnd() const
Definition: LoopInfo.h:418
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:140
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: LoopInfo.h:914
Core dominator tree base class.
Definition: LoopInfo.h:59
reverse_iterator rend() const
Definition: LoopInfo.h:152
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
reverse_iterator rbegin() const
Definition: LoopInfo.h:151
static void clearLoop(LoopT &L)
Definition: LoopInfo.h:720
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
bool isLoopExiting(const BlockT *BB) const
True if terminator in the block can branch to another block that is outside of the current loop...
Definition: LoopInfo.h:180
static ChildIteratorType child_begin(NodeRef N)
Definition: LoopInfo.h:857
iterator end() const
Definition: LoopInfo.h:607
#define H(x, y, z)
Definition: MD5.cpp:57
LoopPrinterPass(raw_ostream &OS)
Definition: LoopInfo.h:886
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:363
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:382
const std::vector< BlockT * > & getBlocks() const
Get a list of the basic blocks which make up this loop.
Definition: LoopInfo.h:156
Represent the analysis usage information of a pass.
bool contains(const BlockT *BB) const
Return true if the specified basic block is in this loop.
Definition: LoopInfo.h:127
static const unsigned End
std::vector< BlockT * >::const_iterator block_iterator
Definition: LoopInfo.h:160
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
op_range operands()
Definition: User.h:222
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:374
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:61
BlockT * getExitBlock() const
If getExitBlocks would return exactly one block, return that block.
Definition: LoopInfoImpl.h:76
void getExitingBlocks(SmallVectorImpl< BlockT *> &ExitingBlocks) const
Return all blocks inside the loop that have successors outside of the loop.
Definition: LoopInfoImpl.h:35
A range representing the start and end location of a loop.
Definition: LoopInfo.h:407
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
void getExitEdges(SmallVectorImpl< Edge > &ExitEdges) const
Return all pairs of (inside_block,outside_block).
Definition: LoopInfoImpl.h:87
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LoopInfoBase & operator=(LoopInfoBase &&RHS)
Definition: LoopInfo.h:579
BlockT * getLoopPredecessor() const
If the given loop&#39;s header has exactly one unique predecessor outside the loop, return it...
Definition: LoopInfoImpl.h:134
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
Definition: LoopInfo.h:117
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:837
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
Definition: SmallPtrSet.h:370
bool movementPreservesLCSSAForm(Instruction *Inst, Instruction *NewLoc)
Checks if moving a specific instruction can break LCSSA in any loop.
Definition: LoopInfo.h:784
reverse_iterator rend() const
Definition: LoopInfo.h:609
Verifier pass for the LoopAnalysis results.
Definition: LoopInfo.h:891
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
iterator begin() const
Definition: LoopInfo.h:149
LoopInfo & getLoopInfo()
Definition: LoopInfo.h:906
LoopT * removeLoop(iterator I)
This removes the specified top-level loop from this loop info object.
Definition: LoopInfo.h:652
bool contains(const InstT *Inst) const
Return true if the specified instruction is in this loop.
Definition: LoopInfo.h:133
static NodeRef getEntryNode(const Loop *L)
Definition: LoopInfo.h:856
LoopInfo(LoopInfo &&Arg)
Definition: LoopInfo.h:738
static ChildIteratorType child_end(NodeRef N)
Definition: LoopInfo.h:858
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
std::vector< LoopT * >::const_reverse_iterator reverse_iterator
Definition: LoopInfo.h:148
bool isLoopLatch(const BlockT *BB) const
Definition: LoopInfo.h:193
iterator begin() const
Definition: LoopInfo.h:606
A range adaptor for a pair of iterators.
LoopInfo::iterator ChildIteratorType
Definition: LoopInfo.h:863
bool isLoopHeader(const BlockT *BB) const
Definition: LoopInfo.h:644
reverse_iterator rbegin() const
Definition: LoopInfo.h:608
amdgpu Simplify well known AMD library false Value Value * Arg
LoopT * getParentLoop() const
Definition: LoopInfo.h:108
const std::vector< LoopT * > & getSubLoops() const
Return the loops contained entirely within this loop.
Definition: LoopInfo.h:138
unsigned getNumBlocks() const
Get the number of blocks in this loop in constant time.
Definition: LoopInfo.h:170
void verifyLoopNest(DenseSet< const LoopT *> *Loops) const
Verify loop structure of this loop and all nested loops.
Definition: LoopInfoImpl.h:313
static NodeRef getEntryNode(Loop *L)
Definition: LoopInfo.h:865
const DebugLoc & getStart() const
Definition: LoopInfo.h:417
void addChildLoop(LoopT *NewChild)
Add the specified loop to be a child of this loop.
Definition: LoopInfo.h:294
StringRef getName() const
Definition: LoopInfo.h:536
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:404
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
static ChildIteratorType child_end(NodeRef N)
Definition: LoopInfo.h:867
void changeTopLevelLoop(LoopT *OldLoop, LoopT *NewLoop)
Replace the specified loop in the top-level loops list with the indicated loop.
Definition: LoopInfo.h:673
iterator end() const
Definition: LoopInfo.h:150
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:323
block_iterator block_end() const
Definition: LoopInfo.h:162
void changeLoopFor(BlockT *BB, LoopT *L)
Change the top-level loop that contains BB to the specified loop.
Definition: LoopInfo.h:663
friend class LoopInfo
Definition: LoopInfo.h:564
void removeBlockFromLoop(BlockT *BB)
This removes the specified basic block from the current loop, updating the Blocks as appropriate...
Definition: LoopInfo.h:353
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:181
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:559
bool empty() const
Definition: LoopInfo.h:153
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
aarch64 promote const
LLVM Value Representation.
Definition: Value.h:73
const LoopT * operator[](const BlockT *BB) const
Same as getLoopFor.
Definition: LoopInfo.h:634
void reverseBlock(unsigned from)
interface to reverse Blocks[from, end of loop] in this loop
Definition: LoopInfo.h:323
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
The legacy pass manager&#39;s analysis pass to compute loop information.
Definition: LoopInfo.h:896
void verifyLoop() const
Verify loop structure.
Definition: LoopInfoImpl.h:227
LoopInfoBase(LoopInfoBase &&Arg)
Definition: LoopInfo.h:573
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
A container for analyses that lazily runs them and caches their results.
void releaseMemory()
Definition: LoopInfo.h:589
std::vector< LoopT * >::const_reverse_iterator reverse_iterator
Definition: LoopInfo.h:605
bool replacementPreservesLCSSAForm(Instruction *From, Value *To)
Returns true if replacing From with To everywhere is guaranteed to preserve LCSSA form...
Definition: LoopInfo.h:758
This header defines various interfaces for pass management in LLVM.
iterator_range< block_iterator > blocks() const
Definition: LoopInfo.h:163
void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop&#39;s contents as LLVM&#39;s text IR assembly.
Definition: LoopInfo.cpp:702
block_iterator block_begin() const
Definition: LoopInfo.h:161
BlockT * getExitingBlock() const
If getExitingBlocks would return exactly one block, return that block.
Definition: LoopInfoImpl.h:50
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:70
static ChildIteratorType child_begin(NodeRef N)
Definition: LoopInfo.h:866
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
Definition: LoopInfo.h:690
const BasicBlock * getParent() const
Definition: Instruction.h:66
LoopBase(BlockT *BB)
Definition: LoopInfo.h:373
LocRange(DebugLoc Start)
Definition: LoopInfo.h:413
This class builds and contains all of the top-level loop structures in the specified function...
Definition: LoopInfo.h:60