diff options
| author | Robin Voetter <robin@voetter.nl> | 2023-04-11 22:29:02 +0200 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2023-05-11 20:31:51 +0200 |
| commit | 6c16465d45527c195302beb1f3a1a6d41cdcdd92 (patch) | |
| tree | 71218d64ba9201bd02479d540ebe5251dbe721d2 /src/codegen/spirv.zig | |
| parent | 83ab1ba8fdb6900e63e1e0aa3a5e1ab966fc2022 (diff) | |
| download | zig-6c16465d45527c195302beb1f3a1a6d41cdcdd92.tar.gz zig-6c16465d45527c195302beb1f3a1a6d41cdcdd92.zip | |
spirv: lower air optional_payload
Implements lowering the AIR tag optional_payload.
Also fixes an issue with lowering constant ints.
Diffstat (limited to 'src/codegen/spirv.zig')
| -rw-r--r-- | src/codegen/spirv.zig | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 0388466c10..ab2bdd64a7 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -957,11 +957,11 @@ pub const DeclGen = struct { switch (ty.zigTypeTag()) { .Int => { - const int_bits = if (ty.isSignedInt()) - @bitCast(u64, val.toSignedInt(target)) - else - val.toUnsignedInt(target); - try self.genConstInt(result_ty_ref, result_id, int_bits); + if (ty.isSignedInt()) { + try self.genConstInt(result_ty_ref, result_id, val.toSignedInt(target)); + } else { + try self.genConstInt(result_ty_ref, result_id, val.toUnsignedInt(target)); + } }, .Bool => { const operands = .{ .id_result_type = result_ty_id, .id_result = result_id }; @@ -1717,6 +1717,8 @@ pub const DeclGen = struct { .is_null => try self.airIsNull(inst, .is_null), .is_non_null => try self.airIsNull(inst, .is_non_null), + .optional_payload => try self.airUnwrapOptional(inst), + .assembly => try self.airAssembly(inst), .call => try self.airCall(inst, .auto), @@ -2694,6 +2696,23 @@ pub const DeclGen = struct { }; } + fn airUnwrapOptional(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { + if (self.liveness.isUnused(inst)) return null; + + const ty_op = self.air.instructions.items(.data)[inst].ty_op; + const operand_id = try self.resolve(ty_op.operand); + const optional_ty = self.air.typeOf(ty_op.operand); + const payload_ty = self.air.typeOfIndex(inst); + + if (!payload_ty.hasRuntimeBitsIgnoreComptime()) return null; + + if (optional_ty.optionalReprIsPayload()) { + return operand_id; + } + + return try self.extractField(payload_ty, operand_id, 0); + } + fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void { const target = self.getTarget(); const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
