Revert r133513:
"Reinstate r133435 and r133449 (reverted in r133499) now that the clang
self-hosted build failure has been fixed (r133512)."
Due to some additional warnings.
llvm-svn: 133700
diff --git a/llvm/lib/VMCore/BasicBlock.cpp b/llvm/lib/VMCore/BasicBlock.cpp
index 7d47044..3f1a6a9 100644
--- a/llvm/lib/VMCore/BasicBlock.cpp
+++ b/llvm/lib/VMCore/BasicBlock.cpp
@@ -308,19 +308,3 @@
return New;
}
-void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
- TerminatorInst *TI = getTerminator();
- if (!TI)
- // Cope with being called on a BasicBlock that doesn't have a terminator
- // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
- return;
- for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
- BasicBlock *Succ = TI->getSuccessor(i);
- for (iterator II = Succ->begin(); PHINode *PN = dyn_cast<PHINode>(II);
- ++II) {
- int i;
- while ((i = PN->getBasicBlockIndex(this)) >= 0)
- PN->setIncomingBlock(i, New);
- }
- }
-}
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index 0eddd5a..8f4eabe 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/lib/VMCore/Instructions.cpp
@@ -87,8 +87,11 @@
: Instruction(PN.getType(), Instruction::PHI,
allocHungoffUses(PN.getNumOperands()), PN.getNumOperands()),
ReservedSpace(PN.getNumOperands()) {
- std::copy(PN.op_begin(), PN.op_end(), op_begin());
- std::copy(PN.block_begin(), PN.block_end(), block_begin());
+ Use *OL = OperandList;
+ for (unsigned i = 0, e = PN.getNumOperands(); i != e; i+=2) {
+ OL[i] = PN.getOperand(i);
+ OL[i+1] = PN.getOperand(i+1);
+ }
SubclassOptionalData = PN.SubclassOptionalData;
}
@@ -96,37 +99,31 @@
dropHungoffUses();
}
-Use *PHINode::allocHungoffUses(unsigned N) const {
- // Allocate the array of Uses of the incoming values, followed by a pointer
- // (with bottom bit set) to the User, followed by the array of pointers to
- // the incoming basic blocks.
- size_t size = N * sizeof(Use) + sizeof(Use::UserRef)
- + N * sizeof(BasicBlock*);
- Use *Begin = static_cast<Use*>(::operator new(size));
- Use *End = Begin + N;
- (void) new(End) Use::UserRef(const_cast<PHINode*>(this), 1);
- return Use::initTags(Begin, End);
-}
-
// removeIncomingValue - Remove an incoming value. This is useful if a
// predecessor basic block is deleted.
Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
- Value *Removed = getIncomingValue(Idx);
+ unsigned NumOps = getNumOperands();
+ Use *OL = OperandList;
+ assert(Idx*2 < NumOps && "BB not in PHI node!");
+ Value *Removed = OL[Idx*2];
// Move everything after this operand down.
//
// FIXME: we could just swap with the end of the list, then erase. However,
- // clients might not expect this to happen. The code as it is thrashes the
+ // client might not expect this to happen. The code as it is thrashes the
// use/def lists, which is kinda lame.
- std::copy(op_begin() + Idx + 1, op_end(), op_begin() + Idx);
- std::copy(block_begin() + Idx + 1, block_end(), block_begin() + Idx);
+ for (unsigned i = (Idx+1)*2; i != NumOps; i += 2) {
+ OL[i-2] = OL[i];
+ OL[i-2+1] = OL[i+1];
+ }
// Nuke the last value.
- Op<-1>().set(0);
- --NumOperands;
+ OL[NumOps-2].set(0);
+ OL[NumOps-2+1].set(0);
+ NumOperands = NumOps-2;
// If the PHI node is dead, because it has zero entries, nuke it now.
- if (getNumOperands() == 0 && DeletePHIIfEmpty) {
+ if (NumOps == 2 && DeletePHIIfEmpty) {
// If anyone is using this PHI, make them use a dummy value instead...
replaceAllUsesWith(UndefValue::get(getType()));
eraseFromParent();
@@ -140,18 +137,15 @@
///
void PHINode::growOperands() {
unsigned e = getNumOperands();
- unsigned NumOps = e + e / 2;
- if (NumOps < 2) NumOps = 2; // 2 op PHI nodes are VERY common.
-
- Use *OldOps = op_begin();
- BasicBlock **OldBlocks = block_begin();
+ // Multiply by 1.5 and round down so the result is still even.
+ unsigned NumOps = e + e / 4 * 2;
+ if (NumOps < 4) NumOps = 4; // 4 op PHI nodes are VERY common.
ReservedSpace = NumOps;
- OperandList = allocHungoffUses(ReservedSpace);
-
- std::copy(OldOps, OldOps + e, op_begin());
- std::copy(OldBlocks, OldBlocks + e, block_begin());
-
+ Use *OldOps = OperandList;
+ Use *NewOps = allocHungoffUses(NumOps);
+ std::copy(OldOps, OldOps + e, NewOps);
+ OperandList = NewOps;
Use::zap(OldOps, OldOps + e, true);
}
diff --git a/llvm/lib/VMCore/User.cpp b/llvm/lib/VMCore/User.cpp
index f01fa34..9601da7 100644
--- a/llvm/lib/VMCore/User.cpp
+++ b/llvm/lib/VMCore/User.cpp
@@ -40,10 +40,8 @@
//===----------------------------------------------------------------------===//
Use *User::allocHungoffUses(unsigned N) const {
- // Allocate the array of Uses, followed by a pointer (with bottom bit set) to
- // the User.
- size_t size = N * sizeof(Use) + sizeof(Use::UserRef);
- Use *Begin = static_cast<Use*>(::operator new(size));
+ Use *Begin = static_cast<Use*>(::operator new(sizeof(Use) * N
+ + sizeof(Use::UserRef)));
Use *End = Begin + N;
(void) new(End) Use::UserRef(const_cast<User*>(this), 1);
return Use::initTags(Begin, End);
diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp
index a03cddc..29f6a80 100644
--- a/llvm/lib/VMCore/Value.cpp
+++ b/llvm/lib/VMCore/Value.cpp
@@ -305,9 +305,6 @@
U.set(New);
}
-
- if (BasicBlock *BB = dyn_cast<BasicBlock>(this))
- BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
}
void Value::replaceAllUsesWith(Value *New) {
diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp
index 18de671..e504016 100644
--- a/llvm/lib/VMCore/Verifier.cpp
+++ b/llvm/lib/VMCore/Verifier.cpp
@@ -1139,6 +1139,9 @@
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
Assert1(PN.getType() == PN.getIncomingValue(i)->getType(),
"PHI node operands are not the same type as the result!", &PN);
+ Assert1(isa<BasicBlock>(PN.getOperand(
+ PHINode::getOperandNumForIncomingBlock(i))),
+ "PHI node incoming block is not a BasicBlock!", &PN);
}
// All other PHI node constraints are checked in the visitBasicBlock method.