eliminate a pair of really inefficient methods now that noone uses them
[oota-llvm.git] / include / llvm / CodeGen / MachineBasicBlock.h
1 //===-- llvm/CodeGen/MachineBasicBlock.h ------------------------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/CodeGen/MachineInstr.h"
18 #include "Support/ilist"
19 #include <iosfwd>
20
21 namespace llvm {
22
23 // ilist_traits
24 template <>
25 class ilist_traits<MachineInstr>
26 {
27   // this is only set by the MachineBasicBlock owning the ilist
28   friend class MachineBasicBlock;
29   MachineBasicBlock* parent;
30
31 public:
32   ilist_traits<MachineInstr>() : parent(0) { }
33
34   static MachineInstr* getPrev(MachineInstr* N) { return N->prev; }
35   static MachineInstr* getNext(MachineInstr* N) { return N->next; }
36
37   static const MachineInstr*
38   getPrev(const MachineInstr* N) { return N->prev; }
39
40   static const MachineInstr*
41   getNext(const MachineInstr* N) { return N->next; }
42
43   static void setPrev(MachineInstr* N, MachineInstr* prev) { N->prev = prev; }
44   static void setNext(MachineInstr* N, MachineInstr* next) { N->next = next; }
45
46   static MachineInstr* createNode();
47   void addNodeToList(MachineInstr* N);
48   void removeNodeFromList(MachineInstr* N);
49   void transferNodesFromList(
50       iplist<MachineInstr, ilist_traits<MachineInstr> >& toList,
51       ilist_iterator<MachineInstr> first,
52       ilist_iterator<MachineInstr> last);
53 };
54
55 class BasicBlock;
56
57 class MachineBasicBlock {
58 public:
59   typedef ilist<MachineInstr> Instructions;
60   Instructions Insts;
61   MachineBasicBlock *Prev, *Next;
62   const BasicBlock *BB;
63 public:
64   MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb) {
65     Insts.parent = this;
66   }
67   ~MachineBasicBlock() {}
68   
69   /// getBasicBlock - Return the LLVM basic block that this instance
70   /// corresponded to originally.
71   ///
72   const BasicBlock *getBasicBlock() const { return BB; }
73   
74   typedef ilist<MachineInstr>::iterator                       iterator;
75   typedef ilist<MachineInstr>::const_iterator           const_iterator;
76   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
77   typedef std::reverse_iterator<iterator>             reverse_iterator;
78
79   unsigned size() const { return Insts.size(); }
80   bool empty() const { return Insts.empty(); }
81
82   MachineInstr& front() { return Insts.front(); }
83   MachineInstr& back()  { return Insts.back(); }
84
85   iterator                begin()       { return Insts.begin();  }
86   const_iterator          begin() const { return Insts.begin();  }
87   iterator                  end()       { return Insts.end();    }
88   const_iterator            end() const { return Insts.end();    }
89   reverse_iterator       rbegin()       { return Insts.rbegin(); }
90   const_reverse_iterator rbegin() const { return Insts.rbegin(); }
91   reverse_iterator       rend  ()       { return Insts.rend();   }
92   const_reverse_iterator rend  () const { return Insts.rend();   }
93
94   void push_back(MachineInstr *MI) { Insts.push_back(MI); }
95   template<typename IT>
96   void insert(iterator I, IT S, IT E) { Insts.insert(I, S, E); }
97   iterator insert(iterator I, MachineInstr *M) { return Insts.insert(I, M); }
98
99   // erase - Remove the specified element or range from the instruction list.
100   // These functions delete any instructions removed.
101   //
102   iterator erase(iterator I)             { return Insts.erase(I); }
103   iterator erase(iterator I, iterator E) { return Insts.erase(I, E); }
104   MachineInstr* remove(iterator &I)      { return Insts.remove(I); }
105
106   // Debugging methods.
107   void dump() const;
108   void print(std::ostream &OS) const;
109
110 private:   // Methods used to maintain doubly linked list of blocks...
111   friend class ilist_traits<MachineBasicBlock>;
112
113   MachineBasicBlock *getPrev() const { return Prev; }
114   MachineBasicBlock *getNext() const { return Next; }
115   void setPrev(MachineBasicBlock *P) { Prev = P; }
116   void setNext(MachineBasicBlock *N) { Next = N; }
117 };
118
119 } // End llvm namespace
120
121 #endif