authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-02 14:37:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:40:03-07:00
log00f82f1c46126f1fc6655c6142ef16e8e5afbf4e
treeaa9f759bddb01a7469083363da65ef4717509a52
parentc7e84ddb722df0403dd6ae8283820c02efc77e50

stage2: add `interned` AIR tag

This required additionally passing the `InternPool` into some AIR methods. Also, implement `Type.isNoReturn` for interned types.

17 files changed, 1050 insertions(+), 961 deletions(-)

src/Air.zig+32-26
......@@ -11,6 +11,7 @@ const Air = @This();
1111const Value = @import("value.zig").Value;
1212const Type = @import("type.zig").Type;
1313const InternPool = @import("InternPool.zig");
14const Module = @import("Module.zig");
1415
1516instructions: std.MultiArrayList(Inst).Slice,
1617/// The meaning of this data is determined by `Inst.Tag` value.
......@@ -401,6 +402,9 @@ pub const Inst = struct {
401402 constant,
402403 /// A comptime-known type. Uses the `ty` field.
403404 const_ty,
405 /// A comptime-known value via an index into the InternPool.
406 /// Uses the `interned` field.
407 interned,
404408 /// Notes the beginning of a source code statement and marks the line and column.
405409 /// Result type is always void.
406410 /// Uses the `dbg_stmt` field.
......@@ -928,6 +932,7 @@ pub const Inst = struct {
928932 pub const Data = union {
929933 no_op: void,
930934 un_op: Ref,
935 interned: InternPool.Index,
931936
932937 bin_op: struct {
933938 lhs: Ref,
......@@ -1147,18 +1152,15 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {
11471152 return air.extra[extra.end..][0..extra.data.body_len];
11481153}
11491154
1150pub fn typeOf(air: Air, inst: Air.Inst.Ref) Type {
1155pub fn typeOf(air: Air, inst: Air.Inst.Ref, ip: InternPool) Type {
11511156 const ref_int = @enumToInt(inst);
11521157 if (ref_int < InternPool.static_keys.len) {
1153 return .{
1154 .ip_index = InternPool.static_keys[ref_int].typeOf(),
1155 .legacy = undefined,
1156 };
1158 return InternPool.static_keys[ref_int].typeOf().toType();
11571159 }
1158 return air.typeOfIndex(ref_int - ref_start_index);
1160 return air.typeOfIndex(ref_int - ref_start_index, ip);
11591161}
11601162
1161pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
1163pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {
11621164 const datas = air.instructions.items(.data);
11631165 switch (air.instructions.items(.tag)[inst]) {
11641166 .add,
......@@ -1200,7 +1202,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
12001202 .div_exact_optimized,
12011203 .rem_optimized,
12021204 .mod_optimized,
1203 => return air.typeOf(datas[inst].bin_op.lhs),
1205 => return air.typeOf(datas[inst].bin_op.lhs, ip),
12041206
12051207 .sqrt,
12061208 .sin,
......@@ -1218,7 +1220,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
12181220 .trunc_float,
12191221 .neg,
12201222 .neg_optimized,
1221 => return air.typeOf(datas[inst].un_op),
1223 => return air.typeOf(datas[inst].un_op, ip),
12221224
12231225 .cmp_lt,
12241226 .cmp_lte,
......@@ -1280,6 +1282,8 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
12801282 .try_ptr,
12811283 => return air.getRefType(datas[inst].ty_pl.ty),
12821284
1285 .interned => return ip.indexToKey(datas[inst].interned).typeOf().toType(),
1286
12831287 .not,
12841288 .bitcast,
12851289 .load,
......@@ -1371,33 +1375,33 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
13711375 .tag_name, .error_name => return Type.initTag(.const_slice_u8_sentinel_0),
13721376
13731377 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
1374 const callee_ty = air.typeOf(datas[inst].pl_op.operand);
1378 const callee_ty = air.typeOf(datas[inst].pl_op.operand, ip);
13751379 return callee_ty.fnReturnType();
13761380 },
13771381
13781382 .slice_elem_val, .ptr_elem_val, .array_elem_val => {
1379 const ptr_ty = air.typeOf(datas[inst].bin_op.lhs);
1383 const ptr_ty = air.typeOf(datas[inst].bin_op.lhs, ip);
13801384 return ptr_ty.elemType();
13811385 },
13821386 .atomic_load => {
1383 const ptr_ty = air.typeOf(datas[inst].atomic_load.ptr);
1387 const ptr_ty = air.typeOf(datas[inst].atomic_load.ptr, ip);
13841388 return ptr_ty.elemType();
13851389 },
13861390 .atomic_rmw => {
1387 const ptr_ty = air.typeOf(datas[inst].pl_op.operand);
1391 const ptr_ty = air.typeOf(datas[inst].pl_op.operand, ip);
13881392 return ptr_ty.elemType();
13891393 },
13901394
1391 .reduce, .reduce_optimized => return air.typeOf(datas[inst].reduce.operand).childType(),
1395 .reduce, .reduce_optimized => return air.typeOf(datas[inst].reduce.operand, ip).childType(),
13921396
1393 .mul_add => return air.typeOf(datas[inst].pl_op.operand),
1397 .mul_add => return air.typeOf(datas[inst].pl_op.operand, ip),
13941398 .select => {
13951399 const extra = air.extraData(Air.Bin, datas[inst].pl_op.payload).data;
1396 return air.typeOf(extra.lhs);
1400 return air.typeOf(extra.lhs, ip);
13971401 },
13981402
13991403 .@"try" => {
1400 const err_union_ty = air.typeOf(datas[inst].pl_op.operand);
1404 const err_union_ty = air.typeOf(datas[inst].pl_op.operand, ip);
14011405 return err_union_ty.errorUnionPayload();
14021406 },
14031407
......@@ -1465,7 +1469,7 @@ pub fn refToIndex(inst: Air.Inst.Ref) ?Air.Inst.Index {
14651469}
14661470
14671471/// Returns `null` if runtime-known.
1468pub fn value(air: Air, inst: Air.Inst.Ref, mod: *const @import("Module.zig")) ?Value {
1472pub fn value(air: Air, inst: Air.Inst.Ref, mod: *const Module) ?Value {
14691473 const ref_int = @enumToInt(inst);
14701474 if (ref_int < ref_start_index) {
14711475 const ip_index = @intToEnum(InternPool.Index, ref_int);
......@@ -1476,7 +1480,7 @@ pub fn value(air: Air, inst: Air.Inst.Ref, mod: *const @import("Module.zig")) ?V
14761480 switch (air.instructions.items(.tag)[inst_index]) {
14771481 .constant => return air.values[air_datas[inst_index].ty_pl.payload],
14781482 .const_ty => unreachable,
1479 else => return air.typeOfIndex(inst_index).onePossibleValue(mod),
1483 else => return air.typeOfIndex(inst_index, mod.intern_pool).onePossibleValue(mod),
14801484 }
14811485}
14821486
......@@ -1489,10 +1493,11 @@ pub fn nullTerminatedString(air: Air, index: usize) [:0]const u8 {
14891493 return bytes[0..end :0];
14901494}
14911495
1492/// Returns whether the given instruction must always be lowered, for instance because it can cause
1493/// side effects. If an instruction does not need to be lowered, and Liveness determines its result
1494/// is unused, backends should avoid lowering it.
1495pub fn mustLower(air: Air, inst: Air.Inst.Index) bool {
1496/// Returns whether the given instruction must always be lowered, for instance
1497/// because it can cause side effects. If an instruction does not need to be
1498/// lowered, and Liveness determines its result is unused, backends should
1499/// avoid lowering it.
1500pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: InternPool) bool {
14961501 const data = air.instructions.items(.data)[inst];
14971502 return switch (air.instructions.items(.tag)[inst]) {
14981503 .arg,
......@@ -1631,6 +1636,7 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index) bool {
16311636 .cmp_vector_optimized,
16321637 .constant,
16331638 .const_ty,
1639 .interned,
16341640 .is_null,
16351641 .is_non_null,
16361642 .is_null_ptr,
......@@ -1699,8 +1705,8 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index) bool {
16991705 => false,
17001706
17011707 .assembly => @truncate(u1, air.extraData(Air.Asm, data.ty_pl.payload).data.flags >> 31) != 0,
1702 .load => air.typeOf(data.ty_op.operand).isVolatilePtr(),
1703 .slice_elem_val, .ptr_elem_val => air.typeOf(data.bin_op.lhs).isVolatilePtr(),
1704 .atomic_load => air.typeOf(data.atomic_load.ptr).isVolatilePtr(),
1708 .load => air.typeOf(data.ty_op.operand, ip).isVolatilePtr(),
1709 .slice_elem_val, .ptr_elem_val => air.typeOf(data.bin_op.lhs, ip).isVolatilePtr(),
1710 .atomic_load => air.typeOf(data.atomic_load.ptr, ip).isVolatilePtr(),
17051711 };
17061712}
src/InternPool.zig+6
......@@ -241,6 +241,11 @@ pub const Item = struct {
241241/// When adding a tag to this enum, consider adding a corresponding entry to
242242/// `primitives` in AstGen.zig.
243243pub const Index = enum(u32) {
244 pub const first_type: Index = .u1_type;
245 pub const last_type: Index = .empty_struct_type;
246 pub const first_value: Index = .undef;
247 pub const last_value: Index = .empty_struct;
248
244249 u1_type,
245250 u8_type,
246251 i8_type,
......@@ -329,6 +334,7 @@ pub const Index = enum(u32) {
329334 bool_false,
330335 /// `.{}` (untyped)
331336 empty_struct,
337
332338 /// Used for generic parameters where the type and value
333339 /// is not known until generic function instantiation.
334340 generic_poison,
src/Liveness.zig+12-6
......@@ -131,7 +131,7 @@ fn LivenessPassData(comptime pass: LivenessPass) type {
131131 };
132132}
133133
134pub fn analyze(gpa: Allocator, air: Air) Allocator.Error!Liveness {
134pub fn analyze(gpa: Allocator, air: Air, intern_pool: *const InternPool) Allocator.Error!Liveness {
135135 const tracy = trace(@src());
136136 defer tracy.end();
137137
......@@ -144,6 +144,7 @@ pub fn analyze(gpa: Allocator, air: Air) Allocator.Error!Liveness {
144144 ),
145145 .extra = .{},
146146 .special = .{},
147 .intern_pool = intern_pool,
147148 };
148149 errdefer gpa.free(a.tomb_bits);
149150 errdefer a.special.deinit(gpa);
......@@ -322,6 +323,7 @@ pub fn categorizeOperand(
322323 .ret_ptr,
323324 .constant,
324325 .const_ty,
326 .interned,
325327 .trap,
326328 .breakpoint,
327329 .dbg_stmt,
......@@ -820,6 +822,7 @@ pub const BigTomb = struct {
820822const Analysis = struct {
821823 gpa: Allocator,
822824 air: Air,
825 intern_pool: *const InternPool,
823826 tomb_bits: []usize,
824827 special: std.AutoHashMapUnmanaged(Air.Inst.Index, u32),
825828 extra: std.ArrayListUnmanaged(u32),
......@@ -971,6 +974,7 @@ fn analyzeInst(
971974
972975 .constant,
973976 .const_ty,
977 .interned,
974978 => unreachable,
975979
976980 .trap,
......@@ -1255,6 +1259,7 @@ fn analyzeOperands(
12551259) Allocator.Error!void {
12561260 const gpa = a.gpa;
12571261 const inst_tags = a.air.instructions.items(.tag);
1262 const ip = a.intern_pool;
12581263
12591264 switch (pass) {
12601265 .loop_analysis => {
......@@ -1265,7 +1270,7 @@ fn analyzeOperands(
12651270
12661271 // Don't compute any liveness for constants
12671272 switch (inst_tags[operand]) {
1268 .constant, .const_ty => continue,
1273 .constant, .const_ty, .interned => continue,
12691274 else => {},
12701275 }
12711276
......@@ -1290,7 +1295,7 @@ fn analyzeOperands(
12901295 // If our result is unused and the instruction doesn't need to be lowered, backends will
12911296 // skip the lowering of this instruction, so we don't want to record uses of operands.
12921297 // That way, we can mark as many instructions as possible unused.
1293 if (!immediate_death or a.air.mustLower(inst)) {
1298 if (!immediate_death or a.air.mustLower(inst, ip.*)) {
12941299 // Note that it's important we iterate over the operands backwards, so that if a dying
12951300 // operand is used multiple times we mark its last use as its death.
12961301 var i = operands.len;
......@@ -1301,7 +1306,7 @@ fn analyzeOperands(
13011306
13021307 // Don't compute any liveness for constants
13031308 switch (inst_tags[operand]) {
1304 .constant, .const_ty => continue,
1309 .constant, .const_ty, .interned => continue,
13051310 else => {},
13061311 }
13071312
......@@ -1821,6 +1826,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18211826
18221827 /// Must be called with operands in reverse order.
18231828 fn feed(big: *Self, op_ref: Air.Inst.Ref) !void {
1829 const ip = big.a.intern_pool;
18241830 // Note that after this, `operands_remaining` becomes the index of the current operand
18251831 big.operands_remaining -= 1;
18261832
......@@ -1834,14 +1840,14 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18341840 // Don't compute any liveness for constants
18351841 const inst_tags = big.a.air.instructions.items(.tag);
18361842 switch (inst_tags[operand]) {
1837 .constant, .const_ty => return,
1843 .constant, .const_ty, .interned => return,
18381844 else => {},
18391845 }
18401846
18411847 // If our result is unused and the instruction doesn't need to be lowered, backends will
18421848 // skip the lowering of this instruction, so we don't want to record uses of operands.
18431849 // That way, we can mark as many instructions as possible unused.
1844 if (big.will_die_immediately and !big.a.air.mustLower(big.inst)) return;
1850 if (big.will_die_immediately and !big.a.air.mustLower(big.inst, ip.*)) return;
18451851
18461852 const extra_byte = (big.operands_remaining - (bpi - 1)) / 31;
18471853 const extra_bit = @intCast(u5, big.operands_remaining - (bpi - 1) - extra_byte * 31);
src/Liveness/Verify.zig+7-3
......@@ -5,6 +5,7 @@ air: Air,
55liveness: Liveness,
66live: LiveMap = .{},
77blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, LiveMap) = .{},
8intern_pool: *const InternPool,
89
910pub const Error = error{ LivenessInvalid, OutOfMemory };
1011
......@@ -27,10 +28,11 @@ pub fn verify(self: *Verify) Error!void {
2728const LiveMap = std.AutoHashMapUnmanaged(Air.Inst.Index, void);
2829
2930fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
31 const ip = self.intern_pool;
3032 const tag = self.air.instructions.items(.tag);
3133 const data = self.air.instructions.items(.data);
3234 for (body) |inst| {
33 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst)) {
35 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*)) {
3436 // This instruction will not be lowered and should be ignored.
3537 continue;
3638 }
......@@ -42,6 +44,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
4244 .ret_ptr,
4345 .constant,
4446 .const_ty,
47 .interned,
4548 .breakpoint,
4649 .dbg_stmt,
4750 .dbg_inline_begin,
......@@ -554,7 +557,7 @@ fn verifyDeath(self: *Verify, inst: Air.Inst.Index, operand: Air.Inst.Index) Err
554557fn verifyOperand(self: *Verify, inst: Air.Inst.Index, op_ref: Air.Inst.Ref, dies: bool) Error!void {
555558 const operand = Air.refToIndex(op_ref) orelse return;
556559 switch (self.air.instructions.items(.tag)[operand]) {
557 .constant, .const_ty => {},
560 .constant, .const_ty, .interned => {},
558561 else => {
559562 if (dies) {
560563 if (!self.live.remove(operand)) return invalid("%{}: dead operand %{} reused and killed again", .{ inst, operand });
......@@ -576,7 +579,7 @@ fn verifyInst(
576579 }
577580 const tag = self.air.instructions.items(.tag);
578581 switch (tag[inst]) {
579 .constant, .const_ty => unreachable,
582 .constant, .const_ty, .interned => unreachable,
580583 else => {
581584 if (self.liveness.isUnused(inst)) {
582585 assert(!self.live.contains(inst));
......@@ -604,4 +607,5 @@ const log = std.log.scoped(.liveness_verify);
604607
605608const Air = @import("../Air.zig");
606609const Liveness = @import("../Liveness.zig");
610const InternPool = @import("../InternPool.zig");
607611const Verify = @This();
src/Module.zig+2-1
......@@ -4397,7 +4397,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {
43974397 if (no_bin_file and !dump_air and !dump_llvm_ir) return;
43984398
43994399 log.debug("analyze liveness of {s}", .{decl.name});
4400 var liveness = try Liveness.analyze(gpa, air);
4400 var liveness = try Liveness.analyze(gpa, air, &mod.intern_pool);
44014401 defer liveness.deinit(gpa);
44024402
44034403 if (dump_air) {
......@@ -4414,6 +4414,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {
44144414 .gpa = gpa,
44154415 .air = air,
44164416 .liveness = liveness,
4417 .intern_pool = &mod.intern_pool,
44174418 };
44184419 defer verify.deinit();
44194420
src/Sema.zig+9-83
......@@ -33007,7 +33007,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3300733007
3300833008/// Returns the type of the AIR instruction.
3300933009fn typeOf(sema: *Sema, inst: Air.Inst.Ref) Type {
33010 return sema.getTmpAir().typeOf(inst);
33010 return sema.getTmpAir().typeOf(inst, sema.mod.intern_pool);
3301133011}
3301233012
3301333013pub fn getTmpAir(sema: Sema) Air {
......@@ -33019,88 +33019,14 @@ pub fn getTmpAir(sema: Sema) Air {
3301933019}
3302033020
3302133021pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
33022 switch (ty.ip_index) {
33023 .u1_type => return .u1_type,
33024 .u8_type => return .u8_type,
33025 .i8_type => return .i8_type,
33026 .u16_type => return .u16_type,
33027 .i16_type => return .i16_type,
33028 .u29_type => return .u29_type,
33029 .u32_type => return .u32_type,
33030 .i32_type => return .i32_type,
33031 .u64_type => return .u64_type,
33032 .i64_type => return .i64_type,
33033 .u80_type => return .u80_type,
33034 .u128_type => return .u128_type,
33035 .i128_type => return .i128_type,
33036 .usize_type => return .usize_type,
33037 .isize_type => return .isize_type,
33038 .c_char_type => return .c_char_type,
33039 .c_short_type => return .c_short_type,
33040 .c_ushort_type => return .c_ushort_type,
33041 .c_int_type => return .c_int_type,
33042 .c_uint_type => return .c_uint_type,
33043 .c_long_type => return .c_long_type,
33044 .c_ulong_type => return .c_ulong_type,
33045 .c_longlong_type => return .c_longlong_type,
33046 .c_ulonglong_type => return .c_ulonglong_type,
33047 .c_longdouble_type => return .c_longdouble_type,
33048 .f16_type => return .f16_type,
33049 .f32_type => return .f32_type,
33050 .f64_type => return .f64_type,
33051 .f80_type => return .f80_type,
33052 .f128_type => return .f128_type,
33053 .anyopaque_type => return .anyopaque_type,
33054 .bool_type => return .bool_type,
33055 .void_type => return .void_type,
33056 .type_type => return .type_type,
33057 .anyerror_type => return .anyerror_type,
33058 .comptime_int_type => return .comptime_int_type,
33059 .comptime_float_type => return .comptime_float_type,
33060 .noreturn_type => return .noreturn_type,
33061 .anyframe_type => return .anyframe_type,
33062 .null_type => return .null_type,
33063 .undefined_type => return .undefined_type,
33064 .enum_literal_type => return .enum_literal_type,
33065 .atomic_order_type => return .atomic_order_type,
33066 .atomic_rmw_op_type => return .atomic_rmw_op_type,
33067 .calling_convention_type => return .calling_convention_type,
33068 .address_space_type => return .address_space_type,
33069 .float_mode_type => return .float_mode_type,
33070 .reduce_op_type => return .reduce_op_type,
33071 .call_modifier_type => return .call_modifier_type,
33072 .prefetch_options_type => return .prefetch_options_type,
33073 .export_options_type => return .export_options_type,
33074 .extern_options_type => return .extern_options_type,
33075 .type_info_type => return .type_info_type,
33076 .manyptr_u8_type => return .manyptr_u8_type,
33077 .manyptr_const_u8_type => return .manyptr_const_u8_type,
33078 .single_const_pointer_to_comptime_int_type => return .single_const_pointer_to_comptime_int_type,
33079 .const_slice_u8_type => return .const_slice_u8_type,
33080 .anyerror_void_error_union_type => return .anyerror_void_error_union_type,
33081 .generic_poison_type => return .generic_poison_type,
33082 .var_args_param_type => return .var_args_param_type,
33083 .empty_struct_type => return .empty_struct_type,
33084
33085 // values
33086 .undef => unreachable,
33087 .zero => unreachable,
33088 .zero_usize => unreachable,
33089 .one => unreachable,
33090 .one_usize => unreachable,
33091 .calling_convention_c => unreachable,
33092 .calling_convention_inline => unreachable,
33093 .void_value => unreachable,
33094 .unreachable_value => unreachable,
33095 .null_value => unreachable,
33096 .bool_true => unreachable,
33097 .bool_false => unreachable,
33098 .empty_struct => unreachable,
33099 .generic_poison => unreachable,
33100
33101 _ => {},
33102
33103 .none => unreachable,
33022 if (ty.ip_index != .none) {
33023 if (@enumToInt(ty.ip_index) < Air.ref_start_index)
33024 return @intToEnum(Air.Inst.Ref, @enumToInt(ty.ip_index));
33025 try sema.air_instructions.append(sema.gpa, .{
33026 .tag = .interned,
33027 .data = .{ .interned = ty.ip_index },
33028 });
33029 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
3310433030 }
3310533031 switch (ty.tag()) {
3310633032 .u1 => return .u1_type,
src/arch/aarch64/CodeGen.zig+92-80
......@@ -521,7 +521,7 @@ fn gen(self: *Self) !void {
521521 const inst = self.air.getMainBody()[arg_index];
522522 assert(self.air.instructions.items(.tag)[inst] == .arg);
523523
524 const ty = self.air.typeOfIndex(inst);
524 const ty = self.typeOfIndex(inst);
525525
526526 const abi_size = @intCast(u32, ty.abiSize(mod));
527527 const abi_align = ty.abiAlignment(mod);
......@@ -653,13 +653,14 @@ fn gen(self: *Self) !void {
653653}
654654
655655fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
656 const mod = self.bin_file.options.module.?;
657 const ip = &mod.intern_pool;
656658 const air_tags = self.air.instructions.items(.tag);
657659
658660 for (body) |inst| {
659661 // TODO: remove now-redundant isUnused calls from AIR handler functions
660 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst)) {
662 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
661663 continue;
662 }
663664
664665 const old_air_bookkeeping = self.air_bookkeeping;
665666 try self.ensureProcessDeathCapacity(Liveness.bpi);
......@@ -845,6 +846,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
845846
846847 .constant => unreachable, // excluded from function bodies
847848 .const_ty => unreachable, // excluded from function bodies
849 .interned => unreachable, // excluded from function bodies
848850 .unreach => self.finishAirBookkeeping(),
849851
850852 .optional_payload => try self.airOptionalPayload(inst),
......@@ -1028,7 +1030,7 @@ fn allocMem(
10281030/// Use a pointer instruction as the basis for allocating stack memory.
10291031fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
10301032 const mod = self.bin_file.options.module.?;
1031 const elem_ty = self.air.typeOfIndex(inst).elemType();
1033 const elem_ty = self.typeOfIndex(inst).elemType();
10321034
10331035 if (!elem_ty.hasRuntimeBits(mod)) {
10341036 // return the stack offset 0. Stack offset 0 will be where all
......@@ -1067,7 +1069,7 @@ fn allocRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool, maybe_inst: ?Air.Inst
10671069}
10681070
10691071pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void {
1070 const stack_mcv = try self.allocRegOrMem(self.air.typeOfIndex(inst), false, inst);
1072 const stack_mcv = try self.allocRegOrMem(self.typeOfIndex(inst), false, inst);
10711073 log.debug("spilling {d} to stack mcv {any}", .{ inst, stack_mcv });
10721074
10731075 const reg_mcv = self.getResolvedInstValue(inst);
......@@ -1079,14 +1081,14 @@ pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void
10791081
10801082 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
10811083 try branch.inst_table.put(self.gpa, inst, stack_mcv);
1082 try self.genSetStack(self.air.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv);
1084 try self.genSetStack(self.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv);
10831085}
10841086
10851087/// Save the current instruction stored in the compare flags if
10861088/// occupied
10871089fn spillCompareFlagsIfOccupied(self: *Self) !void {
10881090 if (self.compare_flags_inst) |inst_to_save| {
1089 const ty = self.air.typeOfIndex(inst_to_save);
1091 const ty = self.typeOfIndex(inst_to_save);
10901092 const mcv = self.getResolvedInstValue(inst_to_save);
10911093 const new_mcv = switch (mcv) {
10921094 .compare_flags => try self.allocRegOrMem(ty, true, inst_to_save),
......@@ -1094,7 +1096,7 @@ fn spillCompareFlagsIfOccupied(self: *Self) !void {
10941096 else => unreachable, // mcv doesn't occupy the compare flags
10951097 };
10961098
1097 try self.setRegOrMem(self.air.typeOfIndex(inst_to_save), new_mcv, mcv);
1099 try self.setRegOrMem(self.typeOfIndex(inst_to_save), new_mcv, mcv);
10981100 log.debug("spilling {d} to mcv {any}", .{ inst_to_save, new_mcv });
10991101
11001102 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
......@@ -1126,9 +1128,9 @@ fn copyToTmpRegister(self: *Self, ty: Type, mcv: MCValue) !Register {
11261128/// This can have a side effect of spilling instructions to the stack to free up a register.
11271129fn copyToNewRegister(self: *Self, reg_owner: Air.Inst.Index, mcv: MCValue) !MCValue {
11281130 const raw_reg = try self.register_manager.allocReg(reg_owner, gp);
1129 const ty = self.air.typeOfIndex(reg_owner);
1131 const ty = self.typeOfIndex(reg_owner);
11301132 const reg = self.registerAlias(raw_reg, ty);
1131 try self.genSetReg(self.air.typeOfIndex(reg_owner), reg, mcv);
1133 try self.genSetReg(self.typeOfIndex(reg_owner), reg, mcv);
11321134 return MCValue{ .register = reg };
11331135}
11341136
......@@ -1181,10 +1183,10 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
11811183 const mod = self.bin_file.options.module.?;
11821184 const operand = ty_op.operand;
11831185 const operand_mcv = try self.resolveInst(operand);
1184 const operand_ty = self.air.typeOf(operand);
1186 const operand_ty = self.typeOf(operand);
11851187 const operand_info = operand_ty.intInfo(mod);
11861188
1187 const dest_ty = self.air.typeOfIndex(inst);
1189 const dest_ty = self.typeOfIndex(inst);
11881190 const dest_info = dest_ty.intInfo(mod);
11891191
11901192 const result: MCValue = result: {
......@@ -1201,14 +1203,14 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
12011203
12021204 if (dest_info.bits > operand_info.bits) {
12031205 const dest_mcv = try self.allocRegOrMem(dest_ty, true, inst);
1204 try self.setRegOrMem(self.air.typeOfIndex(inst), dest_mcv, truncated);
1206 try self.setRegOrMem(self.typeOfIndex(inst), dest_mcv, truncated);
12051207 break :result dest_mcv;
12061208 } else {
12071209 if (self.reuseOperand(inst, operand, 0, truncated)) {
12081210 break :result truncated;
12091211 } else {
12101212 const dest_mcv = try self.allocRegOrMem(dest_ty, true, inst);
1211 try self.setRegOrMem(self.air.typeOfIndex(inst), dest_mcv, truncated);
1213 try self.setRegOrMem(self.typeOfIndex(inst), dest_mcv, truncated);
12121214 break :result dest_mcv;
12131215 }
12141216 }
......@@ -1303,8 +1305,8 @@ fn trunc(
13031305fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
13041306 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
13051307 const operand = try self.resolveInst(ty_op.operand);
1306 const operand_ty = self.air.typeOf(ty_op.operand);
1307 const dest_ty = self.air.typeOfIndex(inst);
1308 const operand_ty = self.typeOf(ty_op.operand);
1309 const dest_ty = self.typeOfIndex(inst);
13081310
13091311 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
13101312 break :blk try self.trunc(inst, operand, operand_ty, dest_ty);
......@@ -1325,7 +1327,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
13251327 const mod = self.bin_file.options.module.?;
13261328 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
13271329 const operand = try self.resolveInst(ty_op.operand);
1328 const operand_ty = self.air.typeOf(ty_op.operand);
1330 const operand_ty = self.typeOf(ty_op.operand);
13291331 switch (operand) {
13301332 .dead => unreachable,
13311333 .unreach => unreachable,
......@@ -1492,8 +1494,8 @@ fn minMax(
14921494fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
14931495 const tag = self.air.instructions.items(.tag)[inst];
14941496 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1495 const lhs_ty = self.air.typeOf(bin_op.lhs);
1496 const rhs_ty = self.air.typeOf(bin_op.rhs);
1497 const lhs_ty = self.typeOf(bin_op.lhs);
1498 const rhs_ty = self.typeOf(bin_op.rhs);
14971499
14981500 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
14991501 const lhs_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
......@@ -1512,9 +1514,9 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
15121514 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
15131515 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
15141516 const ptr = try self.resolveInst(bin_op.lhs);
1515 const ptr_ty = self.air.typeOf(bin_op.lhs);
1517 const ptr_ty = self.typeOf(bin_op.lhs);
15161518 const len = try self.resolveInst(bin_op.rhs);
1517 const len_ty = self.air.typeOf(bin_op.rhs);
1519 const len_ty = self.typeOf(bin_op.rhs);
15181520
15191521 const ptr_bits = self.target.ptrBitWidth();
15201522 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -2436,8 +2438,8 @@ fn ptrArithmetic(
24362438
24372439fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
24382440 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2439 const lhs_ty = self.air.typeOf(bin_op.lhs);
2440 const rhs_ty = self.air.typeOf(bin_op.rhs);
2441 const lhs_ty = self.typeOf(bin_op.lhs);
2442 const rhs_ty = self.typeOf(bin_op.rhs);
24412443
24422444 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
24432445 const lhs_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
......@@ -2487,8 +2489,8 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
24872489fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
24882490 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
24892491 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
2490 const lhs_ty = self.air.typeOf(bin_op.lhs);
2491 const rhs_ty = self.air.typeOf(bin_op.rhs);
2492 const lhs_ty = self.typeOf(bin_op.lhs);
2493 const rhs_ty = self.typeOf(bin_op.rhs);
24922494
24932495 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
24942496 const lhs_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
......@@ -2525,10 +2527,10 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
25252527 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
25262528 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
25272529 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
2528 const lhs_ty = self.air.typeOf(extra.lhs);
2529 const rhs_ty = self.air.typeOf(extra.rhs);
2530 const lhs_ty = self.typeOf(extra.lhs);
2531 const rhs_ty = self.typeOf(extra.rhs);
25302532
2531 const tuple_ty = self.air.typeOfIndex(inst);
2533 const tuple_ty = self.typeOfIndex(inst);
25322534 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));
25332535 const tuple_align = tuple_ty.abiAlignment(mod);
25342536 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));
......@@ -2653,10 +2655,10 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
26532655 const result: MCValue = result: {
26542656 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
26552657 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
2656 const lhs_ty = self.air.typeOf(extra.lhs);
2657 const rhs_ty = self.air.typeOf(extra.rhs);
2658 const lhs_ty = self.typeOf(extra.lhs);
2659 const rhs_ty = self.typeOf(extra.rhs);
26582660
2659 const tuple_ty = self.air.typeOfIndex(inst);
2661 const tuple_ty = self.typeOfIndex(inst);
26602662 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));
26612663 const tuple_align = tuple_ty.abiAlignment(mod);
26622664 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));
......@@ -2877,10 +2879,10 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
28772879 const result: MCValue = result: {
28782880 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
28792881 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
2880 const lhs_ty = self.air.typeOf(extra.lhs);
2881 const rhs_ty = self.air.typeOf(extra.rhs);
2882 const lhs_ty = self.typeOf(extra.lhs);
2883 const rhs_ty = self.typeOf(extra.rhs);
28822884
2883 const tuple_ty = self.air.typeOfIndex(inst);
2885 const tuple_ty = self.typeOfIndex(inst);
28842886 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));
28852887 const tuple_align = tuple_ty.abiAlignment(mod);
28862888 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));
......@@ -3013,7 +3015,7 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
30133015fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
30143016 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
30153017 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3016 const optional_ty = self.air.typeOf(ty_op.operand);
3018 const optional_ty = self.typeOf(ty_op.operand);
30173019 const mcv = try self.resolveInst(ty_op.operand);
30183020 break :result try self.optionalPayload(inst, mcv, optional_ty);
30193021 };
......@@ -3132,7 +3134,7 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
31323134 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
31333135 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
31343136 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
3135 const error_union_ty = self.air.typeOf(ty_op.operand);
3137 const error_union_ty = self.typeOf(ty_op.operand);
31363138
31373139 break :result try self.errUnionErr(error_union_bind, error_union_ty, inst);
31383140 };
......@@ -3212,7 +3214,7 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
32123214 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
32133215 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
32143216 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
3215 const error_union_ty = self.air.typeOf(ty_op.operand);
3217 const error_union_ty = self.typeOf(ty_op.operand);
32163218
32173219 break :result try self.errUnionPayload(error_union_bind, error_union_ty, inst);
32183220 };
......@@ -3266,12 +3268,12 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
32663268 }
32673269
32683270 const result: MCValue = result: {
3269 const payload_ty = self.air.typeOf(ty_op.operand);
3271 const payload_ty = self.typeOf(ty_op.operand);
32703272 if (!payload_ty.hasRuntimeBits(mod)) {
32713273 break :result MCValue{ .immediate = 1 };
32723274 }
32733275
3274 const optional_ty = self.air.typeOfIndex(inst);
3276 const optional_ty = self.typeOfIndex(inst);
32753277 const operand = try self.resolveInst(ty_op.operand);
32763278 const operand_lock: ?RegisterLock = switch (operand) {
32773279 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
......@@ -3433,7 +3435,7 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
34333435
34343436fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
34353437 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
3436 const slice_ty = self.air.typeOf(bin_op.lhs);
3438 const slice_ty = self.typeOf(bin_op.lhs);
34373439 const result: MCValue = if (!slice_ty.isVolatilePtr() and self.liveness.isUnused(inst)) .dead else result: {
34383440 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
34393441 const ptr_ty = slice_ty.slicePtrFieldType(&buf);
......@@ -3482,8 +3484,8 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
34823484 const base_bind: ReadArg.Bind = .{ .mcv = base_mcv };
34833485 const index_bind: ReadArg.Bind = .{ .inst = extra.rhs };
34843486
3485 const slice_ty = self.air.typeOf(extra.lhs);
3486 const index_ty = self.air.typeOf(extra.rhs);
3487 const slice_ty = self.typeOf(extra.lhs);
3488 const index_ty = self.typeOf(extra.rhs);
34873489
34883490 const addr = try self.ptrArithmetic(.ptr_add, base_bind, index_bind, slice_ty, index_ty, null);
34893491 break :result addr;
......@@ -3499,7 +3501,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
34993501
35003502fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
35013503 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
3502 const ptr_ty = self.air.typeOf(bin_op.lhs);
3504 const ptr_ty = self.typeOf(bin_op.lhs);
35033505 const result: MCValue = if (!ptr_ty.isVolatilePtr() and self.liveness.isUnused(inst)) .dead else result: {
35043506 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
35053507 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };
......@@ -3516,8 +3518,8 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
35163518 const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs };
35173519 const index_bind: ReadArg.Bind = .{ .inst = extra.rhs };
35183520
3519 const ptr_ty = self.air.typeOf(extra.lhs);
3520 const index_ty = self.air.typeOf(extra.rhs);
3521 const ptr_ty = self.typeOf(extra.lhs);
3522 const index_ty = self.typeOf(extra.rhs);
35213523
35223524 const addr = try self.ptrArithmetic(.ptr_add, ptr_bind, index_bind, ptr_ty, index_ty, null);
35233525 break :result addr;
......@@ -3862,16 +3864,16 @@ fn genInlineMemsetCode(
38623864}
38633865
38643866fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
3865 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
3866 const elem_ty = self.air.typeOfIndex(inst);
38673867 const mod = self.bin_file.options.module.?;
3868 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
3869 const elem_ty = self.typeOfIndex(inst);
38683870 const elem_size = elem_ty.abiSize(mod);
38693871 const result: MCValue = result: {
38703872 if (!elem_ty.hasRuntimeBits(mod))
38713873 break :result MCValue.none;
38723874
38733875 const ptr = try self.resolveInst(ty_op.operand);
3874 const is_volatile = self.air.typeOf(ty_op.operand).isVolatilePtr();
3876 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr();
38753877 if (self.liveness.isUnused(inst) and !is_volatile)
38763878 break :result MCValue.dead;
38773879
......@@ -3886,7 +3888,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
38863888 break :blk try self.allocRegOrMem(elem_ty, true, inst);
38873889 }
38883890 };
3889 try self.load(dst_mcv, ptr, self.air.typeOf(ty_op.operand));
3891 try self.load(dst_mcv, ptr, self.typeOf(ty_op.operand));
38903892 break :result dst_mcv;
38913893 };
38923894 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -4068,8 +4070,8 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
40684070 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
40694071 const ptr = try self.resolveInst(bin_op.lhs);
40704072 const value = try self.resolveInst(bin_op.rhs);
4071 const ptr_ty = self.air.typeOf(bin_op.lhs);
4072 const value_ty = self.air.typeOf(bin_op.rhs);
4073 const ptr_ty = self.typeOf(bin_op.lhs);
4074 const value_ty = self.typeOf(bin_op.rhs);
40734075
40744076 try self.store(ptr, value, ptr_ty, value_ty);
40754077
......@@ -4093,7 +4095,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
40934095 return if (self.liveness.isUnused(inst)) .dead else result: {
40944096 const mod = self.bin_file.options.module.?;
40954097 const mcv = try self.resolveInst(operand);
4096 const ptr_ty = self.air.typeOf(operand);
4098 const ptr_ty = self.typeOf(operand);
40974099 const struct_ty = ptr_ty.childType();
40984100 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));
40994101 switch (mcv) {
......@@ -4118,7 +4120,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
41184120 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
41194121 const mod = self.bin_file.options.module.?;
41204122 const mcv = try self.resolveInst(operand);
4121 const struct_ty = self.air.typeOf(operand);
4123 const struct_ty = self.typeOf(operand);
41224124 const struct_field_ty = struct_ty.structFieldType(index);
41234125 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));
41244126
......@@ -4194,7 +4196,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
41944196 while (self.args[arg_index] == .none) arg_index += 1;
41954197 self.arg_index = arg_index + 1;
41964198
4197 const ty = self.air.typeOfIndex(inst);
4199 const ty = self.typeOfIndex(inst);
41984200 const tag = self.air.instructions.items(.tag)[inst];
41994201 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;
42004202 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, src_index);
......@@ -4247,7 +4249,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42474249 const callee = pl_op.operand;
42484250 const extra = self.air.extraData(Air.Call, pl_op.payload);
42494251 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);
4250 const ty = self.air.typeOf(callee);
4252 const ty = self.typeOf(callee);
42514253 const mod = self.bin_file.options.module.?;
42524254
42534255 const fn_ty = switch (ty.zigTypeTag(mod)) {
......@@ -4294,7 +4296,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42944296
42954297 for (info.args, 0..) |mc_arg, arg_i| {
42964298 const arg = args[arg_i];
4297 const arg_ty = self.air.typeOf(arg);
4299 const arg_ty = self.typeOf(arg);
42984300 const arg_mcv = try self.resolveInst(args[arg_i]);
42994301
43004302 switch (mc_arg) {
......@@ -4470,7 +4472,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44704472fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44714473 const un_op = self.air.instructions.items(.data)[inst].un_op;
44724474 const ptr = try self.resolveInst(un_op);
4473 const ptr_ty = self.air.typeOf(un_op);
4475 const ptr_ty = self.typeOf(un_op);
44744476 const ret_ty = self.fn_type.fnReturnType();
44754477
44764478 switch (self.ret_mcv) {
......@@ -4512,7 +4514,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
45124514
45134515fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
45144516 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
4515 const lhs_ty = self.air.typeOf(bin_op.lhs);
4517 const lhs_ty = self.typeOf(bin_op.lhs);
45164518
45174519 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
45184520 break :blk try self.cmp(.{ .inst = bin_op.lhs }, .{ .inst = bin_op.rhs }, lhs_ty, op);
......@@ -4652,7 +4654,7 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
46524654 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
46534655 const operand = pl_op.operand;
46544656 const tag = self.air.instructions.items(.tag)[inst];
4655 const ty = self.air.typeOf(operand);
4657 const ty = self.typeOf(operand);
46564658 const mcv = try self.resolveInst(operand);
46574659 const name = self.air.nullTerminatedString(pl_op.payload);
46584660
......@@ -4804,7 +4806,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
48044806 log.debug("consolidating else_entry {d} {}=>{}", .{ else_key, else_value, canon_mcv });
48054807 // TODO make sure the destination stack offset / register does not already have something
48064808 // going on there.
4807 try self.setRegOrMem(self.air.typeOfIndex(else_key), canon_mcv, else_value);
4809 try self.setRegOrMem(self.typeOfIndex(else_key), canon_mcv, else_value);
48084810 // TODO track the new register / stack allocation
48094811 }
48104812 try parent_branch.inst_table.ensureUnusedCapacity(self.gpa, saved_then_branch.inst_table.count());
......@@ -4831,7 +4833,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
48314833 log.debug("consolidating then_entry {d} {}=>{}", .{ then_key, parent_mcv, then_value });
48324834 // TODO make sure the destination stack offset / register does not already have something
48334835 // going on there.
4834 try self.setRegOrMem(self.air.typeOfIndex(then_key), parent_mcv, then_value);
4836 try self.setRegOrMem(self.typeOfIndex(then_key), parent_mcv, then_value);
48354837 // TODO track the new register / stack allocation
48364838 }
48374839
......@@ -4936,7 +4938,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
49364938 const un_op = self.air.instructions.items(.data)[inst].un_op;
49374939 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49384940 const operand = try self.resolveInst(un_op);
4939 const operand_ty = self.air.typeOf(un_op);
4941 const operand_ty = self.typeOf(un_op);
49404942
49414943 break :result try self.isNull(.{ .mcv = operand }, operand_ty);
49424944 };
......@@ -4947,7 +4949,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
49474949 const un_op = self.air.instructions.items(.data)[inst].un_op;
49484950 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49494951 const operand_ptr = try self.resolveInst(un_op);
4950 const ptr_ty = self.air.typeOf(un_op);
4952 const ptr_ty = self.typeOf(un_op);
49514953 const elem_ty = ptr_ty.elemType();
49524954
49534955 const operand = try self.allocRegOrMem(elem_ty, true, null);
......@@ -4962,7 +4964,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
49624964 const un_op = self.air.instructions.items(.data)[inst].un_op;
49634965 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49644966 const operand = try self.resolveInst(un_op);
4965 const operand_ty = self.air.typeOf(un_op);
4967 const operand_ty = self.typeOf(un_op);
49664968
49674969 break :result try self.isNonNull(.{ .mcv = operand }, operand_ty);
49684970 };
......@@ -4973,7 +4975,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
49734975 const un_op = self.air.instructions.items(.data)[inst].un_op;
49744976 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49754977 const operand_ptr = try self.resolveInst(un_op);
4976 const ptr_ty = self.air.typeOf(un_op);
4978 const ptr_ty = self.typeOf(un_op);
49774979 const elem_ty = ptr_ty.elemType();
49784980
49794981 const operand = try self.allocRegOrMem(elem_ty, true, null);
......@@ -4988,7 +4990,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49884990 const un_op = self.air.instructions.items(.data)[inst].un_op;
49894991 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49904992 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
4991 const error_union_ty = self.air.typeOf(un_op);
4993 const error_union_ty = self.typeOf(un_op);
49924994
49934995 break :result try self.isErr(error_union_bind, error_union_ty);
49944996 };
......@@ -4999,7 +5001,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49995001 const un_op = self.air.instructions.items(.data)[inst].un_op;
50005002 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
50015003 const operand_ptr = try self.resolveInst(un_op);
5002 const ptr_ty = self.air.typeOf(un_op);
5004 const ptr_ty = self.typeOf(un_op);
50035005 const elem_ty = ptr_ty.elemType();
50045006
50055007 const operand = try self.allocRegOrMem(elem_ty, true, null);
......@@ -5014,7 +5016,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
50145016 const un_op = self.air.instructions.items(.data)[inst].un_op;
50155017 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
50165018 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
5017 const error_union_ty = self.air.typeOf(un_op);
5019 const error_union_ty = self.typeOf(un_op);
50185020
50195021 break :result try self.isNonErr(error_union_bind, error_union_ty);
50205022 };
......@@ -5025,7 +5027,7 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
50255027 const un_op = self.air.instructions.items(.data)[inst].un_op;
50265028 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
50275029 const operand_ptr = try self.resolveInst(un_op);
5028 const ptr_ty = self.air.typeOf(un_op);
5030 const ptr_ty = self.typeOf(un_op);
50295031 const elem_ty = ptr_ty.elemType();
50305032
50315033 const operand = try self.allocRegOrMem(elem_ty, true, null);
......@@ -5093,7 +5095,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
50935095
50945096fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
50955097 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
5096 const condition_ty = self.air.typeOf(pl_op.operand);
5098 const condition_ty = self.typeOf(pl_op.operand);
50975099 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
50985100 const liveness = try self.liveness.getSwitchBr(
50995101 self.gpa,
......@@ -5241,7 +5243,7 @@ fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
52415243 const mod = self.bin_file.options.module.?;
52425244 const block_data = self.blocks.getPtr(block).?;
52435245
5244 if (self.air.typeOf(operand).hasRuntimeBits(mod)) {
5246 if (self.typeOf(operand).hasRuntimeBits(mod)) {
52455247 const operand_mcv = try self.resolveInst(operand);
52465248 const block_mcv = block_data.mcv;
52475249 if (block_mcv == .none) {
......@@ -5249,14 +5251,14 @@ fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
52495251 .none, .dead, .unreach => unreachable,
52505252 .register, .stack_offset, .memory => operand_mcv,
52515253 .immediate, .stack_argument_offset, .compare_flags => blk: {
5252 const new_mcv = try self.allocRegOrMem(self.air.typeOfIndex(block), true, block);
5253 try self.setRegOrMem(self.air.typeOfIndex(block), new_mcv, operand_mcv);
5254 const new_mcv = try self.allocRegOrMem(self.typeOfIndex(block), true, block);
5255 try self.setRegOrMem(self.typeOfIndex(block), new_mcv, operand_mcv);
52545256 break :blk new_mcv;
52555257 },
52565258 else => return self.fail("TODO implement block_data.mcv = operand_mcv for {}", .{operand_mcv}),
52575259 };
52585260 } else {
5259 try self.setRegOrMem(self.air.typeOfIndex(block), block_mcv, operand_mcv);
5261 try self.setRegOrMem(self.typeOfIndex(block), block_mcv, operand_mcv);
52605262 }
52615263 }
52625264 return self.brVoid(block);
......@@ -5322,7 +5324,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
53225324
53235325 const arg_mcv = try self.resolveInst(input);
53245326 try self.register_manager.getReg(reg, null);
5325 try self.genSetReg(self.air.typeOf(input), reg, arg_mcv);
5327 try self.genSetReg(self.typeOf(input), reg, arg_mcv);
53265328 }
53275329
53285330 {
......@@ -5945,7 +5947,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59455947 };
59465948 defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);
59475949
5948 const dest_ty = self.air.typeOfIndex(inst);
5950 const dest_ty = self.typeOfIndex(inst);
59495951 const dest = try self.allocRegOrMem(dest_ty, true, inst);
59505952 try self.setRegOrMem(dest_ty, dest, operand);
59515953 break :result dest;
......@@ -5956,7 +5958,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59565958fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
59575959 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
59585960 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
5959 const ptr_ty = self.air.typeOf(ty_op.operand);
5961 const ptr_ty = self.typeOf(ty_op.operand);
59605962 const ptr = try self.resolveInst(ty_op.operand);
59615963 const array_ty = ptr_ty.childType();
59625964 const array_len = @intCast(u32, array_ty.arrayLen());
......@@ -6076,7 +6078,7 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
60766078}
60776079
60786080fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6079 const vector_ty = self.air.typeOfIndex(inst);
6081 const vector_ty = self.typeOfIndex(inst);
60806082 const len = vector_ty.vectorLen();
60816083 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
60826084 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
......@@ -6125,7 +6127,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
61256127 const body = self.air.extra[extra.end..][0..extra.data.body_len];
61266128 const result: MCValue = result: {
61276129 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
6128 const error_union_ty = self.air.typeOf(pl_op.operand);
6130 const error_union_ty = self.typeOf(pl_op.operand);
61296131 const error_union_size = @intCast(u32, error_union_ty.abiSize(mod));
61306132 const error_union_align = error_union_ty.abiAlignment(mod);
61316133
......@@ -6159,7 +6161,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
61596161 const mod = self.bin_file.options.module.?;
61606162
61616163 // If the type has no codegen bits, no need to store it.
6162 const inst_ty = self.air.typeOf(inst);
6164 const inst_ty = self.typeOf(inst);
61636165 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod))
61646166 return MCValue{ .none = {} };
61656167
......@@ -6428,3 +6430,13 @@ fn registerAlias(self: *Self, reg: Register, ty: Type) Register {
64286430 },
64296431 }
64306432}
6433
6434fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
6435 const mod = self.bin_file.options.module.?;
6436 return self.air.typeOf(inst, mod.intern_pool);
6437}
6438
6439fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
6440 const mod = self.bin_file.options.module.?;
6441 return self.air.typeOfIndex(inst, mod.intern_pool);
6442}
src/arch/arm/CodeGen.zig+89-77
......@@ -477,6 +477,7 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
477477}
478478
479479fn gen(self: *Self) !void {
480 const mod = self.bin_file.options.module.?;
480481 const cc = self.fn_type.fnCallingConvention();
481482 if (cc != .Naked) {
482483 // push {fp, lr}
......@@ -518,9 +519,8 @@ fn gen(self: *Self) !void {
518519 const inst = self.air.getMainBody()[arg_index];
519520 assert(self.air.instructions.items(.tag)[inst] == .arg);
520521
521 const ty = self.air.typeOfIndex(inst);
522 const ty = self.typeOfIndex(inst);
522523
523 const mod = self.bin_file.options.module.?;
524524 const abi_size = @intCast(u32, ty.abiSize(mod));
525525 const abi_align = ty.abiAlignment(mod);
526526 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
......@@ -637,13 +637,14 @@ fn gen(self: *Self) !void {
637637}
638638
639639fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
640 const mod = self.bin_file.options.module.?;
641 const ip = &mod.intern_pool;
640642 const air_tags = self.air.instructions.items(.tag);
641643
642644 for (body) |inst| {
643645 // TODO: remove now-redundant isUnused calls from AIR handler functions
644 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst)) {
646 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
645647 continue;
646 }
647648
648649 const old_air_bookkeeping = self.air_bookkeeping;
649650 try self.ensureProcessDeathCapacity(Liveness.bpi);
......@@ -829,6 +830,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
829830
830831 .constant => unreachable, // excluded from function bodies
831832 .const_ty => unreachable, // excluded from function bodies
833 .interned => unreachable, // excluded from function bodies
832834 .unreach => self.finishAirBookkeeping(),
833835
834836 .optional_payload => try self.airOptionalPayload(inst),
......@@ -1008,7 +1010,7 @@ fn allocMem(
10081010/// Use a pointer instruction as the basis for allocating stack memory.
10091011fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
10101012 const mod = self.bin_file.options.module.?;
1011 const elem_ty = self.air.typeOfIndex(inst).elemType();
1013 const elem_ty = self.typeOfIndex(inst).elemType();
10121014
10131015 if (!elem_ty.hasRuntimeBits(mod)) {
10141016 // As this stack item will never be dereferenced at runtime,
......@@ -1050,7 +1052,7 @@ fn allocRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool, maybe_inst: ?Air.Inst
10501052}
10511053
10521054pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void {
1053 const stack_mcv = try self.allocRegOrMem(self.air.typeOfIndex(inst), false, inst);
1055 const stack_mcv = try self.allocRegOrMem(self.typeOfIndex(inst), false, inst);
10541056 log.debug("spilling {} (%{d}) to stack mcv {any}", .{ reg, inst, stack_mcv });
10551057
10561058 const reg_mcv = self.getResolvedInstValue(inst);
......@@ -1064,14 +1066,14 @@ pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void
10641066
10651067 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
10661068 try branch.inst_table.put(self.gpa, inst, stack_mcv);
1067 try self.genSetStack(self.air.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv);
1069 try self.genSetStack(self.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv);
10681070}
10691071
10701072/// Save the current instruction stored in the compare flags if
10711073/// occupied
10721074fn spillCompareFlagsIfOccupied(self: *Self) !void {
10731075 if (self.cpsr_flags_inst) |inst_to_save| {
1074 const ty = self.air.typeOfIndex(inst_to_save);
1076 const ty = self.typeOfIndex(inst_to_save);
10751077 const mcv = self.getResolvedInstValue(inst_to_save);
10761078 const new_mcv = switch (mcv) {
10771079 .cpsr_flags => try self.allocRegOrMem(ty, true, inst_to_save),
......@@ -1081,7 +1083,7 @@ fn spillCompareFlagsIfOccupied(self: *Self) !void {
10811083 else => unreachable, // mcv doesn't occupy the compare flags
10821084 };
10831085
1084 try self.setRegOrMem(self.air.typeOfIndex(inst_to_save), new_mcv, mcv);
1086 try self.setRegOrMem(self.typeOfIndex(inst_to_save), new_mcv, mcv);
10851087 log.debug("spilling {d} to mcv {any}", .{ inst_to_save, new_mcv });
10861088
10871089 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
......@@ -1151,15 +1153,15 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
11511153}
11521154
11531155fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
1156 const mod = self.bin_file.options.module.?;
11541157 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
11551158 if (self.liveness.isUnused(inst))
11561159 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
11571160
11581161 const operand = try self.resolveInst(ty_op.operand);
1159 const operand_ty = self.air.typeOf(ty_op.operand);
1160 const dest_ty = self.air.typeOfIndex(inst);
1162 const operand_ty = self.typeOf(ty_op.operand);
1163 const dest_ty = self.typeOfIndex(inst);
11611164
1162 const mod = self.bin_file.options.module.?;
11631165 const operand_abi_size = operand_ty.abiSize(mod);
11641166 const dest_abi_size = dest_ty.abiSize(mod);
11651167 const info_a = operand_ty.intInfo(mod);
......@@ -1262,8 +1264,8 @@ fn trunc(
12621264fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
12631265 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
12641266 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
1265 const operand_ty = self.air.typeOf(ty_op.operand);
1266 const dest_ty = self.air.typeOfIndex(inst);
1267 const operand_ty = self.typeOf(ty_op.operand);
1268 const dest_ty = self.typeOfIndex(inst);
12671269
12681270 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
12691271 break :blk try self.trunc(inst, operand_bind, operand_ty, dest_ty);
......@@ -1284,7 +1286,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
12841286 const mod = self.bin_file.options.module.?;
12851287 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
12861288 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
1287 const operand_ty = self.air.typeOf(ty_op.operand);
1289 const operand_ty = self.typeOf(ty_op.operand);
12881290 switch (try operand_bind.resolveToMcv(self)) {
12891291 .dead => unreachable,
12901292 .unreach => unreachable,
......@@ -1467,8 +1469,8 @@ fn minMax(
14671469fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
14681470 const tag = self.air.instructions.items(.tag)[inst];
14691471 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1470 const lhs_ty = self.air.typeOf(bin_op.lhs);
1471 const rhs_ty = self.air.typeOf(bin_op.rhs);
1472 const lhs_ty = self.typeOf(bin_op.lhs);
1473 const rhs_ty = self.typeOf(bin_op.rhs);
14721474
14731475 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
14741476 const lhs_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
......@@ -1487,9 +1489,9 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
14871489 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
14881490 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
14891491 const ptr = try self.resolveInst(bin_op.lhs);
1490 const ptr_ty = self.air.typeOf(bin_op.lhs);
1492 const ptr_ty = self.typeOf(bin_op.lhs);
14911493 const len = try self.resolveInst(bin_op.rhs);
1492 const len_ty = self.air.typeOf(bin_op.rhs);
1494 const len_ty = self.typeOf(bin_op.rhs);
14931495
14941496 const stack_offset = try self.allocMem(8, 4, inst);
14951497 try self.genSetStack(ptr_ty, stack_offset, ptr);
......@@ -1501,8 +1503,8 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
15011503
15021504fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
15031505 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1504 const lhs_ty = self.air.typeOf(bin_op.lhs);
1505 const rhs_ty = self.air.typeOf(bin_op.rhs);
1506 const lhs_ty = self.typeOf(bin_op.lhs);
1507 const rhs_ty = self.typeOf(bin_op.rhs);
15061508
15071509 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
15081510 const lhs_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
......@@ -1552,8 +1554,8 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
15521554fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
15531555 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
15541556 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
1555 const lhs_ty = self.air.typeOf(bin_op.lhs);
1556 const rhs_ty = self.air.typeOf(bin_op.rhs);
1557 const lhs_ty = self.typeOf(bin_op.lhs);
1558 const rhs_ty = self.typeOf(bin_op.rhs);
15571559
15581560 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
15591561 const lhs_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
......@@ -1590,10 +1592,10 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
15901592 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
15911593 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
15921594 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
1593 const lhs_ty = self.air.typeOf(extra.lhs);
1594 const rhs_ty = self.air.typeOf(extra.rhs);
1595 const lhs_ty = self.typeOf(extra.lhs);
1596 const rhs_ty = self.typeOf(extra.rhs);
15951597
1596 const tuple_ty = self.air.typeOfIndex(inst);
1598 const tuple_ty = self.typeOfIndex(inst);
15971599 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));
15981600 const tuple_align = tuple_ty.abiAlignment(mod);
15991601 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));
......@@ -1703,10 +1705,10 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
17031705 const result: MCValue = result: {
17041706 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
17051707 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
1706 const lhs_ty = self.air.typeOf(extra.lhs);
1707 const rhs_ty = self.air.typeOf(extra.rhs);
1708 const lhs_ty = self.typeOf(extra.lhs);
1709 const rhs_ty = self.typeOf(extra.rhs);
17081710
1709 const tuple_ty = self.air.typeOfIndex(inst);
1711 const tuple_ty = self.typeOfIndex(inst);
17101712 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));
17111713 const tuple_align = tuple_ty.abiAlignment(mod);
17121714 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));
......@@ -1865,10 +1867,10 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
18651867 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
18661868 const mod = self.bin_file.options.module.?;
18671869 const result: MCValue = result: {
1868 const lhs_ty = self.air.typeOf(extra.lhs);
1869 const rhs_ty = self.air.typeOf(extra.rhs);
1870 const lhs_ty = self.typeOf(extra.lhs);
1871 const rhs_ty = self.typeOf(extra.rhs);
18701872
1871 const tuple_ty = self.air.typeOfIndex(inst);
1873 const tuple_ty = self.typeOfIndex(inst);
18721874 const tuple_size = @intCast(u32, tuple_ty.abiSize(mod));
18731875 const tuple_align = tuple_ty.abiAlignment(mod);
18741876 const overflow_bit_offset = @intCast(u32, tuple_ty.structFieldOffset(1, mod));
......@@ -2019,10 +2021,10 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
20192021}
20202022
20212023fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
2024 const mod = self.bin_file.options.module.?;
20222025 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
20232026 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2024 const optional_ty = self.air.typeOfIndex(inst);
2025 const mod = self.bin_file.options.module.?;
2027 const optional_ty = self.typeOfIndex(inst);
20262028 const abi_size = @intCast(u32, optional_ty.abiSize(mod));
20272029
20282030 // Optional with a zero-bit payload type is just a boolean true
......@@ -2105,7 +2107,7 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
21052107 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
21062108 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
21072109 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
2108 const error_union_ty = self.air.typeOf(ty_op.operand);
2110 const error_union_ty = self.typeOf(ty_op.operand);
21092111
21102112 break :result try self.errUnionErr(error_union_bind, error_union_ty, inst);
21112113 };
......@@ -2182,7 +2184,7 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
21822184 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
21832185 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
21842186 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
2185 const error_union_ty = self.air.typeOf(ty_op.operand);
2187 const error_union_ty = self.typeOf(ty_op.operand);
21862188
21872189 break :result try self.errUnionPayload(error_union_bind, error_union_ty, inst);
21882190 };
......@@ -2430,7 +2432,7 @@ fn ptrElemVal(
24302432
24312433fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24322434 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2433 const slice_ty = self.air.typeOf(bin_op.lhs);
2435 const slice_ty = self.typeOf(bin_op.lhs);
24342436 const result: MCValue = if (!slice_ty.isVolatilePtr() and self.liveness.isUnused(inst)) .dead else result: {
24352437 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
24362438 const ptr_ty = slice_ty.slicePtrFieldType(&buf);
......@@ -2456,8 +2458,8 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
24562458 const base_bind: ReadArg.Bind = .{ .mcv = base_mcv };
24572459 const index_bind: ReadArg.Bind = .{ .inst = extra.rhs };
24582460
2459 const slice_ty = self.air.typeOf(extra.lhs);
2460 const index_ty = self.air.typeOf(extra.rhs);
2461 const slice_ty = self.typeOf(extra.lhs);
2462 const index_ty = self.typeOf(extra.rhs);
24612463
24622464 const addr = try self.ptrArithmetic(.ptr_add, base_bind, index_bind, slice_ty, index_ty, null);
24632465 break :result addr;
......@@ -2523,7 +2525,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
25232525 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
25242526 const array_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
25252527 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };
2526 const array_ty = self.air.typeOf(bin_op.lhs);
2528 const array_ty = self.typeOf(bin_op.lhs);
25272529
25282530 break :result try self.arrayElemVal(array_bind, index_bind, array_ty, inst);
25292531 };
......@@ -2532,7 +2534,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
25322534
25332535fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
25342536 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2535 const ptr_ty = self.air.typeOf(bin_op.lhs);
2537 const ptr_ty = self.typeOf(bin_op.lhs);
25362538 const result: MCValue = if (!ptr_ty.isVolatilePtr() and self.liveness.isUnused(inst)) .dead else result: {
25372539 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
25382540 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };
......@@ -2549,8 +2551,8 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
25492551 const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs };
25502552 const index_bind: ReadArg.Bind = .{ .inst = extra.rhs };
25512553
2552 const ptr_ty = self.air.typeOf(extra.lhs);
2553 const index_ty = self.air.typeOf(extra.rhs);
2554 const ptr_ty = self.typeOf(extra.lhs);
2555 const index_ty = self.typeOf(extra.rhs);
25542556
25552557 const addr = try self.ptrArithmetic(.ptr_add, ptr_bind, index_bind, ptr_ty, index_ty, null);
25562558 break :result addr;
......@@ -2736,13 +2738,13 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
27362738fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27372739 const mod = self.bin_file.options.module.?;
27382740 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2739 const elem_ty = self.air.typeOfIndex(inst);
2741 const elem_ty = self.typeOfIndex(inst);
27402742 const result: MCValue = result: {
27412743 if (!elem_ty.hasRuntimeBits(mod))
27422744 break :result MCValue.none;
27432745
27442746 const ptr = try self.resolveInst(ty_op.operand);
2745 const is_volatile = self.air.typeOf(ty_op.operand).isVolatilePtr();
2747 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr();
27462748 if (self.liveness.isUnused(inst) and !is_volatile)
27472749 break :result MCValue.dead;
27482750
......@@ -2755,7 +2757,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27552757 break :blk try self.allocRegOrMem(elem_ty, true, inst);
27562758 }
27572759 };
2758 try self.load(dest_mcv, ptr, self.air.typeOf(ty_op.operand));
2760 try self.load(dest_mcv, ptr, self.typeOf(ty_op.operand));
27592761
27602762 break :result dest_mcv;
27612763 };
......@@ -2860,8 +2862,8 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
28602862 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
28612863 const ptr = try self.resolveInst(bin_op.lhs);
28622864 const value = try self.resolveInst(bin_op.rhs);
2863 const ptr_ty = self.air.typeOf(bin_op.lhs);
2864 const value_ty = self.air.typeOf(bin_op.rhs);
2865 const ptr_ty = self.typeOf(bin_op.lhs);
2866 const value_ty = self.typeOf(bin_op.rhs);
28652867
28662868 try self.store(ptr, value, ptr_ty, value_ty);
28672869
......@@ -2885,7 +2887,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
28852887 return if (self.liveness.isUnused(inst)) .dead else result: {
28862888 const mod = self.bin_file.options.module.?;
28872889 const mcv = try self.resolveInst(operand);
2888 const ptr_ty = self.air.typeOf(operand);
2890 const ptr_ty = self.typeOf(operand);
28892891 const struct_ty = ptr_ty.childType();
28902892 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));
28912893 switch (mcv) {
......@@ -2910,7 +2912,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
29102912 const mod = self.bin_file.options.module.?;
29112913 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
29122914 const mcv = try self.resolveInst(operand);
2913 const struct_ty = self.air.typeOf(operand);
2915 const struct_ty = self.typeOf(operand);
29142916 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));
29152917 const struct_field_ty = struct_ty.structFieldType(index);
29162918
......@@ -4169,7 +4171,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
41694171 while (self.args[arg_index] == .none) arg_index += 1;
41704172 self.arg_index = arg_index + 1;
41714173
4172 const ty = self.air.typeOfIndex(inst);
4174 const ty = self.typeOfIndex(inst);
41734175 const tag = self.air.instructions.items(.tag)[inst];
41744176 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;
41754177 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, src_index);
......@@ -4222,7 +4224,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42224224 const callee = pl_op.operand;
42234225 const extra = self.air.extraData(Air.Call, pl_op.payload);
42244226 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);
4225 const ty = self.air.typeOf(callee);
4227 const ty = self.typeOf(callee);
42264228 const mod = self.bin_file.options.module.?;
42274229
42284230 const fn_ty = switch (ty.zigTypeTag(mod)) {
......@@ -4276,7 +4278,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42764278
42774279 for (info.args, 0..) |mc_arg, arg_i| {
42784280 const arg = args[arg_i];
4279 const arg_ty = self.air.typeOf(arg);
4281 const arg_ty = self.typeOf(arg);
42804282 const arg_mcv = try self.resolveInst(args[arg_i]);
42814283
42824284 switch (mc_arg) {
......@@ -4418,7 +4420,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44184420fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44194421 const un_op = self.air.instructions.items(.data)[inst].un_op;
44204422 const ptr = try self.resolveInst(un_op);
4421 const ptr_ty = self.air.typeOf(un_op);
4423 const ptr_ty = self.typeOf(un_op);
44224424 const ret_ty = self.fn_type.fnReturnType();
44234425
44244426 switch (self.ret_mcv) {
......@@ -4461,7 +4463,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44614463
44624464fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
44634465 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
4464 const lhs_ty = self.air.typeOf(bin_op.lhs);
4466 const lhs_ty = self.typeOf(bin_op.lhs);
44654467
44664468 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
44674469 break :blk try self.cmp(.{ .inst = bin_op.lhs }, .{ .inst = bin_op.rhs }, lhs_ty, op);
......@@ -4600,7 +4602,7 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
46004602 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
46014603 const operand = pl_op.operand;
46024604 const tag = self.air.instructions.items(.tag)[inst];
4603 const ty = self.air.typeOf(operand);
4605 const ty = self.typeOf(operand);
46044606 const mcv = try self.resolveInst(operand);
46054607 const name = self.air.nullTerminatedString(pl_op.payload);
46064608
......@@ -4755,7 +4757,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
47554757 log.debug("consolidating else_entry {d} {}=>{}", .{ else_key, else_value, canon_mcv });
47564758 // TODO make sure the destination stack offset / register does not already have something
47574759 // going on there.
4758 try self.setRegOrMem(self.air.typeOfIndex(else_key), canon_mcv, else_value);
4760 try self.setRegOrMem(self.typeOfIndex(else_key), canon_mcv, else_value);
47594761 // TODO track the new register / stack allocation
47604762 }
47614763 try parent_branch.inst_table.ensureUnusedCapacity(self.gpa, saved_then_branch.inst_table.count());
......@@ -4782,7 +4784,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
47824784 log.debug("consolidating then_entry {d} {}=>{}", .{ then_key, parent_mcv, then_value });
47834785 // TODO make sure the destination stack offset / register does not already have something
47844786 // going on there.
4785 try self.setRegOrMem(self.air.typeOfIndex(then_key), parent_mcv, then_value);
4787 try self.setRegOrMem(self.typeOfIndex(then_key), parent_mcv, then_value);
47864788 // TODO track the new register / stack allocation
47874789 }
47884790
......@@ -4827,7 +4829,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
48274829 const un_op = self.air.instructions.items(.data)[inst].un_op;
48284830 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48294831 const operand_bind: ReadArg.Bind = .{ .inst = un_op };
4830 const operand_ty = self.air.typeOf(un_op);
4832 const operand_ty = self.typeOf(un_op);
48314833
48324834 break :result try self.isNull(operand_bind, operand_ty);
48334835 };
......@@ -4838,7 +4840,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
48384840 const un_op = self.air.instructions.items(.data)[inst].un_op;
48394841 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48404842 const operand_ptr = try self.resolveInst(un_op);
4841 const ptr_ty = self.air.typeOf(un_op);
4843 const ptr_ty = self.typeOf(un_op);
48424844 const elem_ty = ptr_ty.elemType();
48434845
48444846 const operand = try self.allocRegOrMem(elem_ty, true, null);
......@@ -4853,7 +4855,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
48534855 const un_op = self.air.instructions.items(.data)[inst].un_op;
48544856 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48554857 const operand_bind: ReadArg.Bind = .{ .inst = un_op };
4856 const operand_ty = self.air.typeOf(un_op);
4858 const operand_ty = self.typeOf(un_op);
48574859
48584860 break :result try self.isNonNull(operand_bind, operand_ty);
48594861 };
......@@ -4864,7 +4866,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
48644866 const un_op = self.air.instructions.items(.data)[inst].un_op;
48654867 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48664868 const operand_ptr = try self.resolveInst(un_op);
4867 const ptr_ty = self.air.typeOf(un_op);
4869 const ptr_ty = self.typeOf(un_op);
48684870 const elem_ty = ptr_ty.elemType();
48694871
48704872 const operand = try self.allocRegOrMem(elem_ty, true, null);
......@@ -4913,7 +4915,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49134915 const un_op = self.air.instructions.items(.data)[inst].un_op;
49144916 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49154917 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
4916 const error_union_ty = self.air.typeOf(un_op);
4918 const error_union_ty = self.typeOf(un_op);
49174919
49184920 break :result try self.isErr(error_union_bind, error_union_ty);
49194921 };
......@@ -4924,7 +4926,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49244926 const un_op = self.air.instructions.items(.data)[inst].un_op;
49254927 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49264928 const operand_ptr = try self.resolveInst(un_op);
4927 const ptr_ty = self.air.typeOf(un_op);
4929 const ptr_ty = self.typeOf(un_op);
49284930 const elem_ty = ptr_ty.elemType();
49294931
49304932 const operand = try self.allocRegOrMem(elem_ty, true, null);
......@@ -4939,7 +4941,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
49394941 const un_op = self.air.instructions.items(.data)[inst].un_op;
49404942 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49414943 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
4942 const error_union_ty = self.air.typeOf(un_op);
4944 const error_union_ty = self.typeOf(un_op);
49434945
49444946 break :result try self.isNonErr(error_union_bind, error_union_ty);
49454947 };
......@@ -4950,7 +4952,7 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49504952 const un_op = self.air.instructions.items(.data)[inst].un_op;
49514953 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49524954 const operand_ptr = try self.resolveInst(un_op);
4953 const ptr_ty = self.air.typeOf(un_op);
4955 const ptr_ty = self.typeOf(un_op);
49544956 const elem_ty = ptr_ty.elemType();
49554957
49564958 const operand = try self.allocRegOrMem(elem_ty, true, null);
......@@ -5018,7 +5020,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
50185020
50195021fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
50205022 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
5021 const condition_ty = self.air.typeOf(pl_op.operand);
5023 const condition_ty = self.typeOf(pl_op.operand);
50225024 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
50235025 const liveness = try self.liveness.getSwitchBr(
50245026 self.gpa,
......@@ -5164,7 +5166,7 @@ fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
51645166 const mod = self.bin_file.options.module.?;
51655167 const block_data = self.blocks.getPtr(block).?;
51665168
5167 if (self.air.typeOf(operand).hasRuntimeBits(mod)) {
5169 if (self.typeOf(operand).hasRuntimeBits(mod)) {
51685170 const operand_mcv = try self.resolveInst(operand);
51695171 const block_mcv = block_data.mcv;
51705172 if (block_mcv == .none) {
......@@ -5172,14 +5174,14 @@ fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
51725174 .none, .dead, .unreach => unreachable,
51735175 .register, .stack_offset, .memory => operand_mcv,
51745176 .immediate, .stack_argument_offset, .cpsr_flags => blk: {
5175 const new_mcv = try self.allocRegOrMem(self.air.typeOfIndex(block), true, block);
5176 try self.setRegOrMem(self.air.typeOfIndex(block), new_mcv, operand_mcv);
5177 const new_mcv = try self.allocRegOrMem(self.typeOfIndex(block), true, block);
5178 try self.setRegOrMem(self.typeOfIndex(block), new_mcv, operand_mcv);
51775179 break :blk new_mcv;
51785180 },
51795181 else => return self.fail("TODO implement block_data.mcv = operand_mcv for {}", .{operand_mcv}),
51805182 };
51815183 } else {
5182 try self.setRegOrMem(self.air.typeOfIndex(block), block_mcv, operand_mcv);
5184 try self.setRegOrMem(self.typeOfIndex(block), block_mcv, operand_mcv);
51835185 }
51845186 }
51855187 return self.brVoid(block);
......@@ -5243,7 +5245,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
52435245
52445246 const arg_mcv = try self.resolveInst(input);
52455247 try self.register_manager.getReg(reg, null);
5246 try self.genSetReg(self.air.typeOf(input), reg, arg_mcv);
5248 try self.genSetReg(self.typeOf(input), reg, arg_mcv);
52475249 }
52485250
52495251 {
......@@ -5896,7 +5898,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
58965898 };
58975899 defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);
58985900
5899 const dest_ty = self.air.typeOfIndex(inst);
5901 const dest_ty = self.typeOfIndex(inst);
59005902 const dest = try self.allocRegOrMem(dest_ty, true, inst);
59015903 try self.setRegOrMem(dest_ty, dest, operand);
59025904 break :result dest;
......@@ -5907,7 +5909,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59075909fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
59085910 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
59095911 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
5910 const ptr_ty = self.air.typeOf(ty_op.operand);
5912 const ptr_ty = self.typeOf(ty_op.operand);
59115913 const ptr = try self.resolveInst(ty_op.operand);
59125914 const array_ty = ptr_ty.childType();
59135915 const array_len = @intCast(u32, array_ty.arrayLen());
......@@ -6023,7 +6025,7 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
60236025}
60246026
60256027fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6026 const vector_ty = self.air.typeOfIndex(inst);
6028 const vector_ty = self.typeOfIndex(inst);
60276029 const len = vector_ty.vectorLen();
60286030 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
60296031 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
......@@ -6072,7 +6074,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
60726074 const body = self.air.extra[extra.end..][0..extra.data.body_len];
60736075 const result: MCValue = result: {
60746076 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
6075 const error_union_ty = self.air.typeOf(pl_op.operand);
6077 const error_union_ty = self.typeOf(pl_op.operand);
60766078 const mod = self.bin_file.options.module.?;
60776079 const error_union_size = @intCast(u32, error_union_ty.abiSize(mod));
60786080 const error_union_align = error_union_ty.abiAlignment(mod);
......@@ -6107,7 +6109,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
61076109 const mod = self.bin_file.options.module.?;
61086110
61096111 // If the type has no codegen bits, no need to store it.
6110 const inst_ty = self.air.typeOf(inst);
6112 const inst_ty = self.typeOf(inst);
61116113 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod))
61126114 return MCValue{ .none = {} };
61136115
......@@ -6333,3 +6335,13 @@ fn parseRegName(name: []const u8) ?Register {
63336335 }
63346336 return std.meta.stringToEnum(Register, name);
63356337}
6338
6339fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
6340 const mod = self.bin_file.options.module.?;
6341 return self.air.typeOf(inst, mod.intern_pool);
6342}
6343
6344fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
6345 const mod = self.bin_file.options.module.?;
6346 return self.air.typeOfIndex(inst, mod.intern_pool);
6347}
src/arch/riscv64/CodeGen.zig+46-34
......@@ -470,13 +470,14 @@ fn gen(self: *Self) !void {
470470}
471471
472472fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
473 const mod = self.bin_file.options.module.?;
474 const ip = &mod.intern_pool;
473475 const air_tags = self.air.instructions.items(.tag);
474476
475477 for (body) |inst| {
476478 // TODO: remove now-redundant isUnused calls from AIR handler functions
477 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst)) {
479 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
478480 continue;
479 }
480481
481482 const old_air_bookkeeping = self.air_bookkeeping;
482483 try self.ensureProcessDeathCapacity(Liveness.bpi);
......@@ -658,6 +659,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
658659
659660 .constant => unreachable, // excluded from function bodies
660661 .const_ty => unreachable, // excluded from function bodies
662 .interned => unreachable, // excluded from function bodies
661663 .unreach => self.finishAirBookkeeping(),
662664
663665 .optional_payload => try self.airOptionalPayload(inst),
......@@ -804,8 +806,8 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u
804806
805807/// Use a pointer instruction as the basis for allocating stack memory.
806808fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
807 const elem_ty = self.air.typeOfIndex(inst).elemType();
808809 const mod = self.bin_file.options.module.?;
810 const elem_ty = self.typeOfIndex(inst).elemType();
809811 const abi_size = math.cast(u32, elem_ty.abiSize(mod)) orelse {
810812 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(mod)});
811813 };
......@@ -815,8 +817,8 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
815817}
816818
817819fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {
818 const elem_ty = self.air.typeOfIndex(inst);
819820 const mod = self.bin_file.options.module.?;
821 const elem_ty = self.typeOfIndex(inst);
820822 const abi_size = math.cast(u32, elem_ty.abiSize(mod)) orelse {
821823 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(mod)});
822824 };
......@@ -845,7 +847,7 @@ pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void
845847 assert(reg == reg_mcv.register);
846848 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
847849 try branch.inst_table.put(self.gpa, inst, stack_mcv);
848 try self.genSetStack(self.air.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv);
850 try self.genSetStack(self.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv);
849851}
850852
851853/// Copies a value to a register without tracking the register. The register is not considered
......@@ -862,7 +864,7 @@ fn copyToTmpRegister(self: *Self, ty: Type, mcv: MCValue) !Register {
862864/// This can have a side effect of spilling instructions to the stack to free up a register.
863865fn copyToNewRegister(self: *Self, reg_owner: Air.Inst.Index, mcv: MCValue) !MCValue {
864866 const reg = try self.register_manager.allocReg(reg_owner, gp);
865 try self.genSetReg(self.air.typeOfIndex(reg_owner), reg, mcv);
867 try self.genSetReg(self.typeOfIndex(reg_owner), reg, mcv);
866868 return MCValue{ .register = reg };
867869}
868870
......@@ -894,10 +896,10 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
894896 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
895897
896898 const mod = self.bin_file.options.module.?;
897 const operand_ty = self.air.typeOf(ty_op.operand);
899 const operand_ty = self.typeOf(ty_op.operand);
898900 const operand = try self.resolveInst(ty_op.operand);
899901 const info_a = operand_ty.intInfo(mod);
900 const info_b = self.air.typeOfIndex(inst).intInfo(mod);
902 const info_b = self.typeOfIndex(inst).intInfo(mod);
901903 if (info_a.signedness != info_b.signedness)
902904 return self.fail("TODO gen intcast sign safety in semantic analysis", .{});
903905
......@@ -1126,8 +1128,8 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
11261128 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
11271129 const lhs = try self.resolveInst(bin_op.lhs);
11281130 const rhs = try self.resolveInst(bin_op.rhs);
1129 const lhs_ty = self.air.typeOf(bin_op.lhs);
1130 const rhs_ty = self.air.typeOf(bin_op.rhs);
1131 const lhs_ty = self.typeOf(bin_op.lhs);
1132 const rhs_ty = self.typeOf(bin_op.rhs);
11311133
11321134 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else try self.binOp(tag, inst, lhs, rhs, lhs_ty, rhs_ty);
11331135 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
......@@ -1138,8 +1140,8 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void
11381140 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
11391141 const lhs = try self.resolveInst(bin_op.lhs);
11401142 const rhs = try self.resolveInst(bin_op.rhs);
1141 const lhs_ty = self.air.typeOf(bin_op.lhs);
1142 const rhs_ty = self.air.typeOf(bin_op.rhs);
1143 const lhs_ty = self.typeOf(bin_op.lhs);
1144 const rhs_ty = self.typeOf(bin_op.rhs);
11431145
11441146 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else try self.binOp(tag, inst, lhs, rhs, lhs_ty, rhs_ty);
11451147 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
......@@ -1333,7 +1335,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
13331335 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
13341336 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
13351337 const mod = self.bin_file.options.module.?;
1336 const optional_ty = self.air.typeOfIndex(inst);
1338 const optional_ty = self.typeOfIndex(inst);
13371339
13381340 // Optional with a zero-bit payload type is just a boolean true
13391341 if (optional_ty.abiSize(mod) == 1)
......@@ -1525,15 +1527,15 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
15251527}
15261528
15271529fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
1530 const mod = self.bin_file.options.module.?;
15281531 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1529 const elem_ty = self.air.typeOfIndex(inst);
1532 const elem_ty = self.typeOfIndex(inst);
15301533 const result: MCValue = result: {
1531 const mod = self.bin_file.options.module.?;
15321534 if (!elem_ty.hasRuntimeBits(mod))
15331535 break :result MCValue.none;
15341536
15351537 const ptr = try self.resolveInst(ty_op.operand);
1536 const is_volatile = self.air.typeOf(ty_op.operand).isVolatilePtr();
1538 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr();
15371539 if (self.liveness.isUnused(inst) and !is_volatile)
15381540 break :result MCValue.dead;
15391541
......@@ -1545,7 +1547,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
15451547 break :blk try self.allocRegOrMem(inst, true);
15461548 }
15471549 };
1548 try self.load(dst_mcv, ptr, self.air.typeOf(ty_op.operand));
1550 try self.load(dst_mcv, ptr, self.typeOf(ty_op.operand));
15491551 break :result dst_mcv;
15501552 };
15511553 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -1586,8 +1588,8 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
15861588 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
15871589 const ptr = try self.resolveInst(bin_op.lhs);
15881590 const value = try self.resolveInst(bin_op.rhs);
1589 const ptr_ty = self.air.typeOf(bin_op.lhs);
1590 const value_ty = self.air.typeOf(bin_op.rhs);
1591 const ptr_ty = self.typeOf(bin_op.lhs);
1592 const value_ty = self.typeOf(bin_op.rhs);
15911593
15921594 try self.store(ptr, value, ptr_ty, value_ty);
15931595
......@@ -1647,7 +1649,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
16471649 const arg_index = self.arg_index;
16481650 self.arg_index += 1;
16491651
1650 const ty = self.air.typeOfIndex(inst);
1652 const ty = self.typeOfIndex(inst);
16511653 _ = ty;
16521654
16531655 const result = self.args[arg_index];
......@@ -1704,7 +1706,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
17041706 const mod = self.bin_file.options.module.?;
17051707 if (modifier == .always_tail) return self.fail("TODO implement tail calls for riscv64", .{});
17061708 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
1707 const fn_ty = self.air.typeOf(pl_op.operand);
1709 const fn_ty = self.typeOf(pl_op.operand);
17081710 const callee = pl_op.operand;
17091711 const extra = self.air.extraData(Air.Call, pl_op.payload);
17101712 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);
......@@ -1717,7 +1719,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
17171719 if (self.bin_file.cast(link.File.Elf)) |elf_file| {
17181720 for (info.args, 0..) |mc_arg, arg_i| {
17191721 const arg = args[arg_i];
1720 const arg_ty = self.air.typeOf(arg);
1722 const arg_ty = self.typeOf(arg);
17211723 const arg_mcv = try self.resolveInst(args[arg_i]);
17221724
17231725 switch (mc_arg) {
......@@ -1829,9 +1831,9 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
18291831 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
18301832 if (self.liveness.isUnused(inst))
18311833 return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
1832 const ty = self.air.typeOf(bin_op.lhs);
1834 const ty = self.typeOf(bin_op.lhs);
18331835 const mod = self.bin_file.options.module.?;
1834 assert(ty.eql(self.air.typeOf(bin_op.rhs), mod));
1836 assert(ty.eql(self.typeOf(bin_op.rhs), mod));
18351837 if (ty.zigTypeTag(mod) == .ErrorSet)
18361838 return self.fail("TODO implement cmp for errors", .{});
18371839
......@@ -1950,7 +1952,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
19501952 break :blk try self.allocRegOrMem(inst, true);
19511953 }
19521954 };
1953 try self.load(operand, operand_ptr, self.air.typeOf(un_op));
1955 try self.load(operand, operand_ptr, self.typeOf(un_op));
19541956 break :result try self.isNull(operand);
19551957 };
19561958 return self.finishAir(inst, result, .{ un_op, .none, .none });
......@@ -1977,7 +1979,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
19771979 break :blk try self.allocRegOrMem(inst, true);
19781980 }
19791981 };
1980 try self.load(operand, operand_ptr, self.air.typeOf(un_op));
1982 try self.load(operand, operand_ptr, self.typeOf(un_op));
19811983 break :result try self.isNonNull(operand);
19821984 };
19831985 return self.finishAir(inst, result, .{ un_op, .none, .none });
......@@ -2004,7 +2006,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
20042006 break :blk try self.allocRegOrMem(inst, true);
20052007 }
20062008 };
2007 try self.load(operand, operand_ptr, self.air.typeOf(un_op));
2009 try self.load(operand, operand_ptr, self.typeOf(un_op));
20082010 break :result try self.isErr(operand);
20092011 };
20102012 return self.finishAir(inst, result, .{ un_op, .none, .none });
......@@ -2031,7 +2033,7 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
20312033 break :blk try self.allocRegOrMem(inst, true);
20322034 }
20332035 };
2034 try self.load(operand, operand_ptr, self.air.typeOf(un_op));
2036 try self.load(operand, operand_ptr, self.typeOf(un_op));
20352037 break :result try self.isNonErr(operand);
20362038 };
20372039 return self.finishAir(inst, result, .{ un_op, .none, .none });
......@@ -2112,13 +2114,13 @@ fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
21122114 const block_data = self.blocks.getPtr(block).?;
21132115
21142116 const mod = self.bin_file.options.module.?;
2115 if (self.air.typeOf(operand).hasRuntimeBits(mod)) {
2117 if (self.typeOf(operand).hasRuntimeBits(mod)) {
21162118 const operand_mcv = try self.resolveInst(operand);
21172119 const block_mcv = block_data.mcv;
21182120 if (block_mcv == .none) {
21192121 block_data.mcv = operand_mcv;
21202122 } else {
2121 try self.setRegOrMem(self.air.typeOfIndex(block), block_mcv, operand_mcv);
2123 try self.setRegOrMem(self.typeOfIndex(block), block_mcv, operand_mcv);
21222124 }
21232125 }
21242126 return self.brVoid(block);
......@@ -2181,7 +2183,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
21812183
21822184 const arg_mcv = try self.resolveInst(input);
21832185 try self.register_manager.getReg(reg, null);
2184 try self.genSetReg(self.air.typeOf(input), reg, arg_mcv);
2186 try self.genSetReg(self.typeOf(input), reg, arg_mcv);
21852187 }
21862188
21872189 {
......@@ -2377,7 +2379,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
23772379 defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);
23782380
23792381 const dest = try self.allocRegOrMem(inst, true);
2380 try self.setRegOrMem(self.air.typeOfIndex(inst), dest, operand);
2382 try self.setRegOrMem(self.typeOfIndex(inst), dest, operand);
23812383 break :result dest;
23822384 };
23832385 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -2494,7 +2496,7 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
24942496}
24952497
24962498fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
2497 const vector_ty = self.air.typeOfIndex(inst);
2499 const vector_ty = self.typeOfIndex(inst);
24982500 const len = vector_ty.vectorLen();
24992501 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
25002502 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
......@@ -2541,7 +2543,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
25412543 const mod = self.bin_file.options.module.?;
25422544
25432545 // If the type has no codegen bits, no need to store it.
2544 const inst_ty = self.air.typeOf(inst);
2546 const inst_ty = self.typeOf(inst);
25452547 if (!inst_ty.hasRuntimeBits(mod))
25462548 return MCValue{ .none = {} };
25472549
......@@ -2733,3 +2735,13 @@ fn parseRegName(name: []const u8) ?Register {
27332735 }
27342736 return std.meta.stringToEnum(Register, name);
27352737}
2738
2739fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
2740 const mod = self.bin_file.options.module.?;
2741 return self.air.typeOf(inst, mod.intern_pool);
2742}
2743
2744fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
2745 const mod = self.bin_file.options.module.?;
2746 return self.air.typeOfIndex(inst, mod.intern_pool);
2747}
src/arch/sparc64/CodeGen.zig+74-62
......@@ -490,13 +490,14 @@ fn gen(self: *Self) !void {
490490}
491491
492492fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
493 const mod = self.bin_file.options.module.?;
494 const ip = &mod.intern_pool;
493495 const air_tags = self.air.instructions.items(.tag);
494496
495497 for (body) |inst| {
496498 // TODO: remove now-redundant isUnused calls from AIR handler functions
497 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst)) {
499 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
498500 continue;
499 }
500501
501502 const old_air_bookkeeping = self.air_bookkeeping;
502503 try self.ensureProcessDeathCapacity(Liveness.bpi);
......@@ -678,6 +679,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
678679
679680 .constant => unreachable, // excluded from function bodies
680681 .const_ty => unreachable, // excluded from function bodies
682 .interned => unreachable, // excluded from function bodies
681683 .unreach => self.finishAirBookkeeping(),
682684
683685 .optional_payload => try self.airOptionalPayload(inst),
......@@ -762,8 +764,8 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
762764 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
763765 const lhs = try self.resolveInst(extra.lhs);
764766 const rhs = try self.resolveInst(extra.rhs);
765 const lhs_ty = self.air.typeOf(extra.lhs);
766 const rhs_ty = self.air.typeOf(extra.rhs);
767 const lhs_ty = self.typeOf(extra.lhs);
768 const rhs_ty = self.typeOf(extra.rhs);
767769
768770 switch (lhs_ty.zigTypeTag(mod)) {
769771 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
......@@ -836,7 +838,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
836838}
837839
838840fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
839 const vector_ty = self.air.typeOfIndex(inst);
841 const vector_ty = self.typeOfIndex(inst);
840842 const len = vector_ty.vectorLen();
841843 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
842844 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
......@@ -871,7 +873,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
871873fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
872874 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
873875 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
874 const ptr_ty = self.air.typeOf(ty_op.operand);
876 const ptr_ty = self.typeOf(ty_op.operand);
875877 const ptr = try self.resolveInst(ty_op.operand);
876878 const array_ty = ptr_ty.childType();
877879 const array_len = @intCast(u32, array_ty.arrayLen());
......@@ -935,7 +937,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
935937
936938 const arg_mcv = try self.resolveInst(input);
937939 try self.register_manager.getReg(reg, null);
938 try self.genSetReg(self.air.typeOf(input), reg, arg_mcv);
940 try self.genSetReg(self.typeOf(input), reg, arg_mcv);
939941 }
940942
941943 {
......@@ -1008,16 +1010,16 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
10081010}
10091011
10101012fn airArg(self: *Self, inst: Air.Inst.Index) !void {
1013 const mod = self.bin_file.options.module.?;
10111014 const arg_index = self.arg_index;
10121015 self.arg_index += 1;
10131016
1014 const ty = self.air.typeOfIndex(inst);
1017 const ty = self.typeOfIndex(inst);
10151018
10161019 const arg = self.args[arg_index];
10171020 const mcv = blk: {
10181021 switch (arg) {
10191022 .stack_offset => |off| {
1020 const mod = self.bin_file.options.module.?;
10211023 const abi_size = math.cast(u32, ty.abiSize(mod)) orelse {
10221024 return self.fail("type '{}' too big to fit into stack frame", .{ty.fmt(mod)});
10231025 };
......@@ -1063,8 +1065,8 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
10631065 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
10641066 const lhs = try self.resolveInst(bin_op.lhs);
10651067 const rhs = try self.resolveInst(bin_op.rhs);
1066 const lhs_ty = self.air.typeOf(bin_op.lhs);
1067 const rhs_ty = self.air.typeOf(bin_op.rhs);
1068 const lhs_ty = self.typeOf(bin_op.lhs);
1069 const rhs_ty = self.typeOf(bin_op.rhs);
10681070 const result: MCValue = if (self.liveness.isUnused(inst))
10691071 .dead
10701072 else
......@@ -1088,8 +1090,8 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void
10881090 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
10891091 const lhs = try self.resolveInst(bin_op.lhs);
10901092 const rhs = try self.resolveInst(bin_op.rhs);
1091 const lhs_ty = self.air.typeOf(bin_op.lhs);
1092 const rhs_ty = self.air.typeOf(bin_op.rhs);
1093 const lhs_ty = self.typeOf(bin_op.lhs);
1094 const rhs_ty = self.typeOf(bin_op.rhs);
10931095 const result: MCValue = if (self.liveness.isUnused(inst))
10941096 .dead
10951097 else
......@@ -1115,7 +1117,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
11151117 defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);
11161118
11171119 const dest = try self.allocRegOrMem(inst, true);
1118 try self.setRegOrMem(self.air.typeOfIndex(inst), dest, operand);
1120 try self.setRegOrMem(self.typeOfIndex(inst), dest, operand);
11191121 break :result dest;
11201122 };
11211123 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -1218,7 +1220,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12181220 // TODO: Fold byteswap+store into a single ST*A and load+byteswap into a single LD*A.
12191221 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
12201222 const operand = try self.resolveInst(ty_op.operand);
1221 const operand_ty = self.air.typeOf(ty_op.operand);
1223 const operand_ty = self.typeOf(ty_op.operand);
12221224 switch (operand_ty.zigTypeTag(mod)) {
12231225 .Vector => return self.fail("TODO byteswap for vectors", .{}),
12241226 .Int => {
......@@ -1294,7 +1296,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
12941296 const callee = pl_op.operand;
12951297 const extra = self.air.extraData(Air.Call, pl_op.payload);
12961298 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end .. extra.end + extra.data.args_len]);
1297 const ty = self.air.typeOf(callee);
1299 const ty = self.typeOf(callee);
12981300 const mod = self.bin_file.options.module.?;
12991301 const fn_ty = switch (ty.zigTypeTag(mod)) {
13001302 .Fn => ty,
......@@ -1318,7 +1320,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13181320
13191321 for (info.args, 0..) |mc_arg, arg_i| {
13201322 const arg = args[arg_i];
1321 const arg_ty = self.air.typeOf(arg);
1323 const arg_ty = self.typeOf(arg);
13221324 const arg_mcv = try self.resolveInst(arg);
13231325
13241326 switch (mc_arg) {
......@@ -1428,7 +1430,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
14281430 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
14291431 const lhs = try self.resolveInst(bin_op.lhs);
14301432 const rhs = try self.resolveInst(bin_op.rhs);
1431 const lhs_ty = self.air.typeOf(bin_op.lhs);
1433 const lhs_ty = self.typeOf(bin_op.lhs);
14321434
14331435 const int_ty = switch (lhs_ty.zigTypeTag(mod)) {
14341436 .Vector => unreachable, // Handled by cmp_vector.
......@@ -1605,7 +1607,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
16051607 log.debug("consolidating else_entry {d} {}=>{}", .{ else_key, else_value, canon_mcv });
16061608 // TODO make sure the destination stack offset / register does not already have something
16071609 // going on there.
1608 try self.setRegOrMem(self.air.typeOfIndex(else_key), canon_mcv, else_value);
1610 try self.setRegOrMem(self.typeOfIndex(else_key), canon_mcv, else_value);
16091611 // TODO track the new register / stack allocation
16101612 }
16111613 try parent_branch.inst_table.ensureUnusedCapacity(self.gpa, saved_then_branch.inst_table.count());
......@@ -1632,7 +1634,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
16321634 log.debug("consolidating then_entry {d} {}=>{}", .{ then_key, parent_mcv, then_value });
16331635 // TODO make sure the destination stack offset / register does not already have something
16341636 // going on there.
1635 try self.setRegOrMem(self.air.typeOfIndex(then_key), parent_mcv, then_value);
1637 try self.setRegOrMem(self.typeOfIndex(then_key), parent_mcv, then_value);
16361638 // TODO track the new register / stack allocation
16371639 }
16381640
......@@ -1755,10 +1757,10 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
17551757 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
17561758
17571759 const mod = self.bin_file.options.module.?;
1758 const operand_ty = self.air.typeOf(ty_op.operand);
1760 const operand_ty = self.typeOf(ty_op.operand);
17591761 const operand = try self.resolveInst(ty_op.operand);
17601762 const info_a = operand_ty.intInfo(mod);
1761 const info_b = self.air.typeOfIndex(inst).intInfo(mod);
1763 const info_b = self.typeOfIndex(inst).intInfo(mod);
17621764 if (info_a.signedness != info_b.signedness)
17631765 return self.fail("TODO gen intcast sign safety in semantic analysis", .{});
17641766
......@@ -1780,7 +1782,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
17801782 const un_op = self.air.instructions.items(.data)[inst].un_op;
17811783 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
17821784 const operand = try self.resolveInst(un_op);
1783 const ty = self.air.typeOf(un_op);
1785 const ty = self.typeOf(un_op);
17841786 break :result try self.isErr(ty, operand);
17851787 };
17861788 return self.finishAir(inst, result, .{ un_op, .none, .none });
......@@ -1790,7 +1792,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
17901792 const un_op = self.air.instructions.items(.data)[inst].un_op;
17911793 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
17921794 const operand = try self.resolveInst(un_op);
1793 const ty = self.air.typeOf(un_op);
1795 const ty = self.typeOf(un_op);
17941796 break :result try self.isNonErr(ty, operand);
17951797 };
17961798 return self.finishAir(inst, result, .{ un_op, .none, .none });
......@@ -1815,16 +1817,16 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
18151817}
18161818
18171819fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
1818 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1819 const elem_ty = self.air.typeOfIndex(inst);
18201820 const mod = self.bin_file.options.module.?;
1821 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1822 const elem_ty = self.typeOfIndex(inst);
18211823 const elem_size = elem_ty.abiSize(mod);
18221824 const result: MCValue = result: {
18231825 if (!elem_ty.hasRuntimeBits(mod))
18241826 break :result MCValue.none;
18251827
18261828 const ptr = try self.resolveInst(ty_op.operand);
1827 const is_volatile = self.air.typeOf(ty_op.operand).isVolatilePtr();
1829 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr();
18281830 if (self.liveness.isUnused(inst) and !is_volatile)
18291831 break :result MCValue.dead;
18301832
......@@ -1839,7 +1841,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
18391841 break :blk try self.allocRegOrMem(inst, true);
18401842 }
18411843 };
1842 try self.load(dst_mcv, ptr, self.air.typeOf(ty_op.operand));
1844 try self.load(dst_mcv, ptr, self.typeOf(ty_op.operand));
18431845 break :result dst_mcv;
18441846 };
18451847 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -1882,8 +1884,8 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
18821884 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
18831885 const lhs = try self.resolveInst(bin_op.lhs);
18841886 const rhs = try self.resolveInst(bin_op.rhs);
1885 const lhs_ty = self.air.typeOf(bin_op.lhs);
1886 const rhs_ty = self.air.typeOf(bin_op.rhs);
1887 const lhs_ty = self.typeOf(bin_op.lhs);
1888 const rhs_ty = self.typeOf(bin_op.rhs);
18871889
18881890 const result: MCValue = if (self.liveness.isUnused(inst))
18891891 .dead
......@@ -1897,8 +1899,8 @@ fn airMod(self: *Self, inst: Air.Inst.Index) !void {
18971899 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
18981900 const lhs = try self.resolveInst(bin_op.lhs);
18991901 const rhs = try self.resolveInst(bin_op.rhs);
1900 const lhs_ty = self.air.typeOf(bin_op.lhs);
1901 const rhs_ty = self.air.typeOf(bin_op.rhs);
1902 const lhs_ty = self.typeOf(bin_op.lhs);
1903 const rhs_ty = self.typeOf(bin_op.rhs);
19021904 assert(lhs_ty.eql(rhs_ty, self.bin_file.options.module.?));
19031905
19041906 if (self.liveness.isUnused(inst))
......@@ -2045,8 +2047,8 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
20452047 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20462048 const lhs = try self.resolveInst(extra.lhs);
20472049 const rhs = try self.resolveInst(extra.rhs);
2048 const lhs_ty = self.air.typeOf(extra.lhs);
2049 const rhs_ty = self.air.typeOf(extra.rhs);
2050 const lhs_ty = self.typeOf(extra.lhs);
2051 const rhs_ty = self.typeOf(extra.rhs);
20502052
20512053 switch (lhs_ty.zigTypeTag(mod)) {
20522054 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
......@@ -2108,7 +2110,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
21082110 const mod = self.bin_file.options.module.?;
21092111 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
21102112 const operand = try self.resolveInst(ty_op.operand);
2111 const operand_ty = self.air.typeOf(ty_op.operand);
2113 const operand_ty = self.typeOf(ty_op.operand);
21122114 switch (operand) {
21132115 .dead => unreachable,
21142116 .unreach => unreachable,
......@@ -2285,8 +2287,8 @@ fn airRem(self: *Self, inst: Air.Inst.Index) !void {
22852287 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
22862288 const lhs = try self.resolveInst(bin_op.lhs);
22872289 const rhs = try self.resolveInst(bin_op.rhs);
2288 const lhs_ty = self.air.typeOf(bin_op.lhs);
2289 const rhs_ty = self.air.typeOf(bin_op.rhs);
2290 const lhs_ty = self.typeOf(bin_op.lhs);
2291 const rhs_ty = self.typeOf(bin_op.rhs);
22902292
22912293 // TODO add safety check
22922294
......@@ -2341,8 +2343,8 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
23412343 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
23422344 const lhs = try self.resolveInst(extra.lhs);
23432345 const rhs = try self.resolveInst(extra.rhs);
2344 const lhs_ty = self.air.typeOf(extra.lhs);
2345 const rhs_ty = self.air.typeOf(extra.rhs);
2346 const lhs_ty = self.typeOf(extra.lhs);
2347 const rhs_ty = self.typeOf(extra.rhs);
23462348
23472349 switch (lhs_ty.zigTypeTag(mod)) {
23482350 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
......@@ -2429,9 +2431,9 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
24292431 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
24302432 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
24312433 const ptr = try self.resolveInst(bin_op.lhs);
2432 const ptr_ty = self.air.typeOf(bin_op.lhs);
2434 const ptr_ty = self.typeOf(bin_op.lhs);
24332435 const len = try self.resolveInst(bin_op.rhs);
2434 const len_ty = self.air.typeOf(bin_op.rhs);
2436 const len_ty = self.typeOf(bin_op.rhs);
24352437
24362438 const ptr_bits = self.target.ptrBitWidth();
24372439 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -2453,7 +2455,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24532455 const slice_mcv = try self.resolveInst(bin_op.lhs);
24542456 const index_mcv = try self.resolveInst(bin_op.rhs);
24552457
2456 const slice_ty = self.air.typeOf(bin_op.lhs);
2458 const slice_ty = self.typeOf(bin_op.lhs);
24572459 const elem_ty = slice_ty.childType();
24582460 const mod = self.bin_file.options.module.?;
24592461 const elem_size = elem_ty.abiSize(mod);
......@@ -2544,8 +2546,8 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
25442546 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
25452547 const ptr = try self.resolveInst(bin_op.lhs);
25462548 const value = try self.resolveInst(bin_op.rhs);
2547 const ptr_ty = self.air.typeOf(bin_op.lhs);
2548 const value_ty = self.air.typeOf(bin_op.rhs);
2549 const ptr_ty = self.typeOf(bin_op.lhs);
2550 const value_ty = self.typeOf(bin_op.rhs);
25492551
25502552 try self.store(ptr, value, ptr_ty, value_ty);
25512553
......@@ -2573,7 +2575,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
25732575 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
25742576 const mod = self.bin_file.options.module.?;
25752577 const mcv = try self.resolveInst(operand);
2576 const struct_ty = self.air.typeOf(operand);
2578 const struct_ty = self.typeOf(operand);
25772579 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));
25782580
25792581 switch (mcv) {
......@@ -2659,8 +2661,8 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
26592661fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
26602662 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
26612663 const operand = try self.resolveInst(ty_op.operand);
2662 const operand_ty = self.air.typeOf(ty_op.operand);
2663 const dest_ty = self.air.typeOfIndex(inst);
2664 const operand_ty = self.typeOf(ty_op.operand);
2665 const dest_ty = self.typeOfIndex(inst);
26642666
26652667 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
26662668 break :blk try self.trunc(inst, operand, operand_ty, dest_ty);
......@@ -2674,7 +2676,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
26742676 const extra = self.air.extraData(Air.Try, pl_op.payload);
26752677 const body = self.air.extra[extra.end..][0..extra.data.body_len];
26762678 const result: MCValue = result: {
2677 const error_union_ty = self.air.typeOf(pl_op.operand);
2679 const error_union_ty = self.typeOf(pl_op.operand);
26782680 const error_union = try self.resolveInst(pl_op.operand);
26792681 const is_err_result = try self.isErr(error_union_ty, error_union);
26802682 const reloc = try self.condBr(is_err_result);
......@@ -2706,7 +2708,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
27062708fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
27072709 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
27082710 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2709 const error_union_ty = self.air.typeOf(ty_op.operand);
2711 const error_union_ty = self.typeOf(ty_op.operand);
27102712 const payload_ty = error_union_ty.errorUnionPayload();
27112713 const mcv = try self.resolveInst(ty_op.operand);
27122714 const mod = self.bin_file.options.module.?;
......@@ -2720,7 +2722,7 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
27202722fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
27212723 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
27222724 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2723 const error_union_ty = self.air.typeOf(ty_op.operand);
2725 const error_union_ty = self.typeOf(ty_op.operand);
27242726 const payload_ty = error_union_ty.errorUnionPayload();
27252727 const mod = self.bin_file.options.module.?;
27262728 if (!payload_ty.hasRuntimeBits(mod)) break :result MCValue.none;
......@@ -2753,12 +2755,12 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
27532755}
27542756
27552757fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
2758 const mod = self.bin_file.options.module.?;
27562759 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
27572760 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2758 const optional_ty = self.air.typeOfIndex(inst);
2761 const optional_ty = self.typeOfIndex(inst);
27592762
27602763 // Optional with a zero-bit payload type is just a boolean true
2761 const mod = self.bin_file.options.module.?;
27622764 if (optional_ty.abiSize(mod) == 1)
27632765 break :result MCValue{ .immediate = 1 };
27642766
......@@ -2794,9 +2796,9 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u
27942796
27952797/// Use a pointer instruction as the basis for allocating stack memory.
27962798fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
2797 const elem_ty = self.air.typeOfIndex(inst).elemType();
2798
27992799 const mod = self.bin_file.options.module.?;
2800 const elem_ty = self.typeOfIndex(inst).elemType();
2801
28002802 if (!elem_ty.hasRuntimeBits(mod)) {
28012803 // As this stack item will never be dereferenced at runtime,
28022804 // return the stack offset 0. Stack offset 0 will be where all
......@@ -2814,8 +2816,8 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
28142816}
28152817
28162818fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {
2817 const elem_ty = self.air.typeOfIndex(inst);
28182819 const mod = self.bin_file.options.module.?;
2820 const elem_ty = self.typeOfIndex(inst);
28192821 const abi_size = math.cast(u32, elem_ty.abiSize(mod)) orelse {
28202822 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(mod)});
28212823 };
......@@ -3406,7 +3408,7 @@ fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
34063408 const block_data = self.blocks.getPtr(block).?;
34073409
34083410 const mod = self.bin_file.options.module.?;
3409 if (self.air.typeOf(operand).hasRuntimeBits(mod)) {
3411 if (self.typeOf(operand).hasRuntimeBits(mod)) {
34103412 const operand_mcv = try self.resolveInst(operand);
34113413 const block_mcv = block_data.mcv;
34123414 if (block_mcv == .none) {
......@@ -3415,13 +3417,13 @@ fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
34153417 .register, .stack_offset, .memory => operand_mcv,
34163418 .immediate => blk: {
34173419 const new_mcv = try self.allocRegOrMem(block, true);
3418 try self.setRegOrMem(self.air.typeOfIndex(block), new_mcv, operand_mcv);
3420 try self.setRegOrMem(self.typeOfIndex(block), new_mcv, operand_mcv);
34193421 break :blk new_mcv;
34203422 },
34213423 else => return self.fail("TODO implement block_data.mcv = operand_mcv for {}", .{operand_mcv}),
34223424 };
34233425 } else {
3424 try self.setRegOrMem(self.air.typeOfIndex(block), block_mcv, operand_mcv);
3426 try self.setRegOrMem(self.typeOfIndex(block), block_mcv, operand_mcv);
34253427 }
34263428 }
34273429 return self.brVoid(block);
......@@ -4549,7 +4551,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
45494551
45504552fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
45514553 const mod = self.bin_file.options.module.?;
4552 const ty = self.air.typeOf(ref);
4554 const ty = self.typeOf(ref);
45534555
45544556 // If the type has no codegen bits, no need to store it.
45554557 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
......@@ -4654,7 +4656,7 @@ fn spillConditionFlagsIfOccupied(self: *Self) !void {
46544656 else => unreachable, // mcv doesn't occupy the compare flags
46554657 };
46564658
4657 try self.setRegOrMem(self.air.typeOfIndex(inst_to_save), new_mcv, mcv);
4659 try self.setRegOrMem(self.typeOfIndex(inst_to_save), new_mcv, mcv);
46584660 log.debug("spilling {d} to mcv {any}", .{ inst_to_save, new_mcv });
46594661
46604662 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
......@@ -4678,7 +4680,7 @@ pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void
46784680 assert(reg == reg_mcv.register);
46794681 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
46804682 try branch.inst_table.put(self.gpa, inst, stack_mcv);
4681 try self.genSetStack(self.air.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv);
4683 try self.genSetStack(self.typeOfIndex(inst), stack_mcv.stack_offset, reg_mcv);
46824684}
46834685
46844686fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
......@@ -4726,7 +4728,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
47264728 return if (self.liveness.isUnused(inst)) .dead else result: {
47274729 const mod = self.bin_file.options.module.?;
47284730 const mcv = try self.resolveInst(operand);
4729 const ptr_ty = self.air.typeOf(operand);
4731 const ptr_ty = self.typeOf(operand);
47304732 const struct_ty = ptr_ty.childType();
47314733 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));
47324734 switch (mcv) {
......@@ -4885,3 +4887,13 @@ fn wantSafety(self: *Self) bool {
48854887 .ReleaseSmall => false,
48864888 };
48874889}
4890
4891fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
4892 const mod = self.bin_file.options.module.?;
4893 return self.air.typeOf(inst, mod.intern_pool);
4894}
4895
4896fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
4897 const mod = self.bin_file.options.module.?;
4898 return self.air.typeOfIndex(inst, mod.intern_pool);
4899}
src/arch/wasm/CodeGen.zig+127-113
......@@ -790,7 +790,7 @@ fn resolveInst(func: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {
790790
791791 const mod = func.bin_file.base.options.module.?;
792792 const val = func.air.value(ref, mod).?;
793 const ty = func.air.typeOf(ref);
793 const ty = func.typeOf(ref);
794794 if (!ty.hasRuntimeBitsIgnoreComptime(mod) and !ty.isInt(mod) and !ty.isError(mod)) {
795795 gop.value_ptr.* = WValue{ .none = {} };
796796 return gop.value_ptr.*;
......@@ -1260,7 +1260,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
12601260 // we emit an unreachable instruction to tell the stack validator that part will never be reached.
12611261 if (func_type.returns.len != 0 and func.air.instructions.len > 0) {
12621262 const inst = @intCast(u32, func.air.instructions.len - 1);
1263 const last_inst_ty = func.air.typeOfIndex(inst);
1263 const last_inst_ty = func.typeOfIndex(inst);
12641264 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(mod) or last_inst_ty.isNoReturn()) {
12651265 try func.addTag(.@"unreachable");
12661266 }
......@@ -1541,7 +1541,7 @@ fn allocStack(func: *CodeGen, ty: Type) !WValue {
15411541/// if it is set, to ensure the stack alignment will be set correctly.
15421542fn allocStackPtr(func: *CodeGen, inst: Air.Inst.Index) !WValue {
15431543 const mod = func.bin_file.base.options.module.?;
1544 const ptr_ty = func.air.typeOfIndex(inst);
1544 const ptr_ty = func.typeOfIndex(inst);
15451545 const pointee_ty = ptr_ty.childType();
15461546
15471547 if (func.initial_stack_value == .none) {
......@@ -1834,6 +1834,7 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
18341834 return switch (air_tags[inst]) {
18351835 .constant => unreachable,
18361836 .const_ty => unreachable,
1837 .interned => unreachable,
18371838
18381839 .add => func.airBinOp(inst, .add),
18391840 .add_sat => func.airSatBinOp(inst, .add),
......@@ -2073,8 +2074,11 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20732074}
20742075
20752076fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2077 const mod = func.bin_file.base.options.module.?;
2078 const ip = &mod.intern_pool;
2079
20762080 for (body) |inst| {
2077 if (func.liveness.isUnused(inst) and !func.air.mustLower(inst)) {
2081 if (func.liveness.isUnused(inst) and !func.air.mustLower(inst, ip.*)) {
20782082 continue;
20792083 }
20802084 const old_bookkeeping_value = func.air_bookkeeping;
......@@ -2134,8 +2138,8 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21342138}
21352139
21362140fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2137 const child_type = func.air.typeOfIndex(inst).childType();
21382141 const mod = func.bin_file.base.options.module.?;
2142 const child_type = func.typeOfIndex(inst).childType();
21392143
21402144 var result = result: {
21412145 if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
......@@ -2157,7 +2161,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21572161 const mod = func.bin_file.base.options.module.?;
21582162 const un_op = func.air.instructions.items(.data)[inst].un_op;
21592163 const operand = try func.resolveInst(un_op);
2160 const ret_ty = func.air.typeOf(un_op).childType();
2164 const ret_ty = func.typeOf(un_op).childType();
21612165
21622166 const fn_info = func.decl.ty.fnInfo();
21632167 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -2179,7 +2183,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
21792183 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
21802184 const extra = func.air.extraData(Air.Call, pl_op.payload);
21812185 const args = @ptrCast([]const Air.Inst.Ref, func.air.extra[extra.end..][0..extra.data.args_len]);
2182 const ty = func.air.typeOf(pl_op.operand);
2186 const ty = func.typeOf(pl_op.operand);
21832187
21842188 const mod = func.bin_file.base.options.module.?;
21852189 const fn_ty = switch (ty.zigTypeTag(mod)) {
......@@ -2228,7 +2232,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
22282232 for (args) |arg| {
22292233 const arg_val = try func.resolveInst(arg);
22302234
2231 const arg_ty = func.air.typeOf(arg);
2235 const arg_ty = func.typeOf(arg);
22322236 if (!arg_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
22332237
22342238 try func.lowerArg(fn_ty.fnInfo().cc, arg_ty, arg_val);
......@@ -2296,7 +2300,7 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
22962300
22972301 const lhs = try func.resolveInst(bin_op.lhs);
22982302 const rhs = try func.resolveInst(bin_op.rhs);
2299 const ptr_ty = func.air.typeOf(bin_op.lhs);
2303 const ptr_ty = func.typeOf(bin_op.lhs);
23002304 const ptr_info = ptr_ty.ptrInfo().data;
23012305 const ty = ptr_ty.childType();
23022306
......@@ -2449,7 +2453,7 @@ fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
24492453 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
24502454 const operand = try func.resolveInst(ty_op.operand);
24512455 const ty = func.air.getRefType(ty_op.ty);
2452 const ptr_ty = func.air.typeOf(ty_op.operand);
2456 const ptr_ty = func.typeOf(ty_op.operand);
24532457 const ptr_info = ptr_ty.ptrInfo().data;
24542458
24552459 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return func.finishAir(inst, .none, &.{ty_op.operand});
......@@ -2522,11 +2526,11 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu
25222526}
25232527
25242528fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2529 const mod = func.bin_file.base.options.module.?;
25252530 const arg_index = func.arg_index;
25262531 const arg = func.args[arg_index];
25272532 const cc = func.decl.ty.fnInfo().cc;
2528 const arg_ty = func.air.typeOfIndex(inst);
2529 const mod = func.bin_file.base.options.module.?;
2533 const arg_ty = func.typeOfIndex(inst);
25302534 if (cc == .C) {
25312535 const arg_classes = abi.classifyType(arg_ty, mod);
25322536 for (arg_classes) |class| {
......@@ -2572,8 +2576,8 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
25722576 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
25732577 const lhs = try func.resolveInst(bin_op.lhs);
25742578 const rhs = try func.resolveInst(bin_op.rhs);
2575 const lhs_ty = func.air.typeOf(bin_op.lhs);
2576 const rhs_ty = func.air.typeOf(bin_op.rhs);
2579 const lhs_ty = func.typeOf(bin_op.lhs);
2580 const rhs_ty = func.typeOf(bin_op.rhs);
25772581
25782582 // For certain operations, such as shifting, the types are different.
25792583 // When converting this to a WebAssembly type, they *must* match to perform
......@@ -2770,7 +2774,7 @@ const FloatOp = enum {
27702774fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError!void {
27712775 const un_op = func.air.instructions.items(.data)[inst].un_op;
27722776 const operand = try func.resolveInst(un_op);
2773 const ty = func.air.typeOf(un_op);
2777 const ty = func.typeOf(un_op);
27742778
27752779 const result = try (try func.floatOp(op, ty, &.{operand})).toLocal(func, ty);
27762780 func.finishAir(inst, result, &.{un_op});
......@@ -2847,8 +2851,8 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
28472851
28482852 const lhs = try func.resolveInst(bin_op.lhs);
28492853 const rhs = try func.resolveInst(bin_op.rhs);
2850 const lhs_ty = func.air.typeOf(bin_op.lhs);
2851 const rhs_ty = func.air.typeOf(bin_op.rhs);
2854 const lhs_ty = func.typeOf(bin_op.lhs);
2855 const rhs_ty = func.typeOf(bin_op.rhs);
28522856
28532857 if (lhs_ty.zigTypeTag(mod) == .Vector or rhs_ty.zigTypeTag(mod) == .Vector) {
28542858 return func.fail("TODO: Implement wrapping arithmetic for vectors", .{});
......@@ -3387,7 +3391,7 @@ fn airCmp(func: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) In
33873391
33883392 const lhs = try func.resolveInst(bin_op.lhs);
33893393 const rhs = try func.resolveInst(bin_op.rhs);
3390 const operand_ty = func.air.typeOf(bin_op.lhs);
3394 const operand_ty = func.typeOf(bin_op.lhs);
33913395 const result = try (try func.cmp(lhs, rhs, operand_ty, op)).toLocal(func, Type.u32); // comparison result is always 32 bits
33923396 func.finishAir(inst, result, &.{ bin_op.lhs, bin_op.rhs });
33933397}
......@@ -3488,7 +3492,7 @@ fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34883492 const block = func.blocks.get(br.block_inst).?;
34893493
34903494 // if operand has codegen bits we should break with a value
3491 if (func.air.typeOf(br.operand).hasRuntimeBitsIgnoreComptime(mod)) {
3495 if (func.typeOf(br.operand).hasRuntimeBitsIgnoreComptime(mod)) {
34923496 const operand = try func.resolveInst(br.operand);
34933497 try func.lowerToStack(operand);
34943498
......@@ -3509,7 +3513,7 @@ fn airNot(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
35093513 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
35103514
35113515 const operand = try func.resolveInst(ty_op.operand);
3512 const operand_ty = func.air.typeOf(ty_op.operand);
3516 const operand_ty = func.typeOf(ty_op.operand);
35133517 const mod = func.bin_file.base.options.module.?;
35143518
35153519 const result = result: {
......@@ -3575,8 +3579,8 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
35753579 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
35763580 const result = result: {
35773581 const operand = try func.resolveInst(ty_op.operand);
3578 const wanted_ty = func.air.typeOfIndex(inst);
3579 const given_ty = func.air.typeOf(ty_op.operand);
3582 const wanted_ty = func.typeOfIndex(inst);
3583 const given_ty = func.typeOf(ty_op.operand);
35803584 if (given_ty.isAnyFloat() or wanted_ty.isAnyFloat()) {
35813585 const bitcast_result = try func.bitcast(wanted_ty, given_ty, operand);
35823586 break :result try bitcast_result.toLocal(func, wanted_ty);
......@@ -3609,7 +3613,7 @@ fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
36093613 const extra = func.air.extraData(Air.StructField, ty_pl.payload);
36103614
36113615 const struct_ptr = try func.resolveInst(extra.data.struct_operand);
3612 const struct_ty = func.air.typeOf(extra.data.struct_operand).childType();
3616 const struct_ty = func.typeOf(extra.data.struct_operand).childType();
36133617 const result = try func.structFieldPtr(inst, extra.data.struct_operand, struct_ptr, struct_ty, extra.data.field_index);
36143618 func.finishAir(inst, result, &.{extra.data.struct_operand});
36153619}
......@@ -3617,7 +3621,7 @@ fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
36173621fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {
36183622 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
36193623 const struct_ptr = try func.resolveInst(ty_op.operand);
3620 const struct_ty = func.air.typeOf(ty_op.operand).childType();
3624 const struct_ty = func.typeOf(ty_op.operand).childType();
36213625
36223626 const result = try func.structFieldPtr(inst, ty_op.operand, struct_ptr, struct_ty, index);
36233627 func.finishAir(inst, result, &.{ty_op.operand});
......@@ -3632,7 +3636,7 @@ fn structFieldPtr(
36323636 index: u32,
36333637) InnerError!WValue {
36343638 const mod = func.bin_file.base.options.module.?;
3635 const result_ty = func.air.typeOfIndex(inst);
3639 const result_ty = func.typeOfIndex(inst);
36363640 const offset = switch (struct_ty.containerLayout()) {
36373641 .Packed => switch (struct_ty.zigTypeTag(mod)) {
36383642 .Struct => offset: {
......@@ -3663,7 +3667,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
36633667 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
36643668 const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data;
36653669
3666 const struct_ty = func.air.typeOf(struct_field.struct_operand);
3670 const struct_ty = func.typeOf(struct_field.struct_operand);
36673671 const operand = try func.resolveInst(struct_field.struct_operand);
36683672 const field_index = struct_field.field_index;
36693673 const field_ty = struct_ty.structFieldType(field_index);
......@@ -3762,7 +3766,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37623766 const blocktype = wasm.block_empty;
37633767 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
37643768 const target = try func.resolveInst(pl_op.operand);
3765 const target_ty = func.air.typeOf(pl_op.operand);
3769 const target_ty = func.typeOf(pl_op.operand);
37663770 const switch_br = func.air.extraData(Air.SwitchBr, pl_op.payload);
37673771 const liveness = try func.liveness.getSwitchBr(func.gpa, inst, switch_br.data.cases_len + 1);
37683772 defer func.gpa.free(liveness.deaths);
......@@ -3940,7 +3944,7 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
39403944 const mod = func.bin_file.base.options.module.?;
39413945 const un_op = func.air.instructions.items(.data)[inst].un_op;
39423946 const operand = try func.resolveInst(un_op);
3943 const err_union_ty = func.air.typeOf(un_op);
3947 const err_union_ty = func.typeOf(un_op);
39443948 const pl_ty = err_union_ty.errorUnionPayload();
39453949
39463950 const result = result: {
......@@ -3976,7 +3980,7 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
39763980 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
39773981
39783982 const operand = try func.resolveInst(ty_op.operand);
3979 const op_ty = func.air.typeOf(ty_op.operand);
3983 const op_ty = func.typeOf(ty_op.operand);
39803984 const err_ty = if (op_is_ptr) op_ty.childType() else op_ty;
39813985 const payload_ty = err_ty.errorUnionPayload();
39823986
......@@ -4004,7 +4008,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
40044008 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
40054009
40064010 const operand = try func.resolveInst(ty_op.operand);
4007 const op_ty = func.air.typeOf(ty_op.operand);
4011 const op_ty = func.typeOf(ty_op.operand);
40084012 const err_ty = if (op_is_ptr) op_ty.childType() else op_ty;
40094013 const payload_ty = err_ty.errorUnionPayload();
40104014
......@@ -4028,9 +4032,9 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
40284032 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
40294033
40304034 const operand = try func.resolveInst(ty_op.operand);
4031 const err_ty = func.air.typeOfIndex(inst);
4035 const err_ty = func.typeOfIndex(inst);
40324036
4033 const pl_ty = func.air.typeOf(ty_op.operand);
4037 const pl_ty = func.typeOf(ty_op.operand);
40344038 const result = result: {
40354039 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) {
40364040 break :result func.reuseOperand(ty_op.operand, operand);
......@@ -4082,7 +4086,7 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40824086
40834087 const ty = func.air.getRefType(ty_op.ty);
40844088 const operand = try func.resolveInst(ty_op.operand);
4085 const operand_ty = func.air.typeOf(ty_op.operand);
4089 const operand_ty = func.typeOf(ty_op.operand);
40864090 const mod = func.bin_file.base.options.module.?;
40874091 if (ty.zigTypeTag(mod) == .Vector or operand_ty.zigTypeTag(mod) == .Vector) {
40884092 return func.fail("todo Wasm intcast for vectors", .{});
......@@ -4155,7 +4159,7 @@ fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind:
41554159 const un_op = func.air.instructions.items(.data)[inst].un_op;
41564160 const operand = try func.resolveInst(un_op);
41574161
4158 const op_ty = func.air.typeOf(un_op);
4162 const op_ty = func.typeOf(un_op);
41594163 const optional_ty = if (op_kind == .ptr) op_ty.childType() else op_ty;
41604164 const is_null = try func.isNull(operand, optional_ty, opcode);
41614165 const result = try is_null.toLocal(func, optional_ty);
......@@ -4196,8 +4200,8 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod
41964200fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41974201 const mod = func.bin_file.base.options.module.?;
41984202 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4199 const opt_ty = func.air.typeOf(ty_op.operand);
4200 const payload_ty = func.air.typeOfIndex(inst);
4203 const opt_ty = func.typeOf(ty_op.operand);
4204 const payload_ty = func.typeOfIndex(inst);
42014205 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
42024206 return func.finishAir(inst, .none, &.{ty_op.operand});
42034207 }
......@@ -4219,7 +4223,7 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42194223fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42204224 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
42214225 const operand = try func.resolveInst(ty_op.operand);
4222 const opt_ty = func.air.typeOf(ty_op.operand).childType();
4226 const opt_ty = func.typeOf(ty_op.operand).childType();
42234227
42244228 const mod = func.bin_file.base.options.module.?;
42254229 const result = result: {
......@@ -4238,7 +4242,7 @@ fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
42384242 const mod = func.bin_file.base.options.module.?;
42394243 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
42404244 const operand = try func.resolveInst(ty_op.operand);
4241 const opt_ty = func.air.typeOf(ty_op.operand).childType();
4245 const opt_ty = func.typeOf(ty_op.operand).childType();
42424246 var buf: Type.Payload.ElemType = undefined;
42434247 const payload_ty = opt_ty.optionalChild(&buf);
42444248 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -4263,7 +4267,7 @@ fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
42634267
42644268fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42654269 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
4266 const payload_ty = func.air.typeOf(ty_op.operand);
4270 const payload_ty = func.typeOf(ty_op.operand);
42674271 const mod = func.bin_file.base.options.module.?;
42684272
42694273 const result = result: {
......@@ -4276,7 +4280,7 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42764280 }
42774281
42784282 const operand = try func.resolveInst(ty_op.operand);
4279 const op_ty = func.air.typeOfIndex(inst);
4283 const op_ty = func.typeOfIndex(inst);
42804284 if (op_ty.optionalReprIsPayload(mod)) {
42814285 break :result func.reuseOperand(ty_op.operand, operand);
42824286 }
......@@ -4304,7 +4308,7 @@ fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43044308
43054309 const lhs = try func.resolveInst(bin_op.lhs);
43064310 const rhs = try func.resolveInst(bin_op.rhs);
4307 const slice_ty = func.air.typeOfIndex(inst);
4311 const slice_ty = func.typeOfIndex(inst);
43084312
43094313 const slice = try func.allocStack(slice_ty);
43104314 try func.store(slice, lhs, Type.usize, 0);
......@@ -4323,7 +4327,7 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43234327fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43244328 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
43254329
4326 const slice_ty = func.air.typeOf(bin_op.lhs);
4330 const slice_ty = func.typeOf(bin_op.lhs);
43274331 const slice = try func.resolveInst(bin_op.lhs);
43284332 const index = try func.resolveInst(bin_op.rhs);
43294333 const elem_ty = slice_ty.childType();
......@@ -4395,7 +4399,7 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43954399
43964400 const operand = try func.resolveInst(ty_op.operand);
43974401 const wanted_ty = func.air.getRefType(ty_op.ty);
4398 const op_ty = func.air.typeOf(ty_op.operand);
4402 const op_ty = func.typeOf(ty_op.operand);
43994403
44004404 const result = try func.trunc(operand, wanted_ty, op_ty);
44014405 func.finishAir(inst, try result.toLocal(func, wanted_ty), &.{ty_op.operand});
......@@ -4432,7 +4436,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44324436 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
44334437
44344438 const operand = try func.resolveInst(ty_op.operand);
4435 const array_ty = func.air.typeOf(ty_op.operand).childType();
4439 const array_ty = func.typeOf(ty_op.operand).childType();
44364440 const slice_ty = func.air.getRefType(ty_op.ty);
44374441
44384442 // create a slice on the stack
......@@ -4453,7 +4457,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44534457fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44544458 const un_op = func.air.instructions.items(.data)[inst].un_op;
44554459 const operand = try func.resolveInst(un_op);
4456 const ptr_ty = func.air.typeOf(un_op);
4460 const ptr_ty = func.typeOf(un_op);
44574461 const result = if (ptr_ty.isSlice())
44584462 try func.slicePtr(operand)
44594463 else switch (operand) {
......@@ -4467,7 +4471,7 @@ fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44674471fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44684472 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
44694473
4470 const ptr_ty = func.air.typeOf(bin_op.lhs);
4474 const ptr_ty = func.typeOf(bin_op.lhs);
44714475 const ptr = try func.resolveInst(bin_op.lhs);
44724476 const index = try func.resolveInst(bin_op.rhs);
44734477 const elem_ty = ptr_ty.childType();
......@@ -4505,7 +4509,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45054509 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
45064510 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
45074511
4508 const ptr_ty = func.air.typeOf(bin_op.lhs);
4512 const ptr_ty = func.typeOf(bin_op.lhs);
45094513 const elem_ty = func.air.getRefType(ty_pl.ty).childType();
45104514 const mod = func.bin_file.base.options.module.?;
45114515 const elem_size = elem_ty.abiSize(mod);
......@@ -4538,7 +4542,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
45384542
45394543 const ptr = try func.resolveInst(bin_op.lhs);
45404544 const offset = try func.resolveInst(bin_op.rhs);
4541 const ptr_ty = func.air.typeOf(bin_op.lhs);
4545 const ptr_ty = func.typeOf(bin_op.lhs);
45424546 const pointee_ty = switch (ptr_ty.ptrSize()) {
45434547 .One => ptr_ty.childType().childType(), // ptr to array, so get array element type
45444548 else => ptr_ty.childType(),
......@@ -4568,7 +4572,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
45684572 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
45694573
45704574 const ptr = try func.resolveInst(bin_op.lhs);
4571 const ptr_ty = func.air.typeOf(bin_op.lhs);
4575 const ptr_ty = func.typeOf(bin_op.lhs);
45724576 const value = try func.resolveInst(bin_op.rhs);
45734577 const len = switch (ptr_ty.ptrSize()) {
45744578 .Slice => try func.sliceLen(ptr),
......@@ -4683,7 +4687,7 @@ fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue
46834687fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46844688 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
46854689
4686 const array_ty = func.air.typeOf(bin_op.lhs);
4690 const array_ty = func.typeOf(bin_op.lhs);
46874691 const array = try func.resolveInst(bin_op.lhs);
46884692 const index = try func.resolveInst(bin_op.rhs);
46894693 const elem_ty = array_ty.childType();
......@@ -4750,12 +4754,12 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47504754}
47514755
47524756fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4757 const mod = func.bin_file.base.options.module.?;
47534758 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
47544759
47554760 const operand = try func.resolveInst(ty_op.operand);
4756 const dest_ty = func.air.typeOfIndex(inst);
4757 const op_ty = func.air.typeOf(ty_op.operand);
4758 const mod = func.bin_file.base.options.module.?;
4761 const dest_ty = func.typeOfIndex(inst);
4762 const op_ty = func.typeOf(ty_op.operand);
47594763
47604764 if (op_ty.abiSize(mod) > 8) {
47614765 return func.fail("TODO: floatToInt for integers/floats with bitsize larger than 64 bits", .{});
......@@ -4775,12 +4779,12 @@ fn airFloatToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47754779}
47764780
47774781fn airIntToFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4782 const mod = func.bin_file.base.options.module.?;
47784783 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
47794784
47804785 const operand = try func.resolveInst(ty_op.operand);
4781 const dest_ty = func.air.typeOfIndex(inst);
4782 const op_ty = func.air.typeOf(ty_op.operand);
4783 const mod = func.bin_file.base.options.module.?;
4786 const dest_ty = func.typeOfIndex(inst);
4787 const op_ty = func.typeOf(ty_op.operand);
47844788
47854789 if (op_ty.abiSize(mod) > 8) {
47864790 return func.fail("TODO: intToFloat for integers/floats with bitsize larger than 64 bits", .{});
......@@ -4804,7 +4808,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48044808 const mod = func.bin_file.base.options.module.?;
48054809 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
48064810 const operand = try func.resolveInst(ty_op.operand);
4807 const ty = func.air.typeOfIndex(inst);
4811 const ty = func.typeOfIndex(inst);
48084812 const elem_ty = ty.childType();
48094813
48104814 if (determineSimdStoreStrategy(ty, mod) == .direct) blk: {
......@@ -4881,7 +4885,7 @@ fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48814885
48824886fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48834887 const mod = func.bin_file.base.options.module.?;
4884 const inst_ty = func.air.typeOfIndex(inst);
4888 const inst_ty = func.typeOfIndex(inst);
48854889 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
48864890 const extra = func.air.extraData(Air.Shuffle, ty_pl.payload).data;
48874891
......@@ -4894,7 +4898,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48944898 const elem_size = child_ty.abiSize(mod);
48954899
48964900 // TODO: One of them could be by ref; handle in loop
4897 if (isByRef(func.air.typeOf(extra.a), mod) or isByRef(inst_ty, mod)) {
4901 if (isByRef(func.typeOf(extra.a), mod) or isByRef(inst_ty, mod)) {
48984902 const result = try func.allocStack(inst_ty);
48994903
49004904 for (0..mask_len) |index| {
......@@ -4951,11 +4955,11 @@ fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49514955}
49524956
49534957fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4958 const mod = func.bin_file.base.options.module.?;
49544959 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
4955 const result_ty = func.air.typeOfIndex(inst);
4960 const result_ty = func.typeOfIndex(inst);
49564961 const len = @intCast(usize, result_ty.arrayLen());
49574962 const elements = @ptrCast([]const Air.Inst.Ref, func.air.extra[ty_pl.payload..][0..len]);
4958 const mod = func.bin_file.base.options.module.?;
49594963
49604964 const result: WValue = result_value: {
49614965 switch (result_ty.zigTypeTag(mod)) {
......@@ -5085,7 +5089,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50855089 const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data;
50865090
50875091 const result = result: {
5088 const union_ty = func.air.typeOfIndex(inst);
5092 const union_ty = func.typeOfIndex(inst);
50895093 const layout = union_ty.unionGetLayout(mod);
50905094 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
50915095 const field = union_obj.fields.values()[extra.field_index];
......@@ -5164,7 +5168,7 @@ fn airPrefetch(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51645168fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51655169 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
51665170
5167 const result = try func.allocLocal(func.air.typeOfIndex(inst));
5171 const result = try func.allocLocal(func.typeOfIndex(inst));
51685172 try func.addLabel(.memory_size, pl_op.payload);
51695173 try func.addLabel(.local_set, result.local.value);
51705174 func.finishAir(inst, result, &.{pl_op.operand});
......@@ -5174,7 +5178,7 @@ fn airWasmMemoryGrow(func: *CodeGen, inst: Air.Inst.Index) !void {
51745178 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
51755179
51765180 const operand = try func.resolveInst(pl_op.operand);
5177 const result = try func.allocLocal(func.air.typeOfIndex(inst));
5181 const result = try func.allocLocal(func.typeOfIndex(inst));
51785182 try func.emitWValue(operand);
51795183 try func.addLabel(.memory_grow, pl_op.payload);
51805184 try func.addLabel(.local_set, result.local.value);
......@@ -5263,8 +5267,8 @@ fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std
52635267fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52645268 const mod = func.bin_file.base.options.module.?;
52655269 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
5266 const un_ty = func.air.typeOf(bin_op.lhs).childType();
5267 const tag_ty = func.air.typeOf(bin_op.rhs);
5270 const un_ty = func.typeOf(bin_op.lhs).childType();
5271 const tag_ty = func.typeOf(bin_op.rhs);
52685272 const layout = un_ty.unionGetLayout(mod);
52695273 if (layout.tag_size == 0) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
52705274
......@@ -5288,8 +5292,8 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52885292 const mod = func.bin_file.base.options.module.?;
52895293 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
52905294
5291 const un_ty = func.air.typeOf(ty_op.operand);
5292 const tag_ty = func.air.typeOfIndex(inst);
5295 const un_ty = func.typeOf(ty_op.operand);
5296 const tag_ty = func.typeOfIndex(inst);
52935297 const layout = un_ty.unionGetLayout(mod);
52945298 if (layout.tag_size == 0) return func.finishAir(inst, .none, &.{ty_op.operand});
52955299
......@@ -5307,9 +5311,9 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53075311fn airFpext(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53085312 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
53095313
5310 const dest_ty = func.air.typeOfIndex(inst);
5314 const dest_ty = func.typeOfIndex(inst);
53115315 const operand = try func.resolveInst(ty_op.operand);
5312 const extended = try func.fpext(operand, func.air.typeOf(ty_op.operand), dest_ty);
5316 const extended = try func.fpext(operand, func.typeOf(ty_op.operand), dest_ty);
53135317 const result = try extended.toLocal(func, dest_ty);
53145318 func.finishAir(inst, result, &.{ty_op.operand});
53155319}
......@@ -5352,9 +5356,9 @@ fn fpext(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!
53525356fn airFptrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53535357 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
53545358
5355 const dest_ty = func.air.typeOfIndex(inst);
5359 const dest_ty = func.typeOfIndex(inst);
53565360 const operand = try func.resolveInst(ty_op.operand);
5357 const truncated = try func.fptrunc(operand, func.air.typeOf(ty_op.operand), dest_ty);
5361 const truncated = try func.fptrunc(operand, func.typeOf(ty_op.operand), dest_ty);
53585362 const result = try truncated.toLocal(func, dest_ty);
53595363 func.finishAir(inst, result, &.{ty_op.operand});
53605364}
......@@ -5393,7 +5397,7 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
53935397 const mod = func.bin_file.base.options.module.?;
53945398 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
53955399
5396 const err_set_ty = func.air.typeOf(ty_op.operand).childType();
5400 const err_set_ty = func.typeOf(ty_op.operand).childType();
53975401 const payload_ty = err_set_ty.errorUnionPayload();
53985402 const operand = try func.resolveInst(ty_op.operand);
53995403
......@@ -5448,10 +5452,10 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54485452 const mod = func.bin_file.base.options.module.?;
54495453 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
54505454 const dst = try func.resolveInst(bin_op.lhs);
5451 const dst_ty = func.air.typeOf(bin_op.lhs);
5455 const dst_ty = func.typeOf(bin_op.lhs);
54525456 const ptr_elem_ty = dst_ty.childType();
54535457 const src = try func.resolveInst(bin_op.rhs);
5454 const src_ty = func.air.typeOf(bin_op.rhs);
5458 const src_ty = func.typeOf(bin_op.rhs);
54555459 const len = switch (dst_ty.ptrSize()) {
54565460 .Slice => blk: {
54575461 const slice_len = try func.sliceLen(dst);
......@@ -5485,12 +5489,12 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54855489}
54865490
54875491fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5492 const mod = func.bin_file.base.options.module.?;
54885493 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
54895494
54905495 const operand = try func.resolveInst(ty_op.operand);
5491 const op_ty = func.air.typeOf(ty_op.operand);
5492 const result_ty = func.air.typeOfIndex(inst);
5493 const mod = func.bin_file.base.options.module.?;
5496 const op_ty = func.typeOf(ty_op.operand);
5497 const result_ty = func.typeOfIndex(inst);
54945498
54955499 if (op_ty.zigTypeTag(mod) == .Vector) {
54965500 return func.fail("TODO: Implement @popCount for vectors", .{});
......@@ -5585,7 +5589,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
55855589
55865590 const lhs_op = try func.resolveInst(extra.lhs);
55875591 const rhs_op = try func.resolveInst(extra.rhs);
5588 const lhs_ty = func.air.typeOf(extra.lhs);
5592 const lhs_ty = func.typeOf(extra.lhs);
55895593 const mod = func.bin_file.base.options.module.?;
55905594
55915595 if (lhs_ty.zigTypeTag(mod) == .Vector) {
......@@ -5599,7 +5603,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
55995603 };
56005604
56015605 if (wasm_bits == 128) {
5602 const result = try func.addSubWithOverflowBigInt(lhs_op, rhs_op, lhs_ty, func.air.typeOfIndex(inst), op);
5606 const result = try func.addSubWithOverflowBigInt(lhs_op, rhs_op, lhs_ty, func.typeOfIndex(inst), op);
56035607 return func.finishAir(inst, result, &.{ extra.lhs, extra.rhs });
56045608 }
56055609
......@@ -5649,7 +5653,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
56495653 var overflow_local = try overflow_bit.toLocal(func, Type.u32);
56505654 defer overflow_local.free(func);
56515655
5652 const result_ptr = try func.allocStack(func.air.typeOfIndex(inst));
5656 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
56535657 try func.store(result_ptr, result, lhs_ty, 0);
56545658 const offset = @intCast(u32, lhs_ty.abiSize(mod));
56555659 try func.store(result_ptr, overflow_local, Type.initTag(.u1), offset);
......@@ -5729,8 +5733,8 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57295733
57305734 const lhs = try func.resolveInst(extra.lhs);
57315735 const rhs = try func.resolveInst(extra.rhs);
5732 const lhs_ty = func.air.typeOf(extra.lhs);
5733 const rhs_ty = func.air.typeOf(extra.rhs);
5736 const lhs_ty = func.typeOf(extra.lhs);
5737 const rhs_ty = func.typeOf(extra.rhs);
57345738
57355739 if (lhs_ty.zigTypeTag(mod) == .Vector) {
57365740 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});
......@@ -5771,7 +5775,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57715775 var overflow_local = try overflow_bit.toLocal(func, Type.initTag(.u1));
57725776 defer overflow_local.free(func);
57735777
5774 const result_ptr = try func.allocStack(func.air.typeOfIndex(inst));
5778 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
57755779 try func.store(result_ptr, result, lhs_ty, 0);
57765780 const offset = @intCast(u32, lhs_ty.abiSize(mod));
57775781 try func.store(result_ptr, overflow_local, Type.initTag(.u1), offset);
......@@ -5785,7 +5789,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57855789
57865790 const lhs = try func.resolveInst(extra.lhs);
57875791 const rhs = try func.resolveInst(extra.rhs);
5788 const lhs_ty = func.air.typeOf(extra.lhs);
5792 const lhs_ty = func.typeOf(extra.lhs);
57895793 const mod = func.bin_file.base.options.module.?;
57905794
57915795 if (lhs_ty.zigTypeTag(mod) == .Vector) {
......@@ -5946,7 +5950,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59465950 var bin_op_local = try bin_op.toLocal(func, lhs_ty);
59475951 defer bin_op_local.free(func);
59485952
5949 const result_ptr = try func.allocStack(func.air.typeOfIndex(inst));
5953 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
59505954 try func.store(result_ptr, bin_op_local, lhs_ty, 0);
59515955 const offset = @intCast(u32, lhs_ty.abiSize(mod));
59525956 try func.store(result_ptr, overflow_bit, Type.initTag(.u1), offset);
......@@ -5955,10 +5959,10 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59555959}
59565960
59575961fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerError!void {
5962 const mod = func.bin_file.base.options.module.?;
59585963 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
59595964
5960 const ty = func.air.typeOfIndex(inst);
5961 const mod = func.bin_file.base.options.module.?;
5965 const ty = func.typeOfIndex(inst);
59625966 if (ty.zigTypeTag(mod) == .Vector) {
59635967 return func.fail("TODO: `@maximum` and `@minimum` for vectors", .{});
59645968 }
......@@ -5986,11 +5990,11 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerE
59865990}
59875991
59885992fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5993 const mod = func.bin_file.base.options.module.?;
59895994 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
59905995 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;
59915996
5992 const ty = func.air.typeOfIndex(inst);
5993 const mod = func.bin_file.base.options.module.?;
5997 const ty = func.typeOfIndex(inst);
59945998 if (ty.zigTypeTag(mod) == .Vector) {
59955999 return func.fail("TODO: `@mulAdd` for vectors", .{});
59966000 }
......@@ -6020,11 +6024,11 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
60206024}
60216025
60226026fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6027 const mod = func.bin_file.base.options.module.?;
60236028 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
60246029
6025 const ty = func.air.typeOf(ty_op.operand);
6026 const result_ty = func.air.typeOfIndex(inst);
6027 const mod = func.bin_file.base.options.module.?;
6030 const ty = func.typeOf(ty_op.operand);
6031 const result_ty = func.typeOfIndex(inst);
60286032 if (ty.zigTypeTag(mod) == .Vector) {
60296033 return func.fail("TODO: `@clz` for vectors", .{});
60306034 }
......@@ -6073,12 +6077,12 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
60736077}
60746078
60756079fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6080 const mod = func.bin_file.base.options.module.?;
60766081 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
60776082
6078 const ty = func.air.typeOf(ty_op.operand);
6079 const result_ty = func.air.typeOfIndex(inst);
6083 const ty = func.typeOf(ty_op.operand);
6084 const result_ty = func.typeOfIndex(inst);
60806085
6081 const mod = func.bin_file.base.options.module.?;
60826086 if (ty.zigTypeTag(mod) == .Vector) {
60836087 return func.fail("TODO: `@ctz` for vectors", .{});
60846088 }
......@@ -6141,7 +6145,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
61416145 if (func.debug_output != .dwarf) return func.finishAir(inst, .none, &.{});
61426146
61436147 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
6144 const ty = func.air.typeOf(pl_op.operand);
6148 const ty = func.typeOf(pl_op.operand);
61456149 const operand = try func.resolveInst(pl_op.operand);
61466150
61476151 log.debug("airDbgVar: %{d}: {}, {}", .{ inst, ty.fmtDebug(), operand });
......@@ -6179,7 +6183,7 @@ fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61796183 const err_union = try func.resolveInst(pl_op.operand);
61806184 const extra = func.air.extraData(Air.Try, pl_op.payload);
61816185 const body = func.air.extra[extra.end..][0..extra.data.body_len];
6182 const err_union_ty = func.air.typeOf(pl_op.operand);
6186 const err_union_ty = func.typeOf(pl_op.operand);
61836187 const result = try lowerTry(func, inst, err_union, body, err_union_ty, false);
61846188 func.finishAir(inst, result, &.{pl_op.operand});
61856189}
......@@ -6189,7 +6193,7 @@ fn airTryPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61896193 const extra = func.air.extraData(Air.TryPtr, ty_pl.payload);
61906194 const err_union_ptr = try func.resolveInst(extra.data.ptr);
61916195 const body = func.air.extra[extra.end..][0..extra.data.body_len];
6192 const err_union_ty = func.air.typeOf(extra.data.ptr).childType();
6196 const err_union_ty = func.typeOf(extra.data.ptr).childType();
61936197 const result = try lowerTry(func, inst, err_union_ptr, body, err_union_ty, true);
61946198 func.finishAir(inst, result, &.{extra.data.ptr});
61956199}
......@@ -6251,11 +6255,11 @@ fn lowerTry(
62516255}
62526256
62536257fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6258 const mod = func.bin_file.base.options.module.?;
62546259 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
62556260
6256 const ty = func.air.typeOfIndex(inst);
6261 const ty = func.typeOfIndex(inst);
62576262 const operand = try func.resolveInst(ty_op.operand);
6258 const mod = func.bin_file.base.options.module.?;
62596263
62606264 if (ty.zigTypeTag(mod) == .Vector) {
62616265 return func.fail("TODO: @byteSwap for vectors", .{});
......@@ -6325,7 +6329,7 @@ fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63256329 const mod = func.bin_file.base.options.module.?;
63266330 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
63276331
6328 const ty = func.air.typeOfIndex(inst);
6332 const ty = func.typeOfIndex(inst);
63296333 const lhs = try func.resolveInst(bin_op.lhs);
63306334 const rhs = try func.resolveInst(bin_op.rhs);
63316335
......@@ -6340,7 +6344,7 @@ fn airDivTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63406344 const mod = func.bin_file.base.options.module.?;
63416345 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
63426346
6343 const ty = func.air.typeOfIndex(inst);
6347 const ty = func.typeOfIndex(inst);
63446348 const lhs = try func.resolveInst(bin_op.lhs);
63456349 const rhs = try func.resolveInst(bin_op.rhs);
63466350
......@@ -6361,7 +6365,7 @@ fn airDivFloor(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63616365 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
63626366
63636367 const mod = func.bin_file.base.options.module.?;
6364 const ty = func.air.typeOfIndex(inst);
6368 const ty = func.typeOfIndex(inst);
63656369 const lhs = try func.resolveInst(bin_op.lhs);
63666370 const rhs = try func.resolveInst(bin_op.rhs);
63676371
......@@ -6512,7 +6516,7 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
65126516 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
65136517
65146518 const mod = func.bin_file.base.options.module.?;
6515 const ty = func.air.typeOfIndex(inst);
6519 const ty = func.typeOfIndex(inst);
65166520 const lhs = try func.resolveInst(bin_op.lhs);
65176521 const rhs = try func.resolveInst(bin_op.rhs);
65186522
......@@ -6626,7 +6630,7 @@ fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66266630 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
66276631
66286632 const mod = func.bin_file.base.options.module.?;
6629 const ty = func.air.typeOfIndex(inst);
6633 const ty = func.typeOfIndex(inst);
66306634 const int_info = ty.intInfo(mod);
66316635 const is_signed = int_info.signedness == .signed;
66326636 if (int_info.bits > 64) {
......@@ -6785,11 +6789,11 @@ fn callIntrinsic(
67856789fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
67866790 const un_op = func.air.instructions.items(.data)[inst].un_op;
67876791 const operand = try func.resolveInst(un_op);
6788 const enum_ty = func.air.typeOf(un_op);
6792 const enum_ty = func.typeOf(un_op);
67896793
67906794 const func_sym_index = try func.getTagNameFunction(enum_ty);
67916795
6792 const result_ptr = try func.allocStack(func.air.typeOfIndex(inst));
6796 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
67936797 try func.lowerToStack(result_ptr);
67946798 try func.emitWValue(operand);
67956799 try func.addLabel(.call, func_sym_index);
......@@ -7061,9 +7065,9 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
70617065 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
70627066 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
70637067
7064 const ptr_ty = func.air.typeOf(extra.ptr);
7068 const ptr_ty = func.typeOf(extra.ptr);
70657069 const ty = ptr_ty.childType();
7066 const result_ty = func.air.typeOfIndex(inst);
7070 const result_ty = func.typeOfIndex(inst);
70677071
70687072 const ptr_operand = try func.resolveInst(extra.ptr);
70697073 const expected_val = try func.resolveInst(extra.expected_value);
......@@ -7133,7 +7137,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
71337137 const mod = func.bin_file.base.options.module.?;
71347138 const atomic_load = func.air.instructions.items(.data)[inst].atomic_load;
71357139 const ptr = try func.resolveInst(atomic_load.ptr);
7136 const ty = func.air.typeOfIndex(inst);
7140 const ty = func.typeOfIndex(inst);
71377141
71387142 if (func.useAtomicFeature()) {
71397143 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(mod)) {
......@@ -7163,7 +7167,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
71637167
71647168 const ptr = try func.resolveInst(pl_op.operand);
71657169 const operand = try func.resolveInst(extra.operand);
7166 const ty = func.air.typeOfIndex(inst);
7170 const ty = func.typeOfIndex(inst);
71677171 const op: std.builtin.AtomicRmwOp = extra.op();
71687172
71697173 if (func.useAtomicFeature()) {
......@@ -7348,7 +7352,7 @@ fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
73487352
73497353 const ptr = try func.resolveInst(bin_op.lhs);
73507354 const operand = try func.resolveInst(bin_op.rhs);
7351 const ptr_ty = func.air.typeOf(bin_op.lhs);
7355 const ptr_ty = func.typeOf(bin_op.lhs);
73527356 const ty = ptr_ty.childType();
73537357
73547358 if (func.useAtomicFeature()) {
......@@ -7380,3 +7384,13 @@ fn airFrameAddress(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
73807384 const result = try WValue.toLocal(.stack, func, Type.usize);
73817385 return func.finishAir(inst, result, &.{});
73827386}
7387
7388fn typeOf(func: *CodeGen, inst: Air.Inst.Ref) Type {
7389 const mod = func.bin_file.base.options.module.?;
7390 return func.air.typeOf(inst, mod.intern_pool);
7391}
7392
7393fn typeOfIndex(func: *CodeGen, inst: Air.Inst.Index) Type {
7394 const mod = func.bin_file.base.options.module.?;
7395 return func.air.typeOfIndex(inst, mod.intern_pool);
7396}
src/arch/x86_64/CodeGen.zig+150-136
......@@ -447,7 +447,7 @@ const InstTracking = struct {
447447 else => unreachable,
448448 }
449449 tracking_log.debug("spill %{d} from {} to {}", .{ inst, self.short, self.long });
450 try function.genCopy(function.air.typeOfIndex(inst), self.long, self.short);
450 try function.genCopy(function.typeOfIndex(inst), self.long, self.short);
451451 }
452452
453453 fn reuseFrame(self: *InstTracking) void {
......@@ -537,7 +537,7 @@ const InstTracking = struct {
537537 inst: Air.Inst.Index,
538538 target: InstTracking,
539539 ) !void {
540 const ty = function.air.typeOfIndex(inst);
540 const ty = function.typeOfIndex(inst);
541541 if ((self.long == .none or self.long == .reserved_frame) and target.long == .load_frame)
542542 try function.genCopy(ty, target.long, self.short);
543543 try function.genCopy(ty, target.short, self.short);
......@@ -1725,6 +1725,8 @@ fn gen(self: *Self) InnerError!void {
17251725}
17261726
17271727fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
1728 const mod = self.bin_file.options.module.?;
1729 const ip = &mod.intern_pool;
17281730 const air_tags = self.air.instructions.items(.tag);
17291731
17301732 for (body) |inst| {
......@@ -1733,7 +1735,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
17331735 try self.mir_to_air_map.put(self.gpa, mir_inst, inst);
17341736 }
17351737
1736 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst)) continue;
1738 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*)) continue;
17371739 wip_mir_log.debug("{}", .{self.fmtAir(inst)});
17381740 verbose_tracking_log.debug("{}", .{self.fmtTracking()});
17391741
......@@ -1919,6 +1921,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
19191921
19201922 .constant => unreachable, // excluded from function bodies
19211923 .const_ty => unreachable, // excluded from function bodies
1924 .interned => unreachable, // excluded from function bodies
19221925 .unreach => if (self.wantSafety()) try self.airTrap() else self.finishAirBookkeeping(),
19231926
19241927 .optional_payload => try self.airOptionalPayload(inst),
......@@ -2255,7 +2258,7 @@ fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {
22552258/// Use a pointer instruction as the basis for allocating stack memory.
22562259fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !FrameIndex {
22572260 const mod = self.bin_file.options.module.?;
2258 const ptr_ty = self.air.typeOfIndex(inst);
2261 const ptr_ty = self.typeOfIndex(inst);
22592262 const val_ty = ptr_ty.childType();
22602263 return self.allocFrameIndex(FrameAlloc.init(.{
22612264 .size = math.cast(u32, val_ty.abiSize(mod)) orelse {
......@@ -2266,7 +2269,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !FrameIndex {
22662269}
22672270
22682271fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {
2269 return self.allocRegOrMemAdvanced(self.air.typeOfIndex(inst), inst, reg_ok);
2272 return self.allocRegOrMemAdvanced(self.typeOfIndex(inst), inst, reg_ok);
22702273}
22712274
22722275fn allocTempRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool) !MCValue {
......@@ -2485,7 +2488,7 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
24852488 .load_frame => .{ .register_offset = .{
24862489 .reg = (try self.copyToRegisterWithInstTracking(
24872490 inst,
2488 self.air.typeOfIndex(inst),
2491 self.typeOfIndex(inst),
24892492 self.ret_mcv.long,
24902493 )).register,
24912494 .off = self.ret_mcv.short.indirect.off,
......@@ -2496,9 +2499,9 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
24962499
24972500fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
24982501 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2499 const dst_ty = self.air.typeOfIndex(inst);
2502 const dst_ty = self.typeOfIndex(inst);
25002503 const dst_bits = dst_ty.floatBits(self.target.*);
2501 const src_ty = self.air.typeOf(ty_op.operand);
2504 const src_ty = self.typeOf(ty_op.operand);
25022505 const src_bits = src_ty.floatBits(self.target.*);
25032506
25042507 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -2562,9 +2565,9 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
25622565
25632566fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
25642567 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2565 const dst_ty = self.air.typeOfIndex(inst);
2568 const dst_ty = self.typeOfIndex(inst);
25662569 const dst_bits = dst_ty.floatBits(self.target.*);
2567 const src_ty = self.air.typeOf(ty_op.operand);
2570 const src_ty = self.typeOf(ty_op.operand);
25682571 const src_bits = src_ty.floatBits(self.target.*);
25692572
25702573 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -2625,10 +2628,10 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
26252628 const mod = self.bin_file.options.module.?;
26262629 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
26272630 const result: MCValue = result: {
2628 const src_ty = self.air.typeOf(ty_op.operand);
2631 const src_ty = self.typeOf(ty_op.operand);
26292632 const src_int_info = src_ty.intInfo(mod);
26302633
2631 const dst_ty = self.air.typeOfIndex(inst);
2634 const dst_ty = self.typeOfIndex(inst);
26322635 const dst_int_info = dst_ty.intInfo(mod);
26332636 const abi_size = @intCast(u32, dst_ty.abiSize(mod));
26342637
......@@ -2707,9 +2710,9 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27072710 const mod = self.bin_file.options.module.?;
27082711 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
27092712
2710 const dst_ty = self.air.typeOfIndex(inst);
2713 const dst_ty = self.typeOfIndex(inst);
27112714 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));
2712 const src_ty = self.air.typeOf(ty_op.operand);
2715 const src_ty = self.typeOf(ty_op.operand);
27132716 const src_abi_size = @intCast(u32, src_ty.abiSize(mod));
27142717
27152718 const result = result: {
......@@ -2818,7 +2821,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
28182821
28192822fn airBoolToInt(self: *Self, inst: Air.Inst.Index) !void {
28202823 const un_op = self.air.instructions.items(.data)[inst].un_op;
2821 const ty = self.air.typeOfIndex(inst);
2824 const ty = self.typeOfIndex(inst);
28222825
28232826 const operand = try self.resolveInst(un_op);
28242827 const dst_mcv = if (self.reuseOperand(inst, un_op, 0, operand))
......@@ -2834,11 +2837,11 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
28342837 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
28352838 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
28362839
2837 const slice_ty = self.air.typeOfIndex(inst);
2840 const slice_ty = self.typeOfIndex(inst);
28382841 const ptr = try self.resolveInst(bin_op.lhs);
2839 const ptr_ty = self.air.typeOf(bin_op.lhs);
2842 const ptr_ty = self.typeOf(bin_op.lhs);
28402843 const len = try self.resolveInst(bin_op.rhs);
2841 const len_ty = self.air.typeOf(bin_op.rhs);
2844 const len_ty = self.typeOf(bin_op.rhs);
28422845
28432846 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(slice_ty, mod));
28442847 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
......@@ -2877,7 +2880,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
28772880 const air_tag = self.air.instructions.items(.tag);
28782881 const air_data = self.air.instructions.items(.data);
28792882
2880 const dst_ty = self.air.typeOf(dst_air);
2883 const dst_ty = self.typeOf(dst_air);
28812884 const dst_info = dst_ty.intInfo(mod);
28822885 if (Air.refToIndex(dst_air)) |inst| {
28832886 switch (air_tag[inst]) {
......@@ -2889,7 +2892,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
28892892 @boolToInt(src_int.positive and dst_info.signedness == .signed);
28902893 },
28912894 .intcast => {
2892 const src_ty = self.air.typeOf(air_data[inst].ty_op.operand);
2895 const src_ty = self.typeOf(air_data[inst].ty_op.operand);
28932896 const src_info = src_ty.intInfo(mod);
28942897 return @min(switch (src_info.signedness) {
28952898 .signed => switch (dst_info.signedness) {
......@@ -2913,7 +2916,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
29132916 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
29142917 const result = result: {
29152918 const tag = self.air.instructions.items(.tag)[inst];
2916 const dst_ty = self.air.typeOfIndex(inst);
2919 const dst_ty = self.typeOfIndex(inst);
29172920 switch (dst_ty.zigTypeTag(mod)) {
29182921 .Float, .Vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs),
29192922 else => {},
......@@ -2942,7 +2945,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
29422945fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
29432946 const mod = self.bin_file.options.module.?;
29442947 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2945 const ty = self.air.typeOf(bin_op.lhs);
2948 const ty = self.typeOf(bin_op.lhs);
29462949
29472950 const lhs_mcv = try self.resolveInst(bin_op.lhs);
29482951 const dst_mcv = if (lhs_mcv.isRegister() and self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv))
......@@ -3021,7 +3024,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
30213024fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
30223025 const mod = self.bin_file.options.module.?;
30233026 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
3024 const ty = self.air.typeOf(bin_op.lhs);
3027 const ty = self.typeOf(bin_op.lhs);
30253028
30263029 const lhs_mcv = try self.resolveInst(bin_op.lhs);
30273030 const dst_mcv = if (lhs_mcv.isRegister() and self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv))
......@@ -3093,7 +3096,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
30933096fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
30943097 const mod = self.bin_file.options.module.?;
30953098 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
3096 const ty = self.air.typeOf(bin_op.lhs);
3099 const ty = self.typeOf(bin_op.lhs);
30973100
30983101 try self.spillRegisters(&.{ .rax, .rdx });
30993102 const reg_locks = self.register_manager.lockRegs(2, .{ .rax, .rdx });
......@@ -3151,7 +3154,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
31513154 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
31523155 const result: MCValue = result: {
31533156 const tag = self.air.instructions.items(.tag)[inst];
3154 const ty = self.air.typeOf(bin_op.lhs);
3157 const ty = self.typeOf(bin_op.lhs);
31553158 switch (ty.zigTypeTag(mod)) {
31563159 .Vector => return self.fail("TODO implement add/sub with overflow for Vector type", .{}),
31573160 .Int => {
......@@ -3168,7 +3171,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
31683171 .signed => .o,
31693172 };
31703173
3171 const tuple_ty = self.air.typeOfIndex(inst);
3174 const tuple_ty = self.typeOfIndex(inst);
31723175 if (int_info.bits >= 8 and math.isPowerOfTwo(int_info.bits)) {
31733176 switch (partial_mcv) {
31743177 .register => |reg| {
......@@ -3211,8 +3214,8 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
32113214 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
32123215 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
32133216 const result: MCValue = result: {
3214 const lhs_ty = self.air.typeOf(bin_op.lhs);
3215 const rhs_ty = self.air.typeOf(bin_op.rhs);
3217 const lhs_ty = self.typeOf(bin_op.lhs);
3218 const rhs_ty = self.typeOf(bin_op.rhs);
32163219 switch (lhs_ty.zigTypeTag(mod)) {
32173220 .Vector => return self.fail("TODO implement shl with overflow for Vector type", .{}),
32183221 .Int => {
......@@ -3241,7 +3244,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
32413244 try self.genBinOpMir(.{ ._, .cmp }, lhs_ty, tmp_mcv, lhs);
32423245 const cc = Condition.ne;
32433246
3244 const tuple_ty = self.air.typeOfIndex(inst);
3247 const tuple_ty = self.typeOfIndex(inst);
32453248 if (int_info.bits >= 8 and math.isPowerOfTwo(int_info.bits)) {
32463249 switch (partial_mcv) {
32473250 .register => |reg| {
......@@ -3349,7 +3352,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
33493352 const mod = self.bin_file.options.module.?;
33503353 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
33513354 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3352 const dst_ty = self.air.typeOf(bin_op.lhs);
3355 const dst_ty = self.typeOf(bin_op.lhs);
33533356 const result: MCValue = switch (dst_ty.zigTypeTag(mod)) {
33543357 .Vector => return self.fail("TODO implement mul_with_overflow for Vector type", .{}),
33553358 .Int => result: {
......@@ -3370,7 +3373,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
33703373 const lhs = try self.resolveInst(bin_op.lhs);
33713374 const rhs = try self.resolveInst(bin_op.rhs);
33723375
3373 const tuple_ty = self.air.typeOfIndex(inst);
3376 const tuple_ty = self.typeOfIndex(inst);
33743377 const extra_bits = if (dst_info.bits <= 64)
33753378 self.regExtraBits(dst_ty)
33763379 else
......@@ -3525,8 +3528,8 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
35253528 try self.register_manager.getReg(.rcx, null);
35263529 const lhs = try self.resolveInst(bin_op.lhs);
35273530 const rhs = try self.resolveInst(bin_op.rhs);
3528 const lhs_ty = self.air.typeOf(bin_op.lhs);
3529 const rhs_ty = self.air.typeOf(bin_op.rhs);
3531 const lhs_ty = self.typeOf(bin_op.lhs);
3532 const rhs_ty = self.typeOf(bin_op.rhs);
35303533
35313534 const result = try self.genShiftBinOp(tag, inst, lhs, rhs, lhs_ty, rhs_ty);
35323535
......@@ -3543,7 +3546,7 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
35433546fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
35443547 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
35453548 const result: MCValue = result: {
3546 const pl_ty = self.air.typeOfIndex(inst);
3549 const pl_ty = self.typeOfIndex(inst);
35473550 const opt_mcv = try self.resolveInst(ty_op.operand);
35483551
35493552 if (self.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {
......@@ -3568,7 +3571,7 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
35683571fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
35693572 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
35703573
3571 const dst_ty = self.air.typeOfIndex(inst);
3574 const dst_ty = self.typeOfIndex(inst);
35723575 const opt_mcv = try self.resolveInst(ty_op.operand);
35733576
35743577 const dst_mcv = if (self.reuseOperand(inst, ty_op.operand, 0, opt_mcv))
......@@ -3582,8 +3585,8 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
35823585 const mod = self.bin_file.options.module.?;
35833586 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
35843587 const result = result: {
3585 const dst_ty = self.air.typeOfIndex(inst);
3586 const src_ty = self.air.typeOf(ty_op.operand);
3588 const dst_ty = self.typeOfIndex(inst);
3589 const src_ty = self.typeOf(ty_op.operand);
35873590 const opt_ty = src_ty.childType();
35883591 const src_mcv = try self.resolveInst(ty_op.operand);
35893592
......@@ -3615,7 +3618,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
36153618fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
36163619 const mod = self.bin_file.options.module.?;
36173620 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
3618 const err_union_ty = self.air.typeOf(ty_op.operand);
3621 const err_union_ty = self.typeOf(ty_op.operand);
36193622 const err_ty = err_union_ty.errorUnionSet();
36203623 const payload_ty = err_union_ty.errorUnionPayload();
36213624 const operand = try self.resolveInst(ty_op.operand);
......@@ -3662,7 +3665,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
36623665
36633666fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
36643667 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
3665 const err_union_ty = self.air.typeOf(ty_op.operand);
3668 const err_union_ty = self.typeOf(ty_op.operand);
36663669 const operand = try self.resolveInst(ty_op.operand);
36673670 const result = try self.genUnwrapErrorUnionPayloadMir(inst, err_union_ty, operand);
36683671 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -3720,7 +3723,7 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
37203723 const mod = self.bin_file.options.module.?;
37213724 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
37223725
3723 const src_ty = self.air.typeOf(ty_op.operand);
3726 const src_ty = self.typeOf(ty_op.operand);
37243727 const src_mcv = try self.resolveInst(ty_op.operand);
37253728 const src_reg = switch (src_mcv) {
37263729 .register => |reg| reg,
......@@ -3756,7 +3759,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
37563759 const mod = self.bin_file.options.module.?;
37573760 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
37583761
3759 const src_ty = self.air.typeOf(ty_op.operand);
3762 const src_ty = self.typeOf(ty_op.operand);
37603763 const src_mcv = try self.resolveInst(ty_op.operand);
37613764 const src_reg = switch (src_mcv) {
37623765 .register => |reg| reg,
......@@ -3765,7 +3768,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
37653768 const src_lock = self.register_manager.lockRegAssumeUnused(src_reg);
37663769 defer self.register_manager.unlockReg(src_lock);
37673770
3768 const dst_ty = self.air.typeOfIndex(inst);
3771 const dst_ty = self.typeOfIndex(inst);
37693772 const dst_reg = if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
37703773 src_reg
37713774 else
......@@ -3791,7 +3794,7 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
37913794 const mod = self.bin_file.options.module.?;
37923795 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
37933796 const result: MCValue = result: {
3794 const src_ty = self.air.typeOf(ty_op.operand);
3797 const src_ty = self.typeOf(ty_op.operand);
37953798 const src_mcv = try self.resolveInst(ty_op.operand);
37963799 const src_reg = switch (src_mcv) {
37973800 .register => |reg| reg,
......@@ -3816,7 +3819,7 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
38163819
38173820 if (self.liveness.isUnused(inst)) break :result .unreach;
38183821
3819 const dst_ty = self.air.typeOfIndex(inst);
3822 const dst_ty = self.typeOfIndex(inst);
38203823 const dst_reg = if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
38213824 src_reg
38223825 else
......@@ -3856,10 +3859,10 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
38563859 const mod = self.bin_file.options.module.?;
38573860 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
38583861 const result: MCValue = result: {
3859 const pl_ty = self.air.typeOf(ty_op.operand);
3862 const pl_ty = self.typeOf(ty_op.operand);
38603863 if (!pl_ty.hasRuntimeBits(mod)) break :result .{ .immediate = 1 };
38613864
3862 const opt_ty = self.air.typeOfIndex(inst);
3865 const opt_ty = self.typeOfIndex(inst);
38633866 const pl_mcv = try self.resolveInst(ty_op.operand);
38643867 const same_repr = opt_ty.optionalReprIsPayload(mod);
38653868 if (same_repr and self.reuseOperand(inst, ty_op.operand, 0, pl_mcv)) break :result pl_mcv;
......@@ -3952,7 +3955,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
39523955 if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv;
39533956
39543957 const dst_mcv = try self.allocRegOrMem(inst, true);
3955 const dst_ty = self.air.typeOfIndex(inst);
3958 const dst_ty = self.typeOfIndex(inst);
39563959 try self.genCopy(dst_ty, dst_mcv, src_mcv);
39573960 break :result dst_mcv;
39583961 };
......@@ -3980,7 +3983,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
39803983 const mod = self.bin_file.options.module.?;
39813984 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
39823985
3983 const src_ty = self.air.typeOf(ty_op.operand);
3986 const src_ty = self.typeOf(ty_op.operand);
39843987 const src_mcv = try self.resolveInst(ty_op.operand);
39853988 const src_reg = switch (src_mcv) {
39863989 .register => |reg| reg,
......@@ -3989,7 +3992,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
39893992 const src_lock = self.register_manager.lockRegAssumeUnused(src_reg);
39903993 defer self.register_manager.unlockReg(src_lock);
39913994
3992 const dst_ty = self.air.typeOfIndex(inst);
3995 const dst_ty = self.typeOfIndex(inst);
39933996 const dst_reg = if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
39943997 src_reg
39953998 else
......@@ -4014,7 +4017,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
40144017fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
40154018 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
40164019
4017 const dst_ty = self.air.typeOfIndex(inst);
4020 const dst_ty = self.typeOfIndex(inst);
40184021 const opt_mcv = try self.resolveInst(ty_op.operand);
40194022
40204023 const dst_mcv = if (self.reuseOperand(inst, ty_op.operand, 0, opt_mcv))
......@@ -4046,7 +4049,7 @@ fn elemOffset(self: *Self, index_ty: Type, index: MCValue, elem_size: u64) !Regi
40464049
40474050fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
40484051 const mod = self.bin_file.options.module.?;
4049 const slice_ty = self.air.typeOf(lhs);
4052 const slice_ty = self.typeOf(lhs);
40504053 const slice_mcv = try self.resolveInst(lhs);
40514054 const slice_mcv_lock: ?RegisterLock = switch (slice_mcv) {
40524055 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
......@@ -4059,7 +4062,7 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
40594062 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
40604063 const slice_ptr_field_type = slice_ty.slicePtrFieldType(&buf);
40614064
4062 const index_ty = self.air.typeOf(rhs);
4065 const index_ty = self.typeOf(rhs);
40634066 const index_mcv = try self.resolveInst(rhs);
40644067 const index_mcv_lock: ?RegisterLock = switch (index_mcv) {
40654068 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
......@@ -4083,7 +4086,7 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
40834086
40844087fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
40854088 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
4086 const slice_ty = self.air.typeOf(bin_op.lhs);
4089 const slice_ty = self.typeOf(bin_op.lhs);
40874090
40884091 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
40894092 const slice_ptr_field_type = slice_ty.slicePtrFieldType(&buf);
......@@ -4105,7 +4108,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
41054108 const mod = self.bin_file.options.module.?;
41064109 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
41074110
4108 const array_ty = self.air.typeOf(bin_op.lhs);
4111 const array_ty = self.typeOf(bin_op.lhs);
41094112 const array = try self.resolveInst(bin_op.lhs);
41104113 const array_lock: ?RegisterLock = switch (array) {
41114114 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
......@@ -4116,7 +4119,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
41164119 const elem_ty = array_ty.childType();
41174120 const elem_abi_size = elem_ty.abiSize(mod);
41184121
4119 const index_ty = self.air.typeOf(bin_op.rhs);
4122 const index_ty = self.typeOf(bin_op.rhs);
41204123 const index = try self.resolveInst(bin_op.rhs);
41214124 const index_lock: ?RegisterLock = switch (index) {
41224125 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
......@@ -4170,14 +4173,14 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
41704173fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
41714174 const mod = self.bin_file.options.module.?;
41724175 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
4173 const ptr_ty = self.air.typeOf(bin_op.lhs);
4176 const ptr_ty = self.typeOf(bin_op.lhs);
41744177
41754178 // this is identical to the `airPtrElemPtr` codegen expect here an
41764179 // additional `mov` is needed at the end to get the actual value
41774180
41784181 const elem_ty = ptr_ty.elemType2(mod);
41794182 const elem_abi_size = @intCast(u32, elem_ty.abiSize(mod));
4180 const index_ty = self.air.typeOf(bin_op.rhs);
4183 const index_ty = self.typeOf(bin_op.rhs);
41814184 const index_mcv = try self.resolveInst(bin_op.rhs);
41824185 const index_lock = switch (index_mcv) {
41834186 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
......@@ -4218,7 +4221,7 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
42184221 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
42194222 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
42204223
4221 const ptr_ty = self.air.typeOf(extra.lhs);
4224 const ptr_ty = self.typeOf(extra.lhs);
42224225 const ptr = try self.resolveInst(extra.lhs);
42234226 const ptr_lock: ?RegisterLock = switch (ptr) {
42244227 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
......@@ -4228,7 +4231,7 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
42284231
42294232 const elem_ty = ptr_ty.elemType2(mod);
42304233 const elem_abi_size = elem_ty.abiSize(mod);
4231 const index_ty = self.air.typeOf(extra.rhs);
4234 const index_ty = self.typeOf(extra.rhs);
42324235 const index = try self.resolveInst(extra.rhs);
42334236 const index_lock: ?RegisterLock = switch (index) {
42344237 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
......@@ -4249,9 +4252,9 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
42494252fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
42504253 const mod = self.bin_file.options.module.?;
42514254 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
4252 const ptr_union_ty = self.air.typeOf(bin_op.lhs);
4255 const ptr_union_ty = self.typeOf(bin_op.lhs);
42534256 const union_ty = ptr_union_ty.childType();
4254 const tag_ty = self.air.typeOf(bin_op.rhs);
4257 const tag_ty = self.typeOf(bin_op.rhs);
42554258 const layout = union_ty.unionGetLayout(mod);
42564259
42574260 if (layout.tag_size == 0) {
......@@ -4296,8 +4299,8 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
42964299 const mod = self.bin_file.options.module.?;
42974300 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
42984301
4299 const tag_ty = self.air.typeOfIndex(inst);
4300 const union_ty = self.air.typeOf(ty_op.operand);
4302 const tag_ty = self.typeOfIndex(inst);
4303 const union_ty = self.typeOf(ty_op.operand);
43014304 const layout = union_ty.unionGetLayout(mod);
43024305
43034306 if (layout.tag_size == 0) {
......@@ -4350,8 +4353,8 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
43504353 const mod = self.bin_file.options.module.?;
43514354 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
43524355 const result = result: {
4353 const dst_ty = self.air.typeOfIndex(inst);
4354 const src_ty = self.air.typeOf(ty_op.operand);
4356 const dst_ty = self.typeOfIndex(inst);
4357 const src_ty = self.typeOf(ty_op.operand);
43554358
43564359 const src_mcv = try self.resolveInst(ty_op.operand);
43574360 const mat_src_mcv = switch (src_mcv) {
......@@ -4479,8 +4482,8 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
44794482 const mod = self.bin_file.options.module.?;
44804483 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
44814484 const result = result: {
4482 const dst_ty = self.air.typeOfIndex(inst);
4483 const src_ty = self.air.typeOf(ty_op.operand);
4485 const dst_ty = self.typeOfIndex(inst);
4486 const src_ty = self.typeOf(ty_op.operand);
44844487 const src_bits = src_ty.bitSize(mod);
44854488
44864489 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -4575,7 +4578,7 @@ fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
45754578 const mod = self.bin_file.options.module.?;
45764579 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
45774580 const result: MCValue = result: {
4578 const src_ty = self.air.typeOf(ty_op.operand);
4581 const src_ty = self.typeOf(ty_op.operand);
45794582 const src_abi_size = @intCast(u32, src_ty.abiSize(mod));
45804583 const src_mcv = try self.resolveInst(ty_op.operand);
45814584
......@@ -4745,7 +4748,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
47454748 const mod = self.bin_file.options.module.?;
47464749 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
47474750
4748 const src_ty = self.air.typeOf(ty_op.operand);
4751 const src_ty = self.typeOf(ty_op.operand);
47494752 const src_mcv = try self.resolveInst(ty_op.operand);
47504753
47514754 const dst_mcv = try self.byteSwap(inst, src_ty, src_mcv, true);
......@@ -4766,7 +4769,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
47664769 const mod = self.bin_file.options.module.?;
47674770 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
47684771
4769 const src_ty = self.air.typeOf(ty_op.operand);
4772 const src_ty = self.typeOf(ty_op.operand);
47704773 const src_abi_size = @intCast(u32, src_ty.abiSize(mod));
47714774 const src_mcv = try self.resolveInst(ty_op.operand);
47724775
......@@ -4876,12 +4879,12 @@ fn airFloatSign(self: *Self, inst: Air.Inst.Index) !void {
48764879 const mod = self.bin_file.options.module.?;
48774880 const tag = self.air.instructions.items(.tag)[inst];
48784881 const un_op = self.air.instructions.items(.data)[inst].un_op;
4879 const ty = self.air.typeOf(un_op);
4882 const ty = self.typeOf(un_op);
48804883 const abi_size: u32 = switch (ty.abiSize(mod)) {
48814884 1...16 => 16,
48824885 17...32 => 32,
48834886 else => return self.fail("TODO implement airFloatSign for {}", .{
4884 ty.fmt(self.bin_file.options.module.?),
4887 ty.fmt(mod),
48854888 }),
48864889 };
48874890 const scalar_bits = ty.scalarType(mod).floatBits(self.target.*);
......@@ -5005,7 +5008,7 @@ fn airFloatSign(self: *Self, inst: Air.Inst.Index) !void {
50055008
50065009fn airRound(self: *Self, inst: Air.Inst.Index, mode: u4) !void {
50075010 const un_op = self.air.instructions.items(.data)[inst].un_op;
5008 const ty = self.air.typeOf(un_op);
5011 const ty = self.typeOf(un_op);
50095012
50105013 const src_mcv = try self.resolveInst(un_op);
50115014 const dst_mcv = if (src_mcv.isRegister() and self.reuseOperand(inst, un_op, 0, src_mcv))
......@@ -5093,7 +5096,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: u4
50935096fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
50945097 const mod = self.bin_file.options.module.?;
50955098 const un_op = self.air.instructions.items(.data)[inst].un_op;
5096 const ty = self.air.typeOf(un_op);
5099 const ty = self.typeOf(un_op);
50975100 const abi_size = @intCast(u32, ty.abiSize(mod));
50985101
50995102 const src_mcv = try self.resolveInst(un_op);
......@@ -5399,7 +5402,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerErro
53995402fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
54005403 const mod = self.bin_file.options.module.?;
54015404 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
5402 const elem_ty = self.air.typeOfIndex(inst);
5405 const elem_ty = self.typeOfIndex(inst);
54035406 const result: MCValue = result: {
54045407 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none;
54055408
......@@ -5407,7 +5410,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
54075410 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });
54085411 defer for (reg_locks) |lock| self.register_manager.unlockReg(lock);
54095412
5410 const ptr_ty = self.air.typeOf(ty_op.operand);
5413 const ptr_ty = self.typeOf(ty_op.operand);
54115414 const elem_size = elem_ty.abiSize(mod);
54125415
54135416 const elem_rc = regClassForType(elem_ty, mod);
......@@ -5548,7 +5551,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
55485551 }
55495552 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
55505553 const ptr_mcv = try self.resolveInst(bin_op.lhs);
5551 const ptr_ty = self.air.typeOf(bin_op.lhs);
5554 const ptr_ty = self.typeOf(bin_op.lhs);
55525555 const src_mcv = try self.resolveInst(bin_op.rhs);
55535556 if (ptr_ty.ptrInfo().data.host_size > 0) {
55545557 try self.packedStore(ptr_ty, ptr_mcv, src_mcv);
......@@ -5573,8 +5576,8 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
55735576
55745577fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
55755578 const mod = self.bin_file.options.module.?;
5576 const ptr_field_ty = self.air.typeOfIndex(inst);
5577 const ptr_container_ty = self.air.typeOf(operand);
5579 const ptr_field_ty = self.typeOfIndex(inst);
5580 const ptr_container_ty = self.typeOf(operand);
55785581 const container_ty = ptr_container_ty.childType();
55795582 const field_offset = @intCast(i32, switch (container_ty.containerLayout()) {
55805583 .Auto, .Extern => container_ty.structFieldOffset(index, mod),
......@@ -5602,7 +5605,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
56025605 const operand = extra.struct_operand;
56035606 const index = extra.field_index;
56045607
5605 const container_ty = self.air.typeOf(operand);
5608 const container_ty = self.typeOf(operand);
56065609 const container_rc = regClassForType(container_ty, mod);
56075610 const field_ty = container_ty.structFieldType(index);
56085611 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none;
......@@ -5756,7 +5759,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
57565759 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
57575760 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
57585761
5759 const inst_ty = self.air.typeOfIndex(inst);
5762 const inst_ty = self.typeOfIndex(inst);
57605763 const parent_ty = inst_ty.childType();
57615764 const field_offset = @intCast(i32, parent_ty.structFieldOffset(extra.field_index, mod));
57625765
......@@ -5772,7 +5775,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
57725775
57735776fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air: Air.Inst.Ref) !MCValue {
57745777 const mod = self.bin_file.options.module.?;
5775 const src_ty = self.air.typeOf(src_air);
5778 const src_ty = self.typeOf(src_air);
57765779 const src_mcv = try self.resolveInst(src_air);
57775780 if (src_ty.zigTypeTag(mod) == .Vector) {
57785781 return self.fail("TODO implement genUnOp for {}", .{src_ty.fmt(self.bin_file.options.module.?)});
......@@ -6358,8 +6361,8 @@ fn genBinOp(
63586361 rhs_air: Air.Inst.Ref,
63596362) !MCValue {
63606363 const mod = self.bin_file.options.module.?;
6361 const lhs_ty = self.air.typeOf(lhs_air);
6362 const rhs_ty = self.air.typeOf(rhs_air);
6364 const lhs_ty = self.typeOf(lhs_air);
6365 const rhs_ty = self.typeOf(rhs_air);
63636366 const abi_size = @intCast(u32, lhs_ty.abiSize(mod));
63646367
63656368 const maybe_mask_reg = switch (air_tag) {
......@@ -7918,6 +7921,7 @@ fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: M
79187921}
79197922
79207923fn airArg(self: *Self, inst: Air.Inst.Index) !void {
7924 const mod = self.bin_file.options.module.?;
79217925 // skip zero-bit arguments as they don't have a corresponding arg instruction
79227926 var arg_index = self.arg_index;
79237927 while (self.args[arg_index] == .none) arg_index += 1;
......@@ -7931,9 +7935,9 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
79317935 else => return self.fail("TODO implement arg for {}", .{dst_mcv}),
79327936 }
79337937
7934 const ty = self.air.typeOfIndex(inst);
7938 const ty = self.typeOfIndex(inst);
79357939 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;
7936 const name = self.owner.mod_fn.getParamName(self.bin_file.options.module.?, src_index);
7940 const name = self.owner.mod_fn.getParamName(mod, src_index);
79377941 try self.genArgDbgInfo(ty, name, dst_mcv);
79387942
79397943 break :result dst_mcv;
......@@ -8050,7 +8054,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
80508054 const callee = pl_op.operand;
80518055 const extra = self.air.extraData(Air.Call, pl_op.payload);
80528056 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);
8053 const ty = self.air.typeOf(callee);
8057 const ty = self.typeOf(callee);
80548058
80558059 const fn_ty = switch (ty.zigTypeTag(mod)) {
80568060 .Fn => ty,
......@@ -8085,7 +8089,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
80858089 else => unreachable,
80868090 }
80878091 for (args, info.args) |arg, mc_arg| {
8088 const arg_ty = self.air.typeOf(arg);
8092 const arg_ty = self.typeOf(arg);
80898093 const arg_mcv = try self.resolveInst(arg);
80908094 switch (mc_arg) {
80918095 .none => {},
......@@ -8112,7 +8116,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
81128116 defer if (ret_lock) |lock| self.register_manager.unlockReg(lock);
81138117
81148118 for (args, info.args) |arg, mc_arg| {
8115 const arg_ty = self.air.typeOf(arg);
8119 const arg_ty = self.typeOf(arg);
81168120 const arg_mcv = try self.resolveInst(arg);
81178121 switch (mc_arg) {
81188122 .none, .load_frame => {},
......@@ -8241,7 +8245,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
82418245fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
82428246 const un_op = self.air.instructions.items(.data)[inst].un_op;
82438247 const ptr = try self.resolveInst(un_op);
8244 const ptr_ty = self.air.typeOf(un_op);
8248 const ptr_ty = self.typeOf(un_op);
82458249 switch (self.ret_mcv.short) {
82468250 .none => {},
82478251 .register => try self.load(self.ret_mcv.short, ptr_ty, ptr),
......@@ -8258,7 +8262,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
82588262fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
82598263 const mod = self.bin_file.options.module.?;
82608264 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
8261 const ty = self.air.typeOf(bin_op.lhs);
8265 const ty = self.typeOf(bin_op.lhs);
82628266
82638267 try self.spillEflagsIfOccupied();
82648268 self.eflags_inst = inst;
......@@ -8476,7 +8480,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
84768480 try self.spillEflagsIfOccupied();
84778481 self.eflags_inst = inst;
84788482
8479 const op_ty = self.air.typeOf(un_op);
8483 const op_ty = self.typeOf(un_op);
84808484 const op_abi_size = @intCast(u32, op_ty.abiSize(mod));
84818485 const op_mcv = try self.resolveInst(un_op);
84828486 const dst_reg = switch (op_mcv) {
......@@ -8496,7 +8500,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
84968500 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
84978501 const extra = self.air.extraData(Air.Try, pl_op.payload);
84988502 const body = self.air.extra[extra.end..][0..extra.data.body_len];
8499 const err_union_ty = self.air.typeOf(pl_op.operand);
8503 const err_union_ty = self.typeOf(pl_op.operand);
85008504 const result = try self.genTry(inst, pl_op.operand, body, err_union_ty, false);
85018505 return self.finishAir(inst, result, .{ .none, .none, .none });
85028506}
......@@ -8505,7 +8509,7 @@ fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {
85058509 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
85068510 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
85078511 const body = self.air.extra[extra.end..][0..extra.data.body_len];
8508 const err_union_ty = self.air.typeOf(extra.data.ptr).childType();
8512 const err_union_ty = self.typeOf(extra.data.ptr).childType();
85098513 const result = try self.genTry(inst, extra.data.ptr, body, err_union_ty, true);
85108514 return self.finishAir(inst, result, .{ .none, .none, .none });
85118515}
......@@ -8584,7 +8588,7 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
85848588fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
85858589 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
85868590 const operand = pl_op.operand;
8587 const ty = self.air.typeOf(operand);
8591 const ty = self.typeOf(operand);
85888592 const mcv = try self.resolveInst(operand);
85898593
85908594 const name = self.air.nullTerminatedString(pl_op.payload);
......@@ -8626,7 +8630,7 @@ fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !u32 {
86268630fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
86278631 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
86288632 const cond = try self.resolveInst(pl_op.operand);
8629 const cond_ty = self.air.typeOf(pl_op.operand);
8633 const cond_ty = self.typeOf(pl_op.operand);
86308634 const extra = self.air.extraData(Air.CondBr, pl_op.payload);
86318635 const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len];
86328636 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
......@@ -8871,7 +8875,7 @@ fn isNonErr(self: *Self, inst: Air.Inst.Index, ty: Type, operand: MCValue) !MCVa
88718875fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
88728876 const un_op = self.air.instructions.items(.data)[inst].un_op;
88738877 const operand = try self.resolveInst(un_op);
8874 const ty = self.air.typeOf(un_op);
8878 const ty = self.typeOf(un_op);
88758879 const result = try self.isNull(inst, ty, operand);
88768880 return self.finishAir(inst, result, .{ un_op, .none, .none });
88778881}
......@@ -8879,7 +8883,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
88798883fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
88808884 const un_op = self.air.instructions.items(.data)[inst].un_op;
88818885 const operand = try self.resolveInst(un_op);
8882 const ty = self.air.typeOf(un_op);
8886 const ty = self.typeOf(un_op);
88838887 const result = try self.isNullPtr(inst, ty, operand);
88848888 return self.finishAir(inst, result, .{ un_op, .none, .none });
88858889}
......@@ -8887,7 +8891,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
88878891fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
88888892 const un_op = self.air.instructions.items(.data)[inst].un_op;
88898893 const operand = try self.resolveInst(un_op);
8890 const ty = self.air.typeOf(un_op);
8894 const ty = self.typeOf(un_op);
88918895 const result = switch (try self.isNull(inst, ty, operand)) {
88928896 .eflags => |cc| .{ .eflags = cc.negate() },
88938897 else => unreachable,
......@@ -8898,7 +8902,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
88988902fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
88998903 const un_op = self.air.instructions.items(.data)[inst].un_op;
89008904 const operand = try self.resolveInst(un_op);
8901 const ty = self.air.typeOf(un_op);
8905 const ty = self.typeOf(un_op);
89028906 const result = switch (try self.isNullPtr(inst, ty, operand)) {
89038907 .eflags => |cc| .{ .eflags = cc.negate() },
89048908 else => unreachable,
......@@ -8909,7 +8913,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
89098913fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
89108914 const un_op = self.air.instructions.items(.data)[inst].un_op;
89118915 const operand = try self.resolveInst(un_op);
8912 const ty = self.air.typeOf(un_op);
8916 const ty = self.typeOf(un_op);
89138917 const result = try self.isErr(inst, ty, operand);
89148918 return self.finishAir(inst, result, .{ un_op, .none, .none });
89158919}
......@@ -8932,7 +8936,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
89328936 break :blk try self.allocRegOrMem(inst, true);
89338937 }
89348938 };
8935 const ptr_ty = self.air.typeOf(un_op);
8939 const ptr_ty = self.typeOf(un_op);
89368940 try self.load(operand, ptr_ty, operand_ptr);
89378941
89388942 const result = try self.isErr(inst, ptr_ty.childType(), operand);
......@@ -8943,7 +8947,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
89438947fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
89448948 const un_op = self.air.instructions.items(.data)[inst].un_op;
89458949 const operand = try self.resolveInst(un_op);
8946 const ty = self.air.typeOf(un_op);
8950 const ty = self.typeOf(un_op);
89478951 const result = try self.isNonErr(inst, ty, operand);
89488952 return self.finishAir(inst, result, .{ un_op, .none, .none });
89498953}
......@@ -8966,7 +8970,7 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
89668970 break :blk try self.allocRegOrMem(inst, true);
89678971 }
89688972 };
8969 const ptr_ty = self.air.typeOf(un_op);
8973 const ptr_ty = self.typeOf(un_op);
89708974 try self.load(operand, ptr_ty, operand_ptr);
89718975
89728976 const result = try self.isNonErr(inst, ptr_ty.childType(), operand);
......@@ -9032,7 +9036,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
90329036fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
90339037 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
90349038 const condition = try self.resolveInst(pl_op.operand);
9035 const condition_ty = self.air.typeOf(pl_op.operand);
9039 const condition_ty = self.typeOf(pl_op.operand);
90369040 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
90379041 var extra_index: usize = switch_br.end;
90389042 var case_i: u32 = 0;
......@@ -9119,7 +9123,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
91199123 const br = self.air.instructions.items(.data)[inst].br;
91209124 const src_mcv = try self.resolveInst(br.operand);
91219125
9122 const block_ty = self.air.typeOfIndex(br.block_inst);
9126 const block_ty = self.typeOfIndex(br.block_inst);
91239127 const block_unused =
91249128 !block_ty.hasRuntimeBitsIgnoreComptime(mod) or self.liveness.isUnused(br.block_inst);
91259129 const block_tracking = self.inst_tracking.getPtr(br.block_inst).?;
......@@ -9244,7 +9248,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
92449248
92459249 const arg_mcv = try self.resolveInst(input);
92469250 try self.register_manager.getReg(reg, null);
9247 try self.genSetReg(reg, self.air.typeOf(input), arg_mcv);
9251 try self.genSetReg(reg, self.typeOf(input), arg_mcv);
92489252 }
92499253
92509254 {
......@@ -10169,7 +10173,7 @@ fn airPtrToInt(self: *Self, inst: Air.Inst.Index) !void {
1016910173 if (self.reuseOperand(inst, un_op, 0, src_mcv)) break :result src_mcv;
1017010174
1017110175 const dst_mcv = try self.allocRegOrMem(inst, true);
10172 const dst_ty = self.air.typeOfIndex(inst);
10176 const dst_ty = self.typeOfIndex(inst);
1017310177 try self.genCopy(dst_ty, dst_mcv, src_mcv);
1017410178 break :result dst_mcv;
1017510179 };
......@@ -10179,8 +10183,8 @@ fn airPtrToInt(self: *Self, inst: Air.Inst.Index) !void {
1017910183fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1018010184 const mod = self.bin_file.options.module.?;
1018110185 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
10182 const dst_ty = self.air.typeOfIndex(inst);
10183 const src_ty = self.air.typeOf(ty_op.operand);
10186 const dst_ty = self.typeOfIndex(inst);
10187 const src_ty = self.typeOf(ty_op.operand);
1018410188
1018510189 const result = result: {
1018610190 const dst_rc = regClassForType(dst_ty, mod);
......@@ -10241,8 +10245,8 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
1024110245 const mod = self.bin_file.options.module.?;
1024210246 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1024310247
10244 const slice_ty = self.air.typeOfIndex(inst);
10245 const ptr_ty = self.air.typeOf(ty_op.operand);
10248 const slice_ty = self.typeOfIndex(inst);
10249 const ptr_ty = self.typeOf(ty_op.operand);
1024610250 const ptr = try self.resolveInst(ty_op.operand);
1024710251 const array_ty = ptr_ty.childType();
1024810252 const array_len = array_ty.arrayLen();
......@@ -10264,11 +10268,11 @@ fn airIntToFloat(self: *Self, inst: Air.Inst.Index) !void {
1026410268 const mod = self.bin_file.options.module.?;
1026510269 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1026610270
10267 const src_ty = self.air.typeOf(ty_op.operand);
10271 const src_ty = self.typeOf(ty_op.operand);
1026810272 const src_bits = @intCast(u32, src_ty.bitSize(mod));
1026910273 const src_signedness =
1027010274 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;
10271 const dst_ty = self.air.typeOfIndex(inst);
10275 const dst_ty = self.typeOfIndex(inst);
1027210276
1027310277 const src_size = math.divCeil(u32, @max(switch (src_signedness) {
1027410278 .signed => src_bits,
......@@ -10318,8 +10322,8 @@ fn airFloatToInt(self: *Self, inst: Air.Inst.Index) !void {
1031810322 const mod = self.bin_file.options.module.?;
1031910323 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1032010324
10321 const src_ty = self.air.typeOf(ty_op.operand);
10322 const dst_ty = self.air.typeOfIndex(inst);
10325 const src_ty = self.typeOf(ty_op.operand);
10326 const dst_ty = self.typeOfIndex(inst);
1032310327 const dst_bits = @intCast(u32, dst_ty.bitSize(mod));
1032410328 const dst_signedness =
1032510329 if (dst_ty.isAbiInt(mod)) dst_ty.intInfo(mod).signedness else .unsigned;
......@@ -10371,8 +10375,8 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
1037110375 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
1037210376 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
1037310377
10374 const ptr_ty = self.air.typeOf(extra.ptr);
10375 const val_ty = self.air.typeOf(extra.expected_value);
10378 const ptr_ty = self.typeOf(extra.ptr);
10379 const val_ty = self.typeOf(extra.expected_value);
1037610380 const val_abi_size = @intCast(u32, val_ty.abiSize(mod));
1037710381
1037810382 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });
......@@ -10712,10 +10716,10 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {
1071210716
1071310717 const unused = self.liveness.isUnused(inst);
1071410718
10715 const ptr_ty = self.air.typeOf(pl_op.operand);
10719 const ptr_ty = self.typeOf(pl_op.operand);
1071610720 const ptr_mcv = try self.resolveInst(pl_op.operand);
1071710721
10718 const val_ty = self.air.typeOf(extra.operand);
10722 const val_ty = self.typeOf(extra.operand);
1071910723 const val_mcv = try self.resolveInst(extra.operand);
1072010724
1072110725 const result =
......@@ -10726,7 +10730,7 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {
1072610730fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {
1072710731 const atomic_load = self.air.instructions.items(.data)[inst].atomic_load;
1072810732
10729 const ptr_ty = self.air.typeOf(atomic_load.ptr);
10733 const ptr_ty = self.typeOf(atomic_load.ptr);
1073010734 const ptr_mcv = try self.resolveInst(atomic_load.ptr);
1073110735 const ptr_lock = switch (ptr_mcv) {
1073210736 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
......@@ -10747,10 +10751,10 @@ fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {
1074710751fn airAtomicStore(self: *Self, inst: Air.Inst.Index, order: std.builtin.AtomicOrder) !void {
1074810752 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1074910753
10750 const ptr_ty = self.air.typeOf(bin_op.lhs);
10754 const ptr_ty = self.typeOf(bin_op.lhs);
1075110755 const ptr_mcv = try self.resolveInst(bin_op.lhs);
1075210756
10753 const val_ty = self.air.typeOf(bin_op.rhs);
10757 const val_ty = self.typeOf(bin_op.rhs);
1075410758 const val_mcv = try self.resolveInst(bin_op.rhs);
1075510759
1075610760 const result = try self.atomicOp(ptr_mcv, val_mcv, ptr_ty, val_ty, true, null, order);
......@@ -10768,7 +10772,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1076810772 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1076910773
1077010774 const dst_ptr = try self.resolveInst(bin_op.lhs);
10771 const dst_ptr_ty = self.air.typeOf(bin_op.lhs);
10775 const dst_ptr_ty = self.typeOf(bin_op.lhs);
1077210776 const dst_ptr_lock: ?RegisterLock = switch (dst_ptr) {
1077310777 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
1077410778 else => null,
......@@ -10776,7 +10780,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1077610780 defer if (dst_ptr_lock) |lock| self.register_manager.unlockReg(lock);
1077710781
1077810782 const src_val = try self.resolveInst(bin_op.rhs);
10779 const elem_ty = self.air.typeOf(bin_op.rhs);
10783 const elem_ty = self.typeOf(bin_op.rhs);
1078010784 const src_val_lock: ?RegisterLock = switch (src_val) {
1078110785 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
1078210786 else => null,
......@@ -10888,7 +10892,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1088810892 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1088910893
1089010894 const dst_ptr = try self.resolveInst(bin_op.lhs);
10891 const dst_ptr_ty = self.air.typeOf(bin_op.lhs);
10895 const dst_ptr_ty = self.typeOf(bin_op.lhs);
1089210896 const dst_ptr_lock: ?RegisterLock = switch (dst_ptr) {
1089310897 .register => |reg| self.register_manager.lockRegAssumeUnused(reg),
1089410898 else => null,
......@@ -10922,8 +10926,8 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1092210926fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
1092310927 const mod = self.bin_file.options.module.?;
1092410928 const un_op = self.air.instructions.items(.data)[inst].un_op;
10925 const inst_ty = self.air.typeOfIndex(inst);
10926 const enum_ty = self.air.typeOf(un_op);
10929 const inst_ty = self.typeOfIndex(inst);
10930 const enum_ty = self.typeOf(un_op);
1092710931
1092810932 // We need a properly aligned and sized call frame to be able to call this function.
1092910933 {
......@@ -10964,7 +10968,7 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
1096410968 const mod = self.bin_file.options.module.?;
1096510969 const un_op = self.air.instructions.items(.data)[inst].un_op;
1096610970
10967 const err_ty = self.air.typeOf(un_op);
10971 const err_ty = self.typeOf(un_op);
1096810972 const err_mcv = try self.resolveInst(un_op);
1096910973 const err_reg = try self.copyToTmpRegister(err_ty, err_mcv);
1097010974 const err_lock = self.register_manager.lockRegAssumeUnused(err_reg);
......@@ -11046,7 +11050,7 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
1104611050fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1104711051 const mod = self.bin_file.options.module.?;
1104811052 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
11049 const vector_ty = self.air.typeOfIndex(inst);
11053 const vector_ty = self.typeOfIndex(inst);
1105011054 const dst_rc = regClassForType(vector_ty, mod);
1105111055 const scalar_ty = vector_ty.scalarType(mod);
1105211056
......@@ -11266,7 +11270,7 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
1126611270
1126711271fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1126811272 const mod = self.bin_file.options.module.?;
11269 const result_ty = self.air.typeOfIndex(inst);
11273 const result_ty = self.typeOfIndex(inst);
1127011274 const len = @intCast(usize, result_ty.arrayLen());
1127111275 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
1127211276 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
......@@ -11411,10 +11415,10 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1141111415 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
1141211416 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
1141311417 const result: MCValue = result: {
11414 const union_ty = self.air.typeOfIndex(inst);
11418 const union_ty = self.typeOfIndex(inst);
1141511419 const layout = union_ty.unionGetLayout(mod);
1141611420
11417 const src_ty = self.air.typeOf(extra.init);
11421 const src_ty = self.typeOf(extra.init);
1141811422 const src_mcv = try self.resolveInst(extra.init);
1141911423 if (layout.tag_size == 0) {
1142011424 if (self.reuseOperand(inst, extra.init, 0, src_mcv)) break :result src_mcv;
......@@ -11461,7 +11465,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1146111465 const mod = self.bin_file.options.module.?;
1146211466 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
1146311467 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
11464 const ty = self.air.typeOfIndex(inst);
11468 const ty = self.typeOfIndex(inst);
1146511469
1146611470 if (!self.hasFeature(.fma)) return self.fail("TODO implement airMulAdd for {}", .{
1146711471 ty.fmt(self.bin_file.options.module.?),
......@@ -11609,7 +11613,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1160911613
1161011614fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
1161111615 const mod = self.bin_file.options.module.?;
11612 const ty = self.air.typeOf(ref);
11616 const ty = self.typeOf(ref);
1161311617
1161411618 // If the type has no codegen bits, no need to store it.
1161511619 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
......@@ -11713,7 +11717,7 @@ fn resolveCallingConventionValues(
1171311717 defer self.gpa.free(param_types);
1171411718 fn_ty.fnParamTypes(param_types);
1171511719 // TODO: promote var arg types
11716 for (param_types[param_len..], var_args) |*param_ty, arg| param_ty.* = self.air.typeOf(arg);
11720 for (param_types[param_len..], var_args) |*param_ty, arg| param_ty.* = self.typeOf(arg);
1171711721 var result: CallMCValues = .{
1171811722 .args = try self.gpa.alloc(MCValue, param_types.len),
1171911723 // These undefined values must be populated before returning from this function.
......@@ -12023,3 +12027,13 @@ fn hasAnyFeatures(self: *Self, features: anytype) bool {
1202312027fn hasAllFeatures(self: *Self, features: anytype) bool {
1202412028 return Target.x86.featureSetHasAll(self.target.cpu.features, features);
1202512029}
12030
12031fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
12032 const mod = self.bin_file.options.module.?;
12033 return self.air.typeOf(inst, mod.intern_pool);
12034}
12035
12036fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
12037 const mod = self.bin_file.options.module.?;
12038 return self.air.typeOfIndex(inst, mod.intern_pool);
12039}
src/codegen/c.zig+140-128
......@@ -288,7 +288,7 @@ pub const Function = struct {
288288
289289 const mod = f.object.dg.module;
290290 const val = f.air.value(ref, mod).?;
291 const ty = f.air.typeOf(ref);
291 const ty = f.typeOf(ref);
292292
293293 const result: CValue = if (lowersToArray(ty, mod)) result: {
294294 const writer = f.object.code_header.writer();
......@@ -355,7 +355,7 @@ pub const Function = struct {
355355 switch (c_value) {
356356 .constant => |inst| {
357357 const mod = f.object.dg.module;
358 const ty = f.air.typeOf(inst);
358 const ty = f.typeOf(inst);
359359 const val = f.air.value(inst, mod).?;
360360 return f.object.dg.renderValue(w, ty, val, location);
361361 },
......@@ -368,7 +368,7 @@ pub const Function = struct {
368368 switch (c_value) {
369369 .constant => |inst| {
370370 const mod = f.object.dg.module;
371 const ty = f.air.typeOf(inst);
371 const ty = f.typeOf(inst);
372372 const val = f.air.value(inst, mod).?;
373373 try w.writeAll("(*");
374374 try f.object.dg.renderValue(w, ty, val, .Other);
......@@ -382,7 +382,7 @@ pub const Function = struct {
382382 switch (c_value) {
383383 .constant => |inst| {
384384 const mod = f.object.dg.module;
385 const ty = f.air.typeOf(inst);
385 const ty = f.typeOf(inst);
386386 const val = f.air.value(inst, mod).?;
387387 try f.object.dg.renderValue(w, ty, val, .Other);
388388 try w.writeByte('.');
......@@ -396,7 +396,7 @@ pub const Function = struct {
396396 switch (c_value) {
397397 .constant => |inst| {
398398 const mod = f.object.dg.module;
399 const ty = f.air.typeOf(inst);
399 const ty = f.typeOf(inst);
400400 const val = f.air.value(inst, mod).?;
401401 try w.writeByte('(');
402402 try f.object.dg.renderValue(w, ty, val, .Other);
......@@ -486,6 +486,16 @@ pub const Function = struct {
486486 f.object.dg.ctypes.deinit(gpa);
487487 f.object.dg.fwd_decl.deinit();
488488 }
489
490 fn typeOf(f: *Function, inst: Air.Inst.Ref) Type {
491 const mod = f.object.dg.module;
492 return f.air.typeOf(inst, mod.intern_pool);
493 }
494
495 fn typeOfIndex(f: *Function, inst: Air.Inst.Index) Type {
496 const mod = f.object.dg.module;
497 return f.air.typeOfIndex(inst, mod.intern_pool);
498 }
489499};
490500
491501/// This data is available when outputting .c code for a `Module`.
......@@ -2802,17 +2812,19 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con
28022812
28032813fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfMemory }!void {
28042814 const mod = f.object.dg.module;
2815 const ip = &mod.intern_pool;
28052816 const air_tags = f.air.instructions.items(.tag);
28062817
28072818 for (body) |inst| {
2808 if (f.liveness.isUnused(inst) and !f.air.mustLower(inst)) {
2819 if (f.liveness.isUnused(inst) and !f.air.mustLower(inst, ip.*))
28092820 continue;
2810 }
28112821
28122822 const result_value = switch (air_tags[inst]) {
28132823 // zig fmt: off
28142824 .constant => unreachable, // excluded from function bodies
28152825 .const_ty => unreachable, // excluded from function bodies
2826 .interned => unreachable, // excluded from function bodies
2827
28162828 .arg => try airArg(f, inst),
28172829
28182830 .trap => try airTrap(f.object.writer()),
......@@ -2837,7 +2849,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
28372849 .div_trunc, .div_exact => try airBinOp(f, inst, "/", "div_trunc", .none),
28382850 .rem => blk: {
28392851 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
2840 const lhs_scalar_ty = f.air.typeOf(bin_op.lhs).scalarType(mod);
2852 const lhs_scalar_ty = f.typeOf(bin_op.lhs).scalarType(mod);
28412853 // For binary operations @TypeOf(lhs)==@TypeOf(rhs),
28422854 // so we only check one.
28432855 break :blk if (lhs_scalar_ty.isInt(mod))
......@@ -3088,7 +3100,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
30883100fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: []const u8) !CValue {
30893101 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
30903102
3091 const inst_ty = f.air.typeOfIndex(inst);
3103 const inst_ty = f.typeOfIndex(inst);
30923104 const operand = try f.resolveInst(ty_op.operand);
30933105 try reap(f, inst, &.{ty_op.operand});
30943106
......@@ -3107,7 +3119,7 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: [
31073119
31083120fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
31093121 const mod = f.object.dg.module;
3110 const inst_ty = f.air.typeOfIndex(inst);
3122 const inst_ty = f.typeOfIndex(inst);
31113123 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
31123124 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
31133125 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
......@@ -3136,8 +3148,8 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
31363148 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
31373149 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
31383150
3139 const inst_ty = f.air.typeOfIndex(inst);
3140 const ptr_ty = f.air.typeOf(bin_op.lhs);
3151 const inst_ty = f.typeOfIndex(inst);
3152 const ptr_ty = f.typeOf(bin_op.lhs);
31413153 const elem_ty = ptr_ty.childType();
31423154 const elem_has_bits = elem_ty.hasRuntimeBitsIgnoreComptime(mod);
31433155
......@@ -3169,7 +3181,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
31693181
31703182fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
31713183 const mod = f.object.dg.module;
3172 const inst_ty = f.air.typeOfIndex(inst);
3184 const inst_ty = f.typeOfIndex(inst);
31733185 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
31743186 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
31753187 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
......@@ -3198,8 +3210,8 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
31983210 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
31993211 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
32003212
3201 const inst_ty = f.air.typeOfIndex(inst);
3202 const slice_ty = f.air.typeOf(bin_op.lhs);
3213 const inst_ty = f.typeOfIndex(inst);
3214 const slice_ty = f.typeOf(bin_op.lhs);
32033215 const elem_ty = slice_ty.elemType2(mod);
32043216 const elem_has_bits = elem_ty.hasRuntimeBitsIgnoreComptime(mod);
32053217
......@@ -3226,7 +3238,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
32263238fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
32273239 const mod = f.object.dg.module;
32283240 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
3229 const inst_ty = f.air.typeOfIndex(inst);
3241 const inst_ty = f.typeOfIndex(inst);
32303242 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
32313243 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
32323244 return .none;
......@@ -3251,7 +3263,7 @@ fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
32513263
32523264fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue {
32533265 const mod = f.object.dg.module;
3254 const inst_ty = f.air.typeOfIndex(inst);
3266 const inst_ty = f.typeOfIndex(inst);
32553267 const elem_type = inst_ty.elemType();
32563268 if (!elem_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return .{ .undef = inst_ty };
32573269
......@@ -3267,7 +3279,7 @@ fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue {
32673279
32683280fn airRetPtr(f: *Function, inst: Air.Inst.Index) !CValue {
32693281 const mod = f.object.dg.module;
3270 const inst_ty = f.air.typeOfIndex(inst);
3282 const inst_ty = f.typeOfIndex(inst);
32713283 const elem_ty = inst_ty.elemType();
32723284 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return .{ .undef = inst_ty };
32733285
......@@ -3282,7 +3294,7 @@ fn airRetPtr(f: *Function, inst: Air.Inst.Index) !CValue {
32823294}
32833295
32843296fn airArg(f: *Function, inst: Air.Inst.Index) !CValue {
3285 const inst_ty = f.air.typeOfIndex(inst);
3297 const inst_ty = f.typeOfIndex(inst);
32863298 const inst_cty = try f.typeToIndex(inst_ty, .parameter);
32873299
32883300 const i = f.next_arg_index;
......@@ -3309,7 +3321,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
33093321 const mod = f.object.dg.module;
33103322 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
33113323
3312 const ptr_ty = f.air.typeOf(ty_op.operand);
3324 const ptr_ty = f.typeOf(ty_op.operand);
33133325 const ptr_scalar_ty = ptr_ty.scalarType(mod);
33143326 const ptr_info = ptr_scalar_ty.ptrInfo().data;
33153327 const src_ty = ptr_info.pointee_type;
......@@ -3399,7 +3411,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
33993411 const un_op = f.air.instructions.items(.data)[inst].un_op;
34003412 const writer = f.object.writer();
34013413 const op_inst = Air.refToIndex(un_op);
3402 const op_ty = f.air.typeOf(un_op);
3414 const op_ty = f.typeOf(un_op);
34033415 const ret_ty = if (is_ptr) op_ty.childType() else op_ty;
34043416 var lowered_ret_buf: LowerFnRetTyBuffer = undefined;
34053417 const lowered_ret_ty = lowerFnRetTy(ret_ty, &lowered_ret_buf, mod);
......@@ -3453,9 +3465,9 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue {
34533465 const operand = try f.resolveInst(ty_op.operand);
34543466 try reap(f, inst, &.{ty_op.operand});
34553467
3456 const inst_ty = f.air.typeOfIndex(inst);
3468 const inst_ty = f.typeOfIndex(inst);
34573469 const inst_scalar_ty = inst_ty.scalarType(mod);
3458 const operand_ty = f.air.typeOf(ty_op.operand);
3470 const operand_ty = f.typeOf(ty_op.operand);
34593471 const scalar_ty = operand_ty.scalarType(mod);
34603472
34613473 const writer = f.object.writer();
......@@ -3478,13 +3490,13 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
34783490
34793491 const operand = try f.resolveInst(ty_op.operand);
34803492 try reap(f, inst, &.{ty_op.operand});
3481 const inst_ty = f.air.typeOfIndex(inst);
3493 const inst_ty = f.typeOfIndex(inst);
34823494 const inst_scalar_ty = inst_ty.scalarType(mod);
34833495 const dest_int_info = inst_scalar_ty.intInfo(mod);
34843496 const dest_bits = dest_int_info.bits;
34853497 const dest_c_bits = toCIntBits(dest_int_info.bits) orelse
34863498 return f.fail("TODO: C backend: implement integer types larger than 128 bits", .{});
3487 const operand_ty = f.air.typeOf(ty_op.operand);
3499 const operand_ty = f.typeOf(ty_op.operand);
34883500 const scalar_ty = operand_ty.scalarType(mod);
34893501 const scalar_int_info = scalar_ty.intInfo(mod);
34903502
......@@ -3572,7 +3584,7 @@ fn airBoolToInt(f: *Function, inst: Air.Inst.Index) !CValue {
35723584 const operand = try f.resolveInst(un_op);
35733585 try reap(f, inst, &.{un_op});
35743586 const writer = f.object.writer();
3575 const inst_ty = f.air.typeOfIndex(inst);
3587 const inst_ty = f.typeOfIndex(inst);
35763588 const local = try f.allocLocal(inst, inst_ty);
35773589 const a = try Assignment.start(f, writer, inst_ty);
35783590 try f.writeCValue(writer, local, .Other);
......@@ -3587,12 +3599,12 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
35873599 // *a = b;
35883600 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
35893601
3590 const ptr_ty = f.air.typeOf(bin_op.lhs);
3602 const ptr_ty = f.typeOf(bin_op.lhs);
35913603 const ptr_scalar_ty = ptr_ty.scalarType(mod);
35923604 const ptr_info = ptr_scalar_ty.ptrInfo().data;
35933605
35943606 const ptr_val = try f.resolveInst(bin_op.lhs);
3595 const src_ty = f.air.typeOf(bin_op.rhs);
3607 const src_ty = f.typeOf(bin_op.rhs);
35963608
35973609 const val_is_undef = if (f.air.value(bin_op.rhs, mod)) |v| v.isUndefDeep() else false;
35983610
......@@ -3737,8 +3749,8 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info:
37373749 const rhs = try f.resolveInst(bin_op.rhs);
37383750 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
37393751
3740 const inst_ty = f.air.typeOfIndex(inst);
3741 const operand_ty = f.air.typeOf(bin_op.lhs);
3752 const inst_ty = f.typeOfIndex(inst);
3753 const operand_ty = f.typeOf(bin_op.lhs);
37423754 const scalar_ty = operand_ty.scalarType(mod);
37433755
37443756 const w = f.object.writer();
......@@ -3769,14 +3781,14 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info:
37693781fn airNot(f: *Function, inst: Air.Inst.Index) !CValue {
37703782 const mod = f.object.dg.module;
37713783 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
3772 const operand_ty = f.air.typeOf(ty_op.operand);
3784 const operand_ty = f.typeOf(ty_op.operand);
37733785 const scalar_ty = operand_ty.scalarType(mod);
37743786 if (scalar_ty.tag() != .bool) return try airUnBuiltinCall(f, inst, "not", .bits);
37753787
37763788 const op = try f.resolveInst(ty_op.operand);
37773789 try reap(f, inst, &.{ty_op.operand});
37783790
3779 const inst_ty = f.air.typeOfIndex(inst);
3791 const inst_ty = f.typeOfIndex(inst);
37803792
37813793 const writer = f.object.writer();
37823794 const local = try f.allocLocal(inst, inst_ty);
......@@ -3802,7 +3814,7 @@ fn airBinOp(
38023814) !CValue {
38033815 const mod = f.object.dg.module;
38043816 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
3805 const operand_ty = f.air.typeOf(bin_op.lhs);
3817 const operand_ty = f.typeOf(bin_op.lhs);
38063818 const scalar_ty = operand_ty.scalarType(mod);
38073819 if ((scalar_ty.isInt(mod) and scalar_ty.bitSize(mod) > 64) or scalar_ty.isRuntimeFloat())
38083820 return try airBinBuiltinCall(f, inst, operation, info);
......@@ -3811,7 +3823,7 @@ fn airBinOp(
38113823 const rhs = try f.resolveInst(bin_op.rhs);
38123824 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
38133825
3814 const inst_ty = f.air.typeOfIndex(inst);
3826 const inst_ty = f.typeOfIndex(inst);
38153827
38163828 const writer = f.object.writer();
38173829 const local = try f.allocLocal(inst, inst_ty);
......@@ -3839,7 +3851,7 @@ fn airCmpOp(
38393851 operator: std.math.CompareOperator,
38403852) !CValue {
38413853 const mod = f.object.dg.module;
3842 const lhs_ty = f.air.typeOf(data.lhs);
3854 const lhs_ty = f.typeOf(data.lhs);
38433855 const scalar_ty = lhs_ty.scalarType(mod);
38443856
38453857 const scalar_bits = scalar_ty.bitSize(mod);
......@@ -3855,12 +3867,12 @@ fn airCmpOp(
38553867 if (scalar_ty.isRuntimeFloat())
38563868 return airCmpBuiltinCall(f, inst, data, operator, .operator, .none);
38573869
3858 const inst_ty = f.air.typeOfIndex(inst);
3870 const inst_ty = f.typeOfIndex(inst);
38593871 const lhs = try f.resolveInst(data.lhs);
38603872 const rhs = try f.resolveInst(data.rhs);
38613873 try reap(f, inst, &.{ data.lhs, data.rhs });
38623874
3863 const rhs_ty = f.air.typeOf(data.rhs);
3875 const rhs_ty = f.typeOf(data.rhs);
38643876 const need_cast = lhs_ty.isSinglePointer() or rhs_ty.isSinglePointer();
38653877 const writer = f.object.writer();
38663878 const local = try f.allocLocal(inst, inst_ty);
......@@ -3891,7 +3903,7 @@ fn airEquality(
38913903 const mod = f.object.dg.module;
38923904 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
38933905
3894 const operand_ty = f.air.typeOf(bin_op.lhs);
3906 const operand_ty = f.typeOf(bin_op.lhs);
38953907 const operand_bits = operand_ty.bitSize(mod);
38963908 if (operand_ty.isInt(mod) and operand_bits > 64)
38973909 return airCmpBuiltinCall(
......@@ -3910,7 +3922,7 @@ fn airEquality(
39103922 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
39113923
39123924 const writer = f.object.writer();
3913 const inst_ty = f.air.typeOfIndex(inst);
3925 const inst_ty = f.typeOfIndex(inst);
39143926 const local = try f.allocLocal(inst, inst_ty);
39153927 try f.writeCValue(writer, local, .Other);
39163928 try writer.writeAll(" = ");
......@@ -3954,7 +3966,7 @@ fn airEquality(
39543966fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {
39553967 const un_op = f.air.instructions.items(.data)[inst].un_op;
39563968
3957 const inst_ty = f.air.typeOfIndex(inst);
3969 const inst_ty = f.typeOfIndex(inst);
39583970 const operand = try f.resolveInst(un_op);
39593971 try reap(f, inst, &.{un_op});
39603972
......@@ -3976,7 +3988,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
39763988 const rhs = try f.resolveInst(bin_op.rhs);
39773989 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
39783990
3979 const inst_ty = f.air.typeOfIndex(inst);
3991 const inst_ty = f.typeOfIndex(inst);
39803992 const inst_scalar_ty = inst_ty.scalarType(mod);
39813993 const elem_ty = inst_scalar_ty.elemType2(mod);
39823994
......@@ -4019,7 +4031,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons
40194031 const mod = f.object.dg.module;
40204032 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
40214033
4022 const inst_ty = f.air.typeOfIndex(inst);
4034 const inst_ty = f.typeOfIndex(inst);
40234035 const inst_scalar_ty = inst_ty.scalarType(mod);
40244036
40254037 if (inst_scalar_ty.isInt(mod) and inst_scalar_ty.bitSize(mod) > 64)
......@@ -4065,7 +4077,7 @@ fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue {
40654077 const len = try f.resolveInst(bin_op.rhs);
40664078 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
40674079
4068 const inst_ty = f.air.typeOfIndex(inst);
4080 const inst_ty = f.typeOfIndex(inst);
40694081 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
40704082 const ptr_ty = inst_ty.slicePtrFieldType(&buf);
40714083
......@@ -4110,7 +4122,7 @@ fn airCall(
41104122 const resolved_args = try gpa.alloc(CValue, args.len);
41114123 defer gpa.free(resolved_args);
41124124 for (resolved_args, args) |*resolved_arg, arg| {
4113 const arg_ty = f.air.typeOf(arg);
4125 const arg_ty = f.typeOf(arg);
41144126 const arg_cty = try f.typeToIndex(arg_ty, .parameter);
41154127 if (f.indexToCType(arg_cty).tag() == .void) {
41164128 resolved_arg.* = .none;
......@@ -4141,7 +4153,7 @@ fn airCall(
41414153 for (args) |arg| try bt.feed(arg);
41424154 }
41434155
4144 const callee_ty = f.air.typeOf(pl_op.operand);
4156 const callee_ty = f.typeOf(pl_op.operand);
41454157 const fn_ty = switch (callee_ty.zigTypeTag(mod)) {
41464158 .Fn => callee_ty,
41474159 .Pointer => callee_ty.childType(),
......@@ -4279,7 +4291,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
42794291 f.next_block_index += 1;
42804292 const writer = f.object.writer();
42814293
4282 const inst_ty = f.air.typeOfIndex(inst);
4294 const inst_ty = f.typeOfIndex(inst);
42834295 const result = if (inst_ty.tag() != .void and !f.liveness.isUnused(inst))
42844296 try f.allocLocal(inst, inst_ty)
42854297 else
......@@ -4302,7 +4314,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
43024314 try f.object.indent_writer.insertNewline();
43034315
43044316 // noreturn blocks have no `br` instructions reaching them, so we don't want a label
4305 if (!f.air.typeOfIndex(inst).isNoReturn()) {
4317 if (!f.typeOfIndex(inst).isNoReturn()) {
43064318 // label must be followed by an expression, include an empty one.
43074319 try writer.print("zig_block_{d}:;\n", .{block_id});
43084320 }
......@@ -4314,7 +4326,7 @@ fn airTry(f: *Function, inst: Air.Inst.Index) !CValue {
43144326 const pl_op = f.air.instructions.items(.data)[inst].pl_op;
43154327 const extra = f.air.extraData(Air.Try, pl_op.payload);
43164328 const body = f.air.extra[extra.end..][0..extra.data.body_len];
4317 const err_union_ty = f.air.typeOf(pl_op.operand);
4329 const err_union_ty = f.typeOf(pl_op.operand);
43184330 return lowerTry(f, inst, pl_op.operand, body, err_union_ty, false);
43194331}
43204332
......@@ -4322,7 +4334,7 @@ fn airTryPtr(f: *Function, inst: Air.Inst.Index) !CValue {
43224334 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
43234335 const extra = f.air.extraData(Air.TryPtr, ty_pl.payload);
43244336 const body = f.air.extra[extra.end..][0..extra.data.body_len];
4325 const err_union_ty = f.air.typeOf(extra.data.ptr).childType();
4337 const err_union_ty = f.typeOf(extra.data.ptr).childType();
43264338 return lowerTry(f, inst, extra.data.ptr, body, err_union_ty, true);
43274339}
43284340
......@@ -4336,7 +4348,7 @@ fn lowerTry(
43364348) !CValue {
43374349 const mod = f.object.dg.module;
43384350 const err_union = try f.resolveInst(operand);
4339 const inst_ty = f.air.typeOfIndex(inst);
4351 const inst_ty = f.typeOfIndex(inst);
43404352 const liveness_condbr = f.liveness.getCondBr(inst);
43414353 const writer = f.object.writer();
43424354 const payload_ty = err_union_ty.errorUnionPayload();
......@@ -4404,7 +4416,7 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue {
44044416
44054417 // If result is .none then the value of the block is unused.
44064418 if (result != .none) {
4407 const operand_ty = f.air.typeOf(branch.operand);
4419 const operand_ty = f.typeOf(branch.operand);
44084420 const operand = try f.resolveInst(branch.operand);
44094421 try reap(f, inst, &.{branch.operand});
44104422
......@@ -4421,10 +4433,10 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue {
44214433
44224434fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
44234435 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
4424 const dest_ty = f.air.typeOfIndex(inst);
4436 const dest_ty = f.typeOfIndex(inst);
44254437
44264438 const operand = try f.resolveInst(ty_op.operand);
4427 const operand_ty = f.air.typeOf(ty_op.operand);
4439 const operand_ty = f.typeOf(ty_op.operand);
44284440
44294441 const bitcasted = try bitcast(f, dest_ty, operand, operand_ty);
44304442 try reap(f, inst, &.{ty_op.operand});
......@@ -4684,7 +4696,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
46844696 const pl_op = f.air.instructions.items(.data)[inst].pl_op;
46854697 const condition = try f.resolveInst(pl_op.operand);
46864698 try reap(f, inst, &.{pl_op.operand});
4687 const condition_ty = f.air.typeOf(pl_op.operand);
4699 const condition_ty = f.typeOf(pl_op.operand);
46884700 const switch_br = f.air.extraData(Air.SwitchBr, pl_op.payload);
46894701 const writer = f.object.writer();
46904702
......@@ -4784,7 +4796,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
47844796
47854797 const result = result: {
47864798 const writer = f.object.writer();
4787 const inst_ty = f.air.typeOfIndex(inst);
4799 const inst_ty = f.typeOfIndex(inst);
47884800 const local = if (inst_ty.hasRuntimeBitsIgnoreComptime(mod)) local: {
47894801 const local = try f.allocLocal(inst, inst_ty);
47904802 if (f.wantSafety()) {
......@@ -4814,7 +4826,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
48144826
48154827 const is_reg = constraint[1] == '{';
48164828 if (is_reg) {
4817 const output_ty = if (output == .none) inst_ty else f.air.typeOf(output).childType();
4829 const output_ty = if (output == .none) inst_ty else f.typeOf(output).childType();
48184830 try writer.writeAll("register ");
48194831 const alignment = 0;
48204832 const local_value = try f.allocLocalValue(output_ty, alignment);
......@@ -4847,7 +4859,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
48474859 const is_reg = constraint[0] == '{';
48484860 const input_val = try f.resolveInst(input);
48494861 if (asmInputNeedsLocal(constraint, input_val)) {
4850 const input_ty = f.air.typeOf(input);
4862 const input_ty = f.typeOf(input);
48514863 if (is_reg) try writer.writeAll("register ");
48524864 const alignment = 0;
48534865 const local_value = try f.allocLocalValue(input_ty, alignment);
......@@ -5048,7 +5060,7 @@ fn airIsNull(
50485060 try f.writeCValue(writer, operand, .Other);
50495061 }
50505062
5051 const operand_ty = f.air.typeOf(un_op);
5063 const operand_ty = f.typeOf(un_op);
50525064 const optional_ty = if (is_ptr) operand_ty.childType() else operand_ty;
50535065 var payload_buf: Type.Payload.ElemType = undefined;
50545066 const payload_ty = optional_ty.optionalChild(&payload_buf);
......@@ -5083,7 +5095,7 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue {
50835095
50845096 const operand = try f.resolveInst(ty_op.operand);
50855097 try reap(f, inst, &.{ty_op.operand});
5086 const opt_ty = f.air.typeOf(ty_op.operand);
5098 const opt_ty = f.typeOf(ty_op.operand);
50875099
50885100 var buf: Type.Payload.ElemType = undefined;
50895101 const payload_ty = opt_ty.optionalChild(&buf);
......@@ -5092,7 +5104,7 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue {
50925104 return .none;
50935105 }
50945106
5095 const inst_ty = f.air.typeOfIndex(inst);
5107 const inst_ty = f.typeOfIndex(inst);
50965108 const writer = f.object.writer();
50975109 const local = try f.allocLocal(inst, inst_ty);
50985110
......@@ -5119,9 +5131,9 @@ fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue {
51195131 const writer = f.object.writer();
51205132 const operand = try f.resolveInst(ty_op.operand);
51215133 try reap(f, inst, &.{ty_op.operand});
5122 const ptr_ty = f.air.typeOf(ty_op.operand);
5134 const ptr_ty = f.typeOf(ty_op.operand);
51235135 const opt_ty = ptr_ty.childType();
5124 const inst_ty = f.air.typeOfIndex(inst);
5136 const inst_ty = f.typeOfIndex(inst);
51255137
51265138 if (!inst_ty.childType().hasRuntimeBitsIgnoreComptime(mod)) {
51275139 return .{ .undef = inst_ty };
......@@ -5149,11 +5161,11 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
51495161 const writer = f.object.writer();
51505162 const operand = try f.resolveInst(ty_op.operand);
51515163 try reap(f, inst, &.{ty_op.operand});
5152 const operand_ty = f.air.typeOf(ty_op.operand);
5164 const operand_ty = f.typeOf(ty_op.operand);
51535165
51545166 const opt_ty = operand_ty.elemType();
51555167
5156 const inst_ty = f.air.typeOfIndex(inst);
5168 const inst_ty = f.typeOfIndex(inst);
51575169
51585170 if (opt_ty.optionalReprIsPayload(mod)) {
51595171 if (f.liveness.isUnused(inst)) {
......@@ -5249,7 +5261,7 @@ fn airStructFieldPtr(f: *Function, inst: Air.Inst.Index) !CValue {
52495261
52505262 const container_ptr_val = try f.resolveInst(extra.struct_operand);
52515263 try reap(f, inst, &.{extra.struct_operand});
5252 const container_ptr_ty = f.air.typeOf(extra.struct_operand);
5264 const container_ptr_ty = f.typeOf(extra.struct_operand);
52535265 return fieldPtr(f, inst, container_ptr_ty, container_ptr_val, extra.field_index);
52545266}
52555267
......@@ -5258,7 +5270,7 @@ fn airStructFieldPtrIndex(f: *Function, inst: Air.Inst.Index, index: u8) !CValue
52585270
52595271 const container_ptr_val = try f.resolveInst(ty_op.operand);
52605272 try reap(f, inst, &.{ty_op.operand});
5261 const container_ptr_ty = f.air.typeOf(ty_op.operand);
5273 const container_ptr_ty = f.typeOf(ty_op.operand);
52625274 return fieldPtr(f, inst, container_ptr_ty, container_ptr_val, index);
52635275}
52645276
......@@ -5267,10 +5279,10 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
52675279 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
52685280 const extra = f.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
52695281
5270 const container_ptr_ty = f.air.typeOfIndex(inst);
5282 const container_ptr_ty = f.typeOfIndex(inst);
52715283 const container_ty = container_ptr_ty.childType();
52725284
5273 const field_ptr_ty = f.air.typeOf(extra.field_ptr);
5285 const field_ptr_ty = f.typeOf(extra.field_ptr);
52745286 const field_ptr_val = try f.resolveInst(extra.field_ptr);
52755287 try reap(f, inst, &.{extra.field_ptr});
52765288
......@@ -5334,7 +5346,7 @@ fn fieldPtr(
53345346) !CValue {
53355347 const mod = f.object.dg.module;
53365348 const container_ty = container_ptr_ty.elemType();
5337 const field_ptr_ty = f.air.typeOfIndex(inst);
5349 const field_ptr_ty = f.typeOfIndex(inst);
53385350
53395351 // Ensure complete type definition is visible before accessing fields.
53405352 _ = try f.typeToIndex(container_ty, .complete);
......@@ -5385,7 +5397,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
53855397 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
53865398 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;
53875399
5388 const inst_ty = f.air.typeOfIndex(inst);
5400 const inst_ty = f.typeOfIndex(inst);
53895401 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
53905402 try reap(f, inst, &.{extra.struct_operand});
53915403 return .none;
......@@ -5393,7 +5405,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
53935405
53945406 const struct_byval = try f.resolveInst(extra.struct_operand);
53955407 try reap(f, inst, &.{extra.struct_operand});
5396 const struct_ty = f.air.typeOf(extra.struct_operand);
5408 const struct_ty = f.typeOf(extra.struct_operand);
53975409 const writer = f.object.writer();
53985410
53995411 // Ensure complete type definition is visible before accessing fields.
......@@ -5514,9 +5526,9 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
55145526 const mod = f.object.dg.module;
55155527 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
55165528
5517 const inst_ty = f.air.typeOfIndex(inst);
5529 const inst_ty = f.typeOfIndex(inst);
55185530 const operand = try f.resolveInst(ty_op.operand);
5519 const operand_ty = f.air.typeOf(ty_op.operand);
5531 const operand_ty = f.typeOf(ty_op.operand);
55205532 try reap(f, inst, &.{ty_op.operand});
55215533
55225534 const operand_is_ptr = operand_ty.zigTypeTag(mod) == .Pointer;
......@@ -5553,10 +5565,10 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
55535565 const mod = f.object.dg.module;
55545566 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
55555567
5556 const inst_ty = f.air.typeOfIndex(inst);
5568 const inst_ty = f.typeOfIndex(inst);
55575569 const operand = try f.resolveInst(ty_op.operand);
55585570 try reap(f, inst, &.{ty_op.operand});
5559 const operand_ty = f.air.typeOf(ty_op.operand);
5571 const operand_ty = f.typeOf(ty_op.operand);
55605572 const error_union_ty = if (is_ptr) operand_ty.childType() else operand_ty;
55615573
55625574 const writer = f.object.writer();
......@@ -5589,9 +5601,9 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {
55895601 const mod = f.object.dg.module;
55905602 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
55915603
5592 const inst_ty = f.air.typeOfIndex(inst);
5604 const inst_ty = f.typeOfIndex(inst);
55935605 const repr_is_payload = inst_ty.optionalReprIsPayload(mod);
5594 const payload_ty = f.air.typeOf(ty_op.operand);
5606 const payload_ty = f.typeOf(ty_op.operand);
55955607 const payload = try f.resolveInst(ty_op.operand);
55965608 try reap(f, inst, &.{ty_op.operand});
55975609
......@@ -5621,7 +5633,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
56215633 const mod = f.object.dg.module;
56225634 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
56235635
5624 const inst_ty = f.air.typeOfIndex(inst);
5636 const inst_ty = f.typeOfIndex(inst);
56255637 const payload_ty = inst_ty.errorUnionPayload();
56265638 const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(mod);
56275639 const err_ty = inst_ty.errorUnionSet();
......@@ -5661,7 +5673,7 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
56615673 const writer = f.object.writer();
56625674 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
56635675 const operand = try f.resolveInst(ty_op.operand);
5664 const error_union_ty = f.air.typeOf(ty_op.operand).childType();
5676 const error_union_ty = f.typeOf(ty_op.operand).childType();
56655677
56665678 const error_ty = error_union_ty.errorUnionSet();
56675679 const payload_ty = error_union_ty.errorUnionPayload();
......@@ -5684,7 +5696,7 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
56845696 // Then return the payload pointer (only if it is used)
56855697 if (f.liveness.isUnused(inst)) return .none;
56865698
5687 const local = try f.allocLocal(inst, f.air.typeOfIndex(inst));
5699 const local = try f.allocLocal(inst, f.typeOfIndex(inst));
56885700 try f.writeCValue(writer, local, .Other);
56895701 try writer.writeAll(" = &(");
56905702 try f.writeCValueDeref(writer, operand);
......@@ -5711,7 +5723,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
57115723 const mod = f.object.dg.module;
57125724 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
57135725
5714 const inst_ty = f.air.typeOfIndex(inst);
5726 const inst_ty = f.typeOfIndex(inst);
57155727 const payload_ty = inst_ty.errorUnionPayload();
57165728 const payload = try f.resolveInst(ty_op.operand);
57175729 const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(mod);
......@@ -5747,7 +5759,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const
57475759 const writer = f.object.writer();
57485760 const operand = try f.resolveInst(un_op);
57495761 try reap(f, inst, &.{un_op});
5750 const operand_ty = f.air.typeOf(un_op);
5762 const operand_ty = f.typeOf(un_op);
57515763 const local = try f.allocLocal(inst, Type.bool);
57525764 const err_union_ty = if (is_ptr) operand_ty.childType() else operand_ty;
57535765 const payload_ty = err_union_ty.errorUnionPayload();
......@@ -5780,10 +5792,10 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
57805792
57815793 const operand = try f.resolveInst(ty_op.operand);
57825794 try reap(f, inst, &.{ty_op.operand});
5783 const inst_ty = f.air.typeOfIndex(inst);
5795 const inst_ty = f.typeOfIndex(inst);
57845796 const writer = f.object.writer();
57855797 const local = try f.allocLocal(inst, inst_ty);
5786 const array_ty = f.air.typeOf(ty_op.operand).childType();
5798 const array_ty = f.typeOf(ty_op.operand).childType();
57875799
57885800 try f.writeCValueMember(writer, local, .{ .identifier = "ptr" });
57895801 try writer.writeAll(" = ");
......@@ -5812,10 +5824,10 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
58125824 const mod = f.object.dg.module;
58135825 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
58145826
5815 const inst_ty = f.air.typeOfIndex(inst);
5827 const inst_ty = f.typeOfIndex(inst);
58165828 const operand = try f.resolveInst(ty_op.operand);
58175829 try reap(f, inst, &.{ty_op.operand});
5818 const operand_ty = f.air.typeOf(ty_op.operand);
5830 const operand_ty = f.typeOf(ty_op.operand);
58195831 const target = f.object.dg.module.getTarget();
58205832 const operation = if (inst_ty.isRuntimeFloat() and operand_ty.isRuntimeFloat())
58215833 if (inst_ty.floatBits(target) < operand_ty.floatBits(target)) "trunc" else "extend"
......@@ -5855,9 +5867,9 @@ fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue {
58555867 const un_op = f.air.instructions.items(.data)[inst].un_op;
58565868
58575869 const operand = try f.resolveInst(un_op);
5858 const operand_ty = f.air.typeOf(un_op);
5870 const operand_ty = f.typeOf(un_op);
58595871 try reap(f, inst, &.{un_op});
5860 const inst_ty = f.air.typeOfIndex(inst);
5872 const inst_ty = f.typeOfIndex(inst);
58615873 const writer = f.object.writer();
58625874 const local = try f.allocLocal(inst, inst_ty);
58635875 try f.writeCValue(writer, local, .Other);
......@@ -5885,9 +5897,9 @@ fn airUnBuiltinCall(
58855897
58865898 const operand = try f.resolveInst(ty_op.operand);
58875899 try reap(f, inst, &.{ty_op.operand});
5888 const inst_ty = f.air.typeOfIndex(inst);
5900 const inst_ty = f.typeOfIndex(inst);
58895901 const inst_scalar_ty = inst_ty.scalarType(mod);
5890 const operand_ty = f.air.typeOf(ty_op.operand);
5902 const operand_ty = f.typeOf(ty_op.operand);
58915903 const scalar_ty = operand_ty.scalarType(mod);
58925904
58935905 const inst_scalar_cty = try f.typeToCType(inst_scalar_ty, .complete);
......@@ -5927,7 +5939,7 @@ fn airBinBuiltinCall(
59275939 const mod = f.object.dg.module;
59285940 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
59295941
5930 const operand_ty = f.air.typeOf(bin_op.lhs);
5942 const operand_ty = f.typeOf(bin_op.lhs);
59315943 const operand_cty = try f.typeToCType(operand_ty, .complete);
59325944 const is_big = operand_cty.tag() == .array;
59335945
......@@ -5935,7 +5947,7 @@ fn airBinBuiltinCall(
59355947 const rhs = try f.resolveInst(bin_op.rhs);
59365948 if (!is_big) try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
59375949
5938 const inst_ty = f.air.typeOfIndex(inst);
5950 const inst_ty = f.typeOfIndex(inst);
59395951 const inst_scalar_ty = inst_ty.scalarType(mod);
59405952 const scalar_ty = operand_ty.scalarType(mod);
59415953
......@@ -5984,9 +5996,9 @@ fn airCmpBuiltinCall(
59845996 const rhs = try f.resolveInst(data.rhs);
59855997 try reap(f, inst, &.{ data.lhs, data.rhs });
59865998
5987 const inst_ty = f.air.typeOfIndex(inst);
5999 const inst_ty = f.typeOfIndex(inst);
59886000 const inst_scalar_ty = inst_ty.scalarType(mod);
5989 const operand_ty = f.air.typeOf(data.lhs);
6001 const operand_ty = f.typeOf(data.lhs);
59906002 const scalar_ty = operand_ty.scalarType(mod);
59916003
59926004 const inst_scalar_cty = try f.typeToCType(inst_scalar_ty, .complete);
......@@ -6032,11 +6044,11 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
60326044 const mod = f.object.dg.module;
60336045 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
60346046 const extra = f.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
6035 const inst_ty = f.air.typeOfIndex(inst);
6047 const inst_ty = f.typeOfIndex(inst);
60366048 const ptr = try f.resolveInst(extra.ptr);
60376049 const expected_value = try f.resolveInst(extra.expected_value);
60386050 const new_value = try f.resolveInst(extra.new_value);
6039 const ptr_ty = f.air.typeOf(extra.ptr);
6051 const ptr_ty = f.typeOf(extra.ptr);
60406052 const ty = ptr_ty.childType();
60416053
60426054 const writer = f.object.writer();
......@@ -6137,8 +6149,8 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
61376149 const mod = f.object.dg.module;
61386150 const pl_op = f.air.instructions.items(.data)[inst].pl_op;
61396151 const extra = f.air.extraData(Air.AtomicRmw, pl_op.payload).data;
6140 const inst_ty = f.air.typeOfIndex(inst);
6141 const ptr_ty = f.air.typeOf(pl_op.operand);
6152 const inst_ty = f.typeOfIndex(inst);
6153 const ptr_ty = f.typeOf(pl_op.operand);
61426154 const ty = ptr_ty.childType();
61436155 const ptr = try f.resolveInst(pl_op.operand);
61446156 const operand = try f.resolveInst(extra.operand);
......@@ -6193,7 +6205,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
61936205 const atomic_load = f.air.instructions.items(.data)[inst].atomic_load;
61946206 const ptr = try f.resolveInst(atomic_load.ptr);
61956207 try reap(f, inst, &.{atomic_load.ptr});
6196 const ptr_ty = f.air.typeOf(atomic_load.ptr);
6208 const ptr_ty = f.typeOf(atomic_load.ptr);
61976209 const ty = ptr_ty.childType();
61986210
61996211 const repr_ty = if (ty.isRuntimeFloat())
......@@ -6201,7 +6213,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
62016213 else
62026214 ty;
62036215
6204 const inst_ty = f.air.typeOfIndex(inst);
6216 const inst_ty = f.typeOfIndex(inst);
62056217 const writer = f.object.writer();
62066218 const local = try f.allocLocal(inst, inst_ty);
62076219
......@@ -6227,7 +6239,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
62276239fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CValue {
62286240 const mod = f.object.dg.module;
62296241 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
6230 const ptr_ty = f.air.typeOf(bin_op.lhs);
6242 const ptr_ty = f.typeOf(bin_op.lhs);
62316243 const ty = ptr_ty.childType();
62326244 const ptr = try f.resolveInst(bin_op.lhs);
62336245 const element = try f.resolveInst(bin_op.rhs);
......@@ -6270,10 +6282,10 @@ fn writeSliceOrPtr(f: *Function, writer: anytype, ptr: CValue, ptr_ty: Type) !vo
62706282fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
62716283 const mod = f.object.dg.module;
62726284 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
6273 const dest_ty = f.air.typeOf(bin_op.lhs);
6285 const dest_ty = f.typeOf(bin_op.lhs);
62746286 const dest_slice = try f.resolveInst(bin_op.lhs);
62756287 const value = try f.resolveInst(bin_op.rhs);
6276 const elem_ty = f.air.typeOf(bin_op.rhs);
6288 const elem_ty = f.typeOf(bin_op.rhs);
62776289 const elem_abi_size = elem_ty.abiSize(mod);
62786290 const val_is_undef = if (f.air.value(bin_op.rhs, mod)) |val| val.isUndefDeep() else false;
62796291 const writer = f.object.writer();
......@@ -6393,8 +6405,8 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
63936405 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
63946406 const dest_ptr = try f.resolveInst(bin_op.lhs);
63956407 const src_ptr = try f.resolveInst(bin_op.rhs);
6396 const dest_ty = f.air.typeOf(bin_op.lhs);
6397 const src_ty = f.air.typeOf(bin_op.rhs);
6408 const dest_ty = f.typeOf(bin_op.lhs);
6409 const src_ty = f.typeOf(bin_op.rhs);
63986410 const writer = f.object.writer();
63996411
64006412 try writer.writeAll("memcpy(");
......@@ -6434,7 +6446,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
64346446 const new_tag = try f.resolveInst(bin_op.rhs);
64356447 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
64366448
6437 const union_ty = f.air.typeOf(bin_op.lhs).childType();
6449 const union_ty = f.typeOf(bin_op.lhs).childType();
64386450 const layout = union_ty.unionGetLayout(mod);
64396451 if (layout.tag_size == 0) return .none;
64406452 const tag_ty = union_ty.unionTagTypeSafety().?;
......@@ -6455,11 +6467,11 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
64556467 const operand = try f.resolveInst(ty_op.operand);
64566468 try reap(f, inst, &.{ty_op.operand});
64576469
6458 const union_ty = f.air.typeOf(ty_op.operand);
6470 const union_ty = f.typeOf(ty_op.operand);
64596471 const layout = union_ty.unionGetLayout(mod);
64606472 if (layout.tag_size == 0) return .none;
64616473
6462 const inst_ty = f.air.typeOfIndex(inst);
6474 const inst_ty = f.typeOfIndex(inst);
64636475 const writer = f.object.writer();
64646476 const local = try f.allocLocal(inst, inst_ty);
64656477 const a = try Assignment.start(f, writer, inst_ty);
......@@ -6473,8 +6485,8 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
64736485fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue {
64746486 const un_op = f.air.instructions.items(.data)[inst].un_op;
64756487
6476 const inst_ty = f.air.typeOfIndex(inst);
6477 const enum_ty = f.air.typeOf(un_op);
6488 const inst_ty = f.typeOfIndex(inst);
6489 const enum_ty = f.typeOf(un_op);
64786490 const operand = try f.resolveInst(un_op);
64796491 try reap(f, inst, &.{un_op});
64806492
......@@ -6494,7 +6506,7 @@ fn airErrorName(f: *Function, inst: Air.Inst.Index) !CValue {
64946506 const un_op = f.air.instructions.items(.data)[inst].un_op;
64956507
64966508 const writer = f.object.writer();
6497 const inst_ty = f.air.typeOfIndex(inst);
6509 const inst_ty = f.typeOfIndex(inst);
64986510 const operand = try f.resolveInst(un_op);
64996511 try reap(f, inst, &.{un_op});
65006512 const local = try f.allocLocal(inst, inst_ty);
......@@ -6513,7 +6525,7 @@ fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue {
65136525 const operand = try f.resolveInst(ty_op.operand);
65146526 try reap(f, inst, &.{ty_op.operand});
65156527
6516 const inst_ty = f.air.typeOfIndex(inst);
6528 const inst_ty = f.typeOfIndex(inst);
65176529 const inst_scalar_ty = inst_ty.scalarType(mod);
65186530
65196531 const writer = f.object.writer();
......@@ -6539,7 +6551,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue {
65396551 const rhs = try f.resolveInst(extra.rhs);
65406552 try reap(f, inst, &.{ pl_op.operand, extra.lhs, extra.rhs });
65416553
6542 const inst_ty = f.air.typeOfIndex(inst);
6554 const inst_ty = f.typeOfIndex(inst);
65436555
65446556 const writer = f.object.writer();
65456557 const local = try f.allocLocal(inst, inst_ty);
......@@ -6570,7 +6582,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
65706582 const lhs = try f.resolveInst(extra.a);
65716583 const rhs = try f.resolveInst(extra.b);
65726584
6573 const inst_ty = f.air.typeOfIndex(inst);
6585 const inst_ty = f.typeOfIndex(inst);
65746586
65756587 const writer = f.object.writer();
65766588 const local = try f.allocLocal(inst, inst_ty);
......@@ -6607,10 +6619,10 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
66076619 const reduce = f.air.instructions.items(.data)[inst].reduce;
66086620
66096621 const target = mod.getTarget();
6610 const scalar_ty = f.air.typeOfIndex(inst);
6622 const scalar_ty = f.typeOfIndex(inst);
66116623 const operand = try f.resolveInst(reduce.operand);
66126624 try reap(f, inst, &.{reduce.operand});
6613 const operand_ty = f.air.typeOf(reduce.operand);
6625 const operand_ty = f.typeOf(reduce.operand);
66146626 const writer = f.object.writer();
66156627
66166628 const use_operator = scalar_ty.bitSize(mod) <= 64;
......@@ -6762,7 +6774,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
67626774fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
67636775 const mod = f.object.dg.module;
67646776 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
6765 const inst_ty = f.air.typeOfIndex(inst);
6777 const inst_ty = f.typeOfIndex(inst);
67666778 const len = @intCast(usize, inst_ty.arrayLen());
67676779 const elements = @ptrCast([]const Air.Inst.Ref, f.air.extra[ty_pl.payload..][0..len]);
67686780 const gpa = f.object.dg.gpa;
......@@ -6892,10 +6904,10 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
68926904 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
68936905 const extra = f.air.extraData(Air.UnionInit, ty_pl.payload).data;
68946906
6895 const union_ty = f.air.typeOfIndex(inst);
6907 const union_ty = f.typeOfIndex(inst);
68966908 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
68976909 const field_name = union_obj.fields.keys()[extra.field_index];
6898 const payload_ty = f.air.typeOf(extra.init);
6910 const payload_ty = f.typeOf(extra.init);
68996911 const payload = try f.resolveInst(extra.init);
69006912 try reap(f, inst, &.{extra.init});
69016913
......@@ -6965,7 +6977,7 @@ fn airWasmMemorySize(f: *Function, inst: Air.Inst.Index) !CValue {
69656977 const pl_op = f.air.instructions.items(.data)[inst].pl_op;
69666978
69676979 const writer = f.object.writer();
6968 const inst_ty = f.air.typeOfIndex(inst);
6980 const inst_ty = f.typeOfIndex(inst);
69696981 const local = try f.allocLocal(inst, inst_ty);
69706982 try f.writeCValue(writer, local, .Other);
69716983
......@@ -6979,7 +6991,7 @@ fn airWasmMemoryGrow(f: *Function, inst: Air.Inst.Index) !CValue {
69796991 const pl_op = f.air.instructions.items(.data)[inst].pl_op;
69806992
69816993 const writer = f.object.writer();
6982 const inst_ty = f.air.typeOfIndex(inst);
6994 const inst_ty = f.typeOfIndex(inst);
69836995 const operand = try f.resolveInst(pl_op.operand);
69846996 try reap(f, inst, &.{pl_op.operand});
69856997 const local = try f.allocLocal(inst, inst_ty);
......@@ -6999,7 +7011,7 @@ fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue {
69997011 const operand = try f.resolveInst(un_op);
70007012 try reap(f, inst, &.{un_op});
70017013
7002 const operand_ty = f.air.typeOf(un_op);
7014 const operand_ty = f.typeOf(un_op);
70037015 const scalar_ty = operand_ty.scalarType(mod);
70047016
70057017 const writer = f.object.writer();
......@@ -7025,7 +7037,7 @@ fn airUnFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVal
70257037 const operand = try f.resolveInst(un_op);
70267038 try reap(f, inst, &.{un_op});
70277039
7028 const inst_ty = f.air.typeOfIndex(inst);
7040 const inst_ty = f.typeOfIndex(inst);
70297041 const inst_scalar_ty = inst_ty.scalarType(mod);
70307042
70317043 const writer = f.object.writer();
......@@ -7054,7 +7066,7 @@ fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVa
70547066 const rhs = try f.resolveInst(bin_op.rhs);
70557067 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
70567068
7057 const inst_ty = f.air.typeOfIndex(inst);
7069 const inst_ty = f.typeOfIndex(inst);
70587070 const inst_scalar_ty = inst_ty.scalarType(mod);
70597071
70607072 const writer = f.object.writer();
......@@ -7088,7 +7100,7 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue {
70887100 const addend = try f.resolveInst(pl_op.operand);
70897101 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs, pl_op.operand });
70907102
7091 const inst_ty = f.air.typeOfIndex(inst);
7103 const inst_ty = f.typeOfIndex(inst);
70927104 const inst_scalar_ty = inst_ty.scalarType(mod);
70937105
70947106 const writer = f.object.writer();
......@@ -7114,7 +7126,7 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue {
71147126}
71157127
71167128fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue {
7117 const inst_ty = f.air.typeOfIndex(inst);
7129 const inst_ty = f.typeOfIndex(inst);
71187130 const fn_cty = try f.typeToCType(f.object.dg.decl.?.ty, .complete);
71197131 const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len;
71207132
......@@ -7133,7 +7145,7 @@ fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue {
71337145fn airCVaArg(f: *Function, inst: Air.Inst.Index) !CValue {
71347146 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
71357147
7136 const inst_ty = f.air.typeOfIndex(inst);
7148 const inst_ty = f.typeOfIndex(inst);
71377149 const va_list = try f.resolveInst(ty_op.operand);
71387150 try reap(f, inst, &.{ty_op.operand});
71397151
......@@ -7164,7 +7176,7 @@ fn airCVaEnd(f: *Function, inst: Air.Inst.Index) !CValue {
71647176fn airCVaCopy(f: *Function, inst: Air.Inst.Index) !CValue {
71657177 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
71667178
7167 const inst_ty = f.air.typeOfIndex(inst);
7179 const inst_ty = f.typeOfIndex(inst);
71687180 const va_list = try f.resolveInst(ty_op.operand);
71697181 try reap(f, inst, &.{ty_op.operand});
71707182
src/codegen/llvm.zig+156-143
......@@ -4497,7 +4497,7 @@ pub const FuncGen = struct {
44974497
44984498 const mod = self.dg.module;
44994499 const llvm_val = try self.resolveValue(.{
4500 .ty = self.air.typeOf(inst),
4500 .ty = self.typeOf(inst),
45014501 .val = self.air.value(inst, mod).?,
45024502 });
45034503 gop.value_ptr.* = llvm_val;
......@@ -4528,11 +4528,12 @@ pub const FuncGen = struct {
45284528 }
45294529
45304530 fn genBody(self: *FuncGen, body: []const Air.Inst.Index) Error!void {
4531 const mod = self.dg.module;
4532 const ip = &mod.intern_pool;
45314533 const air_tags = self.air.instructions.items(.tag);
45324534 for (body, 0..) |inst, i| {
4533 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst)) {
4535 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
45344536 continue;
4535 }
45364537
45374538 const opt_value: ?*llvm.Value = switch (air_tags[inst]) {
45384539 // zig fmt: off
......@@ -4751,6 +4752,8 @@ pub const FuncGen = struct {
47514752
47524753 .constant => unreachable,
47534754 .const_ty => unreachable,
4755 .interned => unreachable,
4756
47544757 .unreach => self.airUnreach(inst),
47554758 .dbg_stmt => self.airDbgStmt(inst),
47564759 .dbg_inline_begin => try self.airDbgInlineBegin(inst),
......@@ -4781,7 +4784,7 @@ pub const FuncGen = struct {
47814784 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
47824785 const extra = self.air.extraData(Air.Call, pl_op.payload);
47834786 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);
4784 const callee_ty = self.air.typeOf(pl_op.operand);
4787 const callee_ty = self.typeOf(pl_op.operand);
47854788 const mod = self.dg.module;
47864789 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {
47874790 .Fn => callee_ty,
......@@ -4815,7 +4818,7 @@ pub const FuncGen = struct {
48154818 .no_bits => continue,
48164819 .byval => {
48174820 const arg = args[it.zig_index - 1];
4818 const param_ty = self.air.typeOf(arg);
4821 const param_ty = self.typeOf(arg);
48194822 const llvm_arg = try self.resolveInst(arg);
48204823 const llvm_param_ty = try self.dg.lowerType(param_ty);
48214824 if (isByRef(param_ty, mod)) {
......@@ -4829,7 +4832,7 @@ pub const FuncGen = struct {
48294832 },
48304833 .byref => {
48314834 const arg = args[it.zig_index - 1];
4832 const param_ty = self.air.typeOf(arg);
4835 const param_ty = self.typeOf(arg);
48334836 const llvm_arg = try self.resolveInst(arg);
48344837 if (isByRef(param_ty, mod)) {
48354838 try llvm_args.append(llvm_arg);
......@@ -4844,7 +4847,7 @@ pub const FuncGen = struct {
48444847 },
48454848 .byref_mut => {
48464849 const arg = args[it.zig_index - 1];
4847 const param_ty = self.air.typeOf(arg);
4850 const param_ty = self.typeOf(arg);
48484851 const llvm_arg = try self.resolveInst(arg);
48494852
48504853 const alignment = param_ty.abiAlignment(mod);
......@@ -4865,7 +4868,7 @@ pub const FuncGen = struct {
48654868 },
48664869 .abi_sized_int => {
48674870 const arg = args[it.zig_index - 1];
4868 const param_ty = self.air.typeOf(arg);
4871 const param_ty = self.typeOf(arg);
48694872 const llvm_arg = try self.resolveInst(arg);
48704873 const abi_size = @intCast(c_uint, param_ty.abiSize(mod));
48714874 const int_llvm_ty = self.context.intType(abi_size * 8);
......@@ -4901,7 +4904,7 @@ pub const FuncGen = struct {
49014904 },
49024905 .multiple_llvm_types => {
49034906 const arg = args[it.zig_index - 1];
4904 const param_ty = self.air.typeOf(arg);
4907 const param_ty = self.typeOf(arg);
49054908 const llvm_types = it.llvm_types_buffer[0..it.llvm_types_len];
49064909 const llvm_arg = try self.resolveInst(arg);
49074910 const is_by_ref = isByRef(param_ty, mod);
......@@ -4930,7 +4933,7 @@ pub const FuncGen = struct {
49304933 },
49314934 .float_array => |count| {
49324935 const arg = args[it.zig_index - 1];
4933 const arg_ty = self.air.typeOf(arg);
4936 const arg_ty = self.typeOf(arg);
49344937 var llvm_arg = try self.resolveInst(arg);
49354938 if (!isByRef(arg_ty, mod)) {
49364939 const p = self.buildAlloca(llvm_arg.typeOf(), null);
......@@ -4950,7 +4953,7 @@ pub const FuncGen = struct {
49504953 .i32_array, .i64_array => |arr_len| {
49514954 const elem_size: u8 = if (lowering == .i32_array) 32 else 64;
49524955 const arg = args[it.zig_index - 1];
4953 const arg_ty = self.air.typeOf(arg);
4956 const arg_ty = self.typeOf(arg);
49544957 var llvm_arg = try self.resolveInst(arg);
49554958 if (!isByRef(arg_ty, mod)) {
49564959 const p = self.buildAlloca(llvm_arg.typeOf(), null);
......@@ -5094,7 +5097,7 @@ pub const FuncGen = struct {
50945097 fn airRet(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
50955098 const mod = self.dg.module;
50965099 const un_op = self.air.instructions.items(.data)[inst].un_op;
5097 const ret_ty = self.air.typeOf(un_op);
5100 const ret_ty = self.typeOf(un_op);
50985101 if (self.ret_ptr) |ret_ptr| {
50995102 const operand = try self.resolveInst(un_op);
51005103 var ptr_ty_payload: Type.Payload.ElemType = .{
......@@ -5150,7 +5153,7 @@ pub const FuncGen = struct {
51505153
51515154 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
51525155 const un_op = self.air.instructions.items(.data)[inst].un_op;
5153 const ptr_ty = self.air.typeOf(un_op);
5156 const ptr_ty = self.typeOf(un_op);
51545157 const ret_ty = ptr_ty.childType();
51555158 const fn_info = self.dg.decl.ty.fnInfo();
51565159 const mod = self.dg.module;
......@@ -5236,7 +5239,7 @@ pub const FuncGen = struct {
52365239
52375240 fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
52385241 const mod = self.dg.module;
5239 const va_list_ty = self.air.typeOfIndex(inst);
5242 const va_list_ty = self.typeOfIndex(inst);
52405243 const llvm_va_list_ty = try self.dg.lowerType(va_list_ty);
52415244
52425245 const result_alignment = va_list_ty.abiAlignment(mod);
......@@ -5266,7 +5269,7 @@ pub const FuncGen = struct {
52665269 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
52675270 const lhs = try self.resolveInst(bin_op.lhs);
52685271 const rhs = try self.resolveInst(bin_op.rhs);
5269 const operand_ty = self.air.typeOf(bin_op.lhs);
5272 const operand_ty = self.typeOf(bin_op.lhs);
52705273
52715274 return self.cmp(lhs, rhs, operand_ty, op);
52725275 }
......@@ -5279,7 +5282,7 @@ pub const FuncGen = struct {
52795282
52805283 const lhs = try self.resolveInst(extra.lhs);
52815284 const rhs = try self.resolveInst(extra.rhs);
5282 const vec_ty = self.air.typeOf(extra.lhs);
5285 const vec_ty = self.typeOf(extra.lhs);
52835286 const cmp_op = extra.compareOperator();
52845287
52855288 return self.cmp(lhs, rhs, vec_ty, cmp_op);
......@@ -5396,12 +5399,12 @@ pub const FuncGen = struct {
53965399 }
53975400
53985401 fn airBlock(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
5402 const mod = self.dg.module;
53995403 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
54005404 const extra = self.air.extraData(Air.Block, ty_pl.payload);
54015405 const body = self.air.extra[extra.end..][0..extra.data.body_len];
5402 const inst_ty = self.air.typeOfIndex(inst);
5406 const inst_ty = self.typeOfIndex(inst);
54035407 const parent_bb = self.context.createBasicBlock("Block");
5404 const mod = self.dg.module;
54055408
54065409 if (inst_ty.isNoReturn()) {
54075410 try self.genBody(body);
......@@ -5453,7 +5456,7 @@ pub const FuncGen = struct {
54535456 const block = self.blocks.get(branch.block_inst).?;
54545457
54555458 // Add the values to the lists only if the break provides a value.
5456 const operand_ty = self.air.typeOf(branch.operand);
5459 const operand_ty = self.typeOf(branch.operand);
54575460 const mod = self.dg.module;
54585461 if (operand_ty.hasRuntimeBitsIgnoreComptime(mod) or operand_ty.zigTypeTag(mod) == .Fn) {
54595462 const val = try self.resolveInst(branch.operand);
......@@ -5497,8 +5500,8 @@ pub const FuncGen = struct {
54975500 const err_union = try self.resolveInst(pl_op.operand);
54985501 const extra = self.air.extraData(Air.Try, pl_op.payload);
54995502 const body = self.air.extra[extra.end..][0..extra.data.body_len];
5500 const err_union_ty = self.air.typeOf(pl_op.operand);
5501 const payload_ty = self.air.typeOfIndex(inst);
5503 const err_union_ty = self.typeOf(pl_op.operand);
5504 const payload_ty = self.typeOfIndex(inst);
55025505 const can_elide_load = if (isByRef(payload_ty, mod)) self.canElideLoad(body_tail) else false;
55035506 const is_unused = self.liveness.isUnused(inst);
55045507 return lowerTry(self, err_union, body, err_union_ty, false, can_elide_load, is_unused);
......@@ -5509,7 +5512,7 @@ pub const FuncGen = struct {
55095512 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
55105513 const err_union_ptr = try self.resolveInst(extra.data.ptr);
55115514 const body = self.air.extra[extra.end..][0..extra.data.body_len];
5512 const err_union_ty = self.air.typeOf(extra.data.ptr).childType();
5515 const err_union_ty = self.typeOf(extra.data.ptr).childType();
55135516 const is_unused = self.liveness.isUnused(inst);
55145517 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused);
55155518 }
......@@ -5650,7 +5653,7 @@ pub const FuncGen = struct {
56505653 // would have been emitted already. Also the main loop in genBody can
56515654 // be while(true) instead of for(body), which will eliminate 1 branch on
56525655 // a hot path.
5653 if (body.len == 0 or !self.air.typeOfIndex(body[body.len - 1]).isNoReturn()) {
5656 if (body.len == 0 or !self.typeOfIndex(body[body.len - 1]).isNoReturn()) {
56545657 _ = self.builder.buildBr(loop_block);
56555658 }
56565659 return null;
......@@ -5659,11 +5662,11 @@ pub const FuncGen = struct {
56595662 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
56605663 const mod = self.dg.module;
56615664 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
5662 const operand_ty = self.air.typeOf(ty_op.operand);
5665 const operand_ty = self.typeOf(ty_op.operand);
56635666 const array_ty = operand_ty.childType();
56645667 const llvm_usize = try self.dg.lowerType(Type.usize);
56655668 const len = llvm_usize.constInt(array_ty.arrayLen(), .False);
5666 const slice_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst));
5669 const slice_llvm_ty = try self.dg.lowerType(self.typeOfIndex(inst));
56675670 const operand = try self.resolveInst(ty_op.operand);
56685671 if (!array_ty.hasRuntimeBitsIgnoreComptime(mod)) {
56695672 const partial = self.builder.buildInsertValue(slice_llvm_ty.getUndef(), operand, 0, "");
......@@ -5683,10 +5686,10 @@ pub const FuncGen = struct {
56835686 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
56845687
56855688 const operand = try self.resolveInst(ty_op.operand);
5686 const operand_ty = self.air.typeOf(ty_op.operand);
5689 const operand_ty = self.typeOf(ty_op.operand);
56875690 const operand_scalar_ty = operand_ty.scalarType(mod);
56885691
5689 const dest_ty = self.air.typeOfIndex(inst);
5692 const dest_ty = self.typeOfIndex(inst);
56905693 const dest_scalar_ty = dest_ty.scalarType(mod);
56915694 const dest_llvm_ty = try self.dg.lowerType(dest_ty);
56925695 const target = mod.getTarget();
......@@ -5743,10 +5746,10 @@ pub const FuncGen = struct {
57435746 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
57445747
57455748 const operand = try self.resolveInst(ty_op.operand);
5746 const operand_ty = self.air.typeOf(ty_op.operand);
5749 const operand_ty = self.typeOf(ty_op.operand);
57475750 const operand_scalar_ty = operand_ty.scalarType(mod);
57485751
5749 const dest_ty = self.air.typeOfIndex(inst);
5752 const dest_ty = self.typeOfIndex(inst);
57505753 const dest_scalar_ty = dest_ty.scalarType(mod);
57515754 const dest_llvm_ty = try self.dg.lowerType(dest_ty);
57525755
......@@ -5832,7 +5835,7 @@ pub const FuncGen = struct {
58325835 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !?*llvm.Value {
58335836 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
58345837 const slice_ptr = try self.resolveInst(ty_op.operand);
5835 const slice_ptr_ty = self.air.typeOf(ty_op.operand);
5838 const slice_ptr_ty = self.typeOf(ty_op.operand);
58365839 const slice_llvm_ty = try self.dg.lowerPtrElemTy(slice_ptr_ty.childType());
58375840
58385841 return self.builder.buildStructGEP(slice_llvm_ty, slice_ptr, index, "");
......@@ -5842,7 +5845,7 @@ pub const FuncGen = struct {
58425845 const mod = self.dg.module;
58435846 const inst = body_tail[0];
58445847 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
5845 const slice_ty = self.air.typeOf(bin_op.lhs);
5848 const slice_ty = self.typeOf(bin_op.lhs);
58465849 const slice = try self.resolveInst(bin_op.lhs);
58475850 const index = try self.resolveInst(bin_op.rhs);
58485851 const elem_ty = slice_ty.childType();
......@@ -5863,7 +5866,7 @@ pub const FuncGen = struct {
58635866 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
58645867 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
58655868 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
5866 const slice_ty = self.air.typeOf(bin_op.lhs);
5869 const slice_ty = self.typeOf(bin_op.lhs);
58675870
58685871 const slice = try self.resolveInst(bin_op.lhs);
58695872 const index = try self.resolveInst(bin_op.rhs);
......@@ -5878,7 +5881,7 @@ pub const FuncGen = struct {
58785881 const inst = body_tail[0];
58795882
58805883 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
5881 const array_ty = self.air.typeOf(bin_op.lhs);
5884 const array_ty = self.typeOf(bin_op.lhs);
58825885 const array_llvm_val = try self.resolveInst(bin_op.lhs);
58835886 const rhs = try self.resolveInst(bin_op.rhs);
58845887 const array_llvm_ty = try self.dg.lowerType(array_ty);
......@@ -5920,7 +5923,7 @@ pub const FuncGen = struct {
59205923 const mod = self.dg.module;
59215924 const inst = body_tail[0];
59225925 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
5923 const ptr_ty = self.air.typeOf(bin_op.lhs);
5926 const ptr_ty = self.typeOf(bin_op.lhs);
59245927 const elem_ty = ptr_ty.childType();
59255928 const llvm_elem_ty = try self.dg.lowerPtrElemTy(elem_ty);
59265929 const base_ptr = try self.resolveInst(bin_op.lhs);
......@@ -5948,7 +5951,7 @@ pub const FuncGen = struct {
59485951 const mod = self.dg.module;
59495952 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
59505953 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
5951 const ptr_ty = self.air.typeOf(bin_op.lhs);
5954 const ptr_ty = self.typeOf(bin_op.lhs);
59525955 const elem_ty = ptr_ty.childType();
59535956 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return self.dg.lowerPtrToVoid(ptr_ty);
59545957
......@@ -5973,7 +5976,7 @@ pub const FuncGen = struct {
59735976 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
59745977 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
59755978 const struct_ptr = try self.resolveInst(struct_field.struct_operand);
5976 const struct_ptr_ty = self.air.typeOf(struct_field.struct_operand);
5979 const struct_ptr_ty = self.typeOf(struct_field.struct_operand);
59775980 return self.fieldPtr(inst, struct_ptr, struct_ptr_ty, struct_field.field_index);
59785981 }
59795982
......@@ -5984,7 +5987,7 @@ pub const FuncGen = struct {
59845987 ) !?*llvm.Value {
59855988 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
59865989 const struct_ptr = try self.resolveInst(ty_op.operand);
5987 const struct_ptr_ty = self.air.typeOf(ty_op.operand);
5990 const struct_ptr_ty = self.typeOf(ty_op.operand);
59885991 return self.fieldPtr(inst, struct_ptr, struct_ptr_ty, field_index);
59895992 }
59905993
......@@ -5993,7 +5996,7 @@ pub const FuncGen = struct {
59935996 const inst = body_tail[0];
59945997 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
59955998 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
5996 const struct_ty = self.air.typeOf(struct_field.struct_operand);
5999 const struct_ty = self.typeOf(struct_field.struct_operand);
59976000 const struct_llvm_val = try self.resolveInst(struct_field.struct_operand);
59986001 const field_index = struct_field.field_index;
59996002 const field_ty = struct_ty.structFieldType(field_index);
......@@ -6234,7 +6237,7 @@ pub const FuncGen = struct {
62346237 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
62356238 const operand = try self.resolveInst(pl_op.operand);
62366239 const name = self.air.nullTerminatedString(pl_op.payload);
6237 const ptr_ty = self.air.typeOf(pl_op.operand);
6240 const ptr_ty = self.typeOf(pl_op.operand);
62386241
62396242 const di_local_var = dib.createAutoVariable(
62406243 self.di_scope.?,
......@@ -6259,7 +6262,7 @@ pub const FuncGen = struct {
62596262 const dib = self.dg.object.di_builder orelse return null;
62606263 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
62616264 const operand = try self.resolveInst(pl_op.operand);
6262 const operand_ty = self.air.typeOf(pl_op.operand);
6265 const operand_ty = self.typeOf(pl_op.operand);
62636266 const name = self.air.nullTerminatedString(pl_op.payload);
62646267
62656268 if (needDbgVarWorkaround(self.dg)) {
......@@ -6361,7 +6364,7 @@ pub const FuncGen = struct {
63616364 llvm_ret_indirect[i] = (output != .none) and constraintAllowsMemory(constraint);
63626365 if (output != .none) {
63636366 const output_inst = try self.resolveInst(output);
6364 const output_ty = self.air.typeOf(output);
6367 const output_ty = self.typeOf(output);
63656368 assert(output_ty.zigTypeTag(mod) == .Pointer);
63666369 const elem_llvm_ty = try self.dg.lowerPtrElemTy(output_ty.childType());
63676370
......@@ -6379,7 +6382,7 @@ pub const FuncGen = struct {
63796382 llvm_ret_i += 1;
63806383 }
63816384 } else {
6382 const ret_ty = self.air.typeOfIndex(inst);
6385 const ret_ty = self.typeOfIndex(inst);
63836386 llvm_ret_types[llvm_ret_i] = try self.dg.lowerType(ret_ty);
63846387 llvm_ret_i += 1;
63856388 }
......@@ -6414,7 +6417,7 @@ pub const FuncGen = struct {
64146417 extra_i += (constraint.len + name.len + (2 + 3)) / 4;
64156418
64166419 const arg_llvm_value = try self.resolveInst(input);
6417 const arg_ty = self.air.typeOf(input);
6420 const arg_ty = self.typeOf(input);
64186421 var llvm_elem_ty: ?*llvm.Type = null;
64196422 if (isByRef(arg_ty, mod)) {
64206423 llvm_elem_ty = try self.dg.lowerPtrElemTy(arg_ty);
......@@ -6636,7 +6639,7 @@ pub const FuncGen = struct {
66366639
66376640 if (output != .none) {
66386641 const output_ptr = try self.resolveInst(output);
6639 const output_ptr_ty = self.air.typeOf(output);
6642 const output_ptr_ty = self.typeOf(output);
66406643
66416644 const store_inst = self.builder.buildStore(output_value, output_ptr);
66426645 store_inst.setAlignment(output_ptr_ty.ptrAlignment(mod));
......@@ -6657,7 +6660,7 @@ pub const FuncGen = struct {
66576660 ) !?*llvm.Value {
66586661 const un_op = self.air.instructions.items(.data)[inst].un_op;
66596662 const operand = try self.resolveInst(un_op);
6660 const operand_ty = self.air.typeOf(un_op);
6663 const operand_ty = self.typeOf(un_op);
66616664 const optional_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
66626665 const optional_llvm_ty = try self.dg.lowerType(optional_ty);
66636666 var buf: Type.Payload.ElemType = undefined;
......@@ -6706,7 +6709,7 @@ pub const FuncGen = struct {
67066709 const mod = self.dg.module;
67076710 const un_op = self.air.instructions.items(.data)[inst].un_op;
67086711 const operand = try self.resolveInst(un_op);
6709 const operand_ty = self.air.typeOf(un_op);
6712 const operand_ty = self.typeOf(un_op);
67106713 const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
67116714 const payload_ty = err_union_ty.errorUnionPayload();
67126715 const err_set_ty = try self.dg.lowerType(Type.anyerror);
......@@ -6746,7 +6749,7 @@ pub const FuncGen = struct {
67466749 const mod = self.dg.module;
67476750 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
67486751 const operand = try self.resolveInst(ty_op.operand);
6749 const optional_ty = self.air.typeOf(ty_op.operand).childType();
6752 const optional_ty = self.typeOf(ty_op.operand).childType();
67506753 var buf: Type.Payload.ElemType = undefined;
67516754 const payload_ty = optional_ty.optionalChild(&buf);
67526755 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -6768,7 +6771,7 @@ pub const FuncGen = struct {
67686771 const mod = self.dg.module;
67696772 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
67706773 const operand = try self.resolveInst(ty_op.operand);
6771 const optional_ty = self.air.typeOf(ty_op.operand).childType();
6774 const optional_ty = self.typeOf(ty_op.operand).childType();
67726775 var buf: Type.Payload.ElemType = undefined;
67736776 const payload_ty = optional_ty.optionalChild(&buf);
67746777 const non_null_bit = self.context.intType(8).constInt(1, .False);
......@@ -6801,8 +6804,8 @@ pub const FuncGen = struct {
68016804 const inst = body_tail[0];
68026805 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
68036806 const operand = try self.resolveInst(ty_op.operand);
6804 const optional_ty = self.air.typeOf(ty_op.operand);
6805 const payload_ty = self.air.typeOfIndex(inst);
6807 const optional_ty = self.typeOf(ty_op.operand);
6808 const payload_ty = self.typeOfIndex(inst);
68066809 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) return null;
68076810
68086811 if (optional_ty.optionalReprIsPayload(mod)) {
......@@ -6824,9 +6827,9 @@ pub const FuncGen = struct {
68246827 const inst = body_tail[0];
68256828 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
68266829 const operand = try self.resolveInst(ty_op.operand);
6827 const operand_ty = self.air.typeOf(ty_op.operand);
6830 const operand_ty = self.typeOf(ty_op.operand);
68286831 const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
6829 const result_ty = self.air.typeOfIndex(inst);
6832 const result_ty = self.typeOfIndex(inst);
68306833 const payload_ty = if (operand_is_ptr) result_ty.childType() else result_ty;
68316834
68326835 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -6859,7 +6862,7 @@ pub const FuncGen = struct {
68596862 const mod = self.dg.module;
68606863 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
68616864 const operand = try self.resolveInst(ty_op.operand);
6862 const operand_ty = self.air.typeOf(ty_op.operand);
6865 const operand_ty = self.typeOf(ty_op.operand);
68636866 const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
68646867 if (err_union_ty.errorUnionSet().errorSetIsEmpty()) {
68656868 const err_llvm_ty = try self.dg.lowerType(Type.anyerror);
......@@ -6893,7 +6896,7 @@ pub const FuncGen = struct {
68936896 const mod = self.dg.module;
68946897 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
68956898 const operand = try self.resolveInst(ty_op.operand);
6896 const err_union_ty = self.air.typeOf(ty_op.operand).childType();
6899 const err_union_ty = self.typeOf(ty_op.operand).childType();
68976900
68986901 const payload_ty = err_union_ty.errorUnionPayload();
68996902 const non_error_val = try self.dg.lowerValue(.{ .ty = Type.anyerror, .val = Value.zero });
......@@ -6946,12 +6949,12 @@ pub const FuncGen = struct {
69466949 fn airWrapOptional(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
69476950 const mod = self.dg.module;
69486951 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
6949 const payload_ty = self.air.typeOf(ty_op.operand);
6952 const payload_ty = self.typeOf(ty_op.operand);
69506953 const non_null_bit = self.context.intType(8).constInt(1, .False);
69516954 comptime assert(optional_layout_version == 3);
69526955 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) return non_null_bit;
69536956 const operand = try self.resolveInst(ty_op.operand);
6954 const optional_ty = self.air.typeOfIndex(inst);
6957 const optional_ty = self.typeOfIndex(inst);
69556958 if (optional_ty.optionalReprIsPayload(mod)) {
69566959 return operand;
69576960 }
......@@ -6976,9 +6979,9 @@ pub const FuncGen = struct {
69766979 fn airWrapErrUnionPayload(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
69776980 const mod = self.dg.module;
69786981 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
6979 const err_un_ty = self.air.typeOfIndex(inst);
6982 const err_un_ty = self.typeOfIndex(inst);
69806983 const operand = try self.resolveInst(ty_op.operand);
6981 const payload_ty = self.air.typeOf(ty_op.operand);
6984 const payload_ty = self.typeOf(ty_op.operand);
69826985 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
69836986 return operand;
69846987 }
......@@ -7009,7 +7012,7 @@ pub const FuncGen = struct {
70097012 fn airWrapErrUnionErr(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
70107013 const mod = self.dg.module;
70117014 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
7012 const err_un_ty = self.air.typeOfIndex(inst);
7015 const err_un_ty = self.typeOfIndex(inst);
70137016 const payload_ty = err_un_ty.errorUnionPayload();
70147017 const operand = try self.resolveInst(ty_op.operand);
70157018 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -7069,7 +7072,7 @@ pub const FuncGen = struct {
70697072 const extra = self.air.extraData(Air.Bin, data.payload).data;
70707073
70717074 const vector_ptr = try self.resolveInst(data.vector_ptr);
7072 const vector_ptr_ty = self.air.typeOf(data.vector_ptr);
7075 const vector_ptr_ty = self.typeOf(data.vector_ptr);
70737076 const index = try self.resolveInst(extra.lhs);
70747077 const operand = try self.resolveInst(extra.rhs);
70757078
......@@ -7090,7 +7093,7 @@ pub const FuncGen = struct {
70907093 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
70917094 const lhs = try self.resolveInst(bin_op.lhs);
70927095 const rhs = try self.resolveInst(bin_op.rhs);
7093 const scalar_ty = self.air.typeOfIndex(inst).scalarType(mod);
7096 const scalar_ty = self.typeOfIndex(inst).scalarType(mod);
70947097
70957098 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmin, scalar_ty, 2, .{ lhs, rhs });
70967099 if (scalar_ty.isSignedInt(mod)) return self.builder.buildSMin(lhs, rhs, "");
......@@ -7102,7 +7105,7 @@ pub const FuncGen = struct {
71027105 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
71037106 const lhs = try self.resolveInst(bin_op.lhs);
71047107 const rhs = try self.resolveInst(bin_op.rhs);
7105 const scalar_ty = self.air.typeOfIndex(inst).scalarType(mod);
7108 const scalar_ty = self.typeOfIndex(inst).scalarType(mod);
71067109
71077110 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmax, scalar_ty, 2, .{ lhs, rhs });
71087111 if (scalar_ty.isSignedInt(mod)) return self.builder.buildSMax(lhs, rhs, "");
......@@ -7114,7 +7117,7 @@ pub const FuncGen = struct {
71147117 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
71157118 const ptr = try self.resolveInst(bin_op.lhs);
71167119 const len = try self.resolveInst(bin_op.rhs);
7117 const inst_ty = self.air.typeOfIndex(inst);
7120 const inst_ty = self.typeOfIndex(inst);
71187121 const llvm_slice_ty = try self.dg.lowerType(inst_ty);
71197122
71207123 // In case of slicing a global, the result type looks something like `{ i8*, i64 }`
......@@ -7130,7 +7133,7 @@ pub const FuncGen = struct {
71307133 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
71317134 const lhs = try self.resolveInst(bin_op.lhs);
71327135 const rhs = try self.resolveInst(bin_op.rhs);
7133 const inst_ty = self.air.typeOfIndex(inst);
7136 const inst_ty = self.typeOfIndex(inst);
71347137 const scalar_ty = inst_ty.scalarType(mod);
71357138
71367139 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.add, inst_ty, 2, .{ lhs, rhs });
......@@ -7153,7 +7156,7 @@ pub const FuncGen = struct {
71537156 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
71547157 const lhs = try self.resolveInst(bin_op.lhs);
71557158 const rhs = try self.resolveInst(bin_op.rhs);
7156 const inst_ty = self.air.typeOfIndex(inst);
7159 const inst_ty = self.typeOfIndex(inst);
71577160 const scalar_ty = inst_ty.scalarType(mod);
71587161
71597162 if (scalar_ty.isAnyFloat()) return self.todo("saturating float add", .{});
......@@ -7169,7 +7172,7 @@ pub const FuncGen = struct {
71697172 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
71707173 const lhs = try self.resolveInst(bin_op.lhs);
71717174 const rhs = try self.resolveInst(bin_op.rhs);
7172 const inst_ty = self.air.typeOfIndex(inst);
7175 const inst_ty = self.typeOfIndex(inst);
71737176 const scalar_ty = inst_ty.scalarType(mod);
71747177
71757178 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.sub, inst_ty, 2, .{ lhs, rhs });
......@@ -7192,7 +7195,7 @@ pub const FuncGen = struct {
71927195 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
71937196 const lhs = try self.resolveInst(bin_op.lhs);
71947197 const rhs = try self.resolveInst(bin_op.rhs);
7195 const inst_ty = self.air.typeOfIndex(inst);
7198 const inst_ty = self.typeOfIndex(inst);
71967199 const scalar_ty = inst_ty.scalarType(mod);
71977200
71987201 if (scalar_ty.isAnyFloat()) return self.todo("saturating float sub", .{});
......@@ -7207,7 +7210,7 @@ pub const FuncGen = struct {
72077210 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
72087211 const lhs = try self.resolveInst(bin_op.lhs);
72097212 const rhs = try self.resolveInst(bin_op.rhs);
7210 const inst_ty = self.air.typeOfIndex(inst);
7213 const inst_ty = self.typeOfIndex(inst);
72117214 const scalar_ty = inst_ty.scalarType(mod);
72127215
72137216 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.mul, inst_ty, 2, .{ lhs, rhs });
......@@ -7230,7 +7233,7 @@ pub const FuncGen = struct {
72307233 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
72317234 const lhs = try self.resolveInst(bin_op.lhs);
72327235 const rhs = try self.resolveInst(bin_op.rhs);
7233 const inst_ty = self.air.typeOfIndex(inst);
7236 const inst_ty = self.typeOfIndex(inst);
72347237 const scalar_ty = inst_ty.scalarType(mod);
72357238
72367239 if (scalar_ty.isAnyFloat()) return self.todo("saturating float mul", .{});
......@@ -7244,7 +7247,7 @@ pub const FuncGen = struct {
72447247 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
72457248 const lhs = try self.resolveInst(bin_op.lhs);
72467249 const rhs = try self.resolveInst(bin_op.rhs);
7247 const inst_ty = self.air.typeOfIndex(inst);
7250 const inst_ty = self.typeOfIndex(inst);
72487251
72497252 return self.buildFloatOp(.div, inst_ty, 2, .{ lhs, rhs });
72507253 }
......@@ -7256,7 +7259,7 @@ pub const FuncGen = struct {
72567259 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
72577260 const lhs = try self.resolveInst(bin_op.lhs);
72587261 const rhs = try self.resolveInst(bin_op.rhs);
7259 const inst_ty = self.air.typeOfIndex(inst);
7262 const inst_ty = self.typeOfIndex(inst);
72607263 const scalar_ty = inst_ty.scalarType(mod);
72617264
72627265 if (scalar_ty.isRuntimeFloat()) {
......@@ -7274,7 +7277,7 @@ pub const FuncGen = struct {
72747277 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
72757278 const lhs = try self.resolveInst(bin_op.lhs);
72767279 const rhs = try self.resolveInst(bin_op.rhs);
7277 const inst_ty = self.air.typeOfIndex(inst);
7280 const inst_ty = self.typeOfIndex(inst);
72787281 const scalar_ty = inst_ty.scalarType(mod);
72797282
72807283 if (scalar_ty.isRuntimeFloat()) {
......@@ -7314,7 +7317,7 @@ pub const FuncGen = struct {
73147317 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
73157318 const lhs = try self.resolveInst(bin_op.lhs);
73167319 const rhs = try self.resolveInst(bin_op.rhs);
7317 const inst_ty = self.air.typeOfIndex(inst);
7320 const inst_ty = self.typeOfIndex(inst);
73187321 const scalar_ty = inst_ty.scalarType(mod);
73197322
73207323 if (scalar_ty.isRuntimeFloat()) return self.buildFloatOp(.div, inst_ty, 2, .{ lhs, rhs });
......@@ -7329,7 +7332,7 @@ pub const FuncGen = struct {
73297332 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
73307333 const lhs = try self.resolveInst(bin_op.lhs);
73317334 const rhs = try self.resolveInst(bin_op.rhs);
7332 const inst_ty = self.air.typeOfIndex(inst);
7335 const inst_ty = self.typeOfIndex(inst);
73337336 const scalar_ty = inst_ty.scalarType(mod);
73347337
73357338 if (scalar_ty.isRuntimeFloat()) return self.buildFloatOp(.fmod, inst_ty, 2, .{ lhs, rhs });
......@@ -7344,7 +7347,7 @@ pub const FuncGen = struct {
73447347 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
73457348 const lhs = try self.resolveInst(bin_op.lhs);
73467349 const rhs = try self.resolveInst(bin_op.rhs);
7347 const inst_ty = self.air.typeOfIndex(inst);
7350 const inst_ty = self.typeOfIndex(inst);
73487351 const inst_llvm_ty = try self.dg.lowerType(inst_ty);
73497352 const scalar_ty = inst_ty.scalarType(mod);
73507353
......@@ -7386,7 +7389,7 @@ pub const FuncGen = struct {
73867389 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
73877390 const ptr = try self.resolveInst(bin_op.lhs);
73887391 const offset = try self.resolveInst(bin_op.rhs);
7389 const ptr_ty = self.air.typeOf(bin_op.lhs);
7392 const ptr_ty = self.typeOf(bin_op.lhs);
73907393 const llvm_elem_ty = try self.dg.lowerPtrElemTy(ptr_ty.childType());
73917394 switch (ptr_ty.ptrSize()) {
73927395 .One => {
......@@ -7412,7 +7415,7 @@ pub const FuncGen = struct {
74127415 const ptr = try self.resolveInst(bin_op.lhs);
74137416 const offset = try self.resolveInst(bin_op.rhs);
74147417 const negative_offset = self.builder.buildNeg(offset, "");
7415 const ptr_ty = self.air.typeOf(bin_op.lhs);
7418 const ptr_ty = self.typeOf(bin_op.lhs);
74167419 const llvm_elem_ty = try self.dg.lowerPtrElemTy(ptr_ty.childType());
74177420 switch (ptr_ty.ptrSize()) {
74187421 .One => {
......@@ -7447,9 +7450,9 @@ pub const FuncGen = struct {
74477450 const lhs = try self.resolveInst(extra.lhs);
74487451 const rhs = try self.resolveInst(extra.rhs);
74497452
7450 const lhs_ty = self.air.typeOf(extra.lhs);
7453 const lhs_ty = self.typeOf(extra.lhs);
74517454 const scalar_ty = lhs_ty.scalarType(mod);
7452 const dest_ty = self.air.typeOfIndex(inst);
7455 const dest_ty = self.typeOfIndex(inst);
74537456
74547457 const intrinsic_name = if (scalar_ty.isSignedInt(mod)) signed_intrinsic else unsigned_intrinsic;
74557458
......@@ -7735,7 +7738,7 @@ pub const FuncGen = struct {
77357738 const mulend2 = try self.resolveInst(extra.rhs);
77367739 const addend = try self.resolveInst(pl_op.operand);
77377740
7738 const ty = self.air.typeOfIndex(inst);
7741 const ty = self.typeOfIndex(inst);
77397742 return self.buildFloatOp(.fma, ty, 3, .{ mulend1, mulend2, addend });
77407743 }
77417744
......@@ -7747,12 +7750,12 @@ pub const FuncGen = struct {
77477750 const lhs = try self.resolveInst(extra.lhs);
77487751 const rhs = try self.resolveInst(extra.rhs);
77497752
7750 const lhs_ty = self.air.typeOf(extra.lhs);
7751 const rhs_ty = self.air.typeOf(extra.rhs);
7753 const lhs_ty = self.typeOf(extra.lhs);
7754 const rhs_ty = self.typeOf(extra.rhs);
77527755 const lhs_scalar_ty = lhs_ty.scalarType(mod);
77537756 const rhs_scalar_ty = rhs_ty.scalarType(mod);
77547757
7755 const dest_ty = self.air.typeOfIndex(inst);
7758 const dest_ty = self.typeOfIndex(inst);
77567759 const llvm_dest_ty = try self.dg.lowerType(dest_ty);
77577760
77587761 const casted_rhs = if (rhs_scalar_ty.bitSize(mod) < lhs_scalar_ty.bitSize(mod))
......@@ -7821,8 +7824,8 @@ pub const FuncGen = struct {
78217824 const lhs = try self.resolveInst(bin_op.lhs);
78227825 const rhs = try self.resolveInst(bin_op.rhs);
78237826
7824 const lhs_ty = self.air.typeOf(bin_op.lhs);
7825 const rhs_ty = self.air.typeOf(bin_op.rhs);
7827 const lhs_ty = self.typeOf(bin_op.lhs);
7828 const rhs_ty = self.typeOf(bin_op.rhs);
78267829 const lhs_scalar_ty = lhs_ty.scalarType(mod);
78277830 const rhs_scalar_ty = rhs_ty.scalarType(mod);
78287831
......@@ -7841,8 +7844,8 @@ pub const FuncGen = struct {
78417844 const lhs = try self.resolveInst(bin_op.lhs);
78427845 const rhs = try self.resolveInst(bin_op.rhs);
78437846
7844 const lhs_type = self.air.typeOf(bin_op.lhs);
7845 const rhs_type = self.air.typeOf(bin_op.rhs);
7847 const lhs_type = self.typeOf(bin_op.lhs);
7848 const rhs_type = self.typeOf(bin_op.rhs);
78467849 const lhs_scalar_ty = lhs_type.scalarType(mod);
78477850 const rhs_scalar_ty = rhs_type.scalarType(mod);
78487851
......@@ -7860,8 +7863,8 @@ pub const FuncGen = struct {
78607863 const lhs = try self.resolveInst(bin_op.lhs);
78617864 const rhs = try self.resolveInst(bin_op.rhs);
78627865
7863 const lhs_ty = self.air.typeOf(bin_op.lhs);
7864 const rhs_ty = self.air.typeOf(bin_op.rhs);
7866 const lhs_ty = self.typeOf(bin_op.lhs);
7867 const rhs_ty = self.typeOf(bin_op.rhs);
78657868 const lhs_scalar_ty = lhs_ty.scalarType(mod);
78667869 const rhs_scalar_ty = rhs_ty.scalarType(mod);
78677870 const lhs_bits = lhs_scalar_ty.bitSize(mod);
......@@ -7903,8 +7906,8 @@ pub const FuncGen = struct {
79037906 const lhs = try self.resolveInst(bin_op.lhs);
79047907 const rhs = try self.resolveInst(bin_op.rhs);
79057908
7906 const lhs_ty = self.air.typeOf(bin_op.lhs);
7907 const rhs_ty = self.air.typeOf(bin_op.rhs);
7909 const lhs_ty = self.typeOf(bin_op.lhs);
7910 const rhs_ty = self.typeOf(bin_op.rhs);
79087911 const lhs_scalar_ty = lhs_ty.scalarType(mod);
79097912 const rhs_scalar_ty = rhs_ty.scalarType(mod);
79107913
......@@ -7932,11 +7935,11 @@ pub const FuncGen = struct {
79327935 fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
79337936 const mod = self.dg.module;
79347937 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
7935 const dest_ty = self.air.typeOfIndex(inst);
7938 const dest_ty = self.typeOfIndex(inst);
79367939 const dest_info = dest_ty.intInfo(mod);
79377940 const dest_llvm_ty = try self.dg.lowerType(dest_ty);
79387941 const operand = try self.resolveInst(ty_op.operand);
7939 const operand_ty = self.air.typeOf(ty_op.operand);
7942 const operand_ty = self.typeOf(ty_op.operand);
79407943 const operand_info = operand_ty.intInfo(mod);
79417944
79427945 if (operand_info.bits < dest_info.bits) {
......@@ -7954,7 +7957,7 @@ pub const FuncGen = struct {
79547957 fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
79557958 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
79567959 const operand = try self.resolveInst(ty_op.operand);
7957 const dest_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst));
7960 const dest_llvm_ty = try self.dg.lowerType(self.typeOfIndex(inst));
79587961 return self.builder.buildTrunc(operand, dest_llvm_ty, "");
79597962 }
79607963
......@@ -7962,8 +7965,8 @@ pub const FuncGen = struct {
79627965 const mod = self.dg.module;
79637966 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
79647967 const operand = try self.resolveInst(ty_op.operand);
7965 const operand_ty = self.air.typeOf(ty_op.operand);
7966 const dest_ty = self.air.typeOfIndex(inst);
7968 const operand_ty = self.typeOf(ty_op.operand);
7969 const dest_ty = self.typeOfIndex(inst);
79677970 const target = mod.getTarget();
79687971 const dest_bits = dest_ty.floatBits(target);
79697972 const src_bits = operand_ty.floatBits(target);
......@@ -7992,8 +7995,8 @@ pub const FuncGen = struct {
79927995 const mod = self.dg.module;
79937996 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
79947997 const operand = try self.resolveInst(ty_op.operand);
7995 const operand_ty = self.air.typeOf(ty_op.operand);
7996 const dest_ty = self.air.typeOfIndex(inst);
7998 const operand_ty = self.typeOf(ty_op.operand);
7999 const dest_ty = self.typeOfIndex(inst);
79978000 const target = mod.getTarget();
79988001 const dest_bits = dest_ty.floatBits(target);
79998002 const src_bits = operand_ty.floatBits(target);
......@@ -8021,16 +8024,16 @@ pub const FuncGen = struct {
80218024 fn airPtrToInt(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
80228025 const un_op = self.air.instructions.items(.data)[inst].un_op;
80238026 const operand = try self.resolveInst(un_op);
8024 const ptr_ty = self.air.typeOf(un_op);
8027 const ptr_ty = self.typeOf(un_op);
80258028 const operand_ptr = self.sliceOrArrayPtr(operand, ptr_ty);
8026 const dest_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst));
8029 const dest_llvm_ty = try self.dg.lowerType(self.typeOfIndex(inst));
80278030 return self.builder.buildPtrToInt(operand_ptr, dest_llvm_ty, "");
80288031 }
80298032
80308033 fn airBitCast(self: *FuncGen, inst: Air.Inst.Index) !*llvm.Value {
80318034 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
8032 const operand_ty = self.air.typeOf(ty_op.operand);
8033 const inst_ty = self.air.typeOfIndex(inst);
8035 const operand_ty = self.typeOf(ty_op.operand);
8036 const inst_ty = self.typeOfIndex(inst);
80348037 const operand = try self.resolveInst(ty_op.operand);
80358038 return self.bitCast(operand, operand_ty, inst_ty);
80368039 }
......@@ -8159,17 +8162,17 @@ pub const FuncGen = struct {
81598162 }
81608163
81618164 fn airArg(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
8165 const mod = self.dg.module;
81628166 const arg_val = self.args[self.arg_index];
81638167 self.arg_index += 1;
81648168
8165 const inst_ty = self.air.typeOfIndex(inst);
8169 const inst_ty = self.typeOfIndex(inst);
81668170 if (self.dg.object.di_builder) |dib| {
81678171 if (needDbgVarWorkaround(self.dg)) {
81688172 return arg_val;
81698173 }
81708174
81718175 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;
8172 const mod = self.dg.module;
81738176 const func = self.dg.decl.getFunction().?;
81748177 const lbrace_line = mod.declPtr(func.owner_decl).src_line + func.lbrace_line + 1;
81758178 const lbrace_col = func.lbrace_column + 1;
......@@ -8203,9 +8206,9 @@ pub const FuncGen = struct {
82038206 }
82048207
82058208 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
8206 const ptr_ty = self.air.typeOfIndex(inst);
8207 const pointee_type = ptr_ty.childType();
82088209 const mod = self.dg.module;
8210 const ptr_ty = self.typeOfIndex(inst);
8211 const pointee_type = ptr_ty.childType();
82098212 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return self.dg.lowerPtrToVoid(ptr_ty);
82108213
82118214 const pointee_llvm_ty = try self.dg.lowerType(pointee_type);
......@@ -8214,9 +8217,9 @@ pub const FuncGen = struct {
82148217 }
82158218
82168219 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
8217 const ptr_ty = self.air.typeOfIndex(inst);
8218 const ret_ty = ptr_ty.childType();
82198220 const mod = self.dg.module;
8221 const ptr_ty = self.typeOfIndex(inst);
8222 const ret_ty = ptr_ty.childType();
82208223 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return self.dg.lowerPtrToVoid(ptr_ty);
82218224 if (self.ret_ptr) |ret_ptr| return ret_ptr;
82228225 const ret_llvm_ty = try self.dg.lowerType(ret_ty);
......@@ -8232,7 +8235,7 @@ pub const FuncGen = struct {
82328235 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !?*llvm.Value {
82338236 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
82348237 const dest_ptr = try self.resolveInst(bin_op.lhs);
8235 const ptr_ty = self.air.typeOf(bin_op.lhs);
8238 const ptr_ty = self.typeOf(bin_op.lhs);
82368239 const operand_ty = ptr_ty.childType();
82378240 const mod = self.dg.module;
82388241
......@@ -8285,7 +8288,7 @@ pub const FuncGen = struct {
82858288 const mod = fg.dg.module;
82868289 const inst = body_tail[0];
82878290 const ty_op = fg.air.instructions.items(.data)[inst].ty_op;
8288 const ptr_ty = fg.air.typeOf(ty_op.operand);
8291 const ptr_ty = fg.typeOf(ty_op.operand);
82898292 const ptr_info = ptr_ty.ptrInfo().data;
82908293 const ptr = try fg.resolveInst(ty_op.operand);
82918294
......@@ -8361,7 +8364,7 @@ pub const FuncGen = struct {
83618364 const ptr = try self.resolveInst(extra.ptr);
83628365 var expected_value = try self.resolveInst(extra.expected_value);
83638366 var new_value = try self.resolveInst(extra.new_value);
8364 const operand_ty = self.air.typeOf(extra.ptr).elemType();
8367 const operand_ty = self.typeOf(extra.ptr).elemType();
83658368 const opt_abi_ty = self.dg.getAtomicAbiType(operand_ty, false);
83668369 if (opt_abi_ty) |abi_ty| {
83678370 // operand needs widening and truncating
......@@ -8383,7 +8386,7 @@ pub const FuncGen = struct {
83838386 );
83848387 result.setWeak(llvm.Bool.fromBool(is_weak));
83858388
8386 const optional_ty = self.air.typeOfIndex(inst);
8389 const optional_ty = self.typeOfIndex(inst);
83878390
83888391 var payload = self.builder.buildExtractValue(result, 0, "");
83898392 if (opt_abi_ty != null) {
......@@ -8406,7 +8409,7 @@ pub const FuncGen = struct {
84068409 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
84078410 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
84088411 const ptr = try self.resolveInst(pl_op.operand);
8409 const ptr_ty = self.air.typeOf(pl_op.operand);
8412 const ptr_ty = self.typeOf(pl_op.operand);
84108413 const operand_ty = ptr_ty.elemType();
84118414 const operand = try self.resolveInst(extra.operand);
84128415 const is_signed_int = operand_ty.isSignedInt(mod);
......@@ -8461,7 +8464,7 @@ pub const FuncGen = struct {
84618464 const mod = self.dg.module;
84628465 const atomic_load = self.air.instructions.items(.data)[inst].atomic_load;
84638466 const ptr = try self.resolveInst(atomic_load.ptr);
8464 const ptr_ty = self.air.typeOf(atomic_load.ptr);
8467 const ptr_ty = self.typeOf(atomic_load.ptr);
84658468 const ptr_info = ptr_ty.ptrInfo().data;
84668469 const elem_ty = ptr_info.pointee_type;
84678470 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod))
......@@ -8494,7 +8497,7 @@ pub const FuncGen = struct {
84948497 ) !?*llvm.Value {
84958498 const mod = self.dg.module;
84968499 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
8497 const ptr_ty = self.air.typeOf(bin_op.lhs);
8500 const ptr_ty = self.typeOf(bin_op.lhs);
84988501 const operand_ty = ptr_ty.childType();
84998502 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return null;
85008503 const ptr = try self.resolveInst(bin_op.lhs);
......@@ -8517,8 +8520,8 @@ pub const FuncGen = struct {
85178520 const mod = self.dg.module;
85188521 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
85198522 const dest_slice = try self.resolveInst(bin_op.lhs);
8520 const ptr_ty = self.air.typeOf(bin_op.lhs);
8521 const elem_ty = self.air.typeOf(bin_op.rhs);
8523 const ptr_ty = self.typeOf(bin_op.lhs);
8524 const elem_ty = self.typeOf(bin_op.rhs);
85228525 const module = self.dg.module;
85238526 const target = module.getTarget();
85248527 const dest_ptr_align = ptr_ty.ptrAlignment(mod);
......@@ -8641,9 +8644,9 @@ pub const FuncGen = struct {
86418644 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
86428645 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
86438646 const dest_slice = try self.resolveInst(bin_op.lhs);
8644 const dest_ptr_ty = self.air.typeOf(bin_op.lhs);
8647 const dest_ptr_ty = self.typeOf(bin_op.lhs);
86458648 const src_slice = try self.resolveInst(bin_op.rhs);
8646 const src_ptr_ty = self.air.typeOf(bin_op.rhs);
8649 const src_ptr_ty = self.typeOf(bin_op.rhs);
86478650 const src_ptr = self.sliceOrArrayPtr(src_slice, src_ptr_ty);
86488651 const len = self.sliceOrArrayLenInBytes(dest_slice, dest_ptr_ty);
86498652 const dest_ptr = self.sliceOrArrayPtr(dest_slice, dest_ptr_ty);
......@@ -8663,7 +8666,7 @@ pub const FuncGen = struct {
86638666 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
86648667 const mod = self.dg.module;
86658668 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
8666 const un_ty = self.air.typeOf(bin_op.lhs).childType();
8669 const un_ty = self.typeOf(bin_op.lhs).childType();
86678670 const layout = un_ty.unionGetLayout(mod);
86688671 if (layout.tag_size == 0) return null;
86698672 const union_ptr = try self.resolveInst(bin_op.lhs);
......@@ -8684,7 +8687,7 @@ pub const FuncGen = struct {
86848687 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
86858688 const mod = self.dg.module;
86868689 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
8687 const un_ty = self.air.typeOf(ty_op.operand);
8690 const un_ty = self.typeOf(ty_op.operand);
86888691 const layout = un_ty.unionGetLayout(mod);
86898692 if (layout.tag_size == 0) return null;
86908693 const union_handle = try self.resolveInst(ty_op.operand);
......@@ -8708,7 +8711,7 @@ pub const FuncGen = struct {
87088711 fn airUnaryOp(self: *FuncGen, inst: Air.Inst.Index, comptime op: FloatOp) !?*llvm.Value {
87098712 const un_op = self.air.instructions.items(.data)[inst].un_op;
87108713 const operand = try self.resolveInst(un_op);
8711 const operand_ty = self.air.typeOf(un_op);
8714 const operand_ty = self.typeOf(un_op);
87128715
87138716 return self.buildFloatOp(op, operand_ty, 1, .{operand});
87148717 }
......@@ -8718,7 +8721,7 @@ pub const FuncGen = struct {
87188721
87198722 const un_op = self.air.instructions.items(.data)[inst].un_op;
87208723 const operand = try self.resolveInst(un_op);
8721 const operand_ty = self.air.typeOf(un_op);
8724 const operand_ty = self.typeOf(un_op);
87228725
87238726 return self.buildFloatOp(.neg, operand_ty, 1, .{operand});
87248727 }
......@@ -8726,7 +8729,7 @@ pub const FuncGen = struct {
87268729 fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, llvm_fn_name: []const u8) !?*llvm.Value {
87278730 const mod = self.dg.module;
87288731 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
8729 const operand_ty = self.air.typeOf(ty_op.operand);
8732 const operand_ty = self.typeOf(ty_op.operand);
87308733 const operand = try self.resolveInst(ty_op.operand);
87318734
87328735 const llvm_i1 = self.context.intType(1);
......@@ -8735,7 +8738,7 @@ pub const FuncGen = struct {
87358738
87368739 const params = [_]*llvm.Value{ operand, llvm_i1.constNull() };
87378740 const wrong_size_result = self.builder.buildCall(fn_val.globalGetValueType(), fn_val, &params, params.len, .C, .Auto, "");
8738 const result_ty = self.air.typeOfIndex(inst);
8741 const result_ty = self.typeOfIndex(inst);
87398742 const result_llvm_ty = try self.dg.lowerType(result_ty);
87408743
87418744 const bits = operand_ty.intInfo(mod).bits;
......@@ -8752,7 +8755,7 @@ pub const FuncGen = struct {
87528755 fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, llvm_fn_name: []const u8) !?*llvm.Value {
87538756 const mod = self.dg.module;
87548757 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
8755 const operand_ty = self.air.typeOf(ty_op.operand);
8758 const operand_ty = self.typeOf(ty_op.operand);
87568759 const operand = try self.resolveInst(ty_op.operand);
87578760
87588761 const params = [_]*llvm.Value{operand};
......@@ -8760,7 +8763,7 @@ pub const FuncGen = struct {
87608763 const fn_val = self.getIntrinsic(llvm_fn_name, &.{operand_llvm_ty});
87618764
87628765 const wrong_size_result = self.builder.buildCall(fn_val.globalGetValueType(), fn_val, &params, params.len, .C, .Auto, "");
8763 const result_ty = self.air.typeOfIndex(inst);
8766 const result_ty = self.typeOfIndex(inst);
87648767 const result_llvm_ty = try self.dg.lowerType(result_ty);
87658768
87668769 const bits = operand_ty.intInfo(mod).bits;
......@@ -8777,7 +8780,7 @@ pub const FuncGen = struct {
87778780 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index, llvm_fn_name: []const u8) !?*llvm.Value {
87788781 const mod = self.dg.module;
87798782 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
8780 const operand_ty = self.air.typeOf(ty_op.operand);
8783 const operand_ty = self.typeOf(ty_op.operand);
87818784 var bits = operand_ty.intInfo(mod).bits;
87828785 assert(bits % 8 == 0);
87838786
......@@ -8815,7 +8818,7 @@ pub const FuncGen = struct {
88158818
88168819 const wrong_size_result = self.builder.buildCall(fn_val.globalGetValueType(), fn_val, &params, params.len, .C, .Auto, "");
88178820
8818 const result_ty = self.air.typeOfIndex(inst);
8821 const result_ty = self.typeOfIndex(inst);
88198822 const result_llvm_ty = try self.dg.lowerType(result_ty);
88208823 const result_bits = result_ty.intInfo(mod).bits;
88218824 if (bits > result_bits) {
......@@ -8876,7 +8879,7 @@ pub const FuncGen = struct {
88768879 fn airIsNamedEnumValue(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
88778880 const un_op = self.air.instructions.items(.data)[inst].un_op;
88788881 const operand = try self.resolveInst(un_op);
8879 const enum_ty = self.air.typeOf(un_op);
8882 const enum_ty = self.typeOf(un_op);
88808883
88818884 const llvm_fn = try self.getIsNamedEnumValueFunction(enum_ty);
88828885 const params = [_]*llvm.Value{operand};
......@@ -8954,7 +8957,7 @@ pub const FuncGen = struct {
89548957 fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
89558958 const un_op = self.air.instructions.items(.data)[inst].un_op;
89568959 const operand = try self.resolveInst(un_op);
8957 const enum_ty = self.air.typeOf(un_op);
8960 const enum_ty = self.typeOf(un_op);
89588961
89598962 const llvm_fn = try self.getEnumTagNameFunction(enum_ty);
89608963 const params = [_]*llvm.Value{operand};
......@@ -9083,7 +9086,7 @@ pub const FuncGen = struct {
90839086 fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
90849087 const un_op = self.air.instructions.items(.data)[inst].un_op;
90859088 const operand = try self.resolveInst(un_op);
9086 const slice_ty = self.air.typeOfIndex(inst);
9089 const slice_ty = self.typeOfIndex(inst);
90879090 const slice_llvm_ty = try self.dg.lowerType(slice_ty);
90889091
90899092 const error_name_table_ptr = try self.getErrorNameTable();
......@@ -9097,7 +9100,7 @@ pub const FuncGen = struct {
90979100 fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
90989101 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
90999102 const scalar = try self.resolveInst(ty_op.operand);
9100 const vector_ty = self.air.typeOfIndex(inst);
9103 const vector_ty = self.typeOfIndex(inst);
91019104 const len = vector_ty.vectorLen();
91029105 return self.builder.buildVectorSplat(len, scalar, "");
91039106 }
......@@ -9120,7 +9123,7 @@ pub const FuncGen = struct {
91209123 const b = try self.resolveInst(extra.b);
91219124 const mask = self.air.values[extra.mask];
91229125 const mask_len = extra.mask_len;
9123 const a_len = self.air.typeOf(extra.a).vectorLen();
9126 const a_len = self.typeOf(extra.a).vectorLen();
91249127
91259128 // LLVM uses integers larger than the length of the first array to
91269129 // index into the second array. This was deemed unnecessarily fragile
......@@ -9219,8 +9222,8 @@ pub const FuncGen = struct {
92199222
92209223 const reduce = self.air.instructions.items(.data)[inst].reduce;
92219224 const operand = try self.resolveInst(reduce.operand);
9222 const operand_ty = self.air.typeOf(reduce.operand);
9223 const scalar_ty = self.air.typeOfIndex(inst);
9225 const operand_ty = self.typeOf(reduce.operand);
9226 const scalar_ty = self.typeOfIndex(inst);
92249227
92259228 switch (reduce.operation) {
92269229 .And => return self.builder.buildAndReduce(operand),
......@@ -9300,12 +9303,12 @@ pub const FuncGen = struct {
93009303 }
93019304
93029305 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
9306 const mod = self.dg.module;
93039307 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
9304 const result_ty = self.air.typeOfIndex(inst);
9308 const result_ty = self.typeOfIndex(inst);
93059309 const len = @intCast(usize, result_ty.arrayLen());
93069310 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
93079311 const llvm_result_ty = try self.dg.lowerType(result_ty);
9308 const mod = self.dg.module;
93099312
93109313 switch (result_ty.zigTypeTag(mod)) {
93119314 .Vector => {
......@@ -9370,7 +9373,7 @@ pub const FuncGen = struct {
93709373 const field_ptr = self.builder.buildInBoundsGEP(llvm_result_ty, alloca_inst, &indices, indices.len, "");
93719374 var field_ptr_payload: Type.Payload.Pointer = .{
93729375 .data = .{
9373 .pointee_type = self.air.typeOf(elem),
9376 .pointee_type = self.typeOf(elem),
93749377 .@"align" = result_ty.structFieldAlign(i, mod),
93759378 .@"addrspace" = .generic,
93769379 },
......@@ -9440,7 +9443,7 @@ pub const FuncGen = struct {
94409443 const mod = self.dg.module;
94419444 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
94429445 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
9443 const union_ty = self.air.typeOfIndex(inst);
9446 const union_ty = self.typeOfIndex(inst);
94449447 const union_llvm_ty = try self.dg.lowerType(union_ty);
94459448 const layout = union_ty.unionGetLayout(mod);
94469449 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
......@@ -9643,7 +9646,7 @@ pub const FuncGen = struct {
96439646
96449647 fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
96459648 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
9646 const inst_ty = self.air.typeOfIndex(inst);
9649 const inst_ty = self.typeOfIndex(inst);
96479650 const operand = try self.resolveInst(ty_op.operand);
96489651
96499652 const llvm_dest_ty = try self.dg.lowerType(inst_ty);
......@@ -9830,7 +9833,7 @@ pub const FuncGen = struct {
98309833 switch (struct_ty.zigTypeTag(mod)) {
98319834 .Struct => switch (struct_ty.containerLayout()) {
98329835 .Packed => {
9833 const result_ty = self.air.typeOfIndex(inst);
9836 const result_ty = self.typeOfIndex(inst);
98349837 const result_ty_info = result_ty.ptrInfo().data;
98359838
98369839 if (result_ty_info.host_size != 0) {
......@@ -10172,6 +10175,16 @@ pub const FuncGen = struct {
1017210175 );
1017310176 return call;
1017410177 }
10178
10179 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {
10180 const mod = fg.dg.module;
10181 return fg.air.typeOf(inst, mod.intern_pool);
10182 }
10183
10184 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {
10185 const mod = fg.dg.module;
10186 return fg.air.typeOfIndex(inst, mod.intern_pool);
10187 }
1017510188};
1017610189
1017710190fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
......@@ -10833,7 +10846,7 @@ const ParamTypeIterator = struct {
1083310846 if (it.zig_index >= args.len) {
1083410847 return null;
1083510848 } else {
10836 return nextInner(it, fg.air.typeOf(args[it.zig_index]));
10849 return nextInner(it, fg.typeOf(args[it.zig_index]));
1083710850 }
1083810851 } else {
1083910852 return nextInner(it, it.fn_info.param_types[it.zig_index]);
src/codegen/spirv.zig+65-54
......@@ -233,7 +233,7 @@ pub const DeclGen = struct {
233233 fn resolve(self: *DeclGen, inst: Air.Inst.Ref) !IdRef {
234234 const mod = self.module;
235235 if (self.air.value(inst, mod)) |val| {
236 const ty = self.air.typeOf(inst);
236 const ty = self.typeOf(inst);
237237 if (ty.zigTypeTag(mod) == .Fn) {
238238 const fn_decl_index = switch (val.tag()) {
239239 .extern_fn => val.castTag(.extern_fn).?.data.owner_decl,
......@@ -1720,10 +1720,11 @@ pub const DeclGen = struct {
17201720 }
17211721
17221722 fn genInst(self: *DeclGen, inst: Air.Inst.Index) !void {
1723 const mod = self.module;
1724 const ip = &mod.intern_pool;
17231725 // TODO: remove now-redundant isUnused calls from AIR handler functions
1724 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst)) {
1726 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
17251727 return;
1726 }
17271728
17281729 const air_tags = self.air.instructions.items(.tag);
17291730 const maybe_result_id: ?IdRef = switch (air_tags[inst]) {
......@@ -1847,7 +1848,7 @@ pub const DeclGen = struct {
18471848 const lhs_id = try self.resolve(bin_op.lhs);
18481849 const rhs_id = try self.resolve(bin_op.rhs);
18491850 const result_id = self.spv.allocId();
1850 const result_type_id = try self.resolveTypeId(self.air.typeOfIndex(inst));
1851 const result_type_id = try self.resolveTypeId(self.typeOfIndex(inst));
18511852 try self.func.body.emit(self.spv.gpa, opcode, .{
18521853 .id_result_type = result_type_id,
18531854 .id_result = result_id,
......@@ -1862,7 +1863,7 @@ pub const DeclGen = struct {
18621863 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
18631864 const lhs_id = try self.resolve(bin_op.lhs);
18641865 const rhs_id = try self.resolve(bin_op.rhs);
1865 const result_type_id = try self.resolveTypeId(self.air.typeOfIndex(inst));
1866 const result_type_id = try self.resolveTypeId(self.typeOfIndex(inst));
18661867
18671868 // the shift and the base must be the same type in SPIR-V, but in Zig the shift is a smaller int.
18681869 const shift_id = self.spv.allocId();
......@@ -1907,15 +1908,15 @@ pub const DeclGen = struct {
19071908 if (self.liveness.isUnused(inst)) return null;
19081909 // LHS and RHS are guaranteed to have the same type, and AIR guarantees
19091910 // the result to be the same as the LHS and RHS, which matches SPIR-V.
1910 const ty = self.air.typeOfIndex(inst);
1911 const ty = self.typeOfIndex(inst);
19111912 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
19121913 var lhs_id = try self.resolve(bin_op.lhs);
19131914 var rhs_id = try self.resolve(bin_op.rhs);
19141915
19151916 const result_ty_ref = try self.resolveType(ty, .direct);
19161917
1917 assert(self.air.typeOf(bin_op.lhs).eql(ty, self.module));
1918 assert(self.air.typeOf(bin_op.rhs).eql(ty, self.module));
1918 assert(self.typeOf(bin_op.lhs).eql(ty, self.module));
1919 assert(self.typeOf(bin_op.rhs).eql(ty, self.module));
19191920
19201921 // Binary operations are generally applicable to both scalar and vector operations
19211922 // in SPIR-V, but int and float versions of operations require different opcodes.
......@@ -1971,8 +1972,8 @@ pub const DeclGen = struct {
19711972 const lhs = try self.resolve(extra.lhs);
19721973 const rhs = try self.resolve(extra.rhs);
19731974
1974 const operand_ty = self.air.typeOf(extra.lhs);
1975 const result_ty = self.air.typeOfIndex(inst);
1975 const operand_ty = self.typeOf(extra.lhs);
1976 const result_ty = self.typeOfIndex(inst);
19761977
19771978 const info = try self.arithmeticTypeInfo(operand_ty);
19781979 switch (info.class) {
......@@ -2064,14 +2065,14 @@ pub const DeclGen = struct {
20642065 fn airShuffle(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
20652066 const mod = self.module;
20662067 if (self.liveness.isUnused(inst)) return null;
2067 const ty = self.air.typeOfIndex(inst);
2068 const ty = self.typeOfIndex(inst);
20682069 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
20692070 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
20702071 const a = try self.resolve(extra.a);
20712072 const b = try self.resolve(extra.b);
20722073 const mask = self.air.values[extra.mask];
20732074 const mask_len = extra.mask_len;
2074 const a_len = self.air.typeOf(extra.a).vectorLen();
2075 const a_len = self.typeOf(extra.a).vectorLen();
20752076
20762077 const result_id = self.spv.allocId();
20772078 const result_type_id = try self.resolveTypeId(ty);
......@@ -2162,8 +2163,8 @@ pub const DeclGen = struct {
21622163 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
21632164 const ptr_id = try self.resolve(bin_op.lhs);
21642165 const offset_id = try self.resolve(bin_op.rhs);
2165 const ptr_ty = self.air.typeOf(bin_op.lhs);
2166 const result_ty = self.air.typeOfIndex(inst);
2166 const ptr_ty = self.typeOf(bin_op.lhs);
2167 const result_ty = self.typeOfIndex(inst);
21672168
21682169 return try self.ptrAdd(result_ty, ptr_ty, ptr_id, offset_id);
21692170 }
......@@ -2173,11 +2174,11 @@ pub const DeclGen = struct {
21732174 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
21742175 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
21752176 const ptr_id = try self.resolve(bin_op.lhs);
2176 const ptr_ty = self.air.typeOf(bin_op.lhs);
2177 const ptr_ty = self.typeOf(bin_op.lhs);
21772178 const offset_id = try self.resolve(bin_op.rhs);
2178 const offset_ty = self.air.typeOf(bin_op.rhs);
2179 const offset_ty = self.typeOf(bin_op.rhs);
21792180 const offset_ty_ref = try self.resolveType(offset_ty, .direct);
2180 const result_ty = self.air.typeOfIndex(inst);
2181 const result_ty = self.typeOfIndex(inst);
21812182
21822183 const negative_offset_id = self.spv.allocId();
21832184 try self.func.body.emit(self.spv.gpa, .OpSNegate, .{
......@@ -2298,8 +2299,8 @@ pub const DeclGen = struct {
22982299 const lhs_id = try self.resolve(bin_op.lhs);
22992300 const rhs_id = try self.resolve(bin_op.rhs);
23002301 const bool_ty_id = try self.resolveTypeId(Type.bool);
2301 const ty = self.air.typeOf(bin_op.lhs);
2302 assert(ty.eql(self.air.typeOf(bin_op.rhs), self.module));
2302 const ty = self.typeOf(bin_op.lhs);
2303 assert(ty.eql(self.typeOf(bin_op.rhs), self.module));
23032304
23042305 return try self.cmp(op, bool_ty_id, ty, lhs_id, rhs_id);
23052306 }
......@@ -2337,8 +2338,8 @@ pub const DeclGen = struct {
23372338 if (self.liveness.isUnused(inst)) return null;
23382339 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
23392340 const operand_id = try self.resolve(ty_op.operand);
2340 const operand_ty = self.air.typeOf(ty_op.operand);
2341 const result_ty = self.air.typeOfIndex(inst);
2341 const operand_ty = self.typeOf(ty_op.operand);
2342 const result_ty = self.typeOfIndex(inst);
23422343 return try self.bitCast(result_ty, operand_ty, operand_id);
23432344 }
23442345
......@@ -2347,7 +2348,7 @@ pub const DeclGen = struct {
23472348
23482349 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
23492350 const operand_id = try self.resolve(ty_op.operand);
2350 const dest_ty = self.air.typeOfIndex(inst);
2351 const dest_ty = self.typeOfIndex(inst);
23512352 const dest_ty_id = try self.resolveTypeId(dest_ty);
23522353
23532354 const mod = self.module;
......@@ -2391,10 +2392,10 @@ pub const DeclGen = struct {
23912392 if (self.liveness.isUnused(inst)) return null;
23922393
23932394 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2394 const operand_ty = self.air.typeOf(ty_op.operand);
2395 const operand_ty = self.typeOf(ty_op.operand);
23952396 const operand_id = try self.resolve(ty_op.operand);
23962397 const operand_info = try self.arithmeticTypeInfo(operand_ty);
2397 const dest_ty = self.air.typeOfIndex(inst);
2398 const dest_ty = self.typeOfIndex(inst);
23982399 const dest_ty_id = try self.resolveTypeId(dest_ty);
23992400
24002401 const result_id = self.spv.allocId();
......@@ -2418,7 +2419,7 @@ pub const DeclGen = struct {
24182419
24192420 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
24202421 const operand_id = try self.resolve(ty_op.operand);
2421 const dest_ty = self.air.typeOfIndex(inst);
2422 const dest_ty = self.typeOfIndex(inst);
24222423 const dest_info = try self.arithmeticTypeInfo(dest_ty);
24232424 const dest_ty_id = try self.resolveTypeId(dest_ty);
24242425
......@@ -2455,20 +2456,20 @@ pub const DeclGen = struct {
24552456 fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef {
24562457 if (self.liveness.isUnused(inst)) return null;
24572458 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2458 const field_ty = self.air.typeOfIndex(inst);
2459 const field_ty = self.typeOfIndex(inst);
24592460 const operand_id = try self.resolve(ty_op.operand);
24602461 return try self.extractField(field_ty, operand_id, field);
24612462 }
24622463
24632464 fn airSliceElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
24642465 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2465 const slice_ty = self.air.typeOf(bin_op.lhs);
2466 const slice_ty = self.typeOf(bin_op.lhs);
24662467 if (!slice_ty.isVolatilePtr() and self.liveness.isUnused(inst)) return null;
24672468
24682469 const slice_id = try self.resolve(bin_op.lhs);
24692470 const index_id = try self.resolve(bin_op.rhs);
24702471
2471 const ptr_ty = self.air.typeOfIndex(inst);
2472 const ptr_ty = self.typeOfIndex(inst);
24722473 const ptr_ty_ref = try self.resolveType(ptr_ty, .direct);
24732474
24742475 const slice_ptr = try self.extractField(ptr_ty, slice_id, 0);
......@@ -2477,7 +2478,7 @@ pub const DeclGen = struct {
24772478
24782479 fn airSliceElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
24792480 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2480 const slice_ty = self.air.typeOf(bin_op.lhs);
2481 const slice_ty = self.typeOf(bin_op.lhs);
24812482 if (!slice_ty.isVolatilePtr() and self.liveness.isUnused(inst)) return null;
24822483
24832484 const slice_id = try self.resolve(bin_op.lhs);
......@@ -2514,7 +2515,7 @@ pub const DeclGen = struct {
25142515 const mod = self.module;
25152516 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
25162517 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
2517 const ptr_ty = self.air.typeOf(bin_op.lhs);
2518 const ptr_ty = self.typeOf(bin_op.lhs);
25182519 const elem_ty = ptr_ty.childType();
25192520 // TODO: Make this return a null ptr or something
25202521 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return null;
......@@ -2526,7 +2527,7 @@ pub const DeclGen = struct {
25262527
25272528 fn airPtrElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
25282529 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2529 const ptr_ty = self.air.typeOf(bin_op.lhs);
2530 const ptr_ty = self.typeOf(bin_op.lhs);
25302531 const ptr_id = try self.resolve(bin_op.lhs);
25312532 const index_id = try self.resolve(bin_op.rhs);
25322533
......@@ -2544,7 +2545,7 @@ pub const DeclGen = struct {
25442545
25452546 fn airGetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
25462547 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2547 const un_ty = self.air.typeOf(ty_op.operand);
2548 const un_ty = self.typeOf(ty_op.operand);
25482549
25492550 const mod = self.module;
25502551 const layout = un_ty.unionGetLayout(mod);
......@@ -2565,7 +2566,7 @@ pub const DeclGen = struct {
25652566 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
25662567 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
25672568
2568 const struct_ty = self.air.typeOf(struct_field.struct_operand);
2569 const struct_ty = self.typeOf(struct_field.struct_operand);
25692570 const object_id = try self.resolve(struct_field.struct_operand);
25702571 const field_index = struct_field.field_index;
25712572 const field_ty = struct_ty.structFieldType(field_index);
......@@ -2604,8 +2605,8 @@ pub const DeclGen = struct {
26042605 if (self.liveness.isUnused(inst)) return null;
26052606 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
26062607 const struct_ptr = try self.resolve(ty_op.operand);
2607 const struct_ptr_ty = self.air.typeOf(ty_op.operand);
2608 const result_ptr_ty = self.air.typeOfIndex(inst);
2608 const struct_ptr_ty = self.typeOf(ty_op.operand);
2609 const result_ptr_ty = self.typeOfIndex(inst);
26092610 return try self.structFieldPtr(result_ptr_ty, struct_ptr_ty, struct_ptr, field_index);
26102611 }
26112612
......@@ -2661,7 +2662,7 @@ pub const DeclGen = struct {
26612662
26622663 fn airAlloc(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
26632664 if (self.liveness.isUnused(inst)) return null;
2664 const ptr_ty = self.air.typeOfIndex(inst);
2665 const ptr_ty = self.typeOfIndex(inst);
26652666 assert(ptr_ty.ptrAddressSpace() == .generic);
26662667 const child_ty = ptr_ty.childType();
26672668 const child_ty_ref = try self.resolveType(child_ty, .indirect);
......@@ -2694,7 +2695,7 @@ pub const DeclGen = struct {
26942695 incoming_blocks.deinit(self.gpa);
26952696 }
26962697
2697 const ty = self.air.typeOfIndex(inst);
2698 const ty = self.typeOfIndex(inst);
26982699 const inst_datas = self.air.instructions.items(.data);
26992700 const extra = self.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);
27002701 const body = self.air.extra[extra.end..][0..extra.data.body_len];
......@@ -2727,7 +2728,7 @@ pub const DeclGen = struct {
27272728 fn airBr(self: *DeclGen, inst: Air.Inst.Index) !void {
27282729 const br = self.air.instructions.items(.data)[inst].br;
27292730 const block = self.blocks.get(br.block_inst).?;
2730 const operand_ty = self.air.typeOf(br.operand);
2731 const operand_ty = self.typeOf(br.operand);
27312732
27322733 const mod = self.module;
27332734 if (operand_ty.hasRuntimeBits(mod)) {
......@@ -2777,7 +2778,7 @@ pub const DeclGen = struct {
27772778
27782779 fn airLoad(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
27792780 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2780 const ptr_ty = self.air.typeOf(ty_op.operand);
2781 const ptr_ty = self.typeOf(ty_op.operand);
27812782 const operand = try self.resolve(ty_op.operand);
27822783 if (!ptr_ty.isVolatilePtr() and self.liveness.isUnused(inst)) return null;
27832784
......@@ -2787,7 +2788,7 @@ pub const DeclGen = struct {
27872788 fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {
27882789 const mod = self.module;
27892790 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2790 const ptr_ty = self.air.typeOf(bin_op.lhs);
2791 const ptr_ty = self.typeOf(bin_op.lhs);
27912792 const ptr = try self.resolve(bin_op.lhs);
27922793 const value = try self.resolve(bin_op.rhs);
27932794 const ptr_ty_ref = try self.resolveType(ptr_ty, .direct);
......@@ -2819,7 +2820,7 @@ pub const DeclGen = struct {
28192820
28202821 fn airRet(self: *DeclGen, inst: Air.Inst.Index) !void {
28212822 const operand = self.air.instructions.items(.data)[inst].un_op;
2822 const operand_ty = self.air.typeOf(operand);
2823 const operand_ty = self.typeOf(operand);
28232824 const mod = self.module;
28242825 if (operand_ty.hasRuntimeBits(mod)) {
28252826 const operand_id = try self.resolve(operand);
......@@ -2832,7 +2833,7 @@ pub const DeclGen = struct {
28322833 fn airRetLoad(self: *DeclGen, inst: Air.Inst.Index) !void {
28332834 const mod = self.module;
28342835 const un_op = self.air.instructions.items(.data)[inst].un_op;
2835 const ptr_ty = self.air.typeOf(un_op);
2836 const ptr_ty = self.typeOf(un_op);
28362837 const ret_ty = ptr_ty.childType();
28372838
28382839 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -2853,8 +2854,8 @@ pub const DeclGen = struct {
28532854 const extra = self.air.extraData(Air.Try, pl_op.payload);
28542855 const body = self.air.extra[extra.end..][0..extra.data.body_len];
28552856
2856 const err_union_ty = self.air.typeOf(pl_op.operand);
2857 const payload_ty = self.air.typeOfIndex(inst);
2857 const err_union_ty = self.typeOf(pl_op.operand);
2858 const payload_ty = self.typeOfIndex(inst);
28582859
28592860 const err_ty_ref = try self.resolveType(Type.anyerror, .direct);
28602861 const bool_ty_ref = try self.resolveType(Type.bool, .direct);
......@@ -2911,7 +2912,7 @@ pub const DeclGen = struct {
29112912
29122913 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
29132914 const operand_id = try self.resolve(ty_op.operand);
2914 const err_union_ty = self.air.typeOf(ty_op.operand);
2915 const err_union_ty = self.typeOf(ty_op.operand);
29152916 const err_ty_ref = try self.resolveType(Type.anyerror, .direct);
29162917
29172918 if (err_union_ty.errorUnionSet().errorSetIsEmpty()) {
......@@ -2934,7 +2935,7 @@ pub const DeclGen = struct {
29342935 if (self.liveness.isUnused(inst)) return null;
29352936
29362937 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2937 const err_union_ty = self.air.typeOfIndex(inst);
2938 const err_union_ty = self.typeOfIndex(inst);
29382939 const payload_ty = err_union_ty.errorUnionPayload();
29392940 const operand_id = try self.resolve(ty_op.operand);
29402941 const eu_layout = self.errorUnionLayout(payload_ty);
......@@ -2966,7 +2967,7 @@ pub const DeclGen = struct {
29662967 const mod = self.module;
29672968 const un_op = self.air.instructions.items(.data)[inst].un_op;
29682969 const operand_id = try self.resolve(un_op);
2969 const optional_ty = self.air.typeOf(un_op);
2970 const optional_ty = self.typeOf(un_op);
29702971
29712972 var buf: Type.Payload.ElemType = undefined;
29722973 const payload_ty = optional_ty.optionalChild(&buf);
......@@ -3030,8 +3031,8 @@ pub const DeclGen = struct {
30303031 const mod = self.module;
30313032 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
30323033 const operand_id = try self.resolve(ty_op.operand);
3033 const optional_ty = self.air.typeOf(ty_op.operand);
3034 const payload_ty = self.air.typeOfIndex(inst);
3034 const optional_ty = self.typeOf(ty_op.operand);
3035 const payload_ty = self.typeOfIndex(inst);
30353036
30363037 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) return null;
30373038
......@@ -3047,14 +3048,14 @@ pub const DeclGen = struct {
30473048
30483049 const mod = self.module;
30493050 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
3050 const payload_ty = self.air.typeOf(ty_op.operand);
3051 const payload_ty = self.typeOf(ty_op.operand);
30513052
30523053 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
30533054 return try self.constBool(true, .direct);
30543055 }
30553056
30563057 const operand_id = try self.resolve(ty_op.operand);
3057 const optional_ty = self.air.typeOfIndex(inst);
3058 const optional_ty = self.typeOfIndex(inst);
30583059 if (optional_ty.optionalReprIsPayload(mod)) {
30593060 return operand_id;
30603061 }
......@@ -3068,7 +3069,7 @@ pub const DeclGen = struct {
30683069 const mod = self.module;
30693070 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
30703071 const cond = try self.resolve(pl_op.operand);
3071 const cond_ty = self.air.typeOf(pl_op.operand);
3072 const cond_ty = self.typeOf(pl_op.operand);
30723073 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
30733074
30743075 const cond_words: u32 = switch (cond_ty.zigTypeTag(mod)) {
......@@ -3317,7 +3318,7 @@ pub const DeclGen = struct {
33173318 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
33183319 const extra = self.air.extraData(Air.Call, pl_op.payload);
33193320 const args = @ptrCast([]const Air.Inst.Ref, self.air.extra[extra.end..][0..extra.data.args_len]);
3320 const callee_ty = self.air.typeOf(pl_op.operand);
3321 const callee_ty = self.typeOf(pl_op.operand);
33213322 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {
33223323 .Fn => callee_ty,
33233324 .Pointer => return self.fail("cannot call function pointers", .{}),
......@@ -3339,7 +3340,7 @@ pub const DeclGen = struct {
33393340 // before starting to emit OpFunctionCall instructions. Hence the
33403341 // temporary params buffer.
33413342 const arg_id = try self.resolve(arg);
3342 const arg_ty = self.air.typeOf(arg);
3343 const arg_ty = self.typeOf(arg);
33433344 if (!arg_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
33443345
33453346 params[n_params] = arg_id;
......@@ -3363,4 +3364,14 @@ pub const DeclGen = struct {
33633364
33643365 return result_id;
33653366 }
3367
3368 fn typeOf(self: *DeclGen, inst: Air.Inst.Ref) Type {
3369 const mod = self.module;
3370 return self.air.typeOf(inst, mod.intern_pool);
3371 }
3372
3373 fn typeOfIndex(self: *DeclGen, inst: Air.Inst.Index) Type {
3374 const mod = self.module;
3375 return self.air.typeOfIndex(inst, mod.intern_pool);
3376 }
33663377};
src/print_air.zig+16-2
......@@ -306,6 +306,7 @@ const Writer = struct {
306306 .struct_field_ptr => try w.writeStructField(s, inst),
307307 .struct_field_val => try w.writeStructField(s, inst),
308308 .constant => try w.writeConstant(s, inst),
309 .interned => try w.writeInterned(s, inst),
309310 .assembly => try w.writeAssembly(s, inst),
310311 .dbg_stmt => try w.writeDbgStmt(s, inst),
311312
......@@ -515,7 +516,7 @@ const Writer = struct {
515516 const pl_op = w.air.instructions.items(.data)[inst].pl_op;
516517 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
517518
518 const elem_ty = w.air.typeOfIndex(inst).childType();
519 const elem_ty = w.typeOfIndex(inst).childType();
519520 try w.writeType(s, elem_ty);
520521 try s.writeAll(", ");
521522 try w.writeOperand(s, inst, 0, pl_op.operand);
......@@ -614,6 +615,14 @@ const Writer = struct {
614615 try s.print(", {}", .{val.fmtValue(ty, w.module)});
615616 }
616617
618 fn writeInterned(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
619 const mod = w.module;
620 const ip_index = w.air.instructions.items(.data)[inst].interned;
621 const ty = ip_index.toType();
622 try w.writeType(s, ty);
623 try s.print(", {}", .{ip_index.toValue().fmtValue(ty, mod)});
624 }
625
617626 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
618627 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
619628 const extra = w.air.extraData(Air.Asm, ty_pl.payload);
......@@ -622,7 +631,7 @@ const Writer = struct {
622631 var extra_i: usize = extra.end;
623632 var op_index: usize = 0;
624633
625 const ret_ty = w.air.typeOfIndex(inst);
634 const ret_ty = w.typeOfIndex(inst);
626635 try w.writeType(s, ret_ty);
627636
628637 if (is_volatile) {
......@@ -985,4 +994,9 @@ const Writer = struct {
985994 try s.print("%{d}", .{inst});
986995 if (dies) try s.writeByte('!');
987996 }
997
998 fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type {
999 const mod = w.module;
1000 return w.air.typeOfIndex(inst, mod.intern_pool);
1001 }
9881002};
src/type.zig+27-13
......@@ -2827,21 +2827,35 @@ pub const Type = struct {
28272827 };
28282828 }
28292829
2830 /// TODO add enums with no fields here
28312830 pub fn isNoReturn(ty: Type) bool {
2832 switch (ty.tag()) {
2833 .noreturn => return true,
2834 .error_set => {
2835 const err_set_obj = ty.castTag(.error_set).?.data;
2836 const names = err_set_obj.names.keys();
2837 return names.len == 0;
2838 },
2839 .error_set_merged => {
2840 const name_map = ty.castTag(.error_set_merged).?.data;
2841 const names = name_map.keys();
2842 return names.len == 0;
2843 },
2831 switch (@enumToInt(ty.ip_index)) {
2832 @enumToInt(InternPool.Index.first_type)...@enumToInt(InternPool.Index.noreturn_type) - 1 => return false,
2833
2834 @enumToInt(InternPool.Index.noreturn_type) => return true,
2835
2836 @enumToInt(InternPool.Index.noreturn_type) + 1...@enumToInt(InternPool.Index.last_type) => return false,
2837
2838 @enumToInt(InternPool.Index.first_value)...@enumToInt(InternPool.Index.last_value) => unreachable,
2839 @enumToInt(InternPool.Index.generic_poison) => unreachable,
2840
2841 // TODO add empty error sets here
2842 // TODO add enums with no fields here
28442843 else => return false,
2844
2845 @enumToInt(InternPool.Index.none) => switch (ty.tag()) {
2846 .noreturn => return true,
2847 .error_set => {
2848 const err_set_obj = ty.castTag(.error_set).?.data;
2849 const names = err_set_obj.names.keys();
2850 return names.len == 0;
2851 },
2852 .error_set_merged => {
2853 const name_map = ty.castTag(.error_set_merged).?.data;
2854 const names = name_map.keys();
2855 return names.len == 0;
2856 },
2857 else => return false,
2858 },
28452859 }
28462860 }
28472861