[PATCH] D143671: [Flang][OpenMP] Added parser support for device_type clause

Akash Banerjee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 9 11:32:59 PST 2023


TIFitis created this revision.
TIFitis added reviewers: skatrak, kiranchandramohan, clementval.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a reviewer: sscalpone.
Herald added projects: Flang, All.
TIFitis requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, sstefan1, jdoerfert.
Herald added a project: LLVM.

This patch adds parser suppert for the device_type clause used by the Declare Target directive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143671

Files:
  flang/include/flang/Parser/dump-parse-tree.h
  flang/include/flang/Parser/parse-tree.h
  flang/lib/Parser/openmp-parsers.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td


Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===================================================================
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -222,6 +222,9 @@
   let clangClass = "OMPDeviceClause";
   let flangClass = "OmpDeviceClause";
 }
+def OMPC_DeviceType : Clause<"device_type"> {
+  let flangClass = "OmpDeviceTypeClause";
+}
 def OMPC_Threads : Clause<"threads"> { let clangClass = "OMPThreadsClause"; }
 def OMPC_Simd : Clause<"simd"> { let clangClass = "OMPSIMDClause"; }
 def OMPC_Map : Clause<"map"> {
@@ -397,7 +400,6 @@
   let flangClass = "Name";
   let isValueList = true;
 }
-def OMPC_DeviceType : Clause<"device_type"> {}
 def OMPC_Match : Clause<"match"> {}
 def OMPC_AdjustArgs : Clause<"adjust_args"> { }
 def OMPC_AppendArgs : Clause<"append_args"> { }
@@ -1095,6 +1097,9 @@
     VersionedClause<OMPC_Link>,
     VersionedClause<OMPC_Indirect>
   ];
+  let allowedOnceClauses = [
+    VersionedClause<OMPC_DeviceType>
+  ];
 }
 def OMP_EndDeclareTarget : Directive<"end declare target"> {}
 def OMP_DistributeParallelFor : Directive<"distribute parallel for"> {
Index: flang/lib/Parser/openmp-parsers.cpp
===================================================================
--- flang/lib/Parser/openmp-parsers.cpp
+++ flang/lib/Parser/openmp-parsers.cpp
@@ -105,6 +105,12 @@
         ":"),
     scalarIntExpr))
 
+// device_type(any | host | nohost)
+TYPE_PARSER(construct<OmpDeviceTypeClause>(
+    "ANY" >> pure(OmpDeviceTypeClause::Type::Any) ||
+    "HOST" >> pure(OmpDeviceTypeClause::Type::Host) ||
+    "NOHOST" >> pure(OmpDeviceTypeClause::Type::Nohost)))
+
 // 2.12 IF (directive-name-modifier: scalar-logical-expr)
 TYPE_PARSER(construct<OmpIfClause>(
     maybe(
@@ -208,6 +214,8 @@
                     parenthesized(Parser<OmpDependClause>{}))) ||
     "DEVICE" >> construct<OmpClause>(construct<OmpClause::Device>(
                     parenthesized(Parser<OmpDeviceClause>{}))) ||
+    "DEVICE_TYPE" >> construct<OmpClause>(construct<OmpClause::DeviceType>(
+                         parenthesized(Parser<OmpDeviceTypeClause>{}))) ||
     "DIST_SCHEDULE" >>
         construct<OmpClause>(construct<OmpClause::DistSchedule>(
             parenthesized("STATIC" >> maybe("," >> scalarIntExpr)))) ||
Index: flang/include/flang/Parser/parse-tree.h
===================================================================
--- flang/include/flang/Parser/parse-tree.h
+++ flang/include/flang/Parser/parse-tree.h
@@ -3396,6 +3396,12 @@
   std::tuple<std::optional<DeviceModifier>, ScalarIntExpr> t;
 };
 
+// device_type(any | host | nohost)
+struct OmpDeviceTypeClause {
+  ENUM_CLASS(Type, Any, Host, Nohost)
+  WRAPPER_CLASS_BOILERPLATE(OmpDeviceTypeClause, Type);
+};
+
 // 2.12 if-clause -> IF ([ directive-name-modifier :] scalar-logical-expr)
 struct OmpIfClause {
   TUPLE_CLASS_BOILERPLATE(OmpIfClause);
Index: flang/include/flang/Parser/dump-parse-tree.h
===================================================================
--- flang/include/flang/Parser/dump-parse-tree.h
+++ flang/include/flang/Parser/dump-parse-tree.h
@@ -528,6 +528,8 @@
   NODE_ENUM(OmpScheduleClause, ScheduleType)
   NODE(parser, OmpDeviceClause)
   NODE_ENUM(OmpDeviceClause, DeviceModifier)
+  NODE(parser, OmpDeviceTypeClause)
+  NODE_ENUM(OmpDeviceTypeClause, Type)
   NODE(parser, OmpScheduleModifier)
   NODE(OmpScheduleModifier, Modifier1)
   NODE(OmpScheduleModifier, Modifier2)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143671.496196.patch
Type: text/x-patch
Size: 3460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230209/e005c51c/attachment.bin>


More information about the llvm-commits mailing list