authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-04-10 09:55:51+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-04-20 20:28:48+01:00
log4486f271266b330f683ccc266ce19ddbd55e7f59
treedaa1d9548518b61f1f218eade3497f5acb63c576
parent02a8b66b003bcf7fd8a7629f6c155df1d7e0a360
signature Commit is signed but in an unrecognized format.

print_air: print new Liveness data

`try`, `try_ptr`, and `block` now have extra payloads.

1 files changed, 44 insertions(+), 0 deletions(-)

src/print_air.zig+44
......@@ -389,6 +389,10 @@ const Writer = struct {
389389 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
390390 const extra = w.air.extraData(Air.Block, ty_pl.payload);
391391 const body = w.air.extra[extra.end..][0..extra.data.body_len];
392 const liveness_block = if (w.liveness) |liveness|
393 liveness.getBlock(inst)
394 else
395 Liveness.BlockSlices{ .deaths = &.{} };
392396
393397 try w.writeType(s, w.air.getRefType(ty_pl.ty));
394398 if (w.skip_body) return s.writeAll(", ...");
......@@ -399,6 +403,10 @@ const Writer = struct {
399403 w.indent = old_indent;
400404 try s.writeByteNTimes(' ', w.indent);
401405 try s.writeAll("}");
406
407 for (liveness_block.deaths) |operand| {
408 try s.print(" %{d}!", .{operand});
409 }
402410 }
403411
404412 fn writeLoop(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
......@@ -737,22 +745,44 @@ const Writer = struct {
737745 const pl_op = w.air.instructions.items(.data)[inst].pl_op;
738746 const extra = w.air.extraData(Air.Try, pl_op.payload);
739747 const body = w.air.extra[extra.end..][0..extra.data.body_len];
748 const liveness_condbr = if (w.liveness) |liveness|
749 liveness.getCondBr(inst)
750 else
751 Liveness.CondBrSlices{ .then_deaths = &.{}, .else_deaths = &.{} };
740752
741753 try w.writeOperand(s, inst, 0, pl_op.operand);
742754 if (w.skip_body) return s.writeAll(", ...");
743755 try s.writeAll(", {\n");
744756 const old_indent = w.indent;
745757 w.indent += 2;
758
759 if (liveness_condbr.else_deaths.len != 0) {
760 try s.writeByteNTimes(' ', w.indent);
761 for (liveness_condbr.else_deaths, 0..) |operand, i| {
762 if (i != 0) try s.writeAll(" ");
763 try s.print("%{d}!", .{operand});
764 }
765 try s.writeAll("\n");
766 }
746767 try w.writeBody(s, body);
768
747769 w.indent = old_indent;
748770 try s.writeByteNTimes(' ', w.indent);
749771 try s.writeAll("}");
772
773 for (liveness_condbr.then_deaths) |operand| {
774 try s.print(" %{d}!", .{operand});
775 }
750776 }
751777
752778 fn writeTryPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
753779 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
754780 const extra = w.air.extraData(Air.TryPtr, ty_pl.payload);
755781 const body = w.air.extra[extra.end..][0..extra.data.body_len];
782 const liveness_condbr = if (w.liveness) |liveness|
783 liveness.getCondBr(inst)
784 else
785 Liveness.CondBrSlices{ .then_deaths = &.{}, .else_deaths = &.{} };
756786
757787 try w.writeOperand(s, inst, 0, extra.data.ptr);
758788
......@@ -762,10 +792,24 @@ const Writer = struct {
762792 try s.writeAll(", {\n");
763793 const old_indent = w.indent;
764794 w.indent += 2;
795
796 if (liveness_condbr.else_deaths.len != 0) {
797 try s.writeByteNTimes(' ', w.indent);
798 for (liveness_condbr.else_deaths, 0..) |operand, i| {
799 if (i != 0) try s.writeAll(" ");
800 try s.print("%{d}!", .{operand});
801 }
802 try s.writeAll("\n");
803 }
765804 try w.writeBody(s, body);
805
766806 w.indent = old_indent;
767807 try s.writeByteNTimes(' ', w.indent);
768808 try s.writeAll("}");
809
810 for (liveness_condbr.then_deaths) |operand| {
811 try s.print(" %{d}!", .{operand});
812 }
769813 }
770814
771815 fn writeCondBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {