This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Transform] Allow parameter types in merge_handles op
ClosedPublic

Authored by qedawkins on Jun 18 2023, 10:07 PM.

Details

Summary

Similar to operation handles, merging parameters can be useful to
avoid repetition of common transformations across a set of parameters.
For example, forming a list of static values for comparison rather than
comparing the parameters one at a time.

Diff Detail

Event Timeline

qedawkins created this revision.Jun 18 2023, 10:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2023, 10:07 PM
qedawkins requested review of this revision.Jun 18 2023, 10:07 PM
ftynse requested changes to this revision.Jun 19 2023, 1:28 AM

Note that AnyHandleOrParamType also allows for value handles, but the implementation doesn't support them. Please either restrict the type to not allow for value handle or add support for those in the implementation. Looks good otherwise.

This revision now requires changes to proceed.Jun 19 2023, 1:28 AM
qedawkins updated this revision to Diff 532751.Jun 19 2023, 2:12 PM

Enable merging of value handles

Note that AnyHandleOrParamType also allows for value handles, but the implementation doesn't support them. Please either restrict the type to not allow for value handle or add support for those in the implementation. Looks good otherwise.

Thanks, I've been a bit confused by the terminology surrounding handles and parameters. Related, transform.replicate seems to be missing support for value handles as well: https://github.com/llvm/llvm-project/blob/4b6d41cd1d73a72403679ec21732df3610fc0964/mlir/lib/Dialect/Transform/IR/TransformOps.cpp#L1472.

ftynse accepted this revision.Jun 19 2023, 2:42 PM

Thanks!

mlir/lib/Dialect/Transform/IR/TransformOps.cpp
1259

Nit: I don't remember if there is a check somewhere that we have more than one operand so .front() wouldn't crash here, better to double-check and return failure if there no verifier.

This revision is now accepted and ready to land.Jun 19 2023, 2:42 PM

Note that AnyHandleOrParamType also allows for value handles, but the implementation doesn't support them. Please either restrict the type to not allow for value handle or add support for those in the implementation. Looks good otherwise.

Thanks, I've been a bit confused by the terminology surrounding handles and parameters. Related, transform.replicate seems to be missing support for value handles as well: https://github.com/llvm/llvm-project/blob/4b6d41cd1d73a72403679ec21732df3610fc0964/mlir/lib/Dialect/Transform/IR/TransformOps.cpp#L1472.

Value handles are newer than many operations and are not widely used, so there are probably more operations that could be updated but haven't because there was no need.

For terminology, parameters are a kind of "attribute handles" if you wish.

qedawkins added inline comments.Jun 19 2023, 2:50 PM
mlir/lib/Dialect/Transform/IR/TransformOps.cpp
1259

The SameOperandsAndResultType OpTrait seems to check for at least one operand: https://github.com/llvm/llvm-project/blob/58669354bf1f8eef39979e31915b1e212a3985c9/mlir/lib/IR/Operation.cpp#L1024

(verified by trying it anyway) If wanted I can add a test.

error: unexpected error: 'transform.merge_handles' op expected 1 or more operands, but found 0
  transform.merge_handles : !transform.any_value

Value handles are newer than many operations and are not widely used, so there are probably more operations that could be updated but haven't because there was no need.

For terminology, parameters are a kind of "attribute handles" if you wish.

Ah makes sense, thanks for the note.

ftynse added inline comments.Jun 19 2023, 11:58 PM
mlir/lib/Dialect/Transform/IR/TransformOps.cpp
1259

Thanks for checking! There's no need to test that.