[flang][openacc] Fix device_num and device_type clauses for init directive
authorValentin Clement <clementval@gmail.com>
Wed, 7 Oct 2020 01:26:13 +0000 (21:26 -0400)
committerclementval <clementval@gmail.com>
Wed, 7 Oct 2020 01:27:01 +0000 (21:27 -0400)
This patch fix the device_num and device_type clauses used in the init clause. device_num was not
spelled correctly in the parser and was to restrictive with scalarIntConstantExpr instead of scalarIntExpr.
device_type is now taking a list of ScalarIntExpr.

Reviewed By: kiranchandramohan

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

flang/lib/Parser/openacc-parsers.cpp
flang/test/Semantics/acc-clause-validity.f90
llvm/include/llvm/Frontend/OpenACC/ACC.td

index 01c2583..686259b 100644 (file)
@@ -57,17 +57,17 @@ TYPE_PARSER("AUTO" >> construct<AccClause>(construct<AccClause::Auto>()) ||
                     parenthesized(Parser<AccObjectList>{}))) ||
     "DEVICEPTR" >> construct<AccClause>(construct<AccClause::Deviceptr>(
                        parenthesized(Parser<AccObjectList>{}))) ||
-    "DEVICENUM" >> construct<AccClause>(construct<AccClause::DeviceNum>(
-                       parenthesized(scalarIntConstantExpr))) ||
+    "DEVICE_NUM" >> construct<AccClause>(construct<AccClause::DeviceNum>(
+                        parenthesized(scalarIntExpr))) ||
     "DEVICE_RESIDENT" >>
         construct<AccClause>(construct<AccClause::DeviceResident>(
             parenthesized(Parser<AccObjectList>{}))) ||
     ("DEVICE_TYPE"_tok || "DTYPE"_tok) >>
         construct<AccClause>(construct<AccClause::DeviceType>(parenthesized(
-            "*" >> construct<std::optional<std::list<Name>>>()))) ||
+            "*" >> construct<std::optional<std::list<ScalarIntExpr>>>()))) ||
     ("DEVICE_TYPE"_tok || "DTYPE"_tok) >>
         construct<AccClause>(construct<AccClause::DeviceType>(
-            parenthesized(maybe(nonemptyList(name))))) ||
+            parenthesized(maybe(nonemptyList(scalarIntExpr))))) ||
     "FINALIZE" >> construct<AccClause>(construct<AccClause::Finalize>()) ||
     "FIRSTPRIVATE" >> construct<AccClause>(construct<AccClause::Firstprivate>(
                           parenthesized(Parser<AccObjectList>{}))) ||
index 9683a4e..9a7bfe9 100644 (file)
@@ -25,11 +25,21 @@ program openacc_clause_validity
   real :: reduction_r
   logical :: reduction_l
   real(8), dimension(N, N) :: aa
+  logical :: ifCondition = .TRUE.
 
   !ERROR: At least one clause is required on the DECLARE directive
   !$acc declare
   real(8), dimension(N) :: a
 
+  !$acc init
+  !$acc init if(.TRUE.)
+  !$acc init if(ifCondition)
+  !$acc init device_num(1)
+  !$acc init device_num(i)
+  !$acc init device_type(i)
+  !$acc init device_type(2, i, j)
+  !$acc init device_num(i) device_type(i, j) if(ifCondition)
+
   !ERROR: At least one of ATTACH, COPYIN, CREATE clause must appear on the ENTER DATA directive
   !$acc enter data
 
index b15f834..879bbc2 100644 (file)
@@ -106,7 +106,7 @@ def ACCC_Device : Clause<"device"> {
 
 // 2.14.1
 def ACCC_DeviceNum : Clause<"device_num">  {
-  let flangClassValue = "ScalarIntConstantExpr";
+  let flangClassValue = "ScalarIntExpr";
 }
 
 // 2.7.3
@@ -121,7 +121,7 @@ def ACCC_DeviceResident : Clause<"device_resident"> {
 
 // 2.4
 def ACCC_DeviceType : Clause<"device_type"> {
-  let flangClassValue = "Name";
+  let flangClassValue = "ScalarIntExpr";
   let defaultValue = "*";
   let isValueOptional = 1;
   let isValueList = 1;