1 //===-- llvm/CodeGen/MachineBasicBlock.cpp ----------------------*- 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 #include "llvm/CodeGen/MachineBasicBlock.h" 15 #include "llvm/BasicBlock.h" 16 #include "llvm/CodeGen/MachineFunction.h" 17 #include "llvm/CodeGen/MachineInstr.h" 18 #include "Support/LeakDetector.h" 19 using namespace llvm; 20 21 const MachineFunction *MachineBasicBlock::getParent() const { 22 // Get the parent by getting the Function parent of the basic block, and 23 // getting the MachineFunction from it. 24 return &MachineFunction::get(getBasicBlock()->getParent()); 25 } 26 27 28 MachineInstr* ilist_traits<MachineInstr>::createNode() 29 { 30 MachineInstr* dummy = new MachineInstr(0, 0); 31 LeakDetector::removeGarbageObject(dummy); 32 return dummy; 33 } 34 35 void ilist_traits<MachineInstr>::addNodeToList(MachineInstr* N) 36 { 37 assert(N->parent == 0 && "machine instruction already in a basic block"); 38 N->parent = parent; 39 LeakDetector::removeGarbageObject(N); 40 } 41 42 void ilist_traits<MachineInstr>::removeNodeFromList(MachineInstr* N) 43 { 44 assert(N->parent != 0 && "machine instruction not in a basic block"); 45 N->parent = 0; 46 LeakDetector::addGarbageObject(N); 47 } 48 49 void ilist_traits<MachineInstr>::transferNodesFromList( 50 iplist<MachineInstr, ilist_traits<MachineInstr> >& toList, 51 ilist_iterator<MachineInstr> first, 52 ilist_iterator<MachineInstr> last) 53 { 54 if (parent != toList.parent) 55 for (; first != last; ++first) 56 first->parent = toList.parent; 57 } 58 59 void MachineBasicBlock::dump() const 60 { 61 print(std::cerr); 62 } 63 64 void MachineBasicBlock::print(std::ostream &OS) const 65 { 66 const BasicBlock *LBB = getBasicBlock(); 67 OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n"; 68 for (const_iterator I = begin(); I != end(); ++I) { 69 OS << "\t"; 70 I->print(OS, MachineFunction::get(LBB->getParent()).getTarget()); 71 } 72 } 73