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),
5656metadata_items: std.MultiArrayList(Metadata.Item),
5757metadata_extra: std.ArrayListUnmanaged(u32),
5858metadata_limbs: std.ArrayListUnmanaged(std.math.big.Limb),
59metadata_forward_references: std.ArrayListUnmanaged(Metadata),
60metadata_named: std.AutoArrayHashMapUnmanaged(MetadataString, struct {
59metadata_forward_references: std.ArrayListUnmanaged(Metadata.Optional),
60metadata_named: std.AutoArrayHashMapUnmanaged(String, struct {
6161 len: u32,
6262 index: Metadata.Item.ExtraIndex,
6363}),
......@@ -265,19 +265,20 @@ pub const Type = enum(u32) {
265265 };
266266
267267 pub const Simple = enum(u5) {
268 void = 2,
269 half = 10,
270 bfloat = 23,
271 float = 3,
272 double = 4,
273 fp128 = 14,
274 x86_fp80 = 13,
275 ppc_fp128 = 15,
276 x86_amx = 24,
277 x86_mmx = 17,
278 label = 5,
279 token = 22,
280 metadata = 16,
268 const Code = ir.ModuleBlock.TypeBlock.Code;
269 void = @intFromEnum(Code.VOID),
270 half = @intFromEnum(Code.HALF),
271 bfloat = @intFromEnum(Code.BFLOAT),
272 float = @intFromEnum(Code.FLOAT),
273 double = @intFromEnum(Code.DOUBLE),
274 fp128 = @intFromEnum(Code.FP128),
275 x86_fp80 = @intFromEnum(Code.X86_FP80),
276 ppc_fp128 = @intFromEnum(Code.PPC_FP128),
277 x86_amx = @intFromEnum(Code.X86_AMX),
278 x86_mmx = @intFromEnum(Code.X86_MMX),
279 label = @intFromEnum(Code.LABEL),
280 token = @intFromEnum(Code.TOKEN),
281 metadata = @intFromEnum(Code.METADATA),
281282 };
282283
283284 pub const Function = struct {
......@@ -1325,8 +1326,8 @@ pub const Attribute = union(Kind) {
13251326 .none => unreachable,
13261327 }
13271328 }
1328 pub fn fmt(self: Index, builder: *const Builder, mode: FormatData.mode) std.fmt.Alt(FormatData, format) {
1329 return .{ .data = .{ .attribute_index = self, .builder = builder, .mode = mode } };
1329 pub fn fmt(self: Index, builder: *const Builder, flags: FormatData.Flags) std.fmt.Alt(FormatData, format) {
1330 return .{ .data = .{ .attribute_index = self, .builder = builder, .flags = flags } };
13301331 }
13311332
13321333 fn toStorage(self: Index, builder: *const Builder) Storage {
......@@ -2295,7 +2296,7 @@ pub const Global = struct {
22952296 externally_initialized: ExternallyInitialized = .default,
22962297 type: Type,
22972298 partition: String = .none,
2298 dbg: Metadata = .none,
2299 dbg: Metadata.Optional = .none,
22992300 kind: union(enum) {
23002301 alias: Alias.Index,
23012302 variable: Variable.Index,
......@@ -2375,7 +2376,11 @@ pub const Global = struct {
23752376 }
23762377
23772378 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;
23792384 }
23802385
23812386 const FormatData = struct {
......@@ -2606,6 +2611,10 @@ pub const Variable = struct {
26062611 pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void {
26072612 self.ptrConst(builder).global.setDebugMetadata(expression, builder);
26082613 }
2614
2615 pub fn getGlobalVariableExpression(self: Index, builder: *Builder) Metadata.Optional {
2616 return self.ptrConst(builder).global.getDebugMetadata(builder);
2617 }
26092618 };
26102619};
26112620
......@@ -4107,6 +4116,10 @@ pub const Function = struct {
41074116 pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void {
41084117 self.ptrConst(builder).global.setDebugMetadata(subprogram, builder);
41094118 }
4119
4120 pub fn getSubprogram(self: Index, builder: *const Builder) Metadata.Optional {
4121 return self.ptrConst(builder).global.getDebugMetadata(builder);
4122 }
41104123 };
41114124
41124125 pub const Block = struct {
......@@ -4869,13 +4882,20 @@ pub const Function = struct {
48694882 then: Block.Index,
48704883 @"else": Block.Index,
48714884 weights: Weights,
4885
48724886 pub const Weights = enum(u32) {
4873 // We can do this as metadata indices 0 and 1 are reserved.
4874 none = 0,
4875 unpredictable = 1,
4876 /// These values should be converted to `Metadata` to be used
4877 /// in a `prof` annotation providing branch weights.
4887 none = @bitCast(Metadata.Optional.none),
4888 unpredictable,
48784889 _,
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 }
48794899 };
48804900 };
48814901
......@@ -5130,19 +5150,19 @@ pub const DebugLocation = union(enum) {
51305150 pub const Location = struct {
51315151 line: u32,
51325152 column: u32,
5133 scope: Builder.Metadata,
5134 inlined_at: Builder.Metadata,
5153 scope: Builder.Metadata.Optional,
5154 inlined_at: Builder.Metadata.Optional,
51355155 };
51365156
5137 pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata {
5157 pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata.Optional {
51385158 return switch (self) {
51395159 .no_location => .none,
5140 .location => |location| try builder.debugLocation(
5160 .location => |location| (try builder.debugLocation(
51415161 location.line,
51425162 location.column,
5143 location.scope,
5144 location.inlined_at,
5145 ),
5163 location.scope.unwrap().?,
5164 location.inlined_at.unwrap(),
5165 )).toOptional(),
51465166 };
51475167 }
51485168};
......@@ -5280,20 +5300,19 @@ pub const WipFunction = struct {
52805300 .cond = cond,
52815301 .then = then,
52825302 .@"else" = @"else",
5283 .weights = switch (weights) {
5303 .weights = weights: switch (weights) {
52845304 .none => .none,
52855305 .unpredictable => .unpredictable,
5286 .then_likely, .else_likely => w: {
5306 .then_likely, .else_likely => {
52875307 const branch_weights_str = try self.builder.metadataString("branch_weights");
52885308 const unlikely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 1));
52895309 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) {
52915311 .none, .unpredictable => unreachable,
5292 .then_likely => .{ likely_const, unlikely_const },
5293 .else_likely => .{ unlikely_const, likely_const },
5312 .then_likely => .{ branch_weights_str.toMetadata(), likely_const, unlikely_const },
5313 .else_likely => .{ branch_weights_str.toMetadata(), unlikely_const, likely_const },
52945314 };
5295 const tuple = try self.builder.strTuple(branch_weights_str, &weight_vals);
5296 break :w @enumFromInt(@intFromEnum(tuple));
5315 break :weights .fromMetadata(try self.builder.metadataTuple(&weight_vals));
52975316 },
52985317 },
52995318 }),
......@@ -6197,20 +6216,18 @@ pub const WipFunction = struct {
61976216 return instruction.toValue();
61986217 }
61996218
6200 pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata {
6219 pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata.Optional {
62016220 if (self.strip) return .none;
6202 return switch (value.unwrap()) {
6203 .instruction => |instr_index| blk: {
6221 const metadata: Metadata = metadata: switch (value.unwrap()) {
6222 .instruction => |instr_index| {
62046223 const gop = try self.debug_values.getOrPut(self.builder.gpa, instr_index);
6205
6206 const metadata: Metadata = @enumFromInt(Metadata.first_local_metadata + gop.index);
62076224 if (!gop.found_existing) gop.key_ptr.* = instr_index;
6208
6209 break :blk metadata;
6225 break :metadata .{ .index = @intCast(gop.index), .kind = .local };
62106226 },
62116227 .constant => |constant| try self.builder.metadataConstant(constant),
62126228 .metadata => |metadata| metadata,
62136229 };
6230 return metadata.toOptional();
62146231 }
62156232
62166233 pub fn finish(self: *WipFunction) Allocator.Error!void {
......@@ -7820,7 +7837,7 @@ pub const Value = enum(u32) {
78207837 else if (@intFromEnum(self) < first_metadata)
78217838 .{ .constant = @enumFromInt(@intFromEnum(self) - first_constant) }
78227839 else
7823 .{ .metadata = @enumFromInt(@intFromEnum(self) - first_metadata) };
7840 .{ .metadata = @bitCast(@intFromEnum(self) - first_metadata) };
78247841 }
78257842
78267843 pub fn typeOfWip(self: Value, wip: *const WipFunction) Type {
......@@ -7873,50 +7890,110 @@ pub const Value = enum(u32) {
78737890 }
78747891};
78757892
7876pub const MetadataString = enum(u32) {
7877 none = 0,
7878 _,
7893pub const Metadata = packed struct(u32) {
7894 index: u29,
7895 kind: Kind,
7896 unused: enum(u1) { unused = 0 } = .unused,
78797897
7880 pub fn slice(self: MetadataString, builder: *const Builder) []const u8 {
7881 const index = @intFromEnum(self);
7882 const start = builder.metadata_string_indices.items[index];
7883 const end = builder.metadata_string_indices.items[index + 1];
7884 return builder.metadata_string_bytes.items[start..end];
7885 }
7898 pub const Kind = enum(u2) {
7899 string,
7900 node,
7901 forward,
7902 local,
7903 };
78867904
7887 const Adapter = struct {
7888 builder: *const Builder,
7889 pub fn hash(_: Adapter, key: []const u8) u32 {
7890 return @truncate(std.hash.Wyhash.hash(0, key));
7905 pub const empty_tuple: Metadata = .{ .kind = .node, .index = 0 };
7906
7907 pub const Optional = packed struct(u32) {
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();
78917917 }
7892 pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool {
7893 const rhs_metadata_string: MetadataString = @enumFromInt(rhs_index);
7894 return std.mem.eql(u8, lhs_key, rhs_metadata_string.slice(ctx.builder));
7918 pub fn unwrap(metadata: Metadata.Optional) ?Metadata {
7919 return if (metadata.is_none) null else .{ .index = metadata.index, .kind = metadata.kind };
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;
78957926 }
78967927 };
7897
7898 const FormatData = struct {
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);
7928 pub fn toOptional(metadata: Metadata) Metadata.Optional {
7929 return .{ .index = metadata.index, .kind = metadata.kind, .is_none = false };
79047930 }
7905 fn fmt(self: MetadataString, builder: *const Builder) std.fmt.Alt(FormatData, format) {
7906 return .{ .data = .{ .metadata_string = self, .builder = builder } };
7931 pub fn toValue(metadata: Metadata) Value {
7932 return @enumFromInt(Value.first_metadata + @as(u32, @bitCast(metadata)));
79077933 }
7908};
79097934
7910pub const Metadata = enum(u32) {
7911 none = 0,
7912 empty_tuple = 1,
7913 _,
7935 pub const String = enum(u32) {
7936 _,
7937
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;
7916 const first_local_metadata = 1 << 30;
7962 pub fn slice(metadata: Metadata.String, builder: *const Builder) []const u8 {
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
79187996 pub const Tag = enum(u6) {
7919 none,
79207997 file,
79217998 compile_unit,
79227999 @"compile_unit optimized",
......@@ -7947,8 +8024,6 @@ pub const Metadata = enum(u32) {
79478024 enumerator_signed_negative,
79488025 subrange,
79498026 tuple,
7950 str_tuple,
7951 module_flag,
79528027 expression,
79538028 local_var,
79548029 parameter,
......@@ -7957,9 +8032,8 @@ pub const Metadata = enum(u32) {
79578032 global_var_expression,
79588033 constant,
79598034
7960 pub fn isInline(tag: Tag) bool {
7961 return switch (tag) {
7962 .none,
8035 pub fn isInline(metadata_tag: Metadata.Tag) bool {
8036 return switch (metadata_tag) {
79638037 .expression,
79648038 .constant,
79658039 => true,
......@@ -7993,8 +8067,6 @@ pub const Metadata = enum(u32) {
79938067 .enumerator_signed_negative,
79948068 .subrange,
79958069 .tuple,
7996 .str_tuple,
7997 .module_flag,
79988070 .local_var,
79998071 .parameter,
80008072 .global_var,
......@@ -8005,20 +8077,31 @@ pub const Metadata = enum(u32) {
80058077 }
80068078 };
80078079
8008 pub fn isInline(self: Metadata, builder: *const Builder) bool {
8009 return builder.metadata_items.items(.tag)[@intFromEnum(self)].isInline();
8080 pub fn tag(metadata: Metadata, builder: *const Builder) Tag {
8081 assert(metadata.kind == .node);
8082 return builder.metadata_items.items(.tag)[metadata.index];
80108083 }
80118084
8012 pub fn unwrap(self: Metadata, builder: *const Builder) Metadata {
8013 var metadata = self;
8014 while (@intFromEnum(metadata) >= Metadata.first_forward_reference and
8015 @intFromEnum(metadata) < Metadata.first_local_metadata)
8016 {
8017 const index = @intFromEnum(metadata) - Metadata.first_forward_reference;
8018 metadata = builder.metadata_forward_references.items[index];
8019 assert(metadata != .none);
8085 pub fn item(metadata: Metadata, builder: *const Builder) Item {
8086 assert(metadata.kind == .node);
8087 return builder.metadata_items.get(metadata.index);
8088 }
8089
8090 pub fn isInline(metadata: Metadata, builder: *const Builder) bool {
8091 return metadata.tag(builder).isInline();
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 },
80208104 }
8021 return metadata;
80228105 }
80238106
80248107 pub const Item = struct {
......@@ -8086,8 +8169,8 @@ pub const Metadata = enum(u32) {
80868169 };
80878170
80888171 pub const File = struct {
8089 filename: MetadataString,
8090 directory: MetadataString,
8172 filename: Metadata.String.Optional,
8173 directory: Metadata.String.Optional,
80918174 };
80928175
80938176 pub const CompileUnit = struct {
......@@ -8095,10 +8178,10 @@ pub const Metadata = enum(u32) {
80958178 optimized: bool,
80968179 };
80978180
8098 file: Metadata,
8099 producer: MetadataString,
8100 enums: Metadata,
8101 globals: Metadata,
8181 file: Metadata.Optional,
8182 producer: Metadata.String.Optional,
8183 enums: Metadata.Optional,
8184 globals: Metadata.Optional,
81028185 };
81038186
81048187 pub const Subprogram = struct {
......@@ -8142,19 +8225,34 @@ pub const Metadata = enum(u32) {
81428225 }
81438226 };
81448227
8145 file: Metadata,
8146 name: MetadataString,
8147 linkage_name: MetadataString,
8228 file: Metadata.Optional,
8229 name: Metadata.String.Optional,
8230 linkage_name: Metadata.String.Optional,
81488231 line: u32,
81498232 scope_line: u32,
8150 ty: Metadata,
8233 ty: Metadata.Optional,
81518234 di_flags: DIFlags,
8152 compile_unit: Metadata,
8235 compile_unit: Metadata.Optional,
81538236 };
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
81558253 pub const LexicalBlock = struct {
8156 scope: Metadata,
8157 file: Metadata,
8254 scope: Metadata.Optional,
8255 file: Metadata.Optional,
81588256 line: u32,
81598257 column: u32,
81608258 };
......@@ -8163,11 +8261,11 @@ pub const Metadata = enum(u32) {
81638261 line: u32,
81648262 column: u32,
81658263 scope: Metadata,
8166 inlined_at: Metadata,
8264 inlined_at: Metadata.Optional,
81678265 };
81688266
81698267 pub const BasicType = struct {
8170 name: MetadataString,
8268 name: Metadata.String.Optional,
81718269 size_in_bits_lo: u32,
81728270 size_in_bits_hi: u32,
81738271
......@@ -8177,16 +8275,16 @@ pub const Metadata = enum(u32) {
81778275 };
81788276
81798277 pub const CompositeType = struct {
8180 name: MetadataString,
8181 file: Metadata,
8182 scope: Metadata,
8278 name: Metadata.String.Optional,
8279 file: Metadata.Optional,
8280 scope: Metadata.Optional,
81838281 line: u32,
8184 underlying_type: Metadata,
8282 underlying_type: Metadata.Optional,
81858283 size_in_bits_lo: u32,
81868284 size_in_bits_hi: u32,
81878285 align_in_bits_lo: u32,
81888286 align_in_bits_hi: u32,
8189 fields_tuple: Metadata,
8287 fields_tuple: Metadata.Optional,
81908288
81918289 pub fn bitSize(self: CompositeType) u64 {
81928290 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
......@@ -8197,11 +8295,11 @@ pub const Metadata = enum(u32) {
81978295 };
81988296
81998297 pub const DerivedType = struct {
8200 name: MetadataString,
8201 file: Metadata,
8202 scope: Metadata,
8298 name: Metadata.String.Optional,
8299 file: Metadata.Optional,
8300 scope: Metadata.Optional,
82038301 line: u32,
8204 underlying_type: Metadata,
8302 underlying_type: Metadata.Optional,
82058303 size_in_bits_lo: u32,
82068304 size_in_bits_hi: u32,
82078305 align_in_bits_lo: u32,
......@@ -8221,19 +8319,19 @@ pub const Metadata = enum(u32) {
82218319 };
82228320
82238321 pub const SubroutineType = struct {
8224 types_tuple: Metadata,
8322 types_tuple: Metadata.Optional,
82258323 };
82268324
82278325 pub const Enumerator = struct {
8228 name: MetadataString,
8326 name: Metadata.String.Optional,
82298327 bit_width: u32,
82308328 limbs_index: u32,
82318329 limbs_len: u32,
82328330 };
82338331
82348332 pub const Subrange = struct {
8235 lower_bound: Metadata,
8236 count: Metadata,
8333 lower_bound: Metadata.Optional,
8334 count: Metadata.Optional,
82378335 };
82388336
82398337 pub const Expression = struct {
......@@ -8248,33 +8346,20 @@ pub const Metadata = enum(u32) {
82488346 // elements: [elements_len]Metadata
82498347 };
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
82648349 pub const LocalVar = struct {
8265 name: MetadataString,
8266 file: Metadata,
8267 scope: Metadata,
8350 name: Metadata.String.Optional,
8351 file: Metadata.Optional,
8352 scope: Metadata.Optional,
82688353 line: u32,
8269 ty: Metadata,
8354 ty: Metadata.Optional,
82708355 };
82718356
82728357 pub const Parameter = struct {
8273 name: MetadataString,
8274 file: Metadata,
8275 scope: Metadata,
8358 name: Metadata.String.Optional,
8359 file: Metadata.Optional,
8360 scope: Metadata.Optional,
82768361 line: u32,
8277 ty: Metadata,
8362 ty: Metadata.Optional,
82788363 arg_no: u32,
82798364 };
82808365
......@@ -8283,24 +8368,20 @@ pub const Metadata = enum(u32) {
82838368 local: bool,
82848369 };
82858370
8286 name: MetadataString,
8287 linkage_name: MetadataString,
8288 file: Metadata,
8289 scope: Metadata,
8371 name: Metadata.String.Optional,
8372 linkage_name: Metadata.String.Optional,
8373 file: Metadata.Optional,
8374 scope: Metadata.Optional,
82908375 line: u32,
8291 ty: Metadata,
8376 ty: Metadata.Optional,
82928377 variable: Variable.Index,
82938378 };
82948379
82958380 pub const GlobalVarExpression = struct {
8296 variable: Metadata,
8297 expression: Metadata,
8381 variable: Metadata.Optional,
8382 expression: Metadata.Optional,
82988383 };
82998384
8300 pub fn toValue(self: Metadata) Value {
8301 return @enumFromInt(Value.first_metadata + @intFromEnum(self));
8302 }
8303
83048385 const Formatter = struct {
83058386 builder: *Builder,
83068387 need_comma: bool,
......@@ -8325,7 +8406,7 @@ pub const Metadata = enum(u32) {
83258406 local_inline: Metadata,
83268407 local_index: u32,
83278408
8328 string: MetadataString,
8409 string: Metadata.String,
83298410 bool: bool,
83308411 u32: u32,
83318412 u64: u64,
......@@ -8356,10 +8437,10 @@ pub const Metadata = enum(u32) {
83568437 defer data.formatter.need_comma = needed_comma;
83578438 data.formatter.need_comma = false;
83588439
8359 const item = builder.metadata_items.get(@intFromEnum(node));
8360 switch (item.tag) {
8440 const node_item = node.item(builder);
8441 switch (node_item.tag) {
83618442 .expression => {
8362 var extra = builder.metadataExtraDataTrail(Expression, item.data);
8443 var extra = builder.metadataExtraDataTrail(Expression, node_item.data);
83638444 const elements = extra.trail.next(extra.data.elements_len, u32, builder);
83648445 try w.writeAll("!DIExpression(");
83658446 for (elements) |element| try format(.{
......@@ -8370,7 +8451,7 @@ pub const Metadata = enum(u32) {
83708451 try w.writeByte(')');
83718452 },
83728453 .constant => try Constant.format(.{
8373 .constant = @enumFromInt(item.data),
8454 .constant = @enumFromInt(node_item.data),
83748455 .builder = builder,
83758456 .flags = data.specialized orelse .{},
83768457 }, w),
......@@ -8378,17 +8459,17 @@ pub const Metadata = enum(u32) {
83788459 }
83798460 },
83808461 .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(.{
83828463 .value = node.value,
83838464 .function = node.function,
83848465 .builder = builder,
8385 .flags = switch (tag) {
8466 .flags = switch (node_tag) {
83868467 .local_value => data.specialized orelse .{},
83878468 .local_metadata => .{ .percent = true },
83888469 else => unreachable,
83898470 },
83908471 }, w),
8391 inline .local_inline, .local_index => |node, tag| {
8472 inline .local_inline, .local_index => |node, node_tag| {
83928473 if (data.specialized) |flags| {
83938474 if (flags.onlyPercent()) {
83948475 try w.print("{f} ", .{Type.metadata.fmt(builder, .percent)});
......@@ -8396,39 +8477,43 @@ pub const Metadata = enum(u32) {
83968477 }
83978478 try format(.{
83988479 .formatter = data.formatter,
8399 .node = @unionInit(FormatData.Node, @tagName(tag)["local_".len..], node),
8480 .node = @unionInit(FormatData.Node, @tagName(node_tag)["local_".len..], node),
84008481 .specialized = .{ .percent = true },
84018482 }, w);
84028483 },
8403 .string => |node| try w.print("{s}{f}", .{
8404 @as([]const u8, if (is_specialized) "!" else ""), node.fmt(builder),
8405 }),
8484 .string => |s| {
8485 if (is_specialized) try w.writeByte('!');
8486 try w.print("{f}", .{s.fmt(builder)});
8487 },
84068488 inline .bool, .u32, .u64 => |node| try w.print("{}", .{node}),
84078489 inline .di_flags, .sp_flags => |node| try w.print("{f}", .{node}),
84088490 .raw => |node| try w.writeAll(node),
84098491 }
84108492 }
84118493 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,
84138495 else => error{},
84148496 }!std.fmt.Alt(FormatData, format) {
84158497 const Node = @TypeOf(node);
8416 const MaybeNode = switch (@typeInfo(Node)) {
8417 .optional => Node,
8418 .null => ?noreturn,
8419 else => ?Node,
8498 const MaybeNode = switch (Node) {
8499 Metadata.Optional => ?Metadata,
8500 Metadata.String.Optional => ?Metadata.String,
8501 else => switch (@typeInfo(Node)) {
8502 .optional => Node,
8503 .null => ?noreturn,
8504 else => ?Node,
8505 },
84208506 };
84218507 const Some = @typeInfo(MaybeNode).optional.child;
84228508 return .{ .data = .{
84238509 .formatter = formatter,
84248510 .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)) {
84268515 .@"enum" => |enum_info| switch (Some) {
8427 Metadata => switch (some) {
8428 .none => .none,
8429 else => try formatter.refUnwrapped(some.unwrap(formatter.builder)),
8430 },
8431 MetadataString => .{ .string = some },
8516 Metadata.String => .{ .string = some },
84328517 else => if (enum_info.is_exhaustive)
84338518 .{ .raw = @tagName(some) }
84348519 else
......@@ -8438,15 +8523,23 @@ pub const Metadata = enum(u32) {
84388523 .bool => .{ .bool = some },
84398524 .@"struct" => switch (Some) {
84408525 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 },
84418531 Subprogram.DISPFlags => .{ .sp_flags = some },
84428532 else => @compileError("unknown type to format: " ++ @typeName(Node)),
84438533 },
84448534 .int, .comptime_int => .{ .u64 = some },
84458535 .pointer => .{ .raw = some },
84468536 else => @compileError("unknown type to format: " ++ @typeName(Node)),
8447 } else switch (@typeInfo(Node)) {
8448 .optional, .null => .none,
8449 else => unreachable,
8537 } else switch (Node) {
8538 Metadata.Optional, Metadata.String.Optional => .none,
8539 else => switch (@typeInfo(Node)) {
8540 .optional, .null => .none,
8541 else => unreachable,
8542 },
84508543 },
84518544 .specialized = special,
84528545 } };
......@@ -8460,24 +8553,26 @@ pub const Metadata = enum(u32) {
84608553 return .{ .data = .{
84618554 .formatter = formatter,
84628555 .prefix = prefix,
8463 .node = switch (value.unwrap()) {
8556 .node = node: switch (value.unwrap()) {
84648557 .instruction, .constant => .{ .local_value = .{
84658558 .value = value,
84668559 .function = function,
84678560 } },
8468 .metadata => |metadata| if (value == .none) .none else node: {
8561 .metadata => |metadata| if (value == .none) .none else {
84698562 const unwrapped = metadata.unwrap(formatter.builder);
8470 break :node if (@intFromEnum(unwrapped) >= first_local_metadata)
8471 .{ .local_metadata = .{
8563 break :node switch (unwrapped.kind) {
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 = .{
84728571 .value = function.ptrConst(formatter.builder).debug_values[
8473 @intFromEnum(unwrapped) - first_local_metadata
8572 unwrapped.index
84748573 ].toValue(),
84758574 .function = function,
8476 } }
8477 else switch (try formatter.refUnwrapped(unwrapped)) {
8478 .@"inline" => |node| .{ .local_inline = node },
8479 .index => |node| .{ .local_index = node },
8480 else => unreachable,
8575 } },
84818576 };
84828577 },
84838578 },
......@@ -8485,16 +8580,12 @@ pub const Metadata = enum(u32) {
84858580 } };
84868581 }
84878582 fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node {
8488 assert(node != .none);
8489 assert(@intFromEnum(node) < first_forward_reference);
84908583 const builder = formatter.builder;
84918584 const unwrapped_metadata = node.unwrap(builder);
8492 const tag = formatter.builder.metadata_items.items(.tag)[@intFromEnum(unwrapped_metadata)];
8493 switch (tag) {
8494 .none => unreachable,
8585 switch (unwrapped_metadata.tag(builder)) {
84958586 .expression, .constant => return .{ .@"inline" = unwrapped_metadata },
8496 else => {
8497 assert(!tag.isInline());
8587 else => |metadata_tag| {
8588 assert(!metadata_tag.isInline());
84988589 const gop = try formatter.map.getOrPut(builder.gpa, .{ .metadata = unwrapped_metadata });
84998590 return .{ .index = @intCast(gop.index) };
85008591 },
......@@ -8669,11 +8760,9 @@ pub fn init(options: Options) Allocator.Error!Builder {
86698760 assert(try self.intConst(.i32, 1) == .@"1");
86708761 assert(try self.noneConst(.token) == .none);
86718762
8672 assert(try self.metadataNone() == .none);
8673 assert(try self.metadataTuple(&.{}) == .empty_tuple);
8763 assert(try self.metadataTuple(&.{}) == Metadata.empty_tuple);
86748764
86758765 try self.metadata_string_indices.append(self.gpa, 0);
8676 assert(try self.metadataString("") == .none);
86778766
86788767 return self;
86798768}
......@@ -9232,8 +9321,8 @@ pub fn halfConst(self: *Builder, val: f16) Allocator.Error!Constant {
92329321 return self.halfConstAssumeCapacity(val);
92339322}
92349323
9235pub fn halfValue(self: *Builder, ty: Type, value: f16) Allocator.Error!Value {
9236 return (try self.halfConst(ty, value)).toValue();
9324pub fn halfValue(self: *Builder, value: f16) Allocator.Error!Value {
9325 return (try self.halfConst(value)).toValue();
92379326}
92389327
92399328pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant {
......@@ -9241,8 +9330,8 @@ pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant {
92419330 return self.bfloatConstAssumeCapacity(val);
92429331}
92439332
9244pub fn bfloatValue(self: *Builder, ty: Type, value: f32) Allocator.Error!Value {
9245 return (try self.bfloatConst(ty, value)).toValue();
9333pub fn bfloatValue(self: *Builder, value: f32) Allocator.Error!Value {
9334 return (try self.bfloatConst(value)).toValue();
92469335}
92479336
92489337pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant {
......@@ -9250,8 +9339,8 @@ pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant {
92509339 return self.floatConstAssumeCapacity(val);
92519340}
92529341
9253pub fn floatValue(self: *Builder, ty: Type, value: f32) Allocator.Error!Value {
9254 return (try self.floatConst(ty, value)).toValue();
9342pub fn floatValue(self: *Builder, value: f32) Allocator.Error!Value {
9343 return (try self.floatConst(value)).toValue();
92559344}
92569345
92579346pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant {
......@@ -9259,8 +9348,8 @@ pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant {
92599348 return self.doubleConstAssumeCapacity(val);
92609349}
92619350
9262pub fn doubleValue(self: *Builder, ty: Type, value: f64) Allocator.Error!Value {
9263 return (try self.doubleConst(ty, value)).toValue();
9351pub fn doubleValue(self: *Builder, value: f64) Allocator.Error!Value {
9352 return (try self.doubleConst(value)).toValue();
92649353}
92659354
92669355pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant {
......@@ -9268,8 +9357,8 @@ pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant {
92689357 return self.fp128ConstAssumeCapacity(val);
92699358}
92709359
9271pub fn fp128Value(self: *Builder, ty: Type, value: f128) Allocator.Error!Value {
9272 return (try self.fp128Const(ty, value)).toValue();
9360pub fn fp128Value(self: *Builder, value: f128) Allocator.Error!Value {
9361 return (try self.fp128Const(value)).toValue();
92739362}
92749363
92759364pub 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 {
92779366 return self.x86_fp80ConstAssumeCapacity(val);
92789367}
92799368
9280pub fn x86_fp80Value(self: *Builder, ty: Type, value: f80) Allocator.Error!Value {
9281 return (try self.x86_fp80Const(ty, value)).toValue();
9369pub fn x86_fp80Value(self: *Builder, value: f80) Allocator.Error!Value {
9370 return (try self.x86_fp80Const(value)).toValue();
92829371}
92839372
92849373pub 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 {
92869375 return self.ppc_fp128ConstAssumeCapacity(val);
92879376}
92889377
9289pub fn ppc_fp128Value(self: *Builder, ty: Type, value: [2]f64) Allocator.Error!Value {
9290 return (try self.ppc_fp128Const(ty, value)).toValue();
9378pub fn ppc_fp128Value(self: *Builder, value: [2]f64) Allocator.Error!Value {
9379 return (try self.ppc_fp128Const(value)).toValue();
92919380}
92929381
92939382pub 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
98709959 .none => {},
98719960 .unpredictable => try w.writeAll("!unpredictable !{}"),
98729961 _ => 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),
98749963 }),
98759964 }
98769965 },
......@@ -10153,7 +10242,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
1015310242 .none => {},
1015410243 .unpredictable => try w.writeAll("!unpredictable !{}"),
1015510244 _ => 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),
1015710246 }),
1015810247 }
1015910248 },
......@@ -10193,7 +10282,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
1019310282 const elements: []const Metadata =
1019410283 @ptrCast(self.metadata_extra.items[data.index..][0..data.len]);
1019510284 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);
1019710286 try w.writeAll(" = !{");
1019810287 metadata_formatter.need_comma = false;
1019910288 defer metadata_formatter.need_comma = undefined;
......@@ -10223,11 +10312,11 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
1022310312 }, w);
1022410313 continue;
1022510314 },
10226 .metadata => |metadata| self.metadata_items.get(@intFromEnum(metadata)),
10315 .metadata => |metadata| metadata.item(self),
1022710316 };
1022810317
1022910318 switch (metadata_item.tag) {
10230 .none, .expression, .constant => unreachable,
10319 .expression, .constant => unreachable,
1023110320 .file => {
1023210321 const extra = self.metadataExtraData(Metadata.File, metadata_item.data);
1023310322 try metadata_formatter.specialized(.@"!", .DIFile, .{
......@@ -10330,10 +10419,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
1033010419 const extra = self.metadataExtraData(Metadata.BasicType, metadata_item.data);
1033110420 try metadata_formatter.specialized(.@"!", .DIBasicType, .{
1033210421 .tag = null,
10333 .name = switch (extra.name) {
10334 .none => null,
10335 else => extra.name,
10336 },
10422 .name = extra.name,
1033710423 .size = extra.bitSize(),
1033810424 .@"align" = null,
1033910425 .encoding = @as(enum {
......@@ -10371,10 +10457,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
1037110457 .composite_array_type, .composite_vector_type => .DW_TAG_array_type,
1037210458 else => unreachable,
1037310459 }),
10374 .name = switch (extra.name) {
10375 .none => null,
10376 else => extra.name,
10377 },
10460 .name = extra.name,
1037810461 .scope = extra.scope,
1037910462 .file = null,
1038010463 .line = null,
......@@ -10409,10 +10492,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
1040910492 .derived_member_type => .DW_TAG_member,
1041010493 else => unreachable,
1041110494 }),
10412 .name = switch (extra.name) {
10413 .none => null,
10414 else => extra.name,
10415 },
10495 .name = extra.name,
1041610496 .scope = extra.scope,
1041710497 .file = null,
1041810498 .line = null,
......@@ -10505,25 +10585,6 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
1050510585 });
1050610586 try w.writeAll("}\n");
1050710587 },
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 },
1052710588 .local_var => {
1052810589 const extra = self.metadataExtraData(Metadata.LocalVar, metadata_item.data);
1052910590 try metadata_formatter.specialized(.@"!", .DILocalVariable, .{
......@@ -11914,8 +11975,8 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.
1191411975 const value = @field(extra, field.name);
1191511976 self.metadata_extra.appendAssumeCapacity(switch (field.type) {
1191611977 u32 => value,
11917 MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value),
11918 Metadata.DIFlags => @bitCast(value),
11978 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @intFromEnum(value),
11979 Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),
1191911980 else => @compileError("bad field type: " ++ @typeName(field.type)),
1192011981 });
1192111982 }
......@@ -11953,8 +12014,8 @@ fn metadataExtraDataTrail(
1195312014 inline for (fields, self.metadata_extra.items[index..][0..fields.len]) |field, value|
1195412015 @field(result, field.name) = switch (field.type) {
1195512016 u32 => value,
11956 MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value),
11957 Metadata.DIFlags => @bitCast(value),
12017 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @enumFromInt(value),
12018 Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),
1195812019 else => @compileError("bad field type: " ++ @typeName(field.type)),
1195912020 };
1196012021 return .{
......@@ -11967,48 +12028,65 @@ fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Ite
1196712028 return self.metadataExtraDataTrail(T, index).data;
1196812029}
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);
1197112033 try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len);
1197212034 try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);
1197312035 try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);
1197412036
1197512037 const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(
1197612038 bytes,
11977 MetadataString.Adapter{ .builder = self },
12039 Metadata.String.Adapter{ .builder = self },
1197812040 );
1197912041 if (!gop.found_existing) {
1198012042 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 );
1198212046 }
1198312047 return @enumFromInt(gop.index);
1198412048}
1198512049
11986pub fn metadataStringFromStrtabString(self: *Builder, str: StrtabString) Allocator.Error!MetadataString {
11987 if (str == .none or str == .empty) return MetadataString.none;
12050pub fn metadataStringFromStrtabString(
12051 self: *Builder,
12052 str: StrtabString,
12053) Allocator.Error!Metadata.String {
1198812054 return try self.metadataString(str.slice(self).?);
1198912055}
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 {
1199212062 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 );
1199412067 try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);
1199512068 return self.metadataStringFmtAssumeCapacity(fmt_str, fmt_args);
1199612069}
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 {
1199912076 self.metadata_string_bytes.printAssumeCapacity(fmt_str, fmt_args);
1200012077 return self.trailingMetadataStringAssumeCapacity();
1200112078}
1200212079
12003pub fn trailingMetadataString(self: *Builder) Allocator.Error!MetadataString {
12080pub fn trailingMetadataString(self: *Builder) Allocator.Error!Metadata.String {
1200412081 try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);
1200512082 try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);
1200612083 return self.trailingMetadataStringAssumeCapacity();
1200712084}
1200812085
12009pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString {
12086pub fn trailingMetadataStringAssumeCapacity(self: *Builder) Metadata.String {
1201012087 const start = self.metadata_string_indices.getLast();
1201112088 const bytes: []const u8 = self.metadata_string_bytes.items[start..];
12089 assert(bytes.len > 0);
1201212090 const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
1201312091 if (gop.found_existing) {
1201412092 self.metadata_string_bytes.shrinkRetainingCapacity(start);
......@@ -12018,21 +12096,16 @@ pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString {
1201812096 return @enumFromInt(gop.index);
1201912097}
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 {
1202212100 try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len);
1202312101 try self.metadata_named.ensureUnusedCapacity(self.gpa, 1);
12024 self.metadataNamedAssumeCapacity(name, operands);
12025}
12026
12027fn metadataNone(self: *Builder) Allocator.Error!Metadata {
12028 try self.ensureUnusedMetadataCapacity(1, NoExtra, 0);
12029 return self.metadataNoneAssumeCapacity();
12102 self.addNamedMetadataAssumeCapacity(name, operands);
1203012103}
1203112104
1203212105pub fn debugFile(
1203312106 self: *Builder,
12034 filename: MetadataString,
12035 directory: MetadataString,
12107 filename: ?Metadata.String,
12108 directory: ?Metadata.String,
1203612109) Allocator.Error!Metadata {
1203712110 try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0);
1203812111 return self.debugFileAssumeCapacity(filename, directory);
......@@ -12040,10 +12113,10 @@ pub fn debugFile(
1204012113
1204112114pub fn debugCompileUnit(
1204212115 self: *Builder,
12043 file: Metadata,
12044 producer: MetadataString,
12045 enums: Metadata,
12046 globals: Metadata,
12116 file: ?Metadata,
12117 producer: ?Metadata.String,
12118 enums: ?Metadata,
12119 globals: ?Metadata,
1204712120 options: Metadata.CompileUnit.Options,
1204812121) Allocator.Error!Metadata {
1204912122 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);
......@@ -12052,14 +12125,14 @@ pub fn debugCompileUnit(
1205212125
1205312126pub fn debugSubprogram(
1205412127 self: *Builder,
12055 file: Metadata,
12056 name: MetadataString,
12057 linkage_name: MetadataString,
12128 file: ?Metadata,
12129 name: ?Metadata.String,
12130 linkage_name: ?Metadata.String,
1205812131 line: u32,
1205912132 scope_line: u32,
12060 ty: Metadata,
12133 ty: ?Metadata,
1206112134 options: Metadata.Subprogram.Options,
12062 compile_unit: Metadata,
12135 compile_unit: ?Metadata,
1206312136) Allocator.Error!Metadata {
1206412137 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);
1206512138 return self.debugSubprogramAssumeCapacity(
......@@ -12074,32 +12147,60 @@ pub fn debugSubprogram(
1207412147 );
1207512148}
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 {
1207812157 try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0);
1207912158 return self.debugLexicalBlockAssumeCapacity(scope, file, line, column);
1208012159}
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 {
1208312168 try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0);
1208412169 return self.debugLocationAssumeCapacity(line, column, scope, inlined_at);
1208512170}
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 {
1208812177 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
1208912178 return self.debugBoolTypeAssumeCapacity(name, size_in_bits);
1209012179}
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 {
1209312186 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
1209412187 return self.debugUnsignedTypeAssumeCapacity(name, size_in_bits);
1209512188}
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 {
1209812195 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
1209912196 return self.debugSignedTypeAssumeCapacity(name, size_in_bits);
1210012197}
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 {
1210312204 try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
1210412205 return self.debugFloatTypeAssumeCapacity(name, size_in_bits);
1210512206}
......@@ -12111,14 +12212,14 @@ pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata {
1211112212
1211212213pub fn debugStructType(
1211312214 self: *Builder,
12114 name: MetadataString,
12115 file: Metadata,
12116 scope: Metadata,
12215 name: ?Metadata.String,
12216 file: ?Metadata,
12217 scope: ?Metadata,
1211712218 line: u32,
12118 underlying_type: Metadata,
12219 underlying_type: ?Metadata,
1211912220 size_in_bits: u64,
1212012221 align_in_bits: u64,
12121 fields_tuple: Metadata,
12222 fields_tuple: ?Metadata,
1212212223) Allocator.Error!Metadata {
1212312224 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
1212412225 return self.debugStructTypeAssumeCapacity(
......@@ -12135,14 +12236,14 @@ pub fn debugStructType(
1213512236
1213612237pub fn debugUnionType(
1213712238 self: *Builder,
12138 name: MetadataString,
12139 file: Metadata,
12140 scope: Metadata,
12239 name: ?Metadata.String,
12240 file: ?Metadata,
12241 scope: ?Metadata,
1214112242 line: u32,
12142 underlying_type: Metadata,
12243 underlying_type: ?Metadata,
1214312244 size_in_bits: u64,
1214412245 align_in_bits: u64,
12145 fields_tuple: Metadata,
12246 fields_tuple: ?Metadata,
1214612247) Allocator.Error!Metadata {
1214712248 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
1214812249 return self.debugUnionTypeAssumeCapacity(
......@@ -12159,14 +12260,14 @@ pub fn debugUnionType(
1215912260
1216012261pub fn debugEnumerationType(
1216112262 self: *Builder,
12162 name: MetadataString,
12163 file: Metadata,
12164 scope: Metadata,
12263 name: ?Metadata.String,
12264 file: ?Metadata,
12265 scope: ?Metadata,
1216512266 line: u32,
12166 underlying_type: Metadata,
12267 underlying_type: ?Metadata,
1216712268 size_in_bits: u64,
1216812269 align_in_bits: u64,
12169 fields_tuple: Metadata,
12270 fields_tuple: ?Metadata,
1217012271) Allocator.Error!Metadata {
1217112272 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
1217212273 return self.debugEnumerationTypeAssumeCapacity(
......@@ -12183,14 +12284,14 @@ pub fn debugEnumerationType(
1218312284
1218412285pub fn debugArrayType(
1218512286 self: *Builder,
12186 name: MetadataString,
12187 file: Metadata,
12188 scope: Metadata,
12287 name: ?Metadata.String,
12288 file: ?Metadata,
12289 scope: ?Metadata,
1218912290 line: u32,
12190 underlying_type: Metadata,
12291 underlying_type: ?Metadata,
1219112292 size_in_bits: u64,
1219212293 align_in_bits: u64,
12193 fields_tuple: Metadata,
12294 fields_tuple: ?Metadata,
1219412295) Allocator.Error!Metadata {
1219512296 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
1219612297 return self.debugArrayTypeAssumeCapacity(
......@@ -12207,14 +12308,14 @@ pub fn debugArrayType(
1220712308
1220812309pub fn debugVectorType(
1220912310 self: *Builder,
12210 name: MetadataString,
12211 file: Metadata,
12212 scope: Metadata,
12311 name: ?Metadata.String,
12312 file: ?Metadata,
12313 scope: ?Metadata,
1221312314 line: u32,
12214 underlying_type: Metadata,
12315 underlying_type: ?Metadata,
1221512316 size_in_bits: u64,
1221612317 align_in_bits: u64,
12217 fields_tuple: Metadata,
12318 fields_tuple: ?Metadata,
1221812319) Allocator.Error!Metadata {
1221912320 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
1222012321 return self.debugVectorTypeAssumeCapacity(
......@@ -12231,11 +12332,11 @@ pub fn debugVectorType(
1223112332
1223212333pub fn debugPointerType(
1223312334 self: *Builder,
12234 name: MetadataString,
12235 file: Metadata,
12236 scope: Metadata,
12335 name: ?Metadata.String,
12336 file: ?Metadata,
12337 scope: ?Metadata,
1223712338 line: u32,
12238 underlying_type: Metadata,
12339 underlying_type: ?Metadata,
1223912340 size_in_bits: u64,
1224012341 align_in_bits: u64,
1224112342 offset_in_bits: u64,
......@@ -12255,11 +12356,11 @@ pub fn debugPointerType(
1225512356
1225612357pub fn debugMemberType(
1225712358 self: *Builder,
12258 name: MetadataString,
12259 file: Metadata,
12260 scope: Metadata,
12359 name: ?Metadata.String,
12360 file: ?Metadata,
12361 scope: ?Metadata,
1226112362 line: u32,
12262 underlying_type: Metadata,
12363 underlying_type: ?Metadata,
1226312364 size_in_bits: u64,
1226412365 align_in_bits: u64,
1226512366 offset_in_bits: u64,
......@@ -12277,17 +12378,14 @@ pub fn debugMemberType(
1227712378 );
1227812379}
1227912380
12280pub fn debugSubroutineType(
12281 self: *Builder,
12282 types_tuple: Metadata,
12283) Allocator.Error!Metadata {
12381pub fn debugSubroutineType(self: *Builder, types_tuple: ?Metadata) Allocator.Error!Metadata {
1228412382 try self.ensureUnusedMetadataCapacity(1, Metadata.SubroutineType, 0);
1228512383 return self.debugSubroutineTypeAssumeCapacity(types_tuple);
1228612384}
1228712385
1228812386pub fn debugEnumerator(
1228912387 self: *Builder,
12290 name: MetadataString,
12388 name: ?Metadata.String,
1229112389 unsigned: bool,
1229212390 bit_width: u32,
1229312391 value: std.math.big.int.Const,
......@@ -12300,55 +12398,37 @@ pub fn debugEnumerator(
1230012398
1230112399pub fn debugSubrange(
1230212400 self: *Builder,
12303 lower_bound: Metadata,
12304 count: Metadata,
12401 lower_bound: ?Metadata,
12402 count: ?Metadata,
1230512403) Allocator.Error!Metadata {
1230612404 try self.ensureUnusedMetadataCapacity(1, Metadata.Subrange, 0);
1230712405 return self.debugSubrangeAssumeCapacity(lower_bound, count);
1230812406}
1230912407
12310pub fn debugExpression(
12311 self: *Builder,
12312 elements: []const u32,
12313) Allocator.Error!Metadata {
12408pub fn debugExpression(self: *Builder, elements: []const u32) Allocator.Error!Metadata {
1231412409 try self.ensureUnusedMetadataCapacity(1, Metadata.Expression, elements.len);
1231512410 return self.debugExpressionAssumeCapacity(elements);
1231612411}
1231712412
12318pub fn metadataTuple(
12319 self: *Builder,
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);
12413pub fn metadataTuple(self: *Builder, elements: []const Metadata) Allocator.Error!Metadata {
12414 return self.metadataTupleOptionals(@ptrCast(elements));
1233312415}
1233412416
12335pub fn metadataModuleFlag(
12417pub fn metadataTupleOptionals(
1233612418 self: *Builder,
12337 behavior: Metadata,
12338 name: MetadataString,
12339 constant: Metadata,
12419 elements: []const Metadata.Optional,
1234012420) Allocator.Error!Metadata {
12341 try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0);
12342 return self.metadataModuleFlagAssumeCapacity(behavior, name, constant);
12421 try self.ensureUnusedMetadataCapacity(1, Metadata.Tuple, elements.len);
12422 return self.metadataTupleOptionalsAssumeCapacity(elements);
1234312423}
1234412424
1234512425pub fn debugLocalVar(
1234612426 self: *Builder,
12347 name: MetadataString,
12348 file: Metadata,
12349 scope: Metadata,
12427 name: ?Metadata.String,
12428 file: ?Metadata,
12429 scope: ?Metadata,
1235012430 line: u32,
12351 ty: Metadata,
12431 ty: ?Metadata,
1235212432) Allocator.Error!Metadata {
1235312433 try self.ensureUnusedMetadataCapacity(1, Metadata.LocalVar, 0);
1235412434 return self.debugLocalVarAssumeCapacity(name, file, scope, line, ty);
......@@ -12356,11 +12436,11 @@ pub fn debugLocalVar(
1235612436
1235712437pub fn debugParameter(
1235812438 self: *Builder,
12359 name: MetadataString,
12360 file: Metadata,
12361 scope: Metadata,
12439 name: ?Metadata.String,
12440 file: ?Metadata,
12441 scope: ?Metadata,
1236212442 line: u32,
12363 ty: Metadata,
12443 ty: ?Metadata,
1236412444 arg_no: u32,
1236512445) Allocator.Error!Metadata {
1236612446 try self.ensureUnusedMetadataCapacity(1, Metadata.Parameter, 0);
......@@ -12369,12 +12449,12 @@ pub fn debugParameter(
1236912449
1237012450pub fn debugGlobalVar(
1237112451 self: *Builder,
12372 name: MetadataString,
12373 linkage_name: MetadataString,
12374 file: Metadata,
12375 scope: Metadata,
12452 name: ?Metadata.String,
12453 linkage_name: ?Metadata.String,
12454 file: ?Metadata,
12455 scope: ?Metadata,
1237612456 line: u32,
12377 ty: Metadata,
12457 ty: ?Metadata,
1237812458 variable: Variable.Index,
1237912459 options: Metadata.GlobalVar.Options,
1238012460) Allocator.Error!Metadata {
......@@ -12393,8 +12473,8 @@ pub fn debugGlobalVar(
1239312473
1239412474pub fn debugGlobalVarExpression(
1239512475 self: *Builder,
12396 variable: Metadata,
12397 expression: Metadata,
12476 variable: ?Metadata,
12477 expression: ?Metadata,
1239812478) Allocator.Error!Metadata {
1239912479 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVarExpression, 0);
1240012480 return self.debugGlobalVarExpressionAssumeCapacity(variable, expression);
......@@ -12405,13 +12485,11 @@ pub fn metadataConstant(self: *Builder, value: Constant) Allocator.Error!Metadat
1240512485 return self.metadataConstantAssumeCapacity(value);
1240612486}
1240712487
12408pub fn debugForwardReferenceSetType(self: *Builder, fwd_ref: Metadata, ty: Metadata) void {
12409 assert(
12410 @intFromEnum(fwd_ref) >= Metadata.first_forward_reference and
12411 @intFromEnum(fwd_ref) <= Metadata.first_local_metadata,
12412 );
12413 const index = @intFromEnum(fwd_ref) - Metadata.first_forward_reference;
12414 self.metadata_forward_references.items[index] = ty;
12488pub fn resolveDebugForwardReference(self: *Builder, fwd_ref: Metadata, value: Metadata) void {
12489 assert(fwd_ref.kind == .forward);
12490 const resolved = &self.metadata_forward_references.items[fwd_ref.index];
12491 assert(resolved.is_none);
12492 resolved.* = value.toOptional();
1241512493}
1241612494
1241712495fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata {
......@@ -12450,41 +12528,20 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp
1245012528 .data = self.addMetadataExtraAssumeCapacity(value),
1245112529 });
1245212530 }
12453 return @enumFromInt(gop.index);
12531 return .{ .index = @intCast(gop.index), .kind = .node };
1245412532}
1245512533
1245612534fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata {
12457 const Key = struct { tag: Metadata.Tag, index: Metadata };
12458 const Adapter = struct {
12459 pub fn hash(_: @This(), key: Key) u32 {
12460 return @truncate(std.hash.Wyhash.hash(
12461 std.hash.int(@intFromEnum(key.tag)),
12462 std.mem.asBytes(&key.index),
12463 ));
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);
12535 const index = self.metadata_items.len;
12536 _ = self.metadata_map.entries.addOneAssumeCapacity();
12537 self.metadata_items.appendAssumeCapacity(.{
12538 .tag = tag,
12539 .data = self.addMetadataExtraAssumeCapacity(value),
12540 });
12541 return .{ .index = @intCast(index), .kind = .node };
1248512542}
1248612543
12487fn metadataNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void {
12544fn addNamedMetadataAssumeCapacity(self: *Builder, name: String, operands: []const Metadata) void {
1248812545 assert(name != .none);
1248912546 const extra_index: u32 = @intCast(self.metadata_extra.items.len);
1249012547 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands));
......@@ -12496,119 +12553,127 @@ fn metadataNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: [
1249612553 };
1249712554}
1249812555
12499pub fn metadataNoneAssumeCapacity(self: *Builder) Metadata {
12500 return self.metadataSimpleAssumeCapacity(.none, .{});
12501}
12502
1250312556fn debugFileAssumeCapacity(
1250412557 self: *Builder,
12505 filename: MetadataString,
12506 directory: MetadataString,
12558 filename: ?Metadata.String,
12559 directory: ?Metadata.String,
1250712560) Metadata {
1250812561 assert(!self.strip);
1250912562 return self.metadataSimpleAssumeCapacity(.file, Metadata.File{
12510 .filename = filename,
12511 .directory = directory,
12563 .filename = .wrap(filename),
12564 .directory = .wrap(directory),
1251212565 });
1251312566}
1251412567
1251512568pub fn debugCompileUnitAssumeCapacity(
1251612569 self: *Builder,
12517 file: Metadata,
12518 producer: MetadataString,
12519 enums: Metadata,
12520 globals: Metadata,
12570 file: ?Metadata,
12571 producer: ?Metadata.String,
12572 enums: ?Metadata,
12573 globals: ?Metadata,
1252112574 options: Metadata.CompileUnit.Options,
1252212575) Metadata {
1252312576 assert(!self.strip);
1252412577 return self.metadataDistinctAssumeCapacity(
1252512578 if (options.optimized) .@"compile_unit optimized" else .compile_unit,
1252612579 Metadata.CompileUnit{
12527 .file = file,
12528 .producer = producer,
12529 .enums = enums,
12530 .globals = globals,
12580 .file = .wrap(file),
12581 .producer = .wrap(producer),
12582 .enums = .wrap(enums),
12583 .globals = .wrap(globals),
1253112584 },
1253212585 );
1253312586}
1253412587
1253512588fn debugSubprogramAssumeCapacity(
1253612589 self: *Builder,
12537 file: Metadata,
12538 name: MetadataString,
12539 linkage_name: MetadataString,
12590 file: ?Metadata,
12591 name: ?Metadata.String,
12592 linkage_name: ?Metadata.String,
1254012593 line: u32,
1254112594 scope_line: u32,
12542 ty: Metadata,
12595 ty: ?Metadata,
1254312596 options: Metadata.Subprogram.Options,
12544 compile_unit: Metadata,
12597 compile_unit: ?Metadata,
1254512598) Metadata {
1254612599 assert(!self.strip);
1254712600 const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) +
1254812601 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
1254912602 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
12550 .file = file,
12551 .name = name,
12552 .linkage_name = linkage_name,
12603 .file = .wrap(file),
12604 .name = .wrap(name),
12605 .linkage_name = .wrap(linkage_name),
1255312606 .line = line,
1255412607 .scope_line = scope_line,
12555 .ty = ty,
12608 .ty = .wrap(ty),
1255612609 .di_flags = options.di_flags,
12557 .compile_unit = compile_unit,
12610 .compile_unit = .wrap(compile_unit),
1255812611 });
1255912612}
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 {
1256212621 assert(!self.strip);
1256312622 return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{
12564 .scope = scope,
12565 .file = file,
12623 .scope = .wrap(scope),
12624 .file = .wrap(file),
1256612625 .line = line,
1256712626 .column = column,
1256812627 });
1256912628}
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 {
1257212637 assert(!self.strip);
1257312638 return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{
1257412639 .line = line,
1257512640 .column = column,
1257612641 .scope = scope,
12577 .inlined_at = inlined_at,
12642 .inlined_at = .wrap(inlined_at),
1257812643 });
1257912644}
1258012645
12581fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12646fn debugBoolTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
1258212647 assert(!self.strip);
1258312648 return self.metadataSimpleAssumeCapacity(.basic_bool_type, Metadata.BasicType{
12584 .name = name,
12649 .name = .wrap(name),
1258512650 .size_in_bits_lo = @truncate(size_in_bits),
1258612651 .size_in_bits_hi = @truncate(size_in_bits >> 32),
1258712652 });
1258812653}
1258912654
12590fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12655fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
1259112656 assert(!self.strip);
1259212657 return self.metadataSimpleAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{
12593 .name = name,
12658 .name = .wrap(name),
1259412659 .size_in_bits_lo = @truncate(size_in_bits),
1259512660 .size_in_bits_hi = @truncate(size_in_bits >> 32),
1259612661 });
1259712662}
1259812663
12599fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12664fn debugSignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
1260012665 assert(!self.strip);
1260112666 return self.metadataSimpleAssumeCapacity(.basic_signed_type, Metadata.BasicType{
12602 .name = name,
12667 .name = .wrap(name),
1260312668 .size_in_bits_lo = @truncate(size_in_bits),
1260412669 .size_in_bits_hi = @truncate(size_in_bits >> 32),
1260512670 });
1260612671}
1260712672
12608fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12673fn debugFloatTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
1260912674 assert(!self.strip);
1261012675 return self.metadataSimpleAssumeCapacity(.basic_float_type, Metadata.BasicType{
12611 .name = name,
12676 .name = .wrap(name),
1261212677 .size_in_bits_lo = @truncate(size_in_bits),
1261312678 .size_in_bits_hi = @truncate(size_in_bits >> 32),
1261412679 });
......@@ -12616,21 +12681,21 @@ fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bi
1261612681
1261712682fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata {
1261812683 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;
1262012685 self.metadata_forward_references.appendAssumeCapacity(.none);
12621 return @enumFromInt(index);
12686 return .{ .index = @intCast(index), .kind = .forward };
1262212687}
1262312688
1262412689fn debugStructTypeAssumeCapacity(
1262512690 self: *Builder,
12626 name: MetadataString,
12627 file: Metadata,
12628 scope: Metadata,
12691 name: ?Metadata.String,
12692 file: ?Metadata,
12693 scope: ?Metadata,
1262912694 line: u32,
12630 underlying_type: Metadata,
12695 underlying_type: ?Metadata,
1263112696 size_in_bits: u64,
1263212697 align_in_bits: u64,
12633 fields_tuple: Metadata,
12698 fields_tuple: ?Metadata,
1263412699) Metadata {
1263512700 assert(!self.strip);
1263612701 return self.debugCompositeTypeAssumeCapacity(
......@@ -12648,14 +12713,14 @@ fn debugStructTypeAssumeCapacity(
1264812713
1264912714fn debugUnionTypeAssumeCapacity(
1265012715 self: *Builder,
12651 name: MetadataString,
12652 file: Metadata,
12653 scope: Metadata,
12716 name: ?Metadata.String,
12717 file: ?Metadata,
12718 scope: ?Metadata,
1265412719 line: u32,
12655 underlying_type: Metadata,
12720 underlying_type: ?Metadata,
1265612721 size_in_bits: u64,
1265712722 align_in_bits: u64,
12658 fields_tuple: Metadata,
12723 fields_tuple: ?Metadata,
1265912724) Metadata {
1266012725 assert(!self.strip);
1266112726 return self.debugCompositeTypeAssumeCapacity(
......@@ -12673,14 +12738,14 @@ fn debugUnionTypeAssumeCapacity(
1267312738
1267412739fn debugEnumerationTypeAssumeCapacity(
1267512740 self: *Builder,
12676 name: MetadataString,
12677 file: Metadata,
12678 scope: Metadata,
12741 name: ?Metadata.String,
12742 file: ?Metadata,
12743 scope: ?Metadata,
1267912744 line: u32,
12680 underlying_type: Metadata,
12745 underlying_type: ?Metadata,
1268112746 size_in_bits: u64,
1268212747 align_in_bits: u64,
12683 fields_tuple: Metadata,
12748 fields_tuple: ?Metadata,
1268412749) Metadata {
1268512750 assert(!self.strip);
1268612751 return self.debugCompositeTypeAssumeCapacity(
......@@ -12698,14 +12763,14 @@ fn debugEnumerationTypeAssumeCapacity(
1269812763
1269912764fn debugArrayTypeAssumeCapacity(
1270012765 self: *Builder,
12701 name: MetadataString,
12702 file: Metadata,
12703 scope: Metadata,
12766 name: ?Metadata.String,
12767 file: ?Metadata,
12768 scope: ?Metadata,
1270412769 line: u32,
12705 underlying_type: Metadata,
12770 underlying_type: ?Metadata,
1270612771 size_in_bits: u64,
1270712772 align_in_bits: u64,
12708 fields_tuple: Metadata,
12773 fields_tuple: ?Metadata,
1270912774) Metadata {
1271012775 assert(!self.strip);
1271112776 return self.debugCompositeTypeAssumeCapacity(
......@@ -12723,14 +12788,14 @@ fn debugArrayTypeAssumeCapacity(
1272312788
1272412789fn debugVectorTypeAssumeCapacity(
1272512790 self: *Builder,
12726 name: MetadataString,
12727 file: Metadata,
12728 scope: Metadata,
12791 name: ?Metadata.String,
12792 file: ?Metadata,
12793 scope: ?Metadata,
1272912794 line: u32,
12730 underlying_type: Metadata,
12795 underlying_type: ?Metadata,
1273112796 size_in_bits: u64,
1273212797 align_in_bits: u64,
12733 fields_tuple: Metadata,
12798 fields_tuple: ?Metadata,
1273412799) Metadata {
1273512800 assert(!self.strip);
1273612801 return self.debugCompositeTypeAssumeCapacity(
......@@ -12749,48 +12814,48 @@ fn debugVectorTypeAssumeCapacity(
1274912814fn debugCompositeTypeAssumeCapacity(
1275012815 self: *Builder,
1275112816 tag: Metadata.Tag,
12752 name: MetadataString,
12753 file: Metadata,
12754 scope: Metadata,
12817 name: ?Metadata.String,
12818 file: ?Metadata,
12819 scope: ?Metadata,
1275512820 line: u32,
12756 underlying_type: Metadata,
12821 underlying_type: ?Metadata,
1275712822 size_in_bits: u64,
1275812823 align_in_bits: u64,
12759 fields_tuple: Metadata,
12824 fields_tuple: ?Metadata,
1276012825) Metadata {
1276112826 assert(!self.strip);
1276212827 return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{
12763 .name = name,
12764 .file = file,
12765 .scope = scope,
12828 .name = .wrap(name),
12829 .file = .wrap(file),
12830 .scope = .wrap(scope),
1276612831 .line = line,
12767 .underlying_type = underlying_type,
12832 .underlying_type = .wrap(underlying_type),
1276812833 .size_in_bits_lo = @truncate(size_in_bits),
1276912834 .size_in_bits_hi = @truncate(size_in_bits >> 32),
1277012835 .align_in_bits_lo = @truncate(align_in_bits),
1277112836 .align_in_bits_hi = @truncate(align_in_bits >> 32),
12772 .fields_tuple = fields_tuple,
12837 .fields_tuple = .wrap(fields_tuple),
1277312838 });
1277412839}
1277512840
1277612841fn debugPointerTypeAssumeCapacity(
1277712842 self: *Builder,
12778 name: MetadataString,
12779 file: Metadata,
12780 scope: Metadata,
12843 name: ?Metadata.String,
12844 file: ?Metadata,
12845 scope: ?Metadata,
1278112846 line: u32,
12782 underlying_type: Metadata,
12847 underlying_type: ?Metadata,
1278312848 size_in_bits: u64,
1278412849 align_in_bits: u64,
1278512850 offset_in_bits: u64,
1278612851) Metadata {
1278712852 assert(!self.strip);
1278812853 return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{
12789 .name = name,
12790 .file = file,
12791 .scope = scope,
12854 .name = .wrap(name),
12855 .file = .wrap(file),
12856 .scope = .wrap(scope),
1279212857 .line = line,
12793 .underlying_type = underlying_type,
12858 .underlying_type = .wrap(underlying_type),
1279412859 .size_in_bits_lo = @truncate(size_in_bits),
1279512860 .size_in_bits_hi = @truncate(size_in_bits >> 32),
1279612861 .align_in_bits_lo = @truncate(align_in_bits),
......@@ -12802,22 +12867,22 @@ fn debugPointerTypeAssumeCapacity(
1280212867
1280312868fn debugMemberTypeAssumeCapacity(
1280412869 self: *Builder,
12805 name: MetadataString,
12806 file: Metadata,
12807 scope: Metadata,
12870 name: ?Metadata.String,
12871 file: ?Metadata,
12872 scope: ?Metadata,
1280812873 line: u32,
12809 underlying_type: Metadata,
12874 underlying_type: ?Metadata,
1281012875 size_in_bits: u64,
1281112876 align_in_bits: u64,
1281212877 offset_in_bits: u64,
1281312878) Metadata {
1281412879 assert(!self.strip);
1281512880 return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{
12816 .name = name,
12817 .file = file,
12818 .scope = scope,
12881 .name = .wrap(name),
12882 .file = .wrap(file),
12883 .scope = .wrap(scope),
1281912884 .line = line,
12820 .underlying_type = underlying_type,
12885 .underlying_type = .wrap(underlying_type),
1282112886 .size_in_bits_lo = @truncate(size_in_bits),
1282212887 .size_in_bits_hi = @truncate(size_in_bits >> 32),
1282312888 .align_in_bits_lo = @truncate(align_in_bits),
......@@ -12827,19 +12892,16 @@ fn debugMemberTypeAssumeCapacity(
1282712892 });
1282812893}
1282912894
12830fn debugSubroutineTypeAssumeCapacity(
12831 self: *Builder,
12832 types_tuple: Metadata,
12833) Metadata {
12895fn debugSubroutineTypeAssumeCapacity(self: *Builder, types_tuple: ?Metadata) Metadata {
1283412896 assert(!self.strip);
1283512897 return self.metadataSimpleAssumeCapacity(.subroutine_type, Metadata.SubroutineType{
12836 .types_tuple = types_tuple,
12898 .types_tuple = .wrap(types_tuple),
1283712899 });
1283812900}
1283912901
1284012902fn debugEnumeratorAssumeCapacity(
1284112903 self: *Builder,
12842 name: MetadataString,
12904 name: ?Metadata.String,
1284312905 unsigned: bool,
1284412906 bit_width: u32,
1284512907 value: std.math.big.int.Const,
......@@ -12847,7 +12909,7 @@ fn debugEnumeratorAssumeCapacity(
1284712909 assert(!self.strip);
1284812910 const Key = struct {
1284912911 tag: Metadata.Tag,
12850 name: MetadataString,
12912 name: Metadata.String.Optional,
1285112913 bit_width: u32,
1285212914 value: std.math.big.int.Const,
1285312915 };
......@@ -12886,15 +12948,12 @@ fn debugEnumeratorAssumeCapacity(
1288612948
1288712949 assert(!(tag == .enumerator_unsigned and !value.positive));
1288812950
12889 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
12890 Key{
12891 .tag = tag,
12892 .name = name,
12893 .bit_width = bit_width,
12894 .value = value,
12895 },
12896 Adapter{ .builder = self },
12897 );
12951 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(Key{
12952 .tag = tag,
12953 .name = .wrap(name),
12954 .bit_width = bit_width,
12955 .value = value,
12956 }, Adapter{ .builder = self });
1289812957
1289912958 if (!gop.found_existing) {
1290012959 gop.key_ptr.* = {};
......@@ -12902,7 +12961,7 @@ fn debugEnumeratorAssumeCapacity(
1290212961 self.metadata_items.appendAssumeCapacity(.{
1290312962 .tag = tag,
1290412963 .data = self.addMetadataExtraAssumeCapacity(Metadata.Enumerator{
12905 .name = name,
12964 .name = .wrap(name),
1290612965 .bit_width = bit_width,
1290712966 .limbs_index = @intCast(self.metadata_limbs.items.len),
1290812967 .limbs_len = @intCast(value.limbs.len),
......@@ -12910,25 +12969,18 @@ fn debugEnumeratorAssumeCapacity(
1291012969 });
1291112970 self.metadata_limbs.appendSliceAssumeCapacity(value.limbs);
1291212971 }
12913 return @enumFromInt(gop.index);
12972 return .{ .index = @intCast(gop.index), .kind = .node };
1291412973}
1291512974
12916fn debugSubrangeAssumeCapacity(
12917 self: *Builder,
12918 lower_bound: Metadata,
12919 count: Metadata,
12920) Metadata {
12975fn debugSubrangeAssumeCapacity(self: *Builder, lower_bound: ?Metadata, count: ?Metadata) Metadata {
1292112976 assert(!self.strip);
1292212977 return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{
12923 .lower_bound = lower_bound,
12924 .count = count,
12978 .lower_bound = .wrap(lower_bound),
12979 .count = .wrap(count),
1292512980 });
1292612981}
1292712982
12928fn debugExpressionAssumeCapacity(
12929 self: *Builder,
12930 elements: []const u32,
12931) Metadata {
12983fn debugExpressionAssumeCapacity(self: *Builder, elements: []const u32) Metadata {
1293212984 assert(!self.strip);
1293312985 const Key = struct {
1293412986 elements: []const u32,
......@@ -12936,13 +12988,15 @@ fn debugExpressionAssumeCapacity(
1293612988 const Adapter = struct {
1293712989 builder: *const Builder,
1293812990 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)));
1294012993 hasher.update(std.mem.sliceAsBytes(key.elements));
1294112994 return @truncate(hasher.final());
1294212995 }
1294312996
1294412997 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;
1294613000 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
1294713001 var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Expression, rhs_data);
1294813002 return std.mem.eql(
......@@ -12969,15 +13023,12 @@ fn debugExpressionAssumeCapacity(
1296913023 });
1297013024 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements));
1297113025 }
12972 return @enumFromInt(gop.index);
13026 return .{ .index = @intCast(gop.index), .kind = .node };
1297313027}
1297413028
12975fn metadataTupleAssumeCapacity(
12976 self: *Builder,
12977 elements: []const Metadata,
12978) Metadata {
13029fn metadataTupleOptionalsAssumeCapacity(self: *Builder, elements: []const Metadata.Optional) Metadata {
1297913030 const Key = struct {
12980 elements: []const Metadata,
13031 elements: []const Metadata.Optional,
1298113032 };
1298213033 const Adapter = struct {
1298313034 builder: *const Builder,
......@@ -12992,9 +13043,9 @@ fn metadataTupleAssumeCapacity(
1299213043 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
1299313044 var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Tuple, rhs_data);
1299413045 return std.mem.eql(
12995 Metadata,
13046 Metadata.Optional,
1299613047 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),
1299813049 );
1299913050 }
1300013051 };
......@@ -13015,117 +13066,55 @@ fn metadataTupleAssumeCapacity(
1301513066 });
1301613067 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements));
1301713068 }
13018 return @enumFromInt(gop.index);
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 });
13069 return .{ .index = @intCast(gop.index), .kind = .node };
1308113070}
1308213071
1308313072fn debugLocalVarAssumeCapacity(
1308413073 self: *Builder,
13085 name: MetadataString,
13086 file: Metadata,
13087 scope: Metadata,
13074 name: ?Metadata.String,
13075 file: ?Metadata,
13076 scope: ?Metadata,
1308813077 line: u32,
13089 ty: Metadata,
13078 ty: ?Metadata,
1309013079) Metadata {
1309113080 assert(!self.strip);
1309213081 return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{
13093 .name = name,
13094 .file = file,
13095 .scope = scope,
13082 .name = .wrap(name),
13083 .file = .wrap(file),
13084 .scope = .wrap(scope),
1309613085 .line = line,
13097 .ty = ty,
13086 .ty = .wrap(ty),
1309813087 });
1309913088}
1310013089
1310113090fn debugParameterAssumeCapacity(
1310213091 self: *Builder,
13103 name: MetadataString,
13104 file: Metadata,
13105 scope: Metadata,
13092 name: ?Metadata.String,
13093 file: ?Metadata,
13094 scope: ?Metadata,
1310613095 line: u32,
13107 ty: Metadata,
13096 ty: ?Metadata,
1310813097 arg_no: u32,
1310913098) Metadata {
1311013099 assert(!self.strip);
1311113100 return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{
13112 .name = name,
13113 .file = file,
13114 .scope = scope,
13101 .name = .wrap(name),
13102 .file = .wrap(file),
13103 .scope = .wrap(scope),
1311513104 .line = line,
13116 .ty = ty,
13105 .ty = .wrap(ty),
1311713106 .arg_no = arg_no,
1311813107 });
1311913108}
1312013109
1312113110fn debugGlobalVarAssumeCapacity(
1312213111 self: *Builder,
13123 name: MetadataString,
13124 linkage_name: MetadataString,
13125 file: Metadata,
13126 scope: Metadata,
13112 name: ?Metadata.String,
13113 linkage_name: ?Metadata.String,
13114 file: ?Metadata,
13115 scope: ?Metadata,
1312713116 line: u32,
13128 ty: Metadata,
13117 ty: ?Metadata,
1312913118 variable: Variable.Index,
1313013119 options: Metadata.GlobalVar.Options,
1313113120) Metadata {
......@@ -13133,12 +13122,12 @@ fn debugGlobalVarAssumeCapacity(
1313313122 return self.metadataDistinctAssumeCapacity(
1313413123 if (options.local) .@"global_var local" else .global_var,
1313513124 Metadata.GlobalVar{
13136 .name = name,
13137 .linkage_name = linkage_name,
13138 .file = file,
13139 .scope = scope,
13125 .name = .wrap(name),
13126 .linkage_name = .wrap(linkage_name),
13127 .file = .wrap(file),
13128 .scope = .wrap(scope),
1314013129 .line = line,
13141 .ty = ty,
13130 .ty = .wrap(ty),
1314213131 .variable = variable,
1314313132 },
1314413133 );
......@@ -13146,13 +13135,13 @@ fn debugGlobalVarAssumeCapacity(
1314613135
1314713136fn debugGlobalVarExpressionAssumeCapacity(
1314813137 self: *Builder,
13149 variable: Metadata,
13150 expression: Metadata,
13138 variable: ?Metadata,
13139 expression: ?Metadata,
1315113140) Metadata {
1315213141 assert(!self.strip);
1315313142 return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{
13154 .variable = variable,
13155 .expression = expression,
13143 .variable = .wrap(variable),
13144 .expression = .wrap(expression),
1315613145 });
1315713146}
1315813147
......@@ -13185,7 +13174,7 @@ fn metadataConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {
1318513174 .data = @intFromEnum(constant),
1318613175 });
1318713176 }
13188 return @enumFromInt(gop.index);
13177 return .{ .index = @intCast(gop.index), .kind = .node };
1318913178}
1319013179
1319113180pub const Producer = struct {
......@@ -13209,8 +13198,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1320913198
1321013199 // IDENTIFICATION_BLOCK
1321113200 {
13212 const Identification = ir.Identification;
13213 var identification_block = try bitcode.enterTopBlock(Identification);
13201 const IdentificationBlock = ir.IdentificationBlock;
13202 var identification_block = try bitcode.enterTopBlock(IdentificationBlock);
1321413203
1321513204 const producer_str = try std.fmt.allocPrint(self.gpa, "{s} {d}.{d}.{d}", .{
1321613205 producer.name,
......@@ -13220,42 +13209,42 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1322013209 });
1322113210 defer self.gpa.free(producer_str);
1322213211
13223 try identification_block.writeAbbrev(Identification.Version{ .string = producer_str });
13224 try identification_block.writeAbbrev(Identification.Epoch{ .epoch = 0 });
13212 try identification_block.writeAbbrev(IdentificationBlock.Version{ .string = producer_str });
13213 try identification_block.writeAbbrev(IdentificationBlock.Epoch{ .epoch = 0 });
1322513214
1322613215 try identification_block.end();
1322713216 }
1322813217
1322913218 // MODULE_BLOCK
1323013219 {
13231 const Module = ir.Module;
13232 var module_block = try bitcode.enterTopBlock(Module);
13220 const ModuleBlock = ir.ModuleBlock;
13221 var module_block = try bitcode.enterTopBlock(ModuleBlock);
1323313222
13234 try module_block.writeAbbrev(Module.Version{});
13223 try module_block.writeAbbrev(ModuleBlock.Version{});
1323513224
1323613225 if (self.target_triple.slice(self)) |triple| {
13237 try module_block.writeAbbrev(Module.String{
13226 try module_block.writeAbbrev(ModuleBlock.String{
1323813227 .code = 2,
1323913228 .string = triple,
1324013229 });
1324113230 }
1324213231
1324313232 if (self.data_layout.slice(self)) |data_layout| {
13244 try module_block.writeAbbrev(Module.String{
13233 try module_block.writeAbbrev(ModuleBlock.String{
1324513234 .code = 3,
1324613235 .string = data_layout,
1324713236 });
1324813237 }
1324913238
1325013239 if (self.source_filename.slice(self)) |source_filename| {
13251 try module_block.writeAbbrev(Module.String{
13240 try module_block.writeAbbrev(ModuleBlock.String{
1325213241 .code = 16,
1325313242 .string = source_filename,
1325413243 });
1325513244 }
1325613245
1325713246 if (self.module_asm.items.len != 0) {
13258 try module_block.writeAbbrev(Module.String{
13247 try module_block.writeAbbrev(ModuleBlock.String{
1325913248 .code = 4,
1326013249 .string = self.module_asm.items,
1326113250 });
......@@ -13263,16 +13252,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1326313252
1326413253 // TYPE_BLOCK
1326513254 {
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
1327013260 for (self.type_items.items, 0..) |item, i| {
1327113261 const ty: Type = @enumFromInt(i);
1327213262
1327313263 switch (item.tag) {
13274 .simple => try type_block.writeAbbrev(ir.Type.Simple{ .code = @truncate(item.data) }),
13275 .integer => try type_block.writeAbbrev(ir.Type.Integer{ .width = item.data }),
13264 .simple => try type_block.writeAbbrev(TypeBlock.Simple{ .code = @enumFromInt(item.data) }),
13265 .integer => try type_block.writeAbbrev(TypeBlock.Integer{ .width = item.data }),
1327613266 .structure,
1327713267 .packed_structure,
1327813268 => |kind| {
......@@ -13282,19 +13272,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1328213272 else => unreachable,
1328313273 };
1328413274 var extra = self.typeExtraDataTrail(Type.Structure, item.data);
13285 try type_block.writeAbbrev(ir.Type.StructAnon{
13275 try type_block.writeAbbrev(TypeBlock.StructAnon{
1328613276 .is_packed = is_packed,
1328713277 .types = extra.trail.next(extra.data.fields_len, Type, self),
1328813278 });
1328913279 },
1329013280 .named_structure => {
1329113281 const extra = self.typeExtraData(Type.NamedStructure, item.data);
13292 try type_block.writeAbbrev(ir.Type.StructName{
13282 try type_block.writeAbbrev(TypeBlock.StructName{
1329313283 .string = extra.id.slice(self).?,
1329413284 });
1329513285
1329613286 switch (extra.body) {
13297 .none => try type_block.writeAbbrev(ir.Type.Opaque{}),
13287 .none => try type_block.writeAbbrev(TypeBlock.Opaque{}),
1329813288 else => {
1329913289 const real_struct = self.type_items.items[@intFromEnum(extra.body)];
1330013290 const is_packed: bool = switch (real_struct.tag) {
......@@ -13304,7 +13294,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1330413294 };
1330513295
1330613296 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{
1330813298 .is_packed = is_packed,
1330913299 .types = real_extra.trail.next(real_extra.data.fields_len, Type, self),
1331013300 });
......@@ -13313,29 +13303,29 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1331313303 },
1331413304 .array,
1331513305 .small_array,
13316 => try type_block.writeAbbrev(ir.Type.Array{
13306 => try type_block.writeAbbrev(TypeBlock.Array{
1331713307 .len = ty.aggregateLen(self),
1331813308 .child = ty.childType(self),
1331913309 }),
1332013310 .vector,
1332113311 .scalable_vector,
13322 => try type_block.writeAbbrev(ir.Type.Vector{
13312 => try type_block.writeAbbrev(TypeBlock.Vector{
1332313313 .len = ty.aggregateLen(self),
1332413314 .child = ty.childType(self),
1332513315 }),
13326 .pointer => try type_block.writeAbbrev(ir.Type.Pointer{
13316 .pointer => try type_block.writeAbbrev(TypeBlock.Pointer{
1332713317 .addr_space = ty.pointerAddrSpace(self),
1332813318 }),
1332913319 .target => {
1333013320 var extra = self.typeExtraDataTrail(Type.Target, item.data);
13331 try type_block.writeAbbrev(ir.Type.StructName{
13321 try type_block.writeAbbrev(TypeBlock.StructName{
1333213322 .string = extra.data.name.slice(self).?,
1333313323 });
1333413324
1333513325 const types = extra.trail.next(extra.data.types_len, Type, self);
1333613326 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{
1333913329 .num_types = extra.data.types_len,
1334013330 .types = types,
1334113331 .ints = ints,
......@@ -13348,7 +13338,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1334813338 else => unreachable,
1334913339 };
1335013340 var extra = self.typeExtraDataTrail(Type.Function, item.data);
13351 try type_block.writeAbbrev(ir.Type.Function{
13341 try type_block.writeAbbrev(TypeBlock.Function{
1335213342 .is_vararg = is_vararg,
1335313343 .return_type = extra.data.ret,
1335413344 .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
1336813358
1336913359 // PARAMATTR_GROUP_BLOCK
1337013360 {
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
1337513365 for (self.function_attributes_set.keys()) |func_attributes| {
1337613366 for (func_attributes.slice(self), 0..) |attributes, i| {
......@@ -13572,8 +13562,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1357213562
1357313563 // PARAMATTR_BLOCK
1357413564 {
13575 const Paramattr = ir.Paramattr;
13576 var paramattr_block = try module_block.enterSubBlock(Paramattr, true);
13565 const ParamattrBlock = ir.ModuleBlock.ParamattrBlock;
13566 var paramattr_block = try module_block.enterSubBlock(ParamattrBlock, true);
1357713567
1357813568 for (self.function_attributes_set.keys()) |func_attributes| {
1357913569 const func_attributes_slice = func_attributes.slice(self);
......@@ -13590,7 +13580,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1359013580 record.appendAssumeCapacity(@intCast(group_index));
1359113581 }
1359213582
13593 try paramattr_block.writeAbbrev(Paramattr.Entry{ .group_indices = record.items });
13583 try paramattr_block.writeAbbrev(ParamattrBlock.Entry{ .group_indices = record.items });
1359413584 }
1359513585
1359613586 try paramattr_block.end();
......@@ -13624,38 +13614,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1362413614 }
1362513615
1362613616 const ConstantAdapter = struct {
13627 const ConstantAdapter = @This();
1362813617 builder: *const Builder,
1362913618 globals: *const std.AutoArrayHashMapUnmanaged(Global.Index, void),
1363013619
13631 pub fn get(adapter: @This(), param: anytype, comptime field_name: []const u8) @TypeOf(param) {
13632 _ = field_name;
13620 pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) {
13621 Constant => u32,
13622 else => |Param| Param,
13623 } {
1363313624 return switch (@TypeOf(param)) {
13634 Constant => @enumFromInt(adapter.getConstantIndex(param)),
13625 Constant => adapter.getConstantIndex(param),
1363513626 else => param,
1363613627 };
1363713628 }
1363813629
13639 pub fn getConstantIndex(adapter: ConstantAdapter, constant: Constant) u32 {
13630 pub fn getConstantIndex(adapter: @This(), constant: Constant) u32 {
1364013631 return switch (constant.unwrap()) {
1364113632 .constant => |c| c + adapter.numGlobals(),
1364213633 .global => |global| @intCast(adapter.globals.getIndex(global.unwrap(adapter.builder)).?),
1364313634 };
1364413635 }
1364513636
13646 pub fn numConstants(adapter: ConstantAdapter) u32 {
13637 pub fn numConstants(adapter: @This()) u32 {
1364713638 return @intCast(adapter.globals.count() + adapter.builder.constant_items.len);
1364813639 }
1364913640
13650 pub fn numGlobals(adapter: ConstantAdapter) u32 {
13641 pub fn numGlobals(adapter: @This()) u32 {
1365113642 return @intCast(adapter.globals.count());
1365213643 }
1365313644 };
13654
13655 const constant_adapter = ConstantAdapter{
13656 .builder = self,
13657 .globals = &globals,
13658 };
13645 const constant_adapter: ConstantAdapter = .{ .builder = self, .globals = &globals };
1365913646
1366013647 // Globals
1366113648 {
......@@ -13670,7 +13657,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1367013657 if (variable.section == .none) break :blk 0;
1367113658 const gop = section_map.getOrPutAssumeCapacity(variable.section);
1367213659 if (!gop.found_existing) {
13673 try module_block.writeAbbrev(Module.String{
13660 try module_block.writeAbbrev(ModuleBlock.String{
1367413661 .code = 5,
1367513662 .string = variable.section.slice(self).?,
1367613663 });
......@@ -13686,7 +13673,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1368613673 const strtab = variable.global.strtab(self);
1368713674
1368813675 const global = variable.global.ptrConst(self);
13689 try module_block.writeAbbrev(Module.Variable{
13676 try module_block.writeAbbrev(ModuleBlock.Variable{
1369013677 .strtab_offset = strtab.offset,
1369113678 .strtab_size = strtab.size,
1369213679 .type_index = global.type,
......@@ -13717,7 +13704,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1371713704 if (func.section == .none) break :blk 0;
1371813705 const gop = section_map.getOrPutAssumeCapacity(func.section);
1371913706 if (!gop.found_existing) {
13720 try module_block.writeAbbrev(Module.String{
13707 try module_block.writeAbbrev(ModuleBlock.String{
1372113708 .code = 5,
1372213709 .string = func.section.slice(self).?,
1372313710 });
......@@ -13733,7 +13720,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1373313720 const strtab = func.global.strtab(self);
1373413721
1373513722 const global = func.global.ptrConst(self);
13736 try module_block.writeAbbrev(Module.Function{
13723 try module_block.writeAbbrev(ModuleBlock.Function{
1373713724 .strtab_offset = strtab.offset,
1373813725 .strtab_size = strtab.size,
1373913726 .type_index = global.type,
......@@ -13757,7 +13744,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1375713744 const strtab = alias.global.strtab(self);
1375813745
1375913746 const global = alias.global.ptrConst(self);
13760 try module_block.writeAbbrev(Module.Alias{
13747 try module_block.writeAbbrev(ModuleBlock.Alias{
1376113748 .strtab_offset = strtab.offset,
1376213749 .strtab_size = strtab.size,
1376313750 .type_index = global.type,
......@@ -13775,8 +13762,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1377513762
1377613763 // CONSTANTS_BLOCK
1377713764 {
13778 const Constants = ir.Constants;
13779 var constants_block = try module_block.enterSubBlock(Constants, true);
13765 const ConstantsBlock = ir.ModuleBlock.ConstantsBlock;
13766 var constants_block = try module_block.enterSubBlock(ConstantsBlock, true);
1378013767
1378113768 var current_type: Type = .none;
1378213769 const tags = self.constant_items.items(.tag);
......@@ -13786,7 +13773,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1378613773 const constant: Constant = @enumFromInt(index);
1378713774 const constant_type = constant.typeOf(self);
1378813775 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 });
1379013777 current_type = constant_type;
1379113778 }
1379213779 const data = datas[index];
......@@ -13794,9 +13781,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1379413781 .null,
1379513782 .zeroinitializer,
1379613783 .none,
13797 => try constants_block.writeAbbrev(Constants.Null{}),
13798 .undef => try constants_block.writeAbbrev(Constants.Undef{}),
13799 .poison => try constants_block.writeAbbrev(Constants.Poison{}),
13784 => try constants_block.writeAbbrev(ConstantsBlock.Null{}),
13785 .undef => try constants_block.writeAbbrev(ConstantsBlock.Undef{}),
13786 .poison => try constants_block.writeAbbrev(ConstantsBlock.Poison{}),
1380013787 .positive_integer,
1380113788 .negative_integer,
1380213789 => |tag| {
......@@ -13832,7 +13819,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1383213819 try constants_block.writeUnabbrev(5, record.items);
1383313820 continue;
1383413821 };
13835 try constants_block.writeAbbrev(Constants.Integer{
13822 try constants_block.writeAbbrev(ConstantsBlock.Integer{
1383613823 .value = @bitCast(if (val >= 0)
1383713824 val << 1 | 0
1383813825 else
......@@ -13841,17 +13828,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1384113828 },
1384213829 .half,
1384313830 .bfloat,
13844 => try constants_block.writeAbbrev(Constants.Half{ .value = @truncate(data) }),
13845 .float => try constants_block.writeAbbrev(Constants.Float{ .value = data }),
13831 => try constants_block.writeAbbrev(ConstantsBlock.Half{ .value = @truncate(data) }),
13832 .float => try constants_block.writeAbbrev(ConstantsBlock.Float{ .value = data }),
1384613833 .double => {
1384713834 const extra = self.constantExtraData(Constant.Double, data);
13848 try constants_block.writeAbbrev(Constants.Double{
13835 try constants_block.writeAbbrev(ConstantsBlock.Double{
1384913836 .value = (@as(u64, extra.hi) << 32) | extra.lo,
1385013837 });
1385113838 },
1385213839 .x86_fp80 => {
1385313840 const extra = self.constantExtraData(Constant.Fp80, data);
13854 try constants_block.writeAbbrev(Constants.Fp80{
13841 try constants_block.writeAbbrev(ConstantsBlock.Fp80{
1385513842 .hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 |
1385613843 extra.lo_lo >> 16,
1385713844 .lo = @truncate(extra.lo_lo),
......@@ -13861,7 +13848,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1386113848 .ppc_fp128,
1386213849 => {
1386313850 const extra = self.constantExtraData(Constant.Fp128, data);
13864 try constants_block.writeAbbrev(Constants.Fp128{
13851 try constants_block.writeAbbrev(ConstantsBlock.Fp128{
1386513852 .lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo),
1386613853 .hi = @as(u64, extra.hi_hi) << 32 | @as(u64, extra.hi_lo),
1386713854 });
......@@ -13876,35 +13863,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1387613863 const values = extra.trail.next(len, Constant, self);
1387713864
1387813865 try constants_block.writeAbbrevAdapted(
13879 Constants.Aggregate{ .values = values },
13866 ConstantsBlock.Aggregate{ .values = values },
1388013867 constant_adapter,
1388113868 );
1388213869 },
1388313870 .splat => {
13884 const ConstantsWriter = @TypeOf(constants_block);
13871 const ConstantsBlockWriter = @TypeOf(constants_block);
1388513872 const extra = self.constantExtraData(Constant.Splat, data);
1388613873 const vector_len = extra.type.vectorLen(self);
1388713874 const c = constant_adapter.getConstantIndex(extra.value);
1388813875
1388913876 try bitcode.writeBits(
13890 ConstantsWriter.abbrevId(Constants.Aggregate),
13891 ConstantsWriter.abbrev_len,
13877 ConstantsBlockWriter.abbrevId(ConstantsBlock.Aggregate),
13878 ConstantsBlockWriter.abbrev_len,
1389213879 );
13893 try bitcode.writeVBR(vector_len, 6);
13880 try bitcode.writeVbr(vector_len, 6);
1389413881 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);
1389613883 }
1389713884 },
1389813885 .string => {
1389913886 const str: String = @enumFromInt(data);
1390013887 if (str == .none) {
13901 try constants_block.writeAbbrev(Constants.Null{});
13888 try constants_block.writeAbbrev(ConstantsBlock.Null{});
1390213889 } else {
1390313890 const slice = str.slice(self).?;
1390413891 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] })
1390613893 else
13907 try constants_block.writeAbbrev(Constants.String{ .string = slice });
13894 try constants_block.writeAbbrev(ConstantsBlock.String{ .string = slice });
1390813895 }
1390913896 },
1391013897 .bitcast,
......@@ -13914,7 +13901,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1391413901 .trunc,
1391513902 => |tag| {
1391613903 const extra = self.constantExtraData(Constant.Cast, data);
13917 try constants_block.writeAbbrevAdapted(Constants.Cast{
13904 try constants_block.writeAbbrevAdapted(ConstantsBlock.Cast{
1391813905 .type_index = extra.type,
1391913906 .val = extra.val,
1392013907 .opcode = tag.toCastOpcode(),
......@@ -13930,7 +13917,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1393013917 .xor,
1393113918 => |tag| {
1393213919 const extra = self.constantExtraData(Constant.Binary, data);
13933 try constants_block.writeAbbrevAdapted(Constants.Binary{
13920 try constants_block.writeAbbrevAdapted(ConstantsBlock.Binary{
1393413921 .opcode = tag.toBinaryOpcode(),
1393513922 .lhs = extra.lhs,
1393613923 .rhs = extra.rhs,
......@@ -14014,7 +14001,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1401414001 },
1401514002 .blockaddress => {
1401614003 const extra = self.constantExtraData(Constant.BlockAddress, data);
14017 try constants_block.writeAbbrev(Constants.BlockAddress{
14004 try constants_block.writeAbbrev(ConstantsBlock.BlockAddress{
1401814005 .type_id = extra.function.typeOf(self),
1401914006 .function = constant_adapter.getConstantIndex(extra.function.toConst(self)),
1402014007 .block = @intFromEnum(extra.block),
......@@ -14024,10 +14011,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1402414011 .no_cfi,
1402514012 => |tag| {
1402614013 const function: Function.Index = @enumFromInt(data);
14027 try constants_block.writeAbbrev(Constants.DsoLocalEquivalentOrNoCfi{
14014 try constants_block.writeAbbrev(ConstantsBlock.DsoLocalEquivalentOrNoCfi{
1402814015 .code = switch (tag) {
14029 .dso_local_equivalent => 27,
14030 .no_cfi => 29,
14016 .dso_local_equivalent => .DSO_LOCAL_EQUIVALENT,
14017 .no_cfi => .NO_CFI_VALUE,
1403114018 else => unreachable,
1403214019 },
1403314020 .type_id = function.typeOf(self),
......@@ -14042,7 +14029,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1404214029
1404314030 // METADATA_KIND_BLOCK
1404414031 {
14045 const MetadataKindBlock = ir.MetadataKindBlock;
14032 const MetadataKindBlock = ir.ModuleBlock.MetadataKindBlock;
1404614033 var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true);
1404714034
1404814035 inline for (@typeInfo(ir.FixedMetadataKind).@"enum".fields) |field| {
......@@ -14059,95 +14046,85 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1405914046 }
1406014047
1406114048 const MetadataAdapter = struct {
14062 builder: *const Builder,
1406314049 constant_adapter: ConstantAdapter,
1406414050
14065 pub fn init(
14066 builder: *const Builder,
14067 const_adapter: ConstantAdapter,
14068 ) @This() {
14069 return .{
14070 .builder = builder,
14071 .constant_adapter = const_adapter,
14072 };
14073 }
14074
14075 pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) {
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,
14051 pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) {
14052 Metadata, Metadata.Optional, Metadata.String, Metadata.String.Optional, Constant => u32,
14053 else => |Result| Result,
14054 } {
14055 return switch (@TypeOf(param)) {
14056 Metadata => adapter.getMetadataIndex(param),
14057 Metadata.Optional => adapter.getOptionalMetadataIndex(param),
14058 Metadata.String => adapter.getMetadataIndex(param.toMetadata()),
14059 Metadata.String.Optional => adapter.getOptionalMetadataIndex(param.toMetadata()),
14060 Constant => adapter.constant_adapter.getConstantIndex(param),
14061 else => param,
1408314062 };
1408414063 }
1408514064
1408614065 pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32 {
14087 if (metadata == .none) return 0;
14088 return @intCast(adapter.builder.metadata_string_map.count() +
14089 @intFromEnum(metadata.unwrap(adapter.builder)) - 1);
14066 const builder = adapter.constant_adapter.builder;
14067 const unwrapped_metadata = metadata.unwrap(builder);
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 };
1409014073 }
1409114074
14092 pub fn getMetadataStringIndex(_: @This(), metadata_string: MetadataString) u32 {
14093 return @intFromEnum(metadata_string);
14075 pub fn getOptionalMetadataIndex(adapter: @This(), metadata: Metadata.Optional) u32 {
14076 return if (metadata.unwrap()) |m| 1 + adapter.getMetadataIndex(m) else 0;
1409414077 }
1409514078 };
14096
14097 const metadata_adapter = MetadataAdapter.init(self, constant_adapter);
14079 const metadata_adapter: MetadataAdapter = .{ .constant_adapter = constant_adapter };
1409814080
1409914081 // METADATA_BLOCK
1410014082 {
14101 const MetadataBlock = ir.MetadataBlock;
14083 const MetadataBlock = ir.ModuleBlock.MetadataBlock;
1410214084 var metadata_block = try module_block.enterSubBlock(MetadataBlock, true);
1410314085
1410414086 const MetadataBlockWriter = @TypeOf(metadata_block);
1410514087
14106 // Emit all MetadataStrings
14107 if (self.metadata_string_map.count() > 1) {
14108 const strings_offset, const strings_size = blk: {
14109 var strings_offset: u32 = 0;
14110 var strings_size: u32 = 0;
14111 for (1..self.metadata_string_map.count()) |metadata_string_index| {
14112 const metadata_string: MetadataString = @enumFromInt(metadata_string_index);
14113 const slice = metadata_string.slice(self);
14114 strings_offset += bitcode.bitsVBR(@as(u32, @intCast(slice.len)), 6);
14115 strings_size += @intCast(slice.len * 8);
14116 }
14117 break :blk .{
14118 std.mem.alignForward(u32, strings_offset, 32) / 8,
14119 std.mem.alignForward(u32, strings_size, 32) / 8,
14120 };
14088 // Emit all Metadata.Strings
14089 const strings_len: u32 = @intCast(self.metadata_string_map.count());
14090 if (strings_len > 0) {
14091 const string_bytes_offset = string_bytes_offset: {
14092 var string_bytes_bit_offset: u32 = 0;
14093 for (
14094 self.metadata_string_indices.items[0..strings_len],
14095 self.metadata_string_indices.items[1..],
14096 ) |start, end| string_bytes_bit_offset += BitcodeWriter.bitsVbr(end - start, 6);
14097 break :string_bytes_offset @divExact(
14098 std.mem.alignForward(u32, string_bytes_bit_offset, 32),
14099 8,
14100 );
1412114101 };
14102 const string_bytes_len =
14103 std.mem.alignForward(u32, @intCast(self.metadata_string_bytes.items.len), 4);
1412214104
1412314105 try bitcode.writeBits(
1412414106 comptime MetadataBlockWriter.abbrevId(MetadataBlock.Strings),
1412514107 MetadataBlockWriter.abbrev_len,
1412614108 );
1412714109
14128 try bitcode.writeVBR(@as(u32, @intCast(self.metadata_string_map.count() - 1)), 6);
14129 try bitcode.writeVBR(strings_offset, 6);
14110 try bitcode.writeVbr(strings_len, 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
1413314115 try bitcode.alignTo32();
1413414116
14135 for (1..self.metadata_string_map.count()) |metadata_string_index| {
14136 const metadata_string: MetadataString = @enumFromInt(metadata_string_index);
14137 const slice = metadata_string.slice(self);
14138 try bitcode.writeVBR(@as(u32, @intCast(slice.len)), 6);
14139 }
14117 for (
14118 self.metadata_string_indices.items[0..strings_len],
14119 self.metadata_string_indices.items[1..],
14120 ) |start, end| try bitcode.writeVbr(end - start, 6);
1414014121
1414114122 try bitcode.writeBlob(self.metadata_string_bytes.items);
1414214123 }
1414314124
14144 for (
14145 self.metadata_items.items(.tag)[1..],
14146 self.metadata_items.items(.data)[1..],
14147 ) |tag, data| {
14125 for (self.metadata_items.items(.tag), self.metadata_items.items(.data)) |tag, data| {
1414814126 record.clearRetainingCapacity();
1414914127 switch (tag) {
14150 .none => unreachable,
1415114128 .file => {
1415214129 const extra = self.metadataExtraData(Metadata.File, data);
1415314130
......@@ -14209,13 +14186,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1420914186 },
1421014187 .location => {
1421114188 const extra = self.metadataExtraData(Metadata.Location, data);
14212 assert(extra.scope != .none);
14213 try metadata_block.writeAbbrev(MetadataBlock.Location{
14189 try metadata_block.writeAbbrevAdapted(MetadataBlock.Location{
1421414190 .line = extra.line,
1421514191 .column = extra.column,
14216 .scope = metadata_adapter.getMetadataIndex(extra.scope) - 1,
14217 .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(extra.inlined_at)),
14218 });
14192 .scope = extra.scope,
14193 .inlined_at = extra.inlined_at,
14194 }, metadata_adapter);
1421914195 },
1422014196 .basic_bool_type,
1422114197 .basic_unsigned_type,
......@@ -14325,7 +14301,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1432514301 @bitCast(flags),
1432614302 ));
1432714303 record.appendAssumeCapacity(extra.bit_width);
14328 record.appendAssumeCapacity(metadata_adapter.getMetadataStringIndex(extra.name));
14304 record.appendAssumeCapacity(metadata_adapter.getOptionalMetadataIndex(extra.name.toMetadata()));
1432914305 const limbs = record.addManyAsSliceAssumeCapacity(limbs_len);
1433014306 bigint.writeTwosComplement(std.mem.sliceAsBytes(limbs), .little);
1433114307 for (limbs) |*limb| {
......@@ -14335,7 +14311,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1433514311 else
1433614312 -%val << 1 | 1);
1433714313 }
14338 try metadata_block.writeUnabbrev(@intFromEnum(MetadataBlock.Enumerator.id), record.items);
14314 try metadata_block.writeUnabbrev(@intFromEnum(MetadataBlock.Code.ENUMERATOR), record.items);
1433914315 continue;
1434014316 };
1434114317 try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{
......@@ -14350,7 +14326,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1435014326 },
1435114327 .subrange => {
1435214328 const extra = self.metadataExtraData(Metadata.Subrange, data);
14353
1435414329 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subrange{
1435514330 .count = extra.count,
1435614331 .lower_bound = extra.lower_bound,
......@@ -14358,48 +14333,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1435814333 },
1435914334 .expression => {
1436014335 var extra = self.metadataExtraDataTrail(Metadata.Expression, data);
14361
1436214336 const elements = extra.trail.next(extra.data.elements_len, u32, self);
14363
1436414337 try metadata_block.writeAbbrevAdapted(MetadataBlock.Expression{
1436514338 .elements = elements,
1436614339 }, metadata_adapter);
1436714340 },
1436814341 .tuple => {
1436914342 var extra = self.metadataExtraDataTrail(Metadata.Tuple, data);
14370
14371 const elements = extra.trail.next(extra.data.elements_len, Metadata, self);
14372
14343 const elements =
14344 extra.trail.next(extra.data.elements_len, Metadata.Optional, self);
1437314345 try metadata_block.writeAbbrevAdapted(MetadataBlock.Node{
1437414346 .elements = elements,
1437514347 }, metadata_adapter);
1437614348 },
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 },
1440314349 .local_var => {
1440414350 const extra = self.metadataExtraData(Metadata.LocalVar, data);
1440514351 try metadata_block.writeAbbrevAdapted(MetadataBlock.LocalVar{
......@@ -14454,37 +14400,28 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1445414400
1445514401 // Write named metadata
1445614402 for (self.metadata_named.keys(), self.metadata_named.values()) |name, operands| {
14457 const slice = name.slice(self);
14458 try metadata_block.writeAbbrev(MetadataBlock.Name{
14459 .name = slice,
14460 });
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 });
14403 try metadata_block.writeAbbrev(MetadataBlock.Name{ .name = name.slice(self).? });
14404 try metadata_block.writeAbbrevAdapted(MetadataBlock.NamedNode{
14405 .elements = @ptrCast(self.metadata_extra.items[operands.index..][0..operands.len]),
14406 }, metadata_adapter);
1447014407 }
1447114408
1447214409 // Write global attached metadata
1447314410 {
14474 for (globals.keys()) |global| {
14475 const global_ptr = global.ptrConst(self);
14476 if (global_ptr.dbg == .none) continue;
14411 for (globals.keys()) |global_index| {
14412 const global = global_index.ptrConst(self);
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) {
14479 .function => |f| if (f.ptrConst(self).instructions.len != 0) continue,
14480 else => {},
14419 try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalDeclAttachment{
14420 .value = global_index.toConst(),
14421 .kind = .dbg,
14422 .metadata = dbg,
14423 }, metadata_adapter);
1448114424 }
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 });
1448814425 }
1448914426 }
1449014427
......@@ -14493,10 +14430,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1449314430
1449414431 // OPERAND_BUNDLE_TAGS_BLOCK
1449514432 {
14496 const OperandBundleTags = ir.OperandBundleTags;
14497 var operand_bundle_tags_block = try module_block.enterSubBlock(OperandBundleTags, true);
14433 const OperandBundleTagsBlock = ir.ModuleBlock.OperandBundleTagsBlock;
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{
1450014437 .tag = "cold",
1450114438 });
1450214439
......@@ -14505,26 +14442,34 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1450514442
1450614443 // Block info
1450714444 {
14508 const BlockInfo = ir.BlockInfo;
14509 var block_info_block = try module_block.enterSubBlock(BlockInfo, true);
14445 const BlockInfoBlock = ir.BlockInfoBlock;
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});
14512 inline for (ir.FunctionBlock.abbrevs) |abbrev| {
14448 try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
14449 @intFromEnum(ir.ModuleBlock.FunctionBlock.id),
14450 });
14451 inline for (ir.ModuleBlock.FunctionBlock.abbrevs) |abbrev| {
1451314452 try block_info_block.defineAbbrev(&abbrev.ops);
1451414453 }
1451514454
14516 try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.FunctionValueSymbolTable.id});
14517 inline for (ir.FunctionValueSymbolTable.abbrevs) |abbrev| {
14455 try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
14456 @intFromEnum(ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.id),
14457 });
14458 inline for (ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.abbrevs) |abbrev| {
1451814459 try block_info_block.defineAbbrev(&abbrev.ops);
1451914460 }
1452014461
14521 try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.FunctionMetadataBlock.id});
14522 inline for (ir.FunctionMetadataBlock.abbrevs) |abbrev| {
14462 try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
14463 @intFromEnum(ir.ModuleBlock.FunctionBlock.MetadataBlock.id),
14464 });
14465 inline for (ir.ModuleBlock.FunctionBlock.MetadataBlock.abbrevs) |abbrev| {
1452314466 try block_info_block.defineAbbrev(&abbrev.ops);
1452414467 }
1452514468
14526 try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.MetadataAttachmentBlock.id});
14527 inline for (ir.MetadataAttachmentBlock.abbrevs) |abbrev| {
14469 try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
14470 @intFromEnum(ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.id),
14471 });
14472 inline for (ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.abbrevs) |abbrev| {
1452814473 try block_info_block.defineAbbrev(&abbrev.ops);
1452914474 }
1453014475
......@@ -14534,38 +14479,40 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1453414479 // FUNCTION_BLOCKS
1453514480 {
1453614481 const FunctionAdapter = struct {
14537 constant_adapter: ConstantAdapter,
1453814482 metadata_adapter: MetadataAdapter,
1453914483 func: *const Function,
1454014484 instruction_index: Function.Instruction.Index,
1454114485
14542 pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) {
14543 _ = field_name;
14544 const Ty = @TypeOf(value);
14545 return switch (Ty) {
14546 Value => @enumFromInt(adapter.getOffsetValueIndex(value)),
14547 Constant => @enumFromInt(adapter.getOffsetConstantIndex(value)),
14548 FunctionAttributes => @enumFromInt(switch (value) {
14486 pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) {
14487 Value, Constant, FunctionAttributes => u32,
14488 else => |Result| Result,
14489 } {
14490 return switch (@TypeOf(param)) {
14491 Value => adapter.getOffsetValueIndex(param),
14492 Constant => adapter.getOffsetConstantIndex(param),
14493 FunctionAttributes => switch (param) {
1454914494 .none => 0,
14550 else => 1 + adapter.constant_adapter.builder.function_attributes_set.getIndex(value).?,
14551 }),
14552 else => value,
14495 else => @intCast(1 + adapter.metadata_adapter.constant_adapter.builder
14496 .function_attributes_set.getIndex(param).?),
14497 },
14498 else => param,
1455314499 };
1455414500 }
1455514501
1455614502 pub fn getValueIndex(adapter: @This(), value: Value) u32 {
1455714503 return @intCast(switch (value.unwrap()) {
1455814504 .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),
1456014506 .metadata => |metadata| {
14561 const real_metadata = metadata.unwrap(adapter.metadata_adapter.builder);
14562 if (@intFromEnum(real_metadata) < Metadata.first_local_metadata)
14563 return adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1;
14564
14565 return @intCast(@intFromEnum(metadata) -
14566 Metadata.first_local_metadata +
14567 adapter.metadata_adapter.builder.metadata_string_map.count() - 1 +
14568 adapter.metadata_adapter.builder.metadata_map.count() - 1);
14507 const builder = adapter.metadata_adapter.constant_adapter.builder;
14508 const unwrapped_metadata = metadata.unwrap(builder);
14509 return switch (unwrapped_metadata.kind) {
14510 .string, .node => adapter.metadata_adapter.getMetadataIndex(unwrapped_metadata),
14511 .forward => unreachable,
14512 .local => @intCast(builder.metadata_string_map.count() +
14513 builder.metadata_map.count() +
14514 unwrapped_metadata.index),
14515 };
1456914516 },
1457014517 });
1457114518 }
......@@ -14589,12 +14536,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1458914536 }
1459014537
1459114538 fn firstInstr(adapter: @This()) u32 {
14592 return adapter.constant_adapter.numConstants();
14539 return adapter.metadata_adapter.constant_adapter.numConstants();
1459314540 }
1459414541 };
1459514542
1459614543 for (self.functions.items, 0..) |func, func_index| {
14597 const FunctionBlock = ir.FunctionBlock;
14544 const FunctionBlock = ir.ModuleBlock.FunctionBlock;
1459814545 if (func.global.getReplacement(self) != .none) continue;
1459914546
1460014547 if (func.instructions.len == 0) continue;
......@@ -14604,7 +14551,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1460414551 try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len });
1460514552
1460614553 var adapter: FunctionAdapter = .{
14607 .constant_adapter = constant_adapter,
1460814554 .metadata_adapter = metadata_adapter,
1460914555 .func = &func,
1461014556 .instruction_index = @enumFromInt(0),
......@@ -14612,7 +14558,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1461214558
1461314559 // Emit function level metadata block
1461414560 if (!func.strip and func.debug_values.len > 0) {
14615 const MetadataBlock = ir.FunctionMetadataBlock;
14561 const MetadataBlock = ir.ModuleBlock.FunctionBlock.MetadataBlock;
1461614562 var metadata_block = try function_block.enterSubBlock(MetadataBlock, false);
1461714563
1461814564 for (func.debug_values) |value| {
......@@ -15048,7 +14994,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1504814994 const vals = extra.trail.next(extra.data.cases_len, Constant, &func);
1504914995 const blocks = extra.trail.next(extra.data.cases_len, Function.Block.Index, &func);
1505014996 for (vals, blocks) |val, block| {
15051 record.appendAssumeCapacity(adapter.constant_adapter.getConstantIndex(val));
14997 record.appendAssumeCapacity(adapter.metadata_adapter.constant_adapter.getConstantIndex(val));
1505214998 record.appendAssumeCapacity(@intFromEnum(block));
1505314999 }
1505415000
......@@ -15135,12 +15081,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1513515081 switch (debug_location) {
1513615082 .no_location => has_location = false,
1513715083 .location => |location| {
15138 try function_block.writeAbbrev(FunctionBlock.DebugLoc{
15084 try function_block.writeAbbrevAdapted(FunctionBlock.DebugLoc{
1513915085 .line = location.line,
1514015086 .column = location.column,
15141 .scope = @enumFromInt(metadata_adapter.getMetadataIndex(location.scope)),
15142 .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(location.inlined_at)),
15143 });
15087 .scope = location.scope,
15088 .inlined_at = location.inlined_at,
15089 }, metadata_adapter);
1514415090 has_location = true;
1514515091 },
1514615092 }
......@@ -15152,16 +15098,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1515215098
1515315099 // VALUE_SYMTAB
1515415100 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
1515915105 for (func.blocks, 0..) |block, block_index| {
1516015106 const name = block.instruction.name(&func);
1516115107
1516215108 if (name == .none or name == .empty) continue;
1516315109
15164 try value_symtab_block.writeAbbrev(ValueSymbolTable.BlockEntry{
15110 try value_symtab_block.writeAbbrev(ValueSymtabBlock.BlockEntry{
1516515111 .value_id = @intCast(block_index),
1516615112 .string = name.slice(self).?,
1516715113 });
......@@ -15174,17 +15120,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1517415120
1517515121 // METADATA_ATTACHMENT_BLOCK
1517615122 {
15177 const MetadataAttachmentBlock = ir.MetadataAttachmentBlock;
15123 const MetadataAttachmentBlock = ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock;
1517815124 var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false);
1517915125
15180 dbg: {
15181 if (func.strip) break :dbg;
15182 const dbg = func.global.ptrConst(self).dbg;
15183 if (dbg == .none) break :dbg;
15184 try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentGlobalSingle{
15126 if (func.global.ptrConst(self).dbg.unwrap()) |dbg| {
15127 try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentGlobalSingle{
1518515128 .kind = .dbg,
15186 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
15187 });
15129 .metadata = dbg,
15130 }, metadata_adapter);
1518815131 }
1518915132
1519015133 var instr_index: u32 = 0;
......@@ -15201,16 +15144,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1520115144 };
1520215145 switch (weights) {
1520315146 .none => {},
15204 .unpredictable => try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{
15147 .unpredictable => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{
1520515148 .inst = instr_index,
1520615149 .kind = .unpredictable,
15207 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(.empty_tuple) - 1),
15208 }),
15209 _ => try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{
15150 .metadata = .empty_tuple,
15151 }, metadata_adapter),
15152 _ => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{
1521015153 .inst = instr_index,
1521115154 .kind = .prof,
15212 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(@enumFromInt(@intFromEnum(weights))) - 1),
15213 }),
15155 .metadata = weights.toMetadata(),
15156 }, metadata_adapter),
1521415157 }
1521515158 instr_index += 1;
1521615159 },
......@@ -15228,7 +15171,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1522815171
1522915172 // STRTAB_BLOCK
1523015173 {
15231 const Strtab = ir.Strtab;
15174 const Strtab = ir.StrtabBlock;
1523215175 var strtab_block = try bitcode.enterTopBlock(Strtab);
1523315176
1523415177 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 {
8888 }
8989 }
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 {
9292 comptime {
9393 std.debug.assert(vbr_bits > 1);
9494 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 {
110110 try self.writeBits(in_buffer, vbr_bits);
111111 }
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 {
114114 comptime {
115115 std.debug.assert(vbr_bits > 1);
116116 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 {
177177
178178 pub fn init(bitcode: *BcWriter, comptime parent_abbrev_len: u6, comptime define_abbrevs: bool) Error!Self {
179179 try bitcode.writeBits(1, parent_abbrev_len);
180 try bitcode.writeVBR(Block.id, 8);
181 try bitcode.writeVBR(abbrev_len, 4);
180 try bitcode.writeVbr(Block.id, 8);
181 try bitcode.writeVbr(abbrev_len, 4);
182182 try bitcode.alignTo32();
183183
184184 // 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 {
214214
215215 pub fn writeUnabbrev(self: *Self, code: u32, values: []const u64) Error!void {
216216 try self.bitcode.writeBits(3, abbrev_len);
217 try self.bitcode.writeVBR(code, 6);
218 try self.bitcode.writeVBR(values.len, 6);
217 try self.bitcode.writeVbr(code, 6);
218 try self.bitcode.writeVbr(values.len, 6);
219219 for (values) |val| {
220 try self.bitcode.writeVBR(val, 6);
220 try self.bitcode.writeVbr(val, 6);
221221 }
222222 }
223223
224224 pub fn writeAbbrev(self: *Self, params: anytype) Error!void {
225225 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) {
227227 return param;
228228 }
229229 }{});
......@@ -253,47 +253,45 @@ pub fn BitcodeWriter(comptime types: []const type) type {
253253
254254 comptime var field_index: usize = 0;
255255 inline for (Abbrev.ops) |ty| {
256 const field_name = fields[field_index].name;
257 const param = @field(params, field_name);
258
256 const param = @field(params, fields[field_index].name);
259257 switch (ty) {
260258 .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),
262260 .fixed_runtime => |width_ty| try self.bitcode.writeBits(
263 adapter.get(param, field_name),
261 adapter.get(param),
264262 self.bitcode.getTypeWidth(width_ty),
265263 ),
266 .vbr => |len| try self.bitcode.writeVBR(adapter.get(param, field_name), len),
267 .char6 => try self.bitcode.write6BitChar(adapter.get(param, field_name)),
264 .vbr => |len| try self.bitcode.writeVbr(adapter.get(param), len),
265 .char6 => try self.bitcode.write6BitChar(adapter.get(param)),
268266 .blob => {
269 try self.bitcode.writeVBR(param.len, 6);
267 try self.bitcode.writeVbr(param.len, 6);
270268 try self.bitcode.writeBlob(param);
271269 },
272270 .array_fixed => |len| {
273 try self.bitcode.writeVBR(param.len, 6);
271 try self.bitcode.writeVbr(param.len, 6);
274272 for (param) |x| {
275 try self.bitcode.writeBits(adapter.get(x, field_name), len);
273 try self.bitcode.writeBits(adapter.get(x), len);
276274 }
277275 },
278276 .array_fixed_runtime => |width_ty| {
279 try self.bitcode.writeVBR(param.len, 6);
277 try self.bitcode.writeVbr(param.len, 6);
280278 for (param) |x| {
281279 try self.bitcode.writeBits(
282 adapter.get(x, field_name),
280 adapter.get(x),
283281 self.bitcode.getTypeWidth(width_ty),
284282 );
285283 }
286284 },
287285 .array_vbr => |len| {
288 try self.bitcode.writeVBR(param.len, 6);
286 try self.bitcode.writeVbr(param.len, 6);
289287 for (param) |x| {
290 try self.bitcode.writeVBR(adapter.get(x, field_name), len);
288 try self.bitcode.writeVbr(adapter.get(x), len);
291289 }
292290 },
293291 .array_char6 => {
294 try self.bitcode.writeVBR(param.len, 6);
292 try self.bitcode.writeVbr(param.len, 6);
295293 for (param) |x| {
296 try self.bitcode.write6BitChar(adapter.get(x, field_name));
294 try self.bitcode.write6BitChar(adapter.get(x));
297295 }
298296 },
299297 }
......@@ -307,7 +305,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
307305 try bitcode.writeBits(2, abbrev_len);
308306
309307 // ops.len is not accurate because arrays are actually two ops
310 try bitcode.writeVBR(blk: {
308 try bitcode.writeVbr(blk: {
311309 var count: usize = 0;
312310 inline for (ops) |op| {
313311 count += switch (op) {
......@@ -322,22 +320,22 @@ pub fn BitcodeWriter(comptime types: []const type) type {
322320 switch (op) {
323321 .literal => |value| {
324322 try bitcode.writeBits(1, 1);
325 try bitcode.writeVBR(value, 8);
323 try bitcode.writeVbr(value, 8);
326324 },
327325 .fixed => |width| {
328326 try bitcode.writeBits(0, 1);
329327 try bitcode.writeBits(1, 3);
330 try bitcode.writeVBR(width, 5);
328 try bitcode.writeVbr(width, 5);
331329 },
332330 .fixed_runtime => |width_ty| {
333331 try bitcode.writeBits(0, 1);
334332 try bitcode.writeBits(1, 3);
335 try bitcode.writeVBR(bitcode.getTypeWidth(width_ty), 5);
333 try bitcode.writeVbr(bitcode.getTypeWidth(width_ty), 5);
336334 },
337335 .vbr => |width| {
338336 try bitcode.writeBits(0, 1);
339337 try bitcode.writeBits(2, 3);
340 try bitcode.writeVBR(width, 5);
338 try bitcode.writeVbr(width, 5);
341339 },
342340 .char6 => {
343341 try bitcode.writeBits(0, 1);
......@@ -355,7 +353,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
355353 // Fixed or VBR op
356354 try bitcode.writeBits(0, 1);
357355 try bitcode.writeBits(1, 3);
358 try bitcode.writeVBR(width, 5);
356 try bitcode.writeVbr(width, 5);
359357 },
360358 .array_fixed_runtime => |width_ty| {
361359 // Array op
......@@ -365,7 +363,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
365363 // Fixed or VBR op
366364 try bitcode.writeBits(0, 1);
367365 try bitcode.writeBits(1, 3);
368 try bitcode.writeVBR(bitcode.getTypeWidth(width_ty), 5);
366 try bitcode.writeVbr(bitcode.getTypeWidth(width_ty), 5);
369367 },
370368 .array_vbr => |width| {
371369 // Array op
......@@ -375,7 +373,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
375373 // Fixed or VBR op
376374 try bitcode.writeBits(0, 1);
377375 try bitcode.writeBits(2, 3);
378 try bitcode.writeVBR(width, 5);
376 try bitcode.writeVbr(width, 5);
379377 },
380378 .array_char6 => {
381379 // Array op
lib/std/zig/llvm/ir.zig+2048-1612
......@@ -21,9 +21,60 @@ const ColumnAbbrev = AbbrevOp{ .vbr = 8 };
2121const BlockAbbrev = AbbrevOp{ .vbr = 6 };
2222const 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
2475/// Unused tags are commented out so that they are omitted in the generated
2576/// bitcode, which scans over this enum using reflection.
26pub const FixedMetadataKind = enum(u8) {
77pub const FixedMetadataKind = enum(u6) {
2778 dbg = 0,
2879 //tbaa = 1,
2980 prof = 2,
......@@ -66,138 +117,79 @@ pub const FixedMetadataKind = enum(u8) {
66117 //@"coro.outside.frame" = 39,
67118};
68119
69pub const MetadataCode = enum(u8) {
70 /// MDSTRING: [values]
71 STRING_OLD = 1,
72 /// VALUE: [type num, value num]
73 VALUE = 2,
74 /// NODE: [n x md num]
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,
120pub const BlockInfoBlock = struct {
121 pub const id: BlockId = .BLOCKINFO;
122
123 pub const set_block_id = 1;
124
125 pub const abbrevs = [_]type{};
160126};
161127
162pub const Identification = struct {
163 pub const id = 13;
128/// MODULE blocks have a number of optional fields and subblocks.
129pub const ModuleBlock = struct {
130 pub const id: BlockId = .MODULE;
164131
165132 pub const abbrevs = [_]type{
166 Version,
167 Epoch,
133 ModuleBlock.Version,
134 ModuleBlock.String,
135 ModuleBlock.Variable,
136 ModuleBlock.Function,
137 ModuleBlock.Alias,
168138 };
169139
170 pub const Version = struct {
171 pub const ops = [_]AbbrevOp{
172 .{ .literal = 1 },
173 .{ .array_fixed = 8 },
174 };
175 string: []const u8,
176 };
140 pub const Code = enum(u5) {
141 /// VERSION: [version#]
142 VERSION = 1,
143 /// TRIPLE: [strchr x N]
144 TRIPLE = 2,
145 /// DATALAYOUT: [strchr x N]
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 {
179 pub const ops = [_]AbbrevOp{
180 .{ .literal = 2 },
181 .{ .vbr = 6 },
182 };
183 epoch: u32,
184 };
185};
152 /// Deprecated, but still needed to read old bitcode files.
153 /// DEPLIB: [strchr x N]
154 DEPLIB = 6,
186155
187pub const Module = struct {
188 pub const id = 8;
156 /// GLOBALVAR: [pointer type, isconst, initid,
157 /// linkage, alignment, section, visibility, threadlocal]
158 GLOBALVAR = 7,
189159
190 pub const abbrevs = [_]type{
191 Version,
192 String,
193 Variable,
194 Function,
195 Alias,
160 /// FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment,
161 /// section, visibility, gc, unnamed_addr]
162 FUNCTION = 8,
163
164 /// ALIAS: [alias type, aliasee val#, linkage, visibility]
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,
196188 };
197189
198190 pub const Version = struct {
199191 pub const ops = [_]AbbrevOp{
200 .{ .literal = 1 },
192 .{ .literal = @intFromEnum(ModuleBlock.Code.VERSION) },
201193 .{ .literal = 2 },
202194 };
203195 };
......@@ -219,7 +211,7 @@ pub const Module = struct {
219211 };
220212
221213 pub const ops = [_]AbbrevOp{
222 .{ .literal = 7 }, // Code
214 .{ .literal = @intFromEnum(ModuleBlock.Code.GLOBALVAR) }, // Code
223215 .{ .vbr = 16 }, // strtab_offset
224216 .{ .vbr = 16 }, // strtab_size
225217 .{ .fixed_runtime = Builder.Type },
......@@ -255,7 +247,7 @@ pub const Module = struct {
255247
256248 pub const Function = struct {
257249 pub const ops = [_]AbbrevOp{
258 .{ .literal = 8 }, // Code
250 .{ .literal = @intFromEnum(ModuleBlock.Code.FUNCTION) }, // Code
259251 .{ .vbr = 16 }, // strtab_offset
260252 .{ .vbr = 16 }, // strtab_size
261253 .{ .fixed_runtime = Builder.Type },
......@@ -294,7 +286,7 @@ pub const Module = struct {
294286
295287 pub const Alias = struct {
296288 pub const ops = [_]AbbrevOp{
297 .{ .literal = 14 }, // Code
289 .{ .literal = @intFromEnum(ModuleBlock.Code.ALIAS) }, // Code
298290 .{ .vbr = 16 }, // strtab_offset
299291 .{ .vbr = 16 }, // strtab_size
300292 .{ .fixed_runtime = Builder.Type },
......@@ -319,1542 +311,1986 @@ pub const Module = struct {
319311 unnamed_addr: Builder.UnnamedAddr,
320312 preemption: Builder.Preemption,
321313 };
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 {
366 pub const ops = [_]AbbrevOp{
367 .{ .literal = 6 },
368 .{ .literal = 0 },
369 };
370 };
371
372 pub const Integer = struct {
373 pub const ops = [_]AbbrevOp{
374 .{ .literal = 7 },
375 .{ .fixed = 28 },
315 /// PARAMATTR blocks have code for defining a parameter attribute set.
316 pub const ParamattrBlock = struct {
317 pub const id: BlockId = .PARAMATTR;
318
319 pub const abbrevs = [_]type{
320 ModuleBlock.ParamattrBlock.Entry,
321 };
322
323 pub const Code = enum(u2) {
324 /// Deprecated, but still needed to read old bitcode files.
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,
3762181 };
377 width: u28,
378 };
3792182
380 pub const StructAnon = struct {
381 pub const ops = [_]AbbrevOp{
382 .{ .literal = 18 },
383 .{ .fixed = 1 },
384 .{ .array_fixed_runtime = Builder.Type },
2183 pub const Target = struct {
2184 pub const ops = [_]AbbrevOp{
2185 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.TARGET_TYPE) },
2186 .{ .vbr = 4 },
2187 .{ .array_fixed_runtime = Builder.Type },
2188 .{ .array_fixed = 32 },
2189 };
2190 num_types: u32,
2191 types: []const Builder.Type,
2192 ints: []const u32,
3852193 };
386 is_packed: bool,
387 types: []const Builder.Type,
388 };
3892194
390 pub const StructNamed = struct {
391 pub const ops = [_]AbbrevOp{
392 .{ .literal = 20 },
393 .{ .fixed = 1 },
394 .{ .array_fixed_runtime = Builder.Type },
2195 pub const Function = struct {
2196 pub const ops = [_]AbbrevOp{
2197 .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.FUNCTION) },
2198 .{ .fixed = 1 },
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,
3952205 };
396 is_packed: bool,
397 types: []const Builder.Type,
3982206 };
3992207
400 pub const StructName = struct {
401 pub const ops = [_]AbbrevOp{
402 .{ .literal = 19 },
403 .{ .array_fixed = 8 },
404 };
405 string: []const u8,
406 };
2208 pub const OperandBundleTagsBlock = struct {
2209 pub const id: BlockId = .OPERAND_BUNDLE_TAGS;
4072210
408 pub const Array = struct {
409 pub const ops = [_]AbbrevOp{
410 .{ .literal = 11 },
411 .{ .vbr = 16 },
412 .{ .fixed_runtime = Builder.Type },
2211 pub const abbrevs = [_]type{
2212 ModuleBlock.OperandBundleTagsBlock.OperandBundleTag,
4132213 };
414 len: u64,
415 child: Builder.Type,
416 };
4172214
418 pub const Vector = struct {
419 pub const ops = [_]AbbrevOp{
420 .{ .literal = 12 },
421 .{ .vbr = 16 },
422 .{ .fixed_runtime = Builder.Type },
2215 pub const Code = enum(u1) {
2216 /// TAG: [strchr x N]
2217 OPERAND_BUNDLE_TAG = 1,
4232218 };
424 len: u64,
425 child: Builder.Type,
426 };
4272219
428 pub const Pointer = struct {
429 pub const ops = [_]AbbrevOp{
430 .{ .literal = 25 },
431 .{ .vbr = 4 },
2220 pub const OperandBundleTag = struct {
2221 pub const ops = [_]AbbrevOp{
2222 .{ .literal = @intFromEnum(ModuleBlock.OperandBundleTagsBlock.Code.OPERAND_BUNDLE_TAG) },
2223 .array_char6,
2224 };
2225 tag: []const u8,
4322226 };
433 addr_space: Builder.AddrSpace,
4342227 };
4352228
436 pub const Target = struct {
437 pub const ops = [_]AbbrevOp{
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 };
2229 pub const MetadataKindBlock = struct {
2230 pub const id: BlockId = .METADATA_KIND;
4472231
448 pub const Function = struct {
449 pub const ops = [_]AbbrevOp{
450 .{ .literal = 21 },
451 .{ .fixed = 1 },
452 .{ .fixed_runtime = Builder.Type },
453 .{ .array_fixed_runtime = Builder.Type },
2232 pub const abbrevs = [_]type{
2233 ModuleBlock.MetadataKindBlock.Kind,
4542234 };
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 {
469 pub const ops = [_]AbbrevOp{
470 .{ .literal = 2 },
471 .{ .array_vbr = 8 },
2236 pub const Kind = struct {
2237 pub const ops = [_]AbbrevOp{
2238 .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.KIND) },
2239 .{ .vbr = 4 },
2240 .{ .array_fixed = 8 },
2241 };
2242 id: u32,
2243 name: []const u8,
4722244 };
473 group_indices: []const u64,
4742245 };
4752246};
4762247
477pub const ParamattrGroup = struct {
478 pub const id = 10;
479
480 pub const abbrevs = [_]type{};
481};
482
483pub const Constants = struct {
484 pub const id = 11;
2248/// Identification block contains a string that describes the producer details,
2249/// and an epoch that defines the auto-upgrade capability.
2250pub const IdentificationBlock = struct {
2251 pub const id: BlockId = .IDENTIFICATION;
4852252
4862253 pub const abbrevs = [_]type{
487 SetType,
488 Null,
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,
2254 IdentificationBlock.Version,
2255 IdentificationBlock.Epoch,
5952256 };
5962257
597 pub const String = struct {
598 pub const ops = [_]AbbrevOp{
599 .{ .literal = 8 },
600 .{ .array_fixed = 8 },
601 };
602 string: []const u8,
2258 pub const Code = enum(u2) {
2259 /// IDENTIFICATION: [strchr x N]
2260 STRING = 1,
2261 /// EPOCH: [epoch#]
2262 EPOCH = 2,
6032263 };
6042264
605 pub const CString = struct {
2265 pub const Version = struct {
6062266 pub const ops = [_]AbbrevOp{
607 .{ .literal = 9 },
2267 .{ .literal = @intFromEnum(IdentificationBlock.Code.STRING) },
6082268 .{ .array_fixed = 8 },
6092269 };
6102270 string: []const u8,
6112271 };
6122272
613 pub const Cast = 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 {
2273 pub const Epoch = struct {
6422274 pub const ops = [_]AbbrevOp{
643 .{ .literal = 17 },
644 .{ .fixed_runtime = Builder.Type },
645 ConstantAbbrev,
646 ConstantAbbrev,
2275 .{ .literal = @intFromEnum(IdentificationBlock.Code.EPOCH) },
6472276 .{ .vbr = 6 },
6482277 };
649
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,
2278 epoch: u32,
7842279 };
7852280};
7862281
787pub const MetadataBlock = struct {
788 pub const id = 15;
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 };
2282pub const StrtabBlock = struct {
2283 pub const id: BlockId = .STRTAB;
8362284
837 filename: Builder.MetadataString,
838 directory: Builder.MetadataString,
839 };
2285 pub const abbrevs = [_]type{Blob};
8402286
841 pub const CompileUnit = struct {
842 pub const ops = [_]AbbrevOp{
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,
2287 pub const Code = enum(u1) {
2288 BLOB = 1,
8732289 };
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
18552291 pub const Blob = struct {
18562292 pub const ops = [_]AbbrevOp{
1857 .{ .literal = 1 },
2293 .{ .literal = @intFromEnum(StrtabBlock.Code.BLOB) },
18582294 .blob,
18592295 };
18602296 blob: []const u8,
src/codegen/llvm.zig+182-197
......@@ -508,16 +508,16 @@ pub const Object = struct {
508508 gpa: Allocator,
509509 builder: Builder,
510510
511 debug_compile_unit: Builder.Metadata,
511 debug_compile_unit: Builder.Metadata.Optional,
512512
513 debug_enums_fwd_ref: Builder.Metadata,
514 debug_globals_fwd_ref: Builder.Metadata,
513 debug_enums_fwd_ref: Builder.Metadata.Optional,
514 debug_globals_fwd_ref: Builder.Metadata.Optional,
515515
516516 debug_enums: std.ArrayListUnmanaged(Builder.Metadata),
517517 debug_globals: std.ArrayListUnmanaged(Builder.Metadata),
518518
519519 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
522522 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata),
523523
......@@ -630,9 +630,13 @@ pub const Object = struct {
630630 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
631631 );
632632
633 try builder.metadataNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});
634 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };
635 } else .{.none} ** 3;
633 try builder.addNamedMetadata(try builder.string("llvm.dbg.cu"), &.{debug_compile_unit});
634 break :debug_info .{
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
637641 const obj = try arena.create(Object);
638642 obj.* = .{
......@@ -816,17 +820,17 @@ pub const Object = struct {
816820 const namespace = zcu.namespacePtr(namespace_index);
817821 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);
820824 }
821825 }
822826
823 o.builder.debugForwardReferenceSetType(
824 o.debug_enums_fwd_ref,
827 o.builder.resolveDebugForwardReference(
828 o.debug_enums_fwd_ref.unwrap().?,
825829 try o.builder.metadataTuple(o.debug_enums.items),
826830 );
827831
828 o.builder.debugForwardReferenceSetType(
829 o.debug_globals_fwd_ref,
832 o.builder.resolveDebugForwardReference(
833 o.debug_globals_fwd_ref.unwrap().?,
830834 try o.builder.metadataTuple(o.debug_globals.items),
831835 );
832836 }
......@@ -842,36 +846,34 @@ pub const Object = struct {
842846 const behavior_min = try o.builder.metadataConstant(try o.builder.intConst(.i32, 8));
843847
844848 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(&.{
846850 behavior_error,
847 try o.builder.metadataString("target-abi"),
848 try o.builder.metadataConstant(
849 try o.builder.stringConst(try o.builder.string(abi)),
850 ),
851 ));
851 (try o.builder.metadataString("target-abi")).toMetadata(),
852 (try o.builder.metadataString(abi)).toMetadata(),
853 }));
852854 }
853855
854856 const pic_level = target_util.picLevel(&comp.root_mod.resolved_target.result);
855857 if (comp.root_mod.pic) {
856 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
858 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
857859 behavior_min,
858 try o.builder.metadataString("PIC Level"),
860 (try o.builder.metadataString("PIC Level")).toMetadata(),
859861 try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)),
860 ));
862 }));
861863 }
862864
863865 if (comp.config.pie) {
864 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
866 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
865867 behavior_max,
866 try o.builder.metadataString("PIE Level"),
868 (try o.builder.metadataString("PIE Level")).toMetadata(),
867869 try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)),
868 ));
870 }));
869871 }
870872
871873 if (comp.root_mod.code_model != .default) {
872 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
874 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
873875 behavior_error,
874 try o.builder.metadataString("Code Model"),
876 (try o.builder.metadataString("Code Model")).toMetadata(),
875877 try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(
876878 i32,
877879 switch (codeModel(comp.root_mod.code_model, &comp.root_mod.resolved_target.result)) {
......@@ -883,39 +885,39 @@ pub const Object = struct {
883885 .large => 4,
884886 },
885887 ))),
886 ));
888 }));
887889 }
888890
889891 if (!o.builder.strip) {
890 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
892 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
891893 behavior_warning,
892 try o.builder.metadataString("Debug Info Version"),
894 (try o.builder.metadataString("Debug Info Version")).toMetadata(),
893895 try o.builder.metadataConstant(try o.builder.intConst(.i32, 3)),
894 ));
896 }));
895897
896898 switch (comp.config.debug_format) {
897899 .strip => unreachable,
898900 .dwarf => |f| {
899 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
901 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
900902 behavior_max,
901 try o.builder.metadataString("Dwarf Version"),
903 (try o.builder.metadataString("Dwarf Version")).toMetadata(),
902904 try o.builder.metadataConstant(try o.builder.intConst(.i32, 4)),
903 ));
905 }));
904906
905907 if (f == .@"64") {
906 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
908 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
907909 behavior_max,
908 try o.builder.metadataString("DWARF64"),
910 (try o.builder.metadataString("DWARF64")).toMetadata(),
909911 try o.builder.metadataConstant(.@"1"),
910 ));
912 }));
911913 }
912914 },
913915 .code_view => {
914 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
916 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
915917 behavior_warning,
916 try o.builder.metadataString("CodeView"),
918 (try o.builder.metadataString("CodeView")).toMetadata(),
917919 try o.builder.metadataConstant(.@"1"),
918 ));
920 }));
919921 },
920922 }
921923 }
......@@ -925,14 +927,14 @@ pub const Object = struct {
925927 // Add the "RegCallv4" flag so that any functions using `x86_regcallcc` use regcall
926928 // v4, which is essentially a requirement on Windows. See corresponding logic in
927929 // `toLlvmCallConvTag`.
928 module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
930 module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{
929931 behavior_max,
930 try o.builder.metadataString("RegCallv4"),
932 (try o.builder.metadataString("RegCallv4")).toMetadata(),
931933 try o.builder.metadataConstant(.@"1"),
932 ));
934 }));
933935 }
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);
936938 }
937939
938940 const target_triple_sentinel =
......@@ -1477,11 +1479,11 @@ pub const Object = struct {
14771479 .LocalToUnit = is_internal_linkage,
14781480 },
14791481 },
1480 o.debug_compile_unit,
1482 o.debug_compile_unit.unwrap().?,
14811483 );
14821484 function_index.setSubprogram(subprogram, &o.builder);
14831485 break :debug_info .{ file, subprogram };
1484 } else .{.none} ** 2;
1486 } else .{undefined} ** 2;
14851487
14861488 const fuzz: ?FuncGen.Fuzz = f: {
14871489 if (!owner_mod.fuzz) break :f null;
......@@ -1807,7 +1809,7 @@ pub const Object = struct {
18071809 const zcu = pt.zcu;
18081810 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
18121814 switch (ty.zigTypeTag(zcu)) {
18131815 .void,
......@@ -1817,7 +1819,7 @@ pub const Object = struct {
18171819 try o.builder.metadataString("void"),
18181820 0,
18191821 );
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);
18211823 return debug_void_type;
18221824 },
18231825 .int => {
......@@ -1831,13 +1833,13 @@ pub const Object = struct {
18311833 .signed => try o.builder.debugSignedType(builder_name, debug_bits),
18321834 .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits),
18331835 };
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);
18351837 return debug_int_type;
18361838 },
18371839 .@"enum" => {
18381840 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
18391841 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);
18411843 return debug_enum_type;
18421844 }
18431845
......@@ -1884,7 +1886,7 @@ pub const Object = struct {
18841886 try o.builder.metadataTuple(enumerators),
18851887 );
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);
18881890 try o.debug_enums.append(gpa, debug_enum_type);
18891891 return debug_enum_type;
18901892 },
......@@ -1896,7 +1898,7 @@ pub const Object = struct {
18961898 try o.builder.metadataString(name),
18971899 bits,
18981900 );
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);
19001902 return debug_float_type;
19011903 },
19021904 .bool => {
......@@ -1904,7 +1906,7 @@ pub const Object = struct {
19041906 try o.builder.metadataString("bool"),
19051907 8, // lldb cannot handle non-byte sized types
19061908 );
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);
19081910 return debug_bool_type;
19091911 },
19101912 .pointer => {
......@@ -1936,14 +1938,14 @@ pub const Object = struct {
19361938 },
19371939 });
19381940 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);
19401942 return debug_ptr_type;
19411943 }
19421944
19431945 const debug_fwd_ref = try o.builder.debugForwardReference();
19441946
19451947 // 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
19481950 if (ty.isSlice(zcu)) {
19491951 const ptr_ty = ty.slicePtrFieldType(zcu);
......@@ -1962,7 +1964,7 @@ pub const Object = struct {
19621964
19631965 const debug_ptr_type = try o.builder.debugMemberType(
19641966 try o.builder.metadataString("ptr"),
1965 .none, // File
1967 null, // File
19661968 debug_fwd_ref,
19671969 0, // Line
19681970 try o.lowerDebugType(pt, ptr_ty),
......@@ -1973,7 +1975,7 @@ pub const Object = struct {
19731975
19741976 const debug_len_type = try o.builder.debugMemberType(
19751977 try o.builder.metadataString("len"),
1976 .none, // File
1978 null, // File
19771979 debug_fwd_ref,
19781980 0, // Line
19791981 try o.lowerDebugType(pt, len_ty),
......@@ -1984,10 +1986,10 @@ pub const Object = struct {
19841986
19851987 const debug_slice_type = try o.builder.debugStructType(
19861988 try o.builder.metadataString(name),
1987 .none, // File
1988 o.debug_compile_unit, // Scope
1989 null, // File
1990 o.debug_compile_unit.unwrap().?, // Scope
19891991 line,
1990 .none, // Underlying type
1992 null, // Underlying type
19911993 ty.abiSize(zcu) * 8,
19921994 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
19931995 try o.builder.metadataTuple(&.{
......@@ -1996,10 +1998,10 @@ pub const Object = struct {
19961998 }),
19971999 );
19982000
1999 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type);
2001 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_slice_type);
20002002
20012003 // 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;
20032005 map_ptr.* = debug_slice_type;
20042006
20052007 return debug_slice_type;
......@@ -2012,8 +2014,8 @@ pub const Object = struct {
20122014
20132015 const debug_ptr_type = try o.builder.debugPointerType(
20142016 try o.builder.metadataString(name),
2015 .none, // File
2016 .none, // Scope
2017 null, // File
2018 null, // Scope
20172019 0, // Line
20182020 debug_elem_ty,
20192021 target.ptrBitWidth(),
......@@ -2021,10 +2023,10 @@ pub const Object = struct {
20212023 0, // Offset
20222024 );
20232025
2024 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_ptr_type);
2026 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_ptr_type);
20252027
20262028 // 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;
20282030 map_ptr.* = debug_ptr_type;
20292031
20302032 return debug_ptr_type;
......@@ -2035,7 +2037,7 @@ pub const Object = struct {
20352037 try o.builder.metadataString("anyopaque"),
20362038 0,
20372039 );
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);
20392041 return debug_opaque_type;
20402042 }
20412043
......@@ -2053,19 +2055,19 @@ pub const Object = struct {
20532055 file,
20542056 scope,
20552057 ty.typeDeclSrcLine(zcu).? + 1, // Line
2056 .none, // Underlying type
2058 null, // Underlying type
20572059 0, // Size
20582060 0, // Align
2059 .none, // Fields
2061 null, // Fields
20602062 );
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);
20622064 return debug_opaque_type;
20632065 },
20642066 .array => {
20652067 const debug_array_type = try o.builder.debugArrayType(
2066 .none, // Name
2067 .none, // File
2068 .none, // Scope
2068 null, // Name
2069 null, // File
2070 null, // Scope
20692071 0, // Line
20702072 try o.lowerDebugType(pt, ty.childType(zcu)),
20712073 ty.abiSize(zcu) * 8,
......@@ -2077,7 +2079,7 @@ pub const Object = struct {
20772079 ),
20782080 }),
20792081 );
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);
20812083 return debug_array_type;
20822084 },
20832085 .vector => {
......@@ -2106,9 +2108,9 @@ pub const Object = struct {
21062108 };
21072109
21082110 const debug_vector_type = try o.builder.debugVectorType(
2109 .none, // Name
2110 .none, // File
2111 .none, // Scope
2111 null, // Name
2112 null, // File
2113 null, // Scope
21122114 0, // Line
21132115 debug_elem_type,
21142116 ty.abiSize(zcu) * 8,
......@@ -2121,7 +2123,7 @@ pub const Object = struct {
21212123 }),
21222124 );
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);
21252127 return debug_vector_type;
21262128 },
21272129 .optional => {
......@@ -2133,22 +2135,22 @@ pub const Object = struct {
21332135 try o.builder.metadataString(name),
21342136 8,
21352137 );
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);
21372139 return debug_bool_type;
21382140 }
21392141
21402142 const debug_fwd_ref = try o.builder.debugForwardReference();
21412143
21422144 // 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
21452147 if (ty.optionalReprIsPayload(zcu)) {
21462148 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
21502152 // 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;
21522154 map_ptr.* = debug_optional_type;
21532155
21542156 return debug_optional_type;
......@@ -2163,7 +2165,7 @@ pub const Object = struct {
21632165
21642166 const debug_data_type = try o.builder.debugMemberType(
21652167 try o.builder.metadataString("data"),
2166 .none, // File
2168 null, // File
21672169 debug_fwd_ref,
21682170 0, // Line
21692171 try o.lowerDebugType(pt, child_ty),
......@@ -2174,7 +2176,7 @@ pub const Object = struct {
21742176
21752177 const debug_some_type = try o.builder.debugMemberType(
21762178 try o.builder.metadataString("some"),
2177 .none,
2179 null,
21782180 debug_fwd_ref,
21792181 0,
21802182 try o.lowerDebugType(pt, non_null_ty),
......@@ -2185,10 +2187,10 @@ pub const Object = struct {
21852187
21862188 const debug_optional_type = try o.builder.debugStructType(
21872189 try o.builder.metadataString(name),
2188 .none, // File
2189 o.debug_compile_unit, // Scope
2190 null, // File
2191 o.debug_compile_unit.unwrap().?, // Scope
21902192 0, // Line
2191 .none, // Underlying type
2193 null, // Underlying type
21922194 ty.abiSize(zcu) * 8,
21932195 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
21942196 try o.builder.metadataTuple(&.{
......@@ -2197,10 +2199,10 @@ pub const Object = struct {
21972199 }),
21982200 );
21992201
2200 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
2202 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_optional_type);
22012203
22022204 // 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;
22042206 map_ptr.* = debug_optional_type;
22052207
22062208 return debug_optional_type;
......@@ -2210,7 +2212,7 @@ pub const Object = struct {
22102212 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
22112213 // TODO: Maybe remove?
22122214 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);
22142216 return debug_error_union_type;
22152217 }
22162218
......@@ -2243,7 +2245,7 @@ pub const Object = struct {
22432245 var fields: [2]Builder.Metadata = undefined;
22442246 fields[error_index] = try o.builder.debugMemberType(
22452247 try o.builder.metadataString("tag"),
2246 .none, // File
2248 null, // File
22472249 debug_fwd_ref,
22482250 0, // Line
22492251 try o.lowerDebugType(pt, Type.anyerror),
......@@ -2253,7 +2255,7 @@ pub const Object = struct {
22532255 );
22542256 fields[payload_index] = try o.builder.debugMemberType(
22552257 try o.builder.metadataString("value"),
2256 .none, // File
2258 null, // File
22572259 debug_fwd_ref,
22582260 0, // Line
22592261 try o.lowerDebugType(pt, payload_ty),
......@@ -2264,18 +2266,18 @@ pub const Object = struct {
22642266
22652267 const debug_error_union_type = try o.builder.debugStructType(
22662268 try o.builder.metadataString(name),
2267 .none, // File
2268 o.debug_compile_unit, // Sope
2269 null, // File
2270 o.debug_compile_unit.unwrap().?, // Sope
22692271 0, // Line
2270 .none, // Underlying type
2272 null, // Underlying type
22712273 ty.abiSize(zcu) * 8,
22722274 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
22732275 try o.builder.metadataTuple(&fields),
22742276 );
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);
22792281 return debug_error_union_type;
22802282 },
22812283 .error_set => {
......@@ -2283,7 +2285,7 @@ pub const Object = struct {
22832285 try o.builder.metadataString("anyerror"),
22842286 16,
22852287 );
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);
22872289 return debug_error_set;
22882290 },
22892291 .@"struct" => {
......@@ -2299,7 +2301,7 @@ pub const Object = struct {
22992301 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(zcu) * 8),
23002302 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(zcu) * 8),
23012303 };
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);
23032305 return debug_int_type;
23042306 }
23052307 }
......@@ -2329,7 +2331,7 @@ pub const Object = struct {
23292331
23302332 fields.appendAssumeCapacity(try o.builder.debugMemberType(
23312333 try o.builder.metadataString(field_name),
2332 .none, // File
2334 null, // File
23332335 debug_fwd_ref,
23342336 0,
23352337 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
......@@ -2341,18 +2343,18 @@ pub const Object = struct {
23412343
23422344 const debug_struct_type = try o.builder.debugStructType(
23432345 try o.builder.metadataString(name),
2344 .none, // File
2345 o.debug_compile_unit, // Scope
2346 null, // File
2347 o.debug_compile_unit.unwrap().?, // Scope
23462348 0, // Line
2347 .none, // Underlying type
2349 null, // Underlying type
23482350 ty.abiSize(zcu) * 8,
23492351 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
23502352 try o.builder.metadataTuple(fields.items),
23512353 );
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);
23562358 return debug_struct_type;
23572359 },
23582360 .struct_type => {
......@@ -2365,7 +2367,7 @@ pub const Object = struct {
23652367 // rather than changing the frontend to unnecessarily resolve the
23662368 // struct field types.
23672369 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);
23692371 return debug_struct_type;
23702372 }
23712373 },
......@@ -2374,7 +2376,7 @@ pub const Object = struct {
23742376
23752377 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
23762378 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);
23782380 return debug_struct_type;
23792381 }
23802382
......@@ -2388,7 +2390,7 @@ pub const Object = struct {
23882390 const debug_fwd_ref = try o.builder.debugForwardReference();
23892391
23902392 // 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
23932395 comptime assert(struct_layout_version == 2);
23942396 var it = struct_type.iterateRuntimeOrder(ip);
......@@ -2402,7 +2404,7 @@ pub const Object = struct {
24022404 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
24032405 fields.appendAssumeCapacity(try o.builder.debugMemberType(
24042406 try o.builder.metadataString(field_name.toSlice(ip)),
2405 .none, // File
2407 null, // File
24062408 debug_fwd_ref,
24072409 0, // Line
24082410 try o.lowerDebugType(pt, field_ty),
......@@ -2414,19 +2416,19 @@ pub const Object = struct {
24142416
24152417 const debug_struct_type = try o.builder.debugStructType(
24162418 try o.builder.metadataString(name),
2417 .none, // File
2418 o.debug_compile_unit, // Scope
2419 null, // File
2420 o.debug_compile_unit.unwrap().?, // Scope
24192421 0, // Line
2420 .none, // Underlying type
2422 null, // Underlying type
24212423 ty.abiSize(zcu) * 8,
24222424 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
24232425 try o.builder.metadataTuple(fields.items),
24242426 );
24252427
2426 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type);
2428 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_struct_type);
24272429
24282430 // 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;
24302432 map_ptr.* = debug_struct_type;
24312433
24322434 return debug_struct_type;
......@@ -2441,7 +2443,7 @@ pub const Object = struct {
24412443 !union_type.haveLayout(ip))
24422444 {
24432445 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);
24452447 return debug_union_type;
24462448 }
24472449
......@@ -2450,15 +2452,15 @@ pub const Object = struct {
24502452 const debug_fwd_ref = try o.builder.debugForwardReference();
24512453
24522454 // 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
24552457 if (layout.payload_size == 0) {
24562458 const debug_union_type = try o.builder.debugStructType(
24572459 try o.builder.metadataString(name),
2458 .none, // File
2459 o.debug_compile_unit, // Scope
2460 null, // File
2461 o.debug_compile_unit.unwrap().?, // Scope
24602462 0, // Line
2461 .none, // Underlying type
2463 null, // Underlying type
24622464 ty.abiSize(zcu) * 8,
24632465 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
24642466 try o.builder.metadataTuple(
......@@ -2467,7 +2469,7 @@ pub const Object = struct {
24672469 );
24682470
24692471 // 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;
24712473 map_ptr.* = debug_union_type;
24722474
24732475 return debug_union_type;
......@@ -2498,7 +2500,7 @@ pub const Object = struct {
24982500 const field_name = tag_type.names.get(ip)[field_index];
24992501 fields.appendAssumeCapacity(try o.builder.debugMemberType(
25002502 try o.builder.metadataString(field_name.toSlice(ip)),
2501 .none, // File
2503 null, // File
25022504 debug_union_fwd_ref,
25032505 0, // Line
25042506 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
......@@ -2517,20 +2519,20 @@ pub const Object = struct {
25172519
25182520 const debug_union_type = try o.builder.debugUnionType(
25192521 try o.builder.metadataString(union_name),
2520 .none, // File
2521 o.debug_compile_unit, // Scope
2522 null, // File
2523 o.debug_compile_unit.unwrap().?, // Scope
25222524 0, // Line
2523 .none, // Underlying type
2525 null, // Underlying type
25242526 layout.payload_size * 8,
25252527 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
25262528 try o.builder.metadataTuple(fields.items),
25272529 );
25282530
2529 o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type);
2531 o.builder.resolveDebugForwardReference(debug_union_fwd_ref, debug_union_type);
25302532
25312533 if (layout.tag_size == 0) {
25322534 // 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;
25342536 map_ptr.* = debug_union_type;
25352537
25362538 return debug_union_type;
......@@ -2548,7 +2550,7 @@ pub const Object = struct {
25482550
25492551 const debug_tag_type = try o.builder.debugMemberType(
25502552 try o.builder.metadataString("tag"),
2551 .none, // File
2553 null, // File
25522554 debug_fwd_ref,
25532555 0, // Line
25542556 try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty)),
......@@ -2559,7 +2561,7 @@ pub const Object = struct {
25592561
25602562 const debug_payload_type = try o.builder.debugMemberType(
25612563 try o.builder.metadataString("payload"),
2562 .none, // File
2564 null, // File
25632565 debug_fwd_ref,
25642566 0, // Line
25652567 debug_union_type,
......@@ -2576,19 +2578,19 @@ pub const Object = struct {
25762578
25772579 const debug_tagged_union_type = try o.builder.debugStructType(
25782580 try o.builder.metadataString(name),
2579 .none, // File
2580 o.debug_compile_unit, // Scope
2581 null, // File
2582 o.debug_compile_unit.unwrap().?, // Scope
25812583 0, // Line
2582 .none, // Underlying type
2584 null, // Underlying type
25832585 ty.abiSize(zcu) * 8,
25842586 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
25852587 try o.builder.metadataTuple(&full_fields),
25862588 );
25872589
2588 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_tagged_union_type);
2590 o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_tagged_union_type);
25892591
25902592 // 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;
25922594 map_ptr.* = debug_tagged_union_type;
25932595
25942596 return debug_tagged_union_type;
......@@ -2636,7 +2638,7 @@ pub const Object = struct {
26362638 try o.builder.metadataTuple(debug_param_types.items),
26372639 );
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);
26402642 return debug_function_type;
26412643 },
26422644 .comptime_int => unreachable,
......@@ -2676,10 +2678,10 @@ pub const Object = struct {
26762678 file,
26772679 scope,
26782680 ty.typeDeclSrcLine(zcu).? + 1,
2679 .none,
2681 null,
26802682 0,
26812683 0,
2682 .none,
2684 null,
26832685 );
26842686 }
26852687
......@@ -4687,7 +4689,7 @@ pub const FuncGen = struct {
46874689 file: Builder.Metadata,
46884690 scope: Builder.Metadata,
46894691
4690 inlined: Builder.DebugLocation = .no_location,
4692 inlined_at: Builder.Metadata.Optional = .none,
46914693
46924694 base_line: u32,
46934695 prev_dbg_line: c_uint,
......@@ -5156,16 +5158,18 @@ pub const FuncGen = struct {
51565158 ) Error!void {
51575159 if (self.wip.strip) return self.genBody(body, coverage_point);
51585160
5161 const old_debug_location = self.wip.debug_location;
51595162 const old_file = self.file;
5160 const old_inlined = self.inlined;
5163 const old_inlined_at = self.inlined_at;
51615164 const old_base_line = self.base_line;
5162 const old_scope = self.scope;
51635165 defer if (maybe_inline_func) |_| {
5164 self.wip.debug_location = self.inlined;
5166 self.wip.debug_location = old_debug_location;
51655167 self.file = old_file;
5166 self.inlined = old_inlined;
5168 self.inlined_at = old_inlined_at;
51675169 self.base_line = old_base_line;
51685170 };
5171
5172 const old_scope = self.scope;
51695173 defer self.scope = old_scope;
51705174
51715175 if (maybe_inline_func) |inline_func| {
......@@ -5181,8 +5185,9 @@ pub const FuncGen = struct {
51815185
51825186 self.file = try o.getDebugFile(pt, file_scope);
51835187
5184 const line_number = zcu.navSrcLine(func.owner_nav) + 1;
5185 self.inlined = self.wip.debug_location;
5188 self.base_line = zcu.navSrcLine(func.owner_nav);
5189 const line_number = self.base_line + 1;
5190 self.inlined_at = try self.wip.debug_location.toMetadata(&o.builder);
51865191
51875192 const fn_ty = try pt.funcType(.{
51885193 .param_types = &.{},
......@@ -5201,23 +5206,11 @@ pub const FuncGen = struct {
52015206 .sp_flags = .{
52025207 .Optimized = mod.optimize_mode != .Debug,
52035208 .Definition = true,
5204 // TODO: we can't know this at this point, since the function could be exported later!
5205 .LocalToUnit = true,
5209 .LocalToUnit = true, // inline functions cannot be exported
52065210 },
52075211 },
5208 o.debug_compile_unit,
5212 o.debug_compile_unit.unwrap().?,
52095213 );
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 };
52215214 }
52225215
52235216 self.scope = try self.ng.object.builder.debugLexicalBlock(
......@@ -5226,15 +5219,12 @@ pub const FuncGen = struct {
52265219 self.prev_dbg_line,
52275220 self.prev_dbg_column,
52285221 );
5229
5230 switch (self.wip.debug_location) {
5231 .location => |*l| l.scope = self.scope,
5232 .no_location => {},
5233 }
5234 defer switch (self.wip.debug_location) {
5235 .location => |*l| l.scope = old_scope,
5236 .no_location => {},
5237 };
5222 self.wip.debug_location = .{ .location = .{
5223 .line = self.prev_dbg_line,
5224 .column = self.prev_dbg_column,
5225 .scope = self.scope.toOptional(),
5226 .inlined_at = self.inlined_at,
5227 } };
52385228
52395229 try self.genBody(body, coverage_point);
52405230 }
......@@ -6516,8 +6506,13 @@ pub const FuncGen = struct {
65166506 break :llvm_cases_len len;
65176507 };
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);
65206510 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
65226517 const else_weight: u32 = switch (switch_br.getElseHint()) {
65236518 .unpredictable => unreachable,
......@@ -6525,9 +6520,9 @@ pub const FuncGen = struct {
65256520 .likely => 2000,
65266521 .unlikely => 1,
65276522 };
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;
65316526 var it = switch_br.iterateCases();
65326527 while (it.next()) |case| {
65336528 const weight_val: u32 = switch (switch_br.getHint(case.idx)) {
......@@ -6542,10 +6537,7 @@ pub const FuncGen = struct {
65426537 }
65436538
65446539 assert(weight_idx == weights.len);
6545
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));
6540 break :weights .fromMetadata(try o.builder.metadataTuple(weights));
65496541 };
65506542
65516543 const dispatch_info: SwitchDispatchInfo = .{
......@@ -7102,14 +7094,12 @@ pub const FuncGen = struct {
71027094 self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1);
71037095 self.prev_dbg_column = @intCast(dbg_stmt.column + 1);
71047096
7105 self.wip.debug_location = .{
7106 .location = .{
7107 .line = self.prev_dbg_line,
7108 .column = self.prev_dbg_column,
7109 .scope = self.scope,
7110 .inlined_at = try self.inlined.toMetadata(self.wip.builder),
7111 },
7112 };
7097 self.wip.debug_location = .{ .location = .{
7098 .line = self.prev_dbg_line,
7099 .column = self.prev_dbg_column,
7100 .scope = self.scope.toOptional(),
7101 .inlined_at = self.inlined_at,
7102 } };
71137103
71147104 return .none;
71157105 }
......@@ -7167,9 +7157,10 @@ pub const FuncGen = struct {
71677157 const operand = try self.resolveInst(pl_op.operand);
71687158 const operand_ty = self.typeOf(pl_op.operand);
71697159 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
7170
7160 const name_slice = name.toSlice(self.air);
7161 const metadata_name = if (name_slice.len > 0) try o.builder.metadataString(name_slice) else null;
71717162 const debug_local_var = if (is_arg) try o.builder.debugParameter(
7172 try o.builder.metadataString(name.toSlice(self.air)),
7163 metadata_name,
71737164 self.file,
71747165 self.scope,
71757166 self.prev_dbg_line,
......@@ -7179,7 +7170,7 @@ pub const FuncGen = struct {
71797170 break :arg_no self.arg_inline_index;
71807171 },
71817172 ) else try o.builder.debugLocalVar(
7182 try o.builder.metadataString(name.toSlice(self.air)),
7173 metadata_name,
71837174 self.file,
71847175 self.scope,
71857176 self.prev_dbg_line,
......@@ -9547,7 +9538,7 @@ pub const FuncGen = struct {
95479538 const lbrace_col = func.lbrace_column + 1;
95489539
95499540 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,
95519542 self.file,
95529543 self.scope,
95539544 lbrace_line,
......@@ -9556,14 +9547,12 @@ pub const FuncGen = struct {
95569547 );
95579548
95589549 const old_location = self.wip.debug_location;
9559 self.wip.debug_location = .{
9560 .location = .{
9561 .line = lbrace_line,
9562 .column = lbrace_col,
9563 .scope = self.scope,
9564 .inlined_at = .none,
9565 },
9566 };
9550 self.wip.debug_location = .{ .location = .{
9551 .line = lbrace_line,
9552 .column = lbrace_col,
9553 .scope = self.scope.toOptional(),
9554 .inlined_at = .none,
9555 } };
95679556
95689557 if (isByRef(inst_ty, zcu)) {
95699558 _ = try self.wip.callIntrinsic(
......@@ -12614,11 +12603,7 @@ fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key
1261412603 };
1261512604}
1261612605
12617fn ccAbiPromoteInt(
12618 cc: std.builtin.CallingConvention,
12619 zcu: *Zcu,
12620 ty: Type,
12621) ?std.builtin.Signedness {
12606fn ccAbiPromoteInt(cc: std.builtin.CallingConvention, zcu: *Zcu, ty: Type) ?std.builtin.Signedness {
1262212607 const target = zcu.getTarget();
1262312608 switch (cc) {
1262412609 .auto, .@"inline", .async => return null,