[llvm-commits] CVS: llvm/lib/VMCore/InstrTypes.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 8 16:36:00 PDT 2002


Changes in directory llvm/lib/VMCore:

InstrTypes.cpp updated: 1.18 -> 1.19

---
Log message:

  - Change PHINode::removeIncomingValue to delete the phi node if the last
    incoming value is removed!


---
Diffs of the changes:

Index: llvm/lib/VMCore/InstrTypes.cpp
diff -u llvm/lib/VMCore/InstrTypes.cpp:1.18 llvm/lib/VMCore/InstrTypes.cpp:1.19
--- llvm/lib/VMCore/InstrTypes.cpp:1.18	Tue Sep 10 10:45:53 2002
+++ llvm/lib/VMCore/InstrTypes.cpp	Tue Oct  8 16:34:58 2002
@@ -8,6 +8,7 @@
 #include "llvm/iPHINode.h"
 #include "llvm/Function.h"
 #include "llvm/SymbolTable.h"
+#include "llvm/Constant.h"
 #include "llvm/Type.h"
 #include <algorithm>  // find
 
@@ -41,11 +42,19 @@
 
 // removeIncomingValue - Remove an incoming value.  This is useful if a
 // predecessor basic block is deleted.
-Value *PHINode::removeIncomingValue(const BasicBlock *BB) {
+Value *PHINode::removeIncomingValue(const BasicBlock *BB,
+                                    bool DeletePHIIfEmpty) {
   op_iterator Idx = find(Operands.begin(), Operands.end(), (const Value*)BB);
   assert(Idx != Operands.end() && "BB not in PHI node!");
   --Idx;  // Back up to value prior to Basic block
   Value *Removed = *Idx;
   Operands.erase(Idx, Idx+2);  // Erase Value and BasicBlock
+
+  // If the PHI node is dead, because it has zero entries, nuke it now.
+  if (getNumOperands() == 0 && DeletePHIIfEmpty) {
+    // If anyone is using this PHI, make them use a dummy value instead...
+    replaceAllUsesWith(Constant::getNullValue(getType()));
+    getParent()->getInstList().erase(this);
+  }
   return Removed;
 }





More information about the llvm-commits mailing list