llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Jeremy Morse (jmorse)

<details>
<summary>Changes</summary>

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a 
debug-info bit that's needed when getFirstNonPHI and similar feed into 
instruction insertion positions. Call-sites where that's necessary were updated 
a year ago; but to ensure some type safety however, we'd like to have all calls 
to moveBefore use iterators.

This patch adds a (guaranteed dereferenceable) iterator-taking moveBefore, and 
changes a bunch of call-sites where it's obviously safe to change to use it by 
just calling getIterator() on an instruction pointer. A follow-up patch will 
contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer insertBefore, but 
not before adding concise documentation of what considerations are needed (very 
few).

---

Patch is 99.86 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/123583.diff


89 Files Affected:

- (modified) clang/lib/CodeGen/CGCoroutine.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGException.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+1-1) 
- (modified) llvm/include/llvm/IR/BasicBlock.h (+1) 
- (modified) llvm/include/llvm/IR/DebugProgramInstruction.h (+8) 
- (modified) llvm/include/llvm/IR/Instruction.h (+20-3) 
- (modified) llvm/lib/Analysis/LoopInfo.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+16-16) 
- (modified) llvm/lib/CodeGen/SelectOptimize.cpp (+4-4) 
- (modified) llvm/lib/CodeGen/SjLjEHPrepare.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/StackColoring.cpp (+3-2) 
- (modified) llvm/lib/CodeGen/TypePromotion.cpp (+7-7) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+2-2) 
- (modified) llvm/lib/FuzzMutate/IRMutator.cpp (+1-1) 
- (modified) llvm/lib/IR/DIBuilder.cpp (+1-1) 
- (modified) llvm/lib/IR/DebugProgramInstruction.cpp (+33-2) 
- (modified) llvm/lib/IR/Instruction.cpp (+14) 
- (modified) llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp (+3-3) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp (+1-1) 
- (modified) llvm/lib/Target/ARM/ARMParallelDSP.cpp (+1-1) 
- (modified) llvm/lib/Target/BPF/BPFASpaceCastSimplifyPass.cpp (+1-1) 
- (modified) llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp (+4-4) 
- (modified) llvm/lib/Target/BPF/BPFAdjustOpt.cpp (+1-1) 
- (modified) llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp (+6-6) 
- (modified) llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp (+2-2) 
- (modified) llvm/lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp (+1-1) 
- (modified) llvm/lib/Target/NVPTX/NVPTXAllocaHoisting.cpp (+1-1) 
- (modified) llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp (+2-2) 
- (modified) llvm/lib/Target/X86/X86LowerAMXType.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Coroutines/CoroFrame.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Coroutines/SpillUtils.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+3-3) 
- (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+2-2) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+3-3) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp (+1-1) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (+1-1) 
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp 
(+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp (+3-3) 
- (modified) 
llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/ConstantHoisting.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/ConstraintElimination.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/DivRemPairs.cpp (+6-6) 
- (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/GVNHoist.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Scalar/LICM.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/LoopFuse.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/LoopInterchange.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/LoopSink.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/Reassociate.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/Sink.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/BasicBlockUtils.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/CallPromotionUtils.cpp (+7-7) 
- (modified) llvm/lib/Transforms/Utils/CloneFunction.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+4-4) 
- (modified) llvm/lib/Transforms/Utils/CodeMoverUtils.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/GuardUtils.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Utils/Instrumentation.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/Local.cpp (+5-5) 
- (modified) llvm/lib/Transforms/Utils/LoopRotationUtils.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+5-3) 
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Vectorize/VPlan.cpp (+1-1) 
- (modified) llvm/tools/llvm-stress/llvm-stress.cpp (+1-1) 
- (modified) llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp (+12-12) 
- (modified) llvm/unittests/Analysis/CGSCCPassManagerTest.cpp (+1-1) 
- (modified) llvm/unittests/Analysis/MemorySSATest.cpp (+6-6) 
- (modified) llvm/unittests/IR/BasicBlockDbgInfoTest.cpp (+3-3) 
- (modified) llvm/unittests/IR/BasicBlockTest.cpp (+1-1) 
- (modified) llvm/unittests/IR/LegacyPassManagerTest.cpp (+1-1) 
- (modified) llvm/unittests/IR/VerifierTest.cpp (+5-5) 
- (modified) polly/lib/CodeGen/BlockGenerators.cpp (+2-2) 
- (modified) polly/lib/Support/ScopHelper.cpp (+1-1) 


