Skip to content

Conversation

@hanhanW
Copy link
Contributor

@hanhanW hanhanW commented Nov 8, 2025

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.

This is the preparation for llvm/llvm-project#166904

Signed-off-by: hanhanW hanhan0912@gmail.com

@hanhanW hanhanW force-pushed the users/hanhanW/evolve-tablegen branch 2 times, most recently from 35dc907 to e3c7f56 Compare November 11, 2025 18:08
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>
@hanhanW hanhanW force-pushed the users/hanhanW/evolve-tablegen branch from e3c7f56 to 4572127 Compare November 11, 2025 18:09
Signed-off-by: hanhanW <hanhan0912@gmail.com>
@hanhanW hanhanW requested a review from sjarus November 12, 2025 19:00
@hanhanW hanhanW marked this pull request as ready for review November 12, 2025 19:00
@hanhanW
Copy link
Contributor Author

hanhanW commented Nov 17, 2025

Can someone help review this?

Copy link
Member

@sahas3 sahas3 left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the DECL needed?

Copy link
Contributor Author

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.

@zjgarvey
Copy link
Collaborator

I'll take a look in a bit, sorry for the delay.

Copy link
Collaborator

@zjgarvey zjgarvey left a 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.

Comment on lines -26 to -36
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();
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@hanhanW hanhanW enabled auto-merge (squash) November 17, 2025 22:49
@hanhanW hanhanW merged commit a2bcca0 into main Nov 17, 2025
3 checks passed
@hanhanW hanhanW deleted the users/hanhanW/evolve-tablegen branch November 17, 2025 22:49
@hanhanW
Copy link
Contributor Author

hanhanW commented Nov 17, 2025

I unresolved the conversion after I landed the PR, because others may have the same questions and they can see the answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants