[llvm-commits] [llvm] r67523 - /llvm/trunk/lib/Analysis/LiveValues.cpp

Dan Gohman gohman at apple.com
Mon Mar 23 08:49:37 PDT 2009


Author: djg
Date: Mon Mar 23 10:49:37 2009
New Revision: 67523

URL: http://llvm.org/viewvc/llvm-project?rev=67523&view=rev
Log:
Enhance LiveValues to work on PHI operands.

Modified:
    llvm/trunk/lib/Analysis/LiveValues.cpp

Modified: llvm/trunk/lib/Analysis/LiveValues.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LiveValues.cpp?rev=67523&r1=67522&r2=67523&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/LiveValues.cpp (original)
+++ llvm/trunk/lib/Analysis/LiveValues.cpp Mon Mar 23 10:49:37 2009
@@ -142,21 +142,32 @@
       if (L->contains(UseBB))
         break;
 
-    if (isa<PHINode>(U)) {
-      // The value is used by a PHI, so it is live-out of the defining block.
-      LiveOutOfDefBB = true;
-    } else if (UseBB != DefBB) {
-      // A use outside the defining block has been found.
+    // Search for live-through blocks.
+    const BasicBlock *BB;
+    if (const PHINode *PHI = dyn_cast<PHINode>(U)) {
+      // For PHI nodes, start the search at the incoming block paired with the
+      // incoming value, which must be dominated by the definition.
+      unsigned Num = PHI->getIncomingValueNumForOperand(I.getOperandNo());
+      BB = PHI->getIncomingBlock(Num);
+
+      // A PHI-node use means the value is live-out of it's defining block
+      // even if that block also contains the only use.
       LiveOutOfDefBB = true;
+    } else {
+      // Otherwise just start the search at the use.
+      BB = UseBB;
 
-      // Climb the immediate dominator tree from the use to the definition
-      // and mark all intermediate blocks as live-through. Don't do this if
-      // the user is a PHI because such users may not be dominated by the
-      // definition.
-      for (const BasicBlock *BB = getImmediateDominator(UseBB, DT);
-           BB != DefBB; BB = getImmediateDominator(BB, DT))
-        if (!M.LiveThrough.insert(BB))
-          break;
+      // Note if the use is outside the defining block.
+      LiveOutOfDefBB |= UseBB != DefBB;
+    }
+
+    // Climb the immediate dominator tree from the use to the definition
+    // and mark all intermediate blocks as live-through. Don't do this if
+    // the user is a PHI because such users may not be dominated by the
+    // definition.
+    for (; BB != DefBB; BB = getImmediateDominator(BB, DT)) {
+      if (BB != UseBB && !M.LiveThrough.insert(BB))
+        break;
     }
   }
 





More information about the llvm-commits mailing list