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 {...@@ -4550,8 +4550,6 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
4550 air.deinit(gpa);4550 air.deinit(gpa);
4551 return;4551 return;
4552 }4552 }
4553 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
4554 defer pt.deactivate();
4555 const shared_mir = try gpa.create(link.ZcuTask.LinkFunc.SharedMir);4553 const shared_mir = try gpa.create(link.ZcuTask.LinkFunc.SharedMir);
4556 shared_mir.* = .{4554 shared_mir.* = .{
4557 .status = .init(.pending),4555 .status = .init(.pending),
...@@ -4567,7 +4565,11 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {...@@ -4567,7 +4565,11 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
4567 } });4565 } });
4568 } else {4566 } else {
4569 const emit_needs_air = !zcu.backendSupportsFeature(.separate_thread);4567 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 }
4571 assert(shared_mir.status.load(.monotonic) != .pending);4573 assert(shared_mir.status.load(.monotonic) != .pending);
4572 comp.dispatchZcuLinkTask(tid, .{ .link_func = .{4574 comp.dispatchZcuLinkTask(tid, .{ .link_func = .{
4573 .func = func.func,4575 .func = func.func,
src/Zcu/PerThread.zig+22-6
...@@ -4376,26 +4376,40 @@ pub fn addDependency(pt: Zcu.PerThread, unit: AnalUnit, dependee: InternPool.Dep...@@ -4376,26 +4376,40 @@ pub fn addDependency(pt: Zcu.PerThread, unit: AnalUnit, dependee: InternPool.Dep
4376/// other code. This function is currently run either on the main thread, or on a separate4376/// other code. This function is currently run either on the main thread, or on a separate
4377/// codegen thread, depending on whether the backend supports `Zcu.Feature.separate_thread`.4377/// codegen thread, depending on whether the backend supports `Zcu.Feature.separate_thread`.
4378pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air, out: *@import("../link.zig").ZcuTask.LinkFunc.SharedMir) void {4378pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air, out: *@import("../link.zig").ZcuTask.LinkFunc.SharedMir) void {
4379 const zcu = pt.zcu;
4379 if (runCodegenInner(pt, func_index, air)) |mir| {4380 if (runCodegenInner(pt, func_index, air)) |mir| {
4380 out.value = mir;4381 out.value = mir;
4381 out.status.store(.ready, .release);4382 out.status.store(.ready, .release);
4382 } else |err| switch (err) {4383 } else |err| switch (err) {
4383 error.OutOfMemory => {4384 error.OutOfMemory => {
4384 pt.zcu.comp.setAllocFailure();4385 zcu.comp.setAllocFailure();
4385 out.status.store(.failed, .monotonic);4386 out.status.store(.failed, .monotonic);
4386 },4387 },
4387 error.CodegenFail => {4388 error.CodegenFail => {
4388 pt.zcu.assertCodegenFailed(pt.zcu.funcInfo(func_index).owner_nav);4389 zcu.assertCodegenFailed(zcu.funcInfo(func_index).owner_nav);
4389 out.status.store(.failed, .monotonic);4390 out.status.store(.failed, .monotonic);
4390 },4391 },
4391 error.NoLinkFile => {4392 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 }
4393 out.status.store(.failed, .monotonic);4402 out.status.store(.failed, .monotonic);
4394 },4403 },
4395 }4404 }
4396 pt.zcu.comp.link_task_queue.mirReady(pt.zcu.comp, out);4405 zcu.comp.link_task_queue.mirReady(zcu.comp, out);
4397}4406}
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 {
4399 const zcu = pt.zcu;4413 const zcu = pt.zcu;
4400 const gpa = zcu.gpa;4414 const gpa = zcu.gpa;
4401 const ip = &zcu.intern_pool;4415 const ip = &zcu.intern_pool;
...@@ -4441,7 +4455,9 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e...@@ -4441,7 +4455,9 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
4441 // "emit" step because LLVM does not support incremental linking. Our linker (LLD or self-hosted)4455 // "emit" step because LLVM does not support incremental linking. Our linker (LLD or self-hosted)
4442 // will just see the ZCU object file which LLVM ultimately emits.4456 // will just see the ZCU object file which LLVM ultimately emits.
4443 if (zcu.llvm_object) |llvm_object| {4457 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;
4445 }4461 }
44464462
4447 const lf = comp.bin_file orelse return error.NoLinkFile;4463 const lf = comp.bin_file orelse return error.NoLinkFile;
src/arch/aarch64/CodeGen.zig+16-30
...@@ -49,7 +49,6 @@ pt: Zcu.PerThread,...@@ -49,7 +49,6 @@ pt: Zcu.PerThread,
49air: Air,49air: Air,
50liveness: Air.Liveness,50liveness: Air.Liveness,
51bin_file: *link.File,51bin_file: *link.File,
52debug_output: link.File.DebugInfoOutput,
53target: *const std.Target,52target: *const std.Target,
54func_index: InternPool.Index,53func_index: InternPool.Index,
55owner_nav: InternPool.Nav.Index,54owner_nav: InternPool.Nav.Index,
...@@ -185,6 +184,9 @@ const DbgInfoReloc = struct {...@@ -185,6 +184,9 @@ const DbgInfoReloc = struct {
185 }184 }
186185
187 fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) !void {186 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;
188 switch (function.debug_output) {190 switch (function.debug_output) {
189 .dwarf => |dw| {191 .dwarf => |dw| {
190 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {192 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {
...@@ -213,6 +215,9 @@ const DbgInfoReloc = struct {...@@ -213,6 +215,9 @@ const DbgInfoReloc = struct {
213 }215 }
214216
215 fn genVarDbgInfo(reloc: DbgInfoReloc, function: Self) !void {217 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;
216 switch (function.debug_output) {221 switch (function.debug_output) {
217 .dwarf => |dwarf| {222 .dwarf => |dwarf| {
218 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {223 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {
...@@ -326,11 +331,9 @@ pub fn generate(...@@ -326,11 +331,9 @@ pub fn generate(
326 pt: Zcu.PerThread,331 pt: Zcu.PerThread,
327 src_loc: Zcu.LazySrcLoc,332 src_loc: Zcu.LazySrcLoc,
328 func_index: InternPool.Index,333 func_index: InternPool.Index,
329 air: Air,334 air: *const Air,
330 liveness: Air.Liveness,335 liveness: *const Air.Liveness,
331 code: *std.ArrayListUnmanaged(u8),336) CodeGenError!Mir {
332 debug_output: link.File.DebugInfoOutput,
333) CodeGenError!void {
334 const zcu = pt.zcu;337 const zcu = pt.zcu;
335 const gpa = zcu.gpa;338 const gpa = zcu.gpa;
336 const func = zcu.funcInfo(func_index);339 const func = zcu.funcInfo(func_index);
...@@ -349,9 +352,8 @@ pub fn generate(...@@ -349,9 +352,8 @@ pub fn generate(
349 var function: Self = .{352 var function: Self = .{
350 .gpa = gpa,353 .gpa = gpa,
351 .pt = pt,354 .pt = pt,
352 .air = air,355 .air = air.*,
353 .liveness = liveness,356 .liveness = liveness.*,
354 .debug_output = debug_output,
355 .target = target,357 .target = target,
356 .bin_file = lf,358 .bin_file = lf,
357 .func_index = func_index,359 .func_index = func_index,
...@@ -395,29 +397,13 @@ pub fn generate(...@@ -395,29 +397,13 @@ pub fn generate(
395397
396 var mir: Mir = .{398 var mir: Mir = .{
397 .instructions = function.mir_instructions.toOwnedSlice(),399 .instructions = function.mir_instructions.toOwnedSlice(),
398 .extra = try function.mir_extra.toOwnedSlice(gpa),400 .extra = &.{}, // fallible, so assign after errdefer
399 };401 .max_end_stack = function.max_end_stack,
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,
413 .saved_regs_stack_space = function.saved_regs_stack_space,402 .saved_regs_stack_space = function.saved_regs_stack_space,
414 };403 };
415 defer emit.deinit();404 errdefer mir.deinit(gpa);
416405 mir.extra = try function.mir_extra.toOwnedSlice(gpa);
417 emit.emitMir() catch |err| switch (err) {406 return mir;
418 error.EmitFail => return function.failMsg(emit.err_msg.?),
419 else => |e| return e,
420 };
421}407}
422408
423fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {409fn 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;...@@ -13,6 +13,14 @@ const assert = std.debug.assert;
1313
14const bits = @import("bits.zig");14const bits = @import("bits.zig");
15const Register = bits.Register;15const 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
17instructions: std.MultiArrayList(Inst).Slice,25instructions: std.MultiArrayList(Inst).Slice,
18/// The meaning of this data is determined by `Inst.Tag` value.26/// 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 {...@@ -498,6 +506,41 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
498 mir.* = undefined;506 mir.* = undefined;
499}507}
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
501/// Returns the requested data, as well as the new index which is at the start of the544/// Returns the requested data, as well as the new index which is at the start of the
502/// trailers for the object.545/// trailers for the object.
503pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end: usize } {546pub 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,...@@ -50,7 +50,6 @@ pt: Zcu.PerThread,
50air: Air,50air: Air,
51liveness: Air.Liveness,51liveness: Air.Liveness,
52bin_file: *link.File,52bin_file: *link.File,
53debug_output: link.File.DebugInfoOutput,
54target: *const std.Target,53target: *const std.Target,
55func_index: InternPool.Index,54func_index: InternPool.Index,
56err_msg: ?*ErrorMsg,55err_msg: ?*ErrorMsg,
...@@ -264,6 +263,9 @@ const DbgInfoReloc = struct {...@@ -264,6 +263,9 @@ const DbgInfoReloc = struct {
264 }263 }
265264
266 fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) !void {265 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;
267 switch (function.debug_output) {269 switch (function.debug_output) {
268 .dwarf => |dw| {270 .dwarf => |dw| {
269 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {271 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {
...@@ -292,6 +294,9 @@ const DbgInfoReloc = struct {...@@ -292,6 +294,9 @@ const DbgInfoReloc = struct {
292 }294 }
293295
294 fn genVarDbgInfo(reloc: DbgInfoReloc, function: Self) !void {296 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;
295 switch (function.debug_output) {300 switch (function.debug_output) {
296 .dwarf => |dw| {301 .dwarf => |dw| {
297 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {302 const loc: link.File.Dwarf.Loc = switch (reloc.mcv) {
...@@ -335,11 +340,9 @@ pub fn generate(...@@ -335,11 +340,9 @@ pub fn generate(
335 pt: Zcu.PerThread,340 pt: Zcu.PerThread,
336 src_loc: Zcu.LazySrcLoc,341 src_loc: Zcu.LazySrcLoc,
337 func_index: InternPool.Index,342 func_index: InternPool.Index,
338 air: Air,343 air: *const Air,
339 liveness: Air.Liveness,344 liveness: *const Air.Liveness,
340 code: *std.ArrayListUnmanaged(u8),345) CodeGenError!Mir {
341 debug_output: link.File.DebugInfoOutput,
342) CodeGenError!void {
343 const zcu = pt.zcu;346 const zcu = pt.zcu;
344 const gpa = zcu.gpa;347 const gpa = zcu.gpa;
345 const func = zcu.funcInfo(func_index);348 const func = zcu.funcInfo(func_index);
...@@ -358,11 +361,10 @@ pub fn generate(...@@ -358,11 +361,10 @@ pub fn generate(
358 var function: Self = .{361 var function: Self = .{
359 .gpa = gpa,362 .gpa = gpa,
360 .pt = pt,363 .pt = pt,
361 .air = air,364 .air = air.*,
362 .liveness = liveness,365 .liveness = liveness.*,
363 .target = target,366 .target = target,
364 .bin_file = lf,367 .bin_file = lf,
365 .debug_output = debug_output,
366 .func_index = func_index,368 .func_index = func_index,
367 .err_msg = null,369 .err_msg = null,
368 .args = undefined, // populated after `resolveCallingConventionValues`370 .args = undefined, // populated after `resolveCallingConventionValues`
...@@ -402,31 +404,15 @@ pub fn generate(...@@ -402,31 +404,15 @@ pub fn generate(
402 return function.fail("failed to generate debug info: {s}", .{@errorName(err)});404 return function.fail("failed to generate debug info: {s}", .{@errorName(err)});
403 }405 }
404406
405 var mir = Mir{407 var mir: Mir = .{
406 .instructions = function.mir_instructions.toOwnedSlice(),408 .instructions = function.mir_instructions.toOwnedSlice(),
407 .extra = try function.mir_extra.toOwnedSlice(gpa),409 .extra = &.{}, // fallible, so assign after errdefer
408 };410 .max_end_stack = function.max_end_stack,
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,
422 .saved_regs_stack_space = function.saved_regs_stack_space,411 .saved_regs_stack_space = function.saved_regs_stack_space,
423 };412 };
424 defer emit.deinit();413 errdefer mir.deinit(gpa);
425414 mir.extra = try function.mir_extra.toOwnedSlice(gpa);
426 emit.emitMir() catch |err| switch (err) {415 return mir;
427 error.EmitFail => return function.failMsg(emit.err_msg.?),
428 else => |e| return e,
429 };
430}416}
431417
432fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {418fn 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;...@@ -13,6 +13,14 @@ const assert = std.debug.assert;
1313
14const bits = @import("bits.zig");14const bits = @import("bits.zig");
15const Register = bits.Register;15const 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
17instructions: std.MultiArrayList(Inst).Slice,25instructions: std.MultiArrayList(Inst).Slice,
18/// The meaning of this data is determined by `Inst.Tag` value.26/// 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 {...@@ -278,6 +286,41 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
278 mir.* = undefined;286 mir.* = undefined;
279}287}
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
281/// Returns the requested data, as well as the new index which is at the start of the324/// Returns the requested data, as well as the new index which is at the start of the
282/// trailers for the object.325/// trailers for the object.
283pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end: usize } {326pub 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(...@@ -19,19 +19,15 @@ pub fn generate(
19 pt: Zcu.PerThread,19 pt: Zcu.PerThread,
20 src_loc: Zcu.LazySrcLoc,20 src_loc: Zcu.LazySrcLoc,
21 func_index: InternPool.Index,21 func_index: InternPool.Index,
22 air: Air,22 air: *const Air,
23 liveness: Air.Liveness,23 liveness: *const Air.Liveness,
24 code: *std.ArrayListUnmanaged(u8),24) codegen.CodeGenError!noreturn {
25 debug_output: link.File.DebugInfoOutput,
26) codegen.CodeGenError!void {
27 _ = bin_file;25 _ = bin_file;
28 _ = pt;26 _ = pt;
29 _ = src_loc;27 _ = src_loc;
30 _ = func_index;28 _ = func_index;
31 _ = air;29 _ = air;
32 _ = liveness;30 _ = liveness;
33 _ = code;
34 _ = debug_output;
3531
36 unreachable;32 unreachable;
37}33}
src/arch/riscv64/CodeGen.zig+13-38
...@@ -68,7 +68,6 @@ gpa: Allocator,...@@ -68,7 +68,6 @@ gpa: Allocator,
6868
69mod: *Package.Module,69mod: *Package.Module,
70target: *const std.Target,70target: *const std.Target,
71debug_output: link.File.DebugInfoOutput,
72args: []MCValue,71args: []MCValue,
73ret_mcv: InstTracking,72ret_mcv: InstTracking,
74fn_type: Type,73fn_type: Type,
...@@ -746,13 +745,10 @@ pub fn generate(...@@ -746,13 +745,10 @@ pub fn generate(
746 pt: Zcu.PerThread,745 pt: Zcu.PerThread,
747 src_loc: Zcu.LazySrcLoc,746 src_loc: Zcu.LazySrcLoc,
748 func_index: InternPool.Index,747 func_index: InternPool.Index,
749 air: Air,748 air: *const Air,
750 liveness: Air.Liveness,749 liveness: *const Air.Liveness,
751 code: *std.ArrayListUnmanaged(u8),750) CodeGenError!Mir {
752 debug_output: link.File.DebugInfoOutput,
753) CodeGenError!void {
754 const zcu = pt.zcu;751 const zcu = pt.zcu;
755 const comp = zcu.comp;
756 const gpa = zcu.gpa;752 const gpa = zcu.gpa;
757 const ip = &zcu.intern_pool;753 const ip = &zcu.intern_pool;
758 const func = zcu.funcInfo(func_index);754 const func = zcu.funcInfo(func_index);
...@@ -769,13 +765,12 @@ pub fn generate(...@@ -769,13 +765,12 @@ pub fn generate(
769765
770 var function: Func = .{766 var function: Func = .{
771 .gpa = gpa,767 .gpa = gpa,
772 .air = air,768 .air = air.*,
773 .pt = pt,769 .pt = pt,
774 .mod = mod,770 .mod = mod,
775 .bin_file = bin_file,771 .bin_file = bin_file,
776 .liveness = liveness,772 .liveness = liveness.*,
777 .target = &mod.resolved_target.result,773 .target = &mod.resolved_target.result,
778 .debug_output = debug_output,
779 .owner = .{ .nav_index = func.owner_nav },774 .owner = .{ .nav_index = func.owner_nav },
780 .args = undefined, // populated after `resolveCallingConventionValues`775 .args = undefined, // populated after `resolveCallingConventionValues`
781 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`776 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`
...@@ -855,33 +850,8 @@ pub fn generate(...@@ -855,33 +850,8 @@ pub fn generate(
855 .instructions = function.mir_instructions.toOwnedSlice(),850 .instructions = function.mir_instructions.toOwnedSlice(),
856 .frame_locs = function.frame_locs.toOwnedSlice(),851 .frame_locs = function.frame_locs.toOwnedSlice(),
857 };852 };
858 defer mir.deinit(gpa);853 errdefer mir.deinit(gpa);
859854 return mir;
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 };
885}855}
886856
887pub fn generateLazy(857pub fn generateLazy(
...@@ -904,7 +874,6 @@ pub fn generateLazy(...@@ -904,7 +874,6 @@ pub fn generateLazy(
904 .bin_file = bin_file,874 .bin_file = bin_file,
905 .liveness = undefined,875 .liveness = undefined,
906 .target = &mod.resolved_target.result,876 .target = &mod.resolved_target.result,
907 .debug_output = debug_output,
908 .owner = .{ .lazy_sym = lazy_sym },877 .owner = .{ .lazy_sym = lazy_sym },
909 .args = undefined, // populated after `resolveCallingConventionValues`878 .args = undefined, // populated after `resolveCallingConventionValues`
910 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`879 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`
...@@ -4760,6 +4729,9 @@ fn genArgDbgInfo(func: *const Func, inst: Air.Inst.Index, mcv: MCValue) InnerErr...@@ -4760,6 +4729,9 @@ fn genArgDbgInfo(func: *const Func, inst: Air.Inst.Index, mcv: MCValue) InnerErr
4760 const ty = arg.ty.toType();4729 const ty = arg.ty.toType();
4761 if (arg.name == .none) return;4730 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;
4763 switch (func.debug_output) {4735 switch (func.debug_output) {
4764 .dwarf => |dw| switch (mcv) {4736 .dwarf => |dw| switch (mcv) {
4765 .register => |reg| dw.genLocalDebugInfo(4737 .register => |reg| dw.genLocalDebugInfo(
...@@ -5273,6 +5245,9 @@ fn genVarDbgInfo(...@@ -5273,6 +5245,9 @@ fn genVarDbgInfo(
5273 mcv: MCValue,5245 mcv: MCValue,
5274 name: []const u8,5246 name: []const u8,
5275) !void {5247) !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;
5276 switch (func.debug_output) {5251 switch (func.debug_output) {
5277 .dwarf => |dwarf| {5252 .dwarf => |dwarf| {
5278 const loc: link.File.Dwarf.Loc = switch (mcv) {5253 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 {...@@ -109,6 +109,50 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
109 mir.* = undefined;109 mir.* = undefined;
110}110}
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
112pub const FrameLoc = struct {156pub const FrameLoc = struct {
113 base: Register,157 base: Register,
114 disp: i32,158 disp: i32,
...@@ -202,3 +246,9 @@ const FrameIndex = bits.FrameIndex;...@@ -202,3 +246,9 @@ const FrameIndex = bits.FrameIndex;
202const FrameAddr = @import("CodeGen.zig").FrameAddr;246const FrameAddr = @import("CodeGen.zig").FrameAddr;
203const IntegerBitSet = std.bit_set.IntegerBitSet;247const IntegerBitSet = std.bit_set.IntegerBitSet;
204const Mnemonic = @import("mnem.zig").Mnemonic;248const 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,...@@ -57,8 +57,6 @@ liveness: Air.Liveness,
57bin_file: *link.File,57bin_file: *link.File,
58target: *const std.Target,58target: *const std.Target,
59func_index: InternPool.Index,59func_index: InternPool.Index,
60code: *std.ArrayListUnmanaged(u8),
61debug_output: link.File.DebugInfoOutput,
62err_msg: ?*ErrorMsg,60err_msg: ?*ErrorMsg,
63args: []MCValue,61args: []MCValue,
64ret_mcv: MCValue,62ret_mcv: MCValue,
...@@ -268,11 +266,9 @@ pub fn generate(...@@ -268,11 +266,9 @@ pub fn generate(
268 pt: Zcu.PerThread,266 pt: Zcu.PerThread,
269 src_loc: Zcu.LazySrcLoc,267 src_loc: Zcu.LazySrcLoc,
270 func_index: InternPool.Index,268 func_index: InternPool.Index,
271 air: Air,269 air: *const Air,
272 liveness: Air.Liveness,270 liveness: *const Air.Liveness,
273 code: *std.ArrayListUnmanaged(u8),271) CodeGenError!Mir {
274 debug_output: link.File.DebugInfoOutput,
275) CodeGenError!void {
276 const zcu = pt.zcu;272 const zcu = pt.zcu;
277 const gpa = zcu.gpa;273 const gpa = zcu.gpa;
278 const func = zcu.funcInfo(func_index);274 const func = zcu.funcInfo(func_index);
...@@ -291,13 +287,11 @@ pub fn generate(...@@ -291,13 +287,11 @@ pub fn generate(
291 var function: Self = .{287 var function: Self = .{
292 .gpa = gpa,288 .gpa = gpa,
293 .pt = pt,289 .pt = pt,
294 .air = air,290 .air = air.*,
295 .liveness = liveness,291 .liveness = liveness.*,
296 .target = target,292 .target = target,
297 .bin_file = lf,293 .bin_file = lf,
298 .func_index = func_index,294 .func_index = func_index,
299 .code = code,
300 .debug_output = debug_output,
301 .err_msg = null,295 .err_msg = null,
302 .args = undefined, // populated after `resolveCallingConventionValues`296 .args = undefined, // populated after `resolveCallingConventionValues`
303 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`297 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`
...@@ -330,29 +324,13 @@ pub fn generate(...@@ -330,29 +324,13 @@ pub fn generate(
330 else => |e| return e,324 else => |e| return e,
331 };325 };
332326
333 var mir = Mir{327 var mir: Mir = .{
334 .instructions = function.mir_instructions.toOwnedSlice(),328 .instructions = function.mir_instructions.toOwnedSlice(),
335 .extra = try function.mir_extra.toOwnedSlice(gpa),329 .extra = &.{}, // fallible, so populated after errdefer
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,
355 };330 };
331 errdefer mir.deinit(gpa);
332 mir.extra = try function.mir_extra.toOwnedSlice(gpa);
333 return mir;
356}334}
357335
358fn gen(self: *Self) !void {336fn gen(self: *Self) !void {
...@@ -3566,6 +3544,9 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {...@@ -3566,6 +3544,9 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {
3566 const ty = arg.ty.toType();3544 const ty = arg.ty.toType();
3567 if (arg.name == .none) return;3545 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;
3569 switch (self.debug_output) {3550 switch (self.debug_output) {
3570 .dwarf => |dw| switch (mcv) {3551 .dwarf => |dw| switch (mcv) {
3571 .register => |reg| try dw.genLocalDebugInfo(3552 .register => |reg| try dw.genLocalDebugInfo(
src/arch/sparc64/Mir.zig+38-1
...@@ -12,7 +12,11 @@ const assert = std.debug.assert;...@@ -12,7 +12,11 @@ const assert = std.debug.assert;
1212
13const Mir = @This();13const Mir = @This();
14const bits = @import("bits.zig");14const 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
17const Instruction = bits.Instruction;21const Instruction = bits.Instruction;
18const ASI = bits.Instruction.ASI;22const ASI = bits.Instruction.ASI;
...@@ -370,6 +374,39 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {...@@ -370,6 +374,39 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
370 mir.* = undefined;374 mir.* = undefined;
371}375}
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
373/// Returns the requested data, as well as the new index which is at the start of the410/// Returns the requested data, as well as the new index which is at the start of the
374/// trailers for the object.411/// trailers for the object.
375pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end: usize } {412pub 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,...@@ -125,7 +125,6 @@ pt: Zcu.PerThread,
125air: Air,125air: Air,
126liveness: Air.Liveness,126liveness: Air.Liveness,
127bin_file: *link.File,127bin_file: *link.File,
128debug_output: link.File.DebugInfoOutput,
129target: *const std.Target,128target: *const std.Target,
130owner: Owner,129owner: Owner,
131inline_func: InternPool.Index,130inline_func: InternPool.Index,
...@@ -972,13 +971,10 @@ pub fn generate(...@@ -972,13 +971,10 @@ pub fn generate(
972 pt: Zcu.PerThread,971 pt: Zcu.PerThread,
973 src_loc: Zcu.LazySrcLoc,972 src_loc: Zcu.LazySrcLoc,
974 func_index: InternPool.Index,973 func_index: InternPool.Index,
975 air: Air,974 air: *const Air,
976 liveness: Air.Liveness,975 liveness: *const Air.Liveness,
977 code: *std.ArrayListUnmanaged(u8),976) codegen.CodeGenError!Mir {
978 debug_output: link.File.DebugInfoOutput,
979) codegen.CodeGenError!void {
980 const zcu = pt.zcu;977 const zcu = pt.zcu;
981 const comp = zcu.comp;
982 const gpa = zcu.gpa;978 const gpa = zcu.gpa;
983 const ip = &zcu.intern_pool;979 const ip = &zcu.intern_pool;
984 const func = zcu.funcInfo(func_index);980 const func = zcu.funcInfo(func_index);
...@@ -988,12 +984,11 @@ pub fn generate(...@@ -988,12 +984,11 @@ pub fn generate(
988 var function: CodeGen = .{984 var function: CodeGen = .{
989 .gpa = gpa,985 .gpa = gpa,
990 .pt = pt,986 .pt = pt,
991 .air = air,987 .air = air.*,
992 .liveness = liveness,988 .liveness = liveness.*,
993 .target = &mod.resolved_target.result,989 .target = &mod.resolved_target.result,
994 .mod = mod,990 .mod = mod,
995 .bin_file = bin_file,991 .bin_file = bin_file,
996 .debug_output = debug_output,
997 .owner = .{ .nav_index = func.owner_nav },992 .owner = .{ .nav_index = func.owner_nav },
998 .inline_func = func_index,993 .inline_func = func_index,
999 .arg_index = undefined,994 .arg_index = undefined,
...@@ -1090,7 +1085,7 @@ pub fn generate(...@@ -1090,7 +1085,7 @@ pub fn generate(
1090 };1085 };
10911086
1092 // Drop them off at the rbrace.1087 // Drop them off at the rbrace.
1093 if (debug_output != .none) _ = try function.addInst(.{1088 if (!mod.strip) _ = try function.addInst(.{
1094 .tag = .pseudo,1089 .tag = .pseudo,
1095 .ops = .pseudo_dbg_line_line_column,1090 .ops = .pseudo_dbg_line_line_column,
1096 .data = .{ .line_column = .{1091 .data = .{ .line_column = .{
...@@ -1100,49 +1095,17 @@ pub fn generate(...@@ -1100,49 +1095,17 @@ pub fn generate(
1100 });1095 });
11011096
1102 var mir: Mir = .{1097 var mir: Mir = .{
1103 .instructions = function.mir_instructions.toOwnedSlice(),1098 .instructions = .empty,
1104 .extra = try function.mir_extra.toOwnedSlice(gpa),1099 .extra = &.{},
1105 .table = try function.mir_table.toOwnedSlice(gpa),1100 .table = &.{},
1106 .frame_locs = function.frame_locs.toOwnedSlice(),1101 .frame_locs = .empty,
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)}),
1145 };1102 };
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;
1146}1109}
11471110
1148pub fn generateLazy(1111pub fn generateLazy(
...@@ -1165,7 +1128,6 @@ pub fn generateLazy(...@@ -1165,7 +1128,6 @@ pub fn generateLazy(
1165 .target = &mod.resolved_target.result,1128 .target = &mod.resolved_target.result,
1166 .mod = mod,1129 .mod = mod,
1167 .bin_file = bin_file,1130 .bin_file = bin_file,
1168 .debug_output = debug_output,
1169 .owner = .{ .lazy_sym = lazy_sym },1131 .owner = .{ .lazy_sym = lazy_sym },
1170 .inline_func = undefined,1132 .inline_func = undefined,
1171 .arg_index = undefined,1133 .arg_index = undefined,
...@@ -2339,7 +2301,7 @@ fn gen(self: *CodeGen) InnerError!void {...@@ -2339,7 +2301,7 @@ fn gen(self: *CodeGen) InnerError!void {
2339 else => |cc| return self.fail("{s} does not support var args", .{@tagName(cc)}),2301 else => |cc| return self.fail("{s} does not support var args", .{@tagName(cc)}),
2340 };2302 };
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
2344 try self.genBody(self.air.getMainBody());2306 try self.genBody(self.air.getMainBody());
23452307
...@@ -2356,7 +2318,7 @@ fn gen(self: *CodeGen) InnerError!void {...@@ -2356,7 +2318,7 @@ fn gen(self: *CodeGen) InnerError!void {
2356 }2318 }
2357 for (self.epilogue_relocs.items) |epilogue_reloc| self.performReloc(epilogue_reloc);2319 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);
2360 const backpatch_stack_dealloc = try self.asmPlaceholder();2322 const backpatch_stack_dealloc = try self.asmPlaceholder();
2361 const backpatch_pop_callee_preserved_regs = try self.asmPlaceholder();2323 const backpatch_pop_callee_preserved_regs = try self.asmPlaceholder();
2362 try self.asmRegister(.{ ._, .pop }, .rbp);2324 try self.asmRegister(.{ ._, .pop }, .rbp);
...@@ -2475,9 +2437,9 @@ fn gen(self: *CodeGen) InnerError!void {...@@ -2475,9 +2437,9 @@ fn gen(self: *CodeGen) InnerError!void {
2475 });2437 });
2476 }2438 }
2477 } else {2439 } 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);
2479 try self.genBody(self.air.getMainBody());2441 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);
2481 }2443 }
2482}2444}
24832445
...@@ -2498,9 +2460,9 @@ fn checkInvariantsAfterAirInst(self: *CodeGen) void {...@@ -2498,9 +2460,9 @@ fn checkInvariantsAfterAirInst(self: *CodeGen) void {
2498}2460}
24992461
2500fn genBodyBlock(self: *CodeGen, body: []const Air.Inst.Index) InnerError!void {2462fn 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);
2502 try self.genBody(body);2464 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);
2504}2466}
25052467
2506fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {2468fn 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 {...@@ -2544,7 +2506,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2544 .shuffle_one, .shuffle_two => @panic("x86_64 TODO: shuffle_one/shuffle_two"),2506 .shuffle_one, .shuffle_two => @panic("x86_64 TODO: shuffle_one/shuffle_two"),
2545 // zig fmt: on2507 // zig fmt: on
25462508
2547 .arg => if (cg.debug_output != .none) {2509 .arg => if (!cg.mod.strip) {
2548 // skip zero-bit arguments as they don't have a corresponding arg instruction2510 // skip zero-bit arguments as they don't have a corresponding arg instruction
2549 var arg_index = cg.arg_index;2511 var arg_index = cg.arg_index;
2550 while (cg.args[arg_index] == .none) arg_index += 1;2512 while (cg.args[arg_index] == .none) arg_index += 1;
...@@ -64179,9 +64141,9 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -64179,9 +64141,9 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
64179 .block => {64141 .block => {
64180 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;64142 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;
64181 const block = cg.air.extraData(Air.Block, ty_pl.payload);64143 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);
64183 try cg.lowerBlock(inst, @ptrCast(cg.air.extra.items[block.end..][0..block.data.body_len]));64145 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);
64185 },64147 },
64186 .loop => if (use_old) try cg.airLoop(inst) else {64148 .loop => if (use_old) try cg.airLoop(inst) else {
64187 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;64149 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;
...@@ -85191,7 +85153,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -85191,7 +85153,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
85191 .switch_dispatch => try cg.airSwitchDispatch(inst),85153 .switch_dispatch => try cg.airSwitchDispatch(inst),
85192 .@"try", .try_cold => try cg.airTry(inst),85154 .@"try", .try_cold => try cg.airTry(inst),
85193 .try_ptr, .try_ptr_cold => try cg.airTryPtr(inst),85155 .try_ptr, .try_ptr_cold => try cg.airTryPtr(inst),
85194 .dbg_stmt => if (cg.debug_output != .none) {85156 .dbg_stmt => if (!cg.mod.strip) {
85195 const dbg_stmt = air_datas[@intFromEnum(inst)].dbg_stmt;85157 const dbg_stmt = air_datas[@intFromEnum(inst)].dbg_stmt;
85196 _ = try cg.addInst(.{85158 _ = try cg.addInst(.{
85197 .tag = .pseudo,85159 .tag = .pseudo,
...@@ -85202,7 +85164,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -85202,7 +85164,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
85202 } },85164 } },
85203 });85165 });
85204 },85166 },
85205 .dbg_empty_stmt => if (cg.debug_output != .none) {85167 .dbg_empty_stmt => if (!cg.mod.strip) {
85206 if (cg.mir_instructions.len > 0) {85168 if (cg.mir_instructions.len > 0) {
85207 const prev_mir_op = &cg.mir_instructions.items(.ops)[cg.mir_instructions.len - 1];85169 const prev_mir_op = &cg.mir_instructions.items(.ops)[cg.mir_instructions.len - 1];
85208 if (prev_mir_op.* == .pseudo_dbg_line_line_column)85170 if (prev_mir_op.* == .pseudo_dbg_line_line_column)
...@@ -85216,13 +85178,13 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -85216,13 +85178,13 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
85216 const old_inline_func = cg.inline_func;85178 const old_inline_func = cg.inline_func;
85217 defer cg.inline_func = old_inline_func;85179 defer cg.inline_func = old_inline_func;
85218 cg.inline_func = dbg_inline_block.data.func;85180 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(.{
85220 .tag = .pseudo,85182 .tag = .pseudo,
85221 .ops = .pseudo_dbg_enter_inline_func,85183 .ops = .pseudo_dbg_enter_inline_func,
85222 .data = .{ .func = dbg_inline_block.data.func },85184 .data = .{ .func = dbg_inline_block.data.func },
85223 });85185 });
85224 try cg.lowerBlock(inst, @ptrCast(cg.air.extra.items[dbg_inline_block.end..][0..dbg_inline_block.data.body_len]));85186 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(.{
85226 .tag = .pseudo,85188 .tag = .pseudo,
85227 .ops = .pseudo_dbg_leave_inline_func,85189 .ops = .pseudo_dbg_leave_inline_func,
85228 .data = .{ .func = old_inline_func },85190 .data = .{ .func = old_inline_func },
...@@ -85231,7 +85193,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -85231,7 +85193,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
85231 .dbg_var_ptr,85193 .dbg_var_ptr,
85232 .dbg_var_val,85194 .dbg_var_val,
85233 .dbg_arg_inline,85195 .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) {
85235 const pl_op = air_datas[@intFromEnum(inst)].pl_op;85197 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
85236 var ops = try cg.tempsFromOperands(inst, .{pl_op.operand});85198 var ops = try cg.tempsFromOperands(inst, .{pl_op.operand});
85237 var mcv = ops[0].tracking(cg).short;85199 var mcv = ops[0].tracking(cg).short;
...@@ -173366,7 +173328,7 @@ fn airArg(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -173366,7 +173328,7 @@ fn airArg(self: *CodeGen, inst: Air.Inst.Index) !void {
173366 while (self.args[arg_index] == .none) arg_index += 1;173328 while (self.args[arg_index] == .none) arg_index += 1;
173367 self.arg_index = arg_index + 1;173329 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: {
173370 const arg_ty = self.typeOfIndex(inst);173332 const arg_ty = self.typeOfIndex(inst);
173371 const src_mcv = self.args[arg_index];173333 const src_mcv = self.args[arg_index];
173372 switch (src_mcv) {173334 switch (src_mcv) {
...@@ -173468,7 +173430,7 @@ fn airArg(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -173468,7 +173430,7 @@ fn airArg(self: *CodeGen, inst: Air.Inst.Index) !void {
173468}173430}
173469173431
173470fn airDbgVarArgs(self: *CodeGen) !void {173432fn airDbgVarArgs(self: *CodeGen) !void {
173471 if (self.debug_output == .none) return;173433 if (self.mod.strip) return;
173472 if (!self.pt.zcu.typeToFunc(self.fn_type).?.is_var_args) return;173434 if (!self.pt.zcu.typeToFunc(self.fn_type).?.is_var_args) return;
173473 try self.asmPseudo(.pseudo_dbg_var_args_none);173435 try self.asmPseudo(.pseudo_dbg_var_args_none);
173474}173436}
...@@ -173478,7 +173440,7 @@ fn genLocalDebugInfo(...@@ -173478,7 +173440,7 @@ fn genLocalDebugInfo(
173478 inst: Air.Inst.Index,173440 inst: Air.Inst.Index,
173479 mcv: MCValue,173441 mcv: MCValue,
173480) !void {173442) !void {
173481 if (self.debug_output == .none) return;173443 if (self.mod.strip) return;
173482 switch (self.air.instructions.items(.tag)[@intFromEnum(inst)]) {173444 switch (self.air.instructions.items(.tag)[@intFromEnum(inst)]) {
173483 else => unreachable,173445 else => unreachable,
173484 .arg, .dbg_arg_inline, .dbg_var_val => |tag| {173446 .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 {...@@ -1929,6 +1929,67 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
1929 mir.* = undefined;1929 mir.* = undefined;
1930}1930}
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
1932pub fn extraData(mir: Mir, comptime T: type, index: u32) struct { data: T, end: u32 } {1993pub fn extraData(mir: Mir, comptime T: type, index: u32) struct { data: T, end: u32 } {
1933 const fields = std.meta.fields(T);1994 const fields = std.meta.fields(T);
1934 var i: u32 = index;1995 var i: u32 = index;
...@@ -1987,3 +2048,7 @@ const IntegerBitSet = std.bit_set.IntegerBitSet;...@@ -1987,3 +2048,7 @@ const IntegerBitSet = std.bit_set.IntegerBitSet;
1987const InternPool = @import("../../InternPool.zig");2048const InternPool = @import("../../InternPool.zig");
1988const Mir = @This();2049const Mir = @This();
1989const Register = bits.Register;2050const 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(...@@ -182,7 +182,7 @@ pub fn emitFunction(
182 /// in the pipeline. Any information needed to call emit must be stored in MIR.182 /// in the pipeline. Any information needed to call emit must be stored in MIR.
183 /// This is `undefined` if the backend supports the `separate_thread` feature.183 /// This is `undefined` if the backend supports the `separate_thread` feature.
184 air: *const Air,184 air: *const Air,
185) Allocator.Error!void {185) CodeGenError!void {
186 const zcu = pt.zcu;186 const zcu = pt.zcu;
187 const func = zcu.funcInfo(func_index);187 const func = zcu.funcInfo(func_index);
188 const target = zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;188 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 {...@@ -985,7 +985,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {
985 assert(comp.freebsd_so_files == null);985 assert(comp.freebsd_so_files == null);
986 comp.freebsd_so_files = so_files;986 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;
989 var task_buffer_i: usize = 0;989 var task_buffer_i: usize = 0;
990990
991 {991 {
src/libs/glibc.zig+1-1
...@@ -1148,7 +1148,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {...@@ -1148,7 +1148,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {
1148 assert(comp.glibc_so_files == null);1148 assert(comp.glibc_so_files == null);
1149 comp.glibc_so_files = so_files;1149 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;
1152 var task_buffer_i: usize = 0;1152 var task_buffer_i: usize = 0;
11531153
1154 {1154 {
src/libs/netbsd.zig+1-1
...@@ -650,7 +650,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {...@@ -650,7 +650,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {
650 assert(comp.netbsd_so_files == null);650 assert(comp.netbsd_so_files == null);
651 comp.netbsd_so_files = so_files;651 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;
654 var task_buffer_i: usize = 0;654 var task_buffer_i: usize = 0;
655655
656 {656 {
src/link.zig+2
...@@ -759,6 +759,8 @@ pub const File = struct {...@@ -759,6 +759,8 @@ pub const File = struct {
759 switch (base.tag) {759 switch (base.tag) {
760 .lld => unreachable,760 .lld => unreachable,
761 inline else => |tag| {761 inline else => |tag| {
762 if (tag == .wasm) @panic("MLUGG TODO");
763 if (tag == .spirv) @panic("MLUGG TODO");
762 dev.check(tag.devFeature());764 dev.check(tag.devFeature());
763 return @as(*tag.Type(), @fieldParentPtr("base", base)).updateFunc(pt, func_index, mir, maybe_undef_air);765 return @as(*tag.Type(), @fieldParentPtr("base", base)).updateFunc(pt, func_index, mir, maybe_undef_air);
764 },766 },
src/link/Coff.zig+7-5
...@@ -1057,8 +1057,10 @@ pub fn updateFunc(...@@ -1057,8 +1057,10 @@ pub fn updateFunc(
1057 coff: *Coff,1057 coff: *Coff,
1058 pt: Zcu.PerThread,1058 pt: Zcu.PerThread,
1059 func_index: InternPool.Index,1059 func_index: InternPool.Index,
1060 air: Air,1060 mir: *const codegen.AnyMir,
1061 liveness: Air.Liveness,1061 /// This may be `undefined`; only pass it to `emitFunction`.
1062 /// This parameter will eventually be removed.
1063 maybe_undef_air: *const Air,
1062) link.File.UpdateNavError!void {1064) link.File.UpdateNavError!void {
1063 if (build_options.skip_non_native and builtin.object_format != .coff) {1065 if (build_options.skip_non_native and builtin.object_format != .coff) {
1064 @panic("Attempted to compile for object format that was disabled by build configuration");1066 @panic("Attempted to compile for object format that was disabled by build configuration");
...@@ -1079,15 +1081,15 @@ pub fn updateFunc(...@@ -1079,15 +1081,15 @@ pub fn updateFunc(
1079 var code_buffer: std.ArrayListUnmanaged(u8) = .empty;1081 var code_buffer: std.ArrayListUnmanaged(u8) = .empty;
1080 defer code_buffer.deinit(gpa);1082 defer code_buffer.deinit(gpa);
10811083
1082 try codegen.generateFunction(1084 try codegen.emitFunction(
1083 &coff.base,1085 &coff.base,
1084 pt,1086 pt,
1085 zcu.navSrcLoc(nav_index),1087 zcu.navSrcLoc(nav_index),
1086 func_index,1088 func_index,
1087 air,1089 mir,
1088 liveness,
1089 &code_buffer,1090 &code_buffer,
1090 .none,1091 .none,
1092 maybe_undef_air,
1091 );1093 );
10921094
1093 try coff.updateNavCode(pt, nav_index, code_buffer.items, .FUNCTION);1095 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;...@@ -13,6 +13,7 @@ const Path = std.Build.Cache.Path;
13const Zcu = @import("../Zcu.zig");13const Zcu = @import("../Zcu.zig");
14const InternPool = @import("../InternPool.zig");14const InternPool = @import("../InternPool.zig");
15const Compilation = @import("../Compilation.zig");15const Compilation = @import("../Compilation.zig");
16const codegen = @import("../codegen.zig");
16const link = @import("../link.zig");17const link = @import("../link.zig");
17const trace = @import("../tracy.zig").trace;18const trace = @import("../tracy.zig").trace;
18const build_options = @import("build_options");19const build_options = @import("build_options");
...@@ -72,14 +73,14 @@ pub fn updateFunc(...@@ -72,14 +73,14 @@ pub fn updateFunc(
72 self: *Goff,73 self: *Goff,
73 pt: Zcu.PerThread,74 pt: Zcu.PerThread,
74 func_index: InternPool.Index,75 func_index: InternPool.Index,
75 air: Air,76 mir: *const codegen.AnyMir,
76 liveness: Air.Liveness,77 maybe_undef_air: *const Air,
77) link.File.UpdateNavError!void {78) link.File.UpdateNavError!void {
78 _ = self;79 _ = self;
79 _ = pt;80 _ = pt;
80 _ = func_index;81 _ = func_index;
81 _ = air;82 _ = mir;
82 _ = liveness;83 _ = maybe_undef_air;
83 unreachable; // we always use llvm84 unreachable; // we always use llvm
84}85}
8586
src/link/MachO.zig+3-3
...@@ -3051,13 +3051,13 @@ pub fn updateFunc(...@@ -3051,13 +3051,13 @@ pub fn updateFunc(
3051 self: *MachO,3051 self: *MachO,
3052 pt: Zcu.PerThread,3052 pt: Zcu.PerThread,
3053 func_index: InternPool.Index,3053 func_index: InternPool.Index,
3054 air: Air,3054 mir: *const codegen.AnyMir,
3055 liveness: Air.Liveness,3055 maybe_undef_air: *const Air,
3056) link.File.UpdateNavError!void {3056) link.File.UpdateNavError!void {
3057 if (build_options.skip_non_native and builtin.object_format != .macho) {3057 if (build_options.skip_non_native and builtin.object_format != .macho) {
3058 @panic("Attempted to compile for object format that was disabled by build configuration");3058 @panic("Attempted to compile for object format that was disabled by build configuration");
3059 }3059 }
3060 return self.getZigObject().?.updateFunc(self, pt, func_index, air, liveness);3060 return self.getZigObject().?.updateFunc(self, pt, func_index, mir, maybe_undef_air);
3061}3061}
30623062
3063pub fn updateNav(self: *MachO, pt: Zcu.PerThread, nav: InternPool.Nav.Index) link.File.UpdateNavError!void {3063pub 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(...@@ -777,8 +777,10 @@ pub fn updateFunc(
777 macho_file: *MachO,777 macho_file: *MachO,
778 pt: Zcu.PerThread,778 pt: Zcu.PerThread,
779 func_index: InternPool.Index,779 func_index: InternPool.Index,
780 air: Air,780 mir: *const codegen.AnyMir,
781 liveness: Air.Liveness,781 /// This may be `undefined`; only pass it to `emitFunction`.
782 /// This parameter will eventually be removed.
783 maybe_undef_air: *const Air,
782) link.File.UpdateNavError!void {784) link.File.UpdateNavError!void {
783 const tracy = trace(@src());785 const tracy = trace(@src());
784 defer tracy.end();786 defer tracy.end();
...@@ -796,15 +798,15 @@ pub fn updateFunc(...@@ -796,15 +798,15 @@ pub fn updateFunc(
796 var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, func.owner_nav, sym_index) else null;798 var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, func.owner_nav, sym_index) else null;
797 defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit();799 defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit();
798800
799 try codegen.generateFunction(801 try codegen.emitFunction(
800 &macho_file.base,802 &macho_file.base,
801 pt,803 pt,
802 zcu.navSrcLoc(func.owner_nav),804 zcu.navSrcLoc(func.owner_nav),
803 func_index,805 func_index,
804 air,806 mir,
805 liveness,
806 &code_buffer,807 &code_buffer,
807 if (debug_wip_nav) |*wip_nav| .{ .dwarf = wip_nav } else .none,808 if (debug_wip_nav) |*wip_nav| .{ .dwarf = wip_nav } else .none,
809 maybe_undef_air,
808 );810 );
809 const code = code_buffer.items;811 const code = code_buffer.items;
810812
src/link/Plan9.zig+7-5
...@@ -386,8 +386,10 @@ pub fn updateFunc(...@@ -386,8 +386,10 @@ pub fn updateFunc(
386 self: *Plan9,386 self: *Plan9,
387 pt: Zcu.PerThread,387 pt: Zcu.PerThread,
388 func_index: InternPool.Index,388 func_index: InternPool.Index,
389 air: Air,389 mir: *const codegen.AnyMir,
390 liveness: Air.Liveness,390 /// This may be `undefined`; only pass it to `emitFunction`.
391 /// This parameter will eventually be removed.
392 maybe_undef_air: *const Air,
391) link.File.UpdateNavError!void {393) link.File.UpdateNavError!void {
392 if (build_options.skip_non_native and builtin.object_format != .plan9) {394 if (build_options.skip_non_native and builtin.object_format != .plan9) {
393 @panic("Attempted to compile for object format that was disabled by build configuration");395 @panic("Attempted to compile for object format that was disabled by build configuration");
...@@ -412,15 +414,15 @@ pub fn updateFunc(...@@ -412,15 +414,15 @@ pub fn updateFunc(
412 };414 };
413 defer dbg_info_output.dbg_line.deinit();415 defer dbg_info_output.dbg_line.deinit();
414416
415 try codegen.generateFunction(417 try codegen.emitFunction(
416 &self.base,418 &self.base,
417 pt,419 pt,
418 zcu.navSrcLoc(func.owner_nav),420 zcu.navSrcLoc(func.owner_nav),
419 func_index,421 func_index,
420 air,422 mir,
421 liveness,
422 &code_buffer,423 &code_buffer,
423 .{ .plan9 = &dbg_info_output },424 .{ .plan9 = &dbg_info_output },
425 maybe_undef_air,
424 );426 );
425 const code = try code_buffer.toOwnedSlice(gpa);427 const code = try code_buffer.toOwnedSlice(gpa);
426 self.getAtomPtr(atom_idx).code = .{428 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)...@@ -97,8 +97,7 @@ pub fn mirReady(q: *Queue, comp: *Compilation, mir: *ZcuTask.LinkFunc.SharedMir)
97 q.mutex.lock();97 q.mutex.lock();
98 defer q.mutex.unlock();98 defer q.mutex.unlock();
99 switch (q.state) {99 switch (q.state) {
100 .finished => unreachable, // there's definitely a task queued100 .finished, .running => return,
101 .running => return,
102 .wait_for_mir => |wait_for| if (wait_for != mir) return,101 .wait_for_mir => |wait_for| if (wait_for != mir) return,
103 }102 }
104 // We were waiting for `mir`, so we will restart the linker thread.103 // 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;...@@ -13,6 +13,7 @@ const Path = std.Build.Cache.Path;
13const Zcu = @import("../Zcu.zig");13const Zcu = @import("../Zcu.zig");
14const InternPool = @import("../InternPool.zig");14const InternPool = @import("../InternPool.zig");
15const Compilation = @import("../Compilation.zig");15const Compilation = @import("../Compilation.zig");
16const codegen = @import("../codegen.zig");
16const link = @import("../link.zig");17const link = @import("../link.zig");
17const trace = @import("../tracy.zig").trace;18const trace = @import("../tracy.zig").trace;
18const build_options = @import("build_options");19const build_options = @import("build_options");
...@@ -72,14 +73,14 @@ pub fn updateFunc(...@@ -72,14 +73,14 @@ pub fn updateFunc(
72 self: *Xcoff,73 self: *Xcoff,
73 pt: Zcu.PerThread,74 pt: Zcu.PerThread,
74 func_index: InternPool.Index,75 func_index: InternPool.Index,
75 air: Air,76 mir: *const codegen.AnyMir,
76 liveness: Air.Liveness,77 maybe_undef_air: *const Air,
77) link.File.UpdateNavError!void {78) link.File.UpdateNavError!void {
78 _ = self;79 _ = self;
79 _ = pt;80 _ = pt;
80 _ = func_index;81 _ = func_index;
81 _ = air;82 _ = mir;
82 _ = liveness;83 _ = maybe_undef_air;
83 unreachable; // we always use llvm84 unreachable; // we always use llvm
84}85}
8586