diff options
| author | Dan Gohman <gohman@apple.com> | 2008-07-17 23:49:46 +0000 | 
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2008-07-17 23:49:46 +0000 | 
| commit | 0ece94384582605f64f5b90e79cfd561f9269c5f (patch) | |
| tree | afb5f97e88e5be1262666dce98a5bb52d4c81dec | |
| parent | e330aacbed0eff3704198f7162f5a3a3b8be36fe (diff) | |
| download | bcm5719-llvm-0ece94384582605f64f5b90e79cfd561f9269c5f.tar.gz bcm5719-llvm-0ece94384582605f64f5b90e79cfd561f9269c5f.zip  | |
Re-introduce LeakDetector support for MachineInstrs and MachineBasicBlocks.
Fix a leak that this turned up in LowerSubregs.cpp.
And, comment a leak in LiveIntervalAnalysis.cpp.
llvm-svn: 53746
| -rw-r--r-- | llvm/include/llvm/CodeGen/MachineBasicBlock.h | 2 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/LiveIntervalAnalysis.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/LowerSubregs.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/MachineBasicBlock.cpp | 12 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/MachineInstr.cpp | 8 | 
5 files changed, 27 insertions, 7 deletions
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h index 6958dba271e..f0f9d54af54 100644 --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -67,7 +67,7 @@ class MachineBasicBlock {    explicit MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb); -  ~MachineBasicBlock() {} +  ~MachineBasicBlock();    // MachineBasicBlocks are allocated and owned by MachineFunction.    friend class MachineFunction; diff --git a/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp b/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp index 4f79696d00c..8c99831de18 100644 --- a/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -1585,9 +1585,9 @@ addIntervalsForSpills(const LiveInterval &li,      if (ReMatDefMI && isReMaterializable(li, VNI, ReMatDefMI, dummy)) {        // Remember how to remat the def of this val#.        ReMatOrigDefs[VN] = ReMatDefMI; -      // Original def may be modified so we have to make a copy here. vrm must -      // delete these! -      ReMatDefs[VN] = ReMatDefMI = mf_->CloneMachineInstr(ReMatDefMI); +      // Original def may be modified so we have to make a copy here. +      // FIXME: This is a memory leak. vrm should delete these! +      ReMatDefs[VN] = mf_->CloneMachineInstr(ReMatDefMI);        bool CanDelete = true;        if (VNI->hasPHIKill) { diff --git a/llvm/lib/CodeGen/LowerSubregs.cpp b/llvm/lib/CodeGen/LowerSubregs.cpp index e2e68d86713..1cdd34b77f4 100644 --- a/llvm/lib/CodeGen/LowerSubregs.cpp +++ b/llvm/lib/CodeGen/LowerSubregs.cpp @@ -80,7 +80,7 @@ bool LowerSubregsInstructionPass::LowerExtract(MachineInstr *MI) {     }     DOUT << "\n"; -   MBB->remove(MI); +   MBB->erase(MI);     return true;  } @@ -119,7 +119,7 @@ bool LowerSubregsInstructionPass::LowerSubregToReg(MachineInstr *MI) {  #endif    DOUT << "\n"; -  MBB->remove(MI); +  MBB->erase(MI);    return true;                      } @@ -164,7 +164,7 @@ bool LowerSubregsInstructionPass::LowerInsert(MachineInstr *MI) {    }    DOUT << "\n"; -  MBB->remove(MI); +  MBB->erase(MI);    return true;                      } diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index 31e6ea87851..9a9f5b9271a 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -18,6 +18,7 @@  #include "llvm/Target/TargetData.h"  #include "llvm/Target/TargetInstrDesc.h"  #include "llvm/Target/TargetMachine.h" +#include "llvm/Support/LeakDetector.h"  #include <algorithm>  using namespace llvm; @@ -26,6 +27,10 @@ MachineBasicBlock::MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb)    Insts.getTraits().Parent = this;  } +MachineBasicBlock::~MachineBasicBlock() { +  LeakDetector::removeGarbageObject(this); +} +  std::ostream& llvm::operator<<(std::ostream &OS, const MachineBasicBlock &MBB) {    MBB.print(OS);    return OS; @@ -46,11 +51,14 @@ void alist_traits<MachineBasicBlock>::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<MachineBasicBlock>::removeNodeFromList(MachineBasicBlock* N) {    N->getParent()->removeFromMBBNumbering(N->Number);    N->Number = -1; +  LeakDetector::addGarbageObject(N);  } @@ -65,6 +73,8 @@ void alist_traits<MachineInstr>::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 @@ -77,6 +87,8 @@ void alist_traits<MachineInstr>::removeNodeFromList(MachineInstr* N) {    N->RemoveRegOperandsFromUseLists();    N->setParent(0); + +  LeakDetector::addGarbageObject(N);  }  /// transferNodesFromList (MI) - When moving a range of instructions from one diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index 595a9149b38..b672cd9c12b 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -21,6 +21,7 @@  #include "llvm/Target/TargetInstrInfo.h"  #include "llvm/Target/TargetInstrDesc.h"  #include "llvm/Target/TargetRegisterInfo.h" +#include "llvm/Support/LeakDetector.h"  #include "llvm/Support/MathExtras.h"  #include "llvm/Support/Streams.h"  #include <ostream> @@ -257,6 +258,8 @@ MachineMemOperand::MachineMemOperand(const Value *v, unsigned int f,  /// TID NULL and no operands.  MachineInstr::MachineInstr()    : TID(0), NumImplicitOps(0), Parent(0) { +  // Make sure that we get added to a machine basicblock +  LeakDetector::addGarbageObject(this);  }  void MachineInstr::addImplicitDefUseOperands() { @@ -283,6 +286,8 @@ MachineInstr::MachineInstr(const TargetInstrDesc &tid, bool NoImp)    Operands.reserve(NumImplicitOps + TID->getNumOperands());    if (!NoImp)      addImplicitDefUseOperands(); +  // Make sure that we get added to a machine basicblock +  LeakDetector::addGarbageObject(this);  }  /// MachineInstr ctor - Work exactly the same as the ctor above, except that the @@ -300,6 +305,8 @@ MachineInstr::MachineInstr(MachineBasicBlock *MBB,        NumImplicitOps++;    Operands.reserve(NumImplicitOps + TID->getNumOperands());    addImplicitDefUseOperands(); +  // Make sure that we get added to a machine basicblock +  LeakDetector::addGarbageObject(this);    MBB->push_back(this);  // Add instruction to end of basic block!  } @@ -326,6 +333,7 @@ MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI) {  }  MachineInstr::~MachineInstr() { +  LeakDetector::removeGarbageObject(this);    assert(MemOperands.empty() &&           "MachineInstr being deleted with live memoperands!");  #ifndef NDEBUG  | 

