[flang-commits] [flang] 9902229 - [flang][openacc] Fix ambiguity in the self clause parsing

via flang-commits flang-commits at lists.llvm.org
Tue Oct 27 18:10:09 PDT 2020


Author: Valentin Clement
Date: 2020-10-27T21:10:00-04:00
New Revision: 990222931ba2c87803f8b0381a2088b0e2969848

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

LOG: [flang][openacc] Fix ambiguity in the self clause parsing

In the OpenACC specification, there are two different self clause. One for the
update directive with a var-list argument. This clause is a synonym of the host clause.
The second self clause is present for most of the compute construct and takes an optional
condition. To solve this ambiguity, the self clause for the update directive is directly
translated to a host clause during the parsing. The self clause in AccClause refers always
to the compute construct clause.

Reviewed By: kiranktp

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

Added: 
    

Modified: 
    flang/lib/Parser/openacc-parsers.cpp
    flang/test/Semantics/acc-clause-validity.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp
index 546f4e972eaa..510b80277138 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -98,8 +98,13 @@ TYPE_PARSER("AUTO" >> construct<AccClause>(construct<AccClause::Auto>()) ||
                        parenthesized(construct<AccObjectListWithReduction>(
                            Parser<AccReductionOperator>{} / ":",
                            Parser<AccObjectList>{})))) ||
+    // SELF clause is either a simple optional condition for compute construct
+    // or a synonym of the HOST clause for the update directive 2.14.4 holding
+    // an object list.
     "SELF" >> construct<AccClause>(construct<AccClause::Self>(
                   maybe(parenthesized(scalarLogicalExpr)))) ||
+    construct<AccClause>(
+        construct<AccClause::Host>(parenthesized(Parser<AccObjectList>{}))) ||
     "SEQ" >> construct<AccClause>(construct<AccClause::Seq>()) ||
     "TILE" >> construct<AccClause>(construct<AccClause::Tile>(
                   parenthesized(Parser<AccTileExprList>{}))) ||

diff  --git a/flang/test/Semantics/acc-clause-validity.f90 b/flang/test/Semantics/acc-clause-validity.f90
index 56910c2678f1..188d41f6e2a4 100644
--- a/flang/test/Semantics/acc-clause-validity.f90
+++ b/flang/test/Semantics/acc-clause-validity.f90
@@ -31,7 +31,7 @@ program openacc_clause_validity
 
   !ERROR: At least one clause is required on the DECLARE directive
   !$acc declare
-  real(8), dimension(N) :: a
+  real(8), dimension(N) :: a, f, g, h
 
   !$acc init
   !$acc init if(.TRUE.)
@@ -83,6 +83,8 @@ program openacc_clause_validity
   !ERROR: Unmatched PARALLEL directive
   !$acc end parallel
 
+  !$acc update self(a, f) host(g) device(h)
+
   !$acc update device(i) device_type(*) async
 
   !ERROR: Clause IF is not allowed after clause DEVICE_TYPE on the UPDATE directive
@@ -108,6 +110,21 @@ program openacc_clause_validity
     a(i) = 3.14
   end do
 
+  !$acc parallel loop self
+  do i = 1, N
+    a(i) = 3.14
+  end do
+
+  !$acc parallel loop self(.true.)
+  do i = 1, N
+    a(i) = 3.14
+  end do
+
+  !$acc parallel loop self(ifCondition)
+  do i = 1, N
+    a(i) = 3.14
+  end do
+
   !$acc parallel loop tile(2, 2)
   do i = 1, N
     do j = 1, N


        


More information about the flang-commits mailing list