@@ -6549,8 +6549,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
6549
6549
const LocationDescription &Loc, InsertPointTy AllocaIP,
6550
6550
InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
6551
6551
TargetDataInfo &Info, GenMapInfoCallbackTy GenMapInfoCB,
6552
- function_ref<Value *(unsigned int)> CustomMapperCB,
6553
- omp::RuntimeFunction *MapperFunc,
6552
+ CustomMapperCallbackTy CustomMapperCB, omp::RuntimeFunction *MapperFunc,
6554
6553
function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
6555
6554
BodyGenTy BodyGenType)>
6556
6555
BodyGenCB,
@@ -6579,9 +6578,10 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
6579
6578
auto BeginThenGen = [&](InsertPointTy AllocaIP,
6580
6579
InsertPointTy CodeGenIP) -> Error {
6581
6580
MapInfo = &GenMapInfoCB(Builder.saveIP());
6582
- emitOffloadingArrays(AllocaIP, Builder.saveIP(), *MapInfo, Info,
6583
- CustomMapperCB,
6584
- /*IsNonContiguous=*/true, DeviceAddrCB);
6581
+ if (Error Err = emitOffloadingArrays(
6582
+ AllocaIP, Builder.saveIP(), *MapInfo, Info, CustomMapperCB,
6583
+ /*IsNonContiguous=*/true, DeviceAddrCB))
6584
+ return Err;
6585
6585
6586
6586
TargetDataRTArgs RTArgs;
6587
6587
emitOffloadingArraysArgument(Builder, RTArgs, Info);
@@ -7392,14 +7392,17 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask(
7392
7392
return Builder.saveIP();
7393
7393
}
7394
7394
7395
- void OpenMPIRBuilder::emitOffloadingArraysAndArgs(
7395
+ Error OpenMPIRBuilder::emitOffloadingArraysAndArgs(
7396
7396
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &Info,
7397
7397
TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
7398
- function_ref<Value *(unsigned int)> CustomMapperCB, bool IsNonContiguous,
7398
+ CustomMapperCallbackTy CustomMapperCB, bool IsNonContiguous,
7399
7399
bool ForEndCall, function_ref<void(unsigned int, Value *)> DeviceAddrCB) {
7400
- emitOffloadingArrays(AllocaIP, CodeGenIP, CombinedInfo, Info, CustomMapperCB,
7401
- IsNonContiguous, DeviceAddrCB);
7400
+ if (Error Err =
7401
+ emitOffloadingArrays(AllocaIP, CodeGenIP, CombinedInfo, Info,
7402
+ CustomMapperCB, IsNonContiguous, DeviceAddrCB))
7403
+ return Err;
7402
7404
emitOffloadingArraysArgument(Builder, RTArgs, Info, ForEndCall);
7405
+ return Error::success();
7403
7406
}
7404
7407
7405
7408
static void
@@ -7411,7 +7414,7 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
7411
7414
Value *IfCond, Function *OutlinedFn, Constant *OutlinedFnID,
7412
7415
SmallVectorImpl<Value *> &Args,
7413
7416
OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB,
7414
- function_ref<Value *(unsigned int)> CustomMapperCB,
7417
+ OpenMPIRBuilder::CustomMapperCallbackTy CustomMapperCB,
7415
7418
SmallVector<llvm::OpenMPIRBuilder::DependData> Dependencies,
7416
7419
bool HasNoWait) {
7417
7420
// Generate a function call to the host fallback implementation of the target
@@ -7486,10 +7489,11 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
7486
7489
OpenMPIRBuilder::InsertPointTy CodeGenIP) -> Error {
7487
7490
OpenMPIRBuilder::MapInfosTy &MapInfo = GenMapInfoCB(Builder.saveIP());
7488
7491
OpenMPIRBuilder::TargetDataRTArgs RTArgs;
7489
- OMPBuilder.emitOffloadingArraysAndArgs(AllocaIP, Builder.saveIP(), Info,
7490
- RTArgs, MapInfo, CustomMapperCB,
7491
- /*IsNonContiguous=*/true,
7492
- /*ForEndCall=*/false);
7492
+ if (Error Err = OMPBuilder.emitOffloadingArraysAndArgs(
7493
+ AllocaIP, Builder.saveIP(), Info, RTArgs, MapInfo, CustomMapperCB,
7494
+ /*IsNonContiguous=*/true,
7495
+ /*ForEndCall=*/false))
7496
+ return Err;
7493
7497
7494
7498
SmallVector<Value *, 3> NumTeamsC;
7495
7499
for (auto [DefaultVal, RuntimeVal] :
@@ -7598,8 +7602,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget(
7598
7602
SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
7599
7603
OpenMPIRBuilder::TargetBodyGenCallbackTy CBFunc,
7600
7604
OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
7601
- function_ref<Value *(unsigned int)> CustomMapperCB ,
7602
- SmallVector<DependData> Dependencies, bool HasNowait) {
7605
+ CustomMapperCallbackTy CustomMapperCB, SmallVector<DependData> Dependencies ,
7606
+ bool HasNowait) {
7603
7607
7604
7608
if (!updateToLocation(Loc))
7605
7609
return InsertPointTy();
@@ -7951,8 +7955,7 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
7951
7955
function_ref<MapInfosOrErrorTy(InsertPointTy CodeGenIP, llvm::Value *PtrPHI,
7952
7956
llvm::Value *BeginArg)>
7953
7957
GenMapInfoCB,
7954
- Type *ElemTy, StringRef FuncName,
7955
- function_ref<bool(unsigned int, Function **)> CustomMapperCB) {
7958
+ Type *ElemTy, StringRef FuncName, CustomMapperCallbackTy CustomMapperCB) {
7956
7959
SmallVector<Type *> Params;
7957
7960
Params.emplace_back(Builder.getPtrTy());
7958
7961
Params.emplace_back(Builder.getPtrTy());
@@ -8132,17 +8135,19 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
8132
8135
8133
8136
Value *OffloadingArgs[] = {MapperHandle, CurBaseArg, CurBeginArg,
8134
8137
CurSizeArg, CurMapType, CurNameArg};
8135
- Function *ChildMapperFn = nullptr;
8136
- if (CustomMapperCB && CustomMapperCB(I, &ChildMapperFn)) {
8138
+
8139
+ auto ChildMapperFn = CustomMapperCB(I);
8140
+ if (!ChildMapperFn)
8141
+ return ChildMapperFn.takeError();
8142
+ if (*ChildMapperFn)
8137
8143
// Call the corresponding mapper function.
8138
- Builder.CreateCall(ChildMapperFn, OffloadingArgs)->setDoesNotThrow();
8139
- } else {
8144
+ Builder.CreateCall(* ChildMapperFn, OffloadingArgs)->setDoesNotThrow();
8145
+ else
8140
8146
// Call the runtime API __tgt_push_mapper_component to fill up the runtime
8141
8147
// data structure.
8142
8148
Builder.CreateCall(
8143
8149
getOrCreateRuntimeFunction(M, OMPRTL___tgt_push_mapper_component),
8144
8150
OffloadingArgs);
8145
- }
8146
8151
}
8147
8152
8148
8153
// Update the pointer to point to the next element that needs to be mapped,
@@ -8169,9 +8174,9 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
8169
8174
return MapperFn;
8170
8175
}
8171
8176
8172
- void OpenMPIRBuilder::emitOffloadingArrays(
8177
+ Error OpenMPIRBuilder::emitOffloadingArrays(
8173
8178
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
8174
- TargetDataInfo &Info, function_ref<Value *(unsigned int)> CustomMapperCB,
8179
+ TargetDataInfo &Info, CustomMapperCallbackTy CustomMapperCB,
8175
8180
bool IsNonContiguous,
8176
8181
function_ref<void(unsigned int, Value *)> DeviceAddrCB) {
8177
8182
@@ -8180,7 +8185,7 @@ void OpenMPIRBuilder::emitOffloadingArrays(
8180
8185
Info.NumberOfPtrs = CombinedInfo.BasePointers.size();
8181
8186
8182
8187
if (Info.NumberOfPtrs == 0)
8183
- return;
8188
+ return Error::success() ;
8184
8189
8185
8190
Builder.restoreIP(AllocaIP);
8186
8191
// Detect if we have any capture size requiring runtime evaluation of the
@@ -8344,9 +8349,13 @@ void OpenMPIRBuilder::emitOffloadingArrays(
8344
8349
// Fill up the mapper array.
8345
8350
unsigned IndexSize = M.getDataLayout().getIndexSizeInBits(0);
8346
8351
Value *MFunc = ConstantPointerNull::get(PtrTy);
8347
- if (CustomMapperCB)
8348
- if (Value *CustomMFunc = CustomMapperCB(I))
8349
- MFunc = Builder.CreatePointerCast(CustomMFunc, PtrTy);
8352
+
8353
+ auto CustomMFunc = CustomMapperCB(I);
8354
+ if (!CustomMFunc)
8355
+ return CustomMFunc.takeError();
8356
+ if (*CustomMFunc)
8357
+ MFunc = Builder.CreatePointerCast(*CustomMFunc, PtrTy);
8358
+
8350
8359
Value *MAddr = Builder.CreateInBoundsGEP(
8351
8360
MappersArray->getAllocatedType(), MappersArray,
8352
8361
{Builder.getIntN(IndexSize, 0), Builder.getIntN(IndexSize, I)});
@@ -8356,8 +8365,9 @@ void OpenMPIRBuilder::emitOffloadingArrays(
8356
8365
8357
8366
if (!IsNonContiguous || CombinedInfo.NonContigInfo.Offsets.empty() ||
8358
8367
Info.NumberOfPtrs == 0)
8359
- return;
8368
+ return Error::success() ;
8360
8369
emitNonContiguousDescriptor(AllocaIP, CodeGenIP, CombinedInfo, Info);
8370
+ return Error::success();
8361
8371
}
8362
8372
8363
8373
void OpenMPIRBuilder::emitBranch(BasicBlock *Target) {
0 commit comments