authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-11 22:29:02+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-05-11 20:31:51+02:00
log6c16465d45527c195302beb1f3a1a6d41cdcdd92
tree71218d64ba9201bd02479d540ebe5251dbe721d2
parent83ab1ba8fdb6900e63e1e0aa3a5e1ab966fc2022
signaturelock-open Commit is signed but in an unrecognized format.

spirv: lower air optional_payload

Implements lowering the AIR tag optional_payload. Also fixes an issue with lowering constant ints.

1 files changed, 24 insertions(+), 5 deletions(-)

src/codegen/spirv.zig+24-5
......@@ -957,11 +957,11 @@ pub const DeclGen = struct {
957957
958958 switch (ty.zigTypeTag()) {
959959 .Int => {
960 const int_bits = if (ty.isSignedInt())
961 @bitCast(u64, val.toSignedInt(target))
962 else
963 val.toUnsignedInt(target);
964 try self.genConstInt(result_ty_ref, result_id, int_bits);
960 if (ty.isSignedInt()) {
961 try self.genConstInt(result_ty_ref, result_id, val.toSignedInt(target));
962 } else {
963 try self.genConstInt(result_ty_ref, result_id, val.toUnsignedInt(target));
964 }
965965 },
966966 .Bool => {
967967 const operands = .{ .id_result_type = result_ty_id, .id_result = result_id };
......@@ -1717,6 +1717,8 @@ pub const DeclGen = struct {
17171717 .is_null => try self.airIsNull(inst, .is_null),
17181718 .is_non_null => try self.airIsNull(inst, .is_non_null),
17191719
1720 .optional_payload => try self.airUnwrapOptional(inst),
1721
17201722 .assembly => try self.airAssembly(inst),
17211723
17221724 .call => try self.airCall(inst, .auto),
......@@ -2694,6 +2696,23 @@ pub const DeclGen = struct {
26942696 };
26952697 }
26962698
2699 fn airUnwrapOptional(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2700 if (self.liveness.isUnused(inst)) return null;
2701
2702 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2703 const operand_id = try self.resolve(ty_op.operand);
2704 const optional_ty = self.air.typeOf(ty_op.operand);
2705 const payload_ty = self.air.typeOfIndex(inst);
2706
2707 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) return null;
2708
2709 if (optional_ty.optionalReprIsPayload()) {
2710 return operand_id;
2711 }
2712
2713 return try self.extractField(payload_ty, operand_id, 0);
2714 }
2715
26972716 fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void {
26982717 const target = self.getTarget();
26992718 const pl_op = self.air.instructions.items(.data)[inst].pl_op;