-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[mlir][Func] Preserve attribute when converting CallOp/ReturnOp signature #127772
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
Open
ZenithalHourlyRate
wants to merge
1
commit into
llvm:main
Choose a base branch
from
ZenithalHourlyRate:mlir-func-callop-attr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's not clear to me that this is always safe: can't the attribute be irrelevant or incorrect post-transformation? For example the number of operands may change but the attribute refers to them positionally.
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 think it is the responsibility of downstream dialect conversion user to maintain what they want: it is them that provide the type converter and call this type conversion pass. If the attribute accompany the call op does change its meaning after type conversion, the user could add another rewrite pattern to correct them.
The pass itself should not silently discard the attribute, instead it should let the user decide. It is more convenient for the user to see the original attribute after the conversion, than to save these attributes in case they might be lost, and recover it after the standard type conversion.
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.
From this point of view, you could say that it is downstream responsibility to gather their attributes before the pass and reapply them afterward.
I'm not sure why you believe that: these are called "discardable attributes" because the intent is that transformations should discard them when they don't "understand" them (through interfaces or other mechanism).
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.
Or more conversatively we can preserve some dialect attribute?
I have not seen some mechanism for the transformation to query that. For dialect attribute the transformation could query the dialect
namedAttr.getName().getDialect()
but I have not found dialect interface / attribute interface that describe such information.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.
"dialect attributes" are just a different way to say "discardable attributes" I believe. The API you mention don't exist, it is called
setDiscardableAttrs()
in the codebase.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.
@matthias-springer : that's an interesting idea, but note that this wouldn't work with most passes which don't use the greedy driver.
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.
It wouldn't work with any upstream MLIR passes. This can only be done in a downstream pass. E.g., there's no way to inject attribute conversion rules into the upstream
-canonicalize
pass. (Unless we expose it as a pass option that can only be set from C++ but not from the command line.)Instead, users would write their own canonicalizer pass that has a custom greedy config with these conversion rules.
Interestingly, so far, this issue has only come up with patterns.
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.
FYI, downstream I am working on now unsafely store and load back the attribute in func.call to work around this issue, with the implicit assumption that walk order is unchanged and no call op is inserted/deleted.
https://github.com/google/heir/blob/b2ab9dcaac644ab8131ed06c4767251f46cf02d8/lib/Dialect/LWE/Conversions/LWEToLattigo/LWEToLattigo.cpp#L511-L540
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've seen too many workarounds related to discardable attribute handling. We also have some in our code base. I will discuss this with a few more people and send a prototype+RFC for the attribute converter idea if it works out.
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.
If you do so, please account for the previous RFC and discussions on the topic on Discourse, in particular we had an ODM on the topic: https://discourse.llvm.org/t/odm-tomorrow-2-4-discuss-the-role-of-dialect-attributes-merging-and-propagation/2725