aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-05-30 00:22:45 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2025-05-31 18:54:28 -0400
commitb483defc5a5c2f93eb8a445974ab831ae4e4b321 (patch)
tree0fa6fa6721e8731b294f8aafed6ca8f02a0242ae /src/codegen
parentc1e9ef9eaabb2219a3762c5957b1c63ad20bf1ed (diff)
downloadzig-b483defc5a5c2f93eb8a445974ab831ae4e4b321.tar.gz
zig-b483defc5a5c2f93eb8a445974ab831ae4e4b321.zip
Legalize: implement scalarization of binary operations
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig12
-rw-r--r--src/codegen/c/Type.zig21
-rw-r--r--src/codegen/llvm.zig8
3 files changed, 28 insertions, 13 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 8539efdbfe..d83eb8f771 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -1591,7 +1591,7 @@ pub const DeclGen = struct {
try writer.writeAll("((");
try dg.renderCType(writer, ctype);
return writer.print("){x})", .{
- try dg.fmtIntLiteral(try pt.undefValue(.usize), .Other),
+ try dg.fmtIntLiteral(.undef_usize, .Other),
});
},
.slice => {
@@ -1605,7 +1605,7 @@ pub const DeclGen = struct {
const ptr_ty = ty.slicePtrFieldType(zcu);
try dg.renderType(writer, ptr_ty);
return writer.print("){x}, {0x}}}", .{
- try dg.fmtIntLiteral(try dg.pt.undefValue(.usize), .Other),
+ try dg.fmtIntLiteral(.undef_usize, .Other),
});
},
},
@@ -6376,7 +6376,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
if (operand_child_ctype.info(ctype_pool) == .array) {
try writer.writeByte('&');
try f.writeCValueDeref(writer, operand);
- try writer.print("[{}]", .{try f.fmtIntLiteral(try pt.intValue(.usize, 0))});
+ try writer.print("[{}]", .{try f.fmtIntLiteral(.zero_usize)});
} else try f.writeCValue(writer, operand, .Other);
}
try a.end(f, writer);
@@ -6907,7 +6907,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
try writer.writeAll("for (");
try f.writeCValue(writer, index, .Other);
try writer.writeAll(" = ");
- try f.object.dg.renderValue(writer, try pt.intValue(.usize, 0), .Other);
+ try f.object.dg.renderValue(writer, .zero_usize, .Other);
try writer.writeAll("; ");
try f.writeCValue(writer, index, .Other);
try writer.writeAll(" != ");
@@ -8311,11 +8311,11 @@ const Vectorize = struct {
try writer.writeAll("for (");
try f.writeCValue(writer, local, .Other);
- try writer.print(" = {d}; ", .{try f.fmtIntLiteral(try pt.intValue(.usize, 0))});
+ try writer.print(" = {d}; ", .{try f.fmtIntLiteral(.zero_usize)});
try f.writeCValue(writer, local, .Other);
try writer.print(" < {d}; ", .{try f.fmtIntLiteral(try pt.intValue(.usize, ty.vectorLen(zcu)))});
try f.writeCValue(writer, local, .Other);
- try writer.print(" += {d}) {{\n", .{try f.fmtIntLiteral(try pt.intValue(.usize, 1))});
+ try writer.print(" += {d}) {{\n", .{try f.fmtIntLiteral(.one_usize)});
f.object.indent_writer.pushIndent();
break :index .{ .index = local };
diff --git a/src/codegen/c/Type.zig b/src/codegen/c/Type.zig
index 7d3a485e2a..e5901ec626 100644
--- a/src/codegen/c/Type.zig
+++ b/src/codegen/c/Type.zig
@@ -1408,6 +1408,15 @@ pub const Pool = struct {
.bits = pt.zcu.errorSetBits(),
}, mod, kind),
+ .ptr_usize_type,
+ => return pool.getPointer(allocator, .{
+ .elem_ctype = .usize,
+ }),
+ .ptr_const_comptime_int_type,
+ => return pool.getPointer(allocator, .{
+ .elem_ctype = .void,
+ .@"const" = true,
+ }),
.manyptr_u8_type,
=> return pool.getPointer(allocator, .{
.elem_ctype = .u8,
@@ -1418,11 +1427,6 @@ pub const Pool = struct {
.elem_ctype = .u8,
.@"const" = true,
}),
- .single_const_pointer_to_comptime_int_type,
- => return pool.getPointer(allocator, .{
- .elem_ctype = .void,
- .@"const" = true,
- }),
.slice_const_u8_type,
.slice_const_u8_sentinel_0_type,
=> {
@@ -2157,11 +2161,16 @@ pub const Pool = struct {
},
.undef,
+ .undef_bool,
+ .undef_usize,
+ .undef_u1,
.zero,
.zero_usize,
+ .zero_u1,
.zero_u8,
.one,
.one_usize,
+ .one_u1,
.one_u8,
.four_u8,
.negative_one,
@@ -2172,7 +2181,7 @@ pub const Pool = struct {
.bool_false,
.empty_tuple,
.none,
- => unreachable,
+ => unreachable, // values, not types
_ => |ip_index| switch (ip.indexToKey(ip_index)) {
.int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind),
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index d2a72502ed..1820faf90c 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -3081,10 +3081,11 @@ pub const Object = struct {
.undefined_type,
.enum_literal_type,
=> unreachable,
+ .ptr_usize_type,
+ .ptr_const_comptime_int_type,
.manyptr_u8_type,
.manyptr_const_u8_type,
.manyptr_const_u8_sentinel_0_type,
- .single_const_pointer_to_comptime_int_type,
=> .ptr,
.slice_const_u8_type,
.slice_const_u8_sentinel_0_type,
@@ -3098,11 +3099,16 @@ pub const Object = struct {
=> unreachable,
// values, not types
.undef,
+ .undef_bool,
+ .undef_usize,
+ .undef_u1,
.zero,
.zero_usize,
+ .zero_u1,
.zero_u8,
.one,
.one_usize,
+ .one_u1,
.one_u8,
.four_u8,
.negative_one,