Skip to content
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

[RISC-V] New ABI classifiers #101114

Merged
merged 5 commits into from
Apr 17, 2024
Merged

Conversation

tomeksowi
Copy link
Contributor

Implements the RISC-V part of #100744

Part of #84834, cc @dotnet/samsung

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 16, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 16, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jakobbotsch
Copy link
Member

Thanks for this, very happy to see it.
This change should allow you to remove the RISCV version of genHomeRegisterParams and switch to the platform agnostic version in codegencommon.cpp.

@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label Apr 16, 2024
…ist doesn't guarantee no heap allocation in C++11 (only since C++14)
@shushanhf
Copy link
Contributor

shushanhf commented Apr 17, 2024

Thanks for this, very happy to see it. This change should allow you to remove the RISCV version of genHomeRegisterParams and switch to the platform agnostic version in codegencommon.cpp.

I agree with you that we can share the genHomeRegisterParams for different arches.
But we can not optimize by load/store-index instruction at some cases if we use architecture-independent code.

@tomeksowi tomeksowi marked this pull request as ready for review April 17, 2024 06:13
@jakobbotsch
Copy link
Member

But we can not optimize by load/store-index instruction at some cases if we use architecture-independent code.

What is this optimization?

@shushanhf
Copy link
Contributor

shushanhf commented Apr 17, 2024

But we can not optimize by load/store-index instruction at some cases if we use architecture-independent code.

What is this optimization?

As we use emitIns_S_R() to store one by one, if the offset is large offset which out of the store ins's imm encoding range, we have to generate an ins to encode the large offset for each store while we can use the load-index to avoid redundant large offset's ins.
This is the root case making the Prolog size very large and the LoongArch64 had optimized these.

@jakobbotsch
Copy link
Member

As we use emitIns_S_R() to store one by one, if the offset is large offset which out of the store ins's imm encoding range, we have to generate an ins to encode the large offset for each store while we can use the load-index to avoid redundant large offset's ins. This is the root case making the Prolog size very large and the LoongArch64 had optimized these.

What does the codegen look like? Does it set up a temporary register pointing closer to the parameters than FP and store based on this register instead?

Keeping separate version of genHomeRegisterParams means high likelihood of us breaking LA64/RISCV64 in the future. The new version was written partially to support parameters in non-standard registers. PRs like #100823 will break LA64/RISCV64 as long as they have their own version of this function.

@shushanhf
Copy link
Contributor

shushanhf commented Apr 17, 2024

As we use emitIns_S_R() to store one by one, if the offset is large offset which out of the store ins's imm encoding range, we have to generate an ins to encode the large offset for each store while we can use the load-index to avoid redundant large offset's ins. This is the root case making the Prolog size very large and the LoongArch64 had optimized these.

What does the codegen look like? Does it set up a temporary register pointing closer to the parameters than FP and store based on this register instead?

yes, you are right.

Thanks.
I checked and it is not relevant with 100962. As the special offs of emitIns_S_R() is indepent of the offset relative FP.

  • If it is, can we introduce emitIns_StoreParamToStack and LA64/RISCV64 can preface the logic in codegencommon.cpp by setting up the temporary register, and then do its optimization to use that register within emitIns_StoreParamToStack?

Yes, that's a good idea that introducing a new interface to do that.

Keeping separate version of genHomeRegisterParams means high likelihood of us breaking LA64/RISCV64 in the future.

I agree with you for sharing the genHomeRegisterParams.

@jakobbotsch
Copy link
Member

I checked and it is not relevant with 100962.

Are you saying that #100962 doesn't help? I would expect it to make the optimization unimportant because it changes the FP to sit right next to where the parameter locals are allocated on the stack, so the relative offset from the FP is very small now.

As the special offs of emitIns_S_R() is indepent of the offset relative FP.

The offset provided to emitIns_S_R by register homing should be very small, 0 to 8 for structs passed in registers on RISCV64/LA64 if I understand the ABI correctly.


assert((floatFields > 0) || (intFields == 0));

auto PassSlot = [this](bool inFloatReg, unsigned offset, unsigned size) -> ABIPassingSegment {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Most places within the JIT that use lambdas use camelCase naming convention.

No need to address this here.

}
}

unreached();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this do anything? Won't we have a compiler error if this becomes accidentally reachable?

Feel free to remove this separately.

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jakobbotsch jakobbotsch merged commit f930b15 into dotnet:main Apr 17, 2024
108 of 110 checks passed
@shushanhf
Copy link
Contributor

Are you saying that #100962 doesn't help? I would expect it to make the optimization unimportant because it changes the FP to sit right next to where the parameter locals are allocated on the stack, so the relative offset from the FP is very small now.

Yes, from this view, after 100962 the args' position is more near the FP.

jakobbotsch pushed a commit that referenced this pull request Apr 27, 2024
* Code review from #101114

* Use common genHomeRegisterParams on RISC-V

* Make passSlot integer-only because we know hardware floating-point calling convention passes in registers only

* Make a RISC-V specific routine for homing stack parts of split parameters.

* Move genHomeStackPartOfSplitParameter out of genHomeSwiftStructParameters, share stack segment homing with Swift code
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
* Code review from dotnet#101114

* Use common genHomeRegisterParams on RISC-V

* Make passSlot integer-only because we know hardware floating-point calling convention passes in registers only

* Make a RISC-V specific routine for homing stack parts of split parameters.

* Move genHomeStackPartOfSplitParameter out of genHomeSwiftStructParameters, share stack segment homing with Swift code
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
* Code review from dotnet#101114

* Use common genHomeRegisterParams on RISC-V

* Make passSlot integer-only because we know hardware floating-point calling convention passes in registers only

* Make a RISC-V specific routine for homing stack parts of split parameters.

* Move genHomeStackPartOfSplitParameter out of genHomeSwiftStructParameters, share stack segment homing with Swift code
@github-actions github-actions bot locked and limited conversation to collaborators May 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-riscv Related to the RISC-V architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants