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...@@ -2700,8 +2700,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
2700 .rem,2700 .rem,
2701 .shl_exact,2701 .shl_exact,
2702 .shr_exact,2702 .shr_exact,
2703 .bit_offset_of,
2704 .offset_of,
2705 .splat,2703 .splat,
2706 .reduce,2704 .reduce,
2707 .shuffle,2705 .shuffle,
...@@ -9011,11 +9009,12 @@ fn offsetOf(...@@ -9011,11 +9009,12 @@ fn offsetOf(
9011 node: Ast.Node.Index,9009 node: Ast.Node.Index,
9012 lhs_node: Ast.Node.Index,9010 lhs_node: Ast.Node.Index,
9013 rhs_node: Ast.Node.Index,9011 rhs_node: Ast.Node.Index,
9014 tag: Zir.Inst.Tag,9012 tag: Zir.Inst.Extended,
9015) InnerError!Zir.Inst.Ref {9013) InnerError!Zir.Inst.Ref {
9016 const type_inst = try typeExpr(gz, scope, lhs_node);9014 const type_inst = try typeExpr(gz, scope, lhs_node);
9017 const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, rhs_node);9015 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),
9019 .lhs = type_inst,9018 .lhs = type_inst,
9020 .rhs = field_name,9019 .rhs = field_name,
9021 });9020 });
src/Autodoc.zig-2
...@@ -1542,8 +1542,6 @@ fn walkInstruction(...@@ -1542,8 +1542,6 @@ fn walkInstruction(
1542 .bitcast,1542 .bitcast,
1543 .vector_type,1543 .vector_type,
1544 // @check1544 // @check
1545 .bit_offset_of,
1546 .offset_of,
1547 .splat,1545 .splat,
1548 .reduce,1546 .reduce,
1549 .min,1547 .min,
src/Sema.zig+15-15
...@@ -1046,8 +1046,6 @@ fn analyzeBodyInner(...@@ -1046,8 +1046,6 @@ fn analyzeBodyInner(
1046 .has_field => try sema.zirHasField(block, inst),1046 .has_field => try sema.zirHasField(block, inst),
1047 .byte_swap => try sema.zirByteSwap(block, inst),1047 .byte_swap => try sema.zirByteSwap(block, inst),
1048 .bit_reverse => try sema.zirBitReverse(block, inst),1048 .bit_reverse => try sema.zirBitReverse(block, inst),
1049 .bit_offset_of => try sema.zirBitOffsetOf(block, inst),
1050 .offset_of => try sema.zirOffsetOf(block, inst),
1051 .splat => try sema.zirSplat(block, inst),1049 .splat => try sema.zirSplat(block, inst),
1052 .reduce => try sema.zirReduce(block, inst),1050 .reduce => try sema.zirReduce(block, inst),
1053 .shuffle => try sema.zirShuffle(block, inst),1051 .shuffle => try sema.zirShuffle(block, inst),
...@@ -1179,6 +1177,8 @@ fn analyzeBodyInner(...@@ -1179,6 +1177,8 @@ fn analyzeBodyInner(
1179 .work_group_size => try sema.zirWorkItem( block, extended, extended.opcode),1177 .work_group_size => try sema.zirWorkItem( block, extended, extended.opcode),
1180 .work_group_id => try sema.zirWorkItem( block, extended, extended.opcode),1178 .work_group_id => try sema.zirWorkItem( block, extended, extended.opcode),
1181 .in_comptime => try sema.zirInComptime( block),1179 .in_comptime => try sema.zirInComptime( block),
1180 .bit_offset_of => try sema.zirBitOffsetOf( block, extended),
1181 .offset_of => try sema.zirOffsetOf( block, extended),
1182 // zig fmt: on1182 // zig fmt: on
11831183
1184 .fence => {1184 .fence => {
...@@ -21743,24 +21743,24 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -21743,24 +21743,24 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
21743 }21743 }
21744}21744}
2174521745
21746fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {21746fn zirBitOffsetOf(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21747 const offset = try sema.bitOffsetOf(block, inst);21747 const offset = try sema.bitOffsetOf(block, extended);
21748 return sema.addIntUnsigned(Type.comptime_int, offset);21748 return sema.addIntUnsigned(Type.comptime_int, offset);
21749}21749}
2175021750
21751fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {21751fn zirOffsetOf(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21752 const offset = try sema.bitOffsetOf(block, inst);21752 const offset = try sema.bitOffsetOf(block, extended);
21753 // TODO reminder to make this a compile error for packed structs21753 // TODO reminder to make this a compile error for packed structs
21754 return sema.addIntUnsigned(Type.comptime_int, offset / 8);21754 return sema.addIntUnsigned(Type.comptime_int, offset / 8);
21755}21755}
2175621756
21757fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {21757fn bitOffsetOf(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!u64 {
21758 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;21758 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
21759 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };21759
21760 const src: LazySrcLoc = .{ .node_offset_bin_op = extra.node };
21760 sema.src = src;21761 sema.src = src;
21761 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };21762 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = extra.node };
21762 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };21763 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = extra.node };
21763 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2176421764
21765 const ty = try sema.resolveType(block, lhs_src, extra.lhs);21765 const ty = try sema.resolveType(block, lhs_src, extra.lhs);
21766 const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "name of field must be comptime-known");21766 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 {...@@ -33840,9 +33840,9 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
33840 }33840 }
33841}33841}
3384233842
33843// In case of querying the ABI alignment of this struct, we will ask33843/// In case of querying the ABI alignment of this struct, we will ask
33844// for hasRuntimeBits() of each field, so we need "requires comptime"33844/// for hasRuntimeBits() of each field, so we need "requires comptime"
33845// to be known already before this function returns.33845/// to be known already before this function returns.
33846pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {33846pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33847 const mod = sema.mod;33847 const mod = sema.mod;
3384833848
src/Zir.zig+6-12
...@@ -876,12 +876,6 @@ pub const Inst = struct {...@@ -876,12 +876,6 @@ pub const Inst = struct {
876 /// Implements the `@bitReverse` builtin. Uses the `un_node` union field.876 /// Implements the `@bitReverse` builtin. Uses the `un_node` union field.
877 bit_reverse,877 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,
885 /// Implements the `@splat` builtin.879 /// Implements the `@splat` builtin.
886 /// Uses the `pl_node` union field with payload `Bin`.880 /// Uses the `pl_node` union field with payload `Bin`.
887 splat,881 splat,
...@@ -1200,8 +1194,6 @@ pub const Inst = struct {...@@ -1200,8 +1194,6 @@ pub const Inst = struct {
1200 .rem,1194 .rem,
1201 .shl_exact,1195 .shl_exact,
1202 .shr_exact,1196 .shr_exact,
1203 .bit_offset_of,
1204 .offset_of,
1205 .splat,1197 .splat,
1206 .reduce,1198 .reduce,
1207 .shuffle,1199 .shuffle,
...@@ -1484,8 +1476,6 @@ pub const Inst = struct {...@@ -1484,8 +1476,6 @@ pub const Inst = struct {
1484 .rem,1476 .rem,
1485 .shl_exact,1477 .shl_exact,
1486 .shr_exact,1478 .shr_exact,
1487 .bit_offset_of,
1488 .offset_of,
1489 .splat,1479 .splat,
1490 .reduce,1480 .reduce,
1491 .shuffle,1481 .shuffle,
...@@ -1759,8 +1749,6 @@ pub const Inst = struct {...@@ -1759,8 +1749,6 @@ pub const Inst = struct {
1759 .shr = .pl_node,1749 .shr = .pl_node,
1760 .shr_exact = .pl_node,1750 .shr_exact = .pl_node,
17611751
1762 .bit_offset_of = .pl_node,
1763 .offset_of = .pl_node,
1764 .splat = .pl_node,1752 .splat = .pl_node,
1765 .reduce = .pl_node,1753 .reduce = .pl_node,
1766 .shuffle = .pl_node,1754 .shuffle = .pl_node,
...@@ -2009,6 +1997,12 @@ pub const Inst = struct {...@@ -2009,6 +1997,12 @@ pub const Inst = struct {
2009 /// with a specific value. For instance, this is used for the capture of an `errdefer`.1997 /// with a specific value. For instance, this is used for the capture of an `errdefer`.
2010 /// This should never appear in a body.1998 /// This should never appear in a body.
2011 value_placeholder,1999 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
2013 pub const InstData = struct {2007 pub const InstData = struct {
2014 opcode: Extended,2008 opcode: Extended,
src/codegen/llvm.zig+2-3
...@@ -4940,8 +4940,7 @@ pub const FuncGen = struct {...@@ -4940,8 +4940,7 @@ pub const FuncGen = struct {
4940 const frame_alloca = fg.builder.buildArrayAlloca(llvm_i8, frame_size, "");4940 const frame_alloca = fg.builder.buildArrayAlloca(llvm_i8, frame_size, "");
4941 frame_alloca.setAlignment(target.ptrBitWidth() / 4);4941 frame_alloca.setAlignment(target.ptrBitWidth() / 4);
4942 const frame_llvm_ty = try o.lowerAsyncFrameHeader(fn_info.return_type.toType());4942 const frame_llvm_ty = try o.lowerAsyncFrameHeader(fn_info.return_type.toType());
4943 const llvm_ptr_ty = fg.context.pointerType(0);4943 const frame_ptr = fg.builder.buildBitCast(frame_alloca, o.context.pointerType(0), "");
4944 const frame_ptr = fg.builder.buildBitCast(frame_alloca, llvm_ptr_ty, "");
4945 const l = asyncFrameLayout();4944 const l = asyncFrameLayout();
4946 const fn_ptr_ptr = fg.builder.buildStructGEP(frame_llvm_ty, frame_ptr, l.fn_ptr, "");4945 const fn_ptr_ptr = fg.builder.buildStructGEP(frame_llvm_ty, frame_ptr, l.fn_ptr, "");
4947 _ = fg.builder.buildStore(callee, fn_ptr_ptr);4946 _ = fg.builder.buildStore(callee, fn_ptr_ptr);
...@@ -4954,7 +4953,7 @@ pub const FuncGen = struct {...@@ -4954,7 +4953,7 @@ pub const FuncGen = struct {
4954 const awaiter_ptr = fg.builder.buildStructGEP(frame_llvm_ty, frame_ptr, l.awaiter, "");4953 const awaiter_ptr = fg.builder.buildStructGEP(frame_llvm_ty, frame_ptr, l.awaiter, "");
4955 _ = fg.builder.buildStore(zero, awaiter_ptr);4954 _ = 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);
4958 defer llvm_args.deinit();4957 defer llvm_args.deinit();
49594958
4960 try addCallArgs(fg, args, &llvm_args, fn_info);4959 try addCallArgs(fg, args, &llvm_args, fn_info);
src/print_zir.zig+2-2
...@@ -335,8 +335,6 @@ const Writer = struct {...@@ -335,8 +335,6 @@ const Writer = struct {
335 .div_trunc,335 .div_trunc,
336 .mod,336 .mod,
337 .rem,337 .rem,
338 .bit_offset_of,
339 .offset_of,
340 .splat,338 .splat,
341 .reduce,339 .reduce,
342 .bitcast,340 .bitcast,
...@@ -526,6 +524,8 @@ const Writer = struct {...@@ -526,6 +524,8 @@ const Writer = struct {
526 .wasm_memory_grow,524 .wasm_memory_grow,
527 .prefetch,525 .prefetch,
528 .c_va_arg,526 .c_va_arg,
527 .bit_offset_of,
528 .offset_of,
529 => {529 => {
530 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;530 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
531 const src = LazySrcLoc.nodeOffset(inst_data.node);531 const src = LazySrcLoc.nodeOffset(inst_data.node);