authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-10-06 14:51:23-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-10-07 07:49:54-04:00
logd28006153e3f221a3755d78c74f9c7716ad660b5
treea5cc1052c40360571f99ff677e3139c327ca2691
parent2810e4b173507b6d94a7108462b5c9bdcc0b6e0b

llvm.Builder: allow `Metadata` to reference metadata strings

Closes #25486

4 files changed, 3090 insertions(+), 2728 deletions(-)

lib/std/zig/llvm/Builder.zig+830-887
...@@ -56,8 +56,8 @@ metadata_map: std.AutoArrayHashMapUnmanaged(void, void),...@@ -56,8 +56,8 @@ metadata_map: std.AutoArrayHashMapUnmanaged(void, void),
56metadata_items: std.MultiArrayList(Metadata.Item),56metadata_items: std.MultiArrayList(Metadata.Item),
57metadata_extra: std.ArrayListUnmanaged(u32),57metadata_extra: std.ArrayListUnmanaged(u32),
58metadata_limbs: std.ArrayListUnmanaged(std.math.big.Limb),58metadata_limbs: std.ArrayListUnmanaged(std.math.big.Limb),
59metadata_forward_references: std.ArrayListUnmanaged(Metadata),59metadata_forward_references: std.ArrayListUnmanaged(Metadata.Optional),
60metadata_named: std.AutoArrayHashMapUnmanaged(MetadataString, struct {60metadata_named: std.AutoArrayHashMapUnmanaged(String, struct {
61 len: u32,61 len: u32,
62 index: Metadata.Item.ExtraIndex,62 index: Metadata.Item.ExtraIndex,
63}),63}),
...@@ -265,19 +265,20 @@ pub const Type = enum(u32) {...@@ -265,19 +265,20 @@ pub const Type = enum(u32) {
265 };265 };
266266
267 pub const Simple = enum(u5) {267 pub const Simple = enum(u5) {
268 void = 2,268 const Code = ir.ModuleBlock.TypeBlock.Code;
269 half = 10,269 void = @intFromEnum(Code.VOID),
270 bfloat = 23,270 half = @intFromEnum(Code.HALF),
271 float = 3,271 bfloat = @intFromEnum(Code.BFLOAT),
272 double = 4,272 float = @intFromEnum(Code.FLOAT),
273 fp128 = 14,273 double = @intFromEnum(Code.DOUBLE),
274 x86_fp80 = 13,274 fp128 = @intFromEnum(Code.FP128),
275 ppc_fp128 = 15,275 x86_fp80 = @intFromEnum(Code.X86_FP80),
276 x86_amx = 24,276 ppc_fp128 = @intFromEnum(Code.PPC_FP128),
277 x86_mmx = 17,277 x86_amx = @intFromEnum(Code.X86_AMX),
278 label = 5,278 x86_mmx = @intFromEnum(Code.X86_MMX),
279 token = 22,279 label = @intFromEnum(Code.LABEL),
280 metadata = 16,280 token = @intFromEnum(Code.TOKEN),
281 metadata = @intFromEnum(Code.METADATA),
281 };282 };
282283
283 pub const Function = struct {284 pub const Function = struct {
...@@ -1325,8 +1326,8 @@ pub const Attribute = union(Kind) {...@@ -1325,8 +1326,8 @@ pub const Attribute = union(Kind) {
1325 .none => unreachable,1326 .none => unreachable,
1326 }1327 }
1327 }1328 }
1328 pub fn fmt(self: Index, builder: *const Builder, mode: FormatData.mode) std.fmt.Alt(FormatData, format) {1329 pub fn fmt(self: Index, builder: *const Builder, flags: FormatData.Flags) std.fmt.Alt(FormatData, format) {
1329 return .{ .data = .{ .attribute_index = self, .builder = builder, .mode = mode } };1330 return .{ .data = .{ .attribute_index = self, .builder = builder, .flags = flags } };
1330 }1331 }
13311332
1332 fn toStorage(self: Index, builder: *const Builder) Storage {1333 fn toStorage(self: Index, builder: *const Builder) Storage {
...@@ -2295,7 +2296,7 @@ pub const Global = struct {...@@ -2295,7 +2296,7 @@ pub const Global = struct {
2295 externally_initialized: ExternallyInitialized = .default,2296 externally_initialized: ExternallyInitialized = .default,
2296 type: Type,2297 type: Type,
2297 partition: String = .none,2298 partition: String = .none,
2298 dbg: Metadata = .none,2299 dbg: Metadata.Optional = .none,
2299 kind: union(enum) {2300 kind: union(enum) {
2300 alias: Alias.Index,2301 alias: Alias.Index,
2301 variable: Variable.Index,2302 variable: Variable.Index,
...@@ -2375,7 +2376,11 @@ pub const Global = struct {...@@ -2375,7 +2376,11 @@ pub const Global = struct {
2375 }2376 }
23762377
2377 pub fn setDebugMetadata(self: Index, dbg: Metadata, builder: *Builder) void {2378 pub fn setDebugMetadata(self: Index, dbg: Metadata, builder: *Builder) void {
2378 self.ptr(builder).dbg = dbg;2379 self.ptr(builder).dbg = dbg.toOptional();
2380 }
2381
2382 pub fn getDebugMetadata(self: Index, builder: *const Builder) Metadata.Optional {
2383 return self.ptrConst(builder).dbg;
2379 }2384 }
23802385
2381 const FormatData = struct {2386 const FormatData = struct {
...@@ -2606,6 +2611,10 @@ pub const Variable = struct {...@@ -2606,6 +2611,10 @@ pub const Variable = struct {
2606 pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void {2611 pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void {
2607 self.ptrConst(builder).global.setDebugMetadata(expression, builder);2612 self.ptrConst(builder).global.setDebugMetadata(expression, builder);
2608 }2613 }
2614
2615 pub fn getGlobalVariableExpression(self: Index, builder: *Builder) Metadata.Optional {
2616 return self.ptrConst(builder).global.getDebugMetadata(builder);
2617 }
2609 };2618 };
2610};2619};
26112620
...@@ -4107,6 +4116,10 @@ pub const Function = struct {...@@ -4107,6 +4116,10 @@ pub const Function = struct {
4107 pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void {4116 pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void {
4108 self.ptrConst(builder).global.setDebugMetadata(subprogram, builder);4117 self.ptrConst(builder).global.setDebugMetadata(subprogram, builder);
4109 }4118 }
4119
4120 pub fn getSubprogram(self: Index, builder: *const Builder) Metadata.Optional {
4121 return self.ptrConst(builder).global.getDebugMetadata(builder);
4122 }
4110 };4123 };
41114124
4112 pub const Block = struct {4125 pub const Block = struct {
...@@ -4869,13 +4882,20 @@ pub const Function = struct {...@@ -4869,13 +4882,20 @@ pub const Function = struct {
4869 then: Block.Index,4882 then: Block.Index,
4870 @"else": Block.Index,4883 @"else": Block.Index,
4871 weights: Weights,4884 weights: Weights,
4885
4872 pub const Weights = enum(u32) {4886 pub const Weights = enum(u32) {
4873 // We can do this as metadata indices 0 and 1 are reserved.4887 none = @bitCast(Metadata.Optional.none),
4874 none = 0,4888 unpredictable,
4875 unpredictable = 1,
4876 /// These values should be converted to `Metadata` to be used
4877 /// in a `prof` annotation providing branch weights.
4878 _,4889 _,
4890
4891 pub fn fromMetadata(metadata: Metadata) Weights {
4892 assert(metadata.kind == .node);
4893 return @enumFromInt(metadata.index);
4894 }
4895
4896 pub fn toMetadata(weights: Weights) Metadata {
4897 return .{ .index = @intCast(@intFromEnum(weights)), .kind = .node };
4898 }
4879 };4899 };
4880 };4900 };
48814901
...@@ -5130,19 +5150,19 @@ pub const DebugLocation = union(enum) {...@@ -5130,19 +5150,19 @@ pub const DebugLocation = union(enum) {
5130 pub const Location = struct {5150 pub const Location = struct {
5131 line: u32,5151 line: u32,
5132 column: u32,5152 column: u32,
5133 scope: Builder.Metadata,5153 scope: Builder.Metadata.Optional,
5134 inlined_at: Builder.Metadata,5154 inlined_at: Builder.Metadata.Optional,
5135 };5155 };
51365156
5137 pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata {5157 pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata.Optional {
5138 return switch (self) {5158 return switch (self) {
5139 .no_location => .none,5159 .no_location => .none,
5140 .location => |location| try builder.debugLocation(5160 .location => |location| (try builder.debugLocation(
5141 location.line,5161 location.line,
5142 location.column,5162 location.column,
5143 location.scope,5163 location.scope.unwrap().?,
5144 location.inlined_at,5164 location.inlined_at.unwrap(),
5145 ),5165 )).toOptional(),
5146 };5166 };
5147 }5167 }
5148};5168};
...@@ -5280,20 +5300,19 @@ pub const WipFunction = struct {...@@ -5280,20 +5300,19 @@ pub const WipFunction = struct {
5280 .cond = cond,5300 .cond = cond,
5281 .then = then,5301 .then = then,
5282 .@"else" = @"else",5302 .@"else" = @"else",
5283 .weights = switch (weights) {5303 .weights = weights: switch (weights) {
5284 .none => .none,5304 .none => .none,
5285 .unpredictable => .unpredictable,5305 .unpredictable => .unpredictable,
5286 .then_likely, .else_likely => w: {5306 .then_likely, .else_likely => {
5287 const branch_weights_str = try self.builder.metadataString("branch_weights");5307 const branch_weights_str = try self.builder.metadataString("branch_weights");
5288 const unlikely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 1));5308 const unlikely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 1));
5289 const likely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 2000));5309 const likely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 2000));
5290 const weight_vals: [2]Metadata = switch (weights) {5310 const weight_vals: [3]Metadata = switch (weights) {
5291 .none, .unpredictable => unreachable,5311 .none, .unpredictable => unreachable,
5292 .then_likely => .{ likely_const, unlikely_const },5312 .then_likely => .{ branch_weights_str.toMetadata(), likely_const, unlikely_const },
5293 .else_likely => .{ unlikely_const, likely_const },5313 .else_likely => .{ branch_weights_str.toMetadata(), unlikely_const, likely_const },
5294 };5314 };
5295 const tuple = try self.builder.strTuple(branch_weights_str, &weight_vals);5315 break :weights .fromMetadata(try self.builder.metadataTuple(&weight_vals));
5296 break :w @enumFromInt(@intFromEnum(tuple));
5297 },5316 },
5298 },5317 },
5299 }),5318 }),
...@@ -6197,20 +6216,18 @@ pub const WipFunction = struct {...@@ -6197,20 +6216,18 @@ pub const WipFunction = struct {
6197 return instruction.toValue();6216 return instruction.toValue();
6198 }6217 }
61996218
6200 pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata {6219 pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata.Optional {
6201 if (self.strip) return .none;6220 if (self.strip) return .none;
6202 return switch (value.unwrap()) {6221 const metadata: Metadata = metadata: switch (value.unwrap()) {
6203 .instruction => |instr_index| blk: {6222 .instruction => |instr_index| {
6204 const gop = try self.debug_values.getOrPut(self.builder.gpa, instr_index);6223 const gop = try self.debug_values.getOrPut(self.builder.gpa, instr_index);
6205
6206 const metadata: Metadata = @enumFromInt(Metadata.first_local_metadata + gop.index);
6207 if (!gop.found_existing) gop.key_ptr.* = instr_index;6224 if (!gop.found_existing) gop.key_ptr.* = instr_index;
62086225 break :metadata .{ .index = @intCast(gop.index), .kind = .local };
6209 break :blk metadata;
6210 },6226 },
6211 .constant => |constant| try self.builder.metadataConstant(constant),6227 .constant => |constant| try self.builder.metadataConstant(constant),
6212 .metadata => |metadata| metadata,6228 .metadata => |metadata| metadata,
6213 };6229 };
6230 return metadata.toOptional();
6214 }6231 }
62156232
6216 pub fn finish(self: *WipFunction) Allocator.Error!void {6233 pub fn finish(self: *WipFunction) Allocator.Error!void {
...@@ -7820,7 +7837,7 @@ pub const Value = enum(u32) {...@@ -7820,7 +7837,7 @@ pub const Value = enum(u32) {
7820 else if (@intFromEnum(self) < first_metadata)7837 else if (@intFromEnum(self) < first_metadata)
7821 .{ .constant = @enumFromInt(@intFromEnum(self) - first_constant) }7838 .{ .constant = @enumFromInt(@intFromEnum(self) - first_constant) }
7822 else7839 else
7823 .{ .metadata = @enumFromInt(@intFromEnum(self) - first_metadata) };7840 .{ .metadata = @bitCast(@intFromEnum(self) - first_metadata) };
7824 }7841 }
78257842
7826 pub fn typeOfWip(self: Value, wip: *const WipFunction) Type {7843 pub fn typeOfWip(self: Value, wip: *const WipFunction) Type {
...@@ -7873,50 +7890,110 @@ pub const Value = enum(u32) {...@@ -7873,50 +7890,110 @@ pub const Value = enum(u32) {
7873 }7890 }
7874};7891};
78757892
7876pub const MetadataString = enum(u32) {7893pub const Metadata = packed struct(u32) {
7877 none = 0,7894 index: u29,
7878 _,7895 kind: Kind,
7896 unused: enum(u1) { unused = 0 } = .unused,
78797897
7880 pub fn slice(self: MetadataString, builder: *const Builder) []const u8 {7898 pub const Kind = enum(u2) {
7881 const index = @intFromEnum(self);7899 string,
7882 const start = builder.metadata_string_indices.items[index];7900 node,
7883 const end = builder.metadata_string_indices.items[index + 1];7901 forward,
7884 return builder.metadata_string_bytes.items[start..end];7902 local,
7885 }7903 };
78867904
7887 const Adapter = struct {7905 pub const empty_tuple: Metadata = .{ .kind = .node, .index = 0 };
7888 builder: *const Builder,7906
7889 pub fn hash(_: Adapter, key: []const u8) u32 {7907 pub const Optional = packed struct(u32) {
7890 return @truncate(std.hash.Wyhash.hash(0, key));7908 index: u29,
7909 kind: Metadata.Kind,
7910 is_none: bool,
7911
7912 pub const none: Metadata.Optional = .{ .index = 0, .kind = .string, .is_none = true };
7913 pub const empty_tuple: Metadata.Optional = Metadata.empty_tuple.toOptional();
7914
7915 pub fn wrap(metadata: ?Metadata) Metadata.Optional {
7916 return (metadata orelse return .none).toOptional();
7891 }7917 }
7892 pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool {7918 pub fn unwrap(metadata: Metadata.Optional) ?Metadata {
7893 const rhs_metadata_string: MetadataString = @enumFromInt(rhs_index);7919 return if (metadata.is_none) null else .{ .index = metadata.index, .kind = metadata.kind };
7894 return std.mem.eql(u8, lhs_key, rhs_metadata_string.slice(ctx.builder));7920 }
7921 pub fn toValue(metadata: Metadata.Optional) Value {
7922 return if (metadata.unwrap()) |m| m.toValue() else .none;
7923 }
7924 pub fn toString(metadata: Metadata.Optional) Metadata.String.Optional {
7925 return if (metadata.unwrap()) |m| m.toString().toOptional() else .none;
7895 }7926 }
7896 };7927 };
78977928 pub fn toOptional(metadata: Metadata) Metadata.Optional {
7898 const FormatData = struct {7929 return .{ .index = metadata.index, .kind = metadata.kind, .is_none = false };
7899 metadata_string: MetadataString,
7900 builder: *const Builder,
7901 };
7902 fn format(data: FormatData, w: *Writer) Writer.Error!void {
7903 try printEscapedString(data.metadata_string.slice(data.builder), .always_quote, w);
7904 }7930 }
7905 fn fmt(self: MetadataString, builder: *const Builder) std.fmt.Alt(FormatData, format) {7931 pub fn toValue(metadata: Metadata) Value {
7906 return .{ .data = .{ .metadata_string = self, .builder = builder } };7932 return @enumFromInt(Value.first_metadata + @as(u32, @bitCast(metadata)));
7907 }7933 }
7908};
79097934
7910pub const Metadata = enum(u32) {7935 pub const String = enum(u32) {
7911 none = 0,7936 _,
7912 empty_tuple = 1,7937
7913 _,7938 pub const Optional = enum(u32) {
7939 none = @bitCast(Metadata.Optional.none),
7940 _,
7941
7942 pub fn wrap(metadata: ?Metadata.String) Metadata.String.Optional {
7943 return (metadata orelse return .none).toOptional();
7944 }
7945 pub fn unwrap(metadata: Metadata.String.Optional) ?Metadata.String {
7946 return switch (metadata) {
7947 .none => null,
7948 else => @enumFromInt(@intFromEnum(metadata)),
7949 };
7950 }
7951 pub fn toMetadata(metadata: Metadata.String.Optional) Metadata.Optional {
7952 return if (metadata.unwrap()) |m| m.toMetadata().toOptional() else .none;
7953 }
7954 };
7955 pub fn toOptional(metadata: Metadata.String) Metadata.String.Optional {
7956 return @enumFromInt(@intFromEnum(metadata));
7957 }
7958 pub fn toMetadata(metadata: Metadata.String) Metadata {
7959 return .{ .index = @intCast(@intFromEnum(metadata)), .kind = .string };
7960 }
79147961
7915 const first_forward_reference = 1 << 29;7962 pub fn slice(metadata: Metadata.String, builder: *const Builder) []const u8 {
7916 const first_local_metadata = 1 << 30;7963 const index = @intFromEnum(metadata);
7964 const start = builder.metadata_string_indices.items[index];
7965 const end = builder.metadata_string_indices.items[index + 1];
7966 return builder.metadata_string_bytes.items[start..end];
7967 }
7968
7969 const Adapter = struct {
7970 builder: *const Builder,
7971 pub fn hash(_: Adapter, key: []const u8) u32 {
7972 return @truncate(std.hash.Wyhash.hash(0, key));
7973 }
7974 pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool {
7975 const rhs_metadata: Metadata.String = @enumFromInt(rhs_index);
7976 return std.mem.eql(u8, lhs_key, rhs_metadata.slice(ctx.builder));
7977 }
7978 };
7979
7980 const FormatData = struct {
7981 metadata: Metadata.String,
7982 builder: *const Builder,
7983 };
7984 fn format(data: FormatData, w: *Writer) Writer.Error!void {
7985 try printEscapedString(data.metadata.slice(data.builder), .always_quote, w);
7986 }
7987 fn fmt(self: Metadata.String, builder: *const Builder) std.fmt.Alt(FormatData, format) {
7988 return .{ .data = .{ .metadata = self, .builder = builder } };
7989 }
7990 };
7991 pub fn toString(metadata: Metadata) Metadata.String {
7992 assert(metadata.kind == .string);
7993 return @enumFromInt(metadata.index);
7994 }
79177995
7918 pub const Tag = enum(u6) {7996 pub const Tag = enum(u6) {
7919 none,
7920 file,7997 file,
7921 compile_unit,7998 compile_unit,
7922 @"compile_unit optimized",7999 @"compile_unit optimized",
...@@ -7947,8 +8024,6 @@ pub const Metadata = enum(u32) {...@@ -7947,8 +8024,6 @@ pub const Metadata = enum(u32) {
7947 enumerator_signed_negative,8024 enumerator_signed_negative,
7948 subrange,8025 subrange,
7949 tuple,8026 tuple,
7950 str_tuple,
7951 module_flag,
7952 expression,8027 expression,
7953 local_var,8028 local_var,
7954 parameter,8029 parameter,
...@@ -7957,9 +8032,8 @@ pub const Metadata = enum(u32) {...@@ -7957,9 +8032,8 @@ pub const Metadata = enum(u32) {
7957 global_var_expression,8032 global_var_expression,
7958 constant,8033 constant,
79598034
7960 pub fn isInline(tag: Tag) bool {8035 pub fn isInline(metadata_tag: Metadata.Tag) bool {
7961 return switch (tag) {8036 return switch (metadata_tag) {
7962 .none,
7963 .expression,8037 .expression,
7964 .constant,8038 .constant,
7965 => true,8039 => true,
...@@ -7993,8 +8067,6 @@ pub const Metadata = enum(u32) {...@@ -7993,8 +8067,6 @@ pub const Metadata = enum(u32) {
7993 .enumerator_signed_negative,8067 .enumerator_signed_negative,
7994 .subrange,8068 .subrange,
7995 .tuple,8069 .tuple,
7996 .str_tuple,
7997 .module_flag,
7998 .local_var,8070 .local_var,
7999 .parameter,8071 .parameter,
8000 .global_var,8072 .global_var,
...@@ -8005,20 +8077,31 @@ pub const Metadata = enum(u32) {...@@ -8005,20 +8077,31 @@ pub const Metadata = enum(u32) {
8005 }8077 }
8006 };8078 };
80078079
8008 pub fn isInline(self: Metadata, builder: *const Builder) bool {8080 pub fn tag(metadata: Metadata, builder: *const Builder) Tag {
8009 return builder.metadata_items.items(.tag)[@intFromEnum(self)].isInline();8081 assert(metadata.kind == .node);
8082 return builder.metadata_items.items(.tag)[metadata.index];
8010 }8083 }
80118084
8012 pub fn unwrap(self: Metadata, builder: *const Builder) Metadata {8085 pub fn item(metadata: Metadata, builder: *const Builder) Item {
8013 var metadata = self;8086 assert(metadata.kind == .node);
8014 while (@intFromEnum(metadata) >= Metadata.first_forward_reference and8087 return builder.metadata_items.get(metadata.index);
8015 @intFromEnum(metadata) < Metadata.first_local_metadata)8088 }
8016 {8089
8017 const index = @intFromEnum(metadata) - Metadata.first_forward_reference;8090 pub fn isInline(metadata: Metadata, builder: *const Builder) bool {
8018 metadata = builder.metadata_forward_references.items[index];8091 return metadata.tag(builder).isInline();
8019 assert(metadata != .none);8092 }
8093
8094 pub fn unwrap(metadata: Metadata, builder: *const Builder) Metadata {
8095 switch (metadata.kind) {
8096 .string, .node, .local => return metadata,
8097 .forward => {
8098 const referenced = builder.metadata_forward_references.items[metadata.index].unwrap().?;
8099 switch (referenced.kind) {
8100 .string, .node => return referenced,
8101 .forward, .local => unreachable,
8102 }
8103 },
8020 }8104 }
8021 return metadata;
8022 }8105 }
80238106
8024 pub const Item = struct {8107 pub const Item = struct {
...@@ -8086,8 +8169,8 @@ pub const Metadata = enum(u32) {...@@ -8086,8 +8169,8 @@ pub const Metadata = enum(u32) {
8086 };8169 };
80878170
8088 pub const File = struct {8171 pub const File = struct {
8089 filename: MetadataString,8172 filename: Metadata.String.Optional,
8090 directory: MetadataString,8173 directory: Metadata.String.Optional,
8091 };8174 };
80928175
8093 pub const CompileUnit = struct {8176 pub const CompileUnit = struct {
...@@ -8095,10 +8178,10 @@ pub const Metadata = enum(u32) {...@@ -8095,10 +8178,10 @@ pub const Metadata = enum(u32) {
8095 optimized: bool,8178 optimized: bool,
8096 };8179 };
80978180
8098 file: Metadata,8181 file: Metadata.Optional,
8099 producer: MetadataString,8182 producer: Metadata.String.Optional,
8100 enums: Metadata,8183 enums: Metadata.Optional,
8101 globals: Metadata,8184 globals: Metadata.Optional,
8102 };8185 };
81038186
8104 pub const Subprogram = struct {8187 pub const Subprogram = struct {
...@@ -8142,19 +8225,34 @@ pub const Metadata = enum(u32) {...@@ -8142,19 +8225,34 @@ pub const Metadata = enum(u32) {
8142 }8225 }
8143 };8226 };
81448227
8145 file: Metadata,8228 file: Metadata.Optional,
8146 name: MetadataString,8229 name: Metadata.String.Optional,
8147 linkage_name: MetadataString,8230 linkage_name: Metadata.String.Optional,
8148 line: u32,8231 line: u32,
8149 scope_line: u32,8232 scope_line: u32,
8150 ty: Metadata,8233 ty: Metadata.Optional,
8151 di_flags: DIFlags,8234 di_flags: DIFlags,
8152 compile_unit: Metadata,8235 compile_unit: Metadata.Optional,
8153 };8236 };
8237 pub fn getSubprogram(metadata: Metadata, builder: *const Builder) Subprogram {
8238 const metadata_item = metadata.item(builder);
8239 switch (metadata_item.tag) {
8240 else => unreachable,
8241 .subprogram,
8242 .@"subprogram local",
8243 .@"subprogram definition",
8244 .@"subprogram local definition",
8245 .@"subprogram optimized",
8246 .@"subprogram optimized local",
8247 .@"subprogram optimized definition",
8248 .@"subprogram optimized local definition",
8249 => return builder.metadataExtraData(Metadata.Subprogram, metadata_item.data),
8250 }
8251 }
81548252
8155 pub const LexicalBlock = struct {8253 pub const LexicalBlock = struct {
8156 scope: Metadata,8254 scope: Metadata.Optional,
8157 file: Metadata,8255 file: Metadata.Optional,
8158 line: u32,8256 line: u32,
8159 column: u32,8257 column: u32,
8160 };8258 };
...@@ -8163,11 +8261,11 @@ pub const Metadata = enum(u32) {...@@ -8163,11 +8261,11 @@ pub const Metadata = enum(u32) {
8163 line: u32,8261 line: u32,
8164 column: u32,8262 column: u32,
8165 scope: Metadata,8263 scope: Metadata,
8166 inlined_at: Metadata,8264 inlined_at: Metadata.Optional,
8167 };8265 };
81688266
8169 pub const BasicType = struct {8267 pub const BasicType = struct {
8170 name: MetadataString,8268 name: Metadata.String.Optional,
8171 size_in_bits_lo: u32,8269 size_in_bits_lo: u32,
8172 size_in_bits_hi: u32,8270 size_in_bits_hi: u32,
81738271
...@@ -8177,16 +8275,16 @@ pub const Metadata = enum(u32) {...@@ -8177,16 +8275,16 @@ pub const Metadata = enum(u32) {
8177 };8275 };
81788276
8179 pub const CompositeType = struct {8277 pub const CompositeType = struct {
8180 name: MetadataString,8278 name: Metadata.String.Optional,
8181 file: Metadata,8279 file: Metadata.Optional,
8182 scope: Metadata,8280 scope: Metadata.Optional,
8183 line: u32,8281 line: u32,
8184 underlying_type: Metadata,8282 underlying_type: Metadata.Optional,
8185 size_in_bits_lo: u32,8283 size_in_bits_lo: u32,
8186 size_in_bits_hi: u32,8284 size_in_bits_hi: u32,
8187 align_in_bits_lo: u32,8285 align_in_bits_lo: u32,
8188 align_in_bits_hi: u32,8286 align_in_bits_hi: u32,
8189 fields_tuple: Metadata,8287 fields_tuple: Metadata.Optional,
81908288
8191 pub fn bitSize(self: CompositeType) u64 {8289 pub fn bitSize(self: CompositeType) u64 {
8192 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;8290 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
...@@ -8197,11 +8295,11 @@ pub const Metadata = enum(u32) {...@@ -8197,11 +8295,11 @@ pub const Metadata = enum(u32) {
8197 };8295 };
81988296
8199 pub const DerivedType = struct {8297 pub const DerivedType = struct {
8200 name: MetadataString,8298 name: Metadata.String.Optional,
8201 file: Metadata,8299 file: Metadata.Optional,
8202 scope: Metadata,8300 scope: Metadata.Optional,
8203 line: u32,8301 line: u32,
8204 underlying_type: Metadata,8302 underlying_type: Metadata.Optional,
8205 size_in_bits_lo: u32,8303 size_in_bits_lo: u32,
8206 size_in_bits_hi: u32,8304 size_in_bits_hi: u32,
8207 align_in_bits_lo: u32,8305 align_in_bits_lo: u32,
...@@ -8221,19 +8319,19 @@ pub const Metadata = enum(u32) {...@@ -8221,19 +8319,19 @@ pub const Metadata = enum(u32) {
8221 };8319 };
82228320
8223 pub const SubroutineType = struct {8321 pub const SubroutineType = struct {
8224 types_tuple: Metadata,8322 types_tuple: Metadata.Optional,
8225 };8323 };
82268324
8227 pub const Enumerator = struct {8325 pub const Enumerator = struct {
8228 name: MetadataString,8326 name: Metadata.String.Optional,
8229 bit_width: u32,8327 bit_width: u32,
8230 limbs_index: u32,8328 limbs_index: u32,
8231 limbs_len: u32,8329 limbs_len: u32,
8232 };8330 };
82338331
8234 pub const Subrange = struct {8332 pub const Subrange = struct {
8235 lower_bound: Metadata,8333 lower_bound: Metadata.Optional,
8236 count: Metadata,8334 count: Metadata.Optional,
8237 };8335 };
82388336
8239 pub const Expression = struct {8337 pub const Expression = struct {
...@@ -8248,33 +8346,20 @@ pub const Metadata = enum(u32) {...@@ -8248,33 +8346,20 @@ pub const Metadata = enum(u32) {
8248 // elements: [elements_len]Metadata8346 // elements: [elements_len]Metadata
8249 };8347 };
82508348
8251 pub const StrTuple = struct {
8252 str: MetadataString,
8253 elements_len: u32,
8254
8255 // elements: [elements_len]Metadata
8256 };
8257
8258 pub const ModuleFlag = struct {
8259 behavior: Metadata,
8260 name: MetadataString,
8261 constant: Metadata,
8262 };
8263
8264 pub const LocalVar = struct {8349 pub const LocalVar = struct {
8265 name: MetadataString,8350 name: Metadata.String.Optional,
8266 file: Metadata,8351 file: Metadata.Optional,
8267 scope: Metadata,8352 scope: Metadata.Optional,
8268 line: u32,8353 line: u32,
8269 ty: Metadata,8354 ty: Metadata.Optional,
8270 };8355 };
82718356
8272 pub const Parameter = struct {8357 pub const Parameter = struct {
8273 name: MetadataString,8358 name: Metadata.String.Optional,
8274 file: Metadata,8359 file: Metadata.Optional,
8275 scope: Metadata,8360 scope: Metadata.Optional,
8276 line: u32,8361 line: u32,
8277 ty: Metadata,8362 ty: Metadata.Optional,
8278 arg_no: u32,8363 arg_no: u32,
8279 };8364 };
82808365
...@@ -8283,24 +8368,20 @@ pub const Metadata = enum(u32) {...@@ -8283,24 +8368,20 @@ pub const Metadata = enum(u32) {
8283 local: bool,8368 local: bool,
8284 };8369 };
82858370
8286 name: MetadataString,8371 name: Metadata.String.Optional,
8287 linkage_name: MetadataString,8372 linkage_name: Metadata.String.Optional,
8288 file: Metadata,8373 file: Metadata.Optional,
8289 scope: Metadata,8374 scope: Metadata.Optional,
8290 line: u32,8375 line: u32,
8291 ty: Metadata,8376 ty: Metadata.Optional,
8292 variable: Variable.Index,8377 variable: Variable.Index,
8293 };8378 };
82948379
8295 pub const GlobalVarExpression = struct {8380 pub const GlobalVarExpression = struct {
8296 variable: Metadata,8381 variable: Metadata.Optional,
8297 expression: Metadata,8382 expression: Metadata.Optional,
8298 };8383 };
82998384
8300 pub fn toValue(self: Metadata) Value {
8301 return @enumFromInt(Value.first_metadata + @intFromEnum(self));
8302 }
8303
8304 const Formatter = struct {8385 const Formatter = struct {
8305 builder: *Builder,8386 builder: *Builder,
8306 need_comma: bool,8387 need_comma: bool,
...@@ -8325,7 +8406,7 @@ pub const Metadata = enum(u32) {...@@ -8325,7 +8406,7 @@ pub const Metadata = enum(u32) {
8325 local_inline: Metadata,8406 local_inline: Metadata,
8326 local_index: u32,8407 local_index: u32,
83278408
8328 string: MetadataString,8409 string: Metadata.String,
8329 bool: bool,8410 bool: bool,
8330 u32: u32,8411 u32: u32,
8331 u64: u64,8412 u64: u64,
...@@ -8356,10 +8437,10 @@ pub const Metadata = enum(u32) {...@@ -8356,10 +8437,10 @@ pub const Metadata = enum(u32) {
8356 defer data.formatter.need_comma = needed_comma;8437 defer data.formatter.need_comma = needed_comma;
8357 data.formatter.need_comma = false;8438 data.formatter.need_comma = false;
83588439
8359 const item = builder.metadata_items.get(@intFromEnum(node));8440 const node_item = node.item(builder);
8360 switch (item.tag) {8441 switch (node_item.tag) {
8361 .expression => {8442 .expression => {
8362 var extra = builder.metadataExtraDataTrail(Expression, item.data);8443 var extra = builder.metadataExtraDataTrail(Expression, node_item.data);
8363 const elements = extra.trail.next(extra.data.elements_len, u32, builder);8444 const elements = extra.trail.next(extra.data.elements_len, u32, builder);
8364 try w.writeAll("!DIExpression(");8445 try w.writeAll("!DIExpression(");
8365 for (elements) |element| try format(.{8446 for (elements) |element| try format(.{
...@@ -8370,7 +8451,7 @@ pub const Metadata = enum(u32) {...@@ -8370,7 +8451,7 @@ pub const Metadata = enum(u32) {
8370 try w.writeByte(')');8451 try w.writeByte(')');
8371 },8452 },
8372 .constant => try Constant.format(.{8453 .constant => try Constant.format(.{
8373 .constant = @enumFromInt(item.data),8454 .constant = @enumFromInt(node_item.data),
8374 .builder = builder,8455 .builder = builder,
8375 .flags = data.specialized orelse .{},8456 .flags = data.specialized orelse .{},
8376 }, w),8457 }, w),
...@@ -8378,17 +8459,17 @@ pub const Metadata = enum(u32) {...@@ -8378,17 +8459,17 @@ pub const Metadata = enum(u32) {
8378 }8459 }
8379 },8460 },
8380 .index => |node| try w.print("!{d}", .{node}),8461 .index => |node| try w.print("!{d}", .{node}),
8381 inline .local_value, .local_metadata => |node, tag| try Value.format(.{8462 inline .local_value, .local_metadata => |node, node_tag| try Value.format(.{
8382 .value = node.value,8463 .value = node.value,
8383 .function = node.function,8464 .function = node.function,
8384 .builder = builder,8465 .builder = builder,
8385 .flags = switch (tag) {8466 .flags = switch (node_tag) {
8386 .local_value => data.specialized orelse .{},8467 .local_value => data.specialized orelse .{},
8387 .local_metadata => .{ .percent = true },8468 .local_metadata => .{ .percent = true },
8388 else => unreachable,8469 else => unreachable,
8389 },8470 },
8390 }, w),8471 }, w),
8391 inline .local_inline, .local_index => |node, tag| {8472 inline .local_inline, .local_index => |node, node_tag| {
8392 if (data.specialized) |flags| {8473 if (data.specialized) |flags| {
8393 if (flags.onlyPercent()) {8474 if (flags.onlyPercent()) {
8394 try w.print("{f} ", .{Type.metadata.fmt(builder, .percent)});8475 try w.print("{f} ", .{Type.metadata.fmt(builder, .percent)});
...@@ -8396,39 +8477,43 @@ pub const Metadata = enum(u32) {...@@ -8396,39 +8477,43 @@ pub const Metadata = enum(u32) {
8396 }8477 }
8397 try format(.{8478 try format(.{
8398 .formatter = data.formatter,8479 .formatter = data.formatter,
8399 .node = @unionInit(FormatData.Node, @tagName(tag)["local_".len..], node),8480 .node = @unionInit(FormatData.Node, @tagName(node_tag)["local_".len..], node),
8400 .specialized = .{ .percent = true },8481 .specialized = .{ .percent = true },
8401 }, w);8482 }, w);
8402 },8483 },
8403 .string => |node| try w.print("{s}{f}", .{8484 .string => |s| {
8404 @as([]const u8, if (is_specialized) "!" else ""), node.fmt(builder),8485 if (is_specialized) try w.writeByte('!');
8405 }),8486 try w.print("{f}", .{s.fmt(builder)});
8487 },
8406 inline .bool, .u32, .u64 => |node| try w.print("{}", .{node}),8488 inline .bool, .u32, .u64 => |node| try w.print("{}", .{node}),
8407 inline .di_flags, .sp_flags => |node| try w.print("{f}", .{node}),8489 inline .di_flags, .sp_flags => |node| try w.print("{f}", .{node}),
8408 .raw => |node| try w.writeAll(node),8490 .raw => |node| try w.writeAll(node),
8409 }8491 }
8410 }8492 }
8411 inline fn fmt(formatter: *Formatter, prefix: []const u8, node: anytype, special: ?FormatFlags) switch (@TypeOf(node)) {8493 inline fn fmt(formatter: *Formatter, prefix: []const u8, node: anytype, special: ?FormatFlags) switch (@TypeOf(node)) {
8412 Metadata => Allocator.Error,8494 Metadata, Metadata.Optional, ?Metadata => Allocator.Error,
8413 else => error{},8495 else => error{},
8414 }!std.fmt.Alt(FormatData, format) {8496 }!std.fmt.Alt(FormatData, format) {
8415 const Node = @TypeOf(node);8497 const Node = @TypeOf(node);
8416 const MaybeNode = switch (@typeInfo(Node)) {8498 const MaybeNode = switch (Node) {
8417 .optional => Node,8499 Metadata.Optional => ?Metadata,
8418 .null => ?noreturn,8500 Metadata.String.Optional => ?Metadata.String,
8419 else => ?Node,8501 else => switch (@typeInfo(Node)) {
8502 .optional => Node,
8503 .null => ?noreturn,
8504 else => ?Node,
8505 },
8420 };8506 };
8421 const Some = @typeInfo(MaybeNode).optional.child;8507 const Some = @typeInfo(MaybeNode).optional.child;
8422 return .{ .data = .{8508 return .{ .data = .{
8423 .formatter = formatter,8509 .formatter = formatter,
8424 .prefix = prefix,8510 .prefix = prefix,
8425 .node = if (@as(MaybeNode, node)) |some| switch (@typeInfo(Some)) {8511 .node = if (@as(MaybeNode, switch (Node) {
8512 Metadata.Optional, Metadata.String.Optional => node.unwrap(),
8513 else => node,
8514 })) |some| switch (@typeInfo(Some)) {
8426 .@"enum" => |enum_info| switch (Some) {8515 .@"enum" => |enum_info| switch (Some) {
8427 Metadata => switch (some) {8516 Metadata.String => .{ .string = some },
8428 .none => .none,
8429 else => try formatter.refUnwrapped(some.unwrap(formatter.builder)),
8430 },
8431 MetadataString => .{ .string = some },
8432 else => if (enum_info.is_exhaustive)8517 else => if (enum_info.is_exhaustive)
8433 .{ .raw = @tagName(some) }8518 .{ .raw = @tagName(some) }
8434 else8519 else
...@@ -8438,15 +8523,23 @@ pub const Metadata = enum(u32) {...@@ -8438,15 +8523,23 @@ pub const Metadata = enum(u32) {
8438 .bool => .{ .bool = some },8523 .bool => .{ .bool = some },
8439 .@"struct" => switch (Some) {8524 .@"struct" => switch (Some) {
8440 DIFlags => .{ .di_flags = some },8525 DIFlags => .{ .di_flags = some },
8526 Metadata => switch (some.kind) {
8527 .string => .{ .string = some.toString() },
8528 .node, .forward => try formatter.refUnwrapped(some.unwrap(formatter.builder)),
8529 .local => unreachable,
8530 },
8441 Subprogram.DISPFlags => .{ .sp_flags = some },8531 Subprogram.DISPFlags => .{ .sp_flags = some },
8442 else => @compileError("unknown type to format: " ++ @typeName(Node)),8532 else => @compileError("unknown type to format: " ++ @typeName(Node)),
8443 },8533 },
8444 .int, .comptime_int => .{ .u64 = some },8534 .int, .comptime_int => .{ .u64 = some },
8445 .pointer => .{ .raw = some },8535 .pointer => .{ .raw = some },
8446 else => @compileError("unknown type to format: " ++ @typeName(Node)),8536 else => @compileError("unknown type to format: " ++ @typeName(Node)),
8447 } else switch (@typeInfo(Node)) {8537 } else switch (Node) {
8448 .optional, .null => .none,8538 Metadata.Optional, Metadata.String.Optional => .none,
8449 else => unreachable,8539 else => switch (@typeInfo(Node)) {
8540 .optional, .null => .none,
8541 else => unreachable,
8542 },
8450 },8543 },
8451 .specialized = special,8544 .specialized = special,
8452 } };8545 } };
...@@ -8460,24 +8553,26 @@ pub const Metadata = enum(u32) {...@@ -8460,24 +8553,26 @@ pub const Metadata = enum(u32) {
8460 return .{ .data = .{8553 return .{ .data = .{
8461 .formatter = formatter,8554 .formatter = formatter,
8462 .prefix = prefix,8555 .prefix = prefix,
8463 .node = switch (value.unwrap()) {8556 .node = node: switch (value.unwrap()) {
8464 .instruction, .constant => .{ .local_value = .{8557 .instruction, .constant => .{ .local_value = .{
8465 .value = value,8558 .value = value,
8466 .function = function,8559 .function = function,
8467 } },8560 } },
8468 .metadata => |metadata| if (value == .none) .none else node: {8561 .metadata => |metadata| if (value == .none) .none else {
8469 const unwrapped = metadata.unwrap(formatter.builder);8562 const unwrapped = metadata.unwrap(formatter.builder);
8470 break :node if (@intFromEnum(unwrapped) >= first_local_metadata)8563 break :node switch (unwrapped.kind) {
8471 .{ .local_metadata = .{8564 .string, .node => switch (try formatter.refUnwrapped(unwrapped)) {
8565 .@"inline" => |node| .{ .local_inline = node },
8566 .index => |node| .{ .local_index = node },
8567 else => unreachable,
8568 },
8569 .forward => unreachable,
8570 .local => .{ .local_metadata = .{
8472 .value = function.ptrConst(formatter.builder).debug_values[8571 .value = function.ptrConst(formatter.builder).debug_values[
8473 @intFromEnum(unwrapped) - first_local_metadata8572 unwrapped.index
8474 ].toValue(),8573 ].toValue(),
8475 .function = function,8574 .function = function,
8476 } }8575 } },
8477 else switch (try formatter.refUnwrapped(unwrapped)) {
8478 .@"inline" => |node| .{ .local_inline = node },
8479 .index => |node| .{ .local_index = node },
8480 else => unreachable,
8481 };8576 };
8482 },8577 },
8483 },8578 },
...@@ -8485,16 +8580,12 @@ pub const Metadata = enum(u32) {...@@ -8485,16 +8580,12 @@ pub const Metadata = enum(u32) {
8485 } };8580 } };
8486 }8581 }
8487 fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node {8582 fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node {
8488 assert(node != .none);
8489 assert(@intFromEnum(node) < first_forward_reference);
8490 const builder = formatter.builder;8583 const builder = formatter.builder;
8491 const unwrapped_metadata = node.unwrap(builder);8584 const unwrapped_metadata = node.unwrap(builder);
8492 const tag = formatter.builder.metadata_items.items(.tag)[@intFromEnum(unwrapped_metadata)];8585 switch (unwrapped_metadata.tag(builder)) {
8493 switch (tag) {
8494 .none => unreachable,
8495 .expression, .constant => return .{ .@"inline" = unwrapped_metadata },8586 .expression, .constant => return .{ .@"inline" = unwrapped_metadata },
8496 else => {8587 else => |metadata_tag| {
8497 assert(!tag.isInline());8588 assert(!metadata_tag.isInline());
8498 const gop = try formatter.map.getOrPut(builder.gpa, .{ .metadata = unwrapped_metadata });8589 const gop = try formatter.map.getOrPut(builder.gpa, .{ .metadata = unwrapped_metadata });
8499 return .{ .index = @intCast(gop.index) };8590 return .{ .index = @intCast(gop.index) };
8500 },8591 },
...@@ -8669,11 +8760,9 @@ pub fn init(options: Options) Allocator.Error!Builder {...@@ -8669,11 +8760,9 @@ pub fn init(options: Options) Allocator.Error!Builder {
8669 assert(try self.intConst(.i32, 1) == .@"1");8760 assert(try self.intConst(.i32, 1) == .@"1");
8670 assert(try self.noneConst(.token) == .none);8761 assert(try self.noneConst(.token) == .none);
86718762
8672 assert(try self.metadataNone() == .none);8763 assert(try self.metadataTuple(&.{}) == Metadata.empty_tuple);
8673 assert(try self.metadataTuple(&.{}) == .empty_tuple);
86748764
8675 try self.metadata_string_indices.append(self.gpa, 0);8765 try self.metadata_string_indices.append(self.gpa, 0);
8676 assert(try self.metadataString("") == .none);
86778766
8678 return self;8767 return self;
8679}8768}
...@@ -9232,8 +9321,8 @@ pub fn halfConst(self: *Builder, val: f16) Allocator.Error!Constant {...@@ -9232,8 +9321,8 @@ pub fn halfConst(self: *Builder, val: f16) Allocator.Error!Constant {
9232 return self.halfConstAssumeCapacity(val);9321 return self.halfConstAssumeCapacity(val);
9233}9322}
92349323
9235pub fn halfValue(self: *Builder, ty: Type, value: f16) Allocator.Error!Value {9324pub fn halfValue(self: *Builder, value: f16) Allocator.Error!Value {
9236 return (try self.halfConst(ty, value)).toValue();9325 return (try self.halfConst(value)).toValue();
9237}9326}
92389327
9239pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant {9328pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant {
...@@ -9241,8 +9330,8 @@ pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant {...@@ -9241,8 +9330,8 @@ pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant {
9241 return self.bfloatConstAssumeCapacity(val);9330 return self.bfloatConstAssumeCapacity(val);
9242}9331}
92439332
9244pub fn bfloatValue(self: *Builder, ty: Type, value: f32) Allocator.Error!Value {9333pub fn bfloatValue(self: *Builder, value: f32) Allocator.Error!Value {
9245 return (try self.bfloatConst(ty, value)).toValue();9334 return (try self.bfloatConst(value)).toValue();
9246}9335}
92479336
9248pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant {9337pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant {
...@@ -9250,8 +9339,8 @@ pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant {...@@ -9250,8 +9339,8 @@ pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant {
9250 return self.floatConstAssumeCapacity(val);9339 return self.floatConstAssumeCapacity(val);
9251}9340}
92529341
9253pub fn floatValue(self: *Builder, ty: Type, value: f32) Allocator.Error!Value {9342pub fn floatValue(self: *Builder, value: f32) Allocator.Error!Value {
9254 return (try self.floatConst(ty, value)).toValue();9343 return (try self.floatConst(value)).toValue();
9255}9344}
92569345
9257pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant {9346pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant {
...@@ -9259,8 +9348,8 @@ pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant {...@@ -9259,8 +9348,8 @@ pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant {
9259 return self.doubleConstAssumeCapacity(val);9348 return self.doubleConstAssumeCapacity(val);
9260}9349}
92619350
9262pub fn doubleValue(self: *Builder, ty: Type, value: f64) Allocator.Error!Value {9351pub fn doubleValue(self: *Builder, value: f64) Allocator.Error!Value {
9263 return (try self.doubleConst(ty, value)).toValue();9352 return (try self.doubleConst(value)).toValue();
9264}9353}
92659354
9266pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant {9355pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant {
...@@ -9268,8 +9357,8 @@ pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant {...@@ -9268,8 +9357,8 @@ pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant {
9268 return self.fp128ConstAssumeCapacity(val);9357 return self.fp128ConstAssumeCapacity(val);
9269}9358}
92709359
9271pub fn fp128Value(self: *Builder, ty: Type, value: f128) Allocator.Error!Value {9360pub fn fp128Value(self: *Builder, value: f128) Allocator.Error!Value {
9272 return (try self.fp128Const(ty, value)).toValue();9361 return (try self.fp128Const(value)).toValue();
9273}9362}
92749363
9275pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant {9364pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant {
...@@ -9277,8 +9366,8 @@ pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant {...@@ -9277,8 +9366,8 @@ pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant {
9277 return self.x86_fp80ConstAssumeCapacity(val);9366 return self.x86_fp80ConstAssumeCapacity(val);
9278}9367}
92799368
9280pub fn x86_fp80Value(self: *Builder, ty: Type, value: f80) Allocator.Error!Value {9369pub fn x86_fp80Value(self: *Builder, value: f80) Allocator.Error!Value {
9281 return (try self.x86_fp80Const(ty, value)).toValue();9370 return (try self.x86_fp80Const(value)).toValue();
9282}9371}
92839372
9284pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant {9373pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant {
...@@ -9286,8 +9375,8 @@ pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant {...@@ -9286,8 +9375,8 @@ pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant {
9286 return self.ppc_fp128ConstAssumeCapacity(val);9375 return self.ppc_fp128ConstAssumeCapacity(val);
9287}9376}
92889377
9289pub fn ppc_fp128Value(self: *Builder, ty: Type, value: [2]f64) Allocator.Error!Value {9378pub fn ppc_fp128Value(self: *Builder, value: [2]f64) Allocator.Error!Value {
9290 return (try self.ppc_fp128Const(ty, value)).toValue();9379 return (try self.ppc_fp128Const(value)).toValue();
9291}9380}
92929381
9293pub fn nullConst(self: *Builder, ty: Type) Allocator.Error!Constant {9382pub fn nullConst(self: *Builder, ty: Type) Allocator.Error!Constant {
...@@ -9870,7 +9959,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void...@@ -9870,7 +9959,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
9870 .none => {},9959 .none => {},
9871 .unpredictable => try w.writeAll("!unpredictable !{}"),9960 .unpredictable => try w.writeAll("!unpredictable !{}"),
9872 _ => try w.print("{f}", .{9961 _ => try w.print("{f}", .{
9873 try metadata_formatter.fmt("!prof ", @as(Metadata, @enumFromInt(@intFromEnum(extra.weights))), null),9962 try metadata_formatter.fmt("!prof ", extra.weights.toMetadata(), null),
9874 }),9963 }),
9875 }9964 }
9876 },9965 },
...@@ -10153,7 +10242,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void...@@ -10153,7 +10242,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
10153 .none => {},10242 .none => {},
10154 .unpredictable => try w.writeAll("!unpredictable !{}"),10243 .unpredictable => try w.writeAll("!unpredictable !{}"),
10155 _ => try w.print("{f}", .{10244 _ => try w.print("{f}", .{
10156 try metadata_formatter.fmt("!prof ", @as(Metadata, @enumFromInt(@intFromEnum(extra.data.weights))), null),10245 try metadata_formatter.fmt("!prof ", extra.data.weights.toMetadata(), null),
10157 }),10246 }),
10158 }10247 }
10159 },10248 },
...@@ -10193,7 +10282,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void...@@ -10193,7 +10282,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
10193 const elements: []const Metadata =10282 const elements: []const Metadata =
10194 @ptrCast(self.metadata_extra.items[data.index..][0..data.len]);10283 @ptrCast(self.metadata_extra.items[data.index..][0..data.len]);
10195 try w.writeByte('!');10284 try w.writeByte('!');
10196 try printEscapedString(name.slice(self), .quote_unless_valid_identifier, w);10285 try printEscapedString(name.slice(self).?, .quote_unless_valid_identifier, w);
10197 try w.writeAll(" = !{");10286 try w.writeAll(" = !{");
10198 metadata_formatter.need_comma = false;10287 metadata_formatter.need_comma = false;
10199 defer metadata_formatter.need_comma = undefined;10288 defer metadata_formatter.need_comma = undefined;
...@@ -10223,11 +10312,11 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void...@@ -10223,11 +10312,11 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
10223 }, w);10312 }, w);
10224 continue;10313 continue;
10225 },10314 },
10226 .metadata => |metadata| self.metadata_items.get(@intFromEnum(metadata)),10315 .metadata => |metadata| metadata.item(self),
10227 };10316 };
1022810317
10229 switch (metadata_item.tag) {10318 switch (metadata_item.tag) {
10230 .none, .expression, .constant => unreachable,10319 .expression, .constant => unreachable,
10231 .file => {10320 .file => {
10232 const extra = self.metadataExtraData(Metadata.File, metadata_item.data);10321 const extra = self.metadataExtraData(Metadata.File, metadata_item.data);
10233 try metadata_formatter.specialized(.@"!", .DIFile, .{10322 try metadata_formatter.specialized(.@"!", .DIFile, .{
...@@ -10330,10 +10419,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void...@@ -10330,10 +10419,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
10330 const extra = self.metadataExtraData(Metadata.BasicType, metadata_item.data);10419 const extra = self.metadataExtraData(Metadata.BasicType, metadata_item.data);
10331 try metadata_formatter.specialized(.@"!", .DIBasicType, .{10420 try metadata_formatter.specialized(.@"!", .DIBasicType, .{
10332 .tag = null,10421 .tag = null,
10333 .name = switch (extra.name) {10422 .name = extra.name,
10334 .none => null,
10335 else => extra.name,
10336 },
10337 .size = extra.bitSize(),10423 .size = extra.bitSize(),
10338 .@"align" = null,10424 .@"align" = null,
10339 .encoding = @as(enum {10425 .encoding = @as(enum {
...@@ -10371,10 +10457,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void...@@ -10371,10 +10457,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
10371 .composite_array_type, .composite_vector_type => .DW_TAG_array_type,10457 .composite_array_type, .composite_vector_type => .DW_TAG_array_type,
10372 else => unreachable,10458 else => unreachable,
10373 }),10459 }),
10374 .name = switch (extra.name) {10460 .name = extra.name,
10375 .none => null,
10376 else => extra.name,
10377 },
10378 .scope = extra.scope,10461 .scope = extra.scope,
10379 .file = null,10462 .file = null,
10380 .line = null,10463 .line = null,
...@@ -10409,10 +10492,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void...@@ -10409,10 +10492,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
10409 .derived_member_type => .DW_TAG_member,10492 .derived_member_type => .DW_TAG_member,
10410 else => unreachable,10493 else => unreachable,
10411 }),10494 }),
10412 .name = switch (extra.name) {10495 .name = extra.name,
10413 .none => null,
10414 else => extra.name,
10415 },
10416 .scope = extra.scope,10496 .scope = extra.scope,
10417 .file = null,10497 .file = null,
10418 .line = null,10498 .line = null,
...@@ -10505,25 +10585,6 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void...@@ -10505,25 +10585,6 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
10505 });10585 });
10506 try w.writeAll("}\n");10586 try w.writeAll("}\n");
10507 },10587 },
10508 .str_tuple => {
10509 var extra = self.metadataExtraDataTrail(Metadata.StrTuple, metadata_item.data);
10510 const elements = extra.trail.next(extra.data.elements_len, Metadata, self);
10511 try w.print("!{{{[str]f}", .{
10512 .str = try metadata_formatter.fmt("", extra.data.str, .{ .percent = true }),
10513 });
10514 for (elements) |element| try w.print("{[element]f}", .{
10515 .element = try metadata_formatter.fmt("", element, .{ .percent = true }),
10516 });
10517 try w.writeAll("}\n");
10518 },
10519 .module_flag => {
10520 const extra = self.metadataExtraData(Metadata.ModuleFlag, metadata_item.data);
10521 try w.print("!{{{[behavior]f}{[name]f}{[constant]f}}}\n", .{
10522 .behavior = try metadata_formatter.fmt("", extra.behavior, .{ .percent = true }),
10523 .name = try metadata_formatter.fmt("", extra.name, .{ .percent = true }),
10524 .constant = try metadata_formatter.fmt("", extra.constant, .{ .percent = true }),
10525 });
10526 },
10527 .local_var => {10588 .local_var => {
10528 const extra = self.metadataExtraData(Metadata.LocalVar, metadata_item.data);10589 const extra = self.metadataExtraData(Metadata.LocalVar, metadata_item.data);
10529 try metadata_formatter.specialized(.@"!", .DILocalVariable, .{10590 try metadata_formatter.specialized(.@"!", .DILocalVariable, .{
...@@ -11914,8 +11975,8 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item....@@ -11914,8 +11975,8 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.
11914 const value = @field(extra, field.name);11975 const value = @field(extra, field.name);
11915 self.metadata_extra.appendAssumeCapacity(switch (field.type) {11976 self.metadata_extra.appendAssumeCapacity(switch (field.type) {
11916 u32 => value,11977 u32 => value,
11917 MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value),11978 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @intFromEnum(value),
11918 Metadata.DIFlags => @bitCast(value),11979 Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),
11919 else => @compileError("bad field type: " ++ @typeName(field.type)),11980 else => @compileError("bad field type: " ++ @typeName(field.type)),
11920 });11981 });
11921 }11982 }
...@@ -11953,8 +12014,8 @@ fn metadataExtraDataTrail(...@@ -11953,8 +12014,8 @@ fn metadataExtraDataTrail(
11953 inline for (fields, self.metadata_extra.items[index..][0..fields.len]) |field, value|12014 inline for (fields, self.metadata_extra.items[index..][0..fields.len]) |field, value|
11954 @field(result, field.name) = switch (field.type) {12015 @field(result, field.name) = switch (field.type) {
11955 u32 => value,12016 u32 => value,
11956 MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value),12017 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @enumFromInt(value),
11957 Metadata.DIFlags => @bitCast(value),12018 Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),
11958 else => @compileError("bad field type: " ++ @typeName(field.type)),12019 else => @compileError("bad field type: " ++ @typeName(field.type)),
11959 };12020 };
11960 return .{12021 return .{
...@@ -11967,48 +12028,65 @@ fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Ite...@@ -11967,48 +12028,65 @@ fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Ite
11967 return self.metadataExtraDataTrail(T, index).data;12028 return self.metadataExtraDataTrail(T, index).data;
11968}12029}
1196912030
11970pub fn metadataString(self: *Builder, bytes: []const u8) Allocator.Error!MetadataString {12031pub fn metadataString(self: *Builder, bytes: []const u8) Allocator.Error!Metadata.String {
12032 assert(bytes.len > 0);
11971 try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len);12033 try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len);
11972 try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);12034 try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);
11973 try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);12035 try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);
1197412036
11975 const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(12037 const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(
11976 bytes,12038 bytes,
11977 MetadataString.Adapter{ .builder = self },12039 Metadata.String.Adapter{ .builder = self },
11978 );12040 );
11979 if (!gop.found_existing) {12041 if (!gop.found_existing) {
11980 self.metadata_string_bytes.appendSliceAssumeCapacity(bytes);12042 self.metadata_string_bytes.appendSliceAssumeCapacity(bytes);
11981 self.metadata_string_indices.appendAssumeCapacity(@intCast(self.metadata_string_bytes.items.len));12043 self.metadata_string_indices.appendAssumeCapacity(
12044 @intCast(self.metadata_string_bytes.items.len),
12045 );
11982 }12046 }
11983 return @enumFromInt(gop.index);12047 return @enumFromInt(gop.index);
11984}12048}
1198512049
11986pub fn metadataStringFromStrtabString(self: *Builder, str: StrtabString) Allocator.Error!MetadataString {12050pub fn metadataStringFromStrtabString(
11987 if (str == .none or str == .empty) return MetadataString.none;12051 self: *Builder,
12052 str: StrtabString,
12053) Allocator.Error!Metadata.String {
11988 return try self.metadataString(str.slice(self).?);12054 return try self.metadataString(str.slice(self).?);
11989}12055}
1199012056
11991pub fn metadataStringFmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!MetadataString {12057pub fn metadataStringFmt(
12058 self: *Builder,
12059 comptime fmt_str: []const u8,
12060 fmt_args: anytype,
12061) Allocator.Error!Metadata.String {
11992 try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);12062 try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);
11993 try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, @intCast(std.fmt.count(fmt_str, fmt_args)));12063 try self.metadata_string_bytes.ensureUnusedCapacity(
12064 self.gpa,
12065 @intCast(std.fmt.count(fmt_str, fmt_args)),
12066 );
11994 try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);12067 try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);
11995 return self.metadataStringFmtAssumeCapacity(fmt_str, fmt_args);12068 return self.metadataStringFmtAssumeCapacity(fmt_str, fmt_args);
11996}12069}
1199712070
11998pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) MetadataString {12071pub fn metadataStringFmtAssumeCapacity(
12072 self: *Builder,
12073 comptime fmt_str: []const u8,
12074 fmt_args: anytype,
12075) Metadata.String {
11999 self.metadata_string_bytes.printAssumeCapacity(fmt_str, fmt_args);12076 self.metadata_string_bytes.printAssumeCapacity(fmt_str, fmt_args);
12000 return self.trailingMetadataStringAssumeCapacity();12077 return self.trailingMetadataStringAssumeCapacity();
12001}12078}
1200212079
12003pub fn trailingMetadataString(self: *Builder) Allocator.Error!MetadataString {12080pub fn trailingMetadataString(self: *Builder) Allocator.Error!Metadata.String {
12004 try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);12081 try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);
12005 try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);12082 try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);
12006 return self.trailingMetadataStringAssumeCapacity();12083 return self.trailingMetadataStringAssumeCapacity();
12007}12084}
1200812085
12009pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString {12086pub fn trailingMetadataStringAssumeCapacity(self: *Builder) Metadata.String {
12010 const start = self.metadata_string_indices.getLast();12087 const start = self.metadata_string_indices.getLast();
12011 const bytes: []const u8 = self.metadata_string_bytes.items[start..];12088 const bytes: []const u8 = self.metadata_string_bytes.items[start..];
12089 assert(bytes.len > 0);
12012 const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });12090 const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
12013 if (gop.found_existing) {12091 if (gop.found_existing) {
12014 self.metadata_string_bytes.shrinkRetainingCapacity(start);12092 self.metadata_string_bytes.shrinkRetainingCapacity(start);
...@@ -12018,21 +12096,16 @@ pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString {...@@ -12018,21 +12096,16 @@ pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString {
12018 return @enumFromInt(gop.index);12096 return @enumFromInt(gop.index);
12019}12097}
1202012098
12021pub fn metadataNamed(self: *Builder, name: MetadataString, operands: []const Metadata) Allocator.Error!void {12099pub fn addNamedMetadata(self: *Builder, name: String, operands: []const Metadata) Allocator.Error!void {
12022 try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len);12100 try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len);
12023 try self.metadata_named.ensureUnusedCapacity(self.gpa, 1);12101 try self.metadata_named.ensureUnusedCapacity(self.gpa, 1);
12024 self.metadataNamedAssumeCapacity(name, operands);12102 self.addNamedMetadataAssumeCapacity(name, operands);
12025}
12026
12027fn metadataNone(self: *Builder) Allocator.Error!Metadata {
12028 try self.ensureUnusedMetadataCapacity(1, NoExtra, 0);
12029 return self.metadataNoneAssumeCapacity();
12030}12103}
1203112104
12032pub fn debugFile(12105pub fn debugFile(
12033 self: *Builder,12106 self: *Builder,
12034 filename: MetadataString,12107 filename: ?Metadata.String,
12035 directory: MetadataString,12108 directory: ?Metadata.String,
12036) Allocator.Error!Metadata {12109) Allocator.Error!Metadata {
12037 try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0);12110 try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0);
12038 return self.debugFileAssumeCapacity(filename, directory);12111 return self.debugFileAssumeCapacity(filename, directory);
...@@ -12040,10 +12113,10 @@ pub fn debugFile(...@@ -12040,10 +12113,10 @@ pub fn debugFile(
1204012113
12041pub fn debugCompileUnit(12114pub fn debugCompileUnit(
12042 self: *Builder,12115 self: *Builder,
12043 file: Metadata,12116 file: ?Metadata,
12044 producer: MetadataString,12117 producer: ?Metadata.String,
12045 enums: Metadata,12118 enums: ?Metadata,
12046 globals: Metadata,12119 globals: ?Metadata,
12047 options: Metadata.CompileUnit.Options,12120 options: Metadata.CompileUnit.Options,
12048) Allocator.Error!Metadata {12121) Allocator.Error!Metadata {
12049 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);12122 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);
...@@ -12052,14 +12125,14 @@ pub fn debugCompileUnit(...@@ -12052,14 +12125,14 @@ pub fn debugCompileUnit(
1205212125
12053pub fn debugSubprogram(12126pub fn debugSubprogram(
12054 self: *Builder,12127 self: *Builder,
12055 file: Metadata,12128 file: ?Metadata,
12056 name: MetadataString,12129 name: ?Metadata.String,
12057 linkage_name: MetadataString,12130 linkage_name: ?Metadata.String,
12058 line: u32,12131 line: u32,
12059 scope_line: u32,12132 scope_line: u32,
12060 ty: Metadata,12133 ty: ?Metadata,
12061 options: Metadata.Subprogram.Options,12134 options: Metadata.Subprogram.Options,
12062 compile_unit: Metadata,12135 compile_unit: ?Metadata,
12063) Allocator.Error!Metadata {12136) Allocator.Error!Metadata {
12064 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);12137 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);
12065 return self.debugSubprogramAssumeCapacity(12138 return self.debugSubprogramAssumeCapacity(
...@@ -12074,32 +12147,60 @@ pub fn debugSubprogram(...@@ -12074,32 +12147,60 @@ pub fn debugSubprogram(
12074 );12147 );
12075}12148}
1207612149
12077pub fn debugLexicalBlock(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Allocator.Error!Metadata {12150pub fn debugLexicalBlock(
12151 self: *Builder,
12152 scope: ?Metadata,
12153 file: ?Metadata,
12154 line: u32,
12155 column: u32,
12156) Allocator.Error!Metadata {
12078 try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0);12157 try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0);
12079 return self.debugLexicalBlockAssumeCapacity(scope, file, line, column);12158 return self.debugLexicalBlockAssumeCapacity(scope, file, line, column);
12080}12159}
1208112160
12082pub fn debugLocation(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Allocator.Error!Metadata {12161pub fn debugLocation(
12162 self: *Builder,
12163 line: u32,
12164 column: u32,
12165 scope: Metadata,
12166 inlined_at: ?Metadata,
12167) Allocator.Error!Metadata {
12083 try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0);12168 try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0);
12084 return self.debugLocationAssumeCapacity(line, column, scope, inlined_at);12169 return self.debugLocationAssumeCapacity(line, column, scope, inlined_at);
12085}12170}
1208612171
12087pub fn debugBoolType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata {12172pub fn debugBoolType(
12173 self: *Builder,
12174 name: ?Metadata.String,
12175 size_in_bits: u64,
12176) Allocator.Error!Metadata {
12088 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);12177 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
12089 return self.debugBoolTypeAssumeCapacity(name, size_in_bits);12178 return self.debugBoolTypeAssumeCapacity(name, size_in_bits);
12090}12179}
1209112180
12092pub fn debugUnsignedType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata {12181pub fn debugUnsignedType(
12182 self: *Builder,
12183 name: ?Metadata.String,
12184 size_in_bits: u64,
12185) Allocator.Error!Metadata {
12093 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);12186 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
12094 return self.debugUnsignedTypeAssumeCapacity(name, size_in_bits);12187 return self.debugUnsignedTypeAssumeCapacity(name, size_in_bits);
12095}12188}
1209612189
12097pub fn debugSignedType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata {12190pub fn debugSignedType(
12191 self: *Builder,
12192 name: ?Metadata.String,
12193 size_in_bits: u64,
12194) Allocator.Error!Metadata {
12098 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);12195 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
12099 return self.debugSignedTypeAssumeCapacity(name, size_in_bits);12196 return self.debugSignedTypeAssumeCapacity(name, size_in_bits);
12100}12197}
1210112198
12102pub fn debugFloatType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata {12199pub fn debugFloatType(
12200 self: *Builder,
12201 name: ?Metadata.String,
12202 size_in_bits: u64,
12203) Allocator.Error!Metadata {
12103 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);12204 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
12104 return self.debugFloatTypeAssumeCapacity(name, size_in_bits);12205 return self.debugFloatTypeAssumeCapacity(name, size_in_bits);
12105}12206}
...@@ -12111,14 +12212,14 @@ pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata {...@@ -12111,14 +12212,14 @@ pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata {
1211112212
12112pub fn debugStructType(12213pub fn debugStructType(
12113 self: *Builder,12214 self: *Builder,
12114 name: MetadataString,12215 name: ?Metadata.String,
12115 file: Metadata,12216 file: ?Metadata,
12116 scope: Metadata,12217 scope: ?Metadata,
12117 line: u32,12218 line: u32,
12118 underlying_type: Metadata,12219 underlying_type: ?Metadata,
12119 size_in_bits: u64,12220 size_in_bits: u64,
12120 align_in_bits: u64,12221 align_in_bits: u64,
12121 fields_tuple: Metadata,12222 fields_tuple: ?Metadata,
12122) Allocator.Error!Metadata {12223) Allocator.Error!Metadata {
12123 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);12224 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
12124 return self.debugStructTypeAssumeCapacity(12225 return self.debugStructTypeAssumeCapacity(
...@@ -12135,14 +12236,14 @@ pub fn debugStructType(...@@ -12135,14 +12236,14 @@ pub fn debugStructType(
1213512236
12136pub fn debugUnionType(12237pub fn debugUnionType(
12137 self: *Builder,12238 self: *Builder,
12138 name: MetadataString,12239 name: ?Metadata.String,
12139 file: Metadata,12240 file: ?Metadata,
12140 scope: Metadata,12241 scope: ?Metadata,
12141 line: u32,12242 line: u32,
12142 underlying_type: Metadata,12243 underlying_type: ?Metadata,
12143 size_in_bits: u64,12244 size_in_bits: u64,
12144 align_in_bits: u64,12245 align_in_bits: u64,
12145 fields_tuple: Metadata,12246 fields_tuple: ?Metadata,
12146) Allocator.Error!Metadata {12247) Allocator.Error!Metadata {
12147 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);12248 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
12148 return self.debugUnionTypeAssumeCapacity(12249 return self.debugUnionTypeAssumeCapacity(
...@@ -12159,14 +12260,14 @@ pub fn debugUnionType(...@@ -12159,14 +12260,14 @@ pub fn debugUnionType(
1215912260
12160pub fn debugEnumerationType(12261pub fn debugEnumerationType(
12161 self: *Builder,12262 self: *Builder,
12162 name: MetadataString,12263 name: ?Metadata.String,
12163 file: Metadata,12264 file: ?Metadata,
12164 scope: Metadata,12265 scope: ?Metadata,
12165 line: u32,12266 line: u32,
12166 underlying_type: Metadata,12267 underlying_type: ?Metadata,
12167 size_in_bits: u64,12268 size_in_bits: u64,
12168 align_in_bits: u64,12269 align_in_bits: u64,
12169 fields_tuple: Metadata,12270 fields_tuple: ?Metadata,
12170) Allocator.Error!Metadata {12271) Allocator.Error!Metadata {
12171 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);12272 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
12172 return self.debugEnumerationTypeAssumeCapacity(12273 return self.debugEnumerationTypeAssumeCapacity(
...@@ -12183,14 +12284,14 @@ pub fn debugEnumerationType(...@@ -12183,14 +12284,14 @@ pub fn debugEnumerationType(
1218312284
12184pub fn debugArrayType(12285pub fn debugArrayType(
12185 self: *Builder,12286 self: *Builder,
12186 name: MetadataString,12287 name: ?Metadata.String,
12187 file: Metadata,12288 file: ?Metadata,
12188 scope: Metadata,12289 scope: ?Metadata,
12189 line: u32,12290 line: u32,
12190 underlying_type: Metadata,12291 underlying_type: ?Metadata,
12191 size_in_bits: u64,12292 size_in_bits: u64,
12192 align_in_bits: u64,12293 align_in_bits: u64,
12193 fields_tuple: Metadata,12294 fields_tuple: ?Metadata,
12194) Allocator.Error!Metadata {12295) Allocator.Error!Metadata {
12195 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);12296 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
12196 return self.debugArrayTypeAssumeCapacity(12297 return self.debugArrayTypeAssumeCapacity(
...@@ -12207,14 +12308,14 @@ pub fn debugArrayType(...@@ -12207,14 +12308,14 @@ pub fn debugArrayType(
1220712308
12208pub fn debugVectorType(12309pub fn debugVectorType(
12209 self: *Builder,12310 self: *Builder,
12210 name: MetadataString,12311 name: ?Metadata.String,
12211 file: Metadata,12312 file: ?Metadata,
12212 scope: Metadata,12313 scope: ?Metadata,
12213 line: u32,12314 line: u32,
12214 underlying_type: Metadata,12315 underlying_type: ?Metadata,
12215 size_in_bits: u64,12316 size_in_bits: u64,
12216 align_in_bits: u64,12317 align_in_bits: u64,
12217 fields_tuple: Metadata,12318 fields_tuple: ?Metadata,
12218) Allocator.Error!Metadata {12319) Allocator.Error!Metadata {
12219 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);12320 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
12220 return self.debugVectorTypeAssumeCapacity(12321 return self.debugVectorTypeAssumeCapacity(
...@@ -12231,11 +12332,11 @@ pub fn debugVectorType(...@@ -12231,11 +12332,11 @@ pub fn debugVectorType(
1223112332
12232pub fn debugPointerType(12333pub fn debugPointerType(
12233 self: *Builder,12334 self: *Builder,
12234 name: MetadataString,12335 name: ?Metadata.String,
12235 file: Metadata,12336 file: ?Metadata,
12236 scope: Metadata,12337 scope: ?Metadata,
12237 line: u32,12338 line: u32,
12238 underlying_type: Metadata,12339 underlying_type: ?Metadata,
12239 size_in_bits: u64,12340 size_in_bits: u64,
12240 align_in_bits: u64,12341 align_in_bits: u64,
12241 offset_in_bits: u64,12342 offset_in_bits: u64,
...@@ -12255,11 +12356,11 @@ pub fn debugPointerType(...@@ -12255,11 +12356,11 @@ pub fn debugPointerType(
1225512356
12256pub fn debugMemberType(12357pub fn debugMemberType(
12257 self: *Builder,12358 self: *Builder,
12258 name: MetadataString,12359 name: ?Metadata.String,
12259 file: Metadata,12360 file: ?Metadata,
12260 scope: Metadata,12361 scope: ?Metadata,
12261 line: u32,12362 line: u32,
12262 underlying_type: Metadata,12363 underlying_type: ?Metadata,
12263 size_in_bits: u64,12364 size_in_bits: u64,
12264 align_in_bits: u64,12365 align_in_bits: u64,
12265 offset_in_bits: u64,12366 offset_in_bits: u64,
...@@ -12277,17 +12378,14 @@ pub fn debugMemberType(...@@ -12277,17 +12378,14 @@ pub fn debugMemberType(
12277 );12378 );
12278}12379}
1227912380
12280pub fn debugSubroutineType(12381pub fn debugSubroutineType(self: *Builder, types_tuple: ?Metadata) Allocator.Error!Metadata {
12281 self: *Builder,
12282 types_tuple: Metadata,
12283) Allocator.Error!Metadata {
12284 try self.ensureUnusedMetadataCapacity(1, Metadata.SubroutineType, 0);12382 try self.ensureUnusedMetadataCapacity(1, Metadata.SubroutineType, 0);
12285 return self.debugSubroutineTypeAssumeCapacity(types_tuple);12383 return self.debugSubroutineTypeAssumeCapacity(types_tuple);
12286}12384}
1228712385
12288pub fn debugEnumerator(12386pub fn debugEnumerator(
12289 self: *Builder,12387 self: *Builder,
12290 name: MetadataString,12388 name: ?Metadata.String,
12291 unsigned: bool,12389 unsigned: bool,
12292 bit_width: u32,12390 bit_width: u32,
12293 value: std.math.big.int.Const,12391 value: std.math.big.int.Const,
...@@ -12300,55 +12398,37 @@ pub fn debugEnumerator(...@@ -12300,55 +12398,37 @@ pub fn debugEnumerator(
1230012398
12301pub fn debugSubrange(12399pub fn debugSubrange(
12302 self: *Builder,12400 self: *Builder,
12303 lower_bound: Metadata,12401 lower_bound: ?Metadata,
12304 count: Metadata,12402 count: ?Metadata,
12305) Allocator.Error!Metadata {12403) Allocator.Error!Metadata {
12306 try self.ensureUnusedMetadataCapacity(1, Metadata.Subrange, 0);12404 try self.ensureUnusedMetadataCapacity(1, Metadata.Subrange, 0);
12307 return self.debugSubrangeAssumeCapacity(lower_bound, count);12405 return self.debugSubrangeAssumeCapacity(lower_bound, count);
12308}12406}
1230912407
12310pub fn debugExpression(12408pub fn debugExpression(self: *Builder, elements: []const u32) Allocator.Error!Metadata {
12311 self: *Builder,
12312 elements: []const u32,
12313) Allocator.Error!Metadata {
12314 try self.ensureUnusedMetadataCapacity(1, Metadata.Expression, elements.len);12409 try self.ensureUnusedMetadataCapacity(1, Metadata.Expression, elements.len);
12315 return self.debugExpressionAssumeCapacity(elements);12410 return self.debugExpressionAssumeCapacity(elements);
12316}12411}
1231712412
12318pub fn metadataTuple(12413pub fn metadataTuple(self: *Builder, elements: []const Metadata) Allocator.Error!Metadata {
12319 self: *Builder,12414 return self.metadataTupleOptionals(@ptrCast(elements));
12320 elements: []const Metadata,
12321) Allocator.Error!Metadata {
12322 try self.ensureUnusedMetadataCapacity(1, Metadata.Tuple, elements.len);
12323 return self.metadataTupleAssumeCapacity(elements);
12324}
12325
12326pub fn strTuple(
12327 self: *Builder,
12328 str: MetadataString,
12329 elements: []const Metadata,
12330) Allocator.Error!Metadata {
12331 try self.ensureUnusedMetadataCapacity(1, Metadata.StrTuple, elements.len);
12332 return self.strTupleAssumeCapacity(str, elements);
12333}12415}
1233412416
12335pub fn metadataModuleFlag(12417pub fn metadataTupleOptionals(
12336 self: *Builder,12418 self: *Builder,
12337 behavior: Metadata,12419 elements: []const Metadata.Optional,
12338 name: MetadataString,
12339 constant: Metadata,
12340) Allocator.Error!Metadata {12420) Allocator.Error!Metadata {
12341 try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0);12421 try self.ensureUnusedMetadataCapacity(1, Metadata.Tuple, elements.len);
12342 return self.metadataModuleFlagAssumeCapacity(behavior, name, constant);12422 return self.metadataTupleOptionalsAssumeCapacity(elements);
12343}12423}
1234412424
12345pub fn debugLocalVar(12425pub fn debugLocalVar(
12346 self: *Builder,12426 self: *Builder,
12347 name: MetadataString,12427 name: ?Metadata.String,
12348 file: Metadata,12428 file: ?Metadata,
12349 scope: Metadata,12429 scope: ?Metadata,
12350 line: u32,12430 line: u32,
12351 ty: Metadata,12431 ty: ?Metadata,
12352) Allocator.Error!Metadata {12432) Allocator.Error!Metadata {
12353 try self.ensureUnusedMetadataCapacity(1, Metadata.LocalVar, 0);12433 try self.ensureUnusedMetadataCapacity(1, Metadata.LocalVar, 0);
12354 return self.debugLocalVarAssumeCapacity(name, file, scope, line, ty);12434 return self.debugLocalVarAssumeCapacity(name, file, scope, line, ty);
...@@ -12356,11 +12436,11 @@ pub fn debugLocalVar(...@@ -12356,11 +12436,11 @@ pub fn debugLocalVar(
1235612436
12357pub fn debugParameter(12437pub fn debugParameter(
12358 self: *Builder,12438 self: *Builder,
12359 name: MetadataString,12439 name: ?Metadata.String,
12360 file: Metadata,12440 file: ?Metadata,
12361 scope: Metadata,12441 scope: ?Metadata,
12362 line: u32,12442 line: u32,
12363 ty: Metadata,12443 ty: ?Metadata,
12364 arg_no: u32,12444 arg_no: u32,
12365) Allocator.Error!Metadata {12445) Allocator.Error!Metadata {
12366 try self.ensureUnusedMetadataCapacity(1, Metadata.Parameter, 0);12446 try self.ensureUnusedMetadataCapacity(1, Metadata.Parameter, 0);
...@@ -12369,12 +12449,12 @@ pub fn debugParameter(...@@ -12369,12 +12449,12 @@ pub fn debugParameter(
1236912449
12370pub fn debugGlobalVar(12450pub fn debugGlobalVar(
12371 self: *Builder,12451 self: *Builder,
12372 name: MetadataString,12452 name: ?Metadata.String,
12373 linkage_name: MetadataString,12453 linkage_name: ?Metadata.String,
12374 file: Metadata,12454 file: ?Metadata,
12375 scope: Metadata,12455 scope: ?Metadata,
12376 line: u32,12456 line: u32,
12377 ty: Metadata,12457 ty: ?Metadata,
12378 variable: Variable.Index,12458 variable: Variable.Index,
12379 options: Metadata.GlobalVar.Options,12459 options: Metadata.GlobalVar.Options,
12380) Allocator.Error!Metadata {12460) Allocator.Error!Metadata {
...@@ -12393,8 +12473,8 @@ pub fn debugGlobalVar(...@@ -12393,8 +12473,8 @@ pub fn debugGlobalVar(
1239312473
12394pub fn debugGlobalVarExpression(12474pub fn debugGlobalVarExpression(
12395 self: *Builder,12475 self: *Builder,
12396 variable: Metadata,12476 variable: ?Metadata,
12397 expression: Metadata,12477 expression: ?Metadata,
12398) Allocator.Error!Metadata {12478) Allocator.Error!Metadata {
12399 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVarExpression, 0);12479 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVarExpression, 0);
12400 return self.debugGlobalVarExpressionAssumeCapacity(variable, expression);12480 return self.debugGlobalVarExpressionAssumeCapacity(variable, expression);
...@@ -12405,13 +12485,11 @@ pub fn metadataConstant(self: *Builder, value: Constant) Allocator.Error!Metadat...@@ -12405,13 +12485,11 @@ pub fn metadataConstant(self: *Builder, value: Constant) Allocator.Error!Metadat
12405 return self.metadataConstantAssumeCapacity(value);12485 return self.metadataConstantAssumeCapacity(value);
12406}12486}
1240712487
12408pub fn debugForwardReferenceSetType(self: *Builder, fwd_ref: Metadata, ty: Metadata) void {12488pub fn resolveDebugForwardReference(self: *Builder, fwd_ref: Metadata, value: Metadata) void {
12409 assert(12489 assert(fwd_ref.kind == .forward);
12410 @intFromEnum(fwd_ref) >= Metadata.first_forward_reference and12490 const resolved = &self.metadata_forward_references.items[fwd_ref.index];
12411 @intFromEnum(fwd_ref) <= Metadata.first_local_metadata,12491 assert(resolved.is_none);
12412 );12492 resolved.* = value.toOptional();
12413 const index = @intFromEnum(fwd_ref) - Metadata.first_forward_reference;
12414 self.metadata_forward_references.items[index] = ty;
12415}12493}
1241612494
12417fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata {12495fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata {
...@@ -12450,41 +12528,20 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp...@@ -12450,41 +12528,20 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp
12450 .data = self.addMetadataExtraAssumeCapacity(value),12528 .data = self.addMetadataExtraAssumeCapacity(value),
12451 });12529 });
12452 }12530 }
12453 return @enumFromInt(gop.index);12531 return .{ .index = @intCast(gop.index), .kind = .node };
12454}12532}
1245512533
12456fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata {12534fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata {
12457 const Key = struct { tag: Metadata.Tag, index: Metadata };12535 const index = self.metadata_items.len;
12458 const Adapter = struct {12536 _ = self.metadata_map.entries.addOneAssumeCapacity();
12459 pub fn hash(_: @This(), key: Key) u32 {12537 self.metadata_items.appendAssumeCapacity(.{
12460 return @truncate(std.hash.Wyhash.hash(12538 .tag = tag,
12461 std.hash.int(@intFromEnum(key.tag)),12539 .data = self.addMetadataExtraAssumeCapacity(value),
12462 std.mem.asBytes(&key.index),12540 });
12463 ));12541 return .{ .index = @intCast(index), .kind = .node };
12464 }
12465
12466 pub fn eql(_: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
12467 return @intFromEnum(lhs_key.index) == rhs_index;
12468 }
12469 };
12470
12471 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
12472 Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) },
12473 Adapter{},
12474 );
12475
12476 if (!gop.found_existing) {
12477 gop.key_ptr.* = {};
12478 gop.value_ptr.* = {};
12479 self.metadata_items.appendAssumeCapacity(.{
12480 .tag = tag,
12481 .data = self.addMetadataExtraAssumeCapacity(value),
12482 });
12483 }
12484 return @enumFromInt(gop.index);
12485}12542}
1248612543
12487fn metadataNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void {12544fn addNamedMetadataAssumeCapacity(self: *Builder, name: String, operands: []const Metadata) void {
12488 assert(name != .none);12545 assert(name != .none);
12489 const extra_index: u32 = @intCast(self.metadata_extra.items.len);12546 const extra_index: u32 = @intCast(self.metadata_extra.items.len);
12490 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands));12547 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands));
...@@ -12496,119 +12553,127 @@ fn metadataNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: [...@@ -12496,119 +12553,127 @@ fn metadataNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: [
12496 };12553 };
12497}12554}
1249812555
12499pub fn metadataNoneAssumeCapacity(self: *Builder) Metadata {
12500 return self.metadataSimpleAssumeCapacity(.none, .{});
12501}
12502
12503fn debugFileAssumeCapacity(12556fn debugFileAssumeCapacity(
12504 self: *Builder,12557 self: *Builder,
12505 filename: MetadataString,12558 filename: ?Metadata.String,
12506 directory: MetadataString,12559 directory: ?Metadata.String,
12507) Metadata {12560) Metadata {
12508 assert(!self.strip);12561 assert(!self.strip);
12509 return self.metadataSimpleAssumeCapacity(.file, Metadata.File{12562 return self.metadataSimpleAssumeCapacity(.file, Metadata.File{
12510 .filename = filename,12563 .filename = .wrap(filename),
12511 .directory = directory,12564 .directory = .wrap(directory),
12512 });12565 });
12513}12566}
1251412567
12515pub fn debugCompileUnitAssumeCapacity(12568pub fn debugCompileUnitAssumeCapacity(
12516 self: *Builder,12569 self: *Builder,
12517 file: Metadata,12570 file: ?Metadata,
12518 producer: MetadataString,12571 producer: ?Metadata.String,
12519 enums: Metadata,12572 enums: ?Metadata,
12520 globals: Metadata,12573 globals: ?Metadata,
12521 options: Metadata.CompileUnit.Options,12574 options: Metadata.CompileUnit.Options,
12522) Metadata {12575) Metadata {
12523 assert(!self.strip);12576 assert(!self.strip);
12524 return self.metadataDistinctAssumeCapacity(12577 return self.metadataDistinctAssumeCapacity(
12525 if (options.optimized) .@"compile_unit optimized" else .compile_unit,12578 if (options.optimized) .@"compile_unit optimized" else .compile_unit,
12526 Metadata.CompileUnit{12579 Metadata.CompileUnit{
12527 .file = file,12580 .file = .wrap(file),
12528 .producer = producer,12581 .producer = .wrap(producer),
12529 .enums = enums,12582 .enums = .wrap(enums),
12530 .globals = globals,12583 .globals = .wrap(globals),
12531 },12584 },
12532 );12585 );
12533}12586}
1253412587
12535fn debugSubprogramAssumeCapacity(12588fn debugSubprogramAssumeCapacity(
12536 self: *Builder,12589 self: *Builder,
12537 file: Metadata,12590 file: ?Metadata,
12538 name: MetadataString,12591 name: ?Metadata.String,
12539 linkage_name: MetadataString,12592 linkage_name: ?Metadata.String,
12540 line: u32,12593 line: u32,
12541 scope_line: u32,12594 scope_line: u32,
12542 ty: Metadata,12595 ty: ?Metadata,
12543 options: Metadata.Subprogram.Options,12596 options: Metadata.Subprogram.Options,
12544 compile_unit: Metadata,12597 compile_unit: ?Metadata,
12545) Metadata {12598) Metadata {
12546 assert(!self.strip);12599 assert(!self.strip);
12547 const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) +12600 const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) +
12548 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));12601 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
12549 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{12602 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
12550 .file = file,12603 .file = .wrap(file),
12551 .name = name,12604 .name = .wrap(name),
12552 .linkage_name = linkage_name,12605 .linkage_name = .wrap(linkage_name),
12553 .line = line,12606 .line = line,
12554 .scope_line = scope_line,12607 .scope_line = scope_line,
12555 .ty = ty,12608 .ty = .wrap(ty),
12556 .di_flags = options.di_flags,12609 .di_flags = options.di_flags,
12557 .compile_unit = compile_unit,12610 .compile_unit = .wrap(compile_unit),
12558 });12611 });
12559}12612}
1256012613
12561fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Metadata {12614fn debugLexicalBlockAssumeCapacity(
12615 self: *Builder,
12616 scope: ?Metadata,
12617 file: ?Metadata,
12618 line: u32,
12619 column: u32,
12620) Metadata {
12562 assert(!self.strip);12621 assert(!self.strip);
12563 return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{12622 return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{
12564 .scope = scope,12623 .scope = .wrap(scope),
12565 .file = file,12624 .file = .wrap(file),
12566 .line = line,12625 .line = line,
12567 .column = column,12626 .column = column,
12568 });12627 });
12569}12628}
1257012629
12571fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Metadata {12630fn debugLocationAssumeCapacity(
12631 self: *Builder,
12632 line: u32,
12633 column: u32,
12634 scope: Metadata,
12635 inlined_at: ?Metadata,
12636) Metadata {
12572 assert(!self.strip);12637 assert(!self.strip);
12573 return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{12638 return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{
12574 .line = line,12639 .line = line,
12575 .column = column,12640 .column = column,
12576 .scope = scope,12641 .scope = scope,
12577 .inlined_at = inlined_at,12642 .inlined_at = .wrap(inlined_at),
12578 });12643 });
12579}12644}
1258012645
12581fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12646fn debugBoolTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
12582 assert(!self.strip);12647 assert(!self.strip);
12583 return self.metadataSimpleAssumeCapacity(.basic_bool_type, Metadata.BasicType{12648 return self.metadataSimpleAssumeCapacity(.basic_bool_type, Metadata.BasicType{
12584 .name = name,12649 .name = .wrap(name),
12585 .size_in_bits_lo = @truncate(size_in_bits),12650 .size_in_bits_lo = @truncate(size_in_bits),
12586 .size_in_bits_hi = @truncate(size_in_bits >> 32),12651 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12587 });12652 });
12588}12653}
1258912654
12590fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12655fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
12591 assert(!self.strip);12656 assert(!self.strip);
12592 return self.metadataSimpleAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{12657 return self.metadataSimpleAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{
12593 .name = name,12658 .name = .wrap(name),
12594 .size_in_bits_lo = @truncate(size_in_bits),12659 .size_in_bits_lo = @truncate(size_in_bits),
12595 .size_in_bits_hi = @truncate(size_in_bits >> 32),12660 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12596 });12661 });
12597}12662}
1259812663
12599fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12664fn debugSignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
12600 assert(!self.strip);12665 assert(!self.strip);
12601 return self.metadataSimpleAssumeCapacity(.basic_signed_type, Metadata.BasicType{12666 return self.metadataSimpleAssumeCapacity(.basic_signed_type, Metadata.BasicType{
12602 .name = name,12667 .name = .wrap(name),
12603 .size_in_bits_lo = @truncate(size_in_bits),12668 .size_in_bits_lo = @truncate(size_in_bits),
12604 .size_in_bits_hi = @truncate(size_in_bits >> 32),12669 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12605 });12670 });
12606}12671}
1260712672
12608fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12673fn debugFloatTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
12609 assert(!self.strip);12674 assert(!self.strip);
12610 return self.metadataSimpleAssumeCapacity(.basic_float_type, Metadata.BasicType{12675 return self.metadataSimpleAssumeCapacity(.basic_float_type, Metadata.BasicType{
12611 .name = name,12676 .name = .wrap(name),
12612 .size_in_bits_lo = @truncate(size_in_bits),12677 .size_in_bits_lo = @truncate(size_in_bits),
12613 .size_in_bits_hi = @truncate(size_in_bits >> 32),12678 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12614 });12679 });
...@@ -12616,21 +12681,21 @@ fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bi...@@ -12616,21 +12681,21 @@ fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bi
1261612681
12617fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata {12682fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata {
12618 assert(!self.strip);12683 assert(!self.strip);
12619 const index = Metadata.first_forward_reference + self.metadata_forward_references.items.len;12684 const index = self.metadata_forward_references.items.len;
12620 self.metadata_forward_references.appendAssumeCapacity(.none);12685 self.metadata_forward_references.appendAssumeCapacity(.none);
12621 return @enumFromInt(index);12686 return .{ .index = @intCast(index), .kind = .forward };
12622}12687}
1262312688
12624fn debugStructTypeAssumeCapacity(12689fn debugStructTypeAssumeCapacity(
12625 self: *Builder,12690 self: *Builder,
12626 name: MetadataString,12691 name: ?Metadata.String,
12627 file: Metadata,12692 file: ?Metadata,
12628 scope: Metadata,12693 scope: ?Metadata,
12629 line: u32,12694 line: u32,
12630 underlying_type: Metadata,12695 underlying_type: ?Metadata,
12631 size_in_bits: u64,12696 size_in_bits: u64,
12632 align_in_bits: u64,12697 align_in_bits: u64,
12633 fields_tuple: Metadata,12698 fields_tuple: ?Metadata,
12634) Metadata {12699) Metadata {
12635 assert(!self.strip);12700 assert(!self.strip);
12636 return self.debugCompositeTypeAssumeCapacity(12701 return self.debugCompositeTypeAssumeCapacity(
...@@ -12648,14 +12713,14 @@ fn debugStructTypeAssumeCapacity(...@@ -12648,14 +12713,14 @@ fn debugStructTypeAssumeCapacity(
1264812713
12649fn debugUnionTypeAssumeCapacity(12714fn debugUnionTypeAssumeCapacity(
12650 self: *Builder,12715 self: *Builder,
12651 name: MetadataString,12716 name: ?Metadata.String,
12652 file: Metadata,12717 file: ?Metadata,
12653 scope: Metadata,12718 scope: ?Metadata,
12654 line: u32,12719 line: u32,
12655 underlying_type: Metadata,12720 underlying_type: ?Metadata,
12656 size_in_bits: u64,12721 size_in_bits: u64,
12657 align_in_bits: u64,12722 align_in_bits: u64,
12658 fields_tuple: Metadata,12723 fields_tuple: ?Metadata,
12659) Metadata {12724) Metadata {
12660 assert(!self.strip);12725 assert(!self.strip);
12661 return self.debugCompositeTypeAssumeCapacity(12726 return self.debugCompositeTypeAssumeCapacity(
...@@ -12673,14 +12738,14 @@ fn debugUnionTypeAssumeCapacity(...@@ -12673,14 +12738,14 @@ fn debugUnionTypeAssumeCapacity(
1267312738
12674fn debugEnumerationTypeAssumeCapacity(12739fn debugEnumerationTypeAssumeCapacity(
12675 self: *Builder,12740 self: *Builder,
12676 name: MetadataString,12741 name: ?Metadata.String,
12677 file: Metadata,12742 file: ?Metadata,
12678 scope: Metadata,12743 scope: ?Metadata,
12679 line: u32,12744 line: u32,
12680 underlying_type: Metadata,12745 underlying_type: ?Metadata,
12681 size_in_bits: u64,12746 size_in_bits: u64,
12682 align_in_bits: u64,12747 align_in_bits: u64,
12683 fields_tuple: Metadata,12748 fields_tuple: ?Metadata,
12684) Metadata {12749) Metadata {
12685 assert(!self.strip);12750 assert(!self.strip);
12686 return self.debugCompositeTypeAssumeCapacity(12751 return self.debugCompositeTypeAssumeCapacity(
...@@ -12698,14 +12763,14 @@ fn debugEnumerationTypeAssumeCapacity(...@@ -12698,14 +12763,14 @@ fn debugEnumerationTypeAssumeCapacity(
1269812763
12699fn debugArrayTypeAssumeCapacity(12764fn debugArrayTypeAssumeCapacity(
12700 self: *Builder,12765 self: *Builder,
12701 name: MetadataString,12766 name: ?Metadata.String,
12702 file: Metadata,12767 file: ?Metadata,
12703 scope: Metadata,12768 scope: ?Metadata,
12704 line: u32,12769 line: u32,
12705 underlying_type: Metadata,12770 underlying_type: ?Metadata,
12706 size_in_bits: u64,12771 size_in_bits: u64,
12707 align_in_bits: u64,12772 align_in_bits: u64,
12708 fields_tuple: Metadata,12773 fields_tuple: ?Metadata,
12709) Metadata {12774) Metadata {
12710 assert(!self.strip);12775 assert(!self.strip);
12711 return self.debugCompositeTypeAssumeCapacity(12776 return self.debugCompositeTypeAssumeCapacity(
...@@ -12723,14 +12788,14 @@ fn debugArrayTypeAssumeCapacity(...@@ -12723,14 +12788,14 @@ fn debugArrayTypeAssumeCapacity(
1272312788
12724fn debugVectorTypeAssumeCapacity(12789fn debugVectorTypeAssumeCapacity(
12725 self: *Builder,12790 self: *Builder,
12726 name: MetadataString,12791 name: ?Metadata.String,
12727 file: Metadata,12792 file: ?Metadata,
12728 scope: Metadata,12793 scope: ?Metadata,
12729 line: u32,12794 line: u32,
12730 underlying_type: Metadata,12795 underlying_type: ?Metadata,
12731 size_in_bits: u64,12796 size_in_bits: u64,
12732 align_in_bits: u64,12797 align_in_bits: u64,
12733 fields_tuple: Metadata,12798 fields_tuple: ?Metadata,
12734) Metadata {12799) Metadata {
12735 assert(!self.strip);12800 assert(!self.strip);
12736 return self.debugCompositeTypeAssumeCapacity(12801 return self.debugCompositeTypeAssumeCapacity(
...@@ -12749,48 +12814,48 @@ fn debugVectorTypeAssumeCapacity(...@@ -12749,48 +12814,48 @@ fn debugVectorTypeAssumeCapacity(
12749fn debugCompositeTypeAssumeCapacity(12814fn debugCompositeTypeAssumeCapacity(
12750 self: *Builder,12815 self: *Builder,
12751 tag: Metadata.Tag,12816 tag: Metadata.Tag,
12752 name: MetadataString,12817 name: ?Metadata.String,
12753 file: Metadata,12818 file: ?Metadata,
12754 scope: Metadata,12819 scope: ?Metadata,
12755 line: u32,12820 line: u32,
12756 underlying_type: Metadata,12821 underlying_type: ?Metadata,
12757 size_in_bits: u64,12822 size_in_bits: u64,
12758 align_in_bits: u64,12823 align_in_bits: u64,
12759 fields_tuple: Metadata,12824 fields_tuple: ?Metadata,
12760) Metadata {12825) Metadata {
12761 assert(!self.strip);12826 assert(!self.strip);
12762 return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{12827 return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{
12763 .name = name,12828 .name = .wrap(name),
12764 .file = file,12829 .file = .wrap(file),
12765 .scope = scope,12830 .scope = .wrap(scope),
12766 .line = line,12831 .line = line,
12767 .underlying_type = underlying_type,12832 .underlying_type = .wrap(underlying_type),
12768 .size_in_bits_lo = @truncate(size_in_bits),12833 .size_in_bits_lo = @truncate(size_in_bits),
12769 .size_in_bits_hi = @truncate(size_in_bits >> 32),12834 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12770 .align_in_bits_lo = @truncate(align_in_bits),12835 .align_in_bits_lo = @truncate(align_in_bits),
12771 .align_in_bits_hi = @truncate(align_in_bits >> 32),12836 .align_in_bits_hi = @truncate(align_in_bits >> 32),
12772 .fields_tuple = fields_tuple,12837 .fields_tuple = .wrap(fields_tuple),
12773 });12838 });
12774}12839}
1277512840
12776fn debugPointerTypeAssumeCapacity(12841fn debugPointerTypeAssumeCapacity(
12777 self: *Builder,12842 self: *Builder,
12778 name: MetadataString,12843 name: ?Metadata.String,
12779 file: Metadata,12844 file: ?Metadata,
12780 scope: Metadata,12845 scope: ?Metadata,
12781 line: u32,12846 line: u32,
12782 underlying_type: Metadata,12847 underlying_type: ?Metadata,
12783 size_in_bits: u64,12848 size_in_bits: u64,
12784 align_in_bits: u64,12849 align_in_bits: u64,
12785 offset_in_bits: u64,12850 offset_in_bits: u64,
12786) Metadata {12851) Metadata {
12787 assert(!self.strip);12852 assert(!self.strip);
12788 return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{12853 return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{
12789 .name = name,12854 .name = .wrap(name),
12790 .file = file,12855 .file = .wrap(file),
12791 .scope = scope,12856 .scope = .wrap(scope),
12792 .line = line,12857 .line = line,
12793 .underlying_type = underlying_type,12858 .underlying_type = .wrap(underlying_type),
12794 .size_in_bits_lo = @truncate(size_in_bits),12859 .size_in_bits_lo = @truncate(size_in_bits),
12795 .size_in_bits_hi = @truncate(size_in_bits >> 32),12860 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12796 .align_in_bits_lo = @truncate(align_in_bits),12861 .align_in_bits_lo = @truncate(align_in_bits),
...@@ -12802,22 +12867,22 @@ fn debugPointerTypeAssumeCapacity(...@@ -12802,22 +12867,22 @@ fn debugPointerTypeAssumeCapacity(
1280212867
12803fn debugMemberTypeAssumeCapacity(12868fn debugMemberTypeAssumeCapacity(
12804 self: *Builder,12869 self: *Builder,
12805 name: MetadataString,12870 name: ?Metadata.String,
12806 file: Metadata,12871 file: ?Metadata,
12807 scope: Metadata,12872 scope: ?Metadata,
12808 line: u32,12873 line: u32,
12809 underlying_type: Metadata,12874 underlying_type: ?Metadata,
12810 size_in_bits: u64,12875 size_in_bits: u64,
12811 align_in_bits: u64,12876 align_in_bits: u64,
12812 offset_in_bits: u64,12877 offset_in_bits: u64,
12813) Metadata {12878) Metadata {
12814 assert(!self.strip);12879 assert(!self.strip);
12815 return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{12880 return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{
12816 .name = name,12881 .name = .wrap(name),
12817 .file = file,12882 .file = .wrap(file),
12818 .scope = scope,12883 .scope = .wrap(scope),
12819 .line = line,12884 .line = line,
12820 .underlying_type = underlying_type,12885 .underlying_type = .wrap(underlying_type),
12821 .size_in_bits_lo = @truncate(size_in_bits),12886 .size_in_bits_lo = @truncate(size_in_bits),
12822 .size_in_bits_hi = @truncate(size_in_bits >> 32),12887 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12823 .align_in_bits_lo = @truncate(align_in_bits),12888 .align_in_bits_lo = @truncate(align_in_bits),
...@@ -12827,19 +12892,16 @@ fn debugMemberTypeAssumeCapacity(...@@ -12827,19 +12892,16 @@ fn debugMemberTypeAssumeCapacity(
12827 });12892 });
12828}12893}
1282912894
12830fn debugSubroutineTypeAssumeCapacity(12895fn debugSubroutineTypeAssumeCapacity(self: *Builder, types_tuple: ?Metadata) Metadata {
12831 self: *Builder,
12832 types_tuple: Metadata,
12833) Metadata {
12834 assert(!self.strip);12896 assert(!self.strip);
12835 return self.metadataSimpleAssumeCapacity(.subroutine_type, Metadata.SubroutineType{12897 return self.metadataSimpleAssumeCapacity(.subroutine_type, Metadata.SubroutineType{
12836 .types_tuple = types_tuple,12898 .types_tuple = .wrap(types_tuple),
12837 });12899 });
12838}12900}
1283912901
12840fn debugEnumeratorAssumeCapacity(12902fn debugEnumeratorAssumeCapacity(
12841 self: *Builder,12903 self: *Builder,
12842 name: MetadataString,12904 name: ?Metadata.String,
12843 unsigned: bool,12905 unsigned: bool,
12844 bit_width: u32,12906 bit_width: u32,
12845 value: std.math.big.int.Const,12907 value: std.math.big.int.Const,
...@@ -12847,7 +12909,7 @@ fn debugEnumeratorAssumeCapacity(...@@ -12847,7 +12909,7 @@ fn debugEnumeratorAssumeCapacity(
12847 assert(!self.strip);12909 assert(!self.strip);
12848 const Key = struct {12910 const Key = struct {
12849 tag: Metadata.Tag,12911 tag: Metadata.Tag,
12850 name: MetadataString,12912 name: Metadata.String.Optional,
12851 bit_width: u32,12913 bit_width: u32,
12852 value: std.math.big.int.Const,12914 value: std.math.big.int.Const,
12853 };12915 };
...@@ -12886,15 +12948,12 @@ fn debugEnumeratorAssumeCapacity(...@@ -12886,15 +12948,12 @@ fn debugEnumeratorAssumeCapacity(
1288612948
12887 assert(!(tag == .enumerator_unsigned and !value.positive));12949 assert(!(tag == .enumerator_unsigned and !value.positive));
1288812950
12889 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(12951 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(Key{
12890 Key{12952 .tag = tag,
12891 .tag = tag,12953 .name = .wrap(name),
12892 .name = name,12954 .bit_width = bit_width,
12893 .bit_width = bit_width,12955 .value = value,
12894 .value = value,12956 }, Adapter{ .builder = self });
12895 },
12896 Adapter{ .builder = self },
12897 );
1289812957
12899 if (!gop.found_existing) {12958 if (!gop.found_existing) {
12900 gop.key_ptr.* = {};12959 gop.key_ptr.* = {};
...@@ -12902,7 +12961,7 @@ fn debugEnumeratorAssumeCapacity(...@@ -12902,7 +12961,7 @@ fn debugEnumeratorAssumeCapacity(
12902 self.metadata_items.appendAssumeCapacity(.{12961 self.metadata_items.appendAssumeCapacity(.{
12903 .tag = tag,12962 .tag = tag,
12904 .data = self.addMetadataExtraAssumeCapacity(Metadata.Enumerator{12963 .data = self.addMetadataExtraAssumeCapacity(Metadata.Enumerator{
12905 .name = name,12964 .name = .wrap(name),
12906 .bit_width = bit_width,12965 .bit_width = bit_width,
12907 .limbs_index = @intCast(self.metadata_limbs.items.len),12966 .limbs_index = @intCast(self.metadata_limbs.items.len),
12908 .limbs_len = @intCast(value.limbs.len),12967 .limbs_len = @intCast(value.limbs.len),
...@@ -12910,25 +12969,18 @@ fn debugEnumeratorAssumeCapacity(...@@ -12910,25 +12969,18 @@ fn debugEnumeratorAssumeCapacity(
12910 });12969 });
12911 self.metadata_limbs.appendSliceAssumeCapacity(value.limbs);12970 self.metadata_limbs.appendSliceAssumeCapacity(value.limbs);
12912 }12971 }
12913 return @enumFromInt(gop.index);12972 return .{ .index = @intCast(gop.index), .kind = .node };
12914}12973}
1291512974
12916fn debugSubrangeAssumeCapacity(12975fn debugSubrangeAssumeCapacity(self: *Builder, lower_bound: ?Metadata, count: ?Metadata) Metadata {
12917 self: *Builder,
12918 lower_bound: Metadata,
12919 count: Metadata,
12920) Metadata {
12921 assert(!self.strip);12976 assert(!self.strip);
12922 return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{12977 return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{
12923 .lower_bound = lower_bound,12978 .lower_bound = .wrap(lower_bound),
12924 .count = count,12979 .count = .wrap(count),
12925 });12980 });
12926}12981}
1292712982
12928fn debugExpressionAssumeCapacity(12983fn debugExpressionAssumeCapacity(self: *Builder, elements: []const u32) Metadata {
12929 self: *Builder,
12930 elements: []const u32,
12931) Metadata {
12932 assert(!self.strip);12984 assert(!self.strip);
12933 const Key = struct {12985 const Key = struct {
12934 elements: []const u32,12986 elements: []const u32,
...@@ -12936,13 +12988,15 @@ fn debugExpressionAssumeCapacity(...@@ -12936,13 +12988,15 @@ fn debugExpressionAssumeCapacity(
12936 const Adapter = struct {12988 const Adapter = struct {
12937 builder: *const Builder,12989 builder: *const Builder,
12938 pub fn hash(_: @This(), key: Key) u32 {12990 pub fn hash(_: @This(), key: Key) u32 {
12939 var hasher = comptime std.hash.Wyhash.init(std.hash.int(@intFromEnum(Metadata.Tag.expression)));12991 var hasher =
12992 comptime std.hash.Wyhash.init(std.hash.int(@intFromEnum(Metadata.Tag.expression)));
12940 hasher.update(std.mem.sliceAsBytes(key.elements));12993 hasher.update(std.mem.sliceAsBytes(key.elements));
12941 return @truncate(hasher.final());12994 return @truncate(hasher.final());
12942 }12995 }
1294312996
12944 pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {12997 pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
12945 if (Metadata.Tag.expression != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;12998 if (Metadata.Tag.expression != ctx.builder.metadata_items.items(.tag)[rhs_index])
12999 return false;
12946 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];13000 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
12947 var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Expression, rhs_data);13001 var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Expression, rhs_data);
12948 return std.mem.eql(13002 return std.mem.eql(
...@@ -12969,15 +13023,12 @@ fn debugExpressionAssumeCapacity(...@@ -12969,15 +13023,12 @@ fn debugExpressionAssumeCapacity(
12969 });13023 });
12970 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements));13024 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements));
12971 }13025 }
12972 return @enumFromInt(gop.index);13026 return .{ .index = @intCast(gop.index), .kind = .node };
12973}13027}
1297413028
12975fn metadataTupleAssumeCapacity(13029fn metadataTupleOptionalsAssumeCapacity(self: *Builder, elements: []const Metadata.Optional) Metadata {
12976 self: *Builder,
12977 elements: []const Metadata,
12978) Metadata {
12979 const Key = struct {13030 const Key = struct {
12980 elements: []const Metadata,13031 elements: []const Metadata.Optional,
12981 };13032 };
12982 const Adapter = struct {13033 const Adapter = struct {
12983 builder: *const Builder,13034 builder: *const Builder,
...@@ -12992,9 +13043,9 @@ fn metadataTupleAssumeCapacity(...@@ -12992,9 +13043,9 @@ fn metadataTupleAssumeCapacity(
12992 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];13043 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
12993 var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Tuple, rhs_data);13044 var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Tuple, rhs_data);
12994 return std.mem.eql(13045 return std.mem.eql(
12995 Metadata,13046 Metadata.Optional,
12996 lhs_key.elements,13047 lhs_key.elements,
12997 rhs_extra.trail.next(rhs_extra.data.elements_len, Metadata, ctx.builder),13048 rhs_extra.trail.next(rhs_extra.data.elements_len, Metadata.Optional, ctx.builder),
12998 );13049 );
12999 }13050 }
13000 };13051 };
...@@ -13015,117 +13066,55 @@ fn metadataTupleAssumeCapacity(...@@ -13015,117 +13066,55 @@ fn metadataTupleAssumeCapacity(
13015 });13066 });
13016 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements));13067 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements));
13017 }13068 }
13018 return @enumFromInt(gop.index);13069 return .{ .index = @intCast(gop.index), .kind = .node };
13019}
13020
13021fn strTupleAssumeCapacity(
13022 self: *Builder,
13023 str: MetadataString,
13024 elements: []const Metadata,
13025) Metadata {
13026 const Key = struct {
13027 str: MetadataString,
13028 elements: []const Metadata,
13029 };
13030 const Adapter = struct {
13031 builder: *const Builder,
13032 pub fn hash(_: @This(), key: Key) u32 {
13033 var hasher = comptime std.hash.Wyhash.init(std.hash.int(@intFromEnum(Metadata.Tag.tuple)));
13034 hasher.update(std.mem.sliceAsBytes(key.elements));
13035 return @truncate(hasher.final());
13036 }
13037
13038 pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
13039 if (.str_tuple != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
13040 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
13041 var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.StrTuple, rhs_data);
13042 return rhs_extra.data.str == lhs_key.str and std.mem.eql(
13043 Metadata,
13044 lhs_key.elements,
13045 rhs_extra.trail.next(rhs_extra.data.elements_len, Metadata, ctx.builder),
13046 );
13047 }
13048 };
13049
13050 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
13051 Key{ .str = str, .elements = elements },
13052 Adapter{ .builder = self },
13053 );
13054
13055 if (!gop.found_existing) {
13056 gop.key_ptr.* = {};
13057 gop.value_ptr.* = {};
13058 self.metadata_items.appendAssumeCapacity(.{
13059 .tag = .str_tuple,
13060 .data = self.addMetadataExtraAssumeCapacity(Metadata.StrTuple{
13061 .str = str,
13062 .elements_len = @intCast(elements.len),
13063 }),
13064 });
13065 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements));
13066 }
13067 return @enumFromInt(gop.index);
13068}
13069
13070fn metadataModuleFlagAssumeCapacity(
13071 self: *Builder,
13072 behavior: Metadata,
13073 name: MetadataString,
13074 constant: Metadata,
13075) Metadata {
13076 return self.metadataSimpleAssumeCapacity(.module_flag, Metadata.ModuleFlag{
13077 .behavior = behavior,
13078 .name = name,
13079 .constant = constant,
13080 });
13081}13070}
1308213071
13083fn debugLocalVarAssumeCapacity(13072fn debugLocalVarAssumeCapacity(
13084 self: *Builder,13073 self: *Builder,
13085 name: MetadataString,13074 name: ?Metadata.String,
13086 file: Metadata,13075 file: ?Metadata,
13087 scope: Metadata,13076 scope: ?Metadata,
13088 line: u32,13077 line: u32,
13089 ty: Metadata,13078 ty: ?Metadata,
13090) Metadata {13079) Metadata {
13091 assert(!self.strip);13080 assert(!self.strip);
13092 return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{13081 return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{
13093 .name = name,13082 .name = .wrap(name),
13094 .file = file,13083 .file = .wrap(file),
13095 .scope = scope,13084 .scope = .wrap(scope),
13096 .line = line,13085 .line = line,
13097 .ty = ty,13086 .ty = .wrap(ty),
13098 });13087 });
13099}13088}
1310013089
13101fn debugParameterAssumeCapacity(13090fn debugParameterAssumeCapacity(
13102 self: *Builder,13091 self: *Builder,
13103 name: MetadataString,13092 name: ?Metadata.String,
13104 file: Metadata,13093 file: ?Metadata,
13105 scope: Metadata,13094 scope: ?Metadata,
13106 line: u32,13095 line: u32,
13107 ty: Metadata,13096 ty: ?Metadata,
13108 arg_no: u32,13097 arg_no: u32,
13109) Metadata {13098) Metadata {
13110 assert(!self.strip);13099 assert(!self.strip);
13111 return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{13100 return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{
13112 .name = name,13101 .name = .wrap(name),
13113 .file = file,13102 .file = .wrap(file),
13114 .scope = scope,13103 .scope = .wrap(scope),
13115 .line = line,13104 .line = line,
13116 .ty = ty,13105 .ty = .wrap(ty),
13117 .arg_no = arg_no,13106 .arg_no = arg_no,
13118 });13107 });
13119}13108}
1312013109
13121fn debugGlobalVarAssumeCapacity(13110fn debugGlobalVarAssumeCapacity(
13122 self: *Builder,13111 self: *Builder,
13123 name: MetadataString,13112 name: ?Metadata.String,
13124 linkage_name: MetadataString,13113 linkage_name: ?Metadata.String,
13125 file: Metadata,13114 file: ?Metadata,
13126 scope: Metadata,13115 scope: ?Metadata,
13127 line: u32,13116 line: u32,
13128 ty: Metadata,13117 ty: ?Metadata,
13129 variable: Variable.Index,13118 variable: Variable.Index,
13130 options: Metadata.GlobalVar.Options,13119 options: Metadata.GlobalVar.Options,
13131) Metadata {13120) Metadata {
...@@ -13133,12 +13122,12 @@ fn debugGlobalVarAssumeCapacity(...@@ -13133,12 +13122,12 @@ fn debugGlobalVarAssumeCapacity(
13133 return self.metadataDistinctAssumeCapacity(13122 return self.metadataDistinctAssumeCapacity(
13134 if (options.local) .@"global_var local" else .global_var,13123 if (options.local) .@"global_var local" else .global_var,
13135 Metadata.GlobalVar{13124 Metadata.GlobalVar{
13136 .name = name,13125 .name = .wrap(name),
13137 .linkage_name = linkage_name,13126 .linkage_name = .wrap(linkage_name),
13138 .file = file,13127 .file = .wrap(file),
13139 .scope = scope,13128 .scope = .wrap(scope),
13140 .line = line,13129 .line = line,
13141 .ty = ty,13130 .ty = .wrap(ty),
13142 .variable = variable,13131 .variable = variable,
13143 },13132 },
13144 );13133 );
...@@ -13146,13 +13135,13 @@ fn debugGlobalVarAssumeCapacity(...@@ -13146,13 +13135,13 @@ fn debugGlobalVarAssumeCapacity(
1314613135
13147fn debugGlobalVarExpressionAssumeCapacity(13136fn debugGlobalVarExpressionAssumeCapacity(
13148 self: *Builder,13137 self: *Builder,
13149 variable: Metadata,13138 variable: ?Metadata,
13150 expression: Metadata,13139 expression: ?Metadata,
13151) Metadata {13140) Metadata {
13152 assert(!self.strip);13141 assert(!self.strip);
13153 return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{13142 return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{
13154 .variable = variable,13143 .variable = .wrap(variable),
13155 .expression = expression,13144 .expression = .wrap(expression),
13156 });13145 });
13157}13146}
1315813147
...@@ -13185,7 +13174,7 @@ fn metadataConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {...@@ -13185,7 +13174,7 @@ fn metadataConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {
13185 .data = @intFromEnum(constant),13174 .data = @intFromEnum(constant),
13186 });13175 });
13187 }13176 }
13188 return @enumFromInt(gop.index);13177 return .{ .index = @intCast(gop.index), .kind = .node };
13189}13178}
1319013179
13191pub const Producer = struct {13180pub const Producer = struct {
...@@ -13209,8 +13198,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13209,8 +13198,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1320913198
13210 // IDENTIFICATION_BLOCK13199 // IDENTIFICATION_BLOCK
13211 {13200 {
13212 const Identification = ir.Identification;13201 const IdentificationBlock = ir.IdentificationBlock;
13213 var identification_block = try bitcode.enterTopBlock(Identification);13202 var identification_block = try bitcode.enterTopBlock(IdentificationBlock);
1321413203
13215 const producer_str = try std.fmt.allocPrint(self.gpa, "{s} {d}.{d}.{d}", .{13204 const producer_str = try std.fmt.allocPrint(self.gpa, "{s} {d}.{d}.{d}", .{
13216 producer.name,13205 producer.name,
...@@ -13220,42 +13209,42 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13220,42 +13209,42 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13220 });13209 });
13221 defer self.gpa.free(producer_str);13210 defer self.gpa.free(producer_str);
1322213211
13223 try identification_block.writeAbbrev(Identification.Version{ .string = producer_str });13212 try identification_block.writeAbbrev(IdentificationBlock.Version{ .string = producer_str });
13224 try identification_block.writeAbbrev(Identification.Epoch{ .epoch = 0 });13213 try identification_block.writeAbbrev(IdentificationBlock.Epoch{ .epoch = 0 });
1322513214
13226 try identification_block.end();13215 try identification_block.end();
13227 }13216 }
1322813217
13229 // MODULE_BLOCK13218 // MODULE_BLOCK
13230 {13219 {
13231 const Module = ir.Module;13220 const ModuleBlock = ir.ModuleBlock;
13232 var module_block = try bitcode.enterTopBlock(Module);13221 var module_block = try bitcode.enterTopBlock(ModuleBlock);
1323313222
13234 try module_block.writeAbbrev(Module.Version{});13223 try module_block.writeAbbrev(ModuleBlock.Version{});
1323513224
13236 if (self.target_triple.slice(self)) |triple| {13225 if (self.target_triple.slice(self)) |triple| {
13237 try module_block.writeAbbrev(Module.String{13226 try module_block.writeAbbrev(ModuleBlock.String{
13238 .code = 2,13227 .code = 2,
13239 .string = triple,13228 .string = triple,
13240 });13229 });
13241 }13230 }
1324213231
13243 if (self.data_layout.slice(self)) |data_layout| {13232 if (self.data_layout.slice(self)) |data_layout| {
13244 try module_block.writeAbbrev(Module.String{13233 try module_block.writeAbbrev(ModuleBlock.String{
13245 .code = 3,13234 .code = 3,
13246 .string = data_layout,13235 .string = data_layout,
13247 });13236 });
13248 }13237 }
1324913238
13250 if (self.source_filename.slice(self)) |source_filename| {13239 if (self.source_filename.slice(self)) |source_filename| {
13251 try module_block.writeAbbrev(Module.String{13240 try module_block.writeAbbrev(ModuleBlock.String{
13252 .code = 16,13241 .code = 16,
13253 .string = source_filename,13242 .string = source_filename,
13254 });13243 });
13255 }13244 }
1325613245
13257 if (self.module_asm.items.len != 0) {13246 if (self.module_asm.items.len != 0) {
13258 try module_block.writeAbbrev(Module.String{13247 try module_block.writeAbbrev(ModuleBlock.String{
13259 .code = 4,13248 .code = 4,
13260 .string = self.module_asm.items,13249 .string = self.module_asm.items,
13261 });13250 });
...@@ -13263,16 +13252,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13263,16 +13252,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1326313252
13264 // TYPE_BLOCK13253 // TYPE_BLOCK
13265 {13254 {
13266 var type_block = try module_block.enterSubBlock(ir.Type, true);13255 const TypeBlock = ir.ModuleBlock.TypeBlock;
13256 var type_block = try module_block.enterSubBlock(TypeBlock, true);
1326713257
13268 try type_block.writeAbbrev(ir.Type.NumEntry{ .num = @intCast(self.type_items.items.len) });13258 try type_block.writeAbbrev(TypeBlock.NumEntry{ .num = @intCast(self.type_items.items.len) });
1326913259
13270 for (self.type_items.items, 0..) |item, i| {13260 for (self.type_items.items, 0..) |item, i| {
13271 const ty: Type = @enumFromInt(i);13261 const ty: Type = @enumFromInt(i);
1327213262
13273 switch (item.tag) {13263 switch (item.tag) {
13274 .simple => try type_block.writeAbbrev(ir.Type.Simple{ .code = @truncate(item.data) }),13264 .simple => try type_block.writeAbbrev(TypeBlock.Simple{ .code = @enumFromInt(item.data) }),
13275 .integer => try type_block.writeAbbrev(ir.Type.Integer{ .width = item.data }),13265 .integer => try type_block.writeAbbrev(TypeBlock.Integer{ .width = item.data }),
13276 .structure,13266 .structure,
13277 .packed_structure,13267 .packed_structure,
13278 => |kind| {13268 => |kind| {
...@@ -13282,19 +13272,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13282,19 +13272,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13282 else => unreachable,13272 else => unreachable,
13283 };13273 };
13284 var extra = self.typeExtraDataTrail(Type.Structure, item.data);13274 var extra = self.typeExtraDataTrail(Type.Structure, item.data);
13285 try type_block.writeAbbrev(ir.Type.StructAnon{13275 try type_block.writeAbbrev(TypeBlock.StructAnon{
13286 .is_packed = is_packed,13276 .is_packed = is_packed,
13287 .types = extra.trail.next(extra.data.fields_len, Type, self),13277 .types = extra.trail.next(extra.data.fields_len, Type, self),
13288 });13278 });
13289 },13279 },
13290 .named_structure => {13280 .named_structure => {
13291 const extra = self.typeExtraData(Type.NamedStructure, item.data);13281 const extra = self.typeExtraData(Type.NamedStructure, item.data);
13292 try type_block.writeAbbrev(ir.Type.StructName{13282 try type_block.writeAbbrev(TypeBlock.StructName{
13293 .string = extra.id.slice(self).?,13283 .string = extra.id.slice(self).?,
13294 });13284 });
1329513285
13296 switch (extra.body) {13286 switch (extra.body) {
13297 .none => try type_block.writeAbbrev(ir.Type.Opaque{}),13287 .none => try type_block.writeAbbrev(TypeBlock.Opaque{}),
13298 else => {13288 else => {
13299 const real_struct = self.type_items.items[@intFromEnum(extra.body)];13289 const real_struct = self.type_items.items[@intFromEnum(extra.body)];
13300 const is_packed: bool = switch (real_struct.tag) {13290 const is_packed: bool = switch (real_struct.tag) {
...@@ -13304,7 +13294,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13304,7 +13294,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13304 };13294 };
1330513295
13306 var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data);13296 var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data);
13307 try type_block.writeAbbrev(ir.Type.StructNamed{13297 try type_block.writeAbbrev(TypeBlock.StructNamed{
13308 .is_packed = is_packed,13298 .is_packed = is_packed,
13309 .types = real_extra.trail.next(real_extra.data.fields_len, Type, self),13299 .types = real_extra.trail.next(real_extra.data.fields_len, Type, self),
13310 });13300 });
...@@ -13313,29 +13303,29 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13313,29 +13303,29 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13313 },13303 },
13314 .array,13304 .array,
13315 .small_array,13305 .small_array,
13316 => try type_block.writeAbbrev(ir.Type.Array{13306 => try type_block.writeAbbrev(TypeBlock.Array{
13317 .len = ty.aggregateLen(self),13307 .len = ty.aggregateLen(self),
13318 .child = ty.childType(self),13308 .child = ty.childType(self),
13319 }),13309 }),
13320 .vector,13310 .vector,
13321 .scalable_vector,13311 .scalable_vector,
13322 => try type_block.writeAbbrev(ir.Type.Vector{13312 => try type_block.writeAbbrev(TypeBlock.Vector{
13323 .len = ty.aggregateLen(self),13313 .len = ty.aggregateLen(self),
13324 .child = ty.childType(self),13314 .child = ty.childType(self),
13325 }),13315 }),
13326 .pointer => try type_block.writeAbbrev(ir.Type.Pointer{13316 .pointer => try type_block.writeAbbrev(TypeBlock.Pointer{
13327 .addr_space = ty.pointerAddrSpace(self),13317 .addr_space = ty.pointerAddrSpace(self),
13328 }),13318 }),
13329 .target => {13319 .target => {
13330 var extra = self.typeExtraDataTrail(Type.Target, item.data);13320 var extra = self.typeExtraDataTrail(Type.Target, item.data);
13331 try type_block.writeAbbrev(ir.Type.StructName{13321 try type_block.writeAbbrev(TypeBlock.StructName{
13332 .string = extra.data.name.slice(self).?,13322 .string = extra.data.name.slice(self).?,
13333 });13323 });
1333413324
13335 const types = extra.trail.next(extra.data.types_len, Type, self);13325 const types = extra.trail.next(extra.data.types_len, Type, self);
13336 const ints = extra.trail.next(extra.data.ints_len, u32, self);13326 const ints = extra.trail.next(extra.data.ints_len, u32, self);
1333713327
13338 try type_block.writeAbbrev(ir.Type.Target{13328 try type_block.writeAbbrev(TypeBlock.Target{
13339 .num_types = extra.data.types_len,13329 .num_types = extra.data.types_len,
13340 .types = types,13330 .types = types,
13341 .ints = ints,13331 .ints = ints,
...@@ -13348,7 +13338,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13348,7 +13338,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13348 else => unreachable,13338 else => unreachable,
13349 };13339 };
13350 var extra = self.typeExtraDataTrail(Type.Function, item.data);13340 var extra = self.typeExtraDataTrail(Type.Function, item.data);
13351 try type_block.writeAbbrev(ir.Type.Function{13341 try type_block.writeAbbrev(TypeBlock.Function{
13352 .is_vararg = is_vararg,13342 .is_vararg = is_vararg,
13353 .return_type = extra.data.ret,13343 .return_type = extra.data.ret,
13354 .param_types = extra.trail.next(extra.data.params_len, Type, self),13344 .param_types = extra.trail.next(extra.data.params_len, Type, self),
...@@ -13368,9 +13358,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13368,9 +13358,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1336813358
13369 // PARAMATTR_GROUP_BLOCK13359 // PARAMATTR_GROUP_BLOCK
13370 {13360 {
13371 const ParamattrGroup = ir.ParamattrGroup;13361 const ParamattrGroupBlock = ir.ModuleBlock.ParamattrGroupBlock;
1337213362
13373 var paramattr_group_block = try module_block.enterSubBlock(ParamattrGroup, true);13363 var paramattr_group_block = try module_block.enterSubBlock(ParamattrGroupBlock, true);
1337413364
13375 for (self.function_attributes_set.keys()) |func_attributes| {13365 for (self.function_attributes_set.keys()) |func_attributes| {
13376 for (func_attributes.slice(self), 0..) |attributes, i| {13366 for (func_attributes.slice(self), 0..) |attributes, i| {
...@@ -13572,8 +13562,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13572,8 +13562,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1357213562
13573 // PARAMATTR_BLOCK13563 // PARAMATTR_BLOCK
13574 {13564 {
13575 const Paramattr = ir.Paramattr;13565 const ParamattrBlock = ir.ModuleBlock.ParamattrBlock;
13576 var paramattr_block = try module_block.enterSubBlock(Paramattr, true);13566 var paramattr_block = try module_block.enterSubBlock(ParamattrBlock, true);
1357713567
13578 for (self.function_attributes_set.keys()) |func_attributes| {13568 for (self.function_attributes_set.keys()) |func_attributes| {
13579 const func_attributes_slice = func_attributes.slice(self);13569 const func_attributes_slice = func_attributes.slice(self);
...@@ -13590,7 +13580,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13590,7 +13580,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13590 record.appendAssumeCapacity(@intCast(group_index));13580 record.appendAssumeCapacity(@intCast(group_index));
13591 }13581 }
1359213582
13593 try paramattr_block.writeAbbrev(Paramattr.Entry{ .group_indices = record.items });13583 try paramattr_block.writeAbbrev(ParamattrBlock.Entry{ .group_indices = record.items });
13594 }13584 }
1359513585
13596 try paramattr_block.end();13586 try paramattr_block.end();
...@@ -13624,38 +13614,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13624,38 +13614,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13624 }13614 }
1362513615
13626 const ConstantAdapter = struct {13616 const ConstantAdapter = struct {
13627 const ConstantAdapter = @This();
13628 builder: *const Builder,13617 builder: *const Builder,
13629 globals: *const std.AutoArrayHashMapUnmanaged(Global.Index, void),13618 globals: *const std.AutoArrayHashMapUnmanaged(Global.Index, void),
1363013619
13631 pub fn get(adapter: @This(), param: anytype, comptime field_name: []const u8) @TypeOf(param) {13620 pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) {
13632 _ = field_name;13621 Constant => u32,
13622 else => |Param| Param,
13623 } {
13633 return switch (@TypeOf(param)) {13624 return switch (@TypeOf(param)) {
13634 Constant => @enumFromInt(adapter.getConstantIndex(param)),13625 Constant => adapter.getConstantIndex(param),
13635 else => param,13626 else => param,
13636 };13627 };
13637 }13628 }
1363813629
13639 pub fn getConstantIndex(adapter: ConstantAdapter, constant: Constant) u32 {13630 pub fn getConstantIndex(adapter: @This(), constant: Constant) u32 {
13640 return switch (constant.unwrap()) {13631 return switch (constant.unwrap()) {
13641 .constant => |c| c + adapter.numGlobals(),13632 .constant => |c| c + adapter.numGlobals(),
13642 .global => |global| @intCast(adapter.globals.getIndex(global.unwrap(adapter.builder)).?),13633 .global => |global| @intCast(adapter.globals.getIndex(global.unwrap(adapter.builder)).?),
13643 };13634 };
13644 }13635 }
1364513636
13646 pub fn numConstants(adapter: ConstantAdapter) u32 {13637 pub fn numConstants(adapter: @This()) u32 {
13647 return @intCast(adapter.globals.count() + adapter.builder.constant_items.len);13638 return @intCast(adapter.globals.count() + adapter.builder.constant_items.len);
13648 }13639 }
1364913640
13650 pub fn numGlobals(adapter: ConstantAdapter) u32 {13641 pub fn numGlobals(adapter: @This()) u32 {
13651 return @intCast(adapter.globals.count());13642 return @intCast(adapter.globals.count());
13652 }13643 }
13653 };13644 };
1365413645 const constant_adapter: ConstantAdapter = .{ .builder = self, .globals = &globals };
13655 const constant_adapter = ConstantAdapter{
13656 .builder = self,
13657 .globals = &globals,
13658 };
1365913646
13660 // Globals13647 // Globals
13661 {13648 {
...@@ -13670,7 +13657,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13670,7 +13657,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13670 if (variable.section == .none) break :blk 0;13657 if (variable.section == .none) break :blk 0;
13671 const gop = section_map.getOrPutAssumeCapacity(variable.section);13658 const gop = section_map.getOrPutAssumeCapacity(variable.section);
13672 if (!gop.found_existing) {13659 if (!gop.found_existing) {
13673 try module_block.writeAbbrev(Module.String{13660 try module_block.writeAbbrev(ModuleBlock.String{
13674 .code = 5,13661 .code = 5,
13675 .string = variable.section.slice(self).?,13662 .string = variable.section.slice(self).?,
13676 });13663 });
...@@ -13686,7 +13673,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13686,7 +13673,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13686 const strtab = variable.global.strtab(self);13673 const strtab = variable.global.strtab(self);
1368713674
13688 const global = variable.global.ptrConst(self);13675 const global = variable.global.ptrConst(self);
13689 try module_block.writeAbbrev(Module.Variable{13676 try module_block.writeAbbrev(ModuleBlock.Variable{
13690 .strtab_offset = strtab.offset,13677 .strtab_offset = strtab.offset,
13691 .strtab_size = strtab.size,13678 .strtab_size = strtab.size,
13692 .type_index = global.type,13679 .type_index = global.type,
...@@ -13717,7 +13704,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13717,7 +13704,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13717 if (func.section == .none) break :blk 0;13704 if (func.section == .none) break :blk 0;
13718 const gop = section_map.getOrPutAssumeCapacity(func.section);13705 const gop = section_map.getOrPutAssumeCapacity(func.section);
13719 if (!gop.found_existing) {13706 if (!gop.found_existing) {
13720 try module_block.writeAbbrev(Module.String{13707 try module_block.writeAbbrev(ModuleBlock.String{
13721 .code = 5,13708 .code = 5,
13722 .string = func.section.slice(self).?,13709 .string = func.section.slice(self).?,
13723 });13710 });
...@@ -13733,7 +13720,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13733,7 +13720,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13733 const strtab = func.global.strtab(self);13720 const strtab = func.global.strtab(self);
1373413721
13735 const global = func.global.ptrConst(self);13722 const global = func.global.ptrConst(self);
13736 try module_block.writeAbbrev(Module.Function{13723 try module_block.writeAbbrev(ModuleBlock.Function{
13737 .strtab_offset = strtab.offset,13724 .strtab_offset = strtab.offset,
13738 .strtab_size = strtab.size,13725 .strtab_size = strtab.size,
13739 .type_index = global.type,13726 .type_index = global.type,
...@@ -13757,7 +13744,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13757,7 +13744,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13757 const strtab = alias.global.strtab(self);13744 const strtab = alias.global.strtab(self);
1375813745
13759 const global = alias.global.ptrConst(self);13746 const global = alias.global.ptrConst(self);
13760 try module_block.writeAbbrev(Module.Alias{13747 try module_block.writeAbbrev(ModuleBlock.Alias{
13761 .strtab_offset = strtab.offset,13748 .strtab_offset = strtab.offset,
13762 .strtab_size = strtab.size,13749 .strtab_size = strtab.size,
13763 .type_index = global.type,13750 .type_index = global.type,
...@@ -13775,8 +13762,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13775,8 +13762,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1377513762
13776 // CONSTANTS_BLOCK13763 // CONSTANTS_BLOCK
13777 {13764 {
13778 const Constants = ir.Constants;13765 const ConstantsBlock = ir.ModuleBlock.ConstantsBlock;
13779 var constants_block = try module_block.enterSubBlock(Constants, true);13766 var constants_block = try module_block.enterSubBlock(ConstantsBlock, true);
1378013767
13781 var current_type: Type = .none;13768 var current_type: Type = .none;
13782 const tags = self.constant_items.items(.tag);13769 const tags = self.constant_items.items(.tag);
...@@ -13786,7 +13773,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13786,7 +13773,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13786 const constant: Constant = @enumFromInt(index);13773 const constant: Constant = @enumFromInt(index);
13787 const constant_type = constant.typeOf(self);13774 const constant_type = constant.typeOf(self);
13788 if (constant_type != current_type) {13775 if (constant_type != current_type) {
13789 try constants_block.writeAbbrev(Constants.SetType{ .type_id = constant_type });13776 try constants_block.writeAbbrev(ConstantsBlock.SetType{ .type_id = constant_type });
13790 current_type = constant_type;13777 current_type = constant_type;
13791 }13778 }
13792 const data = datas[index];13779 const data = datas[index];
...@@ -13794,9 +13781,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13794,9 +13781,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13794 .null,13781 .null,
13795 .zeroinitializer,13782 .zeroinitializer,
13796 .none,13783 .none,
13797 => try constants_block.writeAbbrev(Constants.Null{}),13784 => try constants_block.writeAbbrev(ConstantsBlock.Null{}),
13798 .undef => try constants_block.writeAbbrev(Constants.Undef{}),13785 .undef => try constants_block.writeAbbrev(ConstantsBlock.Undef{}),
13799 .poison => try constants_block.writeAbbrev(Constants.Poison{}),13786 .poison => try constants_block.writeAbbrev(ConstantsBlock.Poison{}),
13800 .positive_integer,13787 .positive_integer,
13801 .negative_integer,13788 .negative_integer,
13802 => |tag| {13789 => |tag| {
...@@ -13832,7 +13819,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13832,7 +13819,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13832 try constants_block.writeUnabbrev(5, record.items);13819 try constants_block.writeUnabbrev(5, record.items);
13833 continue;13820 continue;
13834 };13821 };
13835 try constants_block.writeAbbrev(Constants.Integer{13822 try constants_block.writeAbbrev(ConstantsBlock.Integer{
13836 .value = @bitCast(if (val >= 0)13823 .value = @bitCast(if (val >= 0)
13837 val << 1 | 013824 val << 1 | 0
13838 else13825 else
...@@ -13841,17 +13828,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13841,17 +13828,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13841 },13828 },
13842 .half,13829 .half,
13843 .bfloat,13830 .bfloat,
13844 => try constants_block.writeAbbrev(Constants.Half{ .value = @truncate(data) }),13831 => try constants_block.writeAbbrev(ConstantsBlock.Half{ .value = @truncate(data) }),
13845 .float => try constants_block.writeAbbrev(Constants.Float{ .value = data }),13832 .float => try constants_block.writeAbbrev(ConstantsBlock.Float{ .value = data }),
13846 .double => {13833 .double => {
13847 const extra = self.constantExtraData(Constant.Double, data);13834 const extra = self.constantExtraData(Constant.Double, data);
13848 try constants_block.writeAbbrev(Constants.Double{13835 try constants_block.writeAbbrev(ConstantsBlock.Double{
13849 .value = (@as(u64, extra.hi) << 32) | extra.lo,13836 .value = (@as(u64, extra.hi) << 32) | extra.lo,
13850 });13837 });
13851 },13838 },
13852 .x86_fp80 => {13839 .x86_fp80 => {
13853 const extra = self.constantExtraData(Constant.Fp80, data);13840 const extra = self.constantExtraData(Constant.Fp80, data);
13854 try constants_block.writeAbbrev(Constants.Fp80{13841 try constants_block.writeAbbrev(ConstantsBlock.Fp80{
13855 .hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 |13842 .hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 |
13856 extra.lo_lo >> 16,13843 extra.lo_lo >> 16,
13857 .lo = @truncate(extra.lo_lo),13844 .lo = @truncate(extra.lo_lo),
...@@ -13861,7 +13848,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13861,7 +13848,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13861 .ppc_fp128,13848 .ppc_fp128,
13862 => {13849 => {
13863 const extra = self.constantExtraData(Constant.Fp128, data);13850 const extra = self.constantExtraData(Constant.Fp128, data);
13864 try constants_block.writeAbbrev(Constants.Fp128{13851 try constants_block.writeAbbrev(ConstantsBlock.Fp128{
13865 .lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo),13852 .lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo),
13866 .hi = @as(u64, extra.hi_hi) << 32 | @as(u64, extra.hi_lo),13853 .hi = @as(u64, extra.hi_hi) << 32 | @as(u64, extra.hi_lo),
13867 });13854 });
...@@ -13876,35 +13863,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13876,35 +13863,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13876 const values = extra.trail.next(len, Constant, self);13863 const values = extra.trail.next(len, Constant, self);
1387713864
13878 try constants_block.writeAbbrevAdapted(13865 try constants_block.writeAbbrevAdapted(
13879 Constants.Aggregate{ .values = values },13866 ConstantsBlock.Aggregate{ .values = values },
13880 constant_adapter,13867 constant_adapter,
13881 );13868 );
13882 },13869 },
13883 .splat => {13870 .splat => {
13884 const ConstantsWriter = @TypeOf(constants_block);13871 const ConstantsBlockWriter = @TypeOf(constants_block);
13885 const extra = self.constantExtraData(Constant.Splat, data);13872 const extra = self.constantExtraData(Constant.Splat, data);
13886 const vector_len = extra.type.vectorLen(self);13873 const vector_len = extra.type.vectorLen(self);
13887 const c = constant_adapter.getConstantIndex(extra.value);13874 const c = constant_adapter.getConstantIndex(extra.value);
1388813875
13889 try bitcode.writeBits(13876 try bitcode.writeBits(
13890 ConstantsWriter.abbrevId(Constants.Aggregate),13877 ConstantsBlockWriter.abbrevId(ConstantsBlock.Aggregate),
13891 ConstantsWriter.abbrev_len,13878 ConstantsBlockWriter.abbrev_len,
13892 );13879 );
13893 try bitcode.writeVBR(vector_len, 6);13880 try bitcode.writeVbr(vector_len, 6);
13894 for (0..vector_len) |_| {13881 for (0..vector_len) |_| {
13895 try bitcode.writeBits(c, Constants.Aggregate.ops[1].array_fixed);13882 try bitcode.writeBits(c, ConstantsBlock.Aggregate.ops[1].array_fixed);
13896 }13883 }
13897 },13884 },
13898 .string => {13885 .string => {
13899 const str: String = @enumFromInt(data);13886 const str: String = @enumFromInt(data);
13900 if (str == .none) {13887 if (str == .none) {
13901 try constants_block.writeAbbrev(Constants.Null{});13888 try constants_block.writeAbbrev(ConstantsBlock.Null{});
13902 } else {13889 } else {
13903 const slice = str.slice(self).?;13890 const slice = str.slice(self).?;
13904 if (slice.len > 0 and slice[slice.len - 1] == 0)13891 if (slice.len > 0 and slice[slice.len - 1] == 0)
13905 try constants_block.writeAbbrev(Constants.CString{ .string = slice[0 .. slice.len - 1] })13892 try constants_block.writeAbbrev(ConstantsBlock.CString{ .string = slice[0 .. slice.len - 1] })
13906 else13893 else
13907 try constants_block.writeAbbrev(Constants.String{ .string = slice });13894 try constants_block.writeAbbrev(ConstantsBlock.String{ .string = slice });
13908 }13895 }
13909 },13896 },
13910 .bitcast,13897 .bitcast,
...@@ -13914,7 +13901,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13914,7 +13901,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13914 .trunc,13901 .trunc,
13915 => |tag| {13902 => |tag| {
13916 const extra = self.constantExtraData(Constant.Cast, data);13903 const extra = self.constantExtraData(Constant.Cast, data);
13917 try constants_block.writeAbbrevAdapted(Constants.Cast{13904 try constants_block.writeAbbrevAdapted(ConstantsBlock.Cast{
13918 .type_index = extra.type,13905 .type_index = extra.type,
13919 .val = extra.val,13906 .val = extra.val,
13920 .opcode = tag.toCastOpcode(),13907 .opcode = tag.toCastOpcode(),
...@@ -13930,7 +13917,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -13930,7 +13917,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
13930 .xor,13917 .xor,
13931 => |tag| {13918 => |tag| {
13932 const extra = self.constantExtraData(Constant.Binary, data);13919 const extra = self.constantExtraData(Constant.Binary, data);
13933 try constants_block.writeAbbrevAdapted(Constants.Binary{13920 try constants_block.writeAbbrevAdapted(ConstantsBlock.Binary{
13934 .opcode = tag.toBinaryOpcode(),13921 .opcode = tag.toBinaryOpcode(),
13935 .lhs = extra.lhs,13922 .lhs = extra.lhs,
13936 .rhs = extra.rhs,13923 .rhs = extra.rhs,
...@@ -14014,7 +14001,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14014,7 +14001,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14014 },14001 },
14015 .blockaddress => {14002 .blockaddress => {
14016 const extra = self.constantExtraData(Constant.BlockAddress, data);14003 const extra = self.constantExtraData(Constant.BlockAddress, data);
14017 try constants_block.writeAbbrev(Constants.BlockAddress{14004 try constants_block.writeAbbrev(ConstantsBlock.BlockAddress{
14018 .type_id = extra.function.typeOf(self),14005 .type_id = extra.function.typeOf(self),
14019 .function = constant_adapter.getConstantIndex(extra.function.toConst(self)),14006 .function = constant_adapter.getConstantIndex(extra.function.toConst(self)),
14020 .block = @intFromEnum(extra.block),14007 .block = @intFromEnum(extra.block),
...@@ -14024,10 +14011,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14024,10 +14011,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14024 .no_cfi,14011 .no_cfi,
14025 => |tag| {14012 => |tag| {
14026 const function: Function.Index = @enumFromInt(data);14013 const function: Function.Index = @enumFromInt(data);
14027 try constants_block.writeAbbrev(Constants.DsoLocalEquivalentOrNoCfi{14014 try constants_block.writeAbbrev(ConstantsBlock.DsoLocalEquivalentOrNoCfi{
14028 .code = switch (tag) {14015 .code = switch (tag) {
14029 .dso_local_equivalent => 27,14016 .dso_local_equivalent => .DSO_LOCAL_EQUIVALENT,
14030 .no_cfi => 29,14017 .no_cfi => .NO_CFI_VALUE,
14031 else => unreachable,14018 else => unreachable,
14032 },14019 },
14033 .type_id = function.typeOf(self),14020 .type_id = function.typeOf(self),
...@@ -14042,7 +14029,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14042,7 +14029,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1404214029
14043 // METADATA_KIND_BLOCK14030 // METADATA_KIND_BLOCK
14044 {14031 {
14045 const MetadataKindBlock = ir.MetadataKindBlock;14032 const MetadataKindBlock = ir.ModuleBlock.MetadataKindBlock;
14046 var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true);14033 var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true);
1404714034
14048 inline for (@typeInfo(ir.FixedMetadataKind).@"enum".fields) |field| {14035 inline for (@typeInfo(ir.FixedMetadataKind).@"enum".fields) |field| {
...@@ -14059,95 +14046,85 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14059,95 +14046,85 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14059 }14046 }
1406014047
14061 const MetadataAdapter = struct {14048 const MetadataAdapter = struct {
14062 builder: *const Builder,
14063 constant_adapter: ConstantAdapter,14049 constant_adapter: ConstantAdapter,
1406414050
14065 pub fn init(14051 pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) {
14066 builder: *const Builder,14052 Metadata, Metadata.Optional, Metadata.String, Metadata.String.Optional, Constant => u32,
14067 const_adapter: ConstantAdapter,14053 else => |Result| Result,
14068 ) @This() {14054 } {
14069 return .{14055 return switch (@TypeOf(param)) {
14070 .builder = builder,14056 Metadata => adapter.getMetadataIndex(param),
14071 .constant_adapter = const_adapter,14057 Metadata.Optional => adapter.getOptionalMetadataIndex(param),
14072 };14058 Metadata.String => adapter.getMetadataIndex(param.toMetadata()),
14073 }14059 Metadata.String.Optional => adapter.getOptionalMetadataIndex(param.toMetadata()),
1407414060 Constant => adapter.constant_adapter.getConstantIndex(param),
14075 pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) {14061 else => param,
14076 _ = field_name;
14077 const Ty = @TypeOf(value);
14078 return switch (Ty) {
14079 Metadata => @enumFromInt(adapter.getMetadataIndex(value)),
14080 MetadataString => @enumFromInt(adapter.getMetadataStringIndex(value)),
14081 Constant => @enumFromInt(adapter.constant_adapter.getConstantIndex(value)),
14082 else => value,
14083 };14062 };
14084 }14063 }
1408514064
14086 pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32 {14065 pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32 {
14087 if (metadata == .none) return 0;14066 const builder = adapter.constant_adapter.builder;
14088 return @intCast(adapter.builder.metadata_string_map.count() +14067 const unwrapped_metadata = metadata.unwrap(builder);
14089 @intFromEnum(metadata.unwrap(adapter.builder)) - 1);14068 return switch (unwrapped_metadata.kind) {
14069 .string => unwrapped_metadata.index,
14070 .node => @intCast(builder.metadata_string_map.count() + unwrapped_metadata.index),
14071 .forward, .local => unreachable,
14072 };
14090 }14073 }
1409114074
14092 pub fn getMetadataStringIndex(_: @This(), metadata_string: MetadataString) u32 {14075 pub fn getOptionalMetadataIndex(adapter: @This(), metadata: Metadata.Optional) u32 {
14093 return @intFromEnum(metadata_string);14076 return if (metadata.unwrap()) |m| 1 + adapter.getMetadataIndex(m) else 0;
14094 }14077 }
14095 };14078 };
1409614079 const metadata_adapter: MetadataAdapter = .{ .constant_adapter = constant_adapter };
14097 const metadata_adapter = MetadataAdapter.init(self, constant_adapter);
1409814080
14099 // METADATA_BLOCK14081 // METADATA_BLOCK
14100 {14082 {
14101 const MetadataBlock = ir.MetadataBlock;14083 const MetadataBlock = ir.ModuleBlock.MetadataBlock;
14102 var metadata_block = try module_block.enterSubBlock(MetadataBlock, true);14084 var metadata_block = try module_block.enterSubBlock(MetadataBlock, true);
1410314085
14104 const MetadataBlockWriter = @TypeOf(metadata_block);14086 const MetadataBlockWriter = @TypeOf(metadata_block);
1410514087
14106 // Emit all MetadataStrings14088 // Emit all Metadata.Strings
14107 if (self.metadata_string_map.count() > 1) {14089 const strings_len: u32 = @intCast(self.metadata_string_map.count());
14108 const strings_offset, const strings_size = blk: {14090 if (strings_len > 0) {
14109 var strings_offset: u32 = 0;14091 const string_bytes_offset = string_bytes_offset: {
14110 var strings_size: u32 = 0;14092 var string_bytes_bit_offset: u32 = 0;
14111 for (1..self.metadata_string_map.count()) |metadata_string_index| {14093 for (
14112 const metadata_string: MetadataString = @enumFromInt(metadata_string_index);14094 self.metadata_string_indices.items[0..strings_len],
14113 const slice = metadata_string.slice(self);14095 self.metadata_string_indices.items[1..],
14114 strings_offset += bitcode.bitsVBR(@as(u32, @intCast(slice.len)), 6);14096 ) |start, end| string_bytes_bit_offset += BitcodeWriter.bitsVbr(end - start, 6);
14115 strings_size += @intCast(slice.len * 8);14097 break :string_bytes_offset @divExact(
14116 }14098 std.mem.alignForward(u32, string_bytes_bit_offset, 32),
14117 break :blk .{14099 8,
14118 std.mem.alignForward(u32, strings_offset, 32) / 8,14100 );
14119 std.mem.alignForward(u32, strings_size, 32) / 8,
14120 };
14121 };14101 };
14102 const string_bytes_len =
14103 std.mem.alignForward(u32, @intCast(self.metadata_string_bytes.items.len), 4);
1412214104
14123 try bitcode.writeBits(14105 try bitcode.writeBits(
14124 comptime MetadataBlockWriter.abbrevId(MetadataBlock.Strings),14106 comptime MetadataBlockWriter.abbrevId(MetadataBlock.Strings),
14125 MetadataBlockWriter.abbrev_len,14107 MetadataBlockWriter.abbrev_len,
14126 );14108 );
1412714109
14128 try bitcode.writeVBR(@as(u32, @intCast(self.metadata_string_map.count() - 1)), 6);14110 try bitcode.writeVbr(strings_len, 6);
14129 try bitcode.writeVBR(strings_offset, 6);14111 try bitcode.writeVbr(string_bytes_offset, 6);
1413014112
14131 try bitcode.writeVBR(strings_size + strings_offset, 6);14113 try bitcode.writeVbr(string_bytes_offset + string_bytes_len, 6);
1413214114
14133 try bitcode.alignTo32();14115 try bitcode.alignTo32();
1413414116
14135 for (1..self.metadata_string_map.count()) |metadata_string_index| {14117 for (
14136 const metadata_string: MetadataString = @enumFromInt(metadata_string_index);14118 self.metadata_string_indices.items[0..strings_len],
14137 const slice = metadata_string.slice(self);14119 self.metadata_string_indices.items[1..],
14138 try bitcode.writeVBR(@as(u32, @intCast(slice.len)), 6);14120 ) |start, end| try bitcode.writeVbr(end - start, 6);
14139 }
1414014121
14141 try bitcode.writeBlob(self.metadata_string_bytes.items);14122 try bitcode.writeBlob(self.metadata_string_bytes.items);
14142 }14123 }
1414314124
14144 for (14125 for (self.metadata_items.items(.tag), self.metadata_items.items(.data)) |tag, data| {
14145 self.metadata_items.items(.tag)[1..],
14146 self.metadata_items.items(.data)[1..],
14147 ) |tag, data| {
14148 record.clearRetainingCapacity();14126 record.clearRetainingCapacity();
14149 switch (tag) {14127 switch (tag) {
14150 .none => unreachable,
14151 .file => {14128 .file => {
14152 const extra = self.metadataExtraData(Metadata.File, data);14129 const extra = self.metadataExtraData(Metadata.File, data);
1415314130
...@@ -14209,13 +14186,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14209,13 +14186,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14209 },14186 },
14210 .location => {14187 .location => {
14211 const extra = self.metadataExtraData(Metadata.Location, data);14188 const extra = self.metadataExtraData(Metadata.Location, data);
14212 assert(extra.scope != .none);14189 try metadata_block.writeAbbrevAdapted(MetadataBlock.Location{
14213 try metadata_block.writeAbbrev(MetadataBlock.Location{
14214 .line = extra.line,14190 .line = extra.line,
14215 .column = extra.column,14191 .column = extra.column,
14216 .scope = metadata_adapter.getMetadataIndex(extra.scope) - 1,14192 .scope = extra.scope,
14217 .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(extra.inlined_at)),14193 .inlined_at = extra.inlined_at,
14218 });14194 }, metadata_adapter);
14219 },14195 },
14220 .basic_bool_type,14196 .basic_bool_type,
14221 .basic_unsigned_type,14197 .basic_unsigned_type,
...@@ -14325,7 +14301,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14325,7 +14301,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14325 @bitCast(flags),14301 @bitCast(flags),
14326 ));14302 ));
14327 record.appendAssumeCapacity(extra.bit_width);14303 record.appendAssumeCapacity(extra.bit_width);
14328 record.appendAssumeCapacity(metadata_adapter.getMetadataStringIndex(extra.name));14304 record.appendAssumeCapacity(metadata_adapter.getOptionalMetadataIndex(extra.name.toMetadata()));
14329 const limbs = record.addManyAsSliceAssumeCapacity(limbs_len);14305 const limbs = record.addManyAsSliceAssumeCapacity(limbs_len);
14330 bigint.writeTwosComplement(std.mem.sliceAsBytes(limbs), .little);14306 bigint.writeTwosComplement(std.mem.sliceAsBytes(limbs), .little);
14331 for (limbs) |*limb| {14307 for (limbs) |*limb| {
...@@ -14335,7 +14311,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14335,7 +14311,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14335 else14311 else
14336 -%val << 1 | 1);14312 -%val << 1 | 1);
14337 }14313 }
14338 try metadata_block.writeUnabbrev(@intFromEnum(MetadataBlock.Enumerator.id), record.items);14314 try metadata_block.writeUnabbrev(@intFromEnum(MetadataBlock.Code.ENUMERATOR), record.items);
14339 continue;14315 continue;
14340 };14316 };
14341 try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{14317 try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{
...@@ -14350,7 +14326,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14350,7 +14326,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14350 },14326 },
14351 .subrange => {14327 .subrange => {
14352 const extra = self.metadataExtraData(Metadata.Subrange, data);14328 const extra = self.metadataExtraData(Metadata.Subrange, data);
14353
14354 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subrange{14329 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subrange{
14355 .count = extra.count,14330 .count = extra.count,
14356 .lower_bound = extra.lower_bound,14331 .lower_bound = extra.lower_bound,
...@@ -14358,48 +14333,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14358,48 +14333,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14358 },14333 },
14359 .expression => {14334 .expression => {
14360 var extra = self.metadataExtraDataTrail(Metadata.Expression, data);14335 var extra = self.metadataExtraDataTrail(Metadata.Expression, data);
14361
14362 const elements = extra.trail.next(extra.data.elements_len, u32, self);14336 const elements = extra.trail.next(extra.data.elements_len, u32, self);
14363
14364 try metadata_block.writeAbbrevAdapted(MetadataBlock.Expression{14337 try metadata_block.writeAbbrevAdapted(MetadataBlock.Expression{
14365 .elements = elements,14338 .elements = elements,
14366 }, metadata_adapter);14339 }, metadata_adapter);
14367 },14340 },
14368 .tuple => {14341 .tuple => {
14369 var extra = self.metadataExtraDataTrail(Metadata.Tuple, data);14342 var extra = self.metadataExtraDataTrail(Metadata.Tuple, data);
1437014343 const elements =
14371 const elements = extra.trail.next(extra.data.elements_len, Metadata, self);14344 extra.trail.next(extra.data.elements_len, Metadata.Optional, self);
14372
14373 try metadata_block.writeAbbrevAdapted(MetadataBlock.Node{14345 try metadata_block.writeAbbrevAdapted(MetadataBlock.Node{
14374 .elements = elements,14346 .elements = elements,
14375 }, metadata_adapter);14347 }, metadata_adapter);
14376 },14348 },
14377 .str_tuple => {
14378 var extra = self.metadataExtraDataTrail(Metadata.StrTuple, data);
14379
14380 const elements = extra.trail.next(extra.data.elements_len, Metadata, self);
14381
14382 const all_elems = try self.gpa.alloc(Metadata, elements.len + 1);
14383 defer self.gpa.free(all_elems);
14384 all_elems[0] = @enumFromInt(metadata_adapter.getMetadataStringIndex(extra.data.str));
14385 for (elements, all_elems[1..]) |elem, *out_elem| {
14386 out_elem.* = @enumFromInt(metadata_adapter.getMetadataIndex(elem));
14387 }
14388
14389 try metadata_block.writeAbbrev(MetadataBlock.Node{
14390 .elements = all_elems,
14391 });
14392 },
14393 .module_flag => {
14394 const extra = self.metadataExtraData(Metadata.ModuleFlag, data);
14395 try metadata_block.writeAbbrev(MetadataBlock.Node{
14396 .elements = &.{
14397 @enumFromInt(metadata_adapter.getMetadataIndex(extra.behavior)),
14398 @enumFromInt(metadata_adapter.getMetadataStringIndex(extra.name)),
14399 @enumFromInt(metadata_adapter.getMetadataIndex(extra.constant)),
14400 },
14401 });
14402 },
14403 .local_var => {14349 .local_var => {
14404 const extra = self.metadataExtraData(Metadata.LocalVar, data);14350 const extra = self.metadataExtraData(Metadata.LocalVar, data);
14405 try metadata_block.writeAbbrevAdapted(MetadataBlock.LocalVar{14351 try metadata_block.writeAbbrevAdapted(MetadataBlock.LocalVar{
...@@ -14454,37 +14400,28 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14454,37 +14400,28 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1445414400
14455 // Write named metadata14401 // Write named metadata
14456 for (self.metadata_named.keys(), self.metadata_named.values()) |name, operands| {14402 for (self.metadata_named.keys(), self.metadata_named.values()) |name, operands| {
14457 const slice = name.slice(self);14403 try metadata_block.writeAbbrev(MetadataBlock.Name{ .name = name.slice(self).? });
14458 try metadata_block.writeAbbrev(MetadataBlock.Name{14404 try metadata_block.writeAbbrevAdapted(MetadataBlock.NamedNode{
14459 .name = slice,14405 .elements = @ptrCast(self.metadata_extra.items[operands.index..][0..operands.len]),
14460 });14406 }, metadata_adapter);
14461
14462 const elements = self.metadata_extra.items[operands.index..][0..operands.len];
14463 for (elements) |*e| {
14464 e.* = metadata_adapter.getMetadataIndex(@enumFromInt(e.*)) - 1;
14465 }
14466
14467 try metadata_block.writeAbbrev(MetadataBlock.NamedNode{
14468 .elements = @ptrCast(elements),
14469 });
14470 }14407 }
1447114408
14472 // Write global attached metadata14409 // Write global attached metadata
14473 {14410 {
14474 for (globals.keys()) |global| {14411 for (globals.keys()) |global_index| {
14475 const global_ptr = global.ptrConst(self);14412 const global = global_index.ptrConst(self);
14476 if (global_ptr.dbg == .none) continue;14413 if (global.dbg.unwrap()) |dbg| {
14414 switch (global.kind) {
14415 .function => |f| if (f.ptrConst(self).instructions.len != 0) continue,
14416 else => {},
14417 }
1447714418
14478 switch (global_ptr.kind) {14419 try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalDeclAttachment{
14479 .function => |f| if (f.ptrConst(self).instructions.len != 0) continue,14420 .value = global_index.toConst(),
14480 else => {},14421 .kind = .dbg,
14422 .metadata = dbg,
14423 }, metadata_adapter);
14481 }14424 }
14482
14483 try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{
14484 .value = @enumFromInt(constant_adapter.getConstantIndex(global.toConst())),
14485 .kind = .dbg,
14486 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(global_ptr.dbg) - 1),
14487 });
14488 }14425 }
14489 }14426 }
1449014427
...@@ -14493,10 +14430,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14493,10 +14430,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1449314430
14494 // OPERAND_BUNDLE_TAGS_BLOCK14431 // OPERAND_BUNDLE_TAGS_BLOCK
14495 {14432 {
14496 const OperandBundleTags = ir.OperandBundleTags;14433 const OperandBundleTagsBlock = ir.ModuleBlock.OperandBundleTagsBlock;
14497 var operand_bundle_tags_block = try module_block.enterSubBlock(OperandBundleTags, true);14434 var operand_bundle_tags_block = try module_block.enterSubBlock(OperandBundleTagsBlock, true);
1449814435
14499 try operand_bundle_tags_block.writeAbbrev(OperandBundleTags.OperandBundleTag{14436 try operand_bundle_tags_block.writeAbbrev(OperandBundleTagsBlock.OperandBundleTag{
14500 .tag = "cold",14437 .tag = "cold",
14501 });14438 });
1450214439
...@@ -14505,26 +14442,34 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14505,26 +14442,34 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1450514442
14506 // Block info14443 // Block info
14507 {14444 {
14508 const BlockInfo = ir.BlockInfo;14445 const BlockInfoBlock = ir.BlockInfoBlock;
14509 var block_info_block = try module_block.enterSubBlock(BlockInfo, true);14446 var block_info_block = try module_block.enterSubBlock(BlockInfoBlock, true);
1451014447
14511 try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.FunctionBlock.id});14448 try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
14512 inline for (ir.FunctionBlock.abbrevs) |abbrev| {14449 @intFromEnum(ir.ModuleBlock.FunctionBlock.id),
14450 });
14451 inline for (ir.ModuleBlock.FunctionBlock.abbrevs) |abbrev| {
14513 try block_info_block.defineAbbrev(&abbrev.ops);14452 try block_info_block.defineAbbrev(&abbrev.ops);
14514 }14453 }
1451514454
14516 try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.FunctionValueSymbolTable.id});14455 try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
14517 inline for (ir.FunctionValueSymbolTable.abbrevs) |abbrev| {14456 @intFromEnum(ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.id),
14457 });
14458 inline for (ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.abbrevs) |abbrev| {
14518 try block_info_block.defineAbbrev(&abbrev.ops);14459 try block_info_block.defineAbbrev(&abbrev.ops);
14519 }14460 }
1452014461
14521 try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.FunctionMetadataBlock.id});14462 try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
14522 inline for (ir.FunctionMetadataBlock.abbrevs) |abbrev| {14463 @intFromEnum(ir.ModuleBlock.FunctionBlock.MetadataBlock.id),
14464 });
14465 inline for (ir.ModuleBlock.FunctionBlock.MetadataBlock.abbrevs) |abbrev| {
14523 try block_info_block.defineAbbrev(&abbrev.ops);14466 try block_info_block.defineAbbrev(&abbrev.ops);
14524 }14467 }
1452514468
14526 try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.MetadataAttachmentBlock.id});14469 try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
14527 inline for (ir.MetadataAttachmentBlock.abbrevs) |abbrev| {14470 @intFromEnum(ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.id),
14471 });
14472 inline for (ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.abbrevs) |abbrev| {
14528 try block_info_block.defineAbbrev(&abbrev.ops);14473 try block_info_block.defineAbbrev(&abbrev.ops);
14529 }14474 }
1453014475
...@@ -14534,38 +14479,40 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14534,38 +14479,40 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14534 // FUNCTION_BLOCKS14479 // FUNCTION_BLOCKS
14535 {14480 {
14536 const FunctionAdapter = struct {14481 const FunctionAdapter = struct {
14537 constant_adapter: ConstantAdapter,
14538 metadata_adapter: MetadataAdapter,14482 metadata_adapter: MetadataAdapter,
14539 func: *const Function,14483 func: *const Function,
14540 instruction_index: Function.Instruction.Index,14484 instruction_index: Function.Instruction.Index,
1454114485
14542 pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) {14486 pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) {
14543 _ = field_name;14487 Value, Constant, FunctionAttributes => u32,
14544 const Ty = @TypeOf(value);14488 else => |Result| Result,
14545 return switch (Ty) {14489 } {
14546 Value => @enumFromInt(adapter.getOffsetValueIndex(value)),14490 return switch (@TypeOf(param)) {
14547 Constant => @enumFromInt(adapter.getOffsetConstantIndex(value)),14491 Value => adapter.getOffsetValueIndex(param),
14548 FunctionAttributes => @enumFromInt(switch (value) {14492 Constant => adapter.getOffsetConstantIndex(param),
14493 FunctionAttributes => switch (param) {
14549 .none => 0,14494 .none => 0,
14550 else => 1 + adapter.constant_adapter.builder.function_attributes_set.getIndex(value).?,14495 else => @intCast(1 + adapter.metadata_adapter.constant_adapter.builder
14551 }),14496 .function_attributes_set.getIndex(param).?),
14552 else => value,14497 },
14498 else => param,
14553 };14499 };
14554 }14500 }
1455514501
14556 pub fn getValueIndex(adapter: @This(), value: Value) u32 {14502 pub fn getValueIndex(adapter: @This(), value: Value) u32 {
14557 return @intCast(switch (value.unwrap()) {14503 return @intCast(switch (value.unwrap()) {
14558 .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(),14504 .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(),
14559 .constant => |constant| adapter.constant_adapter.getConstantIndex(constant),14505 .constant => |constant| adapter.metadata_adapter.constant_adapter.getConstantIndex(constant),
14560 .metadata => |metadata| {14506 .metadata => |metadata| {
14561 const real_metadata = metadata.unwrap(adapter.metadata_adapter.builder);14507 const builder = adapter.metadata_adapter.constant_adapter.builder;
14562 if (@intFromEnum(real_metadata) < Metadata.first_local_metadata)14508 const unwrapped_metadata = metadata.unwrap(builder);
14563 return adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1;14509 return switch (unwrapped_metadata.kind) {
1456414510 .string, .node => adapter.metadata_adapter.getMetadataIndex(unwrapped_metadata),
14565 return @intCast(@intFromEnum(metadata) -14511 .forward => unreachable,
14566 Metadata.first_local_metadata +14512 .local => @intCast(builder.metadata_string_map.count() +
14567 adapter.metadata_adapter.builder.metadata_string_map.count() - 1 +14513 builder.metadata_map.count() +
14568 adapter.metadata_adapter.builder.metadata_map.count() - 1);14514 unwrapped_metadata.index),
14515 };
14569 },14516 },
14570 });14517 });
14571 }14518 }
...@@ -14589,12 +14536,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14589,12 +14536,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14589 }14536 }
1459014537
14591 fn firstInstr(adapter: @This()) u32 {14538 fn firstInstr(adapter: @This()) u32 {
14592 return adapter.constant_adapter.numConstants();14539 return adapter.metadata_adapter.constant_adapter.numConstants();
14593 }14540 }
14594 };14541 };
1459514542
14596 for (self.functions.items, 0..) |func, func_index| {14543 for (self.functions.items, 0..) |func, func_index| {
14597 const FunctionBlock = ir.FunctionBlock;14544 const FunctionBlock = ir.ModuleBlock.FunctionBlock;
14598 if (func.global.getReplacement(self) != .none) continue;14545 if (func.global.getReplacement(self) != .none) continue;
1459914546
14600 if (func.instructions.len == 0) continue;14547 if (func.instructions.len == 0) continue;
...@@ -14604,7 +14551,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14604,7 +14551,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14604 try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len });14551 try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len });
1460514552
14606 var adapter: FunctionAdapter = .{14553 var adapter: FunctionAdapter = .{
14607 .constant_adapter = constant_adapter,
14608 .metadata_adapter = metadata_adapter,14554 .metadata_adapter = metadata_adapter,
14609 .func = &func,14555 .func = &func,
14610 .instruction_index = @enumFromInt(0),14556 .instruction_index = @enumFromInt(0),
...@@ -14612,7 +14558,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14612,7 +14558,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1461214558
14613 // Emit function level metadata block14559 // Emit function level metadata block
14614 if (!func.strip and func.debug_values.len > 0) {14560 if (!func.strip and func.debug_values.len > 0) {
14615 const MetadataBlock = ir.FunctionMetadataBlock;14561 const MetadataBlock = ir.ModuleBlock.FunctionBlock.MetadataBlock;
14616 var metadata_block = try function_block.enterSubBlock(MetadataBlock, false);14562 var metadata_block = try function_block.enterSubBlock(MetadataBlock, false);
1461714563
14618 for (func.debug_values) |value| {14564 for (func.debug_values) |value| {
...@@ -15048,7 +14994,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15048,7 +14994,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
15048 const vals = extra.trail.next(extra.data.cases_len, Constant, &func);14994 const vals = extra.trail.next(extra.data.cases_len, Constant, &func);
15049 const blocks = extra.trail.next(extra.data.cases_len, Function.Block.Index, &func);14995 const blocks = extra.trail.next(extra.data.cases_len, Function.Block.Index, &func);
15050 for (vals, blocks) |val, block| {14996 for (vals, blocks) |val, block| {
15051 record.appendAssumeCapacity(adapter.constant_adapter.getConstantIndex(val));14997 record.appendAssumeCapacity(adapter.metadata_adapter.constant_adapter.getConstantIndex(val));
15052 record.appendAssumeCapacity(@intFromEnum(block));14998 record.appendAssumeCapacity(@intFromEnum(block));
15053 }14999 }
1505415000
...@@ -15135,12 +15081,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15135,12 +15081,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
15135 switch (debug_location) {15081 switch (debug_location) {
15136 .no_location => has_location = false,15082 .no_location => has_location = false,
15137 .location => |location| {15083 .location => |location| {
15138 try function_block.writeAbbrev(FunctionBlock.DebugLoc{15084 try function_block.writeAbbrevAdapted(FunctionBlock.DebugLoc{
15139 .line = location.line,15085 .line = location.line,
15140 .column = location.column,15086 .column = location.column,
15141 .scope = @enumFromInt(metadata_adapter.getMetadataIndex(location.scope)),15087 .scope = location.scope,
15142 .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(location.inlined_at)),15088 .inlined_at = location.inlined_at,
15143 });15089 }, metadata_adapter);
15144 has_location = true;15090 has_location = true;
15145 },15091 },
15146 }15092 }
...@@ -15152,16 +15098,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15152,16 +15098,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1515215098
15153 // VALUE_SYMTAB15099 // VALUE_SYMTAB
15154 if (!func.strip) {15100 if (!func.strip) {
15155 const ValueSymbolTable = ir.FunctionValueSymbolTable;15101 const ValueSymtabBlock = ir.ModuleBlock.FunctionBlock.ValueSymtabBlock;
1515615102
15157 var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable, false);15103 var value_symtab_block = try function_block.enterSubBlock(ValueSymtabBlock, false);
1515815104
15159 for (func.blocks, 0..) |block, block_index| {15105 for (func.blocks, 0..) |block, block_index| {
15160 const name = block.instruction.name(&func);15106 const name = block.instruction.name(&func);
1516115107
15162 if (name == .none or name == .empty) continue;15108 if (name == .none or name == .empty) continue;
1516315109
15164 try value_symtab_block.writeAbbrev(ValueSymbolTable.BlockEntry{15110 try value_symtab_block.writeAbbrev(ValueSymtabBlock.BlockEntry{
15165 .value_id = @intCast(block_index),15111 .value_id = @intCast(block_index),
15166 .string = name.slice(self).?,15112 .string = name.slice(self).?,
15167 });15113 });
...@@ -15174,17 +15120,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15174,17 +15120,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1517415120
15175 // METADATA_ATTACHMENT_BLOCK15121 // METADATA_ATTACHMENT_BLOCK
15176 {15122 {
15177 const MetadataAttachmentBlock = ir.MetadataAttachmentBlock;15123 const MetadataAttachmentBlock = ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock;
15178 var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false);15124 var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false);
1517915125
15180 dbg: {15126 if (func.global.ptrConst(self).dbg.unwrap()) |dbg| {
15181 if (func.strip) break :dbg;15127 try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentGlobalSingle{
15182 const dbg = func.global.ptrConst(self).dbg;
15183 if (dbg == .none) break :dbg;
15184 try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentGlobalSingle{
15185 .kind = .dbg,15128 .kind = .dbg,
15186 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),15129 .metadata = dbg,
15187 });15130 }, metadata_adapter);
15188 }15131 }
1518915132
15190 var instr_index: u32 = 0;15133 var instr_index: u32 = 0;
...@@ -15201,16 +15144,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15201,16 +15144,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
15201 };15144 };
15202 switch (weights) {15145 switch (weights) {
15203 .none => {},15146 .none => {},
15204 .unpredictable => try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{15147 .unpredictable => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{
15205 .inst = instr_index,15148 .inst = instr_index,
15206 .kind = .unpredictable,15149 .kind = .unpredictable,
15207 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(.empty_tuple) - 1),15150 .metadata = .empty_tuple,
15208 }),15151 }, metadata_adapter),
15209 _ => try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{15152 _ => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{
15210 .inst = instr_index,15153 .inst = instr_index,
15211 .kind = .prof,15154 .kind = .prof,
15212 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(@enumFromInt(@intFromEnum(weights))) - 1),15155 .metadata = weights.toMetadata(),
15213 }),15156 }, metadata_adapter),
15214 }15157 }
15215 instr_index += 1;15158 instr_index += 1;
15216 },15159 },
...@@ -15228,7 +15171,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15228,7 +15171,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1522815171
15229 // STRTAB_BLOCK15172 // STRTAB_BLOCK
15230 {15173 {
15231 const Strtab = ir.Strtab;15174 const Strtab = ir.StrtabBlock;
15232 var strtab_block = try bitcode.enterTopBlock(Strtab);15175 var strtab_block = try bitcode.enterTopBlock(Strtab);
1523315176
15234 try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.strtab_string_bytes.items });15177 try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.strtab_string_bytes.items });
lib/std/zig/llvm/bitcode_writer.zig+30-32
...@@ -88,7 +88,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -88,7 +88,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
88 }88 }
89 }89 }
9090
91 pub fn writeVBR(self: *BcWriter, value: anytype, comptime vbr_bits: usize) Error!void {91 pub fn writeVbr(self: *BcWriter, value: anytype, comptime vbr_bits: usize) Error!void {
92 comptime {92 comptime {
93 std.debug.assert(vbr_bits > 1);93 std.debug.assert(vbr_bits > 1);
94 if (@bitSizeOf(@TypeOf(value)) > 64) @compileError("Unsupported VBR block type: " ++ @typeName(@TypeOf(value)));94 if (@bitSizeOf(@TypeOf(value)) > 64) @compileError("Unsupported VBR block type: " ++ @typeName(@TypeOf(value)));
...@@ -110,7 +110,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -110,7 +110,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
110 try self.writeBits(in_buffer, vbr_bits);110 try self.writeBits(in_buffer, vbr_bits);
111 }111 }
112112
113 pub fn bitsVBR(_: *const BcWriter, value: anytype, comptime vbr_bits: usize) u16 {113 pub fn bitsVbr(value: anytype, comptime vbr_bits: usize) u16 {
114 comptime {114 comptime {
115 std.debug.assert(vbr_bits > 1);115 std.debug.assert(vbr_bits > 1);
116 if (@bitSizeOf(@TypeOf(value)) > 64) @compileError("Unsupported VBR block type: " ++ @typeName(@TypeOf(value)));116 if (@bitSizeOf(@TypeOf(value)) > 64) @compileError("Unsupported VBR block type: " ++ @typeName(@TypeOf(value)));
...@@ -177,8 +177,8 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -177,8 +177,8 @@ pub fn BitcodeWriter(comptime types: []const type) type {
177177
178 pub fn init(bitcode: *BcWriter, comptime parent_abbrev_len: u6, comptime define_abbrevs: bool) Error!Self {178 pub fn init(bitcode: *BcWriter, comptime parent_abbrev_len: u6, comptime define_abbrevs: bool) Error!Self {
179 try bitcode.writeBits(1, parent_abbrev_len);179 try bitcode.writeBits(1, parent_abbrev_len);
180 try bitcode.writeVBR(Block.id, 8);180 try bitcode.writeVbr(Block.id, 8);
181 try bitcode.writeVBR(abbrev_len, 4);181 try bitcode.writeVbr(abbrev_len, 4);
182 try bitcode.alignTo32();182 try bitcode.alignTo32();
183183
184 // We store the index of the block size and store a dummy value as the number of words in the block184 // We store the index of the block size and store a dummy value as the number of words in the block
...@@ -214,16 +214,16 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -214,16 +214,16 @@ pub fn BitcodeWriter(comptime types: []const type) type {
214214
215 pub fn writeUnabbrev(self: *Self, code: u32, values: []const u64) Error!void {215 pub fn writeUnabbrev(self: *Self, code: u32, values: []const u64) Error!void {
216 try self.bitcode.writeBits(3, abbrev_len);216 try self.bitcode.writeBits(3, abbrev_len);
217 try self.bitcode.writeVBR(code, 6);217 try self.bitcode.writeVbr(code, 6);
218 try self.bitcode.writeVBR(values.len, 6);218 try self.bitcode.writeVbr(values.len, 6);
219 for (values) |val| {219 for (values) |val| {
220 try self.bitcode.writeVBR(val, 6);220 try self.bitcode.writeVbr(val, 6);
221 }221 }
222 }222 }
223223
224 pub fn writeAbbrev(self: *Self, params: anytype) Error!void {224 pub fn writeAbbrev(self: *Self, params: anytype) Error!void {
225 return self.writeAbbrevAdapted(params, struct {225 return self.writeAbbrevAdapted(params, struct {
226 pub fn get(_: @This(), param: anytype, comptime _: []const u8) @TypeOf(param) {226 pub fn get(_: @This(), param: anytype) @TypeOf(param) {
227 return param;227 return param;
228 }228 }
229 }{});229 }{});
...@@ -253,47 +253,45 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -253,47 +253,45 @@ pub fn BitcodeWriter(comptime types: []const type) type {
253253
254 comptime var field_index: usize = 0;254 comptime var field_index: usize = 0;
255 inline for (Abbrev.ops) |ty| {255 inline for (Abbrev.ops) |ty| {
256 const field_name = fields[field_index].name;256 const param = @field(params, fields[field_index].name);
257 const param = @field(params, field_name);
258
259 switch (ty) {257 switch (ty) {
260 .literal => continue,258 .literal => continue,
261 .fixed => |len| try self.bitcode.writeBits(adapter.get(param, field_name), len),259 .fixed => |len| try self.bitcode.writeBits(adapter.get(param), len),
262 .fixed_runtime => |width_ty| try self.bitcode.writeBits(260 .fixed_runtime => |width_ty| try self.bitcode.writeBits(
263 adapter.get(param, field_name),261 adapter.get(param),
264 self.bitcode.getTypeWidth(width_ty),262 self.bitcode.getTypeWidth(width_ty),
265 ),263 ),
266 .vbr => |len| try self.bitcode.writeVBR(adapter.get(param, field_name), len),264 .vbr => |len| try self.bitcode.writeVbr(adapter.get(param), len),
267 .char6 => try self.bitcode.write6BitChar(adapter.get(param, field_name)),265 .char6 => try self.bitcode.write6BitChar(adapter.get(param)),
268 .blob => {266 .blob => {
269 try self.bitcode.writeVBR(param.len, 6);267 try self.bitcode.writeVbr(param.len, 6);
270 try self.bitcode.writeBlob(param);268 try self.bitcode.writeBlob(param);
271 },269 },
272 .array_fixed => |len| {270 .array_fixed => |len| {
273 try self.bitcode.writeVBR(param.len, 6);271 try self.bitcode.writeVbr(param.len, 6);
274 for (param) |x| {272 for (param) |x| {
275 try self.bitcode.writeBits(adapter.get(x, field_name), len);273 try self.bitcode.writeBits(adapter.get(x), len);
276 }274 }
277 },275 },
278 .array_fixed_runtime => |width_ty| {276 .array_fixed_runtime => |width_ty| {
279 try self.bitcode.writeVBR(param.len, 6);277 try self.bitcode.writeVbr(param.len, 6);
280 for (param) |x| {278 for (param) |x| {
281 try self.bitcode.writeBits(279 try self.bitcode.writeBits(
282 adapter.get(x, field_name),280 adapter.get(x),
283 self.bitcode.getTypeWidth(width_ty),281 self.bitcode.getTypeWidth(width_ty),
284 );282 );
285 }283 }
286 },284 },
287 .array_vbr => |len| {285 .array_vbr => |len| {
288 try self.bitcode.writeVBR(param.len, 6);286 try self.bitcode.writeVbr(param.len, 6);
289 for (param) |x| {287 for (param) |x| {
290 try self.bitcode.writeVBR(adapter.get(x, field_name), len);288 try self.bitcode.writeVbr(adapter.get(x), len);
291 }289 }
292 },290 },
293 .array_char6 => {291 .array_char6 => {
294 try self.bitcode.writeVBR(param.len, 6);292 try self.bitcode.writeVbr(param.len, 6);
295 for (param) |x| {293 for (param) |x| {
296 try self.bitcode.write6BitChar(adapter.get(x, field_name));294 try self.bitcode.write6BitChar(adapter.get(x));
297 }295 }
298 },296 },
299 }297 }
...@@ -307,7 +305,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -307,7 +305,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
307 try bitcode.writeBits(2, abbrev_len);305 try bitcode.writeBits(2, abbrev_len);
308306
309 // ops.len is not accurate because arrays are actually two ops307 // ops.len is not accurate because arrays are actually two ops
310 try bitcode.writeVBR(blk: {308 try bitcode.writeVbr(blk: {
311 var count: usize = 0;309 var count: usize = 0;
312 inline for (ops) |op| {310 inline for (ops) |op| {
313 count += switch (op) {311 count += switch (op) {
...@@ -322,22 +320,22 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -322,22 +320,22 @@ pub fn BitcodeWriter(comptime types: []const type) type {
322 switch (op) {320 switch (op) {
323 .literal => |value| {321 .literal => |value| {
324 try bitcode.writeBits(1, 1);322 try bitcode.writeBits(1, 1);
325 try bitcode.writeVBR(value, 8);323 try bitcode.writeVbr(value, 8);
326 },324 },
327 .fixed => |width| {325 .fixed => |width| {
328 try bitcode.writeBits(0, 1);326 try bitcode.writeBits(0, 1);
329 try bitcode.writeBits(1, 3);327 try bitcode.writeBits(1, 3);
330 try bitcode.writeVBR(width, 5);328 try bitcode.writeVbr(width, 5);
331 },329 },
332 .fixed_runtime => |width_ty| {330 .fixed_runtime => |width_ty| {
333 try bitcode.writeBits(0, 1);331 try bitcode.writeBits(0, 1);
334 try bitcode.writeBits(1, 3);332 try bitcode.writeBits(1, 3);
335 try bitcode.writeVBR(bitcode.getTypeWidth(width_ty), 5);333 try bitcode.writeVbr(bitcode.getTypeWidth(width_ty), 5);
336 },334 },
337 .vbr => |width| {335 .vbr => |width| {
338 try bitcode.writeBits(0, 1);336 try bitcode.writeBits(0, 1);
339 try bitcode.writeBits(2, 3);337 try bitcode.writeBits(2, 3);
340 try bitcode.writeVBR(width, 5);338 try bitcode.writeVbr(width, 5);
341 },339 },
342 .char6 => {340 .char6 => {
343 try bitcode.writeBits(0, 1);341 try bitcode.writeBits(0, 1);
...@@ -355,7 +353,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -355,7 +353,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
355 // Fixed or VBR op353 // Fixed or VBR op
356 try bitcode.writeBits(0, 1);354 try bitcode.writeBits(0, 1);
357 try bitcode.writeBits(1, 3);355 try bitcode.writeBits(1, 3);
358 try bitcode.writeVBR(width, 5);356 try bitcode.writeVbr(width, 5);
359 },357 },
360 .array_fixed_runtime => |width_ty| {358 .array_fixed_runtime => |width_ty| {
361 // Array op359 // Array op
...@@ -365,7 +363,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -365,7 +363,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
365 // Fixed or VBR op363 // Fixed or VBR op
366 try bitcode.writeBits(0, 1);364 try bitcode.writeBits(0, 1);
367 try bitcode.writeBits(1, 3);365 try bitcode.writeBits(1, 3);
368 try bitcode.writeVBR(bitcode.getTypeWidth(width_ty), 5);366 try bitcode.writeVbr(bitcode.getTypeWidth(width_ty), 5);
369 },367 },
370 .array_vbr => |width| {368 .array_vbr => |width| {
371 // Array op369 // Array op
...@@ -375,7 +373,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -375,7 +373,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
375 // Fixed or VBR op373 // Fixed or VBR op
376 try bitcode.writeBits(0, 1);374 try bitcode.writeBits(0, 1);
377 try bitcode.writeBits(2, 3);375 try bitcode.writeBits(2, 3);
378 try bitcode.writeVBR(width, 5);376 try bitcode.writeVbr(width, 5);
379 },377 },
380 .array_char6 => {378 .array_char6 => {
381 // Array op379 // Array op
lib/std/zig/llvm/ir.zig+2048-1612
...@@ -21,9 +21,60 @@ const ColumnAbbrev = AbbrevOp{ .vbr = 8 };...@@ -21,9 +21,60 @@ const ColumnAbbrev = AbbrevOp{ .vbr = 8 };
21const BlockAbbrev = AbbrevOp{ .vbr = 6 };21const BlockAbbrev = AbbrevOp{ .vbr = 6 };
22const BlockArrayAbbrev = AbbrevOp{ .array_vbr = 6 };22const BlockArrayAbbrev = AbbrevOp{ .array_vbr = 6 };
2323
24/// All bitcode files can optionally include a BLOCKINFO block, which contains
25/// metadata about other blocks in the file.
26/// The only top-level block types are MODULE, IDENTIFICATION, STRTAB and SYMTAB.
27pub const BlockId = enum(u5) {
28 /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example,
29 /// standard abbrevs that should be available to all blocks of a specified
30 /// ID.
31 BLOCKINFO = 0,
32
33 /// Blocks
34 MODULE = FIRST_APPLICATION,
35
36 /// Module sub-block id's.
37 PARAMATTR,
38 PARAMATTR_GROUP,
39
40 CONSTANTS,
41 FUNCTION,
42
43 /// Block intended to contains information on the bitcode versioning.
44 /// Can be used to provide better error messages when we fail to parse a
45 /// bitcode file.
46 IDENTIFICATION,
47
48 VALUE_SYMTAB,
49 METADATA,
50 METADATA_ATTACHMENT,
51
52 TYPE,
53
54 USELIST,
55
56 MODULE_STRTAB,
57 GLOBALVAL_SUMMARY,
58
59 OPERAND_BUNDLE_TAGS,
60
61 METADATA_KIND,
62
63 STRTAB,
64
65 FULL_LTO_GLOBALVAL_SUMMARY,
66
67 SYMTAB,
68
69 SYNC_SCOPE_NAMES,
70
71 /// Block IDs 1-7 are reserved for future expansion.
72 pub const FIRST_APPLICATION = 8;
73};
74
24/// Unused tags are commented out so that they are omitted in the generated75/// Unused tags are commented out so that they are omitted in the generated
25/// bitcode, which scans over this enum using reflection.76/// bitcode, which scans over this enum using reflection.
26pub const FixedMetadataKind = enum(u8) {77pub const FixedMetadataKind = enum(u6) {
27 dbg = 0,78 dbg = 0,
28 //tbaa = 1,79 //tbaa = 1,
29 prof = 2,80 prof = 2,
...@@ -66,138 +117,79 @@ pub const FixedMetadataKind = enum(u8) {...@@ -66,138 +117,79 @@ pub const FixedMetadataKind = enum(u8) {
66 //@"coro.outside.frame" = 39,117 //@"coro.outside.frame" = 39,
67};118};
68119
69pub const MetadataCode = enum(u8) {120pub const BlockInfoBlock = struct {
70 /// MDSTRING: [values]121 pub const id: BlockId = .BLOCKINFO;
71 STRING_OLD = 1,122
72 /// VALUE: [type num, value num]123 pub const set_block_id = 1;
73 VALUE = 2,124
74 /// NODE: [n x md num]125 pub const abbrevs = [_]type{};
75 NODE = 3,
76 /// STRING: [values]
77 NAME = 4,
78 /// DISTINCT_NODE: [n x md num]
79 DISTINCT_NODE = 5,
80 /// [n x [id, name]]
81 KIND = 6,
82 /// [distinct, line, col, scope, inlined-at?]
83 LOCATION = 7,
84 /// OLD_NODE: [n x (type num, value num)]
85 OLD_NODE = 8,
86 /// OLD_FN_NODE: [n x (type num, value num)]
87 OLD_FN_NODE = 9,
88 /// NAMED_NODE: [n x mdnodes]
89 NAMED_NODE = 10,
90 /// [m x [value, [n x [id, mdnode]]]
91 ATTACHMENT = 11,
92 /// [distinct, tag, vers, header, n x md num]
93 GENERIC_DEBUG = 12,
94 /// [distinct, count, lo]
95 SUBRANGE = 13,
96 /// [isUnsigned|distinct, value, name]
97 ENUMERATOR = 14,
98 /// [distinct, tag, name, size, align, enc]
99 BASIC_TYPE = 15,
100 /// [distinct, filename, directory, checksumkind, checksum]
101 FILE = 16,
102 /// [distinct, ...]
103 DERIVED_TYPE = 17,
104 /// [distinct, ...]
105 COMPOSITE_TYPE = 18,
106 /// [distinct, flags, types, cc]
107 SUBROUTINE_TYPE = 19,
108 /// [distinct, ...]
109 COMPILE_UNIT = 20,
110 /// [distinct, ...]
111 SUBPROGRAM = 21,
112 /// [distinct, scope, file, line, column]
113 LEXICAL_BLOCK = 22,
114 ///[distinct, scope, file, discriminator]
115 LEXICAL_BLOCK_FILE = 23,
116 /// [distinct, scope, file, name, line, exportSymbols]
117 NAMESPACE = 24,
118 /// [distinct, scope, name, type, ...]
119 TEMPLATE_TYPE = 25,
120 /// [distinct, scope, name, type, value, ...]
121 TEMPLATE_VALUE = 26,
122 /// [distinct, ...]
123 GLOBAL_VAR = 27,
124 /// [distinct, ...]
125 LOCAL_VAR = 28,
126 /// [distinct, n x element]
127 EXPRESSION = 29,
128 /// [distinct, name, file, line, ...]
129 OBJC_PROPERTY = 30,
130 /// [distinct, tag, scope, entity, line, name]
131 IMPORTED_ENTITY = 31,
132 /// [distinct, scope, name, ...]
133 MODULE = 32,
134 /// [distinct, macinfo, line, name, value]
135 MACRO = 33,
136 /// [distinct, macinfo, line, file, ...]
137 MACRO_FILE = 34,
138 /// [count, offset] blob([lengths][chars])
139 STRINGS = 35,
140 /// [valueid, n x [id, mdnode]]
141 GLOBAL_DECL_ATTACHMENT = 36,
142 /// [distinct, var, expr]
143 GLOBAL_VAR_EXPR = 37,
144 /// [offset]
145 INDEX_OFFSET = 38,
146 /// [bitpos]
147 INDEX = 39,
148 /// [distinct, scope, name, file, line]
149 LABEL = 40,
150 /// [distinct, name, size, align,...]
151 STRING_TYPE = 41,
152 /// [distinct, scope, name, variable,...]
153 COMMON_BLOCK = 44,
154 /// [distinct, count, lo, up, stride]
155 GENERIC_SUBRANGE = 45,
156 /// [n x [type num, value num]]
157 ARG_LIST = 46,
158 /// [distinct, ...]
159 ASSIGN_ID = 47,
160};126};
161127
162pub const Identification = struct {128/// MODULE blocks have a number of optional fields and subblocks.
163 pub const id = 13;129pub const ModuleBlock = struct {
130 pub const id: BlockId = .MODULE;
164131
165 pub const abbrevs = [_]type{132 pub const abbrevs = [_]type{
166 Version,133 ModuleBlock.Version,
167 Epoch,134 ModuleBlock.String,
135 ModuleBlock.Variable,
136 ModuleBlock.Function,
137 ModuleBlock.Alias,
168 };138 };
169139
170 pub const Version = struct {140 pub const Code = enum(u5) {
171 pub const ops = [_]AbbrevOp{141 /// VERSION: [version#]
172 .{ .literal = 1 },142 VERSION = 1,
173 .{ .array_fixed = 8 },143 /// TRIPLE: [strchr x N]
174 };144 TRIPLE = 2,
175 string: []const u8,145 /// DATALAYOUT: [strchr x N]
176 };146 DATALAYOUT = 3,
147 /// ASM: [strchr x N]
148 ASM = 4,
149 /// SECTIONNAME: [strchr x N]
150 SECTIONNAME = 5,
177151
178 pub const Epoch = struct {152 /// Deprecated, but still needed to read old bitcode files.
179 pub const ops = [_]AbbrevOp{153 /// DEPLIB: [strchr x N]
180 .{ .literal = 2 },154 DEPLIB = 6,
181 .{ .vbr = 6 },
182 };
183 epoch: u32,
184 };
185};
186155
187pub const Module = struct {156 /// GLOBALVAR: [pointer type, isconst, initid,
188 pub const id = 8;157 /// linkage, alignment, section, visibility, threadlocal]
158 GLOBALVAR = 7,
189159
190 pub const abbrevs = [_]type{160 /// FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment,
191 Version,161 /// section, visibility, gc, unnamed_addr]
192 String,162 FUNCTION = 8,
193 Variable,163
194 Function,164 /// ALIAS: [alias type, aliasee val#, linkage, visibility]
195 Alias,165 ALIAS_OLD = 9,
166
167 /// GCNAME: [strchr x N]
168 GCNAME = 11,
169 /// COMDAT: [selection_kind, name]
170 COMDAT = 12,
171
172 /// VSTOFFSET: [offset]
173 VSTOFFSET = 13,
174
175 /// ALIAS: [alias value type, addrspace, aliasee val#, linkage, visibility]
176 ALIAS = 14,
177
178 METADATA_VALUES_UNUSED = 15,
179
180 /// SOURCE_FILENAME: [namechar x N]
181 SOURCE_FILENAME = 16,
182
183 /// HASH: [5*i32]
184 HASH = 17,
185
186 /// IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
187 IFUNC = 18,
196 };188 };
197189
198 pub const Version = struct {190 pub const Version = struct {
199 pub const ops = [_]AbbrevOp{191 pub const ops = [_]AbbrevOp{
200 .{ .literal = 1 },192 .{ .literal = @intFromEnum(ModuleBlock.Code.VERSION) },
201 .{ .literal = 2 },193 .{ .literal = 2 },
202 };194 };
203 };195 };
...@@ -219,7 +211,7 @@ pub const Module = struct {...@@ -219,7 +211,7 @@ pub const Module = struct {
219 };211 };
220212
221 pub const ops = [_]AbbrevOp{213 pub const ops = [_]AbbrevOp{
222 .{ .literal = 7 }, // Code214 .{ .literal = @intFromEnum(ModuleBlock.Code.GLOBALVAR) }, // Code
223 .{ .vbr = 16 }, // strtab_offset215 .{ .vbr = 16 }, // strtab_offset
224 .{ .vbr = 16 }, // strtab_size216 .{ .vbr = 16 }, // strtab_size
225 .{ .fixed_runtime = Builder.Type },217 .{ .fixed_runtime = Builder.Type },
...@@ -255,7 +247,7 @@ pub const Module = struct {...@@ -255,7 +247,7 @@ pub const Module = struct {
255247
256 pub const Function = struct {248 pub const Function = struct {
257 pub const ops = [_]AbbrevOp{249 pub const ops = [_]AbbrevOp{
258 .{ .literal = 8 }, // Code250 .{ .literal = @intFromEnum(ModuleBlock.Code.FUNCTION) }, // Code
259 .{ .vbr = 16 }, // strtab_offset251 .{ .vbr = 16 }, // strtab_offset
260 .{ .vbr = 16 }, // strtab_size252 .{ .vbr = 16 }, // strtab_size
261 .{ .fixed_runtime = Builder.Type },253 .{ .fixed_runtime = Builder.Type },
...@@ -294,7 +286,7 @@ pub const Module = struct {...@@ -294,7 +286,7 @@ pub const Module = struct {
294286
295 pub const Alias = struct {287 pub const Alias = struct {
296 pub const ops = [_]AbbrevOp{288 pub const ops = [_]AbbrevOp{
297 .{ .literal = 14 }, // Code289 .{ .literal = @intFromEnum(ModuleBlock.Code.ALIAS) }, // Code
298 .{ .vbr = 16 }, // strtab_offset290 .{ .vbr = 16 }, // strtab_offset
299 .{ .vbr = 16 }, // strtab_size291 .{ .vbr = 16 }, // strtab_size
300 .{ .fixed_runtime = Builder.Type },292 .{ .fixed_runtime = Builder.Type },
...@@ -319,1542 +311,1986 @@ pub const Module = struct {...@@ -319,1542 +311,1986 @@ pub const Module = struct {
319 unnamed_addr: Builder.UnnamedAddr,311 unnamed_addr: Builder.UnnamedAddr,
320 preemption: Builder.Preemption,312 preemption: Builder.Preemption,
321 };313 };
322};
323
324pub const BlockInfo = struct {
325 pub const id = 0;
326
327 pub const set_block_id = 1;
328
329 pub const abbrevs = [_]type{};
330};
331
332pub const Type = struct {
333 pub const id = 17;
334
335 pub const abbrevs = [_]type{
336 NumEntry,
337 Simple,
338 Opaque,
339 Integer,
340 StructAnon,
341 StructNamed,
342 StructName,
343 Array,
344 Vector,
345 Pointer,
346 Target,
347 Function,
348 };
349
350 pub const NumEntry = struct {
351 pub const ops = [_]AbbrevOp{
352 .{ .literal = 1 },
353 .{ .fixed = 32 },
354 };
355 num: u32,
356 };
357
358 pub const Simple = struct {
359 pub const ops = [_]AbbrevOp{
360 .{ .vbr = 4 },
361 };
362 code: u5,
363 };
364314
365 pub const Opaque = struct {315 /// PARAMATTR blocks have code for defining a parameter attribute set.
366 pub const ops = [_]AbbrevOp{316 pub const ParamattrBlock = struct {
367 .{ .literal = 6 },317 pub const id: BlockId = .PARAMATTR;
368 .{ .literal = 0 },318
369 };319 pub const abbrevs = [_]type{
370 };320 ModuleBlock.ParamattrBlock.Entry,
371321 };
372 pub const Integer = struct {322
373 pub const ops = [_]AbbrevOp{323 pub const Code = enum(u2) {
374 .{ .literal = 7 },324 /// Deprecated, but still needed to read old bitcode files.
375 .{ .fixed = 28 },325 /// ENTRY: [paramidx0, attr0, paramidx1, attr1...]
326 ENTRY_OLD = 1,
327 /// ENTRY: [attrgrp0, attrgrp1, ...]
328 ENTRY = 2,
329 };
330
331 pub const Entry = struct {
332 pub const ops = [_]AbbrevOp{
333 .{ .literal = @intFromEnum(ModuleBlock.ParamattrBlock.Code.ENTRY) },
334 .{ .array_vbr = 8 },
335 };
336 group_indices: []const u64,
337 };
338 };
339
340 pub const ParamattrGroupBlock = struct {
341 pub const id: BlockId = .PARAMATTR_GROUP;
342
343 pub const abbrevs = [_]type{};
344
345 pub const Code = enum(u2) {
346 /// ENTRY: [grpid, idx, attr0, attr1, ...]
347 CODE_ENTRY = 3,
348 };
349 };
350
351 /// The constants block (CONSTANTS_BLOCK_ID) describes emission for each
352 /// constant and maintains an implicit current type value.
353 pub const ConstantsBlock = struct {
354 pub const id: BlockId = .CONSTANTS;
355
356 pub const abbrevs = [_]type{
357 ModuleBlock.ConstantsBlock.SetType,
358 ModuleBlock.ConstantsBlock.Null,
359 ModuleBlock.ConstantsBlock.Undef,
360 ModuleBlock.ConstantsBlock.Poison,
361 ModuleBlock.ConstantsBlock.Integer,
362 ModuleBlock.ConstantsBlock.Half,
363 ModuleBlock.ConstantsBlock.Float,
364 ModuleBlock.ConstantsBlock.Double,
365 ModuleBlock.ConstantsBlock.Fp80,
366 ModuleBlock.ConstantsBlock.Fp128,
367 ModuleBlock.ConstantsBlock.Aggregate,
368 ModuleBlock.ConstantsBlock.String,
369 ModuleBlock.ConstantsBlock.CString,
370 ModuleBlock.ConstantsBlock.Cast,
371 ModuleBlock.ConstantsBlock.Binary,
372 ModuleBlock.ConstantsBlock.Cmp,
373 ModuleBlock.ConstantsBlock.ExtractElement,
374 ModuleBlock.ConstantsBlock.InsertElement,
375 ModuleBlock.ConstantsBlock.ShuffleVector,
376 ModuleBlock.ConstantsBlock.ShuffleVectorEx,
377 ModuleBlock.ConstantsBlock.BlockAddress,
378 ModuleBlock.ConstantsBlock.DsoLocalEquivalentOrNoCfi,
379 };
380
381 pub const Code = enum(u6) {
382 /// SETTYPE: [typeid]
383 SETTYPE = 1,
384 /// NULL
385 NULL = 2,
386 /// UNDEF
387 UNDEF = 3,
388 /// INTEGER: [intval]
389 INTEGER = 4,
390 /// WIDE_INTEGER: [n x intval]
391 WIDE_INTEGER = 5,
392 /// FLOAT: [fpval]
393 FLOAT = 6,
394 /// AGGREGATE: [n x value number]
395 AGGREGATE = 7,
396 /// STRING: [values]
397 STRING = 8,
398 /// CSTRING: [values]
399 CSTRING = 9,
400 /// CE_BINOP: [opcode, opval, opval]
401 CE_BINOP = 10,
402 /// CE_CAST: [opcode, opty, opval]
403 CE_CAST = 11,
404 /// CE_GEP: [n x operands]
405 CE_GEP_OLD = 12,
406 /// CE_SELECT: [opval, opval, opval]
407 CE_SELECT = 13,
408 /// CE_EXTRACTELT: [opty, opval, opval]
409 CE_EXTRACTELT = 14,
410 /// CE_INSERTELT: [opval, opval, opval]
411 CE_INSERTELT = 15,
412 /// CE_SHUFFLEVEC: [opval, opval, opval]
413 CE_SHUFFLEVEC = 16,
414 /// CE_CMP: [opty, opval, opval, pred]
415 CE_CMP = 17,
416 /// INLINEASM: [sideeffect|alignstack,asmstr,conststr]
417 INLINEASM_OLD = 18,
418 /// SHUFVEC_EX: [opty, opval, opval, opval]
419 CE_SHUFVEC_EX = 19,
420 /// INBOUNDS_GEP: [n x operands]
421 CE_INBOUNDS_GEP = 20,
422 /// BLOCKADDRESS: [fnty, fnval, bb#]
423 BLOCKADDRESS = 21,
424 /// DATA: [n x elements]
425 DATA = 22,
426 /// INLINEASM: [sideeffect|alignstack|asmdialect,asmstr,conststr]
427 INLINEASM_OLD2 = 23,
428 /// [opty, flags, n x operands]
429 CE_GEP_WITH_INRANGE_INDEX_OLD = 24,
430 /// CE_UNOP: [opcode, opval]
431 CE_UNOP = 25,
432 /// POISON
433 POISON = 26,
434 /// DSO_LOCAL_EQUIVALENT [gvty, gv]
435 DSO_LOCAL_EQUIVALENT = 27,
436 /// INLINEASM: [sideeffect|alignstack|asmdialect|unwind,asmstr,
437 /// conststr]
438 INLINEASM_OLD3 = 28,
439 /// NO_CFI [ fty, f ]
440 NO_CFI_VALUE = 29,
441 /// INLINEASM: [fnty,sideeffect|alignstack|asmdialect|unwind,
442 /// asmstr,conststr]
443 INLINEASM = 30,
444 /// [opty, flags, range, n x operands]
445 CE_GEP_WITH_INRANGE = 31,
446 /// [opty, flags, n x operands]
447 CE_GEP = 32,
448 /// [ptr, key, disc, addrdisc]
449 PTRAUTH = 33,
450 };
451
452 pub const SetType = struct {
453 pub const ops = [_]AbbrevOp{
454 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.SETTYPE) },
455 .{ .fixed_runtime = Builder.Type },
456 };
457 type_id: Builder.Type,
458 };
459
460 pub const Null = struct {
461 pub const ops = [_]AbbrevOp{
462 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.NULL) },
463 };
464 };
465
466 pub const Undef = struct {
467 pub const ops = [_]AbbrevOp{
468 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.UNDEF) },
469 };
470 };
471
472 pub const Poison = struct {
473 pub const ops = [_]AbbrevOp{
474 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.POISON) },
475 };
476 };
477
478 pub const Integer = struct {
479 pub const ops = [_]AbbrevOp{
480 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.INTEGER) },
481 .{ .vbr = 16 },
482 };
483 value: u64,
484 };
485
486 pub const Half = struct {
487 pub const ops = [_]AbbrevOp{
488 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) },
489 .{ .fixed = 16 },
490 };
491 value: u16,
492 };
493
494 pub const Float = struct {
495 pub const ops = [_]AbbrevOp{
496 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) },
497 .{ .fixed = 32 },
498 };
499 value: u32,
500 };
501
502 pub const Double = struct {
503 pub const ops = [_]AbbrevOp{
504 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) },
505 .{ .vbr = 6 },
506 };
507 value: u64,
508 };
509
510 pub const Fp80 = struct {
511 pub const ops = [_]AbbrevOp{
512 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) },
513 .{ .vbr = 6 },
514 .{ .vbr = 6 },
515 };
516 hi: u64,
517 lo: u16,
518 };
519
520 pub const Fp128 = struct {
521 pub const ops = [_]AbbrevOp{
522 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) },
523 .{ .vbr = 6 },
524 .{ .vbr = 6 },
525 };
526 lo: u64,
527 hi: u64,
528 };
529
530 pub const Aggregate = struct {
531 pub const ops = [_]AbbrevOp{
532 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.AGGREGATE) },
533 .{ .array_fixed = 32 },
534 };
535 values: []const Builder.Constant,
536 };
537
538 pub const String = struct {
539 pub const ops = [_]AbbrevOp{
540 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.STRING) },
541 .{ .array_fixed = 8 },
542 };
543 string: []const u8,
544 };
545
546 pub const CString = struct {
547 pub const ops = [_]AbbrevOp{
548 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CSTRING) },
549 .{ .array_fixed = 8 },
550 };
551 string: []const u8,
552 };
553
554 pub const Cast = struct {
555 const CastOpcode = Builder.CastOpcode;
556 pub const ops = [_]AbbrevOp{
557 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_CAST) },
558 .{ .fixed = @bitSizeOf(CastOpcode) },
559 .{ .fixed_runtime = Builder.Type },
560 ConstantAbbrev,
561 };
562
563 opcode: CastOpcode,
564 type_index: Builder.Type,
565 val: Builder.Constant,
566 };
567
568 pub const Binary = struct {
569 const BinaryOpcode = Builder.BinaryOpcode;
570 pub const ops = [_]AbbrevOp{
571 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_BINOP) },
572 .{ .fixed = @bitSizeOf(BinaryOpcode) },
573 ConstantAbbrev,
574 ConstantAbbrev,
575 };
576
577 opcode: BinaryOpcode,
578 lhs: Builder.Constant,
579 rhs: Builder.Constant,
580 };
581
582 pub const Cmp = struct {
583 pub const ops = [_]AbbrevOp{
584 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_CMP) },
585 .{ .fixed_runtime = Builder.Type },
586 ConstantAbbrev,
587 ConstantAbbrev,
588 .{ .vbr = 6 },
589 };
590
591 ty: Builder.Type,
592 lhs: Builder.Constant,
593 rhs: Builder.Constant,
594 pred: u32,
595 };
596
597 pub const ExtractElement = struct {
598 pub const ops = [_]AbbrevOp{
599 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_EXTRACTELT) },
600 .{ .fixed_runtime = Builder.Type },
601 ConstantAbbrev,
602 .{ .fixed_runtime = Builder.Type },
603 ConstantAbbrev,
604 };
605
606 val_type: Builder.Type,
607 val: Builder.Constant,
608 index_type: Builder.Type,
609 index: Builder.Constant,
610 };
611
612 pub const InsertElement = struct {
613 pub const ops = [_]AbbrevOp{
614 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_INSERTELT) },
615 ConstantAbbrev,
616 ConstantAbbrev,
617 .{ .fixed_runtime = Builder.Type },
618 ConstantAbbrev,
619 };
620
621 val: Builder.Constant,
622 elem: Builder.Constant,
623 index_type: Builder.Type,
624 index: Builder.Constant,
625 };
626
627 pub const ShuffleVector = struct {
628 pub const ops = [_]AbbrevOp{
629 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_SHUFFLEVEC) },
630 ValueAbbrev,
631 ValueAbbrev,
632 ValueAbbrev,
633 };
634
635 lhs: Builder.Constant,
636 rhs: Builder.Constant,
637 mask: Builder.Constant,
638 };
639
640 pub const ShuffleVectorEx = struct {
641 pub const ops = [_]AbbrevOp{
642 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_SHUFVEC_EX) },
643 .{ .fixed_runtime = Builder.Type },
644 ValueAbbrev,
645 ValueAbbrev,
646 ValueAbbrev,
647 };
648
649 ty: Builder.Type,
650 lhs: Builder.Constant,
651 rhs: Builder.Constant,
652 mask: Builder.Constant,
653 };
654
655 pub const BlockAddress = struct {
656 pub const ops = [_]AbbrevOp{
657 .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.BLOCKADDRESS) },
658 .{ .fixed_runtime = Builder.Type },
659 ConstantAbbrev,
660 BlockAbbrev,
661 };
662 type_id: Builder.Type,
663 function: u32,
664 block: u32,
665 };
666
667 pub const DsoLocalEquivalentOrNoCfi = struct {
668 pub const ops = [_]AbbrevOp{
669 .{ .fixed = 5 },
670 .{ .fixed_runtime = Builder.Type },
671 ConstantAbbrev,
672 };
673 code: ModuleBlock.ConstantsBlock.Code,
674 type_id: Builder.Type,
675 function: u32,
676 };
677 };
678
679 /// The function body block (FUNCTION_BLOCK_ID) describes function bodies. It
680 /// can contain a constant block (CONSTANTS_BLOCK_ID).
681 pub const FunctionBlock = struct {
682 pub const id: BlockId = .FUNCTION;
683
684 pub const abbrevs = [_]type{
685 ModuleBlock.FunctionBlock.DeclareBlocks,
686 ModuleBlock.FunctionBlock.Call,
687 ModuleBlock.FunctionBlock.CallFast,
688 ModuleBlock.FunctionBlock.FNeg,
689 ModuleBlock.FunctionBlock.FNegFast,
690 ModuleBlock.FunctionBlock.Binary,
691 ModuleBlock.FunctionBlock.BinaryNoWrap,
692 ModuleBlock.FunctionBlock.BinaryExact,
693 ModuleBlock.FunctionBlock.BinaryFast,
694 ModuleBlock.FunctionBlock.Cmp,
695 ModuleBlock.FunctionBlock.CmpFast,
696 ModuleBlock.FunctionBlock.Select,
697 ModuleBlock.FunctionBlock.SelectFast,
698 ModuleBlock.FunctionBlock.Cast,
699 ModuleBlock.FunctionBlock.Alloca,
700 ModuleBlock.FunctionBlock.GetElementPtr,
701 ModuleBlock.FunctionBlock.ExtractValue,
702 ModuleBlock.FunctionBlock.InsertValue,
703 ModuleBlock.FunctionBlock.ExtractElement,
704 ModuleBlock.FunctionBlock.InsertElement,
705 ModuleBlock.FunctionBlock.ShuffleVector,
706 ModuleBlock.FunctionBlock.RetVoid,
707 ModuleBlock.FunctionBlock.Ret,
708 ModuleBlock.FunctionBlock.Unreachable,
709 ModuleBlock.FunctionBlock.Load,
710 ModuleBlock.FunctionBlock.LoadAtomic,
711 ModuleBlock.FunctionBlock.Store,
712 ModuleBlock.FunctionBlock.StoreAtomic,
713 ModuleBlock.FunctionBlock.BrUnconditional,
714 ModuleBlock.FunctionBlock.BrConditional,
715 ModuleBlock.FunctionBlock.VaArg,
716 ModuleBlock.FunctionBlock.AtomicRmw,
717 ModuleBlock.FunctionBlock.CmpXchg,
718 ModuleBlock.FunctionBlock.Fence,
719 ModuleBlock.FunctionBlock.DebugLoc,
720 ModuleBlock.FunctionBlock.DebugLocAgain,
721 ModuleBlock.FunctionBlock.ColdOperandBundle,
722 ModuleBlock.FunctionBlock.IndirectBr,
723 };
724
725 pub const Code = enum(u7) {
726 /// DECLAREBLOCKS: [n]
727 DECLAREBLOCKS = 1,
728
729 /// BINOP: [opcode, ty, opval, opval]
730 INST_BINOP = 2,
731 /// CAST: [opcode, ty, opty, opval]
732 INST_CAST = 3,
733 /// GEP: [n x operands]
734 INST_GEP_OLD = 4,
735 /// SELECT: [ty, opval, opval, opval]
736 INST_SELECT = 5,
737 /// EXTRACTELT: [opty, opval, opval]
738 INST_EXTRACTELT = 6,
739 /// INSERTELT: [ty, opval, opval, opval]
740 INST_INSERTELT = 7,
741 /// SHUFFLEVEC: [ty, opval, opval, opval]
742 INST_SHUFFLEVEC = 8,
743 /// CMP: [opty, opval, opval, pred]
744 INST_CMP = 9,
745
746 /// RET: [opty,opval<both optional>]
747 INST_RET = 10,
748 /// BR: [bb#, bb#, cond] or [bb#]
749 INST_BR = 11,
750 /// SWITCH: [opty, op0, op1, ...]
751 INST_SWITCH = 12,
752 /// INVOKE: [attr, fnty, op0,op1, ...]
753 INST_INVOKE = 13,
754 /// UNREACHABLE
755 INST_UNREACHABLE = 15,
756
757 /// PHI: [ty, val0,bb0, ...]
758 INST_PHI = 16,
759 /// ALLOCA: [instty, opty, op, align]
760 INST_ALLOCA = 19,
761 /// LOAD: [opty, op, align, vol]
762 INST_LOAD = 20,
763 /// VAARG: [valistty, valist, instty]
764 /// This store code encodes the pointer type, rather than the value type
765 /// this is so information only available in the pointer type (e.g. address
766 /// spaces) is retained.
767 INST_VAARG = 23,
768 /// STORE: [ptrty,ptr,val, align, vol]
769 INST_STORE_OLD = 24,
770
771 /// EXTRACTVAL: [n x operands]
772 INST_EXTRACTVAL = 26,
773 /// INSERTVAL: [n x operands]
774 INST_INSERTVAL = 27,
775 /// fcmp/icmp returning Int1TY or vector of Int1Ty. Same as CMP, exists to
776 /// support legacy vicmp/vfcmp instructions.
777 /// CMP2: [opty, opval, opval, pred]
778 INST_CMP2 = 28,
779 /// new select on i1 or [N x i1]
780 /// VSELECT: [ty,opval,opval,predty,pred]
781 INST_VSELECT = 29,
782 /// INBOUNDS_GEP: [n x operands]
783 INST_INBOUNDS_GEP_OLD = 30,
784 /// INDIRECTBR: [opty, op0, op1, ...]
785 INST_INDIRECTBR = 31,
786
787 /// DEBUG_LOC_AGAIN
788 DEBUG_LOC_AGAIN = 33,
789
790 /// CALL: [attr, cc, fnty, fnid, args...]
791 INST_CALL = 34,
792
793 /// DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
794 DEBUG_LOC = 35,
795 /// FENCE: [ordering, synchscope]
796 INST_FENCE = 36,
797 /// CMPXCHG: [ptrty, ptr, cmp, val, vol,
798 /// ordering, synchscope,
799 /// failure_ordering?, weak?]
800 INST_CMPXCHG_OLD = 37,
801 /// ATOMICRMW: [ptrty,ptr,val, operation,
802 /// align, vol,
803 /// ordering, synchscope]
804 INST_ATOMICRMW_OLD = 38,
805 /// RESUME: [opval]
806 INST_RESUME = 39,
807 /// LANDINGPAD: [ty,val,val,num,id0,val0...]
808 INST_LANDINGPAD_OLD = 40,
809 /// LOAD: [opty, op, align, vol,
810 /// ordering, synchscope]
811 INST_LOADATOMIC = 41,
812 /// STORE: [ptrty,ptr,val, align, vol
813 /// ordering, synchscope]
814 INST_STOREATOMIC_OLD = 42,
815
816 /// GEP: [inbounds, n x operands]
817 INST_GEP = 43,
818 /// STORE: [ptrty,ptr,valty,val, align, vol]
819 INST_STORE = 44,
820 /// STORE: [ptrty,ptr,val, align, vol
821 INST_STOREATOMIC = 45,
822 /// CMPXCHG: [ptrty, ptr, cmp, val, vol,
823 /// success_ordering, synchscope,
824 /// failure_ordering, weak]
825 INST_CMPXCHG = 46,
826 /// LANDINGPAD: [ty,val,num,id0,val0...]
827 INST_LANDINGPAD = 47,
828 /// CLEANUPRET: [val] or [val,bb#]
829 INST_CLEANUPRET = 48,
830 /// CATCHRET: [val,bb#]
831 INST_CATCHRET = 49,
832 /// CATCHPAD: [bb#,bb#,num,args...]
833 INST_CATCHPAD = 50,
834 /// CLEANUPPAD: [num,args...]
835 INST_CLEANUPPAD = 51,
836 /// CATCHSWITCH: [num,args...] or [num,args...,bb]
837 INST_CATCHSWITCH = 52,
838 /// OPERAND_BUNDLE: [tag#, value...]
839 OPERAND_BUNDLE = 55,
840 /// UNOP: [opcode, ty, opval]
841 INST_UNOP = 56,
842 /// CALLBR: [attr, cc, norm, transfs,
843 /// fnty, fnid, args...]
844 INST_CALLBR = 57,
845 /// FREEZE: [opty, opval]
846 INST_FREEZE = 58,
847 /// ATOMICRMW: [ptrty, ptr, valty, val,
848 /// operation, align, vol,
849 /// ordering, synchscope]
850 INST_ATOMICRMW = 59,
851 /// BLOCKADDR_USERS: [value...]
852 BLOCKADDR_USERS = 60,
853
854 /// [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
855 DEBUG_RECORD_VALUE = 61,
856 /// [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
857 DEBUG_RECORD_DECLARE = 62,
858 /// [DILocation, DILocalVariable, DIExpression, ValueAsMetadata,
859 /// DIAssignID, DIExpression (addr), ValueAsMetadata (addr)]
860 DEBUG_RECORD_ASSIGN = 63,
861 /// [DILocation, DILocalVariable, DIExpression, Value]
862 DEBUG_RECORD_VALUE_SIMPLE = 64,
863 /// [DILocation, DILabel]
864 DEBUG_RECORD_LABEL = 65,
865 };
866
867 pub const DeclareBlocks = struct {
868 pub const ops = [_]AbbrevOp{
869 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.DECLAREBLOCKS) },
870 .{ .vbr = 8 },
871 };
872 num_blocks: usize,
873 };
874
875 pub const Call = struct {
876 pub const CallType = packed struct(u17) {
877 tail: bool = false,
878 call_conv: Builder.CallConv,
879 reserved: u3 = 0,
880 must_tail: bool = false,
881 // We always use the explicit type version as that is what LLVM does
882 explicit_type: bool = true,
883 no_tail: bool = false,
884 };
885 pub const ops = [_]AbbrevOp{
886 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CALL) },
887 .{ .fixed_runtime = Builder.FunctionAttributes },
888 .{ .fixed = @bitSizeOf(CallType) },
889 .{ .fixed_runtime = Builder.Type },
890 ValueAbbrev, // Callee
891 ValueArrayAbbrev, // Args
892 };
893
894 attributes: Builder.FunctionAttributes,
895 call_type: CallType,
896 type_id: Builder.Type,
897 callee: Builder.Value,
898 args: []const Builder.Value,
899 };
900
901 pub const CallFast = struct {
902 const CallType = packed struct(u18) {
903 tail: bool = false,
904 call_conv: Builder.CallConv,
905 reserved: u3 = 0,
906 must_tail: bool = false,
907 // We always use the explicit type version as that is what LLVM does
908 explicit_type: bool = true,
909 no_tail: bool = false,
910 fast: bool = true,
911 };
912
913 pub const ops = [_]AbbrevOp{
914 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CALL) },
915 .{ .fixed_runtime = Builder.FunctionAttributes },
916 .{ .fixed = @bitSizeOf(CallType) },
917 .{ .fixed = @bitSizeOf(Builder.FastMath) },
918 .{ .fixed_runtime = Builder.Type },
919 ValueAbbrev, // Callee
920 ValueArrayAbbrev, // Args
921 };
922
923 attributes: Builder.FunctionAttributes,
924 call_type: CallType,
925 fast_math: Builder.FastMath,
926 type_id: Builder.Type,
927 callee: Builder.Value,
928 args: []const Builder.Value,
929 };
930
931 pub const FNeg = struct {
932 pub const ops = [_]AbbrevOp{
933 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_UNOP) },
934 ValueAbbrev,
935 .{ .literal = 0 },
936 };
937
938 val: u32,
939 };
940
941 pub const FNegFast = struct {
942 pub const ops = [_]AbbrevOp{
943 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_UNOP) },
944 ValueAbbrev,
945 .{ .literal = 0 },
946 .{ .fixed = @bitSizeOf(Builder.FastMath) },
947 };
948
949 val: u32,
950 fast_math: Builder.FastMath,
951 };
952
953 pub const Binary = struct {
954 const BinaryOpcode = Builder.BinaryOpcode;
955 pub const ops = [_]AbbrevOp{
956 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BINOP) },
957 ValueAbbrev,
958 ValueAbbrev,
959 .{ .fixed = @bitSizeOf(BinaryOpcode) },
960 };
961
962 lhs: u32,
963 rhs: u32,
964 opcode: BinaryOpcode,
965 };
966
967 pub const BinaryNoWrap = struct {
968 const BinaryOpcode = Builder.BinaryOpcode;
969 pub const ops = [_]AbbrevOp{
970 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BINOP) },
971 ValueAbbrev,
972 ValueAbbrev,
973 .{ .fixed = @bitSizeOf(BinaryOpcode) },
974 .{ .fixed = 2 },
975 };
976
977 lhs: u32,
978 rhs: u32,
979 opcode: BinaryOpcode,
980 flags: packed struct(u2) {
981 no_unsigned_wrap: bool,
982 no_signed_wrap: bool,
983 },
984 };
985
986 pub const BinaryExact = struct {
987 const BinaryOpcode = Builder.BinaryOpcode;
988 pub const ops = [_]AbbrevOp{
989 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BINOP) },
990 ValueAbbrev,
991 ValueAbbrev,
992 .{ .fixed = @bitSizeOf(BinaryOpcode) },
993 .{ .literal = 1 },
994 };
995
996 lhs: u32,
997 rhs: u32,
998 opcode: BinaryOpcode,
999 };
1000
1001 pub const BinaryFast = struct {
1002 const BinaryOpcode = Builder.BinaryOpcode;
1003 pub const ops = [_]AbbrevOp{
1004 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BINOP) },
1005 ValueAbbrev,
1006 ValueAbbrev,
1007 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1008 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1009 };
1010
1011 lhs: u32,
1012 rhs: u32,
1013 opcode: BinaryOpcode,
1014 fast_math: Builder.FastMath,
1015 };
1016
1017 pub const Cmp = struct {
1018 const CmpPredicate = Builder.CmpPredicate;
1019 pub const ops = [_]AbbrevOp{
1020 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CMP2) },
1021 ValueAbbrev,
1022 ValueAbbrev,
1023 .{ .fixed = @bitSizeOf(CmpPredicate) },
1024 };
1025
1026 lhs: u32,
1027 rhs: u32,
1028 pred: CmpPredicate,
1029 };
1030
1031 pub const CmpFast = struct {
1032 const CmpPredicate = Builder.CmpPredicate;
1033 pub const ops = [_]AbbrevOp{
1034 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CMP2) },
1035 ValueAbbrev,
1036 ValueAbbrev,
1037 .{ .fixed = @bitSizeOf(CmpPredicate) },
1038 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1039 };
1040
1041 lhs: u32,
1042 rhs: u32,
1043 pred: CmpPredicate,
1044 fast_math: Builder.FastMath,
1045 };
1046
1047 pub const Select = struct {
1048 pub const ops = [_]AbbrevOp{
1049 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_VSELECT) },
1050 ValueAbbrev,
1051 ValueAbbrev,
1052 ValueAbbrev,
1053 };
1054
1055 lhs: u32,
1056 rhs: u32,
1057 cond: u32,
1058 };
1059
1060 pub const SelectFast = struct {
1061 pub const ops = [_]AbbrevOp{
1062 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_VSELECT) },
1063 ValueAbbrev,
1064 ValueAbbrev,
1065 ValueAbbrev,
1066 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1067 };
1068
1069 lhs: u32,
1070 rhs: u32,
1071 cond: u32,
1072 fast_math: Builder.FastMath,
1073 };
1074
1075 pub const Cast = struct {
1076 const CastOpcode = Builder.CastOpcode;
1077 pub const ops = [_]AbbrevOp{
1078 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CAST) },
1079 ValueAbbrev,
1080 .{ .fixed_runtime = Builder.Type },
1081 .{ .fixed = @bitSizeOf(CastOpcode) },
1082 };
1083
1084 val: u32,
1085 type_index: Builder.Type,
1086 opcode: CastOpcode,
1087 };
1088
1089 pub const Alloca = struct {
1090 pub const Flags = packed struct(u11) {
1091 align_lower: u5,
1092 inalloca: bool,
1093 explicit_type: bool,
1094 swift_error: bool,
1095 align_upper: u3,
1096 };
1097 pub const ops = [_]AbbrevOp{
1098 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_ALLOCA) },
1099 .{ .fixed_runtime = Builder.Type },
1100 .{ .fixed_runtime = Builder.Type },
1101 ValueAbbrev,
1102 .{ .fixed = @bitSizeOf(Flags) },
1103 };
1104
1105 inst_type: Builder.Type,
1106 len_type: Builder.Type,
1107 len_value: u32,
1108 flags: Flags,
1109 };
1110
1111 pub const RetVoid = struct {
1112 pub const ops = [_]AbbrevOp{
1113 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_RET) },
1114 };
1115 };
1116
1117 pub const Ret = struct {
1118 pub const ops = [_]AbbrevOp{
1119 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_RET) },
1120 ValueAbbrev,
1121 };
1122 val: u32,
1123 };
1124
1125 pub const GetElementPtr = struct {
1126 pub const ops = [_]AbbrevOp{
1127 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_GEP) },
1128 .{ .fixed = 1 },
1129 .{ .fixed_runtime = Builder.Type },
1130 ValueAbbrev,
1131 ValueArrayAbbrev,
1132 };
1133
1134 is_inbounds: bool,
1135 type_index: Builder.Type,
1136 base: Builder.Value,
1137 indices: []const Builder.Value,
1138 };
1139
1140 pub const ExtractValue = struct {
1141 pub const ops = [_]AbbrevOp{
1142 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_EXTRACTVAL) },
1143 ValueAbbrev,
1144 ValueArrayAbbrev,
1145 };
1146
1147 val: u32,
1148 indices: []const u32,
1149 };
1150
1151 pub const InsertValue = struct {
1152 pub const ops = [_]AbbrevOp{
1153 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_INSERTVAL) },
1154 ValueAbbrev,
1155 ValueAbbrev,
1156 ValueArrayAbbrev,
1157 };
1158
1159 val: u32,
1160 elem: u32,
1161 indices: []const u32,
1162 };
1163
1164 pub const ExtractElement = struct {
1165 pub const ops = [_]AbbrevOp{
1166 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_EXTRACTELT) },
1167 ValueAbbrev,
1168 ValueAbbrev,
1169 };
1170
1171 val: u32,
1172 index: u32,
1173 };
1174
1175 pub const InsertElement = struct {
1176 pub const ops = [_]AbbrevOp{
1177 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_INSERTELT) },
1178 ValueAbbrev,
1179 ValueAbbrev,
1180 ValueAbbrev,
1181 };
1182
1183 val: u32,
1184 elem: u32,
1185 index: u32,
1186 };
1187
1188 pub const ShuffleVector = struct {
1189 pub const ops = [_]AbbrevOp{
1190 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_SHUFFLEVEC) },
1191 ValueAbbrev,
1192 ValueAbbrev,
1193 ValueAbbrev,
1194 };
1195
1196 lhs: u32,
1197 rhs: u32,
1198 mask: u32,
1199 };
1200
1201 pub const Unreachable = struct {
1202 pub const ops = [_]AbbrevOp{
1203 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_UNREACHABLE) },
1204 };
1205 };
1206
1207 pub const Load = struct {
1208 pub const ops = [_]AbbrevOp{
1209 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_LOAD) },
1210 ValueAbbrev,
1211 .{ .fixed_runtime = Builder.Type },
1212 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1213 .{ .fixed = 1 },
1214 };
1215 ptr: u32,
1216 ty: Builder.Type,
1217 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1218 is_volatile: bool,
1219 };
1220
1221 pub const LoadAtomic = struct {
1222 pub const ops = [_]AbbrevOp{
1223 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_LOADATOMIC) },
1224 ValueAbbrev,
1225 .{ .fixed_runtime = Builder.Type },
1226 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1227 .{ .fixed = 1 },
1228 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1229 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1230 };
1231 ptr: u32,
1232 ty: Builder.Type,
1233 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1234 is_volatile: bool,
1235 success_ordering: Builder.AtomicOrdering,
1236 sync_scope: Builder.SyncScope,
1237 };
1238
1239 pub const Store = struct {
1240 pub const ops = [_]AbbrevOp{
1241 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_STORE) },
1242 ValueAbbrev,
1243 ValueAbbrev,
1244 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1245 .{ .fixed = 1 },
1246 };
1247 ptr: u32,
1248 val: u32,
1249 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1250 is_volatile: bool,
1251 };
1252
1253 pub const StoreAtomic = struct {
1254 pub const ops = [_]AbbrevOp{
1255 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_STOREATOMIC) },
1256 ValueAbbrev,
1257 ValueAbbrev,
1258 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1259 .{ .fixed = 1 },
1260 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1261 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1262 };
1263 ptr: u32,
1264 val: u32,
1265 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1266 is_volatile: bool,
1267 success_ordering: Builder.AtomicOrdering,
1268 sync_scope: Builder.SyncScope,
1269 };
1270
1271 pub const BrUnconditional = struct {
1272 pub const ops = [_]AbbrevOp{
1273 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BR) },
1274 BlockAbbrev,
1275 };
1276 block: u32,
1277 };
1278
1279 pub const BrConditional = struct {
1280 pub const ops = [_]AbbrevOp{
1281 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BR) },
1282 BlockAbbrev,
1283 BlockAbbrev,
1284 BlockAbbrev,
1285 };
1286 then_block: u32,
1287 else_block: u32,
1288 condition: u32,
1289 };
1290
1291 pub const VaArg = struct {
1292 pub const ops = [_]AbbrevOp{
1293 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_VAARG) },
1294 .{ .fixed_runtime = Builder.Type },
1295 ValueAbbrev,
1296 .{ .fixed_runtime = Builder.Type },
1297 };
1298 list_type: Builder.Type,
1299 list: u32,
1300 type: Builder.Type,
1301 };
1302
1303 pub const AtomicRmw = struct {
1304 pub const ops = [_]AbbrevOp{
1305 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_ATOMICRMW) },
1306 ValueAbbrev,
1307 ValueAbbrev,
1308 .{ .fixed = @bitSizeOf(Builder.Function.Instruction.AtomicRmw.Operation) },
1309 .{ .fixed = 1 },
1310 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1311 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1312 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1313 };
1314 ptr: u32,
1315 val: u32,
1316 operation: Builder.Function.Instruction.AtomicRmw.Operation,
1317 is_volatile: bool,
1318 success_ordering: Builder.AtomicOrdering,
1319 sync_scope: Builder.SyncScope,
1320 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1321 };
1322
1323 pub const CmpXchg = struct {
1324 pub const ops = [_]AbbrevOp{
1325 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CMPXCHG) },
1326 ValueAbbrev,
1327 ValueAbbrev,
1328 ValueAbbrev,
1329 .{ .fixed = 1 },
1330 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1331 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1332 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1333 .{ .fixed = 1 },
1334 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1335 };
1336 ptr: u32,
1337 cmp: u32,
1338 new: u32,
1339 is_volatile: bool,
1340 success_ordering: Builder.AtomicOrdering,
1341 sync_scope: Builder.SyncScope,
1342 failure_ordering: Builder.AtomicOrdering,
1343 is_weak: bool,
1344 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1345 };
1346
1347 pub const Fence = struct {
1348 pub const ops = [_]AbbrevOp{
1349 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_FENCE) },
1350 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1351 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1352 };
1353 ordering: Builder.AtomicOrdering,
1354 sync_scope: Builder.SyncScope,
1355 };
1356
1357 pub const DebugLoc = struct {
1358 pub const ops = [_]AbbrevOp{
1359 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.DEBUG_LOC) },
1360 LineAbbrev,
1361 ColumnAbbrev,
1362 MetadataAbbrev,
1363 MetadataAbbrev,
1364 .{ .literal = 0 },
1365 };
1366 line: u32,
1367 column: u32,
1368 scope: Builder.Metadata.Optional,
1369 inlined_at: Builder.Metadata.Optional,
1370 };
1371
1372 pub const DebugLocAgain = struct {
1373 pub const ops = [_]AbbrevOp{
1374 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.DEBUG_LOC_AGAIN) },
1375 };
1376 };
1377
1378 pub const ColdOperandBundle = struct {
1379 pub const ops = [_]AbbrevOp{
1380 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.OPERAND_BUNDLE) },
1381 .{ .literal = 0 },
1382 };
1383 };
1384
1385 pub const IndirectBr = struct {
1386 pub const ops = [_]AbbrevOp{
1387 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_INDIRECTBR) },
1388 .{ .fixed_runtime = Builder.Type },
1389 ValueAbbrev,
1390 BlockArrayAbbrev,
1391 };
1392 ty: Builder.Type,
1393 addr: Builder.Value,
1394 targets: []const Builder.Function.Block.Index,
1395 };
1396
1397 pub const ValueSymtabBlock = struct {
1398 pub const id: BlockId = .VALUE_SYMTAB;
1399
1400 pub const abbrevs = [_]type{
1401 ModuleBlock.FunctionBlock.ValueSymtabBlock.BlockEntry,
1402 };
1403
1404 /// Value symbol table codes.
1405 pub const Code = enum(u3) {
1406 /// VST_ENTRY: [valueid, namechar x N]
1407 ENTRY = 1,
1408 /// VST_BBENTRY: [bbid, namechar x N]
1409 BBENTRY = 2,
1410 /// VST_FNENTRY: [valueid, offset, namechar x N]
1411 FNENTRY = 3,
1412 /// VST_COMBINED_ENTRY: [valueid, refguid]
1413 COMBINED_ENTRY = 5,
1414 };
1415
1416 pub const BlockEntry = struct {
1417 pub const ops = [_]AbbrevOp{
1418 .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.ValueSymtabBlock.Code.BBENTRY) },
1419 ValueAbbrev,
1420 .{ .array_fixed = 8 },
1421 };
1422 value_id: u32,
1423 string: []const u8,
1424 };
1425 };
1426
1427 pub const MetadataBlock = struct {
1428 pub const id: BlockId = .METADATA;
1429
1430 pub const abbrevs = [_]type{
1431 ModuleBlock.FunctionBlock.MetadataBlock.Value,
1432 };
1433
1434 pub const Value = struct {
1435 pub const ops = [_]AbbrevOp{
1436 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.VALUE) },
1437 .{ .fixed = 32 }, // variable
1438 .{ .fixed = 32 }, // expression
1439 };
1440
1441 ty: Builder.Type,
1442 value: Builder.Value,
1443 };
1444 };
1445
1446 pub const MetadataAttachmentBlock = struct {
1447 pub const id: BlockId = .METADATA_ATTACHMENT;
1448
1449 pub const abbrevs = [_]type{
1450 ModuleBlock.FunctionBlock.MetadataAttachmentBlock.AttachmentGlobalSingle,
1451 ModuleBlock.FunctionBlock.MetadataAttachmentBlock.AttachmentInstructionSingle,
1452 };
1453
1454 pub const AttachmentGlobalSingle = struct {
1455 pub const ops = [_]AbbrevOp{
1456 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.ATTACHMENT) },
1457 .{ .fixed = 1 },
1458 MetadataAbbrev,
1459 };
1460 kind: FixedMetadataKind,
1461 metadata: Builder.Metadata,
1462 };
1463
1464 pub const AttachmentInstructionSingle = struct {
1465 pub const ops = [_]AbbrevOp{
1466 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.ATTACHMENT) },
1467 ValueAbbrev,
1468 .{ .fixed = 5 },
1469 MetadataAbbrev,
1470 };
1471 inst: u32,
1472 kind: FixedMetadataKind,
1473 metadata: Builder.Metadata,
1474 };
1475 };
1476 };
1477
1478 pub const MetadataBlock = struct {
1479 pub const id: BlockId = .METADATA;
1480
1481 pub const abbrevs = [_]type{
1482 ModuleBlock.MetadataBlock.Strings,
1483 ModuleBlock.MetadataBlock.File,
1484 ModuleBlock.MetadataBlock.CompileUnit,
1485 ModuleBlock.MetadataBlock.Subprogram,
1486 ModuleBlock.MetadataBlock.LexicalBlock,
1487 ModuleBlock.MetadataBlock.Location,
1488 ModuleBlock.MetadataBlock.BasicType,
1489 ModuleBlock.MetadataBlock.CompositeType,
1490 ModuleBlock.MetadataBlock.DerivedType,
1491 ModuleBlock.MetadataBlock.SubroutineType,
1492 ModuleBlock.MetadataBlock.Enumerator,
1493 ModuleBlock.MetadataBlock.Subrange,
1494 ModuleBlock.MetadataBlock.Expression,
1495 ModuleBlock.MetadataBlock.Node,
1496 ModuleBlock.MetadataBlock.LocalVar,
1497 ModuleBlock.MetadataBlock.Parameter,
1498 ModuleBlock.MetadataBlock.GlobalVar,
1499 ModuleBlock.MetadataBlock.GlobalVarExpression,
1500 ModuleBlock.MetadataBlock.Constant,
1501 ModuleBlock.MetadataBlock.Name,
1502 ModuleBlock.MetadataBlock.NamedNode,
1503 ModuleBlock.MetadataBlock.GlobalDeclAttachment,
1504 };
1505
1506 pub const Code = enum(u6) {
1507 /// MDSTRING: [values]
1508 STRING_OLD = 1,
1509 /// VALUE: [type num, value num]
1510 VALUE = 2,
1511 /// NODE: [n x md num]
1512 NODE = 3,
1513 /// STRING: [values]
1514 NAME = 4,
1515 /// DISTINCT_NODE: [n x md num]
1516 DISTINCT_NODE = 5,
1517 /// [n x [id, name]]
1518 KIND = 6,
1519 /// [distinct, line, col, scope, inlined-at?]
1520 LOCATION = 7,
1521 /// OLD_NODE: [n x (type num, value num)]
1522 OLD_NODE = 8,
1523 /// OLD_FN_NODE: [n x (type num, value num)]
1524 OLD_FN_NODE = 9,
1525 /// NAMED_NODE: [n x mdnodes]
1526 NAMED_NODE = 10,
1527 /// [m x [value, [n x [id, mdnode]]]
1528 ATTACHMENT = 11,
1529 /// [distinct, tag, vers, header, n x md num]
1530 GENERIC_DEBUG = 12,
1531 /// [distinct, count, lo]
1532 SUBRANGE = 13,
1533 /// [isUnsigned|distinct, value, name]
1534 ENUMERATOR = 14,
1535 /// [distinct, tag, name, size, align, enc]
1536 BASIC_TYPE = 15,
1537 /// [distinct, filename, directory, checksumkind, checksum]
1538 FILE = 16,
1539 /// [distinct, ...]
1540 DERIVED_TYPE = 17,
1541 /// [distinct, ...]
1542 COMPOSITE_TYPE = 18,
1543 /// [distinct, flags, types, cc]
1544 SUBROUTINE_TYPE = 19,
1545 /// [distinct, ...]
1546 COMPILE_UNIT = 20,
1547 /// [distinct, ...]
1548 SUBPROGRAM = 21,
1549 /// [distinct, scope, file, line, column]
1550 LEXICAL_BLOCK = 22,
1551 ///[distinct, scope, file, discriminator]
1552 LEXICAL_BLOCK_FILE = 23,
1553 /// [distinct, scope, file, name, line, exportSymbols]
1554 NAMESPACE = 24,
1555 /// [distinct, scope, name, type, ...]
1556 TEMPLATE_TYPE = 25,
1557 /// [distinct, scope, name, type, value, ...]
1558 TEMPLATE_VALUE = 26,
1559 /// [distinct, ...]
1560 GLOBAL_VAR = 27,
1561 /// [distinct, ...]
1562 LOCAL_VAR = 28,
1563 /// [distinct, n x element]
1564 EXPRESSION = 29,
1565 /// [distinct, name, file, line, ...]
1566 OBJC_PROPERTY = 30,
1567 /// [distinct, tag, scope, entity, line, name]
1568 IMPORTED_ENTITY = 31,
1569 /// [distinct, scope, name, ...]
1570 MODULE = 32,
1571 /// [distinct, macinfo, line, name, value]
1572 MACRO = 33,
1573 /// [distinct, macinfo, line, file, ...]
1574 MACRO_FILE = 34,
1575 /// [count, offset] blob([lengths][chars])
1576 STRINGS = 35,
1577 /// [valueid, n x [id, mdnode]]
1578 GLOBAL_DECL_ATTACHMENT = 36,
1579 /// [distinct, var, expr]
1580 GLOBAL_VAR_EXPR = 37,
1581 /// [offset]
1582 INDEX_OFFSET = 38,
1583 /// [bitpos]
1584 INDEX = 39,
1585 /// [distinct, scope, name, file, line]
1586 LABEL = 40,
1587 /// [distinct, name, size, align,...]
1588 STRING_TYPE = 41,
1589 /// [distinct, scope, name, variable,...]
1590 COMMON_BLOCK = 44,
1591 /// [distinct, count, lo, up, stride]
1592 GENERIC_SUBRANGE = 45,
1593 /// [n x [type num, value num]]
1594 ARG_LIST = 46,
1595 /// [distinct, ...]
1596 ASSIGN_ID = 47,
1597 };
1598
1599 pub const Strings = struct {
1600 pub const ops = [_]AbbrevOp{
1601 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.STRINGS) },
1602 .{ .vbr = 6 },
1603 .{ .vbr = 6 },
1604 .blob,
1605 };
1606 num_strings: u32,
1607 strings_offset: u32,
1608 blob: []const u8,
1609 };
1610
1611 pub const File = struct {
1612 pub const ops = [_]AbbrevOp{
1613 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.FILE) },
1614 .{ .literal = 0 }, // is distinct
1615 MetadataAbbrev, // filename
1616 MetadataAbbrev, // directory
1617 .{ .literal = 0 }, // checksum
1618 .{ .literal = 0 }, // checksum
1619 };
1620
1621 filename: Builder.Metadata.String.Optional,
1622 directory: Builder.Metadata.String.Optional,
1623 };
1624
1625 pub const CompileUnit = struct {
1626 pub const ops = [_]AbbrevOp{
1627 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.COMPILE_UNIT) },
1628 .{ .literal = 1 }, // is distinct
1629 .{ .literal = std.dwarf.LANG.C99 }, // source language
1630 MetadataAbbrev, // file
1631 MetadataAbbrev, // producer
1632 .{ .fixed = 1 }, // isOptimized
1633 .{ .literal = 0 }, // raw flags
1634 .{ .literal = 0 }, // runtime version
1635 .{ .literal = 0 }, // split debug file name
1636 .{ .literal = 1 }, // emission kind
1637 MetadataAbbrev, // enums
1638 .{ .literal = 0 }, // retained types
1639 .{ .literal = 0 }, // subprograms
1640 MetadataAbbrev, // globals
1641 .{ .literal = 0 }, // imported entities
1642 .{ .literal = 0 }, // DWO ID
1643 .{ .literal = 0 }, // macros
1644 .{ .literal = 0 }, // split debug inlining
1645 .{ .literal = 0 }, // debug info profiling
1646 .{ .literal = 0 }, // name table kind
1647 .{ .literal = 0 }, // ranges base address
1648 .{ .literal = 0 }, // raw sysroot
1649 .{ .literal = 0 }, // raw SDK
1650 };
1651
1652 file: Builder.Metadata.Optional,
1653 producer: Builder.Metadata.String.Optional,
1654 is_optimized: bool,
1655 enums: Builder.Metadata.Optional,
1656 globals: Builder.Metadata.Optional,
1657 };
1658
1659 pub const Subprogram = struct {
1660 pub const ops = [_]AbbrevOp{
1661 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.SUBPROGRAM) },
1662 .{ .literal = 0b111 }, // is distinct | has sp flags | has flags
1663 MetadataAbbrev, // scope
1664 MetadataAbbrev, // name
1665 MetadataAbbrev, // linkage name
1666 MetadataAbbrev, // file
1667 LineAbbrev, // line
1668 MetadataAbbrev, // type
1669 LineAbbrev, // scope line
1670 .{ .literal = 0 }, // containing type
1671 .{ .fixed = 32 }, // sp flags
1672 .{ .literal = 0 }, // virtual index
1673 .{ .fixed = 32 }, // flags
1674 MetadataAbbrev, // compile unit
1675 .{ .literal = 0 }, // template params
1676 .{ .literal = 0 }, // declaration
1677 .{ .literal = 0 }, // retained nodes
1678 .{ .literal = 0 }, // this adjustment
1679 .{ .literal = 0 }, // thrown types
1680 .{ .literal = 0 }, // annotations
1681 .{ .literal = 0 }, // target function name
1682 };
1683
1684 scope: Builder.Metadata.Optional,
1685 name: Builder.Metadata.String.Optional,
1686 linkage_name: Builder.Metadata.String.Optional,
1687 file: Builder.Metadata.Optional,
1688 line: u32,
1689 ty: Builder.Metadata.Optional,
1690 scope_line: u32,
1691 sp_flags: Builder.Metadata.Subprogram.DISPFlags,
1692 flags: Builder.Metadata.DIFlags,
1693 compile_unit: Builder.Metadata.Optional,
1694 };
1695
1696 pub const LexicalBlock = struct {
1697 pub const ops = [_]AbbrevOp{
1698 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.LEXICAL_BLOCK) },
1699 .{ .literal = 0 }, // is distinct
1700 MetadataAbbrev, // scope
1701 MetadataAbbrev, // file
1702 LineAbbrev, // line
1703 ColumnAbbrev, // column
1704 };
1705
1706 scope: Builder.Metadata.Optional,
1707 file: Builder.Metadata.Optional,
1708 line: u32,
1709 column: u32,
1710 };
1711
1712 pub const Location = struct {
1713 pub const ops = [_]AbbrevOp{
1714 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.LOCATION) },
1715 .{ .literal = 0 }, // is distinct
1716 LineAbbrev, // line
1717 ColumnAbbrev, // column
1718 MetadataAbbrev, // scope
1719 MetadataAbbrev, // inlined at
1720 .{ .literal = 0 }, // is implicit code
1721 };
1722
1723 line: u32,
1724 column: u32,
1725 scope: Builder.Metadata,
1726 inlined_at: Builder.Metadata.Optional,
1727 };
1728
1729 pub const BasicType = struct {
1730 pub const ops = [_]AbbrevOp{
1731 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.BASIC_TYPE) },
1732 .{ .literal = 0 }, // is distinct
1733 .{ .literal = std.dwarf.TAG.base_type }, // tag
1734 MetadataAbbrev, // name
1735 .{ .vbr = 6 }, // size in bits
1736 .{ .literal = 0 }, // align in bits
1737 .{ .vbr = 8 }, // encoding
1738 .{ .literal = 0 }, // flags
1739 };
1740
1741 name: Builder.Metadata.String.Optional,
1742 size_in_bits: u64,
1743 encoding: u32,
1744 };
1745
1746 pub const CompositeType = struct {
1747 pub const ops = [_]AbbrevOp{
1748 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.COMPOSITE_TYPE) },
1749 .{ .literal = 0 | 0x2 }, // is distinct | is not used in old type ref
1750 .{ .fixed = 32 }, // tag
1751 MetadataAbbrev, // name
1752 MetadataAbbrev, // file
1753 LineAbbrev, // line
1754 MetadataAbbrev, // scope
1755 MetadataAbbrev, // underlying type
1756 .{ .vbr = 6 }, // size in bits
1757 .{ .vbr = 6 }, // align in bits
1758 .{ .literal = 0 }, // offset in bits
1759 .{ .fixed = 32 }, // flags
1760 MetadataAbbrev, // elements
1761 .{ .literal = 0 }, // runtime lang
1762 .{ .literal = 0 }, // vtable holder
1763 .{ .literal = 0 }, // template params
1764 .{ .literal = 0 }, // raw id
1765 .{ .literal = 0 }, // discriminator
1766 .{ .literal = 0 }, // data location
1767 .{ .literal = 0 }, // associated
1768 .{ .literal = 0 }, // allocated
1769 .{ .literal = 0 }, // rank
1770 .{ .literal = 0 }, // annotations
1771 };
1772
1773 tag: u32,
1774 name: Builder.Metadata.String.Optional,
1775 file: Builder.Metadata.Optional,
1776 line: u32,
1777 scope: Builder.Metadata.Optional,
1778 underlying_type: Builder.Metadata.Optional,
1779 size_in_bits: u64,
1780 align_in_bits: u64,
1781 flags: Builder.Metadata.DIFlags,
1782 elements: Builder.Metadata.Optional,
1783 };
1784
1785 pub const DerivedType = struct {
1786 pub const ops = [_]AbbrevOp{
1787 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.DERIVED_TYPE) },
1788 .{ .literal = 0 }, // is distinct
1789 .{ .fixed = 32 }, // tag
1790 MetadataAbbrev, // name
1791 MetadataAbbrev, // file
1792 LineAbbrev, // line
1793 MetadataAbbrev, // scope
1794 MetadataAbbrev, // underlying type
1795 .{ .vbr = 6 }, // size in bits
1796 .{ .vbr = 6 }, // align in bits
1797 .{ .vbr = 6 }, // offset in bits
1798 .{ .literal = 0 }, // flags
1799 .{ .literal = 0 }, // extra data
1800 };
1801
1802 tag: u32,
1803 name: Builder.Metadata.String.Optional,
1804 file: Builder.Metadata.Optional,
1805 line: u32,
1806 scope: Builder.Metadata.Optional,
1807 underlying_type: Builder.Metadata.Optional,
1808 size_in_bits: u64,
1809 align_in_bits: u64,
1810 offset_in_bits: u64,
1811 };
1812
1813 pub const SubroutineType = struct {
1814 pub const ops = [_]AbbrevOp{
1815 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.SUBROUTINE_TYPE) },
1816 .{ .literal = 0 | 0x2 }, // is distinct | has no old type refs
1817 .{ .literal = 0 }, // flags
1818 MetadataAbbrev, // types
1819 .{ .literal = 0 }, // cc
1820 };
1821
1822 types: Builder.Metadata.Optional,
1823 };
1824
1825 pub const Enumerator = struct {
1826 pub const Flags = packed struct(u3) {
1827 distinct: bool = false,
1828 unsigned: bool,
1829 bigint: bool = true,
1830 };
1831
1832 pub const ops = [_]AbbrevOp{
1833 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.ENUMERATOR) },
1834 .{ .fixed = @bitSizeOf(Flags) }, // flags
1835 .{ .vbr = 6 }, // bit width
1836 MetadataAbbrev, // name
1837 .{ .vbr = 16 }, // integer value
1838 };
1839
1840 flags: Flags,
1841 bit_width: u32,
1842 name: Builder.Metadata.String.Optional,
1843 value: u64,
1844 };
1845
1846 pub const Subrange = struct {
1847 pub const ops = [_]AbbrevOp{
1848 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.SUBRANGE) },
1849 .{ .literal = 0 | (2 << 1) }, // is distinct | version
1850 MetadataAbbrev, // count
1851 MetadataAbbrev, // lower bound
1852 .{ .literal = 0 }, // upper bound
1853 .{ .literal = 0 }, // stride
1854 };
1855
1856 count: Builder.Metadata.Optional,
1857 lower_bound: Builder.Metadata.Optional,
1858 };
1859
1860 pub const Expression = struct {
1861 pub const ops = [_]AbbrevOp{
1862 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.EXPRESSION) },
1863 .{ .literal = 0 | (3 << 1) }, // is distinct | version
1864 MetadataArrayAbbrev, // elements
1865 };
1866
1867 elements: []const u32,
1868 };
1869
1870 pub const Node = struct {
1871 pub const ops = [_]AbbrevOp{
1872 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.NODE) },
1873 MetadataArrayAbbrev, // elements
1874 };
1875
1876 elements: []const Builder.Metadata.Optional,
1877 };
1878
1879 pub const LocalVar = struct {
1880 pub const ops = [_]AbbrevOp{
1881 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.LOCAL_VAR) },
1882 .{ .literal = 0b10 }, // is distinct | has alignment
1883 MetadataAbbrev, // scope
1884 MetadataAbbrev, // name
1885 MetadataAbbrev, // file
1886 LineAbbrev, // line
1887 MetadataAbbrev, // type
1888 .{ .literal = 0 }, // arg
1889 .{ .literal = 0 }, // flags
1890 .{ .literal = 0 }, // align bits
1891 .{ .literal = 0 }, // annotations
1892 };
1893
1894 scope: Builder.Metadata.Optional,
1895 name: Builder.Metadata.String.Optional,
1896 file: Builder.Metadata.Optional,
1897 line: u32,
1898 ty: Builder.Metadata.Optional,
1899 };
1900
1901 pub const Parameter = struct {
1902 pub const ops = [_]AbbrevOp{
1903 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.LOCAL_VAR) },
1904 .{ .literal = 0b10 }, // is distinct | has alignment
1905 MetadataAbbrev, // scope
1906 MetadataAbbrev, // name
1907 MetadataAbbrev, // file
1908 LineAbbrev, // line
1909 MetadataAbbrev, // type
1910 .{ .vbr = 4 }, // arg
1911 .{ .literal = 0 }, // flags
1912 .{ .literal = 0 }, // align bits
1913 .{ .literal = 0 }, // annotations
1914 };
1915
1916 scope: Builder.Metadata.Optional,
1917 name: Builder.Metadata.String.Optional,
1918 file: Builder.Metadata.Optional,
1919 line: u32,
1920 ty: Builder.Metadata.Optional,
1921 arg: u32,
1922 };
1923
1924 pub const GlobalVar = struct {
1925 pub const ops = [_]AbbrevOp{
1926 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.GLOBAL_VAR) },
1927 .{ .literal = 0b101 }, // is distinct | version
1928 MetadataAbbrev, // scope
1929 MetadataAbbrev, // name
1930 MetadataAbbrev, // linkage name
1931 MetadataAbbrev, // file
1932 LineAbbrev, // line
1933 MetadataAbbrev, // type
1934 .{ .fixed = 1 }, // local
1935 .{ .literal = 1 }, // defined
1936 .{ .literal = 0 }, // static data members declaration
1937 .{ .literal = 0 }, // template params
1938 .{ .literal = 0 }, // align in bits
1939 .{ .literal = 0 }, // annotations
1940 };
1941
1942 scope: Builder.Metadata.Optional,
1943 name: Builder.Metadata.String.Optional,
1944 linkage_name: Builder.Metadata.String.Optional,
1945 file: Builder.Metadata.Optional,
1946 line: u32,
1947 ty: Builder.Metadata.Optional,
1948 local: bool,
1949 };
1950
1951 pub const GlobalVarExpression = struct {
1952 pub const ops = [_]AbbrevOp{
1953 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.GLOBAL_VAR_EXPR) },
1954 .{ .literal = 0 }, // is distinct
1955 MetadataAbbrev, // variable
1956 MetadataAbbrev, // expression
1957 };
1958
1959 variable: Builder.Metadata.Optional,
1960 expression: Builder.Metadata.Optional,
1961 };
1962
1963 pub const Constant = struct {
1964 pub const ops = [_]AbbrevOp{
1965 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.VALUE) },
1966 MetadataAbbrev, // type
1967 MetadataAbbrev, // value
1968 };
1969
1970 ty: Builder.Type,
1971 constant: Builder.Constant,
1972 };
1973
1974 pub const Name = struct {
1975 pub const ops = [_]AbbrevOp{
1976 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.NAME) },
1977 .{ .array_fixed = 8 }, // name
1978 };
1979
1980 name: []const u8,
1981 };
1982
1983 pub const NamedNode = struct {
1984 pub const ops = [_]AbbrevOp{
1985 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.NAMED_NODE) },
1986 MetadataArrayAbbrev, // elements
1987 };
1988
1989 elements: []const Builder.Metadata,
1990 };
1991
1992 pub const GlobalDeclAttachment = struct {
1993 pub const ops = [_]AbbrevOp{
1994 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.GLOBAL_DECL_ATTACHMENT) },
1995 ValueAbbrev, // value id
1996 .{ .fixed = 1 }, // kind
1997 MetadataAbbrev, // elements
1998 };
1999
2000 value: Builder.Constant,
2001 kind: FixedMetadataKind,
2002 metadata: Builder.Metadata,
2003 };
2004 };
2005
2006 /// TYPE blocks have codes for each type primitive they use.
2007 pub const TypeBlock = struct {
2008 pub const id: BlockId = .TYPE;
2009
2010 pub const abbrevs = [_]type{
2011 ModuleBlock.TypeBlock.NumEntry,
2012 ModuleBlock.TypeBlock.Simple,
2013 ModuleBlock.TypeBlock.Opaque,
2014 ModuleBlock.TypeBlock.Integer,
2015 ModuleBlock.TypeBlock.StructAnon,
2016 ModuleBlock.TypeBlock.StructNamed,
2017 ModuleBlock.TypeBlock.StructName,
2018 ModuleBlock.TypeBlock.Array,
2019 ModuleBlock.TypeBlock.Vector,
2020 ModuleBlock.TypeBlock.Pointer,
2021 ModuleBlock.TypeBlock.Target,
2022 ModuleBlock.TypeBlock.Function,
2023 };
2024
2025 pub const Code = enum(u5) {
2026 /// NUMENTRY: [numentries]
2027 NUMENTRY = 1,
2028
2029 // Type Codes
2030 /// VOID
2031 VOID = 2,
2032 /// FLOAT
2033 FLOAT = 3,
2034 /// DOUBLE
2035 DOUBLE = 4,
2036 /// LABEL
2037 LABEL = 5,
2038 /// OPAQUE
2039 OPAQUE = 6,
2040 /// INTEGER: [width]
2041 INTEGER = 7,
2042 /// POINTER: [pointee type]
2043 POINTER = 8,
2044
2045 /// FUNCTION: [vararg, attrid, retty, paramty x N]
2046 FUNCTION_OLD = 9,
2047
2048 /// HALF
2049 HALF = 10,
2050
2051 /// ARRAY: [numelts, eltty]
2052 ARRAY = 11,
2053 /// VECTOR: [numelts, eltty]
2054 VECTOR = 12,
2055
2056 // These are not with the other floating point types because they're
2057 // a late addition, and putting them in the right place breaks
2058 // binary compatibility.
2059 /// X86 LONG DOUBLE
2060 X86_FP80 = 13,
2061 /// LONG DOUBLE (112 bit mantissa)
2062 FP128 = 14,
2063 /// PPC LONG DOUBLE (2 doubles)
2064 PPC_FP128 = 15,
2065
2066 /// METADATA
2067 METADATA = 16,
2068
2069 /// X86 MMX
2070 X86_MMX = 17,
2071
2072 /// STRUCT_ANON: [ispacked, eltty x N]
2073 STRUCT_ANON = 18,
2074 /// STRUCT_NAME: [strchr x N]
2075 STRUCT_NAME = 19,
2076 /// STRUCT_NAMED: [ispacked, eltty x N]
2077 STRUCT_NAMED = 20,
2078
2079 /// FUNCTION: [vararg, retty, paramty x N]
2080 FUNCTION = 21,
2081
2082 /// TOKEN
2083 TOKEN = 22,
2084
2085 /// BRAIN FLOATING POINT
2086 BFLOAT = 23,
2087 /// X86 AMX
2088 X86_AMX = 24,
2089
2090 /// OPAQUE_POINTER: [addrspace]
2091 OPAQUE_POINTER = 25,
2092
2093 /// TARGET_TYPE
2094 TARGET_TYPE = 26,
2095 };
2096
2097 pub const NumEntry = struct {
2098 pub const ops = [_]AbbrevOp{
2099 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.NUMENTRY) },
2100 .{ .fixed = 32 },
2101 };
2102 num: u32,
2103 };
2104
2105 pub const Simple = struct {
2106 pub const ops = [_]AbbrevOp{
2107 .{ .vbr = 4 },
2108 };
2109 code: ModuleBlock.TypeBlock.Code,
2110 };
2111
2112 pub const Opaque = struct {
2113 pub const ops = [_]AbbrevOp{
2114 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.OPAQUE) },
2115 .{ .literal = 0 },
2116 };
2117 };
2118
2119 pub const Integer = struct {
2120 pub const ops = [_]AbbrevOp{
2121 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.INTEGER) },
2122 .{ .fixed = 28 },
2123 };
2124 width: u28,
2125 };
2126
2127 pub const StructAnon = struct {
2128 pub const ops = [_]AbbrevOp{
2129 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.STRUCT_ANON) },
2130 .{ .fixed = 1 },
2131 .{ .array_fixed_runtime = Builder.Type },
2132 };
2133 is_packed: bool,
2134 types: []const Builder.Type,
2135 };
2136
2137 pub const StructNamed = struct {
2138 pub const ops = [_]AbbrevOp{
2139 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.STRUCT_NAMED) },
2140 .{ .fixed = 1 },
2141 .{ .array_fixed_runtime = Builder.Type },
2142 };
2143 is_packed: bool,
2144 types: []const Builder.Type,
2145 };
2146
2147 pub const StructName = struct {
2148 pub const ops = [_]AbbrevOp{
2149 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.STRUCT_NAME) },
2150 .{ .array_fixed = 8 },
2151 };
2152 string: []const u8,
2153 };
2154
2155 pub const Array = struct {
2156 pub const ops = [_]AbbrevOp{
2157 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.ARRAY) },
2158 .{ .vbr = 16 },
2159 .{ .fixed_runtime = Builder.Type },
2160 };
2161 len: u64,
2162 child: Builder.Type,
2163 };
2164
2165 pub const Vector = struct {
2166 pub const ops = [_]AbbrevOp{
2167 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.VECTOR) },
2168 .{ .vbr = 16 },
2169 .{ .fixed_runtime = Builder.Type },
2170 };
2171 len: u64,
2172 child: Builder.Type,
2173 };
2174
2175 pub const Pointer = struct {
2176 pub const ops = [_]AbbrevOp{
2177 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.OPAQUE_POINTER) },
2178 .{ .vbr = 4 },
2179 };
2180 addr_space: Builder.AddrSpace,
376 };2181 };
377 width: u28,
378 };
3792182
380 pub const StructAnon = struct {2183 pub const Target = struct {
381 pub const ops = [_]AbbrevOp{2184 pub const ops = [_]AbbrevOp{
382 .{ .literal = 18 },2185 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.TARGET_TYPE) },
383 .{ .fixed = 1 },2186 .{ .vbr = 4 },
384 .{ .array_fixed_runtime = Builder.Type },2187 .{ .array_fixed_runtime = Builder.Type },
2188 .{ .array_fixed = 32 },
2189 };
2190 num_types: u32,
2191 types: []const Builder.Type,
2192 ints: []const u32,
385 };2193 };
386 is_packed: bool,
387 types: []const Builder.Type,
388 };
3892194
390 pub const StructNamed = struct {2195 pub const Function = struct {
391 pub const ops = [_]AbbrevOp{2196 pub const ops = [_]AbbrevOp{
392 .{ .literal = 20 },2197 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.FUNCTION) },
393 .{ .fixed = 1 },2198 .{ .fixed = 1 },
394 .{ .array_fixed_runtime = Builder.Type },2199 .{ .fixed_runtime = Builder.Type },
2200 .{ .array_fixed_runtime = Builder.Type },
2201 };
2202 is_vararg: bool,
2203 return_type: Builder.Type,
2204 param_types: []const Builder.Type,
395 };2205 };
396 is_packed: bool,
397 types: []const Builder.Type,
398 };2206 };
3992207
400 pub const StructName = struct {2208 pub const OperandBundleTagsBlock = struct {
401 pub const ops = [_]AbbrevOp{2209 pub const id: BlockId = .OPERAND_BUNDLE_TAGS;
402 .{ .literal = 19 },
403 .{ .array_fixed = 8 },
404 };
405 string: []const u8,
406 };
4072210
408 pub const Array = struct {2211 pub const abbrevs = [_]type{
409 pub const ops = [_]AbbrevOp{2212 ModuleBlock.OperandBundleTagsBlock.OperandBundleTag,
410 .{ .literal = 11 },
411 .{ .vbr = 16 },
412 .{ .fixed_runtime = Builder.Type },
413 };2213 };
414 len: u64,
415 child: Builder.Type,
416 };
4172214
418 pub const Vector = struct {2215 pub const Code = enum(u1) {
419 pub const ops = [_]AbbrevOp{2216 /// TAG: [strchr x N]
420 .{ .literal = 12 },2217 OPERAND_BUNDLE_TAG = 1,
421 .{ .vbr = 16 },
422 .{ .fixed_runtime = Builder.Type },
423 };2218 };
424 len: u64,
425 child: Builder.Type,
426 };
4272219
428 pub const Pointer = struct {2220 pub const OperandBundleTag = struct {
429 pub const ops = [_]AbbrevOp{2221 pub const ops = [_]AbbrevOp{
430 .{ .literal = 25 },2222 .{ .literal = @intFromEnum(ModuleBlock.OperandBundleTagsBlock.Code.OPERAND_BUNDLE_TAG) },
431 .{ .vbr = 4 },2223 .array_char6,
2224 };
2225 tag: []const u8,
432 };2226 };
433 addr_space: Builder.AddrSpace,
434 };2227 };
4352228
436 pub const Target = struct {2229 pub const MetadataKindBlock = struct {
437 pub const ops = [_]AbbrevOp{2230 pub const id: BlockId = .METADATA_KIND;
438 .{ .literal = 26 },
439 .{ .vbr = 4 },
440 .{ .array_fixed_runtime = Builder.Type },
441 .{ .array_fixed = 32 },
442 };
443 num_types: u32,
444 types: []const Builder.Type,
445 ints: []const u32,
446 };
4472231
448 pub const Function = struct {2232 pub const abbrevs = [_]type{
449 pub const ops = [_]AbbrevOp{2233 ModuleBlock.MetadataKindBlock.Kind,
450 .{ .literal = 21 },
451 .{ .fixed = 1 },
452 .{ .fixed_runtime = Builder.Type },
453 .{ .array_fixed_runtime = Builder.Type },
454 };2234 };
455 is_vararg: bool,
456 return_type: Builder.Type,
457 param_types: []const Builder.Type,
458 };
459};
460
461pub const Paramattr = struct {
462 pub const id = 9;
463
464 pub const abbrevs = [_]type{
465 Entry,
466 };
4672235
468 pub const Entry = struct {2236 pub const Kind = struct {
469 pub const ops = [_]AbbrevOp{2237 pub const ops = [_]AbbrevOp{
470 .{ .literal = 2 },2238 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.KIND) },
471 .{ .array_vbr = 8 },2239 .{ .vbr = 4 },
2240 .{ .array_fixed = 8 },
2241 };
2242 id: u32,
2243 name: []const u8,
472 };2244 };
473 group_indices: []const u64,
474 };2245 };
475};2246};
4762247
477pub const ParamattrGroup = struct {2248/// Identification block contains a string that describes the producer details,
478 pub const id = 10;2249/// and an epoch that defines the auto-upgrade capability.
4792250pub const IdentificationBlock = struct {
480 pub const abbrevs = [_]type{};2251 pub const id: BlockId = .IDENTIFICATION;
481};
482
483pub const Constants = struct {
484 pub const id = 11;
4852252
486 pub const abbrevs = [_]type{2253 pub const abbrevs = [_]type{
487 SetType,2254 IdentificationBlock.Version,
488 Null,2255 IdentificationBlock.Epoch,
489 Undef,
490 Poison,
491 Integer,
492 Half,
493 Float,
494 Double,
495 Fp80,
496 Fp128,
497 Aggregate,
498 String,
499 CString,
500 Cast,
501 Binary,
502 Cmp,
503 ExtractElement,
504 InsertElement,
505 ShuffleVector,
506 ShuffleVectorEx,
507 BlockAddress,
508 DsoLocalEquivalentOrNoCfi,
509 };
510
511 pub const SetType = struct {
512 pub const ops = [_]AbbrevOp{
513 .{ .literal = 1 },
514 .{ .fixed_runtime = Builder.Type },
515 };
516 type_id: Builder.Type,
517 };
518
519 pub const Null = struct {
520 pub const ops = [_]AbbrevOp{
521 .{ .literal = 2 },
522 };
523 };
524
525 pub const Undef = struct {
526 pub const ops = [_]AbbrevOp{
527 .{ .literal = 3 },
528 };
529 };
530
531 pub const Poison = struct {
532 pub const ops = [_]AbbrevOp{
533 .{ .literal = 26 },
534 };
535 };
536
537 pub const Integer = struct {
538 pub const ops = [_]AbbrevOp{
539 .{ .literal = 4 },
540 .{ .vbr = 16 },
541 };
542 value: u64,
543 };
544
545 pub const Half = struct {
546 pub const ops = [_]AbbrevOp{
547 .{ .literal = 6 },
548 .{ .fixed = 16 },
549 };
550 value: u16,
551 };
552
553 pub const Float = struct {
554 pub const ops = [_]AbbrevOp{
555 .{ .literal = 6 },
556 .{ .fixed = 32 },
557 };
558 value: u32,
559 };
560
561 pub const Double = struct {
562 pub const ops = [_]AbbrevOp{
563 .{ .literal = 6 },
564 .{ .vbr = 6 },
565 };
566 value: u64,
567 };
568
569 pub const Fp80 = struct {
570 pub const ops = [_]AbbrevOp{
571 .{ .literal = 6 },
572 .{ .vbr = 6 },
573 .{ .vbr = 6 },
574 };
575 hi: u64,
576 lo: u16,
577 };
578
579 pub const Fp128 = struct {
580 pub const ops = [_]AbbrevOp{
581 .{ .literal = 6 },
582 .{ .vbr = 6 },
583 .{ .vbr = 6 },
584 };
585 lo: u64,
586 hi: u64,
587 };
588
589 pub const Aggregate = struct {
590 pub const ops = [_]AbbrevOp{
591 .{ .literal = 7 },
592 .{ .array_fixed = 32 },
593 };
594 values: []const Builder.Constant,
595 };2256 };
5962257
597 pub const String = struct {2258 pub const Code = enum(u2) {
598 pub const ops = [_]AbbrevOp{2259 /// IDENTIFICATION: [strchr x N]
599 .{ .literal = 8 },2260 STRING = 1,
600 .{ .array_fixed = 8 },2261 /// EPOCH: [epoch#]
601 };2262 EPOCH = 2,
602 string: []const u8,
603 };2263 };
6042264
605 pub const CString = struct {2265 pub const Version = struct {
606 pub const ops = [_]AbbrevOp{2266 pub const ops = [_]AbbrevOp{
607 .{ .literal = 9 },2267 .{ .literal = @intFromEnum(IdentificationBlock.Code.STRING) },
608 .{ .array_fixed = 8 },2268 .{ .array_fixed = 8 },
609 };2269 };
610 string: []const u8,2270 string: []const u8,
611 };2271 };
6122272
613 pub const Cast = struct {2273 pub const Epoch = struct {
614 const CastOpcode = Builder.CastOpcode;
615 pub const ops = [_]AbbrevOp{
616 .{ .literal = 11 },
617 .{ .fixed = @bitSizeOf(CastOpcode) },
618 .{ .fixed_runtime = Builder.Type },
619 ConstantAbbrev,
620 };
621
622 opcode: CastOpcode,
623 type_index: Builder.Type,
624 val: Builder.Constant,
625 };
626
627 pub const Binary = struct {
628 const BinaryOpcode = Builder.BinaryOpcode;
629 pub const ops = [_]AbbrevOp{
630 .{ .literal = 10 },
631 .{ .fixed = @bitSizeOf(BinaryOpcode) },
632 ConstantAbbrev,
633 ConstantAbbrev,
634 };
635
636 opcode: BinaryOpcode,
637 lhs: Builder.Constant,
638 rhs: Builder.Constant,
639 };
640
641 pub const Cmp = struct {
642 pub const ops = [_]AbbrevOp{2274 pub const ops = [_]AbbrevOp{
643 .{ .literal = 17 },2275 .{ .literal = @intFromEnum(IdentificationBlock.Code.EPOCH) },
644 .{ .fixed_runtime = Builder.Type },
645 ConstantAbbrev,
646 ConstantAbbrev,
647 .{ .vbr = 6 },2276 .{ .vbr = 6 },
648 };2277 };
6492278 epoch: u32,
650 ty: Builder.Type,
651 lhs: Builder.Constant,
652 rhs: Builder.Constant,
653 pred: u32,
654 };
655
656 pub const ExtractElement = struct {
657 pub const ops = [_]AbbrevOp{
658 .{ .literal = 14 },
659 .{ .fixed_runtime = Builder.Type },
660 ConstantAbbrev,
661 .{ .fixed_runtime = Builder.Type },
662 ConstantAbbrev,
663 };
664
665 val_type: Builder.Type,
666 val: Builder.Constant,
667 index_type: Builder.Type,
668 index: Builder.Constant,
669 };
670
671 pub const InsertElement = struct {
672 pub const ops = [_]AbbrevOp{
673 .{ .literal = 15 },
674 ConstantAbbrev,
675 ConstantAbbrev,
676 .{ .fixed_runtime = Builder.Type },
677 ConstantAbbrev,
678 };
679
680 val: Builder.Constant,
681 elem: Builder.Constant,
682 index_type: Builder.Type,
683 index: Builder.Constant,
684 };
685
686 pub const ShuffleVector = struct {
687 pub const ops = [_]AbbrevOp{
688 .{ .literal = 16 },
689 ValueAbbrev,
690 ValueAbbrev,
691 ValueAbbrev,
692 };
693
694 lhs: Builder.Constant,
695 rhs: Builder.Constant,
696 mask: Builder.Constant,
697 };
698
699 pub const ShuffleVectorEx = struct {
700 pub const ops = [_]AbbrevOp{
701 .{ .literal = 19 },
702 .{ .fixed_runtime = Builder.Type },
703 ValueAbbrev,
704 ValueAbbrev,
705 ValueAbbrev,
706 };
707
708 ty: Builder.Type,
709 lhs: Builder.Constant,
710 rhs: Builder.Constant,
711 mask: Builder.Constant,
712 };
713
714 pub const BlockAddress = struct {
715 pub const ops = [_]AbbrevOp{
716 .{ .literal = 21 },
717 .{ .fixed_runtime = Builder.Type },
718 ConstantAbbrev,
719 BlockAbbrev,
720 };
721 type_id: Builder.Type,
722 function: u32,
723 block: u32,
724 };
725
726 pub const DsoLocalEquivalentOrNoCfi = struct {
727 pub const ops = [_]AbbrevOp{
728 .{ .fixed = 5 },
729 .{ .fixed_runtime = Builder.Type },
730 ConstantAbbrev,
731 };
732 code: u5,
733 type_id: Builder.Type,
734 function: u32,
735 };
736};
737
738pub const MetadataKindBlock = struct {
739 pub const id = 22;
740
741 pub const abbrevs = [_]type{
742 Kind,
743 };
744
745 pub const Kind = struct {
746 pub const ops = [_]AbbrevOp{
747 .{ .literal = 6 },
748 .{ .vbr = 4 },
749 .{ .array_fixed = 8 },
750 };
751 id: u32,
752 name: []const u8,
753 };
754};
755
756pub const MetadataAttachmentBlock = struct {
757 pub const id = 16;
758
759 pub const abbrevs = [_]type{
760 AttachmentGlobalSingle,
761 AttachmentInstructionSingle,
762 };
763
764 pub const AttachmentGlobalSingle = struct {
765 pub const ops = [_]AbbrevOp{
766 .{ .literal = @intFromEnum(MetadataCode.ATTACHMENT) },
767 .{ .fixed = 1 },
768 MetadataAbbrev,
769 };
770 kind: FixedMetadataKind,
771 metadata: Builder.Metadata,
772 };
773
774 pub const AttachmentInstructionSingle = struct {
775 pub const ops = [_]AbbrevOp{
776 .{ .literal = @intFromEnum(MetadataCode.ATTACHMENT) },
777 ValueAbbrev,
778 .{ .fixed = 5 },
779 MetadataAbbrev,
780 };
781 inst: u32,
782 kind: FixedMetadataKind,
783 metadata: Builder.Metadata,
784 };2279 };
785};2280};
7862281
787pub const MetadataBlock = struct {2282pub const StrtabBlock = struct {
788 pub const id = 15;2283 pub const id: BlockId = .STRTAB;
789
790 pub const abbrevs = [_]type{
791 Strings,
792 File,
793 CompileUnit,
794 Subprogram,
795 LexicalBlock,
796 Location,
797 BasicType,
798 CompositeType,
799 DerivedType,
800 SubroutineType,
801 Enumerator,
802 Subrange,
803 Expression,
804 Node,
805 LocalVar,
806 Parameter,
807 GlobalVar,
808 GlobalVarExpression,
809 Constant,
810 Name,
811 NamedNode,
812 GlobalDeclAttachment,
813 };
814
815 pub const Strings = struct {
816 pub const ops = [_]AbbrevOp{
817 .{ .literal = @intFromEnum(MetadataCode.STRINGS) },
818 .{ .vbr = 6 },
819 .{ .vbr = 6 },
820 .blob,
821 };
822 num_strings: u32,
823 strings_offset: u32,
824 blob: []const u8,
825 };
826
827 pub const File = struct {
828 pub const ops = [_]AbbrevOp{
829 .{ .literal = @intFromEnum(MetadataCode.FILE) },
830 .{ .literal = 0 }, // is distinct
831 MetadataAbbrev, // filename
832 MetadataAbbrev, // directory
833 .{ .literal = 0 }, // checksum
834 .{ .literal = 0 }, // checksum
835 };
8362284
837 filename: Builder.MetadataString,2285 pub const abbrevs = [_]type{Blob};
838 directory: Builder.MetadataString,
839 };
8402286
841 pub const CompileUnit = struct {2287 pub const Code = enum(u1) {
842 pub const ops = [_]AbbrevOp{2288 BLOB = 1,
843 .{ .literal = @intFromEnum(MetadataCode.COMPILE_UNIT) },
844 .{ .literal = 1 }, // is distinct
845 .{ .literal = std.dwarf.LANG.C99 }, // source language
846 MetadataAbbrev, // file
847 MetadataAbbrev, // producer
848 .{ .fixed = 1 }, // isOptimized
849 .{ .literal = 0 }, // raw flags
850 .{ .literal = 0 }, // runtime version
851 .{ .literal = 0 }, // split debug file name
852 .{ .literal = 1 }, // emission kind
853 MetadataAbbrev, // enums
854 .{ .literal = 0 }, // retained types
855 .{ .literal = 0 }, // subprograms
856 MetadataAbbrev, // globals
857 .{ .literal = 0 }, // imported entities
858 .{ .literal = 0 }, // DWO ID
859 .{ .literal = 0 }, // macros
860 .{ .literal = 0 }, // split debug inlining
861 .{ .literal = 0 }, // debug info profiling
862 .{ .literal = 0 }, // name table kind
863 .{ .literal = 0 }, // ranges base address
864 .{ .literal = 0 }, // raw sysroot
865 .{ .literal = 0 }, // raw SDK
866 };
867
868 file: Builder.Metadata,
869 producer: Builder.MetadataString,
870 is_optimized: bool,
871 enums: Builder.Metadata,
872 globals: Builder.Metadata,
873 };2289 };
8742290
875 pub const Subprogram = struct {
876 pub const ops = [_]AbbrevOp{
877 .{ .literal = @intFromEnum(MetadataCode.SUBPROGRAM) },
878 .{ .literal = 0b111 }, // is distinct | has sp flags | has flags
879 MetadataAbbrev, // scope
880 MetadataAbbrev, // name
881 MetadataAbbrev, // linkage name
882 MetadataAbbrev, // file
883 LineAbbrev, // line
884 MetadataAbbrev, // type
885 LineAbbrev, // scope line
886 .{ .literal = 0 }, // containing type
887 .{ .fixed = 32 }, // sp flags
888 .{ .literal = 0 }, // virtual index
889 .{ .fixed = 32 }, // flags
890 MetadataAbbrev, // compile unit
891 .{ .literal = 0 }, // template params
892 .{ .literal = 0 }, // declaration
893 .{ .literal = 0 }, // retained nodes
894 .{ .literal = 0 }, // this adjustment
895 .{ .literal = 0 }, // thrown types
896 .{ .literal = 0 }, // annotations
897 .{ .literal = 0 }, // target function name
898 };
899
900 scope: Builder.Metadata,
901 name: Builder.MetadataString,
902 linkage_name: Builder.MetadataString,
903 file: Builder.Metadata,
904 line: u32,
905 ty: Builder.Metadata,
906 scope_line: u32,
907 sp_flags: Builder.Metadata.Subprogram.DISPFlags,
908 flags: Builder.Metadata.DIFlags,
909 compile_unit: Builder.Metadata,
910 };
911
912 pub const LexicalBlock = struct {
913 pub const ops = [_]AbbrevOp{
914 .{ .literal = @intFromEnum(MetadataCode.LEXICAL_BLOCK) },
915 .{ .literal = 0 }, // is distinct
916 MetadataAbbrev, // scope
917 MetadataAbbrev, // file
918 LineAbbrev, // line
919 ColumnAbbrev, // column
920 };
921
922 scope: Builder.Metadata,
923 file: Builder.Metadata,
924 line: u32,
925 column: u32,
926 };
927
928 pub const Location = struct {
929 pub const ops = [_]AbbrevOp{
930 .{ .literal = @intFromEnum(MetadataCode.LOCATION) },
931 .{ .literal = 0 }, // is distinct
932 LineAbbrev, // line
933 ColumnAbbrev, // column
934 MetadataAbbrev, // scope
935 MetadataAbbrev, // inlined at
936 .{ .literal = 0 }, // is implicit code
937 };
938
939 line: u32,
940 column: u32,
941 scope: u32,
942 inlined_at: Builder.Metadata,
943 };
944
945 pub const BasicType = struct {
946 pub const ops = [_]AbbrevOp{
947 .{ .literal = @intFromEnum(MetadataCode.BASIC_TYPE) },
948 .{ .literal = 0 }, // is distinct
949 .{ .literal = std.dwarf.TAG.base_type }, // tag
950 MetadataAbbrev, // name
951 .{ .vbr = 6 }, // size in bits
952 .{ .literal = 0 }, // align in bits
953 .{ .vbr = 8 }, // encoding
954 .{ .literal = 0 }, // flags
955 };
956
957 name: Builder.MetadataString,
958 size_in_bits: u64,
959 encoding: u32,
960 };
961
962 pub const CompositeType = struct {
963 pub const ops = [_]AbbrevOp{
964 .{ .literal = @intFromEnum(MetadataCode.COMPOSITE_TYPE) },
965 .{ .literal = 0 | 0x2 }, // is distinct | is not used in old type ref
966 .{ .fixed = 32 }, // tag
967 MetadataAbbrev, // name
968 MetadataAbbrev, // file
969 LineAbbrev, // line
970 MetadataAbbrev, // scope
971 MetadataAbbrev, // underlying type
972 .{ .vbr = 6 }, // size in bits
973 .{ .vbr = 6 }, // align in bits
974 .{ .literal = 0 }, // offset in bits
975 .{ .fixed = 32 }, // flags
976 MetadataAbbrev, // elements
977 .{ .literal = 0 }, // runtime lang
978 .{ .literal = 0 }, // vtable holder
979 .{ .literal = 0 }, // template params
980 .{ .literal = 0 }, // raw id
981 .{ .literal = 0 }, // discriminator
982 .{ .literal = 0 }, // data location
983 .{ .literal = 0 }, // associated
984 .{ .literal = 0 }, // allocated
985 .{ .literal = 0 }, // rank
986 .{ .literal = 0 }, // annotations
987 };
988
989 tag: u32,
990 name: Builder.MetadataString,
991 file: Builder.Metadata,
992 line: u32,
993 scope: Builder.Metadata,
994 underlying_type: Builder.Metadata,
995 size_in_bits: u64,
996 align_in_bits: u64,
997 flags: Builder.Metadata.DIFlags,
998 elements: Builder.Metadata,
999 };
1000
1001 pub const DerivedType = struct {
1002 pub const ops = [_]AbbrevOp{
1003 .{ .literal = @intFromEnum(MetadataCode.DERIVED_TYPE) },
1004 .{ .literal = 0 }, // is distinct
1005 .{ .fixed = 32 }, // tag
1006 MetadataAbbrev, // name
1007 MetadataAbbrev, // file
1008 LineAbbrev, // line
1009 MetadataAbbrev, // scope
1010 MetadataAbbrev, // underlying type
1011 .{ .vbr = 6 }, // size in bits
1012 .{ .vbr = 6 }, // align in bits
1013 .{ .vbr = 6 }, // offset in bits
1014 .{ .literal = 0 }, // flags
1015 .{ .literal = 0 }, // extra data
1016 };
1017
1018 tag: u32,
1019 name: Builder.MetadataString,
1020 file: Builder.Metadata,
1021 line: u32,
1022 scope: Builder.Metadata,
1023 underlying_type: Builder.Metadata,
1024 size_in_bits: u64,
1025 align_in_bits: u64,
1026 offset_in_bits: u64,
1027 };
1028
1029 pub const SubroutineType = struct {
1030 pub const ops = [_]AbbrevOp{
1031 .{ .literal = @intFromEnum(MetadataCode.SUBROUTINE_TYPE) },
1032 .{ .literal = 0 | 0x2 }, // is distinct | has no old type refs
1033 .{ .literal = 0 }, // flags
1034 MetadataAbbrev, // types
1035 .{ .literal = 0 }, // cc
1036 };
1037
1038 types: Builder.Metadata,
1039 };
1040
1041 pub const Enumerator = struct {
1042 pub const id: MetadataCode = .ENUMERATOR;
1043
1044 pub const Flags = packed struct(u3) {
1045 distinct: bool = false,
1046 unsigned: bool,
1047 bigint: bool = true,
1048 };
1049
1050 pub const ops = [_]AbbrevOp{
1051 .{ .literal = @intFromEnum(Enumerator.id) },
1052 .{ .fixed = @bitSizeOf(Flags) }, // flags
1053 .{ .vbr = 6 }, // bit width
1054 MetadataAbbrev, // name
1055 .{ .vbr = 16 }, // integer value
1056 };
1057
1058 flags: Flags,
1059 bit_width: u32,
1060 name: Builder.MetadataString,
1061 value: u64,
1062 };
1063
1064 pub const Subrange = struct {
1065 pub const ops = [_]AbbrevOp{
1066 .{ .literal = @intFromEnum(MetadataCode.SUBRANGE) },
1067 .{ .literal = 0 | (2 << 1) }, // is distinct | version
1068 MetadataAbbrev, // count
1069 MetadataAbbrev, // lower bound
1070 .{ .literal = 0 }, // upper bound
1071 .{ .literal = 0 }, // stride
1072 };
1073
1074 count: Builder.Metadata,
1075 lower_bound: Builder.Metadata,
1076 };
1077
1078 pub const Expression = struct {
1079 pub const ops = [_]AbbrevOp{
1080 .{ .literal = @intFromEnum(MetadataCode.EXPRESSION) },
1081 .{ .literal = 0 | (3 << 1) }, // is distinct | version
1082 MetadataArrayAbbrev, // elements
1083 };
1084
1085 elements: []const u32,
1086 };
1087
1088 pub const Node = struct {
1089 pub const ops = [_]AbbrevOp{
1090 .{ .literal = @intFromEnum(MetadataCode.NODE) },
1091 MetadataArrayAbbrev, // elements
1092 };
1093
1094 elements: []const Builder.Metadata,
1095 };
1096
1097 pub const LocalVar = struct {
1098 pub const ops = [_]AbbrevOp{
1099 .{ .literal = @intFromEnum(MetadataCode.LOCAL_VAR) },
1100 .{ .literal = 0b10 }, // is distinct | has alignment
1101 MetadataAbbrev, // scope
1102 MetadataAbbrev, // name
1103 MetadataAbbrev, // file
1104 LineAbbrev, // line
1105 MetadataAbbrev, // type
1106 .{ .literal = 0 }, // arg
1107 .{ .literal = 0 }, // flags
1108 .{ .literal = 0 }, // align bits
1109 .{ .literal = 0 }, // annotations
1110 };
1111
1112 scope: Builder.Metadata,
1113 name: Builder.MetadataString,
1114 file: Builder.Metadata,
1115 line: u32,
1116 ty: Builder.Metadata,
1117 };
1118
1119 pub const Parameter = struct {
1120 pub const ops = [_]AbbrevOp{
1121 .{ .literal = @intFromEnum(MetadataCode.LOCAL_VAR) },
1122 .{ .literal = 0b10 }, // is distinct | has alignment
1123 MetadataAbbrev, // scope
1124 MetadataAbbrev, // name
1125 MetadataAbbrev, // file
1126 LineAbbrev, // line
1127 MetadataAbbrev, // type
1128 .{ .vbr = 4 }, // arg
1129 .{ .literal = 0 }, // flags
1130 .{ .literal = 0 }, // align bits
1131 .{ .literal = 0 }, // annotations
1132 };
1133
1134 scope: Builder.Metadata,
1135 name: Builder.MetadataString,
1136 file: Builder.Metadata,
1137 line: u32,
1138 ty: Builder.Metadata,
1139 arg: u32,
1140 };
1141
1142 pub const GlobalVar = struct {
1143 pub const ops = [_]AbbrevOp{
1144 .{ .literal = @intFromEnum(MetadataCode.GLOBAL_VAR) },
1145 .{ .literal = 0b101 }, // is distinct | version
1146 MetadataAbbrev, // scope
1147 MetadataAbbrev, // name
1148 MetadataAbbrev, // linkage name
1149 MetadataAbbrev, // file
1150 LineAbbrev, // line
1151 MetadataAbbrev, // type
1152 .{ .fixed = 1 }, // local
1153 .{ .literal = 1 }, // defined
1154 .{ .literal = 0 }, // static data members declaration
1155 .{ .literal = 0 }, // template params
1156 .{ .literal = 0 }, // align in bits
1157 .{ .literal = 0 }, // annotations
1158 };
1159
1160 scope: Builder.Metadata,
1161 name: Builder.MetadataString,
1162 linkage_name: Builder.MetadataString,
1163 file: Builder.Metadata,
1164 line: u32,
1165 ty: Builder.Metadata,
1166 local: bool,
1167 };
1168
1169 pub const GlobalVarExpression = struct {
1170 pub const ops = [_]AbbrevOp{
1171 .{ .literal = @intFromEnum(MetadataCode.GLOBAL_VAR_EXPR) },
1172 .{ .literal = 0 }, // is distinct
1173 MetadataAbbrev, // variable
1174 MetadataAbbrev, // expression
1175 };
1176
1177 variable: Builder.Metadata,
1178 expression: Builder.Metadata,
1179 };
1180
1181 pub const Constant = struct {
1182 pub const ops = [_]AbbrevOp{
1183 .{ .literal = @intFromEnum(MetadataCode.VALUE) },
1184 MetadataAbbrev, // type
1185 MetadataAbbrev, // value
1186 };
1187
1188 ty: Builder.Type,
1189 constant: Builder.Constant,
1190 };
1191
1192 pub const Name = struct {
1193 pub const ops = [_]AbbrevOp{
1194 .{ .literal = @intFromEnum(MetadataCode.NAME) },
1195 .{ .array_fixed = 8 }, // name
1196 };
1197
1198 name: []const u8,
1199 };
1200
1201 pub const NamedNode = struct {
1202 pub const ops = [_]AbbrevOp{
1203 .{ .literal = @intFromEnum(MetadataCode.NAMED_NODE) },
1204 MetadataArrayAbbrev, // elements
1205 };
1206
1207 elements: []const Builder.Metadata,
1208 };
1209
1210 pub const GlobalDeclAttachment = struct {
1211 pub const ops = [_]AbbrevOp{
1212 .{ .literal = @intFromEnum(MetadataCode.GLOBAL_DECL_ATTACHMENT) },
1213 ValueAbbrev, // value id
1214 .{ .fixed = 1 }, // kind
1215 MetadataAbbrev, // elements
1216 };
1217
1218 value: Builder.Constant,
1219 kind: FixedMetadataKind,
1220 metadata: Builder.Metadata,
1221 };
1222};
1223
1224pub const OperandBundleTags = struct {
1225 pub const id = 21;
1226
1227 pub const abbrevs = [_]type{OperandBundleTag};
1228
1229 pub const OperandBundleTag = struct {
1230 pub const ops = [_]AbbrevOp{
1231 .{ .literal = 1 },
1232 .array_char6,
1233 };
1234 tag: []const u8,
1235 };
1236};
1237
1238pub const FunctionMetadataBlock = struct {
1239 pub const id = 15;
1240
1241 pub const abbrevs = [_]type{
1242 Value,
1243 };
1244
1245 pub const Value = struct {
1246 pub const ops = [_]AbbrevOp{
1247 .{ .literal = 2 },
1248 .{ .fixed = 32 }, // variable
1249 .{ .fixed = 32 }, // expression
1250 };
1251
1252 ty: Builder.Type,
1253 value: Builder.Value,
1254 };
1255};
1256
1257pub const FunctionBlock = struct {
1258 pub const id = 12;
1259
1260 pub const abbrevs = [_]type{
1261 DeclareBlocks,
1262 Call,
1263 CallFast,
1264 FNeg,
1265 FNegFast,
1266 Binary,
1267 BinaryNoWrap,
1268 BinaryExact,
1269 BinaryFast,
1270 Cmp,
1271 CmpFast,
1272 Select,
1273 SelectFast,
1274 Cast,
1275 Alloca,
1276 GetElementPtr,
1277 ExtractValue,
1278 InsertValue,
1279 ExtractElement,
1280 InsertElement,
1281 ShuffleVector,
1282 RetVoid,
1283 Ret,
1284 Unreachable,
1285 Load,
1286 LoadAtomic,
1287 Store,
1288 StoreAtomic,
1289 BrUnconditional,
1290 BrConditional,
1291 VaArg,
1292 AtomicRmw,
1293 CmpXchg,
1294 Fence,
1295 DebugLoc,
1296 DebugLocAgain,
1297 ColdOperandBundle,
1298 IndirectBr,
1299 };
1300
1301 pub const DeclareBlocks = struct {
1302 pub const ops = [_]AbbrevOp{
1303 .{ .literal = 1 },
1304 .{ .vbr = 8 },
1305 };
1306 num_blocks: usize,
1307 };
1308
1309 pub const Call = struct {
1310 pub const CallType = packed struct(u17) {
1311 tail: bool = false,
1312 call_conv: Builder.CallConv,
1313 reserved: u3 = 0,
1314 must_tail: bool = false,
1315 // We always use the explicit type version as that is what LLVM does
1316 explicit_type: bool = true,
1317 no_tail: bool = false,
1318 };
1319 pub const ops = [_]AbbrevOp{
1320 .{ .literal = 34 },
1321 .{ .fixed_runtime = Builder.FunctionAttributes },
1322 .{ .fixed = @bitSizeOf(CallType) },
1323 .{ .fixed_runtime = Builder.Type },
1324 ValueAbbrev, // Callee
1325 ValueArrayAbbrev, // Args
1326 };
1327
1328 attributes: Builder.FunctionAttributes,
1329 call_type: CallType,
1330 type_id: Builder.Type,
1331 callee: Builder.Value,
1332 args: []const Builder.Value,
1333 };
1334
1335 pub const CallFast = struct {
1336 const CallType = packed struct(u18) {
1337 tail: bool = false,
1338 call_conv: Builder.CallConv,
1339 reserved: u3 = 0,
1340 must_tail: bool = false,
1341 // We always use the explicit type version as that is what LLVM does
1342 explicit_type: bool = true,
1343 no_tail: bool = false,
1344 fast: bool = true,
1345 };
1346
1347 pub const ops = [_]AbbrevOp{
1348 .{ .literal = 34 },
1349 .{ .fixed_runtime = Builder.FunctionAttributes },
1350 .{ .fixed = @bitSizeOf(CallType) },
1351 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1352 .{ .fixed_runtime = Builder.Type },
1353 ValueAbbrev, // Callee
1354 ValueArrayAbbrev, // Args
1355 };
1356
1357 attributes: Builder.FunctionAttributes,
1358 call_type: CallType,
1359 fast_math: Builder.FastMath,
1360 type_id: Builder.Type,
1361 callee: Builder.Value,
1362 args: []const Builder.Value,
1363 };
1364
1365 pub const FNeg = struct {
1366 pub const ops = [_]AbbrevOp{
1367 .{ .literal = 56 },
1368 ValueAbbrev,
1369 .{ .literal = 0 },
1370 };
1371
1372 val: u32,
1373 };
1374
1375 pub const FNegFast = struct {
1376 pub const ops = [_]AbbrevOp{
1377 .{ .literal = 56 },
1378 ValueAbbrev,
1379 .{ .literal = 0 },
1380 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1381 };
1382
1383 val: u32,
1384 fast_math: Builder.FastMath,
1385 };
1386
1387 pub const Binary = struct {
1388 const BinaryOpcode = Builder.BinaryOpcode;
1389 pub const ops = [_]AbbrevOp{
1390 .{ .literal = 2 },
1391 ValueAbbrev,
1392 ValueAbbrev,
1393 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1394 };
1395
1396 lhs: u32,
1397 rhs: u32,
1398 opcode: BinaryOpcode,
1399 };
1400
1401 pub const BinaryNoWrap = struct {
1402 const BinaryOpcode = Builder.BinaryOpcode;
1403 pub const ops = [_]AbbrevOp{
1404 .{ .literal = 2 },
1405 ValueAbbrev,
1406 ValueAbbrev,
1407 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1408 .{ .fixed = 2 },
1409 };
1410
1411 lhs: u32,
1412 rhs: u32,
1413 opcode: BinaryOpcode,
1414 flags: packed struct(u2) {
1415 no_unsigned_wrap: bool,
1416 no_signed_wrap: bool,
1417 },
1418 };
1419
1420 pub const BinaryExact = struct {
1421 const BinaryOpcode = Builder.BinaryOpcode;
1422 pub const ops = [_]AbbrevOp{
1423 .{ .literal = 2 },
1424 ValueAbbrev,
1425 ValueAbbrev,
1426 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1427 .{ .literal = 1 },
1428 };
1429
1430 lhs: u32,
1431 rhs: u32,
1432 opcode: BinaryOpcode,
1433 };
1434
1435 pub const BinaryFast = struct {
1436 const BinaryOpcode = Builder.BinaryOpcode;
1437 pub const ops = [_]AbbrevOp{
1438 .{ .literal = 2 },
1439 ValueAbbrev,
1440 ValueAbbrev,
1441 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1442 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1443 };
1444
1445 lhs: u32,
1446 rhs: u32,
1447 opcode: BinaryOpcode,
1448 fast_math: Builder.FastMath,
1449 };
1450
1451 pub const Cmp = struct {
1452 const CmpPredicate = Builder.CmpPredicate;
1453 pub const ops = [_]AbbrevOp{
1454 .{ .literal = 28 },
1455 ValueAbbrev,
1456 ValueAbbrev,
1457 .{ .fixed = @bitSizeOf(CmpPredicate) },
1458 };
1459
1460 lhs: u32,
1461 rhs: u32,
1462 pred: CmpPredicate,
1463 };
1464
1465 pub const CmpFast = struct {
1466 const CmpPredicate = Builder.CmpPredicate;
1467 pub const ops = [_]AbbrevOp{
1468 .{ .literal = 28 },
1469 ValueAbbrev,
1470 ValueAbbrev,
1471 .{ .fixed = @bitSizeOf(CmpPredicate) },
1472 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1473 };
1474
1475 lhs: u32,
1476 rhs: u32,
1477 pred: CmpPredicate,
1478 fast_math: Builder.FastMath,
1479 };
1480
1481 pub const Select = struct {
1482 pub const ops = [_]AbbrevOp{
1483 .{ .literal = 29 },
1484 ValueAbbrev,
1485 ValueAbbrev,
1486 ValueAbbrev,
1487 };
1488
1489 lhs: u32,
1490 rhs: u32,
1491 cond: u32,
1492 };
1493
1494 pub const SelectFast = struct {
1495 pub const ops = [_]AbbrevOp{
1496 .{ .literal = 29 },
1497 ValueAbbrev,
1498 ValueAbbrev,
1499 ValueAbbrev,
1500 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1501 };
1502
1503 lhs: u32,
1504 rhs: u32,
1505 cond: u32,
1506 fast_math: Builder.FastMath,
1507 };
1508
1509 pub const Cast = struct {
1510 const CastOpcode = Builder.CastOpcode;
1511 pub const ops = [_]AbbrevOp{
1512 .{ .literal = 3 },
1513 ValueAbbrev,
1514 .{ .fixed_runtime = Builder.Type },
1515 .{ .fixed = @bitSizeOf(CastOpcode) },
1516 };
1517
1518 val: u32,
1519 type_index: Builder.Type,
1520 opcode: CastOpcode,
1521 };
1522
1523 pub const Alloca = struct {
1524 pub const Flags = packed struct(u11) {
1525 align_lower: u5,
1526 inalloca: bool,
1527 explicit_type: bool,
1528 swift_error: bool,
1529 align_upper: u3,
1530 };
1531 pub const ops = [_]AbbrevOp{
1532 .{ .literal = 19 },
1533 .{ .fixed_runtime = Builder.Type },
1534 .{ .fixed_runtime = Builder.Type },
1535 ValueAbbrev,
1536 .{ .fixed = @bitSizeOf(Flags) },
1537 };
1538
1539 inst_type: Builder.Type,
1540 len_type: Builder.Type,
1541 len_value: u32,
1542 flags: Flags,
1543 };
1544
1545 pub const RetVoid = struct {
1546 pub const ops = [_]AbbrevOp{
1547 .{ .literal = 10 },
1548 };
1549 };
1550
1551 pub const Ret = struct {
1552 pub const ops = [_]AbbrevOp{
1553 .{ .literal = 10 },
1554 ValueAbbrev,
1555 };
1556 val: u32,
1557 };
1558
1559 pub const GetElementPtr = struct {
1560 pub const ops = [_]AbbrevOp{
1561 .{ .literal = 43 },
1562 .{ .fixed = 1 },
1563 .{ .fixed_runtime = Builder.Type },
1564 ValueAbbrev,
1565 ValueArrayAbbrev,
1566 };
1567
1568 is_inbounds: bool,
1569 type_index: Builder.Type,
1570 base: Builder.Value,
1571 indices: []const Builder.Value,
1572 };
1573
1574 pub const ExtractValue = struct {
1575 pub const ops = [_]AbbrevOp{
1576 .{ .literal = 26 },
1577 ValueAbbrev,
1578 ValueArrayAbbrev,
1579 };
1580
1581 val: u32,
1582 indices: []const u32,
1583 };
1584
1585 pub const InsertValue = struct {
1586 pub const ops = [_]AbbrevOp{
1587 .{ .literal = 27 },
1588 ValueAbbrev,
1589 ValueAbbrev,
1590 ValueArrayAbbrev,
1591 };
1592
1593 val: u32,
1594 elem: u32,
1595 indices: []const u32,
1596 };
1597
1598 pub const ExtractElement = struct {
1599 pub const ops = [_]AbbrevOp{
1600 .{ .literal = 6 },
1601 ValueAbbrev,
1602 ValueAbbrev,
1603 };
1604
1605 val: u32,
1606 index: u32,
1607 };
1608
1609 pub const InsertElement = struct {
1610 pub const ops = [_]AbbrevOp{
1611 .{ .literal = 7 },
1612 ValueAbbrev,
1613 ValueAbbrev,
1614 ValueAbbrev,
1615 };
1616
1617 val: u32,
1618 elem: u32,
1619 index: u32,
1620 };
1621
1622 pub const ShuffleVector = struct {
1623 pub const ops = [_]AbbrevOp{
1624 .{ .literal = 8 },
1625 ValueAbbrev,
1626 ValueAbbrev,
1627 ValueAbbrev,
1628 };
1629
1630 lhs: u32,
1631 rhs: u32,
1632 mask: u32,
1633 };
1634
1635 pub const Unreachable = struct {
1636 pub const ops = [_]AbbrevOp{
1637 .{ .literal = 15 },
1638 };
1639 };
1640
1641 pub const Load = struct {
1642 pub const ops = [_]AbbrevOp{
1643 .{ .literal = 20 },
1644 ValueAbbrev,
1645 .{ .fixed_runtime = Builder.Type },
1646 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1647 .{ .fixed = 1 },
1648 };
1649 ptr: u32,
1650 ty: Builder.Type,
1651 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1652 is_volatile: bool,
1653 };
1654
1655 pub const LoadAtomic = struct {
1656 pub const ops = [_]AbbrevOp{
1657 .{ .literal = 41 },
1658 ValueAbbrev,
1659 .{ .fixed_runtime = Builder.Type },
1660 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1661 .{ .fixed = 1 },
1662 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1663 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1664 };
1665 ptr: u32,
1666 ty: Builder.Type,
1667 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1668 is_volatile: bool,
1669 success_ordering: Builder.AtomicOrdering,
1670 sync_scope: Builder.SyncScope,
1671 };
1672
1673 pub const Store = struct {
1674 pub const ops = [_]AbbrevOp{
1675 .{ .literal = 44 },
1676 ValueAbbrev,
1677 ValueAbbrev,
1678 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1679 .{ .fixed = 1 },
1680 };
1681 ptr: u32,
1682 val: u32,
1683 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1684 is_volatile: bool,
1685 };
1686
1687 pub const StoreAtomic = struct {
1688 pub const ops = [_]AbbrevOp{
1689 .{ .literal = 45 },
1690 ValueAbbrev,
1691 ValueAbbrev,
1692 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1693 .{ .fixed = 1 },
1694 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1695 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1696 };
1697 ptr: u32,
1698 val: u32,
1699 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1700 is_volatile: bool,
1701 success_ordering: Builder.AtomicOrdering,
1702 sync_scope: Builder.SyncScope,
1703 };
1704
1705 pub const BrUnconditional = struct {
1706 pub const ops = [_]AbbrevOp{
1707 .{ .literal = 11 },
1708 BlockAbbrev,
1709 };
1710 block: u32,
1711 };
1712
1713 pub const BrConditional = struct {
1714 pub const ops = [_]AbbrevOp{
1715 .{ .literal = 11 },
1716 BlockAbbrev,
1717 BlockAbbrev,
1718 BlockAbbrev,
1719 };
1720 then_block: u32,
1721 else_block: u32,
1722 condition: u32,
1723 };
1724
1725 pub const VaArg = struct {
1726 pub const ops = [_]AbbrevOp{
1727 .{ .literal = 23 },
1728 .{ .fixed_runtime = Builder.Type },
1729 ValueAbbrev,
1730 .{ .fixed_runtime = Builder.Type },
1731 };
1732 list_type: Builder.Type,
1733 list: u32,
1734 type: Builder.Type,
1735 };
1736
1737 pub const AtomicRmw = struct {
1738 pub const ops = [_]AbbrevOp{
1739 .{ .literal = 59 },
1740 ValueAbbrev,
1741 ValueAbbrev,
1742 .{ .fixed = @bitSizeOf(Builder.Function.Instruction.AtomicRmw.Operation) },
1743 .{ .fixed = 1 },
1744 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1745 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1746 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1747 };
1748 ptr: u32,
1749 val: u32,
1750 operation: Builder.Function.Instruction.AtomicRmw.Operation,
1751 is_volatile: bool,
1752 success_ordering: Builder.AtomicOrdering,
1753 sync_scope: Builder.SyncScope,
1754 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1755 };
1756
1757 pub const CmpXchg = struct {
1758 pub const ops = [_]AbbrevOp{
1759 .{ .literal = 46 },
1760 ValueAbbrev,
1761 ValueAbbrev,
1762 ValueAbbrev,
1763 .{ .fixed = 1 },
1764 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1765 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1766 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1767 .{ .fixed = 1 },
1768 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1769 };
1770 ptr: u32,
1771 cmp: u32,
1772 new: u32,
1773 is_volatile: bool,
1774 success_ordering: Builder.AtomicOrdering,
1775 sync_scope: Builder.SyncScope,
1776 failure_ordering: Builder.AtomicOrdering,
1777 is_weak: bool,
1778 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1779 };
1780
1781 pub const Fence = struct {
1782 pub const ops = [_]AbbrevOp{
1783 .{ .literal = 36 },
1784 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1785 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1786 };
1787 ordering: Builder.AtomicOrdering,
1788 sync_scope: Builder.SyncScope,
1789 };
1790
1791 pub const DebugLoc = struct {
1792 pub const ops = [_]AbbrevOp{
1793 .{ .literal = 35 },
1794 LineAbbrev,
1795 ColumnAbbrev,
1796 MetadataAbbrev,
1797 MetadataAbbrev,
1798 .{ .literal = 0 },
1799 };
1800 line: u32,
1801 column: u32,
1802 scope: Builder.Metadata,
1803 inlined_at: Builder.Metadata,
1804 };
1805
1806 pub const DebugLocAgain = struct {
1807 pub const ops = [_]AbbrevOp{
1808 .{ .literal = 33 },
1809 };
1810 };
1811
1812 pub const ColdOperandBundle = struct {
1813 pub const ops = [_]AbbrevOp{
1814 .{ .literal = 55 },
1815 .{ .literal = 0 },
1816 };
1817 };
1818
1819 pub const IndirectBr = struct {
1820 pub const ops = [_]AbbrevOp{
1821 .{ .literal = 31 },
1822 .{ .fixed_runtime = Builder.Type },
1823 ValueAbbrev,
1824 BlockArrayAbbrev,
1825 };
1826 ty: Builder.Type,
1827 addr: Builder.Value,
1828 targets: []const Builder.Function.Block.Index,
1829 };
1830};
1831
1832pub const FunctionValueSymbolTable = struct {
1833 pub const id = 14;
1834
1835 pub const abbrevs = [_]type{
1836 BlockEntry,
1837 };
1838
1839 pub const BlockEntry = struct {
1840 pub const ops = [_]AbbrevOp{
1841 .{ .literal = 2 },
1842 ValueAbbrev,
1843 .{ .array_fixed = 8 },
1844 };
1845 value_id: u32,
1846 string: []const u8,
1847 };
1848};
1849
1850pub const Strtab = struct {
1851 pub const id = 23;
1852
1853 pub const abbrevs = [_]type{Blob};
1854
1855 pub const Blob = struct {2291 pub const Blob = struct {
1856 pub const ops = [_]AbbrevOp{2292 pub const ops = [_]AbbrevOp{
1857 .{ .literal = 1 },2293 .{ .literal = @intFromEnum(StrtabBlock.Code.BLOB) },
1858 .blob,2294 .blob,
1859 };2295 };
1860 blob: []const u8,2296 blob: []const u8,
src/codegen/llvm.zig+182-197
...@@ -508,16 +508,16 @@ pub const Object = struct {...@@ -508,16 +508,16 @@ pub const Object = struct {
508 gpa: Allocator,508 gpa: Allocator,
509 builder: Builder,509 builder: Builder,
510510
511 debug_compile_unit: Builder.Metadata,511 debug_compile_unit: Builder.Metadata.Optional,
512512
513 debug_enums_fwd_ref: Builder.Metadata,513 debug_enums_fwd_ref: Builder.Metadata.Optional,
514 debug_globals_fwd_ref: Builder.Metadata,514 debug_globals_fwd_ref: Builder.Metadata.Optional,
515515
516 debug_enums: std.ArrayListUnmanaged(Builder.Metadata),516 debug_enums: std.ArrayListUnmanaged(Builder.Metadata),
517 debug_globals: std.ArrayListUnmanaged(Builder.Metadata),517 debug_globals: std.ArrayListUnmanaged(Builder.Metadata),
518518
519 debug_file_map: std.AutoHashMapUnmanaged(Zcu.File.Index, Builder.Metadata),519 debug_file_map: std.AutoHashMapUnmanaged(Zcu.File.Index, Builder.Metadata),
520 debug_type_map: std.AutoHashMapUnmanaged(Type, Builder.Metadata),520 debug_type_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Metadata),
521521
522 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata),522 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata),
523523
...@@ -630,9 +630,13 @@ pub const Object = struct {...@@ -630,9 +630,13 @@ pub const Object = struct {
630 .{ .optimized = comp.root_mod.optimize_mode != .Debug },630 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
631 );631 );
632632
633 try builder.metadataNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});633 try builder.addNamedMetadata(try builder.string("llvm.dbg.cu"), &.{debug_compile_unit});
634 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };634 break :debug_info .{
635 } else .{.none} ** 3;635 debug_compile_unit.toOptional(),
636 debug_enums_fwd_ref.toOptional(),
637 debug_globals_fwd_ref.toOptional(),
638 };
639 } else .{Builder.Metadata.Optional.none} ** 3;
636640
637 const obj = try arena.create(Object);641 const obj = try arena.create(Object);
638 obj.* = .{642 obj.* = .{
...@@ -816,17 +820,17 @@ pub const Object = struct {...@@ -816,17 +820,17 @@ pub const Object = struct {
816 const namespace = zcu.namespacePtr(namespace_index);820 const namespace = zcu.namespacePtr(namespace_index);
817 const debug_type = try o.lowerDebugType(pt, Type.fromInterned(namespace.owner_type));821 const debug_type = try o.lowerDebugType(pt, Type.fromInterned(namespace.owner_type));
818822
819 o.builder.debugForwardReferenceSetType(fwd_ref, debug_type);823 o.builder.resolveDebugForwardReference(fwd_ref, debug_type);
820 }824 }
821 }825 }
822826
823 o.builder.debugForwardReferenceSetType(827 o.builder.resolveDebugForwardReference(
824 o.debug_enums_fwd_ref,828 o.debug_enums_fwd_ref.unwrap().?,
825 try o.builder.metadataTuple(o.debug_enums.items),829 try o.builder.metadataTuple(o.debug_enums.items),
826 );830 );
827831
828 o.builder.debugForwardReferenceSetType(832 o.builder.resolveDebugForwardReference(
829 o.debug_globals_fwd_ref,833 o.debug_globals_fwd_ref.unwrap().?,
830 try o.builder.metadataTuple(o.debug_globals.items),834 try o.builder.metadataTuple(o.debug_globals.items),
831 );835 );
832 }836 }
...@@ -842,36 +846,34 @@ pub const Object = struct {...@@ -842,36 +846,34 @@ pub const Object = struct {
842 const behavior_min = try o.builder.metadataConstant(try o.builder.intConst(.i32, 8));846 const behavior_min = try o.builder.metadataConstant(try o.builder.intConst(.i32, 8));
843847
844 if (target_util.llvmMachineAbi(&comp.root_mod.resolved_target.result)) |abi| {848 if (target_util.llvmMachineAbi(&comp.root_mod.resolved_target.result)) |abi| {
845 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(849 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
846 behavior_error,850 behavior_error,
847 try o.builder.metadataString("target-abi"),851 (try o.builder.metadataString("target-abi")).toMetadata(),
848 try o.builder.metadataConstant(852 (try o.builder.metadataString(abi)).toMetadata(),
849 try o.builder.stringConst(try o.builder.string(abi)),853 }));
850 ),
851 ));
852 }854 }
853855
854 const pic_level = target_util.picLevel(&comp.root_mod.resolved_target.result);856 const pic_level = target_util.picLevel(&comp.root_mod.resolved_target.result);
855 if (comp.root_mod.pic) {857 if (comp.root_mod.pic) {
856 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(858 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
857 behavior_min,859 behavior_min,
858 try o.builder.metadataString("PIC Level"),860 (try o.builder.metadataString("PIC Level")).toMetadata(),
859 try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)),861 try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)),
860 ));862 }));
861 }863 }
862864
863 if (comp.config.pie) {865 if (comp.config.pie) {
864 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(866 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
865 behavior_max,867 behavior_max,
866 try o.builder.metadataString("PIE Level"),868 (try o.builder.metadataString("PIE Level")).toMetadata(),
867 try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)),869 try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)),
868 ));870 }));
869 }871 }
870872
871 if (comp.root_mod.code_model != .default) {873 if (comp.root_mod.code_model != .default) {
872 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(874 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
873 behavior_error,875 behavior_error,
874 try o.builder.metadataString("Code Model"),876 (try o.builder.metadataString("Code Model")).toMetadata(),
875 try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(877 try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(
876 i32,878 i32,
877 switch (codeModel(comp.root_mod.code_model, &comp.root_mod.resolved_target.result)) {879 switch (codeModel(comp.root_mod.code_model, &comp.root_mod.resolved_target.result)) {
...@@ -883,39 +885,39 @@ pub const Object = struct {...@@ -883,39 +885,39 @@ pub const Object = struct {
883 .large => 4,885 .large => 4,
884 },886 },
885 ))),887 ))),
886 ));888 }));
887 }889 }
888890
889 if (!o.builder.strip) {891 if (!o.builder.strip) {
890 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(892 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
891 behavior_warning,893 behavior_warning,
892 try o.builder.metadataString("Debug Info Version"),894 (try o.builder.metadataString("Debug Info Version")).toMetadata(),
893 try o.builder.metadataConstant(try o.builder.intConst(.i32, 3)),895 try o.builder.metadataConstant(try o.builder.intConst(.i32, 3)),
894 ));896 }));
895897
896 switch (comp.config.debug_format) {898 switch (comp.config.debug_format) {
897 .strip => unreachable,899 .strip => unreachable,
898 .dwarf => |f| {900 .dwarf => |f| {
899 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(901 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
900 behavior_max,902 behavior_max,
901 try o.builder.metadataString("Dwarf Version"),903 (try o.builder.metadataString("Dwarf Version")).toMetadata(),
902 try o.builder.metadataConstant(try o.builder.intConst(.i32, 4)),904 try o.builder.metadataConstant(try o.builder.intConst(.i32, 4)),
903 ));905 }));
904906
905 if (f == .@"64") {907 if (f == .@"64") {
906 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(908 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
907 behavior_max,909 behavior_max,
908 try o.builder.metadataString("DWARF64"),910 (try o.builder.metadataString("DWARF64")).toMetadata(),
909 try o.builder.metadataConstant(.@"1"),911 try o.builder.metadataConstant(.@"1"),
910 ));912 }));
911 }913 }
912 },914 },
913 .code_view => {915 .code_view => {
914 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(916 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
915 behavior_warning,917 behavior_warning,
916 try o.builder.metadataString("CodeView"),918 (try o.builder.metadataString("CodeView")).toMetadata(),
917 try o.builder.metadataConstant(.@"1"),919 try o.builder.metadataConstant(.@"1"),
918 ));920 }));
919 },921 },
920 }922 }
921 }923 }
...@@ -925,14 +927,14 @@ pub const Object = struct {...@@ -925,14 +927,14 @@ pub const Object = struct {
925 // Add the "RegCallv4" flag so that any functions using `x86_regcallcc` use regcall927 // Add the "RegCallv4" flag so that any functions using `x86_regcallcc` use regcall
926 // v4, which is essentially a requirement on Windows. See corresponding logic in928 // v4, which is essentially a requirement on Windows. See corresponding logic in
927 // `toLlvmCallConvTag`.929 // `toLlvmCallConvTag`.
928 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(930 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
929 behavior_max,931 behavior_max,
930 try o.builder.metadataString("RegCallv4"),932 (try o.builder.metadataString("RegCallv4")).toMetadata(),
931 try o.builder.metadataConstant(.@"1"),933 try o.builder.metadataConstant(.@"1"),
932 ));934 }));
933 }935 }
934936
935 try o.builder.metadataNamed(try o.builder.metadataString("llvm.module.flags"), module_flags.items);937 try o.builder.addNamedMetadata(try o.builder.string("llvm.module.flags"), module_flags.items);
936 }938 }
937939
938 const target_triple_sentinel =940 const target_triple_sentinel =
...@@ -1477,11 +1479,11 @@ pub const Object = struct {...@@ -1477,11 +1479,11 @@ pub const Object = struct {
1477 .LocalToUnit = is_internal_linkage,1479 .LocalToUnit = is_internal_linkage,
1478 },1480 },
1479 },1481 },
1480 o.debug_compile_unit,1482 o.debug_compile_unit.unwrap().?,
1481 );1483 );
1482 function_index.setSubprogram(subprogram, &o.builder);1484 function_index.setSubprogram(subprogram, &o.builder);
1483 break :debug_info .{ file, subprogram };1485 break :debug_info .{ file, subprogram };
1484 } else .{.none} ** 2;1486 } else .{undefined} ** 2;
14851487
1486 const fuzz: ?FuncGen.Fuzz = f: {1488 const fuzz: ?FuncGen.Fuzz = f: {
1487 if (!owner_mod.fuzz) break :f null;1489 if (!owner_mod.fuzz) break :f null;
...@@ -1807,7 +1809,7 @@ pub const Object = struct {...@@ -1807,7 +1809,7 @@ pub const Object = struct {
1807 const zcu = pt.zcu;1809 const zcu = pt.zcu;
1808 const ip = &zcu.intern_pool;1810 const ip = &zcu.intern_pool;
18091811
1810 if (o.debug_type_map.get(ty)) |debug_type| return debug_type;1812 if (o.debug_type_map.get(ty.toIntern())) |debug_type| return debug_type;
18111813
1812 switch (ty.zigTypeTag(zcu)) {1814 switch (ty.zigTypeTag(zcu)) {
1813 .void,1815 .void,
...@@ -1817,7 +1819,7 @@ pub const Object = struct {...@@ -1817,7 +1819,7 @@ pub const Object = struct {
1817 try o.builder.metadataString("void"),1819 try o.builder.metadataString("void"),
1818 0,1820 0,
1819 );1821 );
1820 try o.debug_type_map.put(gpa, ty, debug_void_type);1822 try o.debug_type_map.put(gpa, ty.toIntern(), debug_void_type);
1821 return debug_void_type;1823 return debug_void_type;
1822 },1824 },
1823 .int => {1825 .int => {
...@@ -1831,13 +1833,13 @@ pub const Object = struct {...@@ -1831,13 +1833,13 @@ pub const Object = struct {
1831 .signed => try o.builder.debugSignedType(builder_name, debug_bits),1833 .signed => try o.builder.debugSignedType(builder_name, debug_bits),
1832 .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits),1834 .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits),
1833 };1835 };
1834 try o.debug_type_map.put(gpa, ty, debug_int_type);1836 try o.debug_type_map.put(gpa, ty.toIntern(), debug_int_type);
1835 return debug_int_type;1837 return debug_int_type;
1836 },1838 },
1837 .@"enum" => {1839 .@"enum" => {
1838 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {1840 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1839 const debug_enum_type = try o.makeEmptyNamespaceDebugType(pt, ty);1841 const debug_enum_type = try o.makeEmptyNamespaceDebugType(pt, ty);
1840 try o.debug_type_map.put(gpa, ty, debug_enum_type);1842 try o.debug_type_map.put(gpa, ty.toIntern(), debug_enum_type);
1841 return debug_enum_type;1843 return debug_enum_type;
1842 }1844 }
18431845
...@@ -1884,7 +1886,7 @@ pub const Object = struct {...@@ -1884,7 +1886,7 @@ pub const Object = struct {
1884 try o.builder.metadataTuple(enumerators),1886 try o.builder.metadataTuple(enumerators),
1885 );1887 );
18861888
1887 try o.debug_type_map.put(gpa, ty, debug_enum_type);1889 try o.debug_type_map.put(gpa, ty.toIntern(), debug_enum_type);
1888 try o.debug_enums.append(gpa, debug_enum_type);1890 try o.debug_enums.append(gpa, debug_enum_type);
1889 return debug_enum_type;1891 return debug_enum_type;
1890 },1892 },
...@@ -1896,7 +1898,7 @@ pub const Object = struct {...@@ -1896,7 +1898,7 @@ pub const Object = struct {
1896 try o.builder.metadataString(name),1898 try o.builder.metadataString(name),
1897 bits,1899 bits,
1898 );1900 );
1899 try o.debug_type_map.put(gpa, ty, debug_float_type);1901 try o.debug_type_map.put(gpa, ty.toIntern(), debug_float_type);
1900 return debug_float_type;1902 return debug_float_type;
1901 },1903 },
1902 .bool => {1904 .bool => {
...@@ -1904,7 +1906,7 @@ pub const Object = struct {...@@ -1904,7 +1906,7 @@ pub const Object = struct {
1904 try o.builder.metadataString("bool"),1906 try o.builder.metadataString("bool"),
1905 8, // lldb cannot handle non-byte sized types1907 8, // lldb cannot handle non-byte sized types
1906 );1908 );
1907 try o.debug_type_map.put(gpa, ty, debug_bool_type);1909 try o.debug_type_map.put(gpa, ty.toIntern(), debug_bool_type);
1908 return debug_bool_type;1910 return debug_bool_type;
1909 },1911 },
1910 .pointer => {1912 .pointer => {
...@@ -1936,14 +1938,14 @@ pub const Object = struct {...@@ -1936,14 +1938,14 @@ pub const Object = struct {
1936 },1938 },
1937 });1939 });
1938 const debug_ptr_type = try o.lowerDebugType(pt, bland_ptr_ty);1940 const debug_ptr_type = try o.lowerDebugType(pt, bland_ptr_ty);
1939 try o.debug_type_map.put(gpa, ty, debug_ptr_type);1941 try o.debug_type_map.put(gpa, ty.toIntern(), debug_ptr_type);
1940 return debug_ptr_type;1942 return debug_ptr_type;
1941 }1943 }
19421944
1943 const debug_fwd_ref = try o.builder.debugForwardReference();1945 const debug_fwd_ref = try o.builder.debugForwardReference();
19441946
1945 // Set as forward reference while the type is lowered in case it references itself1947 // Set as forward reference while the type is lowered in case it references itself
1946 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);1948 try o.debug_type_map.put(gpa, ty.toIntern(), debug_fwd_ref);
19471949
1948 if (ty.isSlice(zcu)) {1950 if (ty.isSlice(zcu)) {
1949 const ptr_ty = ty.slicePtrFieldType(zcu);1951 const ptr_ty = ty.slicePtrFieldType(zcu);
...@@ -1962,7 +1964,7 @@ pub const Object = struct {...@@ -1962,7 +1964,7 @@ pub const Object = struct {
19621964
1963 const debug_ptr_type = try o.builder.debugMemberType(1965 const debug_ptr_type = try o.builder.debugMemberType(
1964 try o.builder.metadataString("ptr"),1966 try o.builder.metadataString("ptr"),
1965 .none, // File1967 null, // File
1966 debug_fwd_ref,1968 debug_fwd_ref,
1967 0, // Line1969 0, // Line
1968 try o.lowerDebugType(pt, ptr_ty),1970 try o.lowerDebugType(pt, ptr_ty),
...@@ -1973,7 +1975,7 @@ pub const Object = struct {...@@ -1973,7 +1975,7 @@ pub const Object = struct {
19731975
1974 const debug_len_type = try o.builder.debugMemberType(1976 const debug_len_type = try o.builder.debugMemberType(
1975 try o.builder.metadataString("len"),1977 try o.builder.metadataString("len"),
1976 .none, // File1978 null, // File
1977 debug_fwd_ref,1979 debug_fwd_ref,
1978 0, // Line1980 0, // Line
1979 try o.lowerDebugType(pt, len_ty),1981 try o.lowerDebugType(pt, len_ty),
...@@ -1984,10 +1986,10 @@ pub const Object = struct {...@@ -1984,10 +1986,10 @@ pub const Object = struct {
19841986
1985 const debug_slice_type = try o.builder.debugStructType(1987 const debug_slice_type = try o.builder.debugStructType(
1986 try o.builder.metadataString(name),1988 try o.builder.metadataString(name),
1987 .none, // File1989 null, // File
1988 o.debug_compile_unit, // Scope1990 o.debug_compile_unit.unwrap().?, // Scope
1989 line,1991 line,
1990 .none, // Underlying type1992 null, // Underlying type
1991 ty.abiSize(zcu) * 8,1993 ty.abiSize(zcu) * 8,
1992 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,1994 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
1993 try o.builder.metadataTuple(&.{1995 try o.builder.metadataTuple(&.{
...@@ -1996,10 +1998,10 @@ pub const Object = struct {...@@ -1996,10 +1998,10 @@ pub const Object = struct {
1996 }),1998 }),
1997 );1999 );
19982000
1999 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type);2001 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_slice_type);
20002002
2001 // Set to real type now that it has been lowered fully2003 // Set to real type now that it has been lowered fully
2002 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2004 const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable;
2003 map_ptr.* = debug_slice_type;2005 map_ptr.* = debug_slice_type;
20042006
2005 return debug_slice_type;2007 return debug_slice_type;
...@@ -2012,8 +2014,8 @@ pub const Object = struct {...@@ -2012,8 +2014,8 @@ pub const Object = struct {
20122014
2013 const debug_ptr_type = try o.builder.debugPointerType(2015 const debug_ptr_type = try o.builder.debugPointerType(
2014 try o.builder.metadataString(name),2016 try o.builder.metadataString(name),
2015 .none, // File2017 null, // File
2016 .none, // Scope2018 null, // Scope
2017 0, // Line2019 0, // Line
2018 debug_elem_ty,2020 debug_elem_ty,
2019 target.ptrBitWidth(),2021 target.ptrBitWidth(),
...@@ -2021,10 +2023,10 @@ pub const Object = struct {...@@ -2021,10 +2023,10 @@ pub const Object = struct {
2021 0, // Offset2023 0, // Offset
2022 );2024 );
20232025
2024 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_ptr_type);2026 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_ptr_type);
20252027
2026 // Set to real type now that it has been lowered fully2028 // Set to real type now that it has been lowered fully
2027 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2029 const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable;
2028 map_ptr.* = debug_ptr_type;2030 map_ptr.* = debug_ptr_type;
20292031
2030 return debug_ptr_type;2032 return debug_ptr_type;
...@@ -2035,7 +2037,7 @@ pub const Object = struct {...@@ -2035,7 +2037,7 @@ pub const Object = struct {
2035 try o.builder.metadataString("anyopaque"),2037 try o.builder.metadataString("anyopaque"),
2036 0,2038 0,
2037 );2039 );
2038 try o.debug_type_map.put(gpa, ty, debug_opaque_type);2040 try o.debug_type_map.put(gpa, ty.toIntern(), debug_opaque_type);
2039 return debug_opaque_type;2041 return debug_opaque_type;
2040 }2042 }
20412043
...@@ -2053,19 +2055,19 @@ pub const Object = struct {...@@ -2053,19 +2055,19 @@ pub const Object = struct {
2053 file,2055 file,
2054 scope,2056 scope,
2055 ty.typeDeclSrcLine(zcu).? + 1, // Line2057 ty.typeDeclSrcLine(zcu).? + 1, // Line
2056 .none, // Underlying type2058 null, // Underlying type
2057 0, // Size2059 0, // Size
2058 0, // Align2060 0, // Align
2059 .none, // Fields2061 null, // Fields
2060 );2062 );
2061 try o.debug_type_map.put(gpa, ty, debug_opaque_type);2063 try o.debug_type_map.put(gpa, ty.toIntern(), debug_opaque_type);
2062 return debug_opaque_type;2064 return debug_opaque_type;
2063 },2065 },
2064 .array => {2066 .array => {
2065 const debug_array_type = try o.builder.debugArrayType(2067 const debug_array_type = try o.builder.debugArrayType(
2066 .none, // Name2068 null, // Name
2067 .none, // File2069 null, // File
2068 .none, // Scope2070 null, // Scope
2069 0, // Line2071 0, // Line
2070 try o.lowerDebugType(pt, ty.childType(zcu)),2072 try o.lowerDebugType(pt, ty.childType(zcu)),
2071 ty.abiSize(zcu) * 8,2073 ty.abiSize(zcu) * 8,
...@@ -2077,7 +2079,7 @@ pub const Object = struct {...@@ -2077,7 +2079,7 @@ pub const Object = struct {
2077 ),2079 ),
2078 }),2080 }),
2079 );2081 );
2080 try o.debug_type_map.put(gpa, ty, debug_array_type);2082 try o.debug_type_map.put(gpa, ty.toIntern(), debug_array_type);
2081 return debug_array_type;2083 return debug_array_type;
2082 },2084 },
2083 .vector => {2085 .vector => {
...@@ -2106,9 +2108,9 @@ pub const Object = struct {...@@ -2106,9 +2108,9 @@ pub const Object = struct {
2106 };2108 };
21072109
2108 const debug_vector_type = try o.builder.debugVectorType(2110 const debug_vector_type = try o.builder.debugVectorType(
2109 .none, // Name2111 null, // Name
2110 .none, // File2112 null, // File
2111 .none, // Scope2113 null, // Scope
2112 0, // Line2114 0, // Line
2113 debug_elem_type,2115 debug_elem_type,
2114 ty.abiSize(zcu) * 8,2116 ty.abiSize(zcu) * 8,
...@@ -2121,7 +2123,7 @@ pub const Object = struct {...@@ -2121,7 +2123,7 @@ pub const Object = struct {
2121 }),2123 }),
2122 );2124 );
21232125
2124 try o.debug_type_map.put(gpa, ty, debug_vector_type);2126 try o.debug_type_map.put(gpa, ty.toIntern(), debug_vector_type);
2125 return debug_vector_type;2127 return debug_vector_type;
2126 },2128 },
2127 .optional => {2129 .optional => {
...@@ -2133,22 +2135,22 @@ pub const Object = struct {...@@ -2133,22 +2135,22 @@ pub const Object = struct {
2133 try o.builder.metadataString(name),2135 try o.builder.metadataString(name),
2134 8,2136 8,
2135 );2137 );
2136 try o.debug_type_map.put(gpa, ty, debug_bool_type);2138 try o.debug_type_map.put(gpa, ty.toIntern(), debug_bool_type);
2137 return debug_bool_type;2139 return debug_bool_type;
2138 }2140 }
21392141
2140 const debug_fwd_ref = try o.builder.debugForwardReference();2142 const debug_fwd_ref = try o.builder.debugForwardReference();
21412143
2142 // Set as forward reference while the type is lowered in case it references itself2144 // Set as forward reference while the type is lowered in case it references itself
2143 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);2145 try o.debug_type_map.put(gpa, ty.toIntern(), debug_fwd_ref);
21442146
2145 if (ty.optionalReprIsPayload(zcu)) {2147 if (ty.optionalReprIsPayload(zcu)) {
2146 const debug_optional_type = try o.lowerDebugType(pt, child_ty);2148 const debug_optional_type = try o.lowerDebugType(pt, child_ty);
21472149
2148 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);2150 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_optional_type);
21492151
2150 // Set to real type now that it has been lowered fully2152 // Set to real type now that it has been lowered fully
2151 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2153 const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable;
2152 map_ptr.* = debug_optional_type;2154 map_ptr.* = debug_optional_type;
21532155
2154 return debug_optional_type;2156 return debug_optional_type;
...@@ -2163,7 +2165,7 @@ pub const Object = struct {...@@ -2163,7 +2165,7 @@ pub const Object = struct {
21632165
2164 const debug_data_type = try o.builder.debugMemberType(2166 const debug_data_type = try o.builder.debugMemberType(
2165 try o.builder.metadataString("data"),2167 try o.builder.metadataString("data"),
2166 .none, // File2168 null, // File
2167 debug_fwd_ref,2169 debug_fwd_ref,
2168 0, // Line2170 0, // Line
2169 try o.lowerDebugType(pt, child_ty),2171 try o.lowerDebugType(pt, child_ty),
...@@ -2174,7 +2176,7 @@ pub const Object = struct {...@@ -2174,7 +2176,7 @@ pub const Object = struct {
21742176
2175 const debug_some_type = try o.builder.debugMemberType(2177 const debug_some_type = try o.builder.debugMemberType(
2176 try o.builder.metadataString("some"),2178 try o.builder.metadataString("some"),
2177 .none,2179 null,
2178 debug_fwd_ref,2180 debug_fwd_ref,
2179 0,2181 0,
2180 try o.lowerDebugType(pt, non_null_ty),2182 try o.lowerDebugType(pt, non_null_ty),
...@@ -2185,10 +2187,10 @@ pub const Object = struct {...@@ -2185,10 +2187,10 @@ pub const Object = struct {
21852187
2186 const debug_optional_type = try o.builder.debugStructType(2188 const debug_optional_type = try o.builder.debugStructType(
2187 try o.builder.metadataString(name),2189 try o.builder.metadataString(name),
2188 .none, // File2190 null, // File
2189 o.debug_compile_unit, // Scope2191 o.debug_compile_unit.unwrap().?, // Scope
2190 0, // Line2192 0, // Line
2191 .none, // Underlying type2193 null, // Underlying type
2192 ty.abiSize(zcu) * 8,2194 ty.abiSize(zcu) * 8,
2193 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,2195 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2194 try o.builder.metadataTuple(&.{2196 try o.builder.metadataTuple(&.{
...@@ -2197,10 +2199,10 @@ pub const Object = struct {...@@ -2197,10 +2199,10 @@ pub const Object = struct {
2197 }),2199 }),
2198 );2200 );
21992201
2200 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);2202 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_optional_type);
22012203
2202 // Set to real type now that it has been lowered fully2204 // Set to real type now that it has been lowered fully
2203 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2205 const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable;
2204 map_ptr.* = debug_optional_type;2206 map_ptr.* = debug_optional_type;
22052207
2206 return debug_optional_type;2208 return debug_optional_type;
...@@ -2210,7 +2212,7 @@ pub const Object = struct {...@@ -2210,7 +2212,7 @@ pub const Object = struct {
2210 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {2212 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2211 // TODO: Maybe remove?2213 // TODO: Maybe remove?
2212 const debug_error_union_type = try o.lowerDebugType(pt, Type.anyerror);2214 const debug_error_union_type = try o.lowerDebugType(pt, Type.anyerror);
2213 try o.debug_type_map.put(gpa, ty, debug_error_union_type);2215 try o.debug_type_map.put(gpa, ty.toIntern(), debug_error_union_type);
2214 return debug_error_union_type;2216 return debug_error_union_type;
2215 }2217 }
22162218
...@@ -2243,7 +2245,7 @@ pub const Object = struct {...@@ -2243,7 +2245,7 @@ pub const Object = struct {
2243 var fields: [2]Builder.Metadata = undefined;2245 var fields: [2]Builder.Metadata = undefined;
2244 fields[error_index] = try o.builder.debugMemberType(2246 fields[error_index] = try o.builder.debugMemberType(
2245 try o.builder.metadataString("tag"),2247 try o.builder.metadataString("tag"),
2246 .none, // File2248 null, // File
2247 debug_fwd_ref,2249 debug_fwd_ref,
2248 0, // Line2250 0, // Line
2249 try o.lowerDebugType(pt, Type.anyerror),2251 try o.lowerDebugType(pt, Type.anyerror),
...@@ -2253,7 +2255,7 @@ pub const Object = struct {...@@ -2253,7 +2255,7 @@ pub const Object = struct {
2253 );2255 );
2254 fields[payload_index] = try o.builder.debugMemberType(2256 fields[payload_index] = try o.builder.debugMemberType(
2255 try o.builder.metadataString("value"),2257 try o.builder.metadataString("value"),
2256 .none, // File2258 null, // File
2257 debug_fwd_ref,2259 debug_fwd_ref,
2258 0, // Line2260 0, // Line
2259 try o.lowerDebugType(pt, payload_ty),2261 try o.lowerDebugType(pt, payload_ty),
...@@ -2264,18 +2266,18 @@ pub const Object = struct {...@@ -2264,18 +2266,18 @@ pub const Object = struct {
22642266
2265 const debug_error_union_type = try o.builder.debugStructType(2267 const debug_error_union_type = try o.builder.debugStructType(
2266 try o.builder.metadataString(name),2268 try o.builder.metadataString(name),
2267 .none, // File2269 null, // File
2268 o.debug_compile_unit, // Sope2270 o.debug_compile_unit.unwrap().?, // Sope
2269 0, // Line2271 0, // Line
2270 .none, // Underlying type2272 null, // Underlying type
2271 ty.abiSize(zcu) * 8,2273 ty.abiSize(zcu) * 8,
2272 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,2274 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2273 try o.builder.metadataTuple(&fields),2275 try o.builder.metadataTuple(&fields),
2274 );2276 );
22752277
2276 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_error_union_type);2278 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_error_union_type);
22772279
2278 try o.debug_type_map.put(gpa, ty, debug_error_union_type);2280 try o.debug_type_map.put(gpa, ty.toIntern(), debug_error_union_type);
2279 return debug_error_union_type;2281 return debug_error_union_type;
2280 },2282 },
2281 .error_set => {2283 .error_set => {
...@@ -2283,7 +2285,7 @@ pub const Object = struct {...@@ -2283,7 +2285,7 @@ pub const Object = struct {
2283 try o.builder.metadataString("anyerror"),2285 try o.builder.metadataString("anyerror"),
2284 16,2286 16,
2285 );2287 );
2286 try o.debug_type_map.put(gpa, ty, debug_error_set);2288 try o.debug_type_map.put(gpa, ty.toIntern(), debug_error_set);
2287 return debug_error_set;2289 return debug_error_set;
2288 },2290 },
2289 .@"struct" => {2291 .@"struct" => {
...@@ -2299,7 +2301,7 @@ pub const Object = struct {...@@ -2299,7 +2301,7 @@ pub const Object = struct {
2299 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(zcu) * 8),2301 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(zcu) * 8),
2300 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(zcu) * 8),2302 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(zcu) * 8),
2301 };2303 };
2302 try o.debug_type_map.put(gpa, ty, debug_int_type);2304 try o.debug_type_map.put(gpa, ty.toIntern(), debug_int_type);
2303 return debug_int_type;2305 return debug_int_type;
2304 }2306 }
2305 }2307 }
...@@ -2329,7 +2331,7 @@ pub const Object = struct {...@@ -2329,7 +2331,7 @@ pub const Object = struct {
23292331
2330 fields.appendAssumeCapacity(try o.builder.debugMemberType(2332 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2331 try o.builder.metadataString(field_name),2333 try o.builder.metadataString(field_name),
2332 .none, // File2334 null, // File
2333 debug_fwd_ref,2335 debug_fwd_ref,
2334 0,2336 0,
2335 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),2337 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
...@@ -2341,18 +2343,18 @@ pub const Object = struct {...@@ -2341,18 +2343,18 @@ pub const Object = struct {
23412343
2342 const debug_struct_type = try o.builder.debugStructType(2344 const debug_struct_type = try o.builder.debugStructType(
2343 try o.builder.metadataString(name),2345 try o.builder.metadataString(name),
2344 .none, // File2346 null, // File
2345 o.debug_compile_unit, // Scope2347 o.debug_compile_unit.unwrap().?, // Scope
2346 0, // Line2348 0, // Line
2347 .none, // Underlying type2349 null, // Underlying type
2348 ty.abiSize(zcu) * 8,2350 ty.abiSize(zcu) * 8,
2349 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,2351 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2350 try o.builder.metadataTuple(fields.items),2352 try o.builder.metadataTuple(fields.items),
2351 );2353 );
23522354
2353 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type);2355 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_struct_type);
23542356
2355 try o.debug_type_map.put(gpa, ty, debug_struct_type);2357 try o.debug_type_map.put(gpa, ty.toIntern(), debug_struct_type);
2356 return debug_struct_type;2358 return debug_struct_type;
2357 },2359 },
2358 .struct_type => {2360 .struct_type => {
...@@ -2365,7 +2367,7 @@ pub const Object = struct {...@@ -2365,7 +2367,7 @@ pub const Object = struct {
2365 // rather than changing the frontend to unnecessarily resolve the2367 // rather than changing the frontend to unnecessarily resolve the
2366 // struct field types.2368 // struct field types.
2367 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);2369 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);
2368 try o.debug_type_map.put(gpa, ty, debug_struct_type);2370 try o.debug_type_map.put(gpa, ty.toIntern(), debug_struct_type);
2369 return debug_struct_type;2371 return debug_struct_type;
2370 }2372 }
2371 },2373 },
...@@ -2374,7 +2376,7 @@ pub const Object = struct {...@@ -2374,7 +2376,7 @@ pub const Object = struct {
23742376
2375 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {2377 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2376 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);2378 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);
2377 try o.debug_type_map.put(gpa, ty, debug_struct_type);2379 try o.debug_type_map.put(gpa, ty.toIntern(), debug_struct_type);
2378 return debug_struct_type;2380 return debug_struct_type;
2379 }2381 }
23802382
...@@ -2388,7 +2390,7 @@ pub const Object = struct {...@@ -2388,7 +2390,7 @@ pub const Object = struct {
2388 const debug_fwd_ref = try o.builder.debugForwardReference();2390 const debug_fwd_ref = try o.builder.debugForwardReference();
23892391
2390 // Set as forward reference while the type is lowered in case it references itself2392 // Set as forward reference while the type is lowered in case it references itself
2391 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);2393 try o.debug_type_map.put(gpa, ty.toIntern(), debug_fwd_ref);
23922394
2393 comptime assert(struct_layout_version == 2);2395 comptime assert(struct_layout_version == 2);
2394 var it = struct_type.iterateRuntimeOrder(ip);2396 var it = struct_type.iterateRuntimeOrder(ip);
...@@ -2402,7 +2404,7 @@ pub const Object = struct {...@@ -2402,7 +2404,7 @@ pub const Object = struct {
2402 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);2404 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
2403 fields.appendAssumeCapacity(try o.builder.debugMemberType(2405 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2404 try o.builder.metadataString(field_name.toSlice(ip)),2406 try o.builder.metadataString(field_name.toSlice(ip)),
2405 .none, // File2407 null, // File
2406 debug_fwd_ref,2408 debug_fwd_ref,
2407 0, // Line2409 0, // Line
2408 try o.lowerDebugType(pt, field_ty),2410 try o.lowerDebugType(pt, field_ty),
...@@ -2414,19 +2416,19 @@ pub const Object = struct {...@@ -2414,19 +2416,19 @@ pub const Object = struct {
24142416
2415 const debug_struct_type = try o.builder.debugStructType(2417 const debug_struct_type = try o.builder.debugStructType(
2416 try o.builder.metadataString(name),2418 try o.builder.metadataString(name),
2417 .none, // File2419 null, // File
2418 o.debug_compile_unit, // Scope2420 o.debug_compile_unit.unwrap().?, // Scope
2419 0, // Line2421 0, // Line
2420 .none, // Underlying type2422 null, // Underlying type
2421 ty.abiSize(zcu) * 8,2423 ty.abiSize(zcu) * 8,
2422 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,2424 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2423 try o.builder.metadataTuple(fields.items),2425 try o.builder.metadataTuple(fields.items),
2424 );2426 );
24252427
2426 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type);2428 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_struct_type);
24272429
2428 // Set to real type now that it has been lowered fully2430 // Set to real type now that it has been lowered fully
2429 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2431 const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable;
2430 map_ptr.* = debug_struct_type;2432 map_ptr.* = debug_struct_type;
24312433
2432 return debug_struct_type;2434 return debug_struct_type;
...@@ -2441,7 +2443,7 @@ pub const Object = struct {...@@ -2441,7 +2443,7 @@ pub const Object = struct {
2441 !union_type.haveLayout(ip))2443 !union_type.haveLayout(ip))
2442 {2444 {
2443 const debug_union_type = try o.makeEmptyNamespaceDebugType(pt, ty);2445 const debug_union_type = try o.makeEmptyNamespaceDebugType(pt, ty);
2444 try o.debug_type_map.put(gpa, ty, debug_union_type);2446 try o.debug_type_map.put(gpa, ty.toIntern(), debug_union_type);
2445 return debug_union_type;2447 return debug_union_type;
2446 }2448 }
24472449
...@@ -2450,15 +2452,15 @@ pub const Object = struct {...@@ -2450,15 +2452,15 @@ pub const Object = struct {
2450 const debug_fwd_ref = try o.builder.debugForwardReference();2452 const debug_fwd_ref = try o.builder.debugForwardReference();
24512453
2452 // Set as forward reference while the type is lowered in case it references itself2454 // Set as forward reference while the type is lowered in case it references itself
2453 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);2455 try o.debug_type_map.put(gpa, ty.toIntern(), debug_fwd_ref);
24542456
2455 if (layout.payload_size == 0) {2457 if (layout.payload_size == 0) {
2456 const debug_union_type = try o.builder.debugStructType(2458 const debug_union_type = try o.builder.debugStructType(
2457 try o.builder.metadataString(name),2459 try o.builder.metadataString(name),
2458 .none, // File2460 null, // File
2459 o.debug_compile_unit, // Scope2461 o.debug_compile_unit.unwrap().?, // Scope
2460 0, // Line2462 0, // Line
2461 .none, // Underlying type2463 null, // Underlying type
2462 ty.abiSize(zcu) * 8,2464 ty.abiSize(zcu) * 8,
2463 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,2465 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2464 try o.builder.metadataTuple(2466 try o.builder.metadataTuple(
...@@ -2467,7 +2469,7 @@ pub const Object = struct {...@@ -2467,7 +2469,7 @@ pub const Object = struct {
2467 );2469 );
24682470
2469 // Set to real type now that it has been lowered fully2471 // Set to real type now that it has been lowered fully
2470 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2472 const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable;
2471 map_ptr.* = debug_union_type;2473 map_ptr.* = debug_union_type;
24722474
2473 return debug_union_type;2475 return debug_union_type;
...@@ -2498,7 +2500,7 @@ pub const Object = struct {...@@ -2498,7 +2500,7 @@ pub const Object = struct {
2498 const field_name = tag_type.names.get(ip)[field_index];2500 const field_name = tag_type.names.get(ip)[field_index];
2499 fields.appendAssumeCapacity(try o.builder.debugMemberType(2501 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2500 try o.builder.metadataString(field_name.toSlice(ip)),2502 try o.builder.metadataString(field_name.toSlice(ip)),
2501 .none, // File2503 null, // File
2502 debug_union_fwd_ref,2504 debug_union_fwd_ref,
2503 0, // Line2505 0, // Line
2504 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),2506 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
...@@ -2517,20 +2519,20 @@ pub const Object = struct {...@@ -2517,20 +2519,20 @@ pub const Object = struct {
25172519
2518 const debug_union_type = try o.builder.debugUnionType(2520 const debug_union_type = try o.builder.debugUnionType(
2519 try o.builder.metadataString(union_name),2521 try o.builder.metadataString(union_name),
2520 .none, // File2522 null, // File
2521 o.debug_compile_unit, // Scope2523 o.debug_compile_unit.unwrap().?, // Scope
2522 0, // Line2524 0, // Line
2523 .none, // Underlying type2525 null, // Underlying type
2524 layout.payload_size * 8,2526 layout.payload_size * 8,
2525 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,2527 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2526 try o.builder.metadataTuple(fields.items),2528 try o.builder.metadataTuple(fields.items),
2527 );2529 );
25282530
2529 o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type);2531 o.builder.resolveDebugForwardReference(debug_union_fwd_ref, debug_union_type);
25302532
2531 if (layout.tag_size == 0) {2533 if (layout.tag_size == 0) {
2532 // Set to real type now that it has been lowered fully2534 // Set to real type now that it has been lowered fully
2533 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2535 const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable;
2534 map_ptr.* = debug_union_type;2536 map_ptr.* = debug_union_type;
25352537
2536 return debug_union_type;2538 return debug_union_type;
...@@ -2548,7 +2550,7 @@ pub const Object = struct {...@@ -2548,7 +2550,7 @@ pub const Object = struct {
25482550
2549 const debug_tag_type = try o.builder.debugMemberType(2551 const debug_tag_type = try o.builder.debugMemberType(
2550 try o.builder.metadataString("tag"),2552 try o.builder.metadataString("tag"),
2551 .none, // File2553 null, // File
2552 debug_fwd_ref,2554 debug_fwd_ref,
2553 0, // Line2555 0, // Line
2554 try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty)),2556 try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty)),
...@@ -2559,7 +2561,7 @@ pub const Object = struct {...@@ -2559,7 +2561,7 @@ pub const Object = struct {
25592561
2560 const debug_payload_type = try o.builder.debugMemberType(2562 const debug_payload_type = try o.builder.debugMemberType(
2561 try o.builder.metadataString("payload"),2563 try o.builder.metadataString("payload"),
2562 .none, // File2564 null, // File
2563 debug_fwd_ref,2565 debug_fwd_ref,
2564 0, // Line2566 0, // Line
2565 debug_union_type,2567 debug_union_type,
...@@ -2576,19 +2578,19 @@ pub const Object = struct {...@@ -2576,19 +2578,19 @@ pub const Object = struct {
25762578
2577 const debug_tagged_union_type = try o.builder.debugStructType(2579 const debug_tagged_union_type = try o.builder.debugStructType(
2578 try o.builder.metadataString(name),2580 try o.builder.metadataString(name),
2579 .none, // File2581 null, // File
2580 o.debug_compile_unit, // Scope2582 o.debug_compile_unit.unwrap().?, // Scope
2581 0, // Line2583 0, // Line
2582 .none, // Underlying type2584 null, // Underlying type
2583 ty.abiSize(zcu) * 8,2585 ty.abiSize(zcu) * 8,
2584 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,2586 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2585 try o.builder.metadataTuple(&full_fields),2587 try o.builder.metadataTuple(&full_fields),
2586 );2588 );
25872589
2588 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_tagged_union_type);2590 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_tagged_union_type);
25892591
2590 // Set to real type now that it has been lowered fully2592 // Set to real type now that it has been lowered fully
2591 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;2593 const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable;
2592 map_ptr.* = debug_tagged_union_type;2594 map_ptr.* = debug_tagged_union_type;
25932595
2594 return debug_tagged_union_type;2596 return debug_tagged_union_type;
...@@ -2636,7 +2638,7 @@ pub const Object = struct {...@@ -2636,7 +2638,7 @@ pub const Object = struct {
2636 try o.builder.metadataTuple(debug_param_types.items),2638 try o.builder.metadataTuple(debug_param_types.items),
2637 );2639 );
26382640
2639 try o.debug_type_map.put(gpa, ty, debug_function_type);2641 try o.debug_type_map.put(gpa, ty.toIntern(), debug_function_type);
2640 return debug_function_type;2642 return debug_function_type;
2641 },2643 },
2642 .comptime_int => unreachable,2644 .comptime_int => unreachable,
...@@ -2676,10 +2678,10 @@ pub const Object = struct {...@@ -2676,10 +2678,10 @@ pub const Object = struct {
2676 file,2678 file,
2677 scope,2679 scope,
2678 ty.typeDeclSrcLine(zcu).? + 1,2680 ty.typeDeclSrcLine(zcu).? + 1,
2679 .none,2681 null,
2680 0,2682 0,
2681 0,2683 0,
2682 .none,2684 null,
2683 );2685 );
2684 }2686 }
26852687
...@@ -4687,7 +4689,7 @@ pub const FuncGen = struct {...@@ -4687,7 +4689,7 @@ pub const FuncGen = struct {
4687 file: Builder.Metadata,4689 file: Builder.Metadata,
4688 scope: Builder.Metadata,4690 scope: Builder.Metadata,
46894691
4690 inlined: Builder.DebugLocation = .no_location,4692 inlined_at: Builder.Metadata.Optional = .none,
46914693
4692 base_line: u32,4694 base_line: u32,
4693 prev_dbg_line: c_uint,4695 prev_dbg_line: c_uint,
...@@ -5156,16 +5158,18 @@ pub const FuncGen = struct {...@@ -5156,16 +5158,18 @@ pub const FuncGen = struct {
5156 ) Error!void {5158 ) Error!void {
5157 if (self.wip.strip) return self.genBody(body, coverage_point);5159 if (self.wip.strip) return self.genBody(body, coverage_point);
51585160
5161 const old_debug_location = self.wip.debug_location;
5159 const old_file = self.file;5162 const old_file = self.file;
5160 const old_inlined = self.inlined;5163 const old_inlined_at = self.inlined_at;
5161 const old_base_line = self.base_line;5164 const old_base_line = self.base_line;
5162 const old_scope = self.scope;
5163 defer if (maybe_inline_func) |_| {5165 defer if (maybe_inline_func) |_| {
5164 self.wip.debug_location = self.inlined;5166 self.wip.debug_location = old_debug_location;
5165 self.file = old_file;5167 self.file = old_file;
5166 self.inlined = old_inlined;5168 self.inlined_at = old_inlined_at;
5167 self.base_line = old_base_line;5169 self.base_line = old_base_line;
5168 };5170 };
5171
5172 const old_scope = self.scope;
5169 defer self.scope = old_scope;5173 defer self.scope = old_scope;
51705174
5171 if (maybe_inline_func) |inline_func| {5175 if (maybe_inline_func) |inline_func| {
...@@ -5181,8 +5185,9 @@ pub const FuncGen = struct {...@@ -5181,8 +5185,9 @@ pub const FuncGen = struct {
51815185
5182 self.file = try o.getDebugFile(pt, file_scope);5186 self.file = try o.getDebugFile(pt, file_scope);
51835187
5184 const line_number = zcu.navSrcLine(func.owner_nav) + 1;5188 self.base_line = zcu.navSrcLine(func.owner_nav);
5185 self.inlined = self.wip.debug_location;5189 const line_number = self.base_line + 1;
5190 self.inlined_at = try self.wip.debug_location.toMetadata(&o.builder);
51865191
5187 const fn_ty = try pt.funcType(.{5192 const fn_ty = try pt.funcType(.{
5188 .param_types = &.{},5193 .param_types = &.{},
...@@ -5201,23 +5206,11 @@ pub const FuncGen = struct {...@@ -5201,23 +5206,11 @@ pub const FuncGen = struct {
5201 .sp_flags = .{5206 .sp_flags = .{
5202 .Optimized = mod.optimize_mode != .Debug,5207 .Optimized = mod.optimize_mode != .Debug,
5203 .Definition = true,5208 .Definition = true,
5204 // TODO: we can't know this at this point, since the function could be exported later!5209 .LocalToUnit = true, // inline functions cannot be exported
5205 .LocalToUnit = true,
5206 },5210 },
5207 },5211 },
5208 o.debug_compile_unit,5212 o.debug_compile_unit.unwrap().?,
5209 );5213 );
5210
5211 self.base_line = zcu.navSrcLine(func.owner_nav);
5212 const inlined_at_location = try self.wip.debug_location.toMetadata(&o.builder);
5213 self.wip.debug_location = .{
5214 .location = .{
5215 .line = line_number,
5216 .column = 0,
5217 .scope = self.scope,
5218 .inlined_at = inlined_at_location,
5219 },
5220 };
5221 }5214 }
52225215
5223 self.scope = try self.ng.object.builder.debugLexicalBlock(5216 self.scope = try self.ng.object.builder.debugLexicalBlock(
...@@ -5226,15 +5219,12 @@ pub const FuncGen = struct {...@@ -5226,15 +5219,12 @@ pub const FuncGen = struct {
5226 self.prev_dbg_line,5219 self.prev_dbg_line,
5227 self.prev_dbg_column,5220 self.prev_dbg_column,
5228 );5221 );
52295222 self.wip.debug_location = .{ .location = .{
5230 switch (self.wip.debug_location) {5223 .line = self.prev_dbg_line,
5231 .location => |*l| l.scope = self.scope,5224 .column = self.prev_dbg_column,
5232 .no_location => {},5225 .scope = self.scope.toOptional(),
5233 }5226 .inlined_at = self.inlined_at,
5234 defer switch (self.wip.debug_location) {5227 } };
5235 .location => |*l| l.scope = old_scope,
5236 .no_location => {},
5237 };
52385228
5239 try self.genBody(body, coverage_point);5229 try self.genBody(body, coverage_point);
5240 }5230 }
...@@ -6516,8 +6506,13 @@ pub const FuncGen = struct {...@@ -6516,8 +6506,13 @@ pub const FuncGen = struct {
6516 break :llvm_cases_len len;6506 break :llvm_cases_len len;
6517 };6507 };
65186508
6519 var weights = try self.gpa.alloc(Builder.Metadata, llvm_cases_len + 1);6509 var weights = try self.gpa.alloc(Builder.Metadata, 1 + llvm_cases_len + 1);
6520 defer self.gpa.free(weights);6510 defer self.gpa.free(weights);
6511 var weight_idx: usize = 0;
6512
6513 const branch_weights_str = try o.builder.metadataString("branch_weights");
6514 weights[weight_idx] = branch_weights_str.toMetadata();
6515 weight_idx += 1;
65216516
6522 const else_weight: u32 = switch (switch_br.getElseHint()) {6517 const else_weight: u32 = switch (switch_br.getElseHint()) {
6523 .unpredictable => unreachable,6518 .unpredictable => unreachable,
...@@ -6525,9 +6520,9 @@ pub const FuncGen = struct {...@@ -6525,9 +6520,9 @@ pub const FuncGen = struct {
6525 .likely => 2000,6520 .likely => 2000,
6526 .unlikely => 1,6521 .unlikely => 1,
6527 };6522 };
6528 weights[0] = try o.builder.metadataConstant(try o.builder.intConst(.i32, else_weight));6523 weights[weight_idx] = try o.builder.metadataConstant(try o.builder.intConst(.i32, else_weight));
6524 weight_idx += 1;
65296525
6530 var weight_idx: usize = 1;
6531 var it = switch_br.iterateCases();6526 var it = switch_br.iterateCases();
6532 while (it.next()) |case| {6527 while (it.next()) |case| {
6533 const weight_val: u32 = switch (switch_br.getHint(case.idx)) {6528 const weight_val: u32 = switch (switch_br.getHint(case.idx)) {
...@@ -6542,10 +6537,7 @@ pub const FuncGen = struct {...@@ -6542,10 +6537,7 @@ pub const FuncGen = struct {
6542 }6537 }
65436538
6544 assert(weight_idx == weights.len);6539 assert(weight_idx == weights.len);
65456540 break :weights .fromMetadata(try o.builder.metadataTuple(weights));
6546 const branch_weights_str = try o.builder.metadataString("branch_weights");
6547 const tuple = try o.builder.strTuple(branch_weights_str, weights);
6548 break :weights @enumFromInt(@intFromEnum(tuple));
6549 };6541 };
65506542
6551 const dispatch_info: SwitchDispatchInfo = .{6543 const dispatch_info: SwitchDispatchInfo = .{
...@@ -7102,14 +7094,12 @@ pub const FuncGen = struct {...@@ -7102,14 +7094,12 @@ pub const FuncGen = struct {
7102 self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1);7094 self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1);
7103 self.prev_dbg_column = @intCast(dbg_stmt.column + 1);7095 self.prev_dbg_column = @intCast(dbg_stmt.column + 1);
71047096
7105 self.wip.debug_location = .{7097 self.wip.debug_location = .{ .location = .{
7106 .location = .{7098 .line = self.prev_dbg_line,
7107 .line = self.prev_dbg_line,7099 .column = self.prev_dbg_column,
7108 .column = self.prev_dbg_column,7100 .scope = self.scope.toOptional(),
7109 .scope = self.scope,7101 .inlined_at = self.inlined_at,
7110 .inlined_at = try self.inlined.toMetadata(self.wip.builder),7102 } };
7111 },
7112 };
71137103
7114 return .none;7104 return .none;
7115 }7105 }
...@@ -7167,9 +7157,10 @@ pub const FuncGen = struct {...@@ -7167,9 +7157,10 @@ pub const FuncGen = struct {
7167 const operand = try self.resolveInst(pl_op.operand);7157 const operand = try self.resolveInst(pl_op.operand);
7168 const operand_ty = self.typeOf(pl_op.operand);7158 const operand_ty = self.typeOf(pl_op.operand);
7169 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);7159 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
71707160 const name_slice = name.toSlice(self.air);
7161 const metadata_name = if (name_slice.len > 0) try o.builder.metadataString(name_slice) else null;
7171 const debug_local_var = if (is_arg) try o.builder.debugParameter(7162 const debug_local_var = if (is_arg) try o.builder.debugParameter(
7172 try o.builder.metadataString(name.toSlice(self.air)),7163 metadata_name,
7173 self.file,7164 self.file,
7174 self.scope,7165 self.scope,
7175 self.prev_dbg_line,7166 self.prev_dbg_line,
...@@ -7179,7 +7170,7 @@ pub const FuncGen = struct {...@@ -7179,7 +7170,7 @@ pub const FuncGen = struct {
7179 break :arg_no self.arg_inline_index;7170 break :arg_no self.arg_inline_index;
7180 },7171 },
7181 ) else try o.builder.debugLocalVar(7172 ) else try o.builder.debugLocalVar(
7182 try o.builder.metadataString(name.toSlice(self.air)),7173 metadata_name,
7183 self.file,7174 self.file,
7184 self.scope,7175 self.scope,
7185 self.prev_dbg_line,7176 self.prev_dbg_line,
...@@ -9547,7 +9538,7 @@ pub const FuncGen = struct {...@@ -9547,7 +9538,7 @@ pub const FuncGen = struct {
9547 const lbrace_col = func.lbrace_column + 1;9538 const lbrace_col = func.lbrace_column + 1;
95489539
9549 const debug_parameter = try o.builder.debugParameter(9540 const debug_parameter = try o.builder.debugParameter(
9550 try o.builder.metadataString(name),9541 if (name.len > 0) try o.builder.metadataString(name) else null,
9551 self.file,9542 self.file,
9552 self.scope,9543 self.scope,
9553 lbrace_line,9544 lbrace_line,
...@@ -9556,14 +9547,12 @@ pub const FuncGen = struct {...@@ -9556,14 +9547,12 @@ pub const FuncGen = struct {
9556 );9547 );
95579548
9558 const old_location = self.wip.debug_location;9549 const old_location = self.wip.debug_location;
9559 self.wip.debug_location = .{9550 self.wip.debug_location = .{ .location = .{
9560 .location = .{9551 .line = lbrace_line,
9561 .line = lbrace_line,9552 .column = lbrace_col,
9562 .column = lbrace_col,9553 .scope = self.scope.toOptional(),
9563 .scope = self.scope,9554 .inlined_at = .none,
9564 .inlined_at = .none,9555 } };
9565 },
9566 };
95679556
9568 if (isByRef(inst_ty, zcu)) {9557 if (isByRef(inst_ty, zcu)) {
9569 _ = try self.wip.callIntrinsic(9558 _ = try self.wip.callIntrinsic(
...@@ -12614,11 +12603,7 @@ fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key...@@ -12614,11 +12603,7 @@ fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key
12614 };12603 };
12615}12604}
1261612605
12617fn ccAbiPromoteInt(12606fn ccAbiPromoteInt(cc: std.builtin.CallingConvention, zcu: *Zcu, ty: Type) ?std.builtin.Signedness {
12618 cc: std.builtin.CallingConvention,
12619 zcu: *Zcu,
12620 ty: Type,
12621) ?std.builtin.Signedness {
12622 const target = zcu.getTarget();12607 const target = zcu.getTarget();
12623 switch (cc) {12608 switch (cc) {
12624 .auto, .@"inline", .async => return null,12609 .auto, .@"inline", .async => return null,