diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h index eacf067feb3..d2b1d5fc2d9 100644 --- a/include/llvm/CodeGen/MachineBasicBlock.h +++ b/include/llvm/CodeGen/MachineBasicBlock.h @@ -33,17 +33,17 @@ protected: public: ilist_traits() : parent(0) { } - static MachineInstr* getPrev(MachineInstr* N) { return N->prev; } - static MachineInstr* getNext(MachineInstr* N) { return N->next; } + static MachineInstr* getPrev(MachineInstr* N) { return N->Prev; } + static MachineInstr* getNext(MachineInstr* N) { return N->Next; } static const MachineInstr* - getPrev(const MachineInstr* N) { return N->prev; } + getPrev(const MachineInstr* N) { return N->Prev; } static const MachineInstr* - getNext(const MachineInstr* N) { return N->next; } + getNext(const MachineInstr* N) { return N->Next; } - static void setPrev(MachineInstr* N, MachineInstr* prev) { N->prev = prev; } - static void setNext(MachineInstr* N, MachineInstr* next) { N->next = next; } + static void setPrev(MachineInstr* N, MachineInstr* prev) { N->Prev = prev; } + static void setNext(MachineInstr* N, MachineInstr* next) { N->Next = next; } static MachineInstr* createSentinel(); static void destroySentinel(MachineInstr *MI) { delete MI; } @@ -63,7 +63,9 @@ class MachineBasicBlock { MachineBasicBlock *Prev, *Next; const BasicBlock *BB; int Number; - MachineFunction *Parent; + MachineFunction *xParent; + + void setParent(MachineFunction *P) { xParent = P; } /// Predecessors/Successors - Keep track of the predecessor / successor /// basicblocks. @@ -79,10 +81,8 @@ class MachineBasicBlock { bool IsLandingPad; public: - explicit MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), - BB(bb), Number(-1), - Parent(0), - IsLandingPad(false) { + explicit MachineBasicBlock(const BasicBlock *bb = 0) + : Prev(0), Next(0), BB(bb), Number(-1), xParent(0), IsLandingPad(false) { Insts.parent = this; } @@ -95,8 +95,8 @@ public: /// getParent - Return the MachineFunction containing this basic block. /// - const MachineFunction *getParent() const { return Parent; } - MachineFunction *getParent() { return Parent; } + const MachineFunction *getParent() const { return xParent; } + MachineFunction *getParent() { return xParent; } typedef ilist::iterator iterator; typedef ilist::const_iterator const_iterator; diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index d74440f474c..fa372f6e167 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -34,8 +34,8 @@ class MachineInstr { // are determined at construction time). std::vector Operands; // the operands - MachineInstr* prev, *next; // links for our intrusive list - MachineBasicBlock* parent; // pointer to the owning basic block + MachineInstr *Prev, *Next; // Links for MBB's intrusive list. + MachineBasicBlock *Parent; // Pointer to the owning basic block. // OperandComplete - Return true if it's illegal to add a new operand bool OperandsComplete() const; @@ -45,7 +45,7 @@ class MachineInstr { // Intrusive list support friend struct ilist_traits; - + void setParent(MachineBasicBlock *P) { Parent = P; } public: /// MachineInstr ctor - This constructor creates a dummy MachineInstr with /// TID NULL and no operands. @@ -64,8 +64,8 @@ public: ~MachineInstr(); - const MachineBasicBlock* getParent() const { return parent; } - MachineBasicBlock* getParent() { return parent; } + const MachineBasicBlock* getParent() const { return Parent; } + MachineBasicBlock* getParent() { return Parent; } /// getInstrDescriptor - Returns the target instruction descriptor of this /// MachineInstr. diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp index f5395967bee..3b84d688b87 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 @@ std::ostream& llvm::operator<<(std::ostream &OS, const MachineBasicBlock &MBB) { // gets the next available unique MBB number. If it is removed from a // MachineFunction, it goes back to being #-1. void ilist_traits::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::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 @@ MachineInstr* ilist_traits::createSentinel() { } void ilist_traits::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::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::transferNodesFromList( - iplist >& fromList, - ilist_iterator first, - ilist_iterator last) { - if (parent != fromList.parent) - for (; first != last; ++first) - first->parent = parent; + iplist >& fromList, + ilist_iterator first, + ilist_iterator 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 @@ void MachineBasicBlock::removeSuccessor(MachineBasicBlock *succ) { 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 @@ void MachineBasicBlock::ReplaceUsesOfBlockWith(MachineBasicBlock *Old, /// 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 595159b15f2..3f2c1194863 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -111,12 +111,14 @@ MachineBasicBlock* ilist_traits::createSentinel() { } void ilist_traits::transferNodesFromList( - iplist >& toList, - ilist_iterator first, - ilist_iterator last) { - if (Parent != toList.Parent) - for (; first != last; ++first) - first->Parent = toList.Parent; + iplist >& toList, + ilist_iterator first, + ilist_iterator 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 95c768d72c7..4d0a98a114c 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -136,7 +136,7 @@ void MachineOperand::print(std::ostream &OS, const TargetMachine *TM) const { /// 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 @@ void MachineInstr::addImplicitDefUseOperands() { /// 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(const TargetInstrDescriptor &tid, bool NoImp) /// 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 @@ MachineInstr::MachineInstr(const MachineInstr &MI) { } // Set parent, next, and prev to null - parent = 0; - prev = 0; - next = 0; + Parent = 0; + Prev = 0; + Next = 0; }