aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv.zig
diff options
context:
space:
mode:
authorAli Chraghi <alichraghi@proton.me>2023-05-17 11:24:09 +0330
committerAli Chraghi <alichraghi@proton.me>2023-05-20 18:43:26 +0330
commitfedc9a19e7909694fac107c3da245e08616fd6e4 (patch)
tree57e7bc6dc89a86b2a17d87d8bce5b9a0f99ed42e /src/codegen/spirv.zig
parent40e8c2243c139dc499298645a2b387e30ae09cba (diff)
downloadzig-fedc9a19e7909694fac107c3da245e08616fd6e4.tar.gz
zig-fedc9a19e7909694fac107c3da245e08616fd6e4.zip
spirv: lower get_union_tag
Diffstat (limited to 'src/codegen/spirv.zig')
-rw-r--r--src/codegen/spirv.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig
index d1def8a02e..1793e9fe18 100644
--- a/src/codegen/spirv.zig
+++ b/src/codegen/spirv.zig
@@ -1735,6 +1735,7 @@ pub const DeclGen = struct {
.slice_elem_val => try self.airSliceElemVal(inst),
.ptr_elem_ptr => try self.airPtrElemPtr(inst),
+ .get_union_tag => try self.airGetUnionTag(inst),
.struct_field_val => try self.airStructFieldVal(inst),
.struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0),
@@ -2320,6 +2321,22 @@ pub const DeclGen = struct {
return result_id;
}
+ fn airGetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
+ const ty_op = self.air.instructions.items(.data)[inst].ty_op;
+ const un_ty = self.air.typeOf(ty_op.operand);
+
+ const target = self.module.getTarget();
+ const layout = un_ty.unionGetLayout(target);
+ if (layout.tag_size == 0) return null;
+
+ const union_handle = try self.resolve(ty_op.operand);
+ if (layout.payload_size == 0) return union_handle;
+
+ const tag_ty = un_ty.unionTagTypeSafety().?;
+ const tag_index = @boolToInt(layout.tag_align < layout.payload_align);
+ return try self.extractField(tag_ty, union_handle, tag_index);
+ }
+
fn airStructFieldVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null;