-
Notifications
You must be signed in to change notification settings - Fork 71
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) Add HasInsntrait and implement trait for some operations #2784
Conversation
fae90af
to
7f28655
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2784 +/- ##
==========================================
- Coverage 89.80% 89.79% -0.01%
==========================================
Files 381 388 +7
Lines 48226 48548 +322
Branches 7377 7445 +68
==========================================
+ Hits 43308 43595 +287
- Misses 3765 3785 +20
- Partials 1153 1168 +15 ☔ View full report in Codecov by Sentry. |
If these functions are still implemented as risc-v ops, does that not undo the progress of pr #2784 ? As these ops operate on riscv-register operands in comparison to just i32 or index variables, we will have to do an |
I think you linked to the wrong PR here.
I don't know if I can quite follow. The riscv backend of @superlopuh is already able to convert
Because snrt dialect ops map to multiple individual instructions, making it impractical to carry this information imo. With this plan we gain both:
|
xdsl/dialects/riscv_snitch.py
Outdated
@@ -462,6 +463,8 @@ class DMSourceOp(IRDLOperation, RISCVInstruction): | |||
ptrlo = operand_def(riscv.IntRegisterType) | |||
ptrhi = operand_def(riscv.IntRegisterType) | |||
|
|||
traits = frozenset([StaticInsnsRepresentation(".insn r 0x2b, 0, 0, x0, {0}, {1}")]) |
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.
What would be the best way to test this?
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 have tested this in verilator simulations, and once this is in we can convert the tests in ci to use this system over at snax-mlir
.
Without simulations, I'm not sure.
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.
Here a pytest test that checks that these operations have the exact string you would expect would be good, just to make sure that something in the formatting infrastructure doesn't break, for example
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.
Okay, here again I wast just a bit worried about the unrealized conversian cast resolution
Co-authored-by: Joren Dumoulin <[email protected]>
Co-authored-by: Joren Dumoulin <[email protected]>
Co-authored-by: Joren Dumoulin <[email protected]>
tests/dialects/test_riscv_snitch.py
Outdated
def test_insn_repr(op: RISCVInstruction): | ||
trait = op.get_trait(HasInsnRepresentation) | ||
assert trait is not None | ||
assert trait.get_insn(op) == ground_truth[op.name[13:]] |
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.
Pyright complains that: Method "get_insn" cannot be called because it is abstract and unimplemented (reportGeneralTypeIssues)
But get_insn
is an abstract method on HasInsnRepresentation
, which itself is ABC, so I can never get it "not implemented" as I will always get a subclass of this trait (that by definition has to implement the method). How the heck am I supposed to fix this? @superlopuh @math-fehr
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's because the get_insn
type parameter is invariant, meaning it says that it returns only instances of this type exactly, not subclasses. I think we want the covariant version instead.
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.
Turns out I was wrong, it was indeed a Pyright bug
In order to make progress on #2468 I factored out the insn representation. This will hopefully also make it usable for the RISC-V backend efforts.