| ... | ... | @@ -1037,9 +1037,9 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 1037 | 1037 | fn processDeath(self: *Self, inst: Air.Inst.Index) void { |
| 1038 | 1038 | const air_tags = self.air.instructions.items(.tag); |
| 1039 | 1039 | if (air_tags[inst] == .constant) return; // Constants are immortal. |
| 1040 | const prev_value = self.getResolvedInstValue(inst) orelse return; |
| 1040 | 1041 | log.debug("%{d} => {}", .{ inst, MCValue.dead }); |
| 1041 | 1042 | // When editing this function, note that the logic must synchronize with `reuseOperand`. |
| 1042 | | const prev_value = self.getResolvedInstValue(inst); |
| 1043 | 1043 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 1044 | 1044 | branch.inst_table.putAssumeCapacity(inst, .dead); |
| 1045 | 1045 | switch (prev_value) { |
| ... | ... | @@ -1225,7 +1225,7 @@ fn revertState(self: *Self, state: State) void { |
| 1225 | 1225 | pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void { |
| 1226 | 1226 | const stack_mcv = try self.allocRegOrMem(inst, false); |
| 1227 | 1227 | log.debug("spilling %{d} to stack mcv {any}", .{ inst, stack_mcv }); |
| 1228 | | const reg_mcv = self.getResolvedInstValue(inst); |
| 1228 | const reg_mcv = self.getResolvedInstValue(inst).?; |
| 1229 | 1229 | switch (reg_mcv) { |
| 1230 | 1230 | .register => |other| { |
| 1231 | 1231 | assert(reg.to64() == other.to64()); |
| ... | ... | @@ -1242,7 +1242,7 @@ pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void |
| 1242 | 1242 | |
| 1243 | 1243 | pub fn spillEflagsIfOccupied(self: *Self) !void { |
| 1244 | 1244 | if (self.eflags_inst) |inst_to_save| { |
| 1245 | | const mcv = self.getResolvedInstValue(inst_to_save); |
| 1245 | const mcv = self.getResolvedInstValue(inst_to_save).?; |
| 1246 | 1246 | const new_mcv = switch (mcv) { |
| 1247 | 1247 | .register_overflow => try self.allocRegOrMem(inst_to_save, false), |
| 1248 | 1248 | .eflags => try self.allocRegOrMem(inst_to_save, true), |
| ... | ... | @@ -6315,18 +6315,17 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue { |
| 6315 | 6315 | return gop.value_ptr.*; |
| 6316 | 6316 | }, |
| 6317 | 6317 | .const_ty => unreachable, |
| 6318 | | else => return self.getResolvedInstValue(inst_index), |
| 6318 | else => return self.getResolvedInstValue(inst_index).?, |
| 6319 | 6319 | } |
| 6320 | 6320 | } |
| 6321 | 6321 | |
| 6322 | | fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue { |
| 6322 | fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) ?MCValue { |
| 6323 | 6323 | // Treat each stack item as a "layer" on top of the previous one. |
| 6324 | 6324 | var i: usize = self.branch_stack.items.len; |
| 6325 | 6325 | while (true) { |
| 6326 | 6326 | i -= 1; |
| 6327 | 6327 | if (self.branch_stack.items[i].inst_table.get(inst)) |mcv| { |
| 6328 | | assert(mcv != .dead); |
| 6329 | | return mcv; |
| 6328 | return if (mcv != .dead) mcv else null; |
| 6330 | 6329 | } |
| 6331 | 6330 | } |
| 6332 | 6331 | } |