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(
759759 use_zig_libcxx: bool,
760760) !void {
761761 const mod = exe.root_module;
762 const target = mod.resolved_target.?.result;
762 const target = &mod.resolved_target.?.result;
763763
764764 if (target.os.tag.isDarwin()) {
765765 // 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
525525 };
526526 const target = std.zig.resolveTargetQueryOrFatal(target_query);
527527 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 {
529529 if (includes == .any) {
530530 // fall back to mingw
531531 includes = .gnu;
......@@ -550,7 +550,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A
550550 };
551551 const target = std.zig.resolveTargetQueryOrFatal(target_query);
552552 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) {
554554 error.OutOfMemory => |e| return e,
555555 else => return error.MingwIncludesNotFound,
556556 };
lib/compiler_rt/divmodei4.zig+2-2
......@@ -35,7 +35,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void {
3535
3636pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
3737 @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));
3939 const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
4040 const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
4141 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
4444
4545pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
4646 @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));
4848 const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
4949 const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
5050 const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
lib/compiler_rt/fixdfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/fixhfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/fixsfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/fixtfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/fixunsdfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/fixunshfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/fixunssfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/fixunstfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/fixunsxfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/fixxfei.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515}
lib/compiler_rt/floateidf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f64, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515}
lib/compiler_rt/floateihf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f16, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515}
lib/compiler_rt/floateisf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f32, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515}
lib/compiler_rt/floateitf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f128, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515}
lib/compiler_rt/floateixf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f80, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515}
lib/compiler_rt/floatuneidf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f64, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515}
lib/compiler_rt/floatuneihf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f16, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515}
lib/compiler_rt/floatuneisf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f32, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515}
lib/compiler_rt/floatuneitf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f128, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515}
lib/compiler_rt/floatuneixf.zig+1-1
......@@ -10,6 +10,6 @@ comptime {
1010}
1111
1212pub 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));
1414 return floatFromBigInt(f80, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515}
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 {
114114
115115pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
116116 @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));
118118 const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
119119 const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
120120 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
123123
124124pub fn __umodei4(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
125125 @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));
127127 const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
128128 const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
129129 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(
198198 const wasm_base_path = try buildWasmBinary(ws, arena, optimize_mode);
199199 const bin_name = try std.zig.binNameAlloc(arena, .{
200200 .root_name = fuzzer_bin_name,
201 .target = std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{
201 .target = &(std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{
202202 .arch_os_abi = fuzzer_arch_os_abi,
203203 .cpu_features = fuzzer_cpu_features,
204 }) catch unreachable) catch unreachable,
204 }) catch unreachable) catch unreachable),
205205 .output_mode = .Exe,
206206 });
207207 // 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 {
655655 m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM");
656656}
657657
658fn requireKnownTarget(m: *Module) std.Target {
659 const resolved_target = m.resolved_target orelse
660 @panic("this API requires the Module to be created with a known 'target' field");
661 return resolved_target.result;
658fn requireKnownTarget(m: *Module) *const std.Target {
659 const resolved_target = &(m.resolved_target orelse
660 @panic("this API requires the Module to be created with a known 'target' field"));
661 return &resolved_target.result;
662662}
663663
664664/// 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 {
377377
378378 const resolved_target = options.root_module.resolved_target orelse
379379 @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
382382 const step_name = owner.fmt("compile {s} {s} {s}", .{
383383 // 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
18661866 const arena = c.step.owner.graph.arena;
18671867 const name = ea.cacheName(arena, .{
18681868 .root_name = c.name,
1869 .target = c.root_module.resolved_target.?.result,
1869 .target = &c.root_module.resolved_target.?.result,
18701870 .output_mode = switch (c.kind) {
18711871 .lib => .Lib,
18721872 .obj, .test_obj => .Obj,
lib/std/Build/Step/Run.zig+1-1
......@@ -1108,7 +1108,7 @@ fn runCommand(
11081108 const need_cross_libc = exe.is_linking_libc and
11091109 (root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic));
11101110 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, .{
11121112 .qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null,
11131113 .link_libc = exe.is_linking_libc,
11141114 })) {
lib/std/Target.zig+26-26
......@@ -1074,7 +1074,7 @@ pub const ObjectFormat = enum {
10741074 }
10751075};
10761076
1077pub fn toElfMachine(target: Target) std.elf.EM {
1077pub fn toElfMachine(target: *const Target) std.elf.EM {
10781078 return switch (target.cpu.arch) {
10791079 .amdgcn => .AMDGPU,
10801080 .arc => .ARC_COMPACT,
......@@ -1115,7 +1115,7 @@ pub fn toElfMachine(target: Target) std.elf.EM {
11151115 };
11161116}
11171117
1118pub fn toCoffMachine(target: Target) std.coff.MachineType {
1118pub fn toCoffMachine(target: *const Target) std.coff.MachineType {
11191119 return switch (target.cpu.arch) {
11201120 .arm => .ARM,
11211121 .thumb => .ARMNT,
......@@ -1999,7 +1999,7 @@ pub const Cpu = struct {
19991999 }
20002000};
20012001
2002pub fn zigTriple(target: Target, allocator: Allocator) Allocator.Error![]u8 {
2002pub fn zigTriple(target: *const Target, allocator: Allocator) Allocator.Error![]u8 {
20032003 return Query.fromTarget(target).zigTriple(allocator);
20042004}
20052005
......@@ -2007,7 +2007,7 @@ pub fn hurdTupleSimple(allocator: Allocator, arch: Cpu.Arch, abi: Abi) ![]u8 {
20072007 return std.fmt.allocPrint(allocator, "{s}-{s}", .{ @tagName(arch), @tagName(abi) });
20082008}
20092009
2010pub fn hurdTuple(target: Target, allocator: Allocator) ![]u8 {
2010pub fn hurdTuple(target: *const Target, allocator: Allocator) ![]u8 {
20112011 return hurdTupleSimple(allocator, target.cpu.arch, target.abi);
20122012}
20132013
......@@ -2015,63 +2015,63 @@ pub fn linuxTripleSimple(allocator: Allocator, arch: Cpu.Arch, os_tag: Os.Tag, a
20152015 return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ @tagName(arch), @tagName(os_tag), @tagName(abi) });
20162016}
20172017
2018pub fn linuxTriple(target: Target, allocator: Allocator) ![]u8 {
2018pub fn linuxTriple(target: *const Target, allocator: Allocator) ![]u8 {
20192019 return linuxTripleSimple(allocator, target.cpu.arch, target.os.tag, target.abi);
20202020}
20212021
2022pub fn exeFileExt(target: Target) [:0]const u8 {
2022pub fn exeFileExt(target: *const Target) [:0]const u8 {
20232023 return target.os.tag.exeFileExt(target.cpu.arch);
20242024}
20252025
2026pub fn staticLibSuffix(target: Target) [:0]const u8 {
2026pub fn staticLibSuffix(target: *const Target) [:0]const u8 {
20272027 return target.os.tag.staticLibSuffix(target.abi);
20282028}
20292029
2030pub fn dynamicLibSuffix(target: Target) [:0]const u8 {
2030pub fn dynamicLibSuffix(target: *const Target) [:0]const u8 {
20312031 return target.os.tag.dynamicLibSuffix();
20322032}
20332033
2034pub fn libPrefix(target: Target) [:0]const u8 {
2034pub fn libPrefix(target: *const Target) [:0]const u8 {
20352035 return target.os.tag.libPrefix(target.abi);
20362036}
20372037
2038pub inline fn isMinGW(target: Target) bool {
2038pub inline fn isMinGW(target: *const Target) bool {
20392039 return target.os.tag == .windows and target.abi.isGnu();
20402040}
20412041
2042pub inline fn isGnuLibC(target: Target) bool {
2042pub inline fn isGnuLibC(target: *const Target) bool {
20432043 return switch (target.os.tag) {
20442044 .hurd, .linux => target.abi.isGnu(),
20452045 else => false,
20462046 };
20472047}
20482048
2049pub inline fn isMuslLibC(target: Target) bool {
2049pub inline fn isMuslLibC(target: *const Target) bool {
20502050 return target.os.tag == .linux and target.abi.isMusl();
20512051}
20522052
2053pub inline fn isDarwinLibC(target: Target) bool {
2053pub inline fn isDarwinLibC(target: *const Target) bool {
20542054 return switch (target.abi) {
20552055 .none, .macabi, .simulator => target.os.tag.isDarwin(),
20562056 else => false,
20572057 };
20582058}
20592059
2060pub inline fn isFreeBSDLibC(target: Target) bool {
2060pub inline fn isFreeBSDLibC(target: *const Target) bool {
20612061 return switch (target.abi) {
20622062 .none, .eabihf => target.os.tag == .freebsd,
20632063 else => false,
20642064 };
20652065}
20662066
2067pub inline fn isNetBSDLibC(target: Target) bool {
2067pub inline fn isNetBSDLibC(target: *const Target) bool {
20682068 return switch (target.abi) {
20692069 .none, .eabi, .eabihf => target.os.tag == .netbsd,
20702070 else => false,
20712071 };
20722072}
20732073
2074pub inline fn isWasiLibC(target: Target) bool {
2074pub inline fn isWasiLibC(target: *const Target) bool {
20752075 return target.os.tag == .wasi and target.abi.isMusl();
20762076}
20772077
......@@ -2576,7 +2576,7 @@ pub const DynamicLinker = struct {
25762576 }
25772577};
25782578
2579pub fn standardDynamicLinkerPath(target: Target) DynamicLinker {
2579pub fn standardDynamicLinkerPath(target: *const Target) DynamicLinker {
25802580 return DynamicLinker.standard(target.cpu, target.os, target.abi);
25812581}
25822582
......@@ -2645,11 +2645,11 @@ pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {
26452645 };
26462646}
26472647
2648pub fn ptrBitWidth(target: Target) u16 {
2648pub fn ptrBitWidth(target: *const Target) u16 {
26492649 return ptrBitWidth_cpu_abi(target.cpu, target.abi);
26502650}
26512651
2652pub fn stackAlignment(target: Target) u16 {
2652pub fn stackAlignment(target: *const Target) u16 {
26532653 // Overrides for when the stack alignment is not equal to the pointer width.
26542654 switch (target.cpu.arch) {
26552655 .m68k,
......@@ -2697,7 +2697,7 @@ pub fn stackAlignment(target: Target) u16 {
26972697/// Default signedness of `char` for the native C compiler for this target
26982698/// Note that char signedness is implementation-defined and many compilers provide
26992699/// 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 {
27012701 if (target.os.tag.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;
27022702
27032703 return switch (target.cpu.arch) {
......@@ -2740,7 +2740,7 @@ pub const CType = enum {
27402740 longdouble,
27412741};
27422742
2743pub fn cTypeByteSize(t: Target, c_type: CType) u16 {
2743pub fn cTypeByteSize(t: *const Target, c_type: CType) u16 {
27442744 return switch (c_type) {
27452745 .char,
27462746 .short,
......@@ -2766,7 +2766,7 @@ pub fn cTypeByteSize(t: Target, c_type: CType) u16 {
27662766 };
27672767}
27682768
2769pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
2769pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
27702770 switch (target.os.tag) {
27712771 .freestanding, .other => switch (target.cpu.arch) {
27722772 .msp430 => switch (c_type) {
......@@ -3077,7 +3077,7 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
30773077 }
30783078}
30793079
3080pub fn cTypeAlignment(target: Target, c_type: CType) u16 {
3080pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {
30813081 // Overrides for unusual alignments
30823082 switch (target.cpu.arch) {
30833083 .avr => return 1,
......@@ -3172,7 +3172,7 @@ pub fn cTypeAlignment(target: Target, c_type: CType) u16 {
31723172 );
31733173}
31743174
3175pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
3175pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
31763176 // Overrides for unusual alignments
31773177 switch (target.cpu.arch) {
31783178 .arc => switch (c_type) {
......@@ -3265,7 +3265,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
32653265 );
32663266}
32673267
3268pub fn cMaxIntAlignment(target: std.Target) u16 {
3268pub fn cMaxIntAlignment(target: *const Target) u16 {
32693269 return switch (target.cpu.arch) {
32703270 .avr => 1,
32713271
......@@ -3328,7 +3328,7 @@ pub fn cMaxIntAlignment(target: std.Target) u16 {
33283328 };
33293329}
33303330
3331pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {
3331pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention {
33323332 return switch (target.cpu.arch) {
33333333 .x86_64 => switch (target.os.tag) {
33343334 .windows, .uefi => .{ .x86_64_win = .{} },
lib/std/Target/Query.zig+1-1
......@@ -94,7 +94,7 @@ pub const OsVersion = union(enum) {
9494
9595pub const SemanticVersion = std.SemanticVersion;
9696
97pub fn fromTarget(target: Target) Query {
97pub fn fromTarget(target: *const Target) Query {
9898 var result: Query = .{
9999 .cpu_arch = target.cpu.arch,
100100 .cpu_model = .{ .explicit = target.cpu.model },
lib/std/debug/Dwarf/abi.zig+1-1
......@@ -9,7 +9,7 @@ const Arch = std.Target.Cpu.Arch;
99///
1010/// See also `std.debug.SelfInfo.supportsUnwinding` which tells whether the Zig
1111/// 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 {
1313 return switch (target.cpu.arch) {
1414 .amdgcn,
1515 .nvptx,
lib/std/debug/SelfInfo.zig+3-3
......@@ -1795,10 +1795,10 @@ fn spRegNum(reg_context: Dwarf.abi.RegisterContext) u8 {
17951795const ip_reg_num = Dwarf.abi.ipRegNum(native_arch).?;
17961796
17971797/// Tells whether unwinding for the host is implemented.
1798pub const supports_unwinding = supportsUnwinding(builtin.target);
1798pub const supports_unwinding = supportsUnwinding(&builtin.target);
17991799
18001800comptime {
1801 if (supports_unwinding) assert(Dwarf.abi.supportsUnwinding(builtin.target));
1801 if (supports_unwinding) assert(Dwarf.abi.supportsUnwinding(&builtin.target));
18021802}
18031803
18041804/// Tells whether unwinding for this target is *implemented* here in the Zig
......@@ -1806,7 +1806,7 @@ comptime {
18061806///
18071807/// See also `Dwarf.abi.supportsUnwinding` which tells whether Dwarf supports
18081808/// unwinding on that target *in theory*.
1809pub fn supportsUnwinding(target: std.Target) bool {
1809pub fn supportsUnwinding(target: *const std.Target) bool {
18101810 return switch (target.cpu.arch) {
18111811 .x86 => switch (target.os.tag) {
18121812 .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 {
141141
142142pub const BinNameOptions = struct {
143143 root_name: []const u8,
144 target: std.Target,
144 target: *const std.Target,
145145 output_mode: std.builtin.OutputMode,
146146 link_mode: ?std.builtin.LinkMode = null,
147147 version: ?std.SemanticVersion = null,
lib/std/zig/LibCDirs.zig+4-4
......@@ -15,7 +15,7 @@ pub const DarwinSdkLayout = enum {
1515pub fn detect(
1616 arena: Allocator,
1717 zig_lib_dir: []const u8,
18 target: std.Target,
18 target: *const std.Target,
1919 is_native_abi: bool,
2020 link_libc: bool,
2121 libc_installation: ?*const LibCInstallation,
......@@ -88,7 +88,7 @@ pub fn detect(
8888 };
8989}
9090
91fn detectFromInstallation(arena: Allocator, target: std.Target, lci: *const LibCInstallation) !LibCDirs {
91fn detectFromInstallation(arena: Allocator, target: *const std.Target, lci: *const LibCInstallation) !LibCDirs {
9292 var list = try std.ArrayList([]const u8).initCapacity(arena, 5);
9393 var framework_list = std.ArrayList([]const u8).init(arena);
9494
......@@ -146,7 +146,7 @@ fn detectFromInstallation(arena: Allocator, target: std.Target, lci: *const LibC
146146pub fn detectFromBuilding(
147147 arena: Allocator,
148148 zig_lib_dir: []const u8,
149 target: std.Target,
149 target: *const std.Target,
150150) !LibCDirs {
151151 const s = std.fs.path.sep_str;
152152
......@@ -224,7 +224,7 @@ pub fn detectFromBuilding(
224224 };
225225}
226226
227fn libCGenericName(target: std.Target) [:0]const u8 {
227fn libCGenericName(target: *const std.Target) [:0]const u8 {
228228 switch (target.os.tag) {
229229 .windows => return "mingw",
230230 .macos, .ios, .tvos, .watchos, .visionos => return "darwin",
lib/std/zig/LibCInstallation.zig+4-4
......@@ -26,7 +26,7 @@ pub const FindError = error{
2626pub fn parse(
2727 allocator: Allocator,
2828 libc_file: []const u8,
29 target: std.Target,
29 target: *const std.Target,
3030) !LibCInstallation {
3131 var self: LibCInstallation = .{};
3232
......@@ -157,7 +157,7 @@ pub fn render(self: LibCInstallation, out: anytype) !void {
157157
158158pub const FindNativeOptions = struct {
159159 allocator: Allocator,
160 target: std.Target,
160 target: *const std.Target,
161161
162162 /// If enabled, will print human-friendly errors to stderr.
163163 verbose: bool = false,
......@@ -700,7 +700,7 @@ pub const CrtBasenames = struct {
700700 crtn: ?[]const u8 = null,
701701
702702 pub const GetArgs = struct {
703 target: std.Target,
703 target: *const std.Target,
704704 link_libc: bool,
705705 output_mode: std.builtin.OutputMode,
706706 link_mode: std.builtin.LinkMode,
......@@ -965,7 +965,7 @@ pub fn resolveCrtPaths(
965965 lci: LibCInstallation,
966966 arena: Allocator,
967967 crt_basenames: CrtBasenames,
968 target: std.Target,
968 target: *const std.Target,
969969) error{ OutOfMemory, LibCInstallationMissingCrtDir }!CrtPaths {
970970 const crt_dir_path: Path = .{
971971 .root_dir = std.Build.Cache.Directory.cwd(),
lib/std/zig/llvm/Builder.zig+1-1
......@@ -66,7 +66,7 @@ pub const Options = struct {
6666 allocator: Allocator,
6767 strip: bool = true,
6868 name: []const u8 = &.{},
69 target: std.Target = builtin.target,
69 target: *const std.Target = &builtin.target,
7070 triple: []const u8 = &.{},
7171};
7272
lib/std/zig/system.zig+1-1
......@@ -28,7 +28,7 @@ pub const GetExternalExecutorOptions = struct {
2828/// Return whether or not the given host is capable of running executables of
2929/// the other target.
3030pub fn getExternalExecutor(
31 host: std.Target,
31 host: *const std.Target,
3232 candidate: *const std.Target,
3333 options: GetExternalExecutorOptions,
3434) Executor {
lib/std/zig/system/NativePaths.zig+1-1
......@@ -13,7 +13,7 @@ framework_dirs: std.ArrayListUnmanaged([]const u8) = .empty,
1313rpaths: std.ArrayListUnmanaged([]const u8) = .empty,
1414warnings: 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 {
1717 var self: NativePaths = .{ .arena = arena };
1818 var is_nix = false;
1919 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 {
3434/// Caller owns the memory.
3535/// stderr from xcrun is ignored.
3636/// 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 {
3838 const is_simulator_abi = target.abi == .simulator;
3939 const sdk = switch (target.os.tag) {
4040 .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
116116/// The version of Zig's bundled NetBSD libc used when linking libc statically.
117117pub 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 {
120120 for (available_libcs) |libc| {
121121 if (target.cpu.arch == libc.arch and target.os.tag == libc.os and target.abi == libc.abi) {
122122 if (libc.os_ver) |libc_os_ver| {
......@@ -176,7 +176,7 @@ pub fn muslRuntimeTriple(
176176 return std.Target.linuxTripleSimple(allocator, arch, .linux, abi);
177177}
178178
179pub fn osArchName(target: std.Target) [:0]const u8 {
179pub fn osArchName(target: *const std.Target) [:0]const u8 {
180180 return switch (target.os.tag) {
181181 .linux => switch (target.cpu.arch) {
182182 .arm, .armeb, .thumb, .thumbeb => "arm",
......@@ -276,7 +276,7 @@ pub fn netbsdAbiNameHeaders(abi: std.Target.Abi) [:0]const u8 {
276276 };
277277}
278278
279pub fn isLibCLibName(target: std.Target, name: []const u8) bool {
279pub fn isLibCLibName(target: *const std.Target, name: []const u8) bool {
280280 const ignore_case = target.os.tag.isDarwin() or target.os.tag == .windows;
281281
282282 if (eqlIgnoreCase(ignore_case, name, "c"))
......@@ -453,7 +453,7 @@ pub fn isLibCLibName(target: std.Target, name: []const u8) bool {
453453 return false;
454454}
455455
456pub fn isLibCxxLibName(target: std.Target, name: []const u8) bool {
456pub fn isLibCxxLibName(target: *const std.Target, name: []const u8) bool {
457457 const ignore_case = target.os.tag.isDarwin() or target.os.tag == .windows;
458458
459459 return eqlIgnoreCase(ignore_case, name, "c++") or
......@@ -470,11 +470,11 @@ fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool {
470470 }
471471}
472472
473pub fn intByteSize(target: std.Target, bits: u16) u19 {
473pub fn intByteSize(target: *const std.Target, bits: u16) u19 {
474474 return std.mem.alignForward(u19, @intCast((@as(u17, bits) + 7) / 8), intAlignment(target, bits));
475475}
476476
477pub fn intAlignment(target: std.Target, bits: u16) u16 {
477pub fn intAlignment(target: *const std.Target, bits: u16) u16 {
478478 return switch (target.cpu.arch) {
479479 .x86 => switch (bits) {
480480 0 => 0,
src/Compilation.zig+19-21
......@@ -1361,7 +1361,7 @@ pub const cache_helpers = struct {
13611361 hh: *Cache.HashHelper,
13621362 resolved_target: Package.Module.ResolvedTarget,
13631363 ) void {
1364 const target = resolved_target.result;
1364 const target = &resolved_target.result;
13651365 hh.add(target.cpu.arch);
13661366 hh.addBytes(target.cpu.model.name);
13671367 hh.add(target.cpu.features.ints);
......@@ -1705,7 +1705,7 @@ pub const CreateOptions = struct {
17051705 assert(opts.cache_mode != .none);
17061706 return try ea.cacheName(arena, .{
17071707 .root_name = opts.root_name,
1708 .target = opts.root_mod.resolved_target.result,
1708 .target = &opts.root_mod.resolved_target.result,
17091709 .output_mode = opts.config.output_mode,
17101710 .link_mode = opts.config.link_mode,
17111711 .version = opts.version,
......@@ -1772,14 +1772,14 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17721772 }
17731773
17741774 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
17761778 const comp: *Compilation = comp: {
17771779 // We put the `Compilation` itself in the arena. Freeing the arena will free the module.
17781780 // It's initialized later after we prepare the initialization options.
17791781 const root_name = try arena.dupeZ(u8, options.root_name);
17801782
1781 const use_llvm = options.config.use_llvm;
1782
17831783 // The "any" values provided by resolved config only account for
17841784 // explicitly-provided settings. We now make them additionally account
17851785 // for default setting resolution.
......@@ -1804,7 +1804,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18041804 const libc_dirs = try std.zig.LibCDirs.detect(
18051805 arena,
18061806 options.dirs.zig_lib.path.?,
1807 options.root_mod.resolved_target.result,
1807 target,
18081808 options.root_mod.resolved_target.is_native_abi,
18091809 link_libc,
18101810 options.libc_installation,
......@@ -1846,7 +1846,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18461846 // approach, since the ubsan runtime uses quite a lot of the standard library
18471847 // and this reduces unnecessary bloat.
18481848 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);
18501850 const want_ubsan_rt = options.want_ubsan_rt orelse (can_build_ubsan_rt and any_sanitize_c == .full and is_exe_or_dyn_lib);
18511851 if (!want_ubsan_rt) break :s .none;
18521852 if (options.skip_linker_dependencies) break :s .none;
......@@ -1872,7 +1872,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18721872
18731873 if (options.verbose_llvm_cpu_features) {
18741874 if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {
1875 const target = options.root_mod.resolved_target.result;
18761875 std.debug.lockStdErr();
18771876 defer std.debug.unlockStdErr();
18781877 const stderr = std.io.getStdErr().writer();
......@@ -2244,8 +2243,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
22442243 };
22452244 errdefer comp.destroy();
22462245
2247 const target = comp.root_mod.resolved_target.result;
2248 const can_build_compiler_rt = target_util.canBuildLibCompilerRt(target, comp.config.use_llvm, build_options.have_llvm);
2246 const can_build_compiler_rt = target_util.canBuildLibCompilerRt(target, use_llvm, build_options.have_llvm);
22492247
22502248 // Add a `CObject` for each `c_source_files`.
22512249 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
23442342 comp.link_task_queue.pending_prelink_tasks += 1;
23452343 }
23462344 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
23492347 comp.queued_jobs.glibc_crt_file[@intFromEnum(glibc.CrtFile.libc_nonshared_a)] = true;
23502348 comp.link_task_queue.pending_prelink_tasks += 1;
......@@ -2571,8 +2569,8 @@ pub fn clearMiscFailures(comp: *Compilation) void {
25712569 comp.misc_failures = .{};
25722570}
25732571
2574pub fn getTarget(self: Compilation) Target {
2575 return self.root_mod.resolved_target.result;
2572pub fn getTarget(self: *const Compilation) *const Target {
2573 return &self.root_mod.resolved_target.result;
25762574}
25772575
25782576/// Only legal to call when cache mode is incremental and a link file is present.
......@@ -3210,7 +3208,7 @@ fn addNonIncrementalStuffToCacheManifest(
32103208 man.hash.addOptional(opts.image_base);
32113209 man.hash.addOptional(opts.gc_sections);
32123210 man.hash.add(opts.emit_relocs);
3213 const target = comp.root_mod.resolved_target.result;
3211 const target = &comp.root_mod.resolved_target.result;
32143212 if (target.ofmt == .macho or target.ofmt == .coff) {
32153213 // TODO remove this, libraries need to be resolved by the frontend. this is already
32163214 // done by ELF.
......@@ -6270,7 +6268,7 @@ pub fn addCCArgs(
62706268 out_dep_path: ?[]const u8,
62716269 mod: *Package.Module,
62726270) !void {
6273 const target = mod.resolved_target.result;
6271 const target = &mod.resolved_target.result;
62746272
62756273 // As of Clang 16.x, it will by default read extra flags from /etc/clang.
62766274 // I'm sure the person who implemented this means well, but they have a lot
......@@ -6944,7 +6942,7 @@ pub const FileExt = enum {
69446942 };
69456943 }
69466944
6947 pub fn canonicalName(ext: FileExt, target: Target) [:0]const u8 {
6945 pub fn canonicalName(ext: FileExt, target: *const Target) [:0]const u8 {
69486946 return switch (ext) {
69496947 .c => ".c",
69506948 .cpp => ".cpp",
......@@ -7187,7 +7185,7 @@ pub fn dump_argv(argv: []const []const u8) void {
71877185}
71887186
71897187pub 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;
71917189 return target_util.zigBackend(target, comp.config.use_llvm);
71927190}
71937191
......@@ -7371,7 +7369,7 @@ pub fn build_crt_file(
73717369
73727370 const basename = try std.zig.binNameAlloc(gpa, .{
73737371 .root_name = root_name,
7374 .target = comp.root_mod.resolved_target.result,
7372 .target = &comp.root_mod.resolved_target.result,
73757373 .output_mode = output_mode,
73767374 });
73777375
......@@ -7523,13 +7521,13 @@ pub fn getCrtPaths(
75237521 comp: *Compilation,
75247522 arena: Allocator,
75257523) error{ OutOfMemory, LibCInstallationMissingCrtDir }!LibCInstallation.CrtPaths {
7526 const target = comp.root_mod.resolved_target.result;
7524 const target = &comp.root_mod.resolved_target.result;
75277525 return getCrtPathsInner(arena, target, comp.config, comp.libc_installation, &comp.crt_files);
75287526}
75297527
75307528fn getCrtPathsInner(
75317529 arena: Allocator,
7532 target: std.Target,
7530 target: *const std.Target,
75337531 config: Config,
75347532 libc_installation: ?*const LibCInstallation,
75357533 crt_files: *std.StringHashMapUnmanaged(CrtFile),
......@@ -7558,7 +7556,7 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {
75587556 // then when we create a sub-Compilation for zig libc, it also tries to
75597557 // build kernel32.lib.
75607558 if (comp.skip_linker_dependencies) return;
7561 const target = comp.root_mod.resolved_target.result;
7559 const target = &comp.root_mod.resolved_target.result;
75627560 if (target.os.tag != .windows or target.ofmt == .c) return;
75637561
75647562 // This happens when an `extern "foo"` function is referenced.
......@@ -7574,7 +7572,7 @@ pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode {
75747572 if (comp.debug_compiler_runtime_libs) {
75757573 return comp.root_mod.optimize_mode;
75767574 }
7577 const target = comp.root_mod.resolved_target.result;
7575 const target = &comp.root_mod.resolved_target.result;
75787576 switch (comp.root_mod.optimize_mode) {
75797577 .Debug, .ReleaseSafe => return target_util.defaultCompilerRtOptimizeMode(target),
75807578 .ReleaseFast => return .ReleaseFast,
src/Compilation/Config.zig+1-1
......@@ -150,7 +150,7 @@ pub const ResolveError = error{
150150};
151151
152152pub fn resolve(options: Options) ResolveError!Config {
153 const target = options.resolved_target.result;
153 const target = &options.resolved_target.result;
154154
155155 // WASI-only. Resolve the optional exec-model option, defaults to command.
156156 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 {
102102 if (options.inherited.error_tracing == true) assert(options.global.any_error_tracing);
103103
104104 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
107107 const optimize_mode = options.inherited.optimize_mode orelse
108108 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 {
363363 .root_src_path = options.paths.root_src_path,
364364 .fully_qualified_name = options.fully_qualified_name,
365365 .resolved_target = .{
366 .result = target,
366 .result = target.*,
367367 .is_native_os = resolved_target.is_native_os,
368368 .is_native_abi = resolved_target.is_native_abi,
369369 .is_explicit_dynamic_linker = resolved_target.is_explicit_dynamic_linker,
......@@ -474,7 +474,7 @@ pub fn getBuiltinOptions(m: Module, global: Compilation.Config) Builtin {
474474 assert(global.have_zcu);
475475 return .{
476476 .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),
478478 .output_mode = global.output_mode,
479479 .link_mode = global.link_mode,
480480 .unwind_tables = m.unwind_tables,
src/Sema.zig+4-4
......@@ -29912,7 +29912,7 @@ pub fn coerceInMemoryAllowed(
2991229912 /// load from the `*Src` to effectively perform an in-memory coercion from `Dest` to `Src`.
2991329913 /// Therefore, when `dest_is_mut`, the in-memory coercion must be valid in *both directions*.
2991429914 dest_is_mut: bool,
29915 target: std.Target,
29915 target: *const std.Target,
2991629916 dest_src: LazySrcLoc,
2991729917 src_src: LazySrcLoc,
2991829918 src_val: ?Value,
......@@ -30271,7 +30271,7 @@ fn coerceInMemoryAllowedFns(
3027130271 src_ty: Type,
3027230272 /// If set, the coercion must be valid in both directions.
3027330273 dest_is_mut: bool,
30274 target: std.Target,
30274 target: *const std.Target,
3027530275 dest_src: LazySrcLoc,
3027630276 src_src: LazySrcLoc,
3027730277) !InMemoryCoercionResult {
......@@ -30380,7 +30380,7 @@ fn coerceInMemoryAllowedFns(
3038030380}
3038130381
3038230382fn callconvCoerceAllowed(
30383 target: std.Target,
30383 target: *const std.Target,
3038430384 src_cc: std.builtin.CallingConvention,
3038530385 dest_cc: std.builtin.CallingConvention,
3038630386) bool {
......@@ -30426,7 +30426,7 @@ fn coerceInMemoryAllowedPtrs(
3042630426 src_ptr_ty: Type,
3042730427 /// If set, the coercion must be valid in both directions.
3042830428 dest_is_mut: bool,
30429 target: std.Target,
30429 target: *const std.Target,
3043030430 dest_src: LazySrcLoc,
3043130431 src_src: LazySrcLoc,
3043230432) !InMemoryCoercionResult {
src/Type.zig+3-3
......@@ -1602,7 +1602,7 @@ fn abiSizeInnerOptional(
16021602 };
16031603}
16041604
1605pub fn ptrAbiAlignment(target: Target) Alignment {
1605pub fn ptrAbiAlignment(target: *const Target) Alignment {
16061606 return Alignment.fromNonzeroByteUnits(@divExact(target.ptrBitWidth(), 8));
16071607}
16081608
......@@ -2395,7 +2395,7 @@ pub fn isAnyFloat(ty: Type) bool {
23952395
23962396/// Asserts the type is a fixed-size float or comptime_float.
23972397/// Returns 128 for comptime_float types.
2398pub fn floatBits(ty: Type, target: Target) u16 {
2398pub fn floatBits(ty: Type, target: *const Target) u16 {
23992399 return switch (ty.toIntern()) {
24002400 .f16_type => 16,
24012401 .f32_type => 32,
......@@ -4188,6 +4188,6 @@ pub fn smallestUnsignedBits(max: u64) u16 {
41884188/// to packed struct layout to find out all the places in the codebase you need to edit!
41894189pub 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 {
41924192 return Alignment.fromByteUnits(target.cTypeAlignment(c_type));
41934193}
src/Zcu.zig+3-3
......@@ -3773,8 +3773,8 @@ pub fn errNote(
37733773/// Deprecated. There is no global target for a Zig Compilation Unit. Instead,
37743774/// look up the target based on the Module that contains the source code being
37753775/// analyzed.
3776pub fn getTarget(zcu: *const Zcu) Target {
3777 return zcu.root_mod.resolved_target.result;
3776pub fn getTarget(zcu: *const Zcu) *const Target {
3777 return &zcu.root_mod.resolved_target.result;
37783778}
37793779
37803780/// Deprecated. There is no global optimization mode for a Zig Compilation
......@@ -3863,7 +3863,7 @@ pub const Feature = enum {
38633863};
38643864
38653865pub 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);
38673867 return target_util.backendSupportsFeature(backend, feature);
38683868}
38693869
src/Zcu/PerThread.zig+1-1
......@@ -4382,7 +4382,7 @@ pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air, ou
43824382 error.CodegenFail => zcu.assertCodegenFailed(zcu.funcInfo(func_index).owner_nav),
43834383 error.NoLinkFile => assert(zcu.comp.bin_file == null),
43844384 error.BackendDoesNotProduceMir => switch (target_util.zigBackend(
4385 zcu.root_mod.resolved_target.result,
4385 &zcu.root_mod.resolved_target.result,
43864386 zcu.comp.config.use_llvm,
43874387 )) {
43884388 else => unreachable, // assertion failure
src/arch/aarch64/CodeGen.zig+2-2
......@@ -6175,7 +6175,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
61756175 self.pt,
61766176 self.src_loc,
61776177 val,
6178 self.target.*,
6178 self.target,
61796179 )) {
61806180 .mcv => |mcv| switch (mcv) {
61816181 .none => .none,
......@@ -6379,7 +6379,7 @@ fn registerAlias(self: *Self, reg: Register, ty: Type) Register {
63796379 },
63806380 .stack_pointer => unreachable, // we can't store/load the sp
63816381 .floating_point => {
6382 return switch (ty.floatBits(self.target.*)) {
6382 return switch (ty.floatBits(self.target)) {
63836383 16 => reg.toH(),
63846384 32 => reg.toS(),
63856385 64 => reg.toD(),
src/arch/arm/CodeGen.zig+1-1
......@@ -6148,7 +6148,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
61486148 pt,
61496149 self.src_loc,
61506150 val,
6151 self.target.*,
6151 self.target,
61526152 )) {
61536153 .mcv => |mcv| switch (mcv) {
61546154 .none => .none,
src/arch/riscv64/CodeGen.zig+5-5
......@@ -1881,7 +1881,7 @@ fn memSize(func: *Func, ty: Type) Memory.Size {
18811881 const pt = func.pt;
18821882 const zcu = pt.zcu;
18831883 return switch (ty.zigTypeTag(zcu)) {
1884 .float => Memory.Size.fromBitSize(ty.floatBits(func.target.*)),
1884 .float => Memory.Size.fromBitSize(ty.floatBits(func.target)),
18851885 else => Memory.Size.fromByteSize(ty.abiSize(zcu)),
18861886 };
18871887}
......@@ -2401,7 +2401,7 @@ fn binOp(
24012401 const rhs_ty = func.typeOf(rhs_air);
24022402
24032403 if (lhs_ty.isRuntimeFloat()) libcall: {
2404 const float_bits = lhs_ty.floatBits(func.target.*);
2404 const float_bits = lhs_ty.floatBits(func.target);
24052405 const type_needs_libcall = switch (float_bits) {
24062406 16 => true,
24072407 32, 64 => false,
......@@ -5189,7 +5189,7 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
51895189 }
51905190 },
51915191 .float => {
5192 const float_bits = lhs_ty.floatBits(func.target.*);
5192 const float_bits = lhs_ty.floatBits(func.target);
51935193 const float_reg_size: u32 = if (func.hasFeature(.d)) 64 else 32;
51945194 if (float_bits > float_reg_size) {
51955195 return func.fail("TODO: airCmp float > 64/32 bits", .{});
......@@ -8195,7 +8195,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {
81958195 const result = if (val.isUndef(pt.zcu))
81968196 try lf.lowerUav(pt, val.toIntern(), .none, src_loc)
81978197 else
8198 try codegen.genTypedValue(lf, pt, src_loc, val, func.target.*);
8198 try codegen.genTypedValue(lf, pt, src_loc, val, func.target);
81998199 const mcv: MCValue = switch (result) {
82008200 .mcv => |mcv| switch (mcv) {
82018201 .none => .none,
......@@ -8484,7 +8484,7 @@ fn promoteInt(func: *Func, ty: Type) Type {
84848484
84858485fn promoteVarArg(func: *Func, ty: Type) Type {
84868486 if (!ty.isRuntimeFloat()) return func.promoteInt(ty);
8487 switch (ty.floatBits(func.target.*)) {
8487 switch (ty.floatBits(func.target)) {
84888488 32, 64 => return Type.f64,
84898489 else => |float_bits| {
84908490 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 {
40884088 pt,
40894089 self.src_loc,
40904090 val,
4091 self.target.*,
4091 self.target,
40924092 )) {
40934093 .mcv => |mcv| switch (mcv) {
40944094 .none => .none,
src/arch/wasm/CodeGen.zig+15-15
......@@ -982,7 +982,7 @@ fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
982982pub fn typeToValtype(ty: Type, zcu: *const Zcu, target: *const std.Target) std.wasm.Valtype {
983983 const ip = &zcu.intern_pool;
984984 return switch (ty.zigTypeTag(zcu)) {
985 .float => switch (ty.floatBits(target.*)) {
985 .float => switch (ty.floatBits(target)) {
986986 16 => .i32, // stored/loaded as u16
987987 32 => .f32,
988988 64 => .f64,
......@@ -1715,7 +1715,7 @@ fn isByRef(ty: Type, zcu: *const Zcu, target: *const std.Target) bool {
17151715 .vector => return determineSimdStoreStrategy(ty, zcu, target) == .unrolled,
17161716 .int => return ty.intInfo(zcu).bits > 64,
17171717 .@"enum" => return ty.intInfo(zcu).bits > 64,
1718 .float => return ty.floatBits(target.*) > 64,
1718 .float => return ty.floatBits(target) > 64,
17191719 .error_union => {
17201720 const pl_ty = ty.errorUnionPayload(zcu);
17211721 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
......@@ -2904,7 +2904,7 @@ fn floatOp(cg: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) Inne
29042904 return cg.fail("TODO: Implement floatOps for vectors", .{});
29052905 }
29062906
2907 const float_bits = ty.floatBits(cg.target.*);
2907 const float_bits = ty.floatBits(cg.target);
29082908
29092909 if (float_op == .neg) {
29102910 return cg.floatNeg(ty, args[0]);
......@@ -2931,7 +2931,7 @@ fn floatOp(cg: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) Inne
29312931
29322932/// NOTE: The result value remains on top of the stack.
29332933fn 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);
29352935 switch (float_bits) {
29362936 16 => {
29372937 try cg.emitWValue(arg);
......@@ -3300,7 +3300,7 @@ fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue {
33003300 33...64 => return .{ .imm64 = 0xaaaaaaaaaaaaaaaa },
33013301 else => unreachable,
33023302 },
3303 .float => switch (ty.floatBits(cg.target.*)) {
3303 .float => switch (ty.floatBits(cg.target)) {
33043304 16 => return .{ .imm32 = 0xaaaaaaaa },
33053305 32 => return .{ .float32 = @as(f32, @bitCast(@as(u32, 0xaaaaaaaa))) },
33063306 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
35073507/// Compares two floats.
35083508/// NOTE: Leaves the result of the comparison on top of the stack.
35093509fn 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
35123512 const op: Op = switch (cmp_op) {
35133513 .lt => .lt,
......@@ -4919,7 +4919,7 @@ fn airIntFromFloat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49194919
49204920 const operand = try cg.resolveInst(ty_op.operand);
49214921 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
49244924 const dest_ty = cg.typeOfIndex(inst);
49254925 const dest_info = dest_ty.intInfo(zcu);
......@@ -4973,7 +4973,7 @@ fn airFloatFromInt(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49734973 const op_info = op_ty.intInfo(zcu);
49744974
49754975 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
49784978 if (op_info.bits > 128) {
49794979 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 {
55675567/// Extends a float from a given `Type` to a larger wanted `Type`, leaving the
55685568/// result on the stack.
55695569fn fpext(cg: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {
5570 const given_bits = given.floatBits(cg.target.*);
5571 const wanted_bits = wanted.floatBits(cg.target.*);
5570 const given_bits = given.floatBits(cg.target);
5571 const wanted_bits = wanted.floatBits(cg.target);
55725572
55735573 const intrinsic: Mir.Intrinsic = switch (given_bits) {
55745574 16 => switch (wanted_bits) {
......@@ -5621,8 +5621,8 @@ fn airFptrunc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56215621/// Truncates a float from a given `Type` to its wanted `Type`, leaving the
56225622/// result on the stack.
56235623fn fptrunc(cg: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {
5624 const given_bits = given.floatBits(cg.target.*);
5625 const wanted_bits = wanted.floatBits(cg.target.*);
5624 const given_bits = given.floatBits(cg.target);
5625 const wanted_bits = wanted.floatBits(cg.target);
56265626
56275627 const intrinsic: Mir.Intrinsic = switch (given_bits) {
56285628 32 => switch (wanted_bits) {
......@@ -6231,7 +6231,7 @@ fn airMaxMin(
62316231
62326232 if (ty.zigTypeTag(zcu) == .float) {
62336233 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)) {
62356235 inline 16, 32, 64, 80, 128 => |bits| @field(
62366236 Mir.Intrinsic,
62376237 libcFloatPrefix(bits) ++ @tagName(ct_op) ++ libcFloatSuffix(bits),
......@@ -6268,7 +6268,7 @@ fn airMulAdd(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
62686268 const lhs = try cg.resolveInst(bin_op.lhs);
62696269 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: {
62726272 const rhs_ext = try cg.fpext(rhs, ty, Type.f32);
62736273 const lhs_ext = try cg.fpext(lhs, ty, Type.f32);
62746274 const addend_ext = try cg.fpext(addend, ty, Type.f32);
......@@ -6667,7 +6667,7 @@ fn airDivFloor(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66676667 _ = try cg.wrapOperand(.stack, ty);
66686668 }
66696669 } else {
6670 const float_bits = ty.floatBits(cg.target.*);
6670 const float_bits = ty.floatBits(cg.target);
66716671 if (float_bits > 64) {
66726672 return cg.fail("TODO: `@divFloor` for floats with bitsize: {d}", .{float_bits});
66736673 }
src/arch/x86_64/CodeGen.zig+51-51
......@@ -163704,7 +163704,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok
163704163704
163705163705 if (reg_ok) need_mem: {
163706163706 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)) {
163708163708 16, 32, 64, 128 => 16,
163709163709 80 => break :need_mem,
163710163710 else => unreachable,
......@@ -163993,9 +163993,9 @@ fn airRetPtr(self: *CodeGen, inst: Air.Inst.Index) !void {
163993163993fn airFptrunc(self: *CodeGen, inst: Air.Inst.Index) !void {
163994163994 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
163995163995 const dst_ty = self.typeOfIndex(inst);
163996 const dst_bits = dst_ty.floatBits(self.target.*);
163996 const dst_bits = dst_ty.floatBits(self.target);
163997163997 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
164000164000 const result = result: {
164001164001 if (switch (dst_bits) {
......@@ -164095,10 +164095,10 @@ fn airFpext(self: *CodeGen, inst: Air.Inst.Index) !void {
164095164095 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
164096164096 const dst_ty = self.typeOfIndex(inst);
164097164097 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);
164099164099 const src_ty = self.typeOf(ty_op.operand);
164100164100 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
164103164103 const result = result: {
164104164104 if (switch (src_bits) {
......@@ -168207,7 +168207,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
168207168207 const zcu = pt.zcu;
168208168208
168209168209 const result = result: {
168210 const scalar_bits = ty.scalarType(zcu).floatBits(self.target.*);
168210 const scalar_bits = ty.scalarType(zcu).floatBits(self.target);
168211168211 if (scalar_bits == 80) {
168212168212 if (ty.zigTypeTag(zcu) != .float) return self.fail("TODO implement floatSign for {}", .{
168213168213 ty.fmt(pt),
......@@ -168363,14 +168363,14 @@ fn getRoundTag(self: *CodeGen, ty: Type) ?Mir.Inst.FixedTag {
168363168363 const pt = self.pt;
168364168364 const zcu = pt.zcu;
168365168365 return if (self.hasFeature(.sse4_1)) switch (ty.zigTypeTag(zcu)) {
168366 .float => switch (ty.floatBits(self.target.*)) {
168366 .float => switch (ty.floatBits(self.target)) {
168367168367 32 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
168368168368 64 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },
168369168369 16, 80, 128 => null,
168370168370 else => unreachable,
168371168371 },
168372168372 .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)) {
168374168374 32 => switch (ty.vectorLen(zcu)) {
168375168375 1 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
168376168376 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 {
168670168670 const result: MCValue = result: {
168671168671 switch (ty.zigTypeTag(zcu)) {
168672168672 .float => {
168673 const float_bits = ty.floatBits(self.target.*);
168673 const float_bits = ty.floatBits(self.target);
168674168674 if (switch (float_bits) {
168675168675 16 => !self.hasFeature(.f16c),
168676168676 32, 64 => false,
......@@ -168701,7 +168701,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {
168701168701 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
168702168702
168703168703 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)) {
168705168705 16 => {
168706168706 assert(self.hasFeature(.f16c));
168707168707 const mat_src_reg = if (src_mcv.isRegister())
......@@ -168723,7 +168723,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {
168723168723 else => unreachable,
168724168724 },
168725168725 .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)) {
168727168727 16 => if (self.hasFeature(.f16c)) switch (ty.vectorLen(zcu)) {
168728168728 1 => {
168729168729 try self.asmRegisterRegister(
......@@ -170904,7 +170904,7 @@ fn genBinOp(
170904170904 const abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));
170905170905
170906170906 if (lhs_ty.isRuntimeFloat()) libcall: {
170907 const float_bits = lhs_ty.floatBits(self.target.*);
170907 const float_bits = lhs_ty.floatBits(self.target);
170908170908 const type_needs_libcall = switch (float_bits) {
170909170909 16 => !self.hasFeature(.f16c),
170910170910 32, 64 => false,
......@@ -171083,7 +171083,7 @@ fn genBinOp(
171083171083 },
171084171084 };
171085171085 if (sse_op and ((lhs_ty.scalarType(zcu).isRuntimeFloat() and
171086 lhs_ty.scalarType(zcu).floatBits(self.target.*) == 80) or
171086 lhs_ty.scalarType(zcu).floatBits(self.target) == 80) or
171087171087 lhs_ty.abiSize(zcu) > self.vectorSize(.float)))
171088171088 return self.fail("TODO implement genBinOp for {s} {}", .{ @tagName(air_tag), lhs_ty.fmt(pt) });
171089171089
......@@ -171474,7 +171474,7 @@ fn genBinOp(
171474171474 const dst_reg = registerAlias(dst_mcv.getReg().?, abi_size);
171475171475 const mir_tag = @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
171476171476 else => unreachable,
171477 .float => switch (lhs_ty.floatBits(self.target.*)) {
171477 .float => switch (lhs_ty.floatBits(self.target)) {
171478171478 16 => {
171479171479 assert(self.hasFeature(.f16c));
171480171480 const lhs_reg = if (copied_to_dst) dst_reg else registerAlias(lhs_mcv.getReg().?, abi_size);
......@@ -171917,7 +171917,7 @@ fn genBinOp(
171917171917 },
171918171918 else => null,
171919171919 },
171920 .float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
171920 .float => switch (lhs_ty.childType(zcu).floatBits(self.target)) {
171921171921 16 => tag: {
171922171922 assert(self.hasFeature(.f16c));
171923171923 const lhs_reg = if (copied_to_dst) dst_reg else registerAlias(lhs_mcv.getReg().?, abi_size);
......@@ -172336,14 +172336,14 @@ fn genBinOp(
172336172336
172337172337 try self.asmRegisterRegisterRegisterImmediate(
172338172338 @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)) {
172340172340 32 => .{ .v_ss, .cmp },
172341172341 64 => .{ .v_sd, .cmp },
172342172342 16, 80, 128 => null,
172343172343 else => unreachable,
172344172344 },
172345172345 .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)) {
172347172347 32 => switch (lhs_ty.vectorLen(zcu)) {
172348172348 1 => .{ .v_ss, .cmp },
172349172349 2...8 => .{ .v_ps, .cmp },
......@@ -172370,14 +172370,14 @@ fn genBinOp(
172370172370 );
172371172371 try self.asmRegisterRegisterRegisterRegister(
172372172372 @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)) {
172374172374 32 => .{ .v_ps, .blendv },
172375172375 64 => .{ .v_pd, .blendv },
172376172376 16, 80, 128 => null,
172377172377 else => unreachable,
172378172378 },
172379172379 .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)) {
172381172381 32 => switch (lhs_ty.vectorLen(zcu)) {
172382172382 1...8 => .{ .v_ps, .blendv },
172383172383 else => null,
......@@ -172404,14 +172404,14 @@ fn genBinOp(
172404172404 const has_blend = self.hasFeature(.sse4_1);
172405172405 try self.asmRegisterRegisterImmediate(
172406172406 @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)) {
172408172408 32 => .{ ._ss, .cmp },
172409172409 64 => .{ ._sd, .cmp },
172410172410 16, 80, 128 => null,
172411172411 else => unreachable,
172412172412 },
172413172413 .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)) {
172415172415 32 => switch (lhs_ty.vectorLen(zcu)) {
172416172416 1 => .{ ._ss, .cmp },
172417172417 2...4 => .{ ._ps, .cmp },
......@@ -172437,14 +172437,14 @@ fn genBinOp(
172437172437 );
172438172438 if (has_blend) try self.asmRegisterRegisterRegister(
172439172439 @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)) {
172441172441 32 => .{ ._ps, .blendv },
172442172442 64 => .{ ._pd, .blendv },
172443172443 16, 80, 128 => null,
172444172444 else => unreachable,
172445172445 },
172446172446 .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)) {
172448172448 32 => switch (lhs_ty.vectorLen(zcu)) {
172449172449 1...4 => .{ ._ps, .blendv },
172450172450 else => null,
......@@ -172467,14 +172467,14 @@ fn genBinOp(
172467172467 mask_reg,
172468172468 ) else {
172469172469 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)) {
172471172471 32 => ._ps,
172472172472 64 => ._pd,
172473172473 16, 80, 128 => null,
172474172474 else => unreachable,
172475172475 },
172476172476 .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)) {
172478172478 32 => switch (lhs_ty.vectorLen(zcu)) {
172479172479 1...4 => ._ps,
172480172480 else => null,
......@@ -173832,7 +173832,7 @@ fn airCmp(self: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !v
173832173832
173833173833 switch (ty.zigTypeTag(zcu)) {
173834173834 .float => {
173835 const float_bits = ty.floatBits(self.target.*);
173835 const float_bits = ty.floatBits(self.target);
173836173836 if (!switch (float_bits) {
173837173837 16 => self.hasFeature(.f16c),
173838173838 32 => self.hasFeature(.sse),
......@@ -174188,7 +174188,7 @@ fn airCmp(self: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !v
174188174188 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
174189174189 const src_mcv = if (flipped) lhs_mcv else rhs_mcv;
174190174190
174191 switch (ty.floatBits(self.target.*)) {
174191 switch (ty.floatBits(self.target)) {
174192174192 16 => {
174193174193 assert(self.hasFeature(.f16c));
174194174194 const tmp1_reg =
......@@ -176335,7 +176335,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M
176335176335 else => {},
176336176336 }
176337176337 },
176338 .float => switch (ty.floatBits(cg.target.*)) {
176338 .float => switch (ty.floatBits(cg.target)) {
176339176339 16 => return if (cg.hasFeature(.avx)) .{ .vex_insert_extract = .{
176340176340 .insert = .{ .vp_w, .insr },
176341176341 .extract = .{ .vp_w, .extr },
......@@ -176482,7 +176482,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M
176482176482 }
176483176483 else
176484176484 unreachable,
176485 .float => switch (ty.childType(zcu).floatBits(cg.target.*)) {
176485 .float => switch (ty.childType(zcu).floatBits(cg.target)) {
176486176486 16 => switch (ty.vectorLen(zcu)) {
176487176487 1...8 => return .{ .load_store = if (cg.hasFeature(.avx))
176488176488 .{ if (aligned) .v_dqa else .v_dqu, .mov }
......@@ -177017,7 +177017,7 @@ fn genSetReg(
177017177017 17...32 => if (self.hasFeature(.avx)) .{ .v_dqa, .mov } else null,
177018177018 else => null,
177019177019 },
177020 .float => switch (ty.scalarType(zcu).floatBits(self.target.*)) {
177020 .float => switch (ty.scalarType(zcu).floatBits(self.target)) {
177021177021 16, 128 => switch (abi_size) {
177022177022 2...16 => if (self.hasFeature(.avx))
177023177023 .{ .v_dqa, .mov }
......@@ -177776,7 +177776,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {
177776177776 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
177777177777
177778177778 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
177781177781 const src_ty = self.typeOf(ty_op.operand);
177782177782 const src_bits: u32 = @intCast(src_ty.bitSize(zcu));
......@@ -177828,7 +177828,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {
177828177828 defer self.register_manager.unlockReg(dst_lock);
177829177829
177830177830 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)) {
177832177832 32 => if (self.hasFeature(.avx)) .{ .v_ss, .cvtsi2 } else .{ ._ss, .cvtsi2 },
177833177833 64 => if (self.hasFeature(.avx)) .{ .v_sd, .cvtsi2 } else .{ ._sd, .cvtsi2 },
177834177834 16, 80, 128 => null,
......@@ -177865,7 +177865,7 @@ fn airIntFromFloat(self: *CodeGen, inst: Air.Inst.Index) !void {
177865177865 }, 32), 8) catch unreachable;
177866177866
177867177867 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
177870177870 const result = result: {
177871177871 if (switch (src_bits) {
......@@ -178136,22 +178136,22 @@ fn atomicOp(
178136178136 }
178137178137 if (rmw_op) |op| if (use_sse) {
178138178138 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)) {
178140178140 32 => if (self.hasFeature(.avx)) .{ .v_ss, .add } else .{ ._ss, .add },
178141178141 64 => if (self.hasFeature(.avx)) .{ .v_sd, .add } else .{ ._sd, .add },
178142178142 else => null,
178143178143 },
178144 .Sub => switch (val_ty.floatBits(self.target.*)) {
178144 .Sub => switch (val_ty.floatBits(self.target)) {
178145178145 32 => if (self.hasFeature(.avx)) .{ .v_ss, .sub } else .{ ._ss, .sub },
178146178146 64 => if (self.hasFeature(.avx)) .{ .v_sd, .sub } else .{ ._sd, .sub },
178147178147 else => null,
178148178148 },
178149 .Min => switch (val_ty.floatBits(self.target.*)) {
178149 .Min => switch (val_ty.floatBits(self.target)) {
178150178150 32 => if (self.hasFeature(.avx)) .{ .v_ss, .min } else .{ ._ss, .min },
178151178151 64 => if (self.hasFeature(.avx)) .{ .v_sd, .min } else .{ ._sd, .min },
178152178152 else => null,
178153178153 },
178154 .Max => switch (val_ty.floatBits(self.target.*)) {
178154 .Max => switch (val_ty.floatBits(self.target)) {
178155178155 32 => if (self.hasFeature(.avx)) .{ .v_ss, .max } else .{ ._ss, .max },
178156178156 64 => if (self.hasFeature(.avx)) .{ .v_sd, .max } else .{ ._sd, .max },
178157178157 else => null,
......@@ -178988,7 +178988,7 @@ fn airSplat(self: *CodeGen, inst: Air.Inst.Index) !void {
178988178988 );
178989178989 break :result .{ .register = dst_reg };
178990178990 },
178991 .float => switch (scalar_ty.floatBits(self.target.*)) {
178991 .float => switch (scalar_ty.floatBits(self.target)) {
178992178992 32 => switch (vector_len) {
178993178993 1 => {
178994178994 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -179581,7 +179581,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
179581179581 null,
179582179582 else => null,
179583179583 },
179584 .float => switch (elem_ty.floatBits(self.target.*)) {
179584 .float => switch (elem_ty.floatBits(self.target)) {
179585179585 else => unreachable,
179586179586 16, 80, 128 => null,
179587179587 32 => switch (vec_len) {
......@@ -180308,7 +180308,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
180308180308 defer self.register_manager.unlockReg(mask_lock);
180309180309
180310180310 const mir_fixes: Mir.Inst.Fixes = if (elem_ty.isRuntimeFloat())
180311 switch (elem_ty.floatBits(self.target.*)) {
180311 switch (elem_ty.floatBits(self.target)) {
180312180312 16, 80, 128 => .p_,
180313180313 32 => ._ps,
180314180314 64 => ._pd,
......@@ -180414,7 +180414,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
180414180414 .{ switch (elem_ty.zigTypeTag(zcu)) {
180415180415 else => break :result null,
180416180416 .int => .vp_,
180417 .float => switch (elem_ty.floatBits(self.target.*)) {
180417 .float => switch (elem_ty.floatBits(self.target)) {
180418180418 32 => .v_ps,
180419180419 64 => .v_pd,
180420180420 16, 80, 128 => break :result null,
......@@ -180428,7 +180428,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
180428180428 .{ switch (elem_ty.zigTypeTag(zcu)) {
180429180429 else => break :result null,
180430180430 .int => .p_,
180431 .float => switch (elem_ty.floatBits(self.target.*)) {
180431 .float => switch (elem_ty.floatBits(self.target)) {
180432180432 32 => ._ps,
180433180433 64 => ._pd,
180434180434 16, 80, 128 => break :result null,
......@@ -180800,7 +180800,7 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
180800180800
180801180801 const ops = [3]Air.Inst.Ref{ extra.lhs, extra.rhs, pl_op.operand };
180802180802 const result = result: {
180803 if (switch (ty.scalarType(zcu).floatBits(self.target.*)) {
180803 if (switch (ty.scalarType(zcu).floatBits(self.target)) {
180804180804 16, 80, 128 => true,
180805180805 32, 64 => !self.hasFeature(.fma),
180806180806 else => unreachable,
......@@ -180855,14 +180855,14 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
180855180855 const mir_tag = @as(?Mir.Inst.FixedTag, if (std.mem.eql(u2, &order, &.{ 1, 3, 2 }) or
180856180856 std.mem.eql(u2, &order, &.{ 3, 1, 2 }))
180857180857 switch (ty.zigTypeTag(zcu)) {
180858 .float => switch (ty.floatBits(self.target.*)) {
180858 .float => switch (ty.floatBits(self.target)) {
180859180859 32 => .{ .v_ss, .fmadd132 },
180860180860 64 => .{ .v_sd, .fmadd132 },
180861180861 16, 80, 128 => null,
180862180862 else => unreachable,
180863180863 },
180864180864 .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)) {
180866180866 32 => switch (ty.vectorLen(zcu)) {
180867180867 1 => .{ .v_ss, .fmadd132 },
180868180868 2...8 => .{ .v_ps, .fmadd132 },
......@@ -180882,14 +180882,14 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
180882180882 }
180883180883 else if (std.mem.eql(u2, &order, &.{ 2, 1, 3 }) or std.mem.eql(u2, &order, &.{ 1, 2, 3 }))
180884180884 switch (ty.zigTypeTag(zcu)) {
180885 .float => switch (ty.floatBits(self.target.*)) {
180885 .float => switch (ty.floatBits(self.target)) {
180886180886 32 => .{ .v_ss, .fmadd213 },
180887180887 64 => .{ .v_sd, .fmadd213 },
180888180888 16, 80, 128 => null,
180889180889 else => unreachable,
180890180890 },
180891180891 .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)) {
180893180893 32 => switch (ty.vectorLen(zcu)) {
180894180894 1 => .{ .v_ss, .fmadd213 },
180895180895 2...8 => .{ .v_ps, .fmadd213 },
......@@ -180909,14 +180909,14 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
180909180909 }
180910180910 else if (std.mem.eql(u2, &order, &.{ 2, 3, 1 }) or std.mem.eql(u2, &order, &.{ 3, 2, 1 }))
180911180911 switch (ty.zigTypeTag(zcu)) {
180912 .float => switch (ty.floatBits(self.target.*)) {
180912 .float => switch (ty.floatBits(self.target)) {
180913180913 32 => .{ .v_ss, .fmadd231 },
180914180914 64 => .{ .v_sd, .fmadd231 },
180915180915 16, 80, 128 => null,
180916180916 else => unreachable,
180917180917 },
180918180918 .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)) {
180920180920 32 => switch (ty.vectorLen(zcu)) {
180921180921 1 => .{ .v_ss, .fmadd231 },
180922180922 2...8 => .{ .v_ps, .fmadd231 },
......@@ -181979,7 +181979,7 @@ fn promoteInt(self: *CodeGen, ty: Type) Type {
181979181979
181980181980fn promoteVarArg(self: *CodeGen, ty: Type) Type {
181981181981 if (!ty.isRuntimeFloat()) return self.promoteInt(ty);
181982 switch (ty.floatBits(self.target.*)) {
181982 switch (ty.floatBits(self.target)) {
181983181983 32, 64 => return .f64,
181984181984 else => |float_bits| {
181985181985 assert(float_bits == self.target.cTypeBitSize(.longdouble));
......@@ -182080,7 +182080,7 @@ fn intInfo(cg: *CodeGen, ty: Type) ?std.builtin.Type.Int {
182080182080}
182081182081
182082182082fn 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;
182084182084}
182085182085
182086182086const Temp = struct {
src/arch/x86_64/Emit.zig+2-2
......@@ -105,7 +105,7 @@ pub fn emitMir(emit: *Emit) Error!void {
105105 emit.pt,
106106 emit.lower.src_loc,
107107 nav,
108 emit.lower.target.*,
108 emit.lower.target,
109109 )) {
110110 .mcv => |mcv| mcv.lea_symbol,
111111 .fail => |em| {
......@@ -542,7 +542,7 @@ pub fn emitMir(emit: *Emit) Error!void {
542542 emit.pt,
543543 emit.lower.src_loc,
544544 nav,
545 emit.lower.target.*,
545 emit.lower.target,
546546 ) catch |err| switch (err) {
547547 error.CodegenFail,
548548 => 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
148148 result[0] = .integer;
149149 return result;
150150 },
151 .float => switch (ty.floatBits(target.*)) {
151 .float => switch (ty.floatBits(target)) {
152152 16 => {
153153 if (ctx == .field) {
154154 result[0] = .memory;
src/codegen.zig+11-11
......@@ -65,7 +65,7 @@ fn importBackend(comptime backend: std.builtin.CompilerBackend) type {
6565pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) ?*const Air.Legalize.Features {
6666 const zcu = pt.zcu;
6767 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)) {
6969 else => unreachable,
7070 inline .stage2_llvm,
7171 .stage2_c,
......@@ -114,7 +114,7 @@ pub const AnyMir = union {
114114
115115 pub fn deinit(mir: *AnyMir, zcu: *const Zcu) void {
116116 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);
118118 switch (backend) {
119119 else => unreachable,
120120 inline .stage2_aarch64,
......@@ -145,7 +145,7 @@ pub fn generateFunction(
145145) CodeGenError!AnyMir {
146146 const zcu = pt.zcu;
147147 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;
149149 switch (target_util.zigBackend(target, false)) {
150150 else => unreachable,
151151 inline .stage2_aarch64,
......@@ -183,7 +183,7 @@ pub fn emitFunction(
183183) CodeGenError!void {
184184 const zcu = pt.zcu;
185185 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;
187187 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {
188188 else => unreachable,
189189 inline .stage2_aarch64,
......@@ -210,7 +210,7 @@ pub fn generateLazyFunction(
210210) CodeGenError!void {
211211 const zcu = pt.zcu;
212212 const target = if (Type.fromInterned(lazy_sym.ty).typeDeclInstAllowGeneratedTag(zcu)) |inst_index|
213 zcu.fileByIndex(inst_index.resolveFile(&zcu.intern_pool)).mod.?.resolved_target.result
213 &zcu.fileByIndex(inst_index.resolveFile(&zcu.intern_pool)).mod.?.resolved_target.result
214214 else
215215 zcu.getTarget();
216216 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {
......@@ -225,7 +225,7 @@ pub fn generateLazyFunction(
225225 }
226226}
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 {
229229 _ = target;
230230 const bits = @typeInfo(F).float.bits;
231231 const Int = @Type(.{ .int = .{ .signedness = .unsigned, .bits = bits } });
......@@ -253,7 +253,7 @@ pub fn generateLazySymbol(
253253 const gpa = comp.gpa;
254254 const zcu = pt.zcu;
255255 const ip = &zcu.intern_pool;
256 const target = comp.root_mod.resolved_target.result;
256 const target = &comp.root_mod.resolved_target.result;
257257 const endian = target.cpu.arch.endian();
258258
259259 log.debug("generateLazySymbol: kind = {s}, ty = {}", .{
......@@ -839,7 +839,7 @@ fn lowerNavRef(
839839 const zcu = pt.zcu;
840840 const gpa = zcu.gpa;
841841 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;
843843 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
844844 const is_obj = lf.comp.config.output_mode == .Obj;
845845 const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip));
......@@ -956,7 +956,7 @@ pub fn genNavRef(
956956 pt: Zcu.PerThread,
957957 src_loc: Zcu.LazySrcLoc,
958958 nav_index: InternPool.Nav.Index,
959 target: std.Target,
959 target: *const std.Target,
960960) CodeGenError!GenResult {
961961 const zcu = pt.zcu;
962962 const ip = &zcu.intern_pool;
......@@ -1040,9 +1040,9 @@ pub fn genTypedValue(
10401040 pt: Zcu.PerThread,
10411041 src_loc: Zcu.LazySrcLoc,
10421042 val: Value,
1043 target: std.Target,
1043 target: *const std.Target,
10441044) CodeGenError!GenResult {
1045 return switch (try lowerValue(pt, val, &target)) {
1045 return switch (try lowerValue(pt, val, target)) {
10461046 .none => .{ .mcv = .none },
10471047 .undef => .{ .mcv = .undef },
10481048 .immediate => |imm| .{ .mcv = .{ .immediate = imm } },
src/codegen/c.zig+6-6
......@@ -1080,7 +1080,7 @@ pub const DeclGen = struct {
10801080 },
10811081 .enum_tag => |enum_tag| try dg.renderValue(writer, Value.fromInterned(enum_tag.int), location),
10821082 .float => {
1083 const bits = ty.floatBits(target.*);
1083 const bits = ty.floatBits(target);
10841084 const f128_val = val.toFloat(f128, zcu);
10851085
10861086 // All unsigned ints matching float types are pre-allocated.
......@@ -1608,7 +1608,7 @@ pub const DeclGen = struct {
16081608 .f80_type,
16091609 .f128_type,
16101610 => {
1611 const bits = ty.floatBits(target.*);
1611 const bits = ty.floatBits(target);
16121612 // All unsigned ints matching float types are pre-allocated.
16131613 const repr_ty = dg.pt.intType(.unsigned, bits) catch unreachable;
16141614
......@@ -6543,7 +6543,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
65436543 const scalar_ty = operand_ty.scalarType(zcu);
65446544 const target = &f.object.dg.mod.resolved_target.result;
65456545 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"
65476547 else if (inst_scalar_ty.isInt(zcu) and scalar_ty.isRuntimeFloat())
65486548 if (inst_scalar_ty.isSignedInt(zcu)) "fix" else "fixuns"
65496549 else if (inst_scalar_ty.isRuntimeFloat() and scalar_ty.isInt(zcu))
......@@ -6565,8 +6565,8 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
65656565 }
65666566 try writer.writeAll("zig_");
65676567 try writer.writeAll(operation);
6568 try writer.writeAll(compilerRtAbbrev(scalar_ty, zcu, target.*));
6569 try writer.writeAll(compilerRtAbbrev(inst_scalar_ty, zcu, target.*));
6568 try writer.writeAll(compilerRtAbbrev(scalar_ty, zcu, target));
6569 try writer.writeAll(compilerRtAbbrev(inst_scalar_ty, zcu, target));
65706570 try writer.writeByte('(');
65716571 try f.writeCValue(writer, operand, .FunctionArgument);
65726572 try v.elem(f, writer);
......@@ -8073,7 +8073,7 @@ fn signAbbrev(signedness: std.builtin.Signedness) u8 {
80738073 };
80748074}
80758075
8076fn compilerRtAbbrev(ty: Type, zcu: *Zcu, target: std.Target) []const u8 {
8076fn compilerRtAbbrev(ty: Type, zcu: *Zcu, target: *const std.Target) []const u8 {
80778077 return if (ty.isInt(zcu)) switch (ty.intInfo(zcu).bits) {
80788078 1...32 => "si",
80798079 33...64 => "di",
src/codegen/c/Type.zig+7-7
......@@ -1319,9 +1319,9 @@ pub const Pool = struct {
13191319 },
13201320 else => {
13211321 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);
13231323 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),
13251325 .elem_ctype = try pool.fromIntInfo(allocator, .{
13261326 .signedness = .unsigned,
13271327 .bits = @intCast(abi_align_bytes * 8),
......@@ -1438,13 +1438,13 @@ pub const Pool = struct {
14381438 .elem_ctype = .u8,
14391439 .@"const" = true,
14401440 }),
1441 .alignas = AlignAs.fromAbiAlignment(Type.ptrAbiAlignment(target.*)),
1441 .alignas = AlignAs.fromAbiAlignment(Type.ptrAbiAlignment(target)),
14421442 },
14431443 .{
14441444 .name = .{ .index = .len },
14451445 .ctype = .usize,
14461446 .alignas = AlignAs.fromAbiAlignment(
1447 .fromByteUnits(std.zig.target.intAlignment(target.*, target.ptrBitWidth())),
1447 .fromByteUnits(std.zig.target.intAlignment(target, target.ptrBitWidth())),
14481448 ),
14491449 },
14501450 };
......@@ -2246,13 +2246,13 @@ pub const Pool = struct {
22462246 mod,
22472247 kind,
22482248 ),
2249 .alignas = AlignAs.fromAbiAlignment(Type.ptrAbiAlignment(target.*)),
2249 .alignas = AlignAs.fromAbiAlignment(Type.ptrAbiAlignment(target)),
22502250 },
22512251 .{
22522252 .name = .{ .index = .len },
22532253 .ctype = .usize,
22542254 .alignas = AlignAs.fromAbiAlignment(
2255 .fromByteUnits(std.zig.target.intAlignment(target.*, target.ptrBitWidth())),
2255 .fromByteUnits(std.zig.target.intAlignment(target, target.ptrBitWidth())),
22562256 ),
22572257 },
22582258 };
......@@ -2372,7 +2372,7 @@ pub const Pool = struct {
23722372 .name = .{ .index = .@"error" },
23732373 .ctype = error_set_ctype,
23742374 .alignas = AlignAs.fromAbiAlignment(
2375 .fromByteUnits(std.zig.target.intAlignment(target.*, error_set_bits)),
2375 .fromByteUnits(std.zig.target.intAlignment(target, error_set_bits)),
23762376 ),
23772377 },
23782378 .{
src/codegen/llvm.zig+37-39
......@@ -43,7 +43,7 @@ pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
4343 });
4444}
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 {
4747 inline for (mappings) |mapping| {
4848 if (target.cpu.has(family, mapping[0])) return mapping[1];
4949 }
......@@ -51,7 +51,7 @@ fn subArchName(target: std.Target, comptime family: std.Target.Cpu.Arch.Family,
5151 return null;
5252}
5353
54pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
54pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8 {
5555 var llvm_triple = std.ArrayList(u8).init(allocator);
5656 defer llvm_triple.deinit();
5757
......@@ -309,7 +309,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
309309 return llvm_triple.toOwnedSlice();
310310}
311311
312pub fn supportsTailCall(target: std.Target) bool {
312pub fn supportsTailCall(target: *const std.Target) bool {
313313 return switch (target.cpu.arch) {
314314 .wasm32, .wasm64 => target.cpu.has(.wasm, .tail_call),
315315 // 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 {
319319 };
320320}
321321
322pub fn dataLayout(target: std.Target) []const u8 {
322pub fn dataLayout(target: *const std.Target) []const u8 {
323323 // These data layouts should match Clang.
324324 return switch (target.cpu.arch) {
325325 .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 {
475475 large,
476476};
477477
478fn codeModel(model: std.builtin.CodeModel, target: std.Target) CodeModel {
478fn codeModel(model: std.builtin.CodeModel, target: *const std.Target) CodeModel {
479479 // Roughly match Clang's mapping of GCC code models to LLVM code models.
480480 return switch (model) {
481481 .default => .default,
......@@ -508,7 +508,7 @@ pub const Object = struct {
508508
509509 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata),
510510
511 target: std.Target,
511 target: *const std.Target,
512512 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,
513513 /// but that has some downsides:
514514 /// * we have to compute the fully qualified name every time we want to do the lookup
......@@ -562,7 +562,7 @@ pub const Object = struct {
562562 pub fn create(arena: Allocator, comp: *Compilation) !Ptr {
563563 dev.check(.llvm_backend);
564564 const gpa = comp.gpa;
565 const target = comp.root_mod.resolved_target.result;
565 const target = &comp.root_mod.resolved_target.result;
566566 const llvm_target_triple = try targetTriple(arena, target);
567567
568568 var builder = try Builder.init(.{
......@@ -827,7 +827,7 @@ pub const Object = struct {
827827 const behavior_max = try o.builder.metadataConstant(try o.builder.intConst(.i32, 7));
828828 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| {
831831 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
832832 behavior_error,
833833 try o.builder.metadataString("target-abi"),
......@@ -837,7 +837,7 @@ pub const Object = struct {
837837 ));
838838 }
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);
841841 if (comp.root_mod.pic) {
842842 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
843843 behavior_min,
......@@ -860,7 +860,7 @@ pub const Object = struct {
860860 try o.builder.metadataString("Code Model"),
861861 try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(
862862 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)) {
864864 .default => unreachable,
865865 .tiny => 0,
866866 .small => 1,
......@@ -906,7 +906,7 @@ pub const Object = struct {
906906 }
907907 }
908908
909 const target = comp.root_mod.resolved_target.result;
909 const target = &comp.root_mod.resolved_target.result;
910910 if (target.os.tag == .windows and (target.cpu.arch == .x86_64 or target.cpu.arch == .x86)) {
911911 // Add the "RegCallv4" flag so that any functions using `x86_regcallcc` use regcall
912912 // v4, which is essentially a requirement on Windows. See corresponding logic in
......@@ -1020,7 +1020,7 @@ pub const Object = struct {
10201020 else
10211021 .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)) {
10241024 .default => .Default,
10251025 .tiny => .Tiny,
10261026 .small => .Small,
......@@ -1045,7 +1045,7 @@ pub const Object = struct {
10451045 comp.function_sections,
10461046 comp.data_sections,
10471047 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,
10491049 );
10501050 errdefer target_machine.dispose();
10511051
......@@ -1137,7 +1137,7 @@ pub const Object = struct {
11371137 const owner_mod = zcu.fileByIndex(file_scope).mod.?;
11381138 const fn_ty = Type.fromInterned(func.ty);
11391139 const fn_info = zcu.typeToFunc(fn_ty).?;
1140 const target = owner_mod.resolved_target.result;
1140 const target = &owner_mod.resolved_target.result;
11411141
11421142 var ng: NavGen = .{
11431143 .object = o,
......@@ -2699,7 +2699,7 @@ pub const Object = struct {
26992699 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
27002700
27012701 const fn_info = zcu.typeToFunc(ty).?;
2702 const target = owner_mod.resolved_target.result;
2702 const target = &owner_mod.resolved_target.result;
27032703 const sret = firstParamSRet(fn_info, zcu, target);
27042704
27052705 const is_extern, const lib_name = if (nav.getExtern(ip)) |@"extern"|
......@@ -2913,7 +2913,7 @@ pub const Object = struct {
29132913 try attributes.addFnAttr(.minsize, &o.builder);
29142914 try attributes.addFnAttr(.optsize, &o.builder);
29152915 }
2916 const target = owner_mod.resolved_target.result;
2916 const target = &owner_mod.resolved_target.result;
29172917 if (target.cpu.model.llvm_name) |s| {
29182918 try attributes.addFnAttr(.{ .string = .{
29192919 .kind = try o.builder.string("target-cpu"),
......@@ -4445,7 +4445,7 @@ pub const Object = struct {
44454445 if (o.builder.getGlobal(name)) |llvm_fn| return llvm_fn.ptrConst(&o.builder).kind.function;
44464446
44474447 const zcu = o.pt.zcu;
4448 const target = zcu.root_mod.resolved_target.result;
4448 const target = &zcu.root_mod.resolved_target.result;
44494449 const function_index = try o.builder.addFunction(
44504450 try o.builder.fnType(.i1, &.{try o.errorIntType()}, .normal),
44514451 name,
......@@ -4474,7 +4474,7 @@ pub const Object = struct {
44744474
44754475 const usize_ty = try o.lowerType(Type.usize);
44764476 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;
44784478 const function_index = try o.builder.addFunction(
44794479 try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
44804480 try o.builder.strtabStringFmt("__zig_tag_name_{}", .{enum_type.name.fmt(ip)}),
......@@ -10372,7 +10372,7 @@ pub const FuncGen = struct {
1037210372 if (gop.found_existing) return gop.value_ptr.*;
1037310373 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;
1037610376 const function_index = try o.builder.addFunction(
1037710377 try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
1037810378 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{}", .{enum_type.name.fmt(ip)}),
......@@ -11834,7 +11834,7 @@ const CallingConventionInfo = struct {
1183411834 inreg_param_count: u2 = 0,
1183511835};
1183611836
11837pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) ?CallingConventionInfo {
11837pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: *const std.Target) ?CallingConventionInfo {
1183811838 const llvm_cc = toLlvmCallConvTag(cc, target) orelse return null;
1183911839 const incoming_stack_alignment: ?u64, const register_params: u2 = switch (cc) {
1184011840 inline else => |pl| switch (@TypeOf(pl)) {
......@@ -11858,7 +11858,7 @@ pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) ?Ca
1185811858 .inreg_param_count = register_params,
1185911859 };
1186011860}
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 {
1186211862 if (target.cCallingConvention()) |default_c| {
1186311863 if (cc_tag == default_c) {
1186411864 return .ccc;
......@@ -11972,7 +11972,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Targ
1197211972}
1197311973
1197411974/// 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 {
1197611976 for (llvmAddrSpaceInfo(target)) |info| if (info.zig == address_space) return info.llvm;
1197711977 unreachable;
1197811978}
......@@ -11987,7 +11987,7 @@ const AddrSpaceInfo = struct {
1198711987 idx: ?u16 = null,
1198811988 force_in_data_layout: bool = false,
1198911989};
11990fn llvmAddrSpaceInfo(target: std.Target) []const AddrSpaceInfo {
11990fn llvmAddrSpaceInfo(target: *const std.Target) []const AddrSpaceInfo {
1199111991 return switch (target.cpu.arch) {
1199211992 .x86, .x86_64 => &.{
1199311993 .{ .zig = .generic, .llvm = .default },
......@@ -12063,7 +12063,7 @@ fn llvmAddrSpaceInfo(target: std.Target) []const AddrSpaceInfo {
1206312063/// different address, space and then cast back to the generic address space.
1206412064/// For example, on GPUs local variable declarations must be generated into the local address space.
1206512065/// 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 {
1206712067 return switch (target.cpu.arch) {
1206812068 // On amdgcn, locals should be generated into the private address space.
1206912069 // 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 {
1207512075
1207612076/// On some targets, global values that are in the generic address space must be generated into a
1207712077/// 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 {
1207912079 return switch (target.cpu.arch) {
1208012080 // On amdgcn, globals must be explicitly allocated and uploaded so that the program can access
1208112081 // them.
......@@ -12086,14 +12086,14 @@ fn llvmDefaultGlobalAddressSpace(target: std.Target) Builder.AddrSpace {
1208612086
1208712087/// Return the actual address space that a value should be stored in if its a global address space.
1208812088/// 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 {
1209012090 return switch (wanted_address_space) {
1209112091 .generic => llvmDefaultGlobalAddressSpace(target),
1209212092 else => |as| toLlvmAddressSpace(as, target),
1209312093 };
1209412094}
1209512095
12096fn returnTypeByRef(zcu: *Zcu, target: std.Target, ty: Type) bool {
12096fn returnTypeByRef(zcu: *Zcu, target: *const std.Target, ty: Type) bool {
1209712097 if (isByRef(ty, zcu)) {
1209812098 return true;
1209912099 } else if (target.cpu.arch.isX86() and
......@@ -12108,7 +12108,7 @@ fn returnTypeByRef(zcu: *Zcu, target: std.Target, ty: Type) bool {
1210812108 }
1210912109}
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 {
1211212112 const return_type = Type.fromInterned(fn_info.return_type);
1211312113 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) return false;
1211412114
......@@ -12137,8 +12137,8 @@ fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Targe
1213712137 };
1213812138}
1213912139
12140fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: std.Target) bool {
12141 const class = x86_64_abi.classifySystemV(ty, zcu, &target, .ret);
12140fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: *const std.Target) bool {
12141 const class = x86_64_abi.classifySystemV(ty, zcu, target, .ret);
1214212142 if (class[0] == .memory) return true;
1214312143 if (class[0] == .x87 and class[2] != .none) return true;
1214412144 return false;
......@@ -12238,8 +12238,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
1223812238 if (isScalar(zcu, return_type)) {
1223912239 return o.lowerType(return_type);
1224012240 }
12241 const target = zcu.getTarget();
12242 const classes = x86_64_abi.classifySystemV(return_type, zcu, &target, .ret);
12241 const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret);
1224312242 if (classes[0] == .memory) return .void;
1224412243 var types_index: u32 = 0;
1224512244 var types_buffer: [8]Builder.Type = undefined;
......@@ -12527,8 +12526,7 @@ const ParamTypeIterator = struct {
1252712526 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
1252812527 const zcu = it.object.pt.zcu;
1252912528 const ip = &zcu.intern_pool;
12530 const target = zcu.getTarget();
12531 const classes = x86_64_abi.classifySystemV(ty, zcu, &target, .arg);
12529 const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg);
1253212530 if (classes[0] == .memory) {
1253312531 it.zig_index += 1;
1253412532 it.llvm_index += 1;
......@@ -12794,7 +12792,7 @@ fn isScalar(zcu: *Zcu, ty: Type) bool {
1279412792/// This function returns true if we expect LLVM to lower x86_fp80 correctly
1279512793/// and false if we expect LLVM to crash if it encounters an x86_fp80 type,
1279612794/// or if it produces miscompilations.
12797fn backendSupportsF80(target: std.Target) bool {
12795fn backendSupportsF80(target: *const std.Target) bool {
1279812796 return switch (target.cpu.arch) {
1279912797 .x86, .x86_64 => !target.cpu.has(.x86, .soft_float),
1280012798 else => false,
......@@ -12804,7 +12802,7 @@ fn backendSupportsF80(target: std.Target) bool {
1280412802/// This function returns true if we expect LLVM to lower f16 correctly
1280512803/// and false if we expect LLVM to crash if it encounters an f16 type,
1280612804/// or if it produces miscompilations.
12807fn backendSupportsF16(target: std.Target) bool {
12805fn backendSupportsF16(target: *const std.Target) bool {
1280812806 return switch (target.cpu.arch) {
1280912807 // https://github.com/llvm/llvm-project/issues/97981
1281012808 .csky,
......@@ -12840,7 +12838,7 @@ fn backendSupportsF16(target: std.Target) bool {
1284012838/// This function returns true if we expect LLVM to lower f128 correctly,
1284112839/// and false if we expect LLVM to crash if it encounters an f128 type,
1284212840/// or if it produces miscompilations.
12843fn backendSupportsF128(target: std.Target) bool {
12841fn backendSupportsF128(target: *const std.Target) bool {
1284412842 return switch (target.cpu.arch) {
1284512843 // https://github.com/llvm/llvm-project/issues/121122
1284612844 .amdgcn,
......@@ -12870,7 +12868,7 @@ fn backendSupportsF128(target: std.Target) bool {
1287012868
1287112869/// LLVM does not support all relevant intrinsics for all targets, so we
1287212870/// 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 {
1287412872 return switch (scalar_ty.toIntern()) {
1287512873 .f16_type => backendSupportsF16(target),
1287612874 .f80_type => (target.cTypeBitSize(.longdouble) == 80) and backendSupportsF80(target),
......@@ -12907,7 +12905,7 @@ fn buildAllocaInner(
1290712905 wip: *Builder.WipFunction,
1290812906 llvm_ty: Builder.Type,
1290912907 alignment: Builder.Alignment,
12910 target: std.Target,
12908 target: *const std.Target,
1291112909) Allocator.Error!Builder.Value {
1291212910 const address_space = llvmAllocaAddressSpace(target);
1291312911
src/codegen/spirv.zig+1-1
......@@ -185,7 +185,7 @@ pub const Object = struct {
185185 /// related to that.
186186 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 {
189189 return .{
190190 .gpa = gpa,
191191 .spv = SpvModule.init(gpa, target),
src/codegen/spirv/Module.zig+2-2
......@@ -107,7 +107,7 @@ gpa: Allocator,
107107arena: std.heap.ArenaAllocator,
108108
109109/// Target info
110target: std.Target,
110target: *const std.Target,
111111
112112/// The target SPIR-V version
113113version: spec.Version,
......@@ -187,7 +187,7 @@ decl_deps: std.ArrayListUnmanaged(Decl.Index) = .empty,
187187/// The list of entry points that should be exported from this module.
188188entry_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 {
191191 const version_minor: u8 = blk: {
192192 // Prefer higher versions
193193 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
6666 defer arena_allocator.deinit();
6767 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
7171 // In all cases in this function, we add the C compiler flags to
7272 // cache_exempt_flags rather than extra_flags, because these arguments
......@@ -407,7 +407,7 @@ pub const BuiltSharedObjects = struct {
407407
408408const all_map_basename = "all.map";
409409
410fn wordDirective(target: std.Target) []const u8 {
410fn wordDirective(target: *const std.Target) []const u8 {
411411 // Based on its description in the GNU `as` manual, you might assume that `.word` is sized
412412 // according to the target word size. But no; that would just make too much sense.
413413 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
172172 defer arena_allocator.deinit();
173173 const arena = arena_allocator.allocator();
174174
175 const target = comp.root_mod.resolved_target.result;
175 const target = &comp.root_mod.resolved_target.result;
176176 const target_ver = target.os.versionRange().gnuLibCVersion().?;
177177 const nonshared_stat = target_ver.order(.{ .major = 2, .minor = 32, .patch = 0 }) != .gt;
178178 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([
485485fn add_include_dirs_arch(
486486 arena: Allocator,
487487 args: *std.ArrayList([]const u8),
488 target: std.Target,
488 target: *const std.Target,
489489 opt_nptl: ?[]const u8,
490490 dir: []const u8,
491491) error{OutOfMemory}!void {
......@@ -649,7 +649,7 @@ pub const BuiltSharedObjects = struct {
649649
650650const all_map_basename = "all.map";
651651
652fn wordDirective(target: std.Target) []const u8 {
652fn wordDirective(target: *const std.Target) []const u8 {
653653 // Based on its description in the GNU `as` manual, you might assume that `.word` is sized
654654 // according to the target word size. But no; that would just make too much sense.
655655 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!
121121 const root_name = "c++";
122122 const output_mode = .Lib;
123123 const link_mode = .static;
124 const target = comp.root_mod.resolved_target.result;
124 const target = &comp.root_mod.resolved_target.result;
125125
126126 const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" });
127127 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
314314 const root_name = "c++abi";
315315 const output_mode = .Lib;
316316 const link_mode = .static;
317 const target = comp.root_mod.resolved_target.result;
317 const target = &comp.root_mod.resolved_target.result;
318318
319319 const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" });
320320 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
324324 comp.tsan_lib = crt_file;
325325}
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 {
328328 try args.appendSlice(&[_][]const u8{
329329 "-nostdinc++",
330330 "-fvisibility=hidden",
src/libs/libunwind.zig+1-1
......@@ -27,7 +27,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
2727 const arena = arena_allocator.allocator();
2828
2929 const output_mode = .Lib;
30 const target = comp.root_mod.resolved_target.result;
30 const target = &comp.root_mod.resolved_target.result;
3131 const unwind_tables: std.builtin.UnwindTables =
3232 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .@"async";
3333 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 {
299299 var aro_comp = aro.Compilation.init(gpa, std.fs.cwd());
300300 defer aro_comp.deinit();
301301
302 aro_comp.target = target;
302 aro_comp.target = target.*;
303303
304304 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 {
373373
374374pub fn libExists(
375375 allocator: Allocator,
376 target: std.Target,
376 target: *const std.Target,
377377 zig_lib_directory: Cache.Directory,
378378 lib_name: []const u8,
379379) !bool {
......@@ -389,7 +389,7 @@ pub fn libExists(
389389/// see if a .def file exists.
390390fn findDef(
391391 allocator: Allocator,
392 target: std.Target,
392 target: *const std.Target,
393393 zig_lib_directory: Cache.Directory,
394394 lib_name: []const u8,
395395) ![]u8 {
src/libs/musl.zig+1-1
......@@ -193,7 +193,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
193193 .link_libc = false,
194194 });
195195
196 const target = comp.root_mod.resolved_target.result;
196 const target = &comp.root_mod.resolved_target.result;
197197 const arch_name = std.zig.target.muslArchName(target.cpu.arch, target.abi);
198198 const time32 = for (time32_compat_arch_list) |time32_compat_arch| {
199199 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
5858 defer arena_allocator.deinit();
5959 const arena = arena_allocator.allocator();
6060
61 const target = comp.root_mod.resolved_target.result;
61 const target = &comp.root_mod.resolved_target.result;
6262 const target_version = target.os.version_range.semver.min;
6363
6464 // In all cases in this function, we add the C compiler flags to
......@@ -353,7 +353,7 @@ pub const BuiltSharedObjects = struct {
353353 }
354354};
355355
356fn wordDirective(target: std.Target) []const u8 {
356fn wordDirective(target: *const std.Target) []const u8 {
357357 // Based on its description in the GNU `as` manual, you might assume that `.word` is sized
358358 // according to the target word size. But no; that would just make too much sense.
359359 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 {
13211321 const prog_node = comp.link_prog_node.start("Parse Host libc", 0);
13221322 defer prog_node.end();
13231323
1324 const target = comp.root_mod.resolved_target.result;
1324 const target = &comp.root_mod.resolved_target.result;
13251325 const flags = target_util.libcFullLinkFlags(target);
13261326 const crt_dir = comp.libc_installation.?.crt_dir.?;
13271327 const sep = std.fs.path.sep_str;
......@@ -1670,7 +1670,7 @@ pub fn hashInputs(man: *Cache.Manifest, link_inputs: []const Input) !void {
16701670pub fn resolveInputs(
16711671 gpa: Allocator,
16721672 arena: Allocator,
1673 target: std.Target,
1673 target: *const std.Target,
16741674 /// This function mutates this array but does not take ownership.
16751675 /// Allocated with `gpa`.
16761676 unresolved_inputs: *std.ArrayListUnmanaged(UnresolvedInput),
......@@ -1914,7 +1914,7 @@ fn resolveLibInput(
19141914 ld_script_bytes: *std.ArrayListUnmanaged(u8),
19151915 lib_directory: Directory,
19161916 name_query: UnresolvedInput.NameQuery,
1917 target: std.Target,
1917 target: *const std.Target,
19181918 link_mode: std.builtin.LinkMode,
19191919 color: std.zig.Color,
19201920) Allocator.Error!ResolveLibInputResult {
......@@ -2028,7 +2028,7 @@ fn resolvePathInput(
20282028 resolved_inputs: *std.ArrayListUnmanaged(Input),
20292029 /// Allocated via `gpa`.
20302030 ld_script_bytes: *std.ArrayListUnmanaged(u8),
2031 target: std.Target,
2031 target: *const std.Target,
20322032 pq: UnresolvedInput.PathQuery,
20332033 color: std.zig.Color,
20342034) Allocator.Error!?ResolveLibInputResult {
......@@ -2070,7 +2070,7 @@ fn resolvePathInputLib(
20702070 resolved_inputs: *std.ArrayListUnmanaged(Input),
20712071 /// Allocated via `gpa`.
20722072 ld_script_bytes: *std.ArrayListUnmanaged(u8),
2073 target: std.Target,
2073 target: *const std.Target,
20742074 pq: UnresolvedInput.PathQuery,
20752075 link_mode: std.builtin.LinkMode,
20762076 color: std.zig.Color,
src/link/C.zig+2-2
......@@ -116,7 +116,7 @@ pub fn createEmpty(
116116 emit: Path,
117117 options: link.File.OpenOptions,
118118) !*C {
119 const target = comp.root_mod.resolved_target.result;
119 const target = &comp.root_mod.resolved_target.result;
120120 assert(target.ofmt == .c);
121121 const optimize_mode = comp.root_mod.optimize_mode;
122122 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
331331 _ = ti_id;
332332}
333333
334fn abiDefines(self: *C, target: std.Target) !std.ArrayList(u8) {
334fn abiDefines(self: *C, target: *const std.Target) !std.ArrayList(u8) {
335335 const gpa = self.base.comp.gpa;
336336 var defines = std.ArrayList(u8).init(gpa);
337337 errdefer defines.deinit();
src/link/Coff.zig+4-4
......@@ -208,7 +208,7 @@ pub fn createEmpty(
208208 emit: Path,
209209 options: link.File.OpenOptions,
210210) !*Coff {
211 const target = comp.root_mod.resolved_target.result;
211 const target = &comp.root_mod.resolved_target.result;
212212 assert(target.ofmt == .coff);
213213 const optimize_mode = comp.root_mod.optimize_mode;
214214 const output_mode = comp.config.output_mode;
......@@ -1328,7 +1328,7 @@ fn updateNavCode(
13281328
13291329 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;
13321332 const required_alignment = switch (pt.navAlignment(nav_index)) {
13331333 .none => target_util.defaultFunctionAlignment(target),
13341334 else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
......@@ -2153,7 +2153,7 @@ fn writeDataDirectoriesHeaders(coff: *Coff) !void {
21532153}
21542154
21552155fn 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;
21572157 const gpa = coff.base.comp.gpa;
21582158 var buffer = std.ArrayList(u8).init(gpa);
21592159 defer buffer.deinit();
......@@ -2800,7 +2800,7 @@ pub const Relocation = struct {
28002800 .ptr_width = coff.ptr_width,
28012801 };
28022802
2803 const target = coff.base.comp.root_mod.resolved_target.result;
2803 const target = &coff.base.comp.root_mod.resolved_target.result;
28042804 switch (target.cpu.arch) {
28052805 .aarch64 => reloc.resolveAarch64(ctx),
28062806 .x86, .x86_64 => reloc.resolveX86(ctx),
src/link/Dwarf.zig+4-4
......@@ -92,7 +92,7 @@ const DebugFrame = struct {
9292 };
9393
9494 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;
9696 return @intCast(switch (dwarf.debug_frame.header.format) {
9797 .none => return 0,
9898 .debug_frame => dwarf.unitLengthBytes() + dwarf.sectionOffsetBytes() + 1 + "\x00".len + 1 + 1,
......@@ -2140,7 +2140,7 @@ fn padToIdeal(actual_size: anytype) @TypeOf(actual_size) {
21402140pub fn init(lf: *link.File, format: DW.Format) Dwarf {
21412141 const comp = lf.comp;
21422142 const gpa = comp.gpa;
2143 const target = comp.root_mod.resolved_target.result;
2143 const target = &comp.root_mod.resolved_target.result;
21442144 return .{
21452145 .gpa = gpa,
21462146 .bin_file = lf,
......@@ -2573,7 +2573,7 @@ fn initWipNavInner(
25732573 try wip_nav.infoAddrSym(sym_index, 0);
25742574 wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);
25752575 try diw.writeInt(u32, 0, dwarf.endian);
2576 const target = mod.resolved_target.result;
2576 const target = &mod.resolved_target.result;
25772577 try uleb128(diw, switch (nav.status.fully_resolved.alignment) {
25782578 .none => target_info.defaultFunctionAlignment(target),
25792579 else => |a| a.maxStrict(target_info.minFunctionAlignment(target)),
......@@ -4529,7 +4529,7 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
45294529 dwarf.debug_aranges.section.dirty = false;
45304530 }
45314531 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;
45334533 switch (dwarf.debug_frame.header.format) {
45344534 .none => {},
45354535 .debug_frame => unreachable,
src/link/Elf.zig+6-6
......@@ -196,7 +196,7 @@ pub fn createEmpty(
196196 emit: Path,
197197 options: link.File.OpenOptions,
198198) !*Elf {
199 const target = comp.root_mod.resolved_target.result;
199 const target = &comp.root_mod.resolved_target.result;
200200 assert(target.ofmt == .elf);
201201
202202 const use_llvm = comp.config.use_llvm;
......@@ -1073,7 +1073,7 @@ fn parseObject(self: *Elf, obj: link.Input.Object) !void {
10731073
10741074 const gpa = self.base.comp.gpa;
10751075 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;
10771077 const debug_fmt_strip = self.base.comp.config.debug_format == .strip;
10781078 const default_sym_version = self.default_sym_version;
10791079 const file_handles = &self.file_handles;
......@@ -1104,7 +1104,7 @@ fn parseArchive(
11041104 diags: *Diags,
11051105 file_handles: *std.ArrayListUnmanaged(File.Handle),
11061106 files: *std.MultiArrayList(File.Entry),
1107 target: std.Target,
1107 target: *const std.Target,
11081108 debug_fmt_strip: bool,
11091109 default_sym_version: elf.Versym,
11101110 objects: *std.ArrayListUnmanaged(File.Index),
......@@ -1139,7 +1139,7 @@ fn parseDso(
11391139 dso: link.Input.Dso,
11401140 shared_objects: *std.StringArrayHashMapUnmanaged(File.Index),
11411141 files: *std.MultiArrayList(File.Entry),
1142 target: std.Target,
1142 target: *const std.Target,
11431143) !void {
11441144 const tracy = trace(@src());
11451145 defer tracy.end();
......@@ -4121,8 +4121,8 @@ pub fn lsearch(comptime T: type, haystack: []const T, predicate: anytype) usize
41214121 return i;
41224122}
41234123
4124pub fn getTarget(self: Elf) std.Target {
4125 return self.base.comp.root_mod.resolved_target.result;
4124pub fn getTarget(self: *const Elf) *const std.Target {
4125 return &self.base.comp.root_mod.resolved_target.result;
41264126}
41274127
41284128fn requiresThunks(self: Elf) bool {
src/link/Elf/Object.zig+5-5
......@@ -69,7 +69,7 @@ pub fn parse(
6969 /// For error reporting purposes only.
7070 path: Path,
7171 handle: fs.File,
72 target: std.Target,
72 target: *const std.Target,
7373 debug_fmt_strip: bool,
7474 default_sym_version: elf.Versym,
7575) !void {
......@@ -98,7 +98,7 @@ pub fn parseCommon(
9898 diags: *Diags,
9999 path: Path,
100100 handle: fs.File,
101 target: std.Target,
101 target: *const std.Target,
102102) !void {
103103 const offset = if (self.archive) |ar| ar.offset else 0;
104104 const file_size = (try handle.stat()).size;
......@@ -182,7 +182,7 @@ pub fn parseCommon(
182182pub fn validateEFlags(
183183 diags: *Diags,
184184 path: Path,
185 target: std.Target,
185 target: *const std.Target,
186186 e_flags: elf.Word,
187187) !void {
188188 switch (target.cpu.arch) {
......@@ -263,7 +263,7 @@ fn initAtoms(
263263 path: Path,
264264 handle: fs.File,
265265 debug_fmt_strip: bool,
266 target: std.Target,
266 target: *const std.Target,
267267) !void {
268268 const shdrs = self.shdrs.items;
269269 try self.atoms.ensureTotalCapacityPrecise(gpa, shdrs.len);
......@@ -420,7 +420,7 @@ fn parseEhFrame(
420420 gpa: Allocator,
421421 handle: fs.File,
422422 shndx: u32,
423 target: std.Target,
423 target: *const std.Target,
424424) !void {
425425 const relocs_shndx = for (self.shdrs.items, 0..) |shdr, i| switch (shdr.sh_type) {
426426 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(
9696 file_path: Path,
9797 fs_file: std.fs.File,
9898 stat: Stat,
99 target: std.Target,
99 target: *const std.Target,
100100) !Header {
101101 var ehdr: elf.Elf64_Ehdr = undefined;
102102 {
src/link/Elf/ZigObject.zig+1-1
......@@ -1271,7 +1271,7 @@ fn updateNavCode(
12711271
12721272 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;
12751275 const required_alignment = switch (pt.navAlignment(nav_index)) {
12761276 .none => target_util.defaultFunctionAlignment(target),
12771277 else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
src/link/Goff.zig+2-2
......@@ -26,7 +26,7 @@ pub fn createEmpty(
2626 emit: Path,
2727 options: link.File.OpenOptions,
2828) !*Goff {
29 const target = comp.root_mod.resolved_target.result;
29 const target = &comp.root_mod.resolved_target.result;
3030 const use_lld = build_options.have_llvm and comp.config.use_lld;
3131 const use_llvm = comp.config.use_llvm;
3232
......@@ -59,7 +59,7 @@ pub fn open(
5959 emit: Path,
6060 options: link.File.OpenOptions,
6161) !*Goff {
62 const target = comp.root_mod.resolved_target.result;
62 const target = &comp.root_mod.resolved_target.result;
6363 assert(target.ofmt == .goff);
6464 return createEmpty(arena, comp, emit, options);
6565}
src/link/Lld.zig+8-8
......@@ -30,7 +30,7 @@ const Coff = struct {
3030 dllmain_crt_startup: bool,
3131 },
3232 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;
3434 const output_mode = comp.config.output_mode;
3535 return .{
3636 .image_base = options.image_base orelse switch (output_mode) {
......@@ -103,7 +103,7 @@ pub const Elf = struct {
103103
104104 fn init(comp: *Compilation, options: link.File.OpenOptions) !Elf {
105105 const PtrWidth = enum { p32, p64 };
106 const target = comp.root_mod.resolved_target.result;
106 const target = &comp.root_mod.resolved_target.result;
107107 const output_mode = comp.config.output_mode;
108108 const is_dyn_lib = output_mode == .Lib and comp.config.link_mode == .dynamic;
109109 const ptr_width: PtrWidth = switch (target.ptrBitWidth()) {
......@@ -202,7 +202,7 @@ pub fn createEmpty(
202202 emit: Cache.Path,
203203 options: link.File.OpenOptions,
204204) !*Lld {
205 const target = comp.root_mod.resolved_target.result;
205 const target = &comp.root_mod.resolved_target.result;
206206 const output_mode = comp.config.output_mode;
207207 const optimize_mode = comp.root_mod.optimize_mode;
208208 const is_native_os = comp.root_mod.resolved_target.is_native_os;
......@@ -342,7 +342,7 @@ fn linkAsArchive(lld: *Lld, arena: Allocator) !void {
342342
343343 const llvm_bindings = @import("../codegen/llvm/bindings.zig");
344344 const llvm = @import("../codegen/llvm.zig");
345 const target = comp.root_mod.resolved_target.result;
345 const target = &comp.root_mod.resolved_target.result;
346346 llvm.initializeLLVMTarget(target.cpu.arch);
347347 const bad = llvm_bindings.WriteArchive(
348348 full_out_path_z,
......@@ -374,7 +374,7 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
374374 const is_dyn_lib = comp.config.link_mode == .dynamic and is_lib;
375375 const is_exe_or_dyn_lib = is_dyn_lib or comp.config.output_mode == .Exe;
376376 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;
378378 const optimize_mode = comp.root_mod.optimize_mode;
379379 const entry_name: ?[]const u8 = switch (coff.entry) {
380380 // 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 {
811811 const is_dyn_lib = link_mode == .dynamic and is_lib;
812812 const is_exe_or_dyn_lib = is_dyn_lib or output_mode == .Exe;
813813 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;
815815 const compiler_rt_path: ?Cache.Path = blk: {
816816 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
817817 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
......@@ -1281,7 +1281,7 @@ fn elfLink(lld: *Lld, arena: Allocator) !void {
12811281 try spawnLld(comp, arena, argv.items);
12821282 }
12831283}
1284fn getLDMOption(target: std.Target) ?[]const u8 {
1284fn getLDMOption(target: *const std.Target) ?[]const u8 {
12851285 // This should only return emulations understood by LLD's parseEmulation().
12861286 return switch (target.cpu.arch) {
12871287 .aarch64 => switch (target.os.tag) {
......@@ -1364,7 +1364,7 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void {
13641364 const shared_memory = comp.config.shared_memory;
13651365 const export_memory = comp.config.export_memory;
13661366 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;
13681368 const base = &lld.base;
13691369 const wasm = &lld.ofmt.wasm;
13701370
src/link/MachO.zig+4-4
......@@ -163,7 +163,7 @@ pub fn createEmpty(
163163 emit: Path,
164164 options: link.File.OpenOptions,
165165) !*MachO {
166 const target = comp.root_mod.resolved_target.result;
166 const target = &comp.root_mod.resolved_target.result;
167167 assert(target.ofmt == .macho);
168168
169169 const gpa = comp.gpa;
......@@ -3545,8 +3545,8 @@ pub fn markDirty(self: *MachO, sect_index: u8) void {
35453545 }
35463546}
35473547
3548pub fn getTarget(self: MachO) std.Target {
3549 return self.base.comp.root_mod.resolved_target.result;
3548pub fn getTarget(self: *const MachO) *const std.Target {
3549 return &self.base.comp.root_mod.resolved_target.result;
35503550}
35513551
35523552/// XNU starting with Big Sur running on arm64 is caching inodes of running binaries.
......@@ -4233,7 +4233,7 @@ pub const Platform = struct {
42334233 }
42344234 }
42354235
4236 pub fn fromTarget(target: std.Target) Platform {
4236 pub fn fromTarget(target: *const std.Target) Platform {
42374237 return .{
42384238 .os_tag = target.os.tag,
42394239 .abi = target.abi,
src/link/MachO/ZigObject.zig+1-1
......@@ -948,7 +948,7 @@ fn updateNavCode(
948948
949949 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;
952952 const required_alignment = switch (pt.navAlignment(nav_index)) {
953953 .none => target_util.defaultFunctionAlignment(target),
954954 else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
src/link/Plan9.zig+5-5
......@@ -184,7 +184,7 @@ pub const Atom = struct {
184184
185185 // asserts that self.got_index != null
186186 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;
188188 const ptr_bytes = @divExact(target.ptrBitWidth(), 8);
189189 const got_addr = plan9.bases.data;
190190 const got_index = self.got_index.?;
......@@ -278,7 +278,7 @@ pub fn createEmpty(
278278 emit: Path,
279279 options: link.File.OpenOptions,
280280) !*Plan9 {
281 const target = comp.root_mod.resolved_target.result;
281 const target = &comp.root_mod.resolved_target.result;
282282 const gpa = comp.gpa;
283283 const optimize_mode = comp.root_mod.optimize_mode;
284284 const output_mode = comp.config.output_mode;
......@@ -394,7 +394,7 @@ pub fn updateFunc(
394394
395395 const zcu = pt.zcu;
396396 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;
398398 const func = zcu.funcInfo(func_index);
399399
400400 const atom_idx = try self.seeNav(pt, func.owner_nav);
......@@ -583,7 +583,7 @@ pub fn flush(
583583 const comp = self.base.comp;
584584 const diags = &comp.link_diags;
585585 const gpa = comp.gpa;
586 const target = comp.root_mod.resolved_target.result;
586 const target = &comp.root_mod.resolved_target.result;
587587
588588 switch (comp.config.output_mode) {
589589 .Exe => {},
......@@ -1153,7 +1153,7 @@ pub fn open(
11531153 emit: Path,
11541154 options: link.File.OpenOptions,
11551155) !*Plan9 {
1156 const target = comp.root_mod.resolved_target.result;
1156 const target = &comp.root_mod.resolved_target.result;
11571157 const use_lld = build_options.have_llvm and comp.config.use_lld;
11581158 const use_llvm = comp.config.use_llvm;
11591159
src/link/SpirV.zig+1-1
......@@ -58,7 +58,7 @@ pub fn createEmpty(
5858 options: link.File.OpenOptions,
5959) !*SpirV {
6060 const gpa = comp.gpa;
61 const target = comp.root_mod.resolved_target.result;
61 const target = &comp.root_mod.resolved_target.result;
6262
6363 assert(!comp.config.use_lld); // Caught by Compilation.Config.resolve
6464 assert(!comp.config.use_llvm); // Caught by Compilation.Config.resolve
src/link/Wasm.zig+1-1
......@@ -2943,7 +2943,7 @@ pub fn createEmpty(
29432943 emit: Path,
29442944 options: link.File.OpenOptions,
29452945) !*Wasm {
2946 const target = comp.root_mod.resolved_target.result;
2946 const target = &comp.root_mod.resolved_target.result;
29472947 assert(target.ofmt == .wasm);
29482948
29492949 const use_llvm = comp.config.use_llvm;
src/link/Xcoff.zig+2-2
......@@ -26,7 +26,7 @@ pub fn createEmpty(
2626 emit: Path,
2727 options: link.File.OpenOptions,
2828) !*Xcoff {
29 const target = comp.root_mod.resolved_target.result;
29 const target = &comp.root_mod.resolved_target.result;
3030 const use_lld = build_options.have_llvm and comp.config.use_lld;
3131 const use_llvm = comp.config.use_llvm;
3232
......@@ -59,7 +59,7 @@ pub fn open(
5959 emit: Path,
6060 options: link.File.OpenOptions,
6161) !*Xcoff {
62 const target = comp.root_mod.resolved_target.result;
62 const target = &comp.root_mod.resolved_target.result;
6363 assert(target.ofmt == .xcoff);
6464 return createEmpty(arena, comp, emit, options);
6565}
src/main.zig+7-7
......@@ -340,7 +340,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
340340 dev.check(.targets_command);
341341 const host = std.zig.resolveTargetQueryOrFatal(.{});
342342 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);
344344 } else if (mem.eql(u8, cmd, "version")) {
345345 dev.check(.version_command);
346346 try std.io.getStdOut().writeAll(build_options.version ++ "\n");
......@@ -3086,7 +3086,7 @@ fn buildOutputType(
30863086 else => main_mod,
30873087 };
30883088
3089 const target = main_mod.resolved_target.result;
3089 const target = &main_mod.resolved_target.result;
30903090
30913091 if (target.cpu.arch == .arc or target.cpu.arch.isNvptx()) {
30923092 if (emit_bin != .no and create_module.resolved_options.use_llvm) {
......@@ -3655,7 +3655,7 @@ fn buildOutputType(
36553655 test_exec_args.items,
36563656 self_exe_path,
36573657 arg_mode,
3658 &target,
3658 target,
36593659 &comp_destroyed,
36603660 all_args,
36613661 runtime_args_start,
......@@ -3800,12 +3800,12 @@ fn createModule(
38003800 // This block is for initializing the fields of
38013801 // `Compilation.Config.Options` that require knowledge of the
38023802 // target (which was just now resolved for the root module above).
3803 const resolved_target = cli_mod.inherited.resolved_target.?;
3804 create_module.opts.resolved_target = resolved_target;
3803 const resolved_target = &cli_mod.inherited.resolved_target.?;
3804 create_module.opts.resolved_target = resolved_target.*;
38053805 create_module.opts.root_optimize_mode = cli_mod.inherited.optimize_mode;
38063806 create_module.opts.root_strip = cli_mod.inherited.strip;
38073807 create_module.opts.root_error_tracing = cli_mod.inherited.error_tracing;
3808 const target = resolved_target.result;
3808 const target = &resolved_target.result;
38093809
38103810 // First, remove libc, libc++, and compiler_rt libraries from the system libraries list.
38113811 // We need to know whether the set of system libraries contains anything besides these
......@@ -6482,7 +6482,7 @@ fn warnAboutForeignBinaries(
64826482 const host_query: std.Target.Query = .{};
64836483 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 })) {
64866486 .native => return,
64876487 .rosetta => {
64886488 const host_name = try host_target.zigTriple(arena);
src/print_targets.zig+1-1
......@@ -16,7 +16,7 @@ pub fn cmdTargets(
1616 args: []const []const u8,
1717 /// Output stream
1818 stdout: anytype,
19 native_target: Target,
19 native_target: *const Target,
2020) !void {
2121 _ = args;
2222 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {
src/target.zig+45-42
......@@ -9,7 +9,7 @@ const Feature = @import("Zcu.zig").Feature;
99
1010pub const default_stack_protector_buffer_size = 4;
1111
12pub fn cannotDynamicLink(target: std.Target) bool {
12pub fn cannotDynamicLink(target: *const std.Target) bool {
1313 return switch (target.os.tag) {
1414 .freestanding => true,
1515 else => target.cpu.arch.isSpirV(),
......@@ -19,15 +19,15 @@ pub fn cannotDynamicLink(target: std.Target) bool {
1919/// On Darwin, we always link libSystem which contains libc.
2020/// Similarly on FreeBSD and NetBSD we always link system libc
2121/// since this is the stable syscall interface.
22pub fn osRequiresLibC(target: std.Target) bool {
22pub fn osRequiresLibC(target: *const std.Target) bool {
2323 return target.os.requiresLibC();
2424}
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 {
2727 return target.isGnuLibC() and link_mode == .static;
2828}
2929
30pub fn libCxxNeedsLibUnwind(target: std.Target) bool {
30pub fn libCxxNeedsLibUnwind(target: *const std.Target) bool {
3131 return switch (target.os.tag) {
3232 .macos,
3333 .ios,
......@@ -44,14 +44,14 @@ pub fn libCxxNeedsLibUnwind(target: std.Target) bool {
4444}
4545
4646/// 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 {
4848 return target.abi.isAndroid() or
4949 target.os.tag == .windows or target.os.tag == .uefi or
5050 osRequiresLibC(target) or
5151 (linking_libc and target.isGnuLibC());
5252}
5353
54pub fn picLevel(target: std.Target) u32 {
54pub fn picLevel(target: *const std.Target) u32 {
5555 // MIPS always uses PIC level 1; other platforms vary in their default PIC levels, but they
5656 // support both level 1 and 2, in which case we prefer 2.
5757 return if (target.cpu.arch.isMIPS()) 1 else 2;
......@@ -59,7 +59,7 @@ pub fn picLevel(target: std.Target) u32 {
5959
6060/// This is not whether the target supports Position Independent Code, but whether the -fPIC
6161/// C compiler argument is valid to Clang.
62pub fn supports_fpic(target: std.Target) bool {
62pub fn supports_fpic(target: *const std.Target) bool {
6363 return switch (target.os.tag) {
6464 .windows,
6565 .uefi,
......@@ -68,12 +68,12 @@ pub fn supports_fpic(target: std.Target) bool {
6868 };
6969}
7070
71pub fn alwaysSingleThreaded(target: std.Target) bool {
71pub fn alwaysSingleThreaded(target: *const std.Target) bool {
7272 _ = target;
7373 return false;
7474}
7575
76pub fn defaultSingleThreaded(target: std.Target) bool {
76pub fn defaultSingleThreaded(target: *const std.Target) bool {
7777 switch (target.cpu.arch) {
7878 .wasm32, .wasm64 => return true,
7979 else => {},
......@@ -85,7 +85,7 @@ pub fn defaultSingleThreaded(target: std.Target) bool {
8585 return false;
8686}
8787
88pub fn hasValgrindSupport(target: std.Target, backend: std.builtin.CompilerBackend) bool {
88pub fn hasValgrindSupport(target: *const std.Target, backend: std.builtin.CompilerBackend) bool {
8989 // We can't currently output the necessary Valgrind client request assembly when using the C
9090 // backend and compiling with an MSVC-like compiler.
9191 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
133133/// The set of targets that LLVM has non-experimental support for.
134134/// Used to select between LLVM backend and self-hosted backend when compiling in
135135/// 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 {
137137 switch (ofmt) {
138138 // LLVM does not support these object formats:
139139 .c,
......@@ -221,7 +221,7 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool {
221221/// Used to select between LLVM backend and self-hosted backend when compiling in
222222/// debug mode. A given target should only return true here if it is passing greater
223223/// 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 {
225225 if (target.cpu.arch.isSpirV()) return true;
226226 if (target.cpu.arch == .x86_64 and target.ptrBitWidth() == 64) return switch (target.ofmt) {
227227 .elf, .macho => true,
......@@ -230,12 +230,12 @@ pub fn selfHostedBackendIsAsRobustAsLlvm(target: std.Target) bool {
230230 return false;
231231}
232232
233pub fn supportsStackProbing(target: std.Target) bool {
233pub fn supportsStackProbing(target: *const std.Target) bool {
234234 return target.os.tag != .windows and target.os.tag != .uefi and
235235 (target.cpu.arch == .x86 or target.cpu.arch == .x86_64);
236236}
237237
238pub fn supportsStackProtector(target: std.Target, backend: std.builtin.CompilerBackend) bool {
238pub fn supportsStackProtector(target: *const std.Target, backend: std.builtin.CompilerBackend) bool {
239239 switch (target.os.tag) {
240240 .plan9 => return false,
241241 else => {},
......@@ -250,20 +250,20 @@ pub fn supportsStackProtector(target: std.Target, backend: std.builtin.CompilerB
250250 };
251251}
252252
253pub fn clangSupportsStackProtector(target: std.Target) bool {
253pub fn clangSupportsStackProtector(target: *const std.Target) bool {
254254 return switch (target.cpu.arch) {
255255 .spirv, .spirv32, .spirv64 => return false,
256256 else => true,
257257 };
258258}
259259
260pub fn libcProvidesStackProtector(target: std.Target) bool {
260pub fn libcProvidesStackProtector(target: *const std.Target) bool {
261261 return !target.isMinGW() and target.os.tag != .wasi and !target.cpu.arch.isSpirV();
262262}
263263
264264/// Returns true if `@returnAddress()` is supported by the target and has a
265265/// 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 {
267267 return switch (target.cpu.arch) {
268268 // Emscripten currently implements `emscripten_return_address()` by calling
269269 // out into JavaScript and parsing a stack trace, which introduces significant
......@@ -299,7 +299,7 @@ pub fn classifyCompilerRtLibName(name: []const u8) CompilerRtClassification {
299299 return .none;
300300}
301301
302pub fn hasDebugInfo(target: std.Target) bool {
302pub fn hasDebugInfo(target: *const std.Target) bool {
303303 return switch (target.cpu.arch) {
304304 // TODO: We should make newer PTX versions depend on older ones so we'd just check `ptx75`.
305305 .nvptx, .nvptx64 => target.cpu.hasAny(.nvptx, &.{
......@@ -321,7 +321,7 @@ pub fn hasDebugInfo(target: std.Target) bool {
321321 };
322322}
323323
324pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.OptimizeMode {
324pub fn defaultCompilerRtOptimizeMode(target: *const std.Target) std.builtin.OptimizeMode {
325325 if (target.cpu.arch.isWasm() and target.os.tag == .freestanding) {
326326 return .ReleaseSmall;
327327 } else {
......@@ -329,7 +329,7 @@ pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.OptimizeMod
329329 }
330330}
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 {
333333 switch (target.os.tag) {
334334 .plan9 => return false,
335335 else => {},
......@@ -342,12 +342,15 @@ pub fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool, have_llvm: bool
342342 }
343343 return switch (zigBackend(target, use_llvm)) {
344344 .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 },
346349 else => have_llvm,
347350 };
348351}
349352
350pub fn canBuildLibUbsanRt(target: std.Target) bool {
353pub fn canBuildLibUbsanRt(target: *const std.Target) bool {
351354 switch (target.cpu.arch) {
352355 .spirv, .spirv32, .spirv64 => return false,
353356 // Remove this once https://github.com/ziglang/zig/issues/23715 is fixed
......@@ -356,7 +359,7 @@ pub fn canBuildLibUbsanRt(target: std.Target) bool {
356359 }
357360}
358361
359pub fn hasRedZone(target: std.Target) bool {
362pub fn hasRedZone(target: *const std.Target) bool {
360363 return switch (target.cpu.arch) {
361364 .aarch64,
362365 .aarch64_be,
......@@ -372,7 +375,7 @@ pub fn hasRedZone(target: std.Target) bool {
372375 };
373376}
374377
375pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
378pub fn libcFullLinkFlags(target: *const std.Target) []const []const u8 {
376379 // The linking order of these is significant and should match the order other
377380 // c compilers such as gcc or clang use.
378381 const result: []const []const u8 = switch (target.os.tag) {
......@@ -389,14 +392,14 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
389392 return result;
390393}
391394
392pub fn clangMightShellOutForAssembly(target: std.Target) bool {
395pub fn clangMightShellOutForAssembly(target: *const std.Target) bool {
393396 // Clang defaults to using the system assembler in some cases.
394397 return target.cpu.arch.isNvptx() or target.cpu.arch == .xcore;
395398}
396399
397400/// Each backend architecture in Clang has a different codepath which may or may not
398401/// support an -mcpu flag.
399pub fn clangAssemblerSupportsMcpuArg(target: std.Target) bool {
402pub fn clangAssemblerSupportsMcpuArg(target: *const std.Target) bool {
400403 return switch (target.cpu.arch) {
401404 .arm, .armeb, .thumb, .thumbeb => true,
402405 else => false,
......@@ -405,7 +408,7 @@ pub fn clangAssemblerSupportsMcpuArg(target: std.Target) bool {
405408
406409/// Some experimental or poorly-maintained LLVM targets do not properly process CPU models in their
407410/// 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 {
409412 return switch (target.cpu.arch) {
410413 .arc,
411414 .msp430,
......@@ -417,7 +420,7 @@ pub fn clangSupportsTargetCpuArg(target: std.Target) bool {
417420 };
418421}
419422
420pub fn clangSupportsFloatAbiArg(target: std.Target) bool {
423pub fn clangSupportsFloatAbiArg(target: *const std.Target) bool {
421424 return switch (target.cpu.arch) {
422425 .arm,
423426 .armeb,
......@@ -442,7 +445,7 @@ pub fn clangSupportsFloatAbiArg(target: std.Target) bool {
442445 };
443446}
444447
445pub fn clangSupportsNoImplicitFloatArg(target: std.Target) bool {
448pub fn clangSupportsNoImplicitFloatArg(target: *const std.Target) bool {
446449 return switch (target.cpu.arch) {
447450 .aarch64,
448451 .aarch64_be,
......@@ -459,7 +462,7 @@ pub fn clangSupportsNoImplicitFloatArg(target: std.Target) bool {
459462 };
460463}
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 {
463466 if (target.os.tag == .windows) {
464467 // The old 32-bit x86 variant of SEH doesn't use tables.
465468 return if (target.cpu.arch != .x86) .@"async" else .none;
......@@ -472,7 +475,7 @@ pub fn defaultUnwindTables(target: std.Target, libunwind: bool, libtsan: bool) s
472475}
473476
474477pub fn defaultAddressSpace(
475 target: std.Target,
478 target: *const std.Target,
476479 context: enum {
477480 /// Query the default address space for global constant values.
478481 global_constant,
......@@ -492,7 +495,7 @@ pub fn defaultAddressSpace(
492495
493496/// Returns true if pointers in `from` can be converted to a pointer in `to`.
494497pub fn addrSpaceCastIsValid(
495 target: std.Target,
498 target: *const std.Target,
496499 from: AddressSpace,
497500 to: AddressSpace,
498501) bool {
......@@ -512,7 +515,7 @@ pub fn addrSpaceCastIsValid(
512515/// a number of restrictions on usage of such pointers. For example, a logical pointer may not be
513516/// part of a merge (result of a branch) and may not be stored in memory at all. This function returns
514517/// 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 {
516519 if (target.os.tag != .vulkan) return false;
517520
518521 return switch (as) {
......@@ -537,7 +540,7 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {
537540 };
538541}
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 {
541544 if (target.cpu.arch != .amdgcn) return false;
542545
543546 const sramecc_only = &[_]*const std.Target.Cpu.Model{
......@@ -585,7 +588,7 @@ pub fn isDynamicAMDGCNFeature(target: std.Target, feature: std.Target.Cpu.Featur
585588 return false;
586589}
587590
588pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
591pub fn llvmMachineAbi(target: *const std.Target) ?[:0]const u8 {
589592 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it
590593 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc
591594 // 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 {
642645
643646/// This function returns 1 if function alignment is not observable or settable. Note that this
644647/// 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 {
646649 // Overrides of the minimum for performance.
647650 return switch (target.cpu.arch) {
648651 .csky,
......@@ -669,7 +672,7 @@ pub fn defaultFunctionAlignment(target: std.Target) Alignment {
669672}
670673
671674/// 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 {
673676 return switch (target.cpu.arch) {
674677 .riscv32,
675678 .riscv64,
......@@ -712,7 +715,7 @@ pub fn minFunctionAlignment(target: std.Target) Alignment {
712715 };
713716}
714717
715pub fn supportsFunctionAlignment(target: std.Target) bool {
718pub fn supportsFunctionAlignment(target: *const std.Target) bool {
716719 return switch (target.cpu.arch) {
717720 .nvptx,
718721 .nvptx64,
......@@ -726,7 +729,7 @@ pub fn supportsFunctionAlignment(target: std.Target) bool {
726729 };
727730}
728731
729pub fn functionPointerMask(target: std.Target) ?u64 {
732pub fn functionPointerMask(target: *const std.Target) ?u64 {
730733 // 32-bit Arm uses the LSB to mean that the target function contains Thumb code.
731734 // MIPS uses the LSB to mean that the target function contains MIPS16/microMIPS code.
732735 return if (target.cpu.arch.isArm() or target.cpu.arch.isMIPS32())
......@@ -737,7 +740,7 @@ pub fn functionPointerMask(target: std.Target) ?u64 {
737740 null;
738741}
739742
740pub fn supportsTailCall(target: std.Target, backend: std.builtin.CompilerBackend) bool {
743pub fn supportsTailCall(target: *const std.Target, backend: std.builtin.CompilerBackend) bool {
741744 switch (backend) {
742745 .stage2_llvm => return @import("codegen/llvm.zig").supportsTailCall(target),
743746 .stage2_c => return true,
......@@ -745,7 +748,7 @@ pub fn supportsTailCall(target: std.Target, backend: std.builtin.CompilerBackend
745748 }
746749}
747750
748pub fn supportsThreads(target: std.Target, backend: std.builtin.CompilerBackend) bool {
751pub fn supportsThreads(target: *const std.Target, backend: std.builtin.CompilerBackend) bool {
749752 return switch (backend) {
750753 .stage2_powerpc => true,
751754 .stage2_x86_64 => target.ofmt == .macho or target.ofmt == .elf,
......@@ -804,7 +807,7 @@ pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool {
804807 };
805808}
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 {
808811 if (use_llvm) return .stage2_llvm;
809812 if (target.ofmt == .c) return .stage2_c;
810813 return switch (target.cpu.arch) {
test/link/macho.zig+1-1
......@@ -864,7 +864,7 @@ fn testLayout(b: *Build, opts: Options) *Step {
864864fn testLinkDirectlyCppTbd(b: *Build, opts: Options) *Step {
865865 const test_step = addTestStep(b, "link-directly-cpp-tbd", opts);
866866
867 const sdk = std.zig.system.darwin.getSdk(b.allocator, opts.target.result) orelse
867 const sdk = std.zig.system.darwin.getSdk(b.allocator, &opts.target.result) orelse
868868 @panic("macOS SDK is required to run the test");
869869
870870 const exe = addExecutable(b, opts, .{
test/src/Cases.zig+2-2
......@@ -433,7 +433,7 @@ fn addFromDirInner(
433433 // Cross-product to get all possible test combinations
434434 for (targets) |target_query| {
435435 const resolved_target = b.resolveTargetQuery(target_query);
436 const target = resolved_target.result;
436 const target = &resolved_target.result;
437437 for (backends) |backend| {
438438 if (backend == .stage2 and
439439 target.cpu.arch != .wasm32 and target.cpu.arch != .x86_64 and target.cpu.arch != .spirv64)
......@@ -708,7 +708,7 @@ pub fn lowerToBuildSteps(
708708 },
709709 .Execution => |expected_stdout| no_exec: {
710710 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) {
712712 // We wouldn't be able to run the compiled C code.
713713 break :no_exec;
714714 }
test/src/Debugger.zig+4-4
......@@ -21,7 +21,7 @@ pub const Target = struct {
2121 test_name_suffix: []const u8,
2222};
2323
24pub fn addTestsForTarget(db: *Debugger, target: Target) void {
24pub fn addTestsForTarget(db: *Debugger, target: *const Target) void {
2525 db.addLldbTest(
2626 "basic",
2727 target,
......@@ -2376,7 +2376,7 @@ const File = struct { import: ?[]const u8 = null, path: []const u8, source: []co
23762376fn addGdbTest(
23772377 db: *Debugger,
23782378 name: []const u8,
2379 target: Target,
2379 target: *const Target,
23802380 files: []const File,
23812381 commands: []const u8,
23822382 expected_output: []const []const u8,
......@@ -2402,7 +2402,7 @@ fn addGdbTest(
24022402fn addLldbTest(
24032403 db: *Debugger,
24042404 name: []const u8,
2405 target: Target,
2405 target: *const Target,
24062406 files: []const File,
24072407 commands: []const u8,
24082408 expected_output: []const []const u8,
......@@ -2433,7 +2433,7 @@ const success = 99;
24332433fn addTest(
24342434 db: *Debugger,
24352435 name: []const u8,
2436 target: Target,
2436 target: *const Target,
24372437 files: []const File,
24382438 db_argv1: []const []const u8,
24392439 db_commands: []const u8,
test/src/StackTrace.zig+2-2
......@@ -22,7 +22,7 @@ const Config = struct {
2222
2323pub fn addCase(self: *StackTrace, config: Config) void {
2424 self.addCaseInner(config, true);
25 if (shouldTestNonLlvm(self.b.graph.host.result)) {
25 if (shouldTestNonLlvm(&self.b.graph.host.result)) {
2626 self.addCaseInner(config, false);
2727 }
2828}
......@@ -41,7 +41,7 @@ fn addCaseInner(self: *StackTrace, config: Config, use_llvm: bool) void {
4141 self.addExpect(config.name, config.source, .ReleaseSafe, use_llvm, per_mode);
4242}
4343
44fn shouldTestNonLlvm(target: std.Target) bool {
44fn shouldTestNonLlvm(target: *const std.Target) bool {
4545 return switch (target.cpu.arch) {
4646 .x86_64 => switch (target.ofmt) {
4747 .elf => true,
test/standalone/ios/build.zig+1-1
......@@ -12,7 +12,7 @@ pub fn build(b: *std.Build) void {
1212 .cpu_arch = .aarch64,
1313 .os_tag = .ios,
1414 });
15 const sdk = std.zig.system.darwin.getSdk(b.allocator, target.result) orelse
15 const sdk = std.zig.system.darwin.getSdk(b.allocator, &target.result) orelse
1616 @panic("no iOS SDK found");
1717 b.sysroot = sdk;
1818
test/tests.zig+4-4
......@@ -2311,7 +2311,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
23112311
23122312 const resolved_target = b.resolveTargetQuery(test_target.target);
23132313 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
23162316 if (options.test_target_filters.len > 0) {
23172317 for (options.test_target_filters) |filter| {
......@@ -2557,7 +2557,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
25572557
25582558 const resolved_target = b.resolveTargetQuery(c_abi_target.target);
25592559 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
25622562 if (options.test_target_filters.len > 0) {
25632563 for (options.test_target_filters) |filter| {
......@@ -2659,7 +2659,7 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step
26592659 .options = options,
26602660 .root_step = step,
26612661 };
2662 context.addTestsForTarget(.{
2662 context.addTestsForTarget(&.{
26632663 .resolved = b.resolveTargetQuery(.{
26642664 .cpu_arch = .x86_64,
26652665 .os_tag = .linux,
......@@ -2668,7 +2668,7 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step
26682668 .pic = false,
26692669 .test_name_suffix = "x86_64-linux",
26702670 });
2671 context.addTestsForTarget(.{
2671 context.addTestsForTarget(&.{
26722672 .resolved = b.resolveTargetQuery(.{
26732673 .cpu_arch = .x86_64,
26742674 .os_tag = .linux,
tools/doctest.zig+2-2
......@@ -317,7 +317,7 @@ fn printOutput(
317317 const target = try std.zig.system.resolveTargetQuery(
318318 target_query,
319319 );
320 switch (getExternalExecutor(host, &target, .{
320 switch (getExternalExecutor(&host, &target, .{
321321 .link_libc = code.link_libc,
322322 })) {
323323 .native => {},
......@@ -538,7 +538,7 @@ fn printOutput(
538538 .lib => {
539539 const bin_basename = try std.zig.binNameAlloc(arena, .{
540540 .root_name = code_name,
541 .target = builtin.target,
541 .target = &builtin.target,
542542 .output_mode = .Lib,
543543 });
544544
tools/incr-check.zig+2-2
......@@ -316,7 +316,7 @@ const Eval = struct {
316316
317317 const bin_name = try std.zig.EmitArtifact.bin.cacheName(arena, .{
318318 .root_name = "root", // corresponds to the module name "root"
319 .target = eval.target.resolved,
319 .target = &eval.target.resolved,
320320 .output_mode = .Exe,
321321 });
322322 const bin_path = try std.fs.path.join(arena, &.{ result_dir, bin_name });
......@@ -444,7 +444,7 @@ const Eval = struct {
444444
445445 var argv_buf: [2][]const u8 = undefined;
446446 const argv: []const []const u8, const is_foreign: bool = switch (std.zig.system.getExternalExecutor(
447 eval.host,
447 &eval.host,
448448 &eval.target.resolved,
449449 .{ .link_libc = eval.target.backend == .cbe },
450450 )) {