authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-08-02 16:48:36+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-13 12:16:17-07:00
loge3b79d65d808700d6308996a52186dcb3ff48b06
tree2f9cfb6132af939dae78e58c6ffbea874d993da5
parente7b18a7ce69f30c85f21ec8ad6a70211abf5f24b

LLVM: Move pt field from Object to NavGen

* LLVM: Pass correct tid to emit * Store stack trace type in Zcu * Don't use pt.errorIntType in LLVM backend

5 files changed, 639 insertions(+), 612 deletions(-)

src/Compilation.zig+1-1
......@@ -3042,7 +3042,7 @@ fn flush(
30423042 // If there's an output file, it wants to decide where the LLVM object goes!
30433043 const sub_prog_node = comp.link_prog_node.start("LLVM Emit Object", 0);
30443044 defer sub_prog_node.end();
3045 try llvm_object.emit(.{
3045 try llvm_object.emit(.{ .zcu = zcu, .tid = tid }, .{
30463046 .pre_ir_path = comp.verbose_llvm_ir,
30473047 .pre_bc_path = comp.verbose_llvm_bc,
30483048
src/Sema.zig+2
......@@ -9916,6 +9916,8 @@ fn finishFunc(
99169916 // lower this fn type.
99179917 const unresolved_stack_trace_ty = try sema.getBuiltinType(block.nodeOffset(.zero), .StackTrace);
99189918 try unresolved_stack_trace_ty.resolveFields(pt);
9919
9920 if (zcu.stack_trace_type == .none) zcu.stack_trace_type = unresolved_stack_trace_ty.toIntern();
99199921 }
99209922
99219923 return Air.internedToRef(if (opt_func_index != .none) opt_func_index else func_ty);
src/Zcu.zig+1
......@@ -308,6 +308,7 @@ free_type_references: std.ArrayListUnmanaged(u32) = .empty,
308308
309309/// Populated by analysis of `AnalUnit.wrap(.{ .memoized_state = s })`, where `s` depends on the element.
310310builtin_decl_values: BuiltinDecl.Memoized = .initFill(.none),
311stack_trace_type: InternPool.Index = .none,
311312
312313incremental_debug_state: if (build_options.enable_debug_extensions) IncrementalDebugState else void =
313314 if (build_options.enable_debug_extensions) .init else {},
src/codegen/llvm.zig+633-610
......@@ -494,8 +494,6 @@ pub const Object = struct {
494494 gpa: Allocator,
495495 builder: Builder,
496496
497 pt: Zcu.PerThread,
498
499497 debug_compile_unit: Builder.Metadata,
500498
501499 debug_enums_fwd_ref: Builder.Metadata,
......@@ -626,10 +624,6 @@ pub const Object = struct {
626624 obj.* = .{
627625 .gpa = gpa,
628626 .builder = builder,
629 .pt = .{
630 .zcu = comp.zcu.?,
631 .tid = .main,
632 },
633627 .debug_compile_unit = debug_compile_unit,
634628 .debug_enums_fwd_ref = debug_enums_fwd_ref,
635629 .debug_globals_fwd_ref = debug_globals_fwd_ref,
......@@ -669,11 +663,10 @@ pub const Object = struct {
669663 self.* = undefined;
670664 }
671665
672 fn genErrorNameTable(o: *Object) Allocator.Error!void {
666 fn genErrorNameTable(o: *Object, pt: Zcu.PerThread) Allocator.Error!void {
673667 // If o.error_name_table is null, then it was not referenced by any instructions.
674668 if (o.error_name_table == .none) return;
675669
676 const pt = o.pt;
677670 const zcu = pt.zcu;
678671 const ip = &zcu.intern_pool;
679672
......@@ -683,8 +676,8 @@ pub const Object = struct {
683676
684677 // TODO: Address space
685678 const slice_ty = Type.slice_const_u8_sentinel_0;
686 const llvm_usize_ty = try o.lowerType(Type.usize);
687 const llvm_slice_ty = try o.lowerType(slice_ty);
679 const llvm_usize_ty = try o.lowerType(pt, Type.usize);
680 const llvm_slice_ty = try o.lowerType(pt, slice_ty);
688681 const llvm_table_ty = try o.builder.arrayType(1 + error_name_list.len, llvm_slice_ty);
689682
690683 llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty);
......@@ -721,11 +714,11 @@ pub const Object = struct {
721714 try o.error_name_table.setInitializer(table_variable_index.toConst(&o.builder), &o.builder);
722715 }
723716
724 fn genCmpLtErrorsLenFunction(o: *Object) !void {
717 fn genCmpLtErrorsLenFunction(o: *Object, pt: Zcu.PerThread) !void {
725718 // If there is no such function in the module, it means the source code does not need it.
726719 const name = o.builder.strtabStringIfExists(lt_errors_fn_name) orelse return;
727720 const llvm_fn = o.builder.getGlobal(name) orelse return;
728 const errors_len = o.pt.zcu.intern_pool.global_error_set.getNamesFromMainThread().len;
721 const errors_len = pt.zcu.intern_pool.global_error_set.getNamesFromMainThread().len;
729722
730723 var wip = try Builder.WipFunction.init(&o.builder, .{
731724 .function = llvm_fn.ptrConst(&o.builder).kind.function,
......@@ -740,17 +733,17 @@ pub const Object = struct {
740733 // }
741734
742735 const lhs = wip.arg(0);
743 const rhs = try o.builder.intValue(try o.errorIntType(), errors_len);
736 const rhs = try o.builder.intValue(try o.errorIntType(pt), errors_len);
744737 const is_lt = try wip.icmp(.ule, lhs, rhs, "");
745738 _ = try wip.ret(is_lt);
746739 try wip.finish();
747740 }
748741
749 fn genModuleLevelAssembly(object: *Object) Allocator.Error!void {
742 fn genModuleLevelAssembly(object: *Object, pt: Zcu.PerThread) Allocator.Error!void {
750743 const b = &object.builder;
751744 const gpa = b.gpa;
752745 b.module_asm.clearRetainingCapacity();
753 for (object.pt.zcu.global_assembly.values()) |assembly| {
746 for (pt.zcu.global_assembly.values()) |assembly| {
754747 try b.module_asm.ensureUnusedCapacity(gpa, assembly.len + 1);
755748 b.module_asm.appendSliceAssumeCapacity(assembly);
756749 b.module_asm.appendAssumeCapacity('\n');
......@@ -776,15 +769,15 @@ pub const Object = struct {
776769 lto: std.zig.LtoMode,
777770 };
778771
779 pub fn emit(o: *Object, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void {
780 const zcu = o.pt.zcu;
772 pub fn emit(o: *Object, pt: Zcu.PerThread, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void {
773 const zcu = pt.zcu;
781774 const comp = zcu.comp;
782775 const diags = &comp.link_diags;
783776
784777 {
785 try o.genErrorNameTable();
786 try o.genCmpLtErrorsLenFunction();
787 try o.genModuleLevelAssembly();
778 try o.genErrorNameTable(pt);
779 try o.genCmpLtErrorsLenFunction(pt);
780 try o.genModuleLevelAssembly(pt);
788781
789782 if (o.used.items.len > 0) {
790783 const array_llvm_ty = try o.builder.arrayType(o.used.items.len, .ptr);
......@@ -807,7 +800,7 @@ pub const Object = struct {
807800 const fwd_ref = o.debug_unresolved_namespace_scopes.values()[i];
808801
809802 const namespace = zcu.namespacePtr(namespace_index);
810 const debug_type = try o.lowerDebugType(Type.fromInterned(namespace.owner_type));
803 const debug_type = try o.lowerDebugType(pt, Type.fromInterned(namespace.owner_type));
811804
812805 o.builder.debugForwardReferenceSetType(fwd_ref, debug_type);
813806 }
......@@ -1140,7 +1133,6 @@ pub const Object = struct {
11401133 air: *const Air,
11411134 liveness: *const Air.Liveness,
11421135 ) !void {
1143 assert(std.meta.eql(pt, o.pt));
11441136 const zcu = pt.zcu;
11451137 const comp = zcu.comp;
11461138 const ip = &zcu.intern_pool;
......@@ -1155,10 +1147,11 @@ pub const Object = struct {
11551147 var ng: NavGen = .{
11561148 .object = o,
11571149 .nav_index = func.owner_nav,
1150 .pt = pt,
11581151 .err_msg = null,
11591152 };
11601153
1161 const function_index = try o.resolveLlvmFunction(func.owner_nav);
1154 const function_index = try o.resolveLlvmFunction(pt, func.owner_nav);
11621155
11631156 var attributes = try function_index.ptrConst(&o.builder).attributes.toWip(&o.builder);
11641157 defer attributes.deinit(&o.builder);
......@@ -1272,7 +1265,7 @@ pub const Object = struct {
12721265 defer args.deinit(gpa);
12731266
12741267 {
1275 var it = iterateParamTypes(o, fn_info);
1268 var it = iterateParamTypes(o, pt, fn_info);
12761269 while (try it.next()) |lowering| {
12771270 try args.ensureUnusedCapacity(gpa, 1);
12781271
......@@ -1293,13 +1286,13 @@ pub const Object = struct {
12931286 } else {
12941287 args.appendAssumeCapacity(param);
12951288
1296 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, llvm_arg_i);
1289 try o.addByValParamAttrs(pt, &attributes, param_ty, param_index, fn_info, llvm_arg_i);
12971290 }
12981291 llvm_arg_i += 1;
12991292 },
13001293 .byref => {
13011294 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
1302 const param_llvm_ty = try o.lowerType(param_ty);
1295 const param_llvm_ty = try o.lowerType(pt, param_ty);
13031296 const param = wip.arg(llvm_arg_i);
13041297 const alignment = param_ty.abiAlignment(zcu).toLlvm();
13051298
......@@ -1314,7 +1307,7 @@ pub const Object = struct {
13141307 },
13151308 .byref_mut => {
13161309 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
1317 const param_llvm_ty = try o.lowerType(param_ty);
1310 const param_llvm_ty = try o.lowerType(pt, param_ty);
13181311 const param = wip.arg(llvm_arg_i);
13191312 const alignment = param_ty.abiAlignment(zcu).toLlvm();
13201313
......@@ -1333,7 +1326,7 @@ pub const Object = struct {
13331326 const param = wip.arg(llvm_arg_i);
13341327 llvm_arg_i += 1;
13351328
1336 const param_llvm_ty = try o.lowerType(param_ty);
1329 const param_llvm_ty = try o.lowerType(pt, param_ty);
13371330 const alignment = param_ty.abiAlignment(zcu).toLlvm();
13381331 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);
13391332 _ = try wip.store(.normal, param, arg_ptr, alignment);
......@@ -1372,7 +1365,7 @@ pub const Object = struct {
13721365 const len_param = wip.arg(llvm_arg_i);
13731366 llvm_arg_i += 1;
13741367
1375 const slice_llvm_ty = try o.lowerType(param_ty);
1368 const slice_llvm_ty = try o.lowerType(pt, param_ty);
13761369 args.appendAssumeCapacity(
13771370 try wip.buildAggregate(slice_llvm_ty, &.{ ptr_param, len_param }, ""),
13781371 );
......@@ -1381,7 +1374,7 @@ pub const Object = struct {
13811374 assert(!it.byval_attr);
13821375 const field_types = it.types_buffer[0..it.types_len];
13831376 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
1384 const param_llvm_ty = try o.lowerType(param_ty);
1377 const param_llvm_ty = try o.lowerType(pt, param_ty);
13851378 const param_alignment = param_ty.abiAlignment(zcu).toLlvm();
13861379 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, param_alignment, target);
13871380 const llvm_ty = try o.builder.structType(.normal, field_types);
......@@ -1402,7 +1395,7 @@ pub const Object = struct {
14021395 },
14031396 .float_array => {
14041397 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
1405 const param_llvm_ty = try o.lowerType(param_ty);
1398 const param_llvm_ty = try o.lowerType(pt, param_ty);
14061399 const param = wip.arg(llvm_arg_i);
14071400 llvm_arg_i += 1;
14081401
......@@ -1417,7 +1410,7 @@ pub const Object = struct {
14171410 },
14181411 .i32_array, .i64_array => {
14191412 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
1420 const param_llvm_ty = try o.lowerType(param_ty);
1413 const param_llvm_ty = try o.lowerType(pt, param_ty);
14211414 const param = wip.arg(llvm_arg_i);
14221415 llvm_arg_i += 1;
14231416
......@@ -1435,11 +1428,11 @@ pub const Object = struct {
14351428 }
14361429
14371430 const file, const subprogram = if (!wip.strip) debug_info: {
1438 const file = try o.getDebugFile(file_scope);
1431 const file = try o.getDebugFile(pt, file_scope);
14391432
14401433 const line_number = zcu.navSrcLine(func.owner_nav) + 1;
14411434 const is_internal_linkage = ip.indexToKey(nav.status.fully_resolved.val) != .@"extern";
1442 const debug_decl_type = try o.lowerDebugType(fn_ty);
1435 const debug_decl_type = try o.lowerDebugType(pt, fn_ty);
14431436
14441437 const subprogram = try o.builder.debugSubprogram(
14451438 file,
......@@ -1569,10 +1562,10 @@ pub const Object = struct {
15691562 }
15701563
15711564 pub fn updateNav(self: *Object, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !void {
1572 assert(std.meta.eql(pt, self.pt));
15731565 var ng: NavGen = .{
15741566 .object = self,
15751567 .nav_index = nav_index,
1568 .pt = pt,
15761569 .err_msg = null,
15771570 };
15781571 ng.genDecl() catch |err| switch (err) {
......@@ -1590,11 +1583,10 @@ pub const Object = struct {
15901583 exported: Zcu.Exported,
15911584 export_indices: []const Zcu.Export.Index,
15921585 ) link.File.UpdateExportsError!void {
1593 assert(std.meta.eql(pt, self.pt));
15941586 const zcu = pt.zcu;
15951587 const nav_index = switch (exported) {
15961588 .nav => |nav| nav,
1597 .uav => |uav| return updateExportedValue(self, zcu, uav, export_indices),
1589 .uav => |uav| return updateExportedValue(self, pt, uav, export_indices),
15981590 };
15991591 const ip = &zcu.intern_pool;
16001592 const global_index = self.nav_map.get(nav_index).?;
......@@ -1635,10 +1627,11 @@ pub const Object = struct {
16351627
16361628 fn updateExportedValue(
16371629 o: *Object,
1638 zcu: *Zcu,
1630 pt: Zcu.PerThread,
16391631 exported_value: InternPool.Index,
16401632 export_indices: []const Zcu.Export.Index,
16411633 ) link.File.UpdateExportsError!void {
1634 const zcu = pt.zcu;
16421635 const gpa = zcu.gpa;
16431636 const ip = &zcu.intern_pool;
16441637 const main_exp_name = try o.builder.strtabString(export_indices[0].ptr(zcu).opts.name.toSlice(ip));
......@@ -1652,13 +1645,13 @@ pub const Object = struct {
16521645 const llvm_addr_space = toLlvmAddressSpace(.generic, o.target);
16531646 const variable_index = try o.builder.addVariable(
16541647 main_exp_name,
1655 try o.lowerType(Type.fromInterned(ip.typeOf(exported_value))),
1648 try o.lowerType(pt, Type.fromInterned(ip.typeOf(exported_value))),
16561649 llvm_addr_space,
16571650 );
16581651 const global_index = variable_index.ptrConst(&o.builder).global;
16591652 gop.value_ptr.* = global_index;
16601653 // This line invalidates `gop`.
1661 const init_val = o.lowerValue(exported_value) catch |err| switch (err) {
1654 const init_val = o.lowerValue(pt, exported_value) catch |err| switch (err) {
16621655 error.OutOfMemory => return error.OutOfMemory,
16631656 error.CodegenFail => return error.AnalysisFail,
16641657 };
......@@ -1761,14 +1754,18 @@ pub const Object = struct {
17611754 }
17621755 }
17631756
1764 fn getDebugFile(o: *Object, file_index: Zcu.File.Index) Allocator.Error!Builder.Metadata {
1757 pub fn freeDecl(self: *Object, decl_index: InternPool.DeclIndex) void {
1758 const global = self.decl_map.get(decl_index) orelse return;
1759 global.delete(&self.builder);
1760 }
1761
1762 fn getDebugFile(o: *Object, pt: Zcu.PerThread, file_index: Zcu.File.Index) Allocator.Error!Builder.Metadata {
17651763 const gpa = o.gpa;
17661764 const gop = try o.debug_file_map.getOrPut(gpa, file_index);
17671765 errdefer assert(o.debug_file_map.remove(file_index));
17681766 if (gop.found_existing) return gop.value_ptr.*;
1769 const zcu = o.pt.zcu;
1770 const path = zcu.fileByIndex(file_index).path;
1771 const abs_path = try path.toAbsolute(zcu.comp.dirs, gpa);
1767 const path = pt.zcu.fileByIndex(file_index).path;
1768 const abs_path = try path.toAbsolute(pt.zcu.comp.dirs, gpa);
17721769 defer gpa.free(abs_path);
17731770
17741771 gop.value_ptr.* = try o.builder.debugFile(
......@@ -1780,13 +1777,13 @@ pub const Object = struct {
17801777
17811778 pub fn lowerDebugType(
17821779 o: *Object,
1780 pt: Zcu.PerThread,
17831781 ty: Type,
17841782 ) Allocator.Error!Builder.Metadata {
17851783 assert(!o.builder.strip);
17861784
17871785 const gpa = o.gpa;
17881786 const target = o.target;
1789 const pt = o.pt;
17901787 const zcu = pt.zcu;
17911788 const ip = &zcu.intern_pool;
17921789
......@@ -1806,7 +1803,7 @@ pub const Object = struct {
18061803 .int => {
18071804 const info = ty.intInfo(zcu);
18081805 assert(info.bits != 0);
1809 const name = try o.allocTypeName(ty);
1806 const name = try o.allocTypeName(pt, ty);
18101807 defer gpa.free(name);
18111808 const builder_name = try o.builder.metadataString(name);
18121809 const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types
......@@ -1819,7 +1816,7 @@ pub const Object = struct {
18191816 },
18201817 .@"enum" => {
18211818 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1822 const debug_enum_type = try o.makeEmptyNamespaceDebugType(ty);
1819 const debug_enum_type = try o.makeEmptyNamespaceDebugType(pt, ty);
18231820 try o.debug_type_map.put(gpa, ty, debug_enum_type);
18241821 return debug_enum_type;
18251822 }
......@@ -1847,13 +1844,13 @@ pub const Object = struct {
18471844 );
18481845 }
18491846
1850 const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
1847 const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
18511848 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|
1852 try o.namespaceToDebugScope(parent_namespace)
1849 try o.namespaceToDebugScope(pt, parent_namespace)
18531850 else
18541851 file;
18551852
1856 const name = try o.allocTypeName(ty);
1853 const name = try o.allocTypeName(pt, ty);
18571854 defer gpa.free(name);
18581855
18591856 const debug_enum_type = try o.builder.debugEnumerationType(
......@@ -1861,7 +1858,7 @@ pub const Object = struct {
18611858 file,
18621859 scope,
18631860 ty.typeDeclSrcLine(zcu).? + 1, // Line
1864 try o.lowerDebugType(int_ty),
1861 try o.lowerDebugType(pt, int_ty),
18651862 ty.abiSize(zcu) * 8,
18661863 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
18671864 try o.builder.metadataTuple(enumerators),
......@@ -1873,7 +1870,7 @@ pub const Object = struct {
18731870 },
18741871 .float => {
18751872 const bits = ty.floatBits(target);
1876 const name = try o.allocTypeName(ty);
1873 const name = try o.allocTypeName(pt, ty);
18771874 defer gpa.free(name);
18781875 const debug_float_type = try o.builder.debugFloatType(
18791876 try o.builder.metadataString(name),
......@@ -1918,7 +1915,7 @@ pub const Object = struct {
19181915 },
19191916 },
19201917 });
1921 const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty);
1918 const debug_ptr_type = try o.lowerDebugType(pt, bland_ptr_ty);
19221919 try o.debug_type_map.put(gpa, ty, debug_ptr_type);
19231920 return debug_ptr_type;
19241921 }
......@@ -1932,7 +1929,7 @@ pub const Object = struct {
19321929 const ptr_ty = ty.slicePtrFieldType(zcu);
19331930 const len_ty = Type.usize;
19341931
1935 const name = try o.allocTypeName(ty);
1932 const name = try o.allocTypeName(pt, ty);
19361933 defer gpa.free(name);
19371934 const line = 0;
19381935
......@@ -1948,7 +1945,7 @@ pub const Object = struct {
19481945 .none, // File
19491946 debug_fwd_ref,
19501947 0, // Line
1951 try o.lowerDebugType(ptr_ty),
1948 try o.lowerDebugType(pt, ptr_ty),
19521949 ptr_size * 8,
19531950 (ptr_align.toByteUnits() orelse 0) * 8,
19541951 0, // Offset
......@@ -1959,7 +1956,7 @@ pub const Object = struct {
19591956 .none, // File
19601957 debug_fwd_ref,
19611958 0, // Line
1962 try o.lowerDebugType(len_ty),
1959 try o.lowerDebugType(pt, len_ty),
19631960 len_size * 8,
19641961 (len_align.toByteUnits() orelse 0) * 8,
19651962 len_offset * 8,
......@@ -1988,9 +1985,9 @@ pub const Object = struct {
19881985 return debug_slice_type;
19891986 }
19901987
1991 const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child));
1988 const debug_elem_ty = try o.lowerDebugType(pt, Type.fromInterned(ptr_info.child));
19921989
1993 const name = try o.allocTypeName(ty);
1990 const name = try o.allocTypeName(pt, ty);
19941991 defer gpa.free(name);
19951992
19961993 const debug_ptr_type = try o.builder.debugPointerType(
......@@ -2022,12 +2019,12 @@ pub const Object = struct {
20222019 return debug_opaque_type;
20232020 }
20242021
2025 const name = try o.allocTypeName(ty);
2022 const name = try o.allocTypeName(pt, ty);
20262023 defer gpa.free(name);
20272024
2028 const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
2025 const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
20292026 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|
2030 try o.namespaceToDebugScope(parent_namespace)
2027 try o.namespaceToDebugScope(pt, parent_namespace)
20312028 else
20322029 file;
20332030
......@@ -2050,7 +2047,7 @@ pub const Object = struct {
20502047 .none, // File
20512048 .none, // Scope
20522049 0, // Line
2053 try o.lowerDebugType(ty.childType(zcu)),
2050 try o.lowerDebugType(pt, ty.childType(zcu)),
20542051 ty.abiSize(zcu) * 8,
20552052 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
20562053 try o.builder.metadataTuple(&.{
......@@ -2073,7 +2070,7 @@ pub const Object = struct {
20732070 .int => blk: {
20742071 const info = elem_ty.intInfo(zcu);
20752072 assert(info.bits != 0);
2076 const name = try o.allocTypeName(ty);
2073 const name = try o.allocTypeName(pt, ty);
20772074 defer gpa.free(name);
20782075 const builder_name = try o.builder.metadataString(name);
20792076 break :blk switch (info.signedness) {
......@@ -2085,7 +2082,7 @@ pub const Object = struct {
20852082 try o.builder.metadataString("bool"),
20862083 1,
20872084 ),
2088 else => try o.lowerDebugType(ty.childType(zcu)),
2085 else => try o.lowerDebugType(pt, ty.childType(zcu)),
20892086 };
20902087
20912088 const debug_vector_type = try o.builder.debugVectorType(
......@@ -2108,7 +2105,7 @@ pub const Object = struct {
21082105 return debug_vector_type;
21092106 },
21102107 .optional => {
2111 const name = try o.allocTypeName(ty);
2108 const name = try o.allocTypeName(pt, ty);
21122109 defer gpa.free(name);
21132110 const child_ty = ty.optionalChild(zcu);
21142111 if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
......@@ -2126,7 +2123,7 @@ pub const Object = struct {
21262123 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
21272124
21282125 if (ty.optionalReprIsPayload(zcu)) {
2129 const debug_optional_type = try o.lowerDebugType(child_ty);
2126 const debug_optional_type = try o.lowerDebugType(pt, child_ty);
21302127
21312128 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
21322129
......@@ -2149,7 +2146,7 @@ pub const Object = struct {
21492146 .none, // File
21502147 debug_fwd_ref,
21512148 0, // Line
2152 try o.lowerDebugType(child_ty),
2149 try o.lowerDebugType(pt, child_ty),
21532150 payload_size * 8,
21542151 (payload_align.toByteUnits() orelse 0) * 8,
21552152 0, // Offset
......@@ -2160,7 +2157,7 @@ pub const Object = struct {
21602157 .none,
21612158 debug_fwd_ref,
21622159 0,
2163 try o.lowerDebugType(non_null_ty),
2160 try o.lowerDebugType(pt, non_null_ty),
21642161 non_null_size * 8,
21652162 (non_null_align.toByteUnits() orelse 0) * 8,
21662163 non_null_offset * 8,
......@@ -2192,12 +2189,12 @@ pub const Object = struct {
21922189 const payload_ty = ty.errorUnionPayload(zcu);
21932190 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
21942191 // TODO: Maybe remove?
2195 const debug_error_union_type = try o.lowerDebugType(Type.anyerror);
2192 const debug_error_union_type = try o.lowerDebugType(pt, Type.anyerror);
21962193 try o.debug_type_map.put(gpa, ty, debug_error_union_type);
21972194 return debug_error_union_type;
21982195 }
21992196
2200 const name = try o.allocTypeName(ty);
2197 const name = try o.allocTypeName(pt, ty);
22012198 defer gpa.free(name);
22022199
22032200 const error_size = Type.anyerror.abiSize(zcu);
......@@ -2229,7 +2226,7 @@ pub const Object = struct {
22292226 .none, // File
22302227 debug_fwd_ref,
22312228 0, // Line
2232 try o.lowerDebugType(Type.anyerror),
2229 try o.lowerDebugType(pt, Type.anyerror),
22332230 error_size * 8,
22342231 (error_align.toByteUnits() orelse 0) * 8,
22352232 error_offset * 8,
......@@ -2239,7 +2236,7 @@ pub const Object = struct {
22392236 .none, // File
22402237 debug_fwd_ref,
22412238 0, // Line
2242 try o.lowerDebugType(payload_ty),
2239 try o.lowerDebugType(pt, payload_ty),
22432240 payload_size * 8,
22442241 (payload_align.toByteUnits() orelse 0) * 8,
22452242 payload_offset * 8,
......@@ -2270,7 +2267,7 @@ pub const Object = struct {
22702267 return debug_error_set;
22712268 },
22722269 .@"struct" => {
2273 const name = try o.allocTypeName(ty);
2270 const name = try o.allocTypeName(pt, ty);
22742271 defer gpa.free(name);
22752272
22762273 if (zcu.typeToPackedStruct(ty)) |struct_type| {
......@@ -2315,7 +2312,7 @@ pub const Object = struct {
23152312 .none, // File
23162313 debug_fwd_ref,
23172314 0,
2318 try o.lowerDebugType(Type.fromInterned(field_ty)),
2315 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
23192316 field_size * 8,
23202317 (field_align.toByteUnits() orelse 0) * 8,
23212318 field_offset * 8,
......@@ -2347,7 +2344,7 @@ pub const Object = struct {
23472344 // into. Therefore we can satisfy this by making an empty namespace,
23482345 // rather than changing the frontend to unnecessarily resolve the
23492346 // struct field types.
2350 const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty);
2347 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);
23512348 try o.debug_type_map.put(gpa, ty, debug_struct_type);
23522349 return debug_struct_type;
23532350 }
......@@ -2356,7 +2353,7 @@ pub const Object = struct {
23562353 }
23572354
23582355 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2359 const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty);
2356 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);
23602357 try o.debug_type_map.put(gpa, ty, debug_struct_type);
23612358 return debug_struct_type;
23622359 }
......@@ -2388,7 +2385,7 @@ pub const Object = struct {
23882385 .none, // File
23892386 debug_fwd_ref,
23902387 0, // Line
2391 try o.lowerDebugType(field_ty),
2388 try o.lowerDebugType(pt, field_ty),
23922389 field_size * 8,
23932390 (field_align.toByteUnits() orelse 0) * 8,
23942391 field_offset * 8,
......@@ -2415,7 +2412,7 @@ pub const Object = struct {
24152412 return debug_struct_type;
24162413 },
24172414 .@"union" => {
2418 const name = try o.allocTypeName(ty);
2415 const name = try o.allocTypeName(pt, ty);
24192416 defer gpa.free(name);
24202417
24212418 const union_type = ip.loadUnionType(ty.toIntern());
......@@ -2423,7 +2420,7 @@ pub const Object = struct {
24232420 !ty.hasRuntimeBitsIgnoreComptime(zcu) or
24242421 !union_type.haveLayout(ip))
24252422 {
2426 const debug_union_type = try o.makeEmptyNamespaceDebugType(ty);
2423 const debug_union_type = try o.makeEmptyNamespaceDebugType(pt, ty);
24272424 try o.debug_type_map.put(gpa, ty, debug_union_type);
24282425 return debug_union_type;
24292426 }
......@@ -2445,7 +2442,7 @@ pub const Object = struct {
24452442 ty.abiSize(zcu) * 8,
24462443 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
24472444 try o.builder.metadataTuple(
2448 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
2445 &.{try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty))},
24492446 ),
24502447 );
24512448
......@@ -2484,7 +2481,7 @@ pub const Object = struct {
24842481 .none, // File
24852482 debug_union_fwd_ref,
24862483 0, // Line
2487 try o.lowerDebugType(Type.fromInterned(field_ty)),
2484 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
24882485 field_size * 8,
24892486 (field_align.toByteUnits() orelse 0) * 8,
24902487 0, // Offset
......@@ -2534,7 +2531,7 @@ pub const Object = struct {
25342531 .none, // File
25352532 debug_fwd_ref,
25362533 0, // Line
2537 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)),
2534 try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty)),
25382535 layout.tag_size * 8,
25392536 (layout.tag_align.toByteUnits() orelse 0) * 8,
25402537 tag_offset * 8,
......@@ -2588,19 +2585,19 @@ pub const Object = struct {
25882585 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
25892586 const sret = firstParamSRet(fn_info, zcu, target);
25902587 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2591 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
2588 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ret_ty));
25922589
25932590 if (sret) {
25942591 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2595 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2592 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty));
25962593 }
25972594 } else {
2598 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));
2595 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, Type.void));
25992596 }
26002597
26012598 if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) {
2602 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
2603 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2599 const ptr_ty = try pt.ptrType(.{ .child = zcu.stack_trace_type });
2600 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty));
26042601 }
26052602
26062603 for (0..fn_info.param_types.len) |i| {
......@@ -2609,9 +2606,9 @@ pub const Object = struct {
26092606
26102607 if (isByRef(param_ty, zcu)) {
26112608 const ptr_ty = try pt.singleMutPtrType(param_ty);
2612 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2609 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty));
26132610 } else {
2614 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));
2611 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, param_ty));
26152612 }
26162613 }
26172614
......@@ -2634,10 +2631,10 @@ pub const Object = struct {
26342631 }
26352632 }
26362633
2637 fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata {
2638 const zcu = o.pt.zcu;
2634 fn namespaceToDebugScope(o: *Object, pt: Zcu.PerThread, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata {
2635 const zcu = pt.zcu;
26392636 const namespace = zcu.namespacePtr(namespace_index);
2640 if (namespace.parent == .none) return try o.getDebugFile(namespace.file_scope);
2637 if (namespace.parent == .none) return try o.getDebugFile(pt, namespace.file_scope);
26412638
26422639 const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index);
26432640
......@@ -2646,12 +2643,12 @@ pub const Object = struct {
26462643 return gop.value_ptr.*;
26472644 }
26482645
2649 fn makeEmptyNamespaceDebugType(o: *Object, ty: Type) !Builder.Metadata {
2650 const zcu = o.pt.zcu;
2646 fn makeEmptyNamespaceDebugType(o: *Object, pt: Zcu.PerThread, ty: Type) !Builder.Metadata {
2647 const zcu = pt.zcu;
26512648 const ip = &zcu.intern_pool;
2652 const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
2649 const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
26532650 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|
2654 try o.namespaceToDebugScope(parent_namespace)
2651 try o.namespaceToDebugScope(pt, parent_namespace)
26552652 else
26562653 file;
26572654 return o.builder.debugStructType(
......@@ -2666,31 +2663,10 @@ pub const Object = struct {
26662663 );
26672664 }
26682665
2669 fn getStackTraceType(o: *Object) Allocator.Error!Type {
2670 const pt = o.pt;
2671 const zcu = pt.zcu;
2672 const ip = &zcu.intern_pool;
2673
2674 const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?;
2675 const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls);
2676 const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_index));
2677 const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu));
2678 const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;
2679
2680 const stack_trace_str = try ip.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls);
2681 // buffer is only used for int_type, `builtin` is a struct.
2682 const builtin_ty = zcu.navValue(builtin_nav).toType();
2683 const builtin_namespace = zcu.namespacePtr(builtin_ty.getNamespaceIndex(zcu));
2684 const stack_trace_nav = builtin_namespace.pub_decls.getKeyAdapted(stack_trace_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;
2685
2686 // Sema should have ensured that StackTrace was analyzed.
2687 return zcu.navValue(stack_trace_nav).toType();
2688 }
2689
2690 fn allocTypeName(o: *Object, ty: Type) Allocator.Error![:0]const u8 {
2666 fn allocTypeName(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error![:0]const u8 {
26912667 var aw: std.io.Writer.Allocating = .init(o.gpa);
26922668 defer aw.deinit();
2693 ty.print(&aw.writer, o.pt) catch |err| switch (err) {
2669 ty.print(&aw.writer, pt) catch |err| switch (err) {
26942670 error.WriteFailed => return error.OutOfMemory,
26952671 };
26962672 return aw.toOwnedSliceSentinel(0);
......@@ -2701,9 +2677,9 @@ pub const Object = struct {
27012677 /// completed, so if any attributes rely on that, they must be done in updateFunc, not here.
27022678 fn resolveLlvmFunction(
27032679 o: *Object,
2680 pt: Zcu.PerThread,
27042681 nav_index: InternPool.Nav.Index,
27052682 ) Allocator.Error!Builder.Function.Index {
2706 const pt = o.pt;
27072683 const zcu = pt.zcu;
27082684 const ip = &zcu.intern_pool;
27092685 const gpa = o.gpa;
......@@ -2722,7 +2698,7 @@ pub const Object = struct {
27222698 else
27232699 .{ false, .none };
27242700 const function_index = try o.builder.addFunction(
2725 try o.lowerType(ty),
2701 try o.lowerType(pt, ty),
27262702 try o.builder.strtabString((if (is_extern) nav.name else nav.fqn).toSlice(ip)),
27272703 toLlvmAddressSpace(nav.getAddrspace(), target),
27282704 );
......@@ -2755,7 +2731,7 @@ pub const Object = struct {
27552731 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
27562732 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
27572733
2758 const raw_llvm_ret_ty = try o.lowerType(Type.fromInterned(fn_info.return_type));
2734 const raw_llvm_ret_ty = try o.lowerType(pt, Type.fromInterned(fn_info.return_type));
27592735 try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder);
27602736
27612737 llvm_arg_i += 1;
......@@ -2862,19 +2838,19 @@ pub const Object = struct {
28622838 // Add parameter attributes. We handle only the case of extern functions (no body)
28632839 // because functions with bodies are handled in `updateFunc`.
28642840 if (is_extern) {
2865 var it = iterateParamTypes(o, fn_info);
2841 var it = iterateParamTypes(o, pt, fn_info);
28662842 it.llvm_index = llvm_arg_i;
28672843 while (try it.next()) |lowering| switch (lowering) {
28682844 .byval => {
28692845 const param_index = it.zig_index - 1;
28702846 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
28712847 if (!isByRef(param_ty, zcu)) {
2872 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
2848 try o.addByValParamAttrs(pt, &attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
28732849 }
28742850 },
28752851 .byref => {
28762852 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
2877 const param_llvm_ty = try o.lowerType(param_ty);
2853 const param_llvm_ty = try o.lowerType(pt, param_ty);
28782854 const alignment = param_ty.abiAlignment(zcu);
28792855 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);
28802856 },
......@@ -2969,6 +2945,7 @@ pub const Object = struct {
29692945
29702946 fn resolveGlobalUav(
29712947 o: *Object,
2948 pt: Zcu.PerThread,
29722949 uav: InternPool.Index,
29732950 llvm_addr_space: Builder.AddrSpace,
29742951 alignment: InternPool.Alignment,
......@@ -2986,17 +2963,17 @@ pub const Object = struct {
29862963 }
29872964 errdefer assert(o.uav_map.remove(uav));
29882965
2989 const zcu = o.pt.zcu;
2966 const zcu = pt.zcu;
29902967 const decl_ty = zcu.intern_pool.typeOf(uav);
29912968
29922969 const variable_index = try o.builder.addVariable(
29932970 try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}),
2994 try o.lowerType(Type.fromInterned(decl_ty)),
2971 try o.lowerType(pt, Type.fromInterned(decl_ty)),
29952972 llvm_addr_space,
29962973 );
29972974 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
29982975
2999 try variable_index.setInitializer(try o.lowerValue(uav), &o.builder);
2976 try variable_index.setInitializer(try o.lowerValue(pt, uav), &o.builder);
30002977 variable_index.setLinkage(.internal, &o.builder);
30012978 variable_index.setMutability(.constant, &o.builder);
30022979 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
......@@ -3006,13 +2983,13 @@ pub const Object = struct {
30062983
30072984 fn resolveGlobalNav(
30082985 o: *Object,
2986 pt: Zcu.PerThread,
30092987 nav_index: InternPool.Nav.Index,
30102988 ) Allocator.Error!Builder.Variable.Index {
30112989 const gop = try o.nav_map.getOrPut(o.gpa, nav_index);
30122990 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable;
30132991 errdefer assert(o.nav_map.remove(nav_index));
30142992
3015 const pt = o.pt;
30162993 const zcu = pt.zcu;
30172994 const ip = &zcu.intern_pool;
30182995 const nav = ip.getNav(nav_index);
......@@ -3033,7 +3010,7 @@ pub const Object = struct {
30333010 .strong, .weak => nav.name,
30343011 .link_once => unreachable,
30353012 }.toSlice(ip)),
3036 try o.lowerType(Type.fromInterned(nav.typeOf(ip))),
3013 try o.lowerType(pt, Type.fromInterned(nav.typeOf(ip))),
30373014 toLlvmGlobalAddressSpace(nav.getAddrspace(), zcu.getTarget()),
30383015 );
30393016 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
......@@ -3062,12 +3039,11 @@ pub const Object = struct {
30623039 return variable_index;
30633040 }
30643041
3065 fn errorIntType(o: *Object) Allocator.Error!Builder.Type {
3066 return o.builder.intType(o.pt.zcu.errorSetBits());
3042 fn errorIntType(o: *Object, pt: Zcu.PerThread) Allocator.Error!Builder.Type {
3043 return o.builder.intType(pt.zcu.errorSetBits());
30673044 }
30683045
3069 fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type {
3070 const pt = o.pt;
3046 fn lowerType(o: *Object, pt: Zcu.PerThread, t: Type) Allocator.Error!Builder.Type {
30713047 const zcu = pt.zcu;
30723048 const target = zcu.getTarget();
30733049 const ip = &zcu.intern_pool;
......@@ -3123,7 +3099,7 @@ pub const Object = struct {
31233099 .bool_type => .i1,
31243100 .void_type => .void,
31253101 .type_type => unreachable,
3126 .anyerror_type => try o.errorIntType(),
3102 .anyerror_type => try o.errorIntType(pt),
31273103 .comptime_int_type,
31283104 .comptime_float_type,
31293105 .noreturn_type,
......@@ -3141,11 +3117,11 @@ pub const Object = struct {
31413117 => .ptr,
31423118 .slice_const_u8_type,
31433119 .slice_const_u8_sentinel_0_type,
3144 => try o.builder.structType(.normal, &.{ .ptr, try o.lowerType(Type.usize) }),
3120 => try o.builder.structType(.normal, &.{ .ptr, try o.lowerType(pt, Type.usize) }),
31453121 .optional_noreturn_type => unreachable,
31463122 .anyerror_void_error_union_type,
31473123 .adhoc_inferred_error_set_type,
3148 => try o.errorIntType(),
3124 => try o.errorIntType(pt),
31493125 .generic_poison_type,
31503126 .empty_tuple_type,
31513127 => unreachable,
......@@ -3182,24 +3158,24 @@ pub const Object = struct {
31823158 .one, .many, .c => ptr_ty,
31833159 .slice => try o.builder.structType(.normal, &.{
31843160 ptr_ty,
3185 try o.lowerType(Type.usize),
3161 try o.lowerType(pt, Type.usize),
31863162 }),
31873163 };
31883164 },
31893165 .array_type => |array_type| o.builder.arrayType(
31903166 array_type.lenIncludingSentinel(),
3191 try o.lowerType(Type.fromInterned(array_type.child)),
3167 try o.lowerType(pt, Type.fromInterned(array_type.child)),
31923168 ),
31933169 .vector_type => |vector_type| o.builder.vectorType(
31943170 .normal,
31953171 vector_type.len,
3196 try o.lowerType(Type.fromInterned(vector_type.child)),
3172 try o.lowerType(pt, Type.fromInterned(vector_type.child)),
31973173 ),
31983174 .opt_type => |child_ty| {
31993175 // Must stay in sync with `opt_payload` logic in `lowerPtr`.
32003176 if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(zcu)) return .i8;
32013177
3202 const payload_ty = try o.lowerType(Type.fromInterned(child_ty));
3178 const payload_ty = try o.lowerType(pt, Type.fromInterned(child_ty));
32033179 if (t.optionalReprIsPayload(zcu)) return payload_ty;
32043180
32053181 comptime assert(optional_layout_version == 3);
......@@ -3218,17 +3194,16 @@ pub const Object = struct {
32183194 .error_union_type => |error_union_type| {
32193195 // Must stay in sync with `codegen.errUnionPayloadOffset`.
32203196 // See logic in `lowerPtr`.
3221 const error_type = try o.errorIntType();
3197 const error_type = try o.errorIntType(pt);
32223198 if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu))
32233199 return error_type;
3224 const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type));
3225 const err_int_ty = try o.pt.errorIntType();
3200 const payload_type = try o.lowerType(pt, Type.fromInterned(error_union_type.payload_type));
32263201
32273202 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(zcu);
3228 const error_align = err_int_ty.abiAlignment(zcu);
3203 const error_align: InternPool.Alignment = .fromByteUnits(std.zig.target.intAlignment(target, zcu.errorSetBits()));
32293204
32303205 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(zcu);
3231 const error_size = err_int_ty.abiSize(zcu);
3206 const error_size = std.zig.target.intByteSize(target, zcu.errorSetBits());
32323207
32333208 var fields: [3]Builder.Type = undefined;
32343209 var fields_len: usize = 2;
......@@ -3262,7 +3237,7 @@ pub const Object = struct {
32623237 const struct_type = ip.loadStructType(t.toIntern());
32633238
32643239 if (struct_type.layout == .@"packed") {
3265 const int_ty = try o.lowerType(Type.fromInterned(struct_type.backingIntTypeUnordered(ip)));
3240 const int_ty = try o.lowerType(pt, Type.fromInterned(struct_type.backingIntTypeUnordered(ip)));
32663241 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
32673242 return int_ty;
32683243 }
......@@ -3312,7 +3287,7 @@ pub const Object = struct {
33123287 .struct_ty = t.toIntern(),
33133288 .field_index = field_index,
33143289 }, @intCast(llvm_field_types.items.len));
3315 try llvm_field_types.append(o.gpa, try o.lowerType(field_ty));
3290 try llvm_field_types.append(o.gpa, try o.lowerType(pt, field_ty));
33163291
33173292 offset += field_ty.abiSize(zcu);
33183293 }
......@@ -3382,7 +3357,7 @@ pub const Object = struct {
33823357 .struct_ty = t.toIntern(),
33833358 .field_index = @intCast(field_index),
33843359 }, @intCast(llvm_field_types.items.len));
3385 try llvm_field_types.append(o.gpa, try o.lowerType(Type.fromInterned(field_ty)));
3360 try llvm_field_types.append(o.gpa, try o.lowerType(pt, Type.fromInterned(field_ty)));
33863361
33873362 offset += Type.fromInterned(field_ty).abiSize(zcu);
33883363 }
......@@ -3410,13 +3385,13 @@ pub const Object = struct {
34103385 }
34113386
34123387 if (layout.payload_size == 0) {
3413 const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
3388 const enum_tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty));
34143389 try o.type_map.put(o.gpa, t.toIntern(), enum_tag_ty);
34153390 return enum_tag_ty;
34163391 }
34173392
34183393 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);
3419 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);
3394 const aligned_field_llvm_ty = try o.lowerType(pt, aligned_field_ty);
34203395
34213396 const payload_ty = ty: {
34223397 if (layout.most_aligned_field_size == layout.payload_size) {
......@@ -3442,7 +3417,7 @@ pub const Object = struct {
34423417 );
34433418 return ty;
34443419 }
3445 const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
3420 const enum_tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty));
34463421
34473422 // Put the tag before or after the payload depending on which one's
34483423 // alignment is greater.
......@@ -3477,9 +3452,9 @@ pub const Object = struct {
34773452 }
34783453 return gop.value_ptr.*;
34793454 },
3480 .enum_type => try o.lowerType(Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)),
3481 .func_type => |func_type| try o.lowerTypeFn(func_type),
3482 .error_set_type, .inferred_error_set_type => try o.errorIntType(),
3455 .enum_type => try o.lowerType(pt, Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)),
3456 .func_type => |func_type| try o.lowerTypeFn(pt, func_type),
3457 .error_set_type, .inferred_error_set_type => try o.errorIntType(pt),
34833458 // values, not types
34843459 .undef,
34853460 .simple_value,
......@@ -3508,8 +3483,7 @@ pub const Object = struct {
35083483 /// Use this instead of lowerType when you want to handle correctly the case of elem_ty
35093484 /// being a zero bit type, but it should still be lowered as an i8 in such case.
35103485 /// There are other similar cases handled here as well.
3511 fn lowerPtrElemTy(o: *Object, elem_ty: Type) Allocator.Error!Builder.Type {
3512 const pt = o.pt;
3486 fn lowerPtrElemTy(o: *Object, pt: Zcu.PerThread, elem_ty: Type) Allocator.Error!Builder.Type {
35133487 const zcu = pt.zcu;
35143488 const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) {
35153489 .@"opaque" => true,
......@@ -3517,15 +3491,14 @@ pub const Object = struct {
35173491 .array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu),
35183492 else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu),
35193493 };
3520 return if (lower_elem_ty) try o.lowerType(elem_ty) else .i8;
3494 return if (lower_elem_ty) try o.lowerType(pt, elem_ty) else .i8;
35213495 }
35223496
3523 fn lowerTypeFn(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
3524 const pt = o.pt;
3497 fn lowerTypeFn(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
35253498 const zcu = pt.zcu;
35263499 const ip = &zcu.intern_pool;
35273500 const target = zcu.getTarget();
3528 const ret_ty = try lowerFnRetTy(o, fn_info);
3501 const ret_ty = try lowerFnRetTy(o, pt, fn_info);
35293502
35303503 var llvm_params: std.ArrayListUnmanaged(Builder.Type) = .empty;
35313504 defer llvm_params.deinit(o.gpa);
......@@ -3535,16 +3508,16 @@ pub const Object = struct {
35353508 }
35363509
35373510 if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) {
3538 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
3539 try llvm_params.append(o.gpa, try o.lowerType(ptr_ty));
3511 const ptr_ty = try pt.ptrType(.{ .child = zcu.stack_trace_type });
3512 try llvm_params.append(o.gpa, try o.lowerType(pt, ptr_ty));
35403513 }
35413514
3542 var it = iterateParamTypes(o, fn_info);
3515 var it = iterateParamTypes(o, pt, fn_info);
35433516 while (try it.next()) |lowering| switch (lowering) {
35443517 .no_bits => continue,
35453518 .byval => {
35463519 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
3547 try llvm_params.append(o.gpa, try o.lowerType(param_ty));
3520 try llvm_params.append(o.gpa, try o.lowerType(pt, param_ty));
35483521 },
35493522 .byref, .byref_mut => {
35503523 try llvm_params.append(o.gpa, .ptr);
......@@ -3559,7 +3532,7 @@ pub const Object = struct {
35593532 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
35603533 try llvm_params.appendSlice(o.gpa, &.{
35613534 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(zcu), target)),
3562 try o.lowerType(Type.usize),
3535 try o.lowerType(pt, Type.usize),
35633536 });
35643537 },
35653538 .multiple_llvm_types => {
......@@ -3567,7 +3540,7 @@ pub const Object = struct {
35673540 },
35683541 .float_array => |count| {
35693542 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
3570 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, zcu).?);
3543 const float_ty = try o.lowerType(pt, aarch64_c_abi.getFloatArrayType(param_ty, zcu).?);
35713544 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));
35723545 },
35733546 .i32_array, .i64_array => |arr_len| {
......@@ -3586,8 +3559,7 @@ pub const Object = struct {
35863559 );
35873560 }
35883561
3589 fn lowerValueToInt(o: *Object, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {
3590 const pt = o.pt;
3562 fn lowerValueToInt(o: *Object, pt: Zcu.PerThread, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {
35913563 const zcu = pt.zcu;
35923564 const ip = &zcu.intern_pool;
35933565 const target = zcu.getTarget();
......@@ -3600,23 +3572,23 @@ pub const Object = struct {
36003572 const ty = Type.fromInterned(val_key.typeOf());
36013573 switch (val_key) {
36023574 .@"extern" => |@"extern"| {
3603 const function_index = try o.resolveLlvmFunction(@"extern".owner_nav);
3575 const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav);
36043576 const ptr = function_index.ptrConst(&o.builder).global.toConst();
36053577 return o.builder.convConst(ptr, llvm_int_ty);
36063578 },
36073579 .func => |func| {
3608 const function_index = try o.resolveLlvmFunction(func.owner_nav);
3580 const function_index = try o.resolveLlvmFunction(pt, func.owner_nav);
36093581 const ptr = function_index.ptrConst(&o.builder).global.toConst();
36103582 return o.builder.convConst(ptr, llvm_int_ty);
36113583 },
3612 .ptr => return o.builder.convConst(try o.lowerPtr(arg_val, 0), llvm_int_ty),
3584 .ptr => return o.builder.convConst(try o.lowerPtr(pt, arg_val, 0), llvm_int_ty),
36133585 .aggregate => switch (ip.indexToKey(ty.toIntern())) {
36143586 .struct_type, .vector_type => {},
36153587 else => unreachable,
36163588 },
36173589 .un => |un| {
36183590 const layout = ty.unionGetLayout(zcu);
3619 if (layout.payload_size == 0) return o.lowerValue(un.tag);
3591 if (layout.payload_size == 0) return o.lowerValue(pt, un.tag);
36203592
36213593 const union_obj = zcu.typeToUnion(ty).?;
36223594 const container_layout = union_obj.flagsUnordered(ip).layout;
......@@ -3626,7 +3598,7 @@ pub const Object = struct {
36263598 var need_unnamed = false;
36273599 if (un.tag == .none) {
36283600 assert(layout.tag_size == 0);
3629 const union_val = try o.lowerValueToInt(llvm_int_ty, un.val);
3601 const union_val = try o.lowerValueToInt(pt, llvm_int_ty, un.val);
36303602
36313603 need_unnamed = true;
36323604 return union_val;
......@@ -3634,7 +3606,7 @@ pub const Object = struct {
36343606 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
36353607 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
36363608 if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(llvm_int_ty, 0);
3637 return o.lowerValueToInt(llvm_int_ty, un.val);
3609 return o.lowerValueToInt(pt, llvm_int_ty, un.val);
36383610 },
36393611 .simple_value => |simple_value| switch (simple_value) {
36403612 .false, .true => {},
......@@ -3678,8 +3650,7 @@ pub const Object = struct {
36783650 });
36793651 }
36803652
3681 fn lowerValue(o: *Object, arg_val: InternPool.Index) Error!Builder.Constant {
3682 const pt = o.pt;
3653 fn lowerValue(o: *Object, pt: Zcu.PerThread, arg_val: InternPool.Index) Error!Builder.Constant {
36833654 const zcu = pt.zcu;
36843655 const ip = &zcu.intern_pool;
36853656 const target = zcu.getTarget();
......@@ -3688,7 +3659,7 @@ pub const Object = struct {
36883659 const val_key = ip.indexToKey(val.toIntern());
36893660
36903661 if (val.isUndefDeep(zcu)) {
3691 return o.builder.undefConst(try o.lowerType(Type.fromInterned(val_key.typeOf())));
3662 return o.builder.undefConst(try o.lowerType(pt, Type.fromInterned(val_key.typeOf())));
36923663 }
36933664
36943665 const ty = Type.fromInterned(val_key.typeOf());
......@@ -3727,21 +3698,21 @@ pub const Object = struct {
37273698 .empty_enum_value,
37283699 => unreachable, // non-runtime values
37293700 .@"extern" => |@"extern"| {
3730 const function_index = try o.resolveLlvmFunction(@"extern".owner_nav);
3701 const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav);
37313702 return function_index.ptrConst(&o.builder).global.toConst();
37323703 },
37333704 .func => |func| {
3734 const function_index = try o.resolveLlvmFunction(func.owner_nav);
3705 const function_index = try o.resolveLlvmFunction(pt, func.owner_nav);
37353706 return function_index.ptrConst(&o.builder).global.toConst();
37363707 },
37373708 .int => {
37383709 var bigint_space: Value.BigIntSpace = undefined;
37393710 const bigint = val.toBigInt(&bigint_space, zcu);
3740 return lowerBigInt(o, ty, bigint);
3711 return lowerBigInt(o, pt, ty, bigint);
37413712 },
37423713 .err => |err| {
37433714 const int = try pt.getErrorValue(err.name);
3744 const llvm_int = try o.builder.intConst(try o.errorIntType(), int);
3715 const llvm_int = try o.builder.intConst(try o.errorIntType(pt), int);
37453716 return llvm_int;
37463717 },
37473718 .error_union => |error_union| {
......@@ -3756,13 +3727,13 @@ pub const Object = struct {
37563727 const payload_type = ty.errorUnionPayload(zcu);
37573728 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
37583729 // We use the error type directly as the type.
3759 return o.lowerValue(err_val);
3730 return o.lowerValue(pt, err_val);
37603731 }
37613732
37623733 const payload_align = payload_type.abiAlignment(zcu);
37633734 const error_align = err_int_ty.abiAlignment(zcu);
3764 const llvm_error_value = try o.lowerValue(err_val);
3765 const llvm_payload_value = try o.lowerValue(switch (error_union.val) {
3735 const llvm_error_value = try o.lowerValue(pt, err_val);
3736 const llvm_payload_value = try o.lowerValue(pt, switch (error_union.val) {
37663737 .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }),
37673738 .payload => |payload| payload,
37683739 });
......@@ -3779,7 +3750,7 @@ pub const Object = struct {
37793750 fields[0] = vals[0].typeOf(&o.builder);
37803751 fields[1] = vals[1].typeOf(&o.builder);
37813752
3782 const llvm_ty = try o.lowerType(ty);
3753 const llvm_ty = try o.lowerType(pt, ty);
37833754 const llvm_ty_fields = llvm_ty.structFields(&o.builder);
37843755 if (llvm_ty_fields.len > 2) {
37853756 assert(llvm_ty_fields.len == 3);
......@@ -3791,7 +3762,7 @@ pub const Object = struct {
37913762 fields[0..llvm_ty_fields.len],
37923763 ), vals[0..llvm_ty_fields.len]);
37933764 },
3794 .enum_tag => |enum_tag| o.lowerValue(enum_tag.int),
3765 .enum_tag => |enum_tag| o.lowerValue(pt, enum_tag.int),
37953766 .float => switch (ty.floatBits(target)) {
37963767 16 => if (backendSupportsF16(target))
37973768 try o.builder.halfConst(val.toFloat(f16, zcu))
......@@ -3806,10 +3777,10 @@ pub const Object = struct {
38063777 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)),
38073778 else => unreachable,
38083779 },
3809 .ptr => try o.lowerPtr(arg_val, 0),
3810 .slice => |slice| return o.builder.structConst(try o.lowerType(ty), &.{
3811 try o.lowerValue(slice.ptr),
3812 try o.lowerValue(slice.len),
3780 .ptr => try o.lowerPtr(pt, arg_val, 0),
3781 .slice => |slice| return o.builder.structConst(try o.lowerType(pt, ty), &.{
3782 try o.lowerValue(pt, slice.ptr),
3783 try o.lowerValue(pt, slice.len),
38133784 }),
38143785 .opt => |opt| {
38153786 comptime assert(optional_layout_version == 3);
......@@ -3819,7 +3790,7 @@ pub const Object = struct {
38193790 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
38203791 return non_null_bit;
38213792 }
3822 const llvm_ty = try o.lowerType(ty);
3793 const llvm_ty = try o.lowerType(pt, ty);
38233794 if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) {
38243795 .none => switch (llvm_ty.tag(&o.builder)) {
38253796 .integer => try o.builder.intConst(llvm_ty, 0),
......@@ -3827,13 +3798,13 @@ pub const Object = struct {
38273798 .structure => try o.builder.zeroInitConst(llvm_ty),
38283799 else => unreachable,
38293800 },
3830 else => |payload| try o.lowerValue(payload),
3801 else => |payload| try o.lowerValue(pt, payload),
38313802 };
38323803 assert(payload_ty.zigTypeTag(zcu) != .@"fn");
38333804
38343805 var fields: [3]Builder.Type = undefined;
38353806 var vals: [3]Builder.Constant = undefined;
3836 vals[0] = try o.lowerValue(switch (opt.val) {
3807 vals[0] = try o.lowerValue(pt, switch (opt.val) {
38373808 .none => try pt.intern(.{ .undef = payload_ty.toIntern() }),
38383809 else => |payload| payload,
38393810 });
......@@ -3858,7 +3829,7 @@ pub const Object = struct {
38583829 bytes.toSlice(array_type.lenIncludingSentinel(), ip),
38593830 )),
38603831 .elems => |elems| {
3861 const array_ty = try o.lowerType(ty);
3832 const array_ty = try o.lowerType(pt, ty);
38623833 const elem_ty = array_ty.childType(&o.builder);
38633834 assert(elems.len == array_ty.aggregateLen(&o.builder));
38643835
......@@ -3878,7 +3849,7 @@ pub const Object = struct {
38783849
38793850 var need_unnamed = false;
38803851 for (vals, fields, elems) |*result_val, *result_field, elem| {
3881 result_val.* = try o.lowerValue(elem);
3852 result_val.* = try o.lowerValue(pt, elem);
38823853 result_field.* = result_val.typeOf(&o.builder);
38833854 if (result_field.* != elem_ty) need_unnamed = true;
38843855 }
......@@ -3890,7 +3861,7 @@ pub const Object = struct {
38903861 .repeated_elem => |elem| {
38913862 const len: usize = @intCast(array_type.len);
38923863 const len_including_sentinel: usize = @intCast(array_type.lenIncludingSentinel());
3893 const array_ty = try o.lowerType(ty);
3864 const array_ty = try o.lowerType(pt, ty);
38943865 const elem_ty = array_ty.childType(&o.builder);
38953866
38963867 const ExpectedContents = extern struct {
......@@ -3908,12 +3879,12 @@ pub const Object = struct {
39083879 defer allocator.free(fields);
39093880
39103881 var need_unnamed = false;
3911 @memset(vals[0..len], try o.lowerValue(elem));
3882 @memset(vals[0..len], try o.lowerValue(pt, elem));
39123883 @memset(fields[0..len], vals[0].typeOf(&o.builder));
39133884 if (fields[0] != elem_ty) need_unnamed = true;
39143885
39153886 if (array_type.sentinel != .none) {
3916 vals[len] = try o.lowerValue(array_type.sentinel);
3887 vals[len] = try o.lowerValue(pt, array_type.sentinel);
39173888 fields[len] = vals[len].typeOf(&o.builder);
39183889 if (fields[len] != elem_ty) need_unnamed = true;
39193890 }
......@@ -3925,7 +3896,7 @@ pub const Object = struct {
39253896 },
39263897 },
39273898 .vector_type => |vector_type| {
3928 const vector_ty = try o.lowerType(ty);
3899 const vector_ty = try o.lowerType(pt, ty);
39293900 switch (aggregate.storage) {
39303901 .bytes, .elems => {
39313902 const ExpectedContents = [Builder.expected_fields_len]Builder.Constant;
......@@ -3942,7 +3913,7 @@ pub const Object = struct {
39423913 result_val.* = try o.builder.intConst(.i8, byte);
39433914 },
39443915 .elems => |elems| for (vals, elems) |*result_val, elem| {
3945 result_val.* = try o.lowerValue(elem);
3916 result_val.* = try o.lowerValue(pt, elem);
39463917 },
39473918 .repeated_elem => unreachable,
39483919 }
......@@ -3950,12 +3921,12 @@ pub const Object = struct {
39503921 },
39513922 .repeated_elem => |elem| return o.builder.splatConst(
39523923 vector_ty,
3953 try o.lowerValue(elem),
3924 try o.lowerValue(pt, elem),
39543925 ),
39553926 }
39563927 },
39573928 .tuple_type => |tuple| {
3958 const struct_ty = try o.lowerType(ty);
3929 const struct_ty = try o.lowerType(pt, ty);
39593930 const llvm_len = struct_ty.aggregateLen(&o.builder);
39603931
39613932 const ExpectedContents = extern struct {
......@@ -4001,7 +3972,7 @@ pub const Object = struct {
40013972 }
40023973
40033974 vals[llvm_index] =
4004 try o.lowerValue((try val.fieldValue(pt, field_index)).toIntern());
3975 try o.lowerValue(pt, (try val.fieldValue(pt, field_index)).toIntern());
40053976 fields[llvm_index] = vals[llvm_index].typeOf(&o.builder);
40063977 if (fields[llvm_index] != struct_ty.structFields(&o.builder)[llvm_index])
40073978 need_unnamed = true;
......@@ -4030,14 +4001,14 @@ pub const Object = struct {
40304001 .struct_type => {
40314002 const struct_type = ip.loadStructType(ty.toIntern());
40324003 assert(struct_type.haveLayout(ip));
4033 const struct_ty = try o.lowerType(ty);
4004 const struct_ty = try o.lowerType(pt, ty);
40344005 if (struct_type.layout == .@"packed") {
40354006 comptime assert(Type.packed_struct_layout_version == 2);
40364007
40374008 const bits = ty.bitSize(zcu);
40384009 const llvm_int_ty = try o.builder.intType(@intCast(bits));
40394010
4040 return o.lowerValueToInt(llvm_int_ty, arg_val);
4011 return o.lowerValueToInt(pt, llvm_int_ty, arg_val);
40414012 }
40424013 const llvm_len = struct_ty.aggregateLen(&o.builder);
40434014
......@@ -4085,6 +4056,7 @@ pub const Object = struct {
40854056 }
40864057
40874058 vals[llvm_index] = try o.lowerValue(
4059 pt,
40884060 (try val.fieldValue(pt, field_index)).toIntern(),
40894061 );
40904062 fields[llvm_index] = vals[llvm_index].typeOf(&o.builder);
......@@ -4115,9 +4087,9 @@ pub const Object = struct {
41154087 else => unreachable,
41164088 },
41174089 .un => |un| {
4118 const union_ty = try o.lowerType(ty);
4090 const union_ty = try o.lowerType(pt, ty);
41194091 const layout = ty.unionGetLayout(zcu);
4120 if (layout.payload_size == 0) return o.lowerValue(un.tag);
4092 if (layout.payload_size == 0) return o.lowerValue(pt, un.tag);
41214093
41224094 const union_obj = zcu.typeToUnion(ty).?;
41234095 const container_layout = union_obj.flagsUnordered(ip).layout;
......@@ -4131,7 +4103,7 @@ pub const Object = struct {
41314103 const bits = ty.bitSize(zcu);
41324104 const llvm_int_ty = try o.builder.intType(@intCast(bits));
41334105
4134 return o.lowerValueToInt(llvm_int_ty, arg_val);
4106 return o.lowerValueToInt(pt, llvm_int_ty, arg_val);
41354107 }
41364108
41374109 // Sometimes we must make an unnamed struct because LLVM does
......@@ -4144,7 +4116,7 @@ pub const Object = struct {
41444116 const padding_len = layout.payload_size;
41454117 break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8));
41464118 }
4147 const payload = try o.lowerValue(un.val);
4119 const payload = try o.lowerValue(pt, un.val);
41484120 const payload_ty = payload.typeOf(&o.builder);
41494121 if (payload_ty != union_ty.structFields(&o.builder)[
41504122 @intFromBool(layout.tag_align.compare(.gte, layout.payload_align))
......@@ -4163,10 +4135,10 @@ pub const Object = struct {
41634135 const bits = ty.bitSize(zcu);
41644136 const llvm_int_ty = try o.builder.intType(@intCast(bits));
41654137
4166 return o.lowerValueToInt(llvm_int_ty, arg_val);
4138 return o.lowerValueToInt(pt, llvm_int_ty, arg_val);
41674139 }
41684140
4169 const union_val = try o.lowerValue(un.val);
4141 const union_val = try o.lowerValue(pt, un.val);
41704142 need_unnamed = true;
41714143 break :p union_val;
41724144 };
......@@ -4176,7 +4148,7 @@ pub const Object = struct {
41764148 try o.builder.structType(union_ty.structKind(&o.builder), &.{payload_ty})
41774149 else
41784150 union_ty, &.{payload});
4179 const tag = try o.lowerValue(un.tag);
4151 const tag = try o.lowerValue(pt, un.tag);
41804152 const tag_ty = tag.typeOf(&o.builder);
41814153 var fields: [3]Builder.Type = undefined;
41824154 var vals: [3]Builder.Constant = undefined;
......@@ -4204,48 +4176,50 @@ pub const Object = struct {
42044176
42054177 fn lowerBigInt(
42064178 o: *Object,
4179 pt: Zcu.PerThread,
42074180 ty: Type,
42084181 bigint: std.math.big.int.Const,
42094182 ) Allocator.Error!Builder.Constant {
4210 const zcu = o.pt.zcu;
4183 const zcu = pt.zcu;
42114184 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint);
42124185 }
42134186
42144187 fn lowerPtr(
42154188 o: *Object,
4189 pt: Zcu.PerThread,
42164190 ptr_val: InternPool.Index,
42174191 prev_offset: u64,
42184192 ) Error!Builder.Constant {
4219 const pt = o.pt;
42204193 const zcu = pt.zcu;
42214194 const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr;
42224195 const offset: u64 = prev_offset + ptr.byte_offset;
42234196 return switch (ptr.base_addr) {
42244197 .nav => |nav| {
4225 const base_ptr = try o.lowerNavRefValue(nav);
4198 const base_ptr = try o.lowerNavRefValue(pt, nav);
42264199 return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{
42274200 try o.builder.intConst(.i64, offset),
42284201 });
42294202 },
42304203 .uav => |uav| {
4231 const base_ptr = try o.lowerUavRef(uav);
4204 const base_ptr = try o.lowerUavRef(pt, uav);
42324205 return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{
42334206 try o.builder.intConst(.i64, offset),
42344207 });
42354208 },
42364209 .int => try o.builder.castConst(
42374210 .inttoptr,
4238 try o.builder.intConst(try o.lowerType(Type.usize), offset),
4239 try o.lowerType(Type.fromInterned(ptr.ty)),
4211 try o.builder.intConst(try o.lowerType(pt, Type.usize), offset),
4212 try o.lowerType(pt, Type.fromInterned(ptr.ty)),
42404213 ),
42414214 .eu_payload => |eu_ptr| try o.lowerPtr(
4215 pt,
42424216 eu_ptr,
42434217 offset + @import("../codegen.zig").errUnionPayloadOffset(
42444218 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu),
42454219 zcu,
42464220 ),
42474221 ),
4248 .opt_payload => |opt_ptr| try o.lowerPtr(opt_ptr, offset),
4222 .opt_payload => |opt_ptr| try o.lowerPtr(pt, opt_ptr, offset),
42494223 .field => |field| {
42504224 const agg_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu);
42514225 const field_off: u64 = switch (agg_ty.zigTypeTag(zcu)) {
......@@ -4263,7 +4237,7 @@ pub const Object = struct {
42634237 },
42644238 else => unreachable,
42654239 };
4266 return o.lowerPtr(field.base, offset + field_off);
4240 return o.lowerPtr(pt, field.base, offset + field_off);
42674241 },
42684242 .arr_elem, .comptime_field, .comptime_alloc => unreachable,
42694243 };
......@@ -4273,9 +4247,9 @@ pub const Object = struct {
42734247 /// Maybe the logic could be unified.
42744248 fn lowerUavRef(
42754249 o: *Object,
4250 pt: Zcu.PerThread,
42764251 uav: InternPool.Key.Ptr.BaseAddr.Uav,
42774252 ) Error!Builder.Constant {
4278 const pt = o.pt;
42794253 const zcu = pt.zcu;
42804254 const ip = &zcu.intern_pool;
42814255 const uav_val = uav.val;
......@@ -4292,25 +4266,24 @@ pub const Object = struct {
42924266
42934267 const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn";
42944268 if ((!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) or
4295 (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(ptr_ty);
4269 (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(pt, ptr_ty);
42964270
42974271 if (is_fn_body)
42984272 @panic("TODO");
42994273
43004274 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target);
43014275 const alignment = ptr_ty.ptrAlignment(zcu);
4302 const llvm_global = (try o.resolveGlobalUav(uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
4276 const llvm_global = (try o.resolveGlobalUav(pt, uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
43034277
43044278 const llvm_val = try o.builder.convConst(
43054279 llvm_global.toConst(),
43064280 try o.builder.ptrType(llvm_addr_space),
43074281 );
43084282
4309 return o.builder.convConst(llvm_val, try o.lowerType(ptr_ty));
4283 return o.builder.convConst(llvm_val, try o.lowerType(pt, ptr_ty));
43104284 }
43114285
4312 fn lowerNavRefValue(o: *Object, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant {
4313 const pt = o.pt;
4286 fn lowerNavRefValue(o: *Object, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant {
43144287 const zcu = pt.zcu;
43154288 const ip = &zcu.intern_pool;
43164289
......@@ -4323,24 +4296,24 @@ pub const Object = struct {
43234296 if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or
43244297 (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic))
43254298 {
4326 return o.lowerPtrToVoid(ptr_ty);
4299 return o.lowerPtrToVoid(pt, ptr_ty);
43274300 }
43284301
43294302 const llvm_global = if (is_fn_body)
4330 (try o.resolveLlvmFunction(nav_index)).ptrConst(&o.builder).global
4303 (try o.resolveLlvmFunction(pt, nav_index)).ptrConst(&o.builder).global
43314304 else
4332 (try o.resolveGlobalNav(nav_index)).ptrConst(&o.builder).global;
4305 (try o.resolveGlobalNav(pt, nav_index)).ptrConst(&o.builder).global;
43334306
43344307 const llvm_val = try o.builder.convConst(
43354308 llvm_global.toConst(),
43364309 try o.builder.ptrType(toLlvmAddressSpace(nav.getAddrspace(), zcu.getTarget())),
43374310 );
43384311
4339 return o.builder.convConst(llvm_val, try o.lowerType(ptr_ty));
4312 return o.builder.convConst(llvm_val, try o.lowerType(pt, ptr_ty));
43404313 }
43414314
4342 fn lowerPtrToVoid(o: *Object, ptr_ty: Type) Allocator.Error!Builder.Constant {
4343 const zcu = o.pt.zcu;
4315 fn lowerPtrToVoid(o: *Object, pt: Zcu.PerThread, ptr_ty: Type) Allocator.Error!Builder.Constant {
4316 const zcu = pt.zcu;
43444317 // Even though we are pointing at something which has zero bits (e.g. `void`),
43454318 // Pointers are defined to have bits. So we must return something here.
43464319 // The value cannot be undefined, because we use the `nonnull` annotation
......@@ -4358,8 +4331,8 @@ pub const Object = struct {
43584331 64 => 0xaaaaaaaa_aaaaaaaa,
43594332 else => unreachable,
43604333 };
4361 const llvm_usize = try o.lowerType(Type.usize);
4362 const llvm_ptr_ty = try o.lowerType(ptr_ty);
4334 const llvm_usize = try o.lowerType(pt, Type.usize);
4335 const llvm_ptr_ty = try o.lowerType(pt, ptr_ty);
43634336 return o.builder.castConst(.inttoptr, try o.builder.intConst(llvm_usize, int), llvm_ptr_ty);
43644337 }
43654338
......@@ -4367,8 +4340,7 @@ pub const Object = struct {
43674340 /// widen it before using it and then truncate the result.
43684341 /// RMW exchange of floating-point values is bitcasted to same-sized integer
43694342 /// types to work around a LLVM deficiency when targeting ARM/AArch64.
4370 fn getAtomicAbiType(o: *Object, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type {
4371 const pt = o.pt;
4343 fn getAtomicAbiType(o: *Object, pt: Zcu.PerThread, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type {
43724344 const zcu = pt.zcu;
43734345 const int_ty = switch (ty.zigTypeTag(zcu)) {
43744346 .int => ty,
......@@ -4390,13 +4362,13 @@ pub const Object = struct {
43904362
43914363 fn addByValParamAttrs(
43924364 o: *Object,
4365 pt: Zcu.PerThread,
43934366 attributes: *Builder.FunctionAttributes.Wip,
43944367 param_ty: Type,
43954368 param_index: u32,
43964369 fn_info: InternPool.Key.FuncType,
43974370 llvm_arg_i: u32,
43984371 ) Allocator.Error!void {
4399 const pt = o.pt;
44004372 const zcu = pt.zcu;
44014373 if (param_ty.isPtrAtRuntime(zcu)) {
44024374 const ptr_info = param_ty.ptrInfo(zcu);
......@@ -4416,7 +4388,7 @@ pub const Object = struct {
44164388 .x86_64_interrupt,
44174389 .x86_interrupt,
44184390 => {
4419 const child_type = try lowerType(o, Type.fromInterned(ptr_info.child));
4391 const child_type = try lowerType(o, pt, Type.fromInterned(ptr_info.child));
44204392 try attributes.addParamAttr(llvm_arg_i, .{ .byval = child_type }, &o.builder);
44214393 },
44224394 }
......@@ -4455,14 +4427,14 @@ pub const Object = struct {
44554427 });
44564428 }
44574429
4458 fn getCmpLtErrorsLenFunction(o: *Object) !Builder.Function.Index {
4430 fn getCmpLtErrorsLenFunction(o: *Object, pt: Zcu.PerThread) !Builder.Function.Index {
44594431 const name = try o.builder.strtabString(lt_errors_fn_name);
44604432 if (o.builder.getGlobal(name)) |llvm_fn| return llvm_fn.ptrConst(&o.builder).kind.function;
44614433
4462 const zcu = o.pt.zcu;
4434 const zcu = pt.zcu;
44634435 const target = &zcu.root_mod.resolved_target.result;
44644436 const function_index = try o.builder.addFunction(
4465 try o.builder.fnType(.i1, &.{try o.errorIntType()}, .normal),
4437 try o.builder.fnType(.i1, &.{try o.errorIntType(pt)}, .normal),
44664438 name,
44674439 toLlvmAddressSpace(.generic, target),
44684440 );
......@@ -4477,8 +4449,7 @@ pub const Object = struct {
44774449 return function_index;
44784450 }
44794451
4480 fn getEnumTagNameFunction(o: *Object, enum_ty: Type) !Builder.Function.Index {
4481 const pt = o.pt;
4452 fn getEnumTagNameFunction(o: *Object, pt: Zcu.PerThread, enum_ty: Type) !Builder.Function.Index {
44824453 const zcu = pt.zcu;
44834454 const ip = &zcu.intern_pool;
44844455 const enum_type = ip.loadEnumType(enum_ty.toIntern());
......@@ -4487,11 +4458,11 @@ pub const Object = struct {
44874458 if (gop.found_existing) return gop.value_ptr.ptrConst(&o.builder).kind.function;
44884459 errdefer assert(o.enum_tag_name_map.remove(enum_ty.toIntern()));
44894460
4490 const usize_ty = try o.lowerType(Type.usize);
4491 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);
4461 const usize_ty = try o.lowerType(pt, Type.usize);
4462 const ret_ty = try o.lowerType(pt, Type.slice_const_u8_sentinel_0);
44924463 const target = &zcu.root_mod.resolved_target.result;
44934464 const function_index = try o.builder.addFunction(
4494 try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
4465 try o.builder.fnType(ret_ty, &.{try o.lowerType(pt, Type.fromInterned(enum_type.tag_ty))}, .normal),
44954466 try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_type.name.fmt(ip)}),
44964467 toLlvmAddressSpace(.generic, target),
44974468 );
......@@ -4536,6 +4507,7 @@ pub const Object = struct {
45364507
45374508 const return_block = try wip.block(1, "Name");
45384509 const this_tag_int_value = try o.lowerValue(
4510 pt,
45394511 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),
45404512 );
45414513 try wip_switch.addCase(this_tag_int_value, return_block, &wip);
......@@ -4555,10 +4527,11 @@ pub const Object = struct {
45554527pub const NavGen = struct {
45564528 object: *Object,
45574529 nav_index: InternPool.Nav.Index,
4530 pt: Zcu.PerThread,
45584531 err_msg: ?*Zcu.ErrorMsg,
45594532
45604533 fn ownerModule(ng: NavGen) *Package.Module {
4561 return ng.object.pt.zcu.navFileScope(ng.nav_index).mod.?;
4534 return ng.pt.zcu.navFileScope(ng.nav_index).mod.?;
45624535 }
45634536
45644537 fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {
......@@ -4566,14 +4539,14 @@ pub const NavGen = struct {
45664539 assert(ng.err_msg == null);
45674540 const o = ng.object;
45684541 const gpa = o.gpa;
4569 const src_loc = o.pt.zcu.navSrcLoc(ng.nav_index);
4542 const src_loc = ng.pt.zcu.navSrcLoc(ng.nav_index);
45704543 ng.err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
45714544 return error.CodegenFail;
45724545 }
45734546
45744547 fn genDecl(ng: *NavGen) !void {
45754548 const o = ng.object;
4576 const pt = o.pt;
4549 const pt = ng.pt;
45774550 const zcu = pt.zcu;
45784551 const ip = &zcu.intern_pool;
45794552 const nav_index = ng.nav_index;
......@@ -4588,16 +4561,16 @@ pub const NavGen = struct {
45884561 const ty = Type.fromInterned(nav.typeOf(ip));
45894562
45904563 if (linkage != .internal and ip.isFunctionType(ty.toIntern())) {
4591 _ = try o.resolveLlvmFunction(owner_nav);
4564 _ = try o.resolveLlvmFunction(pt, owner_nav);
45924565 } else {
4593 const variable_index = try o.resolveGlobalNav(nav_index);
4566 const variable_index = try o.resolveGlobalNav(pt, nav_index);
45944567 variable_index.setAlignment(pt.navAlignment(nav_index).toLlvm(), &o.builder);
45954568 if (resolved.@"linksection".toSlice(ip)) |section|
45964569 variable_index.setSection(try o.builder.string(section), &o.builder);
45974570 if (is_const) variable_index.setMutability(.constant, &o.builder);
45984571 try variable_index.setInitializer(switch (init_val) {
45994572 .none => .no_init,
4600 else => try o.lowerValue(init_val),
4573 else => try o.lowerValue(pt, init_val),
46014574 }, &o.builder);
46024575 variable_index.setVisibility(visibility, &o.builder);
46034576
......@@ -4609,7 +4582,7 @@ pub const NavGen = struct {
46094582 const line_number = zcu.navSrcLine(nav_index) + 1;
46104583
46114584 if (!mod.strip) {
4612 const debug_file = try o.getDebugFile(file_scope);
4585 const debug_file = try o.getDebugFile(pt, file_scope);
46134586
46144587 const debug_global_var = try o.builder.debugGlobalVar(
46154588 try o.builder.metadataString(nav.name.toSlice(ip)), // Name
......@@ -4617,7 +4590,7 @@ pub const NavGen = struct {
46174590 debug_file, // File
46184591 debug_file, // Scope
46194592 line_number,
4620 try o.lowerDebugType(ty),
4593 try o.lowerDebugType(pt, ty),
46214594 variable_index,
46224595 .{ .local = linkage == .internal },
46234596 );
......@@ -4814,16 +4787,17 @@ pub const FuncGen = struct {
48144787 const gop = try self.func_inst_table.getOrPut(gpa, inst);
48154788 if (gop.found_existing) return gop.value_ptr.*;
48164789
4817 const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.object.pt)).?);
4790 const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.pt)).?);
48184791 gop.value_ptr.* = llvm_val.toValue();
48194792 return llvm_val.toValue();
48204793 }
48214794
48224795 fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant {
48234796 const o = self.ng.object;
4824 const zcu = o.pt.zcu;
4797 const pt = self.ng.pt;
4798 const zcu = pt.zcu;
48254799 const ty = val.typeOf(zcu);
4826 const llvm_val = try o.lowerValue(val.toIntern());
4800 const llvm_val = try o.lowerValue(pt, val.toIntern());
48274801 if (!isByRef(ty, zcu)) return llvm_val;
48284802
48294803 // We have an LLVM value but we need to create a global constant and
......@@ -4847,7 +4821,7 @@ pub const FuncGen = struct {
48474821
48484822 fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) Error!void {
48494823 const o = self.ng.object;
4850 const zcu = o.pt.zcu;
4824 const zcu = self.ng.pt.zcu;
48514825 const ip = &zcu.intern_pool;
48524826 const air_tags = self.air.instructions.items(.tag);
48534827 switch (coverage_point) {
......@@ -5173,7 +5147,7 @@ pub const FuncGen = struct {
51735147
51745148 if (maybe_inline_func) |inline_func| {
51755149 const o = self.ng.object;
5176 const pt = o.pt;
5150 const pt = self.ng.pt;
51775151 const zcu = pt.zcu;
51785152 const ip = &zcu.intern_pool;
51795153
......@@ -5182,7 +5156,7 @@ pub const FuncGen = struct {
51825156 const file_scope = zcu.navFileScopeIndex(func.owner_nav);
51835157 const mod = zcu.fileByIndex(file_scope).mod.?;
51845158
5185 self.file = try o.getDebugFile(file_scope);
5159 self.file = try o.getDebugFile(pt, file_scope);
51865160
51875161 const line_number = zcu.navSrcLine(func.owner_nav) + 1;
51885162 self.inlined = self.wip.debug_location;
......@@ -5198,7 +5172,7 @@ pub const FuncGen = struct {
51985172 try o.builder.metadataString(nav.fqn.toSlice(&zcu.intern_pool)),
51995173 line_number,
52005174 line_number + func.lbrace_line,
5201 try o.lowerDebugType(fn_ty),
5175 try o.lowerDebugType(pt, fn_ty),
52025176 .{
52035177 .di_flags = .{ .StaticMember = true },
52045178 .sp_flags = .{
......@@ -5255,7 +5229,7 @@ pub const FuncGen = struct {
52555229 const extra = self.air.extraData(Air.Call, pl_op.payload);
52565230 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[extra.end..][0..extra.data.args_len]);
52575231 const o = self.ng.object;
5258 const pt = o.pt;
5232 const pt = self.ng.pt;
52595233 const zcu = pt.zcu;
52605234 const ip = &zcu.intern_pool;
52615235 const callee_ty = self.typeOf(pl_op.operand);
......@@ -5287,7 +5261,7 @@ pub const FuncGen = struct {
52875261 }
52885262
52895263 const ret_ptr = if (!sret) null else blk: {
5290 const llvm_ret_ty = try o.lowerType(return_type);
5264 const llvm_ret_ty = try o.lowerType(pt, return_type);
52915265 try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder);
52925266
52935267 const alignment = return_type.abiAlignment(zcu).toLlvm();
......@@ -5302,14 +5276,14 @@ pub const FuncGen = struct {
53025276 try llvm_args.append(self.err_ret_trace);
53035277 }
53045278
5305 var it = iterateParamTypes(o, fn_info);
5279 var it = iterateParamTypes(o, pt, fn_info);
53065280 while (try it.nextCall(self, args)) |lowering| switch (lowering) {
53075281 .no_bits => continue,
53085282 .byval => {
53095283 const arg = args[it.zig_index - 1];
53105284 const param_ty = self.typeOf(arg);
53115285 const llvm_arg = try self.resolveInst(arg);
5312 const llvm_param_ty = try o.lowerType(param_ty);
5286 const llvm_param_ty = try o.lowerType(pt, param_ty);
53135287 if (isByRef(param_ty, zcu)) {
53145288 const alignment = param_ty.abiAlignment(zcu).toLlvm();
53155289 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");
......@@ -5338,7 +5312,7 @@ pub const FuncGen = struct {
53385312 const llvm_arg = try self.resolveInst(arg);
53395313
53405314 const alignment = param_ty.abiAlignment(zcu).toLlvm();
5341 const param_llvm_ty = try o.lowerType(param_ty);
5315 const param_llvm_ty = try o.lowerType(pt, param_ty);
53425316 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);
53435317 if (isByRef(param_ty, zcu)) {
53445318 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");
......@@ -5409,7 +5383,7 @@ pub const FuncGen = struct {
54095383 llvm_arg = ptr;
54105384 }
54115385
5412 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?);
5386 const float_ty = try o.lowerType(pt, aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?);
54135387 const array_ty = try o.builder.arrayType(count, float_ty);
54145388
54155389 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");
......@@ -5436,7 +5410,7 @@ pub const FuncGen = struct {
54365410
54375411 {
54385412 // Add argument attributes.
5439 it = iterateParamTypes(o, fn_info);
5413 it = iterateParamTypes(o, pt, fn_info);
54405414 it.llvm_index += @intFromBool(sret);
54415415 it.llvm_index += @intFromBool(err_return_tracing);
54425416 while (try it.next()) |lowering| switch (lowering) {
......@@ -5444,13 +5418,13 @@ pub const FuncGen = struct {
54445418 const param_index = it.zig_index - 1;
54455419 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
54465420 if (!isByRef(param_ty, zcu)) {
5447 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
5421 try o.addByValParamAttrs(pt, &attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
54485422 }
54495423 },
54505424 .byref => {
54515425 const param_index = it.zig_index - 1;
54525426 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
5453 const param_llvm_ty = try o.lowerType(param_ty);
5427 const param_llvm_ty = try o.lowerType(pt, param_ty);
54545428 const alignment = param_ty.abiAlignment(zcu).toLlvm();
54555429 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);
54565430 },
......@@ -5502,7 +5476,7 @@ pub const FuncGen = struct {
55025476 },
55035477 toLlvmCallConvTag(fn_info.cc, target).?,
55045478 try attributes.finish(&o.builder),
5505 try o.lowerType(zig_fn_ty),
5479 try o.lowerType(pt, zig_fn_ty),
55065480 llvm_fn,
55075481 llvm_args.items,
55085482 "",
......@@ -5516,7 +5490,7 @@ pub const FuncGen = struct {
55165490 return .none;
55175491 }
55185492
5519 const llvm_ret_ty = try o.lowerType(return_type);
5493 const llvm_ret_ty = try o.lowerType(pt, return_type);
55205494 if (ret_ptr) |rp| {
55215495 if (isByRef(return_type, zcu)) {
55225496 return rp;
......@@ -5527,7 +5501,7 @@ pub const FuncGen = struct {
55275501 }
55285502 }
55295503
5530 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
5504 const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info);
55315505
55325506 if (abi_ret_ty != llvm_ret_ty) {
55335507 // In this case the function return type is honoring the calling convention by having
......@@ -5556,11 +5530,12 @@ pub const FuncGen = struct {
55565530
55575531 fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) !void {
55585532 const o = fg.ng.object;
5559 const zcu = o.pt.zcu;
5533 const pt = fg.ng.pt;
5534 const zcu = pt.zcu;
55605535 const target = zcu.getTarget();
55615536 const panic_func = zcu.funcInfo(zcu.builtin_decl_values.get(panic_id.toBuiltin()));
55625537 const fn_info = zcu.typeToFunc(.fromInterned(panic_func.ty)).?;
5563 const panic_global = try o.resolveLlvmFunction(panic_func.owner_nav);
5538 const panic_global = try o.resolveLlvmFunction(pt, panic_func.owner_nav);
55645539
55655540 const has_err_trace = zcu.comp.config.any_error_tracing and fn_info.cc == .auto;
55665541 if (has_err_trace) assert(fg.err_ret_trace != .none);
......@@ -5579,7 +5554,7 @@ pub const FuncGen = struct {
55795554
55805555 fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !void {
55815556 const o = self.ng.object;
5582 const pt = o.pt;
5557 const pt = self.ng.pt;
55835558 const zcu = pt.zcu;
55845559 const ip = &zcu.intern_pool;
55855560 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
......@@ -5599,7 +5574,7 @@ pub const FuncGen = struct {
55995574 // https://github.com/ziglang/zig/issues/15337
56005575 break :undef;
56015576 }
5602 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu));
5577 const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), ret_ty.abiSize(zcu));
56035578 _ = try self.wip.callMemSet(
56045579 self.ret_ptr,
56055580 ptr_ty.ptrAlignment(zcu).toLlvm(),
......@@ -5635,14 +5610,14 @@ pub const FuncGen = struct {
56355610 // Functions with an empty error set are emitted with an error code
56365611 // return type and return zero so they can be function pointers coerced
56375612 // to functions that return anyerror.
5638 _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(), 0));
5613 _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(pt), 0));
56395614 } else {
56405615 _ = try self.wip.retVoid();
56415616 }
56425617 return;
56435618 }
56445619
5645 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
5620 const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info);
56465621 const operand = try self.resolveInst(un_op);
56475622 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false;
56485623 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
......@@ -5650,7 +5625,7 @@ pub const FuncGen = struct {
56505625 if (val_is_undef and safety) {
56515626 const llvm_ret_ty = operand.typeOfWip(&self.wip);
56525627 const rp = try self.buildAlloca(llvm_ret_ty, alignment);
5653 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu));
5628 const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), ret_ty.abiSize(zcu));
56545629 _ = try self.wip.callMemSet(
56555630 rp,
56565631 alignment,
......@@ -5688,7 +5663,7 @@ pub const FuncGen = struct {
56885663
56895664 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !void {
56905665 const o = self.ng.object;
5691 const pt = o.pt;
5666 const pt = self.ng.pt;
56925667 const zcu = pt.zcu;
56935668 const ip = &zcu.intern_pool;
56945669 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
......@@ -5700,7 +5675,7 @@ pub const FuncGen = struct {
57005675 // Functions with an empty error set are emitted with an error code
57015676 // return type and return zero so they can be function pointers coerced
57025677 // to functions that return anyerror.
5703 _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(), 0));
5678 _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(pt), 0));
57045679 } else {
57055680 _ = try self.wip.retVoid();
57065681 }
......@@ -5711,7 +5686,7 @@ pub const FuncGen = struct {
57115686 return;
57125687 }
57135688 const ptr = try self.resolveInst(un_op);
5714 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
5689 const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info);
57155690 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
57165691 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, ""));
57175692 return;
......@@ -5719,22 +5694,23 @@ pub const FuncGen = struct {
57195694
57205695 fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57215696 const o = self.ng.object;
5697 const pt = self.ng.pt;
57225698 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
57235699 const list = try self.resolveInst(ty_op.operand);
57245700 const arg_ty = ty_op.ty.toType();
5725 const llvm_arg_ty = try o.lowerType(arg_ty);
5701 const llvm_arg_ty = try o.lowerType(pt, arg_ty);
57265702
57275703 return self.wip.vaArg(list, llvm_arg_ty, "");
57285704 }
57295705
57305706 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57315707 const o = self.ng.object;
5732 const pt = o.pt;
5708 const pt = self.ng.pt;
57335709 const zcu = pt.zcu;
57345710 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
57355711 const src_list = try self.resolveInst(ty_op.operand);
57365712 const va_list_ty = ty_op.ty.toType();
5737 const llvm_va_list_ty = try o.lowerType(va_list_ty);
5713 const llvm_va_list_ty = try o.lowerType(pt, va_list_ty);
57385714
57395715 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
57405716 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);
......@@ -5756,10 +5732,10 @@ pub const FuncGen = struct {
57565732
57575733 fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57585734 const o = self.ng.object;
5759 const pt = o.pt;
5735 const pt = self.ng.pt;
57605736 const zcu = pt.zcu;
57615737 const va_list_ty = self.typeOfIndex(inst);
5762 const llvm_va_list_ty = try o.lowerType(va_list_ty);
5738 const llvm_va_list_ty = try o.lowerType(pt, va_list_ty);
57635739
57645740 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
57655741 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);
......@@ -5799,9 +5775,10 @@ pub const FuncGen = struct {
57995775
58005776 fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
58015777 const o = self.ng.object;
5778 const pt = self.ng.pt;
58025779 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
58035780 const operand = try self.resolveInst(un_op);
5804 const llvm_fn = try o.getCmpLtErrorsLenFunction();
5781 const llvm_fn = try o.getCmpLtErrorsLenFunction(pt);
58055782 return self.wip.call(
58065783 .normal,
58075784 .fastcc,
......@@ -5822,7 +5799,7 @@ pub const FuncGen = struct {
58225799 rhs: Builder.Value,
58235800 ) Allocator.Error!Builder.Value {
58245801 const o = self.ng.object;
5825 const pt = o.pt;
5802 const pt = self.ng.pt;
58265803 const zcu = pt.zcu;
58275804 const ip = &zcu.intern_pool;
58285805 const scalar_ty = operand_ty.scalarType(zcu);
......@@ -5839,7 +5816,7 @@ pub const FuncGen = struct {
58395816 // We need to emit instructions to check for equality/inequality
58405817 // of optionals that are not pointers.
58415818 const is_by_ref = isByRef(scalar_ty, zcu);
5842 const opt_llvm_ty = try o.lowerType(scalar_ty);
5819 const opt_llvm_ty = try o.lowerType(pt, scalar_ty);
58435820 const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref, .normal);
58445821 const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref, .normal);
58455822 const llvm_i2 = try o.builder.intType(2);
......@@ -5936,7 +5913,7 @@ pub const FuncGen = struct {
59365913 body: []const Air.Inst.Index,
59375914 ) !Builder.Value {
59385915 const o = self.ng.object;
5939 const pt = o.pt;
5916 const pt = self.ng.pt;
59405917 const zcu = pt.zcu;
59415918 const inst_ty = self.typeOfIndex(inst);
59425919
......@@ -5963,7 +5940,7 @@ pub const FuncGen = struct {
59635940
59645941 // Create a phi node only if the block returns a value.
59655942 if (have_block_result) {
5966 const raw_llvm_ty = try o.lowerType(inst_ty);
5943 const raw_llvm_ty = try o.lowerType(pt, inst_ty);
59675944 const llvm_ty: Builder.Type = ty: {
59685945 // If the zig tag type is a function, this represents an actual function body; not
59695946 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead
......@@ -5986,8 +5963,7 @@ pub const FuncGen = struct {
59865963 }
59875964
59885965 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !void {
5989 const o = self.ng.object;
5990 const zcu = o.pt.zcu;
5966 const zcu = self.ng.pt.zcu;
59915967 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
59925968 const block = self.blocks.get(branch.block_inst).?;
59935969
......@@ -6017,7 +5993,7 @@ pub const FuncGen = struct {
60175993 dispatch_info: SwitchDispatchInfo,
60185994 ) !void {
60195995 const o = self.ng.object;
6020 const pt = o.pt;
5996 const pt = self.ng.pt;
60215997 const zcu = pt.zcu;
60225998 const cond_ty = self.typeOf(cond_ref);
60235999 const switch_br = self.air.unwrapSwitch(switch_inst);
......@@ -6081,7 +6057,7 @@ pub const FuncGen = struct {
60816057 const table_index = try self.wip.cast(
60826058 .zext,
60836059 try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""),
6084 try o.lowerType(Type.usize),
6060 try o.lowerType(pt, Type.usize),
60856061 "",
60866062 );
60876063 const target_ptr_ptr = try self.wip.gep(
......@@ -6108,7 +6084,7 @@ pub const FuncGen = struct {
61086084 // The switch prongs will correspond to our scalar cases. Ranges will
61096085 // be handled by conditional branches in the `else` prong.
61106086
6111 const llvm_usize = try o.lowerType(Type.usize);
6087 const llvm_usize = try o.lowerType(pt, Type.usize);
61126088 const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder))
61136089 try self.wip.cast(.ptrtoint, cond, llvm_usize, "")
61146090 else
......@@ -6268,8 +6244,7 @@ pub const FuncGen = struct {
62686244 }
62696245
62706246 fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index, err_cold: bool) !Builder.Value {
6271 const o = self.ng.object;
6272 const pt = o.pt;
6247 const pt = self.ng.pt;
62736248 const zcu = pt.zcu;
62746249 const inst = body_tail[0];
62756250 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
......@@ -6284,8 +6259,7 @@ pub const FuncGen = struct {
62846259 }
62856260
62866261 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) !Builder.Value {
6287 const o = self.ng.object;
6288 const zcu = o.pt.zcu;
6262 const zcu = self.ng.pt.zcu;
62896263 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
62906264 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
62916265 const err_union_ptr = try self.resolveInst(extra.data.ptr);
......@@ -6309,12 +6283,12 @@ pub const FuncGen = struct {
63096283 err_cold: bool,
63106284 ) !Builder.Value {
63116285 const o = fg.ng.object;
6312 const pt = o.pt;
6286 const pt = fg.ng.pt;
63136287 const zcu = pt.zcu;
63146288 const payload_ty = err_union_ty.errorUnionPayload(zcu);
63156289 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
6316 const err_union_llvm_ty = try o.lowerType(err_union_ty);
6317 const error_type = try o.errorIntType();
6290 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
6291 const error_type = try o.errorIntType(pt);
63186292
63196293 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
63206294 const loaded = loaded: {
......@@ -6378,7 +6352,8 @@ pub const FuncGen = struct {
63786352
63796353 fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) !void {
63806354 const o = self.ng.object;
6381 const zcu = o.pt.zcu;
6355 const pt = self.ng.pt;
6356 const zcu = pt.zcu;
63826357
63836358 const switch_br = self.air.unwrapSwitch(inst);
63846359
......@@ -6483,8 +6458,8 @@ pub const FuncGen = struct {
64836458 const table_includes_else = item_count != table_len;
64846459
64856460 break :jmp_table .{
6486 .min = try o.lowerValue(min.toIntern()),
6487 .max = try o.lowerValue(max.toIntern()),
6461 .min = try o.lowerValue(pt, min.toIntern()),
6462 .max = try o.lowerValue(pt, max.toIntern()),
64886463 .in_bounds_hint = if (table_includes_else) .none else switch (switch_br.getElseHint()) {
64896464 .none, .cold => .none,
64906465 .unpredictable => .unpredictable,
......@@ -6591,7 +6566,7 @@ pub const FuncGen = struct {
65916566 }
65926567
65936568 fn switchCaseItemRange(self: *FuncGen, switch_br: Air.UnwrappedSwitch) [2]Value {
6594 const zcu = self.ng.object.pt.zcu;
6569 const zcu = self.ng.pt.zcu;
65956570 var it = switch_br.iterateCases();
65966571 var min: ?Value = null;
65976572 var max: ?Value = null;
......@@ -6633,18 +6608,18 @@ pub const FuncGen = struct {
66336608
66346609 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
66356610 const o = self.ng.object;
6636 const pt = o.pt;
6611 const pt = self.ng.pt;
66376612 const zcu = pt.zcu;
66386613 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
66396614 const operand_ty = self.typeOf(ty_op.operand);
66406615 const array_ty = operand_ty.childType(zcu);
6641 const llvm_usize = try o.lowerType(Type.usize);
6616 const llvm_usize = try o.lowerType(pt, Type.usize);
66426617 const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu));
6643 const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
6618 const slice_llvm_ty = try o.lowerType(pt, self.typeOfIndex(inst));
66446619 const operand = try self.resolveInst(ty_op.operand);
66456620 if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu))
66466621 return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, "");
6647 const ptr = try self.wip.gep(.inbounds, try o.lowerType(array_ty), operand, &.{
6622 const ptr = try self.wip.gep(.inbounds, try o.lowerType(pt, array_ty), operand, &.{
66486623 try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0),
66496624 }, "");
66506625 return self.wip.buildAggregate(slice_llvm_ty, &.{ ptr, len }, "");
......@@ -6652,7 +6627,7 @@ pub const FuncGen = struct {
66526627
66536628 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
66546629 const o = self.ng.object;
6655 const pt = o.pt;
6630 const pt = self.ng.pt;
66566631 const zcu = pt.zcu;
66576632 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
66586633
......@@ -6663,7 +6638,7 @@ pub const FuncGen = struct {
66636638
66646639 const dest_ty = self.typeOfIndex(inst);
66656640 const dest_scalar_ty = dest_ty.scalarType(zcu);
6666 const dest_llvm_ty = try o.lowerType(dest_ty);
6641 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
66676642 const target = zcu.getTarget();
66686643
66696644 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(
......@@ -6719,7 +6694,7 @@ pub const FuncGen = struct {
67196694 _ = fast;
67206695
67216696 const o = self.ng.object;
6722 const pt = o.pt;
6697 const pt = self.ng.pt;
67236698 const zcu = pt.zcu;
67246699 const target = zcu.getTarget();
67256700 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -6730,7 +6705,7 @@ pub const FuncGen = struct {
67306705
67316706 const dest_ty = self.typeOfIndex(inst);
67326707 const dest_scalar_ty = dest_ty.scalarType(zcu);
6733 const dest_llvm_ty = try o.lowerType(dest_ty);
6708 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
67346709
67356710 if (intrinsicsAllowed(operand_scalar_ty, target)) {
67366711 // TODO set fast math flag
......@@ -6762,7 +6737,7 @@ pub const FuncGen = struct {
67626737 compiler_rt_dest_abbrev,
67636738 });
67646739
6765 const operand_llvm_ty = try o.lowerType(operand_ty);
6740 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
67666741 const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty);
67676742 var result = try self.wip.call(
67686743 .normal,
......@@ -6780,16 +6755,15 @@ pub const FuncGen = struct {
67806755 }
67816756
67826757 fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
6783 const o = fg.ng.object;
6784 const zcu = o.pt.zcu;
6758 const zcu = fg.ng.pt.zcu;
67856759 return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;
67866760 }
67876761
67886762 fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
67896763 const o = fg.ng.object;
6790 const pt = o.pt;
6764 const pt = fg.ng.pt;
67916765 const zcu = pt.zcu;
6792 const llvm_usize = try o.lowerType(Type.usize);
6766 const llvm_usize = try o.lowerType(pt, Type.usize);
67936767 switch (ty.ptrSize(zcu)) {
67946768 .slice => {
67956769 const len = try fg.wip.extractValue(ptr, &.{1}, "");
......@@ -6817,18 +6791,19 @@ pub const FuncGen = struct {
68176791
68186792 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {
68196793 const o = self.ng.object;
6820 const zcu = o.pt.zcu;
6794 const pt = self.ng.pt;
6795 const zcu = pt.zcu;
68216796 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
68226797 const slice_ptr = try self.resolveInst(ty_op.operand);
68236798 const slice_ptr_ty = self.typeOf(ty_op.operand);
6824 const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(zcu));
6799 const slice_llvm_ty = try o.lowerPtrElemTy(pt, slice_ptr_ty.childType(zcu));
68256800
68266801 return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, "");
68276802 }
68286803
68296804 fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
68306805 const o = self.ng.object;
6831 const pt = o.pt;
6806 const pt = self.ng.pt;
68326807 const zcu = pt.zcu;
68336808 const inst = body_tail[0];
68346809 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
......@@ -6836,7 +6811,7 @@ pub const FuncGen = struct {
68366811 const slice = try self.resolveInst(bin_op.lhs);
68376812 const index = try self.resolveInst(bin_op.rhs);
68386813 const elem_ty = slice_ty.childType(zcu);
6839 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6814 const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty);
68406815 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
68416816 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
68426817 if (isByRef(elem_ty, zcu)) {
......@@ -6856,21 +6831,22 @@ pub const FuncGen = struct {
68566831
68576832 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
68586833 const o = self.ng.object;
6859 const zcu = o.pt.zcu;
6834 const pt = self.ng.pt;
6835 const zcu = pt.zcu;
68606836 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
68616837 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
68626838 const slice_ty = self.typeOf(bin_op.lhs);
68636839
68646840 const slice = try self.resolveInst(bin_op.lhs);
68656841 const index = try self.resolveInst(bin_op.rhs);
6866 const llvm_elem_ty = try o.lowerPtrElemTy(slice_ty.childType(zcu));
6842 const llvm_elem_ty = try o.lowerPtrElemTy(pt, slice_ty.childType(zcu));
68676843 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
68686844 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
68696845 }
68706846
68716847 fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
68726848 const o = self.ng.object;
6873 const pt = o.pt;
6849 const pt = self.ng.pt;
68746850 const zcu = pt.zcu;
68756851 const inst = body_tail[0];
68766852
......@@ -6878,11 +6854,11 @@ pub const FuncGen = struct {
68786854 const array_ty = self.typeOf(bin_op.lhs);
68796855 const array_llvm_val = try self.resolveInst(bin_op.lhs);
68806856 const rhs = try self.resolveInst(bin_op.rhs);
6881 const array_llvm_ty = try o.lowerType(array_ty);
6857 const array_llvm_ty = try o.lowerType(pt, array_ty);
68826858 const elem_ty = array_ty.childType(zcu);
68836859 if (isByRef(array_ty, zcu)) {
68846860 const indices: [2]Builder.Value = .{
6885 try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs,
6861 try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs,
68866862 };
68876863 if (isByRef(elem_ty, zcu)) {
68886864 const elem_ptr =
......@@ -6903,19 +6879,19 @@ pub const FuncGen = struct {
69036879
69046880 fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
69056881 const o = self.ng.object;
6906 const pt = o.pt;
6882 const pt = self.ng.pt;
69076883 const zcu = pt.zcu;
69086884 const inst = body_tail[0];
69096885 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
69106886 const ptr_ty = self.typeOf(bin_op.lhs);
69116887 const elem_ty = ptr_ty.childType(zcu);
6912 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6888 const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty);
69136889 const base_ptr = try self.resolveInst(bin_op.lhs);
69146890 const rhs = try self.resolveInst(bin_op.rhs);
69156891 // TODO: when we go fully opaque pointers in LLVM 16 we can remove this branch
69166892 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
69176893 // If this is a single-item pointer to an array, we need another index in the GEP.
6918 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }
6894 &.{ try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs }
69196895 else
69206896 &.{rhs}, "");
69216897 if (isByRef(elem_ty, zcu)) {
......@@ -6934,7 +6910,7 @@ pub const FuncGen = struct {
69346910
69356911 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
69366912 const o = self.ng.object;
6937 const pt = o.pt;
6913 const pt = self.ng.pt;
69386914 const zcu = pt.zcu;
69396915 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
69406916 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
......@@ -6948,10 +6924,10 @@ pub const FuncGen = struct {
69486924 const elem_ptr = ty_pl.ty.toType();
69496925 if (elem_ptr.ptrInfo(zcu).flags.vector_index != .none) return base_ptr;
69506926
6951 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6927 const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty);
69526928 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
69536929 // If this is a single-item pointer to an array, we need another index in the GEP.
6954 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }
6930 &.{ try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs }
69556931 else
69566932 &.{rhs}, "");
69576933 }
......@@ -6977,7 +6953,7 @@ pub const FuncGen = struct {
69776953
69786954 fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
69796955 const o = self.ng.object;
6980 const pt = o.pt;
6956 const pt = self.ng.pt;
69816957 const zcu = pt.zcu;
69826958 const inst = body_tail[0];
69836959 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
......@@ -6999,7 +6975,7 @@ pub const FuncGen = struct {
69996975 const shift_amt =
70006976 try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset);
70016977 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
7002 const elem_llvm_ty = try o.lowerType(field_ty);
6978 const elem_llvm_ty = try o.lowerType(pt, field_ty);
70036979 if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) {
70046980 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
70056981 const truncated_int =
......@@ -7021,7 +6997,7 @@ pub const FuncGen = struct {
70216997 .@"union" => {
70226998 assert(struct_ty.containerLayout(zcu) == .@"packed");
70236999 const containing_int = struct_llvm_val;
7024 const elem_llvm_ty = try o.lowerType(field_ty);
7000 const elem_llvm_ty = try o.lowerType(pt, field_ty);
70257001 if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) {
70267002 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
70277003 const truncated_int =
......@@ -7043,7 +7019,7 @@ pub const FuncGen = struct {
70437019 .@"struct" => {
70447020 const layout = struct_ty.containerLayout(zcu);
70457021 assert(layout != .@"packed");
7046 const struct_llvm_ty = try o.lowerType(struct_ty);
7022 const struct_llvm_ty = try o.lowerType(pt, struct_ty);
70477023 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;
70487024 const field_ptr =
70497025 try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, "");
......@@ -7064,7 +7040,7 @@ pub const FuncGen = struct {
70647040 }
70657041 },
70667042 .@"union" => {
7067 const union_llvm_ty = try o.lowerType(struct_ty);
7043 const union_llvm_ty = try o.lowerType(pt, struct_ty);
70687044 const layout = struct_ty.unionGetLayout(zcu);
70697045 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
70707046 const field_ptr =
......@@ -7083,7 +7059,7 @@ pub const FuncGen = struct {
70837059
70847060 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
70857061 const o = self.ng.object;
7086 const pt = o.pt;
7062 const pt = self.ng.pt;
70877063 const zcu = pt.zcu;
70887064 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
70897065 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
......@@ -7094,8 +7070,8 @@ pub const FuncGen = struct {
70947070 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
70957071 if (field_offset == 0) return field_ptr;
70967072
7097 const res_ty = try o.lowerType(ty_pl.ty.toType());
7098 const llvm_usize = try o.lowerType(Type.usize);
7073 const res_ty = try o.lowerType(pt, ty_pl.ty.toType());
7074 const llvm_usize = try o.lowerType(pt, Type.usize);
70997075
71007076 const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, "");
71017077 const base_ptr_int = try self.wip.bin(
......@@ -7151,7 +7127,8 @@ pub const FuncGen = struct {
71517127
71527128 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
71537129 const o = self.ng.object;
7154 const zcu = o.pt.zcu;
7130 const pt = self.ng.pt;
7131 const zcu = pt.zcu;
71557132 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
71567133 const operand = try self.resolveInst(pl_op.operand);
71577134 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
......@@ -7162,7 +7139,7 @@ pub const FuncGen = struct {
71627139 self.file,
71637140 self.scope,
71647141 self.prev_dbg_line,
7165 try o.lowerDebugType(ptr_ty.childType(zcu)),
7142 try o.lowerDebugType(pt, ptr_ty.childType(zcu)),
71667143 );
71677144
71687145 _ = try self.wip.callIntrinsic(
......@@ -7183,6 +7160,7 @@ pub const FuncGen = struct {
71837160
71847161 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index, is_arg: bool) !Builder.Value {
71857162 const o = self.ng.object;
7163 const pt = self.ng.pt;
71867164 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
71877165 const operand = try self.resolveInst(pl_op.operand);
71887166 const operand_ty = self.typeOf(pl_op.operand);
......@@ -7193,7 +7171,7 @@ pub const FuncGen = struct {
71937171 self.file,
71947172 self.scope,
71957173 self.prev_dbg_line,
7196 try o.lowerDebugType(operand_ty),
7174 try o.lowerDebugType(pt, operand_ty),
71977175 arg_no: {
71987176 self.arg_inline_index += 1;
71997177 break :arg_no self.arg_inline_index;
......@@ -7203,10 +7181,10 @@ pub const FuncGen = struct {
72037181 self.file,
72047182 self.scope,
72057183 self.prev_dbg_line,
7206 try o.lowerDebugType(operand_ty),
7184 try o.lowerDebugType(pt, operand_ty),
72077185 );
72087186
7209 const zcu = o.pt.zcu;
7187 const zcu = pt.zcu;
72107188 const owner_mod = self.ng.ownerModule();
72117189 if (isByRef(operand_ty, zcu)) {
72127190 _ = try self.wip.callIntrinsic(
......@@ -7296,7 +7274,7 @@ pub const FuncGen = struct {
72967274 // This stores whether we need to add an elementtype attribute and
72977275 // if so, the element type itself.
72987276 const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count);
7299 const pt = o.pt;
7277 const pt = self.ng.pt;
73007278 const zcu = pt.zcu;
73017279 const target = zcu.getTarget();
73027280
......@@ -7326,7 +7304,7 @@ pub const FuncGen = struct {
73267304 const output_inst = try self.resolveInst(output);
73277305 const output_ty = self.typeOf(output);
73287306 assert(output_ty.zigTypeTag(zcu) == .pointer);
7329 const elem_llvm_ty = try o.lowerPtrElemTy(output_ty.childType(zcu));
7307 const elem_llvm_ty = try o.lowerPtrElemTy(pt, output_ty.childType(zcu));
73307308
73317309 switch (constraint[0]) {
73327310 '=' => {},
......@@ -7364,7 +7342,7 @@ pub const FuncGen = struct {
73647342 is_indirect.* = false;
73657343
73667344 const ret_ty = self.typeOfIndex(inst);
7367 llvm_ret_types[llvm_ret_i] = try o.lowerType(ret_ty);
7345 llvm_ret_types[llvm_ret_i] = try o.lowerType(pt, ret_ty);
73687346 llvm_ret_i += 1;
73697347 }
73707348
......@@ -7406,7 +7384,7 @@ pub const FuncGen = struct {
74067384 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
74077385 } else {
74087386 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
7409 const arg_llvm_ty = try o.lowerType(arg_ty);
7387 const arg_llvm_ty = try o.lowerType(pt, arg_ty);
74107388 const load_inst =
74117389 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");
74127390 llvm_param_values[llvm_param_i] = load_inst;
......@@ -7447,7 +7425,7 @@ pub const FuncGen = struct {
74477425 llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: {
74487426 if (!is_by_ref) self.maybeMarkAllowZeroAccess(arg_ty.ptrInfo(zcu));
74497427
7450 break :blk try o.lowerPtrElemTy(if (is_by_ref) arg_ty else arg_ty.childType(zcu));
7428 break :blk try o.lowerPtrElemTy(pt, if (is_by_ref) arg_ty else arg_ty.childType(zcu));
74517429 } else .none;
74527430
74537431 llvm_param_i += 1;
......@@ -7465,7 +7443,7 @@ pub const FuncGen = struct {
74657443 if (constraint[0] != '+') continue;
74667444
74677445 const rw_ty = self.typeOf(output);
7468 const llvm_elem_ty = try o.lowerPtrElemTy(rw_ty.childType(zcu));
7446 const llvm_elem_ty = try o.lowerPtrElemTy(pt, rw_ty.childType(zcu));
74697447 if (is_indirect) {
74707448 llvm_param_values[llvm_param_i] = llvm_rw_val;
74717449 llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip);
......@@ -7663,13 +7641,13 @@ pub const FuncGen = struct {
76637641 cond: Builder.IntegerCondition,
76647642 ) !Builder.Value {
76657643 const o = self.ng.object;
7666 const pt = o.pt;
7644 const pt = self.ng.pt;
76677645 const zcu = pt.zcu;
76687646 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
76697647 const operand = try self.resolveInst(un_op);
76707648 const operand_ty = self.typeOf(un_op);
76717649 const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7672 const optional_llvm_ty = try o.lowerType(optional_ty);
7650 const optional_llvm_ty = try o.lowerType(pt, optional_ty);
76737651 const payload_ty = optional_ty.optionalChild(zcu);
76747652
76757653 const access_kind: Builder.MemoryAccessKind =
......@@ -7714,14 +7692,14 @@ pub const FuncGen = struct {
77147692 operand_is_ptr: bool,
77157693 ) !Builder.Value {
77167694 const o = self.ng.object;
7717 const pt = o.pt;
7695 const pt = self.ng.pt;
77187696 const zcu = pt.zcu;
77197697 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
77207698 const operand = try self.resolveInst(un_op);
77217699 const operand_ty = self.typeOf(un_op);
77227700 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
77237701 const payload_ty = err_union_ty.errorUnionPayload(zcu);
7724 const error_type = try o.errorIntType();
7702 const error_type = try o.errorIntType(pt);
77257703 const zero = try o.builder.intValue(error_type, 0);
77267704
77277705 const access_kind: Builder.MemoryAccessKind =
......@@ -7740,7 +7718,7 @@ pub const FuncGen = struct {
77407718
77417719 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
77427720 const loaded = if (operand_is_ptr)
7743 try self.wip.load(access_kind, try o.lowerType(err_union_ty), operand, .default, "")
7721 try self.wip.load(access_kind, try o.lowerType(pt, err_union_ty), operand, .default, "")
77447722 else
77457723 operand;
77467724 return self.wip.icmp(cond, loaded, zero, "");
......@@ -7749,7 +7727,7 @@ pub const FuncGen = struct {
77497727 const err_field_index = try errUnionErrorOffset(payload_ty, pt);
77507728
77517729 const loaded = if (operand_is_ptr or isByRef(err_union_ty, zcu)) loaded: {
7752 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7730 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
77537731 const err_field_ptr =
77547732 try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, "");
77557733 break :loaded try self.wip.load(access_kind, error_type, err_field_ptr, .default, "");
......@@ -7759,7 +7737,7 @@ pub const FuncGen = struct {
77597737
77607738 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
77617739 const o = self.ng.object;
7762 const pt = o.pt;
7740 const pt = self.ng.pt;
77637741 const zcu = pt.zcu;
77647742 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
77657743 const operand = try self.resolveInst(ty_op.operand);
......@@ -7774,14 +7752,14 @@ pub const FuncGen = struct {
77747752 // The payload and the optional are the same value.
77757753 return operand;
77767754 }
7777 return self.wip.gepStruct(try o.lowerType(optional_ty), operand, 0, "");
7755 return self.wip.gepStruct(try o.lowerType(pt, optional_ty), operand, 0, "");
77787756 }
77797757
77807758 fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
77817759 comptime assert(optional_layout_version == 3);
77827760
77837761 const o = self.ng.object;
7784 const pt = o.pt;
7762 const pt = self.ng.pt;
77857763 const zcu = pt.zcu;
77867764 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
77877765 const operand = try self.resolveInst(ty_op.operand);
......@@ -7807,7 +7785,7 @@ pub const FuncGen = struct {
78077785 }
78087786
78097787 // First set the non-null bit.
7810 const optional_llvm_ty = try o.lowerType(optional_ty);
7788 const optional_llvm_ty = try o.lowerType(pt, optional_ty);
78117789 const non_null_ptr = try self.wip.gepStruct(optional_llvm_ty, operand, 1, "");
78127790
78137791 self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu));
......@@ -7823,7 +7801,7 @@ pub const FuncGen = struct {
78237801
78247802 fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
78257803 const o = self.ng.object;
7826 const pt = o.pt;
7804 const pt = self.ng.pt;
78277805 const zcu = pt.zcu;
78287806 const inst = body_tail[0];
78297807 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -7837,7 +7815,7 @@ pub const FuncGen = struct {
78377815 return operand;
78387816 }
78397817
7840 const opt_llvm_ty = try o.lowerType(optional_ty);
7818 const opt_llvm_ty = try o.lowerType(pt, optional_ty);
78417819 const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false;
78427820 return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load);
78437821 }
......@@ -7848,7 +7826,7 @@ pub const FuncGen = struct {
78487826 operand_is_ptr: bool,
78497827 ) !Builder.Value {
78507828 const o = self.ng.object;
7851 const pt = o.pt;
7829 const pt = self.ng.pt;
78527830 const zcu = pt.zcu;
78537831 const inst = body_tail[0];
78547832 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -7862,7 +7840,7 @@ pub const FuncGen = struct {
78627840 return if (operand_is_ptr) operand else .none;
78637841 }
78647842 const offset = try errUnionPayloadOffset(payload_ty, pt);
7865 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7843 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
78667844 if (operand_is_ptr) {
78677845 return self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
78687846 } else if (isByRef(err_union_ty, zcu)) {
......@@ -7884,12 +7862,12 @@ pub const FuncGen = struct {
78847862 operand_is_ptr: bool,
78857863 ) !Builder.Value {
78867864 const o = self.ng.object;
7887 const pt = o.pt;
7865 const pt = self.ng.pt;
78887866 const zcu = pt.zcu;
78897867 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
78907868 const operand = try self.resolveInst(ty_op.operand);
78917869 const operand_ty = self.typeOf(ty_op.operand);
7892 const error_type = try o.errorIntType();
7870 const error_type = try o.errorIntType(pt);
78937871 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
78947872 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
78957873 if (operand_is_ptr) {
......@@ -7916,7 +7894,7 @@ pub const FuncGen = struct {
79167894 if (operand_is_ptr or isByRef(err_union_ty, zcu)) {
79177895 if (operand_is_ptr) self.maybeMarkAllowZeroAccess(operand_ty.ptrInfo(zcu));
79187896
7919 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7897 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
79207898 const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
79217899 return self.wip.load(access_kind, error_type, err_field_ptr, .default, "");
79227900 }
......@@ -7926,7 +7904,7 @@ pub const FuncGen = struct {
79267904
79277905 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
79287906 const o = self.ng.object;
7929 const pt = o.pt;
7907 const pt = self.ng.pt;
79307908 const zcu = pt.zcu;
79317909 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
79327910 const operand = try self.resolveInst(ty_op.operand);
......@@ -7934,7 +7912,7 @@ pub const FuncGen = struct {
79347912 const err_union_ty = err_union_ptr_ty.childType(zcu);
79357913
79367914 const payload_ty = err_union_ty.errorUnionPayload(zcu);
7937 const non_error_val = try o.builder.intValue(try o.errorIntType(), 0);
7915 const non_error_val = try o.builder.intValue(try o.errorIntType(pt), 0);
79387916
79397917 const access_kind: Builder.MemoryAccessKind =
79407918 if (err_union_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
......@@ -7945,7 +7923,7 @@ pub const FuncGen = struct {
79457923 _ = try self.wip.store(access_kind, non_error_val, operand, .default);
79467924 return operand;
79477925 }
7948 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7926 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
79497927 {
79507928 self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu));
79517929
......@@ -7976,14 +7954,14 @@ pub const FuncGen = struct {
79767954
79777955 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
79787956 const o = self.ng.object;
7979 const pt = o.pt;
7957 const pt = self.ng.pt;
79807958 const zcu = pt.zcu;
79817959
79827960 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
79837961 const struct_ty = ty_pl.ty.toType();
79847962 const field_index = ty_pl.payload;
79857963
7986 const struct_llvm_ty = try o.lowerType(struct_ty);
7964 const struct_llvm_ty = try o.lowerType(pt, struct_ty);
79877965 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;
79887966 assert(self.err_ret_trace != .none);
79897967 const field_ptr =
......@@ -8022,7 +8000,7 @@ pub const FuncGen = struct {
80228000
80238001 fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
80248002 const o = self.ng.object;
8025 const pt = o.pt;
8003 const pt = self.ng.pt;
80268004 const zcu = pt.zcu;
80278005 const inst = body_tail[0];
80288006 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -8033,7 +8011,7 @@ pub const FuncGen = struct {
80338011 const operand = try self.resolveInst(ty_op.operand);
80348012 const optional_ty = self.typeOfIndex(inst);
80358013 if (optional_ty.optionalReprIsPayload(zcu)) return operand;
8036 const llvm_optional_ty = try o.lowerType(optional_ty);
8014 const llvm_optional_ty = try o.lowerType(pt, optional_ty);
80378015 if (isByRef(optional_ty, zcu)) {
80388016 const directReturn = self.isNextRet(body_tail);
80398017 const optional_ptr = if (directReturn)
......@@ -8056,7 +8034,7 @@ pub const FuncGen = struct {
80568034
80578035 fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
80588036 const o = self.ng.object;
8059 const pt = o.pt;
8037 const pt = self.ng.pt;
80608038 const zcu = pt.zcu;
80618039 const inst = body_tail[0];
80628040 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -8066,8 +8044,8 @@ pub const FuncGen = struct {
80668044 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
80678045 return operand;
80688046 }
8069 const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0);
8070 const err_un_llvm_ty = try o.lowerType(err_un_ty);
8047 const ok_err_code = try o.builder.intValue(try o.errorIntType(pt), 0);
8048 const err_un_llvm_ty = try o.lowerType(pt, err_un_ty);
80718049
80728050 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
80738051 const error_offset = try errUnionErrorOffset(payload_ty, pt);
......@@ -8098,7 +8076,7 @@ pub const FuncGen = struct {
80988076
80998077 fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
81008078 const o = self.ng.object;
8101 const pt = o.pt;
8079 const pt = self.ng.pt;
81028080 const zcu = pt.zcu;
81038081 const inst = body_tail[0];
81048082 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -8106,7 +8084,7 @@ pub const FuncGen = struct {
81068084 const payload_ty = err_un_ty.errorUnionPayload(zcu);
81078085 const operand = try self.resolveInst(ty_op.operand);
81088086 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return operand;
8109 const err_un_llvm_ty = try o.lowerType(err_un_ty);
8087 const err_un_llvm_ty = try o.lowerType(pt, err_un_ty);
81108088
81118089 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
81128090 const error_offset = try errUnionErrorOffset(payload_ty, pt);
......@@ -8139,9 +8117,10 @@ pub const FuncGen = struct {
81398117
81408118 fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81418119 const o = self.ng.object;
8120 const pt = self.ng.pt;
81428121 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
81438122 const index = pl_op.payload;
8144 const llvm_usize = try o.lowerType(Type.usize);
8123 const llvm_usize = try o.lowerType(pt, Type.usize);
81458124 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{
81468125 try o.builder.intValue(.i32, index),
81478126 }, "");
......@@ -8149,9 +8128,10 @@ pub const FuncGen = struct {
81498128
81508129 fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81518130 const o = self.ng.object;
8131 const pt = self.ng.pt;
81528132 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
81538133 const index = pl_op.payload;
8154 const llvm_isize = try o.lowerType(Type.isize);
8134 const llvm_isize = try o.lowerType(pt, Type.isize);
81558135 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{
81568136 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
81578137 }, "");
......@@ -8159,7 +8139,7 @@ pub const FuncGen = struct {
81598139
81608140 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81618141 const o = self.ng.object;
8162 const pt = o.pt;
8142 const pt = self.ng.pt;
81638143 const zcu = pt.zcu;
81648144 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
81658145 const extra = self.air.extraData(Air.Bin, data.payload).data;
......@@ -8175,7 +8155,7 @@ pub const FuncGen = struct {
81758155 // https://github.com/ziglang/zig/issues/18652#issuecomment-2452844908
81768156 const access_kind: Builder.MemoryAccessKind =
81778157 if (vector_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
8178 const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(zcu));
8158 const elem_llvm_ty = try o.lowerType(pt, vector_ptr_ty.childType(zcu));
81798159 const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm();
81808160 const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, "");
81818161
......@@ -8186,14 +8166,16 @@ pub const FuncGen = struct {
81868166
81878167 fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81888168 const o = fg.ng.object;
8169 const pt = fg.ng.pt;
81898170 const ty_nav = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav;
8190 const llvm_ptr_const = try o.lowerNavRefValue(ty_nav.nav);
8171 const llvm_ptr_const = try o.lowerNavRefValue(pt, ty_nav.nav);
81918172 return llvm_ptr_const.toValue();
81928173 }
81938174
81948175 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81958176 const o = self.ng.object;
8196 const zcu = o.pt.zcu;
8177 const pt = self.ng.pt;
8178 const zcu = pt.zcu;
81978179 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
81988180 const lhs = try self.resolveInst(bin_op.lhs);
81998181 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8205,7 +8187,7 @@ pub const FuncGen = struct {
82058187 .normal,
82068188 .none,
82078189 if (scalar_ty.isSignedInt(zcu)) .smin else .umin,
8208 &.{try o.lowerType(inst_ty)},
8190 &.{try o.lowerType(pt, inst_ty)},
82098191 &.{ lhs, rhs },
82108192 "",
82118193 );
......@@ -8213,7 +8195,8 @@ pub const FuncGen = struct {
82138195
82148196 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
82158197 const o = self.ng.object;
8216 const zcu = o.pt.zcu;
8198 const pt = self.ng.pt;
8199 const zcu = pt.zcu;
82178200 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
82188201 const lhs = try self.resolveInst(bin_op.lhs);
82198202 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8225,7 +8208,7 @@ pub const FuncGen = struct {
82258208 .normal,
82268209 .none,
82278210 if (scalar_ty.isSignedInt(zcu)) .smax else .umax,
8228 &.{try o.lowerType(inst_ty)},
8211 &.{try o.lowerType(pt, inst_ty)},
82298212 &.{ lhs, rhs },
82308213 "",
82318214 );
......@@ -8233,17 +8216,17 @@ pub const FuncGen = struct {
82338216
82348217 fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
82358218 const o = self.ng.object;
8219 const pt = self.ng.pt;
82368220 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
82378221 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
82388222 const ptr = try self.resolveInst(bin_op.lhs);
82398223 const len = try self.resolveInst(bin_op.rhs);
82408224 const inst_ty = self.typeOfIndex(inst);
8241 return self.wip.buildAggregate(try o.lowerType(inst_ty), &.{ ptr, len }, "");
8225 return self.wip.buildAggregate(try o.lowerType(pt, inst_ty), &.{ ptr, len }, "");
82428226 }
82438227
82448228 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8245 const o = self.ng.object;
8246 const zcu = o.pt.zcu;
8229 const zcu = self.ng.pt.zcu;
82478230 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
82488231 const lhs = try self.resolveInst(bin_op.lhs);
82498232 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8261,7 +8244,8 @@ pub const FuncGen = struct {
82618244 unsigned_intrinsic: Builder.Intrinsic,
82628245 ) !Builder.Value {
82638246 const o = fg.ng.object;
8264 const zcu = o.pt.zcu;
8247 const pt = fg.ng.pt;
8248 const zcu = pt.zcu;
82658249
82668250 const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
82678251 const lhs = try fg.resolveInst(bin_op.lhs);
......@@ -8270,7 +8254,7 @@ pub const FuncGen = struct {
82708254 const scalar_ty = inst_ty.scalarType(zcu);
82718255
82728256 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
8273 const llvm_inst_ty = try o.lowerType(inst_ty);
8257 const llvm_inst_ty = try o.lowerType(pt, inst_ty);
82748258 const results =
82758259 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");
82768260
......@@ -8309,7 +8293,8 @@ pub const FuncGen = struct {
83098293
83108294 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
83118295 const o = self.ng.object;
8312 const zcu = o.pt.zcu;
8296 const pt = self.ng.pt;
8297 const zcu = pt.zcu;
83138298 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83148299 const lhs = try self.resolveInst(bin_op.lhs);
83158300 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8321,15 +8306,14 @@ pub const FuncGen = struct {
83218306 .normal,
83228307 .none,
83238308 if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat",
8324 &.{try o.lowerType(inst_ty)},
8309 &.{try o.lowerType(pt, inst_ty)},
83258310 &.{ lhs, rhs },
83268311 "",
83278312 );
83288313 }
83298314
83308315 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8331 const o = self.ng.object;
8332 const zcu = o.pt.zcu;
8316 const zcu = self.ng.pt.zcu;
83338317 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83348318 const lhs = try self.resolveInst(bin_op.lhs);
83358319 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8350,7 +8334,8 @@ pub const FuncGen = struct {
83508334
83518335 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
83528336 const o = self.ng.object;
8353 const zcu = o.pt.zcu;
8337 const pt = self.ng.pt;
8338 const zcu = pt.zcu;
83548339 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83558340 const lhs = try self.resolveInst(bin_op.lhs);
83568341 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8362,15 +8347,14 @@ pub const FuncGen = struct {
83628347 .normal,
83638348 .none,
83648349 if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat",
8365 &.{try o.lowerType(inst_ty)},
8350 &.{try o.lowerType(pt, inst_ty)},
83668351 &.{ lhs, rhs },
83678352 "",
83688353 );
83698354 }
83708355
83718356 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8372 const o = self.ng.object;
8373 const zcu = o.pt.zcu;
8357 const zcu = self.ng.pt.zcu;
83748358 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83758359 const lhs = try self.resolveInst(bin_op.lhs);
83768360 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8391,7 +8375,8 @@ pub const FuncGen = struct {
83918375
83928376 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
83938377 const o = self.ng.object;
8394 const zcu = o.pt.zcu;
8378 const pt = self.ng.pt;
8379 const zcu = pt.zcu;
83958380 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83968381 const lhs = try self.resolveInst(bin_op.lhs);
83978382 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8403,7 +8388,7 @@ pub const FuncGen = struct {
84038388 .normal,
84048389 .none,
84058390 if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat",
8406 &.{try o.lowerType(inst_ty)},
8391 &.{try o.lowerType(pt, inst_ty)},
84078392 &.{ lhs, rhs, .@"0" },
84088393 "",
84098394 );
......@@ -8419,8 +8404,7 @@ pub const FuncGen = struct {
84198404 }
84208405
84218406 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8422 const o = self.ng.object;
8423 const zcu = o.pt.zcu;
8407 const zcu = self.ng.pt.zcu;
84248408 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84258409 const lhs = try self.resolveInst(bin_op.lhs);
84268410 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8436,7 +8420,8 @@ pub const FuncGen = struct {
84368420
84378421 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
84388422 const o = self.ng.object;
8439 const zcu = o.pt.zcu;
8423 const pt = self.ng.pt;
8424 const zcu = pt.zcu;
84408425 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84418426 const lhs = try self.resolveInst(bin_op.lhs);
84428427 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8448,7 +8433,7 @@ pub const FuncGen = struct {
84488433 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});
84498434 }
84508435 if (scalar_ty.isSignedInt(zcu)) {
8451 const inst_llvm_ty = try o.lowerType(inst_ty);
8436 const inst_llvm_ty = try o.lowerType(pt, inst_ty);
84528437
84538438 const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb;
84548439 var stack align(@max(
......@@ -8485,8 +8470,7 @@ pub const FuncGen = struct {
84858470 }
84868471
84878472 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8488 const o = self.ng.object;
8489 const zcu = o.pt.zcu;
8473 const zcu = self.ng.pt.zcu;
84908474 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84918475 const lhs = try self.resolveInst(bin_op.lhs);
84928476 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8503,8 +8487,7 @@ pub const FuncGen = struct {
85038487 }
85048488
85058489 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8506 const o = self.ng.object;
8507 const zcu = o.pt.zcu;
8490 const zcu = self.ng.pt.zcu;
85088491 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85098492 const lhs = try self.resolveInst(bin_op.lhs);
85108493 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8521,12 +8504,13 @@ pub const FuncGen = struct {
85218504
85228505 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
85238506 const o = self.ng.object;
8524 const zcu = o.pt.zcu;
8507 const pt = self.ng.pt;
8508 const zcu = pt.zcu;
85258509 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85268510 const lhs = try self.resolveInst(bin_op.lhs);
85278511 const rhs = try self.resolveInst(bin_op.rhs);
85288512 const inst_ty = self.typeOfIndex(inst);
8529 const inst_llvm_ty = try o.lowerType(inst_ty);
8513 const inst_llvm_ty = try o.lowerType(pt, inst_ty);
85308514 const scalar_ty = inst_ty.scalarType(zcu);
85318515
85328516 if (scalar_ty.isRuntimeFloat()) {
......@@ -8574,17 +8558,18 @@ pub const FuncGen = struct {
85748558
85758559 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85768560 const o = self.ng.object;
8577 const zcu = o.pt.zcu;
8561 const pt = self.ng.pt;
8562 const zcu = pt.zcu;
85788563 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
85798564 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
85808565 const ptr = try self.resolveInst(bin_op.lhs);
85818566 const offset = try self.resolveInst(bin_op.rhs);
85828567 const ptr_ty = self.typeOf(bin_op.lhs);
8583 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8568 const llvm_elem_ty = try o.lowerPtrElemTy(pt, ptr_ty.childType(zcu));
85848569 switch (ptr_ty.ptrSize(zcu)) {
85858570 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
85868571 .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
8587 try o.builder.intValue(try o.lowerType(Type.usize), 0), offset,
8572 try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), offset,
85888573 }, ""),
85898574 .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""),
85908575 .slice => {
......@@ -8596,18 +8581,19 @@ pub const FuncGen = struct {
85968581
85978582 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85988583 const o = self.ng.object;
8599 const zcu = o.pt.zcu;
8584 const pt = self.ng.pt;
8585 const zcu = pt.zcu;
86008586 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
86018587 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
86028588 const ptr = try self.resolveInst(bin_op.lhs);
86038589 const offset = try self.resolveInst(bin_op.rhs);
86048590 const negative_offset = try self.wip.neg(offset, "");
86058591 const ptr_ty = self.typeOf(bin_op.lhs);
8606 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8592 const llvm_elem_ty = try o.lowerPtrElemTy(pt, ptr_ty.childType(zcu));
86078593 switch (ptr_ty.ptrSize(zcu)) {
86088594 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
86098595 .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
8610 try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset,
8596 try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), negative_offset,
86118597 }, ""),
86128598 .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""),
86138599 .slice => {
......@@ -8624,7 +8610,7 @@ pub const FuncGen = struct {
86248610 unsigned_intrinsic: Builder.Intrinsic,
86258611 ) !Builder.Value {
86268612 const o = self.ng.object;
8627 const pt = o.pt;
8613 const pt = self.ng.pt;
86288614 const zcu = pt.zcu;
86298615 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
86308616 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
......@@ -8637,8 +8623,8 @@ pub const FuncGen = struct {
86378623 const inst_ty = self.typeOfIndex(inst);
86388624
86398625 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
8640 const llvm_inst_ty = try o.lowerType(inst_ty);
8641 const llvm_lhs_ty = try o.lowerType(lhs_ty);
8626 const llvm_inst_ty = try o.lowerType(pt, inst_ty);
8627 const llvm_lhs_ty = try o.lowerType(pt, lhs_ty);
86428628 const results =
86438629 try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, "");
86448630
......@@ -8718,7 +8704,7 @@ pub const FuncGen = struct {
87188704 return o.builder.addFunction(
87198705 try o.builder.fnType(return_type, param_types, .normal),
87208706 fn_name,
8721 toLlvmAddressSpace(.generic, o.pt.zcu.getTarget()),
8707 toLlvmAddressSpace(.generic, self.ng.pt.zcu.getTarget()),
87228708 );
87238709 }
87248710
......@@ -8732,10 +8718,11 @@ pub const FuncGen = struct {
87328718 params: [2]Builder.Value,
87338719 ) !Builder.Value {
87348720 const o = self.ng.object;
8735 const zcu = o.pt.zcu;
8721 const pt = self.ng.pt;
8722 const zcu = pt.zcu;
87368723 const target = zcu.getTarget();
87378724 const scalar_ty = ty.scalarType(zcu);
8738 const scalar_llvm_ty = try o.lowerType(scalar_ty);
8725 const scalar_llvm_ty = try o.lowerType(pt, scalar_ty);
87398726
87408727 if (intrinsicsAllowed(scalar_ty, target)) {
87418728 const cond: Builder.FloatCondition = switch (pred) {
......@@ -8838,10 +8825,11 @@ pub const FuncGen = struct {
88388825 params: [params_len]Builder.Value,
88398826 ) !Builder.Value {
88408827 const o = self.ng.object;
8841 const zcu = o.pt.zcu;
8828 const pt = self.ng.pt;
8829 const zcu = pt.zcu;
88428830 const target = zcu.getTarget();
88438831 const scalar_ty = ty.scalarType(zcu);
8844 const llvm_ty = try o.lowerType(ty);
8832 const llvm_ty = try o.lowerType(pt, ty);
88458833
88468834 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {
88478835 // Some operations are dedicated LLVM instructions, not available as intrinsics
......@@ -8979,7 +8967,7 @@ pub const FuncGen = struct {
89798967
89808968 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
89818969 const o = self.ng.object;
8982 const pt = o.pt;
8970 const pt = self.ng.pt;
89838971 const zcu = pt.zcu;
89848972 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
89858973 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
......@@ -8993,9 +8981,9 @@ pub const FuncGen = struct {
89938981 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
89948982
89958983 const dest_ty = self.typeOfIndex(inst);
8996 const llvm_dest_ty = try o.lowerType(dest_ty);
8984 const llvm_dest_ty = try o.lowerType(pt, dest_ty);
89978985
8998 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
8986 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), "");
89998987
90008988 const result = try self.wip.bin(.shl, lhs, casted_rhs, "");
90018989 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
......@@ -9052,7 +9040,8 @@ pub const FuncGen = struct {
90529040
90539041 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
90549042 const o = self.ng.object;
9055 const zcu = o.pt.zcu;
9043 const pt = self.ng.pt;
9044 const zcu = pt.zcu;
90569045 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
90579046
90589047 const lhs = try self.resolveInst(bin_op.lhs);
......@@ -9063,7 +9052,7 @@ pub const FuncGen = struct {
90639052 return self.ng.todo("implement vector shifts with scalar rhs", .{});
90649053 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
90659054
9066 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
9055 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), "");
90679056 return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
90689057 .@"shl nsw"
90699058 else
......@@ -9072,7 +9061,8 @@ pub const FuncGen = struct {
90729061
90739062 fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
90749063 const o = self.ng.object;
9075 const zcu = o.pt.zcu;
9064 const pt = self.ng.pt;
9065 const zcu = pt.zcu;
90769066 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
90779067
90789068 const lhs = try self.resolveInst(bin_op.lhs);
......@@ -9082,13 +9072,13 @@ pub const FuncGen = struct {
90829072 if (lhs_ty.isVector(zcu) and !self.typeOf(bin_op.rhs).isVector(zcu))
90839073 return self.ng.todo("implement vector shifts with scalar rhs", .{});
90849074
9085 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
9075 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), "");
90869076 return self.wip.bin(.shl, lhs, casted_rhs, "");
90879077 }
90889078
90899079 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
90909080 const o = self.ng.object;
9091 const pt = o.pt;
9081 const pt = self.ng.pt;
90929082 const zcu = pt.zcu;
90939083 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
90949084
......@@ -9097,7 +9087,7 @@ pub const FuncGen = struct {
90979087
90989088 const lhs_ty = self.typeOf(bin_op.lhs);
90999089 const lhs_info = lhs_ty.intInfo(zcu);
9100 const llvm_lhs_ty = try o.lowerType(lhs_ty);
9090 const llvm_lhs_ty = try o.lowerType(pt, lhs_ty);
91019091 const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder);
91029092
91039093 const rhs_ty = self.typeOf(bin_op.rhs);
......@@ -9105,7 +9095,7 @@ pub const FuncGen = struct {
91059095 return self.ng.todo("implement vector shifts with scalar rhs", .{});
91069096 const rhs_info = rhs_ty.intInfo(zcu);
91079097 assert(rhs_info.signedness == .unsigned);
9108 const llvm_rhs_ty = try o.lowerType(rhs_ty);
9098 const llvm_rhs_ty = try o.lowerType(pt, rhs_ty);
91099099 const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder);
91109100
91119101 const result = try self.wip.callIntrinsic(
......@@ -9168,7 +9158,8 @@ pub const FuncGen = struct {
91689158
91699159 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {
91709160 const o = self.ng.object;
9171 const zcu = o.pt.zcu;
9161 const pt = self.ng.pt;
9162 const zcu = pt.zcu;
91729163 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
91739164
91749165 const lhs = try self.resolveInst(bin_op.lhs);
......@@ -9179,7 +9170,7 @@ pub const FuncGen = struct {
91799170 return self.ng.todo("implement vector shifts with scalar rhs", .{});
91809171 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
91819172
9182 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
9173 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), "");
91839174 const is_signed_int = lhs_scalar_ty.isSignedInt(zcu);
91849175
91859176 return self.wip.bin(if (is_exact)
......@@ -9189,7 +9180,8 @@ pub const FuncGen = struct {
91899180
91909181 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
91919182 const o = self.ng.object;
9192 const zcu = o.pt.zcu;
9183 const pt = self.ng.pt;
9184 const zcu = pt.zcu;
91939185 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
91949186 const operand = try self.resolveInst(ty_op.operand);
91959187 const operand_ty = self.typeOf(ty_op.operand);
......@@ -9200,7 +9192,7 @@ pub const FuncGen = struct {
92009192 .normal,
92019193 .none,
92029194 .abs,
9203 &.{try o.lowerType(operand_ty)},
9195 &.{try o.lowerType(pt, operand_ty)},
92049196 &.{ operand, try o.builder.intValue(.i1, 0) },
92059197 "",
92069198 ),
......@@ -9211,10 +9203,11 @@ pub const FuncGen = struct {
92119203
92129204 fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
92139205 const o = fg.ng.object;
9214 const zcu = o.pt.zcu;
9206 const pt = fg.ng.pt;
9207 const zcu = pt.zcu;
92159208 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
92169209 const dest_ty = fg.typeOfIndex(inst);
9217 const dest_llvm_ty = try o.lowerType(dest_ty);
9210 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
92189211 const operand = try fg.resolveInst(ty_op.operand);
92199212 const operand_ty = fg.typeOf(ty_op.operand);
92209213 const operand_info = operand_ty.intInfo(zcu);
......@@ -9243,8 +9236,8 @@ pub const FuncGen = struct {
92439236
92449237 if (!have_min_check and !have_max_check) break :safety;
92459238
9246 const operand_llvm_ty = try o.lowerType(operand_ty);
9247 const operand_scalar_llvm_ty = try o.lowerType(operand_scalar);
9239 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9240 const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar);
92489241
92499242 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;
92509243 assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector));
......@@ -9313,15 +9306,17 @@ pub const FuncGen = struct {
93139306
93149307 fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
93159308 const o = self.ng.object;
9309 const pt = self.ng.pt;
93169310 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
93179311 const operand = try self.resolveInst(ty_op.operand);
9318 const dest_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
9312 const dest_llvm_ty = try o.lowerType(pt, self.typeOfIndex(inst));
93199313 return self.wip.cast(.trunc, operand, dest_llvm_ty, "");
93209314 }
93219315
93229316 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
93239317 const o = self.ng.object;
9324 const zcu = o.pt.zcu;
9318 const pt = self.ng.pt;
9319 const zcu = pt.zcu;
93259320 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
93269321 const operand = try self.resolveInst(ty_op.operand);
93279322 const operand_ty = self.typeOf(ty_op.operand);
......@@ -9329,10 +9324,10 @@ pub const FuncGen = struct {
93299324 const target = zcu.getTarget();
93309325
93319326 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {
9332 return self.wip.cast(.fptrunc, operand, try o.lowerType(dest_ty), "");
9327 return self.wip.cast(.fptrunc, operand, try o.lowerType(pt, dest_ty), "");
93339328 } else {
9334 const operand_llvm_ty = try o.lowerType(operand_ty);
9335 const dest_llvm_ty = try o.lowerType(dest_ty);
9329 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9330 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
93369331
93379332 const dest_bits = dest_ty.floatBits(target);
93389333 const src_bits = operand_ty.floatBits(target);
......@@ -9355,7 +9350,8 @@ pub const FuncGen = struct {
93559350
93569351 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
93579352 const o = self.ng.object;
9358 const zcu = o.pt.zcu;
9353 const pt = self.ng.pt;
9354 const zcu = pt.zcu;
93599355 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
93609356 const operand = try self.resolveInst(ty_op.operand);
93619357 const operand_ty = self.typeOf(ty_op.operand);
......@@ -9363,10 +9359,10 @@ pub const FuncGen = struct {
93639359 const target = zcu.getTarget();
93649360
93659361 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {
9366 return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), "");
9362 return self.wip.cast(.fpext, operand, try o.lowerType(pt, dest_ty), "");
93679363 } else {
9368 const operand_llvm_ty = try o.lowerType(operand_ty);
9369 const dest_llvm_ty = try o.lowerType(dest_ty);
9364 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9365 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
93709366
93719367 const dest_bits = dest_ty.scalarType(zcu).floatBits(target);
93729368 const src_bits = operand_ty.scalarType(zcu).floatBits(target);
......@@ -9403,11 +9399,11 @@ pub const FuncGen = struct {
94039399
94049400 fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value {
94059401 const o = self.ng.object;
9406 const pt = o.pt;
9402 const pt = self.ng.pt;
94079403 const zcu = pt.zcu;
94089404 const operand_is_ref = isByRef(operand_ty, zcu);
94099405 const result_is_ref = isByRef(inst_ty, zcu);
9410 const llvm_dest_ty = try o.lowerType(inst_ty);
9406 const llvm_dest_ty = try o.lowerType(pt, inst_ty);
94119407
94129408 if (operand_is_ref and result_is_ref) {
94139409 // They are both pointers, so just return the same opaque pointer :)
......@@ -9442,7 +9438,7 @@ pub const FuncGen = struct {
94429438 } else {
94439439 // If the ABI size of the element type is not evenly divisible by size in bits;
94449440 // a simple bitcast will not work, and we fall back to extractelement.
9445 const llvm_usize = try o.lowerType(Type.usize);
9441 const llvm_usize = try o.lowerType(pt, Type.usize);
94469442 const usize_zero = try o.builder.intValue(llvm_usize, 0);
94479443 const vector_len = operand_ty.arrayLen(zcu);
94489444 var i: u64 = 0;
......@@ -9458,7 +9454,7 @@ pub const FuncGen = struct {
94589454 return array_ptr;
94599455 } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) {
94609456 const elem_ty = operand_ty.childType(zcu);
9461 const llvm_vector_ty = try o.lowerType(inst_ty);
9457 const llvm_vector_ty = try o.lowerType(pt, inst_ty);
94629458 if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{});
94639459
94649460 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;
......@@ -9470,9 +9466,9 @@ pub const FuncGen = struct {
94709466 } else {
94719467 // If the ABI size of the element type is not evenly divisible by size in bits;
94729468 // a simple bitcast will not work, and we fall back to extractelement.
9473 const array_llvm_ty = try o.lowerType(operand_ty);
9474 const elem_llvm_ty = try o.lowerType(elem_ty);
9475 const llvm_usize = try o.lowerType(Type.usize);
9469 const array_llvm_ty = try o.lowerType(pt, operand_ty);
9470 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
9471 const llvm_usize = try o.lowerType(pt, Type.usize);
94769472 const usize_zero = try o.builder.intValue(llvm_usize, 0);
94779473 const vector_len = operand_ty.arrayLen(zcu);
94789474 var vector = try o.builder.poisonValue(llvm_vector_ty);
......@@ -9519,7 +9515,7 @@ pub const FuncGen = struct {
95199515
95209516 fn airArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
95219517 const o = self.ng.object;
9522 const pt = o.pt;
9518 const pt = self.ng.pt;
95239519 const zcu = pt.zcu;
95249520 const arg_val = self.args[self.arg_index];
95259521 self.arg_index += 1;
......@@ -9547,7 +9543,7 @@ pub const FuncGen = struct {
95479543 self.file,
95489544 self.scope,
95499545 lbrace_line,
9550 try o.lowerDebugType(inst_ty),
9546 try o.lowerDebugType(pt, inst_ty),
95519547 self.arg_index,
95529548 );
95539549
......@@ -9611,28 +9607,28 @@ pub const FuncGen = struct {
96119607
96129608 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
96139609 const o = self.ng.object;
9614 const pt = o.pt;
9610 const pt = self.ng.pt;
96159611 const zcu = pt.zcu;
96169612 const ptr_ty = self.typeOfIndex(inst);
96179613 const pointee_type = ptr_ty.childType(zcu);
96189614 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
9619 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
9615 return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue();
96209616
9621 const pointee_llvm_ty = try o.lowerType(pointee_type);
9617 const pointee_llvm_ty = try o.lowerType(pt, pointee_type);
96229618 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
96239619 return self.buildAlloca(pointee_llvm_ty, alignment);
96249620 }
96259621
96269622 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
96279623 const o = self.ng.object;
9628 const pt = o.pt;
9624 const pt = self.ng.pt;
96299625 const zcu = pt.zcu;
96309626 const ptr_ty = self.typeOfIndex(inst);
96319627 const ret_ty = ptr_ty.childType(zcu);
96329628 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
9633 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
9629 return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue();
96349630 if (self.ret_ptr != .none) return self.ret_ptr;
9635 const ret_llvm_ty = try o.lowerType(ret_ty);
9631 const ret_llvm_ty = try o.lowerType(pt, ret_ty);
96369632 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
96379633 return self.buildAlloca(ret_llvm_ty, alignment);
96389634 }
......@@ -9644,13 +9640,13 @@ pub const FuncGen = struct {
96449640 llvm_ty: Builder.Type,
96459641 alignment: Builder.Alignment,
96469642 ) Allocator.Error!Builder.Value {
9647 const target = self.ng.object.pt.zcu.getTarget();
9643 const target = self.ng.pt.zcu.getTarget();
96489644 return buildAllocaInner(&self.wip, llvm_ty, alignment, target);
96499645 }
96509646
96519647 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
96529648 const o = self.ng.object;
9653 const pt = o.pt;
9649 const pt = self.ng.pt;
96549650 const zcu = pt.zcu;
96559651 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
96569652 const dest_ptr = try self.resolveInst(bin_op.lhs);
......@@ -9685,7 +9681,7 @@ pub const FuncGen = struct {
96859681
96869682 self.maybeMarkAllowZeroAccess(ptr_info);
96879683
9688 const len = try o.builder.intValue(try o.lowerType(Type.usize), operand_ty.abiSize(zcu));
9684 const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), operand_ty.abiSize(zcu));
96899685 _ = try self.wip.callMemSet(
96909686 dest_ptr,
96919687 ptr_ty.ptrAlignment(zcu).toLlvm(),
......@@ -9714,8 +9710,7 @@ pub const FuncGen = struct {
97149710 ///
97159711 /// The first instruction of `body_tail` is the one whose copy we want to elide.
97169712 fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool {
9717 const o = fg.ng.object;
9718 const zcu = o.pt.zcu;
9713 const zcu = fg.ng.pt.zcu;
97199714 const ip = &zcu.intern_pool;
97209715 for (body_tail[1..]) |body_inst| {
97219716 switch (fg.liveness.categorizeOperand(fg.air, zcu, body_inst, body_tail[0], ip)) {
......@@ -9730,8 +9725,7 @@ pub const FuncGen = struct {
97309725 }
97319726
97329727 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
9733 const o = fg.ng.object;
9734 const pt = o.pt;
9728 const pt = fg.ng.pt;
97359729 const zcu = pt.zcu;
97369730 const inst = body_tail[0];
97379731 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -9765,8 +9759,9 @@ pub const FuncGen = struct {
97659759 fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
97669760 _ = inst;
97679761 const o = self.ng.object;
9768 const llvm_usize = try o.lowerType(Type.usize);
9769 if (!target_util.supportsReturnAddress(o.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) {
9762 const pt = self.ng.pt;
9763 const llvm_usize = try o.lowerType(pt, Type.usize);
9764 if (!target_util.supportsReturnAddress(self.ng.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) {
97709765 // https://github.com/ziglang/zig/issues/11946
97719766 return o.builder.intValue(llvm_usize, 0);
97729767 }
......@@ -9777,8 +9772,9 @@ pub const FuncGen = struct {
97779772 fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
97789773 _ = inst;
97799774 const o = self.ng.object;
9775 const pt = self.ng.pt;
97809776 const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, "");
9781 return self.wip.cast(.ptrtoint, result, try o.lowerType(Type.usize), "");
9777 return self.wip.cast(.ptrtoint, result, try o.lowerType(pt, Type.usize), "");
97829778 }
97839779
97849780 fn airCmpxchg(
......@@ -9787,7 +9783,7 @@ pub const FuncGen = struct {
97879783 kind: Builder.Function.Instruction.CmpXchg.Kind,
97889784 ) !Builder.Value {
97899785 const o = self.ng.object;
9790 const pt = o.pt;
9786 const pt = self.ng.pt;
97919787 const zcu = pt.zcu;
97929788 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
97939789 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
......@@ -9796,8 +9792,8 @@ pub const FuncGen = struct {
97969792 var expected_value = try self.resolveInst(extra.expected_value);
97979793 var new_value = try self.resolveInst(extra.new_value);
97989794 const operand_ty = ptr_ty.childType(zcu);
9799 const llvm_operand_ty = try o.lowerType(operand_ty);
9800 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);
9795 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
9796 const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false);
98019797 if (llvm_abi_ty != .none) {
98029798 // operand needs widening and truncating
98039799 const signedness: Builder.Function.Instruction.Cast.Signedness =
......@@ -9840,7 +9836,7 @@ pub const FuncGen = struct {
98409836
98419837 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
98429838 const o = self.ng.object;
9843 const pt = o.pt;
9839 const pt = self.ng.pt;
98449840 const zcu = pt.zcu;
98459841 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
98469842 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
......@@ -9852,8 +9848,8 @@ pub const FuncGen = struct {
98529848 const is_float = operand_ty.isRuntimeFloat();
98539849 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);
98549850 const ordering = toLlvmAtomicOrdering(extra.ordering());
9855 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, op == .xchg);
9856 const llvm_operand_ty = try o.lowerType(operand_ty);
9851 const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, op == .xchg);
9852 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
98579853
98589854 const access_kind: Builder.MemoryAccessKind =
98599855 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
......@@ -9896,7 +9892,7 @@ pub const FuncGen = struct {
98969892 access_kind,
98979893 op,
98989894 ptr,
9899 try self.wip.cast(.ptrtoint, operand, try o.lowerType(Type.usize), ""),
9895 try self.wip.cast(.ptrtoint, operand, try o.lowerType(pt, Type.usize), ""),
99009896 self.sync_scope,
99019897 ordering,
99029898 ptr_alignment,
......@@ -9906,7 +9902,7 @@ pub const FuncGen = struct {
99069902
99079903 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
99089904 const o = self.ng.object;
9909 const pt = o.pt;
9905 const pt = self.ng.pt;
99109906 const zcu = pt.zcu;
99119907 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
99129908 const ptr = try self.resolveInst(atomic_load.ptr);
......@@ -9915,14 +9911,14 @@ pub const FuncGen = struct {
99159911 const elem_ty = Type.fromInterned(info.child);
99169912 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
99179913 const ordering = toLlvmAtomicOrdering(atomic_load.order);
9918 const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false);
9914 const llvm_abi_ty = try o.getAtomicAbiType(pt, elem_ty, false);
99199915 const ptr_alignment = (if (info.flags.alignment != .none)
99209916 @as(InternPool.Alignment, info.flags.alignment)
99219917 else
99229918 Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm();
99239919 const access_kind: Builder.MemoryAccessKind =
99249920 if (info.flags.is_volatile) .@"volatile" else .normal;
9925 const elem_llvm_ty = try o.lowerType(elem_ty);
9921 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
99269922
99279923 self.maybeMarkAllowZeroAccess(info);
99289924
......@@ -9956,7 +9952,7 @@ pub const FuncGen = struct {
99569952 ordering: Builder.AtomicOrdering,
99579953 ) !Builder.Value {
99589954 const o = self.ng.object;
9959 const pt = o.pt;
9955 const pt = self.ng.pt;
99609956 const zcu = pt.zcu;
99619957 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
99629958 const ptr_ty = self.typeOf(bin_op.lhs);
......@@ -9964,7 +9960,7 @@ pub const FuncGen = struct {
99649960 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none;
99659961 const ptr = try self.resolveInst(bin_op.lhs);
99669962 var element = try self.resolveInst(bin_op.rhs);
9967 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);
9963 const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false);
99689964
99699965 if (llvm_abi_ty != .none) {
99709966 // operand needs widening
......@@ -9984,7 +9980,7 @@ pub const FuncGen = struct {
99849980
99859981 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
99869982 const o = self.ng.object;
9987 const pt = o.pt;
9983 const pt = self.ng.pt;
99889984 const zcu = pt.zcu;
99899985 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
99909986 const dest_slice = try self.resolveInst(bin_op.lhs);
......@@ -10081,13 +10077,13 @@ pub const FuncGen = struct {
1008110077 const body_block = try self.wip.block(1, "InlineMemsetBody");
1008210078 const end_block = try self.wip.block(1, "InlineMemsetEnd");
1008310079
10084 const llvm_usize_ty = try o.lowerType(Type.usize);
10080 const llvm_usize_ty = try o.lowerType(pt, Type.usize);
1008510081 const len = switch (ptr_ty.ptrSize(zcu)) {
1008610082 .slice => try self.wip.extractValue(dest_slice, &.{1}, ""),
1008710083 .one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)),
1008810084 .many, .c => unreachable,
1008910085 };
10090 const elem_llvm_ty = try o.lowerType(elem_ty);
10086 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
1009110087 const end_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, dest_ptr, &.{len}, "");
1009210088 _ = try self.wip.br(loop_block);
1009310089
......@@ -10121,8 +10117,7 @@ pub const FuncGen = struct {
1012110117 }
1012210118
1012310119 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10124 const o = self.ng.object;
10125 const pt = o.pt;
10120 const pt = self.ng.pt;
1012610121 const zcu = pt.zcu;
1012710122 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1012810123 const dest_slice = try self.resolveInst(bin_op.lhs);
......@@ -10151,8 +10146,7 @@ pub const FuncGen = struct {
1015110146 }
1015210147
1015310148 fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10154 const o = self.ng.object;
10155 const pt = o.pt;
10149 const pt = self.ng.pt;
1015610150 const zcu = pt.zcu;
1015710151 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1015810152 const dest_slice = try self.resolveInst(bin_op.lhs);
......@@ -10178,7 +10172,7 @@ pub const FuncGen = struct {
1017810172
1017910173 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1018010174 const o = self.ng.object;
10181 const pt = o.pt;
10175 const pt = self.ng.pt;
1018210176 const zcu = pt.zcu;
1018310177 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1018410178 const un_ptr_ty = self.typeOf(bin_op.lhs);
......@@ -10199,7 +10193,7 @@ pub const FuncGen = struct {
1019910193 return .none;
1020010194 }
1020110195 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
10202 const tag_field_ptr = try self.wip.gepStruct(try o.lowerType(un_ty), union_ptr, tag_index, "");
10196 const tag_field_ptr = try self.wip.gepStruct(try o.lowerType(pt, un_ty), union_ptr, tag_index, "");
1020310197 // TODO alignment on this store
1020410198 _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, .default);
1020510199 return .none;
......@@ -10207,7 +10201,7 @@ pub const FuncGen = struct {
1020710201
1020810202 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1020910203 const o = self.ng.object;
10210 const pt = o.pt;
10204 const pt = self.ng.pt;
1021110205 const zcu = pt.zcu;
1021210206 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1021310207 const un_ty = self.typeOf(ty_op.operand);
......@@ -10215,7 +10209,7 @@ pub const FuncGen = struct {
1021510209 if (layout.tag_size == 0) return .none;
1021610210 const union_handle = try self.resolveInst(ty_op.operand);
1021710211 if (isByRef(un_ty, zcu)) {
10218 const llvm_un_ty = try o.lowerType(un_ty);
10212 const llvm_un_ty = try o.lowerType(pt, un_ty);
1021910213 if (layout.payload_size == 0)
1022010214 return self.wip.load(.normal, llvm_un_ty, union_handle, .default, "");
1022110215 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
......@@ -10247,6 +10241,7 @@ pub const FuncGen = struct {
1024710241
1024810242 fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
1024910243 const o = self.ng.object;
10244 const pt = self.ng.pt;
1025010245 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1025110246 const inst_ty = self.typeOfIndex(inst);
1025210247 const operand_ty = self.typeOf(ty_op.operand);
......@@ -10256,15 +10251,16 @@ pub const FuncGen = struct {
1025610251 .normal,
1025710252 .none,
1025810253 intrinsic,
10259 &.{try o.lowerType(operand_ty)},
10254 &.{try o.lowerType(pt, operand_ty)},
1026010255 &.{ operand, .false },
1026110256 "",
1026210257 );
10263 return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), "");
10258 return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), "");
1026410259 }
1026510260
1026610261 fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
1026710262 const o = self.ng.object;
10263 const pt = self.ng.pt;
1026810264 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1026910265 const inst_ty = self.typeOfIndex(inst);
1027010266 const operand_ty = self.typeOf(ty_op.operand);
......@@ -10274,16 +10270,17 @@ pub const FuncGen = struct {
1027410270 .normal,
1027510271 .none,
1027610272 intrinsic,
10277 &.{try o.lowerType(operand_ty)},
10273 &.{try o.lowerType(pt, operand_ty)},
1027810274 &.{operand},
1027910275 "",
1028010276 );
10281 return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), "");
10277 return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), "");
1028210278 }
1028310279
1028410280 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1028510281 const o = self.ng.object;
10286 const zcu = o.pt.zcu;
10282 const pt = self.ng.pt;
10283 const zcu = pt.zcu;
1028710284 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1028810285 const operand_ty = self.typeOf(ty_op.operand);
1028910286 var bits = operand_ty.intInfo(zcu).bits;
......@@ -10291,7 +10288,7 @@ pub const FuncGen = struct {
1029110288
1029210289 const inst_ty = self.typeOfIndex(inst);
1029310290 var operand = try self.resolveInst(ty_op.operand);
10294 var llvm_operand_ty = try o.lowerType(operand_ty);
10291 var llvm_operand_ty = try o.lowerType(pt, operand_ty);
1029510292
1029610293 if (bits % 16 == 8) {
1029710294 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte
......@@ -10312,12 +10309,13 @@ pub const FuncGen = struct {
1031210309
1031310310 const result =
1031410311 try self.wip.callIntrinsic(.normal, .none, .bswap, &.{llvm_operand_ty}, &.{operand}, "");
10315 return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), "");
10312 return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), "");
1031610313 }
1031710314
1031810315 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1031910316 const o = self.ng.object;
10320 const zcu = o.pt.zcu;
10317 const pt = self.ng.pt;
10318 const zcu = pt.zcu;
1032110319 const ip = &zcu.intern_pool;
1032210320 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1032310321 const operand = try self.resolveInst(ty_op.operand);
......@@ -10332,7 +10330,7 @@ pub const FuncGen = struct {
1033210330
1033310331 for (0..names.len) |name_index| {
1033410332 const err_int = ip.getErrorValueIfExists(names.get(ip)[name_index]).?;
10335 const this_tag_int_value = try o.builder.intConst(try o.errorIntType(), err_int);
10333 const this_tag_int_value = try o.builder.intConst(try o.errorIntType(pt), err_int);
1033610334 try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip);
1033710335 }
1033810336 self.wip.cursor = .{ .block = valid_block };
......@@ -10367,7 +10365,7 @@ pub const FuncGen = struct {
1036710365
1036810366 fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !Builder.Function.Index {
1036910367 const o = self.ng.object;
10370 const pt = o.pt;
10368 const pt = self.ng.pt;
1037110369 const zcu = pt.zcu;
1037210370 const ip = &zcu.intern_pool;
1037310371 const enum_type = ip.loadEnumType(enum_ty.toIntern());
......@@ -10379,7 +10377,7 @@ pub const FuncGen = struct {
1037910377
1038010378 const target = &zcu.root_mod.resolved_target.result;
1038110379 const function_index = try o.builder.addFunction(
10382 try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
10380 try o.builder.fnType(.i1, &.{try o.lowerType(pt, Type.fromInterned(enum_type.tag_ty))}, .normal),
1038310381 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_type.name.fmt(ip)}),
1038410382 toLlvmAddressSpace(.generic, target),
1038510383 );
......@@ -10408,6 +10406,7 @@ pub const FuncGen = struct {
1040810406
1040910407 for (0..enum_type.names.len) |field_index| {
1041010408 const this_tag_int_value = try o.lowerValue(
10409 pt,
1041110410 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),
1041210411 );
1041310412 try wip_switch.addCase(this_tag_int_value, named_block, &wip);
......@@ -10424,11 +10423,12 @@ pub const FuncGen = struct {
1042410423
1042510424 fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1042610425 const o = self.ng.object;
10426 const pt = self.ng.pt;
1042710427 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1042810428 const operand = try self.resolveInst(un_op);
1042910429 const enum_ty = self.typeOf(un_op);
1043010430
10431 const llvm_fn = try o.getEnumTagNameFunction(enum_ty);
10431 const llvm_fn = try o.getEnumTagNameFunction(pt, enum_ty);
1043210432 return self.wip.call(
1043310433 .normal,
1043410434 .fastcc,
......@@ -10442,10 +10442,11 @@ pub const FuncGen = struct {
1044210442
1044310443 fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1044410444 const o = self.ng.object;
10445 const pt = self.ng.pt;
1044510446 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1044610447 const operand = try self.resolveInst(un_op);
1044710448 const slice_ty = self.typeOfIndex(inst);
10448 const slice_llvm_ty = try o.lowerType(slice_ty);
10449 const slice_llvm_ty = try o.lowerType(pt, slice_ty);
1044910450
1045010451 const error_name_table_ptr = try self.getErrorNameTable();
1045110452 const error_name_table =
......@@ -10457,10 +10458,11 @@ pub const FuncGen = struct {
1045710458
1045810459 fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1045910460 const o = self.ng.object;
10461 const pt = self.ng.pt;
1046010462 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1046110463 const scalar = try self.resolveInst(ty_op.operand);
1046210464 const vector_ty = self.typeOfIndex(inst);
10463 return self.wip.splatVector(try o.lowerType(vector_ty), scalar, "");
10465 return self.wip.splatVector(try o.lowerType(pt, vector_ty), scalar, "");
1046410466 }
1046510467
1046610468 fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
......@@ -10475,7 +10477,7 @@ pub const FuncGen = struct {
1047510477
1047610478 fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1047710479 const o = fg.ng.object;
10478 const pt = o.pt;
10480 const pt = fg.ng.pt;
1047910481 const zcu = pt.zcu;
1048010482 const gpa = zcu.gpa;
1048110483
......@@ -10484,9 +10486,9 @@ pub const FuncGen = struct {
1048410486 const operand = try fg.resolveInst(unwrapped.operand);
1048510487 const mask = unwrapped.mask;
1048610488 const operand_ty = fg.typeOf(unwrapped.operand);
10487 const llvm_operand_ty = try o.lowerType(operand_ty);
10488 const llvm_result_ty = try o.lowerType(unwrapped.result_ty);
10489 const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu));
10489 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
10490 const llvm_result_ty = try o.lowerType(pt, unwrapped.result_ty);
10491 const llvm_elem_ty = try o.lowerType(pt, unwrapped.result_ty.childType(zcu));
1049010492 const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty);
1049110493 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);
1049210494 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);
......@@ -10516,7 +10518,7 @@ pub const FuncGen = struct {
1051610518 .elem => llvm_poison_elem,
1051710519 .value => |val| if (!Value.fromInterned(val).isUndef(zcu)) elem: {
1051810520 any_defined_comptime_value = true;
10519 break :elem try o.lowerValue(val);
10521 break :elem try o.lowerValue(pt, val);
1052010522 } else llvm_poison_elem,
1052110523 };
1052210524 }
......@@ -10582,14 +10584,14 @@ pub const FuncGen = struct {
1058210584
1058310585 fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1058410586 const o = fg.ng.object;
10585 const pt = o.pt;
10587 const pt = fg.ng.pt;
1058610588 const zcu = pt.zcu;
1058710589 const gpa = zcu.gpa;
1058810590
1058910591 const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst);
1059010592
1059110593 const mask = unwrapped.mask;
10592 const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu));
10594 const llvm_elem_ty = try o.lowerType(pt, unwrapped.result_ty.childType(zcu));
1059310595 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);
1059410596 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);
1059510597
......@@ -10681,7 +10683,8 @@ pub const FuncGen = struct {
1068110683 accum_init: Builder.Value,
1068210684 ) !Builder.Value {
1068310685 const o = self.ng.object;
10684 const usize_ty = try o.lowerType(Type.usize);
10686 const pt = self.ng.pt;
10687 const usize_ty = try o.lowerType(pt, Type.usize);
1068510688 const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len);
1068610689 const llvm_result_ty = accum_init.typeOfWip(&self.wip);
1068710690
......@@ -10735,15 +10738,16 @@ pub const FuncGen = struct {
1073510738
1073610739 fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
1073710740 const o = self.ng.object;
10738 const zcu = o.pt.zcu;
10741 const pt = self.ng.pt;
10742 const zcu = pt.zcu;
1073910743 const target = zcu.getTarget();
1074010744
1074110745 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
1074210746 const operand = try self.resolveInst(reduce.operand);
1074310747 const operand_ty = self.typeOf(reduce.operand);
10744 const llvm_operand_ty = try o.lowerType(operand_ty);
10748 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
1074510749 const scalar_ty = self.typeOfIndex(inst);
10746 const llvm_scalar_ty = try o.lowerType(scalar_ty);
10750 const llvm_scalar_ty = try o.lowerType(pt, scalar_ty);
1074710751
1074810752 switch (reduce.operation) {
1074910753 .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
......@@ -10845,14 +10849,14 @@ pub const FuncGen = struct {
1084510849
1084610850 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1084710851 const o = self.ng.object;
10848 const pt = o.pt;
10852 const pt = self.ng.pt;
1084910853 const zcu = pt.zcu;
1085010854 const ip = &zcu.intern_pool;
1085110855 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1085210856 const result_ty = self.typeOfIndex(inst);
1085310857 const len: usize = @intCast(result_ty.arrayLen(zcu));
1085410858 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[ty_pl.payload..][0..len]);
10855 const llvm_result_ty = try o.lowerType(result_ty);
10859 const llvm_result_ty = try o.lowerType(pt, result_ty);
1085610860
1085710861 switch (result_ty.zigTypeTag(zcu)) {
1085810862 .vector => {
......@@ -10933,7 +10937,7 @@ pub const FuncGen = struct {
1093310937 .array => {
1093410938 assert(isByRef(result_ty, zcu));
1093510939
10936 const llvm_usize = try o.lowerType(Type.usize);
10940 const llvm_usize = try o.lowerType(pt, Type.usize);
1093710941 const usize_zero = try o.builder.intValue(llvm_usize, 0);
1093810942 const alignment = result_ty.abiAlignment(zcu).toLlvm();
1093910943 const alloca_inst = try self.buildAlloca(llvm_result_ty, alignment);
......@@ -10966,13 +10970,13 @@ pub const FuncGen = struct {
1096610970
1096710971 fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1096810972 const o = self.ng.object;
10969 const pt = o.pt;
10973 const pt = self.ng.pt;
1097010974 const zcu = pt.zcu;
1097110975 const ip = &zcu.intern_pool;
1097210976 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1097310977 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
1097410978 const union_ty = self.typeOfIndex(inst);
10975 const union_llvm_ty = try o.lowerType(union_ty);
10979 const union_llvm_ty = try o.lowerType(pt, union_ty);
1097610980 const layout = union_ty.unionGetLayout(zcu);
1097710981 const union_obj = zcu.typeToUnion(union_ty).?;
1097810982
......@@ -11014,10 +11018,10 @@ pub const FuncGen = struct {
1101411018 const result_ptr = try self.buildAlloca(union_llvm_ty, alignment);
1101511019 const llvm_payload = try self.resolveInst(extra.init);
1101611020 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
11017 const field_llvm_ty = try o.lowerType(field_ty);
11021 const field_llvm_ty = try o.lowerType(pt, field_ty);
1101811022 const field_size = field_ty.abiSize(zcu);
1101911023 const field_align = union_ty.fieldAlignment(extra.field_index, zcu);
11020 const llvm_usize = try o.lowerType(Type.usize);
11024 const llvm_usize = try o.lowerType(pt, Type.usize);
1102111025 const usize_zero = try o.builder.intValue(llvm_usize, 0);
1102211026
1102311027 const llvm_union_ty = t: {
......@@ -11035,7 +11039,7 @@ pub const FuncGen = struct {
1103511039 });
1103611040 };
1103711041 if (layout.tag_size == 0) break :t try o.builder.structType(.normal, &.{payload_ty});
11038 const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
11042 const tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty));
1103911043 var fields: [3]Builder.Type = undefined;
1104011044 var fields_len: usize = 2;
1104111045 if (layout.tag_align.compare(.gte, layout.payload_align)) {
......@@ -11076,7 +11080,7 @@ pub const FuncGen = struct {
1107611080 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
1107711081 const indices: [2]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, tag_index) };
1107811082 const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, "");
11079 const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
11083 const tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty));
1108011084 var big_int_space: Value.BigIntSpace = undefined;
1108111085 const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu);
1108211086 const llvm_tag = try o.builder.bigIntValue(tag_ty, tag_big_int);
......@@ -11106,7 +11110,7 @@ pub const FuncGen = struct {
1110611110 // by the target.
1110711111 // To work around this, don't emit llvm.prefetch in this case.
1110811112 // See https://bugs.llvm.org/show_bug.cgi?id=21037
11109 const zcu = o.pt.zcu;
11113 const zcu = self.ng.pt.zcu;
1111011114 const target = zcu.getTarget();
1111111115 switch (prefetch.cache) {
1111211116 .instruction => switch (target.cpu.arch) {
......@@ -11139,11 +11143,12 @@ pub const FuncGen = struct {
1113911143
1114011144 fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1114111145 const o = self.ng.object;
11146 const pt = self.ng.pt;
1114211147 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1114311148 const inst_ty = self.typeOfIndex(inst);
1114411149 const operand = try self.resolveInst(ty_op.operand);
1114511150
11146 return self.wip.cast(.addrspacecast, operand, try o.lowerType(inst_ty), "");
11151 return self.wip.cast(.addrspacecast, operand, try o.lowerType(pt, inst_ty), "");
1114711152 }
1114811153
1114911154 fn workIntrinsic(
......@@ -11161,8 +11166,7 @@ pub const FuncGen = struct {
1116111166 }
1116211167
1116311168 fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
11164 const o = self.ng.object;
11165 const target = o.pt.zcu.getTarget();
11169 const target = self.ng.pt.zcu.getTarget();
1116611170
1116711171 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1116811172 const dimension = pl_op.payload;
......@@ -11176,7 +11180,8 @@ pub const FuncGen = struct {
1117611180
1117711181 fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1117811182 const o = self.ng.object;
11179 const target = o.pt.zcu.getTarget();
11183 const pt = self.ng.pt;
11184 const target = pt.zcu.getTarget();
1118011185
1118111186 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1118211187 const dimension = pl_op.payload;
......@@ -11193,7 +11198,7 @@ pub const FuncGen = struct {
1119311198 // Load the work_group_* member from the struct as u16.
1119411199 // Just treat the dispatch pointer as an array of u16 to keep things simple.
1119511200 const workgroup_size_ptr = try self.wip.gep(.inbounds, .i16, dispatch_ptr, &.{
11196 try o.builder.intValue(try o.lowerType(Type.usize), 2 + dimension),
11201 try o.builder.intValue(try o.lowerType(pt, Type.usize), 2 + dimension),
1119711202 }, "");
1119811203 const workgroup_size_alignment = comptime Builder.Alignment.fromByteUnits(2);
1119911204 return self.wip.load(.normal, .i16, workgroup_size_ptr, workgroup_size_alignment, "");
......@@ -11206,8 +11211,7 @@ pub const FuncGen = struct {
1120611211 }
1120711212
1120811213 fn airWorkGroupId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
11209 const o = self.ng.object;
11210 const target = o.pt.zcu.getTarget();
11214 const target = self.ng.pt.zcu.getTarget();
1121111215
1121211216 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1121311217 const dimension = pl_op.payload;
......@@ -11221,7 +11225,7 @@ pub const FuncGen = struct {
1122111225
1122211226 fn getErrorNameTable(self: *FuncGen) Allocator.Error!Builder.Variable.Index {
1122311227 const o = self.ng.object;
11224 const pt = o.pt;
11228 const pt = self.ng.pt;
1122511229
1122611230 const table = o.error_name_table;
1122711231 if (table != .none) return table;
......@@ -11271,8 +11275,7 @@ pub const FuncGen = struct {
1127111275 opt_ty: Type,
1127211276 can_elide_load: bool,
1127311277 ) !Builder.Value {
11274 const o = fg.ng.object;
11275 const pt = o.pt;
11278 const pt = fg.ng.pt;
1127611279 const zcu = pt.zcu;
1127711280 const payload_ty = opt_ty.optionalChild(zcu);
1127811281
......@@ -11301,9 +11304,9 @@ pub const FuncGen = struct {
1130111304 non_null_bit: Builder.Value,
1130211305 ) !Builder.Value {
1130311306 const o = self.ng.object;
11304 const pt = o.pt;
11307 const pt = self.ng.pt;
1130511308 const zcu = pt.zcu;
11306 const optional_llvm_ty = try o.lowerType(optional_ty);
11309 const optional_llvm_ty = try o.lowerType(pt, optional_ty);
1130711310 const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, "");
1130811311
1130911312 if (isByRef(optional_ty, zcu)) {
......@@ -11334,7 +11337,7 @@ pub const FuncGen = struct {
1133411337 field_index: u32,
1133511338 ) !Builder.Value {
1133611339 const o = self.ng.object;
11337 const pt = o.pt;
11340 const pt = self.ng.pt;
1133811341 const zcu = pt.zcu;
1133911342 const struct_ty = struct_ptr_ty.childType(zcu);
1134011343 switch (struct_ty.zigTypeTag(zcu)) {
......@@ -11357,12 +11360,12 @@ pub const FuncGen = struct {
1135711360 // Offset our operand pointer by the correct number of bytes.
1135811361 const byte_offset = @divExact(pt.structPackedFieldBitOffset(struct_type, field_index) + struct_ptr_ty_info.packed_offset.bit_offset, 8);
1135911362 if (byte_offset == 0) return struct_ptr;
11360 const usize_ty = try o.lowerType(Type.usize);
11363 const usize_ty = try o.lowerType(pt, Type.usize);
1136111364 const llvm_index = try o.builder.intValue(usize_ty, byte_offset);
1136211365 return self.wip.gep(.inbounds, .i8, struct_ptr, &.{llvm_index}, "");
1136311366 },
1136411367 else => {
11365 const struct_llvm_ty = try o.lowerPtrElemTy(struct_ty);
11368 const struct_llvm_ty = try o.lowerPtrElemTy(pt, struct_ty);
1136611369
1136711370 if (o.llvmFieldIndex(struct_ty, field_index)) |llvm_field_index| {
1136811371 return self.wip.gepStruct(struct_llvm_ty, struct_ptr, llvm_field_index, "");
......@@ -11372,7 +11375,7 @@ pub const FuncGen = struct {
1137211375 // the index to the element at index `1` to get a pointer to the end of
1137311376 // the struct.
1137411377 const llvm_index = try o.builder.intValue(
11375 try o.lowerType(Type.usize),
11378 try o.lowerType(pt, Type.usize),
1137611379 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)),
1137711380 );
1137811381 return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, "");
......@@ -11383,7 +11386,7 @@ pub const FuncGen = struct {
1138311386 const layout = struct_ty.unionGetLayout(zcu);
1138411387 if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr;
1138511388 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
11386 const union_llvm_ty = try o.lowerType(struct_ty);
11389 const union_llvm_ty = try o.lowerType(pt, struct_ty);
1138711390 return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, "");
1138811391 },
1138911392 else => unreachable,
......@@ -11403,9 +11406,9 @@ pub const FuncGen = struct {
1140311406 // => so load the byte aligned value and trunc the unwanted bits.
1140411407
1140511408 const o = fg.ng.object;
11406 const pt = o.pt;
11409 const pt = fg.ng.pt;
1140711410 const zcu = pt.zcu;
11408 const payload_llvm_ty = try o.lowerType(payload_ty);
11411 const payload_llvm_ty = try o.lowerType(pt, payload_ty);
1140911412 const abi_size = payload_ty.abiSize(zcu);
1141011413
1141111414 // llvm bug workarounds:
......@@ -11450,8 +11453,8 @@ pub const FuncGen = struct {
1145011453 access_kind: Builder.MemoryAccessKind,
1145111454 ) !Builder.Value {
1145211455 const o = fg.ng.object;
11453 const pt = o.pt;
11454 const pointee_llvm_ty = try o.lowerType(pointee_type);
11456 const pt = fg.ng.pt;
11457 const pointee_llvm_ty = try o.lowerType(pt, pointee_type);
1145511458 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment)
1145611459 .max(pointee_type.abiAlignment(pt.zcu)).toLlvm();
1145711460 const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align);
......@@ -11461,7 +11464,7 @@ pub const FuncGen = struct {
1146111464 result_align,
1146211465 ptr,
1146311466 ptr_alignment,
11464 try o.builder.intValue(try o.lowerType(Type.usize), size_bytes),
11467 try o.builder.intValue(try o.lowerType(pt, Type.usize), size_bytes),
1146511468 access_kind,
1146611469 fg.disable_intrinsics,
1146711470 );
......@@ -11473,7 +11476,7 @@ pub const FuncGen = struct {
1147311476 /// For isByRef=false types, it creates a load instruction and returns it.
1147411477 fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value {
1147511478 const o = self.ng.object;
11476 const pt = o.pt;
11479 const pt = self.ng.pt;
1147711480 const zcu = pt.zcu;
1147811481 const info = ptr_ty.ptrInfo(zcu);
1147911482 const elem_ty = Type.fromInterned(info.child);
......@@ -11490,7 +11493,7 @@ pub const FuncGen = struct {
1149011493 assert(info.flags.vector_index != .runtime);
1149111494 if (info.flags.vector_index != .none) {
1149211495 const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index);
11493 const vec_elem_ty = try o.lowerType(elem_ty);
11496 const vec_elem_ty = try o.lowerType(pt, elem_ty);
1149411497 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);
1149511498
1149611499 const loaded_vector = try self.wip.load(access_kind, vec_ty, ptr, ptr_alignment, "");
......@@ -11511,7 +11514,7 @@ pub const FuncGen = struct {
1151111514 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);
1151211515 const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset);
1151311516 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
11514 const elem_llvm_ty = try o.lowerType(elem_ty);
11517 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
1151511518
1151611519 if (isByRef(elem_ty, zcu)) {
1151711520 const result_align = elem_ty.abiAlignment(zcu).toLlvm();
......@@ -11546,7 +11549,7 @@ pub const FuncGen = struct {
1154611549 ordering: Builder.AtomicOrdering,
1154711550 ) !void {
1154811551 const o = self.ng.object;
11549 const pt = o.pt;
11552 const pt = self.ng.pt;
1155011553 const zcu = pt.zcu;
1155111554 const info = ptr_ty.ptrInfo(zcu);
1155211555 const elem_ty = Type.fromInterned(info.child);
......@@ -11560,7 +11563,7 @@ pub const FuncGen = struct {
1156011563 assert(info.flags.vector_index != .runtime);
1156111564 if (info.flags.vector_index != .none) {
1156211565 const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index);
11563 const vec_elem_ty = try o.lowerType(elem_ty);
11566 const vec_elem_ty = try o.lowerType(pt, elem_ty);
1156411567 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);
1156511568
1156611569 const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, "");
......@@ -11629,7 +11632,7 @@ pub const FuncGen = struct {
1162911632 ptr_alignment,
1163011633 elem,
1163111634 elem_ty.abiAlignment(zcu).toLlvm(),
11632 try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(zcu)),
11635 try o.builder.intValue(try o.lowerType(pt, Type.usize), elem_ty.abiSize(zcu)),
1163311636 access_kind,
1163411637 self.disable_intrinsics,
1163511638 );
......@@ -11638,7 +11641,8 @@ pub const FuncGen = struct {
1163811641 fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void {
1163911642 const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545;
1164011643 const o = fg.ng.object;
11641 const usize_ty = try o.lowerType(Type.usize);
11644 const pt = fg.ng.pt;
11645 const usize_ty = try o.lowerType(pt, Type.usize);
1164211646 const zero = try o.builder.intValue(usize_ty, 0);
1164311647 const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED);
1164411648 const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, "");
......@@ -11656,12 +11660,12 @@ pub const FuncGen = struct {
1165611660 a5: Builder.Value,
1165711661 ) Allocator.Error!Builder.Value {
1165811662 const o = fg.ng.object;
11659 const pt = o.pt;
11663 const pt = fg.ng.pt;
1166011664 const zcu = pt.zcu;
1166111665 const target = zcu.getTarget();
1166211666 if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value;
1166311667
11664 const llvm_usize = try o.lowerType(Type.usize);
11668 const llvm_usize = try o.lowerType(pt, Type.usize);
1166511669 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();
1166611670
1166711671 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);
......@@ -11787,14 +11791,12 @@ pub const FuncGen = struct {
1178711791 }
1178811792
1178911793 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {
11790 const o = fg.ng.object;
11791 const zcu = o.pt.zcu;
11794 const zcu = fg.ng.pt.zcu;
1179211795 return fg.air.typeOf(inst, &zcu.intern_pool);
1179311796 }
1179411797
1179511798 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {
11796 const o = fg.ng.object;
11797 const zcu = o.pt.zcu;
11799 const zcu = fg.ng.pt.zcu;
1179811800 return fg.air.typeOfIndex(inst, &zcu.intern_pool);
1179911801 }
1180011802};
......@@ -12152,40 +12154,39 @@ fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: *const std.Target) bool {
1215212154/// In order to support the C calling convention, some return types need to be lowered
1215312155/// completely differently in the function prototype to honor the C ABI, and then
1215412156/// be effectively bitcasted to the actual return type.
12155fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12156 const pt = o.pt;
12157fn lowerFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1215712158 const zcu = pt.zcu;
1215812159 const return_type = Type.fromInterned(fn_info.return_type);
1215912160 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
1216012161 // If the return type is an error set or an error union, then we make this
1216112162 // anyerror return type instead, so that it can be coerced into a function
1216212163 // pointer type which has anyerror as the return type.
12163 return if (return_type.isError(zcu)) try o.errorIntType() else .void;
12164 return if (return_type.isError(zcu)) try o.errorIntType(pt) else .void;
1216412165 }
1216512166 const target = zcu.getTarget();
1216612167 switch (fn_info.cc) {
1216712168 .@"inline" => unreachable,
12168 .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(return_type),
12169 .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(pt, return_type),
1216912170
12170 .x86_64_sysv => return lowerSystemVFnRetTy(o, fn_info),
12171 .x86_64_win => return lowerWin64FnRetTy(o, fn_info),
12172 .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(return_type) else .void,
12173 .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(return_type),
12171 .x86_64_sysv => return lowerSystemVFnRetTy(o, pt, fn_info),
12172 .x86_64_win => return lowerWin64FnRetTy(o, pt, fn_info),
12173 .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(pt, return_type) else .void,
12174 .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(pt, return_type),
1217412175 .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win => switch (aarch64_c_abi.classifyType(return_type, zcu)) {
1217512176 .memory => return .void,
12176 .float_array => return o.lowerType(return_type),
12177 .byval => return o.lowerType(return_type),
12177 .float_array => return o.lowerType(pt, return_type),
12178 .byval => return o.lowerType(pt, return_type),
1217812179 .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))),
1217912180 .double_integer => return o.builder.arrayType(2, .i64),
1218012181 },
1218112182 .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
1218212183 .memory, .i64_array => return .void,
1218312184 .i32_array => |len| return if (len == 1) .i32 else .void,
12184 .byval => return o.lowerType(return_type),
12185 .byval => return o.lowerType(pt, return_type),
1218512186 },
1218612187 .mips_o32 => switch (mips_c_abi.classifyType(return_type, zcu, .ret)) {
1218712188 .memory, .i32_array => return .void,
12188 .byval => return o.lowerType(return_type),
12189 .byval => return o.lowerType(pt, return_type),
1218912190 },
1219012191 .riscv64_lp64, .riscv32_ilp32 => switch (riscv_c_abi.classifyType(return_type, zcu)) {
1219112192 .memory => return .void,
......@@ -12195,53 +12196,52 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1219512196 .double_integer => {
1219612197 return o.builder.structType(.normal, &.{ .i64, .i64 });
1219712198 },
12198 .byval => return o.lowerType(return_type),
12199 .byval => return o.lowerType(pt, return_type),
1219912200 .fields => {
1220012201 var types_len: usize = 0;
1220112202 var types: [8]Builder.Type = undefined;
1220212203 for (0..return_type.structFieldCount(zcu)) |field_index| {
1220312204 const field_ty = return_type.fieldType(field_index, zcu);
1220412205 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
12205 types[types_len] = try o.lowerType(field_ty);
12206 types[types_len] = try o.lowerType(pt, field_ty);
1220612207 types_len += 1;
1220712208 }
1220812209 return o.builder.structType(.normal, types[0..types_len]);
1220912210 },
1221012211 },
1221112212 .wasm_mvp => switch (wasm_c_abi.classifyType(return_type, zcu)) {
12212 .direct => |scalar_ty| return o.lowerType(scalar_ty),
12213 .direct => |scalar_ty| return o.lowerType(pt, scalar_ty),
1221312214 .indirect => return .void,
1221412215 },
1221512216 // TODO investigate other callconvs
12216 else => return o.lowerType(return_type),
12217 else => return o.lowerType(pt, return_type),
1221712218 }
1221812219}
1221912220
12220fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12221 const zcu = o.pt.zcu;
12221fn lowerWin64FnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12222 const zcu = pt.zcu;
1222212223 const return_type = Type.fromInterned(fn_info.return_type);
1222312224 switch (x86_64_abi.classifyWindows(return_type, zcu, zcu.getTarget())) {
1222412225 .integer => {
1222512226 if (isScalar(zcu, return_type)) {
12226 return o.lowerType(return_type);
12227 return o.lowerType(pt, return_type);
1222712228 } else {
1222812229 return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8));
1222912230 }
1223012231 },
1223112232 .win_i128 => return o.builder.vectorType(.normal, 2, .i64),
1223212233 .memory => return .void,
12233 .sse => return o.lowerType(return_type),
12234 .sse => return o.lowerType(pt, return_type),
1223412235 else => unreachable,
1223512236 }
1223612237}
1223712238
12238fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12239 const pt = o.pt;
12239fn lowerSystemVFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1224012240 const zcu = pt.zcu;
1224112241 const ip = &zcu.intern_pool;
1224212242 const return_type = Type.fromInterned(fn_info.return_type);
1224312243 if (isScalar(zcu, return_type)) {
12244 return o.lowerType(return_type);
12244 return o.lowerType(pt, return_type);
1224512245 }
1224612246 const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret);
1224712247 var types_index: u32 = 0;
......@@ -12305,6 +12305,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
1230512305
1230612306const ParamTypeIterator = struct {
1230712307 object: *Object,
12308 pt: Zcu.PerThread,
1230812309 fn_info: InternPool.Key.FuncType,
1230912310 zig_index: u32,
1231012311 llvm_index: u32,
......@@ -12327,7 +12328,7 @@ const ParamTypeIterator = struct {
1232712328
1232812329 pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering {
1232912330 if (it.zig_index >= it.fn_info.param_types.len) return null;
12330 const ip = &it.object.pt.zcu.intern_pool;
12331 const ip = &it.pt.zcu.intern_pool;
1233112332 const ty = it.fn_info.param_types.get(ip)[it.zig_index];
1233212333 it.byval_attr = false;
1233312334 return nextInner(it, Type.fromInterned(ty));
......@@ -12335,7 +12336,8 @@ const ParamTypeIterator = struct {
1233512336
1233612337 /// `airCall` uses this instead of `next` so that it can take into account variadic functions.
1233712338 pub fn nextCall(it: *ParamTypeIterator, fg: *FuncGen, args: []const Air.Inst.Ref) Allocator.Error!?Lowering {
12338 const ip = &it.object.pt.zcu.intern_pool;
12339 assert(std.meta.eql(it.pt, fg.ng.pt));
12340 const ip = &it.pt.zcu.intern_pool;
1233912341 if (it.zig_index >= it.fn_info.param_types.len) {
1234012342 if (it.zig_index >= args.len) {
1234112343 return null;
......@@ -12348,7 +12350,7 @@ const ParamTypeIterator = struct {
1234812350 }
1234912351
1235012352 fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
12351 const pt = it.object.pt;
12353 const pt = it.pt;
1235212354 const zcu = pt.zcu;
1235312355 const target = zcu.getTarget();
1235412356
......@@ -12448,7 +12450,7 @@ const ParamTypeIterator = struct {
1244812450 for (0..ty.structFieldCount(zcu)) |field_index| {
1244912451 const field_ty = ty.fieldType(field_index, zcu);
1245012452 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
12451 it.types_buffer[it.types_len] = try it.object.lowerType(field_ty);
12453 it.types_buffer[it.types_len] = try it.object.lowerType(pt, field_ty);
1245212454 it.types_len += 1;
1245312455 }
1245412456 it.llvm_index += it.types_len - 1;
......@@ -12464,7 +12466,7 @@ const ParamTypeIterator = struct {
1246412466 return .byval;
1246512467 } else {
1246612468 var types_buffer: [8]Builder.Type = undefined;
12467 types_buffer[0] = try it.object.lowerType(scalar_ty);
12469 types_buffer[0] = try it.object.lowerType(pt, scalar_ty);
1246812470 it.types_buffer = types_buffer;
1246912471 it.types_len = 1;
1247012472 it.llvm_index += 1;
......@@ -12489,7 +12491,7 @@ const ParamTypeIterator = struct {
1248912491 }
1249012492
1249112493 fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering {
12492 const zcu = it.object.pt.zcu;
12494 const zcu = it.pt.zcu;
1249312495 switch (x86_64_abi.classifyWindows(ty, zcu, zcu.getTarget())) {
1249412496 .integer => {
1249512497 if (isScalar(zcu, ty)) {
......@@ -12522,7 +12524,7 @@ const ParamTypeIterator = struct {
1252212524 }
1252312525
1252412526 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
12525 const zcu = it.object.pt.zcu;
12527 const zcu = it.pt.zcu;
1252612528 const ip = &zcu.intern_pool;
1252712529 const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg);
1252812530 if (classes[0] == .memory) {
......@@ -12615,9 +12617,10 @@ const ParamTypeIterator = struct {
1261512617 }
1261612618};
1261712619
12618fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTypeIterator {
12620fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) ParamTypeIterator {
1261912621 return .{
1262012622 .object = object,
12623 .pt = pt,
1262112624 .fn_info = fn_info,
1262212625 .zig_index = 0,
1262312626 .llvm_index = 0,
......@@ -12896,6 +12899,26 @@ fn compilerRtIntBits(bits: u16) u16 {
1289612899 return bits;
1289712900}
1289812901
12902fn getStackTraceType(pt: Zcu.PerThread) Allocator.Error!Type {
12903 const zcu = pt.zcu;
12904 const ip = &zcu.intern_pool;
12905
12906 const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?;
12907 const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls);
12908 const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_index));
12909 const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu));
12910 const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;
12911
12912 const stack_trace_str = try ip.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls);
12913 // buffer is only used for int_type, `builtin` is a struct.
12914 const builtin_ty = zcu.navValue(builtin_nav).toType();
12915 const builtin_namespace = zcu.namespacePtr(builtin_ty.getNamespaceIndex(zcu));
12916 const stack_trace_nav = builtin_namespace.pub_decls.getKeyAdapted(stack_trace_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;
12917
12918 // Sema should have ensured that StackTrace was analyzed.
12919 return zcu.navValue(stack_trace_nav).toType();
12920}
12921
1289912922fn buildAllocaInner(
1290012923 wip: *Builder.WipFunction,
1290112924 llvm_ty: Builder.Type,
src/link/Wasm.zig+2-1
......@@ -3807,10 +3807,11 @@ pub fn flush(
38073807 tid: Zcu.PerThread.Id,
38083808 prog_node: std.Progress.Node,
38093809) link.File.FlushError!void {
3810 _ = tid;
3811
38103812 // The goal is to never use this because it's only needed if we need to
38113813 // write to InternPool, but flush is too late to be writing to the
38123814 // InternPool.
3813 _ = tid;
38143815 const comp = wasm.base.comp;
38153816 const diags = &comp.link_diags;
38163817 const gpa = comp.gpa;