diff options
| author | Pavel Verigo <paul.verigo@gmail.com> | 2025-04-27 15:36:24 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-05-01 18:10:36 -0400 |
| commit | a843be44a0cd88d152116a11ba75d059bbb01073 (patch) | |
| tree | 8f424e9ac8029a632d9ed43e5df7e944465040ce /src/codegen/llvm.zig | |
| parent | ad9cb401124e4b2d59e49bed2736aad7813e4f1d (diff) | |
| download | zig-a843be44a0cd88d152116a11ba75d059bbb01073.tar.gz zig-a843be44a0cd88d152116a11ba75d059bbb01073.zip | |
wasm-c-abi: llvm fix struct handling + reorganize
I changed to `wasm/abi.zig`, this design is certainly better than the previous one. Still there is some conflict of interest between llvm and self-hosted backend, better design will appear when abi tests will be tested with self-hosted.
Resolves: #23304
Resolves: #23305
Diffstat (limited to 'src/codegen/llvm.zig')
| -rw-r--r-- | src/codegen/llvm.zig | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 9aa1dd43a3..305951b5fa 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -11723,7 +11723,7 @@ fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Targe .x86_64_win => x86_64_abi.classifyWindows(return_type, zcu) == .memory, .x86_sysv, .x86_win => isByRef(return_type, zcu), .x86_stdcall => !isScalar(zcu, return_type), - .wasm_mvp => wasm_c_abi.classifyType(return_type, zcu)[0] == .indirect, + .wasm_mvp => wasm_c_abi.classifyType(return_type, zcu) == .indirect, .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win, @@ -11808,18 +11808,9 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu return o.builder.structType(.normal, types[0..types_len]); }, }, - .wasm_mvp => { - if (isScalar(zcu, return_type)) { - return o.lowerType(return_type); - } - const classes = wasm_c_abi.classifyType(return_type, zcu); - if (classes[0] == .indirect or classes[0] == .none) { - return .void; - } - - assert(classes[0] == .direct and classes[1] == .none); - const scalar_type = wasm_c_abi.scalarType(return_type, zcu); - return o.builder.intType(@intCast(scalar_type.abiSize(zcu) * 8)); + .wasm_mvp => switch (wasm_c_abi.classifyType(return_type, zcu)) { + .direct => |scalar_ty| return o.lowerType(scalar_ty), + .indirect => return .void, }, // TODO investigate other callconvs else => return o.lowerType(return_type), @@ -12073,17 +12064,28 @@ const ParamTypeIterator = struct { }, } }, - .wasm_mvp => { - it.zig_index += 1; - it.llvm_index += 1; - if (isScalar(zcu, ty)) { - return .byval; - } - const classes = wasm_c_abi.classifyType(ty, zcu); - if (classes[0] == .indirect) { + .wasm_mvp => switch (wasm_c_abi.classifyType(ty, zcu)) { + .direct => |scalar_ty| { + if (isScalar(zcu, ty)) { + it.zig_index += 1; + it.llvm_index += 1; + return .byval; + } else { + var types_buffer: [8]Builder.Type = undefined; + types_buffer[0] = try it.object.lowerType(scalar_ty); + it.types_buffer = types_buffer; + it.types_len = 1; + it.llvm_index += 1; + it.zig_index += 1; + return .multiple_llvm_types; + } + }, + .indirect => { + it.zig_index += 1; + it.llvm_index += 1; + it.byval_attr = true; return .byref; - } - return .abi_sized_int; + }, }, // TODO investigate other callconvs else => { |
