authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-02 23:05:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-04 15:57:40-07:00
log3a9375cae9a3385278e43a2785f4ccfe0dc47c2e
tree2f6795a701780942c6cd48eb5f76180dfeb84f56
parent954019983d17fad9dac1c80e2de92cb7ebe7cd08

wasm codegen: fix some missing Liveness reaps

I did not do a full audit, but I did notice a few issues which are resolved in this commit. Probably it would be worth adding debug infrastructure to assert that the number of reaps equals the number of calls to resolveInst() per air lowering function.

1 files changed, 8 insertions(+), 6 deletions(-)

src/arch/wasm/CodeGen.zig+8-6
...@@ -2001,7 +2001,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2001,7 +2001,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20012001
2002 try func.restoreStackPointer();2002 try func.restoreStackPointer();
2003 try func.addTag(.@"return");2003 try func.addTag(.@"return");
2004 return func.finishAir(inst, .none, &.{});2004 return func.finishAir(inst, .none, &.{un_op});
2005}2005}
20062006
2007fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.Modifier) InnerError!void {2007fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.Modifier) InnerError!void {
...@@ -3161,7 +3161,7 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3161,7 +3161,7 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3161 }3161 }
3162 break :result func.reuseOperand(ty_op.operand, operand);3162 break :result func.reuseOperand(ty_op.operand, operand);
3163 } else WValue{ .none = {} };3163 } else WValue{ .none = {} };
3164 func.finishAir(inst, result, &.{});3164 func.finishAir(inst, result, &.{ty_op.operand});
3165}3165}
31663166
3167fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) InnerError!WValue {3167fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) InnerError!WValue {
...@@ -4115,7 +4115,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4115,7 +4115,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4115 const len = try func.resolveInst(bin_op.rhs);4115 const len = try func.resolveInst(bin_op.rhs);
4116 try func.memset(ptr, len, value);4116 try func.memset(ptr, len, value);
41174117
4118 func.finishAir(inst, .none, &.{pl_op.operand});4118 func.finishAir(inst, .none, &.{ pl_op.operand, bin_op.lhs, bin_op.rhs });
4119}4119}
41204120
4121/// Sets a region of memory at `ptr` to the value of `value`4121/// Sets a region of memory at `ptr` to the value of `value`
...@@ -4424,6 +4424,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4424,6 +4424,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4424 else => unreachable,4424 else => unreachable,
4425 }4425 }
4426 };4426 };
4427 // TODO: this is incorrect Liveness handling code
4427 func.finishAir(inst, result, &.{});4428 func.finishAir(inst, result, &.{});
4428}4429}
44294430
...@@ -4747,7 +4748,7 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4747,7 +4748,7 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4747 const len = try func.resolveInst(bin_op.rhs);4748 const len = try func.resolveInst(bin_op.rhs);
4748 try func.memcpy(dst, src, len);4749 try func.memcpy(dst, src, len);
47494750
4750 func.finishAir(inst, .none, &.{pl_op.operand});4751 func.finishAir(inst, .none, &.{ pl_op.operand, bin_op.lhs, bin_op.rhs });
4751}4752}
47524753
4753fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4754fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
...@@ -5158,7 +5159,8 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerE...@@ -5158,7 +5159,8 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerE
5158fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5159fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5159 const pl_op = func.air.instructions.items(.data)[inst].pl_op;5160 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
5160 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;5161 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;
5161 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });5162 if (func.liveness.isUnused(inst))
5163 return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs, pl_op.operand });
51625164
5163 const ty = func.air.typeOfIndex(inst);5165 const ty = func.air.typeOfIndex(inst);
5164 if (ty.zigTypeTag() == .Vector) {5166 if (ty.zigTypeTag() == .Vector) {
...@@ -5186,7 +5188,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5186,7 +5188,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5186 break :result try (try func.binOp(mul_result, addend, ty, .add)).toLocal(func, ty);5188 break :result try (try func.binOp(mul_result, addend, ty, .add)).toLocal(func, ty);
5187 };5189 };
51885190
5189 func.finishAir(inst, result, &.{ bin_op.lhs, bin_op.rhs });5191 func.finishAir(inst, result, &.{ bin_op.lhs, bin_op.rhs, pl_op.operand });
5190}5192}
51915193
5192fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5194fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {