[llvm-branch-commits] [llvm-branch] r109573 - in /llvm/branches/Apple/Morbo: include/llvm/Analysis/ScalarEvolutionExpressions.h lib/Analysis/ScalarEvolution.cpp

Dan Gohman gohman at apple.com
Tue Jul 27 18:58:44 PDT 2010


Author: djg
Date: Tue Jul 27 20:58:44 2010
New Revision: 109573

URL: http://llvm.org/viewvc/llvm-project?rev=109573&view=rev
Log:
$ svn merge -c 109565 https://djg@llvm.org/svn/llvm-project/llvm/trunk
--- Merging r109565 into '.':
U    include/llvm/Analysis/ScalarEvolutionExpressions.h
$ svn merge -c 109567 https://djg@llvm.org/svn/llvm-project/llvm/trunk
--- Merging r109567 into '.':
U    lib/Analysis/ScalarEvolution.cpp
$ svn merge -c 109570 https://djg@llvm.org/svn/llvm-project/llvm/trunk
--- Merging r109570 into '.':
G    lib/Analysis/ScalarEvolution.cpp

Modified:
    llvm/branches/Apple/Morbo/include/llvm/Analysis/ScalarEvolutionExpressions.h
    llvm/branches/Apple/Morbo/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/branches/Apple/Morbo/include/llvm/Analysis/ScalarEvolutionExpressions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/include/llvm/Analysis/ScalarEvolutionExpressions.h?rev=109573&r1=109572&r2=109573&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/include/llvm/Analysis/ScalarEvolutionExpressions.h (original)
+++ llvm/branches/Apple/Morbo/include/llvm/Analysis/ScalarEvolutionExpressions.h Tue Jul 27 20:58:44 2010
@@ -523,6 +523,8 @@
   class SCEVUnknown : public SCEV {
     friend class ScalarEvolution;
 
+    // This should be an AssertingVH, however SCEVUnknowns are allocated in a
+    // BumpPtrAllocator so their destructors are never called.
     Value *V;
     SCEVUnknown(const FoldingSetNodeIDRef ID, Value *v) :
       SCEV(ID, scUnknown), V(v) {}

Modified: llvm/branches/Apple/Morbo/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/Analysis/ScalarEvolution.cpp?rev=109573&r1=109572&r2=109573&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/Analysis/ScalarEvolution.cpp Tue Jul 27 20:58:44 2010
@@ -3513,6 +3513,26 @@
 /// changed a value in a way that may effect its value, or which may
 /// disconnect it from a def-use chain linking it to a loop.
 void ScalarEvolution::forgetValue(Value *V) {
+  // If there's a SCEVUnknown tying this value into the SCEV
+  // space, remove it from the folding set map. The SCEVUnknown
+  // object and any other SCEV objects which reference it
+  // (transitively) remain allocated, effectively leaked until
+  // the underlying BumpPtrAllocator is freed.
+  //
+  // This permits SCEV pointers to be used as keys in maps
+  // such as the ValuesAtScopes map.
+  FoldingSetNodeID ID;
+  ID.AddInteger(scUnknown);
+  ID.AddPointer(V);
+  void *IP;
+  if (SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) {
+    UniqueSCEVs.RemoveNode(S);
+
+    // This isn't necessary, but we might as well remove the
+    // value from the ValuesAtScopes map too.
+    ValuesAtScopes.erase(S);
+  }
+
   Instruction *I = dyn_cast<Instruction>(V);
   if (!I) return;
 
@@ -5331,16 +5351,32 @@
   // this now dangles!
 }
 
-void ScalarEvolution::SCEVCallbackVH::allUsesReplacedWith(Value *) {
+void ScalarEvolution::SCEVCallbackVH::allUsesReplacedWith(Value *V) {
   assert(SE && "SCEVCallbackVH called with a null ScalarEvolution!");
 
+  Value *Old = getValPtr();
+
+  // If there's a SCEVUnknown tying this value into the SCEV
+  // space, replace the SCEVUnknown's value with the new value
+  // for the benefit of any SCEVs still referencing it, and
+  // and remove it from the folding set map so that new scevs
+  // don't reference it.
+  FoldingSetNodeID ID;
+  ID.AddInteger(scUnknown);
+  ID.AddPointer(Old);
+  void *IP;
+  if (SCEVUnknown *S = cast_or_null<SCEVUnknown>(
+        SE->UniqueSCEVs.FindNodeOrInsertPos(ID, IP))) {
+    S->V = V;
+    SE->UniqueSCEVs.RemoveNode(S);
+    SE->ValuesAtScopes.erase(S);
+  }
+
   // Forget all the expressions associated with users of the old value,
   // so that future queries will recompute the expressions using the new
   // value.
   SmallVector<User *, 16> Worklist;
   SmallPtrSet<User *, 8> Visited;
-  Value *Old = getValPtr();
-  bool DeleteOld = false;
   for (Value::use_iterator UI = Old->use_begin(), UE = Old->use_end();
        UI != UE; ++UI)
     Worklist.push_back(*UI);
@@ -5348,10 +5384,8 @@
     User *U = Worklist.pop_back_val();
     // Deleting the Old value will cause this to dangle. Postpone
     // that until everything else is done.
-    if (U == Old) {
-      DeleteOld = true;
+    if (U == Old)
       continue;
-    }
     if (!Visited.insert(U))
       continue;
     if (PHINode *PN = dyn_cast<PHINode>(U))
@@ -5361,14 +5395,11 @@
          UI != UE; ++UI)
       Worklist.push_back(*UI);
   }
-  // Delete the Old value if it (indirectly) references itself.
-  if (DeleteOld) {
-    if (PHINode *PN = dyn_cast<PHINode>(Old))
-      SE->ConstantEvolutionLoopExitValue.erase(PN);
-    SE->Scalars.erase(Old);
-    // this now dangles!
-  }
-  // this may dangle!
+  // Delete the Old value.
+  if (PHINode *PN = dyn_cast<PHINode>(Old))
+    SE->ConstantEvolutionLoopExitValue.erase(PN);
+  SE->Scalars.erase(Old);
+  // this now dangles!
 }
 
 ScalarEvolution::SCEVCallbackVH::SCEVCallbackVH(Value *V, ScalarEvolution *se)





More information about the llvm-branch-commits mailing list