| author | |
| committer | |
| log | 928914e25afce48f5b4abef7150f2c9242f29ba5 |
| tree | 5f0b3c11a76204c21e1baa35b63317c5b807c3f1 |
| parent | 119b2030f70de9ed900ce3594201de6f869b71c8 |
Debug locations are no longer emitted twice every time2 files changed, 82 insertions(+), 53 deletions(-)
src/codegen/llvm.zig+36-29| ... | ... | @@ -4759,7 +4759,7 @@ pub const FuncGen = struct { |
| 4759 | 4759 | |
| 4760 | 4760 | inlined: std.ArrayListUnmanaged(struct { |
| 4761 | 4761 | base_line: u32, |
| 4762 | location: Builder.Metadata, | |
| 4762 | location: Builder.DebugLocation, | |
| 4763 | 4763 | scope: Builder.Metadata, |
| 4764 | 4764 | }) = .{}, |
| 4765 | 4765 | |
| ... | ... | @@ -6579,17 +6579,20 @@ pub const FuncGen = struct { |
| 6579 | 6579 | const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; |
| 6580 | 6580 | self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1); |
| 6581 | 6581 | self.prev_dbg_column = @intCast(dbg_stmt.column + 1); |
| 6582 | const inlined_at = if (self.inlined.items.len > 0) | |
| 6583 | self.inlined.items[self.inlined.items.len - 1].location | |
| 6582 | ||
| 6583 | const inlined_at_location = if (self.inlined.getLastOrNull()) |inlined| | |
| 6584 | try inlined.location.toMetadata(self.wip.builder) | |
| 6584 | 6585 | else |
| 6585 | 6586 | .none; |
| 6586 | 6587 | |
| 6587 | self.wip.current_debug_location = try self.wip.builder.debugLocation( | |
| 6588 | self.prev_dbg_line, | |
| 6589 | self.prev_dbg_column, | |
| 6590 | self.scope, | |
| 6591 | inlined_at, | |
| 6592 | ); | |
| 6588 | self.wip.debug_location = .{ | |
| 6589 | .location = .{ | |
| 6590 | .line = self.prev_dbg_line, | |
| 6591 | .column = self.prev_dbg_column, | |
| 6592 | .scope = self.scope, | |
| 6593 | .inlined_at = inlined_at_location, | |
| 6594 | }, | |
| 6595 | }; | |
| 6593 | 6596 | |
| 6594 | 6597 | return .none; |
| 6595 | 6598 | } |
| ... | ... | @@ -6610,7 +6613,7 @@ pub const FuncGen = struct { |
| 6610 | 6613 | |
| 6611 | 6614 | const line_number = decl.src_line + 1; |
| 6612 | 6615 | try self.inlined.append(self.gpa, .{ |
| 6613 | .location = self.wip.current_debug_location, | |
| 6616 | .location = self.wip.debug_location, | |
| 6614 | 6617 | .scope = self.scope, |
| 6615 | 6618 | .base_line = self.base_line, |
| 6616 | 6619 | }); |
| ... | ... | @@ -6649,13 +6652,15 @@ pub const FuncGen = struct { |
| 6649 | 6652 | ); |
| 6650 | 6653 | self.scope = lexical_block; |
| 6651 | 6654 | self.base_line = decl.src_line; |
| 6652 | const inlined_at = self.wip.current_debug_location; | |
| 6653 | self.wip.current_debug_location = try o.builder.debugLocation( | |
| 6654 | line_number, | |
| 6655 | 0, | |
| 6656 | self.scope, | |
| 6657 | inlined_at, | |
| 6658 | ); | |
| 6655 | const inlined_at_location = try self.wip.debug_location.toMetadata(&o.builder); | |
| 6656 | self.wip.debug_location = .{ | |
| 6657 | .location = .{ | |
| 6658 | .line = line_number, | |
| 6659 | .column = 0, | |
| 6660 | .scope = self.scope, | |
| 6661 | .inlined_at = inlined_at_location, | |
| 6662 | }, | |
| 6663 | }; | |
| 6659 | 6664 | return .none; |
| 6660 | 6665 | } |
| 6661 | 6666 | |
| ... | ... | @@ -6672,7 +6677,7 @@ pub const FuncGen = struct { |
| 6672 | 6677 | const old = self.inlined.pop(); |
| 6673 | 6678 | self.scope = old.scope; |
| 6674 | 6679 | self.base_line = old.base_line; |
| 6675 | self.wip.current_debug_location = old.location; | |
| 6680 | self.wip.debug_location = old.location; | |
| 6676 | 6681 | return .none; |
| 6677 | 6682 | } |
| 6678 | 6683 | |
| ... | ... | @@ -8833,13 +8838,15 @@ pub const FuncGen = struct { |
| 8833 | 8838 | @intCast(self.arg_index), |
| 8834 | 8839 | ); |
| 8835 | 8840 | |
| 8836 | const old_location = self.wip.current_debug_location; | |
| 8837 | self.wip.current_debug_location = try o.builder.debugLocation( | |
| 8838 | lbrace_line, | |
| 8839 | lbrace_col, | |
| 8840 | self.scope, | |
| 8841 | .none, | |
| 8842 | ); | |
| 8841 | const old_location = self.wip.debug_location; | |
| 8842 | self.wip.debug_location = .{ | |
| 8843 | .location = .{ | |
| 8844 | .line = lbrace_line, | |
| 8845 | .column = lbrace_col, | |
| 8846 | .scope = self.scope, | |
| 8847 | .inlined_at = .none, | |
| 8848 | }, | |
| 8849 | }; | |
| 8843 | 8850 | |
| 8844 | 8851 | const owner_mod = self.dg.ownerModule(); |
| 8845 | 8852 | if (isByRef(inst_ty, mod)) { |
| ... | ... | @@ -8886,7 +8893,7 @@ pub const FuncGen = struct { |
| 8886 | 8893 | ); |
| 8887 | 8894 | } |
| 8888 | 8895 | |
| 8889 | self.wip.current_debug_location = old_location; | |
| 8896 | self.wip.debug_location = old_location; | |
| 8890 | 8897 | return arg_val; |
| 8891 | 8898 | } |
| 8892 | 8899 | |
| ... | ... | @@ -11732,15 +11739,15 @@ fn buildAllocaInner( |
| 11732 | 11739 | |
| 11733 | 11740 | const alloca = blk: { |
| 11734 | 11741 | const prev_cursor = wip.cursor; |
| 11735 | const prev_debug_location = wip.current_debug_location; | |
| 11742 | const prev_debug_location = wip.debug_location; | |
| 11736 | 11743 | defer { |
| 11737 | 11744 | wip.cursor = prev_cursor; |
| 11738 | 11745 | if (wip.cursor.block == .entry) wip.cursor.instruction += 1; |
| 11739 | wip.current_debug_location = prev_debug_location; | |
| 11746 | wip.debug_location = prev_debug_location; | |
| 11740 | 11747 | } |
| 11741 | 11748 | |
| 11742 | 11749 | wip.cursor = .{ .block = .entry }; |
| 11743 | wip.current_debug_location = .none; | |
| 11750 | wip.debug_location = .no_location; | |
| 11744 | 11751 | break :blk try wip.alloca(.normal, llvm_ty, .none, alignment, address_space, ""); |
| 11745 | 11752 | }; |
| 11746 | 11753 |
src/codegen/llvm/Builder.zig+46-24| ... | ... | @@ -3797,7 +3797,7 @@ pub const Function = struct { |
| 3797 | 3797 | instructions: std.MultiArrayList(Instruction) = .{}, |
| 3798 | 3798 | names: [*]const String = &[0]String{}, |
| 3799 | 3799 | value_indices: [*]const u32 = &[0]u32{}, |
| 3800 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{}, | |
| 3800 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{}, | |
| 3801 | 3801 | debug_values: []const Instruction.Index = &.{}, |
| 3802 | 3802 | extra: []const u32 = &.{}, |
| 3803 | 3803 | |
| ... | ... | @@ -4857,16 +4857,40 @@ pub const Function = struct { |
| 4857 | 4857 | } |
| 4858 | 4858 | }; |
| 4859 | 4859 | |
| 4860 | pub const DebugLocation = union(enum) { | |
| 4861 | no_location: void, | |
| 4862 | location: Location, | |
| 4863 | ||
| 4864 | pub const Location = struct { | |
| 4865 | line: u32, | |
| 4866 | column: u32, | |
| 4867 | scope: Builder.Metadata, | |
| 4868 | inlined_at: Builder.Metadata, | |
| 4869 | }; | |
| 4870 | ||
| 4871 | pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata { | |
| 4872 | return switch (self) { | |
| 4873 | .no_location => .none, | |
| 4874 | .location => |location| try builder.debugLocation( | |
| 4875 | location.line, | |
| 4876 | location.column, | |
| 4877 | location.scope, | |
| 4878 | location.inlined_at, | |
| 4879 | ), | |
| 4880 | }; | |
| 4881 | } | |
| 4882 | }; | |
| 4883 | ||
| 4860 | 4884 | pub const WipFunction = struct { |
| 4861 | 4885 | builder: *Builder, |
| 4862 | 4886 | function: Function.Index, |
| 4863 | last_debug_location: Metadata, | |
| 4864 | current_debug_location: Metadata, | |
| 4887 | prev_debug_location: DebugLocation, | |
| 4888 | debug_location: DebugLocation, | |
| 4865 | 4889 | cursor: Cursor, |
| 4866 | 4890 | blocks: std.ArrayListUnmanaged(Block), |
| 4867 | 4891 | instructions: std.MultiArrayList(Instruction), |
| 4868 | 4892 | names: std.ArrayListUnmanaged(String), |
| 4869 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, Metadata), | |
| 4893 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, DebugLocation), | |
| 4870 | 4894 | debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void), |
| 4871 | 4895 | extra: std.ArrayListUnmanaged(u32), |
| 4872 | 4896 | |
| ... | ... | @@ -4902,8 +4926,8 @@ pub const WipFunction = struct { |
| 4902 | 4926 | var self: WipFunction = .{ |
| 4903 | 4927 | .builder = builder, |
| 4904 | 4928 | .function = function, |
| 4905 | .last_debug_location = .none, | |
| 4906 | .current_debug_location = .none, | |
| 4929 | .prev_debug_location = .no_location, | |
| 4930 | .debug_location = .no_location, | |
| 4907 | 4931 | .cursor = undefined, |
| 4908 | 4932 | .blocks = .{}, |
| 4909 | 4933 | .instructions = .{}, |
| ... | ... | @@ -5850,7 +5874,7 @@ pub const WipFunction = struct { |
| 5850 | 5874 | const value_indices = try gpa.alloc(u32, final_instructions_len); |
| 5851 | 5875 | errdefer gpa.free(value_indices); |
| 5852 | 5876 | |
| 5853 | var debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{}; | |
| 5877 | var debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{}; | |
| 5854 | 5878 | errdefer debug_locations.deinit(gpa); |
| 5855 | 5879 | try debug_locations.ensureUnusedCapacity(gpa, @intCast(self.debug_locations.count())); |
| 5856 | 5880 | |
| ... | ... | @@ -6494,10 +6518,10 @@ pub const WipFunction = struct { |
| 6494 | 6518 | if (!self.builder.strip) { |
| 6495 | 6519 | self.names.appendAssumeCapacity(final_name); |
| 6496 | 6520 | if (block_instructions.items.len == 0 or |
| 6497 | self.current_debug_location != self.last_debug_location) | |
| 6521 | !std.meta.eql(self.debug_location, self.prev_debug_location)) | |
| 6498 | 6522 | { |
| 6499 | self.debug_locations.putAssumeCapacity(index, self.current_debug_location); | |
| 6500 | self.last_debug_location = self.current_debug_location; | |
| 6523 | self.debug_locations.putAssumeCapacity(index, self.debug_location); | |
| 6524 | self.prev_debug_location = self.debug_location; | |
| 6501 | 6525 | } |
| 6502 | 6526 | } |
| 6503 | 6527 | block_instructions.insertAssumeCapacity(self.cursor.instruction, index); |
| ... | ... | @@ -14866,20 +14890,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14866 | 14890 | |
| 14867 | 14891 | if (!self.strip) { |
| 14868 | 14892 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { |
| 14869 | if (debug_location != .none) { | |
| 14870 | const location = self.metadata_items.get(@intFromEnum(debug_location)); | |
| 14871 | assert(location.tag == .location); | |
| 14872 | const extra = self.metadataExtraData(Metadata.Location, location.data); | |
| 14873 | try function_block.writeAbbrev(FunctionBlock.DebugLoc{ | |
| 14874 | .line = extra.line, | |
| 14875 | .column = extra.column, | |
| 14876 | .scope = @enumFromInt(metadata_adapter.getMetadataIndex(extra.scope)), | |
| 14877 | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(extra.inlined_at)), | |
| 14878 | .is_implicit = false, | |
| 14879 | }); | |
| 14880 | has_location = true; | |
| 14881 | } else { | |
| 14882 | has_location = false; | |
| 14893 | switch (debug_location) { | |
| 14894 | .no_location => has_location = false, | |
| 14895 | .location => |location| { | |
| 14896 | try function_block.writeAbbrev(FunctionBlock.DebugLoc{ | |
| 14897 | .line = location.line, | |
| 14898 | .column = location.column, | |
| 14899 | .scope = @enumFromInt(metadata_adapter.getMetadataIndex(location.scope)), | |
| 14900 | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(location.inlined_at)), | |
| 14901 | .is_implicit = false, | |
| 14902 | }); | |
| 14903 | has_location = true; | |
| 14904 | }, | |
| 14883 | 14905 | } |
| 14884 | 14906 | } else if (has_location) { |
| 14885 | 14907 | try function_block.writeAbbrev(FunctionBlock.DebugLocAgain{}); |