authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-14 04:19:13+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-07-14 04:19:13+02:00
log5696bbb307effecc2bf6dd1b28f6954186558b94
treebe8b75bf52518a2a0ea8750681816810cf39f86c
parente7b18a7ce69f30c85f21ec8ad6a70211abf5f24b
parenta558885321714ea1a21ee3d585b7f79f002adfd7
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #23552 from alichraghi

Progress towards support for running LLVM backend in a separate thread

3 files changed, 610 insertions(+), 622 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-11
......@@ -9705,7 +9705,6 @@ fn funcCommon(
97059705 func_inst,
97069706 cc_src,
97079707 is_noinline,
9708 is_generic,
97099708 );
97109709 }
97119710
......@@ -9745,7 +9744,6 @@ fn funcCommon(
97459744 func_inst,
97469745 cc_src,
97479746 is_noinline,
9748 is_generic,
97499747 );
97509748 }
97519749
......@@ -9762,7 +9760,6 @@ fn funcCommon(
97629760 func_inst,
97639761 cc_src,
97649762 is_noinline,
9765 is_generic,
97669763 );
97679764}
97689765
......@@ -9779,7 +9776,6 @@ fn finishFunc(
97799776 func_inst: Zir.Inst.Index,
97809777 cc_src: LazySrcLoc,
97819778 is_noinline: bool,
9782 is_generic: bool,
97839779) CompileError!Air.Inst.Ref {
97849780 const pt = sema.pt;
97859781 const zcu = pt.zcu;
......@@ -9911,13 +9907,6 @@ fn finishFunc(
99119907 }),
99129908 }
99139909
9914 if (!is_generic and sema.wantErrorReturnTracing(return_type)) {
9915 // Make sure that StackTrace's fields are resolved so that the backend can
9916 // lower this fn type.
9917 const unresolved_stack_trace_ty = try sema.getBuiltinType(block.nodeOffset(.zero), .StackTrace);
9918 try unresolved_stack_trace_ty.resolveFields(pt);
9919 }
9920
99219910 return Air.internedToRef(if (opt_func_index != .none) opt_func_index else func_ty);
99229911}
99239912
src/codegen/llvm.zig+609-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,13 @@ pub const Object = struct {
17611754 }
17621755 }
17631756
1764 fn getDebugFile(o: *Object, file_index: Zcu.File.Index) Allocator.Error!Builder.Metadata {
1757 fn getDebugFile(o: *Object, pt: Zcu.PerThread, file_index: Zcu.File.Index) Allocator.Error!Builder.Metadata {
17651758 const gpa = o.gpa;
17661759 const gop = try o.debug_file_map.getOrPut(gpa, file_index);
17671760 errdefer assert(o.debug_file_map.remove(file_index));
17681761 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);
1762 const path = pt.zcu.fileByIndex(file_index).path;
1763 const abs_path = try path.toAbsolute(pt.zcu.comp.dirs, gpa);
17721764 defer gpa.free(abs_path);
17731765
17741766 gop.value_ptr.* = try o.builder.debugFile(
......@@ -1780,13 +1772,13 @@ pub const Object = struct {
17801772
17811773 pub fn lowerDebugType(
17821774 o: *Object,
1775 pt: Zcu.PerThread,
17831776 ty: Type,
17841777 ) Allocator.Error!Builder.Metadata {
17851778 assert(!o.builder.strip);
17861779
17871780 const gpa = o.gpa;
17881781 const target = o.target;
1789 const pt = o.pt;
17901782 const zcu = pt.zcu;
17911783 const ip = &zcu.intern_pool;
17921784
......@@ -1806,7 +1798,7 @@ pub const Object = struct {
18061798 .int => {
18071799 const info = ty.intInfo(zcu);
18081800 assert(info.bits != 0);
1809 const name = try o.allocTypeName(ty);
1801 const name = try o.allocTypeName(pt, ty);
18101802 defer gpa.free(name);
18111803 const builder_name = try o.builder.metadataString(name);
18121804 const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types
......@@ -1819,7 +1811,7 @@ pub const Object = struct {
18191811 },
18201812 .@"enum" => {
18211813 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1822 const debug_enum_type = try o.makeEmptyNamespaceDebugType(ty);
1814 const debug_enum_type = try o.makeEmptyNamespaceDebugType(pt, ty);
18231815 try o.debug_type_map.put(gpa, ty, debug_enum_type);
18241816 return debug_enum_type;
18251817 }
......@@ -1847,13 +1839,13 @@ pub const Object = struct {
18471839 );
18481840 }
18491841
1850 const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
1842 const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
18511843 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|
1852 try o.namespaceToDebugScope(parent_namespace)
1844 try o.namespaceToDebugScope(pt, parent_namespace)
18531845 else
18541846 file;
18551847
1856 const name = try o.allocTypeName(ty);
1848 const name = try o.allocTypeName(pt, ty);
18571849 defer gpa.free(name);
18581850
18591851 const debug_enum_type = try o.builder.debugEnumerationType(
......@@ -1861,7 +1853,7 @@ pub const Object = struct {
18611853 file,
18621854 scope,
18631855 ty.typeDeclSrcLine(zcu).? + 1, // Line
1864 try o.lowerDebugType(int_ty),
1856 try o.lowerDebugType(pt, int_ty),
18651857 ty.abiSize(zcu) * 8,
18661858 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
18671859 try o.builder.metadataTuple(enumerators),
......@@ -1873,7 +1865,7 @@ pub const Object = struct {
18731865 },
18741866 .float => {
18751867 const bits = ty.floatBits(target);
1876 const name = try o.allocTypeName(ty);
1868 const name = try o.allocTypeName(pt, ty);
18771869 defer gpa.free(name);
18781870 const debug_float_type = try o.builder.debugFloatType(
18791871 try o.builder.metadataString(name),
......@@ -1918,7 +1910,7 @@ pub const Object = struct {
19181910 },
19191911 },
19201912 });
1921 const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty);
1913 const debug_ptr_type = try o.lowerDebugType(pt, bland_ptr_ty);
19221914 try o.debug_type_map.put(gpa, ty, debug_ptr_type);
19231915 return debug_ptr_type;
19241916 }
......@@ -1932,7 +1924,7 @@ pub const Object = struct {
19321924 const ptr_ty = ty.slicePtrFieldType(zcu);
19331925 const len_ty = Type.usize;
19341926
1935 const name = try o.allocTypeName(ty);
1927 const name = try o.allocTypeName(pt, ty);
19361928 defer gpa.free(name);
19371929 const line = 0;
19381930
......@@ -1948,7 +1940,7 @@ pub const Object = struct {
19481940 .none, // File
19491941 debug_fwd_ref,
19501942 0, // Line
1951 try o.lowerDebugType(ptr_ty),
1943 try o.lowerDebugType(pt, ptr_ty),
19521944 ptr_size * 8,
19531945 (ptr_align.toByteUnits() orelse 0) * 8,
19541946 0, // Offset
......@@ -1959,7 +1951,7 @@ pub const Object = struct {
19591951 .none, // File
19601952 debug_fwd_ref,
19611953 0, // Line
1962 try o.lowerDebugType(len_ty),
1954 try o.lowerDebugType(pt, len_ty),
19631955 len_size * 8,
19641956 (len_align.toByteUnits() orelse 0) * 8,
19651957 len_offset * 8,
......@@ -1988,9 +1980,9 @@ pub const Object = struct {
19881980 return debug_slice_type;
19891981 }
19901982
1991 const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child));
1983 const debug_elem_ty = try o.lowerDebugType(pt, Type.fromInterned(ptr_info.child));
19921984
1993 const name = try o.allocTypeName(ty);
1985 const name = try o.allocTypeName(pt, ty);
19941986 defer gpa.free(name);
19951987
19961988 const debug_ptr_type = try o.builder.debugPointerType(
......@@ -2022,12 +2014,12 @@ pub const Object = struct {
20222014 return debug_opaque_type;
20232015 }
20242016
2025 const name = try o.allocTypeName(ty);
2017 const name = try o.allocTypeName(pt, ty);
20262018 defer gpa.free(name);
20272019
2028 const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
2020 const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
20292021 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|
2030 try o.namespaceToDebugScope(parent_namespace)
2022 try o.namespaceToDebugScope(pt, parent_namespace)
20312023 else
20322024 file;
20332025
......@@ -2050,7 +2042,7 @@ pub const Object = struct {
20502042 .none, // File
20512043 .none, // Scope
20522044 0, // Line
2053 try o.lowerDebugType(ty.childType(zcu)),
2045 try o.lowerDebugType(pt, ty.childType(zcu)),
20542046 ty.abiSize(zcu) * 8,
20552047 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
20562048 try o.builder.metadataTuple(&.{
......@@ -2073,7 +2065,7 @@ pub const Object = struct {
20732065 .int => blk: {
20742066 const info = elem_ty.intInfo(zcu);
20752067 assert(info.bits != 0);
2076 const name = try o.allocTypeName(ty);
2068 const name = try o.allocTypeName(pt, ty);
20772069 defer gpa.free(name);
20782070 const builder_name = try o.builder.metadataString(name);
20792071 break :blk switch (info.signedness) {
......@@ -2085,7 +2077,7 @@ pub const Object = struct {
20852077 try o.builder.metadataString("bool"),
20862078 1,
20872079 ),
2088 else => try o.lowerDebugType(ty.childType(zcu)),
2080 else => try o.lowerDebugType(pt, ty.childType(zcu)),
20892081 };
20902082
20912083 const debug_vector_type = try o.builder.debugVectorType(
......@@ -2108,7 +2100,7 @@ pub const Object = struct {
21082100 return debug_vector_type;
21092101 },
21102102 .optional => {
2111 const name = try o.allocTypeName(ty);
2103 const name = try o.allocTypeName(pt, ty);
21122104 defer gpa.free(name);
21132105 const child_ty = ty.optionalChild(zcu);
21142106 if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
......@@ -2126,7 +2118,7 @@ pub const Object = struct {
21262118 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
21272119
21282120 if (ty.optionalReprIsPayload(zcu)) {
2129 const debug_optional_type = try o.lowerDebugType(child_ty);
2121 const debug_optional_type = try o.lowerDebugType(pt, child_ty);
21302122
21312123 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
21322124
......@@ -2149,7 +2141,7 @@ pub const Object = struct {
21492141 .none, // File
21502142 debug_fwd_ref,
21512143 0, // Line
2152 try o.lowerDebugType(child_ty),
2144 try o.lowerDebugType(pt, child_ty),
21532145 payload_size * 8,
21542146 (payload_align.toByteUnits() orelse 0) * 8,
21552147 0, // Offset
......@@ -2160,7 +2152,7 @@ pub const Object = struct {
21602152 .none,
21612153 debug_fwd_ref,
21622154 0,
2163 try o.lowerDebugType(non_null_ty),
2155 try o.lowerDebugType(pt, non_null_ty),
21642156 non_null_size * 8,
21652157 (non_null_align.toByteUnits() orelse 0) * 8,
21662158 non_null_offset * 8,
......@@ -2192,12 +2184,12 @@ pub const Object = struct {
21922184 const payload_ty = ty.errorUnionPayload(zcu);
21932185 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
21942186 // TODO: Maybe remove?
2195 const debug_error_union_type = try o.lowerDebugType(Type.anyerror);
2187 const debug_error_union_type = try o.lowerDebugType(pt, Type.anyerror);
21962188 try o.debug_type_map.put(gpa, ty, debug_error_union_type);
21972189 return debug_error_union_type;
21982190 }
21992191
2200 const name = try o.allocTypeName(ty);
2192 const name = try o.allocTypeName(pt, ty);
22012193 defer gpa.free(name);
22022194
22032195 const error_size = Type.anyerror.abiSize(zcu);
......@@ -2229,7 +2221,7 @@ pub const Object = struct {
22292221 .none, // File
22302222 debug_fwd_ref,
22312223 0, // Line
2232 try o.lowerDebugType(Type.anyerror),
2224 try o.lowerDebugType(pt, Type.anyerror),
22332225 error_size * 8,
22342226 (error_align.toByteUnits() orelse 0) * 8,
22352227 error_offset * 8,
......@@ -2239,7 +2231,7 @@ pub const Object = struct {
22392231 .none, // File
22402232 debug_fwd_ref,
22412233 0, // Line
2242 try o.lowerDebugType(payload_ty),
2234 try o.lowerDebugType(pt, payload_ty),
22432235 payload_size * 8,
22442236 (payload_align.toByteUnits() orelse 0) * 8,
22452237 payload_offset * 8,
......@@ -2270,7 +2262,7 @@ pub const Object = struct {
22702262 return debug_error_set;
22712263 },
22722264 .@"struct" => {
2273 const name = try o.allocTypeName(ty);
2265 const name = try o.allocTypeName(pt, ty);
22742266 defer gpa.free(name);
22752267
22762268 if (zcu.typeToPackedStruct(ty)) |struct_type| {
......@@ -2315,7 +2307,7 @@ pub const Object = struct {
23152307 .none, // File
23162308 debug_fwd_ref,
23172309 0,
2318 try o.lowerDebugType(Type.fromInterned(field_ty)),
2310 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
23192311 field_size * 8,
23202312 (field_align.toByteUnits() orelse 0) * 8,
23212313 field_offset * 8,
......@@ -2347,7 +2339,7 @@ pub const Object = struct {
23472339 // into. Therefore we can satisfy this by making an empty namespace,
23482340 // rather than changing the frontend to unnecessarily resolve the
23492341 // struct field types.
2350 const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty);
2342 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);
23512343 try o.debug_type_map.put(gpa, ty, debug_struct_type);
23522344 return debug_struct_type;
23532345 }
......@@ -2356,7 +2348,7 @@ pub const Object = struct {
23562348 }
23572349
23582350 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2359 const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty);
2351 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);
23602352 try o.debug_type_map.put(gpa, ty, debug_struct_type);
23612353 return debug_struct_type;
23622354 }
......@@ -2388,7 +2380,7 @@ pub const Object = struct {
23882380 .none, // File
23892381 debug_fwd_ref,
23902382 0, // Line
2391 try o.lowerDebugType(field_ty),
2383 try o.lowerDebugType(pt, field_ty),
23922384 field_size * 8,
23932385 (field_align.toByteUnits() orelse 0) * 8,
23942386 field_offset * 8,
......@@ -2415,7 +2407,7 @@ pub const Object = struct {
24152407 return debug_struct_type;
24162408 },
24172409 .@"union" => {
2418 const name = try o.allocTypeName(ty);
2410 const name = try o.allocTypeName(pt, ty);
24192411 defer gpa.free(name);
24202412
24212413 const union_type = ip.loadUnionType(ty.toIntern());
......@@ -2423,7 +2415,7 @@ pub const Object = struct {
24232415 !ty.hasRuntimeBitsIgnoreComptime(zcu) or
24242416 !union_type.haveLayout(ip))
24252417 {
2426 const debug_union_type = try o.makeEmptyNamespaceDebugType(ty);
2418 const debug_union_type = try o.makeEmptyNamespaceDebugType(pt, ty);
24272419 try o.debug_type_map.put(gpa, ty, debug_union_type);
24282420 return debug_union_type;
24292421 }
......@@ -2445,7 +2437,7 @@ pub const Object = struct {
24452437 ty.abiSize(zcu) * 8,
24462438 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
24472439 try o.builder.metadataTuple(
2448 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
2440 &.{try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty))},
24492441 ),
24502442 );
24512443
......@@ -2484,7 +2476,7 @@ pub const Object = struct {
24842476 .none, // File
24852477 debug_union_fwd_ref,
24862478 0, // Line
2487 try o.lowerDebugType(Type.fromInterned(field_ty)),
2479 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
24882480 field_size * 8,
24892481 (field_align.toByteUnits() orelse 0) * 8,
24902482 0, // Offset
......@@ -2534,7 +2526,7 @@ pub const Object = struct {
25342526 .none, // File
25352527 debug_fwd_ref,
25362528 0, // Line
2537 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)),
2529 try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty)),
25382530 layout.tag_size * 8,
25392531 (layout.tag_align.toByteUnits() orelse 0) * 8,
25402532 tag_offset * 8,
......@@ -2588,19 +2580,19 @@ pub const Object = struct {
25882580 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
25892581 const sret = firstParamSRet(fn_info, zcu, target);
25902582 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2591 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
2583 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ret_ty));
25922584
25932585 if (sret) {
25942586 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2595 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2587 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty));
25962588 }
25972589 } else {
2598 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));
2590 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, Type.void));
25992591 }
26002592
26012593 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));
2594 // Stack trace pointer.
2595 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, .fromInterned(.ptr_usize_type)));
26042596 }
26052597
26062598 for (0..fn_info.param_types.len) |i| {
......@@ -2609,9 +2601,9 @@ pub const Object = struct {
26092601
26102602 if (isByRef(param_ty, zcu)) {
26112603 const ptr_ty = try pt.singleMutPtrType(param_ty);
2612 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2604 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty));
26132605 } else {
2614 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));
2606 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, param_ty));
26152607 }
26162608 }
26172609
......@@ -2634,10 +2626,10 @@ pub const Object = struct {
26342626 }
26352627 }
26362628
2637 fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata {
2638 const zcu = o.pt.zcu;
2629 fn namespaceToDebugScope(o: *Object, pt: Zcu.PerThread, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata {
2630 const zcu = pt.zcu;
26392631 const namespace = zcu.namespacePtr(namespace_index);
2640 if (namespace.parent == .none) return try o.getDebugFile(namespace.file_scope);
2632 if (namespace.parent == .none) return try o.getDebugFile(pt, namespace.file_scope);
26412633
26422634 const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index);
26432635
......@@ -2646,12 +2638,12 @@ pub const Object = struct {
26462638 return gop.value_ptr.*;
26472639 }
26482640
2649 fn makeEmptyNamespaceDebugType(o: *Object, ty: Type) !Builder.Metadata {
2650 const zcu = o.pt.zcu;
2641 fn makeEmptyNamespaceDebugType(o: *Object, pt: Zcu.PerThread, ty: Type) !Builder.Metadata {
2642 const zcu = pt.zcu;
26512643 const ip = &zcu.intern_pool;
2652 const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
2644 const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
26532645 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|
2654 try o.namespaceToDebugScope(parent_namespace)
2646 try o.namespaceToDebugScope(pt, parent_namespace)
26552647 else
26562648 file;
26572649 return o.builder.debugStructType(
......@@ -2666,31 +2658,10 @@ pub const Object = struct {
26662658 );
26672659 }
26682660
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 {
2661 fn allocTypeName(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error![:0]const u8 {
26912662 var aw: std.io.Writer.Allocating = .init(o.gpa);
26922663 defer aw.deinit();
2693 ty.print(&aw.writer, o.pt) catch |err| switch (err) {
2664 ty.print(&aw.writer, pt) catch |err| switch (err) {
26942665 error.WriteFailed => return error.OutOfMemory,
26952666 };
26962667 return aw.toOwnedSliceSentinel(0);
......@@ -2701,9 +2672,9 @@ pub const Object = struct {
27012672 /// completed, so if any attributes rely on that, they must be done in updateFunc, not here.
27022673 fn resolveLlvmFunction(
27032674 o: *Object,
2675 pt: Zcu.PerThread,
27042676 nav_index: InternPool.Nav.Index,
27052677 ) Allocator.Error!Builder.Function.Index {
2706 const pt = o.pt;
27072678 const zcu = pt.zcu;
27082679 const ip = &zcu.intern_pool;
27092680 const gpa = o.gpa;
......@@ -2722,7 +2693,7 @@ pub const Object = struct {
27222693 else
27232694 .{ false, .none };
27242695 const function_index = try o.builder.addFunction(
2725 try o.lowerType(ty),
2696 try o.lowerType(pt, ty),
27262697 try o.builder.strtabString((if (is_extern) nav.name else nav.fqn).toSlice(ip)),
27272698 toLlvmAddressSpace(nav.getAddrspace(), target),
27282699 );
......@@ -2755,7 +2726,7 @@ pub const Object = struct {
27552726 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
27562727 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
27572728
2758 const raw_llvm_ret_ty = try o.lowerType(Type.fromInterned(fn_info.return_type));
2729 const raw_llvm_ret_ty = try o.lowerType(pt, Type.fromInterned(fn_info.return_type));
27592730 try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder);
27602731
27612732 llvm_arg_i += 1;
......@@ -2862,19 +2833,19 @@ pub const Object = struct {
28622833 // Add parameter attributes. We handle only the case of extern functions (no body)
28632834 // because functions with bodies are handled in `updateFunc`.
28642835 if (is_extern) {
2865 var it = iterateParamTypes(o, fn_info);
2836 var it = iterateParamTypes(o, pt, fn_info);
28662837 it.llvm_index = llvm_arg_i;
28672838 while (try it.next()) |lowering| switch (lowering) {
28682839 .byval => {
28692840 const param_index = it.zig_index - 1;
28702841 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
28712842 if (!isByRef(param_ty, zcu)) {
2872 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
2843 try o.addByValParamAttrs(pt, &attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
28732844 }
28742845 },
28752846 .byref => {
28762847 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);
2848 const param_llvm_ty = try o.lowerType(pt, param_ty);
28782849 const alignment = param_ty.abiAlignment(zcu);
28792850 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);
28802851 },
......@@ -2969,6 +2940,7 @@ pub const Object = struct {
29692940
29702941 fn resolveGlobalUav(
29712942 o: *Object,
2943 pt: Zcu.PerThread,
29722944 uav: InternPool.Index,
29732945 llvm_addr_space: Builder.AddrSpace,
29742946 alignment: InternPool.Alignment,
......@@ -2986,17 +2958,17 @@ pub const Object = struct {
29862958 }
29872959 errdefer assert(o.uav_map.remove(uav));
29882960
2989 const zcu = o.pt.zcu;
2961 const zcu = pt.zcu;
29902962 const decl_ty = zcu.intern_pool.typeOf(uav);
29912963
29922964 const variable_index = try o.builder.addVariable(
29932965 try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}),
2994 try o.lowerType(Type.fromInterned(decl_ty)),
2966 try o.lowerType(pt, Type.fromInterned(decl_ty)),
29952967 llvm_addr_space,
29962968 );
29972969 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
29982970
2999 try variable_index.setInitializer(try o.lowerValue(uav), &o.builder);
2971 try variable_index.setInitializer(try o.lowerValue(pt, uav), &o.builder);
30002972 variable_index.setLinkage(.internal, &o.builder);
30012973 variable_index.setMutability(.constant, &o.builder);
30022974 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
......@@ -3006,13 +2978,13 @@ pub const Object = struct {
30062978
30072979 fn resolveGlobalNav(
30082980 o: *Object,
2981 pt: Zcu.PerThread,
30092982 nav_index: InternPool.Nav.Index,
30102983 ) Allocator.Error!Builder.Variable.Index {
30112984 const gop = try o.nav_map.getOrPut(o.gpa, nav_index);
30122985 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable;
30132986 errdefer assert(o.nav_map.remove(nav_index));
30142987
3015 const pt = o.pt;
30162988 const zcu = pt.zcu;
30172989 const ip = &zcu.intern_pool;
30182990 const nav = ip.getNav(nav_index);
......@@ -3033,7 +3005,7 @@ pub const Object = struct {
30333005 .strong, .weak => nav.name,
30343006 .link_once => unreachable,
30353007 }.toSlice(ip)),
3036 try o.lowerType(Type.fromInterned(nav.typeOf(ip))),
3008 try o.lowerType(pt, Type.fromInterned(nav.typeOf(ip))),
30373009 toLlvmGlobalAddressSpace(nav.getAddrspace(), zcu.getTarget()),
30383010 );
30393011 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
......@@ -3062,12 +3034,11 @@ pub const Object = struct {
30623034 return variable_index;
30633035 }
30643036
3065 fn errorIntType(o: *Object) Allocator.Error!Builder.Type {
3066 return o.builder.intType(o.pt.zcu.errorSetBits());
3037 fn errorIntType(o: *Object, pt: Zcu.PerThread) Allocator.Error!Builder.Type {
3038 return o.builder.intType(pt.zcu.errorSetBits());
30673039 }
30683040
3069 fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type {
3070 const pt = o.pt;
3041 fn lowerType(o: *Object, pt: Zcu.PerThread, t: Type) Allocator.Error!Builder.Type {
30713042 const zcu = pt.zcu;
30723043 const target = zcu.getTarget();
30733044 const ip = &zcu.intern_pool;
......@@ -3123,7 +3094,7 @@ pub const Object = struct {
31233094 .bool_type => .i1,
31243095 .void_type => .void,
31253096 .type_type => unreachable,
3126 .anyerror_type => try o.errorIntType(),
3097 .anyerror_type => try o.errorIntType(pt),
31273098 .comptime_int_type,
31283099 .comptime_float_type,
31293100 .noreturn_type,
......@@ -3141,11 +3112,11 @@ pub const Object = struct {
31413112 => .ptr,
31423113 .slice_const_u8_type,
31433114 .slice_const_u8_sentinel_0_type,
3144 => try o.builder.structType(.normal, &.{ .ptr, try o.lowerType(Type.usize) }),
3115 => try o.builder.structType(.normal, &.{ .ptr, try o.lowerType(pt, Type.usize) }),
31453116 .optional_noreturn_type => unreachable,
31463117 .anyerror_void_error_union_type,
31473118 .adhoc_inferred_error_set_type,
3148 => try o.errorIntType(),
3119 => try o.errorIntType(pt),
31493120 .generic_poison_type,
31503121 .empty_tuple_type,
31513122 => unreachable,
......@@ -3182,24 +3153,24 @@ pub const Object = struct {
31823153 .one, .many, .c => ptr_ty,
31833154 .slice => try o.builder.structType(.normal, &.{
31843155 ptr_ty,
3185 try o.lowerType(Type.usize),
3156 try o.lowerType(pt, Type.usize),
31863157 }),
31873158 };
31883159 },
31893160 .array_type => |array_type| o.builder.arrayType(
31903161 array_type.lenIncludingSentinel(),
3191 try o.lowerType(Type.fromInterned(array_type.child)),
3162 try o.lowerType(pt, Type.fromInterned(array_type.child)),
31923163 ),
31933164 .vector_type => |vector_type| o.builder.vectorType(
31943165 .normal,
31953166 vector_type.len,
3196 try o.lowerType(Type.fromInterned(vector_type.child)),
3167 try o.lowerType(pt, Type.fromInterned(vector_type.child)),
31973168 ),
31983169 .opt_type => |child_ty| {
31993170 // Must stay in sync with `opt_payload` logic in `lowerPtr`.
32003171 if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(zcu)) return .i8;
32013172
3202 const payload_ty = try o.lowerType(Type.fromInterned(child_ty));
3173 const payload_ty = try o.lowerType(pt, Type.fromInterned(child_ty));
32033174 if (t.optionalReprIsPayload(zcu)) return payload_ty;
32043175
32053176 comptime assert(optional_layout_version == 3);
......@@ -3218,17 +3189,16 @@ pub const Object = struct {
32183189 .error_union_type => |error_union_type| {
32193190 // Must stay in sync with `codegen.errUnionPayloadOffset`.
32203191 // See logic in `lowerPtr`.
3221 const error_type = try o.errorIntType();
3192 const error_type = try o.errorIntType(pt);
32223193 if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu))
32233194 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();
3195 const payload_type = try o.lowerType(pt, Type.fromInterned(error_union_type.payload_type));
32263196
32273197 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(zcu);
3228 const error_align = err_int_ty.abiAlignment(zcu);
3198 const error_align: InternPool.Alignment = .fromByteUnits(std.zig.target.intAlignment(target, zcu.errorSetBits()));
32293199
32303200 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(zcu);
3231 const error_size = err_int_ty.abiSize(zcu);
3201 const error_size = std.zig.target.intByteSize(target, zcu.errorSetBits());
32323202
32333203 var fields: [3]Builder.Type = undefined;
32343204 var fields_len: usize = 2;
......@@ -3262,7 +3232,7 @@ pub const Object = struct {
32623232 const struct_type = ip.loadStructType(t.toIntern());
32633233
32643234 if (struct_type.layout == .@"packed") {
3265 const int_ty = try o.lowerType(Type.fromInterned(struct_type.backingIntTypeUnordered(ip)));
3235 const int_ty = try o.lowerType(pt, Type.fromInterned(struct_type.backingIntTypeUnordered(ip)));
32663236 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
32673237 return int_ty;
32683238 }
......@@ -3312,7 +3282,7 @@ pub const Object = struct {
33123282 .struct_ty = t.toIntern(),
33133283 .field_index = field_index,
33143284 }, @intCast(llvm_field_types.items.len));
3315 try llvm_field_types.append(o.gpa, try o.lowerType(field_ty));
3285 try llvm_field_types.append(o.gpa, try o.lowerType(pt, field_ty));
33163286
33173287 offset += field_ty.abiSize(zcu);
33183288 }
......@@ -3382,7 +3352,7 @@ pub const Object = struct {
33823352 .struct_ty = t.toIntern(),
33833353 .field_index = @intCast(field_index),
33843354 }, @intCast(llvm_field_types.items.len));
3385 try llvm_field_types.append(o.gpa, try o.lowerType(Type.fromInterned(field_ty)));
3355 try llvm_field_types.append(o.gpa, try o.lowerType(pt, Type.fromInterned(field_ty)));
33863356
33873357 offset += Type.fromInterned(field_ty).abiSize(zcu);
33883358 }
......@@ -3410,13 +3380,13 @@ pub const Object = struct {
34103380 }
34113381
34123382 if (layout.payload_size == 0) {
3413 const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
3383 const enum_tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty));
34143384 try o.type_map.put(o.gpa, t.toIntern(), enum_tag_ty);
34153385 return enum_tag_ty;
34163386 }
34173387
34183388 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);
3389 const aligned_field_llvm_ty = try o.lowerType(pt, aligned_field_ty);
34203390
34213391 const payload_ty = ty: {
34223392 if (layout.most_aligned_field_size == layout.payload_size) {
......@@ -3442,7 +3412,7 @@ pub const Object = struct {
34423412 );
34433413 return ty;
34443414 }
3445 const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
3415 const enum_tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty));
34463416
34473417 // Put the tag before or after the payload depending on which one's
34483418 // alignment is greater.
......@@ -3477,9 +3447,9 @@ pub const Object = struct {
34773447 }
34783448 return gop.value_ptr.*;
34793449 },
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(),
3450 .enum_type => try o.lowerType(pt, Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)),
3451 .func_type => |func_type| try o.lowerTypeFn(pt, func_type),
3452 .error_set_type, .inferred_error_set_type => try o.errorIntType(pt),
34833453 // values, not types
34843454 .undef,
34853455 .simple_value,
......@@ -3508,8 +3478,7 @@ pub const Object = struct {
35083478 /// Use this instead of lowerType when you want to handle correctly the case of elem_ty
35093479 /// being a zero bit type, but it should still be lowered as an i8 in such case.
35103480 /// 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;
3481 fn lowerPtrElemTy(o: *Object, pt: Zcu.PerThread, elem_ty: Type) Allocator.Error!Builder.Type {
35133482 const zcu = pt.zcu;
35143483 const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) {
35153484 .@"opaque" => true,
......@@ -3517,15 +3486,14 @@ pub const Object = struct {
35173486 .array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu),
35183487 else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu),
35193488 };
3520 return if (lower_elem_ty) try o.lowerType(elem_ty) else .i8;
3489 return if (lower_elem_ty) try o.lowerType(pt, elem_ty) else .i8;
35213490 }
35223491
3523 fn lowerTypeFn(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
3524 const pt = o.pt;
3492 fn lowerTypeFn(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
35253493 const zcu = pt.zcu;
35263494 const ip = &zcu.intern_pool;
35273495 const target = zcu.getTarget();
3528 const ret_ty = try lowerFnRetTy(o, fn_info);
3496 const ret_ty = try lowerFnRetTy(o, pt, fn_info);
35293497
35303498 var llvm_params: std.ArrayListUnmanaged(Builder.Type) = .empty;
35313499 defer llvm_params.deinit(o.gpa);
......@@ -3535,16 +3503,17 @@ pub const Object = struct {
35353503 }
35363504
35373505 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));
3506 const stack_trace_ty = zcu.builtin_decl_values.get(.StackTrace);
3507 const ptr_ty = try pt.ptrType(.{ .child = stack_trace_ty });
3508 try llvm_params.append(o.gpa, try o.lowerType(pt, ptr_ty));
35403509 }
35413510
3542 var it = iterateParamTypes(o, fn_info);
3511 var it = iterateParamTypes(o, pt, fn_info);
35433512 while (try it.next()) |lowering| switch (lowering) {
35443513 .no_bits => continue,
35453514 .byval => {
35463515 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));
3516 try llvm_params.append(o.gpa, try o.lowerType(pt, param_ty));
35483517 },
35493518 .byref, .byref_mut => {
35503519 try llvm_params.append(o.gpa, .ptr);
......@@ -3559,7 +3528,7 @@ pub const Object = struct {
35593528 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
35603529 try llvm_params.appendSlice(o.gpa, &.{
35613530 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(zcu), target)),
3562 try o.lowerType(Type.usize),
3531 try o.lowerType(pt, Type.usize),
35633532 });
35643533 },
35653534 .multiple_llvm_types => {
......@@ -3567,7 +3536,7 @@ pub const Object = struct {
35673536 },
35683537 .float_array => |count| {
35693538 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).?);
3539 const float_ty = try o.lowerType(pt, aarch64_c_abi.getFloatArrayType(param_ty, zcu).?);
35713540 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));
35723541 },
35733542 .i32_array, .i64_array => |arr_len| {
......@@ -3586,8 +3555,7 @@ pub const Object = struct {
35863555 );
35873556 }
35883557
3589 fn lowerValueToInt(o: *Object, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {
3590 const pt = o.pt;
3558 fn lowerValueToInt(o: *Object, pt: Zcu.PerThread, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {
35913559 const zcu = pt.zcu;
35923560 const ip = &zcu.intern_pool;
35933561 const target = zcu.getTarget();
......@@ -3600,23 +3568,23 @@ pub const Object = struct {
36003568 const ty = Type.fromInterned(val_key.typeOf());
36013569 switch (val_key) {
36023570 .@"extern" => |@"extern"| {
3603 const function_index = try o.resolveLlvmFunction(@"extern".owner_nav);
3571 const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav);
36043572 const ptr = function_index.ptrConst(&o.builder).global.toConst();
36053573 return o.builder.convConst(ptr, llvm_int_ty);
36063574 },
36073575 .func => |func| {
3608 const function_index = try o.resolveLlvmFunction(func.owner_nav);
3576 const function_index = try o.resolveLlvmFunction(pt, func.owner_nav);
36093577 const ptr = function_index.ptrConst(&o.builder).global.toConst();
36103578 return o.builder.convConst(ptr, llvm_int_ty);
36113579 },
3612 .ptr => return o.builder.convConst(try o.lowerPtr(arg_val, 0), llvm_int_ty),
3580 .ptr => return o.builder.convConst(try o.lowerPtr(pt, arg_val, 0), llvm_int_ty),
36133581 .aggregate => switch (ip.indexToKey(ty.toIntern())) {
36143582 .struct_type, .vector_type => {},
36153583 else => unreachable,
36163584 },
36173585 .un => |un| {
36183586 const layout = ty.unionGetLayout(zcu);
3619 if (layout.payload_size == 0) return o.lowerValue(un.tag);
3587 if (layout.payload_size == 0) return o.lowerValue(pt, un.tag);
36203588
36213589 const union_obj = zcu.typeToUnion(ty).?;
36223590 const container_layout = union_obj.flagsUnordered(ip).layout;
......@@ -3626,7 +3594,7 @@ pub const Object = struct {
36263594 var need_unnamed = false;
36273595 if (un.tag == .none) {
36283596 assert(layout.tag_size == 0);
3629 const union_val = try o.lowerValueToInt(llvm_int_ty, un.val);
3597 const union_val = try o.lowerValueToInt(pt, llvm_int_ty, un.val);
36303598
36313599 need_unnamed = true;
36323600 return union_val;
......@@ -3634,7 +3602,7 @@ pub const Object = struct {
36343602 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
36353603 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
36363604 if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(llvm_int_ty, 0);
3637 return o.lowerValueToInt(llvm_int_ty, un.val);
3605 return o.lowerValueToInt(pt, llvm_int_ty, un.val);
36383606 },
36393607 .simple_value => |simple_value| switch (simple_value) {
36403608 .false, .true => {},
......@@ -3678,8 +3646,7 @@ pub const Object = struct {
36783646 });
36793647 }
36803648
3681 fn lowerValue(o: *Object, arg_val: InternPool.Index) Error!Builder.Constant {
3682 const pt = o.pt;
3649 fn lowerValue(o: *Object, pt: Zcu.PerThread, arg_val: InternPool.Index) Error!Builder.Constant {
36833650 const zcu = pt.zcu;
36843651 const ip = &zcu.intern_pool;
36853652 const target = zcu.getTarget();
......@@ -3688,7 +3655,7 @@ pub const Object = struct {
36883655 const val_key = ip.indexToKey(val.toIntern());
36893656
36903657 if (val.isUndefDeep(zcu)) {
3691 return o.builder.undefConst(try o.lowerType(Type.fromInterned(val_key.typeOf())));
3658 return o.builder.undefConst(try o.lowerType(pt, Type.fromInterned(val_key.typeOf())));
36923659 }
36933660
36943661 const ty = Type.fromInterned(val_key.typeOf());
......@@ -3727,21 +3694,21 @@ pub const Object = struct {
37273694 .empty_enum_value,
37283695 => unreachable, // non-runtime values
37293696 .@"extern" => |@"extern"| {
3730 const function_index = try o.resolveLlvmFunction(@"extern".owner_nav);
3697 const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav);
37313698 return function_index.ptrConst(&o.builder).global.toConst();
37323699 },
37333700 .func => |func| {
3734 const function_index = try o.resolveLlvmFunction(func.owner_nav);
3701 const function_index = try o.resolveLlvmFunction(pt, func.owner_nav);
37353702 return function_index.ptrConst(&o.builder).global.toConst();
37363703 },
37373704 .int => {
37383705 var bigint_space: Value.BigIntSpace = undefined;
37393706 const bigint = val.toBigInt(&bigint_space, zcu);
3740 return lowerBigInt(o, ty, bigint);
3707 return lowerBigInt(o, pt, ty, bigint);
37413708 },
37423709 .err => |err| {
37433710 const int = try pt.getErrorValue(err.name);
3744 const llvm_int = try o.builder.intConst(try o.errorIntType(), int);
3711 const llvm_int = try o.builder.intConst(try o.errorIntType(pt), int);
37453712 return llvm_int;
37463713 },
37473714 .error_union => |error_union| {
......@@ -3756,13 +3723,13 @@ pub const Object = struct {
37563723 const payload_type = ty.errorUnionPayload(zcu);
37573724 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
37583725 // We use the error type directly as the type.
3759 return o.lowerValue(err_val);
3726 return o.lowerValue(pt, err_val);
37603727 }
37613728
37623729 const payload_align = payload_type.abiAlignment(zcu);
37633730 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) {
3731 const llvm_error_value = try o.lowerValue(pt, err_val);
3732 const llvm_payload_value = try o.lowerValue(pt, switch (error_union.val) {
37663733 .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }),
37673734 .payload => |payload| payload,
37683735 });
......@@ -3779,7 +3746,7 @@ pub const Object = struct {
37793746 fields[0] = vals[0].typeOf(&o.builder);
37803747 fields[1] = vals[1].typeOf(&o.builder);
37813748
3782 const llvm_ty = try o.lowerType(ty);
3749 const llvm_ty = try o.lowerType(pt, ty);
37833750 const llvm_ty_fields = llvm_ty.structFields(&o.builder);
37843751 if (llvm_ty_fields.len > 2) {
37853752 assert(llvm_ty_fields.len == 3);
......@@ -3791,7 +3758,7 @@ pub const Object = struct {
37913758 fields[0..llvm_ty_fields.len],
37923759 ), vals[0..llvm_ty_fields.len]);
37933760 },
3794 .enum_tag => |enum_tag| o.lowerValue(enum_tag.int),
3761 .enum_tag => |enum_tag| o.lowerValue(pt, enum_tag.int),
37953762 .float => switch (ty.floatBits(target)) {
37963763 16 => if (backendSupportsF16(target))
37973764 try o.builder.halfConst(val.toFloat(f16, zcu))
......@@ -3806,10 +3773,10 @@ pub const Object = struct {
38063773 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)),
38073774 else => unreachable,
38083775 },
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),
3776 .ptr => try o.lowerPtr(pt, arg_val, 0),
3777 .slice => |slice| return o.builder.structConst(try o.lowerType(pt, ty), &.{
3778 try o.lowerValue(pt, slice.ptr),
3779 try o.lowerValue(pt, slice.len),
38133780 }),
38143781 .opt => |opt| {
38153782 comptime assert(optional_layout_version == 3);
......@@ -3819,7 +3786,7 @@ pub const Object = struct {
38193786 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
38203787 return non_null_bit;
38213788 }
3822 const llvm_ty = try o.lowerType(ty);
3789 const llvm_ty = try o.lowerType(pt, ty);
38233790 if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) {
38243791 .none => switch (llvm_ty.tag(&o.builder)) {
38253792 .integer => try o.builder.intConst(llvm_ty, 0),
......@@ -3827,13 +3794,13 @@ pub const Object = struct {
38273794 .structure => try o.builder.zeroInitConst(llvm_ty),
38283795 else => unreachable,
38293796 },
3830 else => |payload| try o.lowerValue(payload),
3797 else => |payload| try o.lowerValue(pt, payload),
38313798 };
38323799 assert(payload_ty.zigTypeTag(zcu) != .@"fn");
38333800
38343801 var fields: [3]Builder.Type = undefined;
38353802 var vals: [3]Builder.Constant = undefined;
3836 vals[0] = try o.lowerValue(switch (opt.val) {
3803 vals[0] = try o.lowerValue(pt, switch (opt.val) {
38373804 .none => try pt.intern(.{ .undef = payload_ty.toIntern() }),
38383805 else => |payload| payload,
38393806 });
......@@ -3858,7 +3825,7 @@ pub const Object = struct {
38583825 bytes.toSlice(array_type.lenIncludingSentinel(), ip),
38593826 )),
38603827 .elems => |elems| {
3861 const array_ty = try o.lowerType(ty);
3828 const array_ty = try o.lowerType(pt, ty);
38623829 const elem_ty = array_ty.childType(&o.builder);
38633830 assert(elems.len == array_ty.aggregateLen(&o.builder));
38643831
......@@ -3878,7 +3845,7 @@ pub const Object = struct {
38783845
38793846 var need_unnamed = false;
38803847 for (vals, fields, elems) |*result_val, *result_field, elem| {
3881 result_val.* = try o.lowerValue(elem);
3848 result_val.* = try o.lowerValue(pt, elem);
38823849 result_field.* = result_val.typeOf(&o.builder);
38833850 if (result_field.* != elem_ty) need_unnamed = true;
38843851 }
......@@ -3890,7 +3857,7 @@ pub const Object = struct {
38903857 .repeated_elem => |elem| {
38913858 const len: usize = @intCast(array_type.len);
38923859 const len_including_sentinel: usize = @intCast(array_type.lenIncludingSentinel());
3893 const array_ty = try o.lowerType(ty);
3860 const array_ty = try o.lowerType(pt, ty);
38943861 const elem_ty = array_ty.childType(&o.builder);
38953862
38963863 const ExpectedContents = extern struct {
......@@ -3908,12 +3875,12 @@ pub const Object = struct {
39083875 defer allocator.free(fields);
39093876
39103877 var need_unnamed = false;
3911 @memset(vals[0..len], try o.lowerValue(elem));
3878 @memset(vals[0..len], try o.lowerValue(pt, elem));
39123879 @memset(fields[0..len], vals[0].typeOf(&o.builder));
39133880 if (fields[0] != elem_ty) need_unnamed = true;
39143881
39153882 if (array_type.sentinel != .none) {
3916 vals[len] = try o.lowerValue(array_type.sentinel);
3883 vals[len] = try o.lowerValue(pt, array_type.sentinel);
39173884 fields[len] = vals[len].typeOf(&o.builder);
39183885 if (fields[len] != elem_ty) need_unnamed = true;
39193886 }
......@@ -3925,7 +3892,7 @@ pub const Object = struct {
39253892 },
39263893 },
39273894 .vector_type => |vector_type| {
3928 const vector_ty = try o.lowerType(ty);
3895 const vector_ty = try o.lowerType(pt, ty);
39293896 switch (aggregate.storage) {
39303897 .bytes, .elems => {
39313898 const ExpectedContents = [Builder.expected_fields_len]Builder.Constant;
......@@ -3942,7 +3909,7 @@ pub const Object = struct {
39423909 result_val.* = try o.builder.intConst(.i8, byte);
39433910 },
39443911 .elems => |elems| for (vals, elems) |*result_val, elem| {
3945 result_val.* = try o.lowerValue(elem);
3912 result_val.* = try o.lowerValue(pt, elem);
39463913 },
39473914 .repeated_elem => unreachable,
39483915 }
......@@ -3950,12 +3917,12 @@ pub const Object = struct {
39503917 },
39513918 .repeated_elem => |elem| return o.builder.splatConst(
39523919 vector_ty,
3953 try o.lowerValue(elem),
3920 try o.lowerValue(pt, elem),
39543921 ),
39553922 }
39563923 },
39573924 .tuple_type => |tuple| {
3958 const struct_ty = try o.lowerType(ty);
3925 const struct_ty = try o.lowerType(pt, ty);
39593926 const llvm_len = struct_ty.aggregateLen(&o.builder);
39603927
39613928 const ExpectedContents = extern struct {
......@@ -4001,7 +3968,7 @@ pub const Object = struct {
40013968 }
40023969
40033970 vals[llvm_index] =
4004 try o.lowerValue((try val.fieldValue(pt, field_index)).toIntern());
3971 try o.lowerValue(pt, (try val.fieldValue(pt, field_index)).toIntern());
40053972 fields[llvm_index] = vals[llvm_index].typeOf(&o.builder);
40063973 if (fields[llvm_index] != struct_ty.structFields(&o.builder)[llvm_index])
40073974 need_unnamed = true;
......@@ -4030,14 +3997,14 @@ pub const Object = struct {
40303997 .struct_type => {
40313998 const struct_type = ip.loadStructType(ty.toIntern());
40323999 assert(struct_type.haveLayout(ip));
4033 const struct_ty = try o.lowerType(ty);
4000 const struct_ty = try o.lowerType(pt, ty);
40344001 if (struct_type.layout == .@"packed") {
40354002 comptime assert(Type.packed_struct_layout_version == 2);
40364003
40374004 const bits = ty.bitSize(zcu);
40384005 const llvm_int_ty = try o.builder.intType(@intCast(bits));
40394006
4040 return o.lowerValueToInt(llvm_int_ty, arg_val);
4007 return o.lowerValueToInt(pt, llvm_int_ty, arg_val);
40414008 }
40424009 const llvm_len = struct_ty.aggregateLen(&o.builder);
40434010
......@@ -4085,6 +4052,7 @@ pub const Object = struct {
40854052 }
40864053
40874054 vals[llvm_index] = try o.lowerValue(
4055 pt,
40884056 (try val.fieldValue(pt, field_index)).toIntern(),
40894057 );
40904058 fields[llvm_index] = vals[llvm_index].typeOf(&o.builder);
......@@ -4115,9 +4083,9 @@ pub const Object = struct {
41154083 else => unreachable,
41164084 },
41174085 .un => |un| {
4118 const union_ty = try o.lowerType(ty);
4086 const union_ty = try o.lowerType(pt, ty);
41194087 const layout = ty.unionGetLayout(zcu);
4120 if (layout.payload_size == 0) return o.lowerValue(un.tag);
4088 if (layout.payload_size == 0) return o.lowerValue(pt, un.tag);
41214089
41224090 const union_obj = zcu.typeToUnion(ty).?;
41234091 const container_layout = union_obj.flagsUnordered(ip).layout;
......@@ -4131,7 +4099,7 @@ pub const Object = struct {
41314099 const bits = ty.bitSize(zcu);
41324100 const llvm_int_ty = try o.builder.intType(@intCast(bits));
41334101
4134 return o.lowerValueToInt(llvm_int_ty, arg_val);
4102 return o.lowerValueToInt(pt, llvm_int_ty, arg_val);
41354103 }
41364104
41374105 // Sometimes we must make an unnamed struct because LLVM does
......@@ -4144,7 +4112,7 @@ pub const Object = struct {
41444112 const padding_len = layout.payload_size;
41454113 break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8));
41464114 }
4147 const payload = try o.lowerValue(un.val);
4115 const payload = try o.lowerValue(pt, un.val);
41484116 const payload_ty = payload.typeOf(&o.builder);
41494117 if (payload_ty != union_ty.structFields(&o.builder)[
41504118 @intFromBool(layout.tag_align.compare(.gte, layout.payload_align))
......@@ -4163,10 +4131,10 @@ pub const Object = struct {
41634131 const bits = ty.bitSize(zcu);
41644132 const llvm_int_ty = try o.builder.intType(@intCast(bits));
41654133
4166 return o.lowerValueToInt(llvm_int_ty, arg_val);
4134 return o.lowerValueToInt(pt, llvm_int_ty, arg_val);
41674135 }
41684136
4169 const union_val = try o.lowerValue(un.val);
4137 const union_val = try o.lowerValue(pt, un.val);
41704138 need_unnamed = true;
41714139 break :p union_val;
41724140 };
......@@ -4176,7 +4144,7 @@ pub const Object = struct {
41764144 try o.builder.structType(union_ty.structKind(&o.builder), &.{payload_ty})
41774145 else
41784146 union_ty, &.{payload});
4179 const tag = try o.lowerValue(un.tag);
4147 const tag = try o.lowerValue(pt, un.tag);
41804148 const tag_ty = tag.typeOf(&o.builder);
41814149 var fields: [3]Builder.Type = undefined;
41824150 var vals: [3]Builder.Constant = undefined;
......@@ -4204,48 +4172,50 @@ pub const Object = struct {
42044172
42054173 fn lowerBigInt(
42064174 o: *Object,
4175 pt: Zcu.PerThread,
42074176 ty: Type,
42084177 bigint: std.math.big.int.Const,
42094178 ) Allocator.Error!Builder.Constant {
4210 const zcu = o.pt.zcu;
4179 const zcu = pt.zcu;
42114180 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint);
42124181 }
42134182
42144183 fn lowerPtr(
42154184 o: *Object,
4185 pt: Zcu.PerThread,
42164186 ptr_val: InternPool.Index,
42174187 prev_offset: u64,
42184188 ) Error!Builder.Constant {
4219 const pt = o.pt;
42204189 const zcu = pt.zcu;
42214190 const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr;
42224191 const offset: u64 = prev_offset + ptr.byte_offset;
42234192 return switch (ptr.base_addr) {
42244193 .nav => |nav| {
4225 const base_ptr = try o.lowerNavRefValue(nav);
4194 const base_ptr = try o.lowerNavRefValue(pt, nav);
42264195 return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{
42274196 try o.builder.intConst(.i64, offset),
42284197 });
42294198 },
42304199 .uav => |uav| {
4231 const base_ptr = try o.lowerUavRef(uav);
4200 const base_ptr = try o.lowerUavRef(pt, uav);
42324201 return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{
42334202 try o.builder.intConst(.i64, offset),
42344203 });
42354204 },
42364205 .int => try o.builder.castConst(
42374206 .inttoptr,
4238 try o.builder.intConst(try o.lowerType(Type.usize), offset),
4239 try o.lowerType(Type.fromInterned(ptr.ty)),
4207 try o.builder.intConst(try o.lowerType(pt, Type.usize), offset),
4208 try o.lowerType(pt, Type.fromInterned(ptr.ty)),
42404209 ),
42414210 .eu_payload => |eu_ptr| try o.lowerPtr(
4211 pt,
42424212 eu_ptr,
42434213 offset + @import("../codegen.zig").errUnionPayloadOffset(
42444214 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu),
42454215 zcu,
42464216 ),
42474217 ),
4248 .opt_payload => |opt_ptr| try o.lowerPtr(opt_ptr, offset),
4218 .opt_payload => |opt_ptr| try o.lowerPtr(pt, opt_ptr, offset),
42494219 .field => |field| {
42504220 const agg_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu);
42514221 const field_off: u64 = switch (agg_ty.zigTypeTag(zcu)) {
......@@ -4263,7 +4233,7 @@ pub const Object = struct {
42634233 },
42644234 else => unreachable,
42654235 };
4266 return o.lowerPtr(field.base, offset + field_off);
4236 return o.lowerPtr(pt, field.base, offset + field_off);
42674237 },
42684238 .arr_elem, .comptime_field, .comptime_alloc => unreachable,
42694239 };
......@@ -4273,9 +4243,9 @@ pub const Object = struct {
42734243 /// Maybe the logic could be unified.
42744244 fn lowerUavRef(
42754245 o: *Object,
4246 pt: Zcu.PerThread,
42764247 uav: InternPool.Key.Ptr.BaseAddr.Uav,
42774248 ) Error!Builder.Constant {
4278 const pt = o.pt;
42794249 const zcu = pt.zcu;
42804250 const ip = &zcu.intern_pool;
42814251 const uav_val = uav.val;
......@@ -4292,25 +4262,24 @@ pub const Object = struct {
42924262
42934263 const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn";
42944264 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);
4265 (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(pt, ptr_ty);
42964266
42974267 if (is_fn_body)
42984268 @panic("TODO");
42994269
43004270 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target);
43014271 const alignment = ptr_ty.ptrAlignment(zcu);
4302 const llvm_global = (try o.resolveGlobalUav(uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
4272 const llvm_global = (try o.resolveGlobalUav(pt, uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
43034273
43044274 const llvm_val = try o.builder.convConst(
43054275 llvm_global.toConst(),
43064276 try o.builder.ptrType(llvm_addr_space),
43074277 );
43084278
4309 return o.builder.convConst(llvm_val, try o.lowerType(ptr_ty));
4279 return o.builder.convConst(llvm_val, try o.lowerType(pt, ptr_ty));
43104280 }
43114281
4312 fn lowerNavRefValue(o: *Object, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant {
4313 const pt = o.pt;
4282 fn lowerNavRefValue(o: *Object, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant {
43144283 const zcu = pt.zcu;
43154284 const ip = &zcu.intern_pool;
43164285
......@@ -4323,24 +4292,24 @@ pub const Object = struct {
43234292 if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or
43244293 (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic))
43254294 {
4326 return o.lowerPtrToVoid(ptr_ty);
4295 return o.lowerPtrToVoid(pt, ptr_ty);
43274296 }
43284297
43294298 const llvm_global = if (is_fn_body)
4330 (try o.resolveLlvmFunction(nav_index)).ptrConst(&o.builder).global
4299 (try o.resolveLlvmFunction(pt, nav_index)).ptrConst(&o.builder).global
43314300 else
4332 (try o.resolveGlobalNav(nav_index)).ptrConst(&o.builder).global;
4301 (try o.resolveGlobalNav(pt, nav_index)).ptrConst(&o.builder).global;
43334302
43344303 const llvm_val = try o.builder.convConst(
43354304 llvm_global.toConst(),
43364305 try o.builder.ptrType(toLlvmAddressSpace(nav.getAddrspace(), zcu.getTarget())),
43374306 );
43384307
4339 return o.builder.convConst(llvm_val, try o.lowerType(ptr_ty));
4308 return o.builder.convConst(llvm_val, try o.lowerType(pt, ptr_ty));
43404309 }
43414310
4342 fn lowerPtrToVoid(o: *Object, ptr_ty: Type) Allocator.Error!Builder.Constant {
4343 const zcu = o.pt.zcu;
4311 fn lowerPtrToVoid(o: *Object, pt: Zcu.PerThread, ptr_ty: Type) Allocator.Error!Builder.Constant {
4312 const zcu = pt.zcu;
43444313 // Even though we are pointing at something which has zero bits (e.g. `void`),
43454314 // Pointers are defined to have bits. So we must return something here.
43464315 // The value cannot be undefined, because we use the `nonnull` annotation
......@@ -4358,8 +4327,8 @@ pub const Object = struct {
43584327 64 => 0xaaaaaaaa_aaaaaaaa,
43594328 else => unreachable,
43604329 };
4361 const llvm_usize = try o.lowerType(Type.usize);
4362 const llvm_ptr_ty = try o.lowerType(ptr_ty);
4330 const llvm_usize = try o.lowerType(pt, Type.usize);
4331 const llvm_ptr_ty = try o.lowerType(pt, ptr_ty);
43634332 return o.builder.castConst(.inttoptr, try o.builder.intConst(llvm_usize, int), llvm_ptr_ty);
43644333 }
43654334
......@@ -4367,8 +4336,7 @@ pub const Object = struct {
43674336 /// widen it before using it and then truncate the result.
43684337 /// RMW exchange of floating-point values is bitcasted to same-sized integer
43694338 /// 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;
4339 fn getAtomicAbiType(o: *Object, pt: Zcu.PerThread, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type {
43724340 const zcu = pt.zcu;
43734341 const int_ty = switch (ty.zigTypeTag(zcu)) {
43744342 .int => ty,
......@@ -4390,13 +4358,13 @@ pub const Object = struct {
43904358
43914359 fn addByValParamAttrs(
43924360 o: *Object,
4361 pt: Zcu.PerThread,
43934362 attributes: *Builder.FunctionAttributes.Wip,
43944363 param_ty: Type,
43954364 param_index: u32,
43964365 fn_info: InternPool.Key.FuncType,
43974366 llvm_arg_i: u32,
43984367 ) Allocator.Error!void {
4399 const pt = o.pt;
44004368 const zcu = pt.zcu;
44014369 if (param_ty.isPtrAtRuntime(zcu)) {
44024370 const ptr_info = param_ty.ptrInfo(zcu);
......@@ -4416,7 +4384,7 @@ pub const Object = struct {
44164384 .x86_64_interrupt,
44174385 .x86_interrupt,
44184386 => {
4419 const child_type = try lowerType(o, Type.fromInterned(ptr_info.child));
4387 const child_type = try lowerType(o, pt, Type.fromInterned(ptr_info.child));
44204388 try attributes.addParamAttr(llvm_arg_i, .{ .byval = child_type }, &o.builder);
44214389 },
44224390 }
......@@ -4455,14 +4423,14 @@ pub const Object = struct {
44554423 });
44564424 }
44574425
4458 fn getCmpLtErrorsLenFunction(o: *Object) !Builder.Function.Index {
4426 fn getCmpLtErrorsLenFunction(o: *Object, pt: Zcu.PerThread) !Builder.Function.Index {
44594427 const name = try o.builder.strtabString(lt_errors_fn_name);
44604428 if (o.builder.getGlobal(name)) |llvm_fn| return llvm_fn.ptrConst(&o.builder).kind.function;
44614429
4462 const zcu = o.pt.zcu;
4430 const zcu = pt.zcu;
44634431 const target = &zcu.root_mod.resolved_target.result;
44644432 const function_index = try o.builder.addFunction(
4465 try o.builder.fnType(.i1, &.{try o.errorIntType()}, .normal),
4433 try o.builder.fnType(.i1, &.{try o.errorIntType(pt)}, .normal),
44664434 name,
44674435 toLlvmAddressSpace(.generic, target),
44684436 );
......@@ -4477,8 +4445,7 @@ pub const Object = struct {
44774445 return function_index;
44784446 }
44794447
4480 fn getEnumTagNameFunction(o: *Object, enum_ty: Type) !Builder.Function.Index {
4481 const pt = o.pt;
4448 fn getEnumTagNameFunction(o: *Object, pt: Zcu.PerThread, enum_ty: Type) !Builder.Function.Index {
44824449 const zcu = pt.zcu;
44834450 const ip = &zcu.intern_pool;
44844451 const enum_type = ip.loadEnumType(enum_ty.toIntern());
......@@ -4487,11 +4454,11 @@ pub const Object = struct {
44874454 if (gop.found_existing) return gop.value_ptr.ptrConst(&o.builder).kind.function;
44884455 errdefer assert(o.enum_tag_name_map.remove(enum_ty.toIntern()));
44894456
4490 const usize_ty = try o.lowerType(Type.usize);
4491 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);
4457 const usize_ty = try o.lowerType(pt, Type.usize);
4458 const ret_ty = try o.lowerType(pt, Type.slice_const_u8_sentinel_0);
44924459 const target = &zcu.root_mod.resolved_target.result;
44934460 const function_index = try o.builder.addFunction(
4494 try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
4461 try o.builder.fnType(ret_ty, &.{try o.lowerType(pt, Type.fromInterned(enum_type.tag_ty))}, .normal),
44954462 try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_type.name.fmt(ip)}),
44964463 toLlvmAddressSpace(.generic, target),
44974464 );
......@@ -4536,6 +4503,7 @@ pub const Object = struct {
45364503
45374504 const return_block = try wip.block(1, "Name");
45384505 const this_tag_int_value = try o.lowerValue(
4506 pt,
45394507 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),
45404508 );
45414509 try wip_switch.addCase(this_tag_int_value, return_block, &wip);
......@@ -4555,10 +4523,11 @@ pub const Object = struct {
45554523pub const NavGen = struct {
45564524 object: *Object,
45574525 nav_index: InternPool.Nav.Index,
4526 pt: Zcu.PerThread,
45584527 err_msg: ?*Zcu.ErrorMsg,
45594528
45604529 fn ownerModule(ng: NavGen) *Package.Module {
4561 return ng.object.pt.zcu.navFileScope(ng.nav_index).mod.?;
4530 return ng.pt.zcu.navFileScope(ng.nav_index).mod.?;
45624531 }
45634532
45644533 fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {
......@@ -4566,14 +4535,14 @@ pub const NavGen = struct {
45664535 assert(ng.err_msg == null);
45674536 const o = ng.object;
45684537 const gpa = o.gpa;
4569 const src_loc = o.pt.zcu.navSrcLoc(ng.nav_index);
4538 const src_loc = ng.pt.zcu.navSrcLoc(ng.nav_index);
45704539 ng.err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
45714540 return error.CodegenFail;
45724541 }
45734542
45744543 fn genDecl(ng: *NavGen) !void {
45754544 const o = ng.object;
4576 const pt = o.pt;
4545 const pt = ng.pt;
45774546 const zcu = pt.zcu;
45784547 const ip = &zcu.intern_pool;
45794548 const nav_index = ng.nav_index;
......@@ -4588,16 +4557,16 @@ pub const NavGen = struct {
45884557 const ty = Type.fromInterned(nav.typeOf(ip));
45894558
45904559 if (linkage != .internal and ip.isFunctionType(ty.toIntern())) {
4591 _ = try o.resolveLlvmFunction(owner_nav);
4560 _ = try o.resolveLlvmFunction(pt, owner_nav);
45924561 } else {
4593 const variable_index = try o.resolveGlobalNav(nav_index);
4562 const variable_index = try o.resolveGlobalNav(pt, nav_index);
45944563 variable_index.setAlignment(pt.navAlignment(nav_index).toLlvm(), &o.builder);
45954564 if (resolved.@"linksection".toSlice(ip)) |section|
45964565 variable_index.setSection(try o.builder.string(section), &o.builder);
45974566 if (is_const) variable_index.setMutability(.constant, &o.builder);
45984567 try variable_index.setInitializer(switch (init_val) {
45994568 .none => .no_init,
4600 else => try o.lowerValue(init_val),
4569 else => try o.lowerValue(pt, init_val),
46014570 }, &o.builder);
46024571 variable_index.setVisibility(visibility, &o.builder);
46034572
......@@ -4609,7 +4578,7 @@ pub const NavGen = struct {
46094578 const line_number = zcu.navSrcLine(nav_index) + 1;
46104579
46114580 if (!mod.strip) {
4612 const debug_file = try o.getDebugFile(file_scope);
4581 const debug_file = try o.getDebugFile(pt, file_scope);
46134582
46144583 const debug_global_var = try o.builder.debugGlobalVar(
46154584 try o.builder.metadataString(nav.name.toSlice(ip)), // Name
......@@ -4617,7 +4586,7 @@ pub const NavGen = struct {
46174586 debug_file, // File
46184587 debug_file, // Scope
46194588 line_number,
4620 try o.lowerDebugType(ty),
4589 try o.lowerDebugType(pt, ty),
46214590 variable_index,
46224591 .{ .local = linkage == .internal },
46234592 );
......@@ -4814,16 +4783,17 @@ pub const FuncGen = struct {
48144783 const gop = try self.func_inst_table.getOrPut(gpa, inst);
48154784 if (gop.found_existing) return gop.value_ptr.*;
48164785
4817 const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.object.pt)).?);
4786 const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.pt)).?);
48184787 gop.value_ptr.* = llvm_val.toValue();
48194788 return llvm_val.toValue();
48204789 }
48214790
48224791 fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant {
48234792 const o = self.ng.object;
4824 const zcu = o.pt.zcu;
4793 const pt = self.ng.pt;
4794 const zcu = pt.zcu;
48254795 const ty = val.typeOf(zcu);
4826 const llvm_val = try o.lowerValue(val.toIntern());
4796 const llvm_val = try o.lowerValue(pt, val.toIntern());
48274797 if (!isByRef(ty, zcu)) return llvm_val;
48284798
48294799 // We have an LLVM value but we need to create a global constant and
......@@ -4847,7 +4817,7 @@ pub const FuncGen = struct {
48474817
48484818 fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) Error!void {
48494819 const o = self.ng.object;
4850 const zcu = o.pt.zcu;
4820 const zcu = self.ng.pt.zcu;
48514821 const ip = &zcu.intern_pool;
48524822 const air_tags = self.air.instructions.items(.tag);
48534823 switch (coverage_point) {
......@@ -5173,7 +5143,7 @@ pub const FuncGen = struct {
51735143
51745144 if (maybe_inline_func) |inline_func| {
51755145 const o = self.ng.object;
5176 const pt = o.pt;
5146 const pt = self.ng.pt;
51775147 const zcu = pt.zcu;
51785148 const ip = &zcu.intern_pool;
51795149
......@@ -5182,7 +5152,7 @@ pub const FuncGen = struct {
51825152 const file_scope = zcu.navFileScopeIndex(func.owner_nav);
51835153 const mod = zcu.fileByIndex(file_scope).mod.?;
51845154
5185 self.file = try o.getDebugFile(file_scope);
5155 self.file = try o.getDebugFile(pt, file_scope);
51865156
51875157 const line_number = zcu.navSrcLine(func.owner_nav) + 1;
51885158 self.inlined = self.wip.debug_location;
......@@ -5198,7 +5168,7 @@ pub const FuncGen = struct {
51985168 try o.builder.metadataString(nav.fqn.toSlice(&zcu.intern_pool)),
51995169 line_number,
52005170 line_number + func.lbrace_line,
5201 try o.lowerDebugType(fn_ty),
5171 try o.lowerDebugType(pt, fn_ty),
52025172 .{
52035173 .di_flags = .{ .StaticMember = true },
52045174 .sp_flags = .{
......@@ -5255,7 +5225,7 @@ pub const FuncGen = struct {
52555225 const extra = self.air.extraData(Air.Call, pl_op.payload);
52565226 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[extra.end..][0..extra.data.args_len]);
52575227 const o = self.ng.object;
5258 const pt = o.pt;
5228 const pt = self.ng.pt;
52595229 const zcu = pt.zcu;
52605230 const ip = &zcu.intern_pool;
52615231 const callee_ty = self.typeOf(pl_op.operand);
......@@ -5287,7 +5257,7 @@ pub const FuncGen = struct {
52875257 }
52885258
52895259 const ret_ptr = if (!sret) null else blk: {
5290 const llvm_ret_ty = try o.lowerType(return_type);
5260 const llvm_ret_ty = try o.lowerType(pt, return_type);
52915261 try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder);
52925262
52935263 const alignment = return_type.abiAlignment(zcu).toLlvm();
......@@ -5302,14 +5272,14 @@ pub const FuncGen = struct {
53025272 try llvm_args.append(self.err_ret_trace);
53035273 }
53045274
5305 var it = iterateParamTypes(o, fn_info);
5275 var it = iterateParamTypes(o, pt, fn_info);
53065276 while (try it.nextCall(self, args)) |lowering| switch (lowering) {
53075277 .no_bits => continue,
53085278 .byval => {
53095279 const arg = args[it.zig_index - 1];
53105280 const param_ty = self.typeOf(arg);
53115281 const llvm_arg = try self.resolveInst(arg);
5312 const llvm_param_ty = try o.lowerType(param_ty);
5282 const llvm_param_ty = try o.lowerType(pt, param_ty);
53135283 if (isByRef(param_ty, zcu)) {
53145284 const alignment = param_ty.abiAlignment(zcu).toLlvm();
53155285 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");
......@@ -5338,7 +5308,7 @@ pub const FuncGen = struct {
53385308 const llvm_arg = try self.resolveInst(arg);
53395309
53405310 const alignment = param_ty.abiAlignment(zcu).toLlvm();
5341 const param_llvm_ty = try o.lowerType(param_ty);
5311 const param_llvm_ty = try o.lowerType(pt, param_ty);
53425312 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);
53435313 if (isByRef(param_ty, zcu)) {
53445314 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");
......@@ -5409,7 +5379,7 @@ pub const FuncGen = struct {
54095379 llvm_arg = ptr;
54105380 }
54115381
5412 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?);
5382 const float_ty = try o.lowerType(pt, aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?);
54135383 const array_ty = try o.builder.arrayType(count, float_ty);
54145384
54155385 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");
......@@ -5436,7 +5406,7 @@ pub const FuncGen = struct {
54365406
54375407 {
54385408 // Add argument attributes.
5439 it = iterateParamTypes(o, fn_info);
5409 it = iterateParamTypes(o, pt, fn_info);
54405410 it.llvm_index += @intFromBool(sret);
54415411 it.llvm_index += @intFromBool(err_return_tracing);
54425412 while (try it.next()) |lowering| switch (lowering) {
......@@ -5444,13 +5414,13 @@ pub const FuncGen = struct {
54445414 const param_index = it.zig_index - 1;
54455415 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
54465416 if (!isByRef(param_ty, zcu)) {
5447 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
5417 try o.addByValParamAttrs(pt, &attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
54485418 }
54495419 },
54505420 .byref => {
54515421 const param_index = it.zig_index - 1;
54525422 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
5453 const param_llvm_ty = try o.lowerType(param_ty);
5423 const param_llvm_ty = try o.lowerType(pt, param_ty);
54545424 const alignment = param_ty.abiAlignment(zcu).toLlvm();
54555425 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);
54565426 },
......@@ -5502,7 +5472,7 @@ pub const FuncGen = struct {
55025472 },
55035473 toLlvmCallConvTag(fn_info.cc, target).?,
55045474 try attributes.finish(&o.builder),
5505 try o.lowerType(zig_fn_ty),
5475 try o.lowerType(pt, zig_fn_ty),
55065476 llvm_fn,
55075477 llvm_args.items,
55085478 "",
......@@ -5516,7 +5486,7 @@ pub const FuncGen = struct {
55165486 return .none;
55175487 }
55185488
5519 const llvm_ret_ty = try o.lowerType(return_type);
5489 const llvm_ret_ty = try o.lowerType(pt, return_type);
55205490 if (ret_ptr) |rp| {
55215491 if (isByRef(return_type, zcu)) {
55225492 return rp;
......@@ -5527,7 +5497,7 @@ pub const FuncGen = struct {
55275497 }
55285498 }
55295499
5530 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
5500 const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info);
55315501
55325502 if (abi_ret_ty != llvm_ret_ty) {
55335503 // In this case the function return type is honoring the calling convention by having
......@@ -5556,11 +5526,12 @@ pub const FuncGen = struct {
55565526
55575527 fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) !void {
55585528 const o = fg.ng.object;
5559 const zcu = o.pt.zcu;
5529 const pt = fg.ng.pt;
5530 const zcu = pt.zcu;
55605531 const target = zcu.getTarget();
55615532 const panic_func = zcu.funcInfo(zcu.builtin_decl_values.get(panic_id.toBuiltin()));
55625533 const fn_info = zcu.typeToFunc(.fromInterned(panic_func.ty)).?;
5563 const panic_global = try o.resolveLlvmFunction(panic_func.owner_nav);
5534 const panic_global = try o.resolveLlvmFunction(pt, panic_func.owner_nav);
55645535
55655536 const has_err_trace = zcu.comp.config.any_error_tracing and fn_info.cc == .auto;
55665537 if (has_err_trace) assert(fg.err_ret_trace != .none);
......@@ -5579,7 +5550,7 @@ pub const FuncGen = struct {
55795550
55805551 fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !void {
55815552 const o = self.ng.object;
5582 const pt = o.pt;
5553 const pt = self.ng.pt;
55835554 const zcu = pt.zcu;
55845555 const ip = &zcu.intern_pool;
55855556 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
......@@ -5599,7 +5570,7 @@ pub const FuncGen = struct {
55995570 // https://github.com/ziglang/zig/issues/15337
56005571 break :undef;
56015572 }
5602 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu));
5573 const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), ret_ty.abiSize(zcu));
56035574 _ = try self.wip.callMemSet(
56045575 self.ret_ptr,
56055576 ptr_ty.ptrAlignment(zcu).toLlvm(),
......@@ -5635,14 +5606,14 @@ pub const FuncGen = struct {
56355606 // Functions with an empty error set are emitted with an error code
56365607 // return type and return zero so they can be function pointers coerced
56375608 // to functions that return anyerror.
5638 _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(), 0));
5609 _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(pt), 0));
56395610 } else {
56405611 _ = try self.wip.retVoid();
56415612 }
56425613 return;
56435614 }
56445615
5645 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
5616 const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info);
56465617 const operand = try self.resolveInst(un_op);
56475618 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false;
56485619 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
......@@ -5650,7 +5621,7 @@ pub const FuncGen = struct {
56505621 if (val_is_undef and safety) {
56515622 const llvm_ret_ty = operand.typeOfWip(&self.wip);
56525623 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));
5624 const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), ret_ty.abiSize(zcu));
56545625 _ = try self.wip.callMemSet(
56555626 rp,
56565627 alignment,
......@@ -5688,7 +5659,7 @@ pub const FuncGen = struct {
56885659
56895660 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !void {
56905661 const o = self.ng.object;
5691 const pt = o.pt;
5662 const pt = self.ng.pt;
56925663 const zcu = pt.zcu;
56935664 const ip = &zcu.intern_pool;
56945665 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
......@@ -5700,7 +5671,7 @@ pub const FuncGen = struct {
57005671 // Functions with an empty error set are emitted with an error code
57015672 // return type and return zero so they can be function pointers coerced
57025673 // to functions that return anyerror.
5703 _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(), 0));
5674 _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(pt), 0));
57045675 } else {
57055676 _ = try self.wip.retVoid();
57065677 }
......@@ -5711,7 +5682,7 @@ pub const FuncGen = struct {
57115682 return;
57125683 }
57135684 const ptr = try self.resolveInst(un_op);
5714 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
5685 const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info);
57155686 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
57165687 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, ""));
57175688 return;
......@@ -5719,22 +5690,23 @@ pub const FuncGen = struct {
57195690
57205691 fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57215692 const o = self.ng.object;
5693 const pt = self.ng.pt;
57225694 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
57235695 const list = try self.resolveInst(ty_op.operand);
57245696 const arg_ty = ty_op.ty.toType();
5725 const llvm_arg_ty = try o.lowerType(arg_ty);
5697 const llvm_arg_ty = try o.lowerType(pt, arg_ty);
57265698
57275699 return self.wip.vaArg(list, llvm_arg_ty, "");
57285700 }
57295701
57305702 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57315703 const o = self.ng.object;
5732 const pt = o.pt;
5704 const pt = self.ng.pt;
57335705 const zcu = pt.zcu;
57345706 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
57355707 const src_list = try self.resolveInst(ty_op.operand);
57365708 const va_list_ty = ty_op.ty.toType();
5737 const llvm_va_list_ty = try o.lowerType(va_list_ty);
5709 const llvm_va_list_ty = try o.lowerType(pt, va_list_ty);
57385710
57395711 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
57405712 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);
......@@ -5756,10 +5728,10 @@ pub const FuncGen = struct {
57565728
57575729 fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57585730 const o = self.ng.object;
5759 const pt = o.pt;
5731 const pt = self.ng.pt;
57605732 const zcu = pt.zcu;
57615733 const va_list_ty = self.typeOfIndex(inst);
5762 const llvm_va_list_ty = try o.lowerType(va_list_ty);
5734 const llvm_va_list_ty = try o.lowerType(pt, va_list_ty);
57635735
57645736 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
57655737 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);
......@@ -5799,9 +5771,10 @@ pub const FuncGen = struct {
57995771
58005772 fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
58015773 const o = self.ng.object;
5774 const pt = self.ng.pt;
58025775 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
58035776 const operand = try self.resolveInst(un_op);
5804 const llvm_fn = try o.getCmpLtErrorsLenFunction();
5777 const llvm_fn = try o.getCmpLtErrorsLenFunction(pt);
58055778 return self.wip.call(
58065779 .normal,
58075780 .fastcc,
......@@ -5822,7 +5795,7 @@ pub const FuncGen = struct {
58225795 rhs: Builder.Value,
58235796 ) Allocator.Error!Builder.Value {
58245797 const o = self.ng.object;
5825 const pt = o.pt;
5798 const pt = self.ng.pt;
58265799 const zcu = pt.zcu;
58275800 const ip = &zcu.intern_pool;
58285801 const scalar_ty = operand_ty.scalarType(zcu);
......@@ -5839,7 +5812,7 @@ pub const FuncGen = struct {
58395812 // We need to emit instructions to check for equality/inequality
58405813 // of optionals that are not pointers.
58415814 const is_by_ref = isByRef(scalar_ty, zcu);
5842 const opt_llvm_ty = try o.lowerType(scalar_ty);
5815 const opt_llvm_ty = try o.lowerType(pt, scalar_ty);
58435816 const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref, .normal);
58445817 const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref, .normal);
58455818 const llvm_i2 = try o.builder.intType(2);
......@@ -5936,7 +5909,7 @@ pub const FuncGen = struct {
59365909 body: []const Air.Inst.Index,
59375910 ) !Builder.Value {
59385911 const o = self.ng.object;
5939 const pt = o.pt;
5912 const pt = self.ng.pt;
59405913 const zcu = pt.zcu;
59415914 const inst_ty = self.typeOfIndex(inst);
59425915
......@@ -5963,7 +5936,7 @@ pub const FuncGen = struct {
59635936
59645937 // Create a phi node only if the block returns a value.
59655938 if (have_block_result) {
5966 const raw_llvm_ty = try o.lowerType(inst_ty);
5939 const raw_llvm_ty = try o.lowerType(pt, inst_ty);
59675940 const llvm_ty: Builder.Type = ty: {
59685941 // If the zig tag type is a function, this represents an actual function body; not
59695942 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead
......@@ -5986,8 +5959,7 @@ pub const FuncGen = struct {
59865959 }
59875960
59885961 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !void {
5989 const o = self.ng.object;
5990 const zcu = o.pt.zcu;
5962 const zcu = self.ng.pt.zcu;
59915963 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
59925964 const block = self.blocks.get(branch.block_inst).?;
59935965
......@@ -6017,7 +5989,7 @@ pub const FuncGen = struct {
60175989 dispatch_info: SwitchDispatchInfo,
60185990 ) !void {
60195991 const o = self.ng.object;
6020 const pt = o.pt;
5992 const pt = self.ng.pt;
60215993 const zcu = pt.zcu;
60225994 const cond_ty = self.typeOf(cond_ref);
60235995 const switch_br = self.air.unwrapSwitch(switch_inst);
......@@ -6081,7 +6053,7 @@ pub const FuncGen = struct {
60816053 const table_index = try self.wip.cast(
60826054 .zext,
60836055 try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""),
6084 try o.lowerType(Type.usize),
6056 try o.lowerType(pt, Type.usize),
60856057 "",
60866058 );
60876059 const target_ptr_ptr = try self.wip.gep(
......@@ -6108,7 +6080,7 @@ pub const FuncGen = struct {
61086080 // The switch prongs will correspond to our scalar cases. Ranges will
61096081 // be handled by conditional branches in the `else` prong.
61106082
6111 const llvm_usize = try o.lowerType(Type.usize);
6083 const llvm_usize = try o.lowerType(pt, Type.usize);
61126084 const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder))
61136085 try self.wip.cast(.ptrtoint, cond, llvm_usize, "")
61146086 else
......@@ -6268,8 +6240,7 @@ pub const FuncGen = struct {
62686240 }
62696241
62706242 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;
6243 const pt = self.ng.pt;
62736244 const zcu = pt.zcu;
62746245 const inst = body_tail[0];
62756246 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
......@@ -6284,8 +6255,7 @@ pub const FuncGen = struct {
62846255 }
62856256
62866257 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;
6258 const zcu = self.ng.pt.zcu;
62896259 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
62906260 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
62916261 const err_union_ptr = try self.resolveInst(extra.data.ptr);
......@@ -6309,12 +6279,12 @@ pub const FuncGen = struct {
63096279 err_cold: bool,
63106280 ) !Builder.Value {
63116281 const o = fg.ng.object;
6312 const pt = o.pt;
6282 const pt = fg.ng.pt;
63136283 const zcu = pt.zcu;
63146284 const payload_ty = err_union_ty.errorUnionPayload(zcu);
63156285 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();
6286 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
6287 const error_type = try o.errorIntType(pt);
63186288
63196289 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
63206290 const loaded = loaded: {
......@@ -6378,7 +6348,8 @@ pub const FuncGen = struct {
63786348
63796349 fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) !void {
63806350 const o = self.ng.object;
6381 const zcu = o.pt.zcu;
6351 const pt = self.ng.pt;
6352 const zcu = pt.zcu;
63826353
63836354 const switch_br = self.air.unwrapSwitch(inst);
63846355
......@@ -6483,8 +6454,8 @@ pub const FuncGen = struct {
64836454 const table_includes_else = item_count != table_len;
64846455
64856456 break :jmp_table .{
6486 .min = try o.lowerValue(min.toIntern()),
6487 .max = try o.lowerValue(max.toIntern()),
6457 .min = try o.lowerValue(pt, min.toIntern()),
6458 .max = try o.lowerValue(pt, max.toIntern()),
64886459 .in_bounds_hint = if (table_includes_else) .none else switch (switch_br.getElseHint()) {
64896460 .none, .cold => .none,
64906461 .unpredictable => .unpredictable,
......@@ -6591,7 +6562,7 @@ pub const FuncGen = struct {
65916562 }
65926563
65936564 fn switchCaseItemRange(self: *FuncGen, switch_br: Air.UnwrappedSwitch) [2]Value {
6594 const zcu = self.ng.object.pt.zcu;
6565 const zcu = self.ng.pt.zcu;
65956566 var it = switch_br.iterateCases();
65966567 var min: ?Value = null;
65976568 var max: ?Value = null;
......@@ -6633,18 +6604,18 @@ pub const FuncGen = struct {
66336604
66346605 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
66356606 const o = self.ng.object;
6636 const pt = o.pt;
6607 const pt = self.ng.pt;
66376608 const zcu = pt.zcu;
66386609 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
66396610 const operand_ty = self.typeOf(ty_op.operand);
66406611 const array_ty = operand_ty.childType(zcu);
6641 const llvm_usize = try o.lowerType(Type.usize);
6612 const llvm_usize = try o.lowerType(pt, Type.usize);
66426613 const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu));
6643 const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
6614 const slice_llvm_ty = try o.lowerType(pt, self.typeOfIndex(inst));
66446615 const operand = try self.resolveInst(ty_op.operand);
66456616 if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu))
66466617 return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, "");
6647 const ptr = try self.wip.gep(.inbounds, try o.lowerType(array_ty), operand, &.{
6618 const ptr = try self.wip.gep(.inbounds, try o.lowerType(pt, array_ty), operand, &.{
66486619 try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0),
66496620 }, "");
66506621 return self.wip.buildAggregate(slice_llvm_ty, &.{ ptr, len }, "");
......@@ -6652,7 +6623,7 @@ pub const FuncGen = struct {
66526623
66536624 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
66546625 const o = self.ng.object;
6655 const pt = o.pt;
6626 const pt = self.ng.pt;
66566627 const zcu = pt.zcu;
66576628 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
66586629
......@@ -6663,7 +6634,7 @@ pub const FuncGen = struct {
66636634
66646635 const dest_ty = self.typeOfIndex(inst);
66656636 const dest_scalar_ty = dest_ty.scalarType(zcu);
6666 const dest_llvm_ty = try o.lowerType(dest_ty);
6637 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
66676638 const target = zcu.getTarget();
66686639
66696640 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(
......@@ -6719,7 +6690,7 @@ pub const FuncGen = struct {
67196690 _ = fast;
67206691
67216692 const o = self.ng.object;
6722 const pt = o.pt;
6693 const pt = self.ng.pt;
67236694 const zcu = pt.zcu;
67246695 const target = zcu.getTarget();
67256696 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -6730,7 +6701,7 @@ pub const FuncGen = struct {
67306701
67316702 const dest_ty = self.typeOfIndex(inst);
67326703 const dest_scalar_ty = dest_ty.scalarType(zcu);
6733 const dest_llvm_ty = try o.lowerType(dest_ty);
6704 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
67346705
67356706 if (intrinsicsAllowed(operand_scalar_ty, target)) {
67366707 // TODO set fast math flag
......@@ -6762,7 +6733,7 @@ pub const FuncGen = struct {
67626733 compiler_rt_dest_abbrev,
67636734 });
67646735
6765 const operand_llvm_ty = try o.lowerType(operand_ty);
6736 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
67666737 const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty);
67676738 var result = try self.wip.call(
67686739 .normal,
......@@ -6780,16 +6751,15 @@ pub const FuncGen = struct {
67806751 }
67816752
67826753 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;
6754 const zcu = fg.ng.pt.zcu;
67856755 return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;
67866756 }
67876757
67886758 fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
67896759 const o = fg.ng.object;
6790 const pt = o.pt;
6760 const pt = fg.ng.pt;
67916761 const zcu = pt.zcu;
6792 const llvm_usize = try o.lowerType(Type.usize);
6762 const llvm_usize = try o.lowerType(pt, Type.usize);
67936763 switch (ty.ptrSize(zcu)) {
67946764 .slice => {
67956765 const len = try fg.wip.extractValue(ptr, &.{1}, "");
......@@ -6817,18 +6787,19 @@ pub const FuncGen = struct {
68176787
68186788 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {
68196789 const o = self.ng.object;
6820 const zcu = o.pt.zcu;
6790 const pt = self.ng.pt;
6791 const zcu = pt.zcu;
68216792 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
68226793 const slice_ptr = try self.resolveInst(ty_op.operand);
68236794 const slice_ptr_ty = self.typeOf(ty_op.operand);
6824 const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(zcu));
6795 const slice_llvm_ty = try o.lowerPtrElemTy(pt, slice_ptr_ty.childType(zcu));
68256796
68266797 return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, "");
68276798 }
68286799
68296800 fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
68306801 const o = self.ng.object;
6831 const pt = o.pt;
6802 const pt = self.ng.pt;
68326803 const zcu = pt.zcu;
68336804 const inst = body_tail[0];
68346805 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
......@@ -6836,7 +6807,7 @@ pub const FuncGen = struct {
68366807 const slice = try self.resolveInst(bin_op.lhs);
68376808 const index = try self.resolveInst(bin_op.rhs);
68386809 const elem_ty = slice_ty.childType(zcu);
6839 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6810 const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty);
68406811 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
68416812 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
68426813 if (isByRef(elem_ty, zcu)) {
......@@ -6856,21 +6827,22 @@ pub const FuncGen = struct {
68566827
68576828 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
68586829 const o = self.ng.object;
6859 const zcu = o.pt.zcu;
6830 const pt = self.ng.pt;
6831 const zcu = pt.zcu;
68606832 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
68616833 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
68626834 const slice_ty = self.typeOf(bin_op.lhs);
68636835
68646836 const slice = try self.resolveInst(bin_op.lhs);
68656837 const index = try self.resolveInst(bin_op.rhs);
6866 const llvm_elem_ty = try o.lowerPtrElemTy(slice_ty.childType(zcu));
6838 const llvm_elem_ty = try o.lowerPtrElemTy(pt, slice_ty.childType(zcu));
68676839 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
68686840 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
68696841 }
68706842
68716843 fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
68726844 const o = self.ng.object;
6873 const pt = o.pt;
6845 const pt = self.ng.pt;
68746846 const zcu = pt.zcu;
68756847 const inst = body_tail[0];
68766848
......@@ -6878,11 +6850,11 @@ pub const FuncGen = struct {
68786850 const array_ty = self.typeOf(bin_op.lhs);
68796851 const array_llvm_val = try self.resolveInst(bin_op.lhs);
68806852 const rhs = try self.resolveInst(bin_op.rhs);
6881 const array_llvm_ty = try o.lowerType(array_ty);
6853 const array_llvm_ty = try o.lowerType(pt, array_ty);
68826854 const elem_ty = array_ty.childType(zcu);
68836855 if (isByRef(array_ty, zcu)) {
68846856 const indices: [2]Builder.Value = .{
6885 try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs,
6857 try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs,
68866858 };
68876859 if (isByRef(elem_ty, zcu)) {
68886860 const elem_ptr =
......@@ -6903,19 +6875,19 @@ pub const FuncGen = struct {
69036875
69046876 fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
69056877 const o = self.ng.object;
6906 const pt = o.pt;
6878 const pt = self.ng.pt;
69076879 const zcu = pt.zcu;
69086880 const inst = body_tail[0];
69096881 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
69106882 const ptr_ty = self.typeOf(bin_op.lhs);
69116883 const elem_ty = ptr_ty.childType(zcu);
6912 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6884 const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty);
69136885 const base_ptr = try self.resolveInst(bin_op.lhs);
69146886 const rhs = try self.resolveInst(bin_op.rhs);
69156887 // TODO: when we go fully opaque pointers in LLVM 16 we can remove this branch
69166888 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
69176889 // 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 }
6890 &.{ try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs }
69196891 else
69206892 &.{rhs}, "");
69216893 if (isByRef(elem_ty, zcu)) {
......@@ -6934,7 +6906,7 @@ pub const FuncGen = struct {
69346906
69356907 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
69366908 const o = self.ng.object;
6937 const pt = o.pt;
6909 const pt = self.ng.pt;
69386910 const zcu = pt.zcu;
69396911 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
69406912 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
......@@ -6948,10 +6920,10 @@ pub const FuncGen = struct {
69486920 const elem_ptr = ty_pl.ty.toType();
69496921 if (elem_ptr.ptrInfo(zcu).flags.vector_index != .none) return base_ptr;
69506922
6951 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6923 const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty);
69526924 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
69536925 // 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 }
6926 &.{ try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs }
69556927 else
69566928 &.{rhs}, "");
69576929 }
......@@ -6977,7 +6949,7 @@ pub const FuncGen = struct {
69776949
69786950 fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
69796951 const o = self.ng.object;
6980 const pt = o.pt;
6952 const pt = self.ng.pt;
69816953 const zcu = pt.zcu;
69826954 const inst = body_tail[0];
69836955 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
......@@ -6999,7 +6971,7 @@ pub const FuncGen = struct {
69996971 const shift_amt =
70006972 try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset);
70016973 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
7002 const elem_llvm_ty = try o.lowerType(field_ty);
6974 const elem_llvm_ty = try o.lowerType(pt, field_ty);
70036975 if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) {
70046976 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
70056977 const truncated_int =
......@@ -7021,7 +6993,7 @@ pub const FuncGen = struct {
70216993 .@"union" => {
70226994 assert(struct_ty.containerLayout(zcu) == .@"packed");
70236995 const containing_int = struct_llvm_val;
7024 const elem_llvm_ty = try o.lowerType(field_ty);
6996 const elem_llvm_ty = try o.lowerType(pt, field_ty);
70256997 if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) {
70266998 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
70276999 const truncated_int =
......@@ -7043,7 +7015,7 @@ pub const FuncGen = struct {
70437015 .@"struct" => {
70447016 const layout = struct_ty.containerLayout(zcu);
70457017 assert(layout != .@"packed");
7046 const struct_llvm_ty = try o.lowerType(struct_ty);
7018 const struct_llvm_ty = try o.lowerType(pt, struct_ty);
70477019 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;
70487020 const field_ptr =
70497021 try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, "");
......@@ -7064,7 +7036,7 @@ pub const FuncGen = struct {
70647036 }
70657037 },
70667038 .@"union" => {
7067 const union_llvm_ty = try o.lowerType(struct_ty);
7039 const union_llvm_ty = try o.lowerType(pt, struct_ty);
70687040 const layout = struct_ty.unionGetLayout(zcu);
70697041 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
70707042 const field_ptr =
......@@ -7083,7 +7055,7 @@ pub const FuncGen = struct {
70837055
70847056 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
70857057 const o = self.ng.object;
7086 const pt = o.pt;
7058 const pt = self.ng.pt;
70877059 const zcu = pt.zcu;
70887060 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
70897061 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
......@@ -7094,8 +7066,8 @@ pub const FuncGen = struct {
70947066 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
70957067 if (field_offset == 0) return field_ptr;
70967068
7097 const res_ty = try o.lowerType(ty_pl.ty.toType());
7098 const llvm_usize = try o.lowerType(Type.usize);
7069 const res_ty = try o.lowerType(pt, ty_pl.ty.toType());
7070 const llvm_usize = try o.lowerType(pt, Type.usize);
70997071
71007072 const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, "");
71017073 const base_ptr_int = try self.wip.bin(
......@@ -7151,7 +7123,8 @@ pub const FuncGen = struct {
71517123
71527124 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
71537125 const o = self.ng.object;
7154 const zcu = o.pt.zcu;
7126 const pt = self.ng.pt;
7127 const zcu = pt.zcu;
71557128 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
71567129 const operand = try self.resolveInst(pl_op.operand);
71577130 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
......@@ -7162,7 +7135,7 @@ pub const FuncGen = struct {
71627135 self.file,
71637136 self.scope,
71647137 self.prev_dbg_line,
7165 try o.lowerDebugType(ptr_ty.childType(zcu)),
7138 try o.lowerDebugType(pt, ptr_ty.childType(zcu)),
71667139 );
71677140
71687141 _ = try self.wip.callIntrinsic(
......@@ -7183,6 +7156,7 @@ pub const FuncGen = struct {
71837156
71847157 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index, is_arg: bool) !Builder.Value {
71857158 const o = self.ng.object;
7159 const pt = self.ng.pt;
71867160 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
71877161 const operand = try self.resolveInst(pl_op.operand);
71887162 const operand_ty = self.typeOf(pl_op.operand);
......@@ -7193,7 +7167,7 @@ pub const FuncGen = struct {
71937167 self.file,
71947168 self.scope,
71957169 self.prev_dbg_line,
7196 try o.lowerDebugType(operand_ty),
7170 try o.lowerDebugType(pt, operand_ty),
71977171 arg_no: {
71987172 self.arg_inline_index += 1;
71997173 break :arg_no self.arg_inline_index;
......@@ -7203,10 +7177,10 @@ pub const FuncGen = struct {
72037177 self.file,
72047178 self.scope,
72057179 self.prev_dbg_line,
7206 try o.lowerDebugType(operand_ty),
7180 try o.lowerDebugType(pt, operand_ty),
72077181 );
72087182
7209 const zcu = o.pt.zcu;
7183 const zcu = pt.zcu;
72107184 const owner_mod = self.ng.ownerModule();
72117185 if (isByRef(operand_ty, zcu)) {
72127186 _ = try self.wip.callIntrinsic(
......@@ -7296,7 +7270,7 @@ pub const FuncGen = struct {
72967270 // This stores whether we need to add an elementtype attribute and
72977271 // if so, the element type itself.
72987272 const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count);
7299 const pt = o.pt;
7273 const pt = self.ng.pt;
73007274 const zcu = pt.zcu;
73017275 const target = zcu.getTarget();
73027276
......@@ -7326,7 +7300,7 @@ pub const FuncGen = struct {
73267300 const output_inst = try self.resolveInst(output);
73277301 const output_ty = self.typeOf(output);
73287302 assert(output_ty.zigTypeTag(zcu) == .pointer);
7329 const elem_llvm_ty = try o.lowerPtrElemTy(output_ty.childType(zcu));
7303 const elem_llvm_ty = try o.lowerPtrElemTy(pt, output_ty.childType(zcu));
73307304
73317305 switch (constraint[0]) {
73327306 '=' => {},
......@@ -7364,7 +7338,7 @@ pub const FuncGen = struct {
73647338 is_indirect.* = false;
73657339
73667340 const ret_ty = self.typeOfIndex(inst);
7367 llvm_ret_types[llvm_ret_i] = try o.lowerType(ret_ty);
7341 llvm_ret_types[llvm_ret_i] = try o.lowerType(pt, ret_ty);
73687342 llvm_ret_i += 1;
73697343 }
73707344
......@@ -7406,7 +7380,7 @@ pub const FuncGen = struct {
74067380 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
74077381 } else {
74087382 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
7409 const arg_llvm_ty = try o.lowerType(arg_ty);
7383 const arg_llvm_ty = try o.lowerType(pt, arg_ty);
74107384 const load_inst =
74117385 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");
74127386 llvm_param_values[llvm_param_i] = load_inst;
......@@ -7447,7 +7421,7 @@ pub const FuncGen = struct {
74477421 llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: {
74487422 if (!is_by_ref) self.maybeMarkAllowZeroAccess(arg_ty.ptrInfo(zcu));
74497423
7450 break :blk try o.lowerPtrElemTy(if (is_by_ref) arg_ty else arg_ty.childType(zcu));
7424 break :blk try o.lowerPtrElemTy(pt, if (is_by_ref) arg_ty else arg_ty.childType(zcu));
74517425 } else .none;
74527426
74537427 llvm_param_i += 1;
......@@ -7465,7 +7439,7 @@ pub const FuncGen = struct {
74657439 if (constraint[0] != '+') continue;
74667440
74677441 const rw_ty = self.typeOf(output);
7468 const llvm_elem_ty = try o.lowerPtrElemTy(rw_ty.childType(zcu));
7442 const llvm_elem_ty = try o.lowerPtrElemTy(pt, rw_ty.childType(zcu));
74697443 if (is_indirect) {
74707444 llvm_param_values[llvm_param_i] = llvm_rw_val;
74717445 llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip);
......@@ -7663,13 +7637,13 @@ pub const FuncGen = struct {
76637637 cond: Builder.IntegerCondition,
76647638 ) !Builder.Value {
76657639 const o = self.ng.object;
7666 const pt = o.pt;
7640 const pt = self.ng.pt;
76677641 const zcu = pt.zcu;
76687642 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
76697643 const operand = try self.resolveInst(un_op);
76707644 const operand_ty = self.typeOf(un_op);
76717645 const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7672 const optional_llvm_ty = try o.lowerType(optional_ty);
7646 const optional_llvm_ty = try o.lowerType(pt, optional_ty);
76737647 const payload_ty = optional_ty.optionalChild(zcu);
76747648
76757649 const access_kind: Builder.MemoryAccessKind =
......@@ -7714,14 +7688,14 @@ pub const FuncGen = struct {
77147688 operand_is_ptr: bool,
77157689 ) !Builder.Value {
77167690 const o = self.ng.object;
7717 const pt = o.pt;
7691 const pt = self.ng.pt;
77187692 const zcu = pt.zcu;
77197693 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
77207694 const operand = try self.resolveInst(un_op);
77217695 const operand_ty = self.typeOf(un_op);
77227696 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
77237697 const payload_ty = err_union_ty.errorUnionPayload(zcu);
7724 const error_type = try o.errorIntType();
7698 const error_type = try o.errorIntType(pt);
77257699 const zero = try o.builder.intValue(error_type, 0);
77267700
77277701 const access_kind: Builder.MemoryAccessKind =
......@@ -7740,7 +7714,7 @@ pub const FuncGen = struct {
77407714
77417715 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
77427716 const loaded = if (operand_is_ptr)
7743 try self.wip.load(access_kind, try o.lowerType(err_union_ty), operand, .default, "")
7717 try self.wip.load(access_kind, try o.lowerType(pt, err_union_ty), operand, .default, "")
77447718 else
77457719 operand;
77467720 return self.wip.icmp(cond, loaded, zero, "");
......@@ -7749,7 +7723,7 @@ pub const FuncGen = struct {
77497723 const err_field_index = try errUnionErrorOffset(payload_ty, pt);
77507724
77517725 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);
7726 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
77537727 const err_field_ptr =
77547728 try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, "");
77557729 break :loaded try self.wip.load(access_kind, error_type, err_field_ptr, .default, "");
......@@ -7759,7 +7733,7 @@ pub const FuncGen = struct {
77597733
77607734 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
77617735 const o = self.ng.object;
7762 const pt = o.pt;
7736 const pt = self.ng.pt;
77637737 const zcu = pt.zcu;
77647738 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
77657739 const operand = try self.resolveInst(ty_op.operand);
......@@ -7774,14 +7748,14 @@ pub const FuncGen = struct {
77747748 // The payload and the optional are the same value.
77757749 return operand;
77767750 }
7777 return self.wip.gepStruct(try o.lowerType(optional_ty), operand, 0, "");
7751 return self.wip.gepStruct(try o.lowerType(pt, optional_ty), operand, 0, "");
77787752 }
77797753
77807754 fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
77817755 comptime assert(optional_layout_version == 3);
77827756
77837757 const o = self.ng.object;
7784 const pt = o.pt;
7758 const pt = self.ng.pt;
77857759 const zcu = pt.zcu;
77867760 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
77877761 const operand = try self.resolveInst(ty_op.operand);
......@@ -7807,7 +7781,7 @@ pub const FuncGen = struct {
78077781 }
78087782
78097783 // First set the non-null bit.
7810 const optional_llvm_ty = try o.lowerType(optional_ty);
7784 const optional_llvm_ty = try o.lowerType(pt, optional_ty);
78117785 const non_null_ptr = try self.wip.gepStruct(optional_llvm_ty, operand, 1, "");
78127786
78137787 self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu));
......@@ -7823,7 +7797,7 @@ pub const FuncGen = struct {
78237797
78247798 fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
78257799 const o = self.ng.object;
7826 const pt = o.pt;
7800 const pt = self.ng.pt;
78277801 const zcu = pt.zcu;
78287802 const inst = body_tail[0];
78297803 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -7837,7 +7811,7 @@ pub const FuncGen = struct {
78377811 return operand;
78387812 }
78397813
7840 const opt_llvm_ty = try o.lowerType(optional_ty);
7814 const opt_llvm_ty = try o.lowerType(pt, optional_ty);
78417815 const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false;
78427816 return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load);
78437817 }
......@@ -7848,7 +7822,7 @@ pub const FuncGen = struct {
78487822 operand_is_ptr: bool,
78497823 ) !Builder.Value {
78507824 const o = self.ng.object;
7851 const pt = o.pt;
7825 const pt = self.ng.pt;
78527826 const zcu = pt.zcu;
78537827 const inst = body_tail[0];
78547828 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -7862,7 +7836,7 @@ pub const FuncGen = struct {
78627836 return if (operand_is_ptr) operand else .none;
78637837 }
78647838 const offset = try errUnionPayloadOffset(payload_ty, pt);
7865 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7839 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
78667840 if (operand_is_ptr) {
78677841 return self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
78687842 } else if (isByRef(err_union_ty, zcu)) {
......@@ -7884,12 +7858,12 @@ pub const FuncGen = struct {
78847858 operand_is_ptr: bool,
78857859 ) !Builder.Value {
78867860 const o = self.ng.object;
7887 const pt = o.pt;
7861 const pt = self.ng.pt;
78887862 const zcu = pt.zcu;
78897863 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
78907864 const operand = try self.resolveInst(ty_op.operand);
78917865 const operand_ty = self.typeOf(ty_op.operand);
7892 const error_type = try o.errorIntType();
7866 const error_type = try o.errorIntType(pt);
78937867 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
78947868 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
78957869 if (operand_is_ptr) {
......@@ -7916,7 +7890,7 @@ pub const FuncGen = struct {
79167890 if (operand_is_ptr or isByRef(err_union_ty, zcu)) {
79177891 if (operand_is_ptr) self.maybeMarkAllowZeroAccess(operand_ty.ptrInfo(zcu));
79187892
7919 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7893 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
79207894 const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
79217895 return self.wip.load(access_kind, error_type, err_field_ptr, .default, "");
79227896 }
......@@ -7926,7 +7900,7 @@ pub const FuncGen = struct {
79267900
79277901 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
79287902 const o = self.ng.object;
7929 const pt = o.pt;
7903 const pt = self.ng.pt;
79307904 const zcu = pt.zcu;
79317905 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
79327906 const operand = try self.resolveInst(ty_op.operand);
......@@ -7934,7 +7908,7 @@ pub const FuncGen = struct {
79347908 const err_union_ty = err_union_ptr_ty.childType(zcu);
79357909
79367910 const payload_ty = err_union_ty.errorUnionPayload(zcu);
7937 const non_error_val = try o.builder.intValue(try o.errorIntType(), 0);
7911 const non_error_val = try o.builder.intValue(try o.errorIntType(pt), 0);
79387912
79397913 const access_kind: Builder.MemoryAccessKind =
79407914 if (err_union_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
......@@ -7945,7 +7919,7 @@ pub const FuncGen = struct {
79457919 _ = try self.wip.store(access_kind, non_error_val, operand, .default);
79467920 return operand;
79477921 }
7948 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7922 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
79497923 {
79507924 self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu));
79517925
......@@ -7976,14 +7950,14 @@ pub const FuncGen = struct {
79767950
79777951 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
79787952 const o = self.ng.object;
7979 const pt = o.pt;
7953 const pt = self.ng.pt;
79807954 const zcu = pt.zcu;
79817955
79827956 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
79837957 const struct_ty = ty_pl.ty.toType();
79847958 const field_index = ty_pl.payload;
79857959
7986 const struct_llvm_ty = try o.lowerType(struct_ty);
7960 const struct_llvm_ty = try o.lowerType(pt, struct_ty);
79877961 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;
79887962 assert(self.err_ret_trace != .none);
79897963 const field_ptr =
......@@ -8022,7 +7996,7 @@ pub const FuncGen = struct {
80227996
80237997 fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
80247998 const o = self.ng.object;
8025 const pt = o.pt;
7999 const pt = self.ng.pt;
80268000 const zcu = pt.zcu;
80278001 const inst = body_tail[0];
80288002 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -8033,7 +8007,7 @@ pub const FuncGen = struct {
80338007 const operand = try self.resolveInst(ty_op.operand);
80348008 const optional_ty = self.typeOfIndex(inst);
80358009 if (optional_ty.optionalReprIsPayload(zcu)) return operand;
8036 const llvm_optional_ty = try o.lowerType(optional_ty);
8010 const llvm_optional_ty = try o.lowerType(pt, optional_ty);
80378011 if (isByRef(optional_ty, zcu)) {
80388012 const directReturn = self.isNextRet(body_tail);
80398013 const optional_ptr = if (directReturn)
......@@ -8056,7 +8030,7 @@ pub const FuncGen = struct {
80568030
80578031 fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
80588032 const o = self.ng.object;
8059 const pt = o.pt;
8033 const pt = self.ng.pt;
80608034 const zcu = pt.zcu;
80618035 const inst = body_tail[0];
80628036 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -8066,8 +8040,8 @@ pub const FuncGen = struct {
80668040 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
80678041 return operand;
80688042 }
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);
8043 const ok_err_code = try o.builder.intValue(try o.errorIntType(pt), 0);
8044 const err_un_llvm_ty = try o.lowerType(pt, err_un_ty);
80718045
80728046 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
80738047 const error_offset = try errUnionErrorOffset(payload_ty, pt);
......@@ -8098,7 +8072,7 @@ pub const FuncGen = struct {
80988072
80998073 fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
81008074 const o = self.ng.object;
8101 const pt = o.pt;
8075 const pt = self.ng.pt;
81028076 const zcu = pt.zcu;
81038077 const inst = body_tail[0];
81048078 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -8106,7 +8080,7 @@ pub const FuncGen = struct {
81068080 const payload_ty = err_un_ty.errorUnionPayload(zcu);
81078081 const operand = try self.resolveInst(ty_op.operand);
81088082 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return operand;
8109 const err_un_llvm_ty = try o.lowerType(err_un_ty);
8083 const err_un_llvm_ty = try o.lowerType(pt, err_un_ty);
81108084
81118085 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
81128086 const error_offset = try errUnionErrorOffset(payload_ty, pt);
......@@ -8139,9 +8113,10 @@ pub const FuncGen = struct {
81398113
81408114 fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81418115 const o = self.ng.object;
8116 const pt = self.ng.pt;
81428117 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
81438118 const index = pl_op.payload;
8144 const llvm_usize = try o.lowerType(Type.usize);
8119 const llvm_usize = try o.lowerType(pt, Type.usize);
81458120 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{
81468121 try o.builder.intValue(.i32, index),
81478122 }, "");
......@@ -8149,9 +8124,10 @@ pub const FuncGen = struct {
81498124
81508125 fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81518126 const o = self.ng.object;
8127 const pt = self.ng.pt;
81528128 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
81538129 const index = pl_op.payload;
8154 const llvm_isize = try o.lowerType(Type.isize);
8130 const llvm_isize = try o.lowerType(pt, Type.isize);
81558131 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{
81568132 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
81578133 }, "");
......@@ -8159,7 +8135,7 @@ pub const FuncGen = struct {
81598135
81608136 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81618137 const o = self.ng.object;
8162 const pt = o.pt;
8138 const pt = self.ng.pt;
81638139 const zcu = pt.zcu;
81648140 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
81658141 const extra = self.air.extraData(Air.Bin, data.payload).data;
......@@ -8175,7 +8151,7 @@ pub const FuncGen = struct {
81758151 // https://github.com/ziglang/zig/issues/18652#issuecomment-2452844908
81768152 const access_kind: Builder.MemoryAccessKind =
81778153 if (vector_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
8178 const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(zcu));
8154 const elem_llvm_ty = try o.lowerType(pt, vector_ptr_ty.childType(zcu));
81798155 const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm();
81808156 const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, "");
81818157
......@@ -8186,14 +8162,16 @@ pub const FuncGen = struct {
81868162
81878163 fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81888164 const o = fg.ng.object;
8165 const pt = fg.ng.pt;
81898166 const ty_nav = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav;
8190 const llvm_ptr_const = try o.lowerNavRefValue(ty_nav.nav);
8167 const llvm_ptr_const = try o.lowerNavRefValue(pt, ty_nav.nav);
81918168 return llvm_ptr_const.toValue();
81928169 }
81938170
81948171 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
81958172 const o = self.ng.object;
8196 const zcu = o.pt.zcu;
8173 const pt = self.ng.pt;
8174 const zcu = pt.zcu;
81978175 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
81988176 const lhs = try self.resolveInst(bin_op.lhs);
81998177 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8205,7 +8183,7 @@ pub const FuncGen = struct {
82058183 .normal,
82068184 .none,
82078185 if (scalar_ty.isSignedInt(zcu)) .smin else .umin,
8208 &.{try o.lowerType(inst_ty)},
8186 &.{try o.lowerType(pt, inst_ty)},
82098187 &.{ lhs, rhs },
82108188 "",
82118189 );
......@@ -8213,7 +8191,8 @@ pub const FuncGen = struct {
82138191
82148192 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
82158193 const o = self.ng.object;
8216 const zcu = o.pt.zcu;
8194 const pt = self.ng.pt;
8195 const zcu = pt.zcu;
82178196 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
82188197 const lhs = try self.resolveInst(bin_op.lhs);
82198198 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8225,7 +8204,7 @@ pub const FuncGen = struct {
82258204 .normal,
82268205 .none,
82278206 if (scalar_ty.isSignedInt(zcu)) .smax else .umax,
8228 &.{try o.lowerType(inst_ty)},
8207 &.{try o.lowerType(pt, inst_ty)},
82298208 &.{ lhs, rhs },
82308209 "",
82318210 );
......@@ -8233,17 +8212,17 @@ pub const FuncGen = struct {
82338212
82348213 fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
82358214 const o = self.ng.object;
8215 const pt = self.ng.pt;
82368216 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
82378217 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
82388218 const ptr = try self.resolveInst(bin_op.lhs);
82398219 const len = try self.resolveInst(bin_op.rhs);
82408220 const inst_ty = self.typeOfIndex(inst);
8241 return self.wip.buildAggregate(try o.lowerType(inst_ty), &.{ ptr, len }, "");
8221 return self.wip.buildAggregate(try o.lowerType(pt, inst_ty), &.{ ptr, len }, "");
82428222 }
82438223
82448224 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;
8225 const zcu = self.ng.pt.zcu;
82478226 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
82488227 const lhs = try self.resolveInst(bin_op.lhs);
82498228 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8261,7 +8240,8 @@ pub const FuncGen = struct {
82618240 unsigned_intrinsic: Builder.Intrinsic,
82628241 ) !Builder.Value {
82638242 const o = fg.ng.object;
8264 const zcu = o.pt.zcu;
8243 const pt = fg.ng.pt;
8244 const zcu = pt.zcu;
82658245
82668246 const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
82678247 const lhs = try fg.resolveInst(bin_op.lhs);
......@@ -8270,7 +8250,7 @@ pub const FuncGen = struct {
82708250 const scalar_ty = inst_ty.scalarType(zcu);
82718251
82728252 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
8273 const llvm_inst_ty = try o.lowerType(inst_ty);
8253 const llvm_inst_ty = try o.lowerType(pt, inst_ty);
82748254 const results =
82758255 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");
82768256
......@@ -8309,7 +8289,8 @@ pub const FuncGen = struct {
83098289
83108290 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
83118291 const o = self.ng.object;
8312 const zcu = o.pt.zcu;
8292 const pt = self.ng.pt;
8293 const zcu = pt.zcu;
83138294 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83148295 const lhs = try self.resolveInst(bin_op.lhs);
83158296 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8321,15 +8302,14 @@ pub const FuncGen = struct {
83218302 .normal,
83228303 .none,
83238304 if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat",
8324 &.{try o.lowerType(inst_ty)},
8305 &.{try o.lowerType(pt, inst_ty)},
83258306 &.{ lhs, rhs },
83268307 "",
83278308 );
83288309 }
83298310
83308311 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;
8312 const zcu = self.ng.pt.zcu;
83338313 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83348314 const lhs = try self.resolveInst(bin_op.lhs);
83358315 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8350,7 +8330,8 @@ pub const FuncGen = struct {
83508330
83518331 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
83528332 const o = self.ng.object;
8353 const zcu = o.pt.zcu;
8333 const pt = self.ng.pt;
8334 const zcu = pt.zcu;
83548335 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83558336 const lhs = try self.resolveInst(bin_op.lhs);
83568337 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8362,15 +8343,14 @@ pub const FuncGen = struct {
83628343 .normal,
83638344 .none,
83648345 if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat",
8365 &.{try o.lowerType(inst_ty)},
8346 &.{try o.lowerType(pt, inst_ty)},
83668347 &.{ lhs, rhs },
83678348 "",
83688349 );
83698350 }
83708351
83718352 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;
8353 const zcu = self.ng.pt.zcu;
83748354 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83758355 const lhs = try self.resolveInst(bin_op.lhs);
83768356 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8391,7 +8371,8 @@ pub const FuncGen = struct {
83918371
83928372 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
83938373 const o = self.ng.object;
8394 const zcu = o.pt.zcu;
8374 const pt = self.ng.pt;
8375 const zcu = pt.zcu;
83958376 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
83968377 const lhs = try self.resolveInst(bin_op.lhs);
83978378 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8403,7 +8384,7 @@ pub const FuncGen = struct {
84038384 .normal,
84048385 .none,
84058386 if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat",
8406 &.{try o.lowerType(inst_ty)},
8387 &.{try o.lowerType(pt, inst_ty)},
84078388 &.{ lhs, rhs, .@"0" },
84088389 "",
84098390 );
......@@ -8419,8 +8400,7 @@ pub const FuncGen = struct {
84198400 }
84208401
84218402 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;
8403 const zcu = self.ng.pt.zcu;
84248404 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84258405 const lhs = try self.resolveInst(bin_op.lhs);
84268406 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8436,7 +8416,8 @@ pub const FuncGen = struct {
84368416
84378417 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
84388418 const o = self.ng.object;
8439 const zcu = o.pt.zcu;
8419 const pt = self.ng.pt;
8420 const zcu = pt.zcu;
84408421 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84418422 const lhs = try self.resolveInst(bin_op.lhs);
84428423 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8448,7 +8429,7 @@ pub const FuncGen = struct {
84488429 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});
84498430 }
84508431 if (scalar_ty.isSignedInt(zcu)) {
8451 const inst_llvm_ty = try o.lowerType(inst_ty);
8432 const inst_llvm_ty = try o.lowerType(pt, inst_ty);
84528433
84538434 const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb;
84548435 var stack align(@max(
......@@ -8485,8 +8466,7 @@ pub const FuncGen = struct {
84858466 }
84868467
84878468 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;
8469 const zcu = self.ng.pt.zcu;
84908470 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84918471 const lhs = try self.resolveInst(bin_op.lhs);
84928472 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8503,8 +8483,7 @@ pub const FuncGen = struct {
85038483 }
85048484
85058485 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;
8486 const zcu = self.ng.pt.zcu;
85088487 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85098488 const lhs = try self.resolveInst(bin_op.lhs);
85108489 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -8521,12 +8500,13 @@ pub const FuncGen = struct {
85218500
85228501 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
85238502 const o = self.ng.object;
8524 const zcu = o.pt.zcu;
8503 const pt = self.ng.pt;
8504 const zcu = pt.zcu;
85258505 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85268506 const lhs = try self.resolveInst(bin_op.lhs);
85278507 const rhs = try self.resolveInst(bin_op.rhs);
85288508 const inst_ty = self.typeOfIndex(inst);
8529 const inst_llvm_ty = try o.lowerType(inst_ty);
8509 const inst_llvm_ty = try o.lowerType(pt, inst_ty);
85308510 const scalar_ty = inst_ty.scalarType(zcu);
85318511
85328512 if (scalar_ty.isRuntimeFloat()) {
......@@ -8574,17 +8554,18 @@ pub const FuncGen = struct {
85748554
85758555 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85768556 const o = self.ng.object;
8577 const zcu = o.pt.zcu;
8557 const pt = self.ng.pt;
8558 const zcu = pt.zcu;
85788559 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
85798560 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
85808561 const ptr = try self.resolveInst(bin_op.lhs);
85818562 const offset = try self.resolveInst(bin_op.rhs);
85828563 const ptr_ty = self.typeOf(bin_op.lhs);
8583 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8564 const llvm_elem_ty = try o.lowerPtrElemTy(pt, ptr_ty.childType(zcu));
85848565 switch (ptr_ty.ptrSize(zcu)) {
85858566 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
85868567 .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
8587 try o.builder.intValue(try o.lowerType(Type.usize), 0), offset,
8568 try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), offset,
85888569 }, ""),
85898570 .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""),
85908571 .slice => {
......@@ -8596,18 +8577,19 @@ pub const FuncGen = struct {
85968577
85978578 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85988579 const o = self.ng.object;
8599 const zcu = o.pt.zcu;
8580 const pt = self.ng.pt;
8581 const zcu = pt.zcu;
86008582 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
86018583 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
86028584 const ptr = try self.resolveInst(bin_op.lhs);
86038585 const offset = try self.resolveInst(bin_op.rhs);
86048586 const negative_offset = try self.wip.neg(offset, "");
86058587 const ptr_ty = self.typeOf(bin_op.lhs);
8606 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8588 const llvm_elem_ty = try o.lowerPtrElemTy(pt, ptr_ty.childType(zcu));
86078589 switch (ptr_ty.ptrSize(zcu)) {
86088590 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
86098591 .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
8610 try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset,
8592 try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), negative_offset,
86118593 }, ""),
86128594 .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""),
86138595 .slice => {
......@@ -8624,7 +8606,7 @@ pub const FuncGen = struct {
86248606 unsigned_intrinsic: Builder.Intrinsic,
86258607 ) !Builder.Value {
86268608 const o = self.ng.object;
8627 const pt = o.pt;
8609 const pt = self.ng.pt;
86288610 const zcu = pt.zcu;
86298611 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
86308612 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
......@@ -8637,8 +8619,8 @@ pub const FuncGen = struct {
86378619 const inst_ty = self.typeOfIndex(inst);
86388620
86398621 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);
8622 const llvm_inst_ty = try o.lowerType(pt, inst_ty);
8623 const llvm_lhs_ty = try o.lowerType(pt, lhs_ty);
86428624 const results =
86438625 try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, "");
86448626
......@@ -8718,7 +8700,7 @@ pub const FuncGen = struct {
87188700 return o.builder.addFunction(
87198701 try o.builder.fnType(return_type, param_types, .normal),
87208702 fn_name,
8721 toLlvmAddressSpace(.generic, o.pt.zcu.getTarget()),
8703 toLlvmAddressSpace(.generic, self.ng.pt.zcu.getTarget()),
87228704 );
87238705 }
87248706
......@@ -8732,10 +8714,11 @@ pub const FuncGen = struct {
87328714 params: [2]Builder.Value,
87338715 ) !Builder.Value {
87348716 const o = self.ng.object;
8735 const zcu = o.pt.zcu;
8717 const pt = self.ng.pt;
8718 const zcu = pt.zcu;
87368719 const target = zcu.getTarget();
87378720 const scalar_ty = ty.scalarType(zcu);
8738 const scalar_llvm_ty = try o.lowerType(scalar_ty);
8721 const scalar_llvm_ty = try o.lowerType(pt, scalar_ty);
87398722
87408723 if (intrinsicsAllowed(scalar_ty, target)) {
87418724 const cond: Builder.FloatCondition = switch (pred) {
......@@ -8838,10 +8821,11 @@ pub const FuncGen = struct {
88388821 params: [params_len]Builder.Value,
88398822 ) !Builder.Value {
88408823 const o = self.ng.object;
8841 const zcu = o.pt.zcu;
8824 const pt = self.ng.pt;
8825 const zcu = pt.zcu;
88428826 const target = zcu.getTarget();
88438827 const scalar_ty = ty.scalarType(zcu);
8844 const llvm_ty = try o.lowerType(ty);
8828 const llvm_ty = try o.lowerType(pt, ty);
88458829
88468830 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {
88478831 // Some operations are dedicated LLVM instructions, not available as intrinsics
......@@ -8979,7 +8963,7 @@ pub const FuncGen = struct {
89798963
89808964 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
89818965 const o = self.ng.object;
8982 const pt = o.pt;
8966 const pt = self.ng.pt;
89838967 const zcu = pt.zcu;
89848968 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
89858969 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
......@@ -8993,9 +8977,9 @@ pub const FuncGen = struct {
89938977 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
89948978
89958979 const dest_ty = self.typeOfIndex(inst);
8996 const llvm_dest_ty = try o.lowerType(dest_ty);
8980 const llvm_dest_ty = try o.lowerType(pt, dest_ty);
89978981
8998 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
8982 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), "");
89998983
90008984 const result = try self.wip.bin(.shl, lhs, casted_rhs, "");
90018985 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
......@@ -9052,7 +9036,8 @@ pub const FuncGen = struct {
90529036
90539037 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
90549038 const o = self.ng.object;
9055 const zcu = o.pt.zcu;
9039 const pt = self.ng.pt;
9040 const zcu = pt.zcu;
90569041 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
90579042
90589043 const lhs = try self.resolveInst(bin_op.lhs);
......@@ -9063,7 +9048,7 @@ pub const FuncGen = struct {
90639048 return self.ng.todo("implement vector shifts with scalar rhs", .{});
90649049 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
90659050
9066 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
9051 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), "");
90679052 return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
90689053 .@"shl nsw"
90699054 else
......@@ -9072,7 +9057,8 @@ pub const FuncGen = struct {
90729057
90739058 fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
90749059 const o = self.ng.object;
9075 const zcu = o.pt.zcu;
9060 const pt = self.ng.pt;
9061 const zcu = pt.zcu;
90769062 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
90779063
90789064 const lhs = try self.resolveInst(bin_op.lhs);
......@@ -9082,13 +9068,13 @@ pub const FuncGen = struct {
90829068 if (lhs_ty.isVector(zcu) and !self.typeOf(bin_op.rhs).isVector(zcu))
90839069 return self.ng.todo("implement vector shifts with scalar rhs", .{});
90849070
9085 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
9071 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), "");
90869072 return self.wip.bin(.shl, lhs, casted_rhs, "");
90879073 }
90889074
90899075 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
90909076 const o = self.ng.object;
9091 const pt = o.pt;
9077 const pt = self.ng.pt;
90929078 const zcu = pt.zcu;
90939079 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
90949080
......@@ -9097,7 +9083,7 @@ pub const FuncGen = struct {
90979083
90989084 const lhs_ty = self.typeOf(bin_op.lhs);
90999085 const lhs_info = lhs_ty.intInfo(zcu);
9100 const llvm_lhs_ty = try o.lowerType(lhs_ty);
9086 const llvm_lhs_ty = try o.lowerType(pt, lhs_ty);
91019087 const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder);
91029088
91039089 const rhs_ty = self.typeOf(bin_op.rhs);
......@@ -9105,7 +9091,7 @@ pub const FuncGen = struct {
91059091 return self.ng.todo("implement vector shifts with scalar rhs", .{});
91069092 const rhs_info = rhs_ty.intInfo(zcu);
91079093 assert(rhs_info.signedness == .unsigned);
9108 const llvm_rhs_ty = try o.lowerType(rhs_ty);
9094 const llvm_rhs_ty = try o.lowerType(pt, rhs_ty);
91099095 const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder);
91109096
91119097 const result = try self.wip.callIntrinsic(
......@@ -9168,7 +9154,8 @@ pub const FuncGen = struct {
91689154
91699155 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {
91709156 const o = self.ng.object;
9171 const zcu = o.pt.zcu;
9157 const pt = self.ng.pt;
9158 const zcu = pt.zcu;
91729159 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
91739160
91749161 const lhs = try self.resolveInst(bin_op.lhs);
......@@ -9179,7 +9166,7 @@ pub const FuncGen = struct {
91799166 return self.ng.todo("implement vector shifts with scalar rhs", .{});
91809167 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
91819168
9182 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
9169 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), "");
91839170 const is_signed_int = lhs_scalar_ty.isSignedInt(zcu);
91849171
91859172 return self.wip.bin(if (is_exact)
......@@ -9189,7 +9176,8 @@ pub const FuncGen = struct {
91899176
91909177 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
91919178 const o = self.ng.object;
9192 const zcu = o.pt.zcu;
9179 const pt = self.ng.pt;
9180 const zcu = pt.zcu;
91939181 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
91949182 const operand = try self.resolveInst(ty_op.operand);
91959183 const operand_ty = self.typeOf(ty_op.operand);
......@@ -9200,7 +9188,7 @@ pub const FuncGen = struct {
92009188 .normal,
92019189 .none,
92029190 .abs,
9203 &.{try o.lowerType(operand_ty)},
9191 &.{try o.lowerType(pt, operand_ty)},
92049192 &.{ operand, try o.builder.intValue(.i1, 0) },
92059193 "",
92069194 ),
......@@ -9211,10 +9199,11 @@ pub const FuncGen = struct {
92119199
92129200 fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
92139201 const o = fg.ng.object;
9214 const zcu = o.pt.zcu;
9202 const pt = fg.ng.pt;
9203 const zcu = pt.zcu;
92159204 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
92169205 const dest_ty = fg.typeOfIndex(inst);
9217 const dest_llvm_ty = try o.lowerType(dest_ty);
9206 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
92189207 const operand = try fg.resolveInst(ty_op.operand);
92199208 const operand_ty = fg.typeOf(ty_op.operand);
92209209 const operand_info = operand_ty.intInfo(zcu);
......@@ -9243,8 +9232,8 @@ pub const FuncGen = struct {
92439232
92449233 if (!have_min_check and !have_max_check) break :safety;
92459234
9246 const operand_llvm_ty = try o.lowerType(operand_ty);
9247 const operand_scalar_llvm_ty = try o.lowerType(operand_scalar);
9235 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9236 const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar);
92489237
92499238 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;
92509239 assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector));
......@@ -9313,15 +9302,17 @@ pub const FuncGen = struct {
93139302
93149303 fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
93159304 const o = self.ng.object;
9305 const pt = self.ng.pt;
93169306 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
93179307 const operand = try self.resolveInst(ty_op.operand);
9318 const dest_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
9308 const dest_llvm_ty = try o.lowerType(pt, self.typeOfIndex(inst));
93199309 return self.wip.cast(.trunc, operand, dest_llvm_ty, "");
93209310 }
93219311
93229312 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
93239313 const o = self.ng.object;
9324 const zcu = o.pt.zcu;
9314 const pt = self.ng.pt;
9315 const zcu = pt.zcu;
93259316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
93269317 const operand = try self.resolveInst(ty_op.operand);
93279318 const operand_ty = self.typeOf(ty_op.operand);
......@@ -9329,10 +9320,10 @@ pub const FuncGen = struct {
93299320 const target = zcu.getTarget();
93309321
93319322 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {
9332 return self.wip.cast(.fptrunc, operand, try o.lowerType(dest_ty), "");
9323 return self.wip.cast(.fptrunc, operand, try o.lowerType(pt, dest_ty), "");
93339324 } else {
9334 const operand_llvm_ty = try o.lowerType(operand_ty);
9335 const dest_llvm_ty = try o.lowerType(dest_ty);
9325 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9326 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
93369327
93379328 const dest_bits = dest_ty.floatBits(target);
93389329 const src_bits = operand_ty.floatBits(target);
......@@ -9355,7 +9346,8 @@ pub const FuncGen = struct {
93559346
93569347 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
93579348 const o = self.ng.object;
9358 const zcu = o.pt.zcu;
9349 const pt = self.ng.pt;
9350 const zcu = pt.zcu;
93599351 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
93609352 const operand = try self.resolveInst(ty_op.operand);
93619353 const operand_ty = self.typeOf(ty_op.operand);
......@@ -9363,10 +9355,10 @@ pub const FuncGen = struct {
93639355 const target = zcu.getTarget();
93649356
93659357 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {
9366 return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), "");
9358 return self.wip.cast(.fpext, operand, try o.lowerType(pt, dest_ty), "");
93679359 } else {
9368 const operand_llvm_ty = try o.lowerType(operand_ty);
9369 const dest_llvm_ty = try o.lowerType(dest_ty);
9360 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9361 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
93709362
93719363 const dest_bits = dest_ty.scalarType(zcu).floatBits(target);
93729364 const src_bits = operand_ty.scalarType(zcu).floatBits(target);
......@@ -9403,11 +9395,11 @@ pub const FuncGen = struct {
94039395
94049396 fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value {
94059397 const o = self.ng.object;
9406 const pt = o.pt;
9398 const pt = self.ng.pt;
94079399 const zcu = pt.zcu;
94089400 const operand_is_ref = isByRef(operand_ty, zcu);
94099401 const result_is_ref = isByRef(inst_ty, zcu);
9410 const llvm_dest_ty = try o.lowerType(inst_ty);
9402 const llvm_dest_ty = try o.lowerType(pt, inst_ty);
94119403
94129404 if (operand_is_ref and result_is_ref) {
94139405 // They are both pointers, so just return the same opaque pointer :)
......@@ -9442,7 +9434,7 @@ pub const FuncGen = struct {
94429434 } else {
94439435 // If the ABI size of the element type is not evenly divisible by size in bits;
94449436 // a simple bitcast will not work, and we fall back to extractelement.
9445 const llvm_usize = try o.lowerType(Type.usize);
9437 const llvm_usize = try o.lowerType(pt, Type.usize);
94469438 const usize_zero = try o.builder.intValue(llvm_usize, 0);
94479439 const vector_len = operand_ty.arrayLen(zcu);
94489440 var i: u64 = 0;
......@@ -9458,7 +9450,7 @@ pub const FuncGen = struct {
94589450 return array_ptr;
94599451 } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) {
94609452 const elem_ty = operand_ty.childType(zcu);
9461 const llvm_vector_ty = try o.lowerType(inst_ty);
9453 const llvm_vector_ty = try o.lowerType(pt, inst_ty);
94629454 if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{});
94639455
94649456 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;
......@@ -9470,9 +9462,9 @@ pub const FuncGen = struct {
94709462 } else {
94719463 // If the ABI size of the element type is not evenly divisible by size in bits;
94729464 // 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);
9465 const array_llvm_ty = try o.lowerType(pt, operand_ty);
9466 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
9467 const llvm_usize = try o.lowerType(pt, Type.usize);
94769468 const usize_zero = try o.builder.intValue(llvm_usize, 0);
94779469 const vector_len = operand_ty.arrayLen(zcu);
94789470 var vector = try o.builder.poisonValue(llvm_vector_ty);
......@@ -9519,7 +9511,7 @@ pub const FuncGen = struct {
95199511
95209512 fn airArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
95219513 const o = self.ng.object;
9522 const pt = o.pt;
9514 const pt = self.ng.pt;
95239515 const zcu = pt.zcu;
95249516 const arg_val = self.args[self.arg_index];
95259517 self.arg_index += 1;
......@@ -9547,7 +9539,7 @@ pub const FuncGen = struct {
95479539 self.file,
95489540 self.scope,
95499541 lbrace_line,
9550 try o.lowerDebugType(inst_ty),
9542 try o.lowerDebugType(pt, inst_ty),
95519543 self.arg_index,
95529544 );
95539545
......@@ -9611,28 +9603,28 @@ pub const FuncGen = struct {
96119603
96129604 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
96139605 const o = self.ng.object;
9614 const pt = o.pt;
9606 const pt = self.ng.pt;
96159607 const zcu = pt.zcu;
96169608 const ptr_ty = self.typeOfIndex(inst);
96179609 const pointee_type = ptr_ty.childType(zcu);
96189610 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
9619 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
9611 return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue();
96209612
9621 const pointee_llvm_ty = try o.lowerType(pointee_type);
9613 const pointee_llvm_ty = try o.lowerType(pt, pointee_type);
96229614 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
96239615 return self.buildAlloca(pointee_llvm_ty, alignment);
96249616 }
96259617
96269618 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
96279619 const o = self.ng.object;
9628 const pt = o.pt;
9620 const pt = self.ng.pt;
96299621 const zcu = pt.zcu;
96309622 const ptr_ty = self.typeOfIndex(inst);
96319623 const ret_ty = ptr_ty.childType(zcu);
96329624 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
9633 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
9625 return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue();
96349626 if (self.ret_ptr != .none) return self.ret_ptr;
9635 const ret_llvm_ty = try o.lowerType(ret_ty);
9627 const ret_llvm_ty = try o.lowerType(pt, ret_ty);
96369628 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
96379629 return self.buildAlloca(ret_llvm_ty, alignment);
96389630 }
......@@ -9644,13 +9636,13 @@ pub const FuncGen = struct {
96449636 llvm_ty: Builder.Type,
96459637 alignment: Builder.Alignment,
96469638 ) Allocator.Error!Builder.Value {
9647 const target = self.ng.object.pt.zcu.getTarget();
9639 const target = self.ng.pt.zcu.getTarget();
96489640 return buildAllocaInner(&self.wip, llvm_ty, alignment, target);
96499641 }
96509642
96519643 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
96529644 const o = self.ng.object;
9653 const pt = o.pt;
9645 const pt = self.ng.pt;
96549646 const zcu = pt.zcu;
96559647 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
96569648 const dest_ptr = try self.resolveInst(bin_op.lhs);
......@@ -9685,7 +9677,7 @@ pub const FuncGen = struct {
96859677
96869678 self.maybeMarkAllowZeroAccess(ptr_info);
96879679
9688 const len = try o.builder.intValue(try o.lowerType(Type.usize), operand_ty.abiSize(zcu));
9680 const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), operand_ty.abiSize(zcu));
96899681 _ = try self.wip.callMemSet(
96909682 dest_ptr,
96919683 ptr_ty.ptrAlignment(zcu).toLlvm(),
......@@ -9714,8 +9706,7 @@ pub const FuncGen = struct {
97149706 ///
97159707 /// The first instruction of `body_tail` is the one whose copy we want to elide.
97169708 fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool {
9717 const o = fg.ng.object;
9718 const zcu = o.pt.zcu;
9709 const zcu = fg.ng.pt.zcu;
97199710 const ip = &zcu.intern_pool;
97209711 for (body_tail[1..]) |body_inst| {
97219712 switch (fg.liveness.categorizeOperand(fg.air, zcu, body_inst, body_tail[0], ip)) {
......@@ -9730,8 +9721,7 @@ pub const FuncGen = struct {
97309721 }
97319722
97329723 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
9733 const o = fg.ng.object;
9734 const pt = o.pt;
9724 const pt = fg.ng.pt;
97359725 const zcu = pt.zcu;
97369726 const inst = body_tail[0];
97379727 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
......@@ -9765,8 +9755,9 @@ pub const FuncGen = struct {
97659755 fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
97669756 _ = inst;
97679757 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)) {
9758 const pt = self.ng.pt;
9759 const llvm_usize = try o.lowerType(pt, Type.usize);
9760 if (!target_util.supportsReturnAddress(self.ng.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) {
97709761 // https://github.com/ziglang/zig/issues/11946
97719762 return o.builder.intValue(llvm_usize, 0);
97729763 }
......@@ -9777,8 +9768,9 @@ pub const FuncGen = struct {
97779768 fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
97789769 _ = inst;
97799770 const o = self.ng.object;
9771 const pt = self.ng.pt;
97809772 const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, "");
9781 return self.wip.cast(.ptrtoint, result, try o.lowerType(Type.usize), "");
9773 return self.wip.cast(.ptrtoint, result, try o.lowerType(pt, Type.usize), "");
97829774 }
97839775
97849776 fn airCmpxchg(
......@@ -9787,7 +9779,7 @@ pub const FuncGen = struct {
97879779 kind: Builder.Function.Instruction.CmpXchg.Kind,
97889780 ) !Builder.Value {
97899781 const o = self.ng.object;
9790 const pt = o.pt;
9782 const pt = self.ng.pt;
97919783 const zcu = pt.zcu;
97929784 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
97939785 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
......@@ -9796,8 +9788,8 @@ pub const FuncGen = struct {
97969788 var expected_value = try self.resolveInst(extra.expected_value);
97979789 var new_value = try self.resolveInst(extra.new_value);
97989790 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);
9791 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
9792 const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false);
98019793 if (llvm_abi_ty != .none) {
98029794 // operand needs widening and truncating
98039795 const signedness: Builder.Function.Instruction.Cast.Signedness =
......@@ -9840,7 +9832,7 @@ pub const FuncGen = struct {
98409832
98419833 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
98429834 const o = self.ng.object;
9843 const pt = o.pt;
9835 const pt = self.ng.pt;
98449836 const zcu = pt.zcu;
98459837 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
98469838 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
......@@ -9852,8 +9844,8 @@ pub const FuncGen = struct {
98529844 const is_float = operand_ty.isRuntimeFloat();
98539845 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);
98549846 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);
9847 const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, op == .xchg);
9848 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
98579849
98589850 const access_kind: Builder.MemoryAccessKind =
98599851 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
......@@ -9896,7 +9888,7 @@ pub const FuncGen = struct {
98969888 access_kind,
98979889 op,
98989890 ptr,
9899 try self.wip.cast(.ptrtoint, operand, try o.lowerType(Type.usize), ""),
9891 try self.wip.cast(.ptrtoint, operand, try o.lowerType(pt, Type.usize), ""),
99009892 self.sync_scope,
99019893 ordering,
99029894 ptr_alignment,
......@@ -9906,7 +9898,7 @@ pub const FuncGen = struct {
99069898
99079899 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
99089900 const o = self.ng.object;
9909 const pt = o.pt;
9901 const pt = self.ng.pt;
99109902 const zcu = pt.zcu;
99119903 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
99129904 const ptr = try self.resolveInst(atomic_load.ptr);
......@@ -9915,14 +9907,14 @@ pub const FuncGen = struct {
99159907 const elem_ty = Type.fromInterned(info.child);
99169908 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
99179909 const ordering = toLlvmAtomicOrdering(atomic_load.order);
9918 const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false);
9910 const llvm_abi_ty = try o.getAtomicAbiType(pt, elem_ty, false);
99199911 const ptr_alignment = (if (info.flags.alignment != .none)
99209912 @as(InternPool.Alignment, info.flags.alignment)
99219913 else
99229914 Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm();
99239915 const access_kind: Builder.MemoryAccessKind =
99249916 if (info.flags.is_volatile) .@"volatile" else .normal;
9925 const elem_llvm_ty = try o.lowerType(elem_ty);
9917 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
99269918
99279919 self.maybeMarkAllowZeroAccess(info);
99289920
......@@ -9956,7 +9948,7 @@ pub const FuncGen = struct {
99569948 ordering: Builder.AtomicOrdering,
99579949 ) !Builder.Value {
99589950 const o = self.ng.object;
9959 const pt = o.pt;
9951 const pt = self.ng.pt;
99609952 const zcu = pt.zcu;
99619953 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
99629954 const ptr_ty = self.typeOf(bin_op.lhs);
......@@ -9964,7 +9956,7 @@ pub const FuncGen = struct {
99649956 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none;
99659957 const ptr = try self.resolveInst(bin_op.lhs);
99669958 var element = try self.resolveInst(bin_op.rhs);
9967 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);
9959 const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false);
99689960
99699961 if (llvm_abi_ty != .none) {
99709962 // operand needs widening
......@@ -9984,7 +9976,7 @@ pub const FuncGen = struct {
99849976
99859977 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
99869978 const o = self.ng.object;
9987 const pt = o.pt;
9979 const pt = self.ng.pt;
99889980 const zcu = pt.zcu;
99899981 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
99909982 const dest_slice = try self.resolveInst(bin_op.lhs);
......@@ -10081,13 +10073,13 @@ pub const FuncGen = struct {
1008110073 const body_block = try self.wip.block(1, "InlineMemsetBody");
1008210074 const end_block = try self.wip.block(1, "InlineMemsetEnd");
1008310075
10084 const llvm_usize_ty = try o.lowerType(Type.usize);
10076 const llvm_usize_ty = try o.lowerType(pt, Type.usize);
1008510077 const len = switch (ptr_ty.ptrSize(zcu)) {
1008610078 .slice => try self.wip.extractValue(dest_slice, &.{1}, ""),
1008710079 .one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)),
1008810080 .many, .c => unreachable,
1008910081 };
10090 const elem_llvm_ty = try o.lowerType(elem_ty);
10082 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
1009110083 const end_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, dest_ptr, &.{len}, "");
1009210084 _ = try self.wip.br(loop_block);
1009310085
......@@ -10121,8 +10113,7 @@ pub const FuncGen = struct {
1012110113 }
1012210114
1012310115 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10124 const o = self.ng.object;
10125 const pt = o.pt;
10116 const pt = self.ng.pt;
1012610117 const zcu = pt.zcu;
1012710118 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1012810119 const dest_slice = try self.resolveInst(bin_op.lhs);
......@@ -10151,8 +10142,7 @@ pub const FuncGen = struct {
1015110142 }
1015210143
1015310144 fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10154 const o = self.ng.object;
10155 const pt = o.pt;
10145 const pt = self.ng.pt;
1015610146 const zcu = pt.zcu;
1015710147 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1015810148 const dest_slice = try self.resolveInst(bin_op.lhs);
......@@ -10178,7 +10168,7 @@ pub const FuncGen = struct {
1017810168
1017910169 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1018010170 const o = self.ng.object;
10181 const pt = o.pt;
10171 const pt = self.ng.pt;
1018210172 const zcu = pt.zcu;
1018310173 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1018410174 const un_ptr_ty = self.typeOf(bin_op.lhs);
......@@ -10199,7 +10189,7 @@ pub const FuncGen = struct {
1019910189 return .none;
1020010190 }
1020110191 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, "");
10192 const tag_field_ptr = try self.wip.gepStruct(try o.lowerType(pt, un_ty), union_ptr, tag_index, "");
1020310193 // TODO alignment on this store
1020410194 _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, .default);
1020510195 return .none;
......@@ -10207,7 +10197,7 @@ pub const FuncGen = struct {
1020710197
1020810198 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1020910199 const o = self.ng.object;
10210 const pt = o.pt;
10200 const pt = self.ng.pt;
1021110201 const zcu = pt.zcu;
1021210202 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1021310203 const un_ty = self.typeOf(ty_op.operand);
......@@ -10215,7 +10205,7 @@ pub const FuncGen = struct {
1021510205 if (layout.tag_size == 0) return .none;
1021610206 const union_handle = try self.resolveInst(ty_op.operand);
1021710207 if (isByRef(un_ty, zcu)) {
10218 const llvm_un_ty = try o.lowerType(un_ty);
10208 const llvm_un_ty = try o.lowerType(pt, un_ty);
1021910209 if (layout.payload_size == 0)
1022010210 return self.wip.load(.normal, llvm_un_ty, union_handle, .default, "");
1022110211 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
......@@ -10247,6 +10237,7 @@ pub const FuncGen = struct {
1024710237
1024810238 fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
1024910239 const o = self.ng.object;
10240 const pt = self.ng.pt;
1025010241 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1025110242 const inst_ty = self.typeOfIndex(inst);
1025210243 const operand_ty = self.typeOf(ty_op.operand);
......@@ -10256,15 +10247,16 @@ pub const FuncGen = struct {
1025610247 .normal,
1025710248 .none,
1025810249 intrinsic,
10259 &.{try o.lowerType(operand_ty)},
10250 &.{try o.lowerType(pt, operand_ty)},
1026010251 &.{ operand, .false },
1026110252 "",
1026210253 );
10263 return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), "");
10254 return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), "");
1026410255 }
1026510256
1026610257 fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
1026710258 const o = self.ng.object;
10259 const pt = self.ng.pt;
1026810260 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1026910261 const inst_ty = self.typeOfIndex(inst);
1027010262 const operand_ty = self.typeOf(ty_op.operand);
......@@ -10274,16 +10266,17 @@ pub const FuncGen = struct {
1027410266 .normal,
1027510267 .none,
1027610268 intrinsic,
10277 &.{try o.lowerType(operand_ty)},
10269 &.{try o.lowerType(pt, operand_ty)},
1027810270 &.{operand},
1027910271 "",
1028010272 );
10281 return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), "");
10273 return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), "");
1028210274 }
1028310275
1028410276 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1028510277 const o = self.ng.object;
10286 const zcu = o.pt.zcu;
10278 const pt = self.ng.pt;
10279 const zcu = pt.zcu;
1028710280 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1028810281 const operand_ty = self.typeOf(ty_op.operand);
1028910282 var bits = operand_ty.intInfo(zcu).bits;
......@@ -10291,7 +10284,7 @@ pub const FuncGen = struct {
1029110284
1029210285 const inst_ty = self.typeOfIndex(inst);
1029310286 var operand = try self.resolveInst(ty_op.operand);
10294 var llvm_operand_ty = try o.lowerType(operand_ty);
10287 var llvm_operand_ty = try o.lowerType(pt, operand_ty);
1029510288
1029610289 if (bits % 16 == 8) {
1029710290 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte
......@@ -10312,12 +10305,13 @@ pub const FuncGen = struct {
1031210305
1031310306 const result =
1031410307 try self.wip.callIntrinsic(.normal, .none, .bswap, &.{llvm_operand_ty}, &.{operand}, "");
10315 return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), "");
10308 return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), "");
1031610309 }
1031710310
1031810311 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1031910312 const o = self.ng.object;
10320 const zcu = o.pt.zcu;
10313 const pt = self.ng.pt;
10314 const zcu = pt.zcu;
1032110315 const ip = &zcu.intern_pool;
1032210316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1032310317 const operand = try self.resolveInst(ty_op.operand);
......@@ -10332,7 +10326,7 @@ pub const FuncGen = struct {
1033210326
1033310327 for (0..names.len) |name_index| {
1033410328 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);
10329 const this_tag_int_value = try o.builder.intConst(try o.errorIntType(pt), err_int);
1033610330 try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip);
1033710331 }
1033810332 self.wip.cursor = .{ .block = valid_block };
......@@ -10367,7 +10361,7 @@ pub const FuncGen = struct {
1036710361
1036810362 fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !Builder.Function.Index {
1036910363 const o = self.ng.object;
10370 const pt = o.pt;
10364 const pt = self.ng.pt;
1037110365 const zcu = pt.zcu;
1037210366 const ip = &zcu.intern_pool;
1037310367 const enum_type = ip.loadEnumType(enum_ty.toIntern());
......@@ -10379,7 +10373,7 @@ pub const FuncGen = struct {
1037910373
1038010374 const target = &zcu.root_mod.resolved_target.result;
1038110375 const function_index = try o.builder.addFunction(
10382 try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
10376 try o.builder.fnType(.i1, &.{try o.lowerType(pt, Type.fromInterned(enum_type.tag_ty))}, .normal),
1038310377 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_type.name.fmt(ip)}),
1038410378 toLlvmAddressSpace(.generic, target),
1038510379 );
......@@ -10408,6 +10402,7 @@ pub const FuncGen = struct {
1040810402
1040910403 for (0..enum_type.names.len) |field_index| {
1041010404 const this_tag_int_value = try o.lowerValue(
10405 pt,
1041110406 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),
1041210407 );
1041310408 try wip_switch.addCase(this_tag_int_value, named_block, &wip);
......@@ -10424,11 +10419,12 @@ pub const FuncGen = struct {
1042410419
1042510420 fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1042610421 const o = self.ng.object;
10422 const pt = self.ng.pt;
1042710423 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1042810424 const operand = try self.resolveInst(un_op);
1042910425 const enum_ty = self.typeOf(un_op);
1043010426
10431 const llvm_fn = try o.getEnumTagNameFunction(enum_ty);
10427 const llvm_fn = try o.getEnumTagNameFunction(pt, enum_ty);
1043210428 return self.wip.call(
1043310429 .normal,
1043410430 .fastcc,
......@@ -10442,10 +10438,11 @@ pub const FuncGen = struct {
1044210438
1044310439 fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1044410440 const o = self.ng.object;
10441 const pt = self.ng.pt;
1044510442 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1044610443 const operand = try self.resolveInst(un_op);
1044710444 const slice_ty = self.typeOfIndex(inst);
10448 const slice_llvm_ty = try o.lowerType(slice_ty);
10445 const slice_llvm_ty = try o.lowerType(pt, slice_ty);
1044910446
1045010447 const error_name_table_ptr = try self.getErrorNameTable();
1045110448 const error_name_table =
......@@ -10457,10 +10454,11 @@ pub const FuncGen = struct {
1045710454
1045810455 fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1045910456 const o = self.ng.object;
10457 const pt = self.ng.pt;
1046010458 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1046110459 const scalar = try self.resolveInst(ty_op.operand);
1046210460 const vector_ty = self.typeOfIndex(inst);
10463 return self.wip.splatVector(try o.lowerType(vector_ty), scalar, "");
10461 return self.wip.splatVector(try o.lowerType(pt, vector_ty), scalar, "");
1046410462 }
1046510463
1046610464 fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
......@@ -10475,7 +10473,7 @@ pub const FuncGen = struct {
1047510473
1047610474 fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1047710475 const o = fg.ng.object;
10478 const pt = o.pt;
10476 const pt = fg.ng.pt;
1047910477 const zcu = pt.zcu;
1048010478 const gpa = zcu.gpa;
1048110479
......@@ -10484,9 +10482,9 @@ pub const FuncGen = struct {
1048410482 const operand = try fg.resolveInst(unwrapped.operand);
1048510483 const mask = unwrapped.mask;
1048610484 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));
10485 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
10486 const llvm_result_ty = try o.lowerType(pt, unwrapped.result_ty);
10487 const llvm_elem_ty = try o.lowerType(pt, unwrapped.result_ty.childType(zcu));
1049010488 const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty);
1049110489 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);
1049210490 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);
......@@ -10516,7 +10514,7 @@ pub const FuncGen = struct {
1051610514 .elem => llvm_poison_elem,
1051710515 .value => |val| if (!Value.fromInterned(val).isUndef(zcu)) elem: {
1051810516 any_defined_comptime_value = true;
10519 break :elem try o.lowerValue(val);
10517 break :elem try o.lowerValue(pt, val);
1052010518 } else llvm_poison_elem,
1052110519 };
1052210520 }
......@@ -10582,14 +10580,14 @@ pub const FuncGen = struct {
1058210580
1058310581 fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1058410582 const o = fg.ng.object;
10585 const pt = o.pt;
10583 const pt = fg.ng.pt;
1058610584 const zcu = pt.zcu;
1058710585 const gpa = zcu.gpa;
1058810586
1058910587 const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst);
1059010588
1059110589 const mask = unwrapped.mask;
10592 const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu));
10590 const llvm_elem_ty = try o.lowerType(pt, unwrapped.result_ty.childType(zcu));
1059310591 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);
1059410592 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);
1059510593
......@@ -10681,7 +10679,8 @@ pub const FuncGen = struct {
1068110679 accum_init: Builder.Value,
1068210680 ) !Builder.Value {
1068310681 const o = self.ng.object;
10684 const usize_ty = try o.lowerType(Type.usize);
10682 const pt = self.ng.pt;
10683 const usize_ty = try o.lowerType(pt, Type.usize);
1068510684 const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len);
1068610685 const llvm_result_ty = accum_init.typeOfWip(&self.wip);
1068710686
......@@ -10735,15 +10734,16 @@ pub const FuncGen = struct {
1073510734
1073610735 fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
1073710736 const o = self.ng.object;
10738 const zcu = o.pt.zcu;
10737 const pt = self.ng.pt;
10738 const zcu = pt.zcu;
1073910739 const target = zcu.getTarget();
1074010740
1074110741 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
1074210742 const operand = try self.resolveInst(reduce.operand);
1074310743 const operand_ty = self.typeOf(reduce.operand);
10744 const llvm_operand_ty = try o.lowerType(operand_ty);
10744 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
1074510745 const scalar_ty = self.typeOfIndex(inst);
10746 const llvm_scalar_ty = try o.lowerType(scalar_ty);
10746 const llvm_scalar_ty = try o.lowerType(pt, scalar_ty);
1074710747
1074810748 switch (reduce.operation) {
1074910749 .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
......@@ -10845,14 +10845,14 @@ pub const FuncGen = struct {
1084510845
1084610846 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1084710847 const o = self.ng.object;
10848 const pt = o.pt;
10848 const pt = self.ng.pt;
1084910849 const zcu = pt.zcu;
1085010850 const ip = &zcu.intern_pool;
1085110851 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1085210852 const result_ty = self.typeOfIndex(inst);
1085310853 const len: usize = @intCast(result_ty.arrayLen(zcu));
1085410854 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);
10855 const llvm_result_ty = try o.lowerType(pt, result_ty);
1085610856
1085710857 switch (result_ty.zigTypeTag(zcu)) {
1085810858 .vector => {
......@@ -10933,7 +10933,7 @@ pub const FuncGen = struct {
1093310933 .array => {
1093410934 assert(isByRef(result_ty, zcu));
1093510935
10936 const llvm_usize = try o.lowerType(Type.usize);
10936 const llvm_usize = try o.lowerType(pt, Type.usize);
1093710937 const usize_zero = try o.builder.intValue(llvm_usize, 0);
1093810938 const alignment = result_ty.abiAlignment(zcu).toLlvm();
1093910939 const alloca_inst = try self.buildAlloca(llvm_result_ty, alignment);
......@@ -10966,13 +10966,13 @@ pub const FuncGen = struct {
1096610966
1096710967 fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1096810968 const o = self.ng.object;
10969 const pt = o.pt;
10969 const pt = self.ng.pt;
1097010970 const zcu = pt.zcu;
1097110971 const ip = &zcu.intern_pool;
1097210972 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1097310973 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
1097410974 const union_ty = self.typeOfIndex(inst);
10975 const union_llvm_ty = try o.lowerType(union_ty);
10975 const union_llvm_ty = try o.lowerType(pt, union_ty);
1097610976 const layout = union_ty.unionGetLayout(zcu);
1097710977 const union_obj = zcu.typeToUnion(union_ty).?;
1097810978
......@@ -11014,10 +11014,10 @@ pub const FuncGen = struct {
1101411014 const result_ptr = try self.buildAlloca(union_llvm_ty, alignment);
1101511015 const llvm_payload = try self.resolveInst(extra.init);
1101611016 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
11017 const field_llvm_ty = try o.lowerType(field_ty);
11017 const field_llvm_ty = try o.lowerType(pt, field_ty);
1101811018 const field_size = field_ty.abiSize(zcu);
1101911019 const field_align = union_ty.fieldAlignment(extra.field_index, zcu);
11020 const llvm_usize = try o.lowerType(Type.usize);
11020 const llvm_usize = try o.lowerType(pt, Type.usize);
1102111021 const usize_zero = try o.builder.intValue(llvm_usize, 0);
1102211022
1102311023 const llvm_union_ty = t: {
......@@ -11035,7 +11035,7 @@ pub const FuncGen = struct {
1103511035 });
1103611036 };
1103711037 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));
11038 const tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty));
1103911039 var fields: [3]Builder.Type = undefined;
1104011040 var fields_len: usize = 2;
1104111041 if (layout.tag_align.compare(.gte, layout.payload_align)) {
......@@ -11076,7 +11076,7 @@ pub const FuncGen = struct {
1107611076 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
1107711077 const indices: [2]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, tag_index) };
1107811078 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));
11079 const tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty));
1108011080 var big_int_space: Value.BigIntSpace = undefined;
1108111081 const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu);
1108211082 const llvm_tag = try o.builder.bigIntValue(tag_ty, tag_big_int);
......@@ -11106,7 +11106,7 @@ pub const FuncGen = struct {
1110611106 // by the target.
1110711107 // To work around this, don't emit llvm.prefetch in this case.
1110811108 // See https://bugs.llvm.org/show_bug.cgi?id=21037
11109 const zcu = o.pt.zcu;
11109 const zcu = self.ng.pt.zcu;
1111011110 const target = zcu.getTarget();
1111111111 switch (prefetch.cache) {
1111211112 .instruction => switch (target.cpu.arch) {
......@@ -11139,11 +11139,12 @@ pub const FuncGen = struct {
1113911139
1114011140 fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1114111141 const o = self.ng.object;
11142 const pt = self.ng.pt;
1114211143 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1114311144 const inst_ty = self.typeOfIndex(inst);
1114411145 const operand = try self.resolveInst(ty_op.operand);
1114511146
11146 return self.wip.cast(.addrspacecast, operand, try o.lowerType(inst_ty), "");
11147 return self.wip.cast(.addrspacecast, operand, try o.lowerType(pt, inst_ty), "");
1114711148 }
1114811149
1114911150 fn workIntrinsic(
......@@ -11161,8 +11162,7 @@ pub const FuncGen = struct {
1116111162 }
1116211163
1116311164 fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
11164 const o = self.ng.object;
11165 const target = o.pt.zcu.getTarget();
11165 const target = self.ng.pt.zcu.getTarget();
1116611166
1116711167 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1116811168 const dimension = pl_op.payload;
......@@ -11176,7 +11176,8 @@ pub const FuncGen = struct {
1117611176
1117711177 fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1117811178 const o = self.ng.object;
11179 const target = o.pt.zcu.getTarget();
11179 const pt = self.ng.pt;
11180 const target = pt.zcu.getTarget();
1118011181
1118111182 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1118211183 const dimension = pl_op.payload;
......@@ -11193,7 +11194,7 @@ pub const FuncGen = struct {
1119311194 // Load the work_group_* member from the struct as u16.
1119411195 // Just treat the dispatch pointer as an array of u16 to keep things simple.
1119511196 const workgroup_size_ptr = try self.wip.gep(.inbounds, .i16, dispatch_ptr, &.{
11196 try o.builder.intValue(try o.lowerType(Type.usize), 2 + dimension),
11197 try o.builder.intValue(try o.lowerType(pt, Type.usize), 2 + dimension),
1119711198 }, "");
1119811199 const workgroup_size_alignment = comptime Builder.Alignment.fromByteUnits(2);
1119911200 return self.wip.load(.normal, .i16, workgroup_size_ptr, workgroup_size_alignment, "");
......@@ -11206,8 +11207,7 @@ pub const FuncGen = struct {
1120611207 }
1120711208
1120811209 fn airWorkGroupId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
11209 const o = self.ng.object;
11210 const target = o.pt.zcu.getTarget();
11210 const target = self.ng.pt.zcu.getTarget();
1121111211
1121211212 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1121311213 const dimension = pl_op.payload;
......@@ -11221,7 +11221,7 @@ pub const FuncGen = struct {
1122111221
1122211222 fn getErrorNameTable(self: *FuncGen) Allocator.Error!Builder.Variable.Index {
1122311223 const o = self.ng.object;
11224 const pt = o.pt;
11224 const pt = self.ng.pt;
1122511225
1122611226 const table = o.error_name_table;
1122711227 if (table != .none) return table;
......@@ -11271,8 +11271,7 @@ pub const FuncGen = struct {
1127111271 opt_ty: Type,
1127211272 can_elide_load: bool,
1127311273 ) !Builder.Value {
11274 const o = fg.ng.object;
11275 const pt = o.pt;
11274 const pt = fg.ng.pt;
1127611275 const zcu = pt.zcu;
1127711276 const payload_ty = opt_ty.optionalChild(zcu);
1127811277
......@@ -11301,9 +11300,9 @@ pub const FuncGen = struct {
1130111300 non_null_bit: Builder.Value,
1130211301 ) !Builder.Value {
1130311302 const o = self.ng.object;
11304 const pt = o.pt;
11303 const pt = self.ng.pt;
1130511304 const zcu = pt.zcu;
11306 const optional_llvm_ty = try o.lowerType(optional_ty);
11305 const optional_llvm_ty = try o.lowerType(pt, optional_ty);
1130711306 const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, "");
1130811307
1130911308 if (isByRef(optional_ty, zcu)) {
......@@ -11334,7 +11333,7 @@ pub const FuncGen = struct {
1133411333 field_index: u32,
1133511334 ) !Builder.Value {
1133611335 const o = self.ng.object;
11337 const pt = o.pt;
11336 const pt = self.ng.pt;
1133811337 const zcu = pt.zcu;
1133911338 const struct_ty = struct_ptr_ty.childType(zcu);
1134011339 switch (struct_ty.zigTypeTag(zcu)) {
......@@ -11357,12 +11356,12 @@ pub const FuncGen = struct {
1135711356 // Offset our operand pointer by the correct number of bytes.
1135811357 const byte_offset = @divExact(pt.structPackedFieldBitOffset(struct_type, field_index) + struct_ptr_ty_info.packed_offset.bit_offset, 8);
1135911358 if (byte_offset == 0) return struct_ptr;
11360 const usize_ty = try o.lowerType(Type.usize);
11359 const usize_ty = try o.lowerType(pt, Type.usize);
1136111360 const llvm_index = try o.builder.intValue(usize_ty, byte_offset);
1136211361 return self.wip.gep(.inbounds, .i8, struct_ptr, &.{llvm_index}, "");
1136311362 },
1136411363 else => {
11365 const struct_llvm_ty = try o.lowerPtrElemTy(struct_ty);
11364 const struct_llvm_ty = try o.lowerPtrElemTy(pt, struct_ty);
1136611365
1136711366 if (o.llvmFieldIndex(struct_ty, field_index)) |llvm_field_index| {
1136811367 return self.wip.gepStruct(struct_llvm_ty, struct_ptr, llvm_field_index, "");
......@@ -11372,7 +11371,7 @@ pub const FuncGen = struct {
1137211371 // the index to the element at index `1` to get a pointer to the end of
1137311372 // the struct.
1137411373 const llvm_index = try o.builder.intValue(
11375 try o.lowerType(Type.usize),
11374 try o.lowerType(pt, Type.usize),
1137611375 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)),
1137711376 );
1137811377 return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, "");
......@@ -11383,7 +11382,7 @@ pub const FuncGen = struct {
1138311382 const layout = struct_ty.unionGetLayout(zcu);
1138411383 if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr;
1138511384 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
11386 const union_llvm_ty = try o.lowerType(struct_ty);
11385 const union_llvm_ty = try o.lowerType(pt, struct_ty);
1138711386 return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, "");
1138811387 },
1138911388 else => unreachable,
......@@ -11403,9 +11402,9 @@ pub const FuncGen = struct {
1140311402 // => so load the byte aligned value and trunc the unwanted bits.
1140411403
1140511404 const o = fg.ng.object;
11406 const pt = o.pt;
11405 const pt = fg.ng.pt;
1140711406 const zcu = pt.zcu;
11408 const payload_llvm_ty = try o.lowerType(payload_ty);
11407 const payload_llvm_ty = try o.lowerType(pt, payload_ty);
1140911408 const abi_size = payload_ty.abiSize(zcu);
1141011409
1141111410 // llvm bug workarounds:
......@@ -11450,8 +11449,8 @@ pub const FuncGen = struct {
1145011449 access_kind: Builder.MemoryAccessKind,
1145111450 ) !Builder.Value {
1145211451 const o = fg.ng.object;
11453 const pt = o.pt;
11454 const pointee_llvm_ty = try o.lowerType(pointee_type);
11452 const pt = fg.ng.pt;
11453 const pointee_llvm_ty = try o.lowerType(pt, pointee_type);
1145511454 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment)
1145611455 .max(pointee_type.abiAlignment(pt.zcu)).toLlvm();
1145711456 const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align);
......@@ -11461,7 +11460,7 @@ pub const FuncGen = struct {
1146111460 result_align,
1146211461 ptr,
1146311462 ptr_alignment,
11464 try o.builder.intValue(try o.lowerType(Type.usize), size_bytes),
11463 try o.builder.intValue(try o.lowerType(pt, Type.usize), size_bytes),
1146511464 access_kind,
1146611465 fg.disable_intrinsics,
1146711466 );
......@@ -11473,7 +11472,7 @@ pub const FuncGen = struct {
1147311472 /// For isByRef=false types, it creates a load instruction and returns it.
1147411473 fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value {
1147511474 const o = self.ng.object;
11476 const pt = o.pt;
11475 const pt = self.ng.pt;
1147711476 const zcu = pt.zcu;
1147811477 const info = ptr_ty.ptrInfo(zcu);
1147911478 const elem_ty = Type.fromInterned(info.child);
......@@ -11490,7 +11489,7 @@ pub const FuncGen = struct {
1149011489 assert(info.flags.vector_index != .runtime);
1149111490 if (info.flags.vector_index != .none) {
1149211491 const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index);
11493 const vec_elem_ty = try o.lowerType(elem_ty);
11492 const vec_elem_ty = try o.lowerType(pt, elem_ty);
1149411493 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);
1149511494
1149611495 const loaded_vector = try self.wip.load(access_kind, vec_ty, ptr, ptr_alignment, "");
......@@ -11511,7 +11510,7 @@ pub const FuncGen = struct {
1151111510 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);
1151211511 const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset);
1151311512 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
11514 const elem_llvm_ty = try o.lowerType(elem_ty);
11513 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
1151511514
1151611515 if (isByRef(elem_ty, zcu)) {
1151711516 const result_align = elem_ty.abiAlignment(zcu).toLlvm();
......@@ -11546,7 +11545,7 @@ pub const FuncGen = struct {
1154611545 ordering: Builder.AtomicOrdering,
1154711546 ) !void {
1154811547 const o = self.ng.object;
11549 const pt = o.pt;
11548 const pt = self.ng.pt;
1155011549 const zcu = pt.zcu;
1155111550 const info = ptr_ty.ptrInfo(zcu);
1155211551 const elem_ty = Type.fromInterned(info.child);
......@@ -11560,7 +11559,7 @@ pub const FuncGen = struct {
1156011559 assert(info.flags.vector_index != .runtime);
1156111560 if (info.flags.vector_index != .none) {
1156211561 const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index);
11563 const vec_elem_ty = try o.lowerType(elem_ty);
11562 const vec_elem_ty = try o.lowerType(pt, elem_ty);
1156411563 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);
1156511564
1156611565 const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, "");
......@@ -11629,7 +11628,7 @@ pub const FuncGen = struct {
1162911628 ptr_alignment,
1163011629 elem,
1163111630 elem_ty.abiAlignment(zcu).toLlvm(),
11632 try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(zcu)),
11631 try o.builder.intValue(try o.lowerType(pt, Type.usize), elem_ty.abiSize(zcu)),
1163311632 access_kind,
1163411633 self.disable_intrinsics,
1163511634 );
......@@ -11638,7 +11637,8 @@ pub const FuncGen = struct {
1163811637 fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void {
1163911638 const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545;
1164011639 const o = fg.ng.object;
11641 const usize_ty = try o.lowerType(Type.usize);
11640 const pt = fg.ng.pt;
11641 const usize_ty = try o.lowerType(pt, Type.usize);
1164211642 const zero = try o.builder.intValue(usize_ty, 0);
1164311643 const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED);
1164411644 const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, "");
......@@ -11656,12 +11656,12 @@ pub const FuncGen = struct {
1165611656 a5: Builder.Value,
1165711657 ) Allocator.Error!Builder.Value {
1165811658 const o = fg.ng.object;
11659 const pt = o.pt;
11659 const pt = fg.ng.pt;
1166011660 const zcu = pt.zcu;
1166111661 const target = zcu.getTarget();
1166211662 if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value;
1166311663
11664 const llvm_usize = try o.lowerType(Type.usize);
11664 const llvm_usize = try o.lowerType(pt, Type.usize);
1166511665 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();
1166611666
1166711667 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);
......@@ -11787,14 +11787,12 @@ pub const FuncGen = struct {
1178711787 }
1178811788
1178911789 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {
11790 const o = fg.ng.object;
11791 const zcu = o.pt.zcu;
11790 const zcu = fg.ng.pt.zcu;
1179211791 return fg.air.typeOf(inst, &zcu.intern_pool);
1179311792 }
1179411793
1179511794 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {
11796 const o = fg.ng.object;
11797 const zcu = o.pt.zcu;
11795 const zcu = fg.ng.pt.zcu;
1179811796 return fg.air.typeOfIndex(inst, &zcu.intern_pool);
1179911797 }
1180011798};
......@@ -12152,40 +12150,39 @@ fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: *const std.Target) bool {
1215212150/// In order to support the C calling convention, some return types need to be lowered
1215312151/// completely differently in the function prototype to honor the C ABI, and then
1215412152/// 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;
12153fn lowerFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1215712154 const zcu = pt.zcu;
1215812155 const return_type = Type.fromInterned(fn_info.return_type);
1215912156 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
1216012157 // If the return type is an error set or an error union, then we make this
1216112158 // anyerror return type instead, so that it can be coerced into a function
1216212159 // pointer type which has anyerror as the return type.
12163 return if (return_type.isError(zcu)) try o.errorIntType() else .void;
12160 return if (return_type.isError(zcu)) try o.errorIntType(pt) else .void;
1216412161 }
1216512162 const target = zcu.getTarget();
1216612163 switch (fn_info.cc) {
1216712164 .@"inline" => unreachable,
12168 .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(return_type),
12165 .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(pt, return_type),
1216912166
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),
12167 .x86_64_sysv => return lowerSystemVFnRetTy(o, pt, fn_info),
12168 .x86_64_win => return lowerWin64FnRetTy(o, pt, fn_info),
12169 .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(pt, return_type) else .void,
12170 .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(pt, return_type),
1217412171 .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win => switch (aarch64_c_abi.classifyType(return_type, zcu)) {
1217512172 .memory => return .void,
12176 .float_array => return o.lowerType(return_type),
12177 .byval => return o.lowerType(return_type),
12173 .float_array => return o.lowerType(pt, return_type),
12174 .byval => return o.lowerType(pt, return_type),
1217812175 .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))),
1217912176 .double_integer => return o.builder.arrayType(2, .i64),
1218012177 },
1218112178 .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
1218212179 .memory, .i64_array => return .void,
1218312180 .i32_array => |len| return if (len == 1) .i32 else .void,
12184 .byval => return o.lowerType(return_type),
12181 .byval => return o.lowerType(pt, return_type),
1218512182 },
1218612183 .mips_o32 => switch (mips_c_abi.classifyType(return_type, zcu, .ret)) {
1218712184 .memory, .i32_array => return .void,
12188 .byval => return o.lowerType(return_type),
12185 .byval => return o.lowerType(pt, return_type),
1218912186 },
1219012187 .riscv64_lp64, .riscv32_ilp32 => switch (riscv_c_abi.classifyType(return_type, zcu)) {
1219112188 .memory => return .void,
......@@ -12195,53 +12192,52 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1219512192 .double_integer => {
1219612193 return o.builder.structType(.normal, &.{ .i64, .i64 });
1219712194 },
12198 .byval => return o.lowerType(return_type),
12195 .byval => return o.lowerType(pt, return_type),
1219912196 .fields => {
1220012197 var types_len: usize = 0;
1220112198 var types: [8]Builder.Type = undefined;
1220212199 for (0..return_type.structFieldCount(zcu)) |field_index| {
1220312200 const field_ty = return_type.fieldType(field_index, zcu);
1220412201 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
12205 types[types_len] = try o.lowerType(field_ty);
12202 types[types_len] = try o.lowerType(pt, field_ty);
1220612203 types_len += 1;
1220712204 }
1220812205 return o.builder.structType(.normal, types[0..types_len]);
1220912206 },
1221012207 },
1221112208 .wasm_mvp => switch (wasm_c_abi.classifyType(return_type, zcu)) {
12212 .direct => |scalar_ty| return o.lowerType(scalar_ty),
12209 .direct => |scalar_ty| return o.lowerType(pt, scalar_ty),
1221312210 .indirect => return .void,
1221412211 },
1221512212 // TODO investigate other callconvs
12216 else => return o.lowerType(return_type),
12213 else => return o.lowerType(pt, return_type),
1221712214 }
1221812215}
1221912216
12220fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12221 const zcu = o.pt.zcu;
12217fn lowerWin64FnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12218 const zcu = pt.zcu;
1222212219 const return_type = Type.fromInterned(fn_info.return_type);
1222312220 switch (x86_64_abi.classifyWindows(return_type, zcu, zcu.getTarget())) {
1222412221 .integer => {
1222512222 if (isScalar(zcu, return_type)) {
12226 return o.lowerType(return_type);
12223 return o.lowerType(pt, return_type);
1222712224 } else {
1222812225 return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8));
1222912226 }
1223012227 },
1223112228 .win_i128 => return o.builder.vectorType(.normal, 2, .i64),
1223212229 .memory => return .void,
12233 .sse => return o.lowerType(return_type),
12230 .sse => return o.lowerType(pt, return_type),
1223412231 else => unreachable,
1223512232 }
1223612233}
1223712234
12238fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12239 const pt = o.pt;
12235fn lowerSystemVFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1224012236 const zcu = pt.zcu;
1224112237 const ip = &zcu.intern_pool;
1224212238 const return_type = Type.fromInterned(fn_info.return_type);
1224312239 if (isScalar(zcu, return_type)) {
12244 return o.lowerType(return_type);
12240 return o.lowerType(pt, return_type);
1224512241 }
1224612242 const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret);
1224712243 var types_index: u32 = 0;
......@@ -12305,6 +12301,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
1230512301
1230612302const ParamTypeIterator = struct {
1230712303 object: *Object,
12304 pt: Zcu.PerThread,
1230812305 fn_info: InternPool.Key.FuncType,
1230912306 zig_index: u32,
1231012307 llvm_index: u32,
......@@ -12327,7 +12324,7 @@ const ParamTypeIterator = struct {
1232712324
1232812325 pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering {
1232912326 if (it.zig_index >= it.fn_info.param_types.len) return null;
12330 const ip = &it.object.pt.zcu.intern_pool;
12327 const ip = &it.pt.zcu.intern_pool;
1233112328 const ty = it.fn_info.param_types.get(ip)[it.zig_index];
1233212329 it.byval_attr = false;
1233312330 return nextInner(it, Type.fromInterned(ty));
......@@ -12335,7 +12332,8 @@ const ParamTypeIterator = struct {
1233512332
1233612333 /// `airCall` uses this instead of `next` so that it can take into account variadic functions.
1233712334 pub fn nextCall(it: *ParamTypeIterator, fg: *FuncGen, args: []const Air.Inst.Ref) Allocator.Error!?Lowering {
12338 const ip = &it.object.pt.zcu.intern_pool;
12335 assert(std.meta.eql(it.pt, fg.ng.pt));
12336 const ip = &it.pt.zcu.intern_pool;
1233912337 if (it.zig_index >= it.fn_info.param_types.len) {
1234012338 if (it.zig_index >= args.len) {
1234112339 return null;
......@@ -12348,7 +12346,7 @@ const ParamTypeIterator = struct {
1234812346 }
1234912347
1235012348 fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
12351 const pt = it.object.pt;
12349 const pt = it.pt;
1235212350 const zcu = pt.zcu;
1235312351 const target = zcu.getTarget();
1235412352
......@@ -12448,7 +12446,7 @@ const ParamTypeIterator = struct {
1244812446 for (0..ty.structFieldCount(zcu)) |field_index| {
1244912447 const field_ty = ty.fieldType(field_index, zcu);
1245012448 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
12451 it.types_buffer[it.types_len] = try it.object.lowerType(field_ty);
12449 it.types_buffer[it.types_len] = try it.object.lowerType(pt, field_ty);
1245212450 it.types_len += 1;
1245312451 }
1245412452 it.llvm_index += it.types_len - 1;
......@@ -12464,7 +12462,7 @@ const ParamTypeIterator = struct {
1246412462 return .byval;
1246512463 } else {
1246612464 var types_buffer: [8]Builder.Type = undefined;
12467 types_buffer[0] = try it.object.lowerType(scalar_ty);
12465 types_buffer[0] = try it.object.lowerType(pt, scalar_ty);
1246812466 it.types_buffer = types_buffer;
1246912467 it.types_len = 1;
1247012468 it.llvm_index += 1;
......@@ -12489,7 +12487,7 @@ const ParamTypeIterator = struct {
1248912487 }
1249012488
1249112489 fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering {
12492 const zcu = it.object.pt.zcu;
12490 const zcu = it.pt.zcu;
1249312491 switch (x86_64_abi.classifyWindows(ty, zcu, zcu.getTarget())) {
1249412492 .integer => {
1249512493 if (isScalar(zcu, ty)) {
......@@ -12522,7 +12520,7 @@ const ParamTypeIterator = struct {
1252212520 }
1252312521
1252412522 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
12525 const zcu = it.object.pt.zcu;
12523 const zcu = it.pt.zcu;
1252612524 const ip = &zcu.intern_pool;
1252712525 const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg);
1252812526 if (classes[0] == .memory) {
......@@ -12615,9 +12613,10 @@ const ParamTypeIterator = struct {
1261512613 }
1261612614};
1261712615
12618fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTypeIterator {
12616fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) ParamTypeIterator {
1261912617 return .{
1262012618 .object = object,
12619 .pt = pt,
1262112620 .fn_info = fn_info,
1262212621 .zig_index = 0,
1262312622 .llvm_index = 0,