[clang] [llvm] [mlir] [IRBuilder] Remove custom insertion point type (PR #228117)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 09:05:58 PDT 2026


https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/228117

>From a32adc1a8f9bfec79fde9df0a21e28a430427c5f Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 1 Oct 2026 14:25:29 +0200
Subject: [PATCH] [IRBuilder] Remove custom insertion point type

---
 clang/lib/CodeGen/CGCleanup.cpp               |   8 +-
 clang/lib/CodeGen/CGExpr.cpp                  |   3 +-
 clang/lib/CodeGen/CGOpenMPRuntime.cpp         |  19 +-
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp      |  14 +-
 clang/lib/CodeGen/CGStmtOpenMP.cpp            |  19 +-
 clang/lib/CodeGen/CodeGenFunction.h           |  20 +-
 llvm/include/llvm/ADT/ilist_iterator.h        |   3 +
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h       |  10 +-
 llvm/include/llvm/IR/IRBuilder.h              |  41 +-
 .../Utils/ScalarEvolutionExpander.h           |   5 +-
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp     | 189 ++++-----
 llvm/lib/Transforms/IPO/OpenMPOpt.cpp         |  46 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  33 +-
 .../Frontend/OpenMPIRBuilderTest.cpp          | 397 ++++++++----------
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp      |  84 ++--
 15 files changed, 390 insertions(+), 501 deletions(-)

diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 9d279bebe5e0dea..6a49ec0aeec30f2 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -757,7 +757,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
     EHStack.popCleanup(); // safe because there are no fixups
     assert(EHStack.getNumBranchFixups() == 0 ||
            EHStack.hasNormalCleanups());
-    if (NormalDeactivateOrigIP.isSet())
+    if (NormalDeactivateOrigIP.isValid())
       Builder.restoreIP(NormalDeactivateOrigIP);
     return;
   }
@@ -799,11 +799,11 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
       // If we are deactivating a normal cleanup then we don't have a
       // fallthrough. Restore original IP to emit CPP scope ends in the correct
       // block.
-      if (NormalDeactivateOrigIP.isSet())
+      if (NormalDeactivateOrigIP.isValid())
         Builder.restoreIP(NormalDeactivateOrigIP);
       if (Builder.GetInsertBlock() && !IsSEHFinallyCleanup)
         EmitSehCppScopeEnd();
-      if (NormalDeactivateOrigIP.isSet())
+      if (NormalDeactivateOrigIP.isValid())
         NormalDeactivateOrigIP = Builder.saveAndClearIP();
     }
     destroyOptimisticNormalEntry(*this, Scope);
@@ -1030,7 +1030,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
     }
   }
 
-  if (NormalDeactivateOrigIP.isSet())
+  if (NormalDeactivateOrigIP.isValid())
     Builder.restoreIP(NormalDeactivateOrigIP);
   assert(EHStack.hasNormalCleanups() || EHStack.getNumBranchFixups() == 0);
 
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 8acf4b95f3e7797..76bd781a709b695 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -644,8 +644,7 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
 
         OldIP = Builder.saveIP();
         llvm::BasicBlock *Block = OldConditional->getStartingBlock();
-        Builder.restoreIP(CGBuilderTy::InsertPoint(
-            Block, llvm::BasicBlock::iterator(Block->back())));
+        Builder.restoreIP(Block->back().getIterator());
       }
 
       if (EmitLifetimeStart(Alloca.getPointer())) {
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 6de9fea26954efc..58bfd48a49d39a5 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1198,7 +1198,7 @@ struct PushAndPopStackRAII {
     // The FiniCB will still be needed but at the point where the
     // OpenMPIRBuilder is asked to construct a parallel (or similar) construct.
     auto FiniCB = [&CGF](llvm::OpenMPIRBuilder::InsertPointTy IP) {
-      assert(IP.getBlock()->end() == IP.getPoint() &&
+      assert(IP == IP.getNodeParent()->end() &&
              "Clang CG should cause non-terminated block!");
       CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
       CGF.Builder.restoreIP(IP);
@@ -10648,10 +10648,8 @@ static void emitOffloadingArraysAndArgs(
   CodeGenModule &CGM = CGF.CGM;
 
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
-  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
-                         CGF.AllocaInsertPt->getIterator());
-  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
-                          CGF.Builder.GetInsertPoint());
+  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getIterator());
+  InsertPointTy CodeGenIP(CGF.Builder.GetInsertPoint());
 
   auto DeviceAddrCB = [&](unsigned int I, llvm::Value *NewDecl) {
     if (const ValueDecl *DevVD = CombinedInfo.DevicePtrDecls[I]) {
@@ -11283,7 +11281,7 @@ static void emitTargetCallKernelLaunch(
         OMPRuntime->emitTargetNumIterationsCall(CGF, D, SizeEmitter);
     auto [DynCGroupMem, DynCGroupMemFallback] = emitDynCGroupMem(D, CGF);
     llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
-        CGF.AllocaInsertPt->getParent(), CGF.AllocaInsertPt->getIterator());
+        CGF.AllocaInsertPt->getIterator());
 
     llvm::OpenMPIRBuilder::TargetDataRTArgs RTArgs(
         BasePointersArray, PointersArray, SizesArray, MapTypesArray,
@@ -11967,8 +11965,7 @@ void CGOpenMPRuntime::emitTargetDataCalls(
       }
       break;
     }
-    return InsertPointTy(CGF.Builder.GetInsertBlock(),
-                         CGF.Builder.GetInsertPoint());
+    return InsertPointTy(CGF.Builder.GetInsertPoint());
   };
 
   auto DeviceAddrCB = [&](unsigned int I, llvm::Value *NewDecl) {
@@ -11990,10 +11987,8 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   // Source location for the ident struct
   llvm::Value *RTLoc = emitUpdateLocation(CGF, D.getBeginLoc());
 
-  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
-                         CGF.AllocaInsertPt->getIterator());
-  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
-                          CGF.Builder.GetInsertPoint());
+  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getIterator());
+  InsertPointTy CodeGenIP(CGF.Builder.GetInsertPoint());
   llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CGF.Builder);
   llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
       cantFail(OMPBuilder.createTargetData(
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 91c1a08fc7c8a74..190ff5d62fa189c 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1799,10 +1799,8 @@ void CGOpenMPRuntimeGPU::emitReduction(
   llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc);
 
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
-  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
-                         CGF.AllocaInsertPt->getIterator());
-  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
-                          CGF.Builder.GetInsertPoint());
+  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getIterator());
+  InsertPointTy CodeGenIP(CGF.Builder.GetInsertPoint());
   llvm::OpenMPIRBuilder::LocationDescription OmpLoc(
       CodeGenIP, CGF.SourceLocToDebugLoc(Loc));
   llvm::SmallVector<llvm::OpenMPIRBuilder::ReductionInfo, 2> ReductionInfos;
@@ -1862,8 +1860,7 @@ void CGOpenMPRuntimeGPU::emitReduction(
       CGF.Builder.SetCurrentDebugLocation(SavedDebugLoc);
       CGF.CurFn = CurFn;
 
-      return InsertPointTy(CGF.Builder.GetInsertBlock(),
-                           CGF.Builder.GetInsertPoint());
+      return CGF.Builder.GetInsertPoint();
     };
 
     // For the atomic fast path, hand this reduction an atomic combiner if it is
@@ -1894,12 +1891,11 @@ void CGOpenMPRuntimeGPU::emitReduction(
                               SSID](InsertPointTy IP, llvm::Type *EltTy,
                                     llvm::Value *LHS, llvm::Value *RHS)
             -> llvm::OpenMPIRBuilder::InsertPointOrErrorTy {
-          llvm::IRBuilder<> Builder(IP.getBlock(), IP.getPoint());
+          llvm::IRBuilder<> Builder(IP.getNodeParent(), IP);
           llvm::Value *Val = Builder.CreateLoad(EltTy, RHS);
           Builder.CreateAtomicRMW(Op, LHS, Val, Alignment,
                                   llvm::AtomicOrdering::Monotonic, SSID);
-          return InsertPointTy(Builder.GetInsertBlock(),
-                               Builder.GetInsertPoint());
+          return Builder.GetInsertPoint();
         };
       }
     }
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index b5e4b01109cb3c4..98aa20ee72d400b 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -2274,7 +2274,7 @@ void CodeGenFunction::OMPBuilderCBHelpers::EmitOMPInlinedRegionBody(
     CGF.EmitStmt(RegionBodyStmt);
   }
 
-  if (Builder.saveIP().isSet())
+  if (Builder.saveIP().isValid())
     Builder.CreateBr(FiniBB);
 }
 
@@ -2291,7 +2291,7 @@ void CodeGenFunction::OMPBuilderCBHelpers::EmitOMPOutlinedRegionBody(
     CGF.EmitStmt(RegionBodyStmt);
   }
 
-  if (Builder.saveIP().isSet())
+  if (Builder.saveIP().isValid())
     Builder.CreateBr(FiniBB);
 }
 
