[PATCH] D77322: Change pass registration generated code to allow users to selectively register passes
Mehdi AMINI via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 10:50:12 PDT 2020
mehdi_amini created this revision.
mehdi_amini added a reviewer: rriddle.
Herald added subscribers: llvm-commits, grosul1, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar.
Herald added a project: LLVM.
This slightly tweaks the generated code from:
#ifdef GEN_PASS_REGISTRATION
::mlir::registerPass("flag1", ...
::mlir::registerPass("flag2", ...
#endif // GEN_PASS_REGISTRATION
to:
#ifdef GEN_PASS_REGISTRATION
#define GEN_PASS_REGISTRATION_Pass1
#define GEN_PASS_REGISTRATION_Pass2
#endif // GEN_PASS_REGISTRATION
#ifdef GEN_PASS_REGISTRATION_Pass1
::mlir::registerPass("flag1", ...
#endif
#ifdef GEN_PASS_REGISTRATION_Pass1
::mlir::registerPass("flag2", ...
#endif
That way the generated code can be included by defining the
`GEN_PASS_REGISTRATION` macro as currenty and register all the passes,
but one can also define only `GEN_PASS_REGISTRATION_Pass1` to register a
subset of the passes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77322
Files:
mlir/tools/mlir-tblgen/PassGen.cpp
Index: mlir/tools/mlir-tblgen/PassGen.cpp
===================================================================
--- mlir/tools/mlir-tblgen/PassGen.cpp
+++ mlir/tools/mlir-tblgen/PassGen.cpp
@@ -88,13 +88,31 @@
static void emitRegistration(ArrayRef<Pass> passes, raw_ostream &os) {
os << "#ifdef GEN_PASS_REGISTRATION\n";
for (const Pass &pass : passes) {
+ os << llvm::formatv("#define GEN_PASS_REGISTRATION_{0}\n",
+ pass.getDef()->getName());
+ }
+ os << "#endif // GEN_PASS_REGISTRATION\n";
+
+ for (const Pass &pass : passes) {
+ os << llvm::formatv("#ifdef GEN_PASS_REGISTRATION_{0}\n",
+ pass.getDef()->getName());
os << llvm::formatv("::mlir::registerPass(\"{0}\", \"{1}\", []() -> "
"std::unique_ptr<Pass> {{ return {2}; });\n",
pass.getArgument(), pass.getSummary(),
pass.getConstructor());
+ os << llvm::formatv("#endif // GEN_PASS_REGISTRATION_{0}\n",
+ pass.getDef()->getName());
+ os << llvm::formatv("#undef GEN_PASS_REGISTRATION_{0}\n",
+ pass.getDef()->getName());
+ }
+
+ os << "#ifdef GEN_PASS_REGISTRATION\n";
+ for (const Pass &pass : passes) {
+ os << llvm::formatv("#undef GEN_PASS_REGISTRATION_{0}\n",
+ pass.getDef()->getName());
}
- os << "#undef GEN_PASS_REGISTRATION\n";
os << "#endif // GEN_PASS_REGISTRATION\n";
+ os << "#undef GEN_PASS_REGISTRATION\n";
}
//===----------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77322.254564.patch
Type: text/x-patch
Size: 1599 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200402/298e6b5e/attachment.bin>
More information about the llvm-commits
mailing list