aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/iPHINode.h16
-rw-r--r--lib/VMCore/InstrTypes.cpp19
2 files changed, 18 insertions, 17 deletions
diff --git a/include/llvm/iPHINode.h b/include/llvm/iPHINode.h
index 4e217e971e..c9d2a71ecb 100644
--- a/include/llvm/iPHINode.h
+++ b/include/llvm/iPHINode.h
@@ -61,7 +61,12 @@ public:
}
/// addIncoming - Add an incoming value to the end of the PHI list
- void addIncoming(Value *D, BasicBlock *BB);
+ void addIncoming(Value *D, BasicBlock *BB) {
+ assert(getType() == D->getType() &&
+ "All operands to PHI node must be the same type as the PHI node!");
+ Operands.push_back(Use(D, this));
+ Operands.push_back(Use((Value*)BB, this));
+ }
/// removeIncomingValue - Remove an incoming value. This is useful if a
/// predecessor basic block is deleted. The value removed is returned.
@@ -71,8 +76,13 @@ public:
/// dummy values. The only time there should be zero incoming values to a PHI
/// node is when the block is dead, so this strategy is sound.
///
- Value *removeIncomingValue(const BasicBlock *BB,
- bool DeletePHIIfEmpty = true);
+ Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
+
+ Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
+ int Idx = getBasicBlockIndex(BB);
+ assert(Idx >= 0 && "Invalid basic block argument to remove!");
+ return removeIncomingValue(Idx, DeletePHIIfEmpty);
+ }
/// getBasicBlockIndex - Return the first index of the specified basic
/// block in the value list for this PHI. Returns -1 if no instance.
diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp
index ff9d4059d2..f1b5c4f100 100644
--- a/lib/VMCore/InstrTypes.cpp
+++ b/lib/VMCore/InstrTypes.cpp
@@ -33,22 +33,13 @@ PHINode::PHINode(const PHINode &PN)
}
}
-void PHINode::addIncoming(Value *D, BasicBlock *BB) {
- assert(getType() == D->getType() &&
- "All operands to PHI node must be the same type as the PHI node!");
- Operands.push_back(Use(D, this));
- Operands.push_back(Use(BB, this));
-}
-
// removeIncomingValue - Remove an incoming value. This is useful if a
// predecessor basic block is deleted.
-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
+Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
+ assert(Idx*2 < Operands.size() && "BB not in PHI node!");
+ Value *Removed = Operands[Idx*2];
+ Operands.erase(Operands.begin()+Idx*2, // Erase Value and BasicBlock
+ Operands.begin()+Idx*2+2);
// If the PHI node is dead, because it has zero entries, nuke it now.
if (getNumOperands() == 0 && DeletePHIIfEmpty) {