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" {...@@ -460,13 +460,11 @@ test "std.meta.FieldType" {
460 try testing.expect(FieldType(U, .d) == *const u8);460 try testing.expect(FieldType(U, .d) == *const u8);
461}461}
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 {
464 return comptime blk: {464 return comptime blk: {
465 const fieldInfos = fields(T);465 const fieldInfos = fields(T);
466 var names: [fieldInfos.len][]const u8 = undefined;466 var names: [fieldInfos.len][:0]const u8 = undefined;
467 for (fieldInfos, 0..) |field, i| {467 for (&names, fieldInfos) |*name, field| name.* = field.name;
468 names[i] = field.name;
469 }
470 break :blk &names;468 break :blk &names;
471 };469 };
472}470}
src/codegen/llvm.zig+91-93
...@@ -872,8 +872,8 @@ pub const Object = struct {...@@ -872,8 +872,8 @@ pub const Object = struct {
872 };872 };
873873
874 const debug_file = try builder.debugFile(874 const debug_file = try builder.debugFile(
875 try builder.metadataString(compile_unit_dir),
876 try builder.metadataString(comp.root_name),875 try builder.metadataString(comp.root_name),
876 try builder.metadataString(compile_unit_dir),
877 );877 );
878878
879 const debug_enums_fwd_ref = try builder.debugForwardReference();879 const debug_enums_fwd_ref = try builder.debugForwardReference();
...@@ -1646,10 +1646,6 @@ pub const Object = struct {...@@ -1646,10 +1646,6 @@ pub const Object = struct {
1646 const line_number = decl.src_line + 1;1646 const line_number = decl.src_line + 1;
1647 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and1647 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
1648 !zcu.decl_exports.contains(decl_index);1648 !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;
1653 const debug_decl_type = try o.lowerDebugType(decl.ty);1649 const debug_decl_type = try o.lowerDebugType(decl.ty);
16541650
1655 break :blk try o.builder.debugSubprogram(1651 break :blk try o.builder.debugSubprogram(
...@@ -1660,14 +1656,20 @@ pub const Object = struct {...@@ -1660,14 +1656,20 @@ pub const Object = struct {
1660 line_number + func.lbrace_line,1656 line_number + func.lbrace_line,
1661 debug_decl_type,1657 debug_decl_type,
1662 .{1658 .{
1663 .optimized = owner_mod.optimize_mode != .Debug,1659 .di_flags = .{
1664 .definition = true,1660 .StaticMember = true,
1665 .local = is_internal_linkage,1661 .NoReturn = fn_info.return_type == .noreturn_type,
1666 .debug_info_flags = Builder.DIFlags.StaticMember | noret_bit,1662 },
1663 .sp_flags = .{
1664 .Optimized = owner_mod.optimize_mode != .Debug,
1665 .Definition = true,
1666 .LocalToUnit = is_internal_linkage,
1667 },
1667 },1668 },
1668 o.debug_compile_unit,1669 o.debug_compile_unit,
1669 );1670 );
1670 };1671 };
1672 function_index.setSubprogram(subprogram, &o.builder);
16711673
1672 var fg: FuncGen = .{1674 var fg: FuncGen = .{
1673 .gpa = gpa,1675 .gpa = gpa,
...@@ -1682,8 +1684,7 @@ pub const Object = struct {...@@ -1682,8 +1684,7 @@ pub const Object = struct {
1682 .blocks = .{},1684 .blocks = .{},
1683 .sync_scope = if (owner_mod.single_threaded) .singlethread else .system,1685 .sync_scope = if (owner_mod.single_threaded) .singlethread else .system,
1684 .file = file,1686 .file = file,
1685 .subprogram = subprogram,1687 .scope = subprogram,
1686 .current_scope = subprogram,
1687 .base_line = dg.decl.src_line,1688 .base_line = dg.decl.src_line,
1688 .prev_dbg_line = 0,1689 .prev_dbg_line = 0,
1689 .prev_dbg_column = 0,1690 .prev_dbg_column = 0,
...@@ -1914,8 +1915,8 @@ pub const Object = struct {...@@ -1914,8 +1915,8 @@ pub const Object = struct {
19141915
1915 fn getDebugFile(o: *Object, file: *const Module.File) Allocator.Error!Builder.Metadata {1916 fn getDebugFile(o: *Object, file: *const Module.File) Allocator.Error!Builder.Metadata {
1916 return try o.builder.debugFile(1917 return try o.builder.debugFile(
1917 if (std.fs.path.dirname(file.sub_file_path)) |dirname| try o.builder.metadataString(dirname) else .none,
1918 try o.builder.metadataString(std.fs.path.basename(file.sub_file_path)),1918 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,
1919 );1920 );
1920 }1921 }
19211922
...@@ -1923,7 +1924,7 @@ pub const Object = struct {...@@ -1923,7 +1924,7 @@ pub const Object = struct {
1923 o: *Object,1924 o: *Object,
1924 ty: Type,1925 ty: Type,
1925 ) Allocator.Error!Builder.Metadata {1926 ) Allocator.Error!Builder.Metadata {
1926 if (o.builder.strip) return Builder.Metadata.none;1927 if (o.builder.strip) return .none;
1927 const gpa = o.gpa;1928 const gpa = o.gpa;
1928 const target = o.target;1929 const target = o.target;
1929 const mod = o.module;1930 const mod = o.module;
...@@ -2086,7 +2087,7 @@ pub const Object = struct {...@@ -2086,7 +2087,7 @@ pub const Object = struct {
20862087
2087 const debug_ptr_type = try o.builder.debugMemberType(2088 const debug_ptr_type = try o.builder.debugMemberType(
2088 try o.builder.metadataString("ptr"),2089 try o.builder.metadataString("ptr"),
2089 Builder.Metadata.none, // File2090 .none, // File
2090 debug_fwd_ref,2091 debug_fwd_ref,
2091 0, // Line2092 0, // Line
2092 try o.lowerDebugType(ptr_ty),2093 try o.lowerDebugType(ptr_ty),
...@@ -2097,7 +2098,7 @@ pub const Object = struct {...@@ -2097,7 +2098,7 @@ pub const Object = struct {
20972098
2098 const debug_len_type = try o.builder.debugMemberType(2099 const debug_len_type = try o.builder.debugMemberType(
2099 try o.builder.metadataString("len"),2100 try o.builder.metadataString("len"),
2100 Builder.Metadata.none, // File2101 .none, // File
2101 debug_fwd_ref,2102 debug_fwd_ref,
2102 0, // Line2103 0, // Line
2103 try o.lowerDebugType(len_ty),2104 try o.lowerDebugType(len_ty),
...@@ -2108,10 +2109,10 @@ pub const Object = struct {...@@ -2108,10 +2109,10 @@ pub const Object = struct {
21082109
2109 const debug_slice_type = try o.builder.debugStructType(2110 const debug_slice_type = try o.builder.debugStructType(
2110 try o.builder.metadataString(name),2111 try o.builder.metadataString(name),
2111 Builder.Metadata.none, // File2112 .none, // File
2112 o.debug_compile_unit, // Scope2113 o.debug_compile_unit, // Scope
2113 line,2114 line,
2114 Builder.Metadata.none, // Underlying type2115 .none, // Underlying type
2115 ty.abiSize(mod) * 8,2116 ty.abiSize(mod) * 8,
2116 ty.abiAlignment(mod).toByteUnits(0) * 8,2117 ty.abiAlignment(mod).toByteUnits(0) * 8,
2117 try o.builder.debugTuple(&.{2118 try o.builder.debugTuple(&.{
...@@ -2136,8 +2137,8 @@ pub const Object = struct {...@@ -2136,8 +2137,8 @@ pub const Object = struct {
21362137
2137 const debug_ptr_type = try o.builder.debugPointerType(2138 const debug_ptr_type = try o.builder.debugPointerType(
2138 try o.builder.metadataString(name),2139 try o.builder.metadataString(name),
2139 Builder.Metadata.none, // File2140 .none, // File
2140 Builder.Metadata.none, // Scope2141 .none, // Scope
2141 0, // Line2142 0, // Line
2142 debug_elem_ty,2143 debug_elem_ty,
2143 target.ptrBitWidth(),2144 target.ptrBitWidth(),
...@@ -2172,19 +2173,19 @@ pub const Object = struct {...@@ -2172,19 +2173,19 @@ pub const Object = struct {
2172 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),2173 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
2173 try o.namespaceToDebugScope(owner_decl.src_namespace),2174 try o.namespaceToDebugScope(owner_decl.src_namespace),
2174 owner_decl.src_node + 1, // Line2175 owner_decl.src_node + 1, // Line
2175 Builder.Metadata.none, // Underlying type2176 .none, // Underlying type
2176 0, // Size2177 0, // Size
2177 0, // Align2178 0, // Align
2178 Builder.Metadata.none, // Fields2179 .none, // Fields
2179 );2180 );
2180 try o.debug_type_map.put(gpa, ty, debug_opaque_type);2181 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
2181 return debug_opaque_type;2182 return debug_opaque_type;
2182 },2183 },
2183 .Array => {2184 .Array => {
2184 const debug_array_type = try o.builder.debugArrayType(2185 const debug_array_type = try o.builder.debugArrayType(
2185 Builder.MetadataString.none, // Name2186 .none, // Name
2186 Builder.Metadata.none, // File2187 .none, // File
2187 Builder.Metadata.none, // Scope2188 .none, // Scope
2188 0, // Line2189 0, // Line
2189 try o.lowerDebugType(ty.childType(mod)),2190 try o.lowerDebugType(ty.childType(mod)),
2190 ty.abiSize(mod) * 8,2191 ty.abiSize(mod) * 8,
...@@ -2225,9 +2226,9 @@ pub const Object = struct {...@@ -2225,9 +2226,9 @@ pub const Object = struct {
2225 };2226 };
22262227
2227 const debug_vector_type = try o.builder.debugVectorType(2228 const debug_vector_type = try o.builder.debugVectorType(
2228 Builder.MetadataString.none, // Name2229 .none, // Name
2229 Builder.Metadata.none, // File2230 .none, // File
2230 Builder.Metadata.none, // Scope2231 .none, // Scope
2231 0, // Line2232 0, // Line
2232 debug_elem_type,2233 debug_elem_type,
2233 ty.abiSize(mod) * 8,2234 ty.abiSize(mod) * 8,
...@@ -2282,7 +2283,7 @@ pub const Object = struct {...@@ -2282,7 +2283,7 @@ pub const Object = struct {
22822283
2283 const debug_data_type = try o.builder.debugMemberType(2284 const debug_data_type = try o.builder.debugMemberType(
2284 try o.builder.metadataString("data"),2285 try o.builder.metadataString("data"),
2285 Builder.Metadata.none, // File2286 .none, // File
2286 debug_fwd_ref,2287 debug_fwd_ref,
2287 0, // Line2288 0, // Line
2288 try o.lowerDebugType(child_ty),2289 try o.lowerDebugType(child_ty),
...@@ -2293,7 +2294,7 @@ pub const Object = struct {...@@ -2293,7 +2294,7 @@ pub const Object = struct {
22932294
2294 const debug_some_type = try o.builder.debugMemberType(2295 const debug_some_type = try o.builder.debugMemberType(
2295 try o.builder.metadataString("some"),2296 try o.builder.metadataString("some"),
2296 Builder.Metadata.none,2297 .none,
2297 debug_fwd_ref,2298 debug_fwd_ref,
2298 0,2299 0,
2299 try o.lowerDebugType(non_null_ty),2300 try o.lowerDebugType(non_null_ty),
...@@ -2304,10 +2305,10 @@ pub const Object = struct {...@@ -2304,10 +2305,10 @@ pub const Object = struct {
23042305
2305 const debug_optional_type = try o.builder.debugStructType(2306 const debug_optional_type = try o.builder.debugStructType(
2306 try o.builder.metadataString(name),2307 try o.builder.metadataString(name),
2307 Builder.Metadata.none, // File2308 .none, // File
2308 o.debug_compile_unit, // Scope2309 o.debug_compile_unit, // Scope
2309 0, // Line2310 0, // Line
2310 Builder.Metadata.none, // Underlying type2311 .none, // Underlying type
2311 ty.abiSize(mod) * 8,2312 ty.abiSize(mod) * 8,
2312 ty.abiAlignment(mod).toByteUnits(0) * 8,2313 ty.abiAlignment(mod).toByteUnits(0) * 8,
2313 try o.builder.debugTuple(&.{2314 try o.builder.debugTuple(&.{
...@@ -2362,7 +2363,7 @@ pub const Object = struct {...@@ -2362,7 +2363,7 @@ pub const Object = struct {
2362 var fields: [2]Builder.Metadata = undefined;2363 var fields: [2]Builder.Metadata = undefined;
2363 fields[error_index] = try o.builder.debugMemberType(2364 fields[error_index] = try o.builder.debugMemberType(
2364 try o.builder.metadataString("tag"),2365 try o.builder.metadataString("tag"),
2365 Builder.Metadata.none, // File2366 .none, // File
2366 debug_fwd_ref,2367 debug_fwd_ref,
2367 0, // Line2368 0, // Line
2368 try o.lowerDebugType(Type.anyerror),2369 try o.lowerDebugType(Type.anyerror),
...@@ -2372,7 +2373,7 @@ pub const Object = struct {...@@ -2372,7 +2373,7 @@ pub const Object = struct {
2372 );2373 );
2373 fields[payload_index] = try o.builder.debugMemberType(2374 fields[payload_index] = try o.builder.debugMemberType(
2374 try o.builder.metadataString("value"),2375 try o.builder.metadataString("value"),
2375 Builder.Metadata.none, // File2376 .none, // File
2376 debug_fwd_ref,2377 debug_fwd_ref,
2377 0, // Line2378 0, // Line
2378 try o.lowerDebugType(payload_ty),2379 try o.lowerDebugType(payload_ty),
...@@ -2383,10 +2384,10 @@ pub const Object = struct {...@@ -2383,10 +2384,10 @@ pub const Object = struct {
23832384
2384 const debug_error_union_type = try o.builder.debugStructType(2385 const debug_error_union_type = try o.builder.debugStructType(
2385 try o.builder.metadataString(name),2386 try o.builder.metadataString(name),
2386 Builder.Metadata.none, // File2387 .none, // File
2387 o.debug_compile_unit, // Sope2388 o.debug_compile_unit, // Sope
2388 0, // Line2389 0, // Line
2389 Builder.Metadata.none, // Underlying type2390 .none, // Underlying type
2390 ty.abiSize(mod) * 8,2391 ty.abiSize(mod) * 8,
2391 ty.abiAlignment(mod).toByteUnits(0) * 8,2392 ty.abiAlignment(mod).toByteUnits(0) * 8,
2392 try o.builder.debugTuple(&fields),2393 try o.builder.debugTuple(&fields),
...@@ -2451,7 +2452,7 @@ pub const Object = struct {...@@ -2451,7 +2452,7 @@ pub const Object = struct {
24512452
2452 fields.appendAssumeCapacity(try o.builder.debugMemberType(2453 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2453 try o.builder.metadataString(field_name),2454 try o.builder.metadataString(field_name),
2454 Builder.Metadata.none, // File2455 .none, // File
2455 debug_fwd_ref,2456 debug_fwd_ref,
2456 0,2457 0,
2457 try o.lowerDebugType(Type.fromInterned(field_ty)),2458 try o.lowerDebugType(Type.fromInterned(field_ty)),
...@@ -2463,10 +2464,10 @@ pub const Object = struct {...@@ -2463,10 +2464,10 @@ pub const Object = struct {
24632464
2464 const debug_struct_type = try o.builder.debugStructType(2465 const debug_struct_type = try o.builder.debugStructType(
2465 try o.builder.metadataString(name),2466 try o.builder.metadataString(name),
2466 Builder.Metadata.none, // File2467 .none, // File
2467 o.debug_compile_unit, // Scope2468 o.debug_compile_unit, // Scope
2468 0, // Line2469 0, // Line
2469 Builder.Metadata.none, // Underlying type2470 .none, // Underlying type
2470 ty.abiSize(mod) * 8,2471 ty.abiSize(mod) * 8,
2471 ty.abiAlignment(mod).toByteUnits(0) * 8,2472 ty.abiAlignment(mod).toByteUnits(0) * 8,
2472 try o.builder.debugTuple(fields.items),2473 try o.builder.debugTuple(fields.items),
...@@ -2532,7 +2533,7 @@ pub const Object = struct {...@@ -2532,7 +2533,7 @@ pub const Object = struct {
25322533
2533 fields.appendAssumeCapacity(try o.builder.debugMemberType(2534 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2534 try o.builder.metadataString(ip.stringToSlice(field_name)),2535 try o.builder.metadataString(ip.stringToSlice(field_name)),
2535 Builder.Metadata.none, // File2536 .none, // File
2536 debug_fwd_ref,2537 debug_fwd_ref,
2537 0, // Line2538 0, // Line
2538 try o.lowerDebugType(field_ty),2539 try o.lowerDebugType(field_ty),
...@@ -2544,10 +2545,10 @@ pub const Object = struct {...@@ -2544,10 +2545,10 @@ pub const Object = struct {
25442545
2545 const debug_struct_type = try o.builder.debugStructType(2546 const debug_struct_type = try o.builder.debugStructType(
2546 try o.builder.metadataString(name),2547 try o.builder.metadataString(name),
2547 Builder.Metadata.none, // File2548 .none, // File
2548 o.debug_compile_unit, // Scope2549 o.debug_compile_unit, // Scope
2549 0, // Line2550 0, // Line
2550 Builder.Metadata.none, // Underlying type2551 .none, // Underlying type
2551 ty.abiSize(mod) * 8,2552 ty.abiSize(mod) * 8,
2552 ty.abiAlignment(mod).toByteUnits(0) * 8,2553 ty.abiAlignment(mod).toByteUnits(0) * 8,
2553 try o.builder.debugTuple(fields.items),2554 try o.builder.debugTuple(fields.items),
...@@ -2585,10 +2586,10 @@ pub const Object = struct {...@@ -2585,10 +2586,10 @@ pub const Object = struct {
2585 if (layout.payload_size == 0) {2586 if (layout.payload_size == 0) {
2586 const debug_union_type = try o.builder.debugStructType(2587 const debug_union_type = try o.builder.debugStructType(
2587 try o.builder.metadataString(name),2588 try o.builder.metadataString(name),
2588 Builder.Metadata.none, // File2589 .none, // File
2589 o.debug_compile_unit, // Scope2590 o.debug_compile_unit, // Scope
2590 0, // Line2591 0, // Line
2591 Builder.Metadata.none, // Underlying type2592 .none, // Underlying type
2592 ty.abiSize(mod) * 8,2593 ty.abiSize(mod) * 8,
2593 ty.abiAlignment(mod).toByteUnits(0) * 8,2594 ty.abiAlignment(mod).toByteUnits(0) * 8,
2594 try o.builder.debugTuple(2595 try o.builder.debugTuple(
...@@ -2623,7 +2624,7 @@ pub const Object = struct {...@@ -2623,7 +2624,7 @@ pub const Object = struct {
2623 const field_name = union_obj.field_names.get(ip)[field_index];2624 const field_name = union_obj.field_names.get(ip)[field_index];
2624 fields.appendAssumeCapacity(try o.builder.debugMemberType(2625 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2625 try o.builder.metadataString(ip.stringToSlice(field_name)),2626 try o.builder.metadataString(ip.stringToSlice(field_name)),
2626 Builder.Metadata.none, // File2627 .none, // File
2627 debug_union_fwd_ref,2628 debug_union_fwd_ref,
2628 0, // Line2629 0, // Line
2629 try o.lowerDebugType(Type.fromInterned(field_ty)),2630 try o.lowerDebugType(Type.fromInterned(field_ty)),
...@@ -2642,10 +2643,10 @@ pub const Object = struct {...@@ -2642,10 +2643,10 @@ pub const Object = struct {
26422643
2643 const debug_union_type = try o.builder.debugUnionType(2644 const debug_union_type = try o.builder.debugUnionType(
2644 try o.builder.metadataString(union_name),2645 try o.builder.metadataString(union_name),
2645 Builder.Metadata.none, // File2646 .none, // File
2646 o.debug_compile_unit, // Scope2647 o.debug_compile_unit, // Scope
2647 0, // Line2648 0, // Line
2648 Builder.Metadata.none, // Underlying type2649 .none, // Underlying type
2649 ty.abiSize(mod) * 8,2650 ty.abiSize(mod) * 8,
2650 ty.abiAlignment(mod).toByteUnits(0) * 8,2651 ty.abiAlignment(mod).toByteUnits(0) * 8,
2651 try o.builder.debugTuple(fields.items),2652 try o.builder.debugTuple(fields.items),
...@@ -2673,7 +2674,7 @@ pub const Object = struct {...@@ -2673,7 +2674,7 @@ pub const Object = struct {
26732674
2674 const debug_tag_type = try o.builder.debugMemberType(2675 const debug_tag_type = try o.builder.debugMemberType(
2675 try o.builder.metadataString("tag"),2676 try o.builder.metadataString("tag"),
2676 Builder.Metadata.none, // File2677 .none, // File
2677 debug_fwd_ref,2678 debug_fwd_ref,
2678 0, // Line2679 0, // Line
2679 try o.lowerDebugType(Type.fromInterned(union_obj.enum_tag_ty)),2680 try o.lowerDebugType(Type.fromInterned(union_obj.enum_tag_ty)),
...@@ -2684,7 +2685,7 @@ pub const Object = struct {...@@ -2684,7 +2685,7 @@ pub const Object = struct {
26842685
2685 const debug_payload_type = try o.builder.debugMemberType(2686 const debug_payload_type = try o.builder.debugMemberType(
2686 try o.builder.metadataString("payload"),2687 try o.builder.metadataString("payload"),
2687 Builder.Metadata.none, // File2688 .none, // File
2688 debug_fwd_ref,2689 debug_fwd_ref,
2689 0, // Line2690 0, // Line
2690 debug_union_type,2691 debug_union_type,
...@@ -2701,10 +2702,10 @@ pub const Object = struct {...@@ -2701,10 +2702,10 @@ pub const Object = struct {
27012702
2702 const debug_tagged_union_type = try o.builder.debugStructType(2703 const debug_tagged_union_type = try o.builder.debugStructType(
2703 try o.builder.metadataString(name),2704 try o.builder.metadataString(name),
2704 Builder.Metadata.none, // File2705 .none, // File
2705 o.debug_compile_unit, // Scope2706 o.debug_compile_unit, // Scope
2706 0, // Line2707 0, // Line
2707 Builder.Metadata.none, // Underlying type2708 .none, // Underlying type
2708 ty.abiSize(mod) * 8,2709 ty.abiSize(mod) * 8,
2709 ty.abiAlignment(mod).toByteUnits(0) * 8,2710 ty.abiAlignment(mod).toByteUnits(0) * 8,
2710 try o.builder.debugTuple(&full_fields),2711 try o.builder.debugTuple(&full_fields),
...@@ -2798,7 +2799,7 @@ pub const Object = struct {...@@ -2798,7 +2799,7 @@ pub const Object = struct {
2798 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),2799 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),
2799 try o.namespaceToDebugScope(decl.src_namespace),2800 try o.namespaceToDebugScope(decl.src_namespace),
2800 decl.src_line + 1,2801 decl.src_line + 1,
2801 Builder.Metadata.none,2802 .none,
2802 0,2803 0,
2803 0,2804 0,
2804 .none,2805 .none,
...@@ -4715,7 +4716,8 @@ pub const DeclGen = struct {...@@ -4715,7 +4716,8 @@ pub const DeclGen = struct {
4715 debug_global_var,4716 debug_global_var,
4716 debug_expression,4717 debug_expression,
4717 );4718 );
47184719 if (!is_internal_linkage or decl.isExtern(mod))
4720 variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder);
4719 try o.debug_globals.append(o.gpa, debug_global_var_expression);4721 try o.debug_globals.append(o.gpa, debug_global_var_expression);
4720 }4722 }
4721 }4723 }
...@@ -4729,8 +4731,7 @@ pub const FuncGen = struct {...@@ -4729,8 +4731,7 @@ pub const FuncGen = struct {
4729 wip: Builder.WipFunction,4731 wip: Builder.WipFunction,
47304732
4731 file: Builder.Metadata,4733 file: Builder.Metadata,
4732 subprogram: Builder.Metadata,4734 scope: Builder.Metadata,
4733 current_scope: Builder.Metadata,
47344735
4735 inlined: std.ArrayListUnmanaged(struct {4736 inlined: std.ArrayListUnmanaged(struct {
4736 base_line: u32,4737 base_line: u32,
...@@ -6557,20 +6558,20 @@ pub const FuncGen = struct {...@@ -6557,20 +6558,20 @@ pub const FuncGen = struct {
6557 const inlined_at = if (self.inlined.items.len > 0)6558 const inlined_at = if (self.inlined.items.len > 0)
6558 self.inlined.items[self.inlined.items.len - 1].location6559 self.inlined.items[self.inlined.items.len - 1].location
6559 else6560 else
6560 Builder.Metadata.none;6561 .none;
65616562
6562 self.wip.current_debug_location = .{6563 self.wip.current_debug_location = try self.wip.builder.debugLocation(
6563 .line = self.prev_dbg_line,6564 self.prev_dbg_line,
6564 .column = self.prev_dbg_column,6565 self.prev_dbg_column,
6565 .scope = self.current_scope,6566 self.scope,
6566 .inlined_at = inlined_at,6567 inlined_at,
6567 };6568 );
65686569
6569 return .none;6570 return .none;
6570 }6571 }
65716572
6572 fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6573 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;
6574 const o = self.dg.object;6575 const o = self.dg.object;
6575 const zcu = o.module;6576 const zcu = o.module;
65766577
...@@ -6585,13 +6586,8 @@ pub const FuncGen = struct {...@@ -6585,13 +6586,8 @@ pub const FuncGen = struct {
65856586
6586 const line_number = decl.src_line + 1;6587 const line_number = decl.src_line + 1;
6587 try self.inlined.append(self.gpa, .{6588 try self.inlined.append(self.gpa, .{
6588 .location = if (self.wip.current_debug_location) |location| try self.wip.builder.debugLocation(6589 .location = self.wip.current_debug_location,
6589 location.scope,6590 .scope = self.scope,
6590 location.line,
6591 location.column,
6592 location.inlined_at,
6593 ) else .none,
6594 .scope = self.current_scope,
6595 .base_line = self.base_line,6591 .base_line = self.base_line,
6596 });6592 });
65976593
...@@ -6605,16 +6601,18 @@ pub const FuncGen = struct {...@@ -6605,16 +6601,18 @@ pub const FuncGen = struct {
66056601
6606 const subprogram = try o.builder.debugSubprogram(6602 const subprogram = try o.builder.debugSubprogram(
6607 self.file,6603 self.file,
6608 try o.builder.string(zcu.intern_pool.stringToSlice(decl.name)),6604 try o.builder.metadataString(zcu.intern_pool.stringToSlice(decl.name)),
6609 try o.builder.string(zcu.intern_pool.stringToSlice(fqn)),6605 try o.builder.metadataString(zcu.intern_pool.stringToSlice(fqn)),
6610 line_number,6606 line_number,
6611 line_number + func.lbrace_line,6607 line_number + func.lbrace_line,
6612 try o.lowerDebugType(fn_ty),6608 try o.lowerDebugType(fn_ty),
6613 .{6609 .{
6614 .optimized = owner_mod.optimize_mode != .Debug,6610 .di_flags = .{ .StaticMember = true },
6615 .local = is_internal_linkage,6611 .sp_flags = .{
6616 .definition = true,6612 .Optimized = owner_mod.optimize_mode != .Debug,
6617 .debug_info_flags = Builder.DIFlags.StaticMember,6613 .Definition = true,
6614 .LocalToUnit = is_internal_linkage,
6615 },
6618 },6616 },
6619 o.debug_compile_unit,6617 o.debug_compile_unit,
6620 );6618 );
...@@ -6625,13 +6623,13 @@ pub const FuncGen = struct {...@@ -6625,13 +6623,13 @@ pub const FuncGen = struct {
6625 line_number,6623 line_number,
6626 1,6624 1,
6627 );6625 );
6628 self.current_scope = lexical_block;6626 self.scope = lexical_block;
6629 self.base_line = decl.src_line;6627 self.base_line = decl.src_line;
6630 return .none;6628 return .none;
6631 }6629 }
66326630
6633 fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {6631 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;
6635 const o = self.dg.object;6633 const o = self.dg.object;
66366634
6637 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;6635 const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn;
...@@ -6641,7 +6639,7 @@ pub const FuncGen = struct {...@@ -6641,7 +6639,7 @@ pub const FuncGen = struct {
6641 self.file = try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope);6639 self.file = try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope);
66426640
6643 const old = self.inlined.pop();6641 const old = self.inlined.pop();
6644 self.current_scope = old.scope;6642 self.scope = old.scope;
6645 self.base_line = old.base_line;6643 self.base_line = old.base_line;
6646 return .none;6644 return .none;
6647 }6645 }
...@@ -6650,12 +6648,12 @@ pub const FuncGen = struct {...@@ -6650,12 +6648,12 @@ pub const FuncGen = struct {
6650 if (self.wip.builder.strip) return .none;6648 if (self.wip.builder.strip) return .none;
6651 const o = self.dg.object;6649 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;6653 const old = self.scope;
6656 self.current_scope = try o.builder.debugLexicalBlock(6654 self.scope = try o.builder.debugLexicalBlock(
6657 self.file,
6658 old,6655 old,
6656 self.file,
6659 self.prev_dbg_line,6657 self.prev_dbg_line,
6660 self.prev_dbg_column,6658 self.prev_dbg_column,
6661 );6659 );
...@@ -6664,7 +6662,7 @@ pub const FuncGen = struct {...@@ -6664,7 +6662,7 @@ pub const FuncGen = struct {
66646662
6665 fn airDbgBlockEnd(self: *FuncGen) !Builder.Value {6663 fn airDbgBlockEnd(self: *FuncGen) !Builder.Value {
6666 if (self.wip.builder.strip) return .none;6664 if (self.wip.builder.strip) return .none;
6667 self.current_scope = self.scope_stack.pop();6665 self.scope = self.scope_stack.pop();
6668 return .none;6666 return .none;
6669 }6667 }
66706668
...@@ -6680,7 +6678,7 @@ pub const FuncGen = struct {...@@ -6680,7 +6678,7 @@ pub const FuncGen = struct {
6680 const debug_local_var = try o.builder.debugLocalVar(6678 const debug_local_var = try o.builder.debugLocalVar(
6681 try o.builder.metadataString(name),6679 try o.builder.metadataString(name),
6682 self.file,6680 self.file,
6683 self.current_scope,6681 self.scope,
6684 self.prev_dbg_line,6682 self.prev_dbg_line,
6685 try o.lowerDebugType(ptr_ty.childType(mod)),6683 try o.lowerDebugType(ptr_ty.childType(mod)),
6686 );6684 );
...@@ -6714,7 +6712,7 @@ pub const FuncGen = struct {...@@ -6714,7 +6712,7 @@ pub const FuncGen = struct {
6714 const debug_local_var = try o.builder.debugLocalVar(6712 const debug_local_var = try o.builder.debugLocalVar(
6715 try o.builder.metadataString(name),6713 try o.builder.metadataString(name),
6716 self.file,6714 self.file,
6717 self.current_scope,6715 self.scope,
6718 self.prev_dbg_line,6716 self.prev_dbg_line,
6719 try o.lowerDebugType(operand_ty),6717 try o.lowerDebugType(operand_ty),
6720 );6718 );
...@@ -8798,19 +8796,19 @@ pub const FuncGen = struct {...@@ -8798,19 +8796,19 @@ pub const FuncGen = struct {
8798 const debug_parameter = try o.builder.debugParameter(8796 const debug_parameter = try o.builder.debugParameter(
8799 try o.builder.metadataString(mod.getParamName(func_index, src_index)),8797 try o.builder.metadataString(mod.getParamName(func_index, src_index)),
8800 self.file,8798 self.file,
8801 self.current_scope,8799 self.scope,
8802 lbrace_line,8800 lbrace_line,
8803 try o.lowerDebugType(inst_ty),8801 try o.lowerDebugType(inst_ty),
8804 @intCast(self.arg_index),8802 @intCast(self.arg_index),
8805 );8803 );
88068804
8807 const old_location = self.wip.current_debug_location;8805 const old_location = self.wip.current_debug_location;
8808 self.wip.current_debug_location = .{8806 self.wip.current_debug_location = try o.builder.debugLocation(
8809 .line = lbrace_line,8807 lbrace_line,
8810 .column = lbrace_col,8808 lbrace_col,
8811 .scope = self.current_scope,8809 self.scope,
8812 .inlined_at = Builder.Metadata.none,8810 .none,
8813 };8811 );
88148812
8815 const owner_mod = self.dg.ownerModule();8813 const owner_mod = self.dg.ownerModule();
8816 if (isByRef(inst_ty, mod)) {8814 if (isByRef(inst_ty, mod)) {
...@@ -11718,7 +11716,7 @@ fn buildAllocaInner(...@@ -11718,7 +11716,7 @@ fn buildAllocaInner(
11718 }11716 }
1171911717
11720 wip.cursor = .{ .block = .entry };11718 wip.cursor = .{ .block = .entry };
11721 wip.current_debug_location = null;11719 wip.current_debug_location = .none;
11722 break :blk try wip.alloca(.normal, llvm_ty, .none, alignment, address_space, "");11720 break :blk try wip.alloca(.normal, llvm_ty, .none, alignment, address_space, "");
11723 };11721 };
1172411722
src/codegen/llvm/Builder.zig+1145-431
...@@ -77,11 +77,11 @@ pub const String = enum(u32) {...@@ -77,11 +77,11 @@ pub const String = enum(u32) {
77 return self.toIndex() == null;77 return self.toIndex() == null;
78 }78 }
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 {
81 const index = self.toIndex() orelse return null;81 const index = self.toIndex() orelse return null;
82 const start = b.string_indices.items[index];82 const start = builder.string_indices.items[index];
83 const end = b.string_indices.items[index + 1];83 const end = builder.string_indices.items[index + 1];
84 return b.string_bytes.items[start .. end - 1 :0];84 return builder.string_bytes.items[start .. end - 1 :0];
85 }85 }
8686
87 const FormatData = struct {87 const FormatData = struct {
...@@ -1124,7 +1124,8 @@ pub const Attribute = union(Kind) {...@@ -1124,7 +1124,8 @@ pub const Attribute = union(Kind) {
1124 u32 => storage.value,1124 u32 => storage.value,
1125 Alignment, String, Type, UwTable => @enumFromInt(storage.value),1125 Alignment, String, Type, UwTable => @enumFromInt(storage.value),
1126 AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(storage.value),1126 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)),
1128 });1129 });
1129 },1130 },
1130 .string, .none => unreachable,1131 .string, .none => unreachable,
...@@ -1550,12 +1551,12 @@ pub const Attribute = union(Kind) {...@@ -1550,12 +1551,12 @@ pub const Attribute = union(Kind) {
15501551
1551 fn toStorage(self: Attribute) Storage {1552 fn toStorage(self: Attribute) Storage {
1552 return switch (self) {1553 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)) {
1554 void => 0,1555 void => 0,
1555 u32 => value,1556 u32 => value,
1556 Alignment, String, Type, UwTable => @intFromEnum(value),1557 Alignment, String, Type, UwTable => @intFromEnum(value),
1557 AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(value),1558 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))),
1559 } },1560 } },
1560 .string => |string_attr| .{1561 .string => |string_attr| .{
1561 .kind = Kind.fromString(string_attr.kind),1562 .kind = Kind.fromString(string_attr.kind),
...@@ -2130,6 +2131,7 @@ pub const Global = struct {...@@ -2130,6 +2131,7 @@ pub const Global = struct {
2130 externally_initialized: ExternallyInitialized = .default,2131 externally_initialized: ExternallyInitialized = .default,
2131 type: Type,2132 type: Type,
2132 partition: String = .none,2133 partition: String = .none,
2134 dbg: Metadata = .none,
2133 kind: union(enum) {2135 kind: union(enum) {
2134 alias: Alias.Index,2136 alias: Alias.Index,
2135 variable: Variable.Index,2137 variable: Variable.Index,
...@@ -2204,6 +2206,10 @@ pub const Global = struct {...@@ -2204,6 +2206,10 @@ pub const Global = struct {
2204 self.ptr(builder).unnamed_addr = unnamed_addr;2206 self.ptr(builder).unnamed_addr = unnamed_addr;
2205 }2207 }
22062208
2209 pub fn setDebugMetadata(self: Index, dbg: Metadata, builder: *Builder) void {
2210 self.ptr(builder).dbg = dbg;
2211 }
2212
2207 const FormatData = struct {2213 const FormatData = struct {
2208 global: Index,2214 global: Index,
2209 builder: *const Builder,2215 builder: *const Builder,
...@@ -2425,6 +2431,10 @@ pub const Variable = struct {...@@ -2425,6 +2431,10 @@ pub const Variable = struct {
2425 pub fn getAlignment(self: Index, builder: *Builder) Alignment {2431 pub fn getAlignment(self: Index, builder: *Builder) Alignment {
2426 return self.ptr(builder).alignment;2432 return self.ptr(builder).alignment;
2427 }2433 }
2434
2435 pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void {
2436 self.ptrConst(builder).global.setDebugMetadata(expression, builder);
2437 }
2428 };2438 };
2429};2439};
24302440
...@@ -3772,8 +3782,7 @@ pub const Function = struct {...@@ -3772,8 +3782,7 @@ pub const Function = struct {
3772 instructions: std.MultiArrayList(Instruction) = .{},3782 instructions: std.MultiArrayList(Instruction) = .{},
3773 names: [*]const String = &[0]String{},3783 names: [*]const String = &[0]String{},
3774 value_indices: [*]const u32 = &[0]u32{},3784 value_indices: [*]const u32 = &[0]u32{},
3775 metadata: ?[*]const Metadata = null,3785 debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{},
3776 debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, ?DebugLocation) = .{},
3777 debug_values: []const Instruction.Index = &.{},3786 debug_values: []const Instruction.Index = &.{},
3778 extra: []const u32 = &.{},3787 extra: []const u32 = &.{},
37793788
...@@ -3836,6 +3845,10 @@ pub const Function = struct {...@@ -3836,6 +3845,10 @@ pub const Function = struct {
3836 pub fn setAlignment(self: Index, alignment: Alignment, builder: *Builder) void {3845 pub fn setAlignment(self: Index, alignment: Alignment, builder: *Builder) void {
3837 self.ptr(builder).alignment = alignment;3846 self.ptr(builder).alignment = alignment;
3838 }3847 }
3848
3849 pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void {
3850 self.ptrConst(builder).global.setDebugMetadata(subprogram, builder);
3851 }
3839 };3852 };
38403853
3841 pub const Block = struct {3854 pub const Block = struct {
...@@ -4823,7 +4836,7 @@ pub const Function = struct {...@@ -4823,7 +4836,7 @@ pub const Function = struct {
4823 Instruction.Alloca.Info,4836 Instruction.Alloca.Info,
4824 Instruction.Call.Info,4837 Instruction.Call.Info,
4825 => @bitCast(value),4838 => @bitCast(value),
4826 else => @compileError("bad field type: " ++ @typeName(field.type)),4839 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
4827 };4840 };
4828 return .{4841 return .{
4829 .data = result,4842 .data = result,
...@@ -4836,61 +4849,16 @@ pub const Function = struct {...@@ -4836,61 +4849,16 @@ pub const Function = struct {
4836 }4849 }
4837};4850};
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
4884pub const WipFunction = struct {4852pub const WipFunction = struct {
4885 builder: *Builder,4853 builder: *Builder,
4886 function: Function.Index,4854 function: Function.Index,
4887 last_debug_location: ?DebugLocation,4855 last_debug_location: Metadata,
4888 current_debug_location: ?DebugLocation,4856 current_debug_location: Metadata,
4889 cursor: Cursor,4857 cursor: Cursor,
4890 blocks: std.ArrayListUnmanaged(Block),4858 blocks: std.ArrayListUnmanaged(Block),
4891 instructions: std.MultiArrayList(Instruction),4859 instructions: std.MultiArrayList(Instruction),
4892 names: std.ArrayListUnmanaged(String),4860 names: std.ArrayListUnmanaged(String),
4893 debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, ?DebugLocation),4861 debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, Metadata),
4894 debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void),4862 debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void),
4895 extra: std.ArrayListUnmanaged(u32),4863 extra: std.ArrayListUnmanaged(u32),
48964864
...@@ -4923,9 +4891,11 @@ pub const WipFunction = struct {...@@ -4923,9 +4891,11 @@ pub const WipFunction = struct {
4923 pub const Instruction = Function.Instruction;4891 pub const Instruction = Function.Instruction;
49244892
4925 pub fn init(builder: *Builder, function: Function.Index) Allocator.Error!WipFunction {4893 pub fn init(builder: *Builder, function: Function.Index) Allocator.Error!WipFunction {
4926 var self = WipFunction{4894 var self: WipFunction = .{
4927 .builder = builder,4895 .builder = builder,
4928 .function = function,4896 .function = function,
4897 .last_debug_location = .none,
4898 .current_debug_location = .none,
4929 .cursor = undefined,4899 .cursor = undefined,
4930 .blocks = .{},4900 .blocks = .{},
4931 .instructions = .{},4901 .instructions = .{},
...@@ -4933,8 +4903,6 @@ pub const WipFunction = struct {...@@ -4933,8 +4903,6 @@ pub const WipFunction = struct {
4933 .debug_locations = .{},4903 .debug_locations = .{},
4934 .debug_values = .{},4904 .debug_values = .{},
4935 .extra = .{},4905 .extra = .{},
4936 .current_debug_location = null,
4937 .last_debug_location = null,
4938 };4906 };
4939 errdefer self.deinit();4907 errdefer self.deinit();
49404908
...@@ -5874,7 +5842,7 @@ pub const WipFunction = struct {...@@ -5874,7 +5842,7 @@ pub const WipFunction = struct {
5874 const value_indices = try gpa.alloc(u32, final_instructions_len);5842 const value_indices = try gpa.alloc(u32, final_instructions_len);
5875 errdefer gpa.free(value_indices);5843 errdefer gpa.free(value_indices);
58765844
5877 var debug_locations = std.AutoHashMapUnmanaged(Instruction.Index, ?DebugLocation){};5845 var debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{};
5878 errdefer debug_locations.deinit(gpa);5846 errdefer debug_locations.deinit(gpa);
5879 try debug_locations.ensureUnusedCapacity(gpa, @intCast(self.debug_locations.count()));5847 try debug_locations.ensureUnusedCapacity(gpa, @intCast(self.debug_locations.count()));
58805848
...@@ -5902,7 +5870,7 @@ pub const WipFunction = struct {...@@ -5902,7 +5870,7 @@ pub const WipFunction = struct {
5902 Instruction.Alloca.Info,5870 Instruction.Alloca.Info,
5903 Instruction.Call.Info,5871 Instruction.Call.Info,
5904 => @bitCast(value),5872 => @bitCast(value),
5905 else => @compileError("bad field type: " ++ @typeName(field.type)),5873 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
5906 };5874 };
5907 wip_extra.index += 1;5875 wip_extra.index += 1;
5908 }5876 }
...@@ -6472,13 +6440,7 @@ pub const WipFunction = struct {...@@ -6472,13 +6440,7 @@ pub const WipFunction = struct {
6472 try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1);6440 try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1);
6473 if (!self.builder.strip) {6441 if (!self.builder.strip) {
6474 try self.names.ensureUnusedCapacity(self.builder.gpa, 1);6442 try self.names.ensureUnusedCapacity(self.builder.gpa, 1);
6475 if (!std.mem.eql(6443 try self.debug_locations.ensureUnusedCapacity(self.builder.gpa, 1);
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 }
6482 }6444 }
6483 try block_instructions.ensureUnusedCapacity(self.builder.gpa, 1);6445 try block_instructions.ensureUnusedCapacity(self.builder.gpa, 1);
6484 const final_name = if (name) |n|6446 const final_name = if (name) |n|
...@@ -6490,11 +6452,7 @@ pub const WipFunction = struct {...@@ -6490,11 +6452,7 @@ pub const WipFunction = struct {
6490 self.instructions.appendAssumeCapacity(instruction);6452 self.instructions.appendAssumeCapacity(instruction);
6491 if (!self.builder.strip) {6453 if (!self.builder.strip) {
6492 self.names.appendAssumeCapacity(final_name);6454 self.names.appendAssumeCapacity(final_name);
6493 if (!std.mem.eql(6455 if (!std.meta.eql(self.current_debug_location, self.last_debug_location)) {
6494 u8,
6495 std.mem.asBytes(&self.current_debug_location),
6496 std.mem.asBytes(&self.last_debug_location),
6497 )) {
6498 self.debug_locations.putAssumeCapacity(index, self.current_debug_location);6456 self.debug_locations.putAssumeCapacity(index, self.current_debug_location);
6499 self.last_debug_location = self.current_debug_location;6457 self.last_debug_location = self.current_debug_location;
6500 }6458 }
...@@ -6521,7 +6479,7 @@ pub const WipFunction = struct {...@@ -6521,7 +6479,7 @@ pub const WipFunction = struct {
6521 Instruction.Alloca.Info,6479 Instruction.Alloca.Info,
6522 Instruction.Call.Info,6480 Instruction.Call.Info,
6523 => @bitCast(value),6481 => @bitCast(value),
6524 else => @compileError("bad field type: " ++ @typeName(field.type)),6482 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
6525 });6483 });
6526 }6484 }
6527 return result;6485 return result;
...@@ -6569,7 +6527,7 @@ pub const WipFunction = struct {...@@ -6569,7 +6527,7 @@ pub const WipFunction = struct {
6569 Instruction.Alloca.Info,6527 Instruction.Alloca.Info,
6570 Instruction.Call.Info,6528 Instruction.Call.Info,
6571 => @bitCast(value),6529 => @bitCast(value),
6572 else => @compileError("bad field type: " ++ @typeName(field.type)),6530 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
6573 };6531 };
6574 return .{6532 return .{
6575 .data = result,6533 .data = result,
...@@ -7194,7 +7152,7 @@ pub const Constant = enum(u32) {...@@ -7194,7 +7152,7 @@ pub const Constant = enum(u32) {
7194 @ptrCast(data.builder.constant_limbs.items[item.data..][0..Integer.limbs]);7152 @ptrCast(data.builder.constant_limbs.items[item.data..][0..Integer.limbs]);
7195 const limbs = data.builder.constant_limbs7153 const limbs = data.builder.constant_limbs
7196 .items[item.data + Integer.limbs ..][0..extra.limbs_len];7154 .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 = .{
7198 .limbs = limbs,7156 .limbs = limbs,
7199 .positive = tag == .positive_integer,7157 .positive = tag == .positive_integer,
7200 };7158 };
...@@ -7507,7 +7465,7 @@ pub const Value = enum(u32) {...@@ -7507,7 +7465,7 @@ pub const Value = enum(u32) {
7507 return switch (self.unwrap()) {7465 return switch (self.unwrap()) {
7508 .instruction => |instruction| instruction.typeOfWip(wip),7466 .instruction => |instruction| instruction.typeOfWip(wip),
7509 .constant => |constant| constant.typeOf(wip.builder),7467 .constant => |constant| constant.typeOf(wip.builder),
7510 .metadata => Type.metadata,7468 .metadata => .metadata,
7511 };7469 };
7512 }7470 }
75137471
...@@ -7515,7 +7473,7 @@ pub const Value = enum(u32) {...@@ -7515,7 +7473,7 @@ pub const Value = enum(u32) {
7515 return switch (self.unwrap()) {7473 return switch (self.unwrap()) {
7516 .instruction => |instruction| instruction.typeOf(function, builder),7474 .instruction => |instruction| instruction.typeOf(function, builder),
7517 .constant => |constant| constant.typeOf(builder),7475 .constant => |constant| constant.typeOf(builder),
7518 .metadata => Type.metadata,7476 .metadata => .metadata,
7519 };7477 };
7520 }7478 }
75217479
...@@ -7559,11 +7517,11 @@ pub const MetadataString = enum(u32) {...@@ -7559,11 +7517,11 @@ pub const MetadataString = enum(u32) {
7559 none = 0,7517 none = 0,
7560 _,7518 _,
75617519
7562 pub fn slice(self: MetadataString, b: *const Builder) []const u8 {7520 pub fn slice(self: MetadataString, builder: *const Builder) []const u8 {
7563 const index = @intFromEnum(self);7521 const index = @intFromEnum(self);
7564 const start = b.metadata_string_indices.items[index];7522 const start = builder.metadata_string_indices.items[index];
7565 const end = b.metadata_string_indices.items[index + 1];7523 const end = builder.metadata_string_indices.items[index + 1];
7566 return b.metadata_string_bytes.items[start..end];7524 return builder.metadata_string_bytes.items[start..end];
7567 }7525 }
75687526
7569 const Adapter = struct {7527 const Adapter = struct {
...@@ -7576,6 +7534,22 @@ pub const MetadataString = enum(u32) {...@@ -7576,6 +7534,22 @@ pub const MetadataString = enum(u32) {
7576 return std.mem.eql(u8, lhs_key, rhs_metadata_string.slice(ctx.builder));7534 return std.mem.eql(u8, lhs_key, rhs_metadata_string.slice(ctx.builder));
7577 }7535 }
7578 };7536 };
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 }
7579};7553};
75807554
7581pub const Metadata = enum(u32) {7555pub const Metadata = enum(u32) {
...@@ -7591,13 +7565,13 @@ pub const Metadata = enum(u32) {...@@ -7591,13 +7565,13 @@ pub const Metadata = enum(u32) {
7591 compile_unit,7565 compile_unit,
7592 @"compile_unit optimized",7566 @"compile_unit optimized",
7593 subprogram,7567 subprogram,
7594 @"subprogram optimized",
7595 @"subprogram local",7568 @"subprogram local",
7596 @"subprogram definition",7569 @"subprogram definition",
7570 @"subprogram local definition",
7571 @"subprogram optimized",
7597 @"subprogram optimized local",7572 @"subprogram optimized local",
7598 @"subprogram optimized definition",7573 @"subprogram optimized definition",
7599 @"subprogram optimized local definition",7574 @"subprogram optimized local definition",
7600 @"subprogram local definition",
7601 lexical_block,7575 lexical_block,
7602 location,7576 location,
7603 basic_bool_type,7577 basic_bool_type,
...@@ -7625,18 +7599,66 @@ pub const Metadata = enum(u32) {...@@ -7625,18 +7599,66 @@ pub const Metadata = enum(u32) {
7625 @"global_var local",7599 @"global_var local",
7626 global_var_expression,7600 global_var_expression,
7627 constant,7601 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 }
7628 };7648 };
76297649
7650 pub fn isInline(self: Metadata, builder: *const Builder) bool {
7651 return builder.metadata_items.items(.tag)[@intFromEnum(self)].isInline();
7652 }
7653
7630 pub fn unwrap(self: Metadata, builder: *const Builder) Metadata {7654 pub fn unwrap(self: Metadata, builder: *const Builder) Metadata {
7631 var metadata = self;7655 var metadata = self;
7632 var count: usize = 0;
7633 while (@intFromEnum(metadata) >= Metadata.first_forward_reference and7656 while (@intFromEnum(metadata) >= Metadata.first_forward_reference and
7634 @intFromEnum(metadata) < Metadata.first_local_metadata)7657 @intFromEnum(metadata) < Metadata.first_local_metadata)
7635 {7658 {
7636 const index = @intFromEnum(metadata) - Metadata.first_forward_reference;7659 const index = @intFromEnum(metadata) - Metadata.first_forward_reference;
7637 metadata = builder.metadata_forward_references.items[index];7660 metadata = builder.metadata_forward_references.items[index];
7638 std.debug.assert(metadata != .none);7661 std.debug.assert(metadata != .none);
7639 count += 1;
7640 }7662 }
7641 return metadata;7663 return metadata;
7642 }7664 }
...@@ -7648,13 +7670,75 @@ pub const Metadata = enum(u32) {...@@ -7648,13 +7670,75 @@ pub const Metadata = enum(u32) {
7648 const ExtraIndex = u32;7670 const ExtraIndex = u32;
7649 };7671 };
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
7651 pub const File = struct {7735 pub const File = struct {
7652 path: MetadataString,7736 filename: MetadataString,
7653 name: MetadataString,7737 directory: MetadataString,
7654 };7738 };
76557739
7656 pub const CompileUnit = struct {7740 pub const CompileUnit = struct {
7657 pub const Flags = struct {7741 pub const Options = struct {
7658 optimized: bool,7742 optimized: bool,
7659 };7743 };
76607744
...@@ -7665,11 +7749,49 @@ pub const Metadata = enum(u32) {...@@ -7665,11 +7749,49 @@ pub const Metadata = enum(u32) {
7665 };7749 };
76667750
7667 pub const Subprogram = struct {7751 pub const Subprogram = struct {
7668 pub const Flags = struct {7752 pub const Options = struct {
7669 optimized: bool,7753 di_flags: DIFlags,
7670 local: bool,7754 sp_flags: SPFlags,
7671 definition: bool,7755 };
7672 debug_info_flags: u32,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 }
7673 };7795 };
76747796
7675 file: Metadata,7797 file: Metadata,
...@@ -7678,21 +7800,21 @@ pub const Metadata = enum(u32) {...@@ -7678,21 +7800,21 @@ pub const Metadata = enum(u32) {
7678 line: u32,7800 line: u32,
7679 scope_line: u32,7801 scope_line: u32,
7680 ty: Metadata,7802 ty: Metadata,
7681 debug_info_flags: u32,7803 di_flags: DIFlags,
7682 compile_unit: Metadata,7804 compile_unit: Metadata,
7683 };7805 };
76847806
7685 pub const LexicalBlock = struct {7807 pub const LexicalBlock = struct {
7686 file: Metadata,
7687 scope: Metadata,7808 scope: Metadata,
7809 file: Metadata,
7688 line: u32,7810 line: u32,
7689 column: u32,7811 column: u32,
7690 };7812 };
76917813
7692 pub const Location = struct {7814 pub const Location = struct {
7693 scope: Metadata,
7694 line: u32,7815 line: u32,
7695 column: u32,7816 column: u32,
7817 scope: Metadata,
7696 inlined_at: Metadata,7818 inlined_at: Metadata,
7697 };7819 };
76987820
...@@ -7700,6 +7822,10 @@ pub const Metadata = enum(u32) {...@@ -7700,6 +7822,10 @@ pub const Metadata = enum(u32) {
7700 name: MetadataString,7822 name: MetadataString,
7701 size_in_bits_lo: u32,7823 size_in_bits_lo: u32,
7702 size_in_bits_hi: u32,7824 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 }
7703 };7829 };
77047830
7705 pub const CompositeType = struct {7831 pub const CompositeType = struct {
...@@ -7713,6 +7839,13 @@ pub const Metadata = enum(u32) {...@@ -7713,6 +7839,13 @@ pub const Metadata = enum(u32) {
7713 align_in_bits_lo: u32,7839 align_in_bits_lo: u32,
7714 align_in_bits_hi: u32,7840 align_in_bits_hi: u32,
7715 fields_tuple: Metadata,7841 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 }
7716 };7849 };
77177850
7718 pub const DerivedType = struct {7851 pub const DerivedType = struct {
...@@ -7727,6 +7860,16 @@ pub const Metadata = enum(u32) {...@@ -7727,6 +7860,16 @@ pub const Metadata = enum(u32) {
7727 align_in_bits_hi: u32,7860 align_in_bits_hi: u32,
7728 offset_in_bits_lo: u32,7861 offset_in_bits_lo: u32,
7729 offset_in_bits_hi: u32,7862 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 }
7730 };7873 };
77317874
7732 pub const SubroutineType = struct {7875 pub const SubroutineType = struct {
...@@ -7758,7 +7901,7 @@ pub const Metadata = enum(u32) {...@@ -7758,7 +7901,7 @@ pub const Metadata = enum(u32) {
7758 };7901 };
77597902
7760 pub const ModuleFlag = struct {7903 pub const ModuleFlag = struct {
7761 behaviour: Metadata,7904 behavior: Metadata,
7762 name: MetadataString,7905 name: MetadataString,
7763 constant: Metadata,7906 constant: Metadata,
7764 };7907 };
...@@ -7781,7 +7924,7 @@ pub const Metadata = enum(u32) {...@@ -7781,7 +7924,7 @@ pub const Metadata = enum(u32) {
7781 };7924 };
77827925
7783 pub const GlobalVar = struct {7926 pub const GlobalVar = struct {
7784 pub const Flags = struct {7927 pub const Options = struct {
7785 local: bool,7928 local: bool,
7786 };7929 };
77877930
...@@ -7802,13 +7945,276 @@ pub const Metadata = enum(u32) {...@@ -7802,13 +7945,276 @@ pub const Metadata = enum(u32) {
7802 pub fn toValue(self: Metadata) Value {7945 pub fn toValue(self: Metadata) Value {
7803 return @enumFromInt(Value.first_metadata + @intFromEnum(self));7946 return @enumFromInt(Value.first_metadata + @intFromEnum(self));
7804 }7947 }
7805};
78067948
7807pub const InitError = error{7949 const Formatter = struct {
7808 InvalidLlvmTriple,7950 builder: *Builder,
7809} || Allocator.Error;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 {
7812 var self = Builder{8218 var self = Builder{
7813 .gpa = options.allocator,8219 .gpa = options.allocator,
7814 .strip = options.strip,8220 .strip = options.strip,
...@@ -8800,9 +9206,11 @@ pub fn printUnbuffered(...@@ -8800,9 +9206,11 @@ pub fn printUnbuffered(
8800 writer: anytype,9206 writer: anytype,
8801) (@TypeOf(writer).Error || Allocator.Error)!void {9207) (@TypeOf(writer).Error || Allocator.Error)!void {
8802 var need_newline = false;9208 var need_newline = false;
9209 var metadata_formatter: Metadata.Formatter = .{ .builder = self, .need_comma = undefined };
9210 defer metadata_formatter.map.deinit(self.gpa);
88039211
8804 if (self.source_filename != .none or self.data_layout != .none or self.target_triple != .none) {9212 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;
8806 if (self.source_filename != .none) try writer.print(9214 if (self.source_filename != .none) try writer.print(
8807 \\; ModuleID = '{s}'9215 \\; ModuleID = '{s}'
8808 \\source_filename = {"}9216 \\source_filename = {"}
...@@ -8816,36 +9224,35 @@ pub fn printUnbuffered(...@@ -8816,36 +9224,35 @@ pub fn printUnbuffered(
8816 \\target triple = {"}9224 \\target triple = {"}
8817 \\9225 \\
8818 , .{self.target_triple.fmt(self)});9226 , .{self.target_triple.fmt(self)});
8819 need_newline = true;
8820 }9227 }
88219228
8822 if (self.module_asm.items.len > 0) {9229 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;
8824 var line_it = std.mem.tokenizeScalar(u8, self.module_asm.items, '\n');9231 var line_it = std.mem.tokenizeScalar(u8, self.module_asm.items, '\n');
8825 while (line_it.next()) |line| {9232 while (line_it.next()) |line| {
8826 try writer.writeAll("module asm ");9233 try writer.writeAll("module asm ");
8827 try printEscapedString(line, .always_quote, writer);9234 try printEscapedString(line, .always_quote, writer);
8828 try writer.writeByte('\n');9235 try writer.writeByte('\n');
8829 }9236 }
8830 need_newline = true;
8831 }9237 }
88329238
8833 if (self.types.count() > 0) {9239 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;
8835 for (self.types.keys(), self.types.values()) |id, ty| try writer.print(9241 for (self.types.keys(), self.types.values()) |id, ty| try writer.print(
8836 \\%{} = type {}9242 \\%{} = type {}
8837 \\9243 \\
8838 , .{ id.fmt(self), ty.fmt(self) });9244 , .{ id.fmt(self), ty.fmt(self) });
8839 need_newline = true;
8840 }9245 }
88419246
8842 if (self.variables.items.len > 0) {9247 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;
8844 for (self.variables.items) |variable| {9249 for (self.variables.items) |variable| {
8845 if (variable.global.getReplacement(self) != .none) continue;9250 if (variable.global.getReplacement(self) != .none) continue;
8846 const global = variable.global.ptrConst(self);9251 const global = variable.global.ptrConst(self);
9252 metadata_formatter.need_comma = true;
9253 defer metadata_formatter.need_comma = undefined;
8847 try writer.print(9254 try writer.print(
8848 \\{} ={}{}{}{}{ }{}{ }{} {s} {%}{ }{, }9255 \\{} ={}{}{}{}{ }{}{ }{} {s} {%}{ }{, }{}
8849 \\9256 \\
8850 , .{9257 , .{
8851 variable.global.fmt(self),9258 variable.global.fmt(self),
...@@ -8861,18 +9268,20 @@ pub fn printUnbuffered(...@@ -8861,18 +9268,20 @@ pub fn printUnbuffered(
8861 global.type.fmt(self),9268 global.type.fmt(self),
8862 variable.init.fmt(self),9269 variable.init.fmt(self),
8863 variable.alignment,9270 variable.alignment,
9271 try metadata_formatter.fmt("!dbg ", global.dbg),
8864 });9272 });
8865 }9273 }
8866 need_newline = true;
8867 }9274 }
88689275
8869 if (self.aliases.items.len > 0) {9276 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;
8871 for (self.aliases.items) |alias| {9278 for (self.aliases.items) |alias| {
8872 if (alias.global.getReplacement(self) != .none) continue;9279 if (alias.global.getReplacement(self) != .none) continue;
8873 const global = alias.global.ptrConst(self);9280 const global = alias.global.ptrConst(self);
9281 metadata_formatter.need_comma = true;
9282 defer metadata_formatter.need_comma = undefined;
8874 try writer.print(9283 try writer.print(
8875 \\{} ={}{}{}{}{ }{} alias {%}, {%}9284 \\{} ={}{}{}{}{ }{} alias {%}, {%}{}
8876 \\9285 \\
8877 , .{9286 , .{
8878 alias.global.fmt(self),9287 alias.global.fmt(self),
...@@ -8884,9 +9293,9 @@ pub fn printUnbuffered(...@@ -8884,9 +9293,9 @@ pub fn printUnbuffered(
8884 global.unnamed_addr,9293 global.unnamed_addr,
8885 global.type.fmt(self),9294 global.type.fmt(self),
8886 alias.aliasee.fmt(self),9295 alias.aliasee.fmt(self),
9296 try metadata_formatter.fmt("!dbg ", global.dbg),
8887 });9297 });
8888 }9298 }
8889 need_newline = true;
8890 }9299 }
88919300
8892 var attribute_groups: std.AutoArrayHashMapUnmanaged(Attributes, void) = .{};9301 var attribute_groups: std.AutoArrayHashMapUnmanaged(Attributes, void) = .{};
...@@ -8894,7 +9303,7 @@ pub fn printUnbuffered(...@@ -8894,7 +9303,7 @@ pub fn printUnbuffered(
88949303
8895 for (0.., self.functions.items) |function_i, function| {9304 for (0.., self.functions.items) |function_i, function| {
8896 if (function.global.getReplacement(self) != .none) continue;9305 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;
8898 const function_index: Function.Index = @enumFromInt(function_i);9307 const function_index: Function.Index = @enumFromInt(function_i);
8899 const global = function.global.ptrConst(self);9308 const global = function.global.ptrConst(self);
8900 const params_len = global.type.functionParameters(self).len;9309 const params_len = global.type.functionParameters(self).len;
...@@ -8940,13 +9349,23 @@ pub fn printUnbuffered(...@@ -8940,13 +9349,23 @@ pub fn printUnbuffered(
8940 if (function_attributes != .none) try writer.print(" #{d}", .{9349 if (function_attributes != .none) try writer.print(" #{d}", .{
8941 (try attribute_groups.getOrPutValue(self.gpa, function_attributes, {})).index,9350 (try attribute_groups.getOrPutValue(self.gpa, function_attributes, {})).index,
8942 });9351 });
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 }
8944 if (function.instructions.len > 0) {9360 if (function.instructions.len > 0) {
8945 var block_incoming_len: u32 = undefined;9361 var block_incoming_len: u32 = undefined;
8946 try writer.writeAll(" {\n");9362 try writer.writeAll(" {\n");
9363 var dbg: Metadata = .none;
8947 for (params_len..function.instructions.len) |instruction_i| {9364 for (params_len..function.instructions.len) |instruction_i| {
8948 const instruction_index: Function.Instruction.Index = @enumFromInt(instruction_i);9365 const instruction_index: Function.Instruction.Index = @enumFromInt(instruction_i);
8949 const instruction = function.instructions.get(@intFromEnum(instruction_index));9366 const instruction = function.instructions.get(@intFromEnum(instruction_index));
9367 if (function.debug_locations.get(instruction_index)) |debug_location|
9368 dbg = debug_location;
8950 switch (instruction.tag) {9369 switch (instruction.tag) {
8951 .add,9370 .add,
8952 .@"add nsw",9371 .@"add nsw",
...@@ -9031,7 +9450,7 @@ pub fn printUnbuffered(...@@ -9031,7 +9450,7 @@ pub fn printUnbuffered(
9031 .xor,9450 .xor,
9032 => |tag| {9451 => |tag| {
9033 const extra = function.extraData(Function.Instruction.Binary, instruction.data);9452 const extra = function.extraData(Function.Instruction.Binary, instruction.data);
9034 try writer.print(" %{} = {s} {%}, {}\n", .{9453 try writer.print(" %{} = {s} {%}, {}", .{
9035 instruction_index.name(&function).fmt(self),9454 instruction_index.name(&function).fmt(self),
9036 @tagName(tag),9455 @tagName(tag),
9037 extra.lhs.fmt(function_index, self),9456 extra.lhs.fmt(function_index, self),
...@@ -9053,7 +9472,7 @@ pub fn printUnbuffered(...@@ -9053,7 +9472,7 @@ pub fn printUnbuffered(
9053 .zext,9472 .zext,
9054 => |tag| {9473 => |tag| {
9055 const extra = function.extraData(Function.Instruction.Cast, instruction.data);9474 const extra = function.extraData(Function.Instruction.Cast, instruction.data);
9056 try writer.print(" %{} = {s} {%} to {%}\n", .{9475 try writer.print(" %{} = {s} {%} to {%}", .{
9057 instruction_index.name(&function).fmt(self),9476 instruction_index.name(&function).fmt(self),
9058 @tagName(tag),9477 @tagName(tag),
9059 extra.val.fmt(function_index, self),9478 extra.val.fmt(function_index, self),
...@@ -9064,7 +9483,7 @@ pub fn printUnbuffered(...@@ -9064,7 +9483,7 @@ pub fn printUnbuffered(
9064 .@"alloca inalloca",9483 .@"alloca inalloca",
9065 => |tag| {9484 => |tag| {
9066 const extra = function.extraData(Function.Instruction.Alloca, instruction.data);9485 const extra = function.extraData(Function.Instruction.Alloca, instruction.data);
9067 try writer.print(" %{} = {s} {%}{,%}{, }{, }\n", .{9486 try writer.print(" %{} = {s} {%}{,%}{, }{, }", .{
9068 instruction_index.name(&function).fmt(self),9487 instruction_index.name(&function).fmt(self),
9069 @tagName(tag),9488 @tagName(tag),
9070 extra.type.fmt(self),9489 extra.type.fmt(self),
...@@ -9077,7 +9496,7 @@ pub fn printUnbuffered(...@@ -9077,7 +9496,7 @@ pub fn printUnbuffered(
9077 .atomicrmw => |tag| {9496 .atomicrmw => |tag| {
9078 const extra =9497 const extra =
9079 function.extraData(Function.Instruction.AtomicRmw, instruction.data);9498 function.extraData(Function.Instruction.AtomicRmw, instruction.data);
9080 try writer.print(" %{} = {s}{ } {s} {%}, {%}{ }{ }{, }\n", .{9499 try writer.print(" %{} = {s}{ } {s} {%}, {%}{ }{ }{, }", .{
9081 instruction_index.name(&function).fmt(self),9500 instruction_index.name(&function).fmt(self),
9082 @tagName(tag),9501 @tagName(tag),
9083 extra.info.access_kind,9502 extra.info.access_kind,
...@@ -9094,17 +9513,17 @@ pub fn printUnbuffered(...@@ -9094,17 +9513,17 @@ pub fn printUnbuffered(
9094 const name = instruction_index.name(&function);9513 const name = instruction_index.name(&function);
9095 if (@intFromEnum(instruction_index) > params_len)9514 if (@intFromEnum(instruction_index) > params_len)
9096 try writer.writeByte('\n');9515 try writer.writeByte('\n');
9097 try writer.print("{}:\n", .{name.fmt(self)});9516 try writer.print("{}:", .{name.fmt(self)});
9098 },9517 },
9099 .br => |tag| {9518 .br => |tag| {
9100 const target: Function.Block.Index = @enumFromInt(instruction.data);9519 const target: Function.Block.Index = @enumFromInt(instruction.data);
9101 try writer.print(" {s} {%}\n", .{9520 try writer.print(" {s} {%}", .{
9102 @tagName(tag), target.toInst(&function).fmt(function_index, self),9521 @tagName(tag), target.toInst(&function).fmt(function_index, self),
9103 });9522 });
9104 },9523 },
9105 .br_cond => {9524 .br_cond => {
9106 const extra = function.extraData(Function.Instruction.BrCond, instruction.data);9525 const extra = function.extraData(Function.Instruction.BrCond, instruction.data);
9107 try writer.print(" br {%}, {%}, {%}\n", .{9526 try writer.print(" br {%}, {%}, {%}", .{
9108 extra.cond.fmt(function_index, self),9527 extra.cond.fmt(function_index, self),
9109 extra.then.toInst(&function).fmt(function_index, self),9528 extra.then.toInst(&function).fmt(function_index, self),
9110 extra.@"else".toInst(&function).fmt(function_index, self),9529 extra.@"else".toInst(&function).fmt(function_index, self),
...@@ -9144,10 +9563,12 @@ pub fn printUnbuffered(...@@ -9144,10 +9563,12 @@ pub fn printUnbuffered(
9144 });9563 });
9145 for (0.., args) |arg_index, arg| {9564 for (0.., args) |arg_index, arg| {
9146 if (arg_index > 0) try writer.writeAll(", ");9565 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("{%}{}{}", .{
9148 arg.typeOf(function_index, self).fmt(self),9569 arg.typeOf(function_index, self).fmt(self),
9149 extra.data.attributes.param(arg_index, self).fmt(self),9570 extra.data.attributes.param(arg_index, self).fmt(self),
9150 arg.fmt(function_index, self),9571 try metadata_formatter.fmtLocal(" ", arg, function_index),
9151 });9572 });
9152 }9573 }
9153 try writer.writeByte(')');9574 try writer.writeByte(')');
...@@ -9159,14 +9580,13 @@ pub fn printUnbuffered(...@@ -9159,14 +9580,13 @@ pub fn printUnbuffered(
9159 {},9580 {},
9160 )).index,9581 )).index,
9161 });9582 });
9162 try writer.writeByte('\n');
9163 },9583 },
9164 .cmpxchg,9584 .cmpxchg,
9165 .@"cmpxchg weak",9585 .@"cmpxchg weak",
9166 => |tag| {9586 => |tag| {
9167 const extra =9587 const extra =
9168 function.extraData(Function.Instruction.CmpXchg, instruction.data);9588 function.extraData(Function.Instruction.CmpXchg, instruction.data);
9169 try writer.print(" %{} = {s}{ } {%}, {%}, {%}{ }{ }{ }{, }\n", .{9589 try writer.print(" %{} = {s}{ } {%}, {%}, {%}{ }{ }{ }{, }", .{
9170 instruction_index.name(&function).fmt(self),9590 instruction_index.name(&function).fmt(self),
9171 @tagName(tag),9591 @tagName(tag),
9172 extra.info.access_kind,9592 extra.info.access_kind,
...@@ -9182,7 +9602,7 @@ pub fn printUnbuffered(...@@ -9182,7 +9602,7 @@ pub fn printUnbuffered(
9182 .extractelement => |tag| {9602 .extractelement => |tag| {
9183 const extra =9603 const extra =
9184 function.extraData(Function.Instruction.ExtractElement, instruction.data);9604 function.extraData(Function.Instruction.ExtractElement, instruction.data);
9185 try writer.print(" %{} = {s} {%}, {%}\n", .{9605 try writer.print(" %{} = {s} {%}, {%}", .{
9186 instruction_index.name(&function).fmt(self),9606 instruction_index.name(&function).fmt(self),
9187 @tagName(tag),9607 @tagName(tag),
9188 extra.val.fmt(function_index, self),9608 extra.val.fmt(function_index, self),
...@@ -9201,7 +9621,6 @@ pub fn printUnbuffered(...@@ -9201,7 +9621,6 @@ pub fn printUnbuffered(
9201 extra.data.val.fmt(function_index, self),9621 extra.data.val.fmt(function_index, self),
9202 });9622 });
9203 for (indices) |index| try writer.print(", {d}", .{index});9623 for (indices) |index| try writer.print(", {d}", .{index});
9204 try writer.writeByte('\n');
9205 },9624 },
9206 .fence => |tag| {9625 .fence => |tag| {
9207 const info: MemoryAccessInfo = @bitCast(instruction.data);9626 const info: MemoryAccessInfo = @bitCast(instruction.data);
...@@ -9215,7 +9634,7 @@ pub fn printUnbuffered(...@@ -9215,7 +9634,7 @@ pub fn printUnbuffered(
9215 .@"fneg fast",9634 .@"fneg fast",
9216 => |tag| {9635 => |tag| {
9217 const val: Value = @enumFromInt(instruction.data);9636 const val: Value = @enumFromInt(instruction.data);
9218 try writer.print(" %{} = {s} {%}\n", .{9637 try writer.print(" %{} = {s} {%}", .{
9219 instruction_index.name(&function).fmt(self),9638 instruction_index.name(&function).fmt(self),
9220 @tagName(tag),9639 @tagName(tag),
9221 val.fmt(function_index, self),9640 val.fmt(function_index, self),
...@@ -9238,12 +9657,11 @@ pub fn printUnbuffered(...@@ -9238,12 +9657,11 @@ pub fn printUnbuffered(
9238 for (indices) |index| try writer.print(", {%}", .{9657 for (indices) |index| try writer.print(", {%}", .{
9239 index.fmt(function_index, self),9658 index.fmt(function_index, self),
9240 });9659 });
9241 try writer.writeByte('\n');
9242 },9660 },
9243 .insertelement => |tag| {9661 .insertelement => |tag| {
9244 const extra =9662 const extra =
9245 function.extraData(Function.Instruction.InsertElement, instruction.data);9663 function.extraData(Function.Instruction.InsertElement, instruction.data);
9246 try writer.print(" %{} = {s} {%}, {%}, {%}\n", .{9664 try writer.print(" %{} = {s} {%}, {%}, {%}", .{
9247 instruction_index.name(&function).fmt(self),9665 instruction_index.name(&function).fmt(self),
9248 @tagName(tag),9666 @tagName(tag),
9249 extra.val.fmt(function_index, self),9667 extra.val.fmt(function_index, self),
...@@ -9262,13 +9680,12 @@ pub fn printUnbuffered(...@@ -9262,13 +9680,12 @@ pub fn printUnbuffered(
9262 extra.data.elem.fmt(function_index, self),9680 extra.data.elem.fmt(function_index, self),
9263 });9681 });
9264 for (indices) |index| try writer.print(", {d}", .{index});9682 for (indices) |index| try writer.print(", {d}", .{index});
9265 try writer.writeByte('\n');
9266 },9683 },
9267 .load,9684 .load,
9268 .@"load atomic",9685 .@"load atomic",
9269 => |tag| {9686 => |tag| {
9270 const extra = function.extraData(Function.Instruction.Load, instruction.data);9687 const extra = function.extraData(Function.Instruction.Load, instruction.data);
9271 try writer.print(" %{} = {s}{ } {%}, {%}{ }{ }{, }\n", .{9688 try writer.print(" %{} = {s}{ } {%}, {%}{ }{ }{, }", .{
9272 instruction_index.name(&function).fmt(self),9689 instruction_index.name(&function).fmt(self),
9273 @tagName(tag),9690 @tagName(tag),
9274 extra.info.access_kind,9691 extra.info.access_kind,
...@@ -9298,23 +9715,22 @@ pub fn printUnbuffered(...@@ -9298,23 +9715,22 @@ pub fn printUnbuffered(
9298 incoming_block.toInst(&function).fmt(function_index, self),9715 incoming_block.toInst(&function).fmt(function_index, self),
9299 });9716 });
9300 }9717 }
9301 try writer.writeByte('\n');
9302 },9718 },
9303 .ret => |tag| {9719 .ret => |tag| {
9304 const val: Value = @enumFromInt(instruction.data);9720 const val: Value = @enumFromInt(instruction.data);
9305 try writer.print(" {s} {%}\n", .{9721 try writer.print(" {s} {%}", .{
9306 @tagName(tag),9722 @tagName(tag),
9307 val.fmt(function_index, self),9723 val.fmt(function_index, self),
9308 });9724 });
9309 },9725 },
9310 .@"ret void",9726 .@"ret void",
9311 .@"unreachable",9727 .@"unreachable",
9312 => |tag| try writer.print(" {s}\n", .{@tagName(tag)}),9728 => |tag| try writer.print(" {s}", .{@tagName(tag)}),
9313 .select,9729 .select,
9314 .@"select fast",9730 .@"select fast",
9315 => |tag| {9731 => |tag| {
9316 const extra = function.extraData(Function.Instruction.Select, instruction.data);9732 const extra = function.extraData(Function.Instruction.Select, instruction.data);
9317 try writer.print(" %{} = {s} {%}, {%}, {%}\n", .{9733 try writer.print(" %{} = {s} {%}, {%}, {%}", .{
9318 instruction_index.name(&function).fmt(self),9734 instruction_index.name(&function).fmt(self),
9319 @tagName(tag),9735 @tagName(tag),
9320 extra.cond.fmt(function_index, self),9736 extra.cond.fmt(function_index, self),
...@@ -9325,7 +9741,7 @@ pub fn printUnbuffered(...@@ -9325,7 +9741,7 @@ pub fn printUnbuffered(
9325 .shufflevector => |tag| {9741 .shufflevector => |tag| {
9326 const extra =9742 const extra =
9327 function.extraData(Function.Instruction.ShuffleVector, instruction.data);9743 function.extraData(Function.Instruction.ShuffleVector, instruction.data);
9328 try writer.print(" %{} = {s} {%}, {%}, {%}\n", .{9744 try writer.print(" %{} = {s} {%}, {%}, {%}", .{
9329 instruction_index.name(&function).fmt(self),9745 instruction_index.name(&function).fmt(self),
9330 @tagName(tag),9746 @tagName(tag),
9331 extra.lhs.fmt(function_index, self),9747 extra.lhs.fmt(function_index, self),
...@@ -9337,7 +9753,7 @@ pub fn printUnbuffered(...@@ -9337,7 +9753,7 @@ pub fn printUnbuffered(
9337 .@"store atomic",9753 .@"store atomic",
9338 => |tag| {9754 => |tag| {
9339 const extra = function.extraData(Function.Instruction.Store, instruction.data);9755 const extra = function.extraData(Function.Instruction.Store, instruction.data);
9340 try writer.print(" {s}{ } {%}, {%}{ }{ }{, }\n", .{9756 try writer.print(" {s}{ } {%}, {%}{ }{ }{, }", .{
9341 @tagName(tag),9757 @tagName(tag),
9342 extra.info.access_kind,9758 extra.info.access_kind,
9343 extra.val.fmt(function_index, self),9759 extra.val.fmt(function_index, self),
...@@ -9365,11 +9781,11 @@ pub fn printUnbuffered(...@@ -9365,11 +9781,11 @@ pub fn printUnbuffered(
9365 case_block.toInst(&function).fmt(function_index, self),9781 case_block.toInst(&function).fmt(function_index, self),
9366 },9782 },
9367 );9783 );
9368 try writer.writeAll(" ]\n");9784 try writer.writeAll(" ]");
9369 },9785 },
9370 .va_arg => |tag| {9786 .va_arg => |tag| {
9371 const extra = function.extraData(Function.Instruction.VaArg, instruction.data);9787 const extra = function.extraData(Function.Instruction.VaArg, instruction.data);
9372 try writer.print(" %{} = {s} {%}, {%}\n", .{9788 try writer.print(" %{} = {s} {%}, {%}", .{
9373 instruction_index.name(&function).fmt(self),9789 instruction_index.name(&function).fmt(self),
9374 @tagName(tag),9790 @tagName(tag),
9375 extra.list.fmt(function_index, self),9791 extra.list.fmt(function_index, self),
...@@ -9377,11 +9793,13 @@ pub fn printUnbuffered(...@@ -9377,11 +9793,13 @@ pub fn printUnbuffered(
9377 });9793 });
9378 },9794 },
9379 }9795 }
9796 metadata_formatter.need_comma = true;
9797 defer metadata_formatter.need_comma = undefined;
9798 try writer.print("{}\n", .{try metadata_formatter.fmt("!dbg ", dbg)});
9380 }9799 }
9381 try writer.writeByte('}');9800 try writer.writeByte('}');
9382 }9801 }
9383 try writer.writeByte('\n');9802 try writer.writeByte('\n');
9384 need_newline = true;
9385 }9803 }
93869804
9387 if (attribute_groups.count() > 0) {9805 if (attribute_groups.count() > 0) {
...@@ -9391,7 +9809,367 @@ pub fn printUnbuffered(...@@ -9391,7 +9809,367 @@ pub fn printUnbuffered(
9391 \\attributes #{d} = {{{#"} }}9809 \\attributes #{d} = {{{#"} }}
9392 \\9810 \\
9393 , .{ attribute_group_index, attribute_group.fmt(self) });9811 , .{ 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 }
9395 }10173 }
9396}10174}
939710175
...@@ -9725,7 +10503,7 @@ fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraInd...@@ -9725,7 +10503,7 @@ fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraInd
9725 self.type_extra.appendAssumeCapacity(switch (field.type) {10503 self.type_extra.appendAssumeCapacity(switch (field.type) {
9726 u32 => value,10504 u32 => value,
9727 String, Type => @intFromEnum(value),10505 String, Type => @intFromEnum(value),
9728 else => @compileError("bad field type: " ++ @typeName(field.type)),10506 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
9729 });10507 });
9730 }10508 }
9731 return result;10509 return result;
...@@ -10894,6 +11672,7 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item....@@ -10894,6 +11672,7 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.
10894 self.metadata_extra.appendAssumeCapacity(switch (field.type) {11672 self.metadata_extra.appendAssumeCapacity(switch (field.type) {
10895 u32 => value,11673 u32 => value,
10896 MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value),11674 MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value),
11675 Metadata.DIFlags => @bitCast(value),
10897 else => @compileError("bad field type: " ++ @typeName(field.type)),11676 else => @compileError("bad field type: " ++ @typeName(field.type)),
10898 });11677 });
10899 }11678 }
...@@ -10932,6 +11711,7 @@ fn metadataExtraDataTrail(...@@ -10932,6 +11711,7 @@ fn metadataExtraDataTrail(
10932 @field(result, field.name) = switch (field.type) {11711 @field(result, field.name) = switch (field.type) {
10933 u32 => value,11712 u32 => value,
10934 MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value),11713 MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value),
11714 Metadata.DIFlags => @bitCast(value),
10935 else => @compileError("bad field type: " ++ @typeName(field.type)),11715 else => @compileError("bad field type: " ++ @typeName(field.type)),
10936 };11716 };
10937 return .{11717 return .{
...@@ -10989,10 +11769,7 @@ pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const...@@ -10989,10 +11769,7 @@ pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const
10989}11769}
1099011770
10991pub fn debugNamed(self: *Builder, name: MetadataString, operands: []const Metadata) Allocator.Error!void {11771pub fn debugNamed(self: *Builder, name: MetadataString, operands: []const Metadata) Allocator.Error!void {
10992 try self.metadata_extra.ensureUnusedCapacity(11772 try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len);
10993 self.gpa,
10994 operands.len * @sizeOf(Metadata),
10995 );
10996 try self.metadata_named.ensureUnusedCapacity(self.gpa, 1);11773 try self.metadata_named.ensureUnusedCapacity(self.gpa, 1);
10997 self.debugNamedAssumeCapacity(name, operands);11774 self.debugNamedAssumeCapacity(name, operands);
10998}11775}
...@@ -11002,9 +11779,13 @@ fn debugNone(self: *Builder) Allocator.Error!Metadata {...@@ -11002,9 +11779,13 @@ fn debugNone(self: *Builder) Allocator.Error!Metadata {
11002 return self.debugNoneAssumeCapacity();11779 return self.debugNoneAssumeCapacity();
11003}11780}
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 {
11006 try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0);11787 try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0);
11007 return self.debugFileAssumeCapacity(path, name);11788 return self.debugFileAssumeCapacity(filename, directory);
11008}11789}
1100911790
11010pub fn debugCompileUnit(11791pub fn debugCompileUnit(
...@@ -11013,10 +11794,10 @@ pub fn debugCompileUnit(...@@ -11013,10 +11794,10 @@ pub fn debugCompileUnit(
11013 producer: MetadataString,11794 producer: MetadataString,
11014 enums: Metadata,11795 enums: Metadata,
11015 globals: Metadata,11796 globals: Metadata,
11016 flags: Metadata.CompileUnit.Flags,11797 options: Metadata.CompileUnit.Options,
11017) Allocator.Error!Metadata {11798) Allocator.Error!Metadata {
11018 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);11799 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);
11020}11801}
1102111802
11022pub fn debugSubprogram(11803pub fn debugSubprogram(
...@@ -11027,7 +11808,7 @@ pub fn debugSubprogram(...@@ -11027,7 +11808,7 @@ pub fn debugSubprogram(
11027 line: u32,11808 line: u32,
11028 scope_line: u32,11809 scope_line: u32,
11029 ty: Metadata,11810 ty: Metadata,
11030 flags: Metadata.Subprogram.Flags,11811 options: Metadata.Subprogram.Options,
11031 compile_unit: Metadata,11812 compile_unit: Metadata,
11032) Allocator.Error!Metadata {11813) Allocator.Error!Metadata {
11033 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);11814 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);
...@@ -11038,19 +11819,19 @@ pub fn debugSubprogram(...@@ -11038,19 +11819,19 @@ pub fn debugSubprogram(
11038 line,11819 line,
11039 scope_line,11820 scope_line,
11040 ty,11821 ty,
11041 flags,11822 options,
11042 compile_unit,11823 compile_unit,
11043 );11824 );
11044}11825}
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 {
11047 try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0);11828 try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0);
11048 return self.debugLexicalBlockAssumeCapacity(file, scope, line, column);11829 return self.debugLexicalBlockAssumeCapacity(scope, file, line, column);
11049}11830}
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 {
11052 try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0);11833 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);
11054}11835}
1105511836
11056pub fn debugBoolType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata {11837pub fn debugBoolType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata {
...@@ -11294,12 +12075,12 @@ pub fn debugTuple(...@@ -11294,12 +12075,12 @@ pub fn debugTuple(
1129412075
11295pub fn debugModuleFlag(12076pub fn debugModuleFlag(
11296 self: *Builder,12077 self: *Builder,
11297 behaviour: Metadata,12078 behavior: Metadata,
11298 name: MetadataString,12079 name: MetadataString,
11299 constant: Metadata,12080 constant: Metadata,
11300) Allocator.Error!Metadata {12081) Allocator.Error!Metadata {
11301 try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0);12082 try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0);
11302 return self.debugModuleFlagAssumeCapacity(behaviour, name, constant);12083 return self.debugModuleFlagAssumeCapacity(behavior, name, constant);
11303}12084}
1130412085
11305pub fn debugLocalVar(12086pub fn debugLocalVar(
...@@ -11336,7 +12117,7 @@ pub fn debugGlobalVar(...@@ -11336,7 +12117,7 @@ pub fn debugGlobalVar(
11336 line: u32,12117 line: u32,
11337 ty: Metadata,12118 ty: Metadata,
11338 variable: Variable.Index,12119 variable: Variable.Index,
11339 flags: Metadata.GlobalVar.Flags,12120 options: Metadata.GlobalVar.Options,
11340) Allocator.Error!Metadata {12121) Allocator.Error!Metadata {
11341 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);12122 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);
11342 return self.debugGlobalVarAssumeCapacity(12123 return self.debugGlobalVarAssumeCapacity(
...@@ -11347,7 +12128,7 @@ pub fn debugGlobalVar(...@@ -11347,7 +12128,7 @@ pub fn debugGlobalVar(
11347 line,12128 line,
11348 ty,12129 ty,
11349 variable,12130 variable,
11350 flags,12131 options,
11351 );12132 );
11352}12133}
1135312134
...@@ -11393,12 +12174,7 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp...@@ -11393,12 +12174,7 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp
11393 if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;12174 if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
11394 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];12175 const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
11395 const rhs_extra = ctx.builder.metadataExtraData(@TypeOf(value), rhs_data);12176 const rhs_extra = ctx.builder.metadataExtraData(@TypeOf(value), rhs_data);
11396 inline for (std.meta.fields(@TypeOf(value))) |field| {12177 return std.meta.eql(lhs_key.value, rhs_extra);
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;
11402 }12178 }
11403 };12179 };
1140412180
...@@ -11418,6 +12194,37 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp...@@ -11418,6 +12194,37 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp
11418 return @enumFromInt(gop.index);12194 return @enumFromInt(gop.index);
11419}12195}
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
11421fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void {12228fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void {
11422 std.debug.assert(name != .none);12229 std.debug.assert(name != .none);
11423 const extra_index: u32 = @intCast(self.metadata_extra.items.len);12230 const extra_index: u32 = @intCast(self.metadata_extra.items.len);
...@@ -11434,10 +12241,14 @@ pub fn debugNoneAssumeCapacity(self: *Builder) Metadata {...@@ -11434,10 +12241,14 @@ pub fn debugNoneAssumeCapacity(self: *Builder) Metadata {
11434 return self.metadataSimpleAssumeCapacity(.none, .{});12241 return self.metadataSimpleAssumeCapacity(.none, .{});
11435}12242}
1143612243
11437fn debugFileAssumeCapacity(self: *Builder, path: MetadataString, name: MetadataString) Metadata {12244fn debugFileAssumeCapacity(
11438 return self.metadataSimpleAssumeCapacity(.file, Metadata.File{12245 self: *Builder,
11439 .path = path,12246 filename: MetadataString,
11440 .name = name,12247 directory: MetadataString,
12248) Metadata {
12249 return self.metadataDistinctAssumeCapacity(.file, Metadata.File{
12250 .filename = filename,
12251 .directory = directory,
11441 });12252 });
11442}12253}
1144312254
...@@ -11447,10 +12258,10 @@ pub fn debugCompileUnitAssumeCapacity(...@@ -11447,10 +12258,10 @@ pub fn debugCompileUnitAssumeCapacity(
11447 producer: MetadataString,12258 producer: MetadataString,
11448 enums: Metadata,12259 enums: Metadata,
11449 globals: Metadata,12260 globals: Metadata,
11450 flags: Metadata.CompileUnit.Flags,12261 options: Metadata.CompileUnit.Options,
11451) Metadata {12262) Metadata {
11452 return self.metadataSimpleAssumeCapacity(12263 return self.metadataDistinctAssumeCapacity(
11453 if (flags.optimized) .@"compile_unit optimized" else .compile_unit,12264 if (options.optimized) .@"compile_unit optimized" else .compile_unit,
11454 Metadata.CompileUnit{12265 Metadata.CompileUnit{
11455 .file = file,12266 .file = file,
11456 .producer = producer,12267 .producer = producer,
...@@ -11468,57 +12279,43 @@ fn debugSubprogramAssumeCapacity(...@@ -11468,57 +12279,43 @@ fn debugSubprogramAssumeCapacity(
11468 line: u32,12279 line: u32,
11469 scope_line: u32,12280 scope_line: u32,
11470 ty: Metadata,12281 ty: Metadata,
11471 flags: Metadata.Subprogram.Flags,12282 options: Metadata.Subprogram.Options,
11472 compile_unit: Metadata,12283 compile_unit: Metadata,
11473) Metadata {12284) Metadata {
11474 const tag: Metadata.Tag = blk: {12285 const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) +
11475 var int: u3 = 0;12286 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
11476 if (flags.optimized) int |= 0b1;12287 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
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{
11491 .file = file,12288 .file = file,
11492 .name = name,12289 .name = name,
11493 .linkage_name = linkage_name,12290 .linkage_name = linkage_name,
11494 .line = line,12291 .line = line,
11495 .scope_line = scope_line,12292 .scope_line = scope_line,
11496 .ty = ty,12293 .ty = ty,
11497 .debug_info_flags = flags.debug_info_flags,12294 .di_flags = options.di_flags,
11498 .compile_unit = compile_unit,12295 .compile_unit = compile_unit,
11499 });12296 });
11500}12297}
1150112298
11502fn debugLexicalBlockAssumeCapacity(self: *Builder, file: Metadata, scope: Metadata, line: u32, column: u32) Metadata {12299fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Metadata {
11503 return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{12300 return self.metadataDistinctAssumeCapacity(.lexical_block, Metadata.LexicalBlock{
11504 .file = file,
11505 .scope = scope,12301 .scope = scope,
12302 .file = file,
11506 .line = line,12303 .line = line,
11507 .column = column,12304 .column = column,
11508 });12305 });
11509}12306}
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 {
11512 return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{12309 return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{
11513 .scope = scope,
11514 .line = line,12310 .line = line,
11515 .column = column,12311 .column = column,
12312 .scope = scope,
11516 .inlined_at = inlined_at,12313 .inlined_at = inlined_at,
11517 });12314 });
11518}12315}
1151912316
11520fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12317fn 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{
11522 .name = name,12319 .name = name,
11523 .size_in_bits_lo = @truncate(size_in_bits),12320 .size_in_bits_lo = @truncate(size_in_bits),
11524 .size_in_bits_hi = @truncate(size_in_bits >> 32),12321 .size_in_bits_hi = @truncate(size_in_bits >> 32),
...@@ -11526,7 +12323,7 @@ fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bit...@@ -11526,7 +12323,7 @@ fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bit
11526}12323}
1152712324
11528fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12325fn 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{
11530 .name = name,12327 .name = name,
11531 .size_in_bits_lo = @truncate(size_in_bits),12328 .size_in_bits_lo = @truncate(size_in_bits),
11532 .size_in_bits_hi = @truncate(size_in_bits >> 32),12329 .size_in_bits_hi = @truncate(size_in_bits >> 32),
...@@ -11534,7 +12331,7 @@ fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in...@@ -11534,7 +12331,7 @@ fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in
11534}12331}
1153512332
11536fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12333fn 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{
11538 .name = name,12335 .name = name,
11539 .size_in_bits_lo = @truncate(size_in_bits),12336 .size_in_bits_lo = @truncate(size_in_bits),
11540 .size_in_bits_hi = @truncate(size_in_bits >> 32),12337 .size_in_bits_hi = @truncate(size_in_bits >> 32),
...@@ -11542,7 +12339,7 @@ fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_b...@@ -11542,7 +12339,7 @@ fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_b
11542}12339}
1154312340
11544fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12341fn 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{
11546 .name = name,12343 .name = name,
11547 .size_in_bits_lo = @truncate(size_in_bits),12344 .size_in_bits_lo = @truncate(size_in_bits),
11548 .size_in_bits_hi = @truncate(size_in_bits >> 32),12345 .size_in_bits_hi = @truncate(size_in_bits >> 32),
...@@ -11687,84 +12484,18 @@ fn debugCompositeTypeAssumeCapacity(...@@ -11687,84 +12484,18 @@ fn debugCompositeTypeAssumeCapacity(
11687 align_in_bits: u64,12484 align_in_bits: u64,
11688 fields_tuple: Metadata,12485 fields_tuple: Metadata,
11689) Metadata {12486) Metadata {
11690 const Key = struct {12487 return self.metadataDistinctAssumeCapacity(tag, Metadata.CompositeType{
11691 tag: Metadata.Tag,12488 .name = name,
11692 name: MetadataString,12489 .file = file,
11693 file: Metadata,12490 .scope = scope,
11694 scope: Metadata,12491 .line = line,
11695 line: u32,12492 .underlying_type = underlying_type,
11696 underlying_type: Metadata,12493 .size_in_bits_lo = @truncate(size_in_bits),
11697 size_in_bits: u64,12494 .size_in_bits_hi = @truncate(size_in_bits >> 32),
11698 align_in_bits: u64,12495 .align_in_bits_lo = @truncate(align_in_bits),
11699 fields_tuple: Metadata,12496 .align_in_bits_hi = @truncate(align_in_bits >> 32),
11700 };12497 .fields_tuple = fields_tuple,
11701 const Adapter = struct {12498 });
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);
11768}12499}
1176912500
11770fn debugPointerTypeAssumeCapacity(12501fn debugPointerTypeAssumeCapacity(
...@@ -11778,7 +12509,7 @@ fn debugPointerTypeAssumeCapacity(...@@ -11778,7 +12509,7 @@ fn debugPointerTypeAssumeCapacity(
11778 align_in_bits: u64,12509 align_in_bits: u64,
11779 offset_in_bits: u64,12510 offset_in_bits: u64,
11780) Metadata {12511) Metadata {
11781 return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{12512 return self.metadataDistinctAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{
11782 .name = name,12513 .name = name,
11783 .file = file,12514 .file = file,
11784 .scope = scope,12515 .scope = scope,
...@@ -11804,7 +12535,7 @@ fn debugMemberTypeAssumeCapacity(...@@ -11804,7 +12535,7 @@ fn debugMemberTypeAssumeCapacity(
11804 align_in_bits: u64,12535 align_in_bits: u64,
11805 offset_in_bits: u64,12536 offset_in_bits: u64,
11806) Metadata {12537) Metadata {
11807 return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{12538 return self.metadataDistinctAssumeCapacity(.derived_member_type, Metadata.DerivedType{
11808 .name = name,12539 .name = name,
11809 .file = file,12540 .file = file,
11810 .scope = scope,12541 .scope = scope,
...@@ -11823,7 +12554,7 @@ fn debugSubroutineTypeAssumeCapacity(...@@ -11823,7 +12554,7 @@ fn debugSubroutineTypeAssumeCapacity(
11823 self: *Builder,12554 self: *Builder,
11824 types_tuple: Metadata,12555 types_tuple: Metadata,
11825) Metadata {12556) Metadata {
11826 return self.metadataSimpleAssumeCapacity(.subroutine_type, Metadata.SubroutineType{12557 return self.metadataDistinctAssumeCapacity(.subroutine_type, Metadata.SubroutineType{
11827 .types_tuple = types_tuple,12558 .types_tuple = types_tuple,
11828 });12559 });
11829}12560}
...@@ -11835,52 +12566,32 @@ fn debugEnumeratorAssumeCapacity(...@@ -11835,52 +12566,32 @@ fn debugEnumeratorAssumeCapacity(
11835 bit_width: u32,12566 bit_width: u32,
11836 value: std.math.big.int.Const,12567 value: std.math.big.int.Const,
11837) Metadata {12568) Metadata {
11838 const Key = struct {12569 const Key = struct { tag: Metadata.Tag, index: Metadata };
11839 tag: Metadata.Tag,
11840 name: MetadataString,
11841 bit_width: u32,
11842 value: std.math.big.int.Const,
11843 };
11844 const Adapter = struct {12570 const Adapter = struct {
11845 builder: *const Builder,
11846 pub fn hash(_: @This(), key: Key) u32 {12571 pub fn hash(_: @This(), key: Key) u32 {
11847 var hasher = std.hash.Wyhash.init(std.hash.uint32(@intFromEnum(key.tag)));12572 return @truncate(std.hash.Wyhash.hash(
11848 hasher.update(std.mem.asBytes(&key.name));12573 std.hash.uint32(@intFromEnum(key.tag)),
11849 hasher.update(std.mem.asBytes(&key.bit_width));12574 std.mem.asBytes(&key.index),
11850 hasher.update(std.mem.sliceAsBytes(key.value.limbs));12575 ));
11851 return @truncate(hasher.final());
11852 }12576 }
1185312577
11854 pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {12578 pub fn eql(_: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
11855 if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;12579 return @intFromEnum(lhs_key.index) == rhs_index;
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);
11867 }12580 }
11868 };12581 };
1186912582
11870 const tag: Metadata.Tag = if (unsigned)12583 const tag: Metadata.Tag = if (unsigned)
11871 .enumerator_unsigned12584 .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
11874 std.debug.assert(!(tag == .enumerator_unsigned and !value.positive));12590 std.debug.assert(!(tag == .enumerator_unsigned and !value.positive));
1187512591
11876 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(12592 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
11877 Key{12593 Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) },
11878 .tag = tag,12594 Adapter{},
11879 .name = name,
11880 .bit_width = bit_width,
11881 .value = value,
11882 },
11883 Adapter{ .builder = self },
11884 );12595 );
1188512596
11886 if (!gop.found_existing) {12597 if (!gop.found_existing) {
...@@ -11905,7 +12616,7 @@ fn debugSubrangeAssumeCapacity(...@@ -11905,7 +12616,7 @@ fn debugSubrangeAssumeCapacity(
11905 lower_bound: Metadata,12616 lower_bound: Metadata,
11906 count: Metadata,12617 count: Metadata,
11907) Metadata {12618) Metadata {
11908 return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{12619 return self.metadataDistinctAssumeCapacity(.subrange, Metadata.Subrange{
11909 .lower_bound = lower_bound,12620 .lower_bound = lower_bound,
11910 .count = count,12621 .count = count,
11911 });12622 });
...@@ -12005,12 +12716,12 @@ fn debugTupleAssumeCapacity(...@@ -12005,12 +12716,12 @@ fn debugTupleAssumeCapacity(
1200512716
12006fn debugModuleFlagAssumeCapacity(12717fn debugModuleFlagAssumeCapacity(
12007 self: *Builder,12718 self: *Builder,
12008 behaviour: Metadata,12719 behavior: Metadata,
12009 name: MetadataString,12720 name: MetadataString,
12010 constant: Metadata,12721 constant: Metadata,
12011) Metadata {12722) Metadata {
12012 return self.metadataSimpleAssumeCapacity(.module_flag, Metadata.ModuleFlag{12723 return self.metadataSimpleAssumeCapacity(.module_flag, Metadata.ModuleFlag{
12013 .behaviour = behaviour,12724 .behavior = behavior,
12014 .name = name,12725 .name = name,
12015 .constant = constant,12726 .constant = constant,
12016 });12727 });
...@@ -12024,7 +12735,7 @@ fn debugLocalVarAssumeCapacity(...@@ -12024,7 +12735,7 @@ fn debugLocalVarAssumeCapacity(
12024 line: u32,12735 line: u32,
12025 ty: Metadata,12736 ty: Metadata,
12026) Allocator.Error!Metadata {12737) Allocator.Error!Metadata {
12027 return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{12738 return self.metadataDistinctAssumeCapacity(.local_var, Metadata.LocalVar{
12028 .name = name,12739 .name = name,
12029 .file = file,12740 .file = file,
12030 .scope = scope,12741 .scope = scope,
...@@ -12042,7 +12753,7 @@ fn debugParameterAssumeCapacity(...@@ -12042,7 +12753,7 @@ fn debugParameterAssumeCapacity(
12042 ty: Metadata,12753 ty: Metadata,
12043 arg_no: u32,12754 arg_no: u32,
12044) Allocator.Error!Metadata {12755) Allocator.Error!Metadata {
12045 return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{12756 return self.metadataDistinctAssumeCapacity(.parameter, Metadata.Parameter{
12046 .name = name,12757 .name = name,
12047 .file = file,12758 .file = file,
12048 .scope = scope,12759 .scope = scope,
...@@ -12061,10 +12772,10 @@ fn debugGlobalVarAssumeCapacity(...@@ -12061,10 +12772,10 @@ fn debugGlobalVarAssumeCapacity(
12061 line: u32,12772 line: u32,
12062 ty: Metadata,12773 ty: Metadata,
12063 variable: Variable.Index,12774 variable: Variable.Index,
12064 flags: Metadata.GlobalVar.Flags,12775 options: Metadata.GlobalVar.Options,
12065) Allocator.Error!Metadata {12776) Allocator.Error!Metadata {
12066 return self.metadataSimpleAssumeCapacity(12777 return self.metadataDistinctAssumeCapacity(
12067 if (flags.local) .@"global_var local" else .global_var,12778 if (options.local) .@"global_var local" else .global_var,
12068 Metadata.GlobalVar{12779 Metadata.GlobalVar{
12069 .name = name,12780 .name = name,
12070 .linkage_name = linkage_name,12781 .linkage_name = linkage_name,
...@@ -12082,7 +12793,7 @@ fn debugGlobalVarExpressionAssumeCapacity(...@@ -12082,7 +12793,7 @@ fn debugGlobalVarExpressionAssumeCapacity(
12082 variable: Metadata,12793 variable: Metadata,
12083 expression: Metadata,12794 expression: Metadata,
12084) Metadata {12795) Metadata {
12085 return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{12796 return self.metadataDistinctAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{
12086 .variable = variable,12797 .variable = variable,
12087 .expression = expression,12798 .expression = expression,
12088 });12799 });
...@@ -12123,20 +12834,26 @@ fn debugConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {...@@ -12123,20 +12834,26 @@ fn debugConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {
12123pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]const u32 {12834pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]const u32 {
12124 const BitcodeWriter = bitcode_writer.BitcodeWriter(&.{ Type, FunctionAttributes });12835 const BitcodeWriter = bitcode_writer.BitcodeWriter(&.{ Type, FunctionAttributes });
12125 var bitcode = BitcodeWriter.init(allocator, &.{12836 var bitcode = BitcodeWriter.init(allocator, &.{
12126 std.math.log2_int_ceil(usize, self.type_items.items.len - 1),12837 if (self.type_items.items.len > 0)
12127 std.math.log2_int_ceil(usize, self.function_attributes_set.count() - 1),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,
12128 });12845 });
12129 errdefer bitcode.deinit();12846 errdefer bitcode.deinit();
1213012847
12131 // Write LLVM IR magic12848 // 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) = .{};
12135 defer record.deinit(self.gpa);12852 defer record.deinit(self.gpa);
1213612853
12137 // IDENTIFICATION_BLOCK12854 // IDENTIFICATION_BLOCK
12138 {12855 {
12139 const Identification = IR.Identification;12856 const Identification = ir.Identification;
12140 var identification_block = try bitcode.enterTopBlock(Identification);12857 var identification_block = try bitcode.enterTopBlock(Identification);
1214112858
12142 const producer = try std.fmt.allocPrint(self.gpa, "zig {d}.{d}.{d}", .{12859 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...@@ -12154,7 +12871,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1215412871
12155 // MODULE_BLOCK12872 // MODULE_BLOCK
12156 {12873 {
12157 const Module = IR.Module;12874 const Module = ir.Module;
12158 var module_block = try bitcode.enterTopBlock(Module);12875 var module_block = try bitcode.enterTopBlock(Module);
1215912876
12160 try module_block.writeAbbrev(Module.Version{});12877 try module_block.writeAbbrev(Module.Version{});
...@@ -12189,16 +12906,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -12189,16 +12906,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1218912906
12190 // TYPE_BLOCK12907 // TYPE_BLOCK
12191 {12908 {
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
12196 for (self.type_items.items, 0..) |item, i| {12913 for (self.type_items.items, 0..) |item, i| {
12197 const ty: Type = @enumFromInt(i);12914 const ty: Type = @enumFromInt(i);
1219812915
12199 switch (item.tag) {12916 switch (item.tag) {
12200 .simple => try type_block.writeAbbrev(IR.Type.Simple{ .code = @truncate(item.data) }),12917 .simple => try type_block.writeAbbrev(ir.Type.Simple{ .code = @truncate(item.data) }),
12201 .integer => try type_block.writeAbbrev(IR.Type.Integer{ .width = item.data }),12918 .integer => try type_block.writeAbbrev(ir.Type.Integer{ .width = item.data }),
12202 .structure,12919 .structure,
12203 .packed_structure,12920 .packed_structure,
12204 => |kind| {12921 => |kind| {
...@@ -12208,14 +12925,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -12208,14 +12925,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
12208 else => unreachable,12925 else => unreachable,
12209 };12926 };
12210 var extra = self.typeExtraDataTrail(Type.Structure, item.data);12927 var extra = self.typeExtraDataTrail(Type.Structure, item.data);
12211 try type_block.writeAbbrev(IR.Type.StructAnon{12928 try type_block.writeAbbrev(ir.Type.StructAnon{
12212 .is_packed = is_packed,12929 .is_packed = is_packed,
12213 .types = extra.trail.next(extra.data.fields_len, Type, self),12930 .types = extra.trail.next(extra.data.fields_len, Type, self),
12214 });12931 });
12215 },12932 },
12216 .named_structure => {12933 .named_structure => {
12217 const extra = self.typeExtraData(Type.NamedStructure, item.data);12934 const extra = self.typeExtraData(Type.NamedStructure, item.data);
12218 try type_block.writeAbbrev(IR.Type.StructName{12935 try type_block.writeAbbrev(ir.Type.StructName{
12219 .string = extra.id.slice(self).?,12936 .string = extra.id.slice(self).?,
12220 });12937 });
1222112938
...@@ -12227,36 +12944,36 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -12227,36 +12944,36 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
12227 };12944 };
1222812945
12229 var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data);12946 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{
12231 .is_packed = is_packed,12948 .is_packed = is_packed,
12232 .types = real_extra.trail.next(real_extra.data.fields_len, Type, self),12949 .types = real_extra.trail.next(real_extra.data.fields_len, Type, self),
12233 });12950 });
12234 },12951 },
12235 .array,12952 .array,
12236 .small_array,12953 .small_array,
12237 => try type_block.writeAbbrev(IR.Type.Array{12954 => try type_block.writeAbbrev(ir.Type.Array{
12238 .len = ty.aggregateLen(self),12955 .len = ty.aggregateLen(self),
12239 .child = ty.childType(self),12956 .child = ty.childType(self),
12240 }),12957 }),
12241 .vector,12958 .vector,
12242 .scalable_vector,12959 .scalable_vector,
12243 => try type_block.writeAbbrev(IR.Type.Vector{12960 => try type_block.writeAbbrev(ir.Type.Vector{
12244 .len = ty.aggregateLen(self),12961 .len = ty.aggregateLen(self),
12245 .child = ty.childType(self),12962 .child = ty.childType(self),
12246 }),12963 }),
12247 .pointer => try type_block.writeAbbrev(IR.Type.Pointer{12964 .pointer => try type_block.writeAbbrev(ir.Type.Pointer{
12248 .addr_space = ty.pointerAddrSpace(self),12965 .addr_space = ty.pointerAddrSpace(self),
12249 }),12966 }),
12250 .target => {12967 .target => {
12251 var extra = self.typeExtraDataTrail(Type.Target, item.data);12968 var extra = self.typeExtraDataTrail(Type.Target, item.data);
12252 try type_block.writeAbbrev(IR.Type.StructName{12969 try type_block.writeAbbrev(ir.Type.StructName{
12253 .string = extra.data.name.slice(self).?,12970 .string = extra.data.name.slice(self).?,
12254 });12971 });
1225512972
12256 const types = extra.trail.next(extra.data.types_len, Type, self);12973 const types = extra.trail.next(extra.data.types_len, Type, self);
12257 const ints = extra.trail.next(extra.data.ints_len, u32, self);12974 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{
12260 .num_types = extra.data.types_len,12977 .num_types = extra.data.types_len,
12261 .types = types,12978 .types = types,
12262 .ints = ints,12979 .ints = ints,
...@@ -12269,7 +12986,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -12269,7 +12986,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
12269 else => unreachable,12986 else => unreachable,
12270 };12987 };
12271 var extra = self.typeExtraDataTrail(Type.Function, item.data);12988 var extra = self.typeExtraDataTrail(Type.Function, item.data);
12272 try type_block.writeAbbrev(IR.Type.Function{12989 try type_block.writeAbbrev(ir.Type.Function{
12273 .is_vararg = is_vararg,12990 .is_vararg = is_vararg,
12274 .return_type = extra.data.ret,12991 .return_type = extra.data.ret,
12275 .param_types = extra.trail.next(extra.data.params_len, Type, self),12992 .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...@@ -12289,7 +13006,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1228913006
12290 // PARAMATTR_GROUP_BLOCK13007 // PARAMATTR_GROUP_BLOCK
12291 {13008 {
12292 const ParamattrGroup = IR.ParamattrGroup;13009 const ParamattrGroup = ir.ParamattrGroup;
1229313010
12294 var paramattr_group_block = try module_block.enterSubBlock(ParamattrGroup);13011 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...@@ -12493,7 +13210,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1249313210
12494 // PARAMATTR_BLOCK13211 // PARAMATTR_BLOCK
12495 {13212 {
12496 const Paramattr = IR.Paramattr;13213 const Paramattr = ir.Paramattr;
12497 var paramattr_block = try module_block.enterSubBlock(Paramattr);13214 var paramattr_block = try module_block.enterSubBlock(Paramattr);
1249813215
12499 for (self.function_attributes_set.keys()) |func_attributes| {13216 for (self.function_attributes_set.keys()) |func_attributes| {
...@@ -12517,7 +13234,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -12517,7 +13234,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
12517 try paramattr_block.end();13234 try paramattr_block.end();
12518 }13235 }
1251913236
12520 var globals = std.AutoArrayHashMapUnmanaged(Global.Index, void){};13237 var globals: std.AutoArrayHashMapUnmanaged(Global.Index, void) = .{};
12521 defer globals.deinit(self.gpa);13238 defer globals.deinit(self.gpa);
12522 try globals.ensureUnusedCapacity(13239 try globals.ensureUnusedCapacity(
12523 self.gpa,13240 self.gpa,
...@@ -12696,7 +13413,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -12696,7 +13413,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1269613413
12697 // CONSTANTS_BLOCK13414 // CONSTANTS_BLOCK
12698 {13415 {
12699 const Constants = IR.Constants;13416 const Constants = ir.Constants;
12700 var constants_block = try module_block.enterSubBlock(Constants);13417 var constants_block = try module_block.enterSubBlock(Constants);
1270113418
12702 var current_type: Type = .none;13419 var current_type: Type = .none;
...@@ -12725,7 +13442,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -12725,7 +13442,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
12725 @ptrCast(self.constant_limbs.items[data..][0..Constant.Integer.limbs]);13442 @ptrCast(self.constant_limbs.items[data..][0..Constant.Integer.limbs]);
12726 const limbs = self.constant_limbs13443 const limbs = self.constant_limbs
12727 .items[data + Constant.Integer.limbs ..][0..extra.limbs_len];13444 .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 = .{
12729 .limbs = limbs,13446 .limbs = limbs,
12730 .positive = tag == .positive_integer,13447 .positive = tag == .positive_integer,
12731 };13448 };
...@@ -13062,7 +13779,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13062,7 +13779,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1306213779
13063 // METADATA_BLOCK13780 // METADATA_BLOCK
13064 if (!self.strip) {13781 if (!self.strip) {
13065 const MetadataBlock = IR.MetadataBlock;13782 const MetadataBlock = ir.MetadataBlock;
13066 var metadata_block = try module_block.enterSubBlock(MetadataBlock);13783 var metadata_block = try module_block.enterSubBlock(MetadataBlock);
1306713784
13068 const MetadataBlockWriter = @TypeOf(metadata_block);13785 const MetadataBlockWriter = @TypeOf(metadata_block);
...@@ -13115,50 +13832,45 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13115,50 +13832,45 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13115 try bitcode.alignTo32();13832 try bitcode.alignTo32();
13116 }13833 }
1311713834
13118 for (1..self.metadata_items.len) |metadata_index| {13835 for (
13119 const tag = self.metadata_items.items(.tag)[metadata_index];13836 self.metadata_items.items(.tag)[1..],
13120 const data = self.metadata_items.items(.data)[metadata_index];13837 self.metadata_items.items(.data)[1..],
13838 ) |tag, data| {
13121 switch (tag) {13839 switch (tag) {
13122 .none => unreachable,13840 .none => unreachable,
13123 .file => {13841 .file => {
13124 const extra = self.metadataExtraData(Metadata.File, data);13842 const extra = self.metadataExtraData(Metadata.File, data);
1312513843
13126 try metadata_block.writeAbbrevAdapted(MetadataBlock.File{13844 try metadata_block.writeAbbrevAdapted(MetadataBlock.File{
13127 .name = extra.name,13845 .filename = extra.filename,
13128 .path = extra.path,13846 .directory = extra.directory,
13129 }, metadata_adapter);13847 }, metadata_adapter);
13130 },13848 },
13131 .compile_unit, .@"compile_unit optimized" => |kind| {13849 .compile_unit,
13132 const is_optimized = kind == .@"compile_unit optimized";13850 .@"compile_unit optimized",
13851 => |kind| {
13133 const extra = self.metadataExtraData(Metadata.CompileUnit, data);13852 const extra = self.metadataExtraData(Metadata.CompileUnit, data);
13134 try metadata_block.writeAbbrevAdapted(MetadataBlock.CompileUnit{13853 try metadata_block.writeAbbrevAdapted(MetadataBlock.CompileUnit{
13135 .file = extra.file,13854 .file = extra.file,
13136 .producer = extra.producer,13855 .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 },
13138 .enums = extra.enums,13861 .enums = extra.enums,
13139 .globals = extra.globals,13862 .globals = extra.globals,
13140 }, metadata_adapter);13863 }, metadata_adapter);
13141 },13864 },
13142 .subprogram,13865 .subprogram,
13143 .@"subprogram optimized",
13144 .@"subprogram local",13866 .@"subprogram local",
13145 .@"subprogram definition",13867 .@"subprogram definition",
13868 .@"subprogram local definition",
13869 .@"subprogram optimized",
13146 .@"subprogram optimized local",13870 .@"subprogram optimized local",
13147 .@"subprogram optimized definition",13871 .@"subprogram optimized definition",
13148 .@"subprogram optimized local definition",13872 .@"subprogram optimized local definition",
13149 .@"subprogram local definition",
13150 => |kind| {13873 => |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 };
13162 const extra = self.metadataExtraData(Metadata.Subprogram, data);13874 const extra = self.metadataExtraData(Metadata.Subprogram, data);
1316313875
13164 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{13876 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{
...@@ -13167,10 +13879,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13167,10 +13879,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13167 .linkage_name = extra.linkage_name,13879 .linkage_name = extra.linkage_name,
13168 .file = extra.file,13880 .file = extra.file,
13169 .line = extra.line,13881 .line = extra.line,
13170 .ty = Metadata.none, //extra.ty,13882 .ty = .none, //extra.ty,
13171 .scope_line = extra.scope_line,13883 .scope_line = extra.scope_line,
13172 .sp_flags = sp_flags,13884 .sp_flags = @bitCast(@as(u32, @as(u3, @intCast(
13173 .flags = extra.debug_info_flags,13885 @intFromEnum(kind) - @intFromEnum(Metadata.Tag.subprogram),
13886 ))) << 2),
13887 .flags = extra.di_flags,
13174 .compile_unit = extra.compile_unit,13888 .compile_unit = extra.compile_unit,
13175 }, metadata_adapter);13889 }, metadata_adapter);
13176 },13890 },
...@@ -13185,7 +13899,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13185,7 +13899,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13185 },13899 },
13186 .location => {13900 .location => {
13187 const extra = self.metadataExtraData(Metadata.Location, data);13901 const extra = self.metadataExtraData(Metadata.Location, data);
13188 std.debug.assert(extra.scope != Metadata.none);13902 std.debug.assert(extra.scope != .none);
13189 try metadata_block.writeAbbrev(MetadataBlock.Location{13903 try metadata_block.writeAbbrev(MetadataBlock.Location{
13190 .line = extra.line,13904 .line = extra.line,
13191 .column = extra.column,13905 .column = extra.column,
...@@ -13201,12 +13915,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13201,12 +13915,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13201 const extra = self.metadataExtraData(Metadata.BasicType, data);13915 const extra = self.metadataExtraData(Metadata.BasicType, data);
13202 try metadata_block.writeAbbrevAdapted(MetadataBlock.BasicType{13916 try metadata_block.writeAbbrevAdapted(MetadataBlock.BasicType{
13203 .name = extra.name,13917 .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(),
13205 .encoding = switch (kind) {13919 .encoding = switch (kind) {
13206 .basic_bool_type => std.dwarf.ATE.boolean,13920 .basic_bool_type => DW.ATE.boolean,
13207 .basic_unsigned_type => std.dwarf.ATE.unsigned,13921 .basic_unsigned_type => DW.ATE.unsigned,
13208 .basic_signed_type => std.dwarf.ATE.signed,13922 .basic_signed_type => DW.ATE.signed,
13209 .basic_float_type => std.dwarf.ATE.float,13923 .basic_float_type => DW.ATE.float,
13210 else => unreachable,13924 else => unreachable,
13211 },13925 },
13212 }, metadata_adapter);13926 }, metadata_adapter);
...@@ -13221,12 +13935,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13221,12 +13935,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1322113935
13222 try metadata_block.writeAbbrevAdapted(MetadataBlock.CompositeType{13936 try metadata_block.writeAbbrevAdapted(MetadataBlock.CompositeType{
13223 .tag = switch (kind) {13937 .tag = switch (kind) {
13224 .composite_struct_type => std.dwarf.TAG.structure_type,13938 .composite_struct_type => DW.TAG.structure_type,
13225 .composite_union_type => std.dwarf.TAG.union_type,13939 .composite_union_type => DW.TAG.union_type,
13226 .composite_enumeration_type => std.dwarf.TAG.enumeration_type,13940 .composite_enumeration_type => DW.TAG.enumeration_type,
13227 .composite_array_type,13941 .composite_array_type, .composite_vector_type => DW.TAG.array_type,
13228 .composite_vector_type,
13229 => std.dwarf.TAG.array_type,
13230 else => unreachable,13942 else => unreachable,
13231 },13943 },
13232 .name = extra.name,13944 .name = extra.name,
...@@ -13234,9 +13946,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13234,9 +13946,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13234 .line = extra.line,13946 .line = extra.line,
13235 .scope = extra.scope,13947 .scope = extra.scope,
13236 .underlying_type = extra.underlying_type,13948 .underlying_type = extra.underlying_type,
13237 .size_in_bits = @as(u64, extra.size_in_bits_lo) | @as(u64, extra.size_in_bits_hi) << 32,13949 .size_in_bits = extra.bitSize(),
13238 .align_in_bits = @as(u64, extra.align_in_bits_lo) | @as(u64, extra.align_in_bits_hi) << 32,13950 .align_in_bits = extra.bitAlign(),
13239 .flags = if (kind == .composite_vector_type) DIFlags.Vector else 0,13951 .flags = if (kind == .composite_vector_type) .{ .Vector = true } else .{},
13240 .elements = extra.fields_tuple,13952 .elements = extra.fields_tuple,
13241 }, metadata_adapter);13953 }, metadata_adapter);
13242 },13954 },
...@@ -13246,8 +13958,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13246,8 +13958,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13246 const extra = self.metadataExtraData(Metadata.DerivedType, data);13958 const extra = self.metadataExtraData(Metadata.DerivedType, data);
13247 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{13959 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{
13248 .tag = switch (kind) {13960 .tag = switch (kind) {
13249 .derived_pointer_type => std.dwarf.TAG.pointer_type,13961 .derived_pointer_type => DW.TAG.pointer_type,
13250 .derived_member_type => std.dwarf.TAG.member,13962 .derived_member_type => DW.TAG.member,
13251 else => unreachable,13963 else => unreachable,
13252 },13964 },
13253 .name = extra.name,13965 .name = extra.name,
...@@ -13255,9 +13967,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13255,9 +13967,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13255 .line = extra.line,13967 .line = extra.line,
13256 .scope = extra.scope,13968 .scope = extra.scope,
13257 .underlying_type = extra.underlying_type,13969 .underlying_type = extra.underlying_type,
13258 .size_in_bits = @as(u64, extra.size_in_bits_lo) | @as(u64, extra.size_in_bits_hi) << 32,13970 .size_in_bits = extra.bitSize(),
13259 .align_in_bits = @as(u64, extra.align_in_bits_lo) | @as(u64, extra.align_in_bits_hi) << 32,13971 .align_in_bits = extra.bitAlign(),
13260 .offset_in_bits = @as(u64, extra.offset_in_bits_lo) | @as(u64, extra.offset_in_bits_hi) << 32,13972 .offset_in_bits = extra.bitOffset(),
13261 }, metadata_adapter);13973 }, metadata_adapter);
13262 },13974 },
13263 .subroutine_type => {13975 .subroutine_type => {
...@@ -13291,7 +14003,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13291,7 +14003,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1329114003
13292 const limbs = self.metadata_limbs.items[extra.limbs_index..][0..extra.limbs_len];14004 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 = .{
13295 .limbs = limbs,14007 .limbs = limbs,
13296 .positive = positive,14008 .positive = positive,
13297 };14009 };
...@@ -13315,7 +14027,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13315,7 +14027,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13315 const word_count = std.mem.alignForward(u32, extra.bit_width, 64) / 64;14027 const word_count = std.mem.alignForward(u32, extra.bit_width, 64) / 64;
13316 try record.ensureUnusedCapacity(self.gpa, 3 + word_count);14028 try record.ensureUnusedCapacity(self.gpa, 3 + word_count);
1331714029
13318 const flags = MetadataBlock.Enumerator.Flags{14030 const flags: MetadataBlock.Enumerator.Flags = .{
13319 .unsigned = unsigned,14031 .unsigned = unsigned,
13320 .bigint = true,14032 .bigint = true,
13321 };14033 };
...@@ -13375,7 +14087,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13375,7 +14087,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13375 const extra = self.metadataExtraData(Metadata.ModuleFlag, data);14087 const extra = self.metadataExtraData(Metadata.ModuleFlag, data);
13376 try metadata_block.writeAbbrev(MetadataBlock.Node{14088 try metadata_block.writeAbbrev(MetadataBlock.Node{
13377 .elements = &.{14089 .elements = &.{
13378 @enumFromInt(metadata_adapter.getMetadataIndex(extra.behaviour)),14090 @enumFromInt(metadata_adapter.getMetadataIndex(extra.behavior)),
13379 @enumFromInt(metadata_adapter.getMetadataStringIndex(extra.name)),14091 @enumFromInt(metadata_adapter.getMetadataStringIndex(extra.name)),
13380 @enumFromInt(metadata_adapter.getMetadataIndex(extra.constant)),14092 @enumFromInt(metadata_adapter.getMetadataIndex(extra.constant)),
13381 },14093 },
...@@ -13534,7 +14246,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13534,7 +14246,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13534 };14246 };
1353514247
13536 for (self.functions.items, 0..) |func, func_index| {14248 for (self.functions.items, 0..) |func, func_index| {
13537 const FunctionBlock = IR.FunctionBlock;14249 const FunctionBlock = ir.FunctionBlock;
13538 if (func.global.getReplacement(self) != .none) continue;14250 if (func.global.getReplacement(self) != .none) continue;
1353914251
13540 if (func.instructions.len == 0) continue;14252 if (func.instructions.len == 0) continue;
...@@ -13547,7 +14259,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13547,7 +14259,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1354714259
13548 // Emit function level metadata block14260 // Emit function level metadata block
13549 if (!self.strip and func.debug_values.len != 0) {14261 if (!self.strip and func.debug_values.len != 0) {
13550 const MetadataBlock = IR.FunctionMetadataBlock;14262 const MetadataBlock = ir.FunctionMetadataBlock;
13551 var metadata_block = try function_block.enterSubBlock(MetadataBlock);14263 var metadata_block = try function_block.enterSubBlock(MetadataBlock);
1355214264
13553 for (func.debug_values) |value| {14265 for (func.debug_values) |value| {
...@@ -13656,10 +14368,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13656,10 +14368,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13656 .srem,14368 .srem,
13657 .ashr,14369 .ashr,
13658 .@"ashr exact",14370 .@"ashr exact",
13659 => {14371 => |kind| {
13660 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14372 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
13661 try function_block.writeAbbrev(FunctionBlock.Binary{14373 try function_block.writeAbbrev(FunctionBlock.Binary{
13662 .opcode = tag.toBinaryOpcode(),14374 .opcode = kind.toBinaryOpcode(),
13663 .lhs = adapter.getOffsetValueIndex(extra.lhs),14375 .lhs = adapter.getOffsetValueIndex(extra.lhs),
13664 .rhs = adapter.getOffsetValueIndex(extra.rhs),14376 .rhs = adapter.getOffsetValueIndex(extra.rhs),
13665 });14377 });
...@@ -13669,10 +14381,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13669,10 +14381,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13669 .@"fmul fast",14381 .@"fmul fast",
13670 .@"frem fast",14382 .@"frem fast",
13671 .@"fsub fast",14383 .@"fsub fast",
13672 => {14384 => |kind| {
13673 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14385 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
13674 try function_block.writeAbbrev(FunctionBlock.BinaryFast{14386 try function_block.writeAbbrev(FunctionBlock.BinaryFast{
13675 .opcode = tag.toBinaryOpcode(),14387 .opcode = kind.toBinaryOpcode(),
13676 .lhs = adapter.getOffsetValueIndex(extra.lhs),14388 .lhs = adapter.getOffsetValueIndex(extra.lhs),
13677 .rhs = adapter.getOffsetValueIndex(extra.rhs),14389 .rhs = adapter.getOffsetValueIndex(extra.rhs),
13678 .fast_math = .{},14390 .fast_math = .{},
...@@ -13709,12 +14421,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13709,12 +14421,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13709 .fpext,14421 .fpext,
13710 .sext,14422 .sext,
13711 .zext,14423 .zext,
13712 => {14424 => |kind| {
13713 const extra = func.extraData(Function.Instruction.Cast, datas[instr_index]);14425 const extra = func.extraData(Function.Instruction.Cast, datas[instr_index]);
13714 try function_block.writeAbbrev(FunctionBlock.Cast{14426 try function_block.writeAbbrev(FunctionBlock.Cast{
13715 .val = adapter.getOffsetValueIndex(extra.val),14427 .val = adapter.getOffsetValueIndex(extra.val),
13716 .type_index = extra.type,14428 .type_index = extra.type,
13717 .opcode = tag.toCastOpcode(),14429 .opcode = kind.toCastOpcode(),
13718 });14430 });
13719 },14431 },
13720 .@"fcmp false",14432 .@"fcmp false",
...@@ -13743,12 +14455,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13743,12 +14455,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13743 .@"icmp ugt",14455 .@"icmp ugt",
13744 .@"icmp ule",14456 .@"icmp ule",
13745 .@"icmp ult",14457 .@"icmp ult",
13746 => {14458 => |kind| {
13747 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14459 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
13748 try function_block.writeAbbrev(FunctionBlock.Cmp{14460 try function_block.writeAbbrev(FunctionBlock.Cmp{
13749 .lhs = adapter.getOffsetValueIndex(extra.lhs),14461 .lhs = adapter.getOffsetValueIndex(extra.lhs),
13750 .rhs = adapter.getOffsetValueIndex(extra.rhs),14462 .rhs = adapter.getOffsetValueIndex(extra.rhs),
13751 .pred = tag.toCmpPredicate(),14463 .pred = kind.toCmpPredicate(),
13752 });14464 });
13753 },14465 },
13754 .@"fcmp fast false",14466 .@"fcmp fast false",
...@@ -13767,12 +14479,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13767,12 +14479,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13767 .@"fcmp fast ult",14479 .@"fcmp fast ult",
13768 .@"fcmp fast une",14480 .@"fcmp fast une",
13769 .@"fcmp fast uno",14481 .@"fcmp fast uno",
13770 => {14482 => |kind| {
13771 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);14483 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
13772 try function_block.writeAbbrev(FunctionBlock.CmpFast{14484 try function_block.writeAbbrev(FunctionBlock.CmpFast{
13773 .lhs = adapter.getOffsetValueIndex(extra.lhs),14485 .lhs = adapter.getOffsetValueIndex(extra.lhs),
13774 .rhs = adapter.getOffsetValueIndex(extra.rhs),14486 .rhs = adapter.getOffsetValueIndex(extra.rhs),
13775 .pred = tag.toCmpPredicate(),14487 .pred = kind.toCmpPredicate(),
13776 .fast_math = .{},14488 .fast_math = .{},
13777 });14489 });
13778 },14490 },
...@@ -13842,12 +14554,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13842,12 +14554,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13842 },14554 },
13843 .getelementptr,14555 .getelementptr,
13844 .@"getelementptr inbounds",14556 .@"getelementptr inbounds",
13845 => {14557 => |kind| {
13846 var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, datas[instr_index]);14558 var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, datas[instr_index]);
13847 const indices = extra.trail.next(extra.data.indices_len, Value, &func);14559 const indices = extra.trail.next(extra.data.indices_len, Value, &func);
13848 try function_block.writeAbbrevAdapted(14560 try function_block.writeAbbrevAdapted(
13849 FunctionBlock.GetElementPtr{14561 FunctionBlock.GetElementPtr{
13850 .is_inbounds = tag == .@"getelementptr inbounds",14562 .is_inbounds = kind == .@"getelementptr inbounds",
13851 .type_index = extra.data.type,14563 .type_index = extra.data.type,
13852 .base = extra.data.base,14564 .base = extra.data.base,
13853 .indices = indices,14565 .indices = indices,
...@@ -14008,13 +14720,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14008,13 +14720,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14008 }14720 }
1400914721
14010 if (!self.strip) {14722 if (!self.strip) {
14011 if (func.debug_locations.get(@enumFromInt(instr_index))) |maybe_location| {14723 if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| {
14012 if (maybe_location) |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);
14013 try function_block.writeAbbrev(FunctionBlock.DebugLoc{14728 try function_block.writeAbbrev(FunctionBlock.DebugLoc{
14014 .line = location.line,14729 .line = extra.line,
14015 .column = location.column,14730 .column = extra.column,
14016 .scope = @enumFromInt(metadata_adapter.getMetadataIndex(location.scope)),14731 .scope = @enumFromInt(metadata_adapter.getMetadataIndex(extra.scope)),
14017 .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(location.inlined_at)),14732 .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(extra.inlined_at)),
14018 .is_implicit = false,14733 .is_implicit = false,
14019 });14734 });
14020 has_location = true;14735 has_location = true;
...@@ -14031,7 +14746,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14031,7 +14746,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1403114746
14032 // VALUE_SYMTAB14747 // VALUE_SYMTAB
14033 if (!self.strip) {14748 if (!self.strip) {
14034 const ValueSymbolTable = IR.FunctionValueSymbolTable;14749 const ValueSymbolTable = ir.FunctionValueSymbolTable;
1403514750
14036 var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable);14751 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...@@ -14060,7 +14775,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1406014775
14061 // STRTAB_BLOCK14776 // STRTAB_BLOCK
14062 {14777 {
14063 const Strtab = IR.Strtab;14778 const Strtab = ir.Strtab;
14064 var strtab_block = try bitcode.enterTopBlock(Strtab);14779 var strtab_block = try bitcode.enterTopBlock(Strtab);
1406514780
14066 try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.string_bytes.items });14781 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...@@ -14071,14 +14786,13 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14071 return bitcode.toSlice();14786 return bitcode.toSlice();
14072}14787}
1407314788
14789const Allocator = std.mem.Allocator;
14074const assert = std.debug.assert;14790const assert = std.debug.assert;
14791const bitcode_writer = @import("bitcode_writer.zig");
14075const build_options = @import("build_options");14792const build_options = @import("build_options");
14793const Builder = @This();
14076const builtin = @import("builtin");14794const builtin = @import("builtin");
14795const DW = std.dwarf;
14796const ir = @import("ir.zig");
14077const log = std.log.scoped(.llvm);14797const log = std.log.scoped(.llvm);
14078const std = @import("std");14798const 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};