-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Implement Swift's physical lowering pass in the managed type system #98831
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
Conversation
Implement Swift's physical lowering pass by re-using the interval traversal algorithm used in the explicit layout validator. This does not hook it up to the JIT interface yet.
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsImplement Swift's physical lowering pass by re-using the interval traversal algorithm used in the explicit layout validator. This does not hook it up to the JIT interface yet. For the JIT interface API, I was thinking something like: This function would return
|
|
src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/SwiftPhysicalLowering.cs
Outdated
Show resolved
Hide resolved
…t we have a shape the JIT team likes.
|
I hit an assert in the lowering for this type: struct F5_S1_S0
{
public short F0;
}
struct F5_S1
{
public ulong F0;
public long F1;
public F5_S1_S0 F2;
public long F3;
}(https://github.com/dotnet/runtime/compare/main...jakobbotsch:runtime:swift-abi?expand=1 is a branch based on this PR that hooks up the JIT side and has a bunch of tests. Not sure that the JIT side works yet.) |
src/coreclr/tools/aot/ILCompiler.Compiler.Tests/ILCompiler.Compiler.Tests.Assets/SwiftTypes.cs
Show resolved
Hide resolved
…n't do tail padding for non-arrays).
jakobbotsch
left a comment
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, but you may want to get approval from someone more well-versed in the managed type system.
The support here is also for crossgen2, right? It would be good to update the PR title to reflect that if so.
MichalStrehovsky
left a comment
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.
Only looked at how the type system is used. Not reviewing the lowering logic or the correctness of ExplicitLayoutValidator refactor.
|
|
||
| Debug.Assert(PointerSize == 8, "Swift interop is only supported on 64-bit platforms."); | ||
|
|
||
| if (fieldType.Category is TypeFlags.IntPtr or TypeFlags.UIntPtr || fieldType.IsPointer || fieldType.IsFunctionPointer) |
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 (fieldType.Category is TypeFlags.IntPtr or TypeFlags.UIntPtr || fieldType.IsPointer || fieldType.IsFunctionPointer) | |
| if (fieldType.Category is TypeFlags.IntPtr or TypeFlags.UIntPtr or TypeFlags.Pointer or TypeFlags.FunctionPointer) |
kotlarmilos
left a comment
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! I've left one comment for consideration. How will the JIT use it? Is it possible to share this implementation with the Mono runtime so that there is a unified implementation?
| List<CorInfoType> loweredTypes = visitor.GetLoweredTypeSequence(); | ||
|
|
||
| // If a type has a primitive sequence with more than 4 elements, Swift passes it by reference. | ||
| if (loweredTypes.Count > 4) |
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.
Does it make sense to implement an early check in the GetLoweredTypeSequence and avoid lowering the full sequence if loweredTypes.Count > 4?
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 fine. The number of frozen structs that would surpass the max size and be passed by-reference is likely very small (as if the type is being passed by-ref, it's not getting most of the benefits that being frozen allows).
|
The algorithm lowers struct F2087_S0_S0
{
public double F0;
public float F1;
}
struct F2087_S0
{
public F2087_S0_S0 F0;
public int F1;
public sbyte F2;
}to
|
struct F114_S0
{
public float F0;
public ushort F1;
public short F2;
public ushort F3;
}seems to be lowered to however, Swift seems to lower it to (Feel free to merge the PR and fix these separately. I can open my PR once you do that, which may give you a better way to get access to test cases.) |
The JIT will use this through the EE-JIT interface. We are going to need a separate implementation for CoreCLR (we can't use the managed type system there), so we can try to keep it to two implementations instead of three, but I'm not sure how easy that will be. |
|
@jakobbotsch I found the issue. My implementation of the algorithm wasn't taking into account that we need to match padding of the original struct type. I've adjusted the algorithm and am pushing out a fix. |
|
Timeout is unrelated, merging in. |
Implement Swift's physical lowering pass by re-using the interval traversal algorithm used in the explicit layout validator.
This does not hook it up to the JIT interface yet.
For the JIT interface API, I was thinking something like:
BOOL getSwiftLowering(CORINFO_CLASS_HANDLE clsHnd, uint8_t numLoweredElements, CORINFO_TYPE loweredElements[4]);This function would return
FALSEfor any types that should be passed by ref, and theloweredElementsarray would represent the equivalent primitive sequence (ending withCORINFO_TYPE_EMPTYif there are less than 4 primitives).