[clang] 0333567 - [OPENMP] Fix PR47999: correctly map implicit firstprivates in outer tasks.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 17 10:22:38 PST 2020


Author: Alexey Bataev
Date: 2020-11-17T10:21:12-08:00
New Revision: 0333567c47c0d496bba146cd4f7b65a8ef8ba113

URL: https://github.com/llvm/llvm-project/commit/0333567c47c0d496bba146cd4f7b65a8ef8ba113
DIFF: https://github.com/llvm/llvm-project/commit/0333567c47c0d496bba146cd4f7b65a8ef8ba113.diff

LOG: [OPENMP] Fix PR47999: correctly map implicit firstprivates in outer tasks.

If the variable is implicitly firstprivatized in the inner task-based
region, it also must be firstprivatized in outer task-based regions.
Previously firstprivates were captured in tasks but later it was
optimized to reduce the memory usage. But still need to mark such
variables as implicit firstprivate in outer tasks.

Differential Revision: https://reviews.llvm.org/D91627

Added: 
    clang/test/OpenMP/task_in_task_firstprivate_codegen.cpp

Modified: 
    clang/lib/Sema/SemaOpenMP.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6bb63fc4f1fe..b882eccf5288 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3687,7 +3687,8 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
       // Skip analysis of arguments of implicitly defined map clause for target
       // directives.
       if (C && !((isa<OMPFirstprivateClause>(C) || isa<OMPMapClause>(C)) &&
-                 C->isImplicit())) {
+                 C->isImplicit() &&
+                 !isOpenMPTaskingDirective(Stack->getCurrentDirective()))) {
         for (Stmt *CC : C->children()) {
           if (CC)
             Visit(CC);

diff  --git a/clang/test/OpenMP/task_in_task_firstprivate_codegen.cpp b/clang/test/OpenMP/task_in_task_firstprivate_codegen.cpp
new file mode 100644
index 000000000000..3b5d0657f85d
--- /dev/null
+++ b/clang/test/OpenMP/task_in_task_firstprivate_codegen.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c++ -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -x c++ -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// CHECK: @main
+int main() {
+  double var = 0;
+  // Check that var is firstprivatized in the outermost task.
+  // CHECK: [[BASE:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* @{{.+}}, i32 {{.+}}, i32 1, i64 48, i64 1, i32 (i32, i8*)* bitcast (i32 (i32, [[TASK_TY:%.+]]*)* @{{.+}} to i32 (i32, i8*)*))
+  // CHECK: [[TD:%.+]] = bitcast i8* [[BASE]] to [[TASK_TY]]*
+  // CHECK: [[PRIVS:%.+]] = getelementptr inbounds [[TASK_TY]], [[TASK_TY]]* [[TD]], i32 0, i32 1
+  // CHECK: [[VAR_FP:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[PRIVS]], i32 0, i32 0
+  // CHECK: [[VAR_VAL:%.+]] = load double, double* %{{.+}},
+  // CHECK: store double [[VAR_VAL]], double* [[VAR_FP]],
+  // CHECK: call i32 @__kmpc_omp_task(%struct.ident_t* @{{.+}}, i32 %{{.+}}, i8* [[BASE]])
+#pragma omp task
+#pragma omp task
+  var += 1;
+  return 0;
+}
+
+#endif


        


More information about the cfe-commits mailing list