This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Inline an interface method to its only user.
ClosedPublic

Authored by akuegel on Aug 2 2022, 5:57 AM.

Details

Summary

It seems only the default implementation is ever used, so it doesn't seem
necessary to include this method in the interface.

Diff Detail

Event Timeline

akuegel created this revision.Aug 2 2022, 5:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2022, 5:57 AM
akuegel requested review of this revision.Aug 2 2022, 5:57 AM
ftynse added a subscriber: ftynse.Aug 2 2022, 6:01 AM

There are plenty of cases where only the default implementation is used that we can switch from being an (overridable) interface method to an extraSharedClassDeclaration on the interface class IMO.

There are plenty of cases where only the default implementation is used that we can switch from being an (overridable) interface method to an extraSharedClassDeclaration on the interface class IMO.

Agree, I think there are more. This was just one method that I hit when trying to extract the interface for destination-style ops (discussed in https://discourse.llvm.org/t/rfc-interface-for-destination-style-ops/64056)
While working on that, I am happy to do further cleanups.

mravishankar requested changes to this revision.Aug 2 2022, 12:48 PM

I am not sure we want to do this. Some of this was implemented this way to hide the fact that the input and output operands of a linalg op being consecutive is am implementation detail of current Linalg op definition, and would like to hide this from users by relying on interface methods to querry the information without relying on operand ordering.

This revision now requires changes to proceed.Aug 2 2022, 12:48 PM

I am not sure we want to do this. Some of this was implemented this way to hide the fact that the input and output operands of a linalg op being consecutive is am implementation detail of current Linalg op definition, and would like to hide this from users by relying on interface methods to querry the information without relying on operand ordering.

I don't understand this concern. Inlining the method still allows to provide custom getInputOperands and getOutputOperands interface methods which do not need to meet the assumption that the input and output operands are consecutive. And regarding the assumption that the output operands appear consecutive, that is already there in the code, as the method is only allowed to return two values: begin and end of where the output positions are in the loops to shapes map.

pifon2a added a subscriber: pifon2a.EditedAug 3 2022, 12:28 AM

I am not sure we want to do this. Some of this was implemented this way to hide the fact that the input and output operands of a linalg op being consecutive is am implementation detail of current Linalg op definition, and would like to hide this from users by relying on interface methods to querry the information without relying on operand ordering.

I am not sure I follow. This PR does not really change anything. Some of the interfaces in Linalg have to be revisited and cleaned up.

@akuegel, I like @ftynse's idea to just move it to extraSharedClassDeclaration or even make it a static func in cpp file, just to keep stuff readable.

akuegel updated this revision to Diff 449563.Aug 3 2022, 12:46 AM

Move to static function.

pifon2a accepted this revision.Aug 3 2022, 12:52 AM
akuegel updated this revision to Diff 449632.Aug 3 2022, 4:49 AM

Fix formatting.

pifon2a accepted this revision.Aug 3 2022, 5:19 AM
mravishankar accepted this revision.Aug 3 2022, 9:58 AM

Change now makes sense since it is limited to LinalgInterface. This was a a bit of frought API to begin with (full disclosure, I added it).

This revision is now accepted and ready to land.Aug 3 2022, 9:58 AM

Change now makes sense since it is limited to LinalgInterface. This was a a bit of frought API to begin with (full disclosure, I added it).

Just for the record, it was already limited to LinalgInterface before. The only thing I changed is that I have extracted it into a static function.

This revision was landed with ongoing or failed builds.Aug 3 2022, 11:40 PM
This revision was automatically updated to reflect the committed changes.

Change now makes sense since it is limited to LinalgInterface. This was a a bit of frought API to begin with (full disclosure, I added it).

I don't understand. How is it different from just inlining that code? It was already limited to LinalgInterface. Why didn't you approve it before? What changed other than the readability aspect?