aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-05-06 19:20:52 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:42:29 -0700
commit75900ec1b5a250935a6abe050a006738fba99e66 (patch)
tree9d3dd571b59648a585c3ce5bcdb2dbb50a574d58 /src/codegen/spirv.zig
parent73720b6975e2650ece48cc5f38495c091360c6c9 (diff)
downloadzig-75900ec1b5a250935a6abe050a006738fba99e66.tar.gz
zig-75900ec1b5a250935a6abe050a006738fba99e66.zip
stage2: move integer values to InternPool
Diffstat (limited to 'src/codegen/spirv.zig')
-rw-r--r--src/codegen/spirv.zig46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig
index e3b5d24ed9..32e0c13c37 100644
--- a/src/codegen/spirv.zig
+++ b/src/codegen/spirv.zig
@@ -555,15 +555,15 @@ pub const DeclGen = struct {
// TODO: Swap endianess if the compiler is big endian.
switch (ty.floatBits(target)) {
16 => {
- const float_bits = val.toFloat(f16);
+ const float_bits = val.toFloat(f16, mod);
try self.addBytes(std.mem.asBytes(&float_bits)[0..@intCast(usize, len)]);
},
32 => {
- const float_bits = val.toFloat(f32);
+ const float_bits = val.toFloat(f32, mod);
try self.addBytes(std.mem.asBytes(&float_bits)[0..@intCast(usize, len)]);
},
64 => {
- const float_bits = val.toFloat(f64);
+ const float_bits = val.toFloat(f64, mod);
try self.addBytes(std.mem.asBytes(&float_bits)[0..@intCast(usize, len)]);
},
else => unreachable,
@@ -584,7 +584,7 @@ pub const DeclGen = struct {
// TODO: Properly lower function pointers. For now we are going to hack around it and
// just generate an empty pointer. Function pointers are represented by usize for now,
// though.
- try self.addInt(Type.usize, Value.initTag(.zero));
+ try self.addInt(Type.usize, Value.zero);
// TODO: Add dependency
return;
},
@@ -743,8 +743,7 @@ pub const DeclGen = struct {
try self.addUndef(padding);
},
.Enum => {
- var int_val_buffer: Value.Payload.U64 = undefined;
- const int_val = val.enumToInt(ty, &int_val_buffer);
+ const int_val = try val.enumToInt(ty, mod);
const int_ty = ty.intTagType();
@@ -787,22 +786,24 @@ pub const DeclGen = struct {
try self.addUndef(layout.padding);
},
- .ErrorSet => switch (val.tag()) {
- .@"error" => {
- const err_name = val.castTag(.@"error").?.data.name;
- const kv = try dg.module.getErrorValue(err_name);
- try self.addConstInt(u16, @intCast(u16, kv.value));
+ .ErrorSet => switch (val.ip_index) {
+ .none => switch (val.tag()) {
+ .@"error" => {
+ const err_name = val.castTag(.@"error").?.data.name;
+ const kv = try dg.module.getErrorValue(err_name);
+ try self.addConstInt(u16, @intCast(u16, kv.value));
+ },
+ else => unreachable,
},
- .zero => {
- // Unactivated error set.
- try self.addConstInt(u16, 0);
+ else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
+ .int => |int| try self.addConstInt(u16, @intCast(u16, int.storage.u64)),
+ else => unreachable,
},
- else => unreachable,
},
.ErrorUnion => {
const payload_ty = ty.errorUnionPayload();
const is_pl = val.errorUnionIsPayload();
- const error_val = if (!is_pl) val else Value.initTag(.zero);
+ const error_val = if (!is_pl) val else Value.zero;
const eu_layout = dg.errorUnionLayout(payload_ty);
if (!eu_layout.payload_has_bits) {
@@ -993,9 +994,9 @@ pub const DeclGen = struct {
.indirect => return try self.spv.constInt(result_ty_ref, @boolToInt(val.toBool(mod))),
},
.Float => return switch (ty.floatBits(target)) {
- 16 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float16 = val.toFloat(f16) } } }),
- 32 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float32 = val.toFloat(f32) } } }),
- 64 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float64 = val.toFloat(f64) } } }),
+ 16 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float16 = val.toFloat(f16, mod) } } }),
+ 32 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float32 = val.toFloat(f32, mod) } } }),
+ 64 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float64 = val.toFloat(f64, mod) } } }),
80, 128 => unreachable, // TODO
else => unreachable,
},
@@ -1531,6 +1532,7 @@ pub const DeclGen = struct {
}
fn genDecl(self: *DeclGen) !void {
+ if (true) @panic("TODO: update SPIR-V backend for InternPool changes");
const mod = self.module;
const decl = mod.declPtr(self.decl_index);
const spv_decl_index = try self.resolveDecl(self.decl_index);
@@ -2087,8 +2089,7 @@ pub const DeclGen = struct {
var i: usize = 0;
while (i < mask_len) : (i += 1) {
- var buf: Value.ElemValueBuffer = undefined;
- const elem = mask.elemValueBuffer(self.module, i, &buf);
+ const elem = try mask.elemValue(self.module, i);
if (elem.isUndef()) {
self.func.body.writeOperand(spec.LiteralInteger, 0xFFFF_FFFF);
} else {
@@ -3146,9 +3147,8 @@ pub const DeclGen = struct {
const int_val = switch (cond_ty.zigTypeTag(mod)) {
.Int => if (cond_ty.isSignedInt(mod)) @bitCast(u64, value.toSignedInt(mod)) else value.toUnsignedInt(mod),
.Enum => blk: {
- var int_buffer: Value.Payload.U64 = undefined;
// TODO: figure out of cond_ty is correct (something with enum literals)
- break :blk value.enumToInt(cond_ty, &int_buffer).toUnsignedInt(mod); // TODO: composite integer constants
+ break :blk (try value.enumToInt(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
},
else => unreachable,
};