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