ABataev created this revision. ABataev added a reviewer: jdoerfert. Herald added subscribers: guansong, yaxunl. Herald added a project: clang.
No need to generate inlined OpenMP region for variables captured in lambdas or block decls, only for implicitly captured variables in the OpenMP region. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D79966 Files: clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/test/OpenMP/task_firstprivate_codegen.cpp Index: clang/test/OpenMP/task_firstprivate_codegen.cpp =================================================================== --- clang/test/OpenMP/task_firstprivate_codegen.cpp +++ clang/test/OpenMP/task_firstprivate_codegen.cpp @@ -56,6 +56,7 @@ int main() { static int sivar; + float local = 0; #ifdef LAMBDA // LAMBDA: [[G:@.+]] = global double // LAMBDA: [[SIVAR:@.+]] = internal global i{{[0-9]+}} 0, @@ -73,9 +74,12 @@ // LAMBDA: [[SIVAR_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[SIVAR]], // LAMBDA: store i{{[0-9]+}} [[SIVAR_VAL]], i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]] +// LAMBDA: [[LOCAL_PRIVATE_ADDR:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[PRIVATES]], i{{.+}} 0, i{{.+}} 2 +// LAMBDA: store float %{{.+}}, float* [[LOCAL_PRIVATE_ADDR]] + // LAMBDA: call i32 @__kmpc_omp_task(%{{.+}}* @{{.+}}, i32 %{{.+}}, i8* [[RES]]) // LAMBDA: ret -#pragma omp task firstprivate(g, sivar) +#pragma omp task firstprivate(g, sivar, local) { // LAMBDA: define {{.+}} void [[INNER_LAMBDA:@.+]](%{{.+}}* [[ARG_PTR:%.+]]) // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]], @@ -115,9 +119,13 @@ // BLOCKS: [[SIVAR_PRIVATE_ADDR:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[PRIVATES]], i{{.+}} 0, i{{.+}} 1 // BLOCKS: [[SIVAR_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[SIVAR]], // BLOCKS: store i{{[0-9]+}} [[SIVAR_VAL]], i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]], + + // BLOCKS: [[LOCAL_PRIVATE_ADDR:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[PRIVATES]], i{{.+}} 0, i{{.+}} 2 + // BLOCKS: store float %{{.+}}, float* [[LOCAL_PRIVATE_ADDR]] + // BLOCKS: call i32 @__kmpc_omp_task(%{{.+}}* @{{.+}}, i32 %{{.+}}, i8* [[RES]]) // BLOCKS: ret -#pragma omp task firstprivate(g, sivar) +#pragma omp task firstprivate(g, sivar, local) { // BLOCKS: define {{.+}} void {{@.+}}(i8* // BLOCKS-NOT: [[G]]{{[[^:word:]]}} Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -4811,11 +4811,16 @@ C.getDeclAlign(OriginalVD)), SharedRefLValue.getType(), LValueBaseInfo(AlignmentSource::Decl), SharedRefLValue.getTBAAInfo()); + } else if (CGF.LambdaCaptureFields.count( + Pair.second.Original->getCanonicalDecl()) > 0 || + dyn_cast_or_null<BlockDecl>(CGF.CurCodeDecl)) { + SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef); } else { + // Processing for implicitly captured variables. InlinedOpenMPRegionRAII Region( CGF, [](CodeGenFunction &, PrePostActionTy &) {}, OMPD_unknown, /*HasCancel=*/false); - SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef); + SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef); } if (Type->isArrayType()) { // Initialize firstprivate array.
Index: clang/test/OpenMP/task_firstprivate_codegen.cpp =================================================================== --- clang/test/OpenMP/task_firstprivate_codegen.cpp +++ clang/test/OpenMP/task_firstprivate_codegen.cpp @@ -56,6 +56,7 @@ int main() { static int sivar; + float local = 0; #ifdef LAMBDA // LAMBDA: [[G:@.+]] = global double // LAMBDA: [[SIVAR:@.+]] = internal global i{{[0-9]+}} 0, @@ -73,9 +74,12 @@ // LAMBDA: [[SIVAR_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[SIVAR]], // LAMBDA: store i{{[0-9]+}} [[SIVAR_VAL]], i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]] +// LAMBDA: [[LOCAL_PRIVATE_ADDR:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[PRIVATES]], i{{.+}} 0, i{{.+}} 2 +// LAMBDA: store float %{{.+}}, float* [[LOCAL_PRIVATE_ADDR]] + // LAMBDA: call i32 @__kmpc_omp_task(%{{.+}}* @{{.+}}, i32 %{{.+}}, i8* [[RES]]) // LAMBDA: ret -#pragma omp task firstprivate(g, sivar) +#pragma omp task firstprivate(g, sivar, local) { // LAMBDA: define {{.+}} void [[INNER_LAMBDA:@.+]](%{{.+}}* [[ARG_PTR:%.+]]) // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]], @@ -115,9 +119,13 @@ // BLOCKS: [[SIVAR_PRIVATE_ADDR:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[PRIVATES]], i{{.+}} 0, i{{.+}} 1 // BLOCKS: [[SIVAR_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[SIVAR]], // BLOCKS: store i{{[0-9]+}} [[SIVAR_VAL]], i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]], + + // BLOCKS: [[LOCAL_PRIVATE_ADDR:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[PRIVATES]], i{{.+}} 0, i{{.+}} 2 + // BLOCKS: store float %{{.+}}, float* [[LOCAL_PRIVATE_ADDR]] + // BLOCKS: call i32 @__kmpc_omp_task(%{{.+}}* @{{.+}}, i32 %{{.+}}, i8* [[RES]]) // BLOCKS: ret -#pragma omp task firstprivate(g, sivar) +#pragma omp task firstprivate(g, sivar, local) { // BLOCKS: define {{.+}} void {{@.+}}(i8* // BLOCKS-NOT: [[G]]{{[[^:word:]]}} Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -4811,11 +4811,16 @@ C.getDeclAlign(OriginalVD)), SharedRefLValue.getType(), LValueBaseInfo(AlignmentSource::Decl), SharedRefLValue.getTBAAInfo()); + } else if (CGF.LambdaCaptureFields.count( + Pair.second.Original->getCanonicalDecl()) > 0 || + dyn_cast_or_null<BlockDecl>(CGF.CurCodeDecl)) { + SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef); } else { + // Processing for implicitly captured variables. InlinedOpenMPRegionRAII Region( CGF, [](CodeGenFunction &, PrePostActionTy &) {}, OMPD_unknown, /*HasCancel=*/false); - SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef); + SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef); } if (Type->isArrayType()) { // Initialize firstprivate array.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits