1 //===-- llvm/CodeGen/MachineBasicBlock.cpp ----------------------*- 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 #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"
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());
28 MachineInstr* ilist_traits<MachineInstr>::createNode()
30 MachineInstr* dummy = new MachineInstr(0, 0);
31 LeakDetector::removeGarbageObject(dummy);
35 void ilist_traits<MachineInstr>::addNodeToList(MachineInstr* N)
37 assert(N->parent == 0 && "machine instruction already in a basic block");
39 LeakDetector::removeGarbageObject(N);
42 void ilist_traits<MachineInstr>::removeNodeFromList(MachineInstr* N)
44 assert(N->parent != 0 && "machine instruction not in a basic block");
46 LeakDetector::addGarbageObject(N);
49 void ilist_traits<MachineInstr>::transferNodesFromList(
50 iplist<MachineInstr, ilist_traits<MachineInstr> >& toList,
51 ilist_iterator<MachineInstr> first,
52 ilist_iterator<MachineInstr> last)
54 if (parent != toList.parent)
55 for (; first != last; ++first)
56 first->parent = toList.parent;
59 void MachineBasicBlock::dump() const
64 void MachineBasicBlock::print(std::ostream &OS) const
66 const BasicBlock *LBB = getBasicBlock();
67 OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n";
68 for (const_iterator I = begin(); I != end(); ++I) {
70 I->print(OS, MachineFunction::get(LBB->getParent()).getTarget());