Skip to content

Commit fc544dc

Browse files
[NFC][MLIR][OpenMP] Add comments and test for OpenMP enum declaration utility
Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D85857
1 parent 62ef1cb commit fc544dc

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: mlir-tblgen -gen-directive-decl -I %S/../../../llvm/include %s | FileCheck -match-full-lines %s
2+
3+
include "llvm/Frontend/Directive/DirectiveBase.td"
4+
5+
def TDLCV_vala : ClauseVal<"vala",1,1> {}
6+
def TDLCV_valb : ClauseVal<"valb",2,1> {}
7+
def TDLCV_valc : ClauseVal<"valc",3,0> { let isDefault = 1; }
8+
9+
def TDLC_ClauseA : Clause<"clausea"> {
10+
let flangClass = "TdlClauseA";
11+
let enumClauseValue = "AKind";
12+
let allowedClauseValues = [
13+
TDLCV_vala,
14+
TDLCV_valb,
15+
TDLCV_valc
16+
];
17+
}
18+
19+
// CHECK: def AKindvala : StrEnumAttrCase<"vala">;
20+
// CHECK: def AKindvalb : StrEnumAttrCase<"valb">;
21+
// CHECK: def AKind: StrEnumAttr<
22+
// CHECK: "ClauseAKind",
23+
// CHECK: "AKind Clause",
24+
// CHECK: [AKindvala,AKindvalb]> {
25+
// CHECK: let cppNamespace = "::mlir::omp";
26+
// CHECK: }

mlir/tools/mlir-tblgen/OpenMPCommonGen.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ using llvm::raw_ostream;
2424
using llvm::RecordKeeper;
2525
using llvm::Twine;
2626

27+
// LLVM has multiple places (Clang, Flang, MLIR) where information about
28+
// the OpenMP directives, and clauses are needed. It is good software
29+
// engineering to keep the common information in a single place to avoid
30+
// duplication, reduce engineering effort and prevent mistakes.
31+
// Currently that common place is llvm/include/llvm/Frontend/OpenMP/OMP.td.
32+
// We plan to use this tablegen source to generate all the required
33+
// declarations, functions etc.
34+
//
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
38+
// name of the enumeration is specified in the enumClauseValue field of
39+
// Clause record in OMP.td. This name can be used to specify the type of the
40+
// OpenMP operation's operand. The allowedClauseValues field provides the list
41+
// of ClauseValues which are part of the enumeration.
2742
static bool emitDecls(const RecordKeeper &recordKeeper, raw_ostream &os) {
2843
const auto &clauses = recordKeeper.getAllDerivedDefinitions("Clause");
2944

0 commit comments

Comments
 (0)