authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-30 13:54:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:57-07:00
log90a877f462fce8bee69ad366aac66805a7c00571
treefd4271ea498f27ec12c5f9e10fd70cdd25de9279
parent6b81546454f925807d2298a127458741be7239e9

InternPool: pass by const pointer

The Zig language allows the compiler to make this optimization automatically. We should definitely make the compiler do that, and revert this commit. However, that will not happen in this branch, and I want to continue to explore achieving performance parity with merge-base. So, this commit changes all InternPool parameters to be passed by const pointer rather than by value. I measured a 1.03x ± 0.03 speedup vs the previous commit compiling the (set of passing) behavior tests. Against merge-base, this commit is 1.17x ± 0.04 slower, which is an improvement from the previous measurement of 1.22x ± 0.02. Related issue: #13510 Related issue: #14129 Related issue: #15688

17 files changed, 94 insertions(+), 94 deletions(-)

src/Air.zig+4-4
......@@ -1182,7 +1182,7 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {
11821182 return air.extra[extra.end..][0..extra.data.body_len];
11831183}
11841184
1185pub fn typeOf(air: Air, inst: Air.Inst.Ref, ip: InternPool) Type {
1185pub fn typeOf(air: Air, inst: Air.Inst.Ref, ip: *const InternPool) Type {
11861186 const ref_int = @enumToInt(inst);
11871187 if (ref_int < InternPool.static_keys.len) {
11881188 return InternPool.static_keys[ref_int].typeOf().toType();
......@@ -1190,7 +1190,7 @@ pub fn typeOf(air: Air, inst: Air.Inst.Ref, ip: InternPool) Type {
11901190 return air.typeOfIndex(ref_int - ref_start_index, ip);
11911191}
11921192
1193pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {
1193pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
11941194 const datas = air.instructions.items(.data);
11951195 switch (air.instructions.items(.tag)[inst]) {
11961196 .add,
......@@ -1520,7 +1520,7 @@ pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {
15201520 const air_datas = air.instructions.items(.data);
15211521 switch (air.instructions.items(.tag)[inst_index]) {
15221522 .interned => return air_datas[inst_index].interned.toValue(),
1523 else => return air.typeOfIndex(inst_index, mod.intern_pool).onePossibleValue(mod),
1523 else => return air.typeOfIndex(inst_index, &mod.intern_pool).onePossibleValue(mod),
15241524 }
15251525}
15261526
......@@ -1537,7 +1537,7 @@ pub fn nullTerminatedString(air: Air, index: usize) [:0]const u8 {
15371537/// because it can cause side effects. If an instruction does not need to be
15381538/// lowered, and Liveness determines its result is unused, backends should
15391539/// avoid lowering it.
1540pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: InternPool) bool {
1540pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
15411541 const data = air.instructions.items(.data)[inst];
15421542 return switch (air.instructions.items(.tag)[inst]) {
15431543 .arg,
src/InternPool.zig+42-42
......@@ -2992,7 +2992,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
29922992 };
29932993}
29942994
2995fn indexToKeyFuncType(ip: InternPool, data: u32) Key.FuncType {
2995fn indexToKeyFuncType(ip: *const InternPool, data: u32) Key.FuncType {
29962996 const type_function = ip.extraDataTrail(TypeFunction, data);
29972997 const param_types = @ptrCast(
29982998 []Index,
......@@ -3015,7 +3015,7 @@ fn indexToKeyFuncType(ip: InternPool, data: u32) Key.FuncType {
30153015 };
30163016}
30173017
3018fn indexToKeyEnum(ip: InternPool, data: u32, tag_mode: Key.EnumType.TagMode) Key {
3018fn indexToKeyEnum(ip: *const InternPool, data: u32, tag_mode: Key.EnumType.TagMode) Key {
30193019 const enum_explicit = ip.extraDataTrail(EnumExplicit, data);
30203020 const names = @ptrCast(
30213021 []const NullTerminatedString,
......@@ -3038,7 +3038,7 @@ fn indexToKeyEnum(ip: InternPool, data: u32, tag_mode: Key.EnumType.TagMode) Key
30383038 } };
30393039}
30403040
3041fn indexToKeyBigInt(ip: InternPool, limb_index: u32, positive: bool) Key {
3041fn indexToKeyBigInt(ip: *const InternPool, limb_index: u32, positive: bool) Key {
30423042 const int_info = ip.limbData(Int, limb_index);
30433043 return .{ .int = .{
30443044 .ty = int_info.ty,
......@@ -4351,7 +4351,7 @@ fn addLimbsAssumeCapacity(ip: *InternPool, limbs: []const Limb) void {
43514351 }
43524352}
43534353
4354fn extraDataTrail(ip: InternPool, comptime T: type, index: usize) struct { data: T, end: usize } {
4354fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct { data: T, end: usize } {
43554355 var result: T = undefined;
43564356 const fields = @typeInfo(T).Struct.fields;
43574357 inline for (fields, 0..) |field, i| {
......@@ -4384,12 +4384,12 @@ fn extraDataTrail(ip: InternPool, comptime T: type, index: usize) struct { data:
43844384 };
43854385}
43864386
4387fn extraData(ip: InternPool, comptime T: type, index: usize) T {
4387fn extraData(ip: *const InternPool, comptime T: type, index: usize) T {
43884388 return extraDataTrail(ip, T, index).data;
43894389}
43904390
43914391/// Asserts the struct has 32-bit fields and the number of fields is evenly divisible by 2.
4392fn limbData(ip: InternPool, comptime T: type, index: usize) T {
4392fn limbData(ip: *const InternPool, comptime T: type, index: usize) T {
43934393 switch (@sizeOf(Limb)) {
43944394 @sizeOf(u32) => return extraData(ip, T, index),
43954395 @sizeOf(u64) => {},
......@@ -4413,7 +4413,7 @@ fn limbData(ip: InternPool, comptime T: type, index: usize) T {
44134413}
44144414
44154415/// This function returns the Limb slice that is trailing data after a payload.
4416fn limbSlice(ip: InternPool, comptime S: type, limb_index: u32, len: u32) []const Limb {
4416fn limbSlice(ip: *const InternPool, comptime S: type, limb_index: u32, len: u32) []const Limb {
44174417 const field_count = @typeInfo(S).Struct.fields.len;
44184418 switch (@sizeOf(Limb)) {
44194419 @sizeOf(u32) => {
......@@ -4433,7 +4433,7 @@ const LimbsAsIndexes = struct {
44334433 len: u32,
44344434};
44354435
4436fn limbsSliceToIndex(ip: InternPool, limbs: []const Limb) LimbsAsIndexes {
4436fn limbsSliceToIndex(ip: *const InternPool, limbs: []const Limb) LimbsAsIndexes {
44374437 const host_slice = switch (@sizeOf(Limb)) {
44384438 @sizeOf(u32) => ip.extra.items,
44394439 @sizeOf(u64) => ip.limbs.items,
......@@ -4447,7 +4447,7 @@ fn limbsSliceToIndex(ip: InternPool, limbs: []const Limb) LimbsAsIndexes {
44474447}
44484448
44494449/// This function converts Limb array indexes to a primitive slice type.
4450fn limbsIndexToSlice(ip: InternPool, limbs: LimbsAsIndexes) []const Limb {
4450fn limbsIndexToSlice(ip: *const InternPool, limbs: LimbsAsIndexes) []const Limb {
44514451 return switch (@sizeOf(Limb)) {
44524452 @sizeOf(u32) => ip.extra.items[limbs.start..][0..limbs.len],
44534453 @sizeOf(u64) => ip.limbs.items[limbs.start..][0..limbs.len],
......@@ -4485,7 +4485,7 @@ test "basic usage" {
44854485 try std.testing.expect(another_array_i32 == array_i32);
44864486}
44874487
4488pub fn childType(ip: InternPool, i: Index) Index {
4488pub fn childType(ip: *const InternPool, i: Index) Index {
44894489 return switch (ip.indexToKey(i)) {
44904490 .ptr_type => |ptr_type| ptr_type.elem_type,
44914491 .vector_type => |vector_type| vector_type.child,
......@@ -4496,7 +4496,7 @@ pub fn childType(ip: InternPool, i: Index) Index {
44964496}
44974497
44984498/// Given a slice type, returns the type of the ptr field.
4499pub fn slicePtrType(ip: InternPool, i: Index) Index {
4499pub fn slicePtrType(ip: *const InternPool, i: Index) Index {
45004500 switch (i) {
45014501 .slice_const_u8_type => return .manyptr_const_u8_type,
45024502 .slice_const_u8_sentinel_0_type => return .manyptr_const_u8_sentinel_0_type,
......@@ -4510,7 +4510,7 @@ pub fn slicePtrType(ip: InternPool, i: Index) Index {
45104510}
45114511
45124512/// Given a slice value, returns the value of the ptr field.
4513pub fn slicePtr(ip: InternPool, i: Index) Index {
4513pub fn slicePtr(ip: *const InternPool, i: Index) Index {
45144514 const item = ip.items.get(@enumToInt(i));
45154515 switch (item.tag) {
45164516 .ptr_slice => return ip.extraData(PtrSlice, item.data).ptr,
......@@ -4519,7 +4519,7 @@ pub fn slicePtr(ip: InternPool, i: Index) Index {
45194519}
45204520
45214521/// Given a slice value, returns the value of the len field.
4522pub fn sliceLen(ip: InternPool, i: Index) Index {
4522pub fn sliceLen(ip: *const InternPool, i: Index) Index {
45234523 const item = ip.items.get(@enumToInt(i));
45244524 switch (item.tag) {
45254525 .ptr_slice => return ip.extraData(PtrSlice, item.data).len,
......@@ -4702,7 +4702,7 @@ pub fn getCoercedInts(ip: *InternPool, gpa: Allocator, int: Key.Int, new_ty: Ind
47024702 } });
47034703}
47044704
4705pub fn indexToStructType(ip: InternPool, val: Index) Module.Struct.OptionalIndex {
4705pub fn indexToStructType(ip: *const InternPool, val: Index) Module.Struct.OptionalIndex {
47064706 assert(val != .none);
47074707 const tags = ip.items.items(.tag);
47084708 if (tags[@enumToInt(val)] != .type_struct) return .none;
......@@ -4710,7 +4710,7 @@ pub fn indexToStructType(ip: InternPool, val: Index) Module.Struct.OptionalIndex
47104710 return @intToEnum(Module.Struct.Index, datas[@enumToInt(val)]).toOptional();
47114711}
47124712
4713pub fn indexToUnionType(ip: InternPool, val: Index) Module.Union.OptionalIndex {
4713pub fn indexToUnionType(ip: *const InternPool, val: Index) Module.Union.OptionalIndex {
47144714 assert(val != .none);
47154715 const tags = ip.items.items(.tag);
47164716 switch (tags[@enumToInt(val)]) {
......@@ -4721,7 +4721,7 @@ pub fn indexToUnionType(ip: InternPool, val: Index) Module.Union.OptionalIndex {
47214721 return @intToEnum(Module.Union.Index, datas[@enumToInt(val)]).toOptional();
47224722}
47234723
4724pub fn indexToFuncType(ip: InternPool, val: Index) ?Key.FuncType {
4724pub fn indexToFuncType(ip: *const InternPool, val: Index) ?Key.FuncType {
47254725 assert(val != .none);
47264726 const tags = ip.items.items(.tag);
47274727 const datas = ip.items.items(.data);
......@@ -4731,7 +4731,7 @@ pub fn indexToFuncType(ip: InternPool, val: Index) ?Key.FuncType {
47314731 }
47324732}
47334733
4734pub fn indexToFunc(ip: InternPool, val: Index) Module.Fn.OptionalIndex {
4734pub fn indexToFunc(ip: *const InternPool, val: Index) Module.Fn.OptionalIndex {
47354735 assert(val != .none);
47364736 const tags = ip.items.items(.tag);
47374737 if (tags[@enumToInt(val)] != .func) return .none;
......@@ -4739,7 +4739,7 @@ pub fn indexToFunc(ip: InternPool, val: Index) Module.Fn.OptionalIndex {
47394739 return ip.extraData(Key.Func, datas[@enumToInt(val)]).index.toOptional();
47404740}
47414741
4742pub fn indexToInferredErrorSetType(ip: InternPool, val: Index) Module.Fn.InferredErrorSet.OptionalIndex {
4742pub fn indexToInferredErrorSetType(ip: *const InternPool, val: Index) Module.Fn.InferredErrorSet.OptionalIndex {
47434743 assert(val != .none);
47444744 const tags = ip.items.items(.tag);
47454745 if (tags[@enumToInt(val)] != .type_inferred_error_set) return .none;
......@@ -4748,7 +4748,7 @@ pub fn indexToInferredErrorSetType(ip: InternPool, val: Index) Module.Fn.Inferre
47484748}
47494749
47504750/// includes .comptime_int_type
4751pub fn isIntegerType(ip: InternPool, ty: Index) bool {
4751pub fn isIntegerType(ip: *const InternPool, ty: Index) bool {
47524752 return switch (ty) {
47534753 .usize_type,
47544754 .isize_type,
......@@ -4769,7 +4769,7 @@ pub fn isIntegerType(ip: InternPool, ty: Index) bool {
47694769}
47704770
47714771/// does not include .enum_literal_type
4772pub fn isEnumType(ip: InternPool, ty: Index) bool {
4772pub fn isEnumType(ip: *const InternPool, ty: Index) bool {
47734773 return switch (ty) {
47744774 .atomic_order_type,
47754775 .atomic_rmw_op_type,
......@@ -4783,35 +4783,35 @@ pub fn isEnumType(ip: InternPool, ty: Index) bool {
47834783 };
47844784}
47854785
4786pub fn isFunctionType(ip: InternPool, ty: Index) bool {
4786pub fn isFunctionType(ip: *const InternPool, ty: Index) bool {
47874787 return ip.indexToKey(ty) == .func_type;
47884788}
47894789
4790pub fn isPointerType(ip: InternPool, ty: Index) bool {
4790pub fn isPointerType(ip: *const InternPool, ty: Index) bool {
47914791 return ip.indexToKey(ty) == .ptr_type;
47924792}
47934793
4794pub fn isOptionalType(ip: InternPool, ty: Index) bool {
4794pub fn isOptionalType(ip: *const InternPool, ty: Index) bool {
47954795 return ip.indexToKey(ty) == .opt_type;
47964796}
47974797
47984798/// includes .inferred_error_set_type
4799pub fn isErrorSetType(ip: InternPool, ty: Index) bool {
4799pub fn isErrorSetType(ip: *const InternPool, ty: Index) bool {
48004800 return ty == .anyerror_type or switch (ip.indexToKey(ty)) {
48014801 .error_set_type, .inferred_error_set_type => true,
48024802 else => false,
48034803 };
48044804}
48054805
4806pub fn isInferredErrorSetType(ip: InternPool, ty: Index) bool {
4806pub fn isInferredErrorSetType(ip: *const InternPool, ty: Index) bool {
48074807 return ip.indexToKey(ty) == .inferred_error_set_type;
48084808}
48094809
4810pub fn isErrorUnionType(ip: InternPool, ty: Index) bool {
4810pub fn isErrorUnionType(ip: *const InternPool, ty: Index) bool {
48114811 return ip.indexToKey(ty) == .error_union_type;
48124812}
48134813
4814pub fn isAggregateType(ip: InternPool, ty: Index) bool {
4814pub fn isAggregateType(ip: *const InternPool, ty: Index) bool {
48154815 return switch (ip.indexToKey(ty)) {
48164816 .array_type, .vector_type, .anon_struct_type, .struct_type => true,
48174817 else => false,
......@@ -4827,11 +4827,11 @@ pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void {
48274827 ip.extra.items[ip.items.items(.data)[@enumToInt(index)] + field_index] = @enumToInt(init_index);
48284828}
48294829
4830pub fn dump(ip: InternPool) void {
4830pub fn dump(ip: *const InternPool) void {
48314831 dumpFallible(ip, std.heap.page_allocator) catch return;
48324832}
48334833
4834fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void {
4834fn dumpFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
48354835 const items_size = (1 + 4) * ip.items.len;
48364836 const extra_size = 4 * ip.extra.items.len;
48374837 const limbs_size = 8 * ip.limbs.items.len;
......@@ -5023,11 +5023,11 @@ pub fn structPtr(ip: *InternPool, index: Module.Struct.Index) *Module.Struct {
50235023 return ip.allocated_structs.at(@enumToInt(index));
50245024}
50255025
5026pub fn structPtrConst(ip: InternPool, index: Module.Struct.Index) *const Module.Struct {
5026pub fn structPtrConst(ip: *const InternPool, index: Module.Struct.Index) *const Module.Struct {
50275027 return ip.allocated_structs.at(@enumToInt(index));
50285028}
50295029
5030pub fn structPtrUnwrapConst(ip: InternPool, index: Module.Struct.OptionalIndex) ?*const Module.Struct {
5030pub fn structPtrUnwrapConst(ip: *const InternPool, index: Module.Struct.OptionalIndex) ?*const Module.Struct {
50315031 return structPtrConst(ip, index.unwrap() orelse return null);
50325032}
50335033
......@@ -5035,7 +5035,7 @@ pub fn unionPtr(ip: *InternPool, index: Module.Union.Index) *Module.Union {
50355035 return ip.allocated_unions.at(@enumToInt(index));
50365036}
50375037
5038pub fn unionPtrConst(ip: InternPool, index: Module.Union.Index) *const Module.Union {
5038pub fn unionPtrConst(ip: *const InternPool, index: Module.Union.Index) *const Module.Union {
50395039 return ip.allocated_unions.at(@enumToInt(index));
50405040}
50415041
......@@ -5043,7 +5043,7 @@ pub fn funcPtr(ip: *InternPool, index: Module.Fn.Index) *Module.Fn {
50435043 return ip.allocated_funcs.at(@enumToInt(index));
50445044}
50455045
5046pub fn funcPtrConst(ip: InternPool, index: Module.Fn.Index) *const Module.Fn {
5046pub fn funcPtrConst(ip: *const InternPool, index: Module.Fn.Index) *const Module.Fn {
50475047 return ip.allocated_funcs.at(@enumToInt(index));
50485048}
50495049
......@@ -5051,7 +5051,7 @@ pub fn inferredErrorSetPtr(ip: *InternPool, index: Module.Fn.InferredErrorSet.In
50515051 return ip.allocated_inferred_error_sets.at(@enumToInt(index));
50525052}
50535053
5054pub fn inferredErrorSetPtrConst(ip: InternPool, index: Module.Fn.InferredErrorSet.Index) *const Module.Fn.InferredErrorSet {
5054pub fn inferredErrorSetPtrConst(ip: *const InternPool, index: Module.Fn.InferredErrorSet.Index) *const Module.Fn.InferredErrorSet {
50555055 return ip.allocated_inferred_error_sets.at(@enumToInt(index));
50565056}
50575057
......@@ -5182,7 +5182,7 @@ pub fn getString(ip: *InternPool, s: []const u8) OptionalNullTerminatedString {
51825182 }
51835183}
51845184
5185pub fn stringToSlice(ip: InternPool, s: NullTerminatedString) [:0]const u8 {
5185pub fn stringToSlice(ip: *const InternPool, s: NullTerminatedString) [:0]const u8 {
51865186 const string_bytes = ip.string_bytes.items;
51875187 const start = @enumToInt(s);
51885188 var end: usize = start;
......@@ -5190,11 +5190,11 @@ pub fn stringToSlice(ip: InternPool, s: NullTerminatedString) [:0]const u8 {
51905190 return string_bytes[start..end :0];
51915191}
51925192
5193pub fn stringToSliceUnwrap(ip: InternPool, s: OptionalNullTerminatedString) ?[:0]const u8 {
5193pub fn stringToSliceUnwrap(ip: *const InternPool, s: OptionalNullTerminatedString) ?[:0]const u8 {
51945194 return ip.stringToSlice(s.unwrap() orelse return null);
51955195}
51965196
5197pub fn typeOf(ip: InternPool, index: Index) Index {
5197pub fn typeOf(ip: *const InternPool, index: Index) Index {
51985198 // This optimization of static keys is required so that typeOf can be called
51995199 // on static keys that haven't been added yet during static key initialization.
52005200 // An alternative would be to topological sort the static keys, but this would
......@@ -5382,12 +5382,12 @@ pub fn typeOf(ip: InternPool, index: Index) Index {
53825382}
53835383
53845384/// Assumes that the enum's field indexes equal its value tags.
5385pub fn toEnum(ip: InternPool, comptime E: type, i: Index) E {
5385pub fn toEnum(ip: *const InternPool, comptime E: type, i: Index) E {
53865386 const int = ip.indexToKey(i).enum_tag.int;
53875387 return @intToEnum(E, ip.indexToKey(int).int.storage.u64);
53885388}
53895389
5390pub fn aggregateTypeLen(ip: InternPool, ty: Index) u64 {
5390pub fn aggregateTypeLen(ip: *const InternPool, ty: Index) u64 {
53915391 return switch (ip.indexToKey(ty)) {
53925392 .struct_type => |struct_type| ip.structPtrConst(struct_type.index.unwrap() orelse return 0).fields.count(),
53935393 .anon_struct_type => |anon_struct_type| anon_struct_type.types.len,
......@@ -5397,7 +5397,7 @@ pub fn aggregateTypeLen(ip: InternPool, ty: Index) u64 {
53975397 };
53985398}
53995399
5400pub fn aggregateTypeLenIncludingSentinel(ip: InternPool, ty: Index) u64 {
5400pub fn aggregateTypeLenIncludingSentinel(ip: *const InternPool, ty: Index) u64 {
54015401 return switch (ip.indexToKey(ty)) {
54025402 .struct_type => |struct_type| ip.structPtrConst(struct_type.index.unwrap() orelse return 0).fields.count(),
54035403 .anon_struct_type => |anon_struct_type| anon_struct_type.types.len,
......@@ -5407,7 +5407,7 @@ pub fn aggregateTypeLenIncludingSentinel(ip: InternPool, ty: Index) u64 {
54075407 };
54085408}
54095409
5410pub fn isNoReturn(ip: InternPool, ty: Index) bool {
5410pub fn isNoReturn(ip: *const InternPool, ty: Index) bool {
54115411 return switch (ty) {
54125412 .noreturn_type => true,
54135413 else => switch (ip.indexToKey(ty)) {
......@@ -5420,7 +5420,7 @@ pub fn isNoReturn(ip: InternPool, ty: Index) bool {
54205420
54215421/// This is a particularly hot function, so we operate directly on encodings
54225422/// rather than the more straightforward implementation of calling `indexToKey`.
5423pub fn zigTypeTagOrPoison(ip: InternPool, index: Index) error{GenericPoison}!std.builtin.TypeId {
5423pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPoison}!std.builtin.TypeId {
54245424 return switch (index) {
54255425 .u1_type,
54265426 .u8_type,
src/Liveness.zig+4-4
......@@ -225,7 +225,7 @@ pub fn categorizeOperand(
225225 air: Air,
226226 inst: Air.Inst.Index,
227227 operand: Air.Inst.Index,
228 ip: InternPool,
228 ip: *const InternPool,
229229) OperandCategory {
230230 const air_tags = air.instructions.items(.tag);
231231 const air_datas = air.instructions.items(.data);
......@@ -1139,7 +1139,7 @@ fn analyzeInst(
11391139 .aggregate_init => {
11401140 const ty_pl = inst_datas[inst].ty_pl;
11411141 const aggregate_ty = a.air.getRefType(ty_pl.ty);
1142 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip.*));
1142 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip));
11431143 const elements = @ptrCast([]const Air.Inst.Ref, a.air.extra[ty_pl.payload..][0..len]);
11441144
11451145 if (elements.len <= bpi - 1) {
......@@ -1291,7 +1291,7 @@ fn analyzeOperands(
12911291 // If our result is unused and the instruction doesn't need to be lowered, backends will
12921292 // skip the lowering of this instruction, so we don't want to record uses of operands.
12931293 // That way, we can mark as many instructions as possible unused.
1294 if (!immediate_death or a.air.mustLower(inst, ip.*)) {
1294 if (!immediate_death or a.air.mustLower(inst, ip)) {
12951295 // Note that it's important we iterate over the operands backwards, so that if a dying
12961296 // operand is used multiple times we mark its last use as its death.
12971297 var i = operands.len;
......@@ -1837,7 +1837,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18371837 // If our result is unused and the instruction doesn't need to be lowered, backends will
18381838 // skip the lowering of this instruction, so we don't want to record uses of operands.
18391839 // That way, we can mark as many instructions as possible unused.
1840 if (big.will_die_immediately and !big.a.air.mustLower(big.inst, ip.*)) return;
1840 if (big.will_die_immediately and !big.a.air.mustLower(big.inst, ip)) return;
18411841
18421842 const extra_byte = (big.operands_remaining - (bpi - 1)) / 31;
18431843 const extra_bit = @intCast(u5, big.operands_remaining - (bpi - 1) - extra_byte * 31);
src/Liveness/Verify.zig+2-2
......@@ -32,7 +32,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
3232 const tag = self.air.instructions.items(.tag);
3333 const data = self.air.instructions.items(.data);
3434 for (body) |inst| {
35 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*)) {
35 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) {
3636 // This instruction will not be lowered and should be ignored.
3737 continue;
3838 }
......@@ -325,7 +325,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
325325 .aggregate_init => {
326326 const ty_pl = data[inst].ty_pl;
327327 const aggregate_ty = self.air.getRefType(ty_pl.ty);
328 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip.*));
328 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip));
329329 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
330330
331331 var bt = self.liveness.iterateBigTomb(inst);
src/Module.zig+1-1
......@@ -6726,7 +6726,7 @@ pub fn manyConstPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
67266726}
67276727
67286728pub fn adjustPtrTypeChild(mod: *Module, ptr_ty: Type, new_child: Type) Allocator.Error!Type {
6729 const info = Type.ptrInfoIp(mod.intern_pool, ptr_ty.toIntern());
6729 const info = Type.ptrInfoIp(&mod.intern_pool, ptr_ty.toIntern());
67306730 return mod.ptrType(.{
67316731 .elem_type = new_child.toIntern(),
67326732
src/Sema.zig+1-1
......@@ -33624,7 +33624,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3362433624
3362533625/// Returns the type of the AIR instruction.
3362633626fn typeOf(sema: *Sema, inst: Air.Inst.Ref) Type {
33627 return sema.getTmpAir().typeOf(inst, sema.mod.intern_pool);
33627 return sema.getTmpAir().typeOf(inst, &sema.mod.intern_pool);
3362833628}
3362933629
3363033630pub fn getTmpAir(sema: Sema) Air {
src/arch/aarch64/CodeGen.zig+3-3
......@@ -660,7 +660,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
660660
661661 for (body) |inst| {
662662 // TODO: remove now-redundant isUnused calls from AIR handler functions
663 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
663 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
664664 continue;
665665
666666 const old_air_bookkeeping = self.air_bookkeeping;
......@@ -6412,10 +6412,10 @@ fn registerAlias(self: *Self, reg: Register, ty: Type) Register {
64126412
64136413fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
64146414 const mod = self.bin_file.options.module.?;
6415 return self.air.typeOf(inst, mod.intern_pool);
6415 return self.air.typeOf(inst, &mod.intern_pool);
64166416}
64176417
64186418fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
64196419 const mod = self.bin_file.options.module.?;
6420 return self.air.typeOfIndex(inst, mod.intern_pool);
6420 return self.air.typeOfIndex(inst, &mod.intern_pool);
64216421}
src/arch/arm/CodeGen.zig+3-3
......@@ -644,7 +644,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
644644
645645 for (body) |inst| {
646646 // TODO: remove now-redundant isUnused calls from AIR handler functions
647 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
647 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
648648 continue;
649649
650650 const old_air_bookkeeping = self.air_bookkeeping;
......@@ -6317,10 +6317,10 @@ fn parseRegName(name: []const u8) ?Register {
63176317
63186318fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
63196319 const mod = self.bin_file.options.module.?;
6320 return self.air.typeOf(inst, mod.intern_pool);
6320 return self.air.typeOf(inst, &mod.intern_pool);
63216321}
63226322
63236323fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
63246324 const mod = self.bin_file.options.module.?;
6325 return self.air.typeOfIndex(inst, mod.intern_pool);
6325 return self.air.typeOfIndex(inst, &mod.intern_pool);
63266326}
src/arch/riscv64/CodeGen.zig+3-3
......@@ -478,7 +478,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
478478
479479 for (body) |inst| {
480480 // TODO: remove now-redundant isUnused calls from AIR handler functions
481 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
481 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
482482 continue;
483483
484484 const old_air_bookkeeping = self.air_bookkeeping;
......@@ -2737,10 +2737,10 @@ fn parseRegName(name: []const u8) ?Register {
27372737
27382738fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
27392739 const mod = self.bin_file.options.module.?;
2740 return self.air.typeOf(inst, mod.intern_pool);
2740 return self.air.typeOf(inst, &mod.intern_pool);
27412741}
27422742
27432743fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
27442744 const mod = self.bin_file.options.module.?;
2745 return self.air.typeOfIndex(inst, mod.intern_pool);
2745 return self.air.typeOfIndex(inst, &mod.intern_pool);
27462746}
src/arch/sparc64/CodeGen.zig+3-3
......@@ -498,7 +498,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
498498
499499 for (body) |inst| {
500500 // TODO: remove now-redundant isUnused calls from AIR handler functions
501 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
501 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
502502 continue;
503503
504504 const old_air_bookkeeping = self.air_bookkeeping;
......@@ -4883,10 +4883,10 @@ fn wantSafety(self: *Self) bool {
48834883
48844884fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
48854885 const mod = self.bin_file.options.module.?;
4886 return self.air.typeOf(inst, mod.intern_pool);
4886 return self.air.typeOf(inst, &mod.intern_pool);
48874887}
48884888
48894889fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
48904890 const mod = self.bin_file.options.module.?;
4891 return self.air.typeOfIndex(inst, mod.intern_pool);
4891 return self.air.typeOfIndex(inst, &mod.intern_pool);
48924892}
src/arch/wasm/CodeGen.zig+3-3
......@@ -2076,7 +2076,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
20762076 const ip = &mod.intern_pool;
20772077
20782078 for (body) |inst| {
2079 if (func.liveness.isUnused(inst) and !func.air.mustLower(inst, ip.*)) {
2079 if (func.liveness.isUnused(inst) and !func.air.mustLower(inst, ip)) {
20802080 continue;
20812081 }
20822082 const old_bookkeeping_value = func.air_bookkeeping;
......@@ -7436,10 +7436,10 @@ fn airFrameAddress(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
74367436
74377437fn typeOf(func: *CodeGen, inst: Air.Inst.Ref) Type {
74387438 const mod = func.bin_file.base.options.module.?;
7439 return func.air.typeOf(inst, mod.intern_pool);
7439 return func.air.typeOf(inst, &mod.intern_pool);
74407440}
74417441
74427442fn typeOfIndex(func: *CodeGen, inst: Air.Inst.Index) Type {
74437443 const mod = func.bin_file.base.options.module.?;
7444 return func.air.typeOfIndex(inst, mod.intern_pool);
7444 return func.air.typeOfIndex(inst, &mod.intern_pool);
74457445}
src/arch/x86_64/CodeGen.zig+3-3
......@@ -1738,7 +1738,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
17381738 try self.mir_to_air_map.put(self.gpa, mir_inst, inst);
17391739 }
17401740
1741 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*)) continue;
1741 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;
17421742 wip_mir_log.debug("{}", .{self.fmtAir(inst)});
17431743 verbose_tracking_log.debug("{}", .{self.fmtTracking()});
17441744
......@@ -11992,10 +11992,10 @@ fn hasAllFeatures(self: *Self, features: anytype) bool {
1199211992
1199311993fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
1199411994 const mod = self.bin_file.options.module.?;
11995 return self.air.typeOf(inst, mod.intern_pool);
11995 return self.air.typeOf(inst, &mod.intern_pool);
1199611996}
1199711997
1199811998fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
1199911999 const mod = self.bin_file.options.module.?;
12000 return self.air.typeOfIndex(inst, mod.intern_pool);
12000 return self.air.typeOfIndex(inst, &mod.intern_pool);
1200112001}
src/codegen/c.zig+3-3
......@@ -489,12 +489,12 @@ pub const Function = struct {
489489
490490 fn typeOf(f: *Function, inst: Air.Inst.Ref) Type {
491491 const mod = f.object.dg.module;
492 return f.air.typeOf(inst, mod.intern_pool);
492 return f.air.typeOf(inst, &mod.intern_pool);
493493 }
494494
495495 fn typeOfIndex(f: *Function, inst: Air.Inst.Index) Type {
496496 const mod = f.object.dg.module;
497 return f.air.typeOfIndex(inst, mod.intern_pool);
497 return f.air.typeOfIndex(inst, &mod.intern_pool);
498498 }
499499};
500500
......@@ -2808,7 +2808,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
28082808 const air_tags = f.air.instructions.items(.tag);
28092809
28102810 for (body) |inst| {
2811 if (f.liveness.isUnused(inst) and !f.air.mustLower(inst, ip.*))
2811 if (f.liveness.isUnused(inst) and !f.air.mustLower(inst, ip))
28122812 continue;
28132813
28142814 const result_value = switch (air_tags[inst]) {
src/codegen/llvm.zig+5-5
......@@ -1574,7 +1574,7 @@ pub const Object = struct {
15741574 },
15751575 .Pointer => {
15761576 // Normalize everything that the debug info does not represent.
1577 const ptr_info = Type.ptrInfoIp(mod.intern_pool, ty.toIntern());
1577 const ptr_info = Type.ptrInfoIp(&mod.intern_pool, ty.toIntern());
15781578
15791579 if (ptr_info.sentinel != .none or
15801580 ptr_info.address_space != .generic or
......@@ -4330,7 +4330,7 @@ pub const FuncGen = struct {
43304330 const ip = &mod.intern_pool;
43314331 const air_tags = self.air.instructions.items(.tag);
43324332 for (body, 0..) |inst, i| {
4333 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
4333 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
43344334 continue;
43354335
43364336 const opt_value: ?*llvm.Value = switch (air_tags[inst]) {
......@@ -8055,7 +8055,7 @@ pub const FuncGen = struct {
80558055 const mod = fg.dg.module;
80568056 const ip = &mod.intern_pool;
80578057 for (body_tail[1..]) |body_inst| {
8058 switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0], ip.*)) {
8058 switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0], ip)) {
80598059 .none => continue,
80608060 .write, .noret, .complex => return false,
80618061 .tomb => return true,
......@@ -9920,12 +9920,12 @@ pub const FuncGen = struct {
99209920
99219921 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {
99229922 const mod = fg.dg.module;
9923 return fg.air.typeOf(inst, mod.intern_pool);
9923 return fg.air.typeOf(inst, &mod.intern_pool);
99249924 }
99259925
99269926 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {
99279927 const mod = fg.dg.module;
9928 return fg.air.typeOfIndex(inst, mod.intern_pool);
9928 return fg.air.typeOfIndex(inst, &mod.intern_pool);
99299929 }
99309930};
99319931
src/codegen/spirv.zig+3-3
......@@ -1688,7 +1688,7 @@ pub const DeclGen = struct {
16881688 const mod = self.module;
16891689 const ip = &mod.intern_pool;
16901690 // TODO: remove now-redundant isUnused calls from AIR handler functions
1691 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
1691 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
16921692 return;
16931693
16941694 const air_tags = self.air.instructions.items(.tag);
......@@ -3339,11 +3339,11 @@ pub const DeclGen = struct {
33393339
33403340 fn typeOf(self: *DeclGen, inst: Air.Inst.Ref) Type {
33413341 const mod = self.module;
3342 return self.air.typeOf(inst, mod.intern_pool);
3342 return self.air.typeOf(inst, &mod.intern_pool);
33433343 }
33443344
33453345 fn typeOfIndex(self: *DeclGen, inst: Air.Inst.Index) Type {
33463346 const mod = self.module;
3347 return self.air.typeOfIndex(inst, mod.intern_pool);
3347 return self.air.typeOfIndex(inst, &mod.intern_pool);
33483348 }
33493349};
src/print_air.zig+1-1
......@@ -978,6 +978,6 @@ const Writer = struct {
978978
979979 fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type {
980980 const mod = w.module;
981 return w.air.typeOfIndex(inst, mod.intern_pool);
981 return w.air.typeOfIndex(inst, &mod.intern_pool);
982982 }
983983};
src/type.zig+10-10
......@@ -102,7 +102,7 @@ pub const Type = struct {
102102 };
103103 }
104104
105 pub fn ptrInfoIp(ip: InternPool, ty: InternPool.Index) InternPool.Key.PtrType {
105 pub fn ptrInfoIp(ip: *const InternPool, ty: InternPool.Index) InternPool.Key.PtrType {
106106 return switch (ip.indexToKey(ty)) {
107107 .ptr_type => |p| p,
108108 .opt_type => |child| switch (ip.indexToKey(child)) {
......@@ -114,7 +114,7 @@ pub const Type = struct {
114114 }
115115
116116 pub fn ptrInfo(ty: Type, mod: *const Module) Payload.Pointer.Data {
117 return Payload.Pointer.Data.fromKey(ptrInfoIp(mod.intern_pool, ty.toIntern()));
117 return Payload.Pointer.Data.fromKey(ptrInfoIp(&mod.intern_pool, ty.toIntern()));
118118 }
119119
120120 pub fn eql(a: Type, b: Type, mod: *const Module) bool {
......@@ -1832,10 +1832,10 @@ pub const Type = struct {
18321832 }
18331833
18341834 pub fn isVolatilePtr(ty: Type, mod: *const Module) bool {
1835 return isVolatilePtrIp(ty, mod.intern_pool);
1835 return isVolatilePtrIp(ty, &mod.intern_pool);
18361836 }
18371837
1838 pub fn isVolatilePtrIp(ty: Type, ip: InternPool) bool {
1838 pub fn isVolatilePtrIp(ty: Type, ip: *const InternPool) bool {
18391839 return switch (ip.indexToKey(ty.toIntern())) {
18401840 .ptr_type => |ptr_type| ptr_type.is_volatile,
18411841 else => false,
......@@ -1920,10 +1920,10 @@ pub const Type = struct {
19201920 /// For *T, returns T.
19211921 /// For [*]T, returns T.
19221922 pub fn childType(ty: Type, mod: *const Module) Type {
1923 return childTypeIp(ty, mod.intern_pool);
1923 return childTypeIp(ty, &mod.intern_pool);
19241924 }
19251925
1926 pub fn childTypeIp(ty: Type, ip: InternPool) Type {
1926 pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {
19271927 return ip.childType(ty.toIntern()).toType();
19281928 }
19291929
......@@ -2164,10 +2164,10 @@ pub const Type = struct {
21642164
21652165 /// Asserts the type is an array or vector or struct.
21662166 pub fn arrayLen(ty: Type, mod: *const Module) u64 {
2167 return arrayLenIp(ty, mod.intern_pool);
2167 return arrayLenIp(ty, &mod.intern_pool);
21682168 }
21692169
2170 pub fn arrayLenIp(ty: Type, ip: InternPool) u64 {
2170 pub fn arrayLenIp(ty: Type, ip: *const InternPool) u64 {
21712171 return switch (ip.indexToKey(ty.toIntern())) {
21722172 .vector_type => |vector_type| vector_type.len,
21732173 .array_type => |array_type| array_type.len,
......@@ -2385,10 +2385,10 @@ pub const Type = struct {
23852385
23862386 /// Asserts the type is a function or a function pointer.
23872387 pub fn fnReturnType(ty: Type, mod: *Module) Type {
2388 return fnReturnTypeIp(ty, mod.intern_pool);
2388 return fnReturnTypeIp(ty, &mod.intern_pool);
23892389 }
23902390
2391 pub fn fnReturnTypeIp(ty: Type, ip: InternPool) Type {
2391 pub fn fnReturnTypeIp(ty: Type, ip: *const InternPool) Type {
23922392 return switch (ip.indexToKey(ty.toIntern())) {
23932393 .ptr_type => |ptr_type| ip.indexToKey(ptr_type.elem_type).func_type.return_type,
23942394 .func_type => |func_type| func_type.return_type,