[llvm-branch-commits] [mlir] 0bd9a13 - [mlir][openacc] Use TableGen information for default enum
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 12 06:47:18 PST 2021
Author: Valentin Clement
Date: 2021-01-12T09:42:42-05:00
New Revision: 0bd9a1369112f7d0a8a3b94a050fd5ed37037e9b
URL: https://github.com/llvm/llvm-project/commit/0bd9a1369112f7d0a8a3b94a050fd5ed37037e9b
DIFF: https://github.com/llvm/llvm-project/commit/0bd9a1369112f7d0a8a3b94a050fd5ed37037e9b.diff
LOG: [mlir][openacc] Use TableGen information for default enum
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
Added:
mlir/test/mlir-tblgen/directive-common.td
mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
Modified:
llvm/include/llvm/Frontend/OpenACC/ACC.td
mlir/include/mlir/Dialect/OpenACC/CMakeLists.txt
mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
mlir/tools/mlir-tblgen/CMakeLists.txt
Removed:
mlir/test/mlir-tblgen/openmp-common.td
mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp
################################################################################
diff --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index d53d3132c969..58bb73fb6402 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -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";
diff --git a/mlir/include/mlir/Dialect/OpenACC/CMakeLists.txt b/mlir/include/mlir/Dialect/OpenACC/CMakeLists.txt
index 32b92096c71b..32b0c7f902ae 100644
--- a/mlir/include/mlir/Dialect/OpenACC/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/OpenACC/CMakeLists.txt
@@ -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)
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index 6feec888ec8e..a48af00535a7 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -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);
diff --git a/mlir/test/mlir-tblgen/openmp-common.td b/mlir/test/mlir-tblgen/directive-common.td
similarity index 83%
rename from mlir/test/mlir-tblgen/openmp-common.td
rename to mlir/test/mlir-tblgen/directive-common.td
index 579988beda94..96439b40e9e8 100644
--- a/mlir/test/mlir-tblgen/openmp-common.td
+++ b/mlir/test/mlir-tblgen/directive-common.td
@@ -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: }
diff --git a/mlir/tools/mlir-tblgen/CMakeLists.txt b/mlir/tools/mlir-tblgen/CMakeLists.txt
index 119d03573a66..32c0d739b517 100644
--- a/mlir/tools/mlir-tblgen/CMakeLists.txt
+++ b/mlir/tools/mlir-tblgen/CMakeLists.txt
@@ -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
diff --git a/mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp b/mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
similarity index 72%
rename from mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp
rename to mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
index dbe888e6ab59..aaad51794821 100644
--- a/mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp
+++ b/mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
@@ -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);
+ });
More information about the llvm-branch-commits
mailing list