| author | |
| committer | |
| log | daf91ed8d1149d10f0e4a597efc9f17c4a49b0ca |
| tree | 947f39a04ad2aed68faa4d5929c923e026c7138c |
| parent | bf5ab54510fd8fbd300ddc22f9af4767477be0e5 |
I need some indices for a thing...15 files changed, 1669 insertions(+), 1642 deletions(-)
src/Air.zig+70-62| ... | ... | @@ -875,7 +875,19 @@ pub const Inst = struct { |
| 875 | 875 | }; |
| 876 | 876 | |
| 877 | 877 | /// The position of an AIR instruction within the `Air` instructions array. |
| 878 | pub const Index = u32; | |
| 878 | pub const Index = enum(u32) { | |
| 879 | _, | |
| 880 | ||
| 881 | pub fn toRef(i: Index) Inst.Ref { | |
| 882 | assert(@intFromEnum(i) >> 31 == 0); | |
| 883 | return @enumFromInt((1 << 31) | @intFromEnum(i)); | |
| 884 | } | |
| 885 | ||
| 886 | pub fn toTargetIndex(i: Index) u31 { | |
| 887 | assert(@intFromEnum(i) >> 31 == 1); | |
| 888 | return @truncate(@intFromEnum(i)); | |
| 889 | } | |
| 890 | }; | |
| 879 | 891 | |
| 880 | 892 | /// Either a reference to a value stored in the InternPool, or a reference to an AIR instruction. |
| 881 | 893 | /// The most-significant bit of the value is a tag bit. This bit is 1 if the value represents an |
| ... | ... | @@ -976,6 +988,41 @@ pub const Inst = struct { |
| 976 | 988 | /// value and may instead be used as a sentinel to indicate null. |
| 977 | 989 | none = @intFromEnum(InternPool.Index.none), |
| 978 | 990 | _, |
| 991 | ||
| 992 | pub fn toInterned(ref: Ref) ?InternPool.Index { | |
| 993 | assert(ref != .none); | |
| 994 | return ref.toInternedAllowNone(); | |
| 995 | } | |
| 996 | ||
| 997 | pub fn toInternedAllowNone(ref: Ref) ?InternPool.Index { | |
| 998 | return switch (ref) { | |
| 999 | .var_args_param_type => .var_args_param_type, | |
| 1000 | .none => .none, | |
| 1001 | else => if (@intFromEnum(ref) >> 31 == 0) | |
| 1002 | @enumFromInt(@as(u31, @truncate(@intFromEnum(ref)))) | |
| 1003 | else | |
| 1004 | null, | |
| 1005 | }; | |
| 1006 | } | |
| 1007 | ||
| 1008 | pub fn toIndex(ref: Ref) ?Index { | |
| 1009 | assert(ref != .none); | |
| 1010 | return ref.toIndexAllowNone(); | |
| 1011 | } | |
| 1012 | ||
| 1013 | pub fn toIndexAllowNone(ref: Ref) ?Index { | |
| 1014 | return switch (ref) { | |
| 1015 | .var_args_param_type, .none => null, | |
| 1016 | else => if (@intFromEnum(ref) >> 31 != 0) | |
| 1017 | @enumFromInt(@as(u31, @truncate(@intFromEnum(ref)))) | |
| 1018 | else | |
| 1019 | null, | |
| 1020 | }; | |
| 1021 | } | |
| 1022 | ||
| 1023 | pub fn toType(ref: Ref) Type { | |
| 1024 | return Type.fromInterned(ref.toInterned().?); | |
| 1025 | } | |
| 979 | 1026 | }; |
| 980 | 1027 | |
| 981 | 1028 | /// All instructions have an 8-byte payload, which is contained within |
| ... | ... | @@ -1216,20 +1263,20 @@ pub const UnionInit = struct { |
| 1216 | 1263 | pub fn getMainBody(air: Air) []const Air.Inst.Index { |
| 1217 | 1264 | const body_index = air.extra[@intFromEnum(ExtraIndex.main_block)]; |
| 1218 | 1265 | const extra = air.extraData(Block, body_index); |
| 1219 | return air.extra[extra.end..][0..extra.data.body_len]; | |
| 1266 | return @ptrCast(air.extra[extra.end..][0..extra.data.body_len]); | |
| 1220 | 1267 | } |
| 1221 | 1268 | |
| 1222 | 1269 | pub fn typeOf(air: *const Air, inst: Air.Inst.Ref, ip: *const InternPool) Type { |
| 1223 | if (refToInterned(inst)) |ip_index| { | |
| 1270 | if (inst.toInterned()) |ip_index| { | |
| 1224 | 1271 | return Type.fromInterned(ip.typeOf(ip_index)); |
| 1225 | 1272 | } else { |
| 1226 | return air.typeOfIndex(refToIndex(inst).?, ip); | |
| 1273 | return air.typeOfIndex(inst.toIndex().?, ip); | |
| 1227 | 1274 | } |
| 1228 | 1275 | } |
| 1229 | 1276 | |
| 1230 | 1277 | pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) Type { |
| 1231 | 1278 | const datas = air.instructions.items(.data); |
| 1232 | switch (air.instructions.items(.tag)[inst]) { | |
| 1279 | switch (air.instructions.items(.tag)[@intFromEnum(inst)]) { | |
| 1233 | 1280 | .add, |
| 1234 | 1281 | .add_safe, |
| 1235 | 1282 | .add_wrap, |
| ... | ... | @@ -1269,7 +1316,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) |
| 1269 | 1316 | .div_exact_optimized, |
| 1270 | 1317 | .rem_optimized, |
| 1271 | 1318 | .mod_optimized, |
| 1272 | => return air.typeOf(datas[inst].bin_op.lhs, ip), | |
| 1319 | => return air.typeOf(datas[@intFromEnum(inst)].bin_op.lhs, ip), | |
| 1273 | 1320 | |
| 1274 | 1321 | .sqrt, |
| 1275 | 1322 | .sin, |
| ... | ... | @@ -1286,7 +1333,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) |
| 1286 | 1333 | .trunc_float, |
| 1287 | 1334 | .neg, |
| 1288 | 1335 | .neg_optimized, |
| 1289 | => return air.typeOf(datas[inst].un_op, ip), | |
| 1336 | => return air.typeOf(datas[@intFromEnum(inst)].un_op, ip), | |
| 1290 | 1337 | |
| 1291 | 1338 | .cmp_lt, |
| 1292 | 1339 | .cmp_lte, |
| ... | ... | @@ -1317,9 +1364,9 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) |
| 1317 | 1364 | .ret_ptr, |
| 1318 | 1365 | .err_return_trace, |
| 1319 | 1366 | .c_va_start, |
| 1320 | => return datas[inst].ty, | |
| 1367 | => return datas[@intFromEnum(inst)].ty, | |
| 1321 | 1368 | |
| 1322 | .arg => return air.getRefType(datas[inst].arg.ty), | |
| 1369 | .arg => return datas[@intFromEnum(inst)].arg.ty.toType(), | |
| 1323 | 1370 | |
| 1324 | 1371 | .assembly, |
| 1325 | 1372 | .block, |
| ... | ... | @@ -1343,7 +1390,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) |
| 1343 | 1390 | .ptr_add, |
| 1344 | 1391 | .ptr_sub, |
| 1345 | 1392 | .try_ptr, |
| 1346 | => return air.getRefType(datas[inst].ty_pl.ty), | |
| 1393 | => return datas[@intFromEnum(inst)].ty_pl.ty.toType(), | |
| 1347 | 1394 | |
| 1348 | 1395 | .not, |
| 1349 | 1396 | .bitcast, |
| ... | ... | @@ -1385,7 +1432,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) |
| 1385 | 1432 | .c_va_arg, |
| 1386 | 1433 | .c_va_copy, |
| 1387 | 1434 | .abs, |
| 1388 | => return air.getRefType(datas[inst].ty_op.ty), | |
| 1435 | => return datas[@intFromEnum(inst)].ty_op.ty.toType(), | |
| 1389 | 1436 | |
| 1390 | 1437 | .loop, |
| 1391 | 1438 | .br, |
| ... | ... | @@ -1437,36 +1484,36 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) |
| 1437 | 1484 | .tag_name, .error_name => return Type.slice_const_u8_sentinel_0, |
| 1438 | 1485 | |
| 1439 | 1486 | .call, .call_always_tail, .call_never_tail, .call_never_inline => { |
| 1440 | const callee_ty = air.typeOf(datas[inst].pl_op.operand, ip); | |
| 1487 | const callee_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip); | |
| 1441 | 1488 | return Type.fromInterned(ip.funcTypeReturnType(callee_ty.toIntern())); |
| 1442 | 1489 | }, |
| 1443 | 1490 | |
| 1444 | 1491 | .slice_elem_val, .ptr_elem_val, .array_elem_val => { |
| 1445 | const ptr_ty = air.typeOf(datas[inst].bin_op.lhs, ip); | |
| 1492 | const ptr_ty = air.typeOf(datas[@intFromEnum(inst)].bin_op.lhs, ip); | |
| 1446 | 1493 | return ptr_ty.childTypeIp(ip); |
| 1447 | 1494 | }, |
| 1448 | 1495 | .atomic_load => { |
| 1449 | const ptr_ty = air.typeOf(datas[inst].atomic_load.ptr, ip); | |
| 1496 | const ptr_ty = air.typeOf(datas[@intFromEnum(inst)].atomic_load.ptr, ip); | |
| 1450 | 1497 | return ptr_ty.childTypeIp(ip); |
| 1451 | 1498 | }, |
| 1452 | 1499 | .atomic_rmw => { |
| 1453 | const ptr_ty = air.typeOf(datas[inst].pl_op.operand, ip); | |
| 1500 | const ptr_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip); | |
| 1454 | 1501 | return ptr_ty.childTypeIp(ip); |
| 1455 | 1502 | }, |
| 1456 | 1503 | |
| 1457 | 1504 | .reduce, .reduce_optimized => { |
| 1458 | const operand_ty = air.typeOf(datas[inst].reduce.operand, ip); | |
| 1505 | const operand_ty = air.typeOf(datas[@intFromEnum(inst)].reduce.operand, ip); | |
| 1459 | 1506 | return Type.fromInterned(ip.indexToKey(operand_ty.ip_index).vector_type.child); |
| 1460 | 1507 | }, |
| 1461 | 1508 | |
| 1462 | .mul_add => return air.typeOf(datas[inst].pl_op.operand, ip), | |
| 1509 | .mul_add => return air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip), | |
| 1463 | 1510 | .select => { |
| 1464 | const extra = air.extraData(Air.Bin, datas[inst].pl_op.payload).data; | |
| 1511 | const extra = air.extraData(Air.Bin, datas[@intFromEnum(inst)].pl_op.payload).data; | |
| 1465 | 1512 | return air.typeOf(extra.lhs, ip); |
| 1466 | 1513 | }, |
| 1467 | 1514 | |
| 1468 | 1515 | .@"try" => { |
| 1469 | const err_union_ty = air.typeOf(datas[inst].pl_op.operand, ip); | |
| 1516 | const err_union_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip); | |
| 1470 | 1517 | return Type.fromInterned(ip.indexToKey(err_union_ty.ip_index).error_union_type.payload_type); |
| 1471 | 1518 | }, |
| 1472 | 1519 | |
| ... | ... | @@ -1480,11 +1527,6 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) |
| 1480 | 1527 | } |
| 1481 | 1528 | } |
| 1482 | 1529 | |
| 1483 | pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type { | |
| 1484 | _ = air; // TODO: remove this parameter | |
| 1485 | return Type.fromInterned(refToInterned(ref).?); | |
| 1486 | } | |
| 1487 | ||
| 1488 | 1530 | /// Returns the requested data, as well as the new index which is at the start of the |
| 1489 | 1531 | /// trailers for the object. |
| 1490 | 1532 | pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end: usize } { |
| ... | ... | @@ -1513,21 +1555,6 @@ pub fn deinit(air: *Air, gpa: std.mem.Allocator) void { |
| 1513 | 1555 | air.* = undefined; |
| 1514 | 1556 | } |
| 1515 | 1557 | |
| 1516 | pub 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 | ||
| 1526 | pub fn refToInterned(ref: Inst.Ref) ?InternPool.Index { | |
| 1527 | assert(ref != .none); | |
| 1528 | return refToInternedAllowNone(ref); | |
| 1529 | } | |
| 1530 | ||
| 1531 | 1558 | pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref { |
| 1532 | 1559 | return switch (ip_index) { |
| 1533 | 1560 | .var_args_param_type => .var_args_param_type, |
| ... | ... | @@ -1539,31 +1566,12 @@ pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref { |
| 1539 | 1566 | }; |
| 1540 | 1567 | } |
| 1541 | 1568 | |
| 1542 | pub 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 | ||
| 1551 | pub fn refToIndex(ref: Inst.Ref) ?Inst.Index { | |
| 1552 | assert(ref != .none); | |
| 1553 | return refToIndexAllowNone(ref); | |
| 1554 | } | |
| 1555 | ||
| 1556 | pub fn indexToRef(inst: Inst.Index) Inst.Ref { | |
| 1557 | assert(inst >> 31 == 0); | |
| 1558 | return @enumFromInt((1 << 31) | inst); | |
| 1559 | } | |
| 1560 | ||
| 1561 | 1569 | /// Returns `null` if runtime-known. |
| 1562 | 1570 | pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value { |
| 1563 | if (refToInterned(inst)) |ip_index| { | |
| 1571 | if (inst.toInterned()) |ip_index| { | |
| 1564 | 1572 | return Value.fromInterned(ip_index); |
| 1565 | 1573 | } |
| 1566 | const index = refToIndex(inst).?; | |
| 1574 | const index = inst.toIndex().?; | |
| 1567 | 1575 | return air.typeOfIndex(index, &mod.intern_pool).onePossibleValue(mod); |
| 1568 | 1576 | } |
| 1569 | 1577 | |
| ... | ... | @@ -1581,8 +1589,8 @@ pub fn nullTerminatedString(air: Air, index: usize) [:0]const u8 { |
| 1581 | 1589 | /// lowered, and Liveness determines its result is unused, backends should |
| 1582 | 1590 | /// avoid lowering it. |
| 1583 | 1591 | pub 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)]) { | |
| 1586 | 1594 | .arg, |
| 1587 | 1595 | .block, |
| 1588 | 1596 | .loop, |
src/Liveness.zig+117-117| ... | ... | @@ -177,31 +177,31 @@ pub fn analyze(gpa: Allocator, air: Air, intern_pool: *const InternPool) Allocat |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | pub fn getTombBits(l: Liveness, inst: Air.Inst.Index) Bpi { |
| 180 | const usize_index = (inst * bpi) / @bitSizeOf(usize); | |
| 180 | const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize); | |
| 181 | 181 | return @as(Bpi, @truncate(l.tomb_bits[usize_index] >> |
| 182 | @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi)))); | |
| 182 | @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi)))); | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | pub fn isUnused(l: Liveness, inst: Air.Inst.Index) bool { |
| 186 | const usize_index = (inst * bpi) / @bitSizeOf(usize); | |
| 186 | const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize); | |
| 187 | 187 | const mask = @as(usize, 1) << |
| 188 | @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi + (bpi - 1))); | |
| 188 | @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi + (bpi - 1))); | |
| 189 | 189 | return (l.tomb_bits[usize_index] & mask) != 0; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool { |
| 193 | 193 | assert(operand < bpi - 1); |
| 194 | const usize_index = (inst * bpi) / @bitSizeOf(usize); | |
| 194 | const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize); | |
| 195 | 195 | const mask = @as(usize, 1) << |
| 196 | @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi + operand)); | |
| 196 | @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi + operand)); | |
| 197 | 197 | return (l.tomb_bits[usize_index] & mask) != 0; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | pub fn clearOperandDeath(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) void { |
| 201 | 201 | assert(operand < bpi - 1); |
| 202 | const usize_index = (inst * bpi) / @bitSizeOf(usize); | |
| 202 | const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize); | |
| 203 | 203 | const mask = @as(usize, 1) << |
| 204 | @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi + operand)); | |
| 204 | @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi + operand)); | |
| 205 | 205 | l.tomb_bits[usize_index] &= ~mask; |
| 206 | 206 | } |
| 207 | 207 | |
| ... | ... | @@ -229,8 +229,8 @@ pub fn categorizeOperand( |
| 229 | 229 | ) OperandCategory { |
| 230 | 230 | const air_tags = air.instructions.items(.tag); |
| 231 | 231 | 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)]) { | |
| 234 | 234 | .add, |
| 235 | 235 | .add_safe, |
| 236 | 236 | .add_wrap, |
| ... | ... | @@ -287,7 +287,7 @@ pub fn categorizeOperand( |
| 287 | 287 | .cmp_gt_optimized, |
| 288 | 288 | .cmp_neq_optimized, |
| 289 | 289 | => { |
| 290 | const o = air_datas[inst].bin_op; | |
| 290 | const o = air_datas[@intFromEnum(inst)].bin_op; | |
| 291 | 291 | if (o.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 292 | 292 | if (o.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none); |
| 293 | 293 | return .none; |
| ... | ... | @@ -304,14 +304,14 @@ pub fn categorizeOperand( |
| 304 | 304 | .memset_safe, |
| 305 | 305 | .memcpy, |
| 306 | 306 | => { |
| 307 | const o = air_datas[inst].bin_op; | |
| 307 | const o = air_datas[@intFromEnum(inst)].bin_op; | |
| 308 | 308 | if (o.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write); |
| 309 | 309 | if (o.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write); |
| 310 | 310 | return .write; |
| 311 | 311 | }, |
| 312 | 312 | |
| 313 | 313 | .vector_store_elem => { |
| 314 | const o = air_datas[inst].vector_store_elem; | |
| 314 | const o = air_datas[@intFromEnum(inst)].vector_store_elem; | |
| 315 | 315 | const extra = air.extraData(Air.Bin, o.payload).data; |
| 316 | 316 | if (o.vector_ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write); |
| 317 | 317 | if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none); |
| ... | ... | @@ -386,7 +386,7 @@ pub fn categorizeOperand( |
| 386 | 386 | .c_va_copy, |
| 387 | 387 | .abs, |
| 388 | 388 | => { |
| 389 | const o = air_datas[inst].ty_op; | |
| 389 | const o = air_datas[@intFromEnum(inst)].ty_op; | |
| 390 | 390 | if (o.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 391 | 391 | return .none; |
| 392 | 392 | }, |
| ... | ... | @@ -394,7 +394,7 @@ pub fn categorizeOperand( |
| 394 | 394 | .optional_payload_ptr_set, |
| 395 | 395 | .errunion_payload_ptr_set, |
| 396 | 396 | => { |
| 397 | const o = air_datas[inst].ty_op; | |
| 397 | const o = air_datas[@intFromEnum(inst)].ty_op; | |
| 398 | 398 | if (o.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write); |
| 399 | 399 | return .write; |
| 400 | 400 | }, |
| ... | ... | @@ -429,7 +429,7 @@ pub fn categorizeOperand( |
| 429 | 429 | .cmp_lt_errors_len, |
| 430 | 430 | .c_va_end, |
| 431 | 431 | => { |
| 432 | const o = air_datas[inst].un_op; | |
| 432 | const o = air_datas[@intFromEnum(inst)].un_op; | |
| 433 | 433 | if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 434 | 434 | return .none; |
| 435 | 435 | }, |
| ... | ... | @@ -437,13 +437,13 @@ pub fn categorizeOperand( |
| 437 | 437 | .ret, |
| 438 | 438 | .ret_load, |
| 439 | 439 | => { |
| 440 | const o = air_datas[inst].un_op; | |
| 440 | const o = air_datas[@intFromEnum(inst)].un_op; | |
| 441 | 441 | if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .noret); |
| 442 | 442 | return .noret; |
| 443 | 443 | }, |
| 444 | 444 | |
| 445 | 445 | .set_err_return_trace => { |
| 446 | const o = air_datas[inst].un_op; | |
| 446 | const o = air_datas[@intFromEnum(inst)].un_op; | |
| 447 | 447 | if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write); |
| 448 | 448 | return .write; |
| 449 | 449 | }, |
| ... | ... | @@ -458,7 +458,7 @@ pub fn categorizeOperand( |
| 458 | 458 | .slice_elem_ptr, |
| 459 | 459 | .slice, |
| 460 | 460 | => { |
| 461 | const ty_pl = air_datas[inst].ty_pl; | |
| 461 | const ty_pl = air_datas[@intFromEnum(inst)].ty_pl; | |
| 462 | 462 | const extra = air.extraData(Air.Bin, ty_pl.payload).data; |
| 463 | 463 | if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 464 | 464 | if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none); |
| ... | ... | @@ -468,19 +468,19 @@ pub fn categorizeOperand( |
| 468 | 468 | .dbg_var_ptr, |
| 469 | 469 | .dbg_var_val, |
| 470 | 470 | => { |
| 471 | const o = air_datas[inst].pl_op.operand; | |
| 471 | const o = air_datas[@intFromEnum(inst)].pl_op.operand; | |
| 472 | 472 | if (o == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 473 | 473 | return .none; |
| 474 | 474 | }, |
| 475 | 475 | |
| 476 | 476 | .prefetch => { |
| 477 | const prefetch = air_datas[inst].prefetch; | |
| 477 | const prefetch = air_datas[@intFromEnum(inst)].prefetch; | |
| 478 | 478 | if (prefetch.ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 479 | 479 | return .none; |
| 480 | 480 | }, |
| 481 | 481 | |
| 482 | 482 | .call, .call_always_tail, .call_never_tail, .call_never_inline => { |
| 483 | const inst_data = air_datas[inst].pl_op; | |
| 483 | const inst_data = air_datas[@intFromEnum(inst)].pl_op; | |
| 484 | 484 | const callee = inst_data.operand; |
| 485 | 485 | const extra = air.extraData(Air.Call, inst_data.payload); |
| 486 | 486 | const args = @as([]const Air.Inst.Ref, @ptrCast(air.extra[extra.end..][0..extra.data.args_len])); |
| ... | ... | @@ -507,7 +507,7 @@ pub fn categorizeOperand( |
| 507 | 507 | return .write; |
| 508 | 508 | }, |
| 509 | 509 | .select => { |
| 510 | const pl_op = air_datas[inst].pl_op; | |
| 510 | const pl_op = air_datas[@intFromEnum(inst)].pl_op; | |
| 511 | 511 | const extra = air.extraData(Air.Bin, pl_op.payload).data; |
| 512 | 512 | if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 513 | 513 | if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none); |
| ... | ... | @@ -515,25 +515,25 @@ pub fn categorizeOperand( |
| 515 | 515 | return .none; |
| 516 | 516 | }, |
| 517 | 517 | .shuffle => { |
| 518 | const extra = air.extraData(Air.Shuffle, air_datas[inst].ty_pl.payload).data; | |
| 518 | const extra = air.extraData(Air.Shuffle, air_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 519 | 519 | if (extra.a == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 520 | 520 | if (extra.b == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none); |
| 521 | 521 | return .none; |
| 522 | 522 | }, |
| 523 | 523 | .reduce, .reduce_optimized => { |
| 524 | const reduce = air_datas[inst].reduce; | |
| 524 | const reduce = air_datas[@intFromEnum(inst)].reduce; | |
| 525 | 525 | if (reduce.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 526 | 526 | return .none; |
| 527 | 527 | }, |
| 528 | 528 | .cmp_vector, .cmp_vector_optimized => { |
| 529 | const extra = air.extraData(Air.VectorCmp, air_datas[inst].ty_pl.payload).data; | |
| 529 | const extra = air.extraData(Air.VectorCmp, air_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 530 | 530 | if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 531 | 531 | if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none); |
| 532 | 532 | return .none; |
| 533 | 533 | }, |
| 534 | 534 | .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(); | |
| 537 | 537 | const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip))); |
| 538 | 538 | const elements = @as([]const Air.Inst.Ref, @ptrCast(air.extra[ty_pl.payload..][0..len])); |
| 539 | 539 | |
| ... | ... | @@ -555,29 +555,29 @@ pub fn categorizeOperand( |
| 555 | 555 | return .write; |
| 556 | 556 | }, |
| 557 | 557 | .union_init => { |
| 558 | const extra = air.extraData(Air.UnionInit, air_datas[inst].ty_pl.payload).data; | |
| 558 | const extra = air.extraData(Air.UnionInit, air_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 559 | 559 | if (extra.init == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 560 | 560 | return .none; |
| 561 | 561 | }, |
| 562 | 562 | .struct_field_ptr, .struct_field_val => { |
| 563 | const extra = air.extraData(Air.StructField, air_datas[inst].ty_pl.payload).data; | |
| 563 | const extra = air.extraData(Air.StructField, air_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 564 | 564 | if (extra.struct_operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 565 | 565 | return .none; |
| 566 | 566 | }, |
| 567 | 567 | .field_parent_ptr => { |
| 568 | const extra = air.extraData(Air.FieldParentPtr, air_datas[inst].ty_pl.payload).data; | |
| 568 | const extra = air.extraData(Air.FieldParentPtr, air_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 569 | 569 | if (extra.field_ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 570 | 570 | return .none; |
| 571 | 571 | }, |
| 572 | 572 | .cmpxchg_strong, .cmpxchg_weak => { |
| 573 | const extra = air.extraData(Air.Cmpxchg, air_datas[inst].ty_pl.payload).data; | |
| 573 | const extra = air.extraData(Air.Cmpxchg, air_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 574 | 574 | if (extra.ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write); |
| 575 | 575 | if (extra.expected_value == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write); |
| 576 | 576 | if (extra.new_value == operand_ref) return matchOperandSmallIndex(l, inst, 2, .write); |
| 577 | 577 | return .write; |
| 578 | 578 | }, |
| 579 | 579 | .mul_add => { |
| 580 | const pl_op = air_datas[inst].pl_op; | |
| 580 | const pl_op = air_datas[@intFromEnum(inst)].pl_op; | |
| 581 | 581 | const extra = air.extraData(Air.Bin, pl_op.payload).data; |
| 582 | 582 | if (extra.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 583 | 583 | if (extra.rhs == operand_ref) return matchOperandSmallIndex(l, inst, 1, .none); |
| ... | ... | @@ -585,12 +585,12 @@ pub fn categorizeOperand( |
| 585 | 585 | return .none; |
| 586 | 586 | }, |
| 587 | 587 | .atomic_load => { |
| 588 | const ptr = air_datas[inst].atomic_load.ptr; | |
| 588 | const ptr = air_datas[@intFromEnum(inst)].atomic_load.ptr; | |
| 589 | 589 | if (ptr == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 590 | 590 | return .none; |
| 591 | 591 | }, |
| 592 | 592 | .atomic_rmw => { |
| 593 | const pl_op = air_datas[inst].pl_op; | |
| 593 | const pl_op = air_datas[@intFromEnum(inst)].pl_op; | |
| 594 | 594 | const extra = air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 595 | 595 | if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write); |
| 596 | 596 | if (extra.operand == operand_ref) return matchOperandSmallIndex(l, inst, 1, .write); |
| ... | ... | @@ -598,7 +598,7 @@ pub fn categorizeOperand( |
| 598 | 598 | }, |
| 599 | 599 | |
| 600 | 600 | .br => { |
| 601 | const br = air_datas[inst].br; | |
| 601 | const br = air_datas[@intFromEnum(inst)].br; | |
| 602 | 602 | if (br.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .noret); |
| 603 | 603 | return .noret; |
| 604 | 604 | }, |
| ... | ... | @@ -606,16 +606,16 @@ pub fn categorizeOperand( |
| 606 | 606 | return .complex; |
| 607 | 607 | }, |
| 608 | 608 | .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]); | |
| 611 | 611 | |
| 612 | if (body.len == 1 and air_tags[body[0]] == .cond_br) { | |
| 612 | if (body.len == 1 and air_tags[@intFromEnum(body[0])] == .cond_br) { | |
| 613 | 613 | // Peephole optimization for "panic-like" conditionals, which have |
| 614 | 614 | // one empty branch and another which calls a `noreturn` function. |
| 615 | 615 | // This allows us to infer that safety checks do not modify memory, |
| 616 | 616 | // as far as control flow successors are concerned. |
| 617 | 617 | |
| 618 | const inst_data = air_datas[body[0]].pl_op; | |
| 618 | const inst_data = air_datas[@intFromEnum(body[0])].pl_op; | |
| 619 | 619 | const cond_extra = air.extraData(Air.CondBr, inst_data.payload); |
| 620 | 620 | if (inst_data.operand == operand_ref and operandDies(l, body[0], 0)) |
| 621 | 621 | return .tomb; |
| ... | ... | @@ -623,21 +623,21 @@ pub fn categorizeOperand( |
| 623 | 623 | if (cond_extra.data.then_body_len > 2 or cond_extra.data.else_body_len > 2) |
| 624 | 624 | return .complex; |
| 625 | 625 | |
| 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) | |
| 629 | 629 | return .complex; |
| 630 | if (else_body.len > 1 and air_tags[else_body[1]] != .unreach) | |
| 630 | if (else_body.len > 1 and air_tags[@intFromEnum(else_body[1])] != .unreach) | |
| 631 | 631 | return .complex; |
| 632 | 632 | |
| 633 | 633 | var operand_live: bool = true; |
| 634 | for (&[_]u32{ then_body[0], else_body[0] }) |cond_inst| { | |
| 634 | for (&[_]Air.Inst.Index{ then_body[0], else_body[0] }) |cond_inst| { | |
| 635 | 635 | if (l.categorizeOperand(air, cond_inst, operand, ip) == .tomb) |
| 636 | 636 | operand_live = false; |
| 637 | 637 | |
| 638 | switch (air_tags[cond_inst]) { | |
| 638 | switch (air_tags[@intFromEnum(cond_inst)]) { | |
| 639 | 639 | .br => { // Breaks immediately back to block |
| 640 | const br = air_datas[cond_inst].br; | |
| 640 | const br = air_datas[@intFromEnum(cond_inst)].br; | |
| 641 | 641 | if (br.block_inst != inst) |
| 642 | 642 | return .complex; |
| 643 | 643 | }, |
| ... | ... | @@ -666,7 +666,7 @@ pub fn categorizeOperand( |
| 666 | 666 | return .complex; |
| 667 | 667 | }, |
| 668 | 668 | .wasm_memory_grow => { |
| 669 | const pl_op = air_datas[inst].pl_op; | |
| 669 | const pl_op = air_datas[@intFromEnum(inst)].pl_op; | |
| 670 | 670 | if (pl_op.operand == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none); |
| 671 | 671 | return .none; |
| 672 | 672 | }, |
| ... | ... | @@ -701,11 +701,11 @@ pub fn getCondBr(l: Liveness, inst: Air.Inst.Index) CondBrSlices { |
| 701 | 701 | index += 1; |
| 702 | 702 | const else_death_count = l.extra[index]; |
| 703 | 703 | index += 1; |
| 704 | const then_deaths = l.extra[index..][0..then_death_count]; | |
| 704 | const then_deaths: []const Air.Inst.Index = @ptrCast(l.extra[index..][0..then_death_count]); | |
| 705 | 705 | index += then_death_count; |
| 706 | 706 | return .{ |
| 707 | 707 | .then_deaths = then_deaths, |
| 708 | .else_deaths = l.extra[index..][0..else_death_count], | |
| 708 | .else_deaths = @ptrCast(l.extra[index..][0..else_death_count]), | |
| 709 | 709 | }; |
| 710 | 710 | } |
| 711 | 711 | |
| ... | ... | @@ -731,13 +731,13 @@ pub fn getSwitchBr(l: Liveness, gpa: Allocator, inst: Air.Inst.Index, cases_len: |
| 731 | 731 | while (case_i < cases_len - 1) : (case_i += 1) { |
| 732 | 732 | const case_death_count: u32 = l.extra[index]; |
| 733 | 733 | index += 1; |
| 734 | const case_deaths = l.extra[index..][0..case_death_count]; | |
| 734 | const case_deaths: []const Air.Inst.Index = @ptrCast(l.extra[index..][0..case_death_count]); | |
| 735 | 735 | index += case_death_count; |
| 736 | 736 | deaths.appendAssumeCapacity(case_deaths); |
| 737 | 737 | } |
| 738 | 738 | { |
| 739 | 739 | // Else |
| 740 | const else_deaths = l.extra[index..][0..else_death_count]; | |
| 740 | const else_deaths: []const Air.Inst.Index = @ptrCast(l.extra[index..][0..else_death_count]); | |
| 741 | 741 | deaths.appendAssumeCapacity(else_deaths); |
| 742 | 742 | } |
| 743 | 743 | return SwitchBrTable{ |
| ... | ... | @@ -756,7 +756,7 @@ pub fn getBlock(l: Liveness, inst: Air.Inst.Index) BlockSlices { |
| 756 | 756 | .deaths = &.{}, |
| 757 | 757 | }; |
| 758 | 758 | const death_count = l.extra[index]; |
| 759 | const deaths = l.extra[index + 1 ..][0..death_count]; | |
| 759 | const deaths: []const Air.Inst.Index = @ptrCast(l.extra[index + 1 ..][0..death_count]); | |
| 760 | 760 | return .{ |
| 761 | 761 | .deaths = deaths, |
| 762 | 762 | }; |
| ... | ... | @@ -883,7 +883,7 @@ fn analyzeInst( |
| 883 | 883 | const inst_tags = a.air.instructions.items(.tag); |
| 884 | 884 | const inst_datas = a.air.instructions.items(.data); |
| 885 | 885 | |
| 886 | switch (inst_tags[inst]) { | |
| 886 | switch (inst_tags[@intFromEnum(inst)]) { | |
| 887 | 887 | .add, |
| 888 | 888 | .add_safe, |
| 889 | 889 | .add_optimized, |
| ... | ... | @@ -949,12 +949,12 @@ fn analyzeInst( |
| 949 | 949 | .memset_safe, |
| 950 | 950 | .memcpy, |
| 951 | 951 | => { |
| 952 | const o = inst_datas[inst].bin_op; | |
| 952 | const o = inst_datas[@intFromEnum(inst)].bin_op; | |
| 953 | 953 | return analyzeOperands(a, pass, data, inst, .{ o.lhs, o.rhs, .none }); |
| 954 | 954 | }, |
| 955 | 955 | |
| 956 | 956 | .vector_store_elem => { |
| 957 | const o = inst_datas[inst].vector_store_elem; | |
| 957 | const o = inst_datas[@intFromEnum(inst)].vector_store_elem; | |
| 958 | 958 | const extra = a.air.extraData(Air.Bin, o.payload).data; |
| 959 | 959 | return analyzeOperands(a, pass, data, inst, .{ o.vector_ptr, extra.lhs, extra.rhs }); |
| 960 | 960 | }, |
| ... | ... | @@ -1029,7 +1029,7 @@ fn analyzeInst( |
| 1029 | 1029 | .c_va_copy, |
| 1030 | 1030 | .abs, |
| 1031 | 1031 | => { |
| 1032 | const o = inst_datas[inst].ty_op; | |
| 1032 | const o = inst_datas[@intFromEnum(inst)].ty_op; | |
| 1033 | 1033 | return analyzeOperands(a, pass, data, inst, .{ o.operand, .none, .none }); |
| 1034 | 1034 | }, |
| 1035 | 1035 | |
| ... | ... | @@ -1065,14 +1065,14 @@ fn analyzeInst( |
| 1065 | 1065 | .set_err_return_trace, |
| 1066 | 1066 | .c_va_end, |
| 1067 | 1067 | => { |
| 1068 | const operand = inst_datas[inst].un_op; | |
| 1068 | const operand = inst_datas[@intFromEnum(inst)].un_op; | |
| 1069 | 1069 | return analyzeOperands(a, pass, data, inst, .{ operand, .none, .none }); |
| 1070 | 1070 | }, |
| 1071 | 1071 | |
| 1072 | 1072 | .ret, |
| 1073 | 1073 | .ret_load, |
| 1074 | 1074 | => { |
| 1075 | const operand = inst_datas[inst].un_op; | |
| 1075 | const operand = inst_datas[@intFromEnum(inst)].un_op; | |
| 1076 | 1076 | return analyzeFuncEnd(a, pass, data, inst, .{ operand, .none, .none }); |
| 1077 | 1077 | }, |
| 1078 | 1078 | |
| ... | ... | @@ -1086,7 +1086,7 @@ fn analyzeInst( |
| 1086 | 1086 | .slice_elem_ptr, |
| 1087 | 1087 | .slice, |
| 1088 | 1088 | => { |
| 1089 | const ty_pl = inst_datas[inst].ty_pl; | |
| 1089 | const ty_pl = inst_datas[@intFromEnum(inst)].ty_pl; | |
| 1090 | 1090 | const extra = a.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1091 | 1091 | return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, .none }); |
| 1092 | 1092 | }, |
| ... | ... | @@ -1094,17 +1094,17 @@ fn analyzeInst( |
| 1094 | 1094 | .dbg_var_ptr, |
| 1095 | 1095 | .dbg_var_val, |
| 1096 | 1096 | => { |
| 1097 | const operand = inst_datas[inst].pl_op.operand; | |
| 1097 | const operand = inst_datas[@intFromEnum(inst)].pl_op.operand; | |
| 1098 | 1098 | return analyzeOperands(a, pass, data, inst, .{ operand, .none, .none }); |
| 1099 | 1099 | }, |
| 1100 | 1100 | |
| 1101 | 1101 | .prefetch => { |
| 1102 | const prefetch = inst_datas[inst].prefetch; | |
| 1102 | const prefetch = inst_datas[@intFromEnum(inst)].prefetch; | |
| 1103 | 1103 | return analyzeOperands(a, pass, data, inst, .{ prefetch.ptr, .none, .none }); |
| 1104 | 1104 | }, |
| 1105 | 1105 | |
| 1106 | 1106 | .call, .call_always_tail, .call_never_tail, .call_never_inline => { |
| 1107 | const inst_data = inst_datas[inst].pl_op; | |
| 1107 | const inst_data = inst_datas[@intFromEnum(inst)].pl_op; | |
| 1108 | 1108 | const callee = inst_data.operand; |
| 1109 | 1109 | const extra = a.air.extraData(Air.Call, inst_data.payload); |
| 1110 | 1110 | const args = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra.end..][0..extra.data.args_len])); |
| ... | ... | @@ -1126,25 +1126,25 @@ fn analyzeInst( |
| 1126 | 1126 | return big.finish(); |
| 1127 | 1127 | }, |
| 1128 | 1128 | .select => { |
| 1129 | const pl_op = inst_datas[inst].pl_op; | |
| 1129 | const pl_op = inst_datas[@intFromEnum(inst)].pl_op; | |
| 1130 | 1130 | const extra = a.air.extraData(Air.Bin, pl_op.payload).data; |
| 1131 | 1131 | return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, extra.lhs, extra.rhs }); |
| 1132 | 1132 | }, |
| 1133 | 1133 | .shuffle => { |
| 1134 | const extra = a.air.extraData(Air.Shuffle, inst_datas[inst].ty_pl.payload).data; | |
| 1134 | const extra = a.air.extraData(Air.Shuffle, inst_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 1135 | 1135 | return analyzeOperands(a, pass, data, inst, .{ extra.a, extra.b, .none }); |
| 1136 | 1136 | }, |
| 1137 | 1137 | .reduce, .reduce_optimized => { |
| 1138 | const reduce = inst_datas[inst].reduce; | |
| 1138 | const reduce = inst_datas[@intFromEnum(inst)].reduce; | |
| 1139 | 1139 | return analyzeOperands(a, pass, data, inst, .{ reduce.operand, .none, .none }); |
| 1140 | 1140 | }, |
| 1141 | 1141 | .cmp_vector, .cmp_vector_optimized => { |
| 1142 | const extra = a.air.extraData(Air.VectorCmp, inst_datas[inst].ty_pl.payload).data; | |
| 1142 | const extra = a.air.extraData(Air.VectorCmp, inst_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 1143 | 1143 | return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, .none }); |
| 1144 | 1144 | }, |
| 1145 | 1145 | .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(); | |
| 1148 | 1148 | const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip))); |
| 1149 | 1149 | const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[ty_pl.payload..][0..len])); |
| 1150 | 1150 | |
| ... | ... | @@ -1164,32 +1164,32 @@ fn analyzeInst( |
| 1164 | 1164 | return big.finish(); |
| 1165 | 1165 | }, |
| 1166 | 1166 | .union_init => { |
| 1167 | const extra = a.air.extraData(Air.UnionInit, inst_datas[inst].ty_pl.payload).data; | |
| 1167 | const extra = a.air.extraData(Air.UnionInit, inst_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 1168 | 1168 | return analyzeOperands(a, pass, data, inst, .{ extra.init, .none, .none }); |
| 1169 | 1169 | }, |
| 1170 | 1170 | .struct_field_ptr, .struct_field_val => { |
| 1171 | const extra = a.air.extraData(Air.StructField, inst_datas[inst].ty_pl.payload).data; | |
| 1171 | const extra = a.air.extraData(Air.StructField, inst_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 1172 | 1172 | return analyzeOperands(a, pass, data, inst, .{ extra.struct_operand, .none, .none }); |
| 1173 | 1173 | }, |
| 1174 | 1174 | .field_parent_ptr => { |
| 1175 | const extra = a.air.extraData(Air.FieldParentPtr, inst_datas[inst].ty_pl.payload).data; | |
| 1175 | const extra = a.air.extraData(Air.FieldParentPtr, inst_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 1176 | 1176 | return analyzeOperands(a, pass, data, inst, .{ extra.field_ptr, .none, .none }); |
| 1177 | 1177 | }, |
| 1178 | 1178 | .cmpxchg_strong, .cmpxchg_weak => { |
| 1179 | const extra = a.air.extraData(Air.Cmpxchg, inst_datas[inst].ty_pl.payload).data; | |
| 1179 | const extra = a.air.extraData(Air.Cmpxchg, inst_datas[@intFromEnum(inst)].ty_pl.payload).data; | |
| 1180 | 1180 | return analyzeOperands(a, pass, data, inst, .{ extra.ptr, extra.expected_value, extra.new_value }); |
| 1181 | 1181 | }, |
| 1182 | 1182 | .mul_add => { |
| 1183 | const pl_op = inst_datas[inst].pl_op; | |
| 1183 | const pl_op = inst_datas[@intFromEnum(inst)].pl_op; | |
| 1184 | 1184 | const extra = a.air.extraData(Air.Bin, pl_op.payload).data; |
| 1185 | 1185 | return analyzeOperands(a, pass, data, inst, .{ extra.lhs, extra.rhs, pl_op.operand }); |
| 1186 | 1186 | }, |
| 1187 | 1187 | .atomic_load => { |
| 1188 | const ptr = inst_datas[inst].atomic_load.ptr; | |
| 1188 | const ptr = inst_datas[@intFromEnum(inst)].atomic_load.ptr; | |
| 1189 | 1189 | return analyzeOperands(a, pass, data, inst, .{ ptr, .none, .none }); |
| 1190 | 1190 | }, |
| 1191 | 1191 | .atomic_rmw => { |
| 1192 | const pl_op = inst_datas[inst].pl_op; | |
| 1192 | const pl_op = inst_datas[@intFromEnum(inst)].pl_op; | |
| 1193 | 1193 | const extra = a.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 1194 | 1194 | return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, extra.operand, .none }); |
| 1195 | 1195 | }, |
| ... | ... | @@ -1197,7 +1197,7 @@ fn analyzeInst( |
| 1197 | 1197 | .br => return analyzeInstBr(a, pass, data, inst), |
| 1198 | 1198 | |
| 1199 | 1199 | .assembly => { |
| 1200 | const extra = a.air.extraData(Air.Asm, inst_datas[inst].ty_pl.payload); | |
| 1200 | const extra = a.air.extraData(Air.Asm, inst_datas[@intFromEnum(inst)].ty_pl.payload); | |
| 1201 | 1201 | var extra_i: usize = extra.end; |
| 1202 | 1202 | const outputs = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra[extra_i..][0..extra.data.outputs_len])); |
| 1203 | 1203 | extra_i += outputs.len; |
| ... | ... | @@ -1246,7 +1246,7 @@ fn analyzeInst( |
| 1246 | 1246 | .switch_br => return analyzeInstSwitchBr(a, pass, data, inst), |
| 1247 | 1247 | |
| 1248 | 1248 | .wasm_memory_grow => { |
| 1249 | const pl_op = inst_datas[inst].pl_op; | |
| 1249 | const pl_op = inst_datas[@intFromEnum(inst)].pl_op; | |
| 1250 | 1250 | return analyzeOperands(a, pass, data, inst, .{ pl_op.operand, .none, .none }); |
| 1251 | 1251 | }, |
| 1252 | 1252 | } |
| ... | ... | @@ -1270,20 +1270,20 @@ fn analyzeOperands( |
| 1270 | 1270 | _ = data.live_set.remove(inst); |
| 1271 | 1271 | |
| 1272 | 1272 | for (operands) |op_ref| { |
| 1273 | const operand = Air.refToIndexAllowNone(op_ref) orelse continue; | |
| 1273 | const operand = op_ref.toIndexAllowNone() orelse continue; | |
| 1274 | 1274 | _ = try data.live_set.put(gpa, operand, {}); |
| 1275 | 1275 | } |
| 1276 | 1276 | }, |
| 1277 | 1277 | |
| 1278 | 1278 | .main_analysis => { |
| 1279 | const usize_index = (inst * bpi) / @bitSizeOf(usize); | |
| 1279 | const usize_index = (@intFromEnum(inst) * bpi) / @bitSizeOf(usize); | |
| 1280 | 1280 | |
| 1281 | 1281 | // This logic must synchronize with `will_die_immediately` in `AnalyzeBigOperands.init`. |
| 1282 | 1282 | const immediate_death = if (data.live_set.remove(inst)) blk: { |
| 1283 | log.debug("[{}] %{}: removed from live set", .{ pass, inst }); | |
| 1283 | log.debug("[{}] %{}: removed from live set", .{ pass, @intFromEnum(inst) }); | |
| 1284 | 1284 | break :blk false; |
| 1285 | 1285 | } else blk: { |
| 1286 | log.debug("[{}] %{}: immediate death", .{ pass, inst }); | |
| 1286 | log.debug("[{}] %{}: immediate death", .{ pass, @intFromEnum(inst) }); | |
| 1287 | 1287 | break :blk true; |
| 1288 | 1288 | }; |
| 1289 | 1289 | |
| ... | ... | @@ -1299,19 +1299,19 @@ fn analyzeOperands( |
| 1299 | 1299 | while (i > 0) { |
| 1300 | 1300 | i -= 1; |
| 1301 | 1301 | const op_ref = operands[i]; |
| 1302 | const operand = Air.refToIndexAllowNone(op_ref) orelse continue; | |
| 1302 | const operand = op_ref.toIndexAllowNone() orelse continue; | |
| 1303 | 1303 | |
| 1304 | 1304 | const mask = @as(Bpi, 1) << @as(OperandInt, @intCast(i)); |
| 1305 | 1305 | |
| 1306 | 1306 | if ((try data.live_set.fetchPut(gpa, operand, {})) == null) { |
| 1307 | log.debug("[{}] %{}: added %{} to live set (operand dies here)", .{ pass, inst, operand }); | |
| 1307 | log.debug("[{}] %{}: added %{} to live set (operand dies here)", .{ pass, @intFromEnum(inst), operand }); | |
| 1308 | 1308 | tomb_bits |= mask; |
| 1309 | 1309 | } |
| 1310 | 1310 | } |
| 1311 | 1311 | } |
| 1312 | 1312 | |
| 1313 | 1313 | a.tomb_bits[usize_index] |= @as(usize, tomb_bits) << |
| 1314 | @as(Log2Int(usize), @intCast((inst % (@bitSizeOf(usize) / bpi)) * bpi)); | |
| 1314 | @as(Log2Int(usize), @intCast((@intFromEnum(inst) % (@bitSizeOf(usize) / bpi)) * bpi)); | |
| 1315 | 1315 | }, |
| 1316 | 1316 | } |
| 1317 | 1317 | } |
| ... | ... | @@ -1346,7 +1346,7 @@ fn analyzeInstBr( |
| 1346 | 1346 | inst: Air.Inst.Index, |
| 1347 | 1347 | ) !void { |
| 1348 | 1348 | const inst_datas = a.air.instructions.items(.data); |
| 1349 | const br = inst_datas[inst].br; | |
| 1349 | const br = inst_datas[@intFromEnum(inst)].br; | |
| 1350 | 1350 | const gpa = a.gpa; |
| 1351 | 1351 | |
| 1352 | 1352 | switch (pass) { |
| ... | ... | @@ -1373,9 +1373,9 @@ fn analyzeInstBlock( |
| 1373 | 1373 | inst: Air.Inst.Index, |
| 1374 | 1374 | ) !void { |
| 1375 | 1375 | const inst_datas = a.air.instructions.items(.data); |
| 1376 | const ty_pl = inst_datas[inst].ty_pl; | |
| 1376 | const ty_pl = inst_datas[@intFromEnum(inst)].ty_pl; | |
| 1377 | 1377 | const extra = a.air.extraData(Air.Block, ty_pl.payload); |
| 1378 | const body = a.air.extra[extra.end..][0..extra.data.body_len]; | |
| 1378 | const body: []const Air.Inst.Index = @ptrCast(a.air.extra[extra.end..][0..extra.data.body_len]); | |
| 1379 | 1379 | |
| 1380 | 1380 | const gpa = a.gpa; |
| 1381 | 1381 | |
| ... | ... | @@ -1405,7 +1405,7 @@ fn analyzeInstBlock( |
| 1405 | 1405 | |
| 1406 | 1406 | // If the block is noreturn, block deaths not only aren't useful, they're impossible to |
| 1407 | 1407 | // find: there could be more stuff alive after the block than before it! |
| 1408 | if (!a.intern_pool.isNoReturn(a.air.getRefType(ty_pl.ty).ip_index)) { | |
| 1408 | if (!a.intern_pool.isNoReturn(ty_pl.ty.toType().ip_index)) { | |
| 1409 | 1409 | // The block kills the difference in the live sets |
| 1410 | 1410 | const block_scope = data.block_scopes.get(inst).?; |
| 1411 | 1411 | const num_deaths = data.live_set.count() - block_scope.live_set.count(); |
| ... | ... | @@ -1421,7 +1421,7 @@ fn analyzeInstBlock( |
| 1421 | 1421 | const alive = key.*; |
| 1422 | 1422 | if (!block_scope.live_set.contains(alive)) { |
| 1423 | 1423 | // Dies in block |
| 1424 | a.extra.appendAssumeCapacity(alive); | |
| 1424 | a.extra.appendAssumeCapacity(@intFromEnum(alive)); | |
| 1425 | 1425 | measured_num += 1; |
| 1426 | 1426 | } |
| 1427 | 1427 | } |
| ... | ... | @@ -1430,7 +1430,7 @@ fn analyzeInstBlock( |
| 1430 | 1430 | log.debug("[{}] %{}: block deaths are {}", .{ |
| 1431 | 1431 | pass, |
| 1432 | 1432 | inst, |
| 1433 | fmtInstList(a.extra.items[extra_index + 1 ..][0..num_deaths]), | |
| 1433 | fmtInstList(@ptrCast(a.extra.items[extra_index + 1 ..][0..num_deaths])), | |
| 1434 | 1434 | }); |
| 1435 | 1435 | } |
| 1436 | 1436 | }, |
| ... | ... | @@ -1444,8 +1444,8 @@ fn analyzeInstLoop( |
| 1444 | 1444 | inst: Air.Inst.Index, |
| 1445 | 1445 | ) !void { |
| 1446 | 1446 | 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]); | |
| 1449 | 1449 | const gpa = a.gpa; |
| 1450 | 1450 | |
| 1451 | 1451 | try analyzeOperands(a, pass, data, inst, .{ .none, .none, .none }); |
| ... | ... | @@ -1469,7 +1469,7 @@ fn analyzeInstLoop( |
| 1469 | 1469 | var it = data.breaks.keyIterator(); |
| 1470 | 1470 | while (it.next()) |key| { |
| 1471 | 1471 | const block_inst = key.*; |
| 1472 | a.extra.appendAssumeCapacity(block_inst); | |
| 1472 | a.extra.appendAssumeCapacity(@intFromEnum(block_inst)); | |
| 1473 | 1473 | } |
| 1474 | 1474 | log.debug("[{}] %{}: includes breaks to {}", .{ pass, inst, fmtInstSet(&data.breaks) }); |
| 1475 | 1475 | |
| ... | ... | @@ -1481,7 +1481,7 @@ fn analyzeInstLoop( |
| 1481 | 1481 | it = data.live_set.keyIterator(); |
| 1482 | 1482 | while (it.next()) |key| { |
| 1483 | 1483 | const alive = key.*; |
| 1484 | a.extra.appendAssumeCapacity(alive); | |
| 1484 | a.extra.appendAssumeCapacity(@intFromEnum(alive)); | |
| 1485 | 1485 | } |
| 1486 | 1486 | log.debug("[{}] %{}: maintain liveness of {}", .{ pass, inst, fmtInstSet(&data.live_set) }); |
| 1487 | 1487 | |
| ... | ... | @@ -1506,15 +1506,15 @@ fn analyzeInstLoop( |
| 1506 | 1506 | const extra_idx = a.special.fetchRemove(inst).?.value; // remove because this data does not exist after analysis |
| 1507 | 1507 | |
| 1508 | 1508 | const num_breaks = data.old_extra.items[extra_idx]; |
| 1509 | const breaks = data.old_extra.items[extra_idx + 1 ..][0..num_breaks]; | |
| 1509 | const breaks: []const Air.Inst.Index = @ptrCast(data.old_extra.items[extra_idx + 1 ..][0..num_breaks]); | |
| 1510 | 1510 | |
| 1511 | 1511 | const num_loop_live = data.old_extra.items[extra_idx + num_breaks + 1]; |
| 1512 | const loop_live = data.old_extra.items[extra_idx + num_breaks + 2 ..][0..num_loop_live]; | |
| 1512 | const loop_live: []const Air.Inst.Index = @ptrCast(data.old_extra.items[extra_idx + num_breaks + 2 ..][0..num_loop_live]); | |
| 1513 | 1513 | |
| 1514 | 1514 | // This is necessarily not in the same control flow branch, because loops are noreturn |
| 1515 | 1515 | data.live_set.clearRetainingCapacity(); |
| 1516 | 1516 | |
| 1517 | try data.live_set.ensureUnusedCapacity(gpa, @as(u32, @intCast(loop_live.len))); | |
| 1517 | try data.live_set.ensureUnusedCapacity(gpa, @intCast(loop_live.len)); | |
| 1518 | 1518 | for (loop_live) |alive| { |
| 1519 | 1519 | data.live_set.putAssumeCapacity(alive, {}); |
| 1520 | 1520 | } |
| ... | ... | @@ -1551,25 +1551,25 @@ fn analyzeInstCondBr( |
| 1551 | 1551 | const gpa = a.gpa; |
| 1552 | 1552 | |
| 1553 | 1553 | 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), | |
| 1557 | 1557 | }; |
| 1558 | 1558 | |
| 1559 | 1559 | const condition = switch (inst_type) { |
| 1560 | .cond_br, .@"try" => inst_datas[inst].pl_op.operand, | |
| 1560 | .cond_br, .@"try" => inst_datas[@intFromEnum(inst)].pl_op.operand, | |
| 1561 | 1561 | .try_ptr => extra.data.ptr, |
| 1562 | 1562 | }; |
| 1563 | 1563 | |
| 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 | |
| 1567 | 1567 | }; |
| 1568 | 1568 | |
| 1569 | const else_body = switch (inst_type) { | |
| 1569 | const else_body: []const Air.Inst.Index = @ptrCast(switch (inst_type) { | |
| 1570 | 1570 | .cond_br => a.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len], |
| 1571 | 1571 | .@"try", .try_ptr => a.air.extra[extra.end..][0..extra.data.body_len], |
| 1572 | }; | |
| 1572 | }); | |
| 1573 | 1573 | |
| 1574 | 1574 | switch (pass) { |
| 1575 | 1575 | .loop_analysis => { |
| ... | ... | @@ -1645,8 +1645,8 @@ fn analyzeInstCondBr( |
| 1645 | 1645 | .then_death_count = then_death_count, |
| 1646 | 1646 | .else_death_count = else_death_count, |
| 1647 | 1647 | }); |
| 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)); | |
| 1650 | 1650 | try a.special.put(gpa, inst, extra_index); |
| 1651 | 1651 | }, |
| 1652 | 1652 | } |
| ... | ... | @@ -1661,7 +1661,7 @@ fn analyzeInstSwitchBr( |
| 1661 | 1661 | inst: Air.Inst.Index, |
| 1662 | 1662 | ) !void { |
| 1663 | 1663 | const inst_datas = a.air.instructions.items(.data); |
| 1664 | const pl_op = inst_datas[inst].pl_op; | |
| 1664 | const pl_op = inst_datas[@intFromEnum(inst)].pl_op; | |
| 1665 | 1665 | const condition = pl_op.operand; |
| 1666 | 1666 | const switch_br = a.air.extraData(Air.SwitchBr, pl_op.payload); |
| 1667 | 1667 | const gpa = a.gpa; |
| ... | ... | @@ -1672,12 +1672,12 @@ fn analyzeInstSwitchBr( |
| 1672 | 1672 | var air_extra_index: usize = switch_br.end; |
| 1673 | 1673 | for (0..ncases) |_| { |
| 1674 | 1674 | const case = a.air.extraData(Air.SwitchBr.Case, air_extra_index); |
| 1675 | const case_body = a.air.extra[case.end + case.data.items_len ..][0..case.data.body_len]; | |
| 1675 | const case_body: []const Air.Inst.Index = @ptrCast(a.air.extra[case.end + case.data.items_len ..][0..case.data.body_len]); | |
| 1676 | 1676 | air_extra_index = case.end + case.data.items_len + case_body.len; |
| 1677 | 1677 | try analyzeBody(a, pass, data, case_body); |
| 1678 | 1678 | } |
| 1679 | 1679 | { // else |
| 1680 | const else_body = a.air.extra[air_extra_index..][0..switch_br.data.else_body_len]; | |
| 1680 | const else_body: []const Air.Inst.Index = @ptrCast(a.air.extra[air_extra_index..][0..switch_br.data.else_body_len]); | |
| 1681 | 1681 | try analyzeBody(a, pass, data, else_body); |
| 1682 | 1682 | } |
| 1683 | 1683 | }, |
| ... | ... | @@ -1698,13 +1698,13 @@ fn analyzeInstSwitchBr( |
| 1698 | 1698 | var air_extra_index: usize = switch_br.end; |
| 1699 | 1699 | for (case_live_sets[0..ncases]) |*live_set| { |
| 1700 | 1700 | const case = a.air.extraData(Air.SwitchBr.Case, air_extra_index); |
| 1701 | const case_body = a.air.extra[case.end + case.data.items_len ..][0..case.data.body_len]; | |
| 1701 | const case_body: []const Air.Inst.Index = @ptrCast(a.air.extra[case.end + case.data.items_len ..][0..case.data.body_len]); | |
| 1702 | 1702 | air_extra_index = case.end + case.data.items_len + case_body.len; |
| 1703 | 1703 | try analyzeBody(a, pass, data, case_body); |
| 1704 | 1704 | live_set.* = data.live_set.move(); |
| 1705 | 1705 | } |
| 1706 | 1706 | { // else |
| 1707 | const else_body = a.air.extra[air_extra_index..][0..switch_br.data.else_body_len]; | |
| 1707 | const else_body: []const Air.Inst.Index = @ptrCast(a.air.extra[air_extra_index..][0..switch_br.data.else_body_len]); | |
| 1708 | 1708 | try analyzeBody(a, pass, data, else_body); |
| 1709 | 1709 | case_live_sets[ncases] = data.live_set.move(); |
| 1710 | 1710 | } |
| ... | ... | @@ -1757,10 +1757,10 @@ fn analyzeInstSwitchBr( |
| 1757 | 1757 | const num = @as(u32, @intCast(mirrored.items.len)); |
| 1758 | 1758 | try a.extra.ensureUnusedCapacity(gpa, num + 1); |
| 1759 | 1759 | a.extra.appendAssumeCapacity(num); |
| 1760 | a.extra.appendSliceAssumeCapacity(mirrored.items); | |
| 1760 | a.extra.appendSliceAssumeCapacity(@ptrCast(mirrored.items)); | |
| 1761 | 1761 | } |
| 1762 | 1762 | try a.extra.ensureUnusedCapacity(gpa, else_death_count); |
| 1763 | a.extra.appendSliceAssumeCapacity(mirrored_deaths[ncases].items); | |
| 1763 | a.extra.appendSliceAssumeCapacity(@ptrCast(mirrored_deaths[ncases].items)); | |
| 1764 | 1764 | try a.special.put(gpa, inst, extra_index); |
| 1765 | 1765 | }, |
| 1766 | 1766 | } |
| ... | ... | @@ -1826,7 +1826,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type { |
| 1826 | 1826 | return; |
| 1827 | 1827 | } |
| 1828 | 1828 | |
| 1829 | const operand = Air.refToIndex(op_ref) orelse return; | |
| 1829 | const operand = op_ref.toIndex() orelse return; | |
| 1830 | 1830 | |
| 1831 | 1831 | // If our result is unused and the instruction doesn't need to be lowered, backends will |
| 1832 | 1832 | // skip the lowering of this instruction, so we don't want to record uses of operands. |
src/Liveness/Verify.zig+42-42| ... | ... | @@ -37,7 +37,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 37 | 37 | continue; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | switch (tag[inst]) { | |
| 40 | switch (tag[@intFromEnum(inst)]) { | |
| 41 | 41 | // no operands |
| 42 | 42 | .arg, |
| 43 | 43 | .alloc, |
| ... | ... | @@ -112,7 +112,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 112 | 112 | .c_va_copy, |
| 113 | 113 | .abs, |
| 114 | 114 | => { |
| 115 | const ty_op = data[inst].ty_op; | |
| 115 | const ty_op = data[@intFromEnum(inst)].ty_op; | |
| 116 | 116 | try self.verifyInstOperands(inst, .{ ty_op.operand, .none, .none }); |
| 117 | 117 | }, |
| 118 | 118 | .is_null, |
| ... | ... | @@ -147,13 +147,13 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 147 | 147 | .set_err_return_trace, |
| 148 | 148 | .c_va_end, |
| 149 | 149 | => { |
| 150 | const un_op = data[inst].un_op; | |
| 150 | const un_op = data[@intFromEnum(inst)].un_op; | |
| 151 | 151 | try self.verifyInstOperands(inst, .{ un_op, .none, .none }); |
| 152 | 152 | }, |
| 153 | 153 | .ret, |
| 154 | 154 | .ret_load, |
| 155 | 155 | => { |
| 156 | const un_op = data[inst].un_op; | |
| 156 | const un_op = data[@intFromEnum(inst)].un_op; | |
| 157 | 157 | try self.verifyInstOperands(inst, .{ un_op, .none, .none }); |
| 158 | 158 | // This instruction terminates the function, so everything should be dead |
| 159 | 159 | if (self.live.count() > 0) return invalid("%{}: instructions still alive", .{inst}); |
| ... | ... | @@ -162,36 +162,36 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 162 | 162 | .dbg_var_val, |
| 163 | 163 | .wasm_memory_grow, |
| 164 | 164 | => { |
| 165 | const pl_op = data[inst].pl_op; | |
| 165 | const pl_op = data[@intFromEnum(inst)].pl_op; | |
| 166 | 166 | try self.verifyInstOperands(inst, .{ pl_op.operand, .none, .none }); |
| 167 | 167 | }, |
| 168 | 168 | .prefetch => { |
| 169 | const prefetch = data[inst].prefetch; | |
| 169 | const prefetch = data[@intFromEnum(inst)].prefetch; | |
| 170 | 170 | try self.verifyInstOperands(inst, .{ prefetch.ptr, .none, .none }); |
| 171 | 171 | }, |
| 172 | 172 | .reduce, |
| 173 | 173 | .reduce_optimized, |
| 174 | 174 | => { |
| 175 | const reduce = data[inst].reduce; | |
| 175 | const reduce = data[@intFromEnum(inst)].reduce; | |
| 176 | 176 | try self.verifyInstOperands(inst, .{ reduce.operand, .none, .none }); |
| 177 | 177 | }, |
| 178 | 178 | .union_init => { |
| 179 | const ty_pl = data[inst].ty_pl; | |
| 179 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 180 | 180 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 181 | 181 | try self.verifyInstOperands(inst, .{ extra.init, .none, .none }); |
| 182 | 182 | }, |
| 183 | 183 | .struct_field_ptr, .struct_field_val => { |
| 184 | const ty_pl = data[inst].ty_pl; | |
| 184 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 185 | 185 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 186 | 186 | try self.verifyInstOperands(inst, .{ extra.struct_operand, .none, .none }); |
| 187 | 187 | }, |
| 188 | 188 | .field_parent_ptr => { |
| 189 | const ty_pl = data[inst].ty_pl; | |
| 189 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 190 | 190 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 191 | 191 | try self.verifyInstOperands(inst, .{ extra.field_ptr, .none, .none }); |
| 192 | 192 | }, |
| 193 | 193 | .atomic_load => { |
| 194 | const atomic_load = data[inst].atomic_load; | |
| 194 | const atomic_load = data[@intFromEnum(inst)].atomic_load; | |
| 195 | 195 | try self.verifyInstOperands(inst, .{ atomic_load.ptr, .none, .none }); |
| 196 | 196 | }, |
| 197 | 197 | |
| ... | ... | @@ -261,7 +261,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 261 | 261 | .memset_safe, |
| 262 | 262 | .memcpy, |
| 263 | 263 | => { |
| 264 | const bin_op = data[inst].bin_op; | |
| 264 | const bin_op = data[@intFromEnum(inst)].bin_op; | |
| 265 | 265 | try self.verifyInstOperands(inst, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 266 | 266 | }, |
| 267 | 267 | .add_with_overflow, |
| ... | ... | @@ -274,56 +274,56 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 274 | 274 | .slice_elem_ptr, |
| 275 | 275 | .slice, |
| 276 | 276 | => { |
| 277 | const ty_pl = data[inst].ty_pl; | |
| 277 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 278 | 278 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 279 | 279 | try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, .none }); |
| 280 | 280 | }, |
| 281 | 281 | .shuffle => { |
| 282 | const ty_pl = data[inst].ty_pl; | |
| 282 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 283 | 283 | const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data; |
| 284 | 284 | try self.verifyInstOperands(inst, .{ extra.a, extra.b, .none }); |
| 285 | 285 | }, |
| 286 | 286 | .cmp_vector, |
| 287 | 287 | .cmp_vector_optimized, |
| 288 | 288 | => { |
| 289 | const ty_pl = data[inst].ty_pl; | |
| 289 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 290 | 290 | const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data; |
| 291 | 291 | try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, .none }); |
| 292 | 292 | }, |
| 293 | 293 | .atomic_rmw => { |
| 294 | const pl_op = data[inst].pl_op; | |
| 294 | const pl_op = data[@intFromEnum(inst)].pl_op; | |
| 295 | 295 | const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 296 | 296 | try self.verifyInstOperands(inst, .{ pl_op.operand, extra.operand, .none }); |
| 297 | 297 | }, |
| 298 | 298 | |
| 299 | 299 | // ternary |
| 300 | 300 | .select => { |
| 301 | const pl_op = data[inst].pl_op; | |
| 301 | const pl_op = data[@intFromEnum(inst)].pl_op; | |
| 302 | 302 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 303 | 303 | try self.verifyInstOperands(inst, .{ pl_op.operand, extra.lhs, extra.rhs }); |
| 304 | 304 | }, |
| 305 | 305 | .mul_add => { |
| 306 | const pl_op = data[inst].pl_op; | |
| 306 | const pl_op = data[@intFromEnum(inst)].pl_op; | |
| 307 | 307 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 308 | 308 | try self.verifyInstOperands(inst, .{ extra.lhs, extra.rhs, pl_op.operand }); |
| 309 | 309 | }, |
| 310 | 310 | .vector_store_elem => { |
| 311 | const vector_store_elem = data[inst].vector_store_elem; | |
| 311 | const vector_store_elem = data[@intFromEnum(inst)].vector_store_elem; | |
| 312 | 312 | const extra = self.air.extraData(Air.Bin, vector_store_elem.payload).data; |
| 313 | 313 | try self.verifyInstOperands(inst, .{ vector_store_elem.vector_ptr, extra.lhs, extra.rhs }); |
| 314 | 314 | }, |
| 315 | 315 | .cmpxchg_strong, |
| 316 | 316 | .cmpxchg_weak, |
| 317 | 317 | => { |
| 318 | const ty_pl = data[inst].ty_pl; | |
| 318 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 319 | 319 | const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 320 | 320 | try self.verifyInstOperands(inst, .{ extra.ptr, extra.expected_value, extra.new_value }); |
| 321 | 321 | }, |
| 322 | 322 | |
| 323 | 323 | // big tombs |
| 324 | 324 | .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(); | |
| 327 | 327 | const len = @as(usize, @intCast(aggregate_ty.arrayLenIp(ip))); |
| 328 | 328 | const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len])); |
| 329 | 329 | |
| ... | ... | @@ -334,7 +334,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 334 | 334 | try self.verifyInst(inst); |
| 335 | 335 | }, |
| 336 | 336 | .call, .call_always_tail, .call_never_tail, .call_never_inline => { |
| 337 | const pl_op = data[inst].pl_op; | |
| 337 | const pl_op = data[@intFromEnum(inst)].pl_op; | |
| 338 | 338 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 339 | 339 | const args = @as( |
| 340 | 340 | []const Air.Inst.Ref, |
| ... | ... | @@ -349,7 +349,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 349 | 349 | try self.verifyInst(inst); |
| 350 | 350 | }, |
| 351 | 351 | .assembly => { |
| 352 | const ty_pl = data[inst].ty_pl; | |
| 352 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 353 | 353 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); |
| 354 | 354 | var extra_i = extra.end; |
| 355 | 355 | const outputs = @as( |
| ... | ... | @@ -377,9 +377,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 377 | 377 | |
| 378 | 378 | // control flow |
| 379 | 379 | .@"try" => { |
| 380 | const pl_op = data[inst].pl_op; | |
| 380 | const pl_op = data[@intFromEnum(inst)].pl_op; | |
| 381 | 381 | const extra = self.air.extraData(Air.Try, pl_op.payload); |
| 382 | const try_body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 382 | const try_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 383 | 383 | |
| 384 | 384 | const cond_br_liveness = self.liveness.getCondBr(inst); |
| 385 | 385 | |
| ... | ... | @@ -399,9 +399,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 399 | 399 | try self.verifyInst(inst); |
| 400 | 400 | }, |
| 401 | 401 | .try_ptr => { |
| 402 | const ty_pl = data[inst].ty_pl; | |
| 402 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 403 | 403 | const extra = self.air.extraData(Air.TryPtr, ty_pl.payload); |
| 404 | const try_body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 404 | const try_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 405 | 405 | |
| 406 | 406 | const cond_br_liveness = self.liveness.getCondBr(inst); |
| 407 | 407 | |
| ... | ... | @@ -421,7 +421,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 421 | 421 | try self.verifyInst(inst); |
| 422 | 422 | }, |
| 423 | 423 | .br => { |
| 424 | const br = data[inst].br; | |
| 424 | const br = data[@intFromEnum(inst)].br; | |
| 425 | 425 | const gop = try self.blocks.getOrPut(self.gpa, br.block_inst); |
| 426 | 426 | |
| 427 | 427 | try self.verifyOperand(inst, br.operand, self.liveness.operandDies(inst, 0)); |
| ... | ... | @@ -433,10 +433,10 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 433 | 433 | try self.verifyInst(inst); |
| 434 | 434 | }, |
| 435 | 435 | .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(); | |
| 438 | 438 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 439 | const block_body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 439 | const block_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 440 | 440 | const block_liveness = self.liveness.getBlock(inst); |
| 441 | 441 | |
| 442 | 442 | var orig_live = try self.live.clone(self.gpa); |
| ... | ... | @@ -464,9 +464,9 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 464 | 464 | try self.verifyInstOperands(inst, .{ .none, .none, .none }); |
| 465 | 465 | }, |
| 466 | 466 | .loop => { |
| 467 | const ty_pl = data[inst].ty_pl; | |
| 467 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 468 | 468 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 469 | const loop_body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 469 | const loop_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 470 | 470 | |
| 471 | 471 | var live = try self.live.clone(self.gpa); |
| 472 | 472 | defer live.deinit(self.gpa); |
| ... | ... | @@ -479,10 +479,10 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 479 | 479 | try self.verifyInstOperands(inst, .{ .none, .none, .none }); |
| 480 | 480 | }, |
| 481 | 481 | .cond_br => { |
| 482 | const pl_op = data[inst].pl_op; | |
| 482 | const pl_op = data[@intFromEnum(inst)].pl_op; | |
| 483 | 483 | const extra = self.air.extraData(Air.CondBr, pl_op.payload); |
| 484 | const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len]; | |
| 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]); | |
| 486 | 486 | const cond_br_liveness = self.liveness.getCondBr(inst); |
| 487 | 487 | |
| 488 | 488 | try self.verifyOperand(inst, pl_op.operand, self.liveness.operandDies(inst, 0)); |
| ... | ... | @@ -502,7 +502,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 502 | 502 | try self.verifyInst(inst); |
| 503 | 503 | }, |
| 504 | 504 | .switch_br => { |
| 505 | const pl_op = data[inst].pl_op; | |
| 505 | const pl_op = data[@intFromEnum(inst)].pl_op; | |
| 506 | 506 | const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload); |
| 507 | 507 | var extra_index = switch_br.end; |
| 508 | 508 | var case_i: u32 = 0; |
| ... | ... | @@ -524,7 +524,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 524 | 524 | []const Air.Inst.Ref, |
| 525 | 525 | @ptrCast(self.air.extra[case.end..][0..case.data.items_len]), |
| 526 | 526 | ); |
| 527 | const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len]; | |
| 527 | const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]); | |
| 528 | 528 | extra_index = case.end + items.len + case_body.len; |
| 529 | 529 | |
| 530 | 530 | self.live.deinit(self.gpa); |
| ... | ... | @@ -534,7 +534,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 534 | 534 | try self.verifyBody(case_body); |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len]; | |
| 537 | const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]); | |
| 538 | 538 | if (else_body.len > 0) { |
| 539 | 539 | self.live.deinit(self.gpa); |
| 540 | 540 | self.live = try live.clone(self.gpa); |
| ... | ... | @@ -550,11 +550,11 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void { |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | fn verifyDeath(self: *Verify, inst: Air.Inst.Index, operand: Air.Inst.Index) Error!void { |
| 553 | try self.verifyOperand(inst, Air.indexToRef(operand), true); | |
| 553 | try self.verifyOperand(inst, operand.toRef(), true); | |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | fn verifyOperand(self: *Verify, inst: Air.Inst.Index, op_ref: Air.Inst.Ref, dies: bool) Error!void { |
| 557 | const operand = Air.refToIndexAllowNone(op_ref) orelse { | |
| 557 | const operand = op_ref.toIndexAllowNone() orelse { | |
| 558 | 558 | assert(!dies); |
| 559 | 559 | return; |
| 560 | 560 | }; |
src/Module.zig+4-4| ... | ... | @@ -4591,8 +4591,8 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato |
| 4591 | 4591 | gop.value_ptr.* = Air.internedToRef(opv.toIntern()); |
| 4592 | 4592 | continue; |
| 4593 | 4593 | } |
| 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(); | |
| 4596 | 4596 | inner_block.instructions.appendAssumeCapacity(arg_index); |
| 4597 | 4597 | sema.air_instructions.appendAssumeCapacity(.{ |
| 4598 | 4598 | .tag = .arg, |
| ... | ... | @@ -4626,7 +4626,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato |
| 4626 | 4626 | while (it.next()) |ptr_inst| { |
| 4627 | 4627 | // The lack of a resolve_inferred_alloc means that this instruction |
| 4628 | 4628 | // is unused so it just has to be a no-op. |
| 4629 | sema.air_instructions.set(ptr_inst.*, .{ | |
| 4629 | sema.air_instructions.set(@intFromEnum(ptr_inst.*), .{ | |
| 4630 | 4630 | .tag = .alloc, |
| 4631 | 4631 | .data = .{ .ty = Type.single_const_pointer_to_comptime_int }, |
| 4632 | 4632 | }); |
| ... | ... | @@ -4659,7 +4659,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato |
| 4659 | 4659 | const main_block_index = sema.addExtraAssumeCapacity(Air.Block{ |
| 4660 | 4660 | .body_len = @intCast(inner_block.instructions.items.len), |
| 4661 | 4661 | }); |
| 4662 | sema.air_extra.appendSliceAssumeCapacity(inner_block.instructions.items); | |
| 4662 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(inner_block.instructions.items)); | |
| 4663 | 4663 | sema.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)] = main_block_index; |
| 4664 | 4664 | |
| 4665 | 4665 | // Resolving inferred error sets is done *before* setting the function |
src/Sema.zig+195-195| ... | ... | @@ -741,7 +741,7 @@ pub const Block = struct { |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | pub fn addInst(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref { |
| 744 | return Air.indexToRef(try block.addInstAsIndex(inst)); | |
| 744 | return (try block.addInstAsIndex(inst)).toRef(); | |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | pub fn addInstAsIndex(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index { |
| ... | ... | @@ -751,7 +751,7 @@ pub const Block = struct { |
| 751 | 751 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); |
| 752 | 752 | try block.instructions.ensureUnusedCapacity(gpa, 1); |
| 753 | 753 | |
| 754 | const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len); | |
| 754 | const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); | |
| 755 | 755 | sema.air_instructions.appendAssumeCapacity(inst); |
| 756 | 756 | block.instructions.appendAssumeCapacity(result_index); |
| 757 | 757 | return result_index; |
| ... | ... | @@ -760,7 +760,7 @@ pub const Block = struct { |
| 760 | 760 | /// Insert an instruction into the block at `index`. Moves all following |
| 761 | 761 | /// instructions forward in the block to make room. Operation is O(N). |
| 762 | 762 | pub fn insertInst(block: *Block, index: Air.Inst.Index, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref { |
| 763 | return Air.indexToRef(try block.insertInstAsIndex(index, inst)); | |
| 763 | return (try block.insertInstAsIndex(index, inst)).toRef(); | |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | pub fn insertInstAsIndex(block: *Block, index: Air.Inst.Index, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index { |
| ... | ... | @@ -769,10 +769,10 @@ pub const Block = struct { |
| 769 | 769 | |
| 770 | 770 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); |
| 771 | 771 | |
| 772 | const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len); | |
| 772 | const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); | |
| 773 | 773 | sema.air_instructions.appendAssumeCapacity(inst); |
| 774 | 774 | |
| 775 | try block.instructions.insert(gpa, index, result_index); | |
| 775 | try block.instructions.insert(gpa, @intFromEnum(index), result_index); | |
| 776 | 776 | return result_index; |
| 777 | 777 | } |
| 778 | 778 | |
| ... | ... | @@ -935,7 +935,7 @@ pub fn analyzeBodyBreak( |
| 935 | 935 | else => |e| return e, |
| 936 | 936 | }; |
| 937 | 937 | if (block.instructions.items.len != 0 and |
| 938 | sema.isNoReturn(Air.indexToRef(block.instructions.items[block.instructions.items.len - 1]))) | |
| 938 | sema.isNoReturn(block.instructions.items[block.instructions.items.len - 1].toRef())) | |
| 939 | 939 | return null; |
| 940 | 940 | const break_data = sema.code.instructions.items(.data)[@intFromEnum(break_inst)].@"break"; |
| 941 | 941 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; |
| ... | ... | @@ -1638,7 +1638,7 @@ fn analyzeBodyInner( |
| 1638 | 1638 | // Comptime control flow populates the map, so we don't actually know |
| 1639 | 1639 | // if this is a post-hoc runtime block until we check the |
| 1640 | 1640 | // post_hoc_block map. |
| 1641 | const new_block_inst = Air.refToIndex(new_block_ref) orelse break :ph; | |
| 1641 | const new_block_inst = new_block_ref.toIndex() orelse break :ph; | |
| 1642 | 1642 | const labeled_block = sema.post_hoc_blocks.get(new_block_inst) orelse |
| 1643 | 1643 | break :ph; |
| 1644 | 1644 | |
| ... | ... | @@ -1817,7 +1817,7 @@ fn analyzeBodyInner( |
| 1817 | 1817 | if (sema.isNoReturn(air_inst)) { |
| 1818 | 1818 | // We're going to assume that the body itself is noreturn, so let's ensure that now |
| 1819 | 1819 | assert(block.instructions.items.len > 0); |
| 1820 | assert(sema.isNoReturn(Air.indexToRef(block.instructions.items[block.instructions.items.len - 1]))); | |
| 1820 | assert(sema.isNoReturn(block.instructions.items[block.instructions.items.len - 1].toRef())); | |
| 1821 | 1821 | break always_noreturn; |
| 1822 | 1822 | } |
| 1823 | 1823 | map.putAssumeCapacity(inst, air_inst); |
| ... | ... | @@ -2003,7 +2003,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { |
| 2003 | 2003 | const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) { |
| 2004 | 2004 | error.GenericPoison => unreachable, // this is a type, not a value |
| 2005 | 2005 | }; |
| 2006 | const operand_val = Air.refToInterned(operand_ref) orelse return .unknown; | |
| 2006 | const operand_val = operand_ref.toInterned() orelse return .unknown; | |
| 2007 | 2007 | if (operand_val == .generic_poison_type) { |
| 2008 | 2008 | // The pointer was generic poison - keep looking. |
| 2009 | 2009 | cur = un_node.operand; |
| ... | ... | @@ -2158,14 +2158,14 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val |
| 2158 | 2158 | |
| 2159 | 2159 | const air_tags = sema.air_instructions.items(.tag); |
| 2160 | 2160 | if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| { |
| 2161 | if (Air.refToInterned(inst)) |ip_index| { | |
| 2161 | if (inst.toInterned()) |ip_index| { | |
| 2162 | 2162 | const val = Value.fromInterned(ip_index); |
| 2163 | 2163 | if (val.getVariable(sema.mod) != null) return val; |
| 2164 | 2164 | } |
| 2165 | 2165 | return opv; |
| 2166 | 2166 | } |
| 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().?)]) { | |
| 2169 | 2169 | .inferred_alloc => unreachable, |
| 2170 | 2170 | .inferred_alloc_comptime => unreachable, |
| 2171 | 2171 | else => return null, |
| ... | ... | @@ -3543,7 +3543,7 @@ fn zirAllocExtended( |
| 3543 | 3543 | .is_const = small.is_const, |
| 3544 | 3544 | } }, |
| 3545 | 3545 | }); |
| 3546 | return Air.indexToRef(@intCast(sema.air_instructions.len - 1)); | |
| 3546 | return @as(Air.Inst.Index, @enumFromInt(sema.air_instructions.len - 1)).toRef(); | |
| 3547 | 3547 | } |
| 3548 | 3548 | } |
| 3549 | 3549 | |
| ... | ... | @@ -3562,7 +3562,7 @@ fn zirAllocExtended( |
| 3562 | 3562 | }); |
| 3563 | 3563 | const ptr = try block.addTy(.alloc, ptr_type); |
| 3564 | 3564 | if (small.is_const) { |
| 3565 | const ptr_inst = Air.refToIndex(ptr).?; | |
| 3565 | const ptr_inst = ptr.toIndex().?; | |
| 3566 | 3566 | try sema.maybe_comptime_allocs.put(gpa, ptr_inst, .{ .runtime_index = block.runtime_index }); |
| 3567 | 3567 | try sema.base_allocs.put(gpa, ptr_inst, ptr_inst); |
| 3568 | 3568 | } |
| ... | ... | @@ -3581,7 +3581,7 @@ fn zirAllocExtended( |
| 3581 | 3581 | try sema.maybe_comptime_allocs.put(gpa, result_index, .{ .runtime_index = block.runtime_index }); |
| 3582 | 3582 | try sema.base_allocs.put(gpa, result_index, result_index); |
| 3583 | 3583 | } |
| 3584 | return Air.indexToRef(result_index); | |
| 3584 | return result_index.toRef(); | |
| 3585 | 3585 | } |
| 3586 | 3586 | |
| 3587 | 3587 | fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -3654,7 +3654,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3654 | 3654 | const ptr_info = alloc_ty.ptrInfo(mod); |
| 3655 | 3655 | const elem_ty = Type.fromInterned(ptr_info.child); |
| 3656 | 3656 | |
| 3657 | const alloc_inst = Air.refToIndex(alloc) orelse return null; | |
| 3657 | const alloc_inst = alloc.toIndex() orelse return null; | |
| 3658 | 3658 | const comptime_info = sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return null; |
| 3659 | 3659 | const stores = comptime_info.value.stores.items; |
| 3660 | 3660 | |
| ... | ... | @@ -3674,10 +3674,10 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3674 | 3674 | simple: { |
| 3675 | 3675 | if (stores.len != 1) break :simple; |
| 3676 | 3676 | const store_inst = stores[0]; |
| 3677 | const store_data = sema.air_instructions.items(.data)[store_inst].bin_op; | |
| 3677 | const store_data = sema.air_instructions.items(.data)[@intFromEnum(store_inst)].bin_op; | |
| 3678 | 3678 | if (store_data.lhs != alloc) break :simple; |
| 3679 | 3679 | |
| 3680 | const val = Air.refToInterned(store_data.rhs).?; | |
| 3680 | const val = store_data.rhs.toInterned().?; | |
| 3681 | 3681 | assert(mod.intern_pool.typeOf(val) == elem_ty.toIntern()); |
| 3682 | 3682 | return sema.finishResolveComptimeKnownAllocValue(val, alloc_inst, comptime_info.value); |
| 3683 | 3683 | } |
| ... | ... | @@ -3704,8 +3704,8 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3704 | 3704 | |
| 3705 | 3705 | var to_map = try std.ArrayList(Air.Inst.Index).initCapacity(sema.arena, stores.len); |
| 3706 | 3706 | 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().?); | |
| 3709 | 3709 | } |
| 3710 | 3710 | |
| 3711 | 3711 | const tmp_air = sema.getTmpAir(); |
| ... | ... | @@ -3719,12 +3719,12 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3719 | 3719 | field: u32, |
| 3720 | 3720 | elem: u64, |
| 3721 | 3721 | }; |
| 3722 | const inst_tag = tmp_air.instructions.items(.tag)[air_ptr]; | |
| 3722 | const inst_tag = tmp_air.instructions.items(.tag)[@intFromEnum(air_ptr)]; | |
| 3723 | 3723 | const air_parent_ptr: Air.Inst.Ref, const method: PointerMethod = switch (inst_tag) { |
| 3724 | 3724 | .struct_field_ptr => blk: { |
| 3725 | 3725 | const data = tmp_air.extraData( |
| 3726 | 3726 | Air.StructField, |
| 3727 | tmp_air.instructions.items(.data)[air_ptr].ty_pl.payload, | |
| 3727 | tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_pl.payload, | |
| 3728 | 3728 | ).data; |
| 3729 | 3729 | break :blk .{ |
| 3730 | 3730 | data.struct_operand, |
| ... | ... | @@ -3736,7 +3736,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3736 | 3736 | .struct_field_ptr_index_2, |
| 3737 | 3737 | .struct_field_ptr_index_3, |
| 3738 | 3738 | => .{ |
| 3739 | tmp_air.instructions.items(.data)[air_ptr].ty_op.operand, | |
| 3739 | tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand, | |
| 3740 | 3740 | .{ .field = switch (inst_tag) { |
| 3741 | 3741 | .struct_field_ptr_index_0 => 0, |
| 3742 | 3742 | .struct_field_ptr_index_1 => 1, |
| ... | ... | @@ -3746,17 +3746,17 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3746 | 3746 | } }, |
| 3747 | 3747 | }, |
| 3748 | 3748 | .ptr_slice_ptr_ptr => .{ |
| 3749 | tmp_air.instructions.items(.data)[air_ptr].ty_op.operand, | |
| 3749 | tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand, | |
| 3750 | 3750 | .{ .field = Value.slice_ptr_index }, |
| 3751 | 3751 | }, |
| 3752 | 3752 | .ptr_slice_len_ptr => .{ |
| 3753 | tmp_air.instructions.items(.data)[air_ptr].ty_op.operand, | |
| 3753 | tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand, | |
| 3754 | 3754 | .{ .field = Value.slice_len_index }, |
| 3755 | 3755 | }, |
| 3756 | 3756 | .ptr_elem_ptr => blk: { |
| 3757 | 3757 | const data = tmp_air.extraData( |
| 3758 | 3758 | Air.Bin, |
| 3759 | tmp_air.instructions.items(.data)[air_ptr].ty_pl.payload, | |
| 3759 | tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_pl.payload, | |
| 3760 | 3760 | ).data; |
| 3761 | 3761 | const idx_val = (try sema.resolveValue(data.rhs)).?; |
| 3762 | 3762 | break :blk .{ |
| ... | ... | @@ -3765,24 +3765,24 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3765 | 3765 | }; |
| 3766 | 3766 | }, |
| 3767 | 3767 | .bitcast => .{ |
| 3768 | tmp_air.instructions.items(.data)[air_ptr].ty_op.operand, | |
| 3768 | tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand, | |
| 3769 | 3769 | .same_addr, |
| 3770 | 3770 | }, |
| 3771 | 3771 | .optional_payload_ptr_set => .{ |
| 3772 | tmp_air.instructions.items(.data)[air_ptr].ty_op.operand, | |
| 3772 | tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand, | |
| 3773 | 3773 | .opt_payload, |
| 3774 | 3774 | }, |
| 3775 | 3775 | .errunion_payload_ptr_set => .{ |
| 3776 | tmp_air.instructions.items(.data)[air_ptr].ty_op.operand, | |
| 3776 | tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_op.operand, | |
| 3777 | 3777 | .eu_payload, |
| 3778 | 3778 | }, |
| 3779 | 3779 | else => unreachable, |
| 3780 | 3780 | }; |
| 3781 | 3781 | |
| 3782 | const decl_parent_ptr = ptr_mapping.get(Air.refToIndex(air_parent_ptr).?) orelse { | |
| 3782 | const decl_parent_ptr = ptr_mapping.get(air_parent_ptr.toIndex().?) orelse { | |
| 3783 | 3783 | // Resolve the parent pointer first. |
| 3784 | 3784 | // Note that we add in what seems like the wrong order, because we're popping from the end of this array. |
| 3785 | try to_map.appendSlice(&.{ air_ptr, Air.refToIndex(air_parent_ptr).? }); | |
| 3785 | try to_map.appendSlice(&.{ air_ptr, air_parent_ptr.toIndex().? }); | |
| 3786 | 3786 | continue; |
| 3787 | 3787 | }; |
| 3788 | 3788 | const new_ptr_ty = tmp_air.typeOfIndex(air_ptr, &mod.intern_pool).toIntern(); |
| ... | ... | @@ -3811,12 +3811,12 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3811 | 3811 | // We have a correlation between AIR pointers and decl pointers. Perform all stores at comptime. |
| 3812 | 3812 | |
| 3813 | 3813 | for (stores) |store_inst| { |
| 3814 | switch (sema.air_instructions.items(.tag)[store_inst]) { | |
| 3814 | switch (sema.air_instructions.items(.tag)[@intFromEnum(store_inst)]) { | |
| 3815 | 3815 | .set_union_tag => { |
| 3816 | 3816 | // If this tag has an OPV payload, there won't be a corresponding |
| 3817 | 3817 | // 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().?; | |
| 3820 | 3820 | const tag_val = (try sema.resolveValue(bin_op.rhs)).?; |
| 3821 | 3821 | const union_ty = sema.typeOf(bin_op.lhs).childType(mod); |
| 3822 | 3822 | const payload_ty = union_ty.unionFieldType(tag_val, mod).?; |
| ... | ... | @@ -3827,8 +3827,8 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3827 | 3827 | } |
| 3828 | 3828 | }, |
| 3829 | 3829 | .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().?; | |
| 3832 | 3832 | const store_val = (try sema.resolveValue(bin_op.rhs)).?; |
| 3833 | 3833 | const new_ptr = ptr_mapping.get(air_ptr_inst).?; |
| 3834 | 3834 | try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(mod.intern_pool.typeOf(store_val.toIntern()))); |
| ... | ... | @@ -3858,12 +3858,12 @@ fn finishResolveComptimeKnownAllocValue(sema: *Sema, result_val: InternPool.Inde |
| 3858 | 3858 | // Liveness to elide it. |
| 3859 | 3859 | const nop_inst: Air.Inst = .{ .tag = .bitcast, .data = .{ .ty_op = .{ .ty = .u8_type, .operand = .zero_u8 } } }; |
| 3860 | 3860 | |
| 3861 | sema.air_instructions.set(alloc_inst, nop_inst); | |
| 3861 | sema.air_instructions.set(@intFromEnum(alloc_inst), nop_inst); | |
| 3862 | 3862 | for (comptime_info.stores.items) |store_inst| { |
| 3863 | sema.air_instructions.set(store_inst, nop_inst); | |
| 3863 | sema.air_instructions.set(@intFromEnum(store_inst), nop_inst); | |
| 3864 | 3864 | } |
| 3865 | 3865 | for (comptime_info.non_elideable_pointers.items) |ptr_inst| { |
| 3866 | sema.air_instructions.set(ptr_inst, nop_inst); | |
| 3866 | sema.air_instructions.set(@intFromEnum(ptr_inst), nop_inst); | |
| 3867 | 3867 | } |
| 3868 | 3868 | |
| 3869 | 3869 | return result_val; |
| ... | ... | @@ -3905,7 +3905,7 @@ fn zirAllocInferredComptime( |
| 3905 | 3905 | .is_const = is_const, |
| 3906 | 3906 | } }, |
| 3907 | 3907 | }); |
| 3908 | return Air.indexToRef(@intCast(sema.air_instructions.len - 1)); | |
| 3908 | return @as(Air.Inst.Index, @enumFromInt(sema.air_instructions.len - 1)).toRef(); | |
| 3909 | 3909 | } |
| 3910 | 3910 | |
| 3911 | 3911 | fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -3925,7 +3925,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 3925 | 3925 | }); |
| 3926 | 3926 | try sema.queueFullTypeResolution(var_ty); |
| 3927 | 3927 | const ptr = try block.addTy(.alloc, ptr_type); |
| 3928 | const ptr_inst = Air.refToIndex(ptr).?; | |
| 3928 | const ptr_inst = ptr.toIndex().?; | |
| 3929 | 3929 | try sema.maybe_comptime_allocs.put(sema.gpa, ptr_inst, .{ .runtime_index = block.runtime_index }); |
| 3930 | 3930 | try sema.base_allocs.put(sema.gpa, ptr_inst, ptr_inst); |
| 3931 | 3931 | return ptr; |
| ... | ... | @@ -3974,7 +3974,7 @@ fn zirAllocInferred( |
| 3974 | 3974 | .is_const = is_const, |
| 3975 | 3975 | } }, |
| 3976 | 3976 | }); |
| 3977 | return Air.indexToRef(@intCast(sema.air_instructions.len - 1)); | |
| 3977 | return @as(Air.Inst.Index, @enumFromInt(sema.air_instructions.len - 1)).toRef(); | |
| 3978 | 3978 | } |
| 3979 | 3979 | |
| 3980 | 3980 | const result_index = try block.addInstAsIndex(.{ |
| ... | ... | @@ -3987,7 +3987,7 @@ fn zirAllocInferred( |
| 3987 | 3987 | try sema.unresolved_inferred_allocs.putNoClobber(gpa, result_index, .{}); |
| 3988 | 3988 | try sema.maybe_comptime_allocs.put(gpa, result_index, .{ .runtime_index = block.runtime_index }); |
| 3989 | 3989 | try sema.base_allocs.put(sema.gpa, result_index, result_index); |
| 3990 | return Air.indexToRef(result_index); | |
| 3990 | return result_index.toRef(); | |
| 3991 | 3991 | } |
| 3992 | 3992 | |
| 3993 | 3993 | fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | ... | @@ -4000,12 +4000,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4000 | 4000 | const src = inst_data.src(); |
| 4001 | 4001 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 4002 | 4002 | const ptr = try sema.resolveInst(inst_data.operand); |
| 4003 | const ptr_inst = Air.refToIndex(ptr).?; | |
| 4003 | const ptr_inst = ptr.toIndex().?; | |
| 4004 | 4004 | const target = mod.getTarget(); |
| 4005 | 4005 | |
| 4006 | switch (sema.air_instructions.items(.tag)[ptr_inst]) { | |
| 4006 | switch (sema.air_instructions.items(.tag)[@intFromEnum(ptr_inst)]) { | |
| 4007 | 4007 | .inferred_alloc_comptime => { |
| 4008 | const iac = sema.air_instructions.items(.data)[ptr_inst].inferred_alloc_comptime; | |
| 4008 | const iac = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].inferred_alloc_comptime; | |
| 4009 | 4009 | const decl_index = iac.decl_index; |
| 4010 | 4010 | |
| 4011 | 4011 | const decl = mod.declPtr(decl_index); |
| ... | ... | @@ -4022,7 +4022,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4022 | 4022 | |
| 4023 | 4023 | if (std.debug.runtime_safety) { |
| 4024 | 4024 | // The inferred_alloc_comptime should never be referenced again |
| 4025 | sema.air_instructions.set(ptr_inst, .{ .tag = undefined, .data = undefined }); | |
| 4025 | sema.air_instructions.set(@intFromEnum(ptr_inst), .{ .tag = undefined, .data = undefined }); | |
| 4026 | 4026 | } |
| 4027 | 4027 | |
| 4028 | 4028 | try sema.maybeQueueFuncBodyAnalysis(decl_index); |
| ... | ... | @@ -4039,12 +4039,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4039 | 4039 | sema.inst_map.putAssumeCapacity(inst_data.operand.toIndex().?, Air.internedToRef(interned)); |
| 4040 | 4040 | }, |
| 4041 | 4041 | .inferred_alloc => { |
| 4042 | const ia1 = sema.air_instructions.items(.data)[ptr_inst].inferred_alloc; | |
| 4042 | const ia1 = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].inferred_alloc; | |
| 4043 | 4043 | const ia2 = sema.unresolved_inferred_allocs.fetchRemove(ptr_inst).?.value; |
| 4044 | 4044 | const peer_vals = try sema.arena.alloc(Air.Inst.Ref, ia2.prongs.items.len); |
| 4045 | 4045 | 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; | |
| 4048 | 4048 | peer_val.* = bin_op.rhs; |
| 4049 | 4049 | } |
| 4050 | 4050 | const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_vals, .none); |
| ... | ... | @@ -4083,7 +4083,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4083 | 4083 | try sema.queueFullTypeResolution(final_elem_ty); |
| 4084 | 4084 | |
| 4085 | 4085 | // Change it to a normal alloc. |
| 4086 | sema.air_instructions.set(ptr_inst, .{ | |
| 4086 | sema.air_instructions.set(@intFromEnum(ptr_inst), .{ | |
| 4087 | 4087 | .tag = .alloc, |
| 4088 | 4088 | .data = .{ .ty = final_ptr_ty }, |
| 4089 | 4089 | }); |
| ... | ... | @@ -4095,15 +4095,15 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4095 | 4095 | var replacement_block = block.makeSubBlock(); |
| 4096 | 4096 | defer replacement_block.instructions.deinit(gpa); |
| 4097 | 4097 | |
| 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; | |
| 4100 | 4100 | try sema.storePtr2(&replacement_block, src, bin_op.lhs, src, bin_op.rhs, src, .store); |
| 4101 | 4101 | |
| 4102 | 4102 | // If only one instruction is produced then we can replace the store |
| 4103 | 4103 | // placeholder instruction with this instruction; no need for an entire block. |
| 4104 | 4104 | if (replacement_block.instructions.items.len == 1) { |
| 4105 | 4105 | const only_inst = replacement_block.instructions.items[0]; |
| 4106 | sema.air_instructions.set(placeholder_inst, sema.air_instructions.get(only_inst)); | |
| 4106 | sema.air_instructions.set(@intFromEnum(placeholder_inst), sema.air_instructions.get(@intFromEnum(only_inst))); | |
| 4107 | 4107 | continue; |
| 4108 | 4108 | } |
| 4109 | 4109 | |
| ... | ... | @@ -4114,7 +4114,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4114 | 4114 | gpa, |
| 4115 | 4115 | @typeInfo(Air.Block).Struct.fields.len + replacement_block.instructions.items.len, |
| 4116 | 4116 | ); |
| 4117 | sema.air_instructions.set(placeholder_inst, .{ | |
| 4117 | sema.air_instructions.set(@intFromEnum(placeholder_inst), .{ | |
| 4118 | 4118 | .tag = .block, |
| 4119 | 4119 | .data = .{ .ty_pl = .{ |
| 4120 | 4120 | .ty = .void_type, |
| ... | ... | @@ -4123,7 +4123,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4123 | 4123 | }), |
| 4124 | 4124 | } }, |
| 4125 | 4125 | }); |
| 4126 | sema.air_extra.appendSliceAssumeCapacity(replacement_block.instructions.items); | |
| 4126 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(replacement_block.instructions.items)); | |
| 4127 | 4127 | } |
| 4128 | 4128 | }, |
| 4129 | 4129 | else => unreachable, |
| ... | ... | @@ -4584,18 +4584,18 @@ fn validateUnionInit( |
| 4584 | 4584 | var init_val: ?Value = null; |
| 4585 | 4585 | while (block_index > 0) : (block_index -= 1) { |
| 4586 | 4586 | 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)]) { | |
| 4589 | 4589 | .store, .store_safe => {}, |
| 4590 | 4590 | else => continue, |
| 4591 | 4591 | } |
| 4592 | const bin_op = air_datas[store_inst].bin_op; | |
| 4592 | const bin_op = air_datas[@intFromEnum(store_inst)].bin_op; | |
| 4593 | 4593 | 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; | |
| 4596 | 4596 | }; |
| 4597 | 4597 | if (ptr_ref != field_ptr_ref) continue; |
| 4598 | first_block_index = @min(if (Air.refToIndex(field_ptr_ref)) |field_ptr_inst| | |
| 4598 | first_block_index = @min(if (field_ptr_ref.toIndex()) |field_ptr_inst| | |
| 4599 | 4599 | std.mem.lastIndexOfScalar( |
| 4600 | 4600 | Air.Inst.Index, |
| 4601 | 4601 | block.instructions.items[0..block_index], |
| ... | ... | @@ -4615,18 +4615,18 @@ fn validateUnionInit( |
| 4615 | 4615 | // instead a single `store` to the result ptr with a comptime union value. |
| 4616 | 4616 | block_index = first_block_index; |
| 4617 | 4617 | for (block.instructions.items[first_block_index..]) |cur_inst| { |
| 4618 | switch (air_tags[cur_inst]) { | |
| 4618 | switch (air_tags[@intFromEnum(cur_inst)]) { | |
| 4619 | 4619 | .struct_field_ptr, |
| 4620 | 4620 | .struct_field_ptr_index_0, |
| 4621 | 4621 | .struct_field_ptr_index_1, |
| 4622 | 4622 | .struct_field_ptr_index_2, |
| 4623 | 4623 | .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, | |
| 4626 | 4626 | .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; | |
| 4630 | 4630 | }; |
| 4631 | 4631 | if (ptr_ref == field_ptr_ref) continue; |
| 4632 | 4632 | }, |
| ... | ... | @@ -4807,21 +4807,21 @@ fn validateStructInit( |
| 4807 | 4807 | var block_index = block.instructions.items.len -| 1; |
| 4808 | 4808 | while (block_index > 0) : (block_index -= 1) { |
| 4809 | 4809 | const store_inst = block.instructions.items[block_index]; |
| 4810 | if (Air.indexToRef(store_inst) == field_ptr_ref) { | |
| 4810 | if (store_inst.toRef() == field_ptr_ref) { | |
| 4811 | 4811 | struct_is_comptime = false; |
| 4812 | 4812 | continue :field; |
| 4813 | 4813 | } |
| 4814 | switch (air_tags[store_inst]) { | |
| 4814 | switch (air_tags[@intFromEnum(store_inst)]) { | |
| 4815 | 4815 | .store, .store_safe => {}, |
| 4816 | 4816 | else => continue, |
| 4817 | 4817 | } |
| 4818 | const bin_op = air_datas[store_inst].bin_op; | |
| 4818 | const bin_op = air_datas[@intFromEnum(store_inst)].bin_op; | |
| 4819 | 4819 | 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; | |
| 4822 | 4822 | }; |
| 4823 | 4823 | if (ptr_ref != field_ptr_ref) continue; |
| 4824 | first_block_index = @min(if (Air.refToIndex(field_ptr_ref)) |field_ptr_inst| | |
| 4824 | first_block_index = @min(if (field_ptr_ref.toIndex()) |field_ptr_inst| | |
| 4825 | 4825 | std.mem.lastIndexOfScalar( |
| 4826 | 4826 | Air.Inst.Index, |
| 4827 | 4827 | block.instructions.items[0..block_index], |
| ... | ... | @@ -4895,18 +4895,18 @@ fn validateStructInit( |
| 4895 | 4895 | if (try field_ty.onePossibleValue(mod)) |_| continue; |
| 4896 | 4896 | field_ptr_ref = sema.inst_map.get(instrs[init_index]).?; |
| 4897 | 4897 | } |
| 4898 | switch (air_tags[cur_inst]) { | |
| 4898 | switch (air_tags[@intFromEnum(cur_inst)]) { | |
| 4899 | 4899 | .struct_field_ptr, |
| 4900 | 4900 | .struct_field_ptr_index_0, |
| 4901 | 4901 | .struct_field_ptr_index_1, |
| 4902 | 4902 | .struct_field_ptr_index_2, |
| 4903 | 4903 | .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, | |
| 4906 | 4906 | .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; | |
| 4910 | 4910 | }; |
| 4911 | 4911 | if (ptr_ref == field_ptr_ref) { |
| 4912 | 4912 | field_ptr_ref = .none; |
| ... | ... | @@ -5063,21 +5063,21 @@ fn zirValidatePtrArrayInit( |
| 5063 | 5063 | var block_index = block.instructions.items.len -| 1; |
| 5064 | 5064 | while (block_index > 0) : (block_index -= 1) { |
| 5065 | 5065 | const store_inst = block.instructions.items[block_index]; |
| 5066 | if (Air.indexToRef(store_inst) == elem_ptr_ref) { | |
| 5066 | if (store_inst.toRef() == elem_ptr_ref) { | |
| 5067 | 5067 | array_is_comptime = false; |
| 5068 | 5068 | continue :outer; |
| 5069 | 5069 | } |
| 5070 | switch (air_tags[store_inst]) { | |
| 5070 | switch (air_tags[@intFromEnum(store_inst)]) { | |
| 5071 | 5071 | .store, .store_safe => {}, |
| 5072 | 5072 | else => continue, |
| 5073 | 5073 | } |
| 5074 | const bin_op = air_datas[store_inst].bin_op; | |
| 5074 | const bin_op = air_datas[@intFromEnum(store_inst)].bin_op; | |
| 5075 | 5075 | 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; | |
| 5078 | 5078 | }; |
| 5079 | 5079 | if (ptr_ref != elem_ptr_ref) continue; |
| 5080 | first_block_index = @min(if (Air.refToIndex(elem_ptr_ref)) |elem_ptr_inst| | |
| 5080 | first_block_index = @min(if (elem_ptr_ref.toIndex()) |elem_ptr_inst| | |
| 5081 | 5081 | std.mem.lastIndexOfScalar( |
| 5082 | 5082 | Air.Inst.Index, |
| 5083 | 5083 | block.instructions.items[0..block_index], |
| ... | ... | @@ -5117,13 +5117,13 @@ fn zirValidatePtrArrayInit( |
| 5117 | 5117 | if (array_ty.isTuple(mod) and array_ty.structFieldIsComptime(elem_index, mod)) continue; |
| 5118 | 5118 | elem_ptr_ref = sema.inst_map.get(instrs[elem_index]).?; |
| 5119 | 5119 | } |
| 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, | |
| 5123 | 5123 | .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; | |
| 5127 | 5127 | }; |
| 5128 | 5128 | if (ptr_ref == elem_ptr_ref) { |
| 5129 | 5129 | elem_ptr_ref = .none; |
| ... | ... | @@ -5336,12 +5336,12 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 5336 | 5336 | const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; |
| 5337 | 5337 | const ptr = try sema.resolveInst(bin_inst.lhs); |
| 5338 | 5338 | const operand = try sema.resolveInst(bin_inst.rhs); |
| 5339 | const ptr_inst = Air.refToIndex(ptr).?; | |
| 5339 | const ptr_inst = ptr.toIndex().?; | |
| 5340 | 5340 | const air_datas = sema.air_instructions.items(.data); |
| 5341 | 5341 | |
| 5342 | switch (sema.air_instructions.items(.tag)[ptr_inst]) { | |
| 5342 | switch (sema.air_instructions.items(.tag)[@intFromEnum(ptr_inst)]) { | |
| 5343 | 5343 | .inferred_alloc_comptime => { |
| 5344 | const iac = &air_datas[ptr_inst].inferred_alloc_comptime; | |
| 5344 | const iac = &air_datas[@intFromEnum(ptr_inst)].inferred_alloc_comptime; | |
| 5345 | 5345 | return sema.storeToInferredAllocComptime(block, src, operand, iac); |
| 5346 | 5346 | }, |
| 5347 | 5347 | .inferred_alloc => { |
| ... | ... | @@ -5365,7 +5365,7 @@ fn storeToInferredAlloc( |
| 5365 | 5365 | try sema.checkComptimeKnownStore(block, dummy_store); |
| 5366 | 5366 | // Add the stored instruction to the set we will use to resolve peer types |
| 5367 | 5367 | // for the inferred allocation. |
| 5368 | try inferred_alloc.prongs.append(sema.arena, Air.refToIndex(dummy_store).?); | |
| 5368 | try inferred_alloc.prongs.append(sema.arena, dummy_store.toIndex().?); | |
| 5369 | 5369 | } |
| 5370 | 5370 | |
| 5371 | 5371 | fn storeToInferredAllocComptime( |
| ... | ... | @@ -5635,8 +5635,8 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5635 | 5635 | // Reserve space for a Loop instruction so that generated Break instructions can |
| 5636 | 5636 | // point to it, even if it doesn't end up getting used because the code ends up being |
| 5637 | 5637 | // 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); | |
| 5640 | 5640 | try sema.air_instructions.ensureUnusedCapacity(gpa, 2); |
| 5641 | 5641 | sema.air_instructions.appendAssumeCapacity(.{ |
| 5642 | 5642 | .tag = .block, |
| ... | ... | @@ -5674,7 +5674,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5674 | 5674 | try sema.analyzeBody(&loop_block, body); |
| 5675 | 5675 | |
| 5676 | 5676 | const loop_block_len = loop_block.instructions.items.len; |
| 5677 | if (loop_block_len > 0 and sema.typeOf(Air.indexToRef(loop_block.instructions.items[loop_block_len - 1])).isNoReturn(mod)) { | |
| 5677 | if (loop_block_len > 0 and sema.typeOf(loop_block.instructions.items[loop_block_len - 1].toRef()).isNoReturn(mod)) { | |
| 5678 | 5678 | // If the loop ended with a noreturn terminator, then there is no way for it to loop, |
| 5679 | 5679 | // so we can just use the block instead. |
| 5680 | 5680 | try child_block.instructions.appendSlice(gpa, loop_block.instructions.items); |
| ... | ... | @@ -5682,10 +5682,10 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5682 | 5682 | try child_block.instructions.append(gpa, loop_inst); |
| 5683 | 5683 | |
| 5684 | 5684 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + loop_block_len); |
| 5685 | sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity( | |
| 5685 | sema.air_instructions.items(.data)[@intFromEnum(loop_inst)].ty_pl.payload = sema.addExtraAssumeCapacity( | |
| 5686 | 5686 | Air.Block{ .body_len = @intCast(loop_block_len) }, |
| 5687 | 5687 | ); |
| 5688 | sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items); | |
| 5688 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(loop_block.instructions.items)); | |
| 5689 | 5689 | } |
| 5690 | 5690 | return sema.analyzeBlockBody(parent_block, src, &child_block, merges); |
| 5691 | 5691 | } |
| ... | ... | @@ -5793,7 +5793,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 5793 | 5793 | // Reserve space for a Block instruction so that generated Break instructions can |
| 5794 | 5794 | // point to it, even if it doesn't end up getting used because the code ends up being |
| 5795 | 5795 | // comptime evaluated or is an unlabeled block. |
| 5796 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); | |
| 5796 | const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); | |
| 5797 | 5797 | try sema.air_instructions.append(gpa, .{ |
| 5798 | 5798 | .tag = .block, |
| 5799 | 5799 | .data = undefined, |
| ... | ... | @@ -5887,13 +5887,13 @@ fn analyzeBlockBody( |
| 5887 | 5887 | |
| 5888 | 5888 | // Blocks must terminate with noreturn instruction. |
| 5889 | 5889 | assert(child_block.instructions.items.len != 0); |
| 5890 | assert(sema.typeOf(Air.indexToRef(child_block.instructions.items[child_block.instructions.items.len - 1])).isNoReturn(mod)); | |
| 5890 | assert(sema.typeOf(child_block.instructions.items[child_block.instructions.items.len - 1].toRef()).isNoReturn(mod)); | |
| 5891 | 5891 | |
| 5892 | 5892 | if (merges.results.items.len == 0) { |
| 5893 | 5893 | // No need for a block instruction. We can put the new instructions |
| 5894 | 5894 | // directly into the parent block. |
| 5895 | 5895 | try parent_block.instructions.appendSlice(gpa, child_block.instructions.items); |
| 5896 | return Air.indexToRef(child_block.instructions.items[child_block.instructions.items.len - 1]); | |
| 5896 | return child_block.instructions.items[child_block.instructions.items.len - 1].toRef(); | |
| 5897 | 5897 | } |
| 5898 | 5898 | if (merges.results.items.len == 1) { |
| 5899 | 5899 | const last_inst_index = child_block.instructions.items.len - 1; |
| ... | ... | @@ -5936,17 +5936,17 @@ fn analyzeBlockBody( |
| 5936 | 5936 | const ty_inst = Air.internedToRef(resolved_ty.toIntern()); |
| 5937 | 5937 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + |
| 5938 | 5938 | child_block.instructions.items.len); |
| 5939 | sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{ | |
| 5939 | sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{ | |
| 5940 | 5940 | .ty = ty_inst, |
| 5941 | 5941 | .payload = sema.addExtraAssumeCapacity(Air.Block{ |
| 5942 | 5942 | .body_len = @intCast(child_block.instructions.items.len), |
| 5943 | 5943 | }), |
| 5944 | 5944 | } }; |
| 5945 | sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items); | |
| 5945 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(child_block.instructions.items)); | |
| 5946 | 5946 | // Now that the block has its type resolved, we need to go back into all the break |
| 5947 | 5947 | // instructions, and insert type coercion on the operands. |
| 5948 | 5948 | for (merges.br_list.items) |br| { |
| 5949 | const br_operand = sema.air_instructions.items(.data)[br].br.operand; | |
| 5949 | const br_operand = sema.air_instructions.items(.data)[@intFromEnum(br)].br.operand; | |
| 5950 | 5950 | const br_operand_src = src; |
| 5951 | 5951 | const br_operand_ty = sema.typeOf(br_operand); |
| 5952 | 5952 | if (br_operand_ty.eql(resolved_ty, mod)) { |
| ... | ... | @@ -5959,10 +5959,10 @@ fn analyzeBlockBody( |
| 5959 | 5959 | // If no instructions were produced, such as in the case of a coercion of a |
| 5960 | 5960 | // constant value to a new type, we can simply point the br operand to it. |
| 5961 | 5961 | if (coerce_block.instructions.items.len == 0) { |
| 5962 | sema.air_instructions.items(.data)[br].br.operand = coerced_operand; | |
| 5962 | sema.air_instructions.items(.data)[@intFromEnum(br)].br.operand = coerced_operand; | |
| 5963 | 5963 | continue; |
| 5964 | 5964 | } |
| 5965 | assert(Air.indexToRef(coerce_block.instructions.items[coerce_block.instructions.items.len - 1]) == coerced_operand); | |
| 5965 | assert(coerce_block.instructions.items[coerce_block.instructions.items.len - 1].toRef() == coerced_operand); | |
| 5966 | 5966 | |
| 5967 | 5967 | // Convert the br instruction to a block instruction that has the coercion |
| 5968 | 5968 | // and then a new br inside that returns the coerced instruction. |
| ... | ... | @@ -5970,17 +5970,17 @@ fn analyzeBlockBody( |
| 5970 | 5970 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + |
| 5971 | 5971 | sub_block_len); |
| 5972 | 5972 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); |
| 5973 | const sub_br_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); | |
| 5973 | const sub_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); | |
| 5974 | 5974 | |
| 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 = .{ | |
| 5977 | 5977 | .ty = .noreturn_type, |
| 5978 | 5978 | .payload = sema.addExtraAssumeCapacity(Air.Block{ |
| 5979 | 5979 | .body_len = sub_block_len, |
| 5980 | 5980 | }), |
| 5981 | 5981 | } }; |
| 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)); | |
| 5984 | 5984 | |
| 5985 | 5985 | sema.air_instructions.appendAssumeCapacity(.{ |
| 5986 | 5986 | .tag = .br, |
| ... | ... | @@ -5990,7 +5990,7 @@ fn analyzeBlockBody( |
| 5990 | 5990 | } }, |
| 5991 | 5991 | }); |
| 5992 | 5992 | } |
| 5993 | return Air.indexToRef(merges.block_inst); | |
| 5993 | return merges.block_inst.toRef(); | |
| 5994 | 5994 | } |
| 5995 | 5995 | |
| 5996 | 5996 | fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | ... | @@ -6249,7 +6249,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError |
| 6249 | 6249 | null; |
| 6250 | 6250 | try label.merges.src_locs.append(sema.gpa, src_loc); |
| 6251 | 6251 | try label.merges.results.append(sema.gpa, operand); |
| 6252 | try label.merges.br_list.append(sema.gpa, Air.refToIndex(br_ref).?); | |
| 6252 | try label.merges.br_list.append(sema.gpa, br_ref.toIndex().?); | |
| 6253 | 6253 | block.runtime_index.increment(); |
| 6254 | 6254 | if (block.runtime_cond == null and block.runtime_loop == null) { |
| 6255 | 6255 | block.runtime_cond = start_block.runtime_cond orelse start_block.runtime_loop; |
| ... | ... | @@ -6273,9 +6273,9 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 6273 | 6273 | |
| 6274 | 6274 | if (block.instructions.items.len != 0) { |
| 6275 | 6275 | const idx = block.instructions.items[block.instructions.items.len - 1]; |
| 6276 | if (sema.air_instructions.items(.tag)[idx] == .dbg_stmt) { | |
| 6276 | if (sema.air_instructions.items(.tag)[@intFromEnum(idx)] == .dbg_stmt) { | |
| 6277 | 6277 | // The previous dbg_stmt didn't correspond to any actual code, so replace it. |
| 6278 | sema.air_instructions.items(.data)[idx].dbg_stmt = .{ | |
| 6278 | sema.air_instructions.items(.data)[@intFromEnum(idx)].dbg_stmt = .{ | |
| 6279 | 6279 | .line = inst_data.line, |
| 6280 | 6280 | .column = inst_data.column, |
| 6281 | 6281 | }; |
| ... | ... | @@ -6609,7 +6609,7 @@ fn popErrorReturnTrace( |
| 6609 | 6609 | then_block.instructions.items.len + else_block.instructions.items.len + |
| 6610 | 6610 | @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block |
| 6611 | 6611 | |
| 6612 | const cond_br_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); | |
| 6612 | const cond_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); | |
| 6613 | 6613 | try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{ |
| 6614 | 6614 | .operand = is_non_error_inst, |
| 6615 | 6615 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| ... | ... | @@ -6617,11 +6617,11 @@ fn popErrorReturnTrace( |
| 6617 | 6617 | .else_body_len = @intCast(else_block.instructions.items.len), |
| 6618 | 6618 | }), |
| 6619 | 6619 | } } }); |
| 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)); | |
| 6622 | 6622 | |
| 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)); | |
| 6625 | 6625 | } |
| 6626 | 6626 | } |
| 6627 | 6627 | |
| ... | ... | @@ -6668,7 +6668,7 @@ fn zirCall( |
| 6668 | 6668 | const func_ty = try sema.checkCallArgumentCount(block, func, callee_src, callee_ty, total_args, callee == .method); |
| 6669 | 6669 | |
| 6670 | 6670 | // The block index before the call, so we can potentially insert an error trace save here later. |
| 6671 | const block_index: Air.Inst.Index = @intCast(block.instructions.items.len); | |
| 6671 | const block_index: Air.Inst.Index = @enumFromInt(block.instructions.items.len); | |
| 6672 | 6672 | |
| 6673 | 6673 | // This will be set by `analyzeCall` to indicate whether any parameter was an error (making the |
| 6674 | 6674 | // error trace potentially dirty). |
| ... | ... | @@ -7283,7 +7283,7 @@ fn analyzeCall( |
| 7283 | 7283 | // set to in the `Block`. |
| 7284 | 7284 | // This block instruction will be used to capture the return value from the |
| 7285 | 7285 | // inlined function. |
| 7286 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); | |
| 7286 | const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); | |
| 7287 | 7287 | try sema.air_instructions.append(gpa, .{ |
| 7288 | 7288 | .tag = .block, |
| 7289 | 7289 | .data = undefined, |
| ... | ... | @@ -9737,12 +9737,12 @@ fn zirParam( |
| 9737 | 9737 | sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison); |
| 9738 | 9738 | } else { |
| 9739 | 9739 | // Otherwise we need a dummy runtime instruction. |
| 9740 | const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len); | |
| 9740 | const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); | |
| 9741 | 9741 | try sema.air_instructions.append(sema.gpa, .{ |
| 9742 | 9742 | .tag = .alloc, |
| 9743 | 9743 | .data = .{ .ty = param_ty }, |
| 9744 | 9744 | }); |
| 9745 | sema.inst_map.putAssumeCapacityNoClobber(inst, Air.indexToRef(result_index)); | |
| 9745 | sema.inst_map.putAssumeCapacityNoClobber(inst, result_index.toRef()); | |
| 9746 | 9746 | } |
| 9747 | 9747 | } |
| 9748 | 9748 | |
| ... | ... | @@ -10991,7 +10991,7 @@ const SwitchProngAnalysis = struct { |
| 10991 | 10991 | cases_extra.appendAssumeCapacity(1); // items_len |
| 10992 | 10992 | cases_extra.appendAssumeCapacity(@intCast(coerce_block.instructions.items.len)); // body_len |
| 10993 | 10993 | 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 | |
| 10995 | 10995 | } |
| 10996 | 10996 | } |
| 10997 | 10997 | const else_body_len = len: { |
| ... | ... | @@ -11006,7 +11006,7 @@ const SwitchProngAnalysis = struct { |
| 11006 | 11006 | const coerced = try coerce_block.addBitCast(capture_ty, uncoerced); |
| 11007 | 11007 | _ = try coerce_block.addBr(capture_block_inst, coerced); |
| 11008 | 11008 | |
| 11009 | try cases_extra.appendSlice(coerce_block.instructions.items); | |
| 11009 | try cases_extra.appendSlice(@ptrCast(coerce_block.instructions.items)); | |
| 11010 | 11010 | break :len coerce_block.instructions.items.len; |
| 11011 | 11011 | }; |
| 11012 | 11012 | |
| ... | ... | @@ -11029,12 +11029,12 @@ const SwitchProngAnalysis = struct { |
| 11029 | 11029 | sema.air_extra.appendSliceAssumeCapacity(cases_extra.items); |
| 11030 | 11030 | |
| 11031 | 11031 | // Set up block body |
| 11032 | sema.air_instructions.items(.data)[capture_block_inst].ty_pl.payload = sema.addExtraAssumeCapacity(Air.Block{ | |
| 11032 | sema.air_instructions.items(.data)[@intFromEnum(capture_block_inst)].ty_pl.payload = sema.addExtraAssumeCapacity(Air.Block{ | |
| 11033 | 11033 | .body_len = 1, |
| 11034 | 11034 | }); |
| 11035 | 11035 | sema.air_extra.appendAssumeCapacity(switch_br_inst); |
| 11036 | 11036 | |
| 11037 | return Air.indexToRef(capture_block_inst); | |
| 11037 | return capture_block_inst.toRef(); | |
| 11038 | 11038 | }, |
| 11039 | 11039 | .ErrorSet => { |
| 11040 | 11040 | if (capture_byref) { |
| ... | ... | @@ -11780,7 +11780,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11780 | 11780 | .tag_capture_inst = tag_capture_inst, |
| 11781 | 11781 | }; |
| 11782 | 11782 | |
| 11783 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); | |
| 11783 | const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); | |
| 11784 | 11784 | try sema.air_instructions.append(gpa, .{ |
| 11785 | 11785 | .tag = .block, |
| 11786 | 11786 | .data = undefined, |
| ... | ... | @@ -12023,7 +12023,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12023 | 12023 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12024 | 12024 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12025 | 12025 | cases_extra.appendAssumeCapacity(@intFromEnum(item)); |
| 12026 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | |
| 12026 | cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items)); | |
| 12027 | 12027 | } |
| 12028 | 12028 | |
| 12029 | 12029 | var is_first = true; |
| ... | ... | @@ -12110,7 +12110,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12110 | 12110 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12111 | 12111 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12112 | 12112 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); |
| 12113 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | |
| 12113 | cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items)); | |
| 12114 | 12114 | |
| 12115 | 12115 | if (item.compareScalar(.eq, item_last, operand_ty, mod)) break; |
| 12116 | 12116 | } |
| ... | ... | @@ -12160,7 +12160,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12160 | 12160 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12161 | 12161 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12162 | 12162 | cases_extra.appendAssumeCapacity(@intFromEnum(item)); |
| 12163 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | |
| 12163 | cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items)); | |
| 12164 | 12164 | } |
| 12165 | 12165 | |
| 12166 | 12166 | extra_index += info.body_len; |
| ... | ... | @@ -12213,7 +12213,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12213 | 12213 | cases_extra.appendAssumeCapacity(@intFromEnum(item)); |
| 12214 | 12214 | } |
| 12215 | 12215 | |
| 12216 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | |
| 12216 | cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items)); | |
| 12217 | 12217 | } else { |
| 12218 | 12218 | for (items) |item| { |
| 12219 | 12219 | const cmp_ok = try case_block.addBinOp(if (case_block.float_mode == .Optimized) .cmp_eq_optimized else .cmp_eq, operand, item); |
| ... | ... | @@ -12295,13 +12295,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12295 | 12295 | @typeInfo(Air.CondBr).Struct.fields.len + prev_then_body.len + cond_body.len, |
| 12296 | 12296 | ); |
| 12297 | 12297 | |
| 12298 | sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload = | |
| 12298 | sema.air_instructions.items(.data)[@intFromEnum(prev_cond_br)].pl_op.payload = | |
| 12299 | 12299 | sema.addExtraAssumeCapacity(Air.CondBr{ |
| 12300 | 12300 | .then_body_len = @intCast(prev_then_body.len), |
| 12301 | 12301 | .else_body_len = @intCast(cond_body.len), |
| 12302 | 12302 | }); |
| 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)); | |
| 12305 | 12305 | } |
| 12306 | 12306 | gpa.free(prev_then_body); |
| 12307 | 12307 | prev_then_body = try case_block.instructions.toOwnedSlice(gpa); |
| ... | ... | @@ -12356,7 +12356,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12356 | 12356 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12357 | 12357 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12358 | 12358 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); |
| 12359 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | |
| 12359 | cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items)); | |
| 12360 | 12360 | } |
| 12361 | 12361 | }, |
| 12362 | 12362 | .ErrorSet => { |
| ... | ... | @@ -12397,7 +12397,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12397 | 12397 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12398 | 12398 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12399 | 12399 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); |
| 12400 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | |
| 12400 | cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items)); | |
| 12401 | 12401 | } |
| 12402 | 12402 | }, |
| 12403 | 12403 | .Int => { |
| ... | ... | @@ -12428,7 +12428,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12428 | 12428 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12429 | 12429 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12430 | 12430 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); |
| 12431 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | |
| 12431 | cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items)); | |
| 12432 | 12432 | } |
| 12433 | 12433 | }, |
| 12434 | 12434 | .Bool => { |
| ... | ... | @@ -12456,7 +12456,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12456 | 12456 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12457 | 12457 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12458 | 12458 | cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_true)); |
| 12459 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | |
| 12459 | cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items)); | |
| 12460 | 12460 | } |
| 12461 | 12461 | if (false_count == 0) { |
| 12462 | 12462 | cases_len += 1; |
| ... | ... | @@ -12482,7 +12482,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12482 | 12482 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12483 | 12483 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12484 | 12484 | cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_false)); |
| 12485 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | |
| 12485 | cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items)); | |
| 12486 | 12486 | } |
| 12487 | 12487 | }, |
| 12488 | 12488 | else => return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{ |
| ... | ... | @@ -12544,13 +12544,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12544 | 12544 | try sema.air_extra.ensureUnusedCapacity(gpa, prev_then_body.len + |
| 12545 | 12545 | @typeInfo(Air.CondBr).Struct.fields.len + case_block.instructions.items.len); |
| 12546 | 12546 | |
| 12547 | sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload = | |
| 12547 | sema.air_instructions.items(.data)[@intFromEnum(prev_cond_br)].pl_op.payload = | |
| 12548 | 12548 | sema.addExtraAssumeCapacity(Air.CondBr{ |
| 12549 | 12549 | .then_body_len = @intCast(prev_then_body.len), |
| 12550 | 12550 | .else_body_len = @intCast(case_block.instructions.items.len), |
| 12551 | 12551 | }); |
| 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)); | |
| 12554 | 12554 | final_else_body = first_else_body; |
| 12555 | 12555 | } |
| 12556 | 12556 | } |
| ... | ... | @@ -12565,8 +12565,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12565 | 12565 | .else_body_len = @intCast(final_else_body.len), |
| 12566 | 12566 | }), |
| 12567 | 12567 | } } }); |
| 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)); | |
| 12570 | 12570 | |
| 12571 | 12571 | return sema.analyzeBlockBody(block, src, &child_block, merges); |
| 12572 | 12572 | } |
| ... | ... | @@ -18140,7 +18140,7 @@ fn zirBoolBr( |
| 18140 | 18140 | return sema.resolveBody(parent_block, body, inst); |
| 18141 | 18141 | } |
| 18142 | 18142 | |
| 18143 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); | |
| 18143 | const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); | |
| 18144 | 18144 | try sema.air_instructions.append(gpa, .{ |
| 18145 | 18145 | .tag = .block, |
| 18146 | 18146 | .data = .{ .ty_pl = .{ |
| ... | ... | @@ -18205,21 +18205,21 @@ fn finishCondBr( |
| 18205 | 18205 | .then_body_len = @intCast(then_block.instructions.items.len), |
| 18206 | 18206 | .else_body_len = @intCast(else_block.instructions.items.len), |
| 18207 | 18207 | }); |
| 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)); | |
| 18210 | 18210 | |
| 18211 | 18211 | _ = try child_block.addInst(.{ .tag = .cond_br, .data = .{ .pl_op = .{ |
| 18212 | 18212 | .operand = cond, |
| 18213 | 18213 | .payload = cond_br_payload, |
| 18214 | 18214 | } } }); |
| 18215 | 18215 | |
| 18216 | sema.air_instructions.items(.data)[block_inst].ty_pl.payload = sema.addExtraAssumeCapacity( | |
| 18216 | sema.air_instructions.items(.data)[@intFromEnum(block_inst)].ty_pl.payload = sema.addExtraAssumeCapacity( | |
| 18217 | 18217 | Air.Block{ .body_len = @intCast(child_block.instructions.items.len) }, |
| 18218 | 18218 | ); |
| 18219 | sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items); | |
| 18219 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(child_block.instructions.items)); | |
| 18220 | 18220 | |
| 18221 | 18221 | try parent_block.instructions.append(gpa, block_inst); |
| 18222 | return Air.indexToRef(block_inst); | |
| 18222 | return block_inst.toRef(); | |
| 18223 | 18223 | } |
| 18224 | 18224 | |
| 18225 | 18225 | fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { |
| ... | ... | @@ -18382,8 +18382,8 @@ fn zirCondbr( |
| 18382 | 18382 | }), |
| 18383 | 18383 | } }, |
| 18384 | 18384 | }); |
| 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)); | |
| 18387 | 18387 | return always_noreturn; |
| 18388 | 18388 | } |
| 18389 | 18389 | |
| ... | ... | @@ -18429,7 +18429,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 18429 | 18429 | }), |
| 18430 | 18430 | } }, |
| 18431 | 18431 | }); |
| 18432 | sema.air_extra.appendSliceAssumeCapacity(sub_block.instructions.items); | |
| 18432 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(sub_block.instructions.items)); | |
| 18433 | 18433 | return try_inst; |
| 18434 | 18434 | } |
| 18435 | 18435 | |
| ... | ... | @@ -18489,7 +18489,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr |
| 18489 | 18489 | }), |
| 18490 | 18490 | } }, |
| 18491 | 18491 | }); |
| 18492 | sema.air_extra.appendSliceAssumeCapacity(sub_block.instructions.items); | |
| 18492 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(sub_block.instructions.items)); | |
| 18493 | 18493 | return try_inst; |
| 18494 | 18494 | } |
| 18495 | 18495 | |
| ... | ... | @@ -18501,8 +18501,8 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi |
| 18501 | 18501 | const labeled_block = if (!gop.found_existing) blk: { |
| 18502 | 18502 | try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1); |
| 18503 | 18503 | |
| 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(); | |
| 18506 | 18506 | try sema.air_instructions.append(sema.gpa, .{ |
| 18507 | 18507 | .tag = .block, |
| 18508 | 18508 | .data = undefined, |
| ... | ... | @@ -18533,7 +18533,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi |
| 18533 | 18533 | sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block); |
| 18534 | 18534 | break :blk labeled_block; |
| 18535 | 18535 | } else blk: { |
| 18536 | const new_block_inst = Air.refToIndex(gop.value_ptr.*).?; | |
| 18536 | const new_block_inst = gop.value_ptr.*.toIndex().?; | |
| 18537 | 18537 | const labeled_block = sema.post_hoc_blocks.get(new_block_inst).?; |
| 18538 | 18538 | break :blk labeled_block; |
| 18539 | 18539 | }; |
| ... | ... | @@ -18541,7 +18541,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi |
| 18541 | 18541 | const operand = try sema.resolveInst(break_data.operand); |
| 18542 | 18542 | const br_ref = try child_block.addBr(labeled_block.label.merges.block_inst, operand); |
| 18543 | 18543 | try labeled_block.label.merges.results.append(sema.gpa, operand); |
| 18544 | try labeled_block.label.merges.br_list.append(sema.gpa, Air.refToIndex(br_ref).?); | |
| 18544 | try labeled_block.label.merges.br_list.append(sema.gpa, br_ref.toIndex().?); | |
| 18545 | 18545 | labeled_block.block.runtime_index.increment(); |
| 18546 | 18546 | if (labeled_block.block.runtime_cond == null and labeled_block.block.runtime_loop == null) { |
| 18547 | 18547 | labeled_block.block.runtime_cond = child_block.runtime_cond orelse child_block.runtime_loop; |
| ... | ... | @@ -18719,8 +18719,8 @@ fn retWithErrTracing( |
| 18719 | 18719 | .then_body_len = @intCast(then_block.instructions.items.len), |
| 18720 | 18720 | .else_body_len = @intCast(else_block.instructions.items.len), |
| 18721 | 18721 | }); |
| 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)); | |
| 18724 | 18724 | |
| 18725 | 18725 | _ = try block.addInst(.{ .tag = .cond_br, .data = .{ .pl_op = .{ |
| 18726 | 18726 | .operand = is_non_err, |
| ... | ... | @@ -25856,9 +25856,9 @@ fn addSafetyCheckExtra( |
| 25856 | 25856 | fail_block.instructions.items.len); |
| 25857 | 25857 | |
| 25858 | 25858 | 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); | |
| 25862 | 25862 | sema.air_instructions.appendAssumeCapacity(.{ |
| 25863 | 25863 | .tag = .block, |
| 25864 | 25864 | .data = .{ .ty_pl = .{ |
| ... | ... | @@ -25868,7 +25868,7 @@ fn addSafetyCheckExtra( |
| 25868 | 25868 | }), |
| 25869 | 25869 | } }, |
| 25870 | 25870 | }); |
| 25871 | sema.air_extra.appendAssumeCapacity(cond_br_inst); | |
| 25871 | sema.air_extra.appendAssumeCapacity(@intFromEnum(cond_br_inst)); | |
| 25872 | 25872 | |
| 25873 | 25873 | sema.air_instructions.appendAssumeCapacity(.{ |
| 25874 | 25874 | .tag = .cond_br, |
| ... | ... | @@ -25880,8 +25880,8 @@ fn addSafetyCheckExtra( |
| 25880 | 25880 | }), |
| 25881 | 25881 | } }, |
| 25882 | 25882 | }); |
| 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)); | |
| 25885 | 25885 | |
| 25886 | 25886 | sema.air_instructions.appendAssumeCapacity(.{ |
| 25887 | 25887 | .tag = .br, |
| ... | ... | @@ -29621,10 +29621,10 @@ fn storePtr2( |
| 29621 | 29621 | try sema.queueFullTypeResolution(elem_ty); |
| 29622 | 29622 | |
| 29623 | 29623 | if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) { |
| 29624 | const ptr_inst = Air.refToIndex(ptr).?; | |
| 29624 | const ptr_inst = ptr.toIndex().?; | |
| 29625 | 29625 | 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; | |
| 29628 | 29628 | const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data; |
| 29629 | 29629 | _ = try block.addInst(.{ |
| 29630 | 29630 | .tag = .vector_store_elem, |
| ... | ... | @@ -29657,9 +29657,9 @@ fn storePtr2( |
| 29657 | 29657 | /// comptime-known store to a local alloc, and updates `maybe_comptime_allocs` |
| 29658 | 29658 | /// accordingly. |
| 29659 | 29659 | fn 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; | |
| 29663 | 29663 | const operand = inst_data.rhs; |
| 29664 | 29664 | |
| 29665 | 29665 | const maybe_base_alloc = sema.base_allocs.get(ptr) orelse return; |
| ... | ... | @@ -29679,19 +29679,19 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst. |
| 29679 | 29679 | /// ptr_elem_ptr, bitcast, etc), checks whether the base pointer refers to a |
| 29680 | 29680 | /// local alloc, and updates `base_allocs` accordingly. |
| 29681 | 29681 | fn 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; | |
| 29684 | 29684 | const alloc_inst = sema.base_allocs.get(base_ptr_inst) orelse return; |
| 29685 | 29685 | try sema.base_allocs.put(sema.gpa, new_ptr_inst, alloc_inst); |
| 29686 | 29686 | |
| 29687 | switch (sema.air_instructions.items(.tag)[new_ptr_inst]) { | |
| 29687 | switch (sema.air_instructions.items(.tag)[@intFromEnum(new_ptr_inst)]) { | |
| 29688 | 29688 | .optional_payload_ptr_set, .errunion_payload_ptr_set => { |
| 29689 | 29689 | const maybe_comptime_alloc = sema.maybe_comptime_allocs.getPtr(alloc_inst) orelse return; |
| 29690 | 29690 | try maybe_comptime_alloc.non_elideable_pointers.append(sema.arena, new_ptr_inst); |
| 29691 | 29691 | }, |
| 29692 | 29692 | .ptr_elem_ptr => { |
| 29693 | 29693 | const tmp_air = sema.getTmpAir(); |
| 29694 | const pl_idx = tmp_air.instructions.items(.data)[new_ptr_inst].ty_pl.payload; | |
| 29694 | const pl_idx = tmp_air.instructions.items(.data)[@intFromEnum(new_ptr_inst)].ty_pl.payload; | |
| 29695 | 29695 | const bin = tmp_air.extraData(Air.Bin, pl_idx).data; |
| 29696 | 29696 | const index_ref = bin.rhs; |
| 29697 | 29697 | |
| ... | ... | @@ -29713,15 +29713,15 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref { |
| 29713 | 29713 | const array_ty = sema.typeOf(ptr).childType(mod); |
| 29714 | 29714 | if (array_ty.zigTypeTag(mod) != .Array) return null; |
| 29715 | 29715 | var ptr_ref = ptr; |
| 29716 | var ptr_inst = Air.refToIndex(ptr_ref) orelse return null; | |
| 29716 | var ptr_inst = ptr_ref.toIndex() orelse return null; | |
| 29717 | 29717 | const air_datas = sema.air_instructions.items(.data); |
| 29718 | 29718 | 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; | |
| 29721 | 29721 | if (!sema.isKnownZigType(ptr_ref, .Pointer)) return null; |
| 29722 | 29722 | const child_ty = sema.typeOf(ptr_ref).childType(mod); |
| 29723 | 29723 | if (child_ty.zigTypeTag(mod) == .Vector) break child_ty; |
| 29724 | ptr_inst = Air.refToIndex(ptr_ref) orelse return null; | |
| 29724 | ptr_inst = ptr_ref.toIndex() orelse return null; | |
| 29725 | 29725 | } else return null; |
| 29726 | 29726 | |
| 29727 | 29727 | // We have a pointer-to-array and a pointer-to-vector. If the elements and |
| ... | ... | @@ -31631,7 +31631,7 @@ fn analyzeDeclVal( |
| 31631 | 31631 | } |
| 31632 | 31632 | const decl_ref = try sema.analyzeDeclRefInner(decl_index, false); |
| 31633 | 31633 | const result = try sema.analyzeLoad(block, src, decl_ref, src); |
| 31634 | if (Air.refToInterned(result) != null) { | |
| 31634 | if (result.toInterned() != null) { | |
| 31635 | 31635 | if (!block.is_typeof) { |
| 31636 | 31636 | try sema.decl_val_table.put(sema.gpa, decl_index, result); |
| 31637 | 31637 | } |
| ... | ... | @@ -31811,10 +31811,10 @@ fn analyzeLoad( |
| 31811 | 31811 | } |
| 31812 | 31812 | |
| 31813 | 31813 | if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) { |
| 31814 | const ptr_inst = Air.refToIndex(ptr).?; | |
| 31814 | const ptr_inst = ptr.toIndex().?; | |
| 31815 | 31815 | 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; | |
| 31818 | 31818 | const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data; |
| 31819 | 31819 | return block.addBinOp(.ptr_elem_val, bin_op.lhs, bin_op.rhs); |
| 31820 | 31820 | } |
| ... | ... | @@ -31932,8 +31932,8 @@ fn analyzeIsNonErrComptimeOnly( |
| 31932 | 31932 | return .bool_false; |
| 31933 | 31933 | } |
| 31934 | 31934 | |
| 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)]) { | |
| 31937 | 31937 | .wrap_errunion_payload => return .bool_true, |
| 31938 | 31938 | .wrap_errunion_err => return .bool_false, |
| 31939 | 31939 | else => {}, |
| ... | ... | @@ -37089,8 +37089,8 @@ fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void { |
| 37089 | 37089 | fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index { |
| 37090 | 37090 | const air_datas = sema.air_instructions.items(.data); |
| 37091 | 37091 | 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, | |
| 37094 | 37094 | else => return null, |
| 37095 | 37095 | } |
| 37096 | 37096 | } |
| ... | ... | @@ -38121,7 +38121,7 @@ fn errorSetMerge(sema: *Sema, lhs: Type, rhs: Type) !Type { |
| 38121 | 38121 | /// Avoids crashing the compiler when asking if inferred allocations are noreturn. |
| 38122 | 38122 | fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool { |
| 38123 | 38123 | if (ref == .unreachable_value) return true; |
| 38124 | if (Air.refToIndex(ref)) |inst| switch (sema.air_instructions.items(.tag)[inst]) { | |
| 38124 | if (ref.toIndex()) |inst| switch (sema.air_instructions.items(.tag)[@intFromEnum(inst)]) { | |
| 38125 | 38125 | .inferred_alloc, .inferred_alloc_comptime => return false, |
| 38126 | 38126 | else => {}, |
| 38127 | 38127 | }; |
| ... | ... | @@ -38130,7 +38130,7 @@ fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool { |
| 38130 | 38130 | |
| 38131 | 38131 | /// Avoids crashing the compiler when asking if inferred allocations are known to be a certain zig type. |
| 38132 | 38132 | fn isKnownZigType(sema: *Sema, ref: Air.Inst.Ref, tag: std.builtin.TypeId) bool { |
| 38133 | if (Air.refToIndex(ref)) |inst| switch (sema.air_instructions.items(.tag)[inst]) { | |
| 38133 | if (ref.toIndex()) |inst| switch (sema.air_instructions.items(.tag)[@intFromEnum(inst)]) { | |
| 38134 | 38134 | .inferred_alloc, .inferred_alloc_comptime => return false, |
| 38135 | 38135 | else => {}, |
| 38136 | 38136 | }; |
src/arch/aarch64/CodeGen.zig+124-124| ... | ... | @@ -287,7 +287,7 @@ const BigTomb = struct { |
| 287 | 287 | |
| 288 | 288 | fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void { |
| 289 | 289 | const dies = bt.lbt.feed(); |
| 290 | const op_index = Air.refToIndex(op_ref) orelse return; | |
| 290 | const op_index = op_ref.toIndex() orelse return; | |
| 291 | 291 | if (!dies) return; |
| 292 | 292 | bt.function.processDeath(op_index); |
| 293 | 293 | } |
| ... | ... | @@ -444,7 +444,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index { |
| 444 | 444 | |
| 445 | 445 | try self.mir_instructions.ensureUnusedCapacity(gpa, 1); |
| 446 | 446 | |
| 447 | const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len)); | |
| 447 | const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len); | |
| 448 | 448 | self.mir_instructions.appendAssumeCapacity(inst); |
| 449 | 449 | return result_index; |
| 450 | 450 | } |
| ... | ... | @@ -522,7 +522,7 @@ fn gen(self: *Self) !void { |
| 522 | 522 | // The first AIR instructions of the main body are guaranteed |
| 523 | 523 | // to be the functions arguments |
| 524 | 524 | const inst = self.air.getMainBody()[arg_index]; |
| 525 | assert(self.air.instructions.items(.tag)[inst] == .arg); | |
| 525 | assert(self.air.instructions.items(.tag)[@intFromEnum(inst)] == .arg); | |
| 526 | 526 | |
| 527 | 527 | const ty = self.typeOfIndex(inst); |
| 528 | 528 | |
| ... | ... | @@ -668,7 +668,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 668 | 668 | const old_air_bookkeeping = self.air_bookkeeping; |
| 669 | 669 | try self.ensureProcessDeathCapacity(Liveness.bpi); |
| 670 | 670 | |
| 671 | switch (air_tags[inst]) { | |
| 671 | switch (air_tags[@intFromEnum(inst)]) { | |
| 672 | 672 | // zig fmt: off |
| 673 | 673 | .add => try self.airBinOp(inst, .add), |
| 674 | 674 | .add_wrap => try self.airBinOp(inst, .add_wrap), |
| ... | ... | @@ -914,7 +914,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 914 | 914 | |
| 915 | 915 | if (std.debug.runtime_safety) { |
| 916 | 916 | if (self.air_bookkeeping < old_air_bookkeeping + 1) { |
| 917 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] }); | |
| 917 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] }); | |
| 918 | 918 | } |
| 919 | 919 | } |
| 920 | 920 | } |
| ... | ... | @@ -954,7 +954,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live |
| 954 | 954 | const dies = @as(u1, @truncate(tomb_bits)) != 0; |
| 955 | 955 | tomb_bits >>= 1; |
| 956 | 956 | if (!dies) continue; |
| 957 | const op_index = Air.refToIndex(op) orelse continue; | |
| 957 | const op_index = op.toIndex() orelse continue; | |
| 958 | 958 | self.processDeath(op_index); |
| 959 | 959 | } |
| 960 | 960 | const is_used = @as(u1, @truncate(tomb_bits)) == 0; |
| ... | ... | @@ -1160,19 +1160,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 1163 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1163 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1164 | 1164 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch}); |
| 1165 | 1165 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | fn airFpext(self: *Self, inst: Air.Inst.Index) !void { |
| 1169 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1169 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1170 | 1170 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch}); |
| 1171 | 1171 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | fn airIntCast(self: *Self, inst: Air.Inst.Index) !void { |
| 1175 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1175 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1176 | 1176 | if (self.liveness.isUnused(inst)) |
| 1177 | 1177 | return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none }); |
| 1178 | 1178 | |
| ... | ... | @@ -1277,7 +1277,7 @@ fn trunc( |
| 1277 | 1277 | defer if (lock) |reg| self.register_manager.unlockReg(reg); |
| 1278 | 1278 | |
| 1279 | 1279 | const dest_reg = if (maybe_inst) |inst| blk: { |
| 1280 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1280 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1281 | 1281 | |
| 1282 | 1282 | if (operand == .register and self.reuseOperand(inst, ty_op.operand, 0, operand)) { |
| 1283 | 1283 | break :blk self.registerAlias(operand_reg, dest_ty); |
| ... | ... | @@ -1299,7 +1299,7 @@ fn trunc( |
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | 1301 | fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 1302 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1302 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1303 | 1303 | const operand = try self.resolveInst(ty_op.operand); |
| 1304 | 1304 | const operand_ty = self.typeOf(ty_op.operand); |
| 1305 | 1305 | const dest_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -1312,14 +1312,14 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | 1314 | fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void { |
| 1315 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1315 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1316 | 1316 | const operand = try self.resolveInst(un_op); |
| 1317 | 1317 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand; |
| 1318 | 1318 | return self.finishAir(inst, result, .{ un_op, .none, .none }); |
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | 1321 | fn airNot(self: *Self, inst: Air.Inst.Index) !void { |
| 1322 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1322 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1323 | 1323 | const mod = self.bin_file.options.module.?; |
| 1324 | 1324 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1325 | 1325 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -1488,8 +1488,8 @@ fn minMax( |
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | 1490 | fn 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; | |
| 1493 | 1493 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 1494 | 1494 | const rhs_ty = self.typeOf(bin_op.rhs); |
| 1495 | 1495 | |
| ... | ... | @@ -1506,7 +1506,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void { |
| 1506 | 1506 | } |
| 1507 | 1507 | |
| 1508 | 1508 | fn airSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 1509 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1509 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1510 | 1510 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1511 | 1511 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1512 | 1512 | const ptr = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -1662,7 +1662,7 @@ fn allocRegs( |
| 1662 | 1662 | arg.reg.* = self.registerAlias(raw_reg, arg.ty); |
| 1663 | 1663 | } else { |
| 1664 | 1664 | const track_inst: ?Air.Inst.Index = switch (arg.bind) { |
| 1665 | .inst => |inst| Air.refToIndex(inst).?, | |
| 1665 | .inst => |inst| inst.toIndex().?, | |
| 1666 | 1666 | else => null, |
| 1667 | 1667 | }; |
| 1668 | 1668 | const raw_reg = try self.register_manager.allocReg(track_inst, gp); |
| ... | ... | @@ -1725,7 +1725,7 @@ fn allocRegs( |
| 1725 | 1725 | if (mcv != .register) { |
| 1726 | 1726 | if (arg.bind == .inst) { |
| 1727 | 1727 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 1728 | const inst = Air.refToIndex(arg.bind.inst).?; | |
| 1728 | const inst = arg.bind.inst.toIndex().?; | |
| 1729 | 1729 | |
| 1730 | 1730 | // Overwrite the MCValue associated with this inst |
| 1731 | 1731 | branch.inst_table.putAssumeCapacity(inst, .{ .register = arg.reg.* }); |
| ... | ... | @@ -2430,7 +2430,7 @@ fn ptrArithmetic( |
| 2430 | 2430 | } |
| 2431 | 2431 | |
| 2432 | 2432 | fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 2433 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2433 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2434 | 2434 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 2435 | 2435 | const rhs_ty = self.typeOf(bin_op.rhs); |
| 2436 | 2436 | |
| ... | ... | @@ -2480,7 +2480,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 2480 | 2480 | } |
| 2481 | 2481 | |
| 2482 | 2482 | fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 2483 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2483 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2484 | 2484 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2485 | 2485 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 2486 | 2486 | const rhs_ty = self.typeOf(bin_op.rhs); |
| ... | ... | @@ -2495,26 +2495,26 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void |
| 2495 | 2495 | } |
| 2496 | 2496 | |
| 2497 | 2497 | fn airAddSat(self: *Self, inst: Air.Inst.Index) !void { |
| 2498 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2498 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2499 | 2499 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch}); |
| 2500 | 2500 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2501 | 2501 | } |
| 2502 | 2502 | |
| 2503 | 2503 | fn airSubSat(self: *Self, inst: Air.Inst.Index) !void { |
| 2504 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2504 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2505 | 2505 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch}); |
| 2506 | 2506 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2507 | 2507 | } |
| 2508 | 2508 | |
| 2509 | 2509 | fn airMulSat(self: *Self, inst: Air.Inst.Index) !void { |
| 2510 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2510 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2511 | 2511 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch}); |
| 2512 | 2512 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2513 | 2513 | } |
| 2514 | 2514 | |
| 2515 | 2515 | fn 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; | |
| 2518 | 2518 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2519 | 2519 | const mod = self.bin_file.options.module.?; |
| 2520 | 2520 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| ... | ... | @@ -2641,7 +2641,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 2641 | 2641 | } |
| 2642 | 2642 | |
| 2643 | 2643 | fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 2644 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2644 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2645 | 2645 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2646 | 2646 | if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none }); |
| 2647 | 2647 | const mod = self.bin_file.options.module.?; |
| ... | ... | @@ -2865,7 +2865,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 2865 | 2865 | } |
| 2866 | 2866 | |
| 2867 | 2867 | fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 2868 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2868 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2869 | 2869 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2870 | 2870 | if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none }); |
| 2871 | 2871 | const mod = self.bin_file.options.module.?; |
| ... | ... | @@ -3000,13 +3000,13 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 3000 | 3000 | } |
| 3001 | 3001 | |
| 3002 | 3002 | fn airShlSat(self: *Self, inst: Air.Inst.Index) !void { |
| 3003 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3003 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3004 | 3004 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch}); |
| 3005 | 3005 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 3006 | 3006 | } |
| 3007 | 3007 | |
| 3008 | 3008 | fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 3009 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3009 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3010 | 3010 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3011 | 3011 | const optional_ty = self.typeOf(ty_op.operand); |
| 3012 | 3012 | const mcv = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -3042,13 +3042,13 @@ fn optionalPayload(self: *Self, inst: Air.Inst.Index, mcv: MCValue, optional_ty: |
| 3042 | 3042 | } |
| 3043 | 3043 | |
| 3044 | 3044 | fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3045 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3045 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3046 | 3046 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch}); |
| 3047 | 3047 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3048 | 3048 | } |
| 3049 | 3049 | |
| 3050 | 3050 | fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 3051 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3051 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3052 | 3052 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch}); |
| 3053 | 3053 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3054 | 3054 | } |
| ... | ... | @@ -3123,7 +3123,7 @@ fn errUnionErr( |
| 3123 | 3123 | } |
| 3124 | 3124 | |
| 3125 | 3125 | fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void { |
| 3126 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3126 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3127 | 3127 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3128 | 3128 | const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand }; |
| 3129 | 3129 | const error_union_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -3203,7 +3203,7 @@ fn errUnionPayload( |
| 3203 | 3203 | } |
| 3204 | 3204 | |
| 3205 | 3205 | fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 3206 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3206 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3207 | 3207 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3208 | 3208 | const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand }; |
| 3209 | 3209 | const error_union_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -3215,20 +3215,20 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 3215 | 3215 | |
| 3216 | 3216 | // *(E!T) -> E |
| 3217 | 3217 | fn airUnwrapErrErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3218 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3218 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3219 | 3219 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error ptr for {}", .{self.target.cpu.arch}); |
| 3220 | 3220 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3221 | 3221 | } |
| 3222 | 3222 | |
| 3223 | 3223 | // *(E!T) -> *T |
| 3224 | 3224 | fn airUnwrapErrPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3225 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3225 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3226 | 3226 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload ptr for {}", .{self.target.cpu.arch}); |
| 3227 | 3227 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3228 | 3228 | } |
| 3229 | 3229 | |
| 3230 | 3230 | fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 3231 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3231 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3232 | 3232 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch}); |
| 3233 | 3233 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3234 | 3234 | } |
| ... | ... | @@ -3253,7 +3253,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void { |
| 3253 | 3253 | |
| 3254 | 3254 | fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| 3255 | 3255 | const mod = self.bin_file.options.module.?; |
| 3256 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3256 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3257 | 3257 | |
| 3258 | 3258 | if (self.liveness.isUnused(inst)) { |
| 3259 | 3259 | return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none }); |
| ... | ... | @@ -3298,9 +3298,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| 3298 | 3298 | /// T to E!T |
| 3299 | 3299 | fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 3300 | 3300 | const mod = self.bin_file.options.module.?; |
| 3301 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3301 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3302 | 3302 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3303 | const error_union_ty = self.air.getRefType(ty_op.ty); | |
| 3303 | const error_union_ty = ty_op.ty.toType(); | |
| 3304 | 3304 | const error_ty = error_union_ty.errorUnionSet(mod); |
| 3305 | 3305 | const payload_ty = error_union_ty.errorUnionPayload(mod); |
| 3306 | 3306 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -3321,10 +3321,10 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 3321 | 3321 | |
| 3322 | 3322 | /// E to E!T |
| 3323 | 3323 | fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 3324 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3324 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3325 | 3325 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3326 | 3326 | const mod = self.bin_file.options.module.?; |
| 3327 | const error_union_ty = self.air.getRefType(ty_op.ty); | |
| 3327 | const error_union_ty = ty_op.ty.toType(); | |
| 3328 | 3328 | const error_ty = error_union_ty.errorUnionSet(mod); |
| 3329 | 3329 | const payload_ty = error_union_ty.errorUnionPayload(mod); |
| 3330 | 3330 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -3361,7 +3361,7 @@ fn slicePtr(mcv: MCValue) MCValue { |
| 3361 | 3361 | } |
| 3362 | 3362 | |
| 3363 | 3363 | fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3364 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3364 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3365 | 3365 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3366 | 3366 | const mcv = try self.resolveInst(ty_op.operand); |
| 3367 | 3367 | break :result slicePtr(mcv); |
| ... | ... | @@ -3370,7 +3370,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3370 | 3370 | } |
| 3371 | 3371 | |
| 3372 | 3372 | fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { |
| 3373 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3373 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3374 | 3374 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3375 | 3375 | const ptr_bits = 64; |
| 3376 | 3376 | const ptr_bytes = @divExact(ptr_bits, 8); |
| ... | ... | @@ -3394,7 +3394,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { |
| 3394 | 3394 | } |
| 3395 | 3395 | |
| 3396 | 3396 | fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3397 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3397 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3398 | 3398 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3399 | 3399 | const ptr_bits = 64; |
| 3400 | 3400 | const ptr_bytes = @divExact(ptr_bits, 8); |
| ... | ... | @@ -3411,7 +3411,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3411 | 3411 | } |
| 3412 | 3412 | |
| 3413 | 3413 | fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3414 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3414 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3415 | 3415 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3416 | 3416 | const mcv = try self.resolveInst(ty_op.operand); |
| 3417 | 3417 | switch (mcv) { |
| ... | ... | @@ -3427,7 +3427,7 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3427 | 3427 | |
| 3428 | 3428 | fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 3429 | 3429 | const mod = self.bin_file.options.module.?; |
| 3430 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3430 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3431 | 3431 | const slice_ty = self.typeOf(bin_op.lhs); |
| 3432 | 3432 | const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: { |
| 3433 | 3433 | const ptr_ty = slice_ty.slicePtrFieldType(mod); |
| ... | ... | @@ -3467,7 +3467,7 @@ fn ptrElemVal( |
| 3467 | 3467 | } |
| 3468 | 3468 | |
| 3469 | 3469 | fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3470 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3470 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3471 | 3471 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3472 | 3472 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3473 | 3473 | const slice_mcv = try self.resolveInst(extra.lhs); |
| ... | ... | @@ -3486,14 +3486,14 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3486 | 3486 | } |
| 3487 | 3487 | |
| 3488 | 3488 | fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 3489 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3489 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3490 | 3490 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch}); |
| 3491 | 3491 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 3492 | 3492 | } |
| 3493 | 3493 | |
| 3494 | 3494 | fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 3495 | 3495 | const mod = self.bin_file.options.module.?; |
| 3496 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3496 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3497 | 3497 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 3498 | 3498 | const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: { |
| 3499 | 3499 | const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs }; |
| ... | ... | @@ -3505,7 +3505,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 3505 | 3505 | } |
| 3506 | 3506 | |
| 3507 | 3507 | fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3508 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3508 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3509 | 3509 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3510 | 3510 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3511 | 3511 | const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs }; |
| ... | ... | @@ -3521,55 +3521,55 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3521 | 3521 | } |
| 3522 | 3522 | |
| 3523 | 3523 | fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 3524 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3524 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3525 | 3525 | _ = bin_op; |
| 3526 | 3526 | return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch}); |
| 3527 | 3527 | } |
| 3528 | 3528 | |
| 3529 | 3529 | fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 3530 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3530 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3531 | 3531 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch}); |
| 3532 | 3532 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3533 | 3533 | } |
| 3534 | 3534 | |
| 3535 | 3535 | fn airClz(self: *Self, inst: Air.Inst.Index) !void { |
| 3536 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3536 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3537 | 3537 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch}); |
| 3538 | 3538 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3539 | 3539 | } |
| 3540 | 3540 | |
| 3541 | 3541 | fn airCtz(self: *Self, inst: Air.Inst.Index) !void { |
| 3542 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3542 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3543 | 3543 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch}); |
| 3544 | 3544 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3545 | 3545 | } |
| 3546 | 3546 | |
| 3547 | 3547 | fn airPopcount(self: *Self, inst: Air.Inst.Index) !void { |
| 3548 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3548 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3549 | 3549 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch}); |
| 3550 | 3550 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3551 | 3551 | } |
| 3552 | 3552 | |
| 3553 | 3553 | fn airAbs(self: *Self, inst: Air.Inst.Index) !void { |
| 3554 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3554 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3555 | 3555 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch}); |
| 3556 | 3556 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3557 | 3557 | } |
| 3558 | 3558 | |
| 3559 | 3559 | fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { |
| 3560 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3560 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3561 | 3561 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch}); |
| 3562 | 3562 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3563 | 3563 | } |
| 3564 | 3564 | |
| 3565 | 3565 | fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void { |
| 3566 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3566 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3567 | 3567 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch}); |
| 3568 | 3568 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 3569 | 3569 | } |
| 3570 | 3570 | |
| 3571 | 3571 | fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void { |
| 3572 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 3572 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 3573 | 3573 | const result: MCValue = if (self.liveness.isUnused(inst)) |
| 3574 | 3574 | .dead |
| 3575 | 3575 | else |
| ... | ... | @@ -3609,7 +3609,7 @@ fn reuseOperand( |
| 3609 | 3609 | |
| 3610 | 3610 | // That makes us responsible for doing the rest of the stuff that processDeath would have done. |
| 3611 | 3611 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 3612 | branch.inst_table.putAssumeCapacity(Air.refToIndex(operand).?, .dead); | |
| 3612 | branch.inst_table.putAssumeCapacity(operand.toIndex().?, .dead); | |
| 3613 | 3613 | |
| 3614 | 3614 | return true; |
| 3615 | 3615 | } |
| ... | ... | @@ -3864,7 +3864,7 @@ fn genInlineMemsetCode( |
| 3864 | 3864 | |
| 3865 | 3865 | fn airLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 3866 | 3866 | const mod = self.bin_file.options.module.?; |
| 3867 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3867 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3868 | 3868 | const elem_ty = self.typeOfIndex(inst); |
| 3869 | 3869 | const elem_size = elem_ty.abiSize(mod); |
| 3870 | 3870 | const result: MCValue = result: { |
| ... | ... | @@ -4066,7 +4066,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 4066 | 4066 | } else { |
| 4067 | 4067 | // TODO if the value is undef, don't lower this instruction |
| 4068 | 4068 | } |
| 4069 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 4069 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4070 | 4070 | const ptr = try self.resolveInst(bin_op.lhs); |
| 4071 | 4071 | const value = try self.resolveInst(bin_op.rhs); |
| 4072 | 4072 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -4078,14 +4078,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 4078 | 4078 | } |
| 4079 | 4079 | |
| 4080 | 4080 | fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4081 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 4081 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4082 | 4082 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 4083 | 4083 | const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index); |
| 4084 | 4084 | return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none }); |
| 4085 | 4085 | } |
| 4086 | 4086 | |
| 4087 | 4087 | fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void { |
| 4088 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4088 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4089 | 4089 | const result = try self.structFieldPtr(inst, ty_op.operand, index); |
| 4090 | 4090 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 4091 | 4091 | } |
| ... | ... | @@ -4112,7 +4112,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde |
| 4112 | 4112 | } |
| 4113 | 4113 | |
| 4114 | 4114 | fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 4115 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 4115 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4116 | 4116 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 4117 | 4117 | const operand = extra.struct_operand; |
| 4118 | 4118 | const index = extra.field_index; |
| ... | ... | @@ -4168,11 +4168,11 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 4168 | 4168 | |
| 4169 | 4169 | fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4170 | 4170 | const mod = self.bin_file.options.module.?; |
| 4171 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 4171 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4172 | 4172 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 4173 | 4173 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4174 | 4174 | const field_ptr = try self.resolveInst(extra.field_ptr); |
| 4175 | const struct_ty = self.air.getRefType(ty_pl.ty).childType(mod); | |
| 4175 | const struct_ty = ty_pl.ty.toType().childType(mod); | |
| 4176 | 4176 | const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, mod))); |
| 4177 | 4177 | switch (field_ptr) { |
| 4178 | 4178 | .ptr_stack_offset => |off| { |
| ... | ... | @@ -4197,8 +4197,8 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { |
| 4197 | 4197 | |
| 4198 | 4198 | const mod = self.bin_file.options.module.?; |
| 4199 | 4199 | 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; | |
| 4202 | 4202 | const name = mod.getParamName(self.func_index, src_index); |
| 4203 | 4203 | |
| 4204 | 4204 | try self.dbg_info_relocs.append(self.gpa, .{ |
| ... | ... | @@ -4245,7 +4245,7 @@ fn airFence(self: *Self) !void { |
| 4245 | 4245 | |
| 4246 | 4246 | fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { |
| 4247 | 4247 | if (modifier == .always_tail) return self.fail("TODO implement tail calls for aarch64", .{}); |
| 4248 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4248 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4249 | 4249 | const callee = pl_op.operand; |
| 4250 | 4250 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 4251 | 4251 | const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len])); |
| ... | ... | @@ -4423,7 +4423,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 4423 | 4423 | |
| 4424 | 4424 | fn airRet(self: *Self, inst: Air.Inst.Index) !void { |
| 4425 | 4425 | const mod = self.bin_file.options.module.?; |
| 4426 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4426 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4427 | 4427 | const operand = try self.resolveInst(un_op); |
| 4428 | 4428 | const ret_ty = self.fn_type.fnReturnType(mod); |
| 4429 | 4429 | |
| ... | ... | @@ -4455,7 +4455,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void { |
| 4455 | 4455 | |
| 4456 | 4456 | fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 4457 | 4457 | const mod = self.bin_file.options.module.?; |
| 4458 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4458 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4459 | 4459 | const ptr = try self.resolveInst(un_op); |
| 4460 | 4460 | const ptr_ty = self.typeOf(un_op); |
| 4461 | 4461 | const ret_ty = self.fn_type.fnReturnType(mod); |
| ... | ... | @@ -4476,8 +4476,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 4476 | 4476 | // here. Else we need to load the result from the location |
| 4477 | 4477 | // pointed to by the operand and store it to the result |
| 4478 | 4478 | // 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) { | |
| 4481 | 4481 | const abi_size = @as(u32, @intCast(ret_ty.abiSize(mod))); |
| 4482 | 4482 | const abi_align = ret_ty.abiAlignment(mod); |
| 4483 | 4483 | |
| ... | ... | @@ -4497,7 +4497,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 4497 | 4497 | } |
| 4498 | 4498 | |
| 4499 | 4499 | fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void { |
| 4500 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 4500 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4501 | 4501 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 4502 | 4502 | |
| 4503 | 4503 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: { |
| ... | ... | @@ -4599,7 +4599,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void { |
| 4599 | 4599 | } |
| 4600 | 4600 | |
| 4601 | 4601 | fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 4602 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4602 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4603 | 4603 | const operand = try self.resolveInst(un_op); |
| 4604 | 4604 | _ = operand; |
| 4605 | 4605 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch}); |
| ... | ... | @@ -4607,7 +4607,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 4607 | 4607 | } |
| 4608 | 4608 | |
| 4609 | 4609 | fn 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; | |
| 4611 | 4611 | |
| 4612 | 4612 | _ = try self.addInst(.{ |
| 4613 | 4613 | .tag = .dbg_line, |
| ... | ... | @@ -4621,7 +4621,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void { |
| 4621 | 4621 | } |
| 4622 | 4622 | |
| 4623 | 4623 | fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 4624 | const ty_fn = self.air.instructions.items(.data)[inst].ty_fn; | |
| 4624 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 4625 | 4625 | const mod = self.bin_file.options.module.?; |
| 4626 | 4626 | const func = mod.funcInfo(ty_fn.func); |
| 4627 | 4627 | // TODO emit debug info for function change |
| ... | ... | @@ -4635,9 +4635,9 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 4635 | 4635 | } |
| 4636 | 4636 | |
| 4637 | 4637 | fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 4638 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4638 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4639 | 4639 | const operand = pl_op.operand; |
| 4640 | const tag = self.air.instructions.items(.tag)[inst]; | |
| 4640 | const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)]; | |
| 4641 | 4641 | const ty = self.typeOf(operand); |
| 4642 | 4642 | const mcv = try self.resolveInst(operand); |
| 4643 | 4643 | const name = self.air.nullTerminatedString(pl_op.payload); |
| ... | ... | @@ -4686,11 +4686,11 @@ fn condBr(self: *Self, condition: MCValue) !Mir.Inst.Index { |
| 4686 | 4686 | } |
| 4687 | 4687 | |
| 4688 | 4688 | fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4689 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4689 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4690 | 4690 | const cond = try self.resolveInst(pl_op.operand); |
| 4691 | 4691 | const extra = self.air.extraData(Air.CondBr, pl_op.payload); |
| 4692 | const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len]; | |
| 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]); | |
| 4694 | 4694 | const liveness_condbr = self.liveness.getCondBr(inst); |
| 4695 | 4695 | |
| 4696 | 4696 | const reloc = try self.condBr(cond); |
| ... | ... | @@ -4699,7 +4699,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4699 | 4699 | // that death now instead of later as this has an effect on |
| 4700 | 4700 | // whether it needs to be spilled in the branches |
| 4701 | 4701 | if (self.liveness.operandDies(inst, 0)) { |
| 4702 | if (Air.refToIndex(pl_op.operand)) |op_index| { | |
| 4702 | if (pl_op.operand.toIndex()) |op_index| { | |
| 4703 | 4703 | self.processDeath(op_index); |
| 4704 | 4704 | } |
| 4705 | 4705 | } |
| ... | ... | @@ -4917,7 +4917,7 @@ fn isNonErr( |
| 4917 | 4917 | } |
| 4918 | 4918 | |
| 4919 | 4919 | fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 4920 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4920 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4921 | 4921 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4922 | 4922 | const operand = try self.resolveInst(un_op); |
| 4923 | 4923 | const operand_ty = self.typeOf(un_op); |
| ... | ... | @@ -4929,7 +4929,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 4929 | 4929 | |
| 4930 | 4930 | fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4931 | 4931 | const mod = self.bin_file.options.module.?; |
| 4932 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4932 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4933 | 4933 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4934 | 4934 | const operand_ptr = try self.resolveInst(un_op); |
| 4935 | 4935 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -4944,7 +4944,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4944 | 4944 | } |
| 4945 | 4945 | |
| 4946 | 4946 | fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 4947 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4947 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4948 | 4948 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4949 | 4949 | const operand = try self.resolveInst(un_op); |
| 4950 | 4950 | const operand_ty = self.typeOf(un_op); |
| ... | ... | @@ -4956,7 +4956,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 4956 | 4956 | |
| 4957 | 4957 | fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4958 | 4958 | const mod = self.bin_file.options.module.?; |
| 4959 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4959 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4960 | 4960 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4961 | 4961 | const operand_ptr = try self.resolveInst(un_op); |
| 4962 | 4962 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -4971,7 +4971,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4971 | 4971 | } |
| 4972 | 4972 | |
| 4973 | 4973 | fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4974 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4974 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4975 | 4975 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4976 | 4976 | const error_union_bind: ReadArg.Bind = .{ .inst = un_op }; |
| 4977 | 4977 | const error_union_ty = self.typeOf(un_op); |
| ... | ... | @@ -4983,7 +4983,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4983 | 4983 | |
| 4984 | 4984 | fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4985 | 4985 | const mod = self.bin_file.options.module.?; |
| 4986 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4986 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4987 | 4987 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4988 | 4988 | const operand_ptr = try self.resolveInst(un_op); |
| 4989 | 4989 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -4998,7 +4998,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4998 | 4998 | } |
| 4999 | 4999 | |
| 5000 | 5000 | fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 5001 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5001 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5002 | 5002 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 5003 | 5003 | const error_union_bind: ReadArg.Bind = .{ .inst = un_op }; |
| 5004 | 5004 | const error_union_ty = self.typeOf(un_op); |
| ... | ... | @@ -5010,7 +5010,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 5010 | 5010 | |
| 5011 | 5011 | fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5012 | 5012 | const mod = self.bin_file.options.module.?; |
| 5013 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5013 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5014 | 5014 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 5015 | 5015 | const operand_ptr = try self.resolveInst(un_op); |
| 5016 | 5016 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -5026,9 +5026,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5026 | 5026 | |
| 5027 | 5027 | fn airLoop(self: *Self, inst: Air.Inst.Index) !void { |
| 5028 | 5028 | // A loop is a setup to be able to jump back to the beginning. |
| 5029 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5029 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5030 | 5030 | const loop = self.air.extraData(Air.Block, ty_pl.payload); |
| 5031 | const body = self.air.extra[loop.end..][0..loop.data.body_len]; | |
| 5031 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]); | |
| 5032 | 5032 | const start_index = @as(u32, @intCast(self.mir_instructions.len)); |
| 5033 | 5033 | |
| 5034 | 5034 | try self.genBody(body); |
| ... | ... | @@ -5058,9 +5058,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 5058 | 5058 | }); |
| 5059 | 5059 | defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa); |
| 5060 | 5060 | |
| 5061 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5061 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5062 | 5062 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 5063 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 5063 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 5064 | 5064 | try self.genBody(body); |
| 5065 | 5065 | |
| 5066 | 5066 | // relocations for `br` instructions |
| ... | ... | @@ -5080,7 +5080,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 5080 | 5080 | } |
| 5081 | 5081 | |
| 5082 | 5082 | fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5083 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 5083 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 5084 | 5084 | const condition_ty = self.typeOf(pl_op.operand); |
| 5085 | 5085 | const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload); |
| 5086 | 5086 | const liveness = try self.liveness.getSwitchBr( |
| ... | ... | @@ -5096,7 +5096,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5096 | 5096 | const case = self.air.extraData(Air.SwitchBr.Case, extra_index); |
| 5097 | 5097 | const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len])); |
| 5098 | 5098 | assert(items.len > 0); |
| 5099 | const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len]; | |
| 5099 | const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]); | |
| 5100 | 5100 | extra_index = case.end + items.len + case_body.len; |
| 5101 | 5101 | |
| 5102 | 5102 | // For every item, we compare it to condition and branch into |
| ... | ... | @@ -5167,7 +5167,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5167 | 5167 | } |
| 5168 | 5168 | |
| 5169 | 5169 | if (switch_br.data.else_body_len > 0) { |
| 5170 | const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len]; | |
| 5170 | const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]); | |
| 5171 | 5171 | |
| 5172 | 5172 | // Capture the state of register and stack allocation state so that we can revert to it. |
| 5173 | 5173 | const parent_next_stack_offset = self.next_stack_offset; |
| ... | ... | @@ -5212,15 +5212,15 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5212 | 5212 | fn performReloc(self: *Self, inst: Mir.Inst.Index) !void { |
| 5213 | 5213 | const tag = self.mir_instructions.items(.tag)[inst]; |
| 5214 | 5214 | 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), | |
| 5218 | 5218 | else => unreachable, |
| 5219 | 5219 | } |
| 5220 | 5220 | } |
| 5221 | 5221 | |
| 5222 | 5222 | fn airBr(self: *Self, inst: Air.Inst.Index) !void { |
| 5223 | const branch = self.air.instructions.items(.data)[inst].br; | |
| 5223 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 5224 | 5224 | try self.br(branch.block_inst, branch.operand); |
| 5225 | 5225 | return self.finishAir(inst, .dead, .{ branch.operand, .none, .none }); |
| 5226 | 5226 | } |
| ... | ... | @@ -5263,7 +5263,7 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void { |
| 5263 | 5263 | } |
| 5264 | 5264 | |
| 5265 | 5265 | fn airAsm(self: *Self, inst: Air.Inst.Index) !void { |
| 5266 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5266 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5267 | 5267 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); |
| 5268 | 5268 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; |
| 5269 | 5269 | const clobbers_len = @as(u31, @truncate(extra.data.flags)); |
| ... | ... | @@ -5907,13 +5907,13 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I |
| 5907 | 5907 | } |
| 5908 | 5908 | |
| 5909 | 5909 | fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5910 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5910 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5911 | 5911 | const result = try self.resolveInst(un_op); |
| 5912 | 5912 | return self.finishAir(inst, result, .{ un_op, .none, .none }); |
| 5913 | 5913 | } |
| 5914 | 5914 | |
| 5915 | 5915 | fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 5916 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5916 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5917 | 5917 | const result = if (self.liveness.isUnused(inst)) .dead else result: { |
| 5918 | 5918 | const operand = try self.resolveInst(ty_op.operand); |
| 5919 | 5919 | if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand; |
| ... | ... | @@ -5935,7 +5935,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 5935 | 5935 | |
| 5936 | 5936 | fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 5937 | 5937 | const mod = self.bin_file.options.module.?; |
| 5938 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5938 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5939 | 5939 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 5940 | 5940 | const ptr_ty = self.typeOf(ty_op.operand); |
| 5941 | 5941 | const ptr = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -5951,7 +5951,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 5951 | 5951 | } |
| 5952 | 5952 | |
| 5953 | 5953 | fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 5954 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5954 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5955 | 5955 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{ |
| 5956 | 5956 | self.target.cpu.arch, |
| 5957 | 5957 | }); |
| ... | ... | @@ -5959,7 +5959,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 5959 | 5959 | } |
| 5960 | 5960 | |
| 5961 | 5961 | fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 5962 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5962 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5963 | 5963 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{ |
| 5964 | 5964 | self.target.cpu.arch, |
| 5965 | 5965 | }); |
| ... | ... | @@ -5967,7 +5967,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 5967 | 5967 | } |
| 5968 | 5968 | |
| 5969 | 5969 | fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void { |
| 5970 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5970 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5971 | 5971 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 5972 | 5972 | _ = extra; |
| 5973 | 5973 | |
| ... | ... | @@ -6008,7 +6008,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void { |
| 6008 | 6008 | } |
| 6009 | 6009 | |
| 6010 | 6010 | fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 6011 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 6011 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 6012 | 6012 | const operand = try self.resolveInst(un_op); |
| 6013 | 6013 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 6014 | 6014 | _ = operand; |
| ... | ... | @@ -6018,7 +6018,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 6018 | 6018 | } |
| 6019 | 6019 | |
| 6020 | 6020 | fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 6021 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 6021 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 6022 | 6022 | const operand = try self.resolveInst(un_op); |
| 6023 | 6023 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 6024 | 6024 | _ = operand; |
| ... | ... | @@ -6028,27 +6028,27 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 6028 | 6028 | } |
| 6029 | 6029 | |
| 6030 | 6030 | fn airSplat(self: *Self, inst: Air.Inst.Index) !void { |
| 6031 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6031 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6032 | 6032 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for {}", .{self.target.cpu.arch}); |
| 6033 | 6033 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 6034 | 6034 | } |
| 6035 | 6035 | |
| 6036 | 6036 | fn airSelect(self: *Self, inst: Air.Inst.Index) !void { |
| 6037 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 6037 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6038 | 6038 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 6039 | 6039 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for {}", .{self.target.cpu.arch}); |
| 6040 | 6040 | return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs }); |
| 6041 | 6041 | } |
| 6042 | 6042 | |
| 6043 | 6043 | fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { |
| 6044 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6044 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6045 | 6045 | const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data; |
| 6046 | 6046 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for {}", .{self.target.cpu.arch}); |
| 6047 | 6047 | return self.finishAir(inst, result, .{ extra.a, extra.b, .none }); |
| 6048 | 6048 | } |
| 6049 | 6049 | |
| 6050 | 6050 | fn airReduce(self: *Self, inst: Air.Inst.Index) !void { |
| 6051 | const reduce = self.air.instructions.items(.data)[inst].reduce; | |
| 6051 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; | |
| 6052 | 6052 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for aarch64", .{}); |
| 6053 | 6053 | return self.finishAir(inst, result, .{ reduce.operand, .none, .none }); |
| 6054 | 6054 | } |
| ... | ... | @@ -6057,7 +6057,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 6057 | 6057 | const mod = self.bin_file.options.module.?; |
| 6058 | 6058 | const vector_ty = self.typeOfIndex(inst); |
| 6059 | 6059 | const len = vector_ty.vectorLen(mod); |
| 6060 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6060 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6061 | 6061 | const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len])); |
| 6062 | 6062 | const result: MCValue = res: { |
| 6063 | 6063 | if (self.liveness.isUnused(inst)) break :res MCValue.dead; |
| ... | ... | @@ -6077,19 +6077,19 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 6077 | 6077 | } |
| 6078 | 6078 | |
| 6079 | 6079 | fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void { |
| 6080 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6080 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6081 | 6081 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 6082 | 6082 | _ = extra; |
| 6083 | 6083 | return self.fail("TODO implement airUnionInit for aarch64", .{}); |
| 6084 | 6084 | } |
| 6085 | 6085 | |
| 6086 | 6086 | fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void { |
| 6087 | const prefetch = self.air.instructions.items(.data)[inst].prefetch; | |
| 6087 | const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; | |
| 6088 | 6088 | return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none }); |
| 6089 | 6089 | } |
| 6090 | 6090 | |
| 6091 | 6091 | fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void { |
| 6092 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 6092 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6093 | 6093 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 6094 | 6094 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 6095 | 6095 | return self.fail("TODO implement airMulAdd for aarch64", .{}); |
| ... | ... | @@ -6099,9 +6099,9 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void { |
| 6099 | 6099 | |
| 6100 | 6100 | fn airTry(self: *Self, inst: Air.Inst.Index) !void { |
| 6101 | 6101 | const mod = self.bin_file.options.module.?; |
| 6102 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 6102 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6103 | 6103 | const extra = self.air.extraData(Air.Try, pl_op.payload); |
| 6104 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 6104 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 6105 | 6105 | const result: MCValue = result: { |
| 6106 | 6106 | const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand }; |
| 6107 | 6107 | const error_union_ty = self.typeOf(pl_op.operand); |
| ... | ... | @@ -6126,7 +6126,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void { |
| 6126 | 6126 | } |
| 6127 | 6127 | |
| 6128 | 6128 | fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 6129 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6129 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6130 | 6130 | const extra = self.air.extraData(Air.TryPtr, ty_pl.payload); |
| 6131 | 6131 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; |
| 6132 | 6132 | _ = body; |
| ... | ... | @@ -6142,7 +6142,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue { |
| 6142 | 6142 | if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod)) |
| 6143 | 6143 | return MCValue{ .none = {} }; |
| 6144 | 6144 | |
| 6145 | const inst_index = Air.refToIndex(inst) orelse return self.genTypedValue(.{ | |
| 6145 | const inst_index = inst.toIndex() orelse return self.genTypedValue(.{ | |
| 6146 | 6146 | .ty = inst_ty, |
| 6147 | 6147 | .val = (try self.air.value(inst, mod)).?, |
| 6148 | 6148 | }); |
src/arch/arm/CodeGen.zig+200-200| ... | ... | @@ -200,7 +200,7 @@ const BigTomb = struct { |
| 200 | 200 | |
| 201 | 201 | fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void { |
| 202 | 202 | const dies = bt.lbt.feed(); |
| 203 | const op_index = Air.refToIndex(op_ref) orelse return; | |
| 203 | const op_index = op_ref.toIndex() orelse return; | |
| 204 | 204 | if (!dies) return; |
| 205 | 205 | bt.function.processDeath(op_index); |
| 206 | 206 | } |
| ... | ... | @@ -450,7 +450,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index { |
| 450 | 450 | |
| 451 | 451 | try self.mir_instructions.ensureUnusedCapacity(gpa, 1); |
| 452 | 452 | |
| 453 | const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len)); | |
| 453 | const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len); | |
| 454 | 454 | self.mir_instructions.appendAssumeCapacity(inst); |
| 455 | 455 | return result_index; |
| 456 | 456 | } |
| ... | ... | @@ -470,11 +470,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 { |
| 470 | 470 | |
| 471 | 471 | pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 { |
| 472 | 472 | const fields = std.meta.fields(@TypeOf(extra)); |
| 473 | const result = @as(u32, @intCast(self.mir_extra.items.len)); | |
| 473 | const result: u32 = @intCast(self.mir_extra.items.len); | |
| 474 | 474 | inline for (fields) |field| { |
| 475 | 475 | self.mir_extra.appendAssumeCapacity(switch (field.type) { |
| 476 | 476 | u32 => @field(extra, field.name), |
| 477 | i32 => @as(u32, @bitCast(@field(extra, field.name))), | |
| 477 | i32 => @bitCast(@field(extra, field.name)), | |
| 478 | 478 | else => @compileError("bad field type"), |
| 479 | 479 | }); |
| 480 | 480 | } |
| ... | ... | @@ -522,11 +522,11 @@ fn gen(self: *Self) !void { |
| 522 | 522 | // The first AIR instructions of the main body are guaranteed |
| 523 | 523 | // to be the functions arguments |
| 524 | 524 | const inst = self.air.getMainBody()[arg_index]; |
| 525 | assert(self.air.instructions.items(.tag)[inst] == .arg); | |
| 525 | assert(self.air.instructions.items(.tag)[@intFromEnum(inst)] == .arg); | |
| 526 | 526 | |
| 527 | 527 | const ty = self.typeOfIndex(inst); |
| 528 | 528 | |
| 529 | const abi_size = @as(u32, @intCast(ty.abiSize(mod))); | |
| 529 | const abi_size: u32 = @intCast(ty.abiSize(mod)); | |
| 530 | 530 | const abi_align = ty.abiAlignment(mod); |
| 531 | 531 | const stack_offset = try self.allocMem(abi_size, abi_align, inst); |
| 532 | 532 | try self.genSetStack(ty, stack_offset, MCValue{ .register = reg }); |
| ... | ... | @@ -592,7 +592,7 @@ fn gen(self: *Self) !void { |
| 592 | 592 | for (self.exitlude_jump_relocs.items) |jmp_reloc| { |
| 593 | 593 | self.mir_instructions.set(jmp_reloc, .{ |
| 594 | 594 | .tag = .b, |
| 595 | .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len)) }, | |
| 595 | .data = .{ .inst = @intCast(self.mir_instructions.len) }, | |
| 596 | 596 | }); |
| 597 | 597 | } |
| 598 | 598 | |
| ... | ... | @@ -654,7 +654,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 654 | 654 | const old_air_bookkeeping = self.air_bookkeeping; |
| 655 | 655 | try self.ensureProcessDeathCapacity(Liveness.bpi); |
| 656 | 656 | |
| 657 | switch (air_tags[inst]) { | |
| 657 | switch (air_tags[@intFromEnum(inst)]) { | |
| 658 | 658 | // zig fmt: off |
| 659 | 659 | .add, => try self.airBinOp(inst, .add), |
| 660 | 660 | .add_wrap => try self.airBinOp(inst, .add_wrap), |
| ... | ... | @@ -900,7 +900,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 900 | 900 | |
| 901 | 901 | if (std.debug.runtime_safety) { |
| 902 | 902 | if (self.air_bookkeeping < old_air_bookkeeping + 1) { |
| 903 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] }); | |
| 903 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] }); | |
| 904 | 904 | } |
| 905 | 905 | } |
| 906 | 906 | } |
| ... | ... | @@ -942,7 +942,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live |
| 942 | 942 | const dies = @as(u1, @truncate(tomb_bits)) != 0; |
| 943 | 943 | tomb_bits >>= 1; |
| 944 | 944 | if (!dies) continue; |
| 945 | const op_index = Air.refToIndex(op) orelse continue; | |
| 945 | const op_index = op.toIndex() orelse continue; | |
| 946 | 946 | self.processDeath(op_index); |
| 947 | 947 | } |
| 948 | 948 | const is_used = @as(u1, @truncate(tomb_bits)) == 0; |
| ... | ... | @@ -1018,7 +1018,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 { |
| 1018 | 1018 | // return the stack offset 0. Stack offset 0 will be where all |
| 1019 | 1019 | // zero-sized stack allocations live as non-zero-sized |
| 1020 | 1020 | // allocations will always have an offset > 0. |
| 1021 | return @as(u32, 0); | |
| 1021 | return 0; | |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | const abi_size = math.cast(u32, elem_ty.abiSize(mod)) orelse { |
| ... | ... | @@ -1139,20 +1139,20 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 1142 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1142 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1143 | 1143 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch}); |
| 1144 | 1144 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | fn airFpext(self: *Self, inst: Air.Inst.Index) !void { |
| 1148 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1148 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1149 | 1149 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch}); |
| 1150 | 1150 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | fn airIntCast(self: *Self, inst: Air.Inst.Index) !void { |
| 1154 | 1154 | const mod = self.bin_file.options.module.?; |
| 1155 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1155 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1156 | 1156 | if (self.liveness.isUnused(inst)) |
| 1157 | 1157 | return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none }); |
| 1158 | 1158 | |
| ... | ... | @@ -1204,7 +1204,7 @@ fn truncRegister( |
| 1204 | 1204 | .rd = dest_reg, |
| 1205 | 1205 | .rn = operand_reg, |
| 1206 | 1206 | .lsb = 0, |
| 1207 | .width = @as(u6, @intCast(int_bits)), | |
| 1207 | .width = @intCast(int_bits), | |
| 1208 | 1208 | } }, |
| 1209 | 1209 | }); |
| 1210 | 1210 | } |
| ... | ... | @@ -1260,7 +1260,7 @@ fn trunc( |
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | 1262 | fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 1263 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1263 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1264 | 1264 | const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand }; |
| 1265 | 1265 | const operand_ty = self.typeOf(ty_op.operand); |
| 1266 | 1266 | const dest_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -1273,14 +1273,14 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void { |
| 1276 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1276 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1277 | 1277 | const operand = try self.resolveInst(un_op); |
| 1278 | 1278 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand; |
| 1279 | 1279 | return self.finishAir(inst, result, .{ un_op, .none, .none }); |
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | fn airNot(self: *Self, inst: Air.Inst.Index) !void { |
| 1283 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1283 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1284 | 1284 | const mod = self.bin_file.options.module.?; |
| 1285 | 1285 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1286 | 1286 | const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand }; |
| ... | ... | @@ -1465,8 +1465,8 @@ fn minMax( |
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | 1467 | fn 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; | |
| 1470 | 1470 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 1471 | 1471 | const rhs_ty = self.typeOf(bin_op.rhs); |
| 1472 | 1472 | |
| ... | ... | @@ -1483,7 +1483,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void { |
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | fn airSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 1486 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1486 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1487 | 1487 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1488 | 1488 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1489 | 1489 | const ptr = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -1500,7 +1500,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 1500 | 1500 | } |
| 1501 | 1501 | |
| 1502 | 1502 | fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 1503 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1503 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1504 | 1504 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 1505 | 1505 | const rhs_ty = self.typeOf(bin_op.rhs); |
| 1506 | 1506 | |
| ... | ... | @@ -1550,7 +1550,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | 1552 | fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 1553 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1553 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1554 | 1554 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1555 | 1555 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 1556 | 1556 | const rhs_ty = self.typeOf(bin_op.rhs); |
| ... | ... | @@ -1565,26 +1565,26 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void |
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | fn airAddSat(self: *Self, inst: Air.Inst.Index) !void { |
| 1568 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1568 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1569 | 1569 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch}); |
| 1570 | 1570 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | 1573 | fn airSubSat(self: *Self, inst: Air.Inst.Index) !void { |
| 1574 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1574 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1575 | 1575 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch}); |
| 1576 | 1576 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1577 | 1577 | } |
| 1578 | 1578 | |
| 1579 | 1579 | fn airMulSat(self: *Self, inst: Air.Inst.Index) !void { |
| 1580 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1580 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1581 | 1581 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch}); |
| 1582 | 1582 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | fn 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; | |
| 1588 | 1588 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1589 | 1589 | const mod = self.bin_file.options.module.?; |
| 1590 | 1590 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| ... | ... | @@ -1594,9 +1594,9 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1594 | 1594 | const rhs_ty = self.typeOf(extra.rhs); |
| 1595 | 1595 | |
| 1596 | 1596 | const tuple_ty = self.typeOfIndex(inst); |
| 1597 | const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod))); | |
| 1597 | const tuple_size: u32 = @intCast(tuple_ty.abiSize(mod)); | |
| 1598 | 1598 | const tuple_align = tuple_ty.abiAlignment(mod); |
| 1599 | const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod))); | |
| 1599 | const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, mod)); | |
| 1600 | 1600 | |
| 1601 | 1601 | switch (lhs_ty.zigTypeTag(mod)) { |
| 1602 | 1602 | .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}), |
| ... | ... | @@ -1696,7 +1696,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1696 | 1696 | } |
| 1697 | 1697 | |
| 1698 | 1698 | fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1699 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1699 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1700 | 1700 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1701 | 1701 | if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none }); |
| 1702 | 1702 | const mod = self.bin_file.options.module.?; |
| ... | ... | @@ -1707,9 +1707,9 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1707 | 1707 | const rhs_ty = self.typeOf(extra.rhs); |
| 1708 | 1708 | |
| 1709 | 1709 | const tuple_ty = self.typeOfIndex(inst); |
| 1710 | const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod))); | |
| 1710 | const tuple_size: u32 = @intCast(tuple_ty.abiSize(mod)); | |
| 1711 | 1711 | const tuple_align = tuple_ty.abiAlignment(mod); |
| 1712 | const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod))); | |
| 1712 | const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, mod)); | |
| 1713 | 1713 | |
| 1714 | 1714 | switch (lhs_ty.zigTypeTag(mod)) { |
| 1715 | 1715 | .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}), |
| ... | ... | @@ -1860,7 +1860,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1863 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1863 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1864 | 1864 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1865 | 1865 | if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none }); |
| 1866 | 1866 | const mod = self.bin_file.options.module.?; |
| ... | ... | @@ -1869,9 +1869,9 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1869 | 1869 | const rhs_ty = self.typeOf(extra.rhs); |
| 1870 | 1870 | |
| 1871 | 1871 | const tuple_ty = self.typeOfIndex(inst); |
| 1872 | const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(mod))); | |
| 1872 | const tuple_size: u32 = @intCast(tuple_ty.abiSize(mod)); | |
| 1873 | 1873 | const tuple_align = tuple_ty.abiAlignment(mod); |
| 1874 | const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, mod))); | |
| 1874 | const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, mod)); | |
| 1875 | 1875 | |
| 1876 | 1876 | switch (lhs_ty.zigTypeTag(mod)) { |
| 1877 | 1877 | .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}), |
| ... | ... | @@ -1918,7 +1918,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1918 | 1918 | .data = .{ .rr_shift = .{ |
| 1919 | 1919 | .rd = dest_reg, |
| 1920 | 1920 | .rm = lhs_reg, |
| 1921 | .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_mcv.immediate))), | |
| 1921 | .shift_amount = Instruction.ShiftAmount.imm(@intCast(rhs_mcv.immediate)), | |
| 1922 | 1922 | } }, |
| 1923 | 1923 | }); |
| 1924 | 1924 | |
| ... | ... | @@ -1930,7 +1930,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1930 | 1930 | .data = .{ .rr_shift = .{ |
| 1931 | 1931 | .rd = reconstructed_reg, |
| 1932 | 1932 | .rm = dest_reg, |
| 1933 | .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_mcv.immediate))), | |
| 1933 | .shift_amount = Instruction.ShiftAmount.imm(@intCast(rhs_mcv.immediate)), | |
| 1934 | 1934 | } }, |
| 1935 | 1935 | }); |
| 1936 | 1936 | } else { |
| ... | ... | @@ -1995,35 +1995,35 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1995 | 1995 | } |
| 1996 | 1996 | |
| 1997 | 1997 | fn airShlSat(self: *Self, inst: Air.Inst.Index) !void { |
| 1998 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1998 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1999 | 1999 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch}); |
| 2000 | 2000 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2001 | 2001 | } |
| 2002 | 2002 | |
| 2003 | 2003 | fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 2004 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2004 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2005 | 2005 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch}); |
| 2006 | 2006 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2007 | 2007 | } |
| 2008 | 2008 | |
| 2009 | 2009 | fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2010 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2010 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2011 | 2011 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch}); |
| 2012 | 2012 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2013 | 2013 | } |
| 2014 | 2014 | |
| 2015 | 2015 | fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 2016 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2016 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2017 | 2017 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch}); |
| 2018 | 2018 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2019 | 2019 | } |
| 2020 | 2020 | |
| 2021 | 2021 | fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| 2022 | 2022 | const mod = self.bin_file.options.module.?; |
| 2023 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2023 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2024 | 2024 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2025 | 2025 | const optional_ty = self.typeOfIndex(inst); |
| 2026 | const abi_size = @as(u32, @intCast(optional_ty.abiSize(mod))); | |
| 2026 | const abi_size: u32 = @intCast(optional_ty.abiSize(mod)); | |
| 2027 | 2027 | |
| 2028 | 2028 | // Optional with a zero-bit payload type is just a boolean true |
| 2029 | 2029 | if (abi_size == 1) { |
| ... | ... | @@ -2052,7 +2052,7 @@ fn errUnionErr( |
| 2052 | 2052 | return try error_union_bind.resolveToMcv(self); |
| 2053 | 2053 | } |
| 2054 | 2054 | |
| 2055 | const err_offset = @as(u32, @intCast(errUnionErrorOffset(payload_ty, mod))); | |
| 2055 | const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, mod)); | |
| 2056 | 2056 | switch (try error_union_bind.resolveToMcv(self)) { |
| 2057 | 2057 | .register => { |
| 2058 | 2058 | var operand_reg: Register = undefined; |
| ... | ... | @@ -2074,15 +2074,15 @@ fn errUnionErr( |
| 2074 | 2074 | ); |
| 2075 | 2075 | |
| 2076 | 2076 | const err_bit_offset = err_offset * 8; |
| 2077 | const err_bit_size = @as(u32, @intCast(err_ty.abiSize(mod))) * 8; | |
| 2077 | const err_bit_size: u32 = @intCast(err_ty.abiSize(mod) * 8); | |
| 2078 | 2078 | |
| 2079 | 2079 | _ = try self.addInst(.{ |
| 2080 | 2080 | .tag = .ubfx, // errors are unsigned integers |
| 2081 | 2081 | .data = .{ .rr_lsb_width = .{ |
| 2082 | 2082 | .rd = dest_reg, |
| 2083 | 2083 | .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), | |
| 2086 | 2086 | } }, |
| 2087 | 2087 | }); |
| 2088 | 2088 | |
| ... | ... | @@ -2102,7 +2102,7 @@ fn errUnionErr( |
| 2102 | 2102 | } |
| 2103 | 2103 | |
| 2104 | 2104 | fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2105 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2105 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2106 | 2106 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2107 | 2107 | const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand }; |
| 2108 | 2108 | const error_union_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -2129,7 +2129,7 @@ fn errUnionPayload( |
| 2129 | 2129 | return MCValue.none; |
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, mod))); | |
| 2132 | const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, mod)); | |
| 2133 | 2133 | switch (try error_union_bind.resolveToMcv(self)) { |
| 2134 | 2134 | .register => { |
| 2135 | 2135 | var operand_reg: Register = undefined; |
| ... | ... | @@ -2151,15 +2151,15 @@ fn errUnionPayload( |
| 2151 | 2151 | ); |
| 2152 | 2152 | |
| 2153 | 2153 | const payload_bit_offset = payload_offset * 8; |
| 2154 | const payload_bit_size = @as(u32, @intCast(payload_ty.abiSize(mod))) * 8; | |
| 2154 | const payload_bit_size: u32 = @intCast(payload_ty.abiSize(mod) * 8); | |
| 2155 | 2155 | |
| 2156 | 2156 | _ = try self.addInst(.{ |
| 2157 | 2157 | .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx, |
| 2158 | 2158 | .data = .{ .rr_lsb_width = .{ |
| 2159 | 2159 | .rd = dest_reg, |
| 2160 | 2160 | .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), | |
| 2163 | 2163 | } }, |
| 2164 | 2164 | }); |
| 2165 | 2165 | |
| ... | ... | @@ -2179,7 +2179,7 @@ fn errUnionPayload( |
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | 2181 | fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 2182 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2182 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2183 | 2183 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2184 | 2184 | const error_union_bind: ReadArg.Bind = .{ .inst = ty_op.operand }; |
| 2185 | 2185 | const error_union_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -2191,20 +2191,20 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 2191 | 2191 | |
| 2192 | 2192 | // *(E!T) -> E |
| 2193 | 2193 | fn airUnwrapErrErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2194 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2194 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2195 | 2195 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error ptr for {}", .{self.target.cpu.arch}); |
| 2196 | 2196 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2197 | 2197 | } |
| 2198 | 2198 | |
| 2199 | 2199 | // *(E!T) -> *T |
| 2200 | 2200 | fn airUnwrapErrPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2201 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2201 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2202 | 2202 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload ptr for {}", .{self.target.cpu.arch}); |
| 2203 | 2203 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2204 | 2204 | } |
| 2205 | 2205 | |
| 2206 | 2206 | fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 2207 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2207 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2208 | 2208 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch}); |
| 2209 | 2209 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2210 | 2210 | } |
| ... | ... | @@ -2230,17 +2230,17 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void { |
| 2230 | 2230 | /// T to E!T |
| 2231 | 2231 | fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 2232 | 2232 | const mod = self.bin_file.options.module.?; |
| 2233 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2233 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2234 | 2234 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2235 | const error_union_ty = self.air.getRefType(ty_op.ty); | |
| 2235 | const error_union_ty = ty_op.ty.toType(); | |
| 2236 | 2236 | const error_ty = error_union_ty.errorUnionSet(mod); |
| 2237 | 2237 | const payload_ty = error_union_ty.errorUnionPayload(mod); |
| 2238 | 2238 | const operand = try self.resolveInst(ty_op.operand); |
| 2239 | 2239 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand; |
| 2240 | 2240 | |
| 2241 | const abi_size = @as(u32, @intCast(error_union_ty.abiSize(mod))); | |
| 2241 | const abi_size: u32 = @intCast(error_union_ty.abiSize(mod)); | |
| 2242 | 2242 | const abi_align = error_union_ty.abiAlignment(mod); |
| 2243 | const stack_offset = @as(u32, @intCast(try self.allocMem(abi_size, abi_align, inst))); | |
| 2243 | const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst)); | |
| 2244 | 2244 | const payload_off = errUnionPayloadOffset(payload_ty, mod); |
| 2245 | 2245 | const err_off = errUnionErrorOffset(payload_ty, mod); |
| 2246 | 2246 | try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand); |
| ... | ... | @@ -2254,17 +2254,17 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 2254 | 2254 | /// E to E!T |
| 2255 | 2255 | fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2256 | 2256 | const mod = self.bin_file.options.module.?; |
| 2257 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2257 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2258 | 2258 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2259 | const error_union_ty = self.air.getRefType(ty_op.ty); | |
| 2259 | const error_union_ty = ty_op.ty.toType(); | |
| 2260 | 2260 | const error_ty = error_union_ty.errorUnionSet(mod); |
| 2261 | 2261 | const payload_ty = error_union_ty.errorUnionPayload(mod); |
| 2262 | 2262 | const operand = try self.resolveInst(ty_op.operand); |
| 2263 | 2263 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result operand; |
| 2264 | 2264 | |
| 2265 | const abi_size = @as(u32, @intCast(error_union_ty.abiSize(mod))); | |
| 2265 | const abi_size: u32 = @intCast(error_union_ty.abiSize(mod)); | |
| 2266 | 2266 | const abi_align = error_union_ty.abiAlignment(mod); |
| 2267 | const stack_offset = @as(u32, @intCast(try self.allocMem(abi_size, abi_align, inst))); | |
| 2267 | const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst)); | |
| 2268 | 2268 | const payload_off = errUnionPayloadOffset(payload_ty, mod); |
| 2269 | 2269 | const err_off = errUnionErrorOffset(payload_ty, mod); |
| 2270 | 2270 | try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand); |
| ... | ... | @@ -2293,7 +2293,7 @@ fn slicePtr(mcv: MCValue) MCValue { |
| 2293 | 2293 | } |
| 2294 | 2294 | |
| 2295 | 2295 | fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2296 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2296 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2297 | 2297 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2298 | 2298 | const mcv = try self.resolveInst(ty_op.operand); |
| 2299 | 2299 | break :result slicePtr(mcv); |
| ... | ... | @@ -2302,7 +2302,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2302 | 2302 | } |
| 2303 | 2303 | |
| 2304 | 2304 | fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { |
| 2305 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2305 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2306 | 2306 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2307 | 2307 | const mcv = try self.resolveInst(ty_op.operand); |
| 2308 | 2308 | switch (mcv) { |
| ... | ... | @@ -2323,7 +2323,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { |
| 2323 | 2323 | } |
| 2324 | 2324 | |
| 2325 | 2325 | fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2326 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2326 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2327 | 2327 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2328 | 2328 | const mcv = try self.resolveInst(ty_op.operand); |
| 2329 | 2329 | switch (mcv) { |
| ... | ... | @@ -2343,7 +2343,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2343 | 2343 | } |
| 2344 | 2344 | |
| 2345 | 2345 | fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2346 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2346 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2347 | 2347 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2348 | 2348 | const mcv = try self.resolveInst(ty_op.operand); |
| 2349 | 2349 | switch (mcv) { |
| ... | ... | @@ -2372,7 +2372,7 @@ fn ptrElemVal( |
| 2372 | 2372 | ) !MCValue { |
| 2373 | 2373 | const mod = self.bin_file.options.module.?; |
| 2374 | 2374 | const elem_ty = ptr_ty.childType(mod); |
| 2375 | const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod))); | |
| 2375 | const elem_size: u32 = @intCast(elem_ty.abiSize(mod)); | |
| 2376 | 2376 | |
| 2377 | 2377 | switch (elem_size) { |
| 2378 | 2378 | 1, 4 => { |
| ... | ... | @@ -2430,7 +2430,7 @@ fn ptrElemVal( |
| 2430 | 2430 | |
| 2431 | 2431 | fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2432 | 2432 | const mod = self.bin_file.options.module.?; |
| 2433 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2433 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2434 | 2434 | const slice_ty = self.typeOf(bin_op.lhs); |
| 2435 | 2435 | const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: { |
| 2436 | 2436 | const ptr_ty = slice_ty.slicePtrFieldType(mod); |
| ... | ... | @@ -2447,7 +2447,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2447 | 2447 | } |
| 2448 | 2448 | |
| 2449 | 2449 | fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2450 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2450 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2451 | 2451 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2452 | 2452 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2453 | 2453 | const slice_mcv = try self.resolveInst(extra.lhs); |
| ... | ... | @@ -2483,7 +2483,7 @@ fn arrayElemVal( |
| 2483 | 2483 | => { |
| 2484 | 2484 | const ptr_to_mcv = switch (mcv) { |
| 2485 | 2485 | .stack_offset => |off| MCValue{ .ptr_stack_offset = off }, |
| 2486 | .memory => |addr| MCValue{ .immediate = @as(u32, @intCast(addr)) }, | |
| 2486 | .memory => |addr| MCValue{ .immediate = @intCast(addr) }, | |
| 2487 | 2487 | .stack_argument_offset => |off| blk: { |
| 2488 | 2488 | const reg = try self.register_manager.allocReg(null, gp); |
| 2489 | 2489 | |
| ... | ... | @@ -2516,7 +2516,7 @@ fn arrayElemVal( |
| 2516 | 2516 | } |
| 2517 | 2517 | |
| 2518 | 2518 | fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2519 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2519 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2520 | 2520 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2521 | 2521 | const array_bind: ReadArg.Bind = .{ .inst = bin_op.lhs }; |
| 2522 | 2522 | const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs }; |
| ... | ... | @@ -2529,7 +2529,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2529 | 2529 | |
| 2530 | 2530 | fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2531 | 2531 | const mod = self.bin_file.options.module.?; |
| 2532 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2532 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2533 | 2533 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 2534 | 2534 | const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: { |
| 2535 | 2535 | const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs }; |
| ... | ... | @@ -2541,7 +2541,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2541 | 2541 | } |
| 2542 | 2542 | |
| 2543 | 2543 | fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2544 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2544 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2545 | 2545 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2546 | 2546 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2547 | 2547 | const ptr_bind: ReadArg.Bind = .{ .inst = extra.lhs }; |
| ... | ... | @@ -2557,63 +2557,63 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2557 | 2557 | } |
| 2558 | 2558 | |
| 2559 | 2559 | fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 2560 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2560 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2561 | 2561 | _ = bin_op; |
| 2562 | 2562 | return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch}); |
| 2563 | 2563 | // return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2564 | 2564 | } |
| 2565 | 2565 | |
| 2566 | 2566 | fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 2567 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2567 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2568 | 2568 | _ = ty_op; |
| 2569 | 2569 | return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch}); |
| 2570 | 2570 | // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2571 | 2571 | } |
| 2572 | 2572 | |
| 2573 | 2573 | fn airClz(self: *Self, inst: Air.Inst.Index) !void { |
| 2574 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2574 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2575 | 2575 | _ = ty_op; |
| 2576 | 2576 | return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch}); |
| 2577 | 2577 | // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2578 | 2578 | } |
| 2579 | 2579 | |
| 2580 | 2580 | fn airCtz(self: *Self, inst: Air.Inst.Index) !void { |
| 2581 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2581 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2582 | 2582 | _ = ty_op; |
| 2583 | 2583 | return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch}); |
| 2584 | 2584 | // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2585 | 2585 | } |
| 2586 | 2586 | |
| 2587 | 2587 | fn airPopcount(self: *Self, inst: Air.Inst.Index) !void { |
| 2588 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2588 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2589 | 2589 | _ = ty_op; |
| 2590 | 2590 | return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch}); |
| 2591 | 2591 | // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2592 | 2592 | } |
| 2593 | 2593 | |
| 2594 | 2594 | fn airAbs(self: *Self, inst: Air.Inst.Index) !void { |
| 2595 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2595 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2596 | 2596 | _ = ty_op; |
| 2597 | 2597 | return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch}); |
| 2598 | 2598 | // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2599 | 2599 | } |
| 2600 | 2600 | |
| 2601 | 2601 | fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { |
| 2602 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2602 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2603 | 2603 | _ = ty_op; |
| 2604 | 2604 | return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch}); |
| 2605 | 2605 | // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2606 | 2606 | } |
| 2607 | 2607 | |
| 2608 | 2608 | fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void { |
| 2609 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2609 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2610 | 2610 | _ = ty_op; |
| 2611 | 2611 | return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch}); |
| 2612 | 2612 | // return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2613 | 2613 | } |
| 2614 | 2614 | |
| 2615 | 2615 | fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void { |
| 2616 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2616 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2617 | 2617 | const result: MCValue = if (self.liveness.isUnused(inst)) |
| 2618 | 2618 | .dead |
| 2619 | 2619 | else |
| ... | ... | @@ -2656,7 +2656,7 @@ fn reuseOperand( |
| 2656 | 2656 | |
| 2657 | 2657 | // That makes us responsible for doing the rest of the stuff that processDeath would have done. |
| 2658 | 2658 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 2659 | branch.inst_table.putAssumeCapacity(Air.refToIndex(operand).?, .dead); | |
| 2659 | branch.inst_table.putAssumeCapacity(operand.toIndex().?, .dead); | |
| 2660 | 2660 | |
| 2661 | 2661 | return true; |
| 2662 | 2662 | } |
| ... | ... | @@ -2664,7 +2664,7 @@ fn reuseOperand( |
| 2664 | 2664 | fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void { |
| 2665 | 2665 | const mod = self.bin_file.options.module.?; |
| 2666 | 2666 | const elem_ty = ptr_ty.childType(mod); |
| 2667 | const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod))); | |
| 2667 | const elem_size: u32 = @intCast(elem_ty.abiSize(mod)); | |
| 2668 | 2668 | |
| 2669 | 2669 | switch (ptr) { |
| 2670 | 2670 | .none => unreachable, |
| ... | ... | @@ -2740,7 +2740,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo |
| 2740 | 2740 | |
| 2741 | 2741 | fn airLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 2742 | 2742 | const mod = self.bin_file.options.module.?; |
| 2743 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2743 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2744 | 2744 | const elem_ty = self.typeOfIndex(inst); |
| 2745 | 2745 | const result: MCValue = result: { |
| 2746 | 2746 | if (!elem_ty.hasRuntimeBits(mod)) |
| ... | ... | @@ -2769,7 +2769,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 2769 | 2769 | |
| 2770 | 2770 | fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void { |
| 2771 | 2771 | const mod = self.bin_file.options.module.?; |
| 2772 | const elem_size = @as(u32, @intCast(value_ty.abiSize(mod))); | |
| 2772 | const elem_size: u32 = @intCast(value_ty.abiSize(mod)); | |
| 2773 | 2773 | |
| 2774 | 2774 | switch (ptr) { |
| 2775 | 2775 | .none => unreachable, |
| ... | ... | @@ -2824,7 +2824,7 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type |
| 2824 | 2824 | // sub src_reg, fp, #off |
| 2825 | 2825 | try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off }); |
| 2826 | 2826 | }, |
| 2827 | .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }), | |
| 2827 | .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(addr) }), | |
| 2828 | 2828 | .stack_argument_offset => |off| { |
| 2829 | 2829 | _ = try self.addInst(.{ |
| 2830 | 2830 | .tag = .ldr_ptr_stack_argument, |
| ... | ... | @@ -2862,7 +2862,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 2862 | 2862 | } else { |
| 2863 | 2863 | // TODO if the value is undef, don't lower this instruction |
| 2864 | 2864 | } |
| 2865 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2865 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2866 | 2866 | const ptr = try self.resolveInst(bin_op.lhs); |
| 2867 | 2867 | const value = try self.resolveInst(bin_op.rhs); |
| 2868 | 2868 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2874,14 +2874,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 2874 | 2874 | } |
| 2875 | 2875 | |
| 2876 | 2876 | fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2877 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2877 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2878 | 2878 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 2879 | 2879 | const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index); |
| 2880 | 2880 | return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none }); |
| 2881 | 2881 | } |
| 2882 | 2882 | |
| 2883 | 2883 | fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void { |
| 2884 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2884 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2885 | 2885 | const result = try self.structFieldPtr(inst, ty_op.operand, index); |
| 2886 | 2886 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2887 | 2887 | } |
| ... | ... | @@ -2892,7 +2892,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde |
| 2892 | 2892 | const mcv = try self.resolveInst(operand); |
| 2893 | 2893 | const ptr_ty = self.typeOf(operand); |
| 2894 | 2894 | const struct_ty = ptr_ty.childType(mod); |
| 2895 | const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod))); | |
| 2895 | const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, mod)); | |
| 2896 | 2896 | switch (mcv) { |
| 2897 | 2897 | .ptr_stack_offset => |off| { |
| 2898 | 2898 | break :result MCValue{ .ptr_stack_offset = off - struct_field_offset }; |
| ... | ... | @@ -2908,7 +2908,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde |
| 2908 | 2908 | } |
| 2909 | 2909 | |
| 2910 | 2910 | fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2911 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2911 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2912 | 2912 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 2913 | 2913 | const operand = extra.struct_operand; |
| 2914 | 2914 | const index = extra.field_index; |
| ... | ... | @@ -2916,7 +2916,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2916 | 2916 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2917 | 2917 | const mcv = try self.resolveInst(operand); |
| 2918 | 2918 | const struct_ty = self.typeOf(operand); |
| 2919 | const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, mod))); | |
| 2919 | const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, mod)); | |
| 2920 | 2920 | const struct_field_ty = struct_ty.structFieldType(index, mod); |
| 2921 | 2921 | |
| 2922 | 2922 | switch (mcv) { |
| ... | ... | @@ -2980,15 +2980,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2980 | 2980 | ); |
| 2981 | 2981 | |
| 2982 | 2982 | const field_bit_offset = struct_field_offset * 8; |
| 2983 | const field_bit_size = @as(u32, @intCast(struct_field_ty.abiSize(mod))) * 8; | |
| 2983 | const field_bit_size: u32 = @intCast(struct_field_ty.abiSize(mod) * 8); | |
| 2984 | 2984 | |
| 2985 | 2985 | _ = try self.addInst(.{ |
| 2986 | 2986 | .tag = if (struct_field_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx, |
| 2987 | 2987 | .data = .{ .rr_lsb_width = .{ |
| 2988 | 2988 | .rd = dest_reg, |
| 2989 | 2989 | .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), | |
| 2992 | 2992 | } }, |
| 2993 | 2993 | }); |
| 2994 | 2994 | |
| ... | ... | @@ -3003,17 +3003,17 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 3003 | 3003 | |
| 3004 | 3004 | fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 3005 | 3005 | const mod = self.bin_file.options.module.?; |
| 3006 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3006 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3007 | 3007 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 3008 | 3008 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 3009 | 3009 | const field_ptr = try self.resolveInst(extra.field_ptr); |
| 3010 | const struct_ty = self.air.getRefType(ty_pl.ty).childType(mod); | |
| 3010 | const struct_ty = ty_pl.ty.toType().childType(mod); | |
| 3011 | 3011 | |
| 3012 | 3012 | if (struct_ty.zigTypeTag(mod) == .Union) { |
| 3013 | 3013 | return self.fail("TODO implement @fieldParentPtr codegen for unions", .{}); |
| 3014 | 3014 | } |
| 3015 | 3015 | |
| 3016 | const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, mod))); | |
| 3016 | const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(extra.field_index, mod)); | |
| 3017 | 3017 | switch (field_ptr) { |
| 3018 | 3018 | .ptr_stack_offset => |off| { |
| 3019 | 3019 | break :result MCValue{ .ptr_stack_offset = off + struct_field_offset }; |
| ... | ... | @@ -3168,7 +3168,7 @@ fn allocRegs( |
| 3168 | 3168 | arg.reg.* = mcv.register; |
| 3169 | 3169 | } else { |
| 3170 | 3170 | const track_inst: ?Air.Inst.Index = switch (arg.bind) { |
| 3171 | .inst => |inst| Air.refToIndex(inst).?, | |
| 3171 | .inst => |inst| inst.toIndex().?, | |
| 3172 | 3172 | else => null, |
| 3173 | 3173 | }; |
| 3174 | 3174 | arg.reg.* = try self.register_manager.allocReg(track_inst, arg.class); |
| ... | ... | @@ -3225,7 +3225,7 @@ fn allocRegs( |
| 3225 | 3225 | if (mcv != .register) { |
| 3226 | 3226 | if (arg.bind == .inst) { |
| 3227 | 3227 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 3228 | const inst = Air.refToIndex(arg.bind.inst).?; | |
| 3228 | const inst = arg.bind.inst.toIndex().?; | |
| 3229 | 3229 | |
| 3230 | 3230 | // Overwrite the MCValue associated with this inst |
| 3231 | 3231 | branch.inst_table.putAssumeCapacity(inst, .{ .register = arg.reg.* }); |
| ... | ... | @@ -3374,7 +3374,7 @@ fn binOpImmediate( |
| 3374 | 3374 | => .{ .rr_shift = .{ |
| 3375 | 3375 | .rd = dest_reg, |
| 3376 | 3376 | .rm = lhs_reg, |
| 3377 | .shift_amount = Instruction.ShiftAmount.imm(@as(u5, @intCast(rhs_immediate))), | |
| 3377 | .shift_amount = Instruction.ShiftAmount.imm(@intCast(rhs_immediate)), | |
| 3378 | 3378 | } }, |
| 3379 | 3379 | else => unreachable, |
| 3380 | 3380 | }; |
| ... | ... | @@ -3905,7 +3905,7 @@ fn ptrArithmetic( |
| 3905 | 3905 | .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type |
| 3906 | 3906 | else => ptr_ty.childType(mod), |
| 3907 | 3907 | }; |
| 3908 | const elem_size = @as(u32, @intCast(elem_ty.abiSize(mod))); | |
| 3908 | const elem_size: u32 = @intCast(elem_ty.abiSize(mod)); | |
| 3909 | 3909 | |
| 3910 | 3910 | const base_tag: Air.Inst.Tag = switch (tag) { |
| 3911 | 3911 | .ptr_add => .add, |
| ... | ... | @@ -4032,7 +4032,7 @@ fn genInlineMemcpy( |
| 4032 | 4032 | _ = try self.addInst(.{ |
| 4033 | 4033 | .tag = .b, |
| 4034 | 4034 | .cond = .ge, |
| 4035 | .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 5)) }, | |
| 4035 | .data = .{ .inst = @intCast(self.mir_instructions.len + 5) }, | |
| 4036 | 4036 | }); |
| 4037 | 4037 | |
| 4038 | 4038 | // ldrb tmp, [src, count] |
| ... | ... | @@ -4068,7 +4068,7 @@ fn genInlineMemcpy( |
| 4068 | 4068 | // b loop |
| 4069 | 4069 | _ = try self.addInst(.{ |
| 4070 | 4070 | .tag = .b, |
| 4071 | .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 5)) }, | |
| 4071 | .data = .{ .inst = @intCast(self.mir_instructions.len - 5) }, | |
| 4072 | 4072 | }); |
| 4073 | 4073 | |
| 4074 | 4074 | // end: |
| ... | ... | @@ -4136,7 +4136,7 @@ fn genInlineMemsetCode( |
| 4136 | 4136 | _ = try self.addInst(.{ |
| 4137 | 4137 | .tag = .b, |
| 4138 | 4138 | .cond = .ge, |
| 4139 | .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len + 4)) }, | |
| 4139 | .data = .{ .inst = @intCast(self.mir_instructions.len + 4) }, | |
| 4140 | 4140 | }); |
| 4141 | 4141 | |
| 4142 | 4142 | // strb val, [src, count] |
| ... | ... | @@ -4162,7 +4162,7 @@ fn genInlineMemsetCode( |
| 4162 | 4162 | // b loop |
| 4163 | 4163 | _ = try self.addInst(.{ |
| 4164 | 4164 | .tag = .b, |
| 4165 | .data = .{ .inst = @as(u32, @intCast(self.mir_instructions.len - 4)) }, | |
| 4165 | .data = .{ .inst = @intCast(self.mir_instructions.len - 4) }, | |
| 4166 | 4166 | }); |
| 4167 | 4167 | |
| 4168 | 4168 | // end: |
| ... | ... | @@ -4176,8 +4176,8 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { |
| 4176 | 4176 | |
| 4177 | 4177 | const mod = self.bin_file.options.module.?; |
| 4178 | 4178 | 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; | |
| 4181 | 4181 | const name = mod.getParamName(self.func_index, src_index); |
| 4182 | 4182 | |
| 4183 | 4183 | try self.dbg_info_relocs.append(self.gpa, .{ |
| ... | ... | @@ -4224,10 +4224,10 @@ fn airFence(self: *Self) !void { |
| 4224 | 4224 | |
| 4225 | 4225 | fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { |
| 4226 | 4226 | if (modifier == .always_tail) return self.fail("TODO implement tail calls for arm", .{}); |
| 4227 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4227 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4228 | 4228 | const callee = pl_op.operand; |
| 4229 | 4229 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 4230 | const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len])); | |
| 4230 | const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]); | |
| 4231 | 4231 | const ty = self.typeOf(callee); |
| 4232 | 4232 | const mod = self.bin_file.options.module.?; |
| 4233 | 4233 | |
| ... | ... | @@ -4305,7 +4305,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 4305 | 4305 | const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl); |
| 4306 | 4306 | const sym = elf_file.symbol(sym_index); |
| 4307 | 4307 | _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file); |
| 4308 | const got_addr = @as(u32, @intCast(sym.zigGotAddress(elf_file))); | |
| 4308 | const got_addr: u32 = @intCast(sym.zigGotAddress(elf_file)); | |
| 4309 | 4309 | try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr }); |
| 4310 | 4310 | } else if (self.bin_file.cast(link.File.MachO)) |_| { |
| 4311 | 4311 | unreachable; // unsupported architecture for MachO |
| ... | ... | @@ -4381,7 +4381,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 4381 | 4381 | |
| 4382 | 4382 | fn airRet(self: *Self, inst: Air.Inst.Index) !void { |
| 4383 | 4383 | const mod = self.bin_file.options.module.?; |
| 4384 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4384 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4385 | 4385 | const operand = try self.resolveInst(un_op); |
| 4386 | 4386 | const ret_ty = self.fn_type.fnReturnType(mod); |
| 4387 | 4387 | |
| ... | ... | @@ -4413,7 +4413,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void { |
| 4413 | 4413 | |
| 4414 | 4414 | fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 4415 | 4415 | const mod = self.bin_file.options.module.?; |
| 4416 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4416 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4417 | 4417 | const ptr = try self.resolveInst(un_op); |
| 4418 | 4418 | const ptr_ty = self.typeOf(un_op); |
| 4419 | 4419 | const ret_ty = self.fn_type.fnReturnType(mod); |
| ... | ... | @@ -4434,9 +4434,9 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 4434 | 4434 | // here. Else we need to load the result from the location |
| 4435 | 4435 | // pointed to by the operand and store it to the result |
| 4436 | 4436 | // 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)); | |
| 4440 | 4440 | const abi_align = ret_ty.abiAlignment(mod); |
| 4441 | 4441 | |
| 4442 | 4442 | const offset = try self.allocMem(abi_size, abi_align, null); |
| ... | ... | @@ -4456,7 +4456,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 4456 | 4456 | } |
| 4457 | 4457 | |
| 4458 | 4458 | fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void { |
| 4459 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 4459 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4460 | 4460 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 4461 | 4461 | |
| 4462 | 4462 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else blk: { |
| ... | ... | @@ -4556,7 +4556,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void { |
| 4556 | 4556 | } |
| 4557 | 4557 | |
| 4558 | 4558 | fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 4559 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4559 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4560 | 4560 | const operand = try self.resolveInst(un_op); |
| 4561 | 4561 | _ = operand; |
| 4562 | 4562 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch}); |
| ... | ... | @@ -4564,7 +4564,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 4564 | 4564 | } |
| 4565 | 4565 | |
| 4566 | 4566 | fn 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; | |
| 4568 | 4568 | |
| 4569 | 4569 | _ = try self.addInst(.{ |
| 4570 | 4570 | .tag = .dbg_line, |
| ... | ... | @@ -4579,7 +4579,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void { |
| 4579 | 4579 | } |
| 4580 | 4580 | |
| 4581 | 4581 | fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 4582 | const ty_fn = self.air.instructions.items(.data)[inst].ty_fn; | |
| 4582 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 4583 | 4583 | const mod = self.bin_file.options.module.?; |
| 4584 | 4584 | const func = mod.funcInfo(ty_fn.func); |
| 4585 | 4585 | // TODO emit debug info for function change |
| ... | ... | @@ -4593,9 +4593,9 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 4593 | 4593 | } |
| 4594 | 4594 | |
| 4595 | 4595 | fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 4596 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4596 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4597 | 4597 | const operand = pl_op.operand; |
| 4598 | const tag = self.air.instructions.items(.tag)[inst]; | |
| 4598 | const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)]; | |
| 4599 | 4599 | const ty = self.typeOf(operand); |
| 4600 | 4600 | const mcv = try self.resolveInst(operand); |
| 4601 | 4601 | const name = self.air.nullTerminatedString(pl_op.payload); |
| ... | ... | @@ -4647,11 +4647,11 @@ fn condBr(self: *Self, condition: MCValue) !Mir.Inst.Index { |
| 4647 | 4647 | } |
| 4648 | 4648 | |
| 4649 | 4649 | fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4650 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4650 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4651 | 4651 | const cond_inst = try self.resolveInst(pl_op.operand); |
| 4652 | 4652 | const extra = self.air.extraData(Air.CondBr, pl_op.payload); |
| 4653 | const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len]; | |
| 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]); | |
| 4655 | 4655 | const liveness_condbr = self.liveness.getCondBr(inst); |
| 4656 | 4656 | |
| 4657 | 4657 | const reloc: Mir.Inst.Index = try self.condBr(cond_inst); |
| ... | ... | @@ -4660,7 +4660,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4660 | 4660 | // that death now instead of later as this has an effect on |
| 4661 | 4661 | // whether it needs to be spilled in the branches |
| 4662 | 4662 | if (self.liveness.operandDies(inst, 0)) { |
| 4663 | if (Air.refToIndex(pl_op.operand)) |op_index| { | |
| 4663 | if (pl_op.operand.toIndex()) |op_index| { | |
| 4664 | 4664 | self.processDeath(op_index); |
| 4665 | 4665 | } |
| 4666 | 4666 | } |
| ... | ... | @@ -4818,7 +4818,7 @@ fn isNonNull( |
| 4818 | 4818 | } |
| 4819 | 4819 | |
| 4820 | 4820 | fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 4821 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4821 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4822 | 4822 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4823 | 4823 | const operand_bind: ReadArg.Bind = .{ .inst = un_op }; |
| 4824 | 4824 | const operand_ty = self.typeOf(un_op); |
| ... | ... | @@ -4830,7 +4830,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 4830 | 4830 | |
| 4831 | 4831 | fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4832 | 4832 | const mod = self.bin_file.options.module.?; |
| 4833 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4833 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4834 | 4834 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4835 | 4835 | const operand_ptr = try self.resolveInst(un_op); |
| 4836 | 4836 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -4845,7 +4845,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4845 | 4845 | } |
| 4846 | 4846 | |
| 4847 | 4847 | fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 4848 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4848 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4849 | 4849 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4850 | 4850 | const operand_bind: ReadArg.Bind = .{ .inst = un_op }; |
| 4851 | 4851 | const operand_ty = self.typeOf(un_op); |
| ... | ... | @@ -4857,7 +4857,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 4857 | 4857 | |
| 4858 | 4858 | fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4859 | 4859 | const mod = self.bin_file.options.module.?; |
| 4860 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4860 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4861 | 4861 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4862 | 4862 | const operand_ptr = try self.resolveInst(un_op); |
| 4863 | 4863 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -4907,7 +4907,7 @@ fn isNonErr( |
| 4907 | 4907 | } |
| 4908 | 4908 | |
| 4909 | 4909 | fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4910 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4910 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4911 | 4911 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4912 | 4912 | const error_union_bind: ReadArg.Bind = .{ .inst = un_op }; |
| 4913 | 4913 | const error_union_ty = self.typeOf(un_op); |
| ... | ... | @@ -4919,7 +4919,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4919 | 4919 | |
| 4920 | 4920 | fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4921 | 4921 | const mod = self.bin_file.options.module.?; |
| 4922 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4922 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4923 | 4923 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4924 | 4924 | const operand_ptr = try self.resolveInst(un_op); |
| 4925 | 4925 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -4934,7 +4934,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4934 | 4934 | } |
| 4935 | 4935 | |
| 4936 | 4936 | fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4937 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4937 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4938 | 4938 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4939 | 4939 | const error_union_bind: ReadArg.Bind = .{ .inst = un_op }; |
| 4940 | 4940 | const error_union_ty = self.typeOf(un_op); |
| ... | ... | @@ -4946,7 +4946,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4946 | 4946 | |
| 4947 | 4947 | fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4948 | 4948 | const mod = self.bin_file.options.module.?; |
| 4949 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4949 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4950 | 4950 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4951 | 4951 | const operand_ptr = try self.resolveInst(un_op); |
| 4952 | 4952 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -4962,10 +4962,10 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4962 | 4962 | |
| 4963 | 4963 | fn airLoop(self: *Self, inst: Air.Inst.Index) !void { |
| 4964 | 4964 | // A loop is a setup to be able to jump back to the beginning. |
| 4965 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 4965 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4966 | 4966 | 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); | |
| 4969 | 4969 | |
| 4970 | 4970 | try self.genBody(body); |
| 4971 | 4971 | try self.jump(start_index); |
| ... | ... | @@ -4994,9 +4994,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 4994 | 4994 | }); |
| 4995 | 4995 | defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa); |
| 4996 | 4996 | |
| 4997 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 4997 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4998 | 4998 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 4999 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 4999 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 5000 | 5000 | try self.genBody(body); |
| 5001 | 5001 | |
| 5002 | 5002 | // relocations for `br` instructions |
| ... | ... | @@ -5016,7 +5016,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 5016 | 5016 | } |
| 5017 | 5017 | |
| 5018 | 5018 | fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5019 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 5019 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 5020 | 5020 | const condition_ty = self.typeOf(pl_op.operand); |
| 5021 | 5021 | const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload); |
| 5022 | 5022 | const liveness = try self.liveness.getSwitchBr( |
| ... | ... | @@ -5030,9 +5030,9 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5030 | 5030 | var case_i: u32 = 0; |
| 5031 | 5031 | while (case_i < switch_br.data.cases_len) : (case_i += 1) { |
| 5032 | 5032 | const case = self.air.extraData(Air.SwitchBr.Case, extra_index); |
| 5033 | const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len])); | |
| 5033 | const items: []const Air.Inst.Ref = @ptrCast(self.air.extra[case.end..][0..case.data.items_len]); | |
| 5034 | 5034 | assert(items.len > 0); |
| 5035 | const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len]; | |
| 5035 | const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]); | |
| 5036 | 5036 | extra_index = case.end + items.len + case_body.len; |
| 5037 | 5037 | |
| 5038 | 5038 | // For every item, we compare it to condition and branch into |
| ... | ... | @@ -5103,7 +5103,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5103 | 5103 | } |
| 5104 | 5104 | |
| 5105 | 5105 | if (switch_br.data.else_body_len > 0) { |
| 5106 | const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len]; | |
| 5106 | const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]); | |
| 5107 | 5107 | |
| 5108 | 5108 | // Capture the state of register and stack allocation state so that we can revert to it. |
| 5109 | 5109 | const parent_next_stack_offset = self.next_stack_offset; |
| ... | ... | @@ -5148,13 +5148,13 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5148 | 5148 | fn performReloc(self: *Self, inst: Mir.Inst.Index) !void { |
| 5149 | 5149 | const tag = self.mir_instructions.items(.tag)[inst]; |
| 5150 | 5150 | switch (tag) { |
| 5151 | .b => self.mir_instructions.items(.data)[inst].inst = @as(Air.Inst.Index, @intCast(self.mir_instructions.len)), | |
| 5151 | .b => self.mir_instructions.items(.data)[inst].inst = @intCast(self.mir_instructions.len), | |
| 5152 | 5152 | else => unreachable, |
| 5153 | 5153 | } |
| 5154 | 5154 | } |
| 5155 | 5155 | |
| 5156 | 5156 | fn airBr(self: *Self, inst: Air.Inst.Index) !void { |
| 5157 | const branch = self.air.instructions.items(.data)[inst].br; | |
| 5157 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 5158 | 5158 | try self.br(branch.block_inst, branch.operand); |
| 5159 | 5159 | return self.finishAir(inst, .dead, .{ branch.operand, .none, .none }); |
| 5160 | 5160 | } |
| ... | ... | @@ -5195,14 +5195,14 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void { |
| 5195 | 5195 | } |
| 5196 | 5196 | |
| 5197 | 5197 | fn airAsm(self: *Self, inst: Air.Inst.Index) !void { |
| 5198 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5198 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5199 | 5199 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); |
| 5200 | 5200 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; |
| 5201 | const clobbers_len = @as(u31, @truncate(extra.data.flags)); | |
| 5201 | const clobbers_len: u31 = @truncate(extra.data.flags); | |
| 5202 | 5202 | var extra_i: usize = extra.end; |
| 5203 | const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len])); | |
| 5203 | const outputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]); | |
| 5204 | 5204 | extra_i += outputs.len; |
| 5205 | const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len])); | |
| 5205 | const inputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]); | |
| 5206 | 5206 | extra_i += inputs.len; |
| 5207 | 5207 | |
| 5208 | 5208 | const dead = !is_volatile and self.liveness.isUnused(inst); |
| ... | ... | @@ -5332,7 +5332,7 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void { |
| 5332 | 5332 | |
| 5333 | 5333 | fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void { |
| 5334 | 5334 | const mod = self.bin_file.options.module.?; |
| 5335 | const abi_size = @as(u32, @intCast(ty.abiSize(mod))); | |
| 5335 | const abi_size: u32 = @intCast(ty.abiSize(mod)); | |
| 5336 | 5336 | switch (mcv) { |
| 5337 | 5337 | .dead => unreachable, |
| 5338 | 5338 | .unreach, .none => return, // Nothing to do. |
| ... | ... | @@ -5385,7 +5385,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro |
| 5385 | 5385 | }, |
| 5386 | 5386 | 2 => { |
| 5387 | 5387 | const offset = if (stack_offset <= math.maxInt(u8)) blk: { |
| 5388 | break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(stack_offset))); | |
| 5388 | break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(stack_offset)); | |
| 5389 | 5389 | } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset })); |
| 5390 | 5390 | |
| 5391 | 5391 | _ = try self.addInst(.{ |
| ... | ... | @@ -5413,7 +5413,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro |
| 5413 | 5413 | try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg }); |
| 5414 | 5414 | |
| 5415 | 5415 | const overflow_bit_ty = ty.structFieldType(1, mod); |
| 5416 | const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, mod))); | |
| 5416 | const overflow_bit_offset: u32 = @intCast(ty.structFieldOffset(1, mod)); | |
| 5417 | 5417 | const cond_reg = try self.register_manager.allocReg(null, gp); |
| 5418 | 5418 | |
| 5419 | 5419 | // C flag: movcs reg, #1 |
| ... | ... | @@ -5466,7 +5466,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro |
| 5466 | 5466 | // sub src_reg, fp, #off |
| 5467 | 5467 | try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off }); |
| 5468 | 5468 | }, |
| 5469 | .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }), | |
| 5469 | .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(addr) }), | |
| 5470 | 5470 | .stack_argument_offset => |off| { |
| 5471 | 5471 | _ = try self.addInst(.{ |
| 5472 | 5472 | .tag = .ldr_ptr_stack_argument, |
| ... | ... | @@ -5563,7 +5563,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5563 | 5563 | .tag = .movw, |
| 5564 | 5564 | .data = .{ .r_imm16 = .{ |
| 5565 | 5565 | .rd = reg, |
| 5566 | .imm16 = @as(u16, @intCast(x)), | |
| 5566 | .imm16 = @intCast(x), | |
| 5567 | 5567 | } }, |
| 5568 | 5568 | }); |
| 5569 | 5569 | } else { |
| ... | ... | @@ -5571,7 +5571,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5571 | 5571 | .tag = .mov, |
| 5572 | 5572 | .data = .{ .r_op_mov = .{ |
| 5573 | 5573 | .rd = reg, |
| 5574 | .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0), | |
| 5574 | .op = Instruction.Operand.imm(@truncate(x), 0), | |
| 5575 | 5575 | } }, |
| 5576 | 5576 | }); |
| 5577 | 5577 | _ = try self.addInst(.{ |
| ... | ... | @@ -5579,7 +5579,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5579 | 5579 | .data = .{ .rr_op = .{ |
| 5580 | 5580 | .rd = reg, |
| 5581 | 5581 | .rn = reg, |
| 5582 | .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12), | |
| 5582 | .op = Instruction.Operand.imm(@truncate(x >> 8), 12), | |
| 5583 | 5583 | } }, |
| 5584 | 5584 | }); |
| 5585 | 5585 | } |
| ... | ... | @@ -5594,14 +5594,14 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5594 | 5594 | .tag = .movw, |
| 5595 | 5595 | .data = .{ .r_imm16 = .{ |
| 5596 | 5596 | .rd = reg, |
| 5597 | .imm16 = @as(u16, @truncate(x)), | |
| 5597 | .imm16 = @truncate(x), | |
| 5598 | 5598 | } }, |
| 5599 | 5599 | }); |
| 5600 | 5600 | _ = try self.addInst(.{ |
| 5601 | 5601 | .tag = .movt, |
| 5602 | 5602 | .data = .{ .r_imm16 = .{ |
| 5603 | 5603 | .rd = reg, |
| 5604 | .imm16 = @as(u16, @truncate(x >> 16)), | |
| 5604 | .imm16 = @truncate(x >> 16), | |
| 5605 | 5605 | } }, |
| 5606 | 5606 | }); |
| 5607 | 5607 | } else { |
| ... | ... | @@ -5614,7 +5614,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5614 | 5614 | .tag = .mov, |
| 5615 | 5615 | .data = .{ .r_op_mov = .{ |
| 5616 | 5616 | .rd = reg, |
| 5617 | .op = Instruction.Operand.imm(@as(u8, @truncate(x)), 0), | |
| 5617 | .op = Instruction.Operand.imm(@truncate(x), 0), | |
| 5618 | 5618 | } }, |
| 5619 | 5619 | }); |
| 5620 | 5620 | _ = try self.addInst(.{ |
| ... | ... | @@ -5622,7 +5622,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5622 | 5622 | .data = .{ .rr_op = .{ |
| 5623 | 5623 | .rd = reg, |
| 5624 | 5624 | .rn = reg, |
| 5625 | .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 8)), 12), | |
| 5625 | .op = Instruction.Operand.imm(@truncate(x >> 8), 12), | |
| 5626 | 5626 | } }, |
| 5627 | 5627 | }); |
| 5628 | 5628 | _ = try self.addInst(.{ |
| ... | ... | @@ -5630,7 +5630,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5630 | 5630 | .data = .{ .rr_op = .{ |
| 5631 | 5631 | .rd = reg, |
| 5632 | 5632 | .rn = reg, |
| 5633 | .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 16)), 8), | |
| 5633 | .op = Instruction.Operand.imm(@truncate(x >> 16), 8), | |
| 5634 | 5634 | } }, |
| 5635 | 5635 | }); |
| 5636 | 5636 | _ = try self.addInst(.{ |
| ... | ... | @@ -5638,7 +5638,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5638 | 5638 | .data = .{ .rr_op = .{ |
| 5639 | 5639 | .rd = reg, |
| 5640 | 5640 | .rn = reg, |
| 5641 | .op = Instruction.Operand.imm(@as(u8, @truncate(x >> 24)), 4), | |
| 5641 | .op = Instruction.Operand.imm(@truncate(x >> 24), 4), | |
| 5642 | 5642 | } }, |
| 5643 | 5643 | }); |
| 5644 | 5644 | } |
| ... | ... | @@ -5663,12 +5663,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5663 | 5663 | .memory => |addr| { |
| 5664 | 5664 | // The value is in memory at a hard-coded address. |
| 5665 | 5665 | // If the type is a pointer, it means the pointer address is at this memory location. |
| 5666 | try self.genSetReg(ty, reg, .{ .immediate = @as(u32, @intCast(addr)) }); | |
| 5666 | try self.genSetReg(ty, reg, .{ .immediate = @intCast(addr) }); | |
| 5667 | 5667 | try self.genLdrRegister(reg, reg, ty); |
| 5668 | 5668 | }, |
| 5669 | 5669 | .stack_offset => |off| { |
| 5670 | 5670 | // 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)); | |
| 5672 | 5672 | |
| 5673 | 5673 | const tag: Mir.Inst.Tag = switch (abi_size) { |
| 5674 | 5674 | 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb else .ldrb, |
| ... | ... | @@ -5686,7 +5686,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5686 | 5686 | |
| 5687 | 5687 | if (extra_offset) { |
| 5688 | 5688 | const offset = if (off <= math.maxInt(u8)) blk: { |
| 5689 | break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(off))); | |
| 5689 | break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(off)); | |
| 5690 | 5690 | } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off })); |
| 5691 | 5691 | |
| 5692 | 5692 | _ = try self.addInst(.{ |
| ... | ... | @@ -5702,7 +5702,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5702 | 5702 | }); |
| 5703 | 5703 | } else { |
| 5704 | 5704 | const offset = if (off <= math.maxInt(u12)) blk: { |
| 5705 | break :blk Instruction.Offset.imm(@as(u12, @intCast(off))); | |
| 5705 | break :blk Instruction.Offset.imm(@intCast(off)); | |
| 5706 | 5706 | } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.usize, MCValue{ .immediate = off }), .none); |
| 5707 | 5707 | |
| 5708 | 5708 | _ = try self.addInst(.{ |
| ... | ... | @@ -5741,7 +5741,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 5741 | 5741 | |
| 5742 | 5742 | fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void { |
| 5743 | 5743 | const mod = self.bin_file.options.module.?; |
| 5744 | const abi_size = @as(u32, @intCast(ty.abiSize(mod))); | |
| 5744 | const abi_size: u32 = @intCast(ty.abiSize(mod)); | |
| 5745 | 5745 | switch (mcv) { |
| 5746 | 5746 | .dead => unreachable, |
| 5747 | 5747 | .none, .unreach => return, |
| ... | ... | @@ -5780,7 +5780,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I |
| 5780 | 5780 | }, |
| 5781 | 5781 | 2 => { |
| 5782 | 5782 | const offset = if (stack_offset <= math.maxInt(u8)) blk: { |
| 5783 | break :blk Instruction.ExtraLoadStoreOffset.imm(@as(u8, @intCast(stack_offset))); | |
| 5783 | break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(stack_offset)); | |
| 5784 | 5784 | } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset })); |
| 5785 | 5785 | |
| 5786 | 5786 | _ = try self.addInst(.{ |
| ... | ... | @@ -5823,7 +5823,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I |
| 5823 | 5823 | // sub src_reg, fp, #off |
| 5824 | 5824 | try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off }); |
| 5825 | 5825 | }, |
| 5826 | .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @as(u32, @intCast(addr)) }), | |
| 5826 | .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(addr) }), | |
| 5827 | 5827 | .stack_argument_offset => |off| { |
| 5828 | 5828 | _ = try self.addInst(.{ |
| 5829 | 5829 | .tag = .ldr_ptr_stack_argument, |
| ... | ... | @@ -5867,13 +5867,13 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I |
| 5867 | 5867 | } |
| 5868 | 5868 | |
| 5869 | 5869 | fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5870 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5870 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5871 | 5871 | const result = try self.resolveInst(un_op); |
| 5872 | 5872 | return self.finishAir(inst, result, .{ un_op, .none, .none }); |
| 5873 | 5873 | } |
| 5874 | 5874 | |
| 5875 | 5875 | fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 5876 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5876 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5877 | 5877 | const result = if (self.liveness.isUnused(inst)) .dead else result: { |
| 5878 | 5878 | const operand = try self.resolveInst(ty_op.operand); |
| 5879 | 5879 | if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand; |
| ... | ... | @@ -5897,12 +5897,12 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 5897 | 5897 | |
| 5898 | 5898 | fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 5899 | 5899 | const mod = self.bin_file.options.module.?; |
| 5900 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5900 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5901 | 5901 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 5902 | 5902 | const ptr_ty = self.typeOf(ty_op.operand); |
| 5903 | 5903 | const ptr = try self.resolveInst(ty_op.operand); |
| 5904 | 5904 | const array_ty = ptr_ty.childType(mod); |
| 5905 | const array_len = @as(u32, @intCast(array_ty.arrayLen(mod))); | |
| 5905 | const array_len: u32 = @intCast(array_ty.arrayLen(mod)); | |
| 5906 | 5906 | |
| 5907 | 5907 | const stack_offset = try self.allocMem(8, .@"8", inst); |
| 5908 | 5908 | try self.genSetStack(ptr_ty, stack_offset, ptr); |
| ... | ... | @@ -5913,7 +5913,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 5913 | 5913 | } |
| 5914 | 5914 | |
| 5915 | 5915 | fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 5916 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5916 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5917 | 5917 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{ |
| 5918 | 5918 | self.target.cpu.arch, |
| 5919 | 5919 | }); |
| ... | ... | @@ -5921,7 +5921,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 5921 | 5921 | } |
| 5922 | 5922 | |
| 5923 | 5923 | fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 5924 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5924 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5925 | 5925 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{ |
| 5926 | 5926 | self.target.cpu.arch, |
| 5927 | 5927 | }); |
| ... | ... | @@ -5929,7 +5929,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 5929 | 5929 | } |
| 5930 | 5930 | |
| 5931 | 5931 | fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void { |
| 5932 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5932 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5933 | 5933 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 5934 | 5934 | _ = extra; |
| 5935 | 5935 | |
| ... | ... | @@ -5970,7 +5970,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void { |
| 5970 | 5970 | } |
| 5971 | 5971 | |
| 5972 | 5972 | fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 5973 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5973 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5974 | 5974 | const operand = try self.resolveInst(un_op); |
| 5975 | 5975 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 5976 | 5976 | _ = operand; |
| ... | ... | @@ -5980,7 +5980,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 5980 | 5980 | } |
| 5981 | 5981 | |
| 5982 | 5982 | fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 5983 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5983 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5984 | 5984 | const operand = try self.resolveInst(un_op); |
| 5985 | 5985 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 5986 | 5986 | _ = operand; |
| ... | ... | @@ -5990,26 +5990,26 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 5990 | 5990 | } |
| 5991 | 5991 | |
| 5992 | 5992 | fn airSplat(self: *Self, inst: Air.Inst.Index) !void { |
| 5993 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5993 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5994 | 5994 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for arm", .{}); |
| 5995 | 5995 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 5996 | 5996 | } |
| 5997 | 5997 | |
| 5998 | 5998 | fn airSelect(self: *Self, inst: Air.Inst.Index) !void { |
| 5999 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 5999 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6000 | 6000 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 6001 | 6001 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for arm", .{}); |
| 6002 | 6002 | return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs }); |
| 6003 | 6003 | } |
| 6004 | 6004 | |
| 6005 | 6005 | fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { |
| 6006 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6006 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6007 | 6007 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for arm", .{}); |
| 6008 | 6008 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 6009 | 6009 | } |
| 6010 | 6010 | |
| 6011 | 6011 | fn airReduce(self: *Self, inst: Air.Inst.Index) !void { |
| 6012 | const reduce = self.air.instructions.items(.data)[inst].reduce; | |
| 6012 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; | |
| 6013 | 6013 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for arm", .{}); |
| 6014 | 6014 | return self.finishAir(inst, result, .{ reduce.operand, .none, .none }); |
| 6015 | 6015 | } |
| ... | ... | @@ -6018,8 +6018,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 6018 | 6018 | const mod = self.bin_file.options.module.?; |
| 6019 | 6019 | const vector_ty = self.typeOfIndex(inst); |
| 6020 | 6020 | 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]); | |
| 6023 | 6023 | const result: MCValue = res: { |
| 6024 | 6024 | if (self.liveness.isUnused(inst)) break :res MCValue.dead; |
| 6025 | 6025 | return self.fail("TODO implement airAggregateInit for arm", .{}); |
| ... | ... | @@ -6038,7 +6038,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 6038 | 6038 | } |
| 6039 | 6039 | |
| 6040 | 6040 | fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void { |
| 6041 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6041 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6042 | 6042 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 6043 | 6043 | _ = extra; |
| 6044 | 6044 | |
| ... | ... | @@ -6046,12 +6046,12 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void { |
| 6046 | 6046 | } |
| 6047 | 6047 | |
| 6048 | 6048 | fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void { |
| 6049 | const prefetch = self.air.instructions.items(.data)[inst].prefetch; | |
| 6049 | const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; | |
| 6050 | 6050 | return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none }); |
| 6051 | 6051 | } |
| 6052 | 6052 | |
| 6053 | 6053 | fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void { |
| 6054 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 6054 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6055 | 6055 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 6056 | 6056 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 6057 | 6057 | return self.fail("TODO implement airMulAdd for arm", .{}); |
| ... | ... | @@ -6060,14 +6060,14 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void { |
| 6060 | 6060 | } |
| 6061 | 6061 | |
| 6062 | 6062 | fn airTry(self: *Self, inst: Air.Inst.Index) !void { |
| 6063 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 6063 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6064 | 6064 | const extra = self.air.extraData(Air.Try, pl_op.payload); |
| 6065 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 6065 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 6066 | 6066 | const result: MCValue = result: { |
| 6067 | 6067 | const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand }; |
| 6068 | 6068 | const error_union_ty = self.typeOf(pl_op.operand); |
| 6069 | 6069 | const mod = self.bin_file.options.module.?; |
| 6070 | const error_union_size = @as(u32, @intCast(error_union_ty.abiSize(mod))); | |
| 6070 | const error_union_size: u32 = @intCast(error_union_ty.abiSize(mod)); | |
| 6071 | 6071 | const error_union_align = error_union_ty.abiAlignment(mod); |
| 6072 | 6072 | |
| 6073 | 6073 | // The error union will die in the body. However, we need the |
| ... | ... | @@ -6088,7 +6088,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void { |
| 6088 | 6088 | } |
| 6089 | 6089 | |
| 6090 | 6090 | fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 6091 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6091 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6092 | 6092 | const extra = self.air.extraData(Air.TryPtr, ty_pl.payload); |
| 6093 | 6093 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; |
| 6094 | 6094 | _ = body; |
| ... | ... | @@ -6104,7 +6104,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue { |
| 6104 | 6104 | if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod)) |
| 6105 | 6105 | return MCValue{ .none = {} }; |
| 6106 | 6106 | |
| 6107 | const inst_index = Air.refToIndex(inst) orelse return self.genTypedValue(.{ | |
| 6107 | const inst_index = inst.toIndex() orelse return self.genTypedValue(.{ | |
| 6108 | 6108 | .ty = inst_ty, |
| 6109 | 6109 | .val = (try self.air.value(inst, mod)).?, |
| 6110 | 6110 | }); |
| ... | ... | @@ -6136,7 +6136,7 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue { |
| 6136 | 6136 | .none => .none, |
| 6137 | 6137 | .undef => .undef, |
| 6138 | 6138 | .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO |
| 6139 | .immediate => |imm| .{ .immediate = @as(u32, @truncate(imm)) }, | |
| 6139 | .immediate => |imm| .{ .immediate = @truncate(imm) }, | |
| 6140 | 6140 | .memory => |addr| .{ .memory = addr }, |
| 6141 | 6141 | }, |
| 6142 | 6142 | .fail => |msg| { |
| ... | ... | @@ -6194,7 +6194,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6194 | 6194 | } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 6195 | 6195 | result.return_value = .{ .none = {} }; |
| 6196 | 6196 | } else { |
| 6197 | const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod))); | |
| 6197 | const ret_ty_size: u32 = @intCast(ret_ty.abiSize(mod)); | |
| 6198 | 6198 | // TODO handle cases where multiple registers are used |
| 6199 | 6199 | if (ret_ty_size <= 4) { |
| 6200 | 6200 | result.return_value = .{ .register = c_abi_int_return_regs[0] }; |
| ... | ... | @@ -6212,7 +6212,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6212 | 6212 | if (Type.fromInterned(ty).abiAlignment(mod) == .@"8") |
| 6213 | 6213 | ncrn = std.mem.alignForward(usize, ncrn, 2); |
| 6214 | 6214 | |
| 6215 | const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(mod))); | |
| 6215 | const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(mod)); | |
| 6216 | 6216 | if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) { |
| 6217 | 6217 | if (param_size <= 4) { |
| 6218 | 6218 | result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] }; |
| ... | ... | @@ -6241,7 +6241,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6241 | 6241 | } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod) and !ret_ty.isError(mod)) { |
| 6242 | 6242 | result.return_value = .{ .none = {} }; |
| 6243 | 6243 | } else { |
| 6244 | const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod))); | |
| 6244 | const ret_ty_size: u32 = @intCast(ret_ty.abiSize(mod)); | |
| 6245 | 6245 | if (ret_ty_size == 0) { |
| 6246 | 6246 | assert(ret_ty.isError(mod)); |
| 6247 | 6247 | result.return_value = .{ .immediate = 0 }; |
src/arch/riscv64/CodeGen.zig+129-129| ... | ... | @@ -198,7 +198,7 @@ const BigTomb = struct { |
| 198 | 198 | |
| 199 | 199 | fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void { |
| 200 | 200 | const dies = bt.lbt.feed(); |
| 201 | const op_index = Air.refToIndex(op_ref) orelse return; | |
| 201 | const op_index = op_ref.toIndex() orelse return; | |
| 202 | 202 | if (!dies) return; |
| 203 | 203 | bt.function.processDeath(op_index); |
| 204 | 204 | } |
| ... | ... | @@ -325,7 +325,7 @@ fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index { |
| 325 | 325 | |
| 326 | 326 | try self.mir_instructions.ensureUnusedCapacity(gpa, 1); |
| 327 | 327 | |
| 328 | const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len)); | |
| 328 | const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len); | |
| 329 | 329 | self.mir_instructions.appendAssumeCapacity(inst); |
| 330 | 330 | return result_index; |
| 331 | 331 | } |
| ... | ... | @@ -338,11 +338,11 @@ pub fn addExtra(self: *Self, extra: anytype) Allocator.Error!u32 { |
| 338 | 338 | |
| 339 | 339 | pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 { |
| 340 | 340 | const fields = std.meta.fields(@TypeOf(extra)); |
| 341 | const result = @as(u32, @intCast(self.mir_extra.items.len)); | |
| 341 | const result: u32 = @intCast(self.mir_extra.items.len); | |
| 342 | 342 | inline for (fields) |field| { |
| 343 | 343 | self.mir_extra.appendAssumeCapacity(switch (field.type) { |
| 344 | 344 | u32 => @field(extra, field.name), |
| 345 | i32 => @as(u32, @bitCast(@field(extra, field.name))), | |
| 345 | i32 => @bitCast(@field(extra, field.name)), | |
| 346 | 346 | else => @compileError("bad field type"), |
| 347 | 347 | }); |
| 348 | 348 | } |
| ... | ... | @@ -486,7 +486,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 486 | 486 | const old_air_bookkeeping = self.air_bookkeeping; |
| 487 | 487 | try self.ensureProcessDeathCapacity(Liveness.bpi); |
| 488 | 488 | |
| 489 | switch (air_tags[inst]) { | |
| 489 | switch (air_tags[@intFromEnum(inst)]) { | |
| 490 | 490 | // zig fmt: off |
| 491 | 491 | .ptr_add => try self.airPtrArithmetic(inst, .ptr_add), |
| 492 | 492 | .ptr_sub => try self.airPtrArithmetic(inst, .ptr_sub), |
| ... | ... | @@ -725,7 +725,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 725 | 725 | } |
| 726 | 726 | if (std.debug.runtime_safety) { |
| 727 | 727 | if (self.air_bookkeeping < old_air_bookkeeping + 1) { |
| 728 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] }); | |
| 728 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] }); | |
| 729 | 729 | } |
| 730 | 730 | } |
| 731 | 731 | } |
| ... | ... | @@ -758,7 +758,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live |
| 758 | 758 | const dies = @as(u1, @truncate(tomb_bits)) != 0; |
| 759 | 759 | tomb_bits >>= 1; |
| 760 | 760 | if (!dies) continue; |
| 761 | const op_index = Air.refToIndex(op) orelse continue; | |
| 761 | const op_index = op.toIndex() orelse continue; | |
| 762 | 762 | self.processDeath(op_index); |
| 763 | 763 | } |
| 764 | 764 | const is_used = @as(u1, @truncate(tomb_bits)) == 0; |
| ... | ... | @@ -877,19 +877,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 880 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 880 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 881 | 881 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFptrunc for {}", .{self.target.cpu.arch}); |
| 882 | 882 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | fn airFpext(self: *Self, inst: Air.Inst.Index) !void { |
| 886 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 886 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 887 | 887 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFpext for {}", .{self.target.cpu.arch}); |
| 888 | 888 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | fn airIntCast(self: *Self, inst: Air.Inst.Index) !void { |
| 892 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 892 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 893 | 893 | if (self.liveness.isUnused(inst)) |
| 894 | 894 | return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none }); |
| 895 | 895 | |
| ... | ... | @@ -909,7 +909,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void { |
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 912 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 912 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 913 | 913 | if (self.liveness.isUnused(inst)) |
| 914 | 914 | return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none }); |
| 915 | 915 | |
| ... | ... | @@ -920,32 +920,32 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void { |
| 923 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 923 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 924 | 924 | const operand = try self.resolveInst(un_op); |
| 925 | 925 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand; |
| 926 | 926 | return self.finishAir(inst, result, .{ un_op, .none, .none }); |
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | fn airNot(self: *Self, inst: Air.Inst.Index) !void { |
| 930 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 930 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 931 | 931 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement NOT for {}", .{self.target.cpu.arch}); |
| 932 | 932 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | fn airMin(self: *Self, inst: Air.Inst.Index) !void { |
| 936 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 936 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 937 | 937 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement min for {}", .{self.target.cpu.arch}); |
| 938 | 938 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | fn airMax(self: *Self, inst: Air.Inst.Index) !void { |
| 942 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 942 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 943 | 943 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement max for {}", .{self.target.cpu.arch}); |
| 944 | 944 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | fn airSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 948 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 948 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 949 | 949 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 950 | 950 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice for {}", .{self.target.cpu.arch}); |
| 951 | 951 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| ... | ... | @@ -981,8 +981,8 @@ fn binOpRegister( |
| 981 | 981 | |
| 982 | 982 | const lhs_reg = if (lhs_is_register) lhs.register else blk: { |
| 983 | 983 | 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().?; | |
| 986 | 986 | } else null; |
| 987 | 987 | |
| 988 | 988 | const reg = try self.register_manager.allocReg(track_inst, gp); |
| ... | ... | @@ -996,8 +996,8 @@ fn binOpRegister( |
| 996 | 996 | |
| 997 | 997 | const rhs_reg = if (rhs_is_register) rhs.register else blk: { |
| 998 | 998 | 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().?; | |
| 1001 | 1001 | } else null; |
| 1002 | 1002 | |
| 1003 | 1003 | const reg = try self.register_manager.allocReg(track_inst, gp); |
| ... | ... | @@ -1010,7 +1010,7 @@ fn binOpRegister( |
| 1010 | 1010 | defer if (new_rhs_lock) |reg| self.register_manager.unlockReg(reg); |
| 1011 | 1011 | |
| 1012 | 1012 | const dest_reg = if (maybe_inst) |inst| blk: { |
| 1013 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1013 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1014 | 1014 | |
| 1015 | 1015 | if (lhs_is_register and self.reuseOperand(inst, bin_op.lhs, 0, lhs)) { |
| 1016 | 1016 | break :blk lhs_reg; |
| ... | ... | @@ -1123,7 +1123,7 @@ fn binOp( |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 1126 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1126 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1127 | 1127 | const lhs = try self.resolveInst(bin_op.lhs); |
| 1128 | 1128 | const rhs = try self.resolveInst(bin_op.rhs); |
| 1129 | 1129 | const lhs_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -1134,7 +1134,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 1137 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1137 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1138 | 1138 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1139 | 1139 | const lhs = try self.resolveInst(bin_op.lhs); |
| 1140 | 1140 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -1146,43 +1146,43 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void |
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | fn airAddWrap(self: *Self, inst: Air.Inst.Index) !void { |
| 1149 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1149 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1150 | 1150 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement addwrap for {}", .{self.target.cpu.arch}); |
| 1151 | 1151 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | 1154 | fn airAddSat(self: *Self, inst: Air.Inst.Index) !void { |
| 1155 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1155 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1156 | 1156 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch}); |
| 1157 | 1157 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | fn airSubWrap(self: *Self, inst: Air.Inst.Index) !void { |
| 1161 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1161 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1162 | 1162 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement subwrap for {}", .{self.target.cpu.arch}); |
| 1163 | 1163 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | fn airSubSat(self: *Self, inst: Air.Inst.Index) !void { |
| 1167 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1167 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1168 | 1168 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch}); |
| 1169 | 1169 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | fn airMul(self: *Self, inst: Air.Inst.Index) !void { |
| 1173 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1173 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1174 | 1174 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul for {}", .{self.target.cpu.arch}); |
| 1175 | 1175 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | fn airMulWrap(self: *Self, inst: Air.Inst.Index) !void { |
| 1179 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1179 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1180 | 1180 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mulwrap for {}", .{self.target.cpu.arch}); |
| 1181 | 1181 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | fn airMulSat(self: *Self, inst: Air.Inst.Index) !void { |
| 1185 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1185 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1186 | 1186 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch}); |
| 1187 | 1187 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1188 | 1188 | } |
| ... | ... | @@ -1208,105 +1208,105 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | fn airDiv(self: *Self, inst: Air.Inst.Index) !void { |
| 1211 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1211 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1212 | 1212 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement div for {}", .{self.target.cpu.arch}); |
| 1213 | 1213 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | fn airRem(self: *Self, inst: Air.Inst.Index) !void { |
| 1217 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1217 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1218 | 1218 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement rem for {}", .{self.target.cpu.arch}); |
| 1219 | 1219 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | fn airMod(self: *Self, inst: Air.Inst.Index) !void { |
| 1223 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1223 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1224 | 1224 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mod for {}", .{self.target.cpu.arch}); |
| 1225 | 1225 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | fn airBitAnd(self: *Self, inst: Air.Inst.Index) !void { |
| 1229 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1229 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1230 | 1230 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement bitwise and for {}", .{self.target.cpu.arch}); |
| 1231 | 1231 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1232 | 1232 | } |
| 1233 | 1233 | |
| 1234 | 1234 | fn airBitOr(self: *Self, inst: Air.Inst.Index) !void { |
| 1235 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1235 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1236 | 1236 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement bitwise or for {}", .{self.target.cpu.arch}); |
| 1237 | 1237 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | fn airXor(self: *Self, inst: Air.Inst.Index) !void { |
| 1241 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1241 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1242 | 1242 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement xor for {}", .{self.target.cpu.arch}); |
| 1243 | 1243 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | 1246 | fn airShl(self: *Self, inst: Air.Inst.Index) !void { |
| 1247 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1247 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1248 | 1248 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl for {}", .{self.target.cpu.arch}); |
| 1249 | 1249 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1250 | 1250 | } |
| 1251 | 1251 | |
| 1252 | 1252 | fn airShlSat(self: *Self, inst: Air.Inst.Index) !void { |
| 1253 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1253 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1254 | 1254 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch}); |
| 1255 | 1255 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | fn airShr(self: *Self, inst: Air.Inst.Index) !void { |
| 1259 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1259 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1260 | 1260 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shr for {}", .{self.target.cpu.arch}); |
| 1261 | 1261 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | 1264 | fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 1265 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1265 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1266 | 1266 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch}); |
| 1267 | 1267 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | 1270 | fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1271 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1271 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1272 | 1272 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch}); |
| 1273 | 1273 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 1277 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1277 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1278 | 1278 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch}); |
| 1279 | 1279 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void { |
| 1283 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1283 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1284 | 1284 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error for {}", .{self.target.cpu.arch}); |
| 1285 | 1285 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 1289 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1289 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1290 | 1290 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload for {}", .{self.target.cpu.arch}); |
| 1291 | 1291 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | // *(E!T) -> E |
| 1295 | 1295 | fn airUnwrapErrErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1296 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1296 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1297 | 1297 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union error ptr for {}", .{self.target.cpu.arch}); |
| 1298 | 1298 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | 1301 | // *(E!T) -> *T |
| 1302 | 1302 | fn airUnwrapErrPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1303 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1303 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1304 | 1304 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement unwrap error union payload ptr for {}", .{self.target.cpu.arch}); |
| 1305 | 1305 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1306 | 1306 | } |
| 1307 | 1307 | |
| 1308 | 1308 | fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 1309 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1309 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1310 | 1310 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch}); |
| 1311 | 1311 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1312 | 1312 | } |
| ... | ... | @@ -1330,7 +1330,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void { |
| 1330 | 1330 | } |
| 1331 | 1331 | |
| 1332 | 1332 | fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| 1333 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1333 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1334 | 1334 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1335 | 1335 | const mod = self.bin_file.options.module.?; |
| 1336 | 1336 | const optional_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -1346,127 +1346,127 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| 1346 | 1346 | |
| 1347 | 1347 | /// T to E!T |
| 1348 | 1348 | fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 1349 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1349 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1350 | 1350 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion payload for {}", .{self.target.cpu.arch}); |
| 1351 | 1351 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1352 | 1352 | } |
| 1353 | 1353 | |
| 1354 | 1354 | /// E to E!T |
| 1355 | 1355 | fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 1356 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1356 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1357 | 1357 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion error for {}", .{self.target.cpu.arch}); |
| 1358 | 1358 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1362 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1362 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1363 | 1363 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_ptr for {}", .{self.target.cpu.arch}); |
| 1364 | 1364 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1365 | 1365 | } |
| 1366 | 1366 | |
| 1367 | 1367 | fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { |
| 1368 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1368 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1369 | 1369 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_len for {}", .{self.target.cpu.arch}); |
| 1370 | 1370 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1374 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1374 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1375 | 1375 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_len_ptr for {}", .{self.target.cpu.arch}); |
| 1376 | 1376 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1377 | 1377 | } |
| 1378 | 1378 | |
| 1379 | 1379 | fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1380 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1380 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1381 | 1381 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_ptr_ptr for {}", .{self.target.cpu.arch}); |
| 1382 | 1382 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | 1385 | fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 1386 | 1386 | const is_volatile = false; // TODO |
| 1387 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1387 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1388 | 1388 | const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_elem_val for {}", .{self.target.cpu.arch}); |
| 1389 | 1389 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1393 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1393 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1394 | 1394 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1395 | 1395 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement slice_elem_ptr for {}", .{self.target.cpu.arch}); |
| 1396 | 1396 | return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none }); |
| 1397 | 1397 | } |
| 1398 | 1398 | |
| 1399 | 1399 | fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 1400 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1400 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1401 | 1401 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch}); |
| 1402 | 1402 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 1406 | 1406 | const is_volatile = false; // TODO |
| 1407 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1407 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1408 | 1408 | const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_val for {}", .{self.target.cpu.arch}); |
| 1409 | 1409 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1413 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1413 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1414 | 1414 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1415 | 1415 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_ptr for {}", .{self.target.cpu.arch}); |
| 1416 | 1416 | return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none }); |
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 1420 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1420 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1421 | 1421 | _ = bin_op; |
| 1422 | 1422 | return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch}); |
| 1423 | 1423 | // return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1424 | 1424 | } |
| 1425 | 1425 | |
| 1426 | 1426 | fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 1427 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1427 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1428 | 1428 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch}); |
| 1429 | 1429 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | fn airClz(self: *Self, inst: Air.Inst.Index) !void { |
| 1433 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1433 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1434 | 1434 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch}); |
| 1435 | 1435 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | fn airCtz(self: *Self, inst: Air.Inst.Index) !void { |
| 1439 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1439 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1440 | 1440 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch}); |
| 1441 | 1441 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | fn airPopcount(self: *Self, inst: Air.Inst.Index) !void { |
| 1445 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1445 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1446 | 1446 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch}); |
| 1447 | 1447 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | fn airAbs(self: *Self, inst: Air.Inst.Index) !void { |
| 1451 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1451 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1452 | 1452 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airAbs for {}", .{self.target.cpu.arch}); |
| 1453 | 1453 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | 1456 | fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { |
| 1457 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1457 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1458 | 1458 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airByteSwap for {}", .{self.target.cpu.arch}); |
| 1459 | 1459 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void { |
| 1463 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1463 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1464 | 1464 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch}); |
| 1465 | 1465 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1466 | 1466 | } |
| 1467 | 1467 | |
| 1468 | 1468 | fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void { |
| 1469 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1469 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1470 | 1470 | const result: MCValue = if (self.liveness.isUnused(inst)) |
| 1471 | 1471 | .dead |
| 1472 | 1472 | else |
| ... | ... | @@ -1500,7 +1500,7 @@ fn reuseOperand(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, op_ind |
| 1500 | 1500 | |
| 1501 | 1501 | // That makes us responsible for doing the rest of the stuff that processDeath would have done. |
| 1502 | 1502 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 1503 | branch.inst_table.putAssumeCapacity(Air.refToIndex(operand).?, .dead); | |
| 1503 | branch.inst_table.putAssumeCapacity(operand.toIndex().?, .dead); | |
| 1504 | 1504 | |
| 1505 | 1505 | return true; |
| 1506 | 1506 | } |
| ... | ... | @@ -1533,7 +1533,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo |
| 1533 | 1533 | |
| 1534 | 1534 | fn airLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 1535 | 1535 | const mod = self.bin_file.options.module.?; |
| 1536 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1536 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1537 | 1537 | const elem_ty = self.typeOfIndex(inst); |
| 1538 | 1538 | const result: MCValue = result: { |
| 1539 | 1539 | if (!elem_ty.hasRuntimeBits(mod)) |
| ... | ... | @@ -1590,7 +1590,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 1590 | 1590 | } else { |
| 1591 | 1591 | // TODO if the value is undef, don't lower this instruction |
| 1592 | 1592 | } |
| 1593 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1593 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1594 | 1594 | const ptr = try self.resolveInst(bin_op.lhs); |
| 1595 | 1595 | const value = try self.resolveInst(bin_op.rhs); |
| 1596 | 1596 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -1602,13 +1602,13 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | 1604 | fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1605 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1605 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1606 | 1606 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 1607 | 1607 | return self.structFieldPtr(extra.struct_operand, ty_pl.ty, extra.field_index); |
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void { |
| 1611 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1611 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1612 | 1612 | return self.structFieldPtr(ty_op.operand, ty_op.ty, index); |
| 1613 | 1613 | } |
| 1614 | 1614 | fn structFieldPtr(self: *Self, operand: Air.Inst.Ref, ty: Air.Inst.Ref, index: u32) !void { |
| ... | ... | @@ -1620,7 +1620,7 @@ fn structFieldPtr(self: *Self, operand: Air.Inst.Ref, ty: Air.Inst.Ref, index: u |
| 1620 | 1620 | } |
| 1621 | 1621 | |
| 1622 | 1622 | fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 1623 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1623 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1624 | 1624 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 1625 | 1625 | _ = extra; |
| 1626 | 1626 | return self.fail("TODO implement codegen struct_field_val", .{}); |
| ... | ... | @@ -1634,8 +1634,8 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1634 | 1634 | |
| 1635 | 1635 | fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void { |
| 1636 | 1636 | 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(); | |
| 1639 | 1639 | const owner_decl = mod.funcOwnerDeclIndex(self.func_index); |
| 1640 | 1640 | const name = mod.getParamName(self.func_index, arg.src_index); |
| 1641 | 1641 | |
| ... | ... | @@ -1712,11 +1712,11 @@ fn airFence(self: *Self) !void { |
| 1712 | 1712 | fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { |
| 1713 | 1713 | const mod = self.bin_file.options.module.?; |
| 1714 | 1714 | if (modifier == .always_tail) return self.fail("TODO implement tail calls for riscv64", .{}); |
| 1715 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 1715 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 1716 | 1716 | const fn_ty = self.typeOf(pl_op.operand); |
| 1717 | 1717 | const callee = pl_op.operand; |
| 1718 | 1718 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 1719 | const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len])); | |
| 1719 | const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]); | |
| 1720 | 1720 | |
| 1721 | 1721 | var info = try self.resolveCallingConventionValues(fn_ty); |
| 1722 | 1722 | defer info.deinit(self); |
| ... | ... | @@ -1755,7 +1755,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 1755 | 1755 | const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl); |
| 1756 | 1756 | const sym = elf_file.symbol(sym_index); |
| 1757 | 1757 | _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file); |
| 1758 | const got_addr = @as(u32, @intCast(sym.zigGotAddress(elf_file))); | |
| 1758 | const got_addr: u32 = @intCast(sym.zigGotAddress(elf_file)); | |
| 1759 | 1759 | try self.genSetReg(Type.usize, .ra, .{ .memory = got_addr }); |
| 1760 | 1760 | _ = try self.addInst(.{ |
| 1761 | 1761 | .tag = .jalr, |
| ... | ... | @@ -1824,14 +1824,14 @@ fn ret(self: *Self, mcv: MCValue) !void { |
| 1824 | 1824 | } |
| 1825 | 1825 | |
| 1826 | 1826 | fn airRet(self: *Self, inst: Air.Inst.Index) !void { |
| 1827 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1827 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1828 | 1828 | const operand = try self.resolveInst(un_op); |
| 1829 | 1829 | try self.ret(operand); |
| 1830 | 1830 | return self.finishAir(inst, .dead, .{ un_op, .none, .none }); |
| 1831 | 1831 | } |
| 1832 | 1832 | |
| 1833 | 1833 | fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 1834 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1834 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1835 | 1835 | const ptr = try self.resolveInst(un_op); |
| 1836 | 1836 | _ = ptr; |
| 1837 | 1837 | return self.fail("TODO implement airRetLoad for {}", .{self.target.cpu.arch}); |
| ... | ... | @@ -1839,7 +1839,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | 1841 | fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void { |
| 1842 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1842 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1843 | 1843 | if (self.liveness.isUnused(inst)) |
| 1844 | 1844 | return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1845 | 1845 | const ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -1864,7 +1864,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void { |
| 1864 | 1864 | } |
| 1865 | 1865 | |
| 1866 | 1866 | fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 1867 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1867 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1868 | 1868 | const operand = try self.resolveInst(un_op); |
| 1869 | 1869 | _ = operand; |
| 1870 | 1870 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch}); |
| ... | ... | @@ -1872,7 +1872,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 1872 | 1872 | } |
| 1873 | 1873 | |
| 1874 | 1874 | fn 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; | |
| 1876 | 1876 | |
| 1877 | 1877 | _ = try self.addInst(.{ |
| 1878 | 1878 | .tag = .dbg_line, |
| ... | ... | @@ -1886,7 +1886,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void { |
| 1886 | 1886 | } |
| 1887 | 1887 | |
| 1888 | 1888 | fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 1889 | const ty_fn = self.air.instructions.items(.data)[inst].ty_fn; | |
| 1889 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 1890 | 1890 | const mod = self.bin_file.options.module.?; |
| 1891 | 1891 | const func = mod.funcInfo(ty_fn.func); |
| 1892 | 1892 | // TODO emit debug info for function change |
| ... | ... | @@ -1900,7 +1900,7 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 1900 | 1900 | } |
| 1901 | 1901 | |
| 1902 | 1902 | fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 1903 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 1903 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 1904 | 1904 | const name = self.air.nullTerminatedString(pl_op.payload); |
| 1905 | 1905 | const operand = pl_op.operand; |
| 1906 | 1906 | // TODO emit debug info for this variable |
| ... | ... | @@ -1944,7 +1944,7 @@ fn isNonErr(self: *Self, operand: MCValue) !MCValue { |
| 1944 | 1944 | } |
| 1945 | 1945 | |
| 1946 | 1946 | fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 1947 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1947 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1948 | 1948 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1949 | 1949 | const operand = try self.resolveInst(un_op); |
| 1950 | 1950 | break :result try self.isNull(operand); |
| ... | ... | @@ -1953,7 +1953,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 1953 | 1953 | } |
| 1954 | 1954 | |
| 1955 | 1955 | fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1956 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1956 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1957 | 1957 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1958 | 1958 | const operand_ptr = try self.resolveInst(un_op); |
| 1959 | 1959 | const operand: MCValue = blk: { |
| ... | ... | @@ -1971,7 +1971,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1971 | 1971 | } |
| 1972 | 1972 | |
| 1973 | 1973 | fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 1974 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1974 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1975 | 1975 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1976 | 1976 | const operand = try self.resolveInst(un_op); |
| 1977 | 1977 | break :result try self.isNonNull(operand); |
| ... | ... | @@ -1980,7 +1980,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 1980 | 1980 | } |
| 1981 | 1981 | |
| 1982 | 1982 | fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1983 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1983 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1984 | 1984 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1985 | 1985 | const operand_ptr = try self.resolveInst(un_op); |
| 1986 | 1986 | const operand: MCValue = blk: { |
| ... | ... | @@ -1998,7 +1998,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 1998 | 1998 | } |
| 1999 | 1999 | |
| 2000 | 2000 | fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2001 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2001 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2002 | 2002 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2003 | 2003 | const operand = try self.resolveInst(un_op); |
| 2004 | 2004 | break :result try self.isErr(operand); |
| ... | ... | @@ -2007,7 +2007,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2007 | 2007 | } |
| 2008 | 2008 | |
| 2009 | 2009 | fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2010 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2010 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2011 | 2011 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2012 | 2012 | const operand_ptr = try self.resolveInst(un_op); |
| 2013 | 2013 | const operand: MCValue = blk: { |
| ... | ... | @@ -2025,7 +2025,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2025 | 2025 | } |
| 2026 | 2026 | |
| 2027 | 2027 | fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2028 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2028 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2029 | 2029 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2030 | 2030 | const operand = try self.resolveInst(un_op); |
| 2031 | 2031 | break :result try self.isNonErr(operand); |
| ... | ... | @@ -2034,7 +2034,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 2036 | 2036 | fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2037 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2037 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2038 | 2038 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2039 | 2039 | const operand_ptr = try self.resolveInst(un_op); |
| 2040 | 2040 | const operand: MCValue = blk: { |
| ... | ... | @@ -2053,9 +2053,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2053 | 2053 | |
| 2054 | 2054 | fn airLoop(self: *Self, inst: Air.Inst.Index) !void { |
| 2055 | 2055 | // A loop is a setup to be able to jump back to the beginning. |
| 2056 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2056 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2057 | 2057 | const loop = self.air.extraData(Air.Block, ty_pl.payload); |
| 2058 | const body = self.air.extra[loop.end..][0..loop.data.body_len]; | |
| 2058 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]); | |
| 2059 | 2059 | const start_index = self.code.items.len; |
| 2060 | 2060 | try self.genBody(body); |
| 2061 | 2061 | try self.jump(start_index); |
| ... | ... | @@ -2081,9 +2081,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 2081 | 2081 | }); |
| 2082 | 2082 | defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa); |
| 2083 | 2083 | |
| 2084 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2084 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2085 | 2085 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 2086 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 2086 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 2087 | 2087 | try self.genBody(body); |
| 2088 | 2088 | |
| 2089 | 2089 | for (self.blocks.getPtr(inst).?.relocs.items) |reloc| try self.performReloc(reloc); |
| ... | ... | @@ -2093,7 +2093,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | 2095 | fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 2096 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 2096 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 2097 | 2097 | const condition = pl_op.operand; |
| 2098 | 2098 | _ = condition; |
| 2099 | 2099 | return self.fail("TODO airSwitch for {}", .{self.target.cpu.arch}); |
| ... | ... | @@ -2109,13 +2109,13 @@ fn performReloc(self: *Self, reloc: Reloc) !void { |
| 2109 | 2109 | } |
| 2110 | 2110 | |
| 2111 | 2111 | fn airBr(self: *Self, inst: Air.Inst.Index) !void { |
| 2112 | const branch = self.air.instructions.items(.data)[inst].br; | |
| 2112 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 2113 | 2113 | try self.br(branch.block_inst, branch.operand); |
| 2114 | 2114 | return self.finishAir(inst, .dead, .{ branch.operand, .none, .none }); |
| 2115 | 2115 | } |
| 2116 | 2116 | |
| 2117 | 2117 | fn airBoolOp(self: *Self, inst: Air.Inst.Index) !void { |
| 2118 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2118 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2119 | 2119 | const air_tags = self.air.instructions.items(.tag); |
| 2120 | 2120 | _ = air_tags; |
| 2121 | 2121 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement boolean operations for {}", .{self.target.cpu.arch}); |
| ... | ... | @@ -2148,14 +2148,14 @@ fn brVoid(self: *Self, block: Air.Inst.Index) !void { |
| 2148 | 2148 | } |
| 2149 | 2149 | |
| 2150 | 2150 | fn airAsm(self: *Self, inst: Air.Inst.Index) !void { |
| 2151 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2151 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2152 | 2152 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); |
| 2153 | 2153 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; |
| 2154 | const clobbers_len = @as(u31, @truncate(extra.data.flags)); | |
| 2154 | const clobbers_len: u31 = @truncate(extra.data.flags); | |
| 2155 | 2155 | var extra_i: usize = extra.end; |
| 2156 | const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len])); | |
| 2156 | const outputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]); | |
| 2157 | 2157 | extra_i += outputs.len; |
| 2158 | const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len])); | |
| 2158 | const inputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]); | |
| 2159 | 2159 | extra_i += inputs.len; |
| 2160 | 2160 | |
| 2161 | 2161 | const dead = !is_volatile and self.liveness.isUnused(inst); |
| ... | ... | @@ -2300,20 +2300,20 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 2300 | 2300 | return self.genSetReg(ty, reg, .{ .immediate = 0xaaaaaaaaaaaaaaaa }); |
| 2301 | 2301 | }, |
| 2302 | 2302 | .immediate => |unsigned_x| { |
| 2303 | const x = @as(i64, @bitCast(unsigned_x)); | |
| 2303 | const x: i64 = @bitCast(unsigned_x); | |
| 2304 | 2304 | if (math.minInt(i12) <= x and x <= math.maxInt(i12)) { |
| 2305 | 2305 | _ = try self.addInst(.{ |
| 2306 | 2306 | .tag = .addi, |
| 2307 | 2307 | .data = .{ .i_type = .{ |
| 2308 | 2308 | .rd = reg, |
| 2309 | 2309 | .rs1 = .zero, |
| 2310 | .imm12 = @as(i12, @intCast(x)), | |
| 2310 | .imm12 = @intCast(x), | |
| 2311 | 2311 | } }, |
| 2312 | 2312 | }); |
| 2313 | 2313 | } else if (math.minInt(i32) <= x and x <= math.maxInt(i32)) { |
| 2314 | const lo12 = @as(i12, @truncate(x)); | |
| 2314 | const lo12: i12 = @truncate(x); | |
| 2315 | 2315 | const carry: i32 = if (lo12 < 0) 1 else 0; |
| 2316 | const hi20 = @as(i20, @truncate((x >> 12) +% carry)); | |
| 2316 | const hi20: i20 = @truncate((x >> 12) +% carry); | |
| 2317 | 2317 | |
| 2318 | 2318 | // TODO: add test case for 32-bit immediate |
| 2319 | 2319 | _ = try self.addInst(.{ |
| ... | ... | @@ -2373,13 +2373,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void |
| 2373 | 2373 | } |
| 2374 | 2374 | |
| 2375 | 2375 | fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2376 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2376 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2377 | 2377 | const result = try self.resolveInst(un_op); |
| 2378 | 2378 | return self.finishAir(inst, result, .{ un_op, .none, .none }); |
| 2379 | 2379 | } |
| 2380 | 2380 | |
| 2381 | 2381 | fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 2382 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2382 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2383 | 2383 | const result = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2384 | 2384 | const operand = try self.resolveInst(ty_op.operand); |
| 2385 | 2385 | if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand; |
| ... | ... | @@ -2398,7 +2398,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 2398 | 2398 | } |
| 2399 | 2399 | |
| 2400 | 2400 | fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 2401 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2401 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2402 | 2402 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airArrayToSlice for {}", .{ |
| 2403 | 2403 | self.target.cpu.arch, |
| 2404 | 2404 | }); |
| ... | ... | @@ -2406,7 +2406,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 2406 | 2406 | } |
| 2407 | 2407 | |
| 2408 | 2408 | fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 2409 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2409 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2410 | 2410 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{ |
| 2411 | 2411 | self.target.cpu.arch, |
| 2412 | 2412 | }); |
| ... | ... | @@ -2414,7 +2414,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 2414 | 2414 | } |
| 2415 | 2415 | |
| 2416 | 2416 | fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 2417 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2417 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2418 | 2418 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{ |
| 2419 | 2419 | self.target.cpu.arch, |
| 2420 | 2420 | }); |
| ... | ... | @@ -2422,7 +2422,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 2422 | 2422 | } |
| 2423 | 2423 | |
| 2424 | 2424 | fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void { |
| 2425 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2425 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2426 | 2426 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 2427 | 2427 | _ = extra; |
| 2428 | 2428 | return self.fail("TODO implement airCmpxchg for {}", .{ |
| ... | ... | @@ -2463,7 +2463,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void { |
| 2463 | 2463 | } |
| 2464 | 2464 | |
| 2465 | 2465 | fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 2466 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2466 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2467 | 2467 | const operand = try self.resolveInst(un_op); |
| 2468 | 2468 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 2469 | 2469 | _ = operand; |
| ... | ... | @@ -2473,7 +2473,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 2473 | 2473 | } |
| 2474 | 2474 | |
| 2475 | 2475 | fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 2476 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2476 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2477 | 2477 | const operand = try self.resolveInst(un_op); |
| 2478 | 2478 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 2479 | 2479 | _ = operand; |
| ... | ... | @@ -2483,26 +2483,26 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 2483 | 2483 | } |
| 2484 | 2484 | |
| 2485 | 2485 | fn airSplat(self: *Self, inst: Air.Inst.Index) !void { |
| 2486 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2486 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2487 | 2487 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for riscv64", .{}); |
| 2488 | 2488 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2489 | 2489 | } |
| 2490 | 2490 | |
| 2491 | 2491 | fn airSelect(self: *Self, inst: Air.Inst.Index) !void { |
| 2492 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 2492 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 2493 | 2493 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 2494 | 2494 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for riscv64", .{}); |
| 2495 | 2495 | return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs }); |
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { |
| 2499 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2499 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2500 | 2500 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airShuffle for riscv64", .{}); |
| 2501 | 2501 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2502 | 2502 | } |
| 2503 | 2503 | |
| 2504 | 2504 | fn airReduce(self: *Self, inst: Air.Inst.Index) !void { |
| 2505 | const reduce = self.air.instructions.items(.data)[inst].reduce; | |
| 2505 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; | |
| 2506 | 2506 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airReduce for riscv64", .{}); |
| 2507 | 2507 | return self.finishAir(inst, result, .{ reduce.operand, .none, .none }); |
| 2508 | 2508 | } |
| ... | ... | @@ -2511,8 +2511,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 2511 | 2511 | const mod = self.bin_file.options.module.?; |
| 2512 | 2512 | const vector_ty = self.typeOfIndex(inst); |
| 2513 | 2513 | 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]); | |
| 2516 | 2516 | const result: MCValue = res: { |
| 2517 | 2517 | if (self.liveness.isUnused(inst)) break :res MCValue.dead; |
| 2518 | 2518 | return self.fail("TODO implement airAggregateInit for riscv64", .{}); |
| ... | ... | @@ -2531,7 +2531,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 2531 | 2531 | } |
| 2532 | 2532 | |
| 2533 | 2533 | fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void { |
| 2534 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2534 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2535 | 2535 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 2536 | 2536 | _ = extra; |
| 2537 | 2537 | return self.fail("TODO implement airUnionInit for riscv64", .{}); |
| ... | ... | @@ -2539,12 +2539,12 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void { |
| 2539 | 2539 | } |
| 2540 | 2540 | |
| 2541 | 2541 | fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void { |
| 2542 | const prefetch = self.air.instructions.items(.data)[inst].prefetch; | |
| 2542 | const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; | |
| 2543 | 2543 | return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none }); |
| 2544 | 2544 | } |
| 2545 | 2545 | |
| 2546 | 2546 | fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void { |
| 2547 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 2547 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 2548 | 2548 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 2549 | 2549 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 2550 | 2550 | return self.fail("TODO implement airMulAdd for riscv64", .{}); |
| ... | ... | @@ -2560,7 +2560,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue { |
| 2560 | 2560 | if (!inst_ty.hasRuntimeBits(mod)) |
| 2561 | 2561 | return MCValue{ .none = {} }; |
| 2562 | 2562 | |
| 2563 | const inst_index = Air.refToIndex(inst) orelse return self.genTypedValue(.{ | |
| 2563 | const inst_index = inst.toIndex() orelse return self.genTypedValue(.{ | |
| 2564 | 2564 | .ty = inst_ty, |
| 2565 | 2565 | .val = (try self.air.value(inst, mod)).?, |
| 2566 | 2566 | }); |
| ... | ... | @@ -2656,7 +2656,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 2656 | 2656 | const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 }; |
| 2657 | 2657 | |
| 2658 | 2658 | for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| { |
| 2659 | const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(mod))); | |
| 2659 | const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(mod)); | |
| 2660 | 2660 | if (param_size <= 8) { |
| 2661 | 2661 | if (next_register < argument_registers.len) { |
| 2662 | 2662 | result_arg.* = .{ .register = argument_registers[next_register] }; |
| ... | ... | @@ -2693,7 +2693,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 2693 | 2693 | } else switch (cc) { |
| 2694 | 2694 | .Naked => unreachable, |
| 2695 | 2695 | .Unspecified, .C => { |
| 2696 | const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(mod))); | |
| 2696 | const ret_ty_size: u32 = @intCast(ret_ty.abiSize(mod)); | |
| 2697 | 2697 | if (ret_ty_size <= 8) { |
| 2698 | 2698 | result.return_value = .{ .register = .a0 }; |
| 2699 | 2699 | } else if (ret_ty_size <= 16) { |
src/arch/sparc64/CodeGen.zig+107-109| ... | ... | @@ -243,7 +243,7 @@ const BigTomb = struct { |
| 243 | 243 | |
| 244 | 244 | fn feed(bt: *BigTomb, op_ref: Air.Inst.Ref) void { |
| 245 | 245 | const dies = bt.lbt.feed(); |
| 246 | const op_index = Air.refToIndex(op_ref) orelse return; | |
| 246 | const op_index = op_ref.toIndex() orelse return; | |
| 247 | 247 | if (!dies) return; |
| 248 | 248 | bt.function.processDeath(op_index); |
| 249 | 249 | } |
| ... | ... | @@ -504,7 +504,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 504 | 504 | const old_air_bookkeeping = self.air_bookkeeping; |
| 505 | 505 | try self.ensureProcessDeathCapacity(Liveness.bpi); |
| 506 | 506 | |
| 507 | switch (air_tags[inst]) { | |
| 507 | switch (air_tags[@intFromEnum(inst)]) { | |
| 508 | 508 | // zig fmt: off |
| 509 | 509 | .ptr_add => try self.airPtrArithmetic(inst, .ptr_add), |
| 510 | 510 | .ptr_sub => try self.airPtrArithmetic(inst, .ptr_sub), |
| ... | ... | @@ -746,21 +746,21 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 746 | 746 | |
| 747 | 747 | if (std.debug.runtime_safety) { |
| 748 | 748 | if (self.air_bookkeeping < old_air_bookkeeping + 1) { |
| 749 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] }); | |
| 749 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] }); | |
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | } |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | fn airAddSat(self: *Self, inst: Air.Inst.Index) !void { |
| 756 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 756 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 757 | 757 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement add_sat for {}", .{self.target.cpu.arch}); |
| 758 | 758 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | fn 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; | |
| 764 | 764 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 765 | 765 | const mod = self.bin_file.options.module.?; |
| 766 | 766 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| ... | ... | @@ -843,7 +843,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 843 | 843 | const mod = self.bin_file.options.module.?; |
| 844 | 844 | const vector_ty = self.typeOfIndex(inst); |
| 845 | 845 | const len = vector_ty.vectorLen(mod); |
| 846 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 846 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 847 | 847 | const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len])); |
| 848 | 848 | const result: MCValue = res: { |
| 849 | 849 | if (self.liveness.isUnused(inst)) break :res MCValue.dead; |
| ... | ... | @@ -868,14 +868,14 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void { |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 871 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 871 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 872 | 872 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement array_elem_val for {}", .{self.target.cpu.arch}); |
| 873 | 873 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 877 | 877 | const mod = self.bin_file.options.module.?; |
| 878 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 878 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 879 | 879 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 880 | 880 | const ptr_ty = self.typeOf(ty_op.operand); |
| 881 | 881 | const ptr = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -891,7 +891,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | fn airAsm(self: *Self, inst: Air.Inst.Index) !void { |
| 894 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 894 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 895 | 895 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); |
| 896 | 896 | const is_volatile = (extra.data.flags & 0x80000000) != 0; |
| 897 | 897 | const clobbers_len = @as(u31, @truncate(extra.data.flags)); |
| ... | ... | @@ -1047,7 +1047,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { |
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | fn 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; | |
| 1051 | 1051 | |
| 1052 | 1052 | return self.fail("TODO implement airAtomicLoad for {}", .{ |
| 1053 | 1053 | self.target.cpu.arch, |
| ... | ... | @@ -1055,7 +1055,7 @@ fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | fn 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; | |
| 1059 | 1059 | |
| 1060 | 1060 | return self.fail("TODO implement airAtomicRmw for {}", .{ |
| 1061 | 1061 | self.target.cpu.arch, |
| ... | ... | @@ -1063,7 +1063,7 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void { |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 1066 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1066 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1067 | 1067 | const lhs = try self.resolveInst(bin_op.lhs); |
| 1068 | 1068 | const rhs = try self.resolveInst(bin_op.rhs); |
| 1069 | 1069 | const lhs_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -1080,14 +1080,14 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void { |
| 1083 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1083 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1084 | 1084 | const operand = try self.resolveInst(un_op); |
| 1085 | 1085 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else operand; |
| 1086 | 1086 | return self.finishAir(inst, result, .{ un_op, .none, .none }); |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 1090 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1090 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1091 | 1091 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 1092 | 1092 | const lhs = try self.resolveInst(bin_op.lhs); |
| 1093 | 1093 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -1105,7 +1105,7 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void |
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 1108 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1108 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1109 | 1109 | const result = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1110 | 1110 | const operand = try self.resolveInst(ty_op.operand); |
| 1111 | 1111 | if (self.reuseOperand(inst, ty_op.operand, 0, operand)) break :result operand; |
| ... | ... | @@ -1125,7 +1125,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | 1127 | fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void { |
| 1128 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1128 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1129 | 1129 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airBitReverse for {}", .{self.target.cpu.arch}); |
| 1130 | 1130 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1131 | 1131 | } |
| ... | ... | @@ -1143,9 +1143,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 1143 | 1143 | }); |
| 1144 | 1144 | defer self.blocks.getPtr(inst).?.relocs.deinit(self.gpa); |
| 1145 | 1145 | |
| 1146 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1146 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1147 | 1147 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 1148 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 1148 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 1149 | 1149 | try self.genBody(body); |
| 1150 | 1150 | |
| 1151 | 1151 | // relocations for `bpcc` instructions |
| ... | ... | @@ -1170,7 +1170,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | fn airBr(self: *Self, inst: Air.Inst.Index) !void { |
| 1173 | const branch = self.air.instructions.items(.data)[inst].br; | |
| 1173 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 1174 | 1174 | try self.br(branch.block_inst, branch.operand); |
| 1175 | 1175 | return self.finishAir(inst, .dead, .{ branch.operand, .none, .none }); |
| 1176 | 1176 | } |
| ... | ... | @@ -1207,7 +1207,7 @@ fn airBreakpoint(self: *Self) !void { |
| 1207 | 1207 | |
| 1208 | 1208 | fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { |
| 1209 | 1209 | const mod = self.bin_file.options.module.?; |
| 1210 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1210 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1211 | 1211 | |
| 1212 | 1212 | // We have hardware byteswapper in SPARCv9, don't let mainstream compilers mislead you. |
| 1213 | 1213 | // That being said, the strategy to lower this is: |
| ... | ... | @@ -1293,7 +1293,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { |
| 1293 | 1293 | fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { |
| 1294 | 1294 | if (modifier == .always_tail) return self.fail("TODO implement tail calls for {}", .{self.target.cpu.arch}); |
| 1295 | 1295 | |
| 1296 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 1296 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 1297 | 1297 | const callee = pl_op.operand; |
| 1298 | 1298 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 1299 | 1299 | const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end .. extra.end + extra.data.args_len])); |
| ... | ... | @@ -1423,13 +1423,13 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | fn airClz(self: *Self, inst: Air.Inst.Index) !void { |
| 1426 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1426 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1427 | 1427 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airClz for {}", .{self.target.cpu.arch}); |
| 1428 | 1428 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1429 | 1429 | } |
| 1430 | 1430 | |
| 1431 | 1431 | fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void { |
| 1432 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1432 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1433 | 1433 | const mod = self.bin_file.options.module.?; |
| 1434 | 1434 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1435 | 1435 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -1486,7 +1486,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void { |
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | 1488 | fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 1489 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1489 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1490 | 1490 | const operand = try self.resolveInst(un_op); |
| 1491 | 1491 | _ = operand; |
| 1492 | 1492 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCmpLtErrorsLen for {}", .{self.target.cpu.arch}); |
| ... | ... | @@ -1494,7 +1494,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | 1496 | fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void { |
| 1497 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1497 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1498 | 1498 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 1499 | 1499 | _ = extra; |
| 1500 | 1500 | |
| ... | ... | @@ -1504,11 +1504,11 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void { |
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 1507 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 1507 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 1508 | 1508 | const condition = try self.resolveInst(pl_op.operand); |
| 1509 | 1509 | const extra = self.air.extraData(Air.CondBr, pl_op.payload); |
| 1510 | const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len]; | |
| 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]); | |
| 1512 | 1512 | const liveness_condbr = self.liveness.getCondBr(inst); |
| 1513 | 1513 | |
| 1514 | 1514 | // Here we emit a branch to the false section. |
| ... | ... | @@ -1518,7 +1518,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 1518 | 1518 | // that death now instead of later as this has an effect on |
| 1519 | 1519 | // whether it needs to be spilled in the branches |
| 1520 | 1520 | if (self.liveness.operandDies(inst, 0)) { |
| 1521 | if (Air.refToIndex(pl_op.operand)) |op_index| { | |
| 1521 | if (pl_op.operand.toIndex()) |op_index| { | |
| 1522 | 1522 | self.processDeath(op_index); |
| 1523 | 1523 | } |
| 1524 | 1524 | } |
| ... | ... | @@ -1650,7 +1650,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | 1652 | fn airCtz(self: *Self, inst: Air.Inst.Index) !void { |
| 1653 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1653 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1654 | 1654 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airCtz for {}", .{self.target.cpu.arch}); |
| 1655 | 1655 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1656 | 1656 | } |
| ... | ... | @@ -1661,7 +1661,7 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 1664 | const ty_fn = self.air.instructions.items(.data)[inst].ty_fn; | |
| 1664 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 1665 | 1665 | const mod = self.bin_file.options.module.?; |
| 1666 | 1666 | const func = mod.funcInfo(ty_fn.func); |
| 1667 | 1667 | // TODO emit debug info for function change |
| ... | ... | @@ -1670,7 +1670,7 @@ fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | 1672 | fn 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; | |
| 1674 | 1674 | |
| 1675 | 1675 | _ = try self.addInst(.{ |
| 1676 | 1676 | .tag = .dbg_line, |
| ... | ... | @@ -1686,7 +1686,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void { |
| 1686 | 1686 | } |
| 1687 | 1687 | |
| 1688 | 1688 | fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 1689 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 1689 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 1690 | 1690 | const name = self.air.nullTerminatedString(pl_op.payload); |
| 1691 | 1691 | const operand = pl_op.operand; |
| 1692 | 1692 | // TODO emit debug info for this variable |
| ... | ... | @@ -1695,13 +1695,13 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | 1697 | fn airDiv(self: *Self, inst: Air.Inst.Index) !void { |
| 1698 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1698 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1699 | 1699 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement div for {}", .{self.target.cpu.arch}); |
| 1700 | 1700 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | 1703 | fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 1704 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1704 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1705 | 1705 | const operand = try self.resolveInst(un_op); |
| 1706 | 1706 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 1707 | 1707 | _ = operand; |
| ... | ... | @@ -1711,14 +1711,14 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 1711 | 1711 | } |
| 1712 | 1712 | |
| 1713 | 1713 | fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 1714 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1714 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1715 | 1715 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .errunion_payload_ptr_set for {}", .{self.target.cpu.arch}); |
| 1716 | 1716 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | 1719 | fn airFence(self: *Self, inst: Air.Inst.Index) !void { |
| 1720 | 1720 | // TODO weaken this as needed, currently this implements the strongest membar form |
| 1721 | const fence = self.air.instructions.items(.data)[inst].fence; | |
| 1721 | const fence = self.air.instructions.items(.data)[@intFromEnum(inst)].fence; | |
| 1722 | 1722 | _ = fence; |
| 1723 | 1723 | |
| 1724 | 1724 | // membar #StoreStore | #LoadStore | #StoreLoad | #LoadLoad |
| ... | ... | @@ -1740,7 +1740,7 @@ fn airFence(self: *Self, inst: Air.Inst.Index) !void { |
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 1743 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1743 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1744 | 1744 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airIntFromFloat for {}", .{ |
| 1745 | 1745 | self.target.cpu.arch, |
| 1746 | 1746 | }); |
| ... | ... | @@ -1748,13 +1748,13 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | 1750 | fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 1751 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1751 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1752 | 1752 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airGetUnionTag for {}", .{self.target.cpu.arch}); |
| 1753 | 1753 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 1754 | 1754 | } |
| 1755 | 1755 | |
| 1756 | 1756 | fn airIntCast(self: *Self, inst: Air.Inst.Index) !void { |
| 1757 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1757 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1758 | 1758 | if (self.liveness.isUnused(inst)) |
| 1759 | 1759 | return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none }); |
| 1760 | 1760 | |
| ... | ... | @@ -1773,7 +1773,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void { |
| 1773 | 1773 | } |
| 1774 | 1774 | |
| 1775 | 1775 | fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 1776 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1776 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1777 | 1777 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFloatFromInt for {}", .{ |
| 1778 | 1778 | self.target.cpu.arch, |
| 1779 | 1779 | }); |
| ... | ... | @@ -1781,7 +1781,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 1781 | 1781 | } |
| 1782 | 1782 | |
| 1783 | 1783 | fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 1784 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1784 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1785 | 1785 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1786 | 1786 | const operand = try self.resolveInst(un_op); |
| 1787 | 1787 | const ty = self.typeOf(un_op); |
| ... | ... | @@ -1791,7 +1791,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 1791 | 1791 | } |
| 1792 | 1792 | |
| 1793 | 1793 | fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 1794 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1794 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1795 | 1795 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1796 | 1796 | const operand = try self.resolveInst(un_op); |
| 1797 | 1797 | const ty = self.typeOf(un_op); |
| ... | ... | @@ -1801,7 +1801,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 1801 | 1801 | } |
| 1802 | 1802 | |
| 1803 | 1803 | fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 1804 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1804 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1805 | 1805 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1806 | 1806 | const operand = try self.resolveInst(un_op); |
| 1807 | 1807 | break :result try self.isNull(operand); |
| ... | ... | @@ -1810,7 +1810,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 1810 | 1810 | } |
| 1811 | 1811 | |
| 1812 | 1812 | fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 1813 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 1813 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 1814 | 1814 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 1815 | 1815 | const operand = try self.resolveInst(un_op); |
| 1816 | 1816 | break :result try self.isNonNull(operand); |
| ... | ... | @@ -1820,7 +1820,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 1820 | 1820 | |
| 1821 | 1821 | fn airLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 1822 | 1822 | const mod = self.bin_file.options.module.?; |
| 1823 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 1823 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 1824 | 1824 | const elem_ty = self.typeOfIndex(inst); |
| 1825 | 1825 | const elem_size = elem_ty.abiSize(mod); |
| 1826 | 1826 | const result: MCValue = result: { |
| ... | ... | @@ -1851,9 +1851,9 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 1851 | 1851 | |
| 1852 | 1852 | fn airLoop(self: *Self, inst: Air.Inst.Index) !void { |
| 1853 | 1853 | // A loop is a setup to be able to jump back to the beginning. |
| 1854 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 1854 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 1855 | 1855 | const loop = self.air.extraData(Air.Block, ty_pl.payload); |
| 1856 | const body = self.air.extra[loop.end .. loop.end + loop.data.body_len]; | |
| 1856 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end .. loop.end + loop.data.body_len]); | |
| 1857 | 1857 | const start = @as(u32, @intCast(self.mir_instructions.len)); |
| 1858 | 1858 | |
| 1859 | 1859 | try self.genBody(body); |
| ... | ... | @@ -1868,7 +1868,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 1868 | 1868 | } else { |
| 1869 | 1869 | // TODO if the value is undef, don't lower this instruction |
| 1870 | 1870 | } |
| 1871 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 1871 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 1872 | 1872 | const extra = self.air.extraData(Air.Bin, pl_op.payload); |
| 1873 | 1873 | |
| 1874 | 1874 | const operand = pl_op.operand; |
| ... | ... | @@ -1882,8 +1882,8 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 1882 | 1882 | } |
| 1883 | 1883 | |
| 1884 | 1884 | fn 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; | |
| 1887 | 1887 | const lhs = try self.resolveInst(bin_op.lhs); |
| 1888 | 1888 | const rhs = try self.resolveInst(bin_op.rhs); |
| 1889 | 1889 | const lhs_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -1898,7 +1898,7 @@ fn airMinMax(self: *Self, inst: Air.Inst.Index) !void { |
| 1898 | 1898 | } |
| 1899 | 1899 | |
| 1900 | 1900 | fn airMod(self: *Self, inst: Air.Inst.Index) !void { |
| 1901 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 1901 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 1902 | 1902 | const lhs = try self.resolveInst(bin_op.lhs); |
| 1903 | 1903 | const rhs = try self.resolveInst(bin_op.rhs); |
| 1904 | 1904 | const lhs_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2036,14 +2036,14 @@ fn airMod(self: *Self, inst: Air.Inst.Index) !void { |
| 2036 | 2036 | } |
| 2037 | 2037 | |
| 2038 | 2038 | fn airMulSat(self: *Self, inst: Air.Inst.Index) !void { |
| 2039 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2039 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2040 | 2040 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement mul_sat for {}", .{self.target.cpu.arch}); |
| 2041 | 2041 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2042 | 2042 | } |
| 2043 | 2043 | |
| 2044 | 2044 | fn 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; | |
| 2047 | 2047 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2048 | 2048 | const mod = self.bin_file.options.module.?; |
| 2049 | 2049 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| ... | ... | @@ -2108,7 +2108,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 2108 | 2108 | } |
| 2109 | 2109 | |
| 2110 | 2110 | fn airNot(self: *Self, inst: Air.Inst.Index) !void { |
| 2111 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2111 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2112 | 2112 | const mod = self.bin_file.options.module.?; |
| 2113 | 2113 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2114 | 2114 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -2204,51 +2204,51 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void { |
| 2204 | 2204 | } |
| 2205 | 2205 | |
| 2206 | 2206 | fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 2207 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2207 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2208 | 2208 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload for {}", .{self.target.cpu.arch}); |
| 2209 | 2209 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2210 | 2210 | } |
| 2211 | 2211 | |
| 2212 | 2212 | fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2213 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2213 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2214 | 2214 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr for {}", .{self.target.cpu.arch}); |
| 2215 | 2215 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2216 | 2216 | } |
| 2217 | 2217 | |
| 2218 | 2218 | fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 2219 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2219 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2220 | 2220 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement .optional_payload_ptr_set for {}", .{self.target.cpu.arch}); |
| 2221 | 2221 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2222 | 2222 | } |
| 2223 | 2223 | |
| 2224 | 2224 | fn airPopcount(self: *Self, inst: Air.Inst.Index) !void { |
| 2225 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2225 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2226 | 2226 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airPopcount for {}", .{self.target.cpu.arch}); |
| 2227 | 2227 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2228 | 2228 | } |
| 2229 | 2229 | |
| 2230 | 2230 | fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void { |
| 2231 | const prefetch = self.air.instructions.items(.data)[inst].prefetch; | |
| 2231 | const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; | |
| 2232 | 2232 | // TODO Emit a PREFETCH/IPREFETCH as necessary, see A.7 and A.42 |
| 2233 | 2233 | return self.finishAir(inst, MCValue.dead, .{ prefetch.ptr, .none, .none }); |
| 2234 | 2234 | } |
| 2235 | 2235 | |
| 2236 | 2236 | fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2237 | 2237 | const is_volatile = false; // TODO |
| 2238 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2238 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2239 | 2239 | const result: MCValue = if (!is_volatile and self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_val for {}", .{self.target.cpu.arch}); |
| 2240 | 2240 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2241 | 2241 | } |
| 2242 | 2242 | |
| 2243 | 2243 | fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2244 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2244 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2245 | 2245 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2246 | 2246 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_elem_ptr for {}", .{self.target.cpu.arch}); |
| 2247 | 2247 | return self.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none }); |
| 2248 | 2248 | } |
| 2249 | 2249 | |
| 2250 | 2250 | fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2251 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2251 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2252 | 2252 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2253 | 2253 | const ptr_bits = self.target.ptrBitWidth(); |
| 2254 | 2254 | const ptr_bytes = @divExact(ptr_bits, 8); |
| ... | ... | @@ -2265,7 +2265,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2265 | 2265 | } |
| 2266 | 2266 | |
| 2267 | 2267 | fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2268 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2268 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2269 | 2269 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2270 | 2270 | const mcv = try self.resolveInst(ty_op.operand); |
| 2271 | 2271 | switch (mcv) { |
| ... | ... | @@ -2280,13 +2280,13 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2280 | 2280 | } |
| 2281 | 2281 | |
| 2282 | 2282 | fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2283 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2283 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2284 | 2284 | const result = try self.resolveInst(un_op); |
| 2285 | 2285 | return self.finishAir(inst, result, .{ un_op, .none, .none }); |
| 2286 | 2286 | } |
| 2287 | 2287 | |
| 2288 | 2288 | fn airRem(self: *Self, inst: Air.Inst.Index) !void { |
| 2289 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2289 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2290 | 2290 | const lhs = try self.resolveInst(bin_op.lhs); |
| 2291 | 2291 | const rhs = try self.resolveInst(bin_op.rhs); |
| 2292 | 2292 | const lhs_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2307,14 +2307,14 @@ fn airRem(self: *Self, inst: Air.Inst.Index) !void { |
| 2307 | 2307 | } |
| 2308 | 2308 | |
| 2309 | 2309 | fn airRet(self: *Self, inst: Air.Inst.Index) !void { |
| 2310 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2310 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2311 | 2311 | const operand = try self.resolveInst(un_op); |
| 2312 | 2312 | try self.ret(operand); |
| 2313 | 2313 | return self.finishAir(inst, .dead, .{ un_op, .none, .none }); |
| 2314 | 2314 | } |
| 2315 | 2315 | |
| 2316 | 2316 | fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 2317 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2317 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2318 | 2318 | const ptr = try self.resolveInst(un_op); |
| 2319 | 2319 | _ = ptr; |
| 2320 | 2320 | return self.fail("TODO implement airRetLoad for {}", .{self.target.cpu.arch}); |
| ... | ... | @@ -2327,19 +2327,19 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2327 | 2327 | } |
| 2328 | 2328 | |
| 2329 | 2329 | fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 2330 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2330 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2331 | 2331 | _ = bin_op; |
| 2332 | 2332 | return self.fail("TODO implement airSetUnionTag for {}", .{self.target.cpu.arch}); |
| 2333 | 2333 | } |
| 2334 | 2334 | |
| 2335 | 2335 | fn airShlSat(self: *Self, inst: Air.Inst.Index) !void { |
| 2336 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2336 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2337 | 2337 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch}); |
| 2338 | 2338 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2339 | 2339 | } |
| 2340 | 2340 | |
| 2341 | 2341 | fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 2342 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2342 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2343 | 2343 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2344 | 2344 | const mod = self.bin_file.options.module.?; |
| 2345 | 2345 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| ... | ... | @@ -2429,7 +2429,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 2429 | 2429 | } |
| 2430 | 2430 | |
| 2431 | 2431 | fn airSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 2432 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2432 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2433 | 2433 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2434 | 2434 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2435 | 2435 | const ptr = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -2448,7 +2448,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 2448 | 2448 | fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2449 | 2449 | const mod = self.bin_file.options.module.?; |
| 2450 | 2450 | 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; | |
| 2452 | 2452 | |
| 2453 | 2453 | if (!is_volatile and self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2454 | 2454 | const result: MCValue = result: { |
| ... | ... | @@ -2490,7 +2490,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2490 | 2490 | } |
| 2491 | 2491 | |
| 2492 | 2492 | fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { |
| 2493 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2493 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2494 | 2494 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2495 | 2495 | const ptr_bits = self.target.ptrBitWidth(); |
| 2496 | 2496 | const ptr_bytes = @divExact(ptr_bits, 8); |
| ... | ... | @@ -2511,7 +2511,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { |
| 2511 | 2511 | } |
| 2512 | 2512 | |
| 2513 | 2513 | fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2514 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2514 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2515 | 2515 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2516 | 2516 | const mcv = try self.resolveInst(ty_op.operand); |
| 2517 | 2517 | switch (mcv) { |
| ... | ... | @@ -2530,7 +2530,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2530 | 2530 | } |
| 2531 | 2531 | |
| 2532 | 2532 | fn airSplat(self: *Self, inst: Air.Inst.Index) !void { |
| 2533 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2533 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2534 | 2534 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSplat for {}", .{self.target.cpu.arch}); |
| 2535 | 2535 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2536 | 2536 | } |
| ... | ... | @@ -2541,7 +2541,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 2541 | 2541 | } else { |
| 2542 | 2542 | // TODO if the value is undef, don't lower this instruction |
| 2543 | 2543 | } |
| 2544 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2544 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2545 | 2545 | const ptr = try self.resolveInst(bin_op.lhs); |
| 2546 | 2546 | const value = try self.resolveInst(bin_op.rhs); |
| 2547 | 2547 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2553,20 +2553,20 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 2553 | 2553 | } |
| 2554 | 2554 | |
| 2555 | 2555 | fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2556 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2556 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2557 | 2557 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 2558 | 2558 | const result = try self.structFieldPtr(inst, extra.struct_operand, extra.field_index); |
| 2559 | 2559 | return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none }); |
| 2560 | 2560 | } |
| 2561 | 2561 | |
| 2562 | 2562 | fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void { |
| 2563 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2563 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2564 | 2564 | const result = try self.structFieldPtr(inst, ty_op.operand, index); |
| 2565 | 2565 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2566 | 2566 | } |
| 2567 | 2567 | |
| 2568 | 2568 | fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2569 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2569 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2570 | 2570 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 2571 | 2571 | const operand = extra.struct_operand; |
| 2572 | 2572 | const index = extra.field_index; |
| ... | ... | @@ -2636,7 +2636,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2636 | 2636 | } |
| 2637 | 2637 | |
| 2638 | 2638 | fn airSubSat(self: *Self, inst: Air.Inst.Index) !void { |
| 2639 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2639 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2640 | 2640 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement sub_sat for {}", .{self.target.cpu.arch}); |
| 2641 | 2641 | return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| 2642 | 2642 | } |
| ... | ... | @@ -2647,7 +2647,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 2647 | 2647 | } |
| 2648 | 2648 | |
| 2649 | 2649 | fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 2650 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2650 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2651 | 2651 | const operand = try self.resolveInst(un_op); |
| 2652 | 2652 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else { |
| 2653 | 2653 | _ = operand; |
| ... | ... | @@ -2657,7 +2657,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 2657 | 2657 | } |
| 2658 | 2658 | |
| 2659 | 2659 | fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 2660 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2660 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2661 | 2661 | const operand = try self.resolveInst(ty_op.operand); |
| 2662 | 2662 | const operand_ty = self.typeOf(ty_op.operand); |
| 2663 | 2663 | const dest_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -2670,9 +2670,9 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 2670 | 2670 | } |
| 2671 | 2671 | |
| 2672 | 2672 | fn airTry(self: *Self, inst: Air.Inst.Index) !void { |
| 2673 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 2673 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 2674 | 2674 | const extra = self.air.extraData(Air.Try, pl_op.payload); |
| 2675 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 2675 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 2676 | 2676 | const result: MCValue = result: { |
| 2677 | 2677 | const error_union_ty = self.typeOf(pl_op.operand); |
| 2678 | 2678 | const error_union = try self.resolveInst(pl_op.operand); |
| ... | ... | @@ -2688,7 +2688,7 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void { |
| 2688 | 2688 | } |
| 2689 | 2689 | |
| 2690 | 2690 | fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void { |
| 2691 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 2691 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2692 | 2692 | const result: MCValue = if (self.liveness.isUnused(inst)) |
| 2693 | 2693 | .dead |
| 2694 | 2694 | else |
| ... | ... | @@ -2697,7 +2697,7 @@ fn airUnaryMath(self: *Self, inst: Air.Inst.Index) !void { |
| 2697 | 2697 | } |
| 2698 | 2698 | |
| 2699 | 2699 | fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void { |
| 2700 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2700 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2701 | 2701 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 2702 | 2702 | _ = extra; |
| 2703 | 2703 | return self.fail("TODO implement airUnionInit for {}", .{self.target.cpu.arch}); |
| ... | ... | @@ -2705,7 +2705,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void { |
| 2705 | 2705 | |
| 2706 | 2706 | fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2707 | 2707 | const mod = self.bin_file.options.module.?; |
| 2708 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2708 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2709 | 2709 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2710 | 2710 | const error_union_ty = self.typeOf(ty_op.operand); |
| 2711 | 2711 | const payload_ty = error_union_ty.errorUnionPayload(mod); |
| ... | ... | @@ -2719,7 +2719,7 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2719 | 2719 | |
| 2720 | 2720 | fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 2721 | 2721 | const mod = self.bin_file.options.module.?; |
| 2722 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2722 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2723 | 2723 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2724 | 2724 | const error_union_ty = self.typeOf(ty_op.operand); |
| 2725 | 2725 | const payload_ty = error_union_ty.errorUnionPayload(mod); |
| ... | ... | @@ -2733,9 +2733,9 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 2733 | 2733 | /// E to E!T |
| 2734 | 2734 | fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2735 | 2735 | const mod = self.bin_file.options.module.?; |
| 2736 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2736 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2737 | 2737 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2738 | const error_union_ty = self.air.getRefType(ty_op.ty); | |
| 2738 | const error_union_ty = ty_op.ty.toType(); | |
| 2739 | 2739 | const payload_ty = error_union_ty.errorUnionPayload(mod); |
| 2740 | 2740 | const mcv = try self.resolveInst(ty_op.operand); |
| 2741 | 2741 | if (!payload_ty.hasRuntimeBits(mod)) break :result mcv; |
| ... | ... | @@ -2747,14 +2747,14 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2747 | 2747 | |
| 2748 | 2748 | /// T to E!T |
| 2749 | 2749 | fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 2750 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2750 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2751 | 2751 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement wrap errunion payload for {}", .{self.target.cpu.arch}); |
| 2752 | 2752 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2753 | 2753 | } |
| 2754 | 2754 | |
| 2755 | 2755 | fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| 2756 | 2756 | const mod = self.bin_file.options.module.?; |
| 2757 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2757 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2758 | 2758 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 2759 | 2759 | const optional_ty = self.typeOfIndex(inst); |
| 2760 | 2760 | |
| ... | ... | @@ -2772,7 +2772,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| 2772 | 2772 | fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index { |
| 2773 | 2773 | const gpa = self.gpa; |
| 2774 | 2774 | try self.mir_instructions.ensureUnusedCapacity(gpa, 1); |
| 2775 | const result_index = @as(Air.Inst.Index, @intCast(self.mir_instructions.len)); | |
| 2775 | const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len); | |
| 2776 | 2776 | self.mir_instructions.appendAssumeCapacity(inst); |
| 2777 | 2777 | return result_index; |
| 2778 | 2778 | } |
| ... | ... | @@ -3143,9 +3143,7 @@ fn binOpImmediate( |
| 3143 | 3143 | |
| 3144 | 3144 | const lhs_reg = if (lhs_is_register) lhs.register else blk: { |
| 3145 | 3145 | 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().?; | |
| 3149 | 3147 | } else null; |
| 3150 | 3148 | |
| 3151 | 3149 | const reg = try self.register_manager.allocReg(track_inst, gp); |
| ... | ... | @@ -3284,7 +3282,7 @@ fn binOpRegister( |
| 3284 | 3282 | |
| 3285 | 3283 | const lhs_reg = if (lhs_is_register) lhs.register else blk: { |
| 3286 | 3284 | const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: { |
| 3287 | break :inst Air.refToIndex(md.lhs).?; | |
| 3285 | break :inst md.lhs.toIndex().?; | |
| 3288 | 3286 | } else null; |
| 3289 | 3287 | |
| 3290 | 3288 | const reg = try self.register_manager.allocReg(track_inst, gp); |
| ... | ... | @@ -3308,7 +3306,7 @@ fn binOpRegister( |
| 3308 | 3306 | |
| 3309 | 3307 | const rhs_reg = if (rhs_is_register) rhs.register else blk: { |
| 3310 | 3308 | const track_inst: ?Air.Inst.Index = if (metadata) |md| inst: { |
| 3311 | break :inst Air.refToIndex(md.rhs).?; | |
| 3309 | break :inst md.rhs.toIndex().?; | |
| 3312 | 3310 | } else null; |
| 3313 | 3311 | |
| 3314 | 3312 | const reg = try self.register_manager.allocReg(track_inst, gp); |
| ... | ... | @@ -3566,7 +3564,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live |
| 3566 | 3564 | const dies = @as(u1, @truncate(tomb_bits)) != 0; |
| 3567 | 3565 | tomb_bits >>= 1; |
| 3568 | 3566 | if (!dies) continue; |
| 3569 | const op_index = Air.refToIndex(op) orelse continue; | |
| 3567 | const op_index = op.toIndex() orelse continue; | |
| 3570 | 3568 | self.processDeath(op_index); |
| 3571 | 3569 | } |
| 3572 | 3570 | const is_used = @as(u1, @truncate(tomb_bits)) == 0; |
| ... | ... | @@ -3594,8 +3592,8 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live |
| 3594 | 3592 | |
| 3595 | 3593 | fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void { |
| 3596 | 3594 | 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(); | |
| 3599 | 3597 | const owner_decl = mod.funcOwnerDeclIndex(self.func_index); |
| 3600 | 3598 | const name = mod.getParamName(self.func_index, arg.src_index); |
| 3601 | 3599 | |
| ... | ... | @@ -4411,8 +4409,8 @@ fn parseRegName(name: []const u8) ?Register { |
| 4411 | 4409 | fn performReloc(self: *Self, inst: Mir.Inst.Index) !void { |
| 4412 | 4410 | const tag = self.mir_instructions.items(.tag)[inst]; |
| 4413 | 4411 | 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), | |
| 4416 | 4414 | else => unreachable, |
| 4417 | 4415 | } |
| 4418 | 4416 | } |
| ... | ... | @@ -4550,7 +4548,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue { |
| 4550 | 4548 | // If the type has no codegen bits, no need to store it. |
| 4551 | 4549 | if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none; |
| 4552 | 4550 | |
| 4553 | if (Air.refToIndex(ref)) |inst| { | |
| 4551 | if (ref.toIndex()) |inst| { | |
| 4554 | 4552 | return self.getResolvedInstValue(inst); |
| 4555 | 4553 | } |
| 4556 | 4554 | |
| ... | ... | @@ -4606,7 +4604,7 @@ fn reuseOperand(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, op_ind |
| 4606 | 4604 | |
| 4607 | 4605 | // That makes us responsible for doing the rest of the stuff that processDeath would have done. |
| 4608 | 4606 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 4609 | branch.inst_table.putAssumeCapacity(Air.refToIndex(operand).?, .dead); | |
| 4607 | branch.inst_table.putAssumeCapacity(operand.toIndex().?, .dead); | |
| 4610 | 4608 | |
| 4611 | 4609 | return true; |
| 4612 | 4610 | } |
| ... | ... | @@ -4767,7 +4765,7 @@ fn trunc( |
| 4767 | 4765 | defer if (lock) |reg| self.register_manager.unlockReg(reg); |
| 4768 | 4766 | |
| 4769 | 4767 | const dest_reg = if (maybe_inst) |inst| blk: { |
| 4770 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4768 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4771 | 4769 | |
| 4772 | 4770 | if (operand == .register and self.reuseOperand(inst, ty_op.operand, 0, operand)) { |
| 4773 | 4771 | break :blk operand_reg; |
src/arch/wasm/CodeGen.zig+118-118| ... | ... | @@ -828,7 +828,7 @@ fn finishAir(func: *CodeGen, inst: Air.Inst.Index, result: WValue, operands: []c |
| 828 | 828 | if (result != .none) { |
| 829 | 829 | assert(result != .stack); // it's illegal to store a stack value as we cannot track its position |
| 830 | 830 | const branch = func.currentBranch(); |
| 831 | branch.values.putAssumeCapacityNoClobber(Air.indexToRef(inst), result); | |
| 831 | branch.values.putAssumeCapacityNoClobber(inst.toRef(), result); | |
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | if (builtin.mode == .Debug) { |
| ... | ... | @@ -864,7 +864,7 @@ const BigTomb = struct { |
| 864 | 864 | fn finishAir(bt: *BigTomb, result: WValue) void { |
| 865 | 865 | assert(result != .stack); |
| 866 | 866 | if (result != .none) { |
| 867 | bt.gen.currentBranch().values.putAssumeCapacityNoClobber(Air.indexToRef(bt.inst), result); | |
| 867 | bt.gen.currentBranch().values.putAssumeCapacityNoClobber(bt.inst.toRef(), result); | |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | if (builtin.mode == .Debug) { |
| ... | ... | @@ -883,7 +883,7 @@ fn iterateBigTomb(func: *CodeGen, inst: Air.Inst.Index, operand_count: usize) !B |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | fn processDeath(func: *CodeGen, ref: Air.Inst.Ref) void { |
| 886 | if (Air.refToIndex(ref) == null) return; | |
| 886 | if (ref.toIndex() == null) return; | |
| 887 | 887 | // Branches are currently only allowed to free locals allocated |
| 888 | 888 | // within their own branch. |
| 889 | 889 | // TODO: Upon branch consolidation free any locals if needed. |
| ... | ... | @@ -893,7 +893,7 @@ fn processDeath(func: *CodeGen, ref: Air.Inst.Ref) void { |
| 893 | 893 | if (value.local.value < reserved_indexes) { |
| 894 | 894 | return; // function arguments can never be re-used |
| 895 | 895 | } |
| 896 | log.debug("Decreasing reference for ref: %{?d}, using local '{d}'", .{ Air.refToIndex(ref), value.local.value }); | |
| 896 | log.debug("Decreasing reference for ref: %{d}, using local '{d}'", .{ @intFromEnum(ref.toIndex().?), value.local.value }); | |
| 897 | 897 | value.local.references -= 1; // if this panics, a call to `reuseOperand` was forgotten by the developer |
| 898 | 898 | if (value.local.references == 0) { |
| 899 | 899 | value.free(func); |
| ... | ... | @@ -1265,7 +1265,7 @@ fn genFunc(func: *CodeGen) InnerError!void { |
| 1265 | 1265 | // In case we have a return value, but the last instruction is a noreturn (such as a while loop) |
| 1266 | 1266 | // we emit an unreachable instruction to tell the stack validator that part will never be reached. |
| 1267 | 1267 | if (func_type.returns.len != 0 and func.air.instructions.len > 0) { |
| 1268 | const inst = @as(u32, @intCast(func.air.instructions.len - 1)); | |
| 1268 | const inst: Air.Inst.Index = @enumFromInt(func.air.instructions.len - 1); | |
| 1269 | 1269 | const last_inst_ty = func.typeOfIndex(inst); |
| 1270 | 1270 | if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(mod) or last_inst_ty.isNoReturn(mod)) { |
| 1271 | 1271 | try func.addTag(.@"unreachable"); |
| ... | ... | @@ -1828,7 +1828,7 @@ fn buildPointerOffset(func: *CodeGen, ptr_value: WValue, offset: u64, action: en |
| 1828 | 1828 | |
| 1829 | 1829 | fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 1830 | 1830 | const air_tags = func.air.instructions.items(.tag); |
| 1831 | return switch (air_tags[inst]) { | |
| 1831 | return switch (air_tags[@intFromEnum(inst)]) { | |
| 1832 | 1832 | .inferred_alloc, .inferred_alloc_comptime => unreachable, |
| 1833 | 1833 | |
| 1834 | 1834 | .add => func.airBinOp(inst, .add), |
| ... | ... | @@ -2086,7 +2086,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void { |
| 2086 | 2086 | if (builtin.mode == .Debug and func.air_bookkeeping < old_bookkeeping_value + 1) { |
| 2087 | 2087 | std.debug.panic("Missing call to `finishAir` in AIR instruction %{d} ('{}')", .{ |
| 2088 | 2088 | inst, |
| 2089 | func.air.instructions.items(.tag)[inst], | |
| 2089 | func.air.instructions.items(.tag)[@intFromEnum(inst)], | |
| 2090 | 2090 | }); |
| 2091 | 2091 | } |
| 2092 | 2092 | } |
| ... | ... | @@ -2094,7 +2094,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void { |
| 2094 | 2094 | |
| 2095 | 2095 | fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2096 | 2096 | const mod = func.bin_file.base.options.module.?; |
| 2097 | const un_op = func.air.instructions.items(.data)[inst].un_op; | |
| 2097 | const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2098 | 2098 | const operand = try func.resolveInst(un_op); |
| 2099 | 2099 | const fn_info = mod.typeToFunc(func.decl.ty).?; |
| 2100 | 2100 | const ret_ty = Type.fromInterned(fn_info.return_type); |
| ... | ... | @@ -2157,7 +2157,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2157 | 2157 | |
| 2158 | 2158 | fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2159 | 2159 | const mod = func.bin_file.base.options.module.?; |
| 2160 | const un_op = func.air.instructions.items(.data)[inst].un_op; | |
| 2160 | const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2161 | 2161 | const operand = try func.resolveInst(un_op); |
| 2162 | 2162 | const ret_ty = func.typeOf(un_op).childType(mod); |
| 2163 | 2163 | |
| ... | ... | @@ -2178,7 +2178,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2178 | 2178 | |
| 2179 | 2179 | fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) InnerError!void { |
| 2180 | 2180 | if (modifier == .always_tail) return func.fail("TODO implement tail calls for wasm", .{}); |
| 2181 | const pl_op = func.air.instructions.items(.data)[inst].pl_op; | |
| 2181 | const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 2182 | 2182 | const extra = func.air.extraData(Air.Call, pl_op.payload); |
| 2183 | 2183 | const args = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[extra.end..][0..extra.data.args_len])); |
| 2184 | 2184 | const ty = func.typeOf(pl_op.operand); |
| ... | ... | @@ -2301,7 +2301,7 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void |
| 2301 | 2301 | } else { |
| 2302 | 2302 | // TODO if the value is undef, don't lower this instruction |
| 2303 | 2303 | } |
| 2304 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 2304 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2305 | 2305 | |
| 2306 | 2306 | const lhs = try func.resolveInst(bin_op.lhs); |
| 2307 | 2307 | const rhs = try func.resolveInst(bin_op.rhs); |
| ... | ... | @@ -2457,9 +2457,9 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE |
| 2457 | 2457 | |
| 2458 | 2458 | fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2459 | 2459 | const mod = func.bin_file.base.options.module.?; |
| 2460 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 2460 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2461 | 2461 | const operand = try func.resolveInst(ty_op.operand); |
| 2462 | const ty = func.air.getRefType(ty_op.ty); | |
| 2462 | const ty = ty_op.ty.toType(); | |
| 2463 | 2463 | const ptr_ty = func.typeOf(ty_op.operand); |
| 2464 | 2464 | const ptr_info = ptr_ty.ptrInfo(mod); |
| 2465 | 2465 | |
| ... | ... | @@ -2569,7 +2569,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2569 | 2569 | |
| 2570 | 2570 | switch (func.debug_output) { |
| 2571 | 2571 | .dwarf => |dwarf| { |
| 2572 | const src_index = func.air.instructions.items(.data)[inst].arg.src_index; | |
| 2572 | const src_index = func.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index; | |
| 2573 | 2573 | const name = mod.getParamName(func.func_index, src_index); |
| 2574 | 2574 | try dwarf.genArgDbgInfo(name, arg_ty, mod.funcOwnerDeclIndex(func.func_index), .{ |
| 2575 | 2575 | .wasm_local = arg.local.value, |
| ... | ... | @@ -2583,7 +2583,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2583 | 2583 | |
| 2584 | 2584 | fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 2585 | 2585 | const mod = func.bin_file.base.options.module.?; |
| 2586 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 2586 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2587 | 2587 | const lhs = try func.resolveInst(bin_op.lhs); |
| 2588 | 2588 | const rhs = try func.resolveInst(bin_op.rhs); |
| 2589 | 2589 | const lhs_ty = func.typeOf(bin_op.lhs); |
| ... | ... | @@ -2789,7 +2789,7 @@ const FloatOp = enum { |
| 2789 | 2789 | |
| 2790 | 2790 | fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2791 | 2791 | const mod = func.bin_file.base.options.module.?; |
| 2792 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 2792 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2793 | 2793 | const operand = try func.resolveInst(ty_op.operand); |
| 2794 | 2794 | const ty = func.typeOf(ty_op.operand); |
| 2795 | 2795 | const scalar_ty = ty.scalarType(mod); |
| ... | ... | @@ -2864,7 +2864,7 @@ fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2864 | 2864 | } |
| 2865 | 2865 | |
| 2866 | 2866 | fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError!void { |
| 2867 | const un_op = func.air.instructions.items(.data)[inst].un_op; | |
| 2867 | const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 2868 | 2868 | const operand = try func.resolveInst(un_op); |
| 2869 | 2869 | const ty = func.typeOf(un_op); |
| 2870 | 2870 | |
| ... | ... | @@ -2980,7 +2980,7 @@ fn floatNeg(func: *CodeGen, ty: Type, arg: WValue) InnerError!WValue { |
| 2980 | 2980 | |
| 2981 | 2981 | fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 2982 | 2982 | const mod = func.bin_file.base.options.module.?; |
| 2983 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 2983 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2984 | 2984 | |
| 2985 | 2985 | const lhs = try func.resolveInst(bin_op.lhs); |
| 2986 | 2986 | const rhs = try func.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3473,11 +3473,11 @@ fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 { |
| 3473 | 3473 | |
| 3474 | 3474 | fn airBlock(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3475 | 3475 | 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(); | |
| 3478 | 3478 | const wasm_block_ty = genBlockType(block_ty, mod); |
| 3479 | 3479 | const extra = func.air.extraData(Air.Block, ty_pl.payload); |
| 3480 | const body = func.air.extra[extra.end..][0..extra.data.body_len]; | |
| 3480 | const body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end..][0..extra.data.body_len]); | |
| 3481 | 3481 | |
| 3482 | 3482 | // if wasm_block_ty is non-empty, we create a register to store the temporary value |
| 3483 | 3483 | const block_result: WValue = if (wasm_block_ty != wasm.block_empty) blk: { |
| ... | ... | @@ -3518,9 +3518,9 @@ fn endBlock(func: *CodeGen) !void { |
| 3518 | 3518 | } |
| 3519 | 3519 | |
| 3520 | 3520 | fn airLoop(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3521 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 3521 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3522 | 3522 | const loop = func.air.extraData(Air.Block, ty_pl.payload); |
| 3523 | const body = func.air.extra[loop.end..][0..loop.data.body_len]; | |
| 3523 | const body: []const Air.Inst.Index = @ptrCast(func.air.extra[loop.end..][0..loop.data.body_len]); | |
| 3524 | 3524 | |
| 3525 | 3525 | // result type of loop is always 'noreturn', meaning we can always |
| 3526 | 3526 | // emit the wasm type 'block_empty'. |
| ... | ... | @@ -3535,11 +3535,11 @@ fn airLoop(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3535 | 3535 | } |
| 3536 | 3536 | |
| 3537 | 3537 | fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3538 | const pl_op = func.air.instructions.items(.data)[inst].pl_op; | |
| 3538 | const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 3539 | 3539 | const condition = try func.resolveInst(pl_op.operand); |
| 3540 | 3540 | const extra = func.air.extraData(Air.CondBr, pl_op.payload); |
| 3541 | const then_body = func.air.extra[extra.end..][0..extra.data.then_body_len]; | |
| 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]); | |
| 3543 | 3543 | const liveness_condbr = func.liveness.getCondBr(inst); |
| 3544 | 3544 | |
| 3545 | 3545 | // result type is always noreturn, so use `block_empty` as type. |
| ... | ... | @@ -3579,7 +3579,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3579 | 3579 | } |
| 3580 | 3580 | |
| 3581 | 3581 | fn 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; | |
| 3583 | 3583 | |
| 3584 | 3584 | const lhs = try func.resolveInst(bin_op.lhs); |
| 3585 | 3585 | const rhs = try func.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3705,7 +3705,7 @@ fn airCmpVector(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3705 | 3705 | } |
| 3706 | 3706 | |
| 3707 | 3707 | fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3708 | const un_op = func.air.instructions.items(.data)[inst].un_op; | |
| 3708 | const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 3709 | 3709 | const operand = try func.resolveInst(un_op); |
| 3710 | 3710 | const sym_index = try func.bin_file.getGlobalSymbol("__zig_errors_len", null); |
| 3711 | 3711 | const errors_len = WValue{ .memory = sym_index }; |
| ... | ... | @@ -3721,7 +3721,7 @@ fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3721 | 3721 | |
| 3722 | 3722 | fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3723 | 3723 | const mod = func.bin_file.base.options.module.?; |
| 3724 | const br = func.air.instructions.items(.data)[inst].br; | |
| 3724 | const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 3725 | 3725 | const block = func.blocks.get(br.block_inst).?; |
| 3726 | 3726 | |
| 3727 | 3727 | // if operand has codegen bits we should break with a value |
| ... | ... | @@ -3743,7 +3743,7 @@ fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3743 | 3743 | } |
| 3744 | 3744 | |
| 3745 | 3745 | fn 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; | |
| 3747 | 3747 | |
| 3748 | 3748 | const operand = try func.resolveInst(ty_op.operand); |
| 3749 | 3749 | const operand_ty = func.typeOf(ty_op.operand); |
| ... | ... | @@ -3809,7 +3809,7 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3809 | 3809 | } |
| 3810 | 3810 | |
| 3811 | 3811 | fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3812 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 3812 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3813 | 3813 | const result = result: { |
| 3814 | 3814 | const operand = try func.resolveInst(ty_op.operand); |
| 3815 | 3815 | const wanted_ty = func.typeOfIndex(inst); |
| ... | ... | @@ -3853,7 +3853,7 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn |
| 3853 | 3853 | |
| 3854 | 3854 | fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3855 | 3855 | const mod = func.bin_file.base.options.module.?; |
| 3856 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 3856 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3857 | 3857 | const extra = func.air.extraData(Air.StructField, ty_pl.payload); |
| 3858 | 3858 | |
| 3859 | 3859 | const struct_ptr = try func.resolveInst(extra.data.struct_operand); |
| ... | ... | @@ -3865,7 +3865,7 @@ fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3865 | 3865 | |
| 3866 | 3866 | fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void { |
| 3867 | 3867 | const mod = func.bin_file.base.options.module.?; |
| 3868 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 3868 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3869 | 3869 | const struct_ptr = try func.resolveInst(ty_op.operand); |
| 3870 | 3870 | const struct_ptr_ty = func.typeOf(ty_op.operand); |
| 3871 | 3871 | const struct_ty = struct_ptr_ty.childType(mod); |
| ... | ... | @@ -3916,7 +3916,7 @@ fn structFieldPtr( |
| 3916 | 3916 | fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3917 | 3917 | const mod = func.bin_file.base.options.module.?; |
| 3918 | 3918 | const ip = &mod.intern_pool; |
| 3919 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 3919 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3920 | 3920 | const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data; |
| 3921 | 3921 | |
| 3922 | 3922 | const struct_ty = func.typeOf(struct_field.struct_operand); |
| ... | ... | @@ -4016,7 +4016,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4016 | 4016 | const mod = func.bin_file.base.options.module.?; |
| 4017 | 4017 | // result type is always 'noreturn' |
| 4018 | 4018 | const blocktype = wasm.block_empty; |
| 4019 | const pl_op = func.air.instructions.items(.data)[inst].pl_op; | |
| 4019 | const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4020 | 4020 | const target = try func.resolveInst(pl_op.operand); |
| 4021 | 4021 | const target_ty = func.typeOf(pl_op.operand); |
| 4022 | 4022 | const switch_br = func.air.extraData(Air.SwitchBr, pl_op.payload); |
| ... | ... | @@ -4040,8 +4040,8 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4040 | 4040 | var highest_maybe: ?i32 = null; |
| 4041 | 4041 | while (case_i < switch_br.data.cases_len) : (case_i += 1) { |
| 4042 | 4042 | const case = func.air.extraData(Air.SwitchBr.Case, extra_index); |
| 4043 | const items = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[case.end..][0..case.data.items_len])); | |
| 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]); | |
| 4045 | 4045 | extra_index = case.end + items.len + case_body.len; |
| 4046 | 4046 | const values = try func.gpa.alloc(CaseValue, items.len); |
| 4047 | 4047 | errdefer func.gpa.free(values); |
| ... | ... | @@ -4072,7 +4072,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4072 | 4072 | // TODO: Benchmark this to find a proper value, LLVM seems to draw the line at '40~45'. |
| 4073 | 4073 | const is_sparse = highest - lowest > 50 or target_ty.bitSize(mod) > 32; |
| 4074 | 4074 | |
| 4075 | const else_body = func.air.extra[extra_index..][0..switch_br.data.else_body_len]; | |
| 4075 | const else_body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra_index..][0..switch_br.data.else_body_len]); | |
| 4076 | 4076 | const has_else_body = else_body.len != 0; |
| 4077 | 4077 | if (has_else_body) { |
| 4078 | 4078 | try func.startBlock(.block, blocktype); |
| ... | ... | @@ -4194,7 +4194,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4194 | 4194 | |
| 4195 | 4195 | fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void { |
| 4196 | 4196 | const mod = func.bin_file.base.options.module.?; |
| 4197 | const un_op = func.air.instructions.items(.data)[inst].un_op; | |
| 4197 | const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4198 | 4198 | const operand = try func.resolveInst(un_op); |
| 4199 | 4199 | const err_union_ty = func.typeOf(un_op); |
| 4200 | 4200 | const pl_ty = err_union_ty.errorUnionPayload(mod); |
| ... | ... | @@ -4229,7 +4229,7 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro |
| 4229 | 4229 | |
| 4230 | 4230 | fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void { |
| 4231 | 4231 | const mod = func.bin_file.base.options.module.?; |
| 4232 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4232 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4233 | 4233 | |
| 4234 | 4234 | const operand = try func.resolveInst(ty_op.operand); |
| 4235 | 4235 | const op_ty = func.typeOf(ty_op.operand); |
| ... | ... | @@ -4257,7 +4257,7 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo |
| 4257 | 4257 | |
| 4258 | 4258 | fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void { |
| 4259 | 4259 | const mod = func.bin_file.base.options.module.?; |
| 4260 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4260 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4261 | 4261 | |
| 4262 | 4262 | const operand = try func.resolveInst(ty_op.operand); |
| 4263 | 4263 | const op_ty = func.typeOf(ty_op.operand); |
| ... | ... | @@ -4281,7 +4281,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) |
| 4281 | 4281 | |
| 4282 | 4282 | fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4283 | 4283 | const mod = func.bin_file.base.options.module.?; |
| 4284 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4284 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4285 | 4285 | |
| 4286 | 4286 | const operand = try func.resolveInst(ty_op.operand); |
| 4287 | 4287 | const err_ty = func.typeOfIndex(inst); |
| ... | ... | @@ -4311,10 +4311,10 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void |
| 4311 | 4311 | |
| 4312 | 4312 | fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4313 | 4313 | const mod = func.bin_file.base.options.module.?; |
| 4314 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4314 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4315 | 4315 | |
| 4316 | 4316 | const operand = try func.resolveInst(ty_op.operand); |
| 4317 | const err_ty = func.air.getRefType(ty_op.ty); | |
| 4317 | const err_ty = ty_op.ty.toType(); | |
| 4318 | 4318 | const pl_ty = err_ty.errorUnionPayload(mod); |
| 4319 | 4319 | |
| 4320 | 4320 | const result = result: { |
| ... | ... | @@ -4337,9 +4337,9 @@ fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4337 | 4337 | } |
| 4338 | 4338 | |
| 4339 | 4339 | fn 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; | |
| 4341 | 4341 | |
| 4342 | const ty = func.air.getRefType(ty_op.ty); | |
| 4342 | const ty = ty_op.ty.toType(); | |
| 4343 | 4343 | const operand = try func.resolveInst(ty_op.operand); |
| 4344 | 4344 | const operand_ty = func.typeOf(ty_op.operand); |
| 4345 | 4345 | const mod = func.bin_file.base.options.module.?; |
| ... | ... | @@ -4434,7 +4434,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro |
| 4434 | 4434 | |
| 4435 | 4435 | fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void { |
| 4436 | 4436 | const mod = func.bin_file.base.options.module.?; |
| 4437 | const un_op = func.air.instructions.items(.data)[inst].un_op; | |
| 4437 | const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4438 | 4438 | const operand = try func.resolveInst(un_op); |
| 4439 | 4439 | |
| 4440 | 4440 | const op_ty = func.typeOf(un_op); |
| ... | ... | @@ -4476,7 +4476,7 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod |
| 4476 | 4476 | |
| 4477 | 4477 | fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4478 | 4478 | const mod = func.bin_file.base.options.module.?; |
| 4479 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4479 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4480 | 4480 | const opt_ty = func.typeOf(ty_op.operand); |
| 4481 | 4481 | const payload_ty = func.typeOfIndex(inst); |
| 4482 | 4482 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| ... | ... | @@ -4499,7 +4499,7 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4499 | 4499 | |
| 4500 | 4500 | fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4501 | 4501 | const mod = func.bin_file.base.options.module.?; |
| 4502 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4502 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4503 | 4503 | const operand = try func.resolveInst(ty_op.operand); |
| 4504 | 4504 | const opt_ty = func.typeOf(ty_op.operand).childType(mod); |
| 4505 | 4505 | |
| ... | ... | @@ -4516,7 +4516,7 @@ fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4516 | 4516 | |
| 4517 | 4517 | fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4518 | 4518 | const mod = func.bin_file.base.options.module.?; |
| 4519 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4519 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4520 | 4520 | const operand = try func.resolveInst(ty_op.operand); |
| 4521 | 4521 | const opt_ty = func.typeOf(ty_op.operand).childType(mod); |
| 4522 | 4522 | const payload_ty = opt_ty.optionalChild(mod); |
| ... | ... | @@ -4541,7 +4541,7 @@ fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi |
| 4541 | 4541 | } |
| 4542 | 4542 | |
| 4543 | 4543 | fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4544 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4544 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4545 | 4545 | const payload_ty = func.typeOf(ty_op.operand); |
| 4546 | 4546 | const mod = func.bin_file.base.options.module.?; |
| 4547 | 4547 | |
| ... | ... | @@ -4578,7 +4578,7 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4578 | 4578 | } |
| 4579 | 4579 | |
| 4580 | 4580 | fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4581 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 4581 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4582 | 4582 | const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4583 | 4583 | |
| 4584 | 4584 | const lhs = try func.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4593,7 +4593,7 @@ fn airSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4593 | 4593 | } |
| 4594 | 4594 | |
| 4595 | 4595 | fn 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; | |
| 4597 | 4597 | |
| 4598 | 4598 | const operand = try func.resolveInst(ty_op.operand); |
| 4599 | 4599 | func.finishAir(inst, try func.sliceLen(operand), &.{ty_op.operand}); |
| ... | ... | @@ -4601,7 +4601,7 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4601 | 4601 | |
| 4602 | 4602 | fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4603 | 4603 | const mod = func.bin_file.base.options.module.?; |
| 4604 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 4604 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4605 | 4605 | |
| 4606 | 4606 | const slice_ty = func.typeOf(bin_op.lhs); |
| 4607 | 4607 | const slice = try func.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4631,10 +4631,10 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4631 | 4631 | |
| 4632 | 4632 | fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4633 | 4633 | const mod = func.bin_file.base.options.module.?; |
| 4634 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 4634 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4635 | 4635 | const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4636 | 4636 | |
| 4637 | const elem_ty = func.air.getRefType(ty_pl.ty).childType(mod); | |
| 4637 | const elem_ty = ty_pl.ty.toType().childType(mod); | |
| 4638 | 4638 | const elem_size = elem_ty.abiSize(mod); |
| 4639 | 4639 | |
| 4640 | 4640 | const slice = try func.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4654,7 +4654,7 @@ fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4654 | 4654 | } |
| 4655 | 4655 | |
| 4656 | 4656 | fn airSlicePtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4657 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4657 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4658 | 4658 | const operand = try func.resolveInst(ty_op.operand); |
| 4659 | 4659 | func.finishAir(inst, try func.slicePtr(operand), &.{ty_op.operand}); |
| 4660 | 4660 | } |
| ... | ... | @@ -4670,10 +4670,10 @@ fn sliceLen(func: *CodeGen, operand: WValue) InnerError!WValue { |
| 4670 | 4670 | } |
| 4671 | 4671 | |
| 4672 | 4672 | fn 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; | |
| 4674 | 4674 | |
| 4675 | 4675 | const operand = try func.resolveInst(ty_op.operand); |
| 4676 | const wanted_ty = func.air.getRefType(ty_op.ty); | |
| 4676 | const wanted_ty = ty_op.ty.toType(); | |
| 4677 | 4677 | const op_ty = func.typeOf(ty_op.operand); |
| 4678 | 4678 | |
| 4679 | 4679 | const result = try func.trunc(operand, wanted_ty, op_ty); |
| ... | ... | @@ -4699,7 +4699,7 @@ fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) Inner |
| 4699 | 4699 | } |
| 4700 | 4700 | |
| 4701 | 4701 | fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4702 | const un_op = func.air.instructions.items(.data)[inst].un_op; | |
| 4702 | const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4703 | 4703 | const operand = try func.resolveInst(un_op); |
| 4704 | 4704 | const result = func.reuseOperand(un_op, operand); |
| 4705 | 4705 | |
| ... | ... | @@ -4708,11 +4708,11 @@ fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4708 | 4708 | |
| 4709 | 4709 | fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4710 | 4710 | const mod = func.bin_file.base.options.module.?; |
| 4711 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 4711 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4712 | 4712 | |
| 4713 | 4713 | const operand = try func.resolveInst(ty_op.operand); |
| 4714 | 4714 | const array_ty = func.typeOf(ty_op.operand).childType(mod); |
| 4715 | const slice_ty = func.air.getRefType(ty_op.ty); | |
| 4715 | const slice_ty = ty_op.ty.toType(); | |
| 4716 | 4716 | |
| 4717 | 4717 | // create a slice on the stack |
| 4718 | 4718 | const slice_local = try func.allocStack(slice_ty); |
| ... | ... | @@ -4731,7 +4731,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4731 | 4731 | |
| 4732 | 4732 | fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4733 | 4733 | const mod = func.bin_file.base.options.module.?; |
| 4734 | const un_op = func.air.instructions.items(.data)[inst].un_op; | |
| 4734 | const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4735 | 4735 | const operand = try func.resolveInst(un_op); |
| 4736 | 4736 | const ptr_ty = func.typeOf(un_op); |
| 4737 | 4737 | const result = if (ptr_ty.isSlice(mod)) |
| ... | ... | @@ -4746,7 +4746,7 @@ fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4746 | 4746 | |
| 4747 | 4747 | fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4748 | 4748 | const mod = func.bin_file.base.options.module.?; |
| 4749 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 4749 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4750 | 4750 | |
| 4751 | 4751 | const ptr_ty = func.typeOf(bin_op.lhs); |
| 4752 | 4752 | const ptr = try func.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4783,11 +4783,11 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4783 | 4783 | |
| 4784 | 4784 | fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4785 | 4785 | const mod = func.bin_file.base.options.module.?; |
| 4786 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 4786 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4787 | 4787 | const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4788 | 4788 | |
| 4789 | 4789 | const ptr_ty = func.typeOf(bin_op.lhs); |
| 4790 | const elem_ty = func.air.getRefType(ty_pl.ty).childType(mod); | |
| 4790 | const elem_ty = ty_pl.ty.toType().childType(mod); | |
| 4791 | 4791 | const elem_size = elem_ty.abiSize(mod); |
| 4792 | 4792 | |
| 4793 | 4793 | const ptr = try func.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4813,7 +4813,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4813 | 4813 | |
| 4814 | 4814 | fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 4815 | 4815 | const mod = func.bin_file.base.options.module.?; |
| 4816 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 4816 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4817 | 4817 | const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4818 | 4818 | |
| 4819 | 4819 | const ptr = try func.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4846,7 +4846,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void |
| 4846 | 4846 | } else { |
| 4847 | 4847 | // TODO if the value is undef, don't lower this instruction |
| 4848 | 4848 | } |
| 4849 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 4849 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4850 | 4850 | |
| 4851 | 4851 | const ptr = try func.resolveInst(bin_op.lhs); |
| 4852 | 4852 | const ptr_ty = func.typeOf(bin_op.lhs); |
| ... | ... | @@ -4963,7 +4963,7 @@ fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue |
| 4963 | 4963 | |
| 4964 | 4964 | fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4965 | 4965 | const mod = func.bin_file.base.options.module.?; |
| 4966 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 4966 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4967 | 4967 | |
| 4968 | 4968 | const array_ty = func.typeOf(bin_op.lhs); |
| 4969 | 4969 | const array = try func.resolveInst(bin_op.lhs); |
| ... | ... | @@ -5032,7 +5032,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5032 | 5032 | |
| 5033 | 5033 | fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5034 | 5034 | const mod = func.bin_file.base.options.module.?; |
| 5035 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 5035 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5036 | 5036 | |
| 5037 | 5037 | const operand = try func.resolveInst(ty_op.operand); |
| 5038 | 5038 | const op_ty = func.typeOf(ty_op.operand); |
| ... | ... | @@ -5077,7 +5077,7 @@ fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5077 | 5077 | |
| 5078 | 5078 | fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5079 | 5079 | const mod = func.bin_file.base.options.module.?; |
| 5080 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 5080 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5081 | 5081 | |
| 5082 | 5082 | const operand = try func.resolveInst(ty_op.operand); |
| 5083 | 5083 | const op_ty = func.typeOf(ty_op.operand); |
| ... | ... | @@ -5123,7 +5123,7 @@ fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5123 | 5123 | |
| 5124 | 5124 | fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5125 | 5125 | const mod = func.bin_file.base.options.module.?; |
| 5126 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 5126 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5127 | 5127 | const operand = try func.resolveInst(ty_op.operand); |
| 5128 | 5128 | const ty = func.typeOfIndex(inst); |
| 5129 | 5129 | const elem_ty = ty.childType(mod); |
| ... | ... | @@ -5193,7 +5193,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5193 | 5193 | } |
| 5194 | 5194 | |
| 5195 | 5195 | fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5196 | const pl_op = func.air.instructions.items(.data)[inst].pl_op; | |
| 5196 | const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 5197 | 5197 | const operand = try func.resolveInst(pl_op.operand); |
| 5198 | 5198 | |
| 5199 | 5199 | _ = operand; |
| ... | ... | @@ -5203,7 +5203,7 @@ fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5203 | 5203 | fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5204 | 5204 | const mod = func.bin_file.base.options.module.?; |
| 5205 | 5205 | const inst_ty = func.typeOfIndex(inst); |
| 5206 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 5206 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5207 | 5207 | const extra = func.air.extraData(Air.Shuffle, ty_pl.payload).data; |
| 5208 | 5208 | |
| 5209 | 5209 | const a = try func.resolveInst(extra.a); |
| ... | ... | @@ -5262,7 +5262,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5262 | 5262 | } |
| 5263 | 5263 | |
| 5264 | 5264 | fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5265 | const reduce = func.air.instructions.items(.data)[inst].reduce; | |
| 5265 | const reduce = func.air.instructions.items(.data)[@intFromEnum(inst)].reduce; | |
| 5266 | 5266 | const operand = try func.resolveInst(reduce.operand); |
| 5267 | 5267 | |
| 5268 | 5268 | _ = operand; |
| ... | ... | @@ -5272,7 +5272,7 @@ fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5272 | 5272 | fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5273 | 5273 | const mod = func.bin_file.base.options.module.?; |
| 5274 | 5274 | const ip = &mod.intern_pool; |
| 5275 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 5275 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5276 | 5276 | const result_ty = func.typeOfIndex(inst); |
| 5277 | 5277 | const len = @as(usize, @intCast(result_ty.arrayLen(mod))); |
| 5278 | 5278 | const elements = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[ty_pl.payload..][0..len])); |
| ... | ... | @@ -5402,7 +5402,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5402 | 5402 | fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5403 | 5403 | const mod = func.bin_file.base.options.module.?; |
| 5404 | 5404 | const ip = &mod.intern_pool; |
| 5405 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 5405 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5406 | 5406 | const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 5407 | 5407 | |
| 5408 | 5408 | const result = result: { |
| ... | ... | @@ -5474,12 +5474,12 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5474 | 5474 | } |
| 5475 | 5475 | |
| 5476 | 5476 | fn airPrefetch(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5477 | const prefetch = func.air.instructions.items(.data)[inst].prefetch; | |
| 5477 | const prefetch = func.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; | |
| 5478 | 5478 | func.finishAir(inst, .none, &.{prefetch.ptr}); |
| 5479 | 5479 | } |
| 5480 | 5480 | |
| 5481 | 5481 | fn 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; | |
| 5483 | 5483 | |
| 5484 | 5484 | const result = try func.allocLocal(func.typeOfIndex(inst)); |
| 5485 | 5485 | try func.addLabel(.memory_size, pl_op.payload); |
| ... | ... | @@ -5488,7 +5488,7 @@ fn airWasmMemorySize(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5488 | 5488 | } |
| 5489 | 5489 | |
| 5490 | 5490 | fn 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; | |
| 5492 | 5492 | |
| 5493 | 5493 | const operand = try func.resolveInst(pl_op.operand); |
| 5494 | 5494 | const result = try func.allocLocal(func.typeOfIndex(inst)); |
| ... | ... | @@ -5578,7 +5578,7 @@ fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std |
| 5578 | 5578 | |
| 5579 | 5579 | fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5580 | 5580 | const mod = func.bin_file.base.options.module.?; |
| 5581 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 5581 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 5582 | 5582 | const un_ty = func.typeOf(bin_op.lhs).childType(mod); |
| 5583 | 5583 | const tag_ty = func.typeOf(bin_op.rhs); |
| 5584 | 5584 | const layout = un_ty.unionGetLayout(mod); |
| ... | ... | @@ -5602,7 +5602,7 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5602 | 5602 | |
| 5603 | 5603 | fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5604 | 5604 | const mod = func.bin_file.base.options.module.?; |
| 5605 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 5605 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5606 | 5606 | |
| 5607 | 5607 | const un_ty = func.typeOf(ty_op.operand); |
| 5608 | 5608 | const tag_ty = func.typeOfIndex(inst); |
| ... | ... | @@ -5621,7 +5621,7 @@ fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5621 | 5621 | } |
| 5622 | 5622 | |
| 5623 | 5623 | fn 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; | |
| 5625 | 5625 | |
| 5626 | 5626 | const dest_ty = func.typeOfIndex(inst); |
| 5627 | 5627 | const operand = try func.resolveInst(ty_op.operand); |
| ... | ... | @@ -5666,7 +5666,7 @@ fn fpext(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError! |
| 5666 | 5666 | } |
| 5667 | 5667 | |
| 5668 | 5668 | fn 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; | |
| 5670 | 5670 | |
| 5671 | 5671 | const dest_ty = func.typeOfIndex(inst); |
| 5672 | 5672 | const operand = try func.resolveInst(ty_op.operand); |
| ... | ... | @@ -5707,7 +5707,7 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro |
| 5707 | 5707 | |
| 5708 | 5708 | fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5709 | 5709 | const mod = func.bin_file.base.options.module.?; |
| 5710 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 5710 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5711 | 5711 | |
| 5712 | 5712 | const err_set_ty = func.typeOf(ty_op.operand).childType(mod); |
| 5713 | 5713 | const payload_ty = err_set_ty.errorUnionPayload(mod); |
| ... | ... | @@ -5733,11 +5733,11 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi |
| 5733 | 5733 | |
| 5734 | 5734 | fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5735 | 5735 | const mod = func.bin_file.base.options.module.?; |
| 5736 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 5736 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5737 | 5737 | const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 5738 | 5738 | |
| 5739 | 5739 | const field_ptr = try func.resolveInst(extra.field_ptr); |
| 5740 | const parent_ty = func.air.getRefType(ty_pl.ty).childType(mod); | |
| 5740 | const parent_ty = ty_pl.ty.toType().childType(mod); | |
| 5741 | 5741 | const field_offset = parent_ty.structFieldOffset(extra.field_index, mod); |
| 5742 | 5742 | |
| 5743 | 5743 | const result = if (field_offset != 0) result: { |
| ... | ... | @@ -5763,7 +5763,7 @@ fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue |
| 5763 | 5763 | |
| 5764 | 5764 | fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5765 | 5765 | const mod = func.bin_file.base.options.module.?; |
| 5766 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 5766 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 5767 | 5767 | const dst = try func.resolveInst(bin_op.lhs); |
| 5768 | 5768 | const dst_ty = func.typeOf(bin_op.lhs); |
| 5769 | 5769 | const ptr_elem_ty = dst_ty.childType(mod); |
| ... | ... | @@ -5803,7 +5803,7 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5803 | 5803 | |
| 5804 | 5804 | fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5805 | 5805 | const mod = func.bin_file.base.options.module.?; |
| 5806 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 5806 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5807 | 5807 | |
| 5808 | 5808 | const operand = try func.resolveInst(ty_op.operand); |
| 5809 | 5809 | const op_ty = func.typeOf(ty_op.operand); |
| ... | ... | @@ -5847,7 +5847,7 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5847 | 5847 | } |
| 5848 | 5848 | |
| 5849 | 5849 | fn 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; | |
| 5851 | 5851 | |
| 5852 | 5852 | const operand = try func.resolveInst(un_op); |
| 5853 | 5853 | // First retrieve the symbol index to the error name table |
| ... | ... | @@ -5889,7 +5889,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5889 | 5889 | } |
| 5890 | 5890 | |
| 5891 | 5891 | fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerError!void { |
| 5892 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 5892 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5893 | 5893 | const slice_ptr = try func.resolveInst(ty_op.operand); |
| 5894 | 5894 | const result = try func.buildPointerOffset(slice_ptr, offset, .new); |
| 5895 | 5895 | func.finishAir(inst, result, &.{ty_op.operand}); |
| ... | ... | @@ -5897,7 +5897,7 @@ fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerE |
| 5897 | 5897 | |
| 5898 | 5898 | fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 5899 | 5899 | assert(op == .add or op == .sub); |
| 5900 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 5900 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5901 | 5901 | const extra = func.air.extraData(Air.Bin, ty_pl.payload).data; |
| 5902 | 5902 | |
| 5903 | 5903 | const lhs_op = try func.resolveInst(extra.lhs); |
| ... | ... | @@ -6041,7 +6041,7 @@ fn addSubWithOverflowBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, |
| 6041 | 6041 | |
| 6042 | 6042 | fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6043 | 6043 | const mod = func.bin_file.base.options.module.?; |
| 6044 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 6044 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6045 | 6045 | const extra = func.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6046 | 6046 | |
| 6047 | 6047 | const lhs = try func.resolveInst(extra.lhs); |
| ... | ... | @@ -6097,7 +6097,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6097 | 6097 | } |
| 6098 | 6098 | |
| 6099 | 6099 | fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6100 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 6100 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6101 | 6101 | const extra = func.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6102 | 6102 | |
| 6103 | 6103 | const lhs = try func.resolveInst(extra.lhs); |
| ... | ... | @@ -6275,7 +6275,7 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 6275 | 6275 | assert(op == .max or op == .min); |
| 6276 | 6276 | const mod = func.bin_file.base.options.module.?; |
| 6277 | 6277 | const target = mod.getTarget(); |
| 6278 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 6278 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6279 | 6279 | |
| 6280 | 6280 | const ty = func.typeOfIndex(inst); |
| 6281 | 6281 | if (ty.zigTypeTag(mod) == .Vector) { |
| ... | ... | @@ -6318,7 +6318,7 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 6318 | 6318 | |
| 6319 | 6319 | fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6320 | 6320 | const mod = func.bin_file.base.options.module.?; |
| 6321 | const pl_op = func.air.instructions.items(.data)[inst].pl_op; | |
| 6321 | const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6322 | 6322 | const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data; |
| 6323 | 6323 | |
| 6324 | 6324 | const ty = func.typeOfIndex(inst); |
| ... | ... | @@ -6352,7 +6352,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6352 | 6352 | |
| 6353 | 6353 | fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6354 | 6354 | const mod = func.bin_file.base.options.module.?; |
| 6355 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 6355 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6356 | 6356 | |
| 6357 | 6357 | const ty = func.typeOf(ty_op.operand); |
| 6358 | 6358 | const result_ty = func.typeOfIndex(inst); |
| ... | ... | @@ -6405,7 +6405,7 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6405 | 6405 | |
| 6406 | 6406 | fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6407 | 6407 | const mod = func.bin_file.base.options.module.?; |
| 6408 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 6408 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6409 | 6409 | |
| 6410 | 6410 | const ty = func.typeOf(ty_op.operand); |
| 6411 | 6411 | const result_ty = func.typeOfIndex(inst); |
| ... | ... | @@ -6472,7 +6472,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void { |
| 6472 | 6472 | if (func.debug_output != .dwarf) return func.finishAir(inst, .none, &.{}); |
| 6473 | 6473 | |
| 6474 | 6474 | const mod = func.bin_file.base.options.module.?; |
| 6475 | const pl_op = func.air.instructions.items(.data)[inst].pl_op; | |
| 6475 | const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6476 | 6476 | const ty = func.typeOf(pl_op.operand); |
| 6477 | 6477 | const operand = try func.resolveInst(pl_op.operand); |
| 6478 | 6478 | |
| ... | ... | @@ -6496,7 +6496,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void { |
| 6496 | 6496 | fn airDbgStmt(func: *CodeGen, inst: Air.Inst.Index) !void { |
| 6497 | 6497 | if (func.debug_output != .dwarf) return func.finishAir(inst, .none, &.{}); |
| 6498 | 6498 | |
| 6499 | const dbg_stmt = func.air.instructions.items(.data)[inst].dbg_stmt; | |
| 6499 | const dbg_stmt = func.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; | |
| 6500 | 6500 | try func.addInst(.{ .tag = .dbg_line, .data = .{ |
| 6501 | 6501 | .payload = try func.addExtra(Mir.DbgLineColumn{ |
| 6502 | 6502 | .line = dbg_stmt.line, |
| ... | ... | @@ -6507,10 +6507,10 @@ fn airDbgStmt(func: *CodeGen, inst: Air.Inst.Index) !void { |
| 6507 | 6507 | } |
| 6508 | 6508 | |
| 6509 | 6509 | fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6510 | const pl_op = func.air.instructions.items(.data)[inst].pl_op; | |
| 6510 | const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6511 | 6511 | const err_union = try func.resolveInst(pl_op.operand); |
| 6512 | 6512 | const extra = func.air.extraData(Air.Try, pl_op.payload); |
| 6513 | const body = func.air.extra[extra.end..][0..extra.data.body_len]; | |
| 6513 | const body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end..][0..extra.data.body_len]); | |
| 6514 | 6514 | const err_union_ty = func.typeOf(pl_op.operand); |
| 6515 | 6515 | const result = try lowerTry(func, inst, err_union, body, err_union_ty, false); |
| 6516 | 6516 | func.finishAir(inst, result, &.{pl_op.operand}); |
| ... | ... | @@ -6518,10 +6518,10 @@ fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6518 | 6518 | |
| 6519 | 6519 | fn airTryPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6520 | 6520 | const mod = func.bin_file.base.options.module.?; |
| 6521 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 6521 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6522 | 6522 | const extra = func.air.extraData(Air.TryPtr, ty_pl.payload); |
| 6523 | 6523 | const err_union_ptr = try func.resolveInst(extra.data.ptr); |
| 6524 | const body = func.air.extra[extra.end..][0..extra.data.body_len]; | |
| 6524 | const body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end..][0..extra.data.body_len]); | |
| 6525 | 6525 | const err_union_ty = func.typeOf(extra.data.ptr).childType(mod); |
| 6526 | 6526 | const result = try lowerTry(func, inst, err_union_ptr, body, err_union_ty, true); |
| 6527 | 6527 | func.finishAir(inst, result, &.{extra.data.ptr}); |
| ... | ... | @@ -6585,7 +6585,7 @@ fn lowerTry( |
| 6585 | 6585 | |
| 6586 | 6586 | fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6587 | 6587 | const mod = func.bin_file.base.options.module.?; |
| 6588 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 6588 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6589 | 6589 | |
| 6590 | 6590 | const ty = func.typeOfIndex(inst); |
| 6591 | 6591 | const operand = try func.resolveInst(ty_op.operand); |
| ... | ... | @@ -6656,7 +6656,7 @@ fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6656 | 6656 | |
| 6657 | 6657 | fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6658 | 6658 | const mod = func.bin_file.base.options.module.?; |
| 6659 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 6659 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6660 | 6660 | |
| 6661 | 6661 | const ty = func.typeOfIndex(inst); |
| 6662 | 6662 | const lhs = try func.resolveInst(bin_op.lhs); |
| ... | ... | @@ -6671,7 +6671,7 @@ fn airDiv(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6671 | 6671 | |
| 6672 | 6672 | fn airDivTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6673 | 6673 | const mod = func.bin_file.base.options.module.?; |
| 6674 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 6674 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6675 | 6675 | |
| 6676 | 6676 | const ty = func.typeOfIndex(inst); |
| 6677 | 6677 | const lhs = try func.resolveInst(bin_op.lhs); |
| ... | ... | @@ -6691,7 +6691,7 @@ fn airDivTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6691 | 6691 | } |
| 6692 | 6692 | |
| 6693 | 6693 | fn 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; | |
| 6695 | 6695 | |
| 6696 | 6696 | const mod = func.bin_file.base.options.module.?; |
| 6697 | 6697 | const ty = func.typeOfIndex(inst); |
| ... | ... | @@ -6834,7 +6834,7 @@ fn divSigned(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type) InnerError!WVal |
| 6834 | 6834 | /// Remainder after floor division, defined by: |
| 6835 | 6835 | /// @divFloor(a, b) * b + @mod(a, b) = a |
| 6836 | 6836 | fn 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; | |
| 6838 | 6838 | |
| 6839 | 6839 | const mod = func.bin_file.base.options.module.?; |
| 6840 | 6840 | const ty = func.typeOfIndex(inst); |
| ... | ... | @@ -6917,7 +6917,7 @@ fn signExtendInt(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue { |
| 6917 | 6917 | |
| 6918 | 6918 | fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 6919 | 6919 | assert(op == .add or op == .sub); |
| 6920 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 6920 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6921 | 6921 | |
| 6922 | 6922 | const mod = func.bin_file.base.options.module.?; |
| 6923 | 6923 | const ty = func.typeOfIndex(inst); |
| ... | ... | @@ -7032,7 +7032,7 @@ fn signedSat(func: *CodeGen, lhs_operand: WValue, rhs_operand: WValue, ty: Type, |
| 7032 | 7032 | } |
| 7033 | 7033 | |
| 7034 | 7034 | fn 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; | |
| 7036 | 7036 | |
| 7037 | 7037 | const mod = func.bin_file.base.options.module.?; |
| 7038 | 7038 | const ty = func.typeOfIndex(inst); |
| ... | ... | @@ -7193,7 +7193,7 @@ fn callIntrinsic( |
| 7193 | 7193 | } |
| 7194 | 7194 | |
| 7195 | 7195 | fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7196 | const un_op = func.air.instructions.items(.data)[inst].un_op; | |
| 7196 | const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 7197 | 7197 | const operand = try func.resolveInst(un_op); |
| 7198 | 7198 | const enum_ty = func.typeOf(un_op); |
| 7199 | 7199 | |
| ... | ... | @@ -7365,10 +7365,10 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7365 | 7365 | |
| 7366 | 7366 | fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7367 | 7367 | const mod = func.bin_file.base.options.module.?; |
| 7368 | const ty_op = func.air.instructions.items(.data)[inst].ty_op; | |
| 7368 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7369 | 7369 | |
| 7370 | 7370 | const operand = try func.resolveInst(ty_op.operand); |
| 7371 | const error_set_ty = func.air.getRefType(ty_op.ty); | |
| 7371 | const error_set_ty = ty_op.ty.toType(); | |
| 7372 | 7372 | const result = try func.allocLocal(Type.bool); |
| 7373 | 7373 | |
| 7374 | 7374 | const names = error_set_ty.errorSetNames(mod); |
| ... | ... | @@ -7450,7 +7450,7 @@ inline fn useAtomicFeature(func: *const CodeGen) bool { |
| 7450 | 7450 | |
| 7451 | 7451 | fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7452 | 7452 | const mod = func.bin_file.base.options.module.?; |
| 7453 | const ty_pl = func.air.instructions.items(.data)[inst].ty_pl; | |
| 7453 | const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 7454 | 7454 | const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 7455 | 7455 | |
| 7456 | 7456 | const ptr_ty = func.typeOf(extra.ptr); |
| ... | ... | @@ -7523,7 +7523,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7523 | 7523 | |
| 7524 | 7524 | fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7525 | 7525 | const mod = func.bin_file.base.options.module.?; |
| 7526 | const atomic_load = func.air.instructions.items(.data)[inst].atomic_load; | |
| 7526 | const atomic_load = func.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; | |
| 7527 | 7527 | const ptr = try func.resolveInst(atomic_load.ptr); |
| 7528 | 7528 | const ty = func.typeOfIndex(inst); |
| 7529 | 7529 | |
| ... | ... | @@ -7550,7 +7550,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7550 | 7550 | |
| 7551 | 7551 | fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7552 | 7552 | const mod = func.bin_file.base.options.module.?; |
| 7553 | const pl_op = func.air.instructions.items(.data)[inst].pl_op; | |
| 7553 | const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 7554 | 7554 | const extra = func.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 7555 | 7555 | |
| 7556 | 7556 | const ptr = try func.resolveInst(pl_op.operand); |
| ... | ... | @@ -7736,7 +7736,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7736 | 7736 | |
| 7737 | 7737 | fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7738 | 7738 | const mod = func.bin_file.base.options.module.?; |
| 7739 | const bin_op = func.air.instructions.items(.data)[inst].bin_op; | |
| 7739 | const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7740 | 7740 | |
| 7741 | 7741 | const ptr = try func.resolveInst(bin_op.lhs); |
| 7742 | 7742 | const operand = try func.resolveInst(bin_op.rhs); |
src/arch/x86_64/CodeGen.zig+145-141| ... | ... | @@ -1901,7 +1901,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 1901 | 1901 | |
| 1902 | 1902 | const old_air_bookkeeping = self.air_bookkeeping; |
| 1903 | 1903 | try self.inst_tracking.ensureUnusedCapacity(self.gpa, 1); |
| 1904 | switch (air_tags[inst]) { | |
| 1904 | switch (air_tags[@intFromEnum(inst)]) { | |
| 1905 | 1905 | // zig fmt: off |
| 1906 | 1906 | .not, |
| 1907 | 1907 | => |tag| try self.airUnOp(inst, tag), |
| ... | ... | @@ -2148,7 +2148,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 2148 | 2148 | |
| 2149 | 2149 | if (std.debug.runtime_safety) { |
| 2150 | 2150 | if (self.air_bookkeeping < old_air_bookkeeping + 1) { |
| 2151 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[inst] }); | |
| 2151 | std.debug.panic("in codegen.zig, handling of AIR instruction %{d} ('{}') did not do proper bookkeeping. Look for a missing call to finishAir.", .{ inst, air_tags[@intFromEnum(inst)] }); | |
| 2152 | 2152 | } |
| 2153 | 2153 | |
| 2154 | 2154 | { // check consistency of tracked registers |
| ... | ... | @@ -2251,7 +2251,7 @@ fn freeValue(self: *Self, value: MCValue) !void { |
| 2251 | 2251 | } |
| 2252 | 2252 | |
| 2253 | 2253 | fn feed(self: *Self, bt: *Liveness.BigTomb, operand: Air.Inst.Ref) !void { |
| 2254 | if (bt.feed()) if (Air.refToIndex(operand)) |inst| try self.processDeath(inst); | |
| 2254 | if (bt.feed()) if (operand.toIndex()) |inst| try self.processDeath(inst); | |
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | 2257 | /// Asserts there is already capacity to insert into top branch inst_table. |
| ... | ... | @@ -2292,7 +2292,7 @@ fn finishAir( |
| 2292 | 2292 | const dies = @as(u1, @truncate(tomb_bits)) != 0; |
| 2293 | 2293 | tomb_bits >>= 1; |
| 2294 | 2294 | if (!dies) continue; |
| 2295 | try self.processDeath(Air.refToIndexAllowNone(op) orelse continue); | |
| 2295 | try self.processDeath(op.toIndexAllowNone() orelse continue); | |
| 2296 | 2296 | } |
| 2297 | 2297 | self.finishAirResult(inst, result); |
| 2298 | 2298 | } |
| ... | ... | @@ -2683,7 +2683,7 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 2683 | 2683 | } |
| 2684 | 2684 | |
| 2685 | 2685 | fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 2686 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2686 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2687 | 2687 | const dst_ty = self.typeOfIndex(inst); |
| 2688 | 2688 | const dst_bits = dst_ty.floatBits(self.target.*); |
| 2689 | 2689 | const src_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -2782,7 +2782,7 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 2782 | 2782 | } |
| 2783 | 2783 | |
| 2784 | 2784 | fn airFpext(self: *Self, inst: Air.Inst.Index) !void { |
| 2785 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2785 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2786 | 2786 | const dst_ty = self.typeOfIndex(inst); |
| 2787 | 2787 | const dst_bits = dst_ty.floatBits(self.target.*); |
| 2788 | 2788 | const src_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -2882,7 +2882,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void { |
| 2882 | 2882 | |
| 2883 | 2883 | fn airIntCast(self: *Self, inst: Air.Inst.Index) !void { |
| 2884 | 2884 | const mod = self.bin_file.options.module.?; |
| 2885 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2885 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2886 | 2886 | const result: MCValue = result: { |
| 2887 | 2887 | const src_ty = self.typeOf(ty_op.operand); |
| 2888 | 2888 | const src_int_info = src_ty.intInfo(mod); |
| ... | ... | @@ -2973,7 +2973,7 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void { |
| 2973 | 2973 | |
| 2974 | 2974 | fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 2975 | 2975 | const mod = self.bin_file.options.module.?; |
| 2976 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 2976 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 2977 | 2977 | |
| 2978 | 2978 | const dst_ty = self.typeOfIndex(inst); |
| 2979 | 2979 | const dst_abi_size: u32 = @intCast(dst_ty.abiSize(mod)); |
| ... | ... | @@ -3086,7 +3086,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 3086 | 3086 | } |
| 3087 | 3087 | |
| 3088 | 3088 | fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void { |
| 3089 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 3089 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 3090 | 3090 | const ty = self.typeOfIndex(inst); |
| 3091 | 3091 | |
| 3092 | 3092 | const operand = try self.resolveInst(un_op); |
| ... | ... | @@ -3100,7 +3100,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void { |
| 3100 | 3100 | |
| 3101 | 3101 | fn airSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 3102 | 3102 | const mod = self.bin_file.options.module.?; |
| 3103 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3103 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3104 | 3104 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3105 | 3105 | |
| 3106 | 3106 | const slice_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -3123,14 +3123,14 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 3123 | 3123 | } |
| 3124 | 3124 | |
| 3125 | 3125 | fn airUnOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 3126 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3126 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3127 | 3127 | const dst_mcv = try self.genUnOp(inst, tag, ty_op.operand); |
| 3128 | 3128 | return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none }); |
| 3129 | 3129 | } |
| 3130 | 3130 | |
| 3131 | 3131 | fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 3132 | 3132 | const mod = self.bin_file.options.module.?; |
| 3133 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3133 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3134 | 3134 | const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs); |
| 3135 | 3135 | |
| 3136 | 3136 | const dst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -3163,7 +3163,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 3163 | 3163 | } |
| 3164 | 3164 | |
| 3165 | 3165 | fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 3166 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3166 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3167 | 3167 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3168 | 3168 | const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs); |
| 3169 | 3169 | return self.finishAir(inst, dst_mcv, .{ bin_op.lhs, bin_op.rhs, .none }); |
| ... | ... | @@ -3176,10 +3176,10 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 { |
| 3176 | 3176 | |
| 3177 | 3177 | const dst_ty = self.typeOf(dst_air); |
| 3178 | 3178 | 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)]) { | |
| 3181 | 3181 | .intcast => { |
| 3182 | const src_ty = self.typeOf(air_data[inst].ty_op.operand); | |
| 3182 | const src_ty = self.typeOf(air_data[@intFromEnum(inst)].ty_op.operand); | |
| 3183 | 3183 | const src_info = src_ty.intInfo(mod); |
| 3184 | 3184 | return @min(switch (src_info.signedness) { |
| 3185 | 3185 | .signed => switch (dst_info.signedness) { |
| ... | ... | @@ -3194,7 +3194,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 { |
| 3194 | 3194 | }, |
| 3195 | 3195 | else => {}, |
| 3196 | 3196 | } |
| 3197 | } else if (Air.refToInterned(dst_air)) |ip_index| { | |
| 3197 | } else if (dst_air.toInterned()) |ip_index| { | |
| 3198 | 3198 | var space: Value.BigIntSpace = undefined; |
| 3199 | 3199 | const src_int = Value.fromInterned(ip_index).toBigInt(&space, mod); |
| 3200 | 3200 | return @as(u16, @intCast(src_int.bitCountTwosComp())) + |
| ... | ... | @@ -3205,9 +3205,9 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 { |
| 3205 | 3205 | |
| 3206 | 3206 | fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void { |
| 3207 | 3207 | const mod = self.bin_file.options.module.?; |
| 3208 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3208 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3209 | 3209 | const result = result: { |
| 3210 | const tag = self.air.instructions.items(.tag)[inst]; | |
| 3210 | const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)]; | |
| 3211 | 3211 | const dst_ty = self.typeOfIndex(inst); |
| 3212 | 3212 | switch (dst_ty.zigTypeTag(mod)) { |
| 3213 | 3213 | .Float, .Vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs), |
| ... | ... | @@ -3431,7 +3431,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void { |
| 3431 | 3431 | |
| 3432 | 3432 | fn airAddSat(self: *Self, inst: Air.Inst.Index) !void { |
| 3433 | 3433 | const mod = self.bin_file.options.module.?; |
| 3434 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3434 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3435 | 3435 | const ty = self.typeOf(bin_op.lhs); |
| 3436 | 3436 | if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail( |
| 3437 | 3437 | "TODO implement airAddSat for {}", |
| ... | ... | @@ -3514,7 +3514,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void { |
| 3514 | 3514 | |
| 3515 | 3515 | fn airSubSat(self: *Self, inst: Air.Inst.Index) !void { |
| 3516 | 3516 | const mod = self.bin_file.options.module.?; |
| 3517 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3517 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3518 | 3518 | const ty = self.typeOf(bin_op.lhs); |
| 3519 | 3519 | if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail( |
| 3520 | 3520 | "TODO implement airSubSat for {}", |
| ... | ... | @@ -3590,7 +3590,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void { |
| 3590 | 3590 | |
| 3591 | 3591 | fn airMulSat(self: *Self, inst: Air.Inst.Index) !void { |
| 3592 | 3592 | const mod = self.bin_file.options.module.?; |
| 3593 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3593 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3594 | 3594 | const ty = self.typeOf(bin_op.lhs); |
| 3595 | 3595 | |
| 3596 | 3596 | const result = result: { |
| ... | ... | @@ -3730,10 +3730,10 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void { |
| 3730 | 3730 | |
| 3731 | 3731 | fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 3732 | 3732 | const mod = self.bin_file.options.module.?; |
| 3733 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3733 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3734 | 3734 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3735 | 3735 | const result: MCValue = result: { |
| 3736 | const tag = self.air.instructions.items(.tag)[inst]; | |
| 3736 | const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)]; | |
| 3737 | 3737 | const ty = self.typeOf(bin_op.lhs); |
| 3738 | 3738 | switch (ty.zigTypeTag(mod)) { |
| 3739 | 3739 | .Vector => return self.fail("TODO implement add/sub with overflow for Vector type", .{}), |
| ... | ... | @@ -3791,7 +3791,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 3791 | 3791 | |
| 3792 | 3792 | fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 3793 | 3793 | const mod = self.bin_file.options.module.?; |
| 3794 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3794 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3795 | 3795 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3796 | 3796 | const result: MCValue = result: { |
| 3797 | 3797 | const lhs_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -3934,7 +3934,7 @@ fn genSetFrameTruncatedOverflowCompare( |
| 3934 | 3934 | |
| 3935 | 3935 | fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void { |
| 3936 | 3936 | const mod = self.bin_file.options.module.?; |
| 3937 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3937 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3938 | 3938 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3939 | 3939 | const tuple_ty = self.typeOfIndex(inst); |
| 3940 | 3940 | const dst_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -4270,10 +4270,10 @@ fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCVa |
| 4270 | 4270 | |
| 4271 | 4271 | fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void { |
| 4272 | 4272 | const mod = self.bin_file.options.module.?; |
| 4273 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 4273 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4274 | 4274 | |
| 4275 | 4275 | const air_tags = self.air.instructions.items(.tag); |
| 4276 | const tag = air_tags[inst]; | |
| 4276 | const tag = air_tags[@intFromEnum(inst)]; | |
| 4277 | 4277 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 4278 | 4278 | const rhs_ty = self.typeOf(bin_op.rhs); |
| 4279 | 4279 | const result: MCValue = result: { |
| ... | ... | @@ -4449,7 +4449,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void { |
| 4449 | 4449 | }, |
| 4450 | 4450 | else => {}, |
| 4451 | 4451 | } |
| 4452 | } else if (Air.refToIndex(bin_op.rhs)) |rhs_inst| switch (air_tags[rhs_inst]) { | |
| 4452 | } else if (bin_op.rhs.toIndex()) |rhs_inst| switch (air_tags[@intFromEnum(rhs_inst)]) { | |
| 4453 | 4453 | .splat => { |
| 4454 | 4454 | const abi_size: u32 = @intCast(lhs_ty.abiSize(mod)); |
| 4455 | 4455 | |
| ... | ... | @@ -4537,7 +4537,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void { |
| 4537 | 4537 | } |
| 4538 | 4538 | |
| 4539 | 4539 | fn airShlSat(self: *Self, inst: Air.Inst.Index) !void { |
| 4540 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 4540 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4541 | 4541 | _ = bin_op; |
| 4542 | 4542 | return self.fail("TODO implement shl_sat for {}", .{self.target.cpu.arch}); |
| 4543 | 4543 | //return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); |
| ... | ... | @@ -4545,7 +4545,7 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) !void { |
| 4545 | 4545 | |
| 4546 | 4546 | fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 4547 | 4547 | const mod = self.bin_file.options.module.?; |
| 4548 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4548 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4549 | 4549 | const result: MCValue = result: { |
| 4550 | 4550 | const pl_ty = self.typeOfIndex(inst); |
| 4551 | 4551 | if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none; |
| ... | ... | @@ -4577,7 +4577,7 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 4577 | 4577 | } |
| 4578 | 4578 | |
| 4579 | 4579 | fn 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; | |
| 4581 | 4581 | |
| 4582 | 4582 | const dst_ty = self.typeOfIndex(inst); |
| 4583 | 4583 | const opt_mcv = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -4591,7 +4591,7 @@ fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4591 | 4591 | |
| 4592 | 4592 | fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 4593 | 4593 | const mod = self.bin_file.options.module.?; |
| 4594 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4594 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4595 | 4595 | const result = result: { |
| 4596 | 4596 | const dst_ty = self.typeOfIndex(inst); |
| 4597 | 4597 | const src_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -4625,7 +4625,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 4625 | 4625 | |
| 4626 | 4626 | fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4627 | 4627 | const mod = self.bin_file.options.module.?; |
| 4628 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4628 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4629 | 4629 | const err_union_ty = self.typeOf(ty_op.operand); |
| 4630 | 4630 | const err_ty = err_union_ty.errorUnionSet(mod); |
| 4631 | 4631 | const payload_ty = err_union_ty.errorUnionPayload(mod); |
| ... | ... | @@ -4667,7 +4667,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4667 | 4667 | } |
| 4668 | 4668 | |
| 4669 | 4669 | fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 4670 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4670 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4671 | 4671 | const operand_ty = self.typeOf(ty_op.operand); |
| 4672 | 4672 | const operand = try self.resolveInst(ty_op.operand); |
| 4673 | 4673 | const result = try self.genUnwrapErrUnionPayloadMir(inst, operand_ty, operand); |
| ... | ... | @@ -4677,7 +4677,7 @@ fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 4677 | 4677 | // *(E!T) -> E |
| 4678 | 4678 | fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4679 | 4679 | const mod = self.bin_file.options.module.?; |
| 4680 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4680 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4681 | 4681 | |
| 4682 | 4682 | const src_ty = self.typeOf(ty_op.operand); |
| 4683 | 4683 | const src_mcv = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -4715,7 +4715,7 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4715 | 4715 | |
| 4716 | 4716 | // *(E!T) -> *T |
| 4717 | 4717 | fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4718 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4718 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4719 | 4719 | const operand_ty = self.typeOf(ty_op.operand); |
| 4720 | 4720 | const operand = try self.resolveInst(ty_op.operand); |
| 4721 | 4721 | const result = try self.genUnwrapErrUnionPayloadPtrMir(inst, operand_ty, operand); |
| ... | ... | @@ -4724,7 +4724,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4724 | 4724 | |
| 4725 | 4725 | fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void { |
| 4726 | 4726 | const mod = self.bin_file.options.module.?; |
| 4727 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4727 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4728 | 4728 | const result: MCValue = result: { |
| 4729 | 4729 | const src_ty = self.typeOf(ty_op.operand); |
| 4730 | 4730 | const src_mcv = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -4866,7 +4866,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void { |
| 4866 | 4866 | |
| 4867 | 4867 | fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| 4868 | 4868 | const mod = self.bin_file.options.module.?; |
| 4869 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4869 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4870 | 4870 | const result: MCValue = result: { |
| 4871 | 4871 | const pl_ty = self.typeOf(ty_op.operand); |
| 4872 | 4872 | if (!pl_ty.hasRuntimeBits(mod)) break :result .{ .immediate = 1 }; |
| ... | ... | @@ -4920,9 +4920,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| 4920 | 4920 | /// T to E!T |
| 4921 | 4921 | fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 4922 | 4922 | const mod = self.bin_file.options.module.?; |
| 4923 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4923 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4924 | 4924 | |
| 4925 | const eu_ty = self.air.getRefType(ty_op.ty); | |
| 4925 | const eu_ty = ty_op.ty.toType(); | |
| 4926 | 4926 | const pl_ty = eu_ty.errorUnionPayload(mod); |
| 4927 | 4927 | const err_ty = eu_ty.errorUnionSet(mod); |
| 4928 | 4928 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -4943,9 +4943,9 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void { |
| 4943 | 4943 | /// E to E!T |
| 4944 | 4944 | fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4945 | 4945 | const mod = self.bin_file.options.module.?; |
| 4946 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4946 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4947 | 4947 | |
| 4948 | const eu_ty = self.air.getRefType(ty_op.ty); | |
| 4948 | const eu_ty = ty_op.ty.toType(); | |
| 4949 | 4949 | const pl_ty = eu_ty.errorUnionPayload(mod); |
| 4950 | 4950 | const err_ty = eu_ty.errorUnionSet(mod); |
| 4951 | 4951 | |
| ... | ... | @@ -4964,7 +4964,7 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 4964 | 4964 | } |
| 4965 | 4965 | |
| 4966 | 4966 | fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4967 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4967 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4968 | 4968 | const result = result: { |
| 4969 | 4969 | const src_mcv = try self.resolveInst(ty_op.operand); |
| 4970 | 4970 | if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv; |
| ... | ... | @@ -4978,7 +4978,7 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4978 | 4978 | } |
| 4979 | 4979 | |
| 4980 | 4980 | fn 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; | |
| 4982 | 4982 | |
| 4983 | 4983 | const result: MCValue = result: { |
| 4984 | 4984 | const src_mcv = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -5002,7 +5002,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { |
| 5002 | 5002 | |
| 5003 | 5003 | fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5004 | 5004 | const mod = self.bin_file.options.module.?; |
| 5005 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5005 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5006 | 5006 | |
| 5007 | 5007 | const src_ty = self.typeOf(ty_op.operand); |
| 5008 | 5008 | const src_mcv = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -5036,7 +5036,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5036 | 5036 | } |
| 5037 | 5037 | |
| 5038 | 5038 | fn 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; | |
| 5040 | 5040 | |
| 5041 | 5041 | const dst_ty = self.typeOfIndex(inst); |
| 5042 | 5042 | const opt_mcv = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -5106,7 +5106,7 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue { |
| 5106 | 5106 | |
| 5107 | 5107 | fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 5108 | 5108 | const mod = self.bin_file.options.module.?; |
| 5109 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 5109 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 5110 | 5110 | |
| 5111 | 5111 | const result: MCValue = result: { |
| 5112 | 5112 | const elem_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -5123,7 +5123,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 5123 | 5123 | } |
| 5124 | 5124 | |
| 5125 | 5125 | fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5126 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5126 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5127 | 5127 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 5128 | 5128 | const dst_mcv = try self.genSliceElemPtr(extra.lhs, extra.rhs); |
| 5129 | 5129 | return self.finishAir(inst, dst_mcv, .{ extra.lhs, extra.rhs, .none }); |
| ... | ... | @@ -5131,7 +5131,7 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5131 | 5131 | |
| 5132 | 5132 | fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 5133 | 5133 | const mod = self.bin_file.options.module.?; |
| 5134 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 5134 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 5135 | 5135 | |
| 5136 | 5136 | const array_ty = self.typeOf(bin_op.lhs); |
| 5137 | 5137 | const array = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -5205,7 +5205,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 5205 | 5205 | |
| 5206 | 5206 | fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 5207 | 5207 | const mod = self.bin_file.options.module.?; |
| 5208 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 5208 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 5209 | 5209 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 5210 | 5210 | |
| 5211 | 5211 | // this is identical to the `airPtrElemPtr` codegen expect here an |
| ... | ... | @@ -5255,7 +5255,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 5255 | 5255 | |
| 5256 | 5256 | fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5257 | 5257 | const mod = self.bin_file.options.module.?; |
| 5258 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5258 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5259 | 5259 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 5260 | 5260 | |
| 5261 | 5261 | const ptr_ty = self.typeOf(extra.lhs); |
| ... | ... | @@ -5288,7 +5288,7 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 5288 | 5288 | |
| 5289 | 5289 | fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 5290 | 5290 | const mod = self.bin_file.options.module.?; |
| 5291 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 5291 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 5292 | 5292 | const ptr_union_ty = self.typeOf(bin_op.lhs); |
| 5293 | 5293 | const union_ty = ptr_union_ty.childType(mod); |
| 5294 | 5294 | const tag_ty = self.typeOf(bin_op.rhs); |
| ... | ... | @@ -5332,7 +5332,7 @@ fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 5332 | 5332 | |
| 5333 | 5333 | fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 5334 | 5334 | const mod = self.bin_file.options.module.?; |
| 5335 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5335 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5336 | 5336 | |
| 5337 | 5337 | const tag_ty = self.typeOfIndex(inst); |
| 5338 | 5338 | const union_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -5386,7 +5386,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void { |
| 5386 | 5386 | |
| 5387 | 5387 | fn airClz(self: *Self, inst: Air.Inst.Index) !void { |
| 5388 | 5388 | const mod = self.bin_file.options.module.?; |
| 5389 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5389 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5390 | 5390 | const result = result: { |
| 5391 | 5391 | const dst_ty = self.typeOfIndex(inst); |
| 5392 | 5392 | const src_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -5545,7 +5545,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void { |
| 5545 | 5545 | |
| 5546 | 5546 | fn airCtz(self: *Self, inst: Air.Inst.Index) !void { |
| 5547 | 5547 | const mod = self.bin_file.options.module.?; |
| 5548 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5548 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5549 | 5549 | const result = result: { |
| 5550 | 5550 | const dst_ty = self.typeOfIndex(inst); |
| 5551 | 5551 | const src_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -5663,7 +5663,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void { |
| 5663 | 5663 | |
| 5664 | 5664 | fn airPopCount(self: *Self, inst: Air.Inst.Index) !void { |
| 5665 | 5665 | const mod = self.bin_file.options.module.?; |
| 5666 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5666 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5667 | 5667 | const result: MCValue = result: { |
| 5668 | 5668 | try self.spillEflagsIfOccupied(); |
| 5669 | 5669 | |
| ... | ... | @@ -5818,7 +5818,7 @@ fn genByteSwap( |
| 5818 | 5818 | mem_ok: bool, |
| 5819 | 5819 | ) !MCValue { |
| 5820 | 5820 | const mod = self.bin_file.options.module.?; |
| 5821 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5821 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5822 | 5822 | |
| 5823 | 5823 | if (src_ty.zigTypeTag(mod) == .Vector) return self.fail( |
| 5824 | 5824 | "TODO implement genByteSwap for {}", |
| ... | ... | @@ -5909,7 +5909,7 @@ fn genByteSwap( |
| 5909 | 5909 | |
| 5910 | 5910 | fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { |
| 5911 | 5911 | const mod = self.bin_file.options.module.?; |
| 5912 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5912 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5913 | 5913 | |
| 5914 | 5914 | const src_ty = self.typeOf(ty_op.operand); |
| 5915 | 5915 | const abi_size: u32 = @intCast(src_ty.abiSize(mod)); |
| ... | ... | @@ -5931,7 +5931,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { |
| 5931 | 5931 | |
| 5932 | 5932 | fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void { |
| 5933 | 5933 | const mod = self.bin_file.options.module.?; |
| 5934 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5934 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5935 | 5935 | |
| 5936 | 5936 | const src_ty = self.typeOf(ty_op.operand); |
| 5937 | 5937 | const abi_size: u32 = @intCast(src_ty.abiSize(mod)); |
| ... | ... | @@ -6053,7 +6053,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void { |
| 6053 | 6053 | |
| 6054 | 6054 | fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) !void { |
| 6055 | 6055 | const mod = self.bin_file.options.module.?; |
| 6056 | const tag = self.air.instructions.items(.tag)[inst]; | |
| 6056 | const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)]; | |
| 6057 | 6057 | |
| 6058 | 6058 | const result = result: { |
| 6059 | 6059 | const scalar_bits = ty.scalarType(mod).floatBits(self.target.*); |
| ... | ... | @@ -6179,7 +6179,7 @@ fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) |
| 6179 | 6179 | } |
| 6180 | 6180 | |
| 6181 | 6181 | fn airFloatSign(self: *Self, inst: Air.Inst.Index) !void { |
| 6182 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 6182 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 6183 | 6183 | const ty = self.typeOf(un_op); |
| 6184 | 6184 | return self.floatSign(inst, un_op, ty); |
| 6185 | 6185 | } |
| ... | ... | @@ -6204,7 +6204,7 @@ const RoundMode = packed struct(u5) { |
| 6204 | 6204 | }; |
| 6205 | 6205 | |
| 6206 | 6206 | fn airRound(self: *Self, inst: Air.Inst.Index, mode: RoundMode) !void { |
| 6207 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 6207 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 6208 | 6208 | const ty = self.typeOf(un_op); |
| 6209 | 6209 | |
| 6210 | 6210 | const result = result: { |
| ... | ... | @@ -6327,7 +6327,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: Ro |
| 6327 | 6327 | |
| 6328 | 6328 | fn airAbs(self: *Self, inst: Air.Inst.Index) !void { |
| 6329 | 6329 | const mod = self.bin_file.options.module.?; |
| 6330 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6330 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6331 | 6331 | const ty = self.typeOf(ty_op.operand); |
| 6332 | 6332 | |
| 6333 | 6333 | const result: MCValue = result: { |
| ... | ... | @@ -6467,7 +6467,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void { |
| 6467 | 6467 | |
| 6468 | 6468 | fn airSqrt(self: *Self, inst: Air.Inst.Index) !void { |
| 6469 | 6469 | const mod = self.bin_file.options.module.?; |
| 6470 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 6470 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 6471 | 6471 | const ty = self.typeOf(un_op); |
| 6472 | 6472 | const abi_size: u32 = @intCast(ty.abiSize(mod)); |
| 6473 | 6473 | |
| ... | ... | @@ -6634,7 +6634,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void { |
| 6634 | 6634 | } |
| 6635 | 6635 | |
| 6636 | 6636 | fn airUnaryMath(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void { |
| 6637 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 6637 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 6638 | 6638 | const ty = self.typeOf(un_op); |
| 6639 | 6639 | var callee_buf: ["__round?".len]u8 = undefined; |
| 6640 | 6640 | const result = try self.genCall(.{ .lib = .{ |
| ... | ... | @@ -6704,7 +6704,7 @@ fn reuseOperandAdvanced( |
| 6704 | 6704 | |
| 6705 | 6705 | // Prevent the operand deaths processing code from deallocating it. |
| 6706 | 6706 | self.liveness.clearOperandDeath(inst, op_index); |
| 6707 | const op_inst = Air.refToIndex(operand).?; | |
| 6707 | const op_inst = operand.toIndex().?; | |
| 6708 | 6708 | self.getResolvedInstValue(op_inst).reuse(self, maybe_tracked_inst, op_inst); |
| 6709 | 6709 | |
| 6710 | 6710 | return true; |
| ... | ... | @@ -6852,7 +6852,7 @@ fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerErro |
| 6852 | 6852 | |
| 6853 | 6853 | fn airLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 6854 | 6854 | const mod = self.bin_file.options.module.?; |
| 6855 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6855 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6856 | 6856 | const elem_ty = self.typeOfIndex(inst); |
| 6857 | 6857 | const result: MCValue = result: { |
| 6858 | 6858 | if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) break :result .none; |
| ... | ... | @@ -7051,7 +7051,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 7051 | 7051 | const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx }); |
| 7052 | 7052 | defer for (reg_locks) |lock| self.register_manager.unlockReg(lock); |
| 7053 | 7053 | |
| 7054 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7054 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7055 | 7055 | const ptr_mcv = try self.resolveInst(bin_op.lhs); |
| 7056 | 7056 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 7057 | 7057 | const src_mcv = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -7064,14 +7064,14 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 7064 | 7064 | } |
| 7065 | 7065 | |
| 7066 | 7066 | fn airStructFieldPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 7067 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 7067 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 7068 | 7068 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 7069 | 7069 | const result = try self.fieldPtr(inst, extra.struct_operand, extra.field_index); |
| 7070 | 7070 | return self.finishAir(inst, result, .{ extra.struct_operand, .none, .none }); |
| 7071 | 7071 | } |
| 7072 | 7072 | |
| 7073 | 7073 | fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void { |
| 7074 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7074 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7075 | 7075 | const result = try self.fieldPtr(inst, ty_op.operand, index); |
| 7076 | 7076 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 7077 | 7077 | } |
| ... | ... | @@ -7103,7 +7103,7 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32 |
| 7103 | 7103 | |
| 7104 | 7104 | fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 7105 | 7105 | const mod = self.bin_file.options.module.?; |
| 7106 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 7106 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 7107 | 7107 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 7108 | 7108 | const result: MCValue = result: { |
| 7109 | 7109 | const operand = extra.struct_operand; |
| ... | ... | @@ -7389,7 +7389,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 7389 | 7389 | |
| 7390 | 7390 | fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 7391 | 7391 | const mod = self.bin_file.options.module.?; |
| 7392 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 7392 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 7393 | 7393 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 7394 | 7394 | |
| 7395 | 7395 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7943,7 +7943,7 @@ fn genShiftBinOp( |
| 7943 | 7943 | |
| 7944 | 7944 | const dst_mcv: MCValue = dst: { |
| 7945 | 7945 | if (maybe_inst) |inst| { |
| 7946 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7946 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7947 | 7947 | if (self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv)) break :dst lhs_mcv; |
| 7948 | 7948 | } |
| 7949 | 7949 | const dst_mcv = try self.allocRegOrMemAdvanced(lhs_ty, maybe_inst, true); |
| ... | ... | @@ -10496,7 +10496,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { |
| 10496 | 10496 | else => return self.fail("TODO implement arg for {}", .{src_mcv}), |
| 10497 | 10497 | }; |
| 10498 | 10498 | |
| 10499 | const src_index = self.air.instructions.items(.data)[inst].arg.src_index; | |
| 10499 | const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index; | |
| 10500 | 10500 | const name = mod.getParamName(self.owner.func_index, src_index); |
| 10501 | 10501 | try self.genArgDbgInfo(arg_ty, name, src_mcv); |
| 10502 | 10502 | |
| ... | ... | @@ -10609,7 +10609,7 @@ fn airFrameAddress(self: *Self, inst: Air.Inst.Index) !void { |
| 10609 | 10609 | } |
| 10610 | 10610 | |
| 10611 | 10611 | fn airFence(self: *Self, inst: Air.Inst.Index) !void { |
| 10612 | const order = self.air.instructions.items(.data)[inst].fence; | |
| 10612 | const order = self.air.instructions.items(.data)[@intFromEnum(inst)].fence; | |
| 10613 | 10613 | switch (order) { |
| 10614 | 10614 | .Unordered, .Monotonic => unreachable, |
| 10615 | 10615 | .Acquire, .Release, .AcqRel => {}, |
| ... | ... | @@ -10621,7 +10621,7 @@ fn airFence(self: *Self, inst: Air.Inst.Index) !void { |
| 10621 | 10621 | fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !void { |
| 10622 | 10622 | if (modifier == .always_tail) return self.fail("TODO implement tail calls for x86_64", .{}); |
| 10623 | 10623 | |
| 10624 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 10624 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 10625 | 10625 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 10626 | 10626 | const arg_refs: []const Air.Inst.Ref = |
| 10627 | 10627 | @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]); |
| ... | ... | @@ -10883,7 +10883,7 @@ fn genCall(self: *Self, info: union(enum) { |
| 10883 | 10883 | |
| 10884 | 10884 | fn airRet(self: *Self, inst: Air.Inst.Index) !void { |
| 10885 | 10885 | const mod = self.bin_file.options.module.?; |
| 10886 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 10886 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 10887 | 10887 | |
| 10888 | 10888 | const ret_ty = self.fn_type.fnReturnType(mod); |
| 10889 | 10889 | switch (self.ret_mcv.short) { |
| ... | ... | @@ -10911,7 +10911,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void { |
| 10911 | 10911 | } |
| 10912 | 10912 | |
| 10913 | 10913 | fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 10914 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 10914 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 10915 | 10915 | const ptr = try self.resolveInst(un_op); |
| 10916 | 10916 | |
| 10917 | 10917 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -10932,7 +10932,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 10932 | 10932 | |
| 10933 | 10933 | fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void { |
| 10934 | 10934 | const mod = self.bin_file.options.module.?; |
| 10935 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 10935 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 10936 | 10936 | const ty = self.typeOf(bin_op.lhs); |
| 10937 | 10937 | |
| 10938 | 10938 | const result: Condition = result: { |
| ... | ... | @@ -11313,7 +11313,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void { |
| 11313 | 11313 | } |
| 11314 | 11314 | |
| 11315 | 11315 | fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void { |
| 11316 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 11316 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 11317 | 11317 | const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data; |
| 11318 | 11318 | const dst_mcv = try self.genBinOp( |
| 11319 | 11319 | inst, |
| ... | ... | @@ -11326,7 +11326,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void { |
| 11326 | 11326 | |
| 11327 | 11327 | fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 11328 | 11328 | const mod = self.bin_file.options.module.?; |
| 11329 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 11329 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 11330 | 11330 | |
| 11331 | 11331 | const addr_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp); |
| 11332 | 11332 | const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg); |
| ... | ... | @@ -11356,18 +11356,18 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 11356 | 11356 | } |
| 11357 | 11357 | |
| 11358 | 11358 | fn airTry(self: *Self, inst: Air.Inst.Index) !void { |
| 11359 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 11359 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 11360 | 11360 | const extra = self.air.extraData(Air.Try, pl_op.payload); |
| 11361 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 11361 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 11362 | 11362 | const operand_ty = self.typeOf(pl_op.operand); |
| 11363 | 11363 | const result = try self.genTry(inst, pl_op.operand, body, operand_ty, false); |
| 11364 | 11364 | return self.finishAir(inst, result, .{ .none, .none, .none }); |
| 11365 | 11365 | } |
| 11366 | 11366 | |
| 11367 | 11367 | fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 11368 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 11368 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 11369 | 11369 | const extra = self.air.extraData(Air.TryPtr, ty_pl.payload); |
| 11370 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 11370 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 11371 | 11371 | const operand_ty = self.typeOf(extra.data.ptr); |
| 11372 | 11372 | const result = try self.genTry(inst, extra.data.ptr, body, operand_ty, true); |
| 11373 | 11373 | return self.finishAir(inst, result, .{ .none, .none, .none }); |
| ... | ... | @@ -11392,7 +11392,7 @@ fn genTry( |
| 11392 | 11392 | const reloc = try self.genCondBrMir(Type.anyerror, is_err_mcv); |
| 11393 | 11393 | |
| 11394 | 11394 | if (self.liveness.operandDies(inst, 0)) { |
| 11395 | if (Air.refToIndex(operand)) |operand_inst| try self.processDeath(operand_inst); | |
| 11395 | if (operand.toIndex()) |operand_inst| try self.processDeath(operand_inst); | |
| 11396 | 11396 | } |
| 11397 | 11397 | |
| 11398 | 11398 | self.scope_generation += 1; |
| ... | ... | @@ -11421,7 +11421,7 @@ fn genTry( |
| 11421 | 11421 | } |
| 11422 | 11422 | |
| 11423 | 11423 | fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void { |
| 11424 | const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt; | |
| 11424 | const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; | |
| 11425 | 11425 | _ = try self.addInst(.{ |
| 11426 | 11426 | .tag = .pseudo, |
| 11427 | 11427 | .ops = .pseudo_dbg_line_line_column, |
| ... | ... | @@ -11434,7 +11434,7 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void { |
| 11434 | 11434 | } |
| 11435 | 11435 | |
| 11436 | 11436 | fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 11437 | const ty_fn = self.air.instructions.items(.data)[inst].ty_fn; | |
| 11437 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 11438 | 11438 | _ = try self.addInst(.{ |
| 11439 | 11439 | .tag = .pseudo, |
| 11440 | 11440 | .ops = .pseudo_dbg_inline_func, |
| ... | ... | @@ -11450,14 +11450,14 @@ fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 11450 | 11450 | } |
| 11451 | 11451 | |
| 11452 | 11452 | fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 11453 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 11453 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 11454 | 11454 | const operand = pl_op.operand; |
| 11455 | 11455 | const ty = self.typeOf(operand); |
| 11456 | 11456 | const mcv = try self.resolveInst(operand); |
| 11457 | 11457 | |
| 11458 | 11458 | const name = self.air.nullTerminatedString(pl_op.payload); |
| 11459 | 11459 | |
| 11460 | const tag = self.air.instructions.items(.tag)[inst]; | |
| 11460 | const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)]; | |
| 11461 | 11461 | try self.genVarDbgInfo(tag, ty, mcv, name); |
| 11462 | 11462 | |
| 11463 | 11463 | return self.finishAir(inst, .unreach, .{ operand, .none, .none }); |
| ... | ... | @@ -11492,19 +11492,21 @@ fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !Mir.Inst.Index { |
| 11492 | 11492 | } |
| 11493 | 11493 | |
| 11494 | 11494 | fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 11495 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 11495 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 11496 | 11496 | const cond = try self.resolveInst(pl_op.operand); |
| 11497 | 11497 | const cond_ty = self.typeOf(pl_op.operand); |
| 11498 | 11498 | const extra = self.air.extraData(Air.CondBr, pl_op.payload); |
| 11499 | const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len]; | |
| 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]); | |
| 11501 | 11503 | const liveness_cond_br = self.liveness.getCondBr(inst); |
| 11502 | 11504 | |
| 11503 | 11505 | // If the condition dies here in this condbr instruction, process |
| 11504 | 11506 | // that death now instead of later as this has an effect on |
| 11505 | 11507 | // whether it needs to be spilled in the branches |
| 11506 | 11508 | if (self.liveness.operandDies(inst, 0)) { |
| 11507 | if (Air.refToIndex(pl_op.operand)) |op_inst| try self.processDeath(op_inst); | |
| 11509 | if (pl_op.operand.toIndex()) |op_inst| try self.processDeath(op_inst); | |
| 11508 | 11510 | } |
| 11509 | 11511 | |
| 11510 | 11512 | self.scope_generation += 1; |
| ... | ... | @@ -11789,7 +11791,7 @@ fn isNonErrPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue |
| 11789 | 11791 | } |
| 11790 | 11792 | |
| 11791 | 11793 | fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 11792 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 11794 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 11793 | 11795 | const operand = try self.resolveInst(un_op); |
| 11794 | 11796 | const ty = self.typeOf(un_op); |
| 11795 | 11797 | const result = try self.isNull(inst, ty, operand); |
| ... | ... | @@ -11797,7 +11799,7 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void { |
| 11797 | 11799 | } |
| 11798 | 11800 | |
| 11799 | 11801 | fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 11800 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 11802 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 11801 | 11803 | const operand = try self.resolveInst(un_op); |
| 11802 | 11804 | const ty = self.typeOf(un_op); |
| 11803 | 11805 | const result = try self.isNullPtr(inst, ty, operand); |
| ... | ... | @@ -11805,7 +11807,7 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 11805 | 11807 | } |
| 11806 | 11808 | |
| 11807 | 11809 | fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 11808 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 11810 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 11809 | 11811 | const operand = try self.resolveInst(un_op); |
| 11810 | 11812 | const ty = self.typeOf(un_op); |
| 11811 | 11813 | const result = switch (try self.isNull(inst, ty, operand)) { |
| ... | ... | @@ -11816,7 +11818,7 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void { |
| 11816 | 11818 | } |
| 11817 | 11819 | |
| 11818 | 11820 | fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 11819 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 11821 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 11820 | 11822 | const operand = try self.resolveInst(un_op); |
| 11821 | 11823 | const ty = self.typeOf(un_op); |
| 11822 | 11824 | const result = switch (try self.isNullPtr(inst, ty, operand)) { |
| ... | ... | @@ -11827,7 +11829,7 @@ fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 11827 | 11829 | } |
| 11828 | 11830 | |
| 11829 | 11831 | fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 11830 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 11832 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 11831 | 11833 | const operand = try self.resolveInst(un_op); |
| 11832 | 11834 | const ty = self.typeOf(un_op); |
| 11833 | 11835 | const result = try self.isErr(inst, ty, operand); |
| ... | ... | @@ -11835,7 +11837,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void { |
| 11835 | 11837 | } |
| 11836 | 11838 | |
| 11837 | 11839 | fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 11838 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 11840 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 11839 | 11841 | const operand = try self.resolveInst(un_op); |
| 11840 | 11842 | const ty = self.typeOf(un_op); |
| 11841 | 11843 | const result = try self.isErrPtr(inst, ty, operand); |
| ... | ... | @@ -11843,7 +11845,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 11843 | 11845 | } |
| 11844 | 11846 | |
| 11845 | 11847 | fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 11846 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 11848 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 11847 | 11849 | const operand = try self.resolveInst(un_op); |
| 11848 | 11850 | const ty = self.typeOf(un_op); |
| 11849 | 11851 | const result = try self.isNonErr(inst, ty, operand); |
| ... | ... | @@ -11851,7 +11853,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void { |
| 11851 | 11853 | } |
| 11852 | 11854 | |
| 11853 | 11855 | fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 11854 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 11856 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 11855 | 11857 | const operand = try self.resolveInst(un_op); |
| 11856 | 11858 | const ty = self.typeOf(un_op); |
| 11857 | 11859 | const result = try self.isNonErrPtr(inst, ty, operand); |
| ... | ... | @@ -11860,9 +11862,9 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 11860 | 11862 | |
| 11861 | 11863 | fn airLoop(self: *Self, inst: Air.Inst.Index) !void { |
| 11862 | 11864 | // A loop is a setup to be able to jump back to the beginning. |
| 11863 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 11865 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 11864 | 11866 | const loop = self.air.extraData(Air.Block, ty_pl.payload); |
| 11865 | const body = self.air.extra[loop.end..][0..loop.data.body_len]; | |
| 11867 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]); | |
| 11866 | 11868 | |
| 11867 | 11869 | self.scope_generation += 1; |
| 11868 | 11870 | const state = try self.saveState(); |
| ... | ... | @@ -11889,9 +11891,9 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 11889 | 11891 | try self.blocks.putNoClobber(self.gpa, inst, .{ .state = self.initRetroactiveState() }); |
| 11890 | 11892 | const liveness = self.liveness.getBlock(inst); |
| 11891 | 11893 | |
| 11892 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 11894 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 11893 | 11895 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 11894 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 11896 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 11895 | 11897 | try self.genBody(body); |
| 11896 | 11898 | |
| 11897 | 11899 | var block_data = self.blocks.fetchRemove(inst).?; |
| ... | ... | @@ -11914,7 +11916,7 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 11914 | 11916 | } |
| 11915 | 11917 | |
| 11916 | 11918 | fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void { |
| 11917 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 11919 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 11918 | 11920 | const condition = try self.resolveInst(pl_op.operand); |
| 11919 | 11921 | const condition_ty = self.typeOf(pl_op.operand); |
| 11920 | 11922 | const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload); |
| ... | ... | @@ -11927,7 +11929,7 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void { |
| 11927 | 11929 | // that death now instead of later as this has an effect on |
| 11928 | 11930 | // whether it needs to be spilled in the branches |
| 11929 | 11931 | if (self.liveness.operandDies(inst, 0)) { |
| 11930 | if (Air.refToIndex(pl_op.operand)) |op_inst| try self.processDeath(op_inst); | |
| 11932 | if (pl_op.operand.toIndex()) |op_inst| try self.processDeath(op_inst); | |
| 11931 | 11933 | } |
| 11932 | 11934 | |
| 11933 | 11935 | self.scope_generation += 1; |
| ... | ... | @@ -11937,7 +11939,8 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void { |
| 11937 | 11939 | const case = self.air.extraData(Air.SwitchBr.Case, extra_index); |
| 11938 | 11940 | const items: []const Air.Inst.Ref = |
| 11939 | 11941 | @ptrCast(self.air.extra[case.end..][0..case.data.items_len]); |
| 11940 | const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len]; | |
| 11942 | const case_body: []const Air.Inst.Index = | |
| 11943 | @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]); | |
| 11941 | 11944 | extra_index = case.end + items.len + case_body.len; |
| 11942 | 11945 | |
| 11943 | 11946 | var relocs = try self.gpa.alloc(Mir.Inst.Index, items.len); |
| ... | ... | @@ -11975,7 +11978,8 @@ fn airSwitchBr(self: *Self, inst: Air.Inst.Index) !void { |
| 11975 | 11978 | } |
| 11976 | 11979 | |
| 11977 | 11980 | if (switch_br.data.else_body_len > 0) { |
| 11978 | const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len]; | |
| 11981 | const else_body: []const Air.Inst.Index = | |
| 11982 | @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]); | |
| 11979 | 11983 | |
| 11980 | 11984 | const else_deaths = liveness.deaths.len - 1; |
| 11981 | 11985 | for (liveness.deaths[else_deaths]) |operand| try self.processDeath(operand); |
| ... | ... | @@ -12008,7 +12012,7 @@ fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void { |
| 12008 | 12012 | |
| 12009 | 12013 | fn airBr(self: *Self, inst: Air.Inst.Index) !void { |
| 12010 | 12014 | const mod = self.bin_file.options.module.?; |
| 12011 | const br = self.air.instructions.items(.data)[inst].br; | |
| 12015 | const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 12012 | 12016 | |
| 12013 | 12017 | const block_ty = self.typeOfIndex(br.block_inst); |
| 12014 | 12018 | const block_unused = |
| ... | ... | @@ -12043,7 +12047,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void { |
| 12043 | 12047 | |
| 12044 | 12048 | // Process operand death so that it is properly accounted for in the State below. |
| 12045 | 12049 | if (self.liveness.operandDies(inst, 0)) { |
| 12046 | if (Air.refToIndex(br.operand)) |op_inst| try self.processDeath(op_inst); | |
| 12050 | if (br.operand.toIndex()) |op_inst| try self.processDeath(op_inst); | |
| 12047 | 12051 | } |
| 12048 | 12052 | |
| 12049 | 12053 | if (first_br) { |
| ... | ... | @@ -12069,7 +12073,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void { |
| 12069 | 12073 | |
| 12070 | 12074 | fn airAsm(self: *Self, inst: Air.Inst.Index) !void { |
| 12071 | 12075 | const mod = self.bin_file.options.module.?; |
| 12072 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 12076 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 12073 | 12077 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); |
| 12074 | 12078 | const clobbers_len: u31 = @truncate(extra.data.flags); |
| 12075 | 12079 | var extra_i: usize = extra.end; |
| ... | ... | @@ -13784,7 +13788,7 @@ fn genLazySymbolRef( |
| 13784 | 13788 | } |
| 13785 | 13789 | |
| 13786 | 13790 | fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 13787 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 13791 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 13788 | 13792 | const result = result: { |
| 13789 | 13793 | // TODO: handle case where the operand is a slice not a raw pointer |
| 13790 | 13794 | const src_mcv = try self.resolveInst(un_op); |
| ... | ... | @@ -13800,7 +13804,7 @@ fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 13800 | 13804 | |
| 13801 | 13805 | fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 13802 | 13806 | const mod = self.bin_file.options.module.?; |
| 13803 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 13807 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 13804 | 13808 | const dst_ty = self.typeOfIndex(inst); |
| 13805 | 13809 | const src_ty = self.typeOf(ty_op.operand); |
| 13806 | 13810 | |
| ... | ... | @@ -13858,7 +13862,7 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void { |
| 13858 | 13862 | |
| 13859 | 13863 | fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 13860 | 13864 | const mod = self.bin_file.options.module.?; |
| 13861 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 13865 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 13862 | 13866 | |
| 13863 | 13867 | const slice_ty = self.typeOfIndex(inst); |
| 13864 | 13868 | const ptr_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -13881,7 +13885,7 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void { |
| 13881 | 13885 | |
| 13882 | 13886 | fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 13883 | 13887 | const mod = self.bin_file.options.module.?; |
| 13884 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 13888 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 13885 | 13889 | |
| 13886 | 13890 | const dst_ty = self.typeOfIndex(inst); |
| 13887 | 13891 | const dst_bits = dst_ty.floatBits(self.target.*); |
| ... | ... | @@ -13960,7 +13964,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void { |
| 13960 | 13964 | |
| 13961 | 13965 | fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 13962 | 13966 | const mod = self.bin_file.options.module.?; |
| 13963 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 13967 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 13964 | 13968 | |
| 13965 | 13969 | const dst_ty = self.typeOfIndex(inst); |
| 13966 | 13970 | const dst_bits: u32 = @intCast(dst_ty.bitSize(mod)); |
| ... | ... | @@ -14031,7 +14035,7 @@ fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void { |
| 14031 | 14035 | |
| 14032 | 14036 | fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void { |
| 14033 | 14037 | const mod = self.bin_file.options.module.?; |
| 14034 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 14038 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 14035 | 14039 | const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 14036 | 14040 | |
| 14037 | 14041 | const ptr_ty = self.typeOf(extra.ptr); |
| ... | ... | @@ -14388,7 +14392,7 @@ fn atomicOp( |
| 14388 | 14392 | } |
| 14389 | 14393 | |
| 14390 | 14394 | fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void { |
| 14391 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 14395 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 14392 | 14396 | const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 14393 | 14397 | |
| 14394 | 14398 | try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx }); |
| ... | ... | @@ -14409,7 +14413,7 @@ fn airAtomicRmw(self: *Self, inst: Air.Inst.Index) !void { |
| 14409 | 14413 | } |
| 14410 | 14414 | |
| 14411 | 14415 | fn 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; | |
| 14413 | 14417 | |
| 14414 | 14418 | const ptr_ty = self.typeOf(atomic_load.ptr); |
| 14415 | 14419 | const ptr_mcv = try self.resolveInst(atomic_load.ptr); |
| ... | ... | @@ -14430,7 +14434,7 @@ fn airAtomicLoad(self: *Self, inst: Air.Inst.Index) !void { |
| 14430 | 14434 | } |
| 14431 | 14435 | |
| 14432 | 14436 | fn 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; | |
| 14434 | 14438 | |
| 14435 | 14439 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 14436 | 14440 | const ptr_mcv = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -14450,7 +14454,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 14450 | 14454 | // TODO if the value is undef, don't lower this instruction |
| 14451 | 14455 | } |
| 14452 | 14456 | |
| 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; | |
| 14454 | 14458 | |
| 14455 | 14459 | try self.spillRegisters(&.{ .rdi, .rsi, .rcx }); |
| 14456 | 14460 | const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx }); |
| ... | ... | @@ -14571,7 +14575,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void { |
| 14571 | 14575 | |
| 14572 | 14576 | fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void { |
| 14573 | 14577 | const mod = self.bin_file.options.module.?; |
| 14574 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 14578 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 14575 | 14579 | |
| 14576 | 14580 | try self.spillRegisters(&.{ .rdi, .rsi, .rcx }); |
| 14577 | 14581 | const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx }); |
| ... | ... | @@ -14626,7 +14630,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void { |
| 14626 | 14630 | |
| 14627 | 14631 | fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 14628 | 14632 | const mod = self.bin_file.options.module.?; |
| 14629 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 14633 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 14630 | 14634 | const inst_ty = self.typeOfIndex(inst); |
| 14631 | 14635 | const enum_ty = self.typeOf(un_op); |
| 14632 | 14636 | const resolved_cc = abi.resolveCallingConvention(.Unspecified, self.target.*); |
| ... | ... | @@ -14668,7 +14672,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 14668 | 14672 | |
| 14669 | 14673 | fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 14670 | 14674 | const mod = self.bin_file.options.module.?; |
| 14671 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 14675 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 14672 | 14676 | |
| 14673 | 14677 | const err_ty = self.typeOf(un_op); |
| 14674 | 14678 | const err_mcv = try self.resolveInst(un_op); |
| ... | ... | @@ -14770,7 +14774,7 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 14770 | 14774 | |
| 14771 | 14775 | fn airSplat(self: *Self, inst: Air.Inst.Index) !void { |
| 14772 | 14776 | const mod = self.bin_file.options.module.?; |
| 14773 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 14777 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 14774 | 14778 | const vector_ty = self.typeOfIndex(inst); |
| 14775 | 14779 | const vector_len = vector_ty.vectorLen(mod); |
| 14776 | 14780 | const dst_rc = self.regClassForType(vector_ty); |
| ... | ... | @@ -15106,7 +15110,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void { |
| 15106 | 15110 | } |
| 15107 | 15111 | |
| 15108 | 15112 | fn airSelect(self: *Self, inst: Air.Inst.Index) !void { |
| 15109 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 15113 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 15110 | 15114 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 15111 | 15115 | _ = extra; |
| 15112 | 15116 | return self.fail("TODO implement airSelect for x86_64", .{}); |
| ... | ... | @@ -15114,7 +15118,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void { |
| 15114 | 15118 | } |
| 15115 | 15119 | |
| 15116 | 15120 | fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { |
| 15117 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 15121 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 15118 | 15122 | _ = ty_pl; |
| 15119 | 15123 | return self.fail("TODO implement airShuffle for x86_64", .{}); |
| 15120 | 15124 | //return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| ... | ... | @@ -15122,7 +15126,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { |
| 15122 | 15126 | |
| 15123 | 15127 | fn airReduce(self: *Self, inst: Air.Inst.Index) !void { |
| 15124 | 15128 | const mod = self.bin_file.options.module.?; |
| 15125 | const reduce = self.air.instructions.items(.data)[inst].reduce; | |
| 15129 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; | |
| 15126 | 15130 | |
| 15127 | 15131 | const result: MCValue = result: { |
| 15128 | 15132 | const operand_ty = self.typeOf(reduce.operand); |
| ... | ... | @@ -15181,7 +15185,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 15181 | 15185 | const mod = self.bin_file.options.module.?; |
| 15182 | 15186 | const result_ty = self.typeOfIndex(inst); |
| 15183 | 15187 | const len: usize = @intCast(result_ty.arrayLen(mod)); |
| 15184 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 15188 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 15185 | 15189 | const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]); |
| 15186 | 15190 | const result: MCValue = result: { |
| 15187 | 15191 | switch (result_ty.zigTypeTag(mod)) { |
| ... | ... | @@ -15321,7 +15325,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 15321 | 15325 | fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void { |
| 15322 | 15326 | const mod = self.bin_file.options.module.?; |
| 15323 | 15327 | const ip = &mod.intern_pool; |
| 15324 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 15328 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 15325 | 15329 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 15326 | 15330 | const result: MCValue = result: { |
| 15327 | 15331 | const union_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -15365,13 +15369,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void { |
| 15365 | 15369 | } |
| 15366 | 15370 | |
| 15367 | 15371 | fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void { |
| 15368 | const prefetch = self.air.instructions.items(.data)[inst].prefetch; | |
| 15372 | const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; | |
| 15369 | 15373 | return self.finishAir(inst, .unreach, .{ prefetch.ptr, .none, .none }); |
| 15370 | 15374 | } |
| 15371 | 15375 | |
| 15372 | 15376 | fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void { |
| 15373 | 15377 | const mod = self.bin_file.options.module.?; |
| 15374 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 15378 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 15375 | 15379 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 15376 | 15380 | const ty = self.typeOfIndex(inst); |
| 15377 | 15381 | |
| ... | ... | @@ -15538,7 +15542,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void { |
| 15538 | 15542 | |
| 15539 | 15543 | fn airVaStart(self: *Self, inst: Air.Inst.Index) !void { |
| 15540 | 15544 | const mod = self.bin_file.options.module.?; |
| 15541 | const va_list_ty = self.air.instructions.items(.data)[inst].ty; | |
| 15545 | const va_list_ty = self.air.instructions.items(.data)[@intFromEnum(inst)].ty; | |
| 15542 | 15546 | const ptr_anyopaque_ty = try mod.singleMutPtrType(Type.anyopaque); |
| 15543 | 15547 | |
| 15544 | 15548 | const result: MCValue = switch (abi.resolveCallingConvention( |
| ... | ... | @@ -15591,7 +15595,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void { |
| 15591 | 15595 | |
| 15592 | 15596 | fn airVaArg(self: *Self, inst: Air.Inst.Index) !void { |
| 15593 | 15597 | const mod = self.bin_file.options.module.?; |
| 15594 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 15598 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 15595 | 15599 | const ty = self.typeOfIndex(inst); |
| 15596 | 15600 | const promote_ty = self.promoteVarArg(ty); |
| 15597 | 15601 | const ptr_anyopaque_ty = try mod.singleMutPtrType(Type.anyopaque); |
| ... | ... | @@ -15785,7 +15789,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void { |
| 15785 | 15789 | } |
| 15786 | 15790 | |
| 15787 | 15791 | fn airVaCopy(self: *Self, inst: Air.Inst.Index) !void { |
| 15788 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 15792 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 15789 | 15793 | const ptr_va_list_ty = self.typeOf(ty_op.operand); |
| 15790 | 15794 | |
| 15791 | 15795 | const dst_mcv = try self.allocRegOrMem(inst, true); |
| ... | ... | @@ -15794,7 +15798,7 @@ fn airVaCopy(self: *Self, inst: Air.Inst.Index) !void { |
| 15794 | 15798 | } |
| 15795 | 15799 | |
| 15796 | 15800 | fn airVaEnd(self: *Self, inst: Air.Inst.Index) !void { |
| 15797 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 15801 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 15798 | 15802 | return self.finishAir(inst, .unreach, .{ un_op, .none, .none }); |
| 15799 | 15803 | } |
| 15800 | 15804 | |
| ... | ... | @@ -15805,10 +15809,10 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue { |
| 15805 | 15809 | // If the type has no codegen bits, no need to store it. |
| 15806 | 15810 | if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return .none; |
| 15807 | 15811 | |
| 15808 | const mcv = if (Air.refToIndex(ref)) |inst| mcv: { | |
| 15812 | const mcv = if (ref.toIndex()) |inst| mcv: { | |
| 15809 | 15813 | break :mcv self.inst_tracking.getPtr(inst).?.short; |
| 15810 | 15814 | } else mcv: { |
| 15811 | const ip_index = Air.refToInterned(ref).?; | |
| 15815 | const ip_index = ref.toInterned().?; | |
| 15812 | 15816 | const gop = try self.const_tracking.getOrPut(self.gpa, ip_index); |
| 15813 | 15817 | if (!gop.found_existing) gop.value_ptr.* = InstTracking.init(init: { |
| 15814 | 15818 | const const_mcv = try self.genTypedValue(.{ .ty = ty, .val = Value.fromInterned(ip_index) }); |
src/codegen/c.zig+145-129| ... | ... | @@ -329,9 +329,13 @@ pub const Function = struct { |
| 329 | 329 | return .{ .new_local = @intCast(f.locals.items.len - 1) }; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | fn allocLocal(f: *Function, inst: Air.Inst.Index, ty: Type) !CValue { | |
| 332 | fn allocLocal(f: *Function, inst: ?Air.Inst.Index, ty: Type) !CValue { | |
| 333 | 333 | const result = try f.allocAlignedLocal(ty, .{}, .none); |
| 334 | log.debug("%{d}: allocating t{d}", .{ inst, result.new_local }); | |
| 334 | if (inst) |i| { | |
| 335 | log.debug("%{d}: allocating t{d}", .{ i, result.new_local }); | |
| 336 | } else { | |
| 337 | log.debug("allocating t{d}", .{result.new_local}); | |
| 338 | } | |
| 335 | 339 | return result; |
| 336 | 340 | } |
| 337 | 341 | |
| ... | ... | @@ -2951,7 +2955,7 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con |
| 2951 | 2955 | const pre_locals_len = @as(LocalIndex, @intCast(f.locals.items.len)); |
| 2952 | 2956 | |
| 2953 | 2957 | for (leading_deaths) |death| { |
| 2954 | try die(f, inst, Air.indexToRef(death)); | |
| 2958 | try die(f, inst, death.toRef()); | |
| 2955 | 2959 | } |
| 2956 | 2960 | |
| 2957 | 2961 | if (inner) { |
| ... | ... | @@ -2969,11 +2973,11 @@ fn genBodyResolveState(f: *Function, inst: Air.Inst.Index, leading_deaths: []con |
| 2969 | 2973 | // them, unless they were used to store allocs. |
| 2970 | 2974 | |
| 2971 | 2975 | for (pre_locals_len..f.locals.items.len) |local_i| { |
| 2972 | const local_index = @as(LocalIndex, @intCast(local_i)); | |
| 2976 | const local_index: LocalIndex = @intCast(local_i); | |
| 2973 | 2977 | if (f.allocs.contains(local_index)) { |
| 2974 | 2978 | continue; |
| 2975 | 2979 | } |
| 2976 | try freeLocal(f, inst, local_index, 0); | |
| 2980 | try freeLocal(f, inst, local_index, null); | |
| 2977 | 2981 | } |
| 2978 | 2982 | } |
| 2979 | 2983 | |
| ... | ... | @@ -2986,7 +2990,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, |
| 2986 | 2990 | if (f.liveness.isUnused(inst) and !f.air.mustLower(inst, ip)) |
| 2987 | 2991 | continue; |
| 2988 | 2992 | |
| 2989 | const result_value = switch (air_tags[inst]) { | |
| 2993 | const result_value = switch (air_tags[@intFromEnum(inst)]) { | |
| 2990 | 2994 | // zig fmt: off |
| 2991 | 2995 | .inferred_alloc, .inferred_alloc_comptime => unreachable, |
| 2992 | 2996 | |
| ... | ... | @@ -3013,7 +3017,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, |
| 3013 | 3017 | |
| 3014 | 3018 | .div_trunc, .div_exact => try airBinOp(f, inst, "/", "div_trunc", .none), |
| 3015 | 3019 | .rem => blk: { |
| 3016 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 3020 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3017 | 3021 | const lhs_scalar_ty = f.typeOf(bin_op.lhs).scalarType(mod); |
| 3018 | 3022 | // For binary operations @TypeOf(lhs)==@TypeOf(rhs), |
| 3019 | 3023 | // so we only check one. |
| ... | ... | @@ -3061,16 +3065,16 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, |
| 3061 | 3065 | |
| 3062 | 3066 | .slice => try airSlice(f, inst), |
| 3063 | 3067 | |
| 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), | |
| 3068 | 3072 | |
| 3069 | 3073 | .cmp_eq => try airEquality(f, inst, .eq), |
| 3070 | 3074 | .cmp_neq => try airEquality(f, inst, .neq), |
| 3071 | 3075 | |
| 3072 | 3076 | .cmp_vector => blk: { |
| 3073 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 3077 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3074 | 3078 | const extra = f.air.extraData(Air.VectorCmp, ty_pl.payload).data; |
| 3075 | 3079 | break :blk try airCmpOp(f, inst, extra, extra.compareOperator()); |
| 3076 | 3080 | }, |
| ... | ... | @@ -3256,7 +3260,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, |
| 3256 | 3260 | if (result_value == .new_local) { |
| 3257 | 3261 | log.debug("map %{d} to t{d}", .{ inst, result_value.new_local }); |
| 3258 | 3262 | } |
| 3259 | try f.value_map.putNoClobber(Air.indexToRef(inst), switch (result_value) { | |
| 3263 | try f.value_map.putNoClobber(inst.toRef(), switch (result_value) { | |
| 3260 | 3264 | .none => continue, |
| 3261 | 3265 | .new_local => |i| .{ .local = i }, |
| 3262 | 3266 | else => result_value, |
| ... | ... | @@ -3265,7 +3269,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, |
| 3265 | 3269 | } |
| 3266 | 3270 | |
| 3267 | 3271 | fn 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; | |
| 3269 | 3273 | |
| 3270 | 3274 | const inst_ty = f.typeOfIndex(inst); |
| 3271 | 3275 | const operand = try f.resolveInst(ty_op.operand); |
| ... | ... | @@ -3287,7 +3291,7 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: [ |
| 3287 | 3291 | fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3288 | 3292 | const mod = f.object.dg.module; |
| 3289 | 3293 | const inst_ty = f.typeOfIndex(inst); |
| 3290 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 3294 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3291 | 3295 | if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 3292 | 3296 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 3293 | 3297 | return .none; |
| ... | ... | @@ -3312,7 +3316,7 @@ fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3312 | 3316 | |
| 3313 | 3317 | fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3314 | 3318 | const mod = f.object.dg.module; |
| 3315 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 3319 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3316 | 3320 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3317 | 3321 | |
| 3318 | 3322 | const inst_ty = f.typeOfIndex(inst); |
| ... | ... | @@ -3349,7 +3353,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3349 | 3353 | fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3350 | 3354 | const mod = f.object.dg.module; |
| 3351 | 3355 | const inst_ty = f.typeOfIndex(inst); |
| 3352 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 3356 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3353 | 3357 | if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 3354 | 3358 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 3355 | 3359 | return .none; |
| ... | ... | @@ -3374,7 +3378,7 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3374 | 3378 | |
| 3375 | 3379 | fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3376 | 3380 | const mod = f.object.dg.module; |
| 3377 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 3381 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3378 | 3382 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3379 | 3383 | |
| 3380 | 3384 | const inst_ty = f.typeOfIndex(inst); |
| ... | ... | @@ -3404,7 +3408,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3404 | 3408 | |
| 3405 | 3409 | fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3406 | 3410 | const mod = f.object.dg.module; |
| 3407 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 3411 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3408 | 3412 | const inst_ty = f.typeOfIndex(inst); |
| 3409 | 3413 | if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 3410 | 3414 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| ... | ... | @@ -3486,7 +3490,7 @@ fn airArg(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3486 | 3490 | |
| 3487 | 3491 | fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3488 | 3492 | const mod = f.object.dg.module; |
| 3489 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 3493 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3490 | 3494 | |
| 3491 | 3495 | const ptr_ty = f.typeOf(ty_op.operand); |
| 3492 | 3496 | const ptr_scalar_ty = ptr_ty.scalarType(mod); |
| ... | ... | @@ -3573,14 +3577,14 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3573 | 3577 | |
| 3574 | 3578 | fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue { |
| 3575 | 3579 | const mod = f.object.dg.module; |
| 3576 | const un_op = f.air.instructions.items(.data)[inst].un_op; | |
| 3580 | const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 3577 | 3581 | const writer = f.object.writer(); |
| 3578 | const op_inst = Air.refToIndex(un_op); | |
| 3582 | const op_inst = un_op.toIndex(); | |
| 3579 | 3583 | const op_ty = f.typeOf(un_op); |
| 3580 | 3584 | const ret_ty = if (is_ptr) op_ty.childType(mod) else op_ty; |
| 3581 | 3585 | const lowered_ret_ty = try lowerFnRetTy(ret_ty, mod); |
| 3582 | 3586 | |
| 3583 | if (op_inst != null and f.air.instructions.items(.tag)[op_inst.?] == .call_always_tail) { | |
| 3587 | if (op_inst != null and f.air.instructions.items(.tag)[@intFromEnum(op_inst.?)] == .call_always_tail) { | |
| 3584 | 3588 | try reap(f, inst, &.{un_op}); |
| 3585 | 3589 | _ = try airCall(f, op_inst.?, .always_tail); |
| 3586 | 3590 | } else if (lowered_ret_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| ... | ... | @@ -3611,7 +3615,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue { |
| 3611 | 3615 | try f.writeCValue(writer, ret_val, .Other); |
| 3612 | 3616 | try writer.writeAll(";\n"); |
| 3613 | 3617 | if (is_array) { |
| 3614 | try freeLocal(f, inst, ret_val.new_local, 0); | |
| 3618 | try freeLocal(f, inst, ret_val.new_local, null); | |
| 3615 | 3619 | } |
| 3616 | 3620 | } else { |
| 3617 | 3621 | try reap(f, inst, &.{un_op}); |
| ... | ... | @@ -3623,7 +3627,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue { |
| 3623 | 3627 | |
| 3624 | 3628 | fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3625 | 3629 | const mod = f.object.dg.module; |
| 3626 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 3630 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3627 | 3631 | |
| 3628 | 3632 | const operand = try f.resolveInst(ty_op.operand); |
| 3629 | 3633 | try reap(f, inst, &.{ty_op.operand}); |
| ... | ... | @@ -3649,7 +3653,7 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3649 | 3653 | |
| 3650 | 3654 | fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3651 | 3655 | const mod = f.object.dg.module; |
| 3652 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 3656 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3653 | 3657 | |
| 3654 | 3658 | const operand = try f.resolveInst(ty_op.operand); |
| 3655 | 3659 | try reap(f, inst, &.{ty_op.operand}); |
| ... | ... | @@ -3732,7 +3736,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3732 | 3736 | } |
| 3733 | 3737 | |
| 3734 | 3738 | fn airIntFromBool(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3735 | const un_op = f.air.instructions.items(.data)[inst].un_op; | |
| 3739 | const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 3736 | 3740 | const operand = try f.resolveInst(un_op); |
| 3737 | 3741 | try reap(f, inst, &.{un_op}); |
| 3738 | 3742 | const writer = f.object.writer(); |
| ... | ... | @@ -3749,7 +3753,7 @@ fn airIntFromBool(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3749 | 3753 | fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { |
| 3750 | 3754 | const mod = f.object.dg.module; |
| 3751 | 3755 | // *a = b; |
| 3752 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 3756 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3753 | 3757 | |
| 3754 | 3758 | const ptr_ty = f.typeOf(bin_op.lhs); |
| 3755 | 3759 | const ptr_scalar_ty = ptr_ty.scalarType(mod); |
| ... | ... | @@ -3815,7 +3819,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { |
| 3815 | 3819 | try f.renderType(writer, src_ty); |
| 3816 | 3820 | try writer.writeAll("))"); |
| 3817 | 3821 | if (src_val == .constant) { |
| 3818 | try freeLocal(f, inst, array_src.new_local, 0); | |
| 3822 | try freeLocal(f, inst, array_src.new_local, null); | |
| 3819 | 3823 | } |
| 3820 | 3824 | } else if (ptr_info.packed_offset.host_size > 0 and ptr_info.flags.vector_index == .none) { |
| 3821 | 3825 | const host_bits = ptr_info.packed_offset.host_size * 8; |
| ... | ... | @@ -3887,7 +3891,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { |
| 3887 | 3891 | |
| 3888 | 3892 | fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info: BuiltinInfo) !CValue { |
| 3889 | 3893 | const mod = f.object.dg.module; |
| 3890 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 3894 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3891 | 3895 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3892 | 3896 | |
| 3893 | 3897 | const lhs = try f.resolveInst(bin_op.lhs); |
| ... | ... | @@ -3925,7 +3929,7 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info: |
| 3925 | 3929 | |
| 3926 | 3930 | fn airNot(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3927 | 3931 | const mod = f.object.dg.module; |
| 3928 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 3932 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3929 | 3933 | const operand_ty = f.typeOf(ty_op.operand); |
| 3930 | 3934 | const scalar_ty = operand_ty.scalarType(mod); |
| 3931 | 3935 | if (scalar_ty.ip_index != .bool_type) return try airUnBuiltinCall(f, inst, "not", .bits); |
| ... | ... | @@ -3958,7 +3962,7 @@ fn airBinOp( |
| 3958 | 3962 | info: BuiltinInfo, |
| 3959 | 3963 | ) !CValue { |
| 3960 | 3964 | const mod = f.object.dg.module; |
| 3961 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 3965 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3962 | 3966 | const operand_ty = f.typeOf(bin_op.lhs); |
| 3963 | 3967 | const scalar_ty = operand_ty.scalarType(mod); |
| 3964 | 3968 | if ((scalar_ty.isInt(mod) and scalar_ty.bitSize(mod) > 64) or scalar_ty.isRuntimeFloat()) |
| ... | ... | @@ -4046,7 +4050,7 @@ fn airEquality( |
| 4046 | 4050 | operator: std.math.CompareOperator, |
| 4047 | 4051 | ) !CValue { |
| 4048 | 4052 | const mod = f.object.dg.module; |
| 4049 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 4053 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4050 | 4054 | |
| 4051 | 4055 | const operand_ty = f.typeOf(bin_op.lhs); |
| 4052 | 4056 | const operand_bits = operand_ty.bitSize(mod); |
| ... | ... | @@ -4109,7 +4113,7 @@ fn airEquality( |
| 4109 | 4113 | } |
| 4110 | 4114 | |
| 4111 | 4115 | fn 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; | |
| 4113 | 4117 | |
| 4114 | 4118 | const inst_ty = f.typeOfIndex(inst); |
| 4115 | 4119 | const operand = try f.resolveInst(un_op); |
| ... | ... | @@ -4126,7 +4130,7 @@ fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4126 | 4130 | |
| 4127 | 4131 | fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue { |
| 4128 | 4132 | const mod = f.object.dg.module; |
| 4129 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 4133 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4130 | 4134 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4131 | 4135 | |
| 4132 | 4136 | const lhs = try f.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4174,7 +4178,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue { |
| 4174 | 4178 | |
| 4175 | 4179 | fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []const u8) !CValue { |
| 4176 | 4180 | const mod = f.object.dg.module; |
| 4177 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 4181 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4178 | 4182 | |
| 4179 | 4183 | const inst_ty = f.typeOfIndex(inst); |
| 4180 | 4184 | const inst_scalar_ty = inst_ty.scalarType(mod); |
| ... | ... | @@ -4216,7 +4220,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons |
| 4216 | 4220 | |
| 4217 | 4221 | fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4218 | 4222 | const mod = f.object.dg.module; |
| 4219 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 4223 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4220 | 4224 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4221 | 4225 | |
| 4222 | 4226 | const ptr = try f.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4260,7 +4264,7 @@ fn airCall( |
| 4260 | 4264 | const gpa = f.object.dg.gpa; |
| 4261 | 4265 | const writer = f.object.writer(); |
| 4262 | 4266 | |
| 4263 | const pl_op = f.air.instructions.items(.data)[inst].pl_op; | |
| 4267 | const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4264 | 4268 | const extra = f.air.extraData(Air.Call, pl_op.payload); |
| 4265 | 4269 | const args = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[extra.end..][0..extra.data.args_len])); |
| 4266 | 4270 | |
| ... | ... | @@ -4366,7 +4370,7 @@ fn airCall( |
| 4366 | 4370 | if (resolved_arg == .none) continue; |
| 4367 | 4371 | if (args_written != 0) try writer.writeAll(", "); |
| 4368 | 4372 | try f.writeCValue(writer, resolved_arg, .FunctionArgument); |
| 4369 | if (resolved_arg == .new_local) try freeLocal(f, inst, resolved_arg.new_local, 0); | |
| 4373 | if (resolved_arg == .new_local) try freeLocal(f, inst, resolved_arg.new_local, null); | |
| 4370 | 4374 | args_written += 1; |
| 4371 | 4375 | } |
| 4372 | 4376 | try writer.writeAll(");\n"); |
| ... | ... | @@ -4383,7 +4387,7 @@ fn airCall( |
| 4383 | 4387 | try writer.writeAll(", sizeof("); |
| 4384 | 4388 | try f.renderType(writer, ret_ty); |
| 4385 | 4389 | try writer.writeAll("));\n"); |
| 4386 | try freeLocal(f, inst, result_local.new_local, 0); | |
| 4390 | try freeLocal(f, inst, result_local.new_local, null); | |
| 4387 | 4391 | break :result array_local; |
| 4388 | 4392 | }; |
| 4389 | 4393 | |
| ... | ... | @@ -4391,7 +4395,7 @@ fn airCall( |
| 4391 | 4395 | } |
| 4392 | 4396 | |
| 4393 | 4397 | fn airDbgStmt(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4394 | const dbg_stmt = f.air.instructions.items(.data)[inst].dbg_stmt; | |
| 4398 | const dbg_stmt = f.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; | |
| 4395 | 4399 | const writer = f.object.writer(); |
| 4396 | 4400 | // TODO re-evaluate whether to emit these or not. If we naively emit |
| 4397 | 4401 | // these directives, the output file will report bogus line numbers because |
| ... | ... | @@ -4406,7 +4410,7 @@ fn airDbgStmt(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4406 | 4410 | } |
| 4407 | 4411 | |
| 4408 | 4412 | fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4409 | const ty_fn = f.air.instructions.items(.data)[inst].ty_fn; | |
| 4413 | const ty_fn = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 4410 | 4414 | const mod = f.object.dg.module; |
| 4411 | 4415 | const writer = f.object.writer(); |
| 4412 | 4416 | const owner_decl = mod.funcOwnerDeclPtr(ty_fn.func); |
| ... | ... | @@ -4418,7 +4422,7 @@ fn airDbgInline(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4418 | 4422 | |
| 4419 | 4423 | fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4420 | 4424 | const mod = f.object.dg.module; |
| 4421 | const pl_op = f.air.instructions.items(.data)[inst].pl_op; | |
| 4425 | const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4422 | 4426 | const name = f.air.nullTerminatedString(pl_op.payload); |
| 4423 | 4427 | const operand_is_undef = if (try f.air.value(pl_op.operand, mod)) |v| v.isUndefDeep(mod) else false; |
| 4424 | 4428 | if (!operand_is_undef) _ = try f.resolveInst(pl_op.operand); |
| ... | ... | @@ -4431,9 +4435,9 @@ fn airDbgVar(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4431 | 4435 | |
| 4432 | 4436 | fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4433 | 4437 | const mod = f.object.dg.module; |
| 4434 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 4438 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4435 | 4439 | const extra = f.air.extraData(Air.Block, ty_pl.payload); |
| 4436 | const body = f.air.extra[extra.end..][0..extra.data.body_len]; | |
| 4440 | const body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra.end..][0..extra.data.body_len]); | |
| 4437 | 4441 | const liveness_block = f.liveness.getBlock(inst); |
| 4438 | 4442 | |
| 4439 | 4443 | const block_id: usize = f.next_block_index; |
| ... | ... | @@ -4457,7 +4461,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4457 | 4461 | |
| 4458 | 4462 | // The body might result in some values we had beforehand being killed |
| 4459 | 4463 | for (liveness_block.deaths) |death| { |
| 4460 | try die(f, inst, Air.indexToRef(death)); | |
| 4464 | try die(f, inst, death.toRef()); | |
| 4461 | 4465 | } |
| 4462 | 4466 | |
| 4463 | 4467 | try f.object.indent_writer.insertNewline(); |
| ... | ... | @@ -4472,18 +4476,18 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4472 | 4476 | } |
| 4473 | 4477 | |
| 4474 | 4478 | fn airTry(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4475 | const pl_op = f.air.instructions.items(.data)[inst].pl_op; | |
| 4479 | const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4476 | 4480 | const extra = f.air.extraData(Air.Try, pl_op.payload); |
| 4477 | const body = f.air.extra[extra.end..][0..extra.data.body_len]; | |
| 4481 | const body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra.end..][0..extra.data.body_len]); | |
| 4478 | 4482 | const err_union_ty = f.typeOf(pl_op.operand); |
| 4479 | 4483 | return lowerTry(f, inst, pl_op.operand, body, err_union_ty, false); |
| 4480 | 4484 | } |
| 4481 | 4485 | |
| 4482 | 4486 | fn airTryPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4483 | 4487 | const mod = f.object.dg.module; |
| 4484 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 4488 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4485 | 4489 | const extra = f.air.extraData(Air.TryPtr, ty_pl.payload); |
| 4486 | const body = f.air.extra[extra.end..][0..extra.data.body_len]; | |
| 4490 | const body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra.end..][0..extra.data.body_len]); | |
| 4487 | 4491 | const err_union_ty = f.typeOf(extra.data.ptr).childType(mod); |
| 4488 | 4492 | return lowerTry(f, inst, extra.data.ptr, body, err_union_ty, true); |
| 4489 | 4493 | } |
| ... | ... | @@ -4529,7 +4533,7 @@ fn lowerTry( |
| 4529 | 4533 | |
| 4530 | 4534 | // Now we have the "then branch" (in terms of the liveness data); process any deaths. |
| 4531 | 4535 | for (liveness_condbr.then_deaths) |death| { |
| 4532 | try die(f, inst, Air.indexToRef(death)); | |
| 4536 | try die(f, inst, death.toRef()); | |
| 4533 | 4537 | } |
| 4534 | 4538 | |
| 4535 | 4539 | if (!payload_has_bits) { |
| ... | ... | @@ -4559,7 +4563,7 @@ fn lowerTry( |
| 4559 | 4563 | } |
| 4560 | 4564 | |
| 4561 | 4565 | fn airBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4562 | const branch = f.air.instructions.items(.data)[inst].br; | |
| 4566 | const branch = f.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 4563 | 4567 | const block = f.blocks.get(branch.block_inst).?; |
| 4564 | 4568 | const result = block.result; |
| 4565 | 4569 | const writer = f.object.writer(); |
| ... | ... | @@ -4582,7 +4586,7 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4582 | 4586 | } |
| 4583 | 4587 | |
| 4584 | 4588 | fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4585 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 4589 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4586 | 4590 | const dest_ty = f.typeOfIndex(inst); |
| 4587 | 4591 | |
| 4588 | 4592 | const operand = try f.resolveInst(ty_op.operand); |
| ... | ... | @@ -4624,7 +4628,7 @@ const LocalResult = struct { |
| 4624 | 4628 | |
| 4625 | 4629 | fn free(lr: LocalResult, f: *Function) !void { |
| 4626 | 4630 | if (lr.need_free) { |
| 4627 | try freeLocal(f, 0, lr.c_value.new_local, 0); | |
| 4631 | try freeLocal(f, null, lr.c_value.new_local, null); | |
| 4628 | 4632 | } |
| 4629 | 4633 | } |
| 4630 | 4634 | }; |
| ... | ... | @@ -4648,7 +4652,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca |
| 4648 | 4652 | } |
| 4649 | 4653 | |
| 4650 | 4654 | if (dest_ty.isPtrAtRuntime(mod) and operand_ty.isPtrAtRuntime(mod)) { |
| 4651 | const local = try f.allocLocal(0, dest_ty); | |
| 4655 | const local = try f.allocLocal(null, dest_ty); | |
| 4652 | 4656 | try f.writeCValue(writer, local, .Other); |
| 4653 | 4657 | try writer.writeAll(" = ("); |
| 4654 | 4658 | try f.renderType(writer, dest_ty); |
| ... | ... | @@ -4662,7 +4666,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca |
| 4662 | 4666 | } |
| 4663 | 4667 | |
| 4664 | 4668 | const operand_lval = if (operand == .constant) blk: { |
| 4665 | const operand_local = try f.allocLocal(0, operand_ty); | |
| 4669 | const operand_local = try f.allocLocal(null, operand_ty); | |
| 4666 | 4670 | try f.writeCValue(writer, operand_local, .Other); |
| 4667 | 4671 | if (operand_ty.isAbiInt(mod)) { |
| 4668 | 4672 | try writer.writeAll(" = "); |
| ... | ... | @@ -4676,7 +4680,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca |
| 4676 | 4680 | break :blk operand_local; |
| 4677 | 4681 | } else operand; |
| 4678 | 4682 | |
| 4679 | const local = try f.allocLocal(0, dest_ty); | |
| 4683 | const local = try f.allocLocal(null, dest_ty); | |
| 4680 | 4684 | try writer.writeAll("memcpy(&"); |
| 4681 | 4685 | try f.writeCValue(writer, local, .Other); |
| 4682 | 4686 | try writer.writeAll(", &"); |
| ... | ... | @@ -4741,7 +4745,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca |
| 4741 | 4745 | } |
| 4742 | 4746 | |
| 4743 | 4747 | if (operand == .constant) { |
| 4744 | try freeLocal(f, 0, operand_lval.new_local, 0); | |
| 4748 | try freeLocal(f, null, operand_lval.new_local, null); | |
| 4745 | 4749 | } |
| 4746 | 4750 | |
| 4747 | 4751 | return .{ |
| ... | ... | @@ -4784,7 +4788,7 @@ fn airFrameAddress(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4784 | 4788 | } |
| 4785 | 4789 | |
| 4786 | 4790 | fn airFence(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4787 | const atomic_order = f.air.instructions.items(.data)[inst].fence; | |
| 4791 | const atomic_order = f.air.instructions.items(.data)[@intFromEnum(inst)].fence; | |
| 4788 | 4792 | const writer = f.object.writer(); |
| 4789 | 4793 | |
| 4790 | 4794 | try writer.writeAll("zig_fence("); |
| ... | ... | @@ -4803,9 +4807,9 @@ fn airUnreach(f: *Function) !CValue { |
| 4803 | 4807 | } |
| 4804 | 4808 | |
| 4805 | 4809 | fn airLoop(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4806 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 4810 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4807 | 4811 | const loop = f.air.extraData(Air.Block, ty_pl.payload); |
| 4808 | const body = f.air.extra[loop.end..][0..loop.data.body_len]; | |
| 4812 | const body: []const Air.Inst.Index = @ptrCast(f.air.extra[loop.end..][0..loop.data.body_len]); | |
| 4809 | 4813 | const writer = f.object.writer(); |
| 4810 | 4814 | |
| 4811 | 4815 | try writer.writeAll("for (;;) "); |
| ... | ... | @@ -4816,12 +4820,12 @@ fn airLoop(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4816 | 4820 | } |
| 4817 | 4821 | |
| 4818 | 4822 | fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4819 | const pl_op = f.air.instructions.items(.data)[inst].pl_op; | |
| 4823 | const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4820 | 4824 | const cond = try f.resolveInst(pl_op.operand); |
| 4821 | 4825 | try reap(f, inst, &.{pl_op.operand}); |
| 4822 | 4826 | const extra = f.air.extraData(Air.CondBr, pl_op.payload); |
| 4823 | const then_body = f.air.extra[extra.end..][0..extra.data.then_body_len]; | |
| 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]); | |
| 4825 | 4829 | const liveness_condbr = f.liveness.getCondBr(inst); |
| 4826 | 4830 | const writer = f.object.writer(); |
| 4827 | 4831 | |
| ... | ... | @@ -4837,7 +4841,7 @@ fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4837 | 4841 | // `free_locals_map` well defined (our parent is responsible for doing that). |
| 4838 | 4842 | |
| 4839 | 4843 | for (liveness_condbr.else_deaths) |death| { |
| 4840 | try die(f, inst, Air.indexToRef(death)); | |
| 4844 | try die(f, inst, death.toRef()); | |
| 4841 | 4845 | } |
| 4842 | 4846 | |
| 4843 | 4847 | // We never actually need an else block, because our branches are noreturn so must (for |
| ... | ... | @@ -4850,7 +4854,7 @@ fn airCondBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4850 | 4854 | |
| 4851 | 4855 | fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4852 | 4856 | const mod = f.object.dg.module; |
| 4853 | const pl_op = f.air.instructions.items(.data)[inst].pl_op; | |
| 4857 | const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4854 | 4858 | const condition = try f.resolveInst(pl_op.operand); |
| 4855 | 4859 | try reap(f, inst, &.{pl_op.operand}); |
| 4856 | 4860 | const condition_ty = f.typeOf(pl_op.operand); |
| ... | ... | @@ -4883,7 +4887,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4883 | 4887 | for (0..switch_br.data.cases_len) |case_i| { |
| 4884 | 4888 | const case = f.air.extraData(Air.SwitchBr.Case, extra_index); |
| 4885 | 4889 | const items = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[case.end..][0..case.data.items_len])); |
| 4886 | const case_body = f.air.extra[case.end + items.len ..][0..case.data.body_len]; | |
| 4890 | const case_body: []const Air.Inst.Index = @ptrCast(f.air.extra[case.end + items.len ..][0..case.data.body_len]); | |
| 4887 | 4891 | extra_index = case.end + case.data.items_len + case_body.len; |
| 4888 | 4892 | |
| 4889 | 4893 | for (items) |item| { |
| ... | ... | @@ -4903,7 +4907,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4903 | 4907 | try genBodyResolveState(f, inst, liveness.deaths[case_i], case_body, false); |
| 4904 | 4908 | } else { |
| 4905 | 4909 | for (liveness.deaths[case_i]) |death| { |
| 4906 | try die(f, inst, Air.indexToRef(death)); | |
| 4910 | try die(f, inst, death.toRef()); | |
| 4907 | 4911 | } |
| 4908 | 4912 | try genBody(f, case_body); |
| 4909 | 4913 | } |
| ... | ... | @@ -4911,12 +4915,12 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4911 | 4915 | // The case body must be noreturn so we don't need to insert a break. |
| 4912 | 4916 | } |
| 4913 | 4917 | |
| 4914 | const else_body = f.air.extra[extra_index..][0..switch_br.data.else_body_len]; | |
| 4918 | const else_body: []const Air.Inst.Index = @ptrCast(f.air.extra[extra_index..][0..switch_br.data.else_body_len]); | |
| 4915 | 4919 | try f.object.indent_writer.insertNewline(); |
| 4916 | 4920 | if (else_body.len > 0) { |
| 4917 | 4921 | // Note that this must be the last case (i.e. the `last_case_i` case was not hit above) |
| 4918 | 4922 | for (liveness.deaths[liveness.deaths.len - 1]) |death| { |
| 4919 | try die(f, inst, Air.indexToRef(death)); | |
| 4923 | try die(f, inst, death.toRef()); | |
| 4920 | 4924 | } |
| 4921 | 4925 | try writer.writeAll("default: "); |
| 4922 | 4926 | try genBody(f, else_body); |
| ... | ... | @@ -4951,7 +4955,7 @@ fn asmInputNeedsLocal(f: *Function, constraint: []const u8, value: CValue) bool |
| 4951 | 4955 | |
| 4952 | 4956 | fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4953 | 4957 | const mod = f.object.dg.module; |
| 4954 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 4958 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4955 | 4959 | const extra = f.air.extraData(Air.Asm, ty_pl.payload); |
| 4956 | 4960 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; |
| 4957 | 4961 | const clobbers_len = @as(u31, @truncate(extra.data.flags)); |
| ... | ... | @@ -5213,7 +5217,7 @@ fn airIsNull( |
| 5213 | 5217 | is_ptr: bool, |
| 5214 | 5218 | ) !CValue { |
| 5215 | 5219 | const mod = f.object.dg.module; |
| 5216 | const un_op = f.air.instructions.items(.data)[inst].un_op; | |
| 5220 | const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5217 | 5221 | |
| 5218 | 5222 | const writer = f.object.writer(); |
| 5219 | 5223 | const operand = try f.resolveInst(un_op); |
| ... | ... | @@ -5259,7 +5263,7 @@ fn airIsNull( |
| 5259 | 5263 | |
| 5260 | 5264 | fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5261 | 5265 | const mod = f.object.dg.module; |
| 5262 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5266 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5263 | 5267 | |
| 5264 | 5268 | const operand = try f.resolveInst(ty_op.operand); |
| 5265 | 5269 | try reap(f, inst, &.{ty_op.operand}); |
| ... | ... | @@ -5293,7 +5297,7 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5293 | 5297 | |
| 5294 | 5298 | fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5295 | 5299 | const mod = f.object.dg.module; |
| 5296 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5300 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5297 | 5301 | |
| 5298 | 5302 | const writer = f.object.writer(); |
| 5299 | 5303 | const operand = try f.resolveInst(ty_op.operand); |
| ... | ... | @@ -5324,7 +5328,7 @@ fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5324 | 5328 | |
| 5325 | 5329 | fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5326 | 5330 | const mod = f.object.dg.module; |
| 5327 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5331 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5328 | 5332 | const writer = f.object.writer(); |
| 5329 | 5333 | const operand = try f.resolveInst(ty_op.operand); |
| 5330 | 5334 | try reap(f, inst, &.{ty_op.operand}); |
| ... | ... | @@ -5433,7 +5437,7 @@ fn fieldLocation( |
| 5433 | 5437 | } |
| 5434 | 5438 | |
| 5435 | 5439 | fn airStructFieldPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5436 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 5440 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5437 | 5441 | const extra = f.air.extraData(Air.StructField, ty_pl.payload).data; |
| 5438 | 5442 | |
| 5439 | 5443 | const container_ptr_val = try f.resolveInst(extra.struct_operand); |
| ... | ... | @@ -5443,7 +5447,7 @@ fn airStructFieldPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5443 | 5447 | } |
| 5444 | 5448 | |
| 5445 | 5449 | fn 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; | |
| 5447 | 5451 | |
| 5448 | 5452 | const container_ptr_val = try f.resolveInst(ty_op.operand); |
| 5449 | 5453 | try reap(f, inst, &.{ty_op.operand}); |
| ... | ... | @@ -5453,7 +5457,7 @@ fn airStructFieldPtrIndex(f: *Function, inst: Air.Inst.Index, index: u8) !CValue |
| 5453 | 5457 | |
| 5454 | 5458 | fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5455 | 5459 | const mod = f.object.dg.module; |
| 5456 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 5460 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5457 | 5461 | const extra = f.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 5458 | 5462 | |
| 5459 | 5463 | const container_ptr_ty = f.typeOfIndex(inst); |
| ... | ... | @@ -5558,7 +5562,7 @@ fn fieldPtr( |
| 5558 | 5562 | fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5559 | 5563 | const mod = f.object.dg.module; |
| 5560 | 5564 | const ip = &mod.intern_pool; |
| 5561 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 5565 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5562 | 5566 | const extra = f.air.extraData(Air.StructField, ty_pl.payload).data; |
| 5563 | 5567 | |
| 5564 | 5568 | const inst_ty = f.typeOfIndex(inst); |
| ... | ... | @@ -5634,7 +5638,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5634 | 5638 | try writer.writeAll(", sizeof("); |
| 5635 | 5639 | try f.renderType(writer, inst_ty); |
| 5636 | 5640 | try writer.writeAll("));\n"); |
| 5637 | try freeLocal(f, inst, temp_local.new_local, 0); | |
| 5641 | try freeLocal(f, inst, temp_local.new_local, null); | |
| 5638 | 5642 | return local; |
| 5639 | 5643 | }, |
| 5640 | 5644 | }, |
| ... | ... | @@ -5666,7 +5670,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5666 | 5670 | try writer.writeAll("));\n"); |
| 5667 | 5671 | |
| 5668 | 5672 | if (struct_byval == .constant) { |
| 5669 | try freeLocal(f, inst, operand_lval.new_local, 0); | |
| 5673 | try freeLocal(f, inst, operand_lval.new_local, null); | |
| 5670 | 5674 | } |
| 5671 | 5675 | |
| 5672 | 5676 | return local; |
| ... | ... | @@ -5695,7 +5699,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5695 | 5699 | /// Note that the result is never a pointer. |
| 5696 | 5700 | fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5697 | 5701 | const mod = f.object.dg.module; |
| 5698 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5702 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5699 | 5703 | |
| 5700 | 5704 | const inst_ty = f.typeOfIndex(inst); |
| 5701 | 5705 | const operand = try f.resolveInst(ty_op.operand); |
| ... | ... | @@ -5736,7 +5740,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5736 | 5740 | |
| 5737 | 5741 | fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue { |
| 5738 | 5742 | const mod = f.object.dg.module; |
| 5739 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5743 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5740 | 5744 | |
| 5741 | 5745 | const inst_ty = f.typeOfIndex(inst); |
| 5742 | 5746 | const operand = try f.resolveInst(ty_op.operand); |
| ... | ... | @@ -5772,7 +5776,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu |
| 5772 | 5776 | |
| 5773 | 5777 | fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5774 | 5778 | const mod = f.object.dg.module; |
| 5775 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5779 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5776 | 5780 | |
| 5777 | 5781 | const inst_ty = f.typeOfIndex(inst); |
| 5778 | 5782 | const repr_is_payload = inst_ty.optionalReprIsPayload(mod); |
| ... | ... | @@ -5804,7 +5808,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5804 | 5808 | |
| 5805 | 5809 | fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5806 | 5810 | const mod = f.object.dg.module; |
| 5807 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5811 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5808 | 5812 | |
| 5809 | 5813 | const inst_ty = f.typeOfIndex(inst); |
| 5810 | 5814 | const payload_ty = inst_ty.errorUnionPayload(mod); |
| ... | ... | @@ -5844,7 +5848,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5844 | 5848 | fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5845 | 5849 | const mod = f.object.dg.module; |
| 5846 | 5850 | const writer = f.object.writer(); |
| 5847 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5851 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5848 | 5852 | const operand = try f.resolveInst(ty_op.operand); |
| 5849 | 5853 | const error_union_ty = f.typeOf(ty_op.operand).childType(mod); |
| 5850 | 5854 | |
| ... | ... | @@ -5894,7 +5898,7 @@ fn airSaveErrReturnTraceIndex(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5894 | 5898 | |
| 5895 | 5899 | fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5896 | 5900 | const mod = f.object.dg.module; |
| 5897 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5901 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5898 | 5902 | |
| 5899 | 5903 | const inst_ty = f.typeOfIndex(inst); |
| 5900 | 5904 | const payload_ty = inst_ty.errorUnionPayload(mod); |
| ... | ... | @@ -5928,7 +5932,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5928 | 5932 | |
| 5929 | 5933 | fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const u8) !CValue { |
| 5930 | 5934 | const mod = f.object.dg.module; |
| 5931 | const un_op = f.air.instructions.items(.data)[inst].un_op; | |
| 5935 | const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5932 | 5936 | |
| 5933 | 5937 | const writer = f.object.writer(); |
| 5934 | 5938 | const operand = try f.resolveInst(un_op); |
| ... | ... | @@ -5963,7 +5967,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const |
| 5963 | 5967 | |
| 5964 | 5968 | fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5965 | 5969 | const mod = f.object.dg.module; |
| 5966 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 5970 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5967 | 5971 | |
| 5968 | 5972 | const operand = try f.resolveInst(ty_op.operand); |
| 5969 | 5973 | try reap(f, inst, &.{ty_op.operand}); |
| ... | ... | @@ -5994,7 +5998,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5994 | 5998 | |
| 5995 | 5999 | fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5996 | 6000 | const mod = f.object.dg.module; |
| 5997 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 6001 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5998 | 6002 | |
| 5999 | 6003 | const inst_ty = f.typeOfIndex(inst); |
| 6000 | 6004 | const operand = try f.resolveInst(ty_op.operand); |
| ... | ... | @@ -6037,7 +6041,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6037 | 6041 | |
| 6038 | 6042 | fn airIntFromPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6039 | 6043 | const mod = f.object.dg.module; |
| 6040 | const un_op = f.air.instructions.items(.data)[inst].un_op; | |
| 6044 | const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 6041 | 6045 | |
| 6042 | 6046 | const operand = try f.resolveInst(un_op); |
| 6043 | 6047 | const operand_ty = f.typeOf(un_op); |
| ... | ... | @@ -6066,7 +6070,7 @@ fn airUnBuiltinCall( |
| 6066 | 6070 | info: BuiltinInfo, |
| 6067 | 6071 | ) !CValue { |
| 6068 | 6072 | const mod = f.object.dg.module; |
| 6069 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 6073 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6070 | 6074 | |
| 6071 | 6075 | const operand = try f.resolveInst(ty_op.operand); |
| 6072 | 6076 | try reap(f, inst, &.{ty_op.operand}); |
| ... | ... | @@ -6110,7 +6114,7 @@ fn airBinBuiltinCall( |
| 6110 | 6114 | info: BuiltinInfo, |
| 6111 | 6115 | ) !CValue { |
| 6112 | 6116 | const mod = f.object.dg.module; |
| 6113 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 6117 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6114 | 6118 | |
| 6115 | 6119 | const operand_ty = f.typeOf(bin_op.lhs); |
| 6116 | 6120 | const operand_cty = try f.typeToCType(operand_ty, .complete); |
| ... | ... | @@ -6215,7 +6219,7 @@ fn airCmpBuiltinCall( |
| 6215 | 6219 | |
| 6216 | 6220 | fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue { |
| 6217 | 6221 | const mod = f.object.dg.module; |
| 6218 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 6222 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6219 | 6223 | const extra = f.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 6220 | 6224 | const inst_ty = f.typeOfIndex(inst); |
| 6221 | 6225 | const ptr = try f.resolveInst(extra.ptr); |
| ... | ... | @@ -6311,7 +6315,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue |
| 6311 | 6315 | try new_value_mat.end(f, inst); |
| 6312 | 6316 | |
| 6313 | 6317 | if (f.liveness.isUnused(inst)) { |
| 6314 | try freeLocal(f, inst, local.new_local, 0); | |
| 6318 | try freeLocal(f, inst, local.new_local, null); | |
| 6315 | 6319 | return .none; |
| 6316 | 6320 | } |
| 6317 | 6321 | |
| ... | ... | @@ -6320,7 +6324,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue |
| 6320 | 6324 | |
| 6321 | 6325 | fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6322 | 6326 | const mod = f.object.dg.module; |
| 6323 | const pl_op = f.air.instructions.items(.data)[inst].pl_op; | |
| 6327 | const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6324 | 6328 | const extra = f.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 6325 | 6329 | const inst_ty = f.typeOfIndex(inst); |
| 6326 | 6330 | const ptr_ty = f.typeOf(pl_op.operand); |
| ... | ... | @@ -6366,7 +6370,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6366 | 6370 | try operand_mat.end(f, inst); |
| 6367 | 6371 | |
| 6368 | 6372 | if (f.liveness.isUnused(inst)) { |
| 6369 | try freeLocal(f, inst, local.new_local, 0); | |
| 6373 | try freeLocal(f, inst, local.new_local, null); | |
| 6370 | 6374 | return .none; |
| 6371 | 6375 | } |
| 6372 | 6376 | |
| ... | ... | @@ -6375,7 +6379,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6375 | 6379 | |
| 6376 | 6380 | fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6377 | 6381 | const mod = f.object.dg.module; |
| 6378 | const atomic_load = f.air.instructions.items(.data)[inst].atomic_load; | |
| 6382 | const atomic_load = f.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; | |
| 6379 | 6383 | const ptr = try f.resolveInst(atomic_load.ptr); |
| 6380 | 6384 | try reap(f, inst, &.{atomic_load.ptr}); |
| 6381 | 6385 | const ptr_ty = f.typeOf(atomic_load.ptr); |
| ... | ... | @@ -6411,7 +6415,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6411 | 6415 | |
| 6412 | 6416 | fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CValue { |
| 6413 | 6417 | const mod = f.object.dg.module; |
| 6414 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 6418 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6415 | 6419 | const ptr_ty = f.typeOf(bin_op.lhs); |
| 6416 | 6420 | const ty = ptr_ty.childType(mod); |
| 6417 | 6421 | const ptr = try f.resolveInst(bin_op.lhs); |
| ... | ... | @@ -6455,7 +6459,7 @@ fn writeSliceOrPtr(f: *Function, writer: anytype, ptr: CValue, ptr_ty: Type) !vo |
| 6455 | 6459 | |
| 6456 | 6460 | fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { |
| 6457 | 6461 | const mod = f.object.dg.module; |
| 6458 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 6462 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6459 | 6463 | const dest_ty = f.typeOf(bin_op.lhs); |
| 6460 | 6464 | const dest_slice = try f.resolveInst(bin_op.lhs); |
| 6461 | 6465 | const value = try f.resolveInst(bin_op.rhs); |
| ... | ... | @@ -6542,7 +6546,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { |
| 6542 | 6546 | try a.end(f, writer); |
| 6543 | 6547 | |
| 6544 | 6548 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 6545 | try freeLocal(f, inst, index.new_local, 0); | |
| 6549 | try freeLocal(f, inst, index.new_local, null); | |
| 6546 | 6550 | |
| 6547 | 6551 | return .none; |
| 6548 | 6552 | } |
| ... | ... | @@ -6577,7 +6581,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { |
| 6577 | 6581 | |
| 6578 | 6582 | fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6579 | 6583 | const mod = f.object.dg.module; |
| 6580 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 6584 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6581 | 6585 | const dest_ptr = try f.resolveInst(bin_op.lhs); |
| 6582 | 6586 | const src_ptr = try f.resolveInst(bin_op.rhs); |
| 6583 | 6587 | const dest_ty = f.typeOf(bin_op.lhs); |
| ... | ... | @@ -6616,7 +6620,7 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6616 | 6620 | |
| 6617 | 6621 | fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6618 | 6622 | const mod = f.object.dg.module; |
| 6619 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 6623 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6620 | 6624 | const union_ptr = try f.resolveInst(bin_op.lhs); |
| 6621 | 6625 | const new_tag = try f.resolveInst(bin_op.rhs); |
| 6622 | 6626 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| ... | ... | @@ -6637,7 +6641,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6637 | 6641 | |
| 6638 | 6642 | fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6639 | 6643 | const mod = f.object.dg.module; |
| 6640 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 6644 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6641 | 6645 | |
| 6642 | 6646 | const operand = try f.resolveInst(ty_op.operand); |
| 6643 | 6647 | try reap(f, inst, &.{ty_op.operand}); |
| ... | ... | @@ -6659,7 +6663,7 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6659 | 6663 | |
| 6660 | 6664 | fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6661 | 6665 | const mod = f.object.dg.module; |
| 6662 | const un_op = f.air.instructions.items(.data)[inst].un_op; | |
| 6666 | const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 6663 | 6667 | |
| 6664 | 6668 | const inst_ty = f.typeOfIndex(inst); |
| 6665 | 6669 | const enum_ty = f.typeOf(un_op); |
| ... | ... | @@ -6679,7 +6683,7 @@ fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6679 | 6683 | } |
| 6680 | 6684 | |
| 6681 | 6685 | fn 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; | |
| 6683 | 6687 | |
| 6684 | 6688 | const writer = f.object.writer(); |
| 6685 | 6689 | const inst_ty = f.typeOfIndex(inst); |
| ... | ... | @@ -6696,7 +6700,7 @@ fn airErrorName(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6696 | 6700 | |
| 6697 | 6701 | fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6698 | 6702 | const mod = f.object.dg.module; |
| 6699 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 6703 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6700 | 6704 | |
| 6701 | 6705 | const operand = try f.resolveInst(ty_op.operand); |
| 6702 | 6706 | try reap(f, inst, &.{ty_op.operand}); |
| ... | ... | @@ -6719,7 +6723,7 @@ fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6719 | 6723 | } |
| 6720 | 6724 | |
| 6721 | 6725 | fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6722 | const pl_op = f.air.instructions.items(.data)[inst].pl_op; | |
| 6726 | const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6723 | 6727 | const extra = f.air.extraData(Air.Bin, pl_op.payload).data; |
| 6724 | 6728 | |
| 6725 | 6729 | const pred = try f.resolveInst(pl_op.operand); |
| ... | ... | @@ -6751,7 +6755,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6751 | 6755 | |
| 6752 | 6756 | fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6753 | 6757 | const mod = f.object.dg.module; |
| 6754 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 6758 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6755 | 6759 | const extra = f.air.extraData(Air.Shuffle, ty_pl.payload).data; |
| 6756 | 6760 | |
| 6757 | 6761 | const mask = Value.fromInterned(extra.mask); |
| ... | ... | @@ -6783,7 +6787,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6783 | 6787 | |
| 6784 | 6788 | fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6785 | 6789 | const mod = f.object.dg.module; |
| 6786 | const reduce = f.air.instructions.items(.data)[inst].reduce; | |
| 6790 | const reduce = f.air.instructions.items(.data)[@intFromEnum(inst)].reduce; | |
| 6787 | 6791 | |
| 6788 | 6792 | const scalar_ty = f.typeOfIndex(inst); |
| 6789 | 6793 | const operand = try f.resolveInst(reduce.operand); |
| ... | ... | @@ -6939,7 +6943,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6939 | 6943 | fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6940 | 6944 | const mod = f.object.dg.module; |
| 6941 | 6945 | const ip = &mod.intern_pool; |
| 6942 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 6946 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6943 | 6947 | const inst_ty = f.typeOfIndex(inst); |
| 6944 | 6948 | const len = @as(usize, @intCast(inst_ty.arrayLen(mod))); |
| 6945 | 6949 | const elements = @as([]const Air.Inst.Ref, @ptrCast(f.air.extra[ty_pl.payload..][0..len])); |
| ... | ... | @@ -7069,7 +7073,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7069 | 7073 | fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7070 | 7074 | const mod = f.object.dg.module; |
| 7071 | 7075 | const ip = &mod.intern_pool; |
| 7072 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | |
| 7076 | const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 7073 | 7077 | const extra = f.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 7074 | 7078 | |
| 7075 | 7079 | const union_ty = f.typeOfIndex(inst); |
| ... | ... | @@ -7117,7 +7121,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7117 | 7121 | |
| 7118 | 7122 | fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7119 | 7123 | const mod = f.object.dg.module; |
| 7120 | const prefetch = f.air.instructions.items(.data)[inst].prefetch; | |
| 7124 | const prefetch = f.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; | |
| 7121 | 7125 | |
| 7122 | 7126 | const ptr_ty = f.typeOf(prefetch.ptr); |
| 7123 | 7127 | const ptr = try f.resolveInst(prefetch.ptr); |
| ... | ... | @@ -7142,7 +7146,7 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7142 | 7146 | } |
| 7143 | 7147 | |
| 7144 | 7148 | fn 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; | |
| 7146 | 7150 | |
| 7147 | 7151 | const writer = f.object.writer(); |
| 7148 | 7152 | const inst_ty = f.typeOfIndex(inst); |
| ... | ... | @@ -7156,7 +7160,7 @@ fn airWasmMemorySize(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7156 | 7160 | } |
| 7157 | 7161 | |
| 7158 | 7162 | fn 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; | |
| 7160 | 7164 | |
| 7161 | 7165 | const writer = f.object.writer(); |
| 7162 | 7166 | const inst_ty = f.typeOfIndex(inst); |
| ... | ... | @@ -7174,7 +7178,7 @@ fn airWasmMemoryGrow(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7174 | 7178 | |
| 7175 | 7179 | fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7176 | 7180 | const mod = f.object.dg.module; |
| 7177 | const un_op = f.air.instructions.items(.data)[inst].un_op; | |
| 7181 | const un_op = f.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 7178 | 7182 | |
| 7179 | 7183 | const operand = try f.resolveInst(un_op); |
| 7180 | 7184 | try reap(f, inst, &.{un_op}); |
| ... | ... | @@ -7200,7 +7204,7 @@ fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7200 | 7204 | |
| 7201 | 7205 | fn airAbs(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7202 | 7206 | const mod = f.object.dg.module; |
| 7203 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | |
| 7207 | const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7204 | 7208 | const operand = try f.resolveInst(ty_op.operand); |
| 7205 | 7209 | const ty = f.typeOf(ty_op.operand); |
| 7206 | 7210 | const scalar_ty = ty.scalarType(mod); |
| ... | ... | @@ -7239,7 +7243,7 @@ fn unFloatOp(f: *Function, inst: Air.Inst.Index, operand: CValue, ty: Type, oper |
| 7239 | 7243 | } |
| 7240 | 7244 | |
| 7241 | 7245 | fn 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; | |
| 7243 | 7247 | |
| 7244 | 7248 | const operand = try f.resolveInst(un_op); |
| 7245 | 7249 | try reap(f, inst, &.{un_op}); |
| ... | ... | @@ -7250,7 +7254,7 @@ fn airUnFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVal |
| 7250 | 7254 | |
| 7251 | 7255 | fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CValue { |
| 7252 | 7256 | const mod = f.object.dg.module; |
| 7253 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | |
| 7257 | const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7254 | 7258 | |
| 7255 | 7259 | const lhs = try f.resolveInst(bin_op.lhs); |
| 7256 | 7260 | const rhs = try f.resolveInst(bin_op.rhs); |
| ... | ... | @@ -7282,7 +7286,7 @@ fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVa |
| 7282 | 7286 | |
| 7283 | 7287 | fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7284 | 7288 | const mod = f.object.dg.module; |
| 7285 | const pl_op = f.air.instructions.items(.data)[inst].pl_op; | |
| 7289 | const pl_op = f.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 7286 | 7290 | const bin_op = f.air.extraData(Air.Bin, pl_op.payload).data; |
| 7287 | 7291 | |
| 7288 | 7292 | const mulend1 = try f.resolveInst(bin_op.lhs); |
| ... | ... | @@ -7336,7 +7340,7 @@ fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7336 | 7340 | } |
| 7337 | 7341 | |
| 7338 | 7342 | fn 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; | |
| 7340 | 7344 | |
| 7341 | 7345 | const inst_ty = f.typeOfIndex(inst); |
| 7342 | 7346 | const va_list = try f.resolveInst(ty_op.operand); |
| ... | ... | @@ -7348,13 +7352,13 @@ fn airCVaArg(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7348 | 7352 | try writer.writeAll(" = va_arg(*(va_list *)"); |
| 7349 | 7353 | try f.writeCValue(writer, va_list, .Other); |
| 7350 | 7354 | try writer.writeAll(", "); |
| 7351 | try f.renderType(writer, f.air.getRefType(ty_op.ty)); | |
| 7355 | try f.renderType(writer, ty_op.ty.toType()); | |
| 7352 | 7356 | try writer.writeAll(");\n"); |
| 7353 | 7357 | return local; |
| 7354 | 7358 | } |
| 7355 | 7359 | |
| 7356 | 7360 | fn 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; | |
| 7358 | 7362 | |
| 7359 | 7363 | const va_list = try f.resolveInst(un_op); |
| 7360 | 7364 | try reap(f, inst, &.{un_op}); |
| ... | ... | @@ -7367,7 +7371,7 @@ fn airCVaEnd(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7367 | 7371 | } |
| 7368 | 7372 | |
| 7369 | 7373 | fn 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; | |
| 7371 | 7375 | |
| 7372 | 7376 | const inst_ty = f.typeOfIndex(inst); |
| 7373 | 7377 | const va_list = try f.resolveInst(ty_op.operand); |
| ... | ... | @@ -7836,7 +7840,7 @@ const Materialize = struct { |
| 7836 | 7840 | |
| 7837 | 7841 | pub fn end(self: Materialize, f: *Function, inst: Air.Inst.Index) !void { |
| 7838 | 7842 | switch (self.local) { |
| 7839 | .new_local => |local| try freeLocal(f, inst, local, 0), | |
| 7843 | .new_local => |local| try freeLocal(f, inst, local, null), | |
| 7840 | 7844 | else => {}, |
| 7841 | 7845 | } |
| 7842 | 7846 | } |
| ... | ... | @@ -7926,7 +7930,7 @@ const Vectorize = struct { |
| 7926 | 7930 | if (self.index != .none) { |
| 7927 | 7931 | f.object.indent_writer.popIndent(); |
| 7928 | 7932 | try writer.writeAll("}\n"); |
| 7929 | try freeLocal(f, inst, self.index.new_local, 0); | |
| 7933 | try freeLocal(f, inst, self.index.new_local, null); | |
| 7930 | 7934 | } |
| 7931 | 7935 | } |
| 7932 | 7936 | }; |
| ... | ... | @@ -7972,7 +7976,7 @@ fn reap(f: *Function, inst: Air.Inst.Index, operands: []const Air.Inst.Ref) !voi |
| 7972 | 7976 | } |
| 7973 | 7977 | |
| 7974 | 7978 | fn die(f: *Function, inst: Air.Inst.Index, ref: Air.Inst.Ref) !void { |
| 7975 | const ref_inst = Air.refToIndex(ref) orelse return; | |
| 7979 | const ref_inst = ref.toIndex() orelse return; | |
| 7976 | 7980 | const c_value = (f.value_map.fetchRemove(ref) orelse return).value; |
| 7977 | 7981 | const local_index = switch (c_value) { |
| 7978 | 7982 | .local, .new_local => |l| l, |
| ... | ... | @@ -7981,10 +7985,22 @@ fn die(f: *Function, inst: Air.Inst.Index, ref: Air.Inst.Ref) !void { |
| 7981 | 7985 | try freeLocal(f, inst, local_index, ref_inst); |
| 7982 | 7986 | } |
| 7983 | 7987 | |
| 7984 | fn freeLocal(f: *Function, inst: Air.Inst.Index, local_index: LocalIndex, ref_inst: Air.Inst.Index) !void { | |
| 7988 | fn freeLocal(f: *Function, inst: ?Air.Inst.Index, local_index: LocalIndex, ref_inst: ?Air.Inst.Index) !void { | |
| 7985 | 7989 | const gpa = f.object.dg.gpa; |
| 7986 | 7990 | const local = &f.locals.items[local_index]; |
| 7987 | log.debug("%{d}: freeing t{d} (operand %{d})", .{ inst, local_index, ref_inst }); | |
| 7991 | if (inst) |i| { | |
| 7992 | if (ref_inst) |operand| { | |
| 7993 | log.debug("%{d}: freeing t{d} (operand %{d})", .{ @intFromEnum(i), local_index, operand }); | |
| 7994 | } else { | |
| 7995 | log.debug("%{d}: freeing t{d}", .{ @intFromEnum(i), local_index }); | |
| 7996 | } | |
| 7997 | } else { | |
| 7998 | if (ref_inst) |operand| { | |
| 7999 | log.debug("freeing t{d} (operand %{d})", .{ local_index, operand }); | |
| 8000 | } else { | |
| 8001 | log.debug("freeing t{d}", .{local_index}); | |
| 8002 | } | |
| 8003 | } | |
| 7988 | 8004 | const gop = try f.free_locals_map.getOrPut(gpa, local.getType()); |
| 7989 | 8005 | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 7990 | 8006 | if (std.debug.runtime_safety) { |
src/codegen/llvm.zig+147-147| ... | ... | @@ -4850,7 +4850,7 @@ pub const FuncGen = struct { |
| 4850 | 4850 | for (body, 0..) |inst, i| { |
| 4851 | 4851 | if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue; |
| 4852 | 4852 | |
| 4853 | const val: Builder.Value = switch (air_tags[inst]) { | |
| 4853 | const val: Builder.Value = switch (air_tags[@intFromEnum(inst)]) { | |
| 4854 | 4854 | // zig fmt: off |
| 4855 | 4855 | .add => try self.airAdd(inst, .normal), |
| 4856 | 4856 | .add_optimized => try self.airAdd(inst, .fast), |
| ... | ... | @@ -5090,7 +5090,7 @@ pub const FuncGen = struct { |
| 5090 | 5090 | .work_group_id => try self.airWorkGroupId(inst), |
| 5091 | 5091 | // zig fmt: on |
| 5092 | 5092 | }; |
| 5093 | if (val != .none) try self.func_inst_table.putNoClobber(self.gpa, Air.indexToRef(inst), val); | |
| 5093 | if (val != .none) try self.func_inst_table.putNoClobber(self.gpa, inst.toRef(), val); | |
| 5094 | 5094 | } |
| 5095 | 5095 | } |
| 5096 | 5096 | |
| ... | ... | @@ -5103,7 +5103,7 @@ pub const FuncGen = struct { |
| 5103 | 5103 | }; |
| 5104 | 5104 | |
| 5105 | 5105 | fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifier) !Builder.Value { |
| 5106 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 5106 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 5107 | 5107 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 5108 | 5108 | const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]); |
| 5109 | 5109 | const o = self.dg.object; |
| ... | ... | @@ -5450,7 +5450,7 @@ pub const FuncGen = struct { |
| 5450 | 5450 | fn airRet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5451 | 5451 | const o = self.dg.object; |
| 5452 | 5452 | const mod = o.module; |
| 5453 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5453 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5454 | 5454 | const ret_ty = self.typeOf(un_op); |
| 5455 | 5455 | if (self.ret_ptr != .none) { |
| 5456 | 5456 | const operand = try self.resolveInst(un_op); |
| ... | ... | @@ -5508,7 +5508,7 @@ pub const FuncGen = struct { |
| 5508 | 5508 | fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5509 | 5509 | const o = self.dg.object; |
| 5510 | 5510 | const mod = o.module; |
| 5511 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5511 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5512 | 5512 | const ptr_ty = self.typeOf(un_op); |
| 5513 | 5513 | const ret_ty = ptr_ty.childType(mod); |
| 5514 | 5514 | const fn_info = mod.typeToFunc(self.dg.decl.ty).?; |
| ... | ... | @@ -5536,9 +5536,9 @@ pub const FuncGen = struct { |
| 5536 | 5536 | |
| 5537 | 5537 | fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5538 | 5538 | const o = self.dg.object; |
| 5539 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5539 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5540 | 5540 | const list = try self.resolveInst(ty_op.operand); |
| 5541 | const arg_ty = self.air.getRefType(ty_op.ty); | |
| 5541 | const arg_ty = ty_op.ty.toType(); | |
| 5542 | 5542 | const llvm_arg_ty = try o.lowerType(arg_ty); |
| 5543 | 5543 | |
| 5544 | 5544 | return self.wip.vaArg(list, llvm_arg_ty, ""); |
| ... | ... | @@ -5546,9 +5546,9 @@ pub const FuncGen = struct { |
| 5546 | 5546 | |
| 5547 | 5547 | fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5548 | 5548 | const o = self.dg.object; |
| 5549 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 5549 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 5550 | 5550 | const src_list = try self.resolveInst(ty_op.operand); |
| 5551 | const va_list_ty = self.air.getRefType(ty_op.ty); | |
| 5551 | const va_list_ty = ty_op.ty.toType(); | |
| 5552 | 5552 | const llvm_va_list_ty = try o.lowerType(va_list_ty); |
| 5553 | 5553 | const mod = o.module; |
| 5554 | 5554 | |
| ... | ... | @@ -5563,7 +5563,7 @@ pub const FuncGen = struct { |
| 5563 | 5563 | } |
| 5564 | 5564 | |
| 5565 | 5565 | fn airCVaEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5566 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5566 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5567 | 5567 | const src_list = try self.resolveInst(un_op); |
| 5568 | 5568 | |
| 5569 | 5569 | _ = try self.wip.callIntrinsic(.normal, .none, .va_end, &.{}, &.{src_list}, ""); |
| ... | ... | @@ -5592,7 +5592,7 @@ pub const FuncGen = struct { |
| 5592 | 5592 | op: math.CompareOperator, |
| 5593 | 5593 | fast: Builder.FastMathKind, |
| 5594 | 5594 | ) !Builder.Value { |
| 5595 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 5595 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 5596 | 5596 | const lhs = try self.resolveInst(bin_op.lhs); |
| 5597 | 5597 | const rhs = try self.resolveInst(bin_op.rhs); |
| 5598 | 5598 | const operand_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -5601,7 +5601,7 @@ pub const FuncGen = struct { |
| 5601 | 5601 | } |
| 5602 | 5602 | |
| 5603 | 5603 | fn airCmpVector(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 5604 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5604 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5605 | 5605 | const extra = self.air.extraData(Air.VectorCmp, ty_pl.payload).data; |
| 5606 | 5606 | |
| 5607 | 5607 | const lhs = try self.resolveInst(extra.lhs); |
| ... | ... | @@ -5614,7 +5614,7 @@ pub const FuncGen = struct { |
| 5614 | 5614 | |
| 5615 | 5615 | fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5616 | 5616 | const o = self.dg.object; |
| 5617 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 5617 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 5618 | 5618 | const operand = try self.resolveInst(un_op); |
| 5619 | 5619 | const llvm_fn = try self.getCmpLtErrorsLenFunction(); |
| 5620 | 5620 | return self.wip.call( |
| ... | ... | @@ -5733,9 +5733,9 @@ pub const FuncGen = struct { |
| 5733 | 5733 | fn airBlock(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5734 | 5734 | const o = self.dg.object; |
| 5735 | 5735 | const mod = o.module; |
| 5736 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5736 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5737 | 5737 | const extra = self.air.extraData(Air.Block, ty_pl.payload); |
| 5738 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 5738 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 5739 | 5739 | const inst_ty = self.typeOfIndex(inst); |
| 5740 | 5740 | |
| 5741 | 5741 | if (inst_ty.isNoReturn(mod)) { |
| ... | ... | @@ -5785,7 +5785,7 @@ pub const FuncGen = struct { |
| 5785 | 5785 | |
| 5786 | 5786 | fn airBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5787 | 5787 | const o = self.dg.object; |
| 5788 | const branch = self.air.instructions.items(.data)[inst].br; | |
| 5788 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 5789 | 5789 | const block = self.blocks.get(branch.block_inst).?; |
| 5790 | 5790 | |
| 5791 | 5791 | // Add the values to the lists only if the break provides a value. |
| ... | ... | @@ -5803,11 +5803,11 @@ pub const FuncGen = struct { |
| 5803 | 5803 | } |
| 5804 | 5804 | |
| 5805 | 5805 | fn airCondBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5806 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 5806 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 5807 | 5807 | const cond = try self.resolveInst(pl_op.operand); |
| 5808 | 5808 | const extra = self.air.extraData(Air.CondBr, pl_op.payload); |
| 5809 | const then_body = self.air.extra[extra.end..][0..extra.data.then_body_len]; | |
| 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]); | |
| 5811 | 5811 | |
| 5812 | 5812 | const then_block = try self.wip.block(1, "Then"); |
| 5813 | 5813 | const else_block = try self.wip.block(1, "Else"); |
| ... | ... | @@ -5827,10 +5827,10 @@ pub const FuncGen = struct { |
| 5827 | 5827 | const o = self.dg.object; |
| 5828 | 5828 | const mod = o.module; |
| 5829 | 5829 | const inst = body_tail[0]; |
| 5830 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 5830 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 5831 | 5831 | const err_union = try self.resolveInst(pl_op.operand); |
| 5832 | 5832 | const extra = self.air.extraData(Air.Try, pl_op.payload); |
| 5833 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 5833 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 5834 | 5834 | const err_union_ty = self.typeOf(pl_op.operand); |
| 5835 | 5835 | const payload_ty = self.typeOfIndex(inst); |
| 5836 | 5836 | const can_elide_load = if (isByRef(payload_ty, mod)) self.canElideLoad(body_tail) else false; |
| ... | ... | @@ -5841,10 +5841,10 @@ pub const FuncGen = struct { |
| 5841 | 5841 | fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5842 | 5842 | const o = self.dg.object; |
| 5843 | 5843 | const mod = o.module; |
| 5844 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5844 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5845 | 5845 | const extra = self.air.extraData(Air.TryPtr, ty_pl.payload); |
| 5846 | 5846 | const err_union_ptr = try self.resolveInst(extra.data.ptr); |
| 5847 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 5847 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 5848 | 5848 | const err_union_ty = self.typeOf(extra.data.ptr).childType(mod); |
| 5849 | 5849 | const is_unused = self.liveness.isUnused(inst); |
| 5850 | 5850 | return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused); |
| ... | ... | @@ -5924,7 +5924,7 @@ pub const FuncGen = struct { |
| 5924 | 5924 | |
| 5925 | 5925 | fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5926 | 5926 | const o = self.dg.object; |
| 5927 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 5927 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 5928 | 5928 | const cond = try self.resolveInst(pl_op.operand); |
| 5929 | 5929 | const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload); |
| 5930 | 5930 | const else_block = try self.wip.block(1, "Default"); |
| ... | ... | @@ -5956,7 +5956,7 @@ pub const FuncGen = struct { |
| 5956 | 5956 | const case = self.air.extraData(Air.SwitchBr.Case, extra_index); |
| 5957 | 5957 | const items: []const Air.Inst.Ref = |
| 5958 | 5958 | @ptrCast(self.air.extra[case.end..][0..case.data.items_len]); |
| 5959 | const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len]; | |
| 5959 | const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]); | |
| 5960 | 5960 | extra_index = case.end + case.data.items_len + case_body.len; |
| 5961 | 5961 | |
| 5962 | 5962 | const case_block = try self.wip.block(@intCast(items.len), "Case"); |
| ... | ... | @@ -5975,7 +5975,7 @@ pub const FuncGen = struct { |
| 5975 | 5975 | } |
| 5976 | 5976 | |
| 5977 | 5977 | self.wip.cursor = .{ .block = else_block }; |
| 5978 | const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len]; | |
| 5978 | const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]); | |
| 5979 | 5979 | if (else_body.len != 0) { |
| 5980 | 5980 | try self.genBody(else_body); |
| 5981 | 5981 | } else { |
| ... | ... | @@ -5989,9 +5989,9 @@ pub const FuncGen = struct { |
| 5989 | 5989 | fn airLoop(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5990 | 5990 | const o = self.dg.object; |
| 5991 | 5991 | const mod = o.module; |
| 5992 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 5992 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 5993 | 5993 | const loop = self.air.extraData(Air.Block, ty_pl.payload); |
| 5994 | const body = self.air.extra[loop.end..][0..loop.data.body_len]; | |
| 5994 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]); | |
| 5995 | 5995 | const loop_block = try self.wip.block(2, "Loop"); |
| 5996 | 5996 | _ = try self.wip.br(loop_block); |
| 5997 | 5997 | |
| ... | ... | @@ -6013,7 +6013,7 @@ pub const FuncGen = struct { |
| 6013 | 6013 | fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6014 | 6014 | const o = self.dg.object; |
| 6015 | 6015 | const mod = o.module; |
| 6016 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6016 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6017 | 6017 | const operand_ty = self.typeOf(ty_op.operand); |
| 6018 | 6018 | const array_ty = operand_ty.childType(mod); |
| 6019 | 6019 | const llvm_usize = try o.lowerType(Type.usize); |
| ... | ... | @@ -6031,7 +6031,7 @@ pub const FuncGen = struct { |
| 6031 | 6031 | fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6032 | 6032 | const o = self.dg.object; |
| 6033 | 6033 | const mod = o.module; |
| 6034 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6034 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6035 | 6035 | |
| 6036 | 6036 | const workaround_operand = try self.resolveInst(ty_op.operand); |
| 6037 | 6037 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -6116,7 +6116,7 @@ pub const FuncGen = struct { |
| 6116 | 6116 | const o = self.dg.object; |
| 6117 | 6117 | const mod = o.module; |
| 6118 | 6118 | const target = mod.getTarget(); |
| 6119 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6119 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6120 | 6120 | |
| 6121 | 6121 | const operand = try self.resolveInst(ty_op.operand); |
| 6122 | 6122 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -6203,7 +6203,7 @@ pub const FuncGen = struct { |
| 6203 | 6203 | } |
| 6204 | 6204 | |
| 6205 | 6205 | fn airSliceField(self: *FuncGen, inst: Air.Inst.Index, index: u32) !Builder.Value { |
| 6206 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6206 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6207 | 6207 | const operand = try self.resolveInst(ty_op.operand); |
| 6208 | 6208 | return self.wip.extractValue(operand, &.{index}, ""); |
| 6209 | 6209 | } |
| ... | ... | @@ -6211,7 +6211,7 @@ pub const FuncGen = struct { |
| 6211 | 6211 | fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value { |
| 6212 | 6212 | const o = self.dg.object; |
| 6213 | 6213 | const mod = o.module; |
| 6214 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6214 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6215 | 6215 | const slice_ptr = try self.resolveInst(ty_op.operand); |
| 6216 | 6216 | const slice_ptr_ty = self.typeOf(ty_op.operand); |
| 6217 | 6217 | const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(mod)); |
| ... | ... | @@ -6223,7 +6223,7 @@ pub const FuncGen = struct { |
| 6223 | 6223 | const o = self.dg.object; |
| 6224 | 6224 | const mod = o.module; |
| 6225 | 6225 | const inst = body_tail[0]; |
| 6226 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 6226 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6227 | 6227 | const slice_ty = self.typeOf(bin_op.lhs); |
| 6228 | 6228 | const slice = try self.resolveInst(bin_op.lhs); |
| 6229 | 6229 | const index = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -6245,7 +6245,7 @@ pub const FuncGen = struct { |
| 6245 | 6245 | fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6246 | 6246 | const o = self.dg.object; |
| 6247 | 6247 | const mod = o.module; |
| 6248 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6248 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6249 | 6249 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6250 | 6250 | const slice_ty = self.typeOf(bin_op.lhs); |
| 6251 | 6251 | |
| ... | ... | @@ -6261,7 +6261,7 @@ pub const FuncGen = struct { |
| 6261 | 6261 | const mod = o.module; |
| 6262 | 6262 | const inst = body_tail[0]; |
| 6263 | 6263 | |
| 6264 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 6264 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6265 | 6265 | const array_ty = self.typeOf(bin_op.lhs); |
| 6266 | 6266 | const array_llvm_val = try self.resolveInst(bin_op.lhs); |
| 6267 | 6267 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -6278,12 +6278,12 @@ pub const FuncGen = struct { |
| 6278 | 6278 | const elem_alignment = elem_ty.abiAlignment(mod).toLlvm(); |
| 6279 | 6279 | return self.loadByRef(elem_ptr, elem_ty, elem_alignment, .normal); |
| 6280 | 6280 | } 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)]; | |
| 6284 | 6284 | 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)]; | |
| 6287 | 6287 | switch (load_ptr_tag) { |
| 6288 | 6288 | .struct_field_ptr, |
| 6289 | 6289 | .struct_field_ptr_index_0, |
| ... | ... | @@ -6320,7 +6320,7 @@ pub const FuncGen = struct { |
| 6320 | 6320 | const o = self.dg.object; |
| 6321 | 6321 | const mod = o.module; |
| 6322 | 6322 | const inst = body_tail[0]; |
| 6323 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 6323 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 6324 | 6324 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 6325 | 6325 | const elem_ty = ptr_ty.childType(mod); |
| 6326 | 6326 | const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty); |
| ... | ... | @@ -6344,7 +6344,7 @@ pub const FuncGen = struct { |
| 6344 | 6344 | fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6345 | 6345 | const o = self.dg.object; |
| 6346 | 6346 | const mod = o.module; |
| 6347 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6347 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6348 | 6348 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6349 | 6349 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 6350 | 6350 | const elem_ty = ptr_ty.childType(mod); |
| ... | ... | @@ -6353,7 +6353,7 @@ pub const FuncGen = struct { |
| 6353 | 6353 | const base_ptr = try self.resolveInst(bin_op.lhs); |
| 6354 | 6354 | const rhs = try self.resolveInst(bin_op.rhs); |
| 6355 | 6355 | |
| 6356 | const elem_ptr = self.air.getRefType(ty_pl.ty); | |
| 6356 | const elem_ptr = ty_pl.ty.toType(); | |
| 6357 | 6357 | if (elem_ptr.ptrInfo(mod).flags.vector_index != .none) return base_ptr; |
| 6358 | 6358 | |
| 6359 | 6359 | const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty); |
| ... | ... | @@ -6365,7 +6365,7 @@ pub const FuncGen = struct { |
| 6365 | 6365 | } |
| 6366 | 6366 | |
| 6367 | 6367 | fn airStructFieldPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6368 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6368 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6369 | 6369 | const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 6370 | 6370 | const struct_ptr = try self.resolveInst(struct_field.struct_operand); |
| 6371 | 6371 | const struct_ptr_ty = self.typeOf(struct_field.struct_operand); |
| ... | ... | @@ -6377,7 +6377,7 @@ pub const FuncGen = struct { |
| 6377 | 6377 | inst: Air.Inst.Index, |
| 6378 | 6378 | field_index: u32, |
| 6379 | 6379 | ) !Builder.Value { |
| 6380 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6380 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6381 | 6381 | const struct_ptr = try self.resolveInst(ty_op.operand); |
| 6382 | 6382 | const struct_ptr_ty = self.typeOf(ty_op.operand); |
| 6383 | 6383 | return self.fieldPtr(inst, struct_ptr, struct_ptr_ty, field_index); |
| ... | ... | @@ -6387,7 +6387,7 @@ pub const FuncGen = struct { |
| 6387 | 6387 | const o = self.dg.object; |
| 6388 | 6388 | const mod = o.module; |
| 6389 | 6389 | const inst = body_tail[0]; |
| 6390 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6390 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6391 | 6391 | const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 6392 | 6392 | const struct_ty = self.typeOf(struct_field.struct_operand); |
| 6393 | 6393 | const struct_llvm_val = try self.resolveInst(struct_field.struct_operand); |
| ... | ... | @@ -6491,16 +6491,16 @@ pub const FuncGen = struct { |
| 6491 | 6491 | fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6492 | 6492 | const o = self.dg.object; |
| 6493 | 6493 | const mod = o.module; |
| 6494 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6494 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6495 | 6495 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 6496 | 6496 | |
| 6497 | 6497 | const field_ptr = try self.resolveInst(extra.field_ptr); |
| 6498 | 6498 | |
| 6499 | const parent_ty = self.air.getRefType(ty_pl.ty).childType(mod); | |
| 6499 | const parent_ty = ty_pl.ty.toType().childType(mod); | |
| 6500 | 6500 | const field_offset = parent_ty.structFieldOffset(extra.field_index, mod); |
| 6501 | 6501 | if (field_offset == 0) return field_ptr; |
| 6502 | 6502 | |
| 6503 | const res_ty = try o.lowerType(self.air.getRefType(ty_pl.ty)); | |
| 6503 | const res_ty = try o.lowerType(ty_pl.ty.toType()); | |
| 6504 | 6504 | const llvm_usize = try o.lowerType(Type.usize); |
| 6505 | 6505 | |
| 6506 | 6506 | const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, ""); |
| ... | ... | @@ -6514,7 +6514,7 @@ pub const FuncGen = struct { |
| 6514 | 6514 | } |
| 6515 | 6515 | |
| 6516 | 6516 | fn airNot(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6517 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 6517 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 6518 | 6518 | const operand = try self.resolveInst(ty_op.operand); |
| 6519 | 6519 | |
| 6520 | 6520 | return self.wip.not(operand, ""); |
| ... | ... | @@ -6528,7 +6528,7 @@ pub const FuncGen = struct { |
| 6528 | 6528 | |
| 6529 | 6529 | fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6530 | 6530 | const di_scope = self.di_scope orelse return .none; |
| 6531 | const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt; | |
| 6531 | const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; | |
| 6532 | 6532 | self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1); |
| 6533 | 6533 | self.prev_dbg_column = @intCast(dbg_stmt.column + 1); |
| 6534 | 6534 | const inlined_at = if (self.dbg_inlined.items.len > 0) |
| ... | ... | @@ -6547,7 +6547,7 @@ pub const FuncGen = struct { |
| 6547 | 6547 | fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6548 | 6548 | const o = self.dg.object; |
| 6549 | 6549 | const dib = o.di_builder orelse return .none; |
| 6550 | const ty_fn = self.air.instructions.items(.data)[inst].ty_fn; | |
| 6550 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 6551 | 6551 | |
| 6552 | 6552 | const mod = o.module; |
| 6553 | 6553 | const func = mod.funcInfo(ty_fn.func); |
| ... | ... | @@ -6596,7 +6596,7 @@ pub const FuncGen = struct { |
| 6596 | 6596 | fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6597 | 6597 | const o = self.dg.object; |
| 6598 | 6598 | if (o.di_builder == null) return .none; |
| 6599 | const ty_fn = self.air.instructions.items(.data)[inst].ty_fn; | |
| 6599 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 6600 | 6600 | |
| 6601 | 6601 | const mod = o.module; |
| 6602 | 6602 | const decl = mod.funcOwnerDeclPtr(ty_fn.func); |
| ... | ... | @@ -6629,7 +6629,7 @@ pub const FuncGen = struct { |
| 6629 | 6629 | const o = self.dg.object; |
| 6630 | 6630 | const mod = o.module; |
| 6631 | 6631 | const dib = o.di_builder orelse return .none; |
| 6632 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 6632 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6633 | 6633 | const operand = try self.resolveInst(pl_op.operand); |
| 6634 | 6634 | const name = self.air.nullTerminatedString(pl_op.payload); |
| 6635 | 6635 | const ptr_ty = self.typeOf(pl_op.operand); |
| ... | ... | @@ -6656,7 +6656,7 @@ pub const FuncGen = struct { |
| 6656 | 6656 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6657 | 6657 | const o = self.dg.object; |
| 6658 | 6658 | const dib = o.di_builder orelse return .none; |
| 6659 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 6659 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 6660 | 6660 | const operand = try self.resolveInst(pl_op.operand); |
| 6661 | 6661 | const operand_ty = self.typeOf(pl_op.operand); |
| 6662 | 6662 | const name = self.air.nullTerminatedString(pl_op.payload); |
| ... | ... | @@ -6700,7 +6700,7 @@ pub const FuncGen = struct { |
| 6700 | 6700 | // this implementation feeds the inline assembly code directly to LLVM. |
| 6701 | 6701 | |
| 6702 | 6702 | const o = self.dg.object; |
| 6703 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 6703 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 6704 | 6704 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); |
| 6705 | 6705 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; |
| 6706 | 6706 | const clobbers_len: u31 = @truncate(extra.data.flags); |
| ... | ... | @@ -7081,7 +7081,7 @@ pub const FuncGen = struct { |
| 7081 | 7081 | ) !Builder.Value { |
| 7082 | 7082 | const o = self.dg.object; |
| 7083 | 7083 | const mod = o.module; |
| 7084 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 7084 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 7085 | 7085 | const operand = try self.resolveInst(un_op); |
| 7086 | 7086 | const operand_ty = self.typeOf(un_op); |
| 7087 | 7087 | const optional_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty; |
| ... | ... | @@ -7125,7 +7125,7 @@ pub const FuncGen = struct { |
| 7125 | 7125 | ) !Builder.Value { |
| 7126 | 7126 | const o = self.dg.object; |
| 7127 | 7127 | const mod = o.module; |
| 7128 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 7128 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 7129 | 7129 | const operand = try self.resolveInst(un_op); |
| 7130 | 7130 | const operand_ty = self.typeOf(un_op); |
| 7131 | 7131 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty; |
| ... | ... | @@ -7164,7 +7164,7 @@ pub const FuncGen = struct { |
| 7164 | 7164 | fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7165 | 7165 | const o = self.dg.object; |
| 7166 | 7166 | const mod = o.module; |
| 7167 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7167 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7168 | 7168 | const operand = try self.resolveInst(ty_op.operand); |
| 7169 | 7169 | const optional_ty = self.typeOf(ty_op.operand).childType(mod); |
| 7170 | 7170 | const payload_ty = optional_ty.optionalChild(mod); |
| ... | ... | @@ -7185,7 +7185,7 @@ pub const FuncGen = struct { |
| 7185 | 7185 | |
| 7186 | 7186 | const o = self.dg.object; |
| 7187 | 7187 | const mod = o.module; |
| 7188 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7188 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7189 | 7189 | const operand = try self.resolveInst(ty_op.operand); |
| 7190 | 7190 | const optional_ty = self.typeOf(ty_op.operand).childType(mod); |
| 7191 | 7191 | const payload_ty = optional_ty.optionalChild(mod); |
| ... | ... | @@ -7217,7 +7217,7 @@ pub const FuncGen = struct { |
| 7217 | 7217 | const o = self.dg.object; |
| 7218 | 7218 | const mod = o.module; |
| 7219 | 7219 | const inst = body_tail[0]; |
| 7220 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7220 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7221 | 7221 | const operand = try self.resolveInst(ty_op.operand); |
| 7222 | 7222 | const optional_ty = self.typeOf(ty_op.operand); |
| 7223 | 7223 | const payload_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7241,7 +7241,7 @@ pub const FuncGen = struct { |
| 7241 | 7241 | const o = self.dg.object; |
| 7242 | 7242 | const mod = o.module; |
| 7243 | 7243 | const inst = body_tail[0]; |
| 7244 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7244 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7245 | 7245 | const operand = try self.resolveInst(ty_op.operand); |
| 7246 | 7246 | const operand_ty = self.typeOf(ty_op.operand); |
| 7247 | 7247 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty; |
| ... | ... | @@ -7275,7 +7275,7 @@ pub const FuncGen = struct { |
| 7275 | 7275 | ) !Builder.Value { |
| 7276 | 7276 | const o = self.dg.object; |
| 7277 | 7277 | const mod = o.module; |
| 7278 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7278 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7279 | 7279 | const operand = try self.resolveInst(ty_op.operand); |
| 7280 | 7280 | const operand_ty = self.typeOf(ty_op.operand); |
| 7281 | 7281 | const error_type = try o.errorIntType(); |
| ... | ... | @@ -7308,7 +7308,7 @@ pub const FuncGen = struct { |
| 7308 | 7308 | fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7309 | 7309 | const o = self.dg.object; |
| 7310 | 7310 | const mod = o.module; |
| 7311 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7311 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7312 | 7312 | const operand = try self.resolveInst(ty_op.operand); |
| 7313 | 7313 | const err_union_ty = self.typeOf(ty_op.operand).childType(mod); |
| 7314 | 7314 | |
| ... | ... | @@ -7340,15 +7340,15 @@ pub const FuncGen = struct { |
| 7340 | 7340 | } |
| 7341 | 7341 | |
| 7342 | 7342 | fn airSetErrReturnTrace(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7343 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 7343 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 7344 | 7344 | self.err_ret_trace = try self.resolveInst(un_op); |
| 7345 | 7345 | return .none; |
| 7346 | 7346 | } |
| 7347 | 7347 | |
| 7348 | 7348 | fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7349 | 7349 | 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(); | |
| 7352 | 7352 | const field_index = ty_pl.payload; |
| 7353 | 7353 | |
| 7354 | 7354 | const mod = o.module; |
| ... | ... | @@ -7378,7 +7378,7 @@ pub const FuncGen = struct { |
| 7378 | 7378 | ) bool { |
| 7379 | 7379 | const air_tags = self.air.instructions.items(.tag); |
| 7380 | 7380 | for (body_tail[1..]) |body_inst| { |
| 7381 | switch (air_tags[body_inst]) { | |
| 7381 | switch (air_tags[@intFromEnum(body_inst)]) { | |
| 7382 | 7382 | .ret => return true, |
| 7383 | 7383 | .dbg_block_begin, .dbg_stmt => continue, |
| 7384 | 7384 | else => return false, |
| ... | ... | @@ -7393,7 +7393,7 @@ pub const FuncGen = struct { |
| 7393 | 7393 | const o = self.dg.object; |
| 7394 | 7394 | const mod = o.module; |
| 7395 | 7395 | const inst = body_tail[0]; |
| 7396 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7396 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7397 | 7397 | const payload_ty = self.typeOf(ty_op.operand); |
| 7398 | 7398 | const non_null_bit = try o.builder.intValue(.i8, 1); |
| 7399 | 7399 | comptime assert(optional_layout_version == 3); |
| ... | ... | @@ -7426,7 +7426,7 @@ pub const FuncGen = struct { |
| 7426 | 7426 | const o = self.dg.object; |
| 7427 | 7427 | const mod = o.module; |
| 7428 | 7428 | const inst = body_tail[0]; |
| 7429 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7429 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7430 | 7430 | const err_un_ty = self.typeOfIndex(inst); |
| 7431 | 7431 | const operand = try self.resolveInst(ty_op.operand); |
| 7432 | 7432 | const payload_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -7467,7 +7467,7 @@ pub const FuncGen = struct { |
| 7467 | 7467 | const o = self.dg.object; |
| 7468 | 7468 | const mod = o.module; |
| 7469 | 7469 | const inst = body_tail[0]; |
| 7470 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 7470 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 7471 | 7471 | const err_un_ty = self.typeOfIndex(inst); |
| 7472 | 7472 | const payload_ty = err_un_ty.errorUnionPayload(mod); |
| 7473 | 7473 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -7505,7 +7505,7 @@ pub const FuncGen = struct { |
| 7505 | 7505 | |
| 7506 | 7506 | fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7507 | 7507 | const o = self.dg.object; |
| 7508 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 7508 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 7509 | 7509 | const index = pl_op.payload; |
| 7510 | 7510 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{.i32}, &.{ |
| 7511 | 7511 | try o.builder.intValue(.i32, index), |
| ... | ... | @@ -7514,7 +7514,7 @@ pub const FuncGen = struct { |
| 7514 | 7514 | |
| 7515 | 7515 | fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7516 | 7516 | const o = self.dg.object; |
| 7517 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 7517 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 7518 | 7518 | const index = pl_op.payload; |
| 7519 | 7519 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{.i32}, &.{ |
| 7520 | 7520 | try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand), |
| ... | ... | @@ -7524,7 +7524,7 @@ pub const FuncGen = struct { |
| 7524 | 7524 | fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7525 | 7525 | const o = self.dg.object; |
| 7526 | 7526 | const mod = o.module; |
| 7527 | const data = self.air.instructions.items(.data)[inst].vector_store_elem; | |
| 7527 | const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem; | |
| 7528 | 7528 | const extra = self.air.extraData(Air.Bin, data.payload).data; |
| 7529 | 7529 | |
| 7530 | 7530 | const vector_ptr = try self.resolveInst(data.vector_ptr); |
| ... | ... | @@ -7546,7 +7546,7 @@ pub const FuncGen = struct { |
| 7546 | 7546 | fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7547 | 7547 | const o = self.dg.object; |
| 7548 | 7548 | const mod = o.module; |
| 7549 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7549 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7550 | 7550 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7551 | 7551 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7552 | 7552 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7566,7 +7566,7 @@ pub const FuncGen = struct { |
| 7566 | 7566 | fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7567 | 7567 | const o = self.dg.object; |
| 7568 | 7568 | const mod = o.module; |
| 7569 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7569 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7570 | 7570 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7571 | 7571 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7572 | 7572 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7585,7 +7585,7 @@ pub const FuncGen = struct { |
| 7585 | 7585 | |
| 7586 | 7586 | fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7587 | 7587 | const o = self.dg.object; |
| 7588 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 7588 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 7589 | 7589 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 7590 | 7590 | const ptr = try self.resolveInst(bin_op.lhs); |
| 7591 | 7591 | const len = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -7596,7 +7596,7 @@ pub const FuncGen = struct { |
| 7596 | 7596 | fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 7597 | 7597 | const o = self.dg.object; |
| 7598 | 7598 | const mod = o.module; |
| 7599 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7599 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7600 | 7600 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7601 | 7601 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7602 | 7602 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7615,7 +7615,7 @@ pub const FuncGen = struct { |
| 7615 | 7615 | const o = fg.dg.object; |
| 7616 | 7616 | const mod = o.module; |
| 7617 | 7617 | |
| 7618 | const bin_op = fg.air.instructions.items(.data)[inst].bin_op; | |
| 7618 | const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7619 | 7619 | const lhs = try fg.resolveInst(bin_op.lhs); |
| 7620 | 7620 | const rhs = try fg.resolveInst(bin_op.rhs); |
| 7621 | 7621 | const inst_ty = fg.typeOfIndex(inst); |
| ... | ... | @@ -7652,7 +7652,7 @@ pub const FuncGen = struct { |
| 7652 | 7652 | } |
| 7653 | 7653 | |
| 7654 | 7654 | fn airAddWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7655 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7655 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7656 | 7656 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7657 | 7657 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7658 | 7658 | |
| ... | ... | @@ -7662,7 +7662,7 @@ pub const FuncGen = struct { |
| 7662 | 7662 | fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7663 | 7663 | const o = self.dg.object; |
| 7664 | 7664 | const mod = o.module; |
| 7665 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7665 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7666 | 7666 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7667 | 7667 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7668 | 7668 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7682,7 +7682,7 @@ pub const FuncGen = struct { |
| 7682 | 7682 | fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 7683 | 7683 | const o = self.dg.object; |
| 7684 | 7684 | const mod = o.module; |
| 7685 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7685 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7686 | 7686 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7687 | 7687 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7688 | 7688 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7693,7 +7693,7 @@ pub const FuncGen = struct { |
| 7693 | 7693 | } |
| 7694 | 7694 | |
| 7695 | 7695 | fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7696 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7696 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7697 | 7697 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7698 | 7698 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7699 | 7699 | |
| ... | ... | @@ -7703,7 +7703,7 @@ pub const FuncGen = struct { |
| 7703 | 7703 | fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7704 | 7704 | const o = self.dg.object; |
| 7705 | 7705 | const mod = o.module; |
| 7706 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7706 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7707 | 7707 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7708 | 7708 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7709 | 7709 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7723,7 +7723,7 @@ pub const FuncGen = struct { |
| 7723 | 7723 | fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 7724 | 7724 | const o = self.dg.object; |
| 7725 | 7725 | const mod = o.module; |
| 7726 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7726 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7727 | 7727 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7728 | 7728 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7729 | 7729 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7734,7 +7734,7 @@ pub const FuncGen = struct { |
| 7734 | 7734 | } |
| 7735 | 7735 | |
| 7736 | 7736 | fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7737 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7737 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7738 | 7738 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7739 | 7739 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7740 | 7740 | |
| ... | ... | @@ -7744,7 +7744,7 @@ pub const FuncGen = struct { |
| 7744 | 7744 | fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7745 | 7745 | const o = self.dg.object; |
| 7746 | 7746 | const mod = o.module; |
| 7747 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7747 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7748 | 7748 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7749 | 7749 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7750 | 7750 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7762,7 +7762,7 @@ pub const FuncGen = struct { |
| 7762 | 7762 | } |
| 7763 | 7763 | |
| 7764 | 7764 | fn airDivFloat(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 7765 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7765 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7766 | 7766 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7767 | 7767 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7768 | 7768 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7773,7 +7773,7 @@ pub const FuncGen = struct { |
| 7773 | 7773 | fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 7774 | 7774 | const o = self.dg.object; |
| 7775 | 7775 | const mod = o.module; |
| 7776 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7776 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7777 | 7777 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7778 | 7778 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7779 | 7779 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7789,7 +7789,7 @@ pub const FuncGen = struct { |
| 7789 | 7789 | fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 7790 | 7790 | const o = self.dg.object; |
| 7791 | 7791 | const mod = o.module; |
| 7792 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7792 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7793 | 7793 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7794 | 7794 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7795 | 7795 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7821,7 +7821,7 @@ pub const FuncGen = struct { |
| 7821 | 7821 | fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 7822 | 7822 | const o = self.dg.object; |
| 7823 | 7823 | const mod = o.module; |
| 7824 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7824 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7825 | 7825 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7826 | 7826 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7827 | 7827 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7839,7 +7839,7 @@ pub const FuncGen = struct { |
| 7839 | 7839 | fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 7840 | 7840 | const o = self.dg.object; |
| 7841 | 7841 | const mod = o.module; |
| 7842 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7842 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7843 | 7843 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7844 | 7844 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7845 | 7845 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7856,7 +7856,7 @@ pub const FuncGen = struct { |
| 7856 | 7856 | fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 7857 | 7857 | const o = self.dg.object; |
| 7858 | 7858 | const mod = o.module; |
| 7859 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 7859 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 7860 | 7860 | const lhs = try self.resolveInst(bin_op.lhs); |
| 7861 | 7861 | const rhs = try self.resolveInst(bin_op.rhs); |
| 7862 | 7862 | const inst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -7892,7 +7892,7 @@ pub const FuncGen = struct { |
| 7892 | 7892 | fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7893 | 7893 | const o = self.dg.object; |
| 7894 | 7894 | const mod = o.module; |
| 7895 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 7895 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 7896 | 7896 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 7897 | 7897 | const ptr = try self.resolveInst(bin_op.lhs); |
| 7898 | 7898 | const offset = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -7914,7 +7914,7 @@ pub const FuncGen = struct { |
| 7914 | 7914 | fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7915 | 7915 | const o = self.dg.object; |
| 7916 | 7916 | const mod = o.module; |
| 7917 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 7917 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 7918 | 7918 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 7919 | 7919 | const ptr = try self.resolveInst(bin_op.lhs); |
| 7920 | 7920 | const offset = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -7942,7 +7942,7 @@ pub const FuncGen = struct { |
| 7942 | 7942 | ) !Builder.Value { |
| 7943 | 7943 | const o = self.dg.object; |
| 7944 | 7944 | const mod = o.module; |
| 7945 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 7945 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 7946 | 7946 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 7947 | 7947 | |
| 7948 | 7948 | const lhs = try self.resolveInst(extra.lhs); |
| ... | ... | @@ -8283,7 +8283,7 @@ pub const FuncGen = struct { |
| 8283 | 8283 | } |
| 8284 | 8284 | |
| 8285 | 8285 | fn airMulAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8286 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 8286 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 8287 | 8287 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 8288 | 8288 | |
| 8289 | 8289 | const mulend1 = try self.resolveInst(extra.lhs); |
| ... | ... | @@ -8297,7 +8297,7 @@ pub const FuncGen = struct { |
| 8297 | 8297 | fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8298 | 8298 | const o = self.dg.object; |
| 8299 | 8299 | const mod = o.module; |
| 8300 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 8300 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 8301 | 8301 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8302 | 8302 | |
| 8303 | 8303 | const lhs = try self.resolveInst(extra.lhs); |
| ... | ... | @@ -8344,21 +8344,21 @@ pub const FuncGen = struct { |
| 8344 | 8344 | } |
| 8345 | 8345 | |
| 8346 | 8346 | fn airAnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8347 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 8347 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 8348 | 8348 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8349 | 8349 | const rhs = try self.resolveInst(bin_op.rhs); |
| 8350 | 8350 | return self.wip.bin(.@"and", lhs, rhs, ""); |
| 8351 | 8351 | } |
| 8352 | 8352 | |
| 8353 | 8353 | fn airOr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8354 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 8354 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 8355 | 8355 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8356 | 8356 | const rhs = try self.resolveInst(bin_op.rhs); |
| 8357 | 8357 | return self.wip.bin(.@"or", lhs, rhs, ""); |
| 8358 | 8358 | } |
| 8359 | 8359 | |
| 8360 | 8360 | fn airXor(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8361 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 8361 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 8362 | 8362 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8363 | 8363 | const rhs = try self.resolveInst(bin_op.rhs); |
| 8364 | 8364 | return self.wip.bin(.xor, lhs, rhs, ""); |
| ... | ... | @@ -8367,7 +8367,7 @@ pub const FuncGen = struct { |
| 8367 | 8367 | fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8368 | 8368 | const o = self.dg.object; |
| 8369 | 8369 | const mod = o.module; |
| 8370 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 8370 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 8371 | 8371 | |
| 8372 | 8372 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8373 | 8373 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8384,7 +8384,7 @@ pub const FuncGen = struct { |
| 8384 | 8384 | |
| 8385 | 8385 | fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8386 | 8386 | const o = self.dg.object; |
| 8387 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 8387 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 8388 | 8388 | |
| 8389 | 8389 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8390 | 8390 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8398,7 +8398,7 @@ pub const FuncGen = struct { |
| 8398 | 8398 | fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8399 | 8399 | const o = self.dg.object; |
| 8400 | 8400 | const mod = o.module; |
| 8401 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 8401 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 8402 | 8402 | |
| 8403 | 8403 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8404 | 8404 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8440,7 +8440,7 @@ pub const FuncGen = struct { |
| 8440 | 8440 | fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value { |
| 8441 | 8441 | const o = self.dg.object; |
| 8442 | 8442 | const mod = o.module; |
| 8443 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 8443 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 8444 | 8444 | |
| 8445 | 8445 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8446 | 8446 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8459,7 +8459,7 @@ pub const FuncGen = struct { |
| 8459 | 8459 | fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8460 | 8460 | const o = self.dg.object; |
| 8461 | 8461 | const mod = o.module; |
| 8462 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 8462 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 8463 | 8463 | const operand = try self.resolveInst(ty_op.operand); |
| 8464 | 8464 | const operand_ty = self.typeOf(ty_op.operand); |
| 8465 | 8465 | const scalar_ty = operand_ty.scalarType(mod); |
| ... | ... | @@ -8481,7 +8481,7 @@ pub const FuncGen = struct { |
| 8481 | 8481 | fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8482 | 8482 | const o = self.dg.object; |
| 8483 | 8483 | const mod = o.module; |
| 8484 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 8484 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 8485 | 8485 | const dest_ty = self.typeOfIndex(inst); |
| 8486 | 8486 | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 8487 | 8487 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -8496,7 +8496,7 @@ pub const FuncGen = struct { |
| 8496 | 8496 | |
| 8497 | 8497 | fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8498 | 8498 | const o = self.dg.object; |
| 8499 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 8499 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 8500 | 8500 | const operand = try self.resolveInst(ty_op.operand); |
| 8501 | 8501 | const dest_llvm_ty = try o.lowerType(self.typeOfIndex(inst)); |
| 8502 | 8502 | return self.wip.cast(.trunc, operand, dest_llvm_ty, ""); |
| ... | ... | @@ -8505,7 +8505,7 @@ pub const FuncGen = struct { |
| 8505 | 8505 | fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8506 | 8506 | const o = self.dg.object; |
| 8507 | 8507 | const mod = o.module; |
| 8508 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 8508 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 8509 | 8509 | const operand = try self.resolveInst(ty_op.operand); |
| 8510 | 8510 | const operand_ty = self.typeOf(ty_op.operand); |
| 8511 | 8511 | const dest_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -8539,7 +8539,7 @@ pub const FuncGen = struct { |
| 8539 | 8539 | fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8540 | 8540 | const o = self.dg.object; |
| 8541 | 8541 | const mod = o.module; |
| 8542 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 8542 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 8543 | 8543 | const operand = try self.resolveInst(ty_op.operand); |
| 8544 | 8544 | const operand_ty = self.typeOf(ty_op.operand); |
| 8545 | 8545 | const dest_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -8572,7 +8572,7 @@ pub const FuncGen = struct { |
| 8572 | 8572 | |
| 8573 | 8573 | fn airIntFromPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8574 | 8574 | const o = self.dg.object; |
| 8575 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 8575 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 8576 | 8576 | const operand = try self.resolveInst(un_op); |
| 8577 | 8577 | const ptr_ty = self.typeOf(un_op); |
| 8578 | 8578 | const operand_ptr = try self.sliceOrArrayPtr(operand, ptr_ty); |
| ... | ... | @@ -8581,7 +8581,7 @@ pub const FuncGen = struct { |
| 8581 | 8581 | } |
| 8582 | 8582 | |
| 8583 | 8583 | fn airBitCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8584 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 8584 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 8585 | 8585 | const operand_ty = self.typeOf(ty_op.operand); |
| 8586 | 8586 | const inst_ty = self.typeOfIndex(inst); |
| 8587 | 8587 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -8698,7 +8698,7 @@ pub const FuncGen = struct { |
| 8698 | 8698 | } |
| 8699 | 8699 | |
| 8700 | 8700 | fn airIntFromBool(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8701 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 8701 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 8702 | 8702 | const operand = try self.resolveInst(un_op); |
| 8703 | 8703 | return operand; |
| 8704 | 8704 | } |
| ... | ... | @@ -8713,7 +8713,7 @@ pub const FuncGen = struct { |
| 8713 | 8713 | if (o.di_builder) |dib| { |
| 8714 | 8714 | if (needDbgVarWorkaround(o)) return arg_val; |
| 8715 | 8715 | |
| 8716 | const src_index = self.air.instructions.items(.data)[inst].arg.src_index; | |
| 8716 | const src_index = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.src_index; | |
| 8717 | 8717 | const func_index = self.dg.decl.getOwnedFunctionIndex(); |
| 8718 | 8718 | const func = mod.funcInfo(func_index); |
| 8719 | 8719 | const lbrace_line = mod.declPtr(func.owner_decl).src_line + func.lbrace_line + 1; |
| ... | ... | @@ -8796,7 +8796,7 @@ pub const FuncGen = struct { |
| 8796 | 8796 | fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 8797 | 8797 | const o = self.dg.object; |
| 8798 | 8798 | const mod = o.module; |
| 8799 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 8799 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 8800 | 8800 | const dest_ptr = try self.resolveInst(bin_op.lhs); |
| 8801 | 8801 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 8802 | 8802 | const operand_ty = ptr_ty.childType(mod); |
| ... | ... | @@ -8860,7 +8860,7 @@ pub const FuncGen = struct { |
| 8860 | 8860 | const o = fg.dg.object; |
| 8861 | 8861 | const mod = o.module; |
| 8862 | 8862 | const inst = body_tail[0]; |
| 8863 | const ty_op = fg.air.instructions.items(.data)[inst].ty_op; | |
| 8863 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 8864 | 8864 | const ptr_ty = fg.typeOf(ty_op.operand); |
| 8865 | 8865 | const ptr_info = ptr_ty.ptrInfo(mod); |
| 8866 | 8866 | const ptr = try fg.resolveInst(ty_op.operand); |
| ... | ... | @@ -8910,7 +8910,7 @@ pub const FuncGen = struct { |
| 8910 | 8910 | } |
| 8911 | 8911 | |
| 8912 | 8912 | fn airFence(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8913 | const atomic_order = self.air.instructions.items(.data)[inst].fence; | |
| 8913 | const atomic_order = self.air.instructions.items(.data)[@intFromEnum(inst)].fence; | |
| 8914 | 8914 | const ordering = toLlvmAtomicOrdering(atomic_order); |
| 8915 | 8915 | _ = try self.wip.fence(self.sync_scope, ordering); |
| 8916 | 8916 | return .none; |
| ... | ... | @@ -8923,7 +8923,7 @@ pub const FuncGen = struct { |
| 8923 | 8923 | ) !Builder.Value { |
| 8924 | 8924 | const o = self.dg.object; |
| 8925 | 8925 | const mod = o.module; |
| 8926 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 8926 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 8927 | 8927 | const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 8928 | 8928 | const ptr = try self.resolveInst(extra.ptr); |
| 8929 | 8929 | const ptr_ty = self.typeOf(extra.ptr); |
| ... | ... | @@ -8973,7 +8973,7 @@ pub const FuncGen = struct { |
| 8973 | 8973 | fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8974 | 8974 | const o = self.dg.object; |
| 8975 | 8975 | const mod = o.module; |
| 8976 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 8976 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 8977 | 8977 | const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 8978 | 8978 | const ptr = try self.resolveInst(pl_op.operand); |
| 8979 | 8979 | const ptr_ty = self.typeOf(pl_op.operand); |
| ... | ... | @@ -9036,7 +9036,7 @@ pub const FuncGen = struct { |
| 9036 | 9036 | fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9037 | 9037 | const o = self.dg.object; |
| 9038 | 9038 | const mod = o.module; |
| 9039 | const atomic_load = self.air.instructions.items(.data)[inst].atomic_load; | |
| 9039 | const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; | |
| 9040 | 9040 | const ptr = try self.resolveInst(atomic_load.ptr); |
| 9041 | 9041 | const ptr_ty = self.typeOf(atomic_load.ptr); |
| 9042 | 9042 | const info = ptr_ty.ptrInfo(mod); |
| ... | ... | @@ -9083,7 +9083,7 @@ pub const FuncGen = struct { |
| 9083 | 9083 | ) !Builder.Value { |
| 9084 | 9084 | const o = self.dg.object; |
| 9085 | 9085 | const mod = o.module; |
| 9086 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 9086 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 9087 | 9087 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 9088 | 9088 | const operand_ty = ptr_ty.childType(mod); |
| 9089 | 9089 | if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return .none; |
| ... | ... | @@ -9107,7 +9107,7 @@ pub const FuncGen = struct { |
| 9107 | 9107 | fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9108 | 9108 | const o = self.dg.object; |
| 9109 | 9109 | const mod = o.module; |
| 9110 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 9110 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 9111 | 9111 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| 9112 | 9112 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 9113 | 9113 | const elem_ty = self.typeOf(bin_op.rhs); |
| ... | ... | @@ -9259,7 +9259,7 @@ pub const FuncGen = struct { |
| 9259 | 9259 | fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9260 | 9260 | const o = self.dg.object; |
| 9261 | 9261 | const mod = o.module; |
| 9262 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 9262 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 9263 | 9263 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| 9264 | 9264 | const dest_ptr_ty = self.typeOf(bin_op.lhs); |
| 9265 | 9265 | const src_slice = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -9312,7 +9312,7 @@ pub const FuncGen = struct { |
| 9312 | 9312 | fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9313 | 9313 | const o = self.dg.object; |
| 9314 | 9314 | const mod = o.module; |
| 9315 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 9315 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 9316 | 9316 | const un_ty = self.typeOf(bin_op.lhs).childType(mod); |
| 9317 | 9317 | const layout = un_ty.unionGetLayout(mod); |
| 9318 | 9318 | if (layout.tag_size == 0) return .none; |
| ... | ... | @@ -9333,7 +9333,7 @@ pub const FuncGen = struct { |
| 9333 | 9333 | fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9334 | 9334 | const o = self.dg.object; |
| 9335 | 9335 | const mod = o.module; |
| 9336 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 9336 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 9337 | 9337 | const un_ty = self.typeOf(ty_op.operand); |
| 9338 | 9338 | const layout = un_ty.unionGetLayout(mod); |
| 9339 | 9339 | if (layout.tag_size == 0) return .none; |
| ... | ... | @@ -9354,7 +9354,7 @@ pub const FuncGen = struct { |
| 9354 | 9354 | } |
| 9355 | 9355 | |
| 9356 | 9356 | fn airUnaryOp(self: *FuncGen, inst: Air.Inst.Index, comptime op: FloatOp) !Builder.Value { |
| 9357 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 9357 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 9358 | 9358 | const operand = try self.resolveInst(un_op); |
| 9359 | 9359 | const operand_ty = self.typeOf(un_op); |
| 9360 | 9360 | |
| ... | ... | @@ -9362,7 +9362,7 @@ pub const FuncGen = struct { |
| 9362 | 9362 | } |
| 9363 | 9363 | |
| 9364 | 9364 | fn airNeg(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 9365 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 9365 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 9366 | 9366 | const operand = try self.resolveInst(un_op); |
| 9367 | 9367 | const operand_ty = self.typeOf(un_op); |
| 9368 | 9368 | |
| ... | ... | @@ -9371,7 +9371,7 @@ pub const FuncGen = struct { |
| 9371 | 9371 | |
| 9372 | 9372 | fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { |
| 9373 | 9373 | const o = self.dg.object; |
| 9374 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 9374 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 9375 | 9375 | const inst_ty = self.typeOfIndex(inst); |
| 9376 | 9376 | const operand_ty = self.typeOf(ty_op.operand); |
| 9377 | 9377 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -9389,7 +9389,7 @@ pub const FuncGen = struct { |
| 9389 | 9389 | |
| 9390 | 9390 | fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { |
| 9391 | 9391 | const o = self.dg.object; |
| 9392 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 9392 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 9393 | 9393 | const inst_ty = self.typeOfIndex(inst); |
| 9394 | 9394 | const operand_ty = self.typeOf(ty_op.operand); |
| 9395 | 9395 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -9408,7 +9408,7 @@ pub const FuncGen = struct { |
| 9408 | 9408 | fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9409 | 9409 | const o = self.dg.object; |
| 9410 | 9410 | const mod = o.module; |
| 9411 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 9411 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 9412 | 9412 | const operand_ty = self.typeOf(ty_op.operand); |
| 9413 | 9413 | var bits = operand_ty.intInfo(mod).bits; |
| 9414 | 9414 | assert(bits % 8 == 0); |
| ... | ... | @@ -9442,9 +9442,9 @@ pub const FuncGen = struct { |
| 9442 | 9442 | fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9443 | 9443 | const o = self.dg.object; |
| 9444 | 9444 | const mod = o.module; |
| 9445 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 9445 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 9446 | 9446 | const operand = try self.resolveInst(ty_op.operand); |
| 9447 | const error_set_ty = self.air.getRefType(ty_op.ty); | |
| 9447 | const error_set_ty = ty_op.ty.toType(); | |
| 9448 | 9448 | |
| 9449 | 9449 | const names = error_set_ty.errorSetNames(mod); |
| 9450 | 9450 | const valid_block = try self.wip.block(@intCast(names.len), "Valid"); |
| ... | ... | @@ -9472,7 +9472,7 @@ pub const FuncGen = struct { |
| 9472 | 9472 | |
| 9473 | 9473 | fn airIsNamedEnumValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9474 | 9474 | const o = self.dg.object; |
| 9475 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 9475 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 9476 | 9476 | const operand = try self.resolveInst(un_op); |
| 9477 | 9477 | const enum_ty = self.typeOf(un_op); |
| 9478 | 9478 | |
| ... | ... | @@ -9542,7 +9542,7 @@ pub const FuncGen = struct { |
| 9542 | 9542 | |
| 9543 | 9543 | fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9544 | 9544 | const o = self.dg.object; |
| 9545 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 9545 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 9546 | 9546 | const operand = try self.resolveInst(un_op); |
| 9547 | 9547 | const enum_ty = self.typeOf(un_op); |
| 9548 | 9548 | |
| ... | ... | @@ -9654,7 +9654,7 @@ pub const FuncGen = struct { |
| 9654 | 9654 | |
| 9655 | 9655 | fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9656 | 9656 | const o = self.dg.object; |
| 9657 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 9657 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 9658 | 9658 | const operand = try self.resolveInst(un_op); |
| 9659 | 9659 | const slice_ty = self.typeOfIndex(inst); |
| 9660 | 9660 | const slice_llvm_ty = try o.lowerType(slice_ty); |
| ... | ... | @@ -9669,14 +9669,14 @@ pub const FuncGen = struct { |
| 9669 | 9669 | |
| 9670 | 9670 | fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9671 | 9671 | const o = self.dg.object; |
| 9672 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 9672 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 9673 | 9673 | const scalar = try self.resolveInst(ty_op.operand); |
| 9674 | 9674 | const vector_ty = self.typeOfIndex(inst); |
| 9675 | 9675 | return self.wip.splatVector(try o.lowerType(vector_ty), scalar, ""); |
| 9676 | 9676 | } |
| 9677 | 9677 | |
| 9678 | 9678 | fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9679 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 9679 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 9680 | 9680 | const extra = self.air.extraData(Air.Bin, pl_op.payload).data; |
| 9681 | 9681 | const pred = try self.resolveInst(pl_op.operand); |
| 9682 | 9682 | const a = try self.resolveInst(extra.lhs); |
| ... | ... | @@ -9688,7 +9688,7 @@ pub const FuncGen = struct { |
| 9688 | 9688 | fn airShuffle(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9689 | 9689 | const o = self.dg.object; |
| 9690 | 9690 | const mod = o.module; |
| 9691 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 9691 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 9692 | 9692 | const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data; |
| 9693 | 9693 | const a = try self.resolveInst(extra.a); |
| 9694 | 9694 | const b = try self.resolveInst(extra.b); |
| ... | ... | @@ -9799,7 +9799,7 @@ pub const FuncGen = struct { |
| 9799 | 9799 | const mod = o.module; |
| 9800 | 9800 | const target = mod.getTarget(); |
| 9801 | 9801 | |
| 9802 | const reduce = self.air.instructions.items(.data)[inst].reduce; | |
| 9802 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; | |
| 9803 | 9803 | const operand = try self.resolveInst(reduce.operand); |
| 9804 | 9804 | const operand_ty = self.typeOf(reduce.operand); |
| 9805 | 9805 | const llvm_operand_ty = try o.lowerType(operand_ty); |
| ... | ... | @@ -9908,7 +9908,7 @@ pub const FuncGen = struct { |
| 9908 | 9908 | const o = self.dg.object; |
| 9909 | 9909 | const mod = o.module; |
| 9910 | 9910 | const ip = &mod.intern_pool; |
| 9911 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 9911 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 9912 | 9912 | const result_ty = self.typeOfIndex(inst); |
| 9913 | 9913 | const len: usize = @intCast(result_ty.arrayLen(mod)); |
| 9914 | 9914 | const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]); |
| ... | ... | @@ -10031,7 +10031,7 @@ pub const FuncGen = struct { |
| 10031 | 10031 | const o = self.dg.object; |
| 10032 | 10032 | const mod = o.module; |
| 10033 | 10033 | const ip = &mod.intern_pool; |
| 10034 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 10034 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 10035 | 10035 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 10036 | 10036 | const union_ty = self.typeOfIndex(inst); |
| 10037 | 10037 | const union_llvm_ty = try o.lowerType(union_ty); |
| ... | ... | @@ -10151,7 +10151,7 @@ pub const FuncGen = struct { |
| 10151 | 10151 | |
| 10152 | 10152 | fn airPrefetch(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10153 | 10153 | const o = self.dg.object; |
| 10154 | const prefetch = self.air.instructions.items(.data)[inst].prefetch; | |
| 10154 | const prefetch = self.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; | |
| 10155 | 10155 | |
| 10156 | 10156 | comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.read) == 0); |
| 10157 | 10157 | comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.write) == 1); |
| ... | ... | @@ -10201,7 +10201,7 @@ pub const FuncGen = struct { |
| 10201 | 10201 | |
| 10202 | 10202 | fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10203 | 10203 | const o = self.dg.object; |
| 10204 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 10204 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 10205 | 10205 | const inst_ty = self.typeOfIndex(inst); |
| 10206 | 10206 | const operand = try self.resolveInst(ty_op.operand); |
| 10207 | 10207 | |
| ... | ... | @@ -10227,7 +10227,7 @@ pub const FuncGen = struct { |
| 10227 | 10227 | const target = o.module.getTarget(); |
| 10228 | 10228 | assert(target.cpu.arch == .amdgcn); // TODO is to port this function to other GPU architectures |
| 10229 | 10229 | |
| 10230 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 10230 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 10231 | 10231 | const dimension = pl_op.payload; |
| 10232 | 10232 | return self.amdgcnWorkIntrinsic(dimension, 0, "amdgcn.workitem.id"); |
| 10233 | 10233 | } |
| ... | ... | @@ -10237,7 +10237,7 @@ pub const FuncGen = struct { |
| 10237 | 10237 | const target = o.module.getTarget(); |
| 10238 | 10238 | assert(target.cpu.arch == .amdgcn); // TODO is to port this function to other GPU architectures |
| 10239 | 10239 | |
| 10240 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 10240 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 10241 | 10241 | const dimension = pl_op.payload; |
| 10242 | 10242 | if (dimension >= 3) return o.builder.intValue(.i32, 1); |
| 10243 | 10243 | |
| ... | ... | @@ -10260,7 +10260,7 @@ pub const FuncGen = struct { |
| 10260 | 10260 | const target = o.module.getTarget(); |
| 10261 | 10261 | assert(target.cpu.arch == .amdgcn); // TODO is to port this function to other GPU architectures |
| 10262 | 10262 | |
| 10263 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 10263 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 10264 | 10264 | const dimension = pl_op.payload; |
| 10265 | 10265 | return self.amdgcnWorkIntrinsic(dimension, 0, "amdgcn.workgroup.id"); |
| 10266 | 10266 | } |
src/codegen/spirv.zig+71-70| ... | ... | @@ -445,7 +445,7 @@ const DeclGen = struct { |
| 445 | 445 | |
| 446 | 446 | return try self.constant(ty, val, .direct); |
| 447 | 447 | } |
| 448 | const index = Air.refToIndex(inst).?; | |
| 448 | const index = inst.toIndex().?; | |
| 449 | 449 | return self.inst_results.get(index).?; // Assertion means instruction does not dominate usage. |
| 450 | 450 | } |
| 451 | 451 | |
| ... | ... | @@ -2089,7 +2089,7 @@ const DeclGen = struct { |
| 2089 | 2089 | return; |
| 2090 | 2090 | |
| 2091 | 2091 | const air_tags = self.air.instructions.items(.tag); |
| 2092 | const maybe_result_id: ?IdRef = switch (air_tags[inst]) { | |
| 2092 | const maybe_result_id: ?IdRef = switch (air_tags[@intFromEnum(inst)]) { | |
| 2093 | 2093 | // zig fmt: off |
| 2094 | 2094 | .add, .add_wrap => try self.airArithOp(inst, .OpFAdd, .OpIAdd, .OpIAdd, true), |
| 2095 | 2095 | .sub, .sub_wrap => try self.airArithOp(inst, .OpFSub, .OpISub, .OpISub, true), |
| ... | ... | @@ -2255,7 +2255,7 @@ const DeclGen = struct { |
| 2255 | 2255 | fn airBinOpSimple(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef { |
| 2256 | 2256 | if (self.liveness.isUnused(inst)) return null; |
| 2257 | 2257 | |
| 2258 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2258 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2259 | 2259 | const lhs_id = try self.resolve(bin_op.lhs); |
| 2260 | 2260 | const rhs_id = try self.resolve(bin_op.rhs); |
| 2261 | 2261 | const ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2265,7 +2265,7 @@ const DeclGen = struct { |
| 2265 | 2265 | |
| 2266 | 2266 | fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef { |
| 2267 | 2267 | if (self.liveness.isUnused(inst)) return null; |
| 2268 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2268 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2269 | 2269 | const lhs_id = try self.resolve(bin_op.lhs); |
| 2270 | 2270 | const rhs_id = try self.resolve(bin_op.rhs); |
| 2271 | 2271 | const result_type_id = try self.resolveTypeId(self.typeOfIndex(inst)); |
| ... | ... | @@ -2291,7 +2291,7 @@ const DeclGen = struct { |
| 2291 | 2291 | fn airMinMax(self: *DeclGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !?IdRef { |
| 2292 | 2292 | if (self.liveness.isUnused(inst)) return null; |
| 2293 | 2293 | |
| 2294 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2294 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2295 | 2295 | const lhs_id = try self.resolve(bin_op.lhs); |
| 2296 | 2296 | const rhs_id = try self.resolve(bin_op.rhs); |
| 2297 | 2297 | const result_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -2395,7 +2395,7 @@ const DeclGen = struct { |
| 2395 | 2395 | // LHS and RHS are guaranteed to have the same type, and AIR guarantees |
| 2396 | 2396 | // the result to be the same as the LHS and RHS, which matches SPIR-V. |
| 2397 | 2397 | const ty = self.typeOfIndex(inst); |
| 2398 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2398 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2399 | 2399 | const lhs_id = try self.resolve(bin_op.lhs); |
| 2400 | 2400 | const rhs_id = try self.resolve(bin_op.rhs); |
| 2401 | 2401 | |
| ... | ... | @@ -2492,7 +2492,7 @@ const DeclGen = struct { |
| 2492 | 2492 | ) !?IdRef { |
| 2493 | 2493 | if (self.liveness.isUnused(inst)) return null; |
| 2494 | 2494 | |
| 2495 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2495 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2496 | 2496 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2497 | 2497 | const lhs = try self.resolve(extra.lhs); |
| 2498 | 2498 | const rhs = try self.resolve(extra.rhs); |
| ... | ... | @@ -2601,7 +2601,7 @@ const DeclGen = struct { |
| 2601 | 2601 | const mod = self.module; |
| 2602 | 2602 | if (self.liveness.isUnused(inst)) return null; |
| 2603 | 2603 | const ty = self.typeOfIndex(inst); |
| 2604 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2604 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2605 | 2605 | const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data; |
| 2606 | 2606 | const a = try self.resolve(extra.a); |
| 2607 | 2607 | const b = try self.resolve(extra.b); |
| ... | ... | @@ -2719,7 +2719,7 @@ const DeclGen = struct { |
| 2719 | 2719 | |
| 2720 | 2720 | fn airPtrAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 2721 | 2721 | if (self.liveness.isUnused(inst)) return null; |
| 2722 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2722 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2723 | 2723 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2724 | 2724 | const ptr_id = try self.resolve(bin_op.lhs); |
| 2725 | 2725 | const offset_id = try self.resolve(bin_op.rhs); |
| ... | ... | @@ -2731,7 +2731,7 @@ const DeclGen = struct { |
| 2731 | 2731 | |
| 2732 | 2732 | fn airPtrSub(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 2733 | 2733 | if (self.liveness.isUnused(inst)) return null; |
| 2734 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2734 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2735 | 2735 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2736 | 2736 | const ptr_id = try self.resolve(bin_op.lhs); |
| 2737 | 2737 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2919,7 +2919,7 @@ const DeclGen = struct { |
| 2919 | 2919 | comptime op: std.math.CompareOperator, |
| 2920 | 2920 | ) !?IdRef { |
| 2921 | 2921 | if (self.liveness.isUnused(inst)) return null; |
| 2922 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 2922 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 2923 | 2923 | const lhs_id = try self.resolve(bin_op.lhs); |
| 2924 | 2924 | const rhs_id = try self.resolve(bin_op.rhs); |
| 2925 | 2925 | const ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2931,7 +2931,7 @@ const DeclGen = struct { |
| 2931 | 2931 | fn airVectorCmp(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 2932 | 2932 | if (self.liveness.isUnused(inst)) return null; |
| 2933 | 2933 | |
| 2934 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 2934 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 2935 | 2935 | const vec_cmp = self.air.extraData(Air.VectorCmp, ty_pl.payload).data; |
| 2936 | 2936 | const lhs_id = try self.resolve(vec_cmp.lhs); |
| 2937 | 2937 | const rhs_id = try self.resolve(vec_cmp.rhs); |
| ... | ... | @@ -2999,7 +2999,7 @@ const DeclGen = struct { |
| 2999 | 2999 | |
| 3000 | 3000 | fn airBitCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3001 | 3001 | if (self.liveness.isUnused(inst)) return null; |
| 3002 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3002 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3003 | 3003 | const operand_id = try self.resolve(ty_op.operand); |
| 3004 | 3004 | const operand_ty = self.typeOf(ty_op.operand); |
| 3005 | 3005 | const result_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -3009,7 +3009,7 @@ const DeclGen = struct { |
| 3009 | 3009 | fn airIntCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3010 | 3010 | if (self.liveness.isUnused(inst)) return null; |
| 3011 | 3011 | |
| 3012 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3012 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3013 | 3013 | const operand_id = try self.resolve(ty_op.operand); |
| 3014 | 3014 | const src_ty = self.typeOf(ty_op.operand); |
| 3015 | 3015 | const dst_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -3057,7 +3057,7 @@ const DeclGen = struct { |
| 3057 | 3057 | fn airIntFromPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3058 | 3058 | if (self.liveness.isUnused(inst)) return null; |
| 3059 | 3059 | |
| 3060 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 3060 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 3061 | 3061 | const operand_id = try self.resolve(un_op); |
| 3062 | 3062 | return try self.intFromPtr(operand_id); |
| 3063 | 3063 | } |
| ... | ... | @@ -3065,7 +3065,7 @@ const DeclGen = struct { |
| 3065 | 3065 | fn airFloatFromInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3066 | 3066 | if (self.liveness.isUnused(inst)) return null; |
| 3067 | 3067 | |
| 3068 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3068 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3069 | 3069 | const operand_ty = self.typeOf(ty_op.operand); |
| 3070 | 3070 | const operand_id = try self.resolve(ty_op.operand); |
| 3071 | 3071 | const operand_info = try self.arithmeticTypeInfo(operand_ty); |
| ... | ... | @@ -3091,7 +3091,7 @@ const DeclGen = struct { |
| 3091 | 3091 | fn airIntFromFloat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3092 | 3092 | if (self.liveness.isUnused(inst)) return null; |
| 3093 | 3093 | |
| 3094 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3094 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3095 | 3095 | const operand_id = try self.resolve(ty_op.operand); |
| 3096 | 3096 | const dest_ty = self.typeOfIndex(inst); |
| 3097 | 3097 | const dest_info = try self.arithmeticTypeInfo(dest_ty); |
| ... | ... | @@ -3116,7 +3116,7 @@ const DeclGen = struct { |
| 3116 | 3116 | fn airFloatCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3117 | 3117 | if (self.liveness.isUnused(inst)) return null; |
| 3118 | 3118 | |
| 3119 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3119 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3120 | 3120 | const operand_id = try self.resolve(ty_op.operand); |
| 3121 | 3121 | const dest_ty = self.typeOfIndex(inst); |
| 3122 | 3122 | const dest_ty_id = try self.resolveTypeId(dest_ty); |
| ... | ... | @@ -3132,7 +3132,7 @@ const DeclGen = struct { |
| 3132 | 3132 | |
| 3133 | 3133 | fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3134 | 3134 | if (self.liveness.isUnused(inst)) return null; |
| 3135 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3135 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3136 | 3136 | const operand_id = try self.resolve(ty_op.operand); |
| 3137 | 3137 | const result_ty = self.typeOfIndex(inst); |
| 3138 | 3138 | const result_ty_id = try self.resolveTypeId(result_ty); |
| ... | ... | @@ -3166,7 +3166,7 @@ const DeclGen = struct { |
| 3166 | 3166 | if (self.liveness.isUnused(inst)) return null; |
| 3167 | 3167 | |
| 3168 | 3168 | const mod = self.module; |
| 3169 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3169 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3170 | 3170 | const array_ptr_ty = self.typeOf(ty_op.operand); |
| 3171 | 3171 | const array_ty = array_ptr_ty.childType(mod); |
| 3172 | 3172 | const slice_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -3195,7 +3195,7 @@ const DeclGen = struct { |
| 3195 | 3195 | fn airSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3196 | 3196 | if (self.liveness.isUnused(inst)) return null; |
| 3197 | 3197 | |
| 3198 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3198 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3199 | 3199 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3200 | 3200 | const ptr_id = try self.resolve(bin_op.lhs); |
| 3201 | 3201 | const len_id = try self.resolve(bin_op.rhs); |
| ... | ... | @@ -3216,7 +3216,7 @@ const DeclGen = struct { |
| 3216 | 3216 | |
| 3217 | 3217 | const mod = self.module; |
| 3218 | 3218 | const ip = &mod.intern_pool; |
| 3219 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3219 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3220 | 3220 | const result_ty = self.typeOfIndex(inst); |
| 3221 | 3221 | const len: usize = @intCast(result_ty.arrayLen(mod)); |
| 3222 | 3222 | const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]); |
| ... | ... | @@ -3316,7 +3316,7 @@ const DeclGen = struct { |
| 3316 | 3316 | } |
| 3317 | 3317 | |
| 3318 | 3318 | fn airMemcpy(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 3319 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3319 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3320 | 3320 | const dest_slice = try self.resolve(bin_op.lhs); |
| 3321 | 3321 | const src_slice = try self.resolve(bin_op.rhs); |
| 3322 | 3322 | const dest_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -3333,7 +3333,7 @@ const DeclGen = struct { |
| 3333 | 3333 | |
| 3334 | 3334 | fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef { |
| 3335 | 3335 | if (self.liveness.isUnused(inst)) return null; |
| 3336 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3336 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3337 | 3337 | const field_ty = self.typeOfIndex(inst); |
| 3338 | 3338 | const operand_id = try self.resolve(ty_op.operand); |
| 3339 | 3339 | return try self.extractField(field_ty, operand_id, field); |
| ... | ... | @@ -3341,7 +3341,7 @@ const DeclGen = struct { |
| 3341 | 3341 | |
| 3342 | 3342 | fn airSliceElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3343 | 3343 | const mod = self.module; |
| 3344 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3344 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3345 | 3345 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3346 | 3346 | const slice_ty = self.typeOf(bin_op.lhs); |
| 3347 | 3347 | if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null; |
| ... | ... | @@ -3358,7 +3358,7 @@ const DeclGen = struct { |
| 3358 | 3358 | |
| 3359 | 3359 | fn airSliceElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3360 | 3360 | const mod = self.module; |
| 3361 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3361 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3362 | 3362 | const slice_ty = self.typeOf(bin_op.lhs); |
| 3363 | 3363 | if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null; |
| 3364 | 3364 | |
| ... | ... | @@ -3392,7 +3392,7 @@ const DeclGen = struct { |
| 3392 | 3392 | if (self.liveness.isUnused(inst)) return null; |
| 3393 | 3393 | |
| 3394 | 3394 | const mod = self.module; |
| 3395 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3395 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3396 | 3396 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3397 | 3397 | const src_ptr_ty = self.typeOf(bin_op.lhs); |
| 3398 | 3398 | const elem_ty = src_ptr_ty.childType(mod); |
| ... | ... | @@ -3411,7 +3411,7 @@ const DeclGen = struct { |
| 3411 | 3411 | if (self.liveness.isUnused(inst)) return null; |
| 3412 | 3412 | |
| 3413 | 3413 | const mod = self.module; |
| 3414 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3414 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3415 | 3415 | const array_ty = self.typeOf(bin_op.lhs); |
| 3416 | 3416 | const elem_ty = array_ty.childType(mod); |
| 3417 | 3417 | const array_id = try self.resolve(bin_op.lhs); |
| ... | ... | @@ -3433,7 +3433,7 @@ const DeclGen = struct { |
| 3433 | 3433 | if (self.liveness.isUnused(inst)) return null; |
| 3434 | 3434 | |
| 3435 | 3435 | const mod = self.module; |
| 3436 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3436 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3437 | 3437 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 3438 | 3438 | const elem_ty = self.typeOfIndex(inst); |
| 3439 | 3439 | const ptr_id = try self.resolve(bin_op.lhs); |
| ... | ... | @@ -3444,7 +3444,7 @@ const DeclGen = struct { |
| 3444 | 3444 | |
| 3445 | 3445 | fn airSetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 3446 | 3446 | const mod = self.module; |
| 3447 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 3447 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 3448 | 3448 | const un_ptr_ty = self.typeOf(bin_op.lhs); |
| 3449 | 3449 | const un_ty = un_ptr_ty.childType(mod); |
| 3450 | 3450 | const layout = self.unionLayout(un_ty); |
| ... | ... | @@ -3468,7 +3468,7 @@ const DeclGen = struct { |
| 3468 | 3468 | fn airGetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3469 | 3469 | if (self.liveness.isUnused(inst)) return null; |
| 3470 | 3470 | |
| 3471 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3471 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3472 | 3472 | const un_ty = self.typeOf(ty_op.operand); |
| 3473 | 3473 | |
| 3474 | 3474 | const mod = self.module; |
| ... | ... | @@ -3555,7 +3555,7 @@ const DeclGen = struct { |
| 3555 | 3555 | |
| 3556 | 3556 | const mod = self.module; |
| 3557 | 3557 | const ip = &mod.intern_pool; |
| 3558 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3558 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3559 | 3559 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 3560 | 3560 | const ty = self.typeOfIndex(inst); |
| 3561 | 3561 | |
| ... | ... | @@ -3572,7 +3572,7 @@ const DeclGen = struct { |
| 3572 | 3572 | if (self.liveness.isUnused(inst)) return null; |
| 3573 | 3573 | |
| 3574 | 3574 | const mod = self.module; |
| 3575 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3575 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3576 | 3576 | const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 3577 | 3577 | |
| 3578 | 3578 | const object_ty = self.typeOf(struct_field.struct_operand); |
| ... | ... | @@ -3616,11 +3616,11 @@ const DeclGen = struct { |
| 3616 | 3616 | |
| 3617 | 3617 | fn airFieldParentPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3618 | 3618 | const mod = self.module; |
| 3619 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 3619 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 3620 | 3620 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 3621 | 3621 | |
| 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); | |
| 3624 | 3624 | const usize_ty = Type.usize; |
| 3625 | 3625 | const usize_ty_ref = try self.resolveType(usize_ty, .direct); |
| 3626 | 3626 | |
| ... | ... | @@ -3692,7 +3692,7 @@ const DeclGen = struct { |
| 3692 | 3692 | |
| 3693 | 3693 | fn airStructFieldPtrIndex(self: *DeclGen, inst: Air.Inst.Index, field_index: u32) !?IdRef { |
| 3694 | 3694 | if (self.liveness.isUnused(inst)) return null; |
| 3695 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 3695 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 3696 | 3696 | const struct_ptr = try self.resolve(ty_op.operand); |
| 3697 | 3697 | const struct_ptr_ty = self.typeOf(ty_op.operand); |
| 3698 | 3698 | const result_ptr_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -3918,8 +3918,9 @@ const DeclGen = struct { |
| 3918 | 3918 | const mod = self.module; |
| 3919 | 3919 | const ty = self.typeOfIndex(inst); |
| 3920 | 3920 | 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]); | |
| 3923 | 3924 | const have_block_result = ty.isFnOrHasRuntimeBitsIgnoreComptime(mod); |
| 3924 | 3925 | |
| 3925 | 3926 | const cf = switch (self.control_flow) { |
| ... | ... | @@ -3983,7 +3984,7 @@ const DeclGen = struct { |
| 3983 | 3984 | |
| 3984 | 3985 | // Check if the target of the branch was this current block. |
| 3985 | 3986 | const block_id_ty_ref = try self.intType(.unsigned, 32); |
| 3986 | const this_block = try self.constInt(block_id_ty_ref, inst); | |
| 3987 | const this_block = try self.constInt(block_id_ty_ref, @intFromEnum(inst)); | |
| 3987 | 3988 | const jump_to_this_block_id = self.spv.allocId(); |
| 3988 | 3989 | const bool_ty_ref = try self.resolveType(Type.bool, .direct); |
| 3989 | 3990 | try self.func.body.emit(self.spv.gpa, .OpIEqual, .{ |
| ... | ... | @@ -4052,7 +4053,7 @@ const DeclGen = struct { |
| 4052 | 4053 | |
| 4053 | 4054 | fn airBr(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4054 | 4055 | const mod = self.module; |
| 4055 | const br = self.air.instructions.items(.data)[inst].br; | |
| 4056 | const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 4056 | 4057 | const operand_ty = self.typeOf(br.operand); |
| 4057 | 4058 | |
| 4058 | 4059 | switch (self.control_flow) { |
| ... | ... | @@ -4064,7 +4065,7 @@ const DeclGen = struct { |
| 4064 | 4065 | } |
| 4065 | 4066 | |
| 4066 | 4067 | const block_id_ty_ref = try self.intType(.unsigned, 32); |
| 4067 | const next_block = try self.constInt(block_id_ty_ref, br.block_inst); | |
| 4068 | const next_block = try self.constInt(block_id_ty_ref, @intFromEnum(br.block_inst)); | |
| 4068 | 4069 | try self.structuredBreak(next_block); |
| 4069 | 4070 | }, |
| 4070 | 4071 | .unstructured => |cf| { |
| ... | ... | @@ -4089,10 +4090,10 @@ const DeclGen = struct { |
| 4089 | 4090 | } |
| 4090 | 4091 | |
| 4091 | 4092 | fn airCondBr(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4092 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4093 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4093 | 4094 | const cond_br = self.air.extraData(Air.CondBr, pl_op.payload); |
| 4094 | const then_body = self.air.extra[cond_br.end..][0..cond_br.data.then_body_len]; | |
| 4095 | const 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]); | |
| 4096 | 4097 | const condition_id = try self.resolve(pl_op.operand); |
| 4097 | 4098 | |
| 4098 | 4099 | const then_label = self.spv.allocId(); |
| ... | ... | @@ -4149,9 +4150,9 @@ const DeclGen = struct { |
| 4149 | 4150 | } |
| 4150 | 4151 | |
| 4151 | 4152 | fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4152 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 4153 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4153 | 4154 | const loop = self.air.extraData(Air.Block, ty_pl.payload); |
| 4154 | const body = self.air.extra[loop.end..][0..loop.data.body_len]; | |
| 4155 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]); | |
| 4155 | 4156 | |
| 4156 | 4157 | const body_label = self.spv.allocId(); |
| 4157 | 4158 | |
| ... | ... | @@ -4197,7 +4198,7 @@ const DeclGen = struct { |
| 4197 | 4198 | |
| 4198 | 4199 | fn airLoad(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 4199 | 4200 | const mod = self.module; |
| 4200 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4201 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4201 | 4202 | const ptr_ty = self.typeOf(ty_op.operand); |
| 4202 | 4203 | const elem_ty = self.typeOfIndex(inst); |
| 4203 | 4204 | const operand = try self.resolve(ty_op.operand); |
| ... | ... | @@ -4207,7 +4208,7 @@ const DeclGen = struct { |
| 4207 | 4208 | } |
| 4208 | 4209 | |
| 4209 | 4210 | fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4210 | const bin_op = self.air.instructions.items(.data)[inst].bin_op; | |
| 4211 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 4211 | 4212 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 4212 | 4213 | const elem_ty = ptr_ty.childType(self.module); |
| 4213 | 4214 | const ptr = try self.resolve(bin_op.lhs); |
| ... | ... | @@ -4217,7 +4218,7 @@ const DeclGen = struct { |
| 4217 | 4218 | } |
| 4218 | 4219 | |
| 4219 | 4220 | fn airRet(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4220 | const operand = self.air.instructions.items(.data)[inst].un_op; | |
| 4221 | const operand = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4221 | 4222 | const ret_ty = self.typeOf(operand); |
| 4222 | 4223 | const mod = self.module; |
| 4223 | 4224 | if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| ... | ... | @@ -4241,7 +4242,7 @@ const DeclGen = struct { |
| 4241 | 4242 | |
| 4242 | 4243 | fn airRetLoad(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4243 | 4244 | const mod = self.module; |
| 4244 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4245 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4245 | 4246 | const ptr_ty = self.typeOf(un_op); |
| 4246 | 4247 | const ret_ty = ptr_ty.childType(mod); |
| 4247 | 4248 | |
| ... | ... | @@ -4269,10 +4270,10 @@ const DeclGen = struct { |
| 4269 | 4270 | |
| 4270 | 4271 | fn airTry(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 4271 | 4272 | const mod = self.module; |
| 4272 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4273 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4273 | 4274 | const err_union_id = try self.resolve(pl_op.operand); |
| 4274 | 4275 | const extra = self.air.extraData(Air.Try, pl_op.payload); |
| 4275 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | |
| 4276 | const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]); | |
| 4276 | 4277 | |
| 4277 | 4278 | const err_union_ty = self.typeOf(pl_op.operand); |
| 4278 | 4279 | const payload_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -4344,7 +4345,7 @@ const DeclGen = struct { |
| 4344 | 4345 | if (self.liveness.isUnused(inst)) return null; |
| 4345 | 4346 | |
| 4346 | 4347 | const mod = self.module; |
| 4347 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4348 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4348 | 4349 | const operand_id = try self.resolve(ty_op.operand); |
| 4349 | 4350 | const err_union_ty = self.typeOf(ty_op.operand); |
| 4350 | 4351 | const err_ty_ref = try self.resolveType(Type.anyerror, .direct); |
| ... | ... | @@ -4368,7 +4369,7 @@ const DeclGen = struct { |
| 4368 | 4369 | fn airErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 4369 | 4370 | if (self.liveness.isUnused(inst)) return null; |
| 4370 | 4371 | |
| 4371 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4372 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4372 | 4373 | const operand_id = try self.resolve(ty_op.operand); |
| 4373 | 4374 | const payload_ty = self.typeOfIndex(inst); |
| 4374 | 4375 | const eu_layout = self.errorUnionLayout(payload_ty); |
| ... | ... | @@ -4384,7 +4385,7 @@ const DeclGen = struct { |
| 4384 | 4385 | if (self.liveness.isUnused(inst)) return null; |
| 4385 | 4386 | |
| 4386 | 4387 | const mod = self.module; |
| 4387 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4388 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4388 | 4389 | const err_union_ty = self.typeOfIndex(inst); |
| 4389 | 4390 | const payload_ty = err_union_ty.errorUnionPayload(mod); |
| 4390 | 4391 | const operand_id = try self.resolve(ty_op.operand); |
| ... | ... | @@ -4410,7 +4411,7 @@ const DeclGen = struct { |
| 4410 | 4411 | fn airWrapErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 4411 | 4412 | if (self.liveness.isUnused(inst)) return null; |
| 4412 | 4413 | |
| 4413 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4414 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4414 | 4415 | const err_union_ty = self.typeOfIndex(inst); |
| 4415 | 4416 | const operand_id = try self.resolve(ty_op.operand); |
| 4416 | 4417 | const payload_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -4436,7 +4437,7 @@ const DeclGen = struct { |
| 4436 | 4437 | if (self.liveness.isUnused(inst)) return null; |
| 4437 | 4438 | |
| 4438 | 4439 | const mod = self.module; |
| 4439 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4440 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4440 | 4441 | const operand_id = try self.resolve(un_op); |
| 4441 | 4442 | const optional_ty = self.typeOf(un_op); |
| 4442 | 4443 | |
| ... | ... | @@ -4493,7 +4494,7 @@ const DeclGen = struct { |
| 4493 | 4494 | if (self.liveness.isUnused(inst)) return null; |
| 4494 | 4495 | |
| 4495 | 4496 | const mod = self.module; |
| 4496 | const un_op = self.air.instructions.items(.data)[inst].un_op; | |
| 4497 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 4497 | 4498 | const operand_id = try self.resolve(un_op); |
| 4498 | 4499 | const err_union_ty = self.typeOf(un_op); |
| 4499 | 4500 | |
| ... | ... | @@ -4529,7 +4530,7 @@ const DeclGen = struct { |
| 4529 | 4530 | if (self.liveness.isUnused(inst)) return null; |
| 4530 | 4531 | |
| 4531 | 4532 | const mod = self.module; |
| 4532 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4533 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4533 | 4534 | const operand_id = try self.resolve(ty_op.operand); |
| 4534 | 4535 | const optional_ty = self.typeOf(ty_op.operand); |
| 4535 | 4536 | const payload_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -4547,7 +4548,7 @@ const DeclGen = struct { |
| 4547 | 4548 | if (self.liveness.isUnused(inst)) return null; |
| 4548 | 4549 | |
| 4549 | 4550 | const mod = self.module; |
| 4550 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | |
| 4551 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | |
| 4551 | 4552 | const payload_ty = self.typeOf(ty_op.operand); |
| 4552 | 4553 | |
| 4553 | 4554 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| ... | ... | @@ -4569,7 +4570,7 @@ const DeclGen = struct { |
| 4569 | 4570 | |
| 4570 | 4571 | fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4571 | 4572 | const mod = self.module; |
| 4572 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4573 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4573 | 4574 | const cond_ty = self.typeOf(pl_op.operand); |
| 4574 | 4575 | const cond = try self.resolve(pl_op.operand); |
| 4575 | 4576 | const cond_indirect = try self.convertToIndirect(cond_ty, cond); |
| ... | ... | @@ -4679,8 +4680,8 @@ const DeclGen = struct { |
| 4679 | 4680 | var extra_index: usize = switch_br.end; |
| 4680 | 4681 | for (0..num_cases) |case_i| { |
| 4681 | 4682 | const case = self.air.extraData(Air.SwitchBr.Case, extra_index); |
| 4682 | const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len])); | |
| 4683 | const 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]); | |
| 4684 | 4685 | extra_index = case.end + case.data.items_len + case_body.len; |
| 4685 | 4686 | |
| 4686 | 4687 | const label = IdResult{ .id = @intCast(first_case_label.id + case_i) }; |
| ... | ... | @@ -4702,7 +4703,7 @@ const DeclGen = struct { |
| 4702 | 4703 | } |
| 4703 | 4704 | } |
| 4704 | 4705 | |
| 4705 | const else_body = self.air.extra[extra_index..][0..switch_br.data.else_body_len]; | |
| 4706 | const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]); | |
| 4706 | 4707 | try self.beginSpvBlock(default); |
| 4707 | 4708 | if (else_body.len != 0) { |
| 4708 | 4709 | switch (self.control_flow) { |
| ... | ... | @@ -4734,7 +4735,7 @@ const DeclGen = struct { |
| 4734 | 4735 | } |
| 4735 | 4736 | |
| 4736 | 4737 | fn airDbgStmt(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4737 | const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt; | |
| 4738 | const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; | |
| 4738 | 4739 | const mod = self.module; |
| 4739 | 4740 | const decl = mod.declPtr(self.decl_index); |
| 4740 | 4741 | const path = decl.getFileScope(mod).sub_file_path; |
| ... | ... | @@ -4749,7 +4750,7 @@ const DeclGen = struct { |
| 4749 | 4750 | |
| 4750 | 4751 | fn airDbgInlineBegin(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4751 | 4752 | const mod = self.module; |
| 4752 | const fn_ty = self.air.instructions.items(.data)[inst].ty_fn; | |
| 4753 | const fn_ty = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 4753 | 4754 | const decl_index = mod.funcInfo(fn_ty.func).owner_decl; |
| 4754 | 4755 | const decl = mod.declPtr(decl_index); |
| 4755 | 4756 | try self.base_line_stack.append(self.gpa, decl.src_line); |
| ... | ... | @@ -4761,7 +4762,7 @@ const DeclGen = struct { |
| 4761 | 4762 | } |
| 4762 | 4763 | |
| 4763 | 4764 | fn airDbgVar(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4764 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4765 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4765 | 4766 | const target_id = try self.resolve(pl_op.operand); |
| 4766 | 4767 | const name = self.air.nullTerminatedString(pl_op.payload); |
| 4767 | 4768 | try self.spv.debugName(target_id, name); |
| ... | ... | @@ -4769,7 +4770,7 @@ const DeclGen = struct { |
| 4769 | 4770 | |
| 4770 | 4771 | fn airAssembly(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 4771 | 4772 | const mod = self.module; |
| 4772 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | |
| 4773 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 4773 | 4774 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); |
| 4774 | 4775 | |
| 4775 | 4776 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; |
| ... | ... | @@ -4901,7 +4902,7 @@ const DeclGen = struct { |
| 4901 | 4902 | _ = modifier; |
| 4902 | 4903 | |
| 4903 | 4904 | const mod = self.module; |
| 4904 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | |
| 4905 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 4905 | 4906 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 4906 | 4907 | const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len])); |
| 4907 | 4908 | const callee_ty = self.typeOf(pl_op.operand); |
src/print_air.zig+55-55| ... | ... | @@ -94,7 +94,7 @@ const Writer = struct { |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | fn writeInst(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 97 | const tag = w.air.instructions.items(.tag)[inst]; | |
| 97 | const tag = w.air.instructions.items(.tag)[@intFromEnum(inst)]; | |
| 98 | 98 | try s.writeByteNTimes(' ', w.indent); |
| 99 | 99 | try s.print("%{d}{c}= {s}(", .{ |
| 100 | 100 | inst, |
| ... | ... | @@ -329,14 +329,14 @@ const Writer = struct { |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | fn writeBinOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 332 | const bin_op = w.air.instructions.items(.data)[inst].bin_op; | |
| 332 | const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 333 | 333 | try w.writeOperand(s, inst, 0, bin_op.lhs); |
| 334 | 334 | try s.writeAll(", "); |
| 335 | 335 | try w.writeOperand(s, inst, 1, bin_op.rhs); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | fn writeUnOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 339 | const un_op = w.air.instructions.items(.data)[inst].un_op; | |
| 339 | const un_op = w.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | |
| 340 | 340 | try w.writeOperand(s, inst, 0, un_op); |
| 341 | 341 | } |
| 342 | 342 | |
| ... | ... | @@ -351,33 +351,33 @@ const Writer = struct { |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | fn writeTy(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 354 | const ty = w.air.instructions.items(.data)[inst].ty; | |
| 354 | const ty = w.air.instructions.items(.data)[@intFromEnum(inst)].ty; | |
| 355 | 355 | try w.writeType(s, ty); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | fn writeArg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 359 | const arg = w.air.instructions.items(.data)[inst].arg; | |
| 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()); | |
| 361 | 361 | try s.print(", {d}", .{arg.src_index}); |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | fn writeTyOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 365 | const ty_op = w.air.instructions.items(.data)[inst].ty_op; | |
| 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()); | |
| 367 | 367 | try s.writeAll(", "); |
| 368 | 368 | try w.writeOperand(s, inst, 0, ty_op.operand); |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | fn writeBlock(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 372 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 372 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 373 | 373 | const extra = w.air.extraData(Air.Block, ty_pl.payload); |
| 374 | const body = w.air.extra[extra.end..][0..extra.data.body_len]; | |
| 374 | const body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end..][0..extra.data.body_len]); | |
| 375 | 375 | const liveness_block = if (w.liveness) |liveness| |
| 376 | 376 | liveness.getBlock(inst) |
| 377 | 377 | else |
| 378 | 378 | Liveness.BlockSlices{ .deaths = &.{} }; |
| 379 | 379 | |
| 380 | try w.writeType(s, w.air.getRefType(ty_pl.ty)); | |
| 380 | try w.writeType(s, ty_pl.ty.toType()); | |
| 381 | 381 | if (w.skip_body) return s.writeAll(", ..."); |
| 382 | 382 | try s.writeAll(", {\n"); |
| 383 | 383 | const old_indent = w.indent; |
| ... | ... | @@ -393,11 +393,11 @@ const Writer = struct { |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | fn writeLoop(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 396 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 396 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 397 | 397 | const extra = w.air.extraData(Air.Block, ty_pl.payload); |
| 398 | const body = w.air.extra[extra.end..][0..extra.data.body_len]; | |
| 398 | const body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end..][0..extra.data.body_len]); | |
| 399 | 399 | |
| 400 | try w.writeType(s, w.air.getRefType(ty_pl.ty)); | |
| 400 | try w.writeType(s, ty_pl.ty.toType()); | |
| 401 | 401 | if (w.skip_body) return s.writeAll(", ..."); |
| 402 | 402 | try s.writeAll(", {\n"); |
| 403 | 403 | const old_indent = w.indent; |
| ... | ... | @@ -410,8 +410,8 @@ const Writer = struct { |
| 410 | 410 | |
| 411 | 411 | fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 412 | 412 | 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(); | |
| 415 | 415 | const len = @as(usize, @intCast(vector_ty.arrayLen(mod))); |
| 416 | 416 | const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len])); |
| 417 | 417 | |
| ... | ... | @@ -425,7 +425,7 @@ const Writer = struct { |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | fn writeUnionInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 428 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 428 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 429 | 429 | const extra = w.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 430 | 430 | |
| 431 | 431 | try s.print("{d}, ", .{extra.field_index}); |
| ... | ... | @@ -433,7 +433,7 @@ const Writer = struct { |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | fn writeStructField(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 436 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 436 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 437 | 437 | const extra = w.air.extraData(Air.StructField, ty_pl.payload).data; |
| 438 | 438 | |
| 439 | 439 | try w.writeOperand(s, inst, 0, extra.struct_operand); |
| ... | ... | @@ -442,10 +442,10 @@ const Writer = struct { |
| 442 | 442 | |
| 443 | 443 | fn writeTyPlBin(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 444 | 444 | const data = w.air.instructions.items(.data); |
| 445 | const ty_pl = data[inst].ty_pl; | |
| 445 | const ty_pl = data[@intFromEnum(inst)].ty_pl; | |
| 446 | 446 | const extra = w.air.extraData(Air.Bin, ty_pl.payload).data; |
| 447 | 447 | |
| 448 | const inst_ty = w.air.getRefType(data[inst].ty_pl.ty); | |
| 448 | const inst_ty = data[@intFromEnum(inst)].ty_pl.ty.toType(); | |
| 449 | 449 | try w.writeType(s, inst_ty); |
| 450 | 450 | try s.writeAll(", "); |
| 451 | 451 | try w.writeOperand(s, inst, 0, extra.lhs); |
| ... | ... | @@ -454,7 +454,7 @@ const Writer = struct { |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | fn writeCmpxchg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 457 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 457 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 458 | 458 | const extra = w.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 459 | 459 | |
| 460 | 460 | try w.writeOperand(s, inst, 0, extra.ptr); |
| ... | ... | @@ -468,7 +468,7 @@ const Writer = struct { |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | fn writeMulAdd(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 471 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 471 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 472 | 472 | const extra = w.air.extraData(Air.Bin, pl_op.payload).data; |
| 473 | 473 | |
| 474 | 474 | try w.writeOperand(s, inst, 0, extra.lhs); |
| ... | ... | @@ -479,7 +479,7 @@ const Writer = struct { |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | fn writeShuffle(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 482 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 482 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 483 | 483 | const extra = w.air.extraData(Air.Shuffle, ty_pl.payload).data; |
| 484 | 484 | |
| 485 | 485 | try w.writeOperand(s, inst, 0, extra.a); |
| ... | ... | @@ -490,7 +490,7 @@ const Writer = struct { |
| 490 | 490 | |
| 491 | 491 | fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 492 | 492 | const mod = w.module; |
| 493 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 493 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 494 | 494 | const extra = w.air.extraData(Air.Bin, pl_op.payload).data; |
| 495 | 495 | |
| 496 | 496 | const elem_ty = w.typeOfIndex(inst).childType(mod); |
| ... | ... | @@ -504,14 +504,14 @@ const Writer = struct { |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | fn writeReduce(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 507 | const reduce = w.air.instructions.items(.data)[inst].reduce; | |
| 507 | const reduce = w.air.instructions.items(.data)[@intFromEnum(inst)].reduce; | |
| 508 | 508 | |
| 509 | 509 | try w.writeOperand(s, inst, 0, reduce.operand); |
| 510 | 510 | try s.print(", {s}", .{@tagName(reduce.operation)}); |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | fn writeCmpVector(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 514 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 514 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 515 | 515 | const extra = w.air.extraData(Air.VectorCmp, ty_pl.payload).data; |
| 516 | 516 | |
| 517 | 517 | try s.print("{s}, ", .{@tagName(extra.compareOperator())}); |
| ... | ... | @@ -521,7 +521,7 @@ const Writer = struct { |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | fn writeVectorStoreElem(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 524 | const data = w.air.instructions.items(.data)[inst].vector_store_elem; | |
| 524 | const data = w.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem; | |
| 525 | 525 | const extra = w.air.extraData(Air.VectorCmp, data.payload).data; |
| 526 | 526 | |
| 527 | 527 | try w.writeOperand(s, inst, 0, data.vector_ptr); |
| ... | ... | @@ -532,20 +532,20 @@ const Writer = struct { |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | fn writeFence(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 535 | const atomic_order = w.air.instructions.items(.data)[inst].fence; | |
| 535 | const atomic_order = w.air.instructions.items(.data)[@intFromEnum(inst)].fence; | |
| 536 | 536 | |
| 537 | 537 | try s.print("{s}", .{@tagName(atomic_order)}); |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | fn writeAtomicLoad(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 541 | const atomic_load = w.air.instructions.items(.data)[inst].atomic_load; | |
| 541 | const atomic_load = w.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; | |
| 542 | 542 | |
| 543 | 543 | try w.writeOperand(s, inst, 0, atomic_load.ptr); |
| 544 | 544 | try s.print(", {s}", .{@tagName(atomic_load.order)}); |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | fn writePrefetch(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 548 | const prefetch = w.air.instructions.items(.data)[inst].prefetch; | |
| 548 | const prefetch = w.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; | |
| 549 | 549 | |
| 550 | 550 | try w.writeOperand(s, inst, 0, prefetch.ptr); |
| 551 | 551 | try s.print(", {s}, {d}, {s}", .{ |
| ... | ... | @@ -559,7 +559,7 @@ const Writer = struct { |
| 559 | 559 | inst: Air.Inst.Index, |
| 560 | 560 | order: std.builtin.AtomicOrder, |
| 561 | 561 | ) @TypeOf(s).Error!void { |
| 562 | const bin_op = w.air.instructions.items(.data)[inst].bin_op; | |
| 562 | const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | |
| 563 | 563 | try w.writeOperand(s, inst, 0, bin_op.lhs); |
| 564 | 564 | try s.writeAll(", "); |
| 565 | 565 | try w.writeOperand(s, inst, 1, bin_op.rhs); |
| ... | ... | @@ -567,7 +567,7 @@ const Writer = struct { |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | fn writeAtomicRmw(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 570 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 570 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 571 | 571 | const extra = w.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 572 | 572 | |
| 573 | 573 | try w.writeOperand(s, inst, 0, pl_op.operand); |
| ... | ... | @@ -577,7 +577,7 @@ const Writer = struct { |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | fn writeFieldParentPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 580 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 580 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 581 | 581 | const extra = w.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 582 | 582 | |
| 583 | 583 | try w.writeOperand(s, inst, 0, extra.field_ptr); |
| ... | ... | @@ -585,7 +585,7 @@ const Writer = struct { |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 588 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 588 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 589 | 589 | const extra = w.air.extraData(Air.Asm, ty_pl.payload); |
| 590 | 590 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; |
| 591 | 591 | const clobbers_len = @as(u31, @truncate(extra.data.flags)); |
| ... | ... | @@ -658,26 +658,26 @@ const Writer = struct { |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | fn writeDbgStmt(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 661 | const dbg_stmt = w.air.instructions.items(.data)[inst].dbg_stmt; | |
| 661 | const dbg_stmt = w.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; | |
| 662 | 662 | try s.print("{d}:{d}", .{ dbg_stmt.line + 1, dbg_stmt.column + 1 }); |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | fn writeDbgInline(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 666 | const ty_fn = w.air.instructions.items(.data)[inst].ty_fn; | |
| 666 | const ty_fn = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | |
| 667 | 667 | const func_index = ty_fn.func; |
| 668 | 668 | const owner_decl = w.module.funcOwnerDeclPtr(func_index); |
| 669 | 669 | try s.print("{}", .{owner_decl.name.fmt(&w.module.intern_pool)}); |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | fn writeDbgVar(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 673 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 673 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 674 | 674 | try w.writeOperand(s, inst, 0, pl_op.operand); |
| 675 | 675 | const name = w.air.nullTerminatedString(pl_op.payload); |
| 676 | 676 | try s.print(", \"{}\"", .{std.zig.fmtEscapes(name)}); |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | fn writeCall(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 680 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 680 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 681 | 681 | const extra = w.air.extraData(Air.Call, pl_op.payload); |
| 682 | 682 | const args = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[extra.end..][0..extra.data.args_len])); |
| 683 | 683 | try w.writeOperand(s, inst, 0, pl_op.operand); |
| ... | ... | @@ -690,16 +690,16 @@ const Writer = struct { |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | fn writeBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 693 | const br = w.air.instructions.items(.data)[inst].br; | |
| 693 | const br = w.air.instructions.items(.data)[@intFromEnum(inst)].br; | |
| 694 | 694 | try w.writeInstIndex(s, br.block_inst, false); |
| 695 | 695 | try s.writeAll(", "); |
| 696 | 696 | try w.writeOperand(s, inst, 0, br.operand); |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | fn writeTry(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 700 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 700 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 701 | 701 | const extra = w.air.extraData(Air.Try, pl_op.payload); |
| 702 | const body = w.air.extra[extra.end..][0..extra.data.body_len]; | |
| 702 | const body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end..][0..extra.data.body_len]); | |
| 703 | 703 | const liveness_condbr = if (w.liveness) |liveness| |
| 704 | 704 | liveness.getCondBr(inst) |
| 705 | 705 | else |
| ... | ... | @@ -731,9 +731,9 @@ const Writer = struct { |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | fn writeTryPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 734 | const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; | |
| 734 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | |
| 735 | 735 | const extra = w.air.extraData(Air.TryPtr, ty_pl.payload); |
| 736 | const body = w.air.extra[extra.end..][0..extra.data.body_len]; | |
| 736 | const body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra.end..][0..extra.data.body_len]); | |
| 737 | 737 | const liveness_condbr = if (w.liveness) |liveness| |
| 738 | 738 | liveness.getCondBr(inst) |
| 739 | 739 | else |
| ... | ... | @@ -742,7 +742,7 @@ const Writer = struct { |
| 742 | 742 | try w.writeOperand(s, inst, 0, extra.data.ptr); |
| 743 | 743 | |
| 744 | 744 | try s.writeAll(", "); |
| 745 | try w.writeType(s, w.air.getRefType(ty_pl.ty)); | |
| 745 | try w.writeType(s, ty_pl.ty.toType()); | |
| 746 | 746 | if (w.skip_body) return s.writeAll(", ..."); |
| 747 | 747 | try s.writeAll(", {\n"); |
| 748 | 748 | const old_indent = w.indent; |
| ... | ... | @@ -768,10 +768,10 @@ const Writer = struct { |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | fn writeCondBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 771 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 771 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 772 | 772 | const extra = w.air.extraData(Air.CondBr, pl_op.payload); |
| 773 | const then_body = w.air.extra[extra.end..][0..extra.data.then_body_len]; | |
| 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]); | |
| 775 | 775 | const liveness_condbr = if (w.liveness) |liveness| |
| 776 | 776 | liveness.getCondBr(inst) |
| 777 | 777 | else |
| ... | ... | @@ -813,7 +813,7 @@ const Writer = struct { |
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | fn writeSwitchBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 816 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 816 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 817 | 817 | const switch_br = w.air.extraData(Air.SwitchBr, pl_op.payload); |
| 818 | 818 | const liveness = if (w.liveness) |liveness| |
| 819 | 819 | liveness.getSwitchBr(w.gpa, inst, switch_br.data.cases_len + 1) catch |
| ... | ... | @@ -836,7 +836,7 @@ const Writer = struct { |
| 836 | 836 | while (case_i < switch_br.data.cases_len) : (case_i += 1) { |
| 837 | 837 | const case = w.air.extraData(Air.SwitchBr.Case, extra_index); |
| 838 | 838 | const items = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[case.end..][0..case.data.items_len])); |
| 839 | const case_body = w.air.extra[case.end + items.len ..][0..case.data.body_len]; | |
| 839 | const case_body: []const Air.Inst.Index = @ptrCast(w.air.extra[case.end + items.len ..][0..case.data.body_len]); | |
| 840 | 840 | extra_index = case.end + case.data.items_len + case_body.len; |
| 841 | 841 | |
| 842 | 842 | try s.writeAll(", ["); |
| ... | ... | @@ -863,7 +863,7 @@ const Writer = struct { |
| 863 | 863 | try s.writeAll("}"); |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | const else_body = w.air.extra[extra_index..][0..switch_br.data.else_body_len]; | |
| 866 | const else_body: []const Air.Inst.Index = @ptrCast(w.air.extra[extra_index..][0..switch_br.data.else_body_len]); | |
| 867 | 867 | if (else_body.len != 0) { |
| 868 | 868 | try s.writeAll(", else => {\n"); |
| 869 | 869 | w.indent += 2; |
| ... | ... | @@ -889,18 +889,18 @@ const Writer = struct { |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | fn writeWasmMemorySize(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 892 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 892 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 893 | 893 | try s.print("{d}", .{pl_op.payload}); |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | fn writeWasmMemoryGrow(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 897 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 897 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 898 | 898 | try s.print("{d}, ", .{pl_op.payload}); |
| 899 | 899 | try w.writeOperand(s, inst, 0, pl_op.operand); |
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | fn writeWorkDimension(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 903 | const pl_op = w.air.instructions.items(.data)[inst].pl_op; | |
| 903 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | |
| 904 | 904 | try s.print("{d}", .{pl_op.payload}); |
| 905 | 905 | } |
| 906 | 906 | |
| ... | ... | @@ -938,7 +938,7 @@ const Writer = struct { |
| 938 | 938 | ) @TypeOf(s).Error!void { |
| 939 | 939 | if (@intFromEnum(operand) < InternPool.static_len) { |
| 940 | 940 | return s.print("@{}", .{operand}); |
| 941 | } else if (Air.refToInterned(operand)) |ip_index| { | |
| 941 | } else if (operand.toInterned()) |ip_index| { | |
| 942 | 942 | const mod = w.module; |
| 943 | 943 | const ty = Type.fromInterned(mod.intern_pool.indexToKey(ip_index).typeOf()); |
| 944 | 944 | try s.print("<{}, {}>", .{ |
| ... | ... | @@ -946,7 +946,7 @@ const Writer = struct { |
| 946 | 946 | Value.fromInterned(ip_index).fmtValue(ty, mod), |
| 947 | 947 | }); |
| 948 | 948 | } else { |
| 949 | return w.writeInstIndex(s, Air.refToIndex(operand).?, dies); | |
| 949 | return w.writeInstIndex(s, operand.toIndex().?, dies); | |
| 950 | 950 | } |
| 951 | 951 | } |
| 952 | 952 |