[clang] d94d6f8 - [IRBuilder] Remove custom insertion point type (#228117)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 06:33:34 PDT 2026
Author: Nikita Popov
Date: 2026-10-02T13:33:25Z
New Revision: d94d6f87d76b224a13e82ae2a249e1090f853300
URL: https://github.com/llvm/llvm-project/commit/d94d6f87d76b224a13e82ae2a249e1090f853300
DIFF: https://github.com/llvm/llvm-project/commit/d94d6f87d76b224a13e82ae2a249e1090f853300.diff
LOG: [IRBuilder] Remove custom insertion point type (#228117)
Historically, insertion points had to be represented as pairs of
BasicBlock and BasicBlock iterator, because an end() iterator did not
know which block it belongs to. This has changed some time ago (I think
as part of the debuginfo records change) and BasicBlock iterators now
have a reference to their parent block. So the canonical representation
of an insertion point is now just a BasicBlock iterator.
This makes the `IRBuilder::SetInsertPoint(BasicBlock::iterator)` API
handle end() iterators correctly (but still keeping the API with a
redundant block argument) and replaces the `IRBuilderBase::InsertPoint`
type (which was a pair of block and iterator) with a plain
`BasicBlock::iterator`.
This requires surprisingly many changes because IRBuilder insertion
points are heavily used in the OpenMP building. A small number of
non-mechanical changes were needed because the code was sometimes
relying on the fact that nothing enforced that the block and iterator
actually referred to the same block, and they diverged sometimes when
splitting. In those cases we need to make sure to get the original block
before splitting.
Added:
Modified:
clang/lib/CodeGen/CGCleanup.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CodeGenFunction.h
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 3cac452a5f2153..087df04897f00b 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 8acf4b95f3e779..76bd781a709b69 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 6de9fea26954ef..58bfd48a49d39a 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 91c1a08fc7c8a7..190ff5d62fa189 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 3ca9d7ee30d175..0913f76018a585 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -2283,7 +2283,7 @@ void CodeGenFunction::OMPBuilderCBHelpers::EmitOMPInlinedRegionBody(
CGF.EmitStmt(RegionBodyStmt);
}
- if (Builder.saveIP().isSet())
+ if (Builder.saveIP().isValid())
Builder.CreateBr(FiniBB);
}
@@ -2300,7 +2300,7 @@ void CodeGenFunction::OMPBuilderCBHelpers::EmitOMPOutlinedRegionBody(
CGF.EmitStmt(RegionBodyStmt);
}
- if (Builder.saveIP().isSet())
+ if (Builder.saveIP().isValid())
Builder.CreateBr(FiniBB);
}
@@ -2357,7 +2357,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,
@@ -4679,7 +4679,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,
@@ -4967,7 +4967,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(),
@@ -6180,8 +6180,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) {
@@ -6773,8 +6772,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>())
@@ -6813,6 +6811,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;
@@ -6821,7 +6820,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, *FiniBB,
OutlinedFn, CapturedVars);
} else {
OMPBuilderCBHelpers::EmitOMPInlinedRegionBody(
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 9976a411fd6739..490267aaefd86c 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!");
@@ -2060,10 +2060,10 @@ class CodeGenFunction : public CodeGenTypeCache {
InsertPointTy CodeGenIP,
Twine RegionName);
- static void EmitCaptureStmt(CodeGenFunction &CGF, InsertPointTy CodeGenIP,
+ static void EmitCaptureStmt(CodeGenFunction &CGF,
+ llvm::BasicBlock *CodeGenIPBB,
llvm::BasicBlock &FiniBB, llvm::Function *Fn,
ArrayRef<llvm::Value *> Args) {
- llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
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/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index a5045e483c7f8c..24b542bd7b3587 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2532,7 +2532,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.
@@ -2562,7 +2562,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,
@@ -4617,21 +4617,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 ec07b746d7ed43..1860526d257c1d 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(Point);
Builder.SetCurrentDebugLocation(DbgLoc);
}
};
diff --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
index d0680373108352..ae2f0f998d85d4 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(Point);
Builder.SetCurrentDebugLocation(DbgLoc);
}
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index cef07379ed64a8..2c60bf3d67a9cd 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 = 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 = 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 = 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::InsertPointOrErrorTy 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::InsertPointOrErrorTy 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.
@@ -6885,7 +6873,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");
@@ -7057,7 +7046,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());
@@ -7568,7 +7557,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);
@@ -8238,7 +8227,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!!");
@@ -8288,7 +8277,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(
@@ -8305,12 +8294,13 @@ 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()))
+ BasicBlock *FinBB = FinIP.getNodeParent();
+ if (Error Err = Fi.mergeFiniBB(Builder, FinBB))
return std::move(Err);
// Exit condition: insertion point is before the terminator of the new Fini
// block
- Builder.SetInsertPoint(FinIP.getBlock()->getTerminator());
+ Builder.SetInsertPoint(FinBB->getTerminator());
}
if (!ExitCall)
@@ -8320,14 +8310,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);
@@ -8344,7 +8333,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);
@@ -8753,7 +8742,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,
@@ -9371,10 +9360,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);
@@ -9446,8 +9433,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);
@@ -9562,9 +9548,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);
@@ -9834,13 +9817,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;
@@ -12194,8 +12176,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;
@@ -12206,7 +12188,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(
@@ -12266,7 +12248,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createDistribute(
if (!updateToLocation(Loc))
return InsertPointTy();
- BasicBlock *OuterAllocaBB = OuterAllocIP.getBlock();
+ BasicBlock *OuterAllocaBB = OuterAllocIP.getNodeParent();
if (OuterAllocaBB == Builder.GetInsertBlock()) {
BasicBlock *BodyBB =
@@ -12281,8 +12263,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;
@@ -12290,7 +12272,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());
@@ -12890,9 +12872,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,
@@ -12934,7 +12916,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 7bf628ce27fa88..6f270eb27fc0b3 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 c18cca1b295830..aad520d25212aa 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 59390da9f2d3f8..2010533b7e6db4 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -417,9 +417,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});
@@ -450,7 +450,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);
@@ -478,9 +478,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});
@@ -517,7 +517,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);
@@ -544,9 +544,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});
@@ -577,7 +577,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);
@@ -668,8 +668,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();
};
@@ -703,8 +703,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,
@@ -797,8 +796,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();
};
@@ -832,8 +831,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,
@@ -921,22 +919,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),
@@ -1024,35 +1021,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),
@@ -1168,8 +1164,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,
@@ -1293,8 +1288,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),
@@ -1380,8 +1374,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,
@@ -1415,8 +1408,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();
};
@@ -1548,7 +1541,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);
@@ -1784,9 +1777,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;
@@ -2599,8 +2592,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,
@@ -2724,8 +2716,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);
@@ -2923,7 +2914,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()));
@@ -2931,8 +2922,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);
@@ -2947,8 +2938,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,
@@ -3003,7 +2994,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()));
@@ -3011,8 +3002,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);
@@ -3027,8 +3018,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);
@@ -3083,8 +3074,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
@@ -3095,8 +3086,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();
@@ -3161,8 +3152,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;
@@ -3245,8 +3235,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;
@@ -3333,8 +3322,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);
@@ -3344,8 +3333,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]"
@@ -3409,8 +3398,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);
@@ -3420,8 +3409,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"
@@ -3510,7 +3499,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()));
@@ -3518,8 +3507,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);
@@ -3534,8 +3523,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(
@@ -3602,7 +3591,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()));
@@ -3610,8 +3599,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);
@@ -3626,8 +3615,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(
@@ -3722,7 +3711,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()));
@@ -3730,8 +3719,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);
@@ -3746,9 +3735,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(
@@ -3838,8 +3827,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);
@@ -3882,8 +3870,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);
@@ -3934,8 +3921,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);
@@ -3981,8 +3967,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));
@@ -4026,8 +4011,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) {
@@ -4094,8 +4078,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) {
@@ -4161,8 +4144,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) {
@@ -4236,8 +4218,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; };
@@ -4577,8 +4558,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();
@@ -4675,8 +4655,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();
};
@@ -5198,7 +5178,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();
}
@@ -5206,7 +5186,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);
@@ -5216,7 +5196,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();
}
@@ -5224,7 +5204,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);
@@ -5245,8 +5225,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;
@@ -5638,8 +5617,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;
@@ -5844,8 +5822,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));
@@ -5877,15 +5854,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 =
@@ -5902,8 +5879,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),
@@ -5986,8 +5962,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,
@@ -6085,8 +6060,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);
@@ -6126,8 +6100,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(
@@ -6188,8 +6161,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;
@@ -6251,8 +6223,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;
@@ -6320,8 +6291,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;
@@ -6689,8 +6659,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;
@@ -7045,12 +7014,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;
@@ -7176,8 +7144,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;
@@ -7355,7 +7322,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 =
@@ -7395,8 +7362,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;
@@ -7474,20 +7440,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();
@@ -7593,13 +7557,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();
@@ -7628,14 +7590,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();
@@ -7665,8 +7625,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;
{
@@ -7676,11 +7635,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();
@@ -7901,22 +7860,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();
@@ -7978,7 +7935,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()));
}
@@ -8001,14 +7958,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);
@@ -8079,20 +8036,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();
@@ -8191,13 +8146,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();
@@ -8468,11 +8421,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);
},
@@ -8498,7 +8449,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 530c1a260ddcc0..1f0f7314f71fd5 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
@@ -1394,7 +1393,7 @@ allocReductionVars(T op, ArrayRef<BlockArgument> reductionArgs,
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,42 +1990,41 @@ 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 the allocaTerminator since the alloca block was split above.
+ allocaTerminator = allocaBB->getTerminator();
+ // The new terminator is an uncondition branch created by the splitBB above.
+ assert(allocaTerminator->getNumSuccessors() == 1 &&
+ "This is an unconditional branch created by splitBB");
+ allocaIP = allocaTerminator->getIterator();
llvm::Instruction *allocatorTerminator = nullptr;
llvm::BasicBlock *afterAllocatorAllocations = nullptr;
if (allocatorIP) {
- allocatorTerminator = allocatorIP->getBlock()->getTerminator();
+ llvm::BasicBlock *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");
+ allocatorTerminator = allocatorBB->getTerminator();
+ assert(allocatorTerminator->getNumSuccessors() == 1 &&
+ "This is an unconditional branch created by splitBB");
}
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();
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();
- assert(allocatorTerminator->getNumSuccessors() == 1 &&
- "This is an unconditional branch created by splitBB");
- }
llvm::DataLayout dataLayout = builder.GetInsertBlock()->getDataLayout();
llvm::BasicBlock *afterAllocas = allocaTerminator->getSuccessor(0);
@@ -2764,7 +2761,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 +2778,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 +3478,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 +3617,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 +3997,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 +4255,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 +4913,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 +4932,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 +4996,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 +5082,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 +5472,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 +9043,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 +9652,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 cfe-commits
mailing list