[clang] 77ebfba - [Flang][Openmp] Upgrade TASKGROUP construct to 5.0.

2021-08-02 Thread Chirag Khandelwal via cfe-commits

Author: Chirag Khandelwal
Date: 2021-08-03T10:27:47+05:30
New Revision: 77ebfba68b9aa89e9ccbcdf8e285afa0661c8ca4

URL: 
https://github.com/llvm/llvm-project/commit/77ebfba68b9aa89e9ccbcdf8e285afa0661c8ca4
DIFF: 
https://github.com/llvm/llvm-project/commit/77ebfba68b9aa89e9ccbcdf8e285afa0661c8ca4.diff

LOG: [Flang][Openmp] Upgrade TASKGROUP construct to 5.0.

In OMP 5.0 specification clause-list with
* task_reduction
* allocate
were allowed on taskgroup construct.

Fix XFAIL - omp-taskloop01.f90.

Reviewed By: kiranchandramohan

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

Added: 
flang/test/Semantics/omp-taskgroup01.f90

Modified: 
clang/test/OpenMP/master_taskloop_simd_ast_print.cpp
clang/test/OpenMP/parallel_master_taskloop_simd_ast_print.cpp
clang/test/OpenMP/taskloop_simd_ast_print.cpp
flang/lib/Semantics/resolve-directives.cpp
flang/lib/Semantics/resolve-names.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/test/OpenMP/master_taskloop_simd_ast_print.cpp 
b/clang/test/OpenMP/master_taskloop_simd_ast_print.cpp
index 54df1bbccc69f..f22db8f29ca88 100644
--- a/clang/test/OpenMP/master_taskloop_simd_ast_print.cpp
+++ b/clang/test/OpenMP/master_taskloop_simd_ast_print.cpp
@@ -1,13 +1,13 @@
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -ast-print %s | 
FileCheck %s --check-prefix CHECK --check-prefix OMP45
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o 
%t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -std=c++11 -include-pch %t 
-fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix CHECK 
--check-prefix OMP45
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -DOMP5 -ast-print %s | 
FileCheck %s --check-prefix CHECK --check-prefix OMP50
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -DOMP5 -x c++ -std=c++11 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -DOMP5 -std=c++11 -include-pch 
%t -fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix CHECK 
--check-prefix OMP50
 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -DOMP5 | FileCheck %s 
--check-prefix CHECK --check-prefix OMP50
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify 
%s -ast-print -DOMP5 | FileCheck %s --check-prefix CHECK --check-prefix OMP50
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ast-print %s | 
FileCheck %s --check-prefix CHECK --check-prefix OMP45
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 
-emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -std=c++11 -include-pch 
%t -fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix CHECK 
--check-prefix OMP45
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 -DOMP5 -ast-print 
%s | FileCheck %s --check-prefix CHECK --check-prefix OMP50
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -DOMP5 -x c++ -std=c++11 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -DOMP5 -std=c++11 
-include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s 
--check-prefix CHECK --check-prefix OMP50
 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -DOMP5 | FileCheck %s 
