X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FMachineBasicBlock.cpp;h=db55a88eddc28722494abb2cb4ad470ebbd54d3b;hb=a29c13086a3add78a3a79f744573fe09eaa9dc88;hp=31e6ea87851e0598f7685f6b6377a303a66122a7;hpb=8e5f2c6f65841542e2a7092553fe42a00048e4c7;p=oota-llvm.git diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp index 31e6ea87851..db55a88eddc 100644 --- a/lib/CodeGen/MachineBasicBlock.cpp +++ b/lib/CodeGen/MachineBasicBlock.cpp @@ -18,12 +18,17 @@ #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetInstrDesc.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Support/LeakDetector.h" #include using namespace llvm; MachineBasicBlock::MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb) : BB(bb), Number(-1), xParent(&mf), Alignment(0), IsLandingPad(false) { - Insts.getTraits().Parent = this; + Insts.Parent = this; +} + +MachineBasicBlock::~MachineBasicBlock() { + LeakDetector::removeGarbageObject(this); } std::ostream& llvm::operator<<(std::ostream &OS, const MachineBasicBlock &MBB) { @@ -38,7 +43,7 @@ std::ostream& llvm::operator<<(std::ostream &OS, const MachineBasicBlock &MBB) { /// 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 alist_traits::addNodeToList(MachineBasicBlock* N) { +void ilist_traits::addNodeToList(MachineBasicBlock* N) { MachineFunction &MF = *N->getParent(); N->Number = MF.addToMBBNumbering(N); @@ -46,18 +51,21 @@ void alist_traits::addNodeToList(MachineBasicBlock* N) { MachineRegisterInfo &RegInfo = MF.getRegInfo(); for (MachineBasicBlock::iterator I = N->begin(), E = N->end(); I != E; ++I) I->AddRegOperandsToUseLists(RegInfo); + + LeakDetector::removeGarbageObject(N); } -void alist_traits::removeNodeFromList(MachineBasicBlock* N) { +void ilist_traits::removeNodeFromList(MachineBasicBlock* N) { N->getParent()->removeFromMBBNumbering(N->Number); N->Number = -1; + LeakDetector::addGarbageObject(N); } /// addNodeToList (MI) - When we add an instruction to a basic block /// list, we update its parent pointer and add its operands from reg use/def /// lists if appropriate. -void alist_traits::addNodeToList(MachineInstr* N) { +void ilist_traits::addNodeToList(MachineInstr* N) { assert(N->getParent() == 0 && "machine instruction already in a basic block"); N->setParent(Parent); @@ -65,52 +73,44 @@ void alist_traits::addNodeToList(MachineInstr* N) { // use/def lists. MachineFunction *MF = Parent->getParent(); N->AddRegOperandsToUseLists(MF->getRegInfo()); + + LeakDetector::removeGarbageObject(N); } /// removeNodeFromList (MI) - When we remove an instruction from a basic block /// list, we update its parent pointer and remove its operands from reg use/def /// lists if appropriate. -void alist_traits::removeNodeFromList(MachineInstr* N) { +void ilist_traits::removeNodeFromList(MachineInstr* N) { assert(N->getParent() != 0 && "machine instruction not in a basic block"); // Remove from the use/def lists. N->RemoveRegOperandsFromUseLists(); N->setParent(0); + + LeakDetector::addGarbageObject(N); } /// transferNodesFromList (MI) - When moving a range of instructions from one /// MBB list to another, we need to update the parent pointers and the use/def /// lists. -void alist_traits::transferNodesFromList( - alist_traits& fromList, +void ilist_traits::transferNodesFromList( + ilist_traits& fromList, MachineBasicBlock::iterator first, MachineBasicBlock::iterator last) { + assert(Parent->getParent() == fromList.Parent->getParent() && + "MachineInstr parent mismatch!"); + // Splice within the same MBB -> no change. if (Parent == fromList.Parent) return; // If splicing between two blocks within the same function, just update the // parent pointers. - if (Parent->getParent() == fromList.Parent->getParent()) { - for (; first != last; ++first) - first->setParent(Parent); - return; - } - - // Otherwise, we have to update the parent and the use/def lists. The common - // case when this occurs is if we're splicing from a block in a MF to a block - // that is not in an MF. - bool HasOldMF = fromList.Parent->getParent() != 0; - MachineFunction *NewMF = Parent->getParent(); - - for (; first != last; ++first) { - if (HasOldMF) first->RemoveRegOperandsFromUseLists(); + for (; first != last; ++first) first->setParent(Parent); - if (NewMF) first->AddRegOperandsToUseLists(NewMF->getRegInfo()); - } } -void alist_traits::deleteNode(MachineInstr* MI) { +void ilist_traits::deleteNode(MachineInstr* MI) { assert(!MI->getParent() && "MI is still in a block!"); Parent->getParent()->DeleteMachineInstr(MI); } @@ -254,6 +254,11 @@ bool MachineBasicBlock::isSuccessor(MachineBasicBlock *MBB) const { return I != Successors.end(); } +bool MachineBasicBlock::isLayoutSuccessor(MachineBasicBlock *MBB) const { + MachineFunction::const_iterator I(this); + return next(I) == MachineFunction::const_iterator(MBB); +} + /// removeFromParent - This method unlinks 'this' from the containing function, /// and returns it, but does not delete it. MachineBasicBlock *MachineBasicBlock::removeFromParent() { @@ -285,7 +290,8 @@ void MachineBasicBlock::ReplaceUsesOfBlockWith(MachineBasicBlock *Old, // Scan the operands of this machine instruction, replacing any uses of Old // with New. for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) - if (I->getOperand(i).isMBB() && I->getOperand(i).getMBB() == Old) + if (I->getOperand(i).isMBB() && + I->getOperand(i).getMBB() == Old) I->getOperand(i).setMBB(New); }