[Mlir-commits] [mlir] fc544dc - [NFC][MLIR][OpenMP] Add comments and test for OpenMP enum declaration utility

Kiran Chandramohan llvmlistbot at llvm.org
Wed Aug 12 15:26:32 PDT 2020


Author: Kiran Chandramohan
Date: 2020-08-14T23:22:23+01:00
New Revision: fc544dcf2daa378c74ea6dd4c86ed5478e7b48c5

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

LOG: [NFC][MLIR][OpenMP] Add comments and test for OpenMP enum declaration utility

Reviewed By: mehdi_amini

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

Added: 
    mlir/test/mlir-tblgen/openmp-common.td

Modified: 
    mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/mlir-tblgen/openmp-common.td b/mlir/test/mlir-tblgen/openmp-common.td
new file mode 100644
index 000000000000..579988beda94
--- /dev/null
+++ b/mlir/test/mlir-tblgen/openmp-common.td
@@ -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: }

diff  --git a/mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp b/mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp
index 689953587a24..dbe888e6ab59 100644
--- a/mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp
@@ -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");
 


        


More information about the Mlir-commits mailing list