authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2024-02-09 12:50:23+03:30
committergravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2024-02-10 09:50:02+03:30
log72bd1cd378dcdb96217473baee899528c21bcbbc
tree392e3e7d57e0ab3ede27c22816fdc2f9eee09ad5
parent5ee96688a7456b9581fa605520fe90f6723bb95b

spirv: remove now-redundant isUnused calls from AIR handler functions


1 files changed, 11 insertions(+), 88 deletions(-)

src/codegen/spirv.zig+11-88
...@@ -947,19 +947,19 @@ const DeclGen = struct {...@@ -947,19 +947,19 @@ const DeclGen = struct {
947 .bytes => |bytes| {947 .bytes => |bytes| {
948 // TODO: This is really space inefficient, perhaps there is a better948 // TODO: This is really space inefficient, perhaps there is a better
949 // way to do it?949 // way to do it?
950 for (constituents, bytes) |*constituent, byte| {950 for (bytes, 0..) |byte, i| {
951 constituent.* = try self.constInt(elem_ty_ref, byte);951 constituents[i] = try self.constInt(elem_ty_ref, byte);
952 }952 }
953 },953 },
954 .elems => |elems| {954 .elems => |elems| {
955 for (constituents, elems) |*constituent, elem| {955 for (0..@as(usize, @intCast(array_type.len))) |i| {
956 constituent.* = try self.constant(elem_ty, Value.fromInterned(elem), .indirect);956 constituents[i] = try self.constant(elem_ty, Value.fromInterned(elems[i]), .indirect);
957 }957 }
958 },958 },
959 .repeated_elem => |elem| {959 .repeated_elem => |elem| {
960 const val_id = try self.constant(elem_ty, Value.fromInterned(elem), .indirect);960 const val_id = try self.constant(elem_ty, Value.fromInterned(elem), .indirect);
961 for (constituents) |*constituent| {961 for (0..@as(usize, @intCast(array_type.len))) |i| {
962 constituent.* = val_id;962 constituents[i] = val_id;
963 }963 }
964 },964 },
965 }965 }
...@@ -2199,7 +2199,6 @@ const DeclGen = struct {...@@ -2199,7 +2199,6 @@ const DeclGen = struct {
2199 fn genInst(self: *DeclGen, inst: Air.Inst.Index) !void {2199 fn genInst(self: *DeclGen, inst: Air.Inst.Index) !void {
2200 const mod = self.module;2200 const mod = self.module;
2201 const ip = &mod.intern_pool;2201 const ip = &mod.intern_pool;
2202 // TODO: remove now-redundant isUnused calls from AIR handler functions
2203 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))2202 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
2204 return;2203 return;
22052204
...@@ -2365,8 +2364,6 @@ const DeclGen = struct {...@@ -2365,8 +2364,6 @@ const DeclGen = struct {
2365 }2364 }
23662365
2367 fn airBinOpSimple(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {2366 fn airBinOpSimple(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {
2368 if (self.liveness.isUnused(inst)) return null;
2369
2370 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;2367 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2371 const lhs_id = try self.resolve(bin_op.lhs);2368 const lhs_id = try self.resolve(bin_op.lhs);
2372 const rhs_id = try self.resolve(bin_op.rhs);2369 const rhs_id = try self.resolve(bin_op.rhs);
...@@ -2376,7 +2373,6 @@ const DeclGen = struct {...@@ -2376,7 +2373,6 @@ const DeclGen = struct {
2376 }2373 }
23772374
2378 fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime unsigned: Opcode, comptime signed: Opcode) !?IdRef {2375 fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime unsigned: Opcode, comptime signed: Opcode) !?IdRef {
2379 if (self.liveness.isUnused(inst)) return null;
2380 const mod = self.module;2376 const mod = self.module;
2381 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;2377 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2382 const lhs_id = try self.resolve(bin_op.lhs);2378 const lhs_id = try self.resolve(bin_op.lhs);
...@@ -2431,8 +2427,6 @@ const DeclGen = struct {...@@ -2431,8 +2427,6 @@ const DeclGen = struct {
2431 }2427 }
24322428
2433 fn airMinMax(self: *DeclGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !?IdRef {2429 fn airMinMax(self: *DeclGen, inst: Air.Inst.Index, op: std.math.CompareOperator) !?IdRef {
2434 if (self.liveness.isUnused(inst)) return null;
2435
2436 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;2430 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2437 const lhs_id = try self.resolve(bin_op.lhs);2431 const lhs_id = try self.resolve(bin_op.lhs);
2438 const rhs_id = try self.resolve(bin_op.rhs);2432 const rhs_id = try self.resolve(bin_op.rhs);
...@@ -2544,7 +2538,6 @@ const DeclGen = struct {...@@ -2544,7 +2538,6 @@ const DeclGen = struct {
2544 comptime sop: Opcode,2538 comptime sop: Opcode,
2545 comptime uop: Opcode,2539 comptime uop: Opcode,
2546 ) !?IdRef {2540 ) !?IdRef {
2547 if (self.liveness.isUnused(inst)) return null;
25482541
2549 // LHS and RHS are guaranteed to have the same type, and AIR guarantees2542 // LHS and RHS are guaranteed to have the same type, and AIR guarantees
2550 // the result to be the same as the LHS and RHS, which matches SPIR-V.2543 // the result to be the same as the LHS and RHS, which matches SPIR-V.
...@@ -2614,8 +2607,6 @@ const DeclGen = struct {...@@ -2614,8 +2607,6 @@ const DeclGen = struct {
2614 }2607 }
26152608
2616 fn airAbs(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2609 fn airAbs(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2617 if (self.liveness.isUnused(inst)) return null;
2618
2619 const mod = self.module;2610 const mod = self.module;
2620 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2611 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2621 const operand_id = try self.resolve(ty_op.operand);2612 const operand_id = try self.resolve(ty_op.operand);
...@@ -2678,8 +2669,6 @@ const DeclGen = struct {...@@ -2678,8 +2669,6 @@ const DeclGen = struct {
2678 comptime ucmp: Opcode,2669 comptime ucmp: Opcode,
2679 comptime scmp: Opcode,2670 comptime scmp: Opcode,
2680 ) !?IdRef {2671 ) !?IdRef {
2681 if (self.liveness.isUnused(inst)) return null;
2682
2683 const mod = self.module;2672 const mod = self.module;
2684 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;2673 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2685 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2674 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
...@@ -2793,7 +2782,6 @@ const DeclGen = struct {...@@ -2793,7 +2782,6 @@ const DeclGen = struct {
2793 }2782 }
27942783
2795 fn airShlOverflow(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2784 fn airShlOverflow(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2796 if (self.liveness.isUnused(inst)) return null;
2797 const mod = self.module;2785 const mod = self.module;
2798 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;2786 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2799 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2787 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
...@@ -2887,8 +2875,6 @@ const DeclGen = struct {...@@ -2887,8 +2875,6 @@ const DeclGen = struct {
2887 }2875 }
28882876
2889 fn airMulAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2877 fn airMulAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2890 if (self.liveness.isUnused(inst)) return null;
2891
2892 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;2878 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
2893 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;2879 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
28942880
...@@ -2923,7 +2909,6 @@ const DeclGen = struct {...@@ -2923,7 +2909,6 @@ const DeclGen = struct {
2923 }2909 }
29242910
2925 fn airSplat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2911 fn airSplat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2926 if (self.liveness.isUnused(inst)) return null;
2927 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2912 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2928 const operand_id = try self.resolve(ty_op.operand);2913 const operand_id = try self.resolve(ty_op.operand);
2929 const result_ty = self.typeOfIndex(inst);2914 const result_ty = self.typeOfIndex(inst);
...@@ -2934,7 +2919,6 @@ const DeclGen = struct {...@@ -2934,7 +2919,6 @@ const DeclGen = struct {
2934 }2919 }
29352920
2936 fn airReduce(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2921 fn airReduce(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2937 if (self.liveness.isUnused(inst)) return null;
2938 const mod = self.module;2922 const mod = self.module;
2939 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;2923 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
2940 const operand = try self.resolve(reduce.operand);2924 const operand = try self.resolve(reduce.operand);
...@@ -3002,7 +2986,6 @@ const DeclGen = struct {...@@ -3002,7 +2986,6 @@ const DeclGen = struct {
30022986
3003 fn airShuffle(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2987 fn airShuffle(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3004 const mod = self.module;2988 const mod = self.module;
3005 if (self.liveness.isUnused(inst)) return null;
3006 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;2989 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3007 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;2990 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
3008 const a = try self.resolve(extra.a);2991 const a = try self.resolve(extra.a);
...@@ -3115,7 +3098,6 @@ const DeclGen = struct {...@@ -3115,7 +3098,6 @@ const DeclGen = struct {
3115 }3098 }
31163099
3117 fn airPtrAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3100 fn airPtrAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3118 if (self.liveness.isUnused(inst)) return null;
3119 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3101 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3120 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3102 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3121 const ptr_id = try self.resolve(bin_op.lhs);3103 const ptr_id = try self.resolve(bin_op.lhs);
...@@ -3127,7 +3109,6 @@ const DeclGen = struct {...@@ -3127,7 +3109,6 @@ const DeclGen = struct {
3127 }3109 }
31283110
3129 fn airPtrSub(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3111 fn airPtrSub(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3130 if (self.liveness.isUnused(inst)) return null;
3131 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3112 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3132 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3113 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3133 const ptr_id = try self.resolve(bin_op.lhs);3114 const ptr_id = try self.resolve(bin_op.lhs);
...@@ -3303,7 +3284,6 @@ const DeclGen = struct {...@@ -3303,7 +3284,6 @@ const DeclGen = struct {
3303 inst: Air.Inst.Index,3284 inst: Air.Inst.Index,
3304 comptime op: std.math.CompareOperator,3285 comptime op: std.math.CompareOperator,
3305 ) !?IdRef {3286 ) !?IdRef {
3306 if (self.liveness.isUnused(inst)) return null;
3307 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3287 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3308 const lhs_id = try self.resolve(bin_op.lhs);3288 const lhs_id = try self.resolve(bin_op.lhs);
3309 const rhs_id = try self.resolve(bin_op.rhs);3289 const rhs_id = try self.resolve(bin_op.rhs);
...@@ -3314,8 +3294,6 @@ const DeclGen = struct {...@@ -3314,8 +3294,6 @@ const DeclGen = struct {
3314 }3294 }
33153295
3316 fn airVectorCmp(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3296 fn airVectorCmp(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3317 if (self.liveness.isUnused(inst)) return null;
3318
3319 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3297 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3320 const vec_cmp = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;3298 const vec_cmp = self.air.extraData(Air.VectorCmp, ty_pl.payload).data;
3321 const lhs_id = try self.resolve(vec_cmp.lhs);3299 const lhs_id = try self.resolve(vec_cmp.lhs);
...@@ -3397,7 +3375,6 @@ const DeclGen = struct {...@@ -3397,7 +3375,6 @@ const DeclGen = struct {
3397 }3375 }
33983376
3399 fn airBitCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3377 fn airBitCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3400 if (self.liveness.isUnused(inst)) return null;
3401 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3378 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3402 const operand_id = try self.resolve(ty_op.operand);3379 const operand_id = try self.resolve(ty_op.operand);
3403 const operand_ty = self.typeOf(ty_op.operand);3380 const operand_ty = self.typeOf(ty_op.operand);
...@@ -3406,8 +3383,6 @@ const DeclGen = struct {...@@ -3406,8 +3383,6 @@ const DeclGen = struct {
3406 }3383 }
34073384
3408 fn airIntCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3385 fn airIntCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3409 if (self.liveness.isUnused(inst)) return null;
3410
3411 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3386 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3412 const operand_id = try self.resolve(ty_op.operand);3387 const operand_id = try self.resolve(ty_op.operand);
3413 const src_ty = self.typeOf(ty_op.operand);3388 const src_ty = self.typeOf(ty_op.operand);
...@@ -3463,16 +3438,12 @@ const DeclGen = struct {...@@ -3463,16 +3438,12 @@ const DeclGen = struct {
3463 }3438 }
34643439
3465 fn airIntFromPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3440 fn airIntFromPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3466 if (self.liveness.isUnused(inst)) return null;
3467
3468 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;3441 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
3469 const operand_id = try self.resolve(un_op);3442 const operand_id = try self.resolve(un_op);
3470 return try self.intFromPtr(operand_id);3443 return try self.intFromPtr(operand_id);
3471 }3444 }
34723445
3473 fn airFloatFromInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3446 fn airFloatFromInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3474 if (self.liveness.isUnused(inst)) return null;
3475
3476 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3447 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3477 const operand_ty = self.typeOf(ty_op.operand);3448 const operand_ty = self.typeOf(ty_op.operand);
3478 const operand_id = try self.resolve(ty_op.operand);3449 const operand_id = try self.resolve(ty_op.operand);
...@@ -3497,8 +3468,6 @@ const DeclGen = struct {...@@ -3497,8 +3468,6 @@ const DeclGen = struct {
3497 }3468 }
34983469
3499 fn airIntFromFloat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3470 fn airIntFromFloat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3500 if (self.liveness.isUnused(inst)) return null;
3501
3502 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3471 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3503 const operand_id = try self.resolve(ty_op.operand);3472 const operand_id = try self.resolve(ty_op.operand);
3504 const dest_ty = self.typeOfIndex(inst);3473 const dest_ty = self.typeOfIndex(inst);
...@@ -3522,8 +3491,6 @@ const DeclGen = struct {...@@ -3522,8 +3491,6 @@ const DeclGen = struct {
3522 }3491 }
35233492
3524 fn airIntFromBool(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3493 fn airIntFromBool(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3525 if (self.liveness.isUnused(inst)) return null;
3526
3527 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;3494 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
3528 const operand_id = try self.resolve(un_op);3495 const operand_id = try self.resolve(un_op);
3529 const result_ty = self.typeOfIndex(inst);3496 const result_ty = self.typeOfIndex(inst);
...@@ -3538,8 +3505,6 @@ const DeclGen = struct {...@@ -3538,8 +3505,6 @@ const DeclGen = struct {
3538 }3505 }
35393506
3540 fn airFloatCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3507 fn airFloatCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3541 if (self.liveness.isUnused(inst)) return null;
3542
3543 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3508 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3544 const operand_id = try self.resolve(ty_op.operand);3509 const operand_id = try self.resolve(ty_op.operand);
3545 const dest_ty = self.typeOfIndex(inst);3510 const dest_ty = self.typeOfIndex(inst);
...@@ -3555,7 +3520,6 @@ const DeclGen = struct {...@@ -3555,7 +3520,6 @@ const DeclGen = struct {
3555 }3520 }
35563521
3557 fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3522 fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3558 if (self.liveness.isUnused(inst)) return null;
3559 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3523 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3560 const operand_id = try self.resolve(ty_op.operand);3524 const operand_id = try self.resolve(ty_op.operand);
3561 const result_ty = self.typeOfIndex(inst);3525 const result_ty = self.typeOfIndex(inst);
...@@ -3587,8 +3551,6 @@ const DeclGen = struct {...@@ -3587,8 +3551,6 @@ const DeclGen = struct {
3587 }3551 }
35883552
3589 fn airArrayToSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3553 fn airArrayToSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3590 if (self.liveness.isUnused(inst)) return null;
3591
3592 const mod = self.module;3554 const mod = self.module;
3593 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3555 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3594 const array_ptr_ty = self.typeOf(ty_op.operand);3556 const array_ptr_ty = self.typeOf(ty_op.operand);
...@@ -3613,8 +3575,6 @@ const DeclGen = struct {...@@ -3613,8 +3575,6 @@ const DeclGen = struct {
3613 }3575 }
36143576
3615 fn airSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3577 fn airSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3616 if (self.liveness.isUnused(inst)) return null;
3617
3618 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3578 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3619 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3579 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3620 const ptr_id = try self.resolve(bin_op.lhs);3580 const ptr_id = try self.resolve(bin_op.lhs);
...@@ -3627,8 +3587,6 @@ const DeclGen = struct {...@@ -3627,8 +3587,6 @@ const DeclGen = struct {
3627 }3587 }
36283588
3629 fn airAggregateInit(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3589 fn airAggregateInit(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3630 if (self.liveness.isUnused(inst)) return null;
3631
3632 const mod = self.module;3590 const mod = self.module;
3633 const ip = &mod.intern_pool;3591 const ip = &mod.intern_pool;
3634 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3592 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
...@@ -3681,9 +3639,9 @@ const DeclGen = struct {...@@ -3681,9 +3639,9 @@ const DeclGen = struct {
3681 const elem_ids = try self.gpa.alloc(IdRef, n_elems);3639 const elem_ids = try self.gpa.alloc(IdRef, n_elems);
3682 defer self.gpa.free(elem_ids);3640 defer self.gpa.free(elem_ids);
36833641
3684 for (elements, elem_ids) |element, *elem_id| {3642 for (elements, 0..) |element, i| {
3685 const id = try self.resolve(element);3643 const id = try self.resolve(element);
3686 elem_id.* = try self.convertToIndirect(result_ty.childType(mod), id);3644 elem_ids[i] = try self.convertToIndirect(result_ty.childType(mod), id);
3687 }3645 }
36883646
3689 return try self.constructComposite(result_ty, elem_ids);3647 return try self.constructComposite(result_ty, elem_ids);
...@@ -3694,9 +3652,9 @@ const DeclGen = struct {...@@ -3694,9 +3652,9 @@ const DeclGen = struct {
3694 const elem_ids = try self.gpa.alloc(IdRef, n_elems);3652 const elem_ids = try self.gpa.alloc(IdRef, n_elems);
3695 defer self.gpa.free(elem_ids);3653 defer self.gpa.free(elem_ids);
36963654
3697 for (elements, elem_ids) |element, *elem_id| {3655 for (elements, 0..) |element, i| {
3698 const id = try self.resolve(element);3656 const id = try self.resolve(element);
3699 elem_id.* = try self.convertToIndirect(array_info.elem_type, id);3657 elem_ids[i] = try self.convertToIndirect(array_info.elem_type, id);
3700 }3658 }
37013659
3702 if (array_info.sentinel) |sentinel_val| {3660 if (array_info.sentinel) |sentinel_val| {
...@@ -3750,7 +3708,6 @@ const DeclGen = struct {...@@ -3750,7 +3708,6 @@ const DeclGen = struct {
3750 }3708 }
37513709
3752 fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef {3710 fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef {
3753 if (self.liveness.isUnused(inst)) return null;
3754 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3711 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3755 const field_ty = self.typeOfIndex(inst);3712 const field_ty = self.typeOfIndex(inst);
3756 const operand_id = try self.resolve(ty_op.operand);3713 const operand_id = try self.resolve(ty_op.operand);
...@@ -3807,8 +3764,6 @@ const DeclGen = struct {...@@ -3807,8 +3764,6 @@ const DeclGen = struct {
3807 }3764 }
38083765
3809 fn airPtrElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3766 fn airPtrElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3810 if (self.liveness.isUnused(inst)) return null;
3811
3812 const mod = self.module;3767 const mod = self.module;
3813 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3768 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3814 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3769 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
...@@ -3826,8 +3781,6 @@ const DeclGen = struct {...@@ -3826,8 +3781,6 @@ const DeclGen = struct {
3826 }3781 }
38273782
3828 fn airArrayElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3783 fn airArrayElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3829 if (self.liveness.isUnused(inst)) return null;
3830
3831 const mod = self.module;3784 const mod = self.module;
3832 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3785 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3833 const array_ty = self.typeOf(bin_op.lhs);3786 const array_ty = self.typeOf(bin_op.lhs);
...@@ -3848,8 +3801,6 @@ const DeclGen = struct {...@@ -3848,8 +3801,6 @@ const DeclGen = struct {
3848 }3801 }
38493802
3850 fn airPtrElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3803 fn airPtrElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3851 if (self.liveness.isUnused(inst)) return null;
3852
3853 const mod = self.module;3804 const mod = self.module;
3854 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3805 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3855 const ptr_ty = self.typeOf(bin_op.lhs);3806 const ptr_ty = self.typeOf(bin_op.lhs);
...@@ -3906,8 +3857,6 @@ const DeclGen = struct {...@@ -3906,8 +3857,6 @@ const DeclGen = struct {
3906 }3857 }
39073858
3908 fn airGetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3859 fn airGetUnionTag(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3909 if (self.liveness.isUnused(inst)) return null;
3910
3911 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3860 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3912 const un_ty = self.typeOf(ty_op.operand);3861 const un_ty = self.typeOf(ty_op.operand);
39133862
...@@ -3991,8 +3940,6 @@ const DeclGen = struct {...@@ -3991,8 +3940,6 @@ const DeclGen = struct {
3991 }3940 }
39923941
3993 fn airUnionInit(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3942 fn airUnionInit(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3994 if (self.liveness.isUnused(inst)) return null;
3995
3996 const mod = self.module;3943 const mod = self.module;
3997 const ip = &mod.intern_pool;3944 const ip = &mod.intern_pool;
3998 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3945 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
...@@ -4009,8 +3956,6 @@ const DeclGen = struct {...@@ -4009,8 +3956,6 @@ const DeclGen = struct {
4009 }3956 }
40103957
4011 fn airStructFieldVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {3958 fn airStructFieldVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4012 if (self.liveness.isUnused(inst)) return null;
4013
4014 const mod = self.module;3959 const mod = self.module;
4015 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3960 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4016 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;3961 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
...@@ -4131,7 +4076,6 @@ const DeclGen = struct {...@@ -4131,7 +4076,6 @@ const DeclGen = struct {
4131 }4076 }
41324077
4133 fn airStructFieldPtrIndex(self: *DeclGen, inst: Air.Inst.Index, field_index: u32) !?IdRef {4078 fn airStructFieldPtrIndex(self: *DeclGen, inst: Air.Inst.Index, field_index: u32) !?IdRef {
4134 if (self.liveness.isUnused(inst)) return null;
4135 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4079 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4136 const struct_ptr = try self.resolve(ty_op.operand);4080 const struct_ptr = try self.resolve(ty_op.operand);
4137 const struct_ptr_ty = self.typeOf(ty_op.operand);4081 const struct_ptr_ty = self.typeOf(ty_op.operand);
...@@ -4185,7 +4129,6 @@ const DeclGen = struct {...@@ -4185,7 +4129,6 @@ const DeclGen = struct {
4185 }4129 }
41864130
4187 fn airAlloc(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4131 fn airAlloc(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4188 if (self.liveness.isUnused(inst)) return null;
4189 const mod = self.module;4132 const mod = self.module;
4190 const ptr_ty = self.typeOfIndex(inst);4133 const ptr_ty = self.typeOfIndex(inst);
4191 assert(ptr_ty.ptrAddressSpace(mod) == .generic);4134 assert(ptr_ty.ptrAddressSpace(mod) == .generic);
...@@ -4769,9 +4712,7 @@ const DeclGen = struct {...@@ -4769,9 +4712,7 @@ const DeclGen = struct {
47694712
4770 try self.beginSpvBlock(ok_block);4713 try self.beginSpvBlock(ok_block);
4771 }4714 }
4772 if (self.liveness.isUnused(inst)) {4715
4773 return null;
4774 }
4775 if (!eu_layout.payload_has_bits) {4716 if (!eu_layout.payload_has_bits) {
4776 return null;4717 return null;
4777 }4718 }
...@@ -4781,8 +4722,6 @@ const DeclGen = struct {...@@ -4781,8 +4722,6 @@ const DeclGen = struct {
4781 }4722 }
47824723
4783 fn airErrUnionErr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4724 fn airErrUnionErr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4784 if (self.liveness.isUnused(inst)) return null;
4785
4786 const mod = self.module;4725 const mod = self.module;
4787 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4726 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4788 const operand_id = try self.resolve(ty_op.operand);4727 const operand_id = try self.resolve(ty_op.operand);
...@@ -4806,8 +4745,6 @@ const DeclGen = struct {...@@ -4806,8 +4745,6 @@ const DeclGen = struct {
4806 }4745 }
48074746
4808 fn airErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4747 fn airErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4809 if (self.liveness.isUnused(inst)) return null;
4810
4811 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4748 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4812 const operand_id = try self.resolve(ty_op.operand);4749 const operand_id = try self.resolve(ty_op.operand);
4813 const payload_ty = self.typeOfIndex(inst);4750 const payload_ty = self.typeOfIndex(inst);
...@@ -4821,8 +4758,6 @@ const DeclGen = struct {...@@ -4821,8 +4758,6 @@ const DeclGen = struct {
4821 }4758 }
48224759
4823 fn airWrapErrUnionErr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4760 fn airWrapErrUnionErr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4824 if (self.liveness.isUnused(inst)) return null;
4825
4826 const mod = self.module;4761 const mod = self.module;
4827 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4762 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4828 const err_union_ty = self.typeOfIndex(inst);4763 const err_union_ty = self.typeOfIndex(inst);
...@@ -4844,8 +4779,6 @@ const DeclGen = struct {...@@ -4844,8 +4779,6 @@ const DeclGen = struct {
4844 }4779 }
48454780
4846 fn airWrapErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4781 fn airWrapErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4847 if (self.liveness.isUnused(inst)) return null;
4848
4849 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4782 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4850 const err_union_ty = self.typeOfIndex(inst);4783 const err_union_ty = self.typeOfIndex(inst);
4851 const operand_id = try self.resolve(ty_op.operand);4784 const operand_id = try self.resolve(ty_op.operand);
...@@ -4865,8 +4798,6 @@ const DeclGen = struct {...@@ -4865,8 +4798,6 @@ const DeclGen = struct {
4865 }4798 }
48664799
4867 fn airIsNull(self: *DeclGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum { is_null, is_non_null }) !?IdRef {4800 fn airIsNull(self: *DeclGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum { is_null, is_non_null }) !?IdRef {
4868 if (self.liveness.isUnused(inst)) return null;
4869
4870 const mod = self.module;4801 const mod = self.module;
4871 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4802 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4872 const operand_id = try self.resolve(un_op);4803 const operand_id = try self.resolve(un_op);
...@@ -4939,8 +4870,6 @@ const DeclGen = struct {...@@ -4939,8 +4870,6 @@ const DeclGen = struct {
4939 }4870 }
49404871
4941 fn airIsErr(self: *DeclGen, inst: Air.Inst.Index, pred: enum { is_err, is_non_err }) !?IdRef {4872 fn airIsErr(self: *DeclGen, inst: Air.Inst.Index, pred: enum { is_err, is_non_err }) !?IdRef {
4942 if (self.liveness.isUnused(inst)) return null;
4943
4944 const mod = self.module;4873 const mod = self.module;
4945 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4874 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4946 const operand_id = try self.resolve(un_op);4875 const operand_id = try self.resolve(un_op);
...@@ -4975,8 +4904,6 @@ const DeclGen = struct {...@@ -4975,8 +4904,6 @@ const DeclGen = struct {
4975 }4904 }
49764905
4977 fn airUnwrapOptional(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4906 fn airUnwrapOptional(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4978 if (self.liveness.isUnused(inst)) return null;
4979
4980 const mod = self.module;4907 const mod = self.module;
4981 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4908 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4982 const operand_id = try self.resolve(ty_op.operand);4909 const operand_id = try self.resolve(ty_op.operand);
...@@ -4993,8 +4920,6 @@ const DeclGen = struct {...@@ -4993,8 +4920,6 @@ const DeclGen = struct {
4993 }4920 }
49944921
4995 fn airUnwrapOptionalPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4922 fn airUnwrapOptionalPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
4996 if (self.liveness.isUnused(inst)) return null;
4997
4998 const mod = self.module;4923 const mod = self.module;
4999 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4924 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5000 const operand_id = try self.resolve(ty_op.operand);4925 const operand_id = try self.resolve(ty_op.operand);
...@@ -5019,8 +4944,6 @@ const DeclGen = struct {...@@ -5019,8 +4944,6 @@ const DeclGen = struct {
5019 }4944 }
50204945
5021 fn airWrapOptional(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {4946 fn airWrapOptional(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
5022 if (self.liveness.isUnused(inst)) return null;
5023
5024 const mod = self.module;4947 const mod = self.module;
5025 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4948 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5026 const payload_ty = self.typeOf(ty_op.operand);4949 const payload_ty = self.typeOf(ty_op.operand);