OSDN Git Service

[mlir][openacc] Use TableGen information for default enum
authorValentin Clement <clementval@gmail.com>
Tue, 12 Jan 2021 14:42:25 +0000 (09:42 -0500)
committerclementval <clementval@gmail.com>
Tue, 12 Jan 2021 14:42:42 +0000 (09:42 -0500)
Use TableGen and information in ACC.td for the Default enum in the OpenACC dialect.
This patch generalize what was done for OpenMP for directives.

Follow up patch after D93576

Reviewed By: kiranchandramohan

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

llvm/include/llvm/Frontend/OpenACC/ACC.td
mlir/include/mlir/Dialect/OpenACC/CMakeLists.txt
mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
mlir/test/mlir-tblgen/directive-common.td [moved from mlir/test/mlir-tblgen/openmp-common.td with 83% similarity]
mlir/tools/mlir-tblgen/CMakeLists.txt
mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp [moved from mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp with 72% similarity]

index d53d313..58bb73f 100644 (file)
@@ -80,8 +80,8 @@ def ACCC_Create : Clause<"create"> {
 }
 
 // 2.5.15
-def ACC_Default_none : ClauseVal<"none", 1, 0> { let isDefault = 1; }
-def ACC_Default_present : ClauseVal<"present", 0, 0> {}
+def ACC_Default_none : ClauseVal<"none", 1, 1> { let isDefault = 1; }
+def ACC_Default_present : ClauseVal<"present", 0, 1> {}
 
 def ACCC_Default : Clause<"default"> {
   let flangClassValue = "AccDefaultClause";
index 32b9209..32b0c7f 100644 (file)
@@ -1,3 +1,7 @@
+set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/OpenACC/ACC.td)
+mlir_tablegen(AccCommon.td --gen-directive-decl)
+add_public_tablegen_target(acc_common_td)
+
 set(LLVM_TARGET_DEFINITIONS OpenACCOps.td)
 mlir_tablegen(OpenACCOpsDialect.h.inc -gen-dialect-decls -dialect=acc)
 mlir_tablegen(OpenACCOps.h.inc -gen-op-decls)
@@ -6,4 +10,4 @@ mlir_tablegen(OpenACCOpsEnums.h.inc -gen-enum-decls)
 mlir_tablegen(OpenACCOpsEnums.cpp.inc -gen-enum-defs)
 add_mlir_doc(OpenACCOps -gen-dialect-doc OpenACCDialect Dialects/)
 add_public_tablegen_target(MLIROpenACCOpsIncGen)
-
+add_dependencies(OpenACCDialectDocGen acc_common_td)
index 6feec88..a48af00 100644 (file)
@@ -14,6 +14,7 @@
 #define OPENACC_OPS
 
 include "mlir/IR/OpBase.td"
+include "mlir/Dialect/OpenACC/AccCommon.td"
 
 def OpenACC_Dialect : Dialect {
   let name = "acc";
@@ -63,15 +64,6 @@ def OpenACC_ReductionOpAttr : StrEnumAttr<"ReductionOpAttr",
 // Type used in operation below.
 def IntOrIndex : AnyTypeOf<[AnyInteger, Index]>;
 
-// Parallel and data op default enumeration
-def OpenACC_DefaultNone : StrEnumAttrCase<"none">;
-def OpenACC_DefaultPresent : StrEnumAttrCase<"present">;
-def OpenACC_DefaultAttr : StrEnumAttr<"DefaultAttr",
-    "default attribute values",
-    [OpenACC_DefaultNone, OpenACC_DefaultPresent]> {
-  let cppNamespace = "::mlir::acc";
-}
-
 //===----------------------------------------------------------------------===//
 // 2.5.1 parallel Construct
 //===----------------------------------------------------------------------===//
@@ -118,7 +110,7 @@ def OpenACC_ParallelOp : OpenACC_Op<"parallel",
                        Variadic<AnyType>:$attachOperands,
                        Variadic<AnyType>:$gangPrivateOperands,
                        Variadic<AnyType>:$gangFirstPrivateOperands,
-                       OptionalAttr<OpenACC_DefaultAttr>:$defaultAttr);
+                       OptionalAttr<DefaultValue>:$defaultAttr);
 
   let regions = (region AnyRegion:$region);
 
