authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-01 20:56:26-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-26 15:57:07-07:00
log8bc759e094cda907acc64c50b86ceb9d3a87213f
treef2ba3b00b7f3f8f143d476dd5823dc05c1a05427
parent3faa550dc2d6b9a3a8e3be22fc927c8c5682d6c8

compiler: free up two ZIR tags


6 files changed, 28 insertions(+), 38 deletions(-)

src/AstGen.zig+3-4
......@@ -2700,8 +2700,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
27002700 .rem,
27012701 .shl_exact,
27022702 .shr_exact,
2703 .bit_offset_of,
2704 .offset_of,
27052703 .splat,
27062704 .reduce,
27072705 .shuffle,
......@@ -9011,11 +9009,12 @@ fn offsetOf(
90119009 node: Ast.Node.Index,
90129010 lhs_node: Ast.Node.Index,
90139011 rhs_node: Ast.Node.Index,
9014 tag: Zir.Inst.Tag,
9012 tag: Zir.Inst.Extended,
90159013) InnerError!Zir.Inst.Ref {
90169014 const type_inst = try typeExpr(gz, scope, lhs_node);
90179015 const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, rhs_node);
9018 const result = try gz.addPlNode(tag, node, Zir.Inst.Bin{
9016 const result = try gz.addExtendedPayload(tag, Zir.Inst.BinNode{
9017 .node = gz.nodeIndexToRelative(node),
90199018 .lhs = type_inst,
90209019 .rhs = field_name,
90219020 });
src/Autodoc.zig-2
......@@ -1542,8 +1542,6 @@ fn walkInstruction(
15421542 .bitcast,
15431543 .vector_type,
15441544 // @check
1545 .bit_offset_of,
1546 .offset_of,
15471545 .splat,
15481546 .reduce,
15491547 .min,
src/Sema.zig+15-15
......@@ -1046,8 +1046,6 @@ fn analyzeBodyInner(
10461046 .has_field => try sema.zirHasField(block, inst),
10471047 .byte_swap => try sema.zirByteSwap(block, inst),
10481048 .bit_reverse => try sema.zirBitReverse(block, inst),
1049 .bit_offset_of => try sema.zirBitOffsetOf(block, inst),
1050 .offset_of => try sema.zirOffsetOf(block, inst),
10511049 .splat => try sema.zirSplat(block, inst),
10521050 .reduce => try sema.zirReduce(block, inst),
10531051 .shuffle => try sema.zirShuffle(block, inst),
......@@ -1179,6 +1177,8 @@ fn analyzeBodyInner(
11791177 .work_group_size => try sema.zirWorkItem( block, extended, extended.opcode),
11801178 .work_group_id => try sema.zirWorkItem( block, extended, extended.opcode),
11811179 .in_comptime => try sema.zirInComptime( block),
1180 .bit_offset_of => try sema.zirBitOffsetOf( block, extended),
1181 .offset_of => try sema.zirOffsetOf( block, extended),
11821182 // zig fmt: on
11831183
11841184 .fence => {
......@@ -21743,24 +21743,24 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2174321743 }
2174421744}
2174521745
21746fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21747 const offset = try sema.bitOffsetOf(block, inst);
21746fn zirBitOffsetOf(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21747 const offset = try sema.bitOffsetOf(block, extended);
2174821748 return sema.addIntUnsigned(Type.comptime_int, offset);
2174921749}
2175021750
21751fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21752 const offset = try sema.bitOffsetOf(block, inst);
21751fn zirOffsetOf(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21752 const offset = try sema.bitOffsetOf(block, extended);
2175321753 // TODO reminder to make this a compile error for packed structs
2175421754 return sema.addIntUnsigned(Type.comptime_int, offset / 8);
2175521755}
2175621756
21757fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {
21758 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
21759 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
21757fn bitOffsetOf(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!u64 {
21758 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
21759
21760 const src: LazySrcLoc = .{ .node_offset_bin_op = extra.node };
2176021761 sema.src = src;
21761 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
21762 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
21763 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
21762 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = extra.node };
21763 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = extra.node };
2176421764
2176521765 const ty = try sema.resolveType(block, lhs_src, extra.lhs);
2176621766 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 {
3384033840 }
3384133841}
3384233842
33843// In case of querying the ABI alignment of this struct, we will ask
33844// for hasRuntimeBits() of each field, so we need "requires comptime"
33845// to be known already before this function returns.
33843/// In case of querying the ABI alignment of this struct, we will ask
33844/// for hasRuntimeBits() of each field, so we need "requires comptime"
33845/// to be known already before this function returns.
3384633846pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3384733847 const mod = sema.mod;
3384833848
src/Zir.zig+6-12
......@@ -876,12 +876,6 @@ pub const Inst = struct {
876876 /// Implements the `@bitReverse` builtin. Uses the `un_node` union field.
877877 bit_reverse,
878878
879 /// Implements the `@bitOffsetOf` builtin.
880 /// Uses the `pl_node` union field with payload `Bin`.
881 bit_offset_of,
882 /// Implements the `@offsetOf` builtin.
883 /// Uses the `pl_node` union field with payload `Bin`.
884 offset_of,
885879 /// Implements the `@splat` builtin.
886880 /// Uses the `pl_node` union field with payload `Bin`.
887881 splat,
......@@ -1200,8 +1194,6 @@ pub const Inst = struct {
12001194 .rem,
12011195 .shl_exact,
12021196 .shr_exact,
1203 .bit_offset_of,
1204 .offset_of,
12051197 .splat,
12061198 .reduce,
12071199 .shuffle,
......@@ -1484,8 +1476,6 @@ pub const Inst = struct {
14841476 .rem,
14851477 .shl_exact,
14861478 .shr_exact,
1487 .bit_offset_of,
1488 .offset_of,
14891479 .splat,
14901480 .reduce,
14911481 .shuffle,
......@@ -1759,8 +1749,6 @@ pub const Inst = struct {
17591749 .shr = .pl_node,
17601750 .shr_exact = .pl_node,
17611751
1762 .bit_offset_of = .pl_node,
1763 .offset_of = .pl_node,
17641752 .splat = .pl_node,
17651753 .reduce = .pl_node,
17661754 .shuffle = .pl_node,
......@@ -2009,6 +1997,12 @@ pub const Inst = struct {
20091997 /// with a specific value. For instance, this is used for the capture of an `errdefer`.
20101998 /// This should never appear in a body.
20111999 value_placeholder,
2000 /// Implements the `@bitOffsetOf` builtin.
2001 /// `operand` is payload index to `BinNode`.
2002 bit_offset_of,
2003 /// Implements the `@offsetOf` builtin.
2004 /// `operand` is payload index to `BinNode`.
2005 offset_of,
20122006
20132007 pub const InstData = struct {
20142008 opcode: Extended,
src/codegen/llvm.zig+2-3
......@@ -4940,8 +4940,7 @@ pub const FuncGen = struct {
49404940 const frame_alloca = fg.builder.buildArrayAlloca(llvm_i8, frame_size, "");
49414941 frame_alloca.setAlignment(target.ptrBitWidth() / 4);
49424942 const frame_llvm_ty = try o.lowerAsyncFrameHeader(fn_info.return_type.toType());
4943 const llvm_ptr_ty = fg.context.pointerType(0);
4944 const frame_ptr = fg.builder.buildBitCast(frame_alloca, llvm_ptr_ty, "");
4943 const frame_ptr = fg.builder.buildBitCast(frame_alloca, o.context.pointerType(0), "");
49454944 const l = asyncFrameLayout();
49464945 const fn_ptr_ptr = fg.builder.buildStructGEP(frame_llvm_ty, frame_ptr, l.fn_ptr, "");
49474946 _ = fg.builder.buildStore(callee, fn_ptr_ptr);
......@@ -4954,7 +4953,7 @@ pub const FuncGen = struct {
49544953 const awaiter_ptr = fg.builder.buildStructGEP(frame_llvm_ty, frame_ptr, l.awaiter, "");
49554954 _ = fg.builder.buildStore(zero, awaiter_ptr);
49564955
4957 var llvm_args = std.ArrayList(*llvm.Value).init(fg.gpa);
4956 var llvm_args = std.ArrayList(*llvm.Value).init(o.gpa);
49584957 defer llvm_args.deinit();
49594958
49604959 try addCallArgs(fg, args, &llvm_args, fn_info);
src/print_zir.zig+2-2
......@@ -335,8 +335,6 @@ const Writer = struct {
335335 .div_trunc,
336336 .mod,
337337 .rem,
338 .bit_offset_of,
339 .offset_of,
340338 .splat,
341339 .reduce,
342340 .bitcast,
......@@ -526,6 +524,8 @@ const Writer = struct {
526524 .wasm_memory_grow,
527525 .prefetch,
528526 .c_va_arg,
527 .bit_offset_of,
528 .offset_of,
529529 => {
530530 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
531531 const src = LazySrcLoc.nodeOffset(inst_data.node);