-
Notifications
You must be signed in to change notification settings - Fork 74
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
dialects: (llvm) Registering llvm.icmp #3356
Conversation
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.
Otherwise, this looks great to me. Maybe @superlopuh and @luisacicolini have comments?
I'm getting this error
Since the predicate is supposed to be an i64 (according to |
xdsl/dialects/llvm.py
Outdated
if i == 0: | ||
return ICmpPredicateFlag.EQ | ||
elif i == 1: | ||
return ICmpPredicateFlag.NE | ||
elif i == 2: | ||
return ICmpPredicateFlag.SLT | ||
elif i == 3: | ||
return ICmpPredicateFlag.SLE | ||
elif i == 4: | ||
return ICmpPredicateFlag.SGE | ||
elif i == 5: | ||
return ICmpPredicateFlag.SGT | ||
elif i == 6: | ||
return ICmpPredicateFlag.ULT | ||
elif i == 7: | ||
return ICmpPredicateFlag.ULE | ||
elif i == 8: | ||
return ICmpPredicateFlag.UGE | ||
elif i == 9: | ||
return ICmpPredicateFlag.UGT |
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.
There has to be a better way of doing this, I'd expect some helper to exist in the Python enum implementation, otherwise we should cache this mapping.
This PR adds an operation and an attribute, and only registers the new op in the dialect. |
I don't get why I'm getting this error with the current def of |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3356 +/- ##
==========================================
+ Coverage 90.10% 90.12% +0.01%
==========================================
Files 449 449
Lines 56599 56693 +94
Branches 5429 5434 +5
==========================================
+ Hits 51001 51092 +91
- Misses 4164 4166 +2
- Partials 1434 1435 +1 ☔ View full report in Codecov by Sentry. |
@superlopuh |
xdsl/dialects/llvm.py
Outdated
lhs = operand_def(T) | ||
rhs = operand_def(T) | ||
res = result_def(T) | ||
predicate = prop_def(Attribute) |
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.
why this change? it was better before as a strenum, no?
I would recommend reverting your last change, and looking into how to index the enum cases |
This seems to work |
and is not O(number of cases) |
@superlopuh do you have any idea on how to fix the current error? |
Co-authored-by: Sasha Lopoukhine <[email protected]>
Ah no, it looks like I was too quick to approve. I would recommend marking the PR as draft if the tests don't pass, and reaching out on Zulip to iterate |
I've actually never used this part of the API before, I'm happy to take a look in a bit if you're stuck, but it would be worth messaging on Zulip in case someone with more experience with your issue knows the answer directly. In this case pinging @alexarice would probably be a good idea, I think he's dealt with these attributes somewhat recently. |
xdsl/dialects/llvm.py
Outdated
|
||
|
||
@irdl_attr_definition | ||
class ICmpPredicateAttr(EnumAttribute[ICmpPredicateFlag]): |
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 believe you want OpaqueSyntaxAttribute
or SpacedOpaqueSyntaxAttribute
here to get it to print properly
xdsl/dialects/llvm.py
Outdated
|
||
|
||
@irdl_op_definition | ||
class ICmpOp(IRDLOperation, ABC): |
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.
Why is this marked as an abstract class?
xdsl/dialects/llvm.py
Outdated
self.predicate.print_parameter(printer) | ||
|
||
def print(self, printer: Printer): | ||
printer.print(' "') |
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 in general, print_string is preferred to print but this is a super nit
@alexarice Thank you for the suggestions, that worked @superlopuh are we good to merge then? |
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 just tested the mlir version and it does this:
bin/mlir-opt ../../test.mlir --mlir-print-op-generic
"builtin.module"() ({
%0:2 = "test.op"() : () -> (i32, i32)
%1 = "llvm.icmp"(%0#0, %0#1) <{predicate = 0 : i64}> : (i32, i32) -> i1
}) : () -> ()
I feel the generic output of your function is not the same. Unsure if this is a blocker but I just wanted to point it 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.
LGTM! The issue Alex pointed out is worth looking into, but I don't want to block on that necessarily. It would be great if you could take a quick look at the generic syntax before merging, and comment here.
Let's merge this for now. @lfrenot, can you still check @alexarice's comment. |
@lfrenot, we should indeed be consistent with MLIR here. I just tried to use your icmp implementation to parse our test cases, but it failed as MLIR emits an integer attribute and you added your own attribute type. It would be great if this could be fixed. |
Co-authored-by: Sasha Lopoukhine <[email protected]>
No description provided.