authorgravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-06-28 18:01:55+02:00
committergravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-07-19 17:51:38+02:00
log177b3359a16016caf080ff95ba4b9359251d04b8
tree0f384209e59eca1af6ef54b3e8321546e7741973
parent52e4cdb45e2bbf6b8a220475190a76c9a392fa6a

llvm: Do not generate static member definitions

They were not helping LLDB and actively throwing off GDB. Also: clean up some llvm.Builder and llvm.ir definitions that are no longer necessary.

3 files changed, 45 insertions(+), 126 deletions(-)

src/codegen/llvm.zig+33-63
...@@ -2444,6 +2444,8 @@ pub const Object = struct {...@@ -2444,6 +2444,8 @@ pub const Object = struct {
2444 if (decl.kind != .named) continue;2444 if (decl.kind != .named) continue;
2445 if (decl.analysis != .complete) continue;2445 if (decl.analysis != .complete) continue;
24462446
2447 const decl_line = 0;
2448
2447 if (decl.val.typeOf(zcu).ip_index == .type_type) {2449 if (decl.val.typeOf(zcu).ip_index == .type_type) {
2448 const nested_type = decl.val.toType();2450 const nested_type = decl.val.toType();
2449 // If this decl is the owner of the type, it will2451 // If this decl is the owner of the type, it will
...@@ -2465,52 +2467,10 @@ pub const Object = struct {...@@ -2465,52 +2467,10 @@ pub const Object = struct {
2465 try o.builder.metadataString(decl_name),2467 try o.builder.metadataString(decl_name),
2466 try o.getDebugFile(namespace.fileScope(zcu)),2468 try o.getDebugFile(namespace.fileScope(zcu)),
2467 fwd_ref,2469 fwd_ref,
2468 0, // Line2470 decl_line,
2469 try o.lowerDebugType(nested_type, false),2471 try o.lowerDebugType(nested_type, false),
2470 0, // Align2472 0, // Align
2471 ));2473 ));
2472 } else if (decl.val.getVariable(zcu)) |v| {
2473 // Imitate a C++ static member variable since neither
2474 // GDB or LLDB can really cope with regular variables
2475 // directly inside a struct type.
2476
2477 const vglobal = (o.decl_map.get(decl_id) orelse continue).ptr(&o.builder);
2478
2479 const linkage_name = try o.builder.metadataStringFromStrtabString(vglobal.kind.variable.name(&o.builder));
2480 const var_name = try o.builder.metadataString(decl.name.toSlice(ip));
2481 const var_type = try o.lowerDebugType(Type.fromInterned(v.ty), false);
2482 const debug_file = try o.getDebugFile(namespace.fileScope(zcu));
2483 const debug_line = decl.navSrcLine(zcu) + 1;
2484
2485 const static_member = try o.builder.debugStaticMemberType(
2486 var_name,
2487 debug_file,
2488 fwd_ref,
2489 debug_line,
2490 var_type,
2491 );
2492 fields.appendAssumeCapacity(static_member);
2493
2494 const debug_global_var = try o.builder.debugGlobalVar(
2495 var_name,
2496 linkage_name,
2497 debug_file,
2498 debug_file,
2499 debug_line,
2500 var_type,
2501 vglobal.kind.variable,
2502 static_member,
2503 .internal,
2504 );
2505
2506 const debug_expression = try o.builder.debugExpression(&.{});
2507
2508 const resolved_var = try o.builder.debugGlobalVarExpression(
2509 debug_global_var,
2510 debug_expression,
2511 );
2512 vglobal.dbg = resolved_var;
2513 try o.debug_globals.append(o.gpa, resolved_var);
2514 }2474 }
2515 }2475 }
2516 }2476 }
...@@ -4778,32 +4738,42 @@ pub const DeclGen = struct {...@@ -4778,32 +4738,42 @@ pub const DeclGen = struct {
4778 const debug_file = try o.getDebugFile(file_scope);4738 const debug_file = try o.getDebugFile(file_scope);
47794739
4780 const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder));4740 const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder));
4741 const is_internal_linkage = !decl.isExtern(zcu);
4742
4743 const ty = try o.lowerDebugType(decl.typeOf(zcu), true);
4744 const debug_global_var = try o.builder.debugGlobalVar(
4745 linkage_name,
4746 linkage_name,
4747 debug_file,
4748 debug_file,
4749 line_number,
4750 ty,
4751 variable_index,
4752 is_internal_linkage,
4753 );
4754 if (is_internal_linkage) {
4755 const name = try o.builder.metadataString(decl.name.toSlice(ip));
4756 const debug_scope = try o.namespaceToDebugScope(decl.src_namespace);
47814757
4782 if (!decl.isExtern(zcu)) {4758 const import = try o.builder.debugImportDeclaration(
4783 // Make it a static member variable, which is resolved later in genNamespaces.4759 name,
4784 _ = try o.namespaceToDebugScope(decl.src_namespace);
4785 } else {
4786 const debug_global_var = try o.builder.debugGlobalVar(
4787 linkage_name,
4788 linkage_name,
4789 debug_file,
4790 debug_file,4760 debug_file,
4761 debug_scope,
4791 line_number,4762 line_number,
4792 try o.lowerDebugType(decl.typeOf(zcu), true),
4793 variable_index,
4794 .none,
4795 .external,
4796 );
4797 const debug_expression = try o.builder.debugExpression(&.{});
4798
4799 const debug_global_var_expression = try o.builder.debugGlobalVarExpression(
4800 debug_global_var,4763 debug_global_var,
4801 debug_expression,
4802 );4764 );
48034765 try o.debug_imports.append(o.gpa, import);
4804 variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder);
4805 try o.debug_globals.append(o.gpa, debug_global_var_expression);
4806 }4766 }
4767
4768 const debug_expression = try o.builder.debugExpression(&.{});
4769
4770 const debug_global_var_expression = try o.builder.debugGlobalVarExpression(
4771 debug_global_var,
4772 debug_expression,
4773 );
4774
4775 variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder);
4776 try o.debug_globals.append(o.gpa, debug_global_var_expression);
4807 }4777 }
4808 }4778 }
48094779
src/codegen/llvm/Builder.zig+10-59
...@@ -7651,7 +7651,6 @@ pub const Metadata = enum(u32) {...@@ -7651,7 +7651,6 @@ pub const Metadata = enum(u32) {
7651 composite_vector_type,7651 composite_vector_type,
7652 derived_pointer_type,7652 derived_pointer_type,
7653 derived_member_type,7653 derived_member_type,
7654 derived_static_member_type,
7655 derived_typedef,7654 derived_typedef,
7656 imported_declaration,7655 imported_declaration,
7657 subroutine_type,7656 subroutine_type,
...@@ -7666,7 +7665,6 @@ pub const Metadata = enum(u32) {...@@ -7666,7 +7665,6 @@ pub const Metadata = enum(u32) {
7666 parameter,7665 parameter,
7667 global_var,7666 global_var,
7668 @"global_var local",7667 @"global_var local",
7669 @"global_var decl",
7670 global_var_expression,7668 global_var_expression,
7671 constant,7669 constant,
76727670
...@@ -7700,7 +7698,6 @@ pub const Metadata = enum(u32) {...@@ -7700,7 +7698,6 @@ pub const Metadata = enum(u32) {
7700 .composite_vector_type,7698 .composite_vector_type,
7701 .derived_pointer_type,7699 .derived_pointer_type,
7702 .derived_member_type,7700 .derived_member_type,
7703 .derived_static_member_type,
7704 .derived_typedef,7701 .derived_typedef,
7705 .imported_declaration,7702 .imported_declaration,
7706 .subroutine_type,7703 .subroutine_type,
...@@ -7714,7 +7711,6 @@ pub const Metadata = enum(u32) {...@@ -7714,7 +7711,6 @@ pub const Metadata = enum(u32) {
7714 .parameter,7711 .parameter,
7715 .global_var,7712 .global_var,
7716 .@"global_var local",7713 .@"global_var local",
7717 .@"global_var decl",
7718 .global_var_expression,7714 .global_var_expression,
7719 => false,7715 => false,
7720 };7716 };
...@@ -8008,12 +8004,6 @@ pub const Metadata = enum(u32) {...@@ -8008,12 +8004,6 @@ pub const Metadata = enum(u32) {
8008 };8004 };
80098005
8010 pub const GlobalVar = struct {8006 pub const GlobalVar = struct {
8011 pub const Options = enum {
8012 internal,
8013 internal_decl,
8014 external,
8015 };
8016
8017 name: MetadataString,8007 name: MetadataString,
8018 linkage_name: MetadataString,8008 linkage_name: MetadataString,
8019 file: Metadata,8009 file: Metadata,
...@@ -8021,7 +8011,6 @@ pub const Metadata = enum(u32) {...@@ -8021,7 +8011,6 @@ pub const Metadata = enum(u32) {
8021 line: u32,8011 line: u32,
8022 ty: Metadata,8012 ty: Metadata,
8023 variable: Variable.Index,8013 variable: Variable.Index,
8024 declaration: Metadata,
8025 };8014 };
80268015
8027 pub const GlobalVarExpression = struct {8016 pub const GlobalVarExpression = struct {
...@@ -10123,7 +10112,6 @@ pub fn printUnbuffered(...@@ -10123,7 +10112,6 @@ pub fn printUnbuffered(
10123 },10112 },
10124 .derived_pointer_type,10113 .derived_pointer_type,
10125 .derived_member_type,10114 .derived_member_type,
10126 .derived_static_member_type,
10127 .derived_typedef,10115 .derived_typedef,
10128 => |kind| {10116 => |kind| {
10129 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);10117 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);
...@@ -10134,7 +10122,7 @@ pub fn printUnbuffered(...@@ -10134,7 +10122,7 @@ pub fn printUnbuffered(
10134 DW_TAG_typedef,10122 DW_TAG_typedef,
10135 }, switch (kind) {10123 }, switch (kind) {
10136 .derived_pointer_type => .DW_TAG_pointer_type,10124 .derived_pointer_type => .DW_TAG_pointer_type,
10137 .derived_member_type, .derived_static_member_type => .DW_TAG_member,10125 .derived_member_type => .DW_TAG_member,
10138 .derived_typedef => .DW_TAG_typedef,10126 .derived_typedef => .DW_TAG_typedef,
10139 else => unreachable,10127 else => unreachable,
10140 }),10128 }),
...@@ -10152,7 +10140,7 @@ pub fn printUnbuffered(...@@ -10152,7 +10140,7 @@ pub fn printUnbuffered(
10152 0 => null,10140 0 => null,
10153 else => |bit_offset| bit_offset,10141 else => |bit_offset| bit_offset,
10154 },10142 },
10155 .flags = null, // TODO staticness10143 .flags = null,
10156 .extraData = null,10144 .extraData = null,
10157 .dwarfAddressSpace = null,10145 .dwarfAddressSpace = null,
10158 .annotations = null,10146 .annotations = null,
...@@ -10288,7 +10276,6 @@ pub fn printUnbuffered(...@@ -10288,7 +10276,6 @@ pub fn printUnbuffered(
10288 },10276 },
10289 .global_var,10277 .global_var,
10290 .@"global_var local",10278 .@"global_var local",
10291 .@"global_var decl",
10292 => |kind| {10279 => |kind| {
10293 const extra = self.metadataExtraData(Metadata.GlobalVar, metadata_item.data);10280 const extra = self.metadataExtraData(Metadata.GlobalVar, metadata_item.data);
10294 try metadata_formatter.specialized(.@"distinct !", .DIGlobalVariable, .{10281 try metadata_formatter.specialized(.@"distinct !", .DIGlobalVariable, .{
...@@ -10299,7 +10286,7 @@ pub fn printUnbuffered(...@@ -10299,7 +10286,7 @@ pub fn printUnbuffered(
10299 .line = extra.line,10286 .line = extra.line,
10300 .type = extra.ty,10287 .type = extra.ty,
10301 .isLocal = kind != .global_var,10288 .isLocal = kind != .global_var,
10302 .isDefinition = kind != .@"global_var decl",10289 .isDefinition = true,
10303 .declaration = null,10290 .declaration = null,
10304 .templateParams = null,10291 .templateParams = null,
10305 .@"align" = null,10292 .@"align" = null,
...@@ -11991,28 +11978,6 @@ pub fn debugPointerType(...@@ -11991,28 +11978,6 @@ pub fn debugPointerType(
11991 );11978 );
11992}11979}
1199311980
11994pub fn debugStaticMemberType(
11995 self: *Builder,
11996 name: MetadataString,
11997 file: Metadata,
11998 scope: Metadata,
11999 line: u32,
12000 underlying_type: Metadata,
12001) Allocator.Error!Metadata {
12002 try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0);
12003 return self.debugMemberTypeAssumeCapacity(
12004 name,
12005 file,
12006 scope,
12007 line,
12008 underlying_type,
12009 0,
12010 0,
12011 0,
12012 true,
12013 );
12014}
12015
12016pub fn debugMemberType(11981pub fn debugMemberType(
12017 self: *Builder,11982 self: *Builder,
12018 name: MetadataString,11983 name: MetadataString,
...@@ -12034,7 +11999,6 @@ pub fn debugMemberType(...@@ -12034,7 +11999,6 @@ pub fn debugMemberType(
12034 size_in_bits,11999 size_in_bits,
12035 align_in_bits,12000 align_in_bits,
12036 offset_in_bits,12001 offset_in_bits,
12037 false,
12038 );12002 );
12039}12003}
1204012004
...@@ -12175,8 +12139,7 @@ pub fn debugGlobalVar(...@@ -12175,8 +12139,7 @@ pub fn debugGlobalVar(
12175 line: u32,12139 line: u32,
12176 ty: Metadata,12140 ty: Metadata,
12177 variable: Variable.Index,12141 variable: Variable.Index,
12178 declaration: Metadata,12142 internal: bool,
12179 options: Metadata.GlobalVar.Options,
12180) Allocator.Error!Metadata {12143) Allocator.Error!Metadata {
12181 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);12144 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);
12182 return self.debugGlobalVarAssumeCapacity(12145 return self.debugGlobalVarAssumeCapacity(
...@@ -12187,8 +12150,7 @@ pub fn debugGlobalVar(...@@ -12187,8 +12150,7 @@ pub fn debugGlobalVar(
12187 line,12150 line,
12188 ty,12151 ty,
12189 variable,12152 variable,
12190 declaration,12153 internal,
12191 options,
12192 );12154 );
12193}12155}
1219412156
...@@ -12617,10 +12579,9 @@ fn debugMemberTypeAssumeCapacity(...@@ -12617,10 +12579,9 @@ fn debugMemberTypeAssumeCapacity(
12617 size_in_bits: u64,12579 size_in_bits: u64,
12618 align_in_bits: u64,12580 align_in_bits: u64,
12619 offset_in_bits: u64,12581 offset_in_bits: u64,
12620 static: bool,
12621) Metadata {12582) Metadata {
12622 assert(!self.strip);12583 assert(!self.strip);
12623 return self.metadataSimpleAssumeCapacity(if (static) .derived_static_member_type else .derived_member_type, Metadata.DerivedType{12584 return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{
12624 .name = name,12585 .name = name,
12625 .file = file,12586 .file = file,
12626 .scope = scope,12587 .scope = scope,
...@@ -12888,16 +12849,11 @@ fn debugGlobalVarAssumeCapacity(...@@ -12888,16 +12849,11 @@ fn debugGlobalVarAssumeCapacity(
12888 line: u32,12849 line: u32,
12889 ty: Metadata,12850 ty: Metadata,
12890 variable: Variable.Index,12851 variable: Variable.Index,
12891 declaration: Metadata,12852 internal: bool,
12892 options: Metadata.GlobalVar.Options,
12893) Metadata {12853) Metadata {
12894 assert(!self.strip);12854 assert(!self.strip);
12895 return self.metadataDistinctAssumeCapacity(12855 return self.metadataDistinctAssumeCapacity(
12896 switch (options) {12856 if (internal) .@"global_var local" else .global_var,
12897 .internal => .@"global_var local",
12898 .internal_decl => .@"global_var decl",
12899 .external => .global_var,
12900 },
12901 Metadata.GlobalVar{12857 Metadata.GlobalVar{
12902 .name = name,12858 .name = name,
12903 .linkage_name = linkage_name,12859 .linkage_name = linkage_name,
...@@ -12906,7 +12862,6 @@ fn debugGlobalVarAssumeCapacity(...@@ -12906,7 +12862,6 @@ fn debugGlobalVarAssumeCapacity(
12906 .line = line,12862 .line = line,
12907 .ty = ty,12863 .ty = ty,
12908 .variable = variable,12864 .variable = variable,
12909 .declaration = declaration,
12910 },12865 },
12911 );12866 );
12912}12867}
...@@ -14024,14 +13979,13 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14024,14 +13979,13 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14024 },13979 },
14025 .derived_pointer_type,13980 .derived_pointer_type,
14026 .derived_member_type,13981 .derived_member_type,
14027 .derived_static_member_type,
14028 .derived_typedef,13982 .derived_typedef,
14029 => |kind| {13983 => |kind| {
14030 const extra = self.metadataExtraData(Metadata.DerivedType, data);13984 const extra = self.metadataExtraData(Metadata.DerivedType, data);
14031 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{13985 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{
14032 .tag = switch (kind) {13986 .tag = switch (kind) {
14033 .derived_pointer_type => DW.TAG.pointer_type,13987 .derived_pointer_type => DW.TAG.pointer_type,
14034 .derived_member_type, .derived_static_member_type => DW.TAG.member,13988 .derived_member_type => DW.TAG.member,
14035 .derived_typedef => DW.TAG.typedef,13989 .derived_typedef => DW.TAG.typedef,
14036 else => unreachable,13990 else => unreachable,
14037 },13991 },
...@@ -14044,7 +13998,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14044,7 +13998,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14044 .align_in_bits = extra.bitAlign(),13998 .align_in_bits = extra.bitAlign(),
14045 .offset_in_bits = extra.bitOffset(),13999 .offset_in_bits = extra.bitOffset(),
14046 .flags = .{14000 .flags = .{
14047 .StaticMember = kind == .derived_static_member_type,14001 .StaticMember = false,
14048 },14002 },
14049 }, metadata_adapter);14003 }, metadata_adapter);
14050 },14004 },
...@@ -14184,7 +14138,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14184,7 +14138,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14184 },14138 },
14185 .global_var,14139 .global_var,
14186 .@"global_var local",14140 .@"global_var local",
14187 .@"global_var decl",
14188 => |kind| {14141 => |kind| {
14189 const extra = self.metadataExtraData(Metadata.GlobalVar, data);14142 const extra = self.metadataExtraData(Metadata.GlobalVar, data);
14190 try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalVar{14143 try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalVar{
...@@ -14195,8 +14148,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14195,8 +14148,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14195 .line = extra.line,14148 .line = extra.line,
14196 .ty = extra.ty,14149 .ty = extra.ty,
14197 .local = kind == .@"global_var local",14150 .local = kind == .@"global_var local",
14198 .defined = kind != .@"global_var decl",
14199 .declaration = extra.declaration,
14200 }, metadata_adapter);14151 }, metadata_adapter);
14201 },14152 },
14202 .global_var_expression => {14153 .global_var_expression => {
src/codegen/llvm/ir.zig+2-4
...@@ -1026,8 +1026,8 @@ pub const MetadataBlock = struct {...@@ -1026,8 +1026,8 @@ pub const MetadataBlock = struct {
1026 LineAbbrev, // line1026 LineAbbrev, // line
1027 MetadataAbbrev, // type1027 MetadataAbbrev, // type
1028 .{ .fixed = 1 }, // local1028 .{ .fixed = 1 }, // local
1029 .{ .fixed = 1 }, // defined1029 .{ .literal = 1 }, // defined
1030 MetadataAbbrev, // static data members declaration1030 .{ .literal = 0 }, // static data members declaration
1031 .{ .literal = 0 }, // template params1031 .{ .literal = 0 }, // template params
1032 .{ .literal = 0 }, // align in bits1032 .{ .literal = 0 }, // align in bits
1033 .{ .literal = 0 }, // annotations1033 .{ .literal = 0 }, // annotations
...@@ -1040,8 +1040,6 @@ pub const MetadataBlock = struct {...@@ -1040,8 +1040,6 @@ pub const MetadataBlock = struct {
1040 line: u32,1040 line: u32,
1041 ty: Builder.Metadata,1041 ty: Builder.Metadata,
1042 local: bool,1042 local: bool,
1043 defined: bool,
1044 declaration: Builder.Metadata,
1045 };1043 };
10461044
1047 pub const GlobalVarExpression = struct {1045 pub const GlobalVarExpression = struct {