[Mlir-commits] [mlir] a22af3e - [MLIR] Keep but deprecate old autogenerated pass base classes
Michele Scuttari
llvmlistbot at llvm.org
Wed Aug 31 14:39:33 PDT 2022
Author: Michele Scuttari
Date: 2022-08-31T23:39:01+02:00
New Revision: a22af3e1eb9eaa6be9638c44f188e086f4d5665b
URL: https://github.com/llvm/llvm-project/commit/a22af3e1eb9eaa6be9638c44f188e086f4d5665b
DIFF: https://github.com/llvm/llvm-project/commit/a22af3e1eb9eaa6be9638c44f188e086f4d5665b.diff
LOG: [MLIR] Keep but deprecate old autogenerated pass base classes
Restore the generation of the old pass base classes for better transitioning of external projects relying on them. They were eliminated with 67d0d7ac0acb0665d6a09f61278fbcf51f0114c2.
Reviewed By: rsmith
Differential Revision: https://reviews.llvm.org/D133027
Added:
Modified:
mlir/tools/mlir-tblgen/PassGen.cpp
Removed:
################################################################################
diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp
index aaecaf0057c91..d81f9d7d327d1 100644
--- a/mlir/tools/mlir-tblgen/PassGen.cpp
+++ b/mlir/tools/mlir-tblgen/PassGen.cpp
@@ -362,6 +362,74 @@ static void emitPass(const Pass &pass, raw_ostream &os) {
emitPassDefs(pass, os);
}
+// TODO: Drop old pass declarations.
+// The old pass base class is being kept until all the passes have switched to
+// the new decls/defs design.
+const char *const oldPassDeclBegin = R"(
+template <typename DerivedT>
+class {0}Base : public {1} {
+public:
+ using Base = {0}Base;
+
+ {0}Base() : {1}(::mlir::TypeID::get<DerivedT>()) {{}
+ {0}Base(const {0}Base &other) : {1}(other) {{}
+
+ /// Returns the command-line argument attached to this pass.
+ static constexpr ::llvm::StringLiteral getArgumentName() {
+ return ::llvm::StringLiteral("{2}");
+ }
+ ::llvm::StringRef getArgument() const override { return "{2}"; }
+
+ ::llvm::StringRef getDescription() const override { return "{3}"; }
+
+ /// Returns the derived pass name.
+ static constexpr ::llvm::StringLiteral getPassName() {
+ return ::llvm::StringLiteral("{0}");
+ }
+ ::llvm::StringRef getName() const override { return "{0}"; }
+
+ /// Support isa/dyn_cast functionality for the derived pass class.
+ static bool classof(const ::mlir::Pass *pass) {{
+ return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
+ }
+
+ /// A clone method to create a copy of this pass.
+ std::unique_ptr<::mlir::Pass> clonePass() const override {{
+ return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
+ }
+
+ /// Return the dialect that must be loaded in the context before this pass.
+ void getDependentDialects(::mlir::DialectRegistry ®istry) const override {
+ {4}
+ }
+
+ /// Explicitly declare the TypeID for this class. We declare an explicit private
+ /// instantiation because Pass classes should only be visible by the current
+ /// library.
+ MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID({0}Base<DerivedT>)
+
+protected:
+)";
+
+// TODO: Drop old pass declarations.
+/// Emit a backward-compatible declaration of the pass base class.
+static void emitOldPassDecl(const Pass &pass, raw_ostream &os) {
+ StringRef defName = pass.getDef()->getName();
+ std::string dependentDialectRegistrations;
+ {
+ llvm::raw_string_ostream dialectsOs(dependentDialectRegistrations);
+ for (StringRef dependentDialect : pass.getDependentDialects())
+ dialectsOs << llvm::formatv(dialectRegistrationTemplate,
+ dependentDialect);
+ }
+ os << llvm::formatv(oldPassDeclBegin, defName, pass.getBaseClass(),
+ pass.getArgument(), pass.getSummary(),
+ dependentDialectRegistrations);
+ emitPassOptionDecls(pass, os);
+ emitPassStatisticDecls(pass, os);
+ os << "};\n";
+}
+
static void emitPasses(const llvm::RecordKeeper &recordKeeper,
raw_ostream &os) {
std::vector<Pass> passes = getPasses(recordKeeper);
@@ -371,6 +439,15 @@ static void emitPasses(const llvm::RecordKeeper &recordKeeper,
emitPass(pass, os);
emitRegistrations(passes, os);
+
+ // TODO: Drop old pass declarations.
+ // Emit the old code until all the passes have switched to the new design.
+ os << "// Deprecated. Please use the new per-pass macros.\n";
+ os << "#ifdef GEN_PASS_CLASSES\n";
+ for (const Pass &pass : passes)
+ emitOldPassDecl(pass, os);
+ os << "#undef GEN_PASS_CLASSES\n";
+ os << "#endif // GEN_PASS_CLASSES\n";
}
static mlir::GenRegistration
More information about the Mlir-commits
mailing list