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: (riscv) remove Register class #1281
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1281 +/- ##
==========================================
- Coverage 89.50% 89.50% -0.01%
==========================================
Files 184 184
Lines 24270 24250 -20
Branches 3682 3676 -6
==========================================
- Hits 21722 21704 -18
+ Misses 1967 1966 -1
+ Partials 581 580 -1
☔ View full report in Codecov by Sentry. |
xdsl/dialects/riscv.py
Outdated
immediate: AnyIntegerAttr | LabelAttr = attr_def(AnyIntegerAttr | LabelAttr) | ||
|
||
def __init__( | ||
self, | ||
immediate: int | AnyIntegerAttr | str | LabelAttr, | ||
*, | ||
rd: RegisterType | Register | None = None, | ||
rd: RegisterAttr | str | None = None, |
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.
Use of str
may lost errors that can catch by type checkers in previous implementation. Can you revert it?
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 still don't see the benefit of the type checking here.
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 a client wants to give a bogus string then so be it, I don't see the problem. Almost all the time they're expected to use one of the RegisterAttr
instances in Registers
or None. I'd rather remove str
than add back Register
TBH, but I also don't see it as a serious potential risk.
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.
BTW this is pretty much equivalent to allowing int instead of an IntegerAttr, there can be type mismatches, but we allow it for convenience's sake
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 don't think so. At least IntegerAttr
has a verifier.
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.
So does this class
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 went over the codebase and the one location where this matters is xdsl/transforms/lower_riscv_func.py
:
ops.append(
riscv.MVOp(
arg,
- rd=riscv.Register(f"a{i}"),
+ rd=f"a{i}",
)
)
as well as similar changes in this very same file. Looking into the implementation of Register, I see that Register also did not verify the name of the Register that was passed in its initializer. Hence, the current change seems to just implement what was already there. If there is a more typesafe way to write lower_riscv_func.py
, we could explore that in the future, but I would suggest to remain permissive for now. In the spirit of reducing feature-creep in our PRs, maybe lets get this one in and then get the custom printing in next?
xdsl/dialects/riscv.py
Outdated
@@ -550,15 +531,15 @@ def __init__( | |||
self, | |||
immediate: int | AnyIntegerAttr | str | LabelAttr, | |||
*, | |||
rd: RegisterType | Register | None = None, | |||
rd: RegisterAttr | str | None = None, |
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.
Same as here.
xdsl/dialects/riscv.py
Outdated
@@ -636,7 +617,7 @@ def __init__( | |||
rs1: Operation | SSAValue, | |||
immediate: int | AnyIntegerAttr | str | LabelAttr, | |||
*, | |||
rd: RegisterType | Register | None = None, | |||
rd: RegisterAttr | str | None = None, |
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.
See above
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 like this better:
unallocated
is exposed in the API and the internal representation can be anything- it's shorter to instantiate
- and more intuitive, since the type is an 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.
LGTM overall, just not sure the name change from type to attr is necessary?
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
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.
At least IntergerAttr
has a verifier.
@superlopuh @kingiler and all, this looks very nice. I did a round of reviews and hope these help us to move forward with this patch (without sacrificing code quality). |
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.
This LGTM. @superlopuh could you address my comments if that feels right to you and @kingiler could you check if after the comments have been addressed this PR is good-to-go?
@kingiler I've addressed all the comments, would be good to merge this soon. Are there any other changes that you think I should make before merging? |
LGTM |
Thank you all. |
1 similar comment
Thank you all. |
When I initially wrote the register types, the reasoning in my mind was that I wanted an optional register name, and
Data
cannot accept an optional generic parameter. But actually an empty string seems more appropriate than None anyway. Now that we have floats in riscv, and some duplication, it feels like a good idea to simplify. This also includes a rename of RegisterType to RegisterAttr, since we don't exclusively use them as types.After some discussions with @kingiler on the changes in #1269, I thought I'd play around with the code to see how to make the generics work for both Register/FloatRegister and RegisterType/FloatRegisterType. There were always some issues with it locally, and quite a lot of complexity due to the extra step of indirection. This is what led me to the changes in this PR, which I propose as an alternative to #1269. It's probably a good idea for reviewers to take a look at both to have a better view of multiple potential ways forward.