[NFC][MLIR][OpenMP] Add comments and test for OpenMP enum declaration utility
authorKiran Chandramohan <kiran.chandramohan@arm.com>
Fri, 14 Aug 2020 21:54:29 +0000 (22:54 +0100)
committerKiran Chandramohan <kiran.chandramohan@arm.com>
Fri, 14 Aug 2020 22:22:23 +0000 (23:22 +0100)
Reviewed By: mehdi_amini

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

mlir/test/mlir-tblgen/openmp-common.td [new file with mode: 0644]
mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp

diff --git a/mlir/test/mlir-tblgen/openmp-common.td b/mlir/test/mlir-tblgen/openmp-common.td
new file mode 100644 (file)
index 0000000..579988b
--- /dev/null
@@ -0,0 +1,26 @@
+// RUN: mlir-tblgen -gen-directive-decl -I %S/../../../llvm/include %s | FileCheck -match-full-lines %s
+
+include "llvm/Frontend/Directive/DirectiveBase.td"
+
+def TDLCV_vala : ClauseVal<"vala",1,1> {}
+def TDLCV_valb : ClauseVal<"valb",2,1> {}
+def TDLCV_valc : ClauseVal<"valc",3,0> { let isDefault = 1; }
+
+def TDLC_ClauseA : Clause<"clausea"> {
+  let flangClass = "TdlClauseA";
+  let enumClauseValue = "AKind";
+  let allowedClauseValues = [
+    TDLCV_vala,
+    TDLCV_valb,
+    TDLCV_valc
+  ];
+}
+
+// CHECK: def AKindvala : StrEnumAttrCase<"vala">;
+// CHECK: def AKindvalb : StrEnumAttrCase<"valb">;
+// CHECK: def AKind: StrEnumAttr<
+// CHECK:   "ClauseAKind",
+// CHECK:   "AKind Clause",
+// CHECK:   [AKindvala,AKindvalb]> {
+// CHECK:     let cppNamespace = "::mlir::omp";
+// CHECK: }
index 6899535..dbe888e 100644 (file)
@@ -24,6 +24,21 @@ using llvm::raw_ostream;
 using llvm::RecordKeeper;
 using llvm::Twine;
 
+// LLVM has multiple places (Clang, Flang, MLIR) where information about
+// the OpenMP directives, and clauses are needed. It is good software
+// engineering to keep the common information in a single place to avoid
+// duplication, reduce engineering effort and prevent mistakes.
+// Currently that common place is llvm/include/llvm/Frontend/OpenMP/OMP.td.
+// We plan to use this tablegen source to generate all the required
+// declarations, functions etc.
+//
+// Some OpenMP clauses accept only a fixed set of values as inputs. These
+// can be represented as a String Enum Attribute (StrEnumAttr) in MLIR ODS.
+// The emitDecls function below currently generates these enumerations. The
+// name of the enumeration is specified in the enumClauseValue field of
+// Clause record in OMP.td. This name can be used to specify the type of the
+// OpenMP operation's operand. The allowedClauseValues field provides the list
+// of ClauseValues which are part of the enumeration.
 static bool emitDecls(const RecordKeeper &recordKeeper, raw_ostream &os) {
   const auto &clauses = recordKeeper.getAllDerivedDefinitions("Clause");