authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-12-02 21:08:00-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-03 02:05:06-08:00
logdaf91ed8d1149d10f0e4a597efc9f17c4a49b0ca
tree947f39a04ad2aed68faa4d5929c923e026c7138c
parentbf5ab54510fd8fbd300ddc22f9af4767477be0e5

Air: use typesafe `Air.Inst.Index`

I need some indices for a thing...

15 files changed, 1669 insertions(+), 1642 deletions(-)

src/Air.zig+70-62
...@@ -875,7 +875,19 @@ pub const Inst = struct {...@@ -875,7 +875,19 @@ pub const Inst = struct {
875 };875 };
876876
877 /// The position of an AIR instruction within the `Air` instructions array.877 /// The position of an AIR instruction within the `Air` instructions array.
878 pub const Index = u32;878 pub const Index = enum(u32) {
879 _,
880
881 pub fn toRef(i: Index) Inst.Ref {
882 assert(@intFromEnum(i) >> 31 == 0);
883 return @enumFromInt((1 << 31) | @intFromEnum(i));
884 }
885
886 pub fn toTargetIndex(i: Index) u31 {
887 assert(@intFromEnum(i) >> 31 == 1);
888 return @truncate(@intFromEnum(i));
889 }
890 };
879891
880 /// Either a reference to a value stored in the InternPool, or a reference to an AIR instruction.892 /// Either a reference to a value stored in the InternPool, or a reference to an AIR instruction.
881 /// The most-significant bit of the value is a tag bit. This bit is 1 if the value represents an893 /// The most-significant bit of the value is a tag bit. This bit is 1 if the value represents an
...@@ -976,6 +988,41 @@ pub const Inst = struct {...@@ -976,6 +988,41 @@ pub const Inst = struct {
976 /// value and may instead be used as a sentinel to indicate null.988 /// value and may instead be used as a sentinel to indicate null.
977 none = @intFromEnum(InternPool.Index.none),989 none = @intFromEnum(InternPool.Index.none),
978 _,990 _,
991
992 pub fn toInterned(ref: Ref) ?InternPool.Index {
993 assert(ref != .none);
994 return ref.toInternedAllowNone();
995 }
996
997 pub fn toInternedAllowNone(ref: Ref) ?InternPool.Index {
998 return switch (ref) {
999 .var_args_param_type => .var_args_param_type,
1000 .none => .none,
1001 else => if (@intFromEnum(ref) >> 31 == 0)
1002 @enumFromInt(@as(u31, @truncate(@intFromEnum(ref))))
1003 else
1004 null,
1005 };
1006 }
1007
1008 pub fn toIndex(ref: Ref) ?Index {
1009 assert(ref != .none);
1010 return ref.toIndexAllowNone();
1011 }
1012
1013 pub fn toIndexAllowNone(ref: Ref) ?Index {
1014 return switch (ref) {
1015 .var_args_param_type, .none => null,
1016 else => if (@intFromEnum(ref) >> 31 != 0)
1017 @enumFromInt(@as(u31, @truncate(@intFromEnum(ref))))
1018 else
1019 null,
1020 };
1021 }
1022
1023 pub fn toType(ref: Ref) Type {
1024 return Type.fromInterned(ref.toInterned().?);
1025 }
979 };1026 };
9801027
981 /// All instructions have an 8-byte payload, which is contained within1028 /// All instructions have an 8-byte payload, which is contained within
...@@ -1216,20 +1263,20 @@ pub const UnionInit = struct {...@@ -1216,20 +1263,20 @@ pub const UnionInit = struct {
1216pub fn getMainBody(air: Air) []const Air.Inst.Index {1263pub fn getMainBody(air: Air) []const Air.Inst.Index {
1217 const body_index = air.extra[@intFromEnum(ExtraIndex.main_block)];1264 const body_index = air.extra[@intFromEnum(ExtraIndex.main_block)];
1218 const extra = air.extraData(Block, body_index);1265 const extra = air.extraData(Block, body_index);
1219 return air.extra[extra.end..][0..extra.data.body_len];1266 return @ptrCast(air.extra[extra.end..][0..extra.data.body_len]);
1220}1267}
12211268
1222pub fn typeOf(air: *const Air, inst: Air.Inst.Ref, ip: *const InternPool) Type {1269pub fn typeOf(air: *const Air, inst: Air.Inst.Ref, ip: *const InternPool) Type {
1223 if (refToInterned(inst)) |ip_index| {1270 if (inst.toInterned()) |ip_index| {
1224 return Type.fromInterned(ip.typeOf(ip_index));1271 return Type.fromInterned(ip.typeOf(ip_index));
1225 } else {1272 } else {
1226 return air.typeOfIndex(refToIndex(inst).?, ip);1273 return air.typeOfIndex(inst.toIndex().?, ip);
1227 }1274 }
1228}1275}
12291276
1230pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) Type {1277pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
1231 const datas = air.instructions.items(.data);1278 const datas = air.instructions.items(.data);
1232 switch (air.instructions.items(.tag)[inst]) {1279 switch (air.instructions.items(.tag)[@intFromEnum(inst)]) {
1233 .add,1280 .add,
1234 .add_safe,1281 .add_safe,
1235 .add_wrap,1282 .add_wrap,
...@@ -1269,7 +1316,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1269,7 +1316,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1269 .div_exact_optimized,1316 .div_exact_optimized,
1270 .rem_optimized,1317 .rem_optimized,
1271 .mod_optimized,1318 .mod_optimized,
1272 => return air.typeOf(datas[inst].bin_op.lhs, ip),1319 => return air.typeOf(datas[@intFromEnum(inst)].bin_op.lhs, ip),
12731320
1274 .sqrt,1321 .sqrt,
1275 .sin,1322 .sin,
...@@ -1286,7 +1333,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1286,7 +1333,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1286 .trunc_float,1333 .trunc_float,
1287 .neg,1334 .neg,
1288 .neg_optimized,1335 .neg_optimized,
1289 => return air.typeOf(datas[inst].un_op, ip),1336 => return air.typeOf(datas[@intFromEnum(inst)].un_op, ip),
12901337
1291 .cmp_lt,1338 .cmp_lt,
1292 .cmp_lte,1339 .cmp_lte,
...@@ -1317,9 +1364,9 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1317,9 +1364,9 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1317 .ret_ptr,1364 .ret_ptr,
1318 .err_return_trace,1365 .err_return_trace,
1319 .c_va_start,1366 .c_va_start,
1320 => return datas[inst].ty,1367 => return datas[@intFromEnum(inst)].ty,
13211368
1322 .arg => return air.getRefType(datas[inst].arg.ty),1369 .arg => return datas[@intFromEnum(inst)].arg.ty.toType(),
13231370
1324 .assembly,1371 .assembly,
1325 .block,1372 .block,
...@@ -1343,7 +1390,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1343,7 +1390,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1343 .ptr_add,1390 .ptr_add,
1344 .ptr_sub,1391 .ptr_sub,
1345 .try_ptr,1392 .try_ptr,
1346 => return air.getRefType(datas[inst].ty_pl.ty),1393 => return datas[@intFromEnum(inst)].ty_pl.ty.toType(),
13471394
1348 .not,1395 .not,
1349 .bitcast,1396 .bitcast,
...@@ -1385,7 +1432,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1385,7 +1432,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1385 .c_va_arg,1432 .c_va_arg,
1386 .c_va_copy,1433 .c_va_copy,
1387 .abs,1434 .abs,
1388 => return air.getRefType(datas[inst].ty_op.ty),1435 => return datas[@intFromEnum(inst)].ty_op.ty.toType(),
13891436
1390 .loop,1437 .loop,
1391 .br,1438 .br,
...@@ -1437,36 +1484,36 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1437,36 +1484,36 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1437 .tag_name, .error_name => return Type.slice_const_u8_sentinel_0,1484 .tag_name, .error_name => return Type.slice_const_u8_sentinel_0,
14381485
1439 .call, .call_always_tail, .call_never_tail, .call_never_inline => {1486 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
1440 const callee_ty = air.typeOf(datas[inst].pl_op.operand, ip);1487 const callee_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip);
1441 return Type.fromInterned(ip.funcTypeReturnType(callee_ty.toIntern()));1488 return Type.fromInterned(ip.funcTypeReturnType(callee_ty.toIntern()));
1442 },1489 },
14431490
1444 .slice_elem_val, .ptr_elem_val, .array_elem_val => {1491 .slice_elem_val, .ptr_elem_val, .array_elem_val => {
1445 const ptr_ty = air.typeOf(datas[inst].bin_op.lhs, ip);1492 const ptr_ty = air.typeOf(datas[@intFromEnum(inst)].bin_op.lhs, ip);
1446 return ptr_ty.childTypeIp(ip);1493 return ptr_ty.childTypeIp(ip);
1447 },1494 },
1448 .atomic_load => {1495 .atomic_load => {
1449 const ptr_ty = air.typeOf(datas[inst].atomic_load.ptr, ip);1496 const ptr_ty = air.typeOf(datas[@intFromEnum(inst)].atomic_load.ptr, ip);
1450 return ptr_ty.childTypeIp(ip);1497 return ptr_ty.childTypeIp(ip);
1451 },1498 },
1452 .atomic_rmw => {1499 .atomic_rmw => {
1453 const ptr_ty = air.typeOf(datas[inst].pl_op.operand, ip);1500 const ptr_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip);
1454 return ptr_ty.childTypeIp(ip);1501 return ptr_ty.childTypeIp(ip);
1455 },1502 },
14561503
1457 .reduce, .reduce_optimized => {1504 .reduce, .reduce_optimized => {
1458 const operand_ty = air.typeOf(datas[inst].reduce.operand, ip);1505 const operand_ty = air.typeOf(datas[@intFromEnum(inst)].reduce.operand, ip);
1459 return Type.fromInterned(ip.indexToKey(operand_ty.ip_index).vector_type.child);1506 return Type.fromInterned(ip.indexToKey(operand_ty.ip_index).vector_type.child);
1460 },1507 },
14611508
1462 .mul_add => return air.typeOf(datas[inst].pl_op.operand, ip),1509 .mul_add => return air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip),
1463 .select => {1510 .select => {
1464 const extra = air.extraData(Air.Bin, datas[inst].pl_op.payload).data;1511 const extra = air.extraData(Air.Bin, datas[@intFromEnum(inst)].pl_op.payload).data;
1465 return air.typeOf(extra.lhs, ip);1512 return air.typeOf(extra.lhs, ip);
1466 },1513 },
14671514
1468 .@"try" => {1515 .@"try" => {
1469 const err_union_ty = air.typeOf(datas[inst].pl_op.operand, ip);1516 const err_union_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip);
1470 return Type.fromInterned(ip.indexToKey(err_union_ty.ip_index).error_union_type.payload_type);1517 return Type.fromInterned(ip.indexToKey(err_union_ty.ip_index).error_union_type.payload_type);
1471 },1518 },
14721519
...@@ -1480,11 +1527,6 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1480,11 +1527,6 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1480 }1527 }
1481}1528}
14821529
1483pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {
1484 _ = air; // TODO: remove this parameter
1485 return Type.fromInterned(refToInterned(ref).?);
1486}
1487
1488/// Returns the requested data, as well as the new index which is at the start of the1530/// Returns the requested data, as well as the new index which is at the start of the
1489/// trailers for the object.1531/// trailers for the object.
1490pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end: usize } {1532pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end: usize } {
...@@ -1513,21 +1555,6 @@ pub fn deinit(air: *Air, gpa: std.mem.Allocator) void {...@@ -1513,21 +1555,6 @@ pub fn deinit(air: *Air, gpa: std.mem.Allocator) void {
1513 air.* = undefined;1555 air.* = undefined;
1514}1556}
15151557
1516pub fn refToInternedAllowNone(ref: Inst.Ref) ?InternPool.Index {
1517 return switch (ref) {
1518 .var_args_param_type => .var_args_param_type,
1519 .none => .none,
1520 else => if (@intFromEnum(ref) >> 31 == 0) {
1521 return @as(InternPool.Index, @enumFromInt(@intFromEnum(ref)));
1522 } else null,
1523 };
1524}
1525
1526pub fn refToInterned(ref: Inst.Ref) ?InternPool.Index {
1527 assert(ref != .none);
1528 return refToInternedAllowNone(ref);
1529}
1530
1531pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {1558pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {
1532 return switch (ip_index) {1559 return switch (ip_index) {
1533 .var_args_param_type => .var_args_param_type,1560 .var_args_param_type => .var_args_param_type,
...@@ -1539,31 +1566,12 @@ pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {...@@ -1539,31 +1566,12 @@ pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {
1539 };1566 };
1540}1567}
15411568
1542pub fn refToIndexAllowNone(ref: Inst.Ref) ?Inst.Index {
1543 return switch (ref) {
1544 .var_args_param_type, .none => null,
1545 else => if (@intFromEnum(ref) >> 31 != 0) {
1546 return @as(u31, @truncate(@intFromEnum(ref)));
1547 } else null,
1548 };
1549}
1550
1551pub fn refToIndex(ref: Inst.Ref) ?Inst.Index {
1552 assert(ref != .none);
1553 return refToIndexAllowNone(ref);
1554}
1555
1556pub fn indexToRef(inst: Inst.Index) Inst.Ref {
1557 assert(inst >> 31 == 0);
1558 return @enumFromInt((1 << 31) | inst);
1559}
1560
1561/// Returns `null` if runtime-known.1569/// Returns `null` if runtime-known.
1562pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {1570pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {
1563 if (refToInterned(inst)) |ip_index| {1571 if (inst.toInterned()) |ip_index| {
1564 return Value.fromInterned(ip_index);1572 return Value.fromInterned(ip_index);
1565 }1573 }
1566 const index = refToIndex(inst).?;1574 const index = inst.toIndex().?;
1567 return air.typeOfIndex(index, &mod.intern_pool).onePossibleValue(mod);1575 return air.typeOfIndex(index, &mod.intern_pool).onePossibleValue(mod);
1568}1576}
15691577
...@@ -1581,8 +1589,8 @@ pub fn nullTerminatedString(air: Air, index: usize) [:0]const u8 {...@@ -1581,8 +1589,8 @@ pub fn nullTerminatedString(air: Air, index: usize) [:0]const u8 {
1581/// lowered, and Liveness determines its result is unused, backends should1589/// lowered, and Liveness determines its result is unused, backends should
1582/// avoid lowering it.1590/// avoid lowering it.
1583pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {1591pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
1584 const data = air.instructions.items(.data)[inst];1592 const data = air.instructions.items(.data)[@intFromEnum(inst)];
1585 return switch (air.instructions.items(.tag)[inst]) {1593 return switch (air.instructions.items(.tag)[@intFromEnum(inst)]) {
1586 .arg,1594 .arg,
1587 .block,1595 .block,
1588 .loop,1596 .loop,
src/Liveness.zig+117-117
...@@ -177,31 +177,31 @@ pub fn analyze(gpa: Allocator, air: Air, intern_pool: *const InternPool) Allocat...@@ -177,31 +177,31 @@ pub fn analyze(gpa: Allocator, air: Air, intern_pool: *const InternPool) Allocat
177}177}
178178
179pub fn getTombBits(l: Liveness, inst: Air.Inst.Index) Bpi {179pub fn getTombBits(l: Liveness, inst: Air.Inst.Index) Bpi {
180 const usize_index = (inst * bpi) / @bitSizeOf(usize);180 const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize);
181 return @as(Bpi, @truncate(l.tomb_bits[usize_index] >>181 return @as(Bpi, @truncate(l.tomb_bits[usize_index] >>
182 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi))));182 @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi))));
183}183}
184184
185pub fn isUnused(l: Liveness, inst: Air.Inst.Index) bool {185pub fn isUnused(l: Liveness, inst: Air.Inst.Index) bool {
186 const usize_index = (inst * bpi) / @bitSizeOf(usize);186 const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize);
187 const mask = @as(usize, 1) <<187 const mask = @as(usize, 1) <<
188 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi + (bpi - 1)));188 @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi + (bpi - 1)));
189 return (l.tomb_bits[usize_index] & mask) != 0;189 return (l.tomb_bits[usize_index] & mask) != 0;
190}190}
191191
192pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool {192pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool {
193 assert(operand < bpi - 1);193 assert(operand < bpi - 1);
194 const usize_index = (inst * bpi) / @bitSizeOf(usize);194 const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize);
195 const mask = @as(usize, 1) <<195 const mask = @as(usize, 1) <<
196 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi + operand));196 @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi + operand));
197 return (l.tomb_bits[usize_index] & mask) != 0;197 return (l.tomb_bits[usize_index] & mask) != 0;
198}198}
199199
200pub fn clearOperandDeath(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) void {200pub fn clearOperandDeath(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) void {
201 assert(operand < bpi - 1);201 assert(operand < bpi - 1);
202 const usize_index = (inst * bpi) / @bitSizeOf(usize);202 const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize);
203 const mask = @as(usize, 1) <<203 const mask = @as(usize, 1) <<
204 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi + operand));204 @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi + operand));
205 l.tomb_bits[usize_index] &= ~mask;205 l.tomb_bits[usize_index] &= ~mask;
206}206}
207207
...@@ -229,8 +229,8 @@ pub fn categorizeOperand(...@@ -229,8 +229,8 @@ pub fn categorizeOperand(
229) OperandCategory {229) OperandCategory {
230 const air_tags = air.instructions.items(.tag);230 const air_tags = air.instructions.items(.tag);
231 const air_datas = air.instructions.items(.data);231 const air_datas = air.instructions.items(.data);
232 const operand_ref = Air.indexToRef(operand);232 const operand_ref = operand.toRef();
233 switch (air_tags[inst]) {233 switch (air_tags[@intFromEnum(inst)]) {
234 .add,234 .add,
235 .add_safe,235 .add_safe,
236 .add_wrap,236 .add_wrap,
...@@ -287,7 +287,7 @@ pub fn categorizeOperand(...@@ -287,7 +287,7 @@ pub fn categorizeOperand(
287 .cmp_gt_optimized,287 .cmp_gt_optimized,
288 .cmp_neq_optimized,288 .cmp_neq_optimized,
289 => {289 => {
290 const o = air_datas[inst].bin_op;290 const o = air_datas[@intFromEnum(inst)].bin_op;
291 if (o.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);291 if (o.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
292 if (o.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);292 if (o.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
293 return .none;293 return .none;
...@@ -304,14 +304,14 @@ pub fn categorizeOperand(...@@ -304,14 +304,14 @@ pub fn categorizeOperand(
304 .memset_safe,304 .memset_safe,
305 .memcpy,305 .memcpy,
306 => {306 => {
307 const o = air_datas[inst].bin_op;307 const o = air_datas[@intFromEnum(inst)].bin_op;
308 if (o.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);308 if (o.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
309 if (o.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write);309 if (o.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write);
310 return .write;310 return .write;
311 },311 },
312312
313 .vector_store_elem => {313 .vector_store_elem => {
314 const o = air_datas[inst].vector_store_elem;314 const o = air_datas[@intFromEnum(inst)].vector_store_elem;
315 const extra = air.extraData(Air.Bin, o.payload).data;315 const extra = air.extraData(Air.Bin, o.payload).data;
316 if (o.vector_ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);316 if (o.vector_ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
317 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);317 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
...@@ -386,7 +386,7 @@ pub fn categorizeOperand(...@@ -386,7 +386,7 @@ pub fn categorizeOperand(
386 .c_va_copy,386 .c_va_copy,
387 .abs,387 .abs,
388 => {388 => {
389 const o = air_datas[inst].ty_op;389 const o = air_datas[@intFromEnum(inst)].ty_op;
390 if (o.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);390 if (o.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
391 return .none;391 return .none;
392 },392 },
...@@ -394,7 +394,7 @@ pub fn categorizeOperand(...@@ -394,7 +394,7 @@ pub fn categorizeOperand(
394 .optional_payload_ptr_set,394 .optional_payload_ptr_set,
395 .errunion_payload_ptr_set,395 .errunion_payload_ptr_set,
396 => {396 => {
397 const o = air_datas[inst].ty_op;397 const o = air_datas[@intFromEnum(inst)].ty_op;
398 if (o.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);398 if (o.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
399 return .write;399 return .write;
400 },400 },
...@@ -429,7 +429,7 @@ pub fn categorizeOperand(...@@ -429,7 +429,7 @@ pub fn categorizeOperand(
429 .cmp_lt_errors_len,429 .cmp_lt_errors_len,
430 .c_va_end,430 .c_va_end,
431 => {431 => {
432 const o = air_datas[inst].un_op;432 const o = air_datas[@intFromEnum(inst)].un_op;
433 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);433 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
434 return .none;434 return .none;
435 },435 },
...@@ -437,13 +437,13 @@ pub fn categorizeOperand(...@@ -437,13 +437,13 @@ pub fn categorizeOperand(
437 .ret,437 .ret,
438 .ret_load,438 .ret_load,
439 => {439 => {
440 const o = air_datas[inst].un_op;440 const o = air_datas[@intFromEnum(inst)].un_op;
441 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .noret);441 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .noret);
442 return .noret;442 return .noret;
443 },443 },
444444
445 .set_err_return_trace => {445 .set_err_return_trace => {
446 const o = air_datas[inst].un_op;446 const o = air_datas[@intFromEnum(inst)].un_op;
447 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);447 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
448 return .write;448 return .write;
449 },449 },
...@@ -458,7 +458,7 @@ pub fn categorizeOperand(...@@ -458,7 +458,7 @@ pub fn categorizeOperand(
458 .slice_elem_ptr,458 .slice_elem_ptr,
459 .slice,459 .slice,
460 => {460 => {
461 const ty_pl = air_datas[inst].ty_pl;461 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;
462 const extra = air.extraData(Air.Bin, ty_pl.payload).data;462 const extra = air.extraData(Air.Bin, ty_pl.payload).data;
463 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);463 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
464 if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);464 if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
...@@ -468,19 +468,19 @@ pub fn categorizeOperand(...@@ -468,19 +468,19 @@ pub fn categorizeOperand(
468 .dbg_var_ptr,468 .dbg_var_ptr,
469 .dbg_var_val,469 .dbg_var_val,
470 => {470 => {
471 const o = air_datas[inst].pl_op.operand;471 const o = air_datas[@intFromEnum(inst)].pl_op.operand;
472 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);472 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
473 return .none;473 return .none;
474 },474 },
475475
476 .prefetch => {476 .prefetch => {
477 const prefetch = air_datas[inst].prefetch;477 const prefetch = air_datas[@intFromEnum(inst)].prefetch;
478 if (prefetch.ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);478 if (prefetch.ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
479 return .none;479 return .none;
480 },480 },
481481
482 .call, .call_always_tail, .call_never_tail, .call_never_inline => {482 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
483 const inst_data = air_datas[inst].pl_op;483 const inst_data = air_datas[@intFromEnum(inst)].pl_op;
484 const callee = inst_data.operand;484 const callee = inst_data.operand;
485 const extra = air.extraData(Air.Call, inst_data.payload);485 const extra = air.extraData(Air.Call, inst_data.payload);
486 const args = @as([]const Air.Inst.Ref, @ptrCast(air.extra[extra.end..][0..extra.data.args_len]));486 const args = @as([]const Air.Inst.Ref, @ptrCast(air.extra[extra.end..][0..extra.data.args_len]));
...@@ -507,7 +507,7 @@ pub fn categorizeOperand(...@@ -507,7 +507,7 @@ pub fn categorizeOperand(
507 return .write;507 return .write;
508 },508 },
509 .select => {509 .select => {
510 const pl_op = air_datas[inst].pl_op;510 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
511 const extra = air.extraData(Air.Bin, pl_op.payload).data;511 const extra = air.extraData(Air.Bin, pl_op.payload).data;
512 if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);512 if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
513 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);513 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
...@@ -515,25 +515,25 @@ pub fn categorizeOperand(...@@ -515,25 +515,25 @@ pub fn categorizeOperand(
515 return .none;515 return .none;
516 },516 },
517 .shuffle => {517 .shuffle => {
518 const extra = air.extraData(Air.Shuffle, air_datas[inst].ty_pl.payload).data;518 const extra = air.extraData(Air.Shuffle, air_datas[@intFromEnum(inst)].ty_pl.payload).data;
519 if (extra.a == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);519 if (extra.a == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
520 if (extra.b == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);520 if (extra.b == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
521 return .none;521 return .none;
522 },522 },
523 .reduce, .reduce_optimized => {523 .reduce, .reduce_optimized => {
524 const reduce = air_datas[inst].reduce;524 const reduce = air_datas[@intFromEnum(inst)].reduce;
525 if (reduce.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);525 if (reduce.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
526 return .none;526 return .none;
527 },527 },
528 .cmp_vector, .cmp_vector_optimized => {528 .cmp_vector, .cmp_vector_optimized => {
529 const extra = air.extraData(Air.VectorCmp, air_datas[inst].ty_pl.payload).data;529 const extra = air.extraData(Air.VectorCmp, air_datas[@intFromEnum(inst)].ty_pl.payload).data;
530 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);530 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
531 if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);531 if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
532 return .none;532 return .none;
533 },533 },
534 .aggregate_init => {534 .aggregate_init => {
535 const ty_pl = air_datas[inst].ty_pl;535 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;
536 const aggregate_ty = air.getRefType(ty_pl.ty);536 const aggregate_ty = ty_pl.ty.toType();
537 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));537 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
538 const elements = @as([]const Air.Inst.Ref, @ptrCast(air.extra[ty_pl.payload..][0..len]));538 const elements = @as([]const Air.Inst.Ref, @ptrCast(air.extra[ty_pl.payload..][0..len]));
539539
...@@ -555,29 +555,29 @@ pub fn categorizeOperand(...@@ -555,29 +555,29 @@ pub fn categorizeOperand(
555 return .write;555 return .write;
556 },556 },
557 .union_init => {557 .union_init => {
558 const extra = air.extraData(Air.UnionInit, air_datas[inst].ty_pl.payload).data;558 const extra = air.extraData(Air.UnionInit, air_datas[@intFromEnum(inst)].ty_pl.payload).data;
559 if (extra.init == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);559 if (extra.init == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
560 return .none;560 return .none;
561 },561 },
562 .struct_field_ptr, .struct_field_val => {562 .struct_field_ptr, .struct_field_val => {
563 const extra = air.extraData(Air.StructField, air_datas[inst].ty_pl.payload).data;563 const extra = air.extraData(Air.StructField, air_datas[@intFromEnum(inst)].ty_pl.payload).data;
564 if (extra.struct_operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);564 if (extra.struct_operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
565 return .none;565 return .none;
566 },566 },
567 .field_parent_ptr => {567 .field_parent_ptr => {
568 const extra = air.extraData(Air.FieldParentPtr, air_datas[inst].ty_pl.payload).data;568 const extra = air.extraData(Air.FieldParentPtr, air_datas[@intFromEnum(inst)].ty_pl.payload).data;
569 if (extra.field_ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);569 if (extra.field_ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
570 return .none;570 return .none;
571 },571 },
572 .cmpxchg_strong, .cmpxchg_weak => {572 .cmpxchg_strong, .cmpxchg_weak => {
573 const extra = air.extraData(Air.Cmpxchg, air_datas[inst].ty_pl.payload).data;573 const extra = air.extraData(Air.Cmpxchg, air_datas[@intFromEnum(inst)].ty_pl.payload).data;
574 if (extra.ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);574 if (extra.ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
575 if (extra.expected_value == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write);575 if (extra.expected_value == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write);
576 if (extra.new_value == operand_ref) return matchOperandSmallIndex(l, inst, 2, .write);576 if (extra.new_value == operand_ref) return matchOperandSmallIndex(l, inst, 2, .write);
577 return .write;577 return .write;
578 },578 },
579 .mul_add => {579 .mul_add => {
580 const pl_op = air_datas[inst].pl_op;580 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
581 const extra = air.extraData(Air.Bin, pl_op.payload).data;581 const extra = air.extraData(Air.Bin, pl_op.payload).data;
582 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);582 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
583 if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);583 if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
...@@ -585,12 +585,12 @@ pub fn categorizeOperand(...@@ -585,12 +585,12 @@ pub fn categorizeOperand(
585 return .none;585 return .none;
586 },586 },
587 .atomic_load => {587 .atomic_load => {
588 const ptr = air_datas[inst].atomic_load.ptr;588 const ptr = air_datas[@intFromEnum(inst)].atomic_load.ptr;
589 if (ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);589 if (ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
590 return .none;590 return .none;
591 },591 },
592 .atomic_rmw => {592 .atomic_rmw => {
593 const pl_op = air_datas[inst].pl_op;593 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
594 const extra = air.extraData(Air.AtomicRmw, pl_op.payload).data;594 const extra = air.extraData(Air.AtomicRmw, pl_op.payload).data;
595 if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);595 if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
596 if (extra.operand == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write);596 if (extra.operand == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write);
...@@ -598,7 +598,7 @@ pub fn categorizeOperand(...@@ -598,7 +598,7 @@ pub fn categorizeOperand(
598 },598 },
599599
600 .br => {600 .br => {
601 const br = air_datas[inst].br;601 const br = air_datas[@intFromEnum(inst)].br;
602 if (br.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .noret);602 if (br.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .noret);
603 return .noret;603 return .noret;
604 },604 },
...@@ -606,16 +606,16 @@ pub fn categorizeOperand(...@@ -606,16 +606,16 @@ pub fn categorizeOperand(
606 return .complex;606 return .complex;
607 },607 },
608 .block => {608 .block => {
609 const extra = air.extraData(Air.Block, air_datas[inst].ty_pl.payload);609 const extra = air.extraData(Air.Block, air_datas[@intFromEnum(inst)].ty_pl.payload);
610 const body = air.extra[extra.end..][0..extra.data.body_len];610 const body: []const Air.Inst.Index = @ptrCast(air.extra[extra.end..][0..extra.data.body_len]);
611611
612 if (body.len == 1 and air_tags[body[0]] == .cond_br) {612 if (body.len == 1 and air_tags[@intFromEnum(body[0])] == .cond_br) {
613 // Peephole optimization for "panic-like" conditionals, which have613 // Peephole optimization for "panic-like" conditionals, which have
614 // one empty branch and another which calls a `noreturn` function.614 // one empty branch and another which calls a `noreturn` function.
615 // This allows us to infer that safety checks do not modify memory,615 // This allows us to infer that safety checks do not modify memory,
616 // as far as control flow successors are concerned.616 // as far as control flow successors are concerned.
617617
618 const inst_data = air_datas[body[0]].pl_op;618 const inst_data = air_datas[@intFromEnum(body[0])].pl_op;
619 const cond_extra = air.extraData(Air.CondBr, inst_data.payload);619 const cond_extra = air.extraData(Air.CondBr, inst_data.payload);
620 if (inst_data.operand == operand_ref and operandDies(l, body[0], 0))620 if (inst_data.operand == operand_ref and operandDies(l, body[0], 0))
621 return .tomb;621 return .tomb;
...@@ -623,21 +623,21 @@ pub fn categorizeOperand(...@@ -623,21 +623,21 @@ pub fn categorizeOperand(
623 if (cond_extra.data.then_body_len > 2 or cond_extra.data.else_body_len > 2)623 if (cond_extra.data.then_body_len > 2 or cond_extra.data.else_body_len > 2)
624 return .complex;624 return .complex;
625625
626 const then_body = air.extra[cond_extra.end..][0..cond_extra.data.then_body_len];626 const then_body: []const Air.Inst.Index = @ptrCast(air.extra[cond_extra.end..][0..cond_extra.data.then_body_len]);
627 const else_body = air.extra[cond_extra.end + cond_extra.data.then_body_len ..][0..cond_extra.data.else_body_len];627 const else_body: []const Air.Inst.Index = @ptrCast(air.extra[cond_extra.end + cond_extra.data.then_body_len ..][0..cond_extra.data.else_body_len]);
628 if (then_body.len > 1 and air_tags[then_body[1]] != .unreach)628 if (then_body.len > 1 and air_tags[@intFromEnum(then_body[1])] != .unreach)
629 return .complex;629 return .complex;
630 if (else_body.len > 1 and air_tags[else_body[1]] != .unreach)630 if (else_body.len > 1 and air_tags[@intFromEnum(else_body[1])] != .unreach)
631 return .complex;631 return .complex;
632632
633 var operand_live: bool = true;633 var operand_live: bool = true;
634 for (&[_]u32{ then_body[0], else_body[0] }) |cond_inst| {634 for (&[_]Air.Inst.Index{ then_body[0], else_body[0] }) |cond_inst| {
635 if (l.categorizeOperand(air, cond_inst, operand, ip) == .tomb)635 if (l.categorizeOperand(air, cond_inst, operand, ip) == .tomb)
636 operand_live = false;636 operand_live = false;
637637
638 switch (air_tags[cond_inst]) {638 switch (air_tags[@intFromEnum(cond_inst)]) {
639 .br => { // Breaks immediately back to block639 .br => { // Breaks immediately back to block
640 const br = air_datas[cond_inst].br;640 const br = air_datas[@intFromEnum(cond_inst)].br;
641 if (br.block_inst != inst)641 if (br.block_inst != inst)
642 return .complex;642 return .complex;
643 },643 },
...@@ -666,7 +666,7 @@ pub fn categorizeOperand(...@@ -666,7 +666,7 @@ pub fn categorizeOperand(
666 return .complex;666 return .complex;
667 },667 },
668 .wasm_memory_grow => {668 .wasm_memory_grow => {
669 const pl_op = air_datas[inst].pl_op;669 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
670 if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);670 if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
671 return .none;671 return .none;
672 },672 },
...@@ -701,11 +701,11 @@ pub fn getCondBr(l: Liveness, inst: Air.Inst.Index) CondBrSlices {...@@ -701,11 +701,11 @@ pub fn getCondBr(l: Liveness, inst: Air.Inst.Index) CondBrSlices {
701 index += 1;701 index += 1;
702 const else_death_count = l.extra[index];702 const else_death_count = l.extra[index];
703 index += 1;703 index += 1;
704 const then_deaths = l.extra[index..][0..then_death_count];704 const then_deaths: []const Air.Inst.Index = @ptrCast(l.extra[index..][0..then_death_count]);
705 index += then_death_count;705 index += then_death_count;
706 return .{706 return .{
707 .then_deaths = then_deaths,707 .then_deaths = then_deaths,
708 .else_deaths = l.extra[index..][0..else_death_count],708 .else_deaths = @ptrCast(l.extra[index..][0..else_death_count]),
709 };709 };
710}710}
711711
...@@ -731,13 +731,13 @@ pub fn getSwitchBr(l: Liveness, gpa: Allocator, inst: Air.Inst.Index, cases_len:...@@ -731,13 +731,13 @@ pub fn getSwitchBr(l: Liveness, gpa: Allocator, inst: Air.Inst.Index, cases_len:
731 while (case_i < cases_len - 1) : (case_i += 1) {731 while (case_i < cases_len - 1) : (case_i += 1) {
732 const case_death_count: u32 = l.extra[index];732 const case_death_count: u32 = l.extra[index];
733 index += 1;733 index += 1;
734 const case_deaths = l.extra[index..][0..case_death_count];734 const case_deaths: []const Air.Inst.Index = @ptrCast(l.extra[index..][0..case_death_count]);
735 index += case_death_count;735 index += case_death_count;
736 deaths.appendAssumeCapacity(case_deaths);736 deaths.appendAssumeCapacity(case_deaths);
737 }737 }
738 {738 {
739 // Else739 // Else
740 const else_deaths = l.extra[index..][0..else_death_count];740 const else_deaths: []const Air.Inst.Index = @ptrCast(l.extra[index..][0..else_death_count]);
741 deaths.appendAssumeCapacity(else_deaths);741 deaths.appendAssumeCapacity(else_deaths);
742 }742 }
743 return SwitchBrTable{743 return SwitchBrTable{
...@@ -756,7 +756,7 @@ pub fn getBlock(l: Liveness, inst: Air.Inst.Index) BlockSlices {...@@ -756,7 +756,7 @@ pub fn getBlock(l: Liveness, inst: Air.Inst.Index) BlockSlices {
756 .deaths = &.{},756 .deaths = &.{},
757 };757 };
758 const death_count = l.extra[index];758 const death_count = l.extra[index];
759 const deaths = l.extra[index + 1 ..][0..death_count];759 const deaths: []const Air.Inst.Index = @ptrCast(l.extra[index + 1 ..][0..death_count]);
760 return .{760 return .{
761 .deaths = deaths,761 .deaths = deaths,
762 };762 };
...@@ -883,7 +883,7 @@ fn analyzeInst(...@@ -883,7 +883,7 @@ fn analyzeInst(
883 const inst_tags = a.air.instructions.items(.tag);883 const inst_tags = a.air.instructions.items(.tag);
884 const inst_datas = a.air.instructions.items(.data);884 const inst_datas = a.air.instructions.items(.data);
885885
886 switch (inst_tags[inst]) {886 switch (inst_tags[@intFromEnum(inst)]) {
887 .add,887 .add,
888 .add_safe,888 .add_safe,
889 .add_optimized,889 .add_optimized,
...@@ -949,12 +949,12 @@ fn analyzeInst(...@@ -949,12 +949,12 @@ fn analyzeInst(
949 .memset_safe,949 .memset_safe,
950 .memcpy,950 .memcpy,
951 => {951 => {
952 const o = inst_datas[inst].bin_op;952 const o = inst_datas[@intFromEnum(inst)].bin_op;
953 return analyzeOperands(a, pass, data, inst, .{ o.lhs, o.rhs, .none });953 return analyzeOperands(a, pass, data, inst, .{ o.lhs, o.rhs, .none });
954 },954 },
955955
956 .vector_store_elem => {956 .vector_store_elem => {
957 const o = inst_datas[inst].vector_store_elem;957 const o = inst_datas[@intFromEnum(inst)].vector_store_elem;
958 const extra = a.air.extraData(Air.Bin, o.payload).data;958 const extra = a.air.extraData(Air.Bin, o.payload).data;
959 return analyzeOperands(a, pass, data, inst, .{ o.vector_ptr, extra.lhs, extra.rhs });959 return analyzeOperands(a, pass, data, inst, .{ o.vector_ptr, extra.lhs, extra.rhs });
960 },960 },
...@@ -1029,7 +1029,7 @@ fn analyzeInst(...@@ -1029,7 +1029,7 @@ fn analyzeInst(
1029 .c_va_copy,1029 .c_va_copy,
1030 .abs,1030 .abs,
1031 => {1031 => {
1032 const o = inst_datas[inst].ty_op;1032 const o = inst_datas[@intFromEnum(inst)].ty_op;
1033 return analyzeOperands(a, pass, data, inst, .{ o.operand, .none, .none });1033 return analyzeOperands(a, pass, data, inst, .{ o.operand, .none, .none });
1034 },1034 },
10351035
...@@ -1065,14 +1065,14 @@ fn analyzeInst(...@@ -1065,14 +1065,14 @@ fn analyzeInst(
1065 .set_err_return_trace,1065 .set_err_return_trace,
1066 .c_va_end,1066 .c_va_end,
1067 => {1067 => {
1068 const operand = inst_datas[inst].un_op;1068 const operand = inst_datas[@intFromEnum(inst)].un_op;
1069 return analyzeOperands(a, pass, data, inst, .{ operand, .none, .none });1069 return analyzeOperands(a, pass, data, inst, .{ operand, .none, .none });
1070 },1070 },
10711071
1072 .ret,1072 .ret,
1073 .ret_load,1073 .ret_load,
1074 => {1074 => {
1075 const operand = inst_datas[inst].un_op;1075 const operand = inst_datas[@intFromEnum(inst)].un_op;
1076 return analyzeFuncEnd(a, pass, data, inst, .{ operand, .none, .none });1076 return analyzeFuncEnd(a, pass, data, inst, .{ operand, .none, .none });
1077 },1077 },
10781078
...@@ -1086,7 +1086,7 @@ fn analyzeInst(...@@ -1086,7 +1086,7 @@ fn analyzeInst(
1086 .slice_elem_ptr,1086 .slice_elem_ptr,
1087 .slice,1087 .slice,
1088 => {1088 => {
1089 const ty_pl = inst_datas[inst].ty_pl;1089 const ty_pl = inst_datas[@intFromEnum(inst)].ty_pl;
1090 const extra = a.air.extraData(Air.Bin, ty_pl.payload).data;1090 const extra = a.air.extraData(Air.Bin, ty_pl.payload).data;
1091 return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, .none });1091 return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, .none });
1092 },1092 },
...@@ -1094,17 +1094,17 @@ fn analyzeInst(...@@ -1094,17 +1094,17 @@ fn analyzeInst(
1094 .dbg_var_ptr,1094 .dbg_var_ptr,
1095 .dbg_var_val,1095 .dbg_var_val,
1096 => {1096 => {
1097 const operand = inst_datas[inst].pl_op.operand;1097 const operand = inst_datas[@intFromEnum(inst)].pl_op.operand;
1098 return analyzeOperands(a, pass, data, inst, .{ operand, .none, .none });1098 return analyzeOperands(a, pass, data, inst, .{ operand, .none, .none });
1099 },1099 },
11001100
1101 .prefetch => {1101 .prefetch => {
1102 const prefetch = inst_datas[inst].prefetch;1102 const prefetch = inst_datas[@intFromEnum(inst)].prefetch;
1103 return analyzeOperands(a, pass, data, inst, .{ prefetch.ptr, .none, .none });1103 return analyzeOperands(a, pass, data, inst, .{ prefetch.ptr, .none, .none });
1104 },1104 },
11051105
1106 .call, .call_always_tail, .call_never_tail, .call_never_inline => {1106 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
1107 const inst_data = inst_datas[inst].pl_op;1107 const inst_data = inst_datas[@intFromEnum(inst)].pl_op;
1108 const callee = inst_data.operand;1108 const callee = inst_data.operand;
1109 const extra = a.air.extraData(Air.Call, inst_data.payload);1109 const extra = a.air.extraData(Air.Call, inst_data.payload);
1110 const args = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra.end..][0..extra.data.args_len]));1110 const args = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra.end..][0..extra.data.args_len]));
...@@ -1126,25 +1126,25 @@ fn analyzeInst(...@@ -1126,25 +1126,25 @@ fn analyzeInst(
1126 return big.finish();1126 return big.finish();
1127 },1127 },
1128 .select => {1128 .select => {
1129 const pl_op = inst_datas[inst].pl_op;1129 const pl_op = inst_datas[@intFromEnum(inst)].pl_op;
1130 const extra = a.air.extraData(Air.Bin, pl_op.payload).data;1130 const extra = a.air.extraData(Air.Bin, pl_op.payload).data;
1131 return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, extra.lhs, extra.rhs });1131 return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, extra.lhs, extra.rhs });
1132 },1132 },
1133 .shuffle => {1133 .shuffle => {
1134 const extra = a.air.extraData(Air.Shuffle, inst_datas[inst].ty_pl.payload).data;1134 const extra = a.air.extraData(Air.Shuffle, inst_datas[@intFromEnum(inst)].ty_pl.payload).data;
1135 return analyzeOperands(a, pass, data, inst, .{ extra.a, extra.b, .none });1135 return analyzeOperands(a, pass, data, inst, .{ extra.a, extra.b, .none });
1136 },1136 },
1137 .reduce, .reduce_optimized => {1137 .reduce, .reduce_optimized => {
1138 const reduce = inst_datas[inst].reduce;1138 const reduce = inst_datas[@intFromEnum(inst)].reduce;
1139 return analyzeOperands(a, pass, data, inst, .{ reduce.operand, .none, .none });1139 return analyzeOperands(a, pass, data, inst, .{ reduce.operand, .none, .none });
1140 },1140 },
1141 .cmp_vector, .cmp_vector_optimized => {1141 .cmp_vector, .cmp_vector_optimized => {
1142 const extra = a.air.extraData(Air.VectorCmp, inst_datas[inst].ty_pl.payload).data;1142 const extra = a.air.extraData(Air.VectorCmp, inst_datas[@intFromEnum(inst)].ty_pl.payload).data;
1143 return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, .none });1143 return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, .none });
1144 },1144 },
1145 .aggregate_init => {1145 .aggregate_init => {
1146 const ty_pl = inst_datas[inst].ty_pl;1146 const ty_pl = inst_datas[@intFromEnum(inst)].ty_pl;
1147 const aggregate_ty = a.air.getRefType(ty_pl.ty);1147 const aggregate_ty = ty_pl.ty.toType();
1148 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));1148 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
1149 const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[ty_pl.payload..][0..len]));1149 const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[ty_pl.payload..][0..len]));
11501150
...@@ -1164,32 +1164,32 @@ fn analyzeInst(...@@ -1164,32 +1164,32 @@ fn analyzeInst(
1164 return big.finish();1164 return big.finish();
1165 },1165 },
1166 .union_init => {1166 .union_init => {
1167 const extra = a.air.extraData(Air.UnionInit, inst_datas[inst].ty_pl.payload).data;1167 const extra = a.air.extraData(Air.UnionInit, inst_datas[@intFromEnum(inst)].ty_pl.payload).data;
1168 return analyzeOperands(a, pass, data, inst, .{ extra.init, .none, .none });1168 return analyzeOperands(a, pass, data, inst, .{ extra.init, .none, .none });
1169 },1169 },
1170 .struct_field_ptr, .struct_field_val => {1170 .struct_field_ptr, .struct_field_val => {
1171 const extra = a.air.extraData(Air.StructField, inst_datas[inst].ty_pl.payload).data;1171 const extra = a.air.extraData(Air.StructField, inst_datas[@intFromEnum(inst)].ty_pl.payload).data;
1172 return analyzeOperands(a, pass, data, inst, .{ extra.struct_operand, .none, .none });1172 return analyzeOperands(a, pass, data, inst, .{ extra.struct_operand, .none, .none });
1173 },1173 },
1174 .field_parent_ptr => {1174 .field_parent_ptr => {
1175 const extra = a.air.extraData(Air.FieldParentPtr, inst_datas[inst].ty_pl.payload).data;1175 const extra = a.air.extraData(Air.FieldParentPtr, inst_datas[@intFromEnum(inst)].ty_pl.payload).data;
1176 return analyzeOperands(a, pass, data, inst, .{ extra.field_ptr, .none, .none });1176 return analyzeOperands(a, pass, data, inst, .{ extra.field_ptr, .none, .none });
1177 },1177 },
1178 .cmpxchg_strong, .cmpxchg_weak => {1178 .cmpxchg_strong, .cmpxchg_weak => {
1179 const extra = a.air.extraData(Air.Cmpxchg, inst_datas[inst].ty_pl.payload).data;1179 const extra = a.air.extraData(Air.Cmpxchg, inst_datas[@intFromEnum(inst)].ty_pl.payload).data;
1180 return analyzeOperands(a, pass, data, inst, .{ extra.ptr, extra.expected_value, extra.new_value });1180 return analyzeOperands(a, pass, data, inst, .{ extra.ptr, extra.expected_value, extra.new_value });
1181 },1181 },
1182 .mul_add => {1182 .mul_add => {
1183 const pl_op = inst_datas[inst].pl_op;1183 const pl_op = inst_datas[@intFromEnum(inst)].pl_op;
1184 const extra = a.air.extraData(Air.Bin, pl_op.payload).data;1184 const extra = a.air.extraData(Air.Bin, pl_op.payload).data;
1185 return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, pl_op.operand });1185 return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, pl_op.operand });
1186 },1186 },
1187 .atomic_load => {1187 .atomic_load => {
1188 const ptr = inst_datas[inst].atomic_load.ptr;1188 const ptr = inst_datas[@intFromEnum(inst)].atomic_load.ptr;
1189 return analyzeOperands(a, pass, data, inst, .{ ptr, .none, .none });1189 return analyzeOperands(a, pass, data, inst, .{ ptr, .none, .none });
1190 },1190 },
1191 .atomic_rmw => {1191 .atomic_rmw => {
1192 const pl_op = inst_datas[inst].pl_op;1192 const pl_op = inst_datas[@intFromEnum(inst)].pl_op;
1193 const extra = a.air.extraData(Air.AtomicRmw, pl_op.payload).data;1193 const extra = a.air.extraData(Air.AtomicRmw, pl_op.payload).data;
1194 return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, extra.operand, .none });1194 return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, extra.operand, .none });
1195 },1195 },
...@@ -1197,7 +1197,7 @@ fn analyzeInst(...@@ -1197,7 +1197,7 @@ fn analyzeInst(
1197 .br => return analyzeInstBr(a, pass, data, inst),1197 .br => return analyzeInstBr(a, pass, data, inst),
11981198
1199 .assembly => {1199 .assembly => {
1200 const extra = a.air.extraData(Air.Asm, inst_datas[inst].ty_pl.payload);1200 const extra = a.air.extraData(Air.Asm, inst_datas[@intFromEnum(inst)].ty_pl.payload);
1201 var extra_i: usize = extra.end;1201 var extra_i: usize = extra.end;
1202 const outputs = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra_i..][0..extra.data.outputs_len]));1202 const outputs = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra_i..][0..extra.data.outputs_len]));
1203 extra_i += outputs.len;1203 extra_i += outputs.len;
...@@ -1246,7 +1246,7 @@ fn analyzeInst(...@@ -1246,7 +1246,7 @@ fn analyzeInst(
1246 .switch_br => return analyzeInstSwitchBr(a, pass, data, inst),1246 .switch_br => return analyzeInstSwitchBr(a, pass, data, inst),
12471247
1248 .wasm_memory_grow => {1248 .wasm_memory_grow => {
1249 const pl_op = inst_datas[inst].pl_op;1249 const pl_op = inst_datas[@intFromEnum(inst)].pl_op;
1250 return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, .none, .none });1250 return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, .none, .none });
1251 },1251 },
1252 }1252 }
...@@ -1270,20 +1270,20 @@ fn analyzeOperands(...@@ -1270,20 +1270,20 @@ fn analyzeOperands(
1270 _ = data.live_set.remove(inst);1270 _ = data.live_set.remove(inst);
12711271
1272 for (operands) |op_ref| {1272 for (operands) |op_ref| {
1273 const operand = Air.refToIndexAllowNone(op_ref) orelse continue;1273 const operand = op_ref.toIndexAllowNone() orelse continue;
1274 _ = try data.live_set.put(gpa, operand, {});1274 _ = try data.live_set.put(gpa, operand, {});
1275 }1275 }
1276 },1276 },
12771277
1278 .main_analysis => {1278 .main_analysis => {
1279 const usize_index = (inst * bpi) / @bitSizeOf(usize);1279 const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize);
12801280
1281 // This logic must synchronize with `will_die_immediately` in `AnalyzeBigOperands.init`.1281 // This logic must synchronize with `will_die_immediately` in `AnalyzeBigOperands.init`.
1282 const immediate_death = if (data.live_set.remove(inst)) blk: {1282 const immediate_death = if (data.live_set.remove(inst)) blk: {
1283 log.debug("[{}] %{}: removed from live set", .{ pass, inst });1283 log.debug("[{}] %{}: removed from live set", .{ pass, @intFromEnum(inst) });
1284 break :blk false;1284 break :blk false;
1285 } else blk: {1285 } else blk: {
1286 log.debug("[{}] %{}: immediate death", .{ pass, inst });1286 log.debug("[{}] %{}: immediate death", .{ pass, @intFromEnum(inst) });
1287 break :blk true;1287 break :blk true;
1288 };1288 };
12891289
...@@ -1299,19 +1299,19 @@ fn analyzeOperands(...@@ -1299,19 +1299,19 @@ fn analyzeOperands(
1299 while (i > 0) {1299 while (i > 0) {
1300 i -= 1;1300 i -= 1;
1301 const op_ref = operands[i];1301 const op_ref = operands[i];
1302 const operand = Air.refToIndexAllowNone(op_ref) orelse continue;1302 const operand = op_ref.toIndexAllowNone() orelse continue;
13031303
1304 const mask = @as(Bpi, 1) << @as(OperandInt, @intCast(i));1304 const mask = @as(Bpi, 1) << @as(OperandInt, @intCast(i));
13051305
1306 if ((try data.live_set.fetchPut(gpa, operand, {})) == null) {1306 if ((try data.live_set.fetchPut(gpa, operand, {})) == null) {
1307 log.debug("[{}] %{}: added %{} to live set (operand dies here)", .{ pass, inst, operand });1307 log.debug("[{}] %{}: added %{} to live set (operand dies here)", .{ pass, @intFromEnum(inst), operand });
1308 tomb_bits |= mask;1308 tomb_bits |= mask;
1309 }1309 }
1310 }1310 }
1311 }1311 }
13121312
1313 a.tomb_bits[usize_index] |= @as(usize, tomb_bits) <<1313 a.tomb_bits[usize_index] |= @as(usize, tomb_bits) <<
1314 @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi));1314 @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi));
1315 },1315 },
1316 }1316 }
1317}1317}
...@@ -1346,7 +1346,7 @@ fn analyzeInstBr(...@@ -1346,7 +1346,7 @@ fn analyzeInstBr(
1346 inst: Air.Inst.Index,1346 inst: Air.Inst.Index,
1347) !void {1347) !void {
1348 const inst_datas = a.air.instructions.items(.data);1348 const inst_datas = a.air.instructions.items(.data);
1349 const br = inst_datas[inst].br;1349 const br = inst_datas[@intFromEnum(inst)].br;
1350 const gpa = a.gpa;1350 const gpa = a.gpa;
13511351
1352 switch (pass) {1352 switch (pass) {
...@@ -1373,9 +1373,9 @@ fn analyzeInstBlock(...@@ -1373,9 +1373,9 @@ fn analyzeInstBlock(
1373 inst: Air.Inst.Index,1373 inst: Air.Inst.Index,
1374) !void {1374) !void {
1375 const inst_datas = a.air.instructions.items(.data);1375 const inst_datas = a.air.instructions.items(.data);
1376 const ty_pl = inst_datas[inst].ty_pl;1376 const ty_pl = inst_datas[@intFromEnum(inst)].ty_pl;
1377 const extra = a.air.extraData(Air.Block, ty_pl.payload);1377 const extra = a.air.extraData(Air.Block, ty_pl.payload);
1378 const body = a.air.extra[extra.end..][0..extra.data.body_len];1378 const body: []const Air.Inst.Index = @ptrCast(a.air.extra[extra.end..][0..extra.data.body_len]);
13791379
1380 const gpa = a.gpa;1380 const gpa = a.gpa;
13811381
...@@ -1405,7 +1405,7 @@ fn analyzeInstBlock(...@@ -1405,7 +1405,7 @@ fn analyzeInstBlock(
14051405
1406 // If the block is noreturn, block deaths not only aren't useful, they're impossible to1406 // If the block is noreturn, block deaths not only aren't useful, they're impossible to
1407 // find: there could be more stuff alive after the block than before it!1407 // find: there could be more stuff alive after the block than before it!
1408 if (!a.intern_pool.isNoReturn(a.air.getRefType(ty_pl.ty).ip_index)) {1408 if (!a.intern_pool.isNoReturn(ty_pl.ty.toType().ip_index)) {
1409 // The block kills the difference in the live sets1409 // The block kills the difference in the live sets
1410 const block_scope = data.block_scopes.get(inst).?;1410 const block_scope = data.block_scopes.get(inst).?;
1411 const num_deaths = data.live_set.count() - block_scope.live_set.count();1411 const num_deaths = data.live_set.count() - block_scope.live_set.count();
...@@ -1421,7 +1421,7 @@ fn analyzeInstBlock(...@@ -1421,7 +1421,7 @@ fn analyzeInstBlock(
1421 const alive = key.*;1421 const alive = key.*;
1422 if (!block_scope.live_set.contains(alive)) {1422 if (!block_scope.live_set.contains(alive)) {
1423 // Dies in block1423 // Dies in block
1424 a.extra.appendAssumeCapacity(alive);1424 a.extra.appendAssumeCapacity(@intFromEnum(alive));
1425 measured_num += 1;1425 measured_num += 1;
1426 }1426 }
1427 }1427 }
...@@ -1430,7 +1430,7 @@ fn analyzeInstBlock(...@@ -1430,7 +1430,7 @@ fn analyzeInstBlock(
1430 log.debug("[{}] %{}: block deaths are {}", .{1430 log.debug("[{}] %{}: block deaths are {}", .{
1431 pass,1431 pass,
1432 inst,1432 inst,
1433 fmtInstList(a.extra.items[extra_index + 1 ..][0..num_deaths]),1433 fmtInstList(@ptrCast(a.extra.items[extra_index + 1 ..][0..num_deaths])),
1434 });1434 });
1435 }1435 }
1436 },1436 },
...@@ -1444,8 +1444,8 @@ fn analyzeInstLoop(...@@ -1444,8 +1444,8 @@ fn analyzeInstLoop(
1444 inst: Air.Inst.Index,1444 inst: Air.Inst.Index,
1445) !void {1445) !void {
1446 const inst_datas = a.air.instructions.items(.data);1446 const inst_datas = a.air.instructions.items(.data);
1447 const extra = a.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);1447 const extra = a.air.extraData(Air.Block, inst_datas[@intFromEnum(inst)].ty_pl.payload);
1448 const body = a.air.extra[extra.end..][0..extra.data.body_len];1448 const body: []const Air.Inst.Index = @ptrCast(a.air.extra[extra.end..][0..extra.data.body_len]);
1449 const gpa = a.gpa;1449 const gpa = a.gpa;
14501450
1451 try analyzeOperands(a, pass, data, inst, .{ .none, .none, .none });1451 try analyzeOperands(a, pass, data, inst, .{ .none, .none, .none });
...@@ -1469,7 +1469,7 @@ fn analyzeInstLoop(...@@ -1469,7 +1469,7 @@ fn analyzeInstLoop(
1469 var it = data.breaks.keyIterator();1469 var it = data.breaks.keyIterator();
1470 while (it.next()) |key| {1470 while (it.next()) |key| {
1471 const block_inst = key.*;1471 const block_inst = key.*;
1472 a.extra.appendAssumeCapacity(block_inst);1472 a.extra.appendAssumeCapacity(@intFromEnum(block_inst));
1473 }1473 }
1474 log.debug("[{}] %{}: includes breaks to {}", .{ pass, inst, fmtInstSet(&data.breaks) });1474 log.debug("[{}] %{}: includes breaks to {}", .{ pass, inst, fmtInstSet(&data.breaks) });
14751475
...@@ -1481,7 +1481,7 @@ fn analyzeInstLoop(...@@ -1481,7 +1481,7 @@ fn analyzeInstLoop(
1481 it = data.live_set.keyIterator();1481 it = data.live_set.keyIterator();
1482 while (it.next()) |key| {1482 while (it.next()) |key| {
1483 const alive = key.*;1483 const alive = key.*;
1484 a.extra.appendAssumeCapacity(alive);1484 a.extra.appendAssumeCapacity(@intFromEnum(alive));
1485 }1485 }
1486 log.debug("[{}] %{}: maintain liveness of {}", .{ pass, inst, fmtInstSet(&data.live_set) });1486 log.debug("[{}] %{}: maintain liveness of {}", .{ pass, inst, fmtInstSet(&data.live_set) });
14871487
...@@ -1506,15 +1506,15 @@ fn analyzeInstLoop(...@@ -1506,15 +1506,15 @@ fn analyzeInstLoop(
1506 const extra_idx = a.special.fetchRemove(inst).?.value; // remove because this data does not exist after analysis1506 const extra_idx = a.special.fetchRemove(inst).?.value; // remove because this data does not exist after analysis
15071507
1508 const num_breaks = data.old_extra.items[extra_idx];1508 const num_breaks = data.old_extra.items[extra_idx];
1509 const breaks = data.old_extra.items[extra_idx + 1 ..][0..num_breaks];1509 const breaks: []const Air.Inst.Index = @ptrCast(data.old_extra.items[extra_idx + 1 ..][0..num_breaks]);
15101510
1511 const num_loop_live = data.old_extra.items[extra_idx + num_breaks + 1];1511 const num_loop_live = data.old_extra.items[extra_idx + num_breaks + 1];
1512 const loop_live = data.old_extra.items[extra_idx + num_breaks + 2 ..][0..num_loop_live];1512 const loop_live: []const Air.Inst.Index = @ptrCast(data.old_extra.items[extra_idx + num_breaks + 2 ..][0..num_loop_live]);
15131513
1514 // This is necessarily not in the same control flow branch, because loops are noreturn1514 // This is necessarily not in the same control flow branch, because loops are noreturn
1515 data.live_set.clearRetainingCapacity();1515 data.live_set.clearRetainingCapacity();
15161516
1517 try data.live_set.ensureUnusedCapacity(gpa, @as(u32, @intCast(loop_live.len)));1517 try data.live_set.ensureUnusedCapacity(gpa, @intCast(loop_live.len));
1518 for (loop_live) |alive| {1518 for (loop_live) |alive| {
1519 data.live_set.putAssumeCapacity(alive, {});1519 data.live_set.putAssumeCapacity(alive, {});
1520 }1520 }
...@@ -1551,25 +1551,25 @@ fn analyzeInstCondBr(...@@ -1551,25 +1551,25 @@ fn analyzeInstCondBr(
1551 const gpa = a.gpa;1551 const gpa = a.gpa;
15521552
1553 const extra = switch (inst_type) {1553 const extra = switch (inst_type) {
1554 .cond_br => a.air.extraData(Air.CondBr, inst_datas[inst].pl_op.payload),1554 .cond_br => a.air.extraData(Air.CondBr, inst_datas[@intFromEnum(inst)].pl_op.payload),
1555 .@"try" => a.air.extraData(Air.Try, inst_datas[inst].pl_op.payload),1555 .@"try" => a.air.extraData(Air.Try, inst_datas[@intFromEnum(inst)].pl_op.payload),
1556 .try_ptr => a.air.extraData(Air.TryPtr, inst_datas[inst].ty_pl.payload),1556 .try_ptr => a.air.extraData(Air.TryPtr, inst_datas[@intFromEnum(inst)].ty_pl.payload),
1557 };1557 };
15581558
1559 const condition = switch (inst_type) {1559 const condition = switch (inst_type) {
1560 .cond_br, .@"try" => inst_datas[inst].pl_op.operand,1560 .cond_br, .@"try" => inst_datas[@intFromEnum(inst)].pl_op.operand,
1561 .try_ptr => extra.data.ptr,1561 .try_ptr => extra.data.ptr,
1562 };1562 };
15631563
1564 const then_body = switch (inst_type) {1564 const then_body: []const Air.Inst.Index = switch (inst_type) {
1565 .cond_br => a.air.extra[extra.end..][0..extra.data.then_body_len],1565 .cond_br => @ptrCast(a.air.extra[extra.end..][0..extra.data.then_body_len]),
1566 else => {}, // we won't use this1566 else => &.{}, // we won't use this
1567 };1567 };
15681568
1569 const else_body = switch (inst_type) {1569 const else_body: []const Air.Inst.Index = @ptrCast(switch (inst_type) {
1570 .cond_br => a.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len],1570 .cond_br => a.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len],
1571 .@"try", .try_ptr => a.air.extra[extra.end..][0..extra.data.body_len],1571 .@"try", .try_ptr => a.air.extra[extra.end..][0..extra.data.body_len],
1572 };1572 });
15731573
1574 switch (pass) {1574 switch (pass) {
1575 .loop_analysis => {1575 .loop_analysis => {
...@@ -1645,8 +1645,8 @@ fn analyzeInstCondBr(...@@ -1645,8 +1645,8 @@ fn analyzeInstCondBr(
1645 .then_death_count = then_death_count,1645 .then_death_count = then_death_count,
1646 .else_death_count = else_death_count,1646 .else_death_count = else_death_count,
1647 });1647 });
1648 a.extra.appendSliceAssumeCapacity(then_mirrored_deaths.items);1648 a.extra.appendSliceAssumeCapacity(@ptrCast(then_mirrored_deaths.items));
1649 a.extra.appendSliceAssumeCapacity(else_mirrored_deaths.items);1649 a.extra.appendSliceAssumeCapacity(@ptrCast(else_mirrored_deaths.items));
1650 try a.special.put(gpa, inst, extra_index);1650 try a.special.put(gpa, inst, extra_index);
1651 },1651 },
1652 }1652 }
...@@ -1661,7 +1661,7 @@ fn analyzeInstSwitchBr(...@@ -1661,7 +1661,7 @@ fn analyzeInstSwitchBr(
1661 inst: Air.Inst.Index,1661 inst: Air.Inst.Index,
1662) !void {1662) !void {
1663 const inst_datas = a.air.instructions.items(.data);1663 const inst_datas = a.air.instructions.items(.data);
1664 const pl_op = inst_datas[inst].pl_op;1664 const pl_op = inst_datas[@intFromEnum(inst)].pl_op;
1665 const condition = pl_op.operand;1665 const condition = pl_op.operand;
1666 const switch_br = a.air.extraData(Air.SwitchBr, pl_op.payload);1666 const switch_br = a.air.extraData(Air.SwitchBr, pl_op.payload);
1667 const gpa = a.gpa;1667 const gpa = a.gpa;
...@@ -1672,12 +1672,12 @@ fn analyzeInstSwitchBr(...@@ -1672,12 +1672,12 @@ fn analyzeInstSwitchBr(
1672 var air_extra_index: usize = switch_br.end;1672 var air_extra_index: usize = switch_br.end;
1673 for (0..ncases) |_| {1673 for (0..ncases) |_| {
1674 const case = a.air.extraData(Air.SwitchBr.Case, air_extra_index);1674 const case = a.air.extraData(Air.SwitchBr.Case, air_extra_index);
1675 const case_body = a.air.extra[case.end + case.data.items_len ..][0..case.data.body_len];1675 const case_body: []const Air.Inst.Index = @ptrCast(a.air.extra[case.end + case.data.items_len ..][0..case.data.body_len]);
1676 air_extra_index = case.end + case.data.items_len + case_body.len;1676 air_extra_index = case.end + case.data.items_len + case_body.len;
1677 try analyzeBody(a, pass, data, case_body);1677 try analyzeBody(a, pass, data, case_body);
1678 }1678 }
1679 { // else1679 { // else
1680 const else_body = a.air.extra[air_extra_index..][0..switch_br.data.else_body_len];1680 const else_body: []const Air.Inst.Index = @ptrCast(a.air.extra[air_extra_index..][0..switch_br.data.else_body_len]);
1681 try analyzeBody(a, pass, data, else_body);1681 try analyzeBody(a, pass, data, else_body);
1682 }1682 }
1683 },1683 },
...@@ -1698,13 +1698,13 @@ fn analyzeInstSwitchBr(...@@ -1698,13 +1698,13 @@ fn analyzeInstSwitchBr(
1698 var air_extra_index: usize = switch_br.end;1698 var air_extra_index: usize = switch_br.end;
1699 for (case_live_sets[0..ncases]) |*live_set| {1699 for (case_live_sets[0..ncases]) |*live_set| {
1700 const case = a.air.extraData(Air.SwitchBr.Case, air_extra_index);1700 const case = a.air.extraData(Air.SwitchBr.Case, air_extra_index);
1701 const case_body = a.air.extra[case.end + case.data.items_len ..][0..case.data.body_len];1701 const case_body: []const Air.Inst.Index = @ptrCast(a.air.extra[case.end + case.data.items_len ..][0..case.data.body_len]);
1702 air_extra_index = case.end + case.data.items_len + case_body.len;1702 air_extra_index = case.end + case.data.items_len + case_body.len;
1703 try analyzeBody(a, pass, data, case_body);1703 try analyzeBody(a, pass, data, case_body);
1704 live_set.* = data.live_set.move();1704 live_set.* = data.live_set.move();
1705 }1705 }
1706 { // else1706 { // else
1707 const else_body = a.air.extra[air_extra_index..][0..switch_br.data.else_body_len];1707 const else_body: []const Air.Inst.Index = @ptrCast(a.air.extra[air_extra_index..][0..switch_br.data.else_body_len]);
1708 try analyzeBody(a, pass, data, else_body);1708 try analyzeBody(a, pass, data, else_body);
1709 case_live_sets[ncases] = data.live_set.move();1709 case_live_sets[ncases] = data.live_set.move();
1710 }1710 }
...@@ -1757,10 +1757,10 @@ fn analyzeInstSwitchBr(...@@ -1757,10 +1757,10 @@ fn analyzeInstSwitchBr(
1757 const num = @as(u32, @intCast(mirrored.items.len));1757 const num = @as(u32, @intCast(mirrored.items.len));
1758 try a.extra.ensureUnusedCapacity(gpa, num + 1);1758 try a.extra.ensureUnusedCapacity(gpa, num + 1);
1759 a.extra.appendAssumeCapacity(num);1759 a.extra.appendAssumeCapacity(num);
1760 a.extra.appendSliceAssumeCapacity(mirrored.items);1760 a.extra.appendSliceAssumeCapacity(@ptrCast(mirrored.items));
1761 }1761 }
1762 try a.extra.ensureUnusedCapacity(gpa, else_death_count);1762 try a.extra.ensureUnusedCapacity(gpa, else_death_count);
1763 a.extra.appendSliceAssumeCapacity(mirrored_deaths[ncases].items);1763 a.extra.appendSliceAssumeCapacity(@ptrCast(mirrored_deaths[ncases].items));
1764 try a.special.put(gpa, inst, extra_index);1764 try a.special.put(gpa, inst, extra_index);
1765 },1765 },
1766 }1766 }
...@@ -1826,7 +1826,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {...@@ -1826,7 +1826,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
1826 return;1826 return;
1827 }1827 }
18281828
1829 const operand = Air.refToIndex(op_ref) orelse return;1829 const operand = op_ref.toIndex() orelse return;
18301830
1831 // If our result is unused and the instruction doesn't need to be lowered, backends will1831 // If our result is unused and the instruction doesn't need to be lowered, backends will
1832 // skip the lowering of this instruction, so we don't want to record uses of operands.1832 // skip the lowering of this instruction, so we don't want to record uses of operands.
src/Liveness/Verify.zig+42-42
...@@ -37,7 +37,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -37,7 +37,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
37 continue;37 continue;
38 }38 }
3939
40 switch (tag[inst]) {40 switch (tag[@intFromEnum(inst)]) {
41 // no operands41 // no operands
42 .arg,42 .arg,
43 .alloc,43 .alloc,
...@@ -112,7 +112,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -112,7 +112,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
112 .c_va_copy,112 .c_va_copy,
113 .abs,113 .abs,
114 => {114 => {
115 const ty_op = data[inst].ty_op;115 const ty_op = data[@intFromEnum(inst)].ty_op;
116 try self.verifyInstOperands(inst, .{ ty_op.operand, .none, .none });116 try self.verifyInstOperands(inst, .{ ty_op.operand, .none, .none });
117 },117 },
118 .is_null,118 .is_null,
...@@ -147,13 +147,13 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -147,13 +147,13 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
147 .set_err_return_trace,147 .set_err_return_trace,
148 .c_va_end,148 .c_va_end,
149 => {149 => {
150 const un_op = data[inst].un_op;150 const un_op = data[@intFromEnum(inst)].un_op;
151 try self.verifyInstOperands(inst, .{ un_op, .none, .none });151 try self.verifyInstOperands(inst, .{ un_op, .none, .none });
152 },152 },
153 .ret,153 .ret,
154 .ret_load,154 .ret_load,
155 => {155 => {
156 const un_op = data[inst].un_op;156 const un_op = data[@intFromEnum(inst)].un_op;
157 try self.verifyInstOperands(inst, .{ un_op, .none, .none });157 try self.verifyInstOperands(inst, .{ un_op, .none, .none });
158 // This instruction terminates the function, so everything should be dead158 // This instruction terminates the function, so everything should be dead
159 if (self.live.count() > 0) return invalid("%{}: instructions still alive", .{inst});159 if (self.live.count() > 0) return invalid("%{}: instructions still alive", .{inst});
...@@ -162,36 +162,36 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -162,36 +162,36 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
162 .dbg_var_val,162 .dbg_var_val,
163 .wasm_memory_grow,163 .wasm_memory_grow,
164 => {164 => {
165 const pl_op = data[inst].pl_op;165 const pl_op = data[@intFromEnum(inst)].pl_op;
166 try self.verifyInstOperands(inst, .{ pl_op.operand, .none, .none });166 try self.verifyInstOperands(inst, .{ pl_op.operand, .none, .none });
167 },167 },
168 .prefetch => {168 .prefetch => {
169 const prefetch = data[inst].prefetch;169 const prefetch = data[@intFromEnum(inst)].prefetch;
170 try self.verifyInstOperands(inst, .{ prefetch.ptr, .none, .none });170 try self.verifyInstOperands(inst, .{ prefetch.ptr, .none, .none });
171 },171 },
172 .reduce,172 .reduce,
173 .reduce_optimized,173 .reduce_optimized,
174 => {174 => {
175 const reduce = data[inst].reduce;175 const reduce = data[@intFromEnum(inst)].reduce;
176 try self.verifyInstOperands(inst, .{ reduce.operand, .none, .none });176 try self.verifyInstOperands(inst, .{ reduce.operand, .none, .none });
177 },177 },
178 .union_init => {178 .union_init => {
179 const ty_pl = data[inst].ty_pl;179 const ty_pl = data[@intFromEnum(inst)].ty_pl;
180 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;180 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
181 try self.verifyInstOperands(inst, .{ extra.init, .none, .none });181 try self.verifyInstOperands(inst, .{ extra.init, .none, .none });
182 },182 },
183 .struct_field_ptr, .struct_field_val => {183 .struct_field_ptr, .struct_field_val => {
184 const ty_pl = data[inst].ty_pl;184 const ty_pl = data[@intFromEnum(inst)].ty_pl;
185 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;185 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
186 try self.verifyInstOperands(inst, .{ extra.struct_operand, .none, .none });186 try self.verifyInstOperands(inst, .{ extra.struct_operand, .none, .none });
187 },187 },
188 .field_parent_ptr => {188 .field_parent_ptr => {
189 const ty_pl = data[inst].ty_pl;189 const ty_pl = data[@intFromEnum(inst)].ty_pl;
190 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;190 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
191 try self.verifyInstOperands(inst, .{ extra.field_ptr, .none, .none });191 try self.verifyInstOperands(inst, .{ extra.field_ptr, .none, .none });
192 },192 },
193 .atomic_load => {193 .atomic_load => {
194 const atomic_load = data[inst].atomic_load;194 const atomic_load = data[@intFromEnum(inst)].atomic_load;
195 try self.verifyInstOperands(inst, .{ atomic_load.ptr, .none, .none });195 try self.verifyInstOperands(inst, .{ atomic_load.ptr, .none, .none });
196 },196 },
197197
...@@ -261,7 +261,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -261,7 +261,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
261 .memset_safe,261 .memset_safe,
262 .memcpy,262 .memcpy,
263 => {263 => {
264 const bin_op = data[inst].bin_op;264 const bin_op = data[@intFromEnum(inst)].bin_op;
265 try self.verifyInstOperands(inst, .{ bin_op.lhs, bin_op.rhs, .none });265 try self.verifyInstOperands(inst, .{ bin_op.lhs, bin_op.rhs, .none });
266 },266 },
267 .add_with_overflow,267 .add_with_overflow,
...@@ -274,56 +274,56 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -274,56 +274,56 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
274 .slice_elem_ptr,274 .slice_elem_ptr,
275 .slice,275 .slice,
276 => {276 => {
277 const ty_pl = data[inst].ty_pl;277 const ty_pl = data[@intFromEnum(inst)].ty_pl;
278 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;278 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
279 try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, .none });279 try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, .none });
280 },280 },
281 .shuffle => {281 .shuffle => {
282 const ty_pl = data[inst].ty_pl;282 const ty_pl = data[@intFromEnum(inst)].ty_pl;
283 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;283 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
284 try self.verifyInstOperands(inst, .{ extra.a, extra.b, .none });284 try self.verifyInstOperands(inst, .{ extra.a, extra.b, .none });
285 },285 },
286 .cmp_vector,286 .cmp_vector,
287 .cmp_vector_optimized,287 .cmp_vector_optimized,
288 => {288 => {
289 const ty_pl = data[inst].ty_pl;289 const ty_pl = data[@intFromEnum(inst)].ty_pl;
290 const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;290 const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;
291 try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, .none });291 try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, .none });
292 },292 },
293 .atomic_rmw => {293 .atomic_rmw => {
294 const pl_op = data[inst].pl_op;294 const pl_op = data[@intFromEnum(inst)].pl_op;
295 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;295 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
296 try self.verifyInstOperands(inst, .{ pl_op.operand, extra.operand, .none });296 try self.verifyInstOperands(inst, .{ pl_op.operand, extra.operand, .none });
297 },297 },
298298
299 // ternary299 // ternary
300 .select => {300 .select => {
301 const pl_op = data[inst].pl_op;301 const pl_op = data[@intFromEnum(inst)].pl_op;
302 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;302 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
303 try self.verifyInstOperands(inst, .{ pl_op.operand, extra.lhs, extra.rhs });303 try self.verifyInstOperands(inst, .{ pl_op.operand, extra.lhs, extra.rhs });
304 },304 },
305 .mul_add => {305 .mul_add => {
306 const pl_op = data[inst].pl_op;306 const pl_op = data[@intFromEnum(inst)].pl_op;
307 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;307 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
308 try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, pl_op.operand });308 try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, pl_op.operand });
309 },309 },
310 .vector_store_elem => {310 .vector_store_elem => {
311 const vector_store_elem = data[inst].vector_store_elem;311 const vector_store_elem = data[@intFromEnum(inst)].vector_store_elem;
312 const extra = self.air.extraData(Air.Bin, vector_store_elem.payload).data;312 const extra = self.air.extraData(Air.Bin, vector_store_elem.payload).data;
313 try self.verifyInstOperands(inst, .{ vector_store_elem.vector_ptr, extra.lhs, extra.rhs });313 try self.verifyInstOperands(inst, .{ vector_store_elem.vector_ptr, extra.lhs, extra.rhs });
314 },314 },
315 .cmpxchg_strong,315 .cmpxchg_strong,
316 .cmpxchg_weak,316 .cmpxchg_weak,
317 => {317 => {
318 const ty_pl = data[inst].ty_pl;318 const ty_pl = data[@intFromEnum(inst)].ty_pl;
319 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;319 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
320 try self.verifyInstOperands(inst, .{ extra.ptr, extra.expected_value, extra.new_value });320 try self.verifyInstOperands(inst, .{ extra.ptr, extra.expected_value, extra.new_value });
321 },321 },
322322
323 // big tombs323 // big tombs
324 .aggregate_init => {324 .aggregate_init => {
325 const ty_pl = data[inst].ty_pl;325 const ty_pl = data[@intFromEnum(inst)].ty_pl;
326 const aggregate_ty = self.air.getRefType(ty_pl.ty);326 const aggregate_ty = ty_pl.ty.toType();
327 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));327 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
328 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));328 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
329329
...@@ -334,7 +334,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -334,7 +334,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
334 try self.verifyInst(inst);334 try self.verifyInst(inst);
335 },335 },
336 .call, .call_always_tail, .call_never_tail, .call_never_inline => {336 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
337 const pl_op = data[inst].pl_op;337 const pl_op = data[@intFromEnum(inst)].pl_op;
338 const extra = self.air.extraData(Air.Call, pl_op.payload);338 const extra = self.air.extraData(Air.Call, pl_op.payload);
339 const args = @as(339 const args = @as(
340 []const Air.Inst.Ref,340 []const Air.Inst.Ref,
...@@ -349,7 +349,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -349,7 +349,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
349 try self.verifyInst(inst);349 try self.verifyInst(inst);
350 },350 },
351 .assembly => {351 .assembly => {
352 const ty_pl = data[inst].ty_pl;352 const ty_pl = data[@intFromEnum(inst)].ty_pl;
353 const extra = self.air.extraData(Air.Asm, ty_pl.payload);353 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
354 var extra_i = extra.end;354 var extra_i = extra.end;
355 const outputs = @as(355 const outputs = @as(
...@@ -377,9 +377,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -377,9 +377,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
377377
378 // control flow378 // control flow
379 .@"try" => {379 .@"try" => {
380 const pl_op = data[inst].pl_op;380 const pl_op = data[@intFromEnum(inst)].pl_op;
381 const extra = self.air.extraData(Air.Try, pl_op.payload);381 const extra = self.air.extraData(Air.Try, pl_op.payload);
382 const try_body = self.air.extra[extra.end..][0..extra.data.body_len];382 const try_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
383383
384 const cond_br_liveness = self.liveness.getCondBr(inst);384 const cond_br_liveness = self.liveness.getCondBr(inst);
385385
...@@ -399,9 +399,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -399,9 +399,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
399 try self.verifyInst(inst);399 try self.verifyInst(inst);
400 },400 },
401 .try_ptr => {401 .try_ptr => {
402 const ty_pl = data[inst].ty_pl;402 const ty_pl = data[@intFromEnum(inst)].ty_pl;
403 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);403 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
404 const try_body = self.air.extra[extra.end..][0..extra.data.body_len];404 const try_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
405405
406 const cond_br_liveness = self.liveness.getCondBr(inst);406 const cond_br_liveness = self.liveness.getCondBr(inst);
407407
...@@ -421,7 +421,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -421,7 +421,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
421 try self.verifyInst(inst);421 try self.verifyInst(inst);
422 },422 },
423 .br => {423 .br => {
424 const br = data[inst].br;424 const br = data[@intFromEnum(inst)].br;
425 const gop = try self.blocks.getOrPut(self.gpa, br.block_inst);425 const gop = try self.blocks.getOrPut(self.gpa, br.block_inst);
426426
427 try self.verifyOperand(inst, br.operand, self.liveness.operandDies(inst, 0));427 try self.verifyOperand(inst, br.operand, self.liveness.operandDies(inst, 0));
...@@ -433,10 +433,10 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -433,10 +433,10 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
433 try self.verifyInst(inst);433 try self.verifyInst(inst);
434 },434 },
435 .block => {435 .block => {
436 const ty_pl = data[inst].ty_pl;436 const ty_pl = data[@intFromEnum(inst)].ty_pl;
437 const block_ty = self.air.getRefType(ty_pl.ty);437 const block_ty = ty_pl.ty.toType();
438 const extra = self.air.extraData(Air.Block, ty_pl.payload);438 const extra = self.air.extraData(Air.Block, ty_pl.payload);
439 const block_body = self.air.extra[extra.end..][0..extra.data.body_len];439 const block_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
440 const block_liveness = self.liveness.getBlock(inst);440 const block_liveness = self.liveness.getBlock(inst);
441441
442 var orig_live = try self.live.clone(self.gpa);442 var orig_live = try self.live.clone(self.gpa);
...@@ -464,9 +464,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -464,9 +464,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
464 try self.verifyInstOperands(inst, .{ .none, .none, .none });464 try self.verifyInstOperands(inst, .{ .none, .none, .none });
465 },465 },
466 .loop => {466 .loop => {
467 const ty_pl = data[inst].ty_pl;467 const ty_pl = data[@intFromEnum(inst)].ty_pl;
468 const extra = self.air.extraData(Air.Block, ty_pl.payload);468 const extra = self.air.extraData(Air.Block, ty_pl.payload);
469 const loop_body = self.air.extra[extra.end..][0..extra.data.body_len];469 const loop_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
470470
471 var live = try self.live.clone(self.gpa);471 var live = try self.live.clone(self.gpa);
472 defer live.deinit(self.gpa);472 defer live.deinit(self.gpa);
...@@ -479,10 +479,10 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -479,10 +479,10 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
479 try self.verifyInstOperands(inst, .{ .none, .none, .none });479 try self.verifyInstOperands(inst, .{ .none, .none, .none });
480 },480 },
481 .cond_br => {481 .cond_br => {
482 const pl_op = data[inst].pl_op;482 const pl_op = data[@intFromEnum(inst)].pl_op;
483 const extra = self.air.extraData(Air.CondBr, pl_op.payload);483 const extra = self.air.extraData(Air.CondBr, pl_op.payload);
484 const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len];484 const then_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.then_body_len]);
485 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];485 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
486 const cond_br_liveness = self.liveness.getCondBr(inst);486 const cond_br_liveness = self.liveness.getCondBr(inst);
487487
488 try self.verifyOperand(inst, pl_op.operand, self.liveness.operandDies(inst, 0));488 try self.verifyOperand(inst, pl_op.operand, self.liveness.operandDies(inst, 0));
...@@ -502,7 +502,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -502,7 +502,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
502 try self.verifyInst(inst);502 try self.verifyInst(inst);
503 },503 },
504 .switch_br => {504 .switch_br => {
505 const pl_op = data[inst].pl_op;505 const pl_op = data[@intFromEnum(inst)].pl_op;
506 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);506 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
507 var extra_index = switch_br.end;507 var extra_index = switch_br.end;
508 var case_i: u32 = 0;508 var case_i: u32 = 0;
...@@ -524,7 +524,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -524,7 +524,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
524 []const Air.Inst.Ref,524 []const Air.Inst.Ref,
525 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]),525 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]),
526 );526 );
527 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];527 const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]);
528 extra_index = case.end + items.len + case_body.len;528 extra_index = case.end + items.len + case_body.len;
529529
530 self.live.deinit(self.gpa);530 self.live.deinit(self.gpa);
...@@ -534,7 +534,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -534,7 +534,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
534 try self.verifyBody(case_body);534 try self.verifyBody(case_body);
535 }535 }
536536
537 const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len];537 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]);
538 if (else_body.len > 0) {538 if (else_body.len > 0) {
539 self.live.deinit(self.gpa);539 self.live.deinit(self.gpa);
540 self.live = try live.clone(self.gpa);540 self.live = try live.clone(self.gpa);
...@@ -550,11 +550,11 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -550,11 +550,11 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
550}550}
551551
552fn verifyDeath(self: *Verify, inst: Air.Inst.Index, operand: Air.Inst.Index) Error!void {552fn verifyDeath(self: *Verify, inst: Air.Inst.Index, operand: Air.Inst.Index) Error!void {
553 try self.verifyOperand(inst, Air.indexToRef(operand), true);553 try self.verifyOperand(inst, operand.toRef(), true);
554}554}
555555
556fn verifyOperand(self: *Verify, inst: Air.Inst.Index, op_ref: Air.Inst.Ref, dies: bool) Error!void {556fn verifyOperand(self: *Verify, inst: Air.Inst.Index, op_ref: Air.Inst.Ref, dies: bool) Error!void {
557 const operand = Air.refToIndexAllowNone(op_ref) orelse {557 const operand = op_ref.toIndexAllowNone() orelse {
558 assert(!dies);558 assert(!dies);
559 return;559 return;
560 };560 };
src/Module.zig+4-4
...@@ -4591,8 +4591,8 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4591,8 +4591,8 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4591 gop.value_ptr.* = Air.internedToRef(opv.toIntern());4591 gop.value_ptr.* = Air.internedToRef(opv.toIntern());
4592 continue;4592 continue;
4593 }4593 }
4594 const arg_index: u32 = @intCast(sema.air_instructions.len);4594 const arg_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
4595 gop.value_ptr.* = Air.indexToRef(arg_index);4595 gop.value_ptr.* = arg_index.toRef();
4596 inner_block.instructions.appendAssumeCapacity(arg_index);4596 inner_block.instructions.appendAssumeCapacity(arg_index);
4597 sema.air_instructions.appendAssumeCapacity(.{4597 sema.air_instructions.appendAssumeCapacity(.{
4598 .tag = .arg,4598 .tag = .arg,
...@@ -4626,7 +4626,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4626,7 +4626,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4626 while (it.next()) |ptr_inst| {4626 while (it.next()) |ptr_inst| {
4627 // The lack of a resolve_inferred_alloc means that this instruction4627 // The lack of a resolve_inferred_alloc means that this instruction
4628 // is unused so it just has to be a no-op.4628 // is unused so it just has to be a no-op.
4629 sema.air_instructions.set(ptr_inst.*, .{4629 sema.air_instructions.set(@intFromEnum(ptr_inst.*), .{
4630 .tag = .alloc,4630 .tag = .alloc,
4631 .data = .{ .ty = Type.single_const_pointer_to_comptime_int },4631 .data = .{ .ty = Type.single_const_pointer_to_comptime_int },
4632 });4632 });
...@@ -4659,7 +4659,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4659,7 +4659,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4659 const main_block_index = sema.addExtraAssumeCapacity(Air.Block{4659 const main_block_index = sema.addExtraAssumeCapacity(Air.Block{
4660 .body_len = @intCast(inner_block.instructions.items.len),4660 .body_len = @intCast(inner_block.instructions.items.len),
4661 });4661 });
4662 sema.air_extra.appendSliceAssumeCapacity(inner_block.instructions.items);4662 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(inner_block.instructions.items));
4663 sema.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)] = main_block_index;4663 sema.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)] = main_block_index;
46644664
4665 // Resolving inferred error sets is done *before* setting the function4665 // Resolving inferred error sets is done *before* setting the function
src/Sema.zig+195-195
...@@ -741,7 +741,7 @@ pub const Block = struct {...@@ -741,7 +741,7 @@ pub const Block = struct {
741 }741 }
742742
743 pub fn addInst(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref {743 pub fn addInst(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref {
744 return Air.indexToRef(try block.addInstAsIndex(inst));744 return (try block.addInstAsIndex(inst)).toRef();
745 }745 }
746746
747 pub fn addInstAsIndex(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index {747 pub fn addInstAsIndex(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index {
...@@ -751,7 +751,7 @@ pub const Block = struct {...@@ -751,7 +751,7 @@ pub const Block = struct {
751 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);751 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
752 try block.instructions.ensureUnusedCapacity(gpa, 1);752 try block.instructions.ensureUnusedCapacity(gpa, 1);
753753
754 const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len);754 const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
755 sema.air_instructions.appendAssumeCapacity(inst);755 sema.air_instructions.appendAssumeCapacity(inst);
756 block.instructions.appendAssumeCapacity(result_index);756 block.instructions.appendAssumeCapacity(result_index);
757 return result_index;757 return result_index;
...@@ -760,7 +760,7 @@ pub const Block = struct {...@@ -760,7 +760,7 @@ pub const Block = struct {
760 /// Insert an instruction into the block at `index`. Moves all following760 /// Insert an instruction into the block at `index`. Moves all following
761 /// instructions forward in the block to make room. Operation is O(N).761 /// instructions forward in the block to make room. Operation is O(N).
762 pub fn insertInst(block: *Block, index: Air.Inst.Index, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref {762 pub fn insertInst(block: *Block, index: Air.Inst.Index, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref {
763 return Air.indexToRef(try block.insertInstAsIndex(index, inst));763 return (try block.insertInstAsIndex(index, inst)).toRef();
764 }764 }
765765
766 pub fn insertInstAsIndex(block: *Block, index: Air.Inst.Index, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index {766 pub fn insertInstAsIndex(block: *Block, index: Air.Inst.Index, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index {
...@@ -769,10 +769,10 @@ pub const Block = struct {...@@ -769,10 +769,10 @@ pub const Block = struct {
769769
770 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);770 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
771771
772 const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len);772 const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
773 sema.air_instructions.appendAssumeCapacity(inst);773 sema.air_instructions.appendAssumeCapacity(inst);
774774
775 try block.instructions.insert(gpa, index, result_index);775 try block.instructions.insert(gpa, @intFromEnum(index), result_index);
776 return result_index;776 return result_index;
777 }777 }
778778
...@@ -935,7 +935,7 @@ pub fn analyzeBodyBreak(...@@ -935,7 +935,7 @@ pub fn analyzeBodyBreak(
935 else => |e| return e,935 else => |e| return e,
936 };936 };
937 if (block.instructions.items.len != 0 and937 if (block.instructions.items.len != 0 and
938 sema.isNoReturn(Air.indexToRef(block.instructions.items[block.instructions.items.len - 1])))938 sema.isNoReturn(block.instructions.items[block.instructions.items.len - 1].toRef()))
939 return null;939 return null;
940 const break_data = sema.code.instructions.items(.data)[@intFromEnum(break_inst)].@"break";940 const break_data = sema.code.instructions.items(.data)[@intFromEnum(break_inst)].@"break";
941 const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data;941 const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data;
...@@ -1638,7 +1638,7 @@ fn analyzeBodyInner(...@@ -1638,7 +1638,7 @@ fn analyzeBodyInner(
1638 // Comptime control flow populates the map, so we don't actually know1638 // Comptime control flow populates the map, so we don't actually know
1639 // if this is a post-hoc runtime block until we check the1639 // if this is a post-hoc runtime block until we check the
1640 // post_hoc_block map.1640 // post_hoc_block map.
1641 const new_block_inst = Air.refToIndex(new_block_ref) orelse break :ph;1641 const new_block_inst = new_block_ref.toIndex() orelse break :ph;
1642 const labeled_block = sema.post_hoc_blocks.get(new_block_inst) orelse1642 const labeled_block = sema.post_hoc_blocks.get(new_block_inst) orelse
1643 break :ph;1643 break :ph;
16441644
...@@ -1817,7 +1817,7 @@ fn analyzeBodyInner(...@@ -1817,7 +1817,7 @@ fn analyzeBodyInner(
1817 if (sema.isNoReturn(air_inst)) {1817 if (sema.isNoReturn(air_inst)) {
1818 // We're going to assume that the body itself is noreturn, so let's ensure that now1818 // We're going to assume that the body itself is noreturn, so let's ensure that now
1819 assert(block.instructions.items.len > 0);1819 assert(block.instructions.items.len > 0);
1820 assert(sema.isNoReturn(Air.indexToRef(block.instructions.items[block.instructions.items.len - 1])));1820 assert(sema.isNoReturn(block.instructions.items[block.instructions.items.len - 1].toRef()));
1821 break always_noreturn;1821 break always_noreturn;
1822 }1822 }
1823 map.putAssumeCapacity(inst, air_inst);1823 map.putAssumeCapacity(inst, air_inst);
...@@ -2003,7 +2003,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {...@@ -2003,7 +2003,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {
2003 const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) {2003 const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) {
2004 error.GenericPoison => unreachable, // this is a type, not a value2004 error.GenericPoison => unreachable, // this is a type, not a value
2005 };2005 };
2006 const operand_val = Air.refToInterned(operand_ref) orelse return .unknown;2006 const operand_val = operand_ref.toInterned() orelse return .unknown;
2007 if (operand_val == .generic_poison_type) {2007 if (operand_val == .generic_poison_type) {
2008 // The pointer was generic poison - keep looking.2008 // The pointer was generic poison - keep looking.
2009 cur = un_node.operand;2009 cur = un_node.operand;
...@@ -2158,14 +2158,14 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val...@@ -2158,14 +2158,14 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val
21582158
2159 const air_tags = sema.air_instructions.items(.tag);2159 const air_tags = sema.air_instructions.items(.tag);
2160 if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {2160 if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {
2161 if (Air.refToInterned(inst)) |ip_index| {2161 if (inst.toInterned()) |ip_index| {
2162 const val = Value.fromInterned(ip_index);2162 const val = Value.fromInterned(ip_index);
2163 if (val.getVariable(sema.mod) != null) return val;2163 if (val.getVariable(sema.mod) != null) return val;
2164 }2164 }
2165 return opv;2165 return opv;
2166 }2166 }
2167 const ip_index = Air.refToInterned(inst) orelse {2167 const ip_index = inst.toInterned() orelse {
2168 switch (air_tags[Air.refToIndex(inst).?]) {2168 switch (air_tags[@intFromEnum(inst.toIndex().?)]) {
2169 .inferred_alloc => unreachable,2169 .inferred_alloc => unreachable,
2170 .inferred_alloc_comptime => unreachable,2170 .inferred_alloc_comptime => unreachable,
2171 else => return null,2171 else => return null,
...@@ -3543,7 +3543,7 @@ fn zirAllocExtended(...@@ -3543,7 +3543,7 @@ fn zirAllocExtended(
3543 .is_const = small.is_const,3543 .is_const = small.is_const,
3544 } },3544 } },
3545 });3545 });
3546 return Air.indexToRef(@intCast(sema.air_instructions.len - 1));3546 return @as(Air.Inst.Index, @enumFromInt(sema.air_instructions.len - 1)).toRef();
3547 }3547 }
3548 }3548 }
35493549
...@@ -3562,7 +3562,7 @@ fn zirAllocExtended(...@@ -3562,7 +3562,7 @@ fn zirAllocExtended(
3562 });3562 });
3563 const ptr = try block.addTy(.alloc, ptr_type);3563 const ptr = try block.addTy(.alloc, ptr_type);
3564 if (small.is_const) {3564 if (small.is_const) {
3565 const ptr_inst = Air.refToIndex(ptr).?;3565 const ptr_inst = ptr.toIndex().?;
3566 try sema.maybe_comptime_allocs.put(gpa, ptr_inst, .{ .runtime_index = block.runtime_index });3566 try sema.maybe_comptime_allocs.put(gpa, ptr_inst, .{ .runtime_index = block.runtime_index });
3567 try sema.base_allocs.put(gpa, ptr_inst, ptr_inst);3567 try sema.base_allocs.put(gpa, ptr_inst, ptr_inst);
3568 }3568 }
...@@ -3581,7 +3581,7 @@ fn zirAllocExtended(...@@ -3581,7 +3581,7 @@ fn zirAllocExtended(
3581 try sema.maybe_comptime_allocs.put(gpa, result_index, .{ .runtime_index = block.runtime_index });3581 try sema.maybe_comptime_allocs.put(gpa, result_index, .{ .runtime_index = block.runtime_index });
3582 try sema.base_allocs.put(gpa, result_index, result_index);3582 try sema.base_allocs.put(gpa, result_index, result_index);
3583 }3583 }
3584 return Air.indexToRef(result_index);3584 return result_index.toRef();
3585}3585}
35863586
3587fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3587fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -3654,7 +3654,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3654,7 +3654,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3654 const ptr_info = alloc_ty.ptrInfo(mod);3654 const ptr_info = alloc_ty.ptrInfo(mod);
3655 const elem_ty = Type.fromInterned(ptr_info.child);3655 const elem_ty = Type.fromInterned(ptr_info.child);
36563656
3657 const alloc_inst = Air.refToIndex(alloc) orelse return null;3657 const alloc_inst = alloc.toIndex() orelse return null;
3658 const comptime_info = sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return null;3658 const comptime_info = sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return null;
3659 const stores = comptime_info.value.stores.items;3659 const stores = comptime_info.value.stores.items;
36603660
...@@ -3674,10 +3674,10 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3674,10 +3674,10 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3674 simple: {3674 simple: {
3675 if (stores.len != 1) break :simple;3675 if (stores.len != 1) break :simple;
3676 const store_inst = stores[0];3676 const store_inst = stores[0];
3677 const store_data = sema.air_instructions.items(.data)[store_inst].bin_op;3677 const store_data = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
3678 if (store_data.lhs != alloc) break :simple;3678 if (store_data.lhs != alloc) break :simple;
36793679
3680 const val = Air.refToInterned(store_data.rhs).?;3680 const val = store_data.rhs.toInterned().?;
3681 assert(mod.intern_pool.typeOf(val) == elem_ty.toIntern());3681 assert(mod.intern_pool.typeOf(val) == elem_ty.toIntern());
3682 return sema.finishResolveComptimeKnownAllocValue(val, alloc_inst, comptime_info.value);3682 return sema.finishResolveComptimeKnownAllocValue(val, alloc_inst, comptime_info.value);
3683 }3683 }
...@@ -3704,8 +3704,8 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3704,8 +3704,8 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
37043704
3705 var to_map = try std.ArrayList(Air.Inst.Index).initCapacity(sema.arena, stores.len);3705 var to_map = try std.ArrayList(Air.Inst.Index).initCapacity(sema.arena, stores.len);
3706 for (stores) |store_inst| {3706 for (stores) |store_inst| {
3707 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;3707 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
3708 to_map.appendAssumeCapacity(Air.refToIndex(bin_op.lhs).?);3708 to_map.appendAssumeCapacity(bin_op.lhs.toIndex().?);
3709 }3709 }
37103710
3711 const tmp_air = sema.getTmpAir();3711 const tmp_air = sema.getTmpAir();
...@@ -3719,12 +3719,12 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3719,12 +3719,12 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3719 field: u32,3719 field: u32,
3720 elem: u64,3720 elem: u64,
3721 };3721 };
3722 const inst_tag = tmp_air.instructions.items(.tag)[air_ptr];3722 const inst_tag = tmp_air.instructions.items(.tag)[@intFromEnum(air_ptr)];
3723 const air_parent_ptr: Air.Inst.Ref, const method: PointerMethod = switch (inst_tag) {3723 const air_parent_ptr: Air.Inst.Ref, const method: PointerMethod = switch (inst_tag) {
3724 .struct_field_ptr => blk: {3724 .struct_field_ptr => blk: {
3725 const data = tmp_air.extraData(3725 const data = tmp_air.extraData(
3726 Air.StructField,3726 Air.StructField,
3727 tmp_air.instructions.items(.data)[air_ptr].ty_pl.payload,3727 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_pl.payload,
3728 ).data;3728 ).data;
3729 break :blk .{3729 break :blk .{
3730 data.struct_operand,3730 data.struct_operand,
...@@ -3736,7 +3736,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3736,7 +3736,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3736 .struct_field_ptr_index_2,3736 .struct_field_ptr_index_2,
3737 .struct_field_ptr_index_3,3737 .struct_field_ptr_index_3,
3738 => .{3738 => .{
3739 tmp_air.instructions.items(.data)[air_ptr].ty_op.operand,3739 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand,
3740 .{ .field = switch (inst_tag) {3740 .{ .field = switch (inst_tag) {
3741 .struct_field_ptr_index_0 => 0,3741 .struct_field_ptr_index_0 => 0,
3742 .struct_field_ptr_index_1 => 1,3742 .struct_field_ptr_index_1 => 1,
...@@ -3746,17 +3746,17 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3746,17 +3746,17 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3746 } },3746 } },
3747 },3747 },
3748 .ptr_slice_ptr_ptr => .{3748 .ptr_slice_ptr_ptr => .{
3749 tmp_air.instructions.items(.data)[air_ptr].ty_op.operand,3749 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand,
3750 .{ .field = Value.slice_ptr_index },3750 .{ .field = Value.slice_ptr_index },
3751 },3751 },
3752 .ptr_slice_len_ptr => .{3752 .ptr_slice_len_ptr => .{
3753 tmp_air.instructions.items(.data)[air_ptr].ty_op.operand,3753 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand,
3754 .{ .field = Value.slice_len_index },3754 .{ .field = Value.slice_len_index },
3755 },3755 },
3756 .ptr_elem_ptr => blk: {3756 .ptr_elem_ptr => blk: {
3757 const data = tmp_air.extraData(3757 const data = tmp_air.extraData(
3758 Air.Bin,3758 Air.Bin,
3759 tmp_air.instructions.items(.data)[air_ptr].ty_pl.payload,3759 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_pl.payload,
3760 ).data;3760 ).data;
3761 const idx_val = (try sema.resolveValue(data.rhs)).?;3761 const idx_val = (try sema.resolveValue(data.rhs)).?;
3762 break :blk .{3762 break :blk .{
...@@ -3765,24 +3765,24 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3765,24 +3765,24 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3765 };3765 };
3766 },3766 },
3767 .bitcast => .{3767 .bitcast => .{
3768 tmp_air.instructions.items(.data)[air_ptr].ty_op.operand,3768 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand,
3769 .same_addr,3769 .same_addr,
3770 },3770 },
3771 .optional_payload_ptr_set => .{3771 .optional_payload_ptr_set => .{
3772 tmp_air.instructions.items(.data)[air_ptr].ty_op.operand,3772 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand,
3773 .opt_payload,3773 .opt_payload,
3774 },3774 },
3775 .errunion_payload_ptr_set => .{3775 .errunion_payload_ptr_set => .{
3776 tmp_air.instructions.items(.data)[air_ptr].ty_op.operand,3776 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand,
3777 .eu_payload,3777 .eu_payload,
3778 },3778 },
3779 else => unreachable,3779 else => unreachable,
3780 };3780 };
37813781
3782 const decl_parent_ptr = ptr_mapping.get(Air.refToIndex(air_parent_ptr).?) orelse {3782 const decl_parent_ptr = ptr_mapping.get(air_parent_ptr.toIndex().?) orelse {
3783 // Resolve the parent pointer first.3783 // Resolve the parent pointer first.
3784 // Note that we add in what seems like the wrong order, because we're popping from the end of this array.3784 // Note that we add in what seems like the wrong order, because we're popping from the end of this array.
3785 try to_map.appendSlice(&.{ air_ptr, Air.refToIndex(air_parent_ptr).? });3785 try to_map.appendSlice(&.{ air_ptr, air_parent_ptr.toIndex().? });
3786 continue;3786 continue;
3787 };3787 };
3788 const new_ptr_ty = tmp_air.typeOfIndex(air_ptr, &mod.intern_pool).toIntern();3788 const new_ptr_ty = tmp_air.typeOfIndex(air_ptr, &mod.intern_pool).toIntern();
...@@ -3811,12 +3811,12 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3811,12 +3811,12 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3811 // We have a correlation between AIR pointers and decl pointers. Perform all stores at comptime.3811 // We have a correlation between AIR pointers and decl pointers. Perform all stores at comptime.
38123812
3813 for (stores) |store_inst| {3813 for (stores) |store_inst| {
3814 switch (sema.air_instructions.items(.tag)[store_inst]) {3814 switch (sema.air_instructions.items(.tag)[@intFromEnum(store_inst)]) {
3815 .set_union_tag => {3815 .set_union_tag => {
3816 // If this tag has an OPV payload, there won't be a corresponding3816 // If this tag has an OPV payload, there won't be a corresponding
3817 // store instruction, so we must set the union payload now.3817 // store instruction, so we must set the union payload now.
3818 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;3818 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
3819 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;3819 const air_ptr_inst = bin_op.lhs.toIndex().?;
3820 const tag_val = (try sema.resolveValue(bin_op.rhs)).?;3820 const tag_val = (try sema.resolveValue(bin_op.rhs)).?;
3821 const union_ty = sema.typeOf(bin_op.lhs).childType(mod);3821 const union_ty = sema.typeOf(bin_op.lhs).childType(mod);
3822 const payload_ty = union_ty.unionFieldType(tag_val, mod).?;3822 const payload_ty = union_ty.unionFieldType(tag_val, mod).?;
...@@ -3827,8 +3827,8 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3827,8 +3827,8 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3827 }3827 }
3828 },3828 },
3829 .store, .store_safe => {3829 .store, .store_safe => {
3830 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;3830 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
3831 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;3831 const air_ptr_inst = bin_op.lhs.toIndex().?;
3832 const store_val = (try sema.resolveValue(bin_op.rhs)).?;3832 const store_val = (try sema.resolveValue(bin_op.rhs)).?;
3833 const new_ptr = ptr_mapping.get(air_ptr_inst).?;3833 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
3834 try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(mod.intern_pool.typeOf(store_val.toIntern())));3834 try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(mod.intern_pool.typeOf(store_val.toIntern())));
...@@ -3858,12 +3858,12 @@ fn finishResolveComptimeKnownAllocValue(sema: *Sema, result_val: InternPool.Inde...@@ -3858,12 +3858,12 @@ fn finishResolveComptimeKnownAllocValue(sema: *Sema, result_val: InternPool.Inde
3858 // Liveness to elide it.3858 // Liveness to elide it.
3859 const nop_inst: Air.Inst = .{ .tag = .bitcast, .data = .{ .ty_op = .{ .ty = .u8_type, .operand = .zero_u8 } } };3859 const nop_inst: Air.Inst = .{ .tag = .bitcast, .data = .{ .ty_op = .{ .ty = .u8_type, .operand = .zero_u8 } } };
38603860
3861 sema.air_instructions.set(alloc_inst, nop_inst);3861 sema.air_instructions.set(@intFromEnum(alloc_inst), nop_inst);
3862 for (comptime_info.stores.items) |store_inst| {3862 for (comptime_info.stores.items) |store_inst| {
3863 sema.air_instructions.set(store_inst, nop_inst);3863 sema.air_instructions.set(@intFromEnum(store_inst), nop_inst);
3864 }3864 }
3865 for (comptime_info.non_elideable_pointers.items) |ptr_inst| {3865 for (comptime_info.non_elideable_pointers.items) |ptr_inst| {
3866 sema.air_instructions.set(ptr_inst, nop_inst);3866 sema.air_instructions.set(@intFromEnum(ptr_inst), nop_inst);
3867 }3867 }
38683868
3869 return result_val;3869 return result_val;
...@@ -3905,7 +3905,7 @@ fn zirAllocInferredComptime(...@@ -3905,7 +3905,7 @@ fn zirAllocInferredComptime(
3905 .is_const = is_const,3905 .is_const = is_const,
3906 } },3906 } },
3907 });3907 });
3908 return Air.indexToRef(@intCast(sema.air_instructions.len - 1));3908 return @as(Air.Inst.Index, @enumFromInt(sema.air_instructions.len - 1)).toRef();
3909}3909}
39103910
3911fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3911fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -3925,7 +3925,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -3925,7 +3925,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
3925 });3925 });
3926 try sema.queueFullTypeResolution(var_ty);3926 try sema.queueFullTypeResolution(var_ty);
3927 const ptr = try block.addTy(.alloc, ptr_type);3927 const ptr = try block.addTy(.alloc, ptr_type);
3928 const ptr_inst = Air.refToIndex(ptr).?;3928 const ptr_inst = ptr.toIndex().?;
3929 try sema.maybe_comptime_allocs.put(sema.gpa, ptr_inst, .{ .runtime_index = block.runtime_index });3929 try sema.maybe_comptime_allocs.put(sema.gpa, ptr_inst, .{ .runtime_index = block.runtime_index });
3930 try sema.base_allocs.put(sema.gpa, ptr_inst, ptr_inst);3930 try sema.base_allocs.put(sema.gpa, ptr_inst, ptr_inst);
3931 return ptr;3931 return ptr;
...@@ -3974,7 +3974,7 @@ fn zirAllocInferred(...@@ -3974,7 +3974,7 @@ fn zirAllocInferred(
3974 .is_const = is_const,3974 .is_const = is_const,
3975 } },3975 } },
3976 });3976 });
3977 return Air.indexToRef(@intCast(sema.air_instructions.len - 1));3977 return @as(Air.Inst.Index, @enumFromInt(sema.air_instructions.len - 1)).toRef();
3978 }3978 }
39793979
3980 const result_index = try block.addInstAsIndex(.{3980 const result_index = try block.addInstAsIndex(.{
...@@ -3987,7 +3987,7 @@ fn zirAllocInferred(...@@ -3987,7 +3987,7 @@ fn zirAllocInferred(
3987 try sema.unresolved_inferred_allocs.putNoClobber(gpa, result_index, .{});3987 try sema.unresolved_inferred_allocs.putNoClobber(gpa, result_index, .{});
3988 try sema.maybe_comptime_allocs.put(gpa, result_index, .{ .runtime_index = block.runtime_index });3988 try sema.maybe_comptime_allocs.put(gpa, result_index, .{ .runtime_index = block.runtime_index });
3989 try sema.base_allocs.put(sema.gpa, result_index, result_index);3989 try sema.base_allocs.put(sema.gpa, result_index, result_index);
3990 return Air.indexToRef(result_index);3990 return result_index.toRef();
3991}3991}
39923992
3993fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {3993fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
...@@ -4000,12 +4000,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4000,12 +4000,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4000 const src = inst_data.src();4000 const src = inst_data.src();
4001 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };4001 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
4002 const ptr = try sema.resolveInst(inst_data.operand);4002 const ptr = try sema.resolveInst(inst_data.operand);
4003 const ptr_inst = Air.refToIndex(ptr).?;4003 const ptr_inst = ptr.toIndex().?;
4004 const target = mod.getTarget();4004 const target = mod.getTarget();
40054005
4006 switch (sema.air_instructions.items(.tag)[ptr_inst]) {4006 switch (sema.air_instructions.items(.tag)[@intFromEnum(ptr_inst)]) {
4007 .inferred_alloc_comptime => {4007 .inferred_alloc_comptime => {
4008 const iac = sema.air_instructions.items(.data)[ptr_inst].inferred_alloc_comptime;4008 const iac = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].inferred_alloc_comptime;
4009 const decl_index = iac.decl_index;4009 const decl_index = iac.decl_index;
40104010
4011 const decl = mod.declPtr(decl_index);4011 const decl = mod.declPtr(decl_index);
...@@ -4022,7 +4022,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4022,7 +4022,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
40224022
4023 if (std.debug.runtime_safety) {4023 if (std.debug.runtime_safety) {
4024 // The inferred_alloc_comptime should never be referenced again4024 // The inferred_alloc_comptime should never be referenced again
4025 sema.air_instructions.set(ptr_inst, .{ .tag = undefined, .data = undefined });4025 sema.air_instructions.set(@intFromEnum(ptr_inst), .{ .tag = undefined, .data = undefined });
4026 }4026 }
40274027
4028 try sema.maybeQueueFuncBodyAnalysis(decl_index);4028 try sema.maybeQueueFuncBodyAnalysis(decl_index);
...@@ -4039,12 +4039,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4039,12 +4039,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4039 sema.inst_map.putAssumeCapacity(inst_data.operand.toIndex().?, Air.internedToRef(interned));4039 sema.inst_map.putAssumeCapacity(inst_data.operand.toIndex().?, Air.internedToRef(interned));
4040 },4040 },
4041 .inferred_alloc => {4041 .inferred_alloc => {
4042 const ia1 = sema.air_instructions.items(.data)[ptr_inst].inferred_alloc;4042 const ia1 = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].inferred_alloc;
4043 const ia2 = sema.unresolved_inferred_allocs.fetchRemove(ptr_inst).?.value;4043 const ia2 = sema.unresolved_inferred_allocs.fetchRemove(ptr_inst).?.value;
4044 const peer_vals = try sema.arena.alloc(Air.Inst.Ref, ia2.prongs.items.len);4044 const peer_vals = try sema.arena.alloc(Air.Inst.Ref, ia2.prongs.items.len);
4045 for (peer_vals, ia2.prongs.items) |*peer_val, store_inst| {4045 for (peer_vals, ia2.prongs.items) |*peer_val, store_inst| {
4046 assert(sema.air_instructions.items(.tag)[store_inst] == .store);4046 assert(sema.air_instructions.items(.tag)[@intFromEnum(store_inst)] == .store);
4047 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;4047 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
4048 peer_val.* = bin_op.rhs;4048 peer_val.* = bin_op.rhs;
4049 }4049 }
4050 const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_vals, .none);4050 const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_vals, .none);
...@@ -4083,7 +4083,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4083,7 +4083,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4083 try sema.queueFullTypeResolution(final_elem_ty);4083 try sema.queueFullTypeResolution(final_elem_ty);
40844084
4085 // Change it to a normal alloc.4085 // Change it to a normal alloc.
4086 sema.air_instructions.set(ptr_inst, .{4086 sema.air_instructions.set(@intFromEnum(ptr_inst), .{
4087 .tag = .alloc,4087 .tag = .alloc,
4088 .data = .{ .ty = final_ptr_ty },4088 .data = .{ .ty = final_ptr_ty },
4089 });4089 });
...@@ -4095,15 +4095,15 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4095,15 +4095,15 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4095 var replacement_block = block.makeSubBlock();4095 var replacement_block = block.makeSubBlock();
4096 defer replacement_block.instructions.deinit(gpa);4096 defer replacement_block.instructions.deinit(gpa);
40974097
4098 assert(sema.air_instructions.items(.tag)[placeholder_inst] == .store);4098 assert(sema.air_instructions.items(.tag)[@intFromEnum(placeholder_inst)] == .store);
4099 const bin_op = sema.air_instructions.items(.data)[placeholder_inst].bin_op;4099 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(placeholder_inst)].bin_op;
4100 try sema.storePtr2(&replacement_block, src, bin_op.lhs, src, bin_op.rhs, src, .store);4100 try sema.storePtr2(&replacement_block, src, bin_op.lhs, src, bin_op.rhs, src, .store);
41014101
4102 // If only one instruction is produced then we can replace the store4102 // If only one instruction is produced then we can replace the store
4103 // placeholder instruction with this instruction; no need for an entire block.4103 // placeholder instruction with this instruction; no need for an entire block.
4104 if (replacement_block.instructions.items.len == 1) {4104 if (replacement_block.instructions.items.len == 1) {
4105 const only_inst = replacement_block.instructions.items[0];4105 const only_inst = replacement_block.instructions.items[0];
4106 sema.air_instructions.set(placeholder_inst, sema.air_instructions.get(only_inst));4106 sema.air_instructions.set(@intFromEnum(placeholder_inst), sema.air_instructions.get(@intFromEnum(only_inst)));
4107 continue;4107 continue;
4108 }4108 }
41094109
...@@ -4114,7 +4114,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4114,7 +4114,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4114 gpa,4114 gpa,
4115 @typeInfo(Air.Block).Struct.fields.len + replacement_block.instructions.items.len,4115 @typeInfo(Air.Block).Struct.fields.len + replacement_block.instructions.items.len,
4116 );4116 );
4117 sema.air_instructions.set(placeholder_inst, .{4117 sema.air_instructions.set(@intFromEnum(placeholder_inst), .{
4118 .tag = .block,4118 .tag = .block,
4119 .data = .{ .ty_pl = .{4119 .data = .{ .ty_pl = .{
4120 .ty = .void_type,4120 .ty = .void_type,
...@@ -4123,7 +4123,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4123,7 +4123,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4123 }),4123 }),
4124 } },4124 } },
4125 });4125 });
4126 sema.air_extra.appendSliceAssumeCapacity(replacement_block.instructions.items);4126 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(replacement_block.instructions.items));
4127 }4127 }
4128 },4128 },
4129 else => unreachable,4129 else => unreachable,
...@@ -4584,18 +4584,18 @@ fn validateUnionInit(...@@ -4584,18 +4584,18 @@ fn validateUnionInit(
4584 var init_val: ?Value = null;4584 var init_val: ?Value = null;
4585 while (block_index > 0) : (block_index -= 1) {4585 while (block_index > 0) : (block_index -= 1) {
4586 const store_inst = block.instructions.items[block_index];4586 const store_inst = block.instructions.items[block_index];
4587 if (Air.indexToRef(store_inst) == field_ptr_ref) break;4587 if (store_inst.toRef() == field_ptr_ref) break;
4588 switch (air_tags[store_inst]) {4588 switch (air_tags[@intFromEnum(store_inst)]) {
4589 .store, .store_safe => {},4589 .store, .store_safe => {},
4590 else => continue,4590 else => continue,
4591 }4591 }
4592 const bin_op = air_datas[store_inst].bin_op;4592 const bin_op = air_datas[@intFromEnum(store_inst)].bin_op;
4593 var ptr_ref = bin_op.lhs;4593 var ptr_ref = bin_op.lhs;
4594 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {4594 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
4595 ptr_ref = air_datas[ptr_inst].ty_op.operand;4595 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
4596 };4596 };
4597 if (ptr_ref != field_ptr_ref) continue;4597 if (ptr_ref != field_ptr_ref) continue;
4598 first_block_index = @min(if (Air.refToIndex(field_ptr_ref)) |field_ptr_inst|4598 first_block_index = @min(if (field_ptr_ref.toIndex()) |field_ptr_inst|
4599 std.mem.lastIndexOfScalar(4599 std.mem.lastIndexOfScalar(
4600 Air.Inst.Index,4600 Air.Inst.Index,
4601 block.instructions.items[0..block_index],4601 block.instructions.items[0..block_index],
...@@ -4615,18 +4615,18 @@ fn validateUnionInit(...@@ -4615,18 +4615,18 @@ fn validateUnionInit(
4615 // instead a single `store` to the result ptr with a comptime union value.4615 // instead a single `store` to the result ptr with a comptime union value.
4616 block_index = first_block_index;4616 block_index = first_block_index;
4617 for (block.instructions.items[first_block_index..]) |cur_inst| {4617 for (block.instructions.items[first_block_index..]) |cur_inst| {
4618 switch (air_tags[cur_inst]) {4618 switch (air_tags[@intFromEnum(cur_inst)]) {
4619 .struct_field_ptr,4619 .struct_field_ptr,
4620 .struct_field_ptr_index_0,4620 .struct_field_ptr_index_0,
4621 .struct_field_ptr_index_1,4621 .struct_field_ptr_index_1,
4622 .struct_field_ptr_index_2,4622 .struct_field_ptr_index_2,
4623 .struct_field_ptr_index_3,4623 .struct_field_ptr_index_3,
4624 => if (Air.indexToRef(cur_inst) == field_ptr_ref) continue,4624 => if (cur_inst.toRef() == field_ptr_ref) continue,
4625 .bitcast => if (air_datas[cur_inst].ty_op.operand == field_ptr_ref) continue,4625 .bitcast => if (air_datas[@intFromEnum(cur_inst)].ty_op.operand == field_ptr_ref) continue,
4626 .store, .store_safe => {4626 .store, .store_safe => {
4627 var ptr_ref = air_datas[cur_inst].bin_op.lhs;4627 var ptr_ref = air_datas[@intFromEnum(cur_inst)].bin_op.lhs;
4628 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {4628 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
4629 ptr_ref = air_datas[ptr_inst].ty_op.operand;4629 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
4630 };4630 };
4631 if (ptr_ref == field_ptr_ref) continue;4631 if (ptr_ref == field_ptr_ref) continue;
4632 },4632 },
...@@ -4807,21 +4807,21 @@ fn validateStructInit(...@@ -4807,21 +4807,21 @@ fn validateStructInit(
4807 var block_index = block.instructions.items.len -| 1;4807 var block_index = block.instructions.items.len -| 1;
4808 while (block_index > 0) : (block_index -= 1) {4808 while (block_index > 0) : (block_index -= 1) {
4809 const store_inst = block.instructions.items[block_index];4809 const store_inst = block.instructions.items[block_index];
4810 if (Air.indexToRef(store_inst) == field_ptr_ref) {4810 if (store_inst.toRef() == field_ptr_ref) {
4811 struct_is_comptime = false;4811 struct_is_comptime = false;
4812 continue :field;4812 continue :field;
4813 }4813 }
4814 switch (air_tags[store_inst]) {4814 switch (air_tags[@intFromEnum(store_inst)]) {
4815 .store, .store_safe => {},4815 .store, .store_safe => {},
4816 else => continue,4816 else => continue,
4817 }4817 }
4818 const bin_op = air_datas[store_inst].bin_op;4818 const bin_op = air_datas[@intFromEnum(store_inst)].bin_op;
4819 var ptr_ref = bin_op.lhs;4819 var ptr_ref = bin_op.lhs;
4820 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {4820 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
4821 ptr_ref = air_datas[ptr_inst].ty_op.operand;4821 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
4822 };4822 };
4823 if (ptr_ref != field_ptr_ref) continue;4823 if (ptr_ref != field_ptr_ref) continue;
4824 first_block_index = @min(if (Air.refToIndex(field_ptr_ref)) |field_ptr_inst|4824 first_block_index = @min(if (field_ptr_ref.toIndex()) |field_ptr_inst|
4825 std.mem.lastIndexOfScalar(4825 std.mem.lastIndexOfScalar(
4826 Air.Inst.Index,4826 Air.Inst.Index,
4827 block.instructions.items[0..block_index],4827 block.instructions.items[0..block_index],
...@@ -4895,18 +4895,18 @@ fn validateStructInit(...@@ -4895,18 +4895,18 @@ fn validateStructInit(
4895 if (try field_ty.onePossibleValue(mod)) |_| continue;4895 if (try field_ty.onePossibleValue(mod)) |_| continue;
4896 field_ptr_ref = sema.inst_map.get(instrs[init_index]).?;4896 field_ptr_ref = sema.inst_map.get(instrs[init_index]).?;
4897 }4897 }
4898 switch (air_tags[cur_inst]) {4898 switch (air_tags[@intFromEnum(cur_inst)]) {
4899 .struct_field_ptr,4899 .struct_field_ptr,
4900 .struct_field_ptr_index_0,4900 .struct_field_ptr_index_0,
4901 .struct_field_ptr_index_1,4901 .struct_field_ptr_index_1,
4902 .struct_field_ptr_index_2,4902 .struct_field_ptr_index_2,
4903 .struct_field_ptr_index_3,4903 .struct_field_ptr_index_3,
4904 => if (Air.indexToRef(cur_inst) == field_ptr_ref) continue,4904 => if (cur_inst.toRef() == field_ptr_ref) continue,
4905 .bitcast => if (air_datas[cur_inst].ty_op.operand == field_ptr_ref) continue,4905 .bitcast => if (air_datas[@intFromEnum(cur_inst)].ty_op.operand == field_ptr_ref) continue,
4906 .store, .store_safe => {4906 .store, .store_safe => {
4907 var ptr_ref = air_datas[cur_inst].bin_op.lhs;4907 var ptr_ref = air_datas[@intFromEnum(cur_inst)].bin_op.lhs;
4908 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {4908 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
4909 ptr_ref = air_datas[ptr_inst].ty_op.operand;4909 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
4910 };4910 };
4911 if (ptr_ref == field_ptr_ref) {4911 if (ptr_ref == field_ptr_ref) {
4912 field_ptr_ref = .none;4912 field_ptr_ref = .none;
...@@ -5063,21 +5063,21 @@ fn zirValidatePtrArrayInit(...@@ -5063,21 +5063,21 @@ fn zirValidatePtrArrayInit(
5063 var block_index = block.instructions.items.len -| 1;5063 var block_index = block.instructions.items.len -| 1;
5064 while (block_index > 0) : (block_index -= 1) {5064 while (block_index > 0) : (block_index -= 1) {
5065 const store_inst = block.instructions.items[block_index];5065 const store_inst = block.instructions.items[block_index];
5066 if (Air.indexToRef(store_inst) == elem_ptr_ref) {5066 if (store_inst.toRef() == elem_ptr_ref) {
5067 array_is_comptime = false;5067 array_is_comptime = false;
5068 continue :outer;5068 continue :outer;
5069 }5069 }
5070 switch (air_tags[store_inst]) {5070 switch (air_tags[@intFromEnum(store_inst)]) {
5071 .store, .store_safe => {},5071 .store, .store_safe => {},
5072 else => continue,5072 else => continue,
5073 }5073 }
5074 const bin_op = air_datas[store_inst].bin_op;5074 const bin_op = air_datas[@intFromEnum(store_inst)].bin_op;
5075 var ptr_ref = bin_op.lhs;5075 var ptr_ref = bin_op.lhs;
5076 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {5076 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
5077 ptr_ref = air_datas[ptr_inst].ty_op.operand;5077 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
5078 };5078 };
5079 if (ptr_ref != elem_ptr_ref) continue;5079 if (ptr_ref != elem_ptr_ref) continue;
5080 first_block_index = @min(if (Air.refToIndex(elem_ptr_ref)) |elem_ptr_inst|5080 first_block_index = @min(if (elem_ptr_ref.toIndex()) |elem_ptr_inst|
5081 std.mem.lastIndexOfScalar(5081 std.mem.lastIndexOfScalar(
5082 Air.Inst.Index,5082 Air.Inst.Index,
5083 block.instructions.items[0..block_index],5083 block.instructions.items[0..block_index],
...@@ -5117,13 +5117,13 @@ fn zirValidatePtrArrayInit(...@@ -5117,13 +5117,13 @@ fn zirValidatePtrArrayInit(
5117 if (array_ty.isTuple(mod) and array_ty.structFieldIsComptime(elem_index, mod)) continue;5117 if (array_ty.isTuple(mod) and array_ty.structFieldIsComptime(elem_index, mod)) continue;
5118 elem_ptr_ref = sema.inst_map.get(instrs[elem_index]).?;5118 elem_ptr_ref = sema.inst_map.get(instrs[elem_index]).?;
5119 }5119 }
5120 switch (air_tags[cur_inst]) {5120 switch (air_tags[@intFromEnum(cur_inst)]) {
5121 .ptr_elem_ptr => if (Air.indexToRef(cur_inst) == elem_ptr_ref) continue,5121 .ptr_elem_ptr => if (cur_inst.toRef() == elem_ptr_ref) continue,
5122 .bitcast => if (air_datas[cur_inst].ty_op.operand == elem_ptr_ref) continue,5122 .bitcast => if (air_datas[@intFromEnum(cur_inst)].ty_op.operand == elem_ptr_ref) continue,
5123 .store, .store_safe => {5123 .store, .store_safe => {
5124 var ptr_ref = air_datas[cur_inst].bin_op.lhs;5124 var ptr_ref = air_datas[@intFromEnum(cur_inst)].bin_op.lhs;
5125 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {5125 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
5126 ptr_ref = air_datas[ptr_inst].ty_op.operand;5126 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
5127 };5127 };
5128 if (ptr_ref == elem_ptr_ref) {5128 if (ptr_ref == elem_ptr_ref) {
5129 elem_ptr_ref = .none;5129 elem_ptr_ref = .none;
...@@ -5336,12 +5336,12 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi...@@ -5336,12 +5336,12 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
5336 const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;5336 const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
5337 const ptr = try sema.resolveInst(bin_inst.lhs);5337 const ptr = try sema.resolveInst(bin_inst.lhs);
5338 const operand = try sema.resolveInst(bin_inst.rhs);5338 const operand = try sema.resolveInst(bin_inst.rhs);
5339 const ptr_inst = Air.refToIndex(ptr).?;5339 const ptr_inst = ptr.toIndex().?;
5340 const air_datas = sema.air_instructions.items(.data);5340 const air_datas = sema.air_instructions.items(.data);
53415341
5342 switch (sema.air_instructions.items(.tag)[ptr_inst]) {5342 switch (sema.air_instructions.items(.tag)[@intFromEnum(ptr_inst)]) {
5343 .inferred_alloc_comptime => {5343 .inferred_alloc_comptime => {
5344 const iac = &air_datas[ptr_inst].inferred_alloc_comptime;5344 const iac = &air_datas[@intFromEnum(ptr_inst)].inferred_alloc_comptime;
5345 return sema.storeToInferredAllocComptime(block, src, operand, iac);5345 return sema.storeToInferredAllocComptime(block, src, operand, iac);
5346 },5346 },
5347 .inferred_alloc => {5347 .inferred_alloc => {
...@@ -5365,7 +5365,7 @@ fn storeToInferredAlloc(...@@ -5365,7 +5365,7 @@ fn storeToInferredAlloc(
5365 try sema.checkComptimeKnownStore(block, dummy_store);5365 try sema.checkComptimeKnownStore(block, dummy_store);
5366 // Add the stored instruction to the set we will use to resolve peer types5366 // Add the stored instruction to the set we will use to resolve peer types
5367 // for the inferred allocation.5367 // for the inferred allocation.
5368 try inferred_alloc.prongs.append(sema.arena, Air.refToIndex(dummy_store).?);5368 try inferred_alloc.prongs.append(sema.arena, dummy_store.toIndex().?);
5369}5369}
53705370
5371fn storeToInferredAllocComptime(5371fn storeToInferredAllocComptime(
...@@ -5635,8 +5635,8 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5635,8 +5635,8 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
5635 // Reserve space for a Loop instruction so that generated Break instructions can5635 // Reserve space for a Loop instruction so that generated Break instructions can
5636 // point to it, even if it doesn't end up getting used because the code ends up being5636 // point to it, even if it doesn't end up getting used because the code ends up being
5637 // comptime evaluated.5637 // comptime evaluated.
5638 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);5638 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
5639 const loop_inst = block_inst + 1;5639 const loop_inst: Air.Inst.Index = @enumFromInt(@intFromEnum(block_inst) + 1);
5640 try sema.air_instructions.ensureUnusedCapacity(gpa, 2);5640 try sema.air_instructions.ensureUnusedCapacity(gpa, 2);
5641 sema.air_instructions.appendAssumeCapacity(.{5641 sema.air_instructions.appendAssumeCapacity(.{
5642 .tag = .block,5642 .tag = .block,
...@@ -5674,7 +5674,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5674,7 +5674,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
5674 try sema.analyzeBody(&loop_block, body);5674 try sema.analyzeBody(&loop_block, body);
56755675
5676 const loop_block_len = loop_block.instructions.items.len;5676 const loop_block_len = loop_block.instructions.items.len;
5677 if (loop_block_len > 0 and sema.typeOf(Air.indexToRef(loop_block.instructions.items[loop_block_len - 1])).isNoReturn(mod)) {5677 if (loop_block_len > 0 and sema.typeOf(loop_block.instructions.items[loop_block_len - 1].toRef()).isNoReturn(mod)) {
5678 // If the loop ended with a noreturn terminator, then there is no way for it to loop,5678 // If the loop ended with a noreturn terminator, then there is no way for it to loop,
5679 // so we can just use the block instead.5679 // so we can just use the block instead.
5680 try child_block.instructions.appendSlice(gpa, loop_block.instructions.items);5680 try child_block.instructions.appendSlice(gpa, loop_block.instructions.items);
...@@ -5682,10 +5682,10 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5682,10 +5682,10 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
5682 try child_block.instructions.append(gpa, loop_inst);5682 try child_block.instructions.append(gpa, loop_inst);
56835683
5684 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + loop_block_len);5684 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + loop_block_len);
5685 sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity(5685 sema.air_instructions.items(.data)[@intFromEnum(loop_inst)].ty_pl.payload = sema.addExtraAssumeCapacity(
5686 Air.Block{ .body_len = @intCast(loop_block_len) },5686 Air.Block{ .body_len = @intCast(loop_block_len) },
5687 );5687 );
5688 sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items);5688 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(loop_block.instructions.items));
5689 }5689 }
5690 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);5690 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);
5691}5691}
...@@ -5793,7 +5793,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt...@@ -5793,7 +5793,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
5793 // Reserve space for a Block instruction so that generated Break instructions can5793 // Reserve space for a Block instruction so that generated Break instructions can
5794 // point to it, even if it doesn't end up getting used because the code ends up being5794 // point to it, even if it doesn't end up getting used because the code ends up being
5795 // comptime evaluated or is an unlabeled block.5795 // comptime evaluated or is an unlabeled block.
5796 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);5796 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
5797 try sema.air_instructions.append(gpa, .{5797 try sema.air_instructions.append(gpa, .{
5798 .tag = .block,5798 .tag = .block,
5799 .data = undefined,5799 .data = undefined,
...@@ -5887,13 +5887,13 @@ fn analyzeBlockBody(...@@ -5887,13 +5887,13 @@ fn analyzeBlockBody(
58875887
5888 // Blocks must terminate with noreturn instruction.5888 // Blocks must terminate with noreturn instruction.
5889 assert(child_block.instructions.items.len != 0);5889 assert(child_block.instructions.items.len != 0);
5890 assert(sema.typeOf(Air.indexToRef(child_block.instructions.items[child_block.instructions.items.len - 1])).isNoReturn(mod));5890 assert(sema.typeOf(child_block.instructions.items[child_block.instructions.items.len - 1].toRef()).isNoReturn(mod));
58915891
5892 if (merges.results.items.len == 0) {5892 if (merges.results.items.len == 0) {
5893 // No need for a block instruction. We can put the new instructions5893 // No need for a block instruction. We can put the new instructions
5894 // directly into the parent block.5894 // directly into the parent block.
5895 try parent_block.instructions.appendSlice(gpa, child_block.instructions.items);5895 try parent_block.instructions.appendSlice(gpa, child_block.instructions.items);
5896 return Air.indexToRef(child_block.instructions.items[child_block.instructions.items.len - 1]);5896 return child_block.instructions.items[child_block.instructions.items.len - 1].toRef();
5897 }5897 }
5898 if (merges.results.items.len == 1) {5898 if (merges.results.items.len == 1) {
5899 const last_inst_index = child_block.instructions.items.len - 1;5899 const last_inst_index = child_block.instructions.items.len - 1;
...@@ -5936,17 +5936,17 @@ fn analyzeBlockBody(...@@ -5936,17 +5936,17 @@ fn analyzeBlockBody(
5936 const ty_inst = Air.internedToRef(resolved_ty.toIntern());5936 const ty_inst = Air.internedToRef(resolved_ty.toIntern());
5937 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +5937 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
5938 child_block.instructions.items.len);5938 child_block.instructions.items.len);
5939 sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{5939 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
5940 .ty = ty_inst,5940 .ty = ty_inst,
5941 .payload = sema.addExtraAssumeCapacity(Air.Block{5941 .payload = sema.addExtraAssumeCapacity(Air.Block{
5942 .body_len = @intCast(child_block.instructions.items.len),5942 .body_len = @intCast(child_block.instructions.items.len),
5943 }),5943 }),
5944 } };5944 } };
5945 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);5945 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(child_block.instructions.items));
5946 // Now that the block has its type resolved, we need to go back into all the break5946 // Now that the block has its type resolved, we need to go back into all the break
5947 // instructions, and insert type coercion on the operands.5947 // instructions, and insert type coercion on the operands.
5948 for (merges.br_list.items) |br| {5948 for (merges.br_list.items) |br| {
5949 const br_operand = sema.air_instructions.items(.data)[br].br.operand;5949 const br_operand = sema.air_instructions.items(.data)[@intFromEnum(br)].br.operand;
5950 const br_operand_src = src;5950 const br_operand_src = src;
5951 const br_operand_ty = sema.typeOf(br_operand);5951 const br_operand_ty = sema.typeOf(br_operand);
5952 if (br_operand_ty.eql(resolved_ty, mod)) {5952 if (br_operand_ty.eql(resolved_ty, mod)) {
...@@ -5959,10 +5959,10 @@ fn analyzeBlockBody(...@@ -5959,10 +5959,10 @@ fn analyzeBlockBody(
5959 // If no instructions were produced, such as in the case of a coercion of a5959 // If no instructions were produced, such as in the case of a coercion of a
5960 // constant value to a new type, we can simply point the br operand to it.5960 // constant value to a new type, we can simply point the br operand to it.
5961 if (coerce_block.instructions.items.len == 0) {5961 if (coerce_block.instructions.items.len == 0) {
5962 sema.air_instructions.items(.data)[br].br.operand = coerced_operand;5962 sema.air_instructions.items(.data)[@intFromEnum(br)].br.operand = coerced_operand;
5963 continue;5963 continue;
5964 }5964 }
5965 assert(Air.indexToRef(coerce_block.instructions.items[coerce_block.instructions.items.len - 1]) == coerced_operand);5965 assert(coerce_block.instructions.items[coerce_block.instructions.items.len - 1].toRef() == coerced_operand);
59665966
5967 // Convert the br instruction to a block instruction that has the coercion5967 // Convert the br instruction to a block instruction that has the coercion
5968 // and then a new br inside that returns the coerced instruction.5968 // and then a new br inside that returns the coerced instruction.
...@@ -5970,17 +5970,17 @@ fn analyzeBlockBody(...@@ -5970,17 +5970,17 @@ fn analyzeBlockBody(
5970 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +5970 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
5971 sub_block_len);5971 sub_block_len);
5972 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);5972 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
5973 const sub_br_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);5973 const sub_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
59745974
5975 sema.air_instructions.items(.tag)[br] = .block;5975 sema.air_instructions.items(.tag)[@intFromEnum(br)] = .block;
5976 sema.air_instructions.items(.data)[br] = .{ .ty_pl = .{5976 sema.air_instructions.items(.data)[@intFromEnum(br)] = .{ .ty_pl = .{
5977 .ty = .noreturn_type,5977 .ty = .noreturn_type,
5978 .payload = sema.addExtraAssumeCapacity(Air.Block{5978 .payload = sema.addExtraAssumeCapacity(Air.Block{
5979 .body_len = sub_block_len,5979 .body_len = sub_block_len,
5980 }),5980 }),
5981 } };5981 } };
5982 sema.air_extra.appendSliceAssumeCapacity(coerce_block.instructions.items);5982 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(coerce_block.instructions.items));
5983 sema.air_extra.appendAssumeCapacity(sub_br_inst);5983 sema.air_extra.appendAssumeCapacity(@intFromEnum(sub_br_inst));
59845984
5985 sema.air_instructions.appendAssumeCapacity(.{5985 sema.air_instructions.appendAssumeCapacity(.{
5986 .tag = .br,5986 .tag = .br,
...@@ -5990,7 +5990,7 @@ fn analyzeBlockBody(...@@ -5990,7 +5990,7 @@ fn analyzeBlockBody(
5990 } },5990 } },
5991 });5991 });
5992 }5992 }
5993 return Air.indexToRef(merges.block_inst);5993 return merges.block_inst.toRef();
5994}5994}
59955995
5996fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5996fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
...@@ -6249,7 +6249,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6249,7 +6249,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
6249 null;6249 null;
6250 try label.merges.src_locs.append(sema.gpa, src_loc);6250 try label.merges.src_locs.append(sema.gpa, src_loc);
6251 try label.merges.results.append(sema.gpa, operand);6251 try label.merges.results.append(sema.gpa, operand);
6252 try label.merges.br_list.append(sema.gpa, Air.refToIndex(br_ref).?);6252 try label.merges.br_list.append(sema.gpa, br_ref.toIndex().?);
6253 block.runtime_index.increment();6253 block.runtime_index.increment();
6254 if (block.runtime_cond == null and block.runtime_loop == null) {6254 if (block.runtime_cond == null and block.runtime_loop == null) {
6255 block.runtime_cond = start_block.runtime_cond orelse start_block.runtime_loop;6255 block.runtime_cond = start_block.runtime_cond orelse start_block.runtime_loop;
...@@ -6273,9 +6273,9 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi...@@ -6273,9 +6273,9 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
62736273
6274 if (block.instructions.items.len != 0) {6274 if (block.instructions.items.len != 0) {
6275 const idx = block.instructions.items[block.instructions.items.len - 1];6275 const idx = block.instructions.items[block.instructions.items.len - 1];
6276 if (sema.air_instructions.items(.tag)[idx] == .dbg_stmt) {6276 if (sema.air_instructions.items(.tag)[@intFromEnum(idx)] == .dbg_stmt) {
6277 // The previous dbg_stmt didn't correspond to any actual code, so replace it.6277 // The previous dbg_stmt didn't correspond to any actual code, so replace it.
6278 sema.air_instructions.items(.data)[idx].dbg_stmt = .{6278 sema.air_instructions.items(.data)[@intFromEnum(idx)].dbg_stmt = .{
6279 .line = inst_data.line,6279 .line = inst_data.line,
6280 .column = inst_data.column,6280 .column = inst_data.column,
6281 };6281 };
...@@ -6609,7 +6609,7 @@ fn popErrorReturnTrace(...@@ -6609,7 +6609,7 @@ fn popErrorReturnTrace(
6609 then_block.instructions.items.len + else_block.instructions.items.len +6609 then_block.instructions.items.len + else_block.instructions.items.len +
6610 @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block6610 @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block
66116611
6612 const cond_br_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);6612 const cond_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
6613 try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{6613 try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{
6614 .operand = is_non_error_inst,6614 .operand = is_non_error_inst,
6615 .payload = sema.addExtraAssumeCapacity(Air.CondBr{6615 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
...@@ -6617,11 +6617,11 @@ fn popErrorReturnTrace(...@@ -6617,11 +6617,11 @@ fn popErrorReturnTrace(
6617 .else_body_len = @intCast(else_block.instructions.items.len),6617 .else_body_len = @intCast(else_block.instructions.items.len),
6618 }),6618 }),
6619 } } });6619 } } });
6620 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);6620 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(then_block.instructions.items));
6621 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);6621 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(else_block.instructions.items));
66226622
6623 sema.air_instructions.items(.data)[cond_block_inst].ty_pl.payload = sema.addExtraAssumeCapacity(Air.Block{ .body_len = 1 });6623 sema.air_instructions.items(.data)[@intFromEnum(cond_block_inst)].ty_pl.payload = sema.addExtraAssumeCapacity(Air.Block{ .body_len = 1 });
6624 sema.air_extra.appendAssumeCapacity(cond_br_inst);6624 sema.air_extra.appendAssumeCapacity(@intFromEnum(cond_br_inst));
6625 }6625 }
6626}6626}
66276627
...@@ -6668,7 +6668,7 @@ fn zirCall(...@@ -6668,7 +6668,7 @@ fn zirCall(
6668 const func_ty = try sema.checkCallArgumentCount(block, func, callee_src, callee_ty, total_args, callee == .method);6668 const func_ty = try sema.checkCallArgumentCount(block, func, callee_src, callee_ty, total_args, callee == .method);
66696669
6670 // The block index before the call, so we can potentially insert an error trace save here later.6670 // The block index before the call, so we can potentially insert an error trace save here later.
6671 const block_index: Air.Inst.Index = @intCast(block.instructions.items.len);6671 const block_index: Air.Inst.Index = @enumFromInt(block.instructions.items.len);
66726672
6673 // This will be set by `analyzeCall` to indicate whether any parameter was an error (making the6673 // This will be set by `analyzeCall` to indicate whether any parameter was an error (making the
6674 // error trace potentially dirty).6674 // error trace potentially dirty).
...@@ -7283,7 +7283,7 @@ fn analyzeCall(...@@ -7283,7 +7283,7 @@ fn analyzeCall(
7283 // set to in the `Block`.7283 // set to in the `Block`.
7284 // This block instruction will be used to capture the return value from the7284 // This block instruction will be used to capture the return value from the
7285 // inlined function.7285 // inlined function.
7286 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);7286 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
7287 try sema.air_instructions.append(gpa, .{7287 try sema.air_instructions.append(gpa, .{
7288 .tag = .block,7288 .tag = .block,
7289 .data = undefined,7289 .data = undefined,
...@@ -9737,12 +9737,12 @@ fn zirParam(...@@ -9737,12 +9737,12 @@ fn zirParam(
9737 sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison);9737 sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison);
9738 } else {9738 } else {
9739 // Otherwise we need a dummy runtime instruction.9739 // Otherwise we need a dummy runtime instruction.
9740 const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len);9740 const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
9741 try sema.air_instructions.append(sema.gpa, .{9741 try sema.air_instructions.append(sema.gpa, .{
9742 .tag = .alloc,9742 .tag = .alloc,
9743 .data = .{ .ty = param_ty },9743 .data = .{ .ty = param_ty },
9744 });9744 });
9745 sema.inst_map.putAssumeCapacityNoClobber(inst, Air.indexToRef(result_index));9745 sema.inst_map.putAssumeCapacityNoClobber(inst, result_index.toRef());
9746 }9746 }
9747}9747}
97489748
...@@ -10991,7 +10991,7 @@ const SwitchProngAnalysis = struct {...@@ -10991,7 +10991,7 @@ const SwitchProngAnalysis = struct {
10991 cases_extra.appendAssumeCapacity(1); // items_len10991 cases_extra.appendAssumeCapacity(1); // items_len
10992 cases_extra.appendAssumeCapacity(@intCast(coerce_block.instructions.items.len)); // body_len10992 cases_extra.appendAssumeCapacity(@intCast(coerce_block.instructions.items.len)); // body_len
10993 cases_extra.appendAssumeCapacity(@intFromEnum(case_vals[idx])); // item10993 cases_extra.appendAssumeCapacity(@intFromEnum(case_vals[idx])); // item
10994 cases_extra.appendSliceAssumeCapacity(coerce_block.instructions.items); // body10994 cases_extra.appendSliceAssumeCapacity(@ptrCast(coerce_block.instructions.items)); // body
10995 }10995 }
10996 }10996 }
10997 const else_body_len = len: {10997 const else_body_len = len: {
...@@ -11006,7 +11006,7 @@ const SwitchProngAnalysis = struct {...@@ -11006,7 +11006,7 @@ const SwitchProngAnalysis = struct {
11006 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);11006 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);
11007 _ = try coerce_block.addBr(capture_block_inst, coerced);11007 _ = try coerce_block.addBr(capture_block_inst, coerced);
1100811008
11009 try cases_extra.appendSlice(coerce_block.instructions.items);11009 try cases_extra.appendSlice(@ptrCast(coerce_block.instructions.items));
11010 break :len coerce_block.instructions.items.len;11010 break :len coerce_block.instructions.items.len;
11011 };11011 };
1101211012
...@@ -11029,12 +11029,12 @@ const SwitchProngAnalysis = struct {...@@ -11029,12 +11029,12 @@ const SwitchProngAnalysis = struct {
11029 sema.air_extra.appendSliceAssumeCapacity(cases_extra.items);11029 sema.air_extra.appendSliceAssumeCapacity(cases_extra.items);
1103011030
11031 // Set up block body11031 // Set up block body
11032 sema.air_instructions.items(.data)[capture_block_inst].ty_pl.payload = sema.addExtraAssumeCapacity(Air.Block{11032 sema.air_instructions.items(.data)[@intFromEnum(capture_block_inst)].ty_pl.payload = sema.addExtraAssumeCapacity(Air.Block{
11033 .body_len = 1,11033 .body_len = 1,
11034 });11034 });
11035 sema.air_extra.appendAssumeCapacity(switch_br_inst);11035 sema.air_extra.appendAssumeCapacity(switch_br_inst);
1103611036
11037 return Air.indexToRef(capture_block_inst);11037 return capture_block_inst.toRef();
11038 },11038 },
11039 .ErrorSet => {11039 .ErrorSet => {
11040 if (capture_byref) {11040 if (capture_byref) {
...@@ -11780,7 +11780,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11780,7 +11780,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11780 .tag_capture_inst = tag_capture_inst,11780 .tag_capture_inst = tag_capture_inst,
11781 };11781 };
1178211782
11783 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);11783 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
11784 try sema.air_instructions.append(gpa, .{11784 try sema.air_instructions.append(gpa, .{
11785 .tag = .block,11785 .tag = .block,
11786 .data = undefined,11786 .data = undefined,
...@@ -12023,7 +12023,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12023,7 +12023,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12023 cases_extra.appendAssumeCapacity(1); // items_len12023 cases_extra.appendAssumeCapacity(1); // items_len
12024 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));12024 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
12025 cases_extra.appendAssumeCapacity(@intFromEnum(item));12025 cases_extra.appendAssumeCapacity(@intFromEnum(item));
12026 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12026 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12027 }12027 }
1202812028
12029 var is_first = true;12029 var is_first = true;
...@@ -12110,7 +12110,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12110,7 +12110,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12110 cases_extra.appendAssumeCapacity(1); // items_len12110 cases_extra.appendAssumeCapacity(1); // items_len
12111 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));12111 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
12112 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));12112 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
12113 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12113 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1211412114
12115 if (item.compareScalar(.eq, item_last, operand_ty, mod)) break;12115 if (item.compareScalar(.eq, item_last, operand_ty, mod)) break;
12116 }12116 }
...@@ -12160,7 +12160,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12160,7 +12160,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12160 cases_extra.appendAssumeCapacity(1); // items_len12160 cases_extra.appendAssumeCapacity(1); // items_len
12161 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));12161 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
12162 cases_extra.appendAssumeCapacity(@intFromEnum(item));12162 cases_extra.appendAssumeCapacity(@intFromEnum(item));
12163 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12163 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12164 }12164 }
1216512165
12166 extra_index += info.body_len;12166 extra_index += info.body_len;
...@@ -12213,7 +12213,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12213,7 +12213,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12213 cases_extra.appendAssumeCapacity(@intFromEnum(item));12213 cases_extra.appendAssumeCapacity(@intFromEnum(item));
12214 }12214 }
1221512215
12216 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12216 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12217 } else {12217 } else {
12218 for (items) |item| {12218 for (items) |item| {
12219 const cmp_ok = try case_block.addBinOp(if (case_block.float_mode == .Optimized) .cmp_eq_optimized else .cmp_eq, operand, item);12219 const cmp_ok = try case_block.addBinOp(if (case_block.float_mode == .Optimized) .cmp_eq_optimized else .cmp_eq, operand, item);
...@@ -12295,13 +12295,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12295,13 +12295,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12295 @typeInfo(Air.CondBr).Struct.fields.len + prev_then_body.len + cond_body.len,12295 @typeInfo(Air.CondBr).Struct.fields.len + prev_then_body.len + cond_body.len,
12296 );12296 );
1229712297
12298 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =12298 sema.air_instructions.items(.data)[@intFromEnum(prev_cond_br)].pl_op.payload =
12299 sema.addExtraAssumeCapacity(Air.CondBr{12299 sema.addExtraAssumeCapacity(Air.CondBr{
12300 .then_body_len = @intCast(prev_then_body.len),12300 .then_body_len = @intCast(prev_then_body.len),
12301 .else_body_len = @intCast(cond_body.len),12301 .else_body_len = @intCast(cond_body.len),
12302 });12302 });
12303 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);12303 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(prev_then_body));
12304 sema.air_extra.appendSliceAssumeCapacity(cond_body);12304 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(cond_body));
12305 }12305 }
12306 gpa.free(prev_then_body);12306 gpa.free(prev_then_body);
12307 prev_then_body = try case_block.instructions.toOwnedSlice(gpa);12307 prev_then_body = try case_block.instructions.toOwnedSlice(gpa);
...@@ -12356,7 +12356,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12356,7 +12356,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12356 cases_extra.appendAssumeCapacity(1); // items_len12356 cases_extra.appendAssumeCapacity(1); // items_len
12357 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));12357 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
12358 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));12358 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
12359 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12359 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12360 }12360 }
12361 },12361 },
12362 .ErrorSet => {12362 .ErrorSet => {
...@@ -12397,7 +12397,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12397,7 +12397,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12397 cases_extra.appendAssumeCapacity(1); // items_len12397 cases_extra.appendAssumeCapacity(1); // items_len
12398 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));12398 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
12399 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));12399 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
12400 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12400 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12401 }12401 }
12402 },12402 },
12403 .Int => {12403 .Int => {
...@@ -12428,7 +12428,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12428,7 +12428,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12428 cases_extra.appendAssumeCapacity(1); // items_len12428 cases_extra.appendAssumeCapacity(1); // items_len
12429 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));12429 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
12430 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));12430 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
12431 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12431 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12432 }12432 }
12433 },12433 },
12434 .Bool => {12434 .Bool => {
...@@ -12456,7 +12456,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12456,7 +12456,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12456 cases_extra.appendAssumeCapacity(1); // items_len12456 cases_extra.appendAssumeCapacity(1); // items_len
12457 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));12457 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
12458 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_true));12458 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_true));
12459 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12459 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12460 }12460 }
12461 if (false_count == 0) {12461 if (false_count == 0) {
12462 cases_len += 1;12462 cases_len += 1;
...@@ -12482,7 +12482,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12482,7 +12482,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12482 cases_extra.appendAssumeCapacity(1); // items_len12482 cases_extra.appendAssumeCapacity(1); // items_len
12483 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));12483 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
12484 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_false));12484 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_false));
12485 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);12485 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12486 }12486 }
12487 },12487 },
12488 else => return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{12488 else => return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{
...@@ -12544,13 +12544,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12544,13 +12544,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12544 try sema.air_extra.ensureUnusedCapacity(gpa, prev_then_body.len +12544 try sema.air_extra.ensureUnusedCapacity(gpa, prev_then_body.len +
12545 @typeInfo(Air.CondBr).Struct.fields.len + case_block.instructions.items.len);12545 @typeInfo(Air.CondBr).Struct.fields.len + case_block.instructions.items.len);
1254612546
12547 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =12547 sema.air_instructions.items(.data)[@intFromEnum(prev_cond_br)].pl_op.payload =
12548 sema.addExtraAssumeCapacity(Air.CondBr{12548 sema.addExtraAssumeCapacity(Air.CondBr{
12549 .then_body_len = @intCast(prev_then_body.len),12549 .then_body_len = @intCast(prev_then_body.len),
12550 .else_body_len = @intCast(case_block.instructions.items.len),12550 .else_body_len = @intCast(case_block.instructions.items.len),
12551 });12551 });
12552 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);12552 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(prev_then_body));
12553 sema.air_extra.appendSliceAssumeCapacity(case_block.instructions.items);12553 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12554 final_else_body = first_else_body;12554 final_else_body = first_else_body;
12555 }12555 }
12556 }12556 }
...@@ -12565,8 +12565,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12565,8 +12565,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12565 .else_body_len = @intCast(final_else_body.len),12565 .else_body_len = @intCast(final_else_body.len),
12566 }),12566 }),
12567 } } });12567 } } });
12568 sema.air_extra.appendSliceAssumeCapacity(cases_extra.items);12568 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(cases_extra.items));
12569 sema.air_extra.appendSliceAssumeCapacity(final_else_body);12569 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(final_else_body));
1257012570
12571 return sema.analyzeBlockBody(block, src, &child_block, merges);12571 return sema.analyzeBlockBody(block, src, &child_block, merges);
12572}12572}
...@@ -18140,7 +18140,7 @@ fn zirBoolBr(...@@ -18140,7 +18140,7 @@ fn zirBoolBr(
18140 return sema.resolveBody(parent_block, body, inst);18140 return sema.resolveBody(parent_block, body, inst);
18141 }18141 }
1814218142
18143 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);18143 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
18144 try sema.air_instructions.append(gpa, .{18144 try sema.air_instructions.append(gpa, .{
18145 .tag = .block,18145 .tag = .block,
18146 .data = .{ .ty_pl = .{18146 .data = .{ .ty_pl = .{
...@@ -18205,21 +18205,21 @@ fn finishCondBr(...@@ -18205,21 +18205,21 @@ fn finishCondBr(
18205 .then_body_len = @intCast(then_block.instructions.items.len),18205 .then_body_len = @intCast(then_block.instructions.items.len),
18206 .else_body_len = @intCast(else_block.instructions.items.len),18206 .else_body_len = @intCast(else_block.instructions.items.len),
18207 });18207 });
18208 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);18208 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(then_block.instructions.items));
18209 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);18209 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(else_block.instructions.items));
1821018210
18211 _ = try child_block.addInst(.{ .tag = .cond_br, .data = .{ .pl_op = .{18211 _ = try child_block.addInst(.{ .tag = .cond_br, .data = .{ .pl_op = .{
18212 .operand = cond,18212 .operand = cond,
18213 .payload = cond_br_payload,18213 .payload = cond_br_payload,
18214 } } });18214 } } });
1821518215
18216 sema.air_instructions.items(.data)[block_inst].ty_pl.payload = sema.addExtraAssumeCapacity(18216 sema.air_instructions.items(.data)[@intFromEnum(block_inst)].ty_pl.payload = sema.addExtraAssumeCapacity(
18217 Air.Block{ .body_len = @intCast(child_block.instructions.items.len) },18217 Air.Block{ .body_len = @intCast(child_block.instructions.items.len) },
18218 );18218 );
18219 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);18219 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(child_block.instructions.items));
1822018220
18221 try parent_block.instructions.append(gpa, block_inst);18221 try parent_block.instructions.append(gpa, block_inst);
18222 return Air.indexToRef(block_inst);18222 return block_inst.toRef();
18223}18223}
1822418224
18225fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {18225fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
...@@ -18382,8 +18382,8 @@ fn zirCondbr(...@@ -18382,8 +18382,8 @@ fn zirCondbr(
18382 }),18382 }),
18383 } },18383 } },
18384 });18384 });
18385 sema.air_extra.appendSliceAssumeCapacity(true_instructions);18385 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(true_instructions));
18386 sema.air_extra.appendSliceAssumeCapacity(sub_block.instructions.items);18386 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(sub_block.instructions.items));
18387 return always_noreturn;18387 return always_noreturn;
18388}18388}
1838918389
...@@ -18429,7 +18429,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -18429,7 +18429,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
18429 }),18429 }),
18430 } },18430 } },
18431 });18431 });
18432 sema.air_extra.appendSliceAssumeCapacity(sub_block.instructions.items);18432 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(sub_block.instructions.items));
18433 return try_inst;18433 return try_inst;
18434}18434}
1843518435
...@@ -18489,7 +18489,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -18489,7 +18489,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
18489 }),18489 }),
18490 } },18490 } },
18491 });18491 });
18492 sema.air_extra.appendSliceAssumeCapacity(sub_block.instructions.items);18492 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(sub_block.instructions.items));
18493 return try_inst;18493 return try_inst;
18494}18494}
1849518495
...@@ -18501,8 +18501,8 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi...@@ -18501,8 +18501,8 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
18501 const labeled_block = if (!gop.found_existing) blk: {18501 const labeled_block = if (!gop.found_existing) blk: {
18502 try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1);18502 try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1);
1850318503
18504 const new_block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);18504 const new_block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
18505 gop.value_ptr.* = Air.indexToRef(new_block_inst);18505 gop.value_ptr.* = new_block_inst.toRef();
18506 try sema.air_instructions.append(sema.gpa, .{18506 try sema.air_instructions.append(sema.gpa, .{
18507 .tag = .block,18507 .tag = .block,
18508 .data = undefined,18508 .data = undefined,
...@@ -18533,7 +18533,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi...@@ -18533,7 +18533,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
18533 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);18533 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);
18534 break :blk labeled_block;18534 break :blk labeled_block;
18535 } else blk: {18535 } else blk: {
18536 const new_block_inst = Air.refToIndex(gop.value_ptr.*).?;18536 const new_block_inst = gop.value_ptr.*.toIndex().?;
18537 const labeled_block = sema.post_hoc_blocks.get(new_block_inst).?;18537 const labeled_block = sema.post_hoc_blocks.get(new_block_inst).?;
18538 break :blk labeled_block;18538 break :blk labeled_block;
18539 };18539 };
...@@ -18541,7 +18541,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi...@@ -18541,7 +18541,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
18541 const operand = try sema.resolveInst(break_data.operand);18541 const operand = try sema.resolveInst(break_data.operand);
18542 const br_ref = try child_block.addBr(labeled_block.label.merges.block_inst, operand);18542 const br_ref = try child_block.addBr(labeled_block.label.merges.block_inst, operand);
18543 try labeled_block.label.merges.results.append(sema.gpa, operand);18543 try labeled_block.label.merges.results.append(sema.gpa, operand);
18544 try labeled_block.label.merges.br_list.append(sema.gpa, Air.refToIndex(br_ref).?);18544 try labeled_block.label.merges.br_list.append(sema.gpa, br_ref.toIndex().?);
18545 labeled_block.block.runtime_index.increment();18545 labeled_block.block.runtime_index.increment();
18546 if (labeled_block.block.runtime_cond == null and labeled_block.block.runtime_loop == null) {18546 if (labeled_block.block.runtime_cond == null and labeled_block.block.runtime_loop == null) {
18547 labeled_block.block.runtime_cond = child_block.runtime_cond orelse child_block.runtime_loop;18547 labeled_block.block.runtime_cond = child_block.runtime_cond orelse child_block.runtime_loop;
...@@ -18719,8 +18719,8 @@ fn retWithErrTracing(...@@ -18719,8 +18719,8 @@ fn retWithErrTracing(
18719 .then_body_len = @intCast(then_block.instructions.items.len),18719 .then_body_len = @intCast(then_block.instructions.items.len),
18720 .else_body_len = @intCast(else_block.instructions.items.len),18720 .else_body_len = @intCast(else_block.instructions.items.len),
18721 });18721 });
18722 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);18722 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(then_block.instructions.items));
18723 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);18723 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(else_block.instructions.items));
1872418724
18725 _ = try block.addInst(.{ .tag = .cond_br, .data = .{ .pl_op = .{18725 _ = try block.addInst(.{ .tag = .cond_br, .data = .{ .pl_op = .{
18726 .operand = is_non_err,18726 .operand = is_non_err,
...@@ -25856,9 +25856,9 @@ fn addSafetyCheckExtra(...@@ -25856,9 +25856,9 @@ fn addSafetyCheckExtra(
25856 fail_block.instructions.items.len);25856 fail_block.instructions.items.len);
2585725857
25858 try sema.air_instructions.ensureUnusedCapacity(gpa, 3);25858 try sema.air_instructions.ensureUnusedCapacity(gpa, 3);
25859 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);25859 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
25860 const cond_br_inst = block_inst + 1;25860 const cond_br_inst: Air.Inst.Index = @enumFromInt(@intFromEnum(block_inst) + 1);
25861 const br_inst = cond_br_inst + 1;25861 const br_inst: Air.Inst.Index = @enumFromInt(@intFromEnum(cond_br_inst) + 1);
25862 sema.air_instructions.appendAssumeCapacity(.{25862 sema.air_instructions.appendAssumeCapacity(.{
25863 .tag = .block,25863 .tag = .block,
25864 .data = .{ .ty_pl = .{25864 .data = .{ .ty_pl = .{
...@@ -25868,7 +25868,7 @@ fn addSafetyCheckExtra(...@@ -25868,7 +25868,7 @@ fn addSafetyCheckExtra(
25868 }),25868 }),
25869 } },25869 } },
25870 });25870 });
25871 sema.air_extra.appendAssumeCapacity(cond_br_inst);25871 sema.air_extra.appendAssumeCapacity(@intFromEnum(cond_br_inst));
2587225872
25873 sema.air_instructions.appendAssumeCapacity(.{25873 sema.air_instructions.appendAssumeCapacity(.{
25874 .tag = .cond_br,25874 .tag = .cond_br,
...@@ -25880,8 +25880,8 @@ fn addSafetyCheckExtra(...@@ -25880,8 +25880,8 @@ fn addSafetyCheckExtra(
25880 }),25880 }),
25881 } },25881 } },
25882 });25882 });
25883 sema.air_extra.appendAssumeCapacity(br_inst);25883 sema.air_extra.appendAssumeCapacity(@intFromEnum(br_inst));
25884 sema.air_extra.appendSliceAssumeCapacity(fail_block.instructions.items);25884 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(fail_block.instructions.items));
2588525885
25886 sema.air_instructions.appendAssumeCapacity(.{25886 sema.air_instructions.appendAssumeCapacity(.{
25887 .tag = .br,25887 .tag = .br,
...@@ -29621,10 +29621,10 @@ fn storePtr2(...@@ -29621,10 +29621,10 @@ fn storePtr2(
29621 try sema.queueFullTypeResolution(elem_ty);29621 try sema.queueFullTypeResolution(elem_ty);
2962229622
29623 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {29623 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {
29624 const ptr_inst = Air.refToIndex(ptr).?;29624 const ptr_inst = ptr.toIndex().?;
29625 const air_tags = sema.air_instructions.items(.tag);29625 const air_tags = sema.air_instructions.items(.tag);
29626 if (air_tags[ptr_inst] == .ptr_elem_ptr) {29626 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
29627 const ty_pl = sema.air_instructions.items(.data)[ptr_inst].ty_pl;29627 const ty_pl = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].ty_pl;
29628 const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data;29628 const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data;
29629 _ = try block.addInst(.{29629 _ = try block.addInst(.{
29630 .tag = .vector_store_elem,29630 .tag = .vector_store_elem,
...@@ -29657,9 +29657,9 @@ fn storePtr2(...@@ -29657,9 +29657,9 @@ fn storePtr2(
29657/// comptime-known store to a local alloc, and updates `maybe_comptime_allocs`29657/// comptime-known store to a local alloc, and updates `maybe_comptime_allocs`
29658/// accordingly.29658/// accordingly.
29659fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.Ref) !void {29659fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.Ref) !void {
29660 const store_inst = Air.refToIndex(store_inst_ref).?;29660 const store_inst = store_inst_ref.toIndex().?;
29661 const inst_data = sema.air_instructions.items(.data)[store_inst].bin_op;29661 const inst_data = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
29662 const ptr = Air.refToIndex(inst_data.lhs) orelse return;29662 const ptr = inst_data.lhs.toIndex() orelse return;
29663 const operand = inst_data.rhs;29663 const operand = inst_data.rhs;
2966429664
29665 const maybe_base_alloc = sema.base_allocs.get(ptr) orelse return;29665 const maybe_base_alloc = sema.base_allocs.get(ptr) orelse return;
...@@ -29679,19 +29679,19 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst....@@ -29679,19 +29679,19 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.
29679/// ptr_elem_ptr, bitcast, etc), checks whether the base pointer refers to a29679/// ptr_elem_ptr, bitcast, etc), checks whether the base pointer refers to a
29680/// local alloc, and updates `base_allocs` accordingly.29680/// local alloc, and updates `base_allocs` accordingly.
29681fn checkKnownAllocPtr(sema: *Sema, base_ptr: Air.Inst.Ref, new_ptr: Air.Inst.Ref) !void {29681fn checkKnownAllocPtr(sema: *Sema, base_ptr: Air.Inst.Ref, new_ptr: Air.Inst.Ref) !void {
29682 const base_ptr_inst = Air.refToIndex(base_ptr) orelse return;29682 const base_ptr_inst = base_ptr.toIndex() orelse return;
29683 const new_ptr_inst = Air.refToIndex(new_ptr) orelse return;29683 const new_ptr_inst = new_ptr.toIndex() orelse return;
29684 const alloc_inst = sema.base_allocs.get(base_ptr_inst) orelse return;29684 const alloc_inst = sema.base_allocs.get(base_ptr_inst) orelse return;
29685 try sema.base_allocs.put(sema.gpa, new_ptr_inst, alloc_inst);29685 try sema.base_allocs.put(sema.gpa, new_ptr_inst, alloc_inst);
2968629686
29687 switch (sema.air_instructions.items(.tag)[new_ptr_inst]) {29687 switch (sema.air_instructions.items(.tag)[@intFromEnum(new_ptr_inst)]) {
29688 .optional_payload_ptr_set, .errunion_payload_ptr_set => {29688 .optional_payload_ptr_set, .errunion_payload_ptr_set => {
29689 const maybe_comptime_alloc = sema.maybe_comptime_allocs.getPtr(alloc_inst) orelse return;29689 const maybe_comptime_alloc = sema.maybe_comptime_allocs.getPtr(alloc_inst) orelse return;
29690 try maybe_comptime_alloc.non_elideable_pointers.append(sema.arena, new_ptr_inst);29690 try maybe_comptime_alloc.non_elideable_pointers.append(sema.arena, new_ptr_inst);
29691 },29691 },
29692 .ptr_elem_ptr => {29692 .ptr_elem_ptr => {
29693 const tmp_air = sema.getTmpAir();29693 const tmp_air = sema.getTmpAir();
29694 const pl_idx = tmp_air.instructions.items(.data)[new_ptr_inst].ty_pl.payload;29694 const pl_idx = tmp_air.instructions.items(.data)[@intFromEnum(new_ptr_inst)].ty_pl.payload;
29695 const bin = tmp_air.extraData(Air.Bin, pl_idx).data;29695 const bin = tmp_air.extraData(Air.Bin, pl_idx).data;
29696 const index_ref = bin.rhs;29696 const index_ref = bin.rhs;
2969729697
...@@ -29713,15 +29713,15 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {...@@ -29713,15 +29713,15 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
29713 const array_ty = sema.typeOf(ptr).childType(mod);29713 const array_ty = sema.typeOf(ptr).childType(mod);
29714 if (array_ty.zigTypeTag(mod) != .Array) return null;29714 if (array_ty.zigTypeTag(mod) != .Array) return null;
29715 var ptr_ref = ptr;29715 var ptr_ref = ptr;
29716 var ptr_inst = Air.refToIndex(ptr_ref) orelse return null;29716 var ptr_inst = ptr_ref.toIndex() orelse return null;
29717 const air_datas = sema.air_instructions.items(.data);29717 const air_datas = sema.air_instructions.items(.data);
29718 const air_tags = sema.air_instructions.items(.tag);29718 const air_tags = sema.air_instructions.items(.tag);
29719 const vector_ty = while (air_tags[ptr_inst] == .bitcast) {29719 const vector_ty = while (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
29720 ptr_ref = air_datas[ptr_inst].ty_op.operand;29720 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
29721 if (!sema.isKnownZigType(ptr_ref, .Pointer)) return null;29721 if (!sema.isKnownZigType(ptr_ref, .Pointer)) return null;
29722 const child_ty = sema.typeOf(ptr_ref).childType(mod);29722 const child_ty = sema.typeOf(ptr_ref).childType(mod);
29723 if (child_ty.zigTypeTag(mod) == .Vector) break child_ty;29723 if (child_ty.zigTypeTag(mod) == .Vector) break child_ty;
29724 ptr_inst = Air.refToIndex(ptr_ref) orelse return null;29724 ptr_inst = ptr_ref.toIndex() orelse return null;
29725 } else return null;29725 } else return null;
2972629726
29727 // We have a pointer-to-array and a pointer-to-vector. If the elements and29727 // We have a pointer-to-array and a pointer-to-vector. If the elements and
...@@ -31631,7 +31631,7 @@ fn analyzeDeclVal(...@@ -31631,7 +31631,7 @@ fn analyzeDeclVal(
31631 }31631 }
31632 const decl_ref = try sema.analyzeDeclRefInner(decl_index, false);31632 const decl_ref = try sema.analyzeDeclRefInner(decl_index, false);
31633 const result = try sema.analyzeLoad(block, src, decl_ref, src);31633 const result = try sema.analyzeLoad(block, src, decl_ref, src);
31634 if (Air.refToInterned(result) != null) {31634 if (result.toInterned() != null) {
31635 if (!block.is_typeof) {31635 if (!block.is_typeof) {
31636 try sema.decl_val_table.put(sema.gpa, decl_index, result);31636 try sema.decl_val_table.put(sema.gpa, decl_index, result);
31637 }31637 }
...@@ -31811,10 +31811,10 @@ fn analyzeLoad(...@@ -31811,10 +31811,10 @@ fn analyzeLoad(
31811 }31811 }
3181231812
31813 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {31813 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {
31814 const ptr_inst = Air.refToIndex(ptr).?;31814 const ptr_inst = ptr.toIndex().?;
31815 const air_tags = sema.air_instructions.items(.tag);31815 const air_tags = sema.air_instructions.items(.tag);
31816 if (air_tags[ptr_inst] == .ptr_elem_ptr) {31816 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
31817 const ty_pl = sema.air_instructions.items(.data)[ptr_inst].ty_pl;31817 const ty_pl = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].ty_pl;
31818 const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data;31818 const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data;
31819 return block.addBinOp(.ptr_elem_val, bin_op.lhs, bin_op.rhs);31819 return block.addBinOp(.ptr_elem_val, bin_op.lhs, bin_op.rhs);
31820 }31820 }
...@@ -31932,8 +31932,8 @@ fn analyzeIsNonErrComptimeOnly(...@@ -31932,8 +31932,8 @@ fn analyzeIsNonErrComptimeOnly(
31932 return .bool_false;31932 return .bool_false;
31933 }31933 }
3193431934
31935 if (Air.refToIndex(operand)) |operand_inst| {31935 if (operand.toIndex()) |operand_inst| {
31936 switch (sema.air_instructions.items(.tag)[operand_inst]) {31936 switch (sema.air_instructions.items(.tag)[@intFromEnum(operand_inst)]) {
31937 .wrap_errunion_payload => return .bool_true,31937 .wrap_errunion_payload => return .bool_true,
31938 .wrap_errunion_err => return .bool_false,31938 .wrap_errunion_err => return .bool_false,
31939 else => {},31939 else => {},
...@@ -37089,8 +37089,8 @@ fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void {...@@ -37089,8 +37089,8 @@ fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void {
37089fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index {37089fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index {
37090 const air_datas = sema.air_instructions.items(.data);37090 const air_datas = sema.air_instructions.items(.data);
37091 const air_tags = sema.air_instructions.items(.tag);37091 const air_tags = sema.air_instructions.items(.tag);
37092 switch (air_tags[inst_index]) {37092 switch (air_tags[@intFromEnum(inst_index)]) {
37093 .br => return air_datas[inst_index].br.block_inst,37093 .br => return air_datas[@intFromEnum(inst_index)].br.block_inst,
37094 else => return null,37094 else => return null,
37095 }37095 }
37096}37096}
...@@ -38121,7 +38121,7 @@ fn errorSetMerge(sema: *Sema, lhs: Type, rhs: Type) !Type {...@@ -38121,7 +38121,7 @@ fn errorSetMerge(sema: *Sema, lhs: Type, rhs: Type) !Type {
38121/// Avoids crashing the compiler when asking if inferred allocations are noreturn.38121/// Avoids crashing the compiler when asking if inferred allocations are noreturn.
38122fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool {38122fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool {
38123 if (ref == .unreachable_value) return true;38123 if (ref == .unreachable_value) return true;
38124 if (Air.refToIndex(ref)) |inst| switch (sema.air_instructions.items(.tag)[inst]) {38124 if (ref.toIndex()) |inst| switch (sema.air_instructions.items(.tag)[@intFromEnum(inst)]) {
38125 .inferred_alloc, .inferred_alloc_comptime => return false,38125 .inferred_alloc, .inferred_alloc_comptime => return false,
38126 else => {},38126 else => {},
38127 };38127 };
...@@ -38130,7 +38130,7 @@ fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool {...@@ -38130,7 +38130,7 @@ fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool {
3813038130
38131/// Avoids crashing the compiler when asking if inferred allocations are known to be a certain zig type.38131/// Avoids crashing the compiler when asking if inferred allocations are known to be a certain zig type.
38132fn isKnownZigType(sema: *Sema, ref: Air.Inst.Ref, tag: std.builtin.TypeId) bool {38132fn isKnownZigType(sema: *Sema, ref: Air.Inst.Ref, tag: std.builtin.TypeId) bool {
38133 if (Air.refToIndex(ref)) |inst| switch (sema.air_instructions.items(.tag)[inst]) {38133 if (ref.toIndex()) |inst| switch (sema.air_instructions.items(.tag)[@intFromEnum(inst)]) {
38134 .inferred_alloc, .inferred_alloc_comptime => return false,38134 .inferred_alloc, .inferred_alloc_comptime => return false,
38135 else => {},38135 else => {},
38136 };38136 };
src/arch/aarch64/CodeGen.zig+124-124
...@@ -287,7 +287,7 @@ const BigTomb = struct {...@@ -287,7 +287,7 @@ const BigTomb = struct {
287287
288 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {288 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {
289 const dies = bt.lbt.feed();289 const dies = bt.lbt.feed();
290 const op_index = Air.refToIndex(op_ref) orelse return;290 const op_index = op_ref.toIndex() orelse return;
291 if (!dies) return;291 if (!dies) return;
292 bt.function.processDeath(op_index);292 bt.function.processDeath(op_index);
293 }293 }
...@@ -444,7 +444,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {...@@ -444,7 +444,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
444444
445 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);445 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
446446
447 const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len));447 const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len);
448 self.mir_instructions.appendAssumeCapacity(inst);448 self.mir_instructions.appendAssumeCapacity(inst);
449 return result_index;449 return result_index;
450}450}
...@@ -522,7 +522,7 @@ fn gen(self: *Self) !void {...@@ -522,7 +522,7 @@ fn gen(self: *Self) !void {
522 // The first AIR instructions of the main body are guaranteed522 // The first AIR instructions of the main body are guaranteed
523 // to be the functions arguments523 // to be the functions arguments
524 const inst = self.air.getMainBody()[arg_index];524 const inst = self.air.getMainBody()[arg_index];
525 assert(self.air.instructions.items(.tag)[inst] == .arg);525 assert(self.air.instructions.items(.tag)[@intFromEnum(inst)] == .arg);
526526
527 const ty = self.typeOfIndex(inst);527 const ty = self.typeOfIndex(inst);
528528
...@@ -668,7 +668,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -668,7 +668,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
668 const old_air_bookkeeping = self.air_bookkeeping;668 const old_air_bookkeeping = self.air_bookkeeping;
669 try self.ensureProcessDeathCapacity(Liveness.bpi);669 try self.ensureProcessDeathCapacity(Liveness.bpi);
670670
671 switch (air_tags[inst]) {671 switch (air_tags[@intFromEnum(inst)]) {
672 // zig fmt: off672 // zig fmt: off
673 .add => try self.airBinOp(inst, .add),673 .add => try self.airBinOp(inst, .add),
674 .add_wrap => try self.airBinOp(inst, .add_wrap),674 .add_wrap => try self.airBinOp(inst, .add_wrap),
...@@ -914,7 +914,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -914,7 +914,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
914914
915 if (std.debug.runtime_safety) {915 if (std.debug.runtime_safety) {
916 if (self.air_bookkeeping < old_air_bookkeeping + 1) {916 if (self.air_bookkeeping < old_air_bookkeeping + 1) {
917 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] });917 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] });
918 }918 }
919 }919 }
920 }920 }
...@@ -954,7 +954,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live...@@ -954,7 +954,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
954 const dies = @as(u1, @truncate(tomb_bits)) != 0;954 const dies = @as(u1, @truncate(tomb_bits)) != 0;
955 tomb_bits >>= 1;955 tomb_bits >>= 1;
956 if (!dies) continue;956 if (!dies) continue;
957 const op_index = Air.refToIndex(op) orelse continue;957 const op_index = op.toIndex() orelse continue;
958 self.processDeath(op_index);958 self.processDeath(op_index);
959 }959 }
960 const is_used = @as(u1, @truncate(tomb_bits)) == 0;960 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
...@@ -1160,19 +1160,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1160,19 +1160,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
1160}1160}
11611161
1162fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {1162fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
1163 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1163 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1164 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch});1164 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch});
1165 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1165 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1166}1166}
11671167
1168fn airFpext(self: *Self, inst: Air.Inst.Index) !void {1168fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
1169 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1169 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1170 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch});1170 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch});
1171 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1171 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1172}1172}
11731173
1174fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {1174fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
1175 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1175 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1176 if (self.liveness.isUnused(inst))1176 if (self.liveness.isUnused(inst))
1177 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });1177 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
11781178
...@@ -1277,7 +1277,7 @@ fn trunc(...@@ -1277,7 +1277,7 @@ fn trunc(
1277 defer if (lock) |reg| self.register_manager.unlockReg(reg);1277 defer if (lock) |reg| self.register_manager.unlockReg(reg);
12781278
1279 const dest_reg = if (maybe_inst) |inst| blk: {1279 const dest_reg = if (maybe_inst) |inst| blk: {
1280 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1280 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
12811281
1282 if (operand == .register and self.reuseOperand(inst, ty_op.operand, 0, operand)) {1282 if (operand == .register and self.reuseOperand(inst, ty_op.operand, 0, operand)) {
1283 break :blk self.registerAlias(operand_reg, dest_ty);1283 break :blk self.registerAlias(operand_reg, dest_ty);
...@@ -1299,7 +1299,7 @@ fn trunc(...@@ -1299,7 +1299,7 @@ fn trunc(
1299}1299}
13001300
1301fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {1301fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
1302 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1302 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1303 const operand = try self.resolveInst(ty_op.operand);1303 const operand = try self.resolveInst(ty_op.operand);
1304 const operand_ty = self.typeOf(ty_op.operand);1304 const operand_ty = self.typeOf(ty_op.operand);
1305 const dest_ty = self.typeOfIndex(inst);1305 const dest_ty = self.typeOfIndex(inst);
...@@ -1312,14 +1312,14 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -1312,14 +1312,14 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
1312}1312}
13131313
1314fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {1314fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
1315 const un_op = self.air.instructions.items(.data)[inst].un_op;1315 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1316 const operand = try self.resolveInst(un_op);1316 const operand = try self.resolveInst(un_op);
1317 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;1317 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
1318 return self.finishAir(inst, result, .{ un_op, .none, .none });1318 return self.finishAir(inst, result, .{ un_op, .none, .none });
1319}1319}
13201320
1321fn airNot(self: *Self, inst: Air.Inst.Index) !void {1321fn airNot(self: *Self, inst: Air.Inst.Index) !void {
1322 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1322 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1323 const mod = self.bin_file.options.module.?;1323 const mod = self.bin_file.options.module.?;
1324 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1324 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1325 const operand = try self.resolveInst(ty_op.operand);1325 const operand = try self.resolveInst(ty_op.operand);
...@@ -1488,8 +1488,8 @@ fn minMax(...@@ -1488,8 +1488,8 @@ fn minMax(
1488}1488}
14891489
1490fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {1490fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
1491 const tag = self.air.instructions.items(.tag)[inst];1491 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1492 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1492 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1493 const lhs_ty = self.typeOf(bin_op.lhs);1493 const lhs_ty = self.typeOf(bin_op.lhs);
1494 const rhs_ty = self.typeOf(bin_op.rhs);1494 const rhs_ty = self.typeOf(bin_op.rhs);
14951495
...@@ -1506,7 +1506,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {...@@ -1506,7 +1506,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
1506}1506}
15071507
1508fn airSlice(self: *Self, inst: Air.Inst.Index) !void {1508fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
1509 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1509 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1510 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;1510 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
1511 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1511 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1512 const ptr = try self.resolveInst(bin_op.lhs);1512 const ptr = try self.resolveInst(bin_op.lhs);
...@@ -1662,7 +1662,7 @@ fn allocRegs(...@@ -1662,7 +1662,7 @@ fn allocRegs(
1662 arg.reg.* = self.registerAlias(raw_reg, arg.ty);1662 arg.reg.* = self.registerAlias(raw_reg, arg.ty);
1663 } else {1663 } else {
1664 const track_inst: ?Air.Inst.Index = switch (arg.bind) {1664 const track_inst: ?Air.Inst.Index = switch (arg.bind) {
1665 .inst => |inst| Air.refToIndex(inst).?,1665 .inst => |inst| inst.toIndex().?,
1666 else => null,1666 else => null,
1667 };1667 };
1668 const raw_reg = try self.register_manager.allocReg(track_inst, gp);1668 const raw_reg = try self.register_manager.allocReg(track_inst, gp);
...@@ -1725,7 +1725,7 @@ fn allocRegs(...@@ -1725,7 +1725,7 @@ fn allocRegs(
1725 if (mcv != .register) {1725 if (mcv != .register) {
1726 if (arg.bind == .inst) {1726 if (arg.bind == .inst) {
1727 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];1727 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
1728 const inst = Air.refToIndex(arg.bind.inst).?;1728 const inst = arg.bind.inst.toIndex().?;
17291729
1730 // Overwrite the MCValue associated with this inst1730 // Overwrite the MCValue associated with this inst
1731 branch.inst_table.putAssumeCapacity(inst, .{ .register = arg.reg.* });1731 branch.inst_table.putAssumeCapacity(inst, .{ .register = arg.reg.* });
...@@ -2430,7 +2430,7 @@ fn ptrArithmetic(...@@ -2430,7 +2430,7 @@ fn ptrArithmetic(
2430}2430}
24312431
2432fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {2432fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
2433 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2433 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2434 const lhs_ty = self.typeOf(bin_op.lhs);2434 const lhs_ty = self.typeOf(bin_op.lhs);
2435 const rhs_ty = self.typeOf(bin_op.rhs);2435 const rhs_ty = self.typeOf(bin_op.rhs);
24362436
...@@ -2480,7 +2480,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {...@@ -2480,7 +2480,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
2480}2480}
24812481
2482fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {2482fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
2483 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2483 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2484 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;2484 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
2485 const lhs_ty = self.typeOf(bin_op.lhs);2485 const lhs_ty = self.typeOf(bin_op.lhs);
2486 const rhs_ty = self.typeOf(bin_op.rhs);2486 const rhs_ty = self.typeOf(bin_op.rhs);
...@@ -2495,26 +2495,26 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void...@@ -2495,26 +2495,26 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void
2495}2495}
24962496
2497fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {2497fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
2498 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2498 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2499 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});2499 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});
2500 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });2500 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
2501}2501}
25022502
2503fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {2503fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
2504 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2504 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2505 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});2505 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});
2506 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });2506 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
2507}2507}
25082508
2509fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {2509fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
2510 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2510 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2511 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});2511 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});
2512 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });2512 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
2513}2513}
25142514
2515fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {2515fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
2516 const tag = self.air.instructions.items(.tag)[inst];2516 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
2517 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2517 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2518 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2518 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2519 const mod = self.bin_file.options.module.?;2519 const mod = self.bin_file.options.module.?;
2520 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2520 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
...@@ -2641,7 +2641,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2641,7 +2641,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
2641}2641}
26422642
2643fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {2643fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2644 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2644 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2645 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2645 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2646 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });2646 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
2647 const mod = self.bin_file.options.module.?;2647 const mod = self.bin_file.options.module.?;
...@@ -2865,7 +2865,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2865,7 +2865,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2865}2865}
28662866
2867fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {2867fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2868 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2868 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2869 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2869 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2870 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });2870 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
2871 const mod = self.bin_file.options.module.?;2871 const mod = self.bin_file.options.module.?;
...@@ -3000,13 +3000,13 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -3000,13 +3000,13 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
3000}3000}
30013001
3002fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {3002fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
3003 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3003 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3004 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});3004 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
3005 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });3005 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
3006}3006}
30073007
3008fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {3008fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
3009 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3009 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3010 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3010 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3011 const optional_ty = self.typeOf(ty_op.operand);3011 const optional_ty = self.typeOf(ty_op.operand);
3012 const mcv = try self.resolveInst(ty_op.operand);3012 const mcv = try self.resolveInst(ty_op.operand);
...@@ -3042,13 +3042,13 @@ fn optionalPayload(self: *Self, inst: Air.Inst.Index, mcv: MCValue, optional_ty:...@@ -3042,13 +3042,13 @@ fn optionalPayload(self: *Self, inst: Air.Inst.Index, mcv: MCValue, optional_ty:
3042}3042}
30433043
3044fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {3044fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
3045 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3045 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3046 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});3046 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});
3047 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3047 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3048}3048}
30493049
3050fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {3050fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
3051 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3051 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3052 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});3052 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});
3053 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3053 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3054}3054}
...@@ -3123,7 +3123,7 @@ fn errUnionErr(...@@ -3123,7 +3123,7 @@ fn errUnionErr(
3123}3123}
31243124
3125fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {3125fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
3126 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3126 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3127 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3127 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3128 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };3128 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
3129 const error_union_ty = self.typeOf(ty_op.operand);3129 const error_union_ty = self.typeOf(ty_op.operand);
...@@ -3203,7 +3203,7 @@ fn errUnionPayload(...@@ -3203,7 +3203,7 @@ fn errUnionPayload(
3203}3203}
32043204
3205fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {3205fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
3206 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3206 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3207 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3207 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3208 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };3208 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
3209 const error_union_ty = self.typeOf(ty_op.operand);3209 const error_union_ty = self.typeOf(ty_op.operand);
...@@ -3215,20 +3215,20 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -3215,20 +3215,20 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
32153215
3216// *(E!T) -> E3216// *(E!T) -> E
3217fn airUnwrapErrErrPtr(self: *Self, inst: Air.Inst.Index) !void {3217fn airUnwrapErrErrPtr(self: *Self, inst: Air.Inst.Index) !void {
3218 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3218 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3219 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error ptr for {}", .{self.target.cpu.arch});3219 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error ptr for {}", .{self.target.cpu.arch});
3220 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3220 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3221}3221}
32223222
3223// *(E!T) -> *T3223// *(E!T) -> *T
3224fn airUnwrapErrPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {3224fn airUnwrapErrPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
3225 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3225 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3226 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload ptr for {}", .{self.target.cpu.arch});3226 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload ptr for {}", .{self.target.cpu.arch});
3227 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3227 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3228}3228}
32293229
3230fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {3230fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
3231 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3231 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3232 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});3232 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});
3233 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3233 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3234}3234}
...@@ -3253,7 +3253,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {...@@ -3253,7 +3253,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
32533253
3254fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {3254fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
3255 const mod = self.bin_file.options.module.?;3255 const mod = self.bin_file.options.module.?;
3256 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3256 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
32573257
3258 if (self.liveness.isUnused(inst)) {3258 if (self.liveness.isUnused(inst)) {
3259 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });3259 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
...@@ -3298,9 +3298,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -3298,9 +3298,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
3298/// T to E!T3298/// T to E!T
3299fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {3299fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
3300 const mod = self.bin_file.options.module.?;3300 const mod = self.bin_file.options.module.?;
3301 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3301 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3302 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3302 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3303 const error_union_ty = self.air.getRefType(ty_op.ty);3303 const error_union_ty = ty_op.ty.toType();
3304 const error_ty = error_union_ty.errorUnionSet(mod);3304 const error_ty = error_union_ty.errorUnionSet(mod);
3305 const payload_ty = error_union_ty.errorUnionPayload(mod);3305 const payload_ty = error_union_ty.errorUnionPayload(mod);
3306 const operand = try self.resolveInst(ty_op.operand);3306 const operand = try self.resolveInst(ty_op.operand);
...@@ -3321,10 +3321,10 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -3321,10 +3321,10 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
33213321
3322/// E to E!T3322/// E to E!T
3323fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {3323fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
3324 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3324 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3325 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3325 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3326 const mod = self.bin_file.options.module.?;3326 const mod = self.bin_file.options.module.?;
3327 const error_union_ty = self.air.getRefType(ty_op.ty);3327 const error_union_ty = ty_op.ty.toType();
3328 const error_ty = error_union_ty.errorUnionSet(mod);3328 const error_ty = error_union_ty.errorUnionSet(mod);
3329 const payload_ty = error_union_ty.errorUnionPayload(mod);3329 const payload_ty = error_union_ty.errorUnionPayload(mod);
3330 const operand = try self.resolveInst(ty_op.operand);3330 const operand = try self.resolveInst(ty_op.operand);
...@@ -3361,7 +3361,7 @@ fn slicePtr(mcv: MCValue) MCValue {...@@ -3361,7 +3361,7 @@ fn slicePtr(mcv: MCValue) MCValue {
3361}3361}
33623362
3363fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {3363fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
3364 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3364 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3365 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3365 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3366 const mcv = try self.resolveInst(ty_op.operand);3366 const mcv = try self.resolveInst(ty_op.operand);
3367 break :result slicePtr(mcv);3367 break :result slicePtr(mcv);
...@@ -3370,7 +3370,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3370,7 +3370,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
3370}3370}
33713371
3372fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {3372fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
3373 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3373 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3374 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3374 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3375 const ptr_bits = 64;3375 const ptr_bits = 64;
3376 const ptr_bytes = @divExact(ptr_bits, 8);3376 const ptr_bytes = @divExact(ptr_bits, 8);
...@@ -3394,7 +3394,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -3394,7 +3394,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
3394}3394}
33953395
3396fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {3396fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
3397 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3397 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3398 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3398 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3399 const ptr_bits = 64;3399 const ptr_bits = 64;
3400 const ptr_bytes = @divExact(ptr_bits, 8);3400 const ptr_bytes = @divExact(ptr_bits, 8);
...@@ -3411,7 +3411,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3411,7 +3411,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
3411}3411}
34123412
3413fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {3413fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
3414 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3414 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3415 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3415 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3416 const mcv = try self.resolveInst(ty_op.operand);3416 const mcv = try self.resolveInst(ty_op.operand);
3417 switch (mcv) {3417 switch (mcv) {
...@@ -3427,7 +3427,7 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3427,7 +3427,7 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
34273427
3428fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {3428fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
3429 const mod = self.bin_file.options.module.?;3429 const mod = self.bin_file.options.module.?;
3430 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3430 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3431 const slice_ty = self.typeOf(bin_op.lhs);3431 const slice_ty = self.typeOf(bin_op.lhs);
3432 const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {3432 const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
3433 const ptr_ty = slice_ty.slicePtrFieldType(mod);3433 const ptr_ty = slice_ty.slicePtrFieldType(mod);
...@@ -3467,7 +3467,7 @@ fn ptrElemVal(...@@ -3467,7 +3467,7 @@ fn ptrElemVal(
3467}3467}
34683468
3469fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {3469fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
3470 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3470 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3471 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;3471 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
3472 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3472 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3473 const slice_mcv = try self.resolveInst(extra.lhs);3473 const slice_mcv = try self.resolveInst(extra.lhs);
...@@ -3486,14 +3486,14 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3486,14 +3486,14 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
3486}3486}
34873487
3488fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {3488fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
3489 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3489 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3490 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch});3490 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch});
3491 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });3491 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
3492}3492}
34933493
3494fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {3494fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
3495 const mod = self.bin_file.options.module.?;3495 const mod = self.bin_file.options.module.?;
3496 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3496 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3497 const ptr_ty = self.typeOf(bin_op.lhs);3497 const ptr_ty = self.typeOf(bin_op.lhs);
3498 const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {3498 const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
3499 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };3499 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
...@@ -3505,7 +3505,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -3505,7 +3505,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
3505}3505}
35063506
3507fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {3507fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
3508 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3508 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3509 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;3509 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
3510 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3510 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3511 const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs };3511 const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs };
...@@ -3521,55 +3521,55 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -3521,55 +3521,55 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
3521}3521}
35223522
3523fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {3523fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
3524 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3524 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3525 _ = bin_op;3525 _ = bin_op;
3526 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});3526 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});
3527}3527}
35283528
3529fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {3529fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
3530 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3530 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3531 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});3531 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});
3532 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3532 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3533}3533}
35343534
3535fn airClz(self: *Self, inst: Air.Inst.Index) !void {3535fn airClz(self: *Self, inst: Air.Inst.Index) !void {
3536 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3536 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3537 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});3537 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});
3538 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3538 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3539}3539}
35403540
3541fn airCtz(self: *Self, inst: Air.Inst.Index) !void {3541fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
3542 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3542 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3543 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});3543 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});
3544 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3544 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3545}3545}
35463546
3547fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {3547fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
3548 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3548 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3549 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});3549 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});
3550 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3550 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3551}3551}
35523552
3553fn airAbs(self: *Self, inst: Air.Inst.Index) !void {3553fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
3554 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3554 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3555 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch});3555 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch});
3556 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3556 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3557}3557}
35583558
3559fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {3559fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
3560 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3560 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3561 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch});3561 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch});
3562 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3562 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3563}3563}
35643564
3565fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {3565fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
3566 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3566 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3567 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});3567 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});
3568 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });3568 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
3569}3569}
35703570
3571fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {3571fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {
3572 const un_op = self.air.instructions.items(.data)[inst].un_op;3572 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
3573 const result: MCValue = if (self.liveness.isUnused(inst))3573 const result: MCValue = if (self.liveness.isUnused(inst))
3574 .dead3574 .dead
3575 else3575 else
...@@ -3609,7 +3609,7 @@ fn reuseOperand(...@@ -3609,7 +3609,7 @@ fn reuseOperand(
36093609
3610 // That makes us responsible for doing the rest of the stuff that processDeath would have done.3610 // That makes us responsible for doing the rest of the stuff that processDeath would have done.
3611 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];3611 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
3612 branch.inst_table.putAssumeCapacity(Air.refToIndex(operand).?, .dead);3612 branch.inst_table.putAssumeCapacity(operand.toIndex().?, .dead);
36133613
3614 return true;3614 return true;
3615}3615}
...@@ -3864,7 +3864,7 @@ fn genInlineMemsetCode(...@@ -3864,7 +3864,7 @@ fn genInlineMemsetCode(
38643864
3865fn airLoad(self: *Self, inst: Air.Inst.Index) !void {3865fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
3866 const mod = self.bin_file.options.module.?;3866 const mod = self.bin_file.options.module.?;
3867 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3867 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3868 const elem_ty = self.typeOfIndex(inst);3868 const elem_ty = self.typeOfIndex(inst);
3869 const elem_size = elem_ty.abiSize(mod);3869 const elem_size = elem_ty.abiSize(mod);
3870 const result: MCValue = result: {3870 const result: MCValue = result: {
...@@ -4066,7 +4066,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -4066,7 +4066,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
4066 } else {4066 } else {
4067 // TODO if the value is undef, don't lower this instruction4067 // TODO if the value is undef, don't lower this instruction
4068 }4068 }
4069 const bin_op = self.air.instructions.items(.data)[inst].bin_op;4069 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4070 const ptr = try self.resolveInst(bin_op.lhs);4070 const ptr = try self.resolveInst(bin_op.lhs);
4071 const value = try self.resolveInst(bin_op.rhs);4071 const value = try self.resolveInst(bin_op.rhs);
4072 const ptr_ty = self.typeOf(bin_op.lhs);4072 const ptr_ty = self.typeOf(bin_op.lhs);
...@@ -4078,14 +4078,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -4078,14 +4078,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
4078}4078}
40794079
4080fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {4080fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {
4081 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;4081 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4082 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;4082 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
4083 const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index);4083 const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index);
4084 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });4084 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });
4085}4085}
40864086
4087fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {4087fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
4088 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4088 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4089 const result = try self.structFieldPtr(inst, ty_op.operand, index);4089 const result = try self.structFieldPtr(inst, ty_op.operand, index);
4090 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });4090 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
4091}4091}
...@@ -4112,7 +4112,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde...@@ -4112,7 +4112,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
4112}4112}
41134113
4114fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {4114fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
4115 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;4115 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4116 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;4116 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
4117 const operand = extra.struct_operand;4117 const operand = extra.struct_operand;
4118 const index = extra.field_index;4118 const index = extra.field_index;
...@@ -4168,11 +4168,11 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -4168,11 +4168,11 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
41684168
4169fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {4169fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
4170 const mod = self.bin_file.options.module.?;4170 const mod = self.bin_file.options.module.?;
4171 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;4171 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4172 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;4172 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
4173 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4173 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4174 const field_ptr = try self.resolveInst(extra.field_ptr);4174 const field_ptr = try self.resolveInst(extra.field_ptr);
4175 const struct_ty = self.air.getRefType(ty_pl.ty).childType(mod);4175 const struct_ty = ty_pl.ty.toType().childType(mod);
4176 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, mod)));4176 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, mod)));
4177 switch (field_ptr) {4177 switch (field_ptr) {
4178 .ptr_stack_offset => |off| {4178 .ptr_stack_offset => |off| {
...@@ -4197,8 +4197,8 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -4197,8 +4197,8 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
41974197
4198 const mod = self.bin_file.options.module.?;4198 const mod = self.bin_file.options.module.?;
4199 const ty = self.typeOfIndex(inst);4199 const ty = self.typeOfIndex(inst);
4200 const tag = self.air.instructions.items(.tag)[inst];4200 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
4201 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;4201 const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;
4202 const name = mod.getParamName(self.func_index, src_index);4202 const name = mod.getParamName(self.func_index, src_index);
42034203
4204 try self.dbg_info_relocs.append(self.gpa, .{4204 try self.dbg_info_relocs.append(self.gpa, .{
...@@ -4245,7 +4245,7 @@ fn airFence(self: *Self) !void {...@@ -4245,7 +4245,7 @@ fn airFence(self: *Self) !void {
42454245
4246fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {4246fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
4247 if (modifier == .always_tail) return self.fail("TODO implement tail calls for aarch64", .{});4247 if (modifier == .always_tail) return self.fail("TODO implement tail calls for aarch64", .{});
4248 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4248 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4249 const callee = pl_op.operand;4249 const callee = pl_op.operand;
4250 const extra = self.air.extraData(Air.Call, pl_op.payload);4250 const extra = self.air.extraData(Air.Call, pl_op.payload);
4251 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));4251 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
...@@ -4423,7 +4423,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4423,7 +4423,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
44234423
4424fn airRet(self: *Self, inst: Air.Inst.Index) !void {4424fn airRet(self: *Self, inst: Air.Inst.Index) !void {
4425 const mod = self.bin_file.options.module.?;4425 const mod = self.bin_file.options.module.?;
4426 const un_op = self.air.instructions.items(.data)[inst].un_op;4426 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4427 const operand = try self.resolveInst(un_op);4427 const operand = try self.resolveInst(un_op);
4428 const ret_ty = self.fn_type.fnReturnType(mod);4428 const ret_ty = self.fn_type.fnReturnType(mod);
44294429
...@@ -4455,7 +4455,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {...@@ -4455,7 +4455,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44554455
4456fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {4456fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4457 const mod = self.bin_file.options.module.?;4457 const mod = self.bin_file.options.module.?;
4458 const un_op = self.air.instructions.items(.data)[inst].un_op;4458 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4459 const ptr = try self.resolveInst(un_op);4459 const ptr = try self.resolveInst(un_op);
4460 const ptr_ty = self.typeOf(un_op);4460 const ptr_ty = self.typeOf(un_op);
4461 const ret_ty = self.fn_type.fnReturnType(mod);4461 const ret_ty = self.fn_type.fnReturnType(mod);
...@@ -4476,8 +4476,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -4476,8 +4476,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4476 // here. Else we need to load the result from the location4476 // here. Else we need to load the result from the location
4477 // pointed to by the operand and store it to the result4477 // pointed to by the operand and store it to the result
4478 // location.4478 // location.
4479 const op_inst = Air.refToIndex(un_op).?;4479 const op_inst = un_op.toIndex().?;
4480 if (self.air.instructions.items(.tag)[op_inst] != .ret_ptr) {4480 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {
4481 const abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));4481 const abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
4482 const abi_align = ret_ty.abiAlignment(mod);4482 const abi_align = ret_ty.abiAlignment(mod);
44834483
...@@ -4497,7 +4497,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -4497,7 +4497,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4497}4497}
44984498
4499fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {4499fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
4500 const bin_op = self.air.instructions.items(.data)[inst].bin_op;4500 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4501 const lhs_ty = self.typeOf(bin_op.lhs);4501 const lhs_ty = self.typeOf(bin_op.lhs);
45024502
4503 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {4503 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
...@@ -4599,7 +4599,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {...@@ -4599,7 +4599,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
4599}4599}
46004600
4601fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {4601fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
4602 const un_op = self.air.instructions.items(.data)[inst].un_op;4602 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4603 const operand = try self.resolveInst(un_op);4603 const operand = try self.resolveInst(un_op);
4604 _ = operand;4604 _ = operand;
4605 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch});4605 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch});
...@@ -4607,7 +4607,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -4607,7 +4607,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
4607}4607}
46084608
4609fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {4609fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
4610 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;4610 const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
46114611
4612 _ = try self.addInst(.{4612 _ = try self.addInst(.{
4613 .tag = .dbg_line,4613 .tag = .dbg_line,
...@@ -4621,7 +4621,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {...@@ -4621,7 +4621,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
4621}4621}
46224622
4623fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {4623fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
4624 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;4624 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
4625 const mod = self.bin_file.options.module.?;4625 const mod = self.bin_file.options.module.?;
4626 const func = mod.funcInfo(ty_fn.func);4626 const func = mod.funcInfo(ty_fn.func);
4627 // TODO emit debug info for function change4627 // TODO emit debug info for function change
...@@ -4635,9 +4635,9 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -4635,9 +4635,9 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
4635}4635}
46364636
4637fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {4637fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
4638 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4638 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4639 const operand = pl_op.operand;4639 const operand = pl_op.operand;
4640 const tag = self.air.instructions.items(.tag)[inst];4640 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
4641 const ty = self.typeOf(operand);4641 const ty = self.typeOf(operand);
4642 const mcv = try self.resolveInst(operand);4642 const mcv = try self.resolveInst(operand);
4643 const name = self.air.nullTerminatedString(pl_op.payload);4643 const name = self.air.nullTerminatedString(pl_op.payload);
...@@ -4686,11 +4686,11 @@ fn condBr(self: *Self, condition: MCValue) !Mir.Inst.Index {...@@ -4686,11 +4686,11 @@ fn condBr(self: *Self, condition: MCValue) !Mir.Inst.Index {
4686}4686}
46874687
4688fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {4688fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
4689 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4689 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4690 const cond = try self.resolveInst(pl_op.operand);4690 const cond = try self.resolveInst(pl_op.operand);
4691 const extra = self.air.extraData(Air.CondBr, pl_op.payload);4691 const extra = self.air.extraData(Air.CondBr, pl_op.payload);
4692 const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len];4692 const then_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.then_body_len]);
4693 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];4693 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
4694 const liveness_condbr = self.liveness.getCondBr(inst);4694 const liveness_condbr = self.liveness.getCondBr(inst);
46954695
4696 const reloc = try self.condBr(cond);4696 const reloc = try self.condBr(cond);
...@@ -4699,7 +4699,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4699,7 +4699,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
4699 // that death now instead of later as this has an effect on4699 // that death now instead of later as this has an effect on
4700 // whether it needs to be spilled in the branches4700 // whether it needs to be spilled in the branches
4701 if (self.liveness.operandDies(inst, 0)) {4701 if (self.liveness.operandDies(inst, 0)) {
4702 if (Air.refToIndex(pl_op.operand)) |op_index| {4702 if (pl_op.operand.toIndex()) |op_index| {
4703 self.processDeath(op_index);4703 self.processDeath(op_index);
4704 }4704 }
4705 }4705 }
...@@ -4917,7 +4917,7 @@ fn isNonErr(...@@ -4917,7 +4917,7 @@ fn isNonErr(
4917}4917}
49184918
4919fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {4919fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
4920 const un_op = self.air.instructions.items(.data)[inst].un_op;4920 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4921 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4921 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4922 const operand = try self.resolveInst(un_op);4922 const operand = try self.resolveInst(un_op);
4923 const operand_ty = self.typeOf(un_op);4923 const operand_ty = self.typeOf(un_op);
...@@ -4929,7 +4929,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -4929,7 +4929,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
49294929
4930fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {4930fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4931 const mod = self.bin_file.options.module.?;4931 const mod = self.bin_file.options.module.?;
4932 const un_op = self.air.instructions.items(.data)[inst].un_op;4932 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4933 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4933 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4934 const operand_ptr = try self.resolveInst(un_op);4934 const operand_ptr = try self.resolveInst(un_op);
4935 const ptr_ty = self.typeOf(un_op);4935 const ptr_ty = self.typeOf(un_op);
...@@ -4944,7 +4944,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4944,7 +4944,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4944}4944}
49454945
4946fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {4946fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
4947 const un_op = self.air.instructions.items(.data)[inst].un_op;4947 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4948 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4948 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4949 const operand = try self.resolveInst(un_op);4949 const operand = try self.resolveInst(un_op);
4950 const operand_ty = self.typeOf(un_op);4950 const operand_ty = self.typeOf(un_op);
...@@ -4956,7 +4956,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -4956,7 +4956,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
49564956
4957fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {4957fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4958 const mod = self.bin_file.options.module.?;4958 const mod = self.bin_file.options.module.?;
4959 const un_op = self.air.instructions.items(.data)[inst].un_op;4959 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4960 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4960 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4961 const operand_ptr = try self.resolveInst(un_op);4961 const operand_ptr = try self.resolveInst(un_op);
4962 const ptr_ty = self.typeOf(un_op);4962 const ptr_ty = self.typeOf(un_op);
...@@ -4971,7 +4971,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4971,7 +4971,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4971}4971}
49724972
4973fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {4973fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
4974 const un_op = self.air.instructions.items(.data)[inst].un_op;4974 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4975 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4975 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4976 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };4976 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
4977 const error_union_ty = self.typeOf(un_op);4977 const error_union_ty = self.typeOf(un_op);
...@@ -4983,7 +4983,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4983,7 +4983,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49834983
4984fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {4984fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4985 const mod = self.bin_file.options.module.?;4985 const mod = self.bin_file.options.module.?;
4986 const un_op = self.air.instructions.items(.data)[inst].un_op;4986 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4987 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4987 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4988 const operand_ptr = try self.resolveInst(un_op);4988 const operand_ptr = try self.resolveInst(un_op);
4989 const ptr_ty = self.typeOf(un_op);4989 const ptr_ty = self.typeOf(un_op);
...@@ -4998,7 +4998,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4998,7 +4998,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4998}4998}
49994999
5000fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {5000fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
5001 const un_op = self.air.instructions.items(.data)[inst].un_op;5001 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5002 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {5002 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
5003 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };5003 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
5004 const error_union_ty = self.typeOf(un_op);5004 const error_union_ty = self.typeOf(un_op);
...@@ -5010,7 +5010,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5010,7 +5010,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
50105010
5011fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {5011fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
5012 const mod = self.bin_file.options.module.?;5012 const mod = self.bin_file.options.module.?;
5013 const un_op = self.air.instructions.items(.data)[inst].un_op;5013 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5014 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {5014 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
5015 const operand_ptr = try self.resolveInst(un_op);5015 const operand_ptr = try self.resolveInst(un_op);
5016 const ptr_ty = self.typeOf(un_op);5016 const ptr_ty = self.typeOf(un_op);
...@@ -5026,9 +5026,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5026,9 +5026,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
50265026
5027fn airLoop(self: *Self, inst: Air.Inst.Index) !void {5027fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
5028 // A loop is a setup to be able to jump back to the beginning.5028 // A loop is a setup to be able to jump back to the beginning.
5029 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5029 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5030 const loop = self.air.extraData(Air.Block, ty_pl.payload);5030 const loop = self.air.extraData(Air.Block, ty_pl.payload);
5031 const body = self.air.extra[loop.end..][0..loop.data.body_len];5031 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);
5032 const start_index = @as(u32, @intCast(self.mir_instructions.len));5032 const start_index = @as(u32, @intCast(self.mir_instructions.len));
50335033
5034 try self.genBody(body);5034 try self.genBody(body);
...@@ -5058,9 +5058,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -5058,9 +5058,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
5058 });5058 });
5059 defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa);5059 defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa);
50605060
5061 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5061 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5062 const extra = self.air.extraData(Air.Block, ty_pl.payload);5062 const extra = self.air.extraData(Air.Block, ty_pl.payload);
5063 const body = self.air.extra[extra.end..][0..extra.data.body_len];5063 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
5064 try self.genBody(body);5064 try self.genBody(body);
50655065
5066 // relocations for `br` instructions5066 // relocations for `br` instructions
...@@ -5080,7 +5080,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -5080,7 +5080,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
5080}5080}
50815081
5082fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {5082fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5083 const pl_op = self.air.instructions.items(.data)[inst].pl_op;5083 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5084 const condition_ty = self.typeOf(pl_op.operand);5084 const condition_ty = self.typeOf(pl_op.operand);
5085 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);5085 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
5086 const liveness = try self.liveness.getSwitchBr(5086 const liveness = try self.liveness.getSwitchBr(
...@@ -5096,7 +5096,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5096,7 +5096,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5096 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);5096 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
5097 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));5097 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));
5098 assert(items.len > 0);5098 assert(items.len > 0);
5099 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];5099 const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]);
5100 extra_index = case.end + items.len + case_body.len;5100 extra_index = case.end + items.len + case_body.len;
51015101
5102 // For every item, we compare it to condition and branch into5102 // For every item, we compare it to condition and branch into
...@@ -5167,7 +5167,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5167,7 +5167,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5167 }5167 }
51685168
5169 if (switch_br.data.else_body_len > 0) {5169 if (switch_br.data.else_body_len > 0) {
5170 const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len];5170 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]);
51715171
5172 // Capture the state of register and stack allocation state so that we can revert to it.5172 // Capture the state of register and stack allocation state so that we can revert to it.
5173 const parent_next_stack_offset = self.next_stack_offset;5173 const parent_next_stack_offset = self.next_stack_offset;
...@@ -5212,15 +5212,15 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5212,15 +5212,15 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5212fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {5212fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
5213 const tag = self.mir_instructions.items(.tag)[inst];5213 const tag = self.mir_instructions.items(.tag)[inst];
5214 switch (tag) {5214 switch (tag) {
5215 .cbz => self.mir_instructions.items(.data)[inst].r_inst.inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),5215 .cbz => self.mir_instructions.items(.data)[inst].r_inst.inst = @intCast(self.mir_instructions.len),
5216 .b_cond => self.mir_instructions.items(.data)[inst].inst_cond.inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),5216 .b_cond => self.mir_instructions.items(.data)[inst].inst_cond.inst = @intCast(self.mir_instructions.len),
5217 .b => self.mir_instructions.items(.data)[inst].inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),5217 .b => self.mir_instructions.items(.data)[inst].inst = @intCast(self.mir_instructions.len),
5218 else => unreachable,5218 else => unreachable,
5219 }5219 }
5220}5220}
52215221
5222fn airBr(self: *Self, inst: Air.Inst.Index) !void {5222fn airBr(self: *Self, inst: Air.Inst.Index) !void {
5223 const branch = self.air.instructions.items(.data)[inst].br;5223 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
5224 try self.br(branch.block_inst, branch.operand);5224 try self.br(branch.block_inst, branch.operand);
5225 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });5225 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });
5226}5226}
...@@ -5263,7 +5263,7 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {...@@ -5263,7 +5263,7 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
5263}5263}
52645264
5265fn airAsm(self: *Self, inst: Air.Inst.Index) !void {5265fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
5266 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5266 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5267 const extra = self.air.extraData(Air.Asm, ty_pl.payload);5267 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
5268 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;5268 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
5269 const clobbers_len = @as(u31, @truncate(extra.data.flags));5269 const clobbers_len = @as(u31, @truncate(extra.data.flags));
...@@ -5907,13 +5907,13 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I...@@ -5907,13 +5907,13 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
5907}5907}
59085908
5909fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {5909fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
5910 const un_op = self.air.instructions.items(.data)[inst].un_op;5910 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5911 const result = try self.resolveInst(un_op);5911 const result = try self.resolveInst(un_op);
5912 return self.finishAir(inst, result, .{ un_op, .none, .none });5912 return self.finishAir(inst, result, .{ un_op, .none, .none });
5913}5913}
59145914
5915fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {5915fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
5916 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5916 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5917 const result = if (self.liveness.isUnused(inst)) .dead else result: {5917 const result = if (self.liveness.isUnused(inst)) .dead else result: {
5918 const operand = try self.resolveInst(ty_op.operand);5918 const operand = try self.resolveInst(ty_op.operand);
5919 if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand;5919 if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand;
...@@ -5935,7 +5935,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -5935,7 +5935,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59355935
5936fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {5936fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5937 const mod = self.bin_file.options.module.?;5937 const mod = self.bin_file.options.module.?;
5938 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5938 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5939 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {5939 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
5940 const ptr_ty = self.typeOf(ty_op.operand);5940 const ptr_ty = self.typeOf(ty_op.operand);
5941 const ptr = try self.resolveInst(ty_op.operand);5941 const ptr = try self.resolveInst(ty_op.operand);
...@@ -5951,7 +5951,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -5951,7 +5951,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5951}5951}
59525952
5953fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {5953fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
5954 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5954 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5955 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{5955 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
5956 self.target.cpu.arch,5956 self.target.cpu.arch,
5957 });5957 });
...@@ -5959,7 +5959,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {...@@ -5959,7 +5959,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
5959}5959}
59605960
5961fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {5961fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
5962 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5962 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5963 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{5963 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
5964 self.target.cpu.arch,5964 self.target.cpu.arch,
5965 });5965 });
...@@ -5967,7 +5967,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {...@@ -5967,7 +5967,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
5967}5967}
59685968
5969fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {5969fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
5970 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5970 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5971 const extra = self.air.extraData(Air.Block, ty_pl.payload);5971 const extra = self.air.extraData(Air.Block, ty_pl.payload);
5972 _ = extra;5972 _ = extra;
59735973
...@@ -6008,7 +6008,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {...@@ -6008,7 +6008,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
6008}6008}
60096009
6010fn airTagName(self: *Self, inst: Air.Inst.Index) !void {6010fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
6011 const un_op = self.air.instructions.items(.data)[inst].un_op;6011 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
6012 const operand = try self.resolveInst(un_op);6012 const operand = try self.resolveInst(un_op);
6013 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {6013 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
6014 _ = operand;6014 _ = operand;
...@@ -6018,7 +6018,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {...@@ -6018,7 +6018,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
6018}6018}
60196019
6020fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {6020fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
6021 const un_op = self.air.instructions.items(.data)[inst].un_op;6021 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
6022 const operand = try self.resolveInst(un_op);6022 const operand = try self.resolveInst(un_op);
6023 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {6023 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
6024 _ = operand;6024 _ = operand;
...@@ -6028,27 +6028,27 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {...@@ -6028,27 +6028,27 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
6028}6028}
60296029
6030fn airSplat(self: *Self, inst: Air.Inst.Index) !void {6030fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
6031 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6031 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6032 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for {}", .{self.target.cpu.arch});6032 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for {}", .{self.target.cpu.arch});
6033 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });6033 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
6034}6034}
60356035
6036fn airSelect(self: *Self, inst: Air.Inst.Index) !void {6036fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
6037 const pl_op = self.air.instructions.items(.data)[inst].pl_op;6037 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6038 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;6038 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
6039 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for {}", .{self.target.cpu.arch});6039 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for {}", .{self.target.cpu.arch});
6040 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });6040 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
6041}6041}
60426042
6043fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {6043fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
6044 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6044 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6045 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;6045 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
6046 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for {}", .{self.target.cpu.arch});6046 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for {}", .{self.target.cpu.arch});
6047 return self.finishAir(inst, result, .{ extra.a, extra.b, .none });6047 return self.finishAir(inst, result, .{ extra.a, extra.b, .none });
6048}6048}
60496049
6050fn airReduce(self: *Self, inst: Air.Inst.Index) !void {6050fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
6051 const reduce = self.air.instructions.items(.data)[inst].reduce;6051 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
6052 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for aarch64", .{});6052 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for aarch64", .{});
6053 return self.finishAir(inst, result, .{ reduce.operand, .none, .none });6053 return self.finishAir(inst, result, .{ reduce.operand, .none, .none });
6054}6054}
...@@ -6057,7 +6057,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6057,7 +6057,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6057 const mod = self.bin_file.options.module.?;6057 const mod = self.bin_file.options.module.?;
6058 const vector_ty = self.typeOfIndex(inst);6058 const vector_ty = self.typeOfIndex(inst);
6059 const len = vector_ty.vectorLen(mod);6059 const len = vector_ty.vectorLen(mod);
6060 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6060 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6061 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));6061 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
6062 const result: MCValue = res: {6062 const result: MCValue = res: {
6063 if (self.liveness.isUnused(inst)) break :res MCValue.dead;6063 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
...@@ -6077,19 +6077,19 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6077,19 +6077,19 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6077}6077}
60786078
6079fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {6079fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
6080 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6080 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6081 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;6081 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
6082 _ = extra;6082 _ = extra;
6083 return self.fail("TODO implement airUnionInit for aarch64", .{});6083 return self.fail("TODO implement airUnionInit for aarch64", .{});
6084}6084}
60856085
6086fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {6086fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {
6087 const prefetch = self.air.instructions.items(.data)[inst].prefetch;6087 const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
6088 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });6088 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });
6089}6089}
60906090
6091fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {6091fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
6092 const pl_op = self.air.instructions.items(.data)[inst].pl_op;6092 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6093 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;6093 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
6094 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {6094 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
6095 return self.fail("TODO implement airMulAdd for aarch64", .{});6095 return self.fail("TODO implement airMulAdd for aarch64", .{});
...@@ -6099,9 +6099,9 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -6099,9 +6099,9 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
60996099
6100fn airTry(self: *Self, inst: Air.Inst.Index) !void {6100fn airTry(self: *Self, inst: Air.Inst.Index) !void {
6101 const mod = self.bin_file.options.module.?;6101 const mod = self.bin_file.options.module.?;
6102 const pl_op = self.air.instructions.items(.data)[inst].pl_op;6102 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6103 const extra = self.air.extraData(Air.Try, pl_op.payload);6103 const extra = self.air.extraData(Air.Try, pl_op.payload);
6104 const body = self.air.extra[extra.end..][0..extra.data.body_len];6104 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
6105 const result: MCValue = result: {6105 const result: MCValue = result: {
6106 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };6106 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
6107 const error_union_ty = self.typeOf(pl_op.operand);6107 const error_union_ty = self.typeOf(pl_op.operand);
...@@ -6126,7 +6126,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {...@@ -6126,7 +6126,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
6126}6126}
61276127
6128fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {6128fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {
6129 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6129 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6130 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);6130 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
6131 const body = self.air.extra[extra.end..][0..extra.data.body_len];6131 const body = self.air.extra[extra.end..][0..extra.data.body_len];
6132 _ = body;6132 _ = body;
...@@ -6142,7 +6142,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {...@@ -6142,7 +6142,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
6142 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod))6142 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod))
6143 return MCValue{ .none = {} };6143 return MCValue{ .none = {} };
61446144
6145 const inst_index = Air.refToIndex(inst) orelse return self.genTypedValue(.{6145 const inst_index = inst.toIndex() orelse return self.genTypedValue(.{
6146 .ty = inst_ty,6146 .ty = inst_ty,
6147 .val = (try self.air.value(inst, mod)).?,6147 .val = (try self.air.value(inst, mod)).?,
6148 });6148 });
src/arch/arm/CodeGen.zig+200-200
...@@ -200,7 +200,7 @@ const BigTomb = struct {...@@ -200,7 +200,7 @@ const BigTomb = struct {
200200
201 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {201 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {
202 const dies = bt.lbt.feed();202 const dies = bt.lbt.feed();
203 const op_index = Air.refToIndex(op_ref) orelse return;203 const op_index = op_ref.toIndex() orelse return;
204 if (!dies) return;204 if (!dies) return;
205 bt.function.processDeath(op_index);205 bt.function.processDeath(op_index);
206 }206 }
...@@ -450,7 +450,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {...@@ -450,7 +450,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
450450
451 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);451 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
452452
453 const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len));453 const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len);
454 self.mir_instructions.appendAssumeCapacity(inst);454 self.mir_instructions.appendAssumeCapacity(inst);
455 return result_index;455 return result_index;
456}456}
...@@ -470,11 +470,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {...@@ -470,11 +470,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
470470
471pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {471pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
472 const fields = std.meta.fields(@TypeOf(extra));472 const fields = std.meta.fields(@TypeOf(extra));
473 const result = @as(u32, @intCast(self.mir_extra.items.len));473 const result: u32 = @intCast(self.mir_extra.items.len);
474 inline for (fields) |field| {474 inline for (fields) |field| {
475 self.mir_extra.appendAssumeCapacity(switch (field.type) {475 self.mir_extra.appendAssumeCapacity(switch (field.type) {
476 u32 => @field(extra, field.name),476 u32 => @field(extra, field.name),
477 i32 => @as(u32, @bitCast(@field(extra, field.name))),477 i32 => @bitCast(@field(extra, field.name)),
478 else => @compileError("bad field type"),478 else => @compileError("bad field type"),
479 });479 });
480 }480 }
...@@ -522,11 +522,11 @@ fn gen(self: *Self) !void {...@@ -522,11 +522,11 @@ fn gen(self: *Self) !void {
522 // The first AIR instructions of the main body are guaranteed522 // The first AIR instructions of the main body are guaranteed
523 // to be the functions arguments523 // to be the functions arguments
524 const inst = self.air.getMainBody()[arg_index];524 const inst = self.air.getMainBody()[arg_index];
525 assert(self.air.instructions.items(.tag)[inst] == .arg);525 assert(self.air.instructions.items(.tag)[@intFromEnum(inst)] == .arg);
526526
527 const ty = self.typeOfIndex(inst);527 const ty = self.typeOfIndex(inst);
528528
529 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));529 const abi_size: u32 = @intCast(ty.abiSize(mod));
530 const abi_align = ty.abiAlignment(mod);530 const abi_align = ty.abiAlignment(mod);
531 const stack_offset = try self.allocMem(abi_size, abi_align, inst);531 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
532 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });532 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
...@@ -592,7 +592,7 @@ fn gen(self: *Self) !void {...@@ -592,7 +592,7 @@ fn gen(self: *Self) !void {
592 for (self.exitlude_jump_relocs.items) |jmp_reloc| {592 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
593 self.mir_instructions.set(jmp_reloc, .{593 self.mir_instructions.set(jmp_reloc, .{
594 .tag = .b,594 .tag = .b,
595 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len)) },595 .data = .{ .inst = @intCast(self.mir_instructions.len) },
596 });596 });
597 }597 }
598598
...@@ -654,7 +654,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -654,7 +654,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
654 const old_air_bookkeeping = self.air_bookkeeping;654 const old_air_bookkeeping = self.air_bookkeeping;
655 try self.ensureProcessDeathCapacity(Liveness.bpi);655 try self.ensureProcessDeathCapacity(Liveness.bpi);
656656
657 switch (air_tags[inst]) {657 switch (air_tags[@intFromEnum(inst)]) {
658 // zig fmt: off658 // zig fmt: off
659 .add, => try self.airBinOp(inst, .add),659 .add, => try self.airBinOp(inst, .add),
660 .add_wrap => try self.airBinOp(inst, .add_wrap),660 .add_wrap => try self.airBinOp(inst, .add_wrap),
...@@ -900,7 +900,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -900,7 +900,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
900900
901 if (std.debug.runtime_safety) {901 if (std.debug.runtime_safety) {
902 if (self.air_bookkeeping < old_air_bookkeeping + 1) {902 if (self.air_bookkeeping < old_air_bookkeeping + 1) {
903 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] });903 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] });
904 }904 }
905 }905 }
906 }906 }
...@@ -942,7 +942,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live...@@ -942,7 +942,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
942 const dies = @as(u1, @truncate(tomb_bits)) != 0;942 const dies = @as(u1, @truncate(tomb_bits)) != 0;
943 tomb_bits >>= 1;943 tomb_bits >>= 1;
944 if (!dies) continue;944 if (!dies) continue;
945 const op_index = Air.refToIndex(op) orelse continue;945 const op_index = op.toIndex() orelse continue;
946 self.processDeath(op_index);946 self.processDeath(op_index);
947 }947 }
948 const is_used = @as(u1, @truncate(tomb_bits)) == 0;948 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
...@@ -1018,7 +1018,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {...@@ -1018,7 +1018,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
1018 // return the stack offset 0. Stack offset 0 will be where all1018 // return the stack offset 0. Stack offset 0 will be where all
1019 // zero-sized stack allocations live as non-zero-sized1019 // zero-sized stack allocations live as non-zero-sized
1020 // allocations will always have an offset > 0.1020 // allocations will always have an offset > 0.
1021 return @as(u32, 0);1021 return 0;
1022 }1022 }
10231023
1024 const abi_size = math.cast(u32, elem_ty.abiSize(mod)) orelse {1024 const abi_size = math.cast(u32, elem_ty.abiSize(mod)) orelse {
...@@ -1139,20 +1139,20 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1139,20 +1139,20 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
1139}1139}
11401140
1141fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {1141fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
1142 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1142 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1143 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch});1143 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch});
1144 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1144 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1145}1145}
11461146
1147fn airFpext(self: *Self, inst: Air.Inst.Index) !void {1147fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
1148 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1148 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1149 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch});1149 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch});
1150 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1150 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1151}1151}
11521152
1153fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {1153fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
1154 const mod = self.bin_file.options.module.?;1154 const mod = self.bin_file.options.module.?;
1155 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1155 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1156 if (self.liveness.isUnused(inst))1156 if (self.liveness.isUnused(inst))
1157 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });1157 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
11581158
...@@ -1204,7 +1204,7 @@ fn truncRegister(...@@ -1204,7 +1204,7 @@ fn truncRegister(
1204 .rd = dest_reg,1204 .rd = dest_reg,
1205 .rn = operand_reg,1205 .rn = operand_reg,
1206 .lsb = 0,1206 .lsb = 0,
1207 .width = @as(u6, @intCast(int_bits)),1207 .width = @intCast(int_bits),
1208 } },1208 } },
1209 });1209 });
1210}1210}
...@@ -1260,7 +1260,7 @@ fn trunc(...@@ -1260,7 +1260,7 @@ fn trunc(
1260}1260}
12611261
1262fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {1262fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
1263 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1263 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1264 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };1264 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
1265 const operand_ty = self.typeOf(ty_op.operand);1265 const operand_ty = self.typeOf(ty_op.operand);
1266 const dest_ty = self.typeOfIndex(inst);1266 const dest_ty = self.typeOfIndex(inst);
...@@ -1273,14 +1273,14 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -1273,14 +1273,14 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
1273}1273}
12741274
1275fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {1275fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
1276 const un_op = self.air.instructions.items(.data)[inst].un_op;1276 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1277 const operand = try self.resolveInst(un_op);1277 const operand = try self.resolveInst(un_op);
1278 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;1278 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
1279 return self.finishAir(inst, result, .{ un_op, .none, .none });1279 return self.finishAir(inst, result, .{ un_op, .none, .none });
1280}1280}
12811281
1282fn airNot(self: *Self, inst: Air.Inst.Index) !void {1282fn airNot(self: *Self, inst: Air.Inst.Index) !void {
1283 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1283 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1284 const mod = self.bin_file.options.module.?;1284 const mod = self.bin_file.options.module.?;
1285 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1285 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1286 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };1286 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
...@@ -1465,8 +1465,8 @@ fn minMax(...@@ -1465,8 +1465,8 @@ fn minMax(
1465}1465}
14661466
1467fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {1467fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
1468 const tag = self.air.instructions.items(.tag)[inst];1468 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1469 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1469 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1470 const lhs_ty = self.typeOf(bin_op.lhs);1470 const lhs_ty = self.typeOf(bin_op.lhs);
1471 const rhs_ty = self.typeOf(bin_op.rhs);1471 const rhs_ty = self.typeOf(bin_op.rhs);
14721472
...@@ -1483,7 +1483,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {...@@ -1483,7 +1483,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
1483}1483}
14841484
1485fn airSlice(self: *Self, inst: Air.Inst.Index) !void {1485fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
1486 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1486 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1487 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;1487 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
1488 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1488 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1489 const ptr = try self.resolveInst(bin_op.lhs);1489 const ptr = try self.resolveInst(bin_op.lhs);
...@@ -1500,7 +1500,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -1500,7 +1500,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
1500}1500}
15011501
1502fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {1502fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1503 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1503 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1504 const lhs_ty = self.typeOf(bin_op.lhs);1504 const lhs_ty = self.typeOf(bin_op.lhs);
1505 const rhs_ty = self.typeOf(bin_op.rhs);1505 const rhs_ty = self.typeOf(bin_op.rhs);
15061506
...@@ -1550,7 +1550,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {...@@ -1550,7 +1550,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1550}1550}
15511551
1552fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {1552fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1553 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1553 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1554 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;1554 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
1555 const lhs_ty = self.typeOf(bin_op.lhs);1555 const lhs_ty = self.typeOf(bin_op.lhs);
1556 const rhs_ty = self.typeOf(bin_op.rhs);1556 const rhs_ty = self.typeOf(bin_op.rhs);
...@@ -1565,26 +1565,26 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void...@@ -1565,26 +1565,26 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void
1565}1565}
15661566
1567fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {1567fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
1568 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1568 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1569 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});1569 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});
1570 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1570 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1571}1571}
15721572
1573fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {1573fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
1574 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1574 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1575 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});1575 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});
1576 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1576 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1577}1577}
15781578
1579fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {1579fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
1580 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1580 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1581 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});1581 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});
1582 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1582 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1583}1583}
15841584
1585fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {1585fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
1586 const tag = self.air.instructions.items(.tag)[inst];1586 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1587 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1587 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1588 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;1588 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
1589 const mod = self.bin_file.options.module.?;1589 const mod = self.bin_file.options.module.?;
1590 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1590 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
...@@ -1594,9 +1594,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1594,9 +1594,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
1594 const rhs_ty = self.typeOf(extra.rhs);1594 const rhs_ty = self.typeOf(extra.rhs);
15951595
1596 const tuple_ty = self.typeOfIndex(inst);1596 const tuple_ty = self.typeOfIndex(inst);
1597 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod)));1597 const tuple_size: u32 = @intCast(tuple_ty.abiSize(mod));
1598 const tuple_align = tuple_ty.abiAlignment(mod);1598 const tuple_align = tuple_ty.abiAlignment(mod);
1599 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod)));1599 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, mod));
16001600
1601 switch (lhs_ty.zigTypeTag(mod)) {1601 switch (lhs_ty.zigTypeTag(mod)) {
1602 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),1602 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
...@@ -1696,7 +1696,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1696,7 +1696,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
1696}1696}
16971697
1698fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {1698fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1699 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1699 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1700 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;1700 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
1701 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });1701 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
1702 const mod = self.bin_file.options.module.?;1702 const mod = self.bin_file.options.module.?;
...@@ -1707,9 +1707,9 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1707,9 +1707,9 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1707 const rhs_ty = self.typeOf(extra.rhs);1707 const rhs_ty = self.typeOf(extra.rhs);
17081708
1709 const tuple_ty = self.typeOfIndex(inst);1709 const tuple_ty = self.typeOfIndex(inst);
1710 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod)));1710 const tuple_size: u32 = @intCast(tuple_ty.abiSize(mod));
1711 const tuple_align = tuple_ty.abiAlignment(mod);1711 const tuple_align = tuple_ty.abiAlignment(mod);
1712 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod)));1712 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, mod));
17131713
1714 switch (lhs_ty.zigTypeTag(mod)) {1714 switch (lhs_ty.zigTypeTag(mod)) {
1715 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),1715 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
...@@ -1860,7 +1860,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1860,7 +1860,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1860}1860}
18611861
1862fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {1862fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1863 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1863 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1864 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;1864 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
1865 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });1865 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
1866 const mod = self.bin_file.options.module.?;1866 const mod = self.bin_file.options.module.?;
...@@ -1869,9 +1869,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1869,9 +1869,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1869 const rhs_ty = self.typeOf(extra.rhs);1869 const rhs_ty = self.typeOf(extra.rhs);
18701870
1871 const tuple_ty = self.typeOfIndex(inst);1871 const tuple_ty = self.typeOfIndex(inst);
1872 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod)));1872 const tuple_size: u32 = @intCast(tuple_ty.abiSize(mod));
1873 const tuple_align = tuple_ty.abiAlignment(mod);1873 const tuple_align = tuple_ty.abiAlignment(mod);
1874 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod)));1874 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, mod));
18751875
1876 switch (lhs_ty.zigTypeTag(mod)) {1876 switch (lhs_ty.zigTypeTag(mod)) {
1877 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),1877 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
...@@ -1918,7 +1918,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1918,7 +1918,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1918 .data = .{ .rr_shift = .{1918 .data = .{ .rr_shift = .{
1919 .rd = dest_reg,1919 .rd = dest_reg,
1920 .rm = lhs_reg,1920 .rm = lhs_reg,
1921 .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_mcv.immediate))),1921 .shift_amount = Instruction.ShiftAmount.imm(@intCast(rhs_mcv.immediate)),
1922 } },1922 } },
1923 });1923 });
19241924
...@@ -1930,7 +1930,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1930,7 +1930,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1930 .data = .{ .rr_shift = .{1930 .data = .{ .rr_shift = .{
1931 .rd = reconstructed_reg,1931 .rd = reconstructed_reg,
1932 .rm = dest_reg,1932 .rm = dest_reg,
1933 .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_mcv.immediate))),1933 .shift_amount = Instruction.ShiftAmount.imm(@intCast(rhs_mcv.immediate)),
1934 } },1934 } },
1935 });1935 });
1936 } else {1936 } else {
...@@ -1995,35 +1995,35 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1995,35 +1995,35 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1995}1995}
19961996
1997fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {1997fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
1998 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1998 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1999 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});1999 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
2000 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });2000 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
2001}2001}
20022002
2003fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {2003fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
2004 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2004 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2005 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch});2005 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch});
2006 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2006 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2007}2007}
20082008
2009fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {2009fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
2010 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2010 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2011 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});2011 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});
2012 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2012 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2013}2013}
20142014
2015fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {2015fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
2016 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2016 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2017 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});2017 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});
2018 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2018 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2019}2019}
20202020
2021fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {2021fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
2022 const mod = self.bin_file.options.module.?;2022 const mod = self.bin_file.options.module.?;
2023 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2023 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2024 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2024 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2025 const optional_ty = self.typeOfIndex(inst);2025 const optional_ty = self.typeOfIndex(inst);
2026 const abi_size = @as(u32, @intCast(optional_ty.abiSize(mod)));2026 const abi_size: u32 = @intCast(optional_ty.abiSize(mod));
20272027
2028 // Optional with a zero-bit payload type is just a boolean true2028 // Optional with a zero-bit payload type is just a boolean true
2029 if (abi_size == 1) {2029 if (abi_size == 1) {
...@@ -2052,7 +2052,7 @@ fn errUnionErr(...@@ -2052,7 +2052,7 @@ fn errUnionErr(
2052 return try error_union_bind.resolveToMcv(self);2052 return try error_union_bind.resolveToMcv(self);
2053 }2053 }
20542054
2055 const err_offset = @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod)));2055 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, mod));
2056 switch (try error_union_bind.resolveToMcv(self)) {2056 switch (try error_union_bind.resolveToMcv(self)) {
2057 .register => {2057 .register => {
2058 var operand_reg: Register = undefined;2058 var operand_reg: Register = undefined;
...@@ -2074,15 +2074,15 @@ fn errUnionErr(...@@ -2074,15 +2074,15 @@ fn errUnionErr(
2074 );2074 );
20752075
2076 const err_bit_offset = err_offset * 8;2076 const err_bit_offset = err_offset * 8;
2077 const err_bit_size = @as(u32, @intCast(err_ty.abiSize(mod))) * 8;2077 const err_bit_size: u32 = @intCast(err_ty.abiSize(mod) * 8);
20782078
2079 _ = try self.addInst(.{2079 _ = try self.addInst(.{
2080 .tag = .ubfx, // errors are unsigned integers2080 .tag = .ubfx, // errors are unsigned integers
2081 .data = .{ .rr_lsb_width = .{2081 .data = .{ .rr_lsb_width = .{
2082 .rd = dest_reg,2082 .rd = dest_reg,
2083 .rn = operand_reg,2083 .rn = operand_reg,
2084 .lsb = @as(u5, @intCast(err_bit_offset)),2084 .lsb = @intCast(err_bit_offset),
2085 .width = @as(u6, @intCast(err_bit_size)),2085 .width = @intCast(err_bit_size),
2086 } },2086 } },
2087 });2087 });
20882088
...@@ -2102,7 +2102,7 @@ fn errUnionErr(...@@ -2102,7 +2102,7 @@ fn errUnionErr(
2102}2102}
21032103
2104fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {2104fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
2105 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2105 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2106 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2106 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2107 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };2107 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
2108 const error_union_ty = self.typeOf(ty_op.operand);2108 const error_union_ty = self.typeOf(ty_op.operand);
...@@ -2129,7 +2129,7 @@ fn errUnionPayload(...@@ -2129,7 +2129,7 @@ fn errUnionPayload(
2129 return MCValue.none;2129 return MCValue.none;
2130 }2130 }
21312131
2132 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));2132 const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, mod));
2133 switch (try error_union_bind.resolveToMcv(self)) {2133 switch (try error_union_bind.resolveToMcv(self)) {
2134 .register => {2134 .register => {
2135 var operand_reg: Register = undefined;2135 var operand_reg: Register = undefined;
...@@ -2151,15 +2151,15 @@ fn errUnionPayload(...@@ -2151,15 +2151,15 @@ fn errUnionPayload(
2151 );2151 );
21522152
2153 const payload_bit_offset = payload_offset * 8;2153 const payload_bit_offset = payload_offset * 8;
2154 const payload_bit_size = @as(u32, @intCast(payload_ty.abiSize(mod))) * 8;2154 const payload_bit_size: u32 = @intCast(payload_ty.abiSize(mod) * 8);
21552155
2156 _ = try self.addInst(.{2156 _ = try self.addInst(.{
2157 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,2157 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
2158 .data = .{ .rr_lsb_width = .{2158 .data = .{ .rr_lsb_width = .{
2159 .rd = dest_reg,2159 .rd = dest_reg,
2160 .rn = operand_reg,2160 .rn = operand_reg,
2161 .lsb = @as(u5, @intCast(payload_bit_offset)),2161 .lsb = @intCast(payload_bit_offset),
2162 .width = @as(u6, @intCast(payload_bit_size)),2162 .width = @intCast(payload_bit_size),
2163 } },2163 } },
2164 });2164 });
21652165
...@@ -2179,7 +2179,7 @@ fn errUnionPayload(...@@ -2179,7 +2179,7 @@ fn errUnionPayload(
2179}2179}
21802180
2181fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {2181fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
2182 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2182 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2183 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2183 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2184 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };2184 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
2185 const error_union_ty = self.typeOf(ty_op.operand);2185 const error_union_ty = self.typeOf(ty_op.operand);
...@@ -2191,20 +2191,20 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -2191,20 +2191,20 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
21912191
2192// *(E!T) -> E2192// *(E!T) -> E
2193fn airUnwrapErrErrPtr(self: *Self, inst: Air.Inst.Index) !void {2193fn airUnwrapErrErrPtr(self: *Self, inst: Air.Inst.Index) !void {
2194 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2194 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2195 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error ptr for {}", .{self.target.cpu.arch});2195 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error ptr for {}", .{self.target.cpu.arch});
2196 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2196 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2197}2197}
21982198
2199// *(E!T) -> *T2199// *(E!T) -> *T
2200fn airUnwrapErrPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {2200fn airUnwrapErrPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
2201 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2201 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2202 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload ptr for {}", .{self.target.cpu.arch});2202 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload ptr for {}", .{self.target.cpu.arch});
2203 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2203 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2204}2204}
22052205
2206fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {2206fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
2207 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2207 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2208 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});2208 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});
2209 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2209 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2210}2210}
...@@ -2230,17 +2230,17 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {...@@ -2230,17 +2230,17 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
2230/// T to E!T2230/// T to E!T
2231fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {2231fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
2232 const mod = self.bin_file.options.module.?;2232 const mod = self.bin_file.options.module.?;
2233 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2233 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2234 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2234 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2235 const error_union_ty = self.air.getRefType(ty_op.ty);2235 const error_union_ty = ty_op.ty.toType();
2236 const error_ty = error_union_ty.errorUnionSet(mod);2236 const error_ty = error_union_ty.errorUnionSet(mod);
2237 const payload_ty = error_union_ty.errorUnionPayload(mod);2237 const payload_ty = error_union_ty.errorUnionPayload(mod);
2238 const operand = try self.resolveInst(ty_op.operand);2238 const operand = try self.resolveInst(ty_op.operand);
2239 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;2239 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;
22402240
2241 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(mod)));2241 const abi_size: u32 = @intCast(error_union_ty.abiSize(mod));
2242 const abi_align = error_union_ty.abiAlignment(mod);2242 const abi_align = error_union_ty.abiAlignment(mod);
2243 const stack_offset = @as(u32, @intCast(try self.allocMem(abi_size, abi_align, inst)));2243 const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst));
2244 const payload_off = errUnionPayloadOffset(payload_ty, mod);2244 const payload_off = errUnionPayloadOffset(payload_ty, mod);
2245 const err_off = errUnionErrorOffset(payload_ty, mod);2245 const err_off = errUnionErrorOffset(payload_ty, mod);
2246 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);2246 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);
...@@ -2254,17 +2254,17 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -2254,17 +2254,17 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
2254/// E to E!T2254/// E to E!T
2255fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {2255fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
2256 const mod = self.bin_file.options.module.?;2256 const mod = self.bin_file.options.module.?;
2257 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2257 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2258 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2258 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2259 const error_union_ty = self.air.getRefType(ty_op.ty);2259 const error_union_ty = ty_op.ty.toType();
2260 const error_ty = error_union_ty.errorUnionSet(mod);2260 const error_ty = error_union_ty.errorUnionSet(mod);
2261 const payload_ty = error_union_ty.errorUnionPayload(mod);2261 const payload_ty = error_union_ty.errorUnionPayload(mod);
2262 const operand = try self.resolveInst(ty_op.operand);2262 const operand = try self.resolveInst(ty_op.operand);
2263 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;2263 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand;
22642264
2265 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(mod)));2265 const abi_size: u32 = @intCast(error_union_ty.abiSize(mod));
2266 const abi_align = error_union_ty.abiAlignment(mod);2266 const abi_align = error_union_ty.abiAlignment(mod);
2267 const stack_offset = @as(u32, @intCast(try self.allocMem(abi_size, abi_align, inst)));2267 const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst));
2268 const payload_off = errUnionPayloadOffset(payload_ty, mod);2268 const payload_off = errUnionPayloadOffset(payload_ty, mod);
2269 const err_off = errUnionErrorOffset(payload_ty, mod);2269 const err_off = errUnionErrorOffset(payload_ty, mod);
2270 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);2270 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
...@@ -2293,7 +2293,7 @@ fn slicePtr(mcv: MCValue) MCValue {...@@ -2293,7 +2293,7 @@ fn slicePtr(mcv: MCValue) MCValue {
2293}2293}
22942294
2295fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {2295fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
2296 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2296 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2297 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2297 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2298 const mcv = try self.resolveInst(ty_op.operand);2298 const mcv = try self.resolveInst(ty_op.operand);
2299 break :result slicePtr(mcv);2299 break :result slicePtr(mcv);
...@@ -2302,7 +2302,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2302,7 +2302,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
2302}2302}
23032303
2304fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {2304fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
2305 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2305 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2306 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2306 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2307 const mcv = try self.resolveInst(ty_op.operand);2307 const mcv = try self.resolveInst(ty_op.operand);
2308 switch (mcv) {2308 switch (mcv) {
...@@ -2323,7 +2323,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -2323,7 +2323,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
2323}2323}
23242324
2325fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {2325fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
2326 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2326 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2327 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2327 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2328 const mcv = try self.resolveInst(ty_op.operand);2328 const mcv = try self.resolveInst(ty_op.operand);
2329 switch (mcv) {2329 switch (mcv) {
...@@ -2343,7 +2343,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2343,7 +2343,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
2343}2343}
23442344
2345fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {2345fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
2346 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2346 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2347 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2347 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2348 const mcv = try self.resolveInst(ty_op.operand);2348 const mcv = try self.resolveInst(ty_op.operand);
2349 switch (mcv) {2349 switch (mcv) {
...@@ -2372,7 +2372,7 @@ fn ptrElemVal(...@@ -2372,7 +2372,7 @@ fn ptrElemVal(
2372) !MCValue {2372) !MCValue {
2373 const mod = self.bin_file.options.module.?;2373 const mod = self.bin_file.options.module.?;
2374 const elem_ty = ptr_ty.childType(mod);2374 const elem_ty = ptr_ty.childType(mod);
2375 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));2375 const elem_size: u32 = @intCast(elem_ty.abiSize(mod));
23762376
2377 switch (elem_size) {2377 switch (elem_size) {
2378 1, 4 => {2378 1, 4 => {
...@@ -2430,7 +2430,7 @@ fn ptrElemVal(...@@ -2430,7 +2430,7 @@ fn ptrElemVal(
24302430
2431fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {2431fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
2432 const mod = self.bin_file.options.module.?;2432 const mod = self.bin_file.options.module.?;
2433 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2433 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2434 const slice_ty = self.typeOf(bin_op.lhs);2434 const slice_ty = self.typeOf(bin_op.lhs);
2435 const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {2435 const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
2436 const ptr_ty = slice_ty.slicePtrFieldType(mod);2436 const ptr_ty = slice_ty.slicePtrFieldType(mod);
...@@ -2447,7 +2447,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2447,7 +2447,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
2447}2447}
24482448
2449fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {2449fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
2450 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2450 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2451 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2451 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2452 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2452 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2453 const slice_mcv = try self.resolveInst(extra.lhs);2453 const slice_mcv = try self.resolveInst(extra.lhs);
...@@ -2483,7 +2483,7 @@ fn arrayElemVal(...@@ -2483,7 +2483,7 @@ fn arrayElemVal(
2483 => {2483 => {
2484 const ptr_to_mcv = switch (mcv) {2484 const ptr_to_mcv = switch (mcv) {
2485 .stack_offset => |off| MCValue{ .ptr_stack_offset = off },2485 .stack_offset => |off| MCValue{ .ptr_stack_offset = off },
2486 .memory => |addr| MCValue{ .immediate = @as(u32, @intCast(addr)) },2486 .memory => |addr| MCValue{ .immediate = @intCast(addr) },
2487 .stack_argument_offset => |off| blk: {2487 .stack_argument_offset => |off| blk: {
2488 const reg = try self.register_manager.allocReg(null, gp);2488 const reg = try self.register_manager.allocReg(null, gp);
24892489
...@@ -2516,7 +2516,7 @@ fn arrayElemVal(...@@ -2516,7 +2516,7 @@ fn arrayElemVal(
2516}2516}
25172517
2518fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {2518fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
2519 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2519 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2520 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2520 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2521 const array_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };2521 const array_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
2522 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };2522 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };
...@@ -2529,7 +2529,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2529,7 +2529,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
25292529
2530fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {2530fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
2531 const mod = self.bin_file.options.module.?;2531 const mod = self.bin_file.options.module.?;
2532 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2532 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2533 const ptr_ty = self.typeOf(bin_op.lhs);2533 const ptr_ty = self.typeOf(bin_op.lhs);
2534 const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {2534 const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
2535 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };2535 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
...@@ -2541,7 +2541,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2541,7 +2541,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
2541}2541}
25422542
2543fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {2543fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
2544 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2544 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2545 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2545 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2546 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2546 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2547 const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs };2547 const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs };
...@@ -2557,63 +2557,63 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2557,63 +2557,63 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
2557}2557}
25582558
2559fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {2559fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
2560 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2560 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2561 _ = bin_op;2561 _ = bin_op;
2562 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});2562 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});
2563 // return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });2563 // return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
2564}2564}
25652565
2566fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {2566fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
2567 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2567 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2568 _ = ty_op;2568 _ = ty_op;
2569 return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});2569 return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});
2570 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2570 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2571}2571}
25722572
2573fn airClz(self: *Self, inst: Air.Inst.Index) !void {2573fn airClz(self: *Self, inst: Air.Inst.Index) !void {
2574 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2574 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2575 _ = ty_op;2575 _ = ty_op;
2576 return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});2576 return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});
2577 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2577 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2578}2578}
25792579
2580fn airCtz(self: *Self, inst: Air.Inst.Index) !void {2580fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
2581 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2581 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2582 _ = ty_op;2582 _ = ty_op;
2583 return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});2583 return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});
2584 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2584 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2585}2585}
25862586
2587fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {2587fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
2588 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2588 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2589 _ = ty_op;2589 _ = ty_op;
2590 return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});2590 return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});
2591 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2591 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2592}2592}
25932593
2594fn airAbs(self: *Self, inst: Air.Inst.Index) !void {2594fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
2595 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2595 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2596 _ = ty_op;2596 _ = ty_op;
2597 return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch});2597 return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch});
2598 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2598 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2599}2599}
26002600
2601fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {2601fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
2602 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2602 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2603 _ = ty_op;2603 _ = ty_op;
2604 return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch});2604 return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch});
2605 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2605 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2606}2606}
26072607
2608fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {2608fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
2609 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2609 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2610 _ = ty_op;2610 _ = ty_op;
2611 return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});2611 return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});
2612 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2612 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2613}2613}
26142614
2615fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {2615fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {
2616 const un_op = self.air.instructions.items(.data)[inst].un_op;2616 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2617 const result: MCValue = if (self.liveness.isUnused(inst))2617 const result: MCValue = if (self.liveness.isUnused(inst))
2618 .dead2618 .dead
2619 else2619 else
...@@ -2656,7 +2656,7 @@ fn reuseOperand(...@@ -2656,7 +2656,7 @@ fn reuseOperand(
26562656
2657 // That makes us responsible for doing the rest of the stuff that processDeath would have done.2657 // That makes us responsible for doing the rest of the stuff that processDeath would have done.
2658 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];2658 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
2659 branch.inst_table.putAssumeCapacity(Air.refToIndex(operand).?, .dead);2659 branch.inst_table.putAssumeCapacity(operand.toIndex().?, .dead);
26602660
2661 return true;2661 return true;
2662}2662}
...@@ -2664,7 +2664,7 @@ fn reuseOperand(...@@ -2664,7 +2664,7 @@ fn reuseOperand(
2664fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {2664fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
2665 const mod = self.bin_file.options.module.?;2665 const mod = self.bin_file.options.module.?;
2666 const elem_ty = ptr_ty.childType(mod);2666 const elem_ty = ptr_ty.childType(mod);
2667 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));2667 const elem_size: u32 = @intCast(elem_ty.abiSize(mod));
26682668
2669 switch (ptr) {2669 switch (ptr) {
2670 .none => unreachable,2670 .none => unreachable,
...@@ -2740,7 +2740,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo...@@ -2740,7 +2740,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
27402740
2741fn airLoad(self: *Self, inst: Air.Inst.Index) !void {2741fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
2742 const mod = self.bin_file.options.module.?;2742 const mod = self.bin_file.options.module.?;
2743 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2743 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2744 const elem_ty = self.typeOfIndex(inst);2744 const elem_ty = self.typeOfIndex(inst);
2745 const result: MCValue = result: {2745 const result: MCValue = result: {
2746 if (!elem_ty.hasRuntimeBits(mod))2746 if (!elem_ty.hasRuntimeBits(mod))
...@@ -2769,7 +2769,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -2769,7 +2769,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27692769
2770fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {2770fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
2771 const mod = self.bin_file.options.module.?;2771 const mod = self.bin_file.options.module.?;
2772 const elem_size = @as(u32, @intCast(value_ty.abiSize(mod)));2772 const elem_size: u32 = @intCast(value_ty.abiSize(mod));
27732773
2774 switch (ptr) {2774 switch (ptr) {
2775 .none => unreachable,2775 .none => unreachable,
...@@ -2824,7 +2824,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type...@@ -2824,7 +2824,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
2824 // sub src_reg, fp, #off2824 // sub src_reg, fp, #off
2825 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });2825 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
2826 },2826 },
2827 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }),2827 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(addr) }),
2828 .stack_argument_offset => |off| {2828 .stack_argument_offset => |off| {
2829 _ = try self.addInst(.{2829 _ = try self.addInst(.{
2830 .tag = .ldr_ptr_stack_argument,2830 .tag = .ldr_ptr_stack_argument,
...@@ -2862,7 +2862,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -2862,7 +2862,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
2862 } else {2862 } else {
2863 // TODO if the value is undef, don't lower this instruction2863 // TODO if the value is undef, don't lower this instruction
2864 }2864 }
2865 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2865 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2866 const ptr = try self.resolveInst(bin_op.lhs);2866 const ptr = try self.resolveInst(bin_op.lhs);
2867 const value = try self.resolveInst(bin_op.rhs);2867 const value = try self.resolveInst(bin_op.rhs);
2868 const ptr_ty = self.typeOf(bin_op.lhs);2868 const ptr_ty = self.typeOf(bin_op.lhs);
...@@ -2874,14 +2874,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -2874,14 +2874,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
2874}2874}
28752875
2876fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {2876fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {
2877 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2877 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2878 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;2878 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
2879 const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index);2879 const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index);
2880 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });2880 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });
2881}2881}
28822882
2883fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {2883fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
2884 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2884 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2885 const result = try self.structFieldPtr(inst, ty_op.operand, index);2885 const result = try self.structFieldPtr(inst, ty_op.operand, index);
2886 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2886 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2887}2887}
...@@ -2892,7 +2892,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde...@@ -2892,7 +2892,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
2892 const mcv = try self.resolveInst(operand);2892 const mcv = try self.resolveInst(operand);
2893 const ptr_ty = self.typeOf(operand);2893 const ptr_ty = self.typeOf(operand);
2894 const struct_ty = ptr_ty.childType(mod);2894 const struct_ty = ptr_ty.childType(mod);
2895 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod)));2895 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, mod));
2896 switch (mcv) {2896 switch (mcv) {
2897 .ptr_stack_offset => |off| {2897 .ptr_stack_offset => |off| {
2898 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };2898 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
...@@ -2908,7 +2908,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde...@@ -2908,7 +2908,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
2908}2908}
29092909
2910fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {2910fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2911 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2911 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2912 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;2912 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
2913 const operand = extra.struct_operand;2913 const operand = extra.struct_operand;
2914 const index = extra.field_index;2914 const index = extra.field_index;
...@@ -2916,7 +2916,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2916,7 +2916,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2916 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2916 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2917 const mcv = try self.resolveInst(operand);2917 const mcv = try self.resolveInst(operand);
2918 const struct_ty = self.typeOf(operand);2918 const struct_ty = self.typeOf(operand);
2919 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod)));2919 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, mod));
2920 const struct_field_ty = struct_ty.structFieldType(index, mod);2920 const struct_field_ty = struct_ty.structFieldType(index, mod);
29212921
2922 switch (mcv) {2922 switch (mcv) {
...@@ -2980,15 +2980,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2980,15 +2980,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2980 );2980 );
29812981
2982 const field_bit_offset = struct_field_offset * 8;2982 const field_bit_offset = struct_field_offset * 8;
2983 const field_bit_size = @as(u32, @intCast(struct_field_ty.abiSize(mod))) * 8;2983 const field_bit_size: u32 = @intCast(struct_field_ty.abiSize(mod) * 8);
29842984
2985 _ = try self.addInst(.{2985 _ = try self.addInst(.{
2986 .tag = if (struct_field_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,2986 .tag = if (struct_field_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
2987 .data = .{ .rr_lsb_width = .{2987 .data = .{ .rr_lsb_width = .{
2988 .rd = dest_reg,2988 .rd = dest_reg,
2989 .rn = operand_reg,2989 .rn = operand_reg,
2990 .lsb = @as(u5, @intCast(field_bit_offset)),2990 .lsb = @intCast(field_bit_offset),
2991 .width = @as(u6, @intCast(field_bit_size)),2991 .width = @intCast(field_bit_size),
2992 } },2992 } },
2993 });2993 });
29942994
...@@ -3003,17 +3003,17 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -3003,17 +3003,17 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
30033003
3004fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {3004fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
3005 const mod = self.bin_file.options.module.?;3005 const mod = self.bin_file.options.module.?;
3006 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3006 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3007 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;3007 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
3008 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3008 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3009 const field_ptr = try self.resolveInst(extra.field_ptr);3009 const field_ptr = try self.resolveInst(extra.field_ptr);
3010 const struct_ty = self.air.getRefType(ty_pl.ty).childType(mod);3010 const struct_ty = ty_pl.ty.toType().childType(mod);
30113011
3012 if (struct_ty.zigTypeTag(mod) == .Union) {3012 if (struct_ty.zigTypeTag(mod) == .Union) {
3013 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});3013 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});
3014 }3014 }
30153015
3016 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, mod)));3016 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(extra.field_index, mod));
3017 switch (field_ptr) {3017 switch (field_ptr) {
3018 .ptr_stack_offset => |off| {3018 .ptr_stack_offset => |off| {
3019 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };3019 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };
...@@ -3168,7 +3168,7 @@ fn allocRegs(...@@ -3168,7 +3168,7 @@ fn allocRegs(
3168 arg.reg.* = mcv.register;3168 arg.reg.* = mcv.register;
3169 } else {3169 } else {
3170 const track_inst: ?Air.Inst.Index = switch (arg.bind) {3170 const track_inst: ?Air.Inst.Index = switch (arg.bind) {
3171 .inst => |inst| Air.refToIndex(inst).?,3171 .inst => |inst| inst.toIndex().?,
3172 else => null,3172 else => null,
3173 };3173 };
3174 arg.reg.* = try self.register_manager.allocReg(track_inst, arg.class);3174 arg.reg.* = try self.register_manager.allocReg(track_inst, arg.class);
...@@ -3225,7 +3225,7 @@ fn allocRegs(...@@ -3225,7 +3225,7 @@ fn allocRegs(
3225 if (mcv != .register) {3225 if (mcv != .register) {
3226 if (arg.bind == .inst) {3226 if (arg.bind == .inst) {
3227 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];3227 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
3228 const inst = Air.refToIndex(arg.bind.inst).?;3228 const inst = arg.bind.inst.toIndex().?;
32293229
3230 // Overwrite the MCValue associated with this inst3230 // Overwrite the MCValue associated with this inst
3231 branch.inst_table.putAssumeCapacity(inst, .{ .register = arg.reg.* });3231 branch.inst_table.putAssumeCapacity(inst, .{ .register = arg.reg.* });
...@@ -3374,7 +3374,7 @@ fn binOpImmediate(...@@ -3374,7 +3374,7 @@ fn binOpImmediate(
3374 => .{ .rr_shift = .{3374 => .{ .rr_shift = .{
3375 .rd = dest_reg,3375 .rd = dest_reg,
3376 .rm = lhs_reg,3376 .rm = lhs_reg,
3377 .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_immediate))),3377 .shift_amount = Instruction.ShiftAmount.imm(@intCast(rhs_immediate)),
3378 } },3378 } },
3379 else => unreachable,3379 else => unreachable,
3380 };3380 };
...@@ -3905,7 +3905,7 @@ fn ptrArithmetic(...@@ -3905,7 +3905,7 @@ fn ptrArithmetic(
3905 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type3905 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
3906 else => ptr_ty.childType(mod),3906 else => ptr_ty.childType(mod),
3907 };3907 };
3908 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));3908 const elem_size: u32 = @intCast(elem_ty.abiSize(mod));
39093909
3910 const base_tag: Air.Inst.Tag = switch (tag) {3910 const base_tag: Air.Inst.Tag = switch (tag) {
3911 .ptr_add => .add,3911 .ptr_add => .add,
...@@ -4032,7 +4032,7 @@ fn genInlineMemcpy(...@@ -4032,7 +4032,7 @@ fn genInlineMemcpy(
4032 _ = try self.addInst(.{4032 _ = try self.addInst(.{
4033 .tag = .b,4033 .tag = .b,
4034 .cond = .ge,4034 .cond = .ge,
4035 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 5)) },4035 .data = .{ .inst = @intCast(self.mir_instructions.len + 5) },
4036 });4036 });
40374037
4038 // ldrb tmp, [src, count]4038 // ldrb tmp, [src, count]
...@@ -4068,7 +4068,7 @@ fn genInlineMemcpy(...@@ -4068,7 +4068,7 @@ fn genInlineMemcpy(
4068 // b loop4068 // b loop
4069 _ = try self.addInst(.{4069 _ = try self.addInst(.{
4070 .tag = .b,4070 .tag = .b,
4071 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 5)) },4071 .data = .{ .inst = @intCast(self.mir_instructions.len - 5) },
4072 });4072 });
40734073
4074 // end:4074 // end:
...@@ -4136,7 +4136,7 @@ fn genInlineMemsetCode(...@@ -4136,7 +4136,7 @@ fn genInlineMemsetCode(
4136 _ = try self.addInst(.{4136 _ = try self.addInst(.{
4137 .tag = .b,4137 .tag = .b,
4138 .cond = .ge,4138 .cond = .ge,
4139 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 4)) },4139 .data = .{ .inst = @intCast(self.mir_instructions.len + 4) },
4140 });4140 });
41414141
4142 // strb val, [src, count]4142 // strb val, [src, count]
...@@ -4162,7 +4162,7 @@ fn genInlineMemsetCode(...@@ -4162,7 +4162,7 @@ fn genInlineMemsetCode(
4162 // b loop4162 // b loop
4163 _ = try self.addInst(.{4163 _ = try self.addInst(.{
4164 .tag = .b,4164 .tag = .b,
4165 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 4)) },4165 .data = .{ .inst = @intCast(self.mir_instructions.len - 4) },
4166 });4166 });
41674167
4168 // end:4168 // end:
...@@ -4176,8 +4176,8 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -4176,8 +4176,8 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
41764176
4177 const mod = self.bin_file.options.module.?;4177 const mod = self.bin_file.options.module.?;
4178 const ty = self.typeOfIndex(inst);4178 const ty = self.typeOfIndex(inst);
4179 const tag = self.air.instructions.items(.tag)[inst];4179 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
4180 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;4180 const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;
4181 const name = mod.getParamName(self.func_index, src_index);4181 const name = mod.getParamName(self.func_index, src_index);
41824182
4183 try self.dbg_info_relocs.append(self.gpa, .{4183 try self.dbg_info_relocs.append(self.gpa, .{
...@@ -4224,10 +4224,10 @@ fn airFence(self: *Self) !void {...@@ -4224,10 +4224,10 @@ fn airFence(self: *Self) !void {
42244224
4225fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {4225fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
4226 if (modifier == .always_tail) return self.fail("TODO implement tail calls for arm", .{});4226 if (modifier == .always_tail) return self.fail("TODO implement tail calls for arm", .{});
4227 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4227 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4228 const callee = pl_op.operand;4228 const callee = pl_op.operand;
4229 const extra = self.air.extraData(Air.Call, pl_op.payload);4229 const extra = self.air.extraData(Air.Call, pl_op.payload);
4230 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));4230 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
4231 const ty = self.typeOf(callee);4231 const ty = self.typeOf(callee);
4232 const mod = self.bin_file.options.module.?;4232 const mod = self.bin_file.options.module.?;
42334233
...@@ -4305,7 +4305,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4305,7 +4305,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4305 const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl);4305 const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl);
4306 const sym = elf_file.symbol(sym_index);4306 const sym = elf_file.symbol(sym_index);
4307 _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);4307 _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);
4308 const got_addr = @as(u32, @intCast(sym.zigGotAddress(elf_file)));4308 const got_addr: u32 = @intCast(sym.zigGotAddress(elf_file));
4309 try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr });4309 try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr });
4310 } else if (self.bin_file.cast(link.File.MachO)) |_| {4310 } else if (self.bin_file.cast(link.File.MachO)) |_| {
4311 unreachable; // unsupported architecture for MachO4311 unreachable; // unsupported architecture for MachO
...@@ -4381,7 +4381,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4381,7 +4381,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43814381
4382fn airRet(self: *Self, inst: Air.Inst.Index) !void {4382fn airRet(self: *Self, inst: Air.Inst.Index) !void {
4383 const mod = self.bin_file.options.module.?;4383 const mod = self.bin_file.options.module.?;
4384 const un_op = self.air.instructions.items(.data)[inst].un_op;4384 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4385 const operand = try self.resolveInst(un_op);4385 const operand = try self.resolveInst(un_op);
4386 const ret_ty = self.fn_type.fnReturnType(mod);4386 const ret_ty = self.fn_type.fnReturnType(mod);
43874387
...@@ -4413,7 +4413,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {...@@ -4413,7 +4413,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44134413
4414fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {4414fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4415 const mod = self.bin_file.options.module.?;4415 const mod = self.bin_file.options.module.?;
4416 const un_op = self.air.instructions.items(.data)[inst].un_op;4416 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4417 const ptr = try self.resolveInst(un_op);4417 const ptr = try self.resolveInst(un_op);
4418 const ptr_ty = self.typeOf(un_op);4418 const ptr_ty = self.typeOf(un_op);
4419 const ret_ty = self.fn_type.fnReturnType(mod);4419 const ret_ty = self.fn_type.fnReturnType(mod);
...@@ -4434,9 +4434,9 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -4434,9 +4434,9 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4434 // here. Else we need to load the result from the location4434 // here. Else we need to load the result from the location
4435 // pointed to by the operand and store it to the result4435 // pointed to by the operand and store it to the result
4436 // location.4436 // location.
4437 const op_inst = Air.refToIndex(un_op).?;4437 const op_inst = un_op.toIndex().?;
4438 if (self.air.instructions.items(.tag)[op_inst] != .ret_ptr) {4438 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {
4439 const abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));4439 const abi_size: u32 = @intCast(ret_ty.abiSize(mod));
4440 const abi_align = ret_ty.abiAlignment(mod);4440 const abi_align = ret_ty.abiAlignment(mod);
44414441
4442 const offset = try self.allocMem(abi_size, abi_align, null);4442 const offset = try self.allocMem(abi_size, abi_align, null);
...@@ -4456,7 +4456,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -4456,7 +4456,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4456}4456}
44574457
4458fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {4458fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
4459 const bin_op = self.air.instructions.items(.data)[inst].bin_op;4459 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4460 const lhs_ty = self.typeOf(bin_op.lhs);4460 const lhs_ty = self.typeOf(bin_op.lhs);
44614461
4462 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {4462 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
...@@ -4556,7 +4556,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {...@@ -4556,7 +4556,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
4556}4556}
45574557
4558fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {4558fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
4559 const un_op = self.air.instructions.items(.data)[inst].un_op;4559 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4560 const operand = try self.resolveInst(un_op);4560 const operand = try self.resolveInst(un_op);
4561 _ = operand;4561 _ = operand;
4562 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch});4562 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch});
...@@ -4564,7 +4564,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -4564,7 +4564,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
4564}4564}
45654565
4566fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {4566fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
4567 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;4567 const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
45684568
4569 _ = try self.addInst(.{4569 _ = try self.addInst(.{
4570 .tag = .dbg_line,4570 .tag = .dbg_line,
...@@ -4579,7 +4579,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {...@@ -4579,7 +4579,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
4579}4579}
45804580
4581fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {4581fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
4582 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;4582 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
4583 const mod = self.bin_file.options.module.?;4583 const mod = self.bin_file.options.module.?;
4584 const func = mod.funcInfo(ty_fn.func);4584 const func = mod.funcInfo(ty_fn.func);
4585 // TODO emit debug info for function change4585 // TODO emit debug info for function change
...@@ -4593,9 +4593,9 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -4593,9 +4593,9 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
4593}4593}
45944594
4595fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {4595fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
4596 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4596 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4597 const operand = pl_op.operand;4597 const operand = pl_op.operand;
4598 const tag = self.air.instructions.items(.tag)[inst];4598 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
4599 const ty = self.typeOf(operand);4599 const ty = self.typeOf(operand);
4600 const mcv = try self.resolveInst(operand);4600 const mcv = try self.resolveInst(operand);
4601 const name = self.air.nullTerminatedString(pl_op.payload);4601 const name = self.air.nullTerminatedString(pl_op.payload);
...@@ -4647,11 +4647,11 @@ fn condBr(self: *Self, condition: MCValue) !Mir.Inst.Index {...@@ -4647,11 +4647,11 @@ fn condBr(self: *Self, condition: MCValue) !Mir.Inst.Index {
4647}4647}
46484648
4649fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {4649fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
4650 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4650 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4651 const cond_inst = try self.resolveInst(pl_op.operand);4651 const cond_inst = try self.resolveInst(pl_op.operand);
4652 const extra = self.air.extraData(Air.CondBr, pl_op.payload);4652 const extra = self.air.extraData(Air.CondBr, pl_op.payload);
4653 const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len];4653 const then_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.then_body_len]);
4654 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];4654 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
4655 const liveness_condbr = self.liveness.getCondBr(inst);4655 const liveness_condbr = self.liveness.getCondBr(inst);
46564656
4657 const reloc: Mir.Inst.Index = try self.condBr(cond_inst);4657 const reloc: Mir.Inst.Index = try self.condBr(cond_inst);
...@@ -4660,7 +4660,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4660,7 +4660,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
4660 // that death now instead of later as this has an effect on4660 // that death now instead of later as this has an effect on
4661 // whether it needs to be spilled in the branches4661 // whether it needs to be spilled in the branches
4662 if (self.liveness.operandDies(inst, 0)) {4662 if (self.liveness.operandDies(inst, 0)) {
4663 if (Air.refToIndex(pl_op.operand)) |op_index| {4663 if (pl_op.operand.toIndex()) |op_index| {
4664 self.processDeath(op_index);4664 self.processDeath(op_index);
4665 }4665 }
4666 }4666 }
...@@ -4818,7 +4818,7 @@ fn isNonNull(...@@ -4818,7 +4818,7 @@ fn isNonNull(
4818}4818}
48194819
4820fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {4820fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
4821 const un_op = self.air.instructions.items(.data)[inst].un_op;4821 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4822 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4822 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4823 const operand_bind: ReadArg.Bind = .{ .inst = un_op };4823 const operand_bind: ReadArg.Bind = .{ .inst = un_op };
4824 const operand_ty = self.typeOf(un_op);4824 const operand_ty = self.typeOf(un_op);
...@@ -4830,7 +4830,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -4830,7 +4830,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
48304830
4831fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {4831fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4832 const mod = self.bin_file.options.module.?;4832 const mod = self.bin_file.options.module.?;
4833 const un_op = self.air.instructions.items(.data)[inst].un_op;4833 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4834 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4834 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4835 const operand_ptr = try self.resolveInst(un_op);4835 const operand_ptr = try self.resolveInst(un_op);
4836 const ptr_ty = self.typeOf(un_op);4836 const ptr_ty = self.typeOf(un_op);
...@@ -4845,7 +4845,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4845,7 +4845,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4845}4845}
48464846
4847fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {4847fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
4848 const un_op = self.air.instructions.items(.data)[inst].un_op;4848 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4849 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4849 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4850 const operand_bind: ReadArg.Bind = .{ .inst = un_op };4850 const operand_bind: ReadArg.Bind = .{ .inst = un_op };
4851 const operand_ty = self.typeOf(un_op);4851 const operand_ty = self.typeOf(un_op);
...@@ -4857,7 +4857,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -4857,7 +4857,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
48574857
4858fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {4858fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4859 const mod = self.bin_file.options.module.?;4859 const mod = self.bin_file.options.module.?;
4860 const un_op = self.air.instructions.items(.data)[inst].un_op;4860 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4861 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4861 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4862 const operand_ptr = try self.resolveInst(un_op);4862 const operand_ptr = try self.resolveInst(un_op);
4863 const ptr_ty = self.typeOf(un_op);4863 const ptr_ty = self.typeOf(un_op);
...@@ -4907,7 +4907,7 @@ fn isNonErr(...@@ -4907,7 +4907,7 @@ fn isNonErr(
4907}4907}
49084908
4909fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {4909fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
4910 const un_op = self.air.instructions.items(.data)[inst].un_op;4910 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4911 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4911 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4912 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };4912 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
4913 const error_union_ty = self.typeOf(un_op);4913 const error_union_ty = self.typeOf(un_op);
...@@ -4919,7 +4919,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4919,7 +4919,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49194919
4920fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {4920fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4921 const mod = self.bin_file.options.module.?;4921 const mod = self.bin_file.options.module.?;
4922 const un_op = self.air.instructions.items(.data)[inst].un_op;4922 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4923 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4923 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4924 const operand_ptr = try self.resolveInst(un_op);4924 const operand_ptr = try self.resolveInst(un_op);
4925 const ptr_ty = self.typeOf(un_op);4925 const ptr_ty = self.typeOf(un_op);
...@@ -4934,7 +4934,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4934,7 +4934,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4934}4934}
49354935
4936fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {4936fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
4937 const un_op = self.air.instructions.items(.data)[inst].un_op;4937 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4938 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4938 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4939 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };4939 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
4940 const error_union_ty = self.typeOf(un_op);4940 const error_union_ty = self.typeOf(un_op);
...@@ -4946,7 +4946,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4946,7 +4946,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
49464946
4947fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {4947fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4948 const mod = self.bin_file.options.module.?;4948 const mod = self.bin_file.options.module.?;
4949 const un_op = self.air.instructions.items(.data)[inst].un_op;4949 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4950 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4950 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4951 const operand_ptr = try self.resolveInst(un_op);4951 const operand_ptr = try self.resolveInst(un_op);
4952 const ptr_ty = self.typeOf(un_op);4952 const ptr_ty = self.typeOf(un_op);
...@@ -4962,10 +4962,10 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4962,10 +4962,10 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49624962
4963fn airLoop(self: *Self, inst: Air.Inst.Index) !void {4963fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
4964 // A loop is a setup to be able to jump back to the beginning.4964 // A loop is a setup to be able to jump back to the beginning.
4965 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;4965 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4966 const loop = self.air.extraData(Air.Block, ty_pl.payload);4966 const loop = self.air.extraData(Air.Block, ty_pl.payload);
4967 const body = self.air.extra[loop.end..][0..loop.data.body_len];4967 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);
4968 const start_index = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len));4968 const start_index: Mir.Inst.Index = @intCast(self.mir_instructions.len);
49694969
4970 try self.genBody(body);4970 try self.genBody(body);
4971 try self.jump(start_index);4971 try self.jump(start_index);
...@@ -4994,9 +4994,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -4994,9 +4994,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
4994 });4994 });
4995 defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa);4995 defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa);
49964996
4997 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;4997 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4998 const extra = self.air.extraData(Air.Block, ty_pl.payload);4998 const extra = self.air.extraData(Air.Block, ty_pl.payload);
4999 const body = self.air.extra[extra.end..][0..extra.data.body_len];4999 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
5000 try self.genBody(body);5000 try self.genBody(body);
50015001
5002 // relocations for `br` instructions5002 // relocations for `br` instructions
...@@ -5016,7 +5016,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -5016,7 +5016,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
5016}5016}
50175017
5018fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {5018fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5019 const pl_op = self.air.instructions.items(.data)[inst].pl_op;5019 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5020 const condition_ty = self.typeOf(pl_op.operand);5020 const condition_ty = self.typeOf(pl_op.operand);
5021 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);5021 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
5022 const liveness = try self.liveness.getSwitchBr(5022 const liveness = try self.liveness.getSwitchBr(
...@@ -5030,9 +5030,9 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5030,9 +5030,9 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5030 var case_i: u32 = 0;5030 var case_i: u32 = 0;
5031 while (case_i < switch_br.data.cases_len) : (case_i += 1) {5031 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
5032 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);5032 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
5033 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));5033 const items: []const Air.Inst.Ref = @ptrCast(self.air.extra[case.end..][0..case.data.items_len]);
5034 assert(items.len > 0);5034 assert(items.len > 0);
5035 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];5035 const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]);
5036 extra_index = case.end + items.len + case_body.len;5036 extra_index = case.end + items.len + case_body.len;
50375037
5038 // For every item, we compare it to condition and branch into5038 // For every item, we compare it to condition and branch into
...@@ -5103,7 +5103,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5103,7 +5103,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5103 }5103 }
51045104
5105 if (switch_br.data.else_body_len > 0) {5105 if (switch_br.data.else_body_len > 0) {
5106 const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len];5106 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]);
51075107
5108 // Capture the state of register and stack allocation state so that we can revert to it.5108 // Capture the state of register and stack allocation state so that we can revert to it.
5109 const parent_next_stack_offset = self.next_stack_offset;5109 const parent_next_stack_offset = self.next_stack_offset;
...@@ -5148,13 +5148,13 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5148,13 +5148,13 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5148fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {5148fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
5149 const tag = self.mir_instructions.items(.tag)[inst];5149 const tag = self.mir_instructions.items(.tag)[inst];
5150 switch (tag) {5150 switch (tag) {
5151 .b => self.mir_instructions.items(.data)[inst].inst = @as(Air.Inst.Index, @intCast(self.mir_instructions.len)),5151 .b => self.mir_instructions.items(.data)[inst].inst = @intCast(self.mir_instructions.len),
5152 else => unreachable,5152 else => unreachable,
5153 }5153 }
5154}5154}
51555155
5156fn airBr(self: *Self, inst: Air.Inst.Index) !void {5156fn airBr(self: *Self, inst: Air.Inst.Index) !void {
5157 const branch = self.air.instructions.items(.data)[inst].br;5157 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
5158 try self.br(branch.block_inst, branch.operand);5158 try self.br(branch.block_inst, branch.operand);
5159 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });5159 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });
5160}5160}
...@@ -5195,14 +5195,14 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {...@@ -5195,14 +5195,14 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
5195}5195}
51965196
5197fn airAsm(self: *Self, inst: Air.Inst.Index) !void {5197fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
5198 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5198 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5199 const extra = self.air.extraData(Air.Asm, ty_pl.payload);5199 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
5200 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;5200 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
5201 const clobbers_len = @as(u31, @truncate(extra.data.flags));5201 const clobbers_len: u31 = @truncate(extra.data.flags);
5202 var extra_i: usize = extra.end;5202 var extra_i: usize = extra.end;
5203 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));5203 const outputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]);
5204 extra_i += outputs.len;5204 extra_i += outputs.len;
5205 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));5205 const inputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]);
5206 extra_i += inputs.len;5206 extra_i += inputs.len;
52075207
5208 const dead = !is_volatile and self.liveness.isUnused(inst);5208 const dead = !is_volatile and self.liveness.isUnused(inst);
...@@ -5332,7 +5332,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {...@@ -5332,7 +5332,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
53325332
5333fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5333fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5334 const mod = self.bin_file.options.module.?;5334 const mod = self.bin_file.options.module.?;
5335 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));5335 const abi_size: u32 = @intCast(ty.abiSize(mod));
5336 switch (mcv) {5336 switch (mcv) {
5337 .dead => unreachable,5337 .dead => unreachable,
5338 .unreach, .none => return, // Nothing to do.5338 .unreach, .none => return, // Nothing to do.
...@@ -5385,7 +5385,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5385,7 +5385,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
5385 },5385 },
5386 2 => {5386 2 => {
5387 const offset = if (stack_offset <= math.maxInt(u8)) blk: {5387 const offset = if (stack_offset <= math.maxInt(u8)) blk: {
5388 break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(stack_offset)));5388 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(stack_offset));
5389 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));5389 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
53905390
5391 _ = try self.addInst(.{5391 _ = try self.addInst(.{
...@@ -5413,7 +5413,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5413,7 +5413,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
5413 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg });5413 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg });
54145414
5415 const overflow_bit_ty = ty.structFieldType(1, mod);5415 const overflow_bit_ty = ty.structFieldType(1, mod);
5416 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, mod)));5416 const overflow_bit_offset: u32 = @intCast(ty.structFieldOffset(1, mod));
5417 const cond_reg = try self.register_manager.allocReg(null, gp);5417 const cond_reg = try self.register_manager.allocReg(null, gp);
54185418
5419 // C flag: movcs reg, #15419 // C flag: movcs reg, #1
...@@ -5466,7 +5466,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5466,7 +5466,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
5466 // sub src_reg, fp, #off5466 // sub src_reg, fp, #off
5467 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });5467 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
5468 },5468 },
5469 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }),5469 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(addr) }),
5470 .stack_argument_offset => |off| {5470 .stack_argument_offset => |off| {
5471 _ = try self.addInst(.{5471 _ = try self.addInst(.{
5472 .tag = .ldr_ptr_stack_argument,5472 .tag = .ldr_ptr_stack_argument,
...@@ -5563,7 +5563,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5563,7 +5563,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5563 .tag = .movw,5563 .tag = .movw,
5564 .data = .{ .r_imm16 = .{5564 .data = .{ .r_imm16 = .{
5565 .rd = reg,5565 .rd = reg,
5566 .imm16 = @as(u16, @intCast(x)),5566 .imm16 = @intCast(x),
5567 } },5567 } },
5568 });5568 });
5569 } else {5569 } else {
...@@ -5571,7 +5571,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5571,7 +5571,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5571 .tag = .mov,5571 .tag = .mov,
5572 .data = .{ .r_op_mov = .{5572 .data = .{ .r_op_mov = .{
5573 .rd = reg,5573 .rd = reg,
5574 .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0),5574 .op = Instruction.Operand.imm(@truncate(x), 0),
5575 } },5575 } },
5576 });5576 });
5577 _ = try self.addInst(.{5577 _ = try self.addInst(.{
...@@ -5579,7 +5579,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5579,7 +5579,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5579 .data = .{ .rr_op = .{5579 .data = .{ .rr_op = .{
5580 .rd = reg,5580 .rd = reg,
5581 .rn = reg,5581 .rn = reg,
5582 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12),5582 .op = Instruction.Operand.imm(@truncate(x >> 8), 12),
5583 } },5583 } },
5584 });5584 });
5585 }5585 }
...@@ -5594,14 +5594,14 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5594,14 +5594,14 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5594 .tag = .movw,5594 .tag = .movw,
5595 .data = .{ .r_imm16 = .{5595 .data = .{ .r_imm16 = .{
5596 .rd = reg,5596 .rd = reg,
5597 .imm16 = @as(u16, @truncate(x)),5597 .imm16 = @truncate(x),
5598 } },5598 } },
5599 });5599 });
5600 _ = try self.addInst(.{5600 _ = try self.addInst(.{
5601 .tag = .movt,5601 .tag = .movt,
5602 .data = .{ .r_imm16 = .{5602 .data = .{ .r_imm16 = .{
5603 .rd = reg,5603 .rd = reg,
5604 .imm16 = @as(u16, @truncate(x >> 16)),5604 .imm16 = @truncate(x >> 16),
5605 } },5605 } },
5606 });5606 });
5607 } else {5607 } else {
...@@ -5614,7 +5614,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5614,7 +5614,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5614 .tag = .mov,5614 .tag = .mov,
5615 .data = .{ .r_op_mov = .{5615 .data = .{ .r_op_mov = .{
5616 .rd = reg,5616 .rd = reg,
5617 .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0),5617 .op = Instruction.Operand.imm(@truncate(x), 0),
5618 } },5618 } },
5619 });5619 });
5620 _ = try self.addInst(.{5620 _ = try self.addInst(.{
...@@ -5622,7 +5622,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5622,7 +5622,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5622 .data = .{ .rr_op = .{5622 .data = .{ .rr_op = .{
5623 .rd = reg,5623 .rd = reg,
5624 .rn = reg,5624 .rn = reg,
5625 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12),5625 .op = Instruction.Operand.imm(@truncate(x >> 8), 12),
5626 } },5626 } },
5627 });5627 });
5628 _ = try self.addInst(.{5628 _ = try self.addInst(.{
...@@ -5630,7 +5630,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5630,7 +5630,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5630 .data = .{ .rr_op = .{5630 .data = .{ .rr_op = .{
5631 .rd = reg,5631 .rd = reg,
5632 .rn = reg,5632 .rn = reg,
5633 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 16)), 8),5633 .op = Instruction.Operand.imm(@truncate(x >> 16), 8),
5634 } },5634 } },
5635 });5635 });
5636 _ = try self.addInst(.{5636 _ = try self.addInst(.{
...@@ -5638,7 +5638,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5638,7 +5638,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5638 .data = .{ .rr_op = .{5638 .data = .{ .rr_op = .{
5639 .rd = reg,5639 .rd = reg,
5640 .rn = reg,5640 .rn = reg,
5641 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 24)), 4),5641 .op = Instruction.Operand.imm(@truncate(x >> 24), 4),
5642 } },5642 } },
5643 });5643 });
5644 }5644 }
...@@ -5663,12 +5663,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5663,12 +5663,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5663 .memory => |addr| {5663 .memory => |addr| {
5664 // The value is in memory at a hard-coded address.5664 // The value is in memory at a hard-coded address.
5665 // If the type is a pointer, it means the pointer address is at this memory location.5665 // If the type is a pointer, it means the pointer address is at this memory location.
5666 try self.genSetReg(ty, reg, .{ .immediate = @as(u32, @intCast(addr)) });5666 try self.genSetReg(ty, reg, .{ .immediate = @intCast(addr) });
5667 try self.genLdrRegister(reg, reg, ty);5667 try self.genLdrRegister(reg, reg, ty);
5668 },5668 },
5669 .stack_offset => |off| {5669 .stack_offset => |off| {
5670 // TODO: maybe addressing from sp instead of fp5670 // TODO: maybe addressing from sp instead of fp
5671 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));5671 const abi_size: u32 = @intCast(ty.abiSize(mod));
56725672
5673 const tag: Mir.Inst.Tag = switch (abi_size) {5673 const tag: Mir.Inst.Tag = switch (abi_size) {
5674 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb else .ldrb,5674 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb else .ldrb,
...@@ -5686,7 +5686,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5686,7 +5686,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56865686
5687 if (extra_offset) {5687 if (extra_offset) {
5688 const offset = if (off <= math.maxInt(u8)) blk: {5688 const offset = if (off <= math.maxInt(u8)) blk: {
5689 break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(off)));5689 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(off));
5690 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }));5690 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }));
56915691
5692 _ = try self.addInst(.{5692 _ = try self.addInst(.{
...@@ -5702,7 +5702,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5702,7 +5702,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5702 });5702 });
5703 } else {5703 } else {
5704 const offset = if (off <= math.maxInt(u12)) blk: {5704 const offset = if (off <= math.maxInt(u12)) blk: {
5705 break :blk Instruction.Offset.imm(@as(u12, @intCast(off)));5705 break :blk Instruction.Offset.imm(@intCast(off));
5706 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }), .none);5706 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }), .none);
57075707
5708 _ = try self.addInst(.{5708 _ = try self.addInst(.{
...@@ -5741,7 +5741,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5741,7 +5741,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57415741
5742fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5742fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5743 const mod = self.bin_file.options.module.?;5743 const mod = self.bin_file.options.module.?;
5744 const abi_size = @as(u32, @intCast(ty.abiSize(mod)));5744 const abi_size: u32 = @intCast(ty.abiSize(mod));
5745 switch (mcv) {5745 switch (mcv) {
5746 .dead => unreachable,5746 .dead => unreachable,
5747 .none, .unreach => return,5747 .none, .unreach => return,
...@@ -5780,7 +5780,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I...@@ -5780,7 +5780,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
5780 },5780 },
5781 2 => {5781 2 => {
5782 const offset = if (stack_offset <= math.maxInt(u8)) blk: {5782 const offset = if (stack_offset <= math.maxInt(u8)) blk: {
5783 break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(stack_offset)));5783 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(stack_offset));
5784 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));5784 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
57855785
5786 _ = try self.addInst(.{5786 _ = try self.addInst(.{
...@@ -5823,7 +5823,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I...@@ -5823,7 +5823,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
5823 // sub src_reg, fp, #off5823 // sub src_reg, fp, #off
5824 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });5824 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
5825 },5825 },
5826 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }),5826 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(addr) }),
5827 .stack_argument_offset => |off| {5827 .stack_argument_offset => |off| {
5828 _ = try self.addInst(.{5828 _ = try self.addInst(.{
5829 .tag = .ldr_ptr_stack_argument,5829 .tag = .ldr_ptr_stack_argument,
...@@ -5867,13 +5867,13 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I...@@ -5867,13 +5867,13 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
5867}5867}
58685868
5869fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {5869fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
5870 const un_op = self.air.instructions.items(.data)[inst].un_op;5870 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5871 const result = try self.resolveInst(un_op);5871 const result = try self.resolveInst(un_op);
5872 return self.finishAir(inst, result, .{ un_op, .none, .none });5872 return self.finishAir(inst, result, .{ un_op, .none, .none });
5873}5873}
58745874
5875fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {5875fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
5876 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5876 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5877 const result = if (self.liveness.isUnused(inst)) .dead else result: {5877 const result = if (self.liveness.isUnused(inst)) .dead else result: {
5878 const operand = try self.resolveInst(ty_op.operand);5878 const operand = try self.resolveInst(ty_op.operand);
5879 if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand;5879 if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand;
...@@ -5897,12 +5897,12 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -5897,12 +5897,12 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
58975897
5898fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {5898fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5899 const mod = self.bin_file.options.module.?;5899 const mod = self.bin_file.options.module.?;
5900 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5900 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5901 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {5901 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
5902 const ptr_ty = self.typeOf(ty_op.operand);5902 const ptr_ty = self.typeOf(ty_op.operand);
5903 const ptr = try self.resolveInst(ty_op.operand);5903 const ptr = try self.resolveInst(ty_op.operand);
5904 const array_ty = ptr_ty.childType(mod);5904 const array_ty = ptr_ty.childType(mod);
5905 const array_len = @as(u32, @intCast(array_ty.arrayLen(mod)));5905 const array_len: u32 = @intCast(array_ty.arrayLen(mod));
59065906
5907 const stack_offset = try self.allocMem(8, .@"8", inst);5907 const stack_offset = try self.allocMem(8, .@"8", inst);
5908 try self.genSetStack(ptr_ty, stack_offset, ptr);5908 try self.genSetStack(ptr_ty, stack_offset, ptr);
...@@ -5913,7 +5913,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -5913,7 +5913,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5913}5913}
59145914
5915fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {5915fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
5916 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5916 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5917 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{5917 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
5918 self.target.cpu.arch,5918 self.target.cpu.arch,
5919 });5919 });
...@@ -5921,7 +5921,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {...@@ -5921,7 +5921,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
5921}5921}
59225922
5923fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {5923fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
5924 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5924 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5925 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{5925 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
5926 self.target.cpu.arch,5926 self.target.cpu.arch,
5927 });5927 });
...@@ -5929,7 +5929,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {...@@ -5929,7 +5929,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
5929}5929}
59305930
5931fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {5931fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
5932 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5932 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5933 const extra = self.air.extraData(Air.Block, ty_pl.payload);5933 const extra = self.air.extraData(Air.Block, ty_pl.payload);
5934 _ = extra;5934 _ = extra;
59355935
...@@ -5970,7 +5970,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {...@@ -5970,7 +5970,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
5970}5970}
59715971
5972fn airTagName(self: *Self, inst: Air.Inst.Index) !void {5972fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
5973 const un_op = self.air.instructions.items(.data)[inst].un_op;5973 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5974 const operand = try self.resolveInst(un_op);5974 const operand = try self.resolveInst(un_op);
5975 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {5975 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
5976 _ = operand;5976 _ = operand;
...@@ -5980,7 +5980,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {...@@ -5980,7 +5980,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
5980}5980}
59815981
5982fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {5982fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
5983 const un_op = self.air.instructions.items(.data)[inst].un_op;5983 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5984 const operand = try self.resolveInst(un_op);5984 const operand = try self.resolveInst(un_op);
5985 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {5985 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
5986 _ = operand;5986 _ = operand;
...@@ -5990,26 +5990,26 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {...@@ -5990,26 +5990,26 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
5990}5990}
59915991
5992fn airSplat(self: *Self, inst: Air.Inst.Index) !void {5992fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
5993 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5993 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5994 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for arm", .{});5994 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for arm", .{});
5995 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });5995 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
5996}5996}
59975997
5998fn airSelect(self: *Self, inst: Air.Inst.Index) !void {5998fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
5999 const pl_op = self.air.instructions.items(.data)[inst].pl_op;5999 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6000 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;6000 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
6001 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for arm", .{});6001 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for arm", .{});
6002 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });6002 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
6003}6003}
60046004
6005fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {6005fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
6006 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6006 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6007 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for arm", .{});6007 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for arm", .{});
6008 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });6008 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
6009}6009}
60106010
6011fn airReduce(self: *Self, inst: Air.Inst.Index) !void {6011fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
6012 const reduce = self.air.instructions.items(.data)[inst].reduce;6012 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
6013 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for arm", .{});6013 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for arm", .{});
6014 return self.finishAir(inst, result, .{ reduce.operand, .none, .none });6014 return self.finishAir(inst, result, .{ reduce.operand, .none, .none });
6015}6015}
...@@ -6018,8 +6018,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6018,8 +6018,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6018 const mod = self.bin_file.options.module.?;6018 const mod = self.bin_file.options.module.?;
6019 const vector_ty = self.typeOfIndex(inst);6019 const vector_ty = self.typeOfIndex(inst);
6020 const len = vector_ty.vectorLen(mod);6020 const len = vector_ty.vectorLen(mod);
6021 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6021 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6022 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));6022 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
6023 const result: MCValue = res: {6023 const result: MCValue = res: {
6024 if (self.liveness.isUnused(inst)) break :res MCValue.dead;6024 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
6025 return self.fail("TODO implement airAggregateInit for arm", .{});6025 return self.fail("TODO implement airAggregateInit for arm", .{});
...@@ -6038,7 +6038,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6038,7 +6038,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6038}6038}
60396039
6040fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {6040fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
6041 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6041 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6042 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;6042 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
6043 _ = extra;6043 _ = extra;
60446044
...@@ -6046,12 +6046,12 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6046,12 +6046,12 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
6046}6046}
60476047
6048fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {6048fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {
6049 const prefetch = self.air.instructions.items(.data)[inst].prefetch;6049 const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
6050 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });6050 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });
6051}6051}
60526052
6053fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {6053fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
6054 const pl_op = self.air.instructions.items(.data)[inst].pl_op;6054 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6055 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;6055 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
6056 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {6056 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
6057 return self.fail("TODO implement airMulAdd for arm", .{});6057 return self.fail("TODO implement airMulAdd for arm", .{});
...@@ -6060,14 +6060,14 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -6060,14 +6060,14 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
6060}6060}
60616061
6062fn airTry(self: *Self, inst: Air.Inst.Index) !void {6062fn airTry(self: *Self, inst: Air.Inst.Index) !void {
6063 const pl_op = self.air.instructions.items(.data)[inst].pl_op;6063 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6064 const extra = self.air.extraData(Air.Try, pl_op.payload);6064 const extra = self.air.extraData(Air.Try, pl_op.payload);
6065 const body = self.air.extra[extra.end..][0..extra.data.body_len];6065 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
6066 const result: MCValue = result: {6066 const result: MCValue = result: {
6067 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };6067 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
6068 const error_union_ty = self.typeOf(pl_op.operand);6068 const error_union_ty = self.typeOf(pl_op.operand);
6069 const mod = self.bin_file.options.module.?;6069 const mod = self.bin_file.options.module.?;
6070 const error_union_size = @as(u32, @intCast(error_union_ty.abiSize(mod)));6070 const error_union_size: u32 = @intCast(error_union_ty.abiSize(mod));
6071 const error_union_align = error_union_ty.abiAlignment(mod);6071 const error_union_align = error_union_ty.abiAlignment(mod);
60726072
6073 // The error union will die in the body. However, we need the6073 // The error union will die in the body. However, we need the
...@@ -6088,7 +6088,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {...@@ -6088,7 +6088,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
6088}6088}
60896089
6090fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {6090fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {
6091 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6091 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6092 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);6092 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
6093 const body = self.air.extra[extra.end..][0..extra.data.body_len];6093 const body = self.air.extra[extra.end..][0..extra.data.body_len];
6094 _ = body;6094 _ = body;
...@@ -6104,7 +6104,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {...@@ -6104,7 +6104,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
6104 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod))6104 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod))
6105 return MCValue{ .none = {} };6105 return MCValue{ .none = {} };
61066106
6107 const inst_index = Air.refToIndex(inst) orelse return self.genTypedValue(.{6107 const inst_index = inst.toIndex() orelse return self.genTypedValue(.{
6108 .ty = inst_ty,6108 .ty = inst_ty,
6109 .val = (try self.air.value(inst, mod)).?,6109 .val = (try self.air.value(inst, mod)).?,
6110 });6110 });
...@@ -6136,7 +6136,7 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {...@@ -6136,7 +6136,7 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
6136 .none => .none,6136 .none => .none,
6137 .undef => .undef,6137 .undef => .undef,
6138 .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO6138 .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO
6139 .immediate => |imm| .{ .immediate = @as(u32, @truncate(imm)) },6139 .immediate => |imm| .{ .immediate = @truncate(imm) },
6140 .memory => |addr| .{ .memory = addr },6140 .memory => |addr| .{ .memory = addr },
6141 },6141 },
6142 .fail => |msg| {6142 .fail => |msg| {
...@@ -6194,7 +6194,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6194,7 +6194,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6194 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {6194 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
6195 result.return_value = .{ .none = {} };6195 result.return_value = .{ .none = {} };
6196 } else {6196 } else {
6197 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));6197 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(mod));
6198 // TODO handle cases where multiple registers are used6198 // TODO handle cases where multiple registers are used
6199 if (ret_ty_size <= 4) {6199 if (ret_ty_size <= 4) {
6200 result.return_value = .{ .register = c_abi_int_return_regs[0] };6200 result.return_value = .{ .register = c_abi_int_return_regs[0] };
...@@ -6212,7 +6212,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6212,7 +6212,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6212 if (Type.fromInterned(ty).abiAlignment(mod) == .@"8")6212 if (Type.fromInterned(ty).abiAlignment(mod) == .@"8")
6213 ncrn = std.mem.alignForward(usize, ncrn, 2);6213 ncrn = std.mem.alignForward(usize, ncrn, 2);
62146214
6215 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(mod)));6215 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(mod));
6216 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {6216 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {
6217 if (param_size <= 4) {6217 if (param_size <= 4) {
6218 result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] };6218 result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] };
...@@ -6241,7 +6241,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6241,7 +6241,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6241 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {6241 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {
6242 result.return_value = .{ .none = {} };6242 result.return_value = .{ .none = {} };
6243 } else {6243 } else {
6244 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));6244 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(mod));
6245 if (ret_ty_size == 0) {6245 if (ret_ty_size == 0) {
6246 assert(ret_ty.isError(mod));6246 assert(ret_ty.isError(mod));
6247 result.return_value = .{ .immediate = 0 };6247 result.return_value = .{ .immediate = 0 };
src/arch/riscv64/CodeGen.zig+129-129
...@@ -198,7 +198,7 @@ const BigTomb = struct {...@@ -198,7 +198,7 @@ const BigTomb = struct {
198198
199 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {199 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {
200 const dies = bt.lbt.feed();200 const dies = bt.lbt.feed();
201 const op_index = Air.refToIndex(op_ref) orelse return;201 const op_index = op_ref.toIndex() orelse return;
202 if (!dies) return;202 if (!dies) return;
203 bt.function.processDeath(op_index);203 bt.function.processDeath(op_index);
204 }204 }
...@@ -325,7 +325,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {...@@ -325,7 +325,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
325325
326 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);326 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
327327
328 const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len));328 const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len);
329 self.mir_instructions.appendAssumeCapacity(inst);329 self.mir_instructions.appendAssumeCapacity(inst);
330 return result_index;330 return result_index;
331}331}
...@@ -338,11 +338,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {...@@ -338,11 +338,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
338338
339pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {339pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
340 const fields = std.meta.fields(@TypeOf(extra));340 const fields = std.meta.fields(@TypeOf(extra));
341 const result = @as(u32, @intCast(self.mir_extra.items.len));341 const result: u32 = @intCast(self.mir_extra.items.len);
342 inline for (fields) |field| {342 inline for (fields) |field| {
343 self.mir_extra.appendAssumeCapacity(switch (field.type) {343 self.mir_extra.appendAssumeCapacity(switch (field.type) {
344 u32 => @field(extra, field.name),344 u32 => @field(extra, field.name),
345 i32 => @as(u32, @bitCast(@field(extra, field.name))),345 i32 => @bitCast(@field(extra, field.name)),
346 else => @compileError("bad field type"),346 else => @compileError("bad field type"),
347 });347 });
348 }348 }
...@@ -486,7 +486,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -486,7 +486,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
486 const old_air_bookkeeping = self.air_bookkeeping;486 const old_air_bookkeeping = self.air_bookkeeping;
487 try self.ensureProcessDeathCapacity(Liveness.bpi);487 try self.ensureProcessDeathCapacity(Liveness.bpi);
488488
489 switch (air_tags[inst]) {489 switch (air_tags[@intFromEnum(inst)]) {
490 // zig fmt: off490 // zig fmt: off
491 .ptr_add => try self.airPtrArithmetic(inst, .ptr_add),491 .ptr_add => try self.airPtrArithmetic(inst, .ptr_add),
492 .ptr_sub => try self.airPtrArithmetic(inst, .ptr_sub),492 .ptr_sub => try self.airPtrArithmetic(inst, .ptr_sub),
...@@ -725,7 +725,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -725,7 +725,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
725 }725 }
726 if (std.debug.runtime_safety) {726 if (std.debug.runtime_safety) {
727 if (self.air_bookkeeping < old_air_bookkeeping + 1) {727 if (self.air_bookkeeping < old_air_bookkeeping + 1) {
728 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] });728 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] });
729 }729 }
730 }730 }
731 }731 }
...@@ -758,7 +758,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live...@@ -758,7 +758,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
758 const dies = @as(u1, @truncate(tomb_bits)) != 0;758 const dies = @as(u1, @truncate(tomb_bits)) != 0;
759 tomb_bits >>= 1;759 tomb_bits >>= 1;
760 if (!dies) continue;760 if (!dies) continue;
761 const op_index = Air.refToIndex(op) orelse continue;761 const op_index = op.toIndex() orelse continue;
762 self.processDeath(op_index);762 self.processDeath(op_index);
763 }763 }
764 const is_used = @as(u1, @truncate(tomb_bits)) == 0;764 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
...@@ -877,19 +877,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -877,19 +877,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
877}877}
878878
879fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {879fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
880 const ty_op = self.air.instructions.items(.data)[inst].ty_op;880 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
881 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch});881 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch});
882 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });882 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
883}883}
884884
885fn airFpext(self: *Self, inst: Air.Inst.Index) !void {885fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
886 const ty_op = self.air.instructions.items(.data)[inst].ty_op;886 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
887 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch});887 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch});
888 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });888 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
889}889}
890890
891fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {891fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
892 const ty_op = self.air.instructions.items(.data)[inst].ty_op;892 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
893 if (self.liveness.isUnused(inst))893 if (self.liveness.isUnused(inst))
894 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });894 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
895895
...@@ -909,7 +909,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -909,7 +909,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
909}909}
910910
911fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {911fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
912 const ty_op = self.air.instructions.items(.data)[inst].ty_op;912 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
913 if (self.liveness.isUnused(inst))913 if (self.liveness.isUnused(inst))
914 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });914 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
915915
...@@ -920,32 +920,32 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -920,32 +920,32 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
920}920}
921921
922fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {922fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
923 const un_op = self.air.instructions.items(.data)[inst].un_op;923 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
924 const operand = try self.resolveInst(un_op);924 const operand = try self.resolveInst(un_op);
925 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;925 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
926 return self.finishAir(inst, result, .{ un_op, .none, .none });926 return self.finishAir(inst, result, .{ un_op, .none, .none });
927}927}
928928
929fn airNot(self: *Self, inst: Air.Inst.Index) !void {929fn airNot(self: *Self, inst: Air.Inst.Index) !void {
930 const ty_op = self.air.instructions.items(.data)[inst].ty_op;930 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
931 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement NOT for {}", .{self.target.cpu.arch});931 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement NOT for {}", .{self.target.cpu.arch});
932 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });932 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
933}933}
934934
935fn airMin(self: *Self, inst: Air.Inst.Index) !void {935fn airMin(self: *Self, inst: Air.Inst.Index) !void {
936 const bin_op = self.air.instructions.items(.data)[inst].bin_op;936 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
937 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement min for {}", .{self.target.cpu.arch});937 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement min for {}", .{self.target.cpu.arch});
938 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });938 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
939}939}
940940
941fn airMax(self: *Self, inst: Air.Inst.Index) !void {941fn airMax(self: *Self, inst: Air.Inst.Index) !void {
942 const bin_op = self.air.instructions.items(.data)[inst].bin_op;942 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
943 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement max for {}", .{self.target.cpu.arch});943 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement max for {}", .{self.target.cpu.arch});
944 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });944 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
945}945}
946946
947fn airSlice(self: *Self, inst: Air.Inst.Index) !void {947fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
948 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;948 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
949 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;949 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
950 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice for {}", .{self.target.cpu.arch});950 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice for {}", .{self.target.cpu.arch});
951 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });951 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
...@@ -981,8 +981,8 @@ fn binOpRegister(...@@ -981,8 +981,8 @@ fn binOpRegister(
981981
982 const lhs_reg = if (lhs_is_register) lhs.register else blk: {982 const lhs_reg = if (lhs_is_register) lhs.register else blk: {
983 const track_inst: ?Air.Inst.Index = if (maybe_inst) |inst| inst: {983 const track_inst: ?Air.Inst.Index = if (maybe_inst) |inst| inst: {
984 const bin_op = self.air.instructions.items(.data)[inst].bin_op;984 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
985 break :inst Air.refToIndex(bin_op.lhs).?;985 break :inst bin_op.lhs.toIndex().?;
986 } else null;986 } else null;
987987
988 const reg = try self.register_manager.allocReg(track_inst, gp);988 const reg = try self.register_manager.allocReg(track_inst, gp);
...@@ -996,8 +996,8 @@ fn binOpRegister(...@@ -996,8 +996,8 @@ fn binOpRegister(
996996
997 const rhs_reg = if (rhs_is_register) rhs.register else blk: {997 const rhs_reg = if (rhs_is_register) rhs.register else blk: {
998 const track_inst: ?Air.Inst.Index = if (maybe_inst) |inst| inst: {998 const track_inst: ?Air.Inst.Index = if (maybe_inst) |inst| inst: {
999 const bin_op = self.air.instructions.items(.data)[inst].bin_op;999 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1000 break :inst Air.refToIndex(bin_op.rhs).?;1000 break :inst bin_op.rhs.toIndex().?;
1001 } else null;1001 } else null;
10021002
1003 const reg = try self.register_manager.allocReg(track_inst, gp);1003 const reg = try self.register_manager.allocReg(track_inst, gp);
...@@ -1010,7 +1010,7 @@ fn binOpRegister(...@@ -1010,7 +1010,7 @@ fn binOpRegister(
1010 defer if (new_rhs_lock) |reg| self.register_manager.unlockReg(reg);1010 defer if (new_rhs_lock) |reg| self.register_manager.unlockReg(reg);
10111011
1012 const dest_reg = if (maybe_inst) |inst| blk: {1012 const dest_reg = if (maybe_inst) |inst| blk: {
1013 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1013 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
10141014
1015 if (lhs_is_register and self.reuseOperand(inst, bin_op.lhs, 0, lhs)) {1015 if (lhs_is_register and self.reuseOperand(inst, bin_op.lhs, 0, lhs)) {
1016 break :blk lhs_reg;1016 break :blk lhs_reg;
...@@ -1123,7 +1123,7 @@ fn binOp(...@@ -1123,7 +1123,7 @@ fn binOp(
1123}1123}
11241124
1125fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {1125fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1126 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1126 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1127 const lhs = try self.resolveInst(bin_op.lhs);1127 const lhs = try self.resolveInst(bin_op.lhs);
1128 const rhs = try self.resolveInst(bin_op.rhs);1128 const rhs = try self.resolveInst(bin_op.rhs);
1129 const lhs_ty = self.typeOf(bin_op.lhs);1129 const lhs_ty = self.typeOf(bin_op.lhs);
...@@ -1134,7 +1134,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {...@@ -1134,7 +1134,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1134}1134}
11351135
1136fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {1136fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1137 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1137 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1138 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;1138 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
1139 const lhs = try self.resolveInst(bin_op.lhs);1139 const lhs = try self.resolveInst(bin_op.lhs);
1140 const rhs = try self.resolveInst(bin_op.rhs);1140 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -1146,43 +1146,43 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void...@@ -1146,43 +1146,43 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void
1146}1146}
11471147
1148fn airAddWrap(self: *Self, inst: Air.Inst.Index) !void {1148fn airAddWrap(self: *Self, inst: Air.Inst.Index) !void {
1149 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1149 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1150 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement addwrap for {}", .{self.target.cpu.arch});1150 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement addwrap for {}", .{self.target.cpu.arch});
1151 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1151 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1152}1152}
11531153
1154fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {1154fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
1155 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1155 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1156 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});1156 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});
1157 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1157 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1158}1158}
11591159
1160fn airSubWrap(self: *Self, inst: Air.Inst.Index) !void {1160fn airSubWrap(self: *Self, inst: Air.Inst.Index) !void {
1161 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1161 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1162 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement subwrap for {}", .{self.target.cpu.arch});1162 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement subwrap for {}", .{self.target.cpu.arch});
1163 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1163 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1164}1164}
11651165
1166fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {1166fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
1167 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1167 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1168 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});1168 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});
1169 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1169 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1170}1170}
11711171
1172fn airMul(self: *Self, inst: Air.Inst.Index) !void {1172fn airMul(self: *Self, inst: Air.Inst.Index) !void {
1173 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1173 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1174 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul for {}", .{self.target.cpu.arch});1174 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul for {}", .{self.target.cpu.arch});
1175 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1175 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1176}1176}
11771177
1178fn airMulWrap(self: *Self, inst: Air.Inst.Index) !void {1178fn airMulWrap(self: *Self, inst: Air.Inst.Index) !void {
1179 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1179 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1180 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mulwrap for {}", .{self.target.cpu.arch});1180 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mulwrap for {}", .{self.target.cpu.arch});
1181 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1181 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1182}1182}
11831183
1184fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {1184fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
1185 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1185 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1186 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});1186 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});
1187 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1187 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1188}1188}
...@@ -1208,105 +1208,105 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1208,105 +1208,105 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1208}1208}
12091209
1210fn airDiv(self: *Self, inst: Air.Inst.Index) !void {1210fn airDiv(self: *Self, inst: Air.Inst.Index) !void {
1211 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1211 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1212 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement div for {}", .{self.target.cpu.arch});1212 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement div for {}", .{self.target.cpu.arch});
1213 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1213 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1214}1214}
12151215
1216fn airRem(self: *Self, inst: Air.Inst.Index) !void {1216fn airRem(self: *Self, inst: Air.Inst.Index) !void {
1217 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1217 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1218 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement rem for {}", .{self.target.cpu.arch});1218 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement rem for {}", .{self.target.cpu.arch});
1219 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1219 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1220}1220}
12211221
1222fn airMod(self: *Self, inst: Air.Inst.Index) !void {1222fn airMod(self: *Self, inst: Air.Inst.Index) !void {
1223 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1223 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1224 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mod for {}", .{self.target.cpu.arch});1224 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mod for {}", .{self.target.cpu.arch});
1225 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1225 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1226}1226}
12271227
1228fn airBitAnd(self: *Self, inst: Air.Inst.Index) !void {1228fn airBitAnd(self: *Self, inst: Air.Inst.Index) !void {
1229 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1229 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1230 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement bitwise and for {}", .{self.target.cpu.arch});1230 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement bitwise and for {}", .{self.target.cpu.arch});
1231 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1231 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1232}1232}
12331233
1234fn airBitOr(self: *Self, inst: Air.Inst.Index) !void {1234fn airBitOr(self: *Self, inst: Air.Inst.Index) !void {
1235 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1235 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1236 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement bitwise or for {}", .{self.target.cpu.arch});1236 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement bitwise or for {}", .{self.target.cpu.arch});
1237 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1237 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1238}1238}
12391239
1240fn airXor(self: *Self, inst: Air.Inst.Index) !void {1240fn airXor(self: *Self, inst: Air.Inst.Index) !void {
1241 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1241 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1242 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement xor for {}", .{self.target.cpu.arch});1242 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement xor for {}", .{self.target.cpu.arch});
1243 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1243 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1244}1244}
12451245
1246fn airShl(self: *Self, inst: Air.Inst.Index) !void {1246fn airShl(self: *Self, inst: Air.Inst.Index) !void {
1247 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1247 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1248 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl for {}", .{self.target.cpu.arch});1248 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl for {}", .{self.target.cpu.arch});
1249 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1249 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1250}1250}
12511251
1252fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {1252fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
1253 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1253 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1254 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});1254 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
1255 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1255 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1256}1256}
12571257
1258fn airShr(self: *Self, inst: Air.Inst.Index) !void {1258fn airShr(self: *Self, inst: Air.Inst.Index) !void {
1259 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1259 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1260 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shr for {}", .{self.target.cpu.arch});1260 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shr for {}", .{self.target.cpu.arch});
1261 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1261 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1262}1262}
12631263
1264fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {1264fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
1265 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1265 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1266 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch});1266 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch});
1267 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1267 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1268}1268}
12691269
1270fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {1270fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
1271 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1271 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1272 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});1272 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});
1273 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1273 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1274}1274}
12751275
1276fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {1276fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
1277 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1277 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1278 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});1278 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});
1279 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1279 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1280}1280}
12811281
1282fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {1282fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
1283 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1283 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1284 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error for {}", .{self.target.cpu.arch});1284 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error for {}", .{self.target.cpu.arch});
1285 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1285 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1286}1286}
12871287
1288fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {1288fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
1289 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1289 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1290 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload for {}", .{self.target.cpu.arch});1290 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload for {}", .{self.target.cpu.arch});
1291 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1291 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1292}1292}
12931293
1294// *(E!T) -> E1294// *(E!T) -> E
1295fn airUnwrapErrErrPtr(self: *Self, inst: Air.Inst.Index) !void {1295fn airUnwrapErrErrPtr(self: *Self, inst: Air.Inst.Index) !void {
1296 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1296 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1297 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error ptr for {}", .{self.target.cpu.arch});1297 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error ptr for {}", .{self.target.cpu.arch});
1298 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1298 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1299}1299}
13001300
1301// *(E!T) -> *T1301// *(E!T) -> *T
1302fn airUnwrapErrPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {1302fn airUnwrapErrPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
1303 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1303 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1304 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload ptr for {}", .{self.target.cpu.arch});1304 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload ptr for {}", .{self.target.cpu.arch});
1305 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1305 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1306}1306}
13071307
1308fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {1308fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
1309 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1309 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1310 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});1310 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});
1311 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1311 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1312}1312}
...@@ -1330,7 +1330,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {...@@ -1330,7 +1330,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
1330}1330}
13311331
1332fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {1332fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
1333 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1333 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1334 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1334 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1335 const mod = self.bin_file.options.module.?;1335 const mod = self.bin_file.options.module.?;
1336 const optional_ty = self.typeOfIndex(inst);1336 const optional_ty = self.typeOfIndex(inst);
...@@ -1346,127 +1346,127 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -1346,127 +1346,127 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
13461346
1347/// T to E!T1347/// T to E!T
1348fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {1348fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
1349 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1349 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1350 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion payload for {}", .{self.target.cpu.arch});1350 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion payload for {}", .{self.target.cpu.arch});
1351 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1351 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1352}1352}
13531353
1354/// E to E!T1354/// E to E!T
1355fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {1355fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
1356 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1356 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1357 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion error for {}", .{self.target.cpu.arch});1357 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion error for {}", .{self.target.cpu.arch});
1358 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1358 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1359}1359}
13601360
1361fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {1361fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
1362 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1362 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1363 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_ptr for {}", .{self.target.cpu.arch});1363 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_ptr for {}", .{self.target.cpu.arch});
1364 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1364 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1365}1365}
13661366
1367fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {1367fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
1368 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1368 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1369 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_len for {}", .{self.target.cpu.arch});1369 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_len for {}", .{self.target.cpu.arch});
1370 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1370 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1371}1371}
13721372
1373fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {1373fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
1374 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1374 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1375 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_len_ptr for {}", .{self.target.cpu.arch});1375 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_len_ptr for {}", .{self.target.cpu.arch});
1376 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1376 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1377}1377}
13781378
1379fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {1379fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
1380 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1380 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1381 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_ptr_ptr for {}", .{self.target.cpu.arch});1381 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_ptr_ptr for {}", .{self.target.cpu.arch});
1382 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1382 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1383}1383}
13841384
1385fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {1385fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
1386 const is_volatile = false; // TODO1386 const is_volatile = false; // TODO
1387 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1387 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1388 const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_elem_val for {}", .{self.target.cpu.arch});1388 const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_elem_val for {}", .{self.target.cpu.arch});
1389 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1389 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1390}1390}
13911391
1392fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {1392fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
1393 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1393 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1394 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;1394 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
1395 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_elem_ptr for {}", .{self.target.cpu.arch});1395 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_elem_ptr for {}", .{self.target.cpu.arch});
1396 return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });1396 return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
1397}1397}
13981398
1399fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {1399fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
1400 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1400 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1401 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch});1401 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch});
1402 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1402 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1403}1403}
14041404
1405fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {1405fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
1406 const is_volatile = false; // TODO1406 const is_volatile = false; // TODO
1407 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1407 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1408 const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_val for {}", .{self.target.cpu.arch});1408 const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_val for {}", .{self.target.cpu.arch});
1409 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1409 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1410}1410}
14111411
1412fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {1412fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
1413 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1413 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1414 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;1414 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
1415 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_ptr for {}", .{self.target.cpu.arch});1415 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_ptr for {}", .{self.target.cpu.arch});
1416 return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });1416 return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
1417}1417}
14181418
1419fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {1419fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
1420 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1420 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1421 _ = bin_op;1421 _ = bin_op;
1422 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});1422 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});
1423 // return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1423 // return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1424}1424}
14251425
1426fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {1426fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
1427 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1427 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1428 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});1428 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});
1429 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1429 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1430}1430}
14311431
1432fn airClz(self: *Self, inst: Air.Inst.Index) !void {1432fn airClz(self: *Self, inst: Air.Inst.Index) !void {
1433 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1433 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1434 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});1434 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});
1435 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1435 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1436}1436}
14371437
1438fn airCtz(self: *Self, inst: Air.Inst.Index) !void {1438fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
1439 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1439 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1440 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});1440 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});
1441 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1441 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1442}1442}
14431443
1444fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {1444fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
1445 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1445 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1446 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});1446 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});
1447 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1447 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1448}1448}
14491449
1450fn airAbs(self: *Self, inst: Air.Inst.Index) !void {1450fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
1451 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1451 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1452 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch});1452 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch});
1453 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1453 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1454}1454}
14551455
1456fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {1456fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
1457 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1457 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1458 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch});1458 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch});
1459 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1459 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1460}1460}
14611461
1462fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {1462fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
1463 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1463 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1464 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});1464 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});
1465 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1465 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1466}1466}
14671467
1468fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {1468fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {
1469 const un_op = self.air.instructions.items(.data)[inst].un_op;1469 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1470 const result: MCValue = if (self.liveness.isUnused(inst))1470 const result: MCValue = if (self.liveness.isUnused(inst))
1471 .dead1471 .dead
1472 else1472 else
...@@ -1500,7 +1500,7 @@ fn reuseOperand(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, op_ind...@@ -1500,7 +1500,7 @@ fn reuseOperand(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, op_ind
15001500
1501 // That makes us responsible for doing the rest of the stuff that processDeath would have done.1501 // That makes us responsible for doing the rest of the stuff that processDeath would have done.
1502 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];1502 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
1503 branch.inst_table.putAssumeCapacity(Air.refToIndex(operand).?, .dead);1503 branch.inst_table.putAssumeCapacity(operand.toIndex().?, .dead);
15041504
1505 return true;1505 return true;
1506}1506}
...@@ -1533,7 +1533,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo...@@ -1533,7 +1533,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
15331533
1534fn airLoad(self: *Self, inst: Air.Inst.Index) !void {1534fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
1535 const mod = self.bin_file.options.module.?;1535 const mod = self.bin_file.options.module.?;
1536 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1536 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1537 const elem_ty = self.typeOfIndex(inst);1537 const elem_ty = self.typeOfIndex(inst);
1538 const result: MCValue = result: {1538 const result: MCValue = result: {
1539 if (!elem_ty.hasRuntimeBits(mod))1539 if (!elem_ty.hasRuntimeBits(mod))
...@@ -1590,7 +1590,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -1590,7 +1590,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1590 } else {1590 } else {
1591 // TODO if the value is undef, don't lower this instruction1591 // TODO if the value is undef, don't lower this instruction
1592 }1592 }
1593 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1593 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1594 const ptr = try self.resolveInst(bin_op.lhs);1594 const ptr = try self.resolveInst(bin_op.lhs);
1595 const value = try self.resolveInst(bin_op.rhs);1595 const value = try self.resolveInst(bin_op.rhs);
1596 const ptr_ty = self.typeOf(bin_op.lhs);1596 const ptr_ty = self.typeOf(bin_op.lhs);
...@@ -1602,13 +1602,13 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -1602,13 +1602,13 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1602}1602}
16031603
1604fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {1604fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {
1605 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1605 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1606 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;1606 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
1607 return self.structFieldPtr(extra.struct_operand, ty_pl.ty, extra.field_index);1607 return self.structFieldPtr(extra.struct_operand, ty_pl.ty, extra.field_index);
1608}1608}
16091609
1610fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {1610fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
1611 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1611 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1612 return self.structFieldPtr(ty_op.operand, ty_op.ty, index);1612 return self.structFieldPtr(ty_op.operand, ty_op.ty, index);
1613}1613}
1614fn structFieldPtr(self: *Self, operand: Air.Inst.Ref, ty: Air.Inst.Ref, index: u32) !void {1614fn structFieldPtr(self: *Self, operand: Air.Inst.Ref, ty: Air.Inst.Ref, index: u32) !void {
...@@ -1620,7 +1620,7 @@ fn structFieldPtr(self: *Self, operand: Air.Inst.Ref, ty: Air.Inst.Ref, index: u...@@ -1620,7 +1620,7 @@ fn structFieldPtr(self: *Self, operand: Air.Inst.Ref, ty: Air.Inst.Ref, index: u
1620}1620}
16211621
1622fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {1622fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
1623 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1623 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1624 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;1624 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
1625 _ = extra;1625 _ = extra;
1626 return self.fail("TODO implement codegen struct_field_val", .{});1626 return self.fail("TODO implement codegen struct_field_val", .{});
...@@ -1634,8 +1634,8 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1634,8 +1634,8 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
16341634
1635fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {1635fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {
1636 const mod = self.bin_file.options.module.?;1636 const mod = self.bin_file.options.module.?;
1637 const arg = self.air.instructions.items(.data)[inst].arg;1637 const arg = self.air.instructions.items(.data)[@intFromEnum(inst)].arg;
1638 const ty = self.air.getRefType(arg.ty);1638 const ty = arg.ty.toType();
1639 const owner_decl = mod.funcOwnerDeclIndex(self.func_index);1639 const owner_decl = mod.funcOwnerDeclIndex(self.func_index);
1640 const name = mod.getParamName(self.func_index, arg.src_index);1640 const name = mod.getParamName(self.func_index, arg.src_index);
16411641
...@@ -1712,11 +1712,11 @@ fn airFence(self: *Self) !void {...@@ -1712,11 +1712,11 @@ fn airFence(self: *Self) !void {
1712fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {1712fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
1713 const mod = self.bin_file.options.module.?;1713 const mod = self.bin_file.options.module.?;
1714 if (modifier == .always_tail) return self.fail("TODO implement tail calls for riscv64", .{});1714 if (modifier == .always_tail) return self.fail("TODO implement tail calls for riscv64", .{});
1715 const pl_op = self.air.instructions.items(.data)[inst].pl_op;1715 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1716 const fn_ty = self.typeOf(pl_op.operand);1716 const fn_ty = self.typeOf(pl_op.operand);
1717 const callee = pl_op.operand;1717 const callee = pl_op.operand;
1718 const extra = self.air.extraData(Air.Call, pl_op.payload);1718 const extra = self.air.extraData(Air.Call, pl_op.payload);
1719 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));1719 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
17201720
1721 var info = try self.resolveCallingConventionValues(fn_ty);1721 var info = try self.resolveCallingConventionValues(fn_ty);
1722 defer info.deinit(self);1722 defer info.deinit(self);
...@@ -1755,7 +1755,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1755,7 +1755,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1755 const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl);1755 const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl);
1756 const sym = elf_file.symbol(sym_index);1756 const sym = elf_file.symbol(sym_index);
1757 _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);1757 _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);
1758 const got_addr = @as(u32, @intCast(sym.zigGotAddress(elf_file)));1758 const got_addr: u32 = @intCast(sym.zigGotAddress(elf_file));
1759 try self.genSetReg(Type.usize, .ra, .{ .memory = got_addr });1759 try self.genSetReg(Type.usize, .ra, .{ .memory = got_addr });
1760 _ = try self.addInst(.{1760 _ = try self.addInst(.{
1761 .tag = .jalr,1761 .tag = .jalr,
...@@ -1824,14 +1824,14 @@ fn ret(self: *Self, mcv: MCValue) !void {...@@ -1824,14 +1824,14 @@ fn ret(self: *Self, mcv: MCValue) !void {
1824}1824}
18251825
1826fn airRet(self: *Self, inst: Air.Inst.Index) !void {1826fn airRet(self: *Self, inst: Air.Inst.Index) !void {
1827 const un_op = self.air.instructions.items(.data)[inst].un_op;1827 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1828 const operand = try self.resolveInst(un_op);1828 const operand = try self.resolveInst(un_op);
1829 try self.ret(operand);1829 try self.ret(operand);
1830 return self.finishAir(inst, .dead, .{ un_op, .none, .none });1830 return self.finishAir(inst, .dead, .{ un_op, .none, .none });
1831}1831}
18321832
1833fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {1833fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
1834 const un_op = self.air.instructions.items(.data)[inst].un_op;1834 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1835 const ptr = try self.resolveInst(un_op);1835 const ptr = try self.resolveInst(un_op);
1836 _ = ptr;1836 _ = ptr;
1837 return self.fail("TODO implement airRetLoad for {}", .{self.target.cpu.arch});1837 return self.fail("TODO implement airRetLoad for {}", .{self.target.cpu.arch});
...@@ -1839,7 +1839,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -1839,7 +1839,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
1839}1839}
18401840
1841fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {1841fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1842 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1842 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1843 if (self.liveness.isUnused(inst))1843 if (self.liveness.isUnused(inst))
1844 return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });1844 return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
1845 const ty = self.typeOf(bin_op.lhs);1845 const ty = self.typeOf(bin_op.lhs);
...@@ -1864,7 +1864,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {...@@ -1864,7 +1864,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
1864}1864}
18651865
1866fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {1866fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
1867 const un_op = self.air.instructions.items(.data)[inst].un_op;1867 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1868 const operand = try self.resolveInst(un_op);1868 const operand = try self.resolveInst(un_op);
1869 _ = operand;1869 _ = operand;
1870 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch});1870 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch});
...@@ -1872,7 +1872,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -1872,7 +1872,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
1872}1872}
18731873
1874fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {1874fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
1875 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;1875 const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
18761876
1877 _ = try self.addInst(.{1877 _ = try self.addInst(.{
1878 .tag = .dbg_line,1878 .tag = .dbg_line,
...@@ -1886,7 +1886,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {...@@ -1886,7 +1886,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
1886}1886}
18871887
1888fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {1888fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
1889 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;1889 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
1890 const mod = self.bin_file.options.module.?;1890 const mod = self.bin_file.options.module.?;
1891 const func = mod.funcInfo(ty_fn.func);1891 const func = mod.funcInfo(ty_fn.func);
1892 // TODO emit debug info for function change1892 // TODO emit debug info for function change
...@@ -1900,7 +1900,7 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -1900,7 +1900,7 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
1900}1900}
19011901
1902fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {1902fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
1903 const pl_op = self.air.instructions.items(.data)[inst].pl_op;1903 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1904 const name = self.air.nullTerminatedString(pl_op.payload);1904 const name = self.air.nullTerminatedString(pl_op.payload);
1905 const operand = pl_op.operand;1905 const operand = pl_op.operand;
1906 // TODO emit debug info for this variable1906 // TODO emit debug info for this variable
...@@ -1944,7 +1944,7 @@ fn isNonErr(self: *Self, operand: MCValue) !MCValue {...@@ -1944,7 +1944,7 @@ fn isNonErr(self: *Self, operand: MCValue) !MCValue {
1944}1944}
19451945
1946fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {1946fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
1947 const un_op = self.air.instructions.items(.data)[inst].un_op;1947 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1948 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1948 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1949 const operand = try self.resolveInst(un_op);1949 const operand = try self.resolveInst(un_op);
1950 break :result try self.isNull(operand);1950 break :result try self.isNull(operand);
...@@ -1953,7 +1953,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -1953,7 +1953,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
1953}1953}
19541954
1955fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {1955fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
1956 const un_op = self.air.instructions.items(.data)[inst].un_op;1956 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1957 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1957 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1958 const operand_ptr = try self.resolveInst(un_op);1958 const operand_ptr = try self.resolveInst(un_op);
1959 const operand: MCValue = blk: {1959 const operand: MCValue = blk: {
...@@ -1971,7 +1971,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1971,7 +1971,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
1971}1971}
19721972
1973fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {1973fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
1974 const un_op = self.air.instructions.items(.data)[inst].un_op;1974 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1975 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1975 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1976 const operand = try self.resolveInst(un_op);1976 const operand = try self.resolveInst(un_op);
1977 break :result try self.isNonNull(operand);1977 break :result try self.isNonNull(operand);
...@@ -1980,7 +1980,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -1980,7 +1980,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
1980}1980}
19811981
1982fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {1982fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
1983 const un_op = self.air.instructions.items(.data)[inst].un_op;1983 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1984 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1984 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1985 const operand_ptr = try self.resolveInst(un_op);1985 const operand_ptr = try self.resolveInst(un_op);
1986 const operand: MCValue = blk: {1986 const operand: MCValue = blk: {
...@@ -1998,7 +1998,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1998,7 +1998,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
1998}1998}
19991999
2000fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {2000fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
2001 const un_op = self.air.instructions.items(.data)[inst].un_op;2001 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2002 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2002 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2003 const operand = try self.resolveInst(un_op);2003 const operand = try self.resolveInst(un_op);
2004 break :result try self.isErr(operand);2004 break :result try self.isErr(operand);
...@@ -2007,7 +2007,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2007,7 +2007,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
2007}2007}
20082008
2009fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {2009fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
2010 const un_op = self.air.instructions.items(.data)[inst].un_op;2010 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2011 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2011 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2012 const operand_ptr = try self.resolveInst(un_op);2012 const operand_ptr = try self.resolveInst(un_op);
2013 const operand: MCValue = blk: {2013 const operand: MCValue = blk: {
...@@ -2025,7 +2025,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2025,7 +2025,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
2025}2025}
20262026
2027fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {2027fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
2028 const un_op = self.air.instructions.items(.data)[inst].un_op;2028 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2029 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2029 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2030 const operand = try self.resolveInst(un_op);2030 const operand = try self.resolveInst(un_op);
2031 break :result try self.isNonErr(operand);2031 break :result try self.isNonErr(operand);
...@@ -2034,7 +2034,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2034,7 +2034,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
2034}2034}
20352035
2036fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {2036fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
2037 const un_op = self.air.instructions.items(.data)[inst].un_op;2037 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2038 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2038 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2039 const operand_ptr = try self.resolveInst(un_op);2039 const operand_ptr = try self.resolveInst(un_op);
2040 const operand: MCValue = blk: {2040 const operand: MCValue = blk: {
...@@ -2053,9 +2053,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2053,9 +2053,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
20532053
2054fn airLoop(self: *Self, inst: Air.Inst.Index) !void {2054fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
2055 // A loop is a setup to be able to jump back to the beginning.2055 // A loop is a setup to be able to jump back to the beginning.
2056 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2056 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2057 const loop = self.air.extraData(Air.Block, ty_pl.payload);2057 const loop = self.air.extraData(Air.Block, ty_pl.payload);
2058 const body = self.air.extra[loop.end..][0..loop.data.body_len];2058 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);
2059 const start_index = self.code.items.len;2059 const start_index = self.code.items.len;
2060 try self.genBody(body);2060 try self.genBody(body);
2061 try self.jump(start_index);2061 try self.jump(start_index);
...@@ -2081,9 +2081,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -2081,9 +2081,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
2081 });2081 });
2082 defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa);2082 defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa);
20832083
2084 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2084 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2085 const extra = self.air.extraData(Air.Block, ty_pl.payload);2085 const extra = self.air.extraData(Air.Block, ty_pl.payload);
2086 const body = self.air.extra[extra.end..][0..extra.data.body_len];2086 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
2087 try self.genBody(body);2087 try self.genBody(body);
20882088
2089 for (self.blocks.getPtr(inst).?.relocs.items) |reloc| try self.performReloc(reloc);2089 for (self.blocks.getPtr(inst).?.relocs.items) |reloc| try self.performReloc(reloc);
...@@ -2093,7 +2093,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -2093,7 +2093,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
2093}2093}
20942094
2095fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {2095fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
2096 const pl_op = self.air.instructions.items(.data)[inst].pl_op;2096 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
2097 const condition = pl_op.operand;2097 const condition = pl_op.operand;
2098 _ = condition;2098 _ = condition;
2099 return self.fail("TODO airSwitch for {}", .{self.target.cpu.arch});2099 return self.fail("TODO airSwitch for {}", .{self.target.cpu.arch});
...@@ -2109,13 +2109,13 @@ fn performReloc(self: *Self, reloc: Reloc) !void {...@@ -2109,13 +2109,13 @@ fn performReloc(self: *Self, reloc: Reloc) !void {
2109}2109}
21102110
2111fn airBr(self: *Self, inst: Air.Inst.Index) !void {2111fn airBr(self: *Self, inst: Air.Inst.Index) !void {
2112 const branch = self.air.instructions.items(.data)[inst].br;2112 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
2113 try self.br(branch.block_inst, branch.operand);2113 try self.br(branch.block_inst, branch.operand);
2114 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });2114 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });
2115}2115}
21162116
2117fn airBoolOp(self: *Self, inst: Air.Inst.Index) !void {2117fn airBoolOp(self: *Self, inst: Air.Inst.Index) !void {
2118 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2118 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2119 const air_tags = self.air.instructions.items(.tag);2119 const air_tags = self.air.instructions.items(.tag);
2120 _ = air_tags;2120 _ = air_tags;
2121 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement boolean operations for {}", .{self.target.cpu.arch});2121 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement boolean operations for {}", .{self.target.cpu.arch});
...@@ -2148,14 +2148,14 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {...@@ -2148,14 +2148,14 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
2148}2148}
21492149
2150fn airAsm(self: *Self, inst: Air.Inst.Index) !void {2150fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
2151 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2151 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2152 const extra = self.air.extraData(Air.Asm, ty_pl.payload);2152 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
2153 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;2153 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
2154 const clobbers_len = @as(u31, @truncate(extra.data.flags));2154 const clobbers_len: u31 = @truncate(extra.data.flags);
2155 var extra_i: usize = extra.end;2155 var extra_i: usize = extra.end;
2156 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));2156 const outputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]);
2157 extra_i += outputs.len;2157 extra_i += outputs.len;
2158 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));2158 const inputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]);
2159 extra_i += inputs.len;2159 extra_i += inputs.len;
21602160
2161 const dead = !is_volatile and self.liveness.isUnused(inst);2161 const dead = !is_volatile and self.liveness.isUnused(inst);
...@@ -2300,20 +2300,20 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -2300,20 +2300,20 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
2300 return self.genSetReg(ty, reg, .{ .immediate = 0xaaaaaaaaaaaaaaaa });2300 return self.genSetReg(ty, reg, .{ .immediate = 0xaaaaaaaaaaaaaaaa });
2301 },2301 },
2302 .immediate => |unsigned_x| {2302 .immediate => |unsigned_x| {
2303 const x = @as(i64, @bitCast(unsigned_x));2303 const x: i64 = @bitCast(unsigned_x);
2304 if (math.minInt(i12) <= x and x <= math.maxInt(i12)) {2304 if (math.minInt(i12) <= x and x <= math.maxInt(i12)) {
2305 _ = try self.addInst(.{2305 _ = try self.addInst(.{
2306 .tag = .addi,2306 .tag = .addi,
2307 .data = .{ .i_type = .{2307 .data = .{ .i_type = .{
2308 .rd = reg,2308 .rd = reg,
2309 .rs1 = .zero,2309 .rs1 = .zero,
2310 .imm12 = @as(i12, @intCast(x)),2310 .imm12 = @intCast(x),
2311 } },2311 } },
2312 });2312 });
2313 } else if (math.minInt(i32) <= x and x <= math.maxInt(i32)) {2313 } else if (math.minInt(i32) <= x and x <= math.maxInt(i32)) {
2314 const lo12 = @as(i12, @truncate(x));2314 const lo12: i12 = @truncate(x);
2315 const carry: i32 = if (lo12 < 0) 1 else 0;2315 const carry: i32 = if (lo12 < 0) 1 else 0;
2316 const hi20 = @as(i20, @truncate((x >> 12) +% carry));2316 const hi20: i20 = @truncate((x >> 12) +% carry);
23172317
2318 // TODO: add test case for 32-bit immediate2318 // TODO: add test case for 32-bit immediate
2319 _ = try self.addInst(.{2319 _ = try self.addInst(.{
...@@ -2373,13 +2373,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -2373,13 +2373,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
2373}2373}
23742374
2375fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {2375fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
2376 const un_op = self.air.instructions.items(.data)[inst].un_op;2376 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2377 const result = try self.resolveInst(un_op);2377 const result = try self.resolveInst(un_op);
2378 return self.finishAir(inst, result, .{ un_op, .none, .none });2378 return self.finishAir(inst, result, .{ un_op, .none, .none });
2379}2379}
23802380
2381fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {2381fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
2382 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2382 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2383 const result = if (self.liveness.isUnused(inst)) .dead else result: {2383 const result = if (self.liveness.isUnused(inst)) .dead else result: {
2384 const operand = try self.resolveInst(ty_op.operand);2384 const operand = try self.resolveInst(ty_op.operand);
2385 if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand;2385 if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand;
...@@ -2398,7 +2398,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -2398,7 +2398,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
2398}2398}
23992399
2400fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {2400fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
2401 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2401 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2402 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airArrayToSlice for {}", .{2402 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airArrayToSlice for {}", .{
2403 self.target.cpu.arch,2403 self.target.cpu.arch,
2404 });2404 });
...@@ -2406,7 +2406,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -2406,7 +2406,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
2406}2406}
24072407
2408fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {2408fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
2409 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2409 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2410 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{2410 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
2411 self.target.cpu.arch,2411 self.target.cpu.arch,
2412 });2412 });
...@@ -2414,7 +2414,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {...@@ -2414,7 +2414,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
2414}2414}
24152415
2416fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {2416fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
2417 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2417 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2418 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{2418 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
2419 self.target.cpu.arch,2419 self.target.cpu.arch,
2420 });2420 });
...@@ -2422,7 +2422,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {...@@ -2422,7 +2422,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
2422}2422}
24232423
2424fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {2424fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
2425 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2425 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2426 const extra = self.air.extraData(Air.Block, ty_pl.payload);2426 const extra = self.air.extraData(Air.Block, ty_pl.payload);
2427 _ = extra;2427 _ = extra;
2428 return self.fail("TODO implement airCmpxchg for {}", .{2428 return self.fail("TODO implement airCmpxchg for {}", .{
...@@ -2463,7 +2463,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {...@@ -2463,7 +2463,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
2463}2463}
24642464
2465fn airTagName(self: *Self, inst: Air.Inst.Index) !void {2465fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
2466 const un_op = self.air.instructions.items(.data)[inst].un_op;2466 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2467 const operand = try self.resolveInst(un_op);2467 const operand = try self.resolveInst(un_op);
2468 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {2468 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
2469 _ = operand;2469 _ = operand;
...@@ -2473,7 +2473,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {...@@ -2473,7 +2473,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
2473}2473}
24742474
2475fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {2475fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
2476 const un_op = self.air.instructions.items(.data)[inst].un_op;2476 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2477 const operand = try self.resolveInst(un_op);2477 const operand = try self.resolveInst(un_op);
2478 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {2478 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
2479 _ = operand;2479 _ = operand;
...@@ -2483,26 +2483,26 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {...@@ -2483,26 +2483,26 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
2483}2483}
24842484
2485fn airSplat(self: *Self, inst: Air.Inst.Index) !void {2485fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
2486 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2486 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2487 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for riscv64", .{});2487 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for riscv64", .{});
2488 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2488 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2489}2489}
24902490
2491fn airSelect(self: *Self, inst: Air.Inst.Index) !void {2491fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
2492 const pl_op = self.air.instructions.items(.data)[inst].pl_op;2492 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
2493 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;2493 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
2494 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for riscv64", .{});2494 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for riscv64", .{});
2495 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });2495 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
2496}2496}
24972497
2498fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {2498fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
2499 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2499 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2500 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for riscv64", .{});2500 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for riscv64", .{});
2501 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2501 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2502}2502}
25032503
2504fn airReduce(self: *Self, inst: Air.Inst.Index) !void {2504fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
2505 const reduce = self.air.instructions.items(.data)[inst].reduce;2505 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
2506 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for riscv64", .{});2506 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for riscv64", .{});
2507 return self.finishAir(inst, result, .{ reduce.operand, .none, .none });2507 return self.finishAir(inst, result, .{ reduce.operand, .none, .none });
2508}2508}
...@@ -2511,8 +2511,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -2511,8 +2511,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
2511 const mod = self.bin_file.options.module.?;2511 const mod = self.bin_file.options.module.?;
2512 const vector_ty = self.typeOfIndex(inst);2512 const vector_ty = self.typeOfIndex(inst);
2513 const len = vector_ty.vectorLen(mod);2513 const len = vector_ty.vectorLen(mod);
2514 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2514 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2515 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));2515 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
2516 const result: MCValue = res: {2516 const result: MCValue = res: {
2517 if (self.liveness.isUnused(inst)) break :res MCValue.dead;2517 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
2518 return self.fail("TODO implement airAggregateInit for riscv64", .{});2518 return self.fail("TODO implement airAggregateInit for riscv64", .{});
...@@ -2531,7 +2531,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -2531,7 +2531,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
2531}2531}
25322532
2533fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {2533fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
2534 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2534 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2535 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;2535 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
2536 _ = extra;2536 _ = extra;
2537 return self.fail("TODO implement airUnionInit for riscv64", .{});2537 return self.fail("TODO implement airUnionInit for riscv64", .{});
...@@ -2539,12 +2539,12 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -2539,12 +2539,12 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
2539}2539}
25402540
2541fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {2541fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {
2542 const prefetch = self.air.instructions.items(.data)[inst].prefetch;2542 const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
2543 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });2543 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });
2544}2544}
25452545
2546fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {2546fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
2547 const pl_op = self.air.instructions.items(.data)[inst].pl_op;2547 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
2548 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;2548 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
2549 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {2549 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
2550 return self.fail("TODO implement airMulAdd for riscv64", .{});2550 return self.fail("TODO implement airMulAdd for riscv64", .{});
...@@ -2560,7 +2560,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {...@@ -2560,7 +2560,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
2560 if (!inst_ty.hasRuntimeBits(mod))2560 if (!inst_ty.hasRuntimeBits(mod))
2561 return MCValue{ .none = {} };2561 return MCValue{ .none = {} };
25622562
2563 const inst_index = Air.refToIndex(inst) orelse return self.genTypedValue(.{2563 const inst_index = inst.toIndex() orelse return self.genTypedValue(.{
2564 .ty = inst_ty,2564 .ty = inst_ty,
2565 .val = (try self.air.value(inst, mod)).?,2565 .val = (try self.air.value(inst, mod)).?,
2566 });2566 });
...@@ -2656,7 +2656,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -2656,7 +2656,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
2656 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };2656 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };
26572657
2658 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {2658 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
2659 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(mod)));2659 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(mod));
2660 if (param_size <= 8) {2660 if (param_size <= 8) {
2661 if (next_register < argument_registers.len) {2661 if (next_register < argument_registers.len) {
2662 result_arg.* = .{ .register = argument_registers[next_register] };2662 result_arg.* = .{ .register = argument_registers[next_register] };
...@@ -2693,7 +2693,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -2693,7 +2693,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
2693 } else switch (cc) {2693 } else switch (cc) {
2694 .Naked => unreachable,2694 .Naked => unreachable,
2695 .Unspecified, .C => {2695 .Unspecified, .C => {
2696 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));2696 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(mod));
2697 if (ret_ty_size <= 8) {2697 if (ret_ty_size <= 8) {
2698 result.return_value = .{ .register = .a0 };2698 result.return_value = .{ .register = .a0 };
2699 } else if (ret_ty_size <= 16) {2699 } else if (ret_ty_size <= 16) {
src/arch/sparc64/CodeGen.zig+107-109
...@@ -243,7 +243,7 @@ const BigTomb = struct {...@@ -243,7 +243,7 @@ const BigTomb = struct {
243243
244 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {244 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {
245 const dies = bt.lbt.feed();245 const dies = bt.lbt.feed();
246 const op_index = Air.refToIndex(op_ref) orelse return;246 const op_index = op_ref.toIndex() orelse return;
247 if (!dies) return;247 if (!dies) return;
248 bt.function.processDeath(op_index);248 bt.function.processDeath(op_index);
249 }249 }
...@@ -504,7 +504,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -504,7 +504,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
504 const old_air_bookkeeping = self.air_bookkeeping;504 const old_air_bookkeeping = self.air_bookkeeping;
505 try self.ensureProcessDeathCapacity(Liveness.bpi);505 try self.ensureProcessDeathCapacity(Liveness.bpi);
506506
507 switch (air_tags[inst]) {507 switch (air_tags[@intFromEnum(inst)]) {
508 // zig fmt: off508 // zig fmt: off
509 .ptr_add => try self.airPtrArithmetic(inst, .ptr_add),509 .ptr_add => try self.airPtrArithmetic(inst, .ptr_add),
510 .ptr_sub => try self.airPtrArithmetic(inst, .ptr_sub),510 .ptr_sub => try self.airPtrArithmetic(inst, .ptr_sub),
...@@ -746,21 +746,21 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -746,21 +746,21 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
746746
747 if (std.debug.runtime_safety) {747 if (std.debug.runtime_safety) {
748 if (self.air_bookkeeping < old_air_bookkeeping + 1) {748 if (self.air_bookkeeping < old_air_bookkeeping + 1) {
749 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] });749 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] });
750 }750 }
751 }751 }
752 }752 }
753}753}
754754
755fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {755fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
756 const bin_op = self.air.instructions.items(.data)[inst].bin_op;756 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
757 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});757 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});
758 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });758 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
759}759}
760760
761fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {761fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
762 const tag = self.air.instructions.items(.tag)[inst];762 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
763 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;763 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
764 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;764 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
765 const mod = self.bin_file.options.module.?;765 const mod = self.bin_file.options.module.?;
766 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {766 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
...@@ -843,7 +843,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -843,7 +843,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
843 const mod = self.bin_file.options.module.?;843 const mod = self.bin_file.options.module.?;
844 const vector_ty = self.typeOfIndex(inst);844 const vector_ty = self.typeOfIndex(inst);
845 const len = vector_ty.vectorLen(mod);845 const len = vector_ty.vectorLen(mod);
846 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;846 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
847 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));847 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
848 const result: MCValue = res: {848 const result: MCValue = res: {
849 if (self.liveness.isUnused(inst)) break :res MCValue.dead;849 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
...@@ -868,14 +868,14 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {...@@ -868,14 +868,14 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
868}868}
869869
870fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {870fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
871 const bin_op = self.air.instructions.items(.data)[inst].bin_op;871 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
872 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch});872 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch});
873 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });873 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
874}874}
875875
876fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {876fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
877 const mod = self.bin_file.options.module.?;877 const mod = self.bin_file.options.module.?;
878 const ty_op = self.air.instructions.items(.data)[inst].ty_op;878 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
879 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {879 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
880 const ptr_ty = self.typeOf(ty_op.operand);880 const ptr_ty = self.typeOf(ty_op.operand);
881 const ptr = try self.resolveInst(ty_op.operand);881 const ptr = try self.resolveInst(ty_op.operand);
...@@ -891,7 +891,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -891,7 +891,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
891}891}
892892
893fn airAsm(self: *Self, inst: Air.Inst.Index) !void {893fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
894 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;894 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
895 const extra = self.air.extraData(Air.Asm, ty_pl.payload);895 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
896 const is_volatile = (extra.data.flags & 0x80000000) != 0;896 const is_volatile = (extra.data.flags & 0x80000000) != 0;
897 const clobbers_len = @as(u31, @truncate(extra.data.flags));897 const clobbers_len = @as(u31, @truncate(extra.data.flags));
...@@ -1047,7 +1047,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -1047,7 +1047,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
1047}1047}
10481048
1049fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {1049fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {
1050 _ = self.air.instructions.items(.data)[inst].atomic_load;1050 _ = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
10511051
1052 return self.fail("TODO implement airAtomicLoad for {}", .{1052 return self.fail("TODO implement airAtomicLoad for {}", .{
1053 self.target.cpu.arch,1053 self.target.cpu.arch,
...@@ -1055,7 +1055,7 @@ fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -1055,7 +1055,7 @@ fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {
1055}1055}
10561056
1057fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {1057fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {
1058 _ = self.air.instructions.items(.data)[inst].pl_op;1058 _ = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
10591059
1060 return self.fail("TODO implement airAtomicRmw for {}", .{1060 return self.fail("TODO implement airAtomicRmw for {}", .{
1061 self.target.cpu.arch,1061 self.target.cpu.arch,
...@@ -1063,7 +1063,7 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {...@@ -1063,7 +1063,7 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {
1063}1063}
10641064
1065fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {1065fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1066 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1066 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1067 const lhs = try self.resolveInst(bin_op.lhs);1067 const lhs = try self.resolveInst(bin_op.lhs);
1068 const rhs = try self.resolveInst(bin_op.rhs);1068 const rhs = try self.resolveInst(bin_op.rhs);
1069 const lhs_ty = self.typeOf(bin_op.lhs);1069 const lhs_ty = self.typeOf(bin_op.lhs);
...@@ -1080,14 +1080,14 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {...@@ -1080,14 +1080,14 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1080}1080}
10811081
1082fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {1082fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
1083 const un_op = self.air.instructions.items(.data)[inst].un_op;1083 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1084 const operand = try self.resolveInst(un_op);1084 const operand = try self.resolveInst(un_op);
1085 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;1085 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
1086 return self.finishAir(inst, result, .{ un_op, .none, .none });1086 return self.finishAir(inst, result, .{ un_op, .none, .none });
1087}1087}
10881088
1089fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {1089fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1090 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1090 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1091 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;1091 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
1092 const lhs = try self.resolveInst(bin_op.lhs);1092 const lhs = try self.resolveInst(bin_op.lhs);
1093 const rhs = try self.resolveInst(bin_op.rhs);1093 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -1105,7 +1105,7 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void...@@ -1105,7 +1105,7 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void
1105}1105}
11061106
1107fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {1107fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1108 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1108 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1109 const result = if (self.liveness.isUnused(inst)) .dead else result: {1109 const result = if (self.liveness.isUnused(inst)) .dead else result: {
1110 const operand = try self.resolveInst(ty_op.operand);1110 const operand = try self.resolveInst(ty_op.operand);
1111 if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand;1111 if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand;
...@@ -1125,7 +1125,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -1125,7 +1125,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1125}1125}
11261126
1127fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {1127fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
1128 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1128 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1129 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});1129 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});
1130 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1130 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1131}1131}
...@@ -1143,9 +1143,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -1143,9 +1143,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
1143 });1143 });
1144 defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa);1144 defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa);
11451145
1146 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1146 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1147 const extra = self.air.extraData(Air.Block, ty_pl.payload);1147 const extra = self.air.extraData(Air.Block, ty_pl.payload);
1148 const body = self.air.extra[extra.end..][0..extra.data.body_len];1148 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
1149 try self.genBody(body);1149 try self.genBody(body);
11501150
1151 // relocations for `bpcc` instructions1151 // relocations for `bpcc` instructions
...@@ -1170,7 +1170,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -1170,7 +1170,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
1170}1170}
11711171
1172fn airBr(self: *Self, inst: Air.Inst.Index) !void {1172fn airBr(self: *Self, inst: Air.Inst.Index) !void {
1173 const branch = self.air.instructions.items(.data)[inst].br;1173 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
1174 try self.br(branch.block_inst, branch.operand);1174 try self.br(branch.block_inst, branch.operand);
1175 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });1175 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });
1176}1176}
...@@ -1207,7 +1207,7 @@ fn airBreakpoint(self: *Self) !void {...@@ -1207,7 +1207,7 @@ fn airBreakpoint(self: *Self) !void {
12071207
1208fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {1208fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
1209 const mod = self.bin_file.options.module.?;1209 const mod = self.bin_file.options.module.?;
1210 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1210 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
12111211
1212 // We have hardware byteswapper in SPARCv9, don't let mainstream compilers mislead you.1212 // We have hardware byteswapper in SPARCv9, don't let mainstream compilers mislead you.
1213 // That being said, the strategy to lower this is:1213 // That being said, the strategy to lower this is:
...@@ -1293,7 +1293,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {...@@ -1293,7 +1293,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
1293fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {1293fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
1294 if (modifier == .always_tail) return self.fail("TODO implement tail calls for {}", .{self.target.cpu.arch});1294 if (modifier == .always_tail) return self.fail("TODO implement tail calls for {}", .{self.target.cpu.arch});
12951295
1296 const pl_op = self.air.instructions.items(.data)[inst].pl_op;1296 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1297 const callee = pl_op.operand;1297 const callee = pl_op.operand;
1298 const extra = self.air.extraData(Air.Call, pl_op.payload);1298 const extra = self.air.extraData(Air.Call, pl_op.payload);
1299 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end .. extra.end + extra.data.args_len]));1299 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end .. extra.end + extra.data.args_len]));
...@@ -1423,13 +1423,13 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1423,13 +1423,13 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1423}1423}
14241424
1425fn airClz(self: *Self, inst: Air.Inst.Index) !void {1425fn airClz(self: *Self, inst: Air.Inst.Index) !void {
1426 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1426 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1427 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});1427 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});
1428 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1428 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1429}1429}
14301430
1431fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {1431fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1432 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1432 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1433 const mod = self.bin_file.options.module.?;1433 const mod = self.bin_file.options.module.?;
1434 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1434 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1435 const lhs = try self.resolveInst(bin_op.lhs);1435 const lhs = try self.resolveInst(bin_op.lhs);
...@@ -1486,7 +1486,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {...@@ -1486,7 +1486,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1486}1486}
14871487
1488fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {1488fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
1489 const un_op = self.air.instructions.items(.data)[inst].un_op;1489 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1490 const operand = try self.resolveInst(un_op);1490 const operand = try self.resolveInst(un_op);
1491 _ = operand;1491 _ = operand;
1492 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch});1492 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch});
...@@ -1494,7 +1494,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -1494,7 +1494,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
1494}1494}
14951495
1496fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {1496fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
1497 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1497 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1498 const extra = self.air.extraData(Air.Block, ty_pl.payload);1498 const extra = self.air.extraData(Air.Block, ty_pl.payload);
1499 _ = extra;1499 _ = extra;
15001500
...@@ -1504,11 +1504,11 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {...@@ -1504,11 +1504,11 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
1504}1504}
15051505
1506fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {1506fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
1507 const pl_op = self.air.instructions.items(.data)[inst].pl_op;1507 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1508 const condition = try self.resolveInst(pl_op.operand);1508 const condition = try self.resolveInst(pl_op.operand);
1509 const extra = self.air.extraData(Air.CondBr, pl_op.payload);1509 const extra = self.air.extraData(Air.CondBr, pl_op.payload);
1510 const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len];1510 const then_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.then_body_len]);
1511 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];1511 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
1512 const liveness_condbr = self.liveness.getCondBr(inst);1512 const liveness_condbr = self.liveness.getCondBr(inst);
15131513
1514 // Here we emit a branch to the false section.1514 // Here we emit a branch to the false section.
...@@ -1518,7 +1518,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1518,7 +1518,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
1518 // that death now instead of later as this has an effect on1518 // that death now instead of later as this has an effect on
1519 // whether it needs to be spilled in the branches1519 // whether it needs to be spilled in the branches
1520 if (self.liveness.operandDies(inst, 0)) {1520 if (self.liveness.operandDies(inst, 0)) {
1521 if (Air.refToIndex(pl_op.operand)) |op_index| {1521 if (pl_op.operand.toIndex()) |op_index| {
1522 self.processDeath(op_index);1522 self.processDeath(op_index);
1523 }1523 }
1524 }1524 }
...@@ -1650,7 +1650,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1650,7 +1650,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
1650}1650}
16511651
1652fn airCtz(self: *Self, inst: Air.Inst.Index) !void {1652fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
1653 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1653 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1654 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});1654 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});
1655 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1655 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1656}1656}
...@@ -1661,7 +1661,7 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -1661,7 +1661,7 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
1661}1661}
16621662
1663fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {1663fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
1664 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;1664 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
1665 const mod = self.bin_file.options.module.?;1665 const mod = self.bin_file.options.module.?;
1666 const func = mod.funcInfo(ty_fn.func);1666 const func = mod.funcInfo(ty_fn.func);
1667 // TODO emit debug info for function change1667 // TODO emit debug info for function change
...@@ -1670,7 +1670,7 @@ fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {...@@ -1670,7 +1670,7 @@ fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
1670}1670}
16711671
1672fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {1672fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
1673 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;1673 const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
16741674
1675 _ = try self.addInst(.{1675 _ = try self.addInst(.{
1676 .tag = .dbg_line,1676 .tag = .dbg_line,
...@@ -1686,7 +1686,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {...@@ -1686,7 +1686,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
1686}1686}
16871687
1688fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {1688fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
1689 const pl_op = self.air.instructions.items(.data)[inst].pl_op;1689 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1690 const name = self.air.nullTerminatedString(pl_op.payload);1690 const name = self.air.nullTerminatedString(pl_op.payload);
1691 const operand = pl_op.operand;1691 const operand = pl_op.operand;
1692 // TODO emit debug info for this variable1692 // TODO emit debug info for this variable
...@@ -1695,13 +1695,13 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {...@@ -1695,13 +1695,13 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
1695}1695}
16961696
1697fn airDiv(self: *Self, inst: Air.Inst.Index) !void {1697fn airDiv(self: *Self, inst: Air.Inst.Index) !void {
1698 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1698 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1699 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement div for {}", .{self.target.cpu.arch});1699 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement div for {}", .{self.target.cpu.arch});
1700 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });1700 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1701}1701}
17021702
1703fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {1703fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
1704 const un_op = self.air.instructions.items(.data)[inst].un_op;1704 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1705 const operand = try self.resolveInst(un_op);1705 const operand = try self.resolveInst(un_op);
1706 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {1706 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
1707 _ = operand;1707 _ = operand;
...@@ -1711,14 +1711,14 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {...@@ -1711,14 +1711,14 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
1711}1711}
17121712
1713fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {1713fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
1714 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1714 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1715 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});1715 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});
1716 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1716 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1717}1717}
17181718
1719fn airFence(self: *Self, inst: Air.Inst.Index) !void {1719fn airFence(self: *Self, inst: Air.Inst.Index) !void {
1720 // TODO weaken this as needed, currently this implements the strongest membar form1720 // TODO weaken this as needed, currently this implements the strongest membar form
1721 const fence = self.air.instructions.items(.data)[inst].fence;1721 const fence = self.air.instructions.items(.data)[@intFromEnum(inst)].fence;
1722 _ = fence;1722 _ = fence;
17231723
1724 // membar #StoreStore | #LoadStore | #StoreLoad | #LoadLoad1724 // membar #StoreStore | #LoadStore | #StoreLoad | #LoadLoad
...@@ -1740,7 +1740,7 @@ fn airFence(self: *Self, inst: Air.Inst.Index) !void {...@@ -1740,7 +1740,7 @@ fn airFence(self: *Self, inst: Air.Inst.Index) !void {
1740}1740}
17411741
1742fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {1742fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1743 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1743 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1744 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{1744 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
1745 self.target.cpu.arch,1745 self.target.cpu.arch,
1746 });1746 });
...@@ -1748,13 +1748,13 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {...@@ -1748,13 +1748,13 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1748}1748}
17491749
1750fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {1750fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
1751 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1751 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1752 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});1752 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});
1753 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1753 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1754}1754}
17551755
1756fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {1756fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
1757 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1757 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1758 if (self.liveness.isUnused(inst))1758 if (self.liveness.isUnused(inst))
1759 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });1759 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
17601760
...@@ -1773,7 +1773,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -1773,7 +1773,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
1773}1773}
17741774
1775fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {1775fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1776 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1776 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1777 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{1777 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
1778 self.target.cpu.arch,1778 self.target.cpu.arch,
1779 });1779 });
...@@ -1781,7 +1781,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {...@@ -1781,7 +1781,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1781}1781}
17821782
1783fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {1783fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
1784 const un_op = self.air.instructions.items(.data)[inst].un_op;1784 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1785 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1785 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1786 const operand = try self.resolveInst(un_op);1786 const operand = try self.resolveInst(un_op);
1787 const ty = self.typeOf(un_op);1787 const ty = self.typeOf(un_op);
...@@ -1791,7 +1791,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1791,7 +1791,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
1791}1791}
17921792
1793fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {1793fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
1794 const un_op = self.air.instructions.items(.data)[inst].un_op;1794 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1795 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1795 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1796 const operand = try self.resolveInst(un_op);1796 const operand = try self.resolveInst(un_op);
1797 const ty = self.typeOf(un_op);1797 const ty = self.typeOf(un_op);
...@@ -1801,7 +1801,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1801,7 +1801,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
1801}1801}
18021802
1803fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {1803fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
1804 const un_op = self.air.instructions.items(.data)[inst].un_op;1804 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1805 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1805 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1806 const operand = try self.resolveInst(un_op);1806 const operand = try self.resolveInst(un_op);
1807 break :result try self.isNull(operand);1807 break :result try self.isNull(operand);
...@@ -1810,7 +1810,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -1810,7 +1810,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
1810}1810}
18111811
1812fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {1812fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
1813 const un_op = self.air.instructions.items(.data)[inst].un_op;1813 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1814 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1814 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1815 const operand = try self.resolveInst(un_op);1815 const operand = try self.resolveInst(un_op);
1816 break :result try self.isNonNull(operand);1816 break :result try self.isNonNull(operand);
...@@ -1820,7 +1820,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -1820,7 +1820,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
18201820
1821fn airLoad(self: *Self, inst: Air.Inst.Index) !void {1821fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
1822 const mod = self.bin_file.options.module.?;1822 const mod = self.bin_file.options.module.?;
1823 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1823 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1824 const elem_ty = self.typeOfIndex(inst);1824 const elem_ty = self.typeOfIndex(inst);
1825 const elem_size = elem_ty.abiSize(mod);1825 const elem_size = elem_ty.abiSize(mod);
1826 const result: MCValue = result: {1826 const result: MCValue = result: {
...@@ -1851,9 +1851,9 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -1851,9 +1851,9 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
18511851
1852fn airLoop(self: *Self, inst: Air.Inst.Index) !void {1852fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
1853 // A loop is a setup to be able to jump back to the beginning.1853 // A loop is a setup to be able to jump back to the beginning.
1854 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;1854 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1855 const loop = self.air.extraData(Air.Block, ty_pl.payload);1855 const loop = self.air.extraData(Air.Block, ty_pl.payload);
1856 const body = self.air.extra[loop.end .. loop.end + loop.data.body_len];1856 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end .. loop.end + loop.data.body_len]);
1857 const start = @as(u32, @intCast(self.mir_instructions.len));1857 const start = @as(u32, @intCast(self.mir_instructions.len));
18581858
1859 try self.genBody(body);1859 try self.genBody(body);
...@@ -1868,7 +1868,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -1868,7 +1868,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1868 } else {1868 } else {
1869 // TODO if the value is undef, don't lower this instruction1869 // TODO if the value is undef, don't lower this instruction
1870 }1870 }
1871 const pl_op = self.air.instructions.items(.data)[inst].pl_op;1871 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1872 const extra = self.air.extraData(Air.Bin, pl_op.payload);1872 const extra = self.air.extraData(Air.Bin, pl_op.payload);
18731873
1874 const operand = pl_op.operand;1874 const operand = pl_op.operand;
...@@ -1882,8 +1882,8 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -1882,8 +1882,8 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1882}1882}
18831883
1884fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {1884fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
1885 const tag = self.air.instructions.items(.tag)[inst];1885 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1886 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1886 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1887 const lhs = try self.resolveInst(bin_op.lhs);1887 const lhs = try self.resolveInst(bin_op.lhs);
1888 const rhs = try self.resolveInst(bin_op.rhs);1888 const rhs = try self.resolveInst(bin_op.rhs);
1889 const lhs_ty = self.typeOf(bin_op.lhs);1889 const lhs_ty = self.typeOf(bin_op.lhs);
...@@ -1898,7 +1898,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {...@@ -1898,7 +1898,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
1898}1898}
18991899
1900fn airMod(self: *Self, inst: Air.Inst.Index) !void {1900fn airMod(self: *Self, inst: Air.Inst.Index) !void {
1901 const bin_op = self.air.instructions.items(.data)[inst].bin_op;1901 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1902 const lhs = try self.resolveInst(bin_op.lhs);1902 const lhs = try self.resolveInst(bin_op.lhs);
1903 const rhs = try self.resolveInst(bin_op.rhs);1903 const rhs = try self.resolveInst(bin_op.rhs);
1904 const lhs_ty = self.typeOf(bin_op.lhs);1904 const lhs_ty = self.typeOf(bin_op.lhs);
...@@ -2036,14 +2036,14 @@ fn airMod(self: *Self, inst: Air.Inst.Index) !void {...@@ -2036,14 +2036,14 @@ fn airMod(self: *Self, inst: Air.Inst.Index) !void {
2036}2036}
20372037
2038fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {2038fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
2039 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2039 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2040 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});2040 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});
2041 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });2041 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
2042}2042}
20432043
2044fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {2044fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2045 //const tag = self.air.instructions.items(.tag)[inst];2045 //const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
2046 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2046 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2047 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2047 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2048 const mod = self.bin_file.options.module.?;2048 const mod = self.bin_file.options.module.?;
2049 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2049 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
...@@ -2108,7 +2108,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2108,7 +2108,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2108}2108}
21092109
2110fn airNot(self: *Self, inst: Air.Inst.Index) !void {2110fn airNot(self: *Self, inst: Air.Inst.Index) !void {
2111 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2111 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2112 const mod = self.bin_file.options.module.?;2112 const mod = self.bin_file.options.module.?;
2113 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2113 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2114 const operand = try self.resolveInst(ty_op.operand);2114 const operand = try self.resolveInst(ty_op.operand);
...@@ -2204,51 +2204,51 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {...@@ -2204,51 +2204,51 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
2204}2204}
22052205
2206fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {2206fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
2207 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2207 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2208 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch});2208 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch});
2209 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2209 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2210}2210}
22112211
2212fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {2212fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
2213 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2213 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2214 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});2214 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});
2215 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2215 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2216}2216}
22172217
2218fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {2218fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
2219 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2219 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2220 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});2220 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});
2221 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2221 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2222}2222}
22232223
2224fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {2224fn airPopcount(self: *Self, inst: Air.Inst.Index) !void {
2225 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2225 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2226 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});2226 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});
2227 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2227 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2228}2228}
22292229
2230fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {2230fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {
2231 const prefetch = self.air.instructions.items(.data)[inst].prefetch;2231 const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
2232 // TODO Emit a PREFETCH/IPREFETCH as necessary, see A.7 and A.422232 // TODO Emit a PREFETCH/IPREFETCH as necessary, see A.7 and A.42
2233 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });2233 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });
2234}2234}
22352235
2236fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {2236fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
2237 const is_volatile = false; // TODO2237 const is_volatile = false; // TODO
2238 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2238 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2239 const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_val for {}", .{self.target.cpu.arch});2239 const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_val for {}", .{self.target.cpu.arch});
2240 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });2240 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
2241}2241}
22422242
2243fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {2243fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
2244 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2244 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2245 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2245 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2246 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_ptr for {}", .{self.target.cpu.arch});2246 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_ptr for {}", .{self.target.cpu.arch});
2247 return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });2247 return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
2248}2248}
22492249
2250fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {2250fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
2251 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2251 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2252 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2252 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2253 const ptr_bits = self.target.ptrBitWidth();2253 const ptr_bits = self.target.ptrBitWidth();
2254 const ptr_bytes = @divExact(ptr_bits, 8);2254 const ptr_bytes = @divExact(ptr_bits, 8);
...@@ -2265,7 +2265,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2265,7 +2265,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
2265}2265}
22662266
2267fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {2267fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
2268 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2268 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2269 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2269 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2270 const mcv = try self.resolveInst(ty_op.operand);2270 const mcv = try self.resolveInst(ty_op.operand);
2271 switch (mcv) {2271 switch (mcv) {
...@@ -2280,13 +2280,13 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2280,13 +2280,13 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
2280}2280}
22812281
2282fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {2282fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
2283 const un_op = self.air.instructions.items(.data)[inst].un_op;2283 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2284 const result = try self.resolveInst(un_op);2284 const result = try self.resolveInst(un_op);
2285 return self.finishAir(inst, result, .{ un_op, .none, .none });2285 return self.finishAir(inst, result, .{ un_op, .none, .none });
2286}2286}
22872287
2288fn airRem(self: *Self, inst: Air.Inst.Index) !void {2288fn airRem(self: *Self, inst: Air.Inst.Index) !void {
2289 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2289 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2290 const lhs = try self.resolveInst(bin_op.lhs);2290 const lhs = try self.resolveInst(bin_op.lhs);
2291 const rhs = try self.resolveInst(bin_op.rhs);2291 const rhs = try self.resolveInst(bin_op.rhs);
2292 const lhs_ty = self.typeOf(bin_op.lhs);2292 const lhs_ty = self.typeOf(bin_op.lhs);
...@@ -2307,14 +2307,14 @@ fn airRem(self: *Self, inst: Air.Inst.Index) !void {...@@ -2307,14 +2307,14 @@ fn airRem(self: *Self, inst: Air.Inst.Index) !void {
2307}2307}
23082308
2309fn airRet(self: *Self, inst: Air.Inst.Index) !void {2309fn airRet(self: *Self, inst: Air.Inst.Index) !void {
2310 const un_op = self.air.instructions.items(.data)[inst].un_op;2310 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2311 const operand = try self.resolveInst(un_op);2311 const operand = try self.resolveInst(un_op);
2312 try self.ret(operand);2312 try self.ret(operand);
2313 return self.finishAir(inst, .dead, .{ un_op, .none, .none });2313 return self.finishAir(inst, .dead, .{ un_op, .none, .none });
2314}2314}
23152315
2316fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {2316fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
2317 const un_op = self.air.instructions.items(.data)[inst].un_op;2317 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2318 const ptr = try self.resolveInst(un_op);2318 const ptr = try self.resolveInst(un_op);
2319 _ = ptr;2319 _ = ptr;
2320 return self.fail("TODO implement airRetLoad for {}", .{self.target.cpu.arch});2320 return self.fail("TODO implement airRetLoad for {}", .{self.target.cpu.arch});
...@@ -2327,19 +2327,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2327,19 +2327,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
2327}2327}
23282328
2329fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {2329fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
2330 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2330 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2331 _ = bin_op;2331 _ = bin_op;
2332 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});2332 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});
2333}2333}
23342334
2335fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {2335fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
2336 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2336 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2337 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});2337 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
2338 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });2338 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
2339}2339}
23402340
2341fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {2341fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2342 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2342 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2343 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2343 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2344 const mod = self.bin_file.options.module.?;2344 const mod = self.bin_file.options.module.?;
2345 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2345 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
...@@ -2429,7 +2429,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2429,7 +2429,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2429}2429}
24302430
2431fn airSlice(self: *Self, inst: Air.Inst.Index) !void {2431fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
2432 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2432 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2433 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;2433 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
2434 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2434 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2435 const ptr = try self.resolveInst(bin_op.lhs);2435 const ptr = try self.resolveInst(bin_op.lhs);
...@@ -2448,7 +2448,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -2448,7 +2448,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
2448fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {2448fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
2449 const mod = self.bin_file.options.module.?;2449 const mod = self.bin_file.options.module.?;
2450 const is_volatile = false; // TODO2450 const is_volatile = false; // TODO
2451 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2451 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
24522452
2453 if (!is_volatile and self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });2453 if (!is_volatile and self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
2454 const result: MCValue = result: {2454 const result: MCValue = result: {
...@@ -2490,7 +2490,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2490,7 +2490,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
2490}2490}
24912491
2492fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {2492fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
2493 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2493 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2494 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2494 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2495 const ptr_bits = self.target.ptrBitWidth();2495 const ptr_bits = self.target.ptrBitWidth();
2496 const ptr_bytes = @divExact(ptr_bits, 8);2496 const ptr_bytes = @divExact(ptr_bits, 8);
...@@ -2511,7 +2511,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -2511,7 +2511,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
2511}2511}
25122512
2513fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {2513fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
2514 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2514 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2515 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2515 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2516 const mcv = try self.resolveInst(ty_op.operand);2516 const mcv = try self.resolveInst(ty_op.operand);
2517 switch (mcv) {2517 switch (mcv) {
...@@ -2530,7 +2530,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2530,7 +2530,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
2530}2530}
25312531
2532fn airSplat(self: *Self, inst: Air.Inst.Index) !void {2532fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
2533 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2533 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2534 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for {}", .{self.target.cpu.arch});2534 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for {}", .{self.target.cpu.arch});
2535 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2535 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2536}2536}
...@@ -2541,7 +2541,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -2541,7 +2541,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
2541 } else {2541 } else {
2542 // TODO if the value is undef, don't lower this instruction2542 // TODO if the value is undef, don't lower this instruction
2543 }2543 }
2544 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2544 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2545 const ptr = try self.resolveInst(bin_op.lhs);2545 const ptr = try self.resolveInst(bin_op.lhs);
2546 const value = try self.resolveInst(bin_op.rhs);2546 const value = try self.resolveInst(bin_op.rhs);
2547 const ptr_ty = self.typeOf(bin_op.lhs);2547 const ptr_ty = self.typeOf(bin_op.lhs);
...@@ -2553,20 +2553,20 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -2553,20 +2553,20 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
2553}2553}
25542554
2555fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {2555fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {
2556 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2556 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2557 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;2557 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
2558 const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index);2558 const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index);
2559 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });2559 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });
2560}2560}
25612561
2562fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {2562fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
2563 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2563 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2564 const result = try self.structFieldPtr(inst, ty_op.operand, index);2564 const result = try self.structFieldPtr(inst, ty_op.operand, index);
2565 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2565 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2566}2566}
25672567
2568fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {2568fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2569 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2569 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2570 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;2570 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
2571 const operand = extra.struct_operand;2571 const operand = extra.struct_operand;
2572 const index = extra.field_index;2572 const index = extra.field_index;
...@@ -2636,7 +2636,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2636,7 +2636,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2636}2636}
26372637
2638fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {2638fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
2639 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2639 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2640 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});2640 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});
2641 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });2641 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
2642}2642}
...@@ -2647,7 +2647,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -2647,7 +2647,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
2647}2647}
26482648
2649fn airTagName(self: *Self, inst: Air.Inst.Index) !void {2649fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
2650 const un_op = self.air.instructions.items(.data)[inst].un_op;2650 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2651 const operand = try self.resolveInst(un_op);2651 const operand = try self.resolveInst(un_op);
2652 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {2652 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
2653 _ = operand;2653 _ = operand;
...@@ -2657,7 +2657,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {...@@ -2657,7 +2657,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
2657}2657}
26582658
2659fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {2659fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
2660 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2660 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2661 const operand = try self.resolveInst(ty_op.operand);2661 const operand = try self.resolveInst(ty_op.operand);
2662 const operand_ty = self.typeOf(ty_op.operand);2662 const operand_ty = self.typeOf(ty_op.operand);
2663 const dest_ty = self.typeOfIndex(inst);2663 const dest_ty = self.typeOfIndex(inst);
...@@ -2670,9 +2670,9 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -2670,9 +2670,9 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
2670}2670}
26712671
2672fn airTry(self: *Self, inst: Air.Inst.Index) !void {2672fn airTry(self: *Self, inst: Air.Inst.Index) !void {
2673 const pl_op = self.air.instructions.items(.data)[inst].pl_op;2673 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
2674 const extra = self.air.extraData(Air.Try, pl_op.payload);2674 const extra = self.air.extraData(Air.Try, pl_op.payload);
2675 const body = self.air.extra[extra.end..][0..extra.data.body_len];2675 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
2676 const result: MCValue = result: {2676 const result: MCValue = result: {
2677 const error_union_ty = self.typeOf(pl_op.operand);2677 const error_union_ty = self.typeOf(pl_op.operand);
2678 const error_union = try self.resolveInst(pl_op.operand);2678 const error_union = try self.resolveInst(pl_op.operand);
...@@ -2688,7 +2688,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {...@@ -2688,7 +2688,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
2688}2688}
26892689
2690fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {2690fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {
2691 const un_op = self.air.instructions.items(.data)[inst].un_op;2691 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2692 const result: MCValue = if (self.liveness.isUnused(inst))2692 const result: MCValue = if (self.liveness.isUnused(inst))
2693 .dead2693 .dead
2694 else2694 else
...@@ -2697,7 +2697,7 @@ fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {...@@ -2697,7 +2697,7 @@ fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {
2697}2697}
26982698
2699fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {2699fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
2700 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2700 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2701 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;2701 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
2702 _ = extra;2702 _ = extra;
2703 return self.fail("TODO implement airUnionInit for {}", .{self.target.cpu.arch});2703 return self.fail("TODO implement airUnionInit for {}", .{self.target.cpu.arch});
...@@ -2705,7 +2705,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -2705,7 +2705,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
27052705
2706fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {2706fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
2707 const mod = self.bin_file.options.module.?;2707 const mod = self.bin_file.options.module.?;
2708 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2708 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2709 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2709 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2710 const error_union_ty = self.typeOf(ty_op.operand);2710 const error_union_ty = self.typeOf(ty_op.operand);
2711 const payload_ty = error_union_ty.errorUnionPayload(mod);2711 const payload_ty = error_union_ty.errorUnionPayload(mod);
...@@ -2719,7 +2719,7 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2719,7 +2719,7 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
27192719
2720fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {2720fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
2721 const mod = self.bin_file.options.module.?;2721 const mod = self.bin_file.options.module.?;
2722 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2722 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2723 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2723 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2724 const error_union_ty = self.typeOf(ty_op.operand);2724 const error_union_ty = self.typeOf(ty_op.operand);
2725 const payload_ty = error_union_ty.errorUnionPayload(mod);2725 const payload_ty = error_union_ty.errorUnionPayload(mod);
...@@ -2733,9 +2733,9 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -2733,9 +2733,9 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
2733/// E to E!T2733/// E to E!T
2734fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {2734fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
2735 const mod = self.bin_file.options.module.?;2735 const mod = self.bin_file.options.module.?;
2736 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2736 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2737 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2737 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2738 const error_union_ty = self.air.getRefType(ty_op.ty);2738 const error_union_ty = ty_op.ty.toType();
2739 const payload_ty = error_union_ty.errorUnionPayload(mod);2739 const payload_ty = error_union_ty.errorUnionPayload(mod);
2740 const mcv = try self.resolveInst(ty_op.operand);2740 const mcv = try self.resolveInst(ty_op.operand);
2741 if (!payload_ty.hasRuntimeBits(mod)) break :result mcv;2741 if (!payload_ty.hasRuntimeBits(mod)) break :result mcv;
...@@ -2747,14 +2747,14 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2747,14 +2747,14 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
27472747
2748/// T to E!T2748/// T to E!T
2749fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {2749fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
2750 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2750 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2751 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion payload for {}", .{self.target.cpu.arch});2751 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion payload for {}", .{self.target.cpu.arch});
2752 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });2752 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
2753}2753}
27542754
2755fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {2755fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
2756 const mod = self.bin_file.options.module.?;2756 const mod = self.bin_file.options.module.?;
2757 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2757 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2758 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2758 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2759 const optional_ty = self.typeOfIndex(inst);2759 const optional_ty = self.typeOfIndex(inst);
27602760
...@@ -2772,7 +2772,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -2772,7 +2772,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
2772fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {2772fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
2773 const gpa = self.gpa;2773 const gpa = self.gpa;
2774 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);2774 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
2775 const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len));2775 const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len);
2776 self.mir_instructions.appendAssumeCapacity(inst);2776 self.mir_instructions.appendAssumeCapacity(inst);
2777 return result_index;2777 return result_index;
2778}2778}
...@@ -3143,9 +3143,7 @@ fn binOpImmediate(...@@ -3143,9 +3143,7 @@ fn binOpImmediate(
31433143
3144 const lhs_reg = if (lhs_is_register) lhs.register else blk: {3144 const lhs_reg = if (lhs_is_register) lhs.register else blk: {
3145 const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: {3145 const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: {
3146 break :inst Air.refToIndex(3146 break :inst (if (lhs_and_rhs_swapped) md.rhs else md.lhs).toIndex().?;
3147 if (lhs_and_rhs_swapped) md.rhs else md.lhs,
3148 ).?;
3149 } else null;3147 } else null;
31503148
3151 const reg = try self.register_manager.allocReg(track_inst, gp);3149 const reg = try self.register_manager.allocReg(track_inst, gp);
...@@ -3284,7 +3282,7 @@ fn binOpRegister(...@@ -3284,7 +3282,7 @@ fn binOpRegister(
32843282
3285 const lhs_reg = if (lhs_is_register) lhs.register else blk: {3283 const lhs_reg = if (lhs_is_register) lhs.register else blk: {
3286 const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: {3284 const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: {
3287 break :inst Air.refToIndex(md.lhs).?;3285 break :inst md.lhs.toIndex().?;
3288 } else null;3286 } else null;
32893287
3290 const reg = try self.register_manager.allocReg(track_inst, gp);3288 const reg = try self.register_manager.allocReg(track_inst, gp);
...@@ -3308,7 +3306,7 @@ fn binOpRegister(...@@ -3308,7 +3306,7 @@ fn binOpRegister(
33083306
3309 const rhs_reg = if (rhs_is_register) rhs.register else blk: {3307 const rhs_reg = if (rhs_is_register) rhs.register else blk: {
3310 const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: {3308 const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: {
3311 break :inst Air.refToIndex(md.rhs).?;3309 break :inst md.rhs.toIndex().?;
3312 } else null;3310 } else null;
33133311
3314 const reg = try self.register_manager.allocReg(track_inst, gp);3312 const reg = try self.register_manager.allocReg(track_inst, gp);
...@@ -3566,7 +3564,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live...@@ -3566,7 +3564,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
3566 const dies = @as(u1, @truncate(tomb_bits)) != 0;3564 const dies = @as(u1, @truncate(tomb_bits)) != 0;
3567 tomb_bits >>= 1;3565 tomb_bits >>= 1;
3568 if (!dies) continue;3566 if (!dies) continue;
3569 const op_index = Air.refToIndex(op) orelse continue;3567 const op_index = op.toIndex() orelse continue;
3570 self.processDeath(op_index);3568 self.processDeath(op_index);
3571 }3569 }
3572 const is_used = @as(u1, @truncate(tomb_bits)) == 0;3570 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
...@@ -3594,8 +3592,8 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live...@@ -3594,8 +3592,8 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
35943592
3595fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {3593fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {
3596 const mod = self.bin_file.options.module.?;3594 const mod = self.bin_file.options.module.?;
3597 const arg = self.air.instructions.items(.data)[inst].arg;3595 const arg = self.air.instructions.items(.data)[@intFromEnum(inst)].arg;
3598 const ty = self.air.getRefType(arg.ty);3596 const ty = arg.ty.toType();
3599 const owner_decl = mod.funcOwnerDeclIndex(self.func_index);3597 const owner_decl = mod.funcOwnerDeclIndex(self.func_index);
3600 const name = mod.getParamName(self.func_index, arg.src_index);3598 const name = mod.getParamName(self.func_index, arg.src_index);
36013599
...@@ -4411,8 +4409,8 @@ fn parseRegName(name: []const u8) ?Register {...@@ -4411,8 +4409,8 @@ fn parseRegName(name: []const u8) ?Register {
4411fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {4409fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
4412 const tag = self.mir_instructions.items(.tag)[inst];4410 const tag = self.mir_instructions.items(.tag)[inst];
4413 switch (tag) {4411 switch (tag) {
4414 .bpcc => self.mir_instructions.items(.data)[inst].branch_predict_int.inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),4412 .bpcc => self.mir_instructions.items(.data)[inst].branch_predict_int.inst = @intCast(self.mir_instructions.len),
4415 .bpr => self.mir_instructions.items(.data)[inst].branch_predict_reg.inst = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len)),4413 .bpr => self.mir_instructions.items(.data)[inst].branch_predict_reg.inst = @intCast(self.mir_instructions.len),
4416 else => unreachable,4414 else => unreachable,
4417 }4415 }
4418}4416}
...@@ -4550,7 +4548,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {...@@ -4550,7 +4548,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
4550 // If the type has no codegen bits, no need to store it.4548 // If the type has no codegen bits, no need to store it.
4551 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;4549 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
45524550
4553 if (Air.refToIndex(ref)) |inst| {4551 if (ref.toIndex()) |inst| {
4554 return self.getResolvedInstValue(inst);4552 return self.getResolvedInstValue(inst);
4555 }4553 }
45564554
...@@ -4606,7 +4604,7 @@ fn reuseOperand(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, op_ind...@@ -4606,7 +4604,7 @@ fn reuseOperand(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, op_ind
46064604
4607 // That makes us responsible for doing the rest of the stuff that processDeath would have done.4605 // That makes us responsible for doing the rest of the stuff that processDeath would have done.
4608 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];4606 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
4609 branch.inst_table.putAssumeCapacity(Air.refToIndex(operand).?, .dead);4607 branch.inst_table.putAssumeCapacity(operand.toIndex().?, .dead);
46104608
4611 return true;4609 return true;
4612}4610}
...@@ -4767,7 +4765,7 @@ fn trunc(...@@ -4767,7 +4765,7 @@ fn trunc(
4767 defer if (lock) |reg| self.register_manager.unlockReg(reg);4765 defer if (lock) |reg| self.register_manager.unlockReg(reg);
47684766
4769 const dest_reg = if (maybe_inst) |inst| blk: {4767 const dest_reg = if (maybe_inst) |inst| blk: {
4770 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4768 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
47714769
4772 if (operand == .register and self.reuseOperand(inst, ty_op.operand, 0, operand)) {4770 if (operand == .register and self.reuseOperand(inst, ty_op.operand, 0, operand)) {
4773 break :blk operand_reg;4771 break :blk operand_reg;
src/arch/wasm/CodeGen.zig+118-118
...@@ -828,7 +828,7 @@ fn finishAir(func: *CodeGen, inst: Air.Inst.Index, result: WValue, operands: []c...@@ -828,7 +828,7 @@ fn finishAir(func: *CodeGen, inst: Air.Inst.Index, result: WValue, operands: []c
828 if (result != .none) {828 if (result != .none) {
829 assert(result != .stack); // it's illegal to store a stack value as we cannot track its position829 assert(result != .stack); // it's illegal to store a stack value as we cannot track its position
830 const branch = func.currentBranch();830 const branch = func.currentBranch();
831 branch.values.putAssumeCapacityNoClobber(Air.indexToRef(inst), result);831 branch.values.putAssumeCapacityNoClobber(inst.toRef(), result);
832 }832 }
833833
834 if (builtin.mode == .Debug) {834 if (builtin.mode == .Debug) {
...@@ -864,7 +864,7 @@ const BigTomb = struct {...@@ -864,7 +864,7 @@ const BigTomb = struct {
864 fn finishAir(bt: *BigTomb, result: WValue) void {864 fn finishAir(bt: *BigTomb, result: WValue) void {
865 assert(result != .stack);865 assert(result != .stack);
866 if (result != .none) {866 if (result != .none) {
867 bt.gen.currentBranch().values.putAssumeCapacityNoClobber(Air.indexToRef(bt.inst), result);867 bt.gen.currentBranch().values.putAssumeCapacityNoClobber(bt.inst.toRef(), result);
868 }868 }
869869
870 if (builtin.mode == .Debug) {870 if (builtin.mode == .Debug) {
...@@ -883,7 +883,7 @@ fn iterateBigTomb(func: *CodeGen, inst: Air.Inst.Index, operand_count: usize) !B...@@ -883,7 +883,7 @@ fn iterateBigTomb(func: *CodeGen, inst: Air.Inst.Index, operand_count: usize) !B
883}883}
884884
885fn processDeath(func: *CodeGen, ref: Air.Inst.Ref) void {885fn processDeath(func: *CodeGen, ref: Air.Inst.Ref) void {
886 if (Air.refToIndex(ref) == null) return;886 if (ref.toIndex() == null) return;
887 // Branches are currently only allowed to free locals allocated887 // Branches are currently only allowed to free locals allocated
888 // within their own branch.888 // within their own branch.
889 // TODO: Upon branch consolidation free any locals if needed.889 // TODO: Upon branch consolidation free any locals if needed.
...@@ -893,7 +893,7 @@ fn processDeath(func: *CodeGen, ref: Air.Inst.Ref) void {...@@ -893,7 +893,7 @@ fn processDeath(func: *CodeGen, ref: Air.Inst.Ref) void {
893 if (value.local.value < reserved_indexes) {893 if (value.local.value < reserved_indexes) {
894 return; // function arguments can never be re-used894 return; // function arguments can never be re-used
895 }895 }
896 log.debug("Decreasing reference for ref: %{?d}, using local '{d}'", .{ Air.refToIndex(ref), value.local.value });896 log.debug("Decreasing reference for ref: %{d}, using local '{d}'", .{ @intFromEnum(ref.toIndex().?), value.local.value });
897 value.local.references -= 1; // if this panics, a call to `reuseOperand` was forgotten by the developer897 value.local.references -= 1; // if this panics, a call to `reuseOperand` was forgotten by the developer
898 if (value.local.references == 0) {898 if (value.local.references == 0) {
899 value.free(func);899 value.free(func);
...@@ -1265,7 +1265,7 @@ fn genFunc(func: *CodeGen) InnerError!void {...@@ -1265,7 +1265,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
1265 // In case we have a return value, but the last instruction is a noreturn (such as a while loop)1265 // In case we have a return value, but the last instruction is a noreturn (such as a while loop)
1266 // we emit an unreachable instruction to tell the stack validator that part will never be reached.1266 // we emit an unreachable instruction to tell the stack validator that part will never be reached.
1267 if (func_type.returns.len != 0 and func.air.instructions.len > 0) {1267 if (func_type.returns.len != 0 and func.air.instructions.len > 0) {
1268 const inst = @as(u32, @intCast(func.air.instructions.len - 1));1268 const inst: Air.Inst.Index = @enumFromInt(func.air.instructions.len - 1);
1269 const last_inst_ty = func.typeOfIndex(inst);1269 const last_inst_ty = func.typeOfIndex(inst);
1270 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(mod) or last_inst_ty.isNoReturn(mod)) {1270 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(mod) or last_inst_ty.isNoReturn(mod)) {
1271 try func.addTag(.@"unreachable");1271 try func.addTag(.@"unreachable");
...@@ -1828,7 +1828,7 @@ fn buildPointerOffset(func: *CodeGen, ptr_value: WValue, offset: u64, action: en...@@ -1828,7 +1828,7 @@ fn buildPointerOffset(func: *CodeGen, ptr_value: WValue, offset: u64, action: en
18281828
1829fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {1829fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
1830 const air_tags = func.air.instructions.items(.tag);1830 const air_tags = func.air.instructions.items(.tag);
1831 return switch (air_tags[inst]) {1831 return switch (air_tags[@intFromEnum(inst)]) {
1832 .inferred_alloc, .inferred_alloc_comptime => unreachable,1832 .inferred_alloc, .inferred_alloc_comptime => unreachable,
18331833
1834 .add => func.airBinOp(inst, .add),1834 .add => func.airBinOp(inst, .add),
...@@ -2086,7 +2086,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -2086,7 +2086,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2086 if (builtin.mode == .Debug and func.air_bookkeeping < old_bookkeeping_value + 1) {2086 if (builtin.mode == .Debug and func.air_bookkeeping < old_bookkeeping_value + 1) {
2087 std.debug.panic("Missing call to `finishAir` in AIR instruction %{d} ('{}')", .{2087 std.debug.panic("Missing call to `finishAir` in AIR instruction %{d} ('{}')", .{
2088 inst,2088 inst,
2089 func.air.instructions.items(.tag)[inst],2089 func.air.instructions.items(.tag)[@intFromEnum(inst)],
2090 });2090 });
2091 }2091 }
2092 }2092 }
...@@ -2094,7 +2094,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -2094,7 +2094,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
20942094
2095fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2095fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2096 const mod = func.bin_file.base.options.module.?;2096 const mod = func.bin_file.base.options.module.?;
2097 const un_op = func.air.instructions.items(.data)[inst].un_op;2097 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2098 const operand = try func.resolveInst(un_op);2098 const operand = try func.resolveInst(un_op);
2099 const fn_info = mod.typeToFunc(func.decl.ty).?;2099 const fn_info = mod.typeToFunc(func.decl.ty).?;
2100 const ret_ty = Type.fromInterned(fn_info.return_type);2100 const ret_ty = Type.fromInterned(fn_info.return_type);
...@@ -2157,7 +2157,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2157,7 +2157,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21572157
2158fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2158fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2159 const mod = func.bin_file.base.options.module.?;2159 const mod = func.bin_file.base.options.module.?;
2160 const un_op = func.air.instructions.items(.data)[inst].un_op;2160 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2161 const operand = try func.resolveInst(un_op);2161 const operand = try func.resolveInst(un_op);
2162 const ret_ty = func.typeOf(un_op).childType(mod);2162 const ret_ty = func.typeOf(un_op).childType(mod);
21632163
...@@ -2178,7 +2178,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2178,7 +2178,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21782178
2179fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) InnerError!void {2179fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) InnerError!void {
2180 if (modifier == .always_tail) return func.fail("TODO implement tail calls for wasm", .{});2180 if (modifier == .always_tail) return func.fail("TODO implement tail calls for wasm", .{});
2181 const pl_op = func.air.instructions.items(.data)[inst].pl_op;2181 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
2182 const extra = func.air.extraData(Air.Call, pl_op.payload);2182 const extra = func.air.extraData(Air.Call, pl_op.payload);
2183 const args = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[extra.end..][0..extra.data.args_len]));2183 const args = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[extra.end..][0..extra.data.args_len]));
2184 const ty = func.typeOf(pl_op.operand);2184 const ty = func.typeOf(pl_op.operand);
...@@ -2301,7 +2301,7 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void...@@ -2301,7 +2301,7 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
2301 } else {2301 } else {
2302 // TODO if the value is undef, don't lower this instruction2302 // TODO if the value is undef, don't lower this instruction
2303 }2303 }
2304 const bin_op = func.air.instructions.items(.data)[inst].bin_op;2304 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
23052305
2306 const lhs = try func.resolveInst(bin_op.lhs);2306 const lhs = try func.resolveInst(bin_op.lhs);
2307 const rhs = try func.resolveInst(bin_op.rhs);2307 const rhs = try func.resolveInst(bin_op.rhs);
...@@ -2457,9 +2457,9 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2457,9 +2457,9 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
24572457
2458fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2458fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2459 const mod = func.bin_file.base.options.module.?;2459 const mod = func.bin_file.base.options.module.?;
2460 const ty_op = func.air.instructions.items(.data)[inst].ty_op;2460 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2461 const operand = try func.resolveInst(ty_op.operand);2461 const operand = try func.resolveInst(ty_op.operand);
2462 const ty = func.air.getRefType(ty_op.ty);2462 const ty = ty_op.ty.toType();
2463 const ptr_ty = func.typeOf(ty_op.operand);2463 const ptr_ty = func.typeOf(ty_op.operand);
2464 const ptr_info = ptr_ty.ptrInfo(mod);2464 const ptr_info = ptr_ty.ptrInfo(mod);
24652465
...@@ -2569,7 +2569,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2569,7 +2569,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
25692569
2570 switch (func.debug_output) {2570 switch (func.debug_output) {
2571 .dwarf => |dwarf| {2571 .dwarf => |dwarf| {
2572 const src_index = func.air.instructions.items(.data)[inst].arg.src_index;2572 const src_index = func.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;
2573 const name = mod.getParamName(func.func_index, src_index);2573 const name = mod.getParamName(func.func_index, src_index);
2574 try dwarf.genArgDbgInfo(name, arg_ty, mod.funcOwnerDeclIndex(func.func_index), .{2574 try dwarf.genArgDbgInfo(name, arg_ty, mod.funcOwnerDeclIndex(func.func_index), .{
2575 .wasm_local = arg.local.value,2575 .wasm_local = arg.local.value,
...@@ -2583,7 +2583,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2583,7 +2583,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
25832583
2584fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {2584fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2585 const mod = func.bin_file.base.options.module.?;2585 const mod = func.bin_file.base.options.module.?;
2586 const bin_op = func.air.instructions.items(.data)[inst].bin_op;2586 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2587 const lhs = try func.resolveInst(bin_op.lhs);2587 const lhs = try func.resolveInst(bin_op.lhs);
2588 const rhs = try func.resolveInst(bin_op.rhs);2588 const rhs = try func.resolveInst(bin_op.rhs);
2589 const lhs_ty = func.typeOf(bin_op.lhs);2589 const lhs_ty = func.typeOf(bin_op.lhs);
...@@ -2789,7 +2789,7 @@ const FloatOp = enum {...@@ -2789,7 +2789,7 @@ const FloatOp = enum {
27892789
2790fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2790fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2791 const mod = func.bin_file.base.options.module.?;2791 const mod = func.bin_file.base.options.module.?;
2792 const ty_op = func.air.instructions.items(.data)[inst].ty_op;2792 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2793 const operand = try func.resolveInst(ty_op.operand);2793 const operand = try func.resolveInst(ty_op.operand);
2794 const ty = func.typeOf(ty_op.operand);2794 const ty = func.typeOf(ty_op.operand);
2795 const scalar_ty = ty.scalarType(mod);2795 const scalar_ty = ty.scalarType(mod);
...@@ -2864,7 +2864,7 @@ fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2864,7 +2864,7 @@ fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2864}2864}
28652865
2866fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError!void {2866fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError!void {
2867 const un_op = func.air.instructions.items(.data)[inst].un_op;2867 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2868 const operand = try func.resolveInst(un_op);2868 const operand = try func.resolveInst(un_op);
2869 const ty = func.typeOf(un_op);2869 const ty = func.typeOf(un_op);
28702870
...@@ -2980,7 +2980,7 @@ fn floatNeg(func: *CodeGen, ty: Type, arg: WValue) InnerError!WValue {...@@ -2980,7 +2980,7 @@ fn floatNeg(func: *CodeGen, ty: Type, arg: WValue) InnerError!WValue {
29802980
2981fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {2981fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2982 const mod = func.bin_file.base.options.module.?;2982 const mod = func.bin_file.base.options.module.?;
2983 const bin_op = func.air.instructions.items(.data)[inst].bin_op;2983 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
29842984
2985 const lhs = try func.resolveInst(bin_op.lhs);2985 const lhs = try func.resolveInst(bin_op.lhs);
2986 const rhs = try func.resolveInst(bin_op.rhs);2986 const rhs = try func.resolveInst(bin_op.rhs);
...@@ -3473,11 +3473,11 @@ fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {...@@ -3473,11 +3473,11 @@ fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {
34733473
3474fn airBlock(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3474fn airBlock(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3475 const mod = func.bin_file.base.options.module.?;3475 const mod = func.bin_file.base.options.module.?;
3476 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;3476 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3477 const block_ty = func.air.getRefType(ty_pl.ty);3477 const block_ty = ty_pl.ty.toType();
3478 const wasm_block_ty = genBlockType(block_ty, mod);3478 const wasm_block_ty = genBlockType(block_ty, mod);
3479 const extra = func.air.extraData(Air.Block, ty_pl.payload);3479 const extra = func.air.extraData(Air.Block, ty_pl.payload);
3480 const body = func.air.extra[extra.end..][0..extra.data.body_len];3480 const body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end..][0..extra.data.body_len]);
34813481
3482 // if wasm_block_ty is non-empty, we create a register to store the temporary value3482 // if wasm_block_ty is non-empty, we create a register to store the temporary value
3483 const block_result: WValue = if (wasm_block_ty != wasm.block_empty) blk: {3483 const block_result: WValue = if (wasm_block_ty != wasm.block_empty) blk: {
...@@ -3518,9 +3518,9 @@ fn endBlock(func: *CodeGen) !void {...@@ -3518,9 +3518,9 @@ fn endBlock(func: *CodeGen) !void {
3518}3518}
35193519
3520fn airLoop(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3520fn airLoop(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3521 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;3521 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3522 const loop = func.air.extraData(Air.Block, ty_pl.payload);3522 const loop = func.air.extraData(Air.Block, ty_pl.payload);
3523 const body = func.air.extra[loop.end..][0..loop.data.body_len];3523 const body: []const Air.Inst.Index = @ptrCast(func.air.extra[loop.end..][0..loop.data.body_len]);
35243524
3525 // result type of loop is always 'noreturn', meaning we can always3525 // result type of loop is always 'noreturn', meaning we can always
3526 // emit the wasm type 'block_empty'.3526 // emit the wasm type 'block_empty'.
...@@ -3535,11 +3535,11 @@ fn airLoop(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3535,11 +3535,11 @@ fn airLoop(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3535}3535}
35363536
3537fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3537fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3538 const pl_op = func.air.instructions.items(.data)[inst].pl_op;3538 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
3539 const condition = try func.resolveInst(pl_op.operand);3539 const condition = try func.resolveInst(pl_op.operand);
3540 const extra = func.air.extraData(Air.CondBr, pl_op.payload);3540 const extra = func.air.extraData(Air.CondBr, pl_op.payload);
3541 const then_body = func.air.extra[extra.end..][0..extra.data.then_body_len];3541 const then_body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end..][0..extra.data.then_body_len]);
3542 const else_body = func.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];3542 const else_body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
3543 const liveness_condbr = func.liveness.getCondBr(inst);3543 const liveness_condbr = func.liveness.getCondBr(inst);
35443544
3545 // result type is always noreturn, so use `block_empty` as type.3545 // result type is always noreturn, so use `block_empty` as type.
...@@ -3579,7 +3579,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3579,7 +3579,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3579}3579}
35803580
3581fn airCmp(func: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) InnerError!void {3581fn airCmp(func: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) InnerError!void {
3582 const bin_op = func.air.instructions.items(.data)[inst].bin_op;3582 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
35833583
3584 const lhs = try func.resolveInst(bin_op.lhs);3584 const lhs = try func.resolveInst(bin_op.lhs);
3585 const rhs = try func.resolveInst(bin_op.rhs);3585 const rhs = try func.resolveInst(bin_op.rhs);
...@@ -3705,7 +3705,7 @@ fn airCmpVector(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3705,7 +3705,7 @@ fn airCmpVector(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3705}3705}
37063706
3707fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3707fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3708 const un_op = func.air.instructions.items(.data)[inst].un_op;3708 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
3709 const operand = try func.resolveInst(un_op);3709 const operand = try func.resolveInst(un_op);
3710 const sym_index = try func.bin_file.getGlobalSymbol("__zig_errors_len", null);3710 const sym_index = try func.bin_file.getGlobalSymbol("__zig_errors_len", null);
3711 const errors_len = WValue{ .memory = sym_index };3711 const errors_len = WValue{ .memory = sym_index };
...@@ -3721,7 +3721,7 @@ fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3721,7 +3721,7 @@ fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37213721
3722fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3722fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3723 const mod = func.bin_file.base.options.module.?;3723 const mod = func.bin_file.base.options.module.?;
3724 const br = func.air.instructions.items(.data)[inst].br;3724 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;
3725 const block = func.blocks.get(br.block_inst).?;3725 const block = func.blocks.get(br.block_inst).?;
37263726
3727 // if operand has codegen bits we should break with a value3727 // if operand has codegen bits we should break with a value
...@@ -3743,7 +3743,7 @@ fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3743,7 +3743,7 @@ fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3743}3743}
37443744
3745fn airNot(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3745fn airNot(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3746 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3746 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
37473747
3748 const operand = try func.resolveInst(ty_op.operand);3748 const operand = try func.resolveInst(ty_op.operand);
3749 const operand_ty = func.typeOf(ty_op.operand);3749 const operand_ty = func.typeOf(ty_op.operand);
...@@ -3809,7 +3809,7 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3809,7 +3809,7 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3809}3809}
38103810
3811fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3811fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3812 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3812 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3813 const result = result: {3813 const result = result: {
3814 const operand = try func.resolveInst(ty_op.operand);3814 const operand = try func.resolveInst(ty_op.operand);
3815 const wanted_ty = func.typeOfIndex(inst);3815 const wanted_ty = func.typeOfIndex(inst);
...@@ -3853,7 +3853,7 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn...@@ -3853,7 +3853,7 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn
38533853
3854fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3854fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3855 const mod = func.bin_file.base.options.module.?;3855 const mod = func.bin_file.base.options.module.?;
3856 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;3856 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3857 const extra = func.air.extraData(Air.StructField, ty_pl.payload);3857 const extra = func.air.extraData(Air.StructField, ty_pl.payload);
38583858
3859 const struct_ptr = try func.resolveInst(extra.data.struct_operand);3859 const struct_ptr = try func.resolveInst(extra.data.struct_operand);
...@@ -3865,7 +3865,7 @@ fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3865,7 +3865,7 @@ fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38653865
3866fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {3866fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {
3867 const mod = func.bin_file.base.options.module.?;3867 const mod = func.bin_file.base.options.module.?;
3868 const ty_op = func.air.instructions.items(.data)[inst].ty_op;3868 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3869 const struct_ptr = try func.resolveInst(ty_op.operand);3869 const struct_ptr = try func.resolveInst(ty_op.operand);
3870 const struct_ptr_ty = func.typeOf(ty_op.operand);3870 const struct_ptr_ty = func.typeOf(ty_op.operand);
3871 const struct_ty = struct_ptr_ty.childType(mod);3871 const struct_ty = struct_ptr_ty.childType(mod);
...@@ -3916,7 +3916,7 @@ fn structFieldPtr(...@@ -3916,7 +3916,7 @@ fn structFieldPtr(
3916fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3916fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3917 const mod = func.bin_file.base.options.module.?;3917 const mod = func.bin_file.base.options.module.?;
3918 const ip = &mod.intern_pool;3918 const ip = &mod.intern_pool;
3919 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;3919 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3920 const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data;3920 const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data;
39213921
3922 const struct_ty = func.typeOf(struct_field.struct_operand);3922 const struct_ty = func.typeOf(struct_field.struct_operand);
...@@ -4016,7 +4016,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4016,7 +4016,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4016 const mod = func.bin_file.base.options.module.?;4016 const mod = func.bin_file.base.options.module.?;
4017 // result type is always 'noreturn'4017 // result type is always 'noreturn'
4018 const blocktype = wasm.block_empty;4018 const blocktype = wasm.block_empty;
4019 const pl_op = func.air.instructions.items(.data)[inst].pl_op;4019 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4020 const target = try func.resolveInst(pl_op.operand);4020 const target = try func.resolveInst(pl_op.operand);
4021 const target_ty = func.typeOf(pl_op.operand);4021 const target_ty = func.typeOf(pl_op.operand);
4022 const switch_br = func.air.extraData(Air.SwitchBr, pl_op.payload);4022 const switch_br = func.air.extraData(Air.SwitchBr, pl_op.payload);
...@@ -4040,8 +4040,8 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4040,8 +4040,8 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4040 var highest_maybe: ?i32 = null;4040 var highest_maybe: ?i32 = null;
4041 while (case_i < switch_br.data.cases_len) : (case_i += 1) {4041 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
4042 const case = func.air.extraData(Air.SwitchBr.Case, extra_index);4042 const case = func.air.extraData(Air.SwitchBr.Case, extra_index);
4043 const items = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[case.end..][0..case.data.items_len]));4043 const items: []const Air.Inst.Ref = @ptrCast(func.air.extra[case.end..][0..case.data.items_len]);
4044 const case_body = func.air.extra[case.end + items.len ..][0..case.data.body_len];4044 const case_body: []const Air.Inst.Index = @ptrCast(func.air.extra[case.end + items.len ..][0..case.data.body_len]);
4045 extra_index = case.end + items.len + case_body.len;4045 extra_index = case.end + items.len + case_body.len;
4046 const values = try func.gpa.alloc(CaseValue, items.len);4046 const values = try func.gpa.alloc(CaseValue, items.len);
4047 errdefer func.gpa.free(values);4047 errdefer func.gpa.free(values);
...@@ -4072,7 +4072,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4072,7 +4072,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4072 // TODO: Benchmark this to find a proper value, LLVM seems to draw the line at '40~45'.4072 // TODO: Benchmark this to find a proper value, LLVM seems to draw the line at '40~45'.
4073 const is_sparse = highest - lowest > 50 or target_ty.bitSize(mod) > 32;4073 const is_sparse = highest - lowest > 50 or target_ty.bitSize(mod) > 32;
40744074
4075 const else_body = func.air.extra[extra_index..][0..switch_br.data.else_body_len];4075 const else_body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra_index..][0..switch_br.data.else_body_len]);
4076 const has_else_body = else_body.len != 0;4076 const has_else_body = else_body.len != 0;
4077 if (has_else_body) {4077 if (has_else_body) {
4078 try func.startBlock(.block, blocktype);4078 try func.startBlock(.block, blocktype);
...@@ -4194,7 +4194,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4194,7 +4194,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41944194
4195fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void {4195fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void {
4196 const mod = func.bin_file.base.options.module.?;4196 const mod = func.bin_file.base.options.module.?;
4197 const un_op = func.air.instructions.items(.data)[inst].un_op;4197 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4198 const operand = try func.resolveInst(un_op);4198 const operand = try func.resolveInst(un_op);
4199 const err_union_ty = func.typeOf(un_op);4199 const err_union_ty = func.typeOf(un_op);
4200 const pl_ty = err_union_ty.errorUnionPayload(mod);4200 const pl_ty = err_union_ty.errorUnionPayload(mod);
...@@ -4229,7 +4229,7 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro...@@ -4229,7 +4229,7 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
42294229
4230fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {4230fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
4231 const mod = func.bin_file.base.options.module.?;4231 const mod = func.bin_file.base.options.module.?;
4232 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4232 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
42334233
4234 const operand = try func.resolveInst(ty_op.operand);4234 const operand = try func.resolveInst(ty_op.operand);
4235 const op_ty = func.typeOf(ty_op.operand);4235 const op_ty = func.typeOf(ty_op.operand);
...@@ -4257,7 +4257,7 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo...@@ -4257,7 +4257,7 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
42574257
4258fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {4258fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
4259 const mod = func.bin_file.base.options.module.?;4259 const mod = func.bin_file.base.options.module.?;
4260 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4260 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
42614261
4262 const operand = try func.resolveInst(ty_op.operand);4262 const operand = try func.resolveInst(ty_op.operand);
4263 const op_ty = func.typeOf(ty_op.operand);4263 const op_ty = func.typeOf(ty_op.operand);
...@@ -4281,7 +4281,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)...@@ -4281,7 +4281,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
42814281
4282fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4282fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4283 const mod = func.bin_file.base.options.module.?;4283 const mod = func.bin_file.base.options.module.?;
4284 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4284 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
42854285
4286 const operand = try func.resolveInst(ty_op.operand);4286 const operand = try func.resolveInst(ty_op.operand);
4287 const err_ty = func.typeOfIndex(inst);4287 const err_ty = func.typeOfIndex(inst);
...@@ -4311,10 +4311,10 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void...@@ -4311,10 +4311,10 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
43114311
4312fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4312fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4313 const mod = func.bin_file.base.options.module.?;4313 const mod = func.bin_file.base.options.module.?;
4314 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4314 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
43154315
4316 const operand = try func.resolveInst(ty_op.operand);4316 const operand = try func.resolveInst(ty_op.operand);
4317 const err_ty = func.air.getRefType(ty_op.ty);4317 const err_ty = ty_op.ty.toType();
4318 const pl_ty = err_ty.errorUnionPayload(mod);4318 const pl_ty = err_ty.errorUnionPayload(mod);
43194319
4320 const result = result: {4320 const result = result: {
...@@ -4337,9 +4337,9 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4337,9 +4337,9 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4337}4337}
43384338
4339fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4339fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4340 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4340 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
43414341
4342 const ty = func.air.getRefType(ty_op.ty);4342 const ty = ty_op.ty.toType();
4343 const operand = try func.resolveInst(ty_op.operand);4343 const operand = try func.resolveInst(ty_op.operand);
4344 const operand_ty = func.typeOf(ty_op.operand);4344 const operand_ty = func.typeOf(ty_op.operand);
4345 const mod = func.bin_file.base.options.module.?;4345 const mod = func.bin_file.base.options.module.?;
...@@ -4434,7 +4434,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro...@@ -4434,7 +4434,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
44344434
4435fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {4435fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {
4436 const mod = func.bin_file.base.options.module.?;4436 const mod = func.bin_file.base.options.module.?;
4437 const un_op = func.air.instructions.items(.data)[inst].un_op;4437 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4438 const operand = try func.resolveInst(un_op);4438 const operand = try func.resolveInst(un_op);
44394439
4440 const op_ty = func.typeOf(un_op);4440 const op_ty = func.typeOf(un_op);
...@@ -4476,7 +4476,7 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod...@@ -4476,7 +4476,7 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod
44764476
4477fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4477fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4478 const mod = func.bin_file.base.options.module.?;4478 const mod = func.bin_file.base.options.module.?;
4479 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4479 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4480 const opt_ty = func.typeOf(ty_op.operand);4480 const opt_ty = func.typeOf(ty_op.operand);
4481 const payload_ty = func.typeOfIndex(inst);4481 const payload_ty = func.typeOfIndex(inst);
4482 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {4482 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
...@@ -4499,7 +4499,7 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4499,7 +4499,7 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44994499
4500fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4500fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4501 const mod = func.bin_file.base.options.module.?;4501 const mod = func.bin_file.base.options.module.?;
4502 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4502 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4503 const operand = try func.resolveInst(ty_op.operand);4503 const operand = try func.resolveInst(ty_op.operand);
4504 const opt_ty = func.typeOf(ty_op.operand).childType(mod);4504 const opt_ty = func.typeOf(ty_op.operand).childType(mod);
45054505
...@@ -4516,7 +4516,7 @@ fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4516,7 +4516,7 @@ fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45164516
4517fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4517fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4518 const mod = func.bin_file.base.options.module.?;4518 const mod = func.bin_file.base.options.module.?;
4519 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4519 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4520 const operand = try func.resolveInst(ty_op.operand);4520 const operand = try func.resolveInst(ty_op.operand);
4521 const opt_ty = func.typeOf(ty_op.operand).childType(mod);4521 const opt_ty = func.typeOf(ty_op.operand).childType(mod);
4522 const payload_ty = opt_ty.optionalChild(mod);4522 const payload_ty = opt_ty.optionalChild(mod);
...@@ -4541,7 +4541,7 @@ fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi...@@ -4541,7 +4541,7 @@ fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
4541}4541}
45424542
4543fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4543fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4544 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4544 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4545 const payload_ty = func.typeOf(ty_op.operand);4545 const payload_ty = func.typeOf(ty_op.operand);
4546 const mod = func.bin_file.base.options.module.?;4546 const mod = func.bin_file.base.options.module.?;
45474547
...@@ -4578,7 +4578,7 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4578,7 +4578,7 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4578}4578}
45794579
4580fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4580fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4581 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;4581 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4582 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4582 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
45834583
4584 const lhs = try func.resolveInst(bin_op.lhs);4584 const lhs = try func.resolveInst(bin_op.lhs);
...@@ -4593,7 +4593,7 @@ fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4593,7 +4593,7 @@ fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4593}4593}
45944594
4595fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4595fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4596 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4596 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
45974597
4598 const operand = try func.resolveInst(ty_op.operand);4598 const operand = try func.resolveInst(ty_op.operand);
4599 func.finishAir(inst, try func.sliceLen(operand), &.{ty_op.operand});4599 func.finishAir(inst, try func.sliceLen(operand), &.{ty_op.operand});
...@@ -4601,7 +4601,7 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4601,7 +4601,7 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46014601
4602fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4602fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4603 const mod = func.bin_file.base.options.module.?;4603 const mod = func.bin_file.base.options.module.?;
4604 const bin_op = func.air.instructions.items(.data)[inst].bin_op;4604 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
46054605
4606 const slice_ty = func.typeOf(bin_op.lhs);4606 const slice_ty = func.typeOf(bin_op.lhs);
4607 const slice = try func.resolveInst(bin_op.lhs);4607 const slice = try func.resolveInst(bin_op.lhs);
...@@ -4631,10 +4631,10 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4631,10 +4631,10 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46314631
4632fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4632fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4633 const mod = func.bin_file.base.options.module.?;4633 const mod = func.bin_file.base.options.module.?;
4634 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;4634 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4635 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4635 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
46364636
4637 const elem_ty = func.air.getRefType(ty_pl.ty).childType(mod);4637 const elem_ty = ty_pl.ty.toType().childType(mod);
4638 const elem_size = elem_ty.abiSize(mod);4638 const elem_size = elem_ty.abiSize(mod);
46394639
4640 const slice = try func.resolveInst(bin_op.lhs);4640 const slice = try func.resolveInst(bin_op.lhs);
...@@ -4654,7 +4654,7 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4654,7 +4654,7 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4654}4654}
46554655
4656fn airSlicePtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4656fn airSlicePtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4657 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4657 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4658 const operand = try func.resolveInst(ty_op.operand);4658 const operand = try func.resolveInst(ty_op.operand);
4659 func.finishAir(inst, try func.slicePtr(operand), &.{ty_op.operand});4659 func.finishAir(inst, try func.slicePtr(operand), &.{ty_op.operand});
4660}4660}
...@@ -4670,10 +4670,10 @@ fn sliceLen(func: *CodeGen, operand: WValue) InnerError!WValue {...@@ -4670,10 +4670,10 @@ fn sliceLen(func: *CodeGen, operand: WValue) InnerError!WValue {
4670}4670}
46714671
4672fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4672fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4673 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4673 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
46744674
4675 const operand = try func.resolveInst(ty_op.operand);4675 const operand = try func.resolveInst(ty_op.operand);
4676 const wanted_ty = func.air.getRefType(ty_op.ty);4676 const wanted_ty = ty_op.ty.toType();
4677 const op_ty = func.typeOf(ty_op.operand);4677 const op_ty = func.typeOf(ty_op.operand);
46784678
4679 const result = try func.trunc(operand, wanted_ty, op_ty);4679 const result = try func.trunc(operand, wanted_ty, op_ty);
...@@ -4699,7 +4699,7 @@ fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) Inner...@@ -4699,7 +4699,7 @@ fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) Inner
4699}4699}
47004700
4701fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4701fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4702 const un_op = func.air.instructions.items(.data)[inst].un_op;4702 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4703 const operand = try func.resolveInst(un_op);4703 const operand = try func.resolveInst(un_op);
4704 const result = func.reuseOperand(un_op, operand);4704 const result = func.reuseOperand(un_op, operand);
47054705
...@@ -4708,11 +4708,11 @@ fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4708,11 +4708,11 @@ fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47084708
4709fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4709fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4710 const mod = func.bin_file.base.options.module.?;4710 const mod = func.bin_file.base.options.module.?;
4711 const ty_op = func.air.instructions.items(.data)[inst].ty_op;4711 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
47124712
4713 const operand = try func.resolveInst(ty_op.operand);4713 const operand = try func.resolveInst(ty_op.operand);
4714 const array_ty = func.typeOf(ty_op.operand).childType(mod);4714 const array_ty = func.typeOf(ty_op.operand).childType(mod);
4715 const slice_ty = func.air.getRefType(ty_op.ty);4715 const slice_ty = ty_op.ty.toType();
47164716
4717 // create a slice on the stack4717 // create a slice on the stack
4718 const slice_local = try func.allocStack(slice_ty);4718 const slice_local = try func.allocStack(slice_ty);
...@@ -4731,7 +4731,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4731,7 +4731,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47314731
4732fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4732fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4733 const mod = func.bin_file.base.options.module.?;4733 const mod = func.bin_file.base.options.module.?;
4734 const un_op = func.air.instructions.items(.data)[inst].un_op;4734 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4735 const operand = try func.resolveInst(un_op);4735 const operand = try func.resolveInst(un_op);
4736 const ptr_ty = func.typeOf(un_op);4736 const ptr_ty = func.typeOf(un_op);
4737 const result = if (ptr_ty.isSlice(mod))4737 const result = if (ptr_ty.isSlice(mod))
...@@ -4746,7 +4746,7 @@ fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4746,7 +4746,7 @@ fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47464746
4747fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4747fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4748 const mod = func.bin_file.base.options.module.?;4748 const mod = func.bin_file.base.options.module.?;
4749 const bin_op = func.air.instructions.items(.data)[inst].bin_op;4749 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
47504750
4751 const ptr_ty = func.typeOf(bin_op.lhs);4751 const ptr_ty = func.typeOf(bin_op.lhs);
4752 const ptr = try func.resolveInst(bin_op.lhs);4752 const ptr = try func.resolveInst(bin_op.lhs);
...@@ -4783,11 +4783,11 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4783,11 +4783,11 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47834783
4784fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4784fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4785 const mod = func.bin_file.base.options.module.?;4785 const mod = func.bin_file.base.options.module.?;
4786 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;4786 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4787 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4787 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
47884788
4789 const ptr_ty = func.typeOf(bin_op.lhs);4789 const ptr_ty = func.typeOf(bin_op.lhs);
4790 const elem_ty = func.air.getRefType(ty_pl.ty).childType(mod);4790 const elem_ty = ty_pl.ty.toType().childType(mod);
4791 const elem_size = elem_ty.abiSize(mod);4791 const elem_size = elem_ty.abiSize(mod);
47924792
4793 const ptr = try func.resolveInst(bin_op.lhs);4793 const ptr = try func.resolveInst(bin_op.lhs);
...@@ -4813,7 +4813,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4813,7 +4813,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48134813
4814fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {4814fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
4815 const mod = func.bin_file.base.options.module.?;4815 const mod = func.bin_file.base.options.module.?;
4816 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;4816 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4817 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4817 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
48184818
4819 const ptr = try func.resolveInst(bin_op.lhs);4819 const ptr = try func.resolveInst(bin_op.lhs);
...@@ -4846,7 +4846,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void...@@ -4846,7 +4846,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
4846 } else {4846 } else {
4847 // TODO if the value is undef, don't lower this instruction4847 // TODO if the value is undef, don't lower this instruction
4848 }4848 }
4849 const bin_op = func.air.instructions.items(.data)[inst].bin_op;4849 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
48504850
4851 const ptr = try func.resolveInst(bin_op.lhs);4851 const ptr = try func.resolveInst(bin_op.lhs);
4852 const ptr_ty = func.typeOf(bin_op.lhs);4852 const ptr_ty = func.typeOf(bin_op.lhs);
...@@ -4963,7 +4963,7 @@ fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue...@@ -4963,7 +4963,7 @@ fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue
49634963
4964fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4964fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4965 const mod = func.bin_file.base.options.module.?;4965 const mod = func.bin_file.base.options.module.?;
4966 const bin_op = func.air.instructions.items(.data)[inst].bin_op;4966 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
49674967
4968 const array_ty = func.typeOf(bin_op.lhs);4968 const array_ty = func.typeOf(bin_op.lhs);
4969 const array = try func.resolveInst(bin_op.lhs);4969 const array = try func.resolveInst(bin_op.lhs);
...@@ -5032,7 +5032,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5032,7 +5032,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50325032
5033fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5033fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5034 const mod = func.bin_file.base.options.module.?;5034 const mod = func.bin_file.base.options.module.?;
5035 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5035 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
50365036
5037 const operand = try func.resolveInst(ty_op.operand);5037 const operand = try func.resolveInst(ty_op.operand);
5038 const op_ty = func.typeOf(ty_op.operand);5038 const op_ty = func.typeOf(ty_op.operand);
...@@ -5077,7 +5077,7 @@ fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5077,7 +5077,7 @@ fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50775077
5078fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5078fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5079 const mod = func.bin_file.base.options.module.?;5079 const mod = func.bin_file.base.options.module.?;
5080 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5080 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
50815081
5082 const operand = try func.resolveInst(ty_op.operand);5082 const operand = try func.resolveInst(ty_op.operand);
5083 const op_ty = func.typeOf(ty_op.operand);5083 const op_ty = func.typeOf(ty_op.operand);
...@@ -5123,7 +5123,7 @@ fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5123,7 +5123,7 @@ fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51235123
5124fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5124fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5125 const mod = func.bin_file.base.options.module.?;5125 const mod = func.bin_file.base.options.module.?;
5126 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5126 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5127 const operand = try func.resolveInst(ty_op.operand);5127 const operand = try func.resolveInst(ty_op.operand);
5128 const ty = func.typeOfIndex(inst);5128 const ty = func.typeOfIndex(inst);
5129 const elem_ty = ty.childType(mod);5129 const elem_ty = ty.childType(mod);
...@@ -5193,7 +5193,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5193,7 +5193,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5193}5193}
51945194
5195fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5195fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5196 const pl_op = func.air.instructions.items(.data)[inst].pl_op;5196 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5197 const operand = try func.resolveInst(pl_op.operand);5197 const operand = try func.resolveInst(pl_op.operand);
51985198
5199 _ = operand;5199 _ = operand;
...@@ -5203,7 +5203,7 @@ fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5203,7 +5203,7 @@ fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5203fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5203fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5204 const mod = func.bin_file.base.options.module.?;5204 const mod = func.bin_file.base.options.module.?;
5205 const inst_ty = func.typeOfIndex(inst);5205 const inst_ty = func.typeOfIndex(inst);
5206 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5206 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5207 const extra = func.air.extraData(Air.Shuffle, ty_pl.payload).data;5207 const extra = func.air.extraData(Air.Shuffle, ty_pl.payload).data;
52085208
5209 const a = try func.resolveInst(extra.a);5209 const a = try func.resolveInst(extra.a);
...@@ -5262,7 +5262,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5262,7 +5262,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5262}5262}
52635263
5264fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5264fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5265 const reduce = func.air.instructions.items(.data)[inst].reduce;5265 const reduce = func.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
5266 const operand = try func.resolveInst(reduce.operand);5266 const operand = try func.resolveInst(reduce.operand);
52675267
5268 _ = operand;5268 _ = operand;
...@@ -5272,7 +5272,7 @@ fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5272,7 +5272,7 @@ fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5272fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5272fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5273 const mod = func.bin_file.base.options.module.?;5273 const mod = func.bin_file.base.options.module.?;
5274 const ip = &mod.intern_pool;5274 const ip = &mod.intern_pool;
5275 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5275 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5276 const result_ty = func.typeOfIndex(inst);5276 const result_ty = func.typeOfIndex(inst);
5277 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));5277 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));
5278 const elements = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[ty_pl.payload..][0..len]));5278 const elements = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[ty_pl.payload..][0..len]));
...@@ -5402,7 +5402,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5402,7 +5402,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5402fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5402fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5403 const mod = func.bin_file.base.options.module.?;5403 const mod = func.bin_file.base.options.module.?;
5404 const ip = &mod.intern_pool;5404 const ip = &mod.intern_pool;
5405 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5405 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5406 const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data;5406 const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data;
54075407
5408 const result = result: {5408 const result = result: {
...@@ -5474,12 +5474,12 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5474,12 +5474,12 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5474}5474}
54755475
5476fn airPrefetch(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5476fn airPrefetch(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5477 const prefetch = func.air.instructions.items(.data)[inst].prefetch;5477 const prefetch = func.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
5478 func.finishAir(inst, .none, &.{prefetch.ptr});5478 func.finishAir(inst, .none, &.{prefetch.ptr});
5479}5479}
54805480
5481fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5481fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5482 const pl_op = func.air.instructions.items(.data)[inst].pl_op;5482 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
54835483
5484 const result = try func.allocLocal(func.typeOfIndex(inst));5484 const result = try func.allocLocal(func.typeOfIndex(inst));
5485 try func.addLabel(.memory_size, pl_op.payload);5485 try func.addLabel(.memory_size, pl_op.payload);
...@@ -5488,7 +5488,7 @@ fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5488,7 +5488,7 @@ fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5488}5488}
54895489
5490fn airWasmMemoryGrow(func: *CodeGen, inst: Air.Inst.Index) !void {5490fn airWasmMemoryGrow(func: *CodeGen, inst: Air.Inst.Index) !void {
5491 const pl_op = func.air.instructions.items(.data)[inst].pl_op;5491 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
54925492
5493 const operand = try func.resolveInst(pl_op.operand);5493 const operand = try func.resolveInst(pl_op.operand);
5494 const result = try func.allocLocal(func.typeOfIndex(inst));5494 const result = try func.allocLocal(func.typeOfIndex(inst));
...@@ -5578,7 +5578,7 @@ fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std...@@ -5578,7 +5578,7 @@ fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std
55785578
5579fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5579fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5580 const mod = func.bin_file.base.options.module.?;5580 const mod = func.bin_file.base.options.module.?;
5581 const bin_op = func.air.instructions.items(.data)[inst].bin_op;5581 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5582 const un_ty = func.typeOf(bin_op.lhs).childType(mod);5582 const un_ty = func.typeOf(bin_op.lhs).childType(mod);
5583 const tag_ty = func.typeOf(bin_op.rhs);5583 const tag_ty = func.typeOf(bin_op.rhs);
5584 const layout = un_ty.unionGetLayout(mod);5584 const layout = un_ty.unionGetLayout(mod);
...@@ -5602,7 +5602,7 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5602,7 +5602,7 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56025602
5603fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5603fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5604 const mod = func.bin_file.base.options.module.?;5604 const mod = func.bin_file.base.options.module.?;
5605 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5605 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56065606
5607 const un_ty = func.typeOf(ty_op.operand);5607 const un_ty = func.typeOf(ty_op.operand);
5608 const tag_ty = func.typeOfIndex(inst);5608 const tag_ty = func.typeOfIndex(inst);
...@@ -5621,7 +5621,7 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5621,7 +5621,7 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5621}5621}
56225622
5623fn airFpext(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5623fn airFpext(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5624 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5624 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56255625
5626 const dest_ty = func.typeOfIndex(inst);5626 const dest_ty = func.typeOfIndex(inst);
5627 const operand = try func.resolveInst(ty_op.operand);5627 const operand = try func.resolveInst(ty_op.operand);
...@@ -5666,7 +5666,7 @@ fn fpext(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!...@@ -5666,7 +5666,7 @@ fn fpext(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!
5666}5666}
56675667
5668fn airFptrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5668fn airFptrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5669 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5669 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56705670
5671 const dest_ty = func.typeOfIndex(inst);5671 const dest_ty = func.typeOfIndex(inst);
5672 const operand = try func.resolveInst(ty_op.operand);5672 const operand = try func.resolveInst(ty_op.operand);
...@@ -5707,7 +5707,7 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro...@@ -5707,7 +5707,7 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
57075707
5708fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5708fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5709 const mod = func.bin_file.base.options.module.?;5709 const mod = func.bin_file.base.options.module.?;
5710 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5710 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
57115711
5712 const err_set_ty = func.typeOf(ty_op.operand).childType(mod);5712 const err_set_ty = func.typeOf(ty_op.operand).childType(mod);
5713 const payload_ty = err_set_ty.errorUnionPayload(mod);5713 const payload_ty = err_set_ty.errorUnionPayload(mod);
...@@ -5733,11 +5733,11 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi...@@ -5733,11 +5733,11 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
57335733
5734fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5734fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5735 const mod = func.bin_file.base.options.module.?;5735 const mod = func.bin_file.base.options.module.?;
5736 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5736 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5737 const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;5737 const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
57385738
5739 const field_ptr = try func.resolveInst(extra.field_ptr);5739 const field_ptr = try func.resolveInst(extra.field_ptr);
5740 const parent_ty = func.air.getRefType(ty_pl.ty).childType(mod);5740 const parent_ty = ty_pl.ty.toType().childType(mod);
5741 const field_offset = parent_ty.structFieldOffset(extra.field_index, mod);5741 const field_offset = parent_ty.structFieldOffset(extra.field_index, mod);
57425742
5743 const result = if (field_offset != 0) result: {5743 const result = if (field_offset != 0) result: {
...@@ -5763,7 +5763,7 @@ fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue...@@ -5763,7 +5763,7 @@ fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue
57635763
5764fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5764fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5765 const mod = func.bin_file.base.options.module.?;5765 const mod = func.bin_file.base.options.module.?;
5766 const bin_op = func.air.instructions.items(.data)[inst].bin_op;5766 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5767 const dst = try func.resolveInst(bin_op.lhs);5767 const dst = try func.resolveInst(bin_op.lhs);
5768 const dst_ty = func.typeOf(bin_op.lhs);5768 const dst_ty = func.typeOf(bin_op.lhs);
5769 const ptr_elem_ty = dst_ty.childType(mod);5769 const ptr_elem_ty = dst_ty.childType(mod);
...@@ -5803,7 +5803,7 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5803,7 +5803,7 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58035803
5804fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5804fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5805 const mod = func.bin_file.base.options.module.?;5805 const mod = func.bin_file.base.options.module.?;
5806 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5806 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
58075807
5808 const operand = try func.resolveInst(ty_op.operand);5808 const operand = try func.resolveInst(ty_op.operand);
5809 const op_ty = func.typeOf(ty_op.operand);5809 const op_ty = func.typeOf(ty_op.operand);
...@@ -5847,7 +5847,7 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5847,7 +5847,7 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5847}5847}
58485848
5849fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5849fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5850 const un_op = func.air.instructions.items(.data)[inst].un_op;5850 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
58515851
5852 const operand = try func.resolveInst(un_op);5852 const operand = try func.resolveInst(un_op);
5853 // First retrieve the symbol index to the error name table5853 // First retrieve the symbol index to the error name table
...@@ -5889,7 +5889,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5889,7 +5889,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5889}5889}
58905890
5891fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerError!void {5891fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerError!void {
5892 const ty_op = func.air.instructions.items(.data)[inst].ty_op;5892 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5893 const slice_ptr = try func.resolveInst(ty_op.operand);5893 const slice_ptr = try func.resolveInst(ty_op.operand);
5894 const result = try func.buildPointerOffset(slice_ptr, offset, .new);5894 const result = try func.buildPointerOffset(slice_ptr, offset, .new);
5895 func.finishAir(inst, result, &.{ty_op.operand});5895 func.finishAir(inst, result, &.{ty_op.operand});
...@@ -5897,7 +5897,7 @@ fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerE...@@ -5897,7 +5897,7 @@ fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerE
58975897
5898fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {5898fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
5899 assert(op == .add or op == .sub);5899 assert(op == .add or op == .sub);
5900 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;5900 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5901 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;5901 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
59025902
5903 const lhs_op = try func.resolveInst(extra.lhs);5903 const lhs_op = try func.resolveInst(extra.lhs);
...@@ -6041,7 +6041,7 @@ fn addSubWithOverflowBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type,...@@ -6041,7 +6041,7 @@ fn addSubWithOverflowBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type,
60416041
6042fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6042fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6043 const mod = func.bin_file.base.options.module.?;6043 const mod = func.bin_file.base.options.module.?;
6044 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;6044 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6045 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;6045 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
60466046
6047 const lhs = try func.resolveInst(extra.lhs);6047 const lhs = try func.resolveInst(extra.lhs);
...@@ -6097,7 +6097,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6097,7 +6097,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6097}6097}
60986098
6099fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6099fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6100 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;6100 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6101 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;6101 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
61026102
6103 const lhs = try func.resolveInst(extra.lhs);6103 const lhs = try func.resolveInst(extra.lhs);
...@@ -6275,7 +6275,7 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -6275,7 +6275,7 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
6275 assert(op == .max or op == .min);6275 assert(op == .max or op == .min);
6276 const mod = func.bin_file.base.options.module.?;6276 const mod = func.bin_file.base.options.module.?;
6277 const target = mod.getTarget();6277 const target = mod.getTarget();
6278 const bin_op = func.air.instructions.items(.data)[inst].bin_op;6278 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
62796279
6280 const ty = func.typeOfIndex(inst);6280 const ty = func.typeOfIndex(inst);
6281 if (ty.zigTypeTag(mod) == .Vector) {6281 if (ty.zigTypeTag(mod) == .Vector) {
...@@ -6318,7 +6318,7 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -6318,7 +6318,7 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
63186318
6319fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6319fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6320 const mod = func.bin_file.base.options.module.?;6320 const mod = func.bin_file.base.options.module.?;
6321 const pl_op = func.air.instructions.items(.data)[inst].pl_op;6321 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6322 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;6322 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;
63236323
6324 const ty = func.typeOfIndex(inst);6324 const ty = func.typeOfIndex(inst);
...@@ -6352,7 +6352,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6352,7 +6352,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63526352
6353fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6353fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6354 const mod = func.bin_file.base.options.module.?;6354 const mod = func.bin_file.base.options.module.?;
6355 const ty_op = func.air.instructions.items(.data)[inst].ty_op;6355 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
63566356
6357 const ty = func.typeOf(ty_op.operand);6357 const ty = func.typeOf(ty_op.operand);
6358 const result_ty = func.typeOfIndex(inst);6358 const result_ty = func.typeOfIndex(inst);
...@@ -6405,7 +6405,7 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6405,7 +6405,7 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64056405
6406fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6406fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6407 const mod = func.bin_file.base.options.module.?;6407 const mod = func.bin_file.base.options.module.?;
6408 const ty_op = func.air.instructions.items(.data)[inst].ty_op;6408 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
64096409
6410 const ty = func.typeOf(ty_op.operand);6410 const ty = func.typeOf(ty_op.operand);
6411 const result_ty = func.typeOfIndex(inst);6411 const result_ty = func.typeOfIndex(inst);
...@@ -6472,7 +6472,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {...@@ -6472,7 +6472,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
6472 if (func.debug_output != .dwarf) return func.finishAir(inst, .none, &.{});6472 if (func.debug_output != .dwarf) return func.finishAir(inst, .none, &.{});
64736473
6474 const mod = func.bin_file.base.options.module.?;6474 const mod = func.bin_file.base.options.module.?;
6475 const pl_op = func.air.instructions.items(.data)[inst].pl_op;6475 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6476 const ty = func.typeOf(pl_op.operand);6476 const ty = func.typeOf(pl_op.operand);
6477 const operand = try func.resolveInst(pl_op.operand);6477 const operand = try func.resolveInst(pl_op.operand);
64786478
...@@ -6496,7 +6496,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {...@@ -6496,7 +6496,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
6496fn airDbgStmt(func: *CodeGen, inst: Air.Inst.Index) !void {6496fn airDbgStmt(func: *CodeGen, inst: Air.Inst.Index) !void {
6497 if (func.debug_output != .dwarf) return func.finishAir(inst, .none, &.{});6497 if (func.debug_output != .dwarf) return func.finishAir(inst, .none, &.{});
64986498
6499 const dbg_stmt = func.air.instructions.items(.data)[inst].dbg_stmt;6499 const dbg_stmt = func.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
6500 try func.addInst(.{ .tag = .dbg_line, .data = .{6500 try func.addInst(.{ .tag = .dbg_line, .data = .{
6501 .payload = try func.addExtra(Mir.DbgLineColumn{6501 .payload = try func.addExtra(Mir.DbgLineColumn{
6502 .line = dbg_stmt.line,6502 .line = dbg_stmt.line,
...@@ -6507,10 +6507,10 @@ fn airDbgStmt(func: *CodeGen, inst: Air.Inst.Index) !void {...@@ -6507,10 +6507,10 @@ fn airDbgStmt(func: *CodeGen, inst: Air.Inst.Index) !void {
6507}6507}
65086508
6509fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6509fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6510 const pl_op = func.air.instructions.items(.data)[inst].pl_op;6510 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6511 const err_union = try func.resolveInst(pl_op.operand);6511 const err_union = try func.resolveInst(pl_op.operand);
6512 const extra = func.air.extraData(Air.Try, pl_op.payload);6512 const extra = func.air.extraData(Air.Try, pl_op.payload);
6513 const body = func.air.extra[extra.end..][0..extra.data.body_len];6513 const body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end..][0..extra.data.body_len]);
6514 const err_union_ty = func.typeOf(pl_op.operand);6514 const err_union_ty = func.typeOf(pl_op.operand);
6515 const result = try lowerTry(func, inst, err_union, body, err_union_ty, false);6515 const result = try lowerTry(func, inst, err_union, body, err_union_ty, false);
6516 func.finishAir(inst, result, &.{pl_op.operand});6516 func.finishAir(inst, result, &.{pl_op.operand});
...@@ -6518,10 +6518,10 @@ fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6518,10 +6518,10 @@ fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
65186518
6519fn airTryPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6519fn airTryPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6520 const mod = func.bin_file.base.options.module.?;6520 const mod = func.bin_file.base.options.module.?;
6521 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;6521 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6522 const extra = func.air.extraData(Air.TryPtr, ty_pl.payload);6522 const extra = func.air.extraData(Air.TryPtr, ty_pl.payload);
6523 const err_union_ptr = try func.resolveInst(extra.data.ptr);6523 const err_union_ptr = try func.resolveInst(extra.data.ptr);
6524 const body = func.air.extra[extra.end..][0..extra.data.body_len];6524 const body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end..][0..extra.data.body_len]);
6525 const err_union_ty = func.typeOf(extra.data.ptr).childType(mod);6525 const err_union_ty = func.typeOf(extra.data.ptr).childType(mod);
6526 const result = try lowerTry(func, inst, err_union_ptr, body, err_union_ty, true);6526 const result = try lowerTry(func, inst, err_union_ptr, body, err_union_ty, true);
6527 func.finishAir(inst, result, &.{extra.data.ptr});6527 func.finishAir(inst, result, &.{extra.data.ptr});
...@@ -6585,7 +6585,7 @@ fn lowerTry(...@@ -6585,7 +6585,7 @@ fn lowerTry(
65856585
6586fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6586fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6587 const mod = func.bin_file.base.options.module.?;6587 const mod = func.bin_file.base.options.module.?;
6588 const ty_op = func.air.instructions.items(.data)[inst].ty_op;6588 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
65896589
6590 const ty = func.typeOfIndex(inst);6590 const ty = func.typeOfIndex(inst);
6591 const operand = try func.resolveInst(ty_op.operand);6591 const operand = try func.resolveInst(ty_op.operand);
...@@ -6656,7 +6656,7 @@ fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6656,7 +6656,7 @@ fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66566656
6657fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6657fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6658 const mod = func.bin_file.base.options.module.?;6658 const mod = func.bin_file.base.options.module.?;
6659 const bin_op = func.air.instructions.items(.data)[inst].bin_op;6659 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
66606660
6661 const ty = func.typeOfIndex(inst);6661 const ty = func.typeOfIndex(inst);
6662 const lhs = try func.resolveInst(bin_op.lhs);6662 const lhs = try func.resolveInst(bin_op.lhs);
...@@ -6671,7 +6671,7 @@ fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6671,7 +6671,7 @@ fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66716671
6672fn airDivTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6672fn airDivTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6673 const mod = func.bin_file.base.options.module.?;6673 const mod = func.bin_file.base.options.module.?;
6674 const bin_op = func.air.instructions.items(.data)[inst].bin_op;6674 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
66756675
6676 const ty = func.typeOfIndex(inst);6676 const ty = func.typeOfIndex(inst);
6677 const lhs = try func.resolveInst(bin_op.lhs);6677 const lhs = try func.resolveInst(bin_op.lhs);
...@@ -6691,7 +6691,7 @@ fn airDivTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6691,7 +6691,7 @@ fn airDivTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6691}6691}
66926692
6693fn airDivFloor(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6693fn airDivFloor(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6694 const bin_op = func.air.instructions.items(.data)[inst].bin_op;6694 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
66956695
6696 const mod = func.bin_file.base.options.module.?;6696 const mod = func.bin_file.base.options.module.?;
6697 const ty = func.typeOfIndex(inst);6697 const ty = func.typeOfIndex(inst);
...@@ -6834,7 +6834,7 @@ fn divSigned(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type) InnerError!WVal...@@ -6834,7 +6834,7 @@ fn divSigned(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type) InnerError!WVal
6834/// Remainder after floor division, defined by:6834/// Remainder after floor division, defined by:
6835/// @divFloor(a, b) * b + @mod(a, b) = a6835/// @divFloor(a, b) * b + @mod(a, b) = a
6836fn airMod(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6836fn airMod(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6837 const bin_op = func.air.instructions.items(.data)[inst].bin_op;6837 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
68386838
6839 const mod = func.bin_file.base.options.module.?;6839 const mod = func.bin_file.base.options.module.?;
6840 const ty = func.typeOfIndex(inst);6840 const ty = func.typeOfIndex(inst);
...@@ -6917,7 +6917,7 @@ fn signExtendInt(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {...@@ -6917,7 +6917,7 @@ fn signExtendInt(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
69176917
6918fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {6918fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
6919 assert(op == .add or op == .sub);6919 assert(op == .add or op == .sub);
6920 const bin_op = func.air.instructions.items(.data)[inst].bin_op;6920 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
69216921
6922 const mod = func.bin_file.base.options.module.?;6922 const mod = func.bin_file.base.options.module.?;
6923 const ty = func.typeOfIndex(inst);6923 const ty = func.typeOfIndex(inst);
...@@ -7032,7 +7032,7 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type,...@@ -7032,7 +7032,7 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type,
7032}7032}
70337033
7034fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7034fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7035 const bin_op = func.air.instructions.items(.data)[inst].bin_op;7035 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
70367036
7037 const mod = func.bin_file.base.options.module.?;7037 const mod = func.bin_file.base.options.module.?;
7038 const ty = func.typeOfIndex(inst);7038 const ty = func.typeOfIndex(inst);
...@@ -7193,7 +7193,7 @@ fn callIntrinsic(...@@ -7193,7 +7193,7 @@ fn callIntrinsic(
7193}7193}
71947194
7195fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7195fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7196 const un_op = func.air.instructions.items(.data)[inst].un_op;7196 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
7197 const operand = try func.resolveInst(un_op);7197 const operand = try func.resolveInst(un_op);
7198 const enum_ty = func.typeOf(un_op);7198 const enum_ty = func.typeOf(un_op);
71997199
...@@ -7365,10 +7365,10 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7365,10 +7365,10 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
73657365
7366fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7366fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7367 const mod = func.bin_file.base.options.module.?;7367 const mod = func.bin_file.base.options.module.?;
7368 const ty_op = func.air.instructions.items(.data)[inst].ty_op;7368 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73697369
7370 const operand = try func.resolveInst(ty_op.operand);7370 const operand = try func.resolveInst(ty_op.operand);
7371 const error_set_ty = func.air.getRefType(ty_op.ty);7371 const error_set_ty = ty_op.ty.toType();
7372 const result = try func.allocLocal(Type.bool);7372 const result = try func.allocLocal(Type.bool);
73737373
7374 const names = error_set_ty.errorSetNames(mod);7374 const names = error_set_ty.errorSetNames(mod);
...@@ -7450,7 +7450,7 @@ inline fn useAtomicFeature(func: *const CodeGen) bool {...@@ -7450,7 +7450,7 @@ inline fn useAtomicFeature(func: *const CodeGen) bool {
74507450
7451fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7451fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7452 const mod = func.bin_file.base.options.module.?;7452 const mod = func.bin_file.base.options.module.?;
7453 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;7453 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7454 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;7454 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
74557455
7456 const ptr_ty = func.typeOf(extra.ptr);7456 const ptr_ty = func.typeOf(extra.ptr);
...@@ -7523,7 +7523,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7523,7 +7523,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75237523
7524fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7524fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7525 const mod = func.bin_file.base.options.module.?;7525 const mod = func.bin_file.base.options.module.?;
7526 const atomic_load = func.air.instructions.items(.data)[inst].atomic_load;7526 const atomic_load = func.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
7527 const ptr = try func.resolveInst(atomic_load.ptr);7527 const ptr = try func.resolveInst(atomic_load.ptr);
7528 const ty = func.typeOfIndex(inst);7528 const ty = func.typeOfIndex(inst);
75297529
...@@ -7550,7 +7550,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7550,7 +7550,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75507550
7551fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7551fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7552 const mod = func.bin_file.base.options.module.?;7552 const mod = func.bin_file.base.options.module.?;
7553 const pl_op = func.air.instructions.items(.data)[inst].pl_op;7553 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7554 const extra = func.air.extraData(Air.AtomicRmw, pl_op.payload).data;7554 const extra = func.air.extraData(Air.AtomicRmw, pl_op.payload).data;
75557555
7556 const ptr = try func.resolveInst(pl_op.operand);7556 const ptr = try func.resolveInst(pl_op.operand);
...@@ -7736,7 +7736,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7736,7 +7736,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77367736
7737fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7737fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7738 const mod = func.bin_file.base.options.module.?;7738 const mod = func.bin_file.base.options.module.?;
7739 const bin_op = func.air.instructions.items(.data)[inst].bin_op;7739 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
77407740
7741 const ptr = try func.resolveInst(bin_op.lhs);7741 const ptr = try func.resolveInst(bin_op.lhs);
7742 const operand = try func.resolveInst(bin_op.rhs);7742 const operand = try func.resolveInst(bin_op.rhs);
src/arch/x86_64/CodeGen.zig+145-141
...@@ -1901,7 +1901,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -1901,7 +1901,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
19011901
1902 const old_air_bookkeeping = self.air_bookkeeping;1902 const old_air_bookkeeping = self.air_bookkeeping;
1903 try self.inst_tracking.ensureUnusedCapacity(self.gpa, 1);1903 try self.inst_tracking.ensureUnusedCapacity(self.gpa, 1);
1904 switch (air_tags[inst]) {1904 switch (air_tags[@intFromEnum(inst)]) {
1905 // zig fmt: off1905 // zig fmt: off
1906 .not,1906 .not,
1907 => |tag| try self.airUnOp(inst, tag),1907 => |tag| try self.airUnOp(inst, tag),
...@@ -2148,7 +2148,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -2148,7 +2148,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
21482148
2149 if (std.debug.runtime_safety) {2149 if (std.debug.runtime_safety) {
2150 if (self.air_bookkeeping < old_air_bookkeeping + 1) {2150 if (self.air_bookkeeping < old_air_bookkeeping + 1) {
2151 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] });2151 std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] });
2152 }2152 }
21532153
2154 { // check consistency of tracked registers2154 { // check consistency of tracked registers
...@@ -2251,7 +2251,7 @@ fn freeValue(self: *Self, value: MCValue) !void {...@@ -2251,7 +2251,7 @@ fn freeValue(self: *Self, value: MCValue) !void {
2251}2251}
22522252
2253fn feed(self: *Self, bt: *Liveness.BigTomb, operand: Air.Inst.Ref) !void {2253fn feed(self: *Self, bt: *Liveness.BigTomb, operand: Air.Inst.Ref) !void {
2254 if (bt.feed()) if (Air.refToIndex(operand)) |inst| try self.processDeath(inst);2254 if (bt.feed()) if (operand.toIndex()) |inst| try self.processDeath(inst);
2255}2255}
22562256
2257/// Asserts there is already capacity to insert into top branch inst_table.2257/// Asserts there is already capacity to insert into top branch inst_table.
...@@ -2292,7 +2292,7 @@ fn finishAir(...@@ -2292,7 +2292,7 @@ fn finishAir(
2292 const dies = @as(u1, @truncate(tomb_bits)) != 0;2292 const dies = @as(u1, @truncate(tomb_bits)) != 0;
2293 tomb_bits >>= 1;2293 tomb_bits >>= 1;
2294 if (!dies) continue;2294 if (!dies) continue;
2295 try self.processDeath(Air.refToIndexAllowNone(op) orelse continue);2295 try self.processDeath(op.toIndexAllowNone() orelse continue);
2296 }2296 }
2297 self.finishAirResult(inst, result);2297 self.finishAirResult(inst, result);
2298}2298}
...@@ -2683,7 +2683,7 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2683,7 +2683,7 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
2683}2683}
26842684
2685fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {2685fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
2686 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2686 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2687 const dst_ty = self.typeOfIndex(inst);2687 const dst_ty = self.typeOfIndex(inst);
2688 const dst_bits = dst_ty.floatBits(self.target.*);2688 const dst_bits = dst_ty.floatBits(self.target.*);
2689 const src_ty = self.typeOf(ty_op.operand);2689 const src_ty = self.typeOf(ty_op.operand);
...@@ -2782,7 +2782,7 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -2782,7 +2782,7 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
2782}2782}
27832783
2784fn airFpext(self: *Self, inst: Air.Inst.Index) !void {2784fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
2785 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2785 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2786 const dst_ty = self.typeOfIndex(inst);2786 const dst_ty = self.typeOfIndex(inst);
2787 const dst_bits = dst_ty.floatBits(self.target.*);2787 const dst_bits = dst_ty.floatBits(self.target.*);
2788 const src_ty = self.typeOf(ty_op.operand);2788 const src_ty = self.typeOf(ty_op.operand);
...@@ -2882,7 +2882,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {...@@ -2882,7 +2882,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
28822882
2883fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {2883fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
2884 const mod = self.bin_file.options.module.?;2884 const mod = self.bin_file.options.module.?;
2885 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2885 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2886 const result: MCValue = result: {2886 const result: MCValue = result: {
2887 const src_ty = self.typeOf(ty_op.operand);2887 const src_ty = self.typeOf(ty_op.operand);
2888 const src_int_info = src_ty.intInfo(mod);2888 const src_int_info = src_ty.intInfo(mod);
...@@ -2973,7 +2973,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -2973,7 +2973,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
29732973
2974fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {2974fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
2975 const mod = self.bin_file.options.module.?;2975 const mod = self.bin_file.options.module.?;
2976 const ty_op = self.air.instructions.items(.data)[inst].ty_op;2976 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
29772977
2978 const dst_ty = self.typeOfIndex(inst);2978 const dst_ty = self.typeOfIndex(inst);
2979 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(mod));2979 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(mod));
...@@ -3086,7 +3086,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -3086,7 +3086,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
3086}3086}
30873087
3088fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {3088fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
3089 const un_op = self.air.instructions.items(.data)[inst].un_op;3089 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
3090 const ty = self.typeOfIndex(inst);3090 const ty = self.typeOfIndex(inst);
30913091
3092 const operand = try self.resolveInst(un_op);3092 const operand = try self.resolveInst(un_op);
...@@ -3100,7 +3100,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {...@@ -3100,7 +3100,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
31003100
3101fn airSlice(self: *Self, inst: Air.Inst.Index) !void {3101fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
3102 const mod = self.bin_file.options.module.?;3102 const mod = self.bin_file.options.module.?;
3103 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3103 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3104 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3104 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
31053105
3106 const slice_ty = self.typeOfIndex(inst);3106 const slice_ty = self.typeOfIndex(inst);
...@@ -3123,14 +3123,14 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -3123,14 +3123,14 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
3123}3123}
31243124
3125fn airUnOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {3125fn airUnOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
3126 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3126 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3127 const dst_mcv = try self.genUnOp(inst, tag, ty_op.operand);3127 const dst_mcv = try self.genUnOp(inst, tag, ty_op.operand);
3128 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });3128 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });
3129}3129}
31303130
3131fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {3131fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
3132 const mod = self.bin_file.options.module.?;3132 const mod = self.bin_file.options.module.?;
3133 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3133 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3134 const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs);3134 const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs);
31353135
3136 const dst_ty = self.typeOfIndex(inst);3136 const dst_ty = self.typeOfIndex(inst);
...@@ -3163,7 +3163,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {...@@ -3163,7 +3163,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
3163}3163}
31643164
3165fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {3165fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
3166 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3166 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3167 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3167 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3168 const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs);3168 const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs);
3169 return self.finishAir(inst, dst_mcv, .{ bin_op.lhs, bin_op.rhs, .none });3169 return self.finishAir(inst, dst_mcv, .{ bin_op.lhs, bin_op.rhs, .none });
...@@ -3176,10 +3176,10 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {...@@ -3176,10 +3176,10 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
31763176
3177 const dst_ty = self.typeOf(dst_air);3177 const dst_ty = self.typeOf(dst_air);
3178 const dst_info = dst_ty.intInfo(mod);3178 const dst_info = dst_ty.intInfo(mod);
3179 if (Air.refToIndex(dst_air)) |inst| {3179 if (dst_air.toIndex()) |inst| {
3180 switch (air_tag[inst]) {3180 switch (air_tag[@intFromEnum(inst)]) {
3181 .intcast => {3181 .intcast => {
3182 const src_ty = self.typeOf(air_data[inst].ty_op.operand);3182 const src_ty = self.typeOf(air_data[@intFromEnum(inst)].ty_op.operand);
3183 const src_info = src_ty.intInfo(mod);3183 const src_info = src_ty.intInfo(mod);
3184 return @min(switch (src_info.signedness) {3184 return @min(switch (src_info.signedness) {
3185 .signed => switch (dst_info.signedness) {3185 .signed => switch (dst_info.signedness) {
...@@ -3194,7 +3194,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {...@@ -3194,7 +3194,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
3194 },3194 },
3195 else => {},3195 else => {},
3196 }3196 }
3197 } else if (Air.refToInterned(dst_air)) |ip_index| {3197 } else if (dst_air.toInterned()) |ip_index| {
3198 var space: Value.BigIntSpace = undefined;3198 var space: Value.BigIntSpace = undefined;
3199 const src_int = Value.fromInterned(ip_index).toBigInt(&space, mod);3199 const src_int = Value.fromInterned(ip_index).toBigInt(&space, mod);
3200 return @as(u16, @intCast(src_int.bitCountTwosComp())) +3200 return @as(u16, @intCast(src_int.bitCountTwosComp())) +
...@@ -3205,9 +3205,9 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {...@@ -3205,9 +3205,9 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
32053205
3206fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {3206fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
3207 const mod = self.bin_file.options.module.?;3207 const mod = self.bin_file.options.module.?;
3208 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3208 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3209 const result = result: {3209 const result = result: {
3210 const tag = self.air.instructions.items(.tag)[inst];3210 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
3211 const dst_ty = self.typeOfIndex(inst);3211 const dst_ty = self.typeOfIndex(inst);
3212 switch (dst_ty.zigTypeTag(mod)) {3212 switch (dst_ty.zigTypeTag(mod)) {
3213 .Float, .Vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs),3213 .Float, .Vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs),
...@@ -3431,7 +3431,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -3431,7 +3431,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
34313431
3432fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {3432fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
3433 const mod = self.bin_file.options.module.?;3433 const mod = self.bin_file.options.module.?;
3434 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3434 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3435 const ty = self.typeOf(bin_op.lhs);3435 const ty = self.typeOf(bin_op.lhs);
3436 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail(3436 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail(
3437 "TODO implement airAddSat for {}",3437 "TODO implement airAddSat for {}",
...@@ -3514,7 +3514,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3514,7 +3514,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
35143514
3515fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {3515fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
3516 const mod = self.bin_file.options.module.?;3516 const mod = self.bin_file.options.module.?;
3517 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3517 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3518 const ty = self.typeOf(bin_op.lhs);3518 const ty = self.typeOf(bin_op.lhs);
3519 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail(3519 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail(
3520 "TODO implement airSubSat for {}",3520 "TODO implement airSubSat for {}",
...@@ -3590,7 +3590,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3590,7 +3590,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
35903590
3591fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {3591fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
3592 const mod = self.bin_file.options.module.?;3592 const mod = self.bin_file.options.module.?;
3593 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3593 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3594 const ty = self.typeOf(bin_op.lhs);3594 const ty = self.typeOf(bin_op.lhs);
35953595
3596 const result = result: {3596 const result = result: {
...@@ -3730,10 +3730,10 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3730,10 +3730,10 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
37303730
3731fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {3731fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
3732 const mod = self.bin_file.options.module.?;3732 const mod = self.bin_file.options.module.?;
3733 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3733 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3734 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3734 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3735 const result: MCValue = result: {3735 const result: MCValue = result: {
3736 const tag = self.air.instructions.items(.tag)[inst];3736 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
3737 const ty = self.typeOf(bin_op.lhs);3737 const ty = self.typeOf(bin_op.lhs);
3738 switch (ty.zigTypeTag(mod)) {3738 switch (ty.zigTypeTag(mod)) {
3739 .Vector => return self.fail("TODO implement add/sub with overflow for Vector type", .{}),3739 .Vector => return self.fail("TODO implement add/sub with overflow for Vector type", .{}),
...@@ -3791,7 +3791,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -3791,7 +3791,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
37913791
3792fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {3792fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
3793 const mod = self.bin_file.options.module.?;3793 const mod = self.bin_file.options.module.?;
3794 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3794 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3795 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3795 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3796 const result: MCValue = result: {3796 const result: MCValue = result: {
3797 const lhs_ty = self.typeOf(bin_op.lhs);3797 const lhs_ty = self.typeOf(bin_op.lhs);
...@@ -3934,7 +3934,7 @@ fn genSetFrameTruncatedOverflowCompare(...@@ -3934,7 +3934,7 @@ fn genSetFrameTruncatedOverflowCompare(
39343934
3935fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {3935fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
3936 const mod = self.bin_file.options.module.?;3936 const mod = self.bin_file.options.module.?;
3937 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3937 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3938 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3938 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3939 const tuple_ty = self.typeOfIndex(inst);3939 const tuple_ty = self.typeOfIndex(inst);
3940 const dst_ty = self.typeOf(bin_op.lhs);3940 const dst_ty = self.typeOf(bin_op.lhs);
...@@ -4270,10 +4270,10 @@ fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCVa...@@ -4270,10 +4270,10 @@ fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCVa
42704270
4271fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {4271fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
4272 const mod = self.bin_file.options.module.?;4272 const mod = self.bin_file.options.module.?;
4273 const bin_op = self.air.instructions.items(.data)[inst].bin_op;4273 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
42744274
4275 const air_tags = self.air.instructions.items(.tag);4275 const air_tags = self.air.instructions.items(.tag);
4276 const tag = air_tags[inst];4276 const tag = air_tags[@intFromEnum(inst)];
4277 const lhs_ty = self.typeOf(bin_op.lhs);4277 const lhs_ty = self.typeOf(bin_op.lhs);
4278 const rhs_ty = self.typeOf(bin_op.rhs);4278 const rhs_ty = self.typeOf(bin_op.rhs);
4279 const result: MCValue = result: {4279 const result: MCValue = result: {
...@@ -4449,7 +4449,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -4449,7 +4449,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
4449 },4449 },
4450 else => {},4450 else => {},
4451 }4451 }
4452 } else if (Air.refToIndex(bin_op.rhs)) |rhs_inst| switch (air_tags[rhs_inst]) {4452 } else if (bin_op.rhs.toIndex()) |rhs_inst| switch (air_tags[@intFromEnum(rhs_inst)]) {
4453 .splat => {4453 .splat => {
4454 const abi_size: u32 = @intCast(lhs_ty.abiSize(mod));4454 const abi_size: u32 = @intCast(lhs_ty.abiSize(mod));
44554455
...@@ -4537,7 +4537,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -4537,7 +4537,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
4537}4537}
45384538
4539fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {4539fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
4540 const bin_op = self.air.instructions.items(.data)[inst].bin_op;4540 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4541 _ = bin_op;4541 _ = bin_op;
4542 return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});4542 return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
4543 //return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });4543 //return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
...@@ -4545,7 +4545,7 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -4545,7 +4545,7 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
45454545
4546fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {4546fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
4547 const mod = self.bin_file.options.module.?;4547 const mod = self.bin_file.options.module.?;
4548 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4548 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4549 const result: MCValue = result: {4549 const result: MCValue = result: {
4550 const pl_ty = self.typeOfIndex(inst);4550 const pl_ty = self.typeOfIndex(inst);
4551 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none;4551 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none;
...@@ -4577,7 +4577,7 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -4577,7 +4577,7 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
4577}4577}
45784578
4579fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {4579fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
4580 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4580 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
45814581
4582 const dst_ty = self.typeOfIndex(inst);4582 const dst_ty = self.typeOfIndex(inst);
4583 const opt_mcv = try self.resolveInst(ty_op.operand);4583 const opt_mcv = try self.resolveInst(ty_op.operand);
...@@ -4591,7 +4591,7 @@ fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4591,7 +4591,7 @@ fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
45914591
4592fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {4592fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
4593 const mod = self.bin_file.options.module.?;4593 const mod = self.bin_file.options.module.?;
4594 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4594 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4595 const result = result: {4595 const result = result: {
4596 const dst_ty = self.typeOfIndex(inst);4596 const dst_ty = self.typeOfIndex(inst);
4597 const src_ty = self.typeOf(ty_op.operand);4597 const src_ty = self.typeOf(ty_op.operand);
...@@ -4625,7 +4625,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {...@@ -4625,7 +4625,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
46254625
4626fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {4626fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
4627 const mod = self.bin_file.options.module.?;4627 const mod = self.bin_file.options.module.?;
4628 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4628 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4629 const err_union_ty = self.typeOf(ty_op.operand);4629 const err_union_ty = self.typeOf(ty_op.operand);
4630 const err_ty = err_union_ty.errorUnionSet(mod);4630 const err_ty = err_union_ty.errorUnionSet(mod);
4631 const payload_ty = err_union_ty.errorUnionPayload(mod);4631 const payload_ty = err_union_ty.errorUnionPayload(mod);
...@@ -4667,7 +4667,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4667,7 +4667,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
4667}4667}
46684668
4669fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {4669fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
4670 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4670 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4671 const operand_ty = self.typeOf(ty_op.operand);4671 const operand_ty = self.typeOf(ty_op.operand);
4672 const operand = try self.resolveInst(ty_op.operand);4672 const operand = try self.resolveInst(ty_op.operand);
4673 const result = try self.genUnwrapErrUnionPayloadMir(inst, operand_ty, operand);4673 const result = try self.genUnwrapErrUnionPayloadMir(inst, operand_ty, operand);
...@@ -4677,7 +4677,7 @@ fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -4677,7 +4677,7 @@ fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
4677// *(E!T) -> E4677// *(E!T) -> E
4678fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {4678fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4679 const mod = self.bin_file.options.module.?;4679 const mod = self.bin_file.options.module.?;
4680 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4680 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
46814681
4682 const src_ty = self.typeOf(ty_op.operand);4682 const src_ty = self.typeOf(ty_op.operand);
4683 const src_mcv = try self.resolveInst(ty_op.operand);4683 const src_mcv = try self.resolveInst(ty_op.operand);
...@@ -4715,7 +4715,7 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4715,7 +4715,7 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
47154715
4716// *(E!T) -> *T4716// *(E!T) -> *T
4717fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {4717fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
4718 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4718 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4719 const operand_ty = self.typeOf(ty_op.operand);4719 const operand_ty = self.typeOf(ty_op.operand);
4720 const operand = try self.resolveInst(ty_op.operand);4720 const operand = try self.resolveInst(ty_op.operand);
4721 const result = try self.genUnwrapErrUnionPayloadPtrMir(inst, operand_ty, operand);4721 const result = try self.genUnwrapErrUnionPayloadPtrMir(inst, operand_ty, operand);
...@@ -4724,7 +4724,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4724,7 +4724,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
47244724
4725fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {4725fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
4726 const mod = self.bin_file.options.module.?;4726 const mod = self.bin_file.options.module.?;
4727 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4727 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4728 const result: MCValue = result: {4728 const result: MCValue = result: {
4729 const src_ty = self.typeOf(ty_op.operand);4729 const src_ty = self.typeOf(ty_op.operand);
4730 const src_mcv = try self.resolveInst(ty_op.operand);4730 const src_mcv = try self.resolveInst(ty_op.operand);
...@@ -4866,7 +4866,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {...@@ -4866,7 +4866,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
48664866
4867fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {4867fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
4868 const mod = self.bin_file.options.module.?;4868 const mod = self.bin_file.options.module.?;
4869 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4869 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4870 const result: MCValue = result: {4870 const result: MCValue = result: {
4871 const pl_ty = self.typeOf(ty_op.operand);4871 const pl_ty = self.typeOf(ty_op.operand);
4872 if (!pl_ty.hasRuntimeBits(mod)) break :result .{ .immediate = 1 };4872 if (!pl_ty.hasRuntimeBits(mod)) break :result .{ .immediate = 1 };
...@@ -4920,9 +4920,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -4920,9 +4920,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
4920/// T to E!T4920/// T to E!T
4921fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {4921fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
4922 const mod = self.bin_file.options.module.?;4922 const mod = self.bin_file.options.module.?;
4923 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4923 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
49244924
4925 const eu_ty = self.air.getRefType(ty_op.ty);4925 const eu_ty = ty_op.ty.toType();
4926 const pl_ty = eu_ty.errorUnionPayload(mod);4926 const pl_ty = eu_ty.errorUnionPayload(mod);
4927 const err_ty = eu_ty.errorUnionSet(mod);4927 const err_ty = eu_ty.errorUnionSet(mod);
4928 const operand = try self.resolveInst(ty_op.operand);4928 const operand = try self.resolveInst(ty_op.operand);
...@@ -4943,9 +4943,9 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -4943,9 +4943,9 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
4943/// E to E!T4943/// E to E!T
4944fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {4944fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
4945 const mod = self.bin_file.options.module.?;4945 const mod = self.bin_file.options.module.?;
4946 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4946 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
49474947
4948 const eu_ty = self.air.getRefType(ty_op.ty);4948 const eu_ty = ty_op.ty.toType();
4949 const pl_ty = eu_ty.errorUnionPayload(mod);4949 const pl_ty = eu_ty.errorUnionPayload(mod);
4950 const err_ty = eu_ty.errorUnionSet(mod);4950 const err_ty = eu_ty.errorUnionSet(mod);
49514951
...@@ -4964,7 +4964,7 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4964,7 +4964,7 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
4964}4964}
49654965
4966fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {4966fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
4967 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4967 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4968 const result = result: {4968 const result = result: {
4969 const src_mcv = try self.resolveInst(ty_op.operand);4969 const src_mcv = try self.resolveInst(ty_op.operand);
4970 if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv;4970 if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv;
...@@ -4978,7 +4978,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4978,7 +4978,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
4978}4978}
49794979
4980fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {4980fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
4981 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4981 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
49824982
4983 const result: MCValue = result: {4983 const result: MCValue = result: {
4984 const src_mcv = try self.resolveInst(ty_op.operand);4984 const src_mcv = try self.resolveInst(ty_op.operand);
...@@ -5002,7 +5002,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -5002,7 +5002,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
50025002
5003fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {5003fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
5004 const mod = self.bin_file.options.module.?;5004 const mod = self.bin_file.options.module.?;
5005 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5005 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
50065006
5007 const src_ty = self.typeOf(ty_op.operand);5007 const src_ty = self.typeOf(ty_op.operand);
5008 const src_mcv = try self.resolveInst(ty_op.operand);5008 const src_mcv = try self.resolveInst(ty_op.operand);
...@@ -5036,7 +5036,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5036,7 +5036,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
5036}5036}
50375037
5038fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {5038fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
5039 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5039 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
50405040
5041 const dst_ty = self.typeOfIndex(inst);5041 const dst_ty = self.typeOfIndex(inst);
5042 const opt_mcv = try self.resolveInst(ty_op.operand);5042 const opt_mcv = try self.resolveInst(ty_op.operand);
...@@ -5106,7 +5106,7 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {...@@ -5106,7 +5106,7 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
51065106
5107fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {5107fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
5108 const mod = self.bin_file.options.module.?;5108 const mod = self.bin_file.options.module.?;
5109 const bin_op = self.air.instructions.items(.data)[inst].bin_op;5109 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
51105110
5111 const result: MCValue = result: {5111 const result: MCValue = result: {
5112 const elem_ty = self.typeOfIndex(inst);5112 const elem_ty = self.typeOfIndex(inst);
...@@ -5123,7 +5123,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5123,7 +5123,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
5123}5123}
51245124
5125fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {5125fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
5126 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5126 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5127 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;5127 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
5128 const dst_mcv = try self.genSliceElemPtr(extra.lhs, extra.rhs);5128 const dst_mcv = try self.genSliceElemPtr(extra.lhs, extra.rhs);
5129 return self.finishAir(inst, dst_mcv, .{ extra.lhs, extra.rhs, .none });5129 return self.finishAir(inst, dst_mcv, .{ extra.lhs, extra.rhs, .none });
...@@ -5131,7 +5131,7 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5131,7 +5131,7 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
51315131
5132fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {5132fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
5133 const mod = self.bin_file.options.module.?;5133 const mod = self.bin_file.options.module.?;
5134 const bin_op = self.air.instructions.items(.data)[inst].bin_op;5134 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
51355135
5136 const array_ty = self.typeOf(bin_op.lhs);5136 const array_ty = self.typeOf(bin_op.lhs);
5137 const array = try self.resolveInst(bin_op.lhs);5137 const array = try self.resolveInst(bin_op.lhs);
...@@ -5205,7 +5205,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5205,7 +5205,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
52055205
5206fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {5206fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
5207 const mod = self.bin_file.options.module.?;5207 const mod = self.bin_file.options.module.?;
5208 const bin_op = self.air.instructions.items(.data)[inst].bin_op;5208 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5209 const ptr_ty = self.typeOf(bin_op.lhs);5209 const ptr_ty = self.typeOf(bin_op.lhs);
52105210
5211 // this is identical to the `airPtrElemPtr` codegen expect here an5211 // this is identical to the `airPtrElemPtr` codegen expect here an
...@@ -5255,7 +5255,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5255,7 +5255,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
52555255
5256fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {5256fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
5257 const mod = self.bin_file.options.module.?;5257 const mod = self.bin_file.options.module.?;
5258 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5258 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5259 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;5259 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
52605260
5261 const ptr_ty = self.typeOf(extra.lhs);5261 const ptr_ty = self.typeOf(extra.lhs);
...@@ -5288,7 +5288,7 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5288,7 +5288,7 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
52885288
5289fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {5289fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
5290 const mod = self.bin_file.options.module.?;5290 const mod = self.bin_file.options.module.?;
5291 const bin_op = self.air.instructions.items(.data)[inst].bin_op;5291 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5292 const ptr_union_ty = self.typeOf(bin_op.lhs);5292 const ptr_union_ty = self.typeOf(bin_op.lhs);
5293 const union_ty = ptr_union_ty.childType(mod);5293 const union_ty = ptr_union_ty.childType(mod);
5294 const tag_ty = self.typeOf(bin_op.rhs);5294 const tag_ty = self.typeOf(bin_op.rhs);
...@@ -5332,7 +5332,7 @@ fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {...@@ -5332,7 +5332,7 @@ fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
53325332
5333fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {5333fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
5334 const mod = self.bin_file.options.module.?;5334 const mod = self.bin_file.options.module.?;
5335 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5335 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
53365336
5337 const tag_ty = self.typeOfIndex(inst);5337 const tag_ty = self.typeOfIndex(inst);
5338 const union_ty = self.typeOf(ty_op.operand);5338 const union_ty = self.typeOf(ty_op.operand);
...@@ -5386,7 +5386,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {...@@ -5386,7 +5386,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
53865386
5387fn airClz(self: *Self, inst: Air.Inst.Index) !void {5387fn airClz(self: *Self, inst: Air.Inst.Index) !void {
5388 const mod = self.bin_file.options.module.?;5388 const mod = self.bin_file.options.module.?;
5389 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5389 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5390 const result = result: {5390 const result = result: {
5391 const dst_ty = self.typeOfIndex(inst);5391 const dst_ty = self.typeOfIndex(inst);
5392 const src_ty = self.typeOf(ty_op.operand);5392 const src_ty = self.typeOf(ty_op.operand);
...@@ -5545,7 +5545,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {...@@ -5545,7 +5545,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
55455545
5546fn airCtz(self: *Self, inst: Air.Inst.Index) !void {5546fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
5547 const mod = self.bin_file.options.module.?;5547 const mod = self.bin_file.options.module.?;
5548 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5548 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5549 const result = result: {5549 const result = result: {
5550 const dst_ty = self.typeOfIndex(inst);5550 const dst_ty = self.typeOfIndex(inst);
5551 const src_ty = self.typeOf(ty_op.operand);5551 const src_ty = self.typeOf(ty_op.operand);
...@@ -5663,7 +5663,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {...@@ -5663,7 +5663,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
56635663
5664fn airPopCount(self: *Self, inst: Air.Inst.Index) !void {5664fn airPopCount(self: *Self, inst: Air.Inst.Index) !void {
5665 const mod = self.bin_file.options.module.?;5665 const mod = self.bin_file.options.module.?;
5666 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5666 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5667 const result: MCValue = result: {5667 const result: MCValue = result: {
5668 try self.spillEflagsIfOccupied();5668 try self.spillEflagsIfOccupied();
56695669
...@@ -5818,7 +5818,7 @@ fn genByteSwap(...@@ -5818,7 +5818,7 @@ fn genByteSwap(
5818 mem_ok: bool,5818 mem_ok: bool,
5819) !MCValue {5819) !MCValue {
5820 const mod = self.bin_file.options.module.?;5820 const mod = self.bin_file.options.module.?;
5821 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5821 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
58225822
5823 if (src_ty.zigTypeTag(mod) == .Vector) return self.fail(5823 if (src_ty.zigTypeTag(mod) == .Vector) return self.fail(
5824 "TODO implement genByteSwap for {}",5824 "TODO implement genByteSwap for {}",
...@@ -5909,7 +5909,7 @@ fn genByteSwap(...@@ -5909,7 +5909,7 @@ fn genByteSwap(
59095909
5910fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {5910fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
5911 const mod = self.bin_file.options.module.?;5911 const mod = self.bin_file.options.module.?;
5912 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5912 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
59135913
5914 const src_ty = self.typeOf(ty_op.operand);5914 const src_ty = self.typeOf(ty_op.operand);
5915 const abi_size: u32 = @intCast(src_ty.abiSize(mod));5915 const abi_size: u32 = @intCast(src_ty.abiSize(mod));
...@@ -5931,7 +5931,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {...@@ -5931,7 +5931,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
59315931
5932fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {5932fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
5933 const mod = self.bin_file.options.module.?;5933 const mod = self.bin_file.options.module.?;
5934 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5934 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
59355935
5936 const src_ty = self.typeOf(ty_op.operand);5936 const src_ty = self.typeOf(ty_op.operand);
5937 const abi_size: u32 = @intCast(src_ty.abiSize(mod));5937 const abi_size: u32 = @intCast(src_ty.abiSize(mod));
...@@ -6053,7 +6053,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {...@@ -6053,7 +6053,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
60536053
6054fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) !void {6054fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) !void {
6055 const mod = self.bin_file.options.module.?;6055 const mod = self.bin_file.options.module.?;
6056 const tag = self.air.instructions.items(.tag)[inst];6056 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
60576057
6058 const result = result: {6058 const result = result: {
6059 const scalar_bits = ty.scalarType(mod).floatBits(self.target.*);6059 const scalar_bits = ty.scalarType(mod).floatBits(self.target.*);
...@@ -6179,7 +6179,7 @@ fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type)...@@ -6179,7 +6179,7 @@ fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type)
6179}6179}
61806180
6181fn airFloatSign(self: *Self, inst: Air.Inst.Index) !void {6181fn airFloatSign(self: *Self, inst: Air.Inst.Index) !void {
6182 const un_op = self.air.instructions.items(.data)[inst].un_op;6182 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
6183 const ty = self.typeOf(un_op);6183 const ty = self.typeOf(un_op);
6184 return self.floatSign(inst, un_op, ty);6184 return self.floatSign(inst, un_op, ty);
6185}6185}
...@@ -6204,7 +6204,7 @@ const RoundMode = packed struct(u5) {...@@ -6204,7 +6204,7 @@ const RoundMode = packed struct(u5) {
6204};6204};
62056205
6206fn airRound(self: *Self, inst: Air.Inst.Index, mode: RoundMode) !void {6206fn airRound(self: *Self, inst: Air.Inst.Index, mode: RoundMode) !void {
6207 const un_op = self.air.instructions.items(.data)[inst].un_op;6207 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
6208 const ty = self.typeOf(un_op);6208 const ty = self.typeOf(un_op);
62096209
6210 const result = result: {6210 const result = result: {
...@@ -6327,7 +6327,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: Ro...@@ -6327,7 +6327,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: Ro
63276327
6328fn airAbs(self: *Self, inst: Air.Inst.Index) !void {6328fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
6329 const mod = self.bin_file.options.module.?;6329 const mod = self.bin_file.options.module.?;
6330 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6330 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6331 const ty = self.typeOf(ty_op.operand);6331 const ty = self.typeOf(ty_op.operand);
63326332
6333 const result: MCValue = result: {6333 const result: MCValue = result: {
...@@ -6467,7 +6467,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {...@@ -6467,7 +6467,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
64676467
6468fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {6468fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
6469 const mod = self.bin_file.options.module.?;6469 const mod = self.bin_file.options.module.?;
6470 const un_op = self.air.instructions.items(.data)[inst].un_op;6470 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
6471 const ty = self.typeOf(un_op);6471 const ty = self.typeOf(un_op);
6472 const abi_size: u32 = @intCast(ty.abiSize(mod));6472 const abi_size: u32 = @intCast(ty.abiSize(mod));
64736473
...@@ -6634,7 +6634,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {...@@ -6634,7 +6634,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
6634}6634}
66356635
6636fn airUnaryMath(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {6636fn airUnaryMath(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
6637 const un_op = self.air.instructions.items(.data)[inst].un_op;6637 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
6638 const ty = self.typeOf(un_op);6638 const ty = self.typeOf(un_op);
6639 var callee_buf: ["__round?".len]u8 = undefined;6639 var callee_buf: ["__round?".len]u8 = undefined;
6640 const result = try self.genCall(.{ .lib = .{6640 const result = try self.genCall(.{ .lib = .{
...@@ -6704,7 +6704,7 @@ fn reuseOperandAdvanced(...@@ -6704,7 +6704,7 @@ fn reuseOperandAdvanced(
67046704
6705 // Prevent the operand deaths processing code from deallocating it.6705 // Prevent the operand deaths processing code from deallocating it.
6706 self.liveness.clearOperandDeath(inst, op_index);6706 self.liveness.clearOperandDeath(inst, op_index);
6707 const op_inst = Air.refToIndex(operand).?;6707 const op_inst = operand.toIndex().?;
6708 self.getResolvedInstValue(op_inst).reuse(self, maybe_tracked_inst, op_inst);6708 self.getResolvedInstValue(op_inst).reuse(self, maybe_tracked_inst, op_inst);
67096709
6710 return true;6710 return true;
...@@ -6852,7 +6852,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerErro...@@ -6852,7 +6852,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerErro
68526852
6853fn airLoad(self: *Self, inst: Air.Inst.Index) !void {6853fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
6854 const mod = self.bin_file.options.module.?;6854 const mod = self.bin_file.options.module.?;
6855 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6855 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6856 const elem_ty = self.typeOfIndex(inst);6856 const elem_ty = self.typeOfIndex(inst);
6857 const result: MCValue = result: {6857 const result: MCValue = result: {
6858 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none;6858 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none;
...@@ -7051,7 +7051,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -7051,7 +7051,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
7051 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });7051 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });
7052 defer for (reg_locks) |lock| self.register_manager.unlockReg(lock);7052 defer for (reg_locks) |lock| self.register_manager.unlockReg(lock);
70537053
7054 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7054 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7055 const ptr_mcv = try self.resolveInst(bin_op.lhs);7055 const ptr_mcv = try self.resolveInst(bin_op.lhs);
7056 const ptr_ty = self.typeOf(bin_op.lhs);7056 const ptr_ty = self.typeOf(bin_op.lhs);
7057 const src_mcv = try self.resolveInst(bin_op.rhs);7057 const src_mcv = try self.resolveInst(bin_op.rhs);
...@@ -7064,14 +7064,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -7064,14 +7064,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
7064}7064}
70657065
7066fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {7066fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void {
7067 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;7067 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7068 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;7068 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
7069 const result = try self.fieldPtr(inst, extra.struct_operand, extra.field_index);7069 const result = try self.fieldPtr(inst, extra.struct_operand, extra.field_index);
7070 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });7070 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });
7071}7071}
70727072
7073fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {7073fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
7074 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7074 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7075 const result = try self.fieldPtr(inst, ty_op.operand, index);7075 const result = try self.fieldPtr(inst, ty_op.operand, index);
7076 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });7076 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
7077}7077}
...@@ -7103,7 +7103,7 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32...@@ -7103,7 +7103,7 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
71037103
7104fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {7104fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
7105 const mod = self.bin_file.options.module.?;7105 const mod = self.bin_file.options.module.?;
7106 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;7106 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7107 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;7107 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
7108 const result: MCValue = result: {7108 const result: MCValue = result: {
7109 const operand = extra.struct_operand;7109 const operand = extra.struct_operand;
...@@ -7389,7 +7389,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -7389,7 +7389,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
73897389
7390fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {7390fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
7391 const mod = self.bin_file.options.module.?;7391 const mod = self.bin_file.options.module.?;
7392 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;7392 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7393 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;7393 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
73947394
7395 const inst_ty = self.typeOfIndex(inst);7395 const inst_ty = self.typeOfIndex(inst);
...@@ -7943,7 +7943,7 @@ fn genShiftBinOp(...@@ -7943,7 +7943,7 @@ fn genShiftBinOp(
79437943
7944 const dst_mcv: MCValue = dst: {7944 const dst_mcv: MCValue = dst: {
7945 if (maybe_inst) |inst| {7945 if (maybe_inst) |inst| {
7946 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7946 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7947 if (self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv)) break :dst lhs_mcv;7947 if (self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv)) break :dst lhs_mcv;
7948 }7948 }
7949 const dst_mcv = try self.allocRegOrMemAdvanced(lhs_ty, maybe_inst, true);7949 const dst_mcv = try self.allocRegOrMemAdvanced(lhs_ty, maybe_inst, true);
...@@ -10496,7 +10496,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -10496,7 +10496,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
10496 else => return self.fail("TODO implement arg for {}", .{src_mcv}),10496 else => return self.fail("TODO implement arg for {}", .{src_mcv}),
10497 };10497 };
1049810498
10499 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;10499 const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;
10500 const name = mod.getParamName(self.owner.func_index, src_index);10500 const name = mod.getParamName(self.owner.func_index, src_index);
10501 try self.genArgDbgInfo(arg_ty, name, src_mcv);10501 try self.genArgDbgInfo(arg_ty, name, src_mcv);
1050210502
...@@ -10609,7 +10609,7 @@ fn airFrameAddress(self: *Self, inst: Air.Inst.Index) !void {...@@ -10609,7 +10609,7 @@ fn airFrameAddress(self: *Self, inst: Air.Inst.Index) !void {
10609}10609}
1061010610
10611fn airFence(self: *Self, inst: Air.Inst.Index) !void {10611fn airFence(self: *Self, inst: Air.Inst.Index) !void {
10612 const order = self.air.instructions.items(.data)[inst].fence;10612 const order = self.air.instructions.items(.data)[@intFromEnum(inst)].fence;
10613 switch (order) {10613 switch (order) {
10614 .Unordered, .Monotonic => unreachable,10614 .Unordered, .Monotonic => unreachable,
10615 .Acquire, .Release, .AcqRel => {},10615 .Acquire, .Release, .AcqRel => {},
...@@ -10621,7 +10621,7 @@ fn airFence(self: *Self, inst: Air.Inst.Index) !void {...@@ -10621,7 +10621,7 @@ fn airFence(self: *Self, inst: Air.Inst.Index) !void {
10621fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {10621fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
10622 if (modifier == .always_tail) return self.fail("TODO implement tail calls for x86_64", .{});10622 if (modifier == .always_tail) return self.fail("TODO implement tail calls for x86_64", .{});
1062310623
10624 const pl_op = self.air.instructions.items(.data)[inst].pl_op;10624 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
10625 const extra = self.air.extraData(Air.Call, pl_op.payload);10625 const extra = self.air.extraData(Air.Call, pl_op.payload);
10626 const arg_refs: []const Air.Inst.Ref =10626 const arg_refs: []const Air.Inst.Ref =
10627 @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);10627 @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
...@@ -10883,7 +10883,7 @@ fn genCall(self: *Self, info: union(enum) {...@@ -10883,7 +10883,7 @@ fn genCall(self: *Self, info: union(enum) {
1088310883
10884fn airRet(self: *Self, inst: Air.Inst.Index) !void {10884fn airRet(self: *Self, inst: Air.Inst.Index) !void {
10885 const mod = self.bin_file.options.module.?;10885 const mod = self.bin_file.options.module.?;
10886 const un_op = self.air.instructions.items(.data)[inst].un_op;10886 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1088710887
10888 const ret_ty = self.fn_type.fnReturnType(mod);10888 const ret_ty = self.fn_type.fnReturnType(mod);
10889 switch (self.ret_mcv.short) {10889 switch (self.ret_mcv.short) {
...@@ -10911,7 +10911,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {...@@ -10911,7 +10911,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
10911}10911}
1091210912
10913fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {10913fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
10914 const un_op = self.air.instructions.items(.data)[inst].un_op;10914 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
10915 const ptr = try self.resolveInst(un_op);10915 const ptr = try self.resolveInst(un_op);
1091610916
10917 const ptr_ty = self.typeOf(un_op);10917 const ptr_ty = self.typeOf(un_op);
...@@ -10932,7 +10932,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -10932,7 +10932,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
1093210932
10933fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {10933fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
10934 const mod = self.bin_file.options.module.?;10934 const mod = self.bin_file.options.module.?;
10935 const bin_op = self.air.instructions.items(.data)[inst].bin_op;10935 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
10936 const ty = self.typeOf(bin_op.lhs);10936 const ty = self.typeOf(bin_op.lhs);
1093710937
10938 const result: Condition = result: {10938 const result: Condition = result: {
...@@ -11313,7 +11313,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {...@@ -11313,7 +11313,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
11313}11313}
1131411314
11315fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {11315fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
11316 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;11316 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
11317 const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;11317 const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;
11318 const dst_mcv = try self.genBinOp(11318 const dst_mcv = try self.genBinOp(
11319 inst,11319 inst,
...@@ -11326,7 +11326,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {...@@ -11326,7 +11326,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
1132611326
11327fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {11327fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
11328 const mod = self.bin_file.options.module.?;11328 const mod = self.bin_file.options.module.?;
11329 const un_op = self.air.instructions.items(.data)[inst].un_op;11329 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1133011330
11331 const addr_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);11331 const addr_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
11332 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);11332 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);
...@@ -11356,18 +11356,18 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -11356,18 +11356,18 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
11356}11356}
1135711357
11358fn airTry(self: *Self, inst: Air.Inst.Index) !void {11358fn airTry(self: *Self, inst: Air.Inst.Index) !void {
11359 const pl_op = self.air.instructions.items(.data)[inst].pl_op;11359 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
11360 const extra = self.air.extraData(Air.Try, pl_op.payload);11360 const extra = self.air.extraData(Air.Try, pl_op.payload);
11361 const body = self.air.extra[extra.end..][0..extra.data.body_len];11361 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
11362 const operand_ty = self.typeOf(pl_op.operand);11362 const operand_ty = self.typeOf(pl_op.operand);
11363 const result = try self.genTry(inst, pl_op.operand, body, operand_ty, false);11363 const result = try self.genTry(inst, pl_op.operand, body, operand_ty, false);
11364 return self.finishAir(inst, result, .{ .none, .none, .none });11364 return self.finishAir(inst, result, .{ .none, .none, .none });
11365}11365}
1136611366
11367fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {11367fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {
11368 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;11368 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
11369 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);11369 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
11370 const body = self.air.extra[extra.end..][0..extra.data.body_len];11370 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
11371 const operand_ty = self.typeOf(extra.data.ptr);11371 const operand_ty = self.typeOf(extra.data.ptr);
11372 const result = try self.genTry(inst, extra.data.ptr, body, operand_ty, true);11372 const result = try self.genTry(inst, extra.data.ptr, body, operand_ty, true);
11373 return self.finishAir(inst, result, .{ .none, .none, .none });11373 return self.finishAir(inst, result, .{ .none, .none, .none });
...@@ -11392,7 +11392,7 @@ fn genTry(...@@ -11392,7 +11392,7 @@ fn genTry(
11392 const reloc = try self.genCondBrMir(Type.anyerror, is_err_mcv);11392 const reloc = try self.genCondBrMir(Type.anyerror, is_err_mcv);
1139311393
11394 if (self.liveness.operandDies(inst, 0)) {11394 if (self.liveness.operandDies(inst, 0)) {
11395 if (Air.refToIndex(operand)) |operand_inst| try self.processDeath(operand_inst);11395 if (operand.toIndex()) |operand_inst| try self.processDeath(operand_inst);
11396 }11396 }
1139711397
11398 self.scope_generation += 1;11398 self.scope_generation += 1;
...@@ -11421,7 +11421,7 @@ fn genTry(...@@ -11421,7 +11421,7 @@ fn genTry(
11421}11421}
1142211422
11423fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {11423fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
11424 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;11424 const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
11425 _ = try self.addInst(.{11425 _ = try self.addInst(.{
11426 .tag = .pseudo,11426 .tag = .pseudo,
11427 .ops = .pseudo_dbg_line_line_column,11427 .ops = .pseudo_dbg_line_line_column,
...@@ -11434,7 +11434,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {...@@ -11434,7 +11434,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
11434}11434}
1143511435
11436fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {11436fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
11437 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;11437 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
11438 _ = try self.addInst(.{11438 _ = try self.addInst(.{
11439 .tag = .pseudo,11439 .tag = .pseudo,
11440 .ops = .pseudo_dbg_inline_func,11440 .ops = .pseudo_dbg_inline_func,
...@@ -11450,14 +11450,14 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -11450,14 +11450,14 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
11450}11450}
1145111451
11452fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {11452fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
11453 const pl_op = self.air.instructions.items(.data)[inst].pl_op;11453 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
11454 const operand = pl_op.operand;11454 const operand = pl_op.operand;
11455 const ty = self.typeOf(operand);11455 const ty = self.typeOf(operand);
11456 const mcv = try self.resolveInst(operand);11456 const mcv = try self.resolveInst(operand);
1145711457
11458 const name = self.air.nullTerminatedString(pl_op.payload);11458 const name = self.air.nullTerminatedString(pl_op.payload);
1145911459
11460 const tag = self.air.instructions.items(.tag)[inst];11460 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
11461 try self.genVarDbgInfo(tag, ty, mcv, name);11461 try self.genVarDbgInfo(tag, ty, mcv, name);
1146211462
11463 return self.finishAir(inst, .unreach, .{ operand, .none, .none });11463 return self.finishAir(inst, .unreach, .{ operand, .none, .none });
...@@ -11492,19 +11492,21 @@ fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !Mir.Inst.Index {...@@ -11492,19 +11492,21 @@ fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !Mir.Inst.Index {
11492}11492}
1149311493
11494fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {11494fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
11495 const pl_op = self.air.instructions.items(.data)[inst].pl_op;11495 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
11496 const cond = try self.resolveInst(pl_op.operand);11496 const cond = try self.resolveInst(pl_op.operand);
11497 const cond_ty = self.typeOf(pl_op.operand);11497 const cond_ty = self.typeOf(pl_op.operand);
11498 const extra = self.air.extraData(Air.CondBr, pl_op.payload);11498 const extra = self.air.extraData(Air.CondBr, pl_op.payload);
11499 const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len];11499 const then_body: []const Air.Inst.Index =
11500 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];11500 @ptrCast(self.air.extra[extra.end..][0..extra.data.then_body_len]);
11501 const else_body: []const Air.Inst.Index =
11502 @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
11501 const liveness_cond_br = self.liveness.getCondBr(inst);11503 const liveness_cond_br = self.liveness.getCondBr(inst);
1150211504
11503 // If the condition dies here in this condbr instruction, process11505 // If the condition dies here in this condbr instruction, process
11504 // that death now instead of later as this has an effect on11506 // that death now instead of later as this has an effect on
11505 // whether it needs to be spilled in the branches11507 // whether it needs to be spilled in the branches
11506 if (self.liveness.operandDies(inst, 0)) {11508 if (self.liveness.operandDies(inst, 0)) {
11507 if (Air.refToIndex(pl_op.operand)) |op_inst| try self.processDeath(op_inst);11509 if (pl_op.operand.toIndex()) |op_inst| try self.processDeath(op_inst);
11508 }11510 }
1150911511
11510 self.scope_generation += 1;11512 self.scope_generation += 1;
...@@ -11789,7 +11791,7 @@ fn isNonErrPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue...@@ -11789,7 +11791,7 @@ fn isNonErrPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue
11789}11791}
1179011792
11791fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {11793fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
11792 const un_op = self.air.instructions.items(.data)[inst].un_op;11794 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
11793 const operand = try self.resolveInst(un_op);11795 const operand = try self.resolveInst(un_op);
11794 const ty = self.typeOf(un_op);11796 const ty = self.typeOf(un_op);
11795 const result = try self.isNull(inst, ty, operand);11797 const result = try self.isNull(inst, ty, operand);
...@@ -11797,7 +11799,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -11797,7 +11799,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
11797}11799}
1179811800
11799fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {11801fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
11800 const un_op = self.air.instructions.items(.data)[inst].un_op;11802 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
11801 const operand = try self.resolveInst(un_op);11803 const operand = try self.resolveInst(un_op);
11802 const ty = self.typeOf(un_op);11804 const ty = self.typeOf(un_op);
11803 const result = try self.isNullPtr(inst, ty, operand);11805 const result = try self.isNullPtr(inst, ty, operand);
...@@ -11805,7 +11807,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -11805,7 +11807,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
11805}11807}
1180611808
11807fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {11809fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
11808 const un_op = self.air.instructions.items(.data)[inst].un_op;11810 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
11809 const operand = try self.resolveInst(un_op);11811 const operand = try self.resolveInst(un_op);
11810 const ty = self.typeOf(un_op);11812 const ty = self.typeOf(un_op);
11811 const result = switch (try self.isNull(inst, ty, operand)) {11813 const result = switch (try self.isNull(inst, ty, operand)) {
...@@ -11816,7 +11818,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -11816,7 +11818,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
11816}11818}
1181711819
11818fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {11820fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
11819 const un_op = self.air.instructions.items(.data)[inst].un_op;11821 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
11820 const operand = try self.resolveInst(un_op);11822 const operand = try self.resolveInst(un_op);
11821 const ty = self.typeOf(un_op);11823 const ty = self.typeOf(un_op);
11822 const result = switch (try self.isNullPtr(inst, ty, operand)) {11824 const result = switch (try self.isNullPtr(inst, ty, operand)) {
...@@ -11827,7 +11829,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -11827,7 +11829,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
11827}11829}
1182811830
11829fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {11831fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
11830 const un_op = self.air.instructions.items(.data)[inst].un_op;11832 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
11831 const operand = try self.resolveInst(un_op);11833 const operand = try self.resolveInst(un_op);
11832 const ty = self.typeOf(un_op);11834 const ty = self.typeOf(un_op);
11833 const result = try self.isErr(inst, ty, operand);11835 const result = try self.isErr(inst, ty, operand);
...@@ -11835,7 +11837,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -11835,7 +11837,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
11835}11837}
1183611838
11837fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {11839fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
11838 const un_op = self.air.instructions.items(.data)[inst].un_op;11840 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
11839 const operand = try self.resolveInst(un_op);11841 const operand = try self.resolveInst(un_op);
11840 const ty = self.typeOf(un_op);11842 const ty = self.typeOf(un_op);
11841 const result = try self.isErrPtr(inst, ty, operand);11843 const result = try self.isErrPtr(inst, ty, operand);
...@@ -11843,7 +11845,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -11843,7 +11845,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
11843}11845}
1184411846
11845fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {11847fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
11846 const un_op = self.air.instructions.items(.data)[inst].un_op;11848 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
11847 const operand = try self.resolveInst(un_op);11849 const operand = try self.resolveInst(un_op);
11848 const ty = self.typeOf(un_op);11850 const ty = self.typeOf(un_op);
11849 const result = try self.isNonErr(inst, ty, operand);11851 const result = try self.isNonErr(inst, ty, operand);
...@@ -11851,7 +11853,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -11851,7 +11853,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
11851}11853}
1185211854
11853fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {11855fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
11854 const un_op = self.air.instructions.items(.data)[inst].un_op;11856 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
11855 const operand = try self.resolveInst(un_op);11857 const operand = try self.resolveInst(un_op);
11856 const ty = self.typeOf(un_op);11858 const ty = self.typeOf(un_op);
11857 const result = try self.isNonErrPtr(inst, ty, operand);11859 const result = try self.isNonErrPtr(inst, ty, operand);
...@@ -11860,9 +11862,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -11860,9 +11862,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
1186011862
11861fn airLoop(self: *Self, inst: Air.Inst.Index) !void {11863fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
11862 // A loop is a setup to be able to jump back to the beginning.11864 // A loop is a setup to be able to jump back to the beginning.
11863 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;11865 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
11864 const loop = self.air.extraData(Air.Block, ty_pl.payload);11866 const loop = self.air.extraData(Air.Block, ty_pl.payload);
11865 const body = self.air.extra[loop.end..][0..loop.data.body_len];11867 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);
1186611868
11867 self.scope_generation += 1;11869 self.scope_generation += 1;
11868 const state = try self.saveState();11870 const state = try self.saveState();
...@@ -11889,9 +11891,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -11889,9 +11891,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
11889 try self.blocks.putNoClobber(self.gpa, inst, .{ .state = self.initRetroactiveState() });11891 try self.blocks.putNoClobber(self.gpa, inst, .{ .state = self.initRetroactiveState() });
11890 const liveness = self.liveness.getBlock(inst);11892 const liveness = self.liveness.getBlock(inst);
1189111893
11892 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;11894 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
11893 const extra = self.air.extraData(Air.Block, ty_pl.payload);11895 const extra = self.air.extraData(Air.Block, ty_pl.payload);
11894 const body = self.air.extra[extra.end..][0..extra.data.body_len];11896 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
11895 try self.genBody(body);11897 try self.genBody(body);
1189611898
11897 var block_data = self.blocks.fetchRemove(inst).?;11899 var block_data = self.blocks.fetchRemove(inst).?;
...@@ -11914,7 +11916,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {...@@ -11914,7 +11916,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
11914}11916}
1191511917
11916fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {11918fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
11917 const pl_op = self.air.instructions.items(.data)[inst].pl_op;11919 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
11918 const condition = try self.resolveInst(pl_op.operand);11920 const condition = try self.resolveInst(pl_op.operand);
11919 const condition_ty = self.typeOf(pl_op.operand);11921 const condition_ty = self.typeOf(pl_op.operand);
11920 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);11922 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
...@@ -11927,7 +11929,7 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -11927,7 +11929,7 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
11927 // that death now instead of later as this has an effect on11929 // that death now instead of later as this has an effect on
11928 // whether it needs to be spilled in the branches11930 // whether it needs to be spilled in the branches
11929 if (self.liveness.operandDies(inst, 0)) {11931 if (self.liveness.operandDies(inst, 0)) {
11930 if (Air.refToIndex(pl_op.operand)) |op_inst| try self.processDeath(op_inst);11932 if (pl_op.operand.toIndex()) |op_inst| try self.processDeath(op_inst);
11931 }11933 }
1193211934
11933 self.scope_generation += 1;11935 self.scope_generation += 1;
...@@ -11937,7 +11939,8 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -11937,7 +11939,8 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
11937 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);11939 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
11938 const items: []const Air.Inst.Ref =11940 const items: []const Air.Inst.Ref =
11939 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]);11941 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]);
11940 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];11942 const case_body: []const Air.Inst.Index =
11943 @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]);
11941 extra_index = case.end + items.len + case_body.len;11944 extra_index = case.end + items.len + case_body.len;
1194211945
11943 var relocs = try self.gpa.alloc(Mir.Inst.Index, items.len);11946 var relocs = try self.gpa.alloc(Mir.Inst.Index, items.len);
...@@ -11975,7 +11978,8 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -11975,7 +11978,8 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
11975 }11978 }
1197611979
11977 if (switch_br.data.else_body_len > 0) {11980 if (switch_br.data.else_body_len > 0) {
11978 const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len];11981 const else_body: []const Air.Inst.Index =
11982 @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]);
1197911983
11980 const else_deaths = liveness.deaths.len - 1;11984 const else_deaths = liveness.deaths.len - 1;
11981 for (liveness.deaths[else_deaths]) |operand| try self.processDeath(operand);11985 for (liveness.deaths[else_deaths]) |operand| try self.processDeath(operand);
...@@ -12008,7 +12012,7 @@ fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void {...@@ -12008,7 +12012,7 @@ fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void {
1200812012
12009fn airBr(self: *Self, inst: Air.Inst.Index) !void {12013fn airBr(self: *Self, inst: Air.Inst.Index) !void {
12010 const mod = self.bin_file.options.module.?;12014 const mod = self.bin_file.options.module.?;
12011 const br = self.air.instructions.items(.data)[inst].br;12015 const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
1201212016
12013 const block_ty = self.typeOfIndex(br.block_inst);12017 const block_ty = self.typeOfIndex(br.block_inst);
12014 const block_unused =12018 const block_unused =
...@@ -12043,7 +12047,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -12043,7 +12047,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
1204312047
12044 // Process operand death so that it is properly accounted for in the State below.12048 // Process operand death so that it is properly accounted for in the State below.
12045 if (self.liveness.operandDies(inst, 0)) {12049 if (self.liveness.operandDies(inst, 0)) {
12046 if (Air.refToIndex(br.operand)) |op_inst| try self.processDeath(op_inst);12050 if (br.operand.toIndex()) |op_inst| try self.processDeath(op_inst);
12047 }12051 }
1204812052
12049 if (first_br) {12053 if (first_br) {
...@@ -12069,7 +12073,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -12069,7 +12073,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
1206912073
12070fn airAsm(self: *Self, inst: Air.Inst.Index) !void {12074fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
12071 const mod = self.bin_file.options.module.?;12075 const mod = self.bin_file.options.module.?;
12072 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;12076 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
12073 const extra = self.air.extraData(Air.Asm, ty_pl.payload);12077 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
12074 const clobbers_len: u31 = @truncate(extra.data.flags);12078 const clobbers_len: u31 = @truncate(extra.data.flags);
12075 var extra_i: usize = extra.end;12079 var extra_i: usize = extra.end;
...@@ -13784,7 +13788,7 @@ fn genLazySymbolRef(...@@ -13784,7 +13788,7 @@ fn genLazySymbolRef(
13784}13788}
1378513789
13786fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {13790fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
13787 const un_op = self.air.instructions.items(.data)[inst].un_op;13791 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
13788 const result = result: {13792 const result = result: {
13789 // TODO: handle case where the operand is a slice not a raw pointer13793 // TODO: handle case where the operand is a slice not a raw pointer
13790 const src_mcv = try self.resolveInst(un_op);13794 const src_mcv = try self.resolveInst(un_op);
...@@ -13800,7 +13804,7 @@ fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -13800,7 +13804,7 @@ fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
1380013804
13801fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {13805fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
13802 const mod = self.bin_file.options.module.?;13806 const mod = self.bin_file.options.module.?;
13803 const ty_op = self.air.instructions.items(.data)[inst].ty_op;13807 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
13804 const dst_ty = self.typeOfIndex(inst);13808 const dst_ty = self.typeOfIndex(inst);
13805 const src_ty = self.typeOf(ty_op.operand);13809 const src_ty = self.typeOf(ty_op.operand);
1380613810
...@@ -13858,7 +13862,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -13858,7 +13862,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1385813862
13859fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {13863fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
13860 const mod = self.bin_file.options.module.?;13864 const mod = self.bin_file.options.module.?;
13861 const ty_op = self.air.instructions.items(.data)[inst].ty_op;13865 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1386213866
13863 const slice_ty = self.typeOfIndex(inst);13867 const slice_ty = self.typeOfIndex(inst);
13864 const ptr_ty = self.typeOf(ty_op.operand);13868 const ptr_ty = self.typeOf(ty_op.operand);
...@@ -13881,7 +13885,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -13881,7 +13885,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
1388113885
13882fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {13886fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
13883 const mod = self.bin_file.options.module.?;13887 const mod = self.bin_file.options.module.?;
13884 const ty_op = self.air.instructions.items(.data)[inst].ty_op;13888 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1388513889
13886 const dst_ty = self.typeOfIndex(inst);13890 const dst_ty = self.typeOfIndex(inst);
13887 const dst_bits = dst_ty.floatBits(self.target.*);13891 const dst_bits = dst_ty.floatBits(self.target.*);
...@@ -13960,7 +13964,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {...@@ -13960,7 +13964,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1396013964
13961fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {13965fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
13962 const mod = self.bin_file.options.module.?;13966 const mod = self.bin_file.options.module.?;
13963 const ty_op = self.air.instructions.items(.data)[inst].ty_op;13967 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1396413968
13965 const dst_ty = self.typeOfIndex(inst);13969 const dst_ty = self.typeOfIndex(inst);
13966 const dst_bits: u32 = @intCast(dst_ty.bitSize(mod));13970 const dst_bits: u32 = @intCast(dst_ty.bitSize(mod));
...@@ -14031,7 +14035,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {...@@ -14031,7 +14035,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1403114035
14032fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {14036fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
14033 const mod = self.bin_file.options.module.?;14037 const mod = self.bin_file.options.module.?;
14034 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;14038 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
14035 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;14039 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
1403614040
14037 const ptr_ty = self.typeOf(extra.ptr);14041 const ptr_ty = self.typeOf(extra.ptr);
...@@ -14388,7 +14392,7 @@ fn atomicOp(...@@ -14388,7 +14392,7 @@ fn atomicOp(
14388}14392}
1438914393
14390fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {14394fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {
14391 const pl_op = self.air.instructions.items(.data)[inst].pl_op;14395 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
14392 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;14396 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
1439314397
14394 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });14398 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });
...@@ -14409,7 +14413,7 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {...@@ -14409,7 +14413,7 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {
14409}14413}
1441014414
14411fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {14415fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {
14412 const atomic_load = self.air.instructions.items(.data)[inst].atomic_load;14416 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
1441314417
14414 const ptr_ty = self.typeOf(atomic_load.ptr);14418 const ptr_ty = self.typeOf(atomic_load.ptr);
14415 const ptr_mcv = try self.resolveInst(atomic_load.ptr);14419 const ptr_mcv = try self.resolveInst(atomic_load.ptr);
...@@ -14430,7 +14434,7 @@ fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -14430,7 +14434,7 @@ fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {
14430}14434}
1443114435
14432fn airAtomicStore(self: *Self, inst: Air.Inst.Index, order: std.builtin.AtomicOrder) !void {14436fn airAtomicStore(self: *Self, inst: Air.Inst.Index, order: std.builtin.AtomicOrder) !void {
14433 const bin_op = self.air.instructions.items(.data)[inst].bin_op;14437 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1443414438
14435 const ptr_ty = self.typeOf(bin_op.lhs);14439 const ptr_ty = self.typeOf(bin_op.lhs);
14436 const ptr_mcv = try self.resolveInst(bin_op.lhs);14440 const ptr_mcv = try self.resolveInst(bin_op.lhs);
...@@ -14450,7 +14454,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -14450,7 +14454,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
14450 // TODO if the value is undef, don't lower this instruction14454 // TODO if the value is undef, don't lower this instruction
14451 }14455 }
1445214456
14453 const bin_op = self.air.instructions.items(.data)[inst].bin_op;14457 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1445414458
14455 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });14459 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
14456 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });14460 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });
...@@ -14571,7 +14575,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -14571,7 +14575,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1457114575
14572fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {14576fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
14573 const mod = self.bin_file.options.module.?;14577 const mod = self.bin_file.options.module.?;
14574 const bin_op = self.air.instructions.items(.data)[inst].bin_op;14578 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1457514579
14576 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });14580 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
14577 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });14581 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });
...@@ -14626,7 +14630,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {...@@ -14626,7 +14630,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1462614630
14627fn airTagName(self: *Self, inst: Air.Inst.Index) !void {14631fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
14628 const mod = self.bin_file.options.module.?;14632 const mod = self.bin_file.options.module.?;
14629 const un_op = self.air.instructions.items(.data)[inst].un_op;14633 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
14630 const inst_ty = self.typeOfIndex(inst);14634 const inst_ty = self.typeOfIndex(inst);
14631 const enum_ty = self.typeOf(un_op);14635 const enum_ty = self.typeOf(un_op);
14632 const resolved_cc = abi.resolveCallingConvention(.Unspecified, self.target.*);14636 const resolved_cc = abi.resolveCallingConvention(.Unspecified, self.target.*);
...@@ -14668,7 +14672,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {...@@ -14668,7 +14672,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
1466814672
14669fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {14673fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
14670 const mod = self.bin_file.options.module.?;14674 const mod = self.bin_file.options.module.?;
14671 const un_op = self.air.instructions.items(.data)[inst].un_op;14675 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1467214676
14673 const err_ty = self.typeOf(un_op);14677 const err_ty = self.typeOf(un_op);
14674 const err_mcv = try self.resolveInst(un_op);14678 const err_mcv = try self.resolveInst(un_op);
...@@ -14770,7 +14774,7 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {...@@ -14770,7 +14774,7 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
1477014774
14771fn airSplat(self: *Self, inst: Air.Inst.Index) !void {14775fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
14772 const mod = self.bin_file.options.module.?;14776 const mod = self.bin_file.options.module.?;
14773 const ty_op = self.air.instructions.items(.data)[inst].ty_op;14777 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
14774 const vector_ty = self.typeOfIndex(inst);14778 const vector_ty = self.typeOfIndex(inst);
14775 const vector_len = vector_ty.vectorLen(mod);14779 const vector_len = vector_ty.vectorLen(mod);
14776 const dst_rc = self.regClassForType(vector_ty);14780 const dst_rc = self.regClassForType(vector_ty);
...@@ -15106,7 +15110,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {...@@ -15106,7 +15110,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
15106}15110}
1510715111
15108fn airSelect(self: *Self, inst: Air.Inst.Index) !void {15112fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
15109 const pl_op = self.air.instructions.items(.data)[inst].pl_op;15113 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
15110 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;15114 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
15111 _ = extra;15115 _ = extra;
15112 return self.fail("TODO implement airSelect for x86_64", .{});15116 return self.fail("TODO implement airSelect for x86_64", .{});
...@@ -15114,7 +15118,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {...@@ -15114,7 +15118,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
15114}15118}
1511515119
15116fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {15120fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
15117 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;15121 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
15118 _ = ty_pl;15122 _ = ty_pl;
15119 return self.fail("TODO implement airShuffle for x86_64", .{});15123 return self.fail("TODO implement airShuffle for x86_64", .{});
15120 //return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });15124 //return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
...@@ -15122,7 +15126,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {...@@ -15122,7 +15126,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
1512215126
15123fn airReduce(self: *Self, inst: Air.Inst.Index) !void {15127fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
15124 const mod = self.bin_file.options.module.?;15128 const mod = self.bin_file.options.module.?;
15125 const reduce = self.air.instructions.items(.data)[inst].reduce;15129 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
1512615130
15127 const result: MCValue = result: {15131 const result: MCValue = result: {
15128 const operand_ty = self.typeOf(reduce.operand);15132 const operand_ty = self.typeOf(reduce.operand);
...@@ -15181,7 +15185,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -15181,7 +15185,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
15181 const mod = self.bin_file.options.module.?;15185 const mod = self.bin_file.options.module.?;
15182 const result_ty = self.typeOfIndex(inst);15186 const result_ty = self.typeOfIndex(inst);
15183 const len: usize = @intCast(result_ty.arrayLen(mod));15187 const len: usize = @intCast(result_ty.arrayLen(mod));
15184 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;15188 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
15185 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);15189 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
15186 const result: MCValue = result: {15190 const result: MCValue = result: {
15187 switch (result_ty.zigTypeTag(mod)) {15191 switch (result_ty.zigTypeTag(mod)) {
...@@ -15321,7 +15325,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -15321,7 +15325,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
15321fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {15325fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
15322 const mod = self.bin_file.options.module.?;15326 const mod = self.bin_file.options.module.?;
15323 const ip = &mod.intern_pool;15327 const ip = &mod.intern_pool;
15324 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;15328 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
15325 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;15329 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
15326 const result: MCValue = result: {15330 const result: MCValue = result: {
15327 const union_ty = self.typeOfIndex(inst);15331 const union_ty = self.typeOfIndex(inst);
...@@ -15365,13 +15369,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -15365,13 +15369,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
15365}15369}
1536615370
15367fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {15371fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {
15368 const prefetch = self.air.instructions.items(.data)[inst].prefetch;15372 const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
15369 return self.finishAir(inst, .unreach, .{ prefetch.ptr, .none, .none });15373 return self.finishAir(inst, .unreach, .{ prefetch.ptr, .none, .none });
15370}15374}
1537115375
15372fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {15376fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
15373 const mod = self.bin_file.options.module.?;15377 const mod = self.bin_file.options.module.?;
15374 const pl_op = self.air.instructions.items(.data)[inst].pl_op;15378 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
15375 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;15379 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
15376 const ty = self.typeOfIndex(inst);15380 const ty = self.typeOfIndex(inst);
1537715381
...@@ -15538,7 +15542,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -15538,7 +15542,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1553815542
15539fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {15543fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
15540 const mod = self.bin_file.options.module.?;15544 const mod = self.bin_file.options.module.?;
15541 const va_list_ty = self.air.instructions.items(.data)[inst].ty;15545 const va_list_ty = self.air.instructions.items(.data)[@intFromEnum(inst)].ty;
15542 const ptr_anyopaque_ty = try mod.singleMutPtrType(Type.anyopaque);15546 const ptr_anyopaque_ty = try mod.singleMutPtrType(Type.anyopaque);
1554315547
15544 const result: MCValue = switch (abi.resolveCallingConvention(15548 const result: MCValue = switch (abi.resolveCallingConvention(
...@@ -15591,7 +15595,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {...@@ -15591,7 +15595,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1559115595
15592fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {15596fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
15593 const mod = self.bin_file.options.module.?;15597 const mod = self.bin_file.options.module.?;
15594 const ty_op = self.air.instructions.items(.data)[inst].ty_op;15598 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
15595 const ty = self.typeOfIndex(inst);15599 const ty = self.typeOfIndex(inst);
15596 const promote_ty = self.promoteVarArg(ty);15600 const promote_ty = self.promoteVarArg(ty);
15597 const ptr_anyopaque_ty = try mod.singleMutPtrType(Type.anyopaque);15601 const ptr_anyopaque_ty = try mod.singleMutPtrType(Type.anyopaque);
...@@ -15785,7 +15789,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -15785,7 +15789,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
15785}15789}
1578615790
15787fn airVaCopy(self: *Self, inst: Air.Inst.Index) !void {15791fn airVaCopy(self: *Self, inst: Air.Inst.Index) !void {
15788 const ty_op = self.air.instructions.items(.data)[inst].ty_op;15792 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
15789 const ptr_va_list_ty = self.typeOf(ty_op.operand);15793 const ptr_va_list_ty = self.typeOf(ty_op.operand);
1579015794
15791 const dst_mcv = try self.allocRegOrMem(inst, true);15795 const dst_mcv = try self.allocRegOrMem(inst, true);
...@@ -15794,7 +15798,7 @@ fn airVaCopy(self: *Self, inst: Air.Inst.Index) !void {...@@ -15794,7 +15798,7 @@ fn airVaCopy(self: *Self, inst: Air.Inst.Index) !void {
15794}15798}
1579515799
15796fn airVaEnd(self: *Self, inst: Air.Inst.Index) !void {15800fn airVaEnd(self: *Self, inst: Air.Inst.Index) !void {
15797 const un_op = self.air.instructions.items(.data)[inst].un_op;15801 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
15798 return self.finishAir(inst, .unreach, .{ un_op, .none, .none });15802 return self.finishAir(inst, .unreach, .{ un_op, .none, .none });
15799}15803}
1580015804
...@@ -15805,10 +15809,10 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {...@@ -15805,10 +15809,10 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
15805 // If the type has no codegen bits, no need to store it.15809 // If the type has no codegen bits, no need to store it.
15806 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;15810 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
1580715811
15808 const mcv = if (Air.refToIndex(ref)) |inst| mcv: {15812 const mcv = if (ref.toIndex()) |inst| mcv: {
15809 break :mcv self.inst_tracking.getPtr(inst).?.short;15813 break :mcv self.inst_tracking.getPtr(inst).?.short;
15810 } else mcv: {15814 } else mcv: {
15811 const ip_index = Air.refToInterned(ref).?;15815 const ip_index = ref.toInterned().?;
15812 const gop = try self.const_tracking.getOrPut(self.gpa, ip_index);15816 const gop = try self.const_tracking.getOrPut(self.gpa, ip_index);
15813 if (!gop.found_existing) gop.value_ptr.* = InstTracking.init(init: {15817 if (!gop.found_existing) gop.value_ptr.* = InstTracking.init(init: {
15814 const const_mcv = try self.genTypedValue(.{ .ty = ty, .val = Value.fromInterned(ip_index) });15818 const const_mcv = try self.genTypedValue(.{ .ty = ty, .val = Value.fromInterned(ip_index) });
src/codegen/c.zig+145-129
...@@ -329,9 +329,13 @@ pub const Function = struct {...@@ -329,9 +329,13 @@ pub const Function = struct {
329 return .{ .new_local = @intCast(f.locals.items.len - 1) };329 return .{ .new_local = @intCast(f.locals.items.len - 1) };
330 }330 }
331331
332 fn allocLocal(f: *Function, inst: Air.Inst.Index, ty: Type) !CValue {332 fn allocLocal(f: *Function, inst: ?Air.Inst.Index, ty: Type) !CValue {
333 const result = try f.allocAlignedLocal(ty, .{}, .none);333 const result = try f.allocAlignedLocal(ty, .{}, .none);
334 log.debug("%{d}: allocating t{d}", .{ inst, result.new_local });334 if (inst) |i| {
335 log.debug("%{d}: allocating t{d}", .{ i, result.new_local });
336 } else {
337 log.debug("allocating t{d}", .{result.new_local});
338 }
335 return result;339 return result;
336 }340 }
337341
...@@ -2951,7 +2955,7 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con...@@ -2951,7 +2955,7 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con
2951 const pre_locals_len = @as(LocalIndex, @intCast(f.locals.items.len));2955 const pre_locals_len = @as(LocalIndex, @intCast(f.locals.items.len));
29522956
2953 for (leading_deaths) |death| {2957 for (leading_deaths) |death| {
2954 try die(f, inst, Air.indexToRef(death));2958 try die(f, inst, death.toRef());
2955 }2959 }
29562960
2957 if (inner) {2961 if (inner) {
...@@ -2969,11 +2973,11 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con...@@ -2969,11 +2973,11 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con
2969 // them, unless they were used to store allocs.2973 // them, unless they were used to store allocs.
29702974
2971 for (pre_locals_len..f.locals.items.len) |local_i| {2975 for (pre_locals_len..f.locals.items.len) |local_i| {
2972 const local_index = @as(LocalIndex, @intCast(local_i));2976 const local_index: LocalIndex = @intCast(local_i);
2973 if (f.allocs.contains(local_index)) {2977 if (f.allocs.contains(local_index)) {
2974 continue;2978 continue;
2975 }2979 }
2976 try freeLocal(f, inst, local_index, 0);2980 try freeLocal(f, inst, local_index, null);
2977 }2981 }
2978}2982}
29792983
...@@ -2986,7 +2990,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,...@@ -2986,7 +2990,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
2986 if (f.liveness.isUnused(inst) and !f.air.mustLower(inst, ip))2990 if (f.liveness.isUnused(inst) and !f.air.mustLower(inst, ip))
2987 continue;2991 continue;
29882992
2989 const result_value = switch (air_tags[inst]) {2993 const result_value = switch (air_tags[@intFromEnum(inst)]) {
2990 // zig fmt: off2994 // zig fmt: off
2991 .inferred_alloc, .inferred_alloc_comptime => unreachable,2995 .inferred_alloc, .inferred_alloc_comptime => unreachable,
29922996
...@@ -3013,7 +3017,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,...@@ -3013,7 +3017,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
30133017
3014 .div_trunc, .div_exact => try airBinOp(f, inst, "/", "div_trunc", .none),3018 .div_trunc, .div_exact => try airBinOp(f, inst, "/", "div_trunc", .none),
3015 .rem => blk: {3019 .rem => blk: {
3016 const bin_op = f.air.instructions.items(.data)[inst].bin_op;3020 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3017 const lhs_scalar_ty = f.typeOf(bin_op.lhs).scalarType(mod);3021 const lhs_scalar_ty = f.typeOf(bin_op.lhs).scalarType(mod);
3018 // For binary operations @TypeOf(lhs)==@TypeOf(rhs),3022 // For binary operations @TypeOf(lhs)==@TypeOf(rhs),
3019 // so we only check one.3023 // so we only check one.
...@@ -3061,16 +3065,16 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,...@@ -3061,16 +3065,16 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
30613065
3062 .slice => try airSlice(f, inst),3066 .slice => try airSlice(f, inst),
30633067
3064 .cmp_gt => try airCmpOp(f, inst, f.air.instructions.items(.data)[inst].bin_op, .gt),3068 .cmp_gt => try airCmpOp(f, inst, f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op, .gt),
3065 .cmp_gte => try airCmpOp(f, inst, f.air.instructions.items(.data)[inst].bin_op, .gte),3069 .cmp_gte => try airCmpOp(f, inst, f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op, .gte),
3066 .cmp_lt => try airCmpOp(f, inst, f.air.instructions.items(.data)[inst].bin_op, .lt),3070 .cmp_lt => try airCmpOp(f, inst, f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op, .lt),
3067 .cmp_lte => try airCmpOp(f, inst, f.air.instructions.items(.data)[inst].bin_op, .lte),3071 .cmp_lte => try airCmpOp(f, inst, f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op, .lte),
30683072
3069 .cmp_eq => try airEquality(f, inst, .eq),3073 .cmp_eq => try airEquality(f, inst, .eq),
3070 .cmp_neq => try airEquality(f, inst, .neq),3074 .cmp_neq => try airEquality(f, inst, .neq),
30713075
3072 .cmp_vector => blk: {3076 .cmp_vector => blk: {
3073 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;3077 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3074 const extra = f.air.extraData(Air.VectorCmp, ty_pl.payload).data;3078 const extra = f.air.extraData(Air.VectorCmp, ty_pl.payload).data;
3075 break :blk try airCmpOp(f, inst, extra, extra.compareOperator());3079 break :blk try airCmpOp(f, inst, extra, extra.compareOperator());
3076 },3080 },
...@@ -3256,7 +3260,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,...@@ -3256,7 +3260,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
3256 if (result_value == .new_local) {3260 if (result_value == .new_local) {
3257 log.debug("map %{d} to t{d}", .{ inst, result_value.new_local });3261 log.debug("map %{d} to t{d}", .{ inst, result_value.new_local });
3258 }3262 }
3259 try f.value_map.putNoClobber(Air.indexToRef(inst), switch (result_value) {3263 try f.value_map.putNoClobber(inst.toRef(), switch (result_value) {
3260 .none => continue,3264 .none => continue,
3261 .new_local => |i| .{ .local = i },3265 .new_local => |i| .{ .local = i },
3262 else => result_value,3266 else => result_value,
...@@ -3265,7 +3269,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,...@@ -3265,7 +3269,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
3265}3269}
32663270
3267fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: []const u8) !CValue {3271fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: []const u8) !CValue {
3268 const ty_op = f.air.instructions.items(.data)[inst].ty_op;3272 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
32693273
3270 const inst_ty = f.typeOfIndex(inst);3274 const inst_ty = f.typeOfIndex(inst);
3271 const operand = try f.resolveInst(ty_op.operand);3275 const operand = try f.resolveInst(ty_op.operand);
...@@ -3287,7 +3291,7 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: [...@@ -3287,7 +3291,7 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: [
3287fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {3291fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3288 const mod = f.object.dg.module;3292 const mod = f.object.dg.module;
3289 const inst_ty = f.typeOfIndex(inst);3293 const inst_ty = f.typeOfIndex(inst);
3290 const bin_op = f.air.instructions.items(.data)[inst].bin_op;3294 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3291 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {3295 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
3292 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });3296 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3293 return .none;3297 return .none;
...@@ -3312,7 +3316,7 @@ fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3312,7 +3316,7 @@ fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
33123316
3313fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {3317fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3314 const mod = f.object.dg.module;3318 const mod = f.object.dg.module;
3315 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;3319 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3316 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;3320 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
33173321
3318 const inst_ty = f.typeOfIndex(inst);3322 const inst_ty = f.typeOfIndex(inst);
...@@ -3349,7 +3353,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3349,7 +3353,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3349fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {3353fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3350 const mod = f.object.dg.module;3354 const mod = f.object.dg.module;
3351 const inst_ty = f.typeOfIndex(inst);3355 const inst_ty = f.typeOfIndex(inst);
3352 const bin_op = f.air.instructions.items(.data)[inst].bin_op;3356 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3353 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {3357 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
3354 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });3358 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3355 return .none;3359 return .none;
...@@ -3374,7 +3378,7 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3374,7 +3378,7 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
33743378
3375fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {3379fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3376 const mod = f.object.dg.module;3380 const mod = f.object.dg.module;
3377 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;3381 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3378 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;3382 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
33793383
3380 const inst_ty = f.typeOfIndex(inst);3384 const inst_ty = f.typeOfIndex(inst);
...@@ -3404,7 +3408,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3404,7 +3408,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
34043408
3405fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {3409fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3406 const mod = f.object.dg.module;3410 const mod = f.object.dg.module;
3407 const bin_op = f.air.instructions.items(.data)[inst].bin_op;3411 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3408 const inst_ty = f.typeOfIndex(inst);3412 const inst_ty = f.typeOfIndex(inst);
3409 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {3413 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
3410 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });3414 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
...@@ -3486,7 +3490,7 @@ fn airArg(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3486,7 +3490,7 @@ fn airArg(f: *Function, inst: Air.Inst.Index) !CValue {
34863490
3487fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {3491fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
3488 const mod = f.object.dg.module;3492 const mod = f.object.dg.module;
3489 const ty_op = f.air.instructions.items(.data)[inst].ty_op;3493 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
34903494
3491 const ptr_ty = f.typeOf(ty_op.operand);3495 const ptr_ty = f.typeOf(ty_op.operand);
3492 const ptr_scalar_ty = ptr_ty.scalarType(mod);3496 const ptr_scalar_ty = ptr_ty.scalarType(mod);
...@@ -3573,14 +3577,14 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3573,14 +3577,14 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
35733577
3574fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {3578fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
3575 const mod = f.object.dg.module;3579 const mod = f.object.dg.module;
3576 const un_op = f.air.instructions.items(.data)[inst].un_op;3580 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
3577 const writer = f.object.writer();3581 const writer = f.object.writer();
3578 const op_inst = Air.refToIndex(un_op);3582 const op_inst = un_op.toIndex();
3579 const op_ty = f.typeOf(un_op);3583 const op_ty = f.typeOf(un_op);
3580 const ret_ty = if (is_ptr) op_ty.childType(mod) else op_ty;3584 const ret_ty = if (is_ptr) op_ty.childType(mod) else op_ty;
3581 const lowered_ret_ty = try lowerFnRetTy(ret_ty, mod);3585 const lowered_ret_ty = try lowerFnRetTy(ret_ty, mod);
35823586
3583 if (op_inst != null and f.air.instructions.items(.tag)[op_inst.?] == .call_always_tail) {3587 if (op_inst != null and f.air.instructions.items(.tag)[@intFromEnum(op_inst.?)] == .call_always_tail) {
3584 try reap(f, inst, &.{un_op});3588 try reap(f, inst, &.{un_op});
3585 _ = try airCall(f, op_inst.?, .always_tail);3589 _ = try airCall(f, op_inst.?, .always_tail);
3586 } else if (lowered_ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {3590 } else if (lowered_ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
...@@ -3611,7 +3615,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {...@@ -3611,7 +3615,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
3611 try f.writeCValue(writer, ret_val, .Other);3615 try f.writeCValue(writer, ret_val, .Other);
3612 try writer.writeAll(";\n");3616 try writer.writeAll(";\n");
3613 if (is_array) {3617 if (is_array) {
3614 try freeLocal(f, inst, ret_val.new_local, 0);3618 try freeLocal(f, inst, ret_val.new_local, null);
3615 }3619 }
3616 } else {3620 } else {
3617 try reap(f, inst, &.{un_op});3621 try reap(f, inst, &.{un_op});
...@@ -3623,7 +3627,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {...@@ -3623,7 +3627,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
36233627
3624fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue {3628fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue {
3625 const mod = f.object.dg.module;3629 const mod = f.object.dg.module;
3626 const ty_op = f.air.instructions.items(.data)[inst].ty_op;3630 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
36273631
3628 const operand = try f.resolveInst(ty_op.operand);3632 const operand = try f.resolveInst(ty_op.operand);
3629 try reap(f, inst, &.{ty_op.operand});3633 try reap(f, inst, &.{ty_op.operand});
...@@ -3649,7 +3653,7 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3649,7 +3653,7 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue {
36493653
3650fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {3654fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
3651 const mod = f.object.dg.module;3655 const mod = f.object.dg.module;
3652 const ty_op = f.air.instructions.items(.data)[inst].ty_op;3656 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
36533657
3654 const operand = try f.resolveInst(ty_op.operand);3658 const operand = try f.resolveInst(ty_op.operand);
3655 try reap(f, inst, &.{ty_op.operand});3659 try reap(f, inst, &.{ty_op.operand});
...@@ -3732,7 +3736,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3732,7 +3736,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
3732}3736}
37333737
3734fn airIntFromBool(f: *Function, inst: Air.Inst.Index) !CValue {3738fn airIntFromBool(f: *Function, inst: Air.Inst.Index) !CValue {
3735 const un_op = f.air.instructions.items(.data)[inst].un_op;3739 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
3736 const operand = try f.resolveInst(un_op);3740 const operand = try f.resolveInst(un_op);
3737 try reap(f, inst, &.{un_op});3741 try reap(f, inst, &.{un_op});
3738 const writer = f.object.writer();3742 const writer = f.object.writer();
...@@ -3749,7 +3753,7 @@ fn airIntFromBool(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3749,7 +3753,7 @@ fn airIntFromBool(f: *Function, inst: Air.Inst.Index) !CValue {
3749fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {3753fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
3750 const mod = f.object.dg.module;3754 const mod = f.object.dg.module;
3751 // *a = b;3755 // *a = b;
3752 const bin_op = f.air.instructions.items(.data)[inst].bin_op;3756 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
37533757
3754 const ptr_ty = f.typeOf(bin_op.lhs);3758 const ptr_ty = f.typeOf(bin_op.lhs);
3755 const ptr_scalar_ty = ptr_ty.scalarType(mod);3759 const ptr_scalar_ty = ptr_ty.scalarType(mod);
...@@ -3815,7 +3819,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -3815,7 +3819,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
3815 try f.renderType(writer, src_ty);3819 try f.renderType(writer, src_ty);
3816 try writer.writeAll("))");3820 try writer.writeAll("))");
3817 if (src_val == .constant) {3821 if (src_val == .constant) {
3818 try freeLocal(f, inst, array_src.new_local, 0);3822 try freeLocal(f, inst, array_src.new_local, null);
3819 }3823 }
3820 } else if (ptr_info.packed_offset.host_size > 0 and ptr_info.flags.vector_index == .none) {3824 } else if (ptr_info.packed_offset.host_size > 0 and ptr_info.flags.vector_index == .none) {
3821 const host_bits = ptr_info.packed_offset.host_size * 8;3825 const host_bits = ptr_info.packed_offset.host_size * 8;
...@@ -3887,7 +3891,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -3887,7 +3891,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
38873891
3888fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info: BuiltinInfo) !CValue {3892fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info: BuiltinInfo) !CValue {
3889 const mod = f.object.dg.module;3893 const mod = f.object.dg.module;
3890 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;3894 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3891 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;3895 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
38923896
3893 const lhs = try f.resolveInst(bin_op.lhs);3897 const lhs = try f.resolveInst(bin_op.lhs);
...@@ -3925,7 +3929,7 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info:...@@ -3925,7 +3929,7 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info:
39253929
3926fn airNot(f: *Function, inst: Air.Inst.Index) !CValue {3930fn airNot(f: *Function, inst: Air.Inst.Index) !CValue {
3927 const mod = f.object.dg.module;3931 const mod = f.object.dg.module;
3928 const ty_op = f.air.instructions.items(.data)[inst].ty_op;3932 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3929 const operand_ty = f.typeOf(ty_op.operand);3933 const operand_ty = f.typeOf(ty_op.operand);
3930 const scalar_ty = operand_ty.scalarType(mod);3934 const scalar_ty = operand_ty.scalarType(mod);
3931 if (scalar_ty.ip_index != .bool_type) return try airUnBuiltinCall(f, inst, "not", .bits);3935 if (scalar_ty.ip_index != .bool_type) return try airUnBuiltinCall(f, inst, "not", .bits);
...@@ -3958,7 +3962,7 @@ fn airBinOp(...@@ -3958,7 +3962,7 @@ fn airBinOp(
3958 info: BuiltinInfo,3962 info: BuiltinInfo,
3959) !CValue {3963) !CValue {
3960 const mod = f.object.dg.module;3964 const mod = f.object.dg.module;
3961 const bin_op = f.air.instructions.items(.data)[inst].bin_op;3965 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3962 const operand_ty = f.typeOf(bin_op.lhs);3966 const operand_ty = f.typeOf(bin_op.lhs);
3963 const scalar_ty = operand_ty.scalarType(mod);3967 const scalar_ty = operand_ty.scalarType(mod);
3964 if ((scalar_ty.isInt(mod) and scalar_ty.bitSize(mod) > 64) or scalar_ty.isRuntimeFloat())3968 if ((scalar_ty.isInt(mod) and scalar_ty.bitSize(mod) > 64) or scalar_ty.isRuntimeFloat())
...@@ -4046,7 +4050,7 @@ fn airEquality(...@@ -4046,7 +4050,7 @@ fn airEquality(
4046 operator: std.math.CompareOperator,4050 operator: std.math.CompareOperator,
4047) !CValue {4051) !CValue {
4048 const mod = f.object.dg.module;4052 const mod = f.object.dg.module;
4049 const bin_op = f.air.instructions.items(.data)[inst].bin_op;4053 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
40504054
4051 const operand_ty = f.typeOf(bin_op.lhs);4055 const operand_ty = f.typeOf(bin_op.lhs);
4052 const operand_bits = operand_ty.bitSize(mod);4056 const operand_bits = operand_ty.bitSize(mod);
...@@ -4109,7 +4113,7 @@ fn airEquality(...@@ -4109,7 +4113,7 @@ fn airEquality(
4109}4113}
41104114
4111fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {4115fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {
4112 const un_op = f.air.instructions.items(.data)[inst].un_op;4116 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
41134117
4114 const inst_ty = f.typeOfIndex(inst);4118 const inst_ty = f.typeOfIndex(inst);
4115 const operand = try f.resolveInst(un_op);4119 const operand = try f.resolveInst(un_op);
...@@ -4126,7 +4130,7 @@ fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4126,7 +4130,7 @@ fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {
41264130
4127fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {4131fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
4128 const mod = f.object.dg.module;4132 const mod = f.object.dg.module;
4129 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;4133 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4130 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;4134 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
41314135
4132 const lhs = try f.resolveInst(bin_op.lhs);4136 const lhs = try f.resolveInst(bin_op.lhs);
...@@ -4174,7 +4178,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {...@@ -4174,7 +4178,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
41744178
4175fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []const u8) !CValue {4179fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []const u8) !CValue {
4176 const mod = f.object.dg.module;4180 const mod = f.object.dg.module;
4177 const bin_op = f.air.instructions.items(.data)[inst].bin_op;4181 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
41784182
4179 const inst_ty = f.typeOfIndex(inst);4183 const inst_ty = f.typeOfIndex(inst);
4180 const inst_scalar_ty = inst_ty.scalarType(mod);4184 const inst_scalar_ty = inst_ty.scalarType(mod);
...@@ -4216,7 +4220,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons...@@ -4216,7 +4220,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons
42164220
4217fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue {4221fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue {
4218 const mod = f.object.dg.module;4222 const mod = f.object.dg.module;
4219 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;4223 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4220 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;4224 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
42214225
4222 const ptr = try f.resolveInst(bin_op.lhs);4226 const ptr = try f.resolveInst(bin_op.lhs);
...@@ -4260,7 +4264,7 @@ fn airCall(...@@ -4260,7 +4264,7 @@ fn airCall(
4260 const gpa = f.object.dg.gpa;4264 const gpa = f.object.dg.gpa;
4261 const writer = f.object.writer();4265 const writer = f.object.writer();
42624266
4263 const pl_op = f.air.instructions.items(.data)[inst].pl_op;4267 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4264 const extra = f.air.extraData(Air.Call, pl_op.payload);4268 const extra = f.air.extraData(Air.Call, pl_op.payload);
4265 const args = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[extra.end..][0..extra.data.args_len]));4269 const args = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[extra.end..][0..extra.data.args_len]));
42664270
...@@ -4366,7 +4370,7 @@ fn airCall(...@@ -4366,7 +4370,7 @@ fn airCall(
4366 if (resolved_arg == .none) continue;4370 if (resolved_arg == .none) continue;
4367 if (args_written != 0) try writer.writeAll(", ");4371 if (args_written != 0) try writer.writeAll(", ");
4368 try f.writeCValue(writer, resolved_arg, .FunctionArgument);4372 try f.writeCValue(writer, resolved_arg, .FunctionArgument);
4369 if (resolved_arg == .new_local) try freeLocal(f, inst, resolved_arg.new_local, 0);4373 if (resolved_arg == .new_local) try freeLocal(f, inst, resolved_arg.new_local, null);
4370 args_written += 1;4374 args_written += 1;
4371 }4375 }
4372 try writer.writeAll(");\n");4376 try writer.writeAll(");\n");
...@@ -4383,7 +4387,7 @@ fn airCall(...@@ -4383,7 +4387,7 @@ fn airCall(
4383 try writer.writeAll(", sizeof(");4387 try writer.writeAll(", sizeof(");
4384 try f.renderType(writer, ret_ty);4388 try f.renderType(writer, ret_ty);
4385 try writer.writeAll("));\n");4389 try writer.writeAll("));\n");
4386 try freeLocal(f, inst, result_local.new_local, 0);4390 try freeLocal(f, inst, result_local.new_local, null);
4387 break :result array_local;4391 break :result array_local;
4388 };4392 };
43894393
...@@ -4391,7 +4395,7 @@ fn airCall(...@@ -4391,7 +4395,7 @@ fn airCall(
4391}4395}
43924396
4393fn airDbgStmt(f: *Function, inst: Air.Inst.Index) !CValue {4397fn airDbgStmt(f: *Function, inst: Air.Inst.Index) !CValue {
4394 const dbg_stmt = f.air.instructions.items(.data)[inst].dbg_stmt;4398 const dbg_stmt = f.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
4395 const writer = f.object.writer();4399 const writer = f.object.writer();
4396 // TODO re-evaluate whether to emit these or not. If we naively emit4400 // TODO re-evaluate whether to emit these or not. If we naively emit
4397 // these directives, the output file will report bogus line numbers because4401 // these directives, the output file will report bogus line numbers because
...@@ -4406,7 +4410,7 @@ fn airDbgStmt(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4406,7 +4410,7 @@ fn airDbgStmt(f: *Function, inst: Air.Inst.Index) !CValue {
4406}4410}
44074411
4408fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue {4412fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue {
4409 const ty_fn = f.air.instructions.items(.data)[inst].ty_fn;4413 const ty_fn = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
4410 const mod = f.object.dg.module;4414 const mod = f.object.dg.module;
4411 const writer = f.object.writer();4415 const writer = f.object.writer();
4412 const owner_decl = mod.funcOwnerDeclPtr(ty_fn.func);4416 const owner_decl = mod.funcOwnerDeclPtr(ty_fn.func);
...@@ -4418,7 +4422,7 @@ fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4418,7 +4422,7 @@ fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue {
44184422
4419fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue {4423fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue {
4420 const mod = f.object.dg.module;4424 const mod = f.object.dg.module;
4421 const pl_op = f.air.instructions.items(.data)[inst].pl_op;4425 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4422 const name = f.air.nullTerminatedString(pl_op.payload);4426 const name = f.air.nullTerminatedString(pl_op.payload);
4423 const operand_is_undef = if (try f.air.value(pl_op.operand, mod)) |v| v.isUndefDeep(mod) else false;4427 const operand_is_undef = if (try f.air.value(pl_op.operand, mod)) |v| v.isUndefDeep(mod) else false;
4424 if (!operand_is_undef) _ = try f.resolveInst(pl_op.operand);4428 if (!operand_is_undef) _ = try f.resolveInst(pl_op.operand);
...@@ -4431,9 +4435,9 @@ fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4431,9 +4435,9 @@ fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue {
44314435
4432fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {4436fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
4433 const mod = f.object.dg.module;4437 const mod = f.object.dg.module;
4434 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;4438 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4435 const extra = f.air.extraData(Air.Block, ty_pl.payload);4439 const extra = f.air.extraData(Air.Block, ty_pl.payload);
4436 const body = f.air.extra[extra.end..][0..extra.data.body_len];4440 const body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra.end..][0..extra.data.body_len]);
4437 const liveness_block = f.liveness.getBlock(inst);4441 const liveness_block = f.liveness.getBlock(inst);
44384442
4439 const block_id: usize = f.next_block_index;4443 const block_id: usize = f.next_block_index;
...@@ -4457,7 +4461,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4457,7 +4461,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
44574461
4458 // The body might result in some values we had beforehand being killed4462 // The body might result in some values we had beforehand being killed
4459 for (liveness_block.deaths) |death| {4463 for (liveness_block.deaths) |death| {
4460 try die(f, inst, Air.indexToRef(death));4464 try die(f, inst, death.toRef());
4461 }4465 }
44624466
4463 try f.object.indent_writer.insertNewline();4467 try f.object.indent_writer.insertNewline();
...@@ -4472,18 +4476,18 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4472,18 +4476,18 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
4472}4476}
44734477
4474fn airTry(f: *Function, inst: Air.Inst.Index) !CValue {4478fn airTry(f: *Function, inst: Air.Inst.Index) !CValue {
4475 const pl_op = f.air.instructions.items(.data)[inst].pl_op;4479 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4476 const extra = f.air.extraData(Air.Try, pl_op.payload);4480 const extra = f.air.extraData(Air.Try, pl_op.payload);
4477 const body = f.air.extra[extra.end..][0..extra.data.body_len];4481 const body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra.end..][0..extra.data.body_len]);
4478 const err_union_ty = f.typeOf(pl_op.operand);4482 const err_union_ty = f.typeOf(pl_op.operand);
4479 return lowerTry(f, inst, pl_op.operand, body, err_union_ty, false);4483 return lowerTry(f, inst, pl_op.operand, body, err_union_ty, false);
4480}4484}
44814485
4482fn airTryPtr(f: *Function, inst: Air.Inst.Index) !CValue {4486fn airTryPtr(f: *Function, inst: Air.Inst.Index) !CValue {
4483 const mod = f.object.dg.module;4487 const mod = f.object.dg.module;
4484 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;4488 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4485 const extra = f.air.extraData(Air.TryPtr, ty_pl.payload);4489 const extra = f.air.extraData(Air.TryPtr, ty_pl.payload);
4486 const body = f.air.extra[extra.end..][0..extra.data.body_len];4490 const body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra.end..][0..extra.data.body_len]);
4487 const err_union_ty = f.typeOf(extra.data.ptr).childType(mod);4491 const err_union_ty = f.typeOf(extra.data.ptr).childType(mod);
4488 return lowerTry(f, inst, extra.data.ptr, body, err_union_ty, true);4492 return lowerTry(f, inst, extra.data.ptr, body, err_union_ty, true);
4489}4493}
...@@ -4529,7 +4533,7 @@ fn lowerTry(...@@ -4529,7 +4533,7 @@ fn lowerTry(
45294533
4530 // Now we have the "then branch" (in terms of the liveness data); process any deaths.4534 // Now we have the "then branch" (in terms of the liveness data); process any deaths.
4531 for (liveness_condbr.then_deaths) |death| {4535 for (liveness_condbr.then_deaths) |death| {
4532 try die(f, inst, Air.indexToRef(death));4536 try die(f, inst, death.toRef());
4533 }4537 }
45344538
4535 if (!payload_has_bits) {4539 if (!payload_has_bits) {
...@@ -4559,7 +4563,7 @@ fn lowerTry(...@@ -4559,7 +4563,7 @@ fn lowerTry(
4559}4563}
45604564
4561fn airBr(f: *Function, inst: Air.Inst.Index) !CValue {4565fn airBr(f: *Function, inst: Air.Inst.Index) !CValue {
4562 const branch = f.air.instructions.items(.data)[inst].br;4566 const branch = f.air.instructions.items(.data)[@intFromEnum(inst)].br;
4563 const block = f.blocks.get(branch.block_inst).?;4567 const block = f.blocks.get(branch.block_inst).?;
4564 const result = block.result;4568 const result = block.result;
4565 const writer = f.object.writer();4569 const writer = f.object.writer();
...@@ -4582,7 +4586,7 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4582,7 +4586,7 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue {
4582}4586}
45834587
4584fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {4588fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
4585 const ty_op = f.air.instructions.items(.data)[inst].ty_op;4589 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4586 const dest_ty = f.typeOfIndex(inst);4590 const dest_ty = f.typeOfIndex(inst);
45874591
4588 const operand = try f.resolveInst(ty_op.operand);4592 const operand = try f.resolveInst(ty_op.operand);
...@@ -4624,7 +4628,7 @@ const LocalResult = struct {...@@ -4624,7 +4628,7 @@ const LocalResult = struct {
46244628
4625 fn free(lr: LocalResult, f: *Function) !void {4629 fn free(lr: LocalResult, f: *Function) !void {
4626 if (lr.need_free) {4630 if (lr.need_free) {
4627 try freeLocal(f, 0, lr.c_value.new_local, 0);4631 try freeLocal(f, null, lr.c_value.new_local, null);
4628 }4632 }
4629 }4633 }
4630};4634};
...@@ -4648,7 +4652,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca...@@ -4648,7 +4652,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
4648 }4652 }
46494653
4650 if (dest_ty.isPtrAtRuntime(mod) and operand_ty.isPtrAtRuntime(mod)) {4654 if (dest_ty.isPtrAtRuntime(mod) and operand_ty.isPtrAtRuntime(mod)) {
4651 const local = try f.allocLocal(0, dest_ty);4655 const local = try f.allocLocal(null, dest_ty);
4652 try f.writeCValue(writer, local, .Other);4656 try f.writeCValue(writer, local, .Other);
4653 try writer.writeAll(" = (");4657 try writer.writeAll(" = (");
4654 try f.renderType(writer, dest_ty);4658 try f.renderType(writer, dest_ty);
...@@ -4662,7 +4666,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca...@@ -4662,7 +4666,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
4662 }4666 }
46634667
4664 const operand_lval = if (operand == .constant) blk: {4668 const operand_lval = if (operand == .constant) blk: {
4665 const operand_local = try f.allocLocal(0, operand_ty);4669 const operand_local = try f.allocLocal(null, operand_ty);
4666 try f.writeCValue(writer, operand_local, .Other);4670 try f.writeCValue(writer, operand_local, .Other);
4667 if (operand_ty.isAbiInt(mod)) {4671 if (operand_ty.isAbiInt(mod)) {
4668 try writer.writeAll(" = ");4672 try writer.writeAll(" = ");
...@@ -4676,7 +4680,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca...@@ -4676,7 +4680,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
4676 break :blk operand_local;4680 break :blk operand_local;
4677 } else operand;4681 } else operand;
46784682
4679 const local = try f.allocLocal(0, dest_ty);4683 const local = try f.allocLocal(null, dest_ty);
4680 try writer.writeAll("memcpy(&");4684 try writer.writeAll("memcpy(&");
4681 try f.writeCValue(writer, local, .Other);4685 try f.writeCValue(writer, local, .Other);
4682 try writer.writeAll(", &");4686 try writer.writeAll(", &");
...@@ -4741,7 +4745,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca...@@ -4741,7 +4745,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
4741 }4745 }
47424746
4743 if (operand == .constant) {4747 if (operand == .constant) {
4744 try freeLocal(f, 0, operand_lval.new_local, 0);4748 try freeLocal(f, null, operand_lval.new_local, null);
4745 }4749 }
47464750
4747 return .{4751 return .{
...@@ -4784,7 +4788,7 @@ fn airFrameAddress(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4784,7 +4788,7 @@ fn airFrameAddress(f: *Function, inst: Air.Inst.Index) !CValue {
4784}4788}
47854789
4786fn airFence(f: *Function, inst: Air.Inst.Index) !CValue {4790fn airFence(f: *Function, inst: Air.Inst.Index) !CValue {
4787 const atomic_order = f.air.instructions.items(.data)[inst].fence;4791 const atomic_order = f.air.instructions.items(.data)[@intFromEnum(inst)].fence;
4788 const writer = f.object.writer();4792 const writer = f.object.writer();
47894793
4790 try writer.writeAll("zig_fence(");4794 try writer.writeAll("zig_fence(");
...@@ -4803,9 +4807,9 @@ fn airUnreach(f: *Function) !CValue {...@@ -4803,9 +4807,9 @@ fn airUnreach(f: *Function) !CValue {
4803}4807}
48044808
4805fn airLoop(f: *Function, inst: Air.Inst.Index) !CValue {4809fn airLoop(f: *Function, inst: Air.Inst.Index) !CValue {
4806 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;4810 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4807 const loop = f.air.extraData(Air.Block, ty_pl.payload);4811 const loop = f.air.extraData(Air.Block, ty_pl.payload);
4808 const body = f.air.extra[loop.end..][0..loop.data.body_len];4812 const body: []const Air.Inst.Index = @ptrCast(f.air.extra[loop.end..][0..loop.data.body_len]);
4809 const writer = f.object.writer();4813 const writer = f.object.writer();
48104814
4811 try writer.writeAll("for (;;) ");4815 try writer.writeAll("for (;;) ");
...@@ -4816,12 +4820,12 @@ fn airLoop(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4816,12 +4820,12 @@ fn airLoop(f: *Function, inst: Air.Inst.Index) !CValue {
4816}4820}
48174821
4818fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue {4822fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue {
4819 const pl_op = f.air.instructions.items(.data)[inst].pl_op;4823 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4820 const cond = try f.resolveInst(pl_op.operand);4824 const cond = try f.resolveInst(pl_op.operand);
4821 try reap(f, inst, &.{pl_op.operand});4825 try reap(f, inst, &.{pl_op.operand});
4822 const extra = f.air.extraData(Air.CondBr, pl_op.payload);4826 const extra = f.air.extraData(Air.CondBr, pl_op.payload);
4823 const then_body = f.air.extra[extra.end..][0..extra.data.then_body_len];4827 const then_body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra.end..][0..extra.data.then_body_len]);
4824 const else_body = f.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];4828 const else_body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
4825 const liveness_condbr = f.liveness.getCondBr(inst);4829 const liveness_condbr = f.liveness.getCondBr(inst);
4826 const writer = f.object.writer();4830 const writer = f.object.writer();
48274831
...@@ -4837,7 +4841,7 @@ fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4837,7 +4841,7 @@ fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue {
4837 // `free_locals_map` well defined (our parent is responsible for doing that).4841 // `free_locals_map` well defined (our parent is responsible for doing that).
48384842
4839 for (liveness_condbr.else_deaths) |death| {4843 for (liveness_condbr.else_deaths) |death| {
4840 try die(f, inst, Air.indexToRef(death));4844 try die(f, inst, death.toRef());
4841 }4845 }
48424846
4843 // We never actually need an else block, because our branches are noreturn so must (for4847 // We never actually need an else block, because our branches are noreturn so must (for
...@@ -4850,7 +4854,7 @@ fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4850,7 +4854,7 @@ fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue {
48504854
4851fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {4855fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
4852 const mod = f.object.dg.module;4856 const mod = f.object.dg.module;
4853 const pl_op = f.air.instructions.items(.data)[inst].pl_op;4857 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4854 const condition = try f.resolveInst(pl_op.operand);4858 const condition = try f.resolveInst(pl_op.operand);
4855 try reap(f, inst, &.{pl_op.operand});4859 try reap(f, inst, &.{pl_op.operand});
4856 const condition_ty = f.typeOf(pl_op.operand);4860 const condition_ty = f.typeOf(pl_op.operand);
...@@ -4883,7 +4887,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4883,7 +4887,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
4883 for (0..switch_br.data.cases_len) |case_i| {4887 for (0..switch_br.data.cases_len) |case_i| {
4884 const case = f.air.extraData(Air.SwitchBr.Case, extra_index);4888 const case = f.air.extraData(Air.SwitchBr.Case, extra_index);
4885 const items = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[case.end..][0..case.data.items_len]));4889 const items = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[case.end..][0..case.data.items_len]));
4886 const case_body = f.air.extra[case.end + items.len ..][0..case.data.body_len];4890 const case_body: []const Air.Inst.Index = @ptrCast(f.air.extra[case.end + items.len ..][0..case.data.body_len]);
4887 extra_index = case.end + case.data.items_len + case_body.len;4891 extra_index = case.end + case.data.items_len + case_body.len;
48884892
4889 for (items) |item| {4893 for (items) |item| {
...@@ -4903,7 +4907,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4903,7 +4907,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
4903 try genBodyResolveState(f, inst, liveness.deaths[case_i], case_body, false);4907 try genBodyResolveState(f, inst, liveness.deaths[case_i], case_body, false);
4904 } else {4908 } else {
4905 for (liveness.deaths[case_i]) |death| {4909 for (liveness.deaths[case_i]) |death| {
4906 try die(f, inst, Air.indexToRef(death));4910 try die(f, inst, death.toRef());
4907 }4911 }
4908 try genBody(f, case_body);4912 try genBody(f, case_body);
4909 }4913 }
...@@ -4911,12 +4915,12 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4911,12 +4915,12 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
4911 // The case body must be noreturn so we don't need to insert a break.4915 // The case body must be noreturn so we don't need to insert a break.
4912 }4916 }
49134917
4914 const else_body = f.air.extra[extra_index..][0..switch_br.data.else_body_len];4918 const else_body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra_index..][0..switch_br.data.else_body_len]);
4915 try f.object.indent_writer.insertNewline();4919 try f.object.indent_writer.insertNewline();
4916 if (else_body.len > 0) {4920 if (else_body.len > 0) {
4917 // Note that this must be the last case (i.e. the `last_case_i` case was not hit above)4921 // Note that this must be the last case (i.e. the `last_case_i` case was not hit above)
4918 for (liveness.deaths[liveness.deaths.len - 1]) |death| {4922 for (liveness.deaths[liveness.deaths.len - 1]) |death| {
4919 try die(f, inst, Air.indexToRef(death));4923 try die(f, inst, death.toRef());
4920 }4924 }
4921 try writer.writeAll("default: ");4925 try writer.writeAll("default: ");
4922 try genBody(f, else_body);4926 try genBody(f, else_body);
...@@ -4951,7 +4955,7 @@ fn asmInputNeedsLocal(f: *Function, constraint: []const u8, value: CValue) bool...@@ -4951,7 +4955,7 @@ fn asmInputNeedsLocal(f: *Function, constraint: []const u8, value: CValue) bool
49514955
4952fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {4956fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
4953 const mod = f.object.dg.module;4957 const mod = f.object.dg.module;
4954 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;4958 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4955 const extra = f.air.extraData(Air.Asm, ty_pl.payload);4959 const extra = f.air.extraData(Air.Asm, ty_pl.payload);
4956 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;4960 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
4957 const clobbers_len = @as(u31, @truncate(extra.data.flags));4961 const clobbers_len = @as(u31, @truncate(extra.data.flags));
...@@ -5213,7 +5217,7 @@ fn airIsNull(...@@ -5213,7 +5217,7 @@ fn airIsNull(
5213 is_ptr: bool,5217 is_ptr: bool,
5214) !CValue {5218) !CValue {
5215 const mod = f.object.dg.module;5219 const mod = f.object.dg.module;
5216 const un_op = f.air.instructions.items(.data)[inst].un_op;5220 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
52175221
5218 const writer = f.object.writer();5222 const writer = f.object.writer();
5219 const operand = try f.resolveInst(un_op);5223 const operand = try f.resolveInst(un_op);
...@@ -5259,7 +5263,7 @@ fn airIsNull(...@@ -5259,7 +5263,7 @@ fn airIsNull(
52595263
5260fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue {5264fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue {
5261 const mod = f.object.dg.module;5265 const mod = f.object.dg.module;
5262 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5266 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
52635267
5264 const operand = try f.resolveInst(ty_op.operand);5268 const operand = try f.resolveInst(ty_op.operand);
5265 try reap(f, inst, &.{ty_op.operand});5269 try reap(f, inst, &.{ty_op.operand});
...@@ -5293,7 +5297,7 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5293,7 +5297,7 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue {
52935297
5294fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue {5298fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue {
5295 const mod = f.object.dg.module;5299 const mod = f.object.dg.module;
5296 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5300 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
52975301
5298 const writer = f.object.writer();5302 const writer = f.object.writer();
5299 const operand = try f.resolveInst(ty_op.operand);5303 const operand = try f.resolveInst(ty_op.operand);
...@@ -5324,7 +5328,7 @@ fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5324,7 +5328,7 @@ fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue {
53245328
5325fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {5329fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
5326 const mod = f.object.dg.module;5330 const mod = f.object.dg.module;
5327 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5331 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5328 const writer = f.object.writer();5332 const writer = f.object.writer();
5329 const operand = try f.resolveInst(ty_op.operand);5333 const operand = try f.resolveInst(ty_op.operand);
5330 try reap(f, inst, &.{ty_op.operand});5334 try reap(f, inst, &.{ty_op.operand});
...@@ -5433,7 +5437,7 @@ fn fieldLocation(...@@ -5433,7 +5437,7 @@ fn fieldLocation(
5433}5437}
54345438
5435fn airStructFieldPtr(f: *Function, inst: Air.Inst.Index) !CValue {5439fn airStructFieldPtr(f: *Function, inst: Air.Inst.Index) !CValue {
5436 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;5440 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5437 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;5441 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;
54385442
5439 const container_ptr_val = try f.resolveInst(extra.struct_operand);5443 const container_ptr_val = try f.resolveInst(extra.struct_operand);
...@@ -5443,7 +5447,7 @@ fn airStructFieldPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5443,7 +5447,7 @@ fn airStructFieldPtr(f: *Function, inst: Air.Inst.Index) !CValue {
5443}5447}
54445448
5445fn airStructFieldPtrIndex(f: *Function, inst: Air.Inst.Index, index: u8) !CValue {5449fn airStructFieldPtrIndex(f: *Function, inst: Air.Inst.Index, index: u8) !CValue {
5446 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5450 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
54475451
5448 const container_ptr_val = try f.resolveInst(ty_op.operand);5452 const container_ptr_val = try f.resolveInst(ty_op.operand);
5449 try reap(f, inst, &.{ty_op.operand});5453 try reap(f, inst, &.{ty_op.operand});
...@@ -5453,7 +5457,7 @@ fn airStructFieldPtrIndex(f: *Function, inst: Air.Inst.Index, index: u8) !CValue...@@ -5453,7 +5457,7 @@ fn airStructFieldPtrIndex(f: *Function, inst: Air.Inst.Index, index: u8) !CValue
54535457
5454fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {5458fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
5455 const mod = f.object.dg.module;5459 const mod = f.object.dg.module;
5456 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;5460 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5457 const extra = f.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;5461 const extra = f.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
54585462
5459 const container_ptr_ty = f.typeOfIndex(inst);5463 const container_ptr_ty = f.typeOfIndex(inst);
...@@ -5558,7 +5562,7 @@ fn fieldPtr(...@@ -5558,7 +5562,7 @@ fn fieldPtr(
5558fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {5562fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5559 const mod = f.object.dg.module;5563 const mod = f.object.dg.module;
5560 const ip = &mod.intern_pool;5564 const ip = &mod.intern_pool;
5561 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;5565 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5562 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;5566 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;
55635567
5564 const inst_ty = f.typeOfIndex(inst);5568 const inst_ty = f.typeOfIndex(inst);
...@@ -5634,7 +5638,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5634,7 +5638,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5634 try writer.writeAll(", sizeof(");5638 try writer.writeAll(", sizeof(");
5635 try f.renderType(writer, inst_ty);5639 try f.renderType(writer, inst_ty);
5636 try writer.writeAll("));\n");5640 try writer.writeAll("));\n");
5637 try freeLocal(f, inst, temp_local.new_local, 0);5641 try freeLocal(f, inst, temp_local.new_local, null);
5638 return local;5642 return local;
5639 },5643 },
5640 },5644 },
...@@ -5666,7 +5670,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5666,7 +5670,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5666 try writer.writeAll("));\n");5670 try writer.writeAll("));\n");
56675671
5668 if (struct_byval == .constant) {5672 if (struct_byval == .constant) {
5669 try freeLocal(f, inst, operand_lval.new_local, 0);5673 try freeLocal(f, inst, operand_lval.new_local, null);
5670 }5674 }
56715675
5672 return local;5676 return local;
...@@ -5695,7 +5699,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5695,7 +5699,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5695/// Note that the result is never a pointer.5699/// Note that the result is never a pointer.
5696fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {5700fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
5697 const mod = f.object.dg.module;5701 const mod = f.object.dg.module;
5698 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5702 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56995703
5700 const inst_ty = f.typeOfIndex(inst);5704 const inst_ty = f.typeOfIndex(inst);
5701 const operand = try f.resolveInst(ty_op.operand);5705 const operand = try f.resolveInst(ty_op.operand);
...@@ -5736,7 +5740,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5736,7 +5740,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
57365740
5737fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {5741fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
5738 const mod = f.object.dg.module;5742 const mod = f.object.dg.module;
5739 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5743 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
57405744
5741 const inst_ty = f.typeOfIndex(inst);5745 const inst_ty = f.typeOfIndex(inst);
5742 const operand = try f.resolveInst(ty_op.operand);5746 const operand = try f.resolveInst(ty_op.operand);
...@@ -5772,7 +5776,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu...@@ -5772,7 +5776,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
57725776
5773fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {5777fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {
5774 const mod = f.object.dg.module;5778 const mod = f.object.dg.module;
5775 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5779 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
57765780
5777 const inst_ty = f.typeOfIndex(inst);5781 const inst_ty = f.typeOfIndex(inst);
5778 const repr_is_payload = inst_ty.optionalReprIsPayload(mod);5782 const repr_is_payload = inst_ty.optionalReprIsPayload(mod);
...@@ -5804,7 +5808,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5804,7 +5808,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {
58045808
5805fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {5809fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
5806 const mod = f.object.dg.module;5810 const mod = f.object.dg.module;
5807 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5811 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
58085812
5809 const inst_ty = f.typeOfIndex(inst);5813 const inst_ty = f.typeOfIndex(inst);
5810 const payload_ty = inst_ty.errorUnionPayload(mod);5814 const payload_ty = inst_ty.errorUnionPayload(mod);
...@@ -5844,7 +5848,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5844,7 +5848,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
5844fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {5848fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
5845 const mod = f.object.dg.module;5849 const mod = f.object.dg.module;
5846 const writer = f.object.writer();5850 const writer = f.object.writer();
5847 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5851 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5848 const operand = try f.resolveInst(ty_op.operand);5852 const operand = try f.resolveInst(ty_op.operand);
5849 const error_union_ty = f.typeOf(ty_op.operand).childType(mod);5853 const error_union_ty = f.typeOf(ty_op.operand).childType(mod);
58505854
...@@ -5894,7 +5898,7 @@ fn airSaveErrReturnTraceIndex(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5894,7 +5898,7 @@ fn airSaveErrReturnTraceIndex(f: *Function, inst: Air.Inst.Index) !CValue {
58945898
5895fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {5899fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
5896 const mod = f.object.dg.module;5900 const mod = f.object.dg.module;
5897 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5901 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
58985902
5899 const inst_ty = f.typeOfIndex(inst);5903 const inst_ty = f.typeOfIndex(inst);
5900 const payload_ty = inst_ty.errorUnionPayload(mod);5904 const payload_ty = inst_ty.errorUnionPayload(mod);
...@@ -5928,7 +5932,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5928,7 +5932,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
59285932
5929fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const u8) !CValue {5933fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const u8) !CValue {
5930 const mod = f.object.dg.module;5934 const mod = f.object.dg.module;
5931 const un_op = f.air.instructions.items(.data)[inst].un_op;5935 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
59325936
5933 const writer = f.object.writer();5937 const writer = f.object.writer();
5934 const operand = try f.resolveInst(un_op);5938 const operand = try f.resolveInst(un_op);
...@@ -5963,7 +5967,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const...@@ -5963,7 +5967,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const
59635967
5964fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {5968fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
5965 const mod = f.object.dg.module;5969 const mod = f.object.dg.module;
5966 const ty_op = f.air.instructions.items(.data)[inst].ty_op;5970 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
59675971
5968 const operand = try f.resolveInst(ty_op.operand);5972 const operand = try f.resolveInst(ty_op.operand);
5969 try reap(f, inst, &.{ty_op.operand});5973 try reap(f, inst, &.{ty_op.operand});
...@@ -5994,7 +5998,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5994,7 +5998,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
59945998
5995fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {5999fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
5996 const mod = f.object.dg.module;6000 const mod = f.object.dg.module;
5997 const ty_op = f.air.instructions.items(.data)[inst].ty_op;6001 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
59986002
5999 const inst_ty = f.typeOfIndex(inst);6003 const inst_ty = f.typeOfIndex(inst);
6000 const operand = try f.resolveInst(ty_op.operand);6004 const operand = try f.resolveInst(ty_op.operand);
...@@ -6037,7 +6041,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6037,7 +6041,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
60376041
6038fn airIntFromPtr(f: *Function, inst: Air.Inst.Index) !CValue {6042fn airIntFromPtr(f: *Function, inst: Air.Inst.Index) !CValue {
6039 const mod = f.object.dg.module;6043 const mod = f.object.dg.module;
6040 const un_op = f.air.instructions.items(.data)[inst].un_op;6044 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
60416045
6042 const operand = try f.resolveInst(un_op);6046 const operand = try f.resolveInst(un_op);
6043 const operand_ty = f.typeOf(un_op);6047 const operand_ty = f.typeOf(un_op);
...@@ -6066,7 +6070,7 @@ fn airUnBuiltinCall(...@@ -6066,7 +6070,7 @@ fn airUnBuiltinCall(
6066 info: BuiltinInfo,6070 info: BuiltinInfo,
6067) !CValue {6071) !CValue {
6068 const mod = f.object.dg.module;6072 const mod = f.object.dg.module;
6069 const ty_op = f.air.instructions.items(.data)[inst].ty_op;6073 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
60706074
6071 const operand = try f.resolveInst(ty_op.operand);6075 const operand = try f.resolveInst(ty_op.operand);
6072 try reap(f, inst, &.{ty_op.operand});6076 try reap(f, inst, &.{ty_op.operand});
...@@ -6110,7 +6114,7 @@ fn airBinBuiltinCall(...@@ -6110,7 +6114,7 @@ fn airBinBuiltinCall(
6110 info: BuiltinInfo,6114 info: BuiltinInfo,
6111) !CValue {6115) !CValue {
6112 const mod = f.object.dg.module;6116 const mod = f.object.dg.module;
6113 const bin_op = f.air.instructions.items(.data)[inst].bin_op;6117 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
61146118
6115 const operand_ty = f.typeOf(bin_op.lhs);6119 const operand_ty = f.typeOf(bin_op.lhs);
6116 const operand_cty = try f.typeToCType(operand_ty, .complete);6120 const operand_cty = try f.typeToCType(operand_ty, .complete);
...@@ -6215,7 +6219,7 @@ fn airCmpBuiltinCall(...@@ -6215,7 +6219,7 @@ fn airCmpBuiltinCall(
62156219
6216fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue {6220fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue {
6217 const mod = f.object.dg.module;6221 const mod = f.object.dg.module;
6218 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;6222 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6219 const extra = f.air.extraData(Air.Cmpxchg, ty_pl.payload).data;6223 const extra = f.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
6220 const inst_ty = f.typeOfIndex(inst);6224 const inst_ty = f.typeOfIndex(inst);
6221 const ptr = try f.resolveInst(extra.ptr);6225 const ptr = try f.resolveInst(extra.ptr);
...@@ -6311,7 +6315,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue...@@ -6311,7 +6315,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
6311 try new_value_mat.end(f, inst);6315 try new_value_mat.end(f, inst);
63126316
6313 if (f.liveness.isUnused(inst)) {6317 if (f.liveness.isUnused(inst)) {
6314 try freeLocal(f, inst, local.new_local, 0);6318 try freeLocal(f, inst, local.new_local, null);
6315 return .none;6319 return .none;
6316 }6320 }
63176321
...@@ -6320,7 +6324,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue...@@ -6320,7 +6324,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
63206324
6321fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {6325fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
6322 const mod = f.object.dg.module;6326 const mod = f.object.dg.module;
6323 const pl_op = f.air.instructions.items(.data)[inst].pl_op;6327 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6324 const extra = f.air.extraData(Air.AtomicRmw, pl_op.payload).data;6328 const extra = f.air.extraData(Air.AtomicRmw, pl_op.payload).data;
6325 const inst_ty = f.typeOfIndex(inst);6329 const inst_ty = f.typeOfIndex(inst);
6326 const ptr_ty = f.typeOf(pl_op.operand);6330 const ptr_ty = f.typeOf(pl_op.operand);
...@@ -6366,7 +6370,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6366,7 +6370,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
6366 try operand_mat.end(f, inst);6370 try operand_mat.end(f, inst);
63676371
6368 if (f.liveness.isUnused(inst)) {6372 if (f.liveness.isUnused(inst)) {
6369 try freeLocal(f, inst, local.new_local, 0);6373 try freeLocal(f, inst, local.new_local, null);
6370 return .none;6374 return .none;
6371 }6375 }
63726376
...@@ -6375,7 +6379,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6375,7 +6379,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
63756379
6376fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {6380fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
6377 const mod = f.object.dg.module;6381 const mod = f.object.dg.module;
6378 const atomic_load = f.air.instructions.items(.data)[inst].atomic_load;6382 const atomic_load = f.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
6379 const ptr = try f.resolveInst(atomic_load.ptr);6383 const ptr = try f.resolveInst(atomic_load.ptr);
6380 try reap(f, inst, &.{atomic_load.ptr});6384 try reap(f, inst, &.{atomic_load.ptr});
6381 const ptr_ty = f.typeOf(atomic_load.ptr);6385 const ptr_ty = f.typeOf(atomic_load.ptr);
...@@ -6411,7 +6415,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6411,7 +6415,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
64116415
6412fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CValue {6416fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CValue {
6413 const mod = f.object.dg.module;6417 const mod = f.object.dg.module;
6414 const bin_op = f.air.instructions.items(.data)[inst].bin_op;6418 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6415 const ptr_ty = f.typeOf(bin_op.lhs);6419 const ptr_ty = f.typeOf(bin_op.lhs);
6416 const ty = ptr_ty.childType(mod);6420 const ty = ptr_ty.childType(mod);
6417 const ptr = try f.resolveInst(bin_op.lhs);6421 const ptr = try f.resolveInst(bin_op.lhs);
...@@ -6455,7 +6459,7 @@ fn writeSliceOrPtr(f: *Function, writer: anytype, ptr: CValue, ptr_ty: Type) !vo...@@ -6455,7 +6459,7 @@ fn writeSliceOrPtr(f: *Function, writer: anytype, ptr: CValue, ptr_ty: Type) !vo
64556459
6456fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {6460fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
6457 const mod = f.object.dg.module;6461 const mod = f.object.dg.module;
6458 const bin_op = f.air.instructions.items(.data)[inst].bin_op;6462 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6459 const dest_ty = f.typeOf(bin_op.lhs);6463 const dest_ty = f.typeOf(bin_op.lhs);
6460 const dest_slice = try f.resolveInst(bin_op.lhs);6464 const dest_slice = try f.resolveInst(bin_op.lhs);
6461 const value = try f.resolveInst(bin_op.rhs);6465 const value = try f.resolveInst(bin_op.rhs);
...@@ -6542,7 +6546,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -6542,7 +6546,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
6542 try a.end(f, writer);6546 try a.end(f, writer);
65436547
6544 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });6548 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
6545 try freeLocal(f, inst, index.new_local, 0);6549 try freeLocal(f, inst, index.new_local, null);
65466550
6547 return .none;6551 return .none;
6548 }6552 }
...@@ -6577,7 +6581,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -6577,7 +6581,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
65776581
6578fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {6582fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
6579 const mod = f.object.dg.module;6583 const mod = f.object.dg.module;
6580 const bin_op = f.air.instructions.items(.data)[inst].bin_op;6584 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6581 const dest_ptr = try f.resolveInst(bin_op.lhs);6585 const dest_ptr = try f.resolveInst(bin_op.lhs);
6582 const src_ptr = try f.resolveInst(bin_op.rhs);6586 const src_ptr = try f.resolveInst(bin_op.rhs);
6583 const dest_ty = f.typeOf(bin_op.lhs);6587 const dest_ty = f.typeOf(bin_op.lhs);
...@@ -6616,7 +6620,7 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6616,7 +6620,7 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
66166620
6617fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {6621fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
6618 const mod = f.object.dg.module;6622 const mod = f.object.dg.module;
6619 const bin_op = f.air.instructions.items(.data)[inst].bin_op;6623 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6620 const union_ptr = try f.resolveInst(bin_op.lhs);6624 const union_ptr = try f.resolveInst(bin_op.lhs);
6621 const new_tag = try f.resolveInst(bin_op.rhs);6625 const new_tag = try f.resolveInst(bin_op.rhs);
6622 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });6626 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
...@@ -6637,7 +6641,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6637,7 +6641,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
66376641
6638fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {6642fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
6639 const mod = f.object.dg.module;6643 const mod = f.object.dg.module;
6640 const ty_op = f.air.instructions.items(.data)[inst].ty_op;6644 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
66416645
6642 const operand = try f.resolveInst(ty_op.operand);6646 const operand = try f.resolveInst(ty_op.operand);
6643 try reap(f, inst, &.{ty_op.operand});6647 try reap(f, inst, &.{ty_op.operand});
...@@ -6659,7 +6663,7 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6659,7 +6663,7 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
66596663
6660fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue {6664fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue {
6661 const mod = f.object.dg.module;6665 const mod = f.object.dg.module;
6662 const un_op = f.air.instructions.items(.data)[inst].un_op;6666 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
66636667
6664 const inst_ty = f.typeOfIndex(inst);6668 const inst_ty = f.typeOfIndex(inst);
6665 const enum_ty = f.typeOf(un_op);6669 const enum_ty = f.typeOf(un_op);
...@@ -6679,7 +6683,7 @@ fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6679,7 +6683,7 @@ fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue {
6679}6683}
66806684
6681fn airErrorName(f: *Function, inst: Air.Inst.Index) !CValue {6685fn airErrorName(f: *Function, inst: Air.Inst.Index) !CValue {
6682 const un_op = f.air.instructions.items(.data)[inst].un_op;6686 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
66836687
6684 const writer = f.object.writer();6688 const writer = f.object.writer();
6685 const inst_ty = f.typeOfIndex(inst);6689 const inst_ty = f.typeOfIndex(inst);
...@@ -6696,7 +6700,7 @@ fn airErrorName(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6696,7 +6700,7 @@ fn airErrorName(f: *Function, inst: Air.Inst.Index) !CValue {
66966700
6697fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue {6701fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue {
6698 const mod = f.object.dg.module;6702 const mod = f.object.dg.module;
6699 const ty_op = f.air.instructions.items(.data)[inst].ty_op;6703 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
67006704
6701 const operand = try f.resolveInst(ty_op.operand);6705 const operand = try f.resolveInst(ty_op.operand);
6702 try reap(f, inst, &.{ty_op.operand});6706 try reap(f, inst, &.{ty_op.operand});
...@@ -6719,7 +6723,7 @@ fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6719,7 +6723,7 @@ fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue {
6719}6723}
67206724
6721fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue {6725fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue {
6722 const pl_op = f.air.instructions.items(.data)[inst].pl_op;6726 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6723 const extra = f.air.extraData(Air.Bin, pl_op.payload).data;6727 const extra = f.air.extraData(Air.Bin, pl_op.payload).data;
67246728
6725 const pred = try f.resolveInst(pl_op.operand);6729 const pred = try f.resolveInst(pl_op.operand);
...@@ -6751,7 +6755,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6751,7 +6755,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue {
67516755
6752fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {6756fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
6753 const mod = f.object.dg.module;6757 const mod = f.object.dg.module;
6754 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;6758 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6755 const extra = f.air.extraData(Air.Shuffle, ty_pl.payload).data;6759 const extra = f.air.extraData(Air.Shuffle, ty_pl.payload).data;
67566760
6757 const mask = Value.fromInterned(extra.mask);6761 const mask = Value.fromInterned(extra.mask);
...@@ -6783,7 +6787,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6783,7 +6787,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
67836787
6784fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {6788fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
6785 const mod = f.object.dg.module;6789 const mod = f.object.dg.module;
6786 const reduce = f.air.instructions.items(.data)[inst].reduce;6790 const reduce = f.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
67876791
6788 const scalar_ty = f.typeOfIndex(inst);6792 const scalar_ty = f.typeOfIndex(inst);
6789 const operand = try f.resolveInst(reduce.operand);6793 const operand = try f.resolveInst(reduce.operand);
...@@ -6939,7 +6943,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6939,7 +6943,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
6939fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {6943fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
6940 const mod = f.object.dg.module;6944 const mod = f.object.dg.module;
6941 const ip = &mod.intern_pool;6945 const ip = &mod.intern_pool;
6942 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;6946 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6943 const inst_ty = f.typeOfIndex(inst);6947 const inst_ty = f.typeOfIndex(inst);
6944 const len = @as(usize, @intCast(inst_ty.arrayLen(mod)));6948 const len = @as(usize, @intCast(inst_ty.arrayLen(mod)));
6945 const elements = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[ty_pl.payload..][0..len]));6949 const elements = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[ty_pl.payload..][0..len]));
...@@ -7069,7 +7073,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7069,7 +7073,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
7069fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {7073fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
7070 const mod = f.object.dg.module;7074 const mod = f.object.dg.module;
7071 const ip = &mod.intern_pool;7075 const ip = &mod.intern_pool;
7072 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;7076 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7073 const extra = f.air.extraData(Air.UnionInit, ty_pl.payload).data;7077 const extra = f.air.extraData(Air.UnionInit, ty_pl.payload).data;
70747078
7075 const union_ty = f.typeOfIndex(inst);7079 const union_ty = f.typeOfIndex(inst);
...@@ -7117,7 +7121,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7117,7 +7121,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
71177121
7118fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {7122fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
7119 const mod = f.object.dg.module;7123 const mod = f.object.dg.module;
7120 const prefetch = f.air.instructions.items(.data)[inst].prefetch;7124 const prefetch = f.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
71217125
7122 const ptr_ty = f.typeOf(prefetch.ptr);7126 const ptr_ty = f.typeOf(prefetch.ptr);
7123 const ptr = try f.resolveInst(prefetch.ptr);7127 const ptr = try f.resolveInst(prefetch.ptr);
...@@ -7142,7 +7146,7 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7142,7 +7146,7 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
7142}7146}
71437147
7144fn airWasmMemorySize(f: *Function, inst: Air.Inst.Index) !CValue {7148fn airWasmMemorySize(f: *Function, inst: Air.Inst.Index) !CValue {
7145 const pl_op = f.air.instructions.items(.data)[inst].pl_op;7149 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
71467150
7147 const writer = f.object.writer();7151 const writer = f.object.writer();
7148 const inst_ty = f.typeOfIndex(inst);7152 const inst_ty = f.typeOfIndex(inst);
...@@ -7156,7 +7160,7 @@ fn airWasmMemorySize(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7156,7 +7160,7 @@ fn airWasmMemorySize(f: *Function, inst: Air.Inst.Index) !CValue {
7156}7160}
71577161
7158fn airWasmMemoryGrow(f: *Function, inst: Air.Inst.Index) !CValue {7162fn airWasmMemoryGrow(f: *Function, inst: Air.Inst.Index) !CValue {
7159 const pl_op = f.air.instructions.items(.data)[inst].pl_op;7163 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
71607164
7161 const writer = f.object.writer();7165 const writer = f.object.writer();
7162 const inst_ty = f.typeOfIndex(inst);7166 const inst_ty = f.typeOfIndex(inst);
...@@ -7174,7 +7178,7 @@ fn airWasmMemoryGrow(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7174,7 +7178,7 @@ fn airWasmMemoryGrow(f: *Function, inst: Air.Inst.Index) !CValue {
71747178
7175fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue {7179fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue {
7176 const mod = f.object.dg.module;7180 const mod = f.object.dg.module;
7177 const un_op = f.air.instructions.items(.data)[inst].un_op;7181 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
71787182
7179 const operand = try f.resolveInst(un_op);7183 const operand = try f.resolveInst(un_op);
7180 try reap(f, inst, &.{un_op});7184 try reap(f, inst, &.{un_op});
...@@ -7200,7 +7204,7 @@ fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7200,7 +7204,7 @@ fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue {
72007204
7201fn airAbs(f: *Function, inst: Air.Inst.Index) !CValue {7205fn airAbs(f: *Function, inst: Air.Inst.Index) !CValue {
7202 const mod = f.object.dg.module;7206 const mod = f.object.dg.module;
7203 const ty_op = f.air.instructions.items(.data)[inst].ty_op;7207 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7204 const operand = try f.resolveInst(ty_op.operand);7208 const operand = try f.resolveInst(ty_op.operand);
7205 const ty = f.typeOf(ty_op.operand);7209 const ty = f.typeOf(ty_op.operand);
7206 const scalar_ty = ty.scalarType(mod);7210 const scalar_ty = ty.scalarType(mod);
...@@ -7239,7 +7243,7 @@ fn unFloatOp(f: *Function, inst: Air.Inst.Index, operand: CValue, ty: Type, oper...@@ -7239,7 +7243,7 @@ fn unFloatOp(f: *Function, inst: Air.Inst.Index, operand: CValue, ty: Type, oper
7239}7243}
72407244
7241fn airUnFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CValue {7245fn airUnFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CValue {
7242 const un_op = f.air.instructions.items(.data)[inst].un_op;7246 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
72437247
7244 const operand = try f.resolveInst(un_op);7248 const operand = try f.resolveInst(un_op);
7245 try reap(f, inst, &.{un_op});7249 try reap(f, inst, &.{un_op});
...@@ -7250,7 +7254,7 @@ fn airUnFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVal...@@ -7250,7 +7254,7 @@ fn airUnFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVal
72507254
7251fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CValue {7255fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CValue {
7252 const mod = f.object.dg.module;7256 const mod = f.object.dg.module;
7253 const bin_op = f.air.instructions.items(.data)[inst].bin_op;7257 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
72547258
7255 const lhs = try f.resolveInst(bin_op.lhs);7259 const lhs = try f.resolveInst(bin_op.lhs);
7256 const rhs = try f.resolveInst(bin_op.rhs);7260 const rhs = try f.resolveInst(bin_op.rhs);
...@@ -7282,7 +7286,7 @@ fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVa...@@ -7282,7 +7286,7 @@ fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVa
72827286
7283fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue {7287fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue {
7284 const mod = f.object.dg.module;7288 const mod = f.object.dg.module;
7285 const pl_op = f.air.instructions.items(.data)[inst].pl_op;7289 const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7286 const bin_op = f.air.extraData(Air.Bin, pl_op.payload).data;7290 const bin_op = f.air.extraData(Air.Bin, pl_op.payload).data;
72877291
7288 const mulend1 = try f.resolveInst(bin_op.lhs);7292 const mulend1 = try f.resolveInst(bin_op.lhs);
...@@ -7336,7 +7340,7 @@ fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7336,7 +7340,7 @@ fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue {
7336}7340}
73377341
7338fn airCVaArg(f: *Function, inst: Air.Inst.Index) !CValue {7342fn airCVaArg(f: *Function, inst: Air.Inst.Index) !CValue {
7339 const ty_op = f.air.instructions.items(.data)[inst].ty_op;7343 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73407344
7341 const inst_ty = f.typeOfIndex(inst);7345 const inst_ty = f.typeOfIndex(inst);
7342 const va_list = try f.resolveInst(ty_op.operand);7346 const va_list = try f.resolveInst(ty_op.operand);
...@@ -7348,13 +7352,13 @@ fn airCVaArg(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7348,13 +7352,13 @@ fn airCVaArg(f: *Function, inst: Air.Inst.Index) !CValue {
7348 try writer.writeAll(" = va_arg(*(va_list *)");7352 try writer.writeAll(" = va_arg(*(va_list *)");
7349 try f.writeCValue(writer, va_list, .Other);7353 try f.writeCValue(writer, va_list, .Other);
7350 try writer.writeAll(", ");7354 try writer.writeAll(", ");
7351 try f.renderType(writer, f.air.getRefType(ty_op.ty));7355 try f.renderType(writer, ty_op.ty.toType());
7352 try writer.writeAll(");\n");7356 try writer.writeAll(");\n");
7353 return local;7357 return local;
7354}7358}
73557359
7356fn airCVaEnd(f: *Function, inst: Air.Inst.Index) !CValue {7360fn airCVaEnd(f: *Function, inst: Air.Inst.Index) !CValue {
7357 const un_op = f.air.instructions.items(.data)[inst].un_op;7361 const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
73587362
7359 const va_list = try f.resolveInst(un_op);7363 const va_list = try f.resolveInst(un_op);
7360 try reap(f, inst, &.{un_op});7364 try reap(f, inst, &.{un_op});
...@@ -7367,7 +7371,7 @@ fn airCVaEnd(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7367,7 +7371,7 @@ fn airCVaEnd(f: *Function, inst: Air.Inst.Index) !CValue {
7367}7371}
73687372
7369fn airCVaCopy(f: *Function, inst: Air.Inst.Index) !CValue {7373fn airCVaCopy(f: *Function, inst: Air.Inst.Index) !CValue {
7370 const ty_op = f.air.instructions.items(.data)[inst].ty_op;7374 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73717375
7372 const inst_ty = f.typeOfIndex(inst);7376 const inst_ty = f.typeOfIndex(inst);
7373 const va_list = try f.resolveInst(ty_op.operand);7377 const va_list = try f.resolveInst(ty_op.operand);
...@@ -7836,7 +7840,7 @@ const Materialize = struct {...@@ -7836,7 +7840,7 @@ const Materialize = struct {
78367840
7837 pub fn end(self: Materialize, f: *Function, inst: Air.Inst.Index) !void {7841 pub fn end(self: Materialize, f: *Function, inst: Air.Inst.Index) !void {
7838 switch (self.local) {7842 switch (self.local) {
7839 .new_local => |local| try freeLocal(f, inst, local, 0),7843 .new_local => |local| try freeLocal(f, inst, local, null),
7840 else => {},7844 else => {},
7841 }7845 }
7842 }7846 }
...@@ -7926,7 +7930,7 @@ const Vectorize = struct {...@@ -7926,7 +7930,7 @@ const Vectorize = struct {
7926 if (self.index != .none) {7930 if (self.index != .none) {
7927 f.object.indent_writer.popIndent();7931 f.object.indent_writer.popIndent();
7928 try writer.writeAll("}\n");7932 try writer.writeAll("}\n");
7929 try freeLocal(f, inst, self.index.new_local, 0);7933 try freeLocal(f, inst, self.index.new_local, null);
7930 }7934 }
7931 }7935 }
7932};7936};
...@@ -7972,7 +7976,7 @@ fn reap(f: *Function, inst: Air.Inst.Index, operands: []const Air.Inst.Ref) !voi...@@ -7972,7 +7976,7 @@ fn reap(f: *Function, inst: Air.Inst.Index, operands: []const Air.Inst.Ref) !voi
7972}7976}
79737977
7974fn die(f: *Function, inst: Air.Inst.Index, ref: Air.Inst.Ref) !void {7978fn die(f: *Function, inst: Air.Inst.Index, ref: Air.Inst.Ref) !void {
7975 const ref_inst = Air.refToIndex(ref) orelse return;7979 const ref_inst = ref.toIndex() orelse return;
7976 const c_value = (f.value_map.fetchRemove(ref) orelse return).value;7980 const c_value = (f.value_map.fetchRemove(ref) orelse return).value;
7977 const local_index = switch (c_value) {7981 const local_index = switch (c_value) {
7978 .local, .new_local => |l| l,7982 .local, .new_local => |l| l,
...@@ -7981,10 +7985,22 @@ fn die(f: *Function, inst: Air.Inst.Index, ref: Air.Inst.Ref) !void {...@@ -7981,10 +7985,22 @@ fn die(f: *Function, inst: Air.Inst.Index, ref: Air.Inst.Ref) !void {
7981 try freeLocal(f, inst, local_index, ref_inst);7985 try freeLocal(f, inst, local_index, ref_inst);
7982}7986}
79837987
7984fn freeLocal(f: *Function, inst: Air.Inst.Index, local_index: LocalIndex, ref_inst: Air.Inst.Index) !void {7988fn freeLocal(f: *Function, inst: ?Air.Inst.Index, local_index: LocalIndex, ref_inst: ?Air.Inst.Index) !void {
7985 const gpa = f.object.dg.gpa;7989 const gpa = f.object.dg.gpa;
7986 const local = &f.locals.items[local_index];7990 const local = &f.locals.items[local_index];
7987 log.debug("%{d}: freeing t{d} (operand %{d})", .{ inst, local_index, ref_inst });7991 if (inst) |i| {
7992 if (ref_inst) |operand| {
7993 log.debug("%{d}: freeing t{d} (operand %{d})", .{ @intFromEnum(i), local_index, operand });
7994 } else {
7995 log.debug("%{d}: freeing t{d}", .{ @intFromEnum(i), local_index });
7996 }
7997 } else {
7998 if (ref_inst) |operand| {
7999 log.debug("freeing t{d} (operand %{d})", .{ local_index, operand });
8000 } else {
8001 log.debug("freeing t{d}", .{local_index});
8002 }
8003 }
7988 const gop = try f.free_locals_map.getOrPut(gpa, local.getType());8004 const gop = try f.free_locals_map.getOrPut(gpa, local.getType());
7989 if (!gop.found_existing) gop.value_ptr.* = .{};8005 if (!gop.found_existing) gop.value_ptr.* = .{};
7990 if (std.debug.runtime_safety) {8006 if (std.debug.runtime_safety) {
src/codegen/llvm.zig+147-147
...@@ -4850,7 +4850,7 @@ pub const FuncGen = struct {...@@ -4850,7 +4850,7 @@ pub const FuncGen = struct {
4850 for (body, 0..) |inst, i| {4850 for (body, 0..) |inst, i| {
4851 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;4851 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;
48524852
4853 const val: Builder.Value = switch (air_tags[inst]) {4853 const val: Builder.Value = switch (air_tags[@intFromEnum(inst)]) {
4854 // zig fmt: off4854 // zig fmt: off
4855 .add => try self.airAdd(inst, .normal),4855 .add => try self.airAdd(inst, .normal),
4856 .add_optimized => try self.airAdd(inst, .fast),4856 .add_optimized => try self.airAdd(inst, .fast),
...@@ -5090,7 +5090,7 @@ pub const FuncGen = struct {...@@ -5090,7 +5090,7 @@ pub const FuncGen = struct {
5090 .work_group_id => try self.airWorkGroupId(inst),5090 .work_group_id => try self.airWorkGroupId(inst),
5091 // zig fmt: on5091 // zig fmt: on
5092 };5092 };
5093 if (val != .none) try self.func_inst_table.putNoClobber(self.gpa, Air.indexToRef(inst), val);5093 if (val != .none) try self.func_inst_table.putNoClobber(self.gpa, inst.toRef(), val);
5094 }5094 }
5095 }5095 }
50965096
...@@ -5103,7 +5103,7 @@ pub const FuncGen = struct {...@@ -5103,7 +5103,7 @@ pub const FuncGen = struct {
5103 };5103 };
51045104
5105 fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !Builder.Value {5105 fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !Builder.Value {
5106 const pl_op = self.air.instructions.items(.data)[inst].pl_op;5106 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5107 const extra = self.air.extraData(Air.Call, pl_op.payload);5107 const extra = self.air.extraData(Air.Call, pl_op.payload);
5108 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);5108 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
5109 const o = self.dg.object;5109 const o = self.dg.object;
...@@ -5450,7 +5450,7 @@ pub const FuncGen = struct {...@@ -5450,7 +5450,7 @@ pub const FuncGen = struct {
5450 fn airRet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5450 fn airRet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5451 const o = self.dg.object;5451 const o = self.dg.object;
5452 const mod = o.module;5452 const mod = o.module;
5453 const un_op = self.air.instructions.items(.data)[inst].un_op;5453 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5454 const ret_ty = self.typeOf(un_op);5454 const ret_ty = self.typeOf(un_op);
5455 if (self.ret_ptr != .none) {5455 if (self.ret_ptr != .none) {
5456 const operand = try self.resolveInst(un_op);5456 const operand = try self.resolveInst(un_op);
...@@ -5508,7 +5508,7 @@ pub const FuncGen = struct {...@@ -5508,7 +5508,7 @@ pub const FuncGen = struct {
5508 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5508 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5509 const o = self.dg.object;5509 const o = self.dg.object;
5510 const mod = o.module;5510 const mod = o.module;
5511 const un_op = self.air.instructions.items(.data)[inst].un_op;5511 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5512 const ptr_ty = self.typeOf(un_op);5512 const ptr_ty = self.typeOf(un_op);
5513 const ret_ty = ptr_ty.childType(mod);5513 const ret_ty = ptr_ty.childType(mod);
5514 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;5514 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
...@@ -5536,9 +5536,9 @@ pub const FuncGen = struct {...@@ -5536,9 +5536,9 @@ pub const FuncGen = struct {
55365536
5537 fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5537 fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5538 const o = self.dg.object;5538 const o = self.dg.object;
5539 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5539 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5540 const list = try self.resolveInst(ty_op.operand);5540 const list = try self.resolveInst(ty_op.operand);
5541 const arg_ty = self.air.getRefType(ty_op.ty);5541 const arg_ty = ty_op.ty.toType();
5542 const llvm_arg_ty = try o.lowerType(arg_ty);5542 const llvm_arg_ty = try o.lowerType(arg_ty);
55435543
5544 return self.wip.vaArg(list, llvm_arg_ty, "");5544 return self.wip.vaArg(list, llvm_arg_ty, "");
...@@ -5546,9 +5546,9 @@ pub const FuncGen = struct {...@@ -5546,9 +5546,9 @@ pub const FuncGen = struct {
55465546
5547 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5547 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5548 const o = self.dg.object;5548 const o = self.dg.object;
5549 const ty_op = self.air.instructions.items(.data)[inst].ty_op;5549 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5550 const src_list = try self.resolveInst(ty_op.operand);5550 const src_list = try self.resolveInst(ty_op.operand);
5551 const va_list_ty = self.air.getRefType(ty_op.ty);5551 const va_list_ty = ty_op.ty.toType();
5552 const llvm_va_list_ty = try o.lowerType(va_list_ty);5552 const llvm_va_list_ty = try o.lowerType(va_list_ty);
5553 const mod = o.module;5553 const mod = o.module;
55545554
...@@ -5563,7 +5563,7 @@ pub const FuncGen = struct {...@@ -5563,7 +5563,7 @@ pub const FuncGen = struct {
5563 }5563 }
55645564
5565 fn airCVaEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5565 fn airCVaEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5566 const un_op = self.air.instructions.items(.data)[inst].un_op;5566 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5567 const src_list = try self.resolveInst(un_op);5567 const src_list = try self.resolveInst(un_op);
55685568
5569 _ = try self.wip.callIntrinsic(.normal, .none, .va_end, &.{}, &.{src_list}, "");5569 _ = try self.wip.callIntrinsic(.normal, .none, .va_end, &.{}, &.{src_list}, "");
...@@ -5592,7 +5592,7 @@ pub const FuncGen = struct {...@@ -5592,7 +5592,7 @@ pub const FuncGen = struct {
5592 op: math.CompareOperator,5592 op: math.CompareOperator,
5593 fast: Builder.FastMathKind,5593 fast: Builder.FastMathKind,
5594 ) !Builder.Value {5594 ) !Builder.Value {
5595 const bin_op = self.air.instructions.items(.data)[inst].bin_op;5595 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5596 const lhs = try self.resolveInst(bin_op.lhs);5596 const lhs = try self.resolveInst(bin_op.lhs);
5597 const rhs = try self.resolveInst(bin_op.rhs);5597 const rhs = try self.resolveInst(bin_op.rhs);
5598 const operand_ty = self.typeOf(bin_op.lhs);5598 const operand_ty = self.typeOf(bin_op.lhs);
...@@ -5601,7 +5601,7 @@ pub const FuncGen = struct {...@@ -5601,7 +5601,7 @@ pub const FuncGen = struct {
5601 }5601 }
56025602
5603 fn airCmpVector(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {5603 fn airCmpVector(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
5604 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5604 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5605 const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;5605 const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;
56065606
5607 const lhs = try self.resolveInst(extra.lhs);5607 const lhs = try self.resolveInst(extra.lhs);
...@@ -5614,7 +5614,7 @@ pub const FuncGen = struct {...@@ -5614,7 +5614,7 @@ pub const FuncGen = struct {
56145614
5615 fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5615 fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5616 const o = self.dg.object;5616 const o = self.dg.object;
5617 const un_op = self.air.instructions.items(.data)[inst].un_op;5617 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5618 const operand = try self.resolveInst(un_op);5618 const operand = try self.resolveInst(un_op);
5619 const llvm_fn = try self.getCmpLtErrorsLenFunction();5619 const llvm_fn = try self.getCmpLtErrorsLenFunction();
5620 return self.wip.call(5620 return self.wip.call(
...@@ -5733,9 +5733,9 @@ pub const FuncGen = struct {...@@ -5733,9 +5733,9 @@ pub const FuncGen = struct {
5733 fn airBlock(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5733 fn airBlock(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5734 const o = self.dg.object;5734 const o = self.dg.object;
5735 const mod = o.module;5735 const mod = o.module;
5736 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5736 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5737 const extra = self.air.extraData(Air.Block, ty_pl.payload);5737 const extra = self.air.extraData(Air.Block, ty_pl.payload);
5738 const body = self.air.extra[extra.end..][0..extra.data.body_len];5738 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
5739 const inst_ty = self.typeOfIndex(inst);5739 const inst_ty = self.typeOfIndex(inst);
57405740
5741 if (inst_ty.isNoReturn(mod)) {5741 if (inst_ty.isNoReturn(mod)) {
...@@ -5785,7 +5785,7 @@ pub const FuncGen = struct {...@@ -5785,7 +5785,7 @@ pub const FuncGen = struct {
57855785
5786 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5786 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5787 const o = self.dg.object;5787 const o = self.dg.object;
5788 const branch = self.air.instructions.items(.data)[inst].br;5788 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
5789 const block = self.blocks.get(branch.block_inst).?;5789 const block = self.blocks.get(branch.block_inst).?;
57905790
5791 // Add the values to the lists only if the break provides a value.5791 // Add the values to the lists only if the break provides a value.
...@@ -5803,11 +5803,11 @@ pub const FuncGen = struct {...@@ -5803,11 +5803,11 @@ pub const FuncGen = struct {
5803 }5803 }
58045804
5805 fn airCondBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5805 fn airCondBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5806 const pl_op = self.air.instructions.items(.data)[inst].pl_op;5806 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5807 const cond = try self.resolveInst(pl_op.operand);5807 const cond = try self.resolveInst(pl_op.operand);
5808 const extra = self.air.extraData(Air.CondBr, pl_op.payload);5808 const extra = self.air.extraData(Air.CondBr, pl_op.payload);
5809 const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len];5809 const then_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.then_body_len]);
5810 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];5810 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
58115811
5812 const then_block = try self.wip.block(1, "Then");5812 const then_block = try self.wip.block(1, "Then");
5813 const else_block = try self.wip.block(1, "Else");5813 const else_block = try self.wip.block(1, "Else");
...@@ -5827,10 +5827,10 @@ pub const FuncGen = struct {...@@ -5827,10 +5827,10 @@ pub const FuncGen = struct {
5827 const o = self.dg.object;5827 const o = self.dg.object;
5828 const mod = o.module;5828 const mod = o.module;
5829 const inst = body_tail[0];5829 const inst = body_tail[0];
5830 const pl_op = self.air.instructions.items(.data)[inst].pl_op;5830 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5831 const err_union = try self.resolveInst(pl_op.operand);5831 const err_union = try self.resolveInst(pl_op.operand);
5832 const extra = self.air.extraData(Air.Try, pl_op.payload);5832 const extra = self.air.extraData(Air.Try, pl_op.payload);
5833 const body = self.air.extra[extra.end..][0..extra.data.body_len];5833 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
5834 const err_union_ty = self.typeOf(pl_op.operand);5834 const err_union_ty = self.typeOf(pl_op.operand);
5835 const payload_ty = self.typeOfIndex(inst);5835 const payload_ty = self.typeOfIndex(inst);
5836 const can_elide_load = if (isByRef(payload_ty, mod)) self.canElideLoad(body_tail) else false;5836 const can_elide_load = if (isByRef(payload_ty, mod)) self.canElideLoad(body_tail) else false;
...@@ -5841,10 +5841,10 @@ pub const FuncGen = struct {...@@ -5841,10 +5841,10 @@ pub const FuncGen = struct {
5841 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5841 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5842 const o = self.dg.object;5842 const o = self.dg.object;
5843 const mod = o.module;5843 const mod = o.module;
5844 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5844 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5845 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);5845 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
5846 const err_union_ptr = try self.resolveInst(extra.data.ptr);5846 const err_union_ptr = try self.resolveInst(extra.data.ptr);
5847 const body = self.air.extra[extra.end..][0..extra.data.body_len];5847 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
5848 const err_union_ty = self.typeOf(extra.data.ptr).childType(mod);5848 const err_union_ty = self.typeOf(extra.data.ptr).childType(mod);
5849 const is_unused = self.liveness.isUnused(inst);5849 const is_unused = self.liveness.isUnused(inst);
5850 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused);5850 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused);
...@@ -5924,7 +5924,7 @@ pub const FuncGen = struct {...@@ -5924,7 +5924,7 @@ pub const FuncGen = struct {
59245924
5925 fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5925 fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5926 const o = self.dg.object;5926 const o = self.dg.object;
5927 const pl_op = self.air.instructions.items(.data)[inst].pl_op;5927 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5928 const cond = try self.resolveInst(pl_op.operand);5928 const cond = try self.resolveInst(pl_op.operand);
5929 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);5929 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
5930 const else_block = try self.wip.block(1, "Default");5930 const else_block = try self.wip.block(1, "Default");
...@@ -5956,7 +5956,7 @@ pub const FuncGen = struct {...@@ -5956,7 +5956,7 @@ pub const FuncGen = struct {
5956 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);5956 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
5957 const items: []const Air.Inst.Ref =5957 const items: []const Air.Inst.Ref =
5958 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]);5958 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]);
5959 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];5959 const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]);
5960 extra_index = case.end + case.data.items_len + case_body.len;5960 extra_index = case.end + case.data.items_len + case_body.len;
59615961
5962 const case_block = try self.wip.block(@intCast(items.len), "Case");5962 const case_block = try self.wip.block(@intCast(items.len), "Case");
...@@ -5975,7 +5975,7 @@ pub const FuncGen = struct {...@@ -5975,7 +5975,7 @@ pub const FuncGen = struct {
5975 }5975 }
59765976
5977 self.wip.cursor = .{ .block = else_block };5977 self.wip.cursor = .{ .block = else_block };
5978 const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len];5978 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]);
5979 if (else_body.len != 0) {5979 if (else_body.len != 0) {
5980 try self.genBody(else_body);5980 try self.genBody(else_body);
5981 } else {5981 } else {
...@@ -5989,9 +5989,9 @@ pub const FuncGen = struct {...@@ -5989,9 +5989,9 @@ pub const FuncGen = struct {
5989 fn airLoop(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5989 fn airLoop(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5990 const o = self.dg.object;5990 const o = self.dg.object;
5991 const mod = o.module;5991 const mod = o.module;
5992 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5992 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5993 const loop = self.air.extraData(Air.Block, ty_pl.payload);5993 const loop = self.air.extraData(Air.Block, ty_pl.payload);
5994 const body = self.air.extra[loop.end..][0..loop.data.body_len];5994 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);
5995 const loop_block = try self.wip.block(2, "Loop");5995 const loop_block = try self.wip.block(2, "Loop");
5996 _ = try self.wip.br(loop_block);5996 _ = try self.wip.br(loop_block);
59975997
...@@ -6013,7 +6013,7 @@ pub const FuncGen = struct {...@@ -6013,7 +6013,7 @@ pub const FuncGen = struct {
6013 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6013 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6014 const o = self.dg.object;6014 const o = self.dg.object;
6015 const mod = o.module;6015 const mod = o.module;
6016 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6016 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6017 const operand_ty = self.typeOf(ty_op.operand);6017 const operand_ty = self.typeOf(ty_op.operand);
6018 const array_ty = operand_ty.childType(mod);6018 const array_ty = operand_ty.childType(mod);
6019 const llvm_usize = try o.lowerType(Type.usize);6019 const llvm_usize = try o.lowerType(Type.usize);
...@@ -6031,7 +6031,7 @@ pub const FuncGen = struct {...@@ -6031,7 +6031,7 @@ pub const FuncGen = struct {
6031 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6031 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6032 const o = self.dg.object;6032 const o = self.dg.object;
6033 const mod = o.module;6033 const mod = o.module;
6034 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6034 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
60356035
6036 const workaround_operand = try self.resolveInst(ty_op.operand);6036 const workaround_operand = try self.resolveInst(ty_op.operand);
6037 const operand_ty = self.typeOf(ty_op.operand);6037 const operand_ty = self.typeOf(ty_op.operand);
...@@ -6116,7 +6116,7 @@ pub const FuncGen = struct {...@@ -6116,7 +6116,7 @@ pub const FuncGen = struct {
6116 const o = self.dg.object;6116 const o = self.dg.object;
6117 const mod = o.module;6117 const mod = o.module;
6118 const target = mod.getTarget();6118 const target = mod.getTarget();
6119 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6119 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61206120
6121 const operand = try self.resolveInst(ty_op.operand);6121 const operand = try self.resolveInst(ty_op.operand);
6122 const operand_ty = self.typeOf(ty_op.operand);6122 const operand_ty = self.typeOf(ty_op.operand);
...@@ -6203,7 +6203,7 @@ pub const FuncGen = struct {...@@ -6203,7 +6203,7 @@ pub const FuncGen = struct {
6203 }6203 }
62046204
6205 fn airSliceField(self: *FuncGen, inst: Air.Inst.Index, index: u32) !Builder.Value {6205 fn airSliceField(self: *FuncGen, inst: Air.Inst.Index, index: u32) !Builder.Value {
6206 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6206 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6207 const operand = try self.resolveInst(ty_op.operand);6207 const operand = try self.resolveInst(ty_op.operand);
6208 return self.wip.extractValue(operand, &.{index}, "");6208 return self.wip.extractValue(operand, &.{index}, "");
6209 }6209 }
...@@ -6211,7 +6211,7 @@ pub const FuncGen = struct {...@@ -6211,7 +6211,7 @@ pub const FuncGen = struct {
6211 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {6211 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {
6212 const o = self.dg.object;6212 const o = self.dg.object;
6213 const mod = o.module;6213 const mod = o.module;
6214 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6214 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6215 const slice_ptr = try self.resolveInst(ty_op.operand);6215 const slice_ptr = try self.resolveInst(ty_op.operand);
6216 const slice_ptr_ty = self.typeOf(ty_op.operand);6216 const slice_ptr_ty = self.typeOf(ty_op.operand);
6217 const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(mod));6217 const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(mod));
...@@ -6223,7 +6223,7 @@ pub const FuncGen = struct {...@@ -6223,7 +6223,7 @@ pub const FuncGen = struct {
6223 const o = self.dg.object;6223 const o = self.dg.object;
6224 const mod = o.module;6224 const mod = o.module;
6225 const inst = body_tail[0];6225 const inst = body_tail[0];
6226 const bin_op = self.air.instructions.items(.data)[inst].bin_op;6226 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6227 const slice_ty = self.typeOf(bin_op.lhs);6227 const slice_ty = self.typeOf(bin_op.lhs);
6228 const slice = try self.resolveInst(bin_op.lhs);6228 const slice = try self.resolveInst(bin_op.lhs);
6229 const index = try self.resolveInst(bin_op.rhs);6229 const index = try self.resolveInst(bin_op.rhs);
...@@ -6245,7 +6245,7 @@ pub const FuncGen = struct {...@@ -6245,7 +6245,7 @@ pub const FuncGen = struct {
6245 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6245 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6246 const o = self.dg.object;6246 const o = self.dg.object;
6247 const mod = o.module;6247 const mod = o.module;
6248 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6248 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6249 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;6249 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
6250 const slice_ty = self.typeOf(bin_op.lhs);6250 const slice_ty = self.typeOf(bin_op.lhs);
62516251
...@@ -6261,7 +6261,7 @@ pub const FuncGen = struct {...@@ -6261,7 +6261,7 @@ pub const FuncGen = struct {
6261 const mod = o.module;6261 const mod = o.module;
6262 const inst = body_tail[0];6262 const inst = body_tail[0];
62636263
6264 const bin_op = self.air.instructions.items(.data)[inst].bin_op;6264 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6265 const array_ty = self.typeOf(bin_op.lhs);6265 const array_ty = self.typeOf(bin_op.lhs);
6266 const array_llvm_val = try self.resolveInst(bin_op.lhs);6266 const array_llvm_val = try self.resolveInst(bin_op.lhs);
6267 const rhs = try self.resolveInst(bin_op.rhs);6267 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -6278,12 +6278,12 @@ pub const FuncGen = struct {...@@ -6278,12 +6278,12 @@ pub const FuncGen = struct {
6278 const elem_alignment = elem_ty.abiAlignment(mod).toLlvm();6278 const elem_alignment = elem_ty.abiAlignment(mod).toLlvm();
6279 return self.loadByRef(elem_ptr, elem_ty, elem_alignment, .normal);6279 return self.loadByRef(elem_ptr, elem_ty, elem_alignment, .normal);
6280 } else {6280 } else {
6281 if (Air.refToIndex(bin_op.lhs)) |lhs_index| {6281 if (bin_op.lhs.toIndex()) |lhs_index| {
6282 if (self.air.instructions.items(.tag)[lhs_index] == .load) {6282 if (self.air.instructions.items(.tag)[@intFromEnum(lhs_index)] == .load) {
6283 const load_data = self.air.instructions.items(.data)[lhs_index];6283 const load_data = self.air.instructions.items(.data)[@intFromEnum(lhs_index)];
6284 const load_ptr = load_data.ty_op.operand;6284 const load_ptr = load_data.ty_op.operand;
6285 if (Air.refToIndex(load_ptr)) |load_ptr_index| {6285 if (load_ptr.toIndex()) |load_ptr_index| {
6286 const load_ptr_tag = self.air.instructions.items(.tag)[load_ptr_index];6286 const load_ptr_tag = self.air.instructions.items(.tag)[@intFromEnum(load_ptr_index)];
6287 switch (load_ptr_tag) {6287 switch (load_ptr_tag) {
6288 .struct_field_ptr,6288 .struct_field_ptr,
6289 .struct_field_ptr_index_0,6289 .struct_field_ptr_index_0,
...@@ -6320,7 +6320,7 @@ pub const FuncGen = struct {...@@ -6320,7 +6320,7 @@ pub const FuncGen = struct {
6320 const o = self.dg.object;6320 const o = self.dg.object;
6321 const mod = o.module;6321 const mod = o.module;
6322 const inst = body_tail[0];6322 const inst = body_tail[0];
6323 const bin_op = self.air.instructions.items(.data)[inst].bin_op;6323 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6324 const ptr_ty = self.typeOf(bin_op.lhs);6324 const ptr_ty = self.typeOf(bin_op.lhs);
6325 const elem_ty = ptr_ty.childType(mod);6325 const elem_ty = ptr_ty.childType(mod);
6326 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);6326 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
...@@ -6344,7 +6344,7 @@ pub const FuncGen = struct {...@@ -6344,7 +6344,7 @@ pub const FuncGen = struct {
6344 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6344 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6345 const o = self.dg.object;6345 const o = self.dg.object;
6346 const mod = o.module;6346 const mod = o.module;
6347 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6347 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6348 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;6348 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
6349 const ptr_ty = self.typeOf(bin_op.lhs);6349 const ptr_ty = self.typeOf(bin_op.lhs);
6350 const elem_ty = ptr_ty.childType(mod);6350 const elem_ty = ptr_ty.childType(mod);
...@@ -6353,7 +6353,7 @@ pub const FuncGen = struct {...@@ -6353,7 +6353,7 @@ pub const FuncGen = struct {
6353 const base_ptr = try self.resolveInst(bin_op.lhs);6353 const base_ptr = try self.resolveInst(bin_op.lhs);
6354 const rhs = try self.resolveInst(bin_op.rhs);6354 const rhs = try self.resolveInst(bin_op.rhs);
63556355
6356 const elem_ptr = self.air.getRefType(ty_pl.ty);6356 const elem_ptr = ty_pl.ty.toType();
6357 if (elem_ptr.ptrInfo(mod).flags.vector_index != .none) return base_ptr;6357 if (elem_ptr.ptrInfo(mod).flags.vector_index != .none) return base_ptr;
63586358
6359 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);6359 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
...@@ -6365,7 +6365,7 @@ pub const FuncGen = struct {...@@ -6365,7 +6365,7 @@ pub const FuncGen = struct {
6365 }6365 }
63666366
6367 fn airStructFieldPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6367 fn airStructFieldPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6368 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6368 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6369 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;6369 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
6370 const struct_ptr = try self.resolveInst(struct_field.struct_operand);6370 const struct_ptr = try self.resolveInst(struct_field.struct_operand);
6371 const struct_ptr_ty = self.typeOf(struct_field.struct_operand);6371 const struct_ptr_ty = self.typeOf(struct_field.struct_operand);
...@@ -6377,7 +6377,7 @@ pub const FuncGen = struct {...@@ -6377,7 +6377,7 @@ pub const FuncGen = struct {
6377 inst: Air.Inst.Index,6377 inst: Air.Inst.Index,
6378 field_index: u32,6378 field_index: u32,
6379 ) !Builder.Value {6379 ) !Builder.Value {
6380 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6380 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6381 const struct_ptr = try self.resolveInst(ty_op.operand);6381 const struct_ptr = try self.resolveInst(ty_op.operand);
6382 const struct_ptr_ty = self.typeOf(ty_op.operand);6382 const struct_ptr_ty = self.typeOf(ty_op.operand);
6383 return self.fieldPtr(inst, struct_ptr, struct_ptr_ty, field_index);6383 return self.fieldPtr(inst, struct_ptr, struct_ptr_ty, field_index);
...@@ -6387,7 +6387,7 @@ pub const FuncGen = struct {...@@ -6387,7 +6387,7 @@ pub const FuncGen = struct {
6387 const o = self.dg.object;6387 const o = self.dg.object;
6388 const mod = o.module;6388 const mod = o.module;
6389 const inst = body_tail[0];6389 const inst = body_tail[0];
6390 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6390 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6391 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;6391 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
6392 const struct_ty = self.typeOf(struct_field.struct_operand);6392 const struct_ty = self.typeOf(struct_field.struct_operand);
6393 const struct_llvm_val = try self.resolveInst(struct_field.struct_operand);6393 const struct_llvm_val = try self.resolveInst(struct_field.struct_operand);
...@@ -6491,16 +6491,16 @@ pub const FuncGen = struct {...@@ -6491,16 +6491,16 @@ pub const FuncGen = struct {
6491 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6491 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6492 const o = self.dg.object;6492 const o = self.dg.object;
6493 const mod = o.module;6493 const mod = o.module;
6494 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6494 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6495 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;6495 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
64966496
6497 const field_ptr = try self.resolveInst(extra.field_ptr);6497 const field_ptr = try self.resolveInst(extra.field_ptr);
64986498
6499 const parent_ty = self.air.getRefType(ty_pl.ty).childType(mod);6499 const parent_ty = ty_pl.ty.toType().childType(mod);
6500 const field_offset = parent_ty.structFieldOffset(extra.field_index, mod);6500 const field_offset = parent_ty.structFieldOffset(extra.field_index, mod);
6501 if (field_offset == 0) return field_ptr;6501 if (field_offset == 0) return field_ptr;
65026502
6503 const res_ty = try o.lowerType(self.air.getRefType(ty_pl.ty));6503 const res_ty = try o.lowerType(ty_pl.ty.toType());
6504 const llvm_usize = try o.lowerType(Type.usize);6504 const llvm_usize = try o.lowerType(Type.usize);
65056505
6506 const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, "");6506 const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, "");
...@@ -6514,7 +6514,7 @@ pub const FuncGen = struct {...@@ -6514,7 +6514,7 @@ pub const FuncGen = struct {
6514 }6514 }
65156515
6516 fn airNot(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6516 fn airNot(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6517 const ty_op = self.air.instructions.items(.data)[inst].ty_op;6517 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6518 const operand = try self.resolveInst(ty_op.operand);6518 const operand = try self.resolveInst(ty_op.operand);
65196519
6520 return self.wip.not(operand, "");6520 return self.wip.not(operand, "");
...@@ -6528,7 +6528,7 @@ pub const FuncGen = struct {...@@ -6528,7 +6528,7 @@ pub const FuncGen = struct {
65286528
6529 fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6529 fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6530 const di_scope = self.di_scope orelse return .none;6530 const di_scope = self.di_scope orelse return .none;
6531 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;6531 const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
6532 self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1);6532 self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1);
6533 self.prev_dbg_column = @intCast(dbg_stmt.column + 1);6533 self.prev_dbg_column = @intCast(dbg_stmt.column + 1);
6534 const inlined_at = if (self.dbg_inlined.items.len > 0)6534 const inlined_at = if (self.dbg_inlined.items.len > 0)
...@@ -6547,7 +6547,7 @@ pub const FuncGen = struct {...@@ -6547,7 +6547,7 @@ pub const FuncGen = struct {
6547 fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6547 fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6548 const o = self.dg.object;6548 const o = self.dg.object;
6549 const dib = o.di_builder orelse return .none;6549 const dib = o.di_builder orelse return .none;
6550 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;6550 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
65516551
6552 const mod = o.module;6552 const mod = o.module;
6553 const func = mod.funcInfo(ty_fn.func);6553 const func = mod.funcInfo(ty_fn.func);
...@@ -6596,7 +6596,7 @@ pub const FuncGen = struct {...@@ -6596,7 +6596,7 @@ pub const FuncGen = struct {
6596 fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6596 fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6597 const o = self.dg.object;6597 const o = self.dg.object;
6598 if (o.di_builder == null) return .none;6598 if (o.di_builder == null) return .none;
6599 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;6599 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
66006600
6601 const mod = o.module;6601 const mod = o.module;
6602 const decl = mod.funcOwnerDeclPtr(ty_fn.func);6602 const decl = mod.funcOwnerDeclPtr(ty_fn.func);
...@@ -6629,7 +6629,7 @@ pub const FuncGen = struct {...@@ -6629,7 +6629,7 @@ pub const FuncGen = struct {
6629 const o = self.dg.object;6629 const o = self.dg.object;
6630 const mod = o.module;6630 const mod = o.module;
6631 const dib = o.di_builder orelse return .none;6631 const dib = o.di_builder orelse return .none;
6632 const pl_op = self.air.instructions.items(.data)[inst].pl_op;6632 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6633 const operand = try self.resolveInst(pl_op.operand);6633 const operand = try self.resolveInst(pl_op.operand);
6634 const name = self.air.nullTerminatedString(pl_op.payload);6634 const name = self.air.nullTerminatedString(pl_op.payload);
6635 const ptr_ty = self.typeOf(pl_op.operand);6635 const ptr_ty = self.typeOf(pl_op.operand);
...@@ -6656,7 +6656,7 @@ pub const FuncGen = struct {...@@ -6656,7 +6656,7 @@ pub const FuncGen = struct {
6656 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6656 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6657 const o = self.dg.object;6657 const o = self.dg.object;
6658 const dib = o.di_builder orelse return .none;6658 const dib = o.di_builder orelse return .none;
6659 const pl_op = self.air.instructions.items(.data)[inst].pl_op;6659 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6660 const operand = try self.resolveInst(pl_op.operand);6660 const operand = try self.resolveInst(pl_op.operand);
6661 const operand_ty = self.typeOf(pl_op.operand);6661 const operand_ty = self.typeOf(pl_op.operand);
6662 const name = self.air.nullTerminatedString(pl_op.payload);6662 const name = self.air.nullTerminatedString(pl_op.payload);
...@@ -6700,7 +6700,7 @@ pub const FuncGen = struct {...@@ -6700,7 +6700,7 @@ pub const FuncGen = struct {
6700 // this implementation feeds the inline assembly code directly to LLVM.6700 // this implementation feeds the inline assembly code directly to LLVM.
67016701
6702 const o = self.dg.object;6702 const o = self.dg.object;
6703 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;6703 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6704 const extra = self.air.extraData(Air.Asm, ty_pl.payload);6704 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
6705 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;6705 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
6706 const clobbers_len: u31 = @truncate(extra.data.flags);6706 const clobbers_len: u31 = @truncate(extra.data.flags);
...@@ -7081,7 +7081,7 @@ pub const FuncGen = struct {...@@ -7081,7 +7081,7 @@ pub const FuncGen = struct {
7081 ) !Builder.Value {7081 ) !Builder.Value {
7082 const o = self.dg.object;7082 const o = self.dg.object;
7083 const mod = o.module;7083 const mod = o.module;
7084 const un_op = self.air.instructions.items(.data)[inst].un_op;7084 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
7085 const operand = try self.resolveInst(un_op);7085 const operand = try self.resolveInst(un_op);
7086 const operand_ty = self.typeOf(un_op);7086 const operand_ty = self.typeOf(un_op);
7087 const optional_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;7087 const optional_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
...@@ -7125,7 +7125,7 @@ pub const FuncGen = struct {...@@ -7125,7 +7125,7 @@ pub const FuncGen = struct {
7125 ) !Builder.Value {7125 ) !Builder.Value {
7126 const o = self.dg.object;7126 const o = self.dg.object;
7127 const mod = o.module;7127 const mod = o.module;
7128 const un_op = self.air.instructions.items(.data)[inst].un_op;7128 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
7129 const operand = try self.resolveInst(un_op);7129 const operand = try self.resolveInst(un_op);
7130 const operand_ty = self.typeOf(un_op);7130 const operand_ty = self.typeOf(un_op);
7131 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;7131 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
...@@ -7164,7 +7164,7 @@ pub const FuncGen = struct {...@@ -7164,7 +7164,7 @@ pub const FuncGen = struct {
7164 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7164 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7165 const o = self.dg.object;7165 const o = self.dg.object;
7166 const mod = o.module;7166 const mod = o.module;
7167 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7167 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7168 const operand = try self.resolveInst(ty_op.operand);7168 const operand = try self.resolveInst(ty_op.operand);
7169 const optional_ty = self.typeOf(ty_op.operand).childType(mod);7169 const optional_ty = self.typeOf(ty_op.operand).childType(mod);
7170 const payload_ty = optional_ty.optionalChild(mod);7170 const payload_ty = optional_ty.optionalChild(mod);
...@@ -7185,7 +7185,7 @@ pub const FuncGen = struct {...@@ -7185,7 +7185,7 @@ pub const FuncGen = struct {
71857185
7186 const o = self.dg.object;7186 const o = self.dg.object;
7187 const mod = o.module;7187 const mod = o.module;
7188 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7188 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7189 const operand = try self.resolveInst(ty_op.operand);7189 const operand = try self.resolveInst(ty_op.operand);
7190 const optional_ty = self.typeOf(ty_op.operand).childType(mod);7190 const optional_ty = self.typeOf(ty_op.operand).childType(mod);
7191 const payload_ty = optional_ty.optionalChild(mod);7191 const payload_ty = optional_ty.optionalChild(mod);
...@@ -7217,7 +7217,7 @@ pub const FuncGen = struct {...@@ -7217,7 +7217,7 @@ pub const FuncGen = struct {
7217 const o = self.dg.object;7217 const o = self.dg.object;
7218 const mod = o.module;7218 const mod = o.module;
7219 const inst = body_tail[0];7219 const inst = body_tail[0];
7220 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7220 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7221 const operand = try self.resolveInst(ty_op.operand);7221 const operand = try self.resolveInst(ty_op.operand);
7222 const optional_ty = self.typeOf(ty_op.operand);7222 const optional_ty = self.typeOf(ty_op.operand);
7223 const payload_ty = self.typeOfIndex(inst);7223 const payload_ty = self.typeOfIndex(inst);
...@@ -7241,7 +7241,7 @@ pub const FuncGen = struct {...@@ -7241,7 +7241,7 @@ pub const FuncGen = struct {
7241 const o = self.dg.object;7241 const o = self.dg.object;
7242 const mod = o.module;7242 const mod = o.module;
7243 const inst = body_tail[0];7243 const inst = body_tail[0];
7244 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7244 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7245 const operand = try self.resolveInst(ty_op.operand);7245 const operand = try self.resolveInst(ty_op.operand);
7246 const operand_ty = self.typeOf(ty_op.operand);7246 const operand_ty = self.typeOf(ty_op.operand);
7247 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;7247 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
...@@ -7275,7 +7275,7 @@ pub const FuncGen = struct {...@@ -7275,7 +7275,7 @@ pub const FuncGen = struct {
7275 ) !Builder.Value {7275 ) !Builder.Value {
7276 const o = self.dg.object;7276 const o = self.dg.object;
7277 const mod = o.module;7277 const mod = o.module;
7278 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7278 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7279 const operand = try self.resolveInst(ty_op.operand);7279 const operand = try self.resolveInst(ty_op.operand);
7280 const operand_ty = self.typeOf(ty_op.operand);7280 const operand_ty = self.typeOf(ty_op.operand);
7281 const error_type = try o.errorIntType();7281 const error_type = try o.errorIntType();
...@@ -7308,7 +7308,7 @@ pub const FuncGen = struct {...@@ -7308,7 +7308,7 @@ pub const FuncGen = struct {
7308 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7308 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7309 const o = self.dg.object;7309 const o = self.dg.object;
7310 const mod = o.module;7310 const mod = o.module;
7311 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7311 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7312 const operand = try self.resolveInst(ty_op.operand);7312 const operand = try self.resolveInst(ty_op.operand);
7313 const err_union_ty = self.typeOf(ty_op.operand).childType(mod);7313 const err_union_ty = self.typeOf(ty_op.operand).childType(mod);
73147314
...@@ -7340,15 +7340,15 @@ pub const FuncGen = struct {...@@ -7340,15 +7340,15 @@ pub const FuncGen = struct {
7340 }7340 }
73417341
7342 fn airSetErrReturnTrace(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7342 fn airSetErrReturnTrace(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7343 const un_op = self.air.instructions.items(.data)[inst].un_op;7343 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
7344 self.err_ret_trace = try self.resolveInst(un_op);7344 self.err_ret_trace = try self.resolveInst(un_op);
7345 return .none;7345 return .none;
7346 }7346 }
73477347
7348 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7348 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7349 const o = self.dg.object;7349 const o = self.dg.object;
7350 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;7350 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7351 const struct_ty = self.air.getRefType(ty_pl.ty);7351 const struct_ty = ty_pl.ty.toType();
7352 const field_index = ty_pl.payload;7352 const field_index = ty_pl.payload;
73537353
7354 const mod = o.module;7354 const mod = o.module;
...@@ -7378,7 +7378,7 @@ pub const FuncGen = struct {...@@ -7378,7 +7378,7 @@ pub const FuncGen = struct {
7378 ) bool {7378 ) bool {
7379 const air_tags = self.air.instructions.items(.tag);7379 const air_tags = self.air.instructions.items(.tag);
7380 for (body_tail[1..]) |body_inst| {7380 for (body_tail[1..]) |body_inst| {
7381 switch (air_tags[body_inst]) {7381 switch (air_tags[@intFromEnum(body_inst)]) {
7382 .ret => return true,7382 .ret => return true,
7383 .dbg_block_begin, .dbg_stmt => continue,7383 .dbg_block_begin, .dbg_stmt => continue,
7384 else => return false,7384 else => return false,
...@@ -7393,7 +7393,7 @@ pub const FuncGen = struct {...@@ -7393,7 +7393,7 @@ pub const FuncGen = struct {
7393 const o = self.dg.object;7393 const o = self.dg.object;
7394 const mod = o.module;7394 const mod = o.module;
7395 const inst = body_tail[0];7395 const inst = body_tail[0];
7396 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7396 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7397 const payload_ty = self.typeOf(ty_op.operand);7397 const payload_ty = self.typeOf(ty_op.operand);
7398 const non_null_bit = try o.builder.intValue(.i8, 1);7398 const non_null_bit = try o.builder.intValue(.i8, 1);
7399 comptime assert(optional_layout_version == 3);7399 comptime assert(optional_layout_version == 3);
...@@ -7426,7 +7426,7 @@ pub const FuncGen = struct {...@@ -7426,7 +7426,7 @@ pub const FuncGen = struct {
7426 const o = self.dg.object;7426 const o = self.dg.object;
7427 const mod = o.module;7427 const mod = o.module;
7428 const inst = body_tail[0];7428 const inst = body_tail[0];
7429 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7429 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7430 const err_un_ty = self.typeOfIndex(inst);7430 const err_un_ty = self.typeOfIndex(inst);
7431 const operand = try self.resolveInst(ty_op.operand);7431 const operand = try self.resolveInst(ty_op.operand);
7432 const payload_ty = self.typeOf(ty_op.operand);7432 const payload_ty = self.typeOf(ty_op.operand);
...@@ -7467,7 +7467,7 @@ pub const FuncGen = struct {...@@ -7467,7 +7467,7 @@ pub const FuncGen = struct {
7467 const o = self.dg.object;7467 const o = self.dg.object;
7468 const mod = o.module;7468 const mod = o.module;
7469 const inst = body_tail[0];7469 const inst = body_tail[0];
7470 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7470 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7471 const err_un_ty = self.typeOfIndex(inst);7471 const err_un_ty = self.typeOfIndex(inst);
7472 const payload_ty = err_un_ty.errorUnionPayload(mod);7472 const payload_ty = err_un_ty.errorUnionPayload(mod);
7473 const operand = try self.resolveInst(ty_op.operand);7473 const operand = try self.resolveInst(ty_op.operand);
...@@ -7505,7 +7505,7 @@ pub const FuncGen = struct {...@@ -7505,7 +7505,7 @@ pub const FuncGen = struct {
75057505
7506 fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7506 fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7507 const o = self.dg.object;7507 const o = self.dg.object;
7508 const pl_op = self.air.instructions.items(.data)[inst].pl_op;7508 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7509 const index = pl_op.payload;7509 const index = pl_op.payload;
7510 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{.i32}, &.{7510 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{.i32}, &.{
7511 try o.builder.intValue(.i32, index),7511 try o.builder.intValue(.i32, index),
...@@ -7514,7 +7514,7 @@ pub const FuncGen = struct {...@@ -7514,7 +7514,7 @@ pub const FuncGen = struct {
75147514
7515 fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7515 fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7516 const o = self.dg.object;7516 const o = self.dg.object;
7517 const pl_op = self.air.instructions.items(.data)[inst].pl_op;7517 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7518 const index = pl_op.payload;7518 const index = pl_op.payload;
7519 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{.i32}, &.{7519 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{.i32}, &.{
7520 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),7520 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
...@@ -7524,7 +7524,7 @@ pub const FuncGen = struct {...@@ -7524,7 +7524,7 @@ pub const FuncGen = struct {
7524 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7524 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7525 const o = self.dg.object;7525 const o = self.dg.object;
7526 const mod = o.module;7526 const mod = o.module;
7527 const data = self.air.instructions.items(.data)[inst].vector_store_elem;7527 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
7528 const extra = self.air.extraData(Air.Bin, data.payload).data;7528 const extra = self.air.extraData(Air.Bin, data.payload).data;
75297529
7530 const vector_ptr = try self.resolveInst(data.vector_ptr);7530 const vector_ptr = try self.resolveInst(data.vector_ptr);
...@@ -7546,7 +7546,7 @@ pub const FuncGen = struct {...@@ -7546,7 +7546,7 @@ pub const FuncGen = struct {
7546 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7546 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7547 const o = self.dg.object;7547 const o = self.dg.object;
7548 const mod = o.module;7548 const mod = o.module;
7549 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7549 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7550 const lhs = try self.resolveInst(bin_op.lhs);7550 const lhs = try self.resolveInst(bin_op.lhs);
7551 const rhs = try self.resolveInst(bin_op.rhs);7551 const rhs = try self.resolveInst(bin_op.rhs);
7552 const inst_ty = self.typeOfIndex(inst);7552 const inst_ty = self.typeOfIndex(inst);
...@@ -7566,7 +7566,7 @@ pub const FuncGen = struct {...@@ -7566,7 +7566,7 @@ pub const FuncGen = struct {
7566 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7566 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7567 const o = self.dg.object;7567 const o = self.dg.object;
7568 const mod = o.module;7568 const mod = o.module;
7569 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7569 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7570 const lhs = try self.resolveInst(bin_op.lhs);7570 const lhs = try self.resolveInst(bin_op.lhs);
7571 const rhs = try self.resolveInst(bin_op.rhs);7571 const rhs = try self.resolveInst(bin_op.rhs);
7572 const inst_ty = self.typeOfIndex(inst);7572 const inst_ty = self.typeOfIndex(inst);
...@@ -7585,7 +7585,7 @@ pub const FuncGen = struct {...@@ -7585,7 +7585,7 @@ pub const FuncGen = struct {
75857585
7586 fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7586 fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7587 const o = self.dg.object;7587 const o = self.dg.object;
7588 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;7588 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7589 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;7589 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
7590 const ptr = try self.resolveInst(bin_op.lhs);7590 const ptr = try self.resolveInst(bin_op.lhs);
7591 const len = try self.resolveInst(bin_op.rhs);7591 const len = try self.resolveInst(bin_op.rhs);
...@@ -7596,7 +7596,7 @@ pub const FuncGen = struct {...@@ -7596,7 +7596,7 @@ pub const FuncGen = struct {
7596 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7596 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7597 const o = self.dg.object;7597 const o = self.dg.object;
7598 const mod = o.module;7598 const mod = o.module;
7599 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7599 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7600 const lhs = try self.resolveInst(bin_op.lhs);7600 const lhs = try self.resolveInst(bin_op.lhs);
7601 const rhs = try self.resolveInst(bin_op.rhs);7601 const rhs = try self.resolveInst(bin_op.rhs);
7602 const inst_ty = self.typeOfIndex(inst);7602 const inst_ty = self.typeOfIndex(inst);
...@@ -7615,7 +7615,7 @@ pub const FuncGen = struct {...@@ -7615,7 +7615,7 @@ pub const FuncGen = struct {
7615 const o = fg.dg.object;7615 const o = fg.dg.object;
7616 const mod = o.module;7616 const mod = o.module;
76177617
7618 const bin_op = fg.air.instructions.items(.data)[inst].bin_op;7618 const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7619 const lhs = try fg.resolveInst(bin_op.lhs);7619 const lhs = try fg.resolveInst(bin_op.lhs);
7620 const rhs = try fg.resolveInst(bin_op.rhs);7620 const rhs = try fg.resolveInst(bin_op.rhs);
7621 const inst_ty = fg.typeOfIndex(inst);7621 const inst_ty = fg.typeOfIndex(inst);
...@@ -7652,7 +7652,7 @@ pub const FuncGen = struct {...@@ -7652,7 +7652,7 @@ pub const FuncGen = struct {
7652 }7652 }
76537653
7654 fn airAddWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7654 fn airAddWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7655 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7655 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7656 const lhs = try self.resolveInst(bin_op.lhs);7656 const lhs = try self.resolveInst(bin_op.lhs);
7657 const rhs = try self.resolveInst(bin_op.rhs);7657 const rhs = try self.resolveInst(bin_op.rhs);
76587658
...@@ -7662,7 +7662,7 @@ pub const FuncGen = struct {...@@ -7662,7 +7662,7 @@ pub const FuncGen = struct {
7662 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7662 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7663 const o = self.dg.object;7663 const o = self.dg.object;
7664 const mod = o.module;7664 const mod = o.module;
7665 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7665 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7666 const lhs = try self.resolveInst(bin_op.lhs);7666 const lhs = try self.resolveInst(bin_op.lhs);
7667 const rhs = try self.resolveInst(bin_op.rhs);7667 const rhs = try self.resolveInst(bin_op.rhs);
7668 const inst_ty = self.typeOfIndex(inst);7668 const inst_ty = self.typeOfIndex(inst);
...@@ -7682,7 +7682,7 @@ pub const FuncGen = struct {...@@ -7682,7 +7682,7 @@ pub const FuncGen = struct {
7682 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7682 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7683 const o = self.dg.object;7683 const o = self.dg.object;
7684 const mod = o.module;7684 const mod = o.module;
7685 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7685 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7686 const lhs = try self.resolveInst(bin_op.lhs);7686 const lhs = try self.resolveInst(bin_op.lhs);
7687 const rhs = try self.resolveInst(bin_op.rhs);7687 const rhs = try self.resolveInst(bin_op.rhs);
7688 const inst_ty = self.typeOfIndex(inst);7688 const inst_ty = self.typeOfIndex(inst);
...@@ -7693,7 +7693,7 @@ pub const FuncGen = struct {...@@ -7693,7 +7693,7 @@ pub const FuncGen = struct {
7693 }7693 }
76947694
7695 fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7695 fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7696 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7696 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7697 const lhs = try self.resolveInst(bin_op.lhs);7697 const lhs = try self.resolveInst(bin_op.lhs);
7698 const rhs = try self.resolveInst(bin_op.rhs);7698 const rhs = try self.resolveInst(bin_op.rhs);
76997699
...@@ -7703,7 +7703,7 @@ pub const FuncGen = struct {...@@ -7703,7 +7703,7 @@ pub const FuncGen = struct {
7703 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7703 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7704 const o = self.dg.object;7704 const o = self.dg.object;
7705 const mod = o.module;7705 const mod = o.module;
7706 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7706 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7707 const lhs = try self.resolveInst(bin_op.lhs);7707 const lhs = try self.resolveInst(bin_op.lhs);
7708 const rhs = try self.resolveInst(bin_op.rhs);7708 const rhs = try self.resolveInst(bin_op.rhs);
7709 const inst_ty = self.typeOfIndex(inst);7709 const inst_ty = self.typeOfIndex(inst);
...@@ -7723,7 +7723,7 @@ pub const FuncGen = struct {...@@ -7723,7 +7723,7 @@ pub const FuncGen = struct {
7723 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7723 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7724 const o = self.dg.object;7724 const o = self.dg.object;
7725 const mod = o.module;7725 const mod = o.module;
7726 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7726 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7727 const lhs = try self.resolveInst(bin_op.lhs);7727 const lhs = try self.resolveInst(bin_op.lhs);
7728 const rhs = try self.resolveInst(bin_op.rhs);7728 const rhs = try self.resolveInst(bin_op.rhs);
7729 const inst_ty = self.typeOfIndex(inst);7729 const inst_ty = self.typeOfIndex(inst);
...@@ -7734,7 +7734,7 @@ pub const FuncGen = struct {...@@ -7734,7 +7734,7 @@ pub const FuncGen = struct {
7734 }7734 }
77357735
7736 fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7736 fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7737 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7737 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7738 const lhs = try self.resolveInst(bin_op.lhs);7738 const lhs = try self.resolveInst(bin_op.lhs);
7739 const rhs = try self.resolveInst(bin_op.rhs);7739 const rhs = try self.resolveInst(bin_op.rhs);
77407740
...@@ -7744,7 +7744,7 @@ pub const FuncGen = struct {...@@ -7744,7 +7744,7 @@ pub const FuncGen = struct {
7744 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7744 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7745 const o = self.dg.object;7745 const o = self.dg.object;
7746 const mod = o.module;7746 const mod = o.module;
7747 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7747 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7748 const lhs = try self.resolveInst(bin_op.lhs);7748 const lhs = try self.resolveInst(bin_op.lhs);
7749 const rhs = try self.resolveInst(bin_op.rhs);7749 const rhs = try self.resolveInst(bin_op.rhs);
7750 const inst_ty = self.typeOfIndex(inst);7750 const inst_ty = self.typeOfIndex(inst);
...@@ -7762,7 +7762,7 @@ pub const FuncGen = struct {...@@ -7762,7 +7762,7 @@ pub const FuncGen = struct {
7762 }7762 }
77637763
7764 fn airDivFloat(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7764 fn airDivFloat(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7765 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7765 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7766 const lhs = try self.resolveInst(bin_op.lhs);7766 const lhs = try self.resolveInst(bin_op.lhs);
7767 const rhs = try self.resolveInst(bin_op.rhs);7767 const rhs = try self.resolveInst(bin_op.rhs);
7768 const inst_ty = self.typeOfIndex(inst);7768 const inst_ty = self.typeOfIndex(inst);
...@@ -7773,7 +7773,7 @@ pub const FuncGen = struct {...@@ -7773,7 +7773,7 @@ pub const FuncGen = struct {
7773 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7773 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7774 const o = self.dg.object;7774 const o = self.dg.object;
7775 const mod = o.module;7775 const mod = o.module;
7776 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7776 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7777 const lhs = try self.resolveInst(bin_op.lhs);7777 const lhs = try self.resolveInst(bin_op.lhs);
7778 const rhs = try self.resolveInst(bin_op.rhs);7778 const rhs = try self.resolveInst(bin_op.rhs);
7779 const inst_ty = self.typeOfIndex(inst);7779 const inst_ty = self.typeOfIndex(inst);
...@@ -7789,7 +7789,7 @@ pub const FuncGen = struct {...@@ -7789,7 +7789,7 @@ pub const FuncGen = struct {
7789 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7789 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7790 const o = self.dg.object;7790 const o = self.dg.object;
7791 const mod = o.module;7791 const mod = o.module;
7792 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7792 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7793 const lhs = try self.resolveInst(bin_op.lhs);7793 const lhs = try self.resolveInst(bin_op.lhs);
7794 const rhs = try self.resolveInst(bin_op.rhs);7794 const rhs = try self.resolveInst(bin_op.rhs);
7795 const inst_ty = self.typeOfIndex(inst);7795 const inst_ty = self.typeOfIndex(inst);
...@@ -7821,7 +7821,7 @@ pub const FuncGen = struct {...@@ -7821,7 +7821,7 @@ pub const FuncGen = struct {
7821 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7821 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7822 const o = self.dg.object;7822 const o = self.dg.object;
7823 const mod = o.module;7823 const mod = o.module;
7824 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7824 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7825 const lhs = try self.resolveInst(bin_op.lhs);7825 const lhs = try self.resolveInst(bin_op.lhs);
7826 const rhs = try self.resolveInst(bin_op.rhs);7826 const rhs = try self.resolveInst(bin_op.rhs);
7827 const inst_ty = self.typeOfIndex(inst);7827 const inst_ty = self.typeOfIndex(inst);
...@@ -7839,7 +7839,7 @@ pub const FuncGen = struct {...@@ -7839,7 +7839,7 @@ pub const FuncGen = struct {
7839 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7839 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7840 const o = self.dg.object;7840 const o = self.dg.object;
7841 const mod = o.module;7841 const mod = o.module;
7842 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7842 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7843 const lhs = try self.resolveInst(bin_op.lhs);7843 const lhs = try self.resolveInst(bin_op.lhs);
7844 const rhs = try self.resolveInst(bin_op.rhs);7844 const rhs = try self.resolveInst(bin_op.rhs);
7845 const inst_ty = self.typeOfIndex(inst);7845 const inst_ty = self.typeOfIndex(inst);
...@@ -7856,7 +7856,7 @@ pub const FuncGen = struct {...@@ -7856,7 +7856,7 @@ pub const FuncGen = struct {
7856 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7856 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7857 const o = self.dg.object;7857 const o = self.dg.object;
7858 const mod = o.module;7858 const mod = o.module;
7859 const bin_op = self.air.instructions.items(.data)[inst].bin_op;7859 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7860 const lhs = try self.resolveInst(bin_op.lhs);7860 const lhs = try self.resolveInst(bin_op.lhs);
7861 const rhs = try self.resolveInst(bin_op.rhs);7861 const rhs = try self.resolveInst(bin_op.rhs);
7862 const inst_ty = self.typeOfIndex(inst);7862 const inst_ty = self.typeOfIndex(inst);
...@@ -7892,7 +7892,7 @@ pub const FuncGen = struct {...@@ -7892,7 +7892,7 @@ pub const FuncGen = struct {
7892 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7892 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7893 const o = self.dg.object;7893 const o = self.dg.object;
7894 const mod = o.module;7894 const mod = o.module;
7895 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;7895 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7896 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;7896 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
7897 const ptr = try self.resolveInst(bin_op.lhs);7897 const ptr = try self.resolveInst(bin_op.lhs);
7898 const offset = try self.resolveInst(bin_op.rhs);7898 const offset = try self.resolveInst(bin_op.rhs);
...@@ -7914,7 +7914,7 @@ pub const FuncGen = struct {...@@ -7914,7 +7914,7 @@ pub const FuncGen = struct {
7914 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7914 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7915 const o = self.dg.object;7915 const o = self.dg.object;
7916 const mod = o.module;7916 const mod = o.module;
7917 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;7917 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7918 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;7918 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
7919 const ptr = try self.resolveInst(bin_op.lhs);7919 const ptr = try self.resolveInst(bin_op.lhs);
7920 const offset = try self.resolveInst(bin_op.rhs);7920 const offset = try self.resolveInst(bin_op.rhs);
...@@ -7942,7 +7942,7 @@ pub const FuncGen = struct {...@@ -7942,7 +7942,7 @@ pub const FuncGen = struct {
7942 ) !Builder.Value {7942 ) !Builder.Value {
7943 const o = self.dg.object;7943 const o = self.dg.object;
7944 const mod = o.module;7944 const mod = o.module;
7945 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;7945 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7946 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;7946 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
79477947
7948 const lhs = try self.resolveInst(extra.lhs);7948 const lhs = try self.resolveInst(extra.lhs);
...@@ -8283,7 +8283,7 @@ pub const FuncGen = struct {...@@ -8283,7 +8283,7 @@ pub const FuncGen = struct {
8283 }8283 }
82848284
8285 fn airMulAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8285 fn airMulAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8286 const pl_op = self.air.instructions.items(.data)[inst].pl_op;8286 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
8287 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;8287 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
82888288
8289 const mulend1 = try self.resolveInst(extra.lhs);8289 const mulend1 = try self.resolveInst(extra.lhs);
...@@ -8297,7 +8297,7 @@ pub const FuncGen = struct {...@@ -8297,7 +8297,7 @@ pub const FuncGen = struct {
8297 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8297 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8298 const o = self.dg.object;8298 const o = self.dg.object;
8299 const mod = o.module;8299 const mod = o.module;
8300 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;8300 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8301 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;8301 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
83028302
8303 const lhs = try self.resolveInst(extra.lhs);8303 const lhs = try self.resolveInst(extra.lhs);
...@@ -8344,21 +8344,21 @@ pub const FuncGen = struct {...@@ -8344,21 +8344,21 @@ pub const FuncGen = struct {
8344 }8344 }
83458345
8346 fn airAnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8346 fn airAnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8347 const bin_op = self.air.instructions.items(.data)[inst].bin_op;8347 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8348 const lhs = try self.resolveInst(bin_op.lhs);8348 const lhs = try self.resolveInst(bin_op.lhs);
8349 const rhs = try self.resolveInst(bin_op.rhs);8349 const rhs = try self.resolveInst(bin_op.rhs);
8350 return self.wip.bin(.@"and", lhs, rhs, "");8350 return self.wip.bin(.@"and", lhs, rhs, "");
8351 }8351 }
83528352
8353 fn airOr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8353 fn airOr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8354 const bin_op = self.air.instructions.items(.data)[inst].bin_op;8354 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8355 const lhs = try self.resolveInst(bin_op.lhs);8355 const lhs = try self.resolveInst(bin_op.lhs);
8356 const rhs = try self.resolveInst(bin_op.rhs);8356 const rhs = try self.resolveInst(bin_op.rhs);
8357 return self.wip.bin(.@"or", lhs, rhs, "");8357 return self.wip.bin(.@"or", lhs, rhs, "");
8358 }8358 }
83598359
8360 fn airXor(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8360 fn airXor(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8361 const bin_op = self.air.instructions.items(.data)[inst].bin_op;8361 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8362 const lhs = try self.resolveInst(bin_op.lhs);8362 const lhs = try self.resolveInst(bin_op.lhs);
8363 const rhs = try self.resolveInst(bin_op.rhs);8363 const rhs = try self.resolveInst(bin_op.rhs);
8364 return self.wip.bin(.xor, lhs, rhs, "");8364 return self.wip.bin(.xor, lhs, rhs, "");
...@@ -8367,7 +8367,7 @@ pub const FuncGen = struct {...@@ -8367,7 +8367,7 @@ pub const FuncGen = struct {
8367 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8367 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8368 const o = self.dg.object;8368 const o = self.dg.object;
8369 const mod = o.module;8369 const mod = o.module;
8370 const bin_op = self.air.instructions.items(.data)[inst].bin_op;8370 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83718371
8372 const lhs = try self.resolveInst(bin_op.lhs);8372 const lhs = try self.resolveInst(bin_op.lhs);
8373 const rhs = try self.resolveInst(bin_op.rhs);8373 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8384,7 +8384,7 @@ pub const FuncGen = struct {...@@ -8384,7 +8384,7 @@ pub const FuncGen = struct {
83848384
8385 fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8385 fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8386 const o = self.dg.object;8386 const o = self.dg.object;
8387 const bin_op = self.air.instructions.items(.data)[inst].bin_op;8387 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83888388
8389 const lhs = try self.resolveInst(bin_op.lhs);8389 const lhs = try self.resolveInst(bin_op.lhs);
8390 const rhs = try self.resolveInst(bin_op.rhs);8390 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8398,7 +8398,7 @@ pub const FuncGen = struct {...@@ -8398,7 +8398,7 @@ pub const FuncGen = struct {
8398 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8398 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8399 const o = self.dg.object;8399 const o = self.dg.object;
8400 const mod = o.module;8400 const mod = o.module;
8401 const bin_op = self.air.instructions.items(.data)[inst].bin_op;8401 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84028402
8403 const lhs = try self.resolveInst(bin_op.lhs);8403 const lhs = try self.resolveInst(bin_op.lhs);
8404 const rhs = try self.resolveInst(bin_op.rhs);8404 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8440,7 +8440,7 @@ pub const FuncGen = struct {...@@ -8440,7 +8440,7 @@ pub const FuncGen = struct {
8440 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {8440 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {
8441 const o = self.dg.object;8441 const o = self.dg.object;
8442 const mod = o.module;8442 const mod = o.module;
8443 const bin_op = self.air.instructions.items(.data)[inst].bin_op;8443 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84448444
8445 const lhs = try self.resolveInst(bin_op.lhs);8445 const lhs = try self.resolveInst(bin_op.lhs);
8446 const rhs = try self.resolveInst(bin_op.rhs);8446 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8459,7 +8459,7 @@ pub const FuncGen = struct {...@@ -8459,7 +8459,7 @@ pub const FuncGen = struct {
8459 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8459 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8460 const o = self.dg.object;8460 const o = self.dg.object;
8461 const mod = o.module;8461 const mod = o.module;
8462 const ty_op = self.air.instructions.items(.data)[inst].ty_op;8462 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8463 const operand = try self.resolveInst(ty_op.operand);8463 const operand = try self.resolveInst(ty_op.operand);
8464 const operand_ty = self.typeOf(ty_op.operand);8464 const operand_ty = self.typeOf(ty_op.operand);
8465 const scalar_ty = operand_ty.scalarType(mod);8465 const scalar_ty = operand_ty.scalarType(mod);
...@@ -8481,7 +8481,7 @@ pub const FuncGen = struct {...@@ -8481,7 +8481,7 @@ pub const FuncGen = struct {
8481 fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8481 fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8482 const o = self.dg.object;8482 const o = self.dg.object;
8483 const mod = o.module;8483 const mod = o.module;
8484 const ty_op = self.air.instructions.items(.data)[inst].ty_op;8484 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8485 const dest_ty = self.typeOfIndex(inst);8485 const dest_ty = self.typeOfIndex(inst);
8486 const dest_llvm_ty = try o.lowerType(dest_ty);8486 const dest_llvm_ty = try o.lowerType(dest_ty);
8487 const operand = try self.resolveInst(ty_op.operand);8487 const operand = try self.resolveInst(ty_op.operand);
...@@ -8496,7 +8496,7 @@ pub const FuncGen = struct {...@@ -8496,7 +8496,7 @@ pub const FuncGen = struct {
84968496
8497 fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8497 fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8498 const o = self.dg.object;8498 const o = self.dg.object;
8499 const ty_op = self.air.instructions.items(.data)[inst].ty_op;8499 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8500 const operand = try self.resolveInst(ty_op.operand);8500 const operand = try self.resolveInst(ty_op.operand);
8501 const dest_llvm_ty = try o.lowerType(self.typeOfIndex(inst));8501 const dest_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
8502 return self.wip.cast(.trunc, operand, dest_llvm_ty, "");8502 return self.wip.cast(.trunc, operand, dest_llvm_ty, "");
...@@ -8505,7 +8505,7 @@ pub const FuncGen = struct {...@@ -8505,7 +8505,7 @@ pub const FuncGen = struct {
8505 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8505 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8506 const o = self.dg.object;8506 const o = self.dg.object;
8507 const mod = o.module;8507 const mod = o.module;
8508 const ty_op = self.air.instructions.items(.data)[inst].ty_op;8508 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8509 const operand = try self.resolveInst(ty_op.operand);8509 const operand = try self.resolveInst(ty_op.operand);
8510 const operand_ty = self.typeOf(ty_op.operand);8510 const operand_ty = self.typeOf(ty_op.operand);
8511 const dest_ty = self.typeOfIndex(inst);8511 const dest_ty = self.typeOfIndex(inst);
...@@ -8539,7 +8539,7 @@ pub const FuncGen = struct {...@@ -8539,7 +8539,7 @@ pub const FuncGen = struct {
8539 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8539 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8540 const o = self.dg.object;8540 const o = self.dg.object;
8541 const mod = o.module;8541 const mod = o.module;
8542 const ty_op = self.air.instructions.items(.data)[inst].ty_op;8542 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8543 const operand = try self.resolveInst(ty_op.operand);8543 const operand = try self.resolveInst(ty_op.operand);
8544 const operand_ty = self.typeOf(ty_op.operand);8544 const operand_ty = self.typeOf(ty_op.operand);
8545 const dest_ty = self.typeOfIndex(inst);8545 const dest_ty = self.typeOfIndex(inst);
...@@ -8572,7 +8572,7 @@ pub const FuncGen = struct {...@@ -8572,7 +8572,7 @@ pub const FuncGen = struct {
85728572
8573 fn airIntFromPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8573 fn airIntFromPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8574 const o = self.dg.object;8574 const o = self.dg.object;
8575 const un_op = self.air.instructions.items(.data)[inst].un_op;8575 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
8576 const operand = try self.resolveInst(un_op);8576 const operand = try self.resolveInst(un_op);
8577 const ptr_ty = self.typeOf(un_op);8577 const ptr_ty = self.typeOf(un_op);
8578 const operand_ptr = try self.sliceOrArrayPtr(operand, ptr_ty);8578 const operand_ptr = try self.sliceOrArrayPtr(operand, ptr_ty);
...@@ -8581,7 +8581,7 @@ pub const FuncGen = struct {...@@ -8581,7 +8581,7 @@ pub const FuncGen = struct {
8581 }8581 }
85828582
8583 fn airBitCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8583 fn airBitCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8584 const ty_op = self.air.instructions.items(.data)[inst].ty_op;8584 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8585 const operand_ty = self.typeOf(ty_op.operand);8585 const operand_ty = self.typeOf(ty_op.operand);
8586 const inst_ty = self.typeOfIndex(inst);8586 const inst_ty = self.typeOfIndex(inst);
8587 const operand = try self.resolveInst(ty_op.operand);8587 const operand = try self.resolveInst(ty_op.operand);
...@@ -8698,7 +8698,7 @@ pub const FuncGen = struct {...@@ -8698,7 +8698,7 @@ pub const FuncGen = struct {
8698 }8698 }
86998699
8700 fn airIntFromBool(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8700 fn airIntFromBool(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8701 const un_op = self.air.instructions.items(.data)[inst].un_op;8701 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
8702 const operand = try self.resolveInst(un_op);8702 const operand = try self.resolveInst(un_op);
8703 return operand;8703 return operand;
8704 }8704 }
...@@ -8713,7 +8713,7 @@ pub const FuncGen = struct {...@@ -8713,7 +8713,7 @@ pub const FuncGen = struct {
8713 if (o.di_builder) |dib| {8713 if (o.di_builder) |dib| {
8714 if (needDbgVarWorkaround(o)) return arg_val;8714 if (needDbgVarWorkaround(o)) return arg_val;
87158715
8716 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;8716 const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;
8717 const func_index = self.dg.decl.getOwnedFunctionIndex();8717 const func_index = self.dg.decl.getOwnedFunctionIndex();
8718 const func = mod.funcInfo(func_index);8718 const func = mod.funcInfo(func_index);
8719 const lbrace_line = mod.declPtr(func.owner_decl).src_line + func.lbrace_line + 1;8719 const lbrace_line = mod.declPtr(func.owner_decl).src_line + func.lbrace_line + 1;
...@@ -8796,7 +8796,7 @@ pub const FuncGen = struct {...@@ -8796,7 +8796,7 @@ pub const FuncGen = struct {
8796 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {8796 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
8797 const o = self.dg.object;8797 const o = self.dg.object;
8798 const mod = o.module;8798 const mod = o.module;
8799 const bin_op = self.air.instructions.items(.data)[inst].bin_op;8799 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8800 const dest_ptr = try self.resolveInst(bin_op.lhs);8800 const dest_ptr = try self.resolveInst(bin_op.lhs);
8801 const ptr_ty = self.typeOf(bin_op.lhs);8801 const ptr_ty = self.typeOf(bin_op.lhs);
8802 const operand_ty = ptr_ty.childType(mod);8802 const operand_ty = ptr_ty.childType(mod);
...@@ -8860,7 +8860,7 @@ pub const FuncGen = struct {...@@ -8860,7 +8860,7 @@ pub const FuncGen = struct {
8860 const o = fg.dg.object;8860 const o = fg.dg.object;
8861 const mod = o.module;8861 const mod = o.module;
8862 const inst = body_tail[0];8862 const inst = body_tail[0];
8863 const ty_op = fg.air.instructions.items(.data)[inst].ty_op;8863 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8864 const ptr_ty = fg.typeOf(ty_op.operand);8864 const ptr_ty = fg.typeOf(ty_op.operand);
8865 const ptr_info = ptr_ty.ptrInfo(mod);8865 const ptr_info = ptr_ty.ptrInfo(mod);
8866 const ptr = try fg.resolveInst(ty_op.operand);8866 const ptr = try fg.resolveInst(ty_op.operand);
...@@ -8910,7 +8910,7 @@ pub const FuncGen = struct {...@@ -8910,7 +8910,7 @@ pub const FuncGen = struct {
8910 }8910 }
89118911
8912 fn airFence(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8912 fn airFence(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8913 const atomic_order = self.air.instructions.items(.data)[inst].fence;8913 const atomic_order = self.air.instructions.items(.data)[@intFromEnum(inst)].fence;
8914 const ordering = toLlvmAtomicOrdering(atomic_order);8914 const ordering = toLlvmAtomicOrdering(atomic_order);
8915 _ = try self.wip.fence(self.sync_scope, ordering);8915 _ = try self.wip.fence(self.sync_scope, ordering);
8916 return .none;8916 return .none;
...@@ -8923,7 +8923,7 @@ pub const FuncGen = struct {...@@ -8923,7 +8923,7 @@ pub const FuncGen = struct {
8923 ) !Builder.Value {8923 ) !Builder.Value {
8924 const o = self.dg.object;8924 const o = self.dg.object;
8925 const mod = o.module;8925 const mod = o.module;
8926 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;8926 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8927 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;8927 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
8928 const ptr = try self.resolveInst(extra.ptr);8928 const ptr = try self.resolveInst(extra.ptr);
8929 const ptr_ty = self.typeOf(extra.ptr);8929 const ptr_ty = self.typeOf(extra.ptr);
...@@ -8973,7 +8973,7 @@ pub const FuncGen = struct {...@@ -8973,7 +8973,7 @@ pub const FuncGen = struct {
8973 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8973 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8974 const o = self.dg.object;8974 const o = self.dg.object;
8975 const mod = o.module;8975 const mod = o.module;
8976 const pl_op = self.air.instructions.items(.data)[inst].pl_op;8976 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
8977 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;8977 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
8978 const ptr = try self.resolveInst(pl_op.operand);8978 const ptr = try self.resolveInst(pl_op.operand);
8979 const ptr_ty = self.typeOf(pl_op.operand);8979 const ptr_ty = self.typeOf(pl_op.operand);
...@@ -9036,7 +9036,7 @@ pub const FuncGen = struct {...@@ -9036,7 +9036,7 @@ pub const FuncGen = struct {
9036 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9036 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9037 const o = self.dg.object;9037 const o = self.dg.object;
9038 const mod = o.module;9038 const mod = o.module;
9039 const atomic_load = self.air.instructions.items(.data)[inst].atomic_load;9039 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
9040 const ptr = try self.resolveInst(atomic_load.ptr);9040 const ptr = try self.resolveInst(atomic_load.ptr);
9041 const ptr_ty = self.typeOf(atomic_load.ptr);9041 const ptr_ty = self.typeOf(atomic_load.ptr);
9042 const info = ptr_ty.ptrInfo(mod);9042 const info = ptr_ty.ptrInfo(mod);
...@@ -9083,7 +9083,7 @@ pub const FuncGen = struct {...@@ -9083,7 +9083,7 @@ pub const FuncGen = struct {
9083 ) !Builder.Value {9083 ) !Builder.Value {
9084 const o = self.dg.object;9084 const o = self.dg.object;
9085 const mod = o.module;9085 const mod = o.module;
9086 const bin_op = self.air.instructions.items(.data)[inst].bin_op;9086 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9087 const ptr_ty = self.typeOf(bin_op.lhs);9087 const ptr_ty = self.typeOf(bin_op.lhs);
9088 const operand_ty = ptr_ty.childType(mod);9088 const operand_ty = ptr_ty.childType(mod);
9089 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return .none;9089 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return .none;
...@@ -9107,7 +9107,7 @@ pub const FuncGen = struct {...@@ -9107,7 +9107,7 @@ pub const FuncGen = struct {
9107 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {9107 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
9108 const o = self.dg.object;9108 const o = self.dg.object;
9109 const mod = o.module;9109 const mod = o.module;
9110 const bin_op = self.air.instructions.items(.data)[inst].bin_op;9110 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9111 const dest_slice = try self.resolveInst(bin_op.lhs);9111 const dest_slice = try self.resolveInst(bin_op.lhs);
9112 const ptr_ty = self.typeOf(bin_op.lhs);9112 const ptr_ty = self.typeOf(bin_op.lhs);
9113 const elem_ty = self.typeOf(bin_op.rhs);9113 const elem_ty = self.typeOf(bin_op.rhs);
...@@ -9259,7 +9259,7 @@ pub const FuncGen = struct {...@@ -9259,7 +9259,7 @@ pub const FuncGen = struct {
9259 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9259 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9260 const o = self.dg.object;9260 const o = self.dg.object;
9261 const mod = o.module;9261 const mod = o.module;
9262 const bin_op = self.air.instructions.items(.data)[inst].bin_op;9262 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9263 const dest_slice = try self.resolveInst(bin_op.lhs);9263 const dest_slice = try self.resolveInst(bin_op.lhs);
9264 const dest_ptr_ty = self.typeOf(bin_op.lhs);9264 const dest_ptr_ty = self.typeOf(bin_op.lhs);
9265 const src_slice = try self.resolveInst(bin_op.rhs);9265 const src_slice = try self.resolveInst(bin_op.rhs);
...@@ -9312,7 +9312,7 @@ pub const FuncGen = struct {...@@ -9312,7 +9312,7 @@ pub const FuncGen = struct {
9312 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9312 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9313 const o = self.dg.object;9313 const o = self.dg.object;
9314 const mod = o.module;9314 const mod = o.module;
9315 const bin_op = self.air.instructions.items(.data)[inst].bin_op;9315 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9316 const un_ty = self.typeOf(bin_op.lhs).childType(mod);9316 const un_ty = self.typeOf(bin_op.lhs).childType(mod);
9317 const layout = un_ty.unionGetLayout(mod);9317 const layout = un_ty.unionGetLayout(mod);
9318 if (layout.tag_size == 0) return .none;9318 if (layout.tag_size == 0) return .none;
...@@ -9333,7 +9333,7 @@ pub const FuncGen = struct {...@@ -9333,7 +9333,7 @@ pub const FuncGen = struct {
9333 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9333 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9334 const o = self.dg.object;9334 const o = self.dg.object;
9335 const mod = o.module;9335 const mod = o.module;
9336 const ty_op = self.air.instructions.items(.data)[inst].ty_op;9336 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9337 const un_ty = self.typeOf(ty_op.operand);9337 const un_ty = self.typeOf(ty_op.operand);
9338 const layout = un_ty.unionGetLayout(mod);9338 const layout = un_ty.unionGetLayout(mod);
9339 if (layout.tag_size == 0) return .none;9339 if (layout.tag_size == 0) return .none;
...@@ -9354,7 +9354,7 @@ pub const FuncGen = struct {...@@ -9354,7 +9354,7 @@ pub const FuncGen = struct {
9354 }9354 }
93559355
9356 fn airUnaryOp(self: *FuncGen, inst: Air.Inst.Index, comptime op: FloatOp) !Builder.Value {9356 fn airUnaryOp(self: *FuncGen, inst: Air.Inst.Index, comptime op: FloatOp) !Builder.Value {
9357 const un_op = self.air.instructions.items(.data)[inst].un_op;9357 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
9358 const operand = try self.resolveInst(un_op);9358 const operand = try self.resolveInst(un_op);
9359 const operand_ty = self.typeOf(un_op);9359 const operand_ty = self.typeOf(un_op);
93609360
...@@ -9362,7 +9362,7 @@ pub const FuncGen = struct {...@@ -9362,7 +9362,7 @@ pub const FuncGen = struct {
9362 }9362 }
93639363
9364 fn airNeg(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {9364 fn airNeg(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
9365 const un_op = self.air.instructions.items(.data)[inst].un_op;9365 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
9366 const operand = try self.resolveInst(un_op);9366 const operand = try self.resolveInst(un_op);
9367 const operand_ty = self.typeOf(un_op);9367 const operand_ty = self.typeOf(un_op);
93689368
...@@ -9371,7 +9371,7 @@ pub const FuncGen = struct {...@@ -9371,7 +9371,7 @@ pub const FuncGen = struct {
93719371
9372 fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {9372 fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
9373 const o = self.dg.object;9373 const o = self.dg.object;
9374 const ty_op = self.air.instructions.items(.data)[inst].ty_op;9374 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9375 const inst_ty = self.typeOfIndex(inst);9375 const inst_ty = self.typeOfIndex(inst);
9376 const operand_ty = self.typeOf(ty_op.operand);9376 const operand_ty = self.typeOf(ty_op.operand);
9377 const operand = try self.resolveInst(ty_op.operand);9377 const operand = try self.resolveInst(ty_op.operand);
...@@ -9389,7 +9389,7 @@ pub const FuncGen = struct {...@@ -9389,7 +9389,7 @@ pub const FuncGen = struct {
93899389
9390 fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {9390 fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
9391 const o = self.dg.object;9391 const o = self.dg.object;
9392 const ty_op = self.air.instructions.items(.data)[inst].ty_op;9392 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9393 const inst_ty = self.typeOfIndex(inst);9393 const inst_ty = self.typeOfIndex(inst);
9394 const operand_ty = self.typeOf(ty_op.operand);9394 const operand_ty = self.typeOf(ty_op.operand);
9395 const operand = try self.resolveInst(ty_op.operand);9395 const operand = try self.resolveInst(ty_op.operand);
...@@ -9408,7 +9408,7 @@ pub const FuncGen = struct {...@@ -9408,7 +9408,7 @@ pub const FuncGen = struct {
9408 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9408 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9409 const o = self.dg.object;9409 const o = self.dg.object;
9410 const mod = o.module;9410 const mod = o.module;
9411 const ty_op = self.air.instructions.items(.data)[inst].ty_op;9411 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9412 const operand_ty = self.typeOf(ty_op.operand);9412 const operand_ty = self.typeOf(ty_op.operand);
9413 var bits = operand_ty.intInfo(mod).bits;9413 var bits = operand_ty.intInfo(mod).bits;
9414 assert(bits % 8 == 0);9414 assert(bits % 8 == 0);
...@@ -9442,9 +9442,9 @@ pub const FuncGen = struct {...@@ -9442,9 +9442,9 @@ pub const FuncGen = struct {
9442 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9442 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9443 const o = self.dg.object;9443 const o = self.dg.object;
9444 const mod = o.module;9444 const mod = o.module;
9445 const ty_op = self.air.instructions.items(.data)[inst].ty_op;9445 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9446 const operand = try self.resolveInst(ty_op.operand);9446 const operand = try self.resolveInst(ty_op.operand);
9447 const error_set_ty = self.air.getRefType(ty_op.ty);9447 const error_set_ty = ty_op.ty.toType();
94489448
9449 const names = error_set_ty.errorSetNames(mod);9449 const names = error_set_ty.errorSetNames(mod);
9450 const valid_block = try self.wip.block(@intCast(names.len), "Valid");9450 const valid_block = try self.wip.block(@intCast(names.len), "Valid");
...@@ -9472,7 +9472,7 @@ pub const FuncGen = struct {...@@ -9472,7 +9472,7 @@ pub const FuncGen = struct {
94729472
9473 fn airIsNamedEnumValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9473 fn airIsNamedEnumValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9474 const o = self.dg.object;9474 const o = self.dg.object;
9475 const un_op = self.air.instructions.items(.data)[inst].un_op;9475 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
9476 const operand = try self.resolveInst(un_op);9476 const operand = try self.resolveInst(un_op);
9477 const enum_ty = self.typeOf(un_op);9477 const enum_ty = self.typeOf(un_op);
94789478
...@@ -9542,7 +9542,7 @@ pub const FuncGen = struct {...@@ -9542,7 +9542,7 @@ pub const FuncGen = struct {
95429542
9543 fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9543 fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9544 const o = self.dg.object;9544 const o = self.dg.object;
9545 const un_op = self.air.instructions.items(.data)[inst].un_op;9545 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
9546 const operand = try self.resolveInst(un_op);9546 const operand = try self.resolveInst(un_op);
9547 const enum_ty = self.typeOf(un_op);9547 const enum_ty = self.typeOf(un_op);
95489548
...@@ -9654,7 +9654,7 @@ pub const FuncGen = struct {...@@ -9654,7 +9654,7 @@ pub const FuncGen = struct {
96549654
9655 fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9655 fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9656 const o = self.dg.object;9656 const o = self.dg.object;
9657 const un_op = self.air.instructions.items(.data)[inst].un_op;9657 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
9658 const operand = try self.resolveInst(un_op);9658 const operand = try self.resolveInst(un_op);
9659 const slice_ty = self.typeOfIndex(inst);9659 const slice_ty = self.typeOfIndex(inst);
9660 const slice_llvm_ty = try o.lowerType(slice_ty);9660 const slice_llvm_ty = try o.lowerType(slice_ty);
...@@ -9669,14 +9669,14 @@ pub const FuncGen = struct {...@@ -9669,14 +9669,14 @@ pub const FuncGen = struct {
96699669
9670 fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9670 fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9671 const o = self.dg.object;9671 const o = self.dg.object;
9672 const ty_op = self.air.instructions.items(.data)[inst].ty_op;9672 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9673 const scalar = try self.resolveInst(ty_op.operand);9673 const scalar = try self.resolveInst(ty_op.operand);
9674 const vector_ty = self.typeOfIndex(inst);9674 const vector_ty = self.typeOfIndex(inst);
9675 return self.wip.splatVector(try o.lowerType(vector_ty), scalar, "");9675 return self.wip.splatVector(try o.lowerType(vector_ty), scalar, "");
9676 }9676 }
96779677
9678 fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9678 fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9679 const pl_op = self.air.instructions.items(.data)[inst].pl_op;9679 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
9680 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;9680 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
9681 const pred = try self.resolveInst(pl_op.operand);9681 const pred = try self.resolveInst(pl_op.operand);
9682 const a = try self.resolveInst(extra.lhs);9682 const a = try self.resolveInst(extra.lhs);
...@@ -9688,7 +9688,7 @@ pub const FuncGen = struct {...@@ -9688,7 +9688,7 @@ pub const FuncGen = struct {
9688 fn airShuffle(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9688 fn airShuffle(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9689 const o = self.dg.object;9689 const o = self.dg.object;
9690 const mod = o.module;9690 const mod = o.module;
9691 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;9691 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
9692 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;9692 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
9693 const a = try self.resolveInst(extra.a);9693 const a = try self.resolveInst(extra.a);
9694 const b = try self.resolveInst(extra.b);9694 const b = try self.resolveInst(extra.b);
...@@ -9799,7 +9799,7 @@ pub const FuncGen = struct {...@@ -9799,7 +9799,7 @@ pub const FuncGen = struct {
9799 const mod = o.module;9799 const mod = o.module;
9800 const target = mod.getTarget();9800 const target = mod.getTarget();
98019801
9802 const reduce = self.air.instructions.items(.data)[inst].reduce;9802 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
9803 const operand = try self.resolveInst(reduce.operand);9803 const operand = try self.resolveInst(reduce.operand);
9804 const operand_ty = self.typeOf(reduce.operand);9804 const operand_ty = self.typeOf(reduce.operand);
9805 const llvm_operand_ty = try o.lowerType(operand_ty);9805 const llvm_operand_ty = try o.lowerType(operand_ty);
...@@ -9908,7 +9908,7 @@ pub const FuncGen = struct {...@@ -9908,7 +9908,7 @@ pub const FuncGen = struct {
9908 const o = self.dg.object;9908 const o = self.dg.object;
9909 const mod = o.module;9909 const mod = o.module;
9910 const ip = &mod.intern_pool;9910 const ip = &mod.intern_pool;
9911 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;9911 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
9912 const result_ty = self.typeOfIndex(inst);9912 const result_ty = self.typeOfIndex(inst);
9913 const len: usize = @intCast(result_ty.arrayLen(mod));9913 const len: usize = @intCast(result_ty.arrayLen(mod));
9914 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);9914 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
...@@ -10031,7 +10031,7 @@ pub const FuncGen = struct {...@@ -10031,7 +10031,7 @@ pub const FuncGen = struct {
10031 const o = self.dg.object;10031 const o = self.dg.object;
10032 const mod = o.module;10032 const mod = o.module;
10033 const ip = &mod.intern_pool;10033 const ip = &mod.intern_pool;
10034 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;10034 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
10035 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;10035 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
10036 const union_ty = self.typeOfIndex(inst);10036 const union_ty = self.typeOfIndex(inst);
10037 const union_llvm_ty = try o.lowerType(union_ty);10037 const union_llvm_ty = try o.lowerType(union_ty);
...@@ -10151,7 +10151,7 @@ pub const FuncGen = struct {...@@ -10151,7 +10151,7 @@ pub const FuncGen = struct {
1015110151
10152 fn airPrefetch(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10152 fn airPrefetch(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10153 const o = self.dg.object;10153 const o = self.dg.object;
10154 const prefetch = self.air.instructions.items(.data)[inst].prefetch;10154 const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
1015510155
10156 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.read) == 0);10156 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.read) == 0);
10157 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.write) == 1);10157 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.write) == 1);
...@@ -10201,7 +10201,7 @@ pub const FuncGen = struct {...@@ -10201,7 +10201,7 @@ pub const FuncGen = struct {
1020110201
10202 fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10202 fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10203 const o = self.dg.object;10203 const o = self.dg.object;
10204 const ty_op = self.air.instructions.items(.data)[inst].ty_op;10204 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
10205 const inst_ty = self.typeOfIndex(inst);10205 const inst_ty = self.typeOfIndex(inst);
10206 const operand = try self.resolveInst(ty_op.operand);10206 const operand = try self.resolveInst(ty_op.operand);
1020710207
...@@ -10227,7 +10227,7 @@ pub const FuncGen = struct {...@@ -10227,7 +10227,7 @@ pub const FuncGen = struct {
10227 const target = o.module.getTarget();10227 const target = o.module.getTarget();
10228 assert(target.cpu.arch == .amdgcn); // TODO is to port this function to other GPU architectures10228 assert(target.cpu.arch == .amdgcn); // TODO is to port this function to other GPU architectures
1022910229
10230 const pl_op = self.air.instructions.items(.data)[inst].pl_op;10230 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
10231 const dimension = pl_op.payload;10231 const dimension = pl_op.payload;
10232 return self.amdgcnWorkIntrinsic(dimension, 0, "amdgcn.workitem.id");10232 return self.amdgcnWorkIntrinsic(dimension, 0, "amdgcn.workitem.id");
10233 }10233 }
...@@ -10237,7 +10237,7 @@ pub const FuncGen = struct {...@@ -10237,7 +10237,7 @@ pub const FuncGen = struct {
10237 const target = o.module.getTarget();10237 const target = o.module.getTarget();
10238 assert(target.cpu.arch == .amdgcn); // TODO is to port this function to other GPU architectures10238 assert(target.cpu.arch == .amdgcn); // TODO is to port this function to other GPU architectures
1023910239
10240 const pl_op = self.air.instructions.items(.data)[inst].pl_op;10240 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
10241 const dimension = pl_op.payload;10241 const dimension = pl_op.payload;
10242 if (dimension >= 3) return o.builder.intValue(.i32, 1);10242 if (dimension >= 3) return o.builder.intValue(.i32, 1);
1024310243
...@@ -10260,7 +10260,7 @@ pub const FuncGen = struct {...@@ -10260,7 +10260,7 @@ pub const FuncGen = struct {
10260 const target = o.module.getTarget();10260 const target = o.module.getTarget();
10261 assert(target.cpu.arch == .amdgcn); // TODO is to port this function to other GPU architectures10261 assert(target.cpu.arch == .amdgcn); // TODO is to port this function to other GPU architectures
1026210262
10263 const pl_op = self.air.instructions.items(.data)[inst].pl_op;10263 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
10264 const dimension = pl_op.payload;10264 const dimension = pl_op.payload;
10265 return self.amdgcnWorkIntrinsic(dimension, 0, "amdgcn.workgroup.id");10265 return self.amdgcnWorkIntrinsic(dimension, 0, "amdgcn.workgroup.id");
10266 }10266 }
src/codegen/spirv.zig+71-70
...@@ -445,7 +445,7 @@ const DeclGen = struct {...@@ -445,7 +445,7 @@ const DeclGen = struct {
445445
446 return try self.constant(ty, val, .direct);446 return try self.constant(ty, val, .direct);
447 }447 }
448 const index = Air.refToIndex(inst).?;448 const index = inst.toIndex().?;
449 return self.inst_results.get(index).?; // Assertion means instruction does not dominate usage.449 return self.inst_results.get(index).?; // Assertion means instruction does not dominate usage.
450 }450 }
451451
...@@ -2089,7 +2089,7 @@ const DeclGen = struct {...@@ -2089,7 +2089,7 @@ const DeclGen = struct {
2089 return;2089 return;
20902090
2091 const air_tags = self.air.instructions.items(.tag);2091 const air_tags = self.air.instructions.items(.tag);
2092 const maybe_result_id: ?IdRef = switch (air_tags[inst]) {2092 const maybe_result_id: ?IdRef = switch (air_tags[@intFromEnum(inst)]) {
2093 // zig fmt: off2093 // zig fmt: off
2094 .add, .add_wrap => try self.airArithOp(inst, .OpFAdd, .OpIAdd, .OpIAdd, true),2094 .add, .add_wrap => try self.airArithOp(inst, .OpFAdd, .OpIAdd, .OpIAdd, true),
2095 .sub, .sub_wrap => try self.airArithOp(inst, .OpFSub, .OpISub, .OpISub, true),2095 .sub, .sub_wrap => try self.airArithOp(inst, .OpFSub, .OpISub, .OpISub, true),
...@@ -2255,7 +2255,7 @@ const DeclGen = struct {...@@ -2255,7 +2255,7 @@ const DeclGen = struct {
2255 fn airBinOpSimple(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {2255 fn airBinOpSimple(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {
2256 if (self.liveness.isUnused(inst)) return null;2256 if (self.liveness.isUnused(inst)) return null;
22572257
2258 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2258 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2259 const lhs_id = try self.resolve(bin_op.lhs);2259 const lhs_id = try self.resolve(bin_op.lhs);
2260 const rhs_id = try self.resolve(bin_op.rhs);2260 const rhs_id = try self.resolve(bin_op.rhs);
2261 const ty = self.typeOf(bin_op.lhs);2261 const ty = self.typeOf(bin_op.lhs);
...@@ -2265,7 +2265,7 @@ const DeclGen = struct {...@@ -2265,7 +2265,7 @@ const DeclGen = struct {
22652265
2266 fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {2266 fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {
2267 if (self.liveness.isUnused(inst)) return null;2267 if (self.liveness.isUnused(inst)) return null;
2268 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2268 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2269 const lhs_id = try self.resolve(bin_op.lhs);2269 const lhs_id = try self.resolve(bin_op.lhs);
2270 const rhs_id = try self.resolve(bin_op.rhs);2270 const rhs_id = try self.resolve(bin_op.rhs);
2271 const result_type_id = try self.resolveTypeId(self.typeOfIndex(inst));2271 const result_type_id = try self.resolveTypeId(self.typeOfIndex(inst));
...@@ -2291,7 +2291,7 @@ const DeclGen = struct {...@@ -2291,7 +2291,7 @@ const DeclGen = struct {
2291 fn airMinMax(self: *DeclGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !?IdRef {2291 fn airMinMax(self: *DeclGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !?IdRef {
2292 if (self.liveness.isUnused(inst)) return null;2292 if (self.liveness.isUnused(inst)) return null;
22932293
2294 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2294 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2295 const lhs_id = try self.resolve(bin_op.lhs);2295 const lhs_id = try self.resolve(bin_op.lhs);
2296 const rhs_id = try self.resolve(bin_op.rhs);2296 const rhs_id = try self.resolve(bin_op.rhs);
2297 const result_ty = self.typeOfIndex(inst);2297 const result_ty = self.typeOfIndex(inst);
...@@ -2395,7 +2395,7 @@ const DeclGen = struct {...@@ -2395,7 +2395,7 @@ const DeclGen = struct {
2395 // LHS and RHS are guaranteed to have the same type, and AIR guarantees2395 // LHS and RHS are guaranteed to have the same type, and AIR guarantees
2396 // the result to be the same as the LHS and RHS, which matches SPIR-V.2396 // the result to be the same as the LHS and RHS, which matches SPIR-V.
2397 const ty = self.typeOfIndex(inst);2397 const ty = self.typeOfIndex(inst);
2398 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2398 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2399 const lhs_id = try self.resolve(bin_op.lhs);2399 const lhs_id = try self.resolve(bin_op.lhs);
2400 const rhs_id = try self.resolve(bin_op.rhs);2400 const rhs_id = try self.resolve(bin_op.rhs);
24012401
...@@ -2492,7 +2492,7 @@ const DeclGen = struct {...@@ -2492,7 +2492,7 @@ const DeclGen = struct {
2492 ) !?IdRef {2492 ) !?IdRef {
2493 if (self.liveness.isUnused(inst)) return null;2493 if (self.liveness.isUnused(inst)) return null;
24942494
2495 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2495 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2496 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2496 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2497 const lhs = try self.resolve(extra.lhs);2497 const lhs = try self.resolve(extra.lhs);
2498 const rhs = try self.resolve(extra.rhs);2498 const rhs = try self.resolve(extra.rhs);
...@@ -2601,7 +2601,7 @@ const DeclGen = struct {...@@ -2601,7 +2601,7 @@ const DeclGen = struct {
2601 const mod = self.module;2601 const mod = self.module;
2602 if (self.liveness.isUnused(inst)) return null;2602 if (self.liveness.isUnused(inst)) return null;
2603 const ty = self.typeOfIndex(inst);2603 const ty = self.typeOfIndex(inst);
2604 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2604 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2605 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;2605 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
2606 const a = try self.resolve(extra.a);2606 const a = try self.resolve(extra.a);
2607 const b = try self.resolve(extra.b);2607 const b = try self.resolve(extra.b);
...@@ -2719,7 +2719,7 @@ const DeclGen = struct {...@@ -2719,7 +2719,7 @@ const DeclGen = struct {
27192719
2720 fn airPtrAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2720 fn airPtrAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2721 if (self.liveness.isUnused(inst)) return null;2721 if (self.liveness.isUnused(inst)) return null;
2722 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2722 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2723 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;2723 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
2724 const ptr_id = try self.resolve(bin_op.lhs);2724 const ptr_id = try self.resolve(bin_op.lhs);
2725 const offset_id = try self.resolve(bin_op.rhs);2725 const offset_id = try self.resolve(bin_op.rhs);
...@@ -2731,7 +2731,7 @@ const DeclGen = struct {...@@ -2731,7 +2731,7 @@ const DeclGen = struct {
27312731
2732 fn airPtrSub(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2732 fn airPtrSub(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2733 if (self.liveness.isUnused(inst)) return null;2733 if (self.liveness.isUnused(inst)) return null;
2734 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2734 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2735 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;2735 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
2736 const ptr_id = try self.resolve(bin_op.lhs);2736 const ptr_id = try self.resolve(bin_op.lhs);
2737 const ptr_ty = self.typeOf(bin_op.lhs);2737 const ptr_ty = self.typeOf(bin_op.lhs);
...@@ -2919,7 +2919,7 @@ const DeclGen = struct {...@@ -2919,7 +2919,7 @@ const DeclGen = struct {
2919 comptime op: std.math.CompareOperator,2919 comptime op: std.math.CompareOperator,
2920 ) !?IdRef {2920 ) !?IdRef {
2921 if (self.liveness.isUnused(inst)) return null;2921 if (self.liveness.isUnused(inst)) return null;
2922 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2922 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2923 const lhs_id = try self.resolve(bin_op.lhs);2923 const lhs_id = try self.resolve(bin_op.lhs);
2924 const rhs_id = try self.resolve(bin_op.rhs);2924 const rhs_id = try self.resolve(bin_op.rhs);
2925 const ty = self.typeOf(bin_op.lhs);2925 const ty = self.typeOf(bin_op.lhs);
...@@ -2931,7 +2931,7 @@ const DeclGen = struct {...@@ -2931,7 +2931,7 @@ const DeclGen = struct {
2931 fn airVectorCmp(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2931 fn airVectorCmp(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2932 if (self.liveness.isUnused(inst)) return null;2932 if (self.liveness.isUnused(inst)) return null;
29332933
2934 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;2934 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2935 const vec_cmp = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;2935 const vec_cmp = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;
2936 const lhs_id = try self.resolve(vec_cmp.lhs);2936 const lhs_id = try self.resolve(vec_cmp.lhs);
2937 const rhs_id = try self.resolve(vec_cmp.rhs);2937 const rhs_id = try self.resolve(vec_cmp.rhs);
...@@ -2999,7 +2999,7 @@ const DeclGen = struct {...@@ -2999,7 +2999,7 @@ const DeclGen = struct {
29992999
3000 fn airBitCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3000 fn airBitCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3001 if (self.liveness.isUnused(inst)) return null;3001 if (self.liveness.isUnused(inst)) return null;
3002 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3002 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3003 const operand_id = try self.resolve(ty_op.operand);3003 const operand_id = try self.resolve(ty_op.operand);
3004 const operand_ty = self.typeOf(ty_op.operand);3004 const operand_ty = self.typeOf(ty_op.operand);
3005 const result_ty = self.typeOfIndex(inst);3005 const result_ty = self.typeOfIndex(inst);
...@@ -3009,7 +3009,7 @@ const DeclGen = struct {...@@ -3009,7 +3009,7 @@ const DeclGen = struct {
3009 fn airIntCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3009 fn airIntCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3010 if (self.liveness.isUnused(inst)) return null;3010 if (self.liveness.isUnused(inst)) return null;
30113011
3012 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3012 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3013 const operand_id = try self.resolve(ty_op.operand);3013 const operand_id = try self.resolve(ty_op.operand);
3014 const src_ty = self.typeOf(ty_op.operand);3014 const src_ty = self.typeOf(ty_op.operand);
3015 const dst_ty = self.typeOfIndex(inst);3015 const dst_ty = self.typeOfIndex(inst);
...@@ -3057,7 +3057,7 @@ const DeclGen = struct {...@@ -3057,7 +3057,7 @@ const DeclGen = struct {
3057 fn airIntFromPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3057 fn airIntFromPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3058 if (self.liveness.isUnused(inst)) return null;3058 if (self.liveness.isUnused(inst)) return null;
30593059
3060 const un_op = self.air.instructions.items(.data)[inst].un_op;3060 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
3061 const operand_id = try self.resolve(un_op);3061 const operand_id = try self.resolve(un_op);
3062 return try self.intFromPtr(operand_id);3062 return try self.intFromPtr(operand_id);
3063 }3063 }
...@@ -3065,7 +3065,7 @@ const DeclGen = struct {...@@ -3065,7 +3065,7 @@ const DeclGen = struct {
3065 fn airFloatFromInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3065 fn airFloatFromInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3066 if (self.liveness.isUnused(inst)) return null;3066 if (self.liveness.isUnused(inst)) return null;
30673067
3068 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3068 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3069 const operand_ty = self.typeOf(ty_op.operand);3069 const operand_ty = self.typeOf(ty_op.operand);
3070 const operand_id = try self.resolve(ty_op.operand);3070 const operand_id = try self.resolve(ty_op.operand);
3071 const operand_info = try self.arithmeticTypeInfo(operand_ty);3071 const operand_info = try self.arithmeticTypeInfo(operand_ty);
...@@ -3091,7 +3091,7 @@ const DeclGen = struct {...@@ -3091,7 +3091,7 @@ const DeclGen = struct {
3091 fn airIntFromFloat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3091 fn airIntFromFloat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3092 if (self.liveness.isUnused(inst)) return null;3092 if (self.liveness.isUnused(inst)) return null;
30933093
3094 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3094 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3095 const operand_id = try self.resolve(ty_op.operand);3095 const operand_id = try self.resolve(ty_op.operand);
3096 const dest_ty = self.typeOfIndex(inst);3096 const dest_ty = self.typeOfIndex(inst);
3097 const dest_info = try self.arithmeticTypeInfo(dest_ty);3097 const dest_info = try self.arithmeticTypeInfo(dest_ty);
...@@ -3116,7 +3116,7 @@ const DeclGen = struct {...@@ -3116,7 +3116,7 @@ const DeclGen = struct {
3116 fn airFloatCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3116 fn airFloatCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3117 if (self.liveness.isUnused(inst)) return null;3117 if (self.liveness.isUnused(inst)) return null;
31183118
3119 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3119 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3120 const operand_id = try self.resolve(ty_op.operand);3120 const operand_id = try self.resolve(ty_op.operand);
3121 const dest_ty = self.typeOfIndex(inst);3121 const dest_ty = self.typeOfIndex(inst);
3122 const dest_ty_id = try self.resolveTypeId(dest_ty);3122 const dest_ty_id = try self.resolveTypeId(dest_ty);
...@@ -3132,7 +3132,7 @@ const DeclGen = struct {...@@ -3132,7 +3132,7 @@ const DeclGen = struct {
31323132
3133 fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3133 fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3134 if (self.liveness.isUnused(inst)) return null;3134 if (self.liveness.isUnused(inst)) return null;
3135 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3135 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3136 const operand_id = try self.resolve(ty_op.operand);3136 const operand_id = try self.resolve(ty_op.operand);
3137 const result_ty = self.typeOfIndex(inst);3137 const result_ty = self.typeOfIndex(inst);
3138 const result_ty_id = try self.resolveTypeId(result_ty);3138 const result_ty_id = try self.resolveTypeId(result_ty);
...@@ -3166,7 +3166,7 @@ const DeclGen = struct {...@@ -3166,7 +3166,7 @@ const DeclGen = struct {
3166 if (self.liveness.isUnused(inst)) return null;3166 if (self.liveness.isUnused(inst)) return null;
31673167
3168 const mod = self.module;3168 const mod = self.module;
3169 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3169 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3170 const array_ptr_ty = self.typeOf(ty_op.operand);3170 const array_ptr_ty = self.typeOf(ty_op.operand);
3171 const array_ty = array_ptr_ty.childType(mod);3171 const array_ty = array_ptr_ty.childType(mod);
3172 const slice_ty = self.typeOfIndex(inst);3172 const slice_ty = self.typeOfIndex(inst);
...@@ -3195,7 +3195,7 @@ const DeclGen = struct {...@@ -3195,7 +3195,7 @@ const DeclGen = struct {
3195 fn airSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3195 fn airSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3196 if (self.liveness.isUnused(inst)) return null;3196 if (self.liveness.isUnused(inst)) return null;
31973197
3198 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3198 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3199 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3199 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3200 const ptr_id = try self.resolve(bin_op.lhs);3200 const ptr_id = try self.resolve(bin_op.lhs);
3201 const len_id = try self.resolve(bin_op.rhs);3201 const len_id = try self.resolve(bin_op.rhs);
...@@ -3216,7 +3216,7 @@ const DeclGen = struct {...@@ -3216,7 +3216,7 @@ const DeclGen = struct {
32163216
3217 const mod = self.module;3217 const mod = self.module;
3218 const ip = &mod.intern_pool;3218 const ip = &mod.intern_pool;
3219 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3219 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3220 const result_ty = self.typeOfIndex(inst);3220 const result_ty = self.typeOfIndex(inst);
3221 const len: usize = @intCast(result_ty.arrayLen(mod));3221 const len: usize = @intCast(result_ty.arrayLen(mod));
3222 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);3222 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
...@@ -3316,7 +3316,7 @@ const DeclGen = struct {...@@ -3316,7 +3316,7 @@ const DeclGen = struct {
3316 }3316 }
33173317
3318 fn airMemcpy(self: *DeclGen, inst: Air.Inst.Index) !void {3318 fn airMemcpy(self: *DeclGen, inst: Air.Inst.Index) !void {
3319 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3319 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3320 const dest_slice = try self.resolve(bin_op.lhs);3320 const dest_slice = try self.resolve(bin_op.lhs);
3321 const src_slice = try self.resolve(bin_op.rhs);3321 const src_slice = try self.resolve(bin_op.rhs);
3322 const dest_ty = self.typeOf(bin_op.lhs);3322 const dest_ty = self.typeOf(bin_op.lhs);
...@@ -3333,7 +3333,7 @@ const DeclGen = struct {...@@ -3333,7 +3333,7 @@ const DeclGen = struct {
33333333
3334 fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef {3334 fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef {
3335 if (self.liveness.isUnused(inst)) return null;3335 if (self.liveness.isUnused(inst)) return null;
3336 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3336 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3337 const field_ty = self.typeOfIndex(inst);3337 const field_ty = self.typeOfIndex(inst);
3338 const operand_id = try self.resolve(ty_op.operand);3338 const operand_id = try self.resolve(ty_op.operand);
3339 return try self.extractField(field_ty, operand_id, field);3339 return try self.extractField(field_ty, operand_id, field);
...@@ -3341,7 +3341,7 @@ const DeclGen = struct {...@@ -3341,7 +3341,7 @@ const DeclGen = struct {
33413341
3342 fn airSliceElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3342 fn airSliceElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3343 const mod = self.module;3343 const mod = self.module;
3344 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3344 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3345 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3345 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3346 const slice_ty = self.typeOf(bin_op.lhs);3346 const slice_ty = self.typeOf(bin_op.lhs);
3347 if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null;3347 if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null;
...@@ -3358,7 +3358,7 @@ const DeclGen = struct {...@@ -3358,7 +3358,7 @@ const DeclGen = struct {
33583358
3359 fn airSliceElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3359 fn airSliceElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3360 const mod = self.module;3360 const mod = self.module;
3361 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3361 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3362 const slice_ty = self.typeOf(bin_op.lhs);3362 const slice_ty = self.typeOf(bin_op.lhs);
3363 if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null;3363 if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null;
33643364
...@@ -3392,7 +3392,7 @@ const DeclGen = struct {...@@ -3392,7 +3392,7 @@ const DeclGen = struct {
3392 if (self.liveness.isUnused(inst)) return null;3392 if (self.liveness.isUnused(inst)) return null;
33933393
3394 const mod = self.module;3394 const mod = self.module;
3395 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3395 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3396 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3396 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3397 const src_ptr_ty = self.typeOf(bin_op.lhs);3397 const src_ptr_ty = self.typeOf(bin_op.lhs);
3398 const elem_ty = src_ptr_ty.childType(mod);3398 const elem_ty = src_ptr_ty.childType(mod);
...@@ -3411,7 +3411,7 @@ const DeclGen = struct {...@@ -3411,7 +3411,7 @@ const DeclGen = struct {
3411 if (self.liveness.isUnused(inst)) return null;3411 if (self.liveness.isUnused(inst)) return null;
34123412
3413 const mod = self.module;3413 const mod = self.module;
3414 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3414 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3415 const array_ty = self.typeOf(bin_op.lhs);3415 const array_ty = self.typeOf(bin_op.lhs);
3416 const elem_ty = array_ty.childType(mod);3416 const elem_ty = array_ty.childType(mod);
3417 const array_id = try self.resolve(bin_op.lhs);3417 const array_id = try self.resolve(bin_op.lhs);
...@@ -3433,7 +3433,7 @@ const DeclGen = struct {...@@ -3433,7 +3433,7 @@ const DeclGen = struct {
3433 if (self.liveness.isUnused(inst)) return null;3433 if (self.liveness.isUnused(inst)) return null;
34343434
3435 const mod = self.module;3435 const mod = self.module;
3436 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3436 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3437 const ptr_ty = self.typeOf(bin_op.lhs);3437 const ptr_ty = self.typeOf(bin_op.lhs);
3438 const elem_ty = self.typeOfIndex(inst);3438 const elem_ty = self.typeOfIndex(inst);
3439 const ptr_id = try self.resolve(bin_op.lhs);3439 const ptr_id = try self.resolve(bin_op.lhs);
...@@ -3444,7 +3444,7 @@ const DeclGen = struct {...@@ -3444,7 +3444,7 @@ const DeclGen = struct {
34443444
3445 fn airSetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !void {3445 fn airSetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !void {
3446 const mod = self.module;3446 const mod = self.module;
3447 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3447 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3448 const un_ptr_ty = self.typeOf(bin_op.lhs);3448 const un_ptr_ty = self.typeOf(bin_op.lhs);
3449 const un_ty = un_ptr_ty.childType(mod);3449 const un_ty = un_ptr_ty.childType(mod);
3450 const layout = self.unionLayout(un_ty);3450 const layout = self.unionLayout(un_ty);
...@@ -3468,7 +3468,7 @@ const DeclGen = struct {...@@ -3468,7 +3468,7 @@ const DeclGen = struct {
3468 fn airGetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3468 fn airGetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3469 if (self.liveness.isUnused(inst)) return null;3469 if (self.liveness.isUnused(inst)) return null;
34703470
3471 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3471 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3472 const un_ty = self.typeOf(ty_op.operand);3472 const un_ty = self.typeOf(ty_op.operand);
34733473
3474 const mod = self.module;3474 const mod = self.module;
...@@ -3555,7 +3555,7 @@ const DeclGen = struct {...@@ -3555,7 +3555,7 @@ const DeclGen = struct {
35553555
3556 const mod = self.module;3556 const mod = self.module;
3557 const ip = &mod.intern_pool;3557 const ip = &mod.intern_pool;
3558 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3558 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3559 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;3559 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
3560 const ty = self.typeOfIndex(inst);3560 const ty = self.typeOfIndex(inst);
35613561
...@@ -3572,7 +3572,7 @@ const DeclGen = struct {...@@ -3572,7 +3572,7 @@ const DeclGen = struct {
3572 if (self.liveness.isUnused(inst)) return null;3572 if (self.liveness.isUnused(inst)) return null;
35733573
3574 const mod = self.module;3574 const mod = self.module;
3575 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3575 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3576 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;3576 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
35773577
3578 const object_ty = self.typeOf(struct_field.struct_operand);3578 const object_ty = self.typeOf(struct_field.struct_operand);
...@@ -3616,11 +3616,11 @@ const DeclGen = struct {...@@ -3616,11 +3616,11 @@ const DeclGen = struct {
36163616
3617 fn airFieldParentPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3617 fn airFieldParentPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3618 const mod = self.module;3618 const mod = self.module;
3619 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;3619 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3620 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;3620 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
36213621
3622 const parent_ty = self.air.getRefType(ty_pl.ty).childType(mod);3622 const parent_ty = ty_pl.ty.toType().childType(mod);
3623 const res_ty = try self.resolveType(self.air.getRefType(ty_pl.ty), .indirect);3623 const res_ty = try self.resolveType(ty_pl.ty.toType(), .indirect);
3624 const usize_ty = Type.usize;3624 const usize_ty = Type.usize;
3625 const usize_ty_ref = try self.resolveType(usize_ty, .direct);3625 const usize_ty_ref = try self.resolveType(usize_ty, .direct);
36263626
...@@ -3692,7 +3692,7 @@ const DeclGen = struct {...@@ -3692,7 +3692,7 @@ const DeclGen = struct {
36923692
3693 fn airStructFieldPtrIndex(self: *DeclGen, inst: Air.Inst.Index, field_index: u32) !?IdRef {3693 fn airStructFieldPtrIndex(self: *DeclGen, inst: Air.Inst.Index, field_index: u32) !?IdRef {
3694 if (self.liveness.isUnused(inst)) return null;3694 if (self.liveness.isUnused(inst)) return null;
3695 const ty_op = self.air.instructions.items(.data)[inst].ty_op;3695 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3696 const struct_ptr = try self.resolve(ty_op.operand);3696 const struct_ptr = try self.resolve(ty_op.operand);
3697 const struct_ptr_ty = self.typeOf(ty_op.operand);3697 const struct_ptr_ty = self.typeOf(ty_op.operand);
3698 const result_ptr_ty = self.typeOfIndex(inst);3698 const result_ptr_ty = self.typeOfIndex(inst);
...@@ -3918,8 +3918,9 @@ const DeclGen = struct {...@@ -3918,8 +3918,9 @@ const DeclGen = struct {
3918 const mod = self.module;3918 const mod = self.module;
3919 const ty = self.typeOfIndex(inst);3919 const ty = self.typeOfIndex(inst);
3920 const inst_datas = self.air.instructions.items(.data);3920 const inst_datas = self.air.instructions.items(.data);
3921 const extra = self.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);3921 const extra = self.air.extraData(Air.Block, inst_datas[@intFromEnum(inst)].ty_pl.payload);
3922 const body = self.air.extra[extra.end..][0..extra.data.body_len];3922 const body: []const Air.Inst.Index =
3923 @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
3923 const have_block_result = ty.isFnOrHasRuntimeBitsIgnoreComptime(mod);3924 const have_block_result = ty.isFnOrHasRuntimeBitsIgnoreComptime(mod);
39243925
3925 const cf = switch (self.control_flow) {3926 const cf = switch (self.control_flow) {
...@@ -3983,7 +3984,7 @@ const DeclGen = struct {...@@ -3983,7 +3984,7 @@ const DeclGen = struct {
39833984
3984 // Check if the target of the branch was this current block.3985 // Check if the target of the branch was this current block.
3985 const block_id_ty_ref = try self.intType(.unsigned, 32);3986 const block_id_ty_ref = try self.intType(.unsigned, 32);
3986 const this_block = try self.constInt(block_id_ty_ref, inst);3987 const this_block = try self.constInt(block_id_ty_ref, @intFromEnum(inst));
3987 const jump_to_this_block_id = self.spv.allocId();3988 const jump_to_this_block_id = self.spv.allocId();
3988 const bool_ty_ref = try self.resolveType(Type.bool, .direct);3989 const bool_ty_ref = try self.resolveType(Type.bool, .direct);
3989 try self.func.body.emit(self.spv.gpa, .OpIEqual, .{3990 try self.func.body.emit(self.spv.gpa, .OpIEqual, .{
...@@ -4052,7 +4053,7 @@ const DeclGen = struct {...@@ -4052,7 +4053,7 @@ const DeclGen = struct {
40524053
4053 fn airBr(self: *DeclGen, inst: Air.Inst.Index) !void {4054 fn airBr(self: *DeclGen, inst: Air.Inst.Index) !void {
4054 const mod = self.module;4055 const mod = self.module;
4055 const br = self.air.instructions.items(.data)[inst].br;4056 const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
4056 const operand_ty = self.typeOf(br.operand);4057 const operand_ty = self.typeOf(br.operand);
40574058
4058 switch (self.control_flow) {4059 switch (self.control_flow) {
...@@ -4064,7 +4065,7 @@ const DeclGen = struct {...@@ -4064,7 +4065,7 @@ const DeclGen = struct {
4064 }4065 }
40654066
4066 const block_id_ty_ref = try self.intType(.unsigned, 32);4067 const block_id_ty_ref = try self.intType(.unsigned, 32);
4067 const next_block = try self.constInt(block_id_ty_ref, br.block_inst);4068 const next_block = try self.constInt(block_id_ty_ref, @intFromEnum(br.block_inst));
4068 try self.structuredBreak(next_block);4069 try self.structuredBreak(next_block);
4069 },4070 },
4070 .unstructured => |cf| {4071 .unstructured => |cf| {
...@@ -4089,10 +4090,10 @@ const DeclGen = struct {...@@ -4089,10 +4090,10 @@ const DeclGen = struct {
4089 }4090 }
40904091
4091 fn airCondBr(self: *DeclGen, inst: Air.Inst.Index) !void {4092 fn airCondBr(self: *DeclGen, inst: Air.Inst.Index) !void {
4092 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4093 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4093 const cond_br = self.air.extraData(Air.CondBr, pl_op.payload);4094 const cond_br = self.air.extraData(Air.CondBr, pl_op.payload);
4094 const then_body = self.air.extra[cond_br.end..][0..cond_br.data.then_body_len];4095 const then_body: []const Air.Inst.Index = @ptrCast(self.air.extra[cond_br.end..][0..cond_br.data.then_body_len]);
4095 const else_body = self.air.extra[cond_br.end + then_body.len ..][0..cond_br.data.else_body_len];4096 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[cond_br.end + then_body.len ..][0..cond_br.data.else_body_len]);
4096 const condition_id = try self.resolve(pl_op.operand);4097 const condition_id = try self.resolve(pl_op.operand);
40974098
4098 const then_label = self.spv.allocId();4099 const then_label = self.spv.allocId();
...@@ -4149,9 +4150,9 @@ const DeclGen = struct {...@@ -4149,9 +4150,9 @@ const DeclGen = struct {
4149 }4150 }
41504151
4151 fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void {4152 fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void {
4152 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;4153 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4153 const loop = self.air.extraData(Air.Block, ty_pl.payload);4154 const loop = self.air.extraData(Air.Block, ty_pl.payload);
4154 const body = self.air.extra[loop.end..][0..loop.data.body_len];4155 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);
41554156
4156 const body_label = self.spv.allocId();4157 const body_label = self.spv.allocId();
41574158
...@@ -4197,7 +4198,7 @@ const DeclGen = struct {...@@ -4197,7 +4198,7 @@ const DeclGen = struct {
41974198
4198 fn airLoad(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4199 fn airLoad(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4199 const mod = self.module;4200 const mod = self.module;
4200 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4201 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4201 const ptr_ty = self.typeOf(ty_op.operand);4202 const ptr_ty = self.typeOf(ty_op.operand);
4202 const elem_ty = self.typeOfIndex(inst);4203 const elem_ty = self.typeOfIndex(inst);
4203 const operand = try self.resolve(ty_op.operand);4204 const operand = try self.resolve(ty_op.operand);
...@@ -4207,7 +4208,7 @@ const DeclGen = struct {...@@ -4207,7 +4208,7 @@ const DeclGen = struct {
4207 }4208 }
42084209
4209 fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {4210 fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {
4210 const bin_op = self.air.instructions.items(.data)[inst].bin_op;4211 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4211 const ptr_ty = self.typeOf(bin_op.lhs);4212 const ptr_ty = self.typeOf(bin_op.lhs);
4212 const elem_ty = ptr_ty.childType(self.module);4213 const elem_ty = ptr_ty.childType(self.module);
4213 const ptr = try self.resolve(bin_op.lhs);4214 const ptr = try self.resolve(bin_op.lhs);
...@@ -4217,7 +4218,7 @@ const DeclGen = struct {...@@ -4217,7 +4218,7 @@ const DeclGen = struct {
4217 }4218 }
42184219
4219 fn airRet(self: *DeclGen, inst: Air.Inst.Index) !void {4220 fn airRet(self: *DeclGen, inst: Air.Inst.Index) !void {
4220 const operand = self.air.instructions.items(.data)[inst].un_op;4221 const operand = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4221 const ret_ty = self.typeOf(operand);4222 const ret_ty = self.typeOf(operand);
4222 const mod = self.module;4223 const mod = self.module;
4223 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {4224 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
...@@ -4241,7 +4242,7 @@ const DeclGen = struct {...@@ -4241,7 +4242,7 @@ const DeclGen = struct {
42414242
4242 fn airRetLoad(self: *DeclGen, inst: Air.Inst.Index) !void {4243 fn airRetLoad(self: *DeclGen, inst: Air.Inst.Index) !void {
4243 const mod = self.module;4244 const mod = self.module;
4244 const un_op = self.air.instructions.items(.data)[inst].un_op;4245 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4245 const ptr_ty = self.typeOf(un_op);4246 const ptr_ty = self.typeOf(un_op);
4246 const ret_ty = ptr_ty.childType(mod);4247 const ret_ty = ptr_ty.childType(mod);
42474248
...@@ -4269,10 +4270,10 @@ const DeclGen = struct {...@@ -4269,10 +4270,10 @@ const DeclGen = struct {
42694270
4270 fn airTry(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4271 fn airTry(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4271 const mod = self.module;4272 const mod = self.module;
4272 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4273 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4273 const err_union_id = try self.resolve(pl_op.operand);4274 const err_union_id = try self.resolve(pl_op.operand);
4274 const extra = self.air.extraData(Air.Try, pl_op.payload);4275 const extra = self.air.extraData(Air.Try, pl_op.payload);
4275 const body = self.air.extra[extra.end..][0..extra.data.body_len];4276 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
42764277
4277 const err_union_ty = self.typeOf(pl_op.operand);4278 const err_union_ty = self.typeOf(pl_op.operand);
4278 const payload_ty = self.typeOfIndex(inst);4279 const payload_ty = self.typeOfIndex(inst);
...@@ -4344,7 +4345,7 @@ const DeclGen = struct {...@@ -4344,7 +4345,7 @@ const DeclGen = struct {
4344 if (self.liveness.isUnused(inst)) return null;4345 if (self.liveness.isUnused(inst)) return null;
43454346
4346 const mod = self.module;4347 const mod = self.module;
4347 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4348 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4348 const operand_id = try self.resolve(ty_op.operand);4349 const operand_id = try self.resolve(ty_op.operand);
4349 const err_union_ty = self.typeOf(ty_op.operand);4350 const err_union_ty = self.typeOf(ty_op.operand);
4350 const err_ty_ref = try self.resolveType(Type.anyerror, .direct);4351 const err_ty_ref = try self.resolveType(Type.anyerror, .direct);
...@@ -4368,7 +4369,7 @@ const DeclGen = struct {...@@ -4368,7 +4369,7 @@ const DeclGen = struct {
4368 fn airErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4369 fn airErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4369 if (self.liveness.isUnused(inst)) return null;4370 if (self.liveness.isUnused(inst)) return null;
43704371
4371 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4372 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4372 const operand_id = try self.resolve(ty_op.operand);4373 const operand_id = try self.resolve(ty_op.operand);
4373 const payload_ty = self.typeOfIndex(inst);4374 const payload_ty = self.typeOfIndex(inst);
4374 const eu_layout = self.errorUnionLayout(payload_ty);4375 const eu_layout = self.errorUnionLayout(payload_ty);
...@@ -4384,7 +4385,7 @@ const DeclGen = struct {...@@ -4384,7 +4385,7 @@ const DeclGen = struct {
4384 if (self.liveness.isUnused(inst)) return null;4385 if (self.liveness.isUnused(inst)) return null;
43854386
4386 const mod = self.module;4387 const mod = self.module;
4387 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4388 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4388 const err_union_ty = self.typeOfIndex(inst);4389 const err_union_ty = self.typeOfIndex(inst);
4389 const payload_ty = err_union_ty.errorUnionPayload(mod);4390 const payload_ty = err_union_ty.errorUnionPayload(mod);
4390 const operand_id = try self.resolve(ty_op.operand);4391 const operand_id = try self.resolve(ty_op.operand);
...@@ -4410,7 +4411,7 @@ const DeclGen = struct {...@@ -4410,7 +4411,7 @@ const DeclGen = struct {
4410 fn airWrapErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4411 fn airWrapErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4411 if (self.liveness.isUnused(inst)) return null;4412 if (self.liveness.isUnused(inst)) return null;
44124413
4413 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4414 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4414 const err_union_ty = self.typeOfIndex(inst);4415 const err_union_ty = self.typeOfIndex(inst);
4415 const operand_id = try self.resolve(ty_op.operand);4416 const operand_id = try self.resolve(ty_op.operand);
4416 const payload_ty = self.typeOf(ty_op.operand);4417 const payload_ty = self.typeOf(ty_op.operand);
...@@ -4436,7 +4437,7 @@ const DeclGen = struct {...@@ -4436,7 +4437,7 @@ const DeclGen = struct {
4436 if (self.liveness.isUnused(inst)) return null;4437 if (self.liveness.isUnused(inst)) return null;
44374438
4438 const mod = self.module;4439 const mod = self.module;
4439 const un_op = self.air.instructions.items(.data)[inst].un_op;4440 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4440 const operand_id = try self.resolve(un_op);4441 const operand_id = try self.resolve(un_op);
4441 const optional_ty = self.typeOf(un_op);4442 const optional_ty = self.typeOf(un_op);
44424443
...@@ -4493,7 +4494,7 @@ const DeclGen = struct {...@@ -4493,7 +4494,7 @@ const DeclGen = struct {
4493 if (self.liveness.isUnused(inst)) return null;4494 if (self.liveness.isUnused(inst)) return null;
44944495
4495 const mod = self.module;4496 const mod = self.module;
4496 const un_op = self.air.instructions.items(.data)[inst].un_op;4497 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4497 const operand_id = try self.resolve(un_op);4498 const operand_id = try self.resolve(un_op);
4498 const err_union_ty = self.typeOf(un_op);4499 const err_union_ty = self.typeOf(un_op);
44994500
...@@ -4529,7 +4530,7 @@ const DeclGen = struct {...@@ -4529,7 +4530,7 @@ const DeclGen = struct {
4529 if (self.liveness.isUnused(inst)) return null;4530 if (self.liveness.isUnused(inst)) return null;
45304531
4531 const mod = self.module;4532 const mod = self.module;
4532 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4533 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4533 const operand_id = try self.resolve(ty_op.operand);4534 const operand_id = try self.resolve(ty_op.operand);
4534 const optional_ty = self.typeOf(ty_op.operand);4535 const optional_ty = self.typeOf(ty_op.operand);
4535 const payload_ty = self.typeOfIndex(inst);4536 const payload_ty = self.typeOfIndex(inst);
...@@ -4547,7 +4548,7 @@ const DeclGen = struct {...@@ -4547,7 +4548,7 @@ const DeclGen = struct {
4547 if (self.liveness.isUnused(inst)) return null;4548 if (self.liveness.isUnused(inst)) return null;
45484549
4549 const mod = self.module;4550 const mod = self.module;
4550 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4551 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4551 const payload_ty = self.typeOf(ty_op.operand);4552 const payload_ty = self.typeOf(ty_op.operand);
45524553
4553 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {4554 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
...@@ -4569,7 +4570,7 @@ const DeclGen = struct {...@@ -4569,7 +4570,7 @@ const DeclGen = struct {
45694570
4570 fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void {4571 fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void {
4571 const mod = self.module;4572 const mod = self.module;
4572 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4573 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4573 const cond_ty = self.typeOf(pl_op.operand);4574 const cond_ty = self.typeOf(pl_op.operand);
4574 const cond = try self.resolve(pl_op.operand);4575 const cond = try self.resolve(pl_op.operand);
4575 const cond_indirect = try self.convertToIndirect(cond_ty, cond);4576 const cond_indirect = try self.convertToIndirect(cond_ty, cond);
...@@ -4679,8 +4680,8 @@ const DeclGen = struct {...@@ -4679,8 +4680,8 @@ const DeclGen = struct {
4679 var extra_index: usize = switch_br.end;4680 var extra_index: usize = switch_br.end;
4680 for (0..num_cases) |case_i| {4681 for (0..num_cases) |case_i| {
4681 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);4682 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
4682 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));4683 const items: []const Air.Inst.Ref = @ptrCast(self.air.extra[case.end..][0..case.data.items_len]);
4683 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];4684 const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]);
4684 extra_index = case.end + case.data.items_len + case_body.len;4685 extra_index = case.end + case.data.items_len + case_body.len;
46854686
4686 const label = IdResult{ .id = @intCast(first_case_label.id + case_i) };4687 const label = IdResult{ .id = @intCast(first_case_label.id + case_i) };
...@@ -4702,7 +4703,7 @@ const DeclGen = struct {...@@ -4702,7 +4703,7 @@ const DeclGen = struct {
4702 }4703 }
4703 }4704 }
47044705
4705 const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len];4706 const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]);
4706 try self.beginSpvBlock(default);4707 try self.beginSpvBlock(default);
4707 if (else_body.len != 0) {4708 if (else_body.len != 0) {
4708 switch (self.control_flow) {4709 switch (self.control_flow) {
...@@ -4734,7 +4735,7 @@ const DeclGen = struct {...@@ -4734,7 +4735,7 @@ const DeclGen = struct {
4734 }4735 }
47354736
4736 fn airDbgStmt(self: *DeclGen, inst: Air.Inst.Index) !void {4737 fn airDbgStmt(self: *DeclGen, inst: Air.Inst.Index) !void {
4737 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;4738 const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
4738 const mod = self.module;4739 const mod = self.module;
4739 const decl = mod.declPtr(self.decl_index);4740 const decl = mod.declPtr(self.decl_index);
4740 const path = decl.getFileScope(mod).sub_file_path;4741 const path = decl.getFileScope(mod).sub_file_path;
...@@ -4749,7 +4750,7 @@ const DeclGen = struct {...@@ -4749,7 +4750,7 @@ const DeclGen = struct {
47494750
4750 fn airDbgInlineBegin(self: *DeclGen, inst: Air.Inst.Index) !void {4751 fn airDbgInlineBegin(self: *DeclGen, inst: Air.Inst.Index) !void {
4751 const mod = self.module;4752 const mod = self.module;
4752 const fn_ty = self.air.instructions.items(.data)[inst].ty_fn;4753 const fn_ty = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
4753 const decl_index = mod.funcInfo(fn_ty.func).owner_decl;4754 const decl_index = mod.funcInfo(fn_ty.func).owner_decl;
4754 const decl = mod.declPtr(decl_index);4755 const decl = mod.declPtr(decl_index);
4755 try self.base_line_stack.append(self.gpa, decl.src_line);4756 try self.base_line_stack.append(self.gpa, decl.src_line);
...@@ -4761,7 +4762,7 @@ const DeclGen = struct {...@@ -4761,7 +4762,7 @@ const DeclGen = struct {
4761 }4762 }
47624763
4763 fn airDbgVar(self: *DeclGen, inst: Air.Inst.Index) !void {4764 fn airDbgVar(self: *DeclGen, inst: Air.Inst.Index) !void {
4764 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4765 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4765 const target_id = try self.resolve(pl_op.operand);4766 const target_id = try self.resolve(pl_op.operand);
4766 const name = self.air.nullTerminatedString(pl_op.payload);4767 const name = self.air.nullTerminatedString(pl_op.payload);
4767 try self.spv.debugName(target_id, name);4768 try self.spv.debugName(target_id, name);
...@@ -4769,7 +4770,7 @@ const DeclGen = struct {...@@ -4769,7 +4770,7 @@ const DeclGen = struct {
47694770
4770 fn airAssembly(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4771 fn airAssembly(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4771 const mod = self.module;4772 const mod = self.module;
4772 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;4773 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4773 const extra = self.air.extraData(Air.Asm, ty_pl.payload);4774 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
47744775
4775 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;4776 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
...@@ -4901,7 +4902,7 @@ const DeclGen = struct {...@@ -4901,7 +4902,7 @@ const DeclGen = struct {
4901 _ = modifier;4902 _ = modifier;
49024903
4903 const mod = self.module;4904 const mod = self.module;
4904 const pl_op = self.air.instructions.items(.data)[inst].pl_op;4905 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
4905 const extra = self.air.extraData(Air.Call, pl_op.payload);4906 const extra = self.air.extraData(Air.Call, pl_op.payload);
4906 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));4907 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
4907 const callee_ty = self.typeOf(pl_op.operand);4908 const callee_ty = self.typeOf(pl_op.operand);
src/print_air.zig+55-55
...@@ -94,7 +94,7 @@ const Writer = struct {...@@ -94,7 +94,7 @@ const Writer = struct {
94 }94 }
9595
96 fn writeInst(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {96 fn writeInst(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
97 const tag = w.air.instructions.items(.tag)[inst];97 const tag = w.air.instructions.items(.tag)[@intFromEnum(inst)];
98 try s.writeByteNTimes(' ', w.indent);98 try s.writeByteNTimes(' ', w.indent);
99 try s.print("%{d}{c}= {s}(", .{99 try s.print("%{d}{c}= {s}(", .{
100 inst,100 inst,
...@@ -329,14 +329,14 @@ const Writer = struct {...@@ -329,14 +329,14 @@ const Writer = struct {
329 }329 }
330330
331 fn writeBinOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {331 fn writeBinOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
332 const bin_op = w.air.instructions.items(.data)[inst].bin_op;332 const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
333 try w.writeOperand(s, inst, 0, bin_op.lhs);333 try w.writeOperand(s, inst, 0, bin_op.lhs);
334 try s.writeAll(", ");334 try s.writeAll(", ");
335 try w.writeOperand(s, inst, 1, bin_op.rhs);335 try w.writeOperand(s, inst, 1, bin_op.rhs);
336 }336 }
337337
338 fn writeUnOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {338 fn writeUnOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
339 const un_op = w.air.instructions.items(.data)[inst].un_op;339 const un_op = w.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
340 try w.writeOperand(s, inst, 0, un_op);340 try w.writeOperand(s, inst, 0, un_op);
341 }341 }
342342
...@@ -351,33 +351,33 @@ const Writer = struct {...@@ -351,33 +351,33 @@ const Writer = struct {
351 }351 }
352352
353 fn writeTy(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {353 fn writeTy(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
354 const ty = w.air.instructions.items(.data)[inst].ty;354 const ty = w.air.instructions.items(.data)[@intFromEnum(inst)].ty;
355 try w.writeType(s, ty);355 try w.writeType(s, ty);
356 }356 }
357357
358 fn writeArg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {358 fn writeArg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
359 const arg = w.air.instructions.items(.data)[inst].arg;359 const arg = w.air.instructions.items(.data)[@intFromEnum(inst)].arg;
360 try w.writeType(s, w.air.getRefType(arg.ty));360 try w.writeType(s, arg.ty.toType());
361 try s.print(", {d}", .{arg.src_index});361 try s.print(", {d}", .{arg.src_index});
362 }362 }
363363
364 fn writeTyOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {364 fn writeTyOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
365 const ty_op = w.air.instructions.items(.data)[inst].ty_op;365 const ty_op = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
366 try w.writeType(s, w.air.getRefType(ty_op.ty));366 try w.writeType(s, ty_op.ty.toType());
367 try s.writeAll(", ");367 try s.writeAll(", ");
368 try w.writeOperand(s, inst, 0, ty_op.operand);368 try w.writeOperand(s, inst, 0, ty_op.operand);
369 }369 }
370370
371 fn writeBlock(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {371 fn writeBlock(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
372 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;372 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
373 const extra = w.air.extraData(Air.Block, ty_pl.payload);373 const extra = w.air.extraData(Air.Block, ty_pl.payload);
374 const body = w.air.extra[extra.end..][0..extra.data.body_len];374 const body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end..][0..extra.data.body_len]);
375 const liveness_block = if (w.liveness) |liveness|375 const liveness_block = if (w.liveness) |liveness|
376 liveness.getBlock(inst)376 liveness.getBlock(inst)
377 else377 else
378 Liveness.BlockSlices{ .deaths = &.{} };378 Liveness.BlockSlices{ .deaths = &.{} };
379379
380 try w.writeType(s, w.air.getRefType(ty_pl.ty));380 try w.writeType(s, ty_pl.ty.toType());
381 if (w.skip_body) return s.writeAll(", ...");381 if (w.skip_body) return s.writeAll(", ...");
382 try s.writeAll(", {\n");382 try s.writeAll(", {\n");
383 const old_indent = w.indent;383 const old_indent = w.indent;
...@@ -393,11 +393,11 @@ const Writer = struct {...@@ -393,11 +393,11 @@ const Writer = struct {
393 }393 }
394394
395 fn writeLoop(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {395 fn writeLoop(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
396 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;396 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
397 const extra = w.air.extraData(Air.Block, ty_pl.payload);397 const extra = w.air.extraData(Air.Block, ty_pl.payload);
398 const body = w.air.extra[extra.end..][0..extra.data.body_len];398 const body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end..][0..extra.data.body_len]);
399399
400 try w.writeType(s, w.air.getRefType(ty_pl.ty));400 try w.writeType(s, ty_pl.ty.toType());
401 if (w.skip_body) return s.writeAll(", ...");401 if (w.skip_body) return s.writeAll(", ...");
402 try s.writeAll(", {\n");402 try s.writeAll(", {\n");
403 const old_indent = w.indent;403 const old_indent = w.indent;
...@@ -410,8 +410,8 @@ const Writer = struct {...@@ -410,8 +410,8 @@ const Writer = struct {
410410
411 fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {411 fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
412 const mod = w.module;412 const mod = w.module;
413 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;413 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
414 const vector_ty = w.air.getRefType(ty_pl.ty);414 const vector_ty = ty_pl.ty.toType();
415 const len = @as(usize, @intCast(vector_ty.arrayLen(mod)));415 const len = @as(usize, @intCast(vector_ty.arrayLen(mod)));
416 const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len]));416 const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len]));
417417
...@@ -425,7 +425,7 @@ const Writer = struct {...@@ -425,7 +425,7 @@ const Writer = struct {
425 }425 }
426426
427 fn writeUnionInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {427 fn writeUnionInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
428 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;428 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
429 const extra = w.air.extraData(Air.UnionInit, ty_pl.payload).data;429 const extra = w.air.extraData(Air.UnionInit, ty_pl.payload).data;
430430
431 try s.print("{d}, ", .{extra.field_index});431 try s.print("{d}, ", .{extra.field_index});
...@@ -433,7 +433,7 @@ const Writer = struct {...@@ -433,7 +433,7 @@ const Writer = struct {
433 }433 }
434434
435 fn writeStructField(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {435 fn writeStructField(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
436 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;436 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
437 const extra = w.air.extraData(Air.StructField, ty_pl.payload).data;437 const extra = w.air.extraData(Air.StructField, ty_pl.payload).data;
438438
439 try w.writeOperand(s, inst, 0, extra.struct_operand);439 try w.writeOperand(s, inst, 0, extra.struct_operand);
...@@ -442,10 +442,10 @@ const Writer = struct {...@@ -442,10 +442,10 @@ const Writer = struct {
442442
443 fn writeTyPlBin(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {443 fn writeTyPlBin(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
444 const data = w.air.instructions.items(.data);444 const data = w.air.instructions.items(.data);
445 const ty_pl = data[inst].ty_pl;445 const ty_pl = data[@intFromEnum(inst)].ty_pl;
446 const extra = w.air.extraData(Air.Bin, ty_pl.payload).data;446 const extra = w.air.extraData(Air.Bin, ty_pl.payload).data;
447447
448 const inst_ty = w.air.getRefType(data[inst].ty_pl.ty);448 const inst_ty = data[@intFromEnum(inst)].ty_pl.ty.toType();
449 try w.writeType(s, inst_ty);449 try w.writeType(s, inst_ty);
450 try s.writeAll(", ");450 try s.writeAll(", ");
451 try w.writeOperand(s, inst, 0, extra.lhs);451 try w.writeOperand(s, inst, 0, extra.lhs);
...@@ -454,7 +454,7 @@ const Writer = struct {...@@ -454,7 +454,7 @@ const Writer = struct {
454 }454 }
455455
456 fn writeCmpxchg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {456 fn writeCmpxchg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
457 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;457 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
458 const extra = w.air.extraData(Air.Cmpxchg, ty_pl.payload).data;458 const extra = w.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
459459
460 try w.writeOperand(s, inst, 0, extra.ptr);460 try w.writeOperand(s, inst, 0, extra.ptr);
...@@ -468,7 +468,7 @@ const Writer = struct {...@@ -468,7 +468,7 @@ const Writer = struct {
468 }468 }
469469
470 fn writeMulAdd(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {470 fn writeMulAdd(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
471 const pl_op = w.air.instructions.items(.data)[inst].pl_op;471 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
472 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;472 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
473473
474 try w.writeOperand(s, inst, 0, extra.lhs);474 try w.writeOperand(s, inst, 0, extra.lhs);
...@@ -479,7 +479,7 @@ const Writer = struct {...@@ -479,7 +479,7 @@ const Writer = struct {
479 }479 }
480480
481 fn writeShuffle(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {481 fn writeShuffle(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
482 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;482 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
483 const extra = w.air.extraData(Air.Shuffle, ty_pl.payload).data;483 const extra = w.air.extraData(Air.Shuffle, ty_pl.payload).data;
484484
485 try w.writeOperand(s, inst, 0, extra.a);485 try w.writeOperand(s, inst, 0, extra.a);
...@@ -490,7 +490,7 @@ const Writer = struct {...@@ -490,7 +490,7 @@ const Writer = struct {
490490
491 fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {491 fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
492 const mod = w.module;492 const mod = w.module;
493 const pl_op = w.air.instructions.items(.data)[inst].pl_op;493 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
494 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;494 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
495495
496 const elem_ty = w.typeOfIndex(inst).childType(mod);496 const elem_ty = w.typeOfIndex(inst).childType(mod);
...@@ -504,14 +504,14 @@ const Writer = struct {...@@ -504,14 +504,14 @@ const Writer = struct {
504 }504 }
505505
506 fn writeReduce(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {506 fn writeReduce(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
507 const reduce = w.air.instructions.items(.data)[inst].reduce;507 const reduce = w.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
508508
509 try w.writeOperand(s, inst, 0, reduce.operand);509 try w.writeOperand(s, inst, 0, reduce.operand);
510 try s.print(", {s}", .{@tagName(reduce.operation)});510 try s.print(", {s}", .{@tagName(reduce.operation)});
511 }511 }
512512
513 fn writeCmpVector(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {513 fn writeCmpVector(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
514 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;514 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
515 const extra = w.air.extraData(Air.VectorCmp, ty_pl.payload).data;515 const extra = w.air.extraData(Air.VectorCmp, ty_pl.payload).data;
516516
517 try s.print("{s}, ", .{@tagName(extra.compareOperator())});517 try s.print("{s}, ", .{@tagName(extra.compareOperator())});
...@@ -521,7 +521,7 @@ const Writer = struct {...@@ -521,7 +521,7 @@ const Writer = struct {
521 }521 }
522522
523 fn writeVectorStoreElem(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {523 fn writeVectorStoreElem(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
524 const data = w.air.instructions.items(.data)[inst].vector_store_elem;524 const data = w.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
525 const extra = w.air.extraData(Air.VectorCmp, data.payload).data;525 const extra = w.air.extraData(Air.VectorCmp, data.payload).data;
526526
527 try w.writeOperand(s, inst, 0, data.vector_ptr);527 try w.writeOperand(s, inst, 0, data.vector_ptr);
...@@ -532,20 +532,20 @@ const Writer = struct {...@@ -532,20 +532,20 @@ const Writer = struct {
532 }532 }
533533
534 fn writeFence(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {534 fn writeFence(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
535 const atomic_order = w.air.instructions.items(.data)[inst].fence;535 const atomic_order = w.air.instructions.items(.data)[@intFromEnum(inst)].fence;
536536
537 try s.print("{s}", .{@tagName(atomic_order)});537 try s.print("{s}", .{@tagName(atomic_order)});
538 }538 }
539539
540 fn writeAtomicLoad(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {540 fn writeAtomicLoad(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
541 const atomic_load = w.air.instructions.items(.data)[inst].atomic_load;541 const atomic_load = w.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
542542
543 try w.writeOperand(s, inst, 0, atomic_load.ptr);543 try w.writeOperand(s, inst, 0, atomic_load.ptr);
544 try s.print(", {s}", .{@tagName(atomic_load.order)});544 try s.print(", {s}", .{@tagName(atomic_load.order)});
545 }545 }
546546
547 fn writePrefetch(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {547 fn writePrefetch(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
548 const prefetch = w.air.instructions.items(.data)[inst].prefetch;548 const prefetch = w.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
549549
550 try w.writeOperand(s, inst, 0, prefetch.ptr);550 try w.writeOperand(s, inst, 0, prefetch.ptr);
551 try s.print(", {s}, {d}, {s}", .{551 try s.print(", {s}, {d}, {s}", .{
...@@ -559,7 +559,7 @@ const Writer = struct {...@@ -559,7 +559,7 @@ const Writer = struct {
559 inst: Air.Inst.Index,559 inst: Air.Inst.Index,
560 order: std.builtin.AtomicOrder,560 order: std.builtin.AtomicOrder,
561 ) @TypeOf(s).Error!void {561 ) @TypeOf(s).Error!void {
562 const bin_op = w.air.instructions.items(.data)[inst].bin_op;562 const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
563 try w.writeOperand(s, inst, 0, bin_op.lhs);563 try w.writeOperand(s, inst, 0, bin_op.lhs);
564 try s.writeAll(", ");564 try s.writeAll(", ");
565 try w.writeOperand(s, inst, 1, bin_op.rhs);565 try w.writeOperand(s, inst, 1, bin_op.rhs);
...@@ -567,7 +567,7 @@ const Writer = struct {...@@ -567,7 +567,7 @@ const Writer = struct {
567 }567 }
568568
569 fn writeAtomicRmw(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {569 fn writeAtomicRmw(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
570 const pl_op = w.air.instructions.items(.data)[inst].pl_op;570 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
571 const extra = w.air.extraData(Air.AtomicRmw, pl_op.payload).data;571 const extra = w.air.extraData(Air.AtomicRmw, pl_op.payload).data;
572572
573 try w.writeOperand(s, inst, 0, pl_op.operand);573 try w.writeOperand(s, inst, 0, pl_op.operand);
...@@ -577,7 +577,7 @@ const Writer = struct {...@@ -577,7 +577,7 @@ const Writer = struct {
577 }577 }
578578
579 fn writeFieldParentPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {579 fn writeFieldParentPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
580 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;580 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
581 const extra = w.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;581 const extra = w.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
582582
583 try w.writeOperand(s, inst, 0, extra.field_ptr);583 try w.writeOperand(s, inst, 0, extra.field_ptr);
...@@ -585,7 +585,7 @@ const Writer = struct {...@@ -585,7 +585,7 @@ const Writer = struct {
585 }585 }
586586
587 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {587 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
588 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;588 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
589 const extra = w.air.extraData(Air.Asm, ty_pl.payload);589 const extra = w.air.extraData(Air.Asm, ty_pl.payload);
590 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;590 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
591 const clobbers_len = @as(u31, @truncate(extra.data.flags));591 const clobbers_len = @as(u31, @truncate(extra.data.flags));
...@@ -658,26 +658,26 @@ const Writer = struct {...@@ -658,26 +658,26 @@ const Writer = struct {
658 }658 }
659659
660 fn writeDbgStmt(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {660 fn writeDbgStmt(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
661 const dbg_stmt = w.air.instructions.items(.data)[inst].dbg_stmt;661 const dbg_stmt = w.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
662 try s.print("{d}:{d}", .{ dbg_stmt.line + 1, dbg_stmt.column + 1 });662 try s.print("{d}:{d}", .{ dbg_stmt.line + 1, dbg_stmt.column + 1 });
663 }663 }
664664
665 fn writeDbgInline(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {665 fn writeDbgInline(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
666 const ty_fn = w.air.instructions.items(.data)[inst].ty_fn;666 const ty_fn = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
667 const func_index = ty_fn.func;667 const func_index = ty_fn.func;
668 const owner_decl = w.module.funcOwnerDeclPtr(func_index);668 const owner_decl = w.module.funcOwnerDeclPtr(func_index);
669 try s.print("{}", .{owner_decl.name.fmt(&w.module.intern_pool)});669 try s.print("{}", .{owner_decl.name.fmt(&w.module.intern_pool)});
670 }670 }
671671
672 fn writeDbgVar(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {672 fn writeDbgVar(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
673 const pl_op = w.air.instructions.items(.data)[inst].pl_op;673 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
674 try w.writeOperand(s, inst, 0, pl_op.operand);674 try w.writeOperand(s, inst, 0, pl_op.operand);
675 const name = w.air.nullTerminatedString(pl_op.payload);675 const name = w.air.nullTerminatedString(pl_op.payload);
676 try s.print(", \"{}\"", .{std.zig.fmtEscapes(name)});676 try s.print(", \"{}\"", .{std.zig.fmtEscapes(name)});
677 }677 }
678678
679 fn writeCall(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {679 fn writeCall(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
680 const pl_op = w.air.instructions.items(.data)[inst].pl_op;680 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
681 const extra = w.air.extraData(Air.Call, pl_op.payload);681 const extra = w.air.extraData(Air.Call, pl_op.payload);
682 const args = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[extra.end..][0..extra.data.args_len]));682 const args = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[extra.end..][0..extra.data.args_len]));
683 try w.writeOperand(s, inst, 0, pl_op.operand);683 try w.writeOperand(s, inst, 0, pl_op.operand);
...@@ -690,16 +690,16 @@ const Writer = struct {...@@ -690,16 +690,16 @@ const Writer = struct {
690 }690 }
691691
692 fn writeBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {692 fn writeBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
693 const br = w.air.instructions.items(.data)[inst].br;693 const br = w.air.instructions.items(.data)[@intFromEnum(inst)].br;
694 try w.writeInstIndex(s, br.block_inst, false);694 try w.writeInstIndex(s, br.block_inst, false);
695 try s.writeAll(", ");695 try s.writeAll(", ");
696 try w.writeOperand(s, inst, 0, br.operand);696 try w.writeOperand(s, inst, 0, br.operand);
697 }697 }
698698
699 fn writeTry(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {699 fn writeTry(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
700 const pl_op = w.air.instructions.items(.data)[inst].pl_op;700 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
701 const extra = w.air.extraData(Air.Try, pl_op.payload);701 const extra = w.air.extraData(Air.Try, pl_op.payload);
702 const body = w.air.extra[extra.end..][0..extra.data.body_len];702 const body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end..][0..extra.data.body_len]);
703 const liveness_condbr = if (w.liveness) |liveness|703 const liveness_condbr = if (w.liveness) |liveness|
704 liveness.getCondBr(inst)704 liveness.getCondBr(inst)
705 else705 else
...@@ -731,9 +731,9 @@ const Writer = struct {...@@ -731,9 +731,9 @@ const Writer = struct {
731 }731 }
732732
733 fn writeTryPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {733 fn writeTryPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
734 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;734 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
735 const extra = w.air.extraData(Air.TryPtr, ty_pl.payload);735 const extra = w.air.extraData(Air.TryPtr, ty_pl.payload);
736 const body = w.air.extra[extra.end..][0..extra.data.body_len];736 const body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end..][0..extra.data.body_len]);
737 const liveness_condbr = if (w.liveness) |liveness|737 const liveness_condbr = if (w.liveness) |liveness|
738 liveness.getCondBr(inst)738 liveness.getCondBr(inst)
739 else739 else
...@@ -742,7 +742,7 @@ const Writer = struct {...@@ -742,7 +742,7 @@ const Writer = struct {
742 try w.writeOperand(s, inst, 0, extra.data.ptr);742 try w.writeOperand(s, inst, 0, extra.data.ptr);
743743
744 try s.writeAll(", ");744 try s.writeAll(", ");
745 try w.writeType(s, w.air.getRefType(ty_pl.ty));745 try w.writeType(s, ty_pl.ty.toType());
746 if (w.skip_body) return s.writeAll(", ...");746 if (w.skip_body) return s.writeAll(", ...");
747 try s.writeAll(", {\n");747 try s.writeAll(", {\n");
748 const old_indent = w.indent;748 const old_indent = w.indent;
...@@ -768,10 +768,10 @@ const Writer = struct {...@@ -768,10 +768,10 @@ const Writer = struct {
768 }768 }
769769
770 fn writeCondBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {770 fn writeCondBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
771 const pl_op = w.air.instructions.items(.data)[inst].pl_op;771 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
772 const extra = w.air.extraData(Air.CondBr, pl_op.payload);772 const extra = w.air.extraData(Air.CondBr, pl_op.payload);
773 const then_body = w.air.extra[extra.end..][0..extra.data.then_body_len];773 const then_body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end..][0..extra.data.then_body_len]);
774 const else_body = w.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];774 const else_body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
775 const liveness_condbr = if (w.liveness) |liveness|775 const liveness_condbr = if (w.liveness) |liveness|
776 liveness.getCondBr(inst)776 liveness.getCondBr(inst)
777 else777 else
...@@ -813,7 +813,7 @@ const Writer = struct {...@@ -813,7 +813,7 @@ const Writer = struct {
813 }813 }
814814
815 fn writeSwitchBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {815 fn writeSwitchBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
816 const pl_op = w.air.instructions.items(.data)[inst].pl_op;816 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
817 const switch_br = w.air.extraData(Air.SwitchBr, pl_op.payload);817 const switch_br = w.air.extraData(Air.SwitchBr, pl_op.payload);
818 const liveness = if (w.liveness) |liveness|818 const liveness = if (w.liveness) |liveness|
819 liveness.getSwitchBr(w.gpa, inst, switch_br.data.cases_len + 1) catch819 liveness.getSwitchBr(w.gpa, inst, switch_br.data.cases_len + 1) catch
...@@ -836,7 +836,7 @@ const Writer = struct {...@@ -836,7 +836,7 @@ const Writer = struct {
836 while (case_i < switch_br.data.cases_len) : (case_i += 1) {836 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
837 const case = w.air.extraData(Air.SwitchBr.Case, extra_index);837 const case = w.air.extraData(Air.SwitchBr.Case, extra_index);
838 const items = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[case.end..][0..case.data.items_len]));838 const items = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[case.end..][0..case.data.items_len]));
839 const case_body = w.air.extra[case.end + items.len ..][0..case.data.body_len];839 const case_body: []const Air.Inst.Index = @ptrCast(w.air.extra[case.end + items.len ..][0..case.data.body_len]);
840 extra_index = case.end + case.data.items_len + case_body.len;840 extra_index = case.end + case.data.items_len + case_body.len;
841841
842 try s.writeAll(", [");842 try s.writeAll(", [");
...@@ -863,7 +863,7 @@ const Writer = struct {...@@ -863,7 +863,7 @@ const Writer = struct {
863 try s.writeAll("}");863 try s.writeAll("}");
864 }864 }
865865
866 const else_body = w.air.extra[extra_index..][0..switch_br.data.else_body_len];866 const else_body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra_index..][0..switch_br.data.else_body_len]);
867 if (else_body.len != 0) {867 if (else_body.len != 0) {
868 try s.writeAll(", else => {\n");868 try s.writeAll(", else => {\n");
869 w.indent += 2;869 w.indent += 2;
...@@ -889,18 +889,18 @@ const Writer = struct {...@@ -889,18 +889,18 @@ const Writer = struct {
889 }889 }
890890
891 fn writeWasmMemorySize(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {891 fn writeWasmMemorySize(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
892 const pl_op = w.air.instructions.items(.data)[inst].pl_op;892 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
893 try s.print("{d}", .{pl_op.payload});893 try s.print("{d}", .{pl_op.payload});
894 }894 }
895895
896 fn writeWasmMemoryGrow(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {896 fn writeWasmMemoryGrow(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
897 const pl_op = w.air.instructions.items(.data)[inst].pl_op;897 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
898 try s.print("{d}, ", .{pl_op.payload});898 try s.print("{d}, ", .{pl_op.payload});
899 try w.writeOperand(s, inst, 0, pl_op.operand);899 try w.writeOperand(s, inst, 0, pl_op.operand);
900 }900 }
901901
902 fn writeWorkDimension(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {902 fn writeWorkDimension(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
903 const pl_op = w.air.instructions.items(.data)[inst].pl_op;903 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
904 try s.print("{d}", .{pl_op.payload});904 try s.print("{d}", .{pl_op.payload});
905 }905 }
906906
...@@ -938,7 +938,7 @@ const Writer = struct {...@@ -938,7 +938,7 @@ const Writer = struct {
938 ) @TypeOf(s).Error!void {938 ) @TypeOf(s).Error!void {
939 if (@intFromEnum(operand) < InternPool.static_len) {939 if (@intFromEnum(operand) < InternPool.static_len) {
940 return s.print("@{}", .{operand});940 return s.print("@{}", .{operand});
941 } else if (Air.refToInterned(operand)) |ip_index| {941 } else if (operand.toInterned()) |ip_index| {
942 const mod = w.module;942 const mod = w.module;
943 const ty = Type.fromInterned(mod.intern_pool.indexToKey(ip_index).typeOf());943 const ty = Type.fromInterned(mod.intern_pool.indexToKey(ip_index).typeOf());
944 try s.print("<{}, {}>", .{944 try s.print("<{}, {}>", .{
...@@ -946,7 +946,7 @@ const Writer = struct {...@@ -946,7 +946,7 @@ const Writer = struct {
946 Value.fromInterned(ip_index).fmtValue(ty, mod),946 Value.fromInterned(ip_index).fmtValue(ty, mod),
947 });947 });
948 } else {948 } else {
949 return w.writeInstIndex(s, Air.refToIndex(operand).?, dies);949 return w.writeInstIndex(s, operand.toIndex().?, dies);
950 }950 }
951 }951 }
952952