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 {
875875 };
876876
877877 /// 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
880892 /// Either a reference to a value stored in the InternPool, or a reference to an AIR instruction.
881893 /// 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 {
976988 /// value and may instead be used as a sentinel to indicate null.
977989 none = @intFromEnum(InternPool.Index.none),
978990 _,
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 }
9791026 };
9801027
9811028 /// All instructions have an 8-byte payload, which is contained within
......@@ -1216,20 +1263,20 @@ pub const UnionInit = struct {
12161263pub fn getMainBody(air: Air) []const Air.Inst.Index {
12171264 const body_index = air.extra[@intFromEnum(ExtraIndex.main_block)];
12181265 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]);
12201267}
12211268
12221269pub 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| {
12241271 return Type.fromInterned(ip.typeOf(ip_index));
12251272 } else {
1226 return air.typeOfIndex(refToIndex(inst).?, ip);
1273 return air.typeOfIndex(inst.toIndex().?, ip);
12271274 }
12281275}
12291276
12301277pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
12311278 const datas = air.instructions.items(.data);
1232 switch (air.instructions.items(.tag)[inst]) {
1279 switch (air.instructions.items(.tag)[@intFromEnum(inst)]) {
12331280 .add,
12341281 .add_safe,
12351282 .add_wrap,
......@@ -1269,7 +1316,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
12691316 .div_exact_optimized,
12701317 .rem_optimized,
12711318 .mod_optimized,
1272 => return air.typeOf(datas[inst].bin_op.lhs, ip),
1319 => return air.typeOf(datas[@intFromEnum(inst)].bin_op.lhs, ip),
12731320
12741321 .sqrt,
12751322 .sin,
......@@ -1286,7 +1333,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
12861333 .trunc_float,
12871334 .neg,
12881335 .neg_optimized,
1289 => return air.typeOf(datas[inst].un_op, ip),
1336 => return air.typeOf(datas[@intFromEnum(inst)].un_op, ip),
12901337
12911338 .cmp_lt,
12921339 .cmp_lte,
......@@ -1317,9 +1364,9 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
13171364 .ret_ptr,
13181365 .err_return_trace,
13191366 .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
13241371 .assembly,
13251372 .block,
......@@ -1343,7 +1390,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
13431390 .ptr_add,
13441391 .ptr_sub,
13451392 .try_ptr,
1346 => return air.getRefType(datas[inst].ty_pl.ty),
1393 => return datas[@intFromEnum(inst)].ty_pl.ty.toType(),
13471394
13481395 .not,
13491396 .bitcast,
......@@ -1385,7 +1432,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
13851432 .c_va_arg,
13861433 .c_va_copy,
13871434 .abs,
1388 => return air.getRefType(datas[inst].ty_op.ty),
1435 => return datas[@intFromEnum(inst)].ty_op.ty.toType(),
13891436
13901437 .loop,
13911438 .br,
......@@ -1437,36 +1484,36 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14371484 .tag_name, .error_name => return Type.slice_const_u8_sentinel_0,
14381485
14391486 .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);
14411488 return Type.fromInterned(ip.funcTypeReturnType(callee_ty.toIntern()));
14421489 },
14431490
14441491 .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);
14461493 return ptr_ty.childTypeIp(ip);
14471494 },
14481495 .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);
14501497 return ptr_ty.childTypeIp(ip);
14511498 },
14521499 .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);
14541501 return ptr_ty.childTypeIp(ip);
14551502 },
14561503
14571504 .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);
14591506 return Type.fromInterned(ip.indexToKey(operand_ty.ip_index).vector_type.child);
14601507 },
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),
14631510 .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;
14651512 return air.typeOf(extra.lhs, ip);
14661513 },
14671514
14681515 .@"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);
14701517 return Type.fromInterned(ip.indexToKey(err_union_ty.ip_index).error_union_type.payload_type);
14711518 },
14721519
......@@ -1480,11 +1527,6 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14801527 }
14811528}
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
14881530/// Returns the requested data, as well as the new index which is at the start of the
14891531/// trailers for the object.
14901532pub 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 {
15131555 air.* = undefined;
15141556}
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
15311558pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {
15321559 return switch (ip_index) {
15331560 .var_args_param_type => .var_args_param_type,
......@@ -1539,31 +1566,12 @@ pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {
15391566 };
15401567}
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
15611569/// Returns `null` if runtime-known.
15621570pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {
1563 if (refToInterned(inst)) |ip_index| {
1571 if (inst.toInterned()) |ip_index| {
15641572 return Value.fromInterned(ip_index);
15651573 }
1566 const index = refToIndex(inst).?;
1574 const index = inst.toIndex().?;
15671575 return air.typeOfIndex(index, &mod.intern_pool).onePossibleValue(mod);
15681576}
15691577
......@@ -1581,8 +1589,8 @@ pub fn nullTerminatedString(air: Air, index: usize) [:0]const u8 {
15811589/// lowered, and Liveness determines its result is unused, backends should
15821590/// avoid lowering it.
15831591pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
1584 const data = air.instructions.items(.data)[inst];
1585 return switch (air.instructions.items(.tag)[inst]) {
1592 const data = air.instructions.items(.data)[@intFromEnum(inst)];
1593 return switch (air.instructions.items(.tag)[@intFromEnum(inst)]) {
15861594 .arg,
15871595 .block,
15881596 .loop,
src/Liveness.zig+117-117
......@@ -177,31 +177,31 @@ pub fn analyze(gpa: Allocator, air: Air, intern_pool: *const InternPool) Allocat
177177}
178178
179179pub 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);
181181 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))));
183183}
184184
185185pub 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);
187187 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)));
189189 return (l.tomb_bits[usize_index] & mask) != 0;
190190}
191191
192192pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool {
193193 assert(operand < bpi - 1);
194 const usize_index = (inst * bpi) / @bitSizeOf(usize);
194 const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize);
195195 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));
197197 return (l.tomb_bits[usize_index] & mask) != 0;
198198}
199199
200200pub fn clearOperandDeath(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) void {
201201 assert(operand < bpi - 1);
202 const usize_index = (inst * bpi) / @bitSizeOf(usize);
202 const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize);
203203 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));
205205 l.tomb_bits[usize_index] &= ~mask;
206206}
207207
......@@ -229,8 +229,8 @@ pub fn categorizeOperand(
229229) OperandCategory {
230230 const air_tags = air.instructions.items(.tag);
231231 const air_datas = air.instructions.items(.data);
232 const operand_ref = Air.indexToRef(operand);
233 switch (air_tags[inst]) {
232 const operand_ref = operand.toRef();
233 switch (air_tags[@intFromEnum(inst)]) {
234234 .add,
235235 .add_safe,
236236 .add_wrap,
......@@ -287,7 +287,7 @@ pub fn categorizeOperand(
287287 .cmp_gt_optimized,
288288 .cmp_neq_optimized,
289289 => {
290 const o = air_datas[inst].bin_op;
290 const o = air_datas[@intFromEnum(inst)].bin_op;
291291 if (o.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
292292 if (o.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
293293 return .none;
......@@ -304,14 +304,14 @@ pub fn categorizeOperand(
304304 .memset_safe,
305305 .memcpy,
306306 => {
307 const o = air_datas[inst].bin_op;
307 const o = air_datas[@intFromEnum(inst)].bin_op;
308308 if (o.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
309309 if (o.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write);
310310 return .write;
311311 },
312312
313313 .vector_store_elem => {
314 const o = air_datas[inst].vector_store_elem;
314 const o = air_datas[@intFromEnum(inst)].vector_store_elem;
315315 const extra = air.extraData(Air.Bin, o.payload).data;
316316 if (o.vector_ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
317317 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
......@@ -386,7 +386,7 @@ pub fn categorizeOperand(
386386 .c_va_copy,
387387 .abs,
388388 => {
389 const o = air_datas[inst].ty_op;
389 const o = air_datas[@intFromEnum(inst)].ty_op;
390390 if (o.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
391391 return .none;
392392 },
......@@ -394,7 +394,7 @@ pub fn categorizeOperand(
394394 .optional_payload_ptr_set,
395395 .errunion_payload_ptr_set,
396396 => {
397 const o = air_datas[inst].ty_op;
397 const o = air_datas[@intFromEnum(inst)].ty_op;
398398 if (o.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
399399 return .write;
400400 },
......@@ -429,7 +429,7 @@ pub fn categorizeOperand(
429429 .cmp_lt_errors_len,
430430 .c_va_end,
431431 => {
432 const o = air_datas[inst].un_op;
432 const o = air_datas[@intFromEnum(inst)].un_op;
433433 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
434434 return .none;
435435 },
......@@ -437,13 +437,13 @@ pub fn categorizeOperand(
437437 .ret,
438438 .ret_load,
439439 => {
440 const o = air_datas[inst].un_op;
440 const o = air_datas[@intFromEnum(inst)].un_op;
441441 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .noret);
442442 return .noret;
443443 },
444444
445445 .set_err_return_trace => {
446 const o = air_datas[inst].un_op;
446 const o = air_datas[@intFromEnum(inst)].un_op;
447447 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
448448 return .write;
449449 },
......@@ -458,7 +458,7 @@ pub fn categorizeOperand(
458458 .slice_elem_ptr,
459459 .slice,
460460 => {
461 const ty_pl = air_datas[inst].ty_pl;
461 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;
462462 const extra = air.extraData(Air.Bin, ty_pl.payload).data;
463463 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
464464 if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
......@@ -468,19 +468,19 @@ pub fn categorizeOperand(
468468 .dbg_var_ptr,
469469 .dbg_var_val,
470470 => {
471 const o = air_datas[inst].pl_op.operand;
471 const o = air_datas[@intFromEnum(inst)].pl_op.operand;
472472 if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
473473 return .none;
474474 },
475475
476476 .prefetch => {
477 const prefetch = air_datas[inst].prefetch;
477 const prefetch = air_datas[@intFromEnum(inst)].prefetch;
478478 if (prefetch.ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
479479 return .none;
480480 },
481481
482482 .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;
484484 const callee = inst_data.operand;
485485 const extra = air.extraData(Air.Call, inst_data.payload);
486486 const args = @as([]const Air.Inst.Ref, @ptrCast(air.extra[extra.end..][0..extra.data.args_len]));
......@@ -507,7 +507,7 @@ pub fn categorizeOperand(
507507 return .write;
508508 },
509509 .select => {
510 const pl_op = air_datas[inst].pl_op;
510 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
511511 const extra = air.extraData(Air.Bin, pl_op.payload).data;
512512 if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
513513 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
......@@ -515,25 +515,25 @@ pub fn categorizeOperand(
515515 return .none;
516516 },
517517 .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;
519519 if (extra.a == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
520520 if (extra.b == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
521521 return .none;
522522 },
523523 .reduce, .reduce_optimized => {
524 const reduce = air_datas[inst].reduce;
524 const reduce = air_datas[@intFromEnum(inst)].reduce;
525525 if (reduce.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
526526 return .none;
527527 },
528528 .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;
530530 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
531531 if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
532532 return .none;
533533 },
534534 .aggregate_init => {
535 const ty_pl = air_datas[inst].ty_pl;
536 const aggregate_ty = air.getRefType(ty_pl.ty);
535 const ty_pl = air_datas[@intFromEnum(inst)].ty_pl;
536 const aggregate_ty = ty_pl.ty.toType();
537537 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
538538 const elements = @as([]const Air.Inst.Ref, @ptrCast(air.extra[ty_pl.payload..][0..len]));
539539
......@@ -555,29 +555,29 @@ pub fn categorizeOperand(
555555 return .write;
556556 },
557557 .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;
559559 if (extra.init == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
560560 return .none;
561561 },
562562 .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;
564564 if (extra.struct_operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
565565 return .none;
566566 },
567567 .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;
569569 if (extra.field_ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
570570 return .none;
571571 },
572572 .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;
574574 if (extra.ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
575575 if (extra.expected_value == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write);
576576 if (extra.new_value == operand_ref) return matchOperandSmallIndex(l, inst, 2, .write);
577577 return .write;
578578 },
579579 .mul_add => {
580 const pl_op = air_datas[inst].pl_op;
580 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
581581 const extra = air.extraData(Air.Bin, pl_op.payload).data;
582582 if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
583583 if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none);
......@@ -585,12 +585,12 @@ pub fn categorizeOperand(
585585 return .none;
586586 },
587587 .atomic_load => {
588 const ptr = air_datas[inst].atomic_load.ptr;
588 const ptr = air_datas[@intFromEnum(inst)].atomic_load.ptr;
589589 if (ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
590590 return .none;
591591 },
592592 .atomic_rmw => {
593 const pl_op = air_datas[inst].pl_op;
593 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
594594 const extra = air.extraData(Air.AtomicRmw, pl_op.payload).data;
595595 if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write);
596596 if (extra.operand == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write);
......@@ -598,7 +598,7 @@ pub fn categorizeOperand(
598598 },
599599
600600 .br => {
601 const br = air_datas[inst].br;
601 const br = air_datas[@intFromEnum(inst)].br;
602602 if (br.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .noret);
603603 return .noret;
604604 },
......@@ -606,16 +606,16 @@ pub fn categorizeOperand(
606606 return .complex;
607607 },
608608 .block => {
609 const extra = air.extraData(Air.Block, air_datas[inst].ty_pl.payload);
610 const body = air.extra[extra.end..][0..extra.data.body_len];
609 const extra = air.extraData(Air.Block, air_datas[@intFromEnum(inst)].ty_pl.payload);
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) {
613613 // Peephole optimization for "panic-like" conditionals, which have
614614 // one empty branch and another which calls a `noreturn` function.
615615 // This allows us to infer that safety checks do not modify memory,
616616 // 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;
619619 const cond_extra = air.extraData(Air.CondBr, inst_data.payload);
620620 if (inst_data.operand == operand_ref and operandDies(l, body[0], 0))
621621 return .tomb;
......@@ -623,21 +623,21 @@ pub fn categorizeOperand(
623623 if (cond_extra.data.then_body_len > 2 or cond_extra.data.else_body_len > 2)
624624 return .complex;
625625
626 const then_body = 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];
628 if (then_body.len > 1 and air_tags[then_body[1]] != .unreach)
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: []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[@intFromEnum(then_body[1])] != .unreach)
629629 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)
631631 return .complex;
632632
633633 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| {
635635 if (l.categorizeOperand(air, cond_inst, operand, ip) == .tomb)
636636 operand_live = false;
637637
638 switch (air_tags[cond_inst]) {
638 switch (air_tags[@intFromEnum(cond_inst)]) {
639639 .br => { // Breaks immediately back to block
640 const br = air_datas[cond_inst].br;
640 const br = air_datas[@intFromEnum(cond_inst)].br;
641641 if (br.block_inst != inst)
642642 return .complex;
643643 },
......@@ -666,7 +666,7 @@ pub fn categorizeOperand(
666666 return .complex;
667667 },
668668 .wasm_memory_grow => {
669 const pl_op = air_datas[inst].pl_op;
669 const pl_op = air_datas[@intFromEnum(inst)].pl_op;
670670 if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
671671 return .none;
672672 },
......@@ -701,11 +701,11 @@ pub fn getCondBr(l: Liveness, inst: Air.Inst.Index) CondBrSlices {
701701 index += 1;
702702 const else_death_count = l.extra[index];
703703 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]);
705705 index += then_death_count;
706706 return .{
707707 .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]),
709709 };
710710}
711711
......@@ -731,13 +731,13 @@ pub fn getSwitchBr(l: Liveness, gpa: Allocator, inst: Air.Inst.Index, cases_len:
731731 while (case_i < cases_len - 1) : (case_i += 1) {
732732 const case_death_count: u32 = l.extra[index];
733733 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]);
735735 index += case_death_count;
736736 deaths.appendAssumeCapacity(case_deaths);
737737 }
738738 {
739739 // 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]);
741741 deaths.appendAssumeCapacity(else_deaths);
742742 }
743743 return SwitchBrTable{
......@@ -756,7 +756,7 @@ pub fn getBlock(l: Liveness, inst: Air.Inst.Index) BlockSlices {
756756 .deaths = &.{},
757757 };
758758 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]);
760760 return .{
761761 .deaths = deaths,
762762 };
......@@ -883,7 +883,7 @@ fn analyzeInst(
883883 const inst_tags = a.air.instructions.items(.tag);
884884 const inst_datas = a.air.instructions.items(.data);
885885
886 switch (inst_tags[inst]) {
886 switch (inst_tags[@intFromEnum(inst)]) {
887887 .add,
888888 .add_safe,
889889 .add_optimized,
......@@ -949,12 +949,12 @@ fn analyzeInst(
949949 .memset_safe,
950950 .memcpy,
951951 => {
952 const o = inst_datas[inst].bin_op;
952 const o = inst_datas[@intFromEnum(inst)].bin_op;
953953 return analyzeOperands(a, pass, data, inst, .{ o.lhs, o.rhs, .none });
954954 },
955955
956956 .vector_store_elem => {
957 const o = inst_datas[inst].vector_store_elem;
957 const o = inst_datas[@intFromEnum(inst)].vector_store_elem;
958958 const extra = a.air.extraData(Air.Bin, o.payload).data;
959959 return analyzeOperands(a, pass, data, inst, .{ o.vector_ptr, extra.lhs, extra.rhs });
960960 },
......@@ -1029,7 +1029,7 @@ fn analyzeInst(
10291029 .c_va_copy,
10301030 .abs,
10311031 => {
1032 const o = inst_datas[inst].ty_op;
1032 const o = inst_datas[@intFromEnum(inst)].ty_op;
10331033 return analyzeOperands(a, pass, data, inst, .{ o.operand, .none, .none });
10341034 },
10351035
......@@ -1065,14 +1065,14 @@ fn analyzeInst(
10651065 .set_err_return_trace,
10661066 .c_va_end,
10671067 => {
1068 const operand = inst_datas[inst].un_op;
1068 const operand = inst_datas[@intFromEnum(inst)].un_op;
10691069 return analyzeOperands(a, pass, data, inst, .{ operand, .none, .none });
10701070 },
10711071
10721072 .ret,
10731073 .ret_load,
10741074 => {
1075 const operand = inst_datas[inst].un_op;
1075 const operand = inst_datas[@intFromEnum(inst)].un_op;
10761076 return analyzeFuncEnd(a, pass, data, inst, .{ operand, .none, .none });
10771077 },
10781078
......@@ -1086,7 +1086,7 @@ fn analyzeInst(
10861086 .slice_elem_ptr,
10871087 .slice,
10881088 => {
1089 const ty_pl = inst_datas[inst].ty_pl;
1089 const ty_pl = inst_datas[@intFromEnum(inst)].ty_pl;
10901090 const extra = a.air.extraData(Air.Bin, ty_pl.payload).data;
10911091 return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, .none });
10921092 },
......@@ -1094,17 +1094,17 @@ fn analyzeInst(
10941094 .dbg_var_ptr,
10951095 .dbg_var_val,
10961096 => {
1097 const operand = inst_datas[inst].pl_op.operand;
1097 const operand = inst_datas[@intFromEnum(inst)].pl_op.operand;
10981098 return analyzeOperands(a, pass, data, inst, .{ operand, .none, .none });
10991099 },
11001100
11011101 .prefetch => {
1102 const prefetch = inst_datas[inst].prefetch;
1102 const prefetch = inst_datas[@intFromEnum(inst)].prefetch;
11031103 return analyzeOperands(a, pass, data, inst, .{ prefetch.ptr, .none, .none });
11041104 },
11051105
11061106 .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;
11081108 const callee = inst_data.operand;
11091109 const extra = a.air.extraData(Air.Call, inst_data.payload);
11101110 const args = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra.end..][0..extra.data.args_len]));
......@@ -1126,25 +1126,25 @@ fn analyzeInst(
11261126 return big.finish();
11271127 },
11281128 .select => {
1129 const pl_op = inst_datas[inst].pl_op;
1129 const pl_op = inst_datas[@intFromEnum(inst)].pl_op;
11301130 const extra = a.air.extraData(Air.Bin, pl_op.payload).data;
11311131 return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, extra.lhs, extra.rhs });
11321132 },
11331133 .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;
11351135 return analyzeOperands(a, pass, data, inst, .{ extra.a, extra.b, .none });
11361136 },
11371137 .reduce, .reduce_optimized => {
1138 const reduce = inst_datas[inst].reduce;
1138 const reduce = inst_datas[@intFromEnum(inst)].reduce;
11391139 return analyzeOperands(a, pass, data, inst, .{ reduce.operand, .none, .none });
11401140 },
11411141 .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;
11431143 return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, .none });
11441144 },
11451145 .aggregate_init => {
1146 const ty_pl = inst_datas[inst].ty_pl;
1147 const aggregate_ty = a.air.getRefType(ty_pl.ty);
1146 const ty_pl = inst_datas[@intFromEnum(inst)].ty_pl;
1147 const aggregate_ty = ty_pl.ty.toType();
11481148 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
11491149 const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[ty_pl.payload..][0..len]));
11501150
......@@ -1164,32 +1164,32 @@ fn analyzeInst(
11641164 return big.finish();
11651165 },
11661166 .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;
11681168 return analyzeOperands(a, pass, data, inst, .{ extra.init, .none, .none });
11691169 },
11701170 .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;
11721172 return analyzeOperands(a, pass, data, inst, .{ extra.struct_operand, .none, .none });
11731173 },
11741174 .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;
11761176 return analyzeOperands(a, pass, data, inst, .{ extra.field_ptr, .none, .none });
11771177 },
11781178 .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;
11801180 return analyzeOperands(a, pass, data, inst, .{ extra.ptr, extra.expected_value, extra.new_value });
11811181 },
11821182 .mul_add => {
1183 const pl_op = inst_datas[inst].pl_op;
1183 const pl_op = inst_datas[@intFromEnum(inst)].pl_op;
11841184 const extra = a.air.extraData(Air.Bin, pl_op.payload).data;
11851185 return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, pl_op.operand });
11861186 },
11871187 .atomic_load => {
1188 const ptr = inst_datas[inst].atomic_load.ptr;
1188 const ptr = inst_datas[@intFromEnum(inst)].atomic_load.ptr;
11891189 return analyzeOperands(a, pass, data, inst, .{ ptr, .none, .none });
11901190 },
11911191 .atomic_rmw => {
1192 const pl_op = inst_datas[inst].pl_op;
1192 const pl_op = inst_datas[@intFromEnum(inst)].pl_op;
11931193 const extra = a.air.extraData(Air.AtomicRmw, pl_op.payload).data;
11941194 return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, extra.operand, .none });
11951195 },
......@@ -1197,7 +1197,7 @@ fn analyzeInst(
11971197 .br => return analyzeInstBr(a, pass, data, inst),
11981198
11991199 .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);
12011201 var extra_i: usize = extra.end;
12021202 const outputs = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra_i..][0..extra.data.outputs_len]));
12031203 extra_i += outputs.len;
......@@ -1246,7 +1246,7 @@ fn analyzeInst(
12461246 .switch_br => return analyzeInstSwitchBr(a, pass, data, inst),
12471247
12481248 .wasm_memory_grow => {
1249 const pl_op = inst_datas[inst].pl_op;
1249 const pl_op = inst_datas[@intFromEnum(inst)].pl_op;
12501250 return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, .none, .none });
12511251 },
12521252 }
......@@ -1270,20 +1270,20 @@ fn analyzeOperands(
12701270 _ = data.live_set.remove(inst);
12711271
12721272 for (operands) |op_ref| {
1273 const operand = Air.refToIndexAllowNone(op_ref) orelse continue;
1273 const operand = op_ref.toIndexAllowNone() orelse continue;
12741274 _ = try data.live_set.put(gpa, operand, {});
12751275 }
12761276 },
12771277
12781278 .main_analysis => {
1279 const usize_index = (inst * bpi) / @bitSizeOf(usize);
1279 const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize);
12801280
12811281 // This logic must synchronize with `will_die_immediately` in `AnalyzeBigOperands.init`.
12821282 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) });
12841284 break :blk false;
12851285 } else blk: {
1286 log.debug("[{}] %{}: immediate death", .{ pass, inst });
1286 log.debug("[{}] %{}: immediate death", .{ pass, @intFromEnum(inst) });
12871287 break :blk true;
12881288 };
12891289
......@@ -1299,19 +1299,19 @@ fn analyzeOperands(
12991299 while (i > 0) {
13001300 i -= 1;
13011301 const op_ref = operands[i];
1302 const operand = Air.refToIndexAllowNone(op_ref) orelse continue;
1302 const operand = op_ref.toIndexAllowNone() orelse continue;
13031303
13041304 const mask = @as(Bpi, 1) << @as(OperandInt, @intCast(i));
13051305
13061306 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 });
13081308 tomb_bits |= mask;
13091309 }
13101310 }
13111311 }
13121312
13131313 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));
13151315 },
13161316 }
13171317}
......@@ -1346,7 +1346,7 @@ fn analyzeInstBr(
13461346 inst: Air.Inst.Index,
13471347) !void {
13481348 const inst_datas = a.air.instructions.items(.data);
1349 const br = inst_datas[inst].br;
1349 const br = inst_datas[@intFromEnum(inst)].br;
13501350 const gpa = a.gpa;
13511351
13521352 switch (pass) {
......@@ -1373,9 +1373,9 @@ fn analyzeInstBlock(
13731373 inst: Air.Inst.Index,
13741374) !void {
13751375 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;
13771377 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
13801380 const gpa = a.gpa;
13811381
......@@ -1405,7 +1405,7 @@ fn analyzeInstBlock(
14051405
14061406 // If the block is noreturn, block deaths not only aren't useful, they're impossible to
14071407 // 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)) {
14091409 // The block kills the difference in the live sets
14101410 const block_scope = data.block_scopes.get(inst).?;
14111411 const num_deaths = data.live_set.count() - block_scope.live_set.count();
......@@ -1421,7 +1421,7 @@ fn analyzeInstBlock(
14211421 const alive = key.*;
14221422 if (!block_scope.live_set.contains(alive)) {
14231423 // Dies in block
1424 a.extra.appendAssumeCapacity(alive);
1424 a.extra.appendAssumeCapacity(@intFromEnum(alive));
14251425 measured_num += 1;
14261426 }
14271427 }
......@@ -1430,7 +1430,7 @@ fn analyzeInstBlock(
14301430 log.debug("[{}] %{}: block deaths are {}", .{
14311431 pass,
14321432 inst,
1433 fmtInstList(a.extra.items[extra_index + 1 ..][0..num_deaths]),
1433 fmtInstList(@ptrCast(a.extra.items[extra_index + 1 ..][0..num_deaths])),
14341434 });
14351435 }
14361436 },
......@@ -1444,8 +1444,8 @@ fn analyzeInstLoop(
14441444 inst: Air.Inst.Index,
14451445) !void {
14461446 const inst_datas = a.air.instructions.items(.data);
1447 const extra = a.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);
1448 const body = a.air.extra[extra.end..][0..extra.data.body_len];
1447 const extra = a.air.extraData(Air.Block, inst_datas[@intFromEnum(inst)].ty_pl.payload);
1448 const body: []const Air.Inst.Index = @ptrCast(a.air.extra[extra.end..][0..extra.data.body_len]);
14491449 const gpa = a.gpa;
14501450
14511451 try analyzeOperands(a, pass, data, inst, .{ .none, .none, .none });
......@@ -1469,7 +1469,7 @@ fn analyzeInstLoop(
14691469 var it = data.breaks.keyIterator();
14701470 while (it.next()) |key| {
14711471 const block_inst = key.*;
1472 a.extra.appendAssumeCapacity(block_inst);
1472 a.extra.appendAssumeCapacity(@intFromEnum(block_inst));
14731473 }
14741474 log.debug("[{}] %{}: includes breaks to {}", .{ pass, inst, fmtInstSet(&data.breaks) });
14751475
......@@ -1481,7 +1481,7 @@ fn analyzeInstLoop(
14811481 it = data.live_set.keyIterator();
14821482 while (it.next()) |key| {
14831483 const alive = key.*;
1484 a.extra.appendAssumeCapacity(alive);
1484 a.extra.appendAssumeCapacity(@intFromEnum(alive));
14851485 }
14861486 log.debug("[{}] %{}: maintain liveness of {}", .{ pass, inst, fmtInstSet(&data.live_set) });
14871487
......@@ -1506,15 +1506,15 @@ fn analyzeInstLoop(
15061506 const extra_idx = a.special.fetchRemove(inst).?.value; // remove because this data does not exist after analysis
15071507
15081508 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
15111511 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
15141514 // This is necessarily not in the same control flow branch, because loops are noreturn
15151515 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));
15181518 for (loop_live) |alive| {
15191519 data.live_set.putAssumeCapacity(alive, {});
15201520 }
......@@ -1551,25 +1551,25 @@ fn analyzeInstCondBr(
15511551 const gpa = a.gpa;
15521552
15531553 const extra = switch (inst_type) {
1554 .cond_br => a.air.extraData(Air.CondBr, inst_datas[inst].pl_op.payload),
1555 .@"try" => a.air.extraData(Air.Try, inst_datas[inst].pl_op.payload),
1556 .try_ptr => a.air.extraData(Air.TryPtr, inst_datas[inst].ty_pl.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[@intFromEnum(inst)].pl_op.payload),
1556 .try_ptr => a.air.extraData(Air.TryPtr, inst_datas[@intFromEnum(inst)].ty_pl.payload),
15571557 };
15581558
15591559 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,
15611561 .try_ptr => extra.data.ptr,
15621562 };
15631563
1564 const then_body = switch (inst_type) {
1565 .cond_br => a.air.extra[extra.end..][0..extra.data.then_body_len],
1566 else => {}, // we won't use this
1564 const then_body: []const Air.Inst.Index = switch (inst_type) {
1565 .cond_br => @ptrCast(a.air.extra[extra.end..][0..extra.data.then_body_len]),
1566 else => &.{}, // we won't use this
15671567 };
15681568
1569 const else_body = switch (inst_type) {
1569 const else_body: []const Air.Inst.Index = @ptrCast(switch (inst_type) {
15701570 .cond_br => a.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len],
15711571 .@"try", .try_ptr => a.air.extra[extra.end..][0..extra.data.body_len],
1572 };
1572 });
15731573
15741574 switch (pass) {
15751575 .loop_analysis => {
......@@ -1645,8 +1645,8 @@ fn analyzeInstCondBr(
16451645 .then_death_count = then_death_count,
16461646 .else_death_count = else_death_count,
16471647 });
1648 a.extra.appendSliceAssumeCapacity(then_mirrored_deaths.items);
1649 a.extra.appendSliceAssumeCapacity(else_mirrored_deaths.items);
1648 a.extra.appendSliceAssumeCapacity(@ptrCast(then_mirrored_deaths.items));
1649 a.extra.appendSliceAssumeCapacity(@ptrCast(else_mirrored_deaths.items));
16501650 try a.special.put(gpa, inst, extra_index);
16511651 },
16521652 }
......@@ -1661,7 +1661,7 @@ fn analyzeInstSwitchBr(
16611661 inst: Air.Inst.Index,
16621662) !void {
16631663 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;
16651665 const condition = pl_op.operand;
16661666 const switch_br = a.air.extraData(Air.SwitchBr, pl_op.payload);
16671667 const gpa = a.gpa;
......@@ -1672,12 +1672,12 @@ fn analyzeInstSwitchBr(
16721672 var air_extra_index: usize = switch_br.end;
16731673 for (0..ncases) |_| {
16741674 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]);
16761676 air_extra_index = case.end + case.data.items_len + case_body.len;
16771677 try analyzeBody(a, pass, data, case_body);
16781678 }
16791679 { // 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]);
16811681 try analyzeBody(a, pass, data, else_body);
16821682 }
16831683 },
......@@ -1698,13 +1698,13 @@ fn analyzeInstSwitchBr(
16981698 var air_extra_index: usize = switch_br.end;
16991699 for (case_live_sets[0..ncases]) |*live_set| {
17001700 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]);
17021702 air_extra_index = case.end + case.data.items_len + case_body.len;
17031703 try analyzeBody(a, pass, data, case_body);
17041704 live_set.* = data.live_set.move();
17051705 }
17061706 { // 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]);
17081708 try analyzeBody(a, pass, data, else_body);
17091709 case_live_sets[ncases] = data.live_set.move();
17101710 }
......@@ -1757,10 +1757,10 @@ fn analyzeInstSwitchBr(
17571757 const num = @as(u32, @intCast(mirrored.items.len));
17581758 try a.extra.ensureUnusedCapacity(gpa, num + 1);
17591759 a.extra.appendAssumeCapacity(num);
1760 a.extra.appendSliceAssumeCapacity(mirrored.items);
1760 a.extra.appendSliceAssumeCapacity(@ptrCast(mirrored.items));
17611761 }
17621762 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));
17641764 try a.special.put(gpa, inst, extra_index);
17651765 },
17661766 }
......@@ -1826,7 +1826,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18261826 return;
18271827 }
18281828
1829 const operand = Air.refToIndex(op_ref) orelse return;
1829 const operand = op_ref.toIndex() orelse return;
18301830
18311831 // If our result is unused and the instruction doesn't need to be lowered, backends will
18321832 // 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 {
3737 continue;
3838 }
3939
40 switch (tag[inst]) {
40 switch (tag[@intFromEnum(inst)]) {
4141 // no operands
4242 .arg,
4343 .alloc,
......@@ -112,7 +112,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
112112 .c_va_copy,
113113 .abs,
114114 => {
115 const ty_op = data[inst].ty_op;
115 const ty_op = data[@intFromEnum(inst)].ty_op;
116116 try self.verifyInstOperands(inst, .{ ty_op.operand, .none, .none });
117117 },
118118 .is_null,
......@@ -147,13 +147,13 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
147147 .set_err_return_trace,
148148 .c_va_end,
149149 => {
150 const un_op = data[inst].un_op;
150 const un_op = data[@intFromEnum(inst)].un_op;
151151 try self.verifyInstOperands(inst, .{ un_op, .none, .none });
152152 },
153153 .ret,
154154 .ret_load,
155155 => {
156 const un_op = data[inst].un_op;
156 const un_op = data[@intFromEnum(inst)].un_op;
157157 try self.verifyInstOperands(inst, .{ un_op, .none, .none });
158158 // This instruction terminates the function, so everything should be dead
159159 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 {
162162 .dbg_var_val,
163163 .wasm_memory_grow,
164164 => {
165 const pl_op = data[inst].pl_op;
165 const pl_op = data[@intFromEnum(inst)].pl_op;
166166 try self.verifyInstOperands(inst, .{ pl_op.operand, .none, .none });
167167 },
168168 .prefetch => {
169 const prefetch = data[inst].prefetch;
169 const prefetch = data[@intFromEnum(inst)].prefetch;
170170 try self.verifyInstOperands(inst, .{ prefetch.ptr, .none, .none });
171171 },
172172 .reduce,
173173 .reduce_optimized,
174174 => {
175 const reduce = data[inst].reduce;
175 const reduce = data[@intFromEnum(inst)].reduce;
176176 try self.verifyInstOperands(inst, .{ reduce.operand, .none, .none });
177177 },
178178 .union_init => {
179 const ty_pl = data[inst].ty_pl;
179 const ty_pl = data[@intFromEnum(inst)].ty_pl;
180180 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
181181 try self.verifyInstOperands(inst, .{ extra.init, .none, .none });
182182 },
183183 .struct_field_ptr, .struct_field_val => {
184 const ty_pl = data[inst].ty_pl;
184 const ty_pl = data[@intFromEnum(inst)].ty_pl;
185185 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
186186 try self.verifyInstOperands(inst, .{ extra.struct_operand, .none, .none });
187187 },
188188 .field_parent_ptr => {
189 const ty_pl = data[inst].ty_pl;
189 const ty_pl = data[@intFromEnum(inst)].ty_pl;
190190 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
191191 try self.verifyInstOperands(inst, .{ extra.field_ptr, .none, .none });
192192 },
193193 .atomic_load => {
194 const atomic_load = data[inst].atomic_load;
194 const atomic_load = data[@intFromEnum(inst)].atomic_load;
195195 try self.verifyInstOperands(inst, .{ atomic_load.ptr, .none, .none });
196196 },
197197
......@@ -261,7 +261,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
261261 .memset_safe,
262262 .memcpy,
263263 => {
264 const bin_op = data[inst].bin_op;
264 const bin_op = data[@intFromEnum(inst)].bin_op;
265265 try self.verifyInstOperands(inst, .{ bin_op.lhs, bin_op.rhs, .none });
266266 },
267267 .add_with_overflow,
......@@ -274,56 +274,56 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
274274 .slice_elem_ptr,
275275 .slice,
276276 => {
277 const ty_pl = data[inst].ty_pl;
277 const ty_pl = data[@intFromEnum(inst)].ty_pl;
278278 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
279279 try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, .none });
280280 },
281281 .shuffle => {
282 const ty_pl = data[inst].ty_pl;
282 const ty_pl = data[@intFromEnum(inst)].ty_pl;
283283 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
284284 try self.verifyInstOperands(inst, .{ extra.a, extra.b, .none });
285285 },
286286 .cmp_vector,
287287 .cmp_vector_optimized,
288288 => {
289 const ty_pl = data[inst].ty_pl;
289 const ty_pl = data[@intFromEnum(inst)].ty_pl;
290290 const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;
291291 try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, .none });
292292 },
293293 .atomic_rmw => {
294 const pl_op = data[inst].pl_op;
294 const pl_op = data[@intFromEnum(inst)].pl_op;
295295 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
296296 try self.verifyInstOperands(inst, .{ pl_op.operand, extra.operand, .none });
297297 },
298298
299299 // ternary
300300 .select => {
301 const pl_op = data[inst].pl_op;
301 const pl_op = data[@intFromEnum(inst)].pl_op;
302302 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
303303 try self.verifyInstOperands(inst, .{ pl_op.operand, extra.lhs, extra.rhs });
304304 },
305305 .mul_add => {
306 const pl_op = data[inst].pl_op;
306 const pl_op = data[@intFromEnum(inst)].pl_op;
307307 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
308308 try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, pl_op.operand });
309309 },
310310 .vector_store_elem => {
311 const vector_store_elem = data[inst].vector_store_elem;
311 const vector_store_elem = data[@intFromEnum(inst)].vector_store_elem;
312312 const extra = self.air.extraData(Air.Bin, vector_store_elem.payload).data;
313313 try self.verifyInstOperands(inst, .{ vector_store_elem.vector_ptr, extra.lhs, extra.rhs });
314314 },
315315 .cmpxchg_strong,
316316 .cmpxchg_weak,
317317 => {
318 const ty_pl = data[inst].ty_pl;
318 const ty_pl = data[@intFromEnum(inst)].ty_pl;
319319 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
320320 try self.verifyInstOperands(inst, .{ extra.ptr, extra.expected_value, extra.new_value });
321321 },
322322
323323 // big tombs
324324 .aggregate_init => {
325 const ty_pl = data[inst].ty_pl;
326 const aggregate_ty = self.air.getRefType(ty_pl.ty);
325 const ty_pl = data[@intFromEnum(inst)].ty_pl;
326 const aggregate_ty = ty_pl.ty.toType();
327327 const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip)));
328328 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 {
334334 try self.verifyInst(inst);
335335 },
336336 .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;
338338 const extra = self.air.extraData(Air.Call, pl_op.payload);
339339 const args = @as(
340340 []const Air.Inst.Ref,
......@@ -349,7 +349,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
349349 try self.verifyInst(inst);
350350 },
351351 .assembly => {
352 const ty_pl = data[inst].ty_pl;
352 const ty_pl = data[@intFromEnum(inst)].ty_pl;
353353 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
354354 var extra_i = extra.end;
355355 const outputs = @as(
......@@ -377,9 +377,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
377377
378378 // control flow
379379 .@"try" => {
380 const pl_op = data[inst].pl_op;
380 const pl_op = data[@intFromEnum(inst)].pl_op;
381381 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
384384 const cond_br_liveness = self.liveness.getCondBr(inst);
385385
......@@ -399,9 +399,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
399399 try self.verifyInst(inst);
400400 },
401401 .try_ptr => {
402 const ty_pl = data[inst].ty_pl;
402 const ty_pl = data[@intFromEnum(inst)].ty_pl;
403403 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
406406 const cond_br_liveness = self.liveness.getCondBr(inst);
407407
......@@ -421,7 +421,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
421421 try self.verifyInst(inst);
422422 },
423423 .br => {
424 const br = data[inst].br;
424 const br = data[@intFromEnum(inst)].br;
425425 const gop = try self.blocks.getOrPut(self.gpa, br.block_inst);
426426
427427 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 {
433433 try self.verifyInst(inst);
434434 },
435435 .block => {
436 const ty_pl = data[inst].ty_pl;
437 const block_ty = self.air.getRefType(ty_pl.ty);
436 const ty_pl = data[@intFromEnum(inst)].ty_pl;
437 const block_ty = ty_pl.ty.toType();
438438 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]);
440440 const block_liveness = self.liveness.getBlock(inst);
441441
442442 var orig_live = try self.live.clone(self.gpa);
......@@ -464,9 +464,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
464464 try self.verifyInstOperands(inst, .{ .none, .none, .none });
465465 },
466466 .loop => {
467 const ty_pl = data[inst].ty_pl;
467 const ty_pl = data[@intFromEnum(inst)].ty_pl;
468468 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
471471 var live = try self.live.clone(self.gpa);
472472 defer live.deinit(self.gpa);
......@@ -479,10 +479,10 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
479479 try self.verifyInstOperands(inst, .{ .none, .none, .none });
480480 },
481481 .cond_br => {
482 const pl_op = data[inst].pl_op;
482 const pl_op = data[@intFromEnum(inst)].pl_op;
483483 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];
485 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_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: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
486486 const cond_br_liveness = self.liveness.getCondBr(inst);
487487
488488 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 {
502502 try self.verifyInst(inst);
503503 },
504504 .switch_br => {
505 const pl_op = data[inst].pl_op;
505 const pl_op = data[@intFromEnum(inst)].pl_op;
506506 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
507507 var extra_index = switch_br.end;
508508 var case_i: u32 = 0;
......@@ -524,7 +524,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
524524 []const Air.Inst.Ref,
525525 @ptrCast(self.air.extra[case.end..][0..case.data.items_len]),
526526 );
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]);
528528 extra_index = case.end + items.len + case_body.len;
529529
530530 self.live.deinit(self.gpa);
......@@ -534,7 +534,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
534534 try self.verifyBody(case_body);
535535 }
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]);
538538 if (else_body.len > 0) {
539539 self.live.deinit(self.gpa);
540540 self.live = try live.clone(self.gpa);
......@@ -550,11 +550,11 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
550550}
551551
552552fn 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);
554554}
555555
556556fn 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 {
558558 assert(!dies);
559559 return;
560560 };
src/Module.zig+4-4
......@@ -4591,8 +4591,8 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
45914591 gop.value_ptr.* = Air.internedToRef(opv.toIntern());
45924592 continue;
45934593 }
4594 const arg_index: u32 = @intCast(sema.air_instructions.len);
4595 gop.value_ptr.* = Air.indexToRef(arg_index);
4594 const arg_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
4595 gop.value_ptr.* = arg_index.toRef();
45964596 inner_block.instructions.appendAssumeCapacity(arg_index);
45974597 sema.air_instructions.appendAssumeCapacity(.{
45984598 .tag = .arg,
......@@ -4626,7 +4626,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
46264626 while (it.next()) |ptr_inst| {
46274627 // The lack of a resolve_inferred_alloc means that this instruction
46284628 // 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.*), .{
46304630 .tag = .alloc,
46314631 .data = .{ .ty = Type.single_const_pointer_to_comptime_int },
46324632 });
......@@ -4659,7 +4659,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
46594659 const main_block_index = sema.addExtraAssumeCapacity(Air.Block{
46604660 .body_len = @intCast(inner_block.instructions.items.len),
46614661 });
4662 sema.air_extra.appendSliceAssumeCapacity(inner_block.instructions.items);
4662 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(inner_block.instructions.items));
46634663 sema.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)] = main_block_index;
46644664
46654665 // Resolving inferred error sets is done *before* setting the function
src/Sema.zig+195-195
......@@ -741,7 +741,7 @@ pub const Block = struct {
741741 }
742742
743743 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();
745745 }
746746
747747 pub fn addInstAsIndex(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index {
......@@ -751,7 +751,7 @@ pub const Block = struct {
751751 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
752752 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);
755755 sema.air_instructions.appendAssumeCapacity(inst);
756756 block.instructions.appendAssumeCapacity(result_index);
757757 return result_index;
......@@ -760,7 +760,7 @@ pub const Block = struct {
760760 /// Insert an instruction into the block at `index`. Moves all following
761761 /// instructions forward in the block to make room. Operation is O(N).
762762 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();
764764 }
765765
766766 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 {
769769
770770 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);
773773 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);
776776 return result_index;
777777 }
778778
......@@ -935,7 +935,7 @@ pub fn analyzeBodyBreak(
935935 else => |e| return e,
936936 };
937937 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()))
939939 return null;
940940 const break_data = sema.code.instructions.items(.data)[@intFromEnum(break_inst)].@"break";
941941 const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data;
......@@ -1638,7 +1638,7 @@ fn analyzeBodyInner(
16381638 // Comptime control flow populates the map, so we don't actually know
16391639 // if this is a post-hoc runtime block until we check the
16401640 // 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;
16421642 const labeled_block = sema.post_hoc_blocks.get(new_block_inst) orelse
16431643 break :ph;
16441644
......@@ -1817,7 +1817,7 @@ fn analyzeBodyInner(
18171817 if (sema.isNoReturn(air_inst)) {
18181818 // We're going to assume that the body itself is noreturn, so let's ensure that now
18191819 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()));
18211821 break always_noreturn;
18221822 }
18231823 map.putAssumeCapacity(inst, air_inst);
......@@ -2003,7 +2003,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {
20032003 const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) {
20042004 error.GenericPoison => unreachable, // this is a type, not a value
20052005 };
2006 const operand_val = Air.refToInterned(operand_ref) orelse return .unknown;
2006 const operand_val = operand_ref.toInterned() orelse return .unknown;
20072007 if (operand_val == .generic_poison_type) {
20082008 // The pointer was generic poison - keep looking.
20092009 cur = un_node.operand;
......@@ -2158,14 +2158,14 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val
21582158
21592159 const air_tags = sema.air_instructions.items(.tag);
21602160 if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {
2161 if (Air.refToInterned(inst)) |ip_index| {
2161 if (inst.toInterned()) |ip_index| {
21622162 const val = Value.fromInterned(ip_index);
21632163 if (val.getVariable(sema.mod) != null) return val;
21642164 }
21652165 return opv;
21662166 }
2167 const ip_index = Air.refToInterned(inst) orelse {
2168 switch (air_tags[Air.refToIndex(inst).?]) {
2167 const ip_index = inst.toInterned() orelse {
2168 switch (air_tags[@intFromEnum(inst.toIndex().?)]) {
21692169 .inferred_alloc => unreachable,
21702170 .inferred_alloc_comptime => unreachable,
21712171 else => return null,
......@@ -3543,7 +3543,7 @@ fn zirAllocExtended(
35433543 .is_const = small.is_const,
35443544 } },
35453545 });
3546 return Air.indexToRef(@intCast(sema.air_instructions.len - 1));
3546 return @as(Air.Inst.Index, @enumFromInt(sema.air_instructions.len - 1)).toRef();
35473547 }
35483548 }
35493549
......@@ -3562,7 +3562,7 @@ fn zirAllocExtended(
35623562 });
35633563 const ptr = try block.addTy(.alloc, ptr_type);
35643564 if (small.is_const) {
3565 const ptr_inst = Air.refToIndex(ptr).?;
3565 const ptr_inst = ptr.toIndex().?;
35663566 try sema.maybe_comptime_allocs.put(gpa, ptr_inst, .{ .runtime_index = block.runtime_index });
35673567 try sema.base_allocs.put(gpa, ptr_inst, ptr_inst);
35683568 }
......@@ -3581,7 +3581,7 @@ fn zirAllocExtended(
35813581 try sema.maybe_comptime_allocs.put(gpa, result_index, .{ .runtime_index = block.runtime_index });
35823582 try sema.base_allocs.put(gpa, result_index, result_index);
35833583 }
3584 return Air.indexToRef(result_index);
3584 return result_index.toRef();
35853585}
35863586
35873587fn 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
36543654 const ptr_info = alloc_ty.ptrInfo(mod);
36553655 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;
36583658 const comptime_info = sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return null;
36593659 const stores = comptime_info.value.stores.items;
36603660
......@@ -3674,10 +3674,10 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
36743674 simple: {
36753675 if (stores.len != 1) break :simple;
36763676 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;
36783678 if (store_data.lhs != alloc) break :simple;
36793679
3680 const val = Air.refToInterned(store_data.rhs).?;
3680 const val = store_data.rhs.toInterned().?;
36813681 assert(mod.intern_pool.typeOf(val) == elem_ty.toIntern());
36823682 return sema.finishResolveComptimeKnownAllocValue(val, alloc_inst, comptime_info.value);
36833683 }
......@@ -3704,8 +3704,8 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
37043704
37053705 var to_map = try std.ArrayList(Air.Inst.Index).initCapacity(sema.arena, stores.len);
37063706 for (stores) |store_inst| {
3707 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;
3708 to_map.appendAssumeCapacity(Air.refToIndex(bin_op.lhs).?);
3707 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
3708 to_map.appendAssumeCapacity(bin_op.lhs.toIndex().?);
37093709 }
37103710
37113711 const tmp_air = sema.getTmpAir();
......@@ -3719,12 +3719,12 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
37193719 field: u32,
37203720 elem: u64,
37213721 };
3722 const inst_tag = tmp_air.instructions.items(.tag)[air_ptr];
3722 const inst_tag = tmp_air.instructions.items(.tag)[@intFromEnum(air_ptr)];
37233723 const air_parent_ptr: Air.Inst.Ref, const method: PointerMethod = switch (inst_tag) {
37243724 .struct_field_ptr => blk: {
37253725 const data = tmp_air.extraData(
37263726 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,
37283728 ).data;
37293729 break :blk .{
37303730 data.struct_operand,
......@@ -3736,7 +3736,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
37363736 .struct_field_ptr_index_2,
37373737 .struct_field_ptr_index_3,
37383738 => .{
3739 tmp_air.instructions.items(.data)[air_ptr].ty_op.operand,
3739 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand,
37403740 .{ .field = switch (inst_tag) {
37413741 .struct_field_ptr_index_0 => 0,
37423742 .struct_field_ptr_index_1 => 1,
......@@ -3746,17 +3746,17 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
37463746 } },
37473747 },
37483748 .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,
37503750 .{ .field = Value.slice_ptr_index },
37513751 },
37523752 .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,
37543754 .{ .field = Value.slice_len_index },
37553755 },
37563756 .ptr_elem_ptr => blk: {
37573757 const data = tmp_air.extraData(
37583758 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,
37603760 ).data;
37613761 const idx_val = (try sema.resolveValue(data.rhs)).?;
37623762 break :blk .{
......@@ -3765,24 +3765,24 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
37653765 };
37663766 },
37673767 .bitcast => .{
3768 tmp_air.instructions.items(.data)[air_ptr].ty_op.operand,
3768 tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand,
37693769 .same_addr,
37703770 },
37713771 .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,
37733773 .opt_payload,
37743774 },
37753775 .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,
37773777 .eu_payload,
37783778 },
37793779 else => unreachable,
37803780 };
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 {
37833783 // Resolve the parent pointer first.
37843784 // 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().? });
37863786 continue;
37873787 };
37883788 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
38113811 // We have a correlation between AIR pointers and decl pointers. Perform all stores at comptime.
38123812
38133813 for (stores) |store_inst| {
3814 switch (sema.air_instructions.items(.tag)[store_inst]) {
3814 switch (sema.air_instructions.items(.tag)[@intFromEnum(store_inst)]) {
38153815 .set_union_tag => {
38163816 // If this tag has an OPV payload, there won't be a corresponding
38173817 // store instruction, so we must set the union payload now.
3818 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;
3819 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
3818 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
3819 const air_ptr_inst = bin_op.lhs.toIndex().?;
38203820 const tag_val = (try sema.resolveValue(bin_op.rhs)).?;
38213821 const union_ty = sema.typeOf(bin_op.lhs).childType(mod);
38223822 const payload_ty = union_ty.unionFieldType(tag_val, mod).?;
......@@ -3827,8 +3827,8 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
38273827 }
38283828 },
38293829 .store, .store_safe => {
3830 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;
3831 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
3830 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
3831 const air_ptr_inst = bin_op.lhs.toIndex().?;
38323832 const store_val = (try sema.resolveValue(bin_op.rhs)).?;
38333833 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
38343834 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
38583858 // Liveness to elide it.
38593859 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);
38623862 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);
38643864 }
38653865 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);
38673867 }
38683868
38693869 return result_val;
......@@ -3905,7 +3905,7 @@ fn zirAllocInferredComptime(
39053905 .is_const = is_const,
39063906 } },
39073907 });
3908 return Air.indexToRef(@intCast(sema.air_instructions.len - 1));
3908 return @as(Air.Inst.Index, @enumFromInt(sema.air_instructions.len - 1)).toRef();
39093909}
39103910
39113911fn 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
39253925 });
39263926 try sema.queueFullTypeResolution(var_ty);
39273927 const ptr = try block.addTy(.alloc, ptr_type);
3928 const ptr_inst = Air.refToIndex(ptr).?;
3928 const ptr_inst = ptr.toIndex().?;
39293929 try sema.maybe_comptime_allocs.put(sema.gpa, ptr_inst, .{ .runtime_index = block.runtime_index });
39303930 try sema.base_allocs.put(sema.gpa, ptr_inst, ptr_inst);
39313931 return ptr;
......@@ -3974,7 +3974,7 @@ fn zirAllocInferred(
39743974 .is_const = is_const,
39753975 } },
39763976 });
3977 return Air.indexToRef(@intCast(sema.air_instructions.len - 1));
3977 return @as(Air.Inst.Index, @enumFromInt(sema.air_instructions.len - 1)).toRef();
39783978 }
39793979
39803980 const result_index = try block.addInstAsIndex(.{
......@@ -3987,7 +3987,7 @@ fn zirAllocInferred(
39873987 try sema.unresolved_inferred_allocs.putNoClobber(gpa, result_index, .{});
39883988 try sema.maybe_comptime_allocs.put(gpa, result_index, .{ .runtime_index = block.runtime_index });
39893989 try sema.base_allocs.put(sema.gpa, result_index, result_index);
3990 return Air.indexToRef(result_index);
3990 return result_index.toRef();
39913991}
39923992
39933993fn 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
40004000 const src = inst_data.src();
40014001 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
40024002 const ptr = try sema.resolveInst(inst_data.operand);
4003 const ptr_inst = Air.refToIndex(ptr).?;
4003 const ptr_inst = ptr.toIndex().?;
40044004 const target = mod.getTarget();
40054005
4006 switch (sema.air_instructions.items(.tag)[ptr_inst]) {
4006 switch (sema.air_instructions.items(.tag)[@intFromEnum(ptr_inst)]) {
40074007 .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;
40094009 const decl_index = iac.decl_index;
40104010
40114011 const decl = mod.declPtr(decl_index);
......@@ -4022,7 +4022,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
40224022
40234023 if (std.debug.runtime_safety) {
40244024 // 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 });
40264026 }
40274027
40284028 try sema.maybeQueueFuncBodyAnalysis(decl_index);
......@@ -4039,12 +4039,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
40394039 sema.inst_map.putAssumeCapacity(inst_data.operand.toIndex().?, Air.internedToRef(interned));
40404040 },
40414041 .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;
40434043 const ia2 = sema.unresolved_inferred_allocs.fetchRemove(ptr_inst).?.value;
40444044 const peer_vals = try sema.arena.alloc(Air.Inst.Ref, ia2.prongs.items.len);
40454045 for (peer_vals, ia2.prongs.items) |*peer_val, store_inst| {
4046 assert(sema.air_instructions.items(.tag)[store_inst] == .store);
4047 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;
4046 assert(sema.air_instructions.items(.tag)[@intFromEnum(store_inst)] == .store);
4047 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
40484048 peer_val.* = bin_op.rhs;
40494049 }
40504050 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
40834083 try sema.queueFullTypeResolution(final_elem_ty);
40844084
40854085 // Change it to a normal alloc.
4086 sema.air_instructions.set(ptr_inst, .{
4086 sema.air_instructions.set(@intFromEnum(ptr_inst), .{
40874087 .tag = .alloc,
40884088 .data = .{ .ty = final_ptr_ty },
40894089 });
......@@ -4095,15 +4095,15 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
40954095 var replacement_block = block.makeSubBlock();
40964096 defer replacement_block.instructions.deinit(gpa);
40974097
4098 assert(sema.air_instructions.items(.tag)[placeholder_inst] == .store);
4099 const bin_op = sema.air_instructions.items(.data)[placeholder_inst].bin_op;
4098 assert(sema.air_instructions.items(.tag)[@intFromEnum(placeholder_inst)] == .store);
4099 const bin_op = sema.air_instructions.items(.data)[@intFromEnum(placeholder_inst)].bin_op;
41004100 try sema.storePtr2(&replacement_block, src, bin_op.lhs, src, bin_op.rhs, src, .store);
41014101
41024102 // If only one instruction is produced then we can replace the store
41034103 // placeholder instruction with this instruction; no need for an entire block.
41044104 if (replacement_block.instructions.items.len == 1) {
41054105 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)));
41074107 continue;
41084108 }
41094109
......@@ -4114,7 +4114,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
41144114 gpa,
41154115 @typeInfo(Air.Block).Struct.fields.len + replacement_block.instructions.items.len,
41164116 );
4117 sema.air_instructions.set(placeholder_inst, .{
4117 sema.air_instructions.set(@intFromEnum(placeholder_inst), .{
41184118 .tag = .block,
41194119 .data = .{ .ty_pl = .{
41204120 .ty = .void_type,
......@@ -4123,7 +4123,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
41234123 }),
41244124 } },
41254125 });
4126 sema.air_extra.appendSliceAssumeCapacity(replacement_block.instructions.items);
4126 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(replacement_block.instructions.items));
41274127 }
41284128 },
41294129 else => unreachable,
......@@ -4584,18 +4584,18 @@ fn validateUnionInit(
45844584 var init_val: ?Value = null;
45854585 while (block_index > 0) : (block_index -= 1) {
45864586 const store_inst = block.instructions.items[block_index];
4587 if (Air.indexToRef(store_inst) == field_ptr_ref) break;
4588 switch (air_tags[store_inst]) {
4587 if (store_inst.toRef() == field_ptr_ref) break;
4588 switch (air_tags[@intFromEnum(store_inst)]) {
45894589 .store, .store_safe => {},
45904590 else => continue,
45914591 }
4592 const bin_op = air_datas[store_inst].bin_op;
4592 const bin_op = air_datas[@intFromEnum(store_inst)].bin_op;
45934593 var ptr_ref = bin_op.lhs;
4594 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {
4595 ptr_ref = air_datas[ptr_inst].ty_op.operand;
4594 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
4595 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
45964596 };
45974597 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|
45994599 std.mem.lastIndexOfScalar(
46004600 Air.Inst.Index,
46014601 block.instructions.items[0..block_index],
......@@ -4615,18 +4615,18 @@ fn validateUnionInit(
46154615 // instead a single `store` to the result ptr with a comptime union value.
46164616 block_index = first_block_index;
46174617 for (block.instructions.items[first_block_index..]) |cur_inst| {
4618 switch (air_tags[cur_inst]) {
4618 switch (air_tags[@intFromEnum(cur_inst)]) {
46194619 .struct_field_ptr,
46204620 .struct_field_ptr_index_0,
46214621 .struct_field_ptr_index_1,
46224622 .struct_field_ptr_index_2,
46234623 .struct_field_ptr_index_3,
4624 => if (Air.indexToRef(cur_inst) == field_ptr_ref) continue,
4625 .bitcast => if (air_datas[cur_inst].ty_op.operand == field_ptr_ref) continue,
4624 => if (cur_inst.toRef() == field_ptr_ref) continue,
4625 .bitcast => if (air_datas[@intFromEnum(cur_inst)].ty_op.operand == field_ptr_ref) continue,
46264626 .store, .store_safe => {
4627 var ptr_ref = air_datas[cur_inst].bin_op.lhs;
4628 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {
4629 ptr_ref = air_datas[ptr_inst].ty_op.operand;
4627 var ptr_ref = air_datas[@intFromEnum(cur_inst)].bin_op.lhs;
4628 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
4629 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
46304630 };
46314631 if (ptr_ref == field_ptr_ref) continue;
46324632 },
......@@ -4807,21 +4807,21 @@ fn validateStructInit(
48074807 var block_index = block.instructions.items.len -| 1;
48084808 while (block_index > 0) : (block_index -= 1) {
48094809 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) {
48114811 struct_is_comptime = false;
48124812 continue :field;
48134813 }
4814 switch (air_tags[store_inst]) {
4814 switch (air_tags[@intFromEnum(store_inst)]) {
48154815 .store, .store_safe => {},
48164816 else => continue,
48174817 }
4818 const bin_op = air_datas[store_inst].bin_op;
4818 const bin_op = air_datas[@intFromEnum(store_inst)].bin_op;
48194819 var ptr_ref = bin_op.lhs;
4820 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {
4821 ptr_ref = air_datas[ptr_inst].ty_op.operand;
4820 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
4821 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
48224822 };
48234823 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|
48254825 std.mem.lastIndexOfScalar(
48264826 Air.Inst.Index,
48274827 block.instructions.items[0..block_index],
......@@ -4895,18 +4895,18 @@ fn validateStructInit(
48954895 if (try field_ty.onePossibleValue(mod)) |_| continue;
48964896 field_ptr_ref = sema.inst_map.get(instrs[init_index]).?;
48974897 }
4898 switch (air_tags[cur_inst]) {
4898 switch (air_tags[@intFromEnum(cur_inst)]) {
48994899 .struct_field_ptr,
49004900 .struct_field_ptr_index_0,
49014901 .struct_field_ptr_index_1,
49024902 .struct_field_ptr_index_2,
49034903 .struct_field_ptr_index_3,
4904 => if (Air.indexToRef(cur_inst) == field_ptr_ref) continue,
4905 .bitcast => if (air_datas[cur_inst].ty_op.operand == field_ptr_ref) continue,
4904 => if (cur_inst.toRef() == field_ptr_ref) continue,
4905 .bitcast => if (air_datas[@intFromEnum(cur_inst)].ty_op.operand == field_ptr_ref) continue,
49064906 .store, .store_safe => {
4907 var ptr_ref = air_datas[cur_inst].bin_op.lhs;
4908 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {
4909 ptr_ref = air_datas[ptr_inst].ty_op.operand;
4907 var ptr_ref = air_datas[@intFromEnum(cur_inst)].bin_op.lhs;
4908 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
4909 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
49104910 };
49114911 if (ptr_ref == field_ptr_ref) {
49124912 field_ptr_ref = .none;
......@@ -5063,21 +5063,21 @@ fn zirValidatePtrArrayInit(
50635063 var block_index = block.instructions.items.len -| 1;
50645064 while (block_index > 0) : (block_index -= 1) {
50655065 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) {
50675067 array_is_comptime = false;
50685068 continue :outer;
50695069 }
5070 switch (air_tags[store_inst]) {
5070 switch (air_tags[@intFromEnum(store_inst)]) {
50715071 .store, .store_safe => {},
50725072 else => continue,
50735073 }
5074 const bin_op = air_datas[store_inst].bin_op;
5074 const bin_op = air_datas[@intFromEnum(store_inst)].bin_op;
50755075 var ptr_ref = bin_op.lhs;
5076 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {
5077 ptr_ref = air_datas[ptr_inst].ty_op.operand;
5076 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
5077 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
50785078 };
50795079 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|
50815081 std.mem.lastIndexOfScalar(
50825082 Air.Inst.Index,
50835083 block.instructions.items[0..block_index],
......@@ -5117,13 +5117,13 @@ fn zirValidatePtrArrayInit(
51175117 if (array_ty.isTuple(mod) and array_ty.structFieldIsComptime(elem_index, mod)) continue;
51185118 elem_ptr_ref = sema.inst_map.get(instrs[elem_index]).?;
51195119 }
5120 switch (air_tags[cur_inst]) {
5121 .ptr_elem_ptr => if (Air.indexToRef(cur_inst) == elem_ptr_ref) continue,
5122 .bitcast => if (air_datas[cur_inst].ty_op.operand == elem_ptr_ref) continue,
5120 switch (air_tags[@intFromEnum(cur_inst)]) {
5121 .ptr_elem_ptr => if (cur_inst.toRef() == elem_ptr_ref) continue,
5122 .bitcast => if (air_datas[@intFromEnum(cur_inst)].ty_op.operand == elem_ptr_ref) continue,
51235123 .store, .store_safe => {
5124 var ptr_ref = air_datas[cur_inst].bin_op.lhs;
5125 if (Air.refToIndex(ptr_ref)) |ptr_inst| if (air_tags[ptr_inst] == .bitcast) {
5126 ptr_ref = air_datas[ptr_inst].ty_op.operand;
5124 var ptr_ref = air_datas[@intFromEnum(cur_inst)].bin_op.lhs;
5125 if (ptr_ref.toIndex()) |ptr_inst| if (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
5126 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
51275127 };
51285128 if (ptr_ref == elem_ptr_ref) {
51295129 elem_ptr_ref = .none;
......@@ -5336,12 +5336,12 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
53365336 const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
53375337 const ptr = try sema.resolveInst(bin_inst.lhs);
53385338 const operand = try sema.resolveInst(bin_inst.rhs);
5339 const ptr_inst = Air.refToIndex(ptr).?;
5339 const ptr_inst = ptr.toIndex().?;
53405340 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)]) {
53435343 .inferred_alloc_comptime => {
5344 const iac = &air_datas[ptr_inst].inferred_alloc_comptime;
5344 const iac = &air_datas[@intFromEnum(ptr_inst)].inferred_alloc_comptime;
53455345 return sema.storeToInferredAllocComptime(block, src, operand, iac);
53465346 },
53475347 .inferred_alloc => {
......@@ -5365,7 +5365,7 @@ fn storeToInferredAlloc(
53655365 try sema.checkComptimeKnownStore(block, dummy_store);
53665366 // Add the stored instruction to the set we will use to resolve peer types
53675367 // 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().?);
53695369}
53705370
53715371fn storeToInferredAllocComptime(
......@@ -5635,8 +5635,8 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
56355635 // Reserve space for a Loop instruction so that generated Break instructions can
56365636 // point to it, even if it doesn't end up getting used because the code ends up being
56375637 // comptime evaluated.
5638 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
5639 const loop_inst = block_inst + 1;
5638 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
5639 const loop_inst: Air.Inst.Index = @enumFromInt(@intFromEnum(block_inst) + 1);
56405640 try sema.air_instructions.ensureUnusedCapacity(gpa, 2);
56415641 sema.air_instructions.appendAssumeCapacity(.{
56425642 .tag = .block,
......@@ -5674,7 +5674,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
56745674 try sema.analyzeBody(&loop_block, body);
56755675
56765676 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)) {
56785678 // If the loop ended with a noreturn terminator, then there is no way for it to loop,
56795679 // so we can just use the block instead.
56805680 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
56825682 try child_block.instructions.append(gpa, loop_inst);
56835683
56845684 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(
56865686 Air.Block{ .body_len = @intCast(loop_block_len) },
56875687 );
5688 sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items);
5688 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(loop_block.instructions.items));
56895689 }
56905690 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);
56915691}
......@@ -5793,7 +5793,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
57935793 // Reserve space for a Block instruction so that generated Break instructions can
57945794 // point to it, even if it doesn't end up getting used because the code ends up being
57955795 // 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);
57975797 try sema.air_instructions.append(gpa, .{
57985798 .tag = .block,
57995799 .data = undefined,
......@@ -5887,13 +5887,13 @@ fn analyzeBlockBody(
58875887
58885888 // Blocks must terminate with noreturn instruction.
58895889 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
58925892 if (merges.results.items.len == 0) {
58935893 // No need for a block instruction. We can put the new instructions
58945894 // directly into the parent block.
58955895 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();
58975897 }
58985898 if (merges.results.items.len == 1) {
58995899 const last_inst_index = child_block.instructions.items.len - 1;
......@@ -5936,17 +5936,17 @@ fn analyzeBlockBody(
59365936 const ty_inst = Air.internedToRef(resolved_ty.toIntern());
59375937 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
59385938 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 = .{
59405940 .ty = ty_inst,
59415941 .payload = sema.addExtraAssumeCapacity(Air.Block{
59425942 .body_len = @intCast(child_block.instructions.items.len),
59435943 }),
59445944 } };
5945 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);
5945 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(child_block.instructions.items));
59465946 // Now that the block has its type resolved, we need to go back into all the break
59475947 // instructions, and insert type coercion on the operands.
59485948 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;
59505950 const br_operand_src = src;
59515951 const br_operand_ty = sema.typeOf(br_operand);
59525952 if (br_operand_ty.eql(resolved_ty, mod)) {
......@@ -5959,10 +5959,10 @@ fn analyzeBlockBody(
59595959 // If no instructions were produced, such as in the case of a coercion of a
59605960 // constant value to a new type, we can simply point the br operand to it.
59615961 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;
59635963 continue;
59645964 }
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
59675967 // Convert the br instruction to a block instruction that has the coercion
59685968 // and then a new br inside that returns the coerced instruction.
......@@ -5970,17 +5970,17 @@ fn analyzeBlockBody(
59705970 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
59715971 sub_block_len);
59725972 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;
5976 sema.air_instructions.items(.data)[br] = .{ .ty_pl = .{
5975 sema.air_instructions.items(.tag)[@intFromEnum(br)] = .block;
5976 sema.air_instructions.items(.data)[@intFromEnum(br)] = .{ .ty_pl = .{
59775977 .ty = .noreturn_type,
59785978 .payload = sema.addExtraAssumeCapacity(Air.Block{
59795979 .body_len = sub_block_len,
59805980 }),
59815981 } };
5982 sema.air_extra.appendSliceAssumeCapacity(coerce_block.instructions.items);
5983 sema.air_extra.appendAssumeCapacity(sub_br_inst);
5982 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(coerce_block.instructions.items));
5983 sema.air_extra.appendAssumeCapacity(@intFromEnum(sub_br_inst));
59845984
59855985 sema.air_instructions.appendAssumeCapacity(.{
59865986 .tag = .br,
......@@ -5990,7 +5990,7 @@ fn analyzeBlockBody(
59905990 } },
59915991 });
59925992 }
5993 return Air.indexToRef(merges.block_inst);
5993 return merges.block_inst.toRef();
59945994}
59955995
59965996fn 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
62496249 null;
62506250 try label.merges.src_locs.append(sema.gpa, src_loc);
62516251 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().?);
62536253 block.runtime_index.increment();
62546254 if (block.runtime_cond == null and block.runtime_loop == null) {
62556255 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
62736273
62746274 if (block.instructions.items.len != 0) {
62756275 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) {
62776277 // 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 = .{
62796279 .line = inst_data.line,
62806280 .column = inst_data.column,
62816281 };
......@@ -6609,7 +6609,7 @@ fn popErrorReturnTrace(
66096609 then_block.instructions.items.len + else_block.instructions.items.len +
66106610 @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);
66136613 try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{
66146614 .operand = is_non_error_inst,
66156615 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
......@@ -6617,11 +6617,11 @@ fn popErrorReturnTrace(
66176617 .else_body_len = @intCast(else_block.instructions.items.len),
66186618 }),
66196619 } } });
6620 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
6621 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);
6620 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(then_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 });
6624 sema.air_extra.appendAssumeCapacity(cond_br_inst);
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(@intFromEnum(cond_br_inst));
66256625 }
66266626}
66276627
......@@ -6668,7 +6668,7 @@ fn zirCall(
66686668 const func_ty = try sema.checkCallArgumentCount(block, func, callee_src, callee_ty, total_args, callee == .method);
66696669
66706670 // 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
66736673 // This will be set by `analyzeCall` to indicate whether any parameter was an error (making the
66746674 // error trace potentially dirty).
......@@ -7283,7 +7283,7 @@ fn analyzeCall(
72837283 // set to in the `Block`.
72847284 // This block instruction will be used to capture the return value from the
72857285 // 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);
72877287 try sema.air_instructions.append(gpa, .{
72887288 .tag = .block,
72897289 .data = undefined,
......@@ -9737,12 +9737,12 @@ fn zirParam(
97379737 sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison);
97389738 } else {
97399739 // 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);
97419741 try sema.air_instructions.append(sema.gpa, .{
97429742 .tag = .alloc,
97439743 .data = .{ .ty = param_ty },
97449744 });
9745 sema.inst_map.putAssumeCapacityNoClobber(inst, Air.indexToRef(result_index));
9745 sema.inst_map.putAssumeCapacityNoClobber(inst, result_index.toRef());
97469746 }
97479747}
97489748
......@@ -10991,7 +10991,7 @@ const SwitchProngAnalysis = struct {
1099110991 cases_extra.appendAssumeCapacity(1); // items_len
1099210992 cases_extra.appendAssumeCapacity(@intCast(coerce_block.instructions.items.len)); // body_len
1099310993 cases_extra.appendAssumeCapacity(@intFromEnum(case_vals[idx])); // item
10994 cases_extra.appendSliceAssumeCapacity(coerce_block.instructions.items); // body
10994 cases_extra.appendSliceAssumeCapacity(@ptrCast(coerce_block.instructions.items)); // body
1099510995 }
1099610996 }
1099710997 const else_body_len = len: {
......@@ -11006,7 +11006,7 @@ const SwitchProngAnalysis = struct {
1100611006 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);
1100711007 _ = 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));
1101011010 break :len coerce_block.instructions.items.len;
1101111011 };
1101211012
......@@ -11029,12 +11029,12 @@ const SwitchProngAnalysis = struct {
1102911029 sema.air_extra.appendSliceAssumeCapacity(cases_extra.items);
1103011030
1103111031 // 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{
1103311033 .body_len = 1,
1103411034 });
1103511035 sema.air_extra.appendAssumeCapacity(switch_br_inst);
1103611036
11037 return Air.indexToRef(capture_block_inst);
11037 return capture_block_inst.toRef();
1103811038 },
1103911039 .ErrorSet => {
1104011040 if (capture_byref) {
......@@ -11780,7 +11780,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1178011780 .tag_capture_inst = tag_capture_inst,
1178111781 };
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);
1178411784 try sema.air_instructions.append(gpa, .{
1178511785 .tag = .block,
1178611786 .data = undefined,
......@@ -12023,7 +12023,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1202312023 cases_extra.appendAssumeCapacity(1); // items_len
1202412024 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1202512025 cases_extra.appendAssumeCapacity(@intFromEnum(item));
12026 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12026 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1202712027 }
1202812028
1202912029 var is_first = true;
......@@ -12110,7 +12110,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1211012110 cases_extra.appendAssumeCapacity(1); // items_len
1211112111 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1211212112 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
12113 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12113 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1211412114
1211512115 if (item.compareScalar(.eq, item_last, operand_ty, mod)) break;
1211612116 }
......@@ -12160,7 +12160,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1216012160 cases_extra.appendAssumeCapacity(1); // items_len
1216112161 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1216212162 cases_extra.appendAssumeCapacity(@intFromEnum(item));
12163 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12163 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1216412164 }
1216512165
1216612166 extra_index += info.body_len;
......@@ -12213,7 +12213,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1221312213 cases_extra.appendAssumeCapacity(@intFromEnum(item));
1221412214 }
1221512215
12216 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12216 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1221712217 } else {
1221812218 for (items) |item| {
1221912219 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
1229512295 @typeInfo(Air.CondBr).Struct.fields.len + prev_then_body.len + cond_body.len,
1229612296 );
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 =
1229912299 sema.addExtraAssumeCapacity(Air.CondBr{
1230012300 .then_body_len = @intCast(prev_then_body.len),
1230112301 .else_body_len = @intCast(cond_body.len),
1230212302 });
12303 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);
12304 sema.air_extra.appendSliceAssumeCapacity(cond_body);
12303 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(prev_then_body));
12304 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(cond_body));
1230512305 }
1230612306 gpa.free(prev_then_body);
1230712307 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
1235612356 cases_extra.appendAssumeCapacity(1); // items_len
1235712357 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1235812358 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
12359 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12359 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1236012360 }
1236112361 },
1236212362 .ErrorSet => {
......@@ -12397,7 +12397,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1239712397 cases_extra.appendAssumeCapacity(1); // items_len
1239812398 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1239912399 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
12400 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12400 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1240112401 }
1240212402 },
1240312403 .Int => {
......@@ -12428,7 +12428,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1242812428 cases_extra.appendAssumeCapacity(1); // items_len
1242912429 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1243012430 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
12431 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12431 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1243212432 }
1243312433 },
1243412434 .Bool => {
......@@ -12456,7 +12456,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1245612456 cases_extra.appendAssumeCapacity(1); // items_len
1245712457 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1245812458 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));
1246012460 }
1246112461 if (false_count == 0) {
1246212462 cases_len += 1;
......@@ -12482,7 +12482,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1248212482 cases_extra.appendAssumeCapacity(1); // items_len
1248312483 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1248412484 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));
1248612486 }
1248712487 },
1248812488 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
1254412544 try sema.air_extra.ensureUnusedCapacity(gpa, prev_then_body.len +
1254512545 @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 =
1254812548 sema.addExtraAssumeCapacity(Air.CondBr{
1254912549 .then_body_len = @intCast(prev_then_body.len),
1255012550 .else_body_len = @intCast(case_block.instructions.items.len),
1255112551 });
12552 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);
12553 sema.air_extra.appendSliceAssumeCapacity(case_block.instructions.items);
12552 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(prev_then_body));
12553 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1255412554 final_else_body = first_else_body;
1255512555 }
1255612556 }
......@@ -12565,8 +12565,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1256512565 .else_body_len = @intCast(final_else_body.len),
1256612566 }),
1256712567 } } });
12568 sema.air_extra.appendSliceAssumeCapacity(cases_extra.items);
12569 sema.air_extra.appendSliceAssumeCapacity(final_else_body);
12568 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(cases_extra.items));
12569 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(final_else_body));
1257012570
1257112571 return sema.analyzeBlockBody(block, src, &child_block, merges);
1257212572}
......@@ -18140,7 +18140,7 @@ fn zirBoolBr(
1814018140 return sema.resolveBody(parent_block, body, inst);
1814118141 }
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);
1814418144 try sema.air_instructions.append(gpa, .{
1814518145 .tag = .block,
1814618146 .data = .{ .ty_pl = .{
......@@ -18205,21 +18205,21 @@ fn finishCondBr(
1820518205 .then_body_len = @intCast(then_block.instructions.items.len),
1820618206 .else_body_len = @intCast(else_block.instructions.items.len),
1820718207 });
18208 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
18209 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);
18208 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(then_block.instructions.items));
18209 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(else_block.instructions.items));
1821018210
1821118211 _ = try child_block.addInst(.{ .tag = .cond_br, .data = .{ .pl_op = .{
1821218212 .operand = cond,
1821318213 .payload = cond_br_payload,
1821418214 } } });
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(
1821718217 Air.Block{ .body_len = @intCast(child_block.instructions.items.len) },
1821818218 );
18219 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);
18219 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(child_block.instructions.items));
1822018220
1822118221 try parent_block.instructions.append(gpa, block_inst);
18222 return Air.indexToRef(block_inst);
18222 return block_inst.toRef();
1822318223}
1822418224
1822518225fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
......@@ -18382,8 +18382,8 @@ fn zirCondbr(
1838218382 }),
1838318383 } },
1838418384 });
18385 sema.air_extra.appendSliceAssumeCapacity(true_instructions);
18386 sema.air_extra.appendSliceAssumeCapacity(sub_block.instructions.items);
18385 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(true_instructions));
18386 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(sub_block.instructions.items));
1838718387 return always_noreturn;
1838818388}
1838918389
......@@ -18429,7 +18429,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1842918429 }),
1843018430 } },
1843118431 });
18432 sema.air_extra.appendSliceAssumeCapacity(sub_block.instructions.items);
18432 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(sub_block.instructions.items));
1843318433 return try_inst;
1843418434}
1843518435
......@@ -18489,7 +18489,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1848918489 }),
1849018490 } },
1849118491 });
18492 sema.air_extra.appendSliceAssumeCapacity(sub_block.instructions.items);
18492 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(sub_block.instructions.items));
1849318493 return try_inst;
1849418494}
1849518495
......@@ -18501,8 +18501,8 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
1850118501 const labeled_block = if (!gop.found_existing) blk: {
1850218502 try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1);
1850318503
18504 const new_block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
18505 gop.value_ptr.* = Air.indexToRef(new_block_inst);
18504 const new_block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
18505 gop.value_ptr.* = new_block_inst.toRef();
1850618506 try sema.air_instructions.append(sema.gpa, .{
1850718507 .tag = .block,
1850818508 .data = undefined,
......@@ -18533,7 +18533,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
1853318533 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);
1853418534 break :blk labeled_block;
1853518535 } else blk: {
18536 const new_block_inst = Air.refToIndex(gop.value_ptr.*).?;
18536 const new_block_inst = gop.value_ptr.*.toIndex().?;
1853718537 const labeled_block = sema.post_hoc_blocks.get(new_block_inst).?;
1853818538 break :blk labeled_block;
1853918539 };
......@@ -18541,7 +18541,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
1854118541 const operand = try sema.resolveInst(break_data.operand);
1854218542 const br_ref = try child_block.addBr(labeled_block.label.merges.block_inst, operand);
1854318543 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().?);
1854518545 labeled_block.block.runtime_index.increment();
1854618546 if (labeled_block.block.runtime_cond == null and labeled_block.block.runtime_loop == null) {
1854718547 labeled_block.block.runtime_cond = child_block.runtime_cond orelse child_block.runtime_loop;
......@@ -18719,8 +18719,8 @@ fn retWithErrTracing(
1871918719 .then_body_len = @intCast(then_block.instructions.items.len),
1872018720 .else_body_len = @intCast(else_block.instructions.items.len),
1872118721 });
18722 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
18723 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);
18722 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(then_block.instructions.items));
18723 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(else_block.instructions.items));
1872418724
1872518725 _ = try block.addInst(.{ .tag = .cond_br, .data = .{ .pl_op = .{
1872618726 .operand = is_non_err,
......@@ -25856,9 +25856,9 @@ fn addSafetyCheckExtra(
2585625856 fail_block.instructions.items.len);
2585725857
2585825858 try sema.air_instructions.ensureUnusedCapacity(gpa, 3);
25859 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
25860 const cond_br_inst = block_inst + 1;
25861 const br_inst = cond_br_inst + 1;
25859 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
25860 const cond_br_inst: Air.Inst.Index = @enumFromInt(@intFromEnum(block_inst) + 1);
25861 const br_inst: Air.Inst.Index = @enumFromInt(@intFromEnum(cond_br_inst) + 1);
2586225862 sema.air_instructions.appendAssumeCapacity(.{
2586325863 .tag = .block,
2586425864 .data = .{ .ty_pl = .{
......@@ -25868,7 +25868,7 @@ fn addSafetyCheckExtra(
2586825868 }),
2586925869 } },
2587025870 });
25871 sema.air_extra.appendAssumeCapacity(cond_br_inst);
25871 sema.air_extra.appendAssumeCapacity(@intFromEnum(cond_br_inst));
2587225872
2587325873 sema.air_instructions.appendAssumeCapacity(.{
2587425874 .tag = .cond_br,
......@@ -25880,8 +25880,8 @@ fn addSafetyCheckExtra(
2588025880 }),
2588125881 } },
2588225882 });
25883 sema.air_extra.appendAssumeCapacity(br_inst);
25884 sema.air_extra.appendSliceAssumeCapacity(fail_block.instructions.items);
25883 sema.air_extra.appendAssumeCapacity(@intFromEnum(br_inst));
25884 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(fail_block.instructions.items));
2588525885
2588625886 sema.air_instructions.appendAssumeCapacity(.{
2588725887 .tag = .br,
......@@ -29621,10 +29621,10 @@ fn storePtr2(
2962129621 try sema.queueFullTypeResolution(elem_ty);
2962229622
2962329623 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {
29624 const ptr_inst = Air.refToIndex(ptr).?;
29624 const ptr_inst = ptr.toIndex().?;
2962529625 const air_tags = sema.air_instructions.items(.tag);
29626 if (air_tags[ptr_inst] == .ptr_elem_ptr) {
29627 const ty_pl = sema.air_instructions.items(.data)[ptr_inst].ty_pl;
29626 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
29627 const ty_pl = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].ty_pl;
2962829628 const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data;
2962929629 _ = try block.addInst(.{
2963029630 .tag = .vector_store_elem,
......@@ -29657,9 +29657,9 @@ fn storePtr2(
2965729657/// comptime-known store to a local alloc, and updates `maybe_comptime_allocs`
2965829658/// accordingly.
2965929659fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.Ref) !void {
29660 const store_inst = Air.refToIndex(store_inst_ref).?;
29661 const inst_data = sema.air_instructions.items(.data)[store_inst].bin_op;
29662 const ptr = Air.refToIndex(inst_data.lhs) orelse return;
29660 const store_inst = store_inst_ref.toIndex().?;
29661 const inst_data = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op;
29662 const ptr = inst_data.lhs.toIndex() orelse return;
2966329663 const operand = inst_data.rhs;
2966429664
2966529665 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.
2967929679/// ptr_elem_ptr, bitcast, etc), checks whether the base pointer refers to a
2968029680/// local alloc, and updates `base_allocs` accordingly.
2968129681fn 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;
29683 const new_ptr_inst = Air.refToIndex(new_ptr) orelse return;
29682 const base_ptr_inst = base_ptr.toIndex() orelse return;
29683 const new_ptr_inst = new_ptr.toIndex() orelse return;
2968429684 const alloc_inst = sema.base_allocs.get(base_ptr_inst) orelse return;
2968529685 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)]) {
2968829688 .optional_payload_ptr_set, .errunion_payload_ptr_set => {
2968929689 const maybe_comptime_alloc = sema.maybe_comptime_allocs.getPtr(alloc_inst) orelse return;
2969029690 try maybe_comptime_alloc.non_elideable_pointers.append(sema.arena, new_ptr_inst);
2969129691 },
2969229692 .ptr_elem_ptr => {
2969329693 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;
2969529695 const bin = tmp_air.extraData(Air.Bin, pl_idx).data;
2969629696 const index_ref = bin.rhs;
2969729697
......@@ -29713,15 +29713,15 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
2971329713 const array_ty = sema.typeOf(ptr).childType(mod);
2971429714 if (array_ty.zigTypeTag(mod) != .Array) return null;
2971529715 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;
2971729717 const air_datas = sema.air_instructions.items(.data);
2971829718 const air_tags = sema.air_instructions.items(.tag);
29719 const vector_ty = while (air_tags[ptr_inst] == .bitcast) {
29720 ptr_ref = air_datas[ptr_inst].ty_op.operand;
29719 const vector_ty = while (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
29720 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
2972129721 if (!sema.isKnownZigType(ptr_ref, .Pointer)) return null;
2972229722 const child_ty = sema.typeOf(ptr_ref).childType(mod);
2972329723 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;
2972529725 } else return null;
2972629726
2972729727 // We have a pointer-to-array and a pointer-to-vector. If the elements and
......@@ -31631,7 +31631,7 @@ fn analyzeDeclVal(
3163131631 }
3163231632 const decl_ref = try sema.analyzeDeclRefInner(decl_index, false);
3163331633 const result = try sema.analyzeLoad(block, src, decl_ref, src);
31634 if (Air.refToInterned(result) != null) {
31634 if (result.toInterned() != null) {
3163531635 if (!block.is_typeof) {
3163631636 try sema.decl_val_table.put(sema.gpa, decl_index, result);
3163731637 }
......@@ -31811,10 +31811,10 @@ fn analyzeLoad(
3181131811 }
3181231812
3181331813 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {
31814 const ptr_inst = Air.refToIndex(ptr).?;
31814 const ptr_inst = ptr.toIndex().?;
3181531815 const air_tags = sema.air_instructions.items(.tag);
31816 if (air_tags[ptr_inst] == .ptr_elem_ptr) {
31817 const ty_pl = sema.air_instructions.items(.data)[ptr_inst].ty_pl;
31816 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
31817 const ty_pl = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].ty_pl;
3181831818 const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data;
3181931819 return block.addBinOp(.ptr_elem_val, bin_op.lhs, bin_op.rhs);
3182031820 }
......@@ -31932,8 +31932,8 @@ fn analyzeIsNonErrComptimeOnly(
3193231932 return .bool_false;
3193331933 }
3193431934
31935 if (Air.refToIndex(operand)) |operand_inst| {
31936 switch (sema.air_instructions.items(.tag)[operand_inst]) {
31935 if (operand.toIndex()) |operand_inst| {
31936 switch (sema.air_instructions.items(.tag)[@intFromEnum(operand_inst)]) {
3193731937 .wrap_errunion_payload => return .bool_true,
3193831938 .wrap_errunion_err => return .bool_false,
3193931939 else => {},
......@@ -37089,8 +37089,8 @@ fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void {
3708937089fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index {
3709037090 const air_datas = sema.air_instructions.items(.data);
3709137091 const air_tags = sema.air_instructions.items(.tag);
37092 switch (air_tags[inst_index]) {
37093 .br => return air_datas[inst_index].br.block_inst,
37092 switch (air_tags[@intFromEnum(inst_index)]) {
37093 .br => return air_datas[@intFromEnum(inst_index)].br.block_inst,
3709437094 else => return null,
3709537095 }
3709637096}
......@@ -38121,7 +38121,7 @@ fn errorSetMerge(sema: *Sema, lhs: Type, rhs: Type) !Type {
3812138121/// Avoids crashing the compiler when asking if inferred allocations are noreturn.
3812238122fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool {
3812338123 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)]) {
3812538125 .inferred_alloc, .inferred_alloc_comptime => return false,
3812638126 else => {},
3812738127 };
......@@ -38130,7 +38130,7 @@ fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool {
3813038130
3813138131/// Avoids crashing the compiler when asking if inferred allocations are known to be a certain zig type.
3813238132fn 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)]) {
3813438134 .inferred_alloc, .inferred_alloc_comptime => return false,
3813538135 else => {},
3813638136 };
src/arch/aarch64/CodeGen.zig+124-124
......@@ -287,7 +287,7 @@ const BigTomb = struct {
287287
288288 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {
289289 const dies = bt.lbt.feed();
290 const op_index = Air.refToIndex(op_ref) orelse return;
290 const op_index = op_ref.toIndex() orelse return;
291291 if (!dies) return;
292292 bt.function.processDeath(op_index);
293293 }
......@@ -444,7 +444,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
444444
445445 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);
448448 self.mir_instructions.appendAssumeCapacity(inst);
449449 return result_index;
450450}
......@@ -522,7 +522,7 @@ fn gen(self: *Self) !void {
522522 // The first AIR instructions of the main body are guaranteed
523523 // to be the functions arguments
524524 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
527527 const ty = self.typeOfIndex(inst);
528528
......@@ -668,7 +668,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
668668 const old_air_bookkeeping = self.air_bookkeeping;
669669 try self.ensureProcessDeathCapacity(Liveness.bpi);
670670
671 switch (air_tags[inst]) {
671 switch (air_tags[@intFromEnum(inst)]) {
672672 // zig fmt: off
673673 .add => try self.airBinOp(inst, .add),
674674 .add_wrap => try self.airBinOp(inst, .add_wrap),
......@@ -914,7 +914,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
914914
915915 if (std.debug.runtime_safety) {
916916 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)] });
918918 }
919919 }
920920 }
......@@ -954,7 +954,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
954954 const dies = @as(u1, @truncate(tomb_bits)) != 0;
955955 tomb_bits >>= 1;
956956 if (!dies) continue;
957 const op_index = Air.refToIndex(op) orelse continue;
957 const op_index = op.toIndex() orelse continue;
958958 self.processDeath(op_index);
959959 }
960960 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
......@@ -1160,19 +1160,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
11601160}
11611161
11621162fn 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;
11641164 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch});
11651165 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
11661166}
11671167
11681168fn 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;
11701170 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch});
11711171 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
11721172}
11731173
11741174fn 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;
11761176 if (self.liveness.isUnused(inst))
11771177 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
11781178
......@@ -1277,7 +1277,7 @@ fn trunc(
12771277 defer if (lock) |reg| self.register_manager.unlockReg(reg);
12781278
12791279 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
12821282 if (operand == .register and self.reuseOperand(inst, ty_op.operand, 0, operand)) {
12831283 break :blk self.registerAlias(operand_reg, dest_ty);
......@@ -1299,7 +1299,7 @@ fn trunc(
12991299}
13001300
13011301fn 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;
13031303 const operand = try self.resolveInst(ty_op.operand);
13041304 const operand_ty = self.typeOf(ty_op.operand);
13051305 const dest_ty = self.typeOfIndex(inst);
......@@ -1312,14 +1312,14 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
13121312}
13131313
13141314fn 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;
13161316 const operand = try self.resolveInst(un_op);
13171317 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
13181318 return self.finishAir(inst, result, .{ un_op, .none, .none });
13191319}
13201320
13211321fn 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;
13231323 const mod = self.bin_file.options.module.?;
13241324 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
13251325 const operand = try self.resolveInst(ty_op.operand);
......@@ -1488,8 +1488,8 @@ fn minMax(
14881488}
14891489
14901490fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
1491 const tag = self.air.instructions.items(.tag)[inst];
1492 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1491 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1492 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
14931493 const lhs_ty = self.typeOf(bin_op.lhs);
14941494 const rhs_ty = self.typeOf(bin_op.rhs);
14951495
......@@ -1506,7 +1506,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
15061506}
15071507
15081508fn 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;
15101510 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
15111511 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
15121512 const ptr = try self.resolveInst(bin_op.lhs);
......@@ -1662,7 +1662,7 @@ fn allocRegs(
16621662 arg.reg.* = self.registerAlias(raw_reg, arg.ty);
16631663 } else {
16641664 const track_inst: ?Air.Inst.Index = switch (arg.bind) {
1665 .inst => |inst| Air.refToIndex(inst).?,
1665 .inst => |inst| inst.toIndex().?,
16661666 else => null,
16671667 };
16681668 const raw_reg = try self.register_manager.allocReg(track_inst, gp);
......@@ -1725,7 +1725,7 @@ fn allocRegs(
17251725 if (mcv != .register) {
17261726 if (arg.bind == .inst) {
17271727 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
17301730 // Overwrite the MCValue associated with this inst
17311731 branch.inst_table.putAssumeCapacity(inst, .{ .register = arg.reg.* });
......@@ -2430,7 +2430,7 @@ fn ptrArithmetic(
24302430}
24312431
24322432fn 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;
24342434 const lhs_ty = self.typeOf(bin_op.lhs);
24352435 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 {
24802480}
24812481
24822482fn 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;
24842484 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
24852485 const lhs_ty = self.typeOf(bin_op.lhs);
24862486 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
24952495}
24962496
24972497fn 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;
24992499 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});
25002500 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
25012501}
25022502
25032503fn 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;
25052505 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});
25062506 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
25072507}
25082508
25092509fn 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;
25112511 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});
25122512 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
25132513}
25142514
25152515fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
2516 const tag = self.air.instructions.items(.tag)[inst];
2517 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
2516 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
2517 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
25182518 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
25192519 const mod = self.bin_file.options.module.?;
25202520 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
......@@ -2641,7 +2641,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
26412641}
26422642
26432643fn 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;
26452645 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
26462646 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
26472647 const mod = self.bin_file.options.module.?;
......@@ -2865,7 +2865,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
28652865}
28662866
28672867fn 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;
28692869 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
28702870 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
28712871 const mod = self.bin_file.options.module.?;
......@@ -3000,13 +3000,13 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
30003000}
30013001
30023002fn 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;
30043004 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
30053005 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
30063006}
30073007
30083008fn 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;
30103010 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
30113011 const optional_ty = self.typeOf(ty_op.operand);
30123012 const mcv = try self.resolveInst(ty_op.operand);
......@@ -3042,13 +3042,13 @@ fn optionalPayload(self: *Self, inst: Air.Inst.Index, mcv: MCValue, optional_ty:
30423042}
30433043
30443044fn 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;
30463046 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});
30473047 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
30483048}
30493049
30503050fn 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;
30523052 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});
30533053 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
30543054}
......@@ -3123,7 +3123,7 @@ fn errUnionErr(
31233123}
31243124
31253125fn 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;
31273127 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
31283128 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
31293129 const error_union_ty = self.typeOf(ty_op.operand);
......@@ -3203,7 +3203,7 @@ fn errUnionPayload(
32033203}
32043204
32053205fn 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;
32073207 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
32083208 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
32093209 const error_union_ty = self.typeOf(ty_op.operand);
......@@ -3215,20 +3215,20 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
32153215
32163216// *(E!T) -> E
32173217fn 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;
32193219 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});
32203220 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
32213221}
32223222
32233223// *(E!T) -> *T
32243224fn 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;
32263226 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});
32273227 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
32283228}
32293229
32303230fn 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;
32323232 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});
32333233 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
32343234}
......@@ -3253,7 +3253,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
32533253
32543254fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
32553255 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
32583258 if (self.liveness.isUnused(inst)) {
32593259 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
......@@ -3298,9 +3298,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
32983298/// T to E!T
32993299fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
33003300 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;
33023302 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();
33043304 const error_ty = error_union_ty.errorUnionSet(mod);
33053305 const payload_ty = error_union_ty.errorUnionPayload(mod);
33063306 const operand = try self.resolveInst(ty_op.operand);
......@@ -3321,10 +3321,10 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
33213321
33223322/// E to E!T
33233323fn 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;
33253325 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
33263326 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();
33283328 const error_ty = error_union_ty.errorUnionSet(mod);
33293329 const payload_ty = error_union_ty.errorUnionPayload(mod);
33303330 const operand = try self.resolveInst(ty_op.operand);
......@@ -3361,7 +3361,7 @@ fn slicePtr(mcv: MCValue) MCValue {
33613361}
33623362
33633363fn 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;
33653365 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
33663366 const mcv = try self.resolveInst(ty_op.operand);
33673367 break :result slicePtr(mcv);
......@@ -3370,7 +3370,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
33703370}
33713371
33723372fn 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;
33743374 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
33753375 const ptr_bits = 64;
33763376 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -3394,7 +3394,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
33943394}
33953395
33963396fn 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;
33983398 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
33993399 const ptr_bits = 64;
34003400 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -3411,7 +3411,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
34113411}
34123412
34133413fn 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;
34153415 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
34163416 const mcv = try self.resolveInst(ty_op.operand);
34173417 switch (mcv) {
......@@ -3427,7 +3427,7 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
34273427
34283428fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
34293429 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;
34313431 const slice_ty = self.typeOf(bin_op.lhs);
34323432 const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
34333433 const ptr_ty = slice_ty.slicePtrFieldType(mod);
......@@ -3467,7 +3467,7 @@ fn ptrElemVal(
34673467}
34683468
34693469fn 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;
34713471 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
34723472 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
34733473 const slice_mcv = try self.resolveInst(extra.lhs);
......@@ -3486,14 +3486,14 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
34863486}
34873487
34883488fn 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;
34903490 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch});
34913491 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
34923492}
34933493
34943494fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
34953495 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;
34973497 const ptr_ty = self.typeOf(bin_op.lhs);
34983498 const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
34993499 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
......@@ -3505,7 +3505,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
35053505}
35063506
35073507fn 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;
35093509 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
35103510 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
35113511 const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs };
......@@ -3521,55 +3521,55 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
35213521}
35223522
35233523fn 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;
35253525 _ = bin_op;
35263526 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});
35273527}
35283528
35293529fn 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;
35313531 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});
35323532 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
35333533}
35343534
35353535fn 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;
35373537 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});
35383538 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
35393539}
35403540
35413541fn 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;
35433543 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});
35443544 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
35453545}
35463546
35473547fn 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;
35493549 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});
35503550 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
35513551}
35523552
35533553fn 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;
35553555 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch});
35563556 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
35573557}
35583558
35593559fn 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;
35613561 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch});
35623562 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
35633563}
35643564
35653565fn 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;
35673567 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});
35683568 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
35693569}
35703570
35713571fn 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;
35733573 const result: MCValue = if (self.liveness.isUnused(inst))
35743574 .dead
35753575 else
......@@ -3609,7 +3609,7 @@ fn reuseOperand(
36093609
36103610 // That makes us responsible for doing the rest of the stuff that processDeath would have done.
36113611 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
36143614 return true;
36153615}
......@@ -3864,7 +3864,7 @@ fn genInlineMemsetCode(
38643864
38653865fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
38663866 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;
38683868 const elem_ty = self.typeOfIndex(inst);
38693869 const elem_size = elem_ty.abiSize(mod);
38703870 const result: MCValue = result: {
......@@ -4066,7 +4066,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
40664066 } else {
40674067 // TODO if the value is undef, don't lower this instruction
40684068 }
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;
40704070 const ptr = try self.resolveInst(bin_op.lhs);
40714071 const value = try self.resolveInst(bin_op.rhs);
40724072 const ptr_ty = self.typeOf(bin_op.lhs);
......@@ -4078,14 +4078,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
40784078}
40794079
40804080fn 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;
40824082 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
40834083 const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index);
40844084 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });
40854085}
40864086
40874087fn 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;
40894089 const result = try self.structFieldPtr(inst, ty_op.operand, index);
40904090 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
40914091}
......@@ -4112,7 +4112,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
41124112}
41134113
41144114fn 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;
41164116 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
41174117 const operand = extra.struct_operand;
41184118 const index = extra.field_index;
......@@ -4168,11 +4168,11 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
41684168
41694169fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
41704170 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;
41724172 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
41734173 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
41744174 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);
41764176 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, mod)));
41774177 switch (field_ptr) {
41784178 .ptr_stack_offset => |off| {
......@@ -4197,8 +4197,8 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
41974197
41984198 const mod = self.bin_file.options.module.?;
41994199 const ty = self.typeOfIndex(inst);
4200 const tag = self.air.instructions.items(.tag)[inst];
4201 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;
4200 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
4201 const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;
42024202 const name = mod.getParamName(self.func_index, src_index);
42034203
42044204 try self.dbg_info_relocs.append(self.gpa, .{
......@@ -4245,7 +4245,7 @@ fn airFence(self: *Self) !void {
42454245
42464246fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
42474247 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;
42494249 const callee = pl_op.operand;
42504250 const extra = self.air.extraData(Air.Call, pl_op.payload);
42514251 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
44234423
44244424fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44254425 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;
44274427 const operand = try self.resolveInst(un_op);
44284428 const ret_ty = self.fn_type.fnReturnType(mod);
44294429
......@@ -4455,7 +4455,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44554455
44564456fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44574457 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;
44594459 const ptr = try self.resolveInst(un_op);
44604460 const ptr_ty = self.typeOf(un_op);
44614461 const ret_ty = self.fn_type.fnReturnType(mod);
......@@ -4476,8 +4476,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44764476 // here. Else we need to load the result from the location
44774477 // pointed to by the operand and store it to the result
44784478 // location.
4479 const op_inst = Air.refToIndex(un_op).?;
4480 if (self.air.instructions.items(.tag)[op_inst] != .ret_ptr) {
4479 const op_inst = un_op.toIndex().?;
4480 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {
44814481 const abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
44824482 const abi_align = ret_ty.abiAlignment(mod);
44834483
......@@ -4497,7 +4497,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44974497}
44984498
44994499fn 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;
45014501 const lhs_ty = self.typeOf(bin_op.lhs);
45024502
45034503 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
......@@ -4599,7 +4599,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
45994599}
46004600
46014601fn 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;
46034603 const operand = try self.resolveInst(un_op);
46044604 _ = operand;
46054605 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 {
46074607}
46084608
46094609fn 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
46124612 _ = try self.addInst(.{
46134613 .tag = .dbg_line,
......@@ -4621,7 +4621,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
46214621}
46224622
46234623fn 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;
46254625 const mod = self.bin_file.options.module.?;
46264626 const func = mod.funcInfo(ty_fn.func);
46274627 // TODO emit debug info for function change
......@@ -4635,9 +4635,9 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
46354635}
46364636
46374637fn 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;
46394639 const operand = pl_op.operand;
4640 const tag = self.air.instructions.items(.tag)[inst];
4640 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
46414641 const ty = self.typeOf(operand);
46424642 const mcv = try self.resolveInst(operand);
46434643 const name = self.air.nullTerminatedString(pl_op.payload);
......@@ -4686,11 +4686,11 @@ fn condBr(self: *Self, condition: MCValue) !Mir.Inst.Index {
46864686}
46874687
46884688fn 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;
46904690 const cond = try self.resolveInst(pl_op.operand);
46914691 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];
4693 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_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: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
46944694 const liveness_condbr = self.liveness.getCondBr(inst);
46954695
46964696 const reloc = try self.condBr(cond);
......@@ -4699,7 +4699,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
46994699 // that death now instead of later as this has an effect on
47004700 // whether it needs to be spilled in the branches
47014701 if (self.liveness.operandDies(inst, 0)) {
4702 if (Air.refToIndex(pl_op.operand)) |op_index| {
4702 if (pl_op.operand.toIndex()) |op_index| {
47034703 self.processDeath(op_index);
47044704 }
47054705 }
......@@ -4917,7 +4917,7 @@ fn isNonErr(
49174917}
49184918
49194919fn 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;
49214921 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49224922 const operand = try self.resolveInst(un_op);
49234923 const operand_ty = self.typeOf(un_op);
......@@ -4929,7 +4929,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
49294929
49304930fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
49314931 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;
49334933 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49344934 const operand_ptr = try self.resolveInst(un_op);
49354935 const ptr_ty = self.typeOf(un_op);
......@@ -4944,7 +4944,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
49444944}
49454945
49464946fn 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;
49484948 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49494949 const operand = try self.resolveInst(un_op);
49504950 const operand_ty = self.typeOf(un_op);
......@@ -4956,7 +4956,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
49564956
49574957fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
49584958 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;
49604960 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49614961 const operand_ptr = try self.resolveInst(un_op);
49624962 const ptr_ty = self.typeOf(un_op);
......@@ -4971,7 +4971,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
49714971}
49724972
49734973fn 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;
49754975 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49764976 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
49774977 const error_union_ty = self.typeOf(un_op);
......@@ -4983,7 +4983,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49834983
49844984fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49854985 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;
49874987 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49884988 const operand_ptr = try self.resolveInst(un_op);
49894989 const ptr_ty = self.typeOf(un_op);
......@@ -4998,7 +4998,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49984998}
49994999
50005000fn 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;
50025002 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
50035003 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
50045004 const error_union_ty = self.typeOf(un_op);
......@@ -5010,7 +5010,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
50105010
50115011fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
50125012 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;
50145014 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
50155015 const operand_ptr = try self.resolveInst(un_op);
50165016 const ptr_ty = self.typeOf(un_op);
......@@ -5026,9 +5026,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
50265026
50275027fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
50285028 // 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;
50305030 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]);
50325032 const start_index = @as(u32, @intCast(self.mir_instructions.len));
50335033
50345034 try self.genBody(body);
......@@ -5058,9 +5058,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
50585058 });
50595059 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;
50625062 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]);
50645064 try self.genBody(body);
50655065
50665066 // relocations for `br` instructions
......@@ -5080,7 +5080,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
50805080}
50815081
50825082fn 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;
50845084 const condition_ty = self.typeOf(pl_op.operand);
50855085 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
50865086 const liveness = try self.liveness.getSwitchBr(
......@@ -5096,7 +5096,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
50965096 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
50975097 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));
50985098 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]);
51005100 extra_index = case.end + items.len + case_body.len;
51015101
51025102 // For every item, we compare it to condition and branch into
......@@ -5167,7 +5167,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
51675167 }
51685168
51695169 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
51725172 // Capture the state of register and stack allocation state so that we can revert to it.
51735173 const parent_next_stack_offset = self.next_stack_offset;
......@@ -5212,15 +5212,15 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
52125212fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
52135213 const tag = self.mir_instructions.items(.tag)[inst];
52145214 switch (tag) {
5215 .cbz => self.mir_instructions.items(.data)[inst].r_inst.inst = @as(Mir.Inst.Index, @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)),
5217 .b => self.mir_instructions.items(.data)[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 = @intCast(self.mir_instructions.len),
5217 .b => self.mir_instructions.items(.data)[inst].inst = @intCast(self.mir_instructions.len),
52185218 else => unreachable,
52195219 }
52205220}
52215221
52225222fn 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;
52245224 try self.br(branch.block_inst, branch.operand);
52255225 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });
52265226}
......@@ -5263,7 +5263,7 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
52635263}
52645264
52655265fn 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;
52675267 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
52685268 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
52695269 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
59075907}
59085908
59095909fn 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;
59115911 const result = try self.resolveInst(un_op);
59125912 return self.finishAir(inst, result, .{ un_op, .none, .none });
59135913}
59145914
59155915fn 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;
59175917 const result = if (self.liveness.isUnused(inst)) .dead else result: {
59185918 const operand = try self.resolveInst(ty_op.operand);
59195919 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 {
59355935
59365936fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
59375937 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;
59395939 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
59405940 const ptr_ty = self.typeOf(ty_op.operand);
59415941 const ptr = try self.resolveInst(ty_op.operand);
......@@ -5951,7 +5951,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
59515951}
59525952
59535953fn 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;
59555955 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
59565956 self.target.cpu.arch,
59575957 });
......@@ -5959,7 +5959,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
59595959}
59605960
59615961fn 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;
59635963 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
59645964 self.target.cpu.arch,
59655965 });
......@@ -5967,7 +5967,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
59675967}
59685968
59695969fn 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;
59715971 const extra = self.air.extraData(Air.Block, ty_pl.payload);
59725972 _ = extra;
59735973
......@@ -6008,7 +6008,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
60086008}
60096009
60106010fn 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;
60126012 const operand = try self.resolveInst(un_op);
60136013 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
60146014 _ = operand;
......@@ -6018,7 +6018,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
60186018}
60196019
60206020fn 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;
60226022 const operand = try self.resolveInst(un_op);
60236023 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
60246024 _ = operand;
......@@ -6028,27 +6028,27 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
60286028}
60296029
60306030fn 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;
60326032 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for {}", .{self.target.cpu.arch});
60336033 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
60346034}
60356035
60366036fn 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;
60386038 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
60396039 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for {}", .{self.target.cpu.arch});
60406040 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
60416041}
60426042
60436043fn 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;
60456045 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
60466046 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for {}", .{self.target.cpu.arch});
60476047 return self.finishAir(inst, result, .{ extra.a, extra.b, .none });
60486048}
60496049
60506050fn 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;
60526052 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for aarch64", .{});
60536053 return self.finishAir(inst, result, .{ reduce.operand, .none, .none });
60546054}
......@@ -6057,7 +6057,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60576057 const mod = self.bin_file.options.module.?;
60586058 const vector_ty = self.typeOfIndex(inst);
60596059 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;
60616061 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
60626062 const result: MCValue = res: {
60636063 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
......@@ -6077,19 +6077,19 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60776077}
60786078
60796079fn 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;
60816081 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
60826082 _ = extra;
60836083 return self.fail("TODO implement airUnionInit for aarch64", .{});
60846084}
60856085
60866086fn 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;
60886088 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });
60896089}
60906090
60916091fn 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;
60936093 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
60946094 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
60956095 return self.fail("TODO implement airMulAdd for aarch64", .{});
......@@ -6099,9 +6099,9 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
60996099
61006100fn airTry(self: *Self, inst: Air.Inst.Index) !void {
61016101 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;
61036103 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]);
61056105 const result: MCValue = result: {
61066106 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
61076107 const error_union_ty = self.typeOf(pl_op.operand);
......@@ -6126,7 +6126,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
61266126}
61276127
61286128fn 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;
61306130 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
61316131 const body = self.air.extra[extra.end..][0..extra.data.body_len];
61326132 _ = body;
......@@ -6142,7 +6142,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
61426142 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod))
61436143 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(.{
61466146 .ty = inst_ty,
61476147 .val = (try self.air.value(inst, mod)).?,
61486148 });
src/arch/arm/CodeGen.zig+200-200
......@@ -200,7 +200,7 @@ const BigTomb = struct {
200200
201201 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {
202202 const dies = bt.lbt.feed();
203 const op_index = Air.refToIndex(op_ref) orelse return;
203 const op_index = op_ref.toIndex() orelse return;
204204 if (!dies) return;
205205 bt.function.processDeath(op_index);
206206 }
......@@ -450,7 +450,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
450450
451451 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);
454454 self.mir_instructions.appendAssumeCapacity(inst);
455455 return result_index;
456456}
......@@ -470,11 +470,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
470470
471471pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
472472 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);
474474 inline for (fields) |field| {
475475 self.mir_extra.appendAssumeCapacity(switch (field.type) {
476476 u32 => @field(extra, field.name),
477 i32 => @as(u32, @bitCast(@field(extra, field.name))),
477 i32 => @bitCast(@field(extra, field.name)),
478478 else => @compileError("bad field type"),
479479 });
480480 }
......@@ -522,11 +522,11 @@ fn gen(self: *Self) !void {
522522 // The first AIR instructions of the main body are guaranteed
523523 // to be the functions arguments
524524 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
527527 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));
530530 const abi_align = ty.abiAlignment(mod);
531531 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
532532 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
......@@ -592,7 +592,7 @@ fn gen(self: *Self) !void {
592592 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
593593 self.mir_instructions.set(jmp_reloc, .{
594594 .tag = .b,
595 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len)) },
595 .data = .{ .inst = @intCast(self.mir_instructions.len) },
596596 });
597597 }
598598
......@@ -654,7 +654,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
654654 const old_air_bookkeeping = self.air_bookkeeping;
655655 try self.ensureProcessDeathCapacity(Liveness.bpi);
656656
657 switch (air_tags[inst]) {
657 switch (air_tags[@intFromEnum(inst)]) {
658658 // zig fmt: off
659659 .add, => try self.airBinOp(inst, .add),
660660 .add_wrap => try self.airBinOp(inst, .add_wrap),
......@@ -900,7 +900,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
900900
901901 if (std.debug.runtime_safety) {
902902 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)] });
904904 }
905905 }
906906 }
......@@ -942,7 +942,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
942942 const dies = @as(u1, @truncate(tomb_bits)) != 0;
943943 tomb_bits >>= 1;
944944 if (!dies) continue;
945 const op_index = Air.refToIndex(op) orelse continue;
945 const op_index = op.toIndex() orelse continue;
946946 self.processDeath(op_index);
947947 }
948948 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
......@@ -1018,7 +1018,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
10181018 // return the stack offset 0. Stack offset 0 will be where all
10191019 // zero-sized stack allocations live as non-zero-sized
10201020 // allocations will always have an offset > 0.
1021 return @as(u32, 0);
1021 return 0;
10221022 }
10231023
10241024 const abi_size = math.cast(u32, elem_ty.abiSize(mod)) orelse {
......@@ -1139,20 +1139,20 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
11391139}
11401140
11411141fn 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;
11431143 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch});
11441144 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
11451145}
11461146
11471147fn 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;
11491149 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch});
11501150 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
11511151}
11521152
11531153fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
11541154 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;
11561156 if (self.liveness.isUnused(inst))
11571157 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
11581158
......@@ -1204,7 +1204,7 @@ fn truncRegister(
12041204 .rd = dest_reg,
12051205 .rn = operand_reg,
12061206 .lsb = 0,
1207 .width = @as(u6, @intCast(int_bits)),
1207 .width = @intCast(int_bits),
12081208 } },
12091209 });
12101210}
......@@ -1260,7 +1260,7 @@ fn trunc(
12601260}
12611261
12621262fn 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;
12641264 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
12651265 const operand_ty = self.typeOf(ty_op.operand);
12661266 const dest_ty = self.typeOfIndex(inst);
......@@ -1273,14 +1273,14 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
12731273}
12741274
12751275fn 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;
12771277 const operand = try self.resolveInst(un_op);
12781278 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
12791279 return self.finishAir(inst, result, .{ un_op, .none, .none });
12801280}
12811281
12821282fn 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;
12841284 const mod = self.bin_file.options.module.?;
12851285 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
12861286 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
......@@ -1465,8 +1465,8 @@ fn minMax(
14651465}
14661466
14671467fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
1468 const tag = self.air.instructions.items(.tag)[inst];
1469 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1468 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1469 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
14701470 const lhs_ty = self.typeOf(bin_op.lhs);
14711471 const rhs_ty = self.typeOf(bin_op.rhs);
14721472
......@@ -1483,7 +1483,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
14831483}
14841484
14851485fn 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;
14871487 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
14881488 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
14891489 const ptr = try self.resolveInst(bin_op.lhs);
......@@ -1500,7 +1500,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
15001500}
15011501
15021502fn 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;
15041504 const lhs_ty = self.typeOf(bin_op.lhs);
15051505 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 {
15501550}
15511551
15521552fn 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;
15541554 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
15551555 const lhs_ty = self.typeOf(bin_op.lhs);
15561556 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
15651565}
15661566
15671567fn 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;
15691569 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});
15701570 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
15711571}
15721572
15731573fn 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;
15751575 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});
15761576 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
15771577}
15781578
15791579fn 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;
15811581 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});
15821582 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
15831583}
15841584
15851585fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
1586 const tag = self.air.instructions.items(.tag)[inst];
1587 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
1586 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1587 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
15881588 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
15891589 const mod = self.bin_file.options.module.?;
15901590 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
......@@ -1594,9 +1594,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
15941594 const rhs_ty = self.typeOf(extra.rhs);
15951595
15961596 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));
15981598 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
16011601 switch (lhs_ty.zigTypeTag(mod)) {
16021602 .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 {
16961696}
16971697
16981698fn 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;
17001700 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
17011701 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
17021702 const mod = self.bin_file.options.module.?;
......@@ -1707,9 +1707,9 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
17071707 const rhs_ty = self.typeOf(extra.rhs);
17081708
17091709 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));
17111711 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
17141714 switch (lhs_ty.zigTypeTag(mod)) {
17151715 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
......@@ -1860,7 +1860,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
18601860}
18611861
18621862fn 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;
18641864 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
18651865 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
18661866 const mod = self.bin_file.options.module.?;
......@@ -1869,9 +1869,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
18691869 const rhs_ty = self.typeOf(extra.rhs);
18701870
18711871 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));
18731873 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
18761876 switch (lhs_ty.zigTypeTag(mod)) {
18771877 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
......@@ -1918,7 +1918,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
19181918 .data = .{ .rr_shift = .{
19191919 .rd = dest_reg,
19201920 .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)),
19221922 } },
19231923 });
19241924
......@@ -1930,7 +1930,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
19301930 .data = .{ .rr_shift = .{
19311931 .rd = reconstructed_reg,
19321932 .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)),
19341934 } },
19351935 });
19361936 } else {
......@@ -1995,35 +1995,35 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
19951995}
19961996
19971997fn 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;
19991999 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
20002000 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
20012001}
20022002
20032003fn 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;
20052005 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch});
20062006 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
20072007}
20082008
20092009fn 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;
20112011 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});
20122012 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
20132013}
20142014
20152015fn 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;
20172017 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});
20182018 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
20192019}
20202020
20212021fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
20222022 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;
20242024 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20252025 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
20282028 // Optional with a zero-bit payload type is just a boolean true
20292029 if (abi_size == 1) {
......@@ -2052,7 +2052,7 @@ fn errUnionErr(
20522052 return try error_union_bind.resolveToMcv(self);
20532053 }
20542054
2055 const err_offset = @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod)));
2055 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, mod));
20562056 switch (try error_union_bind.resolveToMcv(self)) {
20572057 .register => {
20582058 var operand_reg: Register = undefined;
......@@ -2074,15 +2074,15 @@ fn errUnionErr(
20742074 );
20752075
20762076 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
20792079 _ = try self.addInst(.{
20802080 .tag = .ubfx, // errors are unsigned integers
20812081 .data = .{ .rr_lsb_width = .{
20822082 .rd = dest_reg,
20832083 .rn = operand_reg,
2084 .lsb = @as(u5, @intCast(err_bit_offset)),
2085 .width = @as(u6, @intCast(err_bit_size)),
2084 .lsb = @intCast(err_bit_offset),
2085 .width = @intCast(err_bit_size),
20862086 } },
20872087 });
20882088
......@@ -2102,7 +2102,7 @@ fn errUnionErr(
21022102}
21032103
21042104fn 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;
21062106 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
21072107 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
21082108 const error_union_ty = self.typeOf(ty_op.operand);
......@@ -2129,7 +2129,7 @@ fn errUnionPayload(
21292129 return MCValue.none;
21302130 }
21312131
2132 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod)));
2132 const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, mod));
21332133 switch (try error_union_bind.resolveToMcv(self)) {
21342134 .register => {
21352135 var operand_reg: Register = undefined;
......@@ -2151,15 +2151,15 @@ fn errUnionPayload(
21512151 );
21522152
21532153 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
21562156 _ = try self.addInst(.{
21572157 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
21582158 .data = .{ .rr_lsb_width = .{
21592159 .rd = dest_reg,
21602160 .rn = operand_reg,
2161 .lsb = @as(u5, @intCast(payload_bit_offset)),
2162 .width = @as(u6, @intCast(payload_bit_size)),
2161 .lsb = @intCast(payload_bit_offset),
2162 .width = @intCast(payload_bit_size),
21632163 } },
21642164 });
21652165
......@@ -2179,7 +2179,7 @@ fn errUnionPayload(
21792179}
21802180
21812181fn 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;
21832183 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
21842184 const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
21852185 const error_union_ty = self.typeOf(ty_op.operand);
......@@ -2191,20 +2191,20 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
21912191
21922192// *(E!T) -> E
21932193fn 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;
21952195 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});
21962196 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
21972197}
21982198
21992199// *(E!T) -> *T
22002200fn 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;
22022202 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});
22032203 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
22042204}
22052205
22062206fn 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;
22082208 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});
22092209 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
22102210}
......@@ -2230,17 +2230,17 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
22302230/// T to E!T
22312231fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
22322232 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;
22342234 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();
22362236 const error_ty = error_union_ty.errorUnionSet(mod);
22372237 const payload_ty = error_union_ty.errorUnionPayload(mod);
22382238 const operand = try self.resolveInst(ty_op.operand);
22392239 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));
22422242 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));
22442244 const payload_off = errUnionPayloadOffset(payload_ty, mod);
22452245 const err_off = errUnionErrorOffset(payload_ty, mod);
22462246 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 {
22542254/// E to E!T
22552255fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
22562256 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;
22582258 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();
22602260 const error_ty = error_union_ty.errorUnionSet(mod);
22612261 const payload_ty = error_union_ty.errorUnionPayload(mod);
22622262 const operand = try self.resolveInst(ty_op.operand);
22632263 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));
22662266 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));
22682268 const payload_off = errUnionPayloadOffset(payload_ty, mod);
22692269 const err_off = errUnionErrorOffset(payload_ty, mod);
22702270 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
......@@ -2293,7 +2293,7 @@ fn slicePtr(mcv: MCValue) MCValue {
22932293}
22942294
22952295fn 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;
22972297 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
22982298 const mcv = try self.resolveInst(ty_op.operand);
22992299 break :result slicePtr(mcv);
......@@ -2302,7 +2302,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
23022302}
23032303
23042304fn 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;
23062306 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
23072307 const mcv = try self.resolveInst(ty_op.operand);
23082308 switch (mcv) {
......@@ -2323,7 +2323,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
23232323}
23242324
23252325fn 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;
23272327 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
23282328 const mcv = try self.resolveInst(ty_op.operand);
23292329 switch (mcv) {
......@@ -2343,7 +2343,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
23432343}
23442344
23452345fn 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;
23472347 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
23482348 const mcv = try self.resolveInst(ty_op.operand);
23492349 switch (mcv) {
......@@ -2372,7 +2372,7 @@ fn ptrElemVal(
23722372) !MCValue {
23732373 const mod = self.bin_file.options.module.?;
23742374 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
23772377 switch (elem_size) {
23782378 1, 4 => {
......@@ -2430,7 +2430,7 @@ fn ptrElemVal(
24302430
24312431fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24322432 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;
24342434 const slice_ty = self.typeOf(bin_op.lhs);
24352435 const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
24362436 const ptr_ty = slice_ty.slicePtrFieldType(mod);
......@@ -2447,7 +2447,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24472447}
24482448
24492449fn 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;
24512451 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
24522452 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
24532453 const slice_mcv = try self.resolveInst(extra.lhs);
......@@ -2483,7 +2483,7 @@ fn arrayElemVal(
24832483 => {
24842484 const ptr_to_mcv = switch (mcv) {
24852485 .stack_offset => |off| MCValue{ .ptr_stack_offset = off },
2486 .memory => |addr| MCValue{ .immediate = @as(u32, @intCast(addr)) },
2486 .memory => |addr| MCValue{ .immediate = @intCast(addr) },
24872487 .stack_argument_offset => |off| blk: {
24882488 const reg = try self.register_manager.allocReg(null, gp);
24892489
......@@ -2516,7 +2516,7 @@ fn arrayElemVal(
25162516}
25172517
25182518fn 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;
25202520 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
25212521 const array_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
25222522 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };
......@@ -2529,7 +2529,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
25292529
25302530fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
25312531 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;
25332533 const ptr_ty = self.typeOf(bin_op.lhs);
25342534 const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
25352535 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
......@@ -2541,7 +2541,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
25412541}
25422542
25432543fn 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;
25452545 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
25462546 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
25472547 const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs };
......@@ -2557,63 +2557,63 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
25572557}
25582558
25592559fn 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;
25612561 _ = bin_op;
25622562 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});
25632563 // return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
25642564}
25652565
25662566fn 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;
25682568 _ = ty_op;
25692569 return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});
25702570 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
25712571}
25722572
25732573fn 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;
25752575 _ = ty_op;
25762576 return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});
25772577 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
25782578}
25792579
25802580fn 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;
25822582 _ = ty_op;
25832583 return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});
25842584 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
25852585}
25862586
25872587fn 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;
25892589 _ = ty_op;
25902590 return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});
25912591 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
25922592}
25932593
25942594fn 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;
25962596 _ = ty_op;
25972597 return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch});
25982598 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
25992599}
26002600
26012601fn 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;
26032603 _ = ty_op;
26042604 return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch});
26052605 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
26062606}
26072607
26082608fn 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;
26102610 _ = ty_op;
26112611 return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});
26122612 // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
26132613}
26142614
26152615fn 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;
26172617 const result: MCValue = if (self.liveness.isUnused(inst))
26182618 .dead
26192619 else
......@@ -2656,7 +2656,7 @@ fn reuseOperand(
26562656
26572657 // That makes us responsible for doing the rest of the stuff that processDeath would have done.
26582658 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
26612661 return true;
26622662}
......@@ -2664,7 +2664,7 @@ fn reuseOperand(
26642664fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
26652665 const mod = self.bin_file.options.module.?;
26662666 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
26692669 switch (ptr) {
26702670 .none => unreachable,
......@@ -2740,7 +2740,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
27402740
27412741fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27422742 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;
27442744 const elem_ty = self.typeOfIndex(inst);
27452745 const result: MCValue = result: {
27462746 if (!elem_ty.hasRuntimeBits(mod))
......@@ -2769,7 +2769,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27692769
27702770fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
27712771 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
27742774 switch (ptr) {
27752775 .none => unreachable,
......@@ -2824,7 +2824,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
28242824 // sub src_reg, fp, #off
28252825 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
28262826 },
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) }),
28282828 .stack_argument_offset => |off| {
28292829 _ = try self.addInst(.{
28302830 .tag = .ldr_ptr_stack_argument,
......@@ -2862,7 +2862,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
28622862 } else {
28632863 // TODO if the value is undef, don't lower this instruction
28642864 }
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;
28662866 const ptr = try self.resolveInst(bin_op.lhs);
28672867 const value = try self.resolveInst(bin_op.rhs);
28682868 const ptr_ty = self.typeOf(bin_op.lhs);
......@@ -2874,14 +2874,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
28742874}
28752875
28762876fn 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;
28782878 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
28792879 const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index);
28802880 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });
28812881}
28822882
28832883fn 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;
28852885 const result = try self.structFieldPtr(inst, ty_op.operand, index);
28862886 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
28872887}
......@@ -2892,7 +2892,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
28922892 const mcv = try self.resolveInst(operand);
28932893 const ptr_ty = self.typeOf(operand);
28942894 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));
28962896 switch (mcv) {
28972897 .ptr_stack_offset => |off| {
28982898 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
29082908}
29092909
29102910fn 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;
29122912 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
29132913 const operand = extra.struct_operand;
29142914 const index = extra.field_index;
......@@ -2916,7 +2916,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
29162916 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
29172917 const mcv = try self.resolveInst(operand);
29182918 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));
29202920 const struct_field_ty = struct_ty.structFieldType(index, mod);
29212921
29222922 switch (mcv) {
......@@ -2980,15 +2980,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
29802980 );
29812981
29822982 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
29852985 _ = try self.addInst(.{
29862986 .tag = if (struct_field_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
29872987 .data = .{ .rr_lsb_width = .{
29882988 .rd = dest_reg,
29892989 .rn = operand_reg,
2990 .lsb = @as(u5, @intCast(field_bit_offset)),
2991 .width = @as(u6, @intCast(field_bit_size)),
2990 .lsb = @intCast(field_bit_offset),
2991 .width = @intCast(field_bit_size),
29922992 } },
29932993 });
29942994
......@@ -3003,17 +3003,17 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
30033003
30043004fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
30053005 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;
30073007 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
30083008 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
30093009 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
30123012 if (struct_ty.zigTypeTag(mod) == .Union) {
30133013 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});
30143014 }
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));
30173017 switch (field_ptr) {
30183018 .ptr_stack_offset => |off| {
30193019 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };
......@@ -3168,7 +3168,7 @@ fn allocRegs(
31683168 arg.reg.* = mcv.register;
31693169 } else {
31703170 const track_inst: ?Air.Inst.Index = switch (arg.bind) {
3171 .inst => |inst| Air.refToIndex(inst).?,
3171 .inst => |inst| inst.toIndex().?,
31723172 else => null,
31733173 };
31743174 arg.reg.* = try self.register_manager.allocReg(track_inst, arg.class);
......@@ -3225,7 +3225,7 @@ fn allocRegs(
32253225 if (mcv != .register) {
32263226 if (arg.bind == .inst) {
32273227 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
32303230 // Overwrite the MCValue associated with this inst
32313231 branch.inst_table.putAssumeCapacity(inst, .{ .register = arg.reg.* });
......@@ -3374,7 +3374,7 @@ fn binOpImmediate(
33743374 => .{ .rr_shift = .{
33753375 .rd = dest_reg,
33763376 .rm = lhs_reg,
3377 .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_immediate))),
3377 .shift_amount = Instruction.ShiftAmount.imm(@intCast(rhs_immediate)),
33783378 } },
33793379 else => unreachable,
33803380 };
......@@ -3905,7 +3905,7 @@ fn ptrArithmetic(
39053905 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
39063906 else => ptr_ty.childType(mod),
39073907 };
3908 const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod)));
3908 const elem_size: u32 = @intCast(elem_ty.abiSize(mod));
39093909
39103910 const base_tag: Air.Inst.Tag = switch (tag) {
39113911 .ptr_add => .add,
......@@ -4032,7 +4032,7 @@ fn genInlineMemcpy(
40324032 _ = try self.addInst(.{
40334033 .tag = .b,
40344034 .cond = .ge,
4035 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 5)) },
4035 .data = .{ .inst = @intCast(self.mir_instructions.len + 5) },
40364036 });
40374037
40384038 // ldrb tmp, [src, count]
......@@ -4068,7 +4068,7 @@ fn genInlineMemcpy(
40684068 // b loop
40694069 _ = try self.addInst(.{
40704070 .tag = .b,
4071 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 5)) },
4071 .data = .{ .inst = @intCast(self.mir_instructions.len - 5) },
40724072 });
40734073
40744074 // end:
......@@ -4136,7 +4136,7 @@ fn genInlineMemsetCode(
41364136 _ = try self.addInst(.{
41374137 .tag = .b,
41384138 .cond = .ge,
4139 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 4)) },
4139 .data = .{ .inst = @intCast(self.mir_instructions.len + 4) },
41404140 });
41414141
41424142 // strb val, [src, count]
......@@ -4162,7 +4162,7 @@ fn genInlineMemsetCode(
41624162 // b loop
41634163 _ = try self.addInst(.{
41644164 .tag = .b,
4165 .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 4)) },
4165 .data = .{ .inst = @intCast(self.mir_instructions.len - 4) },
41664166 });
41674167
41684168 // end:
......@@ -4176,8 +4176,8 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
41764176
41774177 const mod = self.bin_file.options.module.?;
41784178 const ty = self.typeOfIndex(inst);
4179 const tag = self.air.instructions.items(.tag)[inst];
4180 const src_index = self.air.instructions.items(.data)[inst].arg.src_index;
4179 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
4180 const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index;
41814181 const name = mod.getParamName(self.func_index, src_index);
41824182
41834183 try self.dbg_info_relocs.append(self.gpa, .{
......@@ -4224,10 +4224,10 @@ fn airFence(self: *Self) !void {
42244224
42254225fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
42264226 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;
42284228 const callee = pl_op.operand;
42294229 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]);
42314231 const ty = self.typeOf(callee);
42324232 const mod = self.bin_file.options.module.?;
42334233
......@@ -4305,7 +4305,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43054305 const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl);
43064306 const sym = elf_file.symbol(sym_index);
43074307 _ = 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));
43094309 try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr });
43104310 } else if (self.bin_file.cast(link.File.MachO)) |_| {
43114311 unreachable; // unsupported architecture for MachO
......@@ -4381,7 +4381,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43814381
43824382fn airRet(self: *Self, inst: Air.Inst.Index) !void {
43834383 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;
43854385 const operand = try self.resolveInst(un_op);
43864386 const ret_ty = self.fn_type.fnReturnType(mod);
43874387
......@@ -4413,7 +4413,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44134413
44144414fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44154415 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;
44174417 const ptr = try self.resolveInst(un_op);
44184418 const ptr_ty = self.typeOf(un_op);
44194419 const ret_ty = self.fn_type.fnReturnType(mod);
......@@ -4434,9 +4434,9 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44344434 // here. Else we need to load the result from the location
44354435 // pointed to by the operand and store it to the result
44364436 // location.
4437 const op_inst = Air.refToIndex(un_op).?;
4438 if (self.air.instructions.items(.tag)[op_inst] != .ret_ptr) {
4439 const abi_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
4437 const op_inst = un_op.toIndex().?;
4438 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {
4439 const abi_size: u32 = @intCast(ret_ty.abiSize(mod));
44404440 const abi_align = ret_ty.abiAlignment(mod);
44414441
44424442 const offset = try self.allocMem(abi_size, abi_align, null);
......@@ -4456,7 +4456,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44564456}
44574457
44584458fn 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;
44604460 const lhs_ty = self.typeOf(bin_op.lhs);
44614461
44624462 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: {
......@@ -4556,7 +4556,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
45564556}
45574557
45584558fn 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;
45604560 const operand = try self.resolveInst(un_op);
45614561 _ = operand;
45624562 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 {
45644564}
45654565
45664566fn 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
45694569 _ = try self.addInst(.{
45704570 .tag = .dbg_line,
......@@ -4579,7 +4579,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
45794579}
45804580
45814581fn 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;
45834583 const mod = self.bin_file.options.module.?;
45844584 const func = mod.funcInfo(ty_fn.func);
45854585 // TODO emit debug info for function change
......@@ -4593,9 +4593,9 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
45934593}
45944594
45954595fn 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;
45974597 const operand = pl_op.operand;
4598 const tag = self.air.instructions.items(.tag)[inst];
4598 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
45994599 const ty = self.typeOf(operand);
46004600 const mcv = try self.resolveInst(operand);
46014601 const name = self.air.nullTerminatedString(pl_op.payload);
......@@ -4647,11 +4647,11 @@ fn condBr(self: *Self, condition: MCValue) !Mir.Inst.Index {
46474647}
46484648
46494649fn 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;
46514651 const cond_inst = try self.resolveInst(pl_op.operand);
46524652 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];
4654 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_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: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
46554655 const liveness_condbr = self.liveness.getCondBr(inst);
46564656
46574657 const reloc: Mir.Inst.Index = try self.condBr(cond_inst);
......@@ -4660,7 +4660,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
46604660 // that death now instead of later as this has an effect on
46614661 // whether it needs to be spilled in the branches
46624662 if (self.liveness.operandDies(inst, 0)) {
4663 if (Air.refToIndex(pl_op.operand)) |op_index| {
4663 if (pl_op.operand.toIndex()) |op_index| {
46644664 self.processDeath(op_index);
46654665 }
46664666 }
......@@ -4818,7 +4818,7 @@ fn isNonNull(
48184818}
48194819
48204820fn 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;
48224822 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48234823 const operand_bind: ReadArg.Bind = .{ .inst = un_op };
48244824 const operand_ty = self.typeOf(un_op);
......@@ -4830,7 +4830,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
48304830
48314831fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
48324832 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;
48344834 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48354835 const operand_ptr = try self.resolveInst(un_op);
48364836 const ptr_ty = self.typeOf(un_op);
......@@ -4845,7 +4845,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
48454845}
48464846
48474847fn 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;
48494849 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48504850 const operand_bind: ReadArg.Bind = .{ .inst = un_op };
48514851 const operand_ty = self.typeOf(un_op);
......@@ -4857,7 +4857,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
48574857
48584858fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
48594859 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;
48614861 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48624862 const operand_ptr = try self.resolveInst(un_op);
48634863 const ptr_ty = self.typeOf(un_op);
......@@ -4907,7 +4907,7 @@ fn isNonErr(
49074907}
49084908
49094909fn 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;
49114911 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49124912 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
49134913 const error_union_ty = self.typeOf(un_op);
......@@ -4919,7 +4919,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49194919
49204920fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49214921 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;
49234923 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49244924 const operand_ptr = try self.resolveInst(un_op);
49254925 const ptr_ty = self.typeOf(un_op);
......@@ -4934,7 +4934,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49344934}
49354935
49364936fn 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;
49384938 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49394939 const error_union_bind: ReadArg.Bind = .{ .inst = un_op };
49404940 const error_union_ty = self.typeOf(un_op);
......@@ -4946,7 +4946,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
49464946
49474947fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49484948 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;
49504950 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49514951 const operand_ptr = try self.resolveInst(un_op);
49524952 const ptr_ty = self.typeOf(un_op);
......@@ -4962,10 +4962,10 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49624962
49634963fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
49644964 // 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;
49664966 const loop = self.air.extraData(Air.Block, ty_pl.payload);
4967 const body = self.air.extra[loop.end..][0..loop.data.body_len];
4968 const start_index = @as(Mir.Inst.Index, @intCast(self.mir_instructions.len));
4967 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);
4968 const start_index: Mir.Inst.Index = @intCast(self.mir_instructions.len);
49694969
49704970 try self.genBody(body);
49714971 try self.jump(start_index);
......@@ -4994,9 +4994,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
49944994 });
49954995 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;
49984998 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]);
50005000 try self.genBody(body);
50015001
50025002 // relocations for `br` instructions
......@@ -5016,7 +5016,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
50165016}
50175017
50185018fn 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;
50205020 const condition_ty = self.typeOf(pl_op.operand);
50215021 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
50225022 const liveness = try self.liveness.getSwitchBr(
......@@ -5030,9 +5030,9 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
50305030 var case_i: u32 = 0;
50315031 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
50325032 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]);
50345034 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]);
50365036 extra_index = case.end + items.len + case_body.len;
50375037
50385038 // For every item, we compare it to condition and branch into
......@@ -5103,7 +5103,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
51035103 }
51045104
51055105 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
51085108 // Capture the state of register and stack allocation state so that we can revert to it.
51095109 const parent_next_stack_offset = self.next_stack_offset;
......@@ -5148,13 +5148,13 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
51485148fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
51495149 const tag = self.mir_instructions.items(.tag)[inst];
51505150 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),
51525152 else => unreachable,
51535153 }
51545154}
51555155
51565156fn 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;
51585158 try self.br(branch.block_inst, branch.operand);
51595159 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });
51605160}
......@@ -5195,14 +5195,14 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void {
51955195}
51965196
51975197fn 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;
51995199 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
52005200 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);
52025202 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]);
52045204 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]);
52065206 extra_i += inputs.len;
52075207
52085208 const dead = !is_volatile and self.liveness.isUnused(inst);
......@@ -5332,7 +5332,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
53325332
53335333fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
53345334 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));
53365336 switch (mcv) {
53375337 .dead => unreachable,
53385338 .unreach, .none => return, // Nothing to do.
......@@ -5385,7 +5385,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
53855385 },
53865386 2 => {
53875387 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));
53895389 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
53905390
53915391 _ = try self.addInst(.{
......@@ -5413,7 +5413,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
54135413 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg });
54145414
54155415 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));
54175417 const cond_reg = try self.register_manager.allocReg(null, gp);
54185418
54195419 // C flag: movcs reg, #1
......@@ -5466,7 +5466,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
54665466 // sub src_reg, fp, #off
54675467 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
54685468 },
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) }),
54705470 .stack_argument_offset => |off| {
54715471 _ = try self.addInst(.{
54725472 .tag = .ldr_ptr_stack_argument,
......@@ -5563,7 +5563,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
55635563 .tag = .movw,
55645564 .data = .{ .r_imm16 = .{
55655565 .rd = reg,
5566 .imm16 = @as(u16, @intCast(x)),
5566 .imm16 = @intCast(x),
55675567 } },
55685568 });
55695569 } else {
......@@ -5571,7 +5571,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
55715571 .tag = .mov,
55725572 .data = .{ .r_op_mov = .{
55735573 .rd = reg,
5574 .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0),
5574 .op = Instruction.Operand.imm(@truncate(x), 0),
55755575 } },
55765576 });
55775577 _ = try self.addInst(.{
......@@ -5579,7 +5579,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
55795579 .data = .{ .rr_op = .{
55805580 .rd = reg,
55815581 .rn = reg,
5582 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12),
5582 .op = Instruction.Operand.imm(@truncate(x >> 8), 12),
55835583 } },
55845584 });
55855585 }
......@@ -5594,14 +5594,14 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
55945594 .tag = .movw,
55955595 .data = .{ .r_imm16 = .{
55965596 .rd = reg,
5597 .imm16 = @as(u16, @truncate(x)),
5597 .imm16 = @truncate(x),
55985598 } },
55995599 });
56005600 _ = try self.addInst(.{
56015601 .tag = .movt,
56025602 .data = .{ .r_imm16 = .{
56035603 .rd = reg,
5604 .imm16 = @as(u16, @truncate(x >> 16)),
5604 .imm16 = @truncate(x >> 16),
56055605 } },
56065606 });
56075607 } else {
......@@ -5614,7 +5614,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56145614 .tag = .mov,
56155615 .data = .{ .r_op_mov = .{
56165616 .rd = reg,
5617 .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0),
5617 .op = Instruction.Operand.imm(@truncate(x), 0),
56185618 } },
56195619 });
56205620 _ = try self.addInst(.{
......@@ -5622,7 +5622,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56225622 .data = .{ .rr_op = .{
56235623 .rd = reg,
56245624 .rn = reg,
5625 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12),
5625 .op = Instruction.Operand.imm(@truncate(x >> 8), 12),
56265626 } },
56275627 });
56285628 _ = try self.addInst(.{
......@@ -5630,7 +5630,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56305630 .data = .{ .rr_op = .{
56315631 .rd = reg,
56325632 .rn = reg,
5633 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 16)), 8),
5633 .op = Instruction.Operand.imm(@truncate(x >> 16), 8),
56345634 } },
56355635 });
56365636 _ = try self.addInst(.{
......@@ -5638,7 +5638,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56385638 .data = .{ .rr_op = .{
56395639 .rd = reg,
56405640 .rn = reg,
5641 .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 24)), 4),
5641 .op = Instruction.Operand.imm(@truncate(x >> 24), 4),
56425642 } },
56435643 });
56445644 }
......@@ -5663,12 +5663,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56635663 .memory => |addr| {
56645664 // The value is in memory at a hard-coded address.
56655665 // 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) });
56675667 try self.genLdrRegister(reg, reg, ty);
56685668 },
56695669 .stack_offset => |off| {
56705670 // 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
56735673 const tag: Mir.Inst.Tag = switch (abi_size) {
56745674 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
56865686
56875687 if (extra_offset) {
56885688 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));
56905690 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }));
56915691
56925692 _ = try self.addInst(.{
......@@ -5702,7 +5702,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57025702 });
57035703 } else {
57045704 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));
57065706 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }), .none);
57075707
57085708 _ = try self.addInst(.{
......@@ -5741,7 +5741,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57415741
57425742fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
57435743 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));
57455745 switch (mcv) {
57465746 .dead => unreachable,
57475747 .none, .unreach => return,
......@@ -5780,7 +5780,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
57805780 },
57815781 2 => {
57825782 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));
57845784 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
57855785
57865786 _ = try self.addInst(.{
......@@ -5823,7 +5823,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
58235823 // sub src_reg, fp, #off
58245824 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
58255825 },
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) }),
58275827 .stack_argument_offset => |off| {
58285828 _ = try self.addInst(.{
58295829 .tag = .ldr_ptr_stack_argument,
......@@ -5867,13 +5867,13 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
58675867}
58685868
58695869fn 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;
58715871 const result = try self.resolveInst(un_op);
58725872 return self.finishAir(inst, result, .{ un_op, .none, .none });
58735873}
58745874
58755875fn 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;
58775877 const result = if (self.liveness.isUnused(inst)) .dead else result: {
58785878 const operand = try self.resolveInst(ty_op.operand);
58795879 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 {
58975897
58985898fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
58995899 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;
59015901 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
59025902 const ptr_ty = self.typeOf(ty_op.operand);
59035903 const ptr = try self.resolveInst(ty_op.operand);
59045904 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
59075907 const stack_offset = try self.allocMem(8, .@"8", inst);
59085908 try self.genSetStack(ptr_ty, stack_offset, ptr);
......@@ -5913,7 +5913,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
59135913}
59145914
59155915fn 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;
59175917 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
59185918 self.target.cpu.arch,
59195919 });
......@@ -5921,7 +5921,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
59215921}
59225922
59235923fn 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;
59255925 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
59265926 self.target.cpu.arch,
59275927 });
......@@ -5929,7 +5929,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
59295929}
59305930
59315931fn 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;
59335933 const extra = self.air.extraData(Air.Block, ty_pl.payload);
59345934 _ = extra;
59355935
......@@ -5970,7 +5970,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
59705970}
59715971
59725972fn 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;
59745974 const operand = try self.resolveInst(un_op);
59755975 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
59765976 _ = operand;
......@@ -5980,7 +5980,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
59805980}
59815981
59825982fn 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;
59845984 const operand = try self.resolveInst(un_op);
59855985 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
59865986 _ = operand;
......@@ -5990,26 +5990,26 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
59905990}
59915991
59925992fn 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;
59945994 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for arm", .{});
59955995 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
59965996}
59975997
59985998fn 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;
60006000 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
60016001 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for arm", .{});
60026002 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
60036003}
60046004
60056005fn 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;
60076007 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for arm", .{});
60086008 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
60096009}
60106010
60116011fn 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;
60136013 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for arm", .{});
60146014 return self.finishAir(inst, result, .{ reduce.operand, .none, .none });
60156015}
......@@ -6018,8 +6018,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60186018 const mod = self.bin_file.options.module.?;
60196019 const vector_ty = self.typeOfIndex(inst);
60206020 const len = vector_ty.vectorLen(mod);
6021 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
6022 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
6021 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6022 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
60236023 const result: MCValue = res: {
60246024 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
60256025 return self.fail("TODO implement airAggregateInit for arm", .{});
......@@ -6038,7 +6038,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60386038}
60396039
60406040fn 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;
60426042 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
60436043 _ = extra;
60446044
......@@ -6046,12 +6046,12 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
60466046}
60476047
60486048fn 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;
60506050 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });
60516051}
60526052
60536053fn 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;
60556055 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
60566056 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
60576057 return self.fail("TODO implement airMulAdd for arm", .{});
......@@ -6060,14 +6060,14 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
60606060}
60616061
60626062fn 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;
60646064 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]);
60666066 const result: MCValue = result: {
60676067 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
60686068 const error_union_ty = self.typeOf(pl_op.operand);
60696069 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));
60716071 const error_union_align = error_union_ty.abiAlignment(mod);
60726072
60736073 // 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 {
60886088}
60896089
60906090fn 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;
60926092 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
60936093 const body = self.air.extra[extra.end..][0..extra.data.body_len];
60946094 _ = body;
......@@ -6104,7 +6104,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
61046104 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod))
61056105 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(.{
61086108 .ty = inst_ty,
61096109 .val = (try self.air.value(inst, mod)).?,
61106110 });
......@@ -6136,7 +6136,7 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
61366136 .none => .none,
61376137 .undef => .undef,
61386138 .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO
6139 .immediate => |imm| .{ .immediate = @as(u32, @truncate(imm)) },
6139 .immediate => |imm| .{ .immediate = @truncate(imm) },
61406140 .memory => |addr| .{ .memory = addr },
61416141 },
61426142 .fail => |msg| {
......@@ -6194,7 +6194,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
61946194 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
61956195 result.return_value = .{ .none = {} };
61966196 } else {
6197 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
6197 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(mod));
61986198 // TODO handle cases where multiple registers are used
61996199 if (ret_ty_size <= 4) {
62006200 result.return_value = .{ .register = c_abi_int_return_regs[0] };
......@@ -6212,7 +6212,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62126212 if (Type.fromInterned(ty).abiAlignment(mod) == .@"8")
62136213 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));
62166216 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {
62176217 if (param_size <= 4) {
62186218 result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] };
......@@ -6241,7 +6241,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62416241 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) {
62426242 result.return_value = .{ .none = {} };
62436243 } else {
6244 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod)));
6244 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(mod));
62456245 if (ret_ty_size == 0) {
62466246 assert(ret_ty.isError(mod));
62476247 result.return_value = .{ .immediate = 0 };
src/arch/riscv64/CodeGen.zig+129-129
......@@ -198,7 +198,7 @@ const BigTomb = struct {
198198
199199 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {
200200 const dies = bt.lbt.feed();
201 const op_index = Air.refToIndex(op_ref) orelse return;
201 const op_index = op_ref.toIndex() orelse return;
202202 if (!dies) return;
203203 bt.function.processDeath(op_index);
204204 }
......@@ -325,7 +325,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
325325
326326 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);
329329 self.mir_instructions.appendAssumeCapacity(inst);
330330 return result_index;
331331}
......@@ -338,11 +338,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 {
338338
339339pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
340340 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);
342342 inline for (fields) |field| {
343343 self.mir_extra.appendAssumeCapacity(switch (field.type) {
344344 u32 => @field(extra, field.name),
345 i32 => @as(u32, @bitCast(@field(extra, field.name))),
345 i32 => @bitCast(@field(extra, field.name)),
346346 else => @compileError("bad field type"),
347347 });
348348 }
......@@ -486,7 +486,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
486486 const old_air_bookkeeping = self.air_bookkeeping;
487487 try self.ensureProcessDeathCapacity(Liveness.bpi);
488488
489 switch (air_tags[inst]) {
489 switch (air_tags[@intFromEnum(inst)]) {
490490 // zig fmt: off
491491 .ptr_add => try self.airPtrArithmetic(inst, .ptr_add),
492492 .ptr_sub => try self.airPtrArithmetic(inst, .ptr_sub),
......@@ -725,7 +725,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
725725 }
726726 if (std.debug.runtime_safety) {
727727 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)] });
729729 }
730730 }
731731 }
......@@ -758,7 +758,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
758758 const dies = @as(u1, @truncate(tomb_bits)) != 0;
759759 tomb_bits >>= 1;
760760 if (!dies) continue;
761 const op_index = Air.refToIndex(op) orelse continue;
761 const op_index = op.toIndex() orelse continue;
762762 self.processDeath(op_index);
763763 }
764764 const is_used = @as(u1, @truncate(tomb_bits)) == 0;
......@@ -877,19 +877,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
877877}
878878
879879fn 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;
881881 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch});
882882 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
883883}
884884
885885fn 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;
887887 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch});
888888 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
889889}
890890
891891fn 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;
893893 if (self.liveness.isUnused(inst))
894894 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
895895
......@@ -909,7 +909,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
909909}
910910
911911fn 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;
913913 if (self.liveness.isUnused(inst))
914914 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
915915
......@@ -920,32 +920,32 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
920920}
921921
922922fn 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;
924924 const operand = try self.resolveInst(un_op);
925925 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
926926 return self.finishAir(inst, result, .{ un_op, .none, .none });
927927}
928928
929929fn 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;
931931 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement NOT for {}", .{self.target.cpu.arch});
932932 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
933933}
934934
935935fn 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;
937937 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement min for {}", .{self.target.cpu.arch});
938938 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
939939}
940940
941941fn 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;
943943 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement max for {}", .{self.target.cpu.arch});
944944 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
945945}
946946
947947fn 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;
949949 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
950950 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice for {}", .{self.target.cpu.arch});
951951 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
......@@ -981,8 +981,8 @@ fn binOpRegister(
981981
982982 const lhs_reg = if (lhs_is_register) lhs.register else blk: {
983983 const track_inst: ?Air.Inst.Index = if (maybe_inst) |inst| inst: {
984 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
985 break :inst Air.refToIndex(bin_op.lhs).?;
984 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
985 break :inst bin_op.lhs.toIndex().?;
986986 } else null;
987987
988988 const reg = try self.register_manager.allocReg(track_inst, gp);
......@@ -996,8 +996,8 @@ fn binOpRegister(
996996
997997 const rhs_reg = if (rhs_is_register) rhs.register else blk: {
998998 const track_inst: ?Air.Inst.Index = if (maybe_inst) |inst| inst: {
999 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1000 break :inst Air.refToIndex(bin_op.rhs).?;
999 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1000 break :inst bin_op.rhs.toIndex().?;
10011001 } else null;
10021002
10031003 const reg = try self.register_manager.allocReg(track_inst, gp);
......@@ -1010,7 +1010,7 @@ fn binOpRegister(
10101010 defer if (new_rhs_lock) |reg| self.register_manager.unlockReg(reg);
10111011
10121012 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
10151015 if (lhs_is_register and self.reuseOperand(inst, bin_op.lhs, 0, lhs)) {
10161016 break :blk lhs_reg;
......@@ -1123,7 +1123,7 @@ fn binOp(
11231123}
11241124
11251125fn 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;
11271127 const lhs = try self.resolveInst(bin_op.lhs);
11281128 const rhs = try self.resolveInst(bin_op.rhs);
11291129 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 {
11341134}
11351135
11361136fn 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;
11381138 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
11391139 const lhs = try self.resolveInst(bin_op.lhs);
11401140 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
11461146}
11471147
11481148fn 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;
11501150 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement addwrap for {}", .{self.target.cpu.arch});
11511151 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
11521152}
11531153
11541154fn 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;
11561156 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});
11571157 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
11581158}
11591159
11601160fn 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;
11621162 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement subwrap for {}", .{self.target.cpu.arch});
11631163 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
11641164}
11651165
11661166fn 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;
11681168 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});
11691169 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
11701170}
11711171
11721172fn 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;
11741174 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul for {}", .{self.target.cpu.arch});
11751175 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
11761176}
11771177
11781178fn 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;
11801180 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mulwrap for {}", .{self.target.cpu.arch});
11811181 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
11821182}
11831183
11841184fn 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;
11861186 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});
11871187 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
11881188}
......@@ -1208,105 +1208,105 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
12081208}
12091209
12101210fn 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;
12121212 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement div for {}", .{self.target.cpu.arch});
12131213 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
12141214}
12151215
12161216fn 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;
12181218 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement rem for {}", .{self.target.cpu.arch});
12191219 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
12201220}
12211221
12221222fn 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;
12241224 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mod for {}", .{self.target.cpu.arch});
12251225 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
12261226}
12271227
12281228fn 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;
12301230 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement bitwise and for {}", .{self.target.cpu.arch});
12311231 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
12321232}
12331233
12341234fn 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;
12361236 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement bitwise or for {}", .{self.target.cpu.arch});
12371237 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
12381238}
12391239
12401240fn 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;
12421242 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement xor for {}", .{self.target.cpu.arch});
12431243 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
12441244}
12451245
12461246fn 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;
12481248 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl for {}", .{self.target.cpu.arch});
12491249 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
12501250}
12511251
12521252fn 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;
12541254 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
12551255 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
12561256}
12571257
12581258fn 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;
12601260 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shr for {}", .{self.target.cpu.arch});
12611261 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
12621262}
12631263
12641264fn 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;
12661266 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch});
12671267 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
12681268}
12691269
12701270fn 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;
12721272 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});
12731273 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
12741274}
12751275
12761276fn 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;
12781278 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});
12791279 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
12801280}
12811281
12821282fn 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;
12841284 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error for {}", .{self.target.cpu.arch});
12851285 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
12861286}
12871287
12881288fn 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;
12901290 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload for {}", .{self.target.cpu.arch});
12911291 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
12921292}
12931293
12941294// *(E!T) -> E
12951295fn 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;
12971297 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});
12981298 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
12991299}
13001300
13011301// *(E!T) -> *T
13021302fn 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;
13041304 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});
13051305 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
13061306}
13071307
13081308fn 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;
13101310 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});
13111311 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
13121312}
......@@ -1330,7 +1330,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
13301330}
13311331
13321332fn 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;
13341334 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
13351335 const mod = self.bin_file.options.module.?;
13361336 const optional_ty = self.typeOfIndex(inst);
......@@ -1346,127 +1346,127 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
13461346
13471347/// T to E!T
13481348fn 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;
13501350 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion payload for {}", .{self.target.cpu.arch});
13511351 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
13521352}
13531353
13541354/// E to E!T
13551355fn 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;
13571357 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion error for {}", .{self.target.cpu.arch});
13581358 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
13591359}
13601360
13611361fn 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;
13631363 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_ptr for {}", .{self.target.cpu.arch});
13641364 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
13651365}
13661366
13671367fn 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;
13691369 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_len for {}", .{self.target.cpu.arch});
13701370 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
13711371}
13721372
13731373fn 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;
13751375 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_len_ptr for {}", .{self.target.cpu.arch});
13761376 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
13771377}
13781378
13791379fn 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;
13811381 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_ptr_ptr for {}", .{self.target.cpu.arch});
13821382 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
13831383}
13841384
13851385fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
13861386 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;
13881388 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});
13891389 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
13901390}
13911391
13921392fn 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;
13941394 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
13951395 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_elem_ptr for {}", .{self.target.cpu.arch});
13961396 return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
13971397}
13981398
13991399fn 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;
14011401 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch});
14021402 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
14031403}
14041404
14051405fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
14061406 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;
14081408 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});
14091409 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
14101410}
14111411
14121412fn 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;
14141414 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
14151415 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_ptr for {}", .{self.target.cpu.arch});
14161416 return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
14171417}
14181418
14191419fn 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;
14211421 _ = bin_op;
14221422 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});
14231423 // return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
14241424}
14251425
14261426fn 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;
14281428 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});
14291429 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
14301430}
14311431
14321432fn 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;
14341434 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});
14351435 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
14361436}
14371437
14381438fn 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;
14401440 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});
14411441 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
14421442}
14431443
14441444fn 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;
14461446 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});
14471447 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
14481448}
14491449
14501450fn 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;
14521452 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch});
14531453 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
14541454}
14551455
14561456fn 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;
14581458 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch});
14591459 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
14601460}
14611461
14621462fn 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;
14641464 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});
14651465 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
14661466}
14671467
14681468fn 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;
14701470 const result: MCValue = if (self.liveness.isUnused(inst))
14711471 .dead
14721472 else
......@@ -1500,7 +1500,7 @@ fn reuseOperand(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, op_ind
15001500
15011501 // That makes us responsible for doing the rest of the stuff that processDeath would have done.
15021502 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
15051505 return true;
15061506}
......@@ -1533,7 +1533,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
15331533
15341534fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
15351535 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;
15371537 const elem_ty = self.typeOfIndex(inst);
15381538 const result: MCValue = result: {
15391539 if (!elem_ty.hasRuntimeBits(mod))
......@@ -1590,7 +1590,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
15901590 } else {
15911591 // TODO if the value is undef, don't lower this instruction
15921592 }
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;
15941594 const ptr = try self.resolveInst(bin_op.lhs);
15951595 const value = try self.resolveInst(bin_op.rhs);
15961596 const ptr_ty = self.typeOf(bin_op.lhs);
......@@ -1602,13 +1602,13 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
16021602}
16031603
16041604fn 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;
16061606 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
16071607 return self.structFieldPtr(extra.struct_operand, ty_pl.ty, extra.field_index);
16081608}
16091609
16101610fn 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;
16121612 return self.structFieldPtr(ty_op.operand, ty_op.ty, index);
16131613}
16141614fn 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
16201620}
16211621
16221622fn 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;
16241624 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
16251625 _ = extra;
16261626 return self.fail("TODO implement codegen struct_field_val", .{});
......@@ -1634,8 +1634,8 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
16341634
16351635fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {
16361636 const mod = self.bin_file.options.module.?;
1637 const arg = self.air.instructions.items(.data)[inst].arg;
1638 const ty = self.air.getRefType(arg.ty);
1637 const arg = self.air.instructions.items(.data)[@intFromEnum(inst)].arg;
1638 const ty = arg.ty.toType();
16391639 const owner_decl = mod.funcOwnerDeclIndex(self.func_index);
16401640 const name = mod.getParamName(self.func_index, arg.src_index);
16411641
......@@ -1712,11 +1712,11 @@ fn airFence(self: *Self) !void {
17121712fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
17131713 const mod = self.bin_file.options.module.?;
17141714 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;
17161716 const fn_ty = self.typeOf(pl_op.operand);
17171717 const callee = pl_op.operand;
17181718 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
17211721 var info = try self.resolveCallingConventionValues(fn_ty);
17221722 defer info.deinit(self);
......@@ -1755,7 +1755,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
17551755 const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl);
17561756 const sym = elf_file.symbol(sym_index);
17571757 _ = 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));
17591759 try self.genSetReg(Type.usize, .ra, .{ .memory = got_addr });
17601760 _ = try self.addInst(.{
17611761 .tag = .jalr,
......@@ -1824,14 +1824,14 @@ fn ret(self: *Self, mcv: MCValue) !void {
18241824}
18251825
18261826fn 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;
18281828 const operand = try self.resolveInst(un_op);
18291829 try self.ret(operand);
18301830 return self.finishAir(inst, .dead, .{ un_op, .none, .none });
18311831}
18321832
18331833fn 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;
18351835 const ptr = try self.resolveInst(un_op);
18361836 _ = ptr;
18371837 return self.fail("TODO implement airRetLoad for {}", .{self.target.cpu.arch});
......@@ -1839,7 +1839,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
18391839}
18401840
18411841fn 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;
18431843 if (self.liveness.isUnused(inst))
18441844 return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
18451845 const ty = self.typeOf(bin_op.lhs);
......@@ -1864,7 +1864,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
18641864}
18651865
18661866fn 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;
18681868 const operand = try self.resolveInst(un_op);
18691869 _ = operand;
18701870 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 {
18721872}
18731873
18741874fn 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
18771877 _ = try self.addInst(.{
18781878 .tag = .dbg_line,
......@@ -1886,7 +1886,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
18861886}
18871887
18881888fn 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;
18901890 const mod = self.bin_file.options.module.?;
18911891 const func = mod.funcInfo(ty_fn.func);
18921892 // TODO emit debug info for function change
......@@ -1900,7 +1900,7 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
19001900}
19011901
19021902fn 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;
19041904 const name = self.air.nullTerminatedString(pl_op.payload);
19051905 const operand = pl_op.operand;
19061906 // TODO emit debug info for this variable
......@@ -1944,7 +1944,7 @@ fn isNonErr(self: *Self, operand: MCValue) !MCValue {
19441944}
19451945
19461946fn 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;
19481948 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
19491949 const operand = try self.resolveInst(un_op);
19501950 break :result try self.isNull(operand);
......@@ -1953,7 +1953,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
19531953}
19541954
19551955fn 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;
19571957 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
19581958 const operand_ptr = try self.resolveInst(un_op);
19591959 const operand: MCValue = blk: {
......@@ -1971,7 +1971,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
19711971}
19721972
19731973fn 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;
19751975 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
19761976 const operand = try self.resolveInst(un_op);
19771977 break :result try self.isNonNull(operand);
......@@ -1980,7 +1980,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
19801980}
19811981
19821982fn 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;
19841984 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
19851985 const operand_ptr = try self.resolveInst(un_op);
19861986 const operand: MCValue = blk: {
......@@ -1998,7 +1998,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
19981998}
19991999
20002000fn 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;
20022002 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20032003 const operand = try self.resolveInst(un_op);
20042004 break :result try self.isErr(operand);
......@@ -2007,7 +2007,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
20072007}
20082008
20092009fn 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;
20112011 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20122012 const operand_ptr = try self.resolveInst(un_op);
20132013 const operand: MCValue = blk: {
......@@ -2025,7 +2025,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
20252025}
20262026
20272027fn 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;
20292029 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20302030 const operand = try self.resolveInst(un_op);
20312031 break :result try self.isNonErr(operand);
......@@ -2034,7 +2034,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
20342034}
20352035
20362036fn 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;
20382038 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20392039 const operand_ptr = try self.resolveInst(un_op);
20402040 const operand: MCValue = blk: {
......@@ -2053,9 +2053,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
20532053
20542054fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
20552055 // 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;
20572057 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]);
20592059 const start_index = self.code.items.len;
20602060 try self.genBody(body);
20612061 try self.jump(start_index);
......@@ -2081,9 +2081,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
20812081 });
20822082 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;
20852085 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]);
20872087 try self.genBody(body);
20882088
20892089 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 {
20932093}
20942094
20952095fn 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;
20972097 const condition = pl_op.operand;
20982098 _ = condition;
20992099 return self.fail("TODO airSwitch for {}", .{self.target.cpu.arch});
......@@ -2109,13 +2109,13 @@ fn performReloc(self: *Self, reloc: Reloc) !void {
21092109}
21102110
21112111fn 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;
21132113 try self.br(branch.block_inst, branch.operand);
21142114 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });
21152115}
21162116
21172117fn 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;
21192119 const air_tags = self.air.instructions.items(.tag);
21202120 _ = air_tags;
21212121 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 {
21482148}
21492149
21502150fn 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;
21522152 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
21532153 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);
21552155 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]);
21572157 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]);
21592159 extra_i += inputs.len;
21602160
21612161 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
23002300 return self.genSetReg(ty, reg, .{ .immediate = 0xaaaaaaaaaaaaaaaa });
23012301 },
23022302 .immediate => |unsigned_x| {
2303 const x = @as(i64, @bitCast(unsigned_x));
2303 const x: i64 = @bitCast(unsigned_x);
23042304 if (math.minInt(i12) <= x and x <= math.maxInt(i12)) {
23052305 _ = try self.addInst(.{
23062306 .tag = .addi,
23072307 .data = .{ .i_type = .{
23082308 .rd = reg,
23092309 .rs1 = .zero,
2310 .imm12 = @as(i12, @intCast(x)),
2310 .imm12 = @intCast(x),
23112311 } },
23122312 });
23132313 } else if (math.minInt(i32) <= x and x <= math.maxInt(i32)) {
2314 const lo12 = @as(i12, @truncate(x));
2314 const lo12: i12 = @truncate(x);
23152315 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
23182318 // TODO: add test case for 32-bit immediate
23192319 _ = try self.addInst(.{
......@@ -2373,13 +2373,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
23732373}
23742374
23752375fn 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;
23772377 const result = try self.resolveInst(un_op);
23782378 return self.finishAir(inst, result, .{ un_op, .none, .none });
23792379}
23802380
23812381fn 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;
23832383 const result = if (self.liveness.isUnused(inst)) .dead else result: {
23842384 const operand = try self.resolveInst(ty_op.operand);
23852385 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 {
23982398}
23992399
24002400fn 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;
24022402 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airArrayToSlice for {}", .{
24032403 self.target.cpu.arch,
24042404 });
......@@ -2406,7 +2406,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
24062406}
24072407
24082408fn 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;
24102410 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
24112411 self.target.cpu.arch,
24122412 });
......@@ -2414,7 +2414,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
24142414}
24152415
24162416fn 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;
24182418 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
24192419 self.target.cpu.arch,
24202420 });
......@@ -2422,7 +2422,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
24222422}
24232423
24242424fn 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;
24262426 const extra = self.air.extraData(Air.Block, ty_pl.payload);
24272427 _ = extra;
24282428 return self.fail("TODO implement airCmpxchg for {}", .{
......@@ -2463,7 +2463,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
24632463}
24642464
24652465fn 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;
24672467 const operand = try self.resolveInst(un_op);
24682468 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
24692469 _ = operand;
......@@ -2473,7 +2473,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
24732473}
24742474
24752475fn 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;
24772477 const operand = try self.resolveInst(un_op);
24782478 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
24792479 _ = operand;
......@@ -2483,26 +2483,26 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
24832483}
24842484
24852485fn 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;
24872487 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for riscv64", .{});
24882488 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
24892489}
24902490
24912491fn 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;
24932493 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
24942494 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for riscv64", .{});
24952495 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
24962496}
24972497
24982498fn 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;
25002500 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for riscv64", .{});
25012501 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
25022502}
25032503
25042504fn 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;
25062506 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for riscv64", .{});
25072507 return self.finishAir(inst, result, .{ reduce.operand, .none, .none });
25082508}
......@@ -2511,8 +2511,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
25112511 const mod = self.bin_file.options.module.?;
25122512 const vector_ty = self.typeOfIndex(inst);
25132513 const len = vector_ty.vectorLen(mod);
2514 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
2515 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
2514 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2515 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
25162516 const result: MCValue = res: {
25172517 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
25182518 return self.fail("TODO implement airAggregateInit for riscv64", .{});
......@@ -2531,7 +2531,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
25312531}
25322532
25332533fn 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;
25352535 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
25362536 _ = extra;
25372537 return self.fail("TODO implement airUnionInit for riscv64", .{});
......@@ -2539,12 +2539,12 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
25392539}
25402540
25412541fn 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;
25432543 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });
25442544}
25452545
25462546fn 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;
25482548 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
25492549 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
25502550 return self.fail("TODO implement airMulAdd for riscv64", .{});
......@@ -2560,7 +2560,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
25602560 if (!inst_ty.hasRuntimeBits(mod))
25612561 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(.{
25642564 .ty = inst_ty,
25652565 .val = (try self.air.value(inst, mod)).?,
25662566 });
......@@ -2656,7 +2656,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
26562656 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };
26572657
26582658 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));
26602660 if (param_size <= 8) {
26612661 if (next_register < argument_registers.len) {
26622662 result_arg.* = .{ .register = argument_registers[next_register] };
......@@ -2693,7 +2693,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
26932693 } else switch (cc) {
26942694 .Naked => unreachable,
26952695 .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));
26972697 if (ret_ty_size <= 8) {
26982698 result.return_value = .{ .register = .a0 };
26992699 } else if (ret_ty_size <= 16) {
src/arch/sparc64/CodeGen.zig+107-109
......@@ -243,7 +243,7 @@ const BigTomb = struct {
243243
244244 fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void {
245245 const dies = bt.lbt.feed();
246 const op_index = Air.refToIndex(op_ref) orelse return;
246 const op_index = op_ref.toIndex() orelse return;
247247 if (!dies) return;
248248 bt.function.processDeath(op_index);
249249 }
......@@ -504,7 +504,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
504504 const old_air_bookkeeping = self.air_bookkeeping;
505505 try self.ensureProcessDeathCapacity(Liveness.bpi);
506506
507 switch (air_tags[inst]) {
507 switch (air_tags[@intFromEnum(inst)]) {
508508 // zig fmt: off
509509 .ptr_add => try self.airPtrArithmetic(inst, .ptr_add),
510510 .ptr_sub => try self.airPtrArithmetic(inst, .ptr_sub),
......@@ -746,21 +746,21 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
746746
747747 if (std.debug.runtime_safety) {
748748 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)] });
750750 }
751751 }
752752 }
753753}
754754
755755fn 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;
757757 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch});
758758 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
759759}
760760
761761fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
762 const tag = self.air.instructions.items(.tag)[inst];
763 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
762 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
763 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
764764 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
765765 const mod = self.bin_file.options.module.?;
766766 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
......@@ -843,7 +843,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
843843 const mod = self.bin_file.options.module.?;
844844 const vector_ty = self.typeOfIndex(inst);
845845 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;
847847 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
848848 const result: MCValue = res: {
849849 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
......@@ -868,14 +868,14 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
868868}
869869
870870fn 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;
872872 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch});
873873 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
874874}
875875
876876fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
877877 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;
879879 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
880880 const ptr_ty = self.typeOf(ty_op.operand);
881881 const ptr = try self.resolveInst(ty_op.operand);
......@@ -891,7 +891,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
891891}
892892
893893fn 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;
895895 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
896896 const is_volatile = (extra.data.flags & 0x80000000) != 0;
897897 const clobbers_len = @as(u31, @truncate(extra.data.flags));
......@@ -1047,7 +1047,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
10471047}
10481048
10491049fn 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
10521052 return self.fail("TODO implement airAtomicLoad for {}", .{
10531053 self.target.cpu.arch,
......@@ -1055,7 +1055,7 @@ fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {
10551055}
10561056
10571057fn 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
10601060 return self.fail("TODO implement airAtomicRmw for {}", .{
10611061 self.target.cpu.arch,
......@@ -1063,7 +1063,7 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {
10631063}
10641064
10651065fn 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;
10671067 const lhs = try self.resolveInst(bin_op.lhs);
10681068 const rhs = try self.resolveInst(bin_op.rhs);
10691069 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 {
10801080}
10811081
10821082fn 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;
10841084 const operand = try self.resolveInst(un_op);
10851085 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand;
10861086 return self.finishAir(inst, result, .{ un_op, .none, .none });
10871087}
10881088
10891089fn 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;
10911091 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
10921092 const lhs = try self.resolveInst(bin_op.lhs);
10931093 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
11051105}
11061106
11071107fn 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;
11091109 const result = if (self.liveness.isUnused(inst)) .dead else result: {
11101110 const operand = try self.resolveInst(ty_op.operand);
11111111 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 {
11251125}
11261126
11271127fn 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;
11291129 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch});
11301130 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
11311131}
......@@ -1143,9 +1143,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
11431143 });
11441144 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;
11471147 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]);
11491149 try self.genBody(body);
11501150
11511151 // relocations for `bpcc` instructions
......@@ -1170,7 +1170,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
11701170}
11711171
11721172fn 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;
11741174 try self.br(branch.block_inst, branch.operand);
11751175 return self.finishAir(inst, .dead, .{ branch.operand, .none, .none });
11761176}
......@@ -1207,7 +1207,7 @@ fn airBreakpoint(self: *Self) !void {
12071207
12081208fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12091209 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
12121212 // We have hardware byteswapper in SPARCv9, don't let mainstream compilers mislead you.
12131213 // That being said, the strategy to lower this is:
......@@ -1293,7 +1293,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12931293fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
12941294 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;
12971297 const callee = pl_op.operand;
12981298 const extra = self.air.extraData(Air.Call, pl_op.payload);
12991299 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
14231423}
14241424
14251425fn 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;
14271427 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch});
14281428 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
14291429}
14301430
14311431fn 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;
14331433 const mod = self.bin_file.options.module.?;
14341434 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
14351435 const lhs = try self.resolveInst(bin_op.lhs);
......@@ -1486,7 +1486,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
14861486}
14871487
14881488fn 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;
14901490 const operand = try self.resolveInst(un_op);
14911491 _ = operand;
14921492 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 {
14941494}
14951495
14961496fn 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;
14981498 const extra = self.air.extraData(Air.Block, ty_pl.payload);
14991499 _ = extra;
15001500
......@@ -1504,11 +1504,11 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
15041504}
15051505
15061506fn 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;
15081508 const condition = try self.resolveInst(pl_op.operand);
15091509 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];
1511 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_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: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
15121512 const liveness_condbr = self.liveness.getCondBr(inst);
15131513
15141514 // Here we emit a branch to the false section.
......@@ -1518,7 +1518,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
15181518 // that death now instead of later as this has an effect on
15191519 // whether it needs to be spilled in the branches
15201520 if (self.liveness.operandDies(inst, 0)) {
1521 if (Air.refToIndex(pl_op.operand)) |op_index| {
1521 if (pl_op.operand.toIndex()) |op_index| {
15221522 self.processDeath(op_index);
15231523 }
15241524 }
......@@ -1650,7 +1650,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
16501650}
16511651
16521652fn 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;
16541654 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch});
16551655 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
16561656}
......@@ -1661,7 +1661,7 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
16611661}
16621662
16631663fn 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;
16651665 const mod = self.bin_file.options.module.?;
16661666 const func = mod.funcInfo(ty_fn.func);
16671667 // TODO emit debug info for function change
......@@ -1670,7 +1670,7 @@ fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void {
16701670}
16711671
16721672fn 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
16751675 _ = try self.addInst(.{
16761676 .tag = .dbg_line,
......@@ -1686,7 +1686,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
16861686}
16871687
16881688fn 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;
16901690 const name = self.air.nullTerminatedString(pl_op.payload);
16911691 const operand = pl_op.operand;
16921692 // TODO emit debug info for this variable
......@@ -1695,13 +1695,13 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
16951695}
16961696
16971697fn 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;
16991699 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement div for {}", .{self.target.cpu.arch});
17001700 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
17011701}
17021702
17031703fn 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;
17051705 const operand = try self.resolveInst(un_op);
17061706 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
17071707 _ = operand;
......@@ -1711,14 +1711,14 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
17111711}
17121712
17131713fn 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;
17151715 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch});
17161716 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
17171717}
17181718
17191719fn airFence(self: *Self, inst: Air.Inst.Index) !void {
17201720 // 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;
17221722 _ = fence;
17231723
17241724 // membar #StoreStore | #LoadStore | #StoreLoad | #LoadLoad
......@@ -1740,7 +1740,7 @@ fn airFence(self: *Self, inst: Air.Inst.Index) !void {
17401740}
17411741
17421742fn 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;
17441744 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{
17451745 self.target.cpu.arch,
17461746 });
......@@ -1748,13 +1748,13 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
17481748}
17491749
17501750fn 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;
17521752 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch});
17531753 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
17541754}
17551755
17561756fn 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;
17581758 if (self.liveness.isUnused(inst))
17591759 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
17601760
......@@ -1773,7 +1773,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
17731773}
17741774
17751775fn 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;
17771777 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{
17781778 self.target.cpu.arch,
17791779 });
......@@ -1781,7 +1781,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
17811781}
17821782
17831783fn 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;
17851785 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
17861786 const operand = try self.resolveInst(un_op);
17871787 const ty = self.typeOf(un_op);
......@@ -1791,7 +1791,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
17911791}
17921792
17931793fn 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;
17951795 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
17961796 const operand = try self.resolveInst(un_op);
17971797 const ty = self.typeOf(un_op);
......@@ -1801,7 +1801,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
18011801}
18021802
18031803fn 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;
18051805 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
18061806 const operand = try self.resolveInst(un_op);
18071807 break :result try self.isNull(operand);
......@@ -1810,7 +1810,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
18101810}
18111811
18121812fn 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;
18141814 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
18151815 const operand = try self.resolveInst(un_op);
18161816 break :result try self.isNonNull(operand);
......@@ -1820,7 +1820,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
18201820
18211821fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
18221822 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;
18241824 const elem_ty = self.typeOfIndex(inst);
18251825 const elem_size = elem_ty.abiSize(mod);
18261826 const result: MCValue = result: {
......@@ -1851,9 +1851,9 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
18511851
18521852fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
18531853 // 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;
18551855 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]);
18571857 const start = @as(u32, @intCast(self.mir_instructions.len));
18581858
18591859 try self.genBody(body);
......@@ -1868,7 +1868,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
18681868 } else {
18691869 // TODO if the value is undef, don't lower this instruction
18701870 }
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;
18721872 const extra = self.air.extraData(Air.Bin, pl_op.payload);
18731873
18741874 const operand = pl_op.operand;
......@@ -1882,8 +1882,8 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
18821882}
18831883
18841884fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
1885 const tag = self.air.instructions.items(.tag)[inst];
1886 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1885 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1886 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
18871887 const lhs = try self.resolveInst(bin_op.lhs);
18881888 const rhs = try self.resolveInst(bin_op.rhs);
18891889 const lhs_ty = self.typeOf(bin_op.lhs);
......@@ -1898,7 +1898,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void {
18981898}
18991899
19001900fn 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;
19021902 const lhs = try self.resolveInst(bin_op.lhs);
19031903 const rhs = try self.resolveInst(bin_op.rhs);
19041904 const lhs_ty = self.typeOf(bin_op.lhs);
......@@ -2036,14 +2036,14 @@ fn airMod(self: *Self, inst: Air.Inst.Index) !void {
20362036}
20372037
20382038fn 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;
20402040 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch});
20412041 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
20422042}
20432043
20442044fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2045 //const tag = self.air.instructions.items(.tag)[inst];
2046 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
2045 //const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
2046 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
20472047 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
20482048 const mod = self.bin_file.options.module.?;
20492049 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
......@@ -2108,7 +2108,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
21082108}
21092109
21102110fn 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;
21122112 const mod = self.bin_file.options.module.?;
21132113 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
21142114 const operand = try self.resolveInst(ty_op.operand);
......@@ -2204,51 +2204,51 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
22042204}
22052205
22062206fn 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;
22082208 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch});
22092209 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
22102210}
22112211
22122212fn 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;
22142214 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch});
22152215 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
22162216}
22172217
22182218fn 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;
22202220 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch});
22212221 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
22222222}
22232223
22242224fn 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;
22262226 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch});
22272227 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
22282228}
22292229
22302230fn 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;
22322232 // TODO Emit a PREFETCH/IPREFETCH as necessary, see A.7 and A.42
22332233 return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none });
22342234}
22352235
22362236fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
22372237 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;
22392239 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});
22402240 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
22412241}
22422242
22432243fn 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;
22452245 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
22462246 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_ptr for {}", .{self.target.cpu.arch});
22472247 return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
22482248}
22492249
22502250fn 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;
22522252 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
22532253 const ptr_bits = self.target.ptrBitWidth();
22542254 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -2265,7 +2265,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
22652265}
22662266
22672267fn 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;
22692269 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
22702270 const mcv = try self.resolveInst(ty_op.operand);
22712271 switch (mcv) {
......@@ -2280,13 +2280,13 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
22802280}
22812281
22822282fn 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;
22842284 const result = try self.resolveInst(un_op);
22852285 return self.finishAir(inst, result, .{ un_op, .none, .none });
22862286}
22872287
22882288fn 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;
22902290 const lhs = try self.resolveInst(bin_op.lhs);
22912291 const rhs = try self.resolveInst(bin_op.rhs);
22922292 const lhs_ty = self.typeOf(bin_op.lhs);
......@@ -2307,14 +2307,14 @@ fn airRem(self: *Self, inst: Air.Inst.Index) !void {
23072307}
23082308
23092309fn 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;
23112311 const operand = try self.resolveInst(un_op);
23122312 try self.ret(operand);
23132313 return self.finishAir(inst, .dead, .{ un_op, .none, .none });
23142314}
23152315
23162316fn 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;
23182318 const ptr = try self.resolveInst(un_op);
23192319 _ = ptr;
23202320 return self.fail("TODO implement airRetLoad for {}", .{self.target.cpu.arch});
......@@ -2327,19 +2327,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
23272327}
23282328
23292329fn 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;
23312331 _ = bin_op;
23322332 return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch});
23332333}
23342334
23352335fn 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;
23372337 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
23382338 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
23392339}
23402340
23412341fn 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;
23432343 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
23442344 const mod = self.bin_file.options.module.?;
23452345 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
......@@ -2429,7 +2429,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
24292429}
24302430
24312431fn 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;
24332433 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
24342434 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
24352435 const ptr = try self.resolveInst(bin_op.lhs);
......@@ -2448,7 +2448,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
24482448fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24492449 const mod = self.bin_file.options.module.?;
24502450 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
24532453 if (!is_volatile and self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
24542454 const result: MCValue = result: {
......@@ -2490,7 +2490,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24902490}
24912491
24922492fn 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;
24942494 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
24952495 const ptr_bits = self.target.ptrBitWidth();
24962496 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -2511,7 +2511,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
25112511}
25122512
25132513fn 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;
25152515 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
25162516 const mcv = try self.resolveInst(ty_op.operand);
25172517 switch (mcv) {
......@@ -2530,7 +2530,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
25302530}
25312531
25322532fn 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;
25342534 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for {}", .{self.target.cpu.arch});
25352535 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
25362536}
......@@ -2541,7 +2541,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
25412541 } else {
25422542 // TODO if the value is undef, don't lower this instruction
25432543 }
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;
25452545 const ptr = try self.resolveInst(bin_op.lhs);
25462546 const value = try self.resolveInst(bin_op.rhs);
25472547 const ptr_ty = self.typeOf(bin_op.lhs);
......@@ -2553,20 +2553,20 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
25532553}
25542554
25552555fn 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;
25572557 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
25582558 const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index);
25592559 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });
25602560}
25612561
25622562fn 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;
25642564 const result = try self.structFieldPtr(inst, ty_op.operand, index);
25652565 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
25662566}
25672567
25682568fn 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;
25702570 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
25712571 const operand = extra.struct_operand;
25722572 const index = extra.field_index;
......@@ -2636,7 +2636,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
26362636}
26372637
26382638fn 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;
26402640 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch});
26412641 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
26422642}
......@@ -2647,7 +2647,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
26472647}
26482648
26492649fn 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;
26512651 const operand = try self.resolveInst(un_op);
26522652 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else {
26532653 _ = operand;
......@@ -2657,7 +2657,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
26572657}
26582658
26592659fn 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;
26612661 const operand = try self.resolveInst(ty_op.operand);
26622662 const operand_ty = self.typeOf(ty_op.operand);
26632663 const dest_ty = self.typeOfIndex(inst);
......@@ -2670,9 +2670,9 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
26702670}
26712671
26722672fn 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;
26742674 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]);
26762676 const result: MCValue = result: {
26772677 const error_union_ty = self.typeOf(pl_op.operand);
26782678 const error_union = try self.resolveInst(pl_op.operand);
......@@ -2688,7 +2688,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
26882688}
26892689
26902690fn 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;
26922692 const result: MCValue = if (self.liveness.isUnused(inst))
26932693 .dead
26942694 else
......@@ -2697,7 +2697,7 @@ fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void {
26972697}
26982698
26992699fn 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;
27012701 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
27022702 _ = extra;
27032703 return self.fail("TODO implement airUnionInit for {}", .{self.target.cpu.arch});
......@@ -2705,7 +2705,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
27052705
27062706fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
27072707 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;
27092709 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
27102710 const error_union_ty = self.typeOf(ty_op.operand);
27112711 const payload_ty = error_union_ty.errorUnionPayload(mod);
......@@ -2719,7 +2719,7 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
27192719
27202720fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
27212721 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;
27232723 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
27242724 const error_union_ty = self.typeOf(ty_op.operand);
27252725 const payload_ty = error_union_ty.errorUnionPayload(mod);
......@@ -2733,9 +2733,9 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
27332733/// E to E!T
27342734fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
27352735 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;
27372737 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();
27392739 const payload_ty = error_union_ty.errorUnionPayload(mod);
27402740 const mcv = try self.resolveInst(ty_op.operand);
27412741 if (!payload_ty.hasRuntimeBits(mod)) break :result mcv;
......@@ -2747,14 +2747,14 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
27472747
27482748/// T to E!T
27492749fn 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;
27512751 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion payload for {}", .{self.target.cpu.arch});
27522752 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
27532753}
27542754
27552755fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
27562756 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;
27582758 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
27592759 const optional_ty = self.typeOfIndex(inst);
27602760
......@@ -2772,7 +2772,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
27722772fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
27732773 const gpa = self.gpa;
27742774 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);
27762776 self.mir_instructions.appendAssumeCapacity(inst);
27772777 return result_index;
27782778}
......@@ -3143,9 +3143,7 @@ fn binOpImmediate(
31433143
31443144 const lhs_reg = if (lhs_is_register) lhs.register else blk: {
31453145 const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: {
3146 break :inst Air.refToIndex(
3147 if (lhs_and_rhs_swapped) md.rhs else md.lhs,
3148 ).?;
3146 break :inst (if (lhs_and_rhs_swapped) md.rhs else md.lhs).toIndex().?;
31493147 } else null;
31503148
31513149 const reg = try self.register_manager.allocReg(track_inst, gp);
......@@ -3284,7 +3282,7 @@ fn binOpRegister(
32843282
32853283 const lhs_reg = if (lhs_is_register) lhs.register else blk: {
32863284 const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: {
3287 break :inst Air.refToIndex(md.lhs).?;
3285 break :inst md.lhs.toIndex().?;
32883286 } else null;
32893287
32903288 const reg = try self.register_manager.allocReg(track_inst, gp);
......@@ -3308,7 +3306,7 @@ fn binOpRegister(
33083306
33093307 const rhs_reg = if (rhs_is_register) rhs.register else blk: {
33103308 const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: {
3311 break :inst Air.refToIndex(md.rhs).?;
3309 break :inst md.rhs.toIndex().?;
33123310 } else null;
33133311
33143312 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
35663564 const dies = @as(u1, @truncate(tomb_bits)) != 0;
35673565 tomb_bits >>= 1;
35683566 if (!dies) continue;
3569 const op_index = Air.refToIndex(op) orelse continue;
3567 const op_index = op.toIndex() orelse continue;
35703568 self.processDeath(op_index);
35713569 }
35723570 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
35943592
35953593fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {
35963594 const mod = self.bin_file.options.module.?;
3597 const arg = self.air.instructions.items(.data)[inst].arg;
3598 const ty = self.air.getRefType(arg.ty);
3595 const arg = self.air.instructions.items(.data)[@intFromEnum(inst)].arg;
3596 const ty = arg.ty.toType();
35993597 const owner_decl = mod.funcOwnerDeclIndex(self.func_index);
36003598 const name = mod.getParamName(self.func_index, arg.src_index);
36013599
......@@ -4411,8 +4409,8 @@ fn parseRegName(name: []const u8) ?Register {
44114409fn performReloc(self: *Self, inst: Mir.Inst.Index) !void {
44124410 const tag = self.mir_instructions.items(.tag)[inst];
44134411 switch (tag) {
4414 .bpcc => self.mir_instructions.items(.data)[inst].branch_predict_int.inst = @as(Mir.Inst.Index, @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)),
4412 .bpcc => self.mir_instructions.items(.data)[inst].branch_predict_int.inst = @intCast(self.mir_instructions.len),
4413 .bpr => self.mir_instructions.items(.data)[inst].branch_predict_reg.inst = @intCast(self.mir_instructions.len),
44164414 else => unreachable,
44174415 }
44184416}
......@@ -4550,7 +4548,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
45504548 // If the type has no codegen bits, no need to store it.
45514549 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
45524550
4553 if (Air.refToIndex(ref)) |inst| {
4551 if (ref.toIndex()) |inst| {
45544552 return self.getResolvedInstValue(inst);
45554553 }
45564554
......@@ -4606,7 +4604,7 @@ fn reuseOperand(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, op_ind
46064604
46074605 // That makes us responsible for doing the rest of the stuff that processDeath would have done.
46084606 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
46114609 return true;
46124610}
......@@ -4767,7 +4765,7 @@ fn trunc(
47674765 defer if (lock) |reg| self.register_manager.unlockReg(reg);
47684766
47694767 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
47724770 if (operand == .register and self.reuseOperand(inst, ty_op.operand, 0, operand)) {
47734771 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
828828 if (result != .none) {
829829 assert(result != .stack); // it's illegal to store a stack value as we cannot track its position
830830 const branch = func.currentBranch();
831 branch.values.putAssumeCapacityNoClobber(Air.indexToRef(inst), result);
831 branch.values.putAssumeCapacityNoClobber(inst.toRef(), result);
832832 }
833833
834834 if (builtin.mode == .Debug) {
......@@ -864,7 +864,7 @@ const BigTomb = struct {
864864 fn finishAir(bt: *BigTomb, result: WValue) void {
865865 assert(result != .stack);
866866 if (result != .none) {
867 bt.gen.currentBranch().values.putAssumeCapacityNoClobber(Air.indexToRef(bt.inst), result);
867 bt.gen.currentBranch().values.putAssumeCapacityNoClobber(bt.inst.toRef(), result);
868868 }
869869
870870 if (builtin.mode == .Debug) {
......@@ -883,7 +883,7 @@ fn iterateBigTomb(func: *CodeGen, inst: Air.Inst.Index, operand_count: usize) !B
883883}
884884
885885fn processDeath(func: *CodeGen, ref: Air.Inst.Ref) void {
886 if (Air.refToIndex(ref) == null) return;
886 if (ref.toIndex() == null) return;
887887 // Branches are currently only allowed to free locals allocated
888888 // within their own branch.
889889 // TODO: Upon branch consolidation free any locals if needed.
......@@ -893,7 +893,7 @@ fn processDeath(func: *CodeGen, ref: Air.Inst.Ref) void {
893893 if (value.local.value < reserved_indexes) {
894894 return; // function arguments can never be re-used
895895 }
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 });
897897 value.local.references -= 1; // if this panics, a call to `reuseOperand` was forgotten by the developer
898898 if (value.local.references == 0) {
899899 value.free(func);
......@@ -1265,7 +1265,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
12651265 // In case we have a return value, but the last instruction is a noreturn (such as a while loop)
12661266 // we emit an unreachable instruction to tell the stack validator that part will never be reached.
12671267 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);
12691269 const last_inst_ty = func.typeOfIndex(inst);
12701270 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(mod) or last_inst_ty.isNoReturn(mod)) {
12711271 try func.addTag(.@"unreachable");
......@@ -1828,7 +1828,7 @@ fn buildPointerOffset(func: *CodeGen, ptr_value: WValue, offset: u64, action: en
18281828
18291829fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
18301830 const air_tags = func.air.instructions.items(.tag);
1831 return switch (air_tags[inst]) {
1831 return switch (air_tags[@intFromEnum(inst)]) {
18321832 .inferred_alloc, .inferred_alloc_comptime => unreachable,
18331833
18341834 .add => func.airBinOp(inst, .add),
......@@ -2086,7 +2086,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
20862086 if (builtin.mode == .Debug and func.air_bookkeeping < old_bookkeeping_value + 1) {
20872087 std.debug.panic("Missing call to `finishAir` in AIR instruction %{d} ('{}')", .{
20882088 inst,
2089 func.air.instructions.items(.tag)[inst],
2089 func.air.instructions.items(.tag)[@intFromEnum(inst)],
20902090 });
20912091 }
20922092 }
......@@ -2094,7 +2094,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
20942094
20952095fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20962096 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;
20982098 const operand = try func.resolveInst(un_op);
20992099 const fn_info = mod.typeToFunc(func.decl.ty).?;
21002100 const ret_ty = Type.fromInterned(fn_info.return_type);
......@@ -2157,7 +2157,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21572157
21582158fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21592159 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;
21612161 const operand = try func.resolveInst(un_op);
21622162 const ret_ty = func.typeOf(un_op).childType(mod);
21632163
......@@ -2178,7 +2178,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21782178
21792179fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) InnerError!void {
21802180 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;
21822182 const extra = func.air.extraData(Air.Call, pl_op.payload);
21832183 const args = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[extra.end..][0..extra.data.args_len]));
21842184 const ty = func.typeOf(pl_op.operand);
......@@ -2301,7 +2301,7 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
23012301 } else {
23022302 // TODO if the value is undef, don't lower this instruction
23032303 }
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
23062306 const lhs = try func.resolveInst(bin_op.lhs);
23072307 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
24572457
24582458fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
24592459 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;
24612461 const operand = try func.resolveInst(ty_op.operand);
2462 const ty = func.air.getRefType(ty_op.ty);
2462 const ty = ty_op.ty.toType();
24632463 const ptr_ty = func.typeOf(ty_op.operand);
24642464 const ptr_info = ptr_ty.ptrInfo(mod);
24652465
......@@ -2569,7 +2569,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
25692569
25702570 switch (func.debug_output) {
25712571 .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;
25732573 const name = mod.getParamName(func.func_index, src_index);
25742574 try dwarf.genArgDbgInfo(name, arg_ty, mod.funcOwnerDeclIndex(func.func_index), .{
25752575 .wasm_local = arg.local.value,
......@@ -2583,7 +2583,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
25832583
25842584fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
25852585 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;
25872587 const lhs = try func.resolveInst(bin_op.lhs);
25882588 const rhs = try func.resolveInst(bin_op.rhs);
25892589 const lhs_ty = func.typeOf(bin_op.lhs);
......@@ -2789,7 +2789,7 @@ const FloatOp = enum {
27892789
27902790fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
27912791 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;
27932793 const operand = try func.resolveInst(ty_op.operand);
27942794 const ty = func.typeOf(ty_op.operand);
27952795 const scalar_ty = ty.scalarType(mod);
......@@ -2864,7 +2864,7 @@ fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
28642864}
28652865
28662866fn 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;
28682868 const operand = try func.resolveInst(un_op);
28692869 const ty = func.typeOf(un_op);
28702870
......@@ -2980,7 +2980,7 @@ fn floatNeg(func: *CodeGen, ty: Type, arg: WValue) InnerError!WValue {
29802980
29812981fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
29822982 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
29852985 const lhs = try func.resolveInst(bin_op.lhs);
29862986 const rhs = try func.resolveInst(bin_op.rhs);
......@@ -3473,11 +3473,11 @@ fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {
34733473
34743474fn airBlock(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
34753475 const mod = func.bin_file.base.options.module.?;
3476 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
3477 const block_ty = func.air.getRefType(ty_pl.ty);
3476 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3477 const block_ty = ty_pl.ty.toType();
34783478 const wasm_block_ty = genBlockType(block_ty, mod);
34793479 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
34823482 // if wasm_block_ty is non-empty, we create a register to store the temporary value
34833483 const block_result: WValue = if (wasm_block_ty != wasm.block_empty) blk: {
......@@ -3518,9 +3518,9 @@ fn endBlock(func: *CodeGen) !void {
35183518}
35193519
35203520fn 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;
35223522 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
35253525 // result type of loop is always 'noreturn', meaning we can always
35263526 // emit the wasm type 'block_empty'.
......@@ -3535,11 +3535,11 @@ fn airLoop(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
35353535}
35363536
35373537fn 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;
35393539 const condition = try func.resolveInst(pl_op.operand);
35403540 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];
3542 const else_body = func.air.extra[extra.end + then_body.len ..][0..extra.data.else_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: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
35433543 const liveness_condbr = func.liveness.getCondBr(inst);
35443544
35453545 // 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 {
35793579}
35803580
35813581fn 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
35843584 const lhs = try func.resolveInst(bin_op.lhs);
35853585 const rhs = try func.resolveInst(bin_op.rhs);
......@@ -3705,7 +3705,7 @@ fn airCmpVector(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37053705}
37063706
37073707fn 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;
37093709 const operand = try func.resolveInst(un_op);
37103710 const sym_index = try func.bin_file.getGlobalSymbol("__zig_errors_len", null);
37113711 const errors_len = WValue{ .memory = sym_index };
......@@ -3721,7 +3721,7 @@ fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37213721
37223722fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37233723 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;
37253725 const block = func.blocks.get(br.block_inst).?;
37263726
37273727 // 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 {
37433743}
37443744
37453745fn 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
37483748 const operand = try func.resolveInst(ty_op.operand);
37493749 const operand_ty = func.typeOf(ty_op.operand);
......@@ -3809,7 +3809,7 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38093809}
38103810
38113811fn 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;
38133813 const result = result: {
38143814 const operand = try func.resolveInst(ty_op.operand);
38153815 const wanted_ty = func.typeOfIndex(inst);
......@@ -3853,7 +3853,7 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn
38533853
38543854fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38553855 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;
38573857 const extra = func.air.extraData(Air.StructField, ty_pl.payload);
38583858
38593859 const struct_ptr = try func.resolveInst(extra.data.struct_operand);
......@@ -3865,7 +3865,7 @@ fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38653865
38663866fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {
38673867 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;
38693869 const struct_ptr = try func.resolveInst(ty_op.operand);
38703870 const struct_ptr_ty = func.typeOf(ty_op.operand);
38713871 const struct_ty = struct_ptr_ty.childType(mod);
......@@ -3916,7 +3916,7 @@ fn structFieldPtr(
39163916fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39173917 const mod = func.bin_file.base.options.module.?;
39183918 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;
39203920 const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data;
39213921
39223922 const struct_ty = func.typeOf(struct_field.struct_operand);
......@@ -4016,7 +4016,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40164016 const mod = func.bin_file.base.options.module.?;
40174017 // result type is always 'noreturn'
40184018 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;
40204020 const target = try func.resolveInst(pl_op.operand);
40214021 const target_ty = func.typeOf(pl_op.operand);
40224022 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 {
40404040 var highest_maybe: ?i32 = null;
40414041 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
40424042 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]));
4044 const case_body = func.air.extra[case.end + items.len ..][0..case.data.body_len];
4043 const items: []const Air.Inst.Ref = @ptrCast(func.air.extra[case.end..][0..case.data.items_len]);
4044 const case_body: []const Air.Inst.Index = @ptrCast(func.air.extra[case.end + items.len ..][0..case.data.body_len]);
40454045 extra_index = case.end + items.len + case_body.len;
40464046 const values = try func.gpa.alloc(CaseValue, items.len);
40474047 errdefer func.gpa.free(values);
......@@ -4072,7 +4072,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40724072 // TODO: Benchmark this to find a proper value, LLVM seems to draw the line at '40~45'.
40734073 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]);
40764076 const has_else_body = else_body.len != 0;
40774077 if (has_else_body) {
40784078 try func.startBlock(.block, blocktype);
......@@ -4194,7 +4194,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41944194
41954195fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void {
41964196 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;
41984198 const operand = try func.resolveInst(un_op);
41994199 const err_union_ty = func.typeOf(un_op);
42004200 const pl_ty = err_union_ty.errorUnionPayload(mod);
......@@ -4229,7 +4229,7 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
42294229
42304230fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
42314231 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
42344234 const operand = try func.resolveInst(ty_op.operand);
42354235 const op_ty = func.typeOf(ty_op.operand);
......@@ -4257,7 +4257,7 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
42574257
42584258fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
42594259 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
42624262 const operand = try func.resolveInst(ty_op.operand);
42634263 const op_ty = func.typeOf(ty_op.operand);
......@@ -4281,7 +4281,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
42814281
42824282fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42834283 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
42864286 const operand = try func.resolveInst(ty_op.operand);
42874287 const err_ty = func.typeOfIndex(inst);
......@@ -4311,10 +4311,10 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
43114311
43124312fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43134313 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
43164316 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();
43184318 const pl_ty = err_ty.errorUnionPayload(mod);
43194319
43204320 const result = result: {
......@@ -4337,9 +4337,9 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43374337}
43384338
43394339fn 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();
43434343 const operand = try func.resolveInst(ty_op.operand);
43444344 const operand_ty = func.typeOf(ty_op.operand);
43454345 const mod = func.bin_file.base.options.module.?;
......@@ -4434,7 +4434,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
44344434
44354435fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {
44364436 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;
44384438 const operand = try func.resolveInst(un_op);
44394439
44404440 const op_ty = func.typeOf(un_op);
......@@ -4476,7 +4476,7 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod
44764476
44774477fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44784478 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;
44804480 const opt_ty = func.typeOf(ty_op.operand);
44814481 const payload_ty = func.typeOfIndex(inst);
44824482 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -4499,7 +4499,7 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44994499
45004500fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45014501 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;
45034503 const operand = try func.resolveInst(ty_op.operand);
45044504 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 {
45164516
45174517fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45184518 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;
45204520 const operand = try func.resolveInst(ty_op.operand);
45214521 const opt_ty = func.typeOf(ty_op.operand).childType(mod);
45224522 const payload_ty = opt_ty.optionalChild(mod);
......@@ -4541,7 +4541,7 @@ fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
45414541}
45424542
45434543fn 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;
45454545 const payload_ty = func.typeOf(ty_op.operand);
45464546 const mod = func.bin_file.base.options.module.?;
45474547
......@@ -4578,7 +4578,7 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45784578}
45794579
45804580fn 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;
45824582 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
45834583
45844584 const lhs = try func.resolveInst(bin_op.lhs);
......@@ -4593,7 +4593,7 @@ fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45934593}
45944594
45954595fn 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
45984598 const operand = try func.resolveInst(ty_op.operand);
45994599 func.finishAir(inst, try func.sliceLen(operand), &.{ty_op.operand});
......@@ -4601,7 +4601,7 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46014601
46024602fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46034603 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
46064606 const slice_ty = func.typeOf(bin_op.lhs);
46074607 const slice = try func.resolveInst(bin_op.lhs);
......@@ -4631,10 +4631,10 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46314631
46324632fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46334633 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;
46354635 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);
46384638 const elem_size = elem_ty.abiSize(mod);
46394639
46404640 const slice = try func.resolveInst(bin_op.lhs);
......@@ -4654,7 +4654,7 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46544654}
46554655
46564656fn 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;
46584658 const operand = try func.resolveInst(ty_op.operand);
46594659 func.finishAir(inst, try func.slicePtr(operand), &.{ty_op.operand});
46604660}
......@@ -4670,10 +4670,10 @@ fn sliceLen(func: *CodeGen, operand: WValue) InnerError!WValue {
46704670}
46714671
46724672fn 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
46754675 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();
46774677 const op_ty = func.typeOf(ty_op.operand);
46784678
46794679 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
46994699}
47004700
47014701fn 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;
47034703 const operand = try func.resolveInst(un_op);
47044704 const result = func.reuseOperand(un_op, operand);
47054705
......@@ -4708,11 +4708,11 @@ fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47084708
47094709fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47104710 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
47134713 const operand = try func.resolveInst(ty_op.operand);
47144714 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
47174717 // create a slice on the stack
47184718 const slice_local = try func.allocStack(slice_ty);
......@@ -4731,7 +4731,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47314731
47324732fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47334733 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;
47354735 const operand = try func.resolveInst(un_op);
47364736 const ptr_ty = func.typeOf(un_op);
47374737 const result = if (ptr_ty.isSlice(mod))
......@@ -4746,7 +4746,7 @@ fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47464746
47474747fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47484748 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
47514751 const ptr_ty = func.typeOf(bin_op.lhs);
47524752 const ptr = try func.resolveInst(bin_op.lhs);
......@@ -4783,11 +4783,11 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47834783
47844784fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47854785 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;
47874787 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
47884788
47894789 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);
47914791 const elem_size = elem_ty.abiSize(mod);
47924792
47934793 const ptr = try func.resolveInst(bin_op.lhs);
......@@ -4813,7 +4813,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48134813
48144814fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
48154815 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;
48174817 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
48184818
48194819 const ptr = try func.resolveInst(bin_op.lhs);
......@@ -4846,7 +4846,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
48464846 } else {
48474847 // TODO if the value is undef, don't lower this instruction
48484848 }
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
48514851 const ptr = try func.resolveInst(bin_op.lhs);
48524852 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
49634963
49644964fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49654965 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
49684968 const array_ty = func.typeOf(bin_op.lhs);
49694969 const array = try func.resolveInst(bin_op.lhs);
......@@ -5032,7 +5032,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50325032
50335033fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50345034 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
50375037 const operand = try func.resolveInst(ty_op.operand);
50385038 const op_ty = func.typeOf(ty_op.operand);
......@@ -5077,7 +5077,7 @@ fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50775077
50785078fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50795079 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
50825082 const operand = try func.resolveInst(ty_op.operand);
50835083 const op_ty = func.typeOf(ty_op.operand);
......@@ -5123,7 +5123,7 @@ fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51235123
51245124fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51255125 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;
51275127 const operand = try func.resolveInst(ty_op.operand);
51285128 const ty = func.typeOfIndex(inst);
51295129 const elem_ty = ty.childType(mod);
......@@ -5193,7 +5193,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51935193}
51945194
51955195fn 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;
51975197 const operand = try func.resolveInst(pl_op.operand);
51985198
51995199 _ = operand;
......@@ -5203,7 +5203,7 @@ fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52035203fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52045204 const mod = func.bin_file.base.options.module.?;
52055205 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;
52075207 const extra = func.air.extraData(Air.Shuffle, ty_pl.payload).data;
52085208
52095209 const a = try func.resolveInst(extra.a);
......@@ -5262,7 +5262,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52625262}
52635263
52645264fn 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;
52665266 const operand = try func.resolveInst(reduce.operand);
52675267
52685268 _ = operand;
......@@ -5272,7 +5272,7 @@ fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52725272fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52735273 const mod = func.bin_file.base.options.module.?;
52745274 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;
52765276 const result_ty = func.typeOfIndex(inst);
52775277 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));
52785278 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 {
54025402fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54035403 const mod = func.bin_file.base.options.module.?;
54045404 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;
54065406 const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data;
54075407
54085408 const result = result: {
......@@ -5474,12 +5474,12 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54745474}
54755475
54765476fn 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;
54785478 func.finishAir(inst, .none, &.{prefetch.ptr});
54795479}
54805480
54815481fn 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
54845484 const result = try func.allocLocal(func.typeOfIndex(inst));
54855485 try func.addLabel(.memory_size, pl_op.payload);
......@@ -5488,7 +5488,7 @@ fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54885488}
54895489
54905490fn 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
54935493 const operand = try func.resolveInst(pl_op.operand);
54945494 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
55785578
55795579fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
55805580 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;
55825582 const un_ty = func.typeOf(bin_op.lhs).childType(mod);
55835583 const tag_ty = func.typeOf(bin_op.rhs);
55845584 const layout = un_ty.unionGetLayout(mod);
......@@ -5602,7 +5602,7 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56025602
56035603fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56045604 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
56075607 const un_ty = func.typeOf(ty_op.operand);
56085608 const tag_ty = func.typeOfIndex(inst);
......@@ -5621,7 +5621,7 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56215621}
56225622
56235623fn 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
56265626 const dest_ty = func.typeOfIndex(inst);
56275627 const operand = try func.resolveInst(ty_op.operand);
......@@ -5666,7 +5666,7 @@ fn fpext(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!
56665666}
56675667
56685668fn 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
56715671 const dest_ty = func.typeOfIndex(inst);
56725672 const operand = try func.resolveInst(ty_op.operand);
......@@ -5707,7 +5707,7 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
57075707
57085708fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57095709 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
57125712 const err_set_ty = func.typeOf(ty_op.operand).childType(mod);
57135713 const payload_ty = err_set_ty.errorUnionPayload(mod);
......@@ -5733,11 +5733,11 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
57335733
57345734fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57355735 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;
57375737 const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
57385738
57395739 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);
57415741 const field_offset = parent_ty.structFieldOffset(extra.field_index, mod);
57425742
57435743 const result = if (field_offset != 0) result: {
......@@ -5763,7 +5763,7 @@ fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue
57635763
57645764fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57655765 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;
57675767 const dst = try func.resolveInst(bin_op.lhs);
57685768 const dst_ty = func.typeOf(bin_op.lhs);
57695769 const ptr_elem_ty = dst_ty.childType(mod);
......@@ -5803,7 +5803,7 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58035803
58045804fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58055805 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
58085808 const operand = try func.resolveInst(ty_op.operand);
58095809 const op_ty = func.typeOf(ty_op.operand);
......@@ -5847,7 +5847,7 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58475847}
58485848
58495849fn 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
58525852 const operand = try func.resolveInst(un_op);
58535853 // First retrieve the symbol index to the error name table
......@@ -5889,7 +5889,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58895889}
58905890
58915891fn 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;
58935893 const slice_ptr = try func.resolveInst(ty_op.operand);
58945894 const result = try func.buildPointerOffset(slice_ptr, offset, .new);
58955895 func.finishAir(inst, result, &.{ty_op.operand});
......@@ -5897,7 +5897,7 @@ fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerE
58975897
58985898fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
58995899 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;
59015901 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
59025902
59035903 const lhs_op = try func.resolveInst(extra.lhs);
......@@ -6041,7 +6041,7 @@ fn addSubWithOverflowBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type,
60416041
60426042fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
60436043 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;
60456045 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
60466046
60476047 const lhs = try func.resolveInst(extra.lhs);
......@@ -6097,7 +6097,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
60976097}
60986098
60996099fn 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;
61016101 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
61026102
61036103 const lhs = try func.resolveInst(extra.lhs);
......@@ -6275,7 +6275,7 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
62756275 assert(op == .max or op == .min);
62766276 const mod = func.bin_file.base.options.module.?;
62776277 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
62806280 const ty = func.typeOfIndex(inst);
62816281 if (ty.zigTypeTag(mod) == .Vector) {
......@@ -6318,7 +6318,7 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
63186318
63196319fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63206320 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;
63226322 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;
63236323
63246324 const ty = func.typeOfIndex(inst);
......@@ -6352,7 +6352,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63526352
63536353fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63546354 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
63576357 const ty = func.typeOf(ty_op.operand);
63586358 const result_ty = func.typeOfIndex(inst);
......@@ -6405,7 +6405,7 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64056405
64066406fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64076407 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
64106410 const ty = func.typeOf(ty_op.operand);
64116411 const result_ty = func.typeOfIndex(inst);
......@@ -6472,7 +6472,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
64726472 if (func.debug_output != .dwarf) return func.finishAir(inst, .none, &.{});
64736473
64746474 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;
64766476 const ty = func.typeOf(pl_op.operand);
64776477 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 {
64966496fn airDbgStmt(func: *CodeGen, inst: Air.Inst.Index) !void {
64976497 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;
65006500 try func.addInst(.{ .tag = .dbg_line, .data = .{
65016501 .payload = try func.addExtra(Mir.DbgLineColumn{
65026502 .line = dbg_stmt.line,
......@@ -6507,10 +6507,10 @@ fn airDbgStmt(func: *CodeGen, inst: Air.Inst.Index) !void {
65076507}
65086508
65096509fn 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;
65116511 const err_union = try func.resolveInst(pl_op.operand);
65126512 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]);
65146514 const err_union_ty = func.typeOf(pl_op.operand);
65156515 const result = try lowerTry(func, inst, err_union, body, err_union_ty, false);
65166516 func.finishAir(inst, result, &.{pl_op.operand});
......@@ -6518,10 +6518,10 @@ fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
65186518
65196519fn airTryPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
65206520 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;
65226522 const extra = func.air.extraData(Air.TryPtr, ty_pl.payload);
65236523 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]);
65256525 const err_union_ty = func.typeOf(extra.data.ptr).childType(mod);
65266526 const result = try lowerTry(func, inst, err_union_ptr, body, err_union_ty, true);
65276527 func.finishAir(inst, result, &.{extra.data.ptr});
......@@ -6585,7 +6585,7 @@ fn lowerTry(
65856585
65866586fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
65876587 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
65906590 const ty = func.typeOfIndex(inst);
65916591 const operand = try func.resolveInst(ty_op.operand);
......@@ -6656,7 +6656,7 @@ fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66566656
66576657fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66586658 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
66616661 const ty = func.typeOfIndex(inst);
66626662 const lhs = try func.resolveInst(bin_op.lhs);
......@@ -6671,7 +6671,7 @@ fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66716671
66726672fn airDivTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66736673 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
66766676 const ty = func.typeOfIndex(inst);
66776677 const lhs = try func.resolveInst(bin_op.lhs);
......@@ -6691,7 +6691,7 @@ fn airDivTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66916691}
66926692
66936693fn 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
66966696 const mod = func.bin_file.base.options.module.?;
66976697 const ty = func.typeOfIndex(inst);
......@@ -6834,7 +6834,7 @@ fn divSigned(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type) InnerError!WVal
68346834/// Remainder after floor division, defined by:
68356835/// @divFloor(a, b) * b + @mod(a, b) = a
68366836fn 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
68396839 const mod = func.bin_file.base.options.module.?;
68406840 const ty = func.typeOfIndex(inst);
......@@ -6917,7 +6917,7 @@ fn signExtendInt(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
69176917
69186918fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
69196919 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
69226922 const mod = func.bin_file.base.options.module.?;
69236923 const ty = func.typeOfIndex(inst);
......@@ -7032,7 +7032,7 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type,
70327032}
70337033
70347034fn 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
70377037 const mod = func.bin_file.base.options.module.?;
70387038 const ty = func.typeOfIndex(inst);
......@@ -7193,7 +7193,7 @@ fn callIntrinsic(
71937193}
71947194
71957195fn 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;
71977197 const operand = try func.resolveInst(un_op);
71987198 const enum_ty = func.typeOf(un_op);
71997199
......@@ -7365,10 +7365,10 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
73657365
73667366fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
73677367 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
73707370 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();
73727372 const result = try func.allocLocal(Type.bool);
73737373
73747374 const names = error_set_ty.errorSetNames(mod);
......@@ -7450,7 +7450,7 @@ inline fn useAtomicFeature(func: *const CodeGen) bool {
74507450
74517451fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
74527452 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;
74547454 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
74557455
74567456 const ptr_ty = func.typeOf(extra.ptr);
......@@ -7523,7 +7523,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75237523
75247524fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75257525 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;
75277527 const ptr = try func.resolveInst(atomic_load.ptr);
75287528 const ty = func.typeOfIndex(inst);
75297529
......@@ -7550,7 +7550,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75507550
75517551fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75527552 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;
75547554 const extra = func.air.extraData(Air.AtomicRmw, pl_op.payload).data;
75557555
75567556 const ptr = try func.resolveInst(pl_op.operand);
......@@ -7736,7 +7736,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77367736
77377737fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77387738 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
77417741 const ptr = try func.resolveInst(bin_op.lhs);
77427742 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 {
19011901
19021902 const old_air_bookkeeping = self.air_bookkeeping;
19031903 try self.inst_tracking.ensureUnusedCapacity(self.gpa, 1);
1904 switch (air_tags[inst]) {
1904 switch (air_tags[@intFromEnum(inst)]) {
19051905 // zig fmt: off
19061906 .not,
19071907 => |tag| try self.airUnOp(inst, tag),
......@@ -2148,7 +2148,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
21482148
21492149 if (std.debug.runtime_safety) {
21502150 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)] });
21522152 }
21532153
21542154 { // check consistency of tracked registers
......@@ -2251,7 +2251,7 @@ fn freeValue(self: *Self, value: MCValue) !void {
22512251}
22522252
22532253fn 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);
22552255}
22562256
22572257/// Asserts there is already capacity to insert into top branch inst_table.
......@@ -2292,7 +2292,7 @@ fn finishAir(
22922292 const dies = @as(u1, @truncate(tomb_bits)) != 0;
22932293 tomb_bits >>= 1;
22942294 if (!dies) continue;
2295 try self.processDeath(Air.refToIndexAllowNone(op) orelse continue);
2295 try self.processDeath(op.toIndexAllowNone() orelse continue);
22962296 }
22972297 self.finishAirResult(inst, result);
22982298}
......@@ -2683,7 +2683,7 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
26832683}
26842684
26852685fn 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;
26872687 const dst_ty = self.typeOfIndex(inst);
26882688 const dst_bits = dst_ty.floatBits(self.target.*);
26892689 const src_ty = self.typeOf(ty_op.operand);
......@@ -2782,7 +2782,7 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
27822782}
27832783
27842784fn 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;
27862786 const dst_ty = self.typeOfIndex(inst);
27872787 const dst_bits = dst_ty.floatBits(self.target.*);
27882788 const src_ty = self.typeOf(ty_op.operand);
......@@ -2882,7 +2882,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
28822882
28832883fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
28842884 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;
28862886 const result: MCValue = result: {
28872887 const src_ty = self.typeOf(ty_op.operand);
28882888 const src_int_info = src_ty.intInfo(mod);
......@@ -2973,7 +2973,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
29732973
29742974fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
29752975 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
29782978 const dst_ty = self.typeOfIndex(inst);
29792979 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(mod));
......@@ -3086,7 +3086,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
30863086}
30873087
30883088fn 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;
30903090 const ty = self.typeOfIndex(inst);
30913091
30923092 const operand = try self.resolveInst(un_op);
......@@ -3100,7 +3100,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
31003100
31013101fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
31023102 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;
31043104 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
31053105
31063106 const slice_ty = self.typeOfIndex(inst);
......@@ -3123,14 +3123,14 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
31233123}
31243124
31253125fn 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;
31273127 const dst_mcv = try self.genUnOp(inst, tag, ty_op.operand);
31283128 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });
31293129}
31303130
31313131fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
31323132 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;
31343134 const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs);
31353135
31363136 const dst_ty = self.typeOfIndex(inst);
......@@ -3163,7 +3163,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
31633163}
31643164
31653165fn 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;
31673167 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
31683168 const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs);
31693169 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 {
31763176
31773177 const dst_ty = self.typeOf(dst_air);
31783178 const dst_info = dst_ty.intInfo(mod);
3179 if (Air.refToIndex(dst_air)) |inst| {
3180 switch (air_tag[inst]) {
3179 if (dst_air.toIndex()) |inst| {
3180 switch (air_tag[@intFromEnum(inst)]) {
31813181 .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);
31833183 const src_info = src_ty.intInfo(mod);
31843184 return @min(switch (src_info.signedness) {
31853185 .signed => switch (dst_info.signedness) {
......@@ -3194,7 +3194,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
31943194 },
31953195 else => {},
31963196 }
3197 } else if (Air.refToInterned(dst_air)) |ip_index| {
3197 } else if (dst_air.toInterned()) |ip_index| {
31983198 var space: Value.BigIntSpace = undefined;
31993199 const src_int = Value.fromInterned(ip_index).toBigInt(&space, mod);
32003200 return @as(u16, @intCast(src_int.bitCountTwosComp())) +
......@@ -3205,9 +3205,9 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
32053205
32063206fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
32073207 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;
32093209 const result = result: {
3210 const tag = self.air.instructions.items(.tag)[inst];
3210 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
32113211 const dst_ty = self.typeOfIndex(inst);
32123212 switch (dst_ty.zigTypeTag(mod)) {
32133213 .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 {
34313431
34323432fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
34333433 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;
34353435 const ty = self.typeOf(bin_op.lhs);
34363436 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail(
34373437 "TODO implement airAddSat for {}",
......@@ -3514,7 +3514,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
35143514
35153515fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
35163516 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;
35183518 const ty = self.typeOf(bin_op.lhs);
35193519 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail(
35203520 "TODO implement airSubSat for {}",
......@@ -3590,7 +3590,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
35903590
35913591fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
35923592 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;
35943594 const ty = self.typeOf(bin_op.lhs);
35953595
35963596 const result = result: {
......@@ -3730,10 +3730,10 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
37303730
37313731fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
37323732 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;
37343734 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
37353735 const result: MCValue = result: {
3736 const tag = self.air.instructions.items(.tag)[inst];
3736 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
37373737 const ty = self.typeOf(bin_op.lhs);
37383738 switch (ty.zigTypeTag(mod)) {
37393739 .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 {
37913791
37923792fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
37933793 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;
37953795 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
37963796 const result: MCValue = result: {
37973797 const lhs_ty = self.typeOf(bin_op.lhs);
......@@ -3934,7 +3934,7 @@ fn genSetFrameTruncatedOverflowCompare(
39343934
39353935fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
39363936 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;
39383938 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
39393939 const tuple_ty = self.typeOfIndex(inst);
39403940 const dst_ty = self.typeOf(bin_op.lhs);
......@@ -4270,10 +4270,10 @@ fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCVa
42704270
42714271fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
42724272 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
42754275 const air_tags = self.air.instructions.items(.tag);
4276 const tag = air_tags[inst];
4276 const tag = air_tags[@intFromEnum(inst)];
42774277 const lhs_ty = self.typeOf(bin_op.lhs);
42784278 const rhs_ty = self.typeOf(bin_op.rhs);
42794279 const result: MCValue = result: {
......@@ -4449,7 +4449,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
44494449 },
44504450 else => {},
44514451 }
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)]) {
44534453 .splat => {
44544454 const abi_size: u32 = @intCast(lhs_ty.abiSize(mod));
44554455
......@@ -4537,7 +4537,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
45374537}
45384538
45394539fn 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;
45414541 _ = bin_op;
45424542 return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch});
45434543 //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 {
45454545
45464546fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
45474547 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;
45494549 const result: MCValue = result: {
45504550 const pl_ty = self.typeOfIndex(inst);
45514551 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none;
......@@ -4577,7 +4577,7 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
45774577}
45784578
45794579fn 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
45824582 const dst_ty = self.typeOfIndex(inst);
45834583 const opt_mcv = try self.resolveInst(ty_op.operand);
......@@ -4591,7 +4591,7 @@ fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
45914591
45924592fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
45934593 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;
45954595 const result = result: {
45964596 const dst_ty = self.typeOfIndex(inst);
45974597 const src_ty = self.typeOf(ty_op.operand);
......@@ -4625,7 +4625,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
46254625
46264626fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
46274627 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;
46294629 const err_union_ty = self.typeOf(ty_op.operand);
46304630 const err_ty = err_union_ty.errorUnionSet(mod);
46314631 const payload_ty = err_union_ty.errorUnionPayload(mod);
......@@ -4667,7 +4667,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
46674667}
46684668
46694669fn 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;
46714671 const operand_ty = self.typeOf(ty_op.operand);
46724672 const operand = try self.resolveInst(ty_op.operand);
46734673 const result = try self.genUnwrapErrUnionPayloadMir(inst, operand_ty, operand);
......@@ -4677,7 +4677,7 @@ fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
46774677// *(E!T) -> E
46784678fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
46794679 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
46824682 const src_ty = self.typeOf(ty_op.operand);
46834683 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -4715,7 +4715,7 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
47154715
47164716// *(E!T) -> *T
47174717fn 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;
47194719 const operand_ty = self.typeOf(ty_op.operand);
47204720 const operand = try self.resolveInst(ty_op.operand);
47214721 const result = try self.genUnwrapErrUnionPayloadPtrMir(inst, operand_ty, operand);
......@@ -4724,7 +4724,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
47244724
47254725fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
47264726 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;
47284728 const result: MCValue = result: {
47294729 const src_ty = self.typeOf(ty_op.operand);
47304730 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -4866,7 +4866,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
48664866
48674867fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
48684868 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;
48704870 const result: MCValue = result: {
48714871 const pl_ty = self.typeOf(ty_op.operand);
48724872 if (!pl_ty.hasRuntimeBits(mod)) break :result .{ .immediate = 1 };
......@@ -4920,9 +4920,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
49204920/// T to E!T
49214921fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
49224922 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();
49264926 const pl_ty = eu_ty.errorUnionPayload(mod);
49274927 const err_ty = eu_ty.errorUnionSet(mod);
49284928 const operand = try self.resolveInst(ty_op.operand);
......@@ -4943,9 +4943,9 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
49434943/// E to E!T
49444944fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
49454945 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();
49494949 const pl_ty = eu_ty.errorUnionPayload(mod);
49504950 const err_ty = eu_ty.errorUnionSet(mod);
49514951
......@@ -4964,7 +4964,7 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
49644964}
49654965
49664966fn 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;
49684968 const result = result: {
49694969 const src_mcv = try self.resolveInst(ty_op.operand);
49704970 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 {
49784978}
49794979
49804980fn 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
49834983 const result: MCValue = result: {
49844984 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -5002,7 +5002,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
50025002
50035003fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
50045004 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
50075007 const src_ty = self.typeOf(ty_op.operand);
50085008 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -5036,7 +5036,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
50365036}
50375037
50385038fn 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
50415041 const dst_ty = self.typeOfIndex(inst);
50425042 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 {
51065106
51075107fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
51085108 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
51115111 const result: MCValue = result: {
51125112 const elem_ty = self.typeOfIndex(inst);
......@@ -5123,7 +5123,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
51235123}
51245124
51255125fn 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;
51275127 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
51285128 const dst_mcv = try self.genSliceElemPtr(extra.lhs, extra.rhs);
51295129 return self.finishAir(inst, dst_mcv, .{ extra.lhs, extra.rhs, .none });
......@@ -5131,7 +5131,7 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
51315131
51325132fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
51335133 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
51365136 const array_ty = self.typeOf(bin_op.lhs);
51375137 const array = try self.resolveInst(bin_op.lhs);
......@@ -5205,7 +5205,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
52055205
52065206fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
52075207 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;
52095209 const ptr_ty = self.typeOf(bin_op.lhs);
52105210
52115211 // this is identical to the `airPtrElemPtr` codegen expect here an
......@@ -5255,7 +5255,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
52555255
52565256fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
52575257 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;
52595259 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
52605260
52615261 const ptr_ty = self.typeOf(extra.lhs);
......@@ -5288,7 +5288,7 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
52885288
52895289fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
52905290 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;
52925292 const ptr_union_ty = self.typeOf(bin_op.lhs);
52935293 const union_ty = ptr_union_ty.childType(mod);
52945294 const tag_ty = self.typeOf(bin_op.rhs);
......@@ -5332,7 +5332,7 @@ fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
53325332
53335333fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
53345334 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
53375337 const tag_ty = self.typeOfIndex(inst);
53385338 const union_ty = self.typeOf(ty_op.operand);
......@@ -5386,7 +5386,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
53865386
53875387fn airClz(self: *Self, inst: Air.Inst.Index) !void {
53885388 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;
53905390 const result = result: {
53915391 const dst_ty = self.typeOfIndex(inst);
53925392 const src_ty = self.typeOf(ty_op.operand);
......@@ -5545,7 +5545,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
55455545
55465546fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
55475547 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;
55495549 const result = result: {
55505550 const dst_ty = self.typeOfIndex(inst);
55515551 const src_ty = self.typeOf(ty_op.operand);
......@@ -5663,7 +5663,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
56635663
56645664fn airPopCount(self: *Self, inst: Air.Inst.Index) !void {
56655665 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;
56675667 const result: MCValue = result: {
56685668 try self.spillEflagsIfOccupied();
56695669
......@@ -5818,7 +5818,7 @@ fn genByteSwap(
58185818 mem_ok: bool,
58195819) !MCValue {
58205820 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
58235823 if (src_ty.zigTypeTag(mod) == .Vector) return self.fail(
58245824 "TODO implement genByteSwap for {}",
......@@ -5909,7 +5909,7 @@ fn genByteSwap(
59095909
59105910fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
59115911 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
59145914 const src_ty = self.typeOf(ty_op.operand);
59155915 const abi_size: u32 = @intCast(src_ty.abiSize(mod));
......@@ -5931,7 +5931,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
59315931
59325932fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
59335933 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
59365936 const src_ty = self.typeOf(ty_op.operand);
59375937 const abi_size: u32 = @intCast(src_ty.abiSize(mod));
......@@ -6053,7 +6053,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
60536053
60546054fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) !void {
60556055 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
60586058 const result = result: {
60596059 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)
61796179}
61806180
61816181fn 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;
61836183 const ty = self.typeOf(un_op);
61846184 return self.floatSign(inst, un_op, ty);
61856185}
......@@ -6204,7 +6204,7 @@ const RoundMode = packed struct(u5) {
62046204};
62056205
62066206fn 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;
62086208 const ty = self.typeOf(un_op);
62096209
62106210 const result = result: {
......@@ -6327,7 +6327,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: Ro
63276327
63286328fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
63296329 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;
63316331 const ty = self.typeOf(ty_op.operand);
63326332
63336333 const result: MCValue = result: {
......@@ -6467,7 +6467,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
64676467
64686468fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
64696469 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;
64716471 const ty = self.typeOf(un_op);
64726472 const abi_size: u32 = @intCast(ty.abiSize(mod));
64736473
......@@ -6634,7 +6634,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
66346634}
66356635
66366636fn 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;
66386638 const ty = self.typeOf(un_op);
66396639 var callee_buf: ["__round?".len]u8 = undefined;
66406640 const result = try self.genCall(.{ .lib = .{
......@@ -6704,7 +6704,7 @@ fn reuseOperandAdvanced(
67046704
67056705 // Prevent the operand deaths processing code from deallocating it.
67066706 self.liveness.clearOperandDeath(inst, op_index);
6707 const op_inst = Air.refToIndex(operand).?;
6707 const op_inst = operand.toIndex().?;
67086708 self.getResolvedInstValue(op_inst).reuse(self, maybe_tracked_inst, op_inst);
67096709
67106710 return true;
......@@ -6852,7 +6852,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerErro
68526852
68536853fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
68546854 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;
68566856 const elem_ty = self.typeOfIndex(inst);
68576857 const result: MCValue = result: {
68586858 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none;
......@@ -7051,7 +7051,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
70517051 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });
70527052 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;
70557055 const ptr_mcv = try self.resolveInst(bin_op.lhs);
70567056 const ptr_ty = self.typeOf(bin_op.lhs);
70577057 const src_mcv = try self.resolveInst(bin_op.rhs);
......@@ -7064,14 +7064,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
70647064}
70657065
70667066fn 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;
70687068 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
70697069 const result = try self.fieldPtr(inst, extra.struct_operand, extra.field_index);
70707070 return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none });
70717071}
70727072
70737073fn 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;
70757075 const result = try self.fieldPtr(inst, ty_op.operand, index);
70767076 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
70777077}
......@@ -7103,7 +7103,7 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
71037103
71047104fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
71057105 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;
71077107 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
71087108 const result: MCValue = result: {
71097109 const operand = extra.struct_operand;
......@@ -7389,7 +7389,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
73897389
73907390fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
73917391 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;
73937393 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
73947394
73957395 const inst_ty = self.typeOfIndex(inst);
......@@ -7943,7 +7943,7 @@ fn genShiftBinOp(
79437943
79447944 const dst_mcv: MCValue = dst: {
79457945 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;
79477947 if (self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv)) break :dst lhs_mcv;
79487948 }
79497949 const dst_mcv = try self.allocRegOrMemAdvanced(lhs_ty, maybe_inst, true);
......@@ -10496,7 +10496,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
1049610496 else => return self.fail("TODO implement arg for {}", .{src_mcv}),
1049710497 };
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;
1050010500 const name = mod.getParamName(self.owner.func_index, src_index);
1050110501 try self.genArgDbgInfo(arg_ty, name, src_mcv);
1050210502
......@@ -10609,7 +10609,7 @@ fn airFrameAddress(self: *Self, inst: Air.Inst.Index) !void {
1060910609}
1061010610
1061110611fn 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;
1061310613 switch (order) {
1061410614 .Unordered, .Monotonic => unreachable,
1061510615 .Acquire, .Release, .AcqRel => {},
......@@ -10621,7 +10621,7 @@ fn airFence(self: *Self, inst: Air.Inst.Index) !void {
1062110621fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void {
1062210622 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;
1062510625 const extra = self.air.extraData(Air.Call, pl_op.payload);
1062610626 const arg_refs: []const Air.Inst.Ref =
1062710627 @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
......@@ -10883,7 +10883,7 @@ fn genCall(self: *Self, info: union(enum) {
1088310883
1088410884fn airRet(self: *Self, inst: Air.Inst.Index) !void {
1088510885 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
1088810888 const ret_ty = self.fn_type.fnReturnType(mod);
1088910889 switch (self.ret_mcv.short) {
......@@ -10911,7 +10911,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
1091110911}
1091210912
1091310913fn 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;
1091510915 const ptr = try self.resolveInst(un_op);
1091610916
1091710917 const ptr_ty = self.typeOf(un_op);
......@@ -10932,7 +10932,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
1093210932
1093310933fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1093410934 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;
1093610936 const ty = self.typeOf(bin_op.lhs);
1093710937
1093810938 const result: Condition = result: {
......@@ -11313,7 +11313,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1131311313}
1131411314
1131511315fn 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;
1131711317 const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;
1131811318 const dst_mcv = try self.genBinOp(
1131911319 inst,
......@@ -11326,7 +11326,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
1132611326
1132711327fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
1132811328 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
1133111331 const addr_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
1133211332 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);
......@@ -11356,18 +11356,18 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
1135611356}
1135711357
1135811358fn 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;
1136011360 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]);
1136211362 const operand_ty = self.typeOf(pl_op.operand);
1136311363 const result = try self.genTry(inst, pl_op.operand, body, operand_ty, false);
1136411364 return self.finishAir(inst, result, .{ .none, .none, .none });
1136511365}
1136611366
1136711367fn 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;
1136911369 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]);
1137111371 const operand_ty = self.typeOf(extra.data.ptr);
1137211372 const result = try self.genTry(inst, extra.data.ptr, body, operand_ty, true);
1137311373 return self.finishAir(inst, result, .{ .none, .none, .none });
......@@ -11392,7 +11392,7 @@ fn genTry(
1139211392 const reloc = try self.genCondBrMir(Type.anyerror, is_err_mcv);
1139311393
1139411394 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);
1139611396 }
1139711397
1139811398 self.scope_generation += 1;
......@@ -11421,7 +11421,7 @@ fn genTry(
1142111421}
1142211422
1142311423fn 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;
1142511425 _ = try self.addInst(.{
1142611426 .tag = .pseudo,
1142711427 .ops = .pseudo_dbg_line_line_column,
......@@ -11434,7 +11434,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
1143411434}
1143511435
1143611436fn 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;
1143811438 _ = try self.addInst(.{
1143911439 .tag = .pseudo,
1144011440 .ops = .pseudo_dbg_inline_func,
......@@ -11450,14 +11450,14 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void {
1145011450}
1145111451
1145211452fn 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;
1145411454 const operand = pl_op.operand;
1145511455 const ty = self.typeOf(operand);
1145611456 const mcv = try self.resolveInst(operand);
1145711457
1145811458 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)];
1146111461 try self.genVarDbgInfo(tag, ty, mcv, name);
1146211462
1146311463 return self.finishAir(inst, .unreach, .{ operand, .none, .none });
......@@ -11492,19 +11492,21 @@ fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !Mir.Inst.Index {
1149211492}
1149311493
1149411494fn 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;
1149611496 const cond = try self.resolveInst(pl_op.operand);
1149711497 const cond_ty = self.typeOf(pl_op.operand);
1149811498 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];
11500 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
11499 const then_body: []const Air.Inst.Index =
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]);
1150111503 const liveness_cond_br = self.liveness.getCondBr(inst);
1150211504
1150311505 // If the condition dies here in this condbr instruction, process
1150411506 // that death now instead of later as this has an effect on
1150511507 // whether it needs to be spilled in the branches
1150611508 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);
1150811510 }
1150911511
1151011512 self.scope_generation += 1;
......@@ -11789,7 +11791,7 @@ fn isNonErrPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue
1178911791}
1179011792
1179111793fn 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;
1179311795 const operand = try self.resolveInst(un_op);
1179411796 const ty = self.typeOf(un_op);
1179511797 const result = try self.isNull(inst, ty, operand);
......@@ -11797,7 +11799,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
1179711799}
1179811800
1179911801fn 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;
1180111803 const operand = try self.resolveInst(un_op);
1180211804 const ty = self.typeOf(un_op);
1180311805 const result = try self.isNullPtr(inst, ty, operand);
......@@ -11805,7 +11807,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
1180511807}
1180611808
1180711809fn 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;
1180911811 const operand = try self.resolveInst(un_op);
1181011812 const ty = self.typeOf(un_op);
1181111813 const result = switch (try self.isNull(inst, ty, operand)) {
......@@ -11816,7 +11818,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
1181611818}
1181711819
1181811820fn 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;
1182011822 const operand = try self.resolveInst(un_op);
1182111823 const ty = self.typeOf(un_op);
1182211824 const result = switch (try self.isNullPtr(inst, ty, operand)) {
......@@ -11827,7 +11829,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
1182711829}
1182811830
1182911831fn 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;
1183111833 const operand = try self.resolveInst(un_op);
1183211834 const ty = self.typeOf(un_op);
1183311835 const result = try self.isErr(inst, ty, operand);
......@@ -11835,7 +11837,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
1183511837}
1183611838
1183711839fn 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;
1183911841 const operand = try self.resolveInst(un_op);
1184011842 const ty = self.typeOf(un_op);
1184111843 const result = try self.isErrPtr(inst, ty, operand);
......@@ -11843,7 +11845,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
1184311845}
1184411846
1184511847fn 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;
1184711849 const operand = try self.resolveInst(un_op);
1184811850 const ty = self.typeOf(un_op);
1184911851 const result = try self.isNonErr(inst, ty, operand);
......@@ -11851,7 +11853,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
1185111853}
1185211854
1185311855fn 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;
1185511857 const operand = try self.resolveInst(un_op);
1185611858 const ty = self.typeOf(un_op);
1185711859 const result = try self.isNonErrPtr(inst, ty, operand);
......@@ -11860,9 +11862,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
1186011862
1186111863fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
1186211864 // 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;
1186411866 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
1186711869 self.scope_generation += 1;
1186811870 const state = try self.saveState();
......@@ -11889,9 +11891,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
1188911891 try self.blocks.putNoClobber(self.gpa, inst, .{ .state = self.initRetroactiveState() });
1189011892 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;
1189311895 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]);
1189511897 try self.genBody(body);
1189611898
1189711899 var block_data = self.blocks.fetchRemove(inst).?;
......@@ -11914,7 +11916,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
1191411916}
1191511917
1191611918fn 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;
1191811920 const condition = try self.resolveInst(pl_op.operand);
1191911921 const condition_ty = self.typeOf(pl_op.operand);
1192011922 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
......@@ -11927,7 +11929,7 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
1192711929 // that death now instead of later as this has an effect on
1192811930 // whether it needs to be spilled in the branches
1192911931 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);
1193111933 }
1193211934
1193311935 self.scope_generation += 1;
......@@ -11937,7 +11939,8 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
1193711939 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
1193811940 const items: []const Air.Inst.Ref =
1193911941 @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]);
1194111944 extra_index = case.end + items.len + case_body.len;
1194211945
1194311946 var relocs = try self.gpa.alloc(Mir.Inst.Index, items.len);
......@@ -11975,7 +11978,8 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void {
1197511978 }
1197611979
1197711980 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
1198011984 const else_deaths = liveness.deaths.len - 1;
1198111985 for (liveness.deaths[else_deaths]) |operand| try self.processDeath(operand);
......@@ -12008,7 +12012,7 @@ fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void {
1200812012
1200912013fn airBr(self: *Self, inst: Air.Inst.Index) !void {
1201012014 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
1201312017 const block_ty = self.typeOfIndex(br.block_inst);
1201412018 const block_unused =
......@@ -12043,7 +12047,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
1204312047
1204412048 // Process operand death so that it is properly accounted for in the State below.
1204512049 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);
1204712051 }
1204812052
1204912053 if (first_br) {
......@@ -12069,7 +12073,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
1206912073
1207012074fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
1207112075 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;
1207312077 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
1207412078 const clobbers_len: u31 = @truncate(extra.data.flags);
1207512079 var extra_i: usize = extra.end;
......@@ -13784,7 +13788,7 @@ fn genLazySymbolRef(
1378413788}
1378513789
1378613790fn 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;
1378813792 const result = result: {
1378913793 // TODO: handle case where the operand is a slice not a raw pointer
1379013794 const src_mcv = try self.resolveInst(un_op);
......@@ -13800,7 +13804,7 @@ fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
1380013804
1380113805fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1380213806 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;
1380413808 const dst_ty = self.typeOfIndex(inst);
1380513809 const src_ty = self.typeOf(ty_op.operand);
1380613810
......@@ -13858,7 +13862,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1385813862
1385913863fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
1386013864 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
1386313867 const slice_ty = self.typeOfIndex(inst);
1386413868 const ptr_ty = self.typeOf(ty_op.operand);
......@@ -13881,7 +13885,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
1388113885
1388213886fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1388313887 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
1388613890 const dst_ty = self.typeOfIndex(inst);
1388713891 const dst_bits = dst_ty.floatBits(self.target.*);
......@@ -13960,7 +13964,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1396013964
1396113965fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1396213966 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
1396513969 const dst_ty = self.typeOfIndex(inst);
1396613970 const dst_bits: u32 = @intCast(dst_ty.bitSize(mod));
......@@ -14031,7 +14035,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1403114035
1403214036fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
1403314037 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;
1403514039 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
1403614040
1403714041 const ptr_ty = self.typeOf(extra.ptr);
......@@ -14388,7 +14392,7 @@ fn atomicOp(
1438814392}
1438914393
1439014394fn 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;
1439214396 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
1439314397
1439414398 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });
......@@ -14409,7 +14413,7 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void {
1440914413}
1441014414
1441114415fn 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
1441414418 const ptr_ty = self.typeOf(atomic_load.ptr);
1441514419 const ptr_mcv = try self.resolveInst(atomic_load.ptr);
......@@ -14430,7 +14434,7 @@ fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void {
1443014434}
1443114435
1443214436fn 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
1443514439 const ptr_ty = self.typeOf(bin_op.lhs);
1443614440 const ptr_mcv = try self.resolveInst(bin_op.lhs);
......@@ -14450,7 +14454,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1445014454 // TODO if the value is undef, don't lower this instruction
1445114455 }
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
1445514459 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
1445614460 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 {
1457114575
1457214576fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1457314577 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
1457614580 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
1457714581 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });
......@@ -14626,7 +14630,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1462614630
1462714631fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
1462814632 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;
1463014634 const inst_ty = self.typeOfIndex(inst);
1463114635 const enum_ty = self.typeOf(un_op);
1463214636 const resolved_cc = abi.resolveCallingConvention(.Unspecified, self.target.*);
......@@ -14668,7 +14672,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
1466814672
1466914673fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
1467014674 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
1467314677 const err_ty = self.typeOf(un_op);
1467414678 const err_mcv = try self.resolveInst(un_op);
......@@ -14770,7 +14774,7 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
1477014774
1477114775fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1477214776 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;
1477414778 const vector_ty = self.typeOfIndex(inst);
1477514779 const vector_len = vector_ty.vectorLen(mod);
1477614780 const dst_rc = self.regClassForType(vector_ty);
......@@ -15106,7 +15110,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1510615110}
1510715111
1510815112fn 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;
1511015114 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
1511115115 _ = extra;
1511215116 return self.fail("TODO implement airSelect for x86_64", .{});
......@@ -15114,7 +15118,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
1511415118}
1511515119
1511615120fn 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;
1511815122 _ = ty_pl;
1511915123 return self.fail("TODO implement airShuffle for x86_64", .{});
1512015124 //return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -15122,7 +15126,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
1512215126
1512315127fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
1512415128 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
1512715131 const result: MCValue = result: {
1512815132 const operand_ty = self.typeOf(reduce.operand);
......@@ -15181,7 +15185,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1518115185 const mod = self.bin_file.options.module.?;
1518215186 const result_ty = self.typeOfIndex(inst);
1518315187 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;
1518515189 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
1518615190 const result: MCValue = result: {
1518715191 switch (result_ty.zigTypeTag(mod)) {
......@@ -15321,7 +15325,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1532115325fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1532215326 const mod = self.bin_file.options.module.?;
1532315327 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;
1532515329 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
1532615330 const result: MCValue = result: {
1532715331 const union_ty = self.typeOfIndex(inst);
......@@ -15365,13 +15369,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1536515369}
1536615370
1536715371fn 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;
1536915373 return self.finishAir(inst, .unreach, .{ prefetch.ptr, .none, .none });
1537015374}
1537115375
1537215376fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1537315377 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;
1537515379 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
1537615380 const ty = self.typeOfIndex(inst);
1537715381
......@@ -15538,7 +15542,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1553815542
1553915543fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1554015544 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;
1554215546 const ptr_anyopaque_ty = try mod.singleMutPtrType(Type.anyopaque);
1554315547
1554415548 const result: MCValue = switch (abi.resolveCallingConvention(
......@@ -15591,7 +15595,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1559115595
1559215596fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
1559315597 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;
1559515599 const ty = self.typeOfIndex(inst);
1559615600 const promote_ty = self.promoteVarArg(ty);
1559715601 const ptr_anyopaque_ty = try mod.singleMutPtrType(Type.anyopaque);
......@@ -15785,7 +15789,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
1578515789}
1578615790
1578715791fn 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;
1578915793 const ptr_va_list_ty = self.typeOf(ty_op.operand);
1579015794
1579115795 const dst_mcv = try self.allocRegOrMem(inst, true);
......@@ -15794,7 +15798,7 @@ fn airVaCopy(self: *Self, inst: Air.Inst.Index) !void {
1579415798}
1579515799
1579615800fn 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;
1579815802 return self.finishAir(inst, .unreach, .{ un_op, .none, .none });
1579915803}
1580015804
......@@ -15805,10 +15809,10 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
1580515809 // If the type has no codegen bits, no need to store it.
1580615810 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
1580715811
15808 const mcv = if (Air.refToIndex(ref)) |inst| mcv: {
15812 const mcv = if (ref.toIndex()) |inst| mcv: {
1580915813 break :mcv self.inst_tracking.getPtr(inst).?.short;
1581015814 } else mcv: {
15811 const ip_index = Air.refToInterned(ref).?;
15815 const ip_index = ref.toInterned().?;
1581215816 const gop = try self.const_tracking.getOrPut(self.gpa, ip_index);
1581315817 if (!gop.found_existing) gop.value_ptr.* = InstTracking.init(init: {
1581415818 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 {
329329 return .{ .new_local = @intCast(f.locals.items.len - 1) };
330330 }
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 {
333333 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 }
335339 return result;
336340 }
337341
......@@ -2951,7 +2955,7 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con
29512955 const pre_locals_len = @as(LocalIndex, @intCast(f.locals.items.len));
29522956
29532957 for (leading_deaths) |death| {
2954 try die(f, inst, Air.indexToRef(death));
2958 try die(f, inst, death.toRef());
29552959 }
29562960
29572961 if (inner) {
......@@ -2969,11 +2973,11 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con
29692973 // them, unless they were used to store allocs.
29702974
29712975 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);
29732977 if (f.allocs.contains(local_index)) {
29742978 continue;
29752979 }
2976 try freeLocal(f, inst, local_index, 0);
2980 try freeLocal(f, inst, local_index, null);
29772981 }
29782982}
29792983
......@@ -2986,7 +2990,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
29862990 if (f.liveness.isUnused(inst) and !f.air.mustLower(inst, ip))
29872991 continue;
29882992
2989 const result_value = switch (air_tags[inst]) {
2993 const result_value = switch (air_tags[@intFromEnum(inst)]) {
29902994 // zig fmt: off
29912995 .inferred_alloc, .inferred_alloc_comptime => unreachable,
29922996
......@@ -3013,7 +3017,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
30133017
30143018 .div_trunc, .div_exact => try airBinOp(f, inst, "/", "div_trunc", .none),
30153019 .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;
30173021 const lhs_scalar_ty = f.typeOf(bin_op.lhs).scalarType(mod);
30183022 // For binary operations @TypeOf(lhs)==@TypeOf(rhs),
30193023 // so we only check one.
......@@ -3061,16 +3065,16 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
30613065
30623066 .slice => try airSlice(f, inst),
30633067
3064 .cmp_gt => try airCmpOp(f, inst, f.air.instructions.items(.data)[inst].bin_op, .gt),
3065 .cmp_gte => try airCmpOp(f, inst, f.air.instructions.items(.data)[inst].bin_op, .gte),
3066 .cmp_lt => try airCmpOp(f, inst, f.air.instructions.items(.data)[inst].bin_op, .lt),
3067 .cmp_lte => try airCmpOp(f, inst, f.air.instructions.items(.data)[inst].bin_op, .lte),
3068 .cmp_gt => try airCmpOp(f, inst, f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op, .gt),
3069 .cmp_gte => try airCmpOp(f, inst, f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op, .gte),
3070 .cmp_lt => try airCmpOp(f, inst, f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op, .lt),
3071 .cmp_lte => try airCmpOp(f, inst, f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op, .lte),
30683072
30693073 .cmp_eq => try airEquality(f, inst, .eq),
30703074 .cmp_neq => try airEquality(f, inst, .neq),
30713075
30723076 .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;
30743078 const extra = f.air.extraData(Air.VectorCmp, ty_pl.payload).data;
30753079 break :blk try airCmpOp(f, inst, extra, extra.compareOperator());
30763080 },
......@@ -3256,7 +3260,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
32563260 if (result_value == .new_local) {
32573261 log.debug("map %{d} to t{d}", .{ inst, result_value.new_local });
32583262 }
3259 try f.value_map.putNoClobber(Air.indexToRef(inst), switch (result_value) {
3263 try f.value_map.putNoClobber(inst.toRef(), switch (result_value) {
32603264 .none => continue,
32613265 .new_local => |i| .{ .local = i },
32623266 else => result_value,
......@@ -3265,7 +3269,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
32653269}
32663270
32673271fn 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
32703274 const inst_ty = f.typeOfIndex(inst);
32713275 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: [
32873291fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
32883292 const mod = f.object.dg.module;
32893293 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;
32913295 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
32923296 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
32933297 return .none;
......@@ -3312,7 +3316,7 @@ fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
33123316
33133317fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
33143318 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;
33163320 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
33173321
33183322 const inst_ty = f.typeOfIndex(inst);
......@@ -3349,7 +3353,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
33493353fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
33503354 const mod = f.object.dg.module;
33513355 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;
33533357 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
33543358 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
33553359 return .none;
......@@ -3374,7 +3378,7 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
33743378
33753379fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
33763380 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;
33783382 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
33793383
33803384 const inst_ty = f.typeOfIndex(inst);
......@@ -3404,7 +3408,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
34043408
34053409fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
34063410 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;
34083412 const inst_ty = f.typeOfIndex(inst);
34093413 if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) {
34103414 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
......@@ -3486,7 +3490,7 @@ fn airArg(f: *Function, inst: Air.Inst.Index) !CValue {
34863490
34873491fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
34883492 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
34913495 const ptr_ty = f.typeOf(ty_op.operand);
34923496 const ptr_scalar_ty = ptr_ty.scalarType(mod);
......@@ -3573,14 +3577,14 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
35733577
35743578fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
35753579 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;
35773581 const writer = f.object.writer();
3578 const op_inst = Air.refToIndex(un_op);
3582 const op_inst = un_op.toIndex();
35793583 const op_ty = f.typeOf(un_op);
35803584 const ret_ty = if (is_ptr) op_ty.childType(mod) else op_ty;
35813585 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) {
35843588 try reap(f, inst, &.{un_op});
35853589 _ = try airCall(f, op_inst.?, .always_tail);
35863590 } else if (lowered_ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -3611,7 +3615,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
36113615 try f.writeCValue(writer, ret_val, .Other);
36123616 try writer.writeAll(";\n");
36133617 if (is_array) {
3614 try freeLocal(f, inst, ret_val.new_local, 0);
3618 try freeLocal(f, inst, ret_val.new_local, null);
36153619 }
36163620 } else {
36173621 try reap(f, inst, &.{un_op});
......@@ -3623,7 +3627,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
36233627
36243628fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue {
36253629 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
36283632 const operand = try f.resolveInst(ty_op.operand);
36293633 try reap(f, inst, &.{ty_op.operand});
......@@ -3649,7 +3653,7 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue {
36493653
36503654fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
36513655 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
36543658 const operand = try f.resolveInst(ty_op.operand);
36553659 try reap(f, inst, &.{ty_op.operand});
......@@ -3732,7 +3736,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
37323736}
37333737
37343738fn 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;
37363740 const operand = try f.resolveInst(un_op);
37373741 try reap(f, inst, &.{un_op});
37383742 const writer = f.object.writer();
......@@ -3749,7 +3753,7 @@ fn airIntFromBool(f: *Function, inst: Air.Inst.Index) !CValue {
37493753fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
37503754 const mod = f.object.dg.module;
37513755 // *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
37543758 const ptr_ty = f.typeOf(bin_op.lhs);
37553759 const ptr_scalar_ty = ptr_ty.scalarType(mod);
......@@ -3815,7 +3819,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
38153819 try f.renderType(writer, src_ty);
38163820 try writer.writeAll("))");
38173821 if (src_val == .constant) {
3818 try freeLocal(f, inst, array_src.new_local, 0);
3822 try freeLocal(f, inst, array_src.new_local, null);
38193823 }
38203824 } else if (ptr_info.packed_offset.host_size > 0 and ptr_info.flags.vector_index == .none) {
38213825 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 {
38873891
38883892fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info: BuiltinInfo) !CValue {
38893893 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;
38913895 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
38923896
38933897 const lhs = try f.resolveInst(bin_op.lhs);
......@@ -3925,7 +3929,7 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info:
39253929
39263930fn airNot(f: *Function, inst: Air.Inst.Index) !CValue {
39273931 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;
39293933 const operand_ty = f.typeOf(ty_op.operand);
39303934 const scalar_ty = operand_ty.scalarType(mod);
39313935 if (scalar_ty.ip_index != .bool_type) return try airUnBuiltinCall(f, inst, "not", .bits);
......@@ -3958,7 +3962,7 @@ fn airBinOp(
39583962 info: BuiltinInfo,
39593963) !CValue {
39603964 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;
39623966 const operand_ty = f.typeOf(bin_op.lhs);
39633967 const scalar_ty = operand_ty.scalarType(mod);
39643968 if ((scalar_ty.isInt(mod) and scalar_ty.bitSize(mod) > 64) or scalar_ty.isRuntimeFloat())
......@@ -4046,7 +4050,7 @@ fn airEquality(
40464050 operator: std.math.CompareOperator,
40474051) !CValue {
40484052 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
40514055 const operand_ty = f.typeOf(bin_op.lhs);
40524056 const operand_bits = operand_ty.bitSize(mod);
......@@ -4109,7 +4113,7 @@ fn airEquality(
41094113}
41104114
41114115fn 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
41144118 const inst_ty = f.typeOfIndex(inst);
41154119 const operand = try f.resolveInst(un_op);
......@@ -4126,7 +4130,7 @@ fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {
41264130
41274131fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
41284132 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;
41304134 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
41314135
41324136 const lhs = try f.resolveInst(bin_op.lhs);
......@@ -4174,7 +4178,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
41744178
41754179fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []const u8) !CValue {
41764180 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
41794183 const inst_ty = f.typeOfIndex(inst);
41804184 const inst_scalar_ty = inst_ty.scalarType(mod);
......@@ -4216,7 +4220,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons
42164220
42174221fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue {
42184222 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;
42204224 const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
42214225
42224226 const ptr = try f.resolveInst(bin_op.lhs);
......@@ -4260,7 +4264,7 @@ fn airCall(
42604264 const gpa = f.object.dg.gpa;
42614265 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;
42644268 const extra = f.air.extraData(Air.Call, pl_op.payload);
42654269 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(
43664370 if (resolved_arg == .none) continue;
43674371 if (args_written != 0) try writer.writeAll(", ");
43684372 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);
43704374 args_written += 1;
43714375 }
43724376 try writer.writeAll(");\n");
......@@ -4383,7 +4387,7 @@ fn airCall(
43834387 try writer.writeAll(", sizeof(");
43844388 try f.renderType(writer, ret_ty);
43854389 try writer.writeAll("));\n");
4386 try freeLocal(f, inst, result_local.new_local, 0);
4390 try freeLocal(f, inst, result_local.new_local, null);
43874391 break :result array_local;
43884392 };
43894393
......@@ -4391,7 +4395,7 @@ fn airCall(
43914395}
43924396
43934397fn 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;
43954399 const writer = f.object.writer();
43964400 // TODO re-evaluate whether to emit these or not. If we naively emit
43974401 // these directives, the output file will report bogus line numbers because
......@@ -4406,7 +4410,7 @@ fn airDbgStmt(f: *Function, inst: Air.Inst.Index) !CValue {
44064410}
44074411
44084412fn 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;
44104414 const mod = f.object.dg.module;
44114415 const writer = f.object.writer();
44124416 const owner_decl = mod.funcOwnerDeclPtr(ty_fn.func);
......@@ -4418,7 +4422,7 @@ fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue {
44184422
44194423fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue {
44204424 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;
44224426 const name = f.air.nullTerminatedString(pl_op.payload);
44234427 const operand_is_undef = if (try f.air.value(pl_op.operand, mod)) |v| v.isUndefDeep(mod) else false;
44244428 if (!operand_is_undef) _ = try f.resolveInst(pl_op.operand);
......@@ -4431,9 +4435,9 @@ fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue {
44314435
44324436fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
44334437 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;
44354439 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]);
44374441 const liveness_block = f.liveness.getBlock(inst);
44384442
44394443 const block_id: usize = f.next_block_index;
......@@ -4457,7 +4461,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
44574461
44584462 // The body might result in some values we had beforehand being killed
44594463 for (liveness_block.deaths) |death| {
4460 try die(f, inst, Air.indexToRef(death));
4464 try die(f, inst, death.toRef());
44614465 }
44624466
44634467 try f.object.indent_writer.insertNewline();
......@@ -4472,18 +4476,18 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
44724476}
44734477
44744478fn 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;
44764480 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]);
44784482 const err_union_ty = f.typeOf(pl_op.operand);
44794483 return lowerTry(f, inst, pl_op.operand, body, err_union_ty, false);
44804484}
44814485
44824486fn airTryPtr(f: *Function, inst: Air.Inst.Index) !CValue {
44834487 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;
44854489 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]);
44874491 const err_union_ty = f.typeOf(extra.data.ptr).childType(mod);
44884492 return lowerTry(f, inst, extra.data.ptr, body, err_union_ty, true);
44894493}
......@@ -4529,7 +4533,7 @@ fn lowerTry(
45294533
45304534 // Now we have the "then branch" (in terms of the liveness data); process any deaths.
45314535 for (liveness_condbr.then_deaths) |death| {
4532 try die(f, inst, Air.indexToRef(death));
4536 try die(f, inst, death.toRef());
45334537 }
45344538
45354539 if (!payload_has_bits) {
......@@ -4559,7 +4563,7 @@ fn lowerTry(
45594563}
45604564
45614565fn 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;
45634567 const block = f.blocks.get(branch.block_inst).?;
45644568 const result = block.result;
45654569 const writer = f.object.writer();
......@@ -4582,7 +4586,7 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue {
45824586}
45834587
45844588fn 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;
45864590 const dest_ty = f.typeOfIndex(inst);
45874591
45884592 const operand = try f.resolveInst(ty_op.operand);
......@@ -4624,7 +4628,7 @@ const LocalResult = struct {
46244628
46254629 fn free(lr: LocalResult, f: *Function) !void {
46264630 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);
46284632 }
46294633 }
46304634};
......@@ -4648,7 +4652,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
46484652 }
46494653
46504654 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);
46524656 try f.writeCValue(writer, local, .Other);
46534657 try writer.writeAll(" = (");
46544658 try f.renderType(writer, dest_ty);
......@@ -4662,7 +4666,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
46624666 }
46634667
46644668 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);
46664670 try f.writeCValue(writer, operand_local, .Other);
46674671 if (operand_ty.isAbiInt(mod)) {
46684672 try writer.writeAll(" = ");
......@@ -4676,7 +4680,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
46764680 break :blk operand_local;
46774681 } else operand;
46784682
4679 const local = try f.allocLocal(0, dest_ty);
4683 const local = try f.allocLocal(null, dest_ty);
46804684 try writer.writeAll("memcpy(&");
46814685 try f.writeCValue(writer, local, .Other);
46824686 try writer.writeAll(", &");
......@@ -4741,7 +4745,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
47414745 }
47424746
47434747 if (operand == .constant) {
4744 try freeLocal(f, 0, operand_lval.new_local, 0);
4748 try freeLocal(f, null, operand_lval.new_local, null);
47454749 }
47464750
47474751 return .{
......@@ -4784,7 +4788,7 @@ fn airFrameAddress(f: *Function, inst: Air.Inst.Index) !CValue {
47844788}
47854789
47864790fn 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;
47884792 const writer = f.object.writer();
47894793
47904794 try writer.writeAll("zig_fence(");
......@@ -4803,9 +4807,9 @@ fn airUnreach(f: *Function) !CValue {
48034807}
48044808
48054809fn 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;
48074811 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]);
48094813 const writer = f.object.writer();
48104814
48114815 try writer.writeAll("for (;;) ");
......@@ -4816,12 +4820,12 @@ fn airLoop(f: *Function, inst: Air.Inst.Index) !CValue {
48164820}
48174821
48184822fn 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;
48204824 const cond = try f.resolveInst(pl_op.operand);
48214825 try reap(f, inst, &.{pl_op.operand});
48224826 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];
4824 const else_body = f.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
4827 const then_body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra.end..][0..extra.data.then_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]);
48254829 const liveness_condbr = f.liveness.getCondBr(inst);
48264830 const writer = f.object.writer();
48274831
......@@ -4837,7 +4841,7 @@ fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue {
48374841 // `free_locals_map` well defined (our parent is responsible for doing that).
48384842
48394843 for (liveness_condbr.else_deaths) |death| {
4840 try die(f, inst, Air.indexToRef(death));
4844 try die(f, inst, death.toRef());
48414845 }
48424846
48434847 // 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 {
48504854
48514855fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
48524856 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;
48544858 const condition = try f.resolveInst(pl_op.operand);
48554859 try reap(f, inst, &.{pl_op.operand});
48564860 const condition_ty = f.typeOf(pl_op.operand);
......@@ -4883,7 +4887,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
48834887 for (0..switch_br.data.cases_len) |case_i| {
48844888 const case = f.air.extraData(Air.SwitchBr.Case, extra_index);
48854889 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]);
48874891 extra_index = case.end + case.data.items_len + case_body.len;
48884892
48894893 for (items) |item| {
......@@ -4903,7 +4907,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
49034907 try genBodyResolveState(f, inst, liveness.deaths[case_i], case_body, false);
49044908 } else {
49054909 for (liveness.deaths[case_i]) |death| {
4906 try die(f, inst, Air.indexToRef(death));
4910 try die(f, inst, death.toRef());
49074911 }
49084912 try genBody(f, case_body);
49094913 }
......@@ -4911,12 +4915,12 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
49114915 // The case body must be noreturn so we don't need to insert a break.
49124916 }
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]);
49154919 try f.object.indent_writer.insertNewline();
49164920 if (else_body.len > 0) {
49174921 // Note that this must be the last case (i.e. the `last_case_i` case was not hit above)
49184922 for (liveness.deaths[liveness.deaths.len - 1]) |death| {
4919 try die(f, inst, Air.indexToRef(death));
4923 try die(f, inst, death.toRef());
49204924 }
49214925 try writer.writeAll("default: ");
49224926 try genBody(f, else_body);
......@@ -4951,7 +4955,7 @@ fn asmInputNeedsLocal(f: *Function, constraint: []const u8, value: CValue) bool
49514955
49524956fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
49534957 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;
49554959 const extra = f.air.extraData(Air.Asm, ty_pl.payload);
49564960 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
49574961 const clobbers_len = @as(u31, @truncate(extra.data.flags));
......@@ -5213,7 +5217,7 @@ fn airIsNull(
52135217 is_ptr: bool,
52145218) !CValue {
52155219 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
52185222 const writer = f.object.writer();
52195223 const operand = try f.resolveInst(un_op);
......@@ -5259,7 +5263,7 @@ fn airIsNull(
52595263
52605264fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue {
52615265 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
52645268 const operand = try f.resolveInst(ty_op.operand);
52655269 try reap(f, inst, &.{ty_op.operand});
......@@ -5293,7 +5297,7 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue {
52935297
52945298fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue {
52955299 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
52985302 const writer = f.object.writer();
52995303 const operand = try f.resolveInst(ty_op.operand);
......@@ -5324,7 +5328,7 @@ fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue {
53245328
53255329fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
53265330 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;
53285332 const writer = f.object.writer();
53295333 const operand = try f.resolveInst(ty_op.operand);
53305334 try reap(f, inst, &.{ty_op.operand});
......@@ -5433,7 +5437,7 @@ fn fieldLocation(
54335437}
54345438
54355439fn 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;
54375441 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;
54385442
54395443 const container_ptr_val = try f.resolveInst(extra.struct_operand);
......@@ -5443,7 +5447,7 @@ fn airStructFieldPtr(f: *Function, inst: Air.Inst.Index) !CValue {
54435447}
54445448
54455449fn 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
54485452 const container_ptr_val = try f.resolveInst(ty_op.operand);
54495453 try reap(f, inst, &.{ty_op.operand});
......@@ -5453,7 +5457,7 @@ fn airStructFieldPtrIndex(f: *Function, inst: Air.Inst.Index, index: u8) !CValue
54535457
54545458fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
54555459 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;
54575461 const extra = f.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
54585462
54595463 const container_ptr_ty = f.typeOfIndex(inst);
......@@ -5558,7 +5562,7 @@ fn fieldPtr(
55585562fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
55595563 const mod = f.object.dg.module;
55605564 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;
55625566 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;
55635567
55645568 const inst_ty = f.typeOfIndex(inst);
......@@ -5634,7 +5638,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
56345638 try writer.writeAll(", sizeof(");
56355639 try f.renderType(writer, inst_ty);
56365640 try writer.writeAll("));\n");
5637 try freeLocal(f, inst, temp_local.new_local, 0);
5641 try freeLocal(f, inst, temp_local.new_local, null);
56385642 return local;
56395643 },
56405644 },
......@@ -5666,7 +5670,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
56665670 try writer.writeAll("));\n");
56675671
56685672 if (struct_byval == .constant) {
5669 try freeLocal(f, inst, operand_lval.new_local, 0);
5673 try freeLocal(f, inst, operand_lval.new_local, null);
56705674 }
56715675
56725676 return local;
......@@ -5695,7 +5699,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
56955699/// Note that the result is never a pointer.
56965700fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
56975701 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
57005704 const inst_ty = f.typeOfIndex(inst);
57015705 const operand = try f.resolveInst(ty_op.operand);
......@@ -5736,7 +5740,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
57365740
57375741fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
57385742 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
57415745 const inst_ty = f.typeOfIndex(inst);
57425746 const operand = try f.resolveInst(ty_op.operand);
......@@ -5772,7 +5776,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
57725776
57735777fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {
57745778 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
57775781 const inst_ty = f.typeOfIndex(inst);
57785782 const repr_is_payload = inst_ty.optionalReprIsPayload(mod);
......@@ -5804,7 +5808,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {
58045808
58055809fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
58065810 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
58095813 const inst_ty = f.typeOfIndex(inst);
58105814 const payload_ty = inst_ty.errorUnionPayload(mod);
......@@ -5844,7 +5848,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
58445848fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
58455849 const mod = f.object.dg.module;
58465850 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;
58485852 const operand = try f.resolveInst(ty_op.operand);
58495853 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 {
58945898
58955899fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
58965900 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
58995903 const inst_ty = f.typeOfIndex(inst);
59005904 const payload_ty = inst_ty.errorUnionPayload(mod);
......@@ -5928,7 +5932,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
59285932
59295933fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const u8) !CValue {
59305934 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
59335937 const writer = f.object.writer();
59345938 const operand = try f.resolveInst(un_op);
......@@ -5963,7 +5967,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const
59635967
59645968fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
59655969 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
59685972 const operand = try f.resolveInst(ty_op.operand);
59695973 try reap(f, inst, &.{ty_op.operand});
......@@ -5994,7 +5998,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
59945998
59955999fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
59966000 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
59996003 const inst_ty = f.typeOfIndex(inst);
60006004 const operand = try f.resolveInst(ty_op.operand);
......@@ -6037,7 +6041,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
60376041
60386042fn airIntFromPtr(f: *Function, inst: Air.Inst.Index) !CValue {
60396043 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
60426046 const operand = try f.resolveInst(un_op);
60436047 const operand_ty = f.typeOf(un_op);
......@@ -6066,7 +6070,7 @@ fn airUnBuiltinCall(
60666070 info: BuiltinInfo,
60676071) !CValue {
60686072 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
60716075 const operand = try f.resolveInst(ty_op.operand);
60726076 try reap(f, inst, &.{ty_op.operand});
......@@ -6110,7 +6114,7 @@ fn airBinBuiltinCall(
61106114 info: BuiltinInfo,
61116115) !CValue {
61126116 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
61156119 const operand_ty = f.typeOf(bin_op.lhs);
61166120 const operand_cty = try f.typeToCType(operand_ty, .complete);
......@@ -6215,7 +6219,7 @@ fn airCmpBuiltinCall(
62156219
62166220fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue {
62176221 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;
62196223 const extra = f.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
62206224 const inst_ty = f.typeOfIndex(inst);
62216225 const ptr = try f.resolveInst(extra.ptr);
......@@ -6311,7 +6315,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
63116315 try new_value_mat.end(f, inst);
63126316
63136317 if (f.liveness.isUnused(inst)) {
6314 try freeLocal(f, inst, local.new_local, 0);
6318 try freeLocal(f, inst, local.new_local, null);
63156319 return .none;
63166320 }
63176321
......@@ -6320,7 +6324,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
63206324
63216325fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
63226326 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;
63246328 const extra = f.air.extraData(Air.AtomicRmw, pl_op.payload).data;
63256329 const inst_ty = f.typeOfIndex(inst);
63266330 const ptr_ty = f.typeOf(pl_op.operand);
......@@ -6366,7 +6370,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
63666370 try operand_mat.end(f, inst);
63676371
63686372 if (f.liveness.isUnused(inst)) {
6369 try freeLocal(f, inst, local.new_local, 0);
6373 try freeLocal(f, inst, local.new_local, null);
63706374 return .none;
63716375 }
63726376
......@@ -6375,7 +6379,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
63756379
63766380fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
63776381 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;
63796383 const ptr = try f.resolveInst(atomic_load.ptr);
63806384 try reap(f, inst, &.{atomic_load.ptr});
63816385 const ptr_ty = f.typeOf(atomic_load.ptr);
......@@ -6411,7 +6415,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
64116415
64126416fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CValue {
64136417 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;
64156419 const ptr_ty = f.typeOf(bin_op.lhs);
64166420 const ty = ptr_ty.childType(mod);
64176421 const ptr = try f.resolveInst(bin_op.lhs);
......@@ -6455,7 +6459,7 @@ fn writeSliceOrPtr(f: *Function, writer: anytype, ptr: CValue, ptr_ty: Type) !vo
64556459
64566460fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
64576461 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;
64596463 const dest_ty = f.typeOf(bin_op.lhs);
64606464 const dest_slice = try f.resolveInst(bin_op.lhs);
64616465 const value = try f.resolveInst(bin_op.rhs);
......@@ -6542,7 +6546,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
65426546 try a.end(f, writer);
65436547
65446548 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
65476551 return .none;
65486552 }
......@@ -6577,7 +6581,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
65776581
65786582fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
65796583 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;
65816585 const dest_ptr = try f.resolveInst(bin_op.lhs);
65826586 const src_ptr = try f.resolveInst(bin_op.rhs);
65836587 const dest_ty = f.typeOf(bin_op.lhs);
......@@ -6616,7 +6620,7 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
66166620
66176621fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
66186622 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;
66206624 const union_ptr = try f.resolveInst(bin_op.lhs);
66216625 const new_tag = try f.resolveInst(bin_op.rhs);
66226626 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
......@@ -6637,7 +6641,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
66376641
66386642fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
66396643 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
66426646 const operand = try f.resolveInst(ty_op.operand);
66436647 try reap(f, inst, &.{ty_op.operand});
......@@ -6659,7 +6663,7 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
66596663
66606664fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue {
66616665 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
66646668 const inst_ty = f.typeOfIndex(inst);
66656669 const enum_ty = f.typeOf(un_op);
......@@ -6679,7 +6683,7 @@ fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue {
66796683}
66806684
66816685fn 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
66846688 const writer = f.object.writer();
66856689 const inst_ty = f.typeOfIndex(inst);
......@@ -6696,7 +6700,7 @@ fn airErrorName(f: *Function, inst: Air.Inst.Index) !CValue {
66966700
66976701fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue {
66986702 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
67016705 const operand = try f.resolveInst(ty_op.operand);
67026706 try reap(f, inst, &.{ty_op.operand});
......@@ -6719,7 +6723,7 @@ fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue {
67196723}
67206724
67216725fn 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;
67236727 const extra = f.air.extraData(Air.Bin, pl_op.payload).data;
67246728
67256729 const pred = try f.resolveInst(pl_op.operand);
......@@ -6751,7 +6755,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue {
67516755
67526756fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
67536757 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;
67556759 const extra = f.air.extraData(Air.Shuffle, ty_pl.payload).data;
67566760
67576761 const mask = Value.fromInterned(extra.mask);
......@@ -6783,7 +6787,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
67836787
67846788fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
67856789 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
67886792 const scalar_ty = f.typeOfIndex(inst);
67896793 const operand = try f.resolveInst(reduce.operand);
......@@ -6939,7 +6943,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
69396943fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
69406944 const mod = f.object.dg.module;
69416945 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;
69436947 const inst_ty = f.typeOfIndex(inst);
69446948 const len = @as(usize, @intCast(inst_ty.arrayLen(mod)));
69456949 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 {
70697073fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
70707074 const mod = f.object.dg.module;
70717075 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;
70737077 const extra = f.air.extraData(Air.UnionInit, ty_pl.payload).data;
70747078
70757079 const union_ty = f.typeOfIndex(inst);
......@@ -7117,7 +7121,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
71177121
71187122fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
71197123 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
71227126 const ptr_ty = f.typeOf(prefetch.ptr);
71237127 const ptr = try f.resolveInst(prefetch.ptr);
......@@ -7142,7 +7146,7 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
71427146}
71437147
71447148fn 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
71477151 const writer = f.object.writer();
71487152 const inst_ty = f.typeOfIndex(inst);
......@@ -7156,7 +7160,7 @@ fn airWasmMemorySize(f: *Function, inst: Air.Inst.Index) !CValue {
71567160}
71577161
71587162fn 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
71617165 const writer = f.object.writer();
71627166 const inst_ty = f.typeOfIndex(inst);
......@@ -7174,7 +7178,7 @@ fn airWasmMemoryGrow(f: *Function, inst: Air.Inst.Index) !CValue {
71747178
71757179fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue {
71767180 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
71797183 const operand = try f.resolveInst(un_op);
71807184 try reap(f, inst, &.{un_op});
......@@ -7200,7 +7204,7 @@ fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue {
72007204
72017205fn airAbs(f: *Function, inst: Air.Inst.Index) !CValue {
72027206 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;
72047208 const operand = try f.resolveInst(ty_op.operand);
72057209 const ty = f.typeOf(ty_op.operand);
72067210 const scalar_ty = ty.scalarType(mod);
......@@ -7239,7 +7243,7 @@ fn unFloatOp(f: *Function, inst: Air.Inst.Index, operand: CValue, ty: Type, oper
72397243}
72407244
72417245fn 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
72447248 const operand = try f.resolveInst(un_op);
72457249 try reap(f, inst, &.{un_op});
......@@ -7250,7 +7254,7 @@ fn airUnFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVal
72507254
72517255fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CValue {
72527256 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
72557259 const lhs = try f.resolveInst(bin_op.lhs);
72567260 const rhs = try f.resolveInst(bin_op.rhs);
......@@ -7282,7 +7286,7 @@ fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVa
72827286
72837287fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue {
72847288 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;
72867290 const bin_op = f.air.extraData(Air.Bin, pl_op.payload).data;
72877291
72887292 const mulend1 = try f.resolveInst(bin_op.lhs);
......@@ -7336,7 +7340,7 @@ fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue {
73367340}
73377341
73387342fn 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
73417345 const inst_ty = f.typeOfIndex(inst);
73427346 const va_list = try f.resolveInst(ty_op.operand);
......@@ -7348,13 +7352,13 @@ fn airCVaArg(f: *Function, inst: Air.Inst.Index) !CValue {
73487352 try writer.writeAll(" = va_arg(*(va_list *)");
73497353 try f.writeCValue(writer, va_list, .Other);
73507354 try writer.writeAll(", ");
7351 try f.renderType(writer, f.air.getRefType(ty_op.ty));
7355 try f.renderType(writer, ty_op.ty.toType());
73527356 try writer.writeAll(");\n");
73537357 return local;
73547358}
73557359
73567360fn 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
73597363 const va_list = try f.resolveInst(un_op);
73607364 try reap(f, inst, &.{un_op});
......@@ -7367,7 +7371,7 @@ fn airCVaEnd(f: *Function, inst: Air.Inst.Index) !CValue {
73677371}
73687372
73697373fn 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
73727376 const inst_ty = f.typeOfIndex(inst);
73737377 const va_list = try f.resolveInst(ty_op.operand);
......@@ -7836,7 +7840,7 @@ const Materialize = struct {
78367840
78377841 pub fn end(self: Materialize, f: *Function, inst: Air.Inst.Index) !void {
78387842 switch (self.local) {
7839 .new_local => |local| try freeLocal(f, inst, local, 0),
7843 .new_local => |local| try freeLocal(f, inst, local, null),
78407844 else => {},
78417845 }
78427846 }
......@@ -7926,7 +7930,7 @@ const Vectorize = struct {
79267930 if (self.index != .none) {
79277931 f.object.indent_writer.popIndent();
79287932 try writer.writeAll("}\n");
7929 try freeLocal(f, inst, self.index.new_local, 0);
7933 try freeLocal(f, inst, self.index.new_local, null);
79307934 }
79317935 }
79327936};
......@@ -7972,7 +7976,7 @@ fn reap(f: *Function, inst: Air.Inst.Index, operands: []const Air.Inst.Ref) !voi
79727976}
79737977
79747978fn 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;
79767980 const c_value = (f.value_map.fetchRemove(ref) orelse return).value;
79777981 const local_index = switch (c_value) {
79787982 .local, .new_local => |l| l,
......@@ -7981,10 +7985,22 @@ fn die(f: *Function, inst: Air.Inst.Index, ref: Air.Inst.Ref) !void {
79817985 try freeLocal(f, inst, local_index, ref_inst);
79827986}
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 {
79857989 const gpa = f.object.dg.gpa;
79867990 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 }
79888004 const gop = try f.free_locals_map.getOrPut(gpa, local.getType());
79898005 if (!gop.found_existing) gop.value_ptr.* = .{};
79908006 if (std.debug.runtime_safety) {
src/codegen/llvm.zig+147-147
......@@ -4850,7 +4850,7 @@ pub const FuncGen = struct {
48504850 for (body, 0..) |inst, i| {
48514851 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)]) {
48544854 // zig fmt: off
48554855 .add => try self.airAdd(inst, .normal),
48564856 .add_optimized => try self.airAdd(inst, .fast),
......@@ -5090,7 +5090,7 @@ pub const FuncGen = struct {
50905090 .work_group_id => try self.airWorkGroupId(inst),
50915091 // zig fmt: on
50925092 };
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);
50945094 }
50955095 }
50965096
......@@ -5103,7 +5103,7 @@ pub const FuncGen = struct {
51035103 };
51045104
51055105 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;
51075107 const extra = self.air.extraData(Air.Call, pl_op.payload);
51085108 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
51095109 const o = self.dg.object;
......@@ -5450,7 +5450,7 @@ pub const FuncGen = struct {
54505450 fn airRet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
54515451 const o = self.dg.object;
54525452 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;
54545454 const ret_ty = self.typeOf(un_op);
54555455 if (self.ret_ptr != .none) {
54565456 const operand = try self.resolveInst(un_op);
......@@ -5508,7 +5508,7 @@ pub const FuncGen = struct {
55085508 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
55095509 const o = self.dg.object;
55105510 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;
55125512 const ptr_ty = self.typeOf(un_op);
55135513 const ret_ty = ptr_ty.childType(mod);
55145514 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
......@@ -5536,9 +5536,9 @@ pub const FuncGen = struct {
55365536
55375537 fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
55385538 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;
55405540 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();
55425542 const llvm_arg_ty = try o.lowerType(arg_ty);
55435543
55445544 return self.wip.vaArg(list, llvm_arg_ty, "");
......@@ -5546,9 +5546,9 @@ pub const FuncGen = struct {
55465546
55475547 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
55485548 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;
55505550 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();
55525552 const llvm_va_list_ty = try o.lowerType(va_list_ty);
55535553 const mod = o.module;
55545554
......@@ -5563,7 +5563,7 @@ pub const FuncGen = struct {
55635563 }
55645564
55655565 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;
55675567 const src_list = try self.resolveInst(un_op);
55685568
55695569 _ = try self.wip.callIntrinsic(.normal, .none, .va_end, &.{}, &.{src_list}, "");
......@@ -5592,7 +5592,7 @@ pub const FuncGen = struct {
55925592 op: math.CompareOperator,
55935593 fast: Builder.FastMathKind,
55945594 ) !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;
55965596 const lhs = try self.resolveInst(bin_op.lhs);
55975597 const rhs = try self.resolveInst(bin_op.rhs);
55985598 const operand_ty = self.typeOf(bin_op.lhs);
......@@ -5601,7 +5601,7 @@ pub const FuncGen = struct {
56015601 }
56025602
56035603 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;
56055605 const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;
56065606
56075607 const lhs = try self.resolveInst(extra.lhs);
......@@ -5614,7 +5614,7 @@ pub const FuncGen = struct {
56145614
56155615 fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
56165616 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;
56185618 const operand = try self.resolveInst(un_op);
56195619 const llvm_fn = try self.getCmpLtErrorsLenFunction();
56205620 return self.wip.call(
......@@ -5733,9 +5733,9 @@ pub const FuncGen = struct {
57335733 fn airBlock(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57345734 const o = self.dg.object;
57355735 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;
57375737 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]);
57395739 const inst_ty = self.typeOfIndex(inst);
57405740
57415741 if (inst_ty.isNoReturn(mod)) {
......@@ -5785,7 +5785,7 @@ pub const FuncGen = struct {
57855785
57865786 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57875787 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;
57895789 const block = self.blocks.get(branch.block_inst).?;
57905790
57915791 // Add the values to the lists only if the break provides a value.
......@@ -5803,11 +5803,11 @@ pub const FuncGen = struct {
58035803 }
58045804
58055805 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;
58075807 const cond = try self.resolveInst(pl_op.operand);
58085808 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];
5810 const else_body = self.air.extra[extra.end + then_body.len ..][0..extra.data.else_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: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
58115811
58125812 const then_block = try self.wip.block(1, "Then");
58135813 const else_block = try self.wip.block(1, "Else");
......@@ -5827,10 +5827,10 @@ pub const FuncGen = struct {
58275827 const o = self.dg.object;
58285828 const mod = o.module;
58295829 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;
58315831 const err_union = try self.resolveInst(pl_op.operand);
58325832 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]);
58345834 const err_union_ty = self.typeOf(pl_op.operand);
58355835 const payload_ty = self.typeOfIndex(inst);
58365836 const can_elide_load = if (isByRef(payload_ty, mod)) self.canElideLoad(body_tail) else false;
......@@ -5841,10 +5841,10 @@ pub const FuncGen = struct {
58415841 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
58425842 const o = self.dg.object;
58435843 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;
58455845 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
58465846 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]);
58485848 const err_union_ty = self.typeOf(extra.data.ptr).childType(mod);
58495849 const is_unused = self.liveness.isUnused(inst);
58505850 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused);
......@@ -5924,7 +5924,7 @@ pub const FuncGen = struct {
59245924
59255925 fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
59265926 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;
59285928 const cond = try self.resolveInst(pl_op.operand);
59295929 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
59305930 const else_block = try self.wip.block(1, "Default");
......@@ -5956,7 +5956,7 @@ pub const FuncGen = struct {
59565956 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
59575957 const items: []const Air.Inst.Ref =
59585958 @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]);
59605960 extra_index = case.end + case.data.items_len + case_body.len;
59615961
59625962 const case_block = try self.wip.block(@intCast(items.len), "Case");
......@@ -5975,7 +5975,7 @@ pub const FuncGen = struct {
59755975 }
59765976
59775977 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]);
59795979 if (else_body.len != 0) {
59805980 try self.genBody(else_body);
59815981 } else {
......@@ -5989,9 +5989,9 @@ pub const FuncGen = struct {
59895989 fn airLoop(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
59905990 const o = self.dg.object;
59915991 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;
59935993 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]);
59955995 const loop_block = try self.wip.block(2, "Loop");
59965996 _ = try self.wip.br(loop_block);
59975997
......@@ -6013,7 +6013,7 @@ pub const FuncGen = struct {
60136013 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
60146014 const o = self.dg.object;
60156015 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;
60176017 const operand_ty = self.typeOf(ty_op.operand);
60186018 const array_ty = operand_ty.childType(mod);
60196019 const llvm_usize = try o.lowerType(Type.usize);
......@@ -6031,7 +6031,7 @@ pub const FuncGen = struct {
60316031 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
60326032 const o = self.dg.object;
60336033 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
60366036 const workaround_operand = try self.resolveInst(ty_op.operand);
60376037 const operand_ty = self.typeOf(ty_op.operand);
......@@ -6116,7 +6116,7 @@ pub const FuncGen = struct {
61166116 const o = self.dg.object;
61176117 const mod = o.module;
61186118 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
61216121 const operand = try self.resolveInst(ty_op.operand);
61226122 const operand_ty = self.typeOf(ty_op.operand);
......@@ -6203,7 +6203,7 @@ pub const FuncGen = struct {
62036203 }
62046204
62056205 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;
62076207 const operand = try self.resolveInst(ty_op.operand);
62086208 return self.wip.extractValue(operand, &.{index}, "");
62096209 }
......@@ -6211,7 +6211,7 @@ pub const FuncGen = struct {
62116211 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {
62126212 const o = self.dg.object;
62136213 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;
62156215 const slice_ptr = try self.resolveInst(ty_op.operand);
62166216 const slice_ptr_ty = self.typeOf(ty_op.operand);
62176217 const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(mod));
......@@ -6223,7 +6223,7 @@ pub const FuncGen = struct {
62236223 const o = self.dg.object;
62246224 const mod = o.module;
62256225 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;
62276227 const slice_ty = self.typeOf(bin_op.lhs);
62286228 const slice = try self.resolveInst(bin_op.lhs);
62296229 const index = try self.resolveInst(bin_op.rhs);
......@@ -6245,7 +6245,7 @@ pub const FuncGen = struct {
62456245 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
62466246 const o = self.dg.object;
62476247 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;
62496249 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
62506250 const slice_ty = self.typeOf(bin_op.lhs);
62516251
......@@ -6261,7 +6261,7 @@ pub const FuncGen = struct {
62616261 const mod = o.module;
62626262 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;
62656265 const array_ty = self.typeOf(bin_op.lhs);
62666266 const array_llvm_val = try self.resolveInst(bin_op.lhs);
62676267 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -6278,12 +6278,12 @@ pub const FuncGen = struct {
62786278 const elem_alignment = elem_ty.abiAlignment(mod).toLlvm();
62796279 return self.loadByRef(elem_ptr, elem_ty, elem_alignment, .normal);
62806280 } else {
6281 if (Air.refToIndex(bin_op.lhs)) |lhs_index| {
6282 if (self.air.instructions.items(.tag)[lhs_index] == .load) {
6283 const load_data = self.air.instructions.items(.data)[lhs_index];
6281 if (bin_op.lhs.toIndex()) |lhs_index| {
6282 if (self.air.instructions.items(.tag)[@intFromEnum(lhs_index)] == .load) {
6283 const load_data = self.air.instructions.items(.data)[@intFromEnum(lhs_index)];
62846284 const load_ptr = load_data.ty_op.operand;
6285 if (Air.refToIndex(load_ptr)) |load_ptr_index| {
6286 const load_ptr_tag = self.air.instructions.items(.tag)[load_ptr_index];
6285 if (load_ptr.toIndex()) |load_ptr_index| {
6286 const load_ptr_tag = self.air.instructions.items(.tag)[@intFromEnum(load_ptr_index)];
62876287 switch (load_ptr_tag) {
62886288 .struct_field_ptr,
62896289 .struct_field_ptr_index_0,
......@@ -6320,7 +6320,7 @@ pub const FuncGen = struct {
63206320 const o = self.dg.object;
63216321 const mod = o.module;
63226322 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;
63246324 const ptr_ty = self.typeOf(bin_op.lhs);
63256325 const elem_ty = ptr_ty.childType(mod);
63266326 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
......@@ -6344,7 +6344,7 @@ pub const FuncGen = struct {
63446344 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
63456345 const o = self.dg.object;
63466346 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;
63486348 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
63496349 const ptr_ty = self.typeOf(bin_op.lhs);
63506350 const elem_ty = ptr_ty.childType(mod);
......@@ -6353,7 +6353,7 @@ pub const FuncGen = struct {
63536353 const base_ptr = try self.resolveInst(bin_op.lhs);
63546354 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();
63576357 if (elem_ptr.ptrInfo(mod).flags.vector_index != .none) return base_ptr;
63586358
63596359 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
......@@ -6365,7 +6365,7 @@ pub const FuncGen = struct {
63656365 }
63666366
63676367 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;
63696369 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
63706370 const struct_ptr = try self.resolveInst(struct_field.struct_operand);
63716371 const struct_ptr_ty = self.typeOf(struct_field.struct_operand);
......@@ -6377,7 +6377,7 @@ pub const FuncGen = struct {
63776377 inst: Air.Inst.Index,
63786378 field_index: u32,
63796379 ) !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;
63816381 const struct_ptr = try self.resolveInst(ty_op.operand);
63826382 const struct_ptr_ty = self.typeOf(ty_op.operand);
63836383 return self.fieldPtr(inst, struct_ptr, struct_ptr_ty, field_index);
......@@ -6387,7 +6387,7 @@ pub const FuncGen = struct {
63876387 const o = self.dg.object;
63886388 const mod = o.module;
63896389 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;
63916391 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
63926392 const struct_ty = self.typeOf(struct_field.struct_operand);
63936393 const struct_llvm_val = try self.resolveInst(struct_field.struct_operand);
......@@ -6491,16 +6491,16 @@ pub const FuncGen = struct {
64916491 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
64926492 const o = self.dg.object;
64936493 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;
64956495 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
64966496
64976497 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);
65006500 const field_offset = parent_ty.structFieldOffset(extra.field_index, mod);
65016501 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());
65046504 const llvm_usize = try o.lowerType(Type.usize);
65056505
65066506 const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, "");
......@@ -6514,7 +6514,7 @@ pub const FuncGen = struct {
65146514 }
65156515
65166516 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;
65186518 const operand = try self.resolveInst(ty_op.operand);
65196519
65206520 return self.wip.not(operand, "");
......@@ -6528,7 +6528,7 @@ pub const FuncGen = struct {
65286528
65296529 fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
65306530 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;
65326532 self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1);
65336533 self.prev_dbg_column = @intCast(dbg_stmt.column + 1);
65346534 const inlined_at = if (self.dbg_inlined.items.len > 0)
......@@ -6547,7 +6547,7 @@ pub const FuncGen = struct {
65476547 fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
65486548 const o = self.dg.object;
65496549 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
65526552 const mod = o.module;
65536553 const func = mod.funcInfo(ty_fn.func);
......@@ -6596,7 +6596,7 @@ pub const FuncGen = struct {
65966596 fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
65976597 const o = self.dg.object;
65986598 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
66016601 const mod = o.module;
66026602 const decl = mod.funcOwnerDeclPtr(ty_fn.func);
......@@ -6629,7 +6629,7 @@ pub const FuncGen = struct {
66296629 const o = self.dg.object;
66306630 const mod = o.module;
66316631 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;
66336633 const operand = try self.resolveInst(pl_op.operand);
66346634 const name = self.air.nullTerminatedString(pl_op.payload);
66356635 const ptr_ty = self.typeOf(pl_op.operand);
......@@ -6656,7 +6656,7 @@ pub const FuncGen = struct {
66566656 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
66576657 const o = self.dg.object;
66586658 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;
66606660 const operand = try self.resolveInst(pl_op.operand);
66616661 const operand_ty = self.typeOf(pl_op.operand);
66626662 const name = self.air.nullTerminatedString(pl_op.payload);
......@@ -6700,7 +6700,7 @@ pub const FuncGen = struct {
67006700 // this implementation feeds the inline assembly code directly to LLVM.
67016701
67026702 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;
67046704 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
67056705 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
67066706 const clobbers_len: u31 = @truncate(extra.data.flags);
......@@ -7081,7 +7081,7 @@ pub const FuncGen = struct {
70817081 ) !Builder.Value {
70827082 const o = self.dg.object;
70837083 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;
70857085 const operand = try self.resolveInst(un_op);
70867086 const operand_ty = self.typeOf(un_op);
70877087 const optional_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
......@@ -7125,7 +7125,7 @@ pub const FuncGen = struct {
71257125 ) !Builder.Value {
71267126 const o = self.dg.object;
71277127 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;
71297129 const operand = try self.resolveInst(un_op);
71307130 const operand_ty = self.typeOf(un_op);
71317131 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
......@@ -7164,7 +7164,7 @@ pub const FuncGen = struct {
71647164 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
71657165 const o = self.dg.object;
71667166 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;
71687168 const operand = try self.resolveInst(ty_op.operand);
71697169 const optional_ty = self.typeOf(ty_op.operand).childType(mod);
71707170 const payload_ty = optional_ty.optionalChild(mod);
......@@ -7185,7 +7185,7 @@ pub const FuncGen = struct {
71857185
71867186 const o = self.dg.object;
71877187 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;
71897189 const operand = try self.resolveInst(ty_op.operand);
71907190 const optional_ty = self.typeOf(ty_op.operand).childType(mod);
71917191 const payload_ty = optional_ty.optionalChild(mod);
......@@ -7217,7 +7217,7 @@ pub const FuncGen = struct {
72177217 const o = self.dg.object;
72187218 const mod = o.module;
72197219 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;
72217221 const operand = try self.resolveInst(ty_op.operand);
72227222 const optional_ty = self.typeOf(ty_op.operand);
72237223 const payload_ty = self.typeOfIndex(inst);
......@@ -7241,7 +7241,7 @@ pub const FuncGen = struct {
72417241 const o = self.dg.object;
72427242 const mod = o.module;
72437243 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;
72457245 const operand = try self.resolveInst(ty_op.operand);
72467246 const operand_ty = self.typeOf(ty_op.operand);
72477247 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
......@@ -7275,7 +7275,7 @@ pub const FuncGen = struct {
72757275 ) !Builder.Value {
72767276 const o = self.dg.object;
72777277 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;
72797279 const operand = try self.resolveInst(ty_op.operand);
72807280 const operand_ty = self.typeOf(ty_op.operand);
72817281 const error_type = try o.errorIntType();
......@@ -7308,7 +7308,7 @@ pub const FuncGen = struct {
73087308 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
73097309 const o = self.dg.object;
73107310 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;
73127312 const operand = try self.resolveInst(ty_op.operand);
73137313 const err_union_ty = self.typeOf(ty_op.operand).childType(mod);
73147314
......@@ -7340,15 +7340,15 @@ pub const FuncGen = struct {
73407340 }
73417341
73427342 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;
73447344 self.err_ret_trace = try self.resolveInst(un_op);
73457345 return .none;
73467346 }
73477347
73487348 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
73497349 const o = self.dg.object;
7350 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
7351 const struct_ty = self.air.getRefType(ty_pl.ty);
7350 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7351 const struct_ty = ty_pl.ty.toType();
73527352 const field_index = ty_pl.payload;
73537353
73547354 const mod = o.module;
......@@ -7378,7 +7378,7 @@ pub const FuncGen = struct {
73787378 ) bool {
73797379 const air_tags = self.air.instructions.items(.tag);
73807380 for (body_tail[1..]) |body_inst| {
7381 switch (air_tags[body_inst]) {
7381 switch (air_tags[@intFromEnum(body_inst)]) {
73827382 .ret => return true,
73837383 .dbg_block_begin, .dbg_stmt => continue,
73847384 else => return false,
......@@ -7393,7 +7393,7 @@ pub const FuncGen = struct {
73937393 const o = self.dg.object;
73947394 const mod = o.module;
73957395 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;
73977397 const payload_ty = self.typeOf(ty_op.operand);
73987398 const non_null_bit = try o.builder.intValue(.i8, 1);
73997399 comptime assert(optional_layout_version == 3);
......@@ -7426,7 +7426,7 @@ pub const FuncGen = struct {
74267426 const o = self.dg.object;
74277427 const mod = o.module;
74287428 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;
74307430 const err_un_ty = self.typeOfIndex(inst);
74317431 const operand = try self.resolveInst(ty_op.operand);
74327432 const payload_ty = self.typeOf(ty_op.operand);
......@@ -7467,7 +7467,7 @@ pub const FuncGen = struct {
74677467 const o = self.dg.object;
74687468 const mod = o.module;
74697469 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;
74717471 const err_un_ty = self.typeOfIndex(inst);
74727472 const payload_ty = err_un_ty.errorUnionPayload(mod);
74737473 const operand = try self.resolveInst(ty_op.operand);
......@@ -7505,7 +7505,7 @@ pub const FuncGen = struct {
75057505
75067506 fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
75077507 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;
75097509 const index = pl_op.payload;
75107510 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{.i32}, &.{
75117511 try o.builder.intValue(.i32, index),
......@@ -7514,7 +7514,7 @@ pub const FuncGen = struct {
75147514
75157515 fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
75167516 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;
75187518 const index = pl_op.payload;
75197519 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{.i32}, &.{
75207520 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
......@@ -7524,7 +7524,7 @@ pub const FuncGen = struct {
75247524 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
75257525 const o = self.dg.object;
75267526 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;
75287528 const extra = self.air.extraData(Air.Bin, data.payload).data;
75297529
75307530 const vector_ptr = try self.resolveInst(data.vector_ptr);
......@@ -7546,7 +7546,7 @@ pub const FuncGen = struct {
75467546 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
75477547 const o = self.dg.object;
75487548 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;
75507550 const lhs = try self.resolveInst(bin_op.lhs);
75517551 const rhs = try self.resolveInst(bin_op.rhs);
75527552 const inst_ty = self.typeOfIndex(inst);
......@@ -7566,7 +7566,7 @@ pub const FuncGen = struct {
75667566 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
75677567 const o = self.dg.object;
75687568 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;
75707570 const lhs = try self.resolveInst(bin_op.lhs);
75717571 const rhs = try self.resolveInst(bin_op.rhs);
75727572 const inst_ty = self.typeOfIndex(inst);
......@@ -7585,7 +7585,7 @@ pub const FuncGen = struct {
75857585
75867586 fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
75877587 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;
75897589 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
75907590 const ptr = try self.resolveInst(bin_op.lhs);
75917591 const len = try self.resolveInst(bin_op.rhs);
......@@ -7596,7 +7596,7 @@ pub const FuncGen = struct {
75967596 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
75977597 const o = self.dg.object;
75987598 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;
76007600 const lhs = try self.resolveInst(bin_op.lhs);
76017601 const rhs = try self.resolveInst(bin_op.rhs);
76027602 const inst_ty = self.typeOfIndex(inst);
......@@ -7615,7 +7615,7 @@ pub const FuncGen = struct {
76157615 const o = fg.dg.object;
76167616 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;
76197619 const lhs = try fg.resolveInst(bin_op.lhs);
76207620 const rhs = try fg.resolveInst(bin_op.rhs);
76217621 const inst_ty = fg.typeOfIndex(inst);
......@@ -7652,7 +7652,7 @@ pub const FuncGen = struct {
76527652 }
76537653
76547654 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;
76567656 const lhs = try self.resolveInst(bin_op.lhs);
76577657 const rhs = try self.resolveInst(bin_op.rhs);
76587658
......@@ -7662,7 +7662,7 @@ pub const FuncGen = struct {
76627662 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
76637663 const o = self.dg.object;
76647664 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;
76667666 const lhs = try self.resolveInst(bin_op.lhs);
76677667 const rhs = try self.resolveInst(bin_op.rhs);
76687668 const inst_ty = self.typeOfIndex(inst);
......@@ -7682,7 +7682,7 @@ pub const FuncGen = struct {
76827682 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
76837683 const o = self.dg.object;
76847684 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;
76867686 const lhs = try self.resolveInst(bin_op.lhs);
76877687 const rhs = try self.resolveInst(bin_op.rhs);
76887688 const inst_ty = self.typeOfIndex(inst);
......@@ -7693,7 +7693,7 @@ pub const FuncGen = struct {
76937693 }
76947694
76957695 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;
76977697 const lhs = try self.resolveInst(bin_op.lhs);
76987698 const rhs = try self.resolveInst(bin_op.rhs);
76997699
......@@ -7703,7 +7703,7 @@ pub const FuncGen = struct {
77037703 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
77047704 const o = self.dg.object;
77057705 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;
77077707 const lhs = try self.resolveInst(bin_op.lhs);
77087708 const rhs = try self.resolveInst(bin_op.rhs);
77097709 const inst_ty = self.typeOfIndex(inst);
......@@ -7723,7 +7723,7 @@ pub const FuncGen = struct {
77237723 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
77247724 const o = self.dg.object;
77257725 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;
77277727 const lhs = try self.resolveInst(bin_op.lhs);
77287728 const rhs = try self.resolveInst(bin_op.rhs);
77297729 const inst_ty = self.typeOfIndex(inst);
......@@ -7734,7 +7734,7 @@ pub const FuncGen = struct {
77347734 }
77357735
77367736 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;
77387738 const lhs = try self.resolveInst(bin_op.lhs);
77397739 const rhs = try self.resolveInst(bin_op.rhs);
77407740
......@@ -7744,7 +7744,7 @@ pub const FuncGen = struct {
77447744 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
77457745 const o = self.dg.object;
77467746 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;
77487748 const lhs = try self.resolveInst(bin_op.lhs);
77497749 const rhs = try self.resolveInst(bin_op.rhs);
77507750 const inst_ty = self.typeOfIndex(inst);
......@@ -7762,7 +7762,7 @@ pub const FuncGen = struct {
77627762 }
77637763
77647764 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;
77667766 const lhs = try self.resolveInst(bin_op.lhs);
77677767 const rhs = try self.resolveInst(bin_op.rhs);
77687768 const inst_ty = self.typeOfIndex(inst);
......@@ -7773,7 +7773,7 @@ pub const FuncGen = struct {
77737773 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
77747774 const o = self.dg.object;
77757775 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;
77777777 const lhs = try self.resolveInst(bin_op.lhs);
77787778 const rhs = try self.resolveInst(bin_op.rhs);
77797779 const inst_ty = self.typeOfIndex(inst);
......@@ -7789,7 +7789,7 @@ pub const FuncGen = struct {
77897789 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
77907790 const o = self.dg.object;
77917791 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;
77937793 const lhs = try self.resolveInst(bin_op.lhs);
77947794 const rhs = try self.resolveInst(bin_op.rhs);
77957795 const inst_ty = self.typeOfIndex(inst);
......@@ -7821,7 +7821,7 @@ pub const FuncGen = struct {
78217821 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
78227822 const o = self.dg.object;
78237823 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;
78257825 const lhs = try self.resolveInst(bin_op.lhs);
78267826 const rhs = try self.resolveInst(bin_op.rhs);
78277827 const inst_ty = self.typeOfIndex(inst);
......@@ -7839,7 +7839,7 @@ pub const FuncGen = struct {
78397839 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
78407840 const o = self.dg.object;
78417841 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;
78437843 const lhs = try self.resolveInst(bin_op.lhs);
78447844 const rhs = try self.resolveInst(bin_op.rhs);
78457845 const inst_ty = self.typeOfIndex(inst);
......@@ -7856,7 +7856,7 @@ pub const FuncGen = struct {
78567856 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
78577857 const o = self.dg.object;
78587858 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;
78607860 const lhs = try self.resolveInst(bin_op.lhs);
78617861 const rhs = try self.resolveInst(bin_op.rhs);
78627862 const inst_ty = self.typeOfIndex(inst);
......@@ -7892,7 +7892,7 @@ pub const FuncGen = struct {
78927892 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
78937893 const o = self.dg.object;
78947894 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;
78967896 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
78977897 const ptr = try self.resolveInst(bin_op.lhs);
78987898 const offset = try self.resolveInst(bin_op.rhs);
......@@ -7914,7 +7914,7 @@ pub const FuncGen = struct {
79147914 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
79157915 const o = self.dg.object;
79167916 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;
79187918 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
79197919 const ptr = try self.resolveInst(bin_op.lhs);
79207920 const offset = try self.resolveInst(bin_op.rhs);
......@@ -7942,7 +7942,7 @@ pub const FuncGen = struct {
79427942 ) !Builder.Value {
79437943 const o = self.dg.object;
79447944 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;
79467946 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
79477947
79487948 const lhs = try self.resolveInst(extra.lhs);
......@@ -8283,7 +8283,7 @@ pub const FuncGen = struct {
82838283 }
82848284
82858285 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;
82878287 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
82888288
82898289 const mulend1 = try self.resolveInst(extra.lhs);
......@@ -8297,7 +8297,7 @@ pub const FuncGen = struct {
82978297 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
82988298 const o = self.dg.object;
82998299 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;
83018301 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
83028302
83038303 const lhs = try self.resolveInst(extra.lhs);
......@@ -8344,21 +8344,21 @@ pub const FuncGen = struct {
83448344 }
83458345
83468346 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;
83488348 const lhs = try self.resolveInst(bin_op.lhs);
83498349 const rhs = try self.resolveInst(bin_op.rhs);
83508350 return self.wip.bin(.@"and", lhs, rhs, "");
83518351 }
83528352
83538353 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;
83558355 const lhs = try self.resolveInst(bin_op.lhs);
83568356 const rhs = try self.resolveInst(bin_op.rhs);
83578357 return self.wip.bin(.@"or", lhs, rhs, "");
83588358 }
83598359
83608360 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;
83628362 const lhs = try self.resolveInst(bin_op.lhs);
83638363 const rhs = try self.resolveInst(bin_op.rhs);
83648364 return self.wip.bin(.xor, lhs, rhs, "");
......@@ -8367,7 +8367,7 @@ pub const FuncGen = struct {
83678367 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
83688368 const o = self.dg.object;
83698369 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
83728372 const lhs = try self.resolveInst(bin_op.lhs);
83738373 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8384,7 +8384,7 @@ pub const FuncGen = struct {
83848384
83858385 fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
83868386 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
83898389 const lhs = try self.resolveInst(bin_op.lhs);
83908390 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8398,7 +8398,7 @@ pub const FuncGen = struct {
83988398 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
83998399 const o = self.dg.object;
84008400 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
84038403 const lhs = try self.resolveInst(bin_op.lhs);
84048404 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8440,7 +8440,7 @@ pub const FuncGen = struct {
84408440 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {
84418441 const o = self.dg.object;
84428442 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
84458445 const lhs = try self.resolveInst(bin_op.lhs);
84468446 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8459,7 +8459,7 @@ pub const FuncGen = struct {
84598459 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
84608460 const o = self.dg.object;
84618461 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;
84638463 const operand = try self.resolveInst(ty_op.operand);
84648464 const operand_ty = self.typeOf(ty_op.operand);
84658465 const scalar_ty = operand_ty.scalarType(mod);
......@@ -8481,7 +8481,7 @@ pub const FuncGen = struct {
84818481 fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
84828482 const o = self.dg.object;
84838483 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;
84858485 const dest_ty = self.typeOfIndex(inst);
84868486 const dest_llvm_ty = try o.lowerType(dest_ty);
84878487 const operand = try self.resolveInst(ty_op.operand);
......@@ -8496,7 +8496,7 @@ pub const FuncGen = struct {
84968496
84978497 fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
84988498 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;
85008500 const operand = try self.resolveInst(ty_op.operand);
85018501 const dest_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
85028502 return self.wip.cast(.trunc, operand, dest_llvm_ty, "");
......@@ -8505,7 +8505,7 @@ pub const FuncGen = struct {
85058505 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85068506 const o = self.dg.object;
85078507 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;
85098509 const operand = try self.resolveInst(ty_op.operand);
85108510 const operand_ty = self.typeOf(ty_op.operand);
85118511 const dest_ty = self.typeOfIndex(inst);
......@@ -8539,7 +8539,7 @@ pub const FuncGen = struct {
85398539 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85408540 const o = self.dg.object;
85418541 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;
85438543 const operand = try self.resolveInst(ty_op.operand);
85448544 const operand_ty = self.typeOf(ty_op.operand);
85458545 const dest_ty = self.typeOfIndex(inst);
......@@ -8572,7 +8572,7 @@ pub const FuncGen = struct {
85728572
85738573 fn airIntFromPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85748574 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;
85768576 const operand = try self.resolveInst(un_op);
85778577 const ptr_ty = self.typeOf(un_op);
85788578 const operand_ptr = try self.sliceOrArrayPtr(operand, ptr_ty);
......@@ -8581,7 +8581,7 @@ pub const FuncGen = struct {
85818581 }
85828582
85838583 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;
85858585 const operand_ty = self.typeOf(ty_op.operand);
85868586 const inst_ty = self.typeOfIndex(inst);
85878587 const operand = try self.resolveInst(ty_op.operand);
......@@ -8698,7 +8698,7 @@ pub const FuncGen = struct {
86988698 }
86998699
87008700 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;
87028702 const operand = try self.resolveInst(un_op);
87038703 return operand;
87048704 }
......@@ -8713,7 +8713,7 @@ pub const FuncGen = struct {
87138713 if (o.di_builder) |dib| {
87148714 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;
87178717 const func_index = self.dg.decl.getOwnedFunctionIndex();
87188718 const func = mod.funcInfo(func_index);
87198719 const lbrace_line = mod.declPtr(func.owner_decl).src_line + func.lbrace_line + 1;
......@@ -8796,7 +8796,7 @@ pub const FuncGen = struct {
87968796 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
87978797 const o = self.dg.object;
87988798 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;
88008800 const dest_ptr = try self.resolveInst(bin_op.lhs);
88018801 const ptr_ty = self.typeOf(bin_op.lhs);
88028802 const operand_ty = ptr_ty.childType(mod);
......@@ -8860,7 +8860,7 @@ pub const FuncGen = struct {
88608860 const o = fg.dg.object;
88618861 const mod = o.module;
88628862 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;
88648864 const ptr_ty = fg.typeOf(ty_op.operand);
88658865 const ptr_info = ptr_ty.ptrInfo(mod);
88668866 const ptr = try fg.resolveInst(ty_op.operand);
......@@ -8910,7 +8910,7 @@ pub const FuncGen = struct {
89108910 }
89118911
89128912 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;
89148914 const ordering = toLlvmAtomicOrdering(atomic_order);
89158915 _ = try self.wip.fence(self.sync_scope, ordering);
89168916 return .none;
......@@ -8923,7 +8923,7 @@ pub const FuncGen = struct {
89238923 ) !Builder.Value {
89248924 const o = self.dg.object;
89258925 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;
89278927 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
89288928 const ptr = try self.resolveInst(extra.ptr);
89298929 const ptr_ty = self.typeOf(extra.ptr);
......@@ -8973,7 +8973,7 @@ pub const FuncGen = struct {
89738973 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
89748974 const o = self.dg.object;
89758975 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;
89778977 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
89788978 const ptr = try self.resolveInst(pl_op.operand);
89798979 const ptr_ty = self.typeOf(pl_op.operand);
......@@ -9036,7 +9036,7 @@ pub const FuncGen = struct {
90369036 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
90379037 const o = self.dg.object;
90389038 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;
90409040 const ptr = try self.resolveInst(atomic_load.ptr);
90419041 const ptr_ty = self.typeOf(atomic_load.ptr);
90429042 const info = ptr_ty.ptrInfo(mod);
......@@ -9083,7 +9083,7 @@ pub const FuncGen = struct {
90839083 ) !Builder.Value {
90849084 const o = self.dg.object;
90859085 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;
90879087 const ptr_ty = self.typeOf(bin_op.lhs);
90889088 const operand_ty = ptr_ty.childType(mod);
90899089 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return .none;
......@@ -9107,7 +9107,7 @@ pub const FuncGen = struct {
91079107 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
91089108 const o = self.dg.object;
91099109 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;
91119111 const dest_slice = try self.resolveInst(bin_op.lhs);
91129112 const ptr_ty = self.typeOf(bin_op.lhs);
91139113 const elem_ty = self.typeOf(bin_op.rhs);
......@@ -9259,7 +9259,7 @@ pub const FuncGen = struct {
92599259 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
92609260 const o = self.dg.object;
92619261 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;
92639263 const dest_slice = try self.resolveInst(bin_op.lhs);
92649264 const dest_ptr_ty = self.typeOf(bin_op.lhs);
92659265 const src_slice = try self.resolveInst(bin_op.rhs);
......@@ -9312,7 +9312,7 @@ pub const FuncGen = struct {
93129312 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
93139313 const o = self.dg.object;
93149314 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;
93169316 const un_ty = self.typeOf(bin_op.lhs).childType(mod);
93179317 const layout = un_ty.unionGetLayout(mod);
93189318 if (layout.tag_size == 0) return .none;
......@@ -9333,7 +9333,7 @@ pub const FuncGen = struct {
93339333 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
93349334 const o = self.dg.object;
93359335 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;
93379337 const un_ty = self.typeOf(ty_op.operand);
93389338 const layout = un_ty.unionGetLayout(mod);
93399339 if (layout.tag_size == 0) return .none;
......@@ -9354,7 +9354,7 @@ pub const FuncGen = struct {
93549354 }
93559355
93569356 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;
93589358 const operand = try self.resolveInst(un_op);
93599359 const operand_ty = self.typeOf(un_op);
93609360
......@@ -9362,7 +9362,7 @@ pub const FuncGen = struct {
93629362 }
93639363
93649364 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;
93669366 const operand = try self.resolveInst(un_op);
93679367 const operand_ty = self.typeOf(un_op);
93689368
......@@ -9371,7 +9371,7 @@ pub const FuncGen = struct {
93719371
93729372 fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
93739373 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;
93759375 const inst_ty = self.typeOfIndex(inst);
93769376 const operand_ty = self.typeOf(ty_op.operand);
93779377 const operand = try self.resolveInst(ty_op.operand);
......@@ -9389,7 +9389,7 @@ pub const FuncGen = struct {
93899389
93909390 fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
93919391 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;
93939393 const inst_ty = self.typeOfIndex(inst);
93949394 const operand_ty = self.typeOf(ty_op.operand);
93959395 const operand = try self.resolveInst(ty_op.operand);
......@@ -9408,7 +9408,7 @@ pub const FuncGen = struct {
94089408 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
94099409 const o = self.dg.object;
94109410 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;
94129412 const operand_ty = self.typeOf(ty_op.operand);
94139413 var bits = operand_ty.intInfo(mod).bits;
94149414 assert(bits % 8 == 0);
......@@ -9442,9 +9442,9 @@ pub const FuncGen = struct {
94429442 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
94439443 const o = self.dg.object;
94449444 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;
94469446 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
94499449 const names = error_set_ty.errorSetNames(mod);
94509450 const valid_block = try self.wip.block(@intCast(names.len), "Valid");
......@@ -9472,7 +9472,7 @@ pub const FuncGen = struct {
94729472
94739473 fn airIsNamedEnumValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
94749474 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;
94769476 const operand = try self.resolveInst(un_op);
94779477 const enum_ty = self.typeOf(un_op);
94789478
......@@ -9542,7 +9542,7 @@ pub const FuncGen = struct {
95429542
95439543 fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
95449544 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;
95469546 const operand = try self.resolveInst(un_op);
95479547 const enum_ty = self.typeOf(un_op);
95489548
......@@ -9654,7 +9654,7 @@ pub const FuncGen = struct {
96549654
96559655 fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
96569656 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;
96589658 const operand = try self.resolveInst(un_op);
96599659 const slice_ty = self.typeOfIndex(inst);
96609660 const slice_llvm_ty = try o.lowerType(slice_ty);
......@@ -9669,14 +9669,14 @@ pub const FuncGen = struct {
96699669
96709670 fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
96719671 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;
96739673 const scalar = try self.resolveInst(ty_op.operand);
96749674 const vector_ty = self.typeOfIndex(inst);
96759675 return self.wip.splatVector(try o.lowerType(vector_ty), scalar, "");
96769676 }
96779677
96789678 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;
96809680 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
96819681 const pred = try self.resolveInst(pl_op.operand);
96829682 const a = try self.resolveInst(extra.lhs);
......@@ -9688,7 +9688,7 @@ pub const FuncGen = struct {
96889688 fn airShuffle(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
96899689 const o = self.dg.object;
96909690 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;
96929692 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
96939693 const a = try self.resolveInst(extra.a);
96949694 const b = try self.resolveInst(extra.b);
......@@ -9799,7 +9799,7 @@ pub const FuncGen = struct {
97999799 const mod = o.module;
98009800 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;
98039803 const operand = try self.resolveInst(reduce.operand);
98049804 const operand_ty = self.typeOf(reduce.operand);
98059805 const llvm_operand_ty = try o.lowerType(operand_ty);
......@@ -9908,7 +9908,7 @@ pub const FuncGen = struct {
99089908 const o = self.dg.object;
99099909 const mod = o.module;
99109910 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;
99129912 const result_ty = self.typeOfIndex(inst);
99139913 const len: usize = @intCast(result_ty.arrayLen(mod));
99149914 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
......@@ -10031,7 +10031,7 @@ pub const FuncGen = struct {
1003110031 const o = self.dg.object;
1003210032 const mod = o.module;
1003310033 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;
1003510035 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
1003610036 const union_ty = self.typeOfIndex(inst);
1003710037 const union_llvm_ty = try o.lowerType(union_ty);
......@@ -10151,7 +10151,7 @@ pub const FuncGen = struct {
1015110151
1015210152 fn airPrefetch(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1015310153 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
1015610156 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.read) == 0);
1015710157 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.write) == 1);
......@@ -10201,7 +10201,7 @@ pub const FuncGen = struct {
1020110201
1020210202 fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1020310203 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;
1020510205 const inst_ty = self.typeOfIndex(inst);
1020610206 const operand = try self.resolveInst(ty_op.operand);
1020710207
......@@ -10227,7 +10227,7 @@ pub const FuncGen = struct {
1022710227 const target = o.module.getTarget();
1022810228 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;
1023110231 const dimension = pl_op.payload;
1023210232 return self.amdgcnWorkIntrinsic(dimension, 0, "amdgcn.workitem.id");
1023310233 }
......@@ -10237,7 +10237,7 @@ pub const FuncGen = struct {
1023710237 const target = o.module.getTarget();
1023810238 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;
1024110241 const dimension = pl_op.payload;
1024210242 if (dimension >= 3) return o.builder.intValue(.i32, 1);
1024310243
......@@ -10260,7 +10260,7 @@ pub const FuncGen = struct {
1026010260 const target = o.module.getTarget();
1026110261 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;
1026410264 const dimension = pl_op.payload;
1026510265 return self.amdgcnWorkIntrinsic(dimension, 0, "amdgcn.workgroup.id");
1026610266 }
src/codegen/spirv.zig+71-70
......@@ -445,7 +445,7 @@ const DeclGen = struct {
445445
446446 return try self.constant(ty, val, .direct);
447447 }
448 const index = Air.refToIndex(inst).?;
448 const index = inst.toIndex().?;
449449 return self.inst_results.get(index).?; // Assertion means instruction does not dominate usage.
450450 }
451451
......@@ -2089,7 +2089,7 @@ const DeclGen = struct {
20892089 return;
20902090
20912091 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)]) {
20932093 // zig fmt: off
20942094 .add, .add_wrap => try self.airArithOp(inst, .OpFAdd, .OpIAdd, .OpIAdd, true),
20952095 .sub, .sub_wrap => try self.airArithOp(inst, .OpFSub, .OpISub, .OpISub, true),
......@@ -2255,7 +2255,7 @@ const DeclGen = struct {
22552255 fn airBinOpSimple(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {
22562256 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;
22592259 const lhs_id = try self.resolve(bin_op.lhs);
22602260 const rhs_id = try self.resolve(bin_op.rhs);
22612261 const ty = self.typeOf(bin_op.lhs);
......@@ -2265,7 +2265,7 @@ const DeclGen = struct {
22652265
22662266 fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {
22672267 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;
22692269 const lhs_id = try self.resolve(bin_op.lhs);
22702270 const rhs_id = try self.resolve(bin_op.rhs);
22712271 const result_type_id = try self.resolveTypeId(self.typeOfIndex(inst));
......@@ -2291,7 +2291,7 @@ const DeclGen = struct {
22912291 fn airMinMax(self: *DeclGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !?IdRef {
22922292 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;
22952295 const lhs_id = try self.resolve(bin_op.lhs);
22962296 const rhs_id = try self.resolve(bin_op.rhs);
22972297 const result_ty = self.typeOfIndex(inst);
......@@ -2395,7 +2395,7 @@ const DeclGen = struct {
23952395 // LHS and RHS are guaranteed to have the same type, and AIR guarantees
23962396 // the result to be the same as the LHS and RHS, which matches SPIR-V.
23972397 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;
23992399 const lhs_id = try self.resolve(bin_op.lhs);
24002400 const rhs_id = try self.resolve(bin_op.rhs);
24012401
......@@ -2492,7 +2492,7 @@ const DeclGen = struct {
24922492 ) !?IdRef {
24932493 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;
24962496 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
24972497 const lhs = try self.resolve(extra.lhs);
24982498 const rhs = try self.resolve(extra.rhs);
......@@ -2601,7 +2601,7 @@ const DeclGen = struct {
26012601 const mod = self.module;
26022602 if (self.liveness.isUnused(inst)) return null;
26032603 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;
26052605 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
26062606 const a = try self.resolve(extra.a);
26072607 const b = try self.resolve(extra.b);
......@@ -2719,7 +2719,7 @@ const DeclGen = struct {
27192719
27202720 fn airPtrAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
27212721 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;
27232723 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
27242724 const ptr_id = try self.resolve(bin_op.lhs);
27252725 const offset_id = try self.resolve(bin_op.rhs);
......@@ -2731,7 +2731,7 @@ const DeclGen = struct {
27312731
27322732 fn airPtrSub(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
27332733 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;
27352735 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
27362736 const ptr_id = try self.resolve(bin_op.lhs);
27372737 const ptr_ty = self.typeOf(bin_op.lhs);
......@@ -2919,7 +2919,7 @@ const DeclGen = struct {
29192919 comptime op: std.math.CompareOperator,
29202920 ) !?IdRef {
29212921 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;
29232923 const lhs_id = try self.resolve(bin_op.lhs);
29242924 const rhs_id = try self.resolve(bin_op.rhs);
29252925 const ty = self.typeOf(bin_op.lhs);
......@@ -2931,7 +2931,7 @@ const DeclGen = struct {
29312931 fn airVectorCmp(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
29322932 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;
29352935 const vec_cmp = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;
29362936 const lhs_id = try self.resolve(vec_cmp.lhs);
29372937 const rhs_id = try self.resolve(vec_cmp.rhs);
......@@ -2999,7 +2999,7 @@ const DeclGen = struct {
29992999
30003000 fn airBitCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
30013001 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;
30033003 const operand_id = try self.resolve(ty_op.operand);
30043004 const operand_ty = self.typeOf(ty_op.operand);
30053005 const result_ty = self.typeOfIndex(inst);
......@@ -3009,7 +3009,7 @@ const DeclGen = struct {
30093009 fn airIntCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
30103010 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;
30133013 const operand_id = try self.resolve(ty_op.operand);
30143014 const src_ty = self.typeOf(ty_op.operand);
30153015 const dst_ty = self.typeOfIndex(inst);
......@@ -3057,7 +3057,7 @@ const DeclGen = struct {
30573057 fn airIntFromPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
30583058 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;
30613061 const operand_id = try self.resolve(un_op);
30623062 return try self.intFromPtr(operand_id);
30633063 }
......@@ -3065,7 +3065,7 @@ const DeclGen = struct {
30653065 fn airFloatFromInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
30663066 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;
30693069 const operand_ty = self.typeOf(ty_op.operand);
30703070 const operand_id = try self.resolve(ty_op.operand);
30713071 const operand_info = try self.arithmeticTypeInfo(operand_ty);
......@@ -3091,7 +3091,7 @@ const DeclGen = struct {
30913091 fn airIntFromFloat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
30923092 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;
30953095 const operand_id = try self.resolve(ty_op.operand);
30963096 const dest_ty = self.typeOfIndex(inst);
30973097 const dest_info = try self.arithmeticTypeInfo(dest_ty);
......@@ -3116,7 +3116,7 @@ const DeclGen = struct {
31163116 fn airFloatCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
31173117 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;
31203120 const operand_id = try self.resolve(ty_op.operand);
31213121 const dest_ty = self.typeOfIndex(inst);
31223122 const dest_ty_id = try self.resolveTypeId(dest_ty);
......@@ -3132,7 +3132,7 @@ const DeclGen = struct {
31323132
31333133 fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
31343134 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;
31363136 const operand_id = try self.resolve(ty_op.operand);
31373137 const result_ty = self.typeOfIndex(inst);
31383138 const result_ty_id = try self.resolveTypeId(result_ty);
......@@ -3166,7 +3166,7 @@ const DeclGen = struct {
31663166 if (self.liveness.isUnused(inst)) return null;
31673167
31683168 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;
31703170 const array_ptr_ty = self.typeOf(ty_op.operand);
31713171 const array_ty = array_ptr_ty.childType(mod);
31723172 const slice_ty = self.typeOfIndex(inst);
......@@ -3195,7 +3195,7 @@ const DeclGen = struct {
31953195 fn airSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
31963196 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;
31993199 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
32003200 const ptr_id = try self.resolve(bin_op.lhs);
32013201 const len_id = try self.resolve(bin_op.rhs);
......@@ -3216,7 +3216,7 @@ const DeclGen = struct {
32163216
32173217 const mod = self.module;
32183218 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;
32203220 const result_ty = self.typeOfIndex(inst);
32213221 const len: usize = @intCast(result_ty.arrayLen(mod));
32223222 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
......@@ -3316,7 +3316,7 @@ const DeclGen = struct {
33163316 }
33173317
33183318 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;
33203320 const dest_slice = try self.resolve(bin_op.lhs);
33213321 const src_slice = try self.resolve(bin_op.rhs);
33223322 const dest_ty = self.typeOf(bin_op.lhs);
......@@ -3333,7 +3333,7 @@ const DeclGen = struct {
33333333
33343334 fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef {
33353335 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;
33373337 const field_ty = self.typeOfIndex(inst);
33383338 const operand_id = try self.resolve(ty_op.operand);
33393339 return try self.extractField(field_ty, operand_id, field);
......@@ -3341,7 +3341,7 @@ const DeclGen = struct {
33413341
33423342 fn airSliceElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
33433343 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;
33453345 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
33463346 const slice_ty = self.typeOf(bin_op.lhs);
33473347 if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null;
......@@ -3358,7 +3358,7 @@ const DeclGen = struct {
33583358
33593359 fn airSliceElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
33603360 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;
33623362 const slice_ty = self.typeOf(bin_op.lhs);
33633363 if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null;
33643364
......@@ -3392,7 +3392,7 @@ const DeclGen = struct {
33923392 if (self.liveness.isUnused(inst)) return null;
33933393
33943394 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;
33963396 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
33973397 const src_ptr_ty = self.typeOf(bin_op.lhs);
33983398 const elem_ty = src_ptr_ty.childType(mod);
......@@ -3411,7 +3411,7 @@ const DeclGen = struct {
34113411 if (self.liveness.isUnused(inst)) return null;
34123412
34133413 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;
34153415 const array_ty = self.typeOf(bin_op.lhs);
34163416 const elem_ty = array_ty.childType(mod);
34173417 const array_id = try self.resolve(bin_op.lhs);
......@@ -3433,7 +3433,7 @@ const DeclGen = struct {
34333433 if (self.liveness.isUnused(inst)) return null;
34343434
34353435 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;
34373437 const ptr_ty = self.typeOf(bin_op.lhs);
34383438 const elem_ty = self.typeOfIndex(inst);
34393439 const ptr_id = try self.resolve(bin_op.lhs);
......@@ -3444,7 +3444,7 @@ const DeclGen = struct {
34443444
34453445 fn airSetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !void {
34463446 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;
34483448 const un_ptr_ty = self.typeOf(bin_op.lhs);
34493449 const un_ty = un_ptr_ty.childType(mod);
34503450 const layout = self.unionLayout(un_ty);
......@@ -3468,7 +3468,7 @@ const DeclGen = struct {
34683468 fn airGetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
34693469 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;
34723472 const un_ty = self.typeOf(ty_op.operand);
34733473
34743474 const mod = self.module;
......@@ -3555,7 +3555,7 @@ const DeclGen = struct {
35553555
35563556 const mod = self.module;
35573557 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;
35593559 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
35603560 const ty = self.typeOfIndex(inst);
35613561
......@@ -3572,7 +3572,7 @@ const DeclGen = struct {
35723572 if (self.liveness.isUnused(inst)) return null;
35733573
35743574 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;
35763576 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
35773577
35783578 const object_ty = self.typeOf(struct_field.struct_operand);
......@@ -3616,11 +3616,11 @@ const DeclGen = struct {
36163616
36173617 fn airFieldParentPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
36183618 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;
36203620 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
36213621
3622 const parent_ty = self.air.getRefType(ty_pl.ty).childType(mod);
3623 const res_ty = try self.resolveType(self.air.getRefType(ty_pl.ty), .indirect);
3622 const parent_ty = ty_pl.ty.toType().childType(mod);
3623 const res_ty = try self.resolveType(ty_pl.ty.toType(), .indirect);
36243624 const usize_ty = Type.usize;
36253625 const usize_ty_ref = try self.resolveType(usize_ty, .direct);
36263626
......@@ -3692,7 +3692,7 @@ const DeclGen = struct {
36923692
36933693 fn airStructFieldPtrIndex(self: *DeclGen, inst: Air.Inst.Index, field_index: u32) !?IdRef {
36943694 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;
36963696 const struct_ptr = try self.resolve(ty_op.operand);
36973697 const struct_ptr_ty = self.typeOf(ty_op.operand);
36983698 const result_ptr_ty = self.typeOfIndex(inst);
......@@ -3918,8 +3918,9 @@ const DeclGen = struct {
39183918 const mod = self.module;
39193919 const ty = self.typeOfIndex(inst);
39203920 const inst_datas = self.air.instructions.items(.data);
3921 const extra = self.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);
3922 const body = self.air.extra[extra.end..][0..extra.data.body_len];
3921 const extra = self.air.extraData(Air.Block, inst_datas[@intFromEnum(inst)].ty_pl.payload);
3922 const body: []const Air.Inst.Index =
3923 @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
39233924 const have_block_result = ty.isFnOrHasRuntimeBitsIgnoreComptime(mod);
39243925
39253926 const cf = switch (self.control_flow) {
......@@ -3983,7 +3984,7 @@ const DeclGen = struct {
39833984
39843985 // Check if the target of the branch was this current block.
39853986 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));
39873988 const jump_to_this_block_id = self.spv.allocId();
39883989 const bool_ty_ref = try self.resolveType(Type.bool, .direct);
39893990 try self.func.body.emit(self.spv.gpa, .OpIEqual, .{
......@@ -4052,7 +4053,7 @@ const DeclGen = struct {
40524053
40534054 fn airBr(self: *DeclGen, inst: Air.Inst.Index) !void {
40544055 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;
40564057 const operand_ty = self.typeOf(br.operand);
40574058
40584059 switch (self.control_flow) {
......@@ -4064,7 +4065,7 @@ const DeclGen = struct {
40644065 }
40654066
40664067 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));
40684069 try self.structuredBreak(next_block);
40694070 },
40704071 .unstructured => |cf| {
......@@ -4089,10 +4090,10 @@ const DeclGen = struct {
40894090 }
40904091
40914092 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;
40934094 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 else_body = self.air.extra[cond_br.end + then_body.len ..][0..cond_br.data.else_body_len];
4095 const then_body: []const Air.Inst.Index = @ptrCast(self.air.extra[cond_br.end..][0..cond_br.data.then_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]);
40964097 const condition_id = try self.resolve(pl_op.operand);
40974098
40984099 const then_label = self.spv.allocId();
......@@ -4149,9 +4150,9 @@ const DeclGen = struct {
41494150 }
41504151
41514152 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;
41534154 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
41564157 const body_label = self.spv.allocId();
41574158
......@@ -4197,7 +4198,7 @@ const DeclGen = struct {
41974198
41984199 fn airLoad(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
41994200 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;
42014202 const ptr_ty = self.typeOf(ty_op.operand);
42024203 const elem_ty = self.typeOfIndex(inst);
42034204 const operand = try self.resolve(ty_op.operand);
......@@ -4207,7 +4208,7 @@ const DeclGen = struct {
42074208 }
42084209
42094210 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;
42114212 const ptr_ty = self.typeOf(bin_op.lhs);
42124213 const elem_ty = ptr_ty.childType(self.module);
42134214 const ptr = try self.resolve(bin_op.lhs);
......@@ -4217,7 +4218,7 @@ const DeclGen = struct {
42174218 }
42184219
42194220 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;
42214222 const ret_ty = self.typeOf(operand);
42224223 const mod = self.module;
42234224 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -4241,7 +4242,7 @@ const DeclGen = struct {
42414242
42424243 fn airRetLoad(self: *DeclGen, inst: Air.Inst.Index) !void {
42434244 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;
42454246 const ptr_ty = self.typeOf(un_op);
42464247 const ret_ty = ptr_ty.childType(mod);
42474248
......@@ -4269,10 +4270,10 @@ const DeclGen = struct {
42694270
42704271 fn airTry(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
42714272 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;
42734274 const err_union_id = try self.resolve(pl_op.operand);
42744275 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
42774278 const err_union_ty = self.typeOf(pl_op.operand);
42784279 const payload_ty = self.typeOfIndex(inst);
......@@ -4344,7 +4345,7 @@ const DeclGen = struct {
43444345 if (self.liveness.isUnused(inst)) return null;
43454346
43464347 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;
43484349 const operand_id = try self.resolve(ty_op.operand);
43494350 const err_union_ty = self.typeOf(ty_op.operand);
43504351 const err_ty_ref = try self.resolveType(Type.anyerror, .direct);
......@@ -4368,7 +4369,7 @@ const DeclGen = struct {
43684369 fn airErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
43694370 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;
43724373 const operand_id = try self.resolve(ty_op.operand);
43734374 const payload_ty = self.typeOfIndex(inst);
43744375 const eu_layout = self.errorUnionLayout(payload_ty);
......@@ -4384,7 +4385,7 @@ const DeclGen = struct {
43844385 if (self.liveness.isUnused(inst)) return null;
43854386
43864387 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;
43884389 const err_union_ty = self.typeOfIndex(inst);
43894390 const payload_ty = err_union_ty.errorUnionPayload(mod);
43904391 const operand_id = try self.resolve(ty_op.operand);
......@@ -4410,7 +4411,7 @@ const DeclGen = struct {
44104411 fn airWrapErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
44114412 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;
44144415 const err_union_ty = self.typeOfIndex(inst);
44154416 const operand_id = try self.resolve(ty_op.operand);
44164417 const payload_ty = self.typeOf(ty_op.operand);
......@@ -4436,7 +4437,7 @@ const DeclGen = struct {
44364437 if (self.liveness.isUnused(inst)) return null;
44374438
44384439 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;
44404441 const operand_id = try self.resolve(un_op);
44414442 const optional_ty = self.typeOf(un_op);
44424443
......@@ -4493,7 +4494,7 @@ const DeclGen = struct {
44934494 if (self.liveness.isUnused(inst)) return null;
44944495
44954496 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;
44974498 const operand_id = try self.resolve(un_op);
44984499 const err_union_ty = self.typeOf(un_op);
44994500
......@@ -4529,7 +4530,7 @@ const DeclGen = struct {
45294530 if (self.liveness.isUnused(inst)) return null;
45304531
45314532 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;
45334534 const operand_id = try self.resolve(ty_op.operand);
45344535 const optional_ty = self.typeOf(ty_op.operand);
45354536 const payload_ty = self.typeOfIndex(inst);
......@@ -4547,7 +4548,7 @@ const DeclGen = struct {
45474548 if (self.liveness.isUnused(inst)) return null;
45484549
45494550 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;
45514552 const payload_ty = self.typeOf(ty_op.operand);
45524553
45534554 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -4569,7 +4570,7 @@ const DeclGen = struct {
45694570
45704571 fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void {
45714572 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;
45734574 const cond_ty = self.typeOf(pl_op.operand);
45744575 const cond = try self.resolve(pl_op.operand);
45754576 const cond_indirect = try self.convertToIndirect(cond_ty, cond);
......@@ -4679,8 +4680,8 @@ const DeclGen = struct {
46794680 var extra_index: usize = switch_br.end;
46804681 for (0..num_cases) |case_i| {
46814682 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 case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
4683 const items: []const Air.Inst.Ref = @ptrCast(self.air.extra[case.end..][0..case.data.items_len]);
4684 const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]);
46844685 extra_index = case.end + case.data.items_len + case_body.len;
46854686
46864687 const label = IdResult{ .id = @intCast(first_case_label.id + case_i) };
......@@ -4702,7 +4703,7 @@ const DeclGen = struct {
47024703 }
47034704 }
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]);
47064707 try self.beginSpvBlock(default);
47074708 if (else_body.len != 0) {
47084709 switch (self.control_flow) {
......@@ -4734,7 +4735,7 @@ const DeclGen = struct {
47344735 }
47354736
47364737 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;
47384739 const mod = self.module;
47394740 const decl = mod.declPtr(self.decl_index);
47404741 const path = decl.getFileScope(mod).sub_file_path;
......@@ -4749,7 +4750,7 @@ const DeclGen = struct {
47494750
47504751 fn airDbgInlineBegin(self: *DeclGen, inst: Air.Inst.Index) !void {
47514752 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;
47534754 const decl_index = mod.funcInfo(fn_ty.func).owner_decl;
47544755 const decl = mod.declPtr(decl_index);
47554756 try self.base_line_stack.append(self.gpa, decl.src_line);
......@@ -4761,7 +4762,7 @@ const DeclGen = struct {
47614762 }
47624763
47634764 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;
47654766 const target_id = try self.resolve(pl_op.operand);
47664767 const name = self.air.nullTerminatedString(pl_op.payload);
47674768 try self.spv.debugName(target_id, name);
......@@ -4769,7 +4770,7 @@ const DeclGen = struct {
47694770
47704771 fn airAssembly(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
47714772 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;
47734774 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
47744775
47754776 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
......@@ -4901,7 +4902,7 @@ const DeclGen = struct {
49014902 _ = modifier;
49024903
49034904 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;
49054906 const extra = self.air.extraData(Air.Call, pl_op.payload);
49064907 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
49074908 const callee_ty = self.typeOf(pl_op.operand);
src/print_air.zig+55-55
......@@ -94,7 +94,7 @@ const Writer = struct {
9494 }
9595
9696 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)];
9898 try s.writeByteNTimes(' ', w.indent);
9999 try s.print("%{d}{c}= {s}(", .{
100100 inst,
......@@ -329,14 +329,14 @@ const Writer = struct {
329329 }
330330
331331 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;
333333 try w.writeOperand(s, inst, 0, bin_op.lhs);
334334 try s.writeAll(", ");
335335 try w.writeOperand(s, inst, 1, bin_op.rhs);
336336 }
337337
338338 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;
340340 try w.writeOperand(s, inst, 0, un_op);
341341 }
342342
......@@ -351,33 +351,33 @@ const Writer = struct {
351351 }
352352
353353 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;
355355 try w.writeType(s, ty);
356356 }
357357
358358 fn writeArg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
359 const arg = w.air.instructions.items(.data)[inst].arg;
360 try w.writeType(s, w.air.getRefType(arg.ty));
359 const arg = w.air.instructions.items(.data)[@intFromEnum(inst)].arg;
360 try w.writeType(s, arg.ty.toType());
361361 try s.print(", {d}", .{arg.src_index});
362362 }
363363
364364 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;
366 try w.writeType(s, w.air.getRefType(ty_op.ty));
365 const ty_op = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
366 try w.writeType(s, ty_op.ty.toType());
367367 try s.writeAll(", ");
368368 try w.writeOperand(s, inst, 0, ty_op.operand);
369369 }
370370
371371 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;
373373 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]);
375375 const liveness_block = if (w.liveness) |liveness|
376376 liveness.getBlock(inst)
377377 else
378378 Liveness.BlockSlices{ .deaths = &.{} };
379379
380 try w.writeType(s, w.air.getRefType(ty_pl.ty));
380 try w.writeType(s, ty_pl.ty.toType());
381381 if (w.skip_body) return s.writeAll(", ...");
382382 try s.writeAll(", {\n");
383383 const old_indent = w.indent;
......@@ -393,11 +393,11 @@ const Writer = struct {
393393 }
394394
395395 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;
397397 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());
401401 if (w.skip_body) return s.writeAll(", ...");
402402 try s.writeAll(", {\n");
403403 const old_indent = w.indent;
......@@ -410,8 +410,8 @@ const Writer = struct {
410410
411411 fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
412412 const mod = w.module;
413 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
414 const vector_ty = w.air.getRefType(ty_pl.ty);
413 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
414 const vector_ty = ty_pl.ty.toType();
415415 const len = @as(usize, @intCast(vector_ty.arrayLen(mod)));
416416 const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len]));
417417
......@@ -425,7 +425,7 @@ const Writer = struct {
425425 }
426426
427427 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;
429429 const extra = w.air.extraData(Air.UnionInit, ty_pl.payload).data;
430430
431431 try s.print("{d}, ", .{extra.field_index});
......@@ -433,7 +433,7 @@ const Writer = struct {
433433 }
434434
435435 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;
437437 const extra = w.air.extraData(Air.StructField, ty_pl.payload).data;
438438
439439 try w.writeOperand(s, inst, 0, extra.struct_operand);
......@@ -442,10 +442,10 @@ const Writer = struct {
442442
443443 fn writeTyPlBin(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
444444 const data = w.air.instructions.items(.data);
445 const ty_pl = data[inst].ty_pl;
445 const ty_pl = data[@intFromEnum(inst)].ty_pl;
446446 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();
449449 try w.writeType(s, inst_ty);
450450 try s.writeAll(", ");
451451 try w.writeOperand(s, inst, 0, extra.lhs);
......@@ -454,7 +454,7 @@ const Writer = struct {
454454 }
455455
456456 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;
458458 const extra = w.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
459459
460460 try w.writeOperand(s, inst, 0, extra.ptr);
......@@ -468,7 +468,7 @@ const Writer = struct {
468468 }
469469
470470 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;
472472 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
473473
474474 try w.writeOperand(s, inst, 0, extra.lhs);
......@@ -479,7 +479,7 @@ const Writer = struct {
479479 }
480480
481481 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;
483483 const extra = w.air.extraData(Air.Shuffle, ty_pl.payload).data;
484484
485485 try w.writeOperand(s, inst, 0, extra.a);
......@@ -490,7 +490,7 @@ const Writer = struct {
490490
491491 fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
492492 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;
494494 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
495495
496496 const elem_ty = w.typeOfIndex(inst).childType(mod);
......@@ -504,14 +504,14 @@ const Writer = struct {
504504 }
505505
506506 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
509509 try w.writeOperand(s, inst, 0, reduce.operand);
510510 try s.print(", {s}", .{@tagName(reduce.operation)});
511511 }
512512
513513 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;
515515 const extra = w.air.extraData(Air.VectorCmp, ty_pl.payload).data;
516516
517517 try s.print("{s}, ", .{@tagName(extra.compareOperator())});
......@@ -521,7 +521,7 @@ const Writer = struct {
521521 }
522522
523523 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;
525525 const extra = w.air.extraData(Air.VectorCmp, data.payload).data;
526526
527527 try w.writeOperand(s, inst, 0, data.vector_ptr);
......@@ -532,20 +532,20 @@ const Writer = struct {
532532 }
533533
534534 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
537537 try s.print("{s}", .{@tagName(atomic_order)});
538538 }
539539
540540 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
543543 try w.writeOperand(s, inst, 0, atomic_load.ptr);
544544 try s.print(", {s}", .{@tagName(atomic_load.order)});
545545 }
546546
547547 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
550550 try w.writeOperand(s, inst, 0, prefetch.ptr);
551551 try s.print(", {s}, {d}, {s}", .{
......@@ -559,7 +559,7 @@ const Writer = struct {
559559 inst: Air.Inst.Index,
560560 order: std.builtin.AtomicOrder,
561561 ) @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;
563563 try w.writeOperand(s, inst, 0, bin_op.lhs);
564564 try s.writeAll(", ");
565565 try w.writeOperand(s, inst, 1, bin_op.rhs);
......@@ -567,7 +567,7 @@ const Writer = struct {
567567 }
568568
569569 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;
571571 const extra = w.air.extraData(Air.AtomicRmw, pl_op.payload).data;
572572
573573 try w.writeOperand(s, inst, 0, pl_op.operand);
......@@ -577,7 +577,7 @@ const Writer = struct {
577577 }
578578
579579 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;
581581 const extra = w.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
582582
583583 try w.writeOperand(s, inst, 0, extra.field_ptr);
......@@ -585,7 +585,7 @@ const Writer = struct {
585585 }
586586
587587 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;
589589 const extra = w.air.extraData(Air.Asm, ty_pl.payload);
590590 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
591591 const clobbers_len = @as(u31, @truncate(extra.data.flags));
......@@ -658,26 +658,26 @@ const Writer = struct {
658658 }
659659
660660 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;
662662 try s.print("{d}:{d}", .{ dbg_stmt.line + 1, dbg_stmt.column + 1 });
663663 }
664664
665665 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;
667667 const func_index = ty_fn.func;
668668 const owner_decl = w.module.funcOwnerDeclPtr(func_index);
669669 try s.print("{}", .{owner_decl.name.fmt(&w.module.intern_pool)});
670670 }
671671
672672 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;
674674 try w.writeOperand(s, inst, 0, pl_op.operand);
675675 const name = w.air.nullTerminatedString(pl_op.payload);
676676 try s.print(", \"{}\"", .{std.zig.fmtEscapes(name)});
677677 }
678678
679679 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;
681681 const extra = w.air.extraData(Air.Call, pl_op.payload);
682682 const args = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[extra.end..][0..extra.data.args_len]));
683683 try w.writeOperand(s, inst, 0, pl_op.operand);
......@@ -690,16 +690,16 @@ const Writer = struct {
690690 }
691691
692692 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;
694694 try w.writeInstIndex(s, br.block_inst, false);
695695 try s.writeAll(", ");
696696 try w.writeOperand(s, inst, 0, br.operand);
697697 }
698698
699699 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;
701701 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]);
703703 const liveness_condbr = if (w.liveness) |liveness|
704704 liveness.getCondBr(inst)
705705 else
......@@ -731,9 +731,9 @@ const Writer = struct {
731731 }
732732
733733 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;
735735 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]);
737737 const liveness_condbr = if (w.liveness) |liveness|
738738 liveness.getCondBr(inst)
739739 else
......@@ -742,7 +742,7 @@ const Writer = struct {
742742 try w.writeOperand(s, inst, 0, extra.data.ptr);
743743
744744 try s.writeAll(", ");
745 try w.writeType(s, w.air.getRefType(ty_pl.ty));
745 try w.writeType(s, ty_pl.ty.toType());
746746 if (w.skip_body) return s.writeAll(", ...");
747747 try s.writeAll(", {\n");
748748 const old_indent = w.indent;
......@@ -768,10 +768,10 @@ const Writer = struct {
768768 }
769769
770770 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;
772772 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];
774 const else_body = w.air.extra[extra.end + then_body.len ..][0..extra.data.else_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: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]);
775775 const liveness_condbr = if (w.liveness) |liveness|
776776 liveness.getCondBr(inst)
777777 else
......@@ -813,7 +813,7 @@ const Writer = struct {
813813 }
814814
815815 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;
817817 const switch_br = w.air.extraData(Air.SwitchBr, pl_op.payload);
818818 const liveness = if (w.liveness) |liveness|
819819 liveness.getSwitchBr(w.gpa, inst, switch_br.data.cases_len + 1) catch
......@@ -836,7 +836,7 @@ const Writer = struct {
836836 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
837837 const case = w.air.extraData(Air.SwitchBr.Case, extra_index);
838838 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]);
840840 extra_index = case.end + case.data.items_len + case_body.len;
841841
842842 try s.writeAll(", [");
......@@ -863,7 +863,7 @@ const Writer = struct {
863863 try s.writeAll("}");
864864 }
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]);
867867 if (else_body.len != 0) {
868868 try s.writeAll(", else => {\n");
869869 w.indent += 2;
......@@ -889,18 +889,18 @@ const Writer = struct {
889889 }
890890
891891 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;
893893 try s.print("{d}", .{pl_op.payload});
894894 }
895895
896896 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;
898898 try s.print("{d}, ", .{pl_op.payload});
899899 try w.writeOperand(s, inst, 0, pl_op.operand);
900900 }
901901
902902 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;
904904 try s.print("{d}", .{pl_op.payload});
905905 }
906906
......@@ -938,7 +938,7 @@ const Writer = struct {
938938 ) @TypeOf(s).Error!void {
939939 if (@intFromEnum(operand) < InternPool.static_len) {
940940 return s.print("@{}", .{operand});
941 } else if (Air.refToInterned(operand)) |ip_index| {
941 } else if (operand.toInterned()) |ip_index| {
942942 const mod = w.module;
943943 const ty = Type.fromInterned(mod.intern_pool.indexToKey(ip_index).typeOf());
944944 try s.print("<{}, {}>", .{
......@@ -946,7 +946,7 @@ const Writer = struct {
946946 Value.fromInterned(ip_index).fmtValue(ty, mod),
947947 });
948948 } else {
949 return w.writeInstIndex(s, Air.refToIndex(operand).?, dies);
949 return w.writeInstIndex(s, operand.toIndex().?, dies);
950950 }
951951 }
952952