[llvm-commits] [llvm] r45469 - in /llvm/trunk: include/llvm/CodeGen/MachineBasicBlock.h include/llvm/CodeGen/MachineInstr.h lib/CodeGen/MachineBasicBlock.cpp lib/CodeGen/MachineFunction.cpp lib/CodeGen/MachineInstr.cpp
Chris Lattner
sabre at nondot.org
Sun Dec 30 20:56:34 PST 2007
Author: lattner
Date: Sun Dec 30 22:56:33 2007
New Revision: 45469
URL: http://llvm.org/viewvc/llvm-project?rev=45469&view=rev
Log:
properly encapsulate the parent field of MBB and MI with get/set accessors.
Modified:
llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
llvm/trunk/include/llvm/CodeGen/MachineInstr.h
llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
llvm/trunk/lib/CodeGen/MachineFunction.cpp
llvm/trunk/lib/CodeGen/MachineInstr.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=45469&r1=45468&r2=45469&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Sun Dec 30 22:56:33 2007
@@ -33,17 +33,17 @@
public:
ilist_traits<MachineInstr>() : 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 @@
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 @@
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 @@
/// 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<MachineInstr>::iterator iterator;
typedef ilist<MachineInstr>::const_iterator const_iterator;
Modified: llvm/trunk/include/llvm/CodeGen/MachineInstr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstr.h?rev=45469&r1=45468&r2=45469&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineInstr.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineInstr.h Sun Dec 30 22:56:33 2007
@@ -34,8 +34,8 @@
// are determined at construction time).
std::vector<MachineOperand> 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 @@
// Intrusive list support
friend struct ilist_traits<MachineInstr>;
-
+ 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 @@
~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.
Modified: llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp?rev=45469&r1=45468&r2=45469&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp Sun Dec 30 22:56:33 2007
@@ -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,
Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=45469&r1=45468&r2=45469&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Sun Dec 30 22:56:33 2007
@@ -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,
Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=45469&r1=45468&r2=45469&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Sun Dec 30 22:56:33 2007
@@ -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;
}
More information about the llvm-commits
mailing list