authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-22 08:54:10+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-22 08:54:35+01:00
log4b215e3a115d172913d4bb993b6b48dc97566181
treeb0a3ab6335e76b60b9ae13c98b949f623de86435
parenta907353ca4df47b359b59d15259bbb105253b176

Builder: support printing metadata in llvm ir


5 files changed, 2813 insertions(+), 2103 deletions(-)

lib/std/meta.zig+3-5
......@@ -460,13 +460,11 @@ test "std.meta.FieldType" {
460460 try testing.expect(FieldType(U, .d) == *const u8);
461461}
462462
463pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {
463pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {
464464 return comptime blk: {
465465 const fieldInfos = fields(T);
466 var names: [fieldInfos.len][]const u8 = undefined;
467 for (fieldInfos, 0..) |field, i| {
468 names[i] = field.name;
469 }
466 var names: [fieldInfos.len][:0]const u8 = undefined;
467 for (&names, fieldInfos) |*name, field| name.* = field.name;
470468 break :blk &names;
471469 };
472470}
src/codegen/llvm.zig+91-93
......@@ -872,8 +872,8 @@ pub const Object = struct {
872872 };
873873
874874 const debug_file = try builder.debugFile(
875 try builder.metadataString(compile_unit_dir),
876875 try builder.metadataString(comp.root_name),
876 try builder.metadataString(compile_unit_dir),
877877 );
878878
879879 const debug_enums_fwd_ref = try builder.debugForwardReference();
......@@ -1646,10 +1646,6 @@ pub const Object = struct {
16461646 const line_number = decl.src_line + 1;
16471647 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
16481648 !zcu.decl_exports.contains(decl_index);
1649 const noret_bit: u29 = if (fn_info.return_type == .noreturn_type)
1650 Builder.DIFlags.NoReturn
1651 else
1652 0;
16531649 const debug_decl_type = try o.lowerDebugType(decl.ty);
16541650
16551651 break :blk try o.builder.debugSubprogram(
......@@ -1660,14 +1656,20 @@ pub const Object = struct {
16601656 line_number + func.lbrace_line,
16611657 debug_decl_type,
16621658 .{
1663 .optimized = owner_mod.optimize_mode != .Debug,
1664 .definition = true,
1665 .local = is_internal_linkage,
1666 .debug_info_flags = Builder.DIFlags.StaticMember | noret_bit,
1659 .di_flags = .{
1660 .StaticMember = true,
1661 .NoReturn = fn_info.return_type == .noreturn_type,
1662 },
1663 .sp_flags = .{
1664 .Optimized = owner_mod.optimize_mode != .Debug,
1665 .Definition = true,
1666 .LocalToUnit = is_internal_linkage,
1667 },
16671668 },
16681669 o.debug_compile_unit,
16691670 );
16701671 };
1672 function_index.setSubprogram(subprogram, &o.builder);
16711673
16721674 var fg: FuncGen = .{
16731675 .gpa = gpa,
......@@ -1682,8 +1684,7 @@ pub const Object = struct {
16821684 .blocks = .{},
16831685 .sync_scope = if (owner_mod.single_threaded) .singlethread else .system,
16841686 .file = file,
1685 .subprogram = subprogram,
1686 .current_scope = subprogram,
1687 .scope = subprogram,
16871688 .base_line = dg.decl.src_line,
16881689 .prev_dbg_line = 0,
16891690 .prev_dbg_column = 0,
......@@ -1914,8 +1915,8 @@ pub const Object = struct {
19141915
19151916 fn getDebugFile(o: *Object, file: *const Module.File) Allocator.Error!Builder.Metadata {
19161917 return try o.builder.debugFile(
1917 if (std.fs.path.dirname(file.sub_file_path)) |dirname| try o.builder.metadataString(dirname) else .none,
19181918 try o.builder.metadataString(std.fs.path.basename(file.sub_file_path)),
1919 if (std.fs.path.dirname(file.sub_file_path)) |dirname| try o.builder.metadataString(dirname) else .none,
19191920 );
19201921 }
19211922
......@@ -1923,7 +1924,7 @@ pub const Object = struct {
19231924 o: *Object,
19241925 ty: Type,
19251926 ) Allocator.Error!Builder.Metadata {
1926 if (o.builder.strip) return Builder.Metadata.none;
1927 if (o.builder.strip) return .none;
19271928 const gpa = o.gpa;
19281929 const target = o.target;
19291930 const mod = o.module;
......@@ -2086,7 +2087,7 @@ pub const Object = struct {
20862087
20872088 const debug_ptr_type = try o.builder.debugMemberType(
20882089 try o.builder.metadataString("ptr"),
2089 Builder.Metadata.none, // File
2090 .none, // File
20902091 debug_fwd_ref,
20912092 0, // Line
20922093 try o.lowerDebugType(ptr_ty),
......@@ -2097,7 +2098,7 @@ pub const Object = struct {
20972098
20982099 const debug_len_type = try o.builder.debugMemberType(
20992100 try o.builder.metadataString("len"),
2100 Builder.Metadata.none, // File
2101 .none, // File
21012102 debug_fwd_ref,
21022103 0, // Line
21032104 try o.lowerDebugType(len_ty),
......@@ -2108,10 +2109,10 @@ pub const Object = struct {
21082109
21092110 const debug_slice_type = try o.builder.debugStructType(
21102111 try o.builder.metadataString(name),
2111 Builder.Metadata.none, // File
2112 .none, // File
21122113 o.debug_compile_unit, // Scope
21132114 line,
2114 Builder.Metadata.none, // Underlying type
2115 .none, // Underlying type
21152116 ty.abiSize(mod) * 8,
21162117 ty.abiAlignment(mod).toByteUnits(0) * 8,
21172118 try o.builder.debugTuple(&.{
......@@ -2136,8 +2137,8 @@ pub const Object = struct {
21362137
21372138 const debug_ptr_type = try o.builder.debugPointerType(
21382139 try o.builder.metadataString(name),
2139 Builder.Metadata.none, // File
2140 Builder.Metadata.none, // Scope
2140 .none, // File
2141 .none, // Scope
21412142 0, // Line
21422143 debug_elem_ty,
21432144 target.ptrBitWidth(),
......@@ -2172,19 +2173,19 @@ pub const Object = struct {
21722173 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
21732174 try o.namespaceToDebugScope(owner_decl.src_namespace),
21742175 owner_decl.src_node + 1, // Line
2175 Builder.Metadata.none, // Underlying type
2176 .none, // Underlying type
21762177 0, // Size
21772178 0, // Align
2178 Builder.Metadata.none, // Fields
2179 .none, // Fields
21792180 );
21802181 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
21812182 return debug_opaque_type;
21822183 },
21832184 .Array => {
21842185 const debug_array_type = try o.builder.debugArrayType(
2185 Builder.MetadataString.none, // Name
2186 Builder.Metadata.none, // File
2187 Builder.Metadata.none, // Scope
2186 .none, // Name
2187 .none, // File
2188 .none, // Scope
21882189 0, // Line
21892190 try o.lowerDebugType(ty.childType(mod)),
21902191 ty.abiSize(mod) * 8,
......@@ -2225,9 +2226,9 @@ pub const Object = struct {
22252226 };
22262227
22272228 const debug_vector_type = try o.builder.debugVectorType(
2228 Builder.MetadataString.none, // Name
2229 Builder.Metadata.none, // File
2230 Builder.Metadata.none, // Scope
2229 .none, // Name
2230 .none, // File
2231 .none, // Scope
22312232 0, // Line
22322233 debug_elem_type,
22332234 ty.abiSize(mod) * 8,
......@@ -2282,7 +2283,7 @@ pub const Object = struct {
22822283
22832284 const debug_data_type = try o.builder.debugMemberType(
22842285 try o.builder.metadataString("data"),
2285 Builder.Metadata.none, // File
2286 .none, // File
22862287 debug_fwd_ref,
22872288 0, // Line
22882289 try o.lowerDebugType(child_ty),
......@@ -2293,7 +2294,7 @@ pub const Object = struct {
22932294
22942295 const debug_some_type = try o.builder.debugMemberType(
22952296 try o.builder.metadataString("some"),
2296 Builder.Metadata.none,
2297 .none,
22972298 debug_fwd_ref,
22982299 0,
22992300 try o.lowerDebugType(non_null_ty),
......@@ -2304,10 +2305,10 @@ pub const Object = struct {
23042305
23052306 const debug_optional_type = try o.builder.debugStructType(
23062307 try o.builder.metadataString(name),
2307 Builder.Metadata.none, // File
2308 .none, // File
23082309 o.debug_compile_unit, // Scope
23092310 0, // Line
2310 Builder.Metadata.none, // Underlying type
2311 .none, // Underlying type
23112312 ty.abiSize(mod) * 8,
23122313 ty.abiAlignment(mod).toByteUnits(0) * 8,
23132314 try o.builder.debugTuple(&.{
......@@ -2362,7 +2363,7 @@ pub const Object = struct {
23622363 var fields: [2]Builder.Metadata = undefined;
23632364 fields[error_index] = try o.builder.debugMemberType(
23642365 try o.builder.metadataString("tag"),
2365 Builder.Metadata.none, // File
2366 .none, // File
23662367 debug_fwd_ref,
23672368 0, // Line
23682369 try o.lowerDebugType(Type.anyerror),
......@@ -2372,7 +2373,7 @@ pub const Object = struct {
23722373 );
23732374 fields[payload_index] = try o.builder.debugMemberType(
23742375 try o.builder.metadataString("value"),
2375 Builder.Metadata.none, // File
2376 .none, // File
23762377 debug_fwd_ref,
23772378 0, // Line
23782379 try o.lowerDebugType(payload_ty),
......@@ -2383,10 +2384,10 @@ pub const Object = struct {
23832384
23842385 const debug_error_union_type = try o.builder.debugStructType(
23852386 try o.builder.metadataString(name),
2386 Builder.Metadata.none, // File
2387 .none, // File
23872388 o.debug_compile_unit, // Sope
23882389 0, // Line
2389 Builder.Metadata.none, // Underlying type
2390 .none, // Underlying type
23902391 ty.abiSize(mod) * 8,
23912392 ty.abiAlignment(mod).toByteUnits(0) * 8,
23922393 try o.builder.debugTuple(&fields),
......@@ -2451,7 +2452,7 @@ pub const Object = struct {
24512452
24522453 fields.appendAssumeCapacity(try o.builder.debugMemberType(
24532454 try o.builder.metadataString(field_name),
2454 Builder.Metadata.none, // File
2455 .none, // File
24552456 debug_fwd_ref,
24562457 0,
24572458 try o.lowerDebugType(Type.fromInterned(field_ty)),
......@@ -2463,10 +2464,10 @@ pub const Object = struct {
24632464
24642465 const debug_struct_type = try o.builder.debugStructType(
24652466 try o.builder.metadataString(name),
2466 Builder.Metadata.none, // File
2467 .none, // File
24672468 o.debug_compile_unit, // Scope
24682469 0, // Line
2469 Builder.Metadata.none, // Underlying type
2470 .none, // Underlying type
24702471 ty.abiSize(mod) * 8,
24712472 ty.abiAlignment(mod).toByteUnits(0) * 8,
24722473 try o.builder.debugTuple(fields.items),
......@@ -2532,7 +2533,7 @@ pub const Object = struct {
25322533
25332534 fields.appendAssumeCapacity(try o.builder.debugMemberType(
25342535 try o.builder.metadataString(ip.stringToSlice(field_name)),
2535 Builder.Metadata.none, // File
2536 .none, // File
25362537 debug_fwd_ref,
25372538 0, // Line
25382539 try o.lowerDebugType(field_ty),
......@@ -2544,10 +2545,10 @@ pub const Object = struct {
25442545
25452546 const debug_struct_type = try o.builder.debugStructType(
25462547 try o.builder.metadataString(name),
2547 Builder.Metadata.none, // File
2548 .none, // File
25482549 o.debug_compile_unit, // Scope
25492550 0, // Line
2550 Builder.Metadata.none, // Underlying type
2551 .none, // Underlying type
25512552 ty.abiSize(mod) * 8,
25522553 ty.abiAlignment(mod).toByteUnits(0) * 8,
25532554 try o.builder.debugTuple(fields.items),
......@@ -2585,10 +2586,10 @@ pub const Object = struct {
25852586 if (layout.payload_size == 0) {
25862587 const debug_union_type = try o.builder.debugStructType(
25872588 try o.builder.metadataString(name),
2588 Builder.Metadata.none, // File
2589 .none, // File
25892590 o.debug_compile_unit, // Scope
25902591 0, // Line
2591 Builder.Metadata.none, // Underlying type
2592 .none, // Underlying type
25922593 ty.abiSize(mod) * 8,
25932594 ty.abiAlignment(mod).toByteUnits(0) * 8,
25942595 try o.builder.debugTuple(
......@@ -2623,7 +2624,7 @@ pub const Object = struct {
26232624 const field_name = union_obj.field_names.get(ip)[field_index];
26242625 fields.appendAssumeCapacity(try o.builder.debugMemberType(
26252626 try o.builder.metadataString(ip.stringToSlice(field_name)),
2626 Builder.Metadata.none, // File
2627 .none, // File
26272628 debug_union_fwd_ref,
26282629 0, // Line
26292630 try o.lowerDebugType(Type.fromInterned(field_ty)),
......@@ -2642,10 +2643,10 @@ pub const Object = struct {
26422643
26432644 const debug_union_type = try o.builder.debugUnionType(
26442645 try o.builder.metadataString(union_name),
2645 Builder.Metadata.none, // File
2646 .none, // File
26462647 o.debug_compile_unit, // Scope
26472648 0, // Line
2648 Builder.Metadata.none, // Underlying type
2649 .none, // Underlying type
26492650 ty.abiSize(mod) * 8,
26502651 ty.abiAlignment(mod).toByteUnits(0) * 8,
26512652 try o.builder.debugTuple(fields.items),
......@@ -2673,7 +2674,7 @@ pub const Object = struct {
26732674
26742675 const debug_tag_type = try o.builder.debugMemberType(
26752676 try o.builder.metadataString("tag"),
2676 Builder.Metadata.none, // File
2677 .none, // File
26772678 debug_fwd_ref,
26782679 0, // Line
26792680 try o.lowerDebugType(Type.fromInterned(union_obj.enum_tag_ty)),
......@@ -2684,7 +2685,7 @@ pub const Object = struct {
26842685
26852686 const debug_payload_type = try o.builder.debugMemberType(
26862687 try o.builder.metadataString("payload"),
2687 Builder.Metadata.none, // File
2688 .none, // File
26882689 debug_fwd_ref,
26892690 0, // Line
26902691 debug_union_type,
......@@ -2701,10 +2702,10 @@ pub const Object = struct {
27012702
27022703 const debug_tagged_union_type = try o.builder.debugStructType(
27032704 try o.builder.metadataString(name),
2704 Builder.Metadata.none, // File
2705 .none, // File
27052706 o.debug_compile_unit, // Scope
27062707 0, // Line
2707 Builder.Metadata.none, // Underlying type
2708 .none, // Underlying type
27082709 ty.abiSize(mod) * 8,
27092710 ty.abiAlignment(mod).toByteUnits(0) * 8,
27102711 try o.builder.debugTuple(&full_fields),
......@@ -2798,7 +2799,7 @@ pub const Object = struct {
27982799 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),
27992800 try o.namespaceToDebugScope(decl.src_namespace),
28002801 decl.src_line + 1,
2801 Builder.Metadata.none,
2802 .none,
28022803 0,
28032804 0,
28042805 .none,
......@@ -4715,7 +4716,8 @@ pub const DeclGen = struct {
47154716 debug_global_var,
47164717 debug_expression,
47174718 );
4718
4719 if (!is_internal_linkage or decl.isExtern(mod))
4720 variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder);
47194721 try o.debug_globals.append(o.gpa, debug_global_var_expression);
47204722 }
47214723 }
......@@ -4729,8 +4731,7 @@ pub const FuncGen = struct {
47294731 wip: Builder.WipFunction,
47304732
47314733 file: Builder.Metadata,
4732 subprogram: Builder.Metadata,
4733 current_scope: Builder.Metadata,
4734 scope: Builder.Metadata,
47344735
47354736 inlined: std.ArrayListUnmanaged(struct {
47364737 base_line: u32,
......@@ -6557,20 +6558,20 @@ pub const FuncGen = struct {
65576558 const inlined_at = if (self.inlined.items.len > 0)
65586559 self.inlined.items[self.inlined.items.len - 1].location
65596560 else
6560 Builder.Metadata.none;
6561 .none;
65616562
6562 self.wip.current_debug_location = .{
6563 .line = self.prev_dbg_line,
6564 .column = self.prev_dbg_column,
6565 .scope = self.current_scope,
6566 .inlined_at = inlined_at,
6567 };
6563 self.wip.current_debug_location = try self.wip.builder.debugLocation(
6564 self.prev_dbg_line,
6565 self.prev_dbg_column,
6566 self.scope,
6567 inlined_at,
6568 );
65686569
65696570 return .none;
65706571 }
65716572
65726573 fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6573 if (self.wip.builder.strip or true) return .none;
6574 if (self.wip.builder.strip) return .none;
65746575 const o = self.dg.object;
65756576 const zcu = o.module;
65766577
......@@ -6585,13 +6586,8 @@ pub const FuncGen = struct {
65856586
65866587 const line_number = decl.src_line + 1;
65876588 try self.inlined.append(self.gpa, .{
6588 .location = if (self.wip.current_debug_location) |location| try self.wip.builder.debugLocation(
6589 location.scope,
6590 location.line,
6591 location.column,
6592 location.inlined_at,
6593 ) else .none,
6594 .scope = self.current_scope,
6589 .location = self.wip.current_debug_location,
6590 .scope = self.scope,
65956591 .base_line = self.base_line,
65966592 });
65976593
......@@ -6605,16 +6601,18 @@ pub const FuncGen = struct {
66056601
66066602 const subprogram = try o.builder.debugSubprogram(
66076603 self.file,
6608 try o.builder.string(zcu.intern_pool.stringToSlice(decl.name)),
6609 try o.builder.string(zcu.intern_pool.stringToSlice(fqn)),
6604 try o.builder.metadataString(zcu.intern_pool.stringToSlice(decl.name)),
6605 try o.builder.metadataString(zcu.intern_pool.stringToSlice(fqn)),
66106606 line_number,
66116607 line_number + func.lbrace_line,
66126608 try o.lowerDebugType(fn_ty),
66136609 .{
6614 .optimized = owner_mod.optimize_mode != .Debug,
6615 .local = is_internal_linkage,
6616 .definition = true,
6617 .debug_info_flags = Builder.DIFlags.StaticMember,
6610 .di_flags = .{ .StaticMember = true },
6611 .sp_flags = .{
6612 .Optimized = owner_mod.optimize_mode != .Debug,
6613 .Definition = true,
6614 .LocalToUnit = is_internal_linkage,
6615 },
66186616 },
66196617 o.debug_compile_unit,
66206618 );
......@@ -6625,13 +6623,13 @@ pub const FuncGen = struct {
66256623 line_number,
66266624 1,
66276625 );
6628 self.current_scope = lexical_block;
6626 self.scope = lexical_block;
66296627 self.base_line = decl.src_line;
66306628 return .none;
66316629 }
66326630
66336631 fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
6634 if (self.wip.builder.strip or true) return .none;
6632 if (self.wip.builder.strip) return .none;
66356633 const o = self.dg.object;
66366634
66376635 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
......@@ -6641,7 +6639,7 @@ pub const FuncGen = struct {
66416639 self.file = try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope);
66426640
66436641 const old = self.inlined.pop();
6644 self.current_scope = old.scope;
6642 self.scope = old.scope;
66456643 self.base_line = old.base_line;
66466644 return .none;
66476645 }
......@@ -6650,12 +6648,12 @@ pub const FuncGen = struct {
66506648 if (self.wip.builder.strip) return .none;
66516649 const o = self.dg.object;
66526650
6653 try self.scope_stack.append(self.gpa, self.current_scope);
6651 try self.scope_stack.append(self.gpa, self.scope);
66546652
6655 const old = self.current_scope;
6656 self.current_scope = try o.builder.debugLexicalBlock(
6657 self.file,
6653 const old = self.scope;
6654 self.scope = try o.builder.debugLexicalBlock(
66586655 old,
6656 self.file,
66596657 self.prev_dbg_line,
66606658 self.prev_dbg_column,
66616659 );
......@@ -6664,7 +6662,7 @@ pub const FuncGen = struct {
66646662
66656663 fn airDbgBlockEnd(self: *FuncGen) !Builder.Value {
66666664 if (self.wip.builder.strip) return .none;
6667 self.current_scope = self.scope_stack.pop();
6665 self.scope = self.scope_stack.pop();
66686666 return .none;
66696667 }
66706668
......@@ -6680,7 +6678,7 @@ pub const FuncGen = struct {
66806678 const debug_local_var = try o.builder.debugLocalVar(
66816679 try o.builder.metadataString(name),
66826680 self.file,
6683 self.current_scope,
6681 self.scope,
66846682 self.prev_dbg_line,
66856683 try o.lowerDebugType(ptr_ty.childType(mod)),
66866684 );
......@@ -6714,7 +6712,7 @@ pub const FuncGen = struct {
67146712 const debug_local_var = try o.builder.debugLocalVar(
67156713 try o.builder.metadataString(name),
67166714 self.file,
6717 self.current_scope,
6715 self.scope,
67186716 self.prev_dbg_line,
67196717 try o.lowerDebugType(operand_ty),
67206718 );
......@@ -8798,19 +8796,19 @@ pub const FuncGen = struct {
87988796 const debug_parameter = try o.builder.debugParameter(
87998797 try o.builder.metadataString(mod.getParamName(func_index, src_index)),
88008798 self.file,
8801 self.current_scope,
8799 self.scope,
88028800 lbrace_line,
88038801 try o.lowerDebugType(inst_ty),
88048802 @intCast(self.arg_index),
88058803 );
88068804
88078805 const old_location = self.wip.current_debug_location;
8808 self.wip.current_debug_location = .{
8809 .line = lbrace_line,
8810 .column = lbrace_col,
8811 .scope = self.current_scope,
8812 .inlined_at = Builder.Metadata.none,
8813 };
8806 self.wip.current_debug_location = try o.builder.debugLocation(
8807 lbrace_line,
8808 lbrace_col,
8809 self.scope,
8810 .none,
8811 );
88148812
88158813 const owner_mod = self.dg.ownerModule();
88168814 if (isByRef(inst_ty, mod)) {
......@@ -11718,7 +11716,7 @@ fn buildAllocaInner(
1171811716 }
1171911717
1172011718 wip.cursor = .{ .block = .entry };
11721 wip.current_debug_location = null;
11719 wip.current_debug_location = .none;
1172211720 break :blk try wip.alloca(.normal, llvm_ty, .none, alignment, address_space, "");
1172311721 };
1172411722
src/codegen/llvm/Builder.zig+1145-431
......@@ -77,11 +77,11 @@ pub const String = enum(u32) {
7777 return self.toIndex() == null;
7878 }
7979
80 pub fn slice(self: String, b: *const Builder) ?[:0]const u8 {
80 pub fn slice(self: String, builder: *const Builder) ?[:0]const u8 {
8181 const index = self.toIndex() orelse return null;
82 const start = b.string_indices.items[index];
83 const end = b.string_indices.items[index + 1];
84 return b.string_bytes.items[start .. end - 1 :0];
82 const start = builder.string_indices.items[index];
83 const end = builder.string_indices.items[index + 1];
84 return builder.string_bytes.items[start .. end - 1 :0];
8585 }
8686
8787 const FormatData = struct {
......@@ -1124,7 +1124,8 @@ pub const Attribute = union(Kind) {
11241124 u32 => storage.value,
11251125 Alignment, String, Type, UwTable => @enumFromInt(storage.value),
11261126 AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(storage.value),
1127 else => @compileError("bad payload type: " ++ @typeName(field.type)),
1127 else => @compileError("bad payload type: " ++ field.name ++ ": " ++
1128 @typeName(field.type)),
11281129 });
11291130 },
11301131 .string, .none => unreachable,
......@@ -1550,12 +1551,12 @@ pub const Attribute = union(Kind) {
15501551
15511552 fn toStorage(self: Attribute) Storage {
15521553 return switch (self) {
1553 inline else => |value| .{ .kind = @as(Kind, self), .value = switch (@TypeOf(value)) {
1554 inline else => |value, tag| .{ .kind = @as(Kind, self), .value = switch (@TypeOf(value)) {
15541555 void => 0,
15551556 u32 => value,
15561557 Alignment, String, Type, UwTable => @intFromEnum(value),
15571558 AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(value),
1558 else => @compileError("bad payload type: " ++ @typeName(@TypeOf(value))),
1559 else => @compileError("bad payload type: " ++ @tagName(tag) ++ @typeName(@TypeOf(value))),
15591560 } },
15601561 .string => |string_attr| .{
15611562 .kind = Kind.fromString(string_attr.kind),
......@@ -2130,6 +2131,7 @@ pub const Global = struct {
21302131 externally_initialized: ExternallyInitialized = .default,
21312132 type: Type,
21322133 partition: String = .none,
2134 dbg: Metadata = .none,
21332135 kind: union(enum) {
21342136 alias: Alias.Index,
21352137 variable: Variable.Index,
......@@ -2204,6 +2206,10 @@ pub const Global = struct {
22042206 self.ptr(builder).unnamed_addr = unnamed_addr;
22052207 }
22062208
2209 pub fn setDebugMetadata(self: Index, dbg: Metadata, builder: *Builder) void {
2210 self.ptr(builder).dbg = dbg;
2211 }
2212
22072213 const FormatData = struct {
22082214 global: Index,
22092215 builder: *const Builder,
......@@ -2425,6 +2431,10 @@ pub const Variable = struct {
24252431 pub fn getAlignment(self: Index, builder: *Builder) Alignment {
24262432 return self.ptr(builder).alignment;
24272433 }
2434
2435 pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void {
2436 self.ptrConst(builder).global.setDebugMetadata(expression, builder);
2437 }
24282438 };
24292439};
24302440
......@@ -3772,8 +3782,7 @@ pub const Function = struct {
37723782 instructions: std.MultiArrayList(Instruction) = .{},
37733783 names: [*]const String = &[0]String{},
37743784 value_indices: [*]const u32 = &[0]u32{},
3775 metadata: ?[*]const Metadata = null,
3776 debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, ?DebugLocation) = .{},
3785 debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{},
37773786 debug_values: []const Instruction.Index = &.{},
37783787 extra: []const u32 = &.{},
37793788
......@@ -3836,6 +3845,10 @@ pub const Function = struct {
38363845 pub fn setAlignment(self: Index, alignment: Alignment, builder: *Builder) void {
38373846 self.ptr(builder).alignment = alignment;
38383847 }
3848
3849 pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void {
3850 self.ptrConst(builder).global.setDebugMetadata(subprogram, builder);
3851 }
38393852 };
38403853
38413854 pub const Block = struct {
......@@ -4823,7 +4836,7 @@ pub const Function = struct {
48234836 Instruction.Alloca.Info,
48244837 Instruction.Call.Info,
48254838 => @bitCast(value),
4826 else => @compileError("bad field type: " ++ @typeName(field.type)),
4839 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
48274840 };
48284841 return .{
48294842 .data = result,
......@@ -4836,61 +4849,16 @@ pub const Function = struct {
48364849 }
48374850};
48384851
4839pub const DebugLocation = struct {
4840 line: u32,
4841 column: u32,
4842 scope: Metadata,
4843 inlined_at: Metadata,
4844};
4845
4846pub const DIFlags = opaque {
4847 pub const Zero = 0;
4848 pub const Private = 1;
4849 pub const Protected = 2;
4850 pub const Public = 3;
4851
4852 pub const FwdDecl = 1 << 2;
4853 pub const AppleBlock = 1 << 3;
4854 pub const BlockByrefStruct = 1 << 4;
4855 pub const Virtual = 1 << 5;
4856 pub const Artificial = 1 << 6;
4857 pub const Explicit = 1 << 7;
4858 pub const Prototyped = 1 << 8;
4859 pub const ObjcClassComplete = 1 << 9;
4860 pub const ObjectPointer = 1 << 10;
4861 pub const Vector = 1 << 11;
4862 pub const StaticMember = 1 << 12;
4863 pub const LValueReference = 1 << 13;
4864 pub const RValueReference = 1 << 14;
4865 pub const Reserved = 1 << 15;
4866
4867 pub const SingleInheritance = 1 << 16;
4868 pub const MultipleInheritance = 2 << 16;
4869 pub const VirtualInheritance = 3 << 16;
4870
4871 pub const IntroducedVirtual = 1 << 18;
4872 pub const BitField = 1 << 19;
4873 pub const NoReturn = 1 << 20;
4874 pub const TypePassByValue = 1 << 22;
4875 pub const TypePassByReference = 1 << 23;
4876 pub const EnumClass = 1 << 24;
4877 pub const Thunk = 1 << 25;
4878 pub const NonTrivial = 1 << 26;
4879 pub const BigEndian = 1 << 27;
4880 pub const LittleEndian = 1 << 28;
4881 pub const AllCallsDescribed = 1 << 29;
4882};
4883
48844852pub const WipFunction = struct {
48854853 builder: *Builder,
48864854 function: Function.Index,
4887 last_debug_location: ?DebugLocation,
4888 current_debug_location: ?DebugLocation,
4855 last_debug_location: Metadata,
4856 current_debug_location: Metadata,
48894857 cursor: Cursor,
48904858 blocks: std.ArrayListUnmanaged(Block),
48914859 instructions: std.MultiArrayList(Instruction),
48924860 names: std.ArrayListUnmanaged(String),
4893 debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, ?DebugLocation),
4861 debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, Metadata),
48944862 debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void),
48954863 extra: std.ArrayListUnmanaged(u32),
48964864
......@@ -4923,9 +4891,11 @@ pub const WipFunction = struct {
49234891 pub const Instruction = Function.Instruction;
49244892
49254893 pub fn init(builder: *Builder, function: Function.Index) Allocator.Error!WipFunction {
4926 var self = WipFunction{
4894 var self: WipFunction = .{
49274895 .builder = builder,
49284896 .function = function,
4897 .last_debug_location = .none,
4898 .current_debug_location = .none,
49294899 .cursor = undefined,
49304900 .blocks = .{},
49314901 .instructions = .{},
......@@ -4933,8 +4903,6 @@ pub const WipFunction = struct {
49334903 .debug_locations = .{},
49344904 .debug_values = .{},
49354905 .extra = .{},
4936 .current_debug_location = null,
4937 .last_debug_location = null,
49384906 };
49394907 errdefer self.deinit();
49404908
......@@ -5874,7 +5842,7 @@ pub const WipFunction = struct {
58745842 const value_indices = try gpa.alloc(u32, final_instructions_len);
58755843 errdefer gpa.free(value_indices);
58765844
5877 var debug_locations = std.AutoHashMapUnmanaged(Instruction.Index, ?DebugLocation){};
5845 var debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{};
58785846 errdefer debug_locations.deinit(gpa);
58795847 try debug_locations.ensureUnusedCapacity(gpa, @intCast(self.debug_locations.count()));
58805848
......@@ -5902,7 +5870,7 @@ pub const WipFunction = struct {
59025870 Instruction.Alloca.Info,
59035871 Instruction.Call.Info,
59045872 => @bitCast(value),
5905 else => @compileError("bad field type: " ++ @typeName(field.type)),
5873 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
59065874 };
59075875 wip_extra.index += 1;
59085876 }
......@@ -6472,13 +6440,7 @@ pub const WipFunction = struct {
64726440 try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1);
64736441 if (!self.builder.strip) {
64746442 try self.names.ensureUnusedCapacity(self.builder.gpa, 1);
6475 if (!std.mem.eql(
6476 u8,
6477 std.mem.asBytes(&self.current_debug_location),
6478 std.mem.asBytes(&self.last_debug_location),
6479 )) {
6480 try self.debug_locations.ensureUnusedCapacity(self.builder.gpa, 1);
6481 }
6443 try self.debug_locations.ensureUnusedCapacity(self.builder.gpa, 1);
64826444 }
64836445 try block_instructions.ensureUnusedCapacity(self.builder.gpa, 1);
64846446 const final_name = if (name) |n|
......@@ -6490,11 +6452,7 @@ pub const WipFunction = struct {
64906452 self.instructions.appendAssumeCapacity(instruction);
64916453 if (!self.builder.strip) {
64926454 self.names.appendAssumeCapacity(final_name);
6493 if (!std.mem.eql(
6494 u8,
6495 std.mem.asBytes(&self.current_debug_location),
6496 std.mem.asBytes(&self.last_debug_location),
6497 )) {
6455 if (!std.meta.eql(self.current_debug_location, self.last_debug_location)) {
64986456 self.debug_locations.putAssumeCapacity(index, self.current_debug_location);
64996457 self.last_debug_location = self.current_debug_location;
65006458 }
......@@ -6521,7 +6479,7 @@ pub const WipFunction = struct {
65216479 Instruction.Alloca.Info,
65226480 Instruction.Call.Info,
65236481 => @bitCast(value),
6524 else => @compileError("bad field type: " ++ @typeName(field.type)),
6482 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
65256483 });
65266484 }
65276485 return result;
......@@ -6569,7 +6527,7 @@ pub const WipFunction = struct {
65696527 Instruction.Alloca.Info,
65706528 Instruction.Call.Info,
65716529 => @bitCast(value),
6572 else => @compileError("bad field type: " ++ @typeName(field.type)),
6530 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
65736531 };
65746532 return .{
65756533 .data = result,
......@@ -7194,7 +7152,7 @@ pub const Constant = enum(u32) {
71947152 @ptrCast(data.builder.constant_limbs.items[item.data..][0..Integer.limbs]);
71957153 const limbs = data.builder.constant_limbs
71967154 .items[item.data + Integer.limbs ..][0..extra.limbs_len];
7197 const bigint = std.math.big.int.Const{
7155 const bigint: std.math.big.int.Const = .{
71987156 .limbs = limbs,
71997157 .positive = tag == .positive_integer,
72007158 };
......@@ -7507,7 +7465,7 @@ pub const Value = enum(u32) {
75077465 return switch (self.unwrap()) {
75087466 .instruction => |instruction| instruction.typeOfWip(wip),
75097467 .constant => |constant| constant.typeOf(wip.builder),
7510 .metadata => Type.metadata,
7468 .metadata => .metadata,
75117469 };
75127470 }
75137471
......@@ -7515,7 +7473,7 @@ pub const Value = enum(u32) {
75157473 return switch (self.unwrap()) {
75167474 .instruction => |instruction| instruction.typeOf(function, builder),
75177475 .constant => |constant| constant.typeOf(builder),
7518 .metadata => Type.metadata,
7476 .metadata => .metadata,
75197477 };
75207478 }
75217479
......@@ -7559,11 +7517,11 @@ pub const MetadataString = enum(u32) {
75597517 none = 0,
75607518 _,
75617519
7562 pub fn slice(self: MetadataString, b: *const Builder) []const u8 {
7520 pub fn slice(self: MetadataString, builder: *const Builder) []const u8 {
75637521 const index = @intFromEnum(self);
7564 const start = b.metadata_string_indices.items[index];
7565 const end = b.metadata_string_indices.items[index + 1];
7566 return b.metadata_string_bytes.items[start..end];
7522 const start = builder.metadata_string_indices.items[index];
7523 const end = builder.metadata_string_indices.items[index + 1];
7524 return builder.metadata_string_bytes.items[start..end];
75677525 }
75687526
75697527 const Adapter = struct {
......@@ -7576,6 +7534,22 @@ pub const MetadataString = enum(u32) {
75767534 return std.mem.eql(u8, lhs_key, rhs_metadata_string.slice(ctx.builder));
75777535 }
75787536 };
7537
7538 const FormatData = struct {
7539 metadata_string: MetadataString,
7540 builder: *const Builder,
7541 };
7542 fn format(
7543 data: FormatData,
7544 comptime _: []const u8,
7545 _: std.fmt.FormatOptions,
7546 writer: anytype,
7547 ) @TypeOf(writer).Error!void {
7548 try printEscapedString(data.metadata_string.slice(data.builder), .always_quote, writer);
7549 }
7550 fn fmt(self: MetadataString, builder: *const Builder) std.fmt.Formatter(format) {
7551 return .{ .data = .{ .metadata_string = self, .builder = builder } };
7552 }
75797553};
75807554
75817555pub const Metadata = enum(u32) {
......@@ -7591,13 +7565,13 @@ pub const Metadata = enum(u32) {
75917565 compile_unit,
75927566 @"compile_unit optimized",
75937567 subprogram,
7594 @"subprogram optimized",
75957568 @"subprogram local",
75967569 @"subprogram definition",
7570 @"subprogram local definition",
7571 @"subprogram optimized",
75977572 @"subprogram optimized local",
75987573 @"subprogram optimized definition",
75997574 @"subprogram optimized local definition",
7600 @"subprogram local definition",
76017575 lexical_block,
76027576 location,
76037577 basic_bool_type,
......@@ -7625,18 +7599,66 @@ pub const Metadata = enum(u32) {
76257599 @"global_var local",
76267600 global_var_expression,
76277601 constant,
7602
7603 pub fn isInline(tag: Tag) bool {
7604 return switch (tag) {
7605 .none,
7606 .tuple,
7607 .expression,
7608 .constant,
7609 => true,
7610 .file,
7611 .compile_unit,
7612 .@"compile_unit optimized",
7613 .subprogram,
7614 .@"subprogram local",
7615 .@"subprogram definition",
7616 .@"subprogram local definition",
7617 .@"subprogram optimized",
7618 .@"subprogram optimized local",
7619 .@"subprogram optimized definition",
7620 .@"subprogram optimized local definition",
7621 .lexical_block,
7622 .location,
7623 .basic_bool_type,
7624 .basic_unsigned_type,
7625 .basic_signed_type,
7626 .basic_float_type,
7627 .composite_struct_type,
7628 .composite_union_type,
7629 .composite_enumeration_type,
7630 .composite_array_type,
7631 .composite_vector_type,
7632 .derived_pointer_type,
7633 .derived_member_type,
7634 .subroutine_type,
7635 .enumerator_unsigned,
7636 .enumerator_signed_positive,
7637 .enumerator_signed_negative,
7638 .subrange,
7639 .module_flag,
7640 .local_var,
7641 .parameter,
7642 .global_var,
7643 .@"global_var local",
7644 .global_var_expression,
7645 => false,
7646 };
7647 }
76287648 };
76297649
7650 pub fn isInline(self: Metadata, builder: *const Builder) bool {
7651 return builder.metadata_items.items(.tag)[@intFromEnum(self)].isInline();
7652 }
7653
76307654 pub fn unwrap(self: Metadata, builder: *const Builder) Metadata {
76317655 var metadata = self;
7632 var count: usize = 0;
76337656 while (@intFromEnum(metadata) >= Metadata.first_forward_reference and
76347657 @intFromEnum(metadata) < Metadata.first_local_metadata)
76357658 {
76367659 const index = @intFromEnum(metadata) - Metadata.first_forward_reference;
76377660 metadata = builder.metadata_forward_references.items[index];
76387661 std.debug.assert(metadata != .none);
7639 count += 1;
76407662 }
76417663 return metadata;
76427664 }
......@@ -7648,13 +7670,75 @@ pub const Metadata = enum(u32) {
76487670 const ExtraIndex = u32;
76497671 };
76507672
7673 pub const DIFlags = packed struct(u32) {
7674 Visibility: enum(u2) { Zero, Private, Protected, Public } = .Zero,
7675 FwdDecl: bool = false,
7676 AppleBlock: bool = false,
7677 ReservedBit4: u1 = 0,
7678 Virtual: bool = false,
7679 Artificial: bool = false,
7680 Explicit: bool = false,
7681 Prototyped: bool = false,
7682 ObjcClassComplete: bool = false,
7683 ObjectPointer: bool = false,
7684 Vector: bool = false,
7685 StaticMember: bool = false,
7686 LValueReference: bool = false,
7687 RValueReference: bool = false,
7688 ExportSymbols: bool = false,
7689 Inheritance: enum(u2) {
7690 Zero,
7691 SingleInheritance,
7692 MultipleInheritance,
7693 VirtualInheritance,
7694 } = .Zero,
7695 IntroducedVirtual: bool = false,
7696 BitField: bool = false,
7697 NoReturn: bool = false,
7698 ReservedBit21: u1 = 0,
7699 TypePassbyValue: bool = false,
7700 TypePassbyReference: bool = false,
7701 EnumClass: bool = false,
7702 Thunk: bool = false,
7703 NonTrivial: bool = false,
7704 BigEndian: bool = false,
7705 LittleEndian: bool = false,
7706 AllCallsDescribed: bool = false,
7707 Unused: u2 = 0,
7708
7709 pub fn format(
7710 self: DIFlags,
7711 comptime _: []const u8,
7712 _: std.fmt.FormatOptions,
7713 writer: anytype,
7714 ) @TypeOf(writer).Error!void {
7715 var need_pipe = false;
7716 inline for (@typeInfo(DIFlags).Struct.fields) |field| {
7717 switch (@typeInfo(field.type)) {
7718 .Bool => if (@field(self, field.name)) {
7719 if (need_pipe) try writer.writeAll(" | ") else need_pipe = true;
7720 try writer.print("DIFlag{s}", .{field.name});
7721 },
7722 .Enum => if (@field(self, field.name) != .Zero) {
7723 if (need_pipe) try writer.writeAll(" | ") else need_pipe = true;
7724 try writer.print("DIFlag{s}", .{@tagName(@field(self, field.name))});
7725 },
7726 .Int => assert(@field(self, field.name) == 0),
7727 else => @compileError("bad field type: " ++ field.name ++ ": " ++
7728 @typeName(field.type)),
7729 }
7730 }
7731 if (!need_pipe) try writer.writeByte('0');
7732 }
7733 };
7734
76517735 pub const File = struct {
7652 path: MetadataString,
7653 name: MetadataString,
7736 filename: MetadataString,
7737 directory: MetadataString,
76547738 };
76557739
76567740 pub const CompileUnit = struct {
7657 pub const Flags = struct {
7741 pub const Options = struct {
76587742 optimized: bool,
76597743 };
76607744
......@@ -7665,11 +7749,49 @@ pub const Metadata = enum(u32) {
76657749 };
76667750
76677751 pub const Subprogram = struct {
7668 pub const Flags = struct {
7669 optimized: bool,
7670 local: bool,
7671 definition: bool,
7672 debug_info_flags: u32,
7752 pub const Options = struct {
7753 di_flags: DIFlags,
7754 sp_flags: SPFlags,
7755 };
7756
7757 pub const SPFlags = packed struct(u32) {
7758 Virtuality: enum(u2) { Zero, Virtual, PureVirtual } = .Zero,
7759 LocalToUnit: bool = false,
7760 Definition: bool = false,
7761 Optimized: bool = false,
7762 Pure: bool = false,
7763 Elemental: bool = false,
7764 Recursive: bool = false,
7765 MainSubprogram: bool = false,
7766 Deleted: bool = false,
7767 ReservedBit10: u1 = 0,
7768 ObjCDirect: bool = false,
7769 Unused: u20 = 0,
7770
7771 pub fn format(
7772 self: SPFlags,
7773 comptime _: []const u8,
7774 _: std.fmt.FormatOptions,
7775 writer: anytype,
7776 ) @TypeOf(writer).Error!void {
7777 var need_pipe = false;
7778 inline for (@typeInfo(SPFlags).Struct.fields) |field| {
7779 switch (@typeInfo(field.type)) {
7780 .Bool => if (@field(self, field.name)) {
7781 if (need_pipe) try writer.writeAll(" | ") else need_pipe = true;
7782 try writer.print("SPFlag{s}", .{field.name});
7783 },
7784 .Enum => if (@field(self, field.name) != .Zero) {
7785 if (need_pipe) try writer.writeAll(" | ") else need_pipe = true;
7786 try writer.print("SPFlag{s}", .{@tagName(@field(self, field.name))});
7787 },
7788 .Int => assert(@field(self, field.name) == 0),
7789 else => @compileError("bad field type: " ++ field.name ++ ": " ++
7790 @typeName(field.type)),
7791 }
7792 }
7793 if (!need_pipe) try writer.writeByte('0');
7794 }
76737795 };
76747796
76757797 file: Metadata,
......@@ -7678,21 +7800,21 @@ pub const Metadata = enum(u32) {
76787800 line: u32,
76797801 scope_line: u32,
76807802 ty: Metadata,
7681 debug_info_flags: u32,
7803 di_flags: DIFlags,
76827804 compile_unit: Metadata,
76837805 };
76847806
76857807 pub const LexicalBlock = struct {
7686 file: Metadata,
76877808 scope: Metadata,
7809 file: Metadata,
76887810 line: u32,
76897811 column: u32,
76907812 };
76917813
76927814 pub const Location = struct {
7693 scope: Metadata,
76947815 line: u32,
76957816 column: u32,
7817 scope: Metadata,
76967818 inlined_at: Metadata,
76977819 };
76987820
......@@ -7700,6 +7822,10 @@ pub const Metadata = enum(u32) {
77007822 name: MetadataString,
77017823 size_in_bits_lo: u32,
77027824 size_in_bits_hi: u32,
7825
7826 pub fn bitSize(self: BasicType) u64 {
7827 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
7828 }
77037829 };
77047830
77057831 pub const CompositeType = struct {
......@@ -7713,6 +7839,13 @@ pub const Metadata = enum(u32) {
77137839 align_in_bits_lo: u32,
77147840 align_in_bits_hi: u32,
77157841 fields_tuple: Metadata,
7842
7843 pub fn bitSize(self: CompositeType) u64 {
7844 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
7845 }
7846 pub fn bitAlign(self: CompositeType) u64 {
7847 return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;
7848 }
77167849 };
77177850
77187851 pub const DerivedType = struct {
......@@ -7727,6 +7860,16 @@ pub const Metadata = enum(u32) {
77277860 align_in_bits_hi: u32,
77287861 offset_in_bits_lo: u32,
77297862 offset_in_bits_hi: u32,
7863
7864 pub fn bitSize(self: DerivedType) u64 {
7865 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
7866 }
7867 pub fn bitAlign(self: DerivedType) u64 {
7868 return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;
7869 }
7870 pub fn bitOffset(self: DerivedType) u64 {
7871 return @as(u64, self.offset_in_bits_hi) << 32 | self.offset_in_bits_lo;
7872 }
77307873 };
77317874
77327875 pub const SubroutineType = struct {
......@@ -7758,7 +7901,7 @@ pub const Metadata = enum(u32) {
77587901 };
77597902
77607903 pub const ModuleFlag = struct {
7761 behaviour: Metadata,
7904 behavior: Metadata,
77627905 name: MetadataString,
77637906 constant: Metadata,
77647907 };
......@@ -7781,7 +7924,7 @@ pub const Metadata = enum(u32) {
77817924 };
77827925
77837926 pub const GlobalVar = struct {
7784 pub const Flags = struct {
7927 pub const Options = struct {
77857928 local: bool,
77867929 };
77877930
......@@ -7802,13 +7945,276 @@ pub const Metadata = enum(u32) {
78027945 pub fn toValue(self: Metadata) Value {
78037946 return @enumFromInt(Value.first_metadata + @intFromEnum(self));
78047947 }
7805};
78067948
7807pub const InitError = error{
7808 InvalidLlvmTriple,
7809} || Allocator.Error;
7949 const Formatter = struct {
7950 builder: *Builder,
7951 need_comma: bool,
7952 map: std.AutoArrayHashMapUnmanaged(Metadata, void) = .{},
7953
7954 fn unwrapAssumeExists(formatter: *Formatter, item: Metadata) FormatData.Item {
7955 if (item == .none) return .none;
7956 const unwrapped_metadata = item.unwrap(formatter.builder);
7957 const tag = formatter.builder.metadata_items.items(.tag)[@intFromEnum(unwrapped_metadata)];
7958 return if (tag.isInline())
7959 .{ .@"inline" = unwrapped_metadata }
7960 else
7961 .{ .index = @intCast(formatter.map.getIndex(unwrapped_metadata).?) };
7962 }
7963 fn unwrap(formatter: *Formatter, item: Metadata) Allocator.Error!FormatData.Item {
7964 if (item == .none) return .none;
7965 const builder = formatter.builder;
7966 const unwrapped_metadata = item.unwrap(builder);
7967 const tag = formatter.builder.metadata_items.items(.tag)[@intFromEnum(unwrapped_metadata)];
7968 switch (tag) {
7969 .none => unreachable,
7970 .tuple => {
7971 var extra = builder.metadataExtraDataTrail(
7972 Metadata.Tuple,
7973 builder.metadata_items.items(.data)[@intFromEnum(unwrapped_metadata)],
7974 );
7975 const elements = extra.trail.next(extra.data.elements_len, Metadata, builder);
7976 for (elements) |element| _ = try formatter.unwrap(element);
7977 },
7978 .expression, .constant => {},
7979 else => {
7980 assert(!tag.isInline());
7981 const gop = try formatter.map.getOrPutValue(builder.gpa, unwrapped_metadata, {});
7982 return .{ .index = @intCast(gop.index) };
7983 },
7984 }
7985 return .{ .@"inline" = unwrapped_metadata };
7986 }
78107987
7811pub fn init(options: Options) InitError!Builder {
7988 const FormatData = struct {
7989 formatter: *Formatter,
7990 prefix: []const u8 = "",
7991 item: FormatData.Item,
7992
7993 const Item = union(enum) {
7994 none,
7995 @"inline": Metadata,
7996 index: u32,
7997 string: MetadataString,
7998 value: struct {
7999 value: Value,
8000 function: Function.Index,
8001 },
8002 bool: bool,
8003 u32: u32,
8004 u64: u64,
8005 raw: []const u8,
8006 };
8007 };
8008 fn format(
8009 data: FormatData,
8010 comptime fmt_str: []const u8,
8011 fmt_opts: std.fmt.FormatOptions,
8012 writer: anytype,
8013 ) @TypeOf(writer).Error!void {
8014 if (data.item == .none) return;
8015
8016 if (data.formatter.need_comma) try writer.writeAll(", ");
8017 defer data.formatter.need_comma = true;
8018 try writer.writeAll(data.prefix);
8019
8020 const builder = data.formatter.builder;
8021 switch (data.item) {
8022 .none => unreachable,
8023 .@"inline" => |item| {
8024 const needed_comma = data.formatter.need_comma;
8025 defer data.formatter.need_comma = needed_comma;
8026 data.formatter.need_comma = false;
8027
8028 const metadata_item = builder.metadata_items.get(@intFromEnum(item));
8029 switch (metadata_item.tag) {
8030 .tuple => {
8031 var extra =
8032 builder.metadataExtraDataTrail(Metadata.Tuple, metadata_item.data);
8033 const elements =
8034 extra.trail.next(extra.data.elements_len, Metadata, builder);
8035 try writer.writeAll("!{");
8036 for (elements) |element| try format(.{
8037 .formatter = data.formatter,
8038 .item = data.formatter.unwrapAssumeExists(element),
8039 }, "%", fmt_opts, writer);
8040 try writer.writeByte('}');
8041 },
8042 .expression => {
8043 var extra =
8044 builder.metadataExtraDataTrail(Metadata.Expression, metadata_item.data);
8045 const elements = extra.trail.next(extra.data.elements_len, u32, builder);
8046 try writer.writeAll("!DIExpression(");
8047 for (elements) |element| try format(.{
8048 .formatter = data.formatter,
8049 .item = .{ .u64 = element },
8050 }, "%", fmt_opts, writer);
8051 try writer.writeByte(')');
8052 },
8053 .constant => try Constant.format(.{
8054 .constant = @enumFromInt(metadata_item.data),
8055 .builder = builder,
8056 }, "%", fmt_opts, writer),
8057 else => unreachable,
8058 }
8059 },
8060 .index => |item| try writer.print("!{d}", .{item}),
8061 .value => |item| try Value.format(.{
8062 .value = switch (item.value.unwrap()) {
8063 .instruction, .constant => item.value,
8064 .metadata => |metadata| if (@intFromEnum(metadata) >=
8065 Metadata.first_local_metadata)
8066 item.function.ptrConst(builder).debug_values[
8067 @intFromEnum(metadata) - Metadata.first_local_metadata
8068 ].toValue()
8069 else if (metadata != .none) {
8070 if (comptime std.mem.eql(u8, fmt_str, "%"))
8071 try writer.print("{%} ", .{Type.metadata.fmt(builder)});
8072 try Metadata.Formatter.format(.{
8073 .formatter = data.formatter,
8074 .item = data.formatter.unwrapAssumeExists(metadata),
8075 }, "", fmt_opts, writer);
8076 return;
8077 } else return,
8078 },
8079 .function = item.function,
8080 .builder = builder,
8081 }, "%", fmt_opts, writer),
8082 .string => |item| try writer.print("{}", .{item.fmt(data.formatter.builder)}),
8083 inline .bool, .u32, .u64 => |item| try writer.print("{}", .{item}),
8084 .raw => |item| try writer.print("{s}", .{item}),
8085 }
8086 }
8087 inline fn fmt(formatter: *Formatter, prefix: []const u8, item: anytype) switch (@TypeOf(item)) {
8088 Metadata => Allocator.Error,
8089 else => error{},
8090 }!std.fmt.Formatter(format) {
8091 return .{ .data = .{
8092 .formatter = formatter,
8093 .prefix = prefix,
8094 .item = switch (@typeInfo(@TypeOf(item))) {
8095 .Null => .none,
8096 .Enum => |enum_info| switch (@TypeOf(item)) {
8097 Metadata => try formatter.unwrap(item),
8098 MetadataString => .{ .string = item },
8099 else => if (enum_info.is_exhaustive)
8100 .{ .raw = @tagName(item) }
8101 else
8102 @compileError("unknown type to format: " ++ @typeName(@TypeOf(item))),
8103 },
8104 .EnumLiteral => .{ .raw = @tagName(item) },
8105 .Bool => .{ .bool = item },
8106 .Struct => .{ .u32 = @bitCast(item) },
8107 .Int, .ComptimeInt => .{ .u64 = item },
8108 .Pointer => .{ .raw = item },
8109 .Optional => if (item) |some| switch (@typeInfo(@TypeOf(some))) {
8110 .Enum => |enum_info| switch (@TypeOf(some)) {
8111 Metadata => try formatter.unwrap(some),
8112 MetadataString => .{ .string = some },
8113 else => if (enum_info.is_exhaustive)
8114 .{ .raw = @tagName(some) }
8115 else
8116 @compileError("unknown type to format: " ++ @typeName(@TypeOf(item))),
8117 },
8118 .Bool => .{ .bool = some },
8119 .Struct => .{ .u32 = @bitCast(some) },
8120 .Int => .{ .u64 = some },
8121 .Pointer => .{ .raw = some },
8122 else => @compileError("unknown type to format: " ++ @typeName(@TypeOf(item))),
8123 } else .none,
8124 else => @compileError("unknown type to format: " ++ @typeName(@TypeOf(item))),
8125 },
8126 } };
8127 }
8128 inline fn fmtLocal(
8129 formatter: *Formatter,
8130 prefix: []const u8,
8131 item: Value,
8132 function: Function.Index,
8133 ) Allocator.Error!std.fmt.Formatter(format) {
8134 return .{ .data = .{
8135 .formatter = formatter,
8136 .prefix = prefix,
8137 .item = .{ .value = .{
8138 .value = switch (item.unwrap()) {
8139 .instruction, .constant => item,
8140 .metadata => |metadata| value: {
8141 const unwrapped_metadata = metadata.unwrap(formatter.builder);
8142 if (@intFromEnum(unwrapped_metadata) < Metadata.first_local_metadata)
8143 _ = try formatter.unwrap(unwrapped_metadata);
8144 break :value unwrapped_metadata.toValue();
8145 },
8146 },
8147 .function = function,
8148 } },
8149 } };
8150 }
8151
8152 inline fn specialized(
8153 formatter: *Formatter,
8154 distinct: enum { @"!", @"distinct !" },
8155 node: enum {
8156 DIFile,
8157 DICompileUnit,
8158 DISubprogram,
8159 DILexicalBlock,
8160 DILocation,
8161 DIBasicType,
8162 DICompositeType,
8163 DIDerivedType,
8164 DISubroutineType,
8165 DIEnumerator,
8166 DISubrange,
8167 DILocalVariable,
8168 DIGlobalVariable,
8169 DIGlobalVariableExpression,
8170 },
8171 items: anytype,
8172 writer: anytype,
8173 ) !void {
8174 comptime var fmt_str: []const u8 = "";
8175 const names = comptime std.meta.fieldNames(@TypeOf(items));
8176 comptime var fields: [2 + names.len]std.builtin.Type.StructField = undefined;
8177 inline for (fields[0..2], .{ "distinct", "node" }) |*field, name| {
8178 fmt_str = fmt_str ++ "{[" ++ name ++ "]s}";
8179 field.* = .{
8180 .name = name,
8181 .type = []const u8,
8182 .default_value = null,
8183 .is_comptime = false,
8184 .alignment = 0,
8185 };
8186 }
8187 fmt_str = fmt_str ++ "(";
8188 inline for (fields[2..], names) |*field, name| {
8189 fmt_str = fmt_str ++ "{[" ++ name ++ "]}";
8190 field.* = .{
8191 .name = name ++ "",
8192 .type = std.fmt.Formatter(format),
8193 .default_value = null,
8194 .is_comptime = false,
8195 .alignment = 0,
8196 };
8197 }
8198 fmt_str = fmt_str ++ ")\n";
8199
8200 var fmt_args: @Type(.{ .Struct = .{
8201 .layout = .Auto,
8202 .fields = &fields,
8203 .decls = &.{},
8204 .is_tuple = false,
8205 } }) = undefined;
8206 fmt_args.distinct = @tagName(distinct);
8207 fmt_args.node = @tagName(node);
8208 inline for (names) |name| @field(fmt_args, name) = try formatter.fmt(
8209 name ++ ": ",
8210 @field(items, name),
8211 );
8212 try writer.print(fmt_str, fmt_args);
8213 }
8214 };
8215};
8216
8217pub fn init(options: Options) Allocator.Error!Builder {
78128218 var self = Builder{
78138219 .gpa = options.allocator,
78148220 .strip = options.strip,
......@@ -8800,9 +9206,11 @@ pub fn printUnbuffered(
88009206 writer: anytype,
88019207) (@TypeOf(writer).Error || Allocator.Error)!void {
88029208 var need_newline = false;
9209 var metadata_formatter: Metadata.Formatter = .{ .builder = self, .need_comma = undefined };
9210 defer metadata_formatter.map.deinit(self.gpa);
88039211
88049212 if (self.source_filename != .none or self.data_layout != .none or self.target_triple != .none) {
8805 if (need_newline) try writer.writeByte('\n');
9213 if (need_newline) try writer.writeByte('\n') else need_newline = true;
88069214 if (self.source_filename != .none) try writer.print(
88079215 \\; ModuleID = '{s}'
88089216 \\source_filename = {"}
......@@ -8816,36 +9224,35 @@ pub fn printUnbuffered(
88169224 \\target triple = {"}
88179225 \\
88189226 , .{self.target_triple.fmt(self)});
8819 need_newline = true;
88209227 }
88219228
88229229 if (self.module_asm.items.len > 0) {
8823 if (need_newline) try writer.writeByte('\n');
9230 if (need_newline) try writer.writeByte('\n') else need_newline = true;
88249231 var line_it = std.mem.tokenizeScalar(u8, self.module_asm.items, '\n');
88259232 while (line_it.next()) |line| {
88269233 try writer.writeAll("module asm ");
88279234 try printEscapedString(line, .always_quote, writer);
88289235 try writer.writeByte('\n');
88299236 }
8830 need_newline = true;
88319237 }
88329238
88339239 if (self.types.count() > 0) {
8834 if (need_newline) try writer.writeByte('\n');
9240 if (need_newline) try writer.writeByte('\n') else need_newline = true;
88359241 for (self.types.keys(), self.types.values()) |id, ty| try writer.print(
88369242 \\%{} = type {}
88379243 \\
88389244 , .{ id.fmt(self), ty.fmt(self) });
8839 need_newline = true;
88409245 }
88419246
88429247 if (self.variables.items.len > 0) {
8843 if (need_newline) try writer.writeByte('\n');
9248 if (need_newline) try writer.writeByte('\n') else need_newline = true;
88449249 for (self.variables.items) |variable| {
88459250 if (variable.global.getReplacement(self) != .none) continue;
88469251 const global = variable.global.ptrConst(self);
9252 metadata_formatter.need_comma = true;
9253 defer metadata_formatter.need_comma = undefined;
88479254 try writer.print(
8848 \\{} ={}{}{}{}{ }{}{ }{} {s} {%}{ }{, }
9255 \\{} ={}{}{}{}{ }{}{ }{} {s} {%}{ }{, }{}
88499256 \\
88509257 , .{
88519258 variable.global.fmt(self),
......@@ -8861,18 +9268,20 @@ pub fn printUnbuffered(
88619268 global.type.fmt(self),
88629269 variable.init.fmt(self),
88639270 variable.alignment,
9271 try metadata_formatter.fmt("!dbg ", global.dbg),
88649272 });
88659273 }
8866 need_newline = true;
88679274 }
88689275
88699276 if (self.aliases.items.len > 0) {
8870 if (need_newline) try writer.writeByte('\n');
9277 if (need_newline) try writer.writeByte('\n') else need_newline = true;
88719278 for (self.aliases.items) |alias| {
88729279 if (alias.global.getReplacement(self) != .none) continue;
88739280 const global = alias.global.ptrConst(self);
9281 metadata_formatter.need_comma = true;
9282 defer metadata_formatter.need_comma = undefined;
88749283 try writer.print(
8875 \\{} ={}{}{}{}{ }{} alias {%}, {%}
9284 \\{} ={}{}{}{}{ }{} alias {%}, {%}{}
88769285 \\
88779286 , .{
88789287 alias.global.fmt(self),
......@@ -8884,9 +9293,9 @@ pub fn printUnbuffered(
88849293 global.unnamed_addr,
88859294 global.type.fmt(self),
88869295 alias.aliasee.fmt(self),
9296 try metadata_formatter.fmt("!dbg ", global.dbg),
88879297 });
88889298 }
8889 need_newline = true;
88909299 }
88919300
88929301 var attribute_groups: std.AutoArrayHashMapUnmanaged(Attributes, void) = .{};
......@@ -8894,7 +9303,7 @@ pub fn printUnbuffered(
88949303
88959304 for (0.., self.functions.items) |function_i, function| {
88969305 if (function.global.getReplacement(self) != .none) continue;
8897 if (need_newline) try writer.writeByte('\n');
9306 if (need_newline) try writer.writeByte('\n') else need_newline = true;
88989307 const function_index: Function.Index = @enumFromInt(function_i);
88999308 const global = function.global.ptrConst(self);
89009309 const params_len = global.type.functionParameters(self).len;
......@@ -8940,13 +9349,23 @@ pub fn printUnbuffered(
89409349 if (function_attributes != .none) try writer.print(" #{d}", .{
89419350 (try attribute_groups.getOrPutValue(self.gpa, function_attributes, {})).index,
89429351 });
8943 try writer.print("{ }", .{function.alignment});
9352 {
9353 metadata_formatter.need_comma = false;
9354 defer metadata_formatter.need_comma = undefined;
9355 try writer.print("{ }{}", .{
9356 function.alignment,
9357 try metadata_formatter.fmt("!dbg ", global.dbg),
9358 });
9359 }
89449360 if (function.instructions.len > 0) {
89459361 var block_incoming_len: u32 = undefined;
89469362 try writer.writeAll(" {\n");
9363 var dbg: Metadata = .none;
89479364 for (params_len..function.instructions.len) |instruction_i| {
89489365 const instruction_index: Function.Instruction.Index = @enumFromInt(instruction_i);
89499366 const instruction = function.instructions.get(@intFromEnum(instruction_index));
9367 if (function.debug_locations.get(instruction_index)) |debug_location|
9368 dbg = debug_location;
89509369 switch (instruction.tag) {
89519370 .add,
89529371 .@"add nsw",
......@@ -9031,7 +9450,7 @@ pub fn printUnbuffered(
90319450 .xor,
90329451 => |tag| {
90339452 const extra = function.extraData(Function.Instruction.Binary, instruction.data);
9034 try writer.print(" %{} = {s} {%}, {}\n", .{
9453 try writer.print(" %{} = {s} {%}, {}", .{
90359454 instruction_index.name(&function).fmt(self),
90369455 @tagName(tag),
90379456 extra.lhs.fmt(function_index, self),
......@@ -9053,7 +9472,7 @@ pub fn printUnbuffered(
90539472 .zext,
90549473 => |tag| {
90559474 const extra = function.extraData(Function.Instruction.Cast, instruction.data);
9056 try writer.print(" %{} = {s} {%} to {%}\n", .{
9475 try writer.print(" %{} = {s} {%} to {%}", .{
90579476 instruction_index.name(&function).fmt(self),
90589477 @tagName(tag),
90599478 extra.val.fmt(function_index, self),
......@@ -9064,7 +9483,7 @@ pub fn printUnbuffered(
90649483 .@"alloca inalloca",
90659484 => |tag| {
90669485 const extra = function.extraData(Function.Instruction.Alloca, instruction.data);
9067 try writer.print(" %{} = {s} {%}{,%}{, }{, }\n", .{
9486 try writer.print(" %{} = {s} {%}{,%}{, }{, }", .{
90689487 instruction_index.name(&function).fmt(self),
90699488 @tagName(tag),
90709489 extra.type.fmt(self),
......@@ -9077,7 +9496,7 @@ pub fn printUnbuffered(
90779496 .atomicrmw => |tag| {
90789497 const extra =
90799498 function.extraData(Function.Instruction.AtomicRmw, instruction.data);
9080 try writer.print(" %{} = {s}{ } {s} {%}, {%}{ }{ }{, }\n", .{
9499 try writer.print(" %{} = {s}{ } {s} {%}, {%}{ }{ }{, }", .{
90819500 instruction_index.name(&function).fmt(self),
90829501 @tagName(tag),
90839502 extra.info.access_kind,
......@@ -9094,17 +9513,17 @@ pub fn printUnbuffered(
90949513 const name = instruction_index.name(&function);
90959514 if (@intFromEnum(instruction_index) > params_len)
90969515 try writer.writeByte('\n');
9097 try writer.print("{}:\n", .{name.fmt(self)});
9516 try writer.print("{}:", .{name.fmt(self)});
90989517 },
90999518 .br => |tag| {
91009519 const target: Function.Block.Index = @enumFromInt(instruction.data);
9101 try writer.print(" {s} {%}\n", .{
9520 try writer.print(" {s} {%}", .{
91029521 @tagName(tag), target.toInst(&function).fmt(function_index, self),
91039522 });
91049523 },
91059524 .br_cond => {
91069525 const extra = function.extraData(Function.Instruction.BrCond, instruction.data);
9107 try writer.print(" br {%}, {%}, {%}\n", .{
9526 try writer.print(" br {%}, {%}, {%}", .{
91089527 extra.cond.fmt(function_index, self),
91099528 extra.then.toInst(&function).fmt(function_index, self),
91109529 extra.@"else".toInst(&function).fmt(function_index, self),
......@@ -9144,10 +9563,12 @@ pub fn printUnbuffered(
91449563 });
91459564 for (0.., args) |arg_index, arg| {
91469565 if (arg_index > 0) try writer.writeAll(", ");
9147 try writer.print("{%}{} {}", .{
9566 metadata_formatter.need_comma = false;
9567 defer metadata_formatter.need_comma = undefined;
9568 try writer.print("{%}{}{}", .{
91489569 arg.typeOf(function_index, self).fmt(self),
91499570 extra.data.attributes.param(arg_index, self).fmt(self),
9150 arg.fmt(function_index, self),
9571 try metadata_formatter.fmtLocal(" ", arg, function_index),
91519572 });
91529573 }
91539574 try writer.writeByte(')');
......@@ -9159,14 +9580,13 @@ pub fn printUnbuffered(
91599580 {},
91609581 )).index,
91619582 });
9162 try writer.writeByte('\n');
91639583 },
91649584 .cmpxchg,
91659585 .@"cmpxchg weak",
91669586 => |tag| {
91679587 const extra =
91689588 function.extraData(Function.Instruction.CmpXchg, instruction.data);
9169 try writer.print(" %{} = {s}{ } {%}, {%}, {%}{ }{ }{ }{, }\n", .{
9589 try writer.print(" %{} = {s}{ } {%}, {%}, {%}{ }{ }{ }{, }", .{
91709590 instruction_index.name(&function).fmt(self),
91719591 @tagName(tag),
91729592 extra.info.access_kind,
......@@ -9182,7 +9602,7 @@ pub fn printUnbuffered(
91829602 .extractelement => |tag| {
91839603 const extra =
91849604 function.extraData(Function.Instruction.ExtractElement, instruction.data);
9185 try writer.print(" %{} = {s} {%}, {%}\n", .{
9605 try writer.print(" %{} = {s} {%}, {%}", .{
91869606 instruction_index.name(&function).fmt(self),
91879607 @tagName(tag),
91889608 extra.val.fmt(function_index, self),
......@@ -9201,7 +9621,6 @@ pub fn printUnbuffered(
92019621 extra.data.val.fmt(function_index, self),
92029622 });
92039623 for (indices) |index| try writer.print(", {d}", .{index});
9204 try writer.writeByte('\n');
92059624 },
92069625 .fence => |tag| {
92079626 const info: MemoryAccessInfo = @bitCast(instruction.data);
......@@ -9215,7 +9634,7 @@ pub fn printUnbuffered(
92159634 .@"fneg fast",
92169635 => |tag| {
92179636 const val: Value = @enumFromInt(instruction.data);
9218 try writer.print(" %{} = {s} {%}\n", .{
9637 try writer.print(" %{} = {s} {%}", .{
92199638 instruction_index.name(&function).fmt(self),
92209639 @tagName(tag),
92219640 val.fmt(function_index, self),
......@@ -9238,12 +9657,11 @@ pub fn printUnbuffered(
92389657 for (indices) |index| try writer.print(", {%}", .{
92399658 index.fmt(function_index, self),
92409659 });
9241 try writer.writeByte('\n');
92429660 },
92439661 .insertelement => |tag| {
92449662 const extra =
92459663 function.extraData(Function.Instruction.InsertElement, instruction.data);
9246 try writer.print(" %{} = {s} {%}, {%}, {%}\n", .{
9664 try writer.print(" %{} = {s} {%}, {%}, {%}", .{
92479665 instruction_index.name(&function).fmt(self),
92489666 @tagName(tag),
92499667 extra.val.fmt(function_index, self),
......@@ -9262,13 +9680,12 @@ pub fn printUnbuffered(
92629680 extra.data.elem.fmt(function_index, self),
92639681 });
92649682 for (indices) |index| try writer.print(", {d}", .{index});
9265 try writer.writeByte('\n');
92669683 },
92679684 .load,
92689685 .@"load atomic",
92699686 => |tag| {
92709687 const extra = function.extraData(Function.Instruction.Load, instruction.data);
9271 try writer.print(" %{} = {s}{ } {%}, {%}{ }{ }{, }\n", .{
9688 try writer.print(" %{} = {s}{ } {%}, {%}{ }{ }{, }", .{
92729689 instruction_index.name(&function).fmt(self),
92739690 @tagName(tag),
92749691 extra.info.access_kind,
......@@ -9298,23 +9715,22 @@ pub fn printUnbuffered(
92989715 incoming_block.toInst(&function).fmt(function_index, self),
92999716 });
93009717 }
9301 try writer.writeByte('\n');
93029718 },
93039719 .ret => |tag| {
93049720 const val: Value = @enumFromInt(instruction.data);
9305 try writer.print(" {s} {%}\n", .{
9721 try writer.print(" {s} {%}", .{
93069722 @tagName(tag),
93079723 val.fmt(function_index, self),
93089724 });
93099725 },
93109726 .@"ret void",
93119727 .@"unreachable",
9312 => |tag| try writer.print(" {s}\n", .{@tagName(tag)}),
9728 => |tag| try writer.print(" {s}", .{@tagName(tag)}),
93139729 .select,
93149730 .@"select fast",
93159731 => |tag| {
93169732 const extra = function.extraData(Function.Instruction.Select, instruction.data);
9317 try writer.print(" %{} = {s} {%}, {%}, {%}\n", .{
9733 try writer.print(" %{} = {s} {%}, {%}, {%}", .{
93189734 instruction_index.name(&function).fmt(self),
93199735 @tagName(tag),
93209736 extra.cond.fmt(function_index, self),
......@@ -9325,7 +9741,7 @@ pub fn printUnbuffered(
93259741 .shufflevector => |tag| {
93269742 const extra =
93279743 function.extraData(Function.Instruction.ShuffleVector, instruction.data);
9328 try writer.print(" %{} = {s} {%}, {%}, {%}\n", .{
9744 try writer.print(" %{} = {s} {%}, {%}, {%}", .{
93299745 instruction_index.name(&function).fmt(self),
93309746 @tagName(tag),
93319747 extra.lhs.fmt(function_index, self),
......@@ -9337,7 +9753,7 @@ pub fn printUnbuffered(
93379753 .@"store atomic",
93389754 => |tag| {
93399755 const extra = function.extraData(Function.Instruction.Store, instruction.data);
9340 try writer.print(" {s}{ } {%}, {%}{ }{ }{, }\n", .{
9756 try writer.print(" {s}{ } {%}, {%}{ }{ }{, }", .{
93419757 @tagName(tag),
93429758 extra.info.access_kind,
93439759 extra.val.fmt(function_index, self),
......@@ -9365,11 +9781,11 @@ pub fn printUnbuffered(
93659781 case_block.toInst(&function).fmt(function_index, self),
93669782 },
93679783 );
9368 try writer.writeAll(" ]\n");
9784 try writer.writeAll(" ]");
93699785 },
93709786 .va_arg => |tag| {
93719787 const extra = function.extraData(Function.Instruction.VaArg, instruction.data);
9372 try writer.print(" %{} = {s} {%}, {%}\n", .{
9788 try writer.print(" %{} = {s} {%}, {%}", .{
93739789 instruction_index.name(&function).fmt(self),
93749790 @tagName(tag),
93759791 extra.list.fmt(function_index, self),
......@@ -9377,11 +9793,13 @@ pub fn printUnbuffered(
93779793 });
93789794 },
93799795 }
9796 metadata_formatter.need_comma = true;
9797 defer metadata_formatter.need_comma = undefined;
9798 try writer.print("{}\n", .{try metadata_formatter.fmt("!dbg ", dbg)});
93809799 }
93819800 try writer.writeByte('}');
93829801 }
93839802 try writer.writeByte('\n');
9384 need_newline = true;
93859803 }
93869804
93879805 if (attribute_groups.count() > 0) {
......@@ -9391,7 +9809,367 @@ pub fn printUnbuffered(
93919809 \\attributes #{d} = {{{#"} }}
93929810 \\
93939811 , .{ attribute_group_index, attribute_group.fmt(self) });
9394 need_newline = true;
9812 }
9813
9814 if (self.metadata_named.count() > 0) {
9815 if (need_newline) try writer.writeByte('\n') else need_newline = true;
9816 for (self.metadata_named.keys(), self.metadata_named.values()) |name, data| {
9817 const elements: []const Metadata =
9818 @ptrCast(self.metadata_extra.items[data.index..][0..data.len]);
9819 try writer.writeByte('!');
9820 try printEscapedString(name.slice(self), .quote_unless_valid_identifier, writer);
9821 try writer.writeAll(" = !{");
9822 metadata_formatter.need_comma = false;
9823 defer metadata_formatter.need_comma = undefined;
9824 for (elements) |element| try writer.print("{}", .{try metadata_formatter.fmt("", element)});
9825 try writer.writeAll("}\n");
9826 }
9827 }
9828
9829 if (metadata_formatter.map.count() > 0) {
9830 if (need_newline) try writer.writeByte('\n') else need_newline = true;
9831 var metadata_index: usize = 0;
9832 while (metadata_index < metadata_formatter.map.count()) : (metadata_index += 1) {
9833 @setEvalBranchQuota(10_000);
9834 const metadata_item =
9835 self.metadata_items.get(@intFromEnum(metadata_formatter.map.keys()[metadata_index]));
9836 try writer.print("!{} = ", .{metadata_index});
9837 metadata_formatter.need_comma = false;
9838 defer metadata_formatter.need_comma = undefined;
9839 switch (metadata_item.tag) {
9840 .none, .tuple, .expression, .constant => unreachable,
9841 .file => {
9842 const extra = self.metadataExtraData(Metadata.File, metadata_item.data);
9843 try metadata_formatter.specialized(.@"distinct !", .DIFile, .{
9844 .filename = extra.filename,
9845 .directory = extra.directory,
9846 .checksumkind = null,
9847 .checksum = null,
9848 .source = null,
9849 }, writer);
9850 },
9851 .compile_unit,
9852 .@"compile_unit optimized",
9853 => |kind| {
9854 const extra = self.metadataExtraData(Metadata.CompileUnit, metadata_item.data);
9855 try metadata_formatter.specialized(.@"distinct !", .DICompileUnit, .{
9856 .language = .DW_LANG_C99,
9857 .file = extra.file,
9858 .producer = extra.producer,
9859 .isOptimized = switch (kind) {
9860 .compile_unit => false,
9861 .@"compile_unit optimized" => true,
9862 else => unreachable,
9863 },
9864 .flags = null,
9865 .runtimeVersion = 0,
9866 .splitDebugFilename = null,
9867 .emissionKind = .FullDebug,
9868 .enums = extra.enums,
9869 .retainedTypes = null,
9870 .globals = extra.globals,
9871 .imports = null,
9872 .macros = null,
9873 .dwoId = null,
9874 .splitDebugInlining = false,
9875 .debugInfoForProfiling = null,
9876 .nameTableKind = null,
9877 .rangesBaseAddress = null,
9878 .sysroot = null,
9879 .sdk = null,
9880 }, writer);
9881 },
9882 .subprogram,
9883 .@"subprogram local",
9884 .@"subprogram definition",
9885 .@"subprogram local definition",
9886 .@"subprogram optimized",
9887 .@"subprogram optimized local",
9888 .@"subprogram optimized definition",
9889 .@"subprogram optimized local definition",
9890 => |kind| {
9891 const extra = self.metadataExtraData(Metadata.Subprogram, metadata_item.data);
9892 try metadata_formatter.specialized(.@"distinct !", .DISubprogram, .{
9893 .name = extra.name,
9894 .linkageName = extra.linkage_name,
9895 .scope = extra.file,
9896 .file = extra.file,
9897 .line = extra.line,
9898 .type = null,
9899 .scopeLine = extra.scope_line,
9900 .containingType = null,
9901 .virtualIndex = null,
9902 .thisAdjustment = null,
9903 .flags = extra.di_flags,
9904 .spFlags = @as(Metadata.Subprogram.SPFlags, @bitCast(@as(u32, @as(u3, @intCast(
9905 @intFromEnum(kind) - @intFromEnum(Metadata.Tag.subprogram),
9906 ))) << 2)),
9907 .unit = extra.compile_unit,
9908 .templateParams = null,
9909 .declaration = null,
9910 .retainedNodes = null,
9911 .thrownTypes = null,
9912 .annotations = null,
9913 .targetFuncName = null,
9914 }, writer);
9915 },
9916 .lexical_block => {
9917 const extra = self.metadataExtraData(Metadata.LexicalBlock, metadata_item.data);
9918 try metadata_formatter.specialized(.@"distinct !", .DILexicalBlock, .{
9919 .scope = extra.scope,
9920 .file = extra.file,
9921 .line = extra.line,
9922 .column = extra.column,
9923 }, writer);
9924 },
9925 .location => {
9926 const extra = self.metadataExtraData(Metadata.Location, metadata_item.data);
9927 try metadata_formatter.specialized(.@"!", .DILocation, .{
9928 .line = extra.line,
9929 .column = extra.column,
9930 .scope = extra.scope,
9931 .inlinedAt = extra.inlined_at,
9932 .isImplicitCode = false,
9933 }, writer);
9934 },
9935 .basic_bool_type,
9936 .basic_unsigned_type,
9937 .basic_signed_type,
9938 .basic_float_type,
9939 => |kind| {
9940 const extra = self.metadataExtraData(Metadata.BasicType, metadata_item.data);
9941 try metadata_formatter.specialized(.@"distinct !", .DIBasicType, .{
9942 .tag = null,
9943 .name = switch (extra.name) {
9944 .none => null,
9945 else => extra.name,
9946 },
9947 .size = extra.bitSize(),
9948 .@"align" = null,
9949 .encoding = @as(enum {
9950 DW_ATE_boolean,
9951 DW_ATE_unsigned,
9952 DW_ATE_signed,
9953 DW_ATE_float,
9954 }, switch (kind) {
9955 .basic_bool_type => .DW_ATE_boolean,
9956 .basic_unsigned_type => .DW_ATE_unsigned,
9957 .basic_signed_type => .DW_ATE_signed,
9958 .basic_float_type => .DW_ATE_float,
9959 else => unreachable,
9960 }),
9961 .flags = null,
9962 }, writer);
9963 },
9964 .composite_struct_type,
9965 .composite_union_type,
9966 .composite_enumeration_type,
9967 .composite_array_type,
9968 => |kind| {
9969 const extra = self.metadataExtraData(Metadata.CompositeType, metadata_item.data);
9970 try metadata_formatter.specialized(.@"distinct !", .DICompositeType, .{
9971 .tag = @as(enum {
9972 DW_TAG_structure_type,
9973 DW_TAG_union_type,
9974 DW_TAG_enumeration_type,
9975 DW_TAG_array_type,
9976 }, switch (kind) {
9977 .composite_struct_type => .DW_TAG_structure_type,
9978 .composite_union_type => .DW_TAG_union_type,
9979 .composite_enumeration_type => .DW_TAG_enumeration_type,
9980 .composite_array_type, .composite_vector_type => .DW_TAG_array_type,
9981 else => unreachable,
9982 }),
9983 .name = switch (extra.name) {
9984 .none => null,
9985 else => extra.name,
9986 },
9987 .scope = extra.scope,
9988 .file = null,
9989 .line = null,
9990 .baseType = extra.underlying_type,
9991 .size = extra.bitSize(),
9992 .@"align" = extra.bitAlign(),
9993 .offset = null,
9994 .flags = null,
9995 .elements = extra.fields_tuple,
9996 .runtimeLang = null,
9997 .vtableHolder = null,
9998 .templateParams = null,
9999 .identifier = null,
10000 .discriminator = null,
10001 .dataLocation = null,
10002 .associated = null,
10003 .allocated = null,
10004 .rank = null,
10005 .annotations = null,
10006 }, writer);
10007 },
10008 .derived_pointer_type,
10009 .derived_member_type,
10010 => |kind| {
10011 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);
10012 try metadata_formatter.specialized(.@"distinct !", .DIDerivedType, .{
10013 .tag = @as(enum {
10014 DW_TAG_pointer_type,
10015 DW_TAG_member,
10016 }, switch (kind) {
10017 .derived_pointer_type => .DW_TAG_pointer_type,
10018 .derived_member_type => .DW_TAG_member,
10019 else => unreachable,
10020 }),
10021 .name = switch (extra.name) {
10022 .none => null,
10023 else => extra.name,
10024 },
10025 .scope = extra.scope,
10026 .file = null,
10027 .line = null,
10028 .baseType = extra.underlying_type,
10029 .size = extra.bitSize(),
10030 .@"align" = extra.bitAlign(),
10031 .offset = switch (extra.bitOffset()) {
10032 0 => null,
10033 else => |bit_offset| bit_offset,
10034 },
10035 .flags = null,
10036 .extraData = null,
10037 .dwarfAddressSpace = null,
10038 .annotations = null,
10039 }, writer);
10040 },
10041 .subroutine_type => {
10042 const extra = self.metadataExtraData(Metadata.SubroutineType, metadata_item.data);
10043 try metadata_formatter.specialized(.@"distinct !", .DISubroutineType, .{
10044 .flags = null,
10045 .cc = null,
10046 .types = extra.types_tuple,
10047 }, writer);
10048 },
10049 .enumerator_unsigned,
10050 .enumerator_signed_positive,
10051 .enumerator_signed_negative,
10052 => |kind| {
10053 const extra = self.metadataExtraData(Metadata.Enumerator, metadata_item.data);
10054
10055 const ExpectedContents = extern struct {
10056 string: [(64 * 8 / std.math.log2(10)) + 2]u8,
10057 limbs: [
10058 std.math.big.int.calcToStringLimbsBufferLen(
10059 64 / @sizeOf(std.math.big.Limb),
10060 10,
10061 )
10062 ]std.math.big.Limb,
10063 };
10064 var stack align(@alignOf(ExpectedContents)) =
10065 std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa);
10066 const allocator = stack.get();
10067
10068 const limbs = self.metadata_limbs.items[extra.limbs_index..][0..extra.limbs_len];
10069 const bigint: std.math.big.int.Const = .{
10070 .limbs = limbs,
10071 .positive = switch (kind) {
10072 .enumerator_unsigned,
10073 .enumerator_signed_positive,
10074 => true,
10075 .enumerator_signed_negative => false,
10076 else => unreachable,
10077 },
10078 };
10079 const str = try bigint.toStringAlloc(allocator, 10, undefined);
10080 defer allocator.free(str);
10081
10082 try metadata_formatter.specialized(.@"distinct !", .DIEnumerator, .{
10083 .name = extra.name,
10084 .value = str,
10085 .isUnsigned = switch (kind) {
10086 .enumerator_unsigned => true,
10087 .enumerator_signed_positive, .enumerator_signed_negative => false,
10088 else => unreachable,
10089 },
10090 }, writer);
10091 },
10092 .subrange => {
10093 const extra = self.metadataExtraData(Metadata.Subrange, metadata_item.data);
10094 try metadata_formatter.specialized(.@"!", .DISubrange, .{
10095 .count = extra.count,
10096 .lowerBound = extra.lower_bound,
10097 .upperBound = null,
10098 .stride = null,
10099 }, writer);
10100 },
10101 .module_flag => {
10102 const extra = self.metadataExtraData(Metadata.ModuleFlag, metadata_item.data);
10103 try writer.print("!{{{[behavior]}{[name]}{[constant]}}}\n", .{
10104 .behavior = try metadata_formatter.fmt("", extra.behavior),
10105 .name = try metadata_formatter.fmt("!", extra.name),
10106 .constant = try metadata_formatter.fmt("", extra.constant),
10107 });
10108 },
10109 .local_var => {
10110 const extra = self.metadataExtraData(Metadata.LocalVar, metadata_item.data);
10111 try metadata_formatter.specialized(.@"distinct !", .DILocalVariable, .{
10112 .name = extra.name,
10113 .arg = null,
10114 .scope = extra.scope,
10115 .file = extra.file,
10116 .line = extra.line,
10117 .type = extra.ty,
10118 .flags = null,
10119 .@"align" = null,
10120 .annotations = null,
10121 }, writer);
10122 },
10123 .parameter => {
10124 const extra = self.metadataExtraData(Metadata.Parameter, metadata_item.data);
10125 try metadata_formatter.specialized(.@"distinct !", .DILocalVariable, .{
10126 .name = extra.name,
10127 .arg = extra.arg_no,
10128 .scope = extra.scope,
10129 .file = extra.file,
10130 .line = extra.line,
10131 .type = extra.ty,
10132 .flags = null,
10133 .@"align" = null,
10134 .annotations = null,
10135 }, writer);
10136 },
10137 .global_var,
10138 .@"global_var local",
10139 => |kind| {
10140 const extra = self.metadataExtraData(Metadata.GlobalVar, metadata_item.data);
10141 try metadata_formatter.specialized(.@"distinct !", .DIGlobalVariable, .{
10142 .name = extra.name,
10143 .linkageName = extra.linkage_name,
10144 .scope = extra.scope,
10145 .file = extra.file,
10146 .line = extra.line,
10147 .type = extra.ty,
10148 .isLocal = switch (kind) {
10149 .global_var => false,
10150 .@"global_var local" => true,
10151 else => unreachable,
10152 },
10153 .isDefinition = true,
10154 .declaration = null,
10155 .templateParams = null,
10156 .@"align" = null,
10157 .annotations = null,
10158 }, writer);
10159 },
10160 .global_var_expression => {
10161 const extra =
10162 self.metadataExtraData(Metadata.GlobalVarExpression, metadata_item.data);
10163 try metadata_formatter.specialized(.@"distinct !", .DIGlobalVariableExpression, .{
10164 .@"var" = extra.variable,
10165 .expr = extra.expression,
10166 }, writer);
10167 },
10168 else => {
10169 try writer.writeByte('\n');
10170 },
10171 }
10172 }
939510173 }
939610174}
939710175
......@@ -9725,7 +10503,7 @@ fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraInd
972510503 self.type_extra.appendAssumeCapacity(switch (field.type) {
972610504 u32 => value,
972710505 String, Type => @intFromEnum(value),
9728 else => @compileError("bad field type: " ++ @typeName(field.type)),
10506 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
972910507 });
973010508 }
973110509 return result;
......@@ -10894,6 +11672,7 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.
1089411672 self.metadata_extra.appendAssumeCapacity(switch (field.type) {
1089511673 u32 => value,
1089611674 MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value),
11675 Metadata.DIFlags => @bitCast(value),
1089711676 else => @compileError("bad field type: " ++ @typeName(field.type)),
1089811677 });
1089911678 }
......@@ -10932,6 +11711,7 @@ fn metadataExtraDataTrail(
1093211711 @field(result, field.name) = switch (field.type) {
1093311712 u32 => value,
1093411713 MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value),
11714 Metadata.DIFlags => @bitCast(value),
1093511715 else => @compileError("bad field type: " ++ @typeName(field.type)),
1093611716 };
1093711717 return .{
......@@ -10989,10 +11769,7 @@ pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const
1098911769}
1099011770
1099111771pub fn debugNamed(self: *Builder, name: MetadataString, operands: []const Metadata) Allocator.Error!void {
10992 try self.metadata_extra.ensureUnusedCapacity(
10993 self.gpa,
10994 operands.len * @sizeOf(Metadata),
10995 );
11772 try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len);
1099611773 try self.metadata_named.ensureUnusedCapacity(self.gpa, 1);
1099711774 self.debugNamedAssumeCapacity(name, operands);
1099811775}
......@@ -11002,9 +11779,13 @@ fn debugNone(self: *Builder) Allocator.Error!Metadata {
1100211779 return self.debugNoneAssumeCapacity();
1100311780}
1100411781
11005pub fn debugFile(self: *Builder, path: MetadataString, name: MetadataString) Allocator.Error!Metadata {
11782pub fn debugFile(
11783 self: *Builder,
11784 filename: MetadataString,
11785 directory: MetadataString,
11786) Allocator.Error!Metadata {
1100611787 try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0);
11007 return self.debugFileAssumeCapacity(path, name);
11788 return self.debugFileAssumeCapacity(filename, directory);
1100811789}
1100911790
1101011791pub fn debugCompileUnit(
......@@ -11013,10 +11794,10 @@ pub fn debugCompileUnit(
1101311794 producer: MetadataString,
1101411795 enums: Metadata,
1101511796 globals: Metadata,
11016 flags: Metadata.CompileUnit.Flags,
11797 options: Metadata.CompileUnit.Options,
1101711798) Allocator.Error!Metadata {
1101811799 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);
11019 return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, flags);
11800 return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, options);
1102011801}
1102111802
1102211803pub fn debugSubprogram(
......@@ -11027,7 +11808,7 @@ pub fn debugSubprogram(
1102711808 line: u32,
1102811809 scope_line: u32,
1102911810 ty: Metadata,
11030 flags: Metadata.Subprogram.Flags,
11811 options: Metadata.Subprogram.Options,
1103111812 compile_unit: Metadata,
1103211813) Allocator.Error!Metadata {
1103311814 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);
......@@ -11038,19 +11819,19 @@ pub fn debugSubprogram(
1103811819 line,
1103911820 scope_line,
1104011821 ty,
11041 flags,
11822 options,
1104211823 compile_unit,
1104311824 );
1104411825}
1104511826
11046pub fn debugLexicalBlock(self: *Builder, file: Metadata, scope: Metadata, line: u32, column: u32) Allocator.Error!Metadata {
11827pub fn debugLexicalBlock(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Allocator.Error!Metadata {
1104711828 try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0);
11048 return self.debugLexicalBlockAssumeCapacity(file, scope, line, column);
11829 return self.debugLexicalBlockAssumeCapacity(scope, file, line, column);
1104911830}
1105011831
11051pub fn debugLocation(self: *Builder, scope: Metadata, line: u32, column: u32, inlined_at: Metadata) Allocator.Error!Metadata {
11832pub fn debugLocation(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Allocator.Error!Metadata {
1105211833 try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0);
11053 return self.debugLocationAssumeCapacity(scope, line, column, inlined_at);
11834 return self.debugLocationAssumeCapacity(line, column, scope, inlined_at);
1105411835}
1105511836
1105611837pub fn debugBoolType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata {
......@@ -11294,12 +12075,12 @@ pub fn debugTuple(
1129412075
1129512076pub fn debugModuleFlag(
1129612077 self: *Builder,
11297 behaviour: Metadata,
12078 behavior: Metadata,
1129812079 name: MetadataString,
1129912080 constant: Metadata,
1130012081) Allocator.Error!Metadata {
1130112082 try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0);
11302 return self.debugModuleFlagAssumeCapacity(behaviour, name, constant);
12083 return self.debugModuleFlagAssumeCapacity(behavior, name, constant);
1130312084}
1130412085
1130512086pub fn debugLocalVar(
......@@ -11336,7 +12117,7 @@ pub fn debugGlobalVar(
1133612117 line: u32,
1133712118 ty: Metadata,
1133812119 variable: Variable.Index,
11339 flags: Metadata.GlobalVar.Flags,
12120 options: Metadata.GlobalVar.Options,
1134012121) Allocator.Error!Metadata {
1134112122 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);
1134212123 return self.debugGlobalVarAssumeCapacity(
......@@ -11347,7 +12128,7 @@ pub fn debugGlobalVar(
1134712128 line,
1134812129 ty,
1134912130 variable,
11350 flags,
12131 options,
1135112132 );
1135212133}
1135312134
......@@ -11393,12 +12174,7 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp
1139312174 if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
1139412175 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
1139512176 const rhs_extra = ctx.builder.metadataExtraData(@TypeOf(value), rhs_data);
11396 inline for (std.meta.fields(@TypeOf(value))) |field| {
11397 const lhs = @field(lhs_key.value, field.name);
11398 const rhs = @field(rhs_extra, field.name);
11399 if (lhs != rhs) return false;
11400 }
11401 return true;
12177 return std.meta.eql(lhs_key.value, rhs_extra);
1140212178 }
1140312179 };
1140412180
......@@ -11418,6 +12194,37 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp
1141812194 return @enumFromInt(gop.index);
1141912195}
1142012196
12197fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata {
12198 const Key = struct { tag: Metadata.Tag, index: Metadata };
12199 const Adapter = struct {
12200 pub fn hash(_: @This(), key: Key) u32 {
12201 return @truncate(std.hash.Wyhash.hash(
12202 std.hash.uint32(@intFromEnum(key.tag)),
12203 std.mem.asBytes(&key.index),
12204 ));
12205 }
12206
12207 pub fn eql(_: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
12208 return @intFromEnum(lhs_key.index) == rhs_index;
12209 }
12210 };
12211
12212 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
12213 Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) },
12214 Adapter{},
12215 );
12216
12217 if (!gop.found_existing) {
12218 gop.key_ptr.* = {};
12219 gop.value_ptr.* = {};
12220 self.metadata_items.appendAssumeCapacity(.{
12221 .tag = tag,
12222 .data = self.addMetadataExtraAssumeCapacity(value),
12223 });
12224 }
12225 return @enumFromInt(gop.index);
12226}
12227
1142112228fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void {
1142212229 std.debug.assert(name != .none);
1142312230 const extra_index: u32 = @intCast(self.metadata_extra.items.len);
......@@ -11434,10 +12241,14 @@ pub fn debugNoneAssumeCapacity(self: *Builder) Metadata {
1143412241 return self.metadataSimpleAssumeCapacity(.none, .{});
1143512242}
1143612243
11437fn debugFileAssumeCapacity(self: *Builder, path: MetadataString, name: MetadataString) Metadata {
11438 return self.metadataSimpleAssumeCapacity(.file, Metadata.File{
11439 .path = path,
11440 .name = name,
12244fn debugFileAssumeCapacity(
12245 self: *Builder,
12246 filename: MetadataString,
12247 directory: MetadataString,
12248) Metadata {
12249 return self.metadataDistinctAssumeCapacity(.file, Metadata.File{
12250 .filename = filename,
12251 .directory = directory,
1144112252 });
1144212253}
1144312254
......@@ -11447,10 +12258,10 @@ pub fn debugCompileUnitAssumeCapacity(
1144712258 producer: MetadataString,
1144812259 enums: Metadata,
1144912260 globals: Metadata,
11450 flags: Metadata.CompileUnit.Flags,
12261 options: Metadata.CompileUnit.Options,
1145112262) Metadata {
11452 return self.metadataSimpleAssumeCapacity(
11453 if (flags.optimized) .@"compile_unit optimized" else .compile_unit,
12263 return self.metadataDistinctAssumeCapacity(
12264 if (options.optimized) .@"compile_unit optimized" else .compile_unit,
1145412265 Metadata.CompileUnit{
1145512266 .file = file,
1145612267 .producer = producer,
......@@ -11468,57 +12279,43 @@ fn debugSubprogramAssumeCapacity(
1146812279 line: u32,
1146912280 scope_line: u32,
1147012281 ty: Metadata,
11471 flags: Metadata.Subprogram.Flags,
12282 options: Metadata.Subprogram.Options,
1147212283 compile_unit: Metadata,
1147312284) Metadata {
11474 const tag: Metadata.Tag = blk: {
11475 var int: u3 = 0;
11476 if (flags.optimized) int |= 0b1;
11477 if (flags.local) int |= 0b10;
11478 if (flags.definition) int |= 0b100;
11479 break :blk switch (int) {
11480 0 => .subprogram,
11481 0b1 => .@"subprogram optimized",
11482 0b10 => .@"subprogram local",
11483 0b100 => .@"subprogram definition",
11484 0b011 => .@"subprogram optimized local",
11485 0b111 => .@"subprogram optimized local definition",
11486 0b101 => .@"subprogram optimized definition",
11487 0b110 => .@"subprogram local definition",
11488 };
11489 };
11490 return self.metadataSimpleAssumeCapacity(tag, Metadata.Subprogram{
12285 const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) +
12286 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
12287 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
1149112288 .file = file,
1149212289 .name = name,
1149312290 .linkage_name = linkage_name,
1149412291 .line = line,
1149512292 .scope_line = scope_line,
1149612293 .ty = ty,
11497 .debug_info_flags = flags.debug_info_flags,
12294 .di_flags = options.di_flags,
1149812295 .compile_unit = compile_unit,
1149912296 });
1150012297}
1150112298
11502fn debugLexicalBlockAssumeCapacity(self: *Builder, file: Metadata, scope: Metadata, line: u32, column: u32) Metadata {
11503 return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{
11504 .file = file,
12299fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Metadata {
12300 return self.metadataDistinctAssumeCapacity(.lexical_block, Metadata.LexicalBlock{
1150512301 .scope = scope,
12302 .file = file,
1150612303 .line = line,
1150712304 .column = column,
1150812305 });
1150912306}
1151012307
11511fn debugLocationAssumeCapacity(self: *Builder, scope: Metadata, line: u32, column: u32, inlined_at: Metadata) Metadata {
12308fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Metadata {
1151212309 return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{
11513 .scope = scope,
1151412310 .line = line,
1151512311 .column = column,
12312 .scope = scope,
1151612313 .inlined_at = inlined_at,
1151712314 });
1151812315}
1151912316
1152012317fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
11521 return self.metadataSimpleAssumeCapacity(.basic_bool_type, Metadata.BasicType{
12318 return self.metadataDistinctAssumeCapacity(.basic_bool_type, Metadata.BasicType{
1152212319 .name = name,
1152312320 .size_in_bits_lo = @truncate(size_in_bits),
1152412321 .size_in_bits_hi = @truncate(size_in_bits >> 32),
......@@ -11526,7 +12323,7 @@ fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bit
1152612323}
1152712324
1152812325fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
11529 return self.metadataSimpleAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{
12326 return self.metadataDistinctAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{
1153012327 .name = name,
1153112328 .size_in_bits_lo = @truncate(size_in_bits),
1153212329 .size_in_bits_hi = @truncate(size_in_bits >> 32),
......@@ -11534,7 +12331,7 @@ fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in
1153412331}
1153512332
1153612333fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
11537 return self.metadataSimpleAssumeCapacity(.basic_signed_type, Metadata.BasicType{
12334 return self.metadataDistinctAssumeCapacity(.basic_signed_type, Metadata.BasicType{
1153812335 .name = name,
1153912336 .size_in_bits_lo = @truncate(size_in_bits),
1154012337 .size_in_bits_hi = @truncate(size_in_bits >> 32),
......@@ -11542,7 +12339,7 @@ fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_b
1154212339}
1154312340
1154412341fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
11545 return self.metadataSimpleAssumeCapacity(.basic_float_type, Metadata.BasicType{
12342 return self.metadataDistinctAssumeCapacity(.basic_float_type, Metadata.BasicType{
1154612343 .name = name,
1154712344 .size_in_bits_lo = @truncate(size_in_bits),
1154812345 .size_in_bits_hi = @truncate(size_in_bits >> 32),
......@@ -11687,84 +12484,18 @@ fn debugCompositeTypeAssumeCapacity(
1168712484 align_in_bits: u64,
1168812485 fields_tuple: Metadata,
1168912486) Metadata {
11690 const Key = struct {
11691 tag: Metadata.Tag,
11692 name: MetadataString,
11693 file: Metadata,
11694 scope: Metadata,
11695 line: u32,
11696 underlying_type: Metadata,
11697 size_in_bits: u64,
11698 align_in_bits: u64,
11699 fields_tuple: Metadata,
11700 };
11701 const Adapter = struct {
11702 builder: *const Builder,
11703 pub fn hash(_: @This(), key: Key) u32 {
11704 var hasher = std.hash.Wyhash.init(std.hash.uint32(@intFromEnum(key.tag)));
11705 hasher.update(std.mem.asBytes(&key.name));
11706 hasher.update(std.mem.asBytes(&key.file));
11707 hasher.update(std.mem.asBytes(&key.scope));
11708 hasher.update(std.mem.asBytes(&key.line));
11709 hasher.update(std.mem.asBytes(&key.underlying_type));
11710 hasher.update(std.mem.asBytes(&key.size_in_bits));
11711 hasher.update(std.mem.asBytes(&key.align_in_bits));
11712 hasher.update(std.mem.asBytes(&key.fields_tuple));
11713 return @truncate(hasher.final());
11714 }
11715
11716 pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
11717 if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
11718 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
11719 const rhs_extra = ctx.builder.metadataExtraData(Metadata.CompositeType, rhs_data);
11720 const rhs_size_in_bits = @as(u64, rhs_extra.size_in_bits_lo) | @as(u64, rhs_extra.size_in_bits_hi) << 32;
11721 const rhs_align_in_bits = @as(u64, rhs_extra.align_in_bits_lo) | @as(u64, rhs_extra.align_in_bits_hi) << 32;
11722 return lhs_key.name == rhs_extra.name and
11723 lhs_key.file == rhs_extra.file and
11724 lhs_key.scope == rhs_extra.scope and
11725 lhs_key.line == rhs_extra.line and
11726 lhs_key.underlying_type == rhs_extra.underlying_type and
11727 lhs_key.size_in_bits == rhs_size_in_bits and
11728 lhs_key.align_in_bits == rhs_align_in_bits and
11729 lhs_key.fields_tuple == rhs_extra.fields_tuple;
11730 }
11731 };
11732
11733 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
11734 Key{
11735 .tag = tag,
11736 .name = name,
11737 .file = file,
11738 .scope = scope,
11739 .line = line,
11740 .underlying_type = underlying_type,
11741 .size_in_bits = size_in_bits,
11742 .align_in_bits = align_in_bits,
11743 .fields_tuple = fields_tuple,
11744 },
11745 Adapter{ .builder = self },
11746 );
11747
11748 if (!gop.found_existing) {
11749 gop.key_ptr.* = {};
11750 gop.value_ptr.* = {};
11751 self.metadata_items.appendAssumeCapacity(.{
11752 .tag = tag,
11753 .data = self.addMetadataExtraAssumeCapacity(Metadata.CompositeType{
11754 .name = name,
11755 .file = file,
11756 .scope = scope,
11757 .line = line,
11758 .underlying_type = underlying_type,
11759 .size_in_bits_lo = @truncate(size_in_bits),
11760 .size_in_bits_hi = @truncate(size_in_bits >> 32),
11761 .align_in_bits_lo = @truncate(align_in_bits),
11762 .align_in_bits_hi = @truncate(align_in_bits >> 32),
11763 .fields_tuple = fields_tuple,
11764 }),
11765 });
11766 }
11767 return @enumFromInt(gop.index);
12487 return self.metadataDistinctAssumeCapacity(tag, Metadata.CompositeType{
12488 .name = name,
12489 .file = file,
12490 .scope = scope,
12491 .line = line,
12492 .underlying_type = underlying_type,
12493 .size_in_bits_lo = @truncate(size_in_bits),
12494 .size_in_bits_hi = @truncate(size_in_bits >> 32),
12495 .align_in_bits_lo = @truncate(align_in_bits),
12496 .align_in_bits_hi = @truncate(align_in_bits >> 32),
12497 .fields_tuple = fields_tuple,
12498 });
1176812499}
1176912500
1177012501fn debugPointerTypeAssumeCapacity(
......@@ -11778,7 +12509,7 @@ fn debugPointerTypeAssumeCapacity(
1177812509 align_in_bits: u64,
1177912510 offset_in_bits: u64,
1178012511) Metadata {
11781 return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{
12512 return self.metadataDistinctAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{
1178212513 .name = name,
1178312514 .file = file,
1178412515 .scope = scope,
......@@ -11804,7 +12535,7 @@ fn debugMemberTypeAssumeCapacity(
1180412535 align_in_bits: u64,
1180512536 offset_in_bits: u64,
1180612537) Metadata {
11807 return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{
12538 return self.metadataDistinctAssumeCapacity(.derived_member_type, Metadata.DerivedType{
1180812539 .name = name,
1180912540 .file = file,
1181012541 .scope = scope,
......@@ -11823,7 +12554,7 @@ fn debugSubroutineTypeAssumeCapacity(
1182312554 self: *Builder,
1182412555 types_tuple: Metadata,
1182512556) Metadata {
11826 return self.metadataSimpleAssumeCapacity(.subroutine_type, Metadata.SubroutineType{
12557 return self.metadataDistinctAssumeCapacity(.subroutine_type, Metadata.SubroutineType{
1182712558 .types_tuple = types_tuple,
1182812559 });
1182912560}
......@@ -11835,52 +12566,32 @@ fn debugEnumeratorAssumeCapacity(
1183512566 bit_width: u32,
1183612567 value: std.math.big.int.Const,
1183712568) Metadata {
11838 const Key = struct {
11839 tag: Metadata.Tag,
11840 name: MetadataString,
11841 bit_width: u32,
11842 value: std.math.big.int.Const,
11843 };
12569 const Key = struct { tag: Metadata.Tag, index: Metadata };
1184412570 const Adapter = struct {
11845 builder: *const Builder,
1184612571 pub fn hash(_: @This(), key: Key) u32 {
11847 var hasher = std.hash.Wyhash.init(std.hash.uint32(@intFromEnum(key.tag)));
11848 hasher.update(std.mem.asBytes(&key.name));
11849 hasher.update(std.mem.asBytes(&key.bit_width));
11850 hasher.update(std.mem.sliceAsBytes(key.value.limbs));
11851 return @truncate(hasher.final());
12572 return @truncate(std.hash.Wyhash.hash(
12573 std.hash.uint32(@intFromEnum(key.tag)),
12574 std.mem.asBytes(&key.index),
12575 ));
1185212576 }
1185312577
11854 pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
11855 if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
11856 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
11857 const rhs_extra = ctx.builder.metadataExtraData(Metadata.Enumerator, rhs_data);
11858 const limbs = ctx.builder.metadata_limbs
11859 .items[rhs_extra.limbs_index..][0..rhs_extra.limbs_len];
11860 const rhs_value = std.math.big.int.Const{
11861 .limbs = limbs,
11862 .positive = lhs_key.value.positive,
11863 };
11864 return lhs_key.name == rhs_extra.name and
11865 lhs_key.bit_width == rhs_extra.bit_width and
11866 lhs_key.value.eql(rhs_value);
12578 pub fn eql(_: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
12579 return @intFromEnum(lhs_key.index) == rhs_index;
1186712580 }
1186812581 };
1186912582
1187012583 const tag: Metadata.Tag = if (unsigned)
1187112584 .enumerator_unsigned
11872 else if (value.positive) .enumerator_signed_positive else .enumerator_signed_negative;
12585 else if (value.positive)
12586 .enumerator_signed_positive
12587 else
12588 .enumerator_signed_negative;
1187312589
1187412590 std.debug.assert(!(tag == .enumerator_unsigned and !value.positive));
1187512591
1187612592 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
11877 Key{
11878 .tag = tag,
11879 .name = name,
11880 .bit_width = bit_width,
11881 .value = value,
11882 },
11883 Adapter{ .builder = self },
12593 Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) },
12594 Adapter{},
1188412595 );
1188512596
1188612597 if (!gop.found_existing) {
......@@ -11905,7 +12616,7 @@ fn debugSubrangeAssumeCapacity(
1190512616 lower_bound: Metadata,
1190612617 count: Metadata,
1190712618) Metadata {
11908 return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{
12619 return self.metadataDistinctAssumeCapacity(.subrange, Metadata.Subrange{
1190912620 .lower_bound = lower_bound,
1191012621 .count = count,
1191112622 });
......@@ -12005,12 +12716,12 @@ fn debugTupleAssumeCapacity(
1200512716
1200612717fn debugModuleFlagAssumeCapacity(
1200712718 self: *Builder,
12008 behaviour: Metadata,
12719 behavior: Metadata,
1200912720 name: MetadataString,
1201012721 constant: Metadata,
1201112722) Metadata {
1201212723 return self.metadataSimpleAssumeCapacity(.module_flag, Metadata.ModuleFlag{
12013 .behaviour = behaviour,
12724 .behavior = behavior,
1201412725 .name = name,
1201512726 .constant = constant,
1201612727 });
......@@ -12024,7 +12735,7 @@ fn debugLocalVarAssumeCapacity(
1202412735 line: u32,
1202512736 ty: Metadata,
1202612737) Allocator.Error!Metadata {
12027 return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{
12738 return self.metadataDistinctAssumeCapacity(.local_var, Metadata.LocalVar{
1202812739 .name = name,
1202912740 .file = file,
1203012741 .scope = scope,
......@@ -12042,7 +12753,7 @@ fn debugParameterAssumeCapacity(
1204212753 ty: Metadata,
1204312754 arg_no: u32,
1204412755) Allocator.Error!Metadata {
12045 return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{
12756 return self.metadataDistinctAssumeCapacity(.parameter, Metadata.Parameter{
1204612757 .name = name,
1204712758 .file = file,
1204812759 .scope = scope,
......@@ -12061,10 +12772,10 @@ fn debugGlobalVarAssumeCapacity(
1206112772 line: u32,
1206212773 ty: Metadata,
1206312774 variable: Variable.Index,
12064 flags: Metadata.GlobalVar.Flags,
12775 options: Metadata.GlobalVar.Options,
1206512776) Allocator.Error!Metadata {
12066 return self.metadataSimpleAssumeCapacity(
12067 if (flags.local) .@"global_var local" else .global_var,
12777 return self.metadataDistinctAssumeCapacity(
12778 if (options.local) .@"global_var local" else .global_var,
1206812779 Metadata.GlobalVar{
1206912780 .name = name,
1207012781 .linkage_name = linkage_name,
......@@ -12082,7 +12793,7 @@ fn debugGlobalVarExpressionAssumeCapacity(
1208212793 variable: Metadata,
1208312794 expression: Metadata,
1208412795) Metadata {
12085 return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{
12796 return self.metadataDistinctAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{
1208612797 .variable = variable,
1208712798 .expression = expression,
1208812799 });
......@@ -12123,20 +12834,26 @@ fn debugConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {
1212312834pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]const u32 {
1212412835 const BitcodeWriter = bitcode_writer.BitcodeWriter(&.{ Type, FunctionAttributes });
1212512836 var bitcode = BitcodeWriter.init(allocator, &.{
12126 std.math.log2_int_ceil(usize, self.type_items.items.len - 1),
12127 std.math.log2_int_ceil(usize, self.function_attributes_set.count() - 1),
12837 if (self.type_items.items.len > 0)
12838 std.math.log2_int_ceil(usize, self.type_items.items.len)
12839 else
12840 undefined,
12841 if (self.type_items.items.len > 0)
12842 std.math.log2_int_ceil(usize, self.function_attributes_set.count())
12843 else
12844 undefined,
1212812845 });
1212912846 errdefer bitcode.deinit();
1213012847
1213112848 // Write LLVM IR magic
12132 try bitcode.writeBits(IR.MAGIC, 32);
12849 try bitcode.writeBits(ir.MAGIC, 32);
1213312850
12134 var record = std.ArrayListUnmanaged(u64){};
12851 var record: std.ArrayListUnmanaged(u64) = .{};
1213512852 defer record.deinit(self.gpa);
1213612853
1213712854 // IDENTIFICATION_BLOCK
1213812855 {
12139 const Identification = IR.Identification;
12856 const Identification = ir.Identification;
1214012857 var identification_block = try bitcode.enterTopBlock(Identification);
1214112858
1214212859 const producer = try std.fmt.allocPrint(self.gpa, "zig {d}.{d}.{d}", .{
......@@ -12154,7 +12871,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1215412871
1215512872 // MODULE_BLOCK
1215612873 {
12157 const Module = IR.Module;
12874 const Module = ir.Module;
1215812875 var module_block = try bitcode.enterTopBlock(Module);
1215912876
1216012877 try module_block.writeAbbrev(Module.Version{});
......@@ -12189,16 +12906,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1218912906
1219012907 // TYPE_BLOCK
1219112908 {
12192 var type_block = try module_block.enterSubBlock(IR.Type);
12909 var type_block = try module_block.enterSubBlock(ir.Type);
1219312910
12194 try type_block.writeAbbrev(IR.Type.NumEntry{ .num = @intCast(self.type_items.items.len) });
12911 try type_block.writeAbbrev(ir.Type.NumEntry{ .num = @intCast(self.type_items.items.len) });
1219512912
1219612913 for (self.type_items.items, 0..) |item, i| {
1219712914 const ty: Type = @enumFromInt(i);
1219812915
1219912916 switch (item.tag) {
12200 .simple => try type_block.writeAbbrev(IR.Type.Simple{ .code = @truncate(item.data) }),
12201 .integer => try type_block.writeAbbrev(IR.Type.Integer{ .width = item.data }),
12917 .simple => try type_block.writeAbbrev(ir.Type.Simple{ .code = @truncate(item.data) }),
12918 .integer => try type_block.writeAbbrev(ir.Type.Integer{ .width = item.data }),
1220212919 .structure,
1220312920 .packed_structure,
1220412921 => |kind| {
......@@ -12208,14 +12925,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1220812925 else => unreachable,
1220912926 };
1221012927 var extra = self.typeExtraDataTrail(Type.Structure, item.data);
12211 try type_block.writeAbbrev(IR.Type.StructAnon{
12928 try type_block.writeAbbrev(ir.Type.StructAnon{
1221212929 .is_packed = is_packed,
1221312930 .types = extra.trail.next(extra.data.fields_len, Type, self),
1221412931 });
1221512932 },
1221612933 .named_structure => {
1221712934 const extra = self.typeExtraData(Type.NamedStructure, item.data);
12218 try type_block.writeAbbrev(IR.Type.StructName{
12935 try type_block.writeAbbrev(ir.Type.StructName{
1221912936 .string = extra.id.slice(self).?,
1222012937 });
1222112938
......@@ -12227,36 +12944,36 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1222712944 };
1222812945
1222912946 var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data);
12230 try type_block.writeAbbrev(IR.Type.StructNamed{
12947 try type_block.writeAbbrev(ir.Type.StructNamed{
1223112948 .is_packed = is_packed,
1223212949 .types = real_extra.trail.next(real_extra.data.fields_len, Type, self),
1223312950 });
1223412951 },
1223512952 .array,
1223612953 .small_array,
12237 => try type_block.writeAbbrev(IR.Type.Array{
12954 => try type_block.writeAbbrev(ir.Type.Array{
1223812955 .len = ty.aggregateLen(self),
1223912956 .child = ty.childType(self),
1224012957 }),
1224112958 .vector,
1224212959 .scalable_vector,
12243 => try type_block.writeAbbrev(IR.Type.Vector{
12960 => try type_block.writeAbbrev(ir.Type.Vector{
1224412961 .len = ty.aggregateLen(self),
1224512962 .child = ty.childType(self),
1224612963 }),
12247 .pointer => try type_block.writeAbbrev(IR.Type.Pointer{
12964 .pointer => try type_block.writeAbbrev(ir.Type.Pointer{
1224812965 .addr_space = ty.pointerAddrSpace(self),
1224912966 }),
1225012967 .target => {
1225112968 var extra = self.typeExtraDataTrail(Type.Target, item.data);
12252 try type_block.writeAbbrev(IR.Type.StructName{
12969 try type_block.writeAbbrev(ir.Type.StructName{
1225312970 .string = extra.data.name.slice(self).?,
1225412971 });
1225512972
1225612973 const types = extra.trail.next(extra.data.types_len, Type, self);
1225712974 const ints = extra.trail.next(extra.data.ints_len, u32, self);
1225812975
12259 try type_block.writeAbbrev(IR.Type.Target{
12976 try type_block.writeAbbrev(ir.Type.Target{
1226012977 .num_types = extra.data.types_len,
1226112978 .types = types,
1226212979 .ints = ints,
......@@ -12269,7 +12986,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1226912986 else => unreachable,
1227012987 };
1227112988 var extra = self.typeExtraDataTrail(Type.Function, item.data);
12272 try type_block.writeAbbrev(IR.Type.Function{
12989 try type_block.writeAbbrev(ir.Type.Function{
1227312990 .is_vararg = is_vararg,
1227412991 .return_type = extra.data.ret,
1227512992 .param_types = extra.trail.next(extra.data.params_len, Type, self),
......@@ -12289,7 +13006,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1228913006
1229013007 // PARAMATTR_GROUP_BLOCK
1229113008 {
12292 const ParamattrGroup = IR.ParamattrGroup;
13009 const ParamattrGroup = ir.ParamattrGroup;
1229313010
1229413011 var paramattr_group_block = try module_block.enterSubBlock(ParamattrGroup);
1229513012
......@@ -12493,7 +13210,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1249313210
1249413211 // PARAMATTR_BLOCK
1249513212 {
12496 const Paramattr = IR.Paramattr;
13213 const Paramattr = ir.Paramattr;
1249713214 var paramattr_block = try module_block.enterSubBlock(Paramattr);
1249813215
1249913216 for (self.function_attributes_set.keys()) |func_attributes| {
......@@ -12517,7 +13234,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1251713234 try paramattr_block.end();
1251813235 }
1251913236
12520 var globals = std.AutoArrayHashMapUnmanaged(Global.Index, void){};
13237 var globals: std.AutoArrayHashMapUnmanaged(Global.Index, void) = .{};
1252113238 defer globals.deinit(self.gpa);
1252213239 try globals.ensureUnusedCapacity(
1252313240 self.gpa,
......@@ -12696,7 +13413,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1269613413
1269713414 // CONSTANTS_BLOCK
1269813415 {
12699 const Constants = IR.Constants;
13416 const Constants = ir.Constants;
1270013417 var constants_block = try module_block.enterSubBlock(Constants);
1270113418
1270213419 var current_type: Type = .none;
......@@ -12725,7 +13442,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1272513442 @ptrCast(self.constant_limbs.items[data..][0..Constant.Integer.limbs]);
1272613443 const limbs = self.constant_limbs
1272713444 .items[data + Constant.Integer.limbs ..][0..extra.limbs_len];
12728 const bigint = std.math.big.int.Const{
13445 const bigint: std.math.big.int.Const = .{
1272913446 .limbs = limbs,
1273013447 .positive = tag == .positive_integer,
1273113448 };
......@@ -13062,7 +13779,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1306213779
1306313780 // METADATA_BLOCK
1306413781 if (!self.strip) {
13065 const MetadataBlock = IR.MetadataBlock;
13782 const MetadataBlock = ir.MetadataBlock;
1306613783 var metadata_block = try module_block.enterSubBlock(MetadataBlock);
1306713784
1306813785 const MetadataBlockWriter = @TypeOf(metadata_block);
......@@ -13115,50 +13832,45 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1311513832 try bitcode.alignTo32();
1311613833 }
1311713834
13118 for (1..self.metadata_items.len) |metadata_index| {
13119 const tag = self.metadata_items.items(.tag)[metadata_index];
13120 const data = self.metadata_items.items(.data)[metadata_index];
13835 for (
13836 self.metadata_items.items(.tag)[1..],
13837 self.metadata_items.items(.data)[1..],
13838 ) |tag, data| {
1312113839 switch (tag) {
1312213840 .none => unreachable,
1312313841 .file => {
1312413842 const extra = self.metadataExtraData(Metadata.File, data);
1312513843
1312613844 try metadata_block.writeAbbrevAdapted(MetadataBlock.File{
13127 .name = extra.name,
13128 .path = extra.path,
13845 .filename = extra.filename,
13846 .directory = extra.directory,
1312913847 }, metadata_adapter);
1313013848 },
13131 .compile_unit, .@"compile_unit optimized" => |kind| {
13132 const is_optimized = kind == .@"compile_unit optimized";
13849 .compile_unit,
13850 .@"compile_unit optimized",
13851 => |kind| {
1313313852 const extra = self.metadataExtraData(Metadata.CompileUnit, data);
1313413853 try metadata_block.writeAbbrevAdapted(MetadataBlock.CompileUnit{
1313513854 .file = extra.file,
1313613855 .producer = extra.producer,
13137 .is_optimized = is_optimized,
13856 .is_optimized = switch (kind) {
13857 .compile_unit => false,
13858 .@"compile_unit optimized" => true,
13859 else => unreachable,
13860 },
1313813861 .enums = extra.enums,
1313913862 .globals = extra.globals,
1314013863 }, metadata_adapter);
1314113864 },
1314213865 .subprogram,
13143 .@"subprogram optimized",
1314413866 .@"subprogram local",
1314513867 .@"subprogram definition",
13868 .@"subprogram local definition",
13869 .@"subprogram optimized",
1314613870 .@"subprogram optimized local",
1314713871 .@"subprogram optimized definition",
1314813872 .@"subprogram optimized local definition",
13149 .@"subprogram local definition",
1315013873 => |kind| {
13151 const sp_flags: u32 = switch (kind) {
13152 .subprogram => 0,
13153 .@"subprogram optimized" => 1 << 4,
13154 .@"subprogram local" => 1 << 2,
13155 .@"subprogram definition" => 1 << 3,
13156 .@"subprogram optimized local" => (1 << 4) | (1 << 2),
13157 .@"subprogram optimized definition" => (1 << 4) | (1 << 3),
13158 .@"subprogram optimized local definition" => (1 << 4) | (1 << 2) | (1 << 3),
13159 .@"subprogram local definition" => (1 << 2) | (1 << 3),
13160 else => unreachable,
13161 };
1316213874 const extra = self.metadataExtraData(Metadata.Subprogram, data);
1316313875
1316413876 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{
......@@ -13167,10 +13879,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1316713879 .linkage_name = extra.linkage_name,
1316813880 .file = extra.file,
1316913881 .line = extra.line,
13170 .ty = Metadata.none, //extra.ty,
13882 .ty = .none, //extra.ty,
1317113883 .scope_line = extra.scope_line,
13172 .sp_flags = sp_flags,
13173 .flags = extra.debug_info_flags,
13884 .sp_flags = @bitCast(@as(u32, @as(u3, @intCast(
13885 @intFromEnum(kind) - @intFromEnum(Metadata.Tag.subprogram),
13886 ))) << 2),
13887 .flags = extra.di_flags,
1317413888 .compile_unit = extra.compile_unit,
1317513889 }, metadata_adapter);
1317613890 },
......@@ -13185,7 +13899,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1318513899 },
1318613900 .location => {
1318713901 const extra = self.metadataExtraData(Metadata.Location, data);
13188 std.debug.assert(extra.scope != Metadata.none);
13902 std.debug.assert(extra.scope != .none);
1318913903 try metadata_block.writeAbbrev(MetadataBlock.Location{
1319013904 .line = extra.line,
1319113905 .column = extra.column,
......@@ -13201,12 +13915,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1320113915 const extra = self.metadataExtraData(Metadata.BasicType, data);
1320213916 try metadata_block.writeAbbrevAdapted(MetadataBlock.BasicType{
1320313917 .name = extra.name,
13204 .size_in_bits = @as(u64, extra.size_in_bits_lo) | @as(u64, extra.size_in_bits_hi) << 32,
13918 .size_in_bits = extra.bitSize(),
1320513919 .encoding = switch (kind) {
13206 .basic_bool_type => std.dwarf.ATE.boolean,
13207 .basic_unsigned_type => std.dwarf.ATE.unsigned,
13208 .basic_signed_type => std.dwarf.ATE.signed,
13209 .basic_float_type => std.dwarf.ATE.float,
13920 .basic_bool_type => DW.ATE.boolean,
13921 .basic_unsigned_type => DW.ATE.unsigned,
13922 .basic_signed_type => DW.ATE.signed,
13923 .basic_float_type => DW.ATE.float,
1321013924 else => unreachable,
1321113925 },
1321213926 }, metadata_adapter);
......@@ -13221,12 +13935,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1322113935
1322213936 try metadata_block.writeAbbrevAdapted(MetadataBlock.CompositeType{
1322313937 .tag = switch (kind) {
13224 .composite_struct_type => std.dwarf.TAG.structure_type,
13225 .composite_union_type => std.dwarf.TAG.union_type,
13226 .composite_enumeration_type => std.dwarf.TAG.enumeration_type,
13227 .composite_array_type,
13228 .composite_vector_type,
13229 => std.dwarf.TAG.array_type,
13938 .composite_struct_type => DW.TAG.structure_type,
13939 .composite_union_type => DW.TAG.union_type,
13940 .composite_enumeration_type => DW.TAG.enumeration_type,
13941 .composite_array_type, .composite_vector_type => DW.TAG.array_type,
1323013942 else => unreachable,
1323113943 },
1323213944 .name = extra.name,
......@@ -13234,9 +13946,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1323413946 .line = extra.line,
1323513947 .scope = extra.scope,
1323613948 .underlying_type = extra.underlying_type,
13237 .size_in_bits = @as(u64, extra.size_in_bits_lo) | @as(u64, extra.size_in_bits_hi) << 32,
13238 .align_in_bits = @as(u64, extra.align_in_bits_lo) | @as(u64, extra.align_in_bits_hi) << 32,
13239 .flags = if (kind == .composite_vector_type) DIFlags.Vector else 0,
13949 .size_in_bits = extra.bitSize(),
13950 .align_in_bits = extra.bitAlign(),
13951 .flags = if (kind == .composite_vector_type) .{ .Vector = true } else .{},
1324013952 .elements = extra.fields_tuple,
1324113953 }, metadata_adapter);
1324213954 },
......@@ -13246,8 +13958,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1324613958 const extra = self.metadataExtraData(Metadata.DerivedType, data);
1324713959 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{
1324813960 .tag = switch (kind) {
13249 .derived_pointer_type => std.dwarf.TAG.pointer_type,
13250 .derived_member_type => std.dwarf.TAG.member,
13961 .derived_pointer_type => DW.TAG.pointer_type,
13962 .derived_member_type => DW.TAG.member,
1325113963 else => unreachable,
1325213964 },
1325313965 .name = extra.name,
......@@ -13255,9 +13967,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1325513967 .line = extra.line,
1325613968 .scope = extra.scope,
1325713969 .underlying_type = extra.underlying_type,
13258 .size_in_bits = @as(u64, extra.size_in_bits_lo) | @as(u64, extra.size_in_bits_hi) << 32,
13259 .align_in_bits = @as(u64, extra.align_in_bits_lo) | @as(u64, extra.align_in_bits_hi) << 32,
13260 .offset_in_bits = @as(u64, extra.offset_in_bits_lo) | @as(u64, extra.offset_in_bits_hi) << 32,
13970 .size_in_bits = extra.bitSize(),
13971 .align_in_bits = extra.bitAlign(),
13972 .offset_in_bits = extra.bitOffset(),
1326113973 }, metadata_adapter);
1326213974 },
1326313975 .subroutine_type => {
......@@ -13291,7 +14003,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1329114003
1329214004 const limbs = self.metadata_limbs.items[extra.limbs_index..][0..extra.limbs_len];
1329314005
13294 const bigint = std.math.big.int.Const{
14006 const bigint: std.math.big.int.Const = .{
1329514007 .limbs = limbs,
1329614008 .positive = positive,
1329714009 };
......@@ -13315,7 +14027,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1331514027 const word_count = std.mem.alignForward(u32, extra.bit_width, 64) / 64;
1331614028 try record.ensureUnusedCapacity(self.gpa, 3 + word_count);
1331714029
13318 const flags = MetadataBlock.Enumerator.Flags{
14030 const flags: MetadataBlock.Enumerator.Flags = .{
1331914031 .unsigned = unsigned,
1332014032 .bigint = true,
1332114033 };
......@@ -13375,7 +14087,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1337514087 const extra = self.metadataExtraData(Metadata.ModuleFlag, data);
1337614088 try metadata_block.writeAbbrev(MetadataBlock.Node{
1337714089 .elements = &.{
13378 @enumFromInt(metadata_adapter.getMetadataIndex(extra.behaviour)),
14090 @enumFromInt(metadata_adapter.getMetadataIndex(extra.behavior)),
1337914091 @enumFromInt(metadata_adapter.getMetadataStringIndex(extra.name)),
1338014092 @enumFromInt(metadata_adapter.getMetadataIndex(extra.constant)),
1338114093 },
......@@ -13534,7 +14246,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1353414246 };
1353514247
1353614248 for (self.functions.items, 0..) |func, func_index| {
13537 const FunctionBlock = IR.FunctionBlock;
14249 const FunctionBlock = ir.FunctionBlock;
1353814250 if (func.global.getReplacement(self) != .none) continue;
1353914251
1354014252 if (func.instructions.len == 0) continue;
......@@ -13547,7 +14259,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1354714259
1354814260 // Emit function level metadata block
1354914261 if (!self.strip and func.debug_values.len != 0) {
13550 const MetadataBlock = IR.FunctionMetadataBlock;
14262 const MetadataBlock = ir.FunctionMetadataBlock;
1355114263 var metadata_block = try function_block.enterSubBlock(MetadataBlock);
1355214264
1355314265 for (func.debug_values) |value| {
......@@ -13656,10 +14368,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1365614368 .srem,
1365714369 .ashr,
1365814370 .@"ashr exact",
13659 => {
14371 => |kind| {
1366014372 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
1366114373 try function_block.writeAbbrev(FunctionBlock.Binary{
13662 .opcode = tag.toBinaryOpcode(),
14374 .opcode = kind.toBinaryOpcode(),
1366314375 .lhs = adapter.getOffsetValueIndex(extra.lhs),
1366414376 .rhs = adapter.getOffsetValueIndex(extra.rhs),
1366514377 });
......@@ -13669,10 +14381,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1366914381 .@"fmul fast",
1367014382 .@"frem fast",
1367114383 .@"fsub fast",
13672 => {
14384 => |kind| {
1367314385 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
1367414386 try function_block.writeAbbrev(FunctionBlock.BinaryFast{
13675 .opcode = tag.toBinaryOpcode(),
14387 .opcode = kind.toBinaryOpcode(),
1367614388 .lhs = adapter.getOffsetValueIndex(extra.lhs),
1367714389 .rhs = adapter.getOffsetValueIndex(extra.rhs),
1367814390 .fast_math = .{},
......@@ -13709,12 +14421,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1370914421 .fpext,
1371014422 .sext,
1371114423 .zext,
13712 => {
14424 => |kind| {
1371314425 const extra = func.extraData(Function.Instruction.Cast, datas[instr_index]);
1371414426 try function_block.writeAbbrev(FunctionBlock.Cast{
1371514427 .val = adapter.getOffsetValueIndex(extra.val),
1371614428 .type_index = extra.type,
13717 .opcode = tag.toCastOpcode(),
14429 .opcode = kind.toCastOpcode(),
1371814430 });
1371914431 },
1372014432 .@"fcmp false",
......@@ -13743,12 +14455,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1374314455 .@"icmp ugt",
1374414456 .@"icmp ule",
1374514457 .@"icmp ult",
13746 => {
14458 => |kind| {
1374714459 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
1374814460 try function_block.writeAbbrev(FunctionBlock.Cmp{
1374914461 .lhs = adapter.getOffsetValueIndex(extra.lhs),
1375014462 .rhs = adapter.getOffsetValueIndex(extra.rhs),
13751 .pred = tag.toCmpPredicate(),
14463 .pred = kind.toCmpPredicate(),
1375214464 });
1375314465 },
1375414466 .@"fcmp fast false",
......@@ -13767,12 +14479,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1376714479 .@"fcmp fast ult",
1376814480 .@"fcmp fast une",
1376914481 .@"fcmp fast uno",
13770 => {
14482 => |kind| {
1377114483 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
1377214484 try function_block.writeAbbrev(FunctionBlock.CmpFast{
1377314485 .lhs = adapter.getOffsetValueIndex(extra.lhs),
1377414486 .rhs = adapter.getOffsetValueIndex(extra.rhs),
13775 .pred = tag.toCmpPredicate(),
14487 .pred = kind.toCmpPredicate(),
1377614488 .fast_math = .{},
1377714489 });
1377814490 },
......@@ -13842,12 +14554,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1384214554 },
1384314555 .getelementptr,
1384414556 .@"getelementptr inbounds",
13845 => {
14557 => |kind| {
1384614558 var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, datas[instr_index]);
1384714559 const indices = extra.trail.next(extra.data.indices_len, Value, &func);
1384814560 try function_block.writeAbbrevAdapted(
1384914561 FunctionBlock.GetElementPtr{
13850 .is_inbounds = tag == .@"getelementptr inbounds",
14562 .is_inbounds = kind == .@"getelementptr inbounds",
1385114563 .type_index = extra.data.type,
1385214564 .base = extra.data.base,
1385314565 .indices = indices,
......@@ -14008,13 +14720,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1400814720 }
1400914721
1401014722 if (!self.strip) {
14011 if (func.debug_locations.get(@enumFromInt(instr_index))) |maybe_location| {
14012 if (maybe_location) |location| {
14723 if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| {
14724 if (debug_location != .none) {
14725 const location = self.metadata_items.get(@intFromEnum(debug_location));
14726 assert(location.tag == .location);
14727 const extra = self.metadataExtraData(Metadata.Location, location.data);
1401314728 try function_block.writeAbbrev(FunctionBlock.DebugLoc{
14014 .line = location.line,
14015 .column = location.column,
14016 .scope = @enumFromInt(metadata_adapter.getMetadataIndex(location.scope)),
14017 .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(location.inlined_at)),
14729 .line = extra.line,
14730 .column = extra.column,
14731 .scope = @enumFromInt(metadata_adapter.getMetadataIndex(extra.scope)),
14732 .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(extra.inlined_at)),
1401814733 .is_implicit = false,
1401914734 });
1402014735 has_location = true;
......@@ -14031,7 +14746,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1403114746
1403214747 // VALUE_SYMTAB
1403314748 if (!self.strip) {
14034 const ValueSymbolTable = IR.FunctionValueSymbolTable;
14749 const ValueSymbolTable = ir.FunctionValueSymbolTable;
1403514750
1403614751 var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable);
1403714752
......@@ -14060,7 +14775,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1406014775
1406114776 // STRTAB_BLOCK
1406214777 {
14063 const Strtab = IR.Strtab;
14778 const Strtab = ir.Strtab;
1406414779 var strtab_block = try bitcode.enterTopBlock(Strtab);
1406514780
1406614781 try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.string_bytes.items });
......@@ -14071,14 +14786,13 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1407114786 return bitcode.toSlice();
1407214787}
1407314788
14789const Allocator = std.mem.Allocator;
1407414790const assert = std.debug.assert;
14791const bitcode_writer = @import("bitcode_writer.zig");
1407514792const build_options = @import("build_options");
14793const Builder = @This();
1407614794const builtin = @import("builtin");
14795const DW = std.dwarf;
14796const ir = @import("ir.zig");
1407714797const log = std.log.scoped(.llvm);
1407814798const std = @import("std");
14079
14080const bitcode_writer = @import("bitcode_writer.zig");
14081const IR = @import("IR.zig");
14082
14083const Allocator = std.mem.Allocator;
14084const Builder = @This();
src/codegen/llvm/IR.zig deleted-1574
......@@ -1,1574 +0,0 @@
1const std = @import("std");
2const Builder = @import("Builder.zig");
3const bitcode_writer = @import("bitcode_writer.zig");
4
5const AbbrevOp = bitcode_writer.AbbrevOp;
6
7pub const MAGIC: u32 = 0xdec04342;
8
9const ValueAbbrev = AbbrevOp{ .vbr = 6 };
10const ValueArrayAbbrev = AbbrevOp{ .array_vbr = 6 };
11
12const ConstantAbbrev = AbbrevOp{ .vbr = 6 };
13const ConstantArrayAbbrev = AbbrevOp{ .array_vbr = 6 };
14
15const MetadataAbbrev = AbbrevOp{ .vbr = 16 };
16const MetadataArrayAbbrev = AbbrevOp{ .array_vbr = 16 };
17
18const LineAbbrev = AbbrevOp{ .vbr = 8 };
19const ColumnAbbrev = AbbrevOp{ .vbr = 8 };
20
21const BlockAbbrev = AbbrevOp{ .vbr = 6 };
22
23pub const Identification = struct {
24 pub const id = 13;
25
26 pub const abbrevs = [_]type{
27 Version,
28 Epoch,
29 };
30
31 pub const Version = struct {
32 pub const ops = [_]AbbrevOp{
33 .{ .literal = 1 },
34 .{ .array_fixed = 8 },
35 };
36 string: []const u8,
37 };
38
39 pub const Epoch = struct {
40 pub const ops = [_]AbbrevOp{
41 .{ .literal = 2 },
42 .{ .vbr = 6 },
43 };
44 epoch: u32,
45 };
46};
47
48pub const Module = struct {
49 pub const id = 8;
50
51 pub const abbrevs = [_]type{
52 Version,
53 String,
54 Variable,
55 Function,
56 Alias,
57 };
58
59 pub const Version = struct {
60 pub const ops = [_]AbbrevOp{
61 .{ .literal = 1 },
62 .{ .literal = 2 },
63 };
64 };
65
66 pub const String = struct {
67 pub const ops = [_]AbbrevOp{
68 .{ .vbr = 4 },
69 .{ .array_fixed = 8 },
70 };
71 code: u16,
72 string: []const u8,
73 };
74
75 pub const Variable = struct {
76 const AddrSpaceAndIsConst = packed struct {
77 is_const: bool,
78 one: u1 = 1,
79 addr_space: Builder.AddrSpace,
80 };
81
82 pub const ops = [_]AbbrevOp{
83 .{ .literal = 7 }, // Code
84 .{ .vbr = 16 }, // strtab_offset
85 .{ .vbr = 16 }, // strtab_size
86 .{ .fixed_runtime = Builder.Type },
87 .{ .fixed = @bitSizeOf(AddrSpaceAndIsConst) }, // isconst
88 ConstantAbbrev, // initid
89 .{ .fixed = @bitSizeOf(Builder.Linkage) },
90 .{ .fixed = @bitSizeOf(Builder.Alignment) },
91 .{ .vbr = 16 }, // section
92 .{ .fixed = @bitSizeOf(Builder.Visibility) },
93 .{ .fixed = @bitSizeOf(Builder.ThreadLocal) }, // threadlocal
94 .{ .fixed = @bitSizeOf(Builder.UnnamedAddr) },
95 .{ .fixed = @bitSizeOf(Builder.ExternallyInitialized) },
96 .{ .fixed = @bitSizeOf(Builder.DllStorageClass) },
97 .{ .literal = 0 }, // comdat
98 .{ .literal = 0 }, // attributes
99 .{ .fixed = @bitSizeOf(Builder.Preemption) },
100 };
101 strtab_offset: usize,
102 strtab_size: usize,
103 type_index: Builder.Type,
104 is_const: AddrSpaceAndIsConst,
105 initid: u32,
106 linkage: Builder.Linkage,
107 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
108 section: usize,
109 visibility: Builder.Visibility,
110 thread_local: Builder.ThreadLocal,
111 unnamed_addr: Builder.UnnamedAddr,
112 externally_initialized: Builder.ExternallyInitialized,
113 dllstorageclass: Builder.DllStorageClass,
114 preemption: Builder.Preemption,
115 };
116
117 pub const Function = struct {
118 pub const ops = [_]AbbrevOp{
119 .{ .literal = 8 }, // Code
120 .{ .vbr = 16 }, // strtab_offset
121 .{ .vbr = 16 }, // strtab_size
122 .{ .fixed_runtime = Builder.Type },
123 .{ .fixed = @bitSizeOf(Builder.CallConv) },
124 .{ .fixed = 1 }, // isproto
125 .{ .fixed = @bitSizeOf(Builder.Linkage) },
126 .{ .vbr = 16 }, // paramattr
127 .{ .fixed = @bitSizeOf(Builder.Alignment) },
128 .{ .vbr = 16 }, // section
129 .{ .fixed = @bitSizeOf(Builder.Visibility) },
130 .{ .literal = 0 }, // gc
131 .{ .fixed = @bitSizeOf(Builder.UnnamedAddr) },
132 .{ .literal = 0 }, // prologuedata
133 .{ .fixed = @bitSizeOf(Builder.DllStorageClass) },
134 .{ .literal = 0 }, // comdat
135 .{ .literal = 0 }, // prefixdata
136 .{ .literal = 0 }, // personalityfn
137 .{ .fixed = @bitSizeOf(Builder.Preemption) },
138 .{ .fixed = @bitSizeOf(Builder.AddrSpace) },
139 };
140 strtab_offset: usize,
141 strtab_size: usize,
142 type_index: Builder.Type,
143 call_conv: Builder.CallConv,
144 is_proto: bool,
145 linkage: Builder.Linkage,
146 paramattr: usize,
147 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
148 section: usize,
149 visibility: Builder.Visibility,
150 unnamed_addr: Builder.UnnamedAddr,
151 dllstorageclass: Builder.DllStorageClass,
152 preemption: Builder.Preemption,
153 addr_space: Builder.AddrSpace,
154 };
155
156 pub const Alias = struct {
157 pub const ops = [_]AbbrevOp{
158 .{ .literal = 9 }, // Code
159 .{ .vbr = 16 }, // strtab_offset
160 .{ .vbr = 16 }, // strtab_size
161 .{ .fixed_runtime = Builder.Type },
162 .{ .fixed = @bitSizeOf(Builder.AddrSpace) },
163 ConstantAbbrev, // aliasee val
164 .{ .fixed = @bitSizeOf(Builder.Linkage) },
165 .{ .fixed = @bitSizeOf(Builder.Visibility) },
166 .{ .fixed = @bitSizeOf(Builder.DllStorageClass) },
167 .{ .fixed = @bitSizeOf(Builder.ThreadLocal) },
168 .{ .fixed = @bitSizeOf(Builder.UnnamedAddr) },
169 .{ .fixed = @bitSizeOf(Builder.Preemption) },
170 };
171 strtab_offset: usize,
172 strtab_size: usize,
173 type_index: Builder.Type,
174 addr_space: Builder.AddrSpace,
175 aliasee: u32,
176 linkage: Builder.Linkage,
177 visibility: Builder.Visibility,
178 dllstorageclass: Builder.DllStorageClass,
179 thread_local: Builder.ThreadLocal,
180 unnamed_addr: Builder.UnnamedAddr,
181 preemption: Builder.Preemption,
182 };
183};
184
185pub const Type = struct {
186 pub const id = 17;
187
188 pub const abbrevs = [_]type{
189 NumEntry,
190 Simple,
191 Integer,
192 StructAnon,
193 StructNamed,
194 StructName,
195 Array,
196 Vector,
197 Pointer,
198 Target,
199 Function,
200 };
201
202 pub const NumEntry = struct {
203 pub const ops = [_]AbbrevOp{
204 .{ .literal = 1 },
205 .{ .fixed = 32 },
206 };
207 num: u32,
208 };
209
210 pub const Simple = struct {
211 pub const ops = [_]AbbrevOp{
212 .{ .vbr = 4 },
213 };
214 code: u5,
215 };
216
217 pub const Integer = struct {
218 pub const ops = [_]AbbrevOp{
219 .{ .literal = 7 },
220 .{ .fixed = 28 },
221 };
222 width: u28,
223 };
224
225 pub const StructAnon = struct {
226 pub const ops = [_]AbbrevOp{
227 .{ .literal = 18 },
228 .{ .fixed = 1 },
229 .{ .array_fixed_runtime = Builder.Type },
230 };
231 is_packed: bool,
232 types: []const Builder.Type,
233 };
234
235 pub const StructNamed = struct {
236 pub const ops = [_]AbbrevOp{
237 .{ .literal = 20 },
238 .{ .fixed = 1 },
239 .{ .array_fixed_runtime = Builder.Type },
240 };
241 is_packed: bool,
242 types: []const Builder.Type,
243 };
244
245 pub const StructName = struct {
246 pub const ops = [_]AbbrevOp{
247 .{ .literal = 19 },
248 .{ .array_fixed = 8 },
249 };
250 string: []const u8,
251 };
252
253 pub const Array = struct {
254 pub const ops = [_]AbbrevOp{
255 .{ .literal = 11 },
256 .{ .vbr = 16 },
257 .{ .fixed_runtime = Builder.Type },
258 };
259 len: u64,
260 child: Builder.Type,
261 };
262
263 pub const Vector = struct {
264 pub const ops = [_]AbbrevOp{
265 .{ .literal = 12 },
266 .{ .vbr = 16 },
267 .{ .fixed_runtime = Builder.Type },
268 };
269 len: u64,
270 child: Builder.Type,
271 };
272
273 pub const Pointer = struct {
274 pub const ops = [_]AbbrevOp{
275 .{ .literal = 25 },
276 .{ .vbr = 4 },
277 };
278 addr_space: Builder.AddrSpace,
279 };
280
281 pub const Target = struct {
282 pub const ops = [_]AbbrevOp{
283 .{ .literal = 26 },
284 .{ .vbr = 4 },
285 .{ .array_fixed_runtime = Builder.Type },
286 .{ .array_fixed = 32 },
287 };
288 num_types: u32,
289 types: []const Builder.Type,
290 ints: []const u32,
291 };
292
293 pub const Function = struct {
294 pub const ops = [_]AbbrevOp{
295 .{ .literal = 21 },
296 .{ .fixed = 1 },
297 .{ .fixed_runtime = Builder.Type },
298 .{ .array_fixed_runtime = Builder.Type },
299 };
300 is_vararg: bool,
301 return_type: Builder.Type,
302 param_types: []const Builder.Type,
303 };
304};
305
306pub const Paramattr = struct {
307 pub const id = 9;
308
309 pub const abbrevs = [_]type{
310 Entry,
311 };
312
313 pub const Entry = struct {
314 pub const ops = [_]AbbrevOp{
315 .{ .literal = 2 },
316 .{ .array_vbr = 8 },
317 };
318 group_indices: []const u64,
319 };
320};
321
322pub const ParamattrGroup = struct {
323 pub const id = 10;
324
325 pub const abbrevs = [_]type{};
326};
327
328pub const Constants = struct {
329 pub const id = 11;
330
331 pub const abbrevs = [_]type{
332 SetType,
333 Null,
334 Undef,
335 Poison,
336 Integer,
337 Half,
338 Float,
339 Double,
340 Fp80,
341 Fp128,
342 Aggregate,
343 String,
344 CString,
345 Cast,
346 Binary,
347 Cmp,
348 ExtractElement,
349 InsertElement,
350 ShuffleVector,
351 ShuffleVectorEx,
352 BlockAddress,
353 DsoLocalEquivalentOrNoCfi,
354 };
355
356 pub const SetType = struct {
357 pub const ops = [_]AbbrevOp{
358 .{ .literal = 1 },
359 .{ .fixed_runtime = Builder.Type },
360 };
361 type_id: Builder.Type,
362 };
363
364 pub const Null = struct {
365 pub const ops = [_]AbbrevOp{
366 .{ .literal = 2 },
367 };
368 };
369
370 pub const Undef = struct {
371 pub const ops = [_]AbbrevOp{
372 .{ .literal = 3 },
373 };
374 };
375
376 pub const Poison = struct {
377 pub const ops = [_]AbbrevOp{
378 .{ .literal = 26 },
379 };
380 };
381
382 pub const Integer = struct {
383 pub const ops = [_]AbbrevOp{
384 .{ .literal = 4 },
385 .{ .vbr = 16 },
386 };
387 value: u64,
388 };
389
390 pub const Half = struct {
391 pub const ops = [_]AbbrevOp{
392 .{ .literal = 6 },
393 .{ .fixed = 16 },
394 };
395 value: u16,
396 };
397
398 pub const Float = struct {
399 pub const ops = [_]AbbrevOp{
400 .{ .literal = 6 },
401 .{ .fixed = 32 },
402 };
403 value: u32,
404 };
405
406 pub const Double = struct {
407 pub const ops = [_]AbbrevOp{
408 .{ .literal = 6 },
409 .{ .vbr = 6 },
410 };
411 value: u64,
412 };
413
414 pub const Fp80 = struct {
415 pub const ops = [_]AbbrevOp{
416 .{ .literal = 6 },
417 .{ .vbr = 6 },
418 .{ .vbr = 6 },
419 };
420 lo: u64,
421 hi: u16,
422 };
423
424 pub const Fp128 = struct {
425 pub const ops = [_]AbbrevOp{
426 .{ .literal = 6 },
427 .{ .vbr = 6 },
428 .{ .vbr = 6 },
429 };
430 lo: u64,
431 hi: u64,
432 };
433
434 pub const Aggregate = struct {
435 pub const ops = [_]AbbrevOp{
436 .{ .literal = 7 },
437 .{ .array_fixed = 32 },
438 };
439 values: []const Builder.Constant,
440 };
441
442 pub const String = struct {
443 pub const ops = [_]AbbrevOp{
444 .{ .literal = 8 },
445 .{ .array_fixed = 8 },
446 };
447 string: []const u8,
448 };
449
450 pub const CString = struct {
451 pub const ops = [_]AbbrevOp{
452 .{ .literal = 9 },
453 .{ .array_fixed = 8 },
454 };
455 string: []const u8,
456 };
457
458 pub const Cast = struct {
459 const CastOpcode = Builder.CastOpcode;
460 pub const ops = [_]AbbrevOp{
461 .{ .literal = 11 },
462 .{ .fixed = @bitSizeOf(CastOpcode) },
463 .{ .fixed_runtime = Builder.Type },
464 ConstantAbbrev,
465 };
466
467 opcode: CastOpcode,
468 type_index: Builder.Type,
469 val: Builder.Constant,
470 };
471
472 pub const Binary = struct {
473 const BinaryOpcode = Builder.BinaryOpcode;
474 pub const ops = [_]AbbrevOp{
475 .{ .literal = 10 },
476 .{ .fixed = @bitSizeOf(BinaryOpcode) },
477 ConstantAbbrev,
478 ConstantAbbrev,
479 };
480
481 opcode: BinaryOpcode,
482 lhs: Builder.Constant,
483 rhs: Builder.Constant,
484 };
485
486 pub const Cmp = struct {
487 pub const ops = [_]AbbrevOp{
488 .{ .literal = 17 },
489 .{ .fixed_runtime = Builder.Type },
490 ConstantAbbrev,
491 ConstantAbbrev,
492 .{ .vbr = 6 },
493 };
494
495 ty: Builder.Type,
496 lhs: Builder.Constant,
497 rhs: Builder.Constant,
498 pred: u32,
499 };
500
501 pub const ExtractElement = struct {
502 pub const ops = [_]AbbrevOp{
503 .{ .literal = 14 },
504 .{ .fixed_runtime = Builder.Type },
505 ConstantAbbrev,
506 .{ .fixed_runtime = Builder.Type },
507 ConstantAbbrev,
508 };
509
510 val_type: Builder.Type,
511 val: Builder.Constant,
512 index_type: Builder.Type,
513 index: Builder.Constant,
514 };
515
516 pub const InsertElement = struct {
517 pub const ops = [_]AbbrevOp{
518 .{ .literal = 15 },
519 ConstantAbbrev,
520 ConstantAbbrev,
521 .{ .fixed_runtime = Builder.Type },
522 ConstantAbbrev,
523 };
524
525 val: Builder.Constant,
526 elem: Builder.Constant,
527 index_type: Builder.Type,
528 index: Builder.Constant,
529 };
530
531 pub const ShuffleVector = struct {
532 pub const ops = [_]AbbrevOp{
533 .{ .literal = 16 },
534 ValueAbbrev,
535 ValueAbbrev,
536 ValueAbbrev,
537 };
538
539 lhs: Builder.Constant,
540 rhs: Builder.Constant,
541 mask: Builder.Constant,
542 };
543
544 pub const ShuffleVectorEx = struct {
545 pub const ops = [_]AbbrevOp{
546 .{ .literal = 19 },
547 .{ .fixed_runtime = Builder.Type },
548 ValueAbbrev,
549 ValueAbbrev,
550 ValueAbbrev,
551 };
552
553 ty: Builder.Type,
554 lhs: Builder.Constant,
555 rhs: Builder.Constant,
556 mask: Builder.Constant,
557 };
558
559 pub const BlockAddress = struct {
560 pub const ops = [_]AbbrevOp{
561 .{ .literal = 21 },
562 .{ .fixed_runtime = Builder.Type },
563 ConstantAbbrev,
564 BlockAbbrev,
565 };
566 type_id: Builder.Type,
567 function: u32,
568 block: u32,
569 };
570
571 pub const DsoLocalEquivalentOrNoCfi = struct {
572 pub const ops = [_]AbbrevOp{
573 .{ .fixed = 5 },
574 .{ .fixed_runtime = Builder.Type },
575 ConstantAbbrev,
576 };
577 code: u5,
578 type_id: Builder.Type,
579 function: u32,
580 };
581};
582
583pub const MetadataBlock = struct {
584 pub const id = 15;
585
586 pub const abbrevs = [_]type{
587 Strings,
588 File,
589 CompileUnit,
590 Subprogram,
591 LexicalBlock,
592 Location,
593 BasicType,
594 CompositeType,
595 DerivedType,
596 SubroutineType,
597 Enumerator,
598 Subrange,
599 Expression,
600 Node,
601 LocalVar,
602 Parameter,
603 GlobalVar,
604 GlobalVarExpression,
605 Constant,
606 Name,
607 NamedNode,
608 };
609
610 pub const Strings = struct {
611 pub const ops = [_]AbbrevOp{
612 .{ .literal = 35 },
613 .{ .vbr = 6 },
614 .{ .vbr = 6 },
615 .blob,
616 };
617 num_strings: u32,
618 strings_offset: u32,
619 blob: []const u8,
620 };
621
622 pub const File = struct {
623 pub const ops = [_]AbbrevOp{
624 .{ .literal = 16 },
625 .{ .literal = 1 }, // is distinct
626 MetadataAbbrev, // name
627 MetadataAbbrev, // path
628 .{ .literal = 0 }, // checksum
629 .{ .literal = 0 }, // checksum
630 };
631
632 name: Builder.MetadataString,
633 path: Builder.MetadataString,
634 };
635
636 pub const CompileUnit = struct {
637 pub const ops = [_]AbbrevOp{
638 .{ .literal = 20 },
639 .{ .literal = 1 }, // is distinct
640 .{ .literal = std.dwarf.LANG.C99 }, // source language
641 MetadataAbbrev, // file
642 MetadataAbbrev, // producer
643 .{ .fixed = 1 }, // is optimized
644 .{ .literal = 0 }, // raw flags
645 .{ .literal = 0 }, // runtime version
646 .{ .literal = 0 }, // split debug file name
647 .{ .literal = 1 }, // emission kind
648 MetadataAbbrev, // enum types
649 .{ .literal = 0 }, // retained types
650 .{ .literal = 0 }, // subprograms
651 MetadataAbbrev, // global variables
652 .{ .literal = 0 }, // imported entities
653 .{ .literal = 0 }, // DWO ID
654 .{ .literal = 0 }, // macros
655 .{ .literal = 0 }, // split debug inlining
656 .{ .literal = 0 }, // debug info profiling
657 .{ .literal = 0 }, // name table kind
658 .{ .literal = 0 }, // ranges base address
659 .{ .literal = 0 }, // raw sysroot
660 .{ .literal = 0 }, // raw SDK
661 };
662
663 file: Builder.Metadata,
664 producer: Builder.MetadataString,
665 is_optimized: bool,
666 enums: Builder.Metadata,
667 globals: Builder.Metadata,
668 };
669
670 pub const Subprogram = struct {
671 pub const ops = [_]AbbrevOp{
672 .{ .literal = 21 },
673 .{ .literal = 0b111 }, // is distinct | has sp flags | has flags
674 MetadataAbbrev, // scope
675 MetadataAbbrev, // name
676 MetadataAbbrev, // linkage name
677 MetadataAbbrev, // file
678 LineAbbrev, // line
679 MetadataAbbrev, // type
680 LineAbbrev, // scope line
681 .{ .literal = 0 }, // containing type
682 .{ .fixed = 32 }, // sp flags
683 .{ .literal = 0 }, // virtual index
684 .{ .fixed = 32 }, // flags
685 MetadataAbbrev, // compile unit
686 .{ .literal = 0 }, // template params
687 .{ .literal = 0 }, // declaration
688 .{ .literal = 0 }, // retained nodes
689 .{ .literal = 0 }, // this adjustment
690 .{ .literal = 0 }, // thrown types
691 .{ .literal = 0 }, // annotations
692 .{ .literal = 0 }, // target function name
693 };
694
695 scope: Builder.Metadata,
696 name: Builder.MetadataString,
697 linkage_name: Builder.MetadataString,
698 file: Builder.Metadata,
699 line: u32,
700 ty: Builder.Metadata,
701 scope_line: u32,
702 sp_flags: u32,
703 flags: u32,
704 compile_unit: Builder.Metadata,
705 };
706
707 pub const LexicalBlock = struct {
708 pub const ops = [_]AbbrevOp{
709 .{ .literal = 22 },
710 .{ .literal = 1 }, // is distinct
711 MetadataAbbrev, // scope
712 MetadataAbbrev, // file
713 LineAbbrev, // line
714 ColumnAbbrev, // column
715 };
716
717 scope: Builder.Metadata,
718 file: Builder.Metadata,
719 line: u32,
720 column: u32,
721 };
722
723 pub const Location = struct {
724 pub const ops = [_]AbbrevOp{
725 .{ .literal = 7 },
726 .{ .literal = 0 }, // is distinct
727 LineAbbrev, // line
728 ColumnAbbrev, // column
729 MetadataAbbrev, // scope
730 MetadataAbbrev, // inlined at
731 .{ .literal = 0 }, // is implicit code
732 };
733
734 line: u32,
735 column: u32,
736 scope: u32,
737 inlined_at: Builder.Metadata,
738 };
739
740 pub const BasicType = struct {
741 pub const ops = [_]AbbrevOp{
742 .{ .literal = 15 },
743 .{ .literal = 1 }, // is distinct
744 .{ .literal = std.dwarf.TAG.base_type }, // tag
745 MetadataAbbrev, // name
746 .{ .vbr = 6 }, // size in bits
747 .{ .literal = 0 }, // align in bits
748 .{ .vbr = 8 }, // encoding
749 .{ .literal = 0 }, // flags
750 };
751
752 name: Builder.MetadataString,
753 size_in_bits: u64,
754 encoding: u32,
755 };
756
757 pub const CompositeType = struct {
758 pub const ops = [_]AbbrevOp{
759 .{ .literal = 18 },
760 .{ .literal = 1 | 0x2 }, // is distinct | is not used in old type ref
761 .{ .fixed = 32 }, // tag
762 MetadataAbbrev, // name
763 MetadataAbbrev, // file
764 LineAbbrev, // line
765 MetadataAbbrev, // scope
766 MetadataAbbrev, // underlying type
767 .{ .vbr = 6 }, // size in bits
768 .{ .vbr = 6 }, // align in bits
769 .{ .literal = 0 }, // offset in bits
770 .{ .fixed = 32 }, // flags
771 MetadataAbbrev, // elements
772 .{ .literal = 0 }, // runtime lang
773 .{ .literal = 0 }, // vtable holder
774 .{ .literal = 0 }, // template params
775 .{ .literal = 0 }, // raw id
776 .{ .literal = 0 }, // discriminator
777 .{ .literal = 0 }, // data location
778 .{ .literal = 0 }, // associated
779 .{ .literal = 0 }, // allocated
780 .{ .literal = 0 }, // rank
781 .{ .literal = 0 }, // annotations
782 };
783
784 tag: u32,
785 name: Builder.MetadataString,
786 file: Builder.Metadata,
787 line: u32,
788 scope: Builder.Metadata,
789 underlying_type: Builder.Metadata,
790 size_in_bits: u64,
791 align_in_bits: u64,
792 flags: u32,
793 elements: Builder.Metadata,
794 };
795
796 pub const DerivedType = struct {
797 pub const ops = [_]AbbrevOp{
798 .{ .literal = 17 },
799 .{ .literal = 1 }, // is distinct
800 .{ .fixed = 32 }, // tag
801 MetadataAbbrev, // name
802 MetadataAbbrev, // file
803 LineAbbrev, // line
804 MetadataAbbrev, // scope
805 MetadataAbbrev, // underlying type
806 .{ .vbr = 6 }, // size in bits
807 .{ .vbr = 6 }, // align in bits
808 .{ .vbr = 6 }, // offset in bits
809 .{ .literal = 0 }, // flags
810 .{ .literal = 0 }, // extra data
811 };
812
813 tag: u32,
814 name: Builder.MetadataString,
815 file: Builder.Metadata,
816 line: u32,
817 scope: Builder.Metadata,
818 underlying_type: Builder.Metadata,
819 size_in_bits: u64,
820 align_in_bits: u64,
821 offset_in_bits: u64,
822 };
823
824 pub const SubroutineType = struct {
825 pub const ops = [_]AbbrevOp{
826 .{ .literal = 19 },
827 .{ .literal = 1 | 0x2 }, // is distinct | has no old type refs
828 .{ .literal = 0 }, // flags
829 MetadataAbbrev, // types
830 .{ .literal = 0 }, // cc
831 };
832
833 types: Builder.Metadata,
834 };
835
836 pub const Enumerator = struct {
837 pub const id = 14;
838
839 pub const Flags = packed struct(u3) {
840 distinct: bool = true,
841 unsigned: bool,
842 bigint: bool,
843 };
844
845 pub const ops = [_]AbbrevOp{
846 .{ .literal = Enumerator.id },
847 .{ .fixed = @bitSizeOf(Flags) }, // flags
848 .{ .vbr = 6 }, // bit width
849 MetadataAbbrev, // name
850 .{ .vbr = 16 }, // integer value
851 };
852
853 flags: Flags,
854 bit_width: u32,
855 name: Builder.MetadataString,
856 value: u64,
857 };
858
859 pub const Subrange = struct {
860 pub const ops = [_]AbbrevOp{
861 .{ .literal = 13 },
862 .{ .literal = 0b11 },
863 MetadataAbbrev, // count
864 MetadataAbbrev, // lower bound
865 .{ .literal = 0 }, // upper bound
866 .{ .literal = 0 }, // stride
867 };
868
869 count: Builder.Metadata,
870 lower_bound: Builder.Metadata,
871 };
872
873 pub const Expression = struct {
874 pub const ops = [_]AbbrevOp{
875 .{ .literal = 29 },
876 .{ .literal = 0 | (3 << 1) }, // is distinct | version
877 MetadataArrayAbbrev, // elements
878 };
879
880 elements: []const u32,
881 };
882
883 pub const Node = struct {
884 pub const ops = [_]AbbrevOp{
885 .{ .literal = 3 },
886 MetadataArrayAbbrev, // elements
887 };
888
889 elements: []const Builder.Metadata,
890 };
891
892 pub const LocalVar = struct {
893 pub const ops = [_]AbbrevOp{
894 .{ .literal = 28 },
895 .{ .literal = 0b11 }, // is distinct | has alignment
896 MetadataAbbrev, // scope
897 MetadataAbbrev, // name
898 MetadataAbbrev, // file
899 LineAbbrev, // line
900 MetadataAbbrev, // type
901 .{ .literal = 0 }, // arg
902 .{ .literal = 0 }, // flags
903 .{ .literal = 0 }, // align bits
904 .{ .literal = 0 }, // annotations
905 };
906
907 scope: Builder.Metadata,
908 name: Builder.MetadataString,
909 file: Builder.Metadata,
910 line: u32,
911 ty: Builder.Metadata,
912 };
913
914 pub const Parameter = struct {
915 pub const ops = [_]AbbrevOp{
916 .{ .literal = 28 },
917 .{ .literal = 0b11 }, // is distinct | has alignment
918 MetadataAbbrev, // scope
919 MetadataAbbrev, // name
920 MetadataAbbrev, // file
921 LineAbbrev, // line
922 MetadataAbbrev, // type
923 .{ .vbr = 4 }, // arg
924 .{ .literal = 0 }, // flags
925 .{ .literal = 0 }, // align bits
926 .{ .literal = 0 }, // annotations
927 };
928
929 scope: Builder.Metadata,
930 name: Builder.MetadataString,
931 file: Builder.Metadata,
932 line: u32,
933 ty: Builder.Metadata,
934 arg: u32,
935 };
936
937 pub const GlobalVar = struct {
938 pub const ops = [_]AbbrevOp{
939 .{ .literal = 27 },
940 .{ .literal = 0b101 }, // is distinct | version
941 MetadataAbbrev, // scope
942 MetadataAbbrev, // name
943 MetadataAbbrev, // linkage name
944 MetadataAbbrev, // file
945 LineAbbrev, // line
946 MetadataAbbrev, // type
947 .{ .fixed = 1 }, // local
948 .{ .literal = 1 }, // defined
949 .{ .literal = 0 }, // static data members declaration
950 .{ .literal = 0 }, // template params
951 .{ .literal = 0 }, // align in bits
952 .{ .literal = 0 }, // annotations
953 };
954
955 scope: Builder.Metadata,
956 name: Builder.MetadataString,
957 linkage_name: Builder.MetadataString,
958 file: Builder.Metadata,
959 line: u32,
960 ty: Builder.Metadata,
961 local: bool,
962 };
963
964 pub const GlobalVarExpression = struct {
965 pub const ops = [_]AbbrevOp{
966 .{ .literal = 37 },
967 .{ .literal = 1 }, // is distinct
968 MetadataAbbrev, // variable
969 MetadataAbbrev, // expression
970 };
971
972 variable: Builder.Metadata,
973 expression: Builder.Metadata,
974 };
975
976 pub const Constant = struct {
977 pub const ops = [_]AbbrevOp{
978 .{ .literal = 2 },
979 MetadataAbbrev, // type
980 MetadataAbbrev, // value
981 };
982
983 ty: Builder.Type,
984 constant: Builder.Constant,
985 };
986
987 pub const Name = struct {
988 pub const ops = [_]AbbrevOp{
989 .{ .literal = 4 },
990 .{ .array_fixed = 8 }, // name
991 };
992
993 name: []const u8,
994 };
995
996 pub const NamedNode = struct {
997 pub const ops = [_]AbbrevOp{
998 .{ .literal = 10 },
999 MetadataArrayAbbrev, // elements
1000 };
1001
1002 elements: []const Builder.Metadata,
1003 };
1004};
1005
1006pub const FunctionMetadataBlock = struct {
1007 pub const id = 15;
1008
1009 pub const abbrevs = [_]type{
1010 Value,
1011 };
1012
1013 pub const Value = struct {
1014 pub const ops = [_]AbbrevOp{
1015 .{ .literal = 2 },
1016 .{ .fixed = 32 }, // variable
1017 .{ .fixed = 32 }, // expression
1018 };
1019
1020 ty: Builder.Type,
1021 value: Builder.Value,
1022 };
1023};
1024
1025pub const FunctionBlock = struct {
1026 pub const id = 12;
1027
1028 pub const abbrevs = [_]type{
1029 DeclareBlocks,
1030 Call,
1031 CallFast,
1032 FNeg,
1033 FNegFast,
1034 Binary,
1035 BinaryFast,
1036 Cmp,
1037 CmpFast,
1038 Select,
1039 SelectFast,
1040 Cast,
1041 Alloca,
1042 GetElementPtr,
1043 ExtractValue,
1044 InsertValue,
1045 ExtractElement,
1046 InsertElement,
1047 ShuffleVector,
1048 RetVoid,
1049 Ret,
1050 Unreachable,
1051 Load,
1052 LoadAtomic,
1053 Store,
1054 StoreAtomic,
1055 BrUnconditional,
1056 BrConditional,
1057 VaArg,
1058 AtomicRmw,
1059 CmpXchg,
1060 Fence,
1061 DebugLoc,
1062 DebugLocAgain,
1063 };
1064
1065 pub const DeclareBlocks = struct {
1066 pub const ops = [_]AbbrevOp{
1067 .{ .literal = 1 },
1068 .{ .vbr = 8 },
1069 };
1070 num_blocks: usize,
1071 };
1072
1073 pub const Call = struct {
1074 pub const CallType = packed struct(u17) {
1075 tail: bool = false,
1076 call_conv: Builder.CallConv,
1077 reserved: u3 = 0,
1078 must_tail: bool = false,
1079 // We always use the explicit type version as that is what LLVM does
1080 explicit_type: bool = true,
1081 no_tail: bool = false,
1082 };
1083 pub const ops = [_]AbbrevOp{
1084 .{ .literal = 34 },
1085 .{ .fixed_runtime = Builder.FunctionAttributes },
1086 .{ .fixed = @bitSizeOf(CallType) },
1087 .{ .fixed_runtime = Builder.Type },
1088 ValueAbbrev, // Callee
1089 ValueArrayAbbrev, // Args
1090 };
1091
1092 attributes: Builder.FunctionAttributes,
1093 call_type: CallType,
1094 type_id: Builder.Type,
1095 callee: Builder.Value,
1096 args: []const Builder.Value,
1097 };
1098
1099 pub const CallFast = struct {
1100 const CallType = packed struct(u18) {
1101 tail: bool = false,
1102 call_conv: Builder.CallConv,
1103 reserved: u3 = 0,
1104 must_tail: bool = false,
1105 // We always use the explicit type version as that is what LLVM does
1106 explicit_type: bool = true,
1107 no_tail: bool = false,
1108 fast: bool = true,
1109 };
1110
1111 pub const ops = [_]AbbrevOp{
1112 .{ .literal = 34 },
1113 .{ .fixed_runtime = Builder.FunctionAttributes },
1114 .{ .fixed = @bitSizeOf(CallType) },
1115 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1116 .{ .fixed_runtime = Builder.Type },
1117 ValueAbbrev, // Callee
1118 ValueArrayAbbrev, // Args
1119 };
1120
1121 attributes: Builder.FunctionAttributes,
1122 call_type: CallType,
1123 fast_math: Builder.FastMath,
1124 type_id: Builder.Type,
1125 callee: Builder.Value,
1126 args: []const Builder.Value,
1127 };
1128
1129 pub const FNeg = struct {
1130 pub const ops = [_]AbbrevOp{
1131 .{ .literal = 56 },
1132 ValueAbbrev,
1133 .{ .literal = 0 },
1134 };
1135
1136 val: u32,
1137 };
1138
1139 pub const FNegFast = struct {
1140 pub const ops = [_]AbbrevOp{
1141 .{ .literal = 56 },
1142 ValueAbbrev,
1143 .{ .literal = 0 },
1144 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1145 };
1146
1147 val: u32,
1148 fast_math: Builder.FastMath,
1149 };
1150
1151 pub const Binary = struct {
1152 const BinaryOpcode = Builder.BinaryOpcode;
1153 pub const ops = [_]AbbrevOp{
1154 .{ .literal = 2 },
1155 ValueAbbrev,
1156 ValueAbbrev,
1157 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1158 };
1159
1160 lhs: u32,
1161 rhs: u32,
1162 opcode: BinaryOpcode,
1163 };
1164
1165 pub const BinaryFast = struct {
1166 const BinaryOpcode = Builder.BinaryOpcode;
1167 pub const ops = [_]AbbrevOp{
1168 .{ .literal = 2 },
1169 ValueAbbrev,
1170 ValueAbbrev,
1171 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1172 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1173 };
1174
1175 lhs: u32,
1176 rhs: u32,
1177 opcode: BinaryOpcode,
1178 fast_math: Builder.FastMath,
1179 };
1180
1181 pub const Cmp = struct {
1182 const CmpPredicate = Builder.CmpPredicate;
1183 pub const ops = [_]AbbrevOp{
1184 .{ .literal = 28 },
1185 ValueAbbrev,
1186 ValueAbbrev,
1187 .{ .fixed = @bitSizeOf(CmpPredicate) },
1188 };
1189
1190 lhs: u32,
1191 rhs: u32,
1192 pred: CmpPredicate,
1193 };
1194
1195 pub const CmpFast = struct {
1196 const CmpPredicate = Builder.CmpPredicate;
1197 pub const ops = [_]AbbrevOp{
1198 .{ .literal = 28 },
1199 ValueAbbrev,
1200 ValueAbbrev,
1201 .{ .fixed = @bitSizeOf(CmpPredicate) },
1202 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1203 };
1204
1205 lhs: u32,
1206 rhs: u32,
1207 pred: CmpPredicate,
1208 fast_math: Builder.FastMath,
1209 };
1210
1211 pub const Select = struct {
1212 pub const ops = [_]AbbrevOp{
1213 .{ .literal = 29 },
1214 ValueAbbrev,
1215 ValueAbbrev,
1216 ValueAbbrev,
1217 };
1218
1219 lhs: u32,
1220 rhs: u32,
1221 cond: u32,
1222 };
1223
1224 pub const SelectFast = struct {
1225 pub const ops = [_]AbbrevOp{
1226 .{ .literal = 29 },
1227 ValueAbbrev,
1228 ValueAbbrev,
1229 ValueAbbrev,
1230 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1231 };
1232
1233 lhs: u32,
1234 rhs: u32,
1235 cond: u32,
1236 fast_math: Builder.FastMath,
1237 };
1238
1239 pub const Cast = struct {
1240 const CastOpcode = Builder.CastOpcode;
1241 pub const ops = [_]AbbrevOp{
1242 .{ .literal = 3 },
1243 ValueAbbrev,
1244 .{ .fixed_runtime = Builder.Type },
1245 .{ .fixed = @bitSizeOf(CastOpcode) },
1246 };
1247
1248 val: u32,
1249 type_index: Builder.Type,
1250 opcode: CastOpcode,
1251 };
1252
1253 pub const Alloca = struct {
1254 pub const Flags = packed struct(u11) {
1255 align_lower: u5,
1256 inalloca: bool,
1257 explicit_type: bool,
1258 swift_error: bool,
1259 align_upper: u3,
1260 };
1261 pub const ops = [_]AbbrevOp{
1262 .{ .literal = 19 },
1263 .{ .fixed_runtime = Builder.Type },
1264 .{ .fixed_runtime = Builder.Type },
1265 ValueAbbrev,
1266 .{ .fixed = @bitSizeOf(Flags) },
1267 };
1268
1269 inst_type: Builder.Type,
1270 len_type: Builder.Type,
1271 len_value: u32,
1272 flags: Flags,
1273 };
1274
1275 pub const RetVoid = struct {
1276 pub const ops = [_]AbbrevOp{
1277 .{ .literal = 10 },
1278 };
1279 };
1280
1281 pub const Ret = struct {
1282 pub const ops = [_]AbbrevOp{
1283 .{ .literal = 10 },
1284 ValueAbbrev,
1285 };
1286 val: u32,
1287 };
1288
1289 pub const GetElementPtr = struct {
1290 pub const ops = [_]AbbrevOp{
1291 .{ .literal = 43 },
1292 .{ .fixed = 1 },
1293 .{ .fixed_runtime = Builder.Type },
1294 ValueAbbrev,
1295 ValueArrayAbbrev,
1296 };
1297
1298 is_inbounds: bool,
1299 type_index: Builder.Type,
1300 base: Builder.Value,
1301 indices: []const Builder.Value,
1302 };
1303
1304 pub const ExtractValue = struct {
1305 pub const ops = [_]AbbrevOp{
1306 .{ .literal = 26 },
1307 ValueAbbrev,
1308 ValueArrayAbbrev,
1309 };
1310
1311 val: u32,
1312 indices: []const u32,
1313 };
1314
1315 pub const InsertValue = struct {
1316 pub const ops = [_]AbbrevOp{
1317 .{ .literal = 27 },
1318 ValueAbbrev,
1319 ValueAbbrev,
1320 ValueArrayAbbrev,
1321 };
1322
1323 val: u32,
1324 elem: u32,
1325 indices: []const u32,
1326 };
1327
1328 pub const ExtractElement = struct {
1329 pub const ops = [_]AbbrevOp{
1330 .{ .literal = 6 },
1331 ValueAbbrev,
1332 ValueAbbrev,
1333 };
1334
1335 val: u32,
1336 index: u32,
1337 };
1338
1339 pub const InsertElement = struct {
1340 pub const ops = [_]AbbrevOp{
1341 .{ .literal = 7 },
1342 ValueAbbrev,
1343 ValueAbbrev,
1344 ValueAbbrev,
1345 };
1346
1347 val: u32,
1348 elem: u32,
1349 index: u32,
1350 };
1351
1352 pub const ShuffleVector = struct {
1353 pub const ops = [_]AbbrevOp{
1354 .{ .literal = 8 },
1355 ValueAbbrev,
1356 ValueAbbrev,
1357 ValueAbbrev,
1358 };
1359
1360 lhs: u32,
1361 rhs: u32,
1362 mask: u32,
1363 };
1364
1365 pub const Unreachable = struct {
1366 pub const ops = [_]AbbrevOp{
1367 .{ .literal = 15 },
1368 };
1369 };
1370
1371 pub const Load = struct {
1372 pub const ops = [_]AbbrevOp{
1373 .{ .literal = 20 },
1374 ValueAbbrev,
1375 .{ .fixed_runtime = Builder.Type },
1376 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1377 .{ .fixed = 1 },
1378 };
1379 ptr: u32,
1380 ty: Builder.Type,
1381 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1382 is_volatile: bool,
1383 };
1384
1385 pub const LoadAtomic = struct {
1386 pub const ops = [_]AbbrevOp{
1387 .{ .literal = 41 },
1388 ValueAbbrev,
1389 .{ .fixed_runtime = Builder.Type },
1390 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1391 .{ .fixed = 1 },
1392 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1393 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1394 };
1395 ptr: u32,
1396 ty: Builder.Type,
1397 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1398 is_volatile: bool,
1399 success_ordering: Builder.AtomicOrdering,
1400 sync_scope: Builder.SyncScope,
1401 };
1402
1403 pub const Store = struct {
1404 pub const ops = [_]AbbrevOp{
1405 .{ .literal = 44 },
1406 ValueAbbrev,
1407 ValueAbbrev,
1408 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1409 .{ .fixed = 1 },
1410 };
1411 ptr: u32,
1412 val: u32,
1413 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1414 is_volatile: bool,
1415 };
1416
1417 pub const StoreAtomic = struct {
1418 pub const ops = [_]AbbrevOp{
1419 .{ .literal = 45 },
1420 ValueAbbrev,
1421 ValueAbbrev,
1422 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1423 .{ .fixed = 1 },
1424 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1425 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1426 };
1427 ptr: u32,
1428 val: u32,
1429 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1430 is_volatile: bool,
1431 success_ordering: Builder.AtomicOrdering,
1432 sync_scope: Builder.SyncScope,
1433 };
1434
1435 pub const BrUnconditional = struct {
1436 pub const ops = [_]AbbrevOp{
1437 .{ .literal = 11 },
1438 BlockAbbrev,
1439 };
1440 block: u32,
1441 };
1442
1443 pub const BrConditional = struct {
1444 pub const ops = [_]AbbrevOp{
1445 .{ .literal = 11 },
1446 BlockAbbrev,
1447 BlockAbbrev,
1448 BlockAbbrev,
1449 };
1450 then_block: u32,
1451 else_block: u32,
1452 condition: u32,
1453 };
1454
1455 pub const VaArg = struct {
1456 pub const ops = [_]AbbrevOp{
1457 .{ .literal = 23 },
1458 .{ .fixed_runtime = Builder.Type },
1459 ValueAbbrev,
1460 .{ .fixed_runtime = Builder.Type },
1461 };
1462 list_type: Builder.Type,
1463 list: u32,
1464 type: Builder.Type,
1465 };
1466
1467 pub const AtomicRmw = struct {
1468 pub const ops = [_]AbbrevOp{
1469 .{ .literal = 59 },
1470 ValueAbbrev,
1471 ValueAbbrev,
1472 .{ .fixed = @bitSizeOf(Builder.Function.Instruction.AtomicRmw.Operation) },
1473 .{ .fixed = 1 },
1474 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1475 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1476 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1477 };
1478 ptr: u32,
1479 val: u32,
1480 operation: Builder.Function.Instruction.AtomicRmw.Operation,
1481 is_volatile: bool,
1482 success_ordering: Builder.AtomicOrdering,
1483 sync_scope: Builder.SyncScope,
1484 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1485 };
1486
1487 pub const CmpXchg = struct {
1488 pub const ops = [_]AbbrevOp{
1489 .{ .literal = 46 },
1490 ValueAbbrev,
1491 ValueAbbrev,
1492 ValueAbbrev,
1493 .{ .fixed = 1 },
1494 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1495 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1496 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1497 .{ .fixed = 1 },
1498 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1499 };
1500 ptr: u32,
1501 cmp: u32,
1502 new: u32,
1503 is_volatile: bool,
1504 success_ordering: Builder.AtomicOrdering,
1505 sync_scope: Builder.SyncScope,
1506 failure_ordering: Builder.AtomicOrdering,
1507 is_weak: bool,
1508 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1509 };
1510
1511 pub const Fence = struct {
1512 pub const ops = [_]AbbrevOp{
1513 .{ .literal = 36 },
1514 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1515 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1516 };
1517 ordering: Builder.AtomicOrdering,
1518 sync_scope: Builder.SyncScope,
1519 };
1520
1521 pub const DebugLoc = struct {
1522 pub const ops = [_]AbbrevOp{
1523 .{ .literal = 35 },
1524 .{ .fixed = 32 },
1525 .{ .fixed = 32 },
1526 .{ .fixed = 32 },
1527 .{ .fixed = 32 },
1528 .{ .fixed = 1 },
1529 };
1530 line: u32,
1531 column: u32,
1532 scope: Builder.Metadata,
1533 inlined_at: Builder.Metadata,
1534 is_implicit: bool,
1535 };
1536
1537 pub const DebugLocAgain = struct {
1538 pub const ops = [_]AbbrevOp{
1539 .{ .literal = 33 },
1540 };
1541 };
1542};
1543
1544pub const FunctionValueSymbolTable = struct {
1545 pub const id = 14;
1546
1547 pub const abbrevs = [_]type{
1548 BlockEntry,
1549 };
1550
1551 pub const BlockEntry = struct {
1552 pub const ops = [_]AbbrevOp{
1553 .{ .literal = 2 },
1554 ValueAbbrev,
1555 .{ .array_fixed = 8 },
1556 };
1557 value_id: u32,
1558 string: []const u8,
1559 };
1560};
1561
1562pub const Strtab = struct {
1563 pub const id = 23;
1564
1565 pub const abbrevs = [_]type{Blob};
1566
1567 pub const Blob = struct {
1568 pub const ops = [_]AbbrevOp{
1569 .{ .literal = 1 },
1570 .blob,
1571 };
1572 blob: []const u8,
1573 };
1574};
src/codegen/llvm/ir.zig created+1574
......@@ -0,0 +1,1574 @@
1const std = @import("std");
2const Builder = @import("Builder.zig");
3const bitcode_writer = @import("bitcode_writer.zig");
4
5const AbbrevOp = bitcode_writer.AbbrevOp;
6
7pub const MAGIC: u32 = 0xdec04342;
8
9const ValueAbbrev = AbbrevOp{ .vbr = 6 };
10const ValueArrayAbbrev = AbbrevOp{ .array_vbr = 6 };
11
12const ConstantAbbrev = AbbrevOp{ .vbr = 6 };
13const ConstantArrayAbbrev = AbbrevOp{ .array_vbr = 6 };
14
15const MetadataAbbrev = AbbrevOp{ .vbr = 16 };
16const MetadataArrayAbbrev = AbbrevOp{ .array_vbr = 16 };
17
18const LineAbbrev = AbbrevOp{ .vbr = 8 };
19const ColumnAbbrev = AbbrevOp{ .vbr = 8 };
20
21const BlockAbbrev = AbbrevOp{ .vbr = 6 };
22
23pub const Identification = struct {
24 pub const id = 13;
25
26 pub const abbrevs = [_]type{
27 Version,
28 Epoch,
29 };
30
31 pub const Version = struct {
32 pub const ops = [_]AbbrevOp{
33 .{ .literal = 1 },
34 .{ .array_fixed = 8 },
35 };
36 string: []const u8,
37 };
38
39 pub const Epoch = struct {
40 pub const ops = [_]AbbrevOp{
41 .{ .literal = 2 },
42 .{ .vbr = 6 },
43 };
44 epoch: u32,
45 };
46};
47
48pub const Module = struct {
49 pub const id = 8;
50
51 pub const abbrevs = [_]type{
52 Version,
53 String,
54 Variable,
55 Function,
56 Alias,
57 };
58
59 pub const Version = struct {
60 pub const ops = [_]AbbrevOp{
61 .{ .literal = 1 },
62 .{ .literal = 2 },
63 };
64 };
65
66 pub const String = struct {
67 pub const ops = [_]AbbrevOp{
68 .{ .vbr = 4 },
69 .{ .array_fixed = 8 },
70 };
71 code: u16,
72 string: []const u8,
73 };
74
75 pub const Variable = struct {
76 const AddrSpaceAndIsConst = packed struct {
77 is_const: bool,
78 one: u1 = 1,
79 addr_space: Builder.AddrSpace,
80 };
81
82 pub const ops = [_]AbbrevOp{
83 .{ .literal = 7 }, // Code
84 .{ .vbr = 16 }, // strtab_offset
85 .{ .vbr = 16 }, // strtab_size
86 .{ .fixed_runtime = Builder.Type },
87 .{ .fixed = @bitSizeOf(AddrSpaceAndIsConst) }, // isconst
88 ConstantAbbrev, // initid
89 .{ .fixed = @bitSizeOf(Builder.Linkage) },
90 .{ .fixed = @bitSizeOf(Builder.Alignment) },
91 .{ .vbr = 16 }, // section
92 .{ .fixed = @bitSizeOf(Builder.Visibility) },
93 .{ .fixed = @bitSizeOf(Builder.ThreadLocal) }, // threadlocal
94 .{ .fixed = @bitSizeOf(Builder.UnnamedAddr) },
95 .{ .fixed = @bitSizeOf(Builder.ExternallyInitialized) },
96 .{ .fixed = @bitSizeOf(Builder.DllStorageClass) },
97 .{ .literal = 0 }, // comdat
98 .{ .literal = 0 }, // attributes
99 .{ .fixed = @bitSizeOf(Builder.Preemption) },
100 };
101 strtab_offset: usize,
102 strtab_size: usize,
103 type_index: Builder.Type,
104 is_const: AddrSpaceAndIsConst,
105 initid: u32,
106 linkage: Builder.Linkage,
107 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
108 section: usize,
109 visibility: Builder.Visibility,
110 thread_local: Builder.ThreadLocal,
111 unnamed_addr: Builder.UnnamedAddr,
112 externally_initialized: Builder.ExternallyInitialized,
113 dllstorageclass: Builder.DllStorageClass,
114 preemption: Builder.Preemption,
115 };
116
117 pub const Function = struct {
118 pub const ops = [_]AbbrevOp{
119 .{ .literal = 8 }, // Code
120 .{ .vbr = 16 }, // strtab_offset
121 .{ .vbr = 16 }, // strtab_size
122 .{ .fixed_runtime = Builder.Type },
123 .{ .fixed = @bitSizeOf(Builder.CallConv) },
124 .{ .fixed = 1 }, // isproto
125 .{ .fixed = @bitSizeOf(Builder.Linkage) },
126 .{ .vbr = 16 }, // paramattr
127 .{ .fixed = @bitSizeOf(Builder.Alignment) },
128 .{ .vbr = 16 }, // section
129 .{ .fixed = @bitSizeOf(Builder.Visibility) },
130 .{ .literal = 0 }, // gc
131 .{ .fixed = @bitSizeOf(Builder.UnnamedAddr) },
132 .{ .literal = 0 }, // prologuedata
133 .{ .fixed = @bitSizeOf(Builder.DllStorageClass) },
134 .{ .literal = 0 }, // comdat
135 .{ .literal = 0 }, // prefixdata
136 .{ .literal = 0 }, // personalityfn
137 .{ .fixed = @bitSizeOf(Builder.Preemption) },
138 .{ .fixed = @bitSizeOf(Builder.AddrSpace) },
139 };
140 strtab_offset: usize,
141 strtab_size: usize,
142 type_index: Builder.Type,
143 call_conv: Builder.CallConv,
144 is_proto: bool,
145 linkage: Builder.Linkage,
146 paramattr: usize,
147 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
148 section: usize,
149 visibility: Builder.Visibility,
150 unnamed_addr: Builder.UnnamedAddr,
151 dllstorageclass: Builder.DllStorageClass,
152 preemption: Builder.Preemption,
153 addr_space: Builder.AddrSpace,
154 };
155
156 pub const Alias = struct {
157 pub const ops = [_]AbbrevOp{
158 .{ .literal = 9 }, // Code
159 .{ .vbr = 16 }, // strtab_offset
160 .{ .vbr = 16 }, // strtab_size
161 .{ .fixed_runtime = Builder.Type },
162 .{ .fixed = @bitSizeOf(Builder.AddrSpace) },
163 ConstantAbbrev, // aliasee val
164 .{ .fixed = @bitSizeOf(Builder.Linkage) },
165 .{ .fixed = @bitSizeOf(Builder.Visibility) },
166 .{ .fixed = @bitSizeOf(Builder.DllStorageClass) },
167 .{ .fixed = @bitSizeOf(Builder.ThreadLocal) },
168 .{ .fixed = @bitSizeOf(Builder.UnnamedAddr) },
169 .{ .fixed = @bitSizeOf(Builder.Preemption) },
170 };
171 strtab_offset: usize,
172 strtab_size: usize,
173 type_index: Builder.Type,
174 addr_space: Builder.AddrSpace,
175 aliasee: u32,
176 linkage: Builder.Linkage,
177 visibility: Builder.Visibility,
178 dllstorageclass: Builder.DllStorageClass,
179 thread_local: Builder.ThreadLocal,
180 unnamed_addr: Builder.UnnamedAddr,
181 preemption: Builder.Preemption,
182 };
183};
184
185pub const Type = struct {
186 pub const id = 17;
187
188 pub const abbrevs = [_]type{
189 NumEntry,
190 Simple,
191 Integer,
192 StructAnon,
193 StructNamed,
194 StructName,
195 Array,
196 Vector,
197 Pointer,
198 Target,
199 Function,
200 };
201
202 pub const NumEntry = struct {
203 pub const ops = [_]AbbrevOp{
204 .{ .literal = 1 },
205 .{ .fixed = 32 },
206 };
207 num: u32,
208 };
209
210 pub const Simple = struct {
211 pub const ops = [_]AbbrevOp{
212 .{ .vbr = 4 },
213 };
214 code: u5,
215 };
216
217 pub const Integer = struct {
218 pub const ops = [_]AbbrevOp{
219 .{ .literal = 7 },
220 .{ .fixed = 28 },
221 };
222 width: u28,
223 };
224
225 pub const StructAnon = struct {
226 pub const ops = [_]AbbrevOp{
227 .{ .literal = 18 },
228 .{ .fixed = 1 },
229 .{ .array_fixed_runtime = Builder.Type },
230 };
231 is_packed: bool,
232 types: []const Builder.Type,
233 };
234
235 pub const StructNamed = struct {
236 pub const ops = [_]AbbrevOp{
237 .{ .literal = 20 },
238 .{ .fixed = 1 },
239 .{ .array_fixed_runtime = Builder.Type },
240 };
241 is_packed: bool,
242 types: []const Builder.Type,
243 };
244
245 pub const StructName = struct {
246 pub const ops = [_]AbbrevOp{
247 .{ .literal = 19 },
248 .{ .array_fixed = 8 },
249 };
250 string: []const u8,
251 };
252
253 pub const Array = struct {
254 pub const ops = [_]AbbrevOp{
255 .{ .literal = 11 },
256 .{ .vbr = 16 },
257 .{ .fixed_runtime = Builder.Type },
258 };
259 len: u64,
260 child: Builder.Type,
261 };
262
263 pub const Vector = struct {
264 pub const ops = [_]AbbrevOp{
265 .{ .literal = 12 },
266 .{ .vbr = 16 },
267 .{ .fixed_runtime = Builder.Type },
268 };
269 len: u64,
270 child: Builder.Type,
271 };
272
273 pub const Pointer = struct {
274 pub const ops = [_]AbbrevOp{
275 .{ .literal = 25 },
276 .{ .vbr = 4 },
277 };
278 addr_space: Builder.AddrSpace,
279 };
280
281 pub const Target = struct {
282 pub const ops = [_]AbbrevOp{
283 .{ .literal = 26 },
284 .{ .vbr = 4 },
285 .{ .array_fixed_runtime = Builder.Type },
286 .{ .array_fixed = 32 },
287 };
288 num_types: u32,
289 types: []const Builder.Type,
290 ints: []const u32,
291 };
292
293 pub const Function = struct {
294 pub const ops = [_]AbbrevOp{
295 .{ .literal = 21 },
296 .{ .fixed = 1 },
297 .{ .fixed_runtime = Builder.Type },
298 .{ .array_fixed_runtime = Builder.Type },
299 };
300 is_vararg: bool,
301 return_type: Builder.Type,
302 param_types: []const Builder.Type,
303 };
304};
305
306pub const Paramattr = struct {
307 pub const id = 9;
308
309 pub const abbrevs = [_]type{
310 Entry,
311 };
312
313 pub const Entry = struct {
314 pub const ops = [_]AbbrevOp{
315 .{ .literal = 2 },
316 .{ .array_vbr = 8 },
317 };
318 group_indices: []const u64,
319 };
320};
321
322pub const ParamattrGroup = struct {
323 pub const id = 10;
324
325 pub const abbrevs = [_]type{};
326};
327
328pub const Constants = struct {
329 pub const id = 11;
330
331 pub const abbrevs = [_]type{
332 SetType,
333 Null,
334 Undef,
335 Poison,
336 Integer,
337 Half,
338 Float,
339 Double,
340 Fp80,
341 Fp128,
342 Aggregate,
343 String,
344 CString,
345 Cast,
346 Binary,
347 Cmp,
348 ExtractElement,
349 InsertElement,
350 ShuffleVector,
351 ShuffleVectorEx,
352 BlockAddress,
353 DsoLocalEquivalentOrNoCfi,
354 };
355
356 pub const SetType = struct {
357 pub const ops = [_]AbbrevOp{
358 .{ .literal = 1 },
359 .{ .fixed_runtime = Builder.Type },
360 };
361 type_id: Builder.Type,
362 };
363
364 pub const Null = struct {
365 pub const ops = [_]AbbrevOp{
366 .{ .literal = 2 },
367 };
368 };
369
370 pub const Undef = struct {
371 pub const ops = [_]AbbrevOp{
372 .{ .literal = 3 },
373 };
374 };
375
376 pub const Poison = struct {
377 pub const ops = [_]AbbrevOp{
378 .{ .literal = 26 },
379 };
380 };
381
382 pub const Integer = struct {
383 pub const ops = [_]AbbrevOp{
384 .{ .literal = 4 },
385 .{ .vbr = 16 },
386 };
387 value: u64,
388 };
389
390 pub const Half = struct {
391 pub const ops = [_]AbbrevOp{
392 .{ .literal = 6 },
393 .{ .fixed = 16 },
394 };
395 value: u16,
396 };
397
398 pub const Float = struct {
399 pub const ops = [_]AbbrevOp{
400 .{ .literal = 6 },
401 .{ .fixed = 32 },
402 };
403 value: u32,
404 };
405
406 pub const Double = struct {
407 pub const ops = [_]AbbrevOp{
408 .{ .literal = 6 },
409 .{ .vbr = 6 },
410 };
411 value: u64,
412 };
413
414 pub const Fp80 = struct {
415 pub const ops = [_]AbbrevOp{
416 .{ .literal = 6 },
417 .{ .vbr = 6 },
418 .{ .vbr = 6 },
419 };
420 lo: u64,
421 hi: u16,
422 };
423
424 pub const Fp128 = struct {
425 pub const ops = [_]AbbrevOp{
426 .{ .literal = 6 },
427 .{ .vbr = 6 },
428 .{ .vbr = 6 },
429 };
430 lo: u64,
431 hi: u64,
432 };
433
434 pub const Aggregate = struct {
435 pub const ops = [_]AbbrevOp{
436 .{ .literal = 7 },
437 .{ .array_fixed = 32 },
438 };
439 values: []const Builder.Constant,
440 };
441
442 pub const String = struct {
443 pub const ops = [_]AbbrevOp{
444 .{ .literal = 8 },
445 .{ .array_fixed = 8 },
446 };
447 string: []const u8,
448 };
449
450 pub const CString = struct {
451 pub const ops = [_]AbbrevOp{
452 .{ .literal = 9 },
453 .{ .array_fixed = 8 },
454 };
455 string: []const u8,
456 };
457
458 pub const Cast = struct {
459 const CastOpcode = Builder.CastOpcode;
460 pub const ops = [_]AbbrevOp{
461 .{ .literal = 11 },
462 .{ .fixed = @bitSizeOf(CastOpcode) },
463 .{ .fixed_runtime = Builder.Type },
464 ConstantAbbrev,
465 };
466
467 opcode: CastOpcode,
468 type_index: Builder.Type,
469 val: Builder.Constant,
470 };
471
472 pub const Binary = struct {
473 const BinaryOpcode = Builder.BinaryOpcode;
474 pub const ops = [_]AbbrevOp{
475 .{ .literal = 10 },
476 .{ .fixed = @bitSizeOf(BinaryOpcode) },
477 ConstantAbbrev,
478 ConstantAbbrev,
479 };
480
481 opcode: BinaryOpcode,
482 lhs: Builder.Constant,
483 rhs: Builder.Constant,
484 };
485
486 pub const Cmp = struct {
487 pub const ops = [_]AbbrevOp{
488 .{ .literal = 17 },
489 .{ .fixed_runtime = Builder.Type },
490 ConstantAbbrev,
491 ConstantAbbrev,
492 .{ .vbr = 6 },
493 };
494
495 ty: Builder.Type,
496 lhs: Builder.Constant,
497 rhs: Builder.Constant,
498 pred: u32,
499 };
500
501 pub const ExtractElement = struct {
502 pub const ops = [_]AbbrevOp{
503 .{ .literal = 14 },
504 .{ .fixed_runtime = Builder.Type },
505 ConstantAbbrev,
506 .{ .fixed_runtime = Builder.Type },
507 ConstantAbbrev,
508 };
509
510 val_type: Builder.Type,
511 val: Builder.Constant,
512 index_type: Builder.Type,
513 index: Builder.Constant,
514 };
515
516 pub const InsertElement = struct {
517 pub const ops = [_]AbbrevOp{
518 .{ .literal = 15 },
519 ConstantAbbrev,
520 ConstantAbbrev,
521 .{ .fixed_runtime = Builder.Type },
522 ConstantAbbrev,
523 };
524
525 val: Builder.Constant,
526 elem: Builder.Constant,
527 index_type: Builder.Type,
528 index: Builder.Constant,
529 };
530
531 pub const ShuffleVector = struct {
532 pub const ops = [_]AbbrevOp{
533 .{ .literal = 16 },
534 ValueAbbrev,
535 ValueAbbrev,
536 ValueAbbrev,
537 };
538
539 lhs: Builder.Constant,
540 rhs: Builder.Constant,
541 mask: Builder.Constant,
542 };
543
544 pub const ShuffleVectorEx = struct {
545 pub const ops = [_]AbbrevOp{
546 .{ .literal = 19 },
547 .{ .fixed_runtime = Builder.Type },
548 ValueAbbrev,
549 ValueAbbrev,
550 ValueAbbrev,
551 };
552
553 ty: Builder.Type,
554 lhs: Builder.Constant,
555 rhs: Builder.Constant,
556 mask: Builder.Constant,
557 };
558
559 pub const BlockAddress = struct {
560 pub const ops = [_]AbbrevOp{
561 .{ .literal = 21 },
562 .{ .fixed_runtime = Builder.Type },
563 ConstantAbbrev,
564 BlockAbbrev,
565 };
566 type_id: Builder.Type,
567 function: u32,
568 block: u32,
569 };
570
571 pub const DsoLocalEquivalentOrNoCfi = struct {
572 pub const ops = [_]AbbrevOp{
573 .{ .fixed = 5 },
574 .{ .fixed_runtime = Builder.Type },
575 ConstantAbbrev,
576 };
577 code: u5,
578 type_id: Builder.Type,
579 function: u32,
580 };
581};
582
583pub const MetadataBlock = struct {
584 pub const id = 15;
585
586 pub const abbrevs = [_]type{
587 Strings,
588 File,
589 CompileUnit,
590 Subprogram,
591 LexicalBlock,
592 Location,
593 BasicType,
594 CompositeType,
595 DerivedType,
596 SubroutineType,
597 Enumerator,
598 Subrange,
599 Expression,
600 Node,
601 LocalVar,
602 Parameter,
603 GlobalVar,
604 GlobalVarExpression,
605 Constant,
606 Name,
607 NamedNode,
608 };
609
610 pub const Strings = struct {
611 pub const ops = [_]AbbrevOp{
612 .{ .literal = 35 },
613 .{ .vbr = 6 },
614 .{ .vbr = 6 },
615 .blob,
616 };
617 num_strings: u32,
618 strings_offset: u32,
619 blob: []const u8,
620 };
621
622 pub const File = struct {
623 pub const ops = [_]AbbrevOp{
624 .{ .literal = 16 },
625 .{ .literal = 1 }, // is distinct
626 MetadataAbbrev, // filename
627 MetadataAbbrev, // directory
628 .{ .literal = 0 }, // checksum
629 .{ .literal = 0 }, // checksum
630 };
631
632 filename: Builder.MetadataString,
633 directory: Builder.MetadataString,
634 };
635
636 pub const CompileUnit = struct {
637 pub const ops = [_]AbbrevOp{
638 .{ .literal = 20 },
639 .{ .literal = 1 }, // is distinct
640 .{ .literal = std.dwarf.LANG.C99 }, // source language
641 MetadataAbbrev, // file
642 MetadataAbbrev, // producer
643 .{ .fixed = 1 }, // isOptimized
644 .{ .literal = 0 }, // raw flags
645 .{ .literal = 0 }, // runtime version
646 .{ .literal = 0 }, // split debug file name
647 .{ .literal = 1 }, // emission kind
648 MetadataAbbrev, // enums
649 .{ .literal = 0 }, // retained types
650 .{ .literal = 0 }, // subprograms
651 MetadataAbbrev, // globals
652 .{ .literal = 0 }, // imported entities
653 .{ .literal = 0 }, // DWO ID
654 .{ .literal = 0 }, // macros
655 .{ .literal = 0 }, // split debug inlining
656 .{ .literal = 0 }, // debug info profiling
657 .{ .literal = 0 }, // name table kind
658 .{ .literal = 0 }, // ranges base address
659 .{ .literal = 0 }, // raw sysroot
660 .{ .literal = 0 }, // raw SDK
661 };
662
663 file: Builder.Metadata,
664 producer: Builder.MetadataString,
665 is_optimized: bool,
666 enums: Builder.Metadata,
667 globals: Builder.Metadata,
668 };
669
670 pub const Subprogram = struct {
671 pub const ops = [_]AbbrevOp{
672 .{ .literal = 21 },
673 .{ .literal = 0b111 }, // is distinct | has sp flags | has flags
674 MetadataAbbrev, // scope
675 MetadataAbbrev, // name
676 MetadataAbbrev, // linkage name
677 MetadataAbbrev, // file
678 LineAbbrev, // line
679 MetadataAbbrev, // type
680 LineAbbrev, // scope line
681 .{ .literal = 0 }, // containing type
682 .{ .fixed = 32 }, // sp flags
683 .{ .literal = 0 }, // virtual index
684 .{ .fixed = 32 }, // flags
685 MetadataAbbrev, // compile unit
686 .{ .literal = 0 }, // template params
687 .{ .literal = 0 }, // declaration
688 .{ .literal = 0 }, // retained nodes
689 .{ .literal = 0 }, // this adjustment
690 .{ .literal = 0 }, // thrown types
691 .{ .literal = 0 }, // annotations
692 .{ .literal = 0 }, // target function name
693 };
694
695 scope: Builder.Metadata,
696 name: Builder.MetadataString,
697 linkage_name: Builder.MetadataString,
698 file: Builder.Metadata,
699 line: u32,
700 ty: Builder.Metadata,
701 scope_line: u32,
702 sp_flags: Builder.Metadata.Subprogram.SPFlags,
703 flags: Builder.Metadata.DIFlags,
704 compile_unit: Builder.Metadata,
705 };
706
707 pub const LexicalBlock = struct {
708 pub const ops = [_]AbbrevOp{
709 .{ .literal = 22 },
710 .{ .literal = 1 }, // is distinct
711 MetadataAbbrev, // scope
712 MetadataAbbrev, // file
713 LineAbbrev, // line
714 ColumnAbbrev, // column
715 };
716
717 scope: Builder.Metadata,
718 file: Builder.Metadata,
719 line: u32,
720 column: u32,
721 };
722
723 pub const Location = struct {
724 pub const ops = [_]AbbrevOp{
725 .{ .literal = 7 },
726 .{ .literal = 0 }, // is distinct
727 LineAbbrev, // line
728 ColumnAbbrev, // column
729 MetadataAbbrev, // scope
730 MetadataAbbrev, // inlined at
731 .{ .literal = 0 }, // is implicit code
732 };
733
734 line: u32,
735 column: u32,
736 scope: u32,
737 inlined_at: Builder.Metadata,
738 };
739
740 pub const BasicType = struct {
741 pub const ops = [_]AbbrevOp{
742 .{ .literal = 15 },
743 .{ .literal = 1 }, // is distinct
744 .{ .literal = std.dwarf.TAG.base_type }, // tag
745 MetadataAbbrev, // name
746 .{ .vbr = 6 }, // size in bits
747 .{ .literal = 0 }, // align in bits
748 .{ .vbr = 8 }, // encoding
749 .{ .literal = 0 }, // flags
750 };
751
752 name: Builder.MetadataString,
753 size_in_bits: u64,
754 encoding: u32,
755 };
756
757 pub const CompositeType = struct {
758 pub const ops = [_]AbbrevOp{
759 .{ .literal = 18 },
760 .{ .literal = 1 | 0x2 }, // is distinct | is not used in old type ref
761 .{ .fixed = 32 }, // tag
762 MetadataAbbrev, // name
763 MetadataAbbrev, // file
764 LineAbbrev, // line
765 MetadataAbbrev, // scope
766 MetadataAbbrev, // underlying type
767 .{ .vbr = 6 }, // size in bits
768 .{ .vbr = 6 }, // align in bits
769 .{ .literal = 0 }, // offset in bits
770 .{ .fixed = 32 }, // flags
771 MetadataAbbrev, // elements
772 .{ .literal = 0 }, // runtime lang
773 .{ .literal = 0 }, // vtable holder
774 .{ .literal = 0 }, // template params
775 .{ .literal = 0 }, // raw id
776 .{ .literal = 0 }, // discriminator
777 .{ .literal = 0 }, // data location
778 .{ .literal = 0 }, // associated
779 .{ .literal = 0 }, // allocated
780 .{ .literal = 0 }, // rank
781 .{ .literal = 0 }, // annotations
782 };
783
784 tag: u32,
785 name: Builder.MetadataString,
786 file: Builder.Metadata,
787 line: u32,
788 scope: Builder.Metadata,
789 underlying_type: Builder.Metadata,
790 size_in_bits: u64,
791 align_in_bits: u64,
792 flags: Builder.Metadata.DIFlags,
793 elements: Builder.Metadata,
794 };
795
796 pub const DerivedType = struct {
797 pub const ops = [_]AbbrevOp{
798 .{ .literal = 17 },
799 .{ .literal = 1 }, // is distinct
800 .{ .fixed = 32 }, // tag
801 MetadataAbbrev, // name
802 MetadataAbbrev, // file
803 LineAbbrev, // line
804 MetadataAbbrev, // scope
805 MetadataAbbrev, // underlying type
806 .{ .vbr = 6 }, // size in bits
807 .{ .vbr = 6 }, // align in bits
808 .{ .vbr = 6 }, // offset in bits
809 .{ .literal = 0 }, // flags
810 .{ .literal = 0 }, // extra data
811 };
812
813 tag: u32,
814 name: Builder.MetadataString,
815 file: Builder.Metadata,
816 line: u32,
817 scope: Builder.Metadata,
818 underlying_type: Builder.Metadata,
819 size_in_bits: u64,
820 align_in_bits: u64,
821 offset_in_bits: u64,
822 };
823
824 pub const SubroutineType = struct {
825 pub const ops = [_]AbbrevOp{
826 .{ .literal = 19 },
827 .{ .literal = 1 | 0x2 }, // is distinct | has no old type refs
828 .{ .literal = 0 }, // flags
829 MetadataAbbrev, // types
830 .{ .literal = 0 }, // cc
831 };
832
833 types: Builder.Metadata,
834 };
835
836 pub const Enumerator = struct {
837 pub const id = 14;
838
839 pub const Flags = packed struct(u3) {
840 distinct: bool = true,
841 unsigned: bool,
842 bigint: bool,
843 };
844
845 pub const ops = [_]AbbrevOp{
846 .{ .literal = Enumerator.id },
847 .{ .fixed = @bitSizeOf(Flags) }, // flags
848 .{ .vbr = 6 }, // bit width
849 MetadataAbbrev, // name
850 .{ .vbr = 16 }, // integer value
851 };
852
853 flags: Flags,
854 bit_width: u32,
855 name: Builder.MetadataString,
856 value: u64,
857 };
858
859 pub const Subrange = struct {
860 pub const ops = [_]AbbrevOp{
861 .{ .literal = 13 },
862 .{ .literal = 0b11 }, // is distinct | version
863 MetadataAbbrev, // count
864 MetadataAbbrev, // lower bound
865 .{ .literal = 0 }, // upper bound
866 .{ .literal = 0 }, // stride
867 };
868
869 count: Builder.Metadata,
870 lower_bound: Builder.Metadata,
871 };
872
873 pub const Expression = struct {
874 pub const ops = [_]AbbrevOp{
875 .{ .literal = 29 },
876 .{ .literal = 0 | (3 << 1) }, // is distinct | version
877 MetadataArrayAbbrev, // elements
878 };
879
880 elements: []const u32,
881 };
882
883 pub const Node = struct {
884 pub const ops = [_]AbbrevOp{
885 .{ .literal = 3 },
886 MetadataArrayAbbrev, // elements
887 };
888
889 elements: []const Builder.Metadata,
890 };
891
892 pub const LocalVar = struct {
893 pub const ops = [_]AbbrevOp{
894 .{ .literal = 28 },
895 .{ .literal = 0b11 }, // is distinct | has alignment
896 MetadataAbbrev, // scope
897 MetadataAbbrev, // name
898 MetadataAbbrev, // file
899 LineAbbrev, // line
900 MetadataAbbrev, // type
901 .{ .literal = 0 }, // arg
902 .{ .literal = 0 }, // flags
903 .{ .literal = 0 }, // align bits
904 .{ .literal = 0 }, // annotations
905 };
906
907 scope: Builder.Metadata,
908 name: Builder.MetadataString,
909 file: Builder.Metadata,
910 line: u32,
911 ty: Builder.Metadata,
912 };
913
914 pub const Parameter = struct {
915 pub const ops = [_]AbbrevOp{
916 .{ .literal = 28 },
917 .{ .literal = 0b11 }, // is distinct | has alignment
918 MetadataAbbrev, // scope
919 MetadataAbbrev, // name
920 MetadataAbbrev, // file
921 LineAbbrev, // line
922 MetadataAbbrev, // type
923 .{ .vbr = 4 }, // arg
924 .{ .literal = 0 }, // flags
925 .{ .literal = 0 }, // align bits
926 .{ .literal = 0 }, // annotations
927 };
928
929 scope: Builder.Metadata,
930 name: Builder.MetadataString,
931 file: Builder.Metadata,
932 line: u32,
933 ty: Builder.Metadata,
934 arg: u32,
935 };
936
937 pub const GlobalVar = struct {
938 pub const ops = [_]AbbrevOp{
939 .{ .literal = 27 },
940 .{ .literal = 0b101 }, // is distinct | version
941 MetadataAbbrev, // scope
942 MetadataAbbrev, // name
943 MetadataAbbrev, // linkage name
944 MetadataAbbrev, // file
945 LineAbbrev, // line
946 MetadataAbbrev, // type
947 .{ .fixed = 1 }, // local
948 .{ .literal = 1 }, // defined
949 .{ .literal = 0 }, // static data members declaration
950 .{ .literal = 0 }, // template params
951 .{ .literal = 0 }, // align in bits
952 .{ .literal = 0 }, // annotations
953 };
954
955 scope: Builder.Metadata,
956 name: Builder.MetadataString,
957 linkage_name: Builder.MetadataString,
958 file: Builder.Metadata,
959 line: u32,
960 ty: Builder.Metadata,
961 local: bool,
962 };
963
964 pub const GlobalVarExpression = struct {
965 pub const ops = [_]AbbrevOp{
966 .{ .literal = 37 },
967 .{ .literal = 1 }, // is distinct
968 MetadataAbbrev, // variable
969 MetadataAbbrev, // expression
970 };
971
972 variable: Builder.Metadata,
973 expression: Builder.Metadata,
974 };
975
976 pub const Constant = struct {
977 pub const ops = [_]AbbrevOp{
978 .{ .literal = 2 },
979 MetadataAbbrev, // type
980 MetadataAbbrev, // value
981 };
982
983 ty: Builder.Type,
984 constant: Builder.Constant,
985 };
986
987 pub const Name = struct {
988 pub const ops = [_]AbbrevOp{
989 .{ .literal = 4 },
990 .{ .array_fixed = 8 }, // name
991 };
992
993 name: []const u8,
994 };
995
996 pub const NamedNode = struct {
997 pub const ops = [_]AbbrevOp{
998 .{ .literal = 10 },
999 MetadataArrayAbbrev, // elements
1000 };
1001
1002 elements: []const Builder.Metadata,
1003 };
1004};
1005
1006pub const FunctionMetadataBlock = struct {
1007 pub const id = 15;
1008
1009 pub const abbrevs = [_]type{
1010 Value,
1011 };
1012
1013 pub const Value = struct {
1014 pub const ops = [_]AbbrevOp{
1015 .{ .literal = 2 },
1016 .{ .fixed = 32 }, // variable
1017 .{ .fixed = 32 }, // expression
1018 };
1019
1020 ty: Builder.Type,
1021 value: Builder.Value,
1022 };
1023};
1024
1025pub const FunctionBlock = struct {
1026 pub const id = 12;
1027
1028 pub const abbrevs = [_]type{
1029 DeclareBlocks,
1030 Call,
1031 CallFast,
1032 FNeg,
1033 FNegFast,
1034 Binary,
1035 BinaryFast,
1036 Cmp,
1037 CmpFast,
1038 Select,
1039 SelectFast,
1040 Cast,
1041 Alloca,
1042 GetElementPtr,
1043 ExtractValue,
1044 InsertValue,
1045 ExtractElement,
1046 InsertElement,
1047 ShuffleVector,
1048 RetVoid,
1049 Ret,
1050 Unreachable,
1051 Load,
1052 LoadAtomic,
1053 Store,
1054 StoreAtomic,
1055 BrUnconditional,
1056 BrConditional,
1057 VaArg,
1058 AtomicRmw,
1059 CmpXchg,
1060 Fence,
1061 DebugLoc,
1062 DebugLocAgain,
1063 };
1064
1065 pub const DeclareBlocks = struct {
1066 pub const ops = [_]AbbrevOp{
1067 .{ .literal = 1 },
1068 .{ .vbr = 8 },
1069 };
1070 num_blocks: usize,
1071 };
1072
1073 pub const Call = struct {
1074 pub const CallType = packed struct(u17) {
1075 tail: bool = false,
1076 call_conv: Builder.CallConv,
1077 reserved: u3 = 0,
1078 must_tail: bool = false,
1079 // We always use the explicit type version as that is what LLVM does
1080 explicit_type: bool = true,
1081 no_tail: bool = false,
1082 };
1083 pub const ops = [_]AbbrevOp{
1084 .{ .literal = 34 },
1085 .{ .fixed_runtime = Builder.FunctionAttributes },
1086 .{ .fixed = @bitSizeOf(CallType) },
1087 .{ .fixed_runtime = Builder.Type },
1088 ValueAbbrev, // Callee
1089 ValueArrayAbbrev, // Args
1090 };
1091
1092 attributes: Builder.FunctionAttributes,
1093 call_type: CallType,
1094 type_id: Builder.Type,
1095 callee: Builder.Value,
1096 args: []const Builder.Value,
1097 };
1098
1099 pub const CallFast = struct {
1100 const CallType = packed struct(u18) {
1101 tail: bool = false,
1102 call_conv: Builder.CallConv,
1103 reserved: u3 = 0,
1104 must_tail: bool = false,
1105 // We always use the explicit type version as that is what LLVM does
1106 explicit_type: bool = true,
1107 no_tail: bool = false,
1108 fast: bool = true,
1109 };
1110
1111 pub const ops = [_]AbbrevOp{
1112 .{ .literal = 34 },
1113 .{ .fixed_runtime = Builder.FunctionAttributes },
1114 .{ .fixed = @bitSizeOf(CallType) },
1115 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1116 .{ .fixed_runtime = Builder.Type },
1117 ValueAbbrev, // Callee
1118 ValueArrayAbbrev, // Args
1119 };
1120
1121 attributes: Builder.FunctionAttributes,
1122 call_type: CallType,
1123 fast_math: Builder.FastMath,
1124 type_id: Builder.Type,
1125 callee: Builder.Value,
1126 args: []const Builder.Value,
1127 };
1128
1129 pub const FNeg = struct {
1130 pub const ops = [_]AbbrevOp{
1131 .{ .literal = 56 },
1132 ValueAbbrev,
1133 .{ .literal = 0 },
1134 };
1135
1136 val: u32,
1137 };
1138
1139 pub const FNegFast = struct {
1140 pub const ops = [_]AbbrevOp{
1141 .{ .literal = 56 },
1142 ValueAbbrev,
1143 .{ .literal = 0 },
1144 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1145 };
1146
1147 val: u32,
1148 fast_math: Builder.FastMath,
1149 };
1150
1151 pub const Binary = struct {
1152 const BinaryOpcode = Builder.BinaryOpcode;
1153 pub const ops = [_]AbbrevOp{
1154 .{ .literal = 2 },
1155 ValueAbbrev,
1156 ValueAbbrev,
1157 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1158 };
1159
1160 lhs: u32,
1161 rhs: u32,
1162 opcode: BinaryOpcode,
1163 };
1164
1165 pub const BinaryFast = struct {
1166 const BinaryOpcode = Builder.BinaryOpcode;
1167 pub const ops = [_]AbbrevOp{
1168 .{ .literal = 2 },
1169 ValueAbbrev,
1170 ValueAbbrev,
1171 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1172 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1173 };
1174
1175 lhs: u32,
1176 rhs: u32,
1177 opcode: BinaryOpcode,
1178 fast_math: Builder.FastMath,
1179 };
1180
1181 pub const Cmp = struct {
1182 const CmpPredicate = Builder.CmpPredicate;
1183 pub const ops = [_]AbbrevOp{
1184 .{ .literal = 28 },
1185 ValueAbbrev,
1186 ValueAbbrev,
1187 .{ .fixed = @bitSizeOf(CmpPredicate) },
1188 };
1189
1190 lhs: u32,
1191 rhs: u32,
1192 pred: CmpPredicate,
1193 };
1194
1195 pub const CmpFast = struct {
1196 const CmpPredicate = Builder.CmpPredicate;
1197 pub const ops = [_]AbbrevOp{
1198 .{ .literal = 28 },
1199 ValueAbbrev,
1200 ValueAbbrev,
1201 .{ .fixed = @bitSizeOf(CmpPredicate) },
1202 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1203 };
1204
1205 lhs: u32,
1206 rhs: u32,
1207 pred: CmpPredicate,
1208 fast_math: Builder.FastMath,
1209 };
1210
1211 pub const Select = struct {
1212 pub const ops = [_]AbbrevOp{
1213 .{ .literal = 29 },
1214 ValueAbbrev,
1215 ValueAbbrev,
1216 ValueAbbrev,
1217 };
1218
1219 lhs: u32,
1220 rhs: u32,
1221 cond: u32,
1222 };
1223
1224 pub const SelectFast = struct {
1225 pub const ops = [_]AbbrevOp{
1226 .{ .literal = 29 },
1227 ValueAbbrev,
1228 ValueAbbrev,
1229 ValueAbbrev,
1230 .{ .fixed = @bitSizeOf(Builder.FastMath) },
1231 };
1232
1233 lhs: u32,
1234 rhs: u32,
1235 cond: u32,
1236 fast_math: Builder.FastMath,
1237 };
1238
1239 pub const Cast = struct {
1240 const CastOpcode = Builder.CastOpcode;
1241 pub const ops = [_]AbbrevOp{
1242 .{ .literal = 3 },
1243 ValueAbbrev,
1244 .{ .fixed_runtime = Builder.Type },
1245 .{ .fixed = @bitSizeOf(CastOpcode) },
1246 };
1247
1248 val: u32,
1249 type_index: Builder.Type,
1250 opcode: CastOpcode,
1251 };
1252
1253 pub const Alloca = struct {
1254 pub const Flags = packed struct(u11) {
1255 align_lower: u5,
1256 inalloca: bool,
1257 explicit_type: bool,
1258 swift_error: bool,
1259 align_upper: u3,
1260 };
1261 pub const ops = [_]AbbrevOp{
1262 .{ .literal = 19 },
1263 .{ .fixed_runtime = Builder.Type },
1264 .{ .fixed_runtime = Builder.Type },
1265 ValueAbbrev,
1266 .{ .fixed = @bitSizeOf(Flags) },
1267 };
1268
1269 inst_type: Builder.Type,
1270 len_type: Builder.Type,
1271 len_value: u32,
1272 flags: Flags,
1273 };
1274
1275 pub const RetVoid = struct {
1276 pub const ops = [_]AbbrevOp{
1277 .{ .literal = 10 },
1278 };
1279 };
1280
1281 pub const Ret = struct {
1282 pub const ops = [_]AbbrevOp{
1283 .{ .literal = 10 },
1284 ValueAbbrev,
1285 };
1286 val: u32,
1287 };
1288
1289 pub const GetElementPtr = struct {
1290 pub const ops = [_]AbbrevOp{
1291 .{ .literal = 43 },
1292 .{ .fixed = 1 },
1293 .{ .fixed_runtime = Builder.Type },
1294 ValueAbbrev,
1295 ValueArrayAbbrev,
1296 };
1297
1298 is_inbounds: bool,
1299 type_index: Builder.Type,
1300 base: Builder.Value,
1301 indices: []const Builder.Value,
1302 };
1303
1304 pub const ExtractValue = struct {
1305 pub const ops = [_]AbbrevOp{
1306 .{ .literal = 26 },
1307 ValueAbbrev,
1308 ValueArrayAbbrev,
1309 };
1310
1311 val: u32,
1312 indices: []const u32,
1313 };
1314
1315 pub const InsertValue = struct {
1316 pub const ops = [_]AbbrevOp{
1317 .{ .literal = 27 },
1318 ValueAbbrev,
1319 ValueAbbrev,
1320 ValueArrayAbbrev,
1321 };
1322
1323 val: u32,
1324 elem: u32,
1325 indices: []const u32,
1326 };
1327
1328 pub const ExtractElement = struct {
1329 pub const ops = [_]AbbrevOp{
1330 .{ .literal = 6 },
1331 ValueAbbrev,
1332 ValueAbbrev,
1333 };
1334
1335 val: u32,
1336 index: u32,
1337 };
1338
1339 pub const InsertElement = struct {
1340 pub const ops = [_]AbbrevOp{
1341 .{ .literal = 7 },
1342 ValueAbbrev,
1343 ValueAbbrev,
1344 ValueAbbrev,
1345 };
1346
1347 val: u32,
1348 elem: u32,
1349 index: u32,
1350 };
1351
1352 pub const ShuffleVector = struct {
1353 pub const ops = [_]AbbrevOp{
1354 .{ .literal = 8 },
1355 ValueAbbrev,
1356 ValueAbbrev,
1357 ValueAbbrev,
1358 };
1359
1360 lhs: u32,
1361 rhs: u32,
1362 mask: u32,
1363 };
1364
1365 pub const Unreachable = struct {
1366 pub const ops = [_]AbbrevOp{
1367 .{ .literal = 15 },
1368 };
1369 };
1370
1371 pub const Load = struct {
1372 pub const ops = [_]AbbrevOp{
1373 .{ .literal = 20 },
1374 ValueAbbrev,
1375 .{ .fixed_runtime = Builder.Type },
1376 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1377 .{ .fixed = 1 },
1378 };
1379 ptr: u32,
1380 ty: Builder.Type,
1381 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1382 is_volatile: bool,
1383 };
1384
1385 pub const LoadAtomic = struct {
1386 pub const ops = [_]AbbrevOp{
1387 .{ .literal = 41 },
1388 ValueAbbrev,
1389 .{ .fixed_runtime = Builder.Type },
1390 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1391 .{ .fixed = 1 },
1392 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1393 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1394 };
1395 ptr: u32,
1396 ty: Builder.Type,
1397 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1398 is_volatile: bool,
1399 success_ordering: Builder.AtomicOrdering,
1400 sync_scope: Builder.SyncScope,
1401 };
1402
1403 pub const Store = struct {
1404 pub const ops = [_]AbbrevOp{
1405 .{ .literal = 44 },
1406 ValueAbbrev,
1407 ValueAbbrev,
1408 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1409 .{ .fixed = 1 },
1410 };
1411 ptr: u32,
1412 val: u32,
1413 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1414 is_volatile: bool,
1415 };
1416
1417 pub const StoreAtomic = struct {
1418 pub const ops = [_]AbbrevOp{
1419 .{ .literal = 45 },
1420 ValueAbbrev,
1421 ValueAbbrev,
1422 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1423 .{ .fixed = 1 },
1424 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1425 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1426 };
1427 ptr: u32,
1428 val: u32,
1429 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1430 is_volatile: bool,
1431 success_ordering: Builder.AtomicOrdering,
1432 sync_scope: Builder.SyncScope,
1433 };
1434
1435 pub const BrUnconditional = struct {
1436 pub const ops = [_]AbbrevOp{
1437 .{ .literal = 11 },
1438 BlockAbbrev,
1439 };
1440 block: u32,
1441 };
1442
1443 pub const BrConditional = struct {
1444 pub const ops = [_]AbbrevOp{
1445 .{ .literal = 11 },
1446 BlockAbbrev,
1447 BlockAbbrev,
1448 BlockAbbrev,
1449 };
1450 then_block: u32,
1451 else_block: u32,
1452 condition: u32,
1453 };
1454
1455 pub const VaArg = struct {
1456 pub const ops = [_]AbbrevOp{
1457 .{ .literal = 23 },
1458 .{ .fixed_runtime = Builder.Type },
1459 ValueAbbrev,
1460 .{ .fixed_runtime = Builder.Type },
1461 };
1462 list_type: Builder.Type,
1463 list: u32,
1464 type: Builder.Type,
1465 };
1466
1467 pub const AtomicRmw = struct {
1468 pub const ops = [_]AbbrevOp{
1469 .{ .literal = 59 },
1470 ValueAbbrev,
1471 ValueAbbrev,
1472 .{ .fixed = @bitSizeOf(Builder.Function.Instruction.AtomicRmw.Operation) },
1473 .{ .fixed = 1 },
1474 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1475 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1476 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1477 };
1478 ptr: u32,
1479 val: u32,
1480 operation: Builder.Function.Instruction.AtomicRmw.Operation,
1481 is_volatile: bool,
1482 success_ordering: Builder.AtomicOrdering,
1483 sync_scope: Builder.SyncScope,
1484 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1485 };
1486
1487 pub const CmpXchg = struct {
1488 pub const ops = [_]AbbrevOp{
1489 .{ .literal = 46 },
1490 ValueAbbrev,
1491 ValueAbbrev,
1492 ValueAbbrev,
1493 .{ .fixed = 1 },
1494 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1495 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1496 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1497 .{ .fixed = 1 },
1498 .{ .fixed = @bitSizeOf(Builder.Alignment) },
1499 };
1500 ptr: u32,
1501 cmp: u32,
1502 new: u32,
1503 is_volatile: bool,
1504 success_ordering: Builder.AtomicOrdering,
1505 sync_scope: Builder.SyncScope,
1506 failure_ordering: Builder.AtomicOrdering,
1507 is_weak: bool,
1508 alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)),
1509 };
1510
1511 pub const Fence = struct {
1512 pub const ops = [_]AbbrevOp{
1513 .{ .literal = 36 },
1514 .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) },
1515 .{ .fixed = @bitSizeOf(Builder.SyncScope) },
1516 };
1517 ordering: Builder.AtomicOrdering,
1518 sync_scope: Builder.SyncScope,
1519 };
1520
1521 pub const DebugLoc = struct {
1522 pub const ops = [_]AbbrevOp{
1523 .{ .literal = 35 },
1524 .{ .fixed = 32 },
1525 .{ .fixed = 32 },
1526 .{ .fixed = 32 },
1527 .{ .fixed = 32 },
1528 .{ .fixed = 1 },
1529 };
1530 line: u32,
1531 column: u32,
1532 scope: Builder.Metadata,
1533 inlined_at: Builder.Metadata,
1534 is_implicit: bool,
1535 };
1536
1537 pub const DebugLocAgain = struct {
1538 pub const ops = [_]AbbrevOp{
1539 .{ .literal = 33 },
1540 };
1541 };
1542};
1543
1544pub const FunctionValueSymbolTable = struct {
1545 pub const id = 14;
1546
1547 pub const abbrevs = [_]type{
1548 BlockEntry,
1549 };
1550
1551 pub const BlockEntry = struct {
1552 pub const ops = [_]AbbrevOp{
1553 .{ .literal = 2 },
1554 ValueAbbrev,
1555 .{ .array_fixed = 8 },
1556 };
1557 value_id: u32,
1558 string: []const u8,
1559 };
1560};
1561
1562pub const Strtab = struct {
1563 pub const id = 23;
1564
1565 pub const abbrevs = [_]type{Blob};
1566
1567 pub const Blob = struct {
1568 pub const ops = [_]AbbrevOp{
1569 .{ .literal = 1 },
1570 .blob,
1571 };
1572 blob: []const u8,
1573 };
1574};