authorgravatar for john.schmidt.h@gmail.comJohn Schmidt <john.schmidt.h@gmail.com> 2022-03-24 23:02:06+01:00
committergravatar for john.schmidt.h@gmail.comJohn Schmidt <john.schmidt.h@gmail.com> 2022-03-25 16:13:54+01:00
logf47db0a0dbf64f1fef0ba86bd9f684a5df29bc3d
treed6b639b6f06472aca726dd6c5314b5e94600ca32
parent12d5efcbe621b98b5a99c5f84a9d5b605e4acc40

sema: use `pl_op` for `@select`


10 files changed, 40 insertions(+), 42 deletions(-)

src/Air.zig+5-8
......@@ -554,7 +554,7 @@ pub const Inst = struct {
554554 /// Uses the `ty_pl` field with payload `Shuffle`.
555555 shuffle,
556556 /// Constructs a vector element-wise from `a` or `b` based on `pred`.
557 /// Uses the `ty_pl` field with payload `Select`.
557 /// Uses the `pl_op` field with `pred` as operand, and payload `Bin`.
558558 select,
559559
560560 /// Given dest ptr, value, and len, set all elements at dest to value.
......@@ -788,12 +788,6 @@ pub const Shuffle = struct {
788788 mask_len: u32,
789789};
790790
791pub const Select = struct {
792 pred: Inst.Ref,
793 a: Inst.Ref,
794 b: Inst.Ref,
795};
796
797791pub const VectorCmp = struct {
798792 lhs: Inst.Ref,
799793 rhs: Inst.Ref,
......@@ -965,7 +959,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
965959 .cmpxchg_weak,
966960 .cmpxchg_strong,
967961 .slice,
968 .select,
969962 .shuffle,
970963 .aggregate_init,
971964 .union_init,
......@@ -1077,6 +1070,10 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
10771070 .reduce => return air.typeOf(datas[inst].reduce.operand).childType(),
10781071
10791072 .mul_add => return air.typeOf(datas[inst].pl_op.operand),
1073 .select => {
1074 const extra = air.extraData(Air.Bin, datas[inst].pl_op.payload).data;
1075 return air.typeOf(extra.lhs);
1076 },
10801077
10811078 .add_with_overflow,
10821079 .sub_with_overflow,
src/Liveness.zig+3-2
......@@ -434,8 +434,9 @@ fn analyzeInst(
434434 return extra_tombs.finish();
435435 },
436436 .select => {
437 const extra = a.air.extraData(Air.Select, inst_datas[inst].ty_pl.payload).data;
438 return trackOperands(a, new_set, inst, main_tomb, .{ extra.pred, extra.a, extra.b });
437 const pl_op = inst_datas[inst].pl_op;
438 const extra = a.air.extraData(Air.Bin, pl_op.payload).data;
439 return trackOperands(a, new_set, inst, main_tomb, .{ pl_op.operand, extra.lhs, extra.rhs });
439440 },
440441 .shuffle => {
441442 const extra = a.air.extraData(Air.Shuffle, inst_datas[inst].ty_pl.payload).data;
src/Sema.zig+5-6
......@@ -14894,12 +14894,11 @@ fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1489414894 try sema.requireRuntimeBlock(block, runtime_src);
1489514895 return block.addInst(.{
1489614896 .tag = .select,
14897 .data = .{ .ty_pl = .{
14898 .ty = try block.sema.addType(vec_ty),
14899 .payload = try block.sema.addExtra(Air.Select{
14900 .pred = pred,
14901 .a = a,
14902 .b = b,
14897 .data = .{ .pl_op = .{
14898 .operand = pred,
14899 .payload = try block.sema.addExtra(Air.Bin{
14900 .lhs = a,
14901 .rhs = b,
1490314902 }),
1490414903 } },
1490514904 });
src/arch/aarch64/CodeGen.zig+3-3
......@@ -3748,10 +3748,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
37483748}
37493749
37503750fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
3751 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
3752 const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
3751 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
3752 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
37533753 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for {}", .{self.target.cpu.arch});
3754 return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b });
3754 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
37553755}
37563756
37573757fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
src/arch/arm/CodeGen.zig+3-3
......@@ -4325,10 +4325,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
43254325}
43264326
43274327fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
4328 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
4329 const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
4328 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
4329 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
43304330 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for arm", .{});
4331 return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b });
4331 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
43324332}
43334333
43344334fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
src/arch/riscv64/CodeGen.zig+3-3
......@@ -2398,10 +2398,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
23982398}
23992399
24002400fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
2401 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
2402 const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
2401 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
2402 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
24032403 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for riscv64", .{});
2404 return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b });
2404 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
24052405}
24062406
24072407fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
src/arch/wasm/CodeGen.zig+3-3
......@@ -3269,10 +3269,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
32693269fn airSelect(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
32703270 if (self.liveness.isUnused(inst)) return WValue{ .none = {} };
32713271
3272 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
3273 const ty = try self.resolveInst(ty_pl.ty);
3272 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
3273 const operand = try self.resolveInst(pl_op.operand);
32743274
3275 _ = ty;
3275 _ = operand;
32763276 return self.fail("TODO: Implement wasm airSelect", .{});
32773277}
32783278
src/arch/x86_64/CodeGen.zig+3-3
......@@ -5680,10 +5680,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
56805680}
56815681
56825682fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
5683 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
5684 const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
5683 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
5684 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
56855685 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for x86_64", .{});
5686 return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b });
5686 return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
56875687}
56885688
56895689fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
src/codegen/llvm.zig+5-5
......@@ -6359,11 +6359,11 @@ pub const FuncGen = struct {
63596359 fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
63606360 if (self.liveness.isUnused(inst)) return null;
63616361
6362 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
6363 const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
6364 const pred = try self.resolveInst(extra.pred);
6365 const a = try self.resolveInst(extra.a);
6366 const b = try self.resolveInst(extra.b);
6362 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
6363 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
6364 const pred = try self.resolveInst(pl_op.operand);
6365 const a = try self.resolveInst(extra.lhs);
6366 const b = try self.resolveInst(extra.rhs);
63676367
63686368 return self.builder.buildSelect(pred, a, b, "");
63696369 }
src/print_air.zig+7-6
......@@ -398,15 +398,16 @@ const Writer = struct {
398398 }
399399
400400 fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
401 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
402 const extra = w.air.extraData(Air.Select, ty_pl.payload).data;
401 const pl_op = w.air.instructions.items(.data)[inst].pl_op;
402 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
403403
404 try s.print("{}, ", .{w.air.getRefType(ty_pl.ty).fmtDebug()});
405 try w.writeOperand(s, inst, 0, extra.pred);
404 const elem_ty = w.air.typeOfIndex(inst).childType();
405 try s.print("{}, ", .{elem_ty.fmtDebug()});
406 try w.writeOperand(s, inst, 0, pl_op.operand);
406407 try s.writeAll(", ");
407 try w.writeOperand(s, inst, 1, extra.a);
408 try w.writeOperand(s, inst, 1, extra.lhs);
408409 try s.writeAll(", ");
409 try w.writeOperand(s, inst, 2, extra.b);
410 try w.writeOperand(s, inst, 2, extra.rhs);
410411 }
411412
412413 fn writeReduce(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {