diff options
| author | antlilja <liljaanton2001@gmail.com> | 2024-02-27 13:19:09 +0100 |
|---|---|---|
| committer | antlilja <liljaanton2001@gmail.com> | 2024-02-28 14:46:43 +0100 |
| commit | 826c6c0ec6847f3b2b217ea7738fd8bda757ef04 (patch) | |
| tree | fa3321d84489645642403761d93b1252e2b72d33 /src/codegen/llvm/bitcode_writer.zig | |
| parent | 6e078883eebd0532928dba0c70e86a2eee0f246b (diff) | |
| download | zig-826c6c0ec6847f3b2b217ea7738fd8bda757ef04.tar.gz zig-826c6c0ec6847f3b2b217ea7738fd8bda757ef04.zip | |
LLVM: Implement more efficient blob writing
Diffstat (limited to 'src/codegen/llvm/bitcode_writer.zig')
| -rw-r--r-- | src/codegen/llvm/bitcode_writer.zig | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/codegen/llvm/bitcode_writer.zig b/src/codegen/llvm/bitcode_writer.zig index 7140c87929..414cdea682 100644 --- a/src/codegen/llvm/bitcode_writer.zig +++ b/src/codegen/llvm/bitcode_writer.zig @@ -139,6 +139,17 @@ pub fn BitcodeWriter(comptime types: []const type) type { try self.writeBits(charTo6Bit(c), 6); } + pub fn writeBlob(self: *BcWriter, blob: []const u8) Error!void { + const blob_word_size = std.mem.alignForward(usize, blob.len, 4); + try self.buffer.ensureUnusedCapacity(blob_word_size + 1); + self.alignTo32() catch unreachable; + + const slice = self.buffer.addManyAsSliceAssumeCapacity(blob_word_size / 4); + const slice_bytes = std.mem.sliceAsBytes(slice); + @memcpy(slice_bytes[0..blob.len], blob); + @memset(slice_bytes[blob.len..], 0); + } + pub fn alignTo32(self: *BcWriter) Error!void { if (self.bit_count == 0) return; @@ -256,11 +267,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { .char6 => try self.bitcode.write6BitChar(adapter.get(param, field_name)), .blob => { try self.bitcode.writeVBR(param.len, 6); - try self.bitcode.alignTo32(); - for (param) |x| { - try self.bitcode.writeBits(x, 8); - } - try self.bitcode.alignTo32(); + try self.bitcode.writeBlob(param); }, .array_fixed => |len| { try self.bitcode.writeVBR(param.len, 6); |
