[llvm-commits] [llvm] r53746 - in /llvm/trunk: include/llvm/CodeGen/MachineBasicBlock.h lib/CodeGen/LiveIntervalAnalysis.cpp lib/CodeGen/LowerSubregs.cpp lib/CodeGen/MachineBasicBlock.cpp lib/CodeGen/MachineInstr.cpp

Dan Gohman gohman at apple.com
Thu Jul 17 16:49:46 PDT 2008


Author: djg
Date: Thu Jul 17 18:49:46 2008
New Revision: 53746

URL: http://llvm.org/viewvc/llvm-project?rev=53746&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
    llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
    llvm/trunk/lib/CodeGen/LowerSubregs.cpp
    llvm/trunk/lib/CodeGen/MachineBasicBlock.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=53746&r1=53745&r2=53746&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Thu Jul 17 18:49:46 2008
@@ -67,7 +67,7 @@
 
   explicit MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb);
 
-  ~MachineBasicBlock() {}
+  ~MachineBasicBlock();
 
   // MachineBasicBlocks are allocated and owned by MachineFunction.
   friend class MachineFunction;

Modified: llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp?rev=53746&r1=53745&r2=53746&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp Thu Jul 17 18:49:46 2008
@@ -1585,9 +1585,9 @@
     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) {

Modified: llvm/trunk/lib/CodeGen/LowerSubregs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LowerSubregs.cpp?rev=53746&r1=53745&r2=53746&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/LowerSubregs.cpp (original)
+++ llvm/trunk/lib/CodeGen/LowerSubregs.cpp Thu Jul 17 18:49:46 2008
@@ -80,7 +80,7 @@
    }
 
    DOUT << "\n";
-   MBB->remove(MI);
+   MBB->erase(MI);
    return true;
 }
 
@@ -119,7 +119,7 @@
 #endif
 
   DOUT << "\n";
-  MBB->remove(MI);
+  MBB->erase(MI);
   return true;                    
 }
 
@@ -164,7 +164,7 @@
   }
 
   DOUT << "\n";
-  MBB->remove(MI);
+  MBB->erase(MI);
   return true;                    
 }
 

Modified: llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp?rev=53746&r1=53745&r2=53746&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp Thu Jul 17 18:49:46 2008
@@ -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 @@
   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 @@
   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 @@
   // 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 @@
   N->RemoveRegOperandsFromUseLists();
   
   N->setParent(0);
+
+  LeakDetector::addGarbageObject(N);
 }
 
 /// transferNodesFromList (MI) - When moving a range of instructions from one

Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=53746&r1=53745&r2=53746&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Thu Jul 17 18:49:46 2008
@@ -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 @@
 /// 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 @@
   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 @@
       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() {
+  LeakDetector::removeGarbageObject(this);
   assert(MemOperands.empty() &&
          "MachineInstr being deleted with live memoperands!");
 #ifndef NDEBUG





More information about the llvm-commits mailing list