authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-24 16:41:17+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-24 16:41:37+01:00
log7e9f321f53b53dcefaf3b771720c9c25529c39ef
tree7c1dd7625c1a06e24671f83a6860e6edfdd88e53
parent9b39e824cdd523ec32b33d630ea9a58ca6fd4103

Builder: fix bitcode widths


1 files changed, 12 insertions(+), 15 deletions(-)

src/codegen/llvm/Builder.zig+12-15
...@@ -12945,14 +12945,8 @@ fn debugConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {...@@ -12945,14 +12945,8 @@ fn debugConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {
12945pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]const u32 {12945pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]const u32 {
12946 const BitcodeWriter = bitcode_writer.BitcodeWriter(&.{ Type, FunctionAttributes });12946 const BitcodeWriter = bitcode_writer.BitcodeWriter(&.{ Type, FunctionAttributes });
12947 var bitcode = BitcodeWriter.init(allocator, &.{12947 var bitcode = BitcodeWriter.init(allocator, &.{
12948 if (self.type_items.items.len > 0)12948 std.math.log2_int_ceil(usize, self.type_items.items.len),
12949 std.math.log2_int_ceil(usize, self.type_items.items.len)12949 std.math.log2_int_ceil(usize, 1 + self.function_attributes_set.count()),
12950 else
12951 undefined,
12952 if (self.type_items.items.len > 0)
12953 std.math.log2_int_ceil(usize, self.function_attributes_set.count())
12954 else
12955 undefined,
12956 });12950 });
12957 errdefer bitcode.deinit();12951 errdefer bitcode.deinit();
1295812952
...@@ -13340,7 +13334,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13340,7 +13334,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13340 const group_index = attributes_set.getIndex(.{13334 const group_index = attributes_set.getIndex(.{
13341 .attributes = attributes,13335 .attributes = attributes,
13342 .index = @intCast(i),13336 .index = @intCast(i),
13343 }) orelse unreachable;13337 }).?;
13344 record.appendAssumeCapacity(@intCast(group_index));13338 record.appendAssumeCapacity(@intCast(group_index));
13345 }13339 }
1334613340
...@@ -13426,7 +13420,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13426,7 +13420,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13426 if (!gop.found_existing) {13420 if (!gop.found_existing) {
13427 try module_block.writeAbbrev(Module.String{13421 try module_block.writeAbbrev(Module.String{
13428 .code = 5,13422 .code = 5,
13429 .string = variable.section.slice(self) orelse unreachable,13423 .string = variable.section.slice(self).?,
13430 });13424 });
13431 }13425 }
13432 break :blk gop.index + 1;13426 break :blk gop.index + 1;
...@@ -13473,7 +13467,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13473,7 +13467,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13473 if (!gop.found_existing) {13467 if (!gop.found_existing) {
13474 try module_block.writeAbbrev(Module.String{13468 try module_block.writeAbbrev(Module.String{
13475 .code = 5,13469 .code = 5,
13476 .string = func.section.slice(self) orelse unreachable,13470 .string = func.section.slice(self).?,
13477 });13471 });
13478 }13472 }
13479 break :blk gop.index + 1;13473 break :blk gop.index + 1;
...@@ -13649,7 +13643,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13649,7 +13643,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13649 if (str == .none) {13643 if (str == .none) {
13650 try constants_block.writeAbbrev(Constants.Null{});13644 try constants_block.writeAbbrev(Constants.Null{});
13651 } else {13645 } else {
13652 const slice = str.slice(self) orelse unreachable;13646 const slice = str.slice(self).?;
13653 if (slice.len > 0 and slice[slice.len - 1] == 0)13647 if (slice.len > 0 and slice[slice.len - 1] == 0)
13654 try constants_block.writeAbbrev(Constants.CString{ .string = slice[0 .. slice.len - 1] })13648 try constants_block.writeAbbrev(Constants.CString{ .string = slice[0 .. slice.len - 1] })
13655 else13649 else
...@@ -13791,8 +13785,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13791,8 +13785,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13791 => |tag| {13785 => |tag| {
13792 const extra = self.constantExtraData(Constant.Assembly, data);13786 const extra = self.constantExtraData(Constant.Assembly, data);
1379313787
13794 const assembly_slice = extra.assembly.slice(self) orelse unreachable;13788 const assembly_slice = extra.assembly.slice(self).?;
13795 const constraints_slice = extra.constraints.slice(self) orelse unreachable;13789 const constraints_slice = extra.constraints.slice(self).?;
1379613790
13797 try record.ensureUnusedCapacity(self.gpa, 4 + assembly_slice.len + constraints_slice.len);13791 try record.ensureUnusedCapacity(self.gpa, 4 + assembly_slice.len + constraints_slice.len);
1379813792
...@@ -14341,7 +14335,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14341,7 +14335,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14341 return switch (Ty) {14335 return switch (Ty) {
14342 Value => @enumFromInt(adapter.getOffsetValueIndex(value)),14336 Value => @enumFromInt(adapter.getOffsetValueIndex(value)),
14343 Constant => @enumFromInt(adapter.getOffsetConstantIndex(value)),14337 Constant => @enumFromInt(adapter.getOffsetConstantIndex(value)),
14344 FunctionAttributes => @enumFromInt(if (value == .none) 0 else (adapter.constant_adapter.builder.function_attributes_set.getIndex(value) orelse unreachable) + 1),14338 FunctionAttributes => @enumFromInt(switch (value) {
14339 .none => 0,
14340 else => 1 + adapter.constant_adapter.builder.function_attributes_set.getIndex(value).?,
14341 }),
14345 else => value,14342 else => value,
14346 };14343 };
14347 }14344 }