void WinEHPrepare::findCXXEHReturnPoints(
Function &F, SetVector<BasicBlock *> &EHReturnBlocks) {
for (auto BBI = F.begin(), BBE = F.end(); BBI != BBE; ++BBI) {
- BasicBlock *BB = BBI;
+ BasicBlock *BB = &*BBI;
for (Instruction &I : *BB) {
if (match(&I, m_Intrinsic<Intrinsic::eh_begincatch>())) {
Instruction *SplitPt =
isa<PHINode>(Br->getSuccessor(0)->begin())) {
DEBUG(dbgs() << "splitting block " << BB->getName()
<< " with llvm.eh.endcatch\n");
- BBI = SplitBlock(BB, I.getNextNode(), DT);
+ BBI = SplitBlock(BB, I.getNextNode(), DT)->getIterator();
}
// The next BB is normal control flow.
EHReturnBlocks.insert(BB->getTerminator()->getSuccessor(0));
void WinEHPrepare::findSEHEHReturnPoints(
Function &F, SetVector<BasicBlock *> &EHReturnBlocks) {
for (auto BBI = F.begin(), BBE = F.end(); BBI != BBE; ++BBI) {
- BasicBlock *BB = BBI;
+ BasicBlock *BB = &*BBI;
// If the landingpad is a catch-all, treat the whole lpad as if it is
// reachable from normal control flow.
// FIXME: This is imprecise. We need a better way of identifying where a
if (!CatchHandler->getSinglePredecessor()) {
DEBUG(dbgs() << "splitting EH return edge from " << BB->getName()
<< " to " << CatchHandler->getName() << '\n');
- BBI = CatchHandler = SplitCriticalEdge(
+ CatchHandler = SplitCriticalEdge(
BB, std::find(succ_begin(BB), succ_end(BB), CatchHandler));
+ BBI = CatchHandler->getIterator();
}
EHReturnBlocks.insert(CatchHandler);
}
// FIXME: This demotion is inefficient. We should insert spills at the point
// of definition, insert one reload in each handler that uses the value, and
// insert reloads in the BB used to rejoin normal control flow.
- Instruction *AllocaInsertPt = F.getEntryBlock().getFirstInsertionPt();
+ Instruction *AllocaInsertPt = &*F.getEntryBlock().getFirstInsertionPt();
for (Instruction *I : InstrsToDemote)
DemoteRegToStack(*I, false, AllocaInsertPt);
// FIXME: Switch the ehptr type to i32 and then switch this.
SEHExceptionCodeSlot =
new AllocaInst(Int8PtrType, nullptr, "seh_exception_code",
- F.getEntryBlock().getFirstInsertionPt());
+ &*F.getEntryBlock().getFirstInsertionPt());
}
// In order to handle the case where one outlined catch handler returns
BasicBlock *Entry = &F.getEntryBlock();
IRBuilder<> Builder(F.getParent()->getContext());
- Builder.SetInsertPoint(Entry->getFirstInsertionPt());
+ Builder.SetInsertPoint(Entry, Entry->getFirstInsertionPt());
Function *FrameEscapeFn =
Intrinsic::getDeclaration(M, Intrinsic::localescape);
// and remap return instructions in the nested handlers that should return
// to an address in the outlined handler.
Function *OutlinedHandlerFn = OutlinedBB->getParent();
- BasicBlock::const_iterator II = OriginalLPad;
+ BasicBlock::const_iterator II = OriginalLPad->getIterator();
++II;
// The instruction after the landing pad should now be a call to eh.actions.
- const Instruction *Recover = II;
+ const Instruction *Recover = &*II;
const IntrinsicInst *EHActions = cast<IntrinsicInst>(Recover);
// Remap the return target in the nested handler.
}
static bool isCatchBlock(BasicBlock *BB) {
- for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg(), IE = BB->end();
+ for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg()->getIterator(),
+ IE = BB->end();
II != IE; ++II) {
if (match(cast<Value>(II), m_Intrinsic<Intrinsic::eh_begincatch>()))
return true;
// Skip over PHIs and, if applicable, landingpad instructions.
II = StartBB->getFirstInsertionPt();
- CloneAndPruneIntoFromInst(Handler, SrcFn, II, VMap,
+ CloneAndPruneIntoFromInst(Handler, SrcFn, &*II, VMap,
/*ModuleLevelChanges=*/false, Returns, "",
&OutlinedFunctionInfo, Director.get());
// predecessors. Any other block wouldn't have been cloned if it didn't
// have a predecessor which was also cloned.
Function::iterator ClonedIt = std::next(Function::iterator(Entry));
- while (!pred_empty(ClonedIt))
+ while (!pred_empty(&*ClonedIt))
++ClonedIt;
- BasicBlock *ClonedEntryBB = ClonedIt;
- assert(ClonedEntryBB);
+ assert(ClonedIt != Entry->getParent()->end());
+ BasicBlock *ClonedEntryBB = &*ClonedIt;
Entry->getInstList().splice(Entry->end(), ClonedEntryBB->getInstList());
ClonedEntryBB->eraseFromParent();
auto *Branch = dyn_cast<BranchInst>(Pred->getTerminator());
if (!Branch || !Branch->isUnconditional() || Pred->size() <= 1)
continue;
- BasicBlock::iterator II = const_cast<BranchInst *>(Branch);
+ BasicBlock::iterator II =
+ const_cast<BranchInst *>(Branch)->getIterator();
--II;
if (match(cast<Value>(II), m_Intrinsic<Intrinsic::eh_endcatch>())) {
// This would indicate that a nested landing pad wants to return
} else {
// This must be a catch-all. Split the block after the landingpad.
assert(CatchAction->getSelector()->isNullValue() && "expected catch-all");
- HandlerBB = SplitBlock(StartBB, StartBB->getFirstInsertionPt(), DT);
+ HandlerBB = SplitBlock(StartBB, &*StartBB->getFirstInsertionPt(), DT);
}
- IRBuilder<> Builder(HandlerBB->getFirstInsertionPt());
+ IRBuilder<> Builder(&*HandlerBB->getFirstInsertionPt());
Function *EHCodeFn = Intrinsic::getDeclaration(
StartBB->getParent()->getParent(), Intrinsic::eh_exceptioncode_old);
Value *Code = Builder.CreateCall(EHCodeFn, {}, "sehcode");
// New allocas should be inserted in the entry block, but after the parent FP
// is established if it is an instruction.
- Instruction *InsertPoint = EntryBB->getFirstInsertionPt();
+ BasicBlock::iterator InsertPoint = EntryBB->getFirstInsertionPt();
if (auto *FPInst = dyn_cast<Instruction>(ParentFP))
- InsertPoint = FPInst->getNextNode();
+ InsertPoint = std::next(FPInst->getIterator());
Builder.SetInsertPoint(EntryBB, InsertPoint);
}
if (!Insert1)
return createCleanupHandler(Actions, CleanupHandlerMap, BB);
}
- for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg(), IE = BB->end();
+ for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg()->getIterator(),
+ IE = BB->end();
II != IE; ++II) {
- Instruction *Inst = II;
+ Instruction *Inst = &*II;
if (LPadMap && LPadMap->isLandingPadSpecificInst(Inst))
continue;
if (Inst == Insert1 || Inst == Insert2 || Inst == Resume)
CmpInst *Compare = dyn_cast<CmpInst>(Branch->getCondition());
if (!Compare || !Compare->isEquality())
return createCleanupHandler(Actions, CleanupHandlerMap, BB);
- for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg(), IE = BB->end();
+ for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg()->getIterator(),
+ IE = BB->end();
II != IE; ++II) {
- Instruction *Inst = II;
+ Instruction *Inst = &*II;
if (LPadMap && LPadMap->isLandingPadSpecificInst(Inst))
continue;
if (Inst == Compare || Inst == Branch)
}
// Anything else is either a catch block or interesting cleanup code.
- for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg(), IE = BB->end();
+ for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg()->getIterator(),
+ IE = BB->end();
II != IE; ++II) {
- Instruction *Inst = II;
+ Instruction *Inst = &*II;
if (LPadMap && LPadMap->isLandingPadSpecificInst(Inst))
continue;
// Unconditional branches fall through to this loop.
// Strip PHI nodes off of EH pads.
SmallVector<PHINode *, 16> PHINodes;
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE;) {
- BasicBlock *BB = FI++;
+ BasicBlock *BB = &*FI++;
if (!BB->isEHPad())
continue;
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
- Instruction *I = BI++;
+ Instruction *I = &*BI++;
auto *PN = dyn_cast<PHINode>(I);
// Stop at the first non-PHI.
if (!PN)
void WinEHPrepare::demoteUsesBetweenFunclets(Function &F) {
// Turn all inter-funclet uses of a Value into loads and stores.
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE;) {
- BasicBlock *BB = FI++;
+ BasicBlock *BB = &*FI++;
std::set<BasicBlock *> &ColorsForBB = BlockColors[BB];
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
- Instruction *I = BI++;
+ Instruction *I = &*BI++;
// Funclets are permitted to use static allocas.
if (auto *AI = dyn_cast<AllocaInst>(I))
if (AI->isStaticAlloca())
// Clean-up some of the mess we made by removing useles PHI nodes, trivial
// branches, etc.
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE;) {
- BasicBlock *BB = FI++;
+ BasicBlock *BB = &*FI++;
SimplifyInstructionsInBlock(BB);
ConstantFoldTerminator(BB, /*DeleteDeadConditions=*/true);
MergeBlockIntoPredecessor(BB);
// Insert a load in place of the PHI and replace all uses.
SpillSlot = new AllocaInst(PN->getType(), nullptr,
Twine(PN->getName(), ".wineh.spillslot"),
- F.getEntryBlock().begin());
+ &F.getEntryBlock().front());
Value *V = new LoadInst(SpillSlot, Twine(PN->getName(), ".wineh.reload"),
- PHIBlock->getFirstInsertionPt());
+ &*PHIBlock->getFirstInsertionPt());
PN->replaceAllUsesWith(V);
return SpillSlot;
}
// because we can't insert the store AFTER the terminator instruction.
BasicBlock::iterator InsertPt;
if (isa<Argument>(V)) {
- InsertPt = F.getEntryBlock().getTerminator();
+ InsertPt = F.getEntryBlock().getTerminator()->getIterator();
} else if (isa<TerminatorInst>(V)) {
auto *II = cast<InvokeInst>(V);
// We cannot demote invoke instructions to the stack if their normal
}
InsertPt = II->getNormalDest()->getFirstInsertionPt();
} else {
- InsertPt = cast<Instruction>(V);
+ InsertPt = cast<Instruction>(V)->getIterator();
++InsertPt;
// Don't insert before PHI nodes or EH pad instrs.
for (; isa<PHINode>(InsertPt) || InsertPt->isEHPad(); ++InsertPt)
;
}
- new StoreInst(V, SpillSlot, InsertPt);
+ new StoreInst(V, SpillSlot, &*InsertPt);
}
}
if (!SpillSlot)
SpillSlot = new AllocaInst(V->getType(), nullptr,
Twine(V->getName(), ".wineh.spillslot"),
- F.getEntryBlock().begin());
+ &F.getEntryBlock().front());
auto *UsingInst = cast<Instruction>(U.getUser());
if (auto *UsingPHI = dyn_cast<PHINode>(UsingInst)) {