From: Alexey Bataev Date: Fri, 8 Dec 2017 20:18:58 +0000 (+0000) Subject: [OPENMP] Simplify codegen for loop iteration variables in loop preamble. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd1985cea543e501348ddedc9ec14aa0ca5c9c93;p=clang [OPENMP] Simplify codegen for loop iteration variables in loop preamble. Initial patch could cause trouble in the optimized code because of the incorrectly generated lifetime intrinsics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320191 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index 045c88f630..ad177b752d 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -122,7 +122,12 @@ public: class OMPLoopScope : public CodeGenFunction::RunCleanupsScope { void emitPreInitStmt(CodeGenFunction &CGF, const OMPLoopDirective &S) { CodeGenFunction::OMPPrivateScope PreCondScope(CGF); - CGF.EmitOMPPrivateLoopCounters(S, PreCondScope); + for (auto *E : S.counters()) { + const auto *VD = cast(cast(E)->getDecl()); + (void)PreCondScope.addPrivate(VD, [&CGF, VD]() { + return CGF.CreateMemTemp(VD->getType().getNonReferenceType()); + }); + } (void)PreCondScope.Privatize(); if (auto *LD = dyn_cast(&S)) { if (auto *PreInits = cast_or_null(LD->getPreInits())) { diff --git a/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp b/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp index 506885809a..fccb0cfdb3 100644 --- a/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp +++ b/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp @@ -164,7 +164,7 @@ int main() { // LAMBDA: [[SFVAR_IN_REF:%.+]] = load float*, float** [[SFVAR_PRIVATE_ADDR]], // LAMBDA: [[G1_IN_REF:%.+]] = load double*, double** [[G1_PRIVATE_ADDR]], - // LAMBDA: store double* [[G1_PRIVATE]], double** [[TMP_G1]], + // LAMBDA: store double* [[G1_PRIVATE]], double** [[TMP_G1_PRIVATE]], // LAMBDA: call {{.*}}void @__kmpc_for_static_init_4( diff --git a/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp b/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp index a2ae550cde..89ef33abd6 100644 --- a/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp +++ b/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp @@ -173,7 +173,7 @@ int main() { // LAMBDA: [[SFVAR_IN_REF:%.+]] = load float*, float** [[SFVAR_PRIVATE_ADDR]], // LAMBDA: [[G1_IN_REF:%.+]] = load double*, double** [[G1_PRIVATE_ADDR]], - // LAMBDA: store double* [[G1_PRIVATE]], double** [[TMP_G1]], + // LAMBDA: store double* [[G1_PRIVATE]], double** [[TMP_G1_PRIVATE]], // LAMBDA: call {{.*}}void @__kmpc_for_static_init_4( diff --git a/test/OpenMP/for_codegen.cpp b/test/OpenMP/for_codegen.cpp index 6d719f4486..1f5dd7ddd0 100644 --- a/test/OpenMP/for_codegen.cpp +++ b/test/OpenMP/for_codegen.cpp @@ -386,7 +386,9 @@ void parallel_for(float *a) { char i = 1, j = 2, k = 3; // CHECK-LABEL: for_with_global_lcv void for_with_global_lcv() { +// CHECK: alloca i8, // CHECK: [[I_ADDR:%.+]] = alloca i8, +// CHECK: alloca i8, // CHECK: [[J_ADDR:%.+]] = alloca i8, // CHECK: call void @__kmpc_for_static_init_4( diff --git a/test/OpenMP/for_lastprivate_codegen.cpp b/test/OpenMP/for_lastprivate_codegen.cpp index 7054c0e1c5..30a17eaf58 100644 --- a/test/OpenMP/for_lastprivate_codegen.cpp +++ b/test/OpenMP/for_lastprivate_codegen.cpp @@ -614,6 +614,7 @@ int main() { // CHECK: ret void // CHECK: define internal void [[MAIN_MICROTASK3]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}) +// CHECK: alloca i8, // CHECK: [[CNT_PRIV:%.+]] = alloca i8, // CHECK: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[GTID_ADDR_REF]] diff --git a/test/OpenMP/for_linear_codegen.cpp b/test/OpenMP/for_linear_codegen.cpp index e25de36a6f..54cdf8a4cb 100644 --- a/test/OpenMP/for_linear_codegen.cpp +++ b/test/OpenMP/for_linear_codegen.cpp @@ -157,6 +157,7 @@ int main() { // LAMBDA: alloca i{{[0-9]+}}, // LAMBDA: alloca i{{[0-9]+}}, // LAMBDA: alloca i{{[0-9]+}}, + // LAMBDA: alloca i{{[0-9]+}}, // LAMBDA: [[A_PRIV:%.+]] = alloca i{{[0-9]+}}, // LAMBDA: [[B_PRIV:%.+]] = alloca i{{[0-9]+}}, // LAMBDA: [[C_PRIV:%.+]] = alloca i{{[0-9]+}}, @@ -188,6 +189,7 @@ int main() { // LAMBDA: alloca i{{[0-9]+}}, // LAMBDA: alloca i{{[0-9]+}}, // LAMBDA: alloca i{{[0-9]+}}, + // LAMBDA: alloca i{{[0-9]+}}, // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}}, // LAMBDA: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** %{{.+}} // LAMBDA: [[GTID:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[GTID_REF]] @@ -240,6 +242,7 @@ int main() { // BLOCKS: alloca i{{[0-9]+}}, // BLOCKS: alloca i{{[0-9]+}}, // BLOCKS: alloca i{{[0-9]+}}, + // BLOCKS: alloca i{{[0-9]+}}, // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}}, // BLOCKS: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** %{{.+}} // BLOCKS: [[GTID:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[GTID_REF]] @@ -307,6 +310,7 @@ int main() { // BLOCKS: alloca i{{[0-9]+}}, // BLOCKS: alloca i{{[0-9]+}}, // BLOCKS: alloca i{{[0-9]+}}, +// BLOCKS: alloca i{{[0-9]+}}, // BLOCKS: [[A_PRIV:%.+]] = alloca i{{[0-9]+}}, // BLOCKS: [[B_PRIV:%.+]] = alloca i{{[0-9]+}}, // BLOCKS: [[C_PRIV:%.+]] = alloca i{{[0-9]+}}, @@ -419,6 +423,7 @@ int main() { // CHECK: alloca i{{[0-9]+}}, // CHECK: alloca i{{[0-9]+}}, // CHECK: alloca i{{[0-9]+}}, +// CHECK: alloca i{{[0-9]+}}, // CHECK: [[A_PRIV:%.+]] = alloca i{{[0-9]+}}, // CHECK: [[B_PRIV:%.+]] = alloca i{{[0-9]+}}, // CHECK: [[C_PRIV:%.+]] = alloca i{{[0-9]+}}, diff --git a/test/OpenMP/parallel_for_linear_codegen.cpp b/test/OpenMP/parallel_for_linear_codegen.cpp index 6e7a05991a..2c3cfddbd5 100644 --- a/test/OpenMP/parallel_for_linear_codegen.cpp +++ b/test/OpenMP/parallel_for_linear_codegen.cpp @@ -55,6 +55,7 @@ int main() { // LAMBDA: alloca i{{[0-9]+}}, // LAMBDA: alloca i{{[0-9]+}}, // LAMBDA: alloca i{{[0-9]+}}, + // LAMBDA: alloca i{{[0-9]+}}, // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}}, // LAMBDA: store i32 0, // LAMBDA: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** %{{.+}} @@ -102,6 +103,7 @@ int main() { // BLOCKS: alloca i{{[0-9]+}}, // BLOCKS: alloca i{{[0-9]+}}, // BLOCKS: alloca i{{[0-9]+}}, + // BLOCKS: alloca i{{[0-9]+}}, // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}}, // BLOCKS: store i32 0, // BLOCKS: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** %{{.+}}