[flang-commits] [flang] 2f40e20 - [flang][openacc] Fix device_num and device_type clauses for init directive

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


Author: Valentin Clement
Date: 2020-10-06T21:27:01-04:00
New Revision: 2f40e20613758b3e11a15494c09f4b6973673d6b

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

LOG: [flang][openacc] Fix device_num and device_type clauses for init directive

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp
index 01c258325f2c..686259b75651 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -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>{}))) ||

diff  --git a/flang/test/Semantics/acc-clause-validity.f90 b/flang/test/Semantics/acc-clause-validity.f90
index 9683a4e02c74..9a7bfe97185b 100644
--- a/flang/test/Semantics/acc-clause-validity.f90
+++ b/flang/test/Semantics/acc-clause-validity.f90
@@ -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
 

diff  --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index b15f8348c8f4..879bbc21b940 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -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;


        


More information about the flang-commits mailing list