aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorTanya Lattner <tonic@nondot.org>2004-05-24 06:11:51 +0000
committerTanya Lattner <tonic@nondot.org>2004-05-24 06:11:51 +0000
commit792699c46ef9bfc47dd459bbfa7e71bcb2cee29a (patch)
tree09579fa1fb5054e308cfb202d2c63d643d9b9120 /lib/CodeGen
parent2b90565e3df82377eaadff30ac0bc5fbb54e91e7 (diff)
Added MachineFunction parent* to MachineBasicBlock. Customized ilist template
to set the parent when a MachineBasicBlock is added to a MachineFunction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13716 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/MachineBasicBlock.cpp29
-rw-r--r--lib/CodeGen/MachineFunction.cpp19
2 files changed, 34 insertions, 14 deletions
diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp
index 64f735c48e..c0b144d26c 100644
--- a/lib/CodeGen/MachineBasicBlock.cpp
+++ b/lib/CodeGen/MachineBasicBlock.cpp
@@ -20,29 +20,25 @@
#include "Support/LeakDetector.h"
using namespace llvm;
-const MachineFunction *MachineBasicBlock::getParent() const {
- // Get the parent by getting the Function parent of the basic block, and
- // getting the MachineFunction from it.
- return &MachineFunction::get(getBasicBlock()->getParent());
-}
-
-MachineFunction *MachineBasicBlock::getParent() {
- // Get the parent by getting the Function parent of the basic block, and
- // getting the MachineFunction from it.
- return &MachineFunction::get(getBasicBlock()->getParent());
-}
-
// MBBs start out as #-1. When a MBB is added to a MachineFunction, it
// gets the next available unique MBB number. If it is removed from a
// MachineFunction, it goes back to being #-1.
void ilist_traits<MachineBasicBlock>::addNodeToList (MachineBasicBlock* N)
{
- N->Number = N->getParent ()->getNextMBBNumber ();
+ assert(N->Parent == 0 && "machine instruction already in a basic block");
+ N->Parent = parent;
+ N->Number = parent->getNextMBBNumber();
+ LeakDetector::removeGarbageObject(N);
+
+
}
void ilist_traits<MachineBasicBlock>::removeNodeFromList (MachineBasicBlock* N)
{
+ assert(N->Parent != 0 && "machine instruction not in a basic block");
+ N->Parent = 0;
N->Number = -1;
+ LeakDetector::addGarbageObject(N);
}
@@ -93,8 +89,13 @@ void MachineBasicBlock::dump() const
void MachineBasicBlock::print(std::ostream &OS) const
{
+ if(!getParent()) {
+ OS << "Can't print out MachineBasicBlock because parent MachineFunction is null\n";
+ return;
+ }
const BasicBlock *LBB = getBasicBlock();
- OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n";
+ if(LBB)
+ OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n";
for (const_iterator I = begin(); I != end(); ++I) {
OS << "\t";
I->print(OS, getParent()->getTarget());
diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp
index f0b06378ca..a3e9211f5c 100644
--- a/lib/CodeGen/MachineFunction.cpp
+++ b/lib/CodeGen/MachineFunction.cpp
@@ -24,6 +24,8 @@
#include "llvm/Target/TargetFrameInfo.h"
#include "llvm/Function.h"
#include "llvm/iOther.h"
+#include "Support/LeakDetector.h"
+
using namespace llvm;
static AnnotationID MF_AID(
@@ -84,6 +86,22 @@ FunctionPass *llvm::createMachineCodeDeleter() {
//===---------------------------------------------------------------------===//
// MachineFunction implementation
//===---------------------------------------------------------------------===//
+MachineBasicBlock* ilist_traits<MachineBasicBlock>::createNode()
+{
+ MachineBasicBlock* dummy = new MachineBasicBlock();
+ LeakDetector::removeGarbageObject(dummy);
+ return dummy;
+}
+
+void ilist_traits<MachineBasicBlock>::transferNodesFromList(
+ iplist<MachineBasicBlock, ilist_traits<MachineBasicBlock> >& toList,
+ ilist_iterator<MachineBasicBlock> first,
+ ilist_iterator<MachineBasicBlock> last)
+{
+ if (parent != toList.parent)
+ for (; first != last; ++first)
+ first->Parent = toList.parent;
+}
MachineFunction::MachineFunction(const Function *F,
const TargetMachine &TM)
@@ -92,6 +110,7 @@ MachineFunction::MachineFunction(const Function *F,
MFInfo = new MachineFunctionInfo(*this);
FrameInfo = new MachineFrameInfo();
ConstantPool = new MachineConstantPool();
+ BasicBlocks.parent = this;
}
MachineFunction::~MachineFunction() {