aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorAkash Banerjee <akash.banerjee@amd.com>2025-02-18 17:55:48 +0000
committerGitHub <noreply@github.com>2025-02-18 17:55:48 +0000
commit785a5b4676e7aa77904babb9f66e862b5fc39295 (patch)
tree707f769c5376874a88d6ea8d66a380b22fbf6870 /llvm
parentd6ab12c7cc7058776ad46fe0767080b1e7710cc2 (diff)
downloadllvm-785a5b4676e7aa77904babb9f66e862b5fc39295.zip
llvm-785a5b4676e7aa77904babb9f66e862b5fc39295.tar.gz
llvm-785a5b4676e7aa77904babb9f66e862b5fc39295.tar.bz2
[MLIR][OpenMP] Add LLVM translation support for OpenMP UserDefinedMappers (#124746)
This patch adds OpenMPToLLVMIRTranslation support for the OpenMP Declare Mapper directive. Since both MLIR and Clang now support custom mappers, I've changed the respective function params to no longer be optional as well. Depends on #121005
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h42
-rw-r--r--llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp121
-rw-r--r--llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp66
3 files changed, 141 insertions, 88 deletions
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index d25077c..33b3d7b 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2399,6 +2399,7 @@ public:
CurInfo.NonContigInfo.Strides.end());
}
};
+ using MapInfosOrErrorTy = Expected<MapInfosTy &>;
/// Callback function type for functions emitting the host fallback code that
/// is executed when the kernel launch fails. It takes an insertion point as
@@ -2407,6 +2408,11 @@ public:
using EmitFallbackCallbackTy =
function_ref<InsertPointOrErrorTy(InsertPointTy)>;
+ // Callback function type for emitting and fetching user defined custom
+ // mappers.
+ using CustomMapperCallbackTy =
+ function_ref<Expected<Function *>(unsigned int)>;
+
/// Generate a target region entry call and host fallback call.
///
/// \param Loc The location at which the request originated and is fulfilled.
@@ -2473,11 +2479,11 @@ public:
/// return nullptr by reference. Accepts a reference to a MapInfosTy object
/// that contains information generated for mappable clauses,
/// including base pointers, pointers, sizes, map types, user-defined mappers.
- void emitOffloadingArrays(
+ Error emitOffloadingArrays(
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
- TargetDataInfo &Info, bool IsNonContiguous = false,
- function_ref<void(unsigned int, Value *)> DeviceAddrCB = nullptr,
- function_ref<Value *(unsigned int)> CustomMapperCB = nullptr);
+ TargetDataInfo &Info, CustomMapperCallbackTy CustomMapperCB,
+ bool IsNonContiguous = false,
+ function_ref<void(unsigned int, Value *)> DeviceAddrCB = nullptr);
/// Allocates memory for and populates the arrays required for offloading
/// (offload_{baseptrs|ptrs|mappers|sizes|maptypes|mapnames}). Then, it
@@ -2485,12 +2491,12 @@ public:
/// library. In essence, this function is a combination of
/// emitOffloadingArrays and emitOffloadingArraysArgument and should arguably
/// be preferred by clients of OpenMPIRBuilder.
- void emitOffloadingArraysAndArgs(
+ Error emitOffloadingArraysAndArgs(
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &Info,
TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
- bool IsNonContiguous = false, bool ForEndCall = false,
- function_ref<void(unsigned int, Value *)> DeviceAddrCB = nullptr,
- function_ref<Value *(unsigned int)> CustomMapperCB = nullptr);
+ CustomMapperCallbackTy CustomMapperCB, bool IsNonContiguous = false,
+ bool ForEndCall = false,
+ function_ref<void(unsigned int, Value *)> DeviceAddrCB = nullptr);
/// Creates offloading entry for the provided entry ID \a ID, address \a
/// Addr, size \a Size, and flags \a Flags.
@@ -2950,12 +2956,12 @@ public:
/// \param FuncName Optional param to specify mapper function name.
/// \param CustomMapperCB Optional callback to generate code related to
/// custom mappers.
- Function *emitUserDefinedMapper(
- function_ref<MapInfosTy &(InsertPointTy CodeGenIP, llvm::Value *PtrPHI,
- llvm::Value *BeginArg)>
+ Expected<Function *> emitUserDefinedMapper(
+ function_ref<MapInfosOrErrorTy(
+ InsertPointTy CodeGenIP, llvm::Value *PtrPHI, llvm::Value *BeginArg)>
PrivAndGenMapInfoCB,
llvm::Type *ElemTy, StringRef FuncName,
- function_ref<bool(unsigned int, Function **)> CustomMapperCB = nullptr);
+ CustomMapperCallbackTy CustomMapperCB);
/// Generator for '#omp target data'
///
@@ -2969,21 +2975,21 @@ public:
/// \param IfCond Value which corresponds to the if clause condition.
/// \param Info Stores all information realted to the Target Data directive.
/// \param GenMapInfoCB Callback that populates the MapInfos and returns.
+ /// \param CustomMapperCB Callback to generate code related to
+ /// custom mappers.
/// \param BodyGenCB Optional Callback to generate the region code.
/// \param DeviceAddrCB Optional callback to generate code related to
/// use_device_ptr and use_device_addr.
- /// \param CustomMapperCB Optional callback to generate code related to
- /// custom mappers.
InsertPointOrErrorTy createTargetData(
const LocationDescription &Loc, InsertPointTy AllocaIP,
InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
TargetDataInfo &Info, GenMapInfoCallbackTy GenMapInfoCB,
+ CustomMapperCallbackTy CustomMapperCB,
omp::RuntimeFunction *MapperFunc = nullptr,
function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
BodyGenTy BodyGenType)>
BodyGenCB = nullptr,
function_ref<void(unsigned int, Value *)> DeviceAddrCB = nullptr,
- function_ref<Value *(unsigned int)> CustomMapperCB = nullptr,
Value *SrcLocInfo = nullptr);
using TargetBodyGenCallbackTy = function_ref<InsertPointOrErrorTy(
@@ -2999,6 +3005,7 @@ public:
/// \param IsOffloadEntry whether it is an offload entry.
/// \param CodeGenIP The insertion point where the call to the outlined
/// function should be emitted.
+ /// \param Info Stores all information realted to the Target directive.
/// \param EntryInfo The entry information about the function.
/// \param DefaultAttrs Structure containing the default attributes, including
/// numbers of threads and teams to launch the kernel with.
@@ -3010,6 +3017,8 @@ public:
/// \param BodyGenCB Callback that will generate the region code.
/// \param ArgAccessorFuncCB Callback that will generate accessors
/// instructions for passed in target arguments where neccessary
+ /// \param CustomMapperCB Callback to generate code related to
+ /// custom mappers.
/// \param Dependencies A vector of DependData objects that carry
/// dependency information as passed in the depend clause
/// \param HasNowait Whether the target construct has a `nowait` clause or
@@ -3017,13 +3026,14 @@ public:
InsertPointOrErrorTy createTarget(
const LocationDescription &Loc, bool IsOffloadEntry,
OpenMPIRBuilder::InsertPointTy AllocaIP,
- OpenMPIRBuilder::InsertPointTy CodeGenIP,
+ OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetDataInfo &Info,
TargetRegionEntryInfo &EntryInfo,
const TargetKernelDefaultAttrs &DefaultAttrs,
const TargetKernelRuntimeAttrs &RuntimeAttrs, Value *IfCond,
SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
TargetBodyGenCallbackTy BodyGenCB,
TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
+ CustomMapperCallbackTy CustomMapperCB,
SmallVector<DependData> Dependencies = {}, bool HasNowait = false);
/// Returns __kmpc_for_static_init_* runtime function for the specified
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 7ba23b0..18bc82f 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -6555,12 +6555,11 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
const LocationDescription &Loc, InsertPointTy AllocaIP,
InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
TargetDataInfo &Info, GenMapInfoCallbackTy GenMapInfoCB,
- omp::RuntimeFunction *MapperFunc,
+ CustomMapperCallbackTy CustomMapperCB, omp::RuntimeFunction *MapperFunc,
function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
BodyGenTy BodyGenType)>
BodyGenCB,
- function_ref<void(unsigned int, Value *)> DeviceAddrCB,
- function_ref<Value *(unsigned int)> CustomMapperCB, Value *SrcLocInfo) {
+ function_ref<void(unsigned int, Value *)> DeviceAddrCB, Value *SrcLocInfo) {
if (!updateToLocation(Loc))
return InsertPointTy();
@@ -6585,9 +6584,10 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
auto BeginThenGen = [&](InsertPointTy AllocaIP,
InsertPointTy CodeGenIP) -> Error {
MapInfo = &GenMapInfoCB(Builder.saveIP());
- emitOffloadingArrays(AllocaIP, Builder.saveIP(), *MapInfo, Info,
- /*IsNonContiguous=*/true, DeviceAddrCB,
- CustomMapperCB);
+ if (Error Err = emitOffloadingArrays(
+ AllocaIP, Builder.saveIP(), *MapInfo, Info, CustomMapperCB,
+ /*IsNonContiguous=*/true, DeviceAddrCB))
+ return Err;
TargetDataRTArgs RTArgs;
emitOffloadingArraysArgument(Builder, RTArgs, Info);
@@ -7486,26 +7486,31 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask(
return Builder.saveIP();
}
-void OpenMPIRBuilder::emitOffloadingArraysAndArgs(
+Error OpenMPIRBuilder::emitOffloadingArraysAndArgs(
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &Info,
- TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo, bool IsNonContiguous,
- bool ForEndCall, function_ref<void(unsigned int, Value *)> DeviceAddrCB,
- function_ref<Value *(unsigned int)> CustomMapperCB) {
- emitOffloadingArrays(AllocaIP, CodeGenIP, CombinedInfo, Info, IsNonContiguous,
- DeviceAddrCB, CustomMapperCB);
+ TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
+ CustomMapperCallbackTy CustomMapperCB, bool IsNonContiguous,
+ bool ForEndCall, function_ref<void(unsigned int, Value *)> DeviceAddrCB) {
+ if (Error Err =
+ emitOffloadingArrays(AllocaIP, CodeGenIP, CombinedInfo, Info,
+ CustomMapperCB, IsNonContiguous, DeviceAddrCB))
+ return Err;
emitOffloadingArraysArgument(Builder, RTArgs, Info, ForEndCall);
+ return Error::success();
}
static void
emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
OpenMPIRBuilder::InsertPointTy AllocaIP,
+ OpenMPIRBuilder::TargetDataInfo &Info,
const OpenMPIRBuilder::TargetKernelDefaultAttrs &DefaultAttrs,
const OpenMPIRBuilder::TargetKernelRuntimeAttrs &RuntimeAttrs,
Value *IfCond, Function *OutlinedFn, Constant *OutlinedFnID,
SmallVectorImpl<Value *> &Args,
OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB,
- SmallVector<llvm::OpenMPIRBuilder::DependData> Dependencies = {},
- bool HasNoWait = false) {
+ OpenMPIRBuilder::CustomMapperCallbackTy CustomMapperCB,
+ SmallVector<llvm::OpenMPIRBuilder::DependData> Dependencies,
+ bool HasNoWait) {
// Generate a function call to the host fallback implementation of the target
// region. This is called by the host when no offload entry was generated for
// the target region and when the offloading call fails at runtime.
@@ -7576,16 +7581,13 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
auto &&EmitTargetCallThen =
[&](OpenMPIRBuilder::InsertPointTy AllocaIP,
OpenMPIRBuilder::InsertPointTy CodeGenIP) -> Error {
- OpenMPIRBuilder::TargetDataInfo Info(
- /*RequiresDevicePointerInfo=*/false,
- /*SeparateBeginEndCalls=*/true);
-
OpenMPIRBuilder::MapInfosTy &MapInfo = GenMapInfoCB(Builder.saveIP());
OpenMPIRBuilder::TargetDataRTArgs RTArgs;
- OMPBuilder.emitOffloadingArraysAndArgs(AllocaIP, Builder.saveIP(), Info,
- RTArgs, MapInfo,
- /*IsNonContiguous=*/true,
- /*ForEndCall=*/false);
+ if (Error Err = OMPBuilder.emitOffloadingArraysAndArgs(
+ AllocaIP, Builder.saveIP(), Info, RTArgs, MapInfo, CustomMapperCB,
+ /*IsNonContiguous=*/true,
+ /*ForEndCall=*/false))
+ return Err;
SmallVector<Value *, 3> NumTeamsC;
for (auto [DefaultVal, RuntimeVal] :
@@ -7687,13 +7689,15 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget(
const LocationDescription &Loc, bool IsOffloadEntry, InsertPointTy AllocaIP,
- InsertPointTy CodeGenIP, TargetRegionEntryInfo &EntryInfo,
+ InsertPointTy CodeGenIP, TargetDataInfo &Info,
+ TargetRegionEntryInfo &EntryInfo,
const TargetKernelDefaultAttrs &DefaultAttrs,
const TargetKernelRuntimeAttrs &RuntimeAttrs, Value *IfCond,
- SmallVectorImpl<Value *> &Args, GenMapInfoCallbackTy GenMapInfoCB,
+ SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
OpenMPIRBuilder::TargetBodyGenCallbackTy CBFunc,
OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
- SmallVector<DependData> Dependencies, bool HasNowait) {
+ CustomMapperCallbackTy CustomMapperCB, SmallVector<DependData> Dependencies,
+ bool HasNowait) {
if (!updateToLocation(Loc))
return InsertPointTy();
@@ -7707,16 +7711,16 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget(
// and ArgAccessorFuncCB
if (Error Err = emitTargetOutlinedFunction(
*this, Builder, IsOffloadEntry, EntryInfo, DefaultAttrs, OutlinedFn,
- OutlinedFnID, Args, CBFunc, ArgAccessorFuncCB))
+ OutlinedFnID, Inputs, CBFunc, ArgAccessorFuncCB))
return Err;
// If we are not on the target device, then we need to generate code
// to make a remote call (offload) to the previously outlined function
// that represents the target region. Do that now.
if (!Config.isTargetDevice())
- emitTargetCall(*this, Builder, AllocaIP, DefaultAttrs, RuntimeAttrs, IfCond,
- OutlinedFn, OutlinedFnID, Args, GenMapInfoCB, Dependencies,
- HasNowait);
+ emitTargetCall(*this, Builder, AllocaIP, Info, DefaultAttrs, RuntimeAttrs,
+ IfCond, OutlinedFn, OutlinedFnID, Inputs, GenMapInfoCB,
+ CustomMapperCB, Dependencies, HasNowait);
return Builder.saveIP();
}
@@ -8041,12 +8045,11 @@ void OpenMPIRBuilder::emitUDMapperArrayInitOrDel(
OffloadingArgs);
}
-Function *OpenMPIRBuilder::emitUserDefinedMapper(
- function_ref<MapInfosTy &(InsertPointTy CodeGenIP, llvm::Value *PtrPHI,
- llvm::Value *BeginArg)>
+Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
+ function_ref<MapInfosOrErrorTy(InsertPointTy CodeGenIP, llvm::Value *PtrPHI,
+ llvm::Value *BeginArg)>
GenMapInfoCB,
- Type *ElemTy, StringRef FuncName,
- function_ref<bool(unsigned int, Function **)> CustomMapperCB) {
+ Type *ElemTy, StringRef FuncName, CustomMapperCallbackTy CustomMapperCB) {
SmallVector<Type *> Params;
Params.emplace_back(Builder.getPtrTy());
Params.emplace_back(Builder.getPtrTy());
@@ -8117,7 +8120,9 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
PtrPHI->addIncoming(PtrBegin, HeadBB);
// Get map clause information. Fill up the arrays with all mapped variables.
- MapInfosTy &Info = GenMapInfoCB(Builder.saveIP(), PtrPHI, BeginIn);
+ MapInfosOrErrorTy Info = GenMapInfoCB(Builder.saveIP(), PtrPHI, BeginIn);
+ if (!Info)
+ return Info.takeError();
// Call the runtime API __tgt_mapper_num_components to get the number of
// pre-existing components.
@@ -8129,20 +8134,20 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
Builder.CreateShl(PreviousSize, Builder.getInt64(getFlagMemberOffset()));
// Fill up the runtime mapper handle for all components.
- for (unsigned I = 0; I < Info.BasePointers.size(); ++I) {
+ for (unsigned I = 0; I < Info->BasePointers.size(); ++I) {
Value *CurBaseArg =
- Builder.CreateBitCast(Info.BasePointers[I], Builder.getPtrTy());
+ Builder.CreateBitCast(Info->BasePointers[I], Builder.getPtrTy());
Value *CurBeginArg =
- Builder.CreateBitCast(Info.Pointers[I], Builder.getPtrTy());
- Value *CurSizeArg = Info.Sizes[I];
- Value *CurNameArg = Info.Names.size()
- ? Info.Names[I]
+ Builder.CreateBitCast(Info->Pointers[I], Builder.getPtrTy());
+ Value *CurSizeArg = Info->Sizes[I];
+ Value *CurNameArg = Info->Names.size()
+ ? Info->Names[I]
: Constant::getNullValue(Builder.getPtrTy());
// Extract the MEMBER_OF field from the map type.
Value *OriMapType = Builder.getInt64(
static_cast<std::underlying_type_t<OpenMPOffloadMappingFlags>>(
- Info.Types[I]));
+ Info->Types[I]));
Value *MemberMapType =
Builder.CreateNUWAdd(OriMapType, ShiftedPreviousSize);
@@ -8224,10 +8229,13 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
Value *OffloadingArgs[] = {MapperHandle, CurBaseArg, CurBeginArg,
CurSizeArg, CurMapType, CurNameArg};
- Function *ChildMapperFn = nullptr;
- if (CustomMapperCB && CustomMapperCB(I, &ChildMapperFn)) {
+
+ auto ChildMapperFn = CustomMapperCB(I);
+ if (!ChildMapperFn)
+ return ChildMapperFn.takeError();
+ if (*ChildMapperFn) {
// Call the corresponding mapper function.
- Builder.CreateCall(ChildMapperFn, OffloadingArgs)->setDoesNotThrow();
+ Builder.CreateCall(*ChildMapperFn, OffloadingArgs)->setDoesNotThrow();
} else {
// Call the runtime API __tgt_push_mapper_component to fill up the runtime
// data structure.
@@ -8261,18 +8269,18 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
return MapperFn;
}
-void OpenMPIRBuilder::emitOffloadingArrays(
+Error OpenMPIRBuilder::emitOffloadingArrays(
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
- TargetDataInfo &Info, bool IsNonContiguous,
- function_ref<void(unsigned int, Value *)> DeviceAddrCB,
- function_ref<Value *(unsigned int)> CustomMapperCB) {
+ TargetDataInfo &Info, CustomMapperCallbackTy CustomMapperCB,
+ bool IsNonContiguous,
+ function_ref<void(unsigned int, Value *)> DeviceAddrCB) {
// Reset the array information.
Info.clearArrayInfo();
Info.NumberOfPtrs = CombinedInfo.BasePointers.size();
if (Info.NumberOfPtrs == 0)
- return;
+ return Error::success();
Builder.restoreIP(AllocaIP);
// Detect if we have any capture size requiring runtime evaluation of the
@@ -8436,9 +8444,13 @@ void OpenMPIRBuilder::emitOffloadingArrays(
// Fill up the mapper array.
unsigned IndexSize = M.getDataLayout().getIndexSizeInBits(0);
Value *MFunc = ConstantPointerNull::get(PtrTy);
- if (CustomMapperCB)
- if (Value *CustomMFunc = CustomMapperCB(I))
- MFunc = Builder.CreatePointerCast(CustomMFunc, PtrTy);
+
+ auto CustomMFunc = CustomMapperCB(I);
+ if (!CustomMFunc)
+ return CustomMFunc.takeError();
+ if (*CustomMFunc)
+ MFunc = Builder.CreatePointerCast(*CustomMFunc, PtrTy);
+
Value *MAddr = Builder.CreateInBoundsGEP(
MappersArray->getAllocatedType(), MappersArray,
{Builder.getIntN(IndexSize, 0), Builder.getIntN(IndexSize, I)});
@@ -8448,8 +8460,9 @@ void OpenMPIRBuilder::emitOffloadingArrays(
if (!IsNonContiguous || CombinedInfo.NonContigInfo.Offsets.empty() ||
Info.NumberOfPtrs == 0)
- return;
+ return Error::success();
emitNonContiguousDescriptor(AllocaIP, CodeGenIP, CombinedInfo, Info);
+ return Error::success();
}
void OpenMPIRBuilder::emitBranch(BasicBlock *Target) {
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index 83c8f7e9..a1ea784 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -5928,6 +5928,7 @@ TEST_F(OpenMPIRBuilderTest, TargetEnterData) {
return CombinedInfo;
};
+ auto CustomMapperCB = [&](unsigned int I) { return nullptr; };
llvm::OpenMPIRBuilder::TargetDataInfo Info(
/*RequiresDevicePointerInfo=*/false,
/*SeparateBeginEndCalls=*/true);
@@ -5939,7 +5940,7 @@ TEST_F(OpenMPIRBuilderTest, TargetEnterData) {
OpenMPIRBuilder::InsertPointTy, AfterIP,
OMPBuilder.createTargetData(
Loc, AllocaIP, Builder.saveIP(), Builder.getInt64(DeviceID),
- /* IfCond= */ nullptr, Info, GenMapInfoCB, &RTLFunc));
+ /* IfCond= */ nullptr, Info, GenMapInfoCB, CustomMapperCB, &RTLFunc));
Builder.restoreIP(AfterIP);
CallInst *TargetDataCall = dyn_cast<CallInst>(&BB->back());
@@ -5990,6 +5991,7 @@ TEST_F(OpenMPIRBuilderTest, TargetExitData) {
return CombinedInfo;
};
+ auto CustomMapperCB = [&](unsigned int I) { return nullptr; };
llvm::OpenMPIRBuilder::TargetDataInfo Info(
/*RequiresDevicePointerInfo=*/false,
/*SeparateBeginEndCalls=*/true);
@@ -6001,7 +6003,7 @@ TEST_F(OpenMPIRBuilderTest, TargetExitData) {
OpenMPIRBuilder::InsertPointTy, AfterIP,
OMPBuilder.createTargetData(
Loc, AllocaIP, Builder.saveIP(), Builder.getInt64(DeviceID),
- /* IfCond= */ nullptr, Info, GenMapInfoCB, &RTLFunc));
+ /* IfCond= */ nullptr, Info, GenMapInfoCB, CustomMapperCB, &RTLFunc));
Builder.restoreIP(AfterIP);
CallInst *TargetDataCall = dyn_cast<CallInst>(&BB->back());
@@ -6074,6 +6076,7 @@ TEST_F(OpenMPIRBuilderTest, TargetDataRegion) {
return CombinedInfo;
};
+ auto CustomMapperCB = [&](unsigned int I) { return nullptr; };
llvm::OpenMPIRBuilder::TargetDataInfo Info(
/*RequiresDevicePointerInfo=*/true,
/*SeparateBeginEndCalls=*/true);
@@ -6110,9 +6113,10 @@ TEST_F(OpenMPIRBuilderTest, TargetDataRegion) {
ASSERT_EXPECTED_INIT(
OpenMPIRBuilder::InsertPointTy, TargetDataIP1,
- OMPBuilder.createTargetData(
- Loc, AllocaIP, Builder.saveIP(), Builder.getInt64(DeviceID),
- /* IfCond= */ nullptr, Info, GenMapInfoCB, nullptr, BodyCB));
+ OMPBuilder.createTargetData(Loc, AllocaIP, Builder.saveIP(),
+ Builder.getInt64(DeviceID),
+ /* IfCond= */ nullptr, Info, GenMapInfoCB,
+ CustomMapperCB, nullptr, BodyCB));
Builder.restoreIP(TargetDataIP1);
CallInst *TargetDataCall = dyn_cast<CallInst>(&BB->back());
@@ -6138,9 +6142,10 @@ TEST_F(OpenMPIRBuilderTest, TargetDataRegion) {
};
ASSERT_EXPECTED_INIT(
OpenMPIRBuilder::InsertPointTy, TargetDataIP2,
- OMPBuilder.createTargetData(
- Loc, AllocaIP, Builder.saveIP(), Builder.getInt64(DeviceID),
- /* IfCond= */ nullptr, Info, GenMapInfoCB, nullptr, BodyTargetCB));
+ OMPBuilder.createTargetData(Loc, AllocaIP, Builder.saveIP(),
+ Builder.getInt64(DeviceID),
+ /* IfCond= */ nullptr, Info, GenMapInfoCB,
+ CustomMapperCB, nullptr, BodyTargetCB));
Builder.restoreIP(TargetDataIP2);
EXPECT_TRUE(CheckDevicePassBodyGen);
@@ -6241,6 +6246,11 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
return CombinedInfos;
};
+ auto CustomMapperCB = [&](unsigned int I) { return nullptr; };
+ llvm::OpenMPIRBuilder::TargetDataInfo Info(
+ /*RequiresDevicePointerInfo=*/false,
+ /*SeparateBeginEndCalls=*/true);
+
TargetRegionEntryInfo EntryInfo("func", 42, 4711, 17);
OpenMPIRBuilder::LocationDescription OmpLoc({Builder.saveIP(), DL});
OpenMPIRBuilder::TargetKernelRuntimeAttrs RuntimeAttrs;
@@ -6254,9 +6264,10 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
ASSERT_EXPECTED_INIT(
OpenMPIRBuilder::InsertPointTy, AfterIP,
OMPBuilder.createTarget(OmpLoc, /*IsOffloadEntry=*/true, Builder.saveIP(),
- Builder.saveIP(), EntryInfo, DefaultAttrs,
+ Builder.saveIP(), Info, EntryInfo, DefaultAttrs,
RuntimeAttrs, /*IfCond=*/nullptr, Inputs,
- GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB));
+ GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB,
+ CustomMapperCB, {}, false));
EXPECT_EQ(DL, Builder.getCurrentDebugLocation());
Builder.restoreIP(AfterIP);
@@ -6400,6 +6411,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
return CombinedInfos;
};
+ auto CustomMapperCB = [&](unsigned int I) { return nullptr; };
auto BodyGenCB = [&](OpenMPIRBuilder::InsertPointTy AllocaIP,
OpenMPIRBuilder::InsertPointTy CodeGenIP)
-> OpenMPIRBuilder::InsertPointTy {
@@ -6419,13 +6431,17 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = {
/*ExecFlags=*/omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC,
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
+ llvm::OpenMPIRBuilder::TargetDataInfo Info(
+ /*RequiresDevicePointerInfo=*/false,
+ /*SeparateBeginEndCalls=*/true);
ASSERT_EXPECTED_INIT(
OpenMPIRBuilder::InsertPointTy, AfterIP,
OMPBuilder.createTarget(Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP,
- EntryInfo, DefaultAttrs, RuntimeAttrs,
+ Info, EntryInfo, DefaultAttrs, RuntimeAttrs,
/*IfCond=*/nullptr, CapturedArgs, GenMapInfoCB,
- BodyGenCB, SimpleArgAccessorCB));
+ BodyGenCB, SimpleArgAccessorCB, CustomMapperCB,
+ {}, false));
EXPECT_EQ(DL, Builder.getCurrentDebugLocation());
Builder.restoreIP(AfterIP);
@@ -6549,6 +6565,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionSPMD) {
F->setName("func");
IRBuilder<> Builder(BB);
+ auto CustomMapperCB = [&](unsigned int I) { return nullptr; };
auto BodyGenCB = [&](InsertPointTy,
InsertPointTy CodeGenIP) -> InsertPointTy {
Builder.restoreIP(CodeGenIP);
@@ -6576,13 +6593,17 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionSPMD) {
/*ExecFlags=*/omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_SPMD,
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
RuntimeAttrs.LoopTripCount = Builder.getInt64(1000);
+ llvm::OpenMPIRBuilder::TargetDataInfo Info(
+ /*RequiresDevicePointerInfo=*/false,
+ /*SeparateBeginEndCalls=*/true);
ASSERT_EXPECTED_INIT(
OpenMPIRBuilder::InsertPointTy, AfterIP,
OMPBuilder.createTarget(OmpLoc, /*IsOffloadEntry=*/true, Builder.saveIP(),
- Builder.saveIP(), EntryInfo, DefaultAttrs,
+ Builder.saveIP(), Info, EntryInfo, DefaultAttrs,
RuntimeAttrs, /*IfCond=*/nullptr, Inputs,
- GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB));
+ GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB,
+ CustomMapperCB));
Builder.restoreIP(AfterIP);
OMPBuilder.finalize();
@@ -6663,6 +6684,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDeviceSPMD) {
return CombinedInfos;
};
+ auto CustomMapperCB = [&](unsigned int I) { return nullptr; };
auto BodyGenCB = [&](OpenMPIRBuilder::InsertPointTy,
OpenMPIRBuilder::InsertPointTy CodeGenIP)
-> OpenMPIRBuilder::InsertPointTy {
@@ -6679,13 +6701,16 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDeviceSPMD) {
OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = {
/*ExecFlags=*/omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_SPMD,
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
+ llvm::OpenMPIRBuilder::TargetDataInfo Info(
+ /*RequiresDevicePointerInfo=*/false,
+ /*SeparateBeginEndCalls=*/true);
ASSERT_EXPECTED_INIT(
OpenMPIRBuilder::InsertPointTy, AfterIP,
OMPBuilder.createTarget(Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP,
- EntryInfo, DefaultAttrs, RuntimeAttrs,
+ Info, EntryInfo, DefaultAttrs, RuntimeAttrs,
/*IfCond=*/nullptr, CapturedArgs, GenMapInfoCB,
- BodyGenCB, SimpleArgAccessorCB));
+ BodyGenCB, SimpleArgAccessorCB, CustomMapperCB));
Builder.restoreIP(AfterIP);
Builder.CreateRetVoid();
@@ -6779,6 +6804,7 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
llvm::Value *RaiseAlloca = nullptr;
+ auto CustomMapperCB = [&](unsigned int I) { return nullptr; };
auto BodyGenCB = [&](OpenMPIRBuilder::InsertPointTy AllocaIP,
OpenMPIRBuilder::InsertPointTy CodeGenIP)
-> OpenMPIRBuilder::InsertPointTy {
@@ -6799,13 +6825,17 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = {
/*ExecFlags=*/omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC,
/*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0};
+ llvm::OpenMPIRBuilder::TargetDataInfo Info(
+ /*RequiresDevicePointerInfo=*/false,
+ /*SeparateBeginEndCalls=*/true);
ASSERT_EXPECTED_INIT(
OpenMPIRBuilder::InsertPointTy, AfterIP,
OMPBuilder.createTarget(Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP,
- EntryInfo, DefaultAttrs, RuntimeAttrs,
+ Info, EntryInfo, DefaultAttrs, RuntimeAttrs,
/*IfCond=*/nullptr, CapturedArgs, GenMapInfoCB,
- BodyGenCB, SimpleArgAccessorCB));
+ BodyGenCB, SimpleArgAccessorCB, CustomMapperCB,
+ {}, false));
EXPECT_EQ(DL, Builder.getCurrentDebugLocation());
Builder.restoreIP(AfterIP);