[llvm-commits] CVS: llvm/lib/CodeGen/MachineFunction.cpp MachineBasicBlock.cpp

Tanya Brethour tbrethou at cs.uiuc.edu
Mon May 24 01:13:02 PDT 2004


Changes in directory llvm/lib/CodeGen:

MachineFunction.cpp updated: 1.56 -> 1.57
MachineBasicBlock.cpp updated: 1.11 -> 1.12

---
Log message:

Added MachineFunction parent* to MachineBasicBlock. Customized ilist template
to set the parent when a MachineBasicBlock is added to a MachineFunction.


---
Diffs of the changes:  (+34 -14)

Index: llvm/lib/CodeGen/MachineFunction.cpp
diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.56 llvm/lib/CodeGen/MachineFunction.cpp:1.57
--- llvm/lib/CodeGen/MachineFunction.cpp:1.56	Wed May 12 16:35:23 2004
+++ llvm/lib/CodeGen/MachineFunction.cpp	Mon May 24 01:11:46 2004
@@ -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 @@
 //===---------------------------------------------------------------------===//
 // 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 @@
   MFInfo = new MachineFunctionInfo(*this);
   FrameInfo = new MachineFrameInfo();
   ConstantPool = new MachineConstantPool();
+  BasicBlocks.parent = this;
 }
 
 MachineFunction::~MachineFunction() { 


Index: llvm/lib/CodeGen/MachineBasicBlock.cpp
diff -u llvm/lib/CodeGen/MachineBasicBlock.cpp:1.11 llvm/lib/CodeGen/MachineBasicBlock.cpp:1.12
--- llvm/lib/CodeGen/MachineBasicBlock.cpp:1.11	Sun May 23 22:44:52 2004
+++ llvm/lib/CodeGen/MachineBasicBlock.cpp	Mon May 24 01:11:47 2004
@@ -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::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());





More information about the llvm-commits mailing list