authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-19 16:29:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-20 23:02:03-07:00
log26d5c27ba08db706f6f88d865102b51628c7ee62
treed50d6f5dd7034f17fa704faf5a854cd5524b7d68
parent61919fe63d1eb7134a3c85fe0a4cf279744de3e9

llvm.Builder: add !nosanitize API

see #20992 Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>

2 files changed, 319 insertions(+), 111 deletions(-)

src/codegen/llvm/Builder.zig+143-82
......@@ -3994,6 +3994,7 @@ pub const Function = struct {
39943994 names: [*]const String = &[0]String{},
39953995 value_indices: [*]const u32 = &[0]u32{},
39963996 strip: bool,
3997 any_nosanitize: bool,
39973998 debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{},
39983999 debug_values: []const Instruction.Index = &.{},
39994000 extra: []const u32 = &.{},
......@@ -4090,6 +4091,7 @@ pub const Function = struct {
40904091 block,
40914092 br,
40924093 br_cond,
4094 br_cond_nosanitize,
40934095 call,
40944096 @"call fast",
40954097 cmpxchg,
......@@ -4345,6 +4347,13 @@ pub const Function = struct {
43454347 else => unreachable,
43464348 };
43474349 }
4350
4351 pub fn isNosanitize(self: Tag) bool {
4352 return switch (self) {
4353 .br_cond_nosanitize => true,
4354 else => false,
4355 };
4356 }
43484357 };
43494358
43504359 pub const Index = enum(u32) {
......@@ -4367,6 +4376,7 @@ pub const Function = struct {
43674376 return switch (wip.instructions.items(.tag)[@intFromEnum(self)]) {
43684377 .br,
43694378 .br_cond,
4379 .br_cond_nosanitize,
43704380 .ret,
43714381 .@"ret void",
43724382 .@"switch",
......@@ -4380,6 +4390,7 @@ pub const Function = struct {
43804390 return switch (wip.instructions.items(.tag)[@intFromEnum(self)]) {
43814391 .br,
43824392 .br_cond,
4393 .br_cond_nosanitize,
43834394 .fence,
43844395 .ret,
43854396 .@"ret void",
......@@ -4470,6 +4481,7 @@ pub const Function = struct {
44704481 .block => .label,
44714482 .br,
44724483 .br_cond,
4484 .br_cond_nosanitize,
44734485 .fence,
44744486 .ret,
44754487 .@"ret void",
......@@ -4656,6 +4668,7 @@ pub const Function = struct {
46564668 .block => .label,
46574669 .br,
46584670 .br_cond,
4671 .br_cond_nosanitize,
46594672 .fence,
46604673 .ret,
46614674 .@"ret void",
......@@ -5088,6 +5101,7 @@ pub const WipFunction = struct {
50885101 instructions: std.MultiArrayList(Instruction),
50895102 names: std.ArrayListUnmanaged(String),
50905103 strip: bool,
5104 any_nosanitize: bool,
50915105 debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, DebugLocation),
50925106 debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void),
50935107 extra: std.ArrayListUnmanaged(u32),
......@@ -5134,6 +5148,7 @@ pub const WipFunction = struct {
51345148 .instructions = .{},
51355149 .names = .{},
51365150 .strip = options.strip,
5151 .any_nosanitize = false,
51375152 .debug_locations = .{},
51385153 .debug_values = .{},
51395154 .extra = .{},
......@@ -5201,11 +5216,34 @@ pub const WipFunction = struct {
52015216 cond: Value,
52025217 then: Block.Index,
52035218 @"else": Block.Index,
5219 ) Allocator.Error!Instruction.Index {
5220 return brCondTag(self, cond, then, @"else", .br_cond);
5221 }
5222
5223 pub fn brCondNosanitize(
5224 self: *WipFunction,
5225 cond: Value,
5226 then: Block.Index,
5227 @"else": Block.Index,
5228 ) Allocator.Error!Instruction.Index {
5229 self.any_nosanitize = true;
5230 return brCondTag(self, cond, then, @"else", .br_cond_nosanitize);
5231 }
5232
5233 pub fn brCondTag(
5234 self: *WipFunction,
5235 cond: Value,
5236 then: Block.Index,
5237 @"else": Block.Index,
5238 /// Asserted to be either `.br_cond` or `.br_cond_nosanitize`.
5239 tag: Instruction.Tag,
52045240 ) Allocator.Error!Instruction.Index {
52055241 assert(cond.typeOfWip(self) == .i1);
5242 assert(tag == .br_cond or tag == .br_cond_nosanitize);
5243 assert(tag != .br_cond_nosanitize or self.any_nosanitize);
52065244 try self.ensureUnusedExtraCapacity(1, Instruction.BrCond, 0);
52075245 const instruction = try self.addInst(null, .{
5208 .tag = .br_cond,
5246 .tag = tag,
52095247 .data = self.addExtraAssumeCapacity(Instruction.BrCond{
52105248 .cond = cond,
52115249 .then = then,
......@@ -6374,7 +6412,7 @@ pub const WipFunction = struct {
63746412 .@"ret void",
63756413 .@"unreachable",
63766414 => {},
6377 .br_cond => {
6415 .br_cond, .br_cond_nosanitize => {
63786416 const extra = self.extraData(Instruction.BrCond, instruction.data);
63796417 instruction.data = wip_extra.addExtra(Instruction.BrCond{
63806418 .cond = instructions.map(extra.cond),
......@@ -6559,6 +6597,7 @@ pub const WipFunction = struct {
65596597 function.names = names.ptr;
65606598 function.value_indices = value_indices.ptr;
65616599 function.strip = self.strip;
6600 function.any_nosanitize = self.any_nosanitize;
65626601 function.debug_locations = debug_locations;
65636602 function.debug_values = debug_values;
65646603 }
......@@ -7697,6 +7736,7 @@ pub const MetadataString = enum(u32) {
76977736
76987737pub const Metadata = enum(u32) {
76997738 none = 0,
7739 empty_tuple = 1,
77007740 _,
77017741
77027742 const first_forward_reference = 1 << 29;
......@@ -8355,7 +8395,7 @@ pub const Metadata = enum(u32) {
83558395};
83568396
83578397pub fn init(options: Options) Allocator.Error!Builder {
8358 var self = Builder{
8398 var self: Builder = .{
83598399 .gpa = options.allocator,
83608400 .strip = options.strip,
83618401
......@@ -8458,6 +8498,7 @@ pub fn init(options: Options) Allocator.Error!Builder {
84588498
84598499 try self.metadata_string_indices.append(self.gpa, 0);
84608500 assert(try self.metadataString("") == .none);
8501 assert(try self.debugTuple(&.{}) == .empty_tuple);
84618502
84628503 return self;
84638504}
......@@ -8855,6 +8896,7 @@ pub fn addFunctionAssumeCapacity(
88558896 .kind = .{ .function = function_index },
88568897 }),
88578898 .strip = undefined,
8899 .any_nosanitize = false,
88588900 });
88598901 return function_index;
88608902}
......@@ -9502,6 +9544,12 @@ pub fn printUnbuffered(
95029544 });
95039545 }
95049546 if (function.instructions.len > 0) {
9547 const maybe_empty_tuple: ?u32 = if (!function.any_nosanitize) null else b: {
9548 const gop = try metadata_formatter.map.getOrPut(self.gpa, .{
9549 .metadata = .empty_tuple,
9550 });
9551 break :b @intCast(gop.index);
9552 };
95059553 var block_incoming_len: u32 = undefined;
95069554 try writer.writeAll(" {\n");
95079555 var maybe_dbg_index: ?u32 = null;
......@@ -9684,6 +9732,14 @@ pub fn printUnbuffered(
96849732 extra.@"else".toInst(&function).fmt(function_index, self),
96859733 });
96869734 },
9735 .br_cond_nosanitize => {
9736 const extra = function.extraData(Function.Instruction.BrCond, instruction.data);
9737 try writer.print(" br {%}, {%}, {%}", .{
9738 extra.cond.fmt(function_index, self),
9739 extra.then.toInst(&function).fmt(function_index, self),
9740 extra.@"else".toInst(&function).fmt(function_index, self),
9741 });
9742 },
96879743 .call,
96889744 .@"call fast",
96899745 .@"musttail call",
......@@ -9950,8 +10006,12 @@ pub fn printUnbuffered(
995010006 }
995110007
995210008 if (maybe_dbg_index) |dbg_index| {
9953 try writer.print(", !dbg !{}\n", .{dbg_index});
9954 } else try writer.writeByte('\n');
10009 try writer.print(", !dbg !{}", .{dbg_index});
10010 }
10011 if (instruction.tag.isNosanitize()) {
10012 try writer.print(", !nosanitize !{d}", .{maybe_empty_tuple.?});
10013 }
10014 try writer.writeByte('\n');
995510015 }
995610016 try writer.writeByte('}');
995710017 }
......@@ -13759,7 +13819,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1375913819 const MetadataKindBlock = ir.MetadataKindBlock;
1376013820 var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true);
1376113821
13762 inline for (@typeInfo(ir.MetadataKind).Enum.fields) |field| {
13822 inline for (@typeInfo(ir.FixedMetadataKind).Enum.fields) |field| {
1376313823 try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{
1376413824 .id = field.value,
1376513825 .name = field.name,
......@@ -14046,7 +14106,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1404614106 else
1404714107 -%val << 1 | 1);
1404814108 }
14049 try metadata_block.writeUnabbrev(MetadataBlock.Enumerator.id, record.items);
14109 try metadata_block.writeUnabbrev(@intFromEnum(MetadataBlock.Enumerator.id), record.items);
1405014110 continue;
1405114111 };
1405214112 try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{
......@@ -14177,7 +14237,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1417714237
1417814238 try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{
1417914239 .value = @enumFromInt(constant_adapter.getConstantIndex(global.toConst())),
14180 .kind = ir.MetadataKind.dbg,
14240 .kind = .dbg,
1418114241 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(global_ptr.dbg) - 1),
1418214242 });
1418314243 }
......@@ -14220,20 +14280,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1422014280 constant_adapter: ConstantAdapter,
1422114281 metadata_adapter: MetadataAdapter,
1422214282 func: *const Function,
14223 instruction_index: u32 = 0,
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 }
14283 instruction_index: Function.Instruction.Index,
1423714284
1423814285 pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) {
1423914286 _ = field_name;
......@@ -14282,19 +14329,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1428214329 }
1428314330
1428414331 pub fn offset(adapter: @This()) u32 {
14285 return @as(
14286 Function.Instruction.Index,
14287 @enumFromInt(adapter.instruction_index),
14288 ).valueIndex(adapter.func) + adapter.firstInstr();
14332 return adapter.instruction_index.valueIndex(adapter.func) + adapter.firstInstr();
1428914333 }
1429014334
1429114335 fn firstInstr(adapter: @This()) u32 {
1429214336 return adapter.constant_adapter.numConstants();
1429314337 }
14294
14295 pub fn next(adapter: *@This()) void {
14296 adapter.instruction_index += 1;
14297 }
1429814338 };
1429914339
1430014340 for (self.functions.items, 0..) |func, func_index| {
......@@ -14307,7 +14347,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1430714347
1430814348 try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len });
1430914349
14310 var adapter = FunctionAdapter.init(constant_adapter, metadata_adapter, &func);
14350 var adapter: FunctionAdapter = .{
14351 .constant_adapter = constant_adapter,
14352 .metadata_adapter = metadata_adapter,
14353 .func = &func,
14354 .instruction_index = @enumFromInt(0),
14355 };
1431114356
1431214357 // Emit function level metadata block
1431314358 if (!func.strip and func.debug_values.len > 0) {
......@@ -14330,21 +14375,23 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1433014375 var has_location = false;
1433114376
1433214377 var block_incoming_len: u32 = undefined;
14333 for (0..func.instructions.len) |instr_index| {
14334 const tag = tags[instr_index];
14335
14378 for (tags, datas, 0..) |tag, data, instr_index| {
14379 adapter.instruction_index = @enumFromInt(instr_index);
1433614380 record.clearRetainingCapacity();
1433714381
1433814382 switch (tag) {
14339 .block => block_incoming_len = datas[instr_index],
14340 .arg => {},
14383 .arg => continue,
14384 .block => {
14385 block_incoming_len = data;
14386 continue;
14387 },
1434114388 .@"unreachable" => try function_block.writeAbbrev(FunctionBlock.Unreachable{}),
1434214389 .call,
1434314390 .@"musttail call",
1434414391 .@"notail call",
1434514392 .@"tail call",
1434614393 => |kind| {
14347 var extra = func.extraDataTrail(Function.Instruction.Call, datas[instr_index]);
14394 var extra = func.extraDataTrail(Function.Instruction.Call, data);
1434814395
1434914396 const call_conv = extra.data.info.call_conv;
1435014397 const args = extra.trail.next(extra.data.args_len, Value, &func);
......@@ -14367,7 +14414,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1436714414 .@"notail call fast",
1436814415 .@"tail call fast",
1436914416 => |kind| {
14370 var extra = func.extraDataTrail(Function.Instruction.Call, datas[instr_index]);
14417 var extra = func.extraDataTrail(Function.Instruction.Call, data);
1437114418
1437214419 const call_conv = extra.data.info.call_conv;
1437314420 const args = extra.trail.next(extra.data.args_len, Value, &func);
......@@ -14405,7 +14452,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1440514452 .srem,
1440614453 .ashr,
1440714454 => |kind| {
14408 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
14455 const extra = func.extraData(Function.Instruction.Binary, data);
1440914456 try function_block.writeAbbrev(FunctionBlock.Binary{
1441014457 .opcode = kind.toBinaryOpcode(),
1441114458 .lhs = adapter.getOffsetValueIndex(extra.lhs),
......@@ -14417,7 +14464,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1441714464 .@"lshr exact",
1441814465 .@"ashr exact",
1441914466 => |kind| {
14420 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
14467 const extra = func.extraData(Function.Instruction.Binary, data);
1442114468 try function_block.writeAbbrev(FunctionBlock.BinaryExact{
1442214469 .opcode = kind.toBinaryOpcode(),
1442314470 .lhs = adapter.getOffsetValueIndex(extra.lhs),
......@@ -14437,7 +14484,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1443714484 .@"shl nuw",
1443814485 .@"shl nuw nsw",
1443914486 => |kind| {
14440 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
14487 const extra = func.extraData(Function.Instruction.Binary, data);
1444114488 try function_block.writeAbbrev(FunctionBlock.BinaryNoWrap{
1444214489 .opcode = kind.toBinaryOpcode(),
1444314490 .lhs = adapter.getOffsetValueIndex(extra.lhs),
......@@ -14468,7 +14515,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1446814515 .@"frem fast",
1446914516 .@"fsub fast",
1447014517 => |kind| {
14471 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
14518 const extra = func.extraData(Function.Instruction.Binary, data);
1447214519 try function_block.writeAbbrev(FunctionBlock.BinaryFast{
1447314520 .opcode = kind.toBinaryOpcode(),
1447414521 .lhs = adapter.getOffsetValueIndex(extra.lhs),
......@@ -14479,7 +14526,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1447914526 .alloca,
1448014527 .@"alloca inalloca",
1448114528 => |kind| {
14482 const extra = func.extraData(Function.Instruction.Alloca, datas[instr_index]);
14529 const extra = func.extraData(Function.Instruction.Alloca, data);
1448314530 const alignment = extra.info.alignment.toLlvm();
1448414531 try function_block.writeAbbrev(FunctionBlock.Alloca{
1448514532 .inst_type = extra.type,
......@@ -14508,7 +14555,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1450814555 .sext,
1450914556 .zext,
1451014557 => |kind| {
14511 const extra = func.extraData(Function.Instruction.Cast, datas[instr_index]);
14558 const extra = func.extraData(Function.Instruction.Cast, data);
1451214559 try function_block.writeAbbrev(FunctionBlock.Cast{
1451314560 .val = adapter.getOffsetValueIndex(extra.val),
1451414561 .type_index = extra.type,
......@@ -14542,7 +14589,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1454214589 .@"icmp ule",
1454314590 .@"icmp ult",
1454414591 => |kind| {
14545 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
14592 const extra = func.extraData(Function.Instruction.Binary, data);
1454614593 try function_block.writeAbbrev(FunctionBlock.Cmp{
1454714594 .lhs = adapter.getOffsetValueIndex(extra.lhs),
1454814595 .rhs = adapter.getOffsetValueIndex(extra.rhs),
......@@ -14566,7 +14613,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1456614613 .@"fcmp fast une",
1456714614 .@"fcmp fast uno",
1456814615 => |kind| {
14569 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
14616 const extra = func.extraData(Function.Instruction.Binary, data);
1457014617 try function_block.writeAbbrev(FunctionBlock.CmpFast{
1457114618 .lhs = adapter.getOffsetValueIndex(extra.lhs),
1457214619 .rhs = adapter.getOffsetValueIndex(extra.rhs),
......@@ -14575,14 +14622,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1457514622 });
1457614623 },
1457714624 .fneg => try function_block.writeAbbrev(FunctionBlock.FNeg{
14578 .val = adapter.getOffsetValueIndex(@enumFromInt(datas[instr_index])),
14625 .val = adapter.getOffsetValueIndex(@enumFromInt(data)),
1457914626 }),
1458014627 .@"fneg fast" => try function_block.writeAbbrev(FunctionBlock.FNegFast{
14581 .val = adapter.getOffsetValueIndex(@enumFromInt(datas[instr_index])),
14628 .val = adapter.getOffsetValueIndex(@enumFromInt(data)),
1458214629 .fast_math = FastMath.fast,
1458314630 }),
1458414631 .extractvalue => {
14585 var extra = func.extraDataTrail(Function.Instruction.ExtractValue, datas[instr_index]);
14632 var extra = func.extraDataTrail(Function.Instruction.ExtractValue, data);
1458614633 const indices = extra.trail.next(extra.data.indices_len, u32, &func);
1458714634 try function_block.writeAbbrev(FunctionBlock.ExtractValue{
1458814635 .val = adapter.getOffsetValueIndex(extra.data.val),
......@@ -14590,7 +14637,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1459014637 });
1459114638 },
1459214639 .insertvalue => {
14593 var extra = func.extraDataTrail(Function.Instruction.InsertValue, datas[instr_index]);
14640 var extra = func.extraDataTrail(Function.Instruction.InsertValue, data);
1459414641 const indices = extra.trail.next(extra.data.indices_len, u32, &func);
1459514642 try function_block.writeAbbrev(FunctionBlock.InsertValue{
1459614643 .val = adapter.getOffsetValueIndex(extra.data.val),
......@@ -14599,14 +14646,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1459914646 });
1460014647 },
1460114648 .extractelement => {
14602 const extra = func.extraData(Function.Instruction.ExtractElement, datas[instr_index]);
14649 const extra = func.extraData(Function.Instruction.ExtractElement, data);
1460314650 try function_block.writeAbbrev(FunctionBlock.ExtractElement{
1460414651 .val = adapter.getOffsetValueIndex(extra.val),
1460514652 .index = adapter.getOffsetValueIndex(extra.index),
1460614653 });
1460714654 },
1460814655 .insertelement => {
14609 const extra = func.extraData(Function.Instruction.InsertElement, datas[instr_index]);
14656 const extra = func.extraData(Function.Instruction.InsertElement, data);
1461014657 try function_block.writeAbbrev(FunctionBlock.InsertElement{
1461114658 .val = adapter.getOffsetValueIndex(extra.val),
1461214659 .elem = adapter.getOffsetValueIndex(extra.elem),
......@@ -14614,7 +14661,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1461414661 });
1461514662 },
1461614663 .select => {
14617 const extra = func.extraData(Function.Instruction.Select, datas[instr_index]);
14664 const extra = func.extraData(Function.Instruction.Select, data);
1461814665 try function_block.writeAbbrev(FunctionBlock.Select{
1461914666 .lhs = adapter.getOffsetValueIndex(extra.lhs),
1462014667 .rhs = adapter.getOffsetValueIndex(extra.rhs),
......@@ -14622,7 +14669,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1462214669 });
1462314670 },
1462414671 .@"select fast" => {
14625 const extra = func.extraData(Function.Instruction.Select, datas[instr_index]);
14672 const extra = func.extraData(Function.Instruction.Select, data);
1462614673 try function_block.writeAbbrev(FunctionBlock.SelectFast{
1462714674 .lhs = adapter.getOffsetValueIndex(extra.lhs),
1462814675 .rhs = adapter.getOffsetValueIndex(extra.rhs),
......@@ -14631,7 +14678,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1463114678 });
1463214679 },
1463314680 .shufflevector => {
14634 const extra = func.extraData(Function.Instruction.ShuffleVector, datas[instr_index]);
14681 const extra = func.extraData(Function.Instruction.ShuffleVector, data);
1463514682 try function_block.writeAbbrev(FunctionBlock.ShuffleVector{
1463614683 .lhs = adapter.getOffsetValueIndex(extra.lhs),
1463714684 .rhs = adapter.getOffsetValueIndex(extra.rhs),
......@@ -14641,7 +14688,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1464114688 .getelementptr,
1464214689 .@"getelementptr inbounds",
1464314690 => |kind| {
14644 var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, datas[instr_index]);
14691 var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, data);
1464514692 const indices = extra.trail.next(extra.data.indices_len, Value, &func);
1464614693 try function_block.writeAbbrevAdapted(
1464714694 FunctionBlock.GetElementPtr{
......@@ -14654,7 +14701,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1465414701 );
1465514702 },
1465614703 .load => {
14657 const extra = func.extraData(Function.Instruction.Load, datas[instr_index]);
14704 const extra = func.extraData(Function.Instruction.Load, data);
1465814705 try function_block.writeAbbrev(FunctionBlock.Load{
1465914706 .ptr = adapter.getOffsetValueIndex(extra.ptr),
1466014707 .ty = extra.type,
......@@ -14663,7 +14710,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1466314710 });
1466414711 },
1466514712 .@"load atomic" => {
14666 const extra = func.extraData(Function.Instruction.Load, datas[instr_index]);
14713 const extra = func.extraData(Function.Instruction.Load, data);
1466714714 try function_block.writeAbbrev(FunctionBlock.LoadAtomic{
1466814715 .ptr = adapter.getOffsetValueIndex(extra.ptr),
1466914716 .ty = extra.type,
......@@ -14674,7 +14721,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1467414721 });
1467514722 },
1467614723 .store => {
14677 const extra = func.extraData(Function.Instruction.Store, datas[instr_index]);
14724 const extra = func.extraData(Function.Instruction.Store, data);
1467814725 try function_block.writeAbbrev(FunctionBlock.Store{
1467914726 .ptr = adapter.getOffsetValueIndex(extra.ptr),
1468014727 .val = adapter.getOffsetValueIndex(extra.val),
......@@ -14683,7 +14730,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1468314730 });
1468414731 },
1468514732 .@"store atomic" => {
14686 const extra = func.extraData(Function.Instruction.Store, datas[instr_index]);
14733 const extra = func.extraData(Function.Instruction.Store, data);
1468714734 try function_block.writeAbbrev(FunctionBlock.StoreAtomic{
1468814735 .ptr = adapter.getOffsetValueIndex(extra.ptr),
1468914736 .val = adapter.getOffsetValueIndex(extra.val),
......@@ -14695,11 +14742,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1469514742 },
1469614743 .br => {
1469714744 try function_block.writeAbbrev(FunctionBlock.BrUnconditional{
14698 .block = datas[instr_index],
14745 .block = data,
1469914746 });
1470014747 },
14701 .br_cond => {
14702 const extra = func.extraData(Function.Instruction.BrCond, datas[instr_index]);
14748 .br_cond, .br_cond_nosanitize => {
14749 const extra = func.extraData(Function.Instruction.BrCond, data);
1470314750 try function_block.writeAbbrev(FunctionBlock.BrConditional{
1470414751 .then_block = @intFromEnum(extra.then),
1470514752 .else_block = @intFromEnum(extra.@"else"),
......@@ -14707,7 +14754,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1470714754 });
1470814755 },
1470914756 .@"switch" => {
14710 var extra = func.extraDataTrail(Function.Instruction.Switch, datas[instr_index]);
14757 var extra = func.extraDataTrail(Function.Instruction.Switch, data);
1471114758
1471214759 try record.ensureUnusedCapacity(self.gpa, 3 + extra.data.cases_len * 2);
1471314760
......@@ -14730,7 +14777,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1473014777 try function_block.writeUnabbrev(12, record.items);
1473114778 },
1473214779 .va_arg => {
14733 const extra = func.extraData(Function.Instruction.VaArg, datas[instr_index]);
14780 const extra = func.extraData(Function.Instruction.VaArg, data);
1473414781 try function_block.writeAbbrev(FunctionBlock.VaArg{
1473514782 .list_type = extra.list.typeOf(@enumFromInt(func_index), self),
1473614783 .list = adapter.getOffsetValueIndex(extra.list),
......@@ -14740,7 +14787,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1474014787 .phi,
1474114788 .@"phi fast",
1474214789 => |kind| {
14743 var extra = func.extraDataTrail(Function.Instruction.Phi, datas[instr_index]);
14790 var extra = func.extraDataTrail(Function.Instruction.Phi, data);
1474414791 const vals = extra.trail.next(block_incoming_len, Value, &func);
1474514792 const blocks = extra.trail.next(block_incoming_len, Function.Block.Index, &func);
1474614793
......@@ -14764,11 +14811,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1476414811 try function_block.writeUnabbrev(16, record.items);
1476514812 },
1476614813 .ret => try function_block.writeAbbrev(FunctionBlock.Ret{
14767 .val = adapter.getOffsetValueIndex(@enumFromInt(datas[instr_index])),
14814 .val = adapter.getOffsetValueIndex(@enumFromInt(data)),
1476814815 }),
1476914816 .@"ret void" => try function_block.writeAbbrev(FunctionBlock.RetVoid{}),
1477014817 .atomicrmw => {
14771 const extra = func.extraData(Function.Instruction.AtomicRmw, datas[instr_index]);
14818 const extra = func.extraData(Function.Instruction.AtomicRmw, data);
1477214819 try function_block.writeAbbrev(FunctionBlock.AtomicRmw{
1477314820 .ptr = adapter.getOffsetValueIndex(extra.ptr),
1477414821 .val = adapter.getOffsetValueIndex(extra.val),
......@@ -14782,7 +14829,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1478214829 .cmpxchg,
1478314830 .@"cmpxchg weak",
1478414831 => |kind| {
14785 const extra = func.extraData(Function.Instruction.CmpXchg, datas[instr_index]);
14832 const extra = func.extraData(Function.Instruction.CmpXchg, data);
1478614833
1478714834 try function_block.writeAbbrev(FunctionBlock.CmpXchg{
1478814835 .ptr = adapter.getOffsetValueIndex(extra.ptr),
......@@ -14797,7 +14844,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1479714844 });
1479814845 },
1479914846 .fence => {
14800 const info: MemoryAccessInfo = @bitCast(datas[instr_index]);
14847 const info: MemoryAccessInfo = @bitCast(data);
1480114848 try function_block.writeAbbrev(FunctionBlock.Fence{
1480214849 .ordering = info.success_ordering,
1480314850 .sync_scope = info.sync_scope,
......@@ -14806,7 +14853,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1480614853 }
1480714854
1480814855 if (!func.strip) {
14809 if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| {
14856 if (func.debug_locations.get(adapter.instruction_index)) |debug_location| {
1481014857 switch (debug_location) {
1481114858 .no_location => has_location = false,
1481214859 .location => |location| {
......@@ -14823,8 +14870,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1482314870 try function_block.writeAbbrev(FunctionBlock.DebugLocAgain{});
1482414871 }
1482514872 }
14826
14827 adapter.next();
1482814873 }
1482914874
1483014875 // VALUE_SYMTAB
......@@ -14850,18 +14895,34 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1485014895 }
1485114896
1485214897 // METADATA_ATTACHMENT_BLOCK
14853 if (!func.strip) blk: {
14854 const dbg = func.global.ptrConst(self).dbg;
14855
14856 if (dbg == .none) break :blk;
14857
14898 if (!func.strip or func.any_nosanitize) {
1485814899 const MetadataAttachmentBlock = ir.MetadataAttachmentBlock;
1485914900 var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false);
1486014901
14861 try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentSingle{
14862 .kind = ir.MetadataKind.dbg,
14863 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
14864 });
14902 if (!func.strip) blk: {
14903 const dbg = func.global.ptrConst(self).dbg;
14904 if (dbg == .none) break :blk;
14905 try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentGlobalSingle{
14906 .kind = .dbg,
14907 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
14908 });
14909 }
14910
14911 var instr_index: u32 = 0;
14912 for (func.instructions.items(.tag)) |instr_tag| switch (instr_tag) {
14913 .arg, .block => {},
14914 .br_cond_nosanitize => {
14915 try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{
14916 .inst = instr_index,
14917 .kind = .nosanitize,
14918 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(.empty_tuple) - 1),
14919 });
14920 instr_index += 1;
14921 },
14922 else => {
14923 instr_index += 1;
14924 },
14925 };
1486514926
1486614927 try metadata_attach_block.end();
1486714928 }
src/codegen/llvm/ir.zig+176-29
......@@ -20,8 +20,142 @@ const ColumnAbbrev = AbbrevOp{ .vbr = 8 };
2020
2121const 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) {
2426 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,
25159};
26160
27161pub const Identification = struct {
......@@ -622,16 +756,29 @@ pub const MetadataAttachmentBlock = struct {
622756 pub const id = 16;
623757
624758 pub const abbrevs = [_]type{
625 AttachmentSingle,
759 AttachmentGlobalSingle,
760 AttachmentInstructionSingle,
626761 };
627762
628 pub const AttachmentSingle = struct {
763 pub const AttachmentGlobalSingle = struct {
629764 pub const ops = [_]AbbrevOp{
630 .{ .literal = 11 },
765 .{ .literal = @intFromEnum(MetadataCode.ATTACHMENT) },
631766 .{ .fixed = 1 },
632767 MetadataAbbrev,
633768 };
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,
635782 metadata: Builder.Metadata,
636783 };
637784};
......@@ -666,7 +813,7 @@ pub const MetadataBlock = struct {
666813
667814 pub const Strings = struct {
668815 pub const ops = [_]AbbrevOp{
669 .{ .literal = 35 },
816 .{ .literal = @intFromEnum(MetadataCode.STRINGS) },
670817 .{ .vbr = 6 },
671818 .{ .vbr = 6 },
672819 .blob,
......@@ -678,7 +825,7 @@ pub const MetadataBlock = struct {
678825
679826 pub const File = struct {
680827 pub const ops = [_]AbbrevOp{
681 .{ .literal = 16 },
828 .{ .literal = @intFromEnum(MetadataCode.FILE) },
682829 .{ .literal = 0 }, // is distinct
683830 MetadataAbbrev, // filename
684831 MetadataAbbrev, // directory
......@@ -692,7 +839,7 @@ pub const MetadataBlock = struct {
692839
693840 pub const CompileUnit = struct {
694841 pub const ops = [_]AbbrevOp{
695 .{ .literal = 20 },
842 .{ .literal = @intFromEnum(MetadataCode.COMPILE_UNIT) },
696843 .{ .literal = 1 }, // is distinct
697844 .{ .literal = std.dwarf.LANG.C99 }, // source language
698845 MetadataAbbrev, // file
......@@ -726,7 +873,7 @@ pub const MetadataBlock = struct {
726873
727874 pub const Subprogram = struct {
728875 pub const ops = [_]AbbrevOp{
729 .{ .literal = 21 },
876 .{ .literal = @intFromEnum(MetadataCode.SUBPROGRAM) },
730877 .{ .literal = 0b111 }, // is distinct | has sp flags | has flags
731878 MetadataAbbrev, // scope
732879 MetadataAbbrev, // name
......@@ -763,7 +910,7 @@ pub const MetadataBlock = struct {
763910
764911 pub const LexicalBlock = struct {
765912 pub const ops = [_]AbbrevOp{
766 .{ .literal = 22 },
913 .{ .literal = @intFromEnum(MetadataCode.LEXICAL_BLOCK) },
767914 .{ .literal = 0 }, // is distinct
768915 MetadataAbbrev, // scope
769916 MetadataAbbrev, // file
......@@ -779,7 +926,7 @@ pub const MetadataBlock = struct {
779926
780927 pub const Location = struct {
781928 pub const ops = [_]AbbrevOp{
782 .{ .literal = 7 },
929 .{ .literal = @intFromEnum(MetadataCode.LOCATION) },
783930 .{ .literal = 0 }, // is distinct
784931 LineAbbrev, // line
785932 ColumnAbbrev, // column
......@@ -796,7 +943,7 @@ pub const MetadataBlock = struct {
796943
797944 pub const BasicType = struct {
798945 pub const ops = [_]AbbrevOp{
799 .{ .literal = 15 },
946 .{ .literal = @intFromEnum(MetadataCode.BASIC_TYPE) },
800947 .{ .literal = 0 }, // is distinct
801948 .{ .literal = std.dwarf.TAG.base_type }, // tag
802949 MetadataAbbrev, // name
......@@ -813,7 +960,7 @@ pub const MetadataBlock = struct {
813960
814961 pub const CompositeType = struct {
815962 pub const ops = [_]AbbrevOp{
816 .{ .literal = 18 },
963 .{ .literal = @intFromEnum(MetadataCode.COMPOSITE_TYPE) },
817964 .{ .literal = 0 | 0x2 }, // is distinct | is not used in old type ref
818965 .{ .fixed = 32 }, // tag
819966 MetadataAbbrev, // name
......@@ -852,7 +999,7 @@ pub const MetadataBlock = struct {
852999
8531000 pub const DerivedType = struct {
8541001 pub const ops = [_]AbbrevOp{
855 .{ .literal = 17 },
1002 .{ .literal = @intFromEnum(MetadataCode.DERIVED_TYPE) },
8561003 .{ .literal = 0 }, // is distinct
8571004 .{ .fixed = 32 }, // tag
8581005 MetadataAbbrev, // name
......@@ -880,7 +1027,7 @@ pub const MetadataBlock = struct {
8801027
8811028 pub const SubroutineType = struct {
8821029 pub const ops = [_]AbbrevOp{
883 .{ .literal = 19 },
1030 .{ .literal = @intFromEnum(MetadataCode.SUBROUTINE_TYPE) },
8841031 .{ .literal = 0 | 0x2 }, // is distinct | has no old type refs
8851032 .{ .literal = 0 }, // flags
8861033 MetadataAbbrev, // types
......@@ -891,7 +1038,7 @@ pub const MetadataBlock = struct {
8911038 };
8921039
8931040 pub const Enumerator = struct {
894 pub const id = 14;
1041 pub const id: MetadataCode = .ENUMERATOR;
8951042
8961043 pub const Flags = packed struct(u3) {
8971044 distinct: bool = false,
......@@ -900,7 +1047,7 @@ pub const MetadataBlock = struct {
9001047 };
9011048
9021049 pub const ops = [_]AbbrevOp{
903 .{ .literal = Enumerator.id },
1050 .{ .literal = @intFromEnum(Enumerator.id) },
9041051 .{ .fixed = @bitSizeOf(Flags) }, // flags
9051052 .{ .vbr = 6 }, // bit width
9061053 MetadataAbbrev, // name
......@@ -915,7 +1062,7 @@ pub const MetadataBlock = struct {
9151062
9161063 pub const Subrange = struct {
9171064 pub const ops = [_]AbbrevOp{
918 .{ .literal = 13 },
1065 .{ .literal = @intFromEnum(MetadataCode.SUBRANGE) },
9191066 .{ .literal = 0b10 }, // is distinct | version
9201067 MetadataAbbrev, // count
9211068 MetadataAbbrev, // lower bound
......@@ -929,7 +1076,7 @@ pub const MetadataBlock = struct {
9291076
9301077 pub const Expression = struct {
9311078 pub const ops = [_]AbbrevOp{
932 .{ .literal = 29 },
1079 .{ .literal = @intFromEnum(MetadataCode.EXPRESSION) },
9331080 .{ .literal = 0 | (3 << 1) }, // is distinct | version
9341081 MetadataArrayAbbrev, // elements
9351082 };
......@@ -939,7 +1086,7 @@ pub const MetadataBlock = struct {
9391086
9401087 pub const Node = struct {
9411088 pub const ops = [_]AbbrevOp{
942 .{ .literal = 3 },
1089 .{ .literal = @intFromEnum(MetadataCode.NODE) },
9431090 MetadataArrayAbbrev, // elements
9441091 };
9451092
......@@ -948,7 +1095,7 @@ pub const MetadataBlock = struct {
9481095
9491096 pub const LocalVar = struct {
9501097 pub const ops = [_]AbbrevOp{
951 .{ .literal = 28 },
1098 .{ .literal = @intFromEnum(MetadataCode.LOCAL_VAR) },
9521099 .{ .literal = 0b10 }, // is distinct | has alignment
9531100 MetadataAbbrev, // scope
9541101 MetadataAbbrev, // name
......@@ -970,7 +1117,7 @@ pub const MetadataBlock = struct {
9701117
9711118 pub const Parameter = struct {
9721119 pub const ops = [_]AbbrevOp{
973 .{ .literal = 28 },
1120 .{ .literal = @intFromEnum(MetadataCode.LOCAL_VAR) },
9741121 .{ .literal = 0b10 }, // is distinct | has alignment
9751122 MetadataAbbrev, // scope
9761123 MetadataAbbrev, // name
......@@ -993,7 +1140,7 @@ pub const MetadataBlock = struct {
9931140
9941141 pub const GlobalVar = struct {
9951142 pub const ops = [_]AbbrevOp{
996 .{ .literal = 27 },
1143 .{ .literal = @intFromEnum(MetadataCode.GLOBAL_VAR) },
9971144 .{ .literal = 0b101 }, // is distinct | version
9981145 MetadataAbbrev, // scope
9991146 MetadataAbbrev, // name
......@@ -1020,7 +1167,7 @@ pub const MetadataBlock = struct {
10201167
10211168 pub const GlobalVarExpression = struct {
10221169 pub const ops = [_]AbbrevOp{
1023 .{ .literal = 37 },
1170 .{ .literal = @intFromEnum(MetadataCode.GLOBAL_VAR_EXPR) },
10241171 .{ .literal = 0 }, // is distinct
10251172 MetadataAbbrev, // variable
10261173 MetadataAbbrev, // expression
......@@ -1032,7 +1179,7 @@ pub const MetadataBlock = struct {
10321179
10331180 pub const Constant = struct {
10341181 pub const ops = [_]AbbrevOp{
1035 .{ .literal = 2 },
1182 .{ .literal = @intFromEnum(MetadataCode.VALUE) },
10361183 MetadataAbbrev, // type
10371184 MetadataAbbrev, // value
10381185 };
......@@ -1043,7 +1190,7 @@ pub const MetadataBlock = struct {
10431190
10441191 pub const Name = struct {
10451192 pub const ops = [_]AbbrevOp{
1046 .{ .literal = 4 },
1193 .{ .literal = @intFromEnum(MetadataCode.NAME) },
10471194 .{ .array_fixed = 8 }, // name
10481195 };
10491196
......@@ -1052,7 +1199,7 @@ pub const MetadataBlock = struct {
10521199
10531200 pub const NamedNode = struct {
10541201 pub const ops = [_]AbbrevOp{
1055 .{ .literal = 10 },
1202 .{ .literal = @intFromEnum(MetadataCode.NAMED_NODE) },
10561203 MetadataArrayAbbrev, // elements
10571204 };
10581205
......@@ -1061,14 +1208,14 @@ pub const MetadataBlock = struct {
10611208
10621209 pub const GlobalDeclAttachment = struct {
10631210 pub const ops = [_]AbbrevOp{
1064 .{ .literal = 36 },
1211 .{ .literal = @intFromEnum(MetadataCode.GLOBAL_DECL_ATTACHMENT) },
10651212 ValueAbbrev, // value id
10661213 .{ .fixed = 1 }, // kind
10671214 MetadataAbbrev, // elements
10681215 };
10691216
10701217 value: Builder.Constant,
1071 kind: MetadataKind,
1218 kind: FixedMetadataKind,
10721219 metadata: Builder.Metadata,
10731220 };
10741221};