@@ -190,7 +182,7 @@ def OpenACC_DataOp : OpenACC_Op<"data",
                        Variadic<AnyType>:$presentOperands,
                        Variadic<AnyType>:$deviceptrOperands,
                        Variadic<AnyType>:$attachOperands,
-                       OptionalAttr<OpenACC_DefaultAttr>:$defaultAttr);
+                       OptionalAttr<DefaultValue>:$defaultAttr);
 
   let regions = (region AnyRegion:$region);
 
similarity index 83%
rename from mlir/test/mlir-tblgen/openmp-common.td
rename to mlir/test/mlir-tblgen/directive-common.td
index 579988b..96439b4 100644 (file)
@@ -2,6 +2,11 @@
 
 include "llvm/Frontend/Directive/DirectiveBase.td"
 
+def TestDirectiveLanguage : DirectiveLanguage {
+  let name = "Tdl";
+  let cppNamespace = "tdl";
+}
+
 def TDLCV_vala : ClauseVal<"vala",1,1> {}
 def TDLCV_valb : ClauseVal<"valb",2,1> {}
 def TDLCV_valc : ClauseVal<"valc",3,0> { let isDefault = 1; }
@@ -22,5 +27,5 @@ def TDLC_ClauseA : Clause<"clausea"> {
 // CHECK:   "ClauseAKind",
 // CHECK:   "AKind Clause",
 // CHECK:   [AKindvala,AKindvalb]> {
-// CHECK:     let cppNamespace = "::mlir::omp";
+// CHECK:     let cppNamespace = "::mlir::tdl";
 // CHECK: }
index 119d035..32c0d73 100644 (file)
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
 
 add_tablegen(mlir-tblgen MLIR
   DialectGen.cpp
+  DirectiveCommonGen.cpp
   EnumsGen.cpp
   LLVMIRConversionGen.cpp
   LLVMIRIntrinsicGen.cpp
@@ -15,7 +16,6 @@ add_tablegen(mlir-tblgen MLIR
   OpFormatGen.cpp
   OpInterfacesGen.cpp
   OpPythonBindingGen.cpp
-  OpenMPCommonGen.cpp
   PassCAPIGen.cpp
   PassDocGen.cpp
   PassGen.cpp
similarity index 72%
rename from mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp
rename to mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
index dbe888e..aaad517 100644 (file)
@@ -1,4 +1,4 @@
-//===========- OpenMPCommonGen.cpp - OpenMP common info generator -===========//
+//===========- DirectiveCommonGen.cpp - Directive common info generator -=====//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -25,21 +25,26 @@ 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
+// the directives (OpenMP/OpenACC), 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.
+// Currently that common place is llvm/include/llvm/Frontend/OpenMP/OMP.td for
+// OpenMP and llvm/include/llvm/Frontend/OpenACC/ACC.td for OpenACC.
 // 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
+// Some OpenMP/OpenACC 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 &directiveLanguages =
+      recordKeeper.getAllDerivedDefinitions("DirectiveLanguage");
+  assert(directiveLanguages.size() != 0 && "DirectiveLanguage missing.");
+
   const auto &clauses = recordKeeper.getAllDerivedDefinitions("Clause");
 
   for (const auto &r : clauses) {
@@ -73,16 +78,17 @@ static bool emitDecls(const RecordKeeper &recordKeeper, raw_ostream &os) {
         os << ",";
     }
     os << "]> {\n";
-    os << "    let cppNamespace = \"::mlir::omp\";\n";
+    os << "    let cppNamespace = \"::mlir::"
+       << directiveLanguages[0]->getValueAsString("cppNamespace") << "\";\n";
     os << "}\n";
   }
   return false;
 }
 
 // Registers the generator to mlir-tblgen.
-static mlir::GenRegistration
-    genDirectiveDecls("gen-directive-decl",
-                      "Generate declarations for directives (OpenMP etc.)",
-                      [](const RecordKeeper &records, raw_ostream &os) {
-                        return emitDecls(records, os);
-                      });
+static mlir::GenRegistration genDirectiveDecls(
+    "gen-directive-decl",
+    "Generate declarations for directives (OpenMP/OpenACC etc.)",
+    [](const RecordKeeper &records, raw_ostream &os) {
+      return emitDecls(records, os);
+    });