-
Notifications
You must be signed in to change notification settings - Fork 4
IRDL-to-C++ #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IRDL-to-C++ #15
Changes from 72 commits
a2ce564
05494f3
523d6c3
c47260e
d0acddb
1a4d588
e9304cb
d659648
34e63be
0635ef8
720014f
b79a624
8268794
2b64b15
5d76555
3a84a4e
73b8330
689342d
695d725
8d30c73
835bba9
c0e7a59
6979ab2
9c62446
6464238
02ed6d8
3280596
044929d
782c066
05674b2
cc78177
3d02834
61d5fdf
f1cf168
be50ada
f4e14bf
62cae9c
6bb05ea
34deb76
a4380fe
2e12bad
4f844e7
8f1d1dd
86d1d4e
a58e2d1
bb7e559
5c3a997
69d6c1f
0967a6f
127cc84
896ea58
6e574a4
bae8e1f
b6c9c76
435a542
8c1f018
0240129
319feac
6db8490
6179131
989aadf
d4f0f43
5530474
0f1277d
0fa3ba7
760bf4f
123bf5f
16fdb4f
6e98c8c
23a341e
683dcb8
eb37abe
189d5da
fd1c4c3
6bd3543
50304b0
34813d9
23d4756
a21fb74
53d7b1d
5ff1752
7239841
3c9812e
bbca78f
1bdec97
204eb70
52c2e45
3f15b66
7dc7c15
51a03ed
7549f42
cd7104e
9502d1b
a2f72ed
8e31e71
fe09550
3e3b02f
9d10305
7c093ed
710ef17
21cbc8a
d045eb1
01cb390
0cf3c43
6087854
396278e
76141f8
b878e0d
6e91fb1
961613b
dc8f2f0
f5bfa9b
26c5de5
7dc72a0
b2bb0f9
7b4d2a0
a2d717d
75d62ee
fe30cde
5efd1ae
524ef16
99f1f0e
afd3133
9f5a670
6520b21
7b2fc48
c6be456
441b967
1590ef3
e100f54
795e889
35c15e4
672e926
df03f7e
cd60ee9
eb341f0
1d411f2
77a3f81
faa4505
1695e8b
ea3c225
a8be7a7
26fe803
b208016
e9dbf31
d5802c3
bb03cdc
0c7853d
7e09a00
dddcbc2
ccffa1d
89909d8
f0ff2be
4b97c6e
c8f29e3
84f06b8
871b0a3
15c9f27
75dbda4
48056a7
b5663d0
e03b1b8
92cebab
ef2531b
8323335
08a50bd
407df06
c180d0c
d71dcfa
0918361
3bc174b
2faa45c
6d1d937
a8433b8
a6ca703
0804ca8
af2a957
a9b2998
7cfdd74
294643e
4b4699a
8d374f1
8f9549c
3f3b19d
69f2ff3
aa452b6
1e48418
2849b12
e089d48
1f3b6d8
24c782e
4788d5f
47b9837
13c3df9
64e8935
252bd80
0ef8ef6
3ac2b5c
f3d9dff
346a72f
e373f7a
fb99a85
4675f22
6bbaef1
adaf170
dcef154
7d71a35
7ff0cf6
2f3bc37
abf1bfb
f093d7e
1cc9e6e
fb14c83
1ecc291
4eb91b9
448d0ec
c192d53
1e8e662
d4d8a0f
b77e36d
13d7c60
3793cc1
7407165
2b43657
964aedb
9662a60
b754e40
7687261
b65760b
9d3ea92
0e80be8
068868d
a438b23
e933948
fe32806
d89084c
3910a2c
63adf07
953302e
f64f4f5
e3e949c
1593bf4
bc0c4db
9a440f8
c0506a1
49c39ef
f755e66
028f2dd
47914c6
2a4a43e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| function(add_irdl_to_cpp_target target irdl_file) | ||
| add_custom_command( | ||
| OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc | ||
| COMMAND ${MLIR_IRDL_TO_CPP_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/${irdl_file} -o ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc | ||
| DEPENDS ${MLIR_IRDL_TO_CPP_TARGET} ${irdl_file} | ||
| COMMENT "Building ${irdl_file}..." | ||
| ) | ||
| add_custom_target(${target} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc) | ||
| endfunction() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| //===- TranslationRegistration.h - Register translation ---------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines the registration function for the IRDL to C++ translation. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_TARGET_IRDLTOCPP_IRDLTOCPP_H | ||
| #define MLIR_TARGET_IRDLTOCPP_IRDLTOCPP_H | ||
|
|
||
| #include "mlir/Dialect/IRDL/IR/IRDL.h" | ||
|
|
||
| namespace mlir { | ||
| namespace irdl { | ||
|
|
||
| /// Translates an IRDL dialect definition to a C++ definition that can be used | ||
| /// with MLIR. | ||
| /// | ||
| /// As with TableGen declarations, the following preprocessor macros will | ||
| /// generate the corresponding code: | ||
| /// | ||
| /// // This define generates code for the dialect's class declarations | ||
| /// #define GEN_DIALECT_DECL_HEADER | ||
| /// | ||
| /// // This define generates code for the dialect's class definitions | ||
| /// #define GEN_DIALECT_DEF | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that all the macro guards that are available? |
||
| LogicalResult | ||
| translateIRDLDialectToCpp(llvm::ArrayRef<irdl::DialectOp> dialects, | ||
| raw_ostream &output); | ||
|
|
||
| } // namespace irdl | ||
| } // namespace mlir | ||
|
|
||
| #endif // MLIR_TARGET_IRDLTOCPP_IRDLTOCPP_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===- TranslationRegistration.h - Register translation ---------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines the registration function for the IRDL to C++ translation. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_TARGET_IRDLTOCPP_TRANSLATIONREGISTRATION_H | ||
| #define MLIR_TARGET_IRDLTOCPP_TRANSLATIONREGISTRATION_H | ||
|
|
||
| namespace mlir { | ||
|
|
||
| void registerIRDLToCppTranslation(); | ||
|
|
||
| } // namespace mlir | ||
|
|
||
| #endif // MLIR_TARGET_IRDLTOCPP_TRANSLATIONREGISTRATION_H |
hhkit marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -74,13 +74,62 @@ static void printSingleBlockRegion(OpAsmPrinter &p, Operation *op, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!region.getBlocks().front().empty()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| p.printRegion(region); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static llvm::LogicalResult isValidName(llvm::StringRef in, mlir::Operation *loc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a newline between the two functions? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Twine &label) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (in.empty()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return loc->emitError("name of ") << label << " is empty"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool allowUnderscore = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (auto &elem : in) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (elem == '_') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!allowUnderscore) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return loc->emitError("name of ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << label << " should not contain leading or double underscores"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Moxinilian marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Moxinilian marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!isalnum(elem)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return loc->emitError("name of ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << " must contain only lowercase letters, digits and " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "underscores"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (llvm::isUpper(elem)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return loc->emitError("name of ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << label << " should not contain uppercase letters"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| allowUnderscore = elem != '_'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+83
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't easily format on GitHub but I hope you get the gist.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return success(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LogicalResult DialectOp::verify() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!Dialect::isValidNamespace(getName())) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return emitOpError("invalid dialect name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (failed(isValidName(getSymName(), getOperation(), "dialect"))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return failure(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return success(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LogicalResult OperationOp::verify() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return isValidName(getSymName(), getOperation(), "operation"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LogicalResult TypeOp::verify() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto symName = getSymName(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (symName.front() == '!') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is no bueno but we have to due to symbols. Once this PR is merged upstream I'll fix it myself. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| symName = symName.substr(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return isValidName(symName, getOperation(), "type"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LogicalResult AttributeOp::verify() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto symName = getSymName(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (symName.front() == '#') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| symName = symName.substr(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return isValidName(symName, getOperation(), "attribute"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LogicalResult OperationOp::verifyRegions() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Stores pairs of value kinds and the list of names of values of this kind in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // the operation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -133,18 +182,10 @@ static LogicalResult verifyNames(Operation *op, StringRef kindName, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DenseMap<StringRef, size_t> nameMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (auto [i, name] : llvm::enumerate(names)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StringRef nameRef = llvm::cast<StringAttr>(name).getValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (nameRef.empty()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return op->emitOpError() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << "name of " << kindName << " #" << i << " is empty"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!llvm::isAlpha(nameRef[0]) && nameRef[0] != '_') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return op->emitOpError() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << "name of " << kindName << " #" << i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << " must start with either a letter or an underscore"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (llvm::any_of(nameRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [](char c) { return !llvm::isAlnum(c) && c != '_'; })) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return op->emitOpError() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << "name of " << kindName << " #" << i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << " must contain only letters, digits and underscores"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (failed(isValidName(nameRef, op, Twine(kindName) + " #" + Twine(i)))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return failure(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (nameMap.contains(nameRef)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return op->emitOpError() << "name of " << kindName << " #" << i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| << " is a duplicate of the name of " << kindName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| add_subdirectory(Cpp) | ||
| add_subdirectory(IRDLToCpp) | ||
| add_subdirectory(SPIRV) | ||
| add_subdirectory(LLVMIR) | ||
| add_subdirectory(LLVM) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| add_mlir_translation_library(MLIRTargetIRDLToCpp | ||
| TranslationRegistration.cpp | ||
| IRDLToCpp.cpp | ||
| Templates/DialectDecl.txt | ||
| Templates/DialectDef.txt | ||
| Templates/Header.txt | ||
| Templates/PerOperationDecl.txt | ||
| Templates/PerOperationDef.txt | ||
| Templates/TypeDecl.txt | ||
| Templates/TypeDef.txt | ||
| Templates/TypeHeaderDecl.txt | ||
| Templates/TypeHeaderDef.txt | ||
|
|
||
| LINK_LIBS PUBLIC | ||
| MLIRIR | ||
| MLIRIRDL | ||
| MLIRTranslateLib | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing is inconsistent 👉 👈