Remove GC roots that reference dead objects.
authorNicolas Geoffray <nicolas.geoffray@lip6.fr>
Fri, 26 Oct 2012 09:15:55 +0000 (09:15 +0000)
committerNicolas Geoffray <nicolas.geoffray@lip6.fr>
Fri, 26 Oct 2012 09:15:55 +0000 (09:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166763 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/GCMetadata.h
lib/CodeGen/GCStrategy.cpp

index 20e33f74f650d8db84c23204b8a377344d8537aa..076f6f39fe2c51715ad1e41a0fad8009fb8462e9 100644 (file)
@@ -122,6 +122,11 @@ namespace llvm {
       Roots.push_back(GCRoot(Num, Metadata));
     }
 
+    /// removeStackRoot - Removes a root.
+    roots_iterator removeStackRoot(roots_iterator position) {
+      return Roots.erase(position);
+    }
+
     /// addSafePoint - Notes the existence of a safe point. Num is the ID of the
     /// label just prior to the safe point (if the code generator is using
     /// MachineModuleInfo).
index 8de541de3d99f0b8ed4e1eb1bb12e7e8f03428e1..f4755bb1635cd70e31732c39d17fe5cce32f798b 100644 (file)
@@ -388,9 +388,16 @@ void GCMachineCodeAnalysis::FindStackOffsets(MachineFunction &MF) {
   const TargetFrameLowering *TFI = TM->getFrameLowering();
   assert(TFI && "TargetRegisterInfo not available!");
 
-  for (GCFunctionInfo::roots_iterator RI = FI->roots_begin(),
-                                      RE = FI->roots_end(); RI != RE; ++RI)
-    RI->StackOffset = TFI->getFrameIndexOffset(MF, RI->Num);
+  for (GCFunctionInfo::roots_iterator RI = FI->roots_begin();
+       RI != FI->roots_end();) {
+    // If the root references a dead object, no need to keep it.
+    if (MF.getFrameInfo()->isDeadObjectIndex(RI->Num)) {
+      RI = FI->removeStackRoot(RI);
+    } else {
+      RI->StackOffset = TFI->getFrameIndexOffset(MF, RI->Num);
+      ++RI;
+    }
+  }
 }
 
 bool GCMachineCodeAnalysis::runOnMachineFunction(MachineFunction &MF) {