-
Notifications
You must be signed in to change notification settings - Fork 73
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
backend: (riscv) add tied operands/results to register allocation #2887
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2887 +/- ##
==========================================
+ Coverage 89.85% 89.89% +0.03%
==========================================
Files 399 402 +3
Lines 50171 50459 +288
Branches 7755 7785 +30
==========================================
+ Hits 45083 45360 +277
- Misses 3860 3865 +5
- Partials 1228 1234 +6 ☔ View full report in Codecov by Sentry. |
class TestOp4(Generic[RD1InvT, RD2InvT, RS1InvT, RS2InvT], RISCVInstruction, ABC): | ||
|
||
rd1: OpResult = result_def(RD1InvT) | ||
rd2: OpResult = result_def(RD2InvT) | ||
rs1: Operand = operand_def(RS1InvT) | ||
rs2: Operand = operand_def(RS2InvT) | ||
|
||
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]: | ||
return self.rd1, self.rd2, self.rs1, self.rs2 |
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 was thinking you were going to do something a bit more like this:
class TestOp4(Generic[RD1InvT, RD2InvT, RS1InvT, RS2InvT], RISCVInstruction, ABC): | |
rd1: OpResult = result_def(RD1InvT) | |
rd2: OpResult = result_def(RD2InvT) | |
rs1: Operand = operand_def(RS1InvT) | |
rs2: Operand = operand_def(RS2InvT) | |
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]: | |
return self.rd1, self.rd2, self.rs1, self.rs2 | |
class TestOp4(Generic[RdRsInvT, RD2InvT, RS2InvT], RISCVInstruction, ABC): | |
SameIntRegisterType: TypeAlias = Annotated[RdRsInvT, ConstraintVar("RdRs")] | |
rd1: OpResult = result_def(SameIntRegisterType) | |
rd2: OpResult = result_def(RD2InvT) | |
rs1: Operand = operand_def(SameIntRegisterType) | |
rs2: Operand = operand_def(RS2InvT) | |
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]: | |
return self.rd1, self.rd2, self.rs1, self.rs2 |
So embedding in IRDL the fact that it's the same variable, as opposed to constraining the generic parameter itself.
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.
Much nicer! In this case tho I'm instantiating the generic class with different tie constraints for testing reasons, your suggestion would be 100% error proof when defining real world operations.
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 might be interesting to split this in two, to first add the constraint logic and use it in our current loop allocation code (to constrain that the iter args, block args, and results are in the same registers) and then to use it for operations with same register constraints like in this PR
This PR adds just the bare logic and a a handful of fictional ops just for testing purposes. I think trying to apply it to loops allocation first would be a strong stress test before having the whole thing merged. Trying it out on a stacked branch! |
What's the plan for this? Did we merge the equivalent logic or does this branch go further than what we came up with in Zurich? |
I think that all we need has been merged already, happy to close this! |
Fantastico |
This PR adds the concept of tied operands found in LLVM to be able to model 2-address instructions, a.k.a. when an operand register is both read and written in-place by an instruction. Both the operand and the result must be represented in their own SSA values, but the regalloc must allocate both on the same register to be able to generate correct code.
Keeping as draft for feedback, things that I would like to change:
TiedConstraint
instead of a genericConstraintVar("T")
The code that collects all operands/results definitions that share the sameConstraintVar
is a mess, to be cleaned up.