-
Notifications
You must be signed in to change notification settings - Fork 317
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
[RFC] [Comb][Canonicalize] Best effort dialect attribute propagation #6768
Conversation
How do we know the dialect attributes' intended semantics are valid across the transformation? Looks like in this PR the proposed answer is "if it's the same operation name, it's probably fine"? I appreciate that dropping them may be problematic but I also really don't think we should be preserving attributes we don't know are safe to be preserved. While we could spin up some sort of, e.g., dialect interface to answer "should this be preserved" offhand I'm not sure that's reasonable to do generically -- "does my transformation preserve your attribute meaning?" and as such only makes sense for the subset of dialect attributes that question can be simply answered for "yes if operations are the same". If you're folding two operations, do you merge the attributes? Which do you take? So on. Looking through the linked discussion, I disagree that we're obligated to use heuristics to propagate these -- there's a reason the MLIR core infrastructure doesn't do this. Is there a solution that helps your use case specifically without encoding this sort of assumption about the nature/purpose/meaning of dialect attributes generally? |
Unfortunately we don't unless they were defined within CIRCT.
That is the current naive implementation, yes. Of cause this is highly transformation and attribute specific, but if we want to follow a best effort approach to propagate attributes then we always need to make assumptions at some point to define our "best effort".
Do you have a particular example where propagation of custom (non-CIRCT) dialect attributes is possible without certain assumptions/heuristics?
The only thing that currently comes to my mind would be some sort of whitelisting approach for specific attribute names. However, this would create new questions, for example:
|
I agree with Will's points. This has been discussed on MLIR forums several times and I think basically we cannot safely propagate unknown attributes. https://discourse.llvm.org/t/canonicalization-passes-dont-keep-attributes/59750/2?u=uenoku One thing you could try is to attach an operation to retain your custom attributes before canonicalizations and pull back after canonicalizations, e.g:
This approach is quite similar to what Debug dialect is preserving original signal names. Or another approach might be to introduce a dialect interface to create an allow-list for attributes that can be propagated, and users can dynamically configure them while the dialect registration. |
Yes, I have thought about that solution as well and was wondering to which degree it would inhibit optimizations. Maybe this can be mitigated by adding canonicalizations to
Thanks for the hint. I will take a look at it, specifically regarding optimizations. |
Attaching operations would affect DCE, so you may need to run another DCE(probably you can use |
You cannot safely propagate unknown attributes. |
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.
Cannot be done safely and has been discussed many times over the course of the past couple years.
https://discourse.llvm.org/t/on-querying-an-operations-intrinsic-core-vs-external-user-defined-attributes/4498/5
Thanks for the feedback! I will close this PR and the corresponding issue for now. |
Addresses #6767.
This is a first draft how a less conservative dialect attribute propagation could be implemented.
I checked the uses of
replaceOpWithNewOpAndCopyName
and found one candidate where I would personally not propagate the dialect attributes:circt/lib/Dialect/Comb/CombFolds.cpp
Lines 1685 to 1689 in c403838
It should be possible to opt-out of the implicit attribute propagation by explicitly using
Operation*
as second template parameter:Alternatively, the implementation may be changed to add a boolean template parameter to explicitly opt-in/out of the attribute propagation.