summaryrefslogtreecommitdiff
path: root/lib/VMCore/InstrTypes.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-06-11 15:04:40 +0000
committerChris Lattner <sabre@nondot.org>2001-06-11 15:04:40 +0000
commitee976f33713016a96e3fbb394b7d0c5465be25d7 (patch)
tree0ad7614e587c63accb1cabbe2cc2ff30acefdac5 /lib/VMCore/InstrTypes.cpp
parentc24d2088dc3d79e3b7e38a358b4a71f156c06836 (diff)
downloadllvm-ee976f33713016a96e3fbb394b7d0c5465be25d7.tar.gz
llvm-ee976f33713016a96e3fbb394b7d0c5465be25d7.tar.bz2
llvm-ee976f33713016a96e3fbb394b7d0c5465be25d7.tar.xz
Updates to support
* Changes in PHI node structure git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/InstrTypes.cpp')
-rw-r--r--lib/VMCore/InstrTypes.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp
index decb4ad386..15db9e07a7 100644
--- a/lib/VMCore/InstrTypes.cpp
+++ b/lib/VMCore/InstrTypes.cpp
@@ -45,7 +45,9 @@ PHINode::PHINode(const PHINode &PN)
: Instruction(PN.getType(), Instruction::PHINode) {
for (unsigned i = 0; i < PN.IncomingValues.size(); i++)
- IncomingValues.push_back(Use(PN.IncomingValues[i], this));
+ IncomingValues.push_back(
+ make_pair(Use(PN.IncomingValues[i].first, this),
+ BasicBlockUse(PN.IncomingValues[i].second, this)));
}
void PHINode::dropAllReferences() {
@@ -54,20 +56,37 @@ void PHINode::dropAllReferences() {
bool PHINode::setOperand(unsigned i, Value *Val) {
assert(Val && "PHI node must only reference nonnull definitions!");
- if (i >= IncomingValues.size()) return false;
+ if (i >= IncomingValues.size()*2) return false;
- IncomingValues[i] = Val;
+ if (i & 1) {
+ assert(Val->getValueType() == BasicBlockVal && "Not a BB!");
+ IncomingValues[i/2].second = (BasicBlock*)Val;
+ } else {
+ IncomingValues[i/2].first = Val;
+ }
return true;
}
-void PHINode::addIncoming(Value *D) {
- IncomingValues.push_back(Use(D, this));
+void PHINode::addIncoming(Value *D, BasicBlock *BB) {
+ IncomingValues.push_back(make_pair(Use(D, this), BasicBlockUse(BB, this)));
}
+struct FindBBEntry {
+ const BasicBlock *BB;
+ inline FindBBEntry(const BasicBlock *bb) : BB(bb) {}
+ inline bool operator()(const pair<Use,BasicBlockUse> &Entry) {
+ return Entry.second == BB;
+ }
+};
+
+
// removeIncomingValue - Remove an incoming value. This is useful if a
// predecessor basic block is deleted.
-Value *PHINode::removeIncomingValue(unsigned idx) {
- Value *Removed = IncomingValues[idx];
- IncomingValues.erase(IncomingValues.begin()+idx);
+Value *PHINode::removeIncomingValue(const BasicBlock *BB) {
+ vector<PairTy>::iterator Idx = find_if(IncomingValues.begin(),
+ IncomingValues.end(), FindBBEntry(BB));
+ assert(Idx != IncomingValues.end() && "BB not in PHI node!");
+ Value *Removed = Idx->first;
+ IncomingValues.erase(Idx);
return Removed;
}