compiler: free up two ZIR tags

This commit is contained in:
Andrew Kelley 2022-11-01 20:56:26 -07:00
parent 3faa550dc2
commit 8bc759e094
6 changed files with 28 additions and 38 deletions

View File

@ -2700,8 +2700,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.rem,
.shl_exact,
.shr_exact,
.bit_offset_of,
.offset_of,
.splat,
.reduce,
.shuffle,
@ -9011,11 +9009,12 @@ fn offsetOf(
node: Ast.Node.Index,
lhs_node: Ast.Node.Index,
rhs_node: Ast.Node.Index,
tag: Zir.Inst.Tag,
tag: Zir.Inst.Extended,
) InnerError!Zir.Inst.Ref {
const type_inst = try typeExpr(gz, scope, lhs_node);
const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, rhs_node);
const result = try gz.addPlNode(tag, node, Zir.Inst.Bin{
const result = try gz.addExtendedPayload(tag, Zir.Inst.BinNode{
.node = gz.nodeIndexToRelative(node),
.lhs = type_inst,
.rhs = field_name,
});

View File

@ -1542,8 +1542,6 @@ fn walkInstruction(
.bitcast,
.vector_type,
// @check
.bit_offset_of,
.offset_of,
.splat,
.reduce,
.min,

View File

@ -1046,8 +1046,6 @@ fn analyzeBodyInner(
.has_field => try sema.zirHasField(block, inst),
.byte_swap => try sema.zirByteSwap(block, inst),
.bit_reverse => try sema.zirBitReverse(block, inst),
.bit_offset_of => try sema.zirBitOffsetOf(block, inst),
.offset_of => try sema.zirOffsetOf(block, inst),
.splat => try sema.zirSplat(block, inst),
.reduce => try sema.zirReduce(block, inst),
.shuffle => try sema.zirShuffle(block, inst),
@ -1179,6 +1177,8 @@ fn analyzeBodyInner(
.work_group_size => try sema.zirWorkItem( block, extended, extended.opcode),
.work_group_id => try sema.zirWorkItem( block, extended, extended.opcode),
.in_comptime => try sema.zirInComptime( block),
.bit_offset_of => try sema.zirBitOffsetOf( block, extended),
.offset_of => try sema.zirOffsetOf( block, extended),
// zig fmt: on
.fence => {
@ -21743,24 +21743,24 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
}
}
fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const offset = try sema.bitOffsetOf(block, inst);
fn zirBitOffsetOf(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
const offset = try sema.bitOffsetOf(block, extended);
return sema.addIntUnsigned(Type.comptime_int, offset);
}
fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const offset = try sema.bitOffsetOf(block, inst);
fn zirOffsetOf(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
const offset = try sema.bitOffsetOf(block, extended);
// TODO reminder to make this a compile error for packed structs
return sema.addIntUnsigned(Type.comptime_int, offset / 8);
}
fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {
const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
fn bitOffsetOf(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!u64 {
const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
const src: LazySrcLoc = .{ .node_offset_bin_op = extra.node };
sema.src = src;
const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = extra.node };
const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = extra.node };
const ty = try sema.resolveType(block, lhs_src, extra.lhs);
const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "name of field must be comptime-known");
@ -33840,9 +33840,9 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
}
}
// In case of querying the ABI alignment of this struct, we will ask
// for hasRuntimeBits() of each field, so we need "requires comptime"
// to be known already before this function returns.
/// In case of querying the ABI alignment of this struct, we will ask
/// for hasRuntimeBits() of each field, so we need "requires comptime"
/// to be known already before this function returns.
pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
const mod = sema.mod;

View File

@ -876,12 +876,6 @@ pub const Inst = struct {
/// Implements the `@bitReverse` builtin. Uses the `un_node` union field.
bit_reverse,
/// Implements the `@bitOffsetOf` builtin.
/// Uses the `pl_node` union field with payload `Bin`.
bit_offset_of,
/// Implements the `@offsetOf` builtin.
/// Uses the `pl_node` union field with payload `Bin`.
offset_of,
/// Implements the `@splat` builtin.
/// Uses the `pl_node` union field with payload `Bin`.
splat,
@ -1200,8 +1194,6 @@ pub const Inst = struct {
.rem,
.shl_exact,
.shr_exact,
.bit_offset_of,
.offset_of,
.splat,
.reduce,
.shuffle,
@ -1484,8 +1476,6 @@ pub const Inst = struct {
.rem,
.shl_exact,
.shr_exact,
.bit_offset_of,
.offset_of,
.splat,
.reduce,
.shuffle,
@ -1759,8 +1749,6 @@ pub const Inst = struct {
.shr = .pl_node,
.shr_exact = .pl_node,
.bit_offset_of = .pl_node,
.offset_of = .pl_node,
.splat = .pl_node,
.reduce = .pl_node,
.shuffle = .pl_node,
@ -2009,6 +1997,12 @@ pub const Inst = struct {
/// with a specific value. For instance, this is used for the capture of an `errdefer`.
/// This should never appear in a body.
value_placeholder,
/// Implements the `@bitOffsetOf` builtin.
/// `operand` is payload index to `BinNode`.
bit_offset_of,
/// Implements the `@offsetOf` builtin.
/// `operand` is payload index to `BinNode`.
offset_of,
pub const InstData = struct {
opcode: Extended,

View File

@ -4940,8 +4940,7 @@ pub const FuncGen = struct {
const frame_alloca = fg.builder.buildArrayAlloca(llvm_i8, frame_size, "");
frame_alloca.setAlignment(target.ptrBitWidth() / 4);
const frame_llvm_ty = try o.lowerAsyncFrameHeader(fn_info.return_type.toType());
const llvm_ptr_ty = fg.context.pointerType(0);
const frame_ptr = fg.builder.buildBitCast(frame_alloca, llvm_ptr_ty, "");
const frame_ptr = fg.builder.buildBitCast(frame_alloca, o.context.pointerType(0), "");
const l = asyncFrameLayout();
const fn_ptr_ptr = fg.builder.buildStructGEP(frame_llvm_ty, frame_ptr, l.fn_ptr, "");
_ = fg.builder.buildStore(callee, fn_ptr_ptr);
@ -4954,7 +4953,7 @@ pub const FuncGen = struct {
const awaiter_ptr = fg.builder.buildStructGEP(frame_llvm_ty, frame_ptr, l.awaiter, "");
_ = fg.builder.buildStore(zero, awaiter_ptr);
var llvm_args = std.ArrayList(*llvm.Value).init(fg.gpa);
var llvm_args = std.ArrayList(*llvm.Value).init(o.gpa);
defer llvm_args.deinit();
try addCallArgs(fg, args, &llvm_args, fn_info);

View File

@ -335,8 +335,6 @@ const Writer = struct {
.div_trunc,
.mod,
.rem,
.bit_offset_of,
.offset_of,
.splat,
.reduce,
.bitcast,
@ -526,6 +524,8 @@ const Writer = struct {
.wasm_memory_grow,
.prefetch,
.c_va_arg,
.bit_offset_of,
.offset_of,
=> {
const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
const src = LazySrcLoc.nodeOffset(inst_data.node);