authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-01 22:57:59+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-12 13:55:40+01:00
log5ab307cf47b1f0418d9ed4ab56df6fb798305c20
treee6efda29764d1fdaa92c40cce951f13c394facba
parent9eb400ef19391261a3b61129d8665602c89959c5
signaturelock-open Commit is signed but in an unrecognized format.

compiler: get most backends compiling again

As of this commit, every backend other than self-hosted Wasm and self-hosted SPIR-V compiles and (at least somewhat) functions again. Those two backends are currently disabled with panics. Note that `Zcu.Feature.separate_thread` is *not* enabled for the fixed backends. Avoiding linker references from codegen is a non-trivial task, and can be done after this branch.

25 files changed, 402 insertions(+), 251 deletions(-)

src/Compilation.zig+5-3
......@@ -4550,8 +4550,6 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
45504550 air.deinit(gpa);
45514551 return;
45524552 }
4553 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
4554 defer pt.deactivate();
45554553 const shared_mir = try gpa.create(link.ZcuTask.LinkFunc.SharedMir);
45564554 shared_mir.* = .{
45574555 .status = .init(.pending),
......@@ -4567,7 +4565,11 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
45674565 } });
45684566 } else {
45694567 const emit_needs_air = !zcu.backendSupportsFeature(.separate_thread);
4570 pt.runCodegen(func.func, &air, shared_mir);
4568 {
4569 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
4570 defer pt.deactivate();
4571 pt.runCodegen(func.func, &air, shared_mir);
4572 }
45714573 assert(shared_mir.status.load(.monotonic) != .pending);
45724574 comp.dispatchZcuLinkTask(tid, .{ .link_func = .{
45734575 .func = func.func,
src/Zcu/PerThread.zig+22-6
......@@ -4376,26 +4376,40 @@ pub fn addDependency(pt: Zcu.PerThread, unit: AnalUnit, dependee: InternPool.Dep
43764376/// other code. This function is currently run either on the main thread, or on a separate
43774377/// codegen thread, depending on whether the backend supports `Zcu.Feature.separate_thread`.
43784378pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air, out: *@import("../link.zig").ZcuTask.LinkFunc.SharedMir) void {
4379 const zcu = pt.zcu;
43794380 if (runCodegenInner(pt, func_index, air)) |mir| {
43804381 out.value = mir;
43814382 out.status.store(.ready, .release);
43824383 } else |err| switch (err) {
43834384 error.OutOfMemory => {
4384 pt.zcu.comp.setAllocFailure();
4385 zcu.comp.setAllocFailure();
43854386 out.status.store(.failed, .monotonic);
43864387 },
43874388 error.CodegenFail => {
4388 pt.zcu.assertCodegenFailed(pt.zcu.funcInfo(func_index).owner_nav);
4389 zcu.assertCodegenFailed(zcu.funcInfo(func_index).owner_nav);
43894390 out.status.store(.failed, .monotonic);
43904391 },
43914392 error.NoLinkFile => {
4392 assert(pt.zcu.comp.bin_file == null);
4393 assert(zcu.comp.bin_file == null);
4394 out.status.store(.failed, .monotonic);
4395 },
4396 error.BackendDoesNotProduceMir => {
4397 const backend = target_util.zigBackend(zcu.root_mod.resolved_target.result, zcu.comp.config.use_llvm);
4398 switch (backend) {
4399 else => unreachable, // assertion failure
4400 .stage2_llvm => {},
4401 }
43934402 out.status.store(.failed, .monotonic);
43944403 },
43954404 }
4396 pt.zcu.comp.link_task_queue.mirReady(pt.zcu.comp, out);
4405 zcu.comp.link_task_queue.mirReady(zcu.comp, out);
43974406}
4398fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) error{ OutOfMemory, CodegenFail, NoLinkFile }!codegen.AnyMir {
4407fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) error{
4408 OutOfMemory,
4409 CodegenFail,
4410 NoLinkFile,
4411 BackendDoesNotProduceMir,
4412}!codegen.AnyMir {
43994413 const zcu = pt.zcu;
44004414 const gpa = zcu.gpa;
44014415 const ip = &zcu.intern_pool;
......@@ -4441,7 +4455,9 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
44414455 // "emit" step because LLVM does not support incremental linking. Our linker (LLD or self-hosted)
44424456 // will just see the ZCU object file which LLVM ultimately emits.
44434457 if (zcu.llvm_object) |llvm_object| {
4444 return llvm_object.updateFunc(pt, func_index, air, &liveness);
4458 assert(pt.tid == .main); // LLVM has a lot of shared state
4459 try llvm_object.updateFunc(pt, func_index, air, &liveness);
4460 return error.BackendDoesNotProduceMir;
44454461 }
44464462
44474463 const lf = comp.bin_file orelse return error.NoLinkFile;
src/arch/aarch64/CodeGen.zig+16-30
......@@ -49,7 +49,6 @@ pt: Zcu.PerThread,
4949air: Air,
5050liveness: Air.Liveness,
5151bin_file: *link.File,
52debug_output: link.File.DebugInfoOutput,
5352target: *const std.Target,
5453func_index: InternPool.Index,
5554owner_nav: InternPool.Nav.Index,
......@@ -185,6 +184,9 @@ const DbgInfoReloc = struct {
185184 }
186185
187186 fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) !void {
187 // TODO: Add a pseudo-instruction or something to defer this work until Emit.
188 // We aren't allowed to interact with linker state here.
189 if (true) return;
188190 switch (function.debug_output) {
189191 .dwarf => |dw| {
190192 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {
......@@ -213,6 +215,9 @@ const DbgInfoReloc = struct {
213215 }
214216
215217 fn genVarDbgInfo(reloc: DbgInfoReloc, function: Self) !void {
218 // TODO: Add a pseudo-instruction or something to defer this work until Emit.
219 // We aren't allowed to interact with linker state here.
220 if (true) return;
216221 switch (function.debug_output) {
217222 .dwarf => |dwarf| {
218223 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {
......@@ -326,11 +331,9 @@ pub fn generate(
326331 pt: Zcu.PerThread,
327332 src_loc: Zcu.LazySrcLoc,
328333 func_index: InternPool.Index,
329 air: Air,
330 liveness: Air.Liveness,
331 code: *std.ArrayListUnmanaged(u8),
332 debug_output: link.File.DebugInfoOutput,
333) CodeGenError!void {
334 air: *const Air,
335 liveness: *const Air.Liveness,
336) CodeGenError!Mir {
334337 const zcu = pt.zcu;
335338 const gpa = zcu.gpa;
336339 const func = zcu.funcInfo(func_index);
......@@ -349,9 +352,8 @@ pub fn generate(
349352 var function: Self = .{
350353 .gpa = gpa,
351354 .pt = pt,
352 .air = air,
353 .liveness = liveness,
354 .debug_output = debug_output,
355 .air = air.*,
356 .liveness = liveness.*,
355357 .target = target,
356358 .bin_file = lf,
357359 .func_index = func_index,
......@@ -395,29 +397,13 @@ pub fn generate(
395397
396398 var mir: Mir = .{
397399 .instructions = function.mir_instructions.toOwnedSlice(),
398 .extra = try function.mir_extra.toOwnedSlice(gpa),
399 };
400 defer mir.deinit(gpa);
401
402 var emit: Emit = .{
403 .mir = mir,
404 .bin_file = lf,
405 .debug_output = debug_output,
406 .target = target,
407 .src_loc = src_loc,
408 .code = code,
409 .prev_di_pc = 0,
410 .prev_di_line = func.lbrace_line,
411 .prev_di_column = func.lbrace_column,
412 .stack_size = function.max_end_stack,
400 .extra = &.{}, // fallible, so assign after errdefer
401 .max_end_stack = function.max_end_stack,
413402 .saved_regs_stack_space = function.saved_regs_stack_space,
414403 };
415 defer emit.deinit();
416
417 emit.emitMir() catch |err| switch (err) {
418 error.EmitFail => return function.failMsg(emit.err_msg.?),
419 else => |e| return e,
420 };
404 errdefer mir.deinit(gpa);
405 mir.extra = try function.mir_extra.toOwnedSlice(gpa);
406 return mir;
421407}
422408
423409fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
src/arch/aarch64/Mir.zig+43
......@@ -13,6 +13,14 @@ const assert = std.debug.assert;
1313
1414const bits = @import("bits.zig");
1515const Register = bits.Register;
16const InternPool = @import("../../InternPool.zig");
17const Emit = @import("Emit.zig");
18const codegen = @import("../../codegen.zig");
19const link = @import("../../link.zig");
20const Zcu = @import("../../Zcu.zig");
21
22max_end_stack: u32,
23saved_regs_stack_space: u32,
1624
1725instructions: std.MultiArrayList(Inst).Slice,
1826/// The meaning of this data is determined by `Inst.Tag` value.
......@@ -498,6 +506,41 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
498506 mir.* = undefined;
499507}
500508
509pub fn emit(
510 mir: Mir,
511 lf: *link.File,
512 pt: Zcu.PerThread,
513 src_loc: Zcu.LazySrcLoc,
514 func_index: InternPool.Index,
515 code: *std.ArrayListUnmanaged(u8),
516 debug_output: link.File.DebugInfoOutput,
517 air: *const @import("../../Air.zig"),
518) codegen.CodeGenError!void {
519 _ = air; // using this would be a bug
520 const zcu = pt.zcu;
521 const func = zcu.funcInfo(func_index);
522 const nav = func.owner_nav;
523 const mod = zcu.navFileScope(nav).mod.?;
524 var e: Emit = .{
525 .mir = mir,
526 .bin_file = lf,
527 .debug_output = debug_output,
528 .target = &mod.resolved_target.result,
529 .src_loc = src_loc,
530 .code = code,
531 .prev_di_pc = 0,
532 .prev_di_line = func.lbrace_line,
533 .prev_di_column = func.lbrace_column,
534 .stack_size = mir.max_end_stack,
535 .saved_regs_stack_space = mir.saved_regs_stack_space,
536 };
537 defer e.deinit();
538 e.emitMir() catch |err| switch (err) {
539 error.EmitFail => return zcu.codegenFailMsg(nav, e.err_msg.?),
540 else => |e1| return e1,
541 };
542}
543
501544/// Returns the requested data, as well as the new index which is at the start of the
502545/// trailers for the object.
503546pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end: usize } {
src/arch/arm/CodeGen.zig+17-31
......@@ -50,7 +50,6 @@ pt: Zcu.PerThread,
5050air: Air,
5151liveness: Air.Liveness,
5252bin_file: *link.File,
53debug_output: link.File.DebugInfoOutput,
5453target: *const std.Target,
5554func_index: InternPool.Index,
5655err_msg: ?*ErrorMsg,
......@@ -264,6 +263,9 @@ const DbgInfoReloc = struct {
264263 }
265264
266265 fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) !void {
266 // TODO: Add a pseudo-instruction or something to defer this work until Emit.
267 // We aren't allowed to interact with linker state here.
268 if (true) return;
267269 switch (function.debug_output) {
268270 .dwarf => |dw| {
269271 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {
......@@ -292,6 +294,9 @@ const DbgInfoReloc = struct {
292294 }
293295
294296 fn genVarDbgInfo(reloc: DbgInfoReloc, function: Self) !void {
297 // TODO: Add a pseudo-instruction or something to defer this work until Emit.
298 // We aren't allowed to interact with linker state here.
299 if (true) return;
295300 switch (function.debug_output) {
296301 .dwarf => |dw| {
297302 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {
......@@ -335,11 +340,9 @@ pub fn generate(
335340 pt: Zcu.PerThread,
336341 src_loc: Zcu.LazySrcLoc,
337342 func_index: InternPool.Index,
338 air: Air,
339 liveness: Air.Liveness,
340 code: *std.ArrayListUnmanaged(u8),
341 debug_output: link.File.DebugInfoOutput,
342) CodeGenError!void {
343 air: *const Air,
344 liveness: *const Air.Liveness,
345) CodeGenError!Mir {
343346 const zcu = pt.zcu;
344347 const gpa = zcu.gpa;
345348 const func = zcu.funcInfo(func_index);
......@@ -358,11 +361,10 @@ pub fn generate(
358361 var function: Self = .{
359362 .gpa = gpa,
360363 .pt = pt,
361 .air = air,
362 .liveness = liveness,
364 .air = air.*,
365 .liveness = liveness.*,
363366 .target = target,
364367 .bin_file = lf,
365 .debug_output = debug_output,
366368 .func_index = func_index,
367369 .err_msg = null,
368370 .args = undefined, // populated after `resolveCallingConventionValues`
......@@ -402,31 +404,15 @@ pub fn generate(
402404 return function.fail("failed to generate debug info: {s}", .{@errorName(err)});
403405 }
404406
405 var mir = Mir{
407 var mir: Mir = .{
406408 .instructions = function.mir_instructions.toOwnedSlice(),
407 .extra = try function.mir_extra.toOwnedSlice(gpa),
408 };
409 defer mir.deinit(gpa);
410
411 var emit = Emit{
412 .mir = mir,
413 .bin_file = lf,
414 .debug_output = debug_output,
415 .target = target,
416 .src_loc = src_loc,
417 .code = code,
418 .prev_di_pc = 0,
419 .prev_di_line = func.lbrace_line,
420 .prev_di_column = func.lbrace_column,
421 .stack_size = function.max_end_stack,
409 .extra = &.{}, // fallible, so assign after errdefer
410 .max_end_stack = function.max_end_stack,
422411 .saved_regs_stack_space = function.saved_regs_stack_space,
423412 };
424 defer emit.deinit();
425
426 emit.emitMir() catch |err| switch (err) {
427 error.EmitFail => return function.failMsg(emit.err_msg.?),
428 else => |e| return e,
429 };
413 errdefer mir.deinit(gpa);
414 mir.extra = try function.mir_extra.toOwnedSlice(gpa);
415 return mir;
430416}
431417
432418fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
src/arch/arm/Mir.zig+43
......@@ -13,6 +13,14 @@ const assert = std.debug.assert;
1313
1414const bits = @import("bits.zig");
1515const Register = bits.Register;
16const InternPool = @import("../../InternPool.zig");
17const Emit = @import("Emit.zig");
18const codegen = @import("../../codegen.zig");
19const link = @import("../../link.zig");
20const Zcu = @import("../../Zcu.zig");
21
22max_end_stack: u32,
23saved_regs_stack_space: u32,
1624
1725instructions: std.MultiArrayList(Inst).Slice,
1826/// The meaning of this data is determined by `Inst.Tag` value.
......@@ -278,6 +286,41 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
278286 mir.* = undefined;
279287}
280288
289pub fn emit(
290 mir: Mir,
291 lf: *link.File,
292 pt: Zcu.PerThread,
293 src_loc: Zcu.LazySrcLoc,
294 func_index: InternPool.Index,
295 code: *std.ArrayListUnmanaged(u8),
296 debug_output: link.File.DebugInfoOutput,
297 air: *const @import("../../Air.zig"),
298) codegen.CodeGenError!void {
299 _ = air; // using this would be a bug
300 const zcu = pt.zcu;
301 const func = zcu.funcInfo(func_index);
302 const nav = func.owner_nav;
303 const mod = zcu.navFileScope(nav).mod.?;
304 var e: Emit = .{
305 .mir = mir,
306 .bin_file = lf,
307 .debug_output = debug_output,
308 .target = &mod.resolved_target.result,
309 .src_loc = src_loc,
310 .code = code,
311 .prev_di_pc = 0,
312 .prev_di_line = func.lbrace_line,
313 .prev_di_column = func.lbrace_column,
314 .stack_size = mir.max_end_stack,
315 .saved_regs_stack_space = mir.saved_regs_stack_space,
316 };
317 defer e.deinit();
318 e.emitMir() catch |err| switch (err) {
319 error.EmitFail => return zcu.codegenFailMsg(nav, e.err_msg.?),
320 else => |e1| return e1,
321 };
322}
323
281324/// Returns the requested data, as well as the new index which is at the start of the
282325/// trailers for the object.
283326pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end: usize } {
src/arch/powerpc/CodeGen.zig+3-7
......@@ -19,19 +19,15 @@ pub fn generate(
1919 pt: Zcu.PerThread,
2020 src_loc: Zcu.LazySrcLoc,
2121 func_index: InternPool.Index,
22 air: Air,
23 liveness: Air.Liveness,
24 code: *std.ArrayListUnmanaged(u8),
25 debug_output: link.File.DebugInfoOutput,
26) codegen.CodeGenError!void {
22 air: *const Air,
23 liveness: *const Air.Liveness,
24) codegen.CodeGenError!noreturn {
2725 _ = bin_file;
2826 _ = pt;
2927 _ = src_loc;
3028 _ = func_index;
3129 _ = air;
3230 _ = liveness;
33 _ = code;
34 _ = debug_output;
3531
3632 unreachable;
3733}
src/arch/riscv64/CodeGen.zig+13-38
......@@ -68,7 +68,6 @@ gpa: Allocator,
6868
6969mod: *Package.Module,
7070target: *const std.Target,
71debug_output: link.File.DebugInfoOutput,
7271args: []MCValue,
7372ret_mcv: InstTracking,
7473fn_type: Type,
......@@ -746,13 +745,10 @@ pub fn generate(
746745 pt: Zcu.PerThread,
747746 src_loc: Zcu.LazySrcLoc,
748747 func_index: InternPool.Index,
749 air: Air,
750 liveness: Air.Liveness,
751 code: *std.ArrayListUnmanaged(u8),
752 debug_output: link.File.DebugInfoOutput,
753) CodeGenError!void {
748 air: *const Air,
749 liveness: *const Air.Liveness,
750) CodeGenError!Mir {
754751 const zcu = pt.zcu;
755 const comp = zcu.comp;
756752 const gpa = zcu.gpa;
757753 const ip = &zcu.intern_pool;
758754 const func = zcu.funcInfo(func_index);
......@@ -769,13 +765,12 @@ pub fn generate(
769765
770766 var function: Func = .{
771767 .gpa = gpa,
772 .air = air,
768 .air = air.*,
773769 .pt = pt,
774770 .mod = mod,
775771 .bin_file = bin_file,
776 .liveness = liveness,
772 .liveness = liveness.*,
777773 .target = &mod.resolved_target.result,
778 .debug_output = debug_output,
779774 .owner = .{ .nav_index = func.owner_nav },
780775 .args = undefined, // populated after `resolveCallingConventionValues`
781776 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`
......@@ -855,33 +850,8 @@ pub fn generate(
855850 .instructions = function.mir_instructions.toOwnedSlice(),
856851 .frame_locs = function.frame_locs.toOwnedSlice(),
857852 };
858 defer mir.deinit(gpa);
859
860 var emit: Emit = .{
861 .lower = .{
862 .pt = pt,
863 .allocator = gpa,
864 .mir = mir,
865 .cc = fn_info.cc,
866 .src_loc = src_loc,
867 .output_mode = comp.config.output_mode,
868 .link_mode = comp.config.link_mode,
869 .pic = mod.pic,
870 },
871 .bin_file = bin_file,
872 .debug_output = debug_output,
873 .code = code,
874 .prev_di_pc = 0,
875 .prev_di_line = func.lbrace_line,
876 .prev_di_column = func.lbrace_column,
877 };
878 defer emit.deinit();
879
880 emit.emitMir() catch |err| switch (err) {
881 error.LowerFail, error.EmitFail => return function.failMsg(emit.lower.err_msg.?),
882 error.InvalidInstruction => |e| return function.fail("emit MIR failed: {s} (Zig compiler bug)", .{@errorName(e)}),
883 else => |e| return e,
884 };
853 errdefer mir.deinit(gpa);
854 return mir;
885855}
886856
887857pub fn generateLazy(
......@@ -904,7 +874,6 @@ pub fn generateLazy(
904874 .bin_file = bin_file,
905875 .liveness = undefined,
906876 .target = &mod.resolved_target.result,
907 .debug_output = debug_output,
908877 .owner = .{ .lazy_sym = lazy_sym },
909878 .args = undefined, // populated after `resolveCallingConventionValues`
910879 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`
......@@ -4760,6 +4729,9 @@ fn genArgDbgInfo(func: *const Func, inst: Air.Inst.Index, mcv: MCValue) InnerErr
47604729 const ty = arg.ty.toType();
47614730 if (arg.name == .none) return;
47624731
4732 // TODO: Add a pseudo-instruction or something to defer this work until Emit.
4733 // We aren't allowed to interact with linker state here.
4734 if (true) return;
47634735 switch (func.debug_output) {
47644736 .dwarf => |dw| switch (mcv) {
47654737 .register => |reg| dw.genLocalDebugInfo(
......@@ -5273,6 +5245,9 @@ fn genVarDbgInfo(
52735245 mcv: MCValue,
52745246 name: []const u8,
52755247) !void {
5248 // TODO: Add a pseudo-instruction or something to defer this work until Emit.
5249 // We aren't allowed to interact with linker state here.
5250 if (true) return;
52765251 switch (func.debug_output) {
52775252 .dwarf => |dwarf| {
52785253 const loc: link.File.Dwarf.Loc = switch (mcv) {
src/arch/riscv64/Mir.zig+50
......@@ -109,6 +109,50 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
109109 mir.* = undefined;
110110}
111111
112pub fn emit(
113 mir: Mir,
114 lf: *link.File,
115 pt: Zcu.PerThread,
116 src_loc: Zcu.LazySrcLoc,
117 func_index: InternPool.Index,
118 code: *std.ArrayListUnmanaged(u8),
119 debug_output: link.File.DebugInfoOutput,
120 air: *const @import("../../Air.zig"),
121) codegen.CodeGenError!void {
122 _ = air; // using this would be a bug
123 const zcu = pt.zcu;
124 const comp = zcu.comp;
125 const gpa = comp.gpa;
126 const func = zcu.funcInfo(func_index);
127 const fn_info = zcu.typeToFunc(.fromInterned(func.ty)).?;
128 const nav = func.owner_nav;
129 const mod = zcu.navFileScope(nav).mod.?;
130 var e: Emit = .{
131 .lower = .{
132 .pt = pt,
133 .allocator = gpa,
134 .mir = mir,
135 .cc = fn_info.cc,
136 .src_loc = src_loc,
137 .output_mode = comp.config.output_mode,
138 .link_mode = comp.config.link_mode,
139 .pic = mod.pic,
140 },
141 .bin_file = lf,
142 .debug_output = debug_output,
143 .code = code,
144 .prev_di_pc = 0,
145 .prev_di_line = func.lbrace_line,
146 .prev_di_column = func.lbrace_column,
147 };
148 defer e.deinit();
149 e.emitMir() catch |err| switch (err) {
150 error.LowerFail, error.EmitFail => return zcu.codegenFailMsg(nav, e.lower.err_msg.?),
151 error.InvalidInstruction => return zcu.codegenFail(nav, "emit MIR failed: {s} (Zig compiler bug)", .{@errorName(err)}),
152 else => |err1| return err1,
153 };
154}
155
112156pub const FrameLoc = struct {
113157 base: Register,
114158 disp: i32,
......@@ -202,3 +246,9 @@ const FrameIndex = bits.FrameIndex;
202246const FrameAddr = @import("CodeGen.zig").FrameAddr;
203247const IntegerBitSet = std.bit_set.IntegerBitSet;
204248const Mnemonic = @import("mnem.zig").Mnemonic;
249
250const InternPool = @import("../../InternPool.zig");
251const Emit = @import("Emit.zig");
252const codegen = @import("../../codegen.zig");
253const link = @import("../../link.zig");
254const Zcu = @import("../../Zcu.zig");
src/arch/sparc64/CodeGen.zig+13-32
......@@ -57,8 +57,6 @@ liveness: Air.Liveness,
5757bin_file: *link.File,
5858target: *const std.Target,
5959func_index: InternPool.Index,
60code: *std.ArrayListUnmanaged(u8),
61debug_output: link.File.DebugInfoOutput,
6260err_msg: ?*ErrorMsg,
6361args: []MCValue,
6462ret_mcv: MCValue,
......@@ -268,11 +266,9 @@ pub fn generate(
268266 pt: Zcu.PerThread,
269267 src_loc: Zcu.LazySrcLoc,
270268 func_index: InternPool.Index,
271 air: Air,
272 liveness: Air.Liveness,
273 code: *std.ArrayListUnmanaged(u8),
274 debug_output: link.File.DebugInfoOutput,
275) CodeGenError!void {
269 air: *const Air,
270 liveness: *const Air.Liveness,
271) CodeGenError!Mir {
276272 const zcu = pt.zcu;
277273 const gpa = zcu.gpa;
278274 const func = zcu.funcInfo(func_index);
......@@ -291,13 +287,11 @@ pub fn generate(
291287 var function: Self = .{
292288 .gpa = gpa,
293289 .pt = pt,
294 .air = air,
295 .liveness = liveness,
290 .air = air.*,
291 .liveness = liveness.*,
296292 .target = target,
297293 .bin_file = lf,
298294 .func_index = func_index,
299 .code = code,
300 .debug_output = debug_output,
301295 .err_msg = null,
302296 .args = undefined, // populated after `resolveCallingConventionValues`
303297 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`
......@@ -330,29 +324,13 @@ pub fn generate(
330324 else => |e| return e,
331325 };
332326
333 var mir = Mir{
327 var mir: Mir = .{
334328 .instructions = function.mir_instructions.toOwnedSlice(),
335 .extra = try function.mir_extra.toOwnedSlice(gpa),
336 };
337 defer mir.deinit(gpa);
338
339 var emit: Emit = .{
340 .mir = mir,
341 .bin_file = lf,
342 .debug_output = debug_output,
343 .target = target,
344 .src_loc = src_loc,
345 .code = code,
346 .prev_di_pc = 0,
347 .prev_di_line = func.lbrace_line,
348 .prev_di_column = func.lbrace_column,
349 };
350 defer emit.deinit();
351
352 emit.emitMir() catch |err| switch (err) {
353 error.EmitFail => return function.failMsg(emit.err_msg.?),
354 else => |e| return e,
329 .extra = &.{}, // fallible, so populated after errdefer
355330 };
331 errdefer mir.deinit(gpa);
332 mir.extra = try function.mir_extra.toOwnedSlice(gpa);
333 return mir;
356334}
357335
358336fn gen(self: *Self) !void {
......@@ -3566,6 +3544,9 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {
35663544 const ty = arg.ty.toType();
35673545 if (arg.name == .none) return;
35683546
3547 // TODO: Add a pseudo-instruction or something to defer this work until Emit.
3548 // We aren't allowed to interact with linker state here.
3549 if (true) return;
35693550 switch (self.debug_output) {
35703551 .dwarf => |dw| switch (mcv) {
35713552 .register => |reg| try dw.genLocalDebugInfo(
src/arch/sparc64/Mir.zig+38-1
......@@ -12,7 +12,11 @@ const assert = std.debug.assert;
1212
1313const Mir = @This();
1414const bits = @import("bits.zig");
15const Air = @import("../../Air.zig");
15const InternPool = @import("../../InternPool.zig");
16const Emit = @import("Emit.zig");
17const codegen = @import("../../codegen.zig");
18const link = @import("../../link.zig");
19const Zcu = @import("../../Zcu.zig");
1620
1721const Instruction = bits.Instruction;
1822const ASI = bits.Instruction.ASI;
......@@ -370,6 +374,39 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
370374 mir.* = undefined;
371375}
372376
377pub fn emit(
378 mir: Mir,
379 lf: *link.File,
380 pt: Zcu.PerThread,
381 src_loc: Zcu.LazySrcLoc,
382 func_index: InternPool.Index,
383 code: *std.ArrayListUnmanaged(u8),
384 debug_output: link.File.DebugInfoOutput,
385 air: *const @import("../../Air.zig"),
386) codegen.CodeGenError!void {
387 _ = air; // using this would be a bug
388 const zcu = pt.zcu;
389 const func = zcu.funcInfo(func_index);
390 const nav = func.owner_nav;
391 const mod = zcu.navFileScope(nav).mod.?;
392 var e: Emit = .{
393 .mir = mir,
394 .bin_file = lf,
395 .debug_output = debug_output,
396 .target = &mod.resolved_target.result,
397 .src_loc = src_loc,
398 .code = code,
399 .prev_di_pc = 0,
400 .prev_di_line = func.lbrace_line,
401 .prev_di_column = func.lbrace_column,
402 };
403 defer e.deinit();
404 e.emitMir() catch |err| switch (err) {
405 error.EmitFail => return zcu.codegenFailMsg(nav, e.err_msg.?),
406 else => |err1| return err1,
407 };
408}
409
373410/// Returns the requested data, as well as the new index which is at the start of the
374411/// trailers for the object.
375412pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end: usize } {
src/arch/x86_64/CodeGen.zig+33-71
......@@ -125,7 +125,6 @@ pt: Zcu.PerThread,
125125air: Air,
126126liveness: Air.Liveness,
127127bin_file: *link.File,
128debug_output: link.File.DebugInfoOutput,
129128target: *const std.Target,
130129owner: Owner,
131130inline_func: InternPool.Index,
......@@ -972,13 +971,10 @@ pub fn generate(
972971 pt: Zcu.PerThread,
973972 src_loc: Zcu.LazySrcLoc,
974973 func_index: InternPool.Index,
975 air: Air,
976 liveness: Air.Liveness,
977 code: *std.ArrayListUnmanaged(u8),
978 debug_output: link.File.DebugInfoOutput,
979) codegen.CodeGenError!void {
974 air: *const Air,
975 liveness: *const Air.Liveness,
976) codegen.CodeGenError!Mir {
980977 const zcu = pt.zcu;
981 const comp = zcu.comp;
982978 const gpa = zcu.gpa;
983979 const ip = &zcu.intern_pool;
984980 const func = zcu.funcInfo(func_index);
......@@ -988,12 +984,11 @@ pub fn generate(
988984 var function: CodeGen = .{
989985 .gpa = gpa,
990986 .pt = pt,
991 .air = air,
992 .liveness = liveness,
987 .air = air.*,
988 .liveness = liveness.*,
993989 .target = &mod.resolved_target.result,
994990 .mod = mod,
995991 .bin_file = bin_file,
996 .debug_output = debug_output,
997992 .owner = .{ .nav_index = func.owner_nav },
998993 .inline_func = func_index,
999994 .arg_index = undefined,
......@@ -1090,7 +1085,7 @@ pub fn generate(
10901085 };
10911086
10921087 // Drop them off at the rbrace.
1093 if (debug_output != .none) _ = try function.addInst(.{
1088 if (!mod.strip) _ = try function.addInst(.{
10941089 .tag = .pseudo,
10951090 .ops = .pseudo_dbg_line_line_column,
10961091 .data = .{ .line_column = .{
......@@ -1100,49 +1095,17 @@ pub fn generate(
11001095 });
11011096
11021097 var mir: Mir = .{
1103 .instructions = function.mir_instructions.toOwnedSlice(),
1104 .extra = try function.mir_extra.toOwnedSlice(gpa),
1105 .table = try function.mir_table.toOwnedSlice(gpa),
1106 .frame_locs = function.frame_locs.toOwnedSlice(),
1107 };
1108 defer mir.deinit(gpa);
1109
1110 var emit: Emit = .{
1111 .air = function.air,
1112 .lower = .{
1113 .bin_file = bin_file,
1114 .target = function.target,
1115 .allocator = gpa,
1116 .mir = mir,
1117 .cc = fn_info.cc,
1118 .src_loc = src_loc,
1119 .output_mode = comp.config.output_mode,
1120 .link_mode = comp.config.link_mode,
1121 .pic = mod.pic,
1122 },
1123 .atom_index = function.owner.getSymbolIndex(&function) catch |err| switch (err) {
1124 error.CodegenFail => return error.CodegenFail,
1125 else => |e| return e,
1126 },
1127 .debug_output = debug_output,
1128 .code = code,
1129 .prev_di_loc = .{
1130 .line = func.lbrace_line,
1131 .column = func.lbrace_column,
1132 .is_stmt = switch (debug_output) {
1133 .dwarf => |dwarf| dwarf.dwarf.debug_line.header.default_is_stmt,
1134 .plan9 => undefined,
1135 .none => undefined,
1136 },
1137 },
1138 .prev_di_pc = 0,
1139 };
1140 emit.emitMir() catch |err| switch (err) {
1141 error.LowerFail, error.EmitFail => return function.failMsg(emit.lower.err_msg.?),
1142
1143 error.InvalidInstruction, error.CannotEncode => |e| return function.fail("emit MIR failed: {s} (Zig compiler bug)", .{@errorName(e)}),
1144 else => |e| return function.fail("emit MIR failed: {s}", .{@errorName(e)}),
1098 .instructions = .empty,
1099 .extra = &.{},
1100 .table = &.{},
1101 .frame_locs = .empty,
11451102 };
1103 errdefer mir.deinit(gpa);
1104 mir.instructions = function.mir_instructions.toOwnedSlice();
1105 mir.extra = try function.mir_extra.toOwnedSlice(gpa);
1106 mir.table = try function.mir_table.toOwnedSlice(gpa);
1107 mir.frame_locs = function.frame_locs.toOwnedSlice();
1108 return mir;
11461109}
11471110
11481111pub fn generateLazy(
......@@ -1165,7 +1128,6 @@ pub fn generateLazy(
11651128 .target = &mod.resolved_target.result,
11661129 .mod = mod,
11671130 .bin_file = bin_file,
1168 .debug_output = debug_output,
11691131 .owner = .{ .lazy_sym = lazy_sym },
11701132 .inline_func = undefined,
11711133 .arg_index = undefined,
......@@ -2339,7 +2301,7 @@ fn gen(self: *CodeGen) InnerError!void {
23392301 else => |cc| return self.fail("{s} does not support var args", .{@tagName(cc)}),
23402302 };
23412303
2342 if (self.debug_output != .none) try self.asmPseudo(.pseudo_dbg_prologue_end_none);
2304 if (!self.mod.strip) try self.asmPseudo(.pseudo_dbg_prologue_end_none);
23432305
23442306 try self.genBody(self.air.getMainBody());
23452307
......@@ -2356,7 +2318,7 @@ fn gen(self: *CodeGen) InnerError!void {
23562318 }
23572319 for (self.epilogue_relocs.items) |epilogue_reloc| self.performReloc(epilogue_reloc);
23582320
2359 if (self.debug_output != .none) try self.asmPseudo(.pseudo_dbg_epilogue_begin_none);
2321 if (!self.mod.strip) try self.asmPseudo(.pseudo_dbg_epilogue_begin_none);
23602322 const backpatch_stack_dealloc = try self.asmPlaceholder();
23612323 const backpatch_pop_callee_preserved_regs = try self.asmPlaceholder();
23622324 try self.asmRegister(.{ ._, .pop }, .rbp);
......@@ -2475,9 +2437,9 @@ fn gen(self: *CodeGen) InnerError!void {
24752437 });
24762438 }
24772439 } else {
2478 if (self.debug_output != .none) try self.asmPseudo(.pseudo_dbg_prologue_end_none);
2440 if (!self.mod.strip) try self.asmPseudo(.pseudo_dbg_prologue_end_none);
24792441 try self.genBody(self.air.getMainBody());
2480 if (self.debug_output != .none) try self.asmPseudo(.pseudo_dbg_epilogue_begin_none);
2442 if (!self.mod.strip) try self.asmPseudo(.pseudo_dbg_epilogue_begin_none);
24812443 }
24822444}
24832445
......@@ -2498,9 +2460,9 @@ fn checkInvariantsAfterAirInst(self: *CodeGen) void {
24982460}
24992461
25002462fn genBodyBlock(self: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2501 if (self.debug_output != .none) try self.asmPseudo(.pseudo_dbg_enter_block_none);
2463 if (!self.mod.strip) try self.asmPseudo(.pseudo_dbg_enter_block_none);
25022464 try self.genBody(body);
2503 if (self.debug_output != .none) try self.asmPseudo(.pseudo_dbg_leave_block_none);
2465 if (!self.mod.strip) try self.asmPseudo(.pseudo_dbg_leave_block_none);
25042466}
25052467
25062468fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
......@@ -2544,7 +2506,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
25442506 .shuffle_one, .shuffle_two => @panic("x86_64 TODO: shuffle_one/shuffle_two"),
25452507 // zig fmt: on
25462508
2547 .arg => if (cg.debug_output != .none) {
2509 .arg => if (!cg.mod.strip) {
25482510 // skip zero-bit arguments as they don't have a corresponding arg instruction
25492511 var arg_index = cg.arg_index;
25502512 while (cg.args[arg_index] == .none) arg_index += 1;
......@@ -64179,9 +64141,9 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6417964141 .block => {
6418064142 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;
6418164143 const block = cg.air.extraData(Air.Block, ty_pl.payload);
64182 if (cg.debug_output != .none) try cg.asmPseudo(.pseudo_dbg_enter_block_none);
64144 if (!cg.mod.strip) try cg.asmPseudo(.pseudo_dbg_enter_block_none);
6418364145 try cg.lowerBlock(inst, @ptrCast(cg.air.extra.items[block.end..][0..block.data.body_len]));
64184 if (cg.debug_output != .none) try cg.asmPseudo(.pseudo_dbg_leave_block_none);
64146 if (!cg.mod.strip) try cg.asmPseudo(.pseudo_dbg_leave_block_none);
6418564147 },
6418664148 .loop => if (use_old) try cg.airLoop(inst) else {
6418764149 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;
......@@ -85191,7 +85153,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8519185153 .switch_dispatch => try cg.airSwitchDispatch(inst),
8519285154 .@"try", .try_cold => try cg.airTry(inst),
8519385155 .try_ptr, .try_ptr_cold => try cg.airTryPtr(inst),
85194 .dbg_stmt => if (cg.debug_output != .none) {
85156 .dbg_stmt => if (!cg.mod.strip) {
8519585157 const dbg_stmt = air_datas[@intFromEnum(inst)].dbg_stmt;
8519685158 _ = try cg.addInst(.{
8519785159 .tag = .pseudo,
......@@ -85202,7 +85164,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8520285164 } },
8520385165 });
8520485166 },
85205 .dbg_empty_stmt => if (cg.debug_output != .none) {
85167 .dbg_empty_stmt => if (!cg.mod.strip) {
8520685168 if (cg.mir_instructions.len > 0) {
8520785169 const prev_mir_op = &cg.mir_instructions.items(.ops)[cg.mir_instructions.len - 1];
8520885170 if (prev_mir_op.* == .pseudo_dbg_line_line_column)
......@@ -85216,13 +85178,13 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8521685178 const old_inline_func = cg.inline_func;
8521785179 defer cg.inline_func = old_inline_func;
8521885180 cg.inline_func = dbg_inline_block.data.func;
85219 if (cg.debug_output != .none) _ = try cg.addInst(.{
85181 if (!cg.mod.strip) _ = try cg.addInst(.{
8522085182 .tag = .pseudo,
8522185183 .ops = .pseudo_dbg_enter_inline_func,
8522285184 .data = .{ .func = dbg_inline_block.data.func },
8522385185 });
8522485186 try cg.lowerBlock(inst, @ptrCast(cg.air.extra.items[dbg_inline_block.end..][0..dbg_inline_block.data.body_len]));
85225 if (cg.debug_output != .none) _ = try cg.addInst(.{
85187 if (!cg.mod.strip) _ = try cg.addInst(.{
8522685188 .tag = .pseudo,
8522785189 .ops = .pseudo_dbg_leave_inline_func,
8522885190 .data = .{ .func = old_inline_func },
......@@ -85231,7 +85193,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8523185193 .dbg_var_ptr,
8523285194 .dbg_var_val,
8523385195 .dbg_arg_inline,
85234 => if (use_old) try cg.airDbgVar(inst) else if (cg.debug_output != .none) {
85196 => if (use_old) try cg.airDbgVar(inst) else if (!cg.mod.strip) {
8523585197 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
8523685198 var ops = try cg.tempsFromOperands(inst, .{pl_op.operand});
8523785199 var mcv = ops[0].tracking(cg).short;
......@@ -173366,7 +173328,7 @@ fn airArg(self: *CodeGen, inst: Air.Inst.Index) !void {
173366173328 while (self.args[arg_index] == .none) arg_index += 1;
173367173329 self.arg_index = arg_index + 1;
173368173330
173369 const result: MCValue = if (self.debug_output == .none and self.liveness.isUnused(inst)) .unreach else result: {
173331 const result: MCValue = if (self.mod.strip and self.liveness.isUnused(inst)) .unreach else result: {
173370173332 const arg_ty = self.typeOfIndex(inst);
173371173333 const src_mcv = self.args[arg_index];
173372173334 switch (src_mcv) {
......@@ -173468,7 +173430,7 @@ fn airArg(self: *CodeGen, inst: Air.Inst.Index) !void {
173468173430}
173469173431
173470173432fn airDbgVarArgs(self: *CodeGen) !void {
173471 if (self.debug_output == .none) return;
173433 if (self.mod.strip) return;
173472173434 if (!self.pt.zcu.typeToFunc(self.fn_type).?.is_var_args) return;
173473173435 try self.asmPseudo(.pseudo_dbg_var_args_none);
173474173436}
......@@ -173478,7 +173440,7 @@ fn genLocalDebugInfo(
173478173440 inst: Air.Inst.Index,
173479173441 mcv: MCValue,
173480173442) !void {
173481 if (self.debug_output == .none) return;
173443 if (self.mod.strip) return;
173482173444 switch (self.air.instructions.items(.tag)[@intFromEnum(inst)]) {
173483173445 else => unreachable,
173484173446 .arg, .dbg_arg_inline, .dbg_var_val => |tag| {
src/arch/x86_64/Mir.zig+65
......@@ -1929,6 +1929,67 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
19291929 mir.* = undefined;
19301930}
19311931
1932pub fn emit(
1933 mir: Mir,
1934 lf: *link.File,
1935 pt: Zcu.PerThread,
1936 src_loc: Zcu.LazySrcLoc,
1937 func_index: InternPool.Index,
1938 code: *std.ArrayListUnmanaged(u8),
1939 debug_output: link.File.DebugInfoOutput,
1940 /// TODO: remove dependency on this argument. This blocks enabling `Zcu.Feature.separate_thread`.
1941 air: *const Air,
1942) codegen.CodeGenError!void {
1943 const zcu = pt.zcu;
1944 const comp = zcu.comp;
1945 const gpa = comp.gpa;
1946 const func = zcu.funcInfo(func_index);
1947 const fn_info = zcu.typeToFunc(.fromInterned(func.ty)).?;
1948 const nav = func.owner_nav;
1949 const mod = zcu.navFileScope(nav).mod.?;
1950 var e: Emit = .{
1951 .air = air.*,
1952 .lower = .{
1953 .bin_file = lf,
1954 .target = &mod.resolved_target.result,
1955 .allocator = gpa,
1956 .mir = mir,
1957 .cc = fn_info.cc,
1958 .src_loc = src_loc,
1959 .output_mode = comp.config.output_mode,
1960 .link_mode = comp.config.link_mode,
1961 .pic = mod.pic,
1962 },
1963 .atom_index = sym: {
1964 if (lf.cast(.elf)) |ef| break :sym try ef.zigObjectPtr().?.getOrCreateMetadataForNav(zcu, nav);
1965 if (lf.cast(.macho)) |mf| break :sym try mf.getZigObject().?.getOrCreateMetadataForNav(mf, nav);
1966 if (lf.cast(.coff)) |cf| {
1967 const atom = try cf.getOrCreateAtomForNav(nav);
1968 break :sym cf.getAtom(atom).getSymbolIndex().?;
1969 }
1970 if (lf.cast(.plan9)) |p9f| break :sym try p9f.seeNav(pt, nav);
1971 unreachable;
1972 },
1973 .debug_output = debug_output,
1974 .code = code,
1975 .prev_di_loc = .{
1976 .line = func.lbrace_line,
1977 .column = func.lbrace_column,
1978 .is_stmt = switch (debug_output) {
1979 .dwarf => |dwarf| dwarf.dwarf.debug_line.header.default_is_stmt,
1980 .plan9 => undefined,
1981 .none => undefined,
1982 },
1983 },
1984 .prev_di_pc = 0,
1985 };
1986 e.emitMir() catch |err| switch (err) {
1987 error.LowerFail, error.EmitFail => return zcu.codegenFailMsg(nav, e.lower.err_msg.?),
1988 error.InvalidInstruction, error.CannotEncode => return zcu.codegenFail(nav, "emit MIR failed: {s} (Zig compiler bug)", .{@errorName(err)}),
1989 else => return zcu.codegenFail(nav, "emit MIR failed: {s}", .{@errorName(err)}),
1990 };
1991}
1992
19321993pub fn extraData(mir: Mir, comptime T: type, index: u32) struct { data: T, end: u32 } {
19331994 const fields = std.meta.fields(T);
19341995 var i: u32 = index;
......@@ -1987,3 +2048,7 @@ const IntegerBitSet = std.bit_set.IntegerBitSet;
19872048const InternPool = @import("../../InternPool.zig");
19882049const Mir = @This();
19892050const Register = bits.Register;
2051const Emit = @import("Emit.zig");
2052const codegen = @import("../../codegen.zig");
2053const link = @import("../../link.zig");
2054const Zcu = @import("../../Zcu.zig");
src/codegen.zig+1-1
......@@ -182,7 +182,7 @@ pub fn emitFunction(
182182 /// in the pipeline. Any information needed to call emit must be stored in MIR.
183183 /// This is `undefined` if the backend supports the `separate_thread` feature.
184184 air: *const Air,
185) Allocator.Error!void {
185) CodeGenError!void {
186186 const zcu = pt.zcu;
187187 const func = zcu.funcInfo(func_index);
188188 const target = zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;
src/libs/freebsd.zig+1-1
......@@ -985,7 +985,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {
985985 assert(comp.freebsd_so_files == null);
986986 comp.freebsd_so_files = so_files;
987987
988 var task_buffer: [libs.len]link.Task = undefined;
988 var task_buffer: [libs.len]link.PrelinkTask = undefined;
989989 var task_buffer_i: usize = 0;
990990
991991 {
src/libs/glibc.zig+1-1
......@@ -1148,7 +1148,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {
11481148 assert(comp.glibc_so_files == null);
11491149 comp.glibc_so_files = so_files;
11501150
1151 var task_buffer: [libs.len]link.Task = undefined;
1151 var task_buffer: [libs.len]link.PrelinkTask = undefined;
11521152 var task_buffer_i: usize = 0;
11531153
11541154 {
src/libs/netbsd.zig+1-1
......@@ -650,7 +650,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {
650650 assert(comp.netbsd_so_files == null);
651651 comp.netbsd_so_files = so_files;
652652
653 var task_buffer: [libs.len]link.Task = undefined;
653 var task_buffer: [libs.len]link.PrelinkTask = undefined;
654654 var task_buffer_i: usize = 0;
655655
656656 {
src/link.zig+2
......@@ -759,6 +759,8 @@ pub const File = struct {
759759 switch (base.tag) {
760760 .lld => unreachable,
761761 inline else => |tag| {
762 if (tag == .wasm) @panic("MLUGG TODO");
763 if (tag == .spirv) @panic("MLUGG TODO");
762764 dev.check(tag.devFeature());
763765 return @as(*tag.Type(), @fieldParentPtr("base", base)).updateFunc(pt, func_index, mir, maybe_undef_air);
764766 },
src/link/Coff.zig+7-5
......@@ -1057,8 +1057,10 @@ pub fn updateFunc(
10571057 coff: *Coff,
10581058 pt: Zcu.PerThread,
10591059 func_index: InternPool.Index,
1060 air: Air,
1061 liveness: Air.Liveness,
1060 mir: *const codegen.AnyMir,
1061 /// This may be `undefined`; only pass it to `emitFunction`.
1062 /// This parameter will eventually be removed.
1063 maybe_undef_air: *const Air,
10621064) link.File.UpdateNavError!void {
10631065 if (build_options.skip_non_native and builtin.object_format != .coff) {
10641066 @panic("Attempted to compile for object format that was disabled by build configuration");
......@@ -1079,15 +1081,15 @@ pub fn updateFunc(
10791081 var code_buffer: std.ArrayListUnmanaged(u8) = .empty;
10801082 defer code_buffer.deinit(gpa);
10811083
1082 try codegen.generateFunction(
1084 try codegen.emitFunction(
10831085 &coff.base,
10841086 pt,
10851087 zcu.navSrcLoc(nav_index),
10861088 func_index,
1087 air,
1088 liveness,
1089 mir,
10891090 &code_buffer,
10901091 .none,
1092 maybe_undef_air,
10911093 );
10921094
10931095 try coff.updateNavCode(pt, nav_index, code_buffer.items, .FUNCTION);
src/link/Goff.zig+5-4
......@@ -13,6 +13,7 @@ const Path = std.Build.Cache.Path;
1313const Zcu = @import("../Zcu.zig");
1414const InternPool = @import("../InternPool.zig");
1515const Compilation = @import("../Compilation.zig");
16const codegen = @import("../codegen.zig");
1617const link = @import("../link.zig");
1718const trace = @import("../tracy.zig").trace;
1819const build_options = @import("build_options");
......@@ -72,14 +73,14 @@ pub fn updateFunc(
7273 self: *Goff,
7374 pt: Zcu.PerThread,
7475 func_index: InternPool.Index,
75 air: Air,
76 liveness: Air.Liveness,
76 mir: *const codegen.AnyMir,
77 maybe_undef_air: *const Air,
7778) link.File.UpdateNavError!void {
7879 _ = self;
7980 _ = pt;
8081 _ = func_index;
81 _ = air;
82 _ = liveness;
82 _ = mir;
83 _ = maybe_undef_air;
8384 unreachable; // we always use llvm
8485}
8586
src/link/MachO.zig+3-3
......@@ -3051,13 +3051,13 @@ pub fn updateFunc(
30513051 self: *MachO,
30523052 pt: Zcu.PerThread,
30533053 func_index: InternPool.Index,
3054 air: Air,
3055 liveness: Air.Liveness,
3054 mir: *const codegen.AnyMir,
3055 maybe_undef_air: *const Air,
30563056) link.File.UpdateNavError!void {
30573057 if (build_options.skip_non_native and builtin.object_format != .macho) {
30583058 @panic("Attempted to compile for object format that was disabled by build configuration");
30593059 }
3060 return self.getZigObject().?.updateFunc(self, pt, func_index, air, liveness);
3060 return self.getZigObject().?.updateFunc(self, pt, func_index, mir, maybe_undef_air);
30613061}
30623062
30633063pub fn updateNav(self: *MachO, pt: Zcu.PerThread, nav: InternPool.Nav.Index) link.File.UpdateNavError!void {
src/link/MachO/ZigObject.zig+7-5
......@@ -777,8 +777,10 @@ pub fn updateFunc(
777777 macho_file: *MachO,
778778 pt: Zcu.PerThread,
779779 func_index: InternPool.Index,
780 air: Air,
781 liveness: Air.Liveness,
780 mir: *const codegen.AnyMir,
781 /// This may be `undefined`; only pass it to `emitFunction`.
782 /// This parameter will eventually be removed.
783 maybe_undef_air: *const Air,
782784) link.File.UpdateNavError!void {
783785 const tracy = trace(@src());
784786 defer tracy.end();
......@@ -796,15 +798,15 @@ pub fn updateFunc(
796798 var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, func.owner_nav, sym_index) else null;
797799 defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit();
798800
799 try codegen.generateFunction(
801 try codegen.emitFunction(
800802 &macho_file.base,
801803 pt,
802804 zcu.navSrcLoc(func.owner_nav),
803805 func_index,
804 air,
805 liveness,
806 mir,
806807 &code_buffer,
807808 if (debug_wip_nav) |*wip_nav| .{ .dwarf = wip_nav } else .none,
809 maybe_undef_air,
808810 );
809811 const code = code_buffer.items;
810812
src/link/Plan9.zig+7-5
......@@ -386,8 +386,10 @@ pub fn updateFunc(
386386 self: *Plan9,
387387 pt: Zcu.PerThread,
388388 func_index: InternPool.Index,
389 air: Air,
390 liveness: Air.Liveness,
389 mir: *const codegen.AnyMir,
390 /// This may be `undefined`; only pass it to `emitFunction`.
391 /// This parameter will eventually be removed.
392 maybe_undef_air: *const Air,
391393) link.File.UpdateNavError!void {
392394 if (build_options.skip_non_native and builtin.object_format != .plan9) {
393395 @panic("Attempted to compile for object format that was disabled by build configuration");
......@@ -412,15 +414,15 @@ pub fn updateFunc(
412414 };
413415 defer dbg_info_output.dbg_line.deinit();
414416
415 try codegen.generateFunction(
417 try codegen.emitFunction(
416418 &self.base,
417419 pt,
418420 zcu.navSrcLoc(func.owner_nav),
419421 func_index,
420 air,
421 liveness,
422 mir,
422423 &code_buffer,
423424 .{ .plan9 = &dbg_info_output },
425 maybe_undef_air,
424426 );
425427 const code = try code_buffer.toOwnedSlice(gpa);
426428 self.getAtomPtr(atom_idx).code = .{
src/link/Queue.zig+1-2
......@@ -97,8 +97,7 @@ pub fn mirReady(q: *Queue, comp: *Compilation, mir: *ZcuTask.LinkFunc.SharedMir)
9797 q.mutex.lock();
9898 defer q.mutex.unlock();
9999 switch (q.state) {
100 .finished => unreachable, // there's definitely a task queued
101 .running => return,
100 .finished, .running => return,
102101 .wait_for_mir => |wait_for| if (wait_for != mir) return,
103102 }
104103 // We were waiting for `mir`, so we will restart the linker thread.
src/link/Xcoff.zig+5-4
......@@ -13,6 +13,7 @@ const Path = std.Build.Cache.Path;
1313const Zcu = @import("../Zcu.zig");
1414const InternPool = @import("../InternPool.zig");
1515const Compilation = @import("../Compilation.zig");
16const codegen = @import("../codegen.zig");
1617const link = @import("../link.zig");
1718const trace = @import("../tracy.zig").trace;
1819const build_options = @import("build_options");
......@@ -72,14 +73,14 @@ pub fn updateFunc(
7273 self: *Xcoff,
7374 pt: Zcu.PerThread,
7475 func_index: InternPool.Index,
75 air: Air,
76 liveness: Air.Liveness,
76 mir: *const codegen.AnyMir,
77 maybe_undef_air: *const Air,
7778) link.File.UpdateNavError!void {
7879 _ = self;
7980 _ = pt;
8081 _ = func_index;
81 _ = air;
82 _ = liveness;
82 _ = mir;
83 _ = maybe_undef_air;
8384 unreachable; // we always use llvm
8485}
8586