authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-11-27 10:48:11-05:00
committergravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-11-27 10:56:29-05:00
logdde5f15b494e97cbe54621f330f79cdcb3ee9439
treec354eb395cdd6e2e886c59fab06e7ce280722118
parentbd19f5e611da33d8ae236781a9725de636f0b201

interleave Air instructions and tags in printing Mir instructions


2 files changed, 15 insertions(+), 4 deletions(-)

src/arch/x86_64/CodeGen.zig+10-2
......@@ -86,6 +86,9 @@ next_stack_offset: u32 = 0,
8686/// Debug field, used to find bugs in the compiler.
8787air_bookkeeping: @TypeOf(air_bookkeeping_init) = air_bookkeeping_init,
8888
89/// For mir debug info, maps a mir index to a air index
90mir_to_air_map: if (builtin.mode == .Debug) std.AutoHashMap(Mir.Inst.Index, Air.Inst.Index) else void,
91
8992const air_bookkeeping_init = if (std.debug.runtime_safety) @as(usize, 0) else {};
9093
9194pub const MCValue = union(enum) {
......@@ -272,12 +275,14 @@ pub fn generate(
272275 .stack_align = undefined,
273276 .end_di_line = module_fn.rbrace_line,
274277 .end_di_column = module_fn.rbrace_column,
278 .mir_to_air_map = if (builtin.mode == .Debug) std.AutoHashMap(Mir.Inst.Index, Air.Inst.Index).init(bin_file.allocator) else {},
275279 };
276280 defer function.stack.deinit(bin_file.allocator);
277281 defer function.blocks.deinit(bin_file.allocator);
278282 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
279283 defer function.mir_instructions.deinit(bin_file.allocator);
280284 defer function.mir_extra.deinit(bin_file.allocator);
285 defer if (builtin.mode == .Debug) function.mir_to_air_map.deinit();
281286
282287 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
283288 error.CodegenFail => return FnResult{ .fail = function.err_msg.? },
......@@ -323,8 +328,8 @@ pub fn generate(
323328 const w = std.io.getStdErr().writer();
324329 w.print("# Begin Function MIR: {s}:\n", .{module_fn.owner_decl.name}) catch {};
325330 const print = @import("./PrintMir.zig"){ .mir = mir };
326 print.printMir(w) catch {}; // we don't care if the debug printing fails
327 w.print("# End Function MIR: {s}:\n\n", .{module_fn.owner_decl.name}) catch {};
331 print.printMir(w, function.mir_to_air_map, air) catch {}; // we don't care if the debug printing fails
332 w.print("# End Function MIR: {s}\n\n", .{module_fn.owner_decl.name}) catch {};
328333 }
329334
330335 if (function.err_msg) |em| {
......@@ -525,6 +530,9 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
525530 for (body) |inst| {
526531 const old_air_bookkeeping = self.air_bookkeeping;
527532 try self.ensureProcessDeathCapacity(Liveness.bpi);
533 if (builtin.mode == .Debug) {
534 try self.mir_to_air_map.put(@intCast(u32, self.mir_instructions.len), inst);
535 }
528536
529537 switch (air_tags[inst]) {
530538 // zig fmt: off
src/arch/x86_64/PrintMir.zig+5-2
......@@ -26,7 +26,7 @@ const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
2626
2727mir: Mir,
2828
29pub fn printMir(print: *const Print, w: anytype) !void {
29pub fn printMir(print: *const Print, w: anytype, mir_to_air_map: std.AutoHashMap(Mir.Inst.Index, Air.Inst.Index), air: Air) !void {
3030 const instruction_bytes = print.mir.instructions.len *
3131 // Here we don't use @sizeOf(Mir.Inst.Data) because it would include
3232 // the debug safety tag but we want to measure release size.
......@@ -49,8 +49,11 @@ pub fn printMir(print: *const Print, w: anytype) !void {
4949 const mir_tags = print.mir.instructions.items(.tag);
5050
5151 for (mir_tags) |tag, index| {
52 try w.writeAll(" ");
5352 const inst = @intCast(u32, index);
53 if (mir_to_air_map.get(inst)) |air_index| {
54 try w.print("air index %{} ({}) for following mir inst(s)\n", .{ air_index, air.instructions.items(.tag)[air_index] });
55 }
56 try w.writeAll(" ");
5457 switch (tag) {
5558 .adc => try print.mirArith(.adc, inst, w),
5659 .add => try print.mirArith(.add, inst, w),