mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-03 10:54:42 +00:00
- Change PHINode::removeIncomingValue to delete the phi node if the last
incoming value is removed! llvm-svn: 4078
This commit is contained in:
parent
40df2d9d4c
commit
f868df40b9
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user