-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[wasm] p/invoke and interop improvements #94446
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
6dd24f7
Checkpoint
kg 86b5cdd
Repair merge damage
kg a355079
Merge branch 'main' into pinvoke-srm-1
lewing 13157f3
Run M2NG in-process again
kg 11c3d7a
Our current approach to SystemNative_SNPrintF is incorrect on some ar…
kg 0d413b2
Support initonly fields in blittable structs in PInvokeTableGenerator…
kg a46ddd9
Merge remote-tracking branch 'upstream/main' into pinvoke-srm-1
kg 51274ed
Work around our rampant use of warnaserror
kg bf9439d
Revert most csproj changes
kg 6f49b91
Better solution for warnaserror (probably)
kg c25be75
Restore old EnumCalendarInfo since we're in-process again
kg 65275b6
Revert fn ptr test changes
kg f47f8ea
Maybe fix blazor WBTs
kg 835e278
Make LogAdapter Info high priority so it appears in failed build logs
kg d8ac1a9
Hack to make skiasharp build
kg f40b16a
Merge remote-tracking branch 'upstream/main' into pinvoke-srm-1
kg 3039f55
Implement wasm abi struct scalar rules in interp again
kg e92b95d
Add test coverage for i64 pinvokes + add fixme comments
kg 2964b73
Fix scalar int64 structs
kg ce56e66
Code cleanup
kg 037df97
Formatting
kg 0dda91a
Checkpoint (reverse out-of-process)
kg 8f869e2
Checkpoint
kg 36dc365
Merge branch 'main' into pinvoke-srm-1
radical 77104b3
Merge remote-tracking branch 'upstream/main' into pinvoke-srm-1
kg 9abbf32
Fix Vector64 AOT test failures (calling convention was incorrect when…
kg e9667c7
Merge remote-tracking branch 'upstream/main' into pinvoke-srm-1
kg 8548fbf
Ensure we get MLC 8.0 in WasmAppBuilder
kg 36dc34a
Update tests since function pointers work now
kg 7466463
Attempt to resolve prebuilts/source build CI failure by adding (missi…
kg d15f07a
Merge remote-tracking branch 'upstream/main' into pinvoke-srm-1
kg 19cd8b3
Merge remote-tracking branch 'upstream/main' into pinvoke-srm-1
kg c6a809a
Merge remote-tracking branch 'upstream/main' into pinvoke-srm-1
kg 47478c5
Merge remote-tracking branch 'upstream/main' into pinvoke-srm-1
kg 2a57464
Merge remote-tracking branch 'upstream/main' into pinvoke-srm-1
kg b1e64a0
Address PR feedback
kg 1ba9222
Repair merge damage
kg 5f75189
Merge branch 'main' into pinvoke-srm-1
lewing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4192,6 +4192,7 @@ emit_entry_bb (EmitContext *ctx, LLVMBuilderRef builder) | |
case LLVMArgVtypeAddr: | ||
case LLVMArgVtypeByRef: | ||
case LLVMArgAsFpArgs: | ||
case LLVMArgWasmVtypeAsScalar: | ||
{ | ||
MonoClass *klass = mono_class_from_mono_type_internal (ainfo->type); | ||
if (mini_class_is_simd (ctx->cfg, klass)) { | ||
|
@@ -4968,6 +4969,8 @@ process_call (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder_ref, | |
if (!addresses [call->inst.dreg]) | ||
addresses [call->inst.dreg] = build_alloca_address (ctx, sig->ret); | ||
emit_store (builder, lcall, convert_full (ctx, addresses [call->inst.dreg]->value, pointer_type (LLVMTypeOf (lcall)), FALSE), is_volatile); | ||
load_name = "wasm_vtype_as_scalar"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be WASM only? |
||
should_promote_to_value = TRUE; | ||
break; | ||
} | ||
default: | ||
|
@@ -5421,6 +5424,7 @@ static LLVMValueRef | |
concatenate_vectors (EmitContext *ctx, LLVMValueRef xs, LLVMValueRef ys) | ||
{ | ||
LLVMTypeRef t = LLVMTypeOf (xs); | ||
g_assert (LLVMGetTypeKind (t) == LLVMVectorTypeKind); | ||
unsigned int elems = LLVMGetVectorSize (t) * 2; | ||
int mask [MAX_VECTOR_ELEMS] = { 0 }; | ||
for (guint i = 0; i < elems; ++i) | ||
|
@@ -6175,8 +6179,13 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb) | |
} | ||
break; | ||
case LLVMArgWasmVtypeAsScalar: | ||
g_assert (addresses [ins->sreg1]); | ||
retval = LLVMBuildLoad2 (builder, ret_type, build_ptr_cast (builder, addresses [ins->sreg1]->value, pointer_type (ret_type)), ""); | ||
if (!addresses [ins->sreg1]) { | ||
/* SIMD value */ | ||
g_assert (lhs); | ||
retval = LLVMBuildBitCast (builder, lhs, ret_type, ""); | ||
} else { | ||
retval = LLVMBuildLoad2 (builder, ret_type, build_ptr_cast (builder, addresses [ins->sreg1]->value, pointer_type (ret_type)), ""); | ||
} | ||
break; | ||
} | ||
LLVMBuildRet (builder, retval); | ||
|
@@ -6225,8 +6234,8 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb) | |
|
||
if (lhs) { | ||
// Vector3: ret_type is Vector3, lhs is Vector3 represented as a Vector4 (three elements + zero). We need to extract only the first 3 elements from lhs. | ||
int len = mono_class_value_size (klass, NULL) == 12 ? 3 : LLVMGetVectorSize (LLVMTypeOf (lhs)); | ||
int len = mono_class_value_size (klass, NULL) == 12 ? 3 : LLVMGetVectorSize (LLVMTypeOf (lhs)); | ||
|
||
for (int i = 0; i < len; i++) { | ||
elem = LLVMBuildExtractElement (builder, lhs, const_int32 (i), "extract_elem"); | ||
retval = LLVMBuildInsertValue (builder, retval, elem, i, "insert_val_struct"); | ||
|
@@ -6841,7 +6850,7 @@ MONO_RESTORE_WARNING | |
// LLVM should fuse the individual Div and Rem instructions into one DIV/IDIV on x86 | ||
values [ins->dreg] = LLVMBuildTrunc (builder, LLVMBuildSDiv (builder, dividend, divisor, ""), part_type, ""); | ||
last_divrem = LLVMBuildTrunc (builder, LLVMBuildSRem (builder, dividend, divisor, ""), part_type, ""); | ||
break; | ||
break; | ||
} | ||
case OP_X86_IDIVREMU: | ||
case OP_X86_LDIVREMU: { | ||
|
@@ -6856,7 +6865,7 @@ MONO_RESTORE_WARNING | |
LLVMValueRef divisor = LLVMBuildZExt (builder, convert (ctx, arg3, part_type), full_type, ""); | ||
values [ins->dreg] = LLVMBuildTrunc (builder, LLVMBuildUDiv (builder, dividend, divisor, ""), part_type, ""); | ||
last_divrem = LLVMBuildTrunc (builder, LLVMBuildURem (builder, dividend, divisor, ""), part_type, ""); | ||
break; | ||
break; | ||
} | ||
case OP_X86_IDIVREM2: | ||
case OP_X86_LDIVREM2: { | ||
|
@@ -10671,7 +10680,7 @@ MONO_RESTORE_WARNING | |
|
||
// convert to 0/1 | ||
result = LLVMBuildICmp (builder, LLVMIntEQ, first_elem, LLVMConstAllOnes (LLVMInt64Type ()), ""); | ||
|
||
values [ins->dreg] = LLVMBuildZExt (builder, result, LLVMInt8Type (), ""); | ||
break; | ||
} | ||
|
@@ -12020,7 +12029,7 @@ MONO_RESTORE_WARNING | |
gboolean scalar = ins->opcode == OP_NEGATION_SCALAR; | ||
gboolean is_float = (ins->inst_c1 == MONO_TYPE_R4 || ins->inst_c1 == MONO_TYPE_R8); | ||
|
||
LLVMValueRef result = lhs; | ||
LLVMValueRef result = lhs; | ||
if (scalar) | ||
result = scalar_from_vector (ctx, result); | ||
if (is_float) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Based on the comment above, this toolset version should not be updated without coordination with msbuild and sdk repos.
@ViktorHofer, FYI, this is blocking the codeflow dotnet/sdk#38665 (while previous change made it to the next phases without problems dotnet/sdk#38553). We can either revert this or update https://github.com/dotnet/sdk/blob/b32df9afff77e8f1afbd417e7c70841867cb6cdc/src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj#L75 to 8.0 (if we choose the latter, we can close #96809).
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 coordinated with people from the msbuild team at multiple points while developing this along with the SBRP team, so I'm sorry that something fell through the cracks here. Is there a specific step we missed?
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 see now from looking through the replies to Larry's comment on this issue that you told us there. For some reason, GitHub did not send me a notification for your comment, so I didn't see it :( I guess in the future blocking issues like that need to be PR comments instead of replies.
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.
My preference would definitely be to take the bump in the sdk. VS 17.9 is where these changes will ship and it has taken the update.
cc @ViktorHofer @marcpopMSFT
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.
NP, #96809 is tracking it, but it seems (almost) resolved by your PR. Once confirmed, we can just update sdk's Microsoft.NET.Build.Tasks.csproj#L74-L76 to 8.0 (now that all the related toolings are using 8.0; msbuild, HostModel and VS).
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 for this to work, sdk would need to upgrade its .NET Framework leg to a VS 17.9 Preview image (for the updated msbuild binding redirects that allow to unify to an 8.0.0.0 assembly version). I'm not sure if such an image is already available. Worst case, we would need to revert this dependency bump here. @lewing can you please make sure that this dependency flow issue gets resolved: dotnet/sdk#38665?
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.
Correct me if I'm wrong but the sdk build should be fine, it'd just need the testing legs to use VS17.9 Preview right? That should already be the case: https://github.com/dotnet/sdk/blob/0962c1f89f5daf924a9fe876c80e80b0bde63b0d/.vsts-ci.yml#L108-L111
I'll try bumping the .csproj in the sdk PR and see what happens.
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.
Correct. Binding redirect unification at run time.
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.
Looks like it worked :)