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

[LoongArch64] JIT/EE interface for getting ABI-info #62893

Merged
merged 29 commits into from
Feb 18, 2022
Merged

[LoongArch64] JIT/EE interface for getting ABI-info #62893

merged 29 commits into from
Feb 18, 2022

Conversation

shushanhf
Copy link
Contributor

add ToolBox directory about jitinterace for getting ABI-info.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Dec 16, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed community-contribution Indicates that the PR has been added by a community member labels Dec 16, 2021
@ghost
Copy link

ghost commented Dec 16, 2021

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

Issue Details

add ToolBox directory about jitinterace for getting ABI-info.

Author: shushanhf
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@shushanhf shushanhf changed the title add ToolBox directory about jitinterace for getting ABI-info [LoongArch64] add ToolBox directory about jitinterace for getting ABI-info Dec 16, 2021
@jkotas jkotas changed the title [LoongArch64] add ToolBox directory about jitinterace for getting ABI-info [LoongArch64] jit/EE interace for getting ABI-info Dec 16, 2021
@jkotas jkotas changed the title [LoongArch64] jit/EE interace for getting ABI-info [LoongArch64] JIT/EE interace for getting ABI-info Dec 16, 2021
@jkotas
Copy link
Member

jkotas commented Dec 17, 2021

Could you please add links to the LoongArch64 calling convention spec to https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/clr-abi.md as part of this PR?

@shushanhf
Copy link
Contributor Author

Could you please add links to the LoongArch64 calling convention spec to https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/clr-abi.md as part of this PR?

OK.
I will upload a new patch for it.

@jkotas
Copy link
Member

jkotas commented Dec 17, 2021

Is there a spec that describes passing of non-primitive types (e..g struct with multiple fields that the new JIT/EE interface methods are dealing with)? https://github.com/loongson/LoongArch-Documentation/blob/main/docs/LoongArch-ELF-ABI-EN.adoc does not seem to be cover it.

@shushanhf
Copy link
Contributor Author

Is there a spec that describes passing of non-primitive types (e..g struct with multiple fields that the new JIT/EE interface methods are dealing with)? https://github.com/loongson/LoongArch-Documentation/blob/main/docs/LoongArch-ELF-ABI-EN.adoc does not seem to be cover it.

Sorry for late reponse.
Yes, the english version is a brief version.
As I know the struct passed way is the same with the RISC-V.

Later, I will find or ask where is the full version of the english ABI-spec.

Thanks~

@jkotas
Copy link
Member

jkotas commented Dec 18, 2021

As I know the struct passed way is the same with the RISC-V.

According to https://riscv.org/wp-content/uploads/2015/01/riscv-calling.pdf, the rules for RISC-V are:

  • Structs with size > 2*pointer_size are passed by reference
  • Structs with size <= 2*pointer_size are passed in registers
    • Structs that contain floating point values are passed in floating point registers as long as they are smaller than 2*pointer_size. It extended version of HFAs, even float and double combinations are passed in floating point registers.

If the rules are as simple as this, then I think the JIT/EE interface change can be simplified a lot. I think it can be just a single flag that says whether the struct is passed in floating point registers. It should be possible to infer the rest through existing APIs. Thoughts?

@shushanhf
Copy link
Contributor Author

shushanhf commented Dec 18, 2021

As I know the struct passed way is the same with the RISC-V.

According to https://riscv.org/wp-content/uploads/2015/01/riscv-calling.pdf, the rules for RISC-V are:

  • Structs with size > 2*pointer_size are passed by reference

  • Structs with size <= 2*pointer_size are passed in registers

    • Structs that contain floating point values are passed in floating point registers as long as they are smaller than 2*pointer_size. It extended version of HFAs, even float and double combinations are passed in floating point registers.

If the rules are as simple as this, then I think the JIT/EE interface change can be simplified a lot. I think it can be just a single flag that says whether the struct is passed in floating point registers. It should be possible to infer the rest through existing APIs. Thoughts?

