MachineBasicBlock.h revision 81bf03eb5cd68243eabb52505105aa5f4a831bf3
151a8d8528135ba4e3e4cf7cd711a9e47b19078a3Chris Lattner//===-- llvm/CodeGen/MachineBasicBlock.h ------------------------*- C++ -*-===//
2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
7ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===//
9ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
10e8b5413e5d0c7c0fc5b384e975c4ca87f4c00699Chris Lattner// Collect the sequence of machine instructions for a basic block.
11e8b5413e5d0c7c0fc5b384e975c4ca87f4c00699Chris Lattner//
1251a8d8528135ba4e3e4cf7cd711a9e47b19078a3Chris Lattner//===----------------------------------------------------------------------===//
13deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve
14fce1143bcfa73f61845002fa50473d1a01384202Misha Brukman#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
15fce1143bcfa73f61845002fa50473d1a01384202Misha Brukman#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
16deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve
17c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos#include "llvm/CodeGen/MachineInstr.h"
18551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencer#include "llvm/ADT/GraphTraits.h"
19d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
20d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
21fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
22fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass BasicBlock;
23fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineFunction;
24a655f088b88cf015fc48721fd9869787d1b8ce13Chris Lattnerclass MCSymbol;
25a655f088b88cf015fc48721fd9869787d1b8ce13Chris Lattnerclass StringRef;
261cd1d98232c3c3a0bd3810c3bf6c2572ea02f208Daniel Dunbarclass raw_ostream;
27d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
2894dc07728f091c652f0a8059aba6dce5018485eeAlkis Evlogimenostemplate <>
298e4018e2de52c534405d7155c7009d0b35afb861Cedric Venetstruct ilist_traits<MachineInstr> : public ilist_default_traits<MachineInstr> {
308e4018e2de52c534405d7155c7009d0b35afb861Cedric Venetprivate:
317309be6735666143bd9835b275dc8501617a2591Gabor Greif  mutable ilist_half_node<MachineInstr> Sentinel;
32fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
338e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  // this is only set by the MachineBasicBlock owning the LiveList
3494dc07728f091c652f0a8059aba6dce5018485eeAlkis Evlogimenos  friend class MachineBasicBlock;
358e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineBasicBlock* Parent;
3694dc07728f091c652f0a8059aba6dce5018485eeAlkis Evlogimenos
378e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohmanpublic:
38c7f6b8c5d40e17bf43fd3a1549d7d89c9da735e1Gabor Greif  MachineInstr *createSentinel() const {
39c7f6b8c5d40e17bf43fd3a1549d7d89c9da735e1Gabor Greif    return static_cast<MachineInstr*>(&Sentinel);
40c7f6b8c5d40e17bf43fd3a1549d7d89c9da735e1Gabor Greif  }
41fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  void destroySentinel(MachineInstr *) const {}
4294dc07728f091c652f0a8059aba6dce5018485eeAlkis Evlogimenos
43c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  MachineInstr *provideInitialHead() const { return createSentinel(); }
44c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  MachineInstr *ensureHead(MachineInstr*) const { return createSentinel(); }
45f3841fcbd587c31aa9842b3f33bd57de40c9f443Gabor Greif  static void noteHead(MachineInstr*, MachineInstr*) {}
46c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif
47aad5c0505183a5b7913f1a443a1f0650122551ccAlkis Evlogimenos  void addNodeToList(MachineInstr* N);
48aad5c0505183a5b7913f1a443a1f0650122551ccAlkis Evlogimenos  void removeNodeFromList(MachineInstr* N);
49fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  void transferNodesFromList(ilist_traits &SrcTraits,
50fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman                             ilist_iterator<MachineInstr> first,
51fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman                             ilist_iterator<MachineInstr> last);
528e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void deleteNode(MachineInstr *N);
53fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanprivate:
54fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  void createNode(const MachineInstr &);
5594dc07728f091c652f0a8059aba6dce5018485eeAlkis Evlogimenos};
5694dc07728f091c652f0a8059aba6dce5018485eeAlkis Evlogimenos
57fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineBasicBlock : public ilist_node<MachineBasicBlock> {
58fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  typedef ilist<MachineInstr> Instructions;
59c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos  Instructions Insts;
601194e9501984daf0d3237ed1bf18a156173e7fd4Chris Lattner  const BasicBlock *BB;
61c07d8d8a26f63dfc54dbd0e1ff776763ec6443adBrian Gaeke  int Number;
62f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  MachineFunction *xParent;
63f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner
6413d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  /// Predecessors/Successors - Keep track of the predecessor / successor
6513d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  /// basicblocks.
6613d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  std::vector<MachineBasicBlock *> Predecessors;
6713d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  std::vector<MachineBasicBlock *> Successors;
6813d828567812041c1ca1817f4b66fce840903a1fEvan Cheng
6913d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  /// LiveIns - Keep track of the physical registers that are livein of
7013d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  /// the basicblock.
7113d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  std::vector<unsigned> LiveIns;
72fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng
73fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng  /// Alignment - Alignment of the basic block. Zero if the basic block does
74fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng  /// not need to be aligned.
75fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng  unsigned Alignment;
7630b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey
7730b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey  /// IsLandingPad - Indicate that this basic block is entered via an
7830b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey  /// exception handler.
7930b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey  bool IsLandingPad;
8013d828567812041c1ca1817f4b66fce840903a1fEvan Cheng
818c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman  /// AddressTaken - Indicate that this basic block is potentially the
828c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman  /// target of an indirect branch.
838c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman  bool AddressTaken;
848c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman
85fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  // Intrusive list support
86fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  MachineBasicBlock() {}
87fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
888e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  explicit MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb);
898e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
902c3f7ae3843bdc9dcfe85393e178211976c1f9bdDan Gohman  ~MachineBasicBlock();
9117fb34bf8cd10a798c9206eeef3bff151b4d3688Tanya Lattner
928e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  // MachineBasicBlocks are allocated and owned by MachineFunction.
938e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  friend class MachineFunction;
94ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
958e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohmanpublic:
96d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  /// getBasicBlock - Return the LLVM basic block that this instance
97324da7647cfc3025e0c987176f0a300f9f780e6fJakob Stoklund Olesen  /// corresponded to originally. Note that this may be NULL if this instance
98324da7647cfc3025e0c987176f0a300f9f780e6fJakob Stoklund Olesen  /// does not correspond directly to an LLVM basic block.
99d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  ///
1001194e9501984daf0d3237ed1bf18a156173e7fd4Chris Lattner  const BasicBlock *getBasicBlock() const { return BB; }
1015e61fa95196b85281eec655787e9c73267532bd1Chris Lattner
102324da7647cfc3025e0c987176f0a300f9f780e6fJakob Stoklund Olesen  /// getName - Return the name of the corresponding LLVM basic block, or
103324da7647cfc3025e0c987176f0a300f9f780e6fJakob Stoklund Olesen  /// "(null)".
104324da7647cfc3025e0c987176f0a300f9f780e6fJakob Stoklund Olesen  StringRef getName() const;
105324da7647cfc3025e0c987176f0a300f9f780e6fJakob Stoklund Olesen
1068c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman  /// hasAddressTaken - Test whether this block is potentially the target
1078c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman  /// of an indirect branch.
1088c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman  bool hasAddressTaken() const { return AddressTaken; }
1098c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman
1108c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman  /// setHasAddressTaken - Set this block to reflect that it potentially
1118c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman  /// is the target of an indirect branch.
1128c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman  void setHasAddressTaken() { AddressTaken = true; }
1138c2b52552c90f39e4b2fed43e309e599e742b6acDan Gohman
1145e61fa95196b85281eec655787e9c73267532bd1Chris Lattner  /// getParent - Return the MachineFunction containing this basic block.
1155e61fa95196b85281eec655787e9c73267532bd1Chris Lattner  ///
116f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  const MachineFunction *getParent() const { return xParent; }
117f20c1a497fe3922ac718429d65a5fe396890575eChris Lattner  MachineFunction *getParent() { return xParent; }
1185e61fa95196b85281eec655787e9c73267532bd1Chris Lattner
1198e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  typedef Instructions::iterator                              iterator;
1208e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  typedef Instructions::const_iterator                  const_iterator;
121deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
122deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  typedef std::reverse_iterator<iterator>             reverse_iterator;
123deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve
12434cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  unsigned size() const { return (unsigned)Insts.size(); }
125deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  bool empty() const { return Insts.empty(); }
126deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve
127c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos  MachineInstr& front() { return Insts.front(); }
128c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos  MachineInstr& back()  { return Insts.back(); }
1298e8b8a223c2b0e69f44c0639f846260c8011668fDan Gohman  const MachineInstr& front() const { return Insts.front(); }
1308e8b8a223c2b0e69f44c0639f846260c8011668fDan Gohman  const MachineInstr& back()  const { return Insts.back(); }
131deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve
132deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  iterator                begin()       { return Insts.begin();  }
133deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  const_iterator          begin() const { return Insts.begin();  }
134deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  iterator                  end()       { return Insts.end();    }
135deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  const_iterator            end() const { return Insts.end();    }
136deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  reverse_iterator       rbegin()       { return Insts.rbegin(); }
137deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  const_reverse_iterator rbegin() const { return Insts.rbegin(); }
138deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  reverse_iterator       rend  ()       { return Insts.rend();   }
139deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  const_reverse_iterator rend  () const { return Insts.rend();   }
140deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve
14176456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  // Machine-CFG iterators
14276456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  typedef std::vector<MachineBasicBlock *>::iterator       pred_iterator;
14376456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  typedef std::vector<MachineBasicBlock *>::const_iterator const_pred_iterator;
14476456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  typedef std::vector<MachineBasicBlock *>::iterator       succ_iterator;
14576456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  typedef std::vector<MachineBasicBlock *>::const_iterator const_succ_iterator;
1466603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  typedef std::vector<MachineBasicBlock *>::reverse_iterator
1476603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                                         pred_reverse_iterator;
1486603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
1496603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                                   const_pred_reverse_iterator;
1506603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  typedef std::vector<MachineBasicBlock *>::reverse_iterator
1516603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                                         succ_reverse_iterator;
1526603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
1536603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                                   const_succ_reverse_iterator;
154ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
155cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  pred_iterator        pred_begin()       { return Predecessors.begin(); }
156cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  const_pred_iterator  pred_begin() const { return Predecessors.begin(); }
157cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  pred_iterator        pred_end()         { return Predecessors.end();   }
158cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  const_pred_iterator  pred_end()   const { return Predecessors.end();   }
1596603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  pred_reverse_iterator        pred_rbegin()
1606603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                          { return Predecessors.rbegin();}
1616603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  const_pred_reverse_iterator  pred_rbegin() const
1626603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                          { return Predecessors.rbegin();}
1636603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  pred_reverse_iterator        pred_rend()
1646603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                          { return Predecessors.rend();  }
1656603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  const_pred_reverse_iterator  pred_rend()   const
1666603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                          { return Predecessors.rend();  }
16734cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  unsigned             pred_size()  const {
16834cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng    return (unsigned)Predecessors.size();
16934cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  }
170cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  bool                 pred_empty() const { return Predecessors.empty(); }
171cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  succ_iterator        succ_begin()       { return Successors.begin();   }
172cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  const_succ_iterator  succ_begin() const { return Successors.begin();   }
173cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  succ_iterator        succ_end()         { return Successors.end();     }
174cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  const_succ_iterator  succ_end()   const { return Successors.end();     }
1756603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  succ_reverse_iterator        succ_rbegin()
1766603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                          { return Successors.rbegin();  }
1776603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  const_succ_reverse_iterator  succ_rbegin() const
1786603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                          { return Successors.rbegin();  }
1796603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  succ_reverse_iterator        succ_rend()
1806603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                          { return Successors.rend();    }
1816603d7ec67e64b987451975771759ade4e9f19baEvan Cheng  const_succ_reverse_iterator  succ_rend()   const
1826603d7ec67e64b987451975771759ade4e9f19baEvan Cheng                                          { return Successors.rend();    }
18334cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  unsigned             succ_size()  const {
18434cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng    return (unsigned)Successors.size();
18534cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  }
186cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  bool                 succ_empty() const { return Successors.empty();   }
18776456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke
18813d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  // LiveIn management methods.
18913d828567812041c1ca1817f4b66fce840903a1fEvan Cheng
19013d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  /// addLiveIn - Add the specified register as a live in.  Note that it
19113d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  /// is an error to add the same register to the same set more than once.
19213d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  void addLiveIn(unsigned Reg)  { LiveIns.push_back(Reg); }
19313d828567812041c1ca1817f4b66fce840903a1fEvan Cheng
194b371f457b0ea4a652a9f526ba4375c80ae542252Evan Cheng  /// removeLiveIn - Remove the specified register from the live in set.
195b371f457b0ea4a652a9f526ba4375c80ae542252Evan Cheng  ///
196b371f457b0ea4a652a9f526ba4375c80ae542252Evan Cheng  void removeLiveIn(unsigned Reg);
197b371f457b0ea4a652a9f526ba4375c80ae542252Evan Cheng
198a971dbdde27fd4ff53dbebdd4aaf87826d081aa2Evan Cheng  /// isLiveIn - Return true if the specified register is in the live in set.
199a971dbdde27fd4ff53dbebdd4aaf87826d081aa2Evan Cheng  ///
200a971dbdde27fd4ff53dbebdd4aaf87826d081aa2Evan Cheng  bool isLiveIn(unsigned Reg) const;
201a971dbdde27fd4ff53dbebdd4aaf87826d081aa2Evan Cheng
20213d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  // Iteration support for live in sets.  These sets are kept in sorted
20313d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  // order by their register number.
20481bf03eb5cd68243eabb52505105aa5f4a831bf3Dan Gohman  typedef std::vector<unsigned>::const_iterator livein_iterator;
20581bf03eb5cd68243eabb52505105aa5f4a831bf3Dan Gohman  livein_iterator livein_begin() const { return LiveIns.begin(); }
20681bf03eb5cd68243eabb52505105aa5f4a831bf3Dan Gohman  livein_iterator livein_end()   const { return LiveIns.end(); }
20713d828567812041c1ca1817f4b66fce840903a1fEvan Cheng  bool            livein_empty() const { return LiveIns.empty(); }
20813d828567812041c1ca1817f4b66fce840903a1fEvan Cheng
209fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng  /// getAlignment - Return alignment of the basic block.
210fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng  ///
211fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng  unsigned getAlignment() const { return Alignment; }
212fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng
213fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng  /// setAlignment - Set alignment of the basic block.
214fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng  ///
215fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng  void setAlignment(unsigned Align) { Alignment = Align; }
216fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng
21730b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey  /// isLandingPad - Returns true if the block is a landing pad. That is
21830b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey  /// this basic block is entered via an exception handler.
21930b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey  bool isLandingPad() const { return IsLandingPad; }
22030b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey
22130b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey  /// setIsLandingPad - Indicates the block is a landing pad.  That is
22230b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey  /// this basic block is entered via an exception handler.
22330b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey  void setIsLandingPad() { IsLandingPad = true; }
22430b8e51addc23fb317c03d093a25828d3d5be45aJim Laskey
22534ea07692f4cd7c007f1c5062bcebb6d03131077Chris Lattner  // Code Layout methods.
22634ea07692f4cd7c007f1c5062bcebb6d03131077Chris Lattner
22734ea07692f4cd7c007f1c5062bcebb6d03131077Chris Lattner  /// moveBefore/moveAfter - move 'this' block before or after the specified
22834ea07692f4cd7c007f1c5062bcebb6d03131077Chris Lattner  /// block.  This only moves the block, it does not modify the CFG or adjust
22934ea07692f4cd7c007f1c5062bcebb6d03131077Chris Lattner  /// potential fall-throughs at the end of the block.
23034ea07692f4cd7c007f1c5062bcebb6d03131077Chris Lattner  void moveBefore(MachineBasicBlock *NewAfter);
23134ea07692f4cd7c007f1c5062bcebb6d03131077Chris Lattner  void moveAfter(MachineBasicBlock *NewBefore);
2327707a0df5b00c8326a581205639d6b2871f182e9Jim Grosbach
2337707a0df5b00c8326a581205639d6b2871f182e9Jim Grosbach  /// updateTerminator - Update the terminator instructions in block to account
2347707a0df5b00c8326a581205639d6b2871f182e9Jim Grosbach  /// for changes to the layout. If the block previously used a fallthrough,
2357707a0df5b00c8326a581205639d6b2871f182e9Jim Grosbach  /// it may now need a branch, and if it previously used branching it may now
2367707a0df5b00c8326a581205639d6b2871f182e9Jim Grosbach  /// be able to use a fallthrough.
2377707a0df5b00c8326a581205639d6b2871f182e9Jim Grosbach  void updateTerminator();
2387707a0df5b00c8326a581205639d6b2871f182e9Jim Grosbach
23976456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  // Machine-CFG mutators
24034ea07692f4cd7c007f1c5062bcebb6d03131077Chris Lattner
24176456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  /// addSuccessor - Add succ as a successor of this MachineBasicBlock.
24276456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  /// The Predecessors list of succ is automatically updated.
24376456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  ///
2443dfbb558b5e74554104710ed16807fe74ec220a3Chris Lattner  void addSuccessor(MachineBasicBlock *succ);
24576456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke
246dc4a4922d32b470acd68498d41e3b8130cf1e74eChris Lattner  /// removeSuccessor - Remove successor from the successors list of this
24776456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  /// MachineBasicBlock. The Predecessors list of succ is automatically updated.
24876456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke  ///
2493dfbb558b5e74554104710ed16807fe74ec220a3Chris Lattner  void removeSuccessor(MachineBasicBlock *succ);
250dc4a4922d32b470acd68498d41e3b8130cf1e74eChris Lattner
251dc4a4922d32b470acd68498d41e3b8130cf1e74eChris Lattner  /// removeSuccessor - Remove specified successor from the successors list of
252dc4a4922d32b470acd68498d41e3b8130cf1e74eChris Lattner  /// this MachineBasicBlock. The Predecessors list of succ is automatically
2538a46d342d8cbca7c9c7be6c66007d41329babad0David Greene  /// updated.  Return the iterator to the element after the one removed.
254dc4a4922d32b470acd68498d41e3b8130cf1e74eChris Lattner  ///
2558a46d342d8cbca7c9c7be6c66007d41329babad0David Greene  succ_iterator removeSuccessor(succ_iterator I);
256cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner
25763307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang  /// transferSuccessors - Transfers all the successors from MBB to this
25863307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang  /// machine basic block (i.e., copies all the successors fromMBB and
2591edb8e0910db4cda46a81a4abad80a2a755442aaDan Gohman  /// remove all the successors from fromMBB).
26063307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang  void transferSuccessors(MachineBasicBlock *fromMBB);
26163307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang
262cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  /// isSuccessor - Return true if the specified MBB is a successor of this
263cd5bad37112ba22f4c546e5443714570b4104bb6Chris Lattner  /// block.
2646d1b89e74f98470d05666ca9f59a8ec5d04b5eb4Dan Gohman  bool isSuccessor(const MachineBasicBlock *MBB) const;
26576456bc40c79fcae4da52d34f96c079d9759257cBrian Gaeke
2666ade6f55a836129af634074e96f660ff23f59a30Dan Gohman  /// isLayoutSuccessor - Return true if the specified MBB will be emitted
2676ade6f55a836129af634074e96f660ff23f59a30Dan Gohman  /// immediately after this block, such that if this block exits by
2686ade6f55a836129af634074e96f660ff23f59a30Dan Gohman  /// falling through, control will transfer to the specified MBB. Note
2696ade6f55a836129af634074e96f660ff23f59a30Dan Gohman  /// that MBB need not be a successor at all, for example if this block
2706ade6f55a836129af634074e96f660ff23f59a30Dan Gohman  /// ends with an unconditional branch to some other block.
2716d1b89e74f98470d05666ca9f59a8ec5d04b5eb4Dan Gohman  bool isLayoutSuccessor(const MachineBasicBlock *MBB) const;
2726ade6f55a836129af634074e96f660ff23f59a30Dan Gohman
27315acadde5f87703da5f36721a19c09a7e3f97f53Bob Wilson  /// canFallThrough - Return true if the block can implicitly transfer
27415acadde5f87703da5f36721a19c09a7e3f97f53Bob Wilson  /// control to the block after it by falling off the end of it.  This should
27515acadde5f87703da5f36721a19c09a7e3f97f53Bob Wilson  /// return false if it can reach the block after it, but it uses an explicit
27615acadde5f87703da5f36721a19c09a7e3f97f53Bob Wilson  /// branch to do so (e.g., a table jump).  True is a conservative answer.
27715acadde5f87703da5f36721a19c09a7e3f97f53Bob Wilson  bool canFallThrough();
27815acadde5f87703da5f36721a19c09a7e3f97f53Bob Wilson
279743d0a1f831f1d5a3141a6ca730558f40c35690aAlkis Evlogimenos  /// getFirstTerminator - returns an iterator to the first terminator
280743d0a1f831f1d5a3141a6ca730558f40c35690aAlkis Evlogimenos  /// instruction of this basic block. If a terminator does not exist,
281743d0a1f831f1d5a3141a6ca730558f40c35690aAlkis Evlogimenos  /// it returns end()
282743d0a1f831f1d5a3141a6ca730558f40c35690aAlkis Evlogimenos  iterator getFirstTerminator();
283743d0a1f831f1d5a3141a6ca730558f40c35690aAlkis Evlogimenos
2840bbcd6bfd1a90c2aa7386a88ba9fc9aba47d03a7Brian Gaeke  void pop_front() { Insts.pop_front(); }
285f24d879520a615a03f19ced3c7491f7b51934d1cChris Lattner  void pop_back() { Insts.pop_back(); }
286deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  void push_back(MachineInstr *MI) { Insts.push_back(MI); }
287deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  template<typename IT>
288deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  void insert(iterator I, IT S, IT E) { Insts.insert(I, S, E); }
289deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  iterator insert(iterator I, MachineInstr *M) { return Insts.insert(I, M); }
290deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve
29146d6a1aeb549a2e4ccd982a1a2cefda541d79c52Vikram S. Adve  // erase - Remove the specified element or range from the instruction list.
292c0b9dc5be79f009d260edb5cd5e1d8346587aaa2Alkis Evlogimenos  // These functions delete any instructions removed.
293deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  //
29446d6a1aeb549a2e4ccd982a1a2cefda541d79c52Vikram S. Adve  iterator erase(iterator I)             { return Insts.erase(I); }
295deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve  iterator erase(iterator I, iterator E) { return Insts.erase(I, E); }
29683706a5a3a6f19451765b743c5a72b62f74eb71aChris Lattner  MachineInstr *remove(MachineInstr *I)  { return Insts.remove(I); }
297da44b151259525abc9c299f89b9532f3a9883b4eBrian Gaeke  void clear()                           { Insts.clear(); }
298ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
299c475c3608a5f0fc0c6bd43da04ae786649690070Dan Gohman  /// splice - Take an instruction from MBB 'Other' at the position From,
300c475c3608a5f0fc0c6bd43da04ae786649690070Dan Gohman  /// and insert it into this MBB right before 'where'.
301c475c3608a5f0fc0c6bd43da04ae786649690070Dan Gohman  void splice(iterator where, MachineBasicBlock *Other, iterator From) {
302c475c3608a5f0fc0c6bd43da04ae786649690070Dan Gohman    Insts.splice(where, Other->Insts, From);
303c475c3608a5f0fc0c6bd43da04ae786649690070Dan Gohman  }
304c475c3608a5f0fc0c6bd43da04ae786649690070Dan Gohman
305f24d879520a615a03f19ced3c7491f7b51934d1cChris Lattner  /// splice - Take a block of instructions from MBB 'Other' in the range [From,
306f24d879520a615a03f19ced3c7491f7b51934d1cChris Lattner  /// To), and insert them into this MBB right before 'where'.
307f24d879520a615a03f19ced3c7491f7b51934d1cChris Lattner  void splice(iterator where, MachineBasicBlock *Other, iterator From,
308f24d879520a615a03f19ced3c7491f7b51934d1cChris Lattner              iterator To) {
309f24d879520a615a03f19ced3c7491f7b51934d1cChris Lattner    Insts.splice(where, Other->Insts, From, To);
310f24d879520a615a03f19ced3c7491f7b51934d1cChris Lattner  }
3118e7ae9860bd1f29c95e4e10fe151a22aaafafef9Chris Lattner
3128e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// removeFromParent - This method unlinks 'this' from the containing
3138e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// function, and returns it, but does not delete it.
3148e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineBasicBlock *removeFromParent();
3158e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
3168e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// eraseFromParent - This method unlinks 'this' from the containing
3178e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// function and deletes it.
3188e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void eraseFromParent();
3198e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
3200370fad74b48388412c52d1325512f2c218487faEvan Cheng  /// ReplaceUsesOfBlockWith - Given a machine basic block that branched to
3210370fad74b48388412c52d1325512f2c218487faEvan Cheng  /// 'Old', change the code and CFG so that it branches to 'New' instead.
3220370fad74b48388412c52d1325512f2c218487faEvan Cheng  void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New);
3230370fad74b48388412c52d1325512f2c218487faEvan Cheng
3242bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng  /// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in
3252bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng  /// the CFG to be inserted.  If we have proven that MBB can only branch to
3262bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng  /// DestA and DestB, remove any other MBB successors from the CFG. DestA and
3272bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng  /// DestB can be null. Besides DestA and DestB, retain other edges leading
3282bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng  /// to LandingPads (currently there can be only one; we don't check or require
3292bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng  /// that here). Note it is possible that DestA and/or DestB are LandingPads.
3302bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng  bool CorrectExtraCFGEdges(MachineBasicBlock *DestA,
3312bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng                            MachineBasicBlock *DestB,
3322bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng                            bool isCond);
3332bdb7d0cc88881857073b36f4a09ebe2f2008c24Evan Cheng
33473e884bb3e971b1e794ba2501df15138f73b8b1aDale Johannesen  /// findDebugLoc - find the next valid DebugLoc starting at MBBI, skipping
3353b1906f48d0b541e5be0bc1918c94a454e908bc0Dale Johannesen  /// any DBG_VALUE instructions.  Return UnknownLoc if there is none.
33673e884bb3e971b1e794ba2501df15138f73b8b1aDale Johannesen  DebugLoc findDebugLoc(MachineBasicBlock::iterator &MBBI);
33773e884bb3e971b1e794ba2501df15138f73b8b1aDale Johannesen
338f13a3f4dd1eaa89ca9a64a1e820b089facca3366Brian Gaeke  // Debugging methods.
339f13a3f4dd1eaa89ca9a64a1e820b089facca3366Brian Gaeke  void dump() const;
3402d8e3d20be377112999670f210200b3658762571Chris Lattner  void print(raw_ostream &OS) const;
341f13a3f4dd1eaa89ca9a64a1e820b089facca3366Brian Gaeke
342da86bdc75c8d36cb7b1f4e785a3749d7c8f8e638Brian Gaeke  /// getNumber - MachineBasicBlocks are uniquely numbered at the function
343da86bdc75c8d36cb7b1f4e785a3749d7c8f8e638Brian Gaeke  /// level, unless they're not in a MachineFunction yet, in which case this
344da86bdc75c8d36cb7b1f4e785a3749d7c8f8e638Brian Gaeke  /// will return -1.
345da86bdc75c8d36cb7b1f4e785a3749d7c8f8e638Brian Gaeke  ///
346c07d8d8a26f63dfc54dbd0e1ff776763ec6443adBrian Gaeke  int getNumber() const { return Number; }
34720a6d8e63056cc2025e7143a5f7226e079e0bc80Chris Lattner  void setNumber(int N) { Number = N; }
348c07d8d8a26f63dfc54dbd0e1ff776763ec6443adBrian Gaeke
349f71cb015c1386ff8adc9ef0aa03fc0f0fc4a6e3eChris Lattner  /// getSymbol - Return the MCSymbol for this basic block.
350f71cb015c1386ff8adc9ef0aa03fc0f0fc4a6e3eChris Lattner  ///
3511b2eb0e8a6aaf034675b17be6d853cb1c666200fChris Lattner  MCSymbol *getSymbol() const;
352f71cb015c1386ff8adc9ef0aa03fc0f0fc4a6e3eChris Lattner
3538e7ae9860bd1f29c95e4e10fe151a22aaafafef9Chris Lattnerprivate:   // Methods used to maintain doubly linked list of blocks...
354fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  friend struct ilist_traits<MachineBasicBlock>;
3558560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke
3568560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  // Machine-CFG mutators
3578560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke
3588560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  /// addPredecessor - Remove pred as a predecessor of this MachineBasicBlock.
3598560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  /// Don't do this unless you know what you're doing, because it doesn't
3608560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  /// update pred's successors list. Use pred->addSuccessor instead.
3618560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  ///
3623dfbb558b5e74554104710ed16807fe74ec220a3Chris Lattner  void addPredecessor(MachineBasicBlock *pred);
3638560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke
3648560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  /// removePredecessor - Remove pred as a predecessor of this
3658560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  /// MachineBasicBlock. Don't do this unless you know what you're
3668560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  /// doing, because it doesn't update pred's successors list. Use
3678560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  /// pred->removeSuccessor instead.
3688560af4f5fe589cf792bd44617c2308c4f087ba8Brian Gaeke  ///
3693dfbb558b5e74554104710ed16807fe74ec220a3Chris Lattner  void removePredecessor(MachineBasicBlock *pred);
370deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve};
371deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve
3721cd1d98232c3c3a0bd3810c3bf6c2572ea02f208Daniel Dunbarraw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB);
3730aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner
3742a085c34933a6c76e5a86f2680d93c16b0438801Evan Chengvoid WriteAsOperand(raw_ostream &, const MachineBasicBlock*, bool t);
3752a085c34933a6c76e5a86f2680d93c16b0438801Evan Cheng
3760aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner//===--------------------------------------------------------------------===//
3770aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner// GraphTraits specializations for machine basic block graphs (machine-CFGs)
3780aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner//===--------------------------------------------------------------------===//
3790aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner
3800aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner// Provide specializations of GraphTraits to be able to treat a
3810aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner// MachineFunction as a graph of MachineBasicBlocks...
3820aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner//
3830aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner
3840aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattnertemplate <> struct GraphTraits<MachineBasicBlock *> {
3850aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  typedef MachineBasicBlock NodeType;
3860aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  typedef MachineBasicBlock::succ_iterator ChildIteratorType;
3870aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner
3880aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  static NodeType *getEntryNode(MachineBasicBlock *BB) { return BB; }
389ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_begin(NodeType *N) {
3900aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner    return N->succ_begin();
3910aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
392ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_end(NodeType *N) {
3930aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner    return N->succ_end();
3940aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
3950aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner};
3960aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner
3970aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattnertemplate <> struct GraphTraits<const MachineBasicBlock *> {
3980aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  typedef const MachineBasicBlock NodeType;
3990aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
4000aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner
4010aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  static NodeType *getEntryNode(const MachineBasicBlock *BB) { return BB; }
402ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_begin(NodeType *N) {
4030aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner    return N->succ_begin();
4040aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
405ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_end(NodeType *N) {
4060aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner    return N->succ_end();
4070aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
4080aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner};
4090aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner
4100aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner// Provide specializations of GraphTraits to be able to treat a
4110aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner// MachineFunction as a graph of MachineBasicBlocks... and to walk it
4120aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner// in inverse order.  Inverse order for a function is considered
4130aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner// to be when traversing the predecessor edges of a MBB
4140aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner// instead of the successor edges.
4150aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner//
4160aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattnertemplate <> struct GraphTraits<Inverse<MachineBasicBlock*> > {
4170aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  typedef MachineBasicBlock NodeType;
4180aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  typedef MachineBasicBlock::pred_iterator ChildIteratorType;
4190aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  static NodeType *getEntryNode(Inverse<MachineBasicBlock *> G) {
4200aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner    return G.Graph;
4210aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
422ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_begin(NodeType *N) {
4230aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner    return N->pred_begin();
4240aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
425ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_end(NodeType *N) {
4260aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner    return N->pred_end();
4270aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
4280aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner};
4290aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner
4300aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattnertemplate <> struct GraphTraits<Inverse<const MachineBasicBlock*> > {
4310aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  typedef const MachineBasicBlock NodeType;
4320aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  typedef MachineBasicBlock::const_pred_iterator ChildIteratorType;
4330aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  static NodeType *getEntryNode(Inverse<const MachineBasicBlock*> G) {
434ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman    return G.Graph;
4350aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
436ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_begin(NodeType *N) {
4370aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner    return N->pred_begin();
4380aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
439ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_end(NodeType *N) {
4400aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner    return N->pred_end();
4410aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner  }
4420aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner};
4430aef12a7a96968a80c38144dfc0a7ae6a9152db9Chris Lattner
444d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
445deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve
446deb9654056939a12981446f6ed1139dca3412746Vikram S. Adve#endif
447