tianshilei1992 updated this revision to Diff 299803. tianshilei1992 added a comment.
Fixed an issue that when there is mapper, the variable in the generated wrapped task still uses the one in the encountering function Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89844/new/ https://reviews.llvm.org/D89844 Files: clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp Index: clang/lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- clang/lib/CodeGen/CGStmtOpenMP.cpp +++ clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -4210,16 +4210,21 @@ /*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; }); + // Mapper can be nullptr if user doesn't provide any. We will not take it + // into account in this case. + 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 @@ 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); + // MVD can be nullptr if there is no user-defined mapper + if (MVD) + InputInfo.MappersArray = CGF.Builder.CreateConstArrayGEP( + CGF.GetAddrOfLocalVar(MVD), /*Index=*/0); } Action.Enter(CGF); Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -8863,6 +8863,9 @@ Address MAddr = CGF.Builder.CreateConstArrayGEP(MappersArray, I); CGF.Builder.CreateStore(MFunc, MAddr); } + // If no mapper, we just set the MappersArray to nullptr + if (!Info.HasMapper) + Info.MappersArray = llvm::ConstantPointerNull::get(CGM.VoidPtrTy); } }
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- clang/lib/CodeGen/CGStmtOpenMP.cpp +++ clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -4210,16 +4210,21 @@ /*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; }); + // Mapper can be nullptr if user doesn't provide any. We will not take it + // into account in this case. + 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 @@ 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); + // MVD can be nullptr if there is no user-defined mapper + if (MVD) + InputInfo.MappersArray = CGF.Builder.CreateConstArrayGEP( + CGF.GetAddrOfLocalVar(MVD), /*Index=*/0); } Action.Enter(CGF); Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -8863,6 +8863,9 @@ Address MAddr = CGF.Builder.CreateConstArrayGEP(MappersArray, I); CGF.Builder.CreateStore(MFunc, MAddr); } + // If no mapper, we just set the MappersArray to nullptr + if (!Info.HasMapper) + Info.MappersArray = llvm::ConstantPointerNull::get(CGM.VoidPtrTy); } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits