@@ -6555,8 +6555,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
6555
6555
const LocationDescription &Loc, InsertPointTy AllocaIP,
6556
6556
InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
6557
6557
TargetDataInfo &Info, GenMapInfoCallbackTy GenMapInfoCB,
6558
- function_ref<Value *(unsigned int )> CustomMapperCB,
6559
- omp::RuntimeFunction *MapperFunc,
6558
+ CustomMapperCallbackTy CustomMapperCB, omp::RuntimeFunction *MapperFunc,
6560
6559
function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
6561
6560
BodyGenTy BodyGenType)>
6562
6561
BodyGenCB,
@@ -6585,9 +6584,10 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
6585
6584
auto BeginThenGen = [&](InsertPointTy AllocaIP,
6586
6585
InsertPointTy CodeGenIP) -> Error {
6587
6586
MapInfo = &GenMapInfoCB (Builder.saveIP ());
6588
- emitOffloadingArrays (AllocaIP, Builder.saveIP (), *MapInfo, Info,
6589
- CustomMapperCB,
6590
- /* IsNonContiguous=*/ true , DeviceAddrCB);
6587
+ if (Error Err = emitOffloadingArrays (
6588
+ AllocaIP, Builder.saveIP (), *MapInfo, Info, CustomMapperCB,
6589
+ /* IsNonContiguous=*/ true , DeviceAddrCB))
6590
+ return Err;
6591
6591
6592
6592
TargetDataRTArgs RTArgs;
6593
6593
emitOffloadingArraysArgument (Builder, RTArgs, Info);
@@ -7486,14 +7486,17 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask(
7486
7486
return Builder.saveIP ();
7487
7487
}
7488
7488
7489
- void OpenMPIRBuilder::emitOffloadingArraysAndArgs (
7489
+ Error OpenMPIRBuilder::emitOffloadingArraysAndArgs (
7490
7490
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &Info,
7491
7491
TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
7492
- function_ref<Value *( unsigned int )> CustomMapperCB, bool IsNonContiguous,
7492
+ CustomMapperCallbackTy CustomMapperCB, bool IsNonContiguous,
7493
7493
bool ForEndCall, function_ref<void (unsigned int , Value *)> DeviceAddrCB) {
7494
- emitOffloadingArrays (AllocaIP, CodeGenIP, CombinedInfo, Info, CustomMapperCB,
7495
- IsNonContiguous, DeviceAddrCB);
7494
+ if (Error Err =
7495
+ emitOffloadingArrays (AllocaIP, CodeGenIP, CombinedInfo, Info,
7496
+ CustomMapperCB, IsNonContiguous, DeviceAddrCB))
7497
+ return Err;
7496
7498
emitOffloadingArraysArgument (Builder, RTArgs, Info, ForEndCall);
7499
+ return Error::success ();
7497
7500
}
7498
7501
7499
7502
static void
@@ -7505,7 +7508,7 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
7505
7508
Value *IfCond, Function *OutlinedFn, Constant *OutlinedFnID,
7506
7509
SmallVectorImpl<Value *> &Args,
7507
7510
OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB,
7508
- function_ref<Value *( unsigned int )> CustomMapperCB,
7511
+ OpenMPIRBuilder::CustomMapperCallbackTy CustomMapperCB,
7509
7512
SmallVector<llvm::OpenMPIRBuilder::DependData> Dependencies,
7510
7513
bool HasNoWait) {
7511
7514
// Generate a function call to the host fallback implementation of the target
@@ -7580,10 +7583,11 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
7580
7583
OpenMPIRBuilder::InsertPointTy CodeGenIP) -> Error {
7581
7584
OpenMPIRBuilder::MapInfosTy &MapInfo = GenMapInfoCB (Builder.saveIP ());
7582
7585
OpenMPIRBuilder::TargetDataRTArgs RTArgs;
7583
- OMPBuilder.emitOffloadingArraysAndArgs (AllocaIP, Builder.saveIP (), Info,
7584
- RTArgs, MapInfo, CustomMapperCB,
7585
- /* IsNonContiguous=*/ true ,
7586
- /* ForEndCall=*/ false );
7586
+ if (Error Err = OMPBuilder.emitOffloadingArraysAndArgs (
7587
+ AllocaIP, Builder.saveIP (), Info, RTArgs, MapInfo, CustomMapperCB,
7588
+ /* IsNonContiguous=*/ true ,
7589
+ /* ForEndCall=*/ false ))
7590
+ return Err;
7587
7591
7588
7592
SmallVector<Value *, 3 > NumTeamsC;
7589
7593
for (auto [DefaultVal, RuntimeVal] :
@@ -7692,8 +7696,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget(
7692
7696
SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
7693
7697
OpenMPIRBuilder::TargetBodyGenCallbackTy CBFunc,
7694
7698
OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
7695
- function_ref<Value *( unsigned int )> CustomMapperCB ,
7696
- SmallVector<DependData> Dependencies, bool HasNowait) {
7699
+ CustomMapperCallbackTy CustomMapperCB, SmallVector<DependData> Dependencies ,
7700
+ bool HasNowait) {
7697
7701
7698
7702
if (!updateToLocation (Loc))
7699
7703
return InsertPointTy ();
@@ -8045,8 +8049,7 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
8045
8049
function_ref<MapInfosOrErrorTy(InsertPointTy CodeGenIP, llvm::Value *PtrPHI,
8046
8050
llvm::Value *BeginArg)>
8047
8051
GenMapInfoCB,
8048
- Type *ElemTy, StringRef FuncName,
8049
- function_ref<bool(unsigned int , Function **)> CustomMapperCB) {
8052
+ Type *ElemTy, StringRef FuncName, CustomMapperCallbackTy CustomMapperCB) {
8050
8053
SmallVector<Type *> Params;
8051
8054
Params.emplace_back (Builder.getPtrTy ());
8052
8055
Params.emplace_back (Builder.getPtrTy ());
@@ -8226,17 +8229,19 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
8226
8229
8227
8230
Value *OffloadingArgs[] = {MapperHandle, CurBaseArg, CurBeginArg,
8228
8231
CurSizeArg, CurMapType, CurNameArg};
8229
- Function *ChildMapperFn = nullptr ;
8230
- if (CustomMapperCB && CustomMapperCB (I, &ChildMapperFn)) {
8232
+
8233
+ auto ChildMapperFn = CustomMapperCB (I);
8234
+ if (!ChildMapperFn)
8235
+ return ChildMapperFn.takeError ();
8236
+ if (*ChildMapperFn)
8231
8237
// Call the corresponding mapper function.
8232
- Builder.CreateCall (ChildMapperFn, OffloadingArgs)->setDoesNotThrow ();
8233
- } else {
8238
+ Builder.CreateCall (* ChildMapperFn, OffloadingArgs)->setDoesNotThrow ();
8239
+ else
8234
8240
// Call the runtime API __tgt_push_mapper_component to fill up the runtime
8235
8241
// data structure.
8236
8242
Builder.CreateCall (
8237
8243
getOrCreateRuntimeFunction (M, OMPRTL___tgt_push_mapper_component),
8238
8244
OffloadingArgs);
8239
- }
8240
8245
}
8241
8246
8242
8247
// Update the pointer to point to the next element that needs to be mapped,
@@ -8263,9 +8268,9 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
8263
8268
return MapperFn;
8264
8269
}
8265
8270
8266
- void OpenMPIRBuilder::emitOffloadingArrays (
8271
+ Error OpenMPIRBuilder::emitOffloadingArrays (
8267
8272
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
8268
- TargetDataInfo &Info, function_ref<Value *( unsigned int )> CustomMapperCB,
8273
+ TargetDataInfo &Info, CustomMapperCallbackTy CustomMapperCB,
8269
8274
bool IsNonContiguous,
8270
8275
function_ref<void (unsigned int , Value *)> DeviceAddrCB) {
8271
8276
@@ -8274,7 +8279,7 @@ void OpenMPIRBuilder::emitOffloadingArrays(
8274
8279
Info.NumberOfPtrs = CombinedInfo.BasePointers .size ();
8275
8280
8276
8281
if (Info.NumberOfPtrs == 0 )
8277
- return ;
8282
+ return Error::success () ;
8278
8283
8279
8284
Builder.restoreIP (AllocaIP);
8280
8285
// Detect if we have any capture size requiring runtime evaluation of the
@@ -8438,9 +8443,13 @@ void OpenMPIRBuilder::emitOffloadingArrays(
8438
8443
// Fill up the mapper array.
8439
8444
unsigned IndexSize = M.getDataLayout ().getIndexSizeInBits (0 );
8440
8445
Value *MFunc = ConstantPointerNull::get (PtrTy);
8441
- if (CustomMapperCB)
8442
- if (Value *CustomMFunc = CustomMapperCB (I))
8443
- MFunc = Builder.CreatePointerCast (CustomMFunc, PtrTy);
8446
+
8447
+ auto CustomMFunc = CustomMapperCB (I);
8448
+ if (!CustomMFunc)
8449
+ return CustomMFunc.takeError ();
8450
+ if (*CustomMFunc)
8451
+ MFunc = Builder.CreatePointerCast (*CustomMFunc, PtrTy);
8452
+
8444
8453
Value *MAddr = Builder.CreateInBoundsGEP (
8445
8454
MappersArray->getAllocatedType (), MappersArray,
8446
8455
{Builder.getIntN (IndexSize, 0 ), Builder.getIntN (IndexSize, I)});
@@ -8450,8 +8459,9 @@ void OpenMPIRBuilder::emitOffloadingArrays(
8450
8459
8451
8460
if (!IsNonContiguous || CombinedInfo.NonContigInfo .Offsets .empty () ||
8452
8461
Info.NumberOfPtrs == 0 )
8453
- return ;
8462
+ return Error::success () ;
8454
8463
emitNonContiguousDescriptor (AllocaIP, CodeGenIP, CombinedInfo, Info);
8464
+ return Error::success ();
8455
8465
}
8456
8466
8457
8467
void OpenMPIRBuilder::emitBranch (BasicBlock *Target) {
0 commit comments