``````````diff
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 0c09ff96f9d6b3..9abf2e8c9190d9 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -626,7 +626,7 @@ struct CallCoroDelete final : public EHScopeStack::Cleanup {
 
     // Get back to the block we were originally and move coro.free there.
     auto *InsertPt = SaveInsertBlock->getTerminator();
-    CoroFree->moveBefore(InsertPt);
+    CoroFree->moveBefore(InsertPt->getIterator());
     CGF.Builder.SetInsertPoint(InsertPt);
 
     // Add if (auto *mem = coro.free) Deallocate;
diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index e7dd5fb01ebede..5dc1686e7914c1 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1858,7 +1858,7 @@ Address 
CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
            "expected alloca or localrecover in parent LocalDeclMap");
     RecoverCall = cast<llvm::CallInst>(ParentRecover->clone());
     RecoverCall->setArgOperand(1, ParentFP);
-    RecoverCall->insertBefore(AllocaInsertPt);
+    RecoverCall->insertBefore(AllocaInsertPt->getIterator());
   }
 
   // Bitcast the variable, rename it, and insert it in the local decl map.
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index ddcb04d53661d0..0a089aaa1d3ce7 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1332,7 +1332,7 @@ void 
CGOpenMPRuntime::setLocThreadIdInsertPt(CodeGenFunction &CGF,
                                                  CGF.Builder.GetInsertBlock());
   } else {
     Elem.ServiceInsertPt = new llvm::BitCastInst(Undef, CGF.Int32Ty, "svcpt");
-    Elem.ServiceInsertPt->insertAfter(CGF.AllocaInsertPt);
+    Elem.ServiceInsertPt->insertAfter(CGF.AllocaInsertPt->getIterator());
   }
 }
 
diff --git a/llvm/include/llvm/IR/BasicBlock.h 
b/llvm/include/llvm/IR/BasicBlock.h
index c7913e60cea083..f85b221a211b91 100644
--- a/llvm/include/llvm/IR/BasicBlock.h
+++ b/llvm/include/llvm/IR/BasicBlock.h
@@ -194,6 +194,7 @@ class BasicBlock final : public Value, // Basic blocks are 
data objects also
   // debug-info attachments.
   friend void Instruction::insertBefore(BasicBlock::iterator InsertPos);
   friend void Instruction::insertAfter(Instruction *InsertPos);
+  friend void Instruction::insertAfter(BasicBlock::iterator InsertPos);
   friend void Instruction::insertBefore(BasicBlock &BB,
                                         InstListType::iterator InsertPos);
   friend void Instruction::moveBeforeImpl(BasicBlock &BB,
diff --git a/llvm/include/llvm/IR/DebugProgramInstruction.h 
b/llvm/include/llvm/IR/DebugProgramInstruction.h
index e979d8840cbaf8..37db7894d173dd 100644
--- a/llvm/include/llvm/IR/DebugProgramInstruction.h
+++ b/llvm/include/llvm/IR/DebugProgramInstruction.h
@@ -192,11 +192,19 @@ class DbgRecord : public ilist_node<DbgRecord> {
 
   DbgRecord *getNextNode() { return &*std::next(getIterator()); }
   DbgRecord *getPrevNode() { return &*std::prev(getIterator()); }
+
+  // Some generic lambdas supporting intrinsic-based debug-info mean we need
+  // to support both iterator and instruction position based insertion.
   void insertBefore(DbgRecord *InsertBefore);
   void insertAfter(DbgRecord *InsertAfter);
   void moveBefore(DbgRecord *MoveBefore);
   void moveAfter(DbgRecord *MoveAfter);
 
+  void insertBefore(self_iterator InsertBefore);
+  void insertAfter(self_iterator InsertAfter);
+  void moveBefore(self_iterator MoveBefore);
+  void moveAfter(self_iterator MoveAfter);
+
   DebugLoc getDebugLoc() const { return DbgLoc; }
   void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); }
 
diff --git a/llvm/include/llvm/IR/Instruction.h 
b/llvm/include/llvm/IR/Instruction.h
index aa480aa8d98636..6cdd79ce16005c 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -207,12 +207,19 @@ class Instruction : public User,
   /// Insert an unlinked instruction into a basic block immediately before
   /// the specified instruction.
   void insertBefore(Instruction *InsertPos);
+
+  /// Insert an unlinked instruction into a basic block immediately before
+  /// the specified position.
   void insertBefore(InstListType::iterator InsertPos);
 
   /// Insert an unlinked instruction into a basic block immediately after the
   /// specified instruction.
   void insertAfter(Instruction *InsertPos);
 
+  /// Insert an unlinked instruction into a basic block immediately after the
+  /// specified position.
+  void insertAfter(InstListType::iterator InsertPos);
+
   /// Inserts an unlinked instruction into \p ParentBB at position \p It and
   /// returns the iterator of the inserted instruction.
   InstListType::iterator insertInto(BasicBlock *ParentBB,
@@ -224,11 +231,15 @@ class Instruction : public User,
   /// the basic block that MovePos lives in, right before MovePos.
   void moveBefore(Instruction *MovePos);
 
+  /// Unlink this instruction from its current basic block and insert it into
+  /// the basic block that MovePos lives in, right before MovePos.
+  void moveBefore(InstListType::iterator InsertPos);
+
   /// Perform a \ref moveBefore operation, while signalling that the caller
   /// intends to preserve the original ordering of instructions. This 
implicitly
   /// means that any adjacent debug-info should move with this instruction.
-  /// This method is currently a no-op placeholder, but it will become 
meaningful
-  /// when the "RemoveDIs" project is enabled.
+  /// This method is currently a no-op placeholder, but it will become
+  /// meaningful when the "RemoveDIs" project is enabled.
   void moveBeforePreserving(Instruction *MovePos);
 
 private:
@@ -242,13 +253,19 @@ class Instruction : public User,
   /// \pre I is a valid iterator into BB.
   void moveBefore(BasicBlock &BB, InstListType::iterator I);
 
-  /// (See other overload for moveBeforePreserving).
   void moveBeforePreserving(BasicBlock &BB, InstListType::iterator I);
+  /// Unlink this instruction from its current basic block and insert it into
+  /// the basic block that MovePos lives in, right before MovePos.
+  void moveBeforePreserving(InstListType::iterator I);
 
   /// Unlink this instruction from its current basic block and insert it into
   /// the basic block that MovePos lives in, right after MovePos.
   void moveAfter(Instruction *MovePos);
 
+  /// Unlink this instruction from its current basic block and insert it into
+  /// the basic block that MovePos lives in, right after MovePos.
+  void moveAfter(InstListType::iterator MovePos);
+
   /// See \ref moveBeforePreserving .
   void moveAfterPreserving(Instruction *MovePos);
 
diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp
index 7bd5e1e0cfac8f..0eaf1dca59675b 100644
--- a/llvm/lib/Analysis/LoopInfo.cpp
+++ b/llvm/lib/Analysis/LoopInfo.cpp
@@ -103,7 +103,7 @@ bool Loop::makeLoopInvariant(Instruction *I, bool &Changed,
       return false;
 
   // Hoist.
-  I->moveBefore(InsertPt);
+  I->moveBefore(InsertPt->getIterator());
   if (MSSAU)
     if (auto *MUD = MSSAU->getMemorySSA()->getMemoryAccess(I))
       MSSAU->moveToPlace(MUD, InsertPt->getParent(),
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp 
b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 7106e53bd5516f..7e9d705a7bef6c 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1264,7 +1264,7 @@ simplifyRelocatesOffABase(GCRelocateInst *RelocatedBase,
     if (auto *RI = dyn_cast<GCRelocateInst>(R))
       if (RI->getStatepoint() == RelocatedBase->getStatepoint())
         if (RI->getBasePtrIndex() == RelocatedBase->getBasePtrIndex()) {
-          RelocatedBase->moveBefore(RI);
+          RelocatedBase->moveBefore(RI->getIterator());
           MadeChange = true;
           break;
         }
@@ -2690,7 +2690,7 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, 
ModifyDT &ModifiedDT) {
           ExtVal->getParent() == CI->getParent())
         return false;
       // Sink a zext feeding stlxr/stxr before it, so it can be folded into it.
-      ExtVal->moveBefore(CI);
+      ExtVal->moveBefore(CI->getIterator());
       // Mark this instruction as "inserted by CGP", so that other
       // optimizations don't touch it.
       InsertedInsts.insert(ExtVal);
@@ -3036,7 +3036,7 @@ bool 
CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB,
     for (auto *CI : CallInsts) {
       for (auto const *FakeUse : FakeUses) {
         auto *ClonedInst = FakeUse->clone();
-        ClonedInst->insertBefore(CI);
+        ClonedInst->insertBefore(CI->getIterator());
       }
     }
     BB->eraseFromParent();
@@ -7552,9 +7552,9 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) {
   // Sink expensive instructions into the conditional blocks to avoid executing
   // them speculatively.
   for (Instruction *I : TrueInstrs)
-    I->moveBefore(TrueBranch);
+    I->moveBefore(TrueBranch->getIterator());
   for (Instruction *I : FalseInstrs)
-    I->moveBefore(FalseBranch);
+    I->moveBefore(FalseBranch->getIterator());
 
   // If we did not create a new block for one of the 'true' or 'false' paths
   // of the condition, it means that side of the branch goes to the end block
@@ -7682,7 +7682,7 @@ bool CodeGenPrepare::tryToSinkFreeOperands(Instruction 
*I) {
     NewInstructions[UI] = NI;
     MaybeDead.insert(UI);
     LLVM_DEBUG(dbgs() << "Sinking " << *UI << " to user " << *I << "\n");
-    NI->insertBefore(InsertPoint);
+    NI->insertBefore(InsertPoint->getIterator());
     InsertPoint = NI;
     InsertedInsts.insert(NI);
 
@@ -7744,7 +7744,7 @@ bool CodeGenPrepare::optimizeSwitchType(SwitchInst *SI) {
   }
 
   auto *ExtInst = CastInst::Create(ExtType, Cond, NewType);
-  ExtInst->insertBefore(SI);
+  ExtInst->insertBefore(SI->getIterator());
   ExtInst->setDebugLoc(SI->getDebugLoc());
   SI->setCondition(ExtInst);
   for (auto Case : SI->cases()) {
@@ -8556,7 +8556,7 @@ static bool optimizeBranch(BranchInst *Branch, const 
TargetLowering &TLI,
         match(UI, m_Shr(m_Specific(X), m_SpecificInt(CmpC.logBase2())))) {
       IRBuilder<> Builder(Branch);
       if (UI->getParent() != Branch->getParent())
-        UI->moveBefore(Branch);
+        UI->moveBefore(Branch->getIterator());
       UI->dropPoisonGeneratingFlags();
       Value *NewCmp = Builder.CreateCmp(ICmpInst::ICMP_EQ, UI,
                                         ConstantInt::get(UI->getType(), 0));
@@ -8570,7 +8570,7 @@ static bool optimizeBranch(BranchInst *Branch, const 
TargetLowering &TLI,
          match(UI, m_Sub(m_Specific(X), m_SpecificInt(CmpC))))) {
       IRBuilder<> Builder(Branch);
       if (UI->getParent() != Branch->getParent())
-        UI->moveBefore(Branch);
+        UI->moveBefore(Branch->getIterator());
       UI->dropPoisonGeneratingFlags();
       Value *NewCmp = Builder.CreateCmp(Cmp->getPredicate(), UI,
                                         ConstantInt::get(UI->getType(), 0));
@@ -8890,21 +8890,21 @@ bool 
CodeGenPrepare::fixupDbgVariableRecord(DbgVariableRecord &DVR) {
   return AnyChange;
 }
 
-static void DbgInserterHelper(DbgValueInst *DVI, Instruction *VI) {
+static void DbgInserterHelper(DbgValueInst *DVI, BasicBlock::iterator VI) {
   DVI->removeFromParent();
   if (isa<PHINode>(VI))
-    DVI->insertBefore(&*VI->getParent()->getFirstInsertionPt());
+    DVI->insertBefore(VI->getParent()->getFirstInsertionPt());
   else
     DVI->insertAfter(VI);
 }
 
-static void DbgInserterHelper(DbgVariableRecord *DVR, Instruction *VI) {
+static void DbgInserterHelper(DbgVariableRecord *DVR, BasicBlock::iterator VI) 
{
   DVR->removeFromParent();
   BasicBlock *VIBB = VI->getParent();
   if (isa<PHINode>(VI))
     VIBB->insertDbgRecordBefore(DVR, VIBB->getFirstInsertionPt());
   else
-    VIBB->insertDbgRecordAfter(DVR, VI);
+    VIBB->insertDbgRecordAfter(DVR, &*VI);
 }
 
 // A llvm.dbg.value may be using a value before its definition, due to
@@ -8954,7 +8954,7 @@ bool CodeGenPrepare::placeDbgValues(Function &F) {
 
       LLVM_DEBUG(dbgs() << "Moving Debug Value before :\n"
                         << *DbgItem << ' ' << *VI);
-      DbgInserterHelper(DbgItem, VI);
+      DbgInserterHelper(DbgItem, VI->getIterator());
       MadeChange = true;
       ++NumDbgValueMoved;
     }
@@ -8997,7 +8997,7 @@ bool CodeGenPrepare::placePseudoProbes(Function &F) {
     I++;
     while (I != Block.end()) {
       if (auto *II = dyn_cast<PseudoProbeInst>(I++)) {
-        II->moveBefore(&*FirstInst);
+        II->moveBefore(FirstInst);
         MadeChange = true;
       }
     }
@@ -9105,7 +9105,7 @@ bool CodeGenPrepare::splitBranchCondition(Function &F, 
ModifyDT &ModifiedDT) {
     auto *Br2 = IRBuilder<>(TmpBB).CreateCondBr(Cond2, TBB, FBB);
     if (auto *I = dyn_cast<Instruction>(Cond2)) {
       I->removeFromParent();
-      I->insertBefore(Br2);
+      I->insertBefore(Br2->getIterator());
     }
 
     // Update PHI nodes in both successors. The original BB needs to be
diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp 
b/llvm/lib/CodeGen/SelectOptimize.cpp
index bfc49dd354aa60..57488a90e7a4ab 100644
--- a/llvm/lib/CodeGen/SelectOptimize.cpp
+++ b/llvm/lib/CodeGen/SelectOptimize.cpp
@@ -512,7 +512,7 @@ static Value *getTrueOrFalseValue(
       CBO->setOperand(OtherIdx,
                       isTrue ? OptSelects[IV].first : OptSelects[IV].second);
   }
-  CBO->insertBefore(B->getTerminator());
+  CBO->insertBefore(B->getTerminator()->getIterator());
   return CBO;
 }
 
@@ -637,7 +637,7 @@ void 
SelectOptimizeImpl::convertProfitableSIGroups(SelectGroups &ProfSIGroups) {
     }
     auto InsertionPoint = EndBlock->getFirstInsertionPt();
     for (auto *DI : SinkInstrs)
-      DI->moveBeforePreserving(&*InsertionPoint);
+      DI->moveBeforePreserving(InsertionPoint);
 
     // Duplicate implementation for DbgRecords, the non-instruction debug-info
     // format. Helper lambda for moving DbgRecords to the end block.
@@ -675,7 +675,7 @@ void 
SelectOptimizeImpl::convertProfitableSIGroups(SelectGroups &ProfSIGroups) {
       TrueBranch = BranchInst::Create(EndBlock, TrueBlock);
       TrueBranch->setDebugLoc(LastSI.getI()->getDebugLoc());
       for (Instruction *TrueInst : TrueSlicesInterleaved)
-        TrueInst->moveBefore(TrueBranch);
+        TrueInst->moveBefore(TrueBranch->getIterator());
     }
     if (!FalseSlicesInterleaved.empty() || HasSelectLike(ASI, false)) {
       FalseBlock =
@@ -684,7 +684,7 @@ void 
SelectOptimizeImpl::convertProfitableSIGroups(SelectGroups &ProfSIGroups) {
       FalseBranch = BranchInst::Create(EndBlock, FalseBlock);
       FalseBranch->setDebugLoc(LastSI.getI()->getDebugLoc());
       for (Instruction *FalseInst : FalseSlicesInterleaved)
-        FalseInst->moveBefore(FalseBranch);
+        FalseInst->moveBefore(FalseBranch->getIterator());
     }
     // If there was nothing to sink, then arbitrarily choose the 'false' side
     // for a new input value to the PHI.
diff --git a/llvm/lib/CodeGen/SjLjEHPrepare.cpp 
b/llvm/lib/CodeGen/SjLjEHPrepare.cpp
index 9630ba4307cd21..295475515e08ef 100644
--- a/llvm/lib/CodeGen/SjLjEHPrepare.cpp
+++ b/llvm/lib/CodeGen/SjLjEHPrepare.cpp
@@ -368,7 +368,7 @@ void SjLjEHPrepareImpl::lowerAcrossUnwindEdges(Function &F,
       DemotePHIToStack(PN);
 
     // Move the landingpad instruction back to the top of the landing pad 
block.
-    LPI->moveBefore(&UnwindBlock->front());
+    LPI->moveBefore(UnwindBlock->begin());
   }
 }
 
@@ -478,7 +478,7 @@ bool 
SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
         continue;
       }
       Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
-      StackAddr->insertAfter(&I);
+      StackAddr->insertAfter(I.getIterator());
       new StoreInst(StackAddr, StackPtr, true,
                     std::next(StackAddr->getIterator()));
     }
diff --git a/llvm/lib/CodeGen/StackColoring.cpp 
b/llvm/lib/CodeGen/StackColoring.cpp
index 0305bdce26f731..b77b8dbdd6e595 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -937,7 +937,8 @@ void StackColoring::remapInstructions(DenseMap<int, int> 
&SlotRemap) {
     // If From is before wo, its possible that there is a use of From between
     // them.
     if (From->comesBefore(To))
-      const_cast<AllocaInst*>(To)->moveBefore(const_cast<AllocaInst*>(From));
+      const_cast<AllocaInst *>(To)->moveBefore(
+          const_cast<AllocaInst *>(From)->getIterator());
 
     // AA might be used later for instruction scheduling, and we need it to be
     // able to deduce the correct aliasing releationships between pointers
@@ -948,7 +949,7 @@ void StackColoring::remapInstructions(DenseMap<int, int> 
&SlotRemap) {
     Instruction *Inst = const_cast<AllocaInst *>(To);
     if (From->getType() != To->getType()) {
       BitCastInst *Cast = new BitCastInst(Inst, From->getType());
-      Cast->insertAfter(Inst);
+      Cast->insertAfter(Inst->getIterator());
       Inst = Cast;
     }
 
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp 
b/llvm/lib/CodeGen/TypePromotion.cpp
index b29c46b0540cdc..b1f99094daa4a9 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -436,7 +436,7 @@ void IRPromoter::ReplaceAllUsersOfWith(Value *From, Value 
*To) {
 void IRPromoter::ExtendSources() {
   IRBuilder<> Builder{Ctx};
 
-  auto InsertZExt = [&](Value *V, Instruction *InsertPt) {
+  auto InsertZExt = [&](Value *V, BasicBlock::iterator InsertPt) {
     assert(V->getType() != ExtTy && "zext already extends to i32");
     LLVM_DEBUG(dbgs() << "IR Promotion: Inserting ZExt for " << *V << "\n");
     Builder.SetInsertPoint(InsertPt);
@@ -448,7 +448,7 @@ void IRPromoter::ExtendSources() {
       if (isa<Argument>(V))
         I->moveBefore(InsertPt);
       else
-        I->moveAfter(InsertPt);
+        I->moveAfter(&*InsertPt);
       NewInsts.insert(I);
     }
 
@@ -460,10 +460,10 @@ void IRPromoter::ExtendSources() {
   for (auto *V : Sources) {
     LLVM_DEBUG(dbgs() << " - " << *V << "\n");
     if (auto *I = dyn_cast<Instruction>(V))
-      InsertZExt(I, I);
+      InsertZExt(I, I->getIterator());
     else if (auto *Arg = dyn_cast<Argument>(V)) {
       BasicBlock &BB = Arg->getParent()->front();
-      InsertZExt(Arg, &*BB.getFirstInsertionPt());
+      InsertZExt(Arg, BB.getFirstInsertionPt());
     } else {
       llvm_unreachable("unhandled source that needs extending");
     }
@@ -552,7 +552,7 @@ void IRPromoter::TruncateSinks() {
         Value *Arg = Call->getArgOperand(i);
         Type *Ty = TruncTysMap[Call][i];
         if (Instruction *Trunc = InsertTrunc(Arg, Ty)) {
-          Trunc->moveBefore(Call);
+          Trunc->moveBefore(Call->getIterator());
           Call->setArgOperand(i, Trunc);
         }
       }
@@ -563,7 +563,7 @@ void IRPromoter::TruncateSinks() {
     if (auto *Switch = dyn_cast<SwitchInst>(I)) {
       Type *Ty = TruncTysMap[Switch][0];
       if (Instruction *Trunc = InsertTrunc(Switch->getCondition(), Ty)) {
-        Trunc->moveBefore(Switch);
+        Trunc->moveBefore(Switch->getIterator());
         Switch->setCondition(Trunc);
       }
       continue;
@@ -583,7 +583,7 @@ void IRPromoter::TruncateSinks() {
     for (unsigned i = 0; i < I->getNumOperands(); ++i) {
       Type *Ty = TruncTysMap[I][i];
       if (Instruction *Trunc = InsertTrunc(I->getOperand(i), Ty)) {
-        Trunc->moveBefore(I);
+        Trunc->moveBefore(I->getIterator());
         I->setOperand(i, Trunc);
       }
     }
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 7dbf65fbf055bd..c4dc81e11d8abb 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -1488,12 +1488,12 @@ OpenMPIRBuilder::InsertPointOrErrorTy 
OpenMPIRBuilder::createParallel(
     // Add additional casts to enforce pointers in zero address space
     TIDAddr = new AddrSpaceCastInst(
         TIDAddrAlloca, PointerType ::get(M.getContext(), 0), 
"tid.addr.ascast");
-    TIDAddr->insertAfter(TIDAddrAlloca);
+    TIDAddr->insertAfter(TIDAddrAlloca->getIterator());
     ToBeDeleted.push_back(TIDAddr);
     ZeroAddr = new AddrSpaceCastInst(ZeroAddrAlloca,
                                      PointerType ::get(M.getContext(), 0),
                                      "zero.addr.ascast");
-    ZeroAddr->insertAfter(ZeroAddrAlloca);
+    ZeroAddr->...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/123583
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to