properly encapsulate the parent field of MBB and MI with get/set accessors.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45469 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp
index f539596..3b84d68 100644
--- a/lib/CodeGen/MachineBasicBlock.cpp
+++ b/lib/CodeGen/MachineBasicBlock.cpp
@@ -14,7 +14,6 @@
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Target/MRegisterInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetInstrInfo.h"
@@ -36,17 +35,17 @@
 // 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) {
-  assert(N->Parent == 0 && "machine instruction already in a basic block");
-  N->Parent = Parent;
+  assert(N->getParent() == 0 && "machine instruction already in a basic block");
+  N->setParent(Parent);
   N->Number = Parent->addToMBBNumbering(N);
   LeakDetector::removeGarbageObject(N);
 }
 
 void ilist_traits<MachineBasicBlock>::removeNodeFromList(MachineBasicBlock* N) {
-  assert(N->Parent != 0 && "machine instruction not in a basic block");
-  N->Parent->removeFromMBBNumbering(N->Number);
+  assert(N->getParent() != 0 && "machine instruction not in a basic block");
+  N->getParent()->removeFromMBBNumbering(N->Number);
   N->Number = -1;
-  N->Parent = 0;
+  N->setParent(0);
   LeakDetector::addGarbageObject(N);
 }
 
@@ -58,24 +57,26 @@
 }
 
 void ilist_traits<MachineInstr>::addNodeToList(MachineInstr* N) {
-  assert(N->parent == 0 && "machine instruction already in a basic block");
-  N->parent = parent;
+  assert(N->getParent() == 0 && "machine instruction already in a basic block");
+  N->setParent(parent);
   LeakDetector::removeGarbageObject(N);
 }
 
 void ilist_traits<MachineInstr>::removeNodeFromList(MachineInstr* N) {
-  assert(N->parent != 0 && "machine instruction not in a basic block");
-  N->parent = 0;
+  assert(N->getParent() != 0 && "machine instruction not in a basic block");
+  N->setParent(0);
   LeakDetector::addGarbageObject(N);
 }
 
 void ilist_traits<MachineInstr>::transferNodesFromList(
-  iplist<MachineInstr, ilist_traits<MachineInstr> >& fromList,
-  ilist_iterator<MachineInstr> first,
-  ilist_iterator<MachineInstr> last) {
-  if (parent != fromList.parent)
-    for (; first != last; ++first)
-      first->parent = parent;
+      iplist<MachineInstr, ilist_traits<MachineInstr> >& fromList,
+      ilist_iterator<MachineInstr> first,
+      ilist_iterator<MachineInstr> last) {
+  // Splice within the same MBB -> no change.
+  if (parent == fromList.parent) return;
+  
+  for (; first != last; ++first)
+    first->setParent(parent);
 }
 
 MachineBasicBlock::iterator MachineBasicBlock::getFirstTerminator() {
@@ -177,7 +178,8 @@
   Successors.erase(I);
 }
 
-MachineBasicBlock::succ_iterator MachineBasicBlock::removeSuccessor(succ_iterator I) {
+MachineBasicBlock::succ_iterator 
+MachineBasicBlock::removeSuccessor(succ_iterator I) {
   assert(I != Successors.end() && "Not a current successor!");
   (*I)->removePredecessor(this);
   return(Successors.erase(I));
@@ -229,8 +231,8 @@
 /// CFG to be inserted.  If we have proven that MBB can only branch to DestA and
 /// DestB, remove any other MBB successors from the CFG.  DestA and DestB can
 /// be null.
-/// Besides DestA and DestB, retain other edges leading to LandingPads (currently
-/// there can be only one; we don't check or require that here).
+/// Besides DestA and DestB, retain other edges leading to LandingPads
+/// (currently there can be only one; we don't check or require that here).
 /// Note it is possible that DestA and/or DestB are LandingPads.
 bool MachineBasicBlock::CorrectExtraCFGEdges(MachineBasicBlock *DestA,
                                              MachineBasicBlock *DestB,
diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp
index 595159b..3f2c119 100644
--- a/lib/CodeGen/MachineFunction.cpp
+++ b/lib/CodeGen/MachineFunction.cpp
@@ -111,12 +111,14 @@
 }
 
 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;
+            iplist<MachineBasicBlock, ilist_traits<MachineBasicBlock> >& toList,
+            ilist_iterator<MachineBasicBlock> first,
+            ilist_iterator<MachineBasicBlock> last) {
+  // If splicing withing the same function, no change.
+  if (Parent == toList.Parent) return;
+  
+  for (; first != last; ++first)
+    first->setParent(toList.Parent);
 }
 
 MachineFunction::MachineFunction(const Function *F,
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index 95c768d..4d0a98a 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -136,7 +136,7 @@
 /// MachineInstr ctor - This constructor creates a dummy MachineInstr with
 /// TID NULL and no operands.
 MachineInstr::MachineInstr()
-  : TID(0), NumImplicitOps(0), parent(0) {
+  : TID(0), NumImplicitOps(0), Parent(0) {
   // Make sure that we get added to a machine basicblock
   LeakDetector::addGarbageObject(this);
 }
@@ -155,7 +155,7 @@
 /// TargetInstrDescriptor or the numOperands if it is not zero. (for
 /// instructions with variable number of operands).
 MachineInstr::MachineInstr(const TargetInstrDescriptor &tid, bool NoImp)
-  : TID(&tid), NumImplicitOps(0), parent(0) {
+  : TID(&tid), NumImplicitOps(0), Parent(0) {
   if (!NoImp && TID->ImplicitDefs)
     for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
       NumImplicitOps++;
@@ -174,7 +174,7 @@
 ///
 MachineInstr::MachineInstr(MachineBasicBlock *MBB,
                            const TargetInstrDescriptor &tid)
-  : TID(&tid), NumImplicitOps(0), parent(0) {
+  : TID(&tid), NumImplicitOps(0), Parent(0) {
   assert(MBB && "Cannot use inserting ctor with null basic block!");
   if (TID->ImplicitDefs)
     for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
@@ -203,9 +203,9 @@
   }
 
   // Set parent, next, and prev to null
-  parent = 0;
-  prev = 0;
-  next = 0;
+  Parent = 0;
+  Prev = 0;
+  Next = 0;
 }