authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-19 16:29:45-07:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-27 00:41:49+01:00
log72e00805a61719174b1668d5ce3cbef8338e4690
tree302f039fc8f31e4b4afbc09f503bbf085aadaafb
parentf2d7096bb9d21f5668d22567d1c96b95970cb480
signaturelock-open Commit is signed but in an unrecognized format.

llvm.Builder: add support for more instruction metadata

mlugg: this is cherry-picked from Andrew's nosanitize branch (with Jacob's fixes squashed in) since I needed this for `unpredictable` and `prof` metadata. The nosanitize-specific changes are reverted in the next commit. Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>

2 files changed, 254 insertions(+), 106 deletions(-)

src/codegen/llvm/Builder.zig+78-77
...@@ -7697,6 +7697,7 @@ pub const MetadataString = enum(u32) {...@@ -7697,6 +7697,7 @@ pub const MetadataString = enum(u32) {
76977697
7698pub const Metadata = enum(u32) {7698pub const Metadata = enum(u32) {
7699 none = 0,7699 none = 0,
7700 empty_tuple = 1,
7700 _,7701 _,
77017702
7702 const first_forward_reference = 1 << 29;7703 const first_forward_reference = 1 << 29;
...@@ -8355,7 +8356,7 @@ pub const Metadata = enum(u32) {...@@ -8355,7 +8356,7 @@ pub const Metadata = enum(u32) {
8355};8356};
83568357
8357pub fn init(options: Options) Allocator.Error!Builder {8358pub fn init(options: Options) Allocator.Error!Builder {
8358 var self = Builder{8359 var self: Builder = .{
8359 .gpa = options.allocator,8360 .gpa = options.allocator,
8360 .strip = options.strip,8361 .strip = options.strip,
83618362
...@@ -8458,6 +8459,7 @@ pub fn init(options: Options) Allocator.Error!Builder {...@@ -8458,6 +8459,7 @@ pub fn init(options: Options) Allocator.Error!Builder {
84588459
8459 try self.metadata_string_indices.append(self.gpa, 0);8460 try self.metadata_string_indices.append(self.gpa, 0);
8460 assert(try self.metadataString("") == .none);8461 assert(try self.metadataString("") == .none);
8462 assert(try self.debugTuple(&.{}) == .empty_tuple);
84618463
8462 return self;8464 return self;
8463}8465}
...@@ -13759,7 +13761,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13759,7 +13761,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13759 const MetadataKindBlock = ir.MetadataKindBlock;13761 const MetadataKindBlock = ir.MetadataKindBlock;
13760 var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true);13762 var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true);
1376113763
13762 inline for (@typeInfo(ir.MetadataKind).Enum.fields) |field| {13764 inline for (@typeInfo(ir.FixedMetadataKind).Enum.fields) |field| {
13763 try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{13765 try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{
13764 .id = field.value,13766 .id = field.value,
13765 .name = field.name,13767 .name = field.name,
...@@ -14046,7 +14048,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14046,7 +14048,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14046 else14048 else
14047 -%val << 1 | 1);14049 -%val << 1 | 1);
14048 }14050 }
14049 try metadata_block.writeUnabbrev(MetadataBlock.Enumerator.id, record.items);14051 try metadata_block.writeUnabbrev(@intFromEnum(MetadataBlock.Enumerator.id), record.items);
14050 continue;14052 continue;
14051 };14053 };
14052 try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{14054 try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{
...@@ -14177,7 +14179,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14177,7 +14179,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1417714179
14178 try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{14180 try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{
14179 .value = @enumFromInt(constant_adapter.getConstantIndex(global.toConst())),14181 .value = @enumFromInt(constant_adapter.getConstantIndex(global.toConst())),
14180 .kind = ir.MetadataKind.dbg,14182 .kind = .dbg,
14181 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(global_ptr.dbg) - 1),14183 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(global_ptr.dbg) - 1),
14182 });14184 });
14183 }14185 }
...@@ -14220,20 +14222,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14220,20 +14222,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14220 constant_adapter: ConstantAdapter,14222 constant_adapter: ConstantAdapter,
14221 metadata_adapter: MetadataAdapter,14223 metadata_adapter: MetadataAdapter,
14222 func: *const Function,14224 func: *const Function,
14223 instruction_index: u32 = 0,14225 instruction_index: Function.Instruction.Index,
14224
14225 pub fn init(
14226 const_adapter: ConstantAdapter,
14227 meta_adapter: MetadataAdapter,
14228 func: *const Function,
14229 ) @This() {
14230 return .{
14231 .constant_adapter = const_adapter,
14232 .metadata_adapter = meta_adapter,
14233 .func = func,
14234 .instruction_index = 0,
14235 };
14236 }
1423714226
14238 pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) {14227 pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) {
14239 _ = field_name;14228 _ = field_name;
...@@ -14282,19 +14271,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14282,19 +14271,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14282 }14271 }
1428314272
14284 pub fn offset(adapter: @This()) u32 {14273 pub fn offset(adapter: @This()) u32 {
14285 return @as(14274 return adapter.instruction_index.valueIndex(adapter.func) + adapter.firstInstr();
14286 Function.Instruction.Index,
14287 @enumFromInt(adapter.instruction_index),
14288 ).valueIndex(adapter.func) + adapter.firstInstr();
14289 }14275 }
1429014276
14291 fn firstInstr(adapter: @This()) u32 {14277 fn firstInstr(adapter: @This()) u32 {
14292 return adapter.constant_adapter.numConstants();14278 return adapter.constant_adapter.numConstants();
14293 }14279 }
14294
14295 pub fn next(adapter: *@This()) void {
14296 adapter.instruction_index += 1;
14297 }
14298 };14280 };
1429914281
14300 for (self.functions.items, 0..) |func, func_index| {14282 for (self.functions.items, 0..) |func, func_index| {
...@@ -14307,7 +14289,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14307,7 +14289,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1430714289
14308 try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len });14290 try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len });
1430914291
14310 var adapter = FunctionAdapter.init(constant_adapter, metadata_adapter, &func);14292 var adapter: FunctionAdapter = .{
14293 .constant_adapter = constant_adapter,
14294 .metadata_adapter = metadata_adapter,
14295 .func = &func,
14296 .instruction_index = @enumFromInt(0),
14297 };
1431114298
14312 // Emit function level metadata block14299 // Emit function level metadata block
14313 if (!func.strip and func.debug_values.len > 0) {14300 if (!func.strip and func.debug_values.len > 0) {
...@@ -14330,21 +14317,23 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14330,21 +14317,23 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14330 var has_location = false;14317 var has_location = false;
1433114318
14332 var block_incoming_len: u32 = undefined;14319 var block_incoming_len: u32 = undefined;
14333 for (0..func.instructions.len) |instr_index| {14320 for (tags, datas, 0..) |tag, data, instr_index| {
14334 const tag = tags[instr_index];14321 adapter.instruction_index = @enumFromInt(instr_index);
14335
14336 record.clearRetainingCapacity();14322 record.clearRetainingCapacity();
1433714323
14338 switch (tag) {14324 switch (tag) {
14339 .block => block_incoming_len = datas[instr_index],14325 .arg => continue,
14340 .arg => {},14326 .block => {
14327 block_incoming_len = data;
14328 continue;
14329 },
14341 .@"unreachable" => try function_block.writeAbbrev(FunctionBlock.Unreachable{}),14330 .@"unreachable" => try function_block.writeAbbrev(FunctionBlock.Unreachable{}),
14342 .call,14331 .call,
14343 .@"musttail call",14332 .@"musttail call",
14344 .@"notail call",14333 .@"notail call",
14345 .@"tail call",14334 .@"tail call",
14346 => |kind| {14335 => |kind| {
14347 var extra = func.extraDataTrail(Function.Instruction.Call, datas[instr_index]);14336 var extra = func.extraDataTrail(Function.Instruction.Call, data);
1434814337
14349 const call_conv = extra.data.info.call_conv;14338 const call_conv = extra.data.info.call_conv;
14350 const args = extra.trail.next(extra.data.args_len, Value, &func);14339 const args = extra.trail.next(extra.data.args_len, Value, &func);
...@@ -14367,7 +14356,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14367,7 +14356,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14367 .@"notail call fast",14356 .@"notail call fast",
14368 .@"tail call fast",14357 .@"tail call fast",
14369 => |kind| {14358 => |kind| {
14370 var extra = func.extraDataTrail(Function.Instruction.Call, datas[instr_index]);14359 var extra = func.extraDataTrail(Function.Instruction.Call, data);
1437114360
14372 const call_conv = extra.data.info.call_conv;14361 const call_conv = extra.data.info.call_conv;
14373 const args = extra.trail.next(extra.data.args_len, Value, &func);14362 const args = extra.trail.next(extra.data.args_len, Value, &func);
...@@ -14405,7 +14394,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14405,7 +14394,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14405 .srem,14394 .srem,
14406 .ashr,14395 .ashr,
14407 => |kind| {14396 => |kind| {
14408 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14397 const extra = func.extraData(Function.Instruction.Binary, data);
14409 try function_block.writeAbbrev(FunctionBlock.Binary{14398 try function_block.writeAbbrev(FunctionBlock.Binary{
14410 .opcode = kind.toBinaryOpcode(),14399 .opcode = kind.toBinaryOpcode(),
14411 .lhs = adapter.getOffsetValueIndex(extra.lhs),14400 .lhs = adapter.getOffsetValueIndex(extra.lhs),
...@@ -14417,7 +14406,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14417,7 +14406,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14417 .@"lshr exact",14406 .@"lshr exact",
14418 .@"ashr exact",14407 .@"ashr exact",
14419 => |kind| {14408 => |kind| {
14420 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14409 const extra = func.extraData(Function.Instruction.Binary, data);
14421 try function_block.writeAbbrev(FunctionBlock.BinaryExact{14410 try function_block.writeAbbrev(FunctionBlock.BinaryExact{
14422 .opcode = kind.toBinaryOpcode(),14411 .opcode = kind.toBinaryOpcode(),
14423 .lhs = adapter.getOffsetValueIndex(extra.lhs),14412 .lhs = adapter.getOffsetValueIndex(extra.lhs),
...@@ -14437,7 +14426,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14437,7 +14426,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14437 .@"shl nuw",14426 .@"shl nuw",
14438 .@"shl nuw nsw",14427 .@"shl nuw nsw",
14439 => |kind| {14428 => |kind| {
14440 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14429 const extra = func.extraData(Function.Instruction.Binary, data);
14441 try function_block.writeAbbrev(FunctionBlock.BinaryNoWrap{14430 try function_block.writeAbbrev(FunctionBlock.BinaryNoWrap{
14442 .opcode = kind.toBinaryOpcode(),14431 .opcode = kind.toBinaryOpcode(),
14443 .lhs = adapter.getOffsetValueIndex(extra.lhs),14432 .lhs = adapter.getOffsetValueIndex(extra.lhs),
...@@ -14468,7 +14457,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14468,7 +14457,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14468 .@"frem fast",14457 .@"frem fast",
14469 .@"fsub fast",14458 .@"fsub fast",
14470 => |kind| {14459 => |kind| {
14471 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14460 const extra = func.extraData(Function.Instruction.Binary, data);
14472 try function_block.writeAbbrev(FunctionBlock.BinaryFast{14461 try function_block.writeAbbrev(FunctionBlock.BinaryFast{
14473 .opcode = kind.toBinaryOpcode(),14462 .opcode = kind.toBinaryOpcode(),
14474 .lhs = adapter.getOffsetValueIndex(extra.lhs),14463 .lhs = adapter.getOffsetValueIndex(extra.lhs),
...@@ -14479,7 +14468,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14479,7 +14468,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14479 .alloca,14468 .alloca,
14480 .@"alloca inalloca",14469 .@"alloca inalloca",
14481 => |kind| {14470 => |kind| {
14482 const extra = func.extraData(Function.Instruction.Alloca, datas[instr_index]);14471 const extra = func.extraData(Function.Instruction.Alloca, data);
14483 const alignment = extra.info.alignment.toLlvm();14472 const alignment = extra.info.alignment.toLlvm();
14484 try function_block.writeAbbrev(FunctionBlock.Alloca{14473 try function_block.writeAbbrev(FunctionBlock.Alloca{
14485 .inst_type = extra.type,14474 .inst_type = extra.type,
...@@ -14508,7 +14497,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14508,7 +14497,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14508 .sext,14497 .sext,
14509 .zext,14498 .zext,
14510 => |kind| {14499 => |kind| {
14511 const extra = func.extraData(Function.Instruction.Cast, datas[instr_index]);14500 const extra = func.extraData(Function.Instruction.Cast, data);
14512 try function_block.writeAbbrev(FunctionBlock.Cast{14501 try function_block.writeAbbrev(FunctionBlock.Cast{
14513 .val = adapter.getOffsetValueIndex(extra.val),14502 .val = adapter.getOffsetValueIndex(extra.val),
14514 .type_index = extra.type,14503 .type_index = extra.type,
...@@ -14542,7 +14531,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14542,7 +14531,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14542 .@"icmp ule",14531 .@"icmp ule",
14543 .@"icmp ult",14532 .@"icmp ult",
14544 => |kind| {14533 => |kind| {
14545 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14534 const extra = func.extraData(Function.Instruction.Binary, data);
14546 try function_block.writeAbbrev(FunctionBlock.Cmp{14535 try function_block.writeAbbrev(FunctionBlock.Cmp{
14547 .lhs = adapter.getOffsetValueIndex(extra.lhs),14536 .lhs = adapter.getOffsetValueIndex(extra.lhs),
14548 .rhs = adapter.getOffsetValueIndex(extra.rhs),14537 .rhs = adapter.getOffsetValueIndex(extra.rhs),
...@@ -14566,7 +14555,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14566,7 +14555,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14566 .@"fcmp fast une",14555 .@"fcmp fast une",
14567 .@"fcmp fast uno",14556 .@"fcmp fast uno",
14568 => |kind| {14557 => |kind| {
14569 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14558 const extra = func.extraData(Function.Instruction.Binary, data);
14570 try function_block.writeAbbrev(FunctionBlock.CmpFast{14559 try function_block.writeAbbrev(FunctionBlock.CmpFast{
14571 .lhs = adapter.getOffsetValueIndex(extra.lhs),14560 .lhs = adapter.getOffsetValueIndex(extra.lhs),
14572 .rhs = adapter.getOffsetValueIndex(extra.rhs),14561 .rhs = adapter.getOffsetValueIndex(extra.rhs),
...@@ -14575,14 +14564,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14575,14 +14564,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14575 });14564 });
14576 },14565 },
14577 .fneg => try function_block.writeAbbrev(FunctionBlock.FNeg{14566 .fneg => try function_block.writeAbbrev(FunctionBlock.FNeg{
14578 .val = adapter.getOffsetValueIndex(@enumFromInt(datas[instr_index])),14567 .val = adapter.getOffsetValueIndex(@enumFromInt(data)),
14579 }),14568 }),
14580 .@"fneg fast" => try function_block.writeAbbrev(FunctionBlock.FNegFast{14569 .@"fneg fast" => try function_block.writeAbbrev(FunctionBlock.FNegFast{
14581 .val = adapter.getOffsetValueIndex(@enumFromInt(datas[instr_index])),14570 .val = adapter.getOffsetValueIndex(@enumFromInt(data)),
14582 .fast_math = FastMath.fast,14571 .fast_math = FastMath.fast,
14583 }),14572 }),
14584 .extractvalue => {14573 .extractvalue => {
14585 var extra = func.extraDataTrail(Function.Instruction.ExtractValue, datas[instr_index]);14574 var extra = func.extraDataTrail(Function.Instruction.ExtractValue, data);
14586 const indices = extra.trail.next(extra.data.indices_len, u32, &func);14575 const indices = extra.trail.next(extra.data.indices_len, u32, &func);
14587 try function_block.writeAbbrev(FunctionBlock.ExtractValue{14576 try function_block.writeAbbrev(FunctionBlock.ExtractValue{
14588 .val = adapter.getOffsetValueIndex(extra.data.val),14577 .val = adapter.getOffsetValueIndex(extra.data.val),
...@@ -14590,7 +14579,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14590,7 +14579,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14590 });14579 });
14591 },14580 },
14592 .insertvalue => {14581 .insertvalue => {
14593 var extra = func.extraDataTrail(Function.Instruction.InsertValue, datas[instr_index]);14582 var extra = func.extraDataTrail(Function.Instruction.InsertValue, data);
14594 const indices = extra.trail.next(extra.data.indices_len, u32, &func);14583 const indices = extra.trail.next(extra.data.indices_len, u32, &func);
14595 try function_block.writeAbbrev(FunctionBlock.InsertValue{14584 try function_block.writeAbbrev(FunctionBlock.InsertValue{
14596 .val = adapter.getOffsetValueIndex(extra.data.val),14585 .val = adapter.getOffsetValueIndex(extra.data.val),
...@@ -14599,14 +14588,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14599,14 +14588,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14599 });14588 });
14600 },14589 },
14601 .extractelement => {14590 .extractelement => {
14602 const extra = func.extraData(Function.Instruction.ExtractElement, datas[instr_index]);14591 const extra = func.extraData(Function.Instruction.ExtractElement, data);
14603 try function_block.writeAbbrev(FunctionBlock.ExtractElement{14592 try function_block.writeAbbrev(FunctionBlock.ExtractElement{
14604 .val = adapter.getOffsetValueIndex(extra.val),14593 .val = adapter.getOffsetValueIndex(extra.val),
14605 .index = adapter.getOffsetValueIndex(extra.index),14594 .index = adapter.getOffsetValueIndex(extra.index),
14606 });14595 });
14607 },14596 },
14608 .insertelement => {14597 .insertelement => {
14609 const extra = func.extraData(Function.Instruction.InsertElement, datas[instr_index]);14598 const extra = func.extraData(Function.Instruction.InsertElement, data);
14610 try function_block.writeAbbrev(FunctionBlock.InsertElement{14599 try function_block.writeAbbrev(FunctionBlock.InsertElement{
14611 .val = adapter.getOffsetValueIndex(extra.val),14600 .val = adapter.getOffsetValueIndex(extra.val),
14612 .elem = adapter.getOffsetValueIndex(extra.elem),14601 .elem = adapter.getOffsetValueIndex(extra.elem),
...@@ -14614,7 +14603,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14614,7 +14603,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14614 });14603 });
14615 },14604 },
14616 .select => {14605 .select => {
14617 const extra = func.extraData(Function.Instruction.Select, datas[instr_index]);14606 const extra = func.extraData(Function.Instruction.Select, data);
14618 try function_block.writeAbbrev(FunctionBlock.Select{14607 try function_block.writeAbbrev(FunctionBlock.Select{
14619 .lhs = adapter.getOffsetValueIndex(extra.lhs),14608 .lhs = adapter.getOffsetValueIndex(extra.lhs),
14620 .rhs = adapter.getOffsetValueIndex(extra.rhs),14609 .rhs = adapter.getOffsetValueIndex(extra.rhs),
...@@ -14622,7 +14611,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14622,7 +14611,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14622 });14611 });
14623 },14612 },
14624 .@"select fast" => {14613 .@"select fast" => {
14625 const extra = func.extraData(Function.Instruction.Select, datas[instr_index]);14614 const extra = func.extraData(Function.Instruction.Select, data);
14626 try function_block.writeAbbrev(FunctionBlock.SelectFast{14615 try function_block.writeAbbrev(FunctionBlock.SelectFast{
14627 .lhs = adapter.getOffsetValueIndex(extra.lhs),14616 .lhs = adapter.getOffsetValueIndex(extra.lhs),
14628 .rhs = adapter.getOffsetValueIndex(extra.rhs),14617 .rhs = adapter.getOffsetValueIndex(extra.rhs),
...@@ -14631,7 +14620,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14631,7 +14620,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14631 });14620 });
14632 },14621 },
14633 .shufflevector => {14622 .shufflevector => {
14634 const extra = func.extraData(Function.Instruction.ShuffleVector, datas[instr_index]);14623 const extra = func.extraData(Function.Instruction.ShuffleVector, data);
14635 try function_block.writeAbbrev(FunctionBlock.ShuffleVector{14624 try function_block.writeAbbrev(FunctionBlock.ShuffleVector{
14636 .lhs = adapter.getOffsetValueIndex(extra.lhs),14625 .lhs = adapter.getOffsetValueIndex(extra.lhs),
14637 .rhs = adapter.getOffsetValueIndex(extra.rhs),14626 .rhs = adapter.getOffsetValueIndex(extra.rhs),
...@@ -14641,7 +14630,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14641,7 +14630,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14641 .getelementptr,14630 .getelementptr,
14642 .@"getelementptr inbounds",14631 .@"getelementptr inbounds",
14643 => |kind| {14632 => |kind| {
14644 var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, datas[instr_index]);14633 var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, data);
14645 const indices = extra.trail.next(extra.data.indices_len, Value, &func);14634 const indices = extra.trail.next(extra.data.indices_len, Value, &func);
14646 try function_block.writeAbbrevAdapted(14635 try function_block.writeAbbrevAdapted(
14647 FunctionBlock.GetElementPtr{14636 FunctionBlock.GetElementPtr{
...@@ -14654,7 +14643,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14654,7 +14643,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14654 );14643 );
14655 },14644 },
14656 .load => {14645 .load => {
14657 const extra = func.extraData(Function.Instruction.Load, datas[instr_index]);14646 const extra = func.extraData(Function.Instruction.Load, data);
14658 try function_block.writeAbbrev(FunctionBlock.Load{14647 try function_block.writeAbbrev(FunctionBlock.Load{
14659 .ptr = adapter.getOffsetValueIndex(extra.ptr),14648 .ptr = adapter.getOffsetValueIndex(extra.ptr),
14660 .ty = extra.type,14649 .ty = extra.type,
...@@ -14663,7 +14652,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14663,7 +14652,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14663 });14652 });
14664 },14653 },
14665 .@"load atomic" => {14654 .@"load atomic" => {
14666 const extra = func.extraData(Function.Instruction.Load, datas[instr_index]);14655 const extra = func.extraData(Function.Instruction.Load, data);
14667 try function_block.writeAbbrev(FunctionBlock.LoadAtomic{14656 try function_block.writeAbbrev(FunctionBlock.LoadAtomic{
14668 .ptr = adapter.getOffsetValueIndex(extra.ptr),14657 .ptr = adapter.getOffsetValueIndex(extra.ptr),
14669 .ty = extra.type,14658 .ty = extra.type,
...@@ -14674,7 +14663,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14674,7 +14663,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14674 });14663 });
14675 },14664 },
14676 .store => {14665 .store => {
14677 const extra = func.extraData(Function.Instruction.Store, datas[instr_index]);14666 const extra = func.extraData(Function.Instruction.Store, data);
14678 try function_block.writeAbbrev(FunctionBlock.Store{14667 try function_block.writeAbbrev(FunctionBlock.Store{
14679 .ptr = adapter.getOffsetValueIndex(extra.ptr),14668 .ptr = adapter.getOffsetValueIndex(extra.ptr),
14680 .val = adapter.getOffsetValueIndex(extra.val),14669 .val = adapter.getOffsetValueIndex(extra.val),
...@@ -14683,7 +14672,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14683,7 +14672,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14683 });14672 });
14684 },14673 },
14685 .@"store atomic" => {14674 .@"store atomic" => {
14686 const extra = func.extraData(Function.Instruction.Store, datas[instr_index]);14675 const extra = func.extraData(Function.Instruction.Store, data);
14687 try function_block.writeAbbrev(FunctionBlock.StoreAtomic{14676 try function_block.writeAbbrev(FunctionBlock.StoreAtomic{
14688 .ptr = adapter.getOffsetValueIndex(extra.ptr),14677 .ptr = adapter.getOffsetValueIndex(extra.ptr),
14689 .val = adapter.getOffsetValueIndex(extra.val),14678 .val = adapter.getOffsetValueIndex(extra.val),
...@@ -14695,11 +14684,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14695,11 +14684,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14695 },14684 },
14696 .br => {14685 .br => {
14697 try function_block.writeAbbrev(FunctionBlock.BrUnconditional{14686 try function_block.writeAbbrev(FunctionBlock.BrUnconditional{
14698 .block = datas[instr_index],14687 .block = data,
14699 });14688 });
14700 },14689 },
14701 .br_cond => {14690 .br_cond => {
14702 const extra = func.extraData(Function.Instruction.BrCond, datas[instr_index]);14691 const extra = func.extraData(Function.Instruction.BrCond, data);
14703 try function_block.writeAbbrev(FunctionBlock.BrConditional{14692 try function_block.writeAbbrev(FunctionBlock.BrConditional{
14704 .then_block = @intFromEnum(extra.then),14693 .then_block = @intFromEnum(extra.then),
14705 .else_block = @intFromEnum(extra.@"else"),14694 .else_block = @intFromEnum(extra.@"else"),
...@@ -14707,7 +14696,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14707,7 +14696,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14707 });14696 });
14708 },14697 },
14709 .@"switch" => {14698 .@"switch" => {
14710 var extra = func.extraDataTrail(Function.Instruction.Switch, datas[instr_index]);14699 var extra = func.extraDataTrail(Function.Instruction.Switch, data);
1471114700
14712 try record.ensureUnusedCapacity(self.gpa, 3 + extra.data.cases_len * 2);14701 try record.ensureUnusedCapacity(self.gpa, 3 + extra.data.cases_len * 2);
1471314702
...@@ -14730,7 +14719,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14730,7 +14719,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14730 try function_block.writeUnabbrev(12, record.items);14719 try function_block.writeUnabbrev(12, record.items);
14731 },14720 },
14732 .va_arg => {14721 .va_arg => {
14733 const extra = func.extraData(Function.Instruction.VaArg, datas[instr_index]);14722 const extra = func.extraData(Function.Instruction.VaArg, data);
14734 try function_block.writeAbbrev(FunctionBlock.VaArg{14723 try function_block.writeAbbrev(FunctionBlock.VaArg{
14735 .list_type = extra.list.typeOf(@enumFromInt(func_index), self),14724 .list_type = extra.list.typeOf(@enumFromInt(func_index), self),
14736 .list = adapter.getOffsetValueIndex(extra.list),14725 .list = adapter.getOffsetValueIndex(extra.list),
...@@ -14740,7 +14729,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14740,7 +14729,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14740 .phi,14729 .phi,
14741 .@"phi fast",14730 .@"phi fast",
14742 => |kind| {14731 => |kind| {
14743 var extra = func.extraDataTrail(Function.Instruction.Phi, datas[instr_index]);14732 var extra = func.extraDataTrail(Function.Instruction.Phi, data);
14744 const vals = extra.trail.next(block_incoming_len, Value, &func);14733 const vals = extra.trail.next(block_incoming_len, Value, &func);
14745 const blocks = extra.trail.next(block_incoming_len, Function.Block.Index, &func);14734 const blocks = extra.trail.next(block_incoming_len, Function.Block.Index, &func);
1474614735
...@@ -14764,11 +14753,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14764,11 +14753,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14764 try function_block.writeUnabbrev(16, record.items);14753 try function_block.writeUnabbrev(16, record.items);
14765 },14754 },
14766 .ret => try function_block.writeAbbrev(FunctionBlock.Ret{14755 .ret => try function_block.writeAbbrev(FunctionBlock.Ret{
14767 .val = adapter.getOffsetValueIndex(@enumFromInt(datas[instr_index])),14756 .val = adapter.getOffsetValueIndex(@enumFromInt(data)),
14768 }),14757 }),
14769 .@"ret void" => try function_block.writeAbbrev(FunctionBlock.RetVoid{}),14758 .@"ret void" => try function_block.writeAbbrev(FunctionBlock.RetVoid{}),
14770 .atomicrmw => {14759 .atomicrmw => {
14771 const extra = func.extraData(Function.Instruction.AtomicRmw, datas[instr_index]);14760 const extra = func.extraData(Function.Instruction.AtomicRmw, data);
14772 try function_block.writeAbbrev(FunctionBlock.AtomicRmw{14761 try function_block.writeAbbrev(FunctionBlock.AtomicRmw{
14773 .ptr = adapter.getOffsetValueIndex(extra.ptr),14762 .ptr = adapter.getOffsetValueIndex(extra.ptr),
14774 .val = adapter.getOffsetValueIndex(extra.val),14763 .val = adapter.getOffsetValueIndex(extra.val),
...@@ -14782,7 +14771,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14782,7 +14771,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14782 .cmpxchg,14771 .cmpxchg,
14783 .@"cmpxchg weak",14772 .@"cmpxchg weak",
14784 => |kind| {14773 => |kind| {
14785 const extra = func.extraData(Function.Instruction.CmpXchg, datas[instr_index]);14774 const extra = func.extraData(Function.Instruction.CmpXchg, data);
1478614775
14787 try function_block.writeAbbrev(FunctionBlock.CmpXchg{14776 try function_block.writeAbbrev(FunctionBlock.CmpXchg{
14788 .ptr = adapter.getOffsetValueIndex(extra.ptr),14777 .ptr = adapter.getOffsetValueIndex(extra.ptr),
...@@ -14797,7 +14786,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14797,7 +14786,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14797 });14786 });
14798 },14787 },
14799 .fence => {14788 .fence => {
14800 const info: MemoryAccessInfo = @bitCast(datas[instr_index]);14789 const info: MemoryAccessInfo = @bitCast(data);
14801 try function_block.writeAbbrev(FunctionBlock.Fence{14790 try function_block.writeAbbrev(FunctionBlock.Fence{
14802 .ordering = info.success_ordering,14791 .ordering = info.success_ordering,
14803 .sync_scope = info.sync_scope,14792 .sync_scope = info.sync_scope,
...@@ -14806,7 +14795,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14806,7 +14795,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14806 }14795 }
1480714796
14808 if (!func.strip) {14797 if (!func.strip) {
14809 if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| {14798 if (func.debug_locations.get(adapter.instruction_index)) |debug_location| {
14810 switch (debug_location) {14799 switch (debug_location) {
14811 .no_location => has_location = false,14800 .no_location => has_location = false,
14812 .location => |location| {14801 .location => |location| {
...@@ -14823,8 +14812,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14823,8 +14812,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14823 try function_block.writeAbbrev(FunctionBlock.DebugLocAgain{});14812 try function_block.writeAbbrev(FunctionBlock.DebugLocAgain{});
14824 }14813 }
14825 }14814 }
14826
14827 adapter.next();
14828 }14815 }
1482914816
14830 // VALUE_SYMTAB14817 // VALUE_SYMTAB
...@@ -14850,18 +14837,32 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14850,18 +14837,32 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14850 }14837 }
1485114838
14852 // METADATA_ATTACHMENT_BLOCK14839 // METADATA_ATTACHMENT_BLOCK
14853 if (!func.strip) blk: {14840 const any_nosanitize = true;
14854 const dbg = func.global.ptrConst(self).dbg;14841 if (!func.strip or any_nosanitize) {
14855
14856 if (dbg == .none) break :blk;
14857
14858 const MetadataAttachmentBlock = ir.MetadataAttachmentBlock;14842 const MetadataAttachmentBlock = ir.MetadataAttachmentBlock;
14859 var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false);14843 var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false);
1486014844
14861 try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentSingle{14845 if (!func.strip) blk: {
14862 .kind = ir.MetadataKind.dbg,14846 const dbg = func.global.ptrConst(self).dbg;
14863 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),14847 if (dbg == .none) break :blk;
14864 });14848 try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentGlobalSingle{
14849 .kind = .dbg,
14850 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
14851 });
14852 }
14853
14854 var instr_index: u32 = 0;
14855 for (func.instructions.items(.tag)) |instr_tag| switch (instr_tag) {
14856 .arg, .block => {},
14857 else => {
14858 try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{
14859 .inst = instr_index,
14860 .kind = .nosanitize,
14861 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(.empty_tuple) - 1),
14862 });
14863 instr_index += 1;
14864 },
14865 };
1486514866
14866 try metadata_attach_block.end();14867 try metadata_attach_block.end();
14867 }14868 }
src/codegen/llvm/ir.zig+176-29
...@@ -20,8 +20,142 @@ const ColumnAbbrev = AbbrevOp{ .vbr = 8 };...@@ -20,8 +20,142 @@ const ColumnAbbrev = AbbrevOp{ .vbr = 8 };
2020
21const BlockAbbrev = AbbrevOp{ .vbr = 6 };21const BlockAbbrev = AbbrevOp{ .vbr = 6 };
2222
23pub const MetadataKind = enum(u1) {23/// Unused tags are commented out so that they are omitted in the generated
24/// bitcode, which scans over this enum using reflection.
25pub const FixedMetadataKind = enum(u8) {
24 dbg = 0,26 dbg = 0,
27 //tbaa = 1,
28 //prof = 2,
29 //fpmath = 3,
30 //range = 4,
31 //@"tbaa.struct" = 5,
32 //@"invariant.load" = 6,
33 //@"alias.scope" = 7,
34 //@"noalias" = 8,
35 //nontemporal = 9,
36 //@"llvm.mem.parallel_loop_access" = 10,
37 //nonnull = 11,
38 //dereferenceable = 12,
39 //dereferenceable_or_null = 13,
40 //@"make.implicit" = 14,
41 //unpredictable = 15,
42 //@"invariant.group" = 16,
43 //@"align" = 17,
44 //@"llvm.loop" = 18,
45 //type = 19,
46 //section_prefix = 20,
47 //absolute_symbol = 21,
48 //associated = 22,
49 //callees = 23,
50 //irr_loop = 24,
51 //@"llvm.access.group" = 25,
52 //callback = 26,
53 //@"llvm.preserve.access.index" = 27,
54 //vcall_visibility = 28,
55 //noundef = 29,
56 //annotation = 30,
57 nosanitize = 31,
58 //func_sanitize = 32,
59 //exclude = 33,
60 //memprof = 34,
61 //callsite = 35,
62 //kcfi_type = 36,
63 //pcsections = 37,
64 //DIAssignID = 38,
65 //@"coro.outside.frame" = 39,
66};
67
68pub const MetadataCode = enum(u8) {
69 /// MDSTRING: [values]
70 STRING_OLD = 1,
71 /// VALUE: [type num, value num]
72 VALUE = 2,
73 /// NODE: [n x md num]
74 NODE = 3,
75 /// STRING: [values]
76 NAME = 4,
77 /// DISTINCT_NODE: [n x md num]
78 DISTINCT_NODE = 5,
79 /// [n x [id, name]]
80 KIND = 6,
81 /// [distinct, line, col, scope, inlined-at?]
82 LOCATION = 7,
83 /// OLD_NODE: [n x (type num, value num)]
84 OLD_NODE = 8,
85 /// OLD_FN_NODE: [n x (type num, value num)]
86 OLD_FN_NODE = 9,
87 /// NAMED_NODE: [n x mdnodes]
88 NAMED_NODE = 10,
89 /// [m x [value, [n x [id, mdnode]]]
90 ATTACHMENT = 11,
91 /// [distinct, tag, vers, header, n x md num]
92 GENERIC_DEBUG = 12,
93 /// [distinct, count, lo]
94 SUBRANGE = 13,
95 /// [isUnsigned|distinct, value, name]
96 ENUMERATOR = 14,
97 /// [distinct, tag, name, size, align, enc]
98 BASIC_TYPE = 15,
99 /// [distinct, filename, directory, checksumkind, checksum]
100 FILE = 16,
101 /// [distinct, ...]
102 DERIVED_TYPE = 17,
103 /// [distinct, ...]
104 COMPOSITE_TYPE = 18,
105 /// [distinct, flags, types, cc]
106 SUBROUTINE_TYPE = 19,
107 /// [distinct, ...]
108 COMPILE_UNIT = 20,
109 /// [distinct, ...]
110 SUBPROGRAM = 21,
111 /// [distinct, scope, file, line, column]
112 LEXICAL_BLOCK = 22,
113 ///[distinct, scope, file, discriminator]
114 LEXICAL_BLOCK_FILE = 23,
115 /// [distinct, scope, file, name, line, exportSymbols]
116 NAMESPACE = 24,
117 /// [distinct, scope, name, type, ...]
118 TEMPLATE_TYPE = 25,
119 /// [distinct, scope, name, type, value, ...]
120 TEMPLATE_VALUE = 26,
121 /// [distinct, ...]
122 GLOBAL_VAR = 27,
123 /// [distinct, ...]
124 LOCAL_VAR = 28,
125 /// [distinct, n x element]
126 EXPRESSION = 29,
127 /// [distinct, name, file, line, ...]
128 OBJC_PROPERTY = 30,
129 /// [distinct, tag, scope, entity, line, name]
130 IMPORTED_ENTITY = 31,
131 /// [distinct, scope, name, ...]
132 MODULE = 32,
133 /// [distinct, macinfo, line, name, value]
134 MACRO = 33,
135 /// [distinct, macinfo, line, file, ...]
136 MACRO_FILE = 34,
137 /// [count, offset] blob([lengths][chars])
138 STRINGS = 35,
139 /// [valueid, n x [id, mdnode]]
140 GLOBAL_DECL_ATTACHMENT = 36,
141 /// [distinct, var, expr]
142 GLOBAL_VAR_EXPR = 37,
143 /// [offset]
144 INDEX_OFFSET = 38,
145 /// [bitpos]
146 INDEX = 39,
147 /// [distinct, scope, name, file, line]
148 LABEL = 40,
149 /// [distinct, name, size, align,...]
150 STRING_TYPE = 41,
151 /// [distinct, scope, name, variable,...]
152 COMMON_BLOCK = 44,
153 /// [distinct, count, lo, up, stride]
154 GENERIC_SUBRANGE = 45,
155 /// [n x [type num, value num]]
156 ARG_LIST = 46,
157 /// [distinct, ...]
158 ASSIGN_ID = 47,
25};159};
26160
27pub const Identification = struct {161pub const Identification = struct {
...@@ -622,16 +756,29 @@ pub const MetadataAttachmentBlock = struct {...@@ -622,16 +756,29 @@ pub const MetadataAttachmentBlock = struct {
622 pub const id = 16;756 pub const id = 16;
623757
624 pub const abbrevs = [_]type{758 pub const abbrevs = [_]type{
625 AttachmentSingle,759 AttachmentGlobalSingle,
760 AttachmentInstructionSingle,
626 };761 };
627762
628 pub const AttachmentSingle = struct {763 pub const AttachmentGlobalSingle = struct {
629 pub const ops = [_]AbbrevOp{764 pub const ops = [_]AbbrevOp{
630 .{ .literal = 11 },765 .{ .literal = @intFromEnum(MetadataCode.ATTACHMENT) },
631 .{ .fixed = 1 },766 .{ .fixed = 1 },
632 MetadataAbbrev,767 MetadataAbbrev,
633 };768 };
634 kind: MetadataKind,769 kind: FixedMetadataKind,
770 metadata: Builder.Metadata,
771 };
772
773 pub const AttachmentInstructionSingle = struct {
774 pub const ops = [_]AbbrevOp{
775 .{ .literal = @intFromEnum(MetadataCode.ATTACHMENT) },
776 ValueAbbrev,
777 .{ .fixed = 5 },
778 MetadataAbbrev,
779 };
780 inst: u32,
781 kind: FixedMetadataKind,
635 metadata: Builder.Metadata,782 metadata: Builder.Metadata,
636 };783 };
637};784};
...@@ -666,7 +813,7 @@ pub const MetadataBlock = struct {...@@ -666,7 +813,7 @@ pub const MetadataBlock = struct {
666813
667 pub const Strings = struct {814 pub const Strings = struct {
668 pub const ops = [_]AbbrevOp{815 pub const ops = [_]AbbrevOp{
669 .{ .literal = 35 },816 .{ .literal = @intFromEnum(MetadataCode.STRINGS) },
670 .{ .vbr = 6 },817 .{ .vbr = 6 },
671 .{ .vbr = 6 },818 .{ .vbr = 6 },
672 .blob,819 .blob,
...@@ -678,7 +825,7 @@ pub const MetadataBlock = struct {...@@ -678,7 +825,7 @@ pub const MetadataBlock = struct {
678825
679 pub const File = struct {826 pub const File = struct {
680 pub const ops = [_]AbbrevOp{827 pub const ops = [_]AbbrevOp{
681 .{ .literal = 16 },828 .{ .literal = @intFromEnum(MetadataCode.FILE) },
682 .{ .literal = 0 }, // is distinct829 .{ .literal = 0 }, // is distinct
683 MetadataAbbrev, // filename830 MetadataAbbrev, // filename
684 MetadataAbbrev, // directory831 MetadataAbbrev, // directory
...@@ -692,7 +839,7 @@ pub const MetadataBlock = struct {...@@ -692,7 +839,7 @@ pub const MetadataBlock = struct {
692839
693 pub const CompileUnit = struct {840 pub const CompileUnit = struct {
694 pub const ops = [_]AbbrevOp{841 pub const ops = [_]AbbrevOp{
695 .{ .literal = 20 },842 .{ .literal = @intFromEnum(MetadataCode.COMPILE_UNIT) },
696 .{ .literal = 1 }, // is distinct843 .{ .literal = 1 }, // is distinct
697 .{ .literal = std.dwarf.LANG.C99 }, // source language844 .{ .literal = std.dwarf.LANG.C99 }, // source language
698 MetadataAbbrev, // file845 MetadataAbbrev, // file
...@@ -726,7 +873,7 @@ pub const MetadataBlock = struct {...@@ -726,7 +873,7 @@ pub const MetadataBlock = struct {
726873
727 pub const Subprogram = struct {874 pub const Subprogram = struct {
728 pub const ops = [_]AbbrevOp{875 pub const ops = [_]AbbrevOp{
729 .{ .literal = 21 },876 .{ .literal = @intFromEnum(MetadataCode.SUBPROGRAM) },
730 .{ .literal = 0b111 }, // is distinct | has sp flags | has flags877 .{ .literal = 0b111 }, // is distinct | has sp flags | has flags
731 MetadataAbbrev, // scope878 MetadataAbbrev, // scope
732 MetadataAbbrev, // name879 MetadataAbbrev, // name
...@@ -763,7 +910,7 @@ pub const MetadataBlock = struct {...@@ -763,7 +910,7 @@ pub const MetadataBlock = struct {
763910
764 pub const LexicalBlock = struct {911 pub const LexicalBlock = struct {
765 pub const ops = [_]AbbrevOp{912 pub const ops = [_]AbbrevOp{
766 .{ .literal = 22 },913 .{ .literal = @intFromEnum(MetadataCode.LEXICAL_BLOCK) },
767 .{ .literal = 0 }, // is distinct914 .{ .literal = 0 }, // is distinct
768 MetadataAbbrev, // scope915 MetadataAbbrev, // scope
769 MetadataAbbrev, // file916 MetadataAbbrev, // file
...@@ -779,7 +926,7 @@ pub const MetadataBlock = struct {...@@ -779,7 +926,7 @@ pub const MetadataBlock = struct {
779926
780 pub const Location = struct {927 pub const Location = struct {
781 pub const ops = [_]AbbrevOp{928 pub const ops = [_]AbbrevOp{
782 .{ .literal = 7 },929 .{ .literal = @intFromEnum(MetadataCode.LOCATION) },
783 .{ .literal = 0 }, // is distinct930 .{ .literal = 0 }, // is distinct
784 LineAbbrev, // line931 LineAbbrev, // line
785 ColumnAbbrev, // column932 ColumnAbbrev, // column
...@@ -796,7 +943,7 @@ pub const MetadataBlock = struct {...@@ -796,7 +943,7 @@ pub const MetadataBlock = struct {
796943
797 pub const BasicType = struct {944 pub const BasicType = struct {
798 pub const ops = [_]AbbrevOp{945 pub const ops = [_]AbbrevOp{
799 .{ .literal = 15 },946 .{ .literal = @intFromEnum(MetadataCode.BASIC_TYPE) },
800 .{ .literal = 0 }, // is distinct947 .{ .literal = 0 }, // is distinct
801 .{ .literal = std.dwarf.TAG.base_type }, // tag948 .{ .literal = std.dwarf.TAG.base_type }, // tag
802 MetadataAbbrev, // name949 MetadataAbbrev, // name
...@@ -813,7 +960,7 @@ pub const MetadataBlock = struct {...@@ -813,7 +960,7 @@ pub const MetadataBlock = struct {
813960
814 pub const CompositeType = struct {961 pub const CompositeType = struct {
815 pub const ops = [_]AbbrevOp{962 pub const ops = [_]AbbrevOp{
816 .{ .literal = 18 },963 .{ .literal = @intFromEnum(MetadataCode.COMPOSITE_TYPE) },
817 .{ .literal = 0 | 0x2 }, // is distinct | is not used in old type ref964 .{ .literal = 0 | 0x2 }, // is distinct | is not used in old type ref
818 .{ .fixed = 32 }, // tag965 .{ .fixed = 32 }, // tag
819 MetadataAbbrev, // name966 MetadataAbbrev, // name
...@@ -852,7 +999,7 @@ pub const MetadataBlock = struct {...@@ -852,7 +999,7 @@ pub const MetadataBlock = struct {
852999
853 pub const DerivedType = struct {1000 pub const DerivedType = struct {
854 pub const ops = [_]AbbrevOp{1001 pub const ops = [_]AbbrevOp{
855 .{ .literal = 17 },1002 .{ .literal = @intFromEnum(MetadataCode.DERIVED_TYPE) },
856 .{ .literal = 0 }, // is distinct1003 .{ .literal = 0 }, // is distinct
857 .{ .fixed = 32 }, // tag1004 .{ .fixed = 32 }, // tag
858 MetadataAbbrev, // name1005 MetadataAbbrev, // name
...@@ -880,7 +1027,7 @@ pub const MetadataBlock = struct {...@@ -880,7 +1027,7 @@ pub const MetadataBlock = struct {
8801027
881 pub const SubroutineType = struct {1028 pub const SubroutineType = struct {
882 pub const ops = [_]AbbrevOp{1029 pub const ops = [_]AbbrevOp{
883 .{ .literal = 19 },1030 .{ .literal = @intFromEnum(MetadataCode.SUBROUTINE_TYPE) },
884 .{ .literal = 0 | 0x2 }, // is distinct | has no old type refs1031 .{ .literal = 0 | 0x2 }, // is distinct | has no old type refs
885 .{ .literal = 0 }, // flags1032 .{ .literal = 0 }, // flags
886 MetadataAbbrev, // types1033 MetadataAbbrev, // types
...@@ -891,7 +1038,7 @@ pub const MetadataBlock = struct {...@@ -891,7 +1038,7 @@ pub const MetadataBlock = struct {
891 };1038 };
8921039
893 pub const Enumerator = struct {1040 pub const Enumerator = struct {
894 pub const id = 14;1041 pub const id: MetadataCode = .ENUMERATOR;
8951042
896 pub const Flags = packed struct(u3) {1043 pub const Flags = packed struct(u3) {
897 distinct: bool = false,1044 distinct: bool = false,
...@@ -900,7 +1047,7 @@ pub const MetadataBlock = struct {...@@ -900,7 +1047,7 @@ pub const MetadataBlock = struct {
900 };1047 };
9011048
902 pub const ops = [_]AbbrevOp{1049 pub const ops = [_]AbbrevOp{
903 .{ .literal = Enumerator.id },1050 .{ .literal = @intFromEnum(Enumerator.id) },
904 .{ .fixed = @bitSizeOf(Flags) }, // flags1051 .{ .fixed = @bitSizeOf(Flags) }, // flags
905 .{ .vbr = 6 }, // bit width1052 .{ .vbr = 6 }, // bit width
906 MetadataAbbrev, // name1053 MetadataAbbrev, // name
...@@ -915,7 +1062,7 @@ pub const MetadataBlock = struct {...@@ -915,7 +1062,7 @@ pub const MetadataBlock = struct {
9151062
916 pub const Subrange = struct {1063 pub const Subrange = struct {
917 pub const ops = [_]AbbrevOp{1064 pub const ops = [_]AbbrevOp{
918 .{ .literal = 13 },1065 .{ .literal = @intFromEnum(MetadataCode.SUBRANGE) },
919 .{ .literal = 0b10 }, // is distinct | version1066 .{ .literal = 0b10 }, // is distinct | version
920 MetadataAbbrev, // count1067 MetadataAbbrev, // count
921 MetadataAbbrev, // lower bound1068 MetadataAbbrev, // lower bound
...@@ -929,7 +1076,7 @@ pub const MetadataBlock = struct {...@@ -929,7 +1076,7 @@ pub const MetadataBlock = struct {
9291076
930 pub const Expression = struct {1077 pub const Expression = struct {
931 pub const ops = [_]AbbrevOp{1078 pub const ops = [_]AbbrevOp{
932 .{ .literal = 29 },1079 .{ .literal = @intFromEnum(MetadataCode.EXPRESSION) },
933 .{ .literal = 0 | (3 << 1) }, // is distinct | version1080 .{ .literal = 0 | (3 << 1) }, // is distinct | version
934 MetadataArrayAbbrev, // elements1081 MetadataArrayAbbrev, // elements
935 };1082 };
...@@ -939,7 +1086,7 @@ pub const MetadataBlock = struct {...@@ -939,7 +1086,7 @@ pub const MetadataBlock = struct {
9391086
940 pub const Node = struct {1087 pub const Node = struct {
941 pub const ops = [_]AbbrevOp{1088 pub const ops = [_]AbbrevOp{
942 .{ .literal = 3 },1089 .{ .literal = @intFromEnum(MetadataCode.NODE) },
943 MetadataArrayAbbrev, // elements1090 MetadataArrayAbbrev, // elements
944 };1091 };
9451092
...@@ -948,7 +1095,7 @@ pub const MetadataBlock = struct {...@@ -948,7 +1095,7 @@ pub const MetadataBlock = struct {
9481095
949 pub const LocalVar = struct {1096 pub const LocalVar = struct {
950 pub const ops = [_]AbbrevOp{1097 pub const ops = [_]AbbrevOp{
951 .{ .literal = 28 },1098 .{ .literal = @intFromEnum(MetadataCode.LOCAL_VAR) },
952 .{ .literal = 0b10 }, // is distinct | has alignment1099 .{ .literal = 0b10 }, // is distinct | has alignment
953 MetadataAbbrev, // scope1100 MetadataAbbrev, // scope
954 MetadataAbbrev, // name1101 MetadataAbbrev, // name
...@@ -970,7 +1117,7 @@ pub const MetadataBlock = struct {...@@ -970,7 +1117,7 @@ pub const MetadataBlock = struct {
9701117
971 pub const Parameter = struct {1118 pub const Parameter = struct {
972 pub const ops = [_]AbbrevOp{1119 pub const ops = [_]AbbrevOp{
973 .{ .literal = 28 },1120 .{ .literal = @intFromEnum(MetadataCode.LOCAL_VAR) },
974 .{ .literal = 0b10 }, // is distinct | has alignment1121 .{ .literal = 0b10 }, // is distinct | has alignment
975 MetadataAbbrev, // scope1122 MetadataAbbrev, // scope
976 MetadataAbbrev, // name1123 MetadataAbbrev, // name
...@@ -993,7 +1140,7 @@ pub const MetadataBlock = struct {...@@ -993,7 +1140,7 @@ pub const MetadataBlock = struct {
9931140
994 pub const GlobalVar = struct {1141 pub const GlobalVar = struct {
995 pub const ops = [_]AbbrevOp{1142 pub const ops = [_]AbbrevOp{
996 .{ .literal = 27 },1143 .{ .literal = @intFromEnum(MetadataCode.GLOBAL_VAR) },
997 .{ .literal = 0b101 }, // is distinct | version1144 .{ .literal = 0b101 }, // is distinct | version
998 MetadataAbbrev, // scope1145 MetadataAbbrev, // scope
999 MetadataAbbrev, // name1146 MetadataAbbrev, // name
...@@ -1020,7 +1167,7 @@ pub const MetadataBlock = struct {...@@ -1020,7 +1167,7 @@ pub const MetadataBlock = struct {
10201167
1021 pub const GlobalVarExpression = struct {1168 pub const GlobalVarExpression = struct {
1022 pub const ops = [_]AbbrevOp{1169 pub const ops = [_]AbbrevOp{
1023 .{ .literal = 37 },1170 .{ .literal = @intFromEnum(MetadataCode.GLOBAL_VAR_EXPR) },
1024 .{ .literal = 0 }, // is distinct1171 .{ .literal = 0 }, // is distinct
1025 MetadataAbbrev, // variable1172 MetadataAbbrev, // variable
1026 MetadataAbbrev, // expression1173 MetadataAbbrev, // expression
...@@ -1032,7 +1179,7 @@ pub const MetadataBlock = struct {...@@ -1032,7 +1179,7 @@ pub const MetadataBlock = struct {
10321179
1033 pub const Constant = struct {1180 pub const Constant = struct {
1034 pub const ops = [_]AbbrevOp{1181 pub const ops = [_]AbbrevOp{
1035 .{ .literal = 2 },1182 .{ .literal = @intFromEnum(MetadataCode.VALUE) },
1036 MetadataAbbrev, // type1183 MetadataAbbrev, // type
1037 MetadataAbbrev, // value1184 MetadataAbbrev, // value
1038 };1185 };
...@@ -1043,7 +1190,7 @@ pub const MetadataBlock = struct {...@@ -1043,7 +1190,7 @@ pub const MetadataBlock = struct {
10431190
1044 pub const Name = struct {1191 pub const Name = struct {
1045 pub const ops = [_]AbbrevOp{1192 pub const ops = [_]AbbrevOp{
1046 .{ .literal = 4 },1193 .{ .literal = @intFromEnum(MetadataCode.NAME) },
1047 .{ .array_fixed = 8 }, // name1194 .{ .array_fixed = 8 }, // name
1048 };1195 };
10491196
...@@ -1052,7 +1199,7 @@ pub const MetadataBlock = struct {...@@ -1052,7 +1199,7 @@ pub const MetadataBlock = struct {
10521199
1053 pub const NamedNode = struct {1200 pub const NamedNode = struct {
1054 pub const ops = [_]AbbrevOp{1201 pub const ops = [_]AbbrevOp{
1055 .{ .literal = 10 },1202 .{ .literal = @intFromEnum(MetadataCode.NAMED_NODE) },
1056 MetadataArrayAbbrev, // elements1203 MetadataArrayAbbrev, // elements
1057 };1204 };
10581205
...@@ -1061,14 +1208,14 @@ pub const MetadataBlock = struct {...@@ -1061,14 +1208,14 @@ pub const MetadataBlock = struct {
10611208
1062 pub const GlobalDeclAttachment = struct {1209 pub const GlobalDeclAttachment = struct {
1063 pub const ops = [_]AbbrevOp{1210 pub const ops = [_]AbbrevOp{
1064 .{ .literal = 36 },1211 .{ .literal = @intFromEnum(MetadataCode.GLOBAL_DECL_ATTACHMENT) },
1065 ValueAbbrev, // value id1212 ValueAbbrev, // value id
1066 .{ .fixed = 1 }, // kind1213 .{ .fixed = 1 }, // kind
1067 MetadataAbbrev, // elements1214 MetadataAbbrev, // elements
1068 };1215 };
10691216
1070 value: Builder.Constant,1217 value: Builder.Constant,
1071 kind: MetadataKind,1218 kind: FixedMetadataKind,
1072 metadata: Builder.Metadata,1219 metadata: Builder.Metadata,
1073 };1220 };
1074};1221};