LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MachineBasicBlock.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/MachineBasicBlock.h ------------------------*- 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 // Collect the sequence of machine instructions for a basic block.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
15 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H
16 
17 #include "llvm/ADT/GraphTraits.h"
19 #include "llvm/Support/DataTypes.h"
20 #include <functional>
21 
22 namespace llvm {
23 
24 class Pass;
25 class BasicBlock;
26 class MachineFunction;
27 class MCSymbol;
28 class SlotIndexes;
29 class StringRef;
30 class raw_ostream;
31 class MachineBranchProbabilityInfo;
32 
33 template <>
34 struct ilist_traits<MachineInstr> : public ilist_default_traits<MachineInstr> {
35 private:
36  mutable ilist_half_node<MachineInstr> Sentinel;
37 
38  // this is only set by the MachineBasicBlock owning the LiveList
39  friend class MachineBasicBlock;
40  MachineBasicBlock* Parent;
41 
42 public:
44  return static_cast<MachineInstr*>(&Sentinel);
45  }
46  void destroySentinel(MachineInstr *) const {}
47 
50  static void noteHead(MachineInstr*, MachineInstr*) {}
51 
54  void transferNodesFromList(ilist_traits &SrcTraits,
57  void deleteNode(MachineInstr *N);
58 private:
59  void createNode(const MachineInstr &);
60 };
61 
62 class MachineBasicBlock : public ilist_node<MachineBasicBlock> {
64  Instructions Insts;
65  const BasicBlock *BB;
66  int Number;
67  MachineFunction *xParent;
68 
69  /// Predecessors/Successors - Keep track of the predecessor / successor
70  /// basicblocks.
71  std::vector<MachineBasicBlock *> Predecessors;
72  std::vector<MachineBasicBlock *> Successors;
73 
74  /// Weights - Keep track of the weights to the successors. This vector
75  /// has the same order as Successors, or it is empty if we don't use it
76  /// (disable optimization).
77  std::vector<uint32_t> Weights;
78  typedef std::vector<uint32_t>::iterator weight_iterator;
79  typedef std::vector<uint32_t>::const_iterator const_weight_iterator;
80 
81  /// LiveIns - Keep track of the physical registers that are livein of
82  /// the basicblock.
83  std::vector<unsigned> LiveIns;
84 
85  /// Alignment - Alignment of the basic block. Zero if the basic block does
86  /// not need to be aligned.
87  /// The alignment is specified as log2(bytes).
88  unsigned Alignment;
89 
90  /// IsLandingPad - Indicate that this basic block is entered via an
91  /// exception handler.
92  bool IsLandingPad;
93 
94  /// AddressTaken - Indicate that this basic block is potentially the
95  /// target of an indirect branch.
96  bool AddressTaken;
97 
98  /// \brief since getSymbol is a relatively heavy-weight operation, the symbol
99  /// is only computed once and is cached.
100  mutable MCSymbol *CachedMCSymbol;
101 
102  // Intrusive list support
103  MachineBasicBlock() {}
104 
105  explicit MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb);
106 
108 
109  // MachineBasicBlocks are allocated and owned by MachineFunction.
110  friend class MachineFunction;
111 
112 public:
113  /// getBasicBlock - Return the LLVM basic block that this instance
114  /// corresponded to originally. Note that this may be NULL if this instance
115  /// does not correspond directly to an LLVM basic block.
116  ///
117  const BasicBlock *getBasicBlock() const { return BB; }
118 
119  /// getName - Return the name of the corresponding LLVM basic block, or
120  /// "(null)".
121  StringRef getName() const;
122 
123  /// getFullName - Return a formatted string to identify this block and its
124  /// parent function.
125  std::string getFullName() const;
126 
127  /// hasAddressTaken - Test whether this block is potentially the target
128  /// of an indirect branch.
129  bool hasAddressTaken() const { return AddressTaken; }
130 
131  /// setHasAddressTaken - Set this block to reflect that it potentially
132  /// is the target of an indirect branch.
133  void setHasAddressTaken() { AddressTaken = true; }
134 
135  /// getParent - Return the MachineFunction containing this basic block.
136  ///
137  const MachineFunction *getParent() const { return xParent; }
138  MachineFunction *getParent() { return xParent; }
139 
140 
141  /// bundle_iterator - MachineBasicBlock iterator that automatically skips over
142  /// MIs that are inside bundles (i.e. walk top level MIs only).
143  template<typename Ty, typename IterTy>
145  : public std::iterator<std::bidirectional_iterator_tag, Ty, ptrdiff_t> {
146  IterTy MII;
147 
148  public:
149  bundle_iterator(IterTy mii) : MII(mii) {}
150 
151  bundle_iterator(Ty &mi) : MII(mi) {
152  assert(!mi.isBundledWithPred() &&
153  "It's not legal to initialize bundle_iterator with a bundled MI");
154  }
155  bundle_iterator(Ty *mi) : MII(mi) {
156  assert((!mi || !mi->isBundledWithPred()) &&
157  "It's not legal to initialize bundle_iterator with a bundled MI");
158  }
159  // Template allows conversion from const to nonconst.
160  template<class OtherTy, class OtherIterTy>
162  : MII(I.getInstrIterator()) {}
163  bundle_iterator() : MII(0) {}
164 
165  Ty &operator*() const { return *MII; }
166  Ty *operator->() const { return &operator*(); }
167 
168  operator Ty*() const { return MII; }
169 
170  bool operator==(const bundle_iterator &x) const {
171  return MII == x.MII;
172  }
173  bool operator!=(const bundle_iterator &x) const {
174  return !operator==(x);
175  }
176 
177  // Increment and decrement operators...
178  bundle_iterator &operator--() { // predecrement - Back up
179  do --MII;
180  while (MII->isBundledWithPred());
181  return *this;
182  }
183  bundle_iterator &operator++() { // preincrement - Advance
184  while (MII->isBundledWithSucc())
185  ++MII;
186  ++MII;
187  return *this;
188  }
189  bundle_iterator operator--(int) { // postdecrement operators...
190  bundle_iterator tmp = *this;
191  --*this;
192  return tmp;
193  }
194  bundle_iterator operator++(int) { // postincrement operators...
195  bundle_iterator tmp = *this;
196  ++*this;
197  return tmp;
198  }
199 
200  IterTy getInstrIterator() const {
201  return MII;
202  }
203  };
204 
207  typedef std::reverse_iterator<instr_iterator> reverse_instr_iterator;
208  typedef
209  std::reverse_iterator<const_instr_iterator> const_reverse_instr_iterator;
210 
211  typedef
213  typedef
215  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
216  typedef std::reverse_iterator<iterator> reverse_iterator;
217 
218 
219  unsigned size() const { return (unsigned)Insts.size(); }
220  bool empty() const { return Insts.empty(); }
221 
222  MachineInstr& front() { return Insts.front(); }
223  MachineInstr& back() { return Insts.back(); }
224  const MachineInstr& front() const { return Insts.front(); }
225  const MachineInstr& back() const { return Insts.back(); }
226 
227  instr_iterator instr_begin() { return Insts.begin(); }
228  const_instr_iterator instr_begin() const { return Insts.begin(); }
229  instr_iterator instr_end() { return Insts.end(); }
230  const_instr_iterator instr_end() const { return Insts.end(); }
233  reverse_instr_iterator instr_rend () { return Insts.rend(); }
234  const_reverse_instr_iterator instr_rend () const { return Insts.rend(); }
235 
236  iterator begin() { return instr_begin(); }
237  const_iterator begin() const { return instr_begin(); }
238  iterator end () { return instr_end(); }
239  const_iterator end () const { return instr_end(); }
243  const_reverse_iterator rend () const { return instr_rend(); }
244 
245 
246  // Machine-CFG iterators
247  typedef std::vector<MachineBasicBlock *>::iterator pred_iterator;
248  typedef std::vector<MachineBasicBlock *>::const_iterator const_pred_iterator;
249  typedef std::vector<MachineBasicBlock *>::iterator succ_iterator;
250  typedef std::vector<MachineBasicBlock *>::const_iterator const_succ_iterator;
253  typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
257  typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
259 
260  pred_iterator pred_begin() { return Predecessors.begin(); }
261  const_pred_iterator pred_begin() const { return Predecessors.begin(); }
262  pred_iterator pred_end() { return Predecessors.end(); }
263  const_pred_iterator pred_end() const { return Predecessors.end(); }
265  { return Predecessors.rbegin();}
267  { return Predecessors.rbegin();}
269  { return Predecessors.rend(); }
271  { return Predecessors.rend(); }
272  unsigned pred_size() const {
273  return (unsigned)Predecessors.size();
274  }
275  bool pred_empty() const { return Predecessors.empty(); }
276  succ_iterator succ_begin() { return Successors.begin(); }
277  const_succ_iterator succ_begin() const { return Successors.begin(); }
278  succ_iterator succ_end() { return Successors.end(); }
279  const_succ_iterator succ_end() const { return Successors.end(); }
281  { return Successors.rbegin(); }
283  { return Successors.rbegin(); }
285  { return Successors.rend(); }
287  { return Successors.rend(); }
288  unsigned succ_size() const {
289  return (unsigned)Successors.size();
290  }
291  bool succ_empty() const { return Successors.empty(); }
292 
293  // LiveIn management methods.
294 
295  /// addLiveIn - Add the specified register as a live in. Note that it
296  /// is an error to add the same register to the same set more than once.
297  void addLiveIn(unsigned Reg) { LiveIns.push_back(Reg); }
298 
299  /// Add PhysReg as live in to this block, and ensure that there is a copy of
300  /// PhysReg to a virtual register of class RC. Return the virtual register
301  /// that is a copy of the live in PhysReg.
302  unsigned addLiveIn(unsigned PhysReg, const TargetRegisterClass *RC);
303 
304  /// removeLiveIn - Remove the specified register from the live in set.
305  ///
306  void removeLiveIn(unsigned Reg);
307 
308  /// isLiveIn - Return true if the specified register is in the live in set.
309  ///
310  bool isLiveIn(unsigned Reg) const;
311 
312  // Iteration support for live in sets. These sets are kept in sorted
313  // order by their register number.
314  typedef std::vector<unsigned>::const_iterator livein_iterator;
315  livein_iterator livein_begin() const { return LiveIns.begin(); }
316  livein_iterator livein_end() const { return LiveIns.end(); }
317  bool livein_empty() const { return LiveIns.empty(); }
318 
319  /// getAlignment - Return alignment of the basic block.
320  /// The alignment is specified as log2(bytes).
321  ///
322  unsigned getAlignment() const { return Alignment; }
323 
324  /// setAlignment - Set alignment of the basic block.
325  /// The alignment is specified as log2(bytes).
326  ///
327  void setAlignment(unsigned Align) { Alignment = Align; }
328 
329  /// isLandingPad - Returns true if the block is a landing pad. That is
330  /// this basic block is entered via an exception handler.
331  bool isLandingPad() const { return IsLandingPad; }
332 
333  /// setIsLandingPad - Indicates the block is a landing pad. That is
334  /// this basic block is entered via an exception handler.
335  void setIsLandingPad(bool V = true) { IsLandingPad = V; }
336 
337  /// getLandingPadSuccessor - If this block has a successor that is a landing
338  /// pad, return it. Otherwise return NULL.
340 
341  // Code Layout methods.
342 
343  /// moveBefore/moveAfter - move 'this' block before or after the specified
344  /// block. This only moves the block, it does not modify the CFG or adjust
345  /// potential fall-throughs at the end of the block.
346  void moveBefore(MachineBasicBlock *NewAfter);
347  void moveAfter(MachineBasicBlock *NewBefore);
348 
349  /// updateTerminator - Update the terminator instructions in block to account
350  /// for changes to the layout. If the block previously used a fallthrough,
351  /// it may now need a branch, and if it previously used branching it may now
352  /// be able to use a fallthrough.
353  void updateTerminator();
354 
355  // Machine-CFG mutators
356 
357  /// addSuccessor - Add succ as a successor of this MachineBasicBlock.
358  /// The Predecessors list of succ is automatically updated. WEIGHT
359  /// parameter is stored in Weights list and it may be used by
360  /// MachineBranchProbabilityInfo analysis to calculate branch probability.
361  ///
362  /// Note that duplicate Machine CFG edges are not allowed.
363  ///
364  void addSuccessor(MachineBasicBlock *succ, uint32_t weight = 0);
365 
366  /// removeSuccessor - Remove successor from the successors list of this
367  /// MachineBasicBlock. The Predecessors list of succ is automatically updated.
368  ///
370 
371  /// removeSuccessor - Remove specified successor from the successors list of
372  /// this MachineBasicBlock. The Predecessors list of succ is automatically
373  /// updated. Return the iterator to the element after the one removed.
374  ///
376 
377  /// replaceSuccessor - Replace successor OLD with NEW and update weight info.
378  ///
380 
381 
382  /// transferSuccessors - Transfers all the successors from MBB to this
383  /// machine basic block (i.e., copies all the successors fromMBB and
384  /// remove all the successors from fromMBB).
385  void transferSuccessors(MachineBasicBlock *fromMBB);
386 
387  /// transferSuccessorsAndUpdatePHIs - Transfers all the successors, as
388  /// in transferSuccessors, and update PHI operands in the successor blocks
389  /// which refer to fromMBB to refer to this.
391 
392  /// isPredecessor - Return true if the specified MBB is a predecessor of this
393  /// block.
394  bool isPredecessor(const MachineBasicBlock *MBB) const;
395 
396  /// isSuccessor - Return true if the specified MBB is a successor of this
397  /// block.
398  bool isSuccessor(const MachineBasicBlock *MBB) const;
399 
400  /// isLayoutSuccessor - Return true if the specified MBB will be emitted
401  /// immediately after this block, such that if this block exits by
402  /// falling through, control will transfer to the specified MBB. Note
403  /// that MBB need not be a successor at all, for example if this block
404  /// ends with an unconditional branch to some other block.
405  bool isLayoutSuccessor(const MachineBasicBlock *MBB) const;
406 
407  /// canFallThrough - Return true if the block can implicitly transfer
408  /// control to the block after it by falling off the end of it. This should
409  /// return false if it can reach the block after it, but it uses an explicit
410  /// branch to do so (e.g., a table jump). True is a conservative answer.
411  bool canFallThrough();
412 
413  /// Returns a pointer to the first instruction in this block that is not a
414  /// PHINode instruction. When adding instructions to the beginning of the
415  /// basic block, they should be added before the returned value, not before
416  /// the first instruction, which might be PHI.
417  /// Returns end() is there's no non-PHI instruction.
419 
420  /// SkipPHIsAndLabels - Return the first instruction in MBB after I that is
421  /// not a PHI or a label. This is the correct point to insert copies at the
422  /// beginning of a basic block.
424 
425  /// getFirstTerminator - returns an iterator to the first terminator
426  /// instruction of this basic block. If a terminator does not exist,
427  /// it returns end()
430 
431  /// getFirstInstrTerminator - Same getFirstTerminator but it ignores bundles
432  /// and return an instr_iterator instead.
434 
435  /// getLastNonDebugInstr - returns an iterator to the last non-debug
436  /// instruction in the basic block, or end()
439 
440  /// SplitCriticalEdge - Split the critical edge from this block to the
441  /// given successor block, and return the newly created block, or null
442  /// if splitting is not possible.
443  ///
444  /// This function updates LiveVariables, MachineDominatorTree, and
445  /// MachineLoopInfo, as applicable.
447 
448  void pop_front() { Insts.pop_front(); }
449  void pop_back() { Insts.pop_back(); }
450  void push_back(MachineInstr *MI) { Insts.push_back(MI); }
451 
452  /// Insert MI into the instruction list before I, possibly inside a bundle.
453  ///
454  /// If the insertion point is inside a bundle, MI will be added to the bundle,
455  /// otherwise MI will not be added to any bundle. That means this function
456  /// alone can't be used to prepend or append instructions to bundles. See
457  /// MIBundleBuilder::insert() for a more reliable way of doing that.
459 
460  /// Insert a range of instructions into the instruction list before I.
461  template<typename IT>
462  void insert(iterator I, IT S, IT E) {
463  Insts.insert(I.getInstrIterator(), S, E);
464  }
465 
466  /// Insert MI into the instruction list before I.
468  assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&
469  "Cannot insert instruction with bundle flags");
470  return Insts.insert(I.getInstrIterator(), MI);
471  }
472 
473  /// Insert MI into the instruction list after I.
475  assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&
476  "Cannot insert instruction with bundle flags");
477  return Insts.insertAfter(I.getInstrIterator(), MI);
478  }
479 
480  /// Remove an instruction from the instruction list and delete it.
481  ///
482  /// If the instruction is part of a bundle, the other instructions in the
483  /// bundle will still be bundled after removing the single instruction.
485 
486  /// Remove an instruction from the instruction list and delete it.
487  ///
488  /// If the instruction is part of a bundle, the other instructions in the
489  /// bundle will still be bundled after removing the single instruction.
491  return erase(instr_iterator(I));
492  }
493 
494  /// Remove a range of instructions from the instruction list and delete them.
496  return Insts.erase(I.getInstrIterator(), E.getInstrIterator());
497  }
498 
499  /// Remove an instruction or bundle from the instruction list and delete it.
500  ///
501  /// If I points to a bundle of instructions, they are all erased.
503  return erase(I, llvm::next(I));
504  }
505 
506  /// Remove an instruction from the instruction list and delete it.
507  ///
508  /// If I is the head of a bundle of instructions, the whole bundle will be
509  /// erased.
511  return erase(iterator(I));
512  }
513 
514  /// Remove the unbundled instruction from the instruction list without
515  /// deleting it.
516  ///
517  /// This function can not be used to remove bundled instructions, use
518  /// remove_instr to remove individual instructions from a bundle.
520  assert(!I->isBundled() && "Cannot remove bundled instructions");
521  return Insts.remove(I);
522  }
523 
524  /// Remove the possibly bundled instruction from the instruction list
525  /// without deleting it.
526  ///
527  /// If the instruction is part of a bundle, the other instructions in the
528  /// bundle will still be bundled after removing the single instruction.
530 
531  void clear() {
532  Insts.clear();
533  }
534 
535  /// Take an instruction from MBB 'Other' at the position From, and insert it
536  /// into this MBB right before 'Where'.
537  ///
538  /// If From points to a bundle of instructions, the whole bundle is moved.
539  void splice(iterator Where, MachineBasicBlock *Other, iterator From) {
540  // The range splice() doesn't allow noop moves, but this one does.
541  if (Where != From)
542  splice(Where, Other, From, llvm::next(From));
543  }
544 
545  /// Take a block of instructions from MBB 'Other' in the range [From, To),
546  /// and insert them into this MBB right before 'Where'.
547  ///
548  /// The instruction at 'Where' must not be included in the range of
549  /// instructions to move.
550  void splice(iterator Where, MachineBasicBlock *Other,
551  iterator From, iterator To) {
552  Insts.splice(Where.getInstrIterator(), Other->Insts,
553  From.getInstrIterator(), To.getInstrIterator());
554  }
555 
556  /// removeFromParent - This method unlinks 'this' from the containing
557  /// function, and returns it, but does not delete it.
559 
560  /// eraseFromParent - This method unlinks 'this' from the containing
561  /// function and deletes it.
562  void eraseFromParent();
563 
564  /// ReplaceUsesOfBlockWith - Given a machine basic block that branched to
565  /// 'Old', change the code and CFG so that it branches to 'New' instead.
567 
568  /// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in
569  /// the CFG to be inserted. If we have proven that MBB can only branch to
570  /// DestA and DestB, remove any other MBB successors from the CFG. DestA and
571  /// DestB can be null. Besides DestA and DestB, retain other edges leading
572  /// to LandingPads (currently there can be only one; we don't check or require
573  /// that here). Note it is possible that DestA and/or DestB are LandingPads.
575  MachineBasicBlock *DestB,
576  bool isCond);
577 
578  /// findDebugLoc - find the next valid DebugLoc starting at MBBI, skipping
579  /// any DBG_VALUE instructions. Return UnknownLoc if there is none.
582  return findDebugLoc(MBBI.getInstrIterator());
583  }
584 
585  /// Possible outcome of a register liveness query to computeRegisterLiveness()
587  LQR_Live, ///< Register is known to be live.
588  LQR_OverlappingLive, ///< Register itself is not live, but some overlapping
589  ///< register is.
590  LQR_Dead, ///< Register is known to be dead.
591  LQR_Unknown ///< Register liveness not decidable from local
592  ///< neighborhood.
593  };
594 
595  /// computeRegisterLiveness - Return whether (physical) register \c Reg
596  /// has been <def>ined and not <kill>ed as of just before \c MI.
597  ///
598  /// Search is localised to a neighborhood of
599  /// \c Neighborhood instructions before (searching for defs or kills) and
600  /// Neighborhood instructions after (searching just for defs) MI.
601  ///
602  /// \c Reg must be a physical register.
604  unsigned Reg, MachineInstr *MI,
605  unsigned Neighborhood=10);
606 
607  // Debugging methods.
608  void dump() const;
609  void print(raw_ostream &OS, SlotIndexes* = 0) const;
610 
611  /// getNumber - MachineBasicBlocks are uniquely numbered at the function
612  /// level, unless they're not in a MachineFunction yet, in which case this
613  /// will return -1.
614  ///
615  int getNumber() const { return Number; }
616  void setNumber(int N) { Number = N; }
617 
618  /// getSymbol - Return the MCSymbol for this basic block.
619  ///
620  MCSymbol *getSymbol() const;
621 
622 
623 private:
624  /// getWeightIterator - Return weight iterator corresponding to the I
625  /// successor iterator.
626  weight_iterator getWeightIterator(succ_iterator I);
627  const_weight_iterator getWeightIterator(const_succ_iterator I) const;
628 
630 
631  /// getSuccWeight - Return weight of the edge from this block to MBB. This
632  /// method should NOT be called directly, but by using getEdgeWeight method
633  /// from MachineBranchProbabilityInfo class.
634  uint32_t getSuccWeight(const_succ_iterator Succ) const;
635 
636 
637  // Methods used to maintain doubly linked list of blocks...
639 
640  // Machine-CFG mutators
641 
642  /// addPredecessor - Remove pred as a predecessor of this MachineBasicBlock.
643  /// Don't do this unless you know what you're doing, because it doesn't
644  /// update pred's successors list. Use pred->addSuccessor instead.
645  ///
646  void addPredecessor(MachineBasicBlock *pred);
647 
648  /// removePredecessor - Remove pred as a predecessor of this
649  /// MachineBasicBlock. Don't do this unless you know what you're
650  /// doing, because it doesn't update pred's successors list. Use
651  /// pred->removeSuccessor instead.
652  ///
653  void removePredecessor(MachineBasicBlock *pred);
654 };
655 
657 
658 void WriteAsOperand(raw_ostream &, const MachineBasicBlock*, bool t);
659 
660 // This is useful when building IndexedMaps keyed on basic block pointers.
662  public std::unary_function<const MachineBasicBlock*, unsigned> {
663  unsigned operator()(const MachineBasicBlock *MBB) const {
664  return MBB->getNumber();
665  }
666 };
667 
668 //===--------------------------------------------------------------------===//
669 // GraphTraits specializations for machine basic block graphs (machine-CFGs)
670 //===--------------------------------------------------------------------===//
671 
672 // Provide specializations of GraphTraits to be able to treat a
673 // MachineFunction as a graph of MachineBasicBlocks...
674 //
675 
676 template <> struct GraphTraits<MachineBasicBlock *> {
679 
680  static NodeType *getEntryNode(MachineBasicBlock *BB) { return BB; }
681  static inline ChildIteratorType child_begin(NodeType *N) {
682  return N->succ_begin();
683  }
684  static inline ChildIteratorType child_end(NodeType *N) {
685  return N->succ_end();
686  }
687 };
688 
689 template <> struct GraphTraits<const MachineBasicBlock *> {
692 
693  static NodeType *getEntryNode(const MachineBasicBlock *BB) { return BB; }
694  static inline ChildIteratorType child_begin(NodeType *N) {
695  return N->succ_begin();
696  }
697  static inline ChildIteratorType child_end(NodeType *N) {
698  return N->succ_end();
699  }
700 };
701 
702 // Provide specializations of GraphTraits to be able to treat a
703 // MachineFunction as a graph of MachineBasicBlocks... and to walk it
704 // in inverse order. Inverse order for a function is considered
705 // to be when traversing the predecessor edges of a MBB
706 // instead of the successor edges.
707 //
708 template <> struct GraphTraits<Inverse<MachineBasicBlock*> > {
712  return G.Graph;
713  }
714  static inline ChildIteratorType child_begin(NodeType *N) {
715  return N->pred_begin();
716  }
717  static inline ChildIteratorType child_end(NodeType *N) {
718  return N->pred_end();
719  }
720 };
721 
722 template <> struct GraphTraits<Inverse<const MachineBasicBlock*> > {
726  return G.Graph;
727  }
728  static inline ChildIteratorType child_begin(NodeType *N) {
729  return N->pred_begin();
730  }
731  static inline ChildIteratorType child_end(NodeType *N) {
732  return N->pred_end();
733  }
734 };
735 
736 
737 
738 /// MachineInstrSpan provides an interface to get an iteration range
739 /// containing the instruction it was initialized with, along with all
740 /// those instructions inserted prior to or following that instruction
741 /// at some point after the MachineInstrSpan is constructed.
743  MachineBasicBlock &MBB;
745 public:
747  : MBB(*I->getParent()),
748  I(I),
749  B(I == MBB.begin() ? MBB.end() : llvm::prior(I)),
750  E(llvm::next(I)) {}
751 
753  return B == MBB.end() ? MBB.begin() : llvm::next(B);
754  }
756  bool empty() { return begin() == end(); }
757 
759 };
760 
761 } // End llvm namespace
762 
763 #endif
static ChildIteratorType child_end(NodeType *N)
pred_reverse_iterator pred_rbegin()
unsigned succ_size() const
static void noteHead(MachineInstr *, MachineInstr *)
const MachineFunction * getParent() const
instr_iterator erase(instr_iterator I)
pred_reverse_iterator pred_rend()
const_instr_iterator instr_begin() const
instr_iterator instr_begin()
void transferNodesFromList(ilist_node_traits &, ilist_iterator< NodeTy >, ilist_iterator< NodeTy >)
Definition: ilist.h:117
void removeNodeFromList(NodeTy *)
Definition: ilist.h:116
instr_iterator instr_end()
bool operator==(const bundle_iterator &x) const
iplist< MachineInstr >::iterator iterator
Definition: ilist.h:642
void pop_back()
Definition: ilist.h:559
Various leaf nodes.
Definition: ISDOpcodes.h:60
static NodeTy * createNode(const NodeTy &V)
Definition: ilist.h:112
void setIsLandingPad(bool V=true)
reverse_iterator rend()
Definition: ilist.h:379
Instructions::const_iterator const_instr_iterator
const_succ_iterator succ_begin() const
instr_iterator getFirstInstrTerminator()
MachineBasicBlock::pred_iterator ChildIteratorType
bundle_iterator(const bundle_iterator< OtherTy, OtherIterTy > &I)
std::vector< unsigned >::const_iterator livein_iterator
MachineBasicBlock::succ_iterator ChildIteratorType
void removeLiveIn(unsigned Reg)
static NodeType * getEntryNode(MachineBasicBlock *BB)
void addLiveIn(unsigned Reg)
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, unsigned Reg, MachineInstr *MI, unsigned Neighborhood=10)
DebugLoc findDebugLoc(iterator MBBI)
void moveAfter(MachineBasicBlock *NewBefore)
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *fromMBB)
iterator begin()
Definition: ilist.h:359
std::reverse_iterator< const_instr_iterator > const_reverse_instr_iterator
MachineInstr * createSentinel() const
Instructions::iterator instr_iterator
MachineInstrSpan(MachineBasicBlock::iterator I)
iterator insert(iterator I, MachineInstr *MI)
Insert MI into the instruction list before I.
MachineBasicBlock * removeFromParent()
void setAlignment(unsigned Align)
void splice(iterator Where, MachineBasicBlock *Other, iterator From, iterator To)
reverse_iterator rbegin()
Definition: ilist.h:377
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy=true, const Module *Context=0)
Definition: AsmWriter.cpp:1179
std::vector< MachineBasicBlock * >::const_reverse_iterator const_pred_reverse_iterator
livein_iterator livein_begin() const
void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New)
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT,"arm-default-it","Generate IT block based on arch"), clEnumValN(RestrictedIT,"arm-restrict-it","Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT,"arm-no-restrict-it","Allow IT blocks based on ARMv7"), clEnumValEnd))
iterator erase(MachineInstr *I)
void insert(iterator I, IT S, IT E)
Insert a range of instructions into the instruction list before I.
std::vector< MachineBasicBlock * >::iterator succ_iterator
MachineBasicBlock * SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P)
void print(raw_ostream &OS, SlotIndexes *=0) const
MachineInstr * remove_instr(MachineInstr *I)
void destroySentinel(MachineInstr *) const
MachineBasicBlock::iterator end()
#define G(x, y, z)
Definition: MD5.cpp:52
void clear()
Definition: ilist.h:550
static NodeType * getEntryNode(const MachineBasicBlock *BB)
bool isBundledWithSucc() const
Definition: MachineInstr.h:226
void transferSuccessors(MachineBasicBlock *fromMBB)
std::reverse_iterator< instr_iterator > reverse_instr_iterator
const_succ_iterator succ_end() const
const MachineInstr & front() const
std::vector< MachineBasicBlock * >::iterator pred_iterator
succ_reverse_iterator succ_rend()
reverse_iterator rend()
const_pred_iterator pred_end() const
reverse_iterator rbegin()
const BasicBlock * getBasicBlock() const
static NodeType * getEntryNode(Inverse< MachineBasicBlock * > G)
const_reverse_instr_iterator instr_rend() const
bundle_iterator< MachineInstr, instr_iterator > iterator
#define P(N)
static NodeType * getEntryNode(Inverse< const MachineBasicBlock * > G)
iterator SkipPHIsAndLabels(iterator I)
instr_iterator erase_instr(MachineInstr *I)
LLVM Basic Block Representation.
Definition: BasicBlock.h:72
static ChildIteratorType child_end(NodeType *N)
succ_reverse_iterator succ_rbegin()
size_type LLVM_ATTRIBUTE_UNUSED_RESULT size() const
Definition: ilist.h:539
const_iterator begin() const
livein_iterator livein_end() const
iterator insertAfter(iterator where, NodeTy *New)
Definition: ilist.h:428
iterator insert(iterator where, const NodeTy &val)
Definition: ilist.h:664
Register is known to be dead.
ItTy next(ItTy it, Dist n)
Definition: STLExtras.h:154
std::reverse_iterator< const_iterator > const_reverse_iterator
const MachineBasicBlock * getLandingPadSuccessor() const
const_reverse_instr_iterator instr_rbegin() const
bool isBundledWithPred() const
Definition: MachineInstr.h:222
LivenessQueryResult
Possible outcome of a register liveness query to computeRegisterLiveness()
Register is known to be live.
void removeSuccessor(MachineBasicBlock *succ)
bool operator!=(const bundle_iterator &x) const
void moveBefore(MachineBasicBlock *NewAfter)
iterator erase(iterator I)
static ChildIteratorType child_begin(NodeType *N)
MCSymbol * getSymbol() const
iterator erase(iterator I, iterator E)
Remove a range of instructions from the instruction list and delete them.
iterator erase(iterator where)
Definition: ilist.h:465
std::vector< MachineBasicBlock * >::const_iterator const_pred_iterator
DebugLoc findDebugLoc(instr_iterator MBBI)
std::string getFullName() const
Return a hopefully unique identifier for this block.
MachineInstr * ensureHead(MachineInstr *) const
const_iterator end() const
const GraphType & Graph
Definition: GraphTraits.h:79
reverse_instr_iterator instr_rbegin()
const_succ_reverse_iterator succ_rbegin() const
std::vector< MachineBasicBlock * >::const_reverse_iterator const_succ_reverse_iterator
const_succ_reverse_iterator succ_rend() const
std::vector< MachineBasicBlock * >::reverse_iterator succ_reverse_iterator
bool isSuccessor(const MachineBasicBlock *MBB) const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Definition: ilist.h:385
MachineBasicBlock::iterator getInitial()
const_reverse_iterator rbegin() const
void splice(iterator where, iplist &L2)
Definition: ilist.h:570
reverse_instr_iterator instr_rend()
static void deleteNode(NodeTy *V)
Definition: ilist.h:113
StringRef getName() const
MachineBasicBlock::const_succ_iterator ChildIteratorType
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
MachineFunction * getParent()
MachineInstr * provideInitialHead() const
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
reference front()
Definition: ilist.h:390
bundle_iterator< const MachineInstr, const_instr_iterator > const_iterator
const_pred_iterator pred_begin() const
void addNodeToList(NodeTy *)
Definition: ilist.h:115
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
bool isLiveIn(unsigned Reg) const
std::reverse_iterator< const_iterator > reverse_iterator
Definition: Path.h:79
const_reverse_iterator rend() const
void push_back(MachineInstr *MI)
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
const_pred_reverse_iterator pred_rbegin() const
instr_iterator insert(instr_iterator I, MachineInstr *M)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1688
reference back()
Definition: ilist.h:398
static ChildIteratorType child_begin(NodeType *N)
MachineBasicBlock::const_pred_iterator ChildIteratorType
static NodeTy * createSentinel()
createSentinel - create the dynamic sentinel
Definition: ilist.h:78
static ChildIteratorType child_begin(NodeType *N)
iterator end()
Definition: ilist.h:367
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
std::reverse_iterator< iterator > reverse_iterator
void pop_front()
Definition: ilist.h:555
std::vector< MachineBasicBlock * >::reverse_iterator pred_reverse_iterator
static const Function * getParent(const Value *V)
ItTy prior(ItTy it, Dist n)
Definition: STLExtras.h:167
const_pred_reverse_iterator pred_rend() const
bool isPredecessor(const MachineBasicBlock *MBB) const
const MachineInstr & back() const
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
const_instr_iterator instr_end() const
NodeTy * remove(iterator &IT)
Definition: ilist.h:435
void addSuccessor(MachineBasicBlock *succ, uint32_t weight=0)
unsigned pred_size() const
bool CorrectExtraCFGEdges(MachineBasicBlock *DestA, MachineBasicBlock *DestB, bool isCond)
static ChildIteratorType child_end(NodeType *N)
unsigned operator()(const MachineBasicBlock *MBB) const
void push_back(const NodeTy &val)
Definition: ilist.h:671
MachineBasicBlock::iterator begin()
unsigned getAlignment() const