Skip to content

Commit 0bd9a13

Browse files
committed
[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
1 parent a675947 commit 0bd9a13

File tree

6 files changed

+36
-29
lines changed

6 files changed

+36
-29
lines changed

llvm/include/llvm/Frontend/OpenACC/ACC.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def ACCC_Create : Clause<"create"> {
8080
}
8181

8282
// 2.5.15
83-
def ACC_Default_none : ClauseVal<"none", 1, 0> { let isDefault = 1; }
84-
def ACC_Default_present : ClauseVal<"present", 0, 0> {}
83+
def ACC_Default_none : ClauseVal<"none", 1, 1> { let isDefault = 1; }
84+
def ACC_Default_present : ClauseVal<"present", 0, 1> {}
8585

8686
def ACCC_Default : Clause<"default"> {
8787
let flangClassValue = "AccDefaultClause";
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/OpenACC/ACC.td)
2+
mlir_tablegen(AccCommon.td --gen-directive-decl)
3+
add_public_tablegen_target(acc_common_td)
4+
15
set(LLVM_TARGET_DEFINITIONS OpenACCOps.td)
26
mlir_tablegen(OpenACCOpsDialect.h.inc -gen-dialect-decls -dialect=acc)
37
mlir_tablegen(OpenACCOps.h.inc -gen-op-decls)
@@ -6,4 +10,4 @@ mlir_tablegen(OpenACCOpsEnums.h.inc -gen-enum-decls)
610
mlir_tablegen(OpenACCOpsEnums.cpp.inc -gen-enum-defs)
711
add_mlir_doc(OpenACCOps -gen-dialect-doc OpenACCDialect Dialects/)
812
add_public_tablegen_target(MLIROpenACCOpsIncGen)
9-
13+
add_dependencies(OpenACCDialectDocGen acc_common_td)

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define OPENACC_OPS
1515

1616
include "mlir/IR/OpBase.td"
17+
include "mlir/Dialect/OpenACC/AccCommon.td"
1718

1819
def OpenACC_Dialect : Dialect {
1920
let name = "acc";
@@ -63,15 +64,6 @@ def OpenACC_ReductionOpAttr : StrEnumAttr<"ReductionOpAttr",
6364
// Type used in operation below.
6465
def IntOrIndex : AnyTypeOf<[AnyInteger, Index]>;
6566

66-
// Parallel and data op default enumeration
67-
def OpenACC_DefaultNone : StrEnumAttrCase<"none">;
68-
def OpenACC_DefaultPresent : StrEnumAttrCase<"present">;
69-
def OpenACC_DefaultAttr : StrEnumAttr<"DefaultAttr",
70-
"default attribute values",
71-
[OpenACC_DefaultNone, OpenACC_DefaultPresent]> {
72-
let cppNamespace = "::mlir::acc";
73-
}
74-
7567
//===----------------------------------------------------------------------===//
7668
// 2.5.1 parallel Construct
7769
//===----------------------------------------------------------------------===//
@@ -118,7 +110,7 @@ def OpenACC_ParallelOp : OpenACC_Op<"parallel",
118110
Variadic<AnyType>:$attachOperands,
119111
Variadic<AnyType>:$gangPrivateOperands,
120112
Variadic<AnyType>:$gangFirstPrivateOperands,
121-
OptionalAttr<OpenACC_DefaultAttr>:$defaultAttr);
113+
OptionalAttr<DefaultValue>:$defaultAttr);
122114

123115
let regions = (region AnyRegion:$region);
124116

@@ -190,7 +182,7 @@ def OpenACC_DataOp : OpenACC_Op<"data",
190182
Variadic<AnyType>:$presentOperands,
191183
Variadic<AnyType>:$deviceptrOperands,
192184
Variadic<AnyType>:$attachOperands,
193-
OptionalAttr<OpenACC_DefaultAttr>:$defaultAttr);
185+
OptionalAttr<DefaultValue>:$defaultAttr);
194186

195187
let regions = (region AnyRegion:$region);
196188

mlir/test/mlir-tblgen/openmp-common.td renamed to mlir/test/mlir-tblgen/directive-common.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
include "llvm/Frontend/Directive/DirectiveBase.td"
44