--check-prefix CHECK --check-prefix OMP50
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only 
-verify %s -ast-print -DOMP5 | FileCheck %s --check-prefix CHECK --check-prefix 
OMP50
@@ -85,7 +85,6 @@ int main(int argc, char **argv) {
   foo();
   // CHECK-NEXT: #pragma omp parallel
   // OMP50-NEXT: #pragma omp master taskloop simd private(argc,b) 
firstprivate(argv,c) lastprivate(d,f) collapse(2) shared(g) if(simd: argc) 
mergeable priority(argc) simdlen(16) grainsize(argc) reduction(max: a,e) 
nontemporal(argc,c,d) order(concurrent)
-  // OMP45-NEXT: #pragma omp master taskloop simd private(argc,b) 
firstprivate(argv,c) lastprivate(d,f) collapse(2) shared(g) if(argc) mergeable 
priority(argc) simdlen(16) grainsize(argc) reduction(max: a,e)
   // CHECK-NEXT: for (int i = 0; i < 10; ++i)
   // CHECK-NEXT: for (int j = 0; j < 10; ++j)
   // CHECK-NEXT: foo();

diff  --git a/clang/test/OpenMP/parallel_master_taskloop_simd_ast_print.cpp 
b/clang/test/OpenMP/parallel_master_taskloop_simd_ast_print.cpp
index e052b1c45bc89..02d427952ec67 100644
--- a/clang/test/OpenMP/parallel_master_taskloop_simd_ast_print.cpp
+++ b/clang/test/OpenMP/parallel_master_taskloop_simd_ast_print.cpp
@@ -1,13 +1,13 @@
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -ast-print %s | 
FileCheck %s --check-prefix CHECK --check-prefix OMP45
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o 
%t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -std=c++11

[clang] c204106 - [Clang][OpenMP] Frontend work for sections - D89671

2021-04-29 Thread Chirag Khandelwal via cfe-commits

Author: Chirag Khandelwal
Date: 2021-04-29T19:52:27+05:30
New Revision: c20410618827b7870fbc86d45ff8e9b11bc169b4

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

LOG: [Clang][OpenMP] Frontend work for sections - D89671

This patch is child of D89671, contains the clang
implementation to use the OpenMP IRBuilder's section
construct.

Co-author: @anchu-rajendran

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/cancel_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 0a408837d1c6a..a3c7365fafd87 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1205,7 +1205,7 @@ namespace {
 // Builder if one is present.
 struct PushAndPopStackRAII {
   PushAndPopStackRAII(llvm::OpenMPIRBuilder *OMPBuilder, CodeGenFunction &CGF,
-  bool HasCancel)
+  bool HasCancel, llvm::omp::Directive Kind)
   : OMPBuilder(OMPBuilder) {
 if (!OMPBuilder)
   return;
@@ -1234,8 +1234,7 @@ struct PushAndPopStackRAII {
 
 // TODO: Remove this once we emit parallel regions through the
 //   OpenMPIRBuilder as it can do this setup internally.
-llvm::OpenMPIRBuilder::FinalizationInfo FI(
-{FiniCB, OMPD_parallel, HasCancel});
+llvm::OpenMPIRBuilder::FinalizationInfo FI({FiniCB, Kind, HasCancel});
 OMPBuilder->pushFinalizationCB(std::move(FI));
   }
   ~PushAndPopStackRAII() {
@@ -1276,7 +1275,7 @@ static llvm::Function 
*emitParallelOrTeamsOutlinedFunction(
   // TODO: Temporarily inform the OpenMPIRBuilder, if any, about the new
   //   parallel region to make cancellation barriers work properly.
   llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
-  PushAndPopStackRAII PSR(&OMPBuilder, CGF, HasCancel);
+  PushAndPopStackRAII PSR(&OMPBuilder, CGF, HasCancel, InnermostKind);
   CGOpenMPOutlinedRegionInfo CGInfo(*CS, ThreadIDVar, CodeGen, InnermostKind,
 HasCancel, OutlinedHelperName);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo);

diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 7d8744651a4ee..83d3dd0fc813c 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -3791,6 +3791,64 @@ void CodeGenFunction::EmitSections(const 
OMPExecutableDirective &S) {
 }
 
 void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) {
+  if (CGM.getLangOpts().OpenMPIRBuilder) {
+llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
+using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
+using BodyGenCallbackTy = llvm::OpenMPIRBuilder::StorableBodyGenCallbackTy;
+
+auto FiniCB = [this](InsertPointTy IP) {
+  OMPBuilderCBHelpers::FinalizeOMPRegion(*this, IP);
+};
+
+const CapturedStmt *ICS = S.getInnermostCapturedStmt();
+const Stmt *CapturedStmt = S.getInnermostCapturedStmt()->getCapturedStmt();
+const auto *CS = dyn_cast(CapturedStmt);
+llvm::SmallVector SectionCBVector;
+if (CS) {
+  for (const Stmt *SubStmt : CS->children()) {
+auto SectionCB = [this, SubStmt](InsertPointTy AllocaIP,
+ InsertPointTy CodeGenIP,
+ llvm::BasicBlock &FiniBB) {
+  OMPBuilderCBHelpers::InlinedRegionBodyRAII IRB(*this, AllocaIP,
+ FiniBB);
+  OMPBuilderCBHelpers::EmitOMPRegionBody(*this, SubStmt, CodeGenIP,
+ FiniBB);
+};
+SectionCBVector.push_back(SectionCB);
+  }
+} else {
+  auto SectionCB = [this, CapturedStmt](InsertPointTy AllocaIP,
+InsertPointTy CodeGenIP,
+llvm::BasicBlock &FiniBB) {
+OMPBuilderCBHelpers::InlinedRegionBodyRAII IRB(*this, AllocaIP, 
FiniBB);
+OMPBuilderCBHelpers::EmitOMPRegionBody(*this, CapturedStmt, CodeGenIP,
+   FiniBB);
+  };
+  SectionCBVector.push_back(SectionCB);
+}
+
+// Privatization callback that performs appropriate action for
+// shared/private/firstprivate/lastprivate/copyin/... variables.
+//
+// TODO: This defaults to shared right now.
+auto PrivCB = [](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
+ llvm::Value &, llvm::Value &Val, llvm::Value *&ReplVal) {
+  // The next