aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-09-23 23:06:08 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-09-23 23:06:08 -0700
commita7088fd9a3edb037f0f51bb402a3c557334634f3 (patch)
treedba5fd9f32b341d1cb64b9813033e1558c1e8d2b /src/codegen/llvm.zig
parent8eff0a0a669dbdacf9cebbc96fdf20536f3073ee (diff)
downloadzig-a7088fd9a3edb037f0f51bb402a3c557334634f3.tar.gz
zig-a7088fd9a3edb037f0f51bb402a3c557334634f3.zip
compiler: packed structs cache bit offsets
Instead of linear search every time a packed struct field's bit or byte offset is wanted, they are computed once during resolution of the packed struct's backing int type, and stored in InternPool for O(1) lookup. Closes #17178
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index dc2e2f3859..7057516a51 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -6192,6 +6192,7 @@ pub const FuncGen = struct {
fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
const o = self.dg.object;
const mod = o.module;
+ const ip = &mod.intern_pool;
const inst = body_tail[0];
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
@@ -6207,7 +6208,7 @@ pub const FuncGen = struct {
.Struct => switch (struct_ty.containerLayout(mod)) {
.Packed => {
const struct_type = mod.typeToStruct(struct_ty).?;
- const bit_offset = mod.structPackedFieldBitOffset(struct_type, field_index);
+ const bit_offset = struct_type.fieldBitOffset(ip, field_index);
const containing_int = struct_llvm_val;
const shift_amt =
try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset);