MachineBasicBlock.h revision 6fbcc26f1460eaee4e0eb8b426fc1ff0c7af11be
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 <vector> 18class BasicBlock; 19class MachineInstr; 20template <typename T> struct ilist_traits; 21 22class MachineBasicBlock { 23 std::vector<MachineInstr*> Insts; 24 MachineBasicBlock *Prev, *Next; 25 const BasicBlock *BB; 26public: 27 MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb) {} 28 ~MachineBasicBlock() {} 29 30 /// getBasicBlock - Return the LLVM basic block that this instance 31 /// corresponded to originally. 32 /// 33 const BasicBlock *getBasicBlock() const { return BB; } 34 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; 39 40 unsigned size() const { return Insts.size(); } 41 bool empty() const { return Insts.empty(); } 42 43 MachineInstr * operator[](unsigned i) const { return Insts[i]; } 44 MachineInstr *&operator[](unsigned i) { return Insts[i]; } 45 46 MachineInstr *front() const { return Insts.front(); } 47 MachineInstr *back() const { return Insts.back(); } 48 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(); } 57 58 void push_back(MachineInstr *MI) { Insts.push_back(MI); } 59 template<typename IT> 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); } 62 63 // erase - Remove the specified element or range from the instruction list. 64 // These functions do not delete any instructions removed. 65 // 66 iterator erase(iterator I) { return Insts.erase(I); } 67 iterator erase(iterator I, iterator E) { return Insts.erase(I, E); } 68 69 MachineInstr *pop_back() { 70 MachineInstr *R = back(); 71 Insts.pop_back(); 72 return R; 73 } 74 75private: // Methods used to maintain doubly linked list of blocks... 76 friend class ilist_traits<MachineBasicBlock>; 77 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; } 82}; 83 84 85#endif 86