This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Allow nested operations to be transformed
AbandonedPublic

Authored by Whitney on Feb 23 2023, 8:26 AM.

Details

Summary

We noticed that transformations that operate on func::FuncOp, e.g., AffineScalarReplacementPass, don't get invoked for func::FuncOp nested inside another region, e.g., gpu.module.

This commit allows transformations that operate on func::FuncOp to work as expected even if the func::FuncOp operation is nested in another region.

Diff Detail

Event Timeline

Whitney created this revision.Feb 23 2023, 8:26 AM
Whitney requested review of this revision.Feb 23 2023, 8:26 AM
mehdi_amini added inline comments.Feb 23 2023, 1:52 PM
mlir/test/Pass/nested-operations.mlir
5

I'm not sure I understand what you're trying to do.

If you want -affine-scalrep to be scheduled on the function, you should do so explicitly.

mlir-opt --pass-pipeline="gpu.module(func.func(affine-scalrep))"

mehdi_amini requested changes to this revision.Feb 23 2023, 1:52 PM
This revision now requires changes to proceed.Feb 23 2023, 1:52 PM
Whitney added inline comments.Feb 23 2023, 2:17 PM
mlir/test/Pass/nested-operations.mlir
5

We have a driver that add the pass like PM.addNestedPass<func::FuncOp>(mlir::createAffineScalarReplacementPass());.
We noticed that when we nest the func::FuncOp under gpu.module, the pass is no longer invoked.
Is there a better way to add the pass in the pipeline?

Whitney added inline comments.Feb 23 2023, 2:19 PM
mlir/test/Pass/nested-operations.mlir
5

We are trying to have a pipeline that AffineScalarReplacementPass is invoked no matter the func::FuncOp is nested in gpu.module or not.

mehdi_amini added inline comments.Feb 23 2023, 3:04 PM
mlir/test/Pass/nested-operations.mlir
5

We are trying to have a pipeline that AffineScalarReplacementPass is invoked no matter the func::FuncOp is nested in gpu.module or not.

In general you can't.
What you can do is something equivalent to:

--pass-pipeline="gpu.module(func.func(affine-scalrep)),func.func(affine-scalrep)"

or (I think):

--pass-pipeline="any(func.func(affine-scalrep)),func.func(affine-scalrep)"
Whitney abandoned this revision.Feb 24 2023, 7:37 AM

Given that there is a workaround, closing this review.

mlir/test/Pass/nested-operations.mlir
5

That's unfortunate. It would be ideal to have a way to run a func::FuncOp pass no matter if it is nested or not.

mehdi_amini added inline comments.Feb 24 2023, 8:05 AM
mlir/test/Pass/nested-operations.mlir
5

You can implement this kind of conditional logic in a pass that you write. The pass would run a pipeline dynamically: https://mlir.llvm.org/docs/PassManagement/#dynamic-pass-pipelines

In general a compiler pipeline has full control on the structure of the IR and even more: it expects a specific form.
It's pretty rare that you have to take some IR and find functions without knowing where they are supposed to be.