authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-03 01:05:46+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-03 03:42:42+03:00
log0f61d1f0df887081d60558256e10944633eb868f
tree2c850d79196b43f37ffeb90595607b63dda977f3
parentb83c037f9ffd7a4285de41c95827615fcbdbbf2f

stage2 llvm: improve handling of i128 on Windows C ABI


2 files changed, 18 insertions(+), 2 deletions(-)

src/arch/x86_64/abi.zig+10-2
...@@ -5,7 +5,7 @@ const assert = std.debug.assert;...@@ -5,7 +5,7 @@ const assert = std.debug.assert;
5const Register = @import("bits.zig").Register;5const Register = @import("bits.zig").Register;
6const RegisterManagerFn = @import("../../register_manager.zig").RegisterManager;6const RegisterManagerFn = @import("../../register_manager.zig").RegisterManager;
77
8pub const Class = enum { integer, sse, sseup, x87, x87up, complex_x87, memory, none };8pub const Class = enum { integer, sse, sseup, x87, x87up, complex_x87, memory, none, win_i128 };
99
10pub fn classifyWindows(ty: Type, target: Target) Class {10pub fn classifyWindows(ty: Type, target: Target) Class {
11 // https://docs.microsoft.com/en-gb/cpp/build/x64-calling-convention?view=vs-201711 // https://docs.microsoft.com/en-gb/cpp/build/x64-calling-convention?view=vs-2017
...@@ -34,7 +34,15 @@ pub fn classifyWindows(ty: Type, target: Target) Class {...@@ -34,7 +34,15 @@ pub fn classifyWindows(ty: Type, target: Target) Class {
34 => switch (ty.abiSize(target)) {34 => switch (ty.abiSize(target)) {
35 0 => unreachable,35 0 => unreachable,
36 1, 2, 4, 8 => return .integer,36 1, 2, 4, 8 => return .integer,
37 else => return .memory,37 else => switch (ty.zigTypeTag()) {
38 .Int => return .win_i128,
39 .Struct, .Union => if (ty.containerLayout() == .Packed) {
40 return .win_i128;
41 } else {
42 return .memory;
43 },
44 else => return .memory,
45 },
38 },46 },
3947
40 .Float, .Vector => return .sse,48 .Float, .Vector => return .sse,
src/codegen/llvm.zig+8
...@@ -9687,6 +9687,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm....@@ -9687,6 +9687,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm.
9687 return dg.context.intType(@intCast(c_uint, abi_size * 8));9687 return dg.context.intType(@intCast(c_uint, abi_size * 8));
9688 }9688 }
9689 },9689 },
9690 .win_i128 => return dg.context.intType(64).vectorType(2),
9690 .memory => return dg.context.voidType(),9691 .memory => return dg.context.voidType(),
9691 .sse => return dg.lowerType(fn_info.return_type),9692 .sse => return dg.lowerType(fn_info.return_type),
9692 else => unreachable,9693 else => unreachable,
...@@ -9727,6 +9728,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm....@@ -9727,6 +9728,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm.
9727 @panic("TODO");9728 @panic("TODO");
9728 },9729 },
9729 .memory => unreachable, // handled above9730 .memory => unreachable, // handled above
9731 .win_i128 => unreachable, // windows only
9730 .none => break,9732 .none => break,
9731 }9733 }
9732 }9734 }
...@@ -9851,6 +9853,11 @@ const ParamTypeIterator = struct {...@@ -9851,6 +9853,11 @@ const ParamTypeIterator = struct {
9851 return .abi_sized_int;9853 return .abi_sized_int;
9852 }9854 }
9853 },9855 },
9856 .win_i128 => {
9857 it.zig_index += 1;
9858 it.llvm_index += 1;
9859 return .byref;
9860 },
9854 .memory => {9861 .memory => {
9855 it.zig_index += 1;9862 it.zig_index += 1;
9856 it.llvm_index += 1;9863 it.llvm_index += 1;
...@@ -9905,6 +9912,7 @@ const ParamTypeIterator = struct {...@@ -9905,6 +9912,7 @@ const ParamTypeIterator = struct {
9905 @panic("TODO");9912 @panic("TODO");
9906 },9913 },
9907 .memory => unreachable, // handled above9914 .memory => unreachable, // handled above
9915 .win_i128 => unreachable, // windows only
9908 .none => break,9916 .none => break,
9909 }9917 }
9910 }9918 }