aarch64: implement .wrap_optional always saving to the stack
This commit is contained in:
@@ -3068,13 +3068,37 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
|
||||
fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
|
||||
const ty_op = self.air.instructions.items(.data)[inst].ty_op;
|
||||
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
|
||||
const optional_ty = self.air.typeOfIndex(inst);
|
||||
|
||||
// Optional with a zero-bit payload type is just a boolean true
|
||||
if (optional_ty.abiSize(self.target.*) == 1)
|
||||
const payload_ty = self.air.typeOf(ty_op.operand);
|
||||
if (!payload_ty.hasRuntimeBits()) {
|
||||
break :result MCValue{ .immediate = 1 };
|
||||
}
|
||||
|
||||
return self.fail("TODO implement wrap optional for {}", .{self.target.cpu.arch});
|
||||
const optional_ty = self.air.typeOfIndex(inst);
|
||||
const operand = try self.resolveInst(ty_op.operand);
|
||||
const operand_lock: ?RegisterLock = switch (operand) {
|
||||
.register => |reg| self.register_manager.lockRegAssumeUnused(reg),
|
||||
else => null,
|
||||
};
|
||||
defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);
|
||||
|
||||
if (optional_ty.isPtrLikeOptional()) {
|
||||
// TODO should we check if we can reuse the operand?
|
||||
const raw_reg = try self.register_manager.allocReg(inst, gp);
|
||||
const reg = self.registerAlias(raw_reg, payload_ty);
|
||||
try self.genSetReg(payload_ty, raw_reg, operand);
|
||||
break :result MCValue{ .register = reg };
|
||||
}
|
||||
|
||||
const optional_abi_size = @intCast(u32, optional_ty.abiSize(self.target.*));
|
||||
const optional_abi_align = optional_ty.abiAlignment(self.target.*);
|
||||
const payload_abi_size = @intCast(u32, payload_ty.abiSize(self.target.*));
|
||||
const offset = optional_abi_size - payload_abi_size;
|
||||
|
||||
const stack_offset = try self.allocMem(optional_abi_size, optional_abi_align, inst);
|
||||
try self.genSetStack(Type.bool, stack_offset, .{ .immediate = 1 });
|
||||
try self.genSetStack(payload_ty, stack_offset - @intCast(u32, offset), operand);
|
||||
|
||||
break :result MCValue{ .stack_offset = stack_offset };
|
||||
};
|
||||
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user