-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[mlir] Remove deprecated GEN_PASS_CLASSES. #166904
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
base: main
Are you sure you want to change the base?
Conversation
This was marked as deprecated in 2022, but as comment. Switch to error to make visible and stop generating. Will remove the error message in follow up, just felt this was easier for folks to understand compilation errors. Also updated CIR & flang.
|
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-flang-fir-hlfir Author: Jacques Pienaar (jpienaar) ChangesThis was marked as deprecated in 2022, but as comment. Switch to error to make visible and stop generating. Will remove the error message in follow up, just felt this was easier for folks to understand compilation errors. The change required to new form is rather minimal. Also updated CIR & flang. Full diff: https://github.com/llvm/llvm-project/pull/166904.diff 9 Files Affected:
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index fbecab9774f5b..2ef09b74dc968 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
@@ -26,6 +26,11 @@
using namespace mlir;
using namespace cir;
+namespace mlir {
+#define GEN_PASS_DEF_CIRCANONICALIZE
+#include "clang/CIR/Dialect/Passes.h.inc"
+} // namespace mlir
+
namespace {
/// Removes branches between two blocks if it is the only branch.
@@ -101,7 +106,8 @@ struct RemoveEmptySwitch : public OpRewritePattern<SwitchOp> {
// CIRCanonicalizePass
//===----------------------------------------------------------------------===//
-struct CIRCanonicalizePass : public CIRCanonicalizeBase<CIRCanonicalizePass> {
+struct CIRCanonicalizePass
+ : public impl::CIRCanonicalizeBase<CIRCanonicalizePass> {
using CIRCanonicalizeBase::CIRCanonicalizeBase;
// The same operation rewriting done here could have been performed
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp
index 3c6f76892d5cb..dcef9ddee1bb4 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp
@@ -21,6 +21,11 @@
using namespace mlir;
using namespace cir;
+namespace mlir {
+#define GEN_PASS_DEF_CIRSIMPLIFY
+#include "clang/CIR/Dialect/Passes.h.inc"
+} // namespace mlir
+
//===----------------------------------------------------------------------===//
// Rewrite patterns
//===----------------------------------------------------------------------===//
@@ -283,7 +288,7 @@ struct SimplifyVecSplat : public OpRewritePattern<VecSplatOp> {
// CIRSimplifyPass
//===----------------------------------------------------------------------===//
-struct CIRSimplifyPass : public CIRSimplifyBase<CIRSimplifyPass> {
+struct CIRSimplifyPass : public impl::CIRSimplifyBase<CIRSimplifyPass> {
using CIRSimplifyBase::CIRSimplifyBase;
void runOnOperation() override;
diff --git a/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp b/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
index ca7554e4e3754..69a5334ca2423 100644
--- a/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
@@ -26,6 +26,11 @@
using namespace mlir;
using namespace cir;
+namespace mlir {
+#define GEN_PASS_DEF_CIRFLATTENCFG
+#include "clang/CIR/Dialect/Passes.h.inc"
+} // namespace mlir
+
namespace {
/// Lowers operations with the terminator trait that have a single successor.
@@ -50,7 +55,7 @@ void walkRegionSkipping(
});
}
-struct CIRFlattenCFGPass : public CIRFlattenCFGBase<CIRFlattenCFGPass> {
+struct CIRFlattenCFGPass : public impl::CIRFlattenCFGBase<CIRFlattenCFGPass> {
CIRFlattenCFGPass() = default;
void runOnOperation() override;
diff --git a/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp b/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp
index c0db98440a902..00972b6976295 100644
--- a/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp
@@ -14,9 +14,14 @@
using namespace mlir;
using namespace cir;
+namespace mlir {
+#define GEN_PASS_DEF_GOTOSOLVER
+#include "clang/CIR/Dialect/Passes.h.inc"
+} // namespace mlir
+
namespace {
-struct GotoSolverPass : public GotoSolverBase<GotoSolverPass> {
+struct GotoSolverPass : public impl::GotoSolverBase<GotoSolverPass> {
GotoSolverPass() = default;
void runOnOperation() override;
};
diff --git a/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp b/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp
index 72bbf08c79b16..74b22faadc8ae 100644
--- a/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp
@@ -20,9 +20,14 @@
using namespace mlir;
using namespace cir;
+namespace mlir {
+#define GEN_PASS_DEF_HOISTALLOCAS
+#include "clang/CIR/Dialect/Passes.h.inc"
+} // namespace mlir
+
namespace {
-struct HoistAllocasPass : public HoistAllocasBase<HoistAllocasPass> {
+struct HoistAllocasPass : public impl::HoistAllocasBase<HoistAllocasPass> {
HoistAllocasPass() = default;
void runOnOperation() override;
diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
index cba04649ca05e..29b1211d2c351 100644
--- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
@@ -23,6 +23,11 @@
using namespace mlir;
using namespace cir;
+namespace mlir {
+#define GEN_PASS_DEF_LOWERINGPREPARE
+#include "clang/CIR/Dialect/Passes.h.inc"
+} // namespace mlir
+
static SmallString<128> getTransformedFileName(mlir::ModuleOp mlirModule) {
SmallString<128> fileName;
@@ -53,7 +58,8 @@ static cir::FuncOp getCalledFunction(cir::CallOp callOp) {
}
namespace {
-struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
+struct LoweringPreparePass
+ : public impl::LoweringPrepareBase<LoweringPreparePass> {
LoweringPreparePass() = default;
void runOnOperation() override;
diff --git a/clang/lib/CIR/Dialect/Transforms/PassDetail.h b/clang/lib/CIR/Dialect/Transforms/PassDetail.h
index 600dde56d679f..ef42a85cc2751 100644
--- a/clang/lib/CIR/Dialect/Transforms/PassDetail.h
+++ b/clang/lib/CIR/Dialect/Transforms/PassDetail.h
@@ -21,7 +21,7 @@ namespace mlir {
template <typename ConcreteDialect>
void registerDialect(DialectRegistry ®istry);
-#define GEN_PASS_CLASSES
+#define GEN_PASS_DECL
#include "clang/CIR/Dialect/Passes.h.inc"
} // namespace mlir
diff --git a/flang/lib/Optimizer/CodeGen/PassDetail.h b/flang/lib/Optimizer/CodeGen/PassDetail.h
index f7030131beff9..252da029dc0c8 100644
--- a/flang/lib/Optimizer/CodeGen/PassDetail.h
+++ b/flang/lib/Optimizer/CodeGen/PassDetail.h
@@ -18,7 +18,7 @@
namespace fir {
-#define GEN_PASS_CLASSES
+#define GEN_PASS_DECL
#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
} // namespace fir
diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp
index f4b8eb43b49b8..e4ae78f022405 100644
--- a/mlir/tools/mlir-tblgen/PassGen.cpp
+++ b/mlir/tools/mlir-tblgen/PassGen.cpp
@@ -387,81 +387,6 @@ 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) {{}
- {0}Base& operator=(const {0}Base &) = delete;
- {0}Base({0}Base &&) = delete;
- {0}Base& operator=({0}Base &&) = delete;
- ~{0}Base() = default;
-
- /// 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 R"PD({3})PD"; }
-
- /// 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));
- }
-
- /// Register the dialects 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);
- llvm::interleave(
- pass.getDependentDialects(), dialectsOs,
- [&](StringRef dependentDialect) {
- dialectsOs << formatv(dialectRegistrationTemplate, dependentDialect);
- },
- "\n ");
- }
- os << formatv(oldPassDeclBegin, defName, pass.getBaseClass(),
- pass.getArgument(), pass.getSummary().trim(),
- dependentDialectRegistrations);
- emitPassOptionDecls(pass, os);
- emitPassStatisticDecls(pass, os);
- os << "};\n";
-}
-
static void emitPasses(const RecordKeeper &records, raw_ostream &os) {
std::vector<Pass> passes = getPasses(records);
os << "/* Autogenerated by mlir-tblgen; don't manually edit */\n";
@@ -479,12 +404,10 @@ static void emitPasses(const RecordKeeper &records, raw_ostream &os) {
emitRegistrations(passes, os);
- // TODO: Drop old pass declarations.
+ // TODO: Remove warning, kept in to make error understandable.
// 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 << "#error \"GEN_PASS_CLASSES is deprecated; use per-pass macros\"\n";
os << "#undef GEN_PASS_CLASSES\n";
os << "#endif // GEN_PASS_CLASSES\n";
}
|
mscuttari
left a comment
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.
Leftover of mine, thank you for addressing it!
xlauko
left a comment
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.
lgtm
andykaylor
left a comment
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.
lgtm
|
IREE side, I think we are good because I don't find torch-mlir needs an update: https://github.com/search?q=repo%3Allvm%2Ftorch-mlir%20GEN_PASS_CLASSES&type=code It will break IREE because of torch-mlir. cc @sjarus @MaheshRavishankar |
Looks like a trivial update in a few places that we can handle alongside the next LLVM bump there ? @Lallapallooza - you'd need to patch this in case you're doing another LLVM update on the TorchMLIR side soon |
Note that you'll need to update many files, at least 36 files. You don't need the patch to finish the migration. It took me few days to finish all the migration in IREE, FYI. |
This was marked as deprecated in 2022, but as comment. Switch to error to make visible and stop generating. Will remove the error message in follow up, just felt this was easier for folks to understand compilation errors. The change required to new form is rather minimal.
Also updated CIR & flang.