diff options
author | Shilei Tian <tianshilei1992@gmail.com> | 2020-10-27 00:02:23 -0400 |
---|---|---|
committer | Shilei Tian <tianshilei1992@gmail.com> | 2020-10-27 00:02:32 -0400 |
commit | d38788b357ad29083eb3b03027db908559aae2a6 (patch) | |
tree | 6dae1805a899af590b44ba860eb1512f50c6fa26 /clang/lib | |
parent | c4ef3115b4296321090ce33987d6fdf7fa337fc1 (diff) | |
download | llvm-d38788b357ad29083eb3b03027db908559aae2a6.zip llvm-d38788b357ad29083eb3b03027db908559aae2a6.tar.gz llvm-d38788b357ad29083eb3b03027db908559aae2a6.tar.bz2 |
[Clang][OpenMP] Avoid unnecessary privatization of mapper array when there is no user defined mapper
In current implementation, if it requires an outer task, the mapper array will be privatized no matter whether it has mapper. In fact, when there is no mapper, the mapper array only contains number of nullptr. In the libomptarget, the use of mapper array is `if (mappers_array && mappers_array[i])`, which means we can directly set mapper array to nullptr if there is no mapper. This can avoid unnecessary data copy.
In this patch, the data privatization will not be emitted if the mapper array is nullptr. When it comes to the emit of task body, the nullptr will be used directly.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D90101
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 27 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGStmtOpenMP.cpp | 19 |
2 files changed, 24 insertions, 22 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 1e39379..3cc4a6b 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -8870,10 +8870,8 @@ namespace { /// Additional arguments for emitOffloadingArraysArgument function. struct ArgumentsOptions { bool ForEndCall = false; - bool IsTask = false; ArgumentsOptions() = default; - ArgumentsOptions(bool ForEndCall, bool IsTask) - : ForEndCall(ForEndCall), IsTask(IsTask) {} + ArgumentsOptions(bool ForEndCall) : ForEndCall(ForEndCall) {} }; } // namespace @@ -8909,9 +8907,9 @@ static void emitOffloadingArraysArgument( : Info.MapTypesArray, /*Idx0=*/0, /*Idx1=*/0); - // Always emit the mapper array address in case of a target task for - // privatization. - if (!Options.IsTask && !Info.HasMapper) + // If there is no user-defined mapper, set the mapper array to nullptr to + // avoid an unnecessary data privatization + if (!Info.HasMapper) MappersArrayArg = llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy); else MappersArrayArg = @@ -9664,10 +9662,9 @@ void CGOpenMPRuntime::emitTargetCall( TargetDataInfo Info; // Fill up the arrays and create the arguments. emitOffloadingArrays(CGF, CombinedInfo, Info); - emitOffloadingArraysArgument(CGF, Info.BasePointersArray, - Info.PointersArray, Info.SizesArray, - Info.MapTypesArray, Info.MappersArray, Info, - {/*ForEndTask=*/false, RequiresOuterTask}); + emitOffloadingArraysArgument( + CGF, Info.BasePointersArray, Info.PointersArray, Info.SizesArray, + Info.MapTypesArray, Info.MappersArray, Info, {/*ForEndTask=*/false}); InputInfo.NumberOfTargetItems = Info.NumberOfPtrs; InputInfo.BasePointersArray = Address(Info.BasePointersArray, CGM.getPointerAlign()); @@ -10318,8 +10315,7 @@ void CGOpenMPRuntime::emitTargetDataCalls( llvm::Value *MappersArrayArg = nullptr; emitOffloadingArraysArgument(CGF, BasePointersArrayArg, PointersArrayArg, SizesArrayArg, MapTypesArrayArg, - MappersArrayArg, Info, - {/*ForEndCall=*/true, /*IsTask=*/false}); + MappersArrayArg, Info, {/*ForEndCall=*/true}); // Emit device ID if any. llvm::Value *DeviceID = nullptr; @@ -10518,10 +10514,9 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall( // Fill up the arrays and create the arguments. emitOffloadingArrays(CGF, CombinedInfo, Info); bool HasDependClauses = D.hasClausesOfKind<OMPDependClause>(); - emitOffloadingArraysArgument(CGF, Info.BasePointersArray, - Info.PointersArray, Info.SizesArray, - Info.MapTypesArray, Info.MappersArray, Info, - {/*ForEndTask=*/false, HasDependClauses}); + emitOffloadingArraysArgument( + CGF, Info.BasePointersArray, Info.PointersArray, Info.SizesArray, + Info.MapTypesArray, Info.MappersArray, Info, {/*ForEndTask=*/false}); InputInfo.NumberOfTargetItems = Info.NumberOfPtrs; InputInfo.BasePointersArray = Address(Info.BasePointersArray, CGM.getPointerAlign()); diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index d656792..5884dfd 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -4210,16 +4210,21 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective( /*IndexTypeQuals=*/0); SVD = createImplicitFirstprivateForType(getContext(), Data, SizesType, CD, S.getBeginLoc()); - MVD = createImplicitFirstprivateForType( - getContext(), Data, BaseAndPointerAndMapperType, CD, S.getBeginLoc()); TargetScope.addPrivate( BPVD, [&InputInfo]() { return InputInfo.BasePointersArray; }); TargetScope.addPrivate(PVD, [&InputInfo]() { return InputInfo.PointersArray; }); TargetScope.addPrivate(SVD, [&InputInfo]() { return InputInfo.SizesArray; }); - TargetScope.addPrivate(MVD, - [&InputInfo]() { return InputInfo.MappersArray; }); + // If there is no user-defined mapper, the mapper array will be nullptr. In + // this case, we don't need to privatize it. + if (!dyn_cast_or_null<llvm::ConstantPointerNull>( + InputInfo.MappersArray.getPointer())) { + MVD = createImplicitFirstprivateForType( + getContext(), Data, BaseAndPointerAndMapperType, CD, S.getBeginLoc()); + TargetScope.addPrivate(MVD, + [&InputInfo]() { return InputInfo.MappersArray; }); + } } (void)TargetScope.Privatize(); // Build list of dependences. @@ -4269,8 +4274,10 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective( CGF.GetAddrOfLocalVar(PVD), /*Index=*/0); InputInfo.SizesArray = CGF.Builder.CreateConstArrayGEP( CGF.GetAddrOfLocalVar(SVD), /*Index=*/0); - InputInfo.MappersArray = CGF.Builder.CreateConstArrayGEP( - CGF.GetAddrOfLocalVar(MVD), /*Index=*/0); + // If MVD is nullptr, the mapper array is not privatized + if (MVD) + InputInfo.MappersArray = CGF.Builder.CreateConstArrayGEP( + CGF.GetAddrOfLocalVar(MVD), /*Index=*/0); } Action.Enter(CGF); |