[llvm] r249915 - CodeGen: Remove implicit ilist iterator conversions, NFC

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 15:56:25 PDT 2015


Author: dexonsmith
Date: Fri Oct  9 17:56:24 2015
New Revision: 249915

URL: http://llvm.org/viewvc/llvm-project?rev=249915&view=rev
Log:
CodeGen: Remove implicit ilist iterator conversions, NFC

Finish removing implicit ilist iterator conversions from LLVMCodeGen.
I'm sure there are lots more of these in lib/CodeGen/*/.

Modified:
    llvm/trunk/lib/CodeGen/SjLjEHPrepare.cpp
    llvm/trunk/lib/CodeGen/SpillPlacement.cpp
    llvm/trunk/lib/CodeGen/SplitKit.cpp
    llvm/trunk/lib/CodeGen/StackProtector.cpp
    llvm/trunk/lib/CodeGen/TailDuplication.cpp
    llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp
    llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
    llvm/trunk/lib/CodeGen/VirtRegMap.cpp
    llvm/trunk/lib/CodeGen/WinEHPrepare.cpp

Modified: llvm/trunk/lib/CodeGen/SjLjEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SjLjEHPrepare.cpp?rev=249915&r1=249914&r2=249915&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SjLjEHPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/SjLjEHPrepare.cpp Fri Oct  9 17:56:24 2015
@@ -179,8 +179,8 @@ void SjLjEHPrepare::substituteLPadValues
   // values and replace the LPI with that aggregate.
   Type *LPadType = LPI->getType();
   Value *LPadVal = UndefValue::get(LPadType);
-  IRBuilder<> Builder(
-      std::next(BasicBlock::iterator(cast<Instruction>(SelVal))));
+  auto *SelI = cast<Instruction>(SelVal);
+  IRBuilder<> Builder(SelI->getParent(), std::next(SelI->getIterator()));
   LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
   LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val");
 
@@ -191,7 +191,7 @@ void SjLjEHPrepare::substituteLPadValues
 /// it with all of the data that we know at this point.
 Value *SjLjEHPrepare::setupFunctionContext(Function &F,
                                            ArrayRef<LandingPadInst *> LPads) {
-  BasicBlock *EntryBB = F.begin();
+  BasicBlock *EntryBB = &F.front();
 
   // Create an alloca for the incoming jump buffer ptr and the new jump buffer
   // that needs to be restored on all exits from the function. This is an alloca
@@ -199,12 +199,13 @@ Value *SjLjEHPrepare::setupFunctionConte
   auto &DL = F.getParent()->getDataLayout();
   unsigned Align = DL.getPrefTypeAlignment(FunctionContextTy);
   FuncCtx = new AllocaInst(FunctionContextTy, nullptr, Align, "fn_context",
-                           EntryBB->begin());
+                           &EntryBB->front());
 
   // Fill in the function context structure.
   for (unsigned I = 0, E = LPads.size(); I != E; ++I) {
     LandingPadInst *LPI = LPads[I];
-    IRBuilder<> Builder(LPI->getParent()->getFirstInsertionPt());
+    IRBuilder<> Builder(LPI->getParent(),
+                        LPI->getParent()->getFirstInsertionPt());
 
     // Reference the __data field.
     Value *FCData =
@@ -251,21 +252,20 @@ void SjLjEHPrepare::lowerIncomingArgumen
   while (isa<AllocaInst>(AfterAllocaInsPt) &&
          isa<ConstantInt>(cast<AllocaInst>(AfterAllocaInsPt)->getArraySize()))
     ++AfterAllocaInsPt;
+  assert(AfterAllocaInsPt != F.front().end());
 
-  for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); AI != AE;
-       ++AI) {
-    Type *Ty = AI->getType();
+  for (auto &AI : F.args()) {
+    Type *Ty = AI.getType();
 
     // Use 'select i8 true, %arg, undef' to simulate a 'no-op' instruction.
     Value *TrueValue = ConstantInt::getTrue(F.getContext());
     Value *UndefValue = UndefValue::get(Ty);
-    Instruction *SI = SelectInst::Create(TrueValue, AI, UndefValue,
-                                         AI->getName() + ".tmp",
-                                         AfterAllocaInsPt);
-    AI->replaceAllUsesWith(SI);
+    Instruction *SI = SelectInst::Create(
+        TrueValue, &AI, UndefValue, AI.getName() + ".tmp", &*AfterAllocaInsPt);
+    AI.replaceAllUsesWith(SI);
 
     // Reset the operand, because it  was clobbered by the RAUW above.
-    SI->setOperand(1, AI);
+    SI->setOperand(1, &AI);
   }
 }
 