yes, but there are a lot of details.
struct {float a; double b;} is the simplist.
struct {float a; float b;} is passed by two float registers.
struct {float a; float b; float c;} should be passed by integer register while the size<2*8 is not enough.
struct{ struct {float a; float b}; float c} is not passed by float-register.
For the struct {float a; long b} and struct {char a; double b;} , the offset of the float field should be consider.

}
else if (fieldType == ELEMENT_TYPE_VALUETYPE)
{
pMethodTable = pFieldStart->LookupApproxFieldTypeHandle().GetMethodTable();
Copy link
Member

Choose a reason for hiding this comment

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

LookupApproxFieldTypeHandle can return null. Is there anything that guarantees it won't return null in this case?

Should this rather use GetFieldTypeHandleThrowing that will load the types as necessary and never return null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.
You are right.
In fact, we had updated it by using a if (pMethodTable) and it works ok.

Copy link
Member

Choose a reason for hiding this comment

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

In fact, we had updated it by using a if (pMethodTable) and it works ok.

That's not a correct fix. LookupApproxFieldTypeHandle will return null when the type was not loaded before. Using LookupApproxFieldTypeHandle will lead to non-deterministic behavior - the behavior will depend on whether something else in the program happened to load the type or not.

You should change this code to call GetFieldTypeHandleThrowing.

Copy link
Contributor Author

@shushanhf shushanhf Feb 15, 2022

Choose a reason for hiding this comment

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

In fact, we had updated it by using a if (pMethodTable) and it works ok.

Yes, this is only a workround way.

That's not a correct fix. LookupApproxFieldTypeHandle will return null when the type was not loaded before. Using LookupApproxFieldTypeHandle will lead to non-deterministic behavior - the behavior will depend on whether something else in the program happened to load the type or not.

You should change this code to call GetFieldTypeHandleThrowing.

Thanks a lot !!!
I will update it.

@jkotas
Copy link
Member

jkotas commented Feb 14, 2022

@jkotas Do you have further comments on the changes in jitinterface.cpp

The general shape looks fine to me. I have left some additional comments.

@shushanhf
Copy link
Contributor Author

Hi, @jkotas
I have another question, the funciton getLoongArch64PassStructInRegisterFlags() within the file src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs is unimplement.
Now I implement it but there is a problem for the case of TypeFlags.Class that needs your help.

Should I create a new PR for adding getLoongArch64PassStructInRegisterFlags() ?

@jkotas
Copy link
Member

jkotas commented Feb 15, 2022

getLoongArch64PassStructInRegisterFlags() within the file src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs is unimplement.

The implementation should be part of this PR.

@shushanhf
Copy link
Contributor Author

getLoongArch64PassStructInRegisterFlags() within the file src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs is unimplement.

The implementation should be part of this PR.

OK, I will upload it later.

Copy link
Contributor Author

@shushanhf shushanhf left a comment

Choose a reason for hiding this comment

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

The runtime and SDK for LoongArch64 are based on the 6.0.102 while the sdk-LoongArch64 was made by ourself.

This reverts commit b05a2b9.

The crossgen2 for LoongArch64 will be submitted by a new PR.
@BruceForstall
Copy link
Member

@shushanhf Are there are changes you plan to make in this PR?

We're waiting for this one to be complete, and be merged, before reviewing #62885

@shushanhf
Copy link
Contributor Author

shushanhf commented Feb 18, 2022

@shushanhf Are there are changes you plan to make in this PR?

Hi, @BruceForstall
I had finished for this PR.
The crossgen2 for LA64 will be submitted by a new PR later which waiting the CI's SDK supporting LoongArch64 compiling.

Thanks.

We're waiting for this one to be complete, and be merged, before reviewing #62885

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

I left a couple minor comments.

Plus: you need to change the JIT/EE version in https://github.com/dotnet/runtime/blob/main/src/coreclr/inc/jiteeversionguid.h, since you've changed the interface.

src/coreclr/vm/jitinterface.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/jitinterface.cpp Outdated Show resolved Hide resolved
@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 18, 2022
@BruceForstall
Copy link
Member

@jkotas Do you have any final comments/requests before this gets merged?

@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 18, 2022
@shushanhf
Copy link
Contributor Author

I left a couple minor comments.

Plus: you need to change the JIT/EE version in https://github.com/dotnet/runtime/blob/main/src/coreclr/inc/jiteeversionguid.h, since you've changed the interface.

@BruceForstall
Can use the uuidgen command within the linux for generating the UUID ?

@jkotas
Copy link
Member

jkotas commented Feb 18, 2022

@jkotas Do you have any final comments/requests before this gets merged?

Added a few nits. LGTM otherwise.

qiaopengcheng added 2 commits February 18, 2022 13:17
Also delete some unused comments.
Conflicts:
	src/coreclr/inc/jiteeversionguid.h
@BruceForstall
Copy link
Member

@BruceForstall
Can use the uuidgen command within the linux for generating the UUID ?

Hmmm, probably not, but it looks like you figured out how to get a new GUID (or just chose one randomly).

@BruceForstall BruceForstall merged commit 90b7be3 into dotnet:main Feb 18, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Mar 20, 2022
@shushanhf shushanhf deleted the main_loongarch64_3a branch May 11, 2022 01:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-loongarch64 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