aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-09-27 23:11:00 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-09-27 23:11:00 -0700
commit09e1f37cb6a8e0df4c521f4b76eab07f0c811852 (patch)
treecce1b86a1cd273841a660e5438f714cfbaea74a7 /src/codegen/llvm.zig
parentc2a7542df5e9e93289a5d487ba3bbc37c12ffc11 (diff)
downloadzig-09e1f37cb6a8e0df4c521f4b76eab07f0c811852.tar.gz
zig-09e1f37cb6a8e0df4c521f4b76eab07f0c811852.zip
stage2: implement union coercion to its own tag
* AIR: add `get_union_tag` instruction - implement in LLVM backend * Sema: implement == and != for union and enum literal - Also implement coercion from union to its own tag type * Value: implement hashing for union values The motivating example is this snippet: comptime assert(@typeInfo(T) == .Float); This was the next blocker for stage2 building compiler-rt. Now it is switch at compile-time on an integer.
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index ab164b5d91..4a0d218ead 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1304,6 +1304,7 @@ pub const FuncGen = struct {
.memset => try self.airMemset(inst),
.memcpy => try self.airMemcpy(inst),
.set_union_tag => try self.airSetUnionTag(inst),
+ .get_union_tag => try self.airGetUnionTag(inst),
.atomic_store_unordered => try self.airAtomicStore(inst, .Unordered),
.atomic_store_monotonic => try self.airAtomicStore(inst, .Monotonic),
@@ -2557,6 +2558,18 @@ pub const FuncGen = struct {
return null;
}
+ fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
+ if (self.liveness.isUnused(inst))
+ return null;
+
+ const ty_op = self.air.instructions.items(.data)[inst].ty_op;
+ const un_ty = self.air.typeOf(ty_op.operand);
+ const un = try self.resolveInst(ty_op.operand);
+
+ _ = un_ty; // TODO handle when onlyTagHasCodegenBits() == true and other union forms
+ return self.builder.buildExtractValue(un, 1, "");
+ }
+
fn fieldPtr(
self: *FuncGen,
inst: Air.Inst.Index,