MachineBasicBlock.h revision ab8672c8bb83e722b856eac67863542ea7e0cbb2
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
19namespace llvm {
20
21class BasicBlock;
22
23class MachineBasicBlock {
24public:
25  typedef ilist<MachineInstr> Instructions;
26  Instructions Insts;
27  MachineBasicBlock *Prev, *Next;
28  const BasicBlock *BB;
29public:
30  MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb) {
31    Insts.parent = this;
32  }
33  ~MachineBasicBlock() {}
34
35  /// getBasicBlock - Return the LLVM basic block that this instance
36  /// corresponded to originally.
37  ///
38  const BasicBlock *getBasicBlock() const { return BB; }
39
40  typedef ilist<MachineInstr>::iterator                       iterator;
41  typedef ilist<MachineInstr>::const_iterator           const_iterator;
42  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
43  typedef std::reverse_iterator<iterator>             reverse_iterator;
44
45  unsigned size() const { return Insts.size(); }
46  bool empty() const { return Insts.empty(); }
47
48  const MachineInstr& operator[](unsigned i) const {
49      const_iterator it = Insts.begin();
50      std::advance(it, i);
51      return *it;
52  }
53  MachineInstr& operator[](unsigned i) {
54      iterator it = Insts.begin();
55      std::advance(it, i);
56      return *it;
57  }
58
59  MachineInstr& front() { return Insts.front(); }
60  MachineInstr& back()  { return Insts.back(); }
61
62  iterator                begin()       { return Insts.begin();  }
63  const_iterator          begin() const { return Insts.begin();  }
64  iterator                  end()       { return Insts.end();    }
65  const_iterator            end() const { return Insts.end();    }
66  reverse_iterator       rbegin()       { return Insts.rbegin(); }
67  const_reverse_iterator rbegin() const { return Insts.rbegin(); }
68  reverse_iterator       rend  ()       { return Insts.rend();   }
69  const_reverse_iterator rend  () const { return Insts.rend();   }
70
71  void push_back(MachineInstr *MI) { Insts.push_back(MI); }
72  template<typename IT>
73  void insert(iterator I, IT S, IT E) { Insts.insert(I, S, E); }
74  iterator insert(iterator I, MachineInstr *M) { return Insts.insert(I, M); }
75
76  // erase - Remove the specified element or range from the instruction list.
77  // These functions delete any instructions removed.
78  //
79  iterator erase(iterator I)             { return Insts.erase(I); }
80  iterator erase(iterator I, iterator E) { return Insts.erase(I, E); }
81  MachineInstr* remove(iterator &I)      { return Insts.remove(I); }
82
83private:   // Methods used to maintain doubly linked list of blocks...
84  friend class ilist_traits<MachineBasicBlock>;
85
86  MachineBasicBlock *getPrev() const { return Prev; }
87  MachineBasicBlock *getNext() const { return Next; }
88  void setPrev(MachineBasicBlock *P) { Prev = P; }
89  void setNext(MachineBasicBlock *N) { Next = N; }
90};
91
92} // End llvm namespace
93
94#endif
95