[llvm-commits] [dragonegg] r89200 - /dragonegg/trunk/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Wed Nov 18 01:04:44 PST 2009


Author: baldrick
Date: Wed Nov 18 03:04:38 2009
New Revision: 89200

URL: http://llvm.org/viewvc/llvm-project?rev=89200&view=rev
Log:
Make DefineSSAName idempotent.  This matters in the following theoretical
situation: A is an SSA name for which a placeholder P is being used.  The
definition of SSA name B is that it is equal to A.  Then the SSANames map
will contain the entry B->P.  Each time EmitSSA_NAME is called on the tree
defining B, since we see B mapping to a placeholder (P, not created as a
placeholder for B, created as a placeholder for A), we think it should not
be returned, but instead the definition of B should be processed.  Since B
is defined to be equal to A, this results in calling DefineSSAName with the
value of A, i.e. P.  But the entry B->P already exists in the map.  Doing
a RAUW of P with P then deleting P would be very bad...

Modified:
    dragonegg/trunk/llvm-convert.cpp

Modified: dragonegg/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-convert.cpp?rev=89200&r1=89199&r2=89200&view=diff

==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Wed Nov 18 03:04:38 2009
@@ -781,11 +781,13 @@
 Value *TreeToLLVM::DefineSSAName(tree_node *reg, Value *Val) {
   assert(TREE_CODE(reg) == SSA_NAME && "Not an SSA name!");
   if (Value *ExistingValue = SSANames[reg]) {
-    assert(isSSAPlaceholder(ExistingValue) && "Multiply defined SSA name!");
-    // Replace the placeholder with the value everywhere.  This also updates the
-    // map entry.
-    ExistingValue->replaceAllUsesWith(Val);
-    delete ExistingValue;
+    if (Val != ExistingValue) {
+      assert(isSSAPlaceholder(ExistingValue) && "Multiply defined SSA name!");
+      // Replace the placeholder with the value everywhere.  This also updates
+      // the map entry, because it is a TrackingVH.
+      ExistingValue->replaceAllUsesWith(Val);
+      delete ExistingValue;
+    }
     return Val;
   }
   return SSANames[reg] = Val;





More information about the llvm-commits mailing list