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
}
// 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";
+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)
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)
#define OPENACC_OPS
include "mlir/IR/OpBase.td"
+include "mlir/Dialect/OpenACC/AccCommon.td"
def OpenACC_Dialect : Dialect {
let name = "acc";
// 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
//===----------------------------------------------------------------------===//
Variadic<AnyType>:$attachOperands,
Variadic<AnyType>:$gangPrivateOperands,
Variadic<AnyType>:$gangFirstPrivateOperands,
- OptionalAttr<OpenACC_DefaultAttr>:$defaultAttr);
+ OptionalAttr<DefaultValue>:$defaultAttr);
let regions = (region AnyRegion:$region);
Variadic<AnyType>:$presentOperands,
Variadic<AnyType>:$deviceptrOperands,
Variadic<AnyType>:$attachOperands,
- OptionalAttr<OpenACC_DefaultAttr>:$defaultAttr);
+ OptionalAttr<DefaultValue>:$defaultAttr);
let regions = (region AnyRegion:$region);
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; }
// CHECK: "ClauseAKind",
// CHECK: "AKind Clause",
// CHECK: [AKindvala,AKindvalb]> {
-// CHECK: let cppNamespace = "::mlir::omp";
+// CHECK: let cppNamespace = "::mlir::tdl";
// CHECK: }
add_tablegen(mlir-tblgen MLIR
DialectGen.cpp
+ DirectiveCommonGen.cpp
EnumsGen.cpp
LLVMIRConversionGen.cpp
LLVMIRIntrinsicGen.cpp
OpFormatGen.cpp
OpInterfacesGen.cpp
OpPythonBindingGen.cpp
- OpenMPCommonGen.cpp
PassCAPIGen.cpp
PassDocGen.cpp
PassGen.cpp
-//===========- 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.
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) {
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);
+ });