5+
def TestDirectiveLanguage : DirectiveLanguage {
6+
let name = "Tdl";
7+
let cppNamespace = "tdl";
8+
}
9+
510
def TDLCV_vala : ClauseVal<"vala",1,1> {}
611
def TDLCV_valb : ClauseVal<"valb",2,1> {}
712
def TDLCV_valc : ClauseVal<"valc",3,0> { let isDefault = 1; }
@@ -22,5 +27,5 @@ def TDLC_ClauseA : Clause<"clausea"> {
2227
// CHECK: "ClauseAKind",
2328
// CHECK: "AKind Clause",
2429
// CHECK: [AKindvala,AKindvalb]> {
25-
// CHECK: let cppNamespace = "::mlir::omp";
30+
// CHECK: let cppNamespace = "::mlir::tdl";
2631
// CHECK: }

mlir/tools/mlir-tblgen/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
66

77
add_tablegen(mlir-tblgen MLIR
88
DialectGen.cpp
9+
DirectiveCommonGen.cpp
910
EnumsGen.cpp
1011
LLVMIRConversionGen.cpp
1112
LLVMIRIntrinsicGen.cpp
@@ -15,7 +16,6 @@ add_tablegen(mlir-tblgen MLIR
1516
OpFormatGen.cpp
1617
OpInterfacesGen.cpp
1718
OpPythonBindingGen.cpp
18-
OpenMPCommonGen.cpp
1919
PassCAPIGen.cpp
2020
PassDocGen.cpp
2121
PassGen.cpp

mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp renamed to mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===========- OpenMPCommonGen.cpp - OpenMP common info generator -===========//
1+
//===========- DirectiveCommonGen.cpp - Directive common info generator -=====//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -25,21 +25,26 @@ using llvm::RecordKeeper;
2525
using llvm::Twine;
2626

2727
// LLVM has multiple places (Clang, Flang, MLIR) where information about
28-
// the OpenMP directives, and clauses are needed. It is good software
28+
// the directives (OpenMP/OpenACC), and clauses are needed. It is good software
2929
// engineering to keep the common information in a single place to avoid
3030
// duplication, reduce engineering effort and prevent mistakes.
31-
// Currently that common place is llvm/include/llvm/Frontend/OpenMP/OMP.td.
31+
// Currently that common place is llvm/include/llvm/Frontend/OpenMP/OMP.td for
32+
// OpenMP and llvm/include/llvm/Frontend/OpenACC/ACC.td for OpenACC.
3233
// We plan to use this tablegen source to generate all the required
3334
// declarations, functions etc.
3435
//
35-
// Some OpenMP clauses accept only a fixed set of values as inputs. These
36-
// can be represented as a String Enum Attribute (StrEnumAttr) in MLIR ODS.
37-
// The emitDecls function below currently generates these enumerations. The
36+
// Some OpenMP/OpenACC clauses accept only a fixed set of values as inputs.
37+
// These can be represented as a String Enum Attribute (StrEnumAttr) in MLIR
38+
// ODS. The emitDecls function below currently generates these enumerations. The
3839
// name of the enumeration is specified in the enumClauseValue field of
3940
// Clause record in OMP.td. This name can be used to specify the type of the
4041
// OpenMP operation's operand. The allowedClauseValues field provides the list
4142
// of ClauseValues which are part of the enumeration.
4243
static bool emitDecls(const RecordKeeper &recordKeeper, raw_ostream &os) {
44+
const auto &directiveLanguages =
45+
recordKeeper.getAllDerivedDefinitions("DirectiveLanguage");
46+
assert(directiveLanguages.size() != 0 && "DirectiveLanguage missing.");
47+
4348
const auto &clauses = recordKeeper.getAllDerivedDefinitions("Clause");
4449

4550
for (const auto &r : clauses) {
@@ -73,16 +78,17 @@ static bool emitDecls(const RecordKeeper &recordKeeper, raw_ostream &os) {
7378
os << ",";
7479
}
7580
os << "]> {\n";
76-
os << " let cppNamespace = \"::mlir::omp\";\n";
81+
os << " let cppNamespace = \"::mlir::"
82+
<< directiveLanguages[0]->getValueAsString("cppNamespace") << "\";\n";
7783
os << "}\n";
7884
}
7985
return false;
8086
}
8187

8288
// Registers the generator to mlir-tblgen.
83-
static mlir::GenRegistration
84-
genDirectiveDecls("gen-directive-decl",
85-
"Generate declarations for directives (OpenMP etc.)",
86-
[](const RecordKeeper &records, raw_ostream &os) {
87-
return emitDecls(records, os);
88-
});
89+
static mlir::GenRegistration genDirectiveDecls(
90+
"gen-directive-decl",
91+
"Generate declarations for directives (OpenMP/OpenACC etc.)",
92+
[](const RecordKeeper &records, raw_ostream &os) {
93+
return emitDecls(records, os);
94+
});

0 commit comments

Comments
 (0)