-
Notifications
You must be signed in to change notification settings - Fork 617
[NFC] Switch to new pass generation tablegen definitions. #4370
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
Conversation
35dc907 to
e3c7f56
Compare
This commit completes the migration from the deprecated GEN_PASS_CLASSES to the new GEN_PASS_DEF infrastructure across all torch-mlir passes. Changes include: 1. Remove PassDetail.h files (deprecated pattern) - Deleted lib/Conversion/PassDetail.h - Deleted lib/RefBackend/PassDetail.h - Deleted lib/Dialect/Torch/Transforms/PassDetail.h - Deleted lib/Dialect/TorchConversion/Transforms/PassDetail.h - Deleted lib/Dialect/TMTensor/Transforms/PassDetail.h 2. Migrate conversion passes to GEN_PASS_DEF - Updated all passes in lib/Conversion/ to use #define GEN_PASS_DEF_* - Removed GEN_PASS_DECL from .cpp files (move to headers where needed) - Fixed includes and namespace declarations 3. Migrate dialect transform passes - Updated Torch, TorchConversion, and TMTensor transform passes - Properly scoped GEN_PASS_DEF in namespace blocks 4. Handle passes with options (TorchToStablehlo, TorchToTosa) - Added GEN_PASS_DECL_* to headers - Implemented default and convenience create functions - Used generated constructors via `using BaseClass::BaseClass` 5. Handle passes without options (RefBackend) - Removed manual create function implementations - Let tablegen auto-generate create functions - Added using declarations for Base classes in impl namespace 6. Fix backend type conversion passes - Added missing create functions in BackendTypeConversionPasses.cpp - Fixed namespace scoping issues 7. Fix missing namespace closures - Added proper closing namespace comments in Verify*BackendContract.cpp The migration maintains full backward compatibility while adopting the recommended LLVM pass infrastructure patterns. All passes now use the generated base classes and follow consistent patterns based on whether they have options defined in tablegen. Signed-off-by: hanhanW <hanhan0912@gmail.com>
e3c7f56 to
4572127
Compare
Signed-off-by: hanhanW <hanhan0912@gmail.com>
|
Can someone help review this? |
sahas3
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.
Sorry for the delay.
LGTM but I'll defer to someone else for the final approval as I am not that familiar with the tablegen pass generation infra.
| using namespace mlir::torch::Torch; | ||
| namespace mlir::torch::Torch { | ||
|
|
||
| #define GEN_PASS_DECL_DECOMPOSECOMPLEXOPS |
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.
Is the DECL needed?
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.
We need either GEN_PASS_DECL in some header file or a specific GEN_PASS_DECL_ for each pass. torch-mlir does not like mlir project or IREE project that has Passes.h that declares all the pass for you: https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/Transform/Transforms/Passes.h
The Passes.h seems to be common in pass transformation, and the GEN_PASS_DECL_PASSNAME is more common in conversion in upstream MLIR project.
|
I'll take a look in a bit, sorry for the delay. |
zjgarvey
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.
I'm sure this was very tedious. Thanks for cleaning up the deprecated tablegen defs and introducing per-pass defs.
I have one question about the changes, but other than that, LGTM.
| std::unique_ptr<OperationPass<ModuleOp>> createMungeCallingConventionsPass(); | ||
|
|
||
| std::unique_ptr<OperationPass<func::FuncOp>> createExpandOpsForLLVMPass(); | ||
|
|
||
| std::unique_ptr<OperationPass<ModuleOp>> createMLProgramBufferizePass(); | ||
|
|
||
| std::unique_ptr<OperationPass<func::FuncOp>> createMungeMemrefCopyPass(); | ||
|
|
||
| std::unique_ptr<OperationPass<func::FuncOp>> createGeneralizeTensorConcatPass(); | ||
|
|
||
| std::unique_ptr<OperationPass<func::FuncOp>> createGeneralizeTensorPadPass(); |
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.
Are these removed because they are unused elsewhere in this project? E.g. we still have createTorchToLinalgPass, but is that only because it is used in some pass pipeline?
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.
Edit: this was addressed in your PR description.
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.
Yes, I think they are handled by tablegen now. They were only used because we have let constructor = in tablegen, and the wrapper is not needed at all. I searched one of the pass creation on github, and there are no users at all: https://github.com/search?q=createExpandOpsForLLVM&type=code&p=1
I'd expect people to use the default (e.g., createGeneralizeTensorPad) to add a pass. To me, the pass name in td file should end up with Pass, which matches other MLIR project convention. E.g., def GeneralizeTensorPad -> def GeneralizeTensorPadPass.
|
I unresolved the conversion after I landed the PR, because others may have the same questions and they can see the answer. |
This commit completes the migration from the deprecated GEN_PASS_CLASSES
to the new GEN_PASS_DEF infrastructure across all torch-mlir passes.
Changes include:
Remove PassDetail.h files (deprecated pattern)
Migrate conversion passes to GEN_PASS_DEF
Migrate dialect transform passes
Handle passes with options (TorchToStablehlo, TorchToTosa)
using BaseClass::BaseClassHandle passes without options (RefBackend)
Fix backend type conversion passes
Fix missing namespace closures
The migration maintains full backward compatibility while adopting the
recommended LLVM pass infrastructure patterns. All passes now use the
generated base classes and follow consistent patterns based on whether
they have options defined in tablegen.
This is the preparation for llvm/llvm-project#166904
Signed-off-by: hanhanW hanhan0912@gmail.com