4747#include " llvm/IR/Value.h"
4848#include " llvm/MC/TargetRegistry.h"
4949#include " llvm/Support/CommandLine.h"
50+ #include " llvm/Support/Error.h"
5051#include " llvm/Support/ErrorHandling.h"
5152#include " llvm/Support/FileSystem.h"
5253#include " llvm/Target/TargetMachine.h"
@@ -6480,12 +6481,12 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
64806481 const LocationDescription &Loc, InsertPointTy AllocaIP,
64816482 InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
64826483 TargetDataInfo &Info, GenMapInfoCallbackTy GenMapInfoCB,
6484+ function_ref<Value *(unsigned int )> CustomMapperCB,
64836485 omp::RuntimeFunction *MapperFunc,
64846486 function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
64856487 BodyGenTy BodyGenType)>
64866488 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) {
64896490 if (!updateToLocation (Loc))
64906491 return InsertPointTy ();
64916492
@@ -6511,8 +6512,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
65116512 InsertPointTy CodeGenIP) -> Error {
65126513 MapInfo = &GenMapInfoCB (Builder.saveIP ());
65136514 emitOffloadingArrays (AllocaIP, Builder.saveIP (), *MapInfo, Info,
6514- /* IsNonContiguous= */ true , DeviceAddrCB ,
6515- CustomMapperCB );
6515+ CustomMapperCB ,
6516+ /* IsNonContiguous= */ true , DeviceAddrCB );
65166517
65176518 TargetDataRTArgs RTArgs;
65186519 emitOffloadingArraysArgument (Builder, RTArgs, Info);
@@ -7304,22 +7305,24 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask(
73047305
73057306void OpenMPIRBuilder::emitOffloadingArraysAndArgs (
73067307 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 );
73127313 emitOffloadingArraysArgument (Builder, RTArgs, Info, ForEndCall);
73137314}
73147315
73157316static void
73167317emitTargetCall (OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
7317- OpenMPIRBuilder::InsertPointTy AllocaIP, Function *OutlinedFn,
7318+ OpenMPIRBuilder::InsertPointTy AllocaIP,
7319+ OpenMPIRBuilder::TargetDataInfo &Info, Function *OutlinedFn,
73187320 Constant *OutlinedFnID, ArrayRef<int32_t > NumTeams,
73197321 ArrayRef<int32_t > NumThreads, SmallVectorImpl<Value *> &Args,
73207322 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) {
73237326 // Generate a function call to the host fallback implementation of the target
73247327 // region. This is called by the host when no offload entry was generated for
73257328 // the target region and when the offloading call fails at runtime.
@@ -7384,14 +7387,10 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
73847387 return ;
73857388 }
73867389
7387- OpenMPIRBuilder::TargetDataInfo Info (
7388- /* RequiresDevicePointerInfo=*/ false ,
7389- /* SeparateBeginEndCalls=*/ true );
7390-
73917390 OpenMPIRBuilder::MapInfosTy &MapInfo = GenMapInfoCB (Builder.saveIP ());
73927391 OpenMPIRBuilder::TargetDataRTArgs RTArgs;
73937392 OMPBuilder.emitOffloadingArraysAndArgs (AllocaIP, Builder.saveIP (), Info,
7394- RTArgs, MapInfo,
7393+ RTArgs, MapInfo, CustomMapperCB,
73957394 /* IsNonContiguous=*/ true ,
73967395 /* ForEndCall=*/ false );
73977396
@@ -7439,11 +7438,13 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
74397438
74407439OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget (
74417440 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,
74457445 OpenMPIRBuilder::TargetBodyGenCallbackTy CBFunc,
74467446 OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
7447+ function_ref<Value *(unsigned int )> CustomMapperCB,
74477448 SmallVector<DependData> Dependencies, bool HasNowait) {
74487449
74497450 if (!updateToLocation (Loc))
@@ -7458,15 +7459,16 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTarget(
74587459 // and ArgAccessorFuncCB
74597460 if (Error Err = emitTargetOutlinedFunction (
74607461 *this , Builder, IsOffloadEntry, EntryInfo, OutlinedFn, OutlinedFnID,
7461- Args , CBFunc, ArgAccessorFuncCB))
7462+ Inputs , CBFunc, ArgAccessorFuncCB))
74627463 return Err;
74637464
74647465 // If we are not on the target device, then we need to generate code
74657466 // to make a remote call (offload) to the previously outlined function
74667467 // that represents the target region. Do that now.
74677468 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);
74707472 return Builder.saveIP ();
74717473}
74727474
@@ -7791,9 +7793,9 @@ void OpenMPIRBuilder::emitUDMapperArrayInitOrDel(
77917793 OffloadingArgs);
77927794}
77937795
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)>
77977799 GenMapInfoCB,
77987800 Type *ElemTy, StringRef FuncName,
77997801 function_ref<bool(unsigned int , Function **)> CustomMapperCB) {
@@ -7867,7 +7869,9 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
78677869 PtrPHI->addIncoming (PtrBegin, HeadBB);
78687870
78697871 // 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 ();
78717875
78727876 // Call the runtime API __tgt_mapper_num_components to get the number of
78737877 // pre-existing components.
@@ -7879,20 +7883,20 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
78797883 Builder.CreateShl (PreviousSize, Builder.getInt64 (getFlagMemberOffset ()));
78807884
78817885 // 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) {
78837887 Value *CurBaseArg =
7884- Builder.CreateBitCast (Info. BasePointers [I], Builder.getPtrTy ());
7888+ Builder.CreateBitCast (Info-> BasePointers [I], Builder.getPtrTy ());
78857889 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]
78907894 : Constant::getNullValue (Builder.getPtrTy ());
78917895
78927896 // Extract the MEMBER_OF field from the map type.
78937897 Value *OriMapType = Builder.getInt64 (
78947898 static_cast <std::underlying_type_t <OpenMPOffloadMappingFlags>>(
7895- Info. Types [I]));
7899+ Info-> Types [I]));
78967900 Value *MemberMapType =
78977901 Builder.CreateNUWAdd (OriMapType, ShiftedPreviousSize);
78987902
@@ -8013,9 +8017,9 @@ Function *OpenMPIRBuilder::emitUserDefinedMapper(
80138017
80148018void OpenMPIRBuilder::emitOffloadingArrays (
80158019 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 ) {
80198023
80208024 // Reset the array information.
80218025 Info.clearArrayInfo ();
0 commit comments