diff --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td --- a/llvm/include/llvm/Frontend/OpenACC/ACC.td +++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td @@ -80,8 +80,8 @@ } // 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 --- 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.cpp.inc -gen-enum-defs) add_mlir_doc(OpenACCOps -gen-dialect-doc OpenACCDialect Dialects/) add_public_tablegen_target(MLIROpenACCOpsIncGen) - +add_dependencies(MLIROpenACCOpsIncGen acc_common_td) diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td --- 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 @@ // 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 @@ Variadic:$attachOperands, Variadic:$gangPrivateOperands, Variadic:$gangFirstPrivateOperands, - OptionalAttr:$defaultAttr); + OptionalAttr:$defaultAttr); let regions = (region AnyRegion:$region); @@ -190,7 +182,7 @@ Variadic:$presentOperands, Variadic:$deviceptrOperands, Variadic:$attachOperands, - OptionalAttr:$defaultAttr); + OptionalAttr:$defaultAttr); let regions = (region AnyRegion:$region); diff --git a/mlir/test/mlir-tblgen/openmp-common.td b/mlir/test/mlir-tblgen/directive-common.td rename from mlir/test/mlir-tblgen/openmp-common.td rename to mlir/test/mlir-tblgen/directive-common.td --- 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 @@ // 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 --- a/mlir/tools/mlir-tblgen/CMakeLists.txt +++ b/mlir/tools/mlir-tblgen/CMakeLists.txt @@ -6,6 +6,7 @@ add_tablegen(mlir-tblgen MLIR DialectGen.cpp + DirectiveCommonGen.cpp EnumsGen.cpp LLVMIRConversionGen.cpp LLVMIRIntrinsicGen.cpp @@ -15,7 +16,6 @@ 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 rename from mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp rename to mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp --- 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::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 @@ 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); + });