authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-02-27 13:19:09+01:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-02-28 14:46:43+01:00
log826c6c0ec6847f3b2b217ea7738fd8bda757ef04
treefa3321d84489645642403761d93b1252e2b72d33
parent6e078883eebd0532928dba0c70e86a2eee0f246b

LLVM: Implement more efficient blob writing


2 files changed, 13 insertions(+), 16 deletions(-)

src/codegen/llvm/Builder.zig+1-11
...@@ -14045,17 +14045,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14045,17 +14045,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14045 try bitcode.writeVBR(@as(u32, @intCast(slice.len)), 6);14045 try bitcode.writeVBR(@as(u32, @intCast(slice.len)), 6);
14046 }14046 }
1404714047
14048 try bitcode.alignTo32();14048 try bitcode.writeBlob(self.metadata_string_bytes.items);
14049
14050 for (1..self.metadata_string_map.count()) |metadata_string_index| {
14051 const metadata_string: MetadataString = @enumFromInt(metadata_string_index);
14052 const slice = metadata_string.slice(self);
14053 for (slice) |c| {
14054 try bitcode.writeBits(c, 8);
14055 }
14056 }
14057
14058 try bitcode.alignTo32();
14059 }14049 }
1406014050
14061 for (14051 for (
src/codegen/llvm/bitcode_writer.zig+12-5
...@@ -139,6 +139,17 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -139,6 +139,17 @@ pub fn BitcodeWriter(comptime types: []const type) type {
139 try self.writeBits(charTo6Bit(c), 6);139 try self.writeBits(charTo6Bit(c), 6);
140 }140 }
141141
142 pub fn writeBlob(self: *BcWriter, blob: []const u8) Error!void {
143 const blob_word_size = std.mem.alignForward(usize, blob.len, 4);
144 try self.buffer.ensureUnusedCapacity(blob_word_size + 1);
145 self.alignTo32() catch unreachable;
146
147 const slice = self.buffer.addManyAsSliceAssumeCapacity(blob_word_size / 4);
148 const slice_bytes = std.mem.sliceAsBytes(slice);
149 @memcpy(slice_bytes[0..blob.len], blob);
150 @memset(slice_bytes[blob.len..], 0);
151 }
152
142 pub fn alignTo32(self: *BcWriter) Error!void {153 pub fn alignTo32(self: *BcWriter) Error!void {
143 if (self.bit_count == 0) return;154 if (self.bit_count == 0) return;
144155
...@@ -256,11 +267,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -256,11 +267,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
256 .char6 => try self.bitcode.write6BitChar(adapter.get(param, field_name)),267 .char6 => try self.bitcode.write6BitChar(adapter.get(param, field_name)),
257 .blob => {268 .blob => {
258 try self.bitcode.writeVBR(param.len, 6);269 try self.bitcode.writeVBR(param.len, 6);
259 try self.bitcode.alignTo32();270 try self.bitcode.writeBlob(param);
260 for (param) |x| {
261 try self.bitcode.writeBits(x, 8);
262 }
263 try self.bitcode.alignTo32();
264 },271 },
265 .array_fixed => |len| {272 .array_fixed => |len| {
266 try self.bitcode.writeVBR(param.len, 6);273 try self.bitcode.writeVBR(param.len, 6);