[llvm-branch-commits] [flang] 6f4d460 - [Flang][openmp][openacc] Extend CheckNoBranching to handle branching provided by LabelEnforce.

2021-01-12 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2021-01-13T00:04:45+05:30
New Revision: 6f4d460762006af17826693abc1e7139a76aa1f2

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

LOG: [Flang][openmp][openacc] Extend CheckNoBranching to handle branching 
provided by LabelEnforce.

`CheckNoBranching` is currently handling only illegal branching out for 
constructs
with `Parser::Name` in them.
Extend the same for handling illegal branching out caused by `Parser::Label` 
based statements.
This patch could possibly solve one of the issues(typically branching out) 
mentioned in D92735.

Reviewed By: kiranchandramohan

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

Added: 


Modified: 
flang/lib/Semantics/check-directive-structure.h
flang/lib/Semantics/check-omp-structure.cpp
flang/test/Semantics/omp-parallell01.f90

Removed: 




diff  --git a/flang/lib/Semantics/check-directive-structure.h 
b/flang/lib/Semantics/check-directive-structure.h
index 062f85b63b85..1075087feb4f 100644
--- a/flang/lib/Semantics/check-directive-structure.h
+++ b/flang/lib/Semantics/check-directive-structure.h
@@ -15,7 +15,6 @@
 #include "flang/Common/enum-set.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/tools.h"
