1 //===-- llvm/CodeGen/MachineBasicBlock.h ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // Collect the sequence of machine instructions for a basic block.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
15 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H
20 template <typename T> struct ilist_traits;
22 class MachineBasicBlock {
23 std::vector<MachineInstr*> Insts;
24 MachineBasicBlock *Prev, *Next;
27 MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb) {}
28 ~MachineBasicBlock() {}
30 /// getBasicBlock - Return the LLVM basic block that this instance
31 /// corresponded to originally.
33 const BasicBlock *getBasicBlock() const { return BB; }
35 typedef std::vector<MachineInstr*>::iterator iterator;
36 typedef std::vector<MachineInstr*>::const_iterator const_iterator;
37 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
38 typedef std::reverse_iterator<iterator> reverse_iterator;
40 unsigned size() const { return Insts.size(); }
41 bool empty() const { return Insts.empty(); }
43 MachineInstr * operator[](unsigned i) const { return Insts[i]; }
44 MachineInstr *&operator[](unsigned i) { return Insts[i]; }
46 MachineInstr *front() const { return Insts.front(); }
47 MachineInstr *back() const { return Insts.back(); }
49 iterator begin() { return Insts.begin(); }
50 const_iterator begin() const { return Insts.begin(); }
51 iterator end() { return Insts.end(); }
52 const_iterator end() const { return Insts.end(); }
53 reverse_iterator rbegin() { return Insts.rbegin(); }
54 const_reverse_iterator rbegin() const { return Insts.rbegin(); }
55 reverse_iterator rend () { return Insts.rend(); }
56 const_reverse_iterator rend () const { return Insts.rend(); }
58 void push_back(MachineInstr *MI) { Insts.push_back(MI); }
60 void insert(iterator I, IT S, IT E) { Insts.insert(I, S, E); }
61 iterator insert(iterator I, MachineInstr *M) { return Insts.insert(I, M); }
63 // erase - Remove the specified element or range from the instruction list.
64 // These functions do not delete any instructions removed.
66 iterator erase(iterator I) { return Insts.erase(I); }
67 iterator erase(iterator I, iterator E) { return Insts.erase(I, E); }
69 MachineInstr *pop_back() {
70 MachineInstr *R = back();
75 private: // Methods used to maintain doubly linked list of blocks...
76 friend class ilist_traits<MachineBasicBlock>;
78 MachineBasicBlock *getPrev() const { return Prev; }
79 MachineBasicBlock *getNext() const { return Next; }
80 void setPrev(MachineBasicBlock *P) { Prev = P; }
81 void setNext(MachineBasicBlock *N) { Next = N; }