r346408 - [OPENMP]Make lambda mapping follow reqs for PTR_AND_OBJ mapping.
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 8 07:47:40 PST 2018
Author: abataev
Date: Thu Nov 8 07:47:39 2018
New Revision: 346408
URL: http://llvm.org/viewvc/llvm-project?rev=346408&view=rev
Log:
[OPENMP]Make lambda mapping follow reqs for PTR_AND_OBJ mapping.
The base pointer for the lambda mapping must point to the lambda capture
placement and pointer must point to the captured variable itself. Patch
fixes this problem.
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/nvptx_lambda_capturing.cpp
Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=346408&r1=346407&r2=346408&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Nov 8 07:47:39 2018
@@ -7550,11 +7550,11 @@ public:
}
/// Emit capture info for lambdas for variables captured by reference.
- void generateInfoForLambdaCaptures(const ValueDecl *VD, llvm::Value *Arg,
- MapBaseValuesArrayTy &BasePointers,
- MapValuesArrayTy &Pointers,
- MapValuesArrayTy &Sizes,
- MapFlagsArrayTy &Types) const {
+ void generateInfoForLambdaCaptures(
+ const ValueDecl *VD, llvm::Value *Arg, MapBaseValuesArrayTy &BasePointers,
+ MapValuesArrayTy &Pointers, MapValuesArrayTy &Sizes,
+ MapFlagsArrayTy &Types,
+ llvm::DenseMap<llvm::Value *, llvm::Value *> &LambdaPointers) const {
const auto *RD = VD->getType()
.getCanonicalType()
.getNonReferenceType()
@@ -7570,8 +7570,10 @@ public:
if (ThisCapture) {
LValue ThisLVal =
CGF.EmitLValueForFieldInitialization(VDLVal, ThisCapture);
- BasePointers.push_back(VDLVal.getPointer());
- Pointers.push_back(ThisLVal.getPointer());
+ LValue ThisLValVal = CGF.EmitLValueForField(VDLVal, ThisCapture);
+ LambdaPointers.try_emplace(ThisLVal.getPointer(), VDLVal.getPointer());
+ BasePointers.push_back(ThisLVal.getPointer());
+ Pointers.push_back(ThisLValVal.getPointer());
Sizes.push_back(CGF.getTypeSize(CGF.getContext().VoidPtrTy));
Types.push_back(OMP_MAP_PTR_AND_OBJ | OMP_MAP_LITERAL |
OMP_MAP_MEMBER_OF | OMP_MAP_IMPLICIT);
@@ -7583,8 +7585,10 @@ public:
auto It = Captures.find(VD);
assert(It != Captures.end() && "Found lambda capture without field.");
LValue VarLVal = CGF.EmitLValueForFieldInitialization(VDLVal, It->second);
- BasePointers.push_back(VDLVal.getPointer());
- Pointers.push_back(VarLVal.getPointer());
+ LValue VarLValVal = CGF.EmitLValueForField(VDLVal, It->second);
+ LambdaPointers.try_emplace(VarLVal.getPointer(), VDLVal.getPointer());
+ BasePointers.push_back(VarLVal.getPointer());
+ Pointers.push_back(VarLValVal.getPointer());
Sizes.push_back(CGF.getTypeSize(
VD->getType().getCanonicalType().getNonReferenceType()));
Types.push_back(OMP_MAP_PTR_AND_OBJ | OMP_MAP_LITERAL |
@@ -7593,15 +7597,17 @@ public:
}
/// Set correct indices for lambdas captures.
- void adjustMemberOfForLambdaCaptures(MapBaseValuesArrayTy &BasePointers,
- MapValuesArrayTy &Pointers,
- MapFlagsArrayTy &Types) const {
+ void adjustMemberOfForLambdaCaptures(
+ const llvm::DenseMap<llvm::Value *, llvm::Value *> &LambdaPointers,
+ MapBaseValuesArrayTy &BasePointers, MapValuesArrayTy &Pointers,
+ MapFlagsArrayTy &Types) const {
for (unsigned I = 0, E = Types.size(); I < E; ++I) {
// Set correct member_of idx for all implicit lambda captures.
if (Types[I] != (OMP_MAP_PTR_AND_OBJ | OMP_MAP_LITERAL |
OMP_MAP_MEMBER_OF | OMP_MAP_IMPLICIT))
continue;
- llvm::Value *BasePtr = *BasePointers[I];
+ llvm::Value *BasePtr = LambdaPointers.lookup(*BasePointers[I]);
+ assert(BasePtr && "Unable to find base lambda address.");
int TgtIdx = -1;
for (unsigned J = I; J > 0; --J) {
unsigned Idx = J - 1;
@@ -8191,6 +8197,7 @@ void CGOpenMPRuntime::emitTargetCall(Cod
// Get mappable expression information.
MappableExprsHandler MEHandler(D, CGF);
+ llvm::DenseMap<llvm::Value *, llvm::Value *> LambdaPointers;
auto RI = CS.getCapturedRecordDecl()->field_begin();
auto CV = CapturedVars.begin();
@@ -8223,9 +8230,9 @@ void CGOpenMPRuntime::emitTargetCall(Cod
// Generate correct mapping for variables captured by reference in
// lambdas.
if (CI->capturesVariable())
- MEHandler.generateInfoForLambdaCaptures(CI->getCapturedVar(), *CV,
- CurBasePointers, CurPointers,
- CurSizes, CurMapTypes);
+ MEHandler.generateInfoForLambdaCaptures(
+ CI->getCapturedVar(), *CV, CurBasePointers, CurPointers, CurSizes,
+ CurMapTypes, LambdaPointers);
}
// We expect to have at least an element of information for this capture.
assert(!CurBasePointers.empty() &&
@@ -8248,7 +8255,8 @@ void CGOpenMPRuntime::emitTargetCall(Cod
MapTypes.append(CurMapTypes.begin(), CurMapTypes.end());
}
// Adjust MEMBER_OF flags for the lambdas captures.
- MEHandler.adjustMemberOfForLambdaCaptures(BasePointers, Pointers, MapTypes);
+ MEHandler.adjustMemberOfForLambdaCaptures(LambdaPointers, BasePointers,
+ Pointers, MapTypes);
// Map other list items in the map clause which are not captured variables
// but "declare target link" global variables.
MEHandler.generateInfoForDeclareTargetLink(BasePointers, Pointers, Sizes,
Modified: cfe/trunk/test/OpenMP/nvptx_lambda_capturing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_lambda_capturing.cpp?rev=346408&r1=346407&r2=346408&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/nvptx_lambda_capturing.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_lambda_capturing.cpp Thu Nov 8 07:47:39 2018
@@ -129,4 +129,19 @@ int main(int argc, char **argv) {
return argc + s.foo();
}
+
+// HOST-LABEL: @main
+
+// HOST-DAG: call i32 @__tgt_target(i64 -1, i8* @{{.+}}, i32 11, i8** [[BASES:%.+]], i8** [[PTRS:%.+]],
+// HOST-DAG: [[BASES:%.+]] = getelementptr inbounds [11 x i8*], [11 x i8*]* [[BASE_PTR:%.+]], i32 0, i32 0
+// HOST-DAG: [[PTRS:%.+]] = getelementptr inbounds [11 x i8*], [11 x i8*]* [[PTR_PTR:%.+]], i32 0, i32 0
+// HOST-DAG: [[BASE_REF:%.+]] = getelementptr inbounds [11 x i8*], [11 x i8*]* [[BASE_PTR]], i32 0, i32 5
+// HOST-DAG: [[BASE_REF_CAST:%.+]] = bitcast i8** [[BASE_REF]] to i32***
+// HOST-DAG: store i32** [[BASE:%.+]], i32*** [[BASE_REF_CAST]],
+// HOST-DAG: [[BASE]] = getelementptr inbounds [[LAMBDA:%.+]], [[LAMBDA]]* [[LAMBDA_ADDR:%.+]], i32 0, i32 0
+// HOST-DAG: [[PTR_REF:%.+]] = getelementptr inbounds [11 x i8*], [11 x i8*]* [[PTR_PTR]], i32 0, i32 5
+// HOST-DAG: [[PTR_REF_CAST:%.+]] = bitcast i8** [[PTR_REF]] to i32**
+// HOST-DAG: store i32* [[PTR:%.+]], i32** [[PTR_REF_CAST]],
+// HOST-DAG: [[PTR]] = load i32*, i32** [[PTR_REF:%.+]],
+// HOST-DAG: [[PTR_REF]] = getelementptr inbounds [[LAMBDA]], [[LAMBDA]]* [[LAMBDA_ADDR]], i32 0, i32 0
#endif // HEADER
More information about the cfe-commits
mailing list