-
 #include 
 
 namespace Fortran::semantics {
@@ -43,6 +42,9 @@ template  class NoBranchingEnforce {
 
   template  bool Pre(const parser::Statement &statement) {
 currentStatementSourcePosition_ = statement.source;
+if (statement.label.has_value()) {
+  labels_.insert(*statement.label);
+}
 return true;
   }
 
@@ -54,6 +56,8 @@ template  class NoBranchingEnforce {
   }
   void Post(const parser::StopStmt &) { EmitBranchOutError("STOP"); }
 
+  std::set labels() { return labels_; }
+
 private:
   parser::MessageFormattedText GetEnclosingMsg() const {
 return {"Enclosing %s construct"_en_US, upperCaseDirName_};
@@ -103,6 +107,7 @@ template  class NoBranchingEnforce {
   parser::CharBlock sourcePosition_;
   std::string upperCaseDirName_;
   D currentDirective_;
+  std::set labels_;
 };
 
 // Generic structure checker for directives/clauses language such as OpenMP
@@ -226,6 +231,9 @@ class DirectiveStructureChecker : public virtual 
BaseChecker {
   SayNotMatching(beginDir.source, endDir.source);
 }
   }
+  // Check illegal branching out of `Parser::Block` for `Parser::Name` based
+  // nodes (examples `Parser::ExitStmt`) along with `Parser::Label`
+  // based nodes (example `Parser::GotoStmt`).
   void CheckNoBranching(const parser::Block &block, D directive,
   const parser::CharBlock &directiveSource);
 
@@ -271,6 +279,11 @@ void DirectiveStructureChecker::CheckNoBranching(
   NoBranchingEnforce noBranchingEnforce{
   context_, directiveSource, directive, ContextDirectiveAsFortran()};
   parser::Walk(block, noBranchingEnforce);
+
+  LabelEnforce directiveLabelEnforce{context_, noBranchingEnforce.labels(),
+  directiveSource,
+  parser::ToUpperCaseLetters(getDirectiveName(directive).str()).c_str()};
+  parser::Walk(block, directiveLabelEnforce);
 }
 
 // Check that only clauses included in the given set are present after the 
given

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index 4d1c96f66905..773f5b2aeb21 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -125,14 +125,7 @@ void OmpStructureChecker::Enter(const 
parser::OpenMPBlockConstruct &x) {
   CheckMatching(beginDir, endDir);
 
   PushContextAndClauseSets(beginDir.source, beginDir.v);
-
-  switch (beginDir.v) {
-  case llvm::omp::OMPD_parallel:
-CheckNoBranching(block, llvm::omp::OMPD_parallel, beginDir.source);
-break;
-  default:
-break;
-  }
+  CheckNoBranching(block, beginDir.v, beginDir.source);
 }
 
 void OmpStructureChecker::Leave(const parser::OpenMPBlockConstruct &) {

diff  --git a/flang/test/Semantics/omp-parallell01.f90 
b/flang/test/Semantics/omp-parallell01.f90
index e3490563f332..1a2cae1830bc 100644
--- a/flang/test/Semantics/omp-parallell01.f90
+++ b/flang/test/Semantics/omp-parallell01.f90
@@ -1,5 +1,4 @@
 ! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
-! XFAIL: *
 
 ! OpenMP Version 4.5
 ! 2.5 parallel construct.
@@ -13,7 +12,7 @@ program omp_parallel
   do i = 1, 10
 do j = 1, 10
   print *, "Hello"
-  !ERROR: invalid branch to/from OpenMP structured block
+  !ERROR: Control flow escapes from PARALLEL
   goto 10
 end do
   end do



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] 6280bc1 - [Flang][openmp][5.0] Add task_reduction clause.

2021-01-03 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2021-01-04T08:48:11+05:30
New Revision: 6280bc1cc34ad67c4297b2da1ff3920f410e6894

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

LOG: [Flang][openmp][5.0] Add task_reduction clause.

See OMP-5.0 2.19.5.5 task_reduction Clause.
To add a positive test case we need `taskgroup` directive which is not added 
hence skipping the test.
This is a dependency for `taskgroup` construct.

Reviewed By: clementval

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

Co-authored-by: Valentin Clement 

Added: 


Modified: 
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/test/Semantics/omp-clause-validity01.f90
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 7e258b668576..119a92bee211 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3415,7 +3415,7 @@ struct OmpReductionOperator {
 // variable-name-list)
 struct OmpReductionClause {
   TUPLE_CLASS_BOILERPLATE(OmpReductionClause);
-  std::tuple> t;
+  std::tuple t;
 };
 
 // OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list)

diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 1386b2b16a78..3a0d28cd9c12 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -102,7 +102,7 @@ 
TYPE_PARSER(construct(Parser{}) ||
 construct(Parser{}))
 
 TYPE_PARSER(construct(
-Parser{} / ":", nonemptyList(designator)))
+Parser{} / ":", Parser{}))
 
 // OMP 5.0 2.11.4  ALLOCATE ([allocator:] variable-name-list)
 TYPE_PARSER(construct(
@@ -220,6 +220,9 @@ TYPE_PARSER(
parenthesized(Parser{}))) ||
 "REDUCTION" >>
 construct(parenthesized(Parser{})) ||
+"TASK_REDUCTION" >>
+construct(construct(
+parenthesized(Parser{}))) ||
 "RELAXED" >> construct(construct()) ||
 "RELEASE" >> construct(construct()) ||
 "SAFELEN" >> construct(construct(

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index fdb694f3d26f..ba54a0a84fa7 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2016,7 +2016,7 @@ class UnparseVisitor {
 Word("REDUCTION(");
 Walk(std::get(x.t));
 Put(":");
-Walk(std::get>(x.t), ",");
+Walk(std::get(x.t));
 Put(")");
   }
   void Unparse(const OmpAllocateClause &x) {

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index e2c8333ce7ee..a144c7a2b57b 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -419,6 +419,7 @@ CHECK_SIMPLE_CLAUSE(Mergeable, OMPC_mergeable)
 CHECK_SIMPLE_CLAUSE(Nogroup, OMPC_nogroup)
 CHECK_SIMPLE_CLAUSE(Notinbranch, OMPC_notinbranch)
 CHECK_SIMPLE_CLAUSE(Nowait, OMPC_nowait)
+CHECK_SIMPLE_CLAUSE(TaskReduction, OMPC_task_reduction)
 CHECK_SIMPLE_CLAUSE(To, OMPC_to)
 CHECK_SIMPLE_CLAUSE(Uniform, OMPC_uniform)
 CHECK_SIMPLE_CLAUSE(Untied, OMPC_untied)

diff  --git a/flang/lib/Semantics/check-omp-structure.h 
b/flang/lib/Semantics/check-omp-structure.h
index a966eaf8c4a7..ccd0e08a8c08 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -155,6 +155,7 @@ class OmpStructureChecker
   void Enter(const parser::OmpClause::Safelen &);
   void Enter(const parser::OmpClause::Shared &);
   void Enter(const parser::OmpClause::Simdlen &);
+  void Enter(const parser::OmpClause::TaskReduction &);
   void Enter(const parser::OmpClause::ThreadLimit &);
   void Enter(const parser::OmpClause::To &);
   void Enter(const parser::OmpClause::Link &);

diff  --git a/flang/test/Semantics/omp-clause-validity01.f90 
b/flang/test/Semantics/omp-clause-validity01.f90
index 3f5345137866..1d689ea91699 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -349,7 +349,8 @@
 !  collapse-clause
 
   a = 0.0
-  !$omp simd private(b) reduction(+:a)
+  !ERROR: TASK_REDUCTION clause is not allowed on the SIMD directive
+  !$omp simd private(b) reduction(+:a) task_reduction(+:a)
   do i = 1, N
  a = a + b + 3.14
   enddo
@@ -449,7 +450,8 @@
   enddo
 
   !ERROR: At most one NUM_TASKS clause can appear on the TASKLOOP directive
-  !$omp taskloop num_tasks(3) num_tasks(2)
+  !ERROR: TASK_REDUCTION clause is not allowed on the TASKLOOP directive
+  !$omp taskloop num_tas

[llvm-branch-commits] [flang] a4e47cd - [Flang][openmp]Fix crash in OpenMP semantic check( bug 48308)

2020-12-17 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-17T15:17:13+05:30
New Revision: a4e47cd1857be1a1bfdada2a1c60a521fd21ecee

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

LOG: [Flang][openmp]Fix crash in OpenMP semantic check( bug 48308)

Fixes the bug reported in https://bugs.llvm.org/show_bug.cgi?id=48308

Reviewed By: kiranchandramohan, clementval

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

Added: 
flang/test/Semantics/omp-no-dowhile-in-parallel.f90

Modified: 
flang/lib/Semantics/resolve-directives.cpp

Removed: 




diff  --git a/flang/lib/Semantics/resolve-directives.cpp 
b/flang/lib/Semantics/resolve-directives.cpp
index 56f8f8fae955..16fdb09a5dbc 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -875,17 +875,24 @@ void 
OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
   }
 }
 
-// 2.15.1.1 Data-sharing Attribute Rules - Predetermined
+// [OMP-4.5]2.15.1.1 Data-sharing Attribute Rules - Predetermined
 //   - A loop iteration variable for a sequential loop in a parallel
 // or task generating construct is private in the innermost such
 // construct that encloses the loop
+// Loop iteration variables are not well defined for DO WHILE loop.
+// Use of DO CONCURRENT inside OpenMP construct is unspecified behavior
+// till OpenMP-5.0 standard.
+// In above both cases we skip the privatization of iteration variables.
 bool OmpAttributeVisitor::Pre(const parser::DoConstruct &x) {
-  if (!dirContext_.empty() && GetContext().withinConstruct) {
-if (const auto &iv{GetLoopIndex(x)}; iv.symbol) {
-  if (!iv.symbol->test(Symbol::Flag::OmpPreDetermined)) {
-ResolveSeqLoopIndexInParallelOrTaskConstruct(iv);
-  } else {
-// TODO: conflict checks with explicitly determined DSA
+  // TODO:[OpenMP 5.1] DO CONCURRENT indices are private
+  if (x.IsDoNormal()) {
+if (!dirContext_.empty() && GetContext().withinConstruct) {
+  if (const auto &iv{GetLoopIndex(x)}; iv.symbol) {
+if (!iv.symbol->test(Symbol::Flag::OmpPreDetermined)) {
+  ResolveSeqLoopIndexInParallelOrTaskConstruct(iv);
+} else {
+  // TODO: conflict checks with explicitly determined DSA
+}
   }
 }
   }

diff  --git a/flang/test/Semantics/omp-no-dowhile-in-parallel.f90 
b/flang/test/Semantics/omp-no-dowhile-in-parallel.f90
new file mode 100644
index ..f49d29c93a90
--- /dev/null
+++ b/flang/test/Semantics/omp-no-dowhile-in-parallel.f90
@@ -0,0 +1,28 @@
+! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+
+subroutine bug48308(x,i)
+  real :: x(:)
+  integer :: i
+  !$omp parallel firstprivate(i)
+do while (i>0)
+  x(i) = i
+  i = i - 1
+end do
+  !$omp end parallel
+end subroutine
+
+subroutine s1(x,i)
+  real :: x(:)
+  integer :: i
+  !$omp parallel firstprivate(i)
+do i = 10, 1, -1
+  x(i) = i
+end do
+  !$omp end parallel
+
+  !$omp parallel firstprivate(i)
+do concurrent (i = 1:10:1)
+  x(i) = i
+end do
+  !$omp end parallel
+end subroutine



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] 442aac5 - [Flang][openmp][1/5] Make Allocate clause part of OmpClause

2020-12-21 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-22T12:53:34+05:30
New Revision: 442aac5da68c467563dc6fedf37892ee3d2b688b

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

LOG: [Flang][openmp][1/5] Make Allocate clause part of OmpClause

After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `allocate` clause part of `OmpClause`.The unparse function for
`OmpAllocateClause` is adapted since the keyword and parenthesis are issued by
the corresponding unparse function for `parser::OmpClause::Allocate`.

Reviewed By: clementval

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

Added: 


Modified: 
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 67c377e798ca..ff8ba774a6ce 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -157,8 +157,8 @@ TYPE_PARSER(
 "ACQ_REL" >> construct(construct()) ||
 "ALIGNED" >>
 construct(parenthesized(Parser{})) ||
-"ALLOCATE" >>
-construct(parenthesized(Parser{})) ||
+"ALLOCATE" >> construct(construct(
+  parenthesized(Parser{}))) ||
 "ALLOCATOR" >> construct(construct(
parenthesized(scalarIntExpr))) ||
 "COLLAPSE" >> construct(construct(

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index a027c8fc9af6..ed17bac92965 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2020,10 +2020,9 @@ class UnparseVisitor {
 Put(")");
   }
   void Unparse(const OmpAllocateClause &x) {
-Word("ALLOCATE(");
-Walk(std::get>(x.t), ":");
+Walk(std::get>(x.t));
+Put(":");
 Walk(std::get(x.t));
-Put(")");
   }
   void Unparse(const OmpDependSinkVecLength &x) {
 Walk(std::get(x.t));

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index 978e1c7962a4..58db75459318 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -403,6 +403,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause &x) 
{
 
 // Following clauses do not have a seperate node in parse-tree.h.
 // They fall under 'struct OmpClause' in parse-tree.h.
+CHECK_SIMPLE_CLAUSE(Allocate, OMPC_allocate)
 CHECK_SIMPLE_CLAUSE(Copyin, OMPC_copyin)
 CHECK_SIMPLE_CLAUSE(Copyprivate, OMPC_copyprivate)
 CHECK_SIMPLE_CLAUSE(Device, OMPC_device)
@@ -489,7 +490,6 @@ void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
   }
 }
 // Following clauses have a seperate node in parse-tree.h.
-CHECK_SIMPLE_PARSER_CLAUSE(OmpAllocateClause, OMPC_allocate)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpDefaultClause, OMPC_default)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpDistScheduleClause, OMPC_dist_schedule)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpNowait, OMPC_nowait)

diff  --git a/flang/lib/Semantics/check-omp-structure.h 
b/flang/lib/Semantics/check-omp-structure.h
index 2949568f6044..32da0fb00954 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -127,6 +127,7 @@ class OmpStructureChecker
   void Leave(const parser::OmpClauseList &);
   void Enter(const parser::OmpClause &);
   void Enter(const parser::OmpNowait &);
+  void Enter(const parser::OmpClause::Allocate &);
   void Enter(const parser::OmpClause::Allocator &);
   void Enter(const parser::OmpClause::Inbranch &);
   void Enter(const parser::OmpClause::Mergeable &);
@@ -174,7 +175,6 @@ class OmpStructureChecker
   void Enter(const parser::OmpAtomicCapture &);
   void Leave(const parser::OmpAtomic &);
   void Enter(const parser::OmpAlignedClause &);
-  void Enter(const parser::OmpAllocateClause &);
   void Enter(const parser::OmpDefaultClause &);
   void Enter(const parser::OmpDefaultmapClause &);
   void Enter(const parser::OmpDependClause &);

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td 
b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index 58aa1bf23b68..6ad8fa92084b 100644
--- a/llvm/include/llvm/Fronten

[llvm-branch-commits] [flang] f72c384 - [Flang][openmp][2/5] Make Default clause part of OmpClause

2020-12-21 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-22T13:17:44+05:30
New Revision: f72c384b5ba943c92fadcbe77f9d7661728905ab

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

LOG: [Flang][openmp][2/5] Make Default clause part of OmpClause

After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `OmpDefaultClause` clause part of `OmpClause`.
The unparse function is dropped as the unparsing is done by `WALK_NESTED_ENUM`
for `OmpDefaultClause`.

Reviewed By: clementval, kiranktp

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

Added: 


Modified: 
flang/lib/Lower/OpenMP.cpp
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 97946caa68a0..f73dd09fbe68 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -191,8 +191,9 @@ genOMP(Fortran::lower::AbstractConverter &converter,
 // Handle attribute based clauses.
 for (const auto &clause : parallelOpClauseList.v) {
   if (const auto &defaultClause =
-  std::get_if(&clause.u)) {
-switch (defaultClause->v) {
+  std::get_if(&clause.u)) {
+const auto &ompDefaultClause{defaultClause->v};
+switch (ompDefaultClause.v) {
 case Fortran::parser::OmpDefaultClause::Type::Private:
   parallelOp.default_valAttr(firOpBuilder.getStringAttr(
   omp::stringifyClauseDefault(omp::ClauseDefault::defprivate)));

diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index ff8ba774a6ce..e982dd19e498 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -167,8 +167,8 @@ TYPE_PARSER(
 parenthesized(Parser{}))) ||
 "COPYPRIVATE" >> construct(construct(
  (parenthesized(Parser{} ||
-"DEFAULT"_id >>
-construct(parenthesized(Parser{})) ||
+"DEFAULT"_id >> construct(construct(
+parenthesized(Parser{}))) ||
 "DEFAULTMAP" >>
 construct(parenthesized(Parser{})) ||
 "DEPEND" >>

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index ed17bac92965..a4b0c64011fc 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2058,11 +2058,6 @@ class UnparseVisitor {
   },
 x.u);
   }
-  bool Pre(const OmpDefaultClause &) {
-Word("DEFAULT(");
-return true;
-  }
-  void Post(const OmpDefaultClause &) { Put(")"); }
   bool Pre(const OmpProcBindClause &) {
 Word("PROC_BIND(");
 return true;

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index 58db75459318..6ed7106bb9f4 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -406,6 +406,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause &x) 
{
 CHECK_SIMPLE_CLAUSE(Allocate, OMPC_allocate)
 CHECK_SIMPLE_CLAUSE(Copyin, OMPC_copyin)
 CHECK_SIMPLE_CLAUSE(Copyprivate, OMPC_copyprivate)
+CHECK_SIMPLE_CLAUSE(Default, OMPC_default)
 CHECK_SIMPLE_CLAUSE(Device, OMPC_device)
 CHECK_SIMPLE_CLAUSE(Final, OMPC_final)
 CHECK_SIMPLE_CLAUSE(Firstprivate, OMPC_firstprivate)
@@ -490,7 +491,6 @@ void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
   }
 }
 // Following clauses have a seperate node in parse-tree.h.
-CHECK_SIMPLE_PARSER_CLAUSE(OmpDefaultClause, OMPC_default)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpDistScheduleClause, OMPC_dist_schedule)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpNowait, OMPC_nowait)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpProcBindClause, OMPC_proc_bind)

diff  --git a/flang/lib/Semantics/check-omp-structure.h 
b/flang/lib/Semantics/check-omp-structure.h
index 32da0fb00954..dcc2deeb348c 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -137,6 +137,7 @@ class OmpStructureChecker
   void Enter(const parser::OmpClause::Collapse &);
   void Enter(const parser::OmpClause::Copyin &);
   void Enter(cons

[llvm-branch-commits] [llvm] 34958d1 - [Flang][openmp][3/5] Make ProcBind clause part of OmpClause

2020-12-22 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-22T13:40:38+05:30
New Revision: 34958d11c3457c8e05bbe2b31d5e013c04aecb55

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

LOG: [Flang][openmp][3/5] Make ProcBind clause part of OmpClause

After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `OmpProcBindClause` clause part of `OmpClause`.
The unparse function is dropped as the unparsing is done by `WALK_NESTED_ENUM`
for `OmpProcBindClause`.

Reviewed By: clementval, kiranktp

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

Added: 


Modified: 
flang/lib/Lower/OpenMP.cpp
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index f73dd09fbe68..f765723bb9ae 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -214,8 +214,9 @@ genOMP(Fortran::lower::AbstractConverter &converter,
 }
   }
   if (const auto &procBindClause =
-  std::get_if(&clause.u)) {
-switch (procBindClause->v) {
+  std::get_if(&clause.u)) {
+const auto &ompProcBindClause{procBindClause->v};
+switch (ompProcBindClause.v) {
 case Fortran::parser::OmpProcBindClause::Type::Master:
   parallelOp.proc_bind_valAttr(
   firOpBuilder.getStringAttr(omp::stringifyClauseProcBindKind(

diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index e982dd19e498..50999bef8f52 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -216,8 +216,8 @@ TYPE_PARSER(
   parenthesized(scalarIntExpr))) ||
 "PRIVATE" >> construct(construct(
  parenthesized(Parser{}))) ||
-"PROC_BIND" >>
-construct(parenthesized(Parser{})) ||
+"PROC_BIND" >> construct(construct(
+   parenthesized(Parser{}))) ||
 "REDUCTION" >>
 construct(parenthesized(Parser{})) ||
 "RELAXED" >> construct(construct()) ||

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index a4b0c64011fc..6be063c1b1bc 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2058,11 +2058,6 @@ class UnparseVisitor {
   },
 x.u);
   }
-  bool Pre(const OmpProcBindClause &) {
-Word("PROC_BIND(");
-return true;
-  }
-  void Post(const OmpProcBindClause &) { Put(")"); }
   void Unparse(const OmpDefaultmapClause &x) {
 Word("DEFAULTMAP(");
 Walk(std::get(x.t));

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index 6ed7106bb9f4..481099b34966 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -428,6 +428,7 @@ CHECK_SIMPLE_CLAUSE(SeqCst, OMPC_seq_cst)
 CHECK_SIMPLE_CLAUSE(Release, OMPC_release)
 CHECK_SIMPLE_CLAUSE(Relaxed, OMPC_relaxed)
 CHECK_SIMPLE_CLAUSE(Hint, OMPC_hint)
+CHECK_SIMPLE_CLAUSE(ProcBind, OMPC_proc_bind)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Allocator, OMPC_allocator)
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
@@ -493,7 +494,6 @@ void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
 // Following clauses have a seperate node in parse-tree.h.
 CHECK_SIMPLE_PARSER_CLAUSE(OmpDistScheduleClause, OMPC_dist_schedule)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpNowait, OMPC_nowait)
-CHECK_SIMPLE_PARSER_CLAUSE(OmpProcBindClause, OMPC_proc_bind)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpReductionClause, OMPC_reduction)
 // Atomic-clause
 CHECK_SIMPLE_PARSER_CLAUSE(OmpAtomicRead, OMPC_read)

diff  --git a/flang/lib/Semantics/check-omp-structure.h 
b/flang/lib/Semantics/check-omp-structure.h
index dcc2deeb348c..89fc3d9faa21 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -150,6 +150,7 @@ class OmpStructureChecker
   void Enter(const parser::OmpClause::Ordered &);
   void Enter(const parser::OmpClause::Priority &);
   void Enter(const parser::OmpClause::Private &);
+  void 

[llvm-branch-commits] [flang] e282ae5 - [Flang][openmp][4/5] Make nowait clause part of OmpClause

2020-12-22 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-22T14:02:19+05:30
New Revision: e282ae57da29a37e143ab6d640f68e794f5cd614

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

LOG: [Flang][openmp][4/5] Make nowait clause part of OmpClause

After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `OmpNoWait` clause part of `OmpClause`.

Reviewed By: clementval, kiranktp

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

Added: 


Modified: 
flang/include/flang/Parser/dump-parse-tree.h
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/include/flang/Parser/dump-parse-tree.h 
b/flang/include/flang/Parser/dump-parse-tree.h
index f69dd149e0a3..05152f8c49c6 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -508,7 +508,6 @@ class ParseTreeDumper {
 "llvm::omp::Clause = ", llvm::omp::getOpenMPClauseName(x))
 .str();
   }
-  NODE(parser, OmpNowait)
   NODE(parser, OmpObject)
   NODE(parser, OmpObjectList)
   NODE(parser, OmpProcBindClause)

diff  --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 59fa278e0029..09c61477d2e7 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3456,9 +3456,6 @@ struct OmpDependClause {
   std::variant u;
 };
 
-// 2.7.1 nowait-clause -> NOWAIT
-EMPTY_CLASS(OmpNowait);
-
 // dist_schedule clause does not fit in generic clause class for tablegen.
 // Therefore it is declared separatly here.
 WRAPPER_CLASS(OmpDistScheduleClause, std::optional);

diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 50999bef8f52..62dd0d1e7d29 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -203,7 +203,7 @@ TYPE_PARSER(
 "NOGROUP" >> construct(construct()) ||
 "NOTINBRANCH" >>
 construct(construct()) ||
-"NOWAIT" >> construct(construct()) ||
+"NOWAIT" >> construct(construct()) ||
 "NUM_TASKS" >> construct(construct(
parenthesized(scalarIntExpr))) ||
 "NUM_TEAMS" >> construct(construct(

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 6be063c1b1bc..5dbf9940e26e 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2065,7 +2065,6 @@ class UnparseVisitor {
 std::get>(x.t));
 Word(")");
   }
-  void Unparse(const OmpNowait &) { Word("NOWAIT"); }
   void Unparse(const OmpDistScheduleClause &x) {
 Word("DIST_SCHEDULE(STATIC");
 Walk(", ", x.v);

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index 481099b34966..c901630c098b 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -418,6 +418,7 @@ CHECK_SIMPLE_CLAUSE(Link, OMPC_link)
 CHECK_SIMPLE_CLAUSE(Mergeable, OMPC_mergeable)
 CHECK_SIMPLE_CLAUSE(Nogroup, OMPC_nogroup)
 CHECK_SIMPLE_CLAUSE(Notinbranch, OMPC_notinbranch)
+CHECK_SIMPLE_CLAUSE(Nowait, OMPC_nowait)
 CHECK_SIMPLE_CLAUSE(To, OMPC_to)
 CHECK_SIMPLE_CLAUSE(Uniform, OMPC_uniform)
 CHECK_SIMPLE_CLAUSE(Untied, OMPC_untied)
@@ -493,7 +494,6 @@ void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
 }
 // Following clauses have a seperate node in parse-tree.h.
 CHECK_SIMPLE_PARSER_CLAUSE(OmpDistScheduleClause, OMPC_dist_schedule)
-CHECK_SIMPLE_PARSER_CLAUSE(OmpNowait, OMPC_nowait)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpReductionClause, OMPC_reduction)
 // Atomic-clause
 CHECK_SIMPLE_PARSER_CLAUSE(OmpAtomicRead, OMPC_read)

diff  --git a/flang/lib/Semantics/check-omp-structure.h 
b/flang/lib/Semantics/check-omp-structure.h
index 89fc3d9faa21..72bb9a523366 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -126,12 +126,12 @@ class OmpStructureChecker
 
   void Leave(const parser::OmpClauseList &);
   void Enter(const parser::OmpClause &);
-  void E

[llvm-branch-commits] [flang] 1a6f439 - [Flang][openmp][5/5] Make dist_schedule clause part of OmpClause

2020-12-22 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-22T14:32:33+05:30
New Revision: 1a6f43991ff7e5249f24660074f0dd784aeecd5f

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

LOG: [Flang][openmp][5/5] Make dist_schedule clause part of OmpClause

After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `OmpDistScheduleClause` clause part of `OmpClause`.
The unparse function for `OmpDistScheduleClause` is adapted since the keyword
and parenthesis are issued by the corresponding unparse function for
`parser::OmpClause::DistSchedule`.

Reviewed By: clementval, kiranktp

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

Added: 


Modified: 
flang/include/flang/Parser/dump-parse-tree.h
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/include/flang/Parser/dump-parse-tree.h 
b/flang/include/flang/Parser/dump-parse-tree.h
index 05152f8c49c6..60e2a2df 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -485,7 +485,6 @@ class ParseTreeDumper {
   NODE_ENUM(OmpDependenceType, Type)
   NODE(parser, OmpDependSinkVec)
   NODE(parser, OmpDependSinkVecLength)
-  NODE(parser, OmpDistScheduleClause)
   NODE(parser, OmpEndAtomic)
   NODE(parser, OmpEndBlockDirective)
   NODE(parser, OmpEndCriticalDirective)

diff  --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 09c61477d2e7..7e258b668576 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3456,10 +3456,6 @@ struct OmpDependClause {
   std::variant u;
 };
 
-// dist_schedule clause does not fit in generic clause class for tablegen.
-// Therefore it is declared separatly here.
-WRAPPER_CLASS(OmpDistScheduleClause, std::optional);
-
 // OpenMP Clauses
 struct OmpClause {
   UNION_CLASS_BOILERPLATE(OmpClause);

diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 62dd0d1e7d29..1386b2b16a78 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -176,7 +176,7 @@ TYPE_PARSER(
 "DEVICE" >> construct(construct(
 parenthesized(scalarIntExpr))) ||
 "DIST_SCHEDULE" >>
-construct(construct(
+construct(construct(
 parenthesized("STATIC" >> maybe("," >> scalarIntExpr ||
 "FINAL" >> construct(construct(
parenthesized(scalarLogicalExpr))) ||

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 5dbf9940e26e..fdb694f3d26f 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2065,11 +2065,6 @@ class UnparseVisitor {
 std::get>(x.t));
 Word(")");
   }
-  void Unparse(const OmpDistScheduleClause &x) {
-Word("DIST_SCHEDULE(STATIC");
-Walk(", ", x.v);
-Put(")");
-  }
 #define GEN_FLANG_CLAUSE_UNPARSE
 #include "llvm/Frontend/OpenMP/OMP.inc"
   void Unparse(const OmpLoopDirective &x) {

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index c901630c098b..e2c8333ce7ee 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -430,6 +430,7 @@ CHECK_SIMPLE_CLAUSE(Release, OMPC_release)
 CHECK_SIMPLE_CLAUSE(Relaxed, OMPC_relaxed)
 CHECK_SIMPLE_CLAUSE(Hint, OMPC_hint)
 CHECK_SIMPLE_CLAUSE(ProcBind, OMPC_proc_bind)
+CHECK_SIMPLE_CLAUSE(DistSchedule, OMPC_dist_schedule)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Allocator, OMPC_allocator)
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
@@ -493,7 +494,6 @@ void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
   }
 }
 // Following clauses have a seperate node in parse-tree.h.
-CHECK_SIMPLE_PARSER_CLAUSE(OmpDistScheduleClause, OMPC_dist_schedule)
 CHECK_SIMPLE_PARSER_CLAUSE(OmpReductionClause, OMPC_reduction)
 // Atomic-clause
 CHECK_SIMPLE_PARSER_CLAUSE(OmpAtomicRead, OMPC_read)

diff  --git a/flang/lib/Semantics/check-omp-structure.h 
b

[llvm-branch-commits] [flang] 9a7895d - [Flang][openmp][5.0] Add task_reduction clause.

2020-12-22 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-22T22:34:38+05:30
New Revision: 9a7895dc20852b662a66976d06871ec2a0b968c8

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

LOG: [Flang][openmp][5.0] Add task_reduction clause.

See OMP-5.0 2.19.5.5 task_reduction Clause.
To add a positive test case we need `taskgroup` directive which is not added 
hence skipping the test.
This is a dependency for `taskgroup` construct.

Reviewed By: clementval

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

Added: 


Modified: 
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/test/Semantics/omp-clause-validity01.f90
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 7e258b668576..119a92bee211 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3415,7 +3415,7 @@ struct OmpReductionOperator {
 // variable-name-list)
 struct OmpReductionClause {
   TUPLE_CLASS_BOILERPLATE(OmpReductionClause);
-  std::tuple> t;
+  std::tuple t;
 };
 
 // OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list)

diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 1386b2b16a78..3a0d28cd9c12 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -102,7 +102,7 @@ 
TYPE_PARSER(construct(Parser{}) ||
 construct(Parser{}))
 
 TYPE_PARSER(construct(
-Parser{} / ":", nonemptyList(designator)))
+Parser{} / ":", Parser{}))
 
 // OMP 5.0 2.11.4  ALLOCATE ([allocator:] variable-name-list)
 TYPE_PARSER(construct(
@@ -220,6 +220,9 @@ TYPE_PARSER(
parenthesized(Parser{}))) ||
 "REDUCTION" >>
 construct(parenthesized(Parser{})) ||
+"TASK_REDUCTION" >>
+construct(construct(
+parenthesized(Parser{}))) ||
 "RELAXED" >> construct(construct()) ||
 "RELEASE" >> construct(construct()) ||
 "SAFELEN" >> construct(construct(

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index fdb694f3d26f..ba54a0a84fa7 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2016,7 +2016,7 @@ class UnparseVisitor {
 Word("REDUCTION(");
 Walk(std::get(x.t));
 Put(":");
-Walk(std::get>(x.t), ",");
+Walk(std::get(x.t));
 Put(")");
   }
   void Unparse(const OmpAllocateClause &x) {

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index e2c8333ce7ee..a144c7a2b57b 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -419,6 +419,7 @@ CHECK_SIMPLE_CLAUSE(Mergeable, OMPC_mergeable)
 CHECK_SIMPLE_CLAUSE(Nogroup, OMPC_nogroup)
 CHECK_SIMPLE_CLAUSE(Notinbranch, OMPC_notinbranch)
 CHECK_SIMPLE_CLAUSE(Nowait, OMPC_nowait)
+CHECK_SIMPLE_CLAUSE(TaskReduction, OMPC_task_reduction)
 CHECK_SIMPLE_CLAUSE(To, OMPC_to)
 CHECK_SIMPLE_CLAUSE(Uniform, OMPC_uniform)
 CHECK_SIMPLE_CLAUSE(Untied, OMPC_untied)

diff  --git a/flang/lib/Semantics/check-omp-structure.h 
b/flang/lib/Semantics/check-omp-structure.h
index a966eaf8c4a7..ccd0e08a8c08 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -155,6 +155,7 @@ class OmpStructureChecker
   void Enter(const parser::OmpClause::Safelen &);
   void Enter(const parser::OmpClause::Shared &);
   void Enter(const parser::OmpClause::Simdlen &);
+  void Enter(const parser::OmpClause::TaskReduction &);
   void Enter(const parser::OmpClause::ThreadLimit &);
   void Enter(const parser::OmpClause::To &);
   void Enter(const parser::OmpClause::Link &);

diff  --git a/flang/test/Semantics/omp-clause-validity01.f90 
b/flang/test/Semantics/omp-clause-validity01.f90
index 3f5345137866..1d689ea91699 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -349,7 +349,8 @@
 !  collapse-clause
 
   a = 0.0
-  !$omp simd private(b) reduction(+:a)
+  !ERROR: TASK_REDUCTION clause is not allowed on the SIMD directive
+  !$omp simd private(b) reduction(+:a) task_reduction(+:a)
   do i = 1, N
  a = a + b + 3.14
   enddo
@@ -449,7 +450,8 @@
   enddo
 
   !ERROR: At most one NUM_TASKS clause can appear on the TASKLOOP directive
-  !$omp taskloop num_tasks(3) num_tasks(2)
+  !ERROR: TASK_REDUCTION clause is not allowed on the TASKLOOP directive
+  !$omp taskloop num_tasks(3) num_tasks(2) task_reduction(*

[llvm-branch-commits] [llvm] 1aa10ab - Revert "[Flang][openmp][5.0] Add task_reduction clause."

2020-12-22 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-22T23:53:51+05:30
New Revision: 1aa10ab2e1ddc863a944fb181b2b8ed633864bab

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

LOG: Revert "[Flang][openmp][5.0] Add task_reduction clause."

This reverts commit 9a7895dc20852b662a66976d06871ec2a0b968c8.
Reverting due to missing Co-author attribution.

https://reviews.llvm.org/D93105

Added: 


Modified: 
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/test/Semantics/omp-clause-validity01.f90
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 119a92bee211..7e258b668576 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3415,7 +3415,7 @@ struct OmpReductionOperator {
 // variable-name-list)
 struct OmpReductionClause {
   TUPLE_CLASS_BOILERPLATE(OmpReductionClause);
-  std::tuple t;
+  std::tuple> t;
 };
 
 // OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list)

diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 3a0d28cd9c12..1386b2b16a78 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -102,7 +102,7 @@ 
TYPE_PARSER(construct(Parser{}) ||
 construct(Parser{}))
 
 TYPE_PARSER(construct(
-Parser{} / ":", Parser{}))
+Parser{} / ":", nonemptyList(designator)))
 
 // OMP 5.0 2.11.4  ALLOCATE ([allocator:] variable-name-list)
 TYPE_PARSER(construct(
@@ -220,9 +220,6 @@ TYPE_PARSER(
parenthesized(Parser{}))) ||
 "REDUCTION" >>
 construct(parenthesized(Parser{})) ||
-"TASK_REDUCTION" >>
-construct(construct(
-parenthesized(Parser{}))) ||
 "RELAXED" >> construct(construct()) ||
 "RELEASE" >> construct(construct()) ||
 "SAFELEN" >> construct(construct(

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index ba54a0a84fa7..fdb694f3d26f 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2016,7 +2016,7 @@ class UnparseVisitor {
 Word("REDUCTION(");
 Walk(std::get(x.t));
 Put(":");
-Walk(std::get(x.t));
+Walk(std::get>(x.t), ",");
 Put(")");
   }
   void Unparse(const OmpAllocateClause &x) {

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index a144c7a2b57b..e2c8333ce7ee 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -419,7 +419,6 @@ CHECK_SIMPLE_CLAUSE(Mergeable, OMPC_mergeable)
 CHECK_SIMPLE_CLAUSE(Nogroup, OMPC_nogroup)
 CHECK_SIMPLE_CLAUSE(Notinbranch, OMPC_notinbranch)
 CHECK_SIMPLE_CLAUSE(Nowait, OMPC_nowait)
-CHECK_SIMPLE_CLAUSE(TaskReduction, OMPC_task_reduction)
 CHECK_SIMPLE_CLAUSE(To, OMPC_to)
 CHECK_SIMPLE_CLAUSE(Uniform, OMPC_uniform)
 CHECK_SIMPLE_CLAUSE(Untied, OMPC_untied)

diff  --git a/flang/lib/Semantics/check-omp-structure.h 
b/flang/lib/Semantics/check-omp-structure.h
index ccd0e08a8c08..a966eaf8c4a7 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -155,7 +155,6 @@ class OmpStructureChecker
   void Enter(const parser::OmpClause::Safelen &);
   void Enter(const parser::OmpClause::Shared &);
   void Enter(const parser::OmpClause::Simdlen &);
-  void Enter(const parser::OmpClause::TaskReduction &);
   void Enter(const parser::OmpClause::ThreadLimit &);
   void Enter(const parser::OmpClause::To &);
   void Enter(const parser::OmpClause::Link &);

diff  --git a/flang/test/Semantics/omp-clause-validity01.f90 
b/flang/test/Semantics/omp-clause-validity01.f90
index 1d689ea91699..3f5345137866 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -349,8 +349,7 @@
 !  collapse-clause
 
   a = 0.0
-  !ERROR: TASK_REDUCTION clause is not allowed on the SIMD directive
-  !$omp simd private(b) reduction(+:a) task_reduction(+:a)
+  !$omp simd private(b) reduction(+:a)
   do i = 1, N
  a = a + b + 3.14
   enddo
@@ -450,8 +449,7 @@
   enddo
 
   !ERROR: At most one NUM_TASKS clause can appear on the TASKLOOP directive
-  !ERROR: TASK_REDUCTION clause is not allowed on the TASKLOOP directive
-  !$omp taskloop num_tasks(3) num_tasks(2) task_reduction(*:a)
+  !$omp taskloop num_tasks(3) num_tasks(2)
   do i = 1,N
 a = 3.14
   enddo

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td 
b/llvm/include/llvm/Fronte

[llvm-branch-commits] [llvm] 42ecf18 - [flang][openmp] Fix bug in `OmpClause::Hint` clause which was missing to generate inside in OMP.cpp.inc file.

2020-11-21 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-11-21T19:02:34+05:30
New Revision: 42ecf188b5ae1199d5b7405c521a3e72f80e7e94

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

LOG: [flang][openmp] Fix bug in `OmpClause::Hint` clause which was missing to 
generate inside in OMP.cpp.inc file.

Before this patch "Hint" isn't found inside the generated file.
./bin/llvm-tblgen --gen-directive-gen 
../llvm-project/llvm/include/llvm/Frontend/OpenMP/OMP.td -I 
../llvm-project/llvm/include/ > OMP.cpp.in

Reviewed By: clementval

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

Added: 


Modified: 
flang/lib/Parser/openmp-parsers.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 5a7fd3d9c353..8ad13dffea04 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -184,7 +184,8 @@ TYPE_PARSER(
   parenthesized(Parser{}))) ||
 "GRAINSIZE" >> construct(construct(
parenthesized(scalarIntExpr))) ||
-"HINT" >> construct(parenthesized(constantExpr)) ||
+"HINT" >> construct(
+  construct(parenthesized(constantExpr))) ||
 "IF" >> construct(parenthesized(Parser{})) ||
 "INBRANCH" >> construct(construct()) ||
 "IS_DEVICE_PTR" >> construct(construct(

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td 
b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index 1ecf075c38a9..e73517697547 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -200,7 +200,7 @@ def OMPC_NumTasks : Clause<"num_tasks"> {
 }
 def OMPC_Hint : Clause<"hint"> {
   let clangClass = "OMPHintClause";
-  let flangClass = "ConstantExpr";
+  let flangClassValue = "ConstantExpr";
 }
 def OMPC_DistSchedule : Clause<"dist_schedule"> {
   let clangClass = "OMPDistScheduleClause";



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 1df8fa7 - [Flang][OpenMP][NFC][2/2] Reorder OmpStructureChecker and simplify it.

2020-11-21 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-11-21T22:37:35+05:30
New Revision: 1df8fa78e652d112c83d21096e5f2750f70f5b66

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

LOG: [Flang][OpenMP][NFC][2/2] Reorder OmpStructureChecker and simplify it.

`OmpStructureChecker` has too much boilerplate code in source file.

This patch:
  1. Use helpers from `check-directive-structure.h` and reduces the boilerplate.
  2. Use TableGen infrastructure as much as possible.

Reviewed By: kiranchandramohan

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

Added: 


Modified: 
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/test/Semantics/omp-clause-validity01.f90
flang/test/Semantics/omp-combined-constructs.f90
flang/test/Semantics/omp-device-constructs.f90
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index 93787672b444..3cf77137ec12 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -9,6 +9,7 @@
 #include "check-omp-structure.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/tools.h"
+#include 
 
 namespace Fortran::semantics {
 
@@ -160,8 +161,8 @@ void OmpStructureChecker::Enter(const 
parser::OmpEndSectionsDirective &x) {
   switch (dir.v) {
 // 2.7.2 end-sections -> END SECTIONS [nowait-clause]
   case llvm::omp::Directive::OMPD_sections:
-SetContextDirectiveEnum(llvm::omp::Directive::OMPD_end_sections);
-SetContextAllowedOnce(OmpClauseSet{llvm::omp::Clause::OMPC_nowait});
+PushContextAndClauseSets(
+dir.source, llvm::omp::Directive::OMPD_end_sections);
 break;
   default:
 // no clauses are allowed
@@ -183,8 +184,7 @@ void OmpStructureChecker::Enter(const 
parser::OpenMPDeclareTargetConstruct &x) {
   PushContext(dir.source, llvm::omp::Directive::OMPD_declare_target);
   const auto &spec{std::get(x.t)};
   if (std::holds_alternative(spec.u)) {
-SetContextAllowed(
-OmpClauseSet{llvm::omp::Clause::OMPC_to, 
llvm::omp::Clause::OMPC_link});
+SetClauseSets(llvm::omp::Directive::OMPD_declare_target);
   }
 }
 
@@ -248,17 +248,13 @@ void OmpStructureChecker::Enter(const 
parser::OmpEndBlockDirective &x) {
   switch (dir.v) {
   // 2.7.3 end-single-clause -> copyprivate-clause |
   //nowait-clause
-  case llvm::omp::Directive::OMPD_single: {
-SetContextDirectiveEnum(llvm::omp::Directive::OMPD_end_single);
-OmpClauseSet allowed{llvm::omp::Clause::OMPC_copyprivate};
-SetContextAllowed(allowed);
-OmpClauseSet allowedOnce{llvm::omp::Clause::OMPC_nowait};
-SetContextAllowedOnce(allowedOnce);
-  } break;
+  case llvm::omp::Directive::OMPD_single:
+PushContextAndClauseSets(dir.source, 
llvm::omp::Directive::OMPD_end_single);
+break;
   // 2.7.4 end-workshare -> END WORKSHARE [nowait-clause]
   case llvm::omp::Directive::OMPD_workshare:
-SetContextDirectiveEnum(llvm::omp::Directive::OMPD_end_workshare);
-SetContextAllowed(OmpClauseSet{llvm::omp::Clause::OMPC_nowait});
+PushContextAndClauseSets(
+dir.source, llvm::omp::Directive::OMPD_end_workshare);
 break;
   default:
 // no clauses are allowed
@@ -300,11 +296,8 @@ void OmpStructureChecker::Leave(const 
parser::OmpClauseList &) {
   std::get(clause->u)};
 
   if (orderedClause.v) {
-if (FindClause(llvm::omp::Clause::OMPC_linear)) {
-  context_.Say(clause->source,
-  "A loop directive may not have both a LINEAR clause and "
-  "an ORDERED clause with a parameter"_err_en_US);
-}
+CheckNotAllowedIfClause(
+llvm::omp::Clause::OMPC_ordered, {llvm::omp::Clause::OMPC_linear});
 
 if (auto *clause2{FindClause(llvm::omp::Clause::OMPC_collapse)}) {
   const auto &collapseClause{
@@ -347,19 +340,13 @@ void OmpStructureChecker::Leave(const 
parser::OmpClauseList &) {
 }
   }
 }
-
 // TODO: A list-item cannot appear in more than one aligned clause
   } // SIMD
 
   // 2.7.3 Single Construct Restriction
   if (GetContext().directive == llvm::omp::Directive::OMPD_end_single) {
-if (auto *clause{FindClause(llvm::omp::Clause::OMPC_copyprivate)}) {
-  if (FindClause(llvm::omp::Clause::OMPC_nowait)) {
-context_.Say(clause->source,
-"The COPYPRIVATE clause must not be used with "
-"the NOWAIT clause"_err_en_US);
-  }
-}
+CheckNotAllowedIfClause(
+llvm::omp::Clause::OMPC_copyprivate, {llvm::omp::Clause::OMPC_nowait});
   }
 
   GetContext().requiredClauses.IterateOverMembers(
@@ -410,7 +397,6 @@ void OmpStructureChecker::E

[llvm-branch-commits] [flang] e43b3b0 - [Flang][OpenMP] Semantic checks for Atomic construct.

2020-12-13 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-14T13:03:57+05:30
New Revision: e43b3b08ccd60d63d4c3316859e9fec4cdaeaddd

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

LOG: [Flang][OpenMP] Semantic checks for Atomic construct.

Patch implements restrictions from 2.17.7  of OpenMP 5.0 standard for atomic 
Construct. Tests for the same are added.

One of the restriction
`OpenMP constructs may not be encountered during execution of an atomic region.`
Is mentioned in 5.0 standard to be a semantic restriction, but given the 
stricter nature of parser in F18 it's caught at parsing itself.

This patch is a next patch in series from D88965.

Reviewed By: clementval

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

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

Modified: 
flang/include/flang/Parser/dump-parse-tree.h
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/test/Semantics/omp-atomic.f90
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/include/flang/Parser/dump-parse-tree.h 
b/flang/include/flang/Parser/dump-parse-tree.h
index 791e21fa4b62..0d819f861495 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -551,6 +551,8 @@ class ParseTreeDumper {
   NODE(parser, OpenMPDeclareSimdConstruct)
   NODE(parser, OpenMPDeclareTargetConstruct)
   NODE(parser, OmpMemoryOrderClause)
+  NODE(parser, OmpAtomicClause)
+  NODE(parser, OmpAtomicClauseList)
   NODE(parser, OpenMPFlushConstruct)
   NODE(parser, OpenMPLoopConstruct)
   NODE(parser, OpenMPExecutableAllocate)

diff  --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index ca73af210c15..5d2909a4142a 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3628,11 +3628,30 @@ struct OpenMPExecutableAllocate {
   t;
 };
 
-// 2.17.7 atomic -> ATOMIC [clause[,]] atomic-clause [[,]clause] |
-//  ATOMIC [clause]
-//clause -> memory-order-clause | HINT(hint-expression)
-//memory-order-clause -> SEQ_CST | ACQ_REL | RELEASE | ACQUIRE | 
RELAXED
-//atomic-clause -> READ | WRITE | UPDATE | CAPTURE
+// 2.17.7 Atomic construct/2.17.8 Flush construct [OpenMP 5.0]
+//memory-order-clause -> acq_rel
+//   release
+//   acquire
+//   seq_cst
+//   relaxed
+struct OmpMemoryOrderClause {
+  WRAPPER_CLASS_BOILERPLATE(OmpMemoryOrderClause, OmpClause);
+  CharBlock source;
+};
+
+// 2.17.7 Atomic construct
+//atomic-clause -> memory-order-clause | HINT(hint-expression)
+struct OmpAtomicClause {
+  UNION_CLASS_BOILERPLATE(OmpAtomicClause);
+  CharBlock source;
+  std::variant u;
+};
+
+// atomic-clause-list -> [atomic-clause, [atomic-clause], ...]
+struct OmpAtomicClauseList {
+  WRAPPER_CLASS_BOILERPLATE(OmpAtomicClauseList, std::list);
+  CharBlock source;
+};
 
 // END ATOMIC
 EMPTY_CLASS(OmpEndAtomic);
@@ -3641,8 +3660,8 @@ EMPTY_CLASS(OmpEndAtomic);
 struct OmpAtomicRead {
   TUPLE_CLASS_BOILERPLATE(OmpAtomicRead);
   CharBlock source;
-  std::tuple,
-  std::optional>
+  std::tuple, std::optional>
   t;
 };
 
@@ -3650,8 +3669,8 @@ struct OmpAtomicRead {
 struct OmpAtomicWrite {
   TUPLE_CLASS_BOILERPLATE(OmpAtomicWrite);
   CharBlock source;
-  std::tuple,
-  std::optional>
+  std::tuple, std::optional>
   t;
 };
 
@@ -3659,8 +3678,8 @@ struct OmpAtomicWrite {
 struct OmpAtomicUpdate {
   TUPLE_CLASS_BOILERPLATE(OmpAtomicUpdate);
   CharBlock source;
-  std::tuple,
-  std::optional>
+  std::tuple, std::optional>
   t;
 };
 
@@ -3670,7 +3689,8 @@ struct OmpAtomicCapture {
   CharBlock source;
   WRAPPER_CLASS(Stmt1, Statement);
   WRAPPER_CLASS(Stmt2, Statement);
-  std::tuple
+  std::tuple
   t;
 };
 
@@ -3678,11 +3698,15 @@ struct OmpAtomicCapture {
 struct OmpAtomic {
   TUPLE_CLASS_BOILERPLATE(OmpAtomic);
   CharBlock source;
-  std::tuple,
+  std::tuple,
   std::optional>
   t;
 };
 
+// 2.17.7 atomic ->
+//ATOMIC [atomic-clause-list] atomic-construct [atomic-clause-list] |
+//ATOMIC [atomic-clause-list]
+//atomic-construct -> READ | WRITE | UPDATE | CAPTURE
 struct OpenMPAtomicConstruct {
   UNION_CLASS_BOILERPLATE(OpenMPAtomicConstruct);
   std::variant> t;
 };
 
-// 2.17.8 Flush Construct [OpenMP 5.0]
-// memory-order-clause -> acq_rel
-//release
-//acquire
-struct OmpMemoryOrderClause {
-  WRAPPER_CLASS_BOILERPLATE(OmpMemoryOrderCl

[llvm-branch-commits] [flang] f1569b1 - [Flang][OpenMP-5.0] Semantic checks for flush construct.

2020-12-14 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2020-12-14T13:30:48+05:30
New Revision: f1569b1ece5516d31d8c748f7b2981a688e32826

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

LOG: [Flang][OpenMP-5.0] Semantic checks for flush construct.

>From OMP 5.0 [2.17.8]
Restriction:
If memory-order-clause is release,acquire, or acq_rel, list items must not be 
specified on the flush directive.

Reviewed By: kiranchandramohan, clementval

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

Added: 
flang/test/Semantics/omp-flush01.f90
flang/test/Semantics/omp-flush02.f90

Modified: 
flang/include/flang/Parser/parse-tree.h
flang/lib/Lower/OpenMP.cpp
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/test/Semantics/omp-clause-validity01.f90
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 5d2909a4142a..27998c308cc0 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3747,7 +3747,7 @@ struct OpenMPCancelConstruct {
 struct OpenMPFlushConstruct {
   TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
   CharBlock source;
-  std::tuple,
+  std::tuple>,
   std::optional>
   t;
 };

diff  --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index cfe4b0b86b67..97946caa68a0 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -109,7 +109,8 @@ genOMP(Fortran::lower::AbstractConverter &converter,
 std::get>(
 flushConstruct.t))
   genObjectList(*ompObjectList, converter, operandRange);
-if (std::get>(
+if (std::get>>(
 flushConstruct.t))
   TODO("Handle OmpMemoryOrderClause");
 converter.getFirOpBuilder().create(

diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index fd209abc4138..67c377e798ca 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -331,7 +331,7 @@ TYPE_PARSER(sourced(construct(
 many(maybe(","_tok) >> sourced(Parser{})
 
 TYPE_PARSER(sourced(construct(verbatim("FLUSH"_tok),
-maybe(Parser{}),
+many(maybe(","_tok) >> sourced(Parser{})),
 maybe(parenthesized(Parser{})
 
 // Simple Standalone Directives

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index c5df6990d102..bd1c1a2c71eb 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2460,7 +2460,7 @@ class UnparseVisitor {
   void Unparse(const OpenMPFlushConstruct &x) {
 BeginOpenMP();
 Word("!$OMP FLUSH ");
-Walk(std::get>(x.t));
+Walk(std::get>>(x.t));
 Walk(" (", std::get>(x.t), ")");
 Put("\n");
 EndOpenMP();

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index e58e2e509fb8..978e1c7962a4 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -226,7 +226,17 @@ void OmpStructureChecker::Enter(const 
parser::OpenMPFlushConstruct &x) {
   PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_flush);
 }
 
-void OmpStructureChecker::Leave(const parser::OpenMPFlushConstruct &) {
+void OmpStructureChecker::Leave(const parser::OpenMPFlushConstruct &x) {
+  if (FindClause(llvm::omp::Clause::OMPC_acquire) ||
+  FindClause(llvm::omp::Clause::OMPC_release) ||
+  FindClause(llvm::omp::Clause::OMPC_acq_rel)) {
+if (const auto &flushList{
+std::get>(x.t)}) {
+  context_.Say(parser::FindSourceLocation(flushList),
+  "If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items "
+  "must not be specified on the FLUSH directive"_err_en_US);
+}
+  }
   dirContext_.pop_back();
 }
 

diff  --git a/flang/test/Semantics/omp-clause-validity01.f90 
b/flang/test/Semantics/omp-clause-validity01.f90
index 601e39021e44..3f5345137866 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -487,6 +487,7 @@
   !$omp flush acq_rel
   !$omp flush release
   !$omp flush acquire
+  !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items 
must not be specified on the FLUSH directive
   !$omp flush release (c)
   !ERROR: SEQ_CST clause is not allowed on the FLUSH directive
   !$omp flush seq_cst

diff  --git a/flang/test/Semantics/omp-flush01.f90 
b/flang/test/Semantics/omp-flush01.f90
new file mode 100644
index ..cca78e7a09cd
--- /dev/null
+++ b/flang/test/Semantics/omp-flush01.f90
@@ -0,0 +1,39 @@
+! RUN: %S/test_errors.sh