47
47
#include " llvm/IR/Value.h"
48
48
#include " llvm/MC/TargetRegistry.h"
49
49
#include " llvm/Support/CommandLine.h"
50
+ #include " llvm/Support/Error.h"
50
51
#include " llvm/Support/ErrorHandling.h"
51
52
#include " llvm/Support/FileSystem.h"
52
53
#include " llvm/Target/TargetMachine.h"
@@ -6480,12 +6481,12 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
6480
6481
const LocationDescription &Loc, InsertPointTy AllocaIP,
6481
6482
InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
6482
6483
TargetDataInfo &Info, GenMapInfoCallbackTy GenMapInfoCB,
6484
+ function_ref<Value *(unsigned int )> CustomMapperCB,
6483
6485
omp::RuntimeFunction *MapperFunc,
6484
6486
function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
6485
6487
BodyGenTy BodyGenType)>
6486
6488
BodyGenCB,
6487
- function_ref<void(unsigned int, Value *)> DeviceAddrCB,
6488
- function_ref<Value *(unsigned int)> CustomMapperCB, Value *SrcLocInfo) {
6489
+ function_ref<void(unsigned int , Value *)> DeviceAddrCB, Value *SrcLocInfo) {
6489
6490
if (!updateToLocation (Loc))
6490
6491
return InsertPointTy ();
6491
6492
@@ -6511,8 +6512,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
6511
6512
InsertPointTy CodeGenIP) -> Error {
6512
6513
MapInfo = &GenMapInfoCB (Builder.saveIP ());
6513
6514
emitOffloadingArrays (AllocaIP, Builder.saveIP (), *MapInfo, Info,
6514
- /*IsNonContiguous=*/true, DeviceAddrCB ,
6515
- CustomMapperCB );
6515
+ CustomMapperCB ,
6516
+ /* IsNonContiguous= */ true , DeviceAddrCB );
6516
6517
6517
6518
TargetDataRTArgs RTArgs;
6518
6519
emitOffloadingArraysArgument (Builder, RTArgs, Info);
@@ -7304,22 +7305,24 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask(
7304
7305
7305
7306
void OpenMPIRBuilder::emitOffloadingArraysAndArgs (
7306
7307
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &Info,
7307
- TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo, bool IsNonContiguous,
7308
- bool ForEndCall, function_ref<void (unsigned int, Value * )> DeviceAddrCB ,
7309
- function_ref<Value * (unsigned int)> CustomMapperCB ) {
7310
- emitOffloadingArrays(AllocaIP, CodeGenIP, CombinedInfo, Info, IsNonContiguous ,
7311
- DeviceAddrCB, CustomMapperCB );
7308
+ TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
7309
+ function_ref<Value * (unsigned int )> CustomMapperCB, bool IsNonContiguous ,
7310
+ bool ForEndCall, function_ref<void (unsigned int , Value * )> DeviceAddrCB ) {
7311
+ emitOffloadingArrays (AllocaIP, CodeGenIP, CombinedInfo, Info, CustomMapperCB ,
7312
+ IsNonContiguous, DeviceAddrCB );
7312
7313
emitOffloadingArraysArgument (Builder, RTArgs, Info, ForEndCall);
7313
7314
}
7314
7315
7315
7316
static void
7316
7317
emitTargetCall (OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
7317
- OpenMPIRBuilder::InsertPointTy AllocaIP, Function *OutlinedFn,
7318
+ OpenMPIRBuilder::InsertPointTy AllocaIP,
7319
+ OpenMPIRBuilder::TargetDataInfo &Info, Function *OutlinedFn,
7318
7320
Constant *OutlinedFnID, ArrayRef<int32_t > NumTeams,
7319
7321
ArrayRef<int32_t > NumThreads, SmallVectorImpl<Value *> &Args,
7320
7322
OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB,
7321
- SmallVector<llvm::OpenMPIRBuilder::DependData> Dependencies = {},
7322
- bool HasNoWait = false) {
7323
+ function_ref<Value *(unsigned int )> CustomMapperCB,
7324
+ SmallVector<llvm::OpenMPIRBuilder::DependData> Dependencies,
7325
+ bool HasNoWait) {
7323
7326
// Generate a function call to the host fallback implementation of the target
7324
7327
// region. This is called by the host when no offload entry was generated for
7325
7328
// the target region and when the offloading call fails at runtime.
@@ -7384,14 +7387,10 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
7384
7387
return ;
7385
7388
}
7386
7389
7387
- OpenMPIRBuilder::TargetDataInfo Info(
7388
- /*RequiresDevicePointerInfo=*/false,
7389
- /*SeparateBeginEndCalls=*/true);
7390
-
7391
7390
OpenMPIRBuilder::MapInfosTy &MapInfo = GenMapInfoCB (Builder.saveIP ());
7392
7391
OpenMPIRBuilder::TargetDataRTArgs RTArgs;
7393
7392
OMPBuilder.emitOffloadingArraysAndArgs (AllocaIP, Builder.saveIP (), Info,
7394
- RTArgs, MapInfo,
7393
+ RTArgs, MapInfo, CustomMapperCB,
7395
7394
/* IsNonContiguous=*/ true ,
7396
7395
/* ForEndCall=*/ false );
7397
7396
@@ -7439,11 +7438,13 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
7439
7438
7440
7439
OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget (
7441
7440
const LocationDescription &Loc, bool IsOffloadEntry, InsertPointTy AllocaIP,
7442
- InsertPointTy CodeGenIP, TargetRegionEntryInfo &EntryInfo,
7443
- ArrayRef<int32_t> NumTeams, ArrayRef<int32_t> NumThreads,
7444
- SmallVectorImpl<Value *> &Args, GenMapInfoCallbackTy GenMapInfoCB,
7441
+ InsertPointTy CodeGenIP, TargetDataInfo &Info,
7442
+ TargetRegionEntryInfo &EntryInfo, ArrayRef<int32_t > NumTeams,
7443
+ ArrayRef<int32_t > NumThreads, SmallVectorImpl<Value *> &Inputs,
7444
+ GenMapInfoCallbackTy GenMapInfoCB,
7445
7445
OpenMPIRBuilder::TargetBodyGenCallbackTy CBFunc,
7446
7446
OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
7447
+ function_ref<Value *(unsigned int )> CustomMapperCB,
7447
7448
SmallVector<DependData> Dependencies, bool HasNowait) {
7448
7449
7449
7450
if (!updateToLocation (Loc))
@@ -7458,15 +7459,16 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget(
7458
7459
// and ArgAccessorFuncCB
7459
7460
if (Error Err = emitTargetOutlinedFunction (
7460
7461
*this , Builder, IsOffloadEntry, EntryInfo, OutlinedFn, OutlinedFnID,
7461
- Args , CBFunc, ArgAccessorFuncCB))
7462
+ Inputs , CBFunc, ArgAccessorFuncCB))
7462
7463
return Err;
7463
7464
7464
7465
// If we are not on the target device, then we need to generate code
7465
7466
// to make a remote call (offload) to the previously outlined function
7466
7467
// that represents the target region. Do that now.
7467
7468
if (!Config.isTargetDevice ())
7468
- emitTargetCall(*this, Builder, AllocaIP, OutlinedFn, OutlinedFnID, NumTeams,
7469
- NumThreads, Args, GenMapInfoCB, Dependencies, HasNowait);
7469
+ emitTargetCall (*this , Builder, AllocaIP, Info, OutlinedFn, OutlinedFnID,
7470
+ NumTeams, NumThreads, Inputs, GenMapInfoCB, CustomMapperCB,
7471
+ Dependencies, HasNowait);
7470
7472
return Builder.saveIP ();
7471
7473
}
7472
7474
@@ -7791,9 +7793,9 @@ void OpenMPIRBuilder::emitUDMapperArrayInitOrDel(
7791
7793
OffloadingArgs);
7792
7794
}
7793
7795
7794
- Function *OpenMPIRBuilder::emitUserDefinedMapper(
7795
- function_ref<MapInfosTy & (InsertPointTy CodeGenIP, llvm::Value *PtrPHI,
7796
- llvm::Value *BeginArg)>
7796
+ Expected< Function *> OpenMPIRBuilder::emitUserDefinedMapper (
7797
+ function_ref<MapInfosOrErrorTy (InsertPointTy CodeGenIP, llvm::Value *PtrPHI,
7798
+ llvm::Value *BeginArg)>
7797
7799
GenMapInfoCB,
7798
7800
Type *ElemTy, StringRef FuncName,
7799
7801
function_ref<bool(unsigned int , Function **)> CustomMapperCB) {
@@ -7867,7 +7869,9 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
7867
7869
PtrPHI->addIncoming (PtrBegin, HeadBB);
7868
7870
7869
7871
// Get map clause information. Fill up the arrays with all mapped variables.
7870
- MapInfosTy &Info = GenMapInfoCB(Builder.saveIP(), PtrPHI, BeginIn);
7872
+ MapInfosOrErrorTy Info = GenMapInfoCB (Builder.saveIP (), PtrPHI, BeginIn);
7873
+ if (!Info)
7874
+ return Info.takeError ();
7871
7875
7872
7876
// Call the runtime API __tgt_mapper_num_components to get the number of
7873
7877
// pre-existing components.
@@ -7879,20 +7883,20 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
7879
7883
Builder.CreateShl (PreviousSize, Builder.getInt64 (getFlagMemberOffset ()));
7880
7884
7881
7885
// Fill up the runtime mapper handle for all components.
7882
- for (unsigned I = 0; I < Info. BasePointers.size(); ++I) {
7886
+ for (unsigned I = 0 ; I < Info-> BasePointers .size (); ++I) {
7883
7887
Value *CurBaseArg =
7884
- Builder.CreateBitCast(Info. BasePointers[I], Builder.getPtrTy());
7888
+ Builder.CreateBitCast (Info-> BasePointers [I], Builder.getPtrTy ());
7885
7889
Value *CurBeginArg =
7886
- Builder.CreateBitCast(Info. Pointers[I], Builder.getPtrTy());
7887
- Value *CurSizeArg = Info. Sizes[I];
7888
- Value *CurNameArg = Info. Names.size()
7889
- ? Info. Names[I]
7890
+ Builder.CreateBitCast (Info-> Pointers [I], Builder.getPtrTy ());
7891
+ Value *CurSizeArg = Info-> Sizes [I];
7892
+ Value *CurNameArg = Info-> Names .size ()
7893
+ ? Info-> Names [I]
7890
7894
: Constant::getNullValue (Builder.getPtrTy ());
7891
7895
7892
7896
// Extract the MEMBER_OF field from the map type.
7893
7897
Value *OriMapType = Builder.getInt64 (
7894
7898
static_cast <std::underlying_type_t <OpenMPOffloadMappingFlags>>(
7895
- Info. Types[I]));
7899
+ Info-> Types [I]));
7896
7900
Value *MemberMapType =
7897
7901
Builder.CreateNUWAdd (OriMapType, ShiftedPreviousSize);
7898
7902
@@ -8013,9 +8017,9 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
8013
8017
8014
8018
void OpenMPIRBuilder::emitOffloadingArrays (
8015
8019
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
8016
- TargetDataInfo &Info, bool IsNonContiguous ,
8017
- function_ref<void(unsigned int, Value *)> DeviceAddrCB ,
8018
- function_ref<Value * (unsigned int)> CustomMapperCB ) {
8020
+ TargetDataInfo &Info, function_ref<Value *( unsigned int )> CustomMapperCB ,
8021
+ bool IsNonContiguous ,
8022
+ function_ref<void (unsigned int , Value * )> DeviceAddrCB ) {
8019
8023
8020
8024
// Reset the array information.
8021
8025
Info.clearArrayInfo ();
0 commit comments