Author: abataev
Date: Fri Dec  8 12:18:58 2017
New Revision: 320191

URL: http://llvm.org/viewvc/llvm-project?rev=320191&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
    cfe/trunk/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
    cfe/trunk/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
    cfe/trunk/test/OpenMP/for_codegen.cpp
    cfe/trunk/test/OpenMP/for_lastprivate_codegen.cpp
    cfe/trunk/test/OpenMP/for_linear_codegen.cpp
    cfe/trunk/test/OpenMP/parallel_for_linear_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=320191&r1=320190&r2=320191&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Fri Dec  8 12:18:58 2017
@@ -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<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
+      (void)PreCondScope.addPrivate(VD, [&CGF, VD]() {
+        return CGF.CreateMemTemp(VD->getType().getNonReferenceType());
+      });
+    }
     (void)PreCondScope.Privatize();
     if (auto *LD = dyn_cast<OMPLoopDirective>(&S)) {
       if (auto *PreInits = cast_or_null<DeclStmt>(LD->getPreInits())) {

Modified: cfe/trunk/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp?rev=320191&r1=320190&r2=320191&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp 
(original)
+++ cfe/trunk/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp Fri 
Dec  8 12:18:58 2017
@@ -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(
 

Modified: 
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp?rev=320191&r1=320190&r2=320191&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp 
(original)
+++ cfe/trunk/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp 
Fri Dec  8 12:18:58 2017
@@ -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(
 

Modified: cfe/trunk/test/OpenMP/for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_codegen.cpp?rev=320191&r1=320190&r2=320191&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/for_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_codegen.cpp Fri Dec  8 12:18:58 2017
@@ -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(

Modified: cfe/trunk/test/OpenMP/for_lastprivate_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_lastprivate_codegen.cpp?rev=320191&r1=320190&r2=320191&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/for_lastprivate_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_lastprivate_codegen.cpp Fri Dec  8 12:18:58 2017
@@ -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]]

Modified: cfe/trunk/test/OpenMP/for_linear_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_linear_codegen.cpp?rev=320191&r1=320190&r2=320191&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/for_linear_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_linear_codegen.cpp Fri Dec  8 12:18:58 2017
@@ -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]+}},
@@ -412,6 +416,7 @@ int main() {
 // CHECK: alloca i{{[0-9]+}},
 // CHECK: alloca i{{[0-9]+}},
 // CHECK: alloca i{{[0-9]+}},
+// CHECK: alloca i{{[0-9]+}},
 // CHECK: alloca i{{[0-9]+}},
 // CHECK: alloca i{{[0-9]+}},
 // CHECK: alloca i{{[0-9]+}},

Modified: cfe/trunk/test/OpenMP/parallel_for_linear_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_for_linear_codegen.cpp?rev=320191&r1=320190&r2=320191&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/parallel_for_linear_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_for_linear_codegen.cpp Fri Dec  8 12:18:58 
2017
@@ -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]+}}** %{{.+}}
@@ -101,6 +102,7 @@ int main() {
     // BLOCKS: alloca i{{[0-9]+}},
     // 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,


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to