@@ -2348,7 +2348,7 @@ void CodeGenFunction::EmitOMPParallelDirective(const OMPParallelDirective &S) {
     CGCapturedStmtInfo CGSI(*CS, CR_OpenMP);
     CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(*this, &CGSI);
     llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
-        AllocaInsertPt->getParent(), AllocaInsertPt->getIterator());
+        AllocaInsertPt->getIterator());
     llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
         cantFail(OMPBuilder.createParallel(
             Builder, AllocaIP, /*DeallocBlocks=*/{}, BodyGenCB, PrivCB, FiniCB,
@@ -4670,7 +4670,7 @@ static void emitOMPForDirective(const OMPLoopDirective &S, CodeGenFunction &CGF,
       llvm::OpenMPIRBuilder &OMPBuilder =
           CGM.getOpenMPRuntime().getOMPBuilder();
       llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
-          CGF.AllocaInsertPt->getParent(), CGF.AllocaInsertPt->getIterator());
+          CGF.AllocaInsertPt->getIterator());
       cantFail(OMPBuilder.applyWorkshareLoop(
           CGF.Builder.getCurrentDebugLocation(), CLI, AllocaIP, NeedsBarrier,
           SchedKind, ChunkSize, /*HasSimdModifier=*/false,
@@ -4958,7 +4958,7 @@ void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) {
     CGCapturedStmtInfo CGSI(*ICS, CR_OpenMP);
     CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(*this, &CGSI);
     llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
-        AllocaInsertPt->getParent(), AllocaInsertPt->getIterator());
+        AllocaInsertPt->getIterator());
     llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
         cantFail(OMPBuilder.createSections(
             Builder, AllocaIP, SectionCBVector, PrivCB, FiniCB, S.hasCancel(),
@@ -6171,8 +6171,7 @@ void CodeGenFunction::EmitOMPTaskgroupDirective(
   if (CGM.getLangOpts().OpenMPIRBuilder && isSupportedByOpenMPIRBuilder(S)) {
     llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
     using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
-    InsertPointTy AllocaIP(AllocaInsertPt->getParent(),
-                           AllocaInsertPt->getIterator());
+    InsertPointTy AllocaIP(AllocaInsertPt->getIterator());
 
     auto BodyGenCB = [&, this](InsertPointTy AllocIP, InsertPointTy CodeGenIP,
                                ArrayRef<llvm::BasicBlock *> DeallocBlocks) {
@@ -6764,8 +6763,7 @@ void CodeGenFunction::EmitOMPOrderedStandaloneDirective(
     llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
     using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
 
-    InsertPointTy AllocaIP(AllocaInsertPt->getParent(),
-                           AllocaInsertPt->getIterator());
+    InsertPointTy AllocaIP(AllocaInsertPt->getIterator());
     for (const auto *DC : S.getClausesOfKind<OMPDependClause>())
       emitRestoreIP(*this, DC, AllocaIP, OMPBuilder);
     for (const auto *DC : S.getClausesOfKind<OMPDoacrossClause>())
@@ -6804,6 +6802,7 @@ void CodeGenFunction::EmitOMPOrderedBlockAssocDirective(
 
       const CapturedStmt *CS = S.getInnermostCapturedStmt();
       if (C) {
+        llvm::BasicBlock *CodeGenBB = CodeGenIP.getNodeParent();
         llvm::BasicBlock *FiniBB = splitBBWithSuffix(
             Builder, /*CreateBranch=*/false, ".ordered.after");
         llvm::SmallVector<llvm::Value *, 16> CapturedVars;
@@ -6812,7 +6811,7 @@ void CodeGenFunction::EmitOMPOrderedBlockAssocDirective(
         assert(S.getBeginLoc().isValid() &&
                "Outlined function call location must be valid.");
         ApplyDebugLocation::CreateDefaultArtificial(*this, S.getBeginLoc());
-        OMPBuilderCBHelpers::EmitCaptureStmt(*this, CodeGenIP, *FiniBB,
+        OMPBuilderCBHelpers::EmitCaptureStmt(*this, CodeGenBB->end(), *FiniBB,
                                              OutlinedFn, CapturedVars);
       } else {
         OMPBuilderCBHelpers::EmitOMPInlinedRegionBody(
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 9976a411fd67394..a35d153d238e928 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -2033,10 +2033,10 @@ class CodeGenFunction : public CodeGenTypeCache {
     /// \param IP	Insertion point for generating the finalization code.
     static void FinalizeOMPRegion(CodeGenFunction &CGF, InsertPointTy IP) {
       CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
-      assert(IP.getBlock()->end() != IP.getPoint() &&
+      llvm::BasicBlock *IPBB = IP.getNodeParent();
+      assert(IPBB->end() != IP &&
              "OpenMP IR Builder should cause terminated block!");
 
-      llvm::BasicBlock *IPBB = IP.getBlock();
       llvm::BasicBlock *DestBB = IPBB->getUniqueSuccessor();
       assert(DestBB && "Finalization block should have one successor!");
 
@@ -2063,7 +2063,7 @@ class CodeGenFunction : public CodeGenTypeCache {
     static void EmitCaptureStmt(CodeGenFunction &CGF, InsertPointTy CodeGenIP,
                                 llvm::BasicBlock &FiniBB, llvm::Function *Fn,
                                 ArrayRef<llvm::Value *> Args) {
-      llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
+      llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getNodeParent();
       if (llvm::Instruction *CodeGenIPBBTI = CodeGenIPBB->getTerminatorOrNull())
         CodeGenIPBBTI->eraseFromParent();
 
@@ -2074,7 +2074,7 @@ class CodeGenFunction : public CodeGenTypeCache {
       else
         CGF.EmitRuntimeCall(Fn, Args);
 
-      if (CGF.Builder.saveIP().isSet())
+      if (CGF.Builder.saveIP().isValid())
         CGF.Builder.CreateBr(&FiniBB);
     }
 
@@ -2103,10 +2103,10 @@ class CodeGenFunction : public CodeGenTypeCache {
       OutlinedRegionBodyRAII(CodeGenFunction &cgf, InsertPointTy &AllocaIP,
                              llvm::BasicBlock &RetBB)
           : CGF(cgf) {
-        assert(AllocaIP.isSet() &&
+        assert(AllocaIP.isValid() &&
                "Must specify Insertion point for allocas of outlined function");
         OldAllocaIP = CGF.AllocaInsertPt;
-        CGF.AllocaInsertPt = &*AllocaIP.getPoint();
+        CGF.AllocaInsertPt = &*AllocaIP;
 
         OldReturnBlock = CGF.ReturnBlock;
         CGF.ReturnBlock = CGF.getJumpDestInCurrentScope(&RetBB);
@@ -2132,13 +2132,13 @@ class CodeGenFunction : public CodeGenTypeCache {
         // function so it expects an empty AllocaIP in which case will reuse the
         // old alloca insertion point, or a new AllocaIP in the same block as
         // the old one
-        assert((!AllocaIP.isSet() ||
-                CGF.AllocaInsertPt->getParent() == AllocaIP.getBlock()) &&
+        assert((!AllocaIP.isValid() ||
+                CGF.AllocaInsertPt->getParent() == AllocaIP.getNodeParent()) &&
                "Insertion point should be in the entry block of containing "
                "function!");
         OldAllocaIP = CGF.AllocaInsertPt;
-        if (AllocaIP.isSet())
-          CGF.AllocaInsertPt = &*AllocaIP.getPoint();
+        if (AllocaIP.isValid())
+          CGF.AllocaInsertPt = &*AllocaIP;
 
         // TODO: Remove the call, after making sure the counter is not used by
         //       the EHStack.
diff --git a/llvm/include/llvm/ADT/ilist_iterator.h b/llvm/include/llvm/ADT/ilist_iterator.h
index 882df9d7e767f30..86aaaa3c4e8d69d 100644
--- a/llvm/include/llvm/ADT/ilist_iterator.h
+++ b/llvm/include/llvm/ADT/ilist_iterator.h
@@ -65,6 +65,9 @@ class iterator_parent_access<IteratorTy, ParentTy, true> {
 template <class IteratorTy, class ParentTy>
 class iterator_parent_access<IteratorTy, ParentTy, false> {
 public:
+  inline const ParentTy *getNodeParent() const {
+    return static_cast<const IteratorTy *>(this)->NodePtr->getParent();
+  }
   inline ParentTy *getNodeParent() {
     return static_cast<IteratorTy *>(this)->NodePtr->getParent();
   }
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index c92756092af3373..bcce28894b555df 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2531,7 +2531,7 @@ class OpenMPIRBuilder {
   bool updateToLocation(const LocationDescription &Loc) {
     Builder.restoreIP(Loc.IP);
     Builder.SetCurrentDebugLocation(Loc.DL);
-    return Loc.IP.getBlock() != nullptr;
+    return Loc.IP.isValid();
   }
 
   /// Return the function declaration for the runtime function with \p FnID.
@@ -2561,7 +2561,7 @@ class OpenMPIRBuilder {
   /// Return the (LLVM-IR) string describing the DebugLoc \p DL. Use \p F as
   /// fallback if \p DL does not specify the function name.
   LLVM_ABI Constant *getOrCreateSrcLocStr(DebugLoc DL, uint32_t &SrcLocStrSize,
-                                          Function *F = nullptr);
+                                          const Function *F = nullptr);
 
   /// Return the (LLVM-IR) string describing the source location \p Loc.
   LLVM_ABI Constant *getOrCreateSrcLocStr(const LocationDescription &Loc,
@@ -4616,21 +4616,21 @@ class CanonicalLoopInfo {
   OpenMPIRBuilder::InsertPointTy getPreheaderIP() const {
     assert(isValid() && "Requires a valid canonical loop");
     BasicBlock *Preheader = getPreheader();
-    return {Preheader, std::prev(Preheader->end())};
+    return std::prev(Preheader->end());
   };
 
   /// Return the insertion point for user code in the body.
   OpenMPIRBuilder::InsertPointTy getBodyIP() const {
     assert(isValid() && "Requires a valid canonical loop");
     BasicBlock *Body = getBody();
-    return {Body, Body->begin()};
+    return Body->begin();
   };
 
   /// Return the insertion point for user code after the loop.
   OpenMPIRBuilder::InsertPointTy getAfterIP() const {
     assert(isValid() && "Requires a valid canonical loop");
     BasicBlock *After = getAfter();
-    return {After, After->begin()};
+    return After->begin();
   };
 
   Function *getFunction() const {
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index aba9e8faa919d13..b350dca43d0fbf1 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -200,11 +200,12 @@ class IRBuilderBase {
   }
 
   /// This specifies that created instructions should be inserted at
-  /// the specified point, but also requires that \p IP is dereferencable.
+  /// the specified point.
   void SetInsertPoint(BasicBlock::iterator IP) {
-    BB = IP->getParent();
+    BB = IP.getNodeParent();
     InsertPt = IP;
-    SetCurrentDebugLocation(IP->getStableDebugLoc());
+    if (IP != BB->end())
+      SetCurrentDebugLocation(IP->getStableDebugLoc());
   }
 
   /// This specifies that created instructions should inserted at the beginning
@@ -241,41 +242,22 @@ class IRBuilderBase {
   LLVM_ABI Type *getCurrentFunctionReturnType() const;
 
   /// InsertPoint - A saved insertion point.
-  class InsertPoint {
-    BasicBlock *Block = nullptr;
-    BasicBlock::iterator Point;
-
-  public:
-    /// Creates a new insertion point which doesn't point to anything.
-    InsertPoint() = default;
-
-    /// Creates a new insertion point at the given location.
-    InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
-        : Block(InsertBlock), Point(InsertPoint) {}
-
-    /// Returns true if this insert point is set.
-    bool isSet() const { return (Block != nullptr); }
-
-    BasicBlock *getBlock() const { return Block; }
-    BasicBlock::iterator getPoint() const { return Point; }
-  };
+  using InsertPoint = BasicBlock::iterator;
 
   /// Returns the current insert point.
-  InsertPoint saveIP() const {
-    return InsertPoint(GetInsertBlock(), GetInsertPoint());
-  }
+  InsertPoint saveIP() const { return GetInsertPoint(); }
 
   /// Returns the current insert point, clearing it in the process.
   InsertPoint saveAndClearIP() {
-    InsertPoint IP(GetInsertBlock(), GetInsertPoint());
+    InsertPoint IP(GetInsertPoint());
     ClearInsertionPoint();
     return IP;
   }
 
   /// Sets the current insert point to a previously-saved location.
   void restoreIP(InsertPoint IP) {
-    if (IP.isSet())
-      SetInsertPoint(IP.getBlock(), IP.getPoint());
+    if (IP.isValid())
+      SetInsertPoint(IP);
     else
       ClearInsertionPoint();
   }
@@ -361,20 +343,19 @@ class IRBuilderBase {
   // when the object is destroyed. This includes the debug location.
   class InsertPointGuard {
     IRBuilderBase &Builder;
-    AssertingVH<BasicBlock> Block;
     BasicBlock::iterator Point;
     DebugLoc DbgLoc;
 
   public:
     InsertPointGuard(IRBuilderBase &B)
-        : Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
+        : Builder(B), Point(B.GetInsertPoint()),
           DbgLoc(B.getCurrentDebugLocation()) {}
 
     InsertPointGuard(const InsertPointGuard &) = delete;
     InsertPointGuard &operator=(const InsertPointGuard &) = delete;
 
     ~InsertPointGuard() {
-      Builder.restoreIP(InsertPoint(Block, Point));
+      Builder.restoreIP(InsertPoint(Point));
       Builder.SetCurrentDebugLocation(DbgLoc);
     }
   };
diff --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
index d0680373108352d..a7d02926652e239 100644
--- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
+++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
@@ -151,7 +151,6 @@ class SCEVExpander : public SCEVUseVisitor<SCEVExpander, Value *> {
   // expansion.
   class SCEVInsertPointGuard {
     IRBuilderBase &Builder;
-    AssertingVH<BasicBlock> Block;
     BasicBlock::iterator Point;
     DebugLoc DbgLoc;
     SCEVExpander *SE;
@@ -161,7 +160,7 @@ class SCEVExpander : public SCEVUseVisitor<SCEVExpander, Value *> {
 
   public:
     SCEVInsertPointGuard(IRBuilderBase &B, SCEVExpander *SE)
-        : Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
+        : Builder(B), Point(B.GetInsertPoint()),
           DbgLoc(B.getCurrentDebugLocation()), SE(SE) {
       SE->InsertPointGuards.push_back(this);
     }
@@ -172,7 +171,7 @@ class SCEVExpander : public SCEVUseVisitor<SCEVExpander, Value *> {
       // ScalarEvolutionExpander.
       assert(SE->InsertPointGuards.back() == this);
       SE->InsertPointGuards.pop_back();
-      Builder.restoreIP(IRBuilderBase::InsertPoint(Block, Point));
+      Builder.restoreIP(IRBuilderBase::InsertPoint(Point));
       Builder.SetCurrentDebugLocation(DbgLoc);
     }
 
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 3a8125b835e53df..439534095702df7 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -95,9 +95,9 @@ static cl::opt<bool> UseDefaultMaxThreads(
 /// creating instruction will cause the instructions to be interleaved.
 static bool isConflictIP(IRBuilder<>::InsertPoint IP1,
                          IRBuilder<>::InsertPoint IP2) {
-  if (!IP1.isSet() || !IP2.isSet())
+  if (!IP1.isValid() || !IP2.isValid())
     return false;
-  return IP1.getBlock() == IP2.getBlock() && IP1.getPoint() == IP2.getPoint();
+  return IP1 == IP2;
 }
 
 static bool isValidWorkshareLoopScheduleType(OMPScheduleType SchedType) {
@@ -376,7 +376,7 @@ void llvm::spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New,
          "Target BB must not have PHI nodes");
 
   // Move instructions to new block.
-  BasicBlock *Old = IP.getBlock();
+  BasicBlock *Old = IP.getNodeParent();
   // If the `Old` block is empty then there are no instructions to move. But in
   // the new debug scheme, it could have trailing debug records which will be
   // moved to `New` in `spliceDebugInfoEmptyBlock`. We dont want that for 2
@@ -389,7 +389,7 @@ void llvm::spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New,
   // added to it later in this function.
   // So we call `BasicBlock::splice` only when `Old` is not empty.
   if (!Old->empty())
-    New->splice(New->begin(), Old, IP.getPoint(), Old->end());
+    New->splice(New->begin(), Old, IP, Old->end());
 
   if (CreateBranch) {
     auto *NewBr = UncondBrInst::Create(New, Old);
@@ -414,7 +414,7 @@ void llvm::spliceBB(IRBuilder<> &Builder, BasicBlock *New, bool CreateBranch) {
 
 BasicBlock *llvm::splitBB(IRBuilderBase::InsertPoint IP, bool CreateBranch,
                           DebugLoc DL, llvm::Twine Name) {
-  BasicBlock *Old = IP.getBlock();
+  BasicBlock *Old = IP.getNodeParent();
   BasicBlock *New = BasicBlock::Create(
       Old->getContext(), Name.isTriviallyEmpty() ? Old->getName() : Name,
       Old->getParent(), Old->getNextNode());
@@ -1322,7 +1322,7 @@ OpenMPIRBuilder::getOrCreateDefaultSrcLocStr(uint32_t &SrcLocStrSize) {
 
 Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(DebugLoc DL,
                                                 uint32_t &SrcLocStrSize,
-                                                Function *F) {
+                                                const Function *F) {
   DILocation *DIL = DL.get();
   if (!DIL)
     return getOrCreateDefaultSrcLocStr(SrcLocStrSize);
@@ -1338,7 +1338,7 @@ Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(DebugLoc DL,
 Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(const LocationDescription &Loc,
                                                 uint32_t &SrcLocStrSize) {
   return getOrCreateSrcLocStr(Loc.DL, SrcLocStrSize,
-                              Loc.IP.getBlock()->getParent());
+                              Loc.IP.getNodeParent()->getParent());
 }
 
 Value *OpenMPIRBuilder::getOrCreateThreadID(Value *Ident) {
@@ -1987,7 +1987,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
 
   // Save the outer alloca block because the insertion iterator may get
   // invalidated and we still need this later.
-  BasicBlock *OuterAllocaBlock = OuterAllocIP.getBlock();
+  BasicBlock *OuterAllocaBlock = OuterAllocIP.getNodeParent();
 
   // Vector to remember instructions we used only during the modeling but which
   // we want to delete at the end.
@@ -1995,7 +1995,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
 
   // Change the location to the outer alloca insertion point to create and
   // initialize the allocas we pass into the parallel region.
-  InsertPointTy NewOuter(OuterAllocaBlock, OuterAllocaBlock->begin());
+  InsertPointTy NewOuter(OuterAllocaBlock->begin());
   Builder.restoreIP(NewOuter);
   AllocaInst *TIDAddrAlloca = Builder.CreateAlloca(Int32, nullptr, "tid.addr");
   AllocaInst *ZeroAddrAlloca =
@@ -2034,14 +2034,14 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
   auto FiniCBWrapper = [&](InsertPointTy IP) {
     // Hide "open-ended" blocks from the given FiniCB by setting the right jump
     // target to the region exit block.
-    if (IP.getBlock()->end() == IP.getPoint()) {
+    if (IP == IP.getNodeParent()->end()) {
       IRBuilder<>::InsertPointGuard IPG(Builder);
       Builder.restoreIP(IP);
       Instruction *I = Builder.CreateBr(PRegExitBB);
-      IP = InsertPointTy(I->getParent(), I->getIterator());
+      IP = I->getIterator();
     }
-    assert(IP.getBlock()->getTerminator()->getNumSuccessors() == 1 &&
-           IP.getBlock()->getTerminator()->getSuccessor(0) == PRegExitBB &&
+    assert(IP.getNodeParent()->getTerminator()->getNumSuccessors() == 1 &&
+           IP.getNodeParent()->getTerminator()->getSuccessor(0) == PRegExitBB &&
            "Unexpected insertion point for finalization call!");
     return FiniCB(IP);
   };
@@ -2082,7 +2082,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
 
   // Let the caller create the body.
   assert(BodyGenCB && "Expected body generation callback!");
-  InsertPointTy CodeGenIP(PRegBodyBB, PRegBodyBB->begin());
+  InsertPointTy CodeGenIP(PRegBodyBB->begin());
   if (Error Err = BodyGenCB(InnerAllocaIP, CodeGenIP, PRegExitBB))
     return Err;
 
@@ -2188,13 +2188,12 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
                                    V.getName() + ".reloaded");
         for (BasicBlock *DeallocBlock : OuterDeallocBlocks) {
           assert(DeallocBlock->getParent() ==
-                     OuterAllocIP.getBlock()->getParent() &&
+                     OuterAllocIP.getNodeParent()->getParent() &&
                  "Dealloc block must be in the allocation's function to reuse "
                  "its debug location");
-          createOMPFreeShared(
-              {InsertPointTy(DeallocBlock, DeallocBlock->getFirstInsertionPt()),
-               Builder.getCurrentDebugLocation()},
-              Ptr, V.getType());
+          createOMPFreeShared({DeallocBlock->getFirstInsertionPt(),
+                               Builder.getCurrentDebugLocation()},
+                              Ptr, V.getType());
         }
       } else {
         Ptr = Builder.CreateAlloca(V.getType(), nullptr,
@@ -2222,9 +2221,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
       if (!AfterIP)
         return AfterIP.takeError();
       Builder.restoreIP(*AfterIP);
-      InnerAllocaIP = {
-          InnerAllocaIP.getBlock(),
-          InnerAllocaIP.getBlock()->getTerminator()->getIterator()};
+      InnerAllocaIP =
+          InnerAllocaIP.getNodeParent()->getTerminator()->getIterator();
 
       assert(ReplacementValue &&
              "Expected copy/create callback to set replacement value!");
@@ -2244,13 +2242,11 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
   // that they are available in the generated body and so that the
   // OpenMP-related values (thread ID and zero address pointers) remain leading
   // in the argument list.
-  InnerAllocaIP = IRBuilder<>::InsertPoint(
-      ZeroAddrUse->getParent(), ZeroAddrUse->getNextNode()->getIterator());
+  InnerAllocaIP = ZeroAddrUse->getNextNode()->getIterator();
 
   // Reset the outer alloca insertion point to the entry of the relevant block
   // in case it was invalidated.
-  OuterAllocIP = IRBuilder<>::InsertPoint(
-      OuterAllocaBlock, OuterAllocaBlock->getFirstInsertionPt());
+  OuterAllocIP = OuterAllocaBlock->getFirstInsertionPt();
 
   for (Value *Input : Inputs) {
     LLVM_DEBUG(dbgs() << "Captured input: " << *Input << "\n");
@@ -2280,7 +2276,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
 
   Instruction *PRegPreFiniTI = PRegPreFiniBB->getTerminator();
 
-  InsertPointTy PreFiniIP(PRegPreFiniBB, PRegPreFiniTI->getIterator());
+  InsertPointTy PreFiniIP(PRegPreFiniTI->getIterator());
   Expected<BasicBlock *> FiniBBOrErr = FiniInfo.getFiniBB(Builder);
   if (!FiniBBOrErr)
     return FiniBBOrErr.takeError();
@@ -2297,7 +2293,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
   // Register the outlined info.
   addOutlineInfo(std::move(OI));
 
-  InsertPointTy AfterIP(UI->getParent(), UI->getParent()->end());
+  InsertPointTy AfterIP(UI->getParent()->end());
   UI->eraseFromParent();
 
   return AfterIP;
@@ -2544,8 +2540,7 @@ Expected<Value *> OpenMPIRBuilder::createTaskDuplicationFunction(
   DestTaskContextPtr->setName("destPtr");
   SrcTaskContextPtr->setName("srcPtr");
 
-  InsertPointTy AllocaIP(&DupFunction->getEntryBlock(),
-                         DupFunction->getEntryBlock().begin());
+  InsertPointTy AllocaIP(DupFunction->getEntryBlock().begin());
   InsertPointTy CodeGenIP = Builder.saveIP();
   Expected<IRBuilderBase::InsertPoint> AfterIPOrError =
       DupCB(AllocaIP, CodeGenIP, DestTaskContextPtr, SrcTaskContextPtr);
@@ -2581,10 +2576,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTaskloop(
   BasicBlock *TaskloopAllocaBB =
       splitBB(Builder, /*CreateBranch=*/true, "taskloop.alloca");
 
-  InsertPointTy TaskloopAllocaIP =
-      InsertPointTy(TaskloopAllocaBB, TaskloopAllocaBB->begin());
-  InsertPointTy TaskloopBodyIP =
-      InsertPointTy(TaskloopBodyBB, TaskloopBodyBB->begin());
+  InsertPointTy TaskloopAllocaIP = TaskloopAllocaBB->begin();
+  InsertPointTy TaskloopBodyIP = TaskloopBodyBB->begin();
 
   if (Error Err = BodyGenCB(TaskloopAllocaIP, TaskloopBodyIP, TaskloopExitBB))
     return Err;
@@ -2597,7 +2590,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTaskloop(
   llvm::CanonicalLoopInfo *CLI = result.get();
   auto OI = std::make_unique<OutlineInfo>();
   OI->EntryBB = TaskloopAllocaBB;
-  OI->OuterAllocBB = AllocaIP.getBlock();
+  OI->OuterAllocBB = AllocaIP.getNodeParent();
   OI->ExitBB = TaskloopExitBB;
   OI->OuterDeallocBBs.reserve(DeallocBlocks.size());
   copy(DeallocBlocks, OI->OuterDeallocBBs.end());
@@ -2947,15 +2940,14 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask(
   BasicBlock *TaskAllocaBB =
       splitBB(Builder, /*CreateBranch=*/true, "task.alloca");
 
-  InsertPointTy TaskAllocaIP =
-      InsertPointTy(TaskAllocaBB, TaskAllocaBB->begin());
-  InsertPointTy TaskBodyIP = InsertPointTy(TaskBodyBB, TaskBodyBB->begin());
+  InsertPointTy TaskAllocaIP = TaskAllocaBB->begin();
+  InsertPointTy TaskBodyIP = TaskBodyBB->begin();
   if (Error Err = BodyGenCB(TaskAllocaIP, TaskBodyIP, TaskExitBB))
     return Err;
 
   auto OI = std::make_unique<OutlineInfo>();
   OI->EntryBB = TaskAllocaBB;
-  OI->OuterAllocBB = AllocaIP.getBlock();
+  OI->OuterAllocBB = AllocaIP.getNodeParent();
   OI->ExitBB = TaskExitBB;
   OI->OuterDeallocBBs.reserve(DeallocBlocks.size());
   copy(DeallocBlocks, OI->OuterDeallocBBs.end());
@@ -3280,9 +3272,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createSections(
       SwitchStmt->addCase(Builder.getInt32(CaseNumber), CaseBB);
       Builder.SetInsertPoint(CaseBB);
       UncondBrInst *CaseEndBr = Builder.CreateBr(Continue);
-      if (Error Err =
-              SectionCB(InsertPointTy(),
-                        {CaseEndBr->getParent(), CaseEndBr->getIterator()}, {}))
+      if (Error Err = SectionCB(InsertPointTy(), CaseEndBr->getIterator(), {}))
         return Err;
       CaseNumber++;
     }
@@ -3308,7 +3298,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createSections(
     return WsloopIP.takeError();
   InsertPointTy AfterIP = *WsloopIP;
 
-  BasicBlock *LoopFini = AfterIP.getBlock()->getSinglePredecessor();
+  BasicBlock *LoopFini = AfterIP.getNodeParent()->getSinglePredecessor();
   assert(LoopFini && "Bad structure of static workshare loop finalization");
 
   // Apply the finalization callback in LoopAfterBB
@@ -3329,7 +3319,7 @@ OpenMPIRBuilder::createSection(const LocationDescription &Loc,
     return Loc.IP;
 
   auto FiniCBWrapper = [&](InsertPointTy IP) {
-    if (IP.getBlock()->end() != IP.getPoint())
+    if (IP != IP.getNodeParent()->end())
       return FiniCB(IP);
     // This must be done otherwise any nested constructs using FinalizeOMPRegion
     // will fail because that function requires the Finalization Basic Block to
@@ -3340,11 +3330,11 @@ OpenMPIRBuilder::createSection(const LocationDescription &Loc,
     // to exit block.
     IRBuilder<>::InsertPointGuard IPG(Builder);
     Builder.restoreIP(IP);
-    auto *CaseBB = Loc.IP.getBlock();
+    auto *CaseBB = Loc.IP.getNodeParent();
     auto *CondBB = CaseBB->getSinglePredecessor()->getSinglePredecessor();
     auto *ExitBB = CondBB->getTerminator()->getSuccessor(1);
     Instruction *I = Builder.CreateBr(ExitBB);
-    IP = InsertPointTy(I->getParent(), I->getIterator());
+    IP = I->getIterator();
     return FiniCB(IP);
   };
 
@@ -3359,7 +3349,7 @@ OpenMPIRBuilder::createSection(const LocationDescription &Loc,
 static OpenMPIRBuilder::InsertPointTy getInsertPointAfterInstr(Instruction *I) {
   BasicBlock::iterator IT(I);
   IT++;
-  return OpenMPIRBuilder::InsertPointTy(I->getParent(), IT);
+  return IT;
 }
 
 Value *OpenMPIRBuilder::getGPUThreadID() {
@@ -3748,9 +3738,7 @@ Expected<Function *> OpenMPIRBuilder::emitInterWarpCopyFunction(
   // nvptx_warp_id = nvptx_id / warpsize
   Value *WarpID = getNVPTXWarpID();
 
-  InsertPointTy AllocaIP =
-      InsertPointTy(Builder.GetInsertBlock(),
-                    Builder.GetInsertBlock()->getFirstInsertionPt());
+  InsertPointTy AllocaIP = Builder.GetInsertBlock()->getFirstInsertionPt();
   Type *Arg0Type = ReduceListArg->getType();
   Type *Arg1Type = NumWarpsArg->getType();
   Builder.restoreIP(AllocaIP);
@@ -4356,7 +4344,7 @@ Expected<Function *> OpenMPIRBuilder::emitListToGlobalReduceFunction(
   Value *LocalReduceList =
       Builder.CreateAlloca(RedListArrayTy, nullptr, ".omp.reduction.red_list");
 
-  InsertPointTy AllocaIP{EntryBlock, EntryBlock->begin()};
+  InsertPointTy AllocaIP(EntryBlock->begin());
 
   Value *BufferArgAddrCast = Builder.CreatePointerBitCastOrAddrSpaceCast(
       BufferArgAlloca, Builder.getPtrTy(),
@@ -4587,7 +4575,7 @@ Expected<Function *> OpenMPIRBuilder::emitGlobalToListReduceFunction(
   Value *LocalReduceList =
       Builder.CreateAlloca(RedListArrayTy, nullptr, ".omp.reduction.red_list");
 
-  InsertPointTy AllocaIP{EntryBlock, EntryBlock->begin()};
+  InsertPointTy AllocaIP(EntryBlock->begin());
 
   Value *BufferArgAddrCast = Builder.CreatePointerBitCastOrAddrSpaceCast(
       BufferArgAlloca, Builder.getPtrTy(),
@@ -4837,9 +4825,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductionsGPU(
   BasicBlock *ContinuationBlock = nullptr;
   if (ReductionGenCBKind != ReductionGenCBKind::Clang) {
     // Copied code from createReductions
-    BasicBlock *InsertBlock = Loc.IP.getBlock();
-    ContinuationBlock =
-        InsertBlock->splitBasicBlock(Loc.IP.getPoint(), "reduce.finalize");
+    BasicBlock *InsertBlock = const_cast<BasicBlock *>(Loc.IP.getNodeParent());
+    ContinuationBlock = InsertBlock->splitBasicBlock(Loc.IP, "reduce.finalize");
     InsertBlock->getTerminator()->eraseFromParent();
     Builder.SetInsertPoint(InsertBlock, InsertBlock->end());
   }
@@ -5280,16 +5267,16 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductions(
   if (ReductionInfos.size() == 0)
     return Builder.saveIP();
 
-  BasicBlock *InsertBlock = Loc.IP.getBlock();
+  BasicBlock *InsertBlock = const_cast<BasicBlock *>(Loc.IP.getNodeParent());
   BasicBlock *ContinuationBlock =
-      InsertBlock->splitBasicBlock(Loc.IP.getPoint(), "reduce.finalize");
+      InsertBlock->splitBasicBlock(Loc.IP, "reduce.finalize");
   InsertBlock->getTerminator()->eraseFromParent();
 
   // Create and populate array of type-erased pointers to private reduction
   // values.
   unsigned NumReductions = ReductionInfos.size();
   Type *RedArrayTy = ArrayType::get(Builder.getPtrTy(), NumReductions);
-  Builder.SetInsertPoint(AllocaIP.getBlock()->getTerminator());
+  Builder.SetInsertPoint(AllocaIP.getNodeParent()->getTerminator());
   Value *RedArray = Builder.CreateAlloca(RedArrayTy, nullptr, "red.array");
 
   Builder.SetInsertPoint(InsertBlock, InsertBlock->end());
@@ -5893,7 +5880,7 @@ Expected<CanonicalLoopInfo *>
 OpenMPIRBuilder::createCanonicalLoop(const LocationDescription &Loc,
                                      LoopBodyGenCallbackTy BodyGenCB,
                                      Value *TripCount, const Twine &Name) {
-  BasicBlock *BB = Loc.IP.getBlock();
+  BasicBlock *BB = const_cast<BasicBlock *>(Loc.IP.getNodeParent());
   BasicBlock *NextBB = BB->getNextNode();
 
   CanonicalLoopInfo *CL = createLoopSkeleton(Loc.DL, TripCount, BB->getParent(),
@@ -5932,7 +5919,7 @@ OpenMPIRBuilder::createCanonicalScanLoops(
     Value *Start, Value *Stop, Value *Step, bool IsSigned, bool InclusiveStop,
     InsertPointTy ComputeIP, const Twine &Name, ScanInfo *ScanRedInfo) {
   LocationDescription ComputeLoc =
-      ComputeIP.isSet() ? LocationDescription(ComputeIP, Loc.DL) : Loc;
+      ComputeIP.isValid() ? LocationDescription(ComputeIP, Loc.DL) : Loc;
   updateToLocation(ComputeLoc);
 
   SmallVector<CanonicalLoopInfo *> Result;
@@ -6056,7 +6043,7 @@ Expected<CanonicalLoopInfo *> OpenMPIRBuilder::createCanonicalLoop(
     InsertPointTy ComputeIP, const Twine &Name, bool InScan,
     ScanInfo *ScanRedInfo) {
   LocationDescription ComputeLoc =
-      ComputeIP.isSet() ? LocationDescription(ComputeIP, Loc.DL) : Loc;
+      ComputeIP.isValid() ? LocationDescription(ComputeIP, Loc.DL) : Loc;
 
   Value *TripCount = calculateCanonicalLoopTripCount(
       ComputeLoc, Start, Stop, Step, IsSigned, InclusiveStop, Name);
@@ -6072,7 +6059,7 @@ Expected<CanonicalLoopInfo *> OpenMPIRBuilder::createCanonicalLoop(
     return BodyGenCB(Builder.saveIP(), IndVar);
   };
   LocationDescription LoopLoc =
-      ComputeIP.isSet()
+      ComputeIP.isValid()
           ? Loc
           : LocationDescription(Builder.saveIP(),
                                 Builder.getCurrentDebugLocation());
@@ -6151,7 +6138,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::applyStaticWorkshareLoop(
       getOrCreateRuntimeFunction(M, omp::OMPRTL___kmpc_for_static_fini);
 
   // Allocate space for computed loop bounds as expected by the "init" function.
-  Builder.SetInsertPoint(AllocaIP.getBlock()->getFirstNonPHIOrDbgOrAlloca());
+  Builder.SetInsertPoint(
+      AllocaIP.getNodeParent()->getFirstNonPHIOrDbgOrAlloca());
 
   Type *I32Type = Type::getInt32Ty(M.getContext());
   Value *PLastIter = Builder.CreateAlloca(I32Type, nullptr, "p.lastiter");
@@ -6478,7 +6466,7 @@ OpenMPIRBuilder::applyStaticChunkedWorkshareLoop(
   CLI->assertOK();
 #endif
 
-  return InsertPointTy(DispatchAfter, DispatchAfter->getFirstInsertionPt());
+  return DispatchAfter->getFirstInsertionPt();
 }
 
 // Returns an LLVM function to call for executing an OpenMP static worksharing
@@ -6541,13 +6529,13 @@ static void createTargetLoopWorkshareCall(OpenMPIRBuilder *OMPBuilder,
   if (LoopType == WorksharingLoopType::DistributeStaticLoop) {
     RealArgs.push_back(ConstantInt::get(TripCountTy, 0));
     RealArgs.push_back(ConstantInt::get(Builder.getInt8Ty(), 0));
-    Builder.restoreIP({InsertBlock, std::prev(InsertBlock->end())});
+    Builder.restoreIP(std::prev(InsertBlock->end()));
     OMPBuilder->createRuntimeFunctionCall(RTLFn, RealArgs);
     return;
   }
   FunctionCallee RTLNumThreads = OMPBuilder->getOrCreateRuntimeFunction(
       M, omp::RuntimeFunction::OMPRTL_omp_get_num_threads);
-  Builder.restoreIP({InsertBlock, std::prev(InsertBlock->end())});
+  Builder.restoreIP(std::prev(InsertBlock->end()));
   Value *NumThreads = OMPBuilder->createRuntimeFunctionCall(RTLNumThreads, {});
 
   RealArgs.push_back(
@@ -6581,7 +6569,7 @@ static void workshareLoopTargetCallback(
   // The next step is to remove the whole loop. We do not it need anymore.
   // That's why make an unconditional branch from loop preheader to loop
   // exit block
-  Builder.restoreIP({Preheader, Preheader->end()});
+  Builder.restoreIP(Preheader->end());
   Builder.SetCurrentDebugLocation(Preheader->getTerminator()->getDebugLoc());
   Preheader->getTerminator()->eraseFromParent();
   Builder.CreateBr(CLI->getExit());
@@ -6646,7 +6634,7 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::applyWorkshareLoopTarget(
   // Instructions which need to be deleted at the end of code generation
   SmallVector<Instruction *, 4> ToBeDeleted;
 
-  OI->OuterAllocBB = AllocaIP.getBlock();
+  OI->OuterAllocBB = AllocaIP.getNodeParent();
 
   // Mark the body loop as region which needs to be extracted
   OI->EntryBB = CLI->getBody();
@@ -6654,7 +6642,7 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::applyWorkshareLoopTarget(
                                                       "omp.prelatch");
 
   // Prepare loop body for extraction
-  Builder.restoreIP({CLI->getPreheader(), CLI->getPreheader()->begin()});
+  Builder.restoreIP(CLI->getPreheader()->begin());
 
   // Insert new loop counter variable which will be used only in loop
   // body.
@@ -6870,7 +6858,8 @@ OpenMPIRBuilder::applyDynamicWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI,
   FunctionCallee DynamicNext = getKmpcForDynamicNextForType(IVTy, M, *this);
 
   // Allocate space for computed loop bounds as expected by the "init" function.
-  Builder.SetInsertPoint(AllocaIP.getBlock()->getFirstNonPHIOrDbgOrAlloca());
+  Builder.SetInsertPoint(
+      AllocaIP.getNodeParent()->getFirstNonPHIOrDbgOrAlloca());
   Type *I32Type = Type::getInt32Ty(M.getContext());
   Value *PLastIter = Builder.CreateAlloca(I32Type, nullptr, "p.lastiter");
   Value *PLowerBound = Builder.CreateAlloca(IVTy, nullptr, "p.lowerbound");
@@ -7042,7 +7031,7 @@ OpenMPIRBuilder::collapseLoops(DebugLoc DL, ArrayRef<CanonicalLoopInfo *> Loops,
 
   // Setup the IRBuilder for inserting the trip count computation.
   Builder.SetCurrentDebugLocation(DL);
-  if (ComputeIP.isSet())
+  if (ComputeIP.isValid())
     Builder.restoreIP(ComputeIP);
   else
     Builder.restoreIP(Outermost->getPreheaderIP());
@@ -7553,7 +7542,7 @@ void OpenMPIRBuilder::createIfVersion(CanonicalLoopInfo *CanonicalLoop,
   Builder.SetInsertPoint(SplitBeforeIt);
   Instruction *BrInstr =
       Builder.CreateCondBr(IfCond, ThenBlock, /*ifFalse*/ ElseBlock);
-  InsertPointTy IP{BrInstr->getParent(), ++BrInstr->getIterator()};
+  InsertPointTy IP(++BrInstr->getIterator());
   // Then block contains branch to omp loop body which needs to be vectorized
   spliceBB(IP, ThenBlock, false, Builder.getCurrentDebugLocation());
   ThenBlock->replaceSuccessorsPhiUsesWith(Cond, ThenBlock);
@@ -8223,7 +8212,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::EmitOMPInlinedRegion(
     return Err;
 
   // emit exit call and do any needed finalization.
-  auto FinIP = InsertPointTy(FiniBB, FiniBB->getFirstInsertionPt());
+  auto FinIP = FiniBB->getFirstInsertionPt();
   assert(FiniBB->getTerminator()->getNumSuccessors() == 1 &&
          FiniBB->getTerminator()->getSuccessor(0) == ExitBB &&
          "Unexpected control flow graph state!!");
@@ -8273,7 +8262,7 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitCommonDirectiveEntry(
   Builder.SetInsertPoint(ThenBB->getTerminator());
 
   // return an insertion point to ExitBB.
-  return IRBuilder<>::InsertPoint(ExitBB, ExitBB->getFirstInsertionPt());
+  return ExitBB->getFirstInsertionPt();
 }
 
 OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitCommonDirectiveExit(
@@ -8290,12 +8279,12 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitCommonDirectiveExit(
     FinalizationInfo Fi = FinalizationStack.pop_back_val();
     assert(Fi.DK == OMPD && "Unexpected Directive for Finalization call!");
 
-    if (Error Err = Fi.mergeFiniBB(Builder, FinIP.getBlock()))
+    if (Error Err = Fi.mergeFiniBB(Builder, FinIP.getNodeParent()))
       return std::move(Err);
 
     // Exit condition: insertion point is before the terminator of the new Fini
     // block
-    Builder.SetInsertPoint(FinIP.getBlock()->getTerminator());
+    Builder.SetInsertPoint(FinIP.getNodeParent()->getTerminator());
   }
 
   if (!ExitCall)
@@ -8305,14 +8294,13 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitCommonDirectiveExit(
   ExitCall->removeFromParent();
   Builder.Insert(ExitCall);
 
-  return IRBuilder<>::InsertPoint(ExitCall->getParent(),
-                                  ExitCall->getIterator());
+  return ExitCall->getIterator();
 }
 
 OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createCopyinClauseBlocks(
     InsertPointTy IP, Value *MasterAddr, Value *PrivateAddr,
     llvm::IntegerType *IntPtrTy, bool BranchtoEnd) {
-  if (!IP.isSet())
+  if (!IP.isValid())
     return IP;
 
   IRBuilder<>::InsertPointGuard IPG(Builder);
@@ -8329,7 +8317,7 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createCopyinClauseBlocks(
   //         v
   //   OMP.Entry.Next
 
-  BasicBlock *OMP_Entry = IP.getBlock();
+  BasicBlock *OMP_Entry = IP.getNodeParent();
   Function *CurFn = OMP_Entry->getParent();
   BasicBlock *CopyBegin =
       BasicBlock::Create(M.getContext(), "copyin.not.master", CurFn);
@@ -8738,7 +8726,7 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit(
 
   // Continue in the "user_code" block, see diagram above and in
   // openmp/libomptarget/deviceRTLs/common/include/target.h .
-  return InsertPointTy(UserCodeEntryBB, UserCodeEntryBB->getFirstInsertionPt());
+  return UserCodeEntryBB->getFirstInsertionPt();
 }
 
 void OpenMPIRBuilder::createTargetDeinit(const LocationDescription &Loc,
@@ -9356,10 +9344,8 @@ static Expected<Function *> createOutlinedFunction(
   BasicBlock *ExitBB = splitBB(Builder, /*CreateBranch=*/true, "target.exit");
   BasicBlock *OutlinedBodyBB =
       splitBB(Builder, /*CreateBranch=*/true, "outlined.body");
-  llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = CBFunc(
-      Builder.saveIP(),
-      OpenMPIRBuilder::InsertPointTy(OutlinedBodyBB, OutlinedBodyBB->begin()),
-      ExitBB);
+  llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+      CBFunc(Builder.saveIP(), OutlinedBodyBB->begin(), ExitBB);
   if (!AfterIP)
     return AfterIP.takeError();
   Builder.SetInsertPoint(ExitBB);
@@ -9431,8 +9417,7 @@ static Expected<Function *> createOutlinedFunction(
     Value *InputCopy = nullptr;
 
     llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = ArgAccessorFuncCB(
-        Arg, Input, InputCopy, AllocaIP, Builder.saveIP(),
-        OpenMPIRBuilder::InsertPointTy(ExitBB, ExitBB->begin()));
+        Arg, Input, InputCopy, AllocaIP, Builder.saveIP(), ExitBB->begin());
     if (!AfterIP)
       return AfterIP.takeError();
     Builder.restoreIP(*AfterIP);
@@ -9547,9 +9532,6 @@ static Function *emitTargetTaskProxyFunction(
   // OR
   //
   // call void @_QQmain..omp_par.1(i32 %global.tid.val6)
-  OpenMPIRBuilder::InsertPointTy IP(StaleCI->getParent(),
-                                    StaleCI->getIterator());
-
   LLVMContext &Ctx = StaleCI->getParent()->getContext();
 
   Type *ThreadIDTy = Type::getInt32Ty(Ctx);
@@ -9819,13 +9801,12 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask(
   BasicBlock *TargetTaskAllocaBB =
       splitBB(Builder, /*CreateBranch=*/true, "target.task.alloca");
 
-  InsertPointTy TargetTaskAllocaIP(TargetTaskAllocaBB,
-                                   TargetTaskAllocaBB->begin());
-  InsertPointTy TargetTaskBodyIP(TargetTaskBodyBB, TargetTaskBodyBB->begin());
+  InsertPointTy TargetTaskAllocaIP(TargetTaskAllocaBB->begin());
+  InsertPointTy TargetTaskBodyIP(TargetTaskBodyBB->begin());
 
   auto OI = std::make_unique<OutlineInfo>();
   OI->EntryBB = TargetTaskAllocaBB;
-  OI->OuterAllocBB = AllocaIP.getBlock();
+  OI->OuterAllocBB = AllocaIP.getNodeParent();
 
   // Add the thread ID argument.
   SmallVector<Instruction *, 4> ToBeDeleted;
@@ -12179,8 +12160,8 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
          ThreadLimitInt32});
   }
   // Generate the body of teams.
-  InsertPointTy AllocaIP(AllocaBB, AllocaBB->begin());
-  InsertPointTy CodeGenIP(BodyBB, BodyBB->begin());
+  InsertPointTy AllocaIP(AllocaBB->begin());
+  InsertPointTy CodeGenIP(BodyBB->begin());
   if (Error Err = BodyGenCB(AllocaIP, CodeGenIP, ExitBB))
     return Err;
 
@@ -12191,7 +12172,7 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
 
   // Insert fake values for global tid and bound tid.
   SmallVector<Instruction *, 8> ToBeDeleted;
-  InsertPointTy OuterAllocaIP(&OuterAllocaBB, OuterAllocaBB.begin());
+  InsertPointTy OuterAllocaIP(OuterAllocaBB.begin());
   OI->ExcludeArgsFromAggregate.push_back(createFakeIntVal(
       Builder, OuterAllocaIP, ToBeDeleted, AllocaIP, "gid", true));
   OI->ExcludeArgsFromAggregate.push_back(createFakeIntVal(
@@ -12251,7 +12232,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createDistribute(
   if (!updateToLocation(Loc))
     return InsertPointTy();
 
-  BasicBlock *OuterAllocaBB = OuterAllocIP.getBlock();
+  BasicBlock *OuterAllocaBB = OuterAllocIP.getNodeParent();
 
   if (OuterAllocaBB == Builder.GetInsertBlock()) {
     BasicBlock *BodyBB =
@@ -12266,8 +12247,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createDistribute(
       splitBB(Builder, /*CreateBranch=*/true, "distribute.alloca");
 
   // Generate the body of distribute clause
-  InsertPointTy AllocaIP(AllocaBB, AllocaBB->begin());
-  InsertPointTy CodeGenIP(BodyBB, BodyBB->begin());
+  InsertPointTy AllocaIP(AllocaBB->begin());
+  InsertPointTy CodeGenIP(BodyBB->begin());
   if (Error Err = BodyGenCB(AllocaIP, CodeGenIP, ExitBB))
     return Err;
 
@@ -12275,7 +12256,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createDistribute(
   // callback.
   if (Config.isTargetDevice()) {
     auto OI = std::make_unique<OutlineInfo>();
-    OI->OuterAllocBB = OuterAllocIP.getBlock();
+    OI->OuterAllocBB = OuterAllocIP.getNodeParent();
     OI->EntryBB = AllocaBB;
     OI->ExitBB = ExitBB;
     OI->OuterDeallocBBs.reserve(OuterDeallocBlocks.size());
@@ -12875,9 +12856,9 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createIteratorLoop(
   Function *F = CurBB->getParent();
 
   InsertPointTy SplitIP = Builder.saveIP();
-  if (SplitIP.getPoint() == CurBB->end())
+  if (SplitIP == CurBB->end())
     if (Instruction *Terminator = CurBB->getTerminatorOrNull())
-      SplitIP = InsertPointTy(CurBB, Terminator->getIterator());
+      SplitIP = Terminator->getIterator();
 
   BasicBlock *ContBB =
       splitBB(SplitIP, /*CreateBranch=*/false,
@@ -12919,7 +12900,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createIteratorLoop(
   if (!CLI->getAfter()->hasTerminator())
     Builder.CreateBr(ContBB);
 
-  return InsertPointTy{ContBB, ContBB->begin()};
+  return ContBB->begin();
 }
 
 /// Mangle the parameter part of the vector function name according to
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 7bf628ce27fa88b..6f270eb27fc0b3c 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -1162,9 +1162,8 @@ struct OpenMPOpt {
     BasicBlock *StartBB = nullptr, *EndBB = nullptr;
     auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                          ArrayRef<BasicBlock *> DeallocBlocks) {
-      BasicBlock *CGStartBB = CodeGenIP.getBlock();
-      BasicBlock *CGEndBB =
-          SplitBlock(CGStartBB, &*CodeGenIP.getPoint(), DT, LI);
+      BasicBlock *CGStartBB = CodeGenIP.getNodeParent();
+      BasicBlock *CGEndBB = SplitBlock(CGStartBB, &*CodeGenIP, DT, LI);
       assert(StartBB != nullptr && "StartBB should not be null");
       CGStartBB->getTerminator()->setSuccessor(0, StartBB);
       assert(EndBB != nullptr && "EndBB should not be null");
@@ -1203,9 +1202,8 @@ struct OpenMPOpt {
 
       auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                            ArrayRef<BasicBlock *> DeallocBlocks) {
-        BasicBlock *CGStartBB = CodeGenIP.getBlock();
-        BasicBlock *CGEndBB =
-            SplitBlock(CGStartBB, &*CodeGenIP.getPoint(), DT, LI);
+        BasicBlock *CGStartBB = CodeGenIP.getNodeParent();
+        BasicBlock *CGEndBB = SplitBlock(CGStartBB, &*CodeGenIP, DT, LI);
         assert(SeqStartBB != nullptr && "SeqStartBB should not be null");
         CGStartBB->getTerminator()->setSuccessor(0, SeqStartBB);
         assert(SeqEndBB != nullptr && "SeqEndBB should not be null");
@@ -1253,14 +1251,13 @@ struct OpenMPOpt {
         }
       }
 
-      OpenMPIRBuilder::LocationDescription Loc(
-          InsertPointTy(ParentBB, ParentBB->end()), DL);
+      OpenMPIRBuilder::LocationDescription Loc(ParentBB->end(), DL);
       OpenMPIRBuilder::InsertPointTy SeqAfterIP = cantFail(
           OMPInfoCache.OMPBuilder.createMaster(Loc, BodyGenCB, FiniCB));
       cantFail(OMPInfoCache.OMPBuilder.createBarrier({SeqAfterIP, DL},
                                                      OMPD_parallel));
 
-      UncondBrInst::Create(SeqAfterBB, SeqAfterIP.getBlock());
+      UncondBrInst::Create(SeqAfterBB, SeqAfterIP.getNodeParent());
 
       LLVM_DEBUG(dbgs() << TAG << "After sequential inlining " << *OuterFn
                         << "\n");
@@ -1323,10 +1320,8 @@ struct OpenMPOpt {
                                NextForkCI->getPrevNode());
       }
 
-      OpenMPIRBuilder::LocationDescription Loc(InsertPointTy(BB, BB->end()),
-                                               DL);
+      OpenMPIRBuilder::LocationDescription Loc(BB->end(), DL);
       IRBuilder<>::InsertPoint AllocaIP(
-          &OriginalFn->getEntryBlock(),
           OriginalFn->getEntryBlock().getFirstInsertionPt());
       // Create the merged parallel region with default proc binding, to
       // avoid overriding binding settings, and without explicit cancellation.
@@ -1335,7 +1330,7 @@ struct OpenMPOpt {
               Loc, AllocaIP, /* DeallocBlocks */ {}, BodyGenCB, PrivCB, FiniCB,
               nullptr, nullptr, OMP_PROC_BIND_default,
               /* IsCancellable */ false));
-      UncondBrInst::Create(AfterBB, AfterIP.getBlock());
+      UncondBrInst::Create(AfterBB, AfterIP.getNodeParent());
 
       // Perform the actual outlining.
       OMPInfoCache.OMPBuilder.finalize(OriginalFn);
@@ -1372,9 +1367,7 @@ struct OpenMPOpt {
           // TODO: Remove barrier if the merged parallel region includes the
           // 'nowait' clause.
           cantFail(OMPInfoCache.OMPBuilder.createBarrier(
-              {InsertPointTy(NewCI->getParent(),
-                             NewCI->getNextNode()->getIterator()),
-               NewCI->getDebugLoc()},
+              {NewCI->getNextNode()->getIterator(), NewCI->getDebugLoc()},
               OMPD_parallel));
         }
 
@@ -1880,11 +1873,9 @@ struct OpenMPOpt {
       // The IRBuilder uses the insertion block to get to the module, this is
       // unfortunate but we work around it for now. No instruction is emitted
       // here, so there is no debug location to preserve.
-      if (!OMPInfoCache.OMPBuilder.getInsertionPoint().getBlock())
+      if (!OMPInfoCache.OMPBuilder.getInsertionPoint().isValid())
         OMPInfoCache.OMPBuilder.updateToLocation(
-            {OpenMPIRBuilder::InsertPointTy(&F.getEntryBlock(),
-                                            F.getEntryBlock().begin()),
-             DebugLoc()});
+            {F.getEntryBlock().begin(), DebugLoc()});
       // Create a fallback location if non was found.
       // TODO: Use the debug locations of the calls instead.
       uint32_t SrcLocStrSize;
@@ -4082,7 +4073,6 @@ struct AAKernelInfoFunction : AAKernelInfo {
       LoopInfo *LI = nullptr;
       DominatorTree *DT = nullptr;
       MemorySSAUpdater *MSU = nullptr;
-      using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
 
       BasicBlock *ParentBB = RegionStartI->getParent();
       Function *Fn = ParentBB->getParent();
@@ -4178,8 +4168,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
       // Go to tid check BB in ParentBB.
       const DebugLoc DL = ParentBB->getTerminator()->getDebugLoc();
       ParentBB->getTerminator()->eraseFromParent();
-      OpenMPIRBuilder::LocationDescription Loc(
-          InsertPointTy(ParentBB, ParentBB->end()), DL);
+      OpenMPIRBuilder::LocationDescription Loc(ParentBB->end(), DL);
       OMPInfoCache.OMPBuilder.updateToLocation(Loc);
       uint32_t SrcLocStrSize;
       auto *SrcLocStr =
@@ -4191,7 +4180,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
       // Add check for Tid in RegionCheckTidBB
       RegionCheckTidBB->getTerminator()->eraseFromParent();
       OpenMPIRBuilder::LocationDescription LocRegionCheckTid(
-          InsertPointTy(RegionCheckTidBB, RegionCheckTidBB->end()), DL);
+          RegionCheckTidBB->end(), DL);
       OMPInfoCache.OMPBuilder.updateToLocation(LocRegionCheckTid);
       FunctionCallee HardwareTidFn =
           OMPInfoCache.OMPBuilder.getOrCreateRuntimeFunction(
@@ -4211,9 +4200,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
           OMPInfoCache.OMPBuilder.getOrCreateRuntimeFunction(
               M, OMPRTL___kmpc_barrier_simple_spmd);
       OMPInfoCache.OMPBuilder.updateToLocation(
-          {InsertPointTy(RegionBarrierBB,
-                         RegionBarrierBB->getFirstInsertionPt()),
-           DL});
+          {RegionBarrierBB->getFirstInsertionPt(), DL});
       CallInst *Barrier =
           OMPInfoCache.OMPBuilder.Builder.CreateCall(BarrierFn, {Ident, Tid});
       OMPInfoCache.setCallingConvention(BarrierFn, Barrier);
@@ -4622,10 +4609,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
     WorkFnAI->setDebugLoc(DLoc);
 
     OMPInfoCache.OMPBuilder.updateToLocation(
-        OpenMPIRBuilder::LocationDescription(
-            IRBuilder<>::InsertPoint(StateMachineBeginBB,
-                                     StateMachineBeginBB->end()),
-            DLoc));
+        OpenMPIRBuilder::LocationDescription(StateMachineBeginBB->end(), DLoc));
 
     Value *Ident = KernelInfo::getIdentFromKernelEnvironment(KernelEnvC);
     Value *GTid = KernelInitCB;
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index c18cca1b2958305..aad520d25212aab 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -455,14 +455,14 @@ Instruction *CodeExtractor::allocateVar(IRBuilder<>::InsertPoint AllocaIP,
                                         const Twine &Name,
                                         AddrSpaceCastInst **CastedAlloc) {
   // An alloca needs no debug location, so the one passed in goes unused here.
-  const DataLayout &DL = AllocaIP.getBlock()->getModule()->getDataLayout();
-  Instruction *Alloca = new AllocaInst(VarType, DL.getAllocaAddrSpace(),
-                                       nullptr, Name, AllocaIP.getPoint());
+  BasicBlock *BB = AllocaIP.getNodeParent();
+  const DataLayout &DL = BB->getDataLayout();
+  Instruction *Alloca =
+      new AllocaInst(VarType, DL.getAllocaAddrSpace(), nullptr, Name, AllocaIP);
 
   if (CastedAlloc && ArgsInZeroAddressSpace && DL.getAllocaAddrSpace() != 0) {
     *CastedAlloc = new AddrSpaceCastInst(
-        Alloca, PointerType::get(AllocaIP.getBlock()->getContext(), 0),
-        Name + ".ascast");
+        Alloca, PointerType::get(BB->getContext(), 0), Name + ".ascast");
     (*CastedAlloc)->insertAfter(Alloca->getIterator());
   }
   return Alloca;
@@ -1907,9 +1907,8 @@ CallInst *CodeExtractor::emitReplacerCall(
       continue;
 
     Value *OutAlloc =
-        allocateVar(IRBuilder<>::InsertPoint(
-                        AllocaBlock, AllocaBlock->getFirstInsertionPt()),
-                    DL, output->getType(), output->getName() + ".loc");
+        allocateVar(AllocaBlock->getFirstInsertionPt(), DL, output->getType(),
+                    output->getName() + ".loc");
     params.push_back(OutAlloc);
     ReloadOutputs.push_back(OutAlloc);
   }
@@ -1917,9 +1916,8 @@ CallInst *CodeExtractor::emitReplacerCall(
   Instruction *Struct = nullptr;
   if (!StructValues.empty()) {
     AddrSpaceCastInst *StructSpaceCast = nullptr;
-    Struct = allocateVar(IRBuilder<>::InsertPoint(
-                             AllocaBlock, AllocaBlock->getFirstInsertionPt()),
-                         DL, StructArgTy, "structArg", &StructSpaceCast);
+    Struct = allocateVar(AllocaBlock->getFirstInsertionPt(), DL, StructArgTy,
+                         "structArg", &StructSpaceCast);
     if (StructSpaceCast)
       params.push_back(StructSpaceCast);
     else
@@ -2063,25 +2061,22 @@ CallInst *CodeExtractor::emitReplacerCall(
                                        {}, call);
 
   // Deallocate intermediate variables if they need explicit deallocation.
-  auto deallocVars = [&](BasicBlock *DeallocBlock,
-                         BasicBlock::iterator DeallocIP) {
+  auto deallocVars = [&](BasicBlock::iterator DeallocIP) {
     int Index = 0;
     for (Value *Output : outputs) {
       if (!StructValues.contains(Output))
-        deallocateVar(IRBuilder<>::InsertPoint(DeallocBlock, DeallocIP), DL,
-                      ReloadOutputs[Index++], Output->getType());
+        deallocateVar(DeallocIP, DL, ReloadOutputs[Index++], Output->getType());
     }
 
     if (Struct)
-      deallocateVar(IRBuilder<>::InsertPoint(DeallocBlock, DeallocIP), DL,
-                    Struct, StructArgTy);
+      deallocateVar(DeallocIP, DL, Struct, StructArgTy);
   };
 
   if (DeallocationBlocks.empty()) {
-    deallocVars(codeReplacer, codeReplacer->end());
+    deallocVars(codeReplacer->end());
   } else {
     for (BasicBlock *DeallocationBlock : DeallocationBlocks)
-      deallocVars(DeallocationBlock, DeallocationBlock->getFirstInsertionPt());
+      deallocVars(DeallocationBlock->getFirstInsertionPt());
   }
 
   return call;
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index 901d7e46d5d3e69..9421047681c2567 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -413,9 +413,9 @@ TEST_F(OpenMPIRBuilderTest, CreateCancel) {
   BasicBlock *CBB = BasicBlock::Create(Ctx, "", F);
   new UnreachableInst(Ctx, CBB);
   auto FiniCB = [&](InsertPointTy IP) {
-    ASSERT_NE(IP.getBlock(), nullptr);
-    ASSERT_EQ(IP.getBlock()->end(), IP.getPoint());
-    UncondBrInst::Create(CBB, IP.getBlock());
+    ASSERT_NE(IP.getNodeParent(), nullptr);
+    ASSERT_EQ(IP.getNodeParent()->end(), IP);
+    UncondBrInst::Create(CBB, IP.getNodeParent());
   };
   OMPBuilder.pushFinalizationCB({FINICB_WRAPPER(FiniCB), OMPD_parallel, true});
 
@@ -446,7 +446,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancel) {
   EXPECT_TRUE(Cancel->hasOneUse());
   Instruction *CancelBBTI = Cancel->getParent()->getTerminator();
   EXPECT_EQ(CancelBBTI->getNumSuccessors(), 2U);
-  EXPECT_EQ(CancelBBTI->getSuccessor(0), NewIP.getBlock());
+  EXPECT_EQ(CancelBBTI->getSuccessor(0), NewIP.getNodeParent());
   EXPECT_EQ(CancelBBTI->getSuccessor(1)->size(), 1U);
   EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getNumSuccessors(),
             1U);
@@ -474,9 +474,9 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelIfCond) {
   BasicBlock *CBB = BasicBlock::Create(Ctx, "", F);
   new UnreachableInst(Ctx, CBB);
   auto FiniCB = [&](InsertPointTy IP) {
-    ASSERT_NE(IP.getBlock(), nullptr);
-    ASSERT_EQ(IP.getBlock()->end(), IP.getPoint());
-    UncondBrInst::Create(CBB, IP.getBlock());
+    ASSERT_NE(IP.getNodeParent(), nullptr);
+    ASSERT_EQ(IP.getNodeParent()->end(), IP);
+    UncondBrInst::Create(CBB, IP.getNodeParent());
   };
   OMPBuilder.pushFinalizationCB({FINICB_WRAPPER(FiniCB), OMPD_parallel, true});
 
@@ -513,7 +513,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelIfCond) {
   EXPECT_EQ(CancelBBTI->getNumSuccessors(), 2U);
   EXPECT_EQ(CancelBBTI->getSuccessor(0)->size(), 1U);
   EXPECT_EQ(CancelBBTI->getSuccessor(0)->getUniqueSuccessor(),
-            NewIP.getBlock());
+            NewIP.getNodeParent());
   EXPECT_EQ(CancelBBTI->getSuccessor(1)->size(), 1U);
   EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getNumSuccessors(),
             1U);
@@ -540,9 +540,9 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelBarrier) {
   BasicBlock *CBB = BasicBlock::Create(Ctx, "", F);
   new UnreachableInst(Ctx, CBB);
   auto FiniCB = [&](InsertPointTy IP) {
-    ASSERT_NE(IP.getBlock(), nullptr);
-    ASSERT_EQ(IP.getBlock()->end(), IP.getPoint());
-    UncondBrInst::Create(CBB, IP.getBlock());
+    ASSERT_NE(IP.getNodeParent(), nullptr);
+    ASSERT_EQ(IP.getNodeParent()->end(), IP);
+    UncondBrInst::Create(CBB, IP.getNodeParent());
   };
   OMPBuilder.pushFinalizationCB({FINICB_WRAPPER(FiniCB), OMPD_parallel, true});
 
@@ -573,7 +573,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelBarrier) {
   EXPECT_TRUE(Barrier->hasOneUse());
   Instruction *BarrierBBTI = Barrier->getParent()->getTerminator();
   EXPECT_EQ(BarrierBBTI->getNumSuccessors(), 2U);
-  EXPECT_EQ(BarrierBBTI->getSuccessor(0), NewIP.getBlock());
+  EXPECT_EQ(BarrierBBTI->getSuccessor(0), NewIP.getNodeParent());
   EXPECT_EQ(BarrierBBTI->getSuccessor(1)->size(), 1U);
   EXPECT_EQ(BarrierBBTI->getSuccessor(1)->getTerminator()->getNumSuccessors(),
             1U);
@@ -664,8 +664,8 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimpleGPU) {
     Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
     Value *Cmp = Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
     Instruction *ThenTerm, *ElseTerm;
-    SplitBlockAndInsertIfThenElse(Cmp, CodeGenIP.getBlock()->getTerminator(),
-                                  &ThenTerm, &ElseTerm);
+    SplitBlockAndInsertIfThenElse(
+        Cmp, CodeGenIP.getNodeParent()->getTerminator(), &ThenTerm, &ElseTerm);
     return Error::success();
   };
 
@@ -699,8 +699,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimpleGPU) {
     return Error::success();
   };
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
                        OMPBuilder.createParallel(
                            Loc, AllocaIP, {}, BodyGenCB, PrivCB, FiniCB,
@@ -793,8 +792,8 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimple) {
     Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
     Value *Cmp = Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
     Instruction *ThenTerm, *ElseTerm;
-    SplitBlockAndInsertIfThenElse(Cmp, CodeGenIP.getBlock()->getTerminator(),
-                                  &ThenTerm, &ElseTerm);
+    SplitBlockAndInsertIfThenElse(
+        Cmp, CodeGenIP.getNodeParent()->getTerminator(), &ThenTerm, &ElseTerm);
     return Error::success();
   };
 
@@ -828,8 +827,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimple) {
     return Error::success();
   };
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
                        OMPBuilder.createParallel(
                            Loc, AllocaIP, {}, BodyGenCB, PrivCB, FiniCB,
@@ -917,22 +915,21 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested) {
                             ArrayRef<BasicBlock *> DeallocBlocks) {
     ++NumOuterBodiesGenerated;
     Builder.restoreIP(CodeGenIP);
-    BasicBlock *CGBB = CodeGenIP.getBlock();
-    BasicBlock *NewBB = SplitBlock(CGBB, &*CodeGenIP.getPoint());
+    BasicBlock *CGBB = CodeGenIP.getNodeParent();
+    BasicBlock *NewBB = SplitBlock(CGBB, &*CodeGenIP);
     CGBB->getTerminator()->eraseFromParent();
 
-    ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
-                         OMPBuilder.createParallel(
-                             {InsertPointTy(CGBB, CGBB->end()), DebugLoc()},
-                             AllocaIP, {}, InnerBodyGenCB, PrivCB, FiniCB,
-                             nullptr, nullptr, OMP_PROC_BIND_default, false));
+    ASSERT_EXPECTED_INIT(
+        OpenMPIRBuilder::InsertPointTy, AfterIP,
+        OMPBuilder.createParallel({CGBB->end(), DebugLoc()}, AllocaIP, {},
+                                  InnerBodyGenCB, PrivCB, FiniCB, nullptr,
+                                  nullptr, OMP_PROC_BIND_default, false));
 
     Builder.restoreIP(AfterIP);
     Builder.CreateBr(NewBB);
   };
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
                        OMPBuilder.createParallel(
                            Loc, AllocaIP, {}, BODYGENCB_WRAPPER(OuterBodyGenCB),
@@ -1020,35 +1017,34 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested2Inner) {
                             ArrayRef<BasicBlock *> DeallocBlocks) {
     ++NumOuterBodiesGenerated;
     Builder.restoreIP(CodeGenIP);
-    BasicBlock *CGBB = CodeGenIP.getBlock();
-    BasicBlock *NewBB1 = SplitBlock(CGBB, &*CodeGenIP.getPoint());
+    BasicBlock *CGBB = CodeGenIP.getNodeParent();
+    BasicBlock *NewBB1 = SplitBlock(CGBB, &*CodeGenIP);
     BasicBlock *NewBB2 = SplitBlock(NewBB1, &*NewBB1->getFirstInsertionPt());
     CGBB->getTerminator()->eraseFromParent();
     ;
     NewBB1->getTerminator()->eraseFromParent();
     ;
 
-    ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP1,
-                         OMPBuilder.createParallel(
-                             {InsertPointTy(CGBB, CGBB->end()), DebugLoc()},
-                             AllocaIP, {}, InnerBodyGenCB, PrivCB, FiniCB,
-                             nullptr, nullptr, OMP_PROC_BIND_default, false));
+    ASSERT_EXPECTED_INIT(
+        OpenMPIRBuilder::InsertPointTy, AfterIP1,
+        OMPBuilder.createParallel({CGBB->end(), DebugLoc()}, AllocaIP, {},
+                                  InnerBodyGenCB, PrivCB, FiniCB, nullptr,
+                                  nullptr, OMP_PROC_BIND_default, false));
 
     Builder.restoreIP(AfterIP1);
     Builder.CreateBr(NewBB1);
 
-    ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP2,
-                         OMPBuilder.createParallel(
-                             {InsertPointTy(NewBB1, NewBB1->end()), DebugLoc()},
-                             AllocaIP, {}, InnerBodyGenCB, PrivCB, FiniCB,
-                             nullptr, nullptr, OMP_PROC_BIND_default, false));
+    ASSERT_EXPECTED_INIT(
+        OpenMPIRBuilder::InsertPointTy, AfterIP2,
+        OMPBuilder.createParallel({NewBB1->end(), DebugLoc()}, AllocaIP, {},
+                                  InnerBodyGenCB, PrivCB, FiniCB, nullptr,
+                                  nullptr, OMP_PROC_BIND_default, false));
 
     Builder.restoreIP(AfterIP2);
     Builder.CreateBr(NewBB2);
   };
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
                        OMPBuilder.createParallel(
                            Loc, AllocaIP, {}, BODYGENCB_WRAPPER(OuterBodyGenCB),
@@ -1164,8 +1160,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelIfCond) {
     return Error::success();
   };
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   ASSERT_EXPECTED_INIT(
       OpenMPIRBuilder::InsertPointTy, AfterIP,
       OMPBuilder.createParallel(Loc, AllocaIP, {}, BodyGenCB, PrivCB, FiniCB,
@@ -1289,8 +1284,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {
     return Error::success();
   };
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   ASSERT_EXPECTED_INIT(
       OpenMPIRBuilder::InsertPointTy, AfterIP,
       OMPBuilder.createParallel(Loc, AllocaIP, {}, BODYGENCB_WRAPPER(BodyGenCB),
@@ -1376,8 +1370,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelForwardAsPointers) {
   };
   auto FiniCB = [](InsertPointTy) { return Error::success(); };
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
                        OMPBuilder.createParallel(
                            Loc, AllocaIP, {}, BodyGenCB, PrivCB, FiniCB,
@@ -1411,8 +1404,8 @@ TEST_F(OpenMPIRBuilderTest, CanonicalLoopSimple) {
 
     Value *Cmp = Builder.CreateICmpEQ(LC, TripCount);
     Instruction *ThenTerm, *ElseTerm;
-    SplitBlockAndInsertIfThenElse(Cmp, CodeGenIP.getBlock()->getTerminator(),
-                                  &ThenTerm, &ElseTerm);
+    SplitBlockAndInsertIfThenElse(
+        Cmp, CodeGenIP.getNodeParent()->getTerminator(), &ThenTerm, &ElseTerm);
     return Error::success();
   };
 
@@ -1544,7 +1537,7 @@ TEST_F(OpenMPIRBuilderTest, CollapseNestedLoops) {
       BasicBlock::Create(M->getContext(), "loopnest.enter", F,
                          Builder.GetInsertBlock()->getNextNode());
   UncondBrInst *EnterBr = Builder.CreateBr(LoopNextEnter);
-  InsertPointTy ComputeIP{EnterBr->getParent(), EnterBr->getIterator()};
+  InsertPointTy ComputeIP{EnterBr->getIterator()};
 
   Builder.SetInsertPoint(LoopNextEnter);
   OpenMPIRBuilder::LocationDescription OuterLoc(Builder.saveIP(), DL);
@@ -1780,9 +1773,9 @@ TEST_F(OpenMPIRBuilderTest, TileNestedLoopsWithBounds) {
       BasicBlock::Create(M->getContext(), "loopnest.enter", F,
                          Builder.GetInsertBlock()->getNextNode());
   UncondBrInst *EnterBr = Builder.CreateBr(LoopNextEnter);
-  InsertPointTy ComputeIP{EnterBr->getParent(), EnterBr->getIterator()};
+  InsertPointTy ComputeIP{EnterBr->getIterator()};
 
-  InsertPointTy LoopIP{LoopNextEnter, LoopNextEnter->begin()};
+  InsertPointTy LoopIP{LoopNextEnter->begin()};
   OpenMPIRBuilder::LocationDescription Loc({LoopIP, DL});
 
   BasicBlock *BodyCode = nullptr;
@@ -2577,8 +2570,7 @@ TEST_P(OpenMPIRBuilderTestWithIVBits, StaticChunkedWorkshareLoop) {
 
   Type *LCTy = Type::getInt32Ty(Ctx);
   Value *ChunkSize = ConstantInt::get(LCTy, 5);
-  InsertPointTy AllocaIP{&F->getEntryBlock(),
-                         F->getEntryBlock().getFirstInsertionPt()};
+  InsertPointTy AllocaIP{F->getEntryBlock().getFirstInsertionPt()};
   ASSERT_THAT_EXPECTED(OMPBuilder.applyWorkshareLoop(DL, CLI, AllocaIP,
                                                      /*NeedsBarrier=*/true,
                                                      OMP_SCHEDULE_Static,
@@ -2702,8 +2694,7 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
           /*Ordered=*/false));
 
   // The returned value should be the "after" point.
-  ASSERT_EQ(EndIP.getBlock(), AfterIP.getBlock());
-  ASSERT_EQ(EndIP.getPoint(), AfterIP.getPoint());
+  ASSERT_EQ(EndIP, AfterIP);
 
   auto AllocaIter = BB->begin();
   ASSERT_GE(std::distance(BB->begin(), BB->end()), 4);
@@ -2901,7 +2892,7 @@ TEST_F(OpenMPIRBuilderTest, MasterDirective) {
 
   auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
-    if (AllocaIP.isSet())
+    if (AllocaIP.isValid())
       Builder.restoreIP(AllocaIP);
     else
       Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
@@ -2909,8 +2900,8 @@ TEST_F(OpenMPIRBuilderTest, MasterDirective) {
     PrivAI = Builder.CreateAlloca(PrivType);
     Builder.CreateStore(F->arg_begin(), PrivAI);
 
-    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
-    llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getNodeParent();
+    llvm::Instruction *CodeGenIPInst = &*CodeGenIP;
     EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
 
     Builder.restoreIP(CodeGenIP);
@@ -2925,8 +2916,8 @@ TEST_F(OpenMPIRBuilderTest, MasterDirective) {
   };
 
   auto FiniCB = [&](InsertPointTy IP) {
-    BasicBlock *IPBB = IP.getBlock();
-    EXPECT_NE(IPBB->end(), IP.getPoint());
+    BasicBlock *IPBB = IP.getNodeParent();
+    EXPECT_NE(IPBB->end(), IP);
   };
 
   ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
@@ -2981,7 +2972,7 @@ TEST_F(OpenMPIRBuilderTest, MaskedDirective) {
 
   auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
-    if (AllocaIP.isSet())
+    if (AllocaIP.isValid())
       Builder.restoreIP(AllocaIP);
     else
       Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
@@ -2989,8 +2980,8 @@ TEST_F(OpenMPIRBuilderTest, MaskedDirective) {
     PrivAI = Builder.CreateAlloca(PrivType);
     Builder.CreateStore(F->arg_begin(), PrivAI);
 
-    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
-    llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getNodeParent();
+    llvm::Instruction *CodeGenIPInst = &*CodeGenIP;
     EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
 
     Builder.restoreIP(CodeGenIP);
@@ -3005,8 +2996,8 @@ TEST_F(OpenMPIRBuilderTest, MaskedDirective) {
   };
 
   auto FiniCB = [&](InsertPointTy IP) {
-    BasicBlock *IPBB = IP.getBlock();
-    EXPECT_NE(IPBB->end(), IP.getPoint());
+    BasicBlock *IPBB = IP.getNodeParent();
+    EXPECT_NE(IPBB->end(), IP);
   };
 
   Constant *Filter = ConstantInt::get(Type::getInt32Ty(M->getContext()), 0);
@@ -3061,8 +3052,8 @@ TEST_F(OpenMPIRBuilderTest, CriticalDirective) {
   auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
     // actual start for bodyCB
-    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
-    llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getNodeParent();
+    llvm::Instruction *CodeGenIPInst = &*CodeGenIP;
     EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
 
     // body begin
@@ -3073,8 +3064,8 @@ TEST_F(OpenMPIRBuilderTest, CriticalDirective) {
   };
 
   auto FiniCB = [&](InsertPointTy IP) {
-    BasicBlock *IPBB = IP.getBlock();
-    EXPECT_NE(IPBB->end(), IP.getPoint());
+    BasicBlock *IPBB = IP.getNodeParent();
+    EXPECT_NE(IPBB->end(), IP);
   };
   BasicBlock *EntryBB = Builder.GetInsertBlock();
 
@@ -3139,8 +3130,7 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveDependSource) {
   IRBuilder<> Builder(BB);
   LLVMContext &Ctx = M->getContext();
 
-  InsertPointTy AllocaIP(&F->getEntryBlock(),
-                         F->getEntryBlock().getFirstInsertionPt());
+  InsertPointTy AllocaIP(F->getEntryBlock().getFirstInsertionPt());
 
   unsigned NumLoops = 2;
   SmallVector<Value *, 2> StoreValues;
@@ -3223,8 +3213,7 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveDependSink) {
   IRBuilder<> Builder(BB);
   LLVMContext &Ctx = M->getContext();
 
-  InsertPointTy AllocaIP(&F->getEntryBlock(),
-                         F->getEntryBlock().getFirstInsertionPt());
+  InsertPointTy AllocaIP(F->getEntryBlock().getFirstInsertionPt());
 
   unsigned NumLoops = 2;
   SmallVector<Value *, 2> StoreValues;
@@ -3311,8 +3300,8 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveThreads) {
 
   auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
-    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
-    llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getNodeParent();
+    llvm::Instruction *CodeGenIPInst = &*CodeGenIP;
     EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
 
     Builder.restoreIP(CodeGenIP);
@@ -3322,8 +3311,8 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveThreads) {
   };
 
   auto FiniCB = [&](InsertPointTy IP) {
-    BasicBlock *IPBB = IP.getBlock();
-    EXPECT_NE(IPBB->end(), IP.getPoint());
+    BasicBlock *IPBB = IP.getNodeParent();
+    EXPECT_NE(IPBB->end(), IP);
   };
 
   // Test for "#omp ordered [threads]"
@@ -3387,8 +3376,8 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveSimd) {
 
   auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
-    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
-    llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getNodeParent();
+    llvm::Instruction *CodeGenIPInst = &*CodeGenIP;
     EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
 
     Builder.restoreIP(CodeGenIP);
@@ -3398,8 +3387,8 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveSimd) {
   };
 
   auto FiniCB = [&](InsertPointTy IP) {
-    BasicBlock *IPBB = IP.getBlock();
-    EXPECT_NE(IPBB->end(), IP.getPoint());
+    BasicBlock *IPBB = IP.getNodeParent();
+    EXPECT_NE(IPBB->end(), IP);
   };
 
   // Test for "#omp ordered simd"
@@ -3488,7 +3477,7 @@ TEST_F(OpenMPIRBuilderTest, SingleDirective) {
 
   auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
-    if (AllocaIP.isSet())
+    if (AllocaIP.isValid())
       Builder.restoreIP(AllocaIP);
     else
       Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
@@ -3496,8 +3485,8 @@ TEST_F(OpenMPIRBuilderTest, SingleDirective) {
     PrivAI = Builder.CreateAlloca(PrivType);
     Builder.CreateStore(F->arg_begin(), PrivAI);
 
-    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
-    llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getNodeParent();
+    llvm::Instruction *CodeGenIPInst = &*CodeGenIP;
     EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
 
     Builder.restoreIP(CodeGenIP);
@@ -3512,8 +3501,8 @@ TEST_F(OpenMPIRBuilderTest, SingleDirective) {
   };
 
   auto FiniCB = [&](InsertPointTy IP) {
-    BasicBlock *IPBB = IP.getBlock();
-    EXPECT_NE(IPBB->end(), IP.getPoint());
+    BasicBlock *IPBB = IP.getNodeParent();
+    EXPECT_NE(IPBB->end(), IP);
   };
 
   ASSERT_EXPECTED_INIT(
@@ -3580,7 +3569,7 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveNowait) {
 
   auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
-    if (AllocaIP.isSet())
+    if (AllocaIP.isValid())
       Builder.restoreIP(AllocaIP);
     else
       Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
@@ -3588,8 +3577,8 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveNowait) {
     PrivAI = Builder.CreateAlloca(PrivType);
     Builder.CreateStore(F->arg_begin(), PrivAI);
 
-    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
-    llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getNodeParent();
+    llvm::Instruction *CodeGenIPInst = &*CodeGenIP;
     EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
 
     Builder.restoreIP(CodeGenIP);
@@ -3604,8 +3593,8 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveNowait) {
   };
 
   auto FiniCB = [&](InsertPointTy IP) {
-    BasicBlock *IPBB = IP.getBlock();
-    EXPECT_NE(IPBB->end(), IP.getPoint());
+    BasicBlock *IPBB = IP.getNodeParent();
+    EXPECT_NE(IPBB->end(), IP);
   };
 
   ASSERT_EXPECTED_INIT(
@@ -3700,7 +3689,7 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveCopyPrivate) {
 
   auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
-    if (AllocaIP.isSet())
+    if (AllocaIP.isValid())
       Builder.restoreIP(AllocaIP);
     else
       Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
@@ -3708,8 +3697,8 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveCopyPrivate) {
     PrivAI = Builder.CreateAlloca(PrivType);
     Builder.CreateStore(F->arg_begin(), PrivAI);
 
-    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
-    llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+    llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getNodeParent();
+    llvm::Instruction *CodeGenIPInst = &*CodeGenIP;
     EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
 
     Builder.restoreIP(CodeGenIP);
@@ -3724,9 +3713,9 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveCopyPrivate) {
   };
 
   auto FiniCB = [&](InsertPointTy IP) {
-    BasicBlock *IPBB = IP.getBlock();
+    BasicBlock *IPBB = IP.getNodeParent();
     // IP must be before the unconditional branch to ExitBB
-    EXPECT_NE(IPBB->end(), IP.getPoint());
+    EXPECT_NE(IPBB->end(), IP);
   };
 
   ASSERT_EXPECTED_INIT(
@@ -3816,8 +3805,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicReadFlt) {
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
   BasicBlock *EntryBB = BB;
-  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB,
-                                          EntryBB->getFirstInsertionPt());
+  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB->getFirstInsertionPt());
 
   Type *Float32 = Type::getFloatTy(M->getContext());
   AllocaInst *XVal = Builder.CreateAlloca(Float32);
@@ -3860,8 +3848,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicReadInt) {
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
   BasicBlock *EntryBB = BB;
-  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB,
-                                          EntryBB->getFirstInsertionPt());
+  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB->getFirstInsertionPt());
 
   IntegerType *Int32 = Type::getInt32Ty(M->getContext());
   AllocaInst *XVal = Builder.CreateAlloca(Int32);
@@ -3912,8 +3899,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicWriteFlt) {
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
   BasicBlock *EntryBB = BB;
-  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB,
-                                          EntryBB->getFirstInsertionPt());
+  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB->getFirstInsertionPt());
 
   LLVMContext &Ctx = M->getContext();
   Type *Float32 = Type::getFloatTy(Ctx);
@@ -3959,8 +3945,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicWriteInt) {
   ConstantInt *ValToWrite = ConstantInt::get(Type::getInt32Ty(Ctx), 1U);
 
   BasicBlock *EntryBB = BB;
-  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB,
-                                          EntryBB->getFirstInsertionPt());
+  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB->getFirstInsertionPt());
 
   Builder.restoreIP(
       OMPBuilder.createAtomicWrite(Loc, X, ValToWrite, AO, AllocaIP));
@@ -4004,8 +3989,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdate) {
   bool IsXLHSInRHSPart = false;
 
   BasicBlock *EntryBB = BB;
-  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB,
-                                          EntryBB->getFirstInsertionPt());
+  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB->getFirstInsertionPt());
   Value *Sub = nullptr;
 
   auto UpdateOp = [&](Value *Atomic, IRBuilder<> &IRB) {
@@ -4072,8 +4056,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateFloat) {
   bool IsXLHSInRHSPart = false;
 
   BasicBlock *EntryBB = BB;
-  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB,
-                                          EntryBB->getFirstInsertionPt());
+  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB->getFirstInsertionPt());
   Value *Sub = nullptr;
 
   auto UpdateOp = [&](Value *Atomic, IRBuilder<> &IRB) {
@@ -4139,8 +4122,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateIntr) {
   bool IsXLHSInRHSPart = false;
 
   BasicBlock *EntryBB = BB;
-  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB,
-                                          EntryBB->getFirstInsertionPt());
+  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB->getFirstInsertionPt());
   Value *Sub = nullptr;
 
   auto UpdateOp = [&](Value *Atomic, IRBuilder<> &IRB) {
@@ -4214,8 +4196,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicCapture) {
   bool UpdateExpr = true;
 
   BasicBlock *EntryBB = BB;
-  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB,
-                                          EntryBB->getFirstInsertionPt());
+  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB->getFirstInsertionPt());
 
   // integer update - not used
   auto UpdateOp = [&](Value *Atomic, IRBuilder<> &IRB) { return nullptr; };
@@ -4555,8 +4536,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicRWStructType) {
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
   BasicBlock *EntryBB = BB;
-  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB,
-                                          EntryBB->getFirstInsertionPt());
+  OpenMPIRBuilder::InsertPointTy AllocaIP(EntryBB->getFirstInsertionPt());
 
   LLVMContext &Ctx = M->getContext();
 
@@ -4653,8 +4633,8 @@ TEST_F(OpenMPIRBuilderTest, CreateTeams) {
     Value *Cmp = Builder.CreateICmpNE(
         Val32, Builder.CreateTrunc(PrivLoad128, Val32->getType()));
     Instruction *ThenTerm, *ElseTerm;
-    SplitBlockAndInsertIfThenElse(Cmp, CodeGenIP.getBlock()->getTerminator(),
-                                  &ThenTerm, &ElseTerm);
+    SplitBlockAndInsertIfThenElse(
+        Cmp, CodeGenIP.getNodeParent()->getTerminator(), &ThenTerm, &ElseTerm);
     return Error::success();
   };
 
@@ -5176,7 +5156,7 @@ static bool findGEPZeroOne(Value *Ptr, Value *&Zero, Value *&One) {
 static OpenMPIRBuilder::InsertPointTy
 sumReduction(OpenMPIRBuilder::InsertPointTy IP, Value *LHS, Value *RHS,
              Value *&Result) {
-  IRBuilder<> Builder(IP.getBlock(), IP.getPoint());
+  IRBuilder<> Builder(IP.getNodeParent(), IP);
   Result = Builder.CreateFAdd(LHS, RHS, "red.add");
   return Builder.saveIP();
 }
@@ -5184,7 +5164,7 @@ sumReduction(OpenMPIRBuilder::InsertPointTy IP, Value *LHS, Value *RHS,
 static OpenMPIRBuilder::InsertPointTy
 sumAtomicReduction(OpenMPIRBuilder::InsertPointTy IP, Type *Ty, Value *LHS,
                    Value *RHS) {
-  IRBuilder<> Builder(IP.getBlock(), IP.getPoint());
+  IRBuilder<> Builder(IP.getNodeParent(), IP);
   Value *Partial = Builder.CreateLoad(Ty, RHS, "red.partial");
   Builder.CreateAtomicRMW(AtomicRMWInst::FAdd, LHS, Partial, std::nullopt,
                           AtomicOrdering::Monotonic);
@@ -5194,7 +5174,7 @@ sumAtomicReduction(OpenMPIRBuilder::InsertPointTy IP, Type *Ty, Value *LHS,
 static OpenMPIRBuilder::InsertPointTy
 xorReduction(OpenMPIRBuilder::InsertPointTy IP, Value *LHS, Value *RHS,
              Value *&Result) {
-  IRBuilder<> Builder(IP.getBlock(), IP.getPoint());
+  IRBuilder<> Builder(IP.getNodeParent(), IP);
   Result = Builder.CreateXor(LHS, RHS, "red.xor");
   return Builder.saveIP();
 }
@@ -5202,7 +5182,7 @@ xorReduction(OpenMPIRBuilder::InsertPointTy IP, Value *LHS, Value *RHS,
 static OpenMPIRBuilder::InsertPointTy
 xorAtomicReduction(OpenMPIRBuilder::InsertPointTy IP, Type *Ty, Value *LHS,
                    Value *RHS) {
-  IRBuilder<> Builder(IP.getBlock(), IP.getPoint());
+  IRBuilder<> Builder(IP.getNodeParent(), IP);
   Value *Partial = Builder.CreateLoad(Ty, RHS, "red.partial");
   Builder.CreateAtomicRMW(AtomicRMWInst::Xor, LHS, Partial, std::nullopt,
                           AtomicOrdering::Monotonic);
@@ -5223,8 +5203,7 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
 
   // Create variables to be reduced.
-  InsertPointTy OuterAllocaIP(&F->getEntryBlock(),
-                              F->getEntryBlock().getFirstInsertionPt());
+  InsertPointTy OuterAllocaIP(F->getEntryBlock().getFirstInsertionPt());
   Type *SumType = Builder.getFloatTy();
   Type *XorType = Builder.getInt32Ty();
   Value *SumReduced;
@@ -5616,8 +5595,7 @@ TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) {
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
 
   // Create variables to be reduced.
-  InsertPointTy OuterAllocaIP(&F->getEntryBlock(),
-                              F->getEntryBlock().getFirstInsertionPt());
+  InsertPointTy OuterAllocaIP(F->getEntryBlock().getFirstInsertionPt());
   Type *SumType = Builder.getFloatTy();
   Type *XorType = Builder.getInt32Ty();
   Value *SumReduced;
@@ -5822,8 +5800,7 @@ TEST_F(OpenMPIRBuilderTest, CreateSectionsSimple) {
   auto PrivCB = [](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                    llvm::Value &, llvm::Value &Val,
                    llvm::Value *&ReplVal) { return CodeGenIP; };
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
                        OMPBuilder.createSections(Loc, AllocaIP, SectionCBVector,
                                                  PrivCB, FiniCB, false, false));
@@ -5855,15 +5832,15 @@ TEST_F(OpenMPIRBuilderTest, CreateSections) {
 
   auto FiniCB = [&](InsertPointTy IP) {
     ++NumFiniCBCalls;
-    BasicBlock *IPBB = IP.getBlock();
-    EXPECT_NE(IPBB->end(), IP.getPoint());
+    BasicBlock *IPBB = IP.getNodeParent();
+    EXPECT_NE(IPBB->end(), IP);
   };
 
   auto SectionCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
     ++NumBodiesGenerated;
-    CaseBBs.push_back(CodeGenIP.getBlock());
-    SwitchBB = CodeGenIP.getBlock()->getSinglePredecessor();
+    CaseBBs.push_back(CodeGenIP.getNodeParent());
+    SwitchBB = CodeGenIP.getNodeParent()->getSinglePredecessor();
     Builder.restoreIP(CodeGenIP);
     Builder.CreateStore(F->arg_begin(), PrivAI);
     Value *PrivLoad =
@@ -5880,8 +5857,7 @@ TEST_F(OpenMPIRBuilderTest, CreateSections) {
   SectionCBVector.push_back(SectionCB);
   SectionCBVector.push_back(SectionCB);
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
                        OMPBuilder.createSections(Loc, AllocaIP, SectionCBVector,
                                                  PrivCB, FINICB_WRAPPER(FiniCB),
@@ -5964,8 +5940,7 @@ TEST_F(OpenMPIRBuilderTest, CreateSectionsNoWait) {
   Builder.SetInsertPoint(EnterBB);
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   llvm::SmallVector<BodyGenCallbackTy, 4> SectionCBVector;
   auto PrivCB = [](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                    llvm::Value &, llvm::Value &Val,
@@ -6063,8 +6038,7 @@ TEST_F(OpenMPIRBuilderTest, CreateMapperAllocas) {
   unsigned TotalNbOperand = 2;
 
   OpenMPIRBuilder::MapperAllocas MapperAllocas;
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   OMPBuilder.createMapperAllocas(Loc, AllocaIP, TotalNbOperand, MapperAllocas);
   EXPECT_NE(MapperAllocas.ArgsBase, nullptr);
   EXPECT_NE(MapperAllocas.Args, nullptr);
@@ -6104,8 +6078,7 @@ TEST_F(OpenMPIRBuilderTest, EmitMapperCall) {
   unsigned TotalNbOperand = 2;
 
   OpenMPIRBuilder::MapperAllocas MapperAllocas;
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
   OMPBuilder.createMapperAllocas(Loc, AllocaIP, TotalNbOperand, MapperAllocas);
 
   auto *BeginMapperFunc = OMPBuilder.getOrCreateRuntimeFunctionPtr(
@@ -6166,8 +6139,7 @@ TEST_F(OpenMPIRBuilderTest, TargetEnterData) {
       Builder.CreateAlloca(Builder.getInt32Ty(), Builder.getInt64(1));
   ASSERT_NE(Val1, nullptr);
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
 
   llvm::OpenMPIRBuilder::MapInfosTy CombinedInfo;
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
@@ -6229,8 +6201,7 @@ TEST_F(OpenMPIRBuilderTest, TargetExitData) {
       Builder.CreateAlloca(Builder.getInt32Ty(), Builder.getInt64(1));
   ASSERT_NE(Val1, nullptr);
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
 
   llvm::OpenMPIRBuilder::MapInfosTy CombinedInfo;
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
@@ -6298,8 +6269,7 @@ TEST_F(OpenMPIRBuilderTest, TargetDataRegion) {
   AllocaInst *Val3 = Builder.CreateAlloca(Builder.getPtrTy());
   ASSERT_NE(Val3, nullptr);
 
-  IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
-                                    F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint AllocaIP(F->getEntryBlock().getFirstInsertionPt());
 
   using DeviceInfoTy = llvm::OpenMPIRBuilder::DeviceInfoTy;
   llvm::OpenMPIRBuilder::MapInfosTy CombinedInfo;
@@ -6667,8 +6637,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
     return Builder.saveIP();
   };
 
-  IRBuilder<>::InsertPoint EntryIP(&F->getEntryBlock(),
-                                   F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint EntryIP(F->getEntryBlock().getFirstInsertionPt());
   TargetRegionEntryInfo EntryInfo("parent", /*DeviceID=*/1, /*FileID=*/2,
                                   /*Line=*/3, /*Count=*/0);
   OpenMPIRBuilder::TargetKernelRuntimeAttrs RuntimeAttrs;
@@ -7023,12 +6992,11 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDeviceSPMD) {
           OpenMPIRBuilder::InsertPointTy CodeGenIP,
           ArrayRef<BasicBlock *>) -> OpenMPIRBuilder::InsertPointTy {
     Builder.restoreIP(CodeGenIP);
-    OutlinedFn = CodeGenIP.getBlock()->getParent();
+    OutlinedFn = CodeGenIP.getNodeParent()->getParent();
     return Builder.saveIP();
   };
 
-  IRBuilder<>::InsertPoint EntryIP(&F->getEntryBlock(),
-                                   F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint EntryIP(F->getEntryBlock().getFirstInsertionPt());
   TargetRegionEntryInfo EntryInfo("parent", /*DeviceID=*/1, /*FileID=*/2,
                                   /*Line=*/3, /*Count=*/0);
   OpenMPIRBuilder::TargetKernelRuntimeAttrs RuntimeAttrs;
@@ -7154,8 +7122,7 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
     return Builder.saveIP();
   };
 
-  IRBuilder<>::InsertPoint EntryIP(&F->getEntryBlock(),
-                                   F->getEntryBlock().getFirstInsertionPt());
+  IRBuilder<>::InsertPoint EntryIP(F->getEntryBlock().getFirstInsertionPt());
   TargetRegionEntryInfo EntryInfo("parent", /*DeviceID=*/1, /*FileID=*/2,
                                   /*Line=*/3, /*Count=*/0);
   OpenMPIRBuilder::TargetKernelRuntimeAttrs RuntimeAttrs;
@@ -7333,7 +7300,7 @@ TEST_F(OpenMPIRBuilderTest, DebugRecordLoc) {
         mainSP->getScope(), "target", "", mainSP->getFile(), 2, Type, 2,
         DINode::FlagZero,
         DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized);
-    OutlinedFn = CodeGenIP.getBlock()->getParent();
+    OutlinedFn = CodeGenIP.getNodeParent()->getParent();
     OutlinedFn->setSubprogram(SP);
     DebugLoc Loc = DILocation::get(Ctx, 3, 7, SP);
     DIType *VoidPtrTy =
@@ -7373,8 +7340,7 @@ TEST_F(OpenMPIRBuilderTest, DebugRecordLoc) {
     return Builder.saveIP();
   };
 
-  IRBuilder<>::InsertPoint EntryIP(&F->getEntryBlock(),
-                                   F->getEntryBlock().end());
+  IRBuilder<>::InsertPoint EntryIP(F->getEntryBlock().end());
   TargetRegionEntryInfo EntryInfo("parent", /*DeviceID=*/1, /*FileID=*/2,
                                   /*Line=*/3, /*Count=*/0);
   OpenMPIRBuilder::TargetKernelRuntimeAttrs RuntimeAttrs;
@@ -7452,20 +7418,18 @@ TEST_F(OpenMPIRBuilderTest, CreateTask) {
     Value *Cmp = Builder.CreateICmpNE(
         Val32, Builder.CreateTrunc(PrivLoad128, Val32->getType()));
     Instruction *ThenTerm, *ElseTerm;
-    SplitBlockAndInsertIfThenElse(Cmp, CodeGenIP.getBlock()->getTerminator(),
-                                  &ThenTerm, &ElseTerm);
+    SplitBlockAndInsertIfThenElse(
+        Cmp, CodeGenIP.getNodeParent()->getTerminator(), &ThenTerm, &ElseTerm);
     return Error::success();
   };
 
   BasicBlock *AllocaBB = Builder.GetInsertBlock();
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
-  OpenMPIRBuilder::LocationDescription Loc(
-      InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
-  ASSERT_EXPECTED_INIT(
-      OpenMPIRBuilder::InsertPointTy, AfterIP,
-      OMPBuilder.createTask(
-          Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()),
-          /*DeallocBlocks=*/{}, BodyGenCB));
+  OpenMPIRBuilder::LocationDescription Loc(BodyBB->getFirstInsertionPt(), DL);
+  ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
+                       OMPBuilder.createTask(Loc,
+                                             AllocaBB->getFirstInsertionPt(),
+                                             /*DeallocBlocks=*/{}, BodyGenCB));
   Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
@@ -7571,13 +7535,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskNoArgs) {
 
   BasicBlock *AllocaBB = Builder.GetInsertBlock();
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
-  OpenMPIRBuilder::LocationDescription Loc(
-      InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
-  ASSERT_EXPECTED_INIT(
-      OpenMPIRBuilder::InsertPointTy, AfterIP,
-      OMPBuilder.createTask(
-          Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()),
-          /*DeallocBlocks=*/{}, BodyGenCB));
+  OpenMPIRBuilder::LocationDescription Loc(BodyBB->getFirstInsertionPt(), DL);
+  ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
+                       OMPBuilder.createTask(Loc,
+                                             AllocaBB->getFirstInsertionPt(),
+                                             /*DeallocBlocks=*/{}, BodyGenCB));
   Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
@@ -7606,14 +7568,12 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskUntied) {
   };
   BasicBlock *AllocaBB = Builder.GetInsertBlock();
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
-  OpenMPIRBuilder::LocationDescription Loc(
-      InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
-  ASSERT_EXPECTED_INIT(
-      OpenMPIRBuilder::InsertPointTy, AfterIP,
-      OMPBuilder.createTask(
-          Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()),
-          /*DeallocBlocks=*/{}, BodyGenCB,
-          /*Tied=*/false));
+  OpenMPIRBuilder::LocationDescription Loc(BodyBB->getFirstInsertionPt(), DL);
+  ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
+                       OMPBuilder.createTask(Loc,
+                                             AllocaBB->getFirstInsertionPt(),
+                                             /*DeallocBlocks=*/{}, BodyGenCB,
+                                             /*Tied=*/false));
   Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
@@ -7643,8 +7603,7 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskDepend) {
   };
   BasicBlock *AllocaBB = Builder.GetInsertBlock();
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
-  OpenMPIRBuilder::LocationDescription Loc(
-      InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
+  OpenMPIRBuilder::LocationDescription Loc(BodyBB->getFirstInsertionPt(), DL);
   AllocaInst *InDep = Builder.CreateAlloca(Type::getInt32Ty(M->getContext()));
   SmallVector<OpenMPIRBuilder::DependData> DDS;
   {
@@ -7654,11 +7613,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskDepend) {
   }
   ASSERT_EXPECTED_INIT(
       OpenMPIRBuilder::InsertPointTy, AfterIP,
-      OMPBuilder.createTask(
-          Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()),
-          /*DeallocBlocks=*/{}, BodyGenCB,
-          /*Tied=*/false, /*Final*/ nullptr, /*IfCondition*/ nullptr,
-          OpenMPIRBuilder::DependenciesInfo{std::move(DDS)}));
+      OMPBuilder.createTask(Loc, AllocaBB->getFirstInsertionPt(),
+                            /*DeallocBlocks=*/{}, BodyGenCB,
+                            /*Tied=*/false, /*Final*/ nullptr,
+                            /*IfCondition*/ nullptr,
+                            OpenMPIRBuilder::DependenciesInfo{std::move(DDS)}));
   Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
@@ -7879,22 +7838,20 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskAffinity) {
 
   BasicBlock *AllocaBB = Builder.GetInsertBlock();
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
-  OpenMPIRBuilder::LocationDescription Loc(
-      InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
+  OpenMPIRBuilder::LocationDescription Loc(BodyBB->getFirstInsertionPt(), DL);
 
-  ASSERT_EXPECTED_INIT(
-      OpenMPIRBuilder::InsertPointTy, AfterIP,
-      OMPBuilder.createTask(
-          Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()),
-          /*DeallocBlocks=*/{}, BodyGenCB,
-          /*Tied=*/true,
-          /*Final=*/nullptr,
-          /*IfCondition=*/nullptr,
-          /*Dependencies=*/{},
-          /*Affinity=*/Affinity,
-          /*Mergeable=*/false,
-          /*EventHandle=*/nullptr,
-          /*Priority=*/nullptr));
+  ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP,
+                       OMPBuilder.createTask(Loc,
+                                             AllocaBB->getFirstInsertionPt(),
+                                             /*DeallocBlocks=*/{}, BodyGenCB,
+                                             /*Tied=*/true,
+                                             /*Final=*/nullptr,
+                                             /*IfCondition=*/nullptr,
+                                             /*Dependencies=*/{},
+                                             /*Affinity=*/Affinity,
+                                             /*Mergeable=*/false,
+                                             /*EventHandle=*/nullptr,
+                                             /*Priority=*/nullptr));
 
   Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
@@ -7956,7 +7913,7 @@ TEST_F(OpenMPIRBuilderTest, CreateIteratorLoop) {
     Builder.restoreIP(AfterIP);
     Builder.CreateRetVoid();
 
-    EXPECT_EQ(AfterIP.getBlock()->getName(), "omp.it.cont");
+    EXPECT_EQ(AfterIP.getNodeParent()->getName(), "omp.it.cont");
     EXPECT_FALSE(verifyFunction(*F, &errs()));
   }
 
@@ -7979,14 +7936,14 @@ TEST_F(OpenMPIRBuilderTest, CreateIteratorLoop) {
       return Error::success();
     };
 
-    OpenMPIRBuilder::LocationDescription Loc(InsertPointTy(BB2, BB2->end()),
-                                             DL);
+    OpenMPIRBuilder::LocationDescription Loc(BB2->end(), DL);
     ASSERT_EXPECTED_INIT(InsertPointTy, AfterIP,
                          OMPBuilder.createIteratorLoop(Loc, Builder.getInt64(4),
                                                        BodyGenCB, "iterator"));
 
-    EXPECT_EQ(AfterIP.getBlock()->getName(), "omp.it.cont");
-    auto *ContBr = dyn_cast<UncondBrInst>(AfterIP.getBlock()->getTerminator());
+    EXPECT_EQ(AfterIP.getNodeParent()->getName(), "omp.it.cont");
+    auto *ContBr =
+        dyn_cast<UncondBrInst>(AfterIP.getNodeParent()->getTerminator());
     ASSERT_NE(ContBr, nullptr);
     EXPECT_EQ(ContBr->getSuccessor(), OrigSucc);
 
@@ -8057,20 +8014,18 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroup) {
         InternalLoad32,
         Builder.CreateTrunc(InternalLoad128, InternalLoad32->getType()));
     SplitBlockAndInsertIfThenElse(InternalIfCmp,
-                                  CodeGenIP.getBlock()->getTerminator(),
+                                  CodeGenIP.getNodeParent()->getTerminator(),
                                   &ThenTerm, &ElseTerm);
     return Error::success();
   };
 
   BasicBlock *AllocaBB = Builder.GetInsertBlock();
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
-  OpenMPIRBuilder::LocationDescription Loc(
-      InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
+  OpenMPIRBuilder::LocationDescription Loc(BodyBB->getFirstInsertionPt(), DL);
   ASSERT_EXPECTED_INIT(
       OpenMPIRBuilder::InsertPointTy, AfterIP,
-      OMPBuilder.createTaskgroup(
-          Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()), {},
-          BodyGenCB));
+      OMPBuilder.createTaskgroup(Loc, AllocaBB->getFirstInsertionPt(), {},
+                                 BodyGenCB));
   Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
@@ -8169,13 +8124,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroupWithTasks) {
 
   BasicBlock *AllocaBB = Builder.GetInsertBlock();
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
-  OpenMPIRBuilder::LocationDescription Loc(
-      InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
+  OpenMPIRBuilder::LocationDescription Loc(BodyBB->getFirstInsertionPt(), DL);
   ASSERT_EXPECTED_INIT(
       OpenMPIRBuilder::InsertPointTy, AfterIP,
-      OMPBuilder.createTaskgroup(
-          Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()), {},
-          BODYGENCB_WRAPPER(BodyGenCB)));
+      OMPBuilder.createTaskgroup(Loc, AllocaBB->getFirstInsertionPt(), {},
+                                 BODYGENCB_WRAPPER(BodyGenCB)));
   Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
@@ -8446,11 +8399,9 @@ TEST_F(OpenMPIRBuilderTest, EmitOffloadingArraysNonContigCountExpression) {
   OpenMPIRBuilder::TargetDataInfo Info(true, false);
   Info.NumberOfPtrs = 1;
   OpenMPIRBuilder::TargetDataRTArgs RTArgs;
-  using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
 
   EXPECT_FALSE(OMPBuilder.emitOffloadingArraysAndArgs(
-      InsertPointTy(Builder.saveIP()), InsertPointTy(Builder.saveIP()), Info,
-      RTArgs, CombinedInfo,
+      Builder.saveIP(), Builder.saveIP(), Info, RTArgs, CombinedInfo,
       [](unsigned) -> Expected<Function *> {
         return static_cast<Function *>(nullptr);
       },
@@ -8476,7 +8427,7 @@ TEST_F(OpenMPIRBuilderTest, ScopeDirective) {
   BasicBlock *BodyBB = nullptr;
   auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
                        ArrayRef<BasicBlock *> DeallocBlocks) {
-    BodyBB = CodeGenIP.getBlock();
+    BodyBB = CodeGenIP.getNodeParent();
     Builder.restoreIP(CodeGenIP);
     // Emit a no-op store so the body block is non-empty.
     Builder.CreateStore(Builder.getInt32(42),
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 530c1a260ddcc04..65339e16eaabf44 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -675,7 +675,7 @@ static llvm::OpenMPIRBuilder::InsertPointTy findAllocInsertPoints(
   // insertion point is inside the outlined function. We need to make sure that
   // we do not use it in those cases.
   if (walkResult.wasInterrupted() &&
-      allocInsertPoint.getBlock()->getParent() ==
+      allocInsertPoint.getNodeParent()->getParent() ==
           builder.GetInsertBlock()->getParent()) {
     if (deallocBlocks)
       deallocBlocks->insert(deallocBlocks->end(), deallocInsertPoints.begin(),
@@ -716,8 +716,7 @@ static llvm::OpenMPIRBuilder::InsertPointTy findAllocInsertPoints(
 
   llvm::BasicBlock &funcEntryBlock =
       builder.GetInsertBlock()->getParent()->getEntryBlock();
-  return llvm::OpenMPIRBuilder::InsertPointTy(
-      &funcEntryBlock, funcEntryBlock.getFirstInsertionPt());
+  return funcEntryBlock.getFirstInsertionPt();
 }
 
 /// Find the loop information structure for the loop nest being translated. It
@@ -1387,14 +1386,14 @@ static LogicalResult
 allocReductionVars(T op, ArrayRef<BlockArgument> reductionArgs,
                    llvm::IRBuilderBase &builder,
                    LLVM::ModuleTranslation &moduleTranslation,
-                   const llvm::OpenMPIRBuilder::InsertPointTy &allocaIP,
+                   llvm::OpenMPIRBuilder::InsertPointTy &allocaIP,
                    SmallVectorImpl<omp::DeclareReductionOp> &reductionDecls,
                    SmallVectorImpl<llvm::Value *> &privateReductionVariables,
                    DenseMap<Value, llvm::Value *> &reductionVariableMap,
                    SmallVectorImpl<DeferredStore> &deferredStores,
                    llvm::ArrayRef<bool> isByRefs) {
   llvm::IRBuilderBase::InsertPointGuard guard(builder);
-  builder.SetInsertPoint(allocaIP.getBlock()->getTerminator());
+  builder.SetInsertPoint(allocaIP.getNodeParent()->getTerminator());
 
   llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
   bool useDeviceSharedMem = omp::opInSharedDeviceContext(*op);
@@ -1415,7 +1414,7 @@ allocReductionVars(T op, ArrayRef<BlockArgument> reductionArgs,
             "failed to inline `alloc` region of `omp.declare_reduction`");
 
       assert(phis.size() == 1 && "expected one allocation to be yielded");
-      builder.SetInsertPoint(allocaIP.getBlock()->getTerminator());
+      builder.SetInsertPoint(allocaIP.getNodeParent()->getTerminator());
 
       // Allocate reduction variable (which is a pointer to the real reduction
       // variable allocated in the inlined region)
@@ -1531,8 +1530,7 @@ initReductionVars(OP op, ArrayRef<BlockArgument> reductionArgs,
   bool useDeviceSharedMem = omp::opInSharedDeviceContext(*op);
 
   llvm::BasicBlock *initBlock = splitBB(builder, true, "omp.reduction.init");
-  auto allocaIP = llvm::IRBuilderBase::InsertPoint(
-      latestAllocaBlock, latestAllocaBlock->getTerminator()->getIterator());
+  auto allocaIP = latestAllocaBlock->getTerminator()->getIterator();
   builder.restoreIP(allocaIP);
   SmallVector<llvm::Value *> byRefVars(op.getNumReductionVars());
 
@@ -1750,7 +1748,7 @@ static LogicalResult createReductionsAndCleanup(
   if (failed(handleError(contInsertPoint, *op)))
     return failure();
 
-  if (!contInsertPoint->getBlock())
+  if (!contInsertPoint->isValid())
     return op->emitOpError() << "failed to convert reductions";
 
   llvm::OpenMPIRBuilder::InsertPointTy afterIP = *contInsertPoint;
@@ -1816,7 +1814,7 @@ static LogicalResult allocAndInitializeReductionVars(
     return failure();
 
   return initReductionVars(op, reductionArgs, builder, moduleTranslation,
-                           allocaIP.getBlock(), reductionDecls,
+                           allocaIP.getNodeParent(), reductionDecls,
                            privateReductionVariables, reductionVariableMap,
                            isByRef, deferredStores);
 }
@@ -1992,39 +1990,43 @@ static llvm::Expected<llvm::BasicBlock *> allocatePrivateVars(
     T op, llvm::IRBuilderBase &builder,
     LLVM::ModuleTranslation &moduleTranslation,
     PrivateVarsInfo &privateVarsInfo,
-    const llvm::OpenMPIRBuilder::InsertPointTy &allocaIP,
+    llvm::OpenMPIRBuilder::InsertPointTy &allocaIP,
     llvm::DenseMap<Value, Value> *mappedPrivateVars = nullptr,
     std::optional<llvm::OpenMPIRBuilder::InsertPointTy> allocatorIP =
         std::nullopt) {
   // Allocate private vars
-  llvm::Instruction *allocaTerminator = allocaIP.getBlock()->getTerminator();
-  splitBB(llvm::OpenMPIRBuilder::InsertPointTy(allocaIP.getBlock(),
-                                               allocaTerminator->getIterator()),
-          true, allocaTerminator->getStableDebugLoc(),
-          "omp.region.after_alloca");
+  // Save blocks before splits since allocaIP/allocatorIP iterators may follow
+  // spliced instructions to the new block.
+  llvm::BasicBlock *allocaBB = allocaIP.getNodeParent();
+  llvm::Instruction *allocaTerminator = allocaBB->getTerminator();
+  splitBB(allocaTerminator->getIterator(), true,
+          allocaTerminator->getStableDebugLoc(), "omp.region.after_alloca");
+  // Update allocaIP: the split may have moved its iterator to the new block.
+  allocaIP = allocaBB->getTerminator()->getIterator();
 
   llvm::Instruction *allocatorTerminator = nullptr;
   llvm::BasicBlock *afterAllocatorAllocations = nullptr;
+  llvm::BasicBlock *allocatorBB = nullptr;
   if (allocatorIP) {
-    allocatorTerminator = allocatorIP->getBlock()->getTerminator();
+    allocatorBB = allocatorIP->getNodeParent();
+    allocatorTerminator = allocatorBB->getTerminator();
     afterAllocatorAllocations = splitBB(
-        llvm::OpenMPIRBuilder::InsertPointTy(
-            allocatorIP->getBlock(), allocatorTerminator->getIterator()),
-        true, allocatorTerminator->getStableDebugLoc(),
-        "omp.region.after_allocate");
+        allocatorTerminator->getIterator(), true,
+        allocatorTerminator->getStableDebugLoc(), "omp.region.after_allocate");
+    *allocatorIP = allocatorBB->getTerminator()->getIterator();
   }
 
   std::optional<llvm::IRBuilderBase::InsertPointGuard> guard;
   if (!allocatorIP)
     guard.emplace(builder);
   // Update the allocaTerminator since the alloca block was split above.
-  allocaTerminator = allocaIP.getBlock()->getTerminator();
+  allocaTerminator = allocaBB->getTerminator();
   builder.SetInsertPoint(allocaTerminator);
   // The new terminator is an uncondition branch created by the splitBB above.
   assert(allocaTerminator->getNumSuccessors() == 1 &&
          "This is an unconditional branch created by splitBB");
   if (allocatorIP) {
-    allocatorTerminator = allocatorIP->getBlock()->getTerminator();
+    allocatorTerminator = allocatorBB->getTerminator();
     assert(allocatorTerminator->getNumSuccessors() == 1 &&
            "This is an unconditional branch created by splitBB");
   }
@@ -2764,7 +2766,7 @@ static void pushCancelFinalizationCB(
     // branch to the block that finalizes the taskgroup.
     // That block has not been created yet so use this block as a dummy for now
     // and fix this after creating the operation.
-    cancelTerminators.push_back(llvmBuilder.CreateBr(ip.getBlock()));
+    cancelTerminators.push_back(llvmBuilder.CreateBr(ip.getNodeParent()));
     return llvm::Error::success();
   };
   // We have to add the cleanup to the OpenMPIRBuilder before the body gets
@@ -2781,9 +2783,9 @@ static void pushCancelFinalizationCB(
 static void
 popCancelFinalizationCB(const ArrayRef<llvm::UncondBrInst *> cancelTerminators,
                         llvm::OpenMPIRBuilder &ompBuilder,
-                        const llvm::OpenMPIRBuilder::InsertPointTy &afterIP) {
+                        llvm::BasicBlock *afterBB) {
   ompBuilder.popFinalizationCB();
-  llvm::BasicBlock *constructFini = afterIP.getBlock()->getSinglePredecessor();
+  llvm::BasicBlock *constructFini = afterBB->getSinglePredecessor();
   for (llvm::UncondBrInst *cancelBranch : cancelTerminators)
     cancelBranch->setSuccessor(constructFini);
 }
@@ -3481,7 +3483,7 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
       llvm::IRBuilderBase::InsertPointGuard guard(builder);
       llvm::Type *llvmAllocType =
           moduleTranslation.convertType(privDecl.getType());
-      builder.SetInsertPoint(allocaIP.getBlock()->getTerminator());
+      builder.SetInsertPoint(allocaIP.getNodeParent()->getTerminator());
       llvm::Value *llvmPrivateVar = builder.CreateAlloca(
           llvmAllocType, /*ArraySize=*/nullptr, "omp.private.alloc");
 
@@ -3620,7 +3622,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
     return failure();
 
   // Set the correct branch target for task cancellation
-  popCancelFinalizationCB(cancelTerminators, ompBuilder, afterIP.get());
+  popCancelFinalizationCB(cancelTerminators, ompBuilder,
+                          afterIP->getNodeParent());
 
   builder.restoreIP(*afterIP);
 
@@ -3999,7 +4002,7 @@ convertOmpTaskloopContextOp(omp::TaskloopContextOp contextOp,
       llvm::IRBuilderBase::InsertPointGuard guard(builder);
       llvm::Type *llvmAllocType =
           moduleTranslation.convertType(privDecl.getType());
-      builder.SetInsertPoint(allocaIP.getBlock()->getTerminator());
+      builder.SetInsertPoint(allocaIP.getNodeParent()->getTerminator());
       llvm::Value *llvmPrivateVar = builder.CreateAlloca(
           llvmAllocType, /*ArraySize=*/nullptr, "omp.private.alloc");
 
@@ -4257,7 +4260,8 @@ convertOmpTaskloopContextOp(omp::TaskloopContextOp contextOp,
   if (failed(handleError(afterIP, opInst)))
     return failure();
 
-  popCancelFinalizationCB(cancelTerminators, ompBuilder, afterIP.get());
+  popCancelFinalizationCB(cancelTerminators, ompBuilder,
+                          afterIP->getNodeParent());
 
   builder.restoreIP(*afterIP);
 
@@ -4914,6 +4918,10 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
   if (failed(handleError(wsloopIP, opInst)))
     return failure();
 
+  // Save the continuation block before linear var finalization, which may
+  // invalidate the wsloopIP iterator.
+  llvm::BasicBlock *wsloopContinuationBB = wsloopIP->getNodeParent();
+
   // Emit finalization and in-place rewrites for linear vars.
   if (!wsloopOp.getLinearVars().empty()) {
     llvm::OpenMPIRBuilder::InsertPointTy oldIP = builder.saveIP();
@@ -4929,7 +4937,7 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
   }
 
   // Set the correct branch target for task cancellation
-  popCancelFinalizationCB(cancelTerminators, *ompBuilder, wsloopIP.get());
+  popCancelFinalizationCB(cancelTerminators, *ompBuilder, wsloopContinuationBB);
 
   // Close the task-reduction scope before the worksharing reduction combine.
   if (isTaskReductionMod)
@@ -4993,9 +5001,7 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
     MutableArrayRef<BlockArgument> reductionArgs =
         cast<omp::BlockArgOpenMPOpInterface>(*opInst).getReductionBlockArgs();
 
-    allocaIP =
-        InsertPointTy(allocaIP.getBlock(),
-                      allocaIP.getBlock()->getTerminator()->getIterator());
+    allocaIP = allocaIP.getNodeParent()->getTerminator()->getIterator();
 
     if (failed(allocReductionVars(
             opInst, reductionArgs, builder, moduleTranslation, allocaIP,
@@ -5081,7 +5087,7 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
       if (!contInsertPoint)
         return contInsertPoint.takeError();
 
-      if (!contInsertPoint->getBlock())
+      if (!contInsertPoint->isValid())
         return llvm::make_error<PreviouslyReportedError>();
 
       tempTerminator->eraseFromParent();
@@ -5471,7 +5477,7 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
     // tiling.
     llvm::BasicBlock *afterBB = newLoops.front()->getAfter();
     llvm::BasicBlock *afterAfterBB = afterBB->getSingleSuccessor();
-    afterIP = {afterAfterBB, afterAfterBB->begin()};
+    afterIP = afterAfterBB->begin();
 
     // Update the loop infos.
     loopInfos.clear();
@@ -9042,14 +9048,14 @@ static llvm::IRBuilderBase::InsertPoint createDeviceArgumentAccessor(
     // to the target initialization call. Also, the exit block (where the
     // deallocation is placed) is only executed if the initialization call
     // succeeds.
-    builder.SetInsertPoint(codeGenIP.getBlock()->getFirstInsertionPt());
+    builder.SetInsertPoint(codeGenIP.getNodeParent()->getFirstInsertionPt());
     v = ompBuilder.createOMPAllocShared(builder, arg.getType());
 
     // Create deallocations in all provided deallocation points and then restore
     // the insertion point to right after the new allocations.
     llvm::IRBuilderBase::InsertPointGuard guard(builder);
     for (auto deallocIP : deallocIPs) {
-      builder.SetInsertPoint(deallocIP.getBlock(), deallocIP.getPoint());
+      builder.SetInsertPoint(deallocIP);
       ompBuilder.createOMPFreeShared(builder, v, arg.getType());
     }
   } else {
@@ -9651,7 +9657,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
     // original function to the new outlined function.
     llvm::Function *llvmParentFn =
         moduleTranslation.lookupFunction(parentFn.getName());
-    llvmOutlinedFn = codeGenIP.getBlock()->getParent();
+    llvmOutlinedFn = codeGenIP.getNodeParent()->getParent();
     assert(llvmParentFn && llvmOutlinedFn &&
            "Both parent and outlined functions must exist at this point");
 



More information about the llvm-commits mailing list