Commit f47db0a0db

John Schmidt <john.schmidt.h@gmail.com>
2022-03-24 23:02:06
sema: use `pl_op` for `@select`
1 parent 12d5efc
src/arch/aarch64/CodeGen.zig
@@ -3748,10 +3748,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
 }
 
 fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
-    const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
-    const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
+    const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+    const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
     const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for {}", .{self.target.cpu.arch});
-    return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b });
+    return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
 }
 
 fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
src/arch/arm/CodeGen.zig
@@ -4325,10 +4325,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
 }
 
 fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
-    const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
-    const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
+    const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+    const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
     const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for arm", .{});
-    return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b });
+    return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
 }
 
 fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
src/arch/riscv64/CodeGen.zig
@@ -2398,10 +2398,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
 }
 
 fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
-    const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
-    const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
+    const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+    const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
     const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for riscv64", .{});
-    return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b });
+    return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
 }
 
 fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
src/arch/wasm/CodeGen.zig
@@ -3269,10 +3269,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
 fn airSelect(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
     if (self.liveness.isUnused(inst)) return WValue{ .none = {} };
 
-    const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
-    const ty = try self.resolveInst(ty_pl.ty);
+    const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+    const operand = try self.resolveInst(pl_op.operand);
 
-    _ = ty;
+    _ = operand;
     return self.fail("TODO: Implement wasm airSelect", .{});
 }
 
src/arch/x86_64/CodeGen.zig
@@ -5680,10 +5680,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
 }
 
 fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
-    const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
-    const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
+    const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+    const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
     const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for x86_64", .{});
-    return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b });
+    return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs });
 }
 
 fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
src/codegen/llvm.zig
@@ -6359,11 +6359,11 @@ pub const FuncGen = struct {
     fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
         if (self.liveness.isUnused(inst)) return null;
 
-        const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
-        const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
-        const pred = try self.resolveInst(extra.pred);
-        const a = try self.resolveInst(extra.a);
-        const b = try self.resolveInst(extra.b);
+        const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+        const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
+        const pred = try self.resolveInst(pl_op.operand);
+        const a = try self.resolveInst(extra.lhs);
+        const b = try self.resolveInst(extra.rhs);
 
         return self.builder.buildSelect(pred, a, b, "");
     }
src/Air.zig
@@ -554,7 +554,7 @@ pub const Inst = struct {
         /// Uses the `ty_pl` field with payload `Shuffle`.
         shuffle,
         /// Constructs a vector element-wise from `a` or `b` based on `pred`.
-        /// Uses the `ty_pl` field with payload `Select`.
+        /// Uses the `pl_op` field with `pred` as operand, and payload `Bin`.
         select,
 
         /// Given dest ptr, value, and len, set all elements at dest to value.
@@ -788,12 +788,6 @@ pub const Shuffle = struct {
     mask_len: u32,
 };
 
-pub const Select = struct {
-    pred: Inst.Ref,
-    a: Inst.Ref,
-    b: Inst.Ref,
-};
-
 pub const VectorCmp = struct {
     lhs: Inst.Ref,
     rhs: Inst.Ref,
@@ -965,7 +959,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
         .cmpxchg_weak,
         .cmpxchg_strong,
         .slice,
-        .select,
         .shuffle,
         .aggregate_init,
         .union_init,
@@ -1077,6 +1070,10 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
         .reduce => return air.typeOf(datas[inst].reduce.operand).childType(),
 
         .mul_add => return air.typeOf(datas[inst].pl_op.operand),
+        .select => {
+            const extra = air.extraData(Air.Bin, datas[inst].pl_op.payload).data;
+            return air.typeOf(extra.lhs);
+        },
 
         .add_with_overflow,
         .sub_with_overflow,
src/Liveness.zig
@@ -434,8 +434,9 @@ fn analyzeInst(
             return extra_tombs.finish();
         },
         .select => {
-            const extra = a.air.extraData(Air.Select, inst_datas[inst].ty_pl.payload).data;
-            return trackOperands(a, new_set, inst, main_tomb, .{ extra.pred, extra.a, extra.b });
+            const pl_op = inst_datas[inst].pl_op;
+            const extra = a.air.extraData(Air.Bin, pl_op.payload).data;
+            return trackOperands(a, new_set, inst, main_tomb, .{ pl_op.operand, extra.lhs, extra.rhs });
         },
         .shuffle => {
             const extra = a.air.extraData(Air.Shuffle, inst_datas[inst].ty_pl.payload).data;
src/print_air.zig
@@ -398,15 +398,16 @@ const Writer = struct {
     }
 
     fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
-        const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
-        const extra = w.air.extraData(Air.Select, ty_pl.payload).data;
+        const pl_op = w.air.instructions.items(.data)[inst].pl_op;
+        const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
 
-        try s.print("{}, ", .{w.air.getRefType(ty_pl.ty).fmtDebug()});
-        try w.writeOperand(s, inst, 0, extra.pred);
+        const elem_ty = w.air.typeOfIndex(inst).childType();
+        try s.print("{}, ", .{elem_ty.fmtDebug()});
+        try w.writeOperand(s, inst, 0, pl_op.operand);
         try s.writeAll(", ");
-        try w.writeOperand(s, inst, 1, extra.a);
+        try w.writeOperand(s, inst, 1, extra.lhs);
         try s.writeAll(", ");
-        try w.writeOperand(s, inst, 2, extra.b);
+        try w.writeOperand(s, inst, 2, extra.rhs);
     }
 
     fn writeReduce(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
src/Sema.zig
@@ -14894,12 +14894,11 @@ fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
     try sema.requireRuntimeBlock(block, runtime_src);
     return block.addInst(.{
         .tag = .select,
-        .data = .{ .ty_pl = .{
-            .ty = try block.sema.addType(vec_ty),
-            .payload = try block.sema.addExtra(Air.Select{
-                .pred = pred,
-                .a = a,
-                .b = b,
+        .data = .{ .pl_op = .{
+            .operand = pred,
+            .payload = try block.sema.addExtra(Air.Bin{
+                .lhs = a,
+                .rhs = b,
             }),
         } },
     });