@@ -280,7 +280,7 @@ void SjLjEHPrepare::lowerAcrossUnwindEdg
       // Ignore obvious cases we don't have to handle. In particular, most
       // instructions either have no uses or only have a single use inside the
       // current block. Ignore them quickly.
-      Instruction *Inst = II;
+      Instruction *Inst = &*II;
       if (Inst->use_empty())
         continue;
       if (Inst->hasOneUse() &&
@@ -361,7 +361,7 @@ void SjLjEHPrepare::lowerAcrossUnwindEdg
       DemotePHIToStack(PN);
 
     // Move the landingpad instruction back to the top of the landing pad block.
-    LPI->moveBefore(UnwindBlock->begin());
+    LPI->moveBefore(&UnwindBlock->front());
   }
 }
 
@@ -401,7 +401,7 @@ bool SjLjEHPrepare::setupEntryBlockAndCa
 
   Value *FuncCtx =
       setupFunctionContext(F, makeArrayRef(LPads.begin(), LPads.end()));
-  BasicBlock *EntryBB = F.begin();
+  BasicBlock *EntryBB = &F.front();
   IRBuilder<> Builder(EntryBB->getTerminator());
 
   // Get a reference to the jump buffer.
@@ -475,7 +475,7 @@ bool SjLjEHPrepare::setupEntryBlockAndCa
         continue;
       }
       Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
-      StackAddr->insertAfter(I);
+      StackAddr->insertAfter(&*I);
       Instruction *StoreStackAddr = new StoreInst(StackAddr, StackPtr, true);
       StoreStackAddr->insertAfter(StackAddr);
     }

Modified: llvm/trunk/lib/CodeGen/SpillPlacement.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SpillPlacement.cpp?rev=249915&r1=249914&r2=249915&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SpillPlacement.cpp (original)
+++ llvm/trunk/lib/CodeGen/SpillPlacement.cpp Fri Oct  9 17:56:24 2015
@@ -187,9 +187,9 @@ bool SpillPlacement::runOnMachineFunctio
   BlockFrequencies.resize(mf.getNumBlockIDs());
   MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
   setThreshold(MBFI->getEntryFreq());
-  for (MachineFunction::iterator I = mf.begin(), E = mf.end(); I != E; ++I) {
-    unsigned Num = I->getNumber();
-    BlockFrequencies[Num] = MBFI->getBlockFreq(I);
+  for (auto &I : mf) {
+    unsigned Num = I.getNumber();
+    BlockFrequencies[Num] = MBFI->getBlockFreq(&I);
   }
 
   // We never change the function.

Modified: llvm/trunk/lib/CodeGen/SplitKit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SplitKit.cpp?rev=249915&r1=249914&r2=249915&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SplitKit.cpp (original)
+++ llvm/trunk/lib/CodeGen/SplitKit.cpp Fri Oct  9 17:56:24 2015
@@ -177,10 +177,11 @@ bool SplitAnalysis::calcLiveBlockInfo()
   UseE = UseSlots.end();
 
   // Loop over basic blocks where CurLI is live.
-  MachineFunction::iterator MFI = LIS.getMBBFromIndex(LVI->start);
+  MachineFunction::iterator MFI =
+      LIS.getMBBFromIndex(LVI->start)->getIterator();
   for (;;) {
     BlockInfo BI;
-    BI.MBB = MFI;
+    BI.MBB = &*MFI;
     SlotIndex Start, Stop;
     std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(BI.MBB);
 
@@ -260,7 +261,7 @@ bool SplitAnalysis::calcLiveBlockInfo()
     if (LVI->start < Stop)
       ++MFI;
     else
-      MFI = LIS.getMBBFromIndex(LVI->start);
+      MFI = LIS.getMBBFromIndex(LVI->start)->getIterator();
   }
 
   assert(getNumLiveBlocks() == countLiveBlocks(CurLI) && "Bad block count");
@@ -276,8 +277,9 @@ unsigned SplitAnalysis::countLiveBlocks(
   unsigned Count = 0;
 
   // Loop over basic blocks where li is live.
-  MachineFunction::const_iterator MFI = LIS.getMBBFromIndex(LVI->start);
-  SlotIndex Stop = LIS.getMBBEndIdx(MFI);
+  MachineFunction::const_iterator MFI =
+      LIS.getMBBFromIndex(LVI->start)->getIterator();
+  SlotIndex Stop = LIS.getMBBEndIdx(&*MFI);
   for (;;) {
     ++Count;
     LVI = li->advanceTo(LVI, Stop);
@@ -285,7 +287,7 @@ unsigned SplitAnalysis::countLiveBlocks(
       return Count;
     do {
       ++MFI;
-      Stop = LIS.getMBBEndIdx(MFI);
+      Stop = LIS.getMBBEndIdx(&*MFI);
     } while (Stop <= LVI->start);
   }
 }
@@ -865,9 +867,9 @@ bool SplitEditor::transferValues() {
       // This value has multiple defs in RegIdx, but it wasn't rematerialized,
       // so the live range is accurate. Add live-in blocks in [Start;End) to the
       // LiveInBlocks.
-      MachineFunction::iterator MBB = LIS.getMBBFromIndex(Start);
+      MachineFunction::iterator MBB = LIS.getMBBFromIndex(Start)->getIterator();
       SlotIndex BlockStart, BlockEnd;
-      std::tie(BlockStart, BlockEnd) = LIS.getSlotIndexes()->getMBBRange(MBB);
+      std::tie(BlockStart, BlockEnd) = LIS.getSlotIndexes()->getMBBRange(&*MBB);
 
       // The first block may be live-in, or it may have its own def.
       if (Start != BlockStart) {
@@ -876,7 +878,7 @@ bool SplitEditor::transferValues() {
         DEBUG(dbgs() << ':' << VNI->id << "*BB#" << MBB->getNumber());
         // MBB has its own def. Is it also live-out?
         if (BlockEnd <= End)
-          LRC.setLiveOutValue(MBB, VNI);
+          LRC.setLiveOutValue(&*MBB, VNI);
 
         // Skip to the next block for live-in.
         ++MBB;
@@ -887,23 +889,23 @@ bool SplitEditor::transferValues() {
       assert(Start <= BlockStart && "Expected live-in block");
       while (BlockStart < End) {
         DEBUG(dbgs() << ">BB#" << MBB->getNumber());
-        BlockEnd = LIS.getMBBEndIdx(MBB);
+        BlockEnd = LIS.getMBBEndIdx(&*MBB);
         if (BlockStart == ParentVNI->def) {
           // This block has the def of a parent PHI, so it isn't live-in.
           assert(ParentVNI->isPHIDef() && "Non-phi defined at block start?");
           VNInfo *VNI = LR.extendInBlock(BlockStart, std::min(BlockEnd, End));
           assert(VNI && "Missing def for complex mapped parent PHI");
           if (End >= BlockEnd)
-            LRC.setLiveOutValue(MBB, VNI); // Live-out as well.
+            LRC.setLiveOutValue(&*MBB, VNI); // Live-out as well.
         } else {
           // This block needs a live-in value.  The last block covered may not
           // be live-out.
           if (End < BlockEnd)
-            LRC.addLiveInBlock(LR, MDT[MBB], End);
+            LRC.addLiveInBlock(LR, MDT[&*MBB], End);
           else {
             // Live-through, and we don't know the value.
-            LRC.addLiveInBlock(LR, MDT[MBB]);
-            LRC.setLiveOutValue(MBB, nullptr);
+            LRC.addLiveInBlock(LR, MDT[&*MBB]);
+            LRC.setLiveOutValue(&*MBB, nullptr);
           }
         }
         BlockStart = BlockEnd;

Modified: llvm/trunk/lib/CodeGen/StackProtector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StackProtector.cpp?rev=249915&r1=249914&r2=249915&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/StackProtector.cpp (original)
+++ llvm/trunk/lib/CodeGen/StackProtector.cpp Fri Oct  9 17:56:24 2015
@@ -373,7 +373,7 @@ bool StackProtector::InsertStackProtecto
   Value *StackGuardVar = nullptr; // The stack guard variable.
 
   for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
-    BasicBlock *BB = I++;
+    BasicBlock *BB = &*I++;
     ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator());
     if (!RI)
       continue;
@@ -433,7 +433,7 @@ bool StackProtector::InsertStackProtecto
       BasicBlock *FailBB = CreateFailBB();
 
       // Split the basic block before the return instruction.
-      BasicBlock *NewBB = BB->splitBasicBlock(RI, "SP_return");
+      BasicBlock *NewBB = BB->splitBasicBlock(RI->getIterator(), "SP_return");
 
       // Update the dominator tree if we need to.
       if (DT && DT->isReachableFromEntry(BB)) {

Modified: llvm/trunk/lib/CodeGen/TailDuplication.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TailDuplication.cpp?rev=249915&r1=249914&r2=249915&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TailDuplication.cpp (original)
+++ llvm/trunk/lib/CodeGen/TailDuplication.cpp Fri Oct  9 17:56:24 2015
@@ -161,7 +161,7 @@ void TailDuplicatePass::getAnalysisUsage
 
 static void VerifyPHIs(MachineFunction &MF, bool CheckExtra) {
   for (MachineFunction::iterator I = ++MF.begin(), E = MF.end(); I != E; ++I) {
-    MachineBasicBlock *MBB = I;
+    MachineBasicBlock *MBB = &*I;
     SmallSetVector<MachineBasicBlock*, 8> Preds(MBB->pred_begin(),
                                                 MBB->pred_end());
     MachineBasicBlock::iterator MI = MBB->begin();
@@ -322,7 +322,7 @@ bool TailDuplicatePass::TailDuplicateBlo
   }
 
   for (MachineFunction::iterator I = ++MF.begin(), E = MF.end(); I != E; ) {
-    MachineBasicBlock *MBB = I++;
+    MachineBasicBlock *MBB = &*I++;
 
     if (NumTails == TailDupLimit)
       break;
@@ -689,7 +689,7 @@ TailDuplicatePass::duplicateSimpleBB(Mac
                  << "From simple Succ: " << *TailBB);
 
     MachineBasicBlock *NewTarget = *TailBB->succ_begin();
-    MachineBasicBlock *NextBB = std::next(MachineFunction::iterator(PredBB));
+    MachineBasicBlock *NextBB = &*std::next(PredBB->getIterator());
 
     // Make PredFBB explicit.
     if (PredCond.empty())
@@ -846,7 +846,7 @@ TailDuplicatePass::TailDuplicate(Machine
   // If TailBB was duplicated into all its predecessors except for the prior
   // block, which falls through unconditionally, move the contents of this
   // block into the prior block.
-  MachineBasicBlock *PrevBB = std::prev(MachineFunction::iterator(TailBB));
+  MachineBasicBlock *PrevBB = &*std::prev(TailBB->getIterator());
   MachineBasicBlock *PriorTBB = nullptr, *PriorFBB = nullptr;
   SmallVector<MachineOperand, 4> PriorCond;
   // This has to check PrevBB->succ_size() because EH edges are ignored by

Modified: llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp?rev=249915&r1=249914&r2=249915&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp (original)
+++ llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp Fri Oct  9 17:56:24 2015
@@ -699,9 +699,10 @@ TwoAddressInstructionPass::convertInstTo
                                               unsigned RegA, unsigned RegB,
                                               unsigned Dist) {
   // FIXME: Why does convertToThreeAddress() need an iterator reference?
-  MachineFunction::iterator MFI = MBB;
+  MachineFunction::iterator MFI = MBB->getIterator();
   MachineInstr *NewMI = TII->convertToThreeAddress(MFI, mi, LV);
-  assert(MBB == MFI && "convertToThreeAddress changed iterator reference");
+  assert(MBB->getIterator() == MFI &&
+         "convertToThreeAddress changed iterator reference");
   if (!NewMI)
     return false;
 
@@ -1643,7 +1644,7 @@ bool TwoAddressInstructionPass::runOnMac
   TiedOperandMap TiedOperands;
   for (MachineFunction::iterator MBBI = MF->begin(), MBBE = MF->end();
        MBBI != MBBE; ++MBBI) {
-    MBB = MBBI;
+    MBB = &*MBBI;
     unsigned Dist = 0;
     DistanceMap.clear();
     SrcRegMap.clear();

Modified: llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp?rev=249915&r1=249914&r2=249915&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp (original)
+++ llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp Fri Oct  9 17:56:24 2015
@@ -71,8 +71,8 @@ bool UnreachableBlockElim::runOnFunction
   // in them.
   std::vector<BasicBlock*> DeadBlocks;
   for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
-    if (!Reachable.count(I)) {
-      BasicBlock *BB = I;
+    if (!Reachable.count(&*I)) {
+      BasicBlock *BB = &*I;
       DeadBlocks.push_back(BB);
       while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
         PN->replaceAllUsesWith(Constant::getNullValue(PN->getType()));
@@ -131,7 +131,7 @@ bool UnreachableMachineBlockElim::runOnM
   // in them.
   std::vector<MachineBasicBlock*> DeadBlocks;
   for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) {
-    MachineBasicBlock *BB = I;
+    MachineBasicBlock *BB = &*I;
 
     // Test for deadness.
     if (!Reachable.count(BB)) {
@@ -167,7 +167,7 @@ bool UnreachableMachineBlockElim::runOnM
 
   // Cleanup PHI nodes.
   for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) {
-    MachineBasicBlock *BB = I;
+    MachineBasicBlock *BB = &*I;
     // Prune unneeded PHI entries.
     SmallPtrSet<MachineBasicBlock*, 8> preds(BB->pred_begin(),
                                              BB->pred_end());

Modified: llvm/trunk/lib/CodeGen/VirtRegMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/VirtRegMap.cpp?rev=249915&r1=249914&r2=249915&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/VirtRegMap.cpp (original)
+++ llvm/trunk/lib/CodeGen/VirtRegMap.cpp Fri Oct  9 17:56:24 2015
@@ -355,7 +355,7 @@ void VirtRegRewriter::rewrite() {
     DEBUG(MBBI->print(dbgs(), Indexes));
     for (MachineBasicBlock::instr_iterator
            MII = MBBI->instr_begin(), MIE = MBBI->instr_end(); MII != MIE;) {
-      MachineInstr *MI = MII;
+      MachineInstr *MI = &*MII;
       ++MII;
 
       for (MachineInstr::mop_iterator MOI = MI->operands_begin(),

Modified: llvm/trunk/lib/CodeGen/WinEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/WinEHPrepare.cpp?rev=249915&r1=249914&r2=249915&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/WinEHPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/WinEHPrepare.cpp Fri Oct  9 17:56:24 2015
@@ -541,7 +541,7 @@ static Instruction *findBeginCatchSplitP
 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 =
@@ -564,7 +564,7 @@ void WinEHPrepare::findCXXEHReturnPoints
             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));
@@ -588,7 +588,7 @@ static bool isCatchAllLandingPad(const B
 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
@@ -608,8 +608,9 @@ void WinEHPrepare::findSEHEHReturnPoints
       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);
     }
@@ -759,7 +760,7 @@ void WinEHPrepare::demoteValuesLiveAcros
   // 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);
 
@@ -822,7 +823,7 @@ bool WinEHPrepare::prepareExceptionHandl
     // 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
@@ -1042,7 +1043,7 @@ bool WinEHPrepare::prepareExceptionHandl
 
   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);
@@ -1243,10 +1244,10 @@ void WinEHPrepare::completeNestedLanding
   // 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.
@@ -1349,7 +1350,8 @@ static bool isSelectorDispatch(BasicBloc
 }
 
 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;
@@ -1533,7 +1535,7 @@ bool WinEHPrepare::outlineHandler(Action
   // 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());
 
@@ -1544,10 +1546,10 @@ bool WinEHPrepare::outlineHandler(Action
   // 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();
 
@@ -1579,7 +1581,8 @@ bool WinEHPrepare::outlineHandler(Action
         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
@@ -1615,9 +1618,9 @@ void WinEHPrepare::processSEHCatchHandle
   } 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");
@@ -2042,9 +2045,9 @@ WinEHFrameVariableMaterializer::WinEHFra
 
   // 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);
 }
 
@@ -2441,9 +2444,10 @@ void WinEHPrepare::findCleanupHandlers(L
         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)
@@ -2465,9 +2469,10 @@ void WinEHPrepare::findCleanupHandlers(L
       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)
@@ -2532,9 +2537,10 @@ void WinEHPrepare::findCleanupHandlers(L
     }
 
     // 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.
@@ -3163,11 +3169,11 @@ void WinEHPrepare::demotePHIsOnFunclets(
   // 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)
@@ -3191,10 +3197,10 @@ void WinEHPrepare::demotePHIsOnFunclets(
 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())
@@ -3398,7 +3404,7 @@ void WinEHPrepare::cleanupPreparedFuncle
   // 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);
@@ -3469,9 +3475,9 @@ AllocaInst *WinEHPrepare::insertPHILoads
     // 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;
   }
@@ -3582,7 +3588,7 @@ void WinEHPrepare::demoteNonlocalUses(Va
     // 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
@@ -3602,13 +3608,13 @@ void WinEHPrepare::demoteNonlocalUses(Va
       }
       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);
   }
 }
 
@@ -3619,7 +3625,7 @@ void WinEHPrepare::replaceUseWithLoad(Va
   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)) {




More information about the llvm-commits mailing list