blob: 9d65453edff2ef877d83aacfca51c4b8eeb83e84 [file] [log] [blame]
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +00001//===-- 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"
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000015#include "llvm/BasicBlock.h"
16#include "llvm/CodeGen/MachineFunction.h"
17#include "llvm/CodeGen/MachineInstr.h"
18#include "Support/LeakDetector.h"
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000019using namespace llvm;
20
Chris Lattner5e61fa92004-02-19 16:13:54 +000021const 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
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000028MachineInstr* ilist_traits<MachineInstr>::createNode()
29{
30 MachineInstr* dummy = new MachineInstr(0, 0);
31 LeakDetector::removeGarbageObject(dummy);
32 return dummy;
33}
34
35void 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
42void 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
49void 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
59void MachineBasicBlock::dump() const
60{
61 print(std::cerr);
62}
63
64void 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}