Revert "[llvm] Use BasicBlock::phis() (NFC)"

Reverting because this causes crashes on the 2-stage buildbots, for
example http://lab.llvm.org:8011/#/builders/7/builds/1140.

This reverts commit 9b228f107d.
This commit is contained in:
Oliver Stannard 2021-01-07 09:43:33 +00:00
parent d0fa7a05be
commit 76f6b125ce
6 changed files with 46 additions and 18 deletions

View File

@ -440,8 +440,12 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
// N.B. This might not be a complete BasicBlock, so don't assume
// that it ends with a non-phi instruction.
for (PHINode &PN : phis())
PN.replaceIncomingBlockWith(Old, New);
for (iterator II = begin(), IE = end(); II != IE; ++II) {
PHINode *PN = dyn_cast<PHINode>(II);
if (!PN)
break;
PN->replaceIncomingBlockWith(Old, New);
}
}
void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *Old,

View File

@ -2199,10 +2199,13 @@ CleanupAndExit:
if (ParentL)
ParentL->addBasicBlockToLoop(NewPreheader, *LF);
IRBuilder<>(NewPreheader).CreateBr(Header);
for (PHINode &PN : Header->phis()) {
int bx = PN.getBasicBlockIndex(Preheader);
for (auto &In : *Header) {
PHINode *PN = dyn_cast<PHINode>(&In);
if (!PN)
break;
int bx = PN->getBasicBlockIndex(Preheader);
if (bx >= 0)
PN.setIncomingBlock(bx, NewPreheader);
PN->setIncomingBlock(bx, NewPreheader);
}
DT->addNewBlock(NewPreheader, Preheader);
DT->changeImmediateDominator(Header, NewPreheader);

View File

@ -483,20 +483,24 @@ static Optional<EstimatedUnrollCost> analyzeLoopUnrollCost(
// Prepare for the iteration by collecting any simplified entry or backedge
// inputs.
for (PHINode &PHI : L->getHeader()->phis()) {
for (Instruction &I : *L->getHeader()) {
auto *PHI = dyn_cast<PHINode>(&I);
if (!PHI)
break;
// The loop header PHI nodes must have exactly two input: one from the
// loop preheader and one from the loop latch.
assert(
PHI.getNumIncomingValues() == 2 &&
PHI->getNumIncomingValues() == 2 &&
"Must have an incoming value only for the preheader and the latch.");
Value *V = PHI.getIncomingValueForBlock(
Value *V = PHI->getIncomingValueForBlock(
Iteration == 0 ? L->getLoopPreheader() : L->getLoopLatch());
Constant *C = dyn_cast<Constant>(V);
if (Iteration != 0 && !C)
C = SimplifiedValues.lookup(V);
if (C)
SimplifiedInputValues.push_back({&PHI, C});
SimplifiedInputValues.push_back({PHI, C});
}
// Now clear and re-populate the map for the next iteration.
@ -621,8 +625,12 @@ static Optional<EstimatedUnrollCost> analyzeLoopUnrollCost(
BasicBlock *ExitingBB, *ExitBB;
std::tie(ExitingBB, ExitBB) = ExitWorklist.pop_back_val();
for (PHINode &PN : ExitBB->phis()) {
Value *Op = PN.getIncomingValueForBlock(ExitingBB);
for (Instruction &I : *ExitBB) {
auto *PN = dyn_cast<PHINode>(&I);
if (!PN)
break;
Value *Op = PN->getIncomingValueForBlock(ExitingBB);
if (auto *OpI = dyn_cast<Instruction>(Op))
if (L->contains(OpI))
AddCostRecursively(*OpI, TripCount - 1);

View File

@ -2843,8 +2843,12 @@ static void computeLiveInValues(BasicBlock::reverse_iterator Begin,
static void computeLiveOutSeed(BasicBlock *BB, SetVector<Value *> &LiveTmp) {
for (BasicBlock *Succ : successors(BB)) {
for (PHINode &PN : Succ->phis()) {
Value *V = PN.getIncomingValueForBlock(BB);
for (auto &I : *Succ) {
PHINode *PN = dyn_cast<PHINode>(&I);
if (!PN)
break;
Value *V = PN->getIncomingValueForBlock(BB);
assert(!isUnhandledGCPointerType(V->getType()) &&
"support for FCA unimplemented");
if (isHandledGCPointerType(V->getType()) && !isa<Constant>(V))

View File

@ -657,9 +657,13 @@ static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
// edge from this block.
SmallVector<Value *, 8> UnwindDestPHIValues;
BasicBlock *InvokeBB = II->getParent();
for (PHINode &PHI : UnwindDest->phis())
for (Instruction &I : *UnwindDest) {
// Save the value to use for this edge.
UnwindDestPHIValues.push_back(PHI.getIncomingValueForBlock(InvokeBB));
PHINode *PHI = dyn_cast<PHINode>(&I);
if (!PHI)
break;
UnwindDestPHIValues.push_back(PHI->getIncomingValueForBlock(InvokeBB));
}
// Add incoming-PHI values to the unwind destination block for the given basic
// block, using the values for the original invoke's source block.

View File

@ -7529,9 +7529,14 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
// Collect the incoming values from the PHIs.
Incoming.clear();
for (PHINode &P : BB->phis())
if (!VisitedInstrs.count(&P) && !R.isDeleted(&P))
Incoming.push_back(&P);
for (Instruction &I : *BB) {
PHINode *P = dyn_cast<PHINode>(&I);
if (!P)
break;
if (!VisitedInstrs.count(P) && !R.isDeleted(P))
Incoming.push_back(P);
}
// Sort by type.
llvm::stable_sort(Incoming, PhiTypeSorterFunc);