| ... | @@ -222,6 +222,14 @@ const Branch = struct { | ... | @@ -222,6 +222,14 @@ const Branch = struct { |
| 222 | try writer.writeAll("}"); | 222 | try writer.writeAll("}"); |
| 223 | } | 223 | } |
| 224 | | 224 | |
| | 225 | fn format(branch: Branch, comptime unused_format_string: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { |
| | 226 | _ = branch; |
| | 227 | _ = unused_format_string; |
| | 228 | _ = options; |
| | 229 | _ = writer; |
| | 230 | @compileError("do not format Branch directly; use ty.fmtDebug()"); |
| | 231 | } |
| | 232 | |
| 225 | fn fmtDebug(self: @This()) std.fmt.Formatter(fmt) { | 233 | fn fmtDebug(self: @This()) std.fmt.Formatter(fmt) { |
| 226 | return .{ .data = .{ | 234 | return .{ .data = .{ |
| 227 | .insts = self.inst_table.keys(), | 235 | .insts = self.inst_table.keys(), |
| ... | @@ -823,7 +831,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { | ... | @@ -823,7 +831,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 823 | fn processDeath(self: *Self, inst: Air.Inst.Index) void { | 831 | fn processDeath(self: *Self, inst: Air.Inst.Index) void { |
| 824 | const air_tags = self.air.instructions.items(.tag); | 832 | const air_tags = self.air.instructions.items(.tag); |
| 825 | if (air_tags[inst] == .constant) return; // Constants are immortal. | 833 | if (air_tags[inst] == .constant) return; // Constants are immortal. |
| 826 | log.debug(" (processing death of %{d})", .{inst}); | 834 | log.debug("%{d} => {}", .{ inst, MCValue.dead }); |
| 827 | // When editing this function, note that the logic must synchronize with `reuseOperand`. | 835 | // When editing this function, note that the logic must synchronize with `reuseOperand`. |
| 828 | const prev_value = self.getResolvedInstValue(inst); | 836 | const prev_value = self.getResolvedInstValue(inst); |
| 829 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; | 837 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| ... | @@ -851,10 +859,8 @@ fn finishAirBookkeeping(self: *Self) void { | ... | @@ -851,10 +859,8 @@ fn finishAirBookkeeping(self: *Self) void { |
| 851 | } | 859 | } |
| 852 | | 860 | |
| 853 | fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void { | 861 | fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Liveness.bpi - 1]Air.Inst.Ref) void { |
| 854 | log.debug("finishAir: %{d}, {}, {any}", .{ inst, result, operands }); | | |
| 855 | var tomb_bits = self.liveness.getTombBits(inst); | 862 | var tomb_bits = self.liveness.getTombBits(inst); |
| 856 | for (operands) |op| { | 863 | for (operands) |op| { |
| 857 | log.debug(" (processing {})", .{op}); | | |
| 858 | const dies = @truncate(u1, tomb_bits) != 0; | 864 | const dies = @truncate(u1, tomb_bits) != 0; |
| 859 | tomb_bits >>= 1; | 865 | tomb_bits >>= 1; |
| 860 | if (!dies) continue; | 866 | if (!dies) continue; |
| ... | @@ -865,7 +871,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live | ... | @@ -865,7 +871,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live |
| 865 | } | 871 | } |
| 866 | const is_used = @truncate(u1, tomb_bits) == 0; | 872 | const is_used = @truncate(u1, tomb_bits) == 0; |
| 867 | if (is_used) { | 873 | if (is_used) { |
| 868 | log.debug(" (saving %{d} => {})", .{ inst, result }); | 874 | log.debug("%{d} => {}", .{ inst, result }); |
| 869 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; | 875 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 870 | branch.inst_table.putAssumeCapacityNoClobber(inst, result); | 876 | branch.inst_table.putAssumeCapacityNoClobber(inst, result); |
| 871 | | 877 | |
| ... | @@ -4678,8 +4684,6 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4678,8 +4684,6 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4678 | | 4684 | |
| 4679 | const reloc = try self.genCondBrMir(cond_ty, cond); | 4685 | const reloc = try self.genCondBrMir(cond_ty, cond); |
| 4680 | | 4686 | |
| 4681 | log.debug("airCondBr: %{d}", .{inst}); | | |
| 4682 | | | |
| 4683 | // If the condition dies here in this condbr instruction, process | 4687 | // If the condition dies here in this condbr instruction, process |
| 4684 | // that death now instead of later as this has an effect on | 4688 | // that death now instead of later as this has an effect on |
| 4685 | // whether it needs to be spilled in the branches | 4689 | // whether it needs to be spilled in the branches |
| ... | @@ -4736,6 +4740,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4736,6 +4740,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4736 | // that we can use all the code emitting abstractions. This is why at the bottom we | 4740 | // that we can use all the code emitting abstractions. This is why at the bottom we |
| 4737 | // assert that parent_branch.free_registers equals the saved_then_branch.free_registers | 4741 | // assert that parent_branch.free_registers equals the saved_then_branch.free_registers |
| 4738 | // rather than assigning it. | 4742 | // rather than assigning it. |
| | 4743 | log.debug("airCondBr: %{d}", .{inst}); |
| 4739 | log.debug("Upper branches:", .{}); | 4744 | log.debug("Upper branches:", .{}); |
| 4740 | for (self.branch_stack.items) |bs| { | 4745 | for (self.branch_stack.items) |bs| { |
| 4741 | log.debug("{}", .{bs.fmtDebug()}); | 4746 | log.debug("{}", .{bs.fmtDebug()}); |
| ... | @@ -5119,8 +5124,6 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -5119,8 +5124,6 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5119 | ); | 5124 | ); |
| 5120 | defer self.gpa.free(liveness.deaths); | 5125 | defer self.gpa.free(liveness.deaths); |
| 5121 | | 5126 | |
| 5122 | log.debug("airSwitch: %{d}", .{inst}); | | |
| 5123 | | | |
| 5124 | // If the condition dies here in this switch instruction, process | 5127 | // If the condition dies here in this switch instruction, process |
| 5125 | // that death now instead of later as this has an effect on | 5128 | // that death now instead of later as this has an effect on |
| 5126 | // whether it needs to be spilled in the branches | 5129 | // whether it needs to be spilled in the branches |
| ... | @@ -5207,6 +5210,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -5207,6 +5210,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5207 | | 5210 | |
| 5208 | // Consolidate returned MCValues between prongs and else branch like we do | 5211 | // Consolidate returned MCValues between prongs and else branch like we do |
| 5209 | // in airCondBr. | 5212 | // in airCondBr. |
| | 5213 | log.debug("airSwitch: %{d}", .{inst}); |
| 5210 | log.debug("Upper branches:", .{}); | 5214 | log.debug("Upper branches:", .{}); |
| 5211 | for (self.branch_stack.items) |bs| { | 5215 | for (self.branch_stack.items) |bs| { |
| 5212 | log.debug("{}", .{bs.fmtDebug()}); | 5216 | log.debug("{}", .{bs.fmtDebug()}); |