Skip to content

Commit b885a58

Browse files
authored
[mono][swift-interop] Support for Swift struct lowering in direct P/Invoke returns (#104389)
* refactor struct lowering in method-to-ir.c * [miniJIT][ARM64] Swift struct lowering in returns * [interp][ARM64] Swift struct lowering in returns Interpreter support for Swift struct lowering in returns on arm64 + LLVM fallback for ArgSwiftError and ArgSwiftVtypeLoweredRet ArgStorage types. * enable SwiftRetAbiStress tests on Mono * [miniJIT][x64] Swift struct lowering in returns * [interp][x64] Swift struct lowering in returns * refactoring arm64/x64 * more refactoring x64 * swift ret buffer: r10 to rax move for VCALL * refactoring of swift ret. buffer handlig and more * change byref of typedref to byref of klass * replace spaces with tabs + formatting * [arm64] move add_return_valuetype_swiftcall out of add_valuetype and add it to get_call_info * [x64] refactor add_return_valuetype_swiftcall
1 parent 916e245 commit b885a58

File tree

7 files changed

+413
-113
lines changed

7 files changed

+413
-113
lines changed

src/mono/mono/mini/method-to-ir.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7547,34 +7547,27 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
75477547
// SwiftSelf, SwiftError, and SwiftIndirectResult are special cases where we need to preserve the class information for the codegen to handle them correctly.
75487548
if (mono_type_is_struct (ptype) && !(klass == swift_self || klass == swift_error || klass == swift_indirect_result)) {
75497549
SwiftPhysicalLowering lowered_swift_struct = mono_marshal_get_swift_physical_lowering (ptype, FALSE);
7550+
// Create a new local variable to store the base address of the struct
7551+
MonoInst *struct_base_address = mono_compile_create_var (cfg, mono_get_int_type (), OP_LOCAL);
7552+
CHECK_ARG (idx_param);
7553+
NEW_ARGLOADA (cfg, struct_base_address, idx_param);
7554+
MONO_ADD_INS (cfg->cbb, struct_base_address);
75507555
if (!lowered_swift_struct.by_reference) {
7551-
// Create a new local variable to store the base address of the struct
7552-
MonoInst *struct_base_address = mono_compile_create_var (cfg, mono_get_int_type (), OP_LOCAL);
7553-
CHECK_ARG (idx_param);
7554-
NEW_ARGLOADA (cfg, struct_base_address, idx_param);
7555-
MONO_ADD_INS (cfg->cbb, struct_base_address);
7556-
7556+
// Load the lowered elements of the struct
75577557
for (uint32_t idx_lowered = 0; idx_lowered < lowered_swift_struct.num_lowered_elements; ++idx_lowered) {
7558-
MonoInst *lowered_arg = NULL;
7559-
// Load the lowered elements of the struct
7560-
lowered_arg = mini_emit_memory_load (cfg, lowered_swift_struct.lowered_elements [idx_lowered], struct_base_address, lowered_swift_struct.offsets [idx_lowered], 0);
7558+
MonoInst *lowered_arg = mini_emit_memory_load (cfg, lowered_swift_struct.lowered_elements [idx_lowered], struct_base_address, lowered_swift_struct.offsets [idx_lowered], 0);
75617559
*sp++ = lowered_arg;
75627560

7563-
++new_param_count;
75647561
g_array_append_val (new_params, lowered_swift_struct.lowered_elements [idx_lowered]);
7562+
++new_param_count;
75657563
}
75667564
} else {
75677565
// For structs that cannot be lowered, we change the argument to byref type
7568-
ptype = mono_class_get_byref_type (mono_defaults.typed_reference_class);
7569-
// Load the address of the struct
7570-
MonoInst *struct_base_address = mono_compile_create_var (cfg, mono_get_int_type (), OP_LOCAL);
7571-
CHECK_ARG (idx_param);
7572-
NEW_ARGLOADA (cfg, struct_base_address, idx_param);
7573-
MONO_ADD_INS (cfg->cbb, struct_base_address);
75747566
*sp++ = struct_base_address;
7567+
ptype = mono_class_get_byref_type (klass);
75757568

7576-
++new_param_count;
75777569
g_array_append_val (new_params, ptype);
7570+
++new_param_count;
75787571
}
75797572
} else {
75807573
// Copy over non-struct arguments

0 commit comments

Comments
 (0)