authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-06-13 04:46:30-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-06-19 11:45:06-04:00
log917640810e7f3e18daff9e75b5ecefe761a1896c
tree579e627d695f898d411a3cb1fbc0578d1a763cc2
parent16d78bc0c024da307c7ab5f6b94622e6b4b37397

Target: pass and use locals by pointer instead of by value

This struct is larger than 256 bytes and code that copies it consistently shows up in profiles of the compiler.

96 files changed, 400 insertions(+), 401 deletions(-)

build.zig+1-1
...@@ -759,7 +759,7 @@ fn addCmakeCfgOptionsToExe(...@@ -759,7 +759,7 @@ fn addCmakeCfgOptionsToExe(
759 use_zig_libcxx: bool,759 use_zig_libcxx: bool,
760) !void {760) !void {
761 const mod = exe.root_module;761 const mod = exe.root_module;
762 const target = mod.resolved_target.?.result;762 const target = &mod.resolved_target.?.result;
763763
764 if (target.os.tag.isDarwin()) {764 if (target.os.tag.isDarwin()) {
765 // useful for package maintainers765 // useful for package maintainers
lib/compiler/resinator/main.zig+2-2
...@@ -525,7 +525,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A...@@ -525,7 +525,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A
525 };525 };
526 const target = std.zig.resolveTargetQueryOrFatal(target_query);526 const target = std.zig.resolveTargetQueryOrFatal(target_query);
527 const is_native_abi = target_query.isNativeAbi();527 const is_native_abi = target_query.isNativeAbi();
528 const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, target, is_native_abi, true, null) catch {528 const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch {
529 if (includes == .any) {529 if (includes == .any) {
530 // fall back to mingw530 // fall back to mingw
531 includes = .gnu;531 includes = .gnu;
...@@ -550,7 +550,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A...@@ -550,7 +550,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A
550 };550 };
551 const target = std.zig.resolveTargetQueryOrFatal(target_query);551 const target = std.zig.resolveTargetQueryOrFatal(target_query);
552 const is_native_abi = target_query.isNativeAbi();552 const is_native_abi = target_query.isNativeAbi();
553 const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, target, is_native_abi, true, null) catch |err| switch (err) {553 const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) {
554 error.OutOfMemory => |e| return e,554 error.OutOfMemory => |e| return e,
555 else => return error.MingwIncludesNotFound,555 else => return error.MingwIncludesNotFound,
556 };556 };
lib/compiler_rt/divmodei4.zig+2-2
...@@ -35,7 +35,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void {...@@ -35,7 +35,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void {
3535
36pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {36pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
37 @setRuntimeSafety(builtin.is_test);37 @setRuntimeSafety(builtin.is_test);
38 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));38 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
39 const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));39 const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
40 const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));40 const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
41 const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));41 const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
...@@ -44,7 +44,7 @@ pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) vo...@@ -44,7 +44,7 @@ pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) vo
4444
45pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {45pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
46 @setRuntimeSafety(builtin.is_test);46 @setRuntimeSafety(builtin.is_test);
47 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));47 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
48 const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));48 const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
49 const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));49 const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
50 const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));50 const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
lib/compiler_rt/fixdfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {12pub fn __fixdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/fixhfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixhfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {12pub fn __fixhfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/fixsfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixsfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {12pub fn __fixsfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/fixtfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixtfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {12pub fn __fixtfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/fixunsdfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixunsdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {12pub fn __fixunsdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/fixunshfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixunshfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {12pub fn __fixunshfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/fixunssfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixunssfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {12pub fn __fixunssfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/fixunstfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixunstfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {12pub fn __fixunstfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/fixunsxfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixunsxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {12pub fn __fixunsxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/fixxfei.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __fixxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {12pub fn __fixxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
15}15}
lib/compiler_rt/floateidf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floateidf(a: [*]const u8, bits: usize) callconv(.c) f64 {12pub fn __floateidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f64, .signed, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f64, .signed, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/floateihf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floateihf(a: [*]const u8, bits: usize) callconv(.c) f16 {12pub fn __floateihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f16, .signed, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f16, .signed, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/floateisf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floateisf(a: [*]const u8, bits: usize) callconv(.c) f32 {12pub fn __floateisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f32, .signed, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f32, .signed, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/floateitf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floateitf(a: [*]const u8, bits: usize) callconv(.c) f128 {12pub fn __floateitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f128, .signed, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f128, .signed, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/floateixf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floateixf(a: [*]const u8, bits: usize) callconv(.c) f80 {12pub fn __floateixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f80, .signed, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f80, .signed, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/floatuneidf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floatuneidf(a: [*]const u8, bits: usize) callconv(.c) f64 {12pub fn __floatuneidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f64, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f64, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/floatuneihf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floatuneihf(a: [*]const u8, bits: usize) callconv(.c) f16 {12pub fn __floatuneihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f16, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f16, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/floatuneisf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floatuneisf(a: [*]const u8, bits: usize) callconv(.c) f32 {12pub fn __floatuneisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f32, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f32, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/floatuneitf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floatuneitf(a: [*]const u8, bits: usize) callconv(.c) f128 {12pub fn __floatuneitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f128, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f128, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/floatuneixf.zig+1-1
...@@ -10,6 +10,6 @@ comptime {...@@ -10,6 +10,6 @@ comptime {
10}10}
1111
12pub fn __floatuneixf(a: [*]const u8, bits: usize) callconv(.c) f80 {12pub fn __floatuneixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));13 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
14 return floatFromBigInt(f80, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));14 return floatFromBigInt(f80, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
15}15}
lib/compiler_rt/udivmodei4.zig+2-2
...@@ -114,7 +114,7 @@ pub fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {...@@ -114,7 +114,7 @@ pub fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
114114
115pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {115pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
116 @setRuntimeSafety(builtin.is_test);116 @setRuntimeSafety(builtin.is_test);
117 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));117 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
118 const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));118 const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
119 const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));119 const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
120 const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));120 const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
...@@ -123,7 +123,7 @@ pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) ca...@@ -123,7 +123,7 @@ pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) ca
123123
124pub fn __umodei4(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {124pub fn __umodei4(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
125 @setRuntimeSafety(builtin.is_test);125 @setRuntimeSafety(builtin.is_test);
126 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));126 const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
127 const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));127 const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
128 const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));128 const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
129 const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));129 const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
lib/std/Build/Fuzz/WebServer.zig+2-2
...@@ -198,10 +198,10 @@ fn serveWasm(...@@ -198,10 +198,10 @@ fn serveWasm(
198 const wasm_base_path = try buildWasmBinary(ws, arena, optimize_mode);198 const wasm_base_path = try buildWasmBinary(ws, arena, optimize_mode);
199 const bin_name = try std.zig.binNameAlloc(arena, .{199 const bin_name = try std.zig.binNameAlloc(arena, .{
200 .root_name = fuzzer_bin_name,200 .root_name = fuzzer_bin_name,
201 .target = std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{201 .target = &(std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{
202 .arch_os_abi = fuzzer_arch_os_abi,202 .arch_os_abi = fuzzer_arch_os_abi,
203 .cpu_features = fuzzer_cpu_features,203 .cpu_features = fuzzer_cpu_features,
204 }) catch unreachable) catch unreachable,204 }) catch unreachable) catch unreachable),
205 .output_mode = .Exe,205 .output_mode = .Exe,
206 });206 });
207 // std.http.Server does not have a sendfile API yet.207 // std.http.Server does not have a sendfile API yet.
lib/std/Build/Module.zig+4-4
...@@ -655,10 +655,10 @@ fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void {...@@ -655,10 +655,10 @@ fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void {
655 m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM");655 m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM");
656}656}
657657
658fn requireKnownTarget(m: *Module) std.Target {658fn requireKnownTarget(m: *Module) *const std.Target {
659 const resolved_target = m.resolved_target orelse659 const resolved_target = &(m.resolved_target orelse
660 @panic("this API requires the Module to be created with a known 'target' field");660 @panic("this API requires the Module to be created with a known 'target' field"));
661 return resolved_target.result;661 return &resolved_target.result;
662}662}
663663
664/// Elements of `modules` and `names` are matched one-to-one.664/// Elements of `modules` and `names` are matched one-to-one.
lib/std/Build/Step/Compile.zig+2-2
...@@ -377,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {...@@ -377,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
377377
378 const resolved_target = options.root_module.resolved_target orelse378 const resolved_target = options.root_module.resolved_target orelse
379 @panic("the root Module of a Compile step must be created with a known 'target' field");379 @panic("the root Module of a Compile step must be created with a known 'target' field");
380 const target = resolved_target.result;380 const target = &resolved_target.result;
381381
382 const step_name = owner.fmt("compile {s} {s} {s}", .{382 const step_name = owner.fmt("compile {s} {s} {s}", .{
383 // Avoid the common case of the step name looking like "compile test test".383 // Avoid the common case of the step name looking like "compile test test".
...@@ -1866,7 +1866,7 @@ fn outputPath(c: *Compile, out_dir: std.Build.Cache.Path, ea: std.zig.EmitArtifa...@@ -1866,7 +1866,7 @@ fn outputPath(c: *Compile, out_dir: std.Build.Cache.Path, ea: std.zig.EmitArtifa
1866 const arena = c.step.owner.graph.arena;1866 const arena = c.step.owner.graph.arena;
1867 const name = ea.cacheName(arena, .{1867 const name = ea.cacheName(arena, .{
1868 .root_name = c.name,1868 .root_name = c.name,
1869 .target = c.root_module.resolved_target.?.result,1869 .target = &c.root_module.resolved_target.?.result,
1870 .output_mode = switch (c.kind) {1870 .output_mode = switch (c.kind) {
1871 .lib => .Lib,1871 .lib => .Lib,
1872 .obj, .test_obj => .Obj,1872 .obj, .test_obj => .Obj,
lib/std/Build/Step/Run.zig+1-1
...@@ -1108,7 +1108,7 @@ fn runCommand(...@@ -1108,7 +1108,7 @@ fn runCommand(
1108 const need_cross_libc = exe.is_linking_libc and1108 const need_cross_libc = exe.is_linking_libc and
1109 (root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic));1109 (root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic));
1110 const other_target = exe.root_module.resolved_target.?.result;1110 const other_target = exe.root_module.resolved_target.?.result;
1111 switch (std.zig.system.getExternalExecutor(b.graph.host.result, &other_target, .{1111 switch (std.zig.system.getExternalExecutor(&b.graph.host.result, &other_target, .{
1112 .qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null,1112 .qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null,
1113 .link_libc = exe.is_linking_libc,1113 .link_libc = exe.is_linking_libc,
1114 })) {1114 })) {
lib/std/Target.zig+26-26
...@@ -1074,7 +1074,7 @@ pub const ObjectFormat = enum {...@@ -1074,7 +1074,7 @@ pub const ObjectFormat = enum {
1074 }1074 }
1075};1075};
10761076
1077pub fn toElfMachine(target: Target) std.elf.EM {1077pub fn toElfMachine(target: *const Target) std.elf.EM {
1078 return switch (target.cpu.arch) {1078 return switch (target.cpu.arch) {
1079 .amdgcn => .AMDGPU,1079 .amdgcn => .AMDGPU,
1080 .arc => .ARC_COMPACT,1080 .arc => .ARC_COMPACT,
...@@ -1115,7 +1115,7 @@ pub fn toElfMachine(target: Target) std.elf.EM {...@@ -1115,7 +1115,7 @@ pub fn toElfMachine(target: Target) std.elf.EM {
1115 };1115 };
1116}1116}
11171117
1118pub fn toCoffMachine(target: Target) std.coff.MachineType {1118pub fn toCoffMachine(target: *const Target) std.coff.MachineType {
1119 return switch (target.cpu.arch) {1119 return switch (target.cpu.arch) {
1120 .arm => .ARM,1120 .arm => .ARM,
1121 .thumb => .ARMNT,1121 .thumb => .ARMNT,
...@@ -1999,7 +1999,7 @@ pub const Cpu = struct {...@@ -1999,7 +1999,7 @@ pub const Cpu = struct {
1999 }1999 }
2000};2000};
20012001
2002pub fn zigTriple(target: Target, allocator: Allocator) Allocator.Error![]u8 {2002pub fn zigTriple(target: *const Target, allocator: Allocator) Allocator.Error![]u8 {
2003 return Query.fromTarget(target).zigTriple(allocator);2003 return Query.fromTarget(target).zigTriple(allocator);
2004}2004}
20052005
...@@ -2007,7 +2007,7 @@ pub fn hurdTupleSimple(allocator: Allocator, arch: Cpu.Arch, abi: Abi) ![]u8 {...@@ -2007,7 +2007,7 @@ pub fn hurdTupleSimple(allocator: Allocator, arch: Cpu.Arch, abi: Abi) ![]u8 {
2007 return std.fmt.allocPrint(allocator, "{s}-{s}", .{ @tagName(arch), @tagName(abi) });2007 return std.fmt.allocPrint(allocator, "{s}-{s}", .{ @tagName(arch), @tagName(abi) });
2008}2008}
20092009
2010pub fn hurdTuple(target: Target, allocator: Allocator) ![]u8 {2010pub fn hurdTuple(target: *const Target, allocator: Allocator) ![]u8 {
2011 return hurdTupleSimple(allocator, target.cpu.arch, target.abi);2011 return hurdTupleSimple(allocator, target.cpu.arch, target.abi);
2012}2012}
20132013
...@@ -2015,63 +2015,63 @@ pub fn linuxTripleSimple(allocator: Allocator, arch: Cpu.Arch, os_tag: Os.Tag, a...@@ -2015,63 +2015,63 @@ pub fn linuxTripleSimple(allocator: Allocator, arch: Cpu.Arch, os_tag: Os.Tag, a
2015 return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ @tagName(arch), @tagName(os_tag), @tagName(abi) });2015 return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ @tagName(arch), @tagName(os_tag), @tagName(abi) });
2016}2016}
20172017
2018pub fn linuxTriple(target: Target, allocator: Allocator) ![]u8 {2018pub fn linuxTriple(target: *const Target, allocator: Allocator) ![]u8 {
2019 return linuxTripleSimple(allocator, target.cpu.arch, target.os.tag, target.abi);2019 return linuxTripleSimple(allocator, target.cpu.arch, target.os.tag, target.abi);
2020}2020}
20212021
2022pub fn exeFileExt(target: Target) [:0]const u8 {2022pub fn exeFileExt(target: *const Target) [:0]const u8 {
2023 return target.os.tag.exeFileExt(target.cpu.arch);2023 return target.os.tag.exeFileExt(target.cpu.arch);
2024}2024}
20252025
2026pub fn staticLibSuffix(target: Target) [:0]const u8 {2026pub fn staticLibSuffix(target: *const Target) [:0]const u8 {
2027 return target.os.tag.staticLibSuffix(target.abi);2027 return target.os.tag.staticLibSuffix(target.abi);
2028}2028}
20292029
2030pub fn dynamicLibSuffix(target: Target) [:0]const u8 {2030pub fn dynamicLibSuffix(target: *const Target) [:0]const u8 {
2031 return target.os.tag.dynamicLibSuffix();2031 return target.os.tag.dynamicLibSuffix();
2032}2032}
20332033
2034pub fn libPrefix(target: Target) [:0]const u8 {2034pub fn libPrefix(target: *const Target) [:0]const u8 {
2035 return target.os.tag.libPrefix(target.abi);2035 return target.os.tag.libPrefix(target.abi);
2036}2036}
20372037
2038pub inline fn isMinGW(target: Target) bool {2038pub inline fn isMinGW(target: *const Target) bool {
2039 return target.os.tag == .windows and target.abi.isGnu();2039 return target.os.tag == .windows and target.abi.isGnu();
2040}2040}
20412041
2042pub inline fn isGnuLibC(target: Target) bool {2042pub inline fn isGnuLibC(target: *const Target) bool {
2043 return switch (target.os.tag) {2043 return switch (target.os.tag) {
2044 .hurd, .linux => target.abi.isGnu(),2044 .hurd, .linux => target.abi.isGnu(),
2045 else => false,2045 else => false,
2046 };2046 };
2047}2047}
20482048
2049pub inline fn isMuslLibC(target: Target) bool {2049pub inline fn isMuslLibC(target: *const Target) bool {
2050 return target.os.tag == .linux and target.abi.isMusl();2050 return target.os.tag == .linux and target.abi.isMusl();
2051}2051}
20522052
2053pub inline fn isDarwinLibC(target: Target) bool {2053pub inline fn isDarwinLibC(target: *const Target) bool {
2054 return switch (target.abi) {2054 return switch (target.abi) {
2055 .none, .macabi, .simulator => target.os.tag.isDarwin(),2055 .none, .macabi, .simulator => target.os.tag.isDarwin(),
2056 else => false,2056 else => false,
2057 };2057 };
2058}2058}
20592059
2060pub inline fn isFreeBSDLibC(target: Target) bool {2060pub inline fn isFreeBSDLibC(target: *const Target) bool {
2061 return switch (target.abi) {2061 return switch (target.abi) {
2062 .none, .eabihf => target.os.tag == .freebsd,2062 .none, .eabihf => target.os.tag == .freebsd,
2063 else => false,2063 else => false,
2064 };2064 };
2065}2065}
20662066
2067pub inline fn isNetBSDLibC(target: Target) bool {2067pub inline fn isNetBSDLibC(target: *const Target) bool {
2068 return switch (target.abi) {2068 return switch (target.abi) {
2069 .none, .eabi, .eabihf => target.os.tag == .netbsd,2069 .none, .eabi, .eabihf => target.os.tag == .netbsd,
2070 else => false,2070 else => false,
2071 };2071 };
2072}2072}
20732073
2074pub inline fn isWasiLibC(target: Target) bool {2074pub inline fn isWasiLibC(target: *const Target) bool {
2075 return target.os.tag == .wasi and target.abi.isMusl();2075 return target.os.tag == .wasi and target.abi.isMusl();
2076}2076}
20772077
...@@ -2576,7 +2576,7 @@ pub const DynamicLinker = struct {...@@ -2576,7 +2576,7 @@ pub const DynamicLinker = struct {
2576 }2576 }
2577};2577};
25782578
2579pub fn standardDynamicLinkerPath(target: Target) DynamicLinker {2579pub fn standardDynamicLinkerPath(target: *const Target) DynamicLinker {
2580 return DynamicLinker.standard(target.cpu, target.os, target.abi);2580 return DynamicLinker.standard(target.cpu, target.os, target.abi);
2581}2581}
25822582
...@@ -2645,11 +2645,11 @@ pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {...@@ -2645,11 +2645,11 @@ pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {
2645 };2645 };
2646}2646}
26472647
2648pub fn ptrBitWidth(target: Target) u16 {2648pub fn ptrBitWidth(target: *const Target) u16 {
2649 return ptrBitWidth_cpu_abi(target.cpu, target.abi);2649 return ptrBitWidth_cpu_abi(target.cpu, target.abi);
2650}2650}
26512651
2652pub fn stackAlignment(target: Target) u16 {2652pub fn stackAlignment(target: *const Target) u16 {
2653 // Overrides for when the stack alignment is not equal to the pointer width.2653 // Overrides for when the stack alignment is not equal to the pointer width.
2654 switch (target.cpu.arch) {2654 switch (target.cpu.arch) {
2655 .m68k,2655 .m68k,
...@@ -2697,7 +2697,7 @@ pub fn stackAlignment(target: Target) u16 {...@@ -2697,7 +2697,7 @@ pub fn stackAlignment(target: Target) u16 {
2697/// Default signedness of `char` for the native C compiler for this target2697/// Default signedness of `char` for the native C compiler for this target
2698/// Note that char signedness is implementation-defined and many compilers provide2698/// Note that char signedness is implementation-defined and many compilers provide
2699/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char2699/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char
2700pub fn cCharSignedness(target: Target) std.builtin.Signedness {2700pub fn cCharSignedness(target: *const Target) std.builtin.Signedness {
2701 if (target.os.tag.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;2701 if (target.os.tag.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;
27022702
2703 return switch (target.cpu.arch) {2703 return switch (target.cpu.arch) {
...@@ -2740,7 +2740,7 @@ pub const CType = enum {...@@ -2740,7 +2740,7 @@ pub const CType = enum {
2740 longdouble,2740 longdouble,
2741};2741};
27422742
2743pub fn cTypeByteSize(t: Target, c_type: CType) u16 {2743pub fn cTypeByteSize(t: *const Target, c_type: CType) u16 {
2744 return switch (c_type) {2744 return switch (c_type) {
2745 .char,2745 .char,
2746 .short,2746 .short,
...@@ -2766,7 +2766,7 @@ pub fn cTypeByteSize(t: Target, c_type: CType) u16 {...@@ -2766,7 +2766,7 @@ pub fn cTypeByteSize(t: Target, c_type: CType) u16 {
2766 };2766 };
2767}2767}
27682768
2769pub fn cTypeBitSize(target: Target, c_type: CType) u16 {2769pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
2770 switch (target.os.tag) {2770 switch (target.os.tag) {
2771 .freestanding, .other => switch (target.cpu.arch) {2771 .freestanding, .other => switch (target.cpu.arch) {
2772 .msp430 => switch (c_type) {2772 .msp430 => switch (c_type) {
...@@ -3077,7 +3077,7 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {...@@ -3077,7 +3077,7 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
3077 }3077 }
3078}3078}
30793079
3080pub fn cTypeAlignment(target: Target, c_type: CType) u16 {3080pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {
3081 // Overrides for unusual alignments3081 // Overrides for unusual alignments
3082 switch (target.cpu.arch) {3082 switch (target.cpu.arch) {
3083 .avr => return 1,3083 .avr => return 1,
...@@ -3172,7 +3172,7 @@ pub fn cTypeAlignment(target: Target, c_type: CType) u16 {...@@ -3172,7 +3172,7 @@ pub fn cTypeAlignment(target: Target, c_type: CType) u16 {
3172 );3172 );
3173}3173}
31743174
3175pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {3175pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
3176 // Overrides for unusual alignments3176 // Overrides for unusual alignments
3177 switch (target.cpu.arch) {3177 switch (target.cpu.arch) {
3178 .arc => switch (c_type) {3178 .arc => switch (c_type) {
...@@ -3265,7 +3265,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {...@@ -3265,7 +3265,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
3265 );3265 );
3266}3266}
32673267
3268pub fn cMaxIntAlignment(target: std.Target) u16 {3268pub fn cMaxIntAlignment(target: *const Target) u16 {
3269 return switch (target.cpu.arch) {3269 return switch (target.cpu.arch) {
3270 .avr => 1,3270 .avr => 1,
32713271
...@@ -3328,7 +3328,7 @@ pub fn cMaxIntAlignment(target: std.Target) u16 {...@@ -3328,7 +3328,7 @@ pub fn cMaxIntAlignment(target: std.Target) u16 {
3328 };3328 };
3329}3329}
33303330
3331pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {3331pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention {
3332 return switch (target.cpu.arch) {3332 return switch (target.cpu.arch) {
3333 .x86_64 => switch (target.os.tag) {3333 .x86_64 => switch (target.os.tag) {
3334 .windows, .uefi => .{ .x86_64_win = .{} },3334 .windows, .uefi => .{ .x86_64_win = .{} },
lib/std/Target/Query.zig+1-1
...@@ -94,7 +94,7 @@ pub const OsVersion = union(enum) {...@@ -94,7 +94,7 @@ pub const OsVersion = union(enum) {
9494
95pub const SemanticVersion = std.SemanticVersion;95pub const SemanticVersion = std.SemanticVersion;
9696
97pub fn fromTarget(target: Target) Query {97pub fn fromTarget(target: *const Target) Query {
98 var result: Query = .{98 var result: Query = .{
99 .cpu_arch = target.cpu.arch,99 .cpu_arch = target.cpu.arch,
100 .cpu_model = .{ .explicit = target.cpu.model },100 .cpu_model = .{ .explicit = target.cpu.model },
lib/std/debug/Dwarf/abi.zig+1-1
...@@ -9,7 +9,7 @@ const Arch = std.Target.Cpu.Arch;...@@ -9,7 +9,7 @@ const Arch = std.Target.Cpu.Arch;
9///9///
10/// See also `std.debug.SelfInfo.supportsUnwinding` which tells whether the Zig10/// See also `std.debug.SelfInfo.supportsUnwinding` which tells whether the Zig
11/// standard library has a working implementation of unwinding for this target.11/// standard library has a working implementation of unwinding for this target.
12pub fn supportsUnwinding(target: std.Target) bool {12pub fn supportsUnwinding(target: *const std.Target) bool {
13 return switch (target.cpu.arch) {13 return switch (target.cpu.arch) {
14 .amdgcn,14 .amdgcn,
15 .nvptx,15 .nvptx,
lib/std/debug/SelfInfo.zig+3-3
...@@ -1795,10 +1795,10 @@ fn spRegNum(reg_context: Dwarf.abi.RegisterContext) u8 {...@@ -1795,10 +1795,10 @@ fn spRegNum(reg_context: Dwarf.abi.RegisterContext) u8 {
1795const ip_reg_num = Dwarf.abi.ipRegNum(native_arch).?;1795const ip_reg_num = Dwarf.abi.ipRegNum(native_arch).?;
17961796
1797/// Tells whether unwinding for the host is implemented.1797/// Tells whether unwinding for the host is implemented.
1798pub const supports_unwinding = supportsUnwinding(builtin.target);1798pub const supports_unwinding = supportsUnwinding(&builtin.target);
17991799
1800comptime {1800comptime {
1801 if (supports_unwinding) assert(Dwarf.abi.supportsUnwinding(builtin.target));1801 if (supports_unwinding) assert(Dwarf.abi.supportsUnwinding(&builtin.target));
1802}1802}
18031803
1804/// Tells whether unwinding for this target is *implemented* here in the Zig1804/// Tells whether unwinding for this target is *implemented* here in the Zig
...@@ -1806,7 +1806,7 @@ comptime {...@@ -1806,7 +1806,7 @@ comptime {
1806///1806///
1807/// See also `Dwarf.abi.supportsUnwinding` which tells whether Dwarf supports1807/// See also `Dwarf.abi.supportsUnwinding` which tells whether Dwarf supports
1808/// unwinding on that target *in theory*.1808/// unwinding on that target *in theory*.
1809pub fn supportsUnwinding(target: std.Target) bool {1809pub fn supportsUnwinding(target: *const std.Target) bool {
1810 return switch (target.cpu.arch) {1810 return switch (target.cpu.arch) {
1811 .x86 => switch (target.os.tag) {1811 .x86 => switch (target.os.tag) {
1812 .linux, .netbsd, .solaris, .illumos => true,1812 .linux, .netbsd, .solaris, .illumos => true,
lib/std/zig.zig+1-1
...@@ -141,7 +141,7 @@ pub fn lineDelta(source: []const u8, start: usize, end: usize) isize {...@@ -141,7 +141,7 @@ pub fn lineDelta(source: []const u8, start: usize, end: usize) isize {
141141
142pub const BinNameOptions = struct {142pub const BinNameOptions = struct {
143 root_name: []const u8,143 root_name: []const u8,
144 target: std.Target,144 target: *const std.Target,
145 output_mode: std.builtin.OutputMode,145 output_mode: std.builtin.OutputMode,
146 link_mode: ?std.builtin.LinkMode = null,146 link_mode: ?std.builtin.LinkMode = null,
147 version: ?std.SemanticVersion = null,147 version: ?std.SemanticVersion = null,
lib/std/zig/LibCDirs.zig+4-4
...@@ -15,7 +15,7 @@ pub const DarwinSdkLayout = enum {...@@ -15,7 +15,7 @@ pub const DarwinSdkLayout = enum {
15pub fn detect(15pub fn detect(
16 arena: Allocator,16 arena: Allocator,
17 zig_lib_dir: []const u8,17 zig_lib_dir: []const u8,
18 target: std.Target,18 target: *const std.Target,
19 is_native_abi: bool,19 is_native_abi: bool,
20 link_libc: bool,20 link_libc: bool,
21 libc_installation: ?*const LibCInstallation,21 libc_installation: ?*const LibCInstallation,
...@@ -88,7 +88,7 @@ pub fn detect(...@@ -88,7 +88,7 @@ pub fn detect(
88 };88 };
89}89}
9090
91fn detectFromInstallation(arena: Allocator, target: std.Target, lci: *const LibCInstallation) !LibCDirs {91fn detectFromInstallation(arena: Allocator, target: *const std.Target, lci: *const LibCInstallation) !LibCDirs {
92 var list = try std.ArrayList([]const u8).initCapacity(arena, 5);92 var list = try std.ArrayList([]const u8).initCapacity(arena, 5);
93 var framework_list = std.ArrayList([]const u8).init(arena);93 var framework_list = std.ArrayList([]const u8).init(arena);
9494
...@@ -146,7 +146,7 @@ fn detectFromInstallation(arena: Allocator, target: std.Target, lci: *const LibC...@@ -146,7 +146,7 @@ fn detectFromInstallation(arena: Allocator, target: std.Target, lci: *const LibC
146pub fn detectFromBuilding(146pub fn detectFromBuilding(
147 arena: Allocator,147 arena: Allocator,
148 zig_lib_dir: []const u8,148 zig_lib_dir: []const u8,
149 target: std.Target,149 target: *const std.Target,
150) !LibCDirs {150) !LibCDirs {
151 const s = std.fs.path.sep_str;151 const s = std.fs.path.sep_str;
152152
...@@ -224,7 +224,7 @@ pub fn detectFromBuilding(...@@ -224,7 +224,7 @@ pub fn detectFromBuilding(
224 };224 };
225}225}
226226
227fn libCGenericName(target: std.Target) [:0]const u8 {227fn libCGenericName(target: *const std.Target) [:0]const u8 {
228 switch (target.os.tag) {228 switch (target.os.tag) {
229 .windows => return "mingw",229 .windows => return "mingw",
230 .macos, .ios, .tvos, .watchos, .visionos => return "darwin",230 .macos, .ios, .tvos, .watchos, .visionos => return "darwin",
lib/std/zig/LibCInstallation.zig+4-4
...@@ -26,7 +26,7 @@ pub const FindError = error{...@@ -26,7 +26,7 @@ pub const FindError = error{
26pub fn parse(26pub fn parse(
27 allocator: Allocator,27 allocator: Allocator,
28 libc_file: []const u8,28 libc_file: []const u8,
29 target: std.Target,29 target: *const std.Target,
30) !LibCInstallation {30) !LibCInstallation {
31 var self: LibCInstallation = .{};31 var self: LibCInstallation = .{};
3232
...@@ -157,7 +157,7 @@ pub fn render(self: LibCInstallation, out: anytype) !void {...@@ -157,7 +157,7 @@ pub fn render(self: LibCInstallation, out: anytype) !void {
157157
158pub const FindNativeOptions = struct {158pub const FindNativeOptions = struct {
159 allocator: Allocator,159 allocator: Allocator,
160 target: std.Target,160 target: *const std.Target,
161161
162 /// If enabled, will print human-friendly errors to stderr.162 /// If enabled, will print human-friendly errors to stderr.
163 verbose: bool = false,163 verbose: bool = false,
...@@ -700,7 +700,7 @@ pub const CrtBasenames = struct {...@@ -700,7 +700,7 @@ pub const CrtBasenames = struct {
700 crtn: ?[]const u8 = null,700 crtn: ?[]const u8 = null,
701701
702 pub const GetArgs = struct {702 pub const GetArgs = struct {
703 target: std.Target,703 target: *const std.Target,
704 link_libc: bool,704 link_libc: bool,
705 output_mode: std.builtin.OutputMode,705 output_mode: std.builtin.OutputMode,
706 link_mode: std.builtin.LinkMode,706 link_mode: std.builtin.LinkMode,
...@@ -965,7 +965,7 @@ pub fn resolveCrtPaths(...@@ -965,7 +965,7 @@ pub fn resolveCrtPaths(
965 lci: LibCInstallation,965 lci: LibCInstallation,
966 arena: Allocator,966 arena: Allocator,
967 crt_basenames: CrtBasenames,967 crt_basenames: CrtBasenames,
968 target: std.Target,968 target: *const std.Target,
969) error{ OutOfMemory, LibCInstallationMissingCrtDir }!CrtPaths {969) error{ OutOfMemory, LibCInstallationMissingCrtDir }!CrtPaths {
970 const crt_dir_path: Path = .{970 const crt_dir_path: Path = .{
971 .root_dir = std.Build.Cache.Directory.cwd(),971 .root_dir = std.Build.Cache.Directory.cwd(),
lib/std/zig/llvm/Builder.zig+1-1
...@@ -66,7 +66,7 @@ pub const Options = struct {...@@ -66,7 +66,7 @@ pub const Options = struct {
66 allocator: Allocator,66 allocator: Allocator,
67 strip: bool = true,67 strip: bool = true,
68 name: []const u8 = &.{},68 name: []const u8 = &.{},
69 target: std.Target = builtin.target,69 target: *const std.Target = &builtin.target,
70 triple: []const u8 = &.{},70 triple: []const u8 = &.{},
71};71};
7272
lib/std/zig/system.zig+1-1
...@@ -28,7 +28,7 @@ pub const GetExternalExecutorOptions = struct {...@@ -28,7 +28,7 @@ pub const GetExternalExecutorOptions = struct {
28/// Return whether or not the given host is capable of running executables of28/// Return whether or not the given host is capable of running executables of
29/// the other target.29/// the other target.
30pub fn getExternalExecutor(30pub fn getExternalExecutor(
31 host: std.Target,31 host: *const std.Target,
32 candidate: *const std.Target,32 candidate: *const std.Target,
33 options: GetExternalExecutorOptions,33 options: GetExternalExecutorOptions,
34) Executor {34) Executor {
lib/std/zig/system/NativePaths.zig+1-1
...@@ -13,7 +13,7 @@ framework_dirs: std.ArrayListUnmanaged([]const u8) = .empty,...@@ -13,7 +13,7 @@ framework_dirs: std.ArrayListUnmanaged([]const u8) = .empty,
13rpaths: std.ArrayListUnmanaged([]const u8) = .empty,13rpaths: std.ArrayListUnmanaged([]const u8) = .empty,
14warnings: std.ArrayListUnmanaged([]const u8) = .empty,14warnings: std.ArrayListUnmanaged([]const u8) = .empty,
1515
16pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {16pub fn detect(arena: Allocator, native_target: *const std.Target) !NativePaths {
17 var self: NativePaths = .{ .arena = arena };17 var self: NativePaths = .{ .arena = arena };
18 var is_nix = false;18 var is_nix = false;
19 if (process.getEnvVarOwned(arena, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {19 if (process.getEnvVarOwned(arena, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
lib/std/zig/system/darwin.zig+1-1
...@@ -34,7 +34,7 @@ pub fn isSdkInstalled(allocator: Allocator) bool {...@@ -34,7 +34,7 @@ pub fn isSdkInstalled(allocator: Allocator) bool {
34/// Caller owns the memory.34/// Caller owns the memory.
35/// stderr from xcrun is ignored.35/// stderr from xcrun is ignored.
36/// If error.OutOfMemory occurs in Allocator, this function returns null.36/// If error.OutOfMemory occurs in Allocator, this function returns null.
37pub fn getSdk(allocator: Allocator, target: Target) ?[]const u8 {37pub fn getSdk(allocator: Allocator, target: *const Target) ?[]const u8 {
38 const is_simulator_abi = target.abi == .simulator;38 const is_simulator_abi = target.abi == .simulator;
39 const sdk = switch (target.os.tag) {39 const sdk = switch (target.os.tag) {
40 .ios => switch (target.abi) {40 .ios => switch (target.abi) {
lib/std/zig/target.zig+6-6
...@@ -116,7 +116,7 @@ pub const freebsd_libc_version: std.SemanticVersion = .{ .major = 14, .minor = 0...@@ -116,7 +116,7 @@ pub const freebsd_libc_version: std.SemanticVersion = .{ .major = 14, .minor = 0
116/// The version of Zig's bundled NetBSD libc used when linking libc statically.116/// The version of Zig's bundled NetBSD libc used when linking libc statically.
117pub const netbsd_libc_version: std.SemanticVersion = .{ .major = 10, .minor = 1, .patch = 0 };117pub const netbsd_libc_version: std.SemanticVersion = .{ .major = 10, .minor = 1, .patch = 0 };
118118
119pub fn canBuildLibC(target: std.Target) bool {119pub fn canBuildLibC(target: *const std.Target) bool {
120 for (available_libcs) |libc| {120 for (available_libcs) |libc| {
121 if (target.cpu.arch == libc.arch and target.os.tag == libc.os and target.abi == libc.abi) {121 if (target.cpu.arch == libc.arch and target.os.tag == libc.os and target.abi == libc.abi) {
122 if (libc.os_ver) |libc_os_ver| {122 if (libc.os_ver) |libc_os_ver| {
...@@ -176,7 +176,7 @@ pub fn muslRuntimeTriple(...@@ -176,7 +176,7 @@ pub fn muslRuntimeTriple(
176 return std.Target.linuxTripleSimple(allocator, arch, .linux, abi);176 return std.Target.linuxTripleSimple(allocator, arch, .linux, abi);
177}177}
178178
179pub fn osArchName(target: std.Target) [:0]const u8 {179pub fn osArchName(target: *const std.Target) [:0]const u8 {
180 return switch (target.os.tag) {180 return switch (target.os.tag) {
181 .linux => switch (target.cpu.arch) {181 .linux => switch (target.cpu.arch) {
182 .arm, .armeb, .thumb, .thumbeb => "arm",182 .arm, .armeb, .thumb, .thumbeb => "arm",
...@@ -276,7 +276,7 @@ pub fn netbsdAbiNameHeaders(abi: std.Target.Abi) [:0]const u8 {...@@ -276,7 +276,7 @@ pub fn netbsdAbiNameHeaders(abi: std.Target.Abi) [:0]const u8 {
276 };276 };
277}277}
278278
279pub fn isLibCLibName(target: std.Target, name: []const u8) bool {279pub fn isLibCLibName(target: *const std.Target, name: []const u8) bool {
280 const ignore_case = target.os.tag.isDarwin() or target.os.tag == .windows;280 const ignore_case = target.os.tag.isDarwin() or target.os.tag == .windows;
281281
282 if (eqlIgnoreCase(ignore_case, name, "c"))282 if (eqlIgnoreCase(ignore_case, name, "c"))
...@@ -453,7 +453,7 @@ pub fn isLibCLibName(target: std.Target, name: []const u8) bool {...@@ -453,7 +453,7 @@ pub fn isLibCLibName(target: std.Target, name: []const u8) bool {
453 return false;453 return false;
454}454}
455455
456pub fn isLibCxxLibName(target: std.Target, name: []const u8) bool {456pub fn isLibCxxLibName(target: *const std.Target, name: []const u8) bool {
457 const ignore_case = target.os.tag.isDarwin() or target.os.tag == .windows;457 const ignore_case = target.os.tag.isDarwin() or target.os.tag == .windows;
458458
459 return eqlIgnoreCase(ignore_case, name, "c++") or459 return eqlIgnoreCase(ignore_case, name, "c++") or
...@@ -470,11 +470,11 @@ fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool {...@@ -470,11 +470,11 @@ fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool {
470 }470 }
471}471}
472472
473pub fn intByteSize(target: std.Target, bits: u16) u19 {473pub fn intByteSize(target: *const std.Target, bits: u16) u19 {
474 return std.mem.alignForward(u19, @intCast((@as(u17, bits) + 7) / 8), intAlignment(target, bits));474 return std.mem.alignForward(u19, @intCast((@as(u17, bits) + 7) / 8), intAlignment(target, bits));
475}475}
476476
477pub fn intAlignment(target: std.Target, bits: u16) u16 {477pub fn intAlignment(target: *const std.Target, bits: u16) u16 {
478 return switch (target.cpu.arch) {478 return switch (target.cpu.arch) {
479 .x86 => switch (bits) {479 .x86 => switch (bits) {
480 0 => 0,480 0 => 0,
src/Compilation.zig+19-21
...@@ -1361,7 +1361,7 @@ pub const cache_helpers = struct {...@@ -1361,7 +1361,7 @@ pub const cache_helpers = struct {
1361 hh: *Cache.HashHelper,1361 hh: *Cache.HashHelper,
1362 resolved_target: Package.Module.ResolvedTarget,1362 resolved_target: Package.Module.ResolvedTarget,
1363 ) void {1363 ) void {
1364 const target = resolved_target.result;1364 const target = &resolved_target.result;
1365 hh.add(target.cpu.arch);1365 hh.add(target.cpu.arch);
1366 hh.addBytes(target.cpu.model.name);1366 hh.addBytes(target.cpu.model.name);
1367 hh.add(target.cpu.features.ints);1367 hh.add(target.cpu.features.ints);
...@@ -1705,7 +1705,7 @@ pub const CreateOptions = struct {...@@ -1705,7 +1705,7 @@ pub const CreateOptions = struct {
1705 assert(opts.cache_mode != .none);1705 assert(opts.cache_mode != .none);
1706 return try ea.cacheName(arena, .{1706 return try ea.cacheName(arena, .{
1707 .root_name = opts.root_name,1707 .root_name = opts.root_name,
1708 .target = opts.root_mod.resolved_target.result,1708 .target = &opts.root_mod.resolved_target.result,
1709 .output_mode = opts.config.output_mode,1709 .output_mode = opts.config.output_mode,
1710 .link_mode = opts.config.link_mode,1710 .link_mode = opts.config.link_mode,
1711 .version = opts.version,1711 .version = opts.version,
...@@ -1772,14 +1772,14 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1772,14 +1772,14 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1772 }1772 }
17731773
1774 const have_zcu = options.config.have_zcu;1774 const have_zcu = options.config.have_zcu;
1775 const use_llvm = options.config.use_llvm;
1776 const target = &options.root_mod.resolved_target.result;
17751777
1776 const comp: *Compilation = comp: {1778 const comp: *Compilation = comp: {
1777 // We put the `Compilation` itself in the arena. Freeing the arena will free the module.1779 // We put the `Compilation` itself in the arena. Freeing the arena will free the module.
1778 // It's initialized later after we prepare the initialization options.1780 // It's initialized later after we prepare the initialization options.
1779 const root_name = try arena.dupeZ(u8, options.root_name);1781 const root_name = try arena.dupeZ(u8, options.root_name);
17801782
1781 const use_llvm = options.config.use_llvm;
1782
1783 // The "any" values provided by resolved config only account for1783 // The "any" values provided by resolved config only account for
1784 // explicitly-provided settings. We now make them additionally account1784 // explicitly-provided settings. We now make them additionally account
1785 // for default setting resolution.1785 // for default setting resolution.
...@@ -1804,7 +1804,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1804,7 +1804,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1804 const libc_dirs = try std.zig.LibCDirs.detect(1804 const libc_dirs = try std.zig.LibCDirs.detect(
1805 arena,1805 arena,
1806 options.dirs.zig_lib.path.?,1806 options.dirs.zig_lib.path.?,
1807 options.root_mod.resolved_target.result,1807 target,
1808 options.root_mod.resolved_target.is_native_abi,1808 options.root_mod.resolved_target.is_native_abi,
1809 link_libc,1809 link_libc,
1810 options.libc_installation,1810 options.libc_installation,
...@@ -1846,7 +1846,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1846,7 +1846,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1846 // approach, since the ubsan runtime uses quite a lot of the standard library1846 // approach, since the ubsan runtime uses quite a lot of the standard library
1847 // and this reduces unnecessary bloat.1847 // and this reduces unnecessary bloat.
1848 const ubsan_rt_strat: RtStrat = s: {1848 const ubsan_rt_strat: RtStrat = s: {
1849 const can_build_ubsan_rt = target_util.canBuildLibUbsanRt(options.root_mod.resolved_target.result);1849 const can_build_ubsan_rt = target_util.canBuildLibUbsanRt(target);
1850 const want_ubsan_rt = options.want_ubsan_rt orelse (can_build_ubsan_rt and any_sanitize_c == .full and is_exe_or_dyn_lib);1850 const want_ubsan_rt = options.want_ubsan_rt orelse (can_build_ubsan_rt and any_sanitize_c == .full and is_exe_or_dyn_lib);
1851 if (!want_ubsan_rt) break :s .none;1851 if (!want_ubsan_rt) break :s .none;
1852 if (options.skip_linker_dependencies) break :s .none;1852 if (options.skip_linker_dependencies) break :s .none;
...@@ -1872,7 +1872,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1872,7 +1872,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18721872
1873 if (options.verbose_llvm_cpu_features) {1873 if (options.verbose_llvm_cpu_features) {
1874 if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {1874 if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {
1875 const target = options.root_mod.resolved_target.result;
1876 std.debug.lockStdErr();1875 std.debug.lockStdErr();
1877 defer std.debug.unlockStdErr();1876 defer std.debug.unlockStdErr();
1878 const stderr = std.io.getStdErr().writer();1877 const stderr = std.io.getStdErr().writer();
...@@ -2244,8 +2243,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -2244,8 +2243,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
2244 };2243 };
2245 errdefer comp.destroy();2244 errdefer comp.destroy();
22462245
2247 const target = comp.root_mod.resolved_target.result;2246 const can_build_compiler_rt = target_util.canBuildLibCompilerRt(target, use_llvm, build_options.have_llvm);
2248 const can_build_compiler_rt = target_util.canBuildLibCompilerRt(target, comp.config.use_llvm, build_options.have_llvm);
22492247
2250 // Add a `CObject` for each `c_source_files`.2248 // Add a `CObject` for each `c_source_files`.
2251 try comp.c_object_table.ensureTotalCapacity(gpa, options.c_source_files.len);2249 try comp.c_object_table.ensureTotalCapacity(gpa, options.c_source_files.len);
...@@ -2344,7 +2342,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -2344,7 +2342,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
2344 comp.link_task_queue.pending_prelink_tasks += 1;2342 comp.link_task_queue.pending_prelink_tasks += 1;
2345 }2343 }
2346 comp.queued_jobs.glibc_shared_objects = true;2344 comp.queued_jobs.glibc_shared_objects = true;
2347 comp.link_task_queue.pending_prelink_tasks += glibc.sharedObjectsCount(&target);2345 comp.link_task_queue.pending_prelink_tasks += glibc.sharedObjectsCount(target);
23482346
2349 comp.queued_jobs.glibc_crt_file[@intFromEnum(glibc.CrtFile.libc_nonshared_a)] = true;2347 comp.queued_jobs.glibc_crt_file[@intFromEnum(glibc.CrtFile.libc_nonshared_a)] = true;
2350 comp.link_task_queue.pending_prelink_tasks += 1;2348 comp.link_task_queue.pending_prelink_tasks += 1;
...@@ -2571,8 +2569,8 @@ pub fn clearMiscFailures(comp: *Compilation) void {...@@ -2571,8 +2569,8 @@ pub fn clearMiscFailures(comp: *Compilation) void {
2571 comp.misc_failures = .{};2569 comp.misc_failures = .{};
2572}2570}
25732571
2574pub fn getTarget(self: Compilation) Target {2572pub fn getTarget(self: *const Compilation) *const Target {
2575 return self.root_mod.resolved_target.result;2573 return &self.root_mod.resolved_target.result;
2576}2574}
25772575
2578/// Only legal to call when cache mode is incremental and a link file is present.2576/// Only legal to call when cache mode is incremental and a link file is present.
...@@ -3210,7 +3208,7 @@ fn addNonIncrementalStuffToCacheManifest(...@@ -3210,7 +3208,7 @@ fn addNonIncrementalStuffToCacheManifest(
3210 man.hash.addOptional(opts.image_base);3208 man.hash.addOptional(opts.image_base);
3211 man.hash.addOptional(opts.gc_sections);3209 man.hash.addOptional(opts.gc_sections);
3212 man.hash.add(opts.emit_relocs);3210 man.hash.add(opts.emit_relocs);
3213 const target = comp.root_mod.resolved_target.result;3211 const target = &comp.root_mod.resolved_target.result;
3214 if (target.ofmt == .macho or target.ofmt == .coff) {3212 if (target.ofmt == .macho or target.ofmt == .coff) {
3215 // TODO remove this, libraries need to be resolved by the frontend. this is already3213 // TODO remove this, libraries need to be resolved by the frontend. this is already
3216 // done by ELF.3214 // done by ELF.
...@@ -6270,7 +6268,7 @@ pub fn addCCArgs(...@@ -6270,7 +6268,7 @@ pub fn addCCArgs(
6270 out_dep_path: ?[]const u8,6268 out_dep_path: ?[]const u8,
6271 mod: *Package.Module,6269 mod: *Package.Module,
6272) !void {6270) !void {
6273 const target = mod.resolved_target.result;6271 const target = &mod.resolved_target.result;
62746272
6275 // As of Clang 16.x, it will by default read extra flags from /etc/clang.6273 // As of Clang 16.x, it will by default read extra flags from /etc/clang.
6276 // I'm sure the person who implemented this means well, but they have a lot6274 // I'm sure the person who implemented this means well, but they have a lot
...@@ -6944,7 +6942,7 @@ pub const FileExt = enum {...@@ -6944,7 +6942,7 @@ pub const FileExt = enum {
6944 };6942 };
6945 }6943 }
69466944
6947 pub fn canonicalName(ext: FileExt, target: Target) [:0]const u8 {6945 pub fn canonicalName(ext: FileExt, target: *const Target) [:0]const u8 {
6948 return switch (ext) {6946 return switch (ext) {
6949 .c => ".c",6947 .c => ".c",
6950 .cpp => ".cpp",6948 .cpp => ".cpp",
...@@ -7187,7 +7185,7 @@ pub fn dump_argv(argv: []const []const u8) void {...@@ -7187,7 +7185,7 @@ pub fn dump_argv(argv: []const []const u8) void {
7187}7185}
71887186
7189pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend {7187pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend {
7190 const target = comp.root_mod.resolved_target.result;7188 const target = &comp.root_mod.resolved_target.result;
7191 return target_util.zigBackend(target, comp.config.use_llvm);7189 return target_util.zigBackend(target, comp.config.use_llvm);
7192}7190}
71937191
...@@ -7371,7 +7369,7 @@ pub fn build_crt_file(...@@ -7371,7 +7369,7 @@ pub fn build_crt_file(
73717369
7372 const basename = try std.zig.binNameAlloc(gpa, .{7370 const basename = try std.zig.binNameAlloc(gpa, .{
7373 .root_name = root_name,7371 .root_name = root_name,
7374 .target = comp.root_mod.resolved_target.result,7372 .target = &comp.root_mod.resolved_target.result,
7375 .output_mode = output_mode,7373 .output_mode = output_mode,
7376 });7374 });
73777375
...@@ -7523,13 +7521,13 @@ pub fn getCrtPaths(...@@ -7523,13 +7521,13 @@ pub fn getCrtPaths(
7523 comp: *Compilation,7521 comp: *Compilation,
7524 arena: Allocator,7522 arena: Allocator,
7525) error{ OutOfMemory, LibCInstallationMissingCrtDir }!LibCInstallation.CrtPaths {7523) error{ OutOfMemory, LibCInstallationMissingCrtDir }!LibCInstallation.CrtPaths {
7526 const target = comp.root_mod.resolved_target.result;7524 const target = &comp.root_mod.resolved_target.result;
7527 return getCrtPathsInner(arena, target, comp.config, comp.libc_installation, &comp.crt_files);7525 return getCrtPathsInner(arena, target, comp.config, comp.libc_installation, &comp.crt_files);
7528}7526}
75297527
7530fn getCrtPathsInner(7528fn getCrtPathsInner(
7531 arena: Allocator,7529 arena: Allocator,
7532 target: std.Target,7530 target: *const std.Target,
7533 config: Config,7531 config: Config,
7534 libc_installation: ?*const LibCInstallation,7532 libc_installation: ?*const LibCInstallation,
7535 crt_files: *std.StringHashMapUnmanaged(CrtFile),7533 crt_files: *std.StringHashMapUnmanaged(CrtFile),
...@@ -7558,7 +7556,7 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -7558,7 +7556,7 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {
7558 // then when we create a sub-Compilation for zig libc, it also tries to7556 // then when we create a sub-Compilation for zig libc, it also tries to
7559 // build kernel32.lib.7557 // build kernel32.lib.
7560 if (comp.skip_linker_dependencies) return;7558 if (comp.skip_linker_dependencies) return;
7561 const target = comp.root_mod.resolved_target.result;7559 const target = &comp.root_mod.resolved_target.result;
7562 if (target.os.tag != .windows or target.ofmt == .c) return;7560 if (target.os.tag != .windows or target.ofmt == .c) return;
75637561
7564 // This happens when an `extern "foo"` function is referenced.7562 // This happens when an `extern "foo"` function is referenced.
...@@ -7574,7 +7572,7 @@ pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode {...@@ -7574,7 +7572,7 @@ pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode {
7574 if (comp.debug_compiler_runtime_libs) {7572 if (comp.debug_compiler_runtime_libs) {
7575 return comp.root_mod.optimize_mode;7573 return comp.root_mod.optimize_mode;
7576 }7574 }
7577 const target = comp.root_mod.resolved_target.result;7575 const target = &comp.root_mod.resolved_target.result;
7578 switch (comp.root_mod.optimize_mode) {7576 switch (comp.root_mod.optimize_mode) {
7579 .Debug, .ReleaseSafe => return target_util.defaultCompilerRtOptimizeMode(target),7577 .Debug, .ReleaseSafe => return target_util.defaultCompilerRtOptimizeMode(target),
7580 .ReleaseFast => return .ReleaseFast,7578 .ReleaseFast => return .ReleaseFast,
src/Compilation/Config.zig+1-1
...@@ -150,7 +150,7 @@ pub const ResolveError = error{...@@ -150,7 +150,7 @@ pub const ResolveError = error{
150};150};
151151
152pub fn resolve(options: Options) ResolveError!Config {152pub fn resolve(options: Options) ResolveError!Config {
153 const target = options.resolved_target.result;153 const target = &options.resolved_target.result;
154154
155 // WASI-only. Resolve the optional exec-model option, defaults to command.155 // WASI-only. Resolve the optional exec-model option, defaults to command.
156 if (target.os.tag != .wasi and options.wasi_exec_model != null)156 if (target.os.tag != .wasi and options.wasi_exec_model != null)
src/Package/Module.zig+3-3
...@@ -102,7 +102,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -102,7 +102,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
102 if (options.inherited.error_tracing == true) assert(options.global.any_error_tracing);102 if (options.inherited.error_tracing == true) assert(options.global.any_error_tracing);
103103
104 const resolved_target = options.inherited.resolved_target orelse options.parent.?.resolved_target;104 const resolved_target = options.inherited.resolved_target orelse options.parent.?.resolved_target;
105 const target = resolved_target.result;105 const target = &resolved_target.result;
106106
107 const optimize_mode = options.inherited.optimize_mode orelse107 const optimize_mode = options.inherited.optimize_mode orelse
108 if (options.parent) |p| p.optimize_mode else options.global.root_optimize_mode;108 if (options.parent) |p| p.optimize_mode else options.global.root_optimize_mode;
...@@ -363,7 +363,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -363,7 +363,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
363 .root_src_path = options.paths.root_src_path,363 .root_src_path = options.paths.root_src_path,
364 .fully_qualified_name = options.fully_qualified_name,364 .fully_qualified_name = options.fully_qualified_name,
365 .resolved_target = .{365 .resolved_target = .{
366 .result = target,366 .result = target.*,
367 .is_native_os = resolved_target.is_native_os,367 .is_native_os = resolved_target.is_native_os,
368 .is_native_abi = resolved_target.is_native_abi,368 .is_native_abi = resolved_target.is_native_abi,
369 .is_explicit_dynamic_linker = resolved_target.is_explicit_dynamic_linker,369 .is_explicit_dynamic_linker = resolved_target.is_explicit_dynamic_linker,
...@@ -474,7 +474,7 @@ pub fn getBuiltinOptions(m: Module, global: Compilation.Config) Builtin {...@@ -474,7 +474,7 @@ pub fn getBuiltinOptions(m: Module, global: Compilation.Config) Builtin {
474 assert(global.have_zcu);474 assert(global.have_zcu);
475 return .{475 return .{
476 .target = m.resolved_target.result,476 .target = m.resolved_target.result,
477 .zig_backend = target_util.zigBackend(m.resolved_target.result, global.use_llvm),477 .zig_backend = target_util.zigBackend(&m.resolved_target.result, global.use_llvm),
478 .output_mode = global.output_mode,478 .output_mode = global.output_mode,
479 .link_mode = global.link_mode,479 .link_mode = global.link_mode,
480 .unwind_tables = m.unwind_tables,480 .unwind_tables = m.unwind_tables,
src/Sema.zig+4-4
...@@ -29912,7 +29912,7 @@ pub fn coerceInMemoryAllowed(...@@ -29912,7 +29912,7 @@ pub fn coerceInMemoryAllowed(
29912 /// load from the `*Src` to effectively perform an in-memory coercion from `Dest` to `Src`.29912 /// load from the `*Src` to effectively perform an in-memory coercion from `Dest` to `Src`.
29913 /// Therefore, when `dest_is_mut`, the in-memory coercion must be valid in *both directions*.29913 /// Therefore, when `dest_is_mut`, the in-memory coercion must be valid in *both directions*.
29914 dest_is_mut: bool,29914 dest_is_mut: bool,
29915 target: std.Target,29915 target: *const std.Target,
29916 dest_src: LazySrcLoc,29916 dest_src: LazySrcLoc,
29917 src_src: LazySrcLoc,29917 src_src: LazySrcLoc,
29918 src_val: ?Value,29918 src_val: ?Value,
...@@ -30271,7 +30271,7 @@ fn coerceInMemoryAllowedFns(...@@ -30271,7 +30271,7 @@ fn coerceInMemoryAllowedFns(
30271 src_ty: Type,30271 src_ty: Type,
30272 /// If set, the coercion must be valid in both directions.30272 /// If set, the coercion must be valid in both directions.
30273 dest_is_mut: bool,30273 dest_is_mut: bool,
30274 target: std.Target,30274 target: *const std.Target,
30275 dest_src: LazySrcLoc,30275 dest_src: LazySrcLoc,
30276 src_src: LazySrcLoc,30276 src_src: LazySrcLoc,
30277) !InMemoryCoercionResult {30277) !InMemoryCoercionResult {
...@@ -30380,7 +30380,7 @@ fn coerceInMemoryAllowedFns(...@@ -30380,7 +30380,7 @@ fn coerceInMemoryAllowedFns(
30380}30380}
3038130381
30382fn callconvCoerceAllowed(30382fn callconvCoerceAllowed(
30383 target: std.Target,30383 target: *const std.Target,
30384 src_cc: std.builtin.CallingConvention,30384 src_cc: std.builtin.CallingConvention,
30385 dest_cc: std.builtin.CallingConvention,30385 dest_cc: std.builtin.CallingConvention,
30386) bool {30386) bool {
...@@ -30426,7 +30426,7 @@ fn coerceInMemoryAllowedPtrs(...@@ -30426,7 +30426,7 @@ fn coerceInMemoryAllowedPtrs(
30426 src_ptr_ty: Type,30426 src_ptr_ty: Type,
30427 /// If set, the coercion must be valid in both directions.30427 /// If set, the coercion must be valid in both directions.
30428 dest_is_mut: bool,30428 dest_is_mut: bool,
30429 target: std.Target,30429 target: *const std.Target,
30430 dest_src: LazySrcLoc,30430 dest_src: LazySrcLoc,
30431 src_src: LazySrcLoc,30431 src_src: LazySrcLoc,
30432) !InMemoryCoercionResult {30432) !InMemoryCoercionResult {
src/Type.zig+3-3
...@@ -1602,7 +1602,7 @@ fn abiSizeInnerOptional(...@@ -1602,7 +1602,7 @@ fn abiSizeInnerOptional(
1602 };1602 };
1603}1603}
16041604
1605pub fn ptrAbiAlignment(target: Target) Alignment {1605pub fn ptrAbiAlignment(target: *const Target) Alignment {
1606 return Alignment.fromNonzeroByteUnits(@divExact(target.ptrBitWidth(), 8));1606 return Alignment.fromNonzeroByteUnits(@divExact(target.ptrBitWidth(), 8));
1607}1607}
16081608
...@@ -2395,7 +2395,7 @@ pub fn isAnyFloat(ty: Type) bool {...@@ -2395,7 +2395,7 @@ pub fn isAnyFloat(ty: Type) bool {
23952395
2396/// Asserts the type is a fixed-size float or comptime_float.2396/// Asserts the type is a fixed-size float or comptime_float.
2397/// Returns 128 for comptime_float types.2397/// Returns 128 for comptime_float types.
2398pub fn floatBits(ty: Type, target: Target) u16 {2398pub fn floatBits(ty: Type, target: *const Target) u16 {
2399 return switch (ty.toIntern()) {2399 return switch (ty.toIntern()) {
2400 .f16_type => 16,2400 .f16_type => 16,
2401 .f32_type => 32,2401 .f32_type => 32,
...@@ -4188,6 +4188,6 @@ pub fn smallestUnsignedBits(max: u64) u16 {...@@ -4188,6 +4188,6 @@ pub fn smallestUnsignedBits(max: u64) u16 {
4188/// to packed struct layout to find out all the places in the codebase you need to edit!4188/// to packed struct layout to find out all the places in the codebase you need to edit!
4189pub const packed_struct_layout_version = 2;4189pub const packed_struct_layout_version = 2;
41904190
4191fn cTypeAlign(target: Target, c_type: Target.CType) Alignment {4191fn cTypeAlign(target: *const Target, c_type: Target.CType) Alignment {
4192 return Alignment.fromByteUnits(target.cTypeAlignment(c_type));4192 return Alignment.fromByteUnits(target.cTypeAlignment(c_type));
4193}4193}
src/Zcu.zig+3-3
...@@ -3773,8 +3773,8 @@ pub fn errNote(...@@ -3773,8 +3773,8 @@ pub fn errNote(
3773/// Deprecated. There is no global target for a Zig Compilation Unit. Instead,3773/// Deprecated. There is no global target for a Zig Compilation Unit. Instead,
3774/// look up the target based on the Module that contains the source code being3774/// look up the target based on the Module that contains the source code being
3775/// analyzed.3775/// analyzed.
3776pub fn getTarget(zcu: *const Zcu) Target {3776pub fn getTarget(zcu: *const Zcu) *const Target {
3777 return zcu.root_mod.resolved_target.result;3777 return &zcu.root_mod.resolved_target.result;
3778}3778}
37793779
3780/// Deprecated. There is no global optimization mode for a Zig Compilation3780/// Deprecated. There is no global optimization mode for a Zig Compilation
...@@ -3863,7 +3863,7 @@ pub const Feature = enum {...@@ -3863,7 +3863,7 @@ pub const Feature = enum {
3863};3863};
38643864
3865pub fn backendSupportsFeature(zcu: *const Zcu, comptime feature: Feature) bool {3865pub fn backendSupportsFeature(zcu: *const Zcu, comptime feature: Feature) bool {
3866 const backend = target_util.zigBackend(zcu.root_mod.resolved_target.result, zcu.comp.config.use_llvm);3866 const backend = target_util.zigBackend(&zcu.root_mod.resolved_target.result, zcu.comp.config.use_llvm);
3867 return target_util.backendSupportsFeature(backend, feature);3867 return target_util.backendSupportsFeature(backend, feature);
3868}3868}
38693869
src/Zcu/PerThread.zig+1-1
...@@ -4382,7 +4382,7 @@ pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air, ou...@@ -4382,7 +4382,7 @@ pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air, ou
4382 error.CodegenFail => zcu.assertCodegenFailed(zcu.funcInfo(func_index).owner_nav),4382 error.CodegenFail => zcu.assertCodegenFailed(zcu.funcInfo(func_index).owner_nav),
4383 error.NoLinkFile => assert(zcu.comp.bin_file == null),4383 error.NoLinkFile => assert(zcu.comp.bin_file == null),
4384 error.BackendDoesNotProduceMir => switch (target_util.zigBackend(4384 error.BackendDoesNotProduceMir => switch (target_util.zigBackend(
4385 zcu.root_mod.resolved_target.result,4385 &zcu.root_mod.resolved_target.result,
4386 zcu.comp.config.use_llvm,4386 zcu.comp.config.use_llvm,
4387 )) {4387 )) {
4388 else => unreachable, // assertion failure4388 else => unreachable, // assertion failure
src/arch/aarch64/CodeGen.zig+2-2
...@@ -6175,7 +6175,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {...@@ -6175,7 +6175,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
6175 self.pt,6175 self.pt,
6176 self.src_loc,6176 self.src_loc,
6177 val,6177 val,
6178 self.target.*,6178 self.target,
6179 )) {6179 )) {
6180 .mcv => |mcv| switch (mcv) {6180 .mcv => |mcv| switch (mcv) {
6181 .none => .none,6181 .none => .none,
...@@ -6379,7 +6379,7 @@ fn registerAlias(self: *Self, reg: Register, ty: Type) Register {...@@ -6379,7 +6379,7 @@ fn registerAlias(self: *Self, reg: Register, ty: Type) Register {
6379 },6379 },
6380 .stack_pointer => unreachable, // we can't store/load the sp6380 .stack_pointer => unreachable, // we can't store/load the sp
6381 .floating_point => {6381 .floating_point => {
6382 return switch (ty.floatBits(self.target.*)) {6382 return switch (ty.floatBits(self.target)) {
6383 16 => reg.toH(),6383 16 => reg.toH(),
6384 32 => reg.toS(),6384 32 => reg.toS(),
6385 64 => reg.toD(),6385 64 => reg.toD(),
src/arch/arm/CodeGen.zig+1-1
...@@ -6148,7 +6148,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {...@@ -6148,7 +6148,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
6148 pt,6148 pt,
6149 self.src_loc,6149 self.src_loc,
6150 val,6150 val,
6151 self.target.*,6151 self.target,
6152 )) {6152 )) {
6153 .mcv => |mcv| switch (mcv) {6153 .mcv => |mcv| switch (mcv) {
6154 .none => .none,6154 .none => .none,
src/arch/riscv64/CodeGen.zig+5-5
...@@ -1881,7 +1881,7 @@ fn memSize(func: *Func, ty: Type) Memory.Size {...@@ -1881,7 +1881,7 @@ fn memSize(func: *Func, ty: Type) Memory.Size {
1881 const pt = func.pt;1881 const pt = func.pt;
1882 const zcu = pt.zcu;1882 const zcu = pt.zcu;
1883 return switch (ty.zigTypeTag(zcu)) {1883 return switch (ty.zigTypeTag(zcu)) {
1884 .float => Memory.Size.fromBitSize(ty.floatBits(func.target.*)),1884 .float => Memory.Size.fromBitSize(ty.floatBits(func.target)),
1885 else => Memory.Size.fromByteSize(ty.abiSize(zcu)),1885 else => Memory.Size.fromByteSize(ty.abiSize(zcu)),
1886 };1886 };
1887}1887}
...@@ -2401,7 +2401,7 @@ fn binOp(...@@ -2401,7 +2401,7 @@ fn binOp(
2401 const rhs_ty = func.typeOf(rhs_air);2401 const rhs_ty = func.typeOf(rhs_air);
24022402
2403 if (lhs_ty.isRuntimeFloat()) libcall: {2403 if (lhs_ty.isRuntimeFloat()) libcall: {
2404 const float_bits = lhs_ty.floatBits(func.target.*);2404 const float_bits = lhs_ty.floatBits(func.target);
2405 const type_needs_libcall = switch (float_bits) {2405 const type_needs_libcall = switch (float_bits) {
2406 16 => true,2406 16 => true,
2407 32, 64 => false,2407 32, 64 => false,
...@@ -5189,7 +5189,7 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {...@@ -5189,7 +5189,7 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
5189 }5189 }
5190 },5190 },
5191 .float => {5191 .float => {
5192 const float_bits = lhs_ty.floatBits(func.target.*);5192 const float_bits = lhs_ty.floatBits(func.target);
5193 const float_reg_size: u32 = if (func.hasFeature(.d)) 64 else 32;5193 const float_reg_size: u32 = if (func.hasFeature(.d)) 64 else 32;
5194 if (float_bits > float_reg_size) {5194 if (float_bits > float_reg_size) {
5195 return func.fail("TODO: airCmp float > 64/32 bits", .{});5195 return func.fail("TODO: airCmp float > 64/32 bits", .{});
...@@ -8195,7 +8195,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {...@@ -8195,7 +8195,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {
8195 const result = if (val.isUndef(pt.zcu))8195 const result = if (val.isUndef(pt.zcu))
8196 try lf.lowerUav(pt, val.toIntern(), .none, src_loc)8196 try lf.lowerUav(pt, val.toIntern(), .none, src_loc)
8197 else8197 else
8198 try codegen.genTypedValue(lf, pt, src_loc, val, func.target.*);8198 try codegen.genTypedValue(lf, pt, src_loc, val, func.target);
8199 const mcv: MCValue = switch (result) {8199 const mcv: MCValue = switch (result) {
8200 .mcv => |mcv| switch (mcv) {8200 .mcv => |mcv| switch (mcv) {
8201 .none => .none,8201 .none => .none,
...@@ -8484,7 +8484,7 @@ fn promoteInt(func: *Func, ty: Type) Type {...@@ -8484,7 +8484,7 @@ fn promoteInt(func: *Func, ty: Type) Type {
84848484
8485fn promoteVarArg(func: *Func, ty: Type) Type {8485fn promoteVarArg(func: *Func, ty: Type) Type {
8486 if (!ty.isRuntimeFloat()) return func.promoteInt(ty);8486 if (!ty.isRuntimeFloat()) return func.promoteInt(ty);
8487 switch (ty.floatBits(func.target.*)) {8487 switch (ty.floatBits(func.target)) {
8488 32, 64 => return Type.f64,8488 32, 64 => return Type.f64,
8489 else => |float_bits| {8489 else => |float_bits| {
8490 assert(float_bits == func.target.cTypeBitSize(.longdouble));8490 assert(float_bits == func.target.cTypeBitSize(.longdouble));
src/arch/sparc64/CodeGen.zig+1-1
...@@ -4088,7 +4088,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {...@@ -4088,7 +4088,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
4088 pt,4088 pt,
4089 self.src_loc,4089 self.src_loc,
4090 val,4090 val,
4091 self.target.*,4091 self.target,
4092 )) {4092 )) {
4093 .mcv => |mcv| switch (mcv) {4093 .mcv => |mcv| switch (mcv) {
4094 .none => .none,4094 .none => .none,
src/arch/wasm/CodeGen.zig+15-15
...@@ -982,7 +982,7 @@ fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {...@@ -982,7 +982,7 @@ fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
982pub fn typeToValtype(ty: Type, zcu: *const Zcu, target: *const std.Target) std.wasm.Valtype {982pub fn typeToValtype(ty: Type, zcu: *const Zcu, target: *const std.Target) std.wasm.Valtype {
983 const ip = &zcu.intern_pool;983 const ip = &zcu.intern_pool;
984 return switch (ty.zigTypeTag(zcu)) {984 return switch (ty.zigTypeTag(zcu)) {
985 .float => switch (ty.floatBits(target.*)) {985 .float => switch (ty.floatBits(target)) {
986 16 => .i32, // stored/loaded as u16986 16 => .i32, // stored/loaded as u16
987 32 => .f32,987 32 => .f32,
988 64 => .f64,988 64 => .f64,
...@@ -1715,7 +1715,7 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {...@@ -1715,7 +1715,7 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
1715 .vector => return determineSimdStoreStrategy(ty, zcu, target) == .unrolled,1715 .vector => return determineSimdStoreStrategy(ty, zcu, target) == .unrolled,
1716 .int => return ty.intInfo(zcu).bits > 64,1716 .int => return ty.intInfo(zcu).bits > 64,
1717 .@"enum" => return ty.intInfo(zcu).bits > 64,1717 .@"enum" => return ty.intInfo(zcu).bits > 64,
1718 .float => return ty.floatBits(target.*) > 64,1718 .float => return ty.floatBits(target) > 64,
1719 .error_union => {1719 .error_union => {
1720 const pl_ty = ty.errorUnionPayload(zcu);1720 const pl_ty = ty.errorUnionPayload(zcu);
1721 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {1721 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
...@@ -2904,7 +2904,7 @@ fn floatOp(cg: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) Inne...@@ -2904,7 +2904,7 @@ fn floatOp(cg: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) Inne
2904 return cg.fail("TODO: Implement floatOps for vectors", .{});2904 return cg.fail("TODO: Implement floatOps for vectors", .{});
2905 }2905 }
29062906
2907 const float_bits = ty.floatBits(cg.target.*);2907 const float_bits = ty.floatBits(cg.target);
29082908
2909 if (float_op == .neg) {2909 if (float_op == .neg) {
2910 return cg.floatNeg(ty, args[0]);2910 return cg.floatNeg(ty, args[0]);
...@@ -2931,7 +2931,7 @@ fn floatOp(cg: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) Inne...@@ -2931,7 +2931,7 @@ fn floatOp(cg: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) Inne
29312931
2932/// NOTE: The result value remains on top of the stack.2932/// NOTE: The result value remains on top of the stack.
2933fn floatNeg(cg: *CodeGen, ty: Type, arg: WValue) InnerError!WValue {2933fn floatNeg(cg: *CodeGen, ty: Type, arg: WValue) InnerError!WValue {
2934 const float_bits = ty.floatBits(cg.target.*);2934 const float_bits = ty.floatBits(cg.target);
2935 switch (float_bits) {2935 switch (float_bits) {
2936 16 => {2936 16 => {
2937 try cg.emitWValue(arg);2937 try cg.emitWValue(arg);
...@@ -3300,7 +3300,7 @@ fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {...@@ -3300,7 +3300,7 @@ fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {
3300 33...64 => return .{ .imm64 = 0xaaaaaaaaaaaaaaaa },3300 33...64 => return .{ .imm64 = 0xaaaaaaaaaaaaaaaa },
3301 else => unreachable,3301 else => unreachable,
3302 },3302 },
3303 .float => switch (ty.floatBits(cg.target.*)) {3303 .float => switch (ty.floatBits(cg.target)) {
3304 16 => return .{ .imm32 = 0xaaaaaaaa },3304 16 => return .{ .imm32 = 0xaaaaaaaa },
3305 32 => return .{ .float32 = @as(f32, @bitCast(@as(u32, 0xaaaaaaaa))) },3305 32 => return .{ .float32 = @as(f32, @bitCast(@as(u32, 0xaaaaaaaa))) },
3306 64 => return .{ .float64 = @as(f64, @bitCast(@as(u64, 0xaaaaaaaaaaaaaaaa))) },3306 64 => return .{ .float64 = @as(f64, @bitCast(@as(u64, 0xaaaaaaaaaaaaaaaa))) },
...@@ -3507,7 +3507,7 @@ fn cmp(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareOpe...@@ -3507,7 +3507,7 @@ fn cmp(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareOpe
3507/// Compares two floats.3507/// Compares two floats.
3508/// NOTE: Leaves the result of the comparison on top of the stack.3508/// NOTE: Leaves the result of the comparison on top of the stack.
3509fn cmpFloat(cg: *CodeGen, ty: Type, lhs: WValue, rhs: WValue, cmp_op: std.math.CompareOperator) InnerError!WValue {3509fn cmpFloat(cg: *CodeGen, ty: Type, lhs: WValue, rhs: WValue, cmp_op: std.math.CompareOperator) InnerError!WValue {
3510 const float_bits = ty.floatBits(cg.target.*);3510 const float_bits = ty.floatBits(cg.target);
35113511
3512 const op: Op = switch (cmp_op) {3512 const op: Op = switch (cmp_op) {
3513 .lt => .lt,3513 .lt => .lt,
...@@ -4919,7 +4919,7 @@ fn airIntFromFloat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4919,7 +4919,7 @@ fn airIntFromFloat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49194919
4920 const operand = try cg.resolveInst(ty_op.operand);4920 const operand = try cg.resolveInst(ty_op.operand);
4921 const op_ty = cg.typeOf(ty_op.operand);4921 const op_ty = cg.typeOf(ty_op.operand);
4922 const op_bits = op_ty.floatBits(cg.target.*);4922 const op_bits = op_ty.floatBits(cg.target);
49234923
4924 const dest_ty = cg.typeOfIndex(inst);4924 const dest_ty = cg.typeOfIndex(inst);
4925 const dest_info = dest_ty.intInfo(zcu);4925 const dest_info = dest_ty.intInfo(zcu);
...@@ -4973,7 +4973,7 @@ fn airFloatFromInt(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4973,7 +4973,7 @@ fn airFloatFromInt(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4973 const op_info = op_ty.intInfo(zcu);4973 const op_info = op_ty.intInfo(zcu);
49744974
4975 const dest_ty = cg.typeOfIndex(inst);4975 const dest_ty = cg.typeOfIndex(inst);
4976 const dest_bits = dest_ty.floatBits(cg.target.*);4976 const dest_bits = dest_ty.floatBits(cg.target);
49774977
4978 if (op_info.bits > 128) {4978 if (op_info.bits > 128) {
4979 return cg.fail("TODO: floatFromInt for integers/floats with bitsize {d} bits", .{op_info.bits});4979 return cg.fail("TODO: floatFromInt for integers/floats with bitsize {d} bits", .{op_info.bits});
...@@ -5567,8 +5567,8 @@ fn airFpext(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5567,8 +5567,8 @@ fn airFpext(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5567/// Extends a float from a given `Type` to a larger wanted `Type`, leaving the5567/// Extends a float from a given `Type` to a larger wanted `Type`, leaving the
5568/// result on the stack.5568/// result on the stack.
5569fn fpext(cg: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {5569fn fpext(cg: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {
5570 const given_bits = given.floatBits(cg.target.*);5570 const given_bits = given.floatBits(cg.target);
5571 const wanted_bits = wanted.floatBits(cg.target.*);5571 const wanted_bits = wanted.floatBits(cg.target);
55725572
5573 const intrinsic: Mir.Intrinsic = switch (given_bits) {5573 const intrinsic: Mir.Intrinsic = switch (given_bits) {
5574 16 => switch (wanted_bits) {5574 16 => switch (wanted_bits) {
...@@ -5621,8 +5621,8 @@ fn airFptrunc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5621,8 +5621,8 @@ fn airFptrunc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5621/// Truncates a float from a given `Type` to its wanted `Type`, leaving the5621/// Truncates a float from a given `Type` to its wanted `Type`, leaving the
5622/// result on the stack.5622/// result on the stack.
5623fn fptrunc(cg: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {5623fn fptrunc(cg: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {
5624 const given_bits = given.floatBits(cg.target.*);5624 const given_bits = given.floatBits(cg.target);
5625 const wanted_bits = wanted.floatBits(cg.target.*);5625 const wanted_bits = wanted.floatBits(cg.target);
56265626
5627 const intrinsic: Mir.Intrinsic = switch (given_bits) {5627 const intrinsic: Mir.Intrinsic = switch (given_bits) {
5628 32 => switch (wanted_bits) {5628 32 => switch (wanted_bits) {
...@@ -6231,7 +6231,7 @@ fn airMaxMin(...@@ -6231,7 +6231,7 @@ fn airMaxMin(
62316231
6232 if (ty.zigTypeTag(zcu) == .float) {6232 if (ty.zigTypeTag(zcu) == .float) {
6233 const intrinsic = switch (op) {6233 const intrinsic = switch (op) {
6234 inline .fmin, .fmax => |ct_op| switch (ty.floatBits(cg.target.*)) {6234 inline .fmin, .fmax => |ct_op| switch (ty.floatBits(cg.target)) {
6235 inline 16, 32, 64, 80, 128 => |bits| @field(6235 inline 16, 32, 64, 80, 128 => |bits| @field(
6236 Mir.Intrinsic,6236 Mir.Intrinsic,
6237 libcFloatPrefix(bits) ++ @tagName(ct_op) ++ libcFloatSuffix(bits),6237 libcFloatPrefix(bits) ++ @tagName(ct_op) ++ libcFloatSuffix(bits),
...@@ -6268,7 +6268,7 @@ fn airMulAdd(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6268,7 +6268,7 @@ fn airMulAdd(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6268 const lhs = try cg.resolveInst(bin_op.lhs);6268 const lhs = try cg.resolveInst(bin_op.lhs);
6269 const rhs = try cg.resolveInst(bin_op.rhs);6269 const rhs = try cg.resolveInst(bin_op.rhs);
62706270
6271 const result = if (ty.floatBits(cg.target.*) == 16) fl_result: {6271 const result = if (ty.floatBits(cg.target) == 16) fl_result: {
6272 const rhs_ext = try cg.fpext(rhs, ty, Type.f32);6272 const rhs_ext = try cg.fpext(rhs, ty, Type.f32);
6273 const lhs_ext = try cg.fpext(lhs, ty, Type.f32);6273 const lhs_ext = try cg.fpext(lhs, ty, Type.f32);
6274 const addend_ext = try cg.fpext(addend, ty, Type.f32);6274 const addend_ext = try cg.fpext(addend, ty, Type.f32);
...@@ -6667,7 +6667,7 @@ fn airDivFloor(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6667,7 +6667,7 @@ fn airDivFloor(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6667 _ = try cg.wrapOperand(.stack, ty);6667 _ = try cg.wrapOperand(.stack, ty);
6668 }6668 }
6669 } else {6669 } else {
6670 const float_bits = ty.floatBits(cg.target.*);6670 const float_bits = ty.floatBits(cg.target);
6671 if (float_bits > 64) {6671 if (float_bits > 64) {
6672 return cg.fail("TODO: `@divFloor` for floats with bitsize: {d}", .{float_bits});6672 return cg.fail("TODO: `@divFloor` for floats with bitsize: {d}", .{float_bits});
6673 }6673 }
src/arch/x86_64/CodeGen.zig+51-51
...@@ -163704,7 +163704,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok...@@ -163704,7 +163704,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok
163704163704
163705 if (reg_ok) need_mem: {163705 if (reg_ok) need_mem: {
163706 if (std.math.isPowerOfTwo(abi_size) and abi_size <= @as(u32, max_abi_size: switch (ty.zigTypeTag(zcu)) {163706 if (std.math.isPowerOfTwo(abi_size) and abi_size <= @as(u32, max_abi_size: switch (ty.zigTypeTag(zcu)) {
163707 .float => switch (ty.floatBits(self.target.*)) {163707 .float => switch (ty.floatBits(self.target)) {
163708 16, 32, 64, 128 => 16,163708 16, 32, 64, 128 => 16,
163709 80 => break :need_mem,163709 80 => break :need_mem,
163710 else => unreachable,163710 else => unreachable,
...@@ -163993,9 +163993,9 @@ fn airRetPtr(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -163993,9 +163993,9 @@ fn airRetPtr(self: *CodeGen, inst: Air.Inst.Index) !void {
163993fn airFptrunc(self: *CodeGen, inst: Air.Inst.Index) !void {163993fn airFptrunc(self: *CodeGen, inst: Air.Inst.Index) !void {
163994 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;163994 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
163995 const dst_ty = self.typeOfIndex(inst);163995 const dst_ty = self.typeOfIndex(inst);
163996 const dst_bits = dst_ty.floatBits(self.target.*);163996 const dst_bits = dst_ty.floatBits(self.target);
163997 const src_ty = self.typeOf(ty_op.operand);163997 const src_ty = self.typeOf(ty_op.operand);
163998 const src_bits = src_ty.floatBits(self.target.*);163998 const src_bits = src_ty.floatBits(self.target);
163999163999
164000 const result = result: {164000 const result = result: {
164001 if (switch (dst_bits) {164001 if (switch (dst_bits) {
...@@ -164095,10 +164095,10 @@ fn airFpext(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -164095,10 +164095,10 @@ fn airFpext(self: *CodeGen, inst: Air.Inst.Index) !void {
164095 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;164095 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
164096 const dst_ty = self.typeOfIndex(inst);164096 const dst_ty = self.typeOfIndex(inst);
164097 const dst_scalar_ty = dst_ty.scalarType(zcu);164097 const dst_scalar_ty = dst_ty.scalarType(zcu);
164098 const dst_bits = dst_scalar_ty.floatBits(self.target.*);164098 const dst_bits = dst_scalar_ty.floatBits(self.target);
164099 const src_ty = self.typeOf(ty_op.operand);164099 const src_ty = self.typeOf(ty_op.operand);
164100 const src_scalar_ty = src_ty.scalarType(zcu);164100 const src_scalar_ty = src_ty.scalarType(zcu);
164101 const src_bits = src_scalar_ty.floatBits(self.target.*);164101 const src_bits = src_scalar_ty.floatBits(self.target);
164102164102
164103 const result = result: {164103 const result = result: {
164104 if (switch (src_bits) {164104 if (switch (src_bits) {
...@@ -168207,7 +168207,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A...@@ -168207,7 +168207,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
168207 const zcu = pt.zcu;168207 const zcu = pt.zcu;
168208168208
168209 const result = result: {168209 const result = result: {
168210 const scalar_bits = ty.scalarType(zcu).floatBits(self.target.*);168210 const scalar_bits = ty.scalarType(zcu).floatBits(self.target);
168211 if (scalar_bits == 80) {168211 if (scalar_bits == 80) {
168212 if (ty.zigTypeTag(zcu) != .float) return self.fail("TODO implement floatSign for {}", .{168212 if (ty.zigTypeTag(zcu) != .float) return self.fail("TODO implement floatSign for {}", .{
168213 ty.fmt(pt),168213 ty.fmt(pt),
...@@ -168363,14 +168363,14 @@ fn getRoundTag(self: *CodeGen, ty: Type) ?Mir.Inst.FixedTag {...@@ -168363,14 +168363,14 @@ fn getRoundTag(self: *CodeGen, ty: Type) ?Mir.Inst.FixedTag {
168363 const pt = self.pt;168363 const pt = self.pt;
168364 const zcu = pt.zcu;168364 const zcu = pt.zcu;
168365 return if (self.hasFeature(.sse4_1)) switch (ty.zigTypeTag(zcu)) {168365 return if (self.hasFeature(.sse4_1)) switch (ty.zigTypeTag(zcu)) {
168366 .float => switch (ty.floatBits(self.target.*)) {168366 .float => switch (ty.floatBits(self.target)) {
168367 32 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },168367 32 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
168368 64 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },168368 64 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },
168369 16, 80, 128 => null,168369 16, 80, 128 => null,
168370 else => unreachable,168370 else => unreachable,
168371 },168371 },
168372 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {168372 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
168373 .float => switch (ty.childType(zcu).floatBits(self.target.*)) {168373 .float => switch (ty.childType(zcu).floatBits(self.target)) {
168374 32 => switch (ty.vectorLen(zcu)) {168374 32 => switch (ty.vectorLen(zcu)) {
168375 1 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },168375 1 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
168376 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else .{ ._ps, .round },168376 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else .{ ._ps, .round },
...@@ -168670,7 +168670,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -168670,7 +168670,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {
168670 const result: MCValue = result: {168670 const result: MCValue = result: {
168671 switch (ty.zigTypeTag(zcu)) {168671 switch (ty.zigTypeTag(zcu)) {
168672 .float => {168672 .float => {
168673 const float_bits = ty.floatBits(self.target.*);168673 const float_bits = ty.floatBits(self.target);
168674 if (switch (float_bits) {168674 if (switch (float_bits) {
168675 16 => !self.hasFeature(.f16c),168675 16 => !self.hasFeature(.f16c),
168676 32, 64 => false,168676 32, 64 => false,
...@@ -168701,7 +168701,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -168701,7 +168701,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {
168701 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);168701 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
168702168702
168703 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(zcu)) {168703 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(zcu)) {
168704 .float => switch (ty.floatBits(self.target.*)) {168704 .float => switch (ty.floatBits(self.target)) {
168705 16 => {168705 16 => {
168706 assert(self.hasFeature(.f16c));168706 assert(self.hasFeature(.f16c));
168707 const mat_src_reg = if (src_mcv.isRegister())168707 const mat_src_reg = if (src_mcv.isRegister())
...@@ -168723,7 +168723,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -168723,7 +168723,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {
168723 else => unreachable,168723 else => unreachable,
168724 },168724 },
168725 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {168725 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
168726 .float => switch (ty.childType(zcu).floatBits(self.target.*)) {168726 .float => switch (ty.childType(zcu).floatBits(self.target)) {
168727 16 => if (self.hasFeature(.f16c)) switch (ty.vectorLen(zcu)) {168727 16 => if (self.hasFeature(.f16c)) switch (ty.vectorLen(zcu)) {
168728 1 => {168728 1 => {
168729 try self.asmRegisterRegister(168729 try self.asmRegisterRegister(
...@@ -170904,7 +170904,7 @@ fn genBinOp(...@@ -170904,7 +170904,7 @@ fn genBinOp(
170904 const abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));170904 const abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));
170905170905
170906 if (lhs_ty.isRuntimeFloat()) libcall: {170906 if (lhs_ty.isRuntimeFloat()) libcall: {
170907 const float_bits = lhs_ty.floatBits(self.target.*);170907 const float_bits = lhs_ty.floatBits(self.target);
170908 const type_needs_libcall = switch (float_bits) {170908 const type_needs_libcall = switch (float_bits) {
170909 16 => !self.hasFeature(.f16c),170909 16 => !self.hasFeature(.f16c),
170910 32, 64 => false,170910 32, 64 => false,
...@@ -171083,7 +171083,7 @@ fn genBinOp(...@@ -171083,7 +171083,7 @@ fn genBinOp(
171083 },171083 },
171084 };171084 };
171085 if (sse_op and ((lhs_ty.scalarType(zcu).isRuntimeFloat() and171085 if (sse_op and ((lhs_ty.scalarType(zcu).isRuntimeFloat() and
171086 lhs_ty.scalarType(zcu).floatBits(self.target.*) == 80) or171086 lhs_ty.scalarType(zcu).floatBits(self.target) == 80) or
171087 lhs_ty.abiSize(zcu) > self.vectorSize(.float)))171087 lhs_ty.abiSize(zcu) > self.vectorSize(.float)))
171088 return self.fail("TODO implement genBinOp for {s} {}", .{ @tagName(air_tag), lhs_ty.fmt(pt) });171088 return self.fail("TODO implement genBinOp for {s} {}", .{ @tagName(air_tag), lhs_ty.fmt(pt) });
171089171089
...@@ -171474,7 +171474,7 @@ fn genBinOp(...@@ -171474,7 +171474,7 @@ fn genBinOp(
171474 const dst_reg = registerAlias(dst_mcv.getReg().?, abi_size);171474 const dst_reg = registerAlias(dst_mcv.getReg().?, abi_size);
171475 const mir_tag = @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {171475 const mir_tag = @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
171476 else => unreachable,171476 else => unreachable,
171477 .float => switch (lhs_ty.floatBits(self.target.*)) {171477 .float => switch (lhs_ty.floatBits(self.target)) {
171478 16 => {171478 16 => {
171479 assert(self.hasFeature(.f16c));171479 assert(self.hasFeature(.f16c));
171480 const lhs_reg = if (copied_to_dst) dst_reg else registerAlias(lhs_mcv.getReg().?, abi_size);171480 const lhs_reg = if (copied_to_dst) dst_reg else registerAlias(lhs_mcv.getReg().?, abi_size);
...@@ -171917,7 +171917,7 @@ fn genBinOp(...@@ -171917,7 +171917,7 @@ fn genBinOp(
171917 },171917 },
171918 else => null,171918 else => null,
171919 },171919 },
171920 .float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {171920 .float => switch (lhs_ty.childType(zcu).floatBits(self.target)) {
171921 16 => tag: {171921 16 => tag: {
171922 assert(self.hasFeature(.f16c));171922 assert(self.hasFeature(.f16c));
171923 const lhs_reg = if (copied_to_dst) dst_reg else registerAlias(lhs_mcv.getReg().?, abi_size);171923 const lhs_reg = if (copied_to_dst) dst_reg else registerAlias(lhs_mcv.getReg().?, abi_size);
...@@ -172336,14 +172336,14 @@ fn genBinOp(...@@ -172336,14 +172336,14 @@ fn genBinOp(
172336172336
172337 try self.asmRegisterRegisterRegisterImmediate(172337 try self.asmRegisterRegisterRegisterImmediate(
172338 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {172338 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
172339 .float => switch (lhs_ty.floatBits(self.target.*)) {172339 .float => switch (lhs_ty.floatBits(self.target)) {
172340 32 => .{ .v_ss, .cmp },172340 32 => .{ .v_ss, .cmp },
172341 64 => .{ .v_sd, .cmp },172341 64 => .{ .v_sd, .cmp },
172342 16, 80, 128 => null,172342 16, 80, 128 => null,
172343 else => unreachable,172343 else => unreachable,
172344 },172344 },
172345 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {172345 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
172346 .float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {172346 .float => switch (lhs_ty.childType(zcu).floatBits(self.target)) {
172347 32 => switch (lhs_ty.vectorLen(zcu)) {172347 32 => switch (lhs_ty.vectorLen(zcu)) {
172348 1 => .{ .v_ss, .cmp },172348 1 => .{ .v_ss, .cmp },
172349 2...8 => .{ .v_ps, .cmp },172349 2...8 => .{ .v_ps, .cmp },
...@@ -172370,14 +172370,14 @@ fn genBinOp(...@@ -172370,14 +172370,14 @@ fn genBinOp(
172370 );172370 );
172371 try self.asmRegisterRegisterRegisterRegister(172371 try self.asmRegisterRegisterRegisterRegister(
172372 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {172372 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
172373 .float => switch (lhs_ty.floatBits(self.target.*)) {172373 .float => switch (lhs_ty.floatBits(self.target)) {
172374 32 => .{ .v_ps, .blendv },172374 32 => .{ .v_ps, .blendv },
172375 64 => .{ .v_pd, .blendv },172375 64 => .{ .v_pd, .blendv },
172376 16, 80, 128 => null,172376 16, 80, 128 => null,
172377 else => unreachable,172377 else => unreachable,
172378 },172378 },
172379 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {172379 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
172380 .float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {172380 .float => switch (lhs_ty.childType(zcu).floatBits(self.target)) {
172381 32 => switch (lhs_ty.vectorLen(zcu)) {172381 32 => switch (lhs_ty.vectorLen(zcu)) {
172382 1...8 => .{ .v_ps, .blendv },172382 1...8 => .{ .v_ps, .blendv },
172383 else => null,172383 else => null,
...@@ -172404,14 +172404,14 @@ fn genBinOp(...@@ -172404,14 +172404,14 @@ fn genBinOp(
172404 const has_blend = self.hasFeature(.sse4_1);172404 const has_blend = self.hasFeature(.sse4_1);
172405 try self.asmRegisterRegisterImmediate(172405 try self.asmRegisterRegisterImmediate(
172406 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {172406 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
172407 .float => switch (lhs_ty.floatBits(self.target.*)) {172407 .float => switch (lhs_ty.floatBits(self.target)) {
172408 32 => .{ ._ss, .cmp },172408 32 => .{ ._ss, .cmp },
172409 64 => .{ ._sd, .cmp },172409 64 => .{ ._sd, .cmp },
172410 16, 80, 128 => null,172410 16, 80, 128 => null,
172411 else => unreachable,172411 else => unreachable,
172412 },172412 },
172413 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {172413 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
172414 .float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {172414 .float => switch (lhs_ty.childType(zcu).floatBits(self.target)) {
172415 32 => switch (lhs_ty.vectorLen(zcu)) {172415 32 => switch (lhs_ty.vectorLen(zcu)) {
172416 1 => .{ ._ss, .cmp },172416 1 => .{ ._ss, .cmp },
172417 2...4 => .{ ._ps, .cmp },172417 2...4 => .{ ._ps, .cmp },
...@@ -172437,14 +172437,14 @@ fn genBinOp(...@@ -172437,14 +172437,14 @@ fn genBinOp(
172437 );172437 );
172438 if (has_blend) try self.asmRegisterRegisterRegister(172438 if (has_blend) try self.asmRegisterRegisterRegister(
172439 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {172439 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
172440 .float => switch (lhs_ty.floatBits(self.target.*)) {172440 .float => switch (lhs_ty.floatBits(self.target)) {
172441 32 => .{ ._ps, .blendv },172441 32 => .{ ._ps, .blendv },
172442 64 => .{ ._pd, .blendv },172442 64 => .{ ._pd, .blendv },
172443 16, 80, 128 => null,172443 16, 80, 128 => null,
172444 else => unreachable,172444 else => unreachable,
172445 },172445 },
172446 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {172446 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
172447 .float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {172447 .float => switch (lhs_ty.childType(zcu).floatBits(self.target)) {
172448 32 => switch (lhs_ty.vectorLen(zcu)) {172448 32 => switch (lhs_ty.vectorLen(zcu)) {
172449 1...4 => .{ ._ps, .blendv },172449 1...4 => .{ ._ps, .blendv },
172450 else => null,172450 else => null,
...@@ -172467,14 +172467,14 @@ fn genBinOp(...@@ -172467,14 +172467,14 @@ fn genBinOp(
172467 mask_reg,172467 mask_reg,
172468 ) else {172468 ) else {
172469 const mir_fixes = @as(?Mir.Inst.Fixes, switch (lhs_ty.zigTypeTag(zcu)) {172469 const mir_fixes = @as(?Mir.Inst.Fixes, switch (lhs_ty.zigTypeTag(zcu)) {
172470 .float => switch (lhs_ty.floatBits(self.target.*)) {172470 .float => switch (lhs_ty.floatBits(self.target)) {
172471 32 => ._ps,172471 32 => ._ps,
172472 64 => ._pd,172472 64 => ._pd,
172473 16, 80, 128 => null,172473 16, 80, 128 => null,
172474 else => unreachable,172474 else => unreachable,
172475 },172475 },
172476 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {172476 .vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
172477 .float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {172477 .float => switch (lhs_ty.childType(zcu).floatBits(self.target)) {
172478 32 => switch (lhs_ty.vectorLen(zcu)) {172478 32 => switch (lhs_ty.vectorLen(zcu)) {
172479 1...4 => ._ps,172479 1...4 => ._ps,
172480 else => null,172480 else => null,
...@@ -173832,7 +173832,7 @@ fn airCmp(self: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !v...@@ -173832,7 +173832,7 @@ fn airCmp(self: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !v
173832173832
173833 switch (ty.zigTypeTag(zcu)) {173833 switch (ty.zigTypeTag(zcu)) {
173834 .float => {173834 .float => {
173835 const float_bits = ty.floatBits(self.target.*);173835 const float_bits = ty.floatBits(self.target);
173836 if (!switch (float_bits) {173836 if (!switch (float_bits) {
173837 16 => self.hasFeature(.f16c),173837 16 => self.hasFeature(.f16c),
173838 32 => self.hasFeature(.sse),173838 32 => self.hasFeature(.sse),
...@@ -174188,7 +174188,7 @@ fn airCmp(self: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !v...@@ -174188,7 +174188,7 @@ fn airCmp(self: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !v
174188 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);174188 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
174189 const src_mcv = if (flipped) lhs_mcv else rhs_mcv;174189 const src_mcv = if (flipped) lhs_mcv else rhs_mcv;
174190174190
174191 switch (ty.floatBits(self.target.*)) {174191 switch (ty.floatBits(self.target)) {
174192 16 => {174192 16 => {
174193 assert(self.hasFeature(.f16c));174193 assert(self.hasFeature(.f16c));
174194 const tmp1_reg =174194 const tmp1_reg =
...@@ -176335,7 +176335,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M...@@ -176335,7 +176335,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M
176335 else => {},176335 else => {},
176336 }176336 }
176337 },176337 },
176338 .float => switch (ty.floatBits(cg.target.*)) {176338 .float => switch (ty.floatBits(cg.target)) {
176339 16 => return if (cg.hasFeature(.avx)) .{ .vex_insert_extract = .{176339 16 => return if (cg.hasFeature(.avx)) .{ .vex_insert_extract = .{
176340 .insert = .{ .vp_w, .insr },176340 .insert = .{ .vp_w, .insr },
176341 .extract = .{ .vp_w, .extr },176341 .extract = .{ .vp_w, .extr },
...@@ -176482,7 +176482,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M...@@ -176482,7 +176482,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M
176482 }176482 }
176483 else176483 else
176484 unreachable,176484 unreachable,
176485 .float => switch (ty.childType(zcu).floatBits(cg.target.*)) {176485 .float => switch (ty.childType(zcu).floatBits(cg.target)) {
176486 16 => switch (ty.vectorLen(zcu)) {176486 16 => switch (ty.vectorLen(zcu)) {
176487 1...8 => return .{ .load_store = if (cg.hasFeature(.avx))176487 1...8 => return .{ .load_store = if (cg.hasFeature(.avx))
176488 .{ if (aligned) .v_dqa else .v_dqu, .mov }176488 .{ if (aligned) .v_dqa else .v_dqu, .mov }
...@@ -177017,7 +177017,7 @@ fn genSetReg(...@@ -177017,7 +177017,7 @@ fn genSetReg(
177017 17...32 => if (self.hasFeature(.avx)) .{ .v_dqa, .mov } else null,177017 17...32 => if (self.hasFeature(.avx)) .{ .v_dqa, .mov } else null,
177018 else => null,177018 else => null,
177019 },177019 },
177020 .float => switch (ty.scalarType(zcu).floatBits(self.target.*)) {177020 .float => switch (ty.scalarType(zcu).floatBits(self.target)) {
177021 16, 128 => switch (abi_size) {177021 16, 128 => switch (abi_size) {
177022 2...16 => if (self.hasFeature(.avx))177022 2...16 => if (self.hasFeature(.avx))
177023 .{ .v_dqa, .mov }177023 .{ .v_dqa, .mov }
...@@ -177776,7 +177776,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -177776,7 +177776,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {
177776 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;177776 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
177777177777
177778 const dst_ty = self.typeOfIndex(inst);177778 const dst_ty = self.typeOfIndex(inst);
177779 const dst_bits = dst_ty.floatBits(self.target.*);177779 const dst_bits = dst_ty.floatBits(self.target);
177780177780
177781 const src_ty = self.typeOf(ty_op.operand);177781 const src_ty = self.typeOf(ty_op.operand);
177782 const src_bits: u32 = @intCast(src_ty.bitSize(zcu));177782 const src_bits: u32 = @intCast(src_ty.bitSize(zcu));
...@@ -177828,7 +177828,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -177828,7 +177828,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {
177828 defer self.register_manager.unlockReg(dst_lock);177828 defer self.register_manager.unlockReg(dst_lock);
177829177829
177830 const mir_tag = @as(?Mir.Inst.FixedTag, switch (dst_ty.zigTypeTag(zcu)) {177830 const mir_tag = @as(?Mir.Inst.FixedTag, switch (dst_ty.zigTypeTag(zcu)) {
177831 .float => switch (dst_ty.floatBits(self.target.*)) {177831 .float => switch (dst_ty.floatBits(self.target)) {
177832 32 => if (self.hasFeature(.avx)) .{ .v_ss, .cvtsi2 } else .{ ._ss, .cvtsi2 },177832 32 => if (self.hasFeature(.avx)) .{ .v_ss, .cvtsi2 } else .{ ._ss, .cvtsi2 },
177833 64 => if (self.hasFeature(.avx)) .{ .v_sd, .cvtsi2 } else .{ ._sd, .cvtsi2 },177833 64 => if (self.hasFeature(.avx)) .{ .v_sd, .cvtsi2 } else .{ ._sd, .cvtsi2 },
177834 16, 80, 128 => null,177834 16, 80, 128 => null,
...@@ -177865,7 +177865,7 @@ fn airIntFromFloat(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -177865,7 +177865,7 @@ fn airIntFromFloat(self: *CodeGen, inst: Air.Inst.Index) !void {
177865 }, 32), 8) catch unreachable;177865 }, 32), 8) catch unreachable;
177866177866
177867 const src_ty = self.typeOf(ty_op.operand);177867 const src_ty = self.typeOf(ty_op.operand);
177868 const src_bits = src_ty.floatBits(self.target.*);177868 const src_bits = src_ty.floatBits(self.target);
177869177869
177870 const result = result: {177870 const result = result: {
177871 if (switch (src_bits) {177871 if (switch (src_bits) {
...@@ -178136,22 +178136,22 @@ fn atomicOp(...@@ -178136,22 +178136,22 @@ fn atomicOp(
178136 }178136 }
178137 if (rmw_op) |op| if (use_sse) {178137 if (rmw_op) |op| if (use_sse) {
178138 const mir_tag = @as(?Mir.Inst.FixedTag, switch (op) {178138 const mir_tag = @as(?Mir.Inst.FixedTag, switch (op) {
178139 .Add => switch (val_ty.floatBits(self.target.*)) {178139 .Add => switch (val_ty.floatBits(self.target)) {
178140 32 => if (self.hasFeature(.avx)) .{ .v_ss, .add } else .{ ._ss, .add },178140 32 => if (self.hasFeature(.avx)) .{ .v_ss, .add } else .{ ._ss, .add },
178141 64 => if (self.hasFeature(.avx)) .{ .v_sd, .add } else .{ ._sd, .add },178141 64 => if (self.hasFeature(.avx)) .{ .v_sd, .add } else .{ ._sd, .add },
178142 else => null,178142 else => null,
178143 },178143 },
178144 .Sub => switch (val_ty.floatBits(self.target.*)) {178144 .Sub => switch (val_ty.floatBits(self.target)) {
178145 32 => if (self.hasFeature(.avx)) .{ .v_ss, .sub } else .{ ._ss, .sub },178145 32 => if (self.hasFeature(.avx)) .{ .v_ss, .sub } else .{ ._ss, .sub },
178146 64 => if (self.hasFeature(.avx)) .{ .v_sd, .sub } else .{ ._sd, .sub },178146 64 => if (self.hasFeature(.avx)) .{ .v_sd, .sub } else .{ ._sd, .sub },
178147 else => null,178147 else => null,
178148 },178148 },
178149 .Min => switch (val_ty.floatBits(self.target.*)) {178149 .Min => switch (val_ty.floatBits(self.target)) {
178150 32 => if (self.hasFeature(.avx)) .{ .v_ss, .min } else .{ ._ss, .min },178150 32 => if (self.hasFeature(.avx)) .{ .v_ss, .min } else .{ ._ss, .min },
178151 64 => if (self.hasFeature(.avx)) .{ .v_sd, .min } else .{ ._sd, .min },178151 64 => if (self.hasFeature(.avx)) .{ .v_sd, .min } else .{ ._sd, .min },
178152 else => null,178152 else => null,
178153 },178153 },
178154 .Max => switch (val_ty.floatBits(self.target.*)) {178154 .Max => switch (val_ty.floatBits(self.target)) {
178155 32 => if (self.hasFeature(.avx)) .{ .v_ss, .max } else .{ ._ss, .max },178155 32 => if (self.hasFeature(.avx)) .{ .v_ss, .max } else .{ ._ss, .max },
178156 64 => if (self.hasFeature(.avx)) .{ .v_sd, .max } else .{ ._sd, .max },178156 64 => if (self.hasFeature(.avx)) .{ .v_sd, .max } else .{ ._sd, .max },
178157 else => null,178157 else => null,
...@@ -178988,7 +178988,7 @@ fn airSplat(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -178988,7 +178988,7 @@ fn airSplat(self: *CodeGen, inst: Air.Inst.Index) !void {
178988 );178988 );
178989 break :result .{ .register = dst_reg };178989 break :result .{ .register = dst_reg };
178990 },178990 },
178991 .float => switch (scalar_ty.floatBits(self.target.*)) {178991 .float => switch (scalar_ty.floatBits(self.target)) {
178992 32 => switch (vector_len) {178992 32 => switch (vector_len) {
178993 1 => {178993 1 => {
178994 const src_mcv = try self.resolveInst(ty_op.operand);178994 const src_mcv = try self.resolveInst(ty_op.operand);
...@@ -179581,7 +179581,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -179581,7 +179581,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
179581 null,179581 null,
179582 else => null,179582 else => null,
179583 },179583 },
179584 .float => switch (elem_ty.floatBits(self.target.*)) {179584 .float => switch (elem_ty.floatBits(self.target)) {
179585 else => unreachable,179585 else => unreachable,
179586 16, 80, 128 => null,179586 16, 80, 128 => null,
179587 32 => switch (vec_len) {179587 32 => switch (vec_len) {
...@@ -180308,7 +180308,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -180308,7 +180308,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
180308 defer self.register_manager.unlockReg(mask_lock);180308 defer self.register_manager.unlockReg(mask_lock);
180309180309
180310 const mir_fixes: Mir.Inst.Fixes = if (elem_ty.isRuntimeFloat())180310 const mir_fixes: Mir.Inst.Fixes = if (elem_ty.isRuntimeFloat())
180311 switch (elem_ty.floatBits(self.target.*)) {180311 switch (elem_ty.floatBits(self.target)) {
180312 16, 80, 128 => .p_,180312 16, 80, 128 => .p_,
180313 32 => ._ps,180313 32 => ._ps,
180314 64 => ._pd,180314 64 => ._pd,
...@@ -180414,7 +180414,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -180414,7 +180414,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
180414 .{ switch (elem_ty.zigTypeTag(zcu)) {180414 .{ switch (elem_ty.zigTypeTag(zcu)) {
180415 else => break :result null,180415 else => break :result null,
180416 .int => .vp_,180416 .int => .vp_,
180417 .float => switch (elem_ty.floatBits(self.target.*)) {180417 .float => switch (elem_ty.floatBits(self.target)) {
180418 32 => .v_ps,180418 32 => .v_ps,
180419 64 => .v_pd,180419 64 => .v_pd,
180420 16, 80, 128 => break :result null,180420 16, 80, 128 => break :result null,
...@@ -180428,7 +180428,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -180428,7 +180428,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
180428 .{ switch (elem_ty.zigTypeTag(zcu)) {180428 .{ switch (elem_ty.zigTypeTag(zcu)) {
180429 else => break :result null,180429 else => break :result null,
180430 .int => .p_,180430 .int => .p_,
180431 .float => switch (elem_ty.floatBits(self.target.*)) {180431 .float => switch (elem_ty.floatBits(self.target)) {
180432 32 => ._ps,180432 32 => ._ps,
180433 64 => ._pd,180433 64 => ._pd,
180434 16, 80, 128 => break :result null,180434 16, 80, 128 => break :result null,
...@@ -180800,7 +180800,7 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -180800,7 +180800,7 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
180800180800
180801 const ops = [3]Air.Inst.Ref{ extra.lhs, extra.rhs, pl_op.operand };180801 const ops = [3]Air.Inst.Ref{ extra.lhs, extra.rhs, pl_op.operand };
180802 const result = result: {180802 const result = result: {
180803 if (switch (ty.scalarType(zcu).floatBits(self.target.*)) {180803 if (switch (ty.scalarType(zcu).floatBits(self.target)) {
180804 16, 80, 128 => true,180804 16, 80, 128 => true,
180805 32, 64 => !self.hasFeature(.fma),180805 32, 64 => !self.hasFeature(.fma),
180806 else => unreachable,180806 else => unreachable,
...@@ -180855,14 +180855,14 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -180855,14 +180855,14 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
180855 const mir_tag = @as(?Mir.Inst.FixedTag, if (std.mem.eql(u2, &order, &.{ 1, 3, 2 }) or180855 const mir_tag = @as(?Mir.Inst.FixedTag, if (std.mem.eql(u2, &order, &.{ 1, 3, 2 }) or
180856 std.mem.eql(u2, &order, &.{ 3, 1, 2 }))180856 std.mem.eql(u2, &order, &.{ 3, 1, 2 }))
180857 switch (ty.zigTypeTag(zcu)) {180857 switch (ty.zigTypeTag(zcu)) {
180858 .float => switch (ty.floatBits(self.target.*)) {180858 .float => switch (ty.floatBits(self.target)) {
180859 32 => .{ .v_ss, .fmadd132 },180859 32 => .{ .v_ss, .fmadd132 },
180860 64 => .{ .v_sd, .fmadd132 },180860 64 => .{ .v_sd, .fmadd132 },
180861 16, 80, 128 => null,180861 16, 80, 128 => null,
180862 else => unreachable,180862 else => unreachable,
180863 },180863 },
180864 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {180864 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
180865 .float => switch (ty.childType(zcu).floatBits(self.target.*)) {180865 .float => switch (ty.childType(zcu).floatBits(self.target)) {
180866 32 => switch (ty.vectorLen(zcu)) {180866 32 => switch (ty.vectorLen(zcu)) {
180867 1 => .{ .v_ss, .fmadd132 },180867 1 => .{ .v_ss, .fmadd132 },
180868 2...8 => .{ .v_ps, .fmadd132 },180868 2...8 => .{ .v_ps, .fmadd132 },
...@@ -180882,14 +180882,14 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -180882,14 +180882,14 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
180882 }180882 }
180883 else if (std.mem.eql(u2, &order, &.{ 2, 1, 3 }) or std.mem.eql(u2, &order, &.{ 1, 2, 3 }))180883 else if (std.mem.eql(u2, &order, &.{ 2, 1, 3 }) or std.mem.eql(u2, &order, &.{ 1, 2, 3 }))
180884 switch (ty.zigTypeTag(zcu)) {180884 switch (ty.zigTypeTag(zcu)) {
180885 .float => switch (ty.floatBits(self.target.*)) {180885 .float => switch (ty.floatBits(self.target)) {
180886 32 => .{ .v_ss, .fmadd213 },180886 32 => .{ .v_ss, .fmadd213 },
180887 64 => .{ .v_sd, .fmadd213 },180887 64 => .{ .v_sd, .fmadd213 },
180888 16, 80, 128 => null,180888 16, 80, 128 => null,
180889 else => unreachable,180889 else => unreachable,
180890 },180890 },
180891 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {180891 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
180892 .float => switch (ty.childType(zcu).floatBits(self.target.*)) {180892 .float => switch (ty.childType(zcu).floatBits(self.target)) {
180893 32 => switch (ty.vectorLen(zcu)) {180893 32 => switch (ty.vectorLen(zcu)) {
180894 1 => .{ .v_ss, .fmadd213 },180894 1 => .{ .v_ss, .fmadd213 },
180895 2...8 => .{ .v_ps, .fmadd213 },180895 2...8 => .{ .v_ps, .fmadd213 },
...@@ -180909,14 +180909,14 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -180909,14 +180909,14 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
180909 }180909 }
180910 else if (std.mem.eql(u2, &order, &.{ 2, 3, 1 }) or std.mem.eql(u2, &order, &.{ 3, 2, 1 }))180910 else if (std.mem.eql(u2, &order, &.{ 2, 3, 1 }) or std.mem.eql(u2, &order, &.{ 3, 2, 1 }))
180911 switch (ty.zigTypeTag(zcu)) {180911 switch (ty.zigTypeTag(zcu)) {
180912 .float => switch (ty.floatBits(self.target.*)) {180912 .float => switch (ty.floatBits(self.target)) {
180913 32 => .{ .v_ss, .fmadd231 },180913 32 => .{ .v_ss, .fmadd231 },
180914 64 => .{ .v_sd, .fmadd231 },180914 64 => .{ .v_sd, .fmadd231 },
180915 16, 80, 128 => null,180915 16, 80, 128 => null,
180916 else => unreachable,180916 else => unreachable,
180917 },180917 },
180918 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {180918 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
180919 .float => switch (ty.childType(zcu).floatBits(self.target.*)) {180919 .float => switch (ty.childType(zcu).floatBits(self.target)) {
180920 32 => switch (ty.vectorLen(zcu)) {180920 32 => switch (ty.vectorLen(zcu)) {
180921 1 => .{ .v_ss, .fmadd231 },180921 1 => .{ .v_ss, .fmadd231 },
180922 2...8 => .{ .v_ps, .fmadd231 },180922 2...8 => .{ .v_ps, .fmadd231 },
...@@ -181979,7 +181979,7 @@ fn promoteInt(self: *CodeGen, ty: Type) Type {...@@ -181979,7 +181979,7 @@ fn promoteInt(self: *CodeGen, ty: Type) Type {
181979181979
181980fn promoteVarArg(self: *CodeGen, ty: Type) Type {181980fn promoteVarArg(self: *CodeGen, ty: Type) Type {
181981 if (!ty.isRuntimeFloat()) return self.promoteInt(ty);181981 if (!ty.isRuntimeFloat()) return self.promoteInt(ty);
181982 switch (ty.floatBits(self.target.*)) {181982 switch (ty.floatBits(self.target)) {
181983 32, 64 => return .f64,181983 32, 64 => return .f64,
181984 else => |float_bits| {181984 else => |float_bits| {
181985 assert(float_bits == self.target.cTypeBitSize(.longdouble));181985 assert(float_bits == self.target.cTypeBitSize(.longdouble));
...@@ -182080,7 +182080,7 @@ fn intInfo(cg: *CodeGen, ty: Type) ?std.builtin.Type.Int {...@@ -182080,7 +182080,7 @@ fn intInfo(cg: *CodeGen, ty: Type) ?std.builtin.Type.Int {
182080}182080}
182081182081
182082fn floatBits(cg: *CodeGen, ty: Type) ?u16 {182082fn floatBits(cg: *CodeGen, ty: Type) ?u16 {
182083 return if (ty.isRuntimeFloat()) ty.floatBits(cg.target.*) else null;182083 return if (ty.isRuntimeFloat()) ty.floatBits(cg.target) else null;
182084}182084}
182085182085
182086const Temp = struct {182086const Temp = struct {
src/arch/x86_64/Emit.zig+2-2
...@@ -105,7 +105,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -105,7 +105,7 @@ pub fn emitMir(emit: *Emit) Error!void {
105 emit.pt,105 emit.pt,
106 emit.lower.src_loc,106 emit.lower.src_loc,
107 nav,107 nav,
108 emit.lower.target.*,108 emit.lower.target,
109 )) {109 )) {
110 .mcv => |mcv| mcv.lea_symbol,110 .mcv => |mcv| mcv.lea_symbol,
111 .fail => |em| {111 .fail => |em| {
...@@ -542,7 +542,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -542,7 +542,7 @@ pub fn emitMir(emit: *Emit) Error!void {
542 emit.pt,542 emit.pt,
543 emit.lower.src_loc,543 emit.lower.src_loc,
544 nav,544 nav,
545 emit.lower.target.*,545 emit.lower.target,
546 ) catch |err| switch (err) {546 ) catch |err| switch (err) {
547 error.CodegenFail,547 error.CodegenFail,
548 => return emit.fail("unable to codegen: {s}", .{@errorName(err)}),548 => return emit.fail("unable to codegen: {s}", .{@errorName(err)}),
src/arch/x86_64/abi.zig+1-1
...@@ -148,7 +148,7 @@ pub fn classifySystemV(ty: Type, zcu: *Zcu, target: *const std.Target, ctx: Cont...@@ -148,7 +148,7 @@ pub fn classifySystemV(ty: Type, zcu: *Zcu, target: *const std.Target, ctx: Cont
148 result[0] = .integer;148 result[0] = .integer;
149 return result;149 return result;
150 },150 },
151 .float => switch (ty.floatBits(target.*)) {151 .float => switch (ty.floatBits(target)) {
152 16 => {152 16 => {
153 if (ctx == .field) {153 if (ctx == .field) {
154 result[0] = .memory;154 result[0] = .memory;
src/codegen.zig+11-11
...@@ -65,7 +65,7 @@ fn importBackend(comptime backend: std.builtin.CompilerBackend) type {...@@ -65,7 +65,7 @@ fn importBackend(comptime backend: std.builtin.CompilerBackend) type {
65pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) ?*const Air.Legalize.Features {65pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) ?*const Air.Legalize.Features {
66 const zcu = pt.zcu;66 const zcu = pt.zcu;
67 const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;67 const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
68 switch (target_util.zigBackend(target.*, zcu.comp.config.use_llvm)) {68 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {
69 else => unreachable,69 else => unreachable,
70 inline .stage2_llvm,70 inline .stage2_llvm,
71 .stage2_c,71 .stage2_c,
...@@ -114,7 +114,7 @@ pub const AnyMir = union {...@@ -114,7 +114,7 @@ pub const AnyMir = union {
114114
115 pub fn deinit(mir: *AnyMir, zcu: *const Zcu) void {115 pub fn deinit(mir: *AnyMir, zcu: *const Zcu) void {
116 const gpa = zcu.gpa;116 const gpa = zcu.gpa;
117 const backend = target_util.zigBackend(zcu.root_mod.resolved_target.result, zcu.comp.config.use_llvm);117 const backend = target_util.zigBackend(&zcu.root_mod.resolved_target.result, zcu.comp.config.use_llvm);
118 switch (backend) {118 switch (backend) {
119 else => unreachable,119 else => unreachable,
120 inline .stage2_aarch64,120 inline .stage2_aarch64,
...@@ -145,7 +145,7 @@ pub fn generateFunction(...@@ -145,7 +145,7 @@ pub fn generateFunction(
145) CodeGenError!AnyMir {145) CodeGenError!AnyMir {
146 const zcu = pt.zcu;146 const zcu = pt.zcu;
147 const func = zcu.funcInfo(func_index);147 const func = zcu.funcInfo(func_index);
148 const target = zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;148 const target = &zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;
149 switch (target_util.zigBackend(target, false)) {149 switch (target_util.zigBackend(target, false)) {
150 else => unreachable,150 else => unreachable,
151 inline .stage2_aarch64,151 inline .stage2_aarch64,
...@@ -183,7 +183,7 @@ pub fn emitFunction(...@@ -183,7 +183,7 @@ pub fn emitFunction(
183) CodeGenError!void {183) CodeGenError!void {
184 const zcu = pt.zcu;184 const zcu = pt.zcu;
185 const func = zcu.funcInfo(func_index);185 const func = zcu.funcInfo(func_index);
186 const target = zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;186 const target = &zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;
187 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {187 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {
188 else => unreachable,188 else => unreachable,
189 inline .stage2_aarch64,189 inline .stage2_aarch64,
...@@ -210,7 +210,7 @@ pub fn generateLazyFunction(...@@ -210,7 +210,7 @@ pub fn generateLazyFunction(
210) CodeGenError!void {210) CodeGenError!void {
211 const zcu = pt.zcu;211 const zcu = pt.zcu;
212 const target = if (Type.fromInterned(lazy_sym.ty).typeDeclInstAllowGeneratedTag(zcu)) |inst_index|212 const target = if (Type.fromInterned(lazy_sym.ty).typeDeclInstAllowGeneratedTag(zcu)) |inst_index|
213 zcu.fileByIndex(inst_index.resolveFile(&zcu.intern_pool)).mod.?.resolved_target.result213 &zcu.fileByIndex(inst_index.resolveFile(&zcu.intern_pool)).mod.?.resolved_target.result
214 else214 else
215 zcu.getTarget();215 zcu.getTarget();
216 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {216 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {
...@@ -225,7 +225,7 @@ pub fn generateLazyFunction(...@@ -225,7 +225,7 @@ pub fn generateLazyFunction(
225 }225 }
226}226}
227227
228fn writeFloat(comptime F: type, f: F, target: std.Target, endian: std.builtin.Endian, code: []u8) void {228fn writeFloat(comptime F: type, f: F, target: *const std.Target, endian: std.builtin.Endian, code: []u8) void {
229 _ = target;229 _ = target;
230 const bits = @typeInfo(F).float.bits;230 const bits = @typeInfo(F).float.bits;
231 const Int = @Type(.{ .int = .{ .signedness = .unsigned, .bits = bits } });231 const Int = @Type(.{ .int = .{ .signedness = .unsigned, .bits = bits } });
...@@ -253,7 +253,7 @@ pub fn generateLazySymbol(...@@ -253,7 +253,7 @@ pub fn generateLazySymbol(
253 const gpa = comp.gpa;253 const gpa = comp.gpa;
254 const zcu = pt.zcu;254 const zcu = pt.zcu;
255 const ip = &zcu.intern_pool;255 const ip = &zcu.intern_pool;
256 const target = comp.root_mod.resolved_target.result;256 const target = &comp.root_mod.resolved_target.result;
257 const endian = target.cpu.arch.endian();257 const endian = target.cpu.arch.endian();
258258
259 log.debug("generateLazySymbol: kind = {s}, ty = {}", .{259 log.debug("generateLazySymbol: kind = {s}, ty = {}", .{
...@@ -839,7 +839,7 @@ fn lowerNavRef(...@@ -839,7 +839,7 @@ fn lowerNavRef(
839 const zcu = pt.zcu;839 const zcu = pt.zcu;
840 const gpa = zcu.gpa;840 const gpa = zcu.gpa;
841 const ip = &zcu.intern_pool;841 const ip = &zcu.intern_pool;
842 const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;842 const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
843 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);843 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
844 const is_obj = lf.comp.config.output_mode == .Obj;844 const is_obj = lf.comp.config.output_mode == .Obj;
845 const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip));845 const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip));
...@@ -956,7 +956,7 @@ pub fn genNavRef(...@@ -956,7 +956,7 @@ pub fn genNavRef(
956 pt: Zcu.PerThread,956 pt: Zcu.PerThread,
957 src_loc: Zcu.LazySrcLoc,957 src_loc: Zcu.LazySrcLoc,
958 nav_index: InternPool.Nav.Index,958 nav_index: InternPool.Nav.Index,
959 target: std.Target,959 target: *const std.Target,
960) CodeGenError!GenResult {960) CodeGenError!GenResult {
961 const zcu = pt.zcu;961 const zcu = pt.zcu;
962 const ip = &zcu.intern_pool;962 const ip = &zcu.intern_pool;
...@@ -1040,9 +1040,9 @@ pub fn genTypedValue(...@@ -1040,9 +1040,9 @@ pub fn genTypedValue(
1040 pt: Zcu.PerThread,1040 pt: Zcu.PerThread,
1041 src_loc: Zcu.LazySrcLoc,1041 src_loc: Zcu.LazySrcLoc,
1042 val: Value,1042 val: Value,
1043 target: std.Target,1043 target: *const std.Target,
1044) CodeGenError!GenResult {1044) CodeGenError!GenResult {
1045 return switch (try lowerValue(pt, val, &target)) {1045 return switch (try lowerValue(pt, val, target)) {
1046 .none => .{ .mcv = .none },1046 .none => .{ .mcv = .none },
1047 .undef => .{ .mcv = .undef },1047 .undef => .{ .mcv = .undef },
1048 .immediate => |imm| .{ .mcv = .{ .immediate = imm } },1048 .immediate => |imm| .{ .mcv = .{ .immediate = imm } },
src/codegen/c.zig+6-6
...@@ -1080,7 +1080,7 @@ pub const DeclGen = struct {...@@ -1080,7 +1080,7 @@ pub const DeclGen = struct {
1080 },1080 },
1081 .enum_tag => |enum_tag| try dg.renderValue(writer, Value.fromInterned(enum_tag.int), location),1081 .enum_tag => |enum_tag| try dg.renderValue(writer, Value.fromInterned(enum_tag.int), location),
1082 .float => {1082 .float => {
1083 const bits = ty.floatBits(target.*);1083 const bits = ty.floatBits(target);
1084 const f128_val = val.toFloat(f128, zcu);1084 const f128_val = val.toFloat(f128, zcu);
10851085
1086 // All unsigned ints matching float types are pre-allocated.1086 // All unsigned ints matching float types are pre-allocated.
...@@ -1608,7 +1608,7 @@ pub const DeclGen = struct {...@@ -1608,7 +1608,7 @@ pub const DeclGen = struct {
1608 .f80_type,1608 .f80_type,
1609 .f128_type,1609 .f128_type,
1610 => {1610 => {
1611 const bits = ty.floatBits(target.*);1611 const bits = ty.floatBits(target);
1612 // All unsigned ints matching float types are pre-allocated.1612 // All unsigned ints matching float types are pre-allocated.
1613 const repr_ty = dg.pt.intType(.unsigned, bits) catch unreachable;1613 const repr_ty = dg.pt.intType(.unsigned, bits) catch unreachable;
16141614
...@@ -6543,7 +6543,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6543,7 +6543,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
6543 const scalar_ty = operand_ty.scalarType(zcu);6543 const scalar_ty = operand_ty.scalarType(zcu);
6544 const target = &f.object.dg.mod.resolved_target.result;6544 const target = &f.object.dg.mod.resolved_target.result;
6545 const operation = if (inst_scalar_ty.isRuntimeFloat() and scalar_ty.isRuntimeFloat())6545 const operation = if (inst_scalar_ty.isRuntimeFloat() and scalar_ty.isRuntimeFloat())
6546 if (inst_scalar_ty.floatBits(target.*) < scalar_ty.floatBits(target.*)) "trunc" else "extend"6546 if (inst_scalar_ty.floatBits(target) < scalar_ty.floatBits(target)) "trunc" else "extend"
6547 else if (inst_scalar_ty.isInt(zcu) and scalar_ty.isRuntimeFloat())6547 else if (inst_scalar_ty.isInt(zcu) and scalar_ty.isRuntimeFloat())
6548 if (inst_scalar_ty.isSignedInt(zcu)) "fix" else "fixuns"6548 if (inst_scalar_ty.isSignedInt(zcu)) "fix" else "fixuns"
6549 else if (inst_scalar_ty.isRuntimeFloat() and scalar_ty.isInt(zcu))6549 else if (inst_scalar_ty.isRuntimeFloat() and scalar_ty.isInt(zcu))
...@@ -6565,8 +6565,8 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6565,8 +6565,8 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
6565 }6565 }
6566 try writer.writeAll("zig_");6566 try writer.writeAll("zig_");
6567 try writer.writeAll(operation);6567 try writer.writeAll(operation);
6568 try writer.writeAll(compilerRtAbbrev(scalar_ty, zcu, target.*));6568 try writer.writeAll(compilerRtAbbrev(scalar_ty, zcu, target));
6569 try writer.writeAll(compilerRtAbbrev(inst_scalar_ty, zcu, target.*));6569 try writer.writeAll(compilerRtAbbrev(inst_scalar_ty, zcu, target));
6570 try writer.writeByte('(');6570 try writer.writeByte('(');
6571 try f.writeCValue(writer, operand, .FunctionArgument);6571 try f.writeCValue(writer, operand, .FunctionArgument);
6572 try v.elem(f, writer);6572 try v.elem(f, writer);
...@@ -8073,7 +8073,7 @@ fn signAbbrev(signedness: std.builtin.Signedness) u8 {...@@ -8073,7 +8073,7 @@ fn signAbbrev(signedness: std.builtin.Signedness) u8 {
8073 };8073 };
8074}8074}
80758075
8076fn compilerRtAbbrev(ty: Type, zcu: *Zcu, target: std.Target) []const u8 {8076fn compilerRtAbbrev(ty: Type, zcu: *Zcu, target: *const std.Target) []const u8 {
8077 return if (ty.isInt(zcu)) switch (ty.intInfo(zcu).bits) {8077 return if (ty.isInt(zcu)) switch (ty.intInfo(zcu).bits) {
8078 1...32 => "si",8078 1...32 => "si",
8079 33...64 => "di",8079 33...64 => "di",
src/codegen/c/Type.zig+7-7
...@@ -1319,9 +1319,9 @@ pub const Pool = struct {...@@ -1319,9 +1319,9 @@ pub const Pool = struct {
1319 },1319 },
1320 else => {1320 else => {
1321 const target = &mod.resolved_target.result;1321 const target = &mod.resolved_target.result;
1322 const abi_align_bytes = std.zig.target.intAlignment(target.*, int_info.bits);1322 const abi_align_bytes = std.zig.target.intAlignment(target, int_info.bits);
1323 const array_ctype = try pool.getArray(allocator, .{1323 const array_ctype = try pool.getArray(allocator, .{
1324 .len = @divExact(std.zig.target.intByteSize(target.*, int_info.bits), abi_align_bytes),1324 .len = @divExact(std.zig.target.intByteSize(target, int_info.bits), abi_align_bytes),
1325 .elem_ctype = try pool.fromIntInfo(allocator, .{1325 .elem_ctype = try pool.fromIntInfo(allocator, .{
1326 .signedness = .unsigned,1326 .signedness = .unsigned,
1327 .bits = @intCast(abi_align_bytes * 8),1327 .bits = @intCast(abi_align_bytes * 8),
...@@ -1438,13 +1438,13 @@ pub const Pool = struct {...@@ -1438,13 +1438,13 @@ pub const Pool = struct {
1438 .elem_ctype = .u8,1438 .elem_ctype = .u8,
1439 .@"const" = true,1439 .@"const" = true,
1440 }),1440 }),
1441 .alignas = AlignAs.fromAbiAlignment(Type.ptrAbiAlignment(target.*)),1441 .alignas = AlignAs.fromAbiAlignment(Type.ptrAbiAlignment(target)),
1442 },1442 },
1443 .{1443 .{
1444 .name = .{ .index = .len },1444 .name = .{ .index = .len },
1445 .ctype = .usize,1445 .ctype = .usize,
1446 .alignas = AlignAs.fromAbiAlignment(1446 .alignas = AlignAs.fromAbiAlignment(
1447 .fromByteUnits(std.zig.target.intAlignment(target.*, target.ptrBitWidth())),1447 .fromByteUnits(std.zig.target.intAlignment(target, target.ptrBitWidth())),
1448 ),1448 ),
1449 },1449 },
1450 };1450 };
...@@ -2246,13 +2246,13 @@ pub const Pool = struct {...@@ -2246,13 +2246,13 @@ pub const Pool = struct {
2246 mod,2246 mod,
2247 kind,2247 kind,
2248 ),2248 ),
2249 .alignas = AlignAs.fromAbiAlignment(Type.ptrAbiAlignment(target.*)),2249 .alignas = AlignAs.fromAbiAlignment(Type.ptrAbiAlignment(target)),
2250 },2250 },
2251 .{2251 .{
2252 .name = .{ .index = .len },2252 .name = .{ .index = .len },
2253 .ctype = .usize,2253 .ctype = .usize,
2254 .alignas = AlignAs.fromAbiAlignment(2254 .alignas = AlignAs.fromAbiAlignment(
2255 .fromByteUnits(std.zig.target.intAlignment(target.*, target.ptrBitWidth())),2255 .fromByteUnits(std.zig.target.intAlignment(target, target.ptrBitWidth())),
2256 ),2256 ),
2257 },2257 },
2258 };2258 };
...@@ -2372,7 +2372,7 @@ pub const Pool = struct {...@@ -2372,7 +2372,7 @@ pub const Pool = struct {
2372 .name = .{ .index = .@"error" },2372 .name = .{ .index = .@"error" },
2373 .ctype = error_set_ctype,2373 .ctype = error_set_ctype,
2374 .alignas = AlignAs.fromAbiAlignment(2374 .alignas = AlignAs.fromAbiAlignment(
2375 .fromByteUnits(std.zig.target.intAlignment(target.*, error_set_bits)),2375 .fromByteUnits(std.zig.target.intAlignment(target, error_set_bits)),
2376 ),2376 ),
2377 },2377 },
2378 .{2378 .{
src/codegen/llvm.zig+37-39
...@@ -43,7 +43,7 @@ pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {...@@ -43,7 +43,7 @@ pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
43 });43 });
44}44}
4545
46fn subArchName(target: std.Target, comptime family: std.Target.Cpu.Arch.Family, mappings: anytype) ?[]const u8 {46fn subArchName(target: *const std.Target, comptime family: std.Target.Cpu.Arch.Family, mappings: anytype) ?[]const u8 {
47 inline for (mappings) |mapping| {47 inline for (mappings) |mapping| {
48 if (target.cpu.has(family, mapping[0])) return mapping[1];48 if (target.cpu.has(family, mapping[0])) return mapping[1];
49 }49 }
...@@ -51,7 +51,7 @@ fn subArchName(target: std.Target, comptime family: std.Target.Cpu.Arch.Family,...@@ -51,7 +51,7 @@ fn subArchName(target: std.Target, comptime family: std.Target.Cpu.Arch.Family,
51 return null;51 return null;
52}52}
5353
54pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {54pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8 {
55 var llvm_triple = std.ArrayList(u8).init(allocator);55 var llvm_triple = std.ArrayList(u8).init(allocator);
56 defer llvm_triple.deinit();56 defer llvm_triple.deinit();
5757
...@@ -309,7 +309,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {...@@ -309,7 +309,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
309 return llvm_triple.toOwnedSlice();309 return llvm_triple.toOwnedSlice();
310}310}
311311
312pub fn supportsTailCall(target: std.Target) bool {312pub fn supportsTailCall(target: *const std.Target) bool {
313 return switch (target.cpu.arch) {313 return switch (target.cpu.arch) {
314 .wasm32, .wasm64 => target.cpu.has(.wasm, .tail_call),314 .wasm32, .wasm64 => target.cpu.has(.wasm, .tail_call),
315 // Although these ISAs support tail calls, LLVM does not support tail calls on them.315 // Although these ISAs support tail calls, LLVM does not support tail calls on them.
...@@ -319,7 +319,7 @@ pub fn supportsTailCall(target: std.Target) bool {...@@ -319,7 +319,7 @@ pub fn supportsTailCall(target: std.Target) bool {
319 };319 };
320}320}
321321
322pub fn dataLayout(target: std.Target) []const u8 {322pub fn dataLayout(target: *const std.Target) []const u8 {
323 // These data layouts should match Clang.323 // These data layouts should match Clang.
324 return switch (target.cpu.arch) {324 return switch (target.cpu.arch) {
325 .arc => "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-f32:32:32-i64:32-f64:32-a:0:32-n32",325 .arc => "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-f32:32:32-i64:32-f64:32-a:0:32-n32",
...@@ -475,7 +475,7 @@ const CodeModel = enum {...@@ -475,7 +475,7 @@ const CodeModel = enum {
475 large,475 large,
476};476};
477477
478fn codeModel(model: std.builtin.CodeModel, target: std.Target) CodeModel {478fn codeModel(model: std.builtin.CodeModel, target: *const std.Target) CodeModel {
479 // Roughly match Clang's mapping of GCC code models to LLVM code models.479 // Roughly match Clang's mapping of GCC code models to LLVM code models.
480 return switch (model) {480 return switch (model) {
481 .default => .default,481 .default => .default,
...@@ -508,7 +508,7 @@ pub const Object = struct {...@@ -508,7 +508,7 @@ pub const Object = struct {
508508
509 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata),509 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata),
510510
511 target: std.Target,511 target: *const std.Target,
512 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,512 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,
513 /// but that has some downsides:513 /// but that has some downsides:
514 /// * we have to compute the fully qualified name every time we want to do the lookup514 /// * we have to compute the fully qualified name every time we want to do the lookup
...@@ -562,7 +562,7 @@ pub const Object = struct {...@@ -562,7 +562,7 @@ pub const Object = struct {
562 pub fn create(arena: Allocator, comp: *Compilation) !Ptr {562 pub fn create(arena: Allocator, comp: *Compilation) !Ptr {
563 dev.check(.llvm_backend);563 dev.check(.llvm_backend);
564 const gpa = comp.gpa;564 const gpa = comp.gpa;
565 const target = comp.root_mod.resolved_target.result;565 const target = &comp.root_mod.resolved_target.result;
566 const llvm_target_triple = try targetTriple(arena, target);566 const llvm_target_triple = try targetTriple(arena, target);
567567
568 var builder = try Builder.init(.{568 var builder = try Builder.init(.{
...@@ -827,7 +827,7 @@ pub const Object = struct {...@@ -827,7 +827,7 @@ pub const Object = struct {
827 const behavior_max = try o.builder.metadataConstant(try o.builder.intConst(.i32, 7));827 const behavior_max = try o.builder.metadataConstant(try o.builder.intConst(.i32, 7));
828 const behavior_min = try o.builder.metadataConstant(try o.builder.intConst(.i32, 8));828 const behavior_min = try o.builder.metadataConstant(try o.builder.intConst(.i32, 8));
829829
830 if (target_util.llvmMachineAbi(comp.root_mod.resolved_target.result)) |abi| {830 if (target_util.llvmMachineAbi(&comp.root_mod.resolved_target.result)) |abi| {
831 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(831 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
832 behavior_error,832 behavior_error,
833 try o.builder.metadataString("target-abi"),833 try o.builder.metadataString("target-abi"),
...@@ -837,7 +837,7 @@ pub const Object = struct {...@@ -837,7 +837,7 @@ pub const Object = struct {
837 ));837 ));
838 }838 }
839839
840 const pic_level = target_util.picLevel(comp.root_mod.resolved_target.result);840 const pic_level = target_util.picLevel(&comp.root_mod.resolved_target.result);
841 if (comp.root_mod.pic) {841 if (comp.root_mod.pic) {
842 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(842 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
843 behavior_min,843 behavior_min,
...@@ -860,7 +860,7 @@ pub const Object = struct {...@@ -860,7 +860,7 @@ pub const Object = struct {
860 try o.builder.metadataString("Code Model"),860 try o.builder.metadataString("Code Model"),
861 try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(861 try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(
862 i32,862 i32,
863 switch (codeModel(comp.root_mod.code_model, comp.root_mod.resolved_target.result)) {863 switch (codeModel(comp.root_mod.code_model, &comp.root_mod.resolved_target.result)) {
864 .default => unreachable,864 .default => unreachable,
865 .tiny => 0,865 .tiny => 0,
866 .small => 1,866 .small => 1,
...@@ -906,7 +906,7 @@ pub const Object = struct {...@@ -906,7 +906,7 @@ pub const Object = struct {
906 }906 }
907 }907 }
908908
909 const target = comp.root_mod.resolved_target.result;909 const target = &comp.root_mod.resolved_target.result;
910 if (target.os.tag == .windows and (target.cpu.arch == .x86_64 or target.cpu.arch == .x86)) {910 if (target.os.tag == .windows and (target.cpu.arch == .x86_64 or target.cpu.arch == .x86)) {
911 // Add the "RegCallv4" flag so that any functions using `x86_regcallcc` use regcall911 // Add the "RegCallv4" flag so that any functions using `x86_regcallcc` use regcall
912 // v4, which is essentially a requirement on Windows. See corresponding logic in912 // v4, which is essentially a requirement on Windows. See corresponding logic in
...@@ -1020,7 +1020,7 @@ pub const Object = struct {...@@ -1020,7 +1020,7 @@ pub const Object = struct {
1020 else1020 else
1021 .Static;1021 .Static;
10221022
1023 const code_model: llvm.CodeModel = switch (codeModel(comp.root_mod.code_model, comp.root_mod.resolved_target.result)) {1023 const code_model: llvm.CodeModel = switch (codeModel(comp.root_mod.code_model, &comp.root_mod.resolved_target.result)) {
1024 .default => .Default,1024 .default => .Default,
1025 .tiny => .Tiny,1025 .tiny => .Tiny,
1026 .small => .Small,1026 .small => .Small,
...@@ -1045,7 +1045,7 @@ pub const Object = struct {...@@ -1045,7 +1045,7 @@ pub const Object = struct {
1045 comp.function_sections,1045 comp.function_sections,
1046 comp.data_sections,1046 comp.data_sections,
1047 float_abi,1047 float_abi,
1048 if (target_util.llvmMachineAbi(comp.root_mod.resolved_target.result)) |s| s.ptr else null,1048 if (target_util.llvmMachineAbi(&comp.root_mod.resolved_target.result)) |s| s.ptr else null,
1049 );1049 );
1050 errdefer target_machine.dispose();1050 errdefer target_machine.dispose();
10511051
...@@ -1137,7 +1137,7 @@ pub const Object = struct {...@@ -1137,7 +1137,7 @@ pub const Object = struct {
1137 const owner_mod = zcu.fileByIndex(file_scope).mod.?;1137 const owner_mod = zcu.fileByIndex(file_scope).mod.?;
1138 const fn_ty = Type.fromInterned(func.ty);1138 const fn_ty = Type.fromInterned(func.ty);
1139 const fn_info = zcu.typeToFunc(fn_ty).?;1139 const fn_info = zcu.typeToFunc(fn_ty).?;
1140 const target = owner_mod.resolved_target.result;1140 const target = &owner_mod.resolved_target.result;
11411141
1142 var ng: NavGen = .{1142 var ng: NavGen = .{
1143 .object = o,1143 .object = o,
...@@ -2699,7 +2699,7 @@ pub const Object = struct {...@@ -2699,7 +2699,7 @@ pub const Object = struct {
2699 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;2699 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
27002700
2701 const fn_info = zcu.typeToFunc(ty).?;2701 const fn_info = zcu.typeToFunc(ty).?;
2702 const target = owner_mod.resolved_target.result;2702 const target = &owner_mod.resolved_target.result;
2703 const sret = firstParamSRet(fn_info, zcu, target);2703 const sret = firstParamSRet(fn_info, zcu, target);
27042704
2705 const is_extern, const lib_name = if (nav.getExtern(ip)) |@"extern"|2705 const is_extern, const lib_name = if (nav.getExtern(ip)) |@"extern"|
...@@ -2913,7 +2913,7 @@ pub const Object = struct {...@@ -2913,7 +2913,7 @@ pub const Object = struct {
2913 try attributes.addFnAttr(.minsize, &o.builder);2913 try attributes.addFnAttr(.minsize, &o.builder);
2914 try attributes.addFnAttr(.optsize, &o.builder);2914 try attributes.addFnAttr(.optsize, &o.builder);
2915 }2915 }
2916 const target = owner_mod.resolved_target.result;2916 const target = &owner_mod.resolved_target.result;
2917 if (target.cpu.model.llvm_name) |s| {2917 if (target.cpu.model.llvm_name) |s| {
2918 try attributes.addFnAttr(.{ .string = .{2918 try attributes.addFnAttr(.{ .string = .{
2919 .kind = try o.builder.string("target-cpu"),2919 .kind = try o.builder.string("target-cpu"),
...@@ -4445,7 +4445,7 @@ pub const Object = struct {...@@ -4445,7 +4445,7 @@ pub const Object = struct {
4445 if (o.builder.getGlobal(name)) |llvm_fn| return llvm_fn.ptrConst(&o.builder).kind.function;4445 if (o.builder.getGlobal(name)) |llvm_fn| return llvm_fn.ptrConst(&o.builder).kind.function;
44464446
4447 const zcu = o.pt.zcu;4447 const zcu = o.pt.zcu;
4448 const target = zcu.root_mod.resolved_target.result;4448 const target = &zcu.root_mod.resolved_target.result;
4449 const function_index = try o.builder.addFunction(4449 const function_index = try o.builder.addFunction(
4450 try o.builder.fnType(.i1, &.{try o.errorIntType()}, .normal),4450 try o.builder.fnType(.i1, &.{try o.errorIntType()}, .normal),
4451 name,4451 name,
...@@ -4474,7 +4474,7 @@ pub const Object = struct {...@@ -4474,7 +4474,7 @@ pub const Object = struct {
44744474
4475 const usize_ty = try o.lowerType(Type.usize);4475 const usize_ty = try o.lowerType(Type.usize);
4476 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);4476 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);
4477 const target = zcu.root_mod.resolved_target.result;4477 const target = &zcu.root_mod.resolved_target.result;
4478 const function_index = try o.builder.addFunction(4478 const function_index = try o.builder.addFunction(
4479 try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),4479 try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
4480 try o.builder.strtabStringFmt("__zig_tag_name_{}", .{enum_type.name.fmt(ip)}),4480 try o.builder.strtabStringFmt("__zig_tag_name_{}", .{enum_type.name.fmt(ip)}),
...@@ -10372,7 +10372,7 @@ pub const FuncGen = struct {...@@ -10372,7 +10372,7 @@ pub const FuncGen = struct {
10372 if (gop.found_existing) return gop.value_ptr.*;10372 if (gop.found_existing) return gop.value_ptr.*;
10373 errdefer assert(o.named_enum_map.remove(enum_ty.toIntern()));10373 errdefer assert(o.named_enum_map.remove(enum_ty.toIntern()));
1037410374
10375 const target = zcu.root_mod.resolved_target.result;10375 const target = &zcu.root_mod.resolved_target.result;
10376 const function_index = try o.builder.addFunction(10376 const function_index = try o.builder.addFunction(
10377 try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),10377 try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
10378 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{}", .{enum_type.name.fmt(ip)}),10378 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{}", .{enum_type.name.fmt(ip)}),
...@@ -11834,7 +11834,7 @@ const CallingConventionInfo = struct {...@@ -11834,7 +11834,7 @@ const CallingConventionInfo = struct {
11834 inreg_param_count: u2 = 0,11834 inreg_param_count: u2 = 0,
11835};11835};
1183611836
11837pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) ?CallingConventionInfo {11837pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: *const std.Target) ?CallingConventionInfo {
11838 const llvm_cc = toLlvmCallConvTag(cc, target) orelse return null;11838 const llvm_cc = toLlvmCallConvTag(cc, target) orelse return null;
11839 const incoming_stack_alignment: ?u64, const register_params: u2 = switch (cc) {11839 const incoming_stack_alignment: ?u64, const register_params: u2 = switch (cc) {
11840 inline else => |pl| switch (@TypeOf(pl)) {11840 inline else => |pl| switch (@TypeOf(pl)) {
...@@ -11858,7 +11858,7 @@ pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) ?Ca...@@ -11858,7 +11858,7 @@ pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) ?Ca
11858 .inreg_param_count = register_params,11858 .inreg_param_count = register_params,
11859 };11859 };
11860}11860}
11861fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Target) ?Builder.CallConv {11861fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const std.Target) ?Builder.CallConv {
11862 if (target.cCallingConvention()) |default_c| {11862 if (target.cCallingConvention()) |default_c| {
11863 if (cc_tag == default_c) {11863 if (cc_tag == default_c) {
11864 return .ccc;11864 return .ccc;
...@@ -11972,7 +11972,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Targ...@@ -11972,7 +11972,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Targ
11972}11972}
1197311973
11974/// Convert a zig-address space to an llvm address space.11974/// Convert a zig-address space to an llvm address space.
11975fn toLlvmAddressSpace(address_space: std.builtin.AddressSpace, target: std.Target) Builder.AddrSpace {11975fn toLlvmAddressSpace(address_space: std.builtin.AddressSpace, target: *const std.Target) Builder.AddrSpace {
11976 for (llvmAddrSpaceInfo(target)) |info| if (info.zig == address_space) return info.llvm;11976 for (llvmAddrSpaceInfo(target)) |info| if (info.zig == address_space) return info.llvm;
11977 unreachable;11977 unreachable;
11978}11978}
...@@ -11987,7 +11987,7 @@ const AddrSpaceInfo = struct {...@@ -11987,7 +11987,7 @@ const AddrSpaceInfo = struct {
11987 idx: ?u16 = null,11987 idx: ?u16 = null,
11988 force_in_data_layout: bool = false,11988 force_in_data_layout: bool = false,
11989};11989};
11990fn llvmAddrSpaceInfo(target: std.Target) []const AddrSpaceInfo {11990fn llvmAddrSpaceInfo(target: *const std.Target) []const AddrSpaceInfo {
11991 return switch (target.cpu.arch) {11991 return switch (target.cpu.arch) {
11992 .x86, .x86_64 => &.{11992 .x86, .x86_64 => &.{
11993 .{ .zig = .generic, .llvm = .default },11993 .{ .zig = .generic, .llvm = .default },
...@@ -12063,7 +12063,7 @@ fn llvmAddrSpaceInfo(target: std.Target) []const AddrSpaceInfo {...@@ -12063,7 +12063,7 @@ fn llvmAddrSpaceInfo(target: std.Target) []const AddrSpaceInfo {
12063/// different address, space and then cast back to the generic address space.12063/// different address, space and then cast back to the generic address space.
12064/// For example, on GPUs local variable declarations must be generated into the local address space.12064/// For example, on GPUs local variable declarations must be generated into the local address space.
12065/// This function returns the address space local values should be generated into.12065/// This function returns the address space local values should be generated into.
12066fn llvmAllocaAddressSpace(target: std.Target) Builder.AddrSpace {12066fn llvmAllocaAddressSpace(target: *const std.Target) Builder.AddrSpace {
12067 return switch (target.cpu.arch) {12067 return switch (target.cpu.arch) {
12068 // On amdgcn, locals should be generated into the private address space.12068 // On amdgcn, locals should be generated into the private address space.
12069 // To make Zig not impossible to use, these are then converted to addresses in the12069 // To make Zig not impossible to use, these are then converted to addresses in the
...@@ -12075,7 +12075,7 @@ fn llvmAllocaAddressSpace(target: std.Target) Builder.AddrSpace {...@@ -12075,7 +12075,7 @@ fn llvmAllocaAddressSpace(target: std.Target) Builder.AddrSpace {
1207512075
12076/// On some targets, global values that are in the generic address space must be generated into a12076/// On some targets, global values that are in the generic address space must be generated into a
12077/// different address space, and then cast back to the generic address space.12077/// different address space, and then cast back to the generic address space.
12078fn llvmDefaultGlobalAddressSpace(target: std.Target) Builder.AddrSpace {12078fn llvmDefaultGlobalAddressSpace(target: *const std.Target) Builder.AddrSpace {
12079 return switch (target.cpu.arch) {12079 return switch (target.cpu.arch) {
12080 // On amdgcn, globals must be explicitly allocated and uploaded so that the program can access12080 // On amdgcn, globals must be explicitly allocated and uploaded so that the program can access
12081 // them.12081 // them.
...@@ -12086,14 +12086,14 @@ fn llvmDefaultGlobalAddressSpace(target: std.Target) Builder.AddrSpace {...@@ -12086,14 +12086,14 @@ fn llvmDefaultGlobalAddressSpace(target: std.Target) Builder.AddrSpace {
1208612086
12087/// Return the actual address space that a value should be stored in if its a global address space.12087/// Return the actual address space that a value should be stored in if its a global address space.
12088/// When a value is placed in the resulting address space, it needs to be cast back into wanted_address_space.12088/// When a value is placed in the resulting address space, it needs to be cast back into wanted_address_space.
12089fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, target: std.Target) Builder.AddrSpace {12089fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, target: *const std.Target) Builder.AddrSpace {
12090 return switch (wanted_address_space) {12090 return switch (wanted_address_space) {
12091 .generic => llvmDefaultGlobalAddressSpace(target),12091 .generic => llvmDefaultGlobalAddressSpace(target),
12092 else => |as| toLlvmAddressSpace(as, target),12092 else => |as| toLlvmAddressSpace(as, target),
12093 };12093 };
12094}12094}
1209512095
12096fn returnTypeByRef(zcu: *Zcu, target: std.Target, ty: Type) bool {12096fn returnTypeByRef(zcu: *Zcu, target: *const std.Target, ty: Type) bool {
12097 if (isByRef(ty, zcu)) {12097 if (isByRef(ty, zcu)) {
12098 return true;12098 return true;
12099 } else if (target.cpu.arch.isX86() and12099 } else if (target.cpu.arch.isX86() and
...@@ -12108,7 +12108,7 @@ fn returnTypeByRef(zcu: *Zcu, target: std.Target, ty: Type) bool {...@@ -12108,7 +12108,7 @@ fn returnTypeByRef(zcu: *Zcu, target: std.Target, ty: Type) bool {
12108 }12108 }
12109}12109}
1211012110
12111fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Target) bool {12111fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: *const std.Target) bool {
12112 const return_type = Type.fromInterned(fn_info.return_type);12112 const return_type = Type.fromInterned(fn_info.return_type);
12113 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) return false;12113 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) return false;
1211412114
...@@ -12137,8 +12137,8 @@ fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Targe...@@ -12137,8 +12137,8 @@ fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Targe
12137 };12137 };
12138}12138}
1213912139
12140fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: std.Target) bool {12140fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: *const std.Target) bool {
12141 const class = x86_64_abi.classifySystemV(ty, zcu, &target, .ret);12141 const class = x86_64_abi.classifySystemV(ty, zcu, target, .ret);
12142 if (class[0] == .memory) return true;12142 if (class[0] == .memory) return true;
12143 if (class[0] == .x87 and class[2] != .none) return true;12143 if (class[0] == .x87 and class[2] != .none) return true;
12144 return false;12144 return false;
...@@ -12238,8 +12238,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E...@@ -12238,8 +12238,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
12238 if (isScalar(zcu, return_type)) {12238 if (isScalar(zcu, return_type)) {
12239 return o.lowerType(return_type);12239 return o.lowerType(return_type);
12240 }12240 }
12241 const target = zcu.getTarget();12241 const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret);
12242 const classes = x86_64_abi.classifySystemV(return_type, zcu, &target, .ret);
12243 if (classes[0] == .memory) return .void;12242 if (classes[0] == .memory) return .void;
12244 var types_index: u32 = 0;12243 var types_index: u32 = 0;
12245 var types_buffer: [8]Builder.Type = undefined;12244 var types_buffer: [8]Builder.Type = undefined;
...@@ -12527,8 +12526,7 @@ const ParamTypeIterator = struct {...@@ -12527,8 +12526,7 @@ const ParamTypeIterator = struct {
12527 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {12526 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
12528 const zcu = it.object.pt.zcu;12527 const zcu = it.object.pt.zcu;
12529 const ip = &zcu.intern_pool;12528 const ip = &zcu.intern_pool;
12530 const target = zcu.getTarget();12529 const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg);
12531 const classes = x86_64_abi.classifySystemV(ty, zcu, &target, .arg);
12532 if (classes[0] == .memory) {12530 if (classes[0] == .memory) {
12533 it.zig_index += 1;12531 it.zig_index += 1;
12534 it.llvm_index += 1;12532 it.llvm_index += 1;
...@@ -12794,7 +12792,7 @@ fn isScalar(zcu: *Zcu, ty: Type) bool {...@@ -12794,7 +12792,7 @@ fn isScalar(zcu: *Zcu, ty: Type) bool {
12794/// This function returns true if we expect LLVM to lower x86_fp80 correctly12792/// This function returns true if we expect LLVM to lower x86_fp80 correctly
12795/// and false if we expect LLVM to crash if it encounters an x86_fp80 type,12793/// and false if we expect LLVM to crash if it encounters an x86_fp80 type,
12796/// or if it produces miscompilations.12794/// or if it produces miscompilations.
12797fn backendSupportsF80(target: std.Target) bool {12795fn backendSupportsF80(target: *const std.Target) bool {
12798 return switch (target.cpu.arch) {12796 return switch (target.cpu.arch) {
12799 .x86, .x86_64 => !target.cpu.has(.x86, .soft_float),12797 .x86, .x86_64 => !target.cpu.has(.x86, .soft_float),
12800 else => false,12798 else => false,
...@@ -12804,7 +12802,7 @@ fn backendSupportsF80(target: std.Target) bool {...@@ -12804,7 +12802,7 @@ fn backendSupportsF80(target: std.Target) bool {
12804/// This function returns true if we expect LLVM to lower f16 correctly12802/// This function returns true if we expect LLVM to lower f16 correctly
12805/// and false if we expect LLVM to crash if it encounters an f16 type,12803/// and false if we expect LLVM to crash if it encounters an f16 type,
12806/// or if it produces miscompilations.12804/// or if it produces miscompilations.
12807fn backendSupportsF16(target: std.Target) bool {12805fn backendSupportsF16(target: *const std.Target) bool {
12808 return switch (target.cpu.arch) {12806 return switch (target.cpu.arch) {
12809 // https://github.com/llvm/llvm-project/issues/9798112807 // https://github.com/llvm/llvm-project/issues/97981
12810 .csky,12808 .csky,
...@@ -12840,7 +12838,7 @@ fn backendSupportsF16(target: std.Target) bool {...@@ -12840,7 +12838,7 @@ fn backendSupportsF16(target: std.Target) bool {
12840/// This function returns true if we expect LLVM to lower f128 correctly,12838/// This function returns true if we expect LLVM to lower f128 correctly,
12841/// and false if we expect LLVM to crash if it encounters an f128 type,12839/// and false if we expect LLVM to crash if it encounters an f128 type,
12842/// or if it produces miscompilations.12840/// or if it produces miscompilations.
12843fn backendSupportsF128(target: std.Target) bool {12841fn backendSupportsF128(target: *const std.Target) bool {
12844 return switch (target.cpu.arch) {12842 return switch (target.cpu.arch) {
12845 // https://github.com/llvm/llvm-project/issues/12112212843 // https://github.com/llvm/llvm-project/issues/121122
12846 .amdgcn,12844 .amdgcn,
...@@ -12870,7 +12868,7 @@ fn backendSupportsF128(target: std.Target) bool {...@@ -12870,7 +12868,7 @@ fn backendSupportsF128(target: std.Target) bool {
1287012868
12871/// LLVM does not support all relevant intrinsics for all targets, so we12869/// LLVM does not support all relevant intrinsics for all targets, so we
12872/// may need to manually generate a compiler-rt call.12870/// may need to manually generate a compiler-rt call.
12873fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool {12871fn intrinsicsAllowed(scalar_ty: Type, target: *const std.Target) bool {
12874 return switch (scalar_ty.toIntern()) {12872 return switch (scalar_ty.toIntern()) {
12875 .f16_type => backendSupportsF16(target),12873 .f16_type => backendSupportsF16(target),
12876 .f80_type => (target.cTypeBitSize(.longdouble) == 80) and backendSupportsF80(target),12874 .f80_type => (target.cTypeBitSize(.longdouble) == 80) and backendSupportsF80(target),
...@@ -12907,7 +12905,7 @@ fn buildAllocaInner(...@@ -12907,7 +12905,7 @@ fn buildAllocaInner(
12907 wip: *Builder.WipFunction,12905 wip: *Builder.WipFunction,
12908 llvm_ty: Builder.Type,12906 llvm_ty: Builder.Type,
12909 alignment: Builder.Alignment,12907 alignment: Builder.Alignment,
12910 target: std.Target,12908 target: *const std.Target,
12911) Allocator.Error!Builder.Value {12909) Allocator.Error!Builder.Value {
12912 const address_space = llvmAllocaAddressSpace(target);12910 const address_space = llvmAllocaAddressSpace(target);
1291312911
src/codegen/spirv.zig+1-1
...@@ -185,7 +185,7 @@ pub const Object = struct {...@@ -185,7 +185,7 @@ pub const Object = struct {
185 /// related to that.185 /// related to that.
186 error_buffer: ?SpvModule.Decl.Index = null,186 error_buffer: ?SpvModule.Decl.Index = null,
187187
188 pub fn init(gpa: Allocator, target: std.Target) Object {188 pub fn init(gpa: Allocator, target: *const std.Target) Object {
189 return .{189 return .{
190 .gpa = gpa,190 .gpa = gpa,
191 .spv = SpvModule.init(gpa, target),191 .spv = SpvModule.init(gpa, target),
src/codegen/spirv/Module.zig+2-2
...@@ -107,7 +107,7 @@ gpa: Allocator,...@@ -107,7 +107,7 @@ gpa: Allocator,
107arena: std.heap.ArenaAllocator,107arena: std.heap.ArenaAllocator,
108108
109/// Target info109/// Target info
110target: std.Target,110target: *const std.Target,
111111
112/// The target SPIR-V version112/// The target SPIR-V version
113version: spec.Version,113version: spec.Version,
...@@ -187,7 +187,7 @@ decl_deps: std.ArrayListUnmanaged(Decl.Index) = .empty,...@@ -187,7 +187,7 @@ decl_deps: std.ArrayListUnmanaged(Decl.Index) = .empty,
187/// The list of entry points that should be exported from this module.187/// The list of entry points that should be exported from this module.
188entry_points: std.AutoArrayHashMapUnmanaged(IdRef, EntryPoint) = .empty,188entry_points: std.AutoArrayHashMapUnmanaged(IdRef, EntryPoint) = .empty,
189189
190pub fn init(gpa: Allocator, target: std.Target) Module {190pub fn init(gpa: Allocator, target: *const std.Target) Module {
191 const version_minor: u8 = blk: {191 const version_minor: u8 = blk: {
192 // Prefer higher versions192 // Prefer higher versions
193 if (target.cpu.has(.spirv, .v1_6)) break :blk 6;193 if (target.cpu.has(.spirv, .v1_6)) break :blk 6;
src/libs/freebsd.zig+2-2
...@@ -66,7 +66,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -66,7 +66,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
66 defer arena_allocator.deinit();66 defer arena_allocator.deinit();
67 const arena = arena_allocator.allocator();67 const arena = arena_allocator.allocator();
6868
69 const target = comp.root_mod.resolved_target.result;69 const target = &comp.root_mod.resolved_target.result;
7070
71 // In all cases in this function, we add the C compiler flags to71 // In all cases in this function, we add the C compiler flags to
72 // cache_exempt_flags rather than extra_flags, because these arguments72 // cache_exempt_flags rather than extra_flags, because these arguments
...@@ -407,7 +407,7 @@ pub const BuiltSharedObjects = struct {...@@ -407,7 +407,7 @@ pub const BuiltSharedObjects = struct {
407407
408const all_map_basename = "all.map";408const all_map_basename = "all.map";
409409
410fn wordDirective(target: std.Target) []const u8 {410fn wordDirective(target: *const std.Target) []const u8 {
411 // Based on its description in the GNU `as` manual, you might assume that `.word` is sized411 // Based on its description in the GNU `as` manual, you might assume that `.word` is sized
412 // according to the target word size. But no; that would just make too much sense.412 // according to the target word size. But no; that would just make too much sense.
413 return if (target.ptrBitWidth() == 64) ".quad" else ".long";413 return if (target.ptrBitWidth() == 64) ".quad" else ".long";
src/libs/glibc.zig+3-3
...@@ -172,7 +172,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -172,7 +172,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
172 defer arena_allocator.deinit();172 defer arena_allocator.deinit();
173 const arena = arena_allocator.allocator();173 const arena = arena_allocator.allocator();
174174
175 const target = comp.root_mod.resolved_target.result;175 const target = &comp.root_mod.resolved_target.result;
176 const target_ver = target.os.versionRange().gnuLibCVersion().?;176 const target_ver = target.os.versionRange().gnuLibCVersion().?;
177 const nonshared_stat = target_ver.order(.{ .major = 2, .minor = 32, .patch = 0 }) != .gt;177 const nonshared_stat = target_ver.order(.{ .major = 2, .minor = 32, .patch = 0 }) != .gt;
178 const start_old_init_fini = target_ver.order(.{ .major = 2, .minor = 33, .patch = 0 }) != .gt;178 const start_old_init_fini = target_ver.order(.{ .major = 2, .minor = 33, .patch = 0 }) != .gt;
...@@ -485,7 +485,7 @@ fn add_include_dirs(comp: *Compilation, arena: Allocator, args: *std.ArrayList([...@@ -485,7 +485,7 @@ fn add_include_dirs(comp: *Compilation, arena: Allocator, args: *std.ArrayList([
485fn add_include_dirs_arch(485fn add_include_dirs_arch(
486 arena: Allocator,486 arena: Allocator,
487 args: *std.ArrayList([]const u8),487 args: *std.ArrayList([]const u8),
488 target: std.Target,488 target: *const std.Target,
489 opt_nptl: ?[]const u8,489 opt_nptl: ?[]const u8,
490 dir: []const u8,490 dir: []const u8,
491) error{OutOfMemory}!void {491) error{OutOfMemory}!void {
...@@ -649,7 +649,7 @@ pub const BuiltSharedObjects = struct {...@@ -649,7 +649,7 @@ pub const BuiltSharedObjects = struct {
649649
650const all_map_basename = "all.map";650const all_map_basename = "all.map";
651651
652fn wordDirective(target: std.Target) []const u8 {652fn wordDirective(target: *const std.Target) []const u8 {
653 // Based on its description in the GNU `as` manual, you might assume that `.word` is sized653 // Based on its description in the GNU `as` manual, you might assume that `.word` is sized
654 // according to the target word size. But no; that would just make too much sense.654 // according to the target word size. But no; that would just make too much sense.
655 return if (target.ptrBitWidth() == 64) ".quad" else ".long";655 return if (target.ptrBitWidth() == 64) ".quad" else ".long";
src/libs/libcxx.zig+2-2
...@@ -121,7 +121,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!...@@ -121,7 +121,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
121 const root_name = "c++";121 const root_name = "c++";
122 const output_mode = .Lib;122 const output_mode = .Lib;
123 const link_mode = .static;123 const link_mode = .static;
124 const target = comp.root_mod.resolved_target.result;124 const target = &comp.root_mod.resolved_target.result;
125125
126 const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" });126 const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" });
127 const cxx_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "include" });127 const cxx_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "include" });
...@@ -314,7 +314,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr...@@ -314,7 +314,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
314 const root_name = "c++abi";314 const root_name = "c++abi";
315 const output_mode = .Lib;315 const output_mode = .Lib;
316 const link_mode = .static;316 const link_mode = .static;
317 const target = comp.root_mod.resolved_target.result;317 const target = &comp.root_mod.resolved_target.result;
318318
319 const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" });319 const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" });
320 const cxx_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "include" });320 const cxx_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "include" });
src/libs/libtsan.zig+1-1
...@@ -324,7 +324,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo...@@ -324,7 +324,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
324 comp.tsan_lib = crt_file;324 comp.tsan_lib = crt_file;
325}325}
326326
327fn addCcArgs(target: std.Target, args: *std.ArrayList([]const u8)) error{OutOfMemory}!void {327fn addCcArgs(target: *const std.Target, args: *std.ArrayList([]const u8)) error{OutOfMemory}!void {
328 try args.appendSlice(&[_][]const u8{328 try args.appendSlice(&[_][]const u8{
329 "-nostdinc++",329 "-nostdinc++",
330 "-fvisibility=hidden",330 "-fvisibility=hidden",
src/libs/libunwind.zig+1-1
...@@ -27,7 +27,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr...@@ -27,7 +27,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
27 const arena = arena_allocator.allocator();27 const arena = arena_allocator.allocator();
2828
29 const output_mode = .Lib;29 const output_mode = .Lib;
30 const target = comp.root_mod.resolved_target.result;30 const target = &comp.root_mod.resolved_target.result;
31 const unwind_tables: std.builtin.UnwindTables =31 const unwind_tables: std.builtin.UnwindTables =
32 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .@"async";32 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .@"async";
33 const config = Compilation.Config.resolve(.{33 const config = Compilation.Config.resolve(.{
src/libs/mingw.zig+3-3
...@@ -299,7 +299,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -299,7 +299,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
299 var aro_comp = aro.Compilation.init(gpa, std.fs.cwd());299 var aro_comp = aro.Compilation.init(gpa, std.fs.cwd());
300 defer aro_comp.deinit();300 defer aro_comp.deinit();
301301
302 aro_comp.target = target;302 aro_comp.target = target.*;
303303
304 const include_dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "def-include" });304 const include_dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "def-include" });
305305
...@@ -373,7 +373,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -373,7 +373,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
373373
374pub fn libExists(374pub fn libExists(
375 allocator: Allocator,375 allocator: Allocator,
376 target: std.Target,376 target: *const std.Target,
377 zig_lib_directory: Cache.Directory,377 zig_lib_directory: Cache.Directory,
378 lib_name: []const u8,378 lib_name: []const u8,
379) !bool {379) !bool {
...@@ -389,7 +389,7 @@ pub fn libExists(...@@ -389,7 +389,7 @@ pub fn libExists(
389/// see if a .def file exists.389/// see if a .def file exists.
390fn findDef(390fn findDef(
391 allocator: Allocator,391 allocator: Allocator,
392 target: std.Target,392 target: *const std.Target,
393 zig_lib_directory: Cache.Directory,393 zig_lib_directory: Cache.Directory,
394 lib_name: []const u8,394 lib_name: []const u8,
395) ![]u8 {395) ![]u8 {
src/libs/musl.zig+1-1
...@@ -193,7 +193,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro...@@ -193,7 +193,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
193 .link_libc = false,193 .link_libc = false,
194 });194 });
195195
196 const target = comp.root_mod.resolved_target.result;196 const target = &comp.root_mod.resolved_target.result;
197 const arch_name = std.zig.target.muslArchName(target.cpu.arch, target.abi);197 const arch_name = std.zig.target.muslArchName(target.cpu.arch, target.abi);
198 const time32 = for (time32_compat_arch_list) |time32_compat_arch| {198 const time32 = for (time32_compat_arch_list) |time32_compat_arch| {
199 if (mem.eql(u8, arch_name, time32_compat_arch)) break true;199 if (mem.eql(u8, arch_name, time32_compat_arch)) break true;
src/libs/netbsd.zig+2-2
...@@ -58,7 +58,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -58,7 +58,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
58 defer arena_allocator.deinit();58 defer arena_allocator.deinit();
59 const arena = arena_allocator.allocator();59 const arena = arena_allocator.allocator();
6060
61 const target = comp.root_mod.resolved_target.result;61 const target = &comp.root_mod.resolved_target.result;
62 const target_version = target.os.version_range.semver.min;62 const target_version = target.os.version_range.semver.min;
6363
64 // In all cases in this function, we add the C compiler flags to64 // In all cases in this function, we add the C compiler flags to
...@@ -353,7 +353,7 @@ pub const BuiltSharedObjects = struct {...@@ -353,7 +353,7 @@ pub const BuiltSharedObjects = struct {
353 }353 }
354};354};
355355
356fn wordDirective(target: std.Target) []const u8 {356fn wordDirective(target: *const std.Target) []const u8 {
357 // Based on its description in the GNU `as` manual, you might assume that `.word` is sized357 // Based on its description in the GNU `as` manual, you might assume that `.word` is sized
358 // according to the target word size. But no; that would just make too much sense.358 // according to the target word size. But no; that would just make too much sense.
359 return if (target.ptrBitWidth() == 64) ".quad" else ".long";359 return if (target.ptrBitWidth() == 64) ".quad" else ".long";
src/link.zig+5-5
...@@ -1321,7 +1321,7 @@ pub fn doPrelinkTask(comp: *Compilation, task: PrelinkTask) void {...@@ -1321,7 +1321,7 @@ pub fn doPrelinkTask(comp: *Compilation, task: PrelinkTask) void {
1321 const prog_node = comp.link_prog_node.start("Parse Host libc", 0);1321 const prog_node = comp.link_prog_node.start("Parse Host libc", 0);
1322 defer prog_node.end();1322 defer prog_node.end();
13231323
1324 const target = comp.root_mod.resolved_target.result;1324 const target = &comp.root_mod.resolved_target.result;
1325 const flags = target_util.libcFullLinkFlags(target);1325 const flags = target_util.libcFullLinkFlags(target);
1326 const crt_dir = comp.libc_installation.?.crt_dir.?;1326 const crt_dir = comp.libc_installation.?.crt_dir.?;
1327 const sep = std.fs.path.sep_str;1327 const sep = std.fs.path.sep_str;
...@@ -1670,7 +1670,7 @@ pub fn hashInputs(man: *Cache.Manifest, link_inputs: []const Input) !void {...@@ -1670,7 +1670,7 @@ pub fn hashInputs(man: *Cache.Manifest, link_inputs: []const Input) !void {
1670pub fn resolveInputs(1670pub fn resolveInputs(
1671 gpa: Allocator,1671 gpa: Allocator,
1672 arena: Allocator,1672 arena: Allocator,
1673 target: std.Target,1673 target: *const std.Target,
1674 /// This function mutates this array but does not take ownership.1674 /// This function mutates this array but does not take ownership.
1675 /// Allocated with `gpa`.1675 /// Allocated with `gpa`.
1676 unresolved_inputs: *std.ArrayListUnmanaged(UnresolvedInput),1676 unresolved_inputs: *std.ArrayListUnmanaged(UnresolvedInput),
...@@ -1914,7 +1914,7 @@ fn resolveLibInput(...@@ -1914,7 +1914,7 @@ fn resolveLibInput(
1914 ld_script_bytes: *std.ArrayListUnmanaged(u8),1914 ld_script_bytes: *std.ArrayListUnmanaged(u8),
1915 lib_directory: Directory,1915 lib_directory: Directory,
1916 name_query: UnresolvedInput.NameQuery,1916 name_query: UnresolvedInput.NameQuery,
1917 target: std.Target,1917 target: *const std.Target,
1918 link_mode: std.builtin.LinkMode,1918 link_mode: std.builtin.LinkMode,
1919 color: std.zig.Color,1919 color: std.zig.Color,
1920) Allocator.Error!ResolveLibInputResult {1920) Allocator.Error!ResolveLibInputResult {
...@@ -2028,7 +2028,7 @@ fn resolvePathInput(...@@ -2028,7 +2028,7 @@ fn resolvePathInput(
2028 resolved_inputs: *std.ArrayListUnmanaged(Input),2028 resolved_inputs: *std.ArrayListUnmanaged(Input),
2029 /// Allocated via `gpa`.2029 /// Allocated via `gpa`.
2030 ld_script_bytes: *std.ArrayListUnmanaged(u8),2030 ld_script_bytes: *std.ArrayListUnmanaged(u8),
2031 target: std.Target,2031 target: *const std.Target,
2032 pq: UnresolvedInput.PathQuery,2032 pq: UnresolvedInput.PathQuery,
2033 color: std.zig.Color,2033 color: std.zig.Color,
2034) Allocator.Error!?ResolveLibInputResult {2034) Allocator.Error!?ResolveLibInputResult {
...@@ -2070,7 +2070,7 @@ fn resolvePathInputLib(...@@ -2070,7 +2070,7 @@ fn resolvePathInputLib(
2070 resolved_inputs: *std.ArrayListUnmanaged(Input),2070 resolved_inputs: *std.ArrayListUnmanaged(Input),
2071 /// Allocated via `gpa`.2071 /// Allocated via `gpa`.
2072 ld_script_bytes: *std.ArrayListUnmanaged(u8),2072 ld_script_bytes: *std.ArrayListUnmanaged(u8),
2073 target: std.Target,2073 target: *const std.Target,
2074 pq: UnresolvedInput.PathQuery,2074 pq: UnresolvedInput.PathQuery,
2075 link_mode: std.builtin.LinkMode,2075 link_mode: std.builtin.LinkMode,
2076 color: std.zig.Color,2076 color: std.zig.Color,
src/link/C.zig+2-2
...@@ -116,7 +116,7 @@ pub fn createEmpty(...@@ -116,7 +116,7 @@ pub fn createEmpty(
116 emit: Path,116 emit: Path,
117 options: link.File.OpenOptions,117 options: link.File.OpenOptions,
118) !*C {118) !*C {
119 const target = comp.root_mod.resolved_target.result;119 const target = &comp.root_mod.resolved_target.result;
120 assert(target.ofmt == .c);120 assert(target.ofmt == .c);
121 const optimize_mode = comp.root_mod.optimize_mode;121 const optimize_mode = comp.root_mod.optimize_mode;
122 const use_lld = build_options.have_llvm and comp.config.use_lld;122 const use_lld = build_options.have_llvm and comp.config.use_lld;
...@@ -331,7 +331,7 @@ pub fn updateLineNumber(self: *C, pt: Zcu.PerThread, ti_id: InternPool.TrackedIn...@@ -331,7 +331,7 @@ pub fn updateLineNumber(self: *C, pt: Zcu.PerThread, ti_id: InternPool.TrackedIn
331 _ = ti_id;331 _ = ti_id;
332}332}
333333
334fn abiDefines(self: *C, target: std.Target) !std.ArrayList(u8) {334fn abiDefines(self: *C, target: *const std.Target) !std.ArrayList(u8) {
335 const gpa = self.base.comp.gpa;335 const gpa = self.base.comp.gpa;
336 var defines = std.ArrayList(u8).init(gpa);336 var defines = std.ArrayList(u8).init(gpa);
337 errdefer defines.deinit();337 errdefer defines.deinit();
src/link/Coff.zig+4-4
...@@ -208,7 +208,7 @@ pub fn createEmpty(...@@ -208,7 +208,7 @@ pub fn createEmpty(
208 emit: Path,208 emit: Path,
209 options: link.File.OpenOptions,209 options: link.File.OpenOptions,
210) !*Coff {210) !*Coff {
211 const target = comp.root_mod.resolved_target.result;211 const target = &comp.root_mod.resolved_target.result;
212 assert(target.ofmt == .coff);212 assert(target.ofmt == .coff);
213 const optimize_mode = comp.root_mod.optimize_mode;213 const optimize_mode = comp.root_mod.optimize_mode;
214 const output_mode = comp.config.output_mode;214 const output_mode = comp.config.output_mode;
...@@ -1328,7 +1328,7 @@ fn updateNavCode(...@@ -1328,7 +1328,7 @@ fn updateNavCode(
13281328
1329 log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });1329 log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });
13301330
1331 const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;1331 const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
1332 const required_alignment = switch (pt.navAlignment(nav_index)) {1332 const required_alignment = switch (pt.navAlignment(nav_index)) {
1333 .none => target_util.defaultFunctionAlignment(target),1333 .none => target_util.defaultFunctionAlignment(target),
1334 else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),1334 else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
...@@ -2153,7 +2153,7 @@ fn writeDataDirectoriesHeaders(coff: *Coff) !void {...@@ -2153,7 +2153,7 @@ fn writeDataDirectoriesHeaders(coff: *Coff) !void {
2153}2153}
21542154
2155fn writeHeader(coff: *Coff) !void {2155fn writeHeader(coff: *Coff) !void {
2156 const target = coff.base.comp.root_mod.resolved_target.result;2156 const target = &coff.base.comp.root_mod.resolved_target.result;
2157 const gpa = coff.base.comp.gpa;2157 const gpa = coff.base.comp.gpa;
2158 var buffer = std.ArrayList(u8).init(gpa);2158 var buffer = std.ArrayList(u8).init(gpa);
2159 defer buffer.deinit();2159 defer buffer.deinit();
...@@ -2800,7 +2800,7 @@ pub const Relocation = struct {...@@ -2800,7 +2800,7 @@ pub const Relocation = struct {
2800 .ptr_width = coff.ptr_width,2800 .ptr_width = coff.ptr_width,
2801 };2801 };
28022802
2803 const target = coff.base.comp.root_mod.resolved_target.result;2803 const target = &coff.base.comp.root_mod.resolved_target.result;
2804 switch (target.cpu.arch) {2804 switch (target.cpu.arch) {
2805 .aarch64 => reloc.resolveAarch64(ctx),2805 .aarch64 => reloc.resolveAarch64(ctx),
2806 .x86, .x86_64 => reloc.resolveX86(ctx),2806 .x86, .x86_64 => reloc.resolveX86(ctx),
src/link/Dwarf.zig+4-4
...@@ -92,7 +92,7 @@ const DebugFrame = struct {...@@ -92,7 +92,7 @@ const DebugFrame = struct {
92 };92 };
9393
94 fn headerBytes(dwarf: *Dwarf) u32 {94 fn headerBytes(dwarf: *Dwarf) u32 {
95 const target = dwarf.bin_file.comp.root_mod.resolved_target.result;95 const target = &dwarf.bin_file.comp.root_mod.resolved_target.result;
96 return @intCast(switch (dwarf.debug_frame.header.format) {96 return @intCast(switch (dwarf.debug_frame.header.format) {
97 .none => return 0,97 .none => return 0,
98 .debug_frame => dwarf.unitLengthBytes() + dwarf.sectionOffsetBytes() + 1 + "\x00".len + 1 + 1,98 .debug_frame => dwarf.unitLengthBytes() + dwarf.sectionOffsetBytes() + 1 + "\x00".len + 1 + 1,
...@@ -2140,7 +2140,7 @@ fn padToIdeal(actual_size: anytype) @TypeOf(actual_size) {...@@ -2140,7 +2140,7 @@ fn padToIdeal(actual_size: anytype) @TypeOf(actual_size) {
2140pub fn init(lf: *link.File, format: DW.Format) Dwarf {2140pub fn init(lf: *link.File, format: DW.Format) Dwarf {
2141 const comp = lf.comp;2141 const comp = lf.comp;
2142 const gpa = comp.gpa;2142 const gpa = comp.gpa;
2143 const target = comp.root_mod.resolved_target.result;2143 const target = &comp.root_mod.resolved_target.result;
2144 return .{2144 return .{
2145 .gpa = gpa,2145 .gpa = gpa,
2146 .bin_file = lf,2146 .bin_file = lf,
...@@ -2573,7 +2573,7 @@ fn initWipNavInner(...@@ -2573,7 +2573,7 @@ fn initWipNavInner(
2573 try wip_nav.infoAddrSym(sym_index, 0);2573 try wip_nav.infoAddrSym(sym_index, 0);
2574 wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);2574 wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);
2575 try diw.writeInt(u32, 0, dwarf.endian);2575 try diw.writeInt(u32, 0, dwarf.endian);
2576 const target = mod.resolved_target.result;2576 const target = &mod.resolved_target.result;
2577 try uleb128(diw, switch (nav.status.fully_resolved.alignment) {2577 try uleb128(diw, switch (nav.status.fully_resolved.alignment) {
2578 .none => target_info.defaultFunctionAlignment(target),2578 .none => target_info.defaultFunctionAlignment(target),
2579 else => |a| a.maxStrict(target_info.minFunctionAlignment(target)),2579 else => |a| a.maxStrict(target_info.minFunctionAlignment(target)),
...@@ -4529,7 +4529,7 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {...@@ -4529,7 +4529,7 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
4529 dwarf.debug_aranges.section.dirty = false;4529 dwarf.debug_aranges.section.dirty = false;
4530 }4530 }
4531 if (dwarf.debug_frame.section.dirty) {4531 if (dwarf.debug_frame.section.dirty) {
4532 const target = dwarf.bin_file.comp.root_mod.resolved_target.result;4532 const target = &dwarf.bin_file.comp.root_mod.resolved_target.result;
4533 switch (dwarf.debug_frame.header.format) {4533 switch (dwarf.debug_frame.header.format) {
4534 .none => {},4534 .none => {},
4535 .debug_frame => unreachable,4535 .debug_frame => unreachable,
src/link/Elf.zig+6-6
...@@ -196,7 +196,7 @@ pub fn createEmpty(...@@ -196,7 +196,7 @@ pub fn createEmpty(
196 emit: Path,196 emit: Path,
197 options: link.File.OpenOptions,197 options: link.File.OpenOptions,
198) !*Elf {198) !*Elf {
199 const target = comp.root_mod.resolved_target.result;199 const target = &comp.root_mod.resolved_target.result;
200 assert(target.ofmt == .elf);200 assert(target.ofmt == .elf);
201201
202 const use_llvm = comp.config.use_llvm;202 const use_llvm = comp.config.use_llvm;
...@@ -1073,7 +1073,7 @@ fn parseObject(self: *Elf, obj: link.Input.Object) !void {...@@ -1073,7 +1073,7 @@ fn parseObject(self: *Elf, obj: link.Input.Object) !void {
10731073
1074 const gpa = self.base.comp.gpa;1074 const gpa = self.base.comp.gpa;
1075 const diags = &self.base.comp.link_diags;1075 const diags = &self.base.comp.link_diags;
1076 const target = self.base.comp.root_mod.resolved_target.result;1076 const target = &self.base.comp.root_mod.resolved_target.result;
1077 const debug_fmt_strip = self.base.comp.config.debug_format == .strip;1077 const debug_fmt_strip = self.base.comp.config.debug_format == .strip;
1078 const default_sym_version = self.default_sym_version;1078 const default_sym_version = self.default_sym_version;
1079 const file_handles = &self.file_handles;1079 const file_handles = &self.file_handles;
...@@ -1104,7 +1104,7 @@ fn parseArchive(...@@ -1104,7 +1104,7 @@ fn parseArchive(
1104 diags: *Diags,1104 diags: *Diags,
1105 file_handles: *std.ArrayListUnmanaged(File.Handle),1105 file_handles: *std.ArrayListUnmanaged(File.Handle),
1106 files: *std.MultiArrayList(File.Entry),1106 files: *std.MultiArrayList(File.Entry),
1107 target: std.Target,1107 target: *const std.Target,
1108 debug_fmt_strip: bool,1108 debug_fmt_strip: bool,
1109 default_sym_version: elf.Versym,1109 default_sym_version: elf.Versym,
1110 objects: *std.ArrayListUnmanaged(File.Index),1110 objects: *std.ArrayListUnmanaged(File.Index),
...@@ -1139,7 +1139,7 @@ fn parseDso(...@@ -1139,7 +1139,7 @@ fn parseDso(
1139 dso: link.Input.Dso,1139 dso: link.Input.Dso,
1140 shared_objects: *std.StringArrayHashMapUnmanaged(File.Index),1140 shared_objects: *std.StringArrayHashMapUnmanaged(File.Index),
1141 files: *std.MultiArrayList(File.Entry),1141 files: *std.MultiArrayList(File.Entry),
1142 target: std.Target,1142 target: *const std.Target,
1143) !void {1143) !void {
1144 const tracy = trace(@src());1144 const tracy = trace(@src());
1145 defer tracy.end();1145 defer tracy.end();
...@@ -4121,8 +4121,8 @@ pub fn lsearch(comptime T: type, haystack: []const T, predicate: anytype) usize...@@ -4121,8 +4121,8 @@ pub fn lsearch(comptime T: type, haystack: []const T, predicate: anytype) usize
4121 return i;4121 return i;
4122}4122}
41234123
4124pub fn getTarget(self: Elf) std.Target {4124pub fn getTarget(self: *const Elf) *const std.Target {
4125 return self.base.comp.root_mod.resolved_target.result;4125 return &self.base.comp.root_mod.resolved_target.result;
4126}4126}
41274127
4128fn requiresThunks(self: Elf) bool {4128fn requiresThunks(self: Elf) bool {
src/link/Elf/Object.zig+5-5
...@@ -69,7 +69,7 @@ pub fn parse(...@@ -69,7 +69,7 @@ pub fn parse(
69 /// For error reporting purposes only.69 /// For error reporting purposes only.
70 path: Path,70 path: Path,
71 handle: fs.File,71 handle: fs.File,
72 target: std.Target,72 target: *const std.Target,
73 debug_fmt_strip: bool,73 debug_fmt_strip: bool,
74 default_sym_version: elf.Versym,74 default_sym_version: elf.Versym,
75) !void {75) !void {
...@@ -98,7 +98,7 @@ pub fn parseCommon(...@@ -98,7 +98,7 @@ pub fn parseCommon(
98 diags: *Diags,98 diags: *Diags,
99 path: Path,99 path: Path,
100 handle: fs.File,100 handle: fs.File,
101 target: std.Target,101 target: *const std.Target,
102) !void {102) !void {
103 const offset = if (self.archive) |ar| ar.offset else 0;103 const offset = if (self.archive) |ar| ar.offset else 0;
104 const file_size = (try handle.stat()).size;104 const file_size = (try handle.stat()).size;
...@@ -182,7 +182,7 @@ pub fn parseCommon(...@@ -182,7 +182,7 @@ pub fn parseCommon(
182pub fn validateEFlags(182pub fn validateEFlags(
183 diags: *Diags,183 diags: *Diags,
184 path: Path,184 path: Path,
185 target: std.Target,185 target: *const std.Target,
186 e_flags: elf.Word,186 e_flags: elf.Word,
187) !void {187) !void {
188 switch (target.cpu.arch) {188 switch (target.cpu.arch) {
...@@ -263,7 +263,7 @@ fn initAtoms(...@@ -263,7 +263,7 @@ fn initAtoms(
263 path: Path,263 path: Path,
264 handle: fs.File,264 handle: fs.File,
265 debug_fmt_strip: bool,265 debug_fmt_strip: bool,
266 target: std.Target,266 target: *const std.Target,
267) !void {267) !void {
268 const shdrs = self.shdrs.items;268 const shdrs = self.shdrs.items;
269 try self.atoms.ensureTotalCapacityPrecise(gpa, shdrs.len);269 try self.atoms.ensureTotalCapacityPrecise(gpa, shdrs.len);
...@@ -420,7 +420,7 @@ fn parseEhFrame(...@@ -420,7 +420,7 @@ fn parseEhFrame(
420 gpa: Allocator,420 gpa: Allocator,
421 handle: fs.File,421 handle: fs.File,
422 shndx: u32,422 shndx: u32,
423 target: std.Target,423 target: *const std.Target,
424) !void {424) !void {
425 const relocs_shndx = for (self.shdrs.items, 0..) |shdr, i| switch (shdr.sh_type) {425 const relocs_shndx = for (self.shdrs.items, 0..) |shdr, i| switch (shdr.sh_type) {
426 elf.SHT_RELA => if (shdr.sh_info == shndx) break @as(u32, @intCast(i)),426 elf.SHT_RELA => if (shdr.sh_info == shndx) break @as(u32, @intCast(i)),
src/link/Elf/SharedObject.zig+1-1
...@@ -96,7 +96,7 @@ pub fn parseHeader(...@@ -96,7 +96,7 @@ pub fn parseHeader(
96 file_path: Path,96 file_path: Path,
97 fs_file: std.fs.File,97 fs_file: std.fs.File,
98 stat: Stat,98 stat: Stat,
99 target: std.Target,99 target: *const std.Target,
100) !Header {100) !Header {
101 var ehdr: elf.Elf64_Ehdr = undefined;101 var ehdr: elf.Elf64_Ehdr = undefined;
102 {102 {
src/link/Elf/ZigObject.zig+1-1
...@@ -1271,7 +1271,7 @@ fn updateNavCode(...@@ -1271,7 +1271,7 @@ fn updateNavCode(
12711271
1272 log.debug("updateNavCode {}({d})", .{ nav.fqn.fmt(ip), nav_index });1272 log.debug("updateNavCode {}({d})", .{ nav.fqn.fmt(ip), nav_index });
12731273
1274 const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;1274 const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
1275 const required_alignment = switch (pt.navAlignment(nav_index)) {1275 const required_alignment = switch (pt.navAlignment(nav_index)) {
1276 .none => target_util.defaultFunctionAlignment(target),1276 .none => target_util.defaultFunctionAlignment(target),
1277 else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),1277 else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
src/link/Goff.zig+2-2
...@@ -26,7 +26,7 @@ pub fn createEmpty(...@@ -26,7 +26,7 @@ pub fn createEmpty(
26 emit: Path,26 emit: Path,
27 options: link.File.OpenOptions,27 options: link.File.OpenOptions,
28) !*Goff {28) !*Goff {
29 const target = comp.root_mod.resolved_target.result;29 const target = &comp.root_mod.resolved_target.result;
30 const use_lld = build_options.have_llvm and comp.config.use_lld;30 const use_lld = build_options.have_llvm and comp.config.use_lld;
31 const use_llvm = comp.config.use_llvm;31 const use_llvm = comp.config.use_llvm;
3232
...@@ -59,7 +59,7 @@ pub fn open(...@@ -59,7 +59,7 @@ pub fn open(
59 emit: Path,59 emit: Path,
60 options: link.File.OpenOptions,60 options: link.File.OpenOptions,
61) !*Goff {61) !*Goff {
62 const target = comp.root_mod.resolved_target.result;62 const target = &comp.root_mod.resolved_target.result;
63 assert(target.ofmt == .goff);63 assert(target.ofmt == .goff);
64 return createEmpty(arena, comp, emit, options);64 return createEmpty(arena, comp, emit, options);
65}65}
src/link/Lld.zig+8-8
...@@ -30,7 +30,7 @@ const Coff = struct {...@@ -30,7 +30,7 @@ const Coff = struct {
30 dllmain_crt_startup: bool,30 dllmain_crt_startup: bool,
31 },31 },
32 fn init(comp: *Compilation, options: link.File.OpenOptions) !Coff {32 fn init(comp: *Compilation, options: link.File.OpenOptions) !Coff {
33 const target = comp.root_mod.resolved_target.result;33 const target = &comp.root_mod.resolved_target.result;
34 const output_mode = comp.config.output_mode;34 const output_mode = comp.config.output_mode;
35 return .{35 return .{
36 .image_base = options.image_base orelse switch (output_mode) {36 .image_base = options.image_base orelse switch (output_mode) {
...@@ -103,7 +103,7 @@ pub const Elf = struct {...@@ -103,7 +103,7 @@ pub const Elf = struct {
103103
104 fn init(comp: *Compilation, options: link.File.OpenOptions) !Elf {104 fn init(comp: *Compilation, options: link.File.OpenOptions) !Elf {
105 const PtrWidth = enum { p32, p64 };105 const PtrWidth = enum { p32, p64 };
106 const target = comp.root_mod.resolved_target.result;106 const target = &comp.root_mod.resolved_target.result;
107 const output_mode = comp.config.output_mode;107 const output_mode = comp.config.output_mode;
108 const is_dyn_lib = output_mode == .Lib and comp.config.link_mode == .dynamic;108 const is_dyn_lib = output_mode == .Lib and comp.config.link_mode == .dynamic;
109 const ptr_width: PtrWidth = switch (target.ptrBitWidth()) {109 const ptr_width: PtrWidth = switch (target.ptrBitWidth()) {
...@@ -202,7 +202,7 @@ pub fn createEmpty(...@@ -202,7 +202,7 @@ pub fn createEmpty(
202 emit: Cache.Path,202 emit: Cache.Path,
203 options: link.File.OpenOptions,203 options: link.File.OpenOptions,
204) !*Lld {204) !*Lld {
205 const target = comp.root_mod.resolved_target.result;205 const target = &comp.root_mod.resolved_target.result;
206 const output_mode = comp.config.output_mode;206 const output_mode = comp.config.output_mode;
207 const optimize_mode = comp.root_mod.optimize_mode;207 const optimize_mode = comp.root_mod.optimize_mode;
208 const is_native_os = comp.root_mod.resolved_target.is_native_os;208 const is_native_os = comp.root_mod.resolved_target.is_native_os;
...@@ -342,7 +342,7 @@ fn linkAsArchive(lld: *Lld, arena: Allocator) !void {...@@ -342,7 +342,7 @@ fn linkAsArchive(lld: *Lld, arena: Allocator) !void {
342342
343 const llvm_bindings = @import("../codegen/llvm/bindings.zig");343 const llvm_bindings = @import("../codegen/llvm/bindings.zig");
344 const llvm = @import("../codegen/llvm.zig");344 const llvm = @import("../codegen/llvm.zig");
345 const target = comp.root_mod.resolved_target.result;345 const target = &comp.root_mod.resolved_target.result;
346 llvm.initializeLLVMTarget(target.cpu.arch);346 llvm.initializeLLVMTarget(target.cpu.arch);
347 const bad = llvm_bindings.WriteArchive(347 const bad = llvm_bindings.WriteArchive(
348 full_out_path_z,348 full_out_path_z,
...@@ -374,7 +374,7 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {...@@ -374,7 +374,7 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
374 const is_dyn_lib = comp.config.link_mode == .dynamic and is_lib;374 const is_dyn_lib = comp.config.link_mode == .dynamic and is_lib;
375 const is_exe_or_dyn_lib = is_dyn_lib or comp.config.output_mode == .Exe;375 const is_exe_or_dyn_lib = is_dyn_lib or comp.config.output_mode == .Exe;
376 const link_in_crt = comp.config.link_libc and is_exe_or_dyn_lib;376 const link_in_crt = comp.config.link_libc and is_exe_or_dyn_lib;
377 const target = comp.root_mod.resolved_target.result;377 const target = &comp.root_mod.resolved_target.result;
378 const optimize_mode = comp.root_mod.optimize_mode;378 const optimize_mode = comp.root_mod.optimize_mode;
379 const entry_name: ?[]const u8 = switch (coff.entry) {379 const entry_name: ?[]const u8 = switch (coff.entry) {
380 // This logic isn't quite right for disabled or enabled. No point in fixing it380 // This logic isn't quite right for disabled or enabled. No point in fixing it
...@@ -811,7 +811,7 @@ fn elfLink(lld: *Lld, arena: Allocator) !void {...@@ -811,7 +811,7 @@ fn elfLink(lld: *Lld, arena: Allocator) !void {
811 const is_dyn_lib = link_mode == .dynamic and is_lib;811 const is_dyn_lib = link_mode == .dynamic and is_lib;
812 const is_exe_or_dyn_lib = is_dyn_lib or output_mode == .Exe;812 const is_exe_or_dyn_lib = is_dyn_lib or output_mode == .Exe;
813 const have_dynamic_linker = link_mode == .dynamic and is_exe_or_dyn_lib;813 const have_dynamic_linker = link_mode == .dynamic and is_exe_or_dyn_lib;
814 const target = comp.root_mod.resolved_target.result;814 const target = &comp.root_mod.resolved_target.result;
815 const compiler_rt_path: ?Cache.Path = blk: {815 const compiler_rt_path: ?Cache.Path = blk: {
816 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;816 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
817 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;817 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
...@@ -1281,7 +1281,7 @@ fn elfLink(lld: *Lld, arena: Allocator) !void {...@@ -1281,7 +1281,7 @@ fn elfLink(lld: *Lld, arena: Allocator) !void {
1281 try spawnLld(comp, arena, argv.items);1281 try spawnLld(comp, arena, argv.items);
1282 }1282 }
1283}1283}
1284fn getLDMOption(target: std.Target) ?[]const u8 {1284fn getLDMOption(target: *const std.Target) ?[]const u8 {
1285 // This should only return emulations understood by LLD's parseEmulation().1285 // This should only return emulations understood by LLD's parseEmulation().
1286 return switch (target.cpu.arch) {1286 return switch (target.cpu.arch) {
1287 .aarch64 => switch (target.os.tag) {1287 .aarch64 => switch (target.os.tag) {
...@@ -1364,7 +1364,7 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void {...@@ -1364,7 +1364,7 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void {
1364 const shared_memory = comp.config.shared_memory;1364 const shared_memory = comp.config.shared_memory;
1365 const export_memory = comp.config.export_memory;1365 const export_memory = comp.config.export_memory;
1366 const import_memory = comp.config.import_memory;1366 const import_memory = comp.config.import_memory;
1367 const target = comp.root_mod.resolved_target.result;1367 const target = &comp.root_mod.resolved_target.result;
1368 const base = &lld.base;1368 const base = &lld.base;
1369 const wasm = &lld.ofmt.wasm;1369 const wasm = &lld.ofmt.wasm;
13701370
src/link/MachO.zig+4-4
...@@ -163,7 +163,7 @@ pub fn createEmpty(...@@ -163,7 +163,7 @@ pub fn createEmpty(
163 emit: Path,163 emit: Path,
164 options: link.File.OpenOptions,164 options: link.File.OpenOptions,
165) !*MachO {165) !*MachO {
166 const target = comp.root_mod.resolved_target.result;166 const target = &comp.root_mod.resolved_target.result;
167 assert(target.ofmt == .macho);167 assert(target.ofmt == .macho);
168168
169 const gpa = comp.gpa;169 const gpa = comp.gpa;
...@@ -3545,8 +3545,8 @@ pub fn markDirty(self: *MachO, sect_index: u8) void {...@@ -3545,8 +3545,8 @@ pub fn markDirty(self: *MachO, sect_index: u8) void {
3545 }3545 }
3546}3546}
35473547
3548pub fn getTarget(self: MachO) std.Target {3548pub fn getTarget(self: *const MachO) *const std.Target {
3549 return self.base.comp.root_mod.resolved_target.result;3549 return &self.base.comp.root_mod.resolved_target.result;
3550}3550}
35513551
3552/// XNU starting with Big Sur running on arm64 is caching inodes of running binaries.3552/// XNU starting with Big Sur running on arm64 is caching inodes of running binaries.
...@@ -4233,7 +4233,7 @@ pub const Platform = struct {...@@ -4233,7 +4233,7 @@ pub const Platform = struct {
4233 }4233 }
4234 }4234 }
42354235
4236 pub fn fromTarget(target: std.Target) Platform {4236 pub fn fromTarget(target: *const std.Target) Platform {
4237 return .{4237 return .{
4238 .os_tag = target.os.tag,4238 .os_tag = target.os.tag,
4239 .abi = target.abi,4239 .abi = target.abi,
src/link/MachO/ZigObject.zig+1-1
...@@ -948,7 +948,7 @@ fn updateNavCode(...@@ -948,7 +948,7 @@ fn updateNavCode(
948948
949 log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });949 log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });
950950
951 const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;951 const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
952 const required_alignment = switch (pt.navAlignment(nav_index)) {952 const required_alignment = switch (pt.navAlignment(nav_index)) {
953 .none => target_util.defaultFunctionAlignment(target),953 .none => target_util.defaultFunctionAlignment(target),
954 else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),954 else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
src/link/Plan9.zig+5-5
...@@ -184,7 +184,7 @@ pub const Atom = struct {...@@ -184,7 +184,7 @@ pub const Atom = struct {
184184
185 // asserts that self.got_index != null185 // asserts that self.got_index != null
186 pub fn getOffsetTableAddress(self: Atom, plan9: *Plan9) u64 {186 pub fn getOffsetTableAddress(self: Atom, plan9: *Plan9) u64 {
187 const target = plan9.base.comp.root_mod.resolved_target.result;187 const target = &plan9.base.comp.root_mod.resolved_target.result;
188 const ptr_bytes = @divExact(target.ptrBitWidth(), 8);188 const ptr_bytes = @divExact(target.ptrBitWidth(), 8);
189 const got_addr = plan9.bases.data;189 const got_addr = plan9.bases.data;
190 const got_index = self.got_index.?;190 const got_index = self.got_index.?;
...@@ -278,7 +278,7 @@ pub fn createEmpty(...@@ -278,7 +278,7 @@ pub fn createEmpty(
278 emit: Path,278 emit: Path,
279 options: link.File.OpenOptions,279 options: link.File.OpenOptions,
280) !*Plan9 {280) !*Plan9 {
281 const target = comp.root_mod.resolved_target.result;281 const target = &comp.root_mod.resolved_target.result;
282 const gpa = comp.gpa;282 const gpa = comp.gpa;
283 const optimize_mode = comp.root_mod.optimize_mode;283 const optimize_mode = comp.root_mod.optimize_mode;
284 const output_mode = comp.config.output_mode;284 const output_mode = comp.config.output_mode;
...@@ -394,7 +394,7 @@ pub fn updateFunc(...@@ -394,7 +394,7 @@ pub fn updateFunc(
394394
395 const zcu = pt.zcu;395 const zcu = pt.zcu;
396 const gpa = zcu.gpa;396 const gpa = zcu.gpa;
397 const target = self.base.comp.root_mod.resolved_target.result;397 const target = &self.base.comp.root_mod.resolved_target.result;
398 const func = zcu.funcInfo(func_index);398 const func = zcu.funcInfo(func_index);
399399
400 const atom_idx = try self.seeNav(pt, func.owner_nav);400 const atom_idx = try self.seeNav(pt, func.owner_nav);
...@@ -583,7 +583,7 @@ pub fn flush(...@@ -583,7 +583,7 @@ pub fn flush(
583 const comp = self.base.comp;583 const comp = self.base.comp;
584 const diags = &comp.link_diags;584 const diags = &comp.link_diags;
585 const gpa = comp.gpa;585 const gpa = comp.gpa;
586 const target = comp.root_mod.resolved_target.result;586 const target = &comp.root_mod.resolved_target.result;
587587
588 switch (comp.config.output_mode) {588 switch (comp.config.output_mode) {
589 .Exe => {},589 .Exe => {},
...@@ -1153,7 +1153,7 @@ pub fn open(...@@ -1153,7 +1153,7 @@ pub fn open(
1153 emit: Path,1153 emit: Path,
1154 options: link.File.OpenOptions,1154 options: link.File.OpenOptions,
1155) !*Plan9 {1155) !*Plan9 {
1156 const target = comp.root_mod.resolved_target.result;1156 const target = &comp.root_mod.resolved_target.result;
1157 const use_lld = build_options.have_llvm and comp.config.use_lld;1157 const use_lld = build_options.have_llvm and comp.config.use_lld;
1158 const use_llvm = comp.config.use_llvm;1158 const use_llvm = comp.config.use_llvm;
11591159
src/link/SpirV.zig+1-1
...@@ -58,7 +58,7 @@ pub fn createEmpty(...@@ -58,7 +58,7 @@ pub fn createEmpty(
58 options: link.File.OpenOptions,58 options: link.File.OpenOptions,
59) !*SpirV {59) !*SpirV {
60 const gpa = comp.gpa;60 const gpa = comp.gpa;
61 const target = comp.root_mod.resolved_target.result;61 const target = &comp.root_mod.resolved_target.result;
6262
63 assert(!comp.config.use_lld); // Caught by Compilation.Config.resolve63 assert(!comp.config.use_lld); // Caught by Compilation.Config.resolve
64 assert(!comp.config.use_llvm); // Caught by Compilation.Config.resolve64 assert(!comp.config.use_llvm); // Caught by Compilation.Config.resolve
src/link/Wasm.zig+1-1
...@@ -2943,7 +2943,7 @@ pub fn createEmpty(...@@ -2943,7 +2943,7 @@ pub fn createEmpty(
2943 emit: Path,2943 emit: Path,
2944 options: link.File.OpenOptions,2944 options: link.File.OpenOptions,
2945) !*Wasm {2945) !*Wasm {
2946 const target = comp.root_mod.resolved_target.result;2946 const target = &comp.root_mod.resolved_target.result;
2947 assert(target.ofmt == .wasm);2947 assert(target.ofmt == .wasm);
29482948
2949 const use_llvm = comp.config.use_llvm;2949 const use_llvm = comp.config.use_llvm;
src/link/Xcoff.zig+2-2
...@@ -26,7 +26,7 @@ pub fn createEmpty(...@@ -26,7 +26,7 @@ pub fn createEmpty(
26 emit: Path,26 emit: Path,
27 options: link.File.OpenOptions,27 options: link.File.OpenOptions,
28) !*Xcoff {28) !*Xcoff {
29 const target = comp.root_mod.resolved_target.result;29 const target = &comp.root_mod.resolved_target.result;
30 const use_lld = build_options.have_llvm and comp.config.use_lld;30 const use_lld = build_options.have_llvm and comp.config.use_lld;
31 const use_llvm = comp.config.use_llvm;31 const use_llvm = comp.config.use_llvm;
3232
...@@ -59,7 +59,7 @@ pub fn open(...@@ -59,7 +59,7 @@ pub fn open(
59 emit: Path,59 emit: Path,
60 options: link.File.OpenOptions,60 options: link.File.OpenOptions,
61) !*Xcoff {61) !*Xcoff {
62 const target = comp.root_mod.resolved_target.result;62 const target = &comp.root_mod.resolved_target.result;
63 assert(target.ofmt == .xcoff);63 assert(target.ofmt == .xcoff);
64 return createEmpty(arena, comp, emit, options);64 return createEmpty(arena, comp, emit, options);
65}65}
src/main.zig+7-7
...@@ -340,7 +340,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -340,7 +340,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
340 dev.check(.targets_command);340 dev.check(.targets_command);
341 const host = std.zig.resolveTargetQueryOrFatal(.{});341 const host = std.zig.resolveTargetQueryOrFatal(.{});
342 const stdout = io.getStdOut().writer();342 const stdout = io.getStdOut().writer();
343 return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, host);343 return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, &host);
344 } else if (mem.eql(u8, cmd, "version")) {344 } else if (mem.eql(u8, cmd, "version")) {
345 dev.check(.version_command);345 dev.check(.version_command);
346 try std.io.getStdOut().writeAll(build_options.version ++ "\n");346 try std.io.getStdOut().writeAll(build_options.version ++ "\n");
...@@ -3086,7 +3086,7 @@ fn buildOutputType(...@@ -3086,7 +3086,7 @@ fn buildOutputType(
3086 else => main_mod,3086 else => main_mod,
3087 };3087 };
30883088
3089 const target = main_mod.resolved_target.result;3089 const target = &main_mod.resolved_target.result;
30903090
3091 if (target.cpu.arch == .arc or target.cpu.arch.isNvptx()) {3091 if (target.cpu.arch == .arc or target.cpu.arch.isNvptx()) {
3092 if (emit_bin != .no and create_module.resolved_options.use_llvm) {3092 if (emit_bin != .no and create_module.resolved_options.use_llvm) {
...@@ -3655,7 +3655,7 @@ fn buildOutputType(...@@ -3655,7 +3655,7 @@ fn buildOutputType(
3655 test_exec_args.items,3655 test_exec_args.items,
3656 self_exe_path,3656 self_exe_path,
3657 arg_mode,3657 arg_mode,
3658 &target,3658 target,
3659 &comp_destroyed,3659 &comp_destroyed,
3660 all_args,3660 all_args,
3661 runtime_args_start,3661 runtime_args_start,
...@@ -3800,12 +3800,12 @@ fn createModule(...@@ -3800,12 +3800,12 @@ fn createModule(
3800 // This block is for initializing the fields of3800 // This block is for initializing the fields of
3801 // `Compilation.Config.Options` that require knowledge of the3801 // `Compilation.Config.Options` that require knowledge of the
3802 // target (which was just now resolved for the root module above).3802 // target (which was just now resolved for the root module above).
3803 const resolved_target = cli_mod.inherited.resolved_target.?;3803 const resolved_target = &cli_mod.inherited.resolved_target.?;
3804 create_module.opts.resolved_target = resolved_target;3804 create_module.opts.resolved_target = resolved_target.*;
3805 create_module.opts.root_optimize_mode = cli_mod.inherited.optimize_mode;3805 create_module.opts.root_optimize_mode = cli_mod.inherited.optimize_mode;
3806 create_module.opts.root_strip = cli_mod.inherited.strip;3806 create_module.opts.root_strip = cli_mod.inherited.strip;
3807 create_module.opts.root_error_tracing = cli_mod.inherited.error_tracing;3807 create_module.opts.root_error_tracing = cli_mod.inherited.error_tracing;
3808 const target = resolved_target.result;3808 const target = &resolved_target.result;
38093809
3810 // First, remove libc, libc++, and compiler_rt libraries from the system libraries list.3810 // First, remove libc, libc++, and compiler_rt libraries from the system libraries list.
3811 // We need to know whether the set of system libraries contains anything besides these3811 // We need to know whether the set of system libraries contains anything besides these
...@@ -6482,7 +6482,7 @@ fn warnAboutForeignBinaries(...@@ -6482,7 +6482,7 @@ fn warnAboutForeignBinaries(
6482 const host_query: std.Target.Query = .{};6482 const host_query: std.Target.Query = .{};
6483 const host_target = std.zig.resolveTargetQueryOrFatal(host_query);6483 const host_target = std.zig.resolveTargetQueryOrFatal(host_query);
64846484
6485 switch (std.zig.system.getExternalExecutor(host_target, target, .{ .link_libc = link_libc })) {6485 switch (std.zig.system.getExternalExecutor(&host_target, target, .{ .link_libc = link_libc })) {
6486 .native => return,6486 .native => return,
6487 .rosetta => {6487 .rosetta => {
6488 const host_name = try host_target.zigTriple(arena);6488 const host_name = try host_target.zigTriple(arena);
src/print_targets.zig+1-1
...@@ -16,7 +16,7 @@ pub fn cmdTargets(...@@ -16,7 +16,7 @@ pub fn cmdTargets(
16 args: []const []const u8,16 args: []const []const u8,
17 /// Output stream17 /// Output stream
18 stdout: anytype,18 stdout: anytype,
19 native_target: Target,19 native_target: *const Target,
20) !void {20) !void {
21 _ = args;21 _ = args;
22 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {22 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {
src/target.zig+45-42
...@@ -9,7 +9,7 @@ const Feature = @import("Zcu.zig").Feature;...@@ -9,7 +9,7 @@ const Feature = @import("Zcu.zig").Feature;
99
10pub const default_stack_protector_buffer_size = 4;10pub const default_stack_protector_buffer_size = 4;
1111
12pub fn cannotDynamicLink(target: std.Target) bool {12pub fn cannotDynamicLink(target: *const std.Target) bool {
13 return switch (target.os.tag) {13 return switch (target.os.tag) {
14 .freestanding => true,14 .freestanding => true,
15 else => target.cpu.arch.isSpirV(),15 else => target.cpu.arch.isSpirV(),
...@@ -19,15 +19,15 @@ pub fn cannotDynamicLink(target: std.Target) bool {...@@ -19,15 +19,15 @@ pub fn cannotDynamicLink(target: std.Target) bool {
19/// On Darwin, we always link libSystem which contains libc.19/// On Darwin, we always link libSystem which contains libc.
20/// Similarly on FreeBSD and NetBSD we always link system libc20/// Similarly on FreeBSD and NetBSD we always link system libc
21/// since this is the stable syscall interface.21/// since this is the stable syscall interface.
22pub fn osRequiresLibC(target: std.Target) bool {22pub fn osRequiresLibC(target: *const std.Target) bool {
23 return target.os.requiresLibC();23 return target.os.requiresLibC();
24}24}
2525
26pub fn libCNeedsLibUnwind(target: std.Target, link_mode: std.builtin.LinkMode) bool {26pub fn libCNeedsLibUnwind(target: *const std.Target, link_mode: std.builtin.LinkMode) bool {
27 return target.isGnuLibC() and link_mode == .static;27 return target.isGnuLibC() and link_mode == .static;
28}28}
2929
30pub fn libCxxNeedsLibUnwind(target: std.Target) bool {30pub fn libCxxNeedsLibUnwind(target: *const std.Target) bool {
31 return switch (target.os.tag) {31 return switch (target.os.tag) {
32 .macos,32 .macos,
33 .ios,33 .ios,
...@@ -44,14 +44,14 @@ pub fn libCxxNeedsLibUnwind(target: std.Target) bool {...@@ -44,14 +44,14 @@ pub fn libCxxNeedsLibUnwind(target: std.Target) bool {
44}44}
4545
46/// This function returns whether non-pic code is completely invalid on the given target.46/// This function returns whether non-pic code is completely invalid on the given target.
47pub fn requiresPIC(target: std.Target, linking_libc: bool) bool {47pub fn requiresPIC(target: *const std.Target, linking_libc: bool) bool {
48 return target.abi.isAndroid() or48 return target.abi.isAndroid() or
49 target.os.tag == .windows or target.os.tag == .uefi or49 target.os.tag == .windows or target.os.tag == .uefi or
50 osRequiresLibC(target) or50 osRequiresLibC(target) or
51 (linking_libc and target.isGnuLibC());51 (linking_libc and target.isGnuLibC());
52}52}
5353
54pub fn picLevel(target: std.Target) u32 {54pub fn picLevel(target: *const std.Target) u32 {
55 // MIPS always uses PIC level 1; other platforms vary in their default PIC levels, but they55 // MIPS always uses PIC level 1; other platforms vary in their default PIC levels, but they
56 // support both level 1 and 2, in which case we prefer 2.56 // support both level 1 and 2, in which case we prefer 2.
57 return if (target.cpu.arch.isMIPS()) 1 else 2;57 return if (target.cpu.arch.isMIPS()) 1 else 2;
...@@ -59,7 +59,7 @@ pub fn picLevel(target: std.Target) u32 {...@@ -59,7 +59,7 @@ pub fn picLevel(target: std.Target) u32 {
5959
60/// This is not whether the target supports Position Independent Code, but whether the -fPIC60/// This is not whether the target supports Position Independent Code, but whether the -fPIC
61/// C compiler argument is valid to Clang.61/// C compiler argument is valid to Clang.
62pub fn supports_fpic(target: std.Target) bool {62pub fn supports_fpic(target: *const std.Target) bool {
63 return switch (target.os.tag) {63 return switch (target.os.tag) {
64 .windows,64 .windows,
65 .uefi,65 .uefi,
...@@ -68,12 +68,12 @@ pub fn supports_fpic(target: std.Target) bool {...@@ -68,12 +68,12 @@ pub fn supports_fpic(target: std.Target) bool {
68 };68 };
69}69}
7070
71pub fn alwaysSingleThreaded(target: std.Target) bool {71pub fn alwaysSingleThreaded(target: *const std.Target) bool {
72 _ = target;72 _ = target;
73 return false;73 return false;
74}74}
7575
76pub fn defaultSingleThreaded(target: std.Target) bool {76pub fn defaultSingleThreaded(target: *const std.Target) bool {
77 switch (target.cpu.arch) {77 switch (target.cpu.arch) {
78 .wasm32, .wasm64 => return true,78 .wasm32, .wasm64 => return true,
79 else => {},79 else => {},
...@@ -85,7 +85,7 @@ pub fn defaultSingleThreaded(target: std.Target) bool {...@@ -85,7 +85,7 @@ pub fn defaultSingleThreaded(target: std.Target) bool {
85 return false;85 return false;
86}86}
8787
88pub fn hasValgrindSupport(target: std.Target, backend: std.builtin.CompilerBackend) bool {88pub fn hasValgrindSupport(target: *const std.Target, backend: std.builtin.CompilerBackend) bool {
89 // We can't currently output the necessary Valgrind client request assembly when using the C89 // We can't currently output the necessary Valgrind client request assembly when using the C
90 // backend and compiling with an MSVC-like compiler.90 // backend and compiling with an MSVC-like compiler.
91 const ofmt_c_msvc = (target.abi == .msvc or target.abi == .itanium) and target.ofmt == .c;91 const ofmt_c_msvc = (target.abi == .msvc or target.abi == .itanium) and target.ofmt == .c;
...@@ -133,7 +133,7 @@ pub fn hasValgrindSupport(target: std.Target, backend: std.builtin.CompilerBacke...@@ -133,7 +133,7 @@ pub fn hasValgrindSupport(target: std.Target, backend: std.builtin.CompilerBacke
133/// The set of targets that LLVM has non-experimental support for.133/// The set of targets that LLVM has non-experimental support for.
134/// Used to select between LLVM backend and self-hosted backend when compiling in134/// Used to select between LLVM backend and self-hosted backend when compiling in
135/// release modes.135/// release modes.
136pub fn hasLlvmSupport(target: std.Target, ofmt: std.Target.ObjectFormat) bool {136pub fn hasLlvmSupport(target: *const std.Target, ofmt: std.Target.ObjectFormat) bool {
137 switch (ofmt) {137 switch (ofmt) {
138 // LLVM does not support these object formats:138 // LLVM does not support these object formats:
139 .c,139 .c,
...@@ -221,7 +221,7 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool {...@@ -221,7 +221,7 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool {
221/// Used to select between LLVM backend and self-hosted backend when compiling in221/// Used to select between LLVM backend and self-hosted backend when compiling in
222/// debug mode. A given target should only return true here if it is passing greater222/// debug mode. A given target should only return true here if it is passing greater
223/// than or equal to the number of behavior tests as the respective LLVM backend.223/// than or equal to the number of behavior tests as the respective LLVM backend.
224pub fn selfHostedBackendIsAsRobustAsLlvm(target: std.Target) bool {224pub fn selfHostedBackendIsAsRobustAsLlvm(target: *const std.Target) bool {
225 if (target.cpu.arch.isSpirV()) return true;225 if (target.cpu.arch.isSpirV()) return true;
226 if (target.cpu.arch == .x86_64 and target.ptrBitWidth() == 64) return switch (target.ofmt) {226 if (target.cpu.arch == .x86_64 and target.ptrBitWidth() == 64) return switch (target.ofmt) {
227 .elf, .macho => true,227 .elf, .macho => true,
...@@ -230,12 +230,12 @@ pub fn selfHostedBackendIsAsRobustAsLlvm(target: std.Target) bool {...@@ -230,12 +230,12 @@ pub fn selfHostedBackendIsAsRobustAsLlvm(target: std.Target) bool {
230 return false;230 return false;
231}231}
232232
233pub fn supportsStackProbing(target: std.Target) bool {233pub fn supportsStackProbing(target: *const std.Target) bool {
234 return target.os.tag != .windows and target.os.tag != .uefi and234 return target.os.tag != .windows and target.os.tag != .uefi and
235 (target.cpu.arch == .x86 or target.cpu.arch == .x86_64);235 (target.cpu.arch == .x86 or target.cpu.arch == .x86_64);
236}236}
237237
238pub fn supportsStackProtector(target: std.Target, backend: std.builtin.CompilerBackend) bool {238pub fn supportsStackProtector(target: *const std.Target, backend: std.builtin.CompilerBackend) bool {
239 switch (target.os.tag) {239 switch (target.os.tag) {
240 .plan9 => return false,240 .plan9 => return false,
241 else => {},241 else => {},
...@@ -250,20 +250,20 @@ pub fn supportsStackProtector(target: std.Target, backend: std.builtin.CompilerB...@@ -250,20 +250,20 @@ pub fn supportsStackProtector(target: std.Target, backend: std.builtin.CompilerB
250 };250 };
251}251}
252252
253pub fn clangSupportsStackProtector(target: std.Target) bool {253pub fn clangSupportsStackProtector(target: *const std.Target) bool {
254 return switch (target.cpu.arch) {254 return switch (target.cpu.arch) {
255 .spirv, .spirv32, .spirv64 => return false,255 .spirv, .spirv32, .spirv64 => return false,
256 else => true,256 else => true,
257 };257 };
258}258}
259259
260pub fn libcProvidesStackProtector(target: std.Target) bool {260pub fn libcProvidesStackProtector(target: *const std.Target) bool {
261 return !target.isMinGW() and target.os.tag != .wasi and !target.cpu.arch.isSpirV();261 return !target.isMinGW() and target.os.tag != .wasi and !target.cpu.arch.isSpirV();
262}262}
263263
264/// Returns true if `@returnAddress()` is supported by the target and has a264/// Returns true if `@returnAddress()` is supported by the target and has a
265/// reasonably performant implementation for the requested optimization mode.265/// reasonably performant implementation for the requested optimization mode.
266pub fn supportsReturnAddress(target: std.Target, optimize: std.builtin.OptimizeMode) bool {266pub fn supportsReturnAddress(target: *const std.Target, optimize: std.builtin.OptimizeMode) bool {
267 return switch (target.cpu.arch) {267 return switch (target.cpu.arch) {
268 // Emscripten currently implements `emscripten_return_address()` by calling268 // Emscripten currently implements `emscripten_return_address()` by calling
269 // out into JavaScript and parsing a stack trace, which introduces significant269 // out into JavaScript and parsing a stack trace, which introduces significant
...@@ -299,7 +299,7 @@ pub fn classifyCompilerRtLibName(name: []const u8) CompilerRtClassification {...@@ -299,7 +299,7 @@ pub fn classifyCompilerRtLibName(name: []const u8) CompilerRtClassification {
299 return .none;299 return .none;
300}300}
301301
302pub fn hasDebugInfo(target: std.Target) bool {302pub fn hasDebugInfo(target: *const std.Target) bool {
303 return switch (target.cpu.arch) {303 return switch (target.cpu.arch) {
304 // TODO: We should make newer PTX versions depend on older ones so we'd just check `ptx75`.304 // TODO: We should make newer PTX versions depend on older ones so we'd just check `ptx75`.
305 .nvptx, .nvptx64 => target.cpu.hasAny(.nvptx, &.{305 .nvptx, .nvptx64 => target.cpu.hasAny(.nvptx, &.{
...@@ -321,7 +321,7 @@ pub fn hasDebugInfo(target: std.Target) bool {...@@ -321,7 +321,7 @@ pub fn hasDebugInfo(target: std.Target) bool {
321 };321 };
322}322}
323323
324pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.OptimizeMode {324pub fn defaultCompilerRtOptimizeMode(target: *const std.Target) std.builtin.OptimizeMode {
325 if (target.cpu.arch.isWasm() and target.os.tag == .freestanding) {325 if (target.cpu.arch.isWasm() and target.os.tag == .freestanding) {
326 return .ReleaseSmall;326 return .ReleaseSmall;
327 } else {327 } else {
...@@ -329,7 +329,7 @@ pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.OptimizeMod...@@ -329,7 +329,7 @@ pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.OptimizeMod
329 }329 }
330}330}
331331
332pub fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool, have_llvm: bool) bool {332pub fn canBuildLibCompilerRt(target: *const std.Target, use_llvm: bool, have_llvm: bool) bool {
333 switch (target.os.tag) {333 switch (target.os.tag) {
334 .plan9 => return false,334 .plan9 => return false,
335 else => {},335 else => {},
...@@ -342,12 +342,15 @@ pub fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool, have_llvm: bool...@@ -342,12 +342,15 @@ pub fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool, have_llvm: bool
342 }342 }
343 return switch (zigBackend(target, use_llvm)) {343 return switch (zigBackend(target, use_llvm)) {
344 .stage2_llvm => true,344 .stage2_llvm => true,
345 .stage2_x86_64 => if (target.ofmt == .elf or target.ofmt == .macho) true else have_llvm,345 .stage2_x86_64 => switch (target.ofmt) {
346 .elf, .macho => true,
347 else => have_llvm,
348 },
346 else => have_llvm,349 else => have_llvm,
347 };350 };
348}351}
349352
350pub fn canBuildLibUbsanRt(target: std.Target) bool {353pub fn canBuildLibUbsanRt(target: *const std.Target) bool {
351 switch (target.cpu.arch) {354 switch (target.cpu.arch) {
352 .spirv, .spirv32, .spirv64 => return false,355 .spirv, .spirv32, .spirv64 => return false,
353 // Remove this once https://github.com/ziglang/zig/issues/23715 is fixed356 // Remove this once https://github.com/ziglang/zig/issues/23715 is fixed
...@@ -356,7 +359,7 @@ pub fn canBuildLibUbsanRt(target: std.Target) bool {...@@ -356,7 +359,7 @@ pub fn canBuildLibUbsanRt(target: std.Target) bool {
356 }359 }
357}360}
358361
359pub fn hasRedZone(target: std.Target) bool {362pub fn hasRedZone(target: *const std.Target) bool {
360 return switch (target.cpu.arch) {363 return switch (target.cpu.arch) {
361 .aarch64,364 .aarch64,
362 .aarch64_be,365 .aarch64_be,
...@@ -372,7 +375,7 @@ pub fn hasRedZone(target: std.Target) bool {...@@ -372,7 +375,7 @@ pub fn hasRedZone(target: std.Target) bool {
372 };375 };
373}376}
374377
375pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {378pub fn libcFullLinkFlags(target: *const std.Target) []const []const u8 {
376 // The linking order of these is significant and should match the order other379 // The linking order of these is significant and should match the order other
377 // c compilers such as gcc or clang use.380 // c compilers such as gcc or clang use.
378 const result: []const []const u8 = switch (target.os.tag) {381 const result: []const []const u8 = switch (target.os.tag) {
...@@ -389,14 +392,14 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {...@@ -389,14 +392,14 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
389 return result;392 return result;
390}393}
391394
392pub fn clangMightShellOutForAssembly(target: std.Target) bool {395pub fn clangMightShellOutForAssembly(target: *const std.Target) bool {
393 // Clang defaults to using the system assembler in some cases.396 // Clang defaults to using the system assembler in some cases.
394 return target.cpu.arch.isNvptx() or target.cpu.arch == .xcore;397 return target.cpu.arch.isNvptx() or target.cpu.arch == .xcore;
395}398}
396399
397/// Each backend architecture in Clang has a different codepath which may or may not400/// Each backend architecture in Clang has a different codepath which may or may not
398/// support an -mcpu flag.401/// support an -mcpu flag.
399pub fn clangAssemblerSupportsMcpuArg(target: std.Target) bool {402pub fn clangAssemblerSupportsMcpuArg(target: *const std.Target) bool {
400 return switch (target.cpu.arch) {403 return switch (target.cpu.arch) {
401 .arm, .armeb, .thumb, .thumbeb => true,404 .arm, .armeb, .thumb, .thumbeb => true,
402 else => false,405 else => false,
...@@ -405,7 +408,7 @@ pub fn clangAssemblerSupportsMcpuArg(target: std.Target) bool {...@@ -405,7 +408,7 @@ pub fn clangAssemblerSupportsMcpuArg(target: std.Target) bool {
405408
406/// Some experimental or poorly-maintained LLVM targets do not properly process CPU models in their409/// Some experimental or poorly-maintained LLVM targets do not properly process CPU models in their
407/// Clang driver code. For these, we should omit the `-Xclang -target-cpu -Xclang <model>` flags.410/// Clang driver code. For these, we should omit the `-Xclang -target-cpu -Xclang <model>` flags.
408pub fn clangSupportsTargetCpuArg(target: std.Target) bool {411pub fn clangSupportsTargetCpuArg(target: *const std.Target) bool {
409 return switch (target.cpu.arch) {412 return switch (target.cpu.arch) {
410 .arc,413 .arc,
411 .msp430,414 .msp430,
...@@ -417,7 +420,7 @@ pub fn clangSupportsTargetCpuArg(target: std.Target) bool {...@@ -417,7 +420,7 @@ pub fn clangSupportsTargetCpuArg(target: std.Target) bool {
417 };420 };
418}421}
419422
420pub fn clangSupportsFloatAbiArg(target: std.Target) bool {423pub fn clangSupportsFloatAbiArg(target: *const std.Target) bool {
421 return switch (target.cpu.arch) {424 return switch (target.cpu.arch) {
422 .arm,425 .arm,
423 .armeb,426 .armeb,
...@@ -442,7 +445,7 @@ pub fn clangSupportsFloatAbiArg(target: std.Target) bool {...@@ -442,7 +445,7 @@ pub fn clangSupportsFloatAbiArg(target: std.Target) bool {
442 };445 };
443}446}
444447
445pub fn clangSupportsNoImplicitFloatArg(target: std.Target) bool {448pub fn clangSupportsNoImplicitFloatArg(target: *const std.Target) bool {
446 return switch (target.cpu.arch) {449 return switch (target.cpu.arch) {
447 .aarch64,450 .aarch64,
448 .aarch64_be,451 .aarch64_be,
...@@ -459,7 +462,7 @@ pub fn clangSupportsNoImplicitFloatArg(target: std.Target) bool {...@@ -459,7 +462,7 @@ pub fn clangSupportsNoImplicitFloatArg(target: std.Target) bool {
459 };462 };
460}463}
461464
462pub fn defaultUnwindTables(target: std.Target, libunwind: bool, libtsan: bool) std.builtin.UnwindTables {465pub fn defaultUnwindTables(target: *const std.Target, libunwind: bool, libtsan: bool) std.builtin.UnwindTables {
463 if (target.os.tag == .windows) {466 if (target.os.tag == .windows) {
464 // The old 32-bit x86 variant of SEH doesn't use tables.467 // The old 32-bit x86 variant of SEH doesn't use tables.
465 return if (target.cpu.arch != .x86) .@"async" else .none;468 return if (target.cpu.arch != .x86) .@"async" else .none;
...@@ -472,7 +475,7 @@ pub fn defaultUnwindTables(target: std.Target, libunwind: bool, libtsan: bool) s...@@ -472,7 +475,7 @@ pub fn defaultUnwindTables(target: std.Target, libunwind: bool, libtsan: bool) s
472}475}
473476
474pub fn defaultAddressSpace(477pub fn defaultAddressSpace(
475 target: std.Target,478 target: *const std.Target,
476 context: enum {479 context: enum {
477 /// Query the default address space for global constant values.480 /// Query the default address space for global constant values.
478 global_constant,481 global_constant,
...@@ -492,7 +495,7 @@ pub fn defaultAddressSpace(...@@ -492,7 +495,7 @@ pub fn defaultAddressSpace(
492495
493/// Returns true if pointers in `from` can be converted to a pointer in `to`.496/// Returns true if pointers in `from` can be converted to a pointer in `to`.
494pub fn addrSpaceCastIsValid(497pub fn addrSpaceCastIsValid(
495 target: std.Target,498 target: *const std.Target,
496 from: AddressSpace,499 from: AddressSpace,
497 to: AddressSpace,500 to: AddressSpace,
498) bool {501) bool {
...@@ -512,7 +515,7 @@ pub fn addrSpaceCastIsValid(...@@ -512,7 +515,7 @@ pub fn addrSpaceCastIsValid(
512/// a number of restrictions on usage of such pointers. For example, a logical pointer may not be515/// a number of restrictions on usage of such pointers. For example, a logical pointer may not be
513/// part of a merge (result of a branch) and may not be stored in memory at all. This function returns516/// part of a merge (result of a branch) and may not be stored in memory at all. This function returns
514/// for a particular architecture and address space wether such pointers are logical.517/// for a particular architecture and address space wether such pointers are logical.
515pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {518pub fn arePointersLogical(target: *const std.Target, as: AddressSpace) bool {
516 if (target.os.tag != .vulkan) return false;519 if (target.os.tag != .vulkan) return false;
517520
518 return switch (as) {521 return switch (as) {
...@@ -537,7 +540,7 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {...@@ -537,7 +540,7 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {
537 };540 };
538}541}
539542
540pub fn isDynamicAMDGCNFeature(target: std.Target, feature: std.Target.Cpu.Feature) bool {543pub fn isDynamicAMDGCNFeature(target: *const std.Target, feature: std.Target.Cpu.Feature) bool {
541 if (target.cpu.arch != .amdgcn) return false;544 if (target.cpu.arch != .amdgcn) return false;
542545
543 const sramecc_only = &[_]*const std.Target.Cpu.Model{546 const sramecc_only = &[_]*const std.Target.Cpu.Model{
...@@ -585,7 +588,7 @@ pub fn isDynamicAMDGCNFeature(target: std.Target, feature: std.Target.Cpu.Featur...@@ -585,7 +588,7 @@ pub fn isDynamicAMDGCNFeature(target: std.Target, feature: std.Target.Cpu.Featur
585 return false;588 return false;
586}589}
587590
588pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {591pub fn llvmMachineAbi(target: *const std.Target) ?[:0]const u8 {
589 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it592 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it
590 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc593 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc
591 // is linked as glibc only supports ELFv2 for little endian, but there's nothing we can do about594 // is linked as glibc only supports ELFv2 for little endian, but there's nothing we can do about
...@@ -642,7 +645,7 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {...@@ -642,7 +645,7 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
642645
643/// This function returns 1 if function alignment is not observable or settable. Note that this646/// This function returns 1 if function alignment is not observable or settable. Note that this
644/// value will not necessarily match the backend's default function alignment (e.g. for LLVM).647/// value will not necessarily match the backend's default function alignment (e.g. for LLVM).
645pub fn defaultFunctionAlignment(target: std.Target) Alignment {648pub fn defaultFunctionAlignment(target: *const std.Target) Alignment {
646 // Overrides of the minimum for performance.649 // Overrides of the minimum for performance.
647 return switch (target.cpu.arch) {650 return switch (target.cpu.arch) {
648 .csky,651 .csky,
...@@ -669,7 +672,7 @@ pub fn defaultFunctionAlignment(target: std.Target) Alignment {...@@ -669,7 +672,7 @@ pub fn defaultFunctionAlignment(target: std.Target) Alignment {
669}672}
670673
671/// This function returns 1 if function alignment is not observable or settable.674/// This function returns 1 if function alignment is not observable or settable.
672pub fn minFunctionAlignment(target: std.Target) Alignment {675pub fn minFunctionAlignment(target: *const std.Target) Alignment {
673 return switch (target.cpu.arch) {676 return switch (target.cpu.arch) {
674 .riscv32,677 .riscv32,
675 .riscv64,678 .riscv64,
...@@ -712,7 +715,7 @@ pub fn minFunctionAlignment(target: std.Target) Alignment {...@@ -712,7 +715,7 @@ pub fn minFunctionAlignment(target: std.Target) Alignment {
712 };715 };
713}716}
714717
715pub fn supportsFunctionAlignment(target: std.Target) bool {718pub fn supportsFunctionAlignment(target: *const std.Target) bool {
716 return switch (target.cpu.arch) {719 return switch (target.cpu.arch) {
717 .nvptx,720 .nvptx,
718 .nvptx64,721 .nvptx64,
...@@ -726,7 +729,7 @@ pub fn supportsFunctionAlignment(target: std.Target) bool {...@@ -726,7 +729,7 @@ pub fn supportsFunctionAlignment(target: std.Target) bool {
726 };729 };
727}730}
728731
729pub fn functionPointerMask(target: std.Target) ?u64 {732pub fn functionPointerMask(target: *const std.Target) ?u64 {
730 // 32-bit Arm uses the LSB to mean that the target function contains Thumb code.733 // 32-bit Arm uses the LSB to mean that the target function contains Thumb code.
731 // MIPS uses the LSB to mean that the target function contains MIPS16/microMIPS code.734 // MIPS uses the LSB to mean that the target function contains MIPS16/microMIPS code.
732 return if (target.cpu.arch.isArm() or target.cpu.arch.isMIPS32())735 return if (target.cpu.arch.isArm() or target.cpu.arch.isMIPS32())
...@@ -737,7 +740,7 @@ pub fn functionPointerMask(target: std.Target) ?u64 {...@@ -737,7 +740,7 @@ pub fn functionPointerMask(target: std.Target) ?u64 {
737 null;740 null;
738}741}
739742
740pub fn supportsTailCall(target: std.Target, backend: std.builtin.CompilerBackend) bool {743pub fn supportsTailCall(target: *const std.Target, backend: std.builtin.CompilerBackend) bool {
741 switch (backend) {744 switch (backend) {
742 .stage2_llvm => return @import("codegen/llvm.zig").supportsTailCall(target),745 .stage2_llvm => return @import("codegen/llvm.zig").supportsTailCall(target),
743 .stage2_c => return true,746 .stage2_c => return true,
...@@ -745,7 +748,7 @@ pub fn supportsTailCall(target: std.Target, backend: std.builtin.CompilerBackend...@@ -745,7 +748,7 @@ pub fn supportsTailCall(target: std.Target, backend: std.builtin.CompilerBackend
745 }748 }
746}749}
747750
748pub fn supportsThreads(target: std.Target, backend: std.builtin.CompilerBackend) bool {751pub fn supportsThreads(target: *const std.Target, backend: std.builtin.CompilerBackend) bool {
749 return switch (backend) {752 return switch (backend) {
750 .stage2_powerpc => true,753 .stage2_powerpc => true,
751 .stage2_x86_64 => target.ofmt == .macho or target.ofmt == .elf,754 .stage2_x86_64 => target.ofmt == .macho or target.ofmt == .elf,
...@@ -804,7 +807,7 @@ pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool {...@@ -804,7 +807,7 @@ pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool {
804 };807 };
805}808}
806809
807pub fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBackend {810pub fn zigBackend(target: *const std.Target, use_llvm: bool) std.builtin.CompilerBackend {
808 if (use_llvm) return .stage2_llvm;811 if (use_llvm) return .stage2_llvm;
809 if (target.ofmt == .c) return .stage2_c;812 if (target.ofmt == .c) return .stage2_c;
810 return switch (target.cpu.arch) {813 return switch (target.cpu.arch) {
test/link/macho.zig+1-1
...@@ -864,7 +864,7 @@ fn testLayout(b: *Build, opts: Options) *Step {...@@ -864,7 +864,7 @@ fn testLayout(b: *Build, opts: Options) *Step {
864fn testLinkDirectlyCppTbd(b: *Build, opts: Options) *Step {864fn testLinkDirectlyCppTbd(b: *Build, opts: Options) *Step {
865 const test_step = addTestStep(b, "link-directly-cpp-tbd", opts);865 const test_step = addTestStep(b, "link-directly-cpp-tbd", opts);
866866
867 const sdk = std.zig.system.darwin.getSdk(b.allocator, opts.target.result) orelse867 const sdk = std.zig.system.darwin.getSdk(b.allocator, &opts.target.result) orelse
868 @panic("macOS SDK is required to run the test");868 @panic("macOS SDK is required to run the test");
869869
870 const exe = addExecutable(b, opts, .{870 const exe = addExecutable(b, opts, .{
test/src/Cases.zig+2-2
...@@ -433,7 +433,7 @@ fn addFromDirInner(...@@ -433,7 +433,7 @@ fn addFromDirInner(
433 // Cross-product to get all possible test combinations433 // Cross-product to get all possible test combinations
434 for (targets) |target_query| {434 for (targets) |target_query| {
435 const resolved_target = b.resolveTargetQuery(target_query);435 const resolved_target = b.resolveTargetQuery(target_query);
436 const target = resolved_target.result;436 const target = &resolved_target.result;
437 for (backends) |backend| {437 for (backends) |backend| {
438 if (backend == .stage2 and438 if (backend == .stage2 and
439 target.cpu.arch != .wasm32 and target.cpu.arch != .x86_64 and target.cpu.arch != .spirv64)439 target.cpu.arch != .wasm32 and target.cpu.arch != .x86_64 and target.cpu.arch != .spirv64)
...@@ -708,7 +708,7 @@ pub fn lowerToBuildSteps(...@@ -708,7 +708,7 @@ pub fn lowerToBuildSteps(
708 },708 },
709 .Execution => |expected_stdout| no_exec: {709 .Execution => |expected_stdout| no_exec: {
710 const run = if (case.target.result.ofmt == .c) run_step: {710 const run = if (case.target.result.ofmt == .c) run_step: {
711 if (getExternalExecutor(host, &case.target.result, .{ .link_libc = true }) != .native) {711 if (getExternalExecutor(&host, &case.target.result, .{ .link_libc = true }) != .native) {
712 // We wouldn't be able to run the compiled C code.712 // We wouldn't be able to run the compiled C code.
713 break :no_exec;713 break :no_exec;
714 }714 }
test/src/Debugger.zig+4-4
...@@ -21,7 +21,7 @@ pub const Target = struct {...@@ -21,7 +21,7 @@ pub const Target = struct {
21 test_name_suffix: []const u8,21 test_name_suffix: []const u8,
22};22};
2323
24pub fn addTestsForTarget(db: *Debugger, target: Target) void {24pub fn addTestsForTarget(db: *Debugger, target: *const Target) void {
25 db.addLldbTest(25 db.addLldbTest(
26 "basic",26 "basic",
27 target,27 target,
...@@ -2376,7 +2376,7 @@ const File = struct { import: ?[]const u8 = null, path: []const u8, source: []co...@@ -2376,7 +2376,7 @@ const File = struct { import: ?[]const u8 = null, path: []const u8, source: []co
2376fn addGdbTest(2376fn addGdbTest(
2377 db: *Debugger,2377 db: *Debugger,
2378 name: []const u8,2378 name: []const u8,
2379 target: Target,2379 target: *const Target,
2380 files: []const File,2380 files: []const File,
2381 commands: []const u8,2381 commands: []const u8,
2382 expected_output: []const []const u8,2382 expected_output: []const []const u8,
...@@ -2402,7 +2402,7 @@ fn addGdbTest(...@@ -2402,7 +2402,7 @@ fn addGdbTest(
2402fn addLldbTest(2402fn addLldbTest(
2403 db: *Debugger,2403 db: *Debugger,
2404 name: []const u8,2404 name: []const u8,
2405 target: Target,2405 target: *const Target,
2406 files: []const File,2406 files: []const File,
2407 commands: []const u8,2407 commands: []const u8,
2408 expected_output: []const []const u8,2408 expected_output: []const []const u8,
...@@ -2433,7 +2433,7 @@ const success = 99;...@@ -2433,7 +2433,7 @@ const success = 99;
2433fn addTest(2433fn addTest(
2434 db: *Debugger,2434 db: *Debugger,
2435 name: []const u8,2435 name: []const u8,
2436 target: Target,2436 target: *const Target,
2437 files: []const File,2437 files: []const File,
2438 db_argv1: []const []const u8,2438 db_argv1: []const []const u8,
2439 db_commands: []const u8,2439 db_commands: []const u8,
test/src/StackTrace.zig+2-2
...@@ -22,7 +22,7 @@ const Config = struct {...@@ -22,7 +22,7 @@ const Config = struct {
2222
23pub fn addCase(self: *StackTrace, config: Config) void {23pub fn addCase(self: *StackTrace, config: Config) void {
24 self.addCaseInner(config, true);24 self.addCaseInner(config, true);
25 if (shouldTestNonLlvm(self.b.graph.host.result)) {25 if (shouldTestNonLlvm(&self.b.graph.host.result)) {
26 self.addCaseInner(config, false);26 self.addCaseInner(config, false);
27 }27 }
28}28}
...@@ -41,7 +41,7 @@ fn addCaseInner(self: *StackTrace, config: Config, use_llvm: bool) void {...@@ -41,7 +41,7 @@ fn addCaseInner(self: *StackTrace, config: Config, use_llvm: bool) void {
41 self.addExpect(config.name, config.source, .ReleaseSafe, use_llvm, per_mode);41 self.addExpect(config.name, config.source, .ReleaseSafe, use_llvm, per_mode);
42}42}
4343
44fn shouldTestNonLlvm(target: std.Target) bool {44fn shouldTestNonLlvm(target: *const std.Target) bool {
45 return switch (target.cpu.arch) {45 return switch (target.cpu.arch) {
46 .x86_64 => switch (target.ofmt) {46 .x86_64 => switch (target.ofmt) {
47 .elf => true,47 .elf => true,
test/standalone/ios/build.zig+1-1
...@@ -12,7 +12,7 @@ pub fn build(b: *std.Build) void {...@@ -12,7 +12,7 @@ pub fn build(b: *std.Build) void {
12 .cpu_arch = .aarch64,12 .cpu_arch = .aarch64,
13 .os_tag = .ios,13 .os_tag = .ios,
14 });14 });
15 const sdk = std.zig.system.darwin.getSdk(b.allocator, target.result) orelse15 const sdk = std.zig.system.darwin.getSdk(b.allocator, &target.result) orelse
16 @panic("no iOS SDK found");16 @panic("no iOS SDK found");
17 b.sysroot = sdk;17 b.sysroot = sdk;
1818
test/tests.zig+4-4
...@@ -2311,7 +2311,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {...@@ -2311,7 +2311,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
23112311
2312 const resolved_target = b.resolveTargetQuery(test_target.target);2312 const resolved_target = b.resolveTargetQuery(test_target.target);
2313 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");2313 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
2314 const target = resolved_target.result;2314 const target = &resolved_target.result;
23152315
2316 if (options.test_target_filters.len > 0) {2316 if (options.test_target_filters.len > 0) {
2317 for (options.test_target_filters) |filter| {2317 for (options.test_target_filters) |filter| {
...@@ -2557,7 +2557,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {...@@ -2557,7 +2557,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
25572557
2558 const resolved_target = b.resolveTargetQuery(c_abi_target.target);2558 const resolved_target = b.resolveTargetQuery(c_abi_target.target);
2559 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");2559 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
2560 const target = resolved_target.result;2560 const target = &resolved_target.result;
25612561
2562 if (options.test_target_filters.len > 0) {2562 if (options.test_target_filters.len > 0) {
2563 for (options.test_target_filters) |filter| {2563 for (options.test_target_filters) |filter| {
...@@ -2659,7 +2659,7 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step...@@ -2659,7 +2659,7 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step
2659 .options = options,2659 .options = options,
2660 .root_step = step,2660 .root_step = step,
2661 };2661 };
2662 context.addTestsForTarget(.{2662 context.addTestsForTarget(&.{
2663 .resolved = b.resolveTargetQuery(.{2663 .resolved = b.resolveTargetQuery(.{
2664 .cpu_arch = .x86_64,2664 .cpu_arch = .x86_64,
2665 .os_tag = .linux,2665 .os_tag = .linux,
...@@ -2668,7 +2668,7 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step...@@ -2668,7 +2668,7 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step
2668 .pic = false,2668 .pic = false,
2669 .test_name_suffix = "x86_64-linux",2669 .test_name_suffix = "x86_64-linux",
2670 });2670 });
2671 context.addTestsForTarget(.{2671 context.addTestsForTarget(&.{
2672 .resolved = b.resolveTargetQuery(.{2672 .resolved = b.resolveTargetQuery(.{
2673 .cpu_arch = .x86_64,2673 .cpu_arch = .x86_64,
2674 .os_tag = .linux,2674 .os_tag = .linux,
tools/doctest.zig+2-2
...@@ -317,7 +317,7 @@ fn printOutput(...@@ -317,7 +317,7 @@ fn printOutput(
317 const target = try std.zig.system.resolveTargetQuery(317 const target = try std.zig.system.resolveTargetQuery(
318 target_query,318 target_query,
319 );319 );
320 switch (getExternalExecutor(host, &target, .{320 switch (getExternalExecutor(&host, &target, .{
321 .link_libc = code.link_libc,321 .link_libc = code.link_libc,
322 })) {322 })) {
323 .native => {},323 .native => {},
...@@ -538,7 +538,7 @@ fn printOutput(...@@ -538,7 +538,7 @@ fn printOutput(
538 .lib => {538 .lib => {
539 const bin_basename = try std.zig.binNameAlloc(arena, .{539 const bin_basename = try std.zig.binNameAlloc(arena, .{
540 .root_name = code_name,540 .root_name = code_name,
541 .target = builtin.target,541 .target = &builtin.target,
542 .output_mode = .Lib,542 .output_mode = .Lib,
543 });543 });
544544
tools/incr-check.zig+2-2
...@@ -316,7 +316,7 @@ const Eval = struct {...@@ -316,7 +316,7 @@ const Eval = struct {
316316
317 const bin_name = try std.zig.EmitArtifact.bin.cacheName(arena, .{317 const bin_name = try std.zig.EmitArtifact.bin.cacheName(arena, .{
318 .root_name = "root", // corresponds to the module name "root"318 .root_name = "root", // corresponds to the module name "root"
319 .target = eval.target.resolved,319 .target = &eval.target.resolved,
320 .output_mode = .Exe,320 .output_mode = .Exe,
321 });321 });
322 const bin_path = try std.fs.path.join(arena, &.{ result_dir, bin_name });322 const bin_path = try std.fs.path.join(arena, &.{ result_dir, bin_name });
...@@ -444,7 +444,7 @@ const Eval = struct {...@@ -444,7 +444,7 @@ const Eval = struct {
444444
445 var argv_buf: [2][]const u8 = undefined;445 var argv_buf: [2][]const u8 = undefined;
446 const argv: []const []const u8, const is_foreign: bool = switch (std.zig.system.getExternalExecutor(446 const argv: []const []const u8, const is_foreign: bool = switch (std.zig.system.getExternalExecutor(
447 eval.host,447 &eval.host,
448 &eval.target.resolved,448 &eval.target.resolved,
449 .{ .link_libc = eval.target.backend == .cbe },449 .{ .link_libc = eval.target.backend == .cbe },
450 )) {450 )) {