mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
sema: use pl_op for @select
This commit is contained in:
parent
12d5efcbe6
commit
f47db0a0db
10 changed files with 40 additions and 42 deletions
13
src/Air.zig
13
src/Air.zig
|
|
@ -554,7 +554,7 @@ pub const Inst = struct {
|
||||||
/// Uses the `ty_pl` field with payload `Shuffle`.
|
/// Uses the `ty_pl` field with payload `Shuffle`.
|
||||||
shuffle,
|
shuffle,
|
||||||
/// Constructs a vector element-wise from `a` or `b` based on `pred`.
|
/// 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,
|
select,
|
||||||
|
|
||||||
/// Given dest ptr, value, and len, set all elements at dest to value.
|
/// Given dest ptr, value, and len, set all elements at dest to value.
|
||||||
|
|
@ -788,12 +788,6 @@ pub const Shuffle = struct {
|
||||||
mask_len: u32,
|
mask_len: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Select = struct {
|
|
||||||
pred: Inst.Ref,
|
|
||||||
a: Inst.Ref,
|
|
||||||
b: Inst.Ref,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const VectorCmp = struct {
|
pub const VectorCmp = struct {
|
||||||
lhs: Inst.Ref,
|
lhs: Inst.Ref,
|
||||||
rhs: Inst.Ref,
|
rhs: Inst.Ref,
|
||||||
|
|
@ -965,7 +959,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
|
||||||
.cmpxchg_weak,
|
.cmpxchg_weak,
|
||||||
.cmpxchg_strong,
|
.cmpxchg_strong,
|
||||||
.slice,
|
.slice,
|
||||||
.select,
|
|
||||||
.shuffle,
|
.shuffle,
|
||||||
.aggregate_init,
|
.aggregate_init,
|
||||||
.union_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(),
|
.reduce => return air.typeOf(datas[inst].reduce.operand).childType(),
|
||||||
|
|
||||||
.mul_add => return air.typeOf(datas[inst].pl_op.operand),
|
.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,
|
.add_with_overflow,
|
||||||
.sub_with_overflow,
|
.sub_with_overflow,
|
||||||
|
|
|
||||||
|
|
@ -434,8 +434,9 @@ fn analyzeInst(
|
||||||
return extra_tombs.finish();
|
return extra_tombs.finish();
|
||||||
},
|
},
|
||||||
.select => {
|
.select => {
|
||||||
const extra = a.air.extraData(Air.Select, inst_datas[inst].ty_pl.payload).data;
|
const pl_op = inst_datas[inst].pl_op;
|
||||||
return trackOperands(a, new_set, inst, main_tomb, .{ extra.pred, extra.a, extra.b });
|
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 => {
|
.shuffle => {
|
||||||
const extra = a.air.extraData(Air.Shuffle, inst_datas[inst].ty_pl.payload).data;
|
const extra = a.air.extraData(Air.Shuffle, inst_datas[inst].ty_pl.payload).data;
|
||||||
|
|
|
||||||
11
src/Sema.zig
11
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);
|
try sema.requireRuntimeBlock(block, runtime_src);
|
||||||
return block.addInst(.{
|
return block.addInst(.{
|
||||||
.tag = .select,
|
.tag = .select,
|
||||||
.data = .{ .ty_pl = .{
|
.data = .{ .pl_op = .{
|
||||||
.ty = try block.sema.addType(vec_ty),
|
.operand = pred,
|
||||||
.payload = try block.sema.addExtra(Air.Select{
|
.payload = try block.sema.addExtra(Air.Bin{
|
||||||
.pred = pred,
|
.lhs = a,
|
||||||
.a = a,
|
.rhs = b,
|
||||||
.b = b,
|
|
||||||
}),
|
}),
|
||||||
} },
|
} },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3748,10 +3748,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airSelect(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 pl_op = self.air.instructions.items(.data)[inst].pl_op;
|
||||||
const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
|
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});
|
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 {
|
fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
|
||||||
|
|
|
||||||
|
|
@ -4325,10 +4325,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airSelect(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 pl_op = self.air.instructions.items(.data)[inst].pl_op;
|
||||||
const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
|
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", .{});
|
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 {
|
fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
|
||||||
|
|
|
||||||
|
|
@ -2398,10 +2398,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airSelect(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 pl_op = self.air.instructions.items(.data)[inst].pl_op;
|
||||||
const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
|
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", .{});
|
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 {
|
fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
|
||||||
|
|
|
||||||
|
|
@ -3269,10 +3269,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
|
||||||
fn airSelect(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 = {} };
|
if (self.liveness.isUnused(inst)) return WValue{ .none = {} };
|
||||||
|
|
||||||
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
|
const pl_op = self.air.instructions.items(.data)[inst].pl_op;
|
||||||
const ty = try self.resolveInst(ty_pl.ty);
|
const operand = try self.resolveInst(pl_op.operand);
|
||||||
|
|
||||||
_ = ty;
|
_ = operand;
|
||||||
return self.fail("TODO: Implement wasm airSelect", .{});
|
return self.fail("TODO: Implement wasm airSelect", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5680,10 +5680,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airSelect(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 pl_op = self.air.instructions.items(.data)[inst].pl_op;
|
||||||
const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
|
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", .{});
|
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 {
|
fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
|
||||||
|
|
|
||||||
|
|
@ -6359,11 +6359,11 @@ pub const FuncGen = struct {
|
||||||
fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
|
fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
|
||||||
if (self.liveness.isUnused(inst)) return null;
|
if (self.liveness.isUnused(inst)) return null;
|
||||||
|
|
||||||
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
|
const pl_op = self.air.instructions.items(.data)[inst].pl_op;
|
||||||
const extra = self.air.extraData(Air.Select, ty_pl.payload).data;
|
const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
|
||||||
const pred = try self.resolveInst(extra.pred);
|
const pred = try self.resolveInst(pl_op.operand);
|
||||||
const a = try self.resolveInst(extra.a);
|
const a = try self.resolveInst(extra.lhs);
|
||||||
const b = try self.resolveInst(extra.b);
|
const b = try self.resolveInst(extra.rhs);
|
||||||
|
|
||||||
return self.builder.buildSelect(pred, a, b, "");
|
return self.builder.buildSelect(pred, a, b, "");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -398,15 +398,16 @@ const Writer = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
|
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 pl_op = w.air.instructions.items(.data)[inst].pl_op;
|
||||||
const extra = w.air.extraData(Air.Select, ty_pl.payload).data;
|
const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
|
||||||
|
|
||||||
try s.print("{}, ", .{w.air.getRefType(ty_pl.ty).fmtDebug()});
|
const elem_ty = w.air.typeOfIndex(inst).childType();
|
||||||
try w.writeOperand(s, inst, 0, extra.pred);
|
try s.print("{}, ", .{elem_ty.fmtDebug()});
|
||||||
|
try w.writeOperand(s, inst, 0, pl_op.operand);
|
||||||
try s.writeAll(", ");
|
try s.writeAll(", ");
|
||||||
try w.writeOperand(s, inst, 1, extra.a);
|
try w.writeOperand(s, inst, 1, extra.lhs);
|
||||||
try s.writeAll(", ");
|
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 {
|
fn writeReduce(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue