aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-10-08 21:34:58 +0000
committerChris Lattner <sabre@nondot.org>2002-10-08 21:34:58 +0000
commit8bcb768a9c2bd2a39c066b61b843611920ade3b3 (patch)
treed5ba604b19f2ad8799d24b17e963287eb97ee229
parentf7f009d9a5476d7a08cb2ed0e9b335b087d43fe9 (diff)
- Change PHINode::removeIncomingValue to delete the phi node if the last
incoming value is removed! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4078 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/VMCore/InstrTypes.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp
index b53f480b14..ff9d4059d2 100644
--- a/lib/VMCore/InstrTypes.cpp
+++ b/lib/VMCore/InstrTypes.cpp
@@ -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 @@ void PHINode::addIncoming(Value *D, BasicBlock *BB) {
// 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;
}