diff options
| author | antlilja <liljaanton2001@gmail.com> | 2024-02-26 01:00:58 +0100 |
|---|---|---|
| committer | antlilja <liljaanton2001@gmail.com> | 2024-02-26 01:00:58 +0100 |
| commit | 9754d6d0a0cc69920822b64e35bf73f8775e4eab (patch) | |
| tree | e2c58524959f0757b299e72caaa1a55ee456a9a0 /src/codegen/llvm/bitcode_writer.zig | |
| parent | b2374c4d75d16ac0eb7b7b5e53411a80e9f4413d (diff) | |
| download | zig-9754d6d0a0cc69920822b64e35bf73f8775e4eab.tar.gz zig-9754d6d0a0cc69920822b64e35bf73f8775e4eab.zip | |
Builder: Use BlockInfo block to reduce size of bitcode
Diffstat (limited to 'src/codegen/llvm/bitcode_writer.zig')
| -rw-r--r-- | src/codegen/llvm/bitcode_writer.zig | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/codegen/llvm/bitcode_writer.zig b/src/codegen/llvm/bitcode_writer.zig index d48a92dd40..7140c87929 100644 --- a/src/codegen/llvm/bitcode_writer.zig +++ b/src/codegen/llvm/bitcode_writer.zig @@ -148,7 +148,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { } pub fn enterTopBlock(self: *BcWriter, comptime SubBlock: type) Error!BlockWriter(SubBlock) { - return BlockWriter(SubBlock).init(self, 2); + return BlockWriter(SubBlock).init(self, 2, true); } fn BlockWriter(comptime Block: type) type { @@ -164,7 +164,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { start: usize, bitcode: *BcWriter, - pub fn init(bitcode: *BcWriter, comptime parent_abbrev_len: u6) Error!Self { + pub fn init(bitcode: *BcWriter, comptime parent_abbrev_len: u6, comptime define_abbrevs: bool) Error!Self { try bitcode.writeBits(1, parent_abbrev_len); try bitcode.writeVBR(Block.id, 8); try bitcode.writeVBR(abbrev_len, 4); @@ -174,19 +174,23 @@ pub fn BitcodeWriter(comptime types: []const type) type { const start = bitcode.length(); try bitcode.writeBits(0, 32); - // Predefine all block abbrevs - inline for (Block.abbrevs) |Abbrev| { - try defineAbbrev(bitcode, &Abbrev.ops); - } - - return .{ + var self = Self{ .start = start, .bitcode = bitcode, }; + + // Predefine all block abbrevs + if (define_abbrevs) { + inline for (Block.abbrevs) |Abbrev| { + try self.defineAbbrev(&Abbrev.ops); + } + } + + return self; } - pub fn enterSubBlock(self: Self, comptime SubBlock: type) Error!BlockWriter(SubBlock) { - return BlockWriter(SubBlock).init(self.bitcode, abbrev_len); + pub fn enterSubBlock(self: Self, comptime SubBlock: type, comptime define_abbrevs: bool) Error!BlockWriter(SubBlock) { + return BlockWriter(SubBlock).init(self.bitcode, abbrev_len, define_abbrevs); } pub fn end(self: *Self) Error!void { @@ -291,7 +295,8 @@ pub fn BitcodeWriter(comptime types: []const type) type { } } - fn defineAbbrev(bitcode: *BcWriter, comptime ops: []const AbbrevOp) Error!void { + pub fn defineAbbrev(self: *Self, comptime ops: []const AbbrevOp) Error!void { + const bitcode = self.bitcode; try bitcode.writeBits(2, abbrev_len); // ops.len is not accurate because arrays are actually two ops |
