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(...@@ -3042,7 +3042,7 @@ fn flush(
3042 // If there's an output file, it wants to decide where the LLVM object goes!3042 // If there's an output file, it wants to decide where the LLVM object goes!
3043 const sub_prog_node = comp.link_prog_node.start("LLVM Emit Object", 0);3043 const sub_prog_node = comp.link_prog_node.start("LLVM Emit Object", 0);
3044 defer sub_prog_node.end();3044 defer sub_prog_node.end();
3045 try llvm_object.emit(.{3045 try llvm_object.emit(.{ .zcu = zcu, .tid = tid }, .{
3046 .pre_ir_path = comp.verbose_llvm_ir,3046 .pre_ir_path = comp.verbose_llvm_ir,
3047 .pre_bc_path = comp.verbose_llvm_bc,3047 .pre_bc_path = comp.verbose_llvm_bc,
30483048
src/Sema.zig-11
...@@ -9705,7 +9705,6 @@ fn funcCommon(...@@ -9705,7 +9705,6 @@ fn funcCommon(
9705 func_inst,9705 func_inst,
9706 cc_src,9706 cc_src,
9707 is_noinline,9707 is_noinline,
9708 is_generic,
9709 );9708 );
9710 }9709 }
97119710
...@@ -9745,7 +9744,6 @@ fn funcCommon(...@@ -9745,7 +9744,6 @@ fn funcCommon(
9745 func_inst,9744 func_inst,
9746 cc_src,9745 cc_src,
9747 is_noinline,9746 is_noinline,
9748 is_generic,
9749 );9747 );
9750 }9748 }
97519749
...@@ -9762,7 +9760,6 @@ fn funcCommon(...@@ -9762,7 +9760,6 @@ fn funcCommon(
9762 func_inst,9760 func_inst,
9763 cc_src,9761 cc_src,
9764 is_noinline,9762 is_noinline,
9765 is_generic,
9766 );9763 );
9767}9764}
97689765
...@@ -9779,7 +9776,6 @@ fn finishFunc(...@@ -9779,7 +9776,6 @@ fn finishFunc(
9779 func_inst: Zir.Inst.Index,9776 func_inst: Zir.Inst.Index,
9780 cc_src: LazySrcLoc,9777 cc_src: LazySrcLoc,
9781 is_noinline: bool,9778 is_noinline: bool,
9782 is_generic: bool,
9783) CompileError!Air.Inst.Ref {9779) CompileError!Air.Inst.Ref {
9784 const pt = sema.pt;9780 const pt = sema.pt;
9785 const zcu = pt.zcu;9781 const zcu = pt.zcu;
...@@ -9911,13 +9907,6 @@ fn finishFunc(...@@ -9911,13 +9907,6 @@ fn finishFunc(
9911 }),9907 }),
9912 }9908 }
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
9921 return Air.internedToRef(if (opt_func_index != .none) opt_func_index else func_ty);9910 return Air.internedToRef(if (opt_func_index != .none) opt_func_index else func_ty);
9922}9911}
99239912
src/codegen/llvm.zig+609-610
...@@ -494,8 +494,6 @@ pub const Object = struct {...@@ -494,8 +494,6 @@ pub const Object = struct {
494 gpa: Allocator,494 gpa: Allocator,
495 builder: Builder,495 builder: Builder,
496496
497 pt: Zcu.PerThread,
498
499 debug_compile_unit: Builder.Metadata,497 debug_compile_unit: Builder.Metadata,
500498
501 debug_enums_fwd_ref: Builder.Metadata,499 debug_enums_fwd_ref: Builder.Metadata,
...@@ -626,10 +624,6 @@ pub const Object = struct {...@@ -626,10 +624,6 @@ pub const Object = struct {
626 obj.* = .{624 obj.* = .{
627 .gpa = gpa,625 .gpa = gpa,
628 .builder = builder,626 .builder = builder,
629 .pt = .{
630 .zcu = comp.zcu.?,
631 .tid = .main,
632 },
633 .debug_compile_unit = debug_compile_unit,627 .debug_compile_unit = debug_compile_unit,
634 .debug_enums_fwd_ref = debug_enums_fwd_ref,628 .debug_enums_fwd_ref = debug_enums_fwd_ref,
635 .debug_globals_fwd_ref = debug_globals_fwd_ref,629 .debug_globals_fwd_ref = debug_globals_fwd_ref,
...@@ -669,11 +663,10 @@ pub const Object = struct {...@@ -669,11 +663,10 @@ pub const Object = struct {
669 self.* = undefined;663 self.* = undefined;
670 }664 }
671665
672 fn genErrorNameTable(o: *Object) Allocator.Error!void {666 fn genErrorNameTable(o: *Object, pt: Zcu.PerThread) Allocator.Error!void {
673 // If o.error_name_table is null, then it was not referenced by any instructions.667 // If o.error_name_table is null, then it was not referenced by any instructions.
674 if (o.error_name_table == .none) return;668 if (o.error_name_table == .none) return;
675669
676 const pt = o.pt;
677 const zcu = pt.zcu;670 const zcu = pt.zcu;
678 const ip = &zcu.intern_pool;671 const ip = &zcu.intern_pool;
679672
...@@ -683,8 +676,8 @@ pub const Object = struct {...@@ -683,8 +676,8 @@ pub const Object = struct {
683676
684 // TODO: Address space677 // TODO: Address space
685 const slice_ty = Type.slice_const_u8_sentinel_0;678 const slice_ty = Type.slice_const_u8_sentinel_0;
686 const llvm_usize_ty = try o.lowerType(Type.usize);679 const llvm_usize_ty = try o.lowerType(pt, Type.usize);
687 const llvm_slice_ty = try o.lowerType(slice_ty);680 const llvm_slice_ty = try o.lowerType(pt, slice_ty);
688 const llvm_table_ty = try o.builder.arrayType(1 + error_name_list.len, llvm_slice_ty);681 const llvm_table_ty = try o.builder.arrayType(1 + error_name_list.len, llvm_slice_ty);
689682
690 llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty);683 llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty);
...@@ -721,11 +714,11 @@ pub const Object = struct {...@@ -721,11 +714,11 @@ pub const Object = struct {
721 try o.error_name_table.setInitializer(table_variable_index.toConst(&o.builder), &o.builder);714 try o.error_name_table.setInitializer(table_variable_index.toConst(&o.builder), &o.builder);
722 }715 }
723716
724 fn genCmpLtErrorsLenFunction(o: *Object) !void {717 fn genCmpLtErrorsLenFunction(o: *Object, pt: Zcu.PerThread) !void {
725 // If there is no such function in the module, it means the source code does not need it.718 // If there is no such function in the module, it means the source code does not need it.
726 const name = o.builder.strtabStringIfExists(lt_errors_fn_name) orelse return;719 const name = o.builder.strtabStringIfExists(lt_errors_fn_name) orelse return;
727 const llvm_fn = o.builder.getGlobal(name) orelse return;720 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
730 var wip = try Builder.WipFunction.init(&o.builder, .{723 var wip = try Builder.WipFunction.init(&o.builder, .{
731 .function = llvm_fn.ptrConst(&o.builder).kind.function,724 .function = llvm_fn.ptrConst(&o.builder).kind.function,
...@@ -740,17 +733,17 @@ pub const Object = struct {...@@ -740,17 +733,17 @@ pub const Object = struct {
740 // }733 // }
741734
742 const lhs = wip.arg(0);735 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);
744 const is_lt = try wip.icmp(.ule, lhs, rhs, "");737 const is_lt = try wip.icmp(.ule, lhs, rhs, "");
745 _ = try wip.ret(is_lt);738 _ = try wip.ret(is_lt);
746 try wip.finish();739 try wip.finish();
747 }740 }
748741
749 fn genModuleLevelAssembly(object: *Object) Allocator.Error!void {742 fn genModuleLevelAssembly(object: *Object, pt: Zcu.PerThread) Allocator.Error!void {
750 const b = &object.builder;743 const b = &object.builder;
751 const gpa = b.gpa;744 const gpa = b.gpa;
752 b.module_asm.clearRetainingCapacity();745 b.module_asm.clearRetainingCapacity();
753 for (object.pt.zcu.global_assembly.values()) |assembly| {746 for (pt.zcu.global_assembly.values()) |assembly| {
754 try b.module_asm.ensureUnusedCapacity(gpa, assembly.len + 1);747 try b.module_asm.ensureUnusedCapacity(gpa, assembly.len + 1);
755 b.module_asm.appendSliceAssumeCapacity(assembly);748 b.module_asm.appendSliceAssumeCapacity(assembly);
756 b.module_asm.appendAssumeCapacity('\n');749 b.module_asm.appendAssumeCapacity('\n');
...@@ -776,15 +769,15 @@ pub const Object = struct {...@@ -776,15 +769,15 @@ pub const Object = struct {
776 lto: std.zig.LtoMode,769 lto: std.zig.LtoMode,
777 };770 };
778771
779 pub fn emit(o: *Object, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void {772 pub fn emit(o: *Object, pt: Zcu.PerThread, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void {
780 const zcu = o.pt.zcu;773 const zcu = pt.zcu;
781 const comp = zcu.comp;774 const comp = zcu.comp;
782 const diags = &comp.link_diags;775 const diags = &comp.link_diags;
783776
784 {777 {
785 try o.genErrorNameTable();778 try o.genErrorNameTable(pt);
786 try o.genCmpLtErrorsLenFunction();779 try o.genCmpLtErrorsLenFunction(pt);
787 try o.genModuleLevelAssembly();780 try o.genModuleLevelAssembly(pt);
788781
789 if (o.used.items.len > 0) {782 if (o.used.items.len > 0) {
790 const array_llvm_ty = try o.builder.arrayType(o.used.items.len, .ptr);783 const array_llvm_ty = try o.builder.arrayType(o.used.items.len, .ptr);
...@@ -807,7 +800,7 @@ pub const Object = struct {...@@ -807,7 +800,7 @@ pub const Object = struct {
807 const fwd_ref = o.debug_unresolved_namespace_scopes.values()[i];800 const fwd_ref = o.debug_unresolved_namespace_scopes.values()[i];
808801
809 const namespace = zcu.namespacePtr(namespace_index);802 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
812 o.builder.debugForwardReferenceSetType(fwd_ref, debug_type);805 o.builder.debugForwardReferenceSetType(fwd_ref, debug_type);
813 }806 }
...@@ -1140,7 +1133,6 @@ pub const Object = struct {...@@ -1140,7 +1133,6 @@ pub const Object = struct {
1140 air: *const Air,1133 air: *const Air,
1141 liveness: *const Air.Liveness,1134 liveness: *const Air.Liveness,
1142 ) !void {1135 ) !void {
1143 assert(std.meta.eql(pt, o.pt));
1144 const zcu = pt.zcu;1136 const zcu = pt.zcu;
1145 const comp = zcu.comp;1137 const comp = zcu.comp;
1146 const ip = &zcu.intern_pool;1138 const ip = &zcu.intern_pool;
...@@ -1155,10 +1147,11 @@ pub const Object = struct {...@@ -1155,10 +1147,11 @@ pub const Object = struct {
1155 var ng: NavGen = .{1147 var ng: NavGen = .{
1156 .object = o,1148 .object = o,
1157 .nav_index = func.owner_nav,1149 .nav_index = func.owner_nav,
1150 .pt = pt,
1158 .err_msg = null,1151 .err_msg = null,
1159 };1152 };
11601153
1161 const function_index = try o.resolveLlvmFunction(func.owner_nav);1154 const function_index = try o.resolveLlvmFunction(pt, func.owner_nav);
11621155
1163 var attributes = try function_index.ptrConst(&o.builder).attributes.toWip(&o.builder);1156 var attributes = try function_index.ptrConst(&o.builder).attributes.toWip(&o.builder);
1164 defer attributes.deinit(&o.builder);1157 defer attributes.deinit(&o.builder);
...@@ -1272,7 +1265,7 @@ pub const Object = struct {...@@ -1272,7 +1265,7 @@ pub const Object = struct {
1272 defer args.deinit(gpa);1265 defer args.deinit(gpa);
12731266
1274 {1267 {
1275 var it = iterateParamTypes(o, fn_info);1268 var it = iterateParamTypes(o, pt, fn_info);
1276 while (try it.next()) |lowering| {1269 while (try it.next()) |lowering| {
1277 try args.ensureUnusedCapacity(gpa, 1);1270 try args.ensureUnusedCapacity(gpa, 1);
12781271
...@@ -1293,13 +1286,13 @@ pub const Object = struct {...@@ -1293,13 +1286,13 @@ pub const Object = struct {
1293 } else {1286 } else {
1294 args.appendAssumeCapacity(param);1287 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);
1297 }1290 }
1298 llvm_arg_i += 1;1291 llvm_arg_i += 1;
1299 },1292 },
1300 .byref => {1293 .byref => {
1301 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);1294 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);
1303 const param = wip.arg(llvm_arg_i);1296 const param = wip.arg(llvm_arg_i);
1304 const alignment = param_ty.abiAlignment(zcu).toLlvm();1297 const alignment = param_ty.abiAlignment(zcu).toLlvm();
13051298
...@@ -1314,7 +1307,7 @@ pub const Object = struct {...@@ -1314,7 +1307,7 @@ pub const Object = struct {
1314 },1307 },
1315 .byref_mut => {1308 .byref_mut => {
1316 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);1309 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);
1318 const param = wip.arg(llvm_arg_i);1311 const param = wip.arg(llvm_arg_i);
1319 const alignment = param_ty.abiAlignment(zcu).toLlvm();1312 const alignment = param_ty.abiAlignment(zcu).toLlvm();
13201313
...@@ -1333,7 +1326,7 @@ pub const Object = struct {...@@ -1333,7 +1326,7 @@ pub const Object = struct {
1333 const param = wip.arg(llvm_arg_i);1326 const param = wip.arg(llvm_arg_i);
1334 llvm_arg_i += 1;1327 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);
1337 const alignment = param_ty.abiAlignment(zcu).toLlvm();1330 const alignment = param_ty.abiAlignment(zcu).toLlvm();
1338 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);1331 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);
1339 _ = try wip.store(.normal, param, arg_ptr, alignment);1332 _ = try wip.store(.normal, param, arg_ptr, alignment);
...@@ -1372,7 +1365,7 @@ pub const Object = struct {...@@ -1372,7 +1365,7 @@ pub const Object = struct {
1372 const len_param = wip.arg(llvm_arg_i);1365 const len_param = wip.arg(llvm_arg_i);
1373 llvm_arg_i += 1;1366 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);
1376 args.appendAssumeCapacity(1369 args.appendAssumeCapacity(
1377 try wip.buildAggregate(slice_llvm_ty, &.{ ptr_param, len_param }, ""),1370 try wip.buildAggregate(slice_llvm_ty, &.{ ptr_param, len_param }, ""),
1378 );1371 );
...@@ -1381,7 +1374,7 @@ pub const Object = struct {...@@ -1381,7 +1374,7 @@ pub const Object = struct {
1381 assert(!it.byval_attr);1374 assert(!it.byval_attr);
1382 const field_types = it.types_buffer[0..it.types_len];1375 const field_types = it.types_buffer[0..it.types_len];
1383 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);1376 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);
1385 const param_alignment = param_ty.abiAlignment(zcu).toLlvm();1378 const param_alignment = param_ty.abiAlignment(zcu).toLlvm();
1386 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, param_alignment, target);1379 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, param_alignment, target);
1387 const llvm_ty = try o.builder.structType(.normal, field_types);1380 const llvm_ty = try o.builder.structType(.normal, field_types);
...@@ -1402,7 +1395,7 @@ pub const Object = struct {...@@ -1402,7 +1395,7 @@ pub const Object = struct {
1402 },1395 },
1403 .float_array => {1396 .float_array => {
1404 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);1397 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);
1406 const param = wip.arg(llvm_arg_i);1399 const param = wip.arg(llvm_arg_i);
1407 llvm_arg_i += 1;1400 llvm_arg_i += 1;
14081401
...@@ -1417,7 +1410,7 @@ pub const Object = struct {...@@ -1417,7 +1410,7 @@ pub const Object = struct {
1417 },1410 },
1418 .i32_array, .i64_array => {1411 .i32_array, .i64_array => {
1419 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);1412 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);
1421 const param = wip.arg(llvm_arg_i);1414 const param = wip.arg(llvm_arg_i);
1422 llvm_arg_i += 1;1415 llvm_arg_i += 1;
14231416
...@@ -1435,11 +1428,11 @@ pub const Object = struct {...@@ -1435,11 +1428,11 @@ pub const Object = struct {
1435 }1428 }
14361429
1437 const file, const subprogram = if (!wip.strip) debug_info: {1430 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
1440 const line_number = zcu.navSrcLine(func.owner_nav) + 1;1433 const line_number = zcu.navSrcLine(func.owner_nav) + 1;
1441 const is_internal_linkage = ip.indexToKey(nav.status.fully_resolved.val) != .@"extern";1434 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
1444 const subprogram = try o.builder.debugSubprogram(1437 const subprogram = try o.builder.debugSubprogram(
1445 file,1438 file,
...@@ -1569,10 +1562,10 @@ pub const Object = struct {...@@ -1569,10 +1562,10 @@ pub const Object = struct {
1569 }1562 }
15701563
1571 pub fn updateNav(self: *Object, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !void {1564 pub fn updateNav(self: *Object, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !void {
1572 assert(std.meta.eql(pt, self.pt));
1573 var ng: NavGen = .{1565 var ng: NavGen = .{
1574 .object = self,1566 .object = self,
1575 .nav_index = nav_index,1567 .nav_index = nav_index,
1568 .pt = pt,
1576 .err_msg = null,1569 .err_msg = null,
1577 };1570 };
1578 ng.genDecl() catch |err| switch (err) {1571 ng.genDecl() catch |err| switch (err) {
...@@ -1590,11 +1583,10 @@ pub const Object = struct {...@@ -1590,11 +1583,10 @@ pub const Object = struct {
1590 exported: Zcu.Exported,1583 exported: Zcu.Exported,
1591 export_indices: []const Zcu.Export.Index,1584 export_indices: []const Zcu.Export.Index,
1592 ) link.File.UpdateExportsError!void {1585 ) link.File.UpdateExportsError!void {
1593 assert(std.meta.eql(pt, self.pt));
1594 const zcu = pt.zcu;1586 const zcu = pt.zcu;
1595 const nav_index = switch (exported) {1587 const nav_index = switch (exported) {
1596 .nav => |nav| nav,1588 .nav => |nav| nav,
1597 .uav => |uav| return updateExportedValue(self, zcu, uav, export_indices),1589 .uav => |uav| return updateExportedValue(self, pt, uav, export_indices),
1598 };1590 };
1599 const ip = &zcu.intern_pool;1591 const ip = &zcu.intern_pool;
1600 const global_index = self.nav_map.get(nav_index).?;1592 const global_index = self.nav_map.get(nav_index).?;
...@@ -1635,10 +1627,11 @@ pub const Object = struct {...@@ -1635,10 +1627,11 @@ pub const Object = struct {
16351627
1636 fn updateExportedValue(1628 fn updateExportedValue(
1637 o: *Object,1629 o: *Object,
1638 zcu: *Zcu,1630 pt: Zcu.PerThread,
1639 exported_value: InternPool.Index,1631 exported_value: InternPool.Index,
1640 export_indices: []const Zcu.Export.Index,1632 export_indices: []const Zcu.Export.Index,
1641 ) link.File.UpdateExportsError!void {1633 ) link.File.UpdateExportsError!void {
1634 const zcu = pt.zcu;
1642 const gpa = zcu.gpa;1635 const gpa = zcu.gpa;
1643 const ip = &zcu.intern_pool;1636 const ip = &zcu.intern_pool;
1644 const main_exp_name = try o.builder.strtabString(export_indices[0].ptr(zcu).opts.name.toSlice(ip));1637 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 {...@@ -1652,13 +1645,13 @@ pub const Object = struct {
1652 const llvm_addr_space = toLlvmAddressSpace(.generic, o.target);1645 const llvm_addr_space = toLlvmAddressSpace(.generic, o.target);
1653 const variable_index = try o.builder.addVariable(1646 const variable_index = try o.builder.addVariable(
1654 main_exp_name,1647 main_exp_name,
1655 try o.lowerType(Type.fromInterned(ip.typeOf(exported_value))),1648 try o.lowerType(pt, Type.fromInterned(ip.typeOf(exported_value))),
1656 llvm_addr_space,1649 llvm_addr_space,
1657 );1650 );
1658 const global_index = variable_index.ptrConst(&o.builder).global;1651 const global_index = variable_index.ptrConst(&o.builder).global;
1659 gop.value_ptr.* = global_index;1652 gop.value_ptr.* = global_index;
1660 // This line invalidates `gop`.1653 // 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) {
1662 error.OutOfMemory => return error.OutOfMemory,1655 error.OutOfMemory => return error.OutOfMemory,
1663 error.CodegenFail => return error.AnalysisFail,1656 error.CodegenFail => return error.AnalysisFail,
1664 };1657 };
...@@ -1761,14 +1754,13 @@ pub const Object = struct {...@@ -1761,14 +1754,13 @@ pub const Object = struct {
1761 }1754 }
1762 }1755 }
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 {
1765 const gpa = o.gpa;1758 const gpa = o.gpa;
1766 const gop = try o.debug_file_map.getOrPut(gpa, file_index);1759 const gop = try o.debug_file_map.getOrPut(gpa, file_index);
1767 errdefer assert(o.debug_file_map.remove(file_index));1760 errdefer assert(o.debug_file_map.remove(file_index));
1768 if (gop.found_existing) return gop.value_ptr.*;1761 if (gop.found_existing) return gop.value_ptr.*;
1769 const zcu = o.pt.zcu;1762 const path = pt.zcu.fileByIndex(file_index).path;
1770 const path = zcu.fileByIndex(file_index).path;1763 const abs_path = try path.toAbsolute(pt.zcu.comp.dirs, gpa);
1771 const abs_path = try path.toAbsolute(zcu.comp.dirs, gpa);
1772 defer gpa.free(abs_path);1764 defer gpa.free(abs_path);
17731765
1774 gop.value_ptr.* = try o.builder.debugFile(1766 gop.value_ptr.* = try o.builder.debugFile(
...@@ -1780,13 +1772,13 @@ pub const Object = struct {...@@ -1780,13 +1772,13 @@ pub const Object = struct {
17801772
1781 pub fn lowerDebugType(1773 pub fn lowerDebugType(
1782 o: *Object,1774 o: *Object,
1775 pt: Zcu.PerThread,
1783 ty: Type,1776 ty: Type,
1784 ) Allocator.Error!Builder.Metadata {1777 ) Allocator.Error!Builder.Metadata {
1785 assert(!o.builder.strip);1778 assert(!o.builder.strip);
17861779
1787 const gpa = o.gpa;1780 const gpa = o.gpa;
1788 const target = o.target;1781 const target = o.target;
1789 const pt = o.pt;
1790 const zcu = pt.zcu;1782 const zcu = pt.zcu;
1791 const ip = &zcu.intern_pool;1783 const ip = &zcu.intern_pool;
17921784
...@@ -1806,7 +1798,7 @@ pub const Object = struct {...@@ -1806,7 +1798,7 @@ pub const Object = struct {
1806 .int => {1798 .int => {
1807 const info = ty.intInfo(zcu);1799 const info = ty.intInfo(zcu);
1808 assert(info.bits != 0);1800 assert(info.bits != 0);
1809 const name = try o.allocTypeName(ty);1801 const name = try o.allocTypeName(pt, ty);
1810 defer gpa.free(name);1802 defer gpa.free(name);
1811 const builder_name = try o.builder.metadataString(name);1803 const builder_name = try o.builder.metadataString(name);
1812 const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types1804 const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types
...@@ -1819,7 +1811,7 @@ pub const Object = struct {...@@ -1819,7 +1811,7 @@ pub const Object = struct {
1819 },1811 },
1820 .@"enum" => {1812 .@"enum" => {
1821 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {1813 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1822 const debug_enum_type = try o.makeEmptyNamespaceDebugType(ty);1814 const debug_enum_type = try o.makeEmptyNamespaceDebugType(pt, ty);
1823 try o.debug_type_map.put(gpa, ty, debug_enum_type);1815 try o.debug_type_map.put(gpa, ty, debug_enum_type);
1824 return debug_enum_type;1816 return debug_enum_type;
1825 }1817 }
...@@ -1847,13 +1839,13 @@ pub const Object = struct {...@@ -1847,13 +1839,13 @@ pub const Object = struct {
1847 );1839 );
1848 }1840 }
18491841
1850 const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));1842 const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip));
1851 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|1843 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|
1852 try o.namespaceToDebugScope(parent_namespace)1844 try o.namespaceToDebugScope(pt, parent_namespace)
1853 else1845 else
1854 file;1846 file;
18551847
1856 const name = try o.allocTypeName(ty);1848 const name = try o.allocTypeName(pt, ty);
1857 defer gpa.free(name);1849 defer gpa.free(name);
18581850
1859 const debug_enum_type = try o.builder.debugEnumerationType(1851 const debug_enum_type = try o.builder.debugEnumerationType(
...@@ -1861,7 +1853,7 @@ pub const Object = struct {...@@ -1861,7 +1853,7 @@ pub const Object = struct {
1861 file,1853 file,
1862 scope,1854 scope,
1863 ty.typeDeclSrcLine(zcu).? + 1, // Line1855 ty.typeDeclSrcLine(zcu).? + 1, // Line
1864 try o.lowerDebugType(int_ty),1856 try o.lowerDebugType(pt, int_ty),
1865 ty.abiSize(zcu) * 8,1857 ty.abiSize(zcu) * 8,
1866 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,1858 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
1867 try o.builder.metadataTuple(enumerators),1859 try o.builder.metadataTuple(enumerators),
...@@ -1873,7 +1865,7 @@ pub const Object = struct {...@@ -1873,7 +1865,7 @@ pub const Object = struct {
1873 },1865 },
1874 .float => {1866 .float => {
1875 const bits = ty.floatBits(target);1867 const bits = ty.floatBits(target);
1876 const name = try o.allocTypeName(ty);1868 const name = try o.allocTypeName(pt, ty);
1877 defer gpa.free(name);1869 defer gpa.free(name);
1878 const debug_float_type = try o.builder.debugFloatType(1870 const debug_float_type = try o.builder.debugFloatType(
1879 try o.builder.metadataString(name),1871 try o.builder.metadataString(name),
...@@ -1918,7 +1910,7 @@ pub const Object = struct {...@@ -1918,7 +1910,7 @@ pub const Object = struct {
1918 },1910 },
1919 },1911 },
1920 });1912 });
1921 const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty);1913 const debug_ptr_type = try o.lowerDebugType(pt, bland_ptr_ty);
1922 try o.debug_type_map.put(gpa, ty, debug_ptr_type);1914 try o.debug_type_map.put(gpa, ty, debug_ptr_type);
1923 return debug_ptr_type;1915 return debug_ptr_type;
1924 }1916 }
...@@ -1932,7 +1924,7 @@ pub const Object = struct {...@@ -1932,7 +1924,7 @@ pub const Object = struct {
1932 const ptr_ty = ty.slicePtrFieldType(zcu);1924 const ptr_ty = ty.slicePtrFieldType(zcu);
1933 const len_ty = Type.usize;1925 const len_ty = Type.usize;
19341926
1935 const name = try o.allocTypeName(ty);1927 const name = try o.allocTypeName(pt, ty);
1936 defer gpa.free(name);1928 defer gpa.free(name);
1937 const line = 0;1929 const line = 0;
19381930
...@@ -1948,7 +1940,7 @@ pub const Object = struct {...@@ -1948,7 +1940,7 @@ pub const Object = struct {
1948 .none, // File1940 .none, // File
1949 debug_fwd_ref,1941 debug_fwd_ref,
1950 0, // Line1942 0, // Line
1951 try o.lowerDebugType(ptr_ty),1943 try o.lowerDebugType(pt, ptr_ty),
1952 ptr_size * 8,1944 ptr_size * 8,
1953 (ptr_align.toByteUnits() orelse 0) * 8,1945 (ptr_align.toByteUnits() orelse 0) * 8,
1954 0, // Offset1946 0, // Offset
...@@ -1959,7 +1951,7 @@ pub const Object = struct {...@@ -1959,7 +1951,7 @@ pub const Object = struct {
1959 .none, // File1951 .none, // File
1960 debug_fwd_ref,1952 debug_fwd_ref,
1961 0, // Line1953 0, // Line
1962 try o.lowerDebugType(len_ty),1954 try o.lowerDebugType(pt, len_ty),
1963 len_size * 8,1955 len_size * 8,
1964 (len_align.toByteUnits() orelse 0) * 8,1956 (len_align.toByteUnits() orelse 0) * 8,
1965 len_offset * 8,1957 len_offset * 8,
...@@ -1988,9 +1980,9 @@ pub const Object = struct {...@@ -1988,9 +1980,9 @@ pub const Object = struct {
1988 return debug_slice_type;1980 return debug_slice_type;
1989 }1981 }
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);
1994 defer gpa.free(name);1986 defer gpa.free(name);
19951987
1996 const debug_ptr_type = try o.builder.debugPointerType(1988 const debug_ptr_type = try o.builder.debugPointerType(
...@@ -2022,12 +2014,12 @@ pub const Object = struct {...@@ -2022,12 +2014,12 @@ pub const Object = struct {
2022 return debug_opaque_type;2014 return debug_opaque_type;
2023 }2015 }
20242016
2025 const name = try o.allocTypeName(ty);2017 const name = try o.allocTypeName(pt, ty);
2026 defer gpa.free(name);2018 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));
2029 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|2021 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|
2030 try o.namespaceToDebugScope(parent_namespace)2022 try o.namespaceToDebugScope(pt, parent_namespace)
2031 else2023 else
2032 file;2024 file;
20332025
...@@ -2050,7 +2042,7 @@ pub const Object = struct {...@@ -2050,7 +2042,7 @@ pub const Object = struct {
2050 .none, // File2042 .none, // File
2051 .none, // Scope2043 .none, // Scope
2052 0, // Line2044 0, // Line
2053 try o.lowerDebugType(ty.childType(zcu)),2045 try o.lowerDebugType(pt, ty.childType(zcu)),
2054 ty.abiSize(zcu) * 8,2046 ty.abiSize(zcu) * 8,
2055 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,2047 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2056 try o.builder.metadataTuple(&.{2048 try o.builder.metadataTuple(&.{
...@@ -2073,7 +2065,7 @@ pub const Object = struct {...@@ -2073,7 +2065,7 @@ pub const Object = struct {
2073 .int => blk: {2065 .int => blk: {
2074 const info = elem_ty.intInfo(zcu);2066 const info = elem_ty.intInfo(zcu);
2075 assert(info.bits != 0);2067 assert(info.bits != 0);
2076 const name = try o.allocTypeName(ty);2068 const name = try o.allocTypeName(pt, ty);
2077 defer gpa.free(name);2069 defer gpa.free(name);
2078 const builder_name = try o.builder.metadataString(name);2070 const builder_name = try o.builder.metadataString(name);
2079 break :blk switch (info.signedness) {2071 break :blk switch (info.signedness) {
...@@ -2085,7 +2077,7 @@ pub const Object = struct {...@@ -2085,7 +2077,7 @@ pub const Object = struct {
2085 try o.builder.metadataString("bool"),2077 try o.builder.metadataString("bool"),
2086 1,2078 1,
2087 ),2079 ),
2088 else => try o.lowerDebugType(ty.childType(zcu)),2080 else => try o.lowerDebugType(pt, ty.childType(zcu)),
2089 };2081 };
20902082
2091 const debug_vector_type = try o.builder.debugVectorType(2083 const debug_vector_type = try o.builder.debugVectorType(
...@@ -2108,7 +2100,7 @@ pub const Object = struct {...@@ -2108,7 +2100,7 @@ pub const Object = struct {
2108 return debug_vector_type;2100 return debug_vector_type;
2109 },2101 },
2110 .optional => {2102 .optional => {
2111 const name = try o.allocTypeName(ty);2103 const name = try o.allocTypeName(pt, ty);
2112 defer gpa.free(name);2104 defer gpa.free(name);
2113 const child_ty = ty.optionalChild(zcu);2105 const child_ty = ty.optionalChild(zcu);
2114 if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) {2106 if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
...@@ -2126,7 +2118,7 @@ pub const Object = struct {...@@ -2126,7 +2118,7 @@ pub const Object = struct {
2126 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);2118 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
21272119
2128 if (ty.optionalReprIsPayload(zcu)) {2120 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
2131 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);2123 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
21322124
...@@ -2149,7 +2141,7 @@ pub const Object = struct {...@@ -2149,7 +2141,7 @@ pub const Object = struct {
2149 .none, // File2141 .none, // File
2150 debug_fwd_ref,2142 debug_fwd_ref,
2151 0, // Line2143 0, // Line
2152 try o.lowerDebugType(child_ty),2144 try o.lowerDebugType(pt, child_ty),
2153 payload_size * 8,2145 payload_size * 8,
2154 (payload_align.toByteUnits() orelse 0) * 8,2146 (payload_align.toByteUnits() orelse 0) * 8,
2155 0, // Offset2147 0, // Offset
...@@ -2160,7 +2152,7 @@ pub const Object = struct {...@@ -2160,7 +2152,7 @@ pub const Object = struct {
2160 .none,2152 .none,
2161 debug_fwd_ref,2153 debug_fwd_ref,
2162 0,2154 0,
2163 try o.lowerDebugType(non_null_ty),2155 try o.lowerDebugType(pt, non_null_ty),
2164 non_null_size * 8,2156 non_null_size * 8,
2165 (non_null_align.toByteUnits() orelse 0) * 8,2157 (non_null_align.toByteUnits() orelse 0) * 8,
2166 non_null_offset * 8,2158 non_null_offset * 8,
...@@ -2192,12 +2184,12 @@ pub const Object = struct {...@@ -2192,12 +2184,12 @@ pub const Object = struct {
2192 const payload_ty = ty.errorUnionPayload(zcu);2184 const payload_ty = ty.errorUnionPayload(zcu);
2193 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {2185 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2194 // TODO: Maybe remove?2186 // 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);
2196 try o.debug_type_map.put(gpa, ty, debug_error_union_type);2188 try o.debug_type_map.put(gpa, ty, debug_error_union_type);
2197 return debug_error_union_type;2189 return debug_error_union_type;
2198 }2190 }
21992191
2200 const name = try o.allocTypeName(ty);2192 const name = try o.allocTypeName(pt, ty);
2201 defer gpa.free(name);2193 defer gpa.free(name);
22022194
2203 const error_size = Type.anyerror.abiSize(zcu);2195 const error_size = Type.anyerror.abiSize(zcu);
...@@ -2229,7 +2221,7 @@ pub const Object = struct {...@@ -2229,7 +2221,7 @@ pub const Object = struct {
2229 .none, // File2221 .none, // File
2230 debug_fwd_ref,2222 debug_fwd_ref,
2231 0, // Line2223 0, // Line
2232 try o.lowerDebugType(Type.anyerror),2224 try o.lowerDebugType(pt, Type.anyerror),
2233 error_size * 8,2225 error_size * 8,
2234 (error_align.toByteUnits() orelse 0) * 8,2226 (error_align.toByteUnits() orelse 0) * 8,
2235 error_offset * 8,2227 error_offset * 8,
...@@ -2239,7 +2231,7 @@ pub const Object = struct {...@@ -2239,7 +2231,7 @@ pub const Object = struct {
2239 .none, // File2231 .none, // File
2240 debug_fwd_ref,2232 debug_fwd_ref,
2241 0, // Line2233 0, // Line
2242 try o.lowerDebugType(payload_ty),2234 try o.lowerDebugType(pt, payload_ty),
2243 payload_size * 8,2235 payload_size * 8,
2244 (payload_align.toByteUnits() orelse 0) * 8,2236 (payload_align.toByteUnits() orelse 0) * 8,
2245 payload_offset * 8,2237 payload_offset * 8,
...@@ -2270,7 +2262,7 @@ pub const Object = struct {...@@ -2270,7 +2262,7 @@ pub const Object = struct {
2270 return debug_error_set;2262 return debug_error_set;
2271 },2263 },
2272 .@"struct" => {2264 .@"struct" => {
2273 const name = try o.allocTypeName(ty);2265 const name = try o.allocTypeName(pt, ty);
2274 defer gpa.free(name);2266 defer gpa.free(name);
22752267
2276 if (zcu.typeToPackedStruct(ty)) |struct_type| {2268 if (zcu.typeToPackedStruct(ty)) |struct_type| {
...@@ -2315,7 +2307,7 @@ pub const Object = struct {...@@ -2315,7 +2307,7 @@ pub const Object = struct {
2315 .none, // File2307 .none, // File
2316 debug_fwd_ref,2308 debug_fwd_ref,
2317 0,2309 0,
2318 try o.lowerDebugType(Type.fromInterned(field_ty)),2310 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
2319 field_size * 8,2311 field_size * 8,
2320 (field_align.toByteUnits() orelse 0) * 8,2312 (field_align.toByteUnits() orelse 0) * 8,
2321 field_offset * 8,2313 field_offset * 8,
...@@ -2347,7 +2339,7 @@ pub const Object = struct {...@@ -2347,7 +2339,7 @@ pub const Object = struct {
2347 // into. Therefore we can satisfy this by making an empty namespace,2339 // into. Therefore we can satisfy this by making an empty namespace,
2348 // rather than changing the frontend to unnecessarily resolve the2340 // rather than changing the frontend to unnecessarily resolve the
2349 // struct field types.2341 // struct field types.
2350 const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty);2342 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);
2351 try o.debug_type_map.put(gpa, ty, debug_struct_type);2343 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2352 return debug_struct_type;2344 return debug_struct_type;
2353 }2345 }
...@@ -2356,7 +2348,7 @@ pub const Object = struct {...@@ -2356,7 +2348,7 @@ pub const Object = struct {
2356 }2348 }
23572349
2358 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {2350 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2359 const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty);2351 const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty);
2360 try o.debug_type_map.put(gpa, ty, debug_struct_type);2352 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2361 return debug_struct_type;2353 return debug_struct_type;
2362 }2354 }
...@@ -2388,7 +2380,7 @@ pub const Object = struct {...@@ -2388,7 +2380,7 @@ pub const Object = struct {
2388 .none, // File2380 .none, // File
2389 debug_fwd_ref,2381 debug_fwd_ref,
2390 0, // Line2382 0, // Line
2391 try o.lowerDebugType(field_ty),2383 try o.lowerDebugType(pt, field_ty),
2392 field_size * 8,2384 field_size * 8,
2393 (field_align.toByteUnits() orelse 0) * 8,2385 (field_align.toByteUnits() orelse 0) * 8,
2394 field_offset * 8,2386 field_offset * 8,
...@@ -2415,7 +2407,7 @@ pub const Object = struct {...@@ -2415,7 +2407,7 @@ pub const Object = struct {
2415 return debug_struct_type;2407 return debug_struct_type;
2416 },2408 },
2417 .@"union" => {2409 .@"union" => {
2418 const name = try o.allocTypeName(ty);2410 const name = try o.allocTypeName(pt, ty);
2419 defer gpa.free(name);2411 defer gpa.free(name);
24202412
2421 const union_type = ip.loadUnionType(ty.toIntern());2413 const union_type = ip.loadUnionType(ty.toIntern());
...@@ -2423,7 +2415,7 @@ pub const Object = struct {...@@ -2423,7 +2415,7 @@ pub const Object = struct {
2423 !ty.hasRuntimeBitsIgnoreComptime(zcu) or2415 !ty.hasRuntimeBitsIgnoreComptime(zcu) or
2424 !union_type.haveLayout(ip))2416 !union_type.haveLayout(ip))
2425 {2417 {
2426 const debug_union_type = try o.makeEmptyNamespaceDebugType(ty);2418 const debug_union_type = try o.makeEmptyNamespaceDebugType(pt, ty);
2427 try o.debug_type_map.put(gpa, ty, debug_union_type);2419 try o.debug_type_map.put(gpa, ty, debug_union_type);
2428 return debug_union_type;2420 return debug_union_type;
2429 }2421 }
...@@ -2445,7 +2437,7 @@ pub const Object = struct {...@@ -2445,7 +2437,7 @@ pub const Object = struct {
2445 ty.abiSize(zcu) * 8,2437 ty.abiSize(zcu) * 8,
2446 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,2438 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2447 try o.builder.metadataTuple(2439 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))},
2449 ),2441 ),
2450 );2442 );
24512443
...@@ -2484,7 +2476,7 @@ pub const Object = struct {...@@ -2484,7 +2476,7 @@ pub const Object = struct {
2484 .none, // File2476 .none, // File
2485 debug_union_fwd_ref,2477 debug_union_fwd_ref,
2486 0, // Line2478 0, // Line
2487 try o.lowerDebugType(Type.fromInterned(field_ty)),2479 try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
2488 field_size * 8,2480 field_size * 8,
2489 (field_align.toByteUnits() orelse 0) * 8,2481 (field_align.toByteUnits() orelse 0) * 8,
2490 0, // Offset2482 0, // Offset
...@@ -2534,7 +2526,7 @@ pub const Object = struct {...@@ -2534,7 +2526,7 @@ pub const Object = struct {
2534 .none, // File2526 .none, // File
2535 debug_fwd_ref,2527 debug_fwd_ref,
2536 0, // Line2528 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)),
2538 layout.tag_size * 8,2530 layout.tag_size * 8,
2539 (layout.tag_align.toByteUnits() orelse 0) * 8,2531 (layout.tag_align.toByteUnits() orelse 0) * 8,
2540 tag_offset * 8,2532 tag_offset * 8,
...@@ -2588,19 +2580,19 @@ pub const Object = struct {...@@ -2588,19 +2580,19 @@ pub const Object = struct {
2588 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) {2580 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
2589 const sret = firstParamSRet(fn_info, zcu, target);2581 const sret = firstParamSRet(fn_info, zcu, target);
2590 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);2582 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
2593 if (sret) {2585 if (sret) {
2594 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));2586 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));
2596 }2588 }
2597 } else {2589 } else {
2598 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));2590 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, Type.void));
2599 }2591 }
26002592
2601 if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) {2593 if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) {
2602 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());2594 // Stack trace pointer.
2603 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));2595 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, .fromInterned(.ptr_usize_type)));
2604 }2596 }
26052597
2606 for (0..fn_info.param_types.len) |i| {2598 for (0..fn_info.param_types.len) |i| {
...@@ -2609,9 +2601,9 @@ pub const Object = struct {...@@ -2609,9 +2601,9 @@ pub const Object = struct {
26092601
2610 if (isByRef(param_ty, zcu)) {2602 if (isByRef(param_ty, zcu)) {
2611 const ptr_ty = try pt.singleMutPtrType(param_ty);2603 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));
2613 } else {2605 } else {
2614 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));2606 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, param_ty));
2615 }2607 }
2616 }2608 }
26172609
...@@ -2634,10 +2626,10 @@ pub const Object = struct {...@@ -2634,10 +2626,10 @@ pub const Object = struct {
2634 }2626 }
2635 }2627 }
26362628
2637 fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata {2629 fn namespaceToDebugScope(o: *Object, pt: Zcu.PerThread, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata {
2638 const zcu = o.pt.zcu;2630 const zcu = pt.zcu;
2639 const namespace = zcu.namespacePtr(namespace_index);2631 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
2642 const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index);2634 const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index);
26432635
...@@ -2646,12 +2638,12 @@ pub const Object = struct {...@@ -2646,12 +2638,12 @@ pub const Object = struct {
2646 return gop.value_ptr.*;2638 return gop.value_ptr.*;
2647 }2639 }
26482640
2649 fn makeEmptyNamespaceDebugType(o: *Object, ty: Type) !Builder.Metadata {2641 fn makeEmptyNamespaceDebugType(o: *Object, pt: Zcu.PerThread, ty: Type) !Builder.Metadata {
2650 const zcu = o.pt.zcu;2642 const zcu = pt.zcu;
2651 const ip = &zcu.intern_pool;2643 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));
2653 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|2645 const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace|
2654 try o.namespaceToDebugScope(parent_namespace)2646 try o.namespaceToDebugScope(pt, parent_namespace)
2655 else2647 else
2656 file;2648 file;
2657 return o.builder.debugStructType(2649 return o.builder.debugStructType(
...@@ -2666,31 +2658,10 @@ pub const Object = struct {...@@ -2666,31 +2658,10 @@ pub const Object = struct {
2666 );2658 );
2667 }2659 }
26682660
2669 fn getStackTraceType(o: *Object) Allocator.Error!Type {2661 fn allocTypeName(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error![:0]const u8 {
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 {
2691 var aw: std.io.Writer.Allocating = .init(o.gpa);2662 var aw: std.io.Writer.Allocating = .init(o.gpa);
2692 defer aw.deinit();2663 defer aw.deinit();
2693 ty.print(&aw.writer, o.pt) catch |err| switch (err) {2664 ty.print(&aw.writer, pt) catch |err| switch (err) {
2694 error.WriteFailed => return error.OutOfMemory,2665 error.WriteFailed => return error.OutOfMemory,
2695 };2666 };
2696 return aw.toOwnedSliceSentinel(0);2667 return aw.toOwnedSliceSentinel(0);
...@@ -2701,9 +2672,9 @@ pub const Object = struct {...@@ -2701,9 +2672,9 @@ pub const Object = struct {
2701 /// completed, so if any attributes rely on that, they must be done in updateFunc, not here.2672 /// completed, so if any attributes rely on that, they must be done in updateFunc, not here.
2702 fn resolveLlvmFunction(2673 fn resolveLlvmFunction(
2703 o: *Object,2674 o: *Object,
2675 pt: Zcu.PerThread,
2704 nav_index: InternPool.Nav.Index,2676 nav_index: InternPool.Nav.Index,
2705 ) Allocator.Error!Builder.Function.Index {2677 ) Allocator.Error!Builder.Function.Index {
2706 const pt = o.pt;
2707 const zcu = pt.zcu;2678 const zcu = pt.zcu;
2708 const ip = &zcu.intern_pool;2679 const ip = &zcu.intern_pool;
2709 const gpa = o.gpa;2680 const gpa = o.gpa;
...@@ -2722,7 +2693,7 @@ pub const Object = struct {...@@ -2722,7 +2693,7 @@ pub const Object = struct {
2722 else2693 else
2723 .{ false, .none };2694 .{ false, .none };
2724 const function_index = try o.builder.addFunction(2695 const function_index = try o.builder.addFunction(
2725 try o.lowerType(ty),2696 try o.lowerType(pt, ty),
2726 try o.builder.strtabString((if (is_extern) nav.name else nav.fqn).toSlice(ip)),2697 try o.builder.strtabString((if (is_extern) nav.name else nav.fqn).toSlice(ip)),
2727 toLlvmAddressSpace(nav.getAddrspace(), target),2698 toLlvmAddressSpace(nav.getAddrspace(), target),
2728 );2699 );
...@@ -2755,7 +2726,7 @@ pub const Object = struct {...@@ -2755,7 +2726,7 @@ pub const Object = struct {
2755 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);2726 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
2756 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);2727 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));
2759 try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder);2730 try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder);
27602731
2761 llvm_arg_i += 1;2732 llvm_arg_i += 1;
...@@ -2862,19 +2833,19 @@ pub const Object = struct {...@@ -2862,19 +2833,19 @@ pub const Object = struct {
2862 // Add parameter attributes. We handle only the case of extern functions (no body)2833 // Add parameter attributes. We handle only the case of extern functions (no body)
2863 // because functions with bodies are handled in `updateFunc`.2834 // because functions with bodies are handled in `updateFunc`.
2864 if (is_extern) {2835 if (is_extern) {
2865 var it = iterateParamTypes(o, fn_info);2836 var it = iterateParamTypes(o, pt, fn_info);
2866 it.llvm_index = llvm_arg_i;2837 it.llvm_index = llvm_arg_i;
2867 while (try it.next()) |lowering| switch (lowering) {2838 while (try it.next()) |lowering| switch (lowering) {
2868 .byval => {2839 .byval => {
2869 const param_index = it.zig_index - 1;2840 const param_index = it.zig_index - 1;
2870 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);2841 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
2871 if (!isByRef(param_ty, zcu)) {2842 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);
2873 }2844 }
2874 },2845 },
2875 .byref => {2846 .byref => {
2876 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);2847 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);
2878 const alignment = param_ty.abiAlignment(zcu);2849 const alignment = param_ty.abiAlignment(zcu);
2879 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);2850 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);
2880 },2851 },
...@@ -2969,6 +2940,7 @@ pub const Object = struct {...@@ -2969,6 +2940,7 @@ pub const Object = struct {
29692940
2970 fn resolveGlobalUav(2941 fn resolveGlobalUav(
2971 o: *Object,2942 o: *Object,
2943 pt: Zcu.PerThread,
2972 uav: InternPool.Index,2944 uav: InternPool.Index,
2973 llvm_addr_space: Builder.AddrSpace,2945 llvm_addr_space: Builder.AddrSpace,
2974 alignment: InternPool.Alignment,2946 alignment: InternPool.Alignment,
...@@ -2986,17 +2958,17 @@ pub const Object = struct {...@@ -2986,17 +2958,17 @@ pub const Object = struct {
2986 }2958 }
2987 errdefer assert(o.uav_map.remove(uav));2959 errdefer assert(o.uav_map.remove(uav));
29882960
2989 const zcu = o.pt.zcu;2961 const zcu = pt.zcu;
2990 const decl_ty = zcu.intern_pool.typeOf(uav);2962 const decl_ty = zcu.intern_pool.typeOf(uav);
29912963
2992 const variable_index = try o.builder.addVariable(2964 const variable_index = try o.builder.addVariable(
2993 try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}),2965 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)),
2995 llvm_addr_space,2967 llvm_addr_space,
2996 );2968 );
2997 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;2969 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);
3000 variable_index.setLinkage(.internal, &o.builder);2972 variable_index.setLinkage(.internal, &o.builder);
3001 variable_index.setMutability(.constant, &o.builder);2973 variable_index.setMutability(.constant, &o.builder);
3002 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);2974 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
...@@ -3006,13 +2978,13 @@ pub const Object = struct {...@@ -3006,13 +2978,13 @@ pub const Object = struct {
30062978
3007 fn resolveGlobalNav(2979 fn resolveGlobalNav(
3008 o: *Object,2980 o: *Object,
2981 pt: Zcu.PerThread,
3009 nav_index: InternPool.Nav.Index,2982 nav_index: InternPool.Nav.Index,
3010 ) Allocator.Error!Builder.Variable.Index {2983 ) Allocator.Error!Builder.Variable.Index {
3011 const gop = try o.nav_map.getOrPut(o.gpa, nav_index);2984 const gop = try o.nav_map.getOrPut(o.gpa, nav_index);
3012 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable;2985 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable;
3013 errdefer assert(o.nav_map.remove(nav_index));2986 errdefer assert(o.nav_map.remove(nav_index));
30142987
3015 const pt = o.pt;
3016 const zcu = pt.zcu;2988 const zcu = pt.zcu;
3017 const ip = &zcu.intern_pool;2989 const ip = &zcu.intern_pool;
3018 const nav = ip.getNav(nav_index);2990 const nav = ip.getNav(nav_index);
...@@ -3033,7 +3005,7 @@ pub const Object = struct {...@@ -3033,7 +3005,7 @@ pub const Object = struct {
3033 .strong, .weak => nav.name,3005 .strong, .weak => nav.name,
3034 .link_once => unreachable,3006 .link_once => unreachable,
3035 }.toSlice(ip)),3007 }.toSlice(ip)),
3036 try o.lowerType(Type.fromInterned(nav.typeOf(ip))),3008 try o.lowerType(pt, Type.fromInterned(nav.typeOf(ip))),
3037 toLlvmGlobalAddressSpace(nav.getAddrspace(), zcu.getTarget()),3009 toLlvmGlobalAddressSpace(nav.getAddrspace(), zcu.getTarget()),
3038 );3010 );
3039 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;3011 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
...@@ -3062,12 +3034,11 @@ pub const Object = struct {...@@ -3062,12 +3034,11 @@ pub const Object = struct {
3062 return variable_index;3034 return variable_index;
3063 }3035 }
30643036
3065 fn errorIntType(o: *Object) Allocator.Error!Builder.Type {3037 fn errorIntType(o: *Object, pt: Zcu.PerThread) Allocator.Error!Builder.Type {
3066 return o.builder.intType(o.pt.zcu.errorSetBits());3038 return o.builder.intType(pt.zcu.errorSetBits());
3067 }3039 }
30683040
3069 fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type {3041 fn lowerType(o: *Object, pt: Zcu.PerThread, t: Type) Allocator.Error!Builder.Type {
3070 const pt = o.pt;
3071 const zcu = pt.zcu;3042 const zcu = pt.zcu;
3072 const target = zcu.getTarget();3043 const target = zcu.getTarget();
3073 const ip = &zcu.intern_pool;3044 const ip = &zcu.intern_pool;
...@@ -3123,7 +3094,7 @@ pub const Object = struct {...@@ -3123,7 +3094,7 @@ pub const Object = struct {
3123 .bool_type => .i1,3094 .bool_type => .i1,
3124 .void_type => .void,3095 .void_type => .void,
3125 .type_type => unreachable,3096 .type_type => unreachable,
3126 .anyerror_type => try o.errorIntType(),3097 .anyerror_type => try o.errorIntType(pt),
3127 .comptime_int_type,3098 .comptime_int_type,
3128 .comptime_float_type,3099 .comptime_float_type,
3129 .noreturn_type,3100 .noreturn_type,
...@@ -3141,11 +3112,11 @@ pub const Object = struct {...@@ -3141,11 +3112,11 @@ pub const Object = struct {
3141 => .ptr,3112 => .ptr,
3142 .slice_const_u8_type,3113 .slice_const_u8_type,
3143 .slice_const_u8_sentinel_0_type,3114 .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) }),
3145 .optional_noreturn_type => unreachable,3116 .optional_noreturn_type => unreachable,
3146 .anyerror_void_error_union_type,3117 .anyerror_void_error_union_type,
3147 .adhoc_inferred_error_set_type,3118 .adhoc_inferred_error_set_type,
3148 => try o.errorIntType(),3119 => try o.errorIntType(pt),
3149 .generic_poison_type,3120 .generic_poison_type,
3150 .empty_tuple_type,3121 .empty_tuple_type,
3151 => unreachable,3122 => unreachable,
...@@ -3182,24 +3153,24 @@ pub const Object = struct {...@@ -3182,24 +3153,24 @@ pub const Object = struct {
3182 .one, .many, .c => ptr_ty,3153 .one, .many, .c => ptr_ty,
3183 .slice => try o.builder.structType(.normal, &.{3154 .slice => try o.builder.structType(.normal, &.{
3184 ptr_ty,3155 ptr_ty,
3185 try o.lowerType(Type.usize),3156 try o.lowerType(pt, Type.usize),
3186 }),3157 }),
3187 };3158 };
3188 },3159 },
3189 .array_type => |array_type| o.builder.arrayType(3160 .array_type => |array_type| o.builder.arrayType(
3190 array_type.lenIncludingSentinel(),3161 array_type.lenIncludingSentinel(),
3191 try o.lowerType(Type.fromInterned(array_type.child)),3162 try o.lowerType(pt, Type.fromInterned(array_type.child)),
3192 ),3163 ),
3193 .vector_type => |vector_type| o.builder.vectorType(3164 .vector_type => |vector_type| o.builder.vectorType(
3194 .normal,3165 .normal,
3195 vector_type.len,3166 vector_type.len,
3196 try o.lowerType(Type.fromInterned(vector_type.child)),3167 try o.lowerType(pt, Type.fromInterned(vector_type.child)),
3197 ),3168 ),
3198 .opt_type => |child_ty| {3169 .opt_type => |child_ty| {
3199 // Must stay in sync with `opt_payload` logic in `lowerPtr`.3170 // Must stay in sync with `opt_payload` logic in `lowerPtr`.
3200 if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(zcu)) return .i8;3171 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));
3203 if (t.optionalReprIsPayload(zcu)) return payload_ty;3174 if (t.optionalReprIsPayload(zcu)) return payload_ty;
32043175
3205 comptime assert(optional_layout_version == 3);3176 comptime assert(optional_layout_version == 3);
...@@ -3218,17 +3189,16 @@ pub const Object = struct {...@@ -3218,17 +3189,16 @@ pub const Object = struct {
3218 .error_union_type => |error_union_type| {3189 .error_union_type => |error_union_type| {
3219 // Must stay in sync with `codegen.errUnionPayloadOffset`.3190 // Must stay in sync with `codegen.errUnionPayloadOffset`.
3220 // See logic in `lowerPtr`.3191 // See logic in `lowerPtr`.
3221 const error_type = try o.errorIntType();3192 const error_type = try o.errorIntType(pt);
3222 if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu))3193 if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu))
3223 return error_type;3194 return error_type;
3224 const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type));3195 const payload_type = try o.lowerType(pt, Type.fromInterned(error_union_type.payload_type));
3225 const err_int_ty = try o.pt.errorIntType();
32263196
3227 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(zcu);3197 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
3230 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(zcu);3200 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
3233 var fields: [3]Builder.Type = undefined;3203 var fields: [3]Builder.Type = undefined;
3234 var fields_len: usize = 2;3204 var fields_len: usize = 2;
...@@ -3262,7 +3232,7 @@ pub const Object = struct {...@@ -3262,7 +3232,7 @@ pub const Object = struct {
3262 const struct_type = ip.loadStructType(t.toIntern());3232 const struct_type = ip.loadStructType(t.toIntern());
32633233
3264 if (struct_type.layout == .@"packed") {3234 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)));
3266 try o.type_map.put(o.gpa, t.toIntern(), int_ty);3236 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
3267 return int_ty;3237 return int_ty;
3268 }3238 }
...@@ -3312,7 +3282,7 @@ pub const Object = struct {...@@ -3312,7 +3282,7 @@ pub const Object = struct {
3312 .struct_ty = t.toIntern(),3282 .struct_ty = t.toIntern(),
3313 .field_index = field_index,3283 .field_index = field_index,
3314 }, @intCast(llvm_field_types.items.len));3284 }, @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
3317 offset += field_ty.abiSize(zcu);3287 offset += field_ty.abiSize(zcu);
3318 }3288 }
...@@ -3382,7 +3352,7 @@ pub const Object = struct {...@@ -3382,7 +3352,7 @@ pub const Object = struct {
3382 .struct_ty = t.toIntern(),3352 .struct_ty = t.toIntern(),
3383 .field_index = @intCast(field_index),3353 .field_index = @intCast(field_index),
3384 }, @intCast(llvm_field_types.items.len));3354 }, @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
3387 offset += Type.fromInterned(field_ty).abiSize(zcu);3357 offset += Type.fromInterned(field_ty).abiSize(zcu);
3388 }3358 }
...@@ -3410,13 +3380,13 @@ pub const Object = struct {...@@ -3410,13 +3380,13 @@ pub const Object = struct {
3410 }3380 }
34113381
3412 if (layout.payload_size == 0) {3382 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));
3414 try o.type_map.put(o.gpa, t.toIntern(), enum_tag_ty);3384 try o.type_map.put(o.gpa, t.toIntern(), enum_tag_ty);
3415 return enum_tag_ty;3385 return enum_tag_ty;
3416 }3386 }
34173387
3418 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);3388 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
3421 const payload_ty = ty: {3391 const payload_ty = ty: {
3422 if (layout.most_aligned_field_size == layout.payload_size) {3392 if (layout.most_aligned_field_size == layout.payload_size) {
...@@ -3442,7 +3412,7 @@ pub const Object = struct {...@@ -3442,7 +3412,7 @@ pub const Object = struct {
3442 );3412 );
3443 return ty;3413 return ty;
3444 }3414 }
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
3447 // Put the tag before or after the payload depending on which one's3417 // Put the tag before or after the payload depending on which one's
3448 // alignment is greater.3418 // alignment is greater.
...@@ -3477,9 +3447,9 @@ pub const Object = struct {...@@ -3477,9 +3447,9 @@ pub const Object = struct {
3477 }3447 }
3478 return gop.value_ptr.*;3448 return gop.value_ptr.*;
3479 },3449 },
3480 .enum_type => try o.lowerType(Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)),3450 .enum_type => try o.lowerType(pt, Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)),
3481 .func_type => |func_type| try o.lowerTypeFn(func_type),3451 .func_type => |func_type| try o.lowerTypeFn(pt, func_type),
3482 .error_set_type, .inferred_error_set_type => try o.errorIntType(),3452 .error_set_type, .inferred_error_set_type => try o.errorIntType(pt),
3483 // values, not types3453 // values, not types
3484 .undef,3454 .undef,
3485 .simple_value,3455 .simple_value,
...@@ -3508,8 +3478,7 @@ pub const Object = struct {...@@ -3508,8 +3478,7 @@ pub const Object = struct {
3508 /// Use this instead of lowerType when you want to handle correctly the case of elem_ty3478 /// Use this instead of lowerType when you want to handle correctly the case of elem_ty
3509 /// being a zero bit type, but it should still be lowered as an i8 in such case.3479 /// being a zero bit type, but it should still be lowered as an i8 in such case.
3510 /// There are other similar cases handled here as well.3480 /// There are other similar cases handled here as well.
3511 fn lowerPtrElemTy(o: *Object, elem_ty: Type) Allocator.Error!Builder.Type {3481 fn lowerPtrElemTy(o: *Object, pt: Zcu.PerThread, elem_ty: Type) Allocator.Error!Builder.Type {
3512 const pt = o.pt;
3513 const zcu = pt.zcu;3482 const zcu = pt.zcu;
3514 const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) {3483 const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) {
3515 .@"opaque" => true,3484 .@"opaque" => true,
...@@ -3517,15 +3486,14 @@ pub const Object = struct {...@@ -3517,15 +3486,14 @@ pub const Object = struct {
3517 .array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu),3486 .array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu),
3518 else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu),3487 else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu),
3519 };3488 };
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;
3521 }3490 }
35223491
3523 fn lowerTypeFn(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {3492 fn lowerTypeFn(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
3524 const pt = o.pt;
3525 const zcu = pt.zcu;3493 const zcu = pt.zcu;
3526 const ip = &zcu.intern_pool;3494 const ip = &zcu.intern_pool;
3527 const target = zcu.getTarget();3495 const target = zcu.getTarget();
3528 const ret_ty = try lowerFnRetTy(o, fn_info);3496 const ret_ty = try lowerFnRetTy(o, pt, fn_info);
35293497
3530 var llvm_params: std.ArrayListUnmanaged(Builder.Type) = .empty;3498 var llvm_params: std.ArrayListUnmanaged(Builder.Type) = .empty;
3531 defer llvm_params.deinit(o.gpa);3499 defer llvm_params.deinit(o.gpa);
...@@ -3535,16 +3503,17 @@ pub const Object = struct {...@@ -3535,16 +3503,17 @@ pub const Object = struct {
3535 }3503 }
35363504
3537 if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) {3505 if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) {
3538 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());3506 const stack_trace_ty = zcu.builtin_decl_values.get(.StackTrace);
3539 try llvm_params.append(o.gpa, try o.lowerType(ptr_ty));3507 const ptr_ty = try pt.ptrType(.{ .child = stack_trace_ty });
3508 try llvm_params.append(o.gpa, try o.lowerType(pt, ptr_ty));
3540 }3509 }
35413510
3542 var it = iterateParamTypes(o, fn_info);3511 var it = iterateParamTypes(o, pt, fn_info);
3543 while (try it.next()) |lowering| switch (lowering) {3512 while (try it.next()) |lowering| switch (lowering) {
3544 .no_bits => continue,3513 .no_bits => continue,
3545 .byval => {3514 .byval => {
3546 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);3515 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));
3548 },3517 },
3549 .byref, .byref_mut => {3518 .byref, .byref_mut => {
3550 try llvm_params.append(o.gpa, .ptr);3519 try llvm_params.append(o.gpa, .ptr);
...@@ -3559,7 +3528,7 @@ pub const Object = struct {...@@ -3559,7 +3528,7 @@ pub const Object = struct {
3559 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);3528 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
3560 try llvm_params.appendSlice(o.gpa, &.{3529 try llvm_params.appendSlice(o.gpa, &.{
3561 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(zcu), target)),3530 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(zcu), target)),
3562 try o.lowerType(Type.usize),3531 try o.lowerType(pt, Type.usize),
3563 });3532 });
3564 },3533 },
3565 .multiple_llvm_types => {3534 .multiple_llvm_types => {
...@@ -3567,7 +3536,7 @@ pub const Object = struct {...@@ -3567,7 +3536,7 @@ pub const Object = struct {
3567 },3536 },
3568 .float_array => |count| {3537 .float_array => |count| {
3569 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);3538 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).?);
3571 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));3540 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));
3572 },3541 },
3573 .i32_array, .i64_array => |arr_len| {3542 .i32_array, .i64_array => |arr_len| {
...@@ -3586,8 +3555,7 @@ pub const Object = struct {...@@ -3586,8 +3555,7 @@ pub const Object = struct {
3586 );3555 );
3587 }3556 }
35883557
3589 fn lowerValueToInt(o: *Object, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {3558 fn lowerValueToInt(o: *Object, pt: Zcu.PerThread, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {
3590 const pt = o.pt;
3591 const zcu = pt.zcu;3559 const zcu = pt.zcu;
3592 const ip = &zcu.intern_pool;3560 const ip = &zcu.intern_pool;
3593 const target = zcu.getTarget();3561 const target = zcu.getTarget();
...@@ -3600,23 +3568,23 @@ pub const Object = struct {...@@ -3600,23 +3568,23 @@ pub const Object = struct {
3600 const ty = Type.fromInterned(val_key.typeOf());3568 const ty = Type.fromInterned(val_key.typeOf());
3601 switch (val_key) {3569 switch (val_key) {
3602 .@"extern" => |@"extern"| {3570 .@"extern" => |@"extern"| {
3603 const function_index = try o.resolveLlvmFunction(@"extern".owner_nav);3571 const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav);
3604 const ptr = function_index.ptrConst(&o.builder).global.toConst();3572 const ptr = function_index.ptrConst(&o.builder).global.toConst();
3605 return o.builder.convConst(ptr, llvm_int_ty);3573 return o.builder.convConst(ptr, llvm_int_ty);
3606 },3574 },
3607 .func => |func| {3575 .func => |func| {
3608 const function_index = try o.resolveLlvmFunction(func.owner_nav);3576 const function_index = try o.resolveLlvmFunction(pt, func.owner_nav);
3609 const ptr = function_index.ptrConst(&o.builder).global.toConst();3577 const ptr = function_index.ptrConst(&o.builder).global.toConst();
3610 return o.builder.convConst(ptr, llvm_int_ty);3578 return o.builder.convConst(ptr, llvm_int_ty);
3611 },3579 },
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),
3613 .aggregate => switch (ip.indexToKey(ty.toIntern())) {3581 .aggregate => switch (ip.indexToKey(ty.toIntern())) {
3614 .struct_type, .vector_type => {},3582 .struct_type, .vector_type => {},
3615 else => unreachable,3583 else => unreachable,
3616 },3584 },
3617 .un => |un| {3585 .un => |un| {
3618 const layout = ty.unionGetLayout(zcu);3586 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
3621 const union_obj = zcu.typeToUnion(ty).?;3589 const union_obj = zcu.typeToUnion(ty).?;
3622 const container_layout = union_obj.flagsUnordered(ip).layout;3590 const container_layout = union_obj.flagsUnordered(ip).layout;
...@@ -3626,7 +3594,7 @@ pub const Object = struct {...@@ -3626,7 +3594,7 @@ pub const Object = struct {
3626 var need_unnamed = false;3594 var need_unnamed = false;
3627 if (un.tag == .none) {3595 if (un.tag == .none) {
3628 assert(layout.tag_size == 0);3596 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
3631 need_unnamed = true;3599 need_unnamed = true;
3632 return union_val;3600 return union_val;
...@@ -3634,7 +3602,7 @@ pub const Object = struct {...@@ -3634,7 +3602,7 @@ pub const Object = struct {
3634 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;3602 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
3635 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);3603 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3636 if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(llvm_int_ty, 0);3604 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);
3638 },3606 },
3639 .simple_value => |simple_value| switch (simple_value) {3607 .simple_value => |simple_value| switch (simple_value) {
3640 .false, .true => {},3608 .false, .true => {},
...@@ -3678,8 +3646,7 @@ pub const Object = struct {...@@ -3678,8 +3646,7 @@ pub const Object = struct {
3678 });3646 });
3679 }3647 }
36803648
3681 fn lowerValue(o: *Object, arg_val: InternPool.Index) Error!Builder.Constant {3649 fn lowerValue(o: *Object, pt: Zcu.PerThread, arg_val: InternPool.Index) Error!Builder.Constant {
3682 const pt = o.pt;
3683 const zcu = pt.zcu;3650 const zcu = pt.zcu;
3684 const ip = &zcu.intern_pool;3651 const ip = &zcu.intern_pool;
3685 const target = zcu.getTarget();3652 const target = zcu.getTarget();
...@@ -3688,7 +3655,7 @@ pub const Object = struct {...@@ -3688,7 +3655,7 @@ pub const Object = struct {
3688 const val_key = ip.indexToKey(val.toIntern());3655 const val_key = ip.indexToKey(val.toIntern());
36893656
3690 if (val.isUndefDeep(zcu)) {3657 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())));
3692 }3659 }
36933660
3694 const ty = Type.fromInterned(val_key.typeOf());3661 const ty = Type.fromInterned(val_key.typeOf());
...@@ -3727,21 +3694,21 @@ pub const Object = struct {...@@ -3727,21 +3694,21 @@ pub const Object = struct {
3727 .empty_enum_value,3694 .empty_enum_value,
3728 => unreachable, // non-runtime values3695 => unreachable, // non-runtime values
3729 .@"extern" => |@"extern"| {3696 .@"extern" => |@"extern"| {
3730 const function_index = try o.resolveLlvmFunction(@"extern".owner_nav);3697 const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav);
3731 return function_index.ptrConst(&o.builder).global.toConst();3698 return function_index.ptrConst(&o.builder).global.toConst();
3732 },3699 },
3733 .func => |func| {3700 .func => |func| {
3734 const function_index = try o.resolveLlvmFunction(func.owner_nav);3701 const function_index = try o.resolveLlvmFunction(pt, func.owner_nav);
3735 return function_index.ptrConst(&o.builder).global.toConst();3702 return function_index.ptrConst(&o.builder).global.toConst();
3736 },3703 },
3737 .int => {3704 .int => {
3738 var bigint_space: Value.BigIntSpace = undefined;3705 var bigint_space: Value.BigIntSpace = undefined;
3739 const bigint = val.toBigInt(&bigint_space, zcu);3706 const bigint = val.toBigInt(&bigint_space, zcu);
3740 return lowerBigInt(o, ty, bigint);3707 return lowerBigInt(o, pt, ty, bigint);
3741 },3708 },
3742 .err => |err| {3709 .err => |err| {
3743 const int = try pt.getErrorValue(err.name);3710 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);
3745 return llvm_int;3712 return llvm_int;
3746 },3713 },
3747 .error_union => |error_union| {3714 .error_union => |error_union| {
...@@ -3756,13 +3723,13 @@ pub const Object = struct {...@@ -3756,13 +3723,13 @@ pub const Object = struct {
3756 const payload_type = ty.errorUnionPayload(zcu);3723 const payload_type = ty.errorUnionPayload(zcu);
3757 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {3724 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
3758 // We use the error type directly as the type.3725 // We use the error type directly as the type.
3759 return o.lowerValue(err_val);3726 return o.lowerValue(pt, err_val);
3760 }3727 }
37613728
3762 const payload_align = payload_type.abiAlignment(zcu);3729 const payload_align = payload_type.abiAlignment(zcu);
3763 const error_align = err_int_ty.abiAlignment(zcu);3730 const error_align = err_int_ty.abiAlignment(zcu);
3764 const llvm_error_value = try o.lowerValue(err_val);3731 const llvm_error_value = try o.lowerValue(pt, err_val);
3765 const llvm_payload_value = try o.lowerValue(switch (error_union.val) {3732 const llvm_payload_value = try o.lowerValue(pt, switch (error_union.val) {
3766 .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }),3733 .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }),
3767 .payload => |payload| payload,3734 .payload => |payload| payload,
3768 });3735 });
...@@ -3779,7 +3746,7 @@ pub const Object = struct {...@@ -3779,7 +3746,7 @@ pub const Object = struct {
3779 fields[0] = vals[0].typeOf(&o.builder);3746 fields[0] = vals[0].typeOf(&o.builder);
3780 fields[1] = vals[1].typeOf(&o.builder);3747 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);
3783 const llvm_ty_fields = llvm_ty.structFields(&o.builder);3750 const llvm_ty_fields = llvm_ty.structFields(&o.builder);
3784 if (llvm_ty_fields.len > 2) {3751 if (llvm_ty_fields.len > 2) {
3785 assert(llvm_ty_fields.len == 3);3752 assert(llvm_ty_fields.len == 3);
...@@ -3791,7 +3758,7 @@ pub const Object = struct {...@@ -3791,7 +3758,7 @@ pub const Object = struct {
3791 fields[0..llvm_ty_fields.len],3758 fields[0..llvm_ty_fields.len],
3792 ), vals[0..llvm_ty_fields.len]);3759 ), vals[0..llvm_ty_fields.len]);
3793 },3760 },
3794 .enum_tag => |enum_tag| o.lowerValue(enum_tag.int),3761 .enum_tag => |enum_tag| o.lowerValue(pt, enum_tag.int),
3795 .float => switch (ty.floatBits(target)) {3762 .float => switch (ty.floatBits(target)) {
3796 16 => if (backendSupportsF16(target))3763 16 => if (backendSupportsF16(target))
3797 try o.builder.halfConst(val.toFloat(f16, zcu))3764 try o.builder.halfConst(val.toFloat(f16, zcu))
...@@ -3806,10 +3773,10 @@ pub const Object = struct {...@@ -3806,10 +3773,10 @@ pub const Object = struct {
3806 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)),3773 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)),
3807 else => unreachable,3774 else => unreachable,
3808 },3775 },
3809 .ptr => try o.lowerPtr(arg_val, 0),3776 .ptr => try o.lowerPtr(pt, arg_val, 0),
3810 .slice => |slice| return o.builder.structConst(try o.lowerType(ty), &.{3777 .slice => |slice| return o.builder.structConst(try o.lowerType(pt, ty), &.{
3811 try o.lowerValue(slice.ptr),3778 try o.lowerValue(pt, slice.ptr),
3812 try o.lowerValue(slice.len),3779 try o.lowerValue(pt, slice.len),
3813 }),3780 }),
3814 .opt => |opt| {3781 .opt => |opt| {
3815 comptime assert(optional_layout_version == 3);3782 comptime assert(optional_layout_version == 3);
...@@ -3819,7 +3786,7 @@ pub const Object = struct {...@@ -3819,7 +3786,7 @@ pub const Object = struct {
3819 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {3786 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3820 return non_null_bit;3787 return non_null_bit;
3821 }3788 }
3822 const llvm_ty = try o.lowerType(ty);3789 const llvm_ty = try o.lowerType(pt, ty);
3823 if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) {3790 if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) {
3824 .none => switch (llvm_ty.tag(&o.builder)) {3791 .none => switch (llvm_ty.tag(&o.builder)) {
3825 .integer => try o.builder.intConst(llvm_ty, 0),3792 .integer => try o.builder.intConst(llvm_ty, 0),
...@@ -3827,13 +3794,13 @@ pub const Object = struct {...@@ -3827,13 +3794,13 @@ pub const Object = struct {
3827 .structure => try o.builder.zeroInitConst(llvm_ty),3794 .structure => try o.builder.zeroInitConst(llvm_ty),
3828 else => unreachable,3795 else => unreachable,
3829 },3796 },
3830 else => |payload| try o.lowerValue(payload),3797 else => |payload| try o.lowerValue(pt, payload),
3831 };3798 };
3832 assert(payload_ty.zigTypeTag(zcu) != .@"fn");3799 assert(payload_ty.zigTypeTag(zcu) != .@"fn");
38333800
3834 var fields: [3]Builder.Type = undefined;3801 var fields: [3]Builder.Type = undefined;
3835 var vals: [3]Builder.Constant = undefined;3802 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) {
3837 .none => try pt.intern(.{ .undef = payload_ty.toIntern() }),3804 .none => try pt.intern(.{ .undef = payload_ty.toIntern() }),
3838 else => |payload| payload,3805 else => |payload| payload,
3839 });3806 });
...@@ -3858,7 +3825,7 @@ pub const Object = struct {...@@ -3858,7 +3825,7 @@ pub const Object = struct {
3858 bytes.toSlice(array_type.lenIncludingSentinel(), ip),3825 bytes.toSlice(array_type.lenIncludingSentinel(), ip),
3859 )),3826 )),
3860 .elems => |elems| {3827 .elems => |elems| {
3861 const array_ty = try o.lowerType(ty);3828 const array_ty = try o.lowerType(pt, ty);
3862 const elem_ty = array_ty.childType(&o.builder);3829 const elem_ty = array_ty.childType(&o.builder);
3863 assert(elems.len == array_ty.aggregateLen(&o.builder));3830 assert(elems.len == array_ty.aggregateLen(&o.builder));
38643831
...@@ -3878,7 +3845,7 @@ pub const Object = struct {...@@ -3878,7 +3845,7 @@ pub const Object = struct {
38783845
3879 var need_unnamed = false;3846 var need_unnamed = false;
3880 for (vals, fields, elems) |*result_val, *result_field, elem| {3847 for (vals, fields, elems) |*result_val, *result_field, elem| {
3881 result_val.* = try o.lowerValue(elem);3848 result_val.* = try o.lowerValue(pt, elem);
3882 result_field.* = result_val.typeOf(&o.builder);3849 result_field.* = result_val.typeOf(&o.builder);
3883 if (result_field.* != elem_ty) need_unnamed = true;3850 if (result_field.* != elem_ty) need_unnamed = true;
3884 }3851 }
...@@ -3890,7 +3857,7 @@ pub const Object = struct {...@@ -3890,7 +3857,7 @@ pub const Object = struct {
3890 .repeated_elem => |elem| {3857 .repeated_elem => |elem| {
3891 const len: usize = @intCast(array_type.len);3858 const len: usize = @intCast(array_type.len);
3892 const len_including_sentinel: usize = @intCast(array_type.lenIncludingSentinel());3859 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);
3894 const elem_ty = array_ty.childType(&o.builder);3861 const elem_ty = array_ty.childType(&o.builder);
38953862
3896 const ExpectedContents = extern struct {3863 const ExpectedContents = extern struct {
...@@ -3908,12 +3875,12 @@ pub const Object = struct {...@@ -3908,12 +3875,12 @@ pub const Object = struct {
3908 defer allocator.free(fields);3875 defer allocator.free(fields);
39093876
3910 var need_unnamed = false;3877 var need_unnamed = false;
3911 @memset(vals[0..len], try o.lowerValue(elem));3878 @memset(vals[0..len], try o.lowerValue(pt, elem));
3912 @memset(fields[0..len], vals[0].typeOf(&o.builder));3879 @memset(fields[0..len], vals[0].typeOf(&o.builder));
3913 if (fields[0] != elem_ty) need_unnamed = true;3880 if (fields[0] != elem_ty) need_unnamed = true;
39143881
3915 if (array_type.sentinel != .none) {3882 if (array_type.sentinel != .none) {
3916 vals[len] = try o.lowerValue(array_type.sentinel);3883 vals[len] = try o.lowerValue(pt, array_type.sentinel);
3917 fields[len] = vals[len].typeOf(&o.builder);3884 fields[len] = vals[len].typeOf(&o.builder);
3918 if (fields[len] != elem_ty) need_unnamed = true;3885 if (fields[len] != elem_ty) need_unnamed = true;
3919 }3886 }
...@@ -3925,7 +3892,7 @@ pub const Object = struct {...@@ -3925,7 +3892,7 @@ pub const Object = struct {
3925 },3892 },
3926 },3893 },
3927 .vector_type => |vector_type| {3894 .vector_type => |vector_type| {
3928 const vector_ty = try o.lowerType(ty);3895 const vector_ty = try o.lowerType(pt, ty);
3929 switch (aggregate.storage) {3896 switch (aggregate.storage) {
3930 .bytes, .elems => {3897 .bytes, .elems => {
3931 const ExpectedContents = [Builder.expected_fields_len]Builder.Constant;3898 const ExpectedContents = [Builder.expected_fields_len]Builder.Constant;
...@@ -3942,7 +3909,7 @@ pub const Object = struct {...@@ -3942,7 +3909,7 @@ pub const Object = struct {
3942 result_val.* = try o.builder.intConst(.i8, byte);3909 result_val.* = try o.builder.intConst(.i8, byte);
3943 },3910 },
3944 .elems => |elems| for (vals, elems) |*result_val, elem| {3911 .elems => |elems| for (vals, elems) |*result_val, elem| {
3945 result_val.* = try o.lowerValue(elem);3912 result_val.* = try o.lowerValue(pt, elem);
3946 },3913 },
3947 .repeated_elem => unreachable,3914 .repeated_elem => unreachable,
3948 }3915 }
...@@ -3950,12 +3917,12 @@ pub const Object = struct {...@@ -3950,12 +3917,12 @@ pub const Object = struct {
3950 },3917 },
3951 .repeated_elem => |elem| return o.builder.splatConst(3918 .repeated_elem => |elem| return o.builder.splatConst(
3952 vector_ty,3919 vector_ty,
3953 try o.lowerValue(elem),3920 try o.lowerValue(pt, elem),
3954 ),3921 ),
3955 }3922 }
3956 },3923 },
3957 .tuple_type => |tuple| {3924 .tuple_type => |tuple| {
3958 const struct_ty = try o.lowerType(ty);3925 const struct_ty = try o.lowerType(pt, ty);
3959 const llvm_len = struct_ty.aggregateLen(&o.builder);3926 const llvm_len = struct_ty.aggregateLen(&o.builder);
39603927
3961 const ExpectedContents = extern struct {3928 const ExpectedContents = extern struct {
...@@ -4001,7 +3968,7 @@ pub const Object = struct {...@@ -4001,7 +3968,7 @@ pub const Object = struct {
4001 }3968 }
40023969
4003 vals[llvm_index] =3970 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());
4005 fields[llvm_index] = vals[llvm_index].typeOf(&o.builder);3972 fields[llvm_index] = vals[llvm_index].typeOf(&o.builder);
4006 if (fields[llvm_index] != struct_ty.structFields(&o.builder)[llvm_index])3973 if (fields[llvm_index] != struct_ty.structFields(&o.builder)[llvm_index])
4007 need_unnamed = true;3974 need_unnamed = true;
...@@ -4030,14 +3997,14 @@ pub const Object = struct {...@@ -4030,14 +3997,14 @@ pub const Object = struct {
4030 .struct_type => {3997 .struct_type => {
4031 const struct_type = ip.loadStructType(ty.toIntern());3998 const struct_type = ip.loadStructType(ty.toIntern());
4032 assert(struct_type.haveLayout(ip));3999 assert(struct_type.haveLayout(ip));
4033 const struct_ty = try o.lowerType(ty);4000 const struct_ty = try o.lowerType(pt, ty);
4034 if (struct_type.layout == .@"packed") {4001 if (struct_type.layout == .@"packed") {
4035 comptime assert(Type.packed_struct_layout_version == 2);4002 comptime assert(Type.packed_struct_layout_version == 2);
40364003
4037 const bits = ty.bitSize(zcu);4004 const bits = ty.bitSize(zcu);
4038 const llvm_int_ty = try o.builder.intType(@intCast(bits));4005 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);
4041 }4008 }
4042 const llvm_len = struct_ty.aggregateLen(&o.builder);4009 const llvm_len = struct_ty.aggregateLen(&o.builder);
40434010
...@@ -4085,6 +4052,7 @@ pub const Object = struct {...@@ -4085,6 +4052,7 @@ pub const Object = struct {
4085 }4052 }
40864053
4087 vals[llvm_index] = try o.lowerValue(4054 vals[llvm_index] = try o.lowerValue(
4055 pt,
4088 (try val.fieldValue(pt, field_index)).toIntern(),4056 (try val.fieldValue(pt, field_index)).toIntern(),
4089 );4057 );
4090 fields[llvm_index] = vals[llvm_index].typeOf(&o.builder);4058 fields[llvm_index] = vals[llvm_index].typeOf(&o.builder);
...@@ -4115,9 +4083,9 @@ pub const Object = struct {...@@ -4115,9 +4083,9 @@ pub const Object = struct {
4115 else => unreachable,4083 else => unreachable,
4116 },4084 },
4117 .un => |un| {4085 .un => |un| {
4118 const union_ty = try o.lowerType(ty);4086 const union_ty = try o.lowerType(pt, ty);
4119 const layout = ty.unionGetLayout(zcu);4087 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
4122 const union_obj = zcu.typeToUnion(ty).?;4090 const union_obj = zcu.typeToUnion(ty).?;
4123 const container_layout = union_obj.flagsUnordered(ip).layout;4091 const container_layout = union_obj.flagsUnordered(ip).layout;
...@@ -4131,7 +4099,7 @@ pub const Object = struct {...@@ -4131,7 +4099,7 @@ pub const Object = struct {
4131 const bits = ty.bitSize(zcu);4099 const bits = ty.bitSize(zcu);
4132 const llvm_int_ty = try o.builder.intType(@intCast(bits));4100 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);
4135 }4103 }
41364104
4137 // Sometimes we must make an unnamed struct because LLVM does4105 // Sometimes we must make an unnamed struct because LLVM does
...@@ -4144,7 +4112,7 @@ pub const Object = struct {...@@ -4144,7 +4112,7 @@ pub const Object = struct {
4144 const padding_len = layout.payload_size;4112 const padding_len = layout.payload_size;
4145 break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8));4113 break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8));
4146 }4114 }
4147 const payload = try o.lowerValue(un.val);4115 const payload = try o.lowerValue(pt, un.val);
4148 const payload_ty = payload.typeOf(&o.builder);4116 const payload_ty = payload.typeOf(&o.builder);
4149 if (payload_ty != union_ty.structFields(&o.builder)[4117 if (payload_ty != union_ty.structFields(&o.builder)[
4150 @intFromBool(layout.tag_align.compare(.gte, layout.payload_align))4118 @intFromBool(layout.tag_align.compare(.gte, layout.payload_align))
...@@ -4163,10 +4131,10 @@ pub const Object = struct {...@@ -4163,10 +4131,10 @@ pub const Object = struct {
4163 const bits = ty.bitSize(zcu);4131 const bits = ty.bitSize(zcu);
4164 const llvm_int_ty = try o.builder.intType(@intCast(bits));4132 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);
4167 }4135 }
41684136
4169 const union_val = try o.lowerValue(un.val);4137 const union_val = try o.lowerValue(pt, un.val);
4170 need_unnamed = true;4138 need_unnamed = true;
4171 break :p union_val;4139 break :p union_val;
4172 };4140 };
...@@ -4176,7 +4144,7 @@ pub const Object = struct {...@@ -4176,7 +4144,7 @@ pub const Object = struct {
4176 try o.builder.structType(union_ty.structKind(&o.builder), &.{payload_ty})4144 try o.builder.structType(union_ty.structKind(&o.builder), &.{payload_ty})
4177 else4145 else
4178 union_ty, &.{payload});4146 union_ty, &.{payload});
4179 const tag = try o.lowerValue(un.tag);4147 const tag = try o.lowerValue(pt, un.tag);
4180 const tag_ty = tag.typeOf(&o.builder);4148 const tag_ty = tag.typeOf(&o.builder);
4181 var fields: [3]Builder.Type = undefined;4149 var fields: [3]Builder.Type = undefined;
4182 var vals: [3]Builder.Constant = undefined;4150 var vals: [3]Builder.Constant = undefined;
...@@ -4204,48 +4172,50 @@ pub const Object = struct {...@@ -4204,48 +4172,50 @@ pub const Object = struct {
42044172
4205 fn lowerBigInt(4173 fn lowerBigInt(
4206 o: *Object,4174 o: *Object,
4175 pt: Zcu.PerThread,
4207 ty: Type,4176 ty: Type,
4208 bigint: std.math.big.int.Const,4177 bigint: std.math.big.int.Const,
4209 ) Allocator.Error!Builder.Constant {4178 ) Allocator.Error!Builder.Constant {
4210 const zcu = o.pt.zcu;4179 const zcu = pt.zcu;
4211 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint);4180 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint);
4212 }4181 }
42134182
4214 fn lowerPtr(4183 fn lowerPtr(
4215 o: *Object,4184 o: *Object,
4185 pt: Zcu.PerThread,
4216 ptr_val: InternPool.Index,4186 ptr_val: InternPool.Index,
4217 prev_offset: u64,4187 prev_offset: u64,
4218 ) Error!Builder.Constant {4188 ) Error!Builder.Constant {
4219 const pt = o.pt;
4220 const zcu = pt.zcu;4189 const zcu = pt.zcu;
4221 const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr;4190 const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr;
4222 const offset: u64 = prev_offset + ptr.byte_offset;4191 const offset: u64 = prev_offset + ptr.byte_offset;
4223 return switch (ptr.base_addr) {4192 return switch (ptr.base_addr) {
4224 .nav => |nav| {4193 .nav => |nav| {
4225 const base_ptr = try o.lowerNavRefValue(nav);4194 const base_ptr = try o.lowerNavRefValue(pt, nav);
4226 return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{4195 return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{
4227 try o.builder.intConst(.i64, offset),4196 try o.builder.intConst(.i64, offset),
4228 });4197 });
4229 },4198 },
4230 .uav => |uav| {4199 .uav => |uav| {
4231 const base_ptr = try o.lowerUavRef(uav);4200 const base_ptr = try o.lowerUavRef(pt, uav);
4232 return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{4201 return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{
4233 try o.builder.intConst(.i64, offset),4202 try o.builder.intConst(.i64, offset),
4234 });4203 });
4235 },4204 },
4236 .int => try o.builder.castConst(4205 .int => try o.builder.castConst(
4237 .inttoptr,4206 .inttoptr,
4238 try o.builder.intConst(try o.lowerType(Type.usize), offset),4207 try o.builder.intConst(try o.lowerType(pt, Type.usize), offset),
4239 try o.lowerType(Type.fromInterned(ptr.ty)),4208 try o.lowerType(pt, Type.fromInterned(ptr.ty)),
4240 ),4209 ),
4241 .eu_payload => |eu_ptr| try o.lowerPtr(4210 .eu_payload => |eu_ptr| try o.lowerPtr(
4211 pt,
4242 eu_ptr,4212 eu_ptr,
4243 offset + @import("../codegen.zig").errUnionPayloadOffset(4213 offset + @import("../codegen.zig").errUnionPayloadOffset(
4244 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu),4214 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu),
4245 zcu,4215 zcu,
4246 ),4216 ),
4247 ),4217 ),
4248 .opt_payload => |opt_ptr| try o.lowerPtr(opt_ptr, offset),4218 .opt_payload => |opt_ptr| try o.lowerPtr(pt, opt_ptr, offset),
4249 .field => |field| {4219 .field => |field| {
4250 const agg_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu);4220 const agg_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu);
4251 const field_off: u64 = switch (agg_ty.zigTypeTag(zcu)) {4221 const field_off: u64 = switch (agg_ty.zigTypeTag(zcu)) {
...@@ -4263,7 +4233,7 @@ pub const Object = struct {...@@ -4263,7 +4233,7 @@ pub const Object = struct {
4263 },4233 },
4264 else => unreachable,4234 else => unreachable,
4265 };4235 };
4266 return o.lowerPtr(field.base, offset + field_off);4236 return o.lowerPtr(pt, field.base, offset + field_off);
4267 },4237 },
4268 .arr_elem, .comptime_field, .comptime_alloc => unreachable,4238 .arr_elem, .comptime_field, .comptime_alloc => unreachable,
4269 };4239 };
...@@ -4273,9 +4243,9 @@ pub const Object = struct {...@@ -4273,9 +4243,9 @@ pub const Object = struct {
4273 /// Maybe the logic could be unified.4243 /// Maybe the logic could be unified.
4274 fn lowerUavRef(4244 fn lowerUavRef(
4275 o: *Object,4245 o: *Object,
4246 pt: Zcu.PerThread,
4276 uav: InternPool.Key.Ptr.BaseAddr.Uav,4247 uav: InternPool.Key.Ptr.BaseAddr.Uav,
4277 ) Error!Builder.Constant {4248 ) Error!Builder.Constant {
4278 const pt = o.pt;
4279 const zcu = pt.zcu;4249 const zcu = pt.zcu;
4280 const ip = &zcu.intern_pool;4250 const ip = &zcu.intern_pool;
4281 const uav_val = uav.val;4251 const uav_val = uav.val;
...@@ -4292,25 +4262,24 @@ pub const Object = struct {...@@ -4292,25 +4262,24 @@ pub const Object = struct {
42924262
4293 const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn";4263 const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn";
4294 if ((!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) or4264 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
4297 if (is_fn_body)4267 if (is_fn_body)
4298 @panic("TODO");4268 @panic("TODO");
42994269
4300 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target);4270 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target);
4301 const alignment = ptr_ty.ptrAlignment(zcu);4271 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
4304 const llvm_val = try o.builder.convConst(4274 const llvm_val = try o.builder.convConst(
4305 llvm_global.toConst(),4275 llvm_global.toConst(),
4306 try o.builder.ptrType(llvm_addr_space),4276 try o.builder.ptrType(llvm_addr_space),
4307 );4277 );
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));
4310 }4280 }
43114281
4312 fn lowerNavRefValue(o: *Object, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant {4282 fn lowerNavRefValue(o: *Object, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant {
4313 const pt = o.pt;
4314 const zcu = pt.zcu;4283 const zcu = pt.zcu;
4315 const ip = &zcu.intern_pool;4284 const ip = &zcu.intern_pool;
43164285
...@@ -4323,24 +4292,24 @@ pub const Object = struct {...@@ -4323,24 +4292,24 @@ pub const Object = struct {
4323 if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or4292 if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or
4324 (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic))4293 (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic))
4325 {4294 {
4326 return o.lowerPtrToVoid(ptr_ty);4295 return o.lowerPtrToVoid(pt, ptr_ty);
4327 }4296 }
43284297
4329 const llvm_global = if (is_fn_body)4298 const llvm_global = if (is_fn_body)
4330 (try o.resolveLlvmFunction(nav_index)).ptrConst(&o.builder).global4299 (try o.resolveLlvmFunction(pt, nav_index)).ptrConst(&o.builder).global
4331 else4300 else
4332 (try o.resolveGlobalNav(nav_index)).ptrConst(&o.builder).global;4301 (try o.resolveGlobalNav(pt, nav_index)).ptrConst(&o.builder).global;
43334302
4334 const llvm_val = try o.builder.convConst(4303 const llvm_val = try o.builder.convConst(
4335 llvm_global.toConst(),4304 llvm_global.toConst(),
4336 try o.builder.ptrType(toLlvmAddressSpace(nav.getAddrspace(), zcu.getTarget())),4305 try o.builder.ptrType(toLlvmAddressSpace(nav.getAddrspace(), zcu.getTarget())),
4337 );4306 );
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));
4340 }4309 }
43414310
4342 fn lowerPtrToVoid(o: *Object, ptr_ty: Type) Allocator.Error!Builder.Constant {4311 fn lowerPtrToVoid(o: *Object, pt: Zcu.PerThread, ptr_ty: Type) Allocator.Error!Builder.Constant {
4343 const zcu = o.pt.zcu;4312 const zcu = pt.zcu;
4344 // Even though we are pointing at something which has zero bits (e.g. `void`),4313 // Even though we are pointing at something which has zero bits (e.g. `void`),
4345 // Pointers are defined to have bits. So we must return something here.4314 // Pointers are defined to have bits. So we must return something here.
4346 // The value cannot be undefined, because we use the `nonnull` annotation4315 // The value cannot be undefined, because we use the `nonnull` annotation
...@@ -4358,8 +4327,8 @@ pub const Object = struct {...@@ -4358,8 +4327,8 @@ pub const Object = struct {
4358 64 => 0xaaaaaaaa_aaaaaaaa,4327 64 => 0xaaaaaaaa_aaaaaaaa,
4359 else => unreachable,4328 else => unreachable,
4360 };4329 };
4361 const llvm_usize = try o.lowerType(Type.usize);4330 const llvm_usize = try o.lowerType(pt, Type.usize);
4362 const llvm_ptr_ty = try o.lowerType(ptr_ty);4331 const llvm_ptr_ty = try o.lowerType(pt, ptr_ty);
4363 return o.builder.castConst(.inttoptr, try o.builder.intConst(llvm_usize, int), llvm_ptr_ty);4332 return o.builder.castConst(.inttoptr, try o.builder.intConst(llvm_usize, int), llvm_ptr_ty);
4364 }4333 }
43654334
...@@ -4367,8 +4336,7 @@ pub const Object = struct {...@@ -4367,8 +4336,7 @@ pub const Object = struct {
4367 /// widen it before using it and then truncate the result.4336 /// widen it before using it and then truncate the result.
4368 /// RMW exchange of floating-point values is bitcasted to same-sized integer4337 /// RMW exchange of floating-point values is bitcasted to same-sized integer
4369 /// types to work around a LLVM deficiency when targeting ARM/AArch64.4338 /// 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 {4339 fn getAtomicAbiType(o: *Object, pt: Zcu.PerThread, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type {
4371 const pt = o.pt;
4372 const zcu = pt.zcu;4340 const zcu = pt.zcu;
4373 const int_ty = switch (ty.zigTypeTag(zcu)) {4341 const int_ty = switch (ty.zigTypeTag(zcu)) {
4374 .int => ty,4342 .int => ty,
...@@ -4390,13 +4358,13 @@ pub const Object = struct {...@@ -4390,13 +4358,13 @@ pub const Object = struct {
43904358
4391 fn addByValParamAttrs(4359 fn addByValParamAttrs(
4392 o: *Object,4360 o: *Object,
4361 pt: Zcu.PerThread,
4393 attributes: *Builder.FunctionAttributes.Wip,4362 attributes: *Builder.FunctionAttributes.Wip,
4394 param_ty: Type,4363 param_ty: Type,
4395 param_index: u32,4364 param_index: u32,
4396 fn_info: InternPool.Key.FuncType,4365 fn_info: InternPool.Key.FuncType,
4397 llvm_arg_i: u32,4366 llvm_arg_i: u32,
4398 ) Allocator.Error!void {4367 ) Allocator.Error!void {
4399 const pt = o.pt;
4400 const zcu = pt.zcu;4368 const zcu = pt.zcu;
4401 if (param_ty.isPtrAtRuntime(zcu)) {4369 if (param_ty.isPtrAtRuntime(zcu)) {
4402 const ptr_info = param_ty.ptrInfo(zcu);4370 const ptr_info = param_ty.ptrInfo(zcu);
...@@ -4416,7 +4384,7 @@ pub const Object = struct {...@@ -4416,7 +4384,7 @@ pub const Object = struct {
4416 .x86_64_interrupt,4384 .x86_64_interrupt,
4417 .x86_interrupt,4385 .x86_interrupt,
4418 => {4386 => {
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));
4420 try attributes.addParamAttr(llvm_arg_i, .{ .byval = child_type }, &o.builder);4388 try attributes.addParamAttr(llvm_arg_i, .{ .byval = child_type }, &o.builder);
4421 },4389 },
4422 }4390 }
...@@ -4455,14 +4423,14 @@ pub const Object = struct {...@@ -4455,14 +4423,14 @@ pub const Object = struct {
4455 });4423 });
4456 }4424 }
44574425
4458 fn getCmpLtErrorsLenFunction(o: *Object) !Builder.Function.Index {4426 fn getCmpLtErrorsLenFunction(o: *Object, pt: Zcu.PerThread) !Builder.Function.Index {
4459 const name = try o.builder.strtabString(lt_errors_fn_name);4427 const name = try o.builder.strtabString(lt_errors_fn_name);
4460 if (o.builder.getGlobal(name)) |llvm_fn| return llvm_fn.ptrConst(&o.builder).kind.function;4428 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;
4463 const target = &zcu.root_mod.resolved_target.result;4431 const target = &zcu.root_mod.resolved_target.result;
4464 const function_index = try o.builder.addFunction(4432 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),
4466 name,4434 name,
4467 toLlvmAddressSpace(.generic, target),4435 toLlvmAddressSpace(.generic, target),
4468 );4436 );
...@@ -4477,8 +4445,7 @@ pub const Object = struct {...@@ -4477,8 +4445,7 @@ pub const Object = struct {
4477 return function_index;4445 return function_index;
4478 }4446 }
44794447
4480 fn getEnumTagNameFunction(o: *Object, enum_ty: Type) !Builder.Function.Index {4448 fn getEnumTagNameFunction(o: *Object, pt: Zcu.PerThread, enum_ty: Type) !Builder.Function.Index {
4481 const pt = o.pt;
4482 const zcu = pt.zcu;4449 const zcu = pt.zcu;
4483 const ip = &zcu.intern_pool;4450 const ip = &zcu.intern_pool;
4484 const enum_type = ip.loadEnumType(enum_ty.toIntern());4451 const enum_type = ip.loadEnumType(enum_ty.toIntern());
...@@ -4487,11 +4454,11 @@ pub const Object = struct {...@@ -4487,11 +4454,11 @@ pub const Object = struct {
4487 if (gop.found_existing) return gop.value_ptr.ptrConst(&o.builder).kind.function;4454 if (gop.found_existing) return gop.value_ptr.ptrConst(&o.builder).kind.function;
4488 errdefer assert(o.enum_tag_name_map.remove(enum_ty.toIntern()));4455 errdefer assert(o.enum_tag_name_map.remove(enum_ty.toIntern()));
44894456
4490 const usize_ty = try o.lowerType(Type.usize);4457 const usize_ty = try o.lowerType(pt, Type.usize);
4491 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);4458 const ret_ty = try o.lowerType(pt, Type.slice_const_u8_sentinel_0);
4492 const target = &zcu.root_mod.resolved_target.result;4459 const target = &zcu.root_mod.resolved_target.result;
4493 const function_index = try o.builder.addFunction(4460 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),
4495 try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_type.name.fmt(ip)}),4462 try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_type.name.fmt(ip)}),
4496 toLlvmAddressSpace(.generic, target),4463 toLlvmAddressSpace(.generic, target),
4497 );4464 );
...@@ -4536,6 +4503,7 @@ pub const Object = struct {...@@ -4536,6 +4503,7 @@ pub const Object = struct {
45364503
4537 const return_block = try wip.block(1, "Name");4504 const return_block = try wip.block(1, "Name");
4538 const this_tag_int_value = try o.lowerValue(4505 const this_tag_int_value = try o.lowerValue(
4506 pt,
4539 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),4507 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),
4540 );4508 );
4541 try wip_switch.addCase(this_tag_int_value, return_block, &wip);4509 try wip_switch.addCase(this_tag_int_value, return_block, &wip);
...@@ -4555,10 +4523,11 @@ pub const Object = struct {...@@ -4555,10 +4523,11 @@ pub const Object = struct {
4555pub const NavGen = struct {4523pub const NavGen = struct {
4556 object: *Object,4524 object: *Object,
4557 nav_index: InternPool.Nav.Index,4525 nav_index: InternPool.Nav.Index,
4526 pt: Zcu.PerThread,
4558 err_msg: ?*Zcu.ErrorMsg,4527 err_msg: ?*Zcu.ErrorMsg,
45594528
4560 fn ownerModule(ng: NavGen) *Package.Module {4529 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.?;
4562 }4531 }
45634532
4564 fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {4533 fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {
...@@ -4566,14 +4535,14 @@ pub const NavGen = struct {...@@ -4566,14 +4535,14 @@ pub const NavGen = struct {
4566 assert(ng.err_msg == null);4535 assert(ng.err_msg == null);
4567 const o = ng.object;4536 const o = ng.object;
4568 const gpa = o.gpa;4537 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);
4570 ng.err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);4539 ng.err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
4571 return error.CodegenFail;4540 return error.CodegenFail;
4572 }4541 }
45734542
4574 fn genDecl(ng: *NavGen) !void {4543 fn genDecl(ng: *NavGen) !void {
4575 const o = ng.object;4544 const o = ng.object;
4576 const pt = o.pt;4545 const pt = ng.pt;
4577 const zcu = pt.zcu;4546 const zcu = pt.zcu;
4578 const ip = &zcu.intern_pool;4547 const ip = &zcu.intern_pool;
4579 const nav_index = ng.nav_index;4548 const nav_index = ng.nav_index;
...@@ -4588,16 +4557,16 @@ pub const NavGen = struct {...@@ -4588,16 +4557,16 @@ pub const NavGen = struct {
4588 const ty = Type.fromInterned(nav.typeOf(ip));4557 const ty = Type.fromInterned(nav.typeOf(ip));
45894558
4590 if (linkage != .internal and ip.isFunctionType(ty.toIntern())) {4559 if (linkage != .internal and ip.isFunctionType(ty.toIntern())) {
4591 _ = try o.resolveLlvmFunction(owner_nav);4560 _ = try o.resolveLlvmFunction(pt, owner_nav);
4592 } else {4561 } else {
4593 const variable_index = try o.resolveGlobalNav(nav_index);4562 const variable_index = try o.resolveGlobalNav(pt, nav_index);
4594 variable_index.setAlignment(pt.navAlignment(nav_index).toLlvm(), &o.builder);4563 variable_index.setAlignment(pt.navAlignment(nav_index).toLlvm(), &o.builder);
4595 if (resolved.@"linksection".toSlice(ip)) |section|4564 if (resolved.@"linksection".toSlice(ip)) |section|
4596 variable_index.setSection(try o.builder.string(section), &o.builder);4565 variable_index.setSection(try o.builder.string(section), &o.builder);
4597 if (is_const) variable_index.setMutability(.constant, &o.builder);4566 if (is_const) variable_index.setMutability(.constant, &o.builder);
4598 try variable_index.setInitializer(switch (init_val) {4567 try variable_index.setInitializer(switch (init_val) {
4599 .none => .no_init,4568 .none => .no_init,
4600 else => try o.lowerValue(init_val),4569 else => try o.lowerValue(pt, init_val),
4601 }, &o.builder);4570 }, &o.builder);
4602 variable_index.setVisibility(visibility, &o.builder);4571 variable_index.setVisibility(visibility, &o.builder);
46034572
...@@ -4609,7 +4578,7 @@ pub const NavGen = struct {...@@ -4609,7 +4578,7 @@ pub const NavGen = struct {
4609 const line_number = zcu.navSrcLine(nav_index) + 1;4578 const line_number = zcu.navSrcLine(nav_index) + 1;
46104579
4611 if (!mod.strip) {4580 if (!mod.strip) {
4612 const debug_file = try o.getDebugFile(file_scope);4581 const debug_file = try o.getDebugFile(pt, file_scope);
46134582
4614 const debug_global_var = try o.builder.debugGlobalVar(4583 const debug_global_var = try o.builder.debugGlobalVar(
4615 try o.builder.metadataString(nav.name.toSlice(ip)), // Name4584 try o.builder.metadataString(nav.name.toSlice(ip)), // Name
...@@ -4617,7 +4586,7 @@ pub const NavGen = struct {...@@ -4617,7 +4586,7 @@ pub const NavGen = struct {
4617 debug_file, // File4586 debug_file, // File
4618 debug_file, // Scope4587 debug_file, // Scope
4619 line_number,4588 line_number,
4620 try o.lowerDebugType(ty),4589 try o.lowerDebugType(pt, ty),
4621 variable_index,4590 variable_index,
4622 .{ .local = linkage == .internal },4591 .{ .local = linkage == .internal },
4623 );4592 );
...@@ -4814,16 +4783,17 @@ pub const FuncGen = struct {...@@ -4814,16 +4783,17 @@ pub const FuncGen = struct {
4814 const gop = try self.func_inst_table.getOrPut(gpa, inst);4783 const gop = try self.func_inst_table.getOrPut(gpa, inst);
4815 if (gop.found_existing) return gop.value_ptr.*;4784 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)).?);
4818 gop.value_ptr.* = llvm_val.toValue();4787 gop.value_ptr.* = llvm_val.toValue();
4819 return llvm_val.toValue();4788 return llvm_val.toValue();
4820 }4789 }
48214790
4822 fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant {4791 fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant {
4823 const o = self.ng.object;4792 const o = self.ng.object;
4824 const zcu = o.pt.zcu;4793 const pt = self.ng.pt;
4794 const zcu = pt.zcu;
4825 const ty = val.typeOf(zcu);4795 const ty = val.typeOf(zcu);
4826 const llvm_val = try o.lowerValue(val.toIntern());4796 const llvm_val = try o.lowerValue(pt, val.toIntern());
4827 if (!isByRef(ty, zcu)) return llvm_val;4797 if (!isByRef(ty, zcu)) return llvm_val;
48284798
4829 // We have an LLVM value but we need to create a global constant and4799 // We have an LLVM value but we need to create a global constant and
...@@ -4847,7 +4817,7 @@ pub const FuncGen = struct {...@@ -4847,7 +4817,7 @@ pub const FuncGen = struct {
48474817
4848 fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) Error!void {4818 fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) Error!void {
4849 const o = self.ng.object;4819 const o = self.ng.object;
4850 const zcu = o.pt.zcu;4820 const zcu = self.ng.pt.zcu;
4851 const ip = &zcu.intern_pool;4821 const ip = &zcu.intern_pool;
4852 const air_tags = self.air.instructions.items(.tag);4822 const air_tags = self.air.instructions.items(.tag);
4853 switch (coverage_point) {4823 switch (coverage_point) {
...@@ -5173,7 +5143,7 @@ pub const FuncGen = struct {...@@ -5173,7 +5143,7 @@ pub const FuncGen = struct {
51735143
5174 if (maybe_inline_func) |inline_func| {5144 if (maybe_inline_func) |inline_func| {
5175 const o = self.ng.object;5145 const o = self.ng.object;
5176 const pt = o.pt;5146 const pt = self.ng.pt;
5177 const zcu = pt.zcu;5147 const zcu = pt.zcu;
5178 const ip = &zcu.intern_pool;5148 const ip = &zcu.intern_pool;
51795149
...@@ -5182,7 +5152,7 @@ pub const FuncGen = struct {...@@ -5182,7 +5152,7 @@ pub const FuncGen = struct {
5182 const file_scope = zcu.navFileScopeIndex(func.owner_nav);5152 const file_scope = zcu.navFileScopeIndex(func.owner_nav);
5183 const mod = zcu.fileByIndex(file_scope).mod.?;5153 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
5187 const line_number = zcu.navSrcLine(func.owner_nav) + 1;5157 const line_number = zcu.navSrcLine(func.owner_nav) + 1;
5188 self.inlined = self.wip.debug_location;5158 self.inlined = self.wip.debug_location;
...@@ -5198,7 +5168,7 @@ pub const FuncGen = struct {...@@ -5198,7 +5168,7 @@ pub const FuncGen = struct {
5198 try o.builder.metadataString(nav.fqn.toSlice(&zcu.intern_pool)),5168 try o.builder.metadataString(nav.fqn.toSlice(&zcu.intern_pool)),
5199 line_number,5169 line_number,
5200 line_number + func.lbrace_line,5170 line_number + func.lbrace_line,
5201 try o.lowerDebugType(fn_ty),5171 try o.lowerDebugType(pt, fn_ty),
5202 .{5172 .{
5203 .di_flags = .{ .StaticMember = true },5173 .di_flags = .{ .StaticMember = true },
5204 .sp_flags = .{5174 .sp_flags = .{
...@@ -5255,7 +5225,7 @@ pub const FuncGen = struct {...@@ -5255,7 +5225,7 @@ pub const FuncGen = struct {
5255 const extra = self.air.extraData(Air.Call, pl_op.payload);5225 const extra = self.air.extraData(Air.Call, pl_op.payload);
5256 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[extra.end..][0..extra.data.args_len]);5226 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[extra.end..][0..extra.data.args_len]);
5257 const o = self.ng.object;5227 const o = self.ng.object;
5258 const pt = o.pt;5228 const pt = self.ng.pt;
5259 const zcu = pt.zcu;5229 const zcu = pt.zcu;
5260 const ip = &zcu.intern_pool;5230 const ip = &zcu.intern_pool;
5261 const callee_ty = self.typeOf(pl_op.operand);5231 const callee_ty = self.typeOf(pl_op.operand);
...@@ -5287,7 +5257,7 @@ pub const FuncGen = struct {...@@ -5287,7 +5257,7 @@ pub const FuncGen = struct {
5287 }5257 }
52885258
5289 const ret_ptr = if (!sret) null else blk: {5259 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);
5291 try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder);5261 try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder);
52925262
5293 const alignment = return_type.abiAlignment(zcu).toLlvm();5263 const alignment = return_type.abiAlignment(zcu).toLlvm();
...@@ -5302,14 +5272,14 @@ pub const FuncGen = struct {...@@ -5302,14 +5272,14 @@ pub const FuncGen = struct {
5302 try llvm_args.append(self.err_ret_trace);5272 try llvm_args.append(self.err_ret_trace);
5303 }5273 }
53045274
5305 var it = iterateParamTypes(o, fn_info);5275 var it = iterateParamTypes(o, pt, fn_info);
5306 while (try it.nextCall(self, args)) |lowering| switch (lowering) {5276 while (try it.nextCall(self, args)) |lowering| switch (lowering) {
5307 .no_bits => continue,5277 .no_bits => continue,
5308 .byval => {5278 .byval => {
5309 const arg = args[it.zig_index - 1];5279 const arg = args[it.zig_index - 1];
5310 const param_ty = self.typeOf(arg);5280 const param_ty = self.typeOf(arg);
5311 const llvm_arg = try self.resolveInst(arg);5281 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);
5313 if (isByRef(param_ty, zcu)) {5283 if (isByRef(param_ty, zcu)) {
5314 const alignment = param_ty.abiAlignment(zcu).toLlvm();5284 const alignment = param_ty.abiAlignment(zcu).toLlvm();
5315 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");5285 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");
...@@ -5338,7 +5308,7 @@ pub const FuncGen = struct {...@@ -5338,7 +5308,7 @@ pub const FuncGen = struct {
5338 const llvm_arg = try self.resolveInst(arg);5308 const llvm_arg = try self.resolveInst(arg);
53395309
5340 const alignment = param_ty.abiAlignment(zcu).toLlvm();5310 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);
5342 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);5312 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);
5343 if (isByRef(param_ty, zcu)) {5313 if (isByRef(param_ty, zcu)) {
5344 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");5314 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");
...@@ -5409,7 +5379,7 @@ pub const FuncGen = struct {...@@ -5409,7 +5379,7 @@ pub const FuncGen = struct {
5409 llvm_arg = ptr;5379 llvm_arg = ptr;
5410 }5380 }
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).?);
5413 const array_ty = try o.builder.arrayType(count, float_ty);5383 const array_ty = try o.builder.arrayType(count, float_ty);
54145384
5415 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");5385 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");
...@@ -5436,7 +5406,7 @@ pub const FuncGen = struct {...@@ -5436,7 +5406,7 @@ pub const FuncGen = struct {
54365406
5437 {5407 {
5438 // Add argument attributes.5408 // Add argument attributes.
5439 it = iterateParamTypes(o, fn_info);5409 it = iterateParamTypes(o, pt, fn_info);
5440 it.llvm_index += @intFromBool(sret);5410 it.llvm_index += @intFromBool(sret);
5441 it.llvm_index += @intFromBool(err_return_tracing);5411 it.llvm_index += @intFromBool(err_return_tracing);
5442 while (try it.next()) |lowering| switch (lowering) {5412 while (try it.next()) |lowering| switch (lowering) {
...@@ -5444,13 +5414,13 @@ pub const FuncGen = struct {...@@ -5444,13 +5414,13 @@ pub const FuncGen = struct {
5444 const param_index = it.zig_index - 1;5414 const param_index = it.zig_index - 1;
5445 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);5415 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
5446 if (!isByRef(param_ty, zcu)) {5416 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);
5448 }5418 }
5449 },5419 },
5450 .byref => {5420 .byref => {
5451 const param_index = it.zig_index - 1;5421 const param_index = it.zig_index - 1;
5452 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);5422 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);
5454 const alignment = param_ty.abiAlignment(zcu).toLlvm();5424 const alignment = param_ty.abiAlignment(zcu).toLlvm();
5455 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);5425 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);
5456 },5426 },
...@@ -5502,7 +5472,7 @@ pub const FuncGen = struct {...@@ -5502,7 +5472,7 @@ pub const FuncGen = struct {
5502 },5472 },
5503 toLlvmCallConvTag(fn_info.cc, target).?,5473 toLlvmCallConvTag(fn_info.cc, target).?,
5504 try attributes.finish(&o.builder),5474 try attributes.finish(&o.builder),
5505 try o.lowerType(zig_fn_ty),5475 try o.lowerType(pt, zig_fn_ty),
5506 llvm_fn,5476 llvm_fn,
5507 llvm_args.items,5477 llvm_args.items,
5508 "",5478 "",
...@@ -5516,7 +5486,7 @@ pub const FuncGen = struct {...@@ -5516,7 +5486,7 @@ pub const FuncGen = struct {
5516 return .none;5486 return .none;
5517 }5487 }
55185488
5519 const llvm_ret_ty = try o.lowerType(return_type);5489 const llvm_ret_ty = try o.lowerType(pt, return_type);
5520 if (ret_ptr) |rp| {5490 if (ret_ptr) |rp| {
5521 if (isByRef(return_type, zcu)) {5491 if (isByRef(return_type, zcu)) {
5522 return rp;5492 return rp;
...@@ -5527,7 +5497,7 @@ pub const FuncGen = struct {...@@ -5527,7 +5497,7 @@ pub const FuncGen = struct {
5527 }5497 }
5528 }5498 }
55295499
5530 const abi_ret_ty = try lowerFnRetTy(o, fn_info);5500 const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info);
55315501
5532 if (abi_ret_ty != llvm_ret_ty) {5502 if (abi_ret_ty != llvm_ret_ty) {
5533 // In this case the function return type is honoring the calling convention by having5503 // In this case the function return type is honoring the calling convention by having
...@@ -5556,11 +5526,12 @@ pub const FuncGen = struct {...@@ -5556,11 +5526,12 @@ pub const FuncGen = struct {
55565526
5557 fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) !void {5527 fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) !void {
5558 const o = fg.ng.object;5528 const o = fg.ng.object;
5559 const zcu = o.pt.zcu;5529 const pt = fg.ng.pt;
5530 const zcu = pt.zcu;
5560 const target = zcu.getTarget();5531 const target = zcu.getTarget();
5561 const panic_func = zcu.funcInfo(zcu.builtin_decl_values.get(panic_id.toBuiltin()));5532 const panic_func = zcu.funcInfo(zcu.builtin_decl_values.get(panic_id.toBuiltin()));
5562 const fn_info = zcu.typeToFunc(.fromInterned(panic_func.ty)).?;5533 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
5565 const has_err_trace = zcu.comp.config.any_error_tracing and fn_info.cc == .auto;5536 const has_err_trace = zcu.comp.config.any_error_tracing and fn_info.cc == .auto;
5566 if (has_err_trace) assert(fg.err_ret_trace != .none);5537 if (has_err_trace) assert(fg.err_ret_trace != .none);
...@@ -5579,7 +5550,7 @@ pub const FuncGen = struct {...@@ -5579,7 +5550,7 @@ pub const FuncGen = struct {
55795550
5580 fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !void {5551 fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !void {
5581 const o = self.ng.object;5552 const o = self.ng.object;
5582 const pt = o.pt;5553 const pt = self.ng.pt;
5583 const zcu = pt.zcu;5554 const zcu = pt.zcu;
5584 const ip = &zcu.intern_pool;5555 const ip = &zcu.intern_pool;
5585 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5556 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
...@@ -5599,7 +5570,7 @@ pub const FuncGen = struct {...@@ -5599,7 +5570,7 @@ pub const FuncGen = struct {
5599 // https://github.com/ziglang/zig/issues/153375570 // https://github.com/ziglang/zig/issues/15337
5600 break :undef;5571 break :undef;
5601 }5572 }
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));
5603 _ = try self.wip.callMemSet(5574 _ = try self.wip.callMemSet(
5604 self.ret_ptr,5575 self.ret_ptr,
5605 ptr_ty.ptrAlignment(zcu).toLlvm(),5576 ptr_ty.ptrAlignment(zcu).toLlvm(),
...@@ -5635,14 +5606,14 @@ pub const FuncGen = struct {...@@ -5635,14 +5606,14 @@ pub const FuncGen = struct {
5635 // Functions with an empty error set are emitted with an error code5606 // Functions with an empty error set are emitted with an error code
5636 // return type and return zero so they can be function pointers coerced5607 // return type and return zero so they can be function pointers coerced
5637 // to functions that return anyerror.5608 // 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));
5639 } else {5610 } else {
5640 _ = try self.wip.retVoid();5611 _ = try self.wip.retVoid();
5641 }5612 }
5642 return;5613 return;
5643 }5614 }
56445615
5645 const abi_ret_ty = try lowerFnRetTy(o, fn_info);5616 const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info);
5646 const operand = try self.resolveInst(un_op);5617 const operand = try self.resolveInst(un_op);
5647 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false;5618 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false;
5648 const alignment = ret_ty.abiAlignment(zcu).toLlvm();5619 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
...@@ -5650,7 +5621,7 @@ pub const FuncGen = struct {...@@ -5650,7 +5621,7 @@ pub const FuncGen = struct {
5650 if (val_is_undef and safety) {5621 if (val_is_undef and safety) {
5651 const llvm_ret_ty = operand.typeOfWip(&self.wip);5622 const llvm_ret_ty = operand.typeOfWip(&self.wip);
5652 const rp = try self.buildAlloca(llvm_ret_ty, alignment);5623 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));
5654 _ = try self.wip.callMemSet(5625 _ = try self.wip.callMemSet(
5655 rp,5626 rp,
5656 alignment,5627 alignment,
...@@ -5688,7 +5659,7 @@ pub const FuncGen = struct {...@@ -5688,7 +5659,7 @@ pub const FuncGen = struct {
56885659
5689 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !void {5660 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !void {
5690 const o = self.ng.object;5661 const o = self.ng.object;
5691 const pt = o.pt;5662 const pt = self.ng.pt;
5692 const zcu = pt.zcu;5663 const zcu = pt.zcu;
5693 const ip = &zcu.intern_pool;5664 const ip = &zcu.intern_pool;
5694 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5665 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
...@@ -5700,7 +5671,7 @@ pub const FuncGen = struct {...@@ -5700,7 +5671,7 @@ pub const FuncGen = struct {
5700 // Functions with an empty error set are emitted with an error code5671 // Functions with an empty error set are emitted with an error code
5701 // return type and return zero so they can be function pointers coerced5672 // return type and return zero so they can be function pointers coerced
5702 // to functions that return anyerror.5673 // 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));
5704 } else {5675 } else {
5705 _ = try self.wip.retVoid();5676 _ = try self.wip.retVoid();
5706 }5677 }
...@@ -5711,7 +5682,7 @@ pub const FuncGen = struct {...@@ -5711,7 +5682,7 @@ pub const FuncGen = struct {
5711 return;5682 return;
5712 }5683 }
5713 const ptr = try self.resolveInst(un_op);5684 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);
5715 const alignment = ret_ty.abiAlignment(zcu).toLlvm();5686 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
5716 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, ""));5687 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, ""));
5717 return;5688 return;
...@@ -5719,22 +5690,23 @@ pub const FuncGen = struct {...@@ -5719,22 +5690,23 @@ pub const FuncGen = struct {
57195690
5720 fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5691 fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5721 const o = self.ng.object;5692 const o = self.ng.object;
5693 const pt = self.ng.pt;
5722 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5694 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5723 const list = try self.resolveInst(ty_op.operand);5695 const list = try self.resolveInst(ty_op.operand);
5724 const arg_ty = ty_op.ty.toType();5696 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
5727 return self.wip.vaArg(list, llvm_arg_ty, "");5699 return self.wip.vaArg(list, llvm_arg_ty, "");
5728 }5700 }
57295701
5730 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5702 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5731 const o = self.ng.object;5703 const o = self.ng.object;
5732 const pt = o.pt;5704 const pt = self.ng.pt;
5733 const zcu = pt.zcu;5705 const zcu = pt.zcu;
5734 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5706 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5735 const src_list = try self.resolveInst(ty_op.operand);5707 const src_list = try self.resolveInst(ty_op.operand);
5736 const va_list_ty = ty_op.ty.toType();5708 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
5739 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();5711 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
5740 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);5712 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);
...@@ -5756,10 +5728,10 @@ pub const FuncGen = struct {...@@ -5756,10 +5728,10 @@ pub const FuncGen = struct {
57565728
5757 fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5729 fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5758 const o = self.ng.object;5730 const o = self.ng.object;
5759 const pt = o.pt;5731 const pt = self.ng.pt;
5760 const zcu = pt.zcu;5732 const zcu = pt.zcu;
5761 const va_list_ty = self.typeOfIndex(inst);5733 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
5764 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();5736 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
5765 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);5737 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);
...@@ -5799,9 +5771,10 @@ pub const FuncGen = struct {...@@ -5799,9 +5771,10 @@ pub const FuncGen = struct {
57995771
5800 fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5772 fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5801 const o = self.ng.object;5773 const o = self.ng.object;
5774 const pt = self.ng.pt;
5802 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5775 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5803 const operand = try self.resolveInst(un_op);5776 const operand = try self.resolveInst(un_op);
5804 const llvm_fn = try o.getCmpLtErrorsLenFunction();5777 const llvm_fn = try o.getCmpLtErrorsLenFunction(pt);
5805 return self.wip.call(5778 return self.wip.call(
5806 .normal,5779 .normal,
5807 .fastcc,5780 .fastcc,
...@@ -5822,7 +5795,7 @@ pub const FuncGen = struct {...@@ -5822,7 +5795,7 @@ pub const FuncGen = struct {
5822 rhs: Builder.Value,5795 rhs: Builder.Value,
5823 ) Allocator.Error!Builder.Value {5796 ) Allocator.Error!Builder.Value {
5824 const o = self.ng.object;5797 const o = self.ng.object;
5825 const pt = o.pt;5798 const pt = self.ng.pt;
5826 const zcu = pt.zcu;5799 const zcu = pt.zcu;
5827 const ip = &zcu.intern_pool;5800 const ip = &zcu.intern_pool;
5828 const scalar_ty = operand_ty.scalarType(zcu);5801 const scalar_ty = operand_ty.scalarType(zcu);
...@@ -5839,7 +5812,7 @@ pub const FuncGen = struct {...@@ -5839,7 +5812,7 @@ pub const FuncGen = struct {
5839 // We need to emit instructions to check for equality/inequality5812 // We need to emit instructions to check for equality/inequality
5840 // of optionals that are not pointers.5813 // of optionals that are not pointers.
5841 const is_by_ref = isByRef(scalar_ty, zcu);5814 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);
5843 const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref, .normal);5816 const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref, .normal);
5844 const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref, .normal);5817 const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref, .normal);
5845 const llvm_i2 = try o.builder.intType(2);5818 const llvm_i2 = try o.builder.intType(2);
...@@ -5936,7 +5909,7 @@ pub const FuncGen = struct {...@@ -5936,7 +5909,7 @@ pub const FuncGen = struct {
5936 body: []const Air.Inst.Index,5909 body: []const Air.Inst.Index,
5937 ) !Builder.Value {5910 ) !Builder.Value {
5938 const o = self.ng.object;5911 const o = self.ng.object;
5939 const pt = o.pt;5912 const pt = self.ng.pt;
5940 const zcu = pt.zcu;5913 const zcu = pt.zcu;
5941 const inst_ty = self.typeOfIndex(inst);5914 const inst_ty = self.typeOfIndex(inst);
59425915
...@@ -5963,7 +5936,7 @@ pub const FuncGen = struct {...@@ -5963,7 +5936,7 @@ pub const FuncGen = struct {
59635936
5964 // Create a phi node only if the block returns a value.5937 // Create a phi node only if the block returns a value.
5965 if (have_block_result) {5938 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);
5967 const llvm_ty: Builder.Type = ty: {5940 const llvm_ty: Builder.Type = ty: {
5968 // If the zig tag type is a function, this represents an actual function body; not5941 // If the zig tag type is a function, this represents an actual function body; not
5969 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead5942 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead
...@@ -5986,8 +5959,7 @@ pub const FuncGen = struct {...@@ -5986,8 +5959,7 @@ pub const FuncGen = struct {
5986 }5959 }
59875960
5988 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !void {5961 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !void {
5989 const o = self.ng.object;5962 const zcu = self.ng.pt.zcu;
5990 const zcu = o.pt.zcu;
5991 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;5963 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
5992 const block = self.blocks.get(branch.block_inst).?;5964 const block = self.blocks.get(branch.block_inst).?;
59935965
...@@ -6017,7 +5989,7 @@ pub const FuncGen = struct {...@@ -6017,7 +5989,7 @@ pub const FuncGen = struct {
6017 dispatch_info: SwitchDispatchInfo,5989 dispatch_info: SwitchDispatchInfo,
6018 ) !void {5990 ) !void {
6019 const o = self.ng.object;5991 const o = self.ng.object;
6020 const pt = o.pt;5992 const pt = self.ng.pt;
6021 const zcu = pt.zcu;5993 const zcu = pt.zcu;
6022 const cond_ty = self.typeOf(cond_ref);5994 const cond_ty = self.typeOf(cond_ref);
6023 const switch_br = self.air.unwrapSwitch(switch_inst);5995 const switch_br = self.air.unwrapSwitch(switch_inst);
...@@ -6081,7 +6053,7 @@ pub const FuncGen = struct {...@@ -6081,7 +6053,7 @@ pub const FuncGen = struct {
6081 const table_index = try self.wip.cast(6053 const table_index = try self.wip.cast(
6082 .zext,6054 .zext,
6083 try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""),6055 try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""),
6084 try o.lowerType(Type.usize),6056 try o.lowerType(pt, Type.usize),
6085 "",6057 "",
6086 );6058 );
6087 const target_ptr_ptr = try self.wip.gep(6059 const target_ptr_ptr = try self.wip.gep(
...@@ -6108,7 +6080,7 @@ pub const FuncGen = struct {...@@ -6108,7 +6080,7 @@ pub const FuncGen = struct {
6108 // The switch prongs will correspond to our scalar cases. Ranges will6080 // The switch prongs will correspond to our scalar cases. Ranges will
6109 // be handled by conditional branches in the `else` prong.6081 // 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);
6112 const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder))6084 const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder))
6113 try self.wip.cast(.ptrtoint, cond, llvm_usize, "")6085 try self.wip.cast(.ptrtoint, cond, llvm_usize, "")
6114 else6086 else
...@@ -6268,8 +6240,7 @@ pub const FuncGen = struct {...@@ -6268,8 +6240,7 @@ pub const FuncGen = struct {
6268 }6240 }
62696241
6270 fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index, err_cold: bool) !Builder.Value {6242 fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index, err_cold: bool) !Builder.Value {
6271 const o = self.ng.object;6243 const pt = self.ng.pt;
6272 const pt = o.pt;
6273 const zcu = pt.zcu;6244 const zcu = pt.zcu;
6274 const inst = body_tail[0];6245 const inst = body_tail[0];
6275 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;6246 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
...@@ -6284,8 +6255,7 @@ pub const FuncGen = struct {...@@ -6284,8 +6255,7 @@ pub const FuncGen = struct {
6284 }6255 }
62856256
6286 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) !Builder.Value {6257 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) !Builder.Value {
6287 const o = self.ng.object;6258 const zcu = self.ng.pt.zcu;
6288 const zcu = o.pt.zcu;
6289 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6259 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6290 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);6260 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
6291 const err_union_ptr = try self.resolveInst(extra.data.ptr);6261 const err_union_ptr = try self.resolveInst(extra.data.ptr);
...@@ -6309,12 +6279,12 @@ pub const FuncGen = struct {...@@ -6309,12 +6279,12 @@ pub const FuncGen = struct {
6309 err_cold: bool,6279 err_cold: bool,
6310 ) !Builder.Value {6280 ) !Builder.Value {
6311 const o = fg.ng.object;6281 const o = fg.ng.object;
6312 const pt = o.pt;6282 const pt = fg.ng.pt;
6313 const zcu = pt.zcu;6283 const zcu = pt.zcu;
6314 const payload_ty = err_union_ty.errorUnionPayload(zcu);6284 const payload_ty = err_union_ty.errorUnionPayload(zcu);
6315 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu);6285 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
6316 const err_union_llvm_ty = try o.lowerType(err_union_ty);6286 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
6317 const error_type = try o.errorIntType();6287 const error_type = try o.errorIntType(pt);
63186288
6319 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {6289 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
6320 const loaded = loaded: {6290 const loaded = loaded: {
...@@ -6378,7 +6348,8 @@ pub const FuncGen = struct {...@@ -6378,7 +6348,8 @@ pub const FuncGen = struct {
63786348
6379 fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) !void {6349 fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) !void {
6380 const o = self.ng.object;6350 const o = self.ng.object;
6381 const zcu = o.pt.zcu;6351 const pt = self.ng.pt;
6352 const zcu = pt.zcu;
63826353
6383 const switch_br = self.air.unwrapSwitch(inst);6354 const switch_br = self.air.unwrapSwitch(inst);
63846355
...@@ -6483,8 +6454,8 @@ pub const FuncGen = struct {...@@ -6483,8 +6454,8 @@ pub const FuncGen = struct {
6483 const table_includes_else = item_count != table_len;6454 const table_includes_else = item_count != table_len;
64846455
6485 break :jmp_table .{6456 break :jmp_table .{
6486 .min = try o.lowerValue(min.toIntern()),6457 .min = try o.lowerValue(pt, min.toIntern()),
6487 .max = try o.lowerValue(max.toIntern()),6458 .max = try o.lowerValue(pt, max.toIntern()),
6488 .in_bounds_hint = if (table_includes_else) .none else switch (switch_br.getElseHint()) {6459 .in_bounds_hint = if (table_includes_else) .none else switch (switch_br.getElseHint()) {
6489 .none, .cold => .none,6460 .none, .cold => .none,
6490 .unpredictable => .unpredictable,6461 .unpredictable => .unpredictable,
...@@ -6591,7 +6562,7 @@ pub const FuncGen = struct {...@@ -6591,7 +6562,7 @@ pub const FuncGen = struct {
6591 }6562 }
65926563
6593 fn switchCaseItemRange(self: *FuncGen, switch_br: Air.UnwrappedSwitch) [2]Value {6564 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;
6595 var it = switch_br.iterateCases();6566 var it = switch_br.iterateCases();
6596 var min: ?Value = null;6567 var min: ?Value = null;
6597 var max: ?Value = null;6568 var max: ?Value = null;
...@@ -6633,18 +6604,18 @@ pub const FuncGen = struct {...@@ -6633,18 +6604,18 @@ pub const FuncGen = struct {
66336604
6634 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6605 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6635 const o = self.ng.object;6606 const o = self.ng.object;
6636 const pt = o.pt;6607 const pt = self.ng.pt;
6637 const zcu = pt.zcu;6608 const zcu = pt.zcu;
6638 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6609 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6639 const operand_ty = self.typeOf(ty_op.operand);6610 const operand_ty = self.typeOf(ty_op.operand);
6640 const array_ty = operand_ty.childType(zcu);6611 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);
6642 const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu));6613 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));
6644 const operand = try self.resolveInst(ty_op.operand);6615 const operand = try self.resolveInst(ty_op.operand);
6645 if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu))6616 if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu))
6646 return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, "");6617 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, &.{
6648 try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0),6619 try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0),
6649 }, "");6620 }, "");
6650 return self.wip.buildAggregate(slice_llvm_ty, &.{ ptr, len }, "");6621 return self.wip.buildAggregate(slice_llvm_ty, &.{ ptr, len }, "");
...@@ -6652,7 +6623,7 @@ pub const FuncGen = struct {...@@ -6652,7 +6623,7 @@ pub const FuncGen = struct {
66526623
6653 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6624 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6654 const o = self.ng.object;6625 const o = self.ng.object;
6655 const pt = o.pt;6626 const pt = self.ng.pt;
6656 const zcu = pt.zcu;6627 const zcu = pt.zcu;
6657 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6628 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
66586629
...@@ -6663,7 +6634,7 @@ pub const FuncGen = struct {...@@ -6663,7 +6634,7 @@ pub const FuncGen = struct {
66636634
6664 const dest_ty = self.typeOfIndex(inst);6635 const dest_ty = self.typeOfIndex(inst);
6665 const dest_scalar_ty = dest_ty.scalarType(zcu);6636 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);
6667 const target = zcu.getTarget();6638 const target = zcu.getTarget();
66686639
6669 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(6640 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(
...@@ -6719,7 +6690,7 @@ pub const FuncGen = struct {...@@ -6719,7 +6690,7 @@ pub const FuncGen = struct {
6719 _ = fast;6690 _ = fast;
67206691
6721 const o = self.ng.object;6692 const o = self.ng.object;
6722 const pt = o.pt;6693 const pt = self.ng.pt;
6723 const zcu = pt.zcu;6694 const zcu = pt.zcu;
6724 const target = zcu.getTarget();6695 const target = zcu.getTarget();
6725 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6696 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
...@@ -6730,7 +6701,7 @@ pub const FuncGen = struct {...@@ -6730,7 +6701,7 @@ pub const FuncGen = struct {
67306701
6731 const dest_ty = self.typeOfIndex(inst);6702 const dest_ty = self.typeOfIndex(inst);
6732 const dest_scalar_ty = dest_ty.scalarType(zcu);6703 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
6735 if (intrinsicsAllowed(operand_scalar_ty, target)) {6706 if (intrinsicsAllowed(operand_scalar_ty, target)) {
6736 // TODO set fast math flag6707 // TODO set fast math flag
...@@ -6762,7 +6733,7 @@ pub const FuncGen = struct {...@@ -6762,7 +6733,7 @@ pub const FuncGen = struct {
6762 compiler_rt_dest_abbrev,6733 compiler_rt_dest_abbrev,
6763 });6734 });
67646735
6765 const operand_llvm_ty = try o.lowerType(operand_ty);6736 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
6766 const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty);6737 const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty);
6767 var result = try self.wip.call(6738 var result = try self.wip.call(
6768 .normal,6739 .normal,
...@@ -6780,16 +6751,15 @@ pub const FuncGen = struct {...@@ -6780,16 +6751,15 @@ pub const FuncGen = struct {
6780 }6751 }
67816752
6782 fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {6753 fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
6783 const o = fg.ng.object;6754 const zcu = fg.ng.pt.zcu;
6784 const zcu = o.pt.zcu;
6785 return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;6755 return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;
6786 }6756 }
67876757
6788 fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {6758 fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
6789 const o = fg.ng.object;6759 const o = fg.ng.object;
6790 const pt = o.pt;6760 const pt = fg.ng.pt;
6791 const zcu = pt.zcu;6761 const zcu = pt.zcu;
6792 const llvm_usize = try o.lowerType(Type.usize);6762 const llvm_usize = try o.lowerType(pt, Type.usize);
6793 switch (ty.ptrSize(zcu)) {6763 switch (ty.ptrSize(zcu)) {
6794 .slice => {6764 .slice => {
6795 const len = try fg.wip.extractValue(ptr, &.{1}, "");6765 const len = try fg.wip.extractValue(ptr, &.{1}, "");
...@@ -6817,18 +6787,19 @@ pub const FuncGen = struct {...@@ -6817,18 +6787,19 @@ pub const FuncGen = struct {
68176787
6818 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {6788 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {
6819 const o = self.ng.object;6789 const o = self.ng.object;
6820 const zcu = o.pt.zcu;6790 const pt = self.ng.pt;
6791 const zcu = pt.zcu;
6821 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6792 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6822 const slice_ptr = try self.resolveInst(ty_op.operand);6793 const slice_ptr = try self.resolveInst(ty_op.operand);
6823 const slice_ptr_ty = self.typeOf(ty_op.operand);6794 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
6826 return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, "");6797 return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, "");
6827 }6798 }
68286799
6829 fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {6800 fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
6830 const o = self.ng.object;6801 const o = self.ng.object;
6831 const pt = o.pt;6802 const pt = self.ng.pt;
6832 const zcu = pt.zcu;6803 const zcu = pt.zcu;
6833 const inst = body_tail[0];6804 const inst = body_tail[0];
6834 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6805 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
...@@ -6836,7 +6807,7 @@ pub const FuncGen = struct {...@@ -6836,7 +6807,7 @@ pub const FuncGen = struct {
6836 const slice = try self.resolveInst(bin_op.lhs);6807 const slice = try self.resolveInst(bin_op.lhs);
6837 const index = try self.resolveInst(bin_op.rhs);6808 const index = try self.resolveInst(bin_op.rhs);
6838 const elem_ty = slice_ty.childType(zcu);6809 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);
6840 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");6811 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
6841 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");6812 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
6842 if (isByRef(elem_ty, zcu)) {6813 if (isByRef(elem_ty, zcu)) {
...@@ -6856,21 +6827,22 @@ pub const FuncGen = struct {...@@ -6856,21 +6827,22 @@ pub const FuncGen = struct {
68566827
6857 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6828 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6858 const o = self.ng.object;6829 const o = self.ng.object;
6859 const zcu = o.pt.zcu;6830 const pt = self.ng.pt;
6831 const zcu = pt.zcu;
6860 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6832 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6861 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;6833 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
6862 const slice_ty = self.typeOf(bin_op.lhs);6834 const slice_ty = self.typeOf(bin_op.lhs);
68636835
6864 const slice = try self.resolveInst(bin_op.lhs);6836 const slice = try self.resolveInst(bin_op.lhs);
6865 const index = try self.resolveInst(bin_op.rhs);6837 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));
6867 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");6839 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
6868 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");6840 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
6869 }6841 }
68706842
6871 fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {6843 fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
6872 const o = self.ng.object;6844 const o = self.ng.object;
6873 const pt = o.pt;6845 const pt = self.ng.pt;
6874 const zcu = pt.zcu;6846 const zcu = pt.zcu;
6875 const inst = body_tail[0];6847 const inst = body_tail[0];
68766848
...@@ -6878,11 +6850,11 @@ pub const FuncGen = struct {...@@ -6878,11 +6850,11 @@ pub const FuncGen = struct {
6878 const array_ty = self.typeOf(bin_op.lhs);6850 const array_ty = self.typeOf(bin_op.lhs);
6879 const array_llvm_val = try self.resolveInst(bin_op.lhs);6851 const array_llvm_val = try self.resolveInst(bin_op.lhs);
6880 const rhs = try self.resolveInst(bin_op.rhs);6852 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);
6882 const elem_ty = array_ty.childType(zcu);6854 const elem_ty = array_ty.childType(zcu);
6883 if (isByRef(array_ty, zcu)) {6855 if (isByRef(array_ty, zcu)) {
6884 const indices: [2]Builder.Value = .{6856 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,
6886 };6858 };
6887 if (isByRef(elem_ty, zcu)) {6859 if (isByRef(elem_ty, zcu)) {
6888 const elem_ptr =6860 const elem_ptr =
...@@ -6903,19 +6875,19 @@ pub const FuncGen = struct {...@@ -6903,19 +6875,19 @@ pub const FuncGen = struct {
69036875
6904 fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {6876 fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
6905 const o = self.ng.object;6877 const o = self.ng.object;
6906 const pt = o.pt;6878 const pt = self.ng.pt;
6907 const zcu = pt.zcu;6879 const zcu = pt.zcu;
6908 const inst = body_tail[0];6880 const inst = body_tail[0];
6909 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6881 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6910 const ptr_ty = self.typeOf(bin_op.lhs);6882 const ptr_ty = self.typeOf(bin_op.lhs);
6911 const elem_ty = ptr_ty.childType(zcu);6883 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);
6913 const base_ptr = try self.resolveInst(bin_op.lhs);6885 const base_ptr = try self.resolveInst(bin_op.lhs);
6914 const rhs = try self.resolveInst(bin_op.rhs);6886 const rhs = try self.resolveInst(bin_op.rhs);
6915 // TODO: when we go fully opaque pointers in LLVM 16 we can remove this branch6887 // TODO: when we go fully opaque pointers in LLVM 16 we can remove this branch
6916 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))6888 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
6917 // If this is a single-item pointer to an array, we need another index in the GEP.6889 // 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 }
6919 else6891 else
6920 &.{rhs}, "");6892 &.{rhs}, "");
6921 if (isByRef(elem_ty, zcu)) {6893 if (isByRef(elem_ty, zcu)) {
...@@ -6934,7 +6906,7 @@ pub const FuncGen = struct {...@@ -6934,7 +6906,7 @@ pub const FuncGen = struct {
69346906
6935 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6907 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6936 const o = self.ng.object;6908 const o = self.ng.object;
6937 const pt = o.pt;6909 const pt = self.ng.pt;
6938 const zcu = pt.zcu;6910 const zcu = pt.zcu;
6939 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6911 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6940 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;6912 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
...@@ -6948,10 +6920,10 @@ pub const FuncGen = struct {...@@ -6948,10 +6920,10 @@ pub const FuncGen = struct {
6948 const elem_ptr = ty_pl.ty.toType();6920 const elem_ptr = ty_pl.ty.toType();
6949 if (elem_ptr.ptrInfo(zcu).flags.vector_index != .none) return base_ptr;6921 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);
6952 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))6924 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
6953 // If this is a single-item pointer to an array, we need another index in the GEP.6925 // 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 }
6955 else6927 else
6956 &.{rhs}, "");6928 &.{rhs}, "");
6957 }6929 }
...@@ -6977,7 +6949,7 @@ pub const FuncGen = struct {...@@ -6977,7 +6949,7 @@ pub const FuncGen = struct {
69776949
6978 fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {6950 fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
6979 const o = self.ng.object;6951 const o = self.ng.object;
6980 const pt = o.pt;6952 const pt = self.ng.pt;
6981 const zcu = pt.zcu;6953 const zcu = pt.zcu;
6982 const inst = body_tail[0];6954 const inst = body_tail[0];
6983 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6955 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
...@@ -6999,7 +6971,7 @@ pub const FuncGen = struct {...@@ -6999,7 +6971,7 @@ pub const FuncGen = struct {
6999 const shift_amt =6971 const shift_amt =
7000 try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset);6972 try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset);
7001 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");6973 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);
7003 if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) {6975 if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) {
7004 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));6976 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
7005 const truncated_int =6977 const truncated_int =
...@@ -7021,7 +6993,7 @@ pub const FuncGen = struct {...@@ -7021,7 +6993,7 @@ pub const FuncGen = struct {
7021 .@"union" => {6993 .@"union" => {
7022 assert(struct_ty.containerLayout(zcu) == .@"packed");6994 assert(struct_ty.containerLayout(zcu) == .@"packed");
7023 const containing_int = struct_llvm_val;6995 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);
7025 if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) {6997 if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) {
7026 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));6998 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
7027 const truncated_int =6999 const truncated_int =
...@@ -7043,7 +7015,7 @@ pub const FuncGen = struct {...@@ -7043,7 +7015,7 @@ pub const FuncGen = struct {
7043 .@"struct" => {7015 .@"struct" => {
7044 const layout = struct_ty.containerLayout(zcu);7016 const layout = struct_ty.containerLayout(zcu);
7045 assert(layout != .@"packed");7017 assert(layout != .@"packed");
7046 const struct_llvm_ty = try o.lowerType(struct_ty);7018 const struct_llvm_ty = try o.lowerType(pt, struct_ty);
7047 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;7019 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;
7048 const field_ptr =7020 const field_ptr =
7049 try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, "");7021 try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, "");
...@@ -7064,7 +7036,7 @@ pub const FuncGen = struct {...@@ -7064,7 +7036,7 @@ pub const FuncGen = struct {
7064 }7036 }
7065 },7037 },
7066 .@"union" => {7038 .@"union" => {
7067 const union_llvm_ty = try o.lowerType(struct_ty);7039 const union_llvm_ty = try o.lowerType(pt, struct_ty);
7068 const layout = struct_ty.unionGetLayout(zcu);7040 const layout = struct_ty.unionGetLayout(zcu);
7069 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));7041 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
7070 const field_ptr =7042 const field_ptr =
...@@ -7083,7 +7055,7 @@ pub const FuncGen = struct {...@@ -7083,7 +7055,7 @@ pub const FuncGen = struct {
70837055
7084 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7056 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7085 const o = self.ng.object;7057 const o = self.ng.object;
7086 const pt = o.pt;7058 const pt = self.ng.pt;
7087 const zcu = pt.zcu;7059 const zcu = pt.zcu;
7088 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;7060 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7089 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;7061 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
...@@ -7094,8 +7066,8 @@ pub const FuncGen = struct {...@@ -7094,8 +7066,8 @@ pub const FuncGen = struct {
7094 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);7066 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
7095 if (field_offset == 0) return field_ptr;7067 if (field_offset == 0) return field_ptr;
70967068
7097 const res_ty = try o.lowerType(ty_pl.ty.toType());7069 const res_ty = try o.lowerType(pt, ty_pl.ty.toType());
7098 const llvm_usize = try o.lowerType(Type.usize);7070 const llvm_usize = try o.lowerType(pt, Type.usize);
70997071
7100 const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, "");7072 const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, "");
7101 const base_ptr_int = try self.wip.bin(7073 const base_ptr_int = try self.wip.bin(
...@@ -7151,7 +7123,8 @@ pub const FuncGen = struct {...@@ -7151,7 +7123,8 @@ pub const FuncGen = struct {
71517123
7152 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7124 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7153 const o = self.ng.object;7125 const o = self.ng.object;
7154 const zcu = o.pt.zcu;7126 const pt = self.ng.pt;
7127 const zcu = pt.zcu;
7155 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;7128 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7156 const operand = try self.resolveInst(pl_op.operand);7129 const operand = try self.resolveInst(pl_op.operand);
7157 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);7130 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
...@@ -7162,7 +7135,7 @@ pub const FuncGen = struct {...@@ -7162,7 +7135,7 @@ pub const FuncGen = struct {
7162 self.file,7135 self.file,
7163 self.scope,7136 self.scope,
7164 self.prev_dbg_line,7137 self.prev_dbg_line,
7165 try o.lowerDebugType(ptr_ty.childType(zcu)),7138 try o.lowerDebugType(pt, ptr_ty.childType(zcu)),
7166 );7139 );
71677140
7168 _ = try self.wip.callIntrinsic(7141 _ = try self.wip.callIntrinsic(
...@@ -7183,6 +7156,7 @@ pub const FuncGen = struct {...@@ -7183,6 +7156,7 @@ pub const FuncGen = struct {
71837156
7184 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index, is_arg: bool) !Builder.Value {7157 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index, is_arg: bool) !Builder.Value {
7185 const o = self.ng.object;7158 const o = self.ng.object;
7159 const pt = self.ng.pt;
7186 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;7160 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7187 const operand = try self.resolveInst(pl_op.operand);7161 const operand = try self.resolveInst(pl_op.operand);
7188 const operand_ty = self.typeOf(pl_op.operand);7162 const operand_ty = self.typeOf(pl_op.operand);
...@@ -7193,7 +7167,7 @@ pub const FuncGen = struct {...@@ -7193,7 +7167,7 @@ pub const FuncGen = struct {
7193 self.file,7167 self.file,
7194 self.scope,7168 self.scope,
7195 self.prev_dbg_line,7169 self.prev_dbg_line,
7196 try o.lowerDebugType(operand_ty),7170 try o.lowerDebugType(pt, operand_ty),
7197 arg_no: {7171 arg_no: {
7198 self.arg_inline_index += 1;7172 self.arg_inline_index += 1;
7199 break :arg_no self.arg_inline_index;7173 break :arg_no self.arg_inline_index;
...@@ -7203,10 +7177,10 @@ pub const FuncGen = struct {...@@ -7203,10 +7177,10 @@ pub const FuncGen = struct {
7203 self.file,7177 self.file,
7204 self.scope,7178 self.scope,
7205 self.prev_dbg_line,7179 self.prev_dbg_line,
7206 try o.lowerDebugType(operand_ty),7180 try o.lowerDebugType(pt, operand_ty),
7207 );7181 );
72087182
7209 const zcu = o.pt.zcu;7183 const zcu = pt.zcu;
7210 const owner_mod = self.ng.ownerModule();7184 const owner_mod = self.ng.ownerModule();
7211 if (isByRef(operand_ty, zcu)) {7185 if (isByRef(operand_ty, zcu)) {
7212 _ = try self.wip.callIntrinsic(7186 _ = try self.wip.callIntrinsic(
...@@ -7296,7 +7270,7 @@ pub const FuncGen = struct {...@@ -7296,7 +7270,7 @@ pub const FuncGen = struct {
7296 // This stores whether we need to add an elementtype attribute and7270 // This stores whether we need to add an elementtype attribute and
7297 // if so, the element type itself.7271 // if so, the element type itself.
7298 const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count);7272 const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count);
7299 const pt = o.pt;7273 const pt = self.ng.pt;
7300 const zcu = pt.zcu;7274 const zcu = pt.zcu;
7301 const target = zcu.getTarget();7275 const target = zcu.getTarget();
73027276
...@@ -7326,7 +7300,7 @@ pub const FuncGen = struct {...@@ -7326,7 +7300,7 @@ pub const FuncGen = struct {
7326 const output_inst = try self.resolveInst(output);7300 const output_inst = try self.resolveInst(output);
7327 const output_ty = self.typeOf(output);7301 const output_ty = self.typeOf(output);
7328 assert(output_ty.zigTypeTag(zcu) == .pointer);7302 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
7331 switch (constraint[0]) {7305 switch (constraint[0]) {
7332 '=' => {},7306 '=' => {},
...@@ -7364,7 +7338,7 @@ pub const FuncGen = struct {...@@ -7364,7 +7338,7 @@ pub const FuncGen = struct {
7364 is_indirect.* = false;7338 is_indirect.* = false;
73657339
7366 const ret_ty = self.typeOfIndex(inst);7340 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);
7368 llvm_ret_i += 1;7342 llvm_ret_i += 1;
7369 }7343 }
73707344
...@@ -7406,7 +7380,7 @@ pub const FuncGen = struct {...@@ -7406,7 +7380,7 @@ pub const FuncGen = struct {
7406 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);7380 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
7407 } else {7381 } else {
7408 const alignment = arg_ty.abiAlignment(zcu).toLlvm();7382 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);
7410 const load_inst =7384 const load_inst =
7411 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");7385 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");
7412 llvm_param_values[llvm_param_i] = load_inst;7386 llvm_param_values[llvm_param_i] = load_inst;
...@@ -7447,7 +7421,7 @@ pub const FuncGen = struct {...@@ -7447,7 +7421,7 @@ pub const FuncGen = struct {
7447 llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: {7421 llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: {
7448 if (!is_by_ref) self.maybeMarkAllowZeroAccess(arg_ty.ptrInfo(zcu));7422 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));
7451 } else .none;7425 } else .none;
74527426
7453 llvm_param_i += 1;7427 llvm_param_i += 1;
...@@ -7465,7 +7439,7 @@ pub const FuncGen = struct {...@@ -7465,7 +7439,7 @@ pub const FuncGen = struct {
7465 if (constraint[0] != '+') continue;7439 if (constraint[0] != '+') continue;
74667440
7467 const rw_ty = self.typeOf(output);7441 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));
7469 if (is_indirect) {7443 if (is_indirect) {
7470 llvm_param_values[llvm_param_i] = llvm_rw_val;7444 llvm_param_values[llvm_param_i] = llvm_rw_val;
7471 llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip);7445 llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip);
...@@ -7663,13 +7637,13 @@ pub const FuncGen = struct {...@@ -7663,13 +7637,13 @@ pub const FuncGen = struct {
7663 cond: Builder.IntegerCondition,7637 cond: Builder.IntegerCondition,
7664 ) !Builder.Value {7638 ) !Builder.Value {
7665 const o = self.ng.object;7639 const o = self.ng.object;
7666 const pt = o.pt;7640 const pt = self.ng.pt;
7667 const zcu = pt.zcu;7641 const zcu = pt.zcu;
7668 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;7642 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
7669 const operand = try self.resolveInst(un_op);7643 const operand = try self.resolveInst(un_op);
7670 const operand_ty = self.typeOf(un_op);7644 const operand_ty = self.typeOf(un_op);
7671 const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;7645 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);
7673 const payload_ty = optional_ty.optionalChild(zcu);7647 const payload_ty = optional_ty.optionalChild(zcu);
76747648
7675 const access_kind: Builder.MemoryAccessKind =7649 const access_kind: Builder.MemoryAccessKind =
...@@ -7714,14 +7688,14 @@ pub const FuncGen = struct {...@@ -7714,14 +7688,14 @@ pub const FuncGen = struct {
7714 operand_is_ptr: bool,7688 operand_is_ptr: bool,
7715 ) !Builder.Value {7689 ) !Builder.Value {
7716 const o = self.ng.object;7690 const o = self.ng.object;
7717 const pt = o.pt;7691 const pt = self.ng.pt;
7718 const zcu = pt.zcu;7692 const zcu = pt.zcu;
7719 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;7693 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
7720 const operand = try self.resolveInst(un_op);7694 const operand = try self.resolveInst(un_op);
7721 const operand_ty = self.typeOf(un_op);7695 const operand_ty = self.typeOf(un_op);
7722 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;7696 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7723 const payload_ty = err_union_ty.errorUnionPayload(zcu);7697 const payload_ty = err_union_ty.errorUnionPayload(zcu);
7724 const error_type = try o.errorIntType();7698 const error_type = try o.errorIntType(pt);
7725 const zero = try o.builder.intValue(error_type, 0);7699 const zero = try o.builder.intValue(error_type, 0);
77267700
7727 const access_kind: Builder.MemoryAccessKind =7701 const access_kind: Builder.MemoryAccessKind =
...@@ -7740,7 +7714,7 @@ pub const FuncGen = struct {...@@ -7740,7 +7714,7 @@ pub const FuncGen = struct {
77407714
7741 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {7715 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
7742 const loaded = if (operand_is_ptr)7716 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, "")
7744 else7718 else
7745 operand;7719 operand;
7746 return self.wip.icmp(cond, loaded, zero, "");7720 return self.wip.icmp(cond, loaded, zero, "");
...@@ -7749,7 +7723,7 @@ pub const FuncGen = struct {...@@ -7749,7 +7723,7 @@ pub const FuncGen = struct {
7749 const err_field_index = try errUnionErrorOffset(payload_ty, pt);7723 const err_field_index = try errUnionErrorOffset(payload_ty, pt);
77507724
7751 const loaded = if (operand_is_ptr or isByRef(err_union_ty, zcu)) loaded: {7725 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);
7753 const err_field_ptr =7727 const err_field_ptr =
7754 try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, "");7728 try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, "");
7755 break :loaded try self.wip.load(access_kind, error_type, err_field_ptr, .default, "");7729 break :loaded try self.wip.load(access_kind, error_type, err_field_ptr, .default, "");
...@@ -7759,7 +7733,7 @@ pub const FuncGen = struct {...@@ -7759,7 +7733,7 @@ pub const FuncGen = struct {
77597733
7760 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7734 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7761 const o = self.ng.object;7735 const o = self.ng.object;
7762 const pt = o.pt;7736 const pt = self.ng.pt;
7763 const zcu = pt.zcu;7737 const zcu = pt.zcu;
7764 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7738 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7765 const operand = try self.resolveInst(ty_op.operand);7739 const operand = try self.resolveInst(ty_op.operand);
...@@ -7774,14 +7748,14 @@ pub const FuncGen = struct {...@@ -7774,14 +7748,14 @@ pub const FuncGen = struct {
7774 // The payload and the optional are the same value.7748 // The payload and the optional are the same value.
7775 return operand;7749 return operand;
7776 }7750 }
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, "");
7778 }7752 }
77797753
7780 fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7754 fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7781 comptime assert(optional_layout_version == 3);7755 comptime assert(optional_layout_version == 3);
77827756
7783 const o = self.ng.object;7757 const o = self.ng.object;
7784 const pt = o.pt;7758 const pt = self.ng.pt;
7785 const zcu = pt.zcu;7759 const zcu = pt.zcu;
7786 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7760 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7787 const operand = try self.resolveInst(ty_op.operand);7761 const operand = try self.resolveInst(ty_op.operand);
...@@ -7807,7 +7781,7 @@ pub const FuncGen = struct {...@@ -7807,7 +7781,7 @@ pub const FuncGen = struct {
7807 }7781 }
78087782
7809 // First set the non-null bit.7783 // 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);
7811 const non_null_ptr = try self.wip.gepStruct(optional_llvm_ty, operand, 1, "");7785 const non_null_ptr = try self.wip.gepStruct(optional_llvm_ty, operand, 1, "");
78127786
7813 self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu));7787 self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu));
...@@ -7823,7 +7797,7 @@ pub const FuncGen = struct {...@@ -7823,7 +7797,7 @@ pub const FuncGen = struct {
78237797
7824 fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {7798 fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
7825 const o = self.ng.object;7799 const o = self.ng.object;
7826 const pt = o.pt;7800 const pt = self.ng.pt;
7827 const zcu = pt.zcu;7801 const zcu = pt.zcu;
7828 const inst = body_tail[0];7802 const inst = body_tail[0];
7829 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7803 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
...@@ -7837,7 +7811,7 @@ pub const FuncGen = struct {...@@ -7837,7 +7811,7 @@ pub const FuncGen = struct {
7837 return operand;7811 return operand;
7838 }7812 }
78397813
7840 const opt_llvm_ty = try o.lowerType(optional_ty);7814 const opt_llvm_ty = try o.lowerType(pt, optional_ty);
7841 const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false;7815 const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false;
7842 return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load);7816 return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load);
7843 }7817 }
...@@ -7848,7 +7822,7 @@ pub const FuncGen = struct {...@@ -7848,7 +7822,7 @@ pub const FuncGen = struct {
7848 operand_is_ptr: bool,7822 operand_is_ptr: bool,
7849 ) !Builder.Value {7823 ) !Builder.Value {
7850 const o = self.ng.object;7824 const o = self.ng.object;
7851 const pt = o.pt;7825 const pt = self.ng.pt;
7852 const zcu = pt.zcu;7826 const zcu = pt.zcu;
7853 const inst = body_tail[0];7827 const inst = body_tail[0];
7854 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7828 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
...@@ -7862,7 +7836,7 @@ pub const FuncGen = struct {...@@ -7862,7 +7836,7 @@ pub const FuncGen = struct {
7862 return if (operand_is_ptr) operand else .none;7836 return if (operand_is_ptr) operand else .none;
7863 }7837 }
7864 const offset = try errUnionPayloadOffset(payload_ty, pt);7838 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);
7866 if (operand_is_ptr) {7840 if (operand_is_ptr) {
7867 return self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");7841 return self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
7868 } else if (isByRef(err_union_ty, zcu)) {7842 } else if (isByRef(err_union_ty, zcu)) {
...@@ -7884,12 +7858,12 @@ pub const FuncGen = struct {...@@ -7884,12 +7858,12 @@ pub const FuncGen = struct {
7884 operand_is_ptr: bool,7858 operand_is_ptr: bool,
7885 ) !Builder.Value {7859 ) !Builder.Value {
7886 const o = self.ng.object;7860 const o = self.ng.object;
7887 const pt = o.pt;7861 const pt = self.ng.pt;
7888 const zcu = pt.zcu;7862 const zcu = pt.zcu;
7889 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7863 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7890 const operand = try self.resolveInst(ty_op.operand);7864 const operand = try self.resolveInst(ty_op.operand);
7891 const operand_ty = self.typeOf(ty_op.operand);7865 const operand_ty = self.typeOf(ty_op.operand);
7892 const error_type = try o.errorIntType();7866 const error_type = try o.errorIntType(pt);
7893 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;7867 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7894 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {7868 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
7895 if (operand_is_ptr) {7869 if (operand_is_ptr) {
...@@ -7916,7 +7890,7 @@ pub const FuncGen = struct {...@@ -7916,7 +7890,7 @@ pub const FuncGen = struct {
7916 if (operand_is_ptr or isByRef(err_union_ty, zcu)) {7890 if (operand_is_ptr or isByRef(err_union_ty, zcu)) {
7917 if (operand_is_ptr) self.maybeMarkAllowZeroAccess(operand_ty.ptrInfo(zcu));7891 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);
7920 const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");7894 const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
7921 return self.wip.load(access_kind, error_type, err_field_ptr, .default, "");7895 return self.wip.load(access_kind, error_type, err_field_ptr, .default, "");
7922 }7896 }
...@@ -7926,7 +7900,7 @@ pub const FuncGen = struct {...@@ -7926,7 +7900,7 @@ pub const FuncGen = struct {
79267900
7927 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7901 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7928 const o = self.ng.object;7902 const o = self.ng.object;
7929 const pt = o.pt;7903 const pt = self.ng.pt;
7930 const zcu = pt.zcu;7904 const zcu = pt.zcu;
7931 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7905 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7932 const operand = try self.resolveInst(ty_op.operand);7906 const operand = try self.resolveInst(ty_op.operand);
...@@ -7934,7 +7908,7 @@ pub const FuncGen = struct {...@@ -7934,7 +7908,7 @@ pub const FuncGen = struct {
7934 const err_union_ty = err_union_ptr_ty.childType(zcu);7908 const err_union_ty = err_union_ptr_ty.childType(zcu);
79357909
7936 const payload_ty = err_union_ty.errorUnionPayload(zcu);7910 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
7939 const access_kind: Builder.MemoryAccessKind =7913 const access_kind: Builder.MemoryAccessKind =
7940 if (err_union_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;7914 if (err_union_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
...@@ -7945,7 +7919,7 @@ pub const FuncGen = struct {...@@ -7945,7 +7919,7 @@ pub const FuncGen = struct {
7945 _ = try self.wip.store(access_kind, non_error_val, operand, .default);7919 _ = try self.wip.store(access_kind, non_error_val, operand, .default);
7946 return operand;7920 return operand;
7947 }7921 }
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);
7949 {7923 {
7950 self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu));7924 self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu));
79517925
...@@ -7976,14 +7950,14 @@ pub const FuncGen = struct {...@@ -7976,14 +7950,14 @@ pub const FuncGen = struct {
79767950
7977 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7951 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7978 const o = self.ng.object;7952 const o = self.ng.object;
7979 const pt = o.pt;7953 const pt = self.ng.pt;
7980 const zcu = pt.zcu;7954 const zcu = pt.zcu;
79817955
7982 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;7956 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7983 const struct_ty = ty_pl.ty.toType();7957 const struct_ty = ty_pl.ty.toType();
7984 const field_index = ty_pl.payload;7958 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);
7987 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;7961 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;
7988 assert(self.err_ret_trace != .none);7962 assert(self.err_ret_trace != .none);
7989 const field_ptr =7963 const field_ptr =
...@@ -8022,7 +7996,7 @@ pub const FuncGen = struct {...@@ -8022,7 +7996,7 @@ pub const FuncGen = struct {
80227996
8023 fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {7997 fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
8024 const o = self.ng.object;7998 const o = self.ng.object;
8025 const pt = o.pt;7999 const pt = self.ng.pt;
8026 const zcu = pt.zcu;8000 const zcu = pt.zcu;
8027 const inst = body_tail[0];8001 const inst = body_tail[0];
8028 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;8002 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
...@@ -8033,7 +8007,7 @@ pub const FuncGen = struct {...@@ -8033,7 +8007,7 @@ pub const FuncGen = struct {
8033 const operand = try self.resolveInst(ty_op.operand);8007 const operand = try self.resolveInst(ty_op.operand);
8034 const optional_ty = self.typeOfIndex(inst);8008 const optional_ty = self.typeOfIndex(inst);
8035 if (optional_ty.optionalReprIsPayload(zcu)) return operand;8009 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);
8037 if (isByRef(optional_ty, zcu)) {8011 if (isByRef(optional_ty, zcu)) {
8038 const directReturn = self.isNextRet(body_tail);8012 const directReturn = self.isNextRet(body_tail);
8039 const optional_ptr = if (directReturn)8013 const optional_ptr = if (directReturn)
...@@ -8056,7 +8030,7 @@ pub const FuncGen = struct {...@@ -8056,7 +8030,7 @@ pub const FuncGen = struct {
80568030
8057 fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {8031 fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
8058 const o = self.ng.object;8032 const o = self.ng.object;
8059 const pt = o.pt;8033 const pt = self.ng.pt;
8060 const zcu = pt.zcu;8034 const zcu = pt.zcu;
8061 const inst = body_tail[0];8035 const inst = body_tail[0];
8062 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;8036 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
...@@ -8066,8 +8040,8 @@ pub const FuncGen = struct {...@@ -8066,8 +8040,8 @@ pub const FuncGen = struct {
8066 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {8040 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8067 return operand;8041 return operand;
8068 }8042 }
8069 const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0);8043 const ok_err_code = try o.builder.intValue(try o.errorIntType(pt), 0);
8070 const err_un_llvm_ty = try o.lowerType(err_un_ty);8044 const err_un_llvm_ty = try o.lowerType(pt, err_un_ty);
80718045
8072 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);8046 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
8073 const error_offset = try errUnionErrorOffset(payload_ty, pt);8047 const error_offset = try errUnionErrorOffset(payload_ty, pt);
...@@ -8098,7 +8072,7 @@ pub const FuncGen = struct {...@@ -8098,7 +8072,7 @@ pub const FuncGen = struct {
80988072
8099 fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {8073 fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
8100 const o = self.ng.object;8074 const o = self.ng.object;
8101 const pt = o.pt;8075 const pt = self.ng.pt;
8102 const zcu = pt.zcu;8076 const zcu = pt.zcu;
8103 const inst = body_tail[0];8077 const inst = body_tail[0];
8104 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;8078 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
...@@ -8106,7 +8080,7 @@ pub const FuncGen = struct {...@@ -8106,7 +8080,7 @@ pub const FuncGen = struct {
8106 const payload_ty = err_un_ty.errorUnionPayload(zcu);8080 const payload_ty = err_un_ty.errorUnionPayload(zcu);
8107 const operand = try self.resolveInst(ty_op.operand);8081 const operand = try self.resolveInst(ty_op.operand);
8108 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return operand;8082 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
8111 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);8085 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
8112 const error_offset = try errUnionErrorOffset(payload_ty, pt);8086 const error_offset = try errUnionErrorOffset(payload_ty, pt);
...@@ -8139,9 +8113,10 @@ pub const FuncGen = struct {...@@ -8139,9 +8113,10 @@ pub const FuncGen = struct {
81398113
8140 fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8114 fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8141 const o = self.ng.object;8115 const o = self.ng.object;
8116 const pt = self.ng.pt;
8142 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;8117 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
8143 const index = pl_op.payload;8118 const index = pl_op.payload;
8144 const llvm_usize = try o.lowerType(Type.usize);8119 const llvm_usize = try o.lowerType(pt, Type.usize);
8145 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{8120 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{
8146 try o.builder.intValue(.i32, index),8121 try o.builder.intValue(.i32, index),
8147 }, "");8122 }, "");
...@@ -8149,9 +8124,10 @@ pub const FuncGen = struct {...@@ -8149,9 +8124,10 @@ pub const FuncGen = struct {
81498124
8150 fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8125 fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8151 const o = self.ng.object;8126 const o = self.ng.object;
8127 const pt = self.ng.pt;
8152 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;8128 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
8153 const index = pl_op.payload;8129 const index = pl_op.payload;
8154 const llvm_isize = try o.lowerType(Type.isize);8130 const llvm_isize = try o.lowerType(pt, Type.isize);
8155 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{8131 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{
8156 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),8132 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
8157 }, "");8133 }, "");
...@@ -8159,7 +8135,7 @@ pub const FuncGen = struct {...@@ -8159,7 +8135,7 @@ pub const FuncGen = struct {
81598135
8160 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8136 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8161 const o = self.ng.object;8137 const o = self.ng.object;
8162 const pt = o.pt;8138 const pt = self.ng.pt;
8163 const zcu = pt.zcu;8139 const zcu = pt.zcu;
8164 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;8140 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
8165 const extra = self.air.extraData(Air.Bin, data.payload).data;8141 const extra = self.air.extraData(Air.Bin, data.payload).data;
...@@ -8175,7 +8151,7 @@ pub const FuncGen = struct {...@@ -8175,7 +8151,7 @@ pub const FuncGen = struct {
8175 // https://github.com/ziglang/zig/issues/18652#issuecomment-24528449088151 // https://github.com/ziglang/zig/issues/18652#issuecomment-2452844908
8176 const access_kind: Builder.MemoryAccessKind =8152 const access_kind: Builder.MemoryAccessKind =
8177 if (vector_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;8153 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));
8179 const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm();8155 const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm();
8180 const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, "");8156 const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, "");
81818157
...@@ -8186,14 +8162,16 @@ pub const FuncGen = struct {...@@ -8186,14 +8162,16 @@ pub const FuncGen = struct {
81868162
8187 fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8163 fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8188 const o = fg.ng.object;8164 const o = fg.ng.object;
8165 const pt = fg.ng.pt;
8189 const ty_nav = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav;8166 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);
8191 return llvm_ptr_const.toValue();8168 return llvm_ptr_const.toValue();
8192 }8169 }
81938170
8194 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8171 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8195 const o = self.ng.object;8172 const o = self.ng.object;
8196 const zcu = o.pt.zcu;8173 const pt = self.ng.pt;
8174 const zcu = pt.zcu;
8197 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8175 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8198 const lhs = try self.resolveInst(bin_op.lhs);8176 const lhs = try self.resolveInst(bin_op.lhs);
8199 const rhs = try self.resolveInst(bin_op.rhs);8177 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8205,7 +8183,7 @@ pub const FuncGen = struct {...@@ -8205,7 +8183,7 @@ pub const FuncGen = struct {
8205 .normal,8183 .normal,
8206 .none,8184 .none,
8207 if (scalar_ty.isSignedInt(zcu)) .smin else .umin,8185 if (scalar_ty.isSignedInt(zcu)) .smin else .umin,
8208 &.{try o.lowerType(inst_ty)},8186 &.{try o.lowerType(pt, inst_ty)},
8209 &.{ lhs, rhs },8187 &.{ lhs, rhs },
8210 "",8188 "",
8211 );8189 );
...@@ -8213,7 +8191,8 @@ pub const FuncGen = struct {...@@ -8213,7 +8191,8 @@ pub const FuncGen = struct {
82138191
8214 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8192 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8215 const o = self.ng.object;8193 const o = self.ng.object;
8216 const zcu = o.pt.zcu;8194 const pt = self.ng.pt;
8195 const zcu = pt.zcu;
8217 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8196 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8218 const lhs = try self.resolveInst(bin_op.lhs);8197 const lhs = try self.resolveInst(bin_op.lhs);
8219 const rhs = try self.resolveInst(bin_op.rhs);8198 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8225,7 +8204,7 @@ pub const FuncGen = struct {...@@ -8225,7 +8204,7 @@ pub const FuncGen = struct {
8225 .normal,8204 .normal,
8226 .none,8205 .none,
8227 if (scalar_ty.isSignedInt(zcu)) .smax else .umax,8206 if (scalar_ty.isSignedInt(zcu)) .smax else .umax,
8228 &.{try o.lowerType(inst_ty)},8207 &.{try o.lowerType(pt, inst_ty)},
8229 &.{ lhs, rhs },8208 &.{ lhs, rhs },
8230 "",8209 "",
8231 );8210 );
...@@ -8233,17 +8212,17 @@ pub const FuncGen = struct {...@@ -8233,17 +8212,17 @@ pub const FuncGen = struct {
82338212
8234 fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8213 fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8235 const o = self.ng.object;8214 const o = self.ng.object;
8215 const pt = self.ng.pt;
8236 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8216 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8237 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;8217 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
8238 const ptr = try self.resolveInst(bin_op.lhs);8218 const ptr = try self.resolveInst(bin_op.lhs);
8239 const len = try self.resolveInst(bin_op.rhs);8219 const len = try self.resolveInst(bin_op.rhs);
8240 const inst_ty = self.typeOfIndex(inst);8220 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 }, "");
8242 }8222 }
82438223
8244 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {8224 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8245 const o = self.ng.object;8225 const zcu = self.ng.pt.zcu;
8246 const zcu = o.pt.zcu;
8247 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8226 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8248 const lhs = try self.resolveInst(bin_op.lhs);8227 const lhs = try self.resolveInst(bin_op.lhs);
8249 const rhs = try self.resolveInst(bin_op.rhs);8228 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8261,7 +8240,8 @@ pub const FuncGen = struct {...@@ -8261,7 +8240,8 @@ pub const FuncGen = struct {
8261 unsigned_intrinsic: Builder.Intrinsic,8240 unsigned_intrinsic: Builder.Intrinsic,
8262 ) !Builder.Value {8241 ) !Builder.Value {
8263 const o = fg.ng.object;8242 const o = fg.ng.object;
8264 const zcu = o.pt.zcu;8243 const pt = fg.ng.pt;
8244 const zcu = pt.zcu;
82658245
8266 const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8246 const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8267 const lhs = try fg.resolveInst(bin_op.lhs);8247 const lhs = try fg.resolveInst(bin_op.lhs);
...@@ -8270,7 +8250,7 @@ pub const FuncGen = struct {...@@ -8270,7 +8250,7 @@ pub const FuncGen = struct {
8270 const scalar_ty = inst_ty.scalarType(zcu);8250 const scalar_ty = inst_ty.scalarType(zcu);
82718251
8272 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;8252 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);
8274 const results =8254 const results =
8275 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");8255 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");
82768256
...@@ -8309,7 +8289,8 @@ pub const FuncGen = struct {...@@ -8309,7 +8289,8 @@ pub const FuncGen = struct {
83098289
8310 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8290 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8311 const o = self.ng.object;8291 const o = self.ng.object;
8312 const zcu = o.pt.zcu;8292 const pt = self.ng.pt;
8293 const zcu = pt.zcu;
8313 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8294 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8314 const lhs = try self.resolveInst(bin_op.lhs);8295 const lhs = try self.resolveInst(bin_op.lhs);
8315 const rhs = try self.resolveInst(bin_op.rhs);8296 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8321,15 +8302,14 @@ pub const FuncGen = struct {...@@ -8321,15 +8302,14 @@ pub const FuncGen = struct {
8321 .normal,8302 .normal,
8322 .none,8303 .none,
8323 if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat",8304 if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat",
8324 &.{try o.lowerType(inst_ty)},8305 &.{try o.lowerType(pt, inst_ty)},
8325 &.{ lhs, rhs },8306 &.{ lhs, rhs },
8326 "",8307 "",
8327 );8308 );
8328 }8309 }
83298310
8330 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {8311 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8331 const o = self.ng.object;8312 const zcu = self.ng.pt.zcu;
8332 const zcu = o.pt.zcu;
8333 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8313 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8334 const lhs = try self.resolveInst(bin_op.lhs);8314 const lhs = try self.resolveInst(bin_op.lhs);
8335 const rhs = try self.resolveInst(bin_op.rhs);8315 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8350,7 +8330,8 @@ pub const FuncGen = struct {...@@ -8350,7 +8330,8 @@ pub const FuncGen = struct {
83508330
8351 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8331 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8352 const o = self.ng.object;8332 const o = self.ng.object;
8353 const zcu = o.pt.zcu;8333 const pt = self.ng.pt;
8334 const zcu = pt.zcu;
8354 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8335 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8355 const lhs = try self.resolveInst(bin_op.lhs);8336 const lhs = try self.resolveInst(bin_op.lhs);
8356 const rhs = try self.resolveInst(bin_op.rhs);8337 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8362,15 +8343,14 @@ pub const FuncGen = struct {...@@ -8362,15 +8343,14 @@ pub const FuncGen = struct {
8362 .normal,8343 .normal,
8363 .none,8344 .none,
8364 if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat",8345 if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat",
8365 &.{try o.lowerType(inst_ty)},8346 &.{try o.lowerType(pt, inst_ty)},
8366 &.{ lhs, rhs },8347 &.{ lhs, rhs },
8367 "",8348 "",
8368 );8349 );
8369 }8350 }
83708351
8371 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {8352 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8372 const o = self.ng.object;8353 const zcu = self.ng.pt.zcu;
8373 const zcu = o.pt.zcu;
8374 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8354 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8375 const lhs = try self.resolveInst(bin_op.lhs);8355 const lhs = try self.resolveInst(bin_op.lhs);
8376 const rhs = try self.resolveInst(bin_op.rhs);8356 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8391,7 +8371,8 @@ pub const FuncGen = struct {...@@ -8391,7 +8371,8 @@ pub const FuncGen = struct {
83918371
8392 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8372 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8393 const o = self.ng.object;8373 const o = self.ng.object;
8394 const zcu = o.pt.zcu;8374 const pt = self.ng.pt;
8375 const zcu = pt.zcu;
8395 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8376 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8396 const lhs = try self.resolveInst(bin_op.lhs);8377 const lhs = try self.resolveInst(bin_op.lhs);
8397 const rhs = try self.resolveInst(bin_op.rhs);8378 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8403,7 +8384,7 @@ pub const FuncGen = struct {...@@ -8403,7 +8384,7 @@ pub const FuncGen = struct {
8403 .normal,8384 .normal,
8404 .none,8385 .none,
8405 if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat",8386 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)},
8407 &.{ lhs, rhs, .@"0" },8388 &.{ lhs, rhs, .@"0" },
8408 "",8389 "",
8409 );8390 );
...@@ -8419,8 +8400,7 @@ pub const FuncGen = struct {...@@ -8419,8 +8400,7 @@ pub const FuncGen = struct {
8419 }8400 }
84208401
8421 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {8402 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8422 const o = self.ng.object;8403 const zcu = self.ng.pt.zcu;
8423 const zcu = o.pt.zcu;
8424 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8404 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8425 const lhs = try self.resolveInst(bin_op.lhs);8405 const lhs = try self.resolveInst(bin_op.lhs);
8426 const rhs = try self.resolveInst(bin_op.rhs);8406 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8436,7 +8416,8 @@ pub const FuncGen = struct {...@@ -8436,7 +8416,8 @@ pub const FuncGen = struct {
84368416
8437 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {8417 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8438 const o = self.ng.object;8418 const o = self.ng.object;
8439 const zcu = o.pt.zcu;8419 const pt = self.ng.pt;
8420 const zcu = pt.zcu;
8440 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8421 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8441 const lhs = try self.resolveInst(bin_op.lhs);8422 const lhs = try self.resolveInst(bin_op.lhs);
8442 const rhs = try self.resolveInst(bin_op.rhs);8423 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8448,7 +8429,7 @@ pub const FuncGen = struct {...@@ -8448,7 +8429,7 @@ pub const FuncGen = struct {
8448 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});8429 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});
8449 }8430 }
8450 if (scalar_ty.isSignedInt(zcu)) {8431 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
8453 const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb;8434 const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb;
8454 var stack align(@max(8435 var stack align(@max(
...@@ -8485,8 +8466,7 @@ pub const FuncGen = struct {...@@ -8485,8 +8466,7 @@ pub const FuncGen = struct {
8485 }8466 }
84868467
8487 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {8468 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8488 const o = self.ng.object;8469 const zcu = self.ng.pt.zcu;
8489 const zcu = o.pt.zcu;
8490 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8470 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8491 const lhs = try self.resolveInst(bin_op.lhs);8471 const lhs = try self.resolveInst(bin_op.lhs);
8492 const rhs = try self.resolveInst(bin_op.rhs);8472 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8503,8 +8483,7 @@ pub const FuncGen = struct {...@@ -8503,8 +8483,7 @@ pub const FuncGen = struct {
8503 }8483 }
85048484
8505 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {8485 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8506 const o = self.ng.object;8486 const zcu = self.ng.pt.zcu;
8507 const zcu = o.pt.zcu;
8508 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8487 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8509 const lhs = try self.resolveInst(bin_op.lhs);8488 const lhs = try self.resolveInst(bin_op.lhs);
8510 const rhs = try self.resolveInst(bin_op.rhs);8489 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -8521,12 +8500,13 @@ pub const FuncGen = struct {...@@ -8521,12 +8500,13 @@ pub const FuncGen = struct {
85218500
8522 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {8501 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
8523 const o = self.ng.object;8502 const o = self.ng.object;
8524 const zcu = o.pt.zcu;8503 const pt = self.ng.pt;
8504 const zcu = pt.zcu;
8525 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8505 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8526 const lhs = try self.resolveInst(bin_op.lhs);8506 const lhs = try self.resolveInst(bin_op.lhs);
8527 const rhs = try self.resolveInst(bin_op.rhs);8507 const rhs = try self.resolveInst(bin_op.rhs);
8528 const inst_ty = self.typeOfIndex(inst);8508 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);
8530 const scalar_ty = inst_ty.scalarType(zcu);8510 const scalar_ty = inst_ty.scalarType(zcu);
85318511
8532 if (scalar_ty.isRuntimeFloat()) {8512 if (scalar_ty.isRuntimeFloat()) {
...@@ -8574,17 +8554,18 @@ pub const FuncGen = struct {...@@ -8574,17 +8554,18 @@ pub const FuncGen = struct {
85748554
8575 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8555 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8576 const o = self.ng.object;8556 const o = self.ng.object;
8577 const zcu = o.pt.zcu;8557 const pt = self.ng.pt;
8558 const zcu = pt.zcu;
8578 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8559 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8579 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;8560 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
8580 const ptr = try self.resolveInst(bin_op.lhs);8561 const ptr = try self.resolveInst(bin_op.lhs);
8581 const offset = try self.resolveInst(bin_op.rhs);8562 const offset = try self.resolveInst(bin_op.rhs);
8582 const ptr_ty = self.typeOf(bin_op.lhs);8563 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));
8584 switch (ptr_ty.ptrSize(zcu)) {8565 switch (ptr_ty.ptrSize(zcu)) {
8585 // It's a pointer to an array, so according to LLVM we need an extra GEP index.8566 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
8586 .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{8567 .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,
8588 }, ""),8569 }, ""),
8589 .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""),8570 .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""),
8590 .slice => {8571 .slice => {
...@@ -8596,18 +8577,19 @@ pub const FuncGen = struct {...@@ -8596,18 +8577,19 @@ pub const FuncGen = struct {
85968577
8597 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8578 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8598 const o = self.ng.object;8579 const o = self.ng.object;
8599 const zcu = o.pt.zcu;8580 const pt = self.ng.pt;
8581 const zcu = pt.zcu;
8600 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8582 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8601 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;8583 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
8602 const ptr = try self.resolveInst(bin_op.lhs);8584 const ptr = try self.resolveInst(bin_op.lhs);
8603 const offset = try self.resolveInst(bin_op.rhs);8585 const offset = try self.resolveInst(bin_op.rhs);
8604 const negative_offset = try self.wip.neg(offset, "");8586 const negative_offset = try self.wip.neg(offset, "");
8605 const ptr_ty = self.typeOf(bin_op.lhs);8587 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));
8607 switch (ptr_ty.ptrSize(zcu)) {8589 switch (ptr_ty.ptrSize(zcu)) {
8608 // It's a pointer to an array, so according to LLVM we need an extra GEP index.8590 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
8609 .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{8591 .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,
8611 }, ""),8593 }, ""),
8612 .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""),8594 .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""),
8613 .slice => {8595 .slice => {
...@@ -8624,7 +8606,7 @@ pub const FuncGen = struct {...@@ -8624,7 +8606,7 @@ pub const FuncGen = struct {
8624 unsigned_intrinsic: Builder.Intrinsic,8606 unsigned_intrinsic: Builder.Intrinsic,
8625 ) !Builder.Value {8607 ) !Builder.Value {
8626 const o = self.ng.object;8608 const o = self.ng.object;
8627 const pt = o.pt;8609 const pt = self.ng.pt;
8628 const zcu = pt.zcu;8610 const zcu = pt.zcu;
8629 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8611 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8630 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;8612 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
...@@ -8637,8 +8619,8 @@ pub const FuncGen = struct {...@@ -8637,8 +8619,8 @@ pub const FuncGen = struct {
8637 const inst_ty = self.typeOfIndex(inst);8619 const inst_ty = self.typeOfIndex(inst);
86388620
8639 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;8621 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
8640 const llvm_inst_ty = try o.lowerType(inst_ty);8622 const llvm_inst_ty = try o.lowerType(pt, inst_ty);
8641 const llvm_lhs_ty = try o.lowerType(lhs_ty);8623 const llvm_lhs_ty = try o.lowerType(pt, lhs_ty);
8642 const results =8624 const results =
8643 try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, "");8625 try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, "");
86448626
...@@ -8718,7 +8700,7 @@ pub const FuncGen = struct {...@@ -8718,7 +8700,7 @@ pub const FuncGen = struct {
8718 return o.builder.addFunction(8700 return o.builder.addFunction(
8719 try o.builder.fnType(return_type, param_types, .normal),8701 try o.builder.fnType(return_type, param_types, .normal),
8720 fn_name,8702 fn_name,
8721 toLlvmAddressSpace(.generic, o.pt.zcu.getTarget()),8703 toLlvmAddressSpace(.generic, self.ng.pt.zcu.getTarget()),
8722 );8704 );
8723 }8705 }
87248706
...@@ -8732,10 +8714,11 @@ pub const FuncGen = struct {...@@ -8732,10 +8714,11 @@ pub const FuncGen = struct {
8732 params: [2]Builder.Value,8714 params: [2]Builder.Value,
8733 ) !Builder.Value {8715 ) !Builder.Value {
8734 const o = self.ng.object;8716 const o = self.ng.object;
8735 const zcu = o.pt.zcu;8717 const pt = self.ng.pt;
8718 const zcu = pt.zcu;
8736 const target = zcu.getTarget();8719 const target = zcu.getTarget();
8737 const scalar_ty = ty.scalarType(zcu);8720 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
8740 if (intrinsicsAllowed(scalar_ty, target)) {8723 if (intrinsicsAllowed(scalar_ty, target)) {
8741 const cond: Builder.FloatCondition = switch (pred) {8724 const cond: Builder.FloatCondition = switch (pred) {
...@@ -8838,10 +8821,11 @@ pub const FuncGen = struct {...@@ -8838,10 +8821,11 @@ pub const FuncGen = struct {
8838 params: [params_len]Builder.Value,8821 params: [params_len]Builder.Value,
8839 ) !Builder.Value {8822 ) !Builder.Value {
8840 const o = self.ng.object;8823 const o = self.ng.object;
8841 const zcu = o.pt.zcu;8824 const pt = self.ng.pt;
8825 const zcu = pt.zcu;
8842 const target = zcu.getTarget();8826 const target = zcu.getTarget();
8843 const scalar_ty = ty.scalarType(zcu);8827 const scalar_ty = ty.scalarType(zcu);
8844 const llvm_ty = try o.lowerType(ty);8828 const llvm_ty = try o.lowerType(pt, ty);
88458829
8846 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {8830 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {
8847 // Some operations are dedicated LLVM instructions, not available as intrinsics8831 // Some operations are dedicated LLVM instructions, not available as intrinsics
...@@ -8979,7 +8963,7 @@ pub const FuncGen = struct {...@@ -8979,7 +8963,7 @@ pub const FuncGen = struct {
89798963
8980 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8964 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8981 const o = self.ng.object;8965 const o = self.ng.object;
8982 const pt = o.pt;8966 const pt = self.ng.pt;
8983 const zcu = pt.zcu;8967 const zcu = pt.zcu;
8984 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8968 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8985 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;8969 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
...@@ -8993,9 +8977,9 @@ pub const FuncGen = struct {...@@ -8993,9 +8977,9 @@ pub const FuncGen = struct {
8993 const lhs_scalar_ty = lhs_ty.scalarType(zcu);8977 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
89948978
8995 const dest_ty = self.typeOfIndex(inst);8979 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
9000 const result = try self.wip.bin(.shl, lhs, casted_rhs, "");8984 const result = try self.wip.bin(.shl, lhs, casted_rhs, "");
9001 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))8985 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
...@@ -9052,7 +9036,8 @@ pub const FuncGen = struct {...@@ -9052,7 +9036,8 @@ pub const FuncGen = struct {
90529036
9053 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9037 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9054 const o = self.ng.object;9038 const o = self.ng.object;
9055 const zcu = o.pt.zcu;9039 const pt = self.ng.pt;
9040 const zcu = pt.zcu;
9056 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9041 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
90579042
9058 const lhs = try self.resolveInst(bin_op.lhs);9043 const lhs = try self.resolveInst(bin_op.lhs);
...@@ -9063,7 +9048,7 @@ pub const FuncGen = struct {...@@ -9063,7 +9048,7 @@ pub const FuncGen = struct {
9063 return self.ng.todo("implement vector shifts with scalar rhs", .{});9048 return self.ng.todo("implement vector shifts with scalar rhs", .{});
9064 const lhs_scalar_ty = lhs_ty.scalarType(zcu);9049 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), "");
9067 return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))9052 return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
9068 .@"shl nsw"9053 .@"shl nsw"
9069 else9054 else
...@@ -9072,7 +9057,8 @@ pub const FuncGen = struct {...@@ -9072,7 +9057,8 @@ pub const FuncGen = struct {
90729057
9073 fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9058 fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9074 const o = self.ng.object;9059 const o = self.ng.object;
9075 const zcu = o.pt.zcu;9060 const pt = self.ng.pt;
9061 const zcu = pt.zcu;
9076 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9062 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
90779063
9078 const lhs = try self.resolveInst(bin_op.lhs);9064 const lhs = try self.resolveInst(bin_op.lhs);
...@@ -9082,13 +9068,13 @@ pub const FuncGen = struct {...@@ -9082,13 +9068,13 @@ pub const FuncGen = struct {
9082 if (lhs_ty.isVector(zcu) and !self.typeOf(bin_op.rhs).isVector(zcu))9068 if (lhs_ty.isVector(zcu) and !self.typeOf(bin_op.rhs).isVector(zcu))
9083 return self.ng.todo("implement vector shifts with scalar rhs", .{});9069 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), "");
9086 return self.wip.bin(.shl, lhs, casted_rhs, "");9072 return self.wip.bin(.shl, lhs, casted_rhs, "");
9087 }9073 }
90889074
9089 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9075 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9090 const o = self.ng.object;9076 const o = self.ng.object;
9091 const pt = o.pt;9077 const pt = self.ng.pt;
9092 const zcu = pt.zcu;9078 const zcu = pt.zcu;
9093 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9079 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
90949080
...@@ -9097,7 +9083,7 @@ pub const FuncGen = struct {...@@ -9097,7 +9083,7 @@ pub const FuncGen = struct {
90979083
9098 const lhs_ty = self.typeOf(bin_op.lhs);9084 const lhs_ty = self.typeOf(bin_op.lhs);
9099 const lhs_info = lhs_ty.intInfo(zcu);9085 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);
9101 const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder);9087 const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder);
91029088
9103 const rhs_ty = self.typeOf(bin_op.rhs);9089 const rhs_ty = self.typeOf(bin_op.rhs);
...@@ -9105,7 +9091,7 @@ pub const FuncGen = struct {...@@ -9105,7 +9091,7 @@ pub const FuncGen = struct {
9105 return self.ng.todo("implement vector shifts with scalar rhs", .{});9091 return self.ng.todo("implement vector shifts with scalar rhs", .{});
9106 const rhs_info = rhs_ty.intInfo(zcu);9092 const rhs_info = rhs_ty.intInfo(zcu);
9107 assert(rhs_info.signedness == .unsigned);9093 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);
9109 const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder);9095 const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder);
91109096
9111 const result = try self.wip.callIntrinsic(9097 const result = try self.wip.callIntrinsic(
...@@ -9168,7 +9154,8 @@ pub const FuncGen = struct {...@@ -9168,7 +9154,8 @@ pub const FuncGen = struct {
91689154
9169 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {9155 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {
9170 const o = self.ng.object;9156 const o = self.ng.object;
9171 const zcu = o.pt.zcu;9157 const pt = self.ng.pt;
9158 const zcu = pt.zcu;
9172 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9159 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
91739160
9174 const lhs = try self.resolveInst(bin_op.lhs);9161 const lhs = try self.resolveInst(bin_op.lhs);
...@@ -9179,7 +9166,7 @@ pub const FuncGen = struct {...@@ -9179,7 +9166,7 @@ pub const FuncGen = struct {
9179 return self.ng.todo("implement vector shifts with scalar rhs", .{});9166 return self.ng.todo("implement vector shifts with scalar rhs", .{});
9180 const lhs_scalar_ty = lhs_ty.scalarType(zcu);9167 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), "");
9183 const is_signed_int = lhs_scalar_ty.isSignedInt(zcu);9170 const is_signed_int = lhs_scalar_ty.isSignedInt(zcu);
91849171
9185 return self.wip.bin(if (is_exact)9172 return self.wip.bin(if (is_exact)
...@@ -9189,7 +9176,8 @@ pub const FuncGen = struct {...@@ -9189,7 +9176,8 @@ pub const FuncGen = struct {
91899176
9190 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9177 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9191 const o = self.ng.object;9178 const o = self.ng.object;
9192 const zcu = o.pt.zcu;9179 const pt = self.ng.pt;
9180 const zcu = pt.zcu;
9193 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9181 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9194 const operand = try self.resolveInst(ty_op.operand);9182 const operand = try self.resolveInst(ty_op.operand);
9195 const operand_ty = self.typeOf(ty_op.operand);9183 const operand_ty = self.typeOf(ty_op.operand);
...@@ -9200,7 +9188,7 @@ pub const FuncGen = struct {...@@ -9200,7 +9188,7 @@ pub const FuncGen = struct {
9200 .normal,9188 .normal,
9201 .none,9189 .none,
9202 .abs,9190 .abs,
9203 &.{try o.lowerType(operand_ty)},9191 &.{try o.lowerType(pt, operand_ty)},
9204 &.{ operand, try o.builder.intValue(.i1, 0) },9192 &.{ operand, try o.builder.intValue(.i1, 0) },
9205 "",9193 "",
9206 ),9194 ),
...@@ -9211,10 +9199,11 @@ pub const FuncGen = struct {...@@ -9211,10 +9199,11 @@ pub const FuncGen = struct {
92119199
9212 fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {9200 fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
9213 const o = fg.ng.object;9201 const o = fg.ng.object;
9214 const zcu = o.pt.zcu;9202 const pt = fg.ng.pt;
9203 const zcu = pt.zcu;
9215 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9204 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9216 const dest_ty = fg.typeOfIndex(inst);9205 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);
9218 const operand = try fg.resolveInst(ty_op.operand);9207 const operand = try fg.resolveInst(ty_op.operand);
9219 const operand_ty = fg.typeOf(ty_op.operand);9208 const operand_ty = fg.typeOf(ty_op.operand);
9220 const operand_info = operand_ty.intInfo(zcu);9209 const operand_info = operand_ty.intInfo(zcu);
...@@ -9243,8 +9232,8 @@ pub const FuncGen = struct {...@@ -9243,8 +9232,8 @@ pub const FuncGen = struct {
92439232
9244 if (!have_min_check and !have_max_check) break :safety;9233 if (!have_min_check and !have_max_check) break :safety;
92459234
9246 const operand_llvm_ty = try o.lowerType(operand_ty);9235 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9247 const operand_scalar_llvm_ty = try o.lowerType(operand_scalar);9236 const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar);
92489237
9249 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;9238 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;
9250 assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector));9239 assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector));
...@@ -9313,15 +9302,17 @@ pub const FuncGen = struct {...@@ -9313,15 +9302,17 @@ pub const FuncGen = struct {
93139302
9314 fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9303 fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9315 const o = self.ng.object;9304 const o = self.ng.object;
9305 const pt = self.ng.pt;
9316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9306 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9317 const operand = try self.resolveInst(ty_op.operand);9307 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));
9319 return self.wip.cast(.trunc, operand, dest_llvm_ty, "");9309 return self.wip.cast(.trunc, operand, dest_llvm_ty, "");
9320 }9310 }
93219311
9322 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9312 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9323 const o = self.ng.object;9313 const o = self.ng.object;
9324 const zcu = o.pt.zcu;9314 const pt = self.ng.pt;
9315 const zcu = pt.zcu;
9325 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9326 const operand = try self.resolveInst(ty_op.operand);9317 const operand = try self.resolveInst(ty_op.operand);
9327 const operand_ty = self.typeOf(ty_op.operand);9318 const operand_ty = self.typeOf(ty_op.operand);
...@@ -9329,10 +9320,10 @@ pub const FuncGen = struct {...@@ -9329,10 +9320,10 @@ pub const FuncGen = struct {
9329 const target = zcu.getTarget();9320 const target = zcu.getTarget();
93309321
9331 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {9322 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), "");
9333 } else {9324 } else {
9334 const operand_llvm_ty = try o.lowerType(operand_ty);9325 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9335 const dest_llvm_ty = try o.lowerType(dest_ty);9326 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
93369327
9337 const dest_bits = dest_ty.floatBits(target);9328 const dest_bits = dest_ty.floatBits(target);
9338 const src_bits = operand_ty.floatBits(target);9329 const src_bits = operand_ty.floatBits(target);
...@@ -9355,7 +9346,8 @@ pub const FuncGen = struct {...@@ -9355,7 +9346,8 @@ pub const FuncGen = struct {
93559346
9356 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9347 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9357 const o = self.ng.object;9348 const o = self.ng.object;
9358 const zcu = o.pt.zcu;9349 const pt = self.ng.pt;
9350 const zcu = pt.zcu;
9359 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9351 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9360 const operand = try self.resolveInst(ty_op.operand);9352 const operand = try self.resolveInst(ty_op.operand);
9361 const operand_ty = self.typeOf(ty_op.operand);9353 const operand_ty = self.typeOf(ty_op.operand);
...@@ -9363,10 +9355,10 @@ pub const FuncGen = struct {...@@ -9363,10 +9355,10 @@ pub const FuncGen = struct {
9363 const target = zcu.getTarget();9355 const target = zcu.getTarget();
93649356
9365 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {9357 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), "");
9367 } else {9359 } else {
9368 const operand_llvm_ty = try o.lowerType(operand_ty);9360 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9369 const dest_llvm_ty = try o.lowerType(dest_ty);9361 const dest_llvm_ty = try o.lowerType(pt, dest_ty);
93709362
9371 const dest_bits = dest_ty.scalarType(zcu).floatBits(target);9363 const dest_bits = dest_ty.scalarType(zcu).floatBits(target);
9372 const src_bits = operand_ty.scalarType(zcu).floatBits(target);9364 const src_bits = operand_ty.scalarType(zcu).floatBits(target);
...@@ -9403,11 +9395,11 @@ pub const FuncGen = struct {...@@ -9403,11 +9395,11 @@ pub const FuncGen = struct {
94039395
9404 fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value {9396 fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value {
9405 const o = self.ng.object;9397 const o = self.ng.object;
9406 const pt = o.pt;9398 const pt = self.ng.pt;
9407 const zcu = pt.zcu;9399 const zcu = pt.zcu;
9408 const operand_is_ref = isByRef(operand_ty, zcu);9400 const operand_is_ref = isByRef(operand_ty, zcu);
9409 const result_is_ref = isByRef(inst_ty, zcu);9401 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
9412 if (operand_is_ref and result_is_ref) {9404 if (operand_is_ref and result_is_ref) {
9413 // They are both pointers, so just return the same opaque pointer :)9405 // They are both pointers, so just return the same opaque pointer :)
...@@ -9442,7 +9434,7 @@ pub const FuncGen = struct {...@@ -9442,7 +9434,7 @@ pub const FuncGen = struct {
9442 } else {9434 } else {
9443 // If the ABI size of the element type is not evenly divisible by size in bits;9435 // If the ABI size of the element type is not evenly divisible by size in bits;
9444 // a simple bitcast will not work, and we fall back to extractelement.9436 // 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);
9446 const usize_zero = try o.builder.intValue(llvm_usize, 0);9438 const usize_zero = try o.builder.intValue(llvm_usize, 0);
9447 const vector_len = operand_ty.arrayLen(zcu);9439 const vector_len = operand_ty.arrayLen(zcu);
9448 var i: u64 = 0;9440 var i: u64 = 0;
...@@ -9458,7 +9450,7 @@ pub const FuncGen = struct {...@@ -9458,7 +9450,7 @@ pub const FuncGen = struct {
9458 return array_ptr;9450 return array_ptr;
9459 } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) {9451 } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) {
9460 const elem_ty = operand_ty.childType(zcu);9452 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);
9462 if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{});9454 if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{});
94639455
9464 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;9456 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;
...@@ -9470,9 +9462,9 @@ pub const FuncGen = struct {...@@ -9470,9 +9462,9 @@ pub const FuncGen = struct {
9470 } else {9462 } else {
9471 // If the ABI size of the element type is not evenly divisible by size in bits;9463 // If the ABI size of the element type is not evenly divisible by size in bits;
9472 // a simple bitcast will not work, and we fall back to extractelement.9464 // a simple bitcast will not work, and we fall back to extractelement.
9473 const array_llvm_ty = try o.lowerType(operand_ty);9465 const array_llvm_ty = try o.lowerType(pt, operand_ty);
9474 const elem_llvm_ty = try o.lowerType(elem_ty);9466 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
9475 const llvm_usize = try o.lowerType(Type.usize);9467 const llvm_usize = try o.lowerType(pt, Type.usize);
9476 const usize_zero = try o.builder.intValue(llvm_usize, 0);9468 const usize_zero = try o.builder.intValue(llvm_usize, 0);
9477 const vector_len = operand_ty.arrayLen(zcu);9469 const vector_len = operand_ty.arrayLen(zcu);
9478 var vector = try o.builder.poisonValue(llvm_vector_ty);9470 var vector = try o.builder.poisonValue(llvm_vector_ty);
...@@ -9519,7 +9511,7 @@ pub const FuncGen = struct {...@@ -9519,7 +9511,7 @@ pub const FuncGen = struct {
95199511
9520 fn airArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9512 fn airArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9521 const o = self.ng.object;9513 const o = self.ng.object;
9522 const pt = o.pt;9514 const pt = self.ng.pt;
9523 const zcu = pt.zcu;9515 const zcu = pt.zcu;
9524 const arg_val = self.args[self.arg_index];9516 const arg_val = self.args[self.arg_index];
9525 self.arg_index += 1;9517 self.arg_index += 1;
...@@ -9547,7 +9539,7 @@ pub const FuncGen = struct {...@@ -9547,7 +9539,7 @@ pub const FuncGen = struct {
9547 self.file,9539 self.file,
9548 self.scope,9540 self.scope,
9549 lbrace_line,9541 lbrace_line,
9550 try o.lowerDebugType(inst_ty),9542 try o.lowerDebugType(pt, inst_ty),
9551 self.arg_index,9543 self.arg_index,
9552 );9544 );
95539545
...@@ -9611,28 +9603,28 @@ pub const FuncGen = struct {...@@ -9611,28 +9603,28 @@ pub const FuncGen = struct {
96119603
9612 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9604 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9613 const o = self.ng.object;9605 const o = self.ng.object;
9614 const pt = o.pt;9606 const pt = self.ng.pt;
9615 const zcu = pt.zcu;9607 const zcu = pt.zcu;
9616 const ptr_ty = self.typeOfIndex(inst);9608 const ptr_ty = self.typeOfIndex(inst);
9617 const pointee_type = ptr_ty.childType(zcu);9609 const pointee_type = ptr_ty.childType(zcu);
9618 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu))9610 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);
9622 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();9614 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
9623 return self.buildAlloca(pointee_llvm_ty, alignment);9615 return self.buildAlloca(pointee_llvm_ty, alignment);
9624 }9616 }
96259617
9626 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9618 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9627 const o = self.ng.object;9619 const o = self.ng.object;
9628 const pt = o.pt;9620 const pt = self.ng.pt;
9629 const zcu = pt.zcu;9621 const zcu = pt.zcu;
9630 const ptr_ty = self.typeOfIndex(inst);9622 const ptr_ty = self.typeOfIndex(inst);
9631 const ret_ty = ptr_ty.childType(zcu);9623 const ret_ty = ptr_ty.childType(zcu);
9632 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu))9624 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
9633 return (try o.lowerPtrToVoid(ptr_ty)).toValue();9625 return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue();
9634 if (self.ret_ptr != .none) return self.ret_ptr;9626 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);
9636 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();9628 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
9637 return self.buildAlloca(ret_llvm_ty, alignment);9629 return self.buildAlloca(ret_llvm_ty, alignment);
9638 }9630 }
...@@ -9644,13 +9636,13 @@ pub const FuncGen = struct {...@@ -9644,13 +9636,13 @@ pub const FuncGen = struct {
9644 llvm_ty: Builder.Type,9636 llvm_ty: Builder.Type,
9645 alignment: Builder.Alignment,9637 alignment: Builder.Alignment,
9646 ) Allocator.Error!Builder.Value {9638 ) Allocator.Error!Builder.Value {
9647 const target = self.ng.object.pt.zcu.getTarget();9639 const target = self.ng.pt.zcu.getTarget();
9648 return buildAllocaInner(&self.wip, llvm_ty, alignment, target);9640 return buildAllocaInner(&self.wip, llvm_ty, alignment, target);
9649 }9641 }
96509642
9651 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {9643 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
9652 const o = self.ng.object;9644 const o = self.ng.object;
9653 const pt = o.pt;9645 const pt = self.ng.pt;
9654 const zcu = pt.zcu;9646 const zcu = pt.zcu;
9655 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9647 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9656 const dest_ptr = try self.resolveInst(bin_op.lhs);9648 const dest_ptr = try self.resolveInst(bin_op.lhs);
...@@ -9685,7 +9677,7 @@ pub const FuncGen = struct {...@@ -9685,7 +9677,7 @@ pub const FuncGen = struct {
96859677
9686 self.maybeMarkAllowZeroAccess(ptr_info);9678 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));
9689 _ = try self.wip.callMemSet(9681 _ = try self.wip.callMemSet(
9690 dest_ptr,9682 dest_ptr,
9691 ptr_ty.ptrAlignment(zcu).toLlvm(),9683 ptr_ty.ptrAlignment(zcu).toLlvm(),
...@@ -9714,8 +9706,7 @@ pub const FuncGen = struct {...@@ -9714,8 +9706,7 @@ pub const FuncGen = struct {
9714 ///9706 ///
9715 /// The first instruction of `body_tail` is the one whose copy we want to elide.9707 /// The first instruction of `body_tail` is the one whose copy we want to elide.
9716 fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool {9708 fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool {
9717 const o = fg.ng.object;9709 const zcu = fg.ng.pt.zcu;
9718 const zcu = o.pt.zcu;
9719 const ip = &zcu.intern_pool;9710 const ip = &zcu.intern_pool;
9720 for (body_tail[1..]) |body_inst| {9711 for (body_tail[1..]) |body_inst| {
9721 switch (fg.liveness.categorizeOperand(fg.air, zcu, body_inst, body_tail[0], ip)) {9712 switch (fg.liveness.categorizeOperand(fg.air, zcu, body_inst, body_tail[0], ip)) {
...@@ -9730,8 +9721,7 @@ pub const FuncGen = struct {...@@ -9730,8 +9721,7 @@ pub const FuncGen = struct {
9730 }9721 }
97319722
9732 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {9723 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
9733 const o = fg.ng.object;9724 const pt = fg.ng.pt;
9734 const pt = o.pt;
9735 const zcu = pt.zcu;9725 const zcu = pt.zcu;
9736 const inst = body_tail[0];9726 const inst = body_tail[0];
9737 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9727 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
...@@ -9765,8 +9755,9 @@ pub const FuncGen = struct {...@@ -9765,8 +9755,9 @@ pub const FuncGen = struct {
9765 fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9755 fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9766 _ = inst;9756 _ = inst;
9767 const o = self.ng.object;9757 const o = self.ng.object;
9768 const llvm_usize = try o.lowerType(Type.usize);9758 const pt = self.ng.pt;
9769 if (!target_util.supportsReturnAddress(o.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) {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)) {
9770 // https://github.com/ziglang/zig/issues/119469761 // https://github.com/ziglang/zig/issues/11946
9771 return o.builder.intValue(llvm_usize, 0);9762 return o.builder.intValue(llvm_usize, 0);
9772 }9763 }
...@@ -9777,8 +9768,9 @@ pub const FuncGen = struct {...@@ -9777,8 +9768,9 @@ pub const FuncGen = struct {
9777 fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9768 fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9778 _ = inst;9769 _ = inst;
9779 const o = self.ng.object;9770 const o = self.ng.object;
9771 const pt = self.ng.pt;
9780 const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, "");9772 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), "");
9782 }9774 }
97839775
9784 fn airCmpxchg(9776 fn airCmpxchg(
...@@ -9787,7 +9779,7 @@ pub const FuncGen = struct {...@@ -9787,7 +9779,7 @@ pub const FuncGen = struct {
9787 kind: Builder.Function.Instruction.CmpXchg.Kind,9779 kind: Builder.Function.Instruction.CmpXchg.Kind,
9788 ) !Builder.Value {9780 ) !Builder.Value {
9789 const o = self.ng.object;9781 const o = self.ng.object;
9790 const pt = o.pt;9782 const pt = self.ng.pt;
9791 const zcu = pt.zcu;9783 const zcu = pt.zcu;
9792 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;9784 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
9793 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;9785 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
...@@ -9796,8 +9788,8 @@ pub const FuncGen = struct {...@@ -9796,8 +9788,8 @@ pub const FuncGen = struct {
9796 var expected_value = try self.resolveInst(extra.expected_value);9788 var expected_value = try self.resolveInst(extra.expected_value);
9797 var new_value = try self.resolveInst(extra.new_value);9789 var new_value = try self.resolveInst(extra.new_value);
9798 const operand_ty = ptr_ty.childType(zcu);9790 const operand_ty = ptr_ty.childType(zcu);
9799 const llvm_operand_ty = try o.lowerType(operand_ty);9791 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
9800 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);9792 const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false);
9801 if (llvm_abi_ty != .none) {9793 if (llvm_abi_ty != .none) {
9802 // operand needs widening and truncating9794 // operand needs widening and truncating
9803 const signedness: Builder.Function.Instruction.Cast.Signedness =9795 const signedness: Builder.Function.Instruction.Cast.Signedness =
...@@ -9840,7 +9832,7 @@ pub const FuncGen = struct {...@@ -9840,7 +9832,7 @@ pub const FuncGen = struct {
98409832
9841 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9833 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9842 const o = self.ng.object;9834 const o = self.ng.object;
9843 const pt = o.pt;9835 const pt = self.ng.pt;
9844 const zcu = pt.zcu;9836 const zcu = pt.zcu;
9845 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;9837 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
9846 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;9838 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
...@@ -9852,8 +9844,8 @@ pub const FuncGen = struct {...@@ -9852,8 +9844,8 @@ pub const FuncGen = struct {
9852 const is_float = operand_ty.isRuntimeFloat();9844 const is_float = operand_ty.isRuntimeFloat();
9853 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);9845 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);
9854 const ordering = toLlvmAtomicOrdering(extra.ordering());9846 const ordering = toLlvmAtomicOrdering(extra.ordering());
9855 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, op == .xchg);9847 const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, op == .xchg);
9856 const llvm_operand_ty = try o.lowerType(operand_ty);9848 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
98579849
9858 const access_kind: Builder.MemoryAccessKind =9850 const access_kind: Builder.MemoryAccessKind =
9859 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;9851 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
...@@ -9896,7 +9888,7 @@ pub const FuncGen = struct {...@@ -9896,7 +9888,7 @@ pub const FuncGen = struct {
9896 access_kind,9888 access_kind,
9897 op,9889 op,
9898 ptr,9890 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), ""),
9900 self.sync_scope,9892 self.sync_scope,
9901 ordering,9893 ordering,
9902 ptr_alignment,9894 ptr_alignment,
...@@ -9906,7 +9898,7 @@ pub const FuncGen = struct {...@@ -9906,7 +9898,7 @@ pub const FuncGen = struct {
99069898
9907 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9899 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9908 const o = self.ng.object;9900 const o = self.ng.object;
9909 const pt = o.pt;9901 const pt = self.ng.pt;
9910 const zcu = pt.zcu;9902 const zcu = pt.zcu;
9911 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;9903 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
9912 const ptr = try self.resolveInst(atomic_load.ptr);9904 const ptr = try self.resolveInst(atomic_load.ptr);
...@@ -9915,14 +9907,14 @@ pub const FuncGen = struct {...@@ -9915,14 +9907,14 @@ pub const FuncGen = struct {
9915 const elem_ty = Type.fromInterned(info.child);9907 const elem_ty = Type.fromInterned(info.child);
9916 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;9908 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
9917 const ordering = toLlvmAtomicOrdering(atomic_load.order);9909 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);
9919 const ptr_alignment = (if (info.flags.alignment != .none)9911 const ptr_alignment = (if (info.flags.alignment != .none)
9920 @as(InternPool.Alignment, info.flags.alignment)9912 @as(InternPool.Alignment, info.flags.alignment)
9921 else9913 else
9922 Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm();9914 Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm();
9923 const access_kind: Builder.MemoryAccessKind =9915 const access_kind: Builder.MemoryAccessKind =
9924 if (info.flags.is_volatile) .@"volatile" else .normal;9916 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
9927 self.maybeMarkAllowZeroAccess(info);9919 self.maybeMarkAllowZeroAccess(info);
99289920
...@@ -9956,7 +9948,7 @@ pub const FuncGen = struct {...@@ -9956,7 +9948,7 @@ pub const FuncGen = struct {
9956 ordering: Builder.AtomicOrdering,9948 ordering: Builder.AtomicOrdering,
9957 ) !Builder.Value {9949 ) !Builder.Value {
9958 const o = self.ng.object;9950 const o = self.ng.object;
9959 const pt = o.pt;9951 const pt = self.ng.pt;
9960 const zcu = pt.zcu;9952 const zcu = pt.zcu;
9961 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9953 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9962 const ptr_ty = self.typeOf(bin_op.lhs);9954 const ptr_ty = self.typeOf(bin_op.lhs);
...@@ -9964,7 +9956,7 @@ pub const FuncGen = struct {...@@ -9964,7 +9956,7 @@ pub const FuncGen = struct {
9964 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none;9956 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none;
9965 const ptr = try self.resolveInst(bin_op.lhs);9957 const ptr = try self.resolveInst(bin_op.lhs);
9966 var element = try self.resolveInst(bin_op.rhs);9958 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
9969 if (llvm_abi_ty != .none) {9961 if (llvm_abi_ty != .none) {
9970 // operand needs widening9962 // operand needs widening
...@@ -9984,7 +9976,7 @@ pub const FuncGen = struct {...@@ -9984,7 +9976,7 @@ pub const FuncGen = struct {
99849976
9985 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {9977 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
9986 const o = self.ng.object;9978 const o = self.ng.object;
9987 const pt = o.pt;9979 const pt = self.ng.pt;
9988 const zcu = pt.zcu;9980 const zcu = pt.zcu;
9989 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9981 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9990 const dest_slice = try self.resolveInst(bin_op.lhs);9982 const dest_slice = try self.resolveInst(bin_op.lhs);
...@@ -10081,13 +10073,13 @@ pub const FuncGen = struct {...@@ -10081,13 +10073,13 @@ pub const FuncGen = struct {
10081 const body_block = try self.wip.block(1, "InlineMemsetBody");10073 const body_block = try self.wip.block(1, "InlineMemsetBody");
10082 const end_block = try self.wip.block(1, "InlineMemsetEnd");10074 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);
10085 const len = switch (ptr_ty.ptrSize(zcu)) {10077 const len = switch (ptr_ty.ptrSize(zcu)) {
10086 .slice => try self.wip.extractValue(dest_slice, &.{1}, ""),10078 .slice => try self.wip.extractValue(dest_slice, &.{1}, ""),
10087 .one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)),10079 .one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)),
10088 .many, .c => unreachable,10080 .many, .c => unreachable,
10089 };10081 };
10090 const elem_llvm_ty = try o.lowerType(elem_ty);10082 const elem_llvm_ty = try o.lowerType(pt, elem_ty);
10091 const end_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, dest_ptr, &.{len}, "");10083 const end_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, dest_ptr, &.{len}, "");
10092 _ = try self.wip.br(loop_block);10084 _ = try self.wip.br(loop_block);
1009310085
...@@ -10121,8 +10113,7 @@ pub const FuncGen = struct {...@@ -10121,8 +10113,7 @@ pub const FuncGen = struct {
10121 }10113 }
1012210114
10123 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10115 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10124 const o = self.ng.object;10116 const pt = self.ng.pt;
10125 const pt = o.pt;
10126 const zcu = pt.zcu;10117 const zcu = pt.zcu;
10127 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;10118 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
10128 const dest_slice = try self.resolveInst(bin_op.lhs);10119 const dest_slice = try self.resolveInst(bin_op.lhs);
...@@ -10151,8 +10142,7 @@ pub const FuncGen = struct {...@@ -10151,8 +10142,7 @@ pub const FuncGen = struct {
10151 }10142 }
1015210143
10153 fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10144 fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10154 const o = self.ng.object;10145 const pt = self.ng.pt;
10155 const pt = o.pt;
10156 const zcu = pt.zcu;10146 const zcu = pt.zcu;
10157 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;10147 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
10158 const dest_slice = try self.resolveInst(bin_op.lhs);10148 const dest_slice = try self.resolveInst(bin_op.lhs);
...@@ -10178,7 +10168,7 @@ pub const FuncGen = struct {...@@ -10178,7 +10168,7 @@ pub const FuncGen = struct {
1017810168
10179 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10169 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10180 const o = self.ng.object;10170 const o = self.ng.object;
10181 const pt = o.pt;10171 const pt = self.ng.pt;
10182 const zcu = pt.zcu;10172 const zcu = pt.zcu;
10183 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;10173 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
10184 const un_ptr_ty = self.typeOf(bin_op.lhs);10174 const un_ptr_ty = self.typeOf(bin_op.lhs);
...@@ -10199,7 +10189,7 @@ pub const FuncGen = struct {...@@ -10199,7 +10189,7 @@ pub const FuncGen = struct {
10199 return .none;10189 return .none;
10200 }10190 }
10201 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));10191 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, "");
10203 // TODO alignment on this store10193 // TODO alignment on this store
10204 _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, .default);10194 _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, .default);
10205 return .none;10195 return .none;
...@@ -10207,7 +10197,7 @@ pub const FuncGen = struct {...@@ -10207,7 +10197,7 @@ pub const FuncGen = struct {
1020710197
10208 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10198 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10209 const o = self.ng.object;10199 const o = self.ng.object;
10210 const pt = o.pt;10200 const pt = self.ng.pt;
10211 const zcu = pt.zcu;10201 const zcu = pt.zcu;
10212 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;10202 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
10213 const un_ty = self.typeOf(ty_op.operand);10203 const un_ty = self.typeOf(ty_op.operand);
...@@ -10215,7 +10205,7 @@ pub const FuncGen = struct {...@@ -10215,7 +10205,7 @@ pub const FuncGen = struct {
10215 if (layout.tag_size == 0) return .none;10205 if (layout.tag_size == 0) return .none;
10216 const union_handle = try self.resolveInst(ty_op.operand);10206 const union_handle = try self.resolveInst(ty_op.operand);
10217 if (isByRef(un_ty, zcu)) {10207 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);
10219 if (layout.payload_size == 0)10209 if (layout.payload_size == 0)
10220 return self.wip.load(.normal, llvm_un_ty, union_handle, .default, "");10210 return self.wip.load(.normal, llvm_un_ty, union_handle, .default, "");
10221 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));10211 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
...@@ -10247,6 +10237,7 @@ pub const FuncGen = struct {...@@ -10247,6 +10237,7 @@ pub const FuncGen = struct {
1024710237
10248 fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {10238 fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
10249 const o = self.ng.object;10239 const o = self.ng.object;
10240 const pt = self.ng.pt;
10250 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;10241 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
10251 const inst_ty = self.typeOfIndex(inst);10242 const inst_ty = self.typeOfIndex(inst);
10252 const operand_ty = self.typeOf(ty_op.operand);10243 const operand_ty = self.typeOf(ty_op.operand);
...@@ -10256,15 +10247,16 @@ pub const FuncGen = struct {...@@ -10256,15 +10247,16 @@ pub const FuncGen = struct {
10256 .normal,10247 .normal,
10257 .none,10248 .none,
10258 intrinsic,10249 intrinsic,
10259 &.{try o.lowerType(operand_ty)},10250 &.{try o.lowerType(pt, operand_ty)},
10260 &.{ operand, .false },10251 &.{ operand, .false },
10261 "",10252 "",
10262 );10253 );
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), "");
10264 }10255 }
1026510256
10266 fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {10257 fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value {
10267 const o = self.ng.object;10258 const o = self.ng.object;
10259 const pt = self.ng.pt;
10268 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;10260 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
10269 const inst_ty = self.typeOfIndex(inst);10261 const inst_ty = self.typeOfIndex(inst);
10270 const operand_ty = self.typeOf(ty_op.operand);10262 const operand_ty = self.typeOf(ty_op.operand);
...@@ -10274,16 +10266,17 @@ pub const FuncGen = struct {...@@ -10274,16 +10266,17 @@ pub const FuncGen = struct {
10274 .normal,10266 .normal,
10275 .none,10267 .none,
10276 intrinsic,10268 intrinsic,
10277 &.{try o.lowerType(operand_ty)},10269 &.{try o.lowerType(pt, operand_ty)},
10278 &.{operand},10270 &.{operand},
10279 "",10271 "",
10280 );10272 );
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), "");
10282 }10274 }
1028310275
10284 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10276 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10285 const o = self.ng.object;10277 const o = self.ng.object;
10286 const zcu = o.pt.zcu;10278 const pt = self.ng.pt;
10279 const zcu = pt.zcu;
10287 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;10280 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
10288 const operand_ty = self.typeOf(ty_op.operand);10281 const operand_ty = self.typeOf(ty_op.operand);
10289 var bits = operand_ty.intInfo(zcu).bits;10282 var bits = operand_ty.intInfo(zcu).bits;
...@@ -10291,7 +10284,7 @@ pub const FuncGen = struct {...@@ -10291,7 +10284,7 @@ pub const FuncGen = struct {
1029110284
10292 const inst_ty = self.typeOfIndex(inst);10285 const inst_ty = self.typeOfIndex(inst);
10293 var operand = try self.resolveInst(ty_op.operand);10286 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
10296 if (bits % 16 == 8) {10289 if (bits % 16 == 8) {
10297 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte10290 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte
...@@ -10312,12 +10305,13 @@ pub const FuncGen = struct {...@@ -10312,12 +10305,13 @@ pub const FuncGen = struct {
1031210305
10313 const result =10306 const result =
10314 try self.wip.callIntrinsic(.normal, .none, .bswap, &.{llvm_operand_ty}, &.{operand}, "");10307 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), "");
10316 }10309 }
1031710310
10318 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10311 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10319 const o = self.ng.object;10312 const o = self.ng.object;
10320 const zcu = o.pt.zcu;10313 const pt = self.ng.pt;
10314 const zcu = pt.zcu;
10321 const ip = &zcu.intern_pool;10315 const ip = &zcu.intern_pool;
10322 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;10316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
10323 const operand = try self.resolveInst(ty_op.operand);10317 const operand = try self.resolveInst(ty_op.operand);
...@@ -10332,7 +10326,7 @@ pub const FuncGen = struct {...@@ -10332,7 +10326,7 @@ pub const FuncGen = struct {
1033210326
10333 for (0..names.len) |name_index| {10327 for (0..names.len) |name_index| {
10334 const err_int = ip.getErrorValueIfExists(names.get(ip)[name_index]).?;10328 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);
10336 try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip);10330 try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip);
10337 }10331 }
10338 self.wip.cursor = .{ .block = valid_block };10332 self.wip.cursor = .{ .block = valid_block };
...@@ -10367,7 +10361,7 @@ pub const FuncGen = struct {...@@ -10367,7 +10361,7 @@ pub const FuncGen = struct {
1036710361
10368 fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !Builder.Function.Index {10362 fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !Builder.Function.Index {
10369 const o = self.ng.object;10363 const o = self.ng.object;
10370 const pt = o.pt;10364 const pt = self.ng.pt;
10371 const zcu = pt.zcu;10365 const zcu = pt.zcu;
10372 const ip = &zcu.intern_pool;10366 const ip = &zcu.intern_pool;
10373 const enum_type = ip.loadEnumType(enum_ty.toIntern());10367 const enum_type = ip.loadEnumType(enum_ty.toIntern());
...@@ -10379,7 +10373,7 @@ pub const FuncGen = struct {...@@ -10379,7 +10373,7 @@ pub const FuncGen = struct {
1037910373
10380 const target = &zcu.root_mod.resolved_target.result;10374 const target = &zcu.root_mod.resolved_target.result;
10381 const function_index = try o.builder.addFunction(10375 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),
10383 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_type.name.fmt(ip)}),10377 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_type.name.fmt(ip)}),
10384 toLlvmAddressSpace(.generic, target),10378 toLlvmAddressSpace(.generic, target),
10385 );10379 );
...@@ -10408,6 +10402,7 @@ pub const FuncGen = struct {...@@ -10408,6 +10402,7 @@ pub const FuncGen = struct {
1040810402
10409 for (0..enum_type.names.len) |field_index| {10403 for (0..enum_type.names.len) |field_index| {
10410 const this_tag_int_value = try o.lowerValue(10404 const this_tag_int_value = try o.lowerValue(
10405 pt,
10411 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),10406 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),
10412 );10407 );
10413 try wip_switch.addCase(this_tag_int_value, named_block, &wip);10408 try wip_switch.addCase(this_tag_int_value, named_block, &wip);
...@@ -10424,11 +10419,12 @@ pub const FuncGen = struct {...@@ -10424,11 +10419,12 @@ pub const FuncGen = struct {
1042410419
10425 fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10420 fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10426 const o = self.ng.object;10421 const o = self.ng.object;
10422 const pt = self.ng.pt;
10427 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;10423 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
10428 const operand = try self.resolveInst(un_op);10424 const operand = try self.resolveInst(un_op);
10429 const enum_ty = self.typeOf(un_op);10425 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);
10432 return self.wip.call(10428 return self.wip.call(
10433 .normal,10429 .normal,
10434 .fastcc,10430 .fastcc,
...@@ -10442,10 +10438,11 @@ pub const FuncGen = struct {...@@ -10442,10 +10438,11 @@ pub const FuncGen = struct {
1044210438
10443 fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10439 fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10444 const o = self.ng.object;10440 const o = self.ng.object;
10441 const pt = self.ng.pt;
10445 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;10442 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
10446 const operand = try self.resolveInst(un_op);10443 const operand = try self.resolveInst(un_op);
10447 const slice_ty = self.typeOfIndex(inst);10444 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
10450 const error_name_table_ptr = try self.getErrorNameTable();10447 const error_name_table_ptr = try self.getErrorNameTable();
10451 const error_name_table =10448 const error_name_table =
...@@ -10457,10 +10454,11 @@ pub const FuncGen = struct {...@@ -10457,10 +10454,11 @@ pub const FuncGen = struct {
1045710454
10458 fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10455 fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10459 const o = self.ng.object;10456 const o = self.ng.object;
10457 const pt = self.ng.pt;
10460 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;10458 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
10461 const scalar = try self.resolveInst(ty_op.operand);10459 const scalar = try self.resolveInst(ty_op.operand);
10462 const vector_ty = self.typeOfIndex(inst);10460 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, "");
10464 }10462 }
1046510463
10466 fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10464 fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
...@@ -10475,7 +10473,7 @@ pub const FuncGen = struct {...@@ -10475,7 +10473,7 @@ pub const FuncGen = struct {
1047510473
10476 fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10474 fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10477 const o = fg.ng.object;10475 const o = fg.ng.object;
10478 const pt = o.pt;10476 const pt = fg.ng.pt;
10479 const zcu = pt.zcu;10477 const zcu = pt.zcu;
10480 const gpa = zcu.gpa;10478 const gpa = zcu.gpa;
1048110479
...@@ -10484,9 +10482,9 @@ pub const FuncGen = struct {...@@ -10484,9 +10482,9 @@ pub const FuncGen = struct {
10484 const operand = try fg.resolveInst(unwrapped.operand);10482 const operand = try fg.resolveInst(unwrapped.operand);
10485 const mask = unwrapped.mask;10483 const mask = unwrapped.mask;
10486 const operand_ty = fg.typeOf(unwrapped.operand);10484 const operand_ty = fg.typeOf(unwrapped.operand);
10487 const llvm_operand_ty = try o.lowerType(operand_ty);10485 const llvm_operand_ty = try o.lowerType(pt, operand_ty);
10488 const llvm_result_ty = try o.lowerType(unwrapped.result_ty);10486 const llvm_result_ty = try o.lowerType(pt, unwrapped.result_ty);
10489 const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu));10487 const llvm_elem_ty = try o.lowerType(pt, unwrapped.result_ty.childType(zcu));
10490 const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty);10488 const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty);
10491 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);10489 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);
10492 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);10490 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);
...@@ -10516,7 +10514,7 @@ pub const FuncGen = struct {...@@ -10516,7 +10514,7 @@ pub const FuncGen = struct {
10516 .elem => llvm_poison_elem,10514 .elem => llvm_poison_elem,
10517 .value => |val| if (!Value.fromInterned(val).isUndef(zcu)) elem: {10515 .value => |val| if (!Value.fromInterned(val).isUndef(zcu)) elem: {
10518 any_defined_comptime_value = true;10516 any_defined_comptime_value = true;
10519 break :elem try o.lowerValue(val);10517 break :elem try o.lowerValue(pt, val);
10520 } else llvm_poison_elem,10518 } else llvm_poison_elem,
10521 };10519 };
10522 }10520 }
...@@ -10582,14 +10580,14 @@ pub const FuncGen = struct {...@@ -10582,14 +10580,14 @@ pub const FuncGen = struct {
1058210580
10583 fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10581 fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10584 const o = fg.ng.object;10582 const o = fg.ng.object;
10585 const pt = o.pt;10583 const pt = fg.ng.pt;
10586 const zcu = pt.zcu;10584 const zcu = pt.zcu;
10587 const gpa = zcu.gpa;10585 const gpa = zcu.gpa;
1058810586
10589 const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst);10587 const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst);
1059010588
10591 const mask = unwrapped.mask;10589 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));
10593 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);10591 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);
10594 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);10592 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);
1059510593
...@@ -10681,7 +10679,8 @@ pub const FuncGen = struct {...@@ -10681,7 +10679,8 @@ pub const FuncGen = struct {
10681 accum_init: Builder.Value,10679 accum_init: Builder.Value,
10682 ) !Builder.Value {10680 ) !Builder.Value {
10683 const o = self.ng.object;10681 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);
10685 const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len);10684 const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len);
10686 const llvm_result_ty = accum_init.typeOfWip(&self.wip);10685 const llvm_result_ty = accum_init.typeOfWip(&self.wip);
1068710686
...@@ -10735,15 +10734,16 @@ pub const FuncGen = struct {...@@ -10735,15 +10734,16 @@ pub const FuncGen = struct {
1073510734
10736 fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {10735 fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
10737 const o = self.ng.object;10736 const o = self.ng.object;
10738 const zcu = o.pt.zcu;10737 const pt = self.ng.pt;
10738 const zcu = pt.zcu;
10739 const target = zcu.getTarget();10739 const target = zcu.getTarget();
1074010740
10741 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;10741 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
10742 const operand = try self.resolveInst(reduce.operand);10742 const operand = try self.resolveInst(reduce.operand);
10743 const operand_ty = self.typeOf(reduce.operand);10743 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);
10745 const scalar_ty = self.typeOfIndex(inst);10745 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
10748 switch (reduce.operation) {10748 switch (reduce.operation) {
10749 .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {10749 .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
...@@ -10845,14 +10845,14 @@ pub const FuncGen = struct {...@@ -10845,14 +10845,14 @@ pub const FuncGen = struct {
1084510845
10846 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10846 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10847 const o = self.ng.object;10847 const o = self.ng.object;
10848 const pt = o.pt;10848 const pt = self.ng.pt;
10849 const zcu = pt.zcu;10849 const zcu = pt.zcu;
10850 const ip = &zcu.intern_pool;10850 const ip = &zcu.intern_pool;
10851 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;10851 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
10852 const result_ty = self.typeOfIndex(inst);10852 const result_ty = self.typeOfIndex(inst);
10853 const len: usize = @intCast(result_ty.arrayLen(zcu));10853 const len: usize = @intCast(result_ty.arrayLen(zcu));
10854 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[ty_pl.payload..][0..len]);10854 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
10857 switch (result_ty.zigTypeTag(zcu)) {10857 switch (result_ty.zigTypeTag(zcu)) {
10858 .vector => {10858 .vector => {
...@@ -10933,7 +10933,7 @@ pub const FuncGen = struct {...@@ -10933,7 +10933,7 @@ pub const FuncGen = struct {
10933 .array => {10933 .array => {
10934 assert(isByRef(result_ty, zcu));10934 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);
10937 const usize_zero = try o.builder.intValue(llvm_usize, 0);10937 const usize_zero = try o.builder.intValue(llvm_usize, 0);
10938 const alignment = result_ty.abiAlignment(zcu).toLlvm();10938 const alignment = result_ty.abiAlignment(zcu).toLlvm();
10939 const alloca_inst = try self.buildAlloca(llvm_result_ty, alignment);10939 const alloca_inst = try self.buildAlloca(llvm_result_ty, alignment);
...@@ -10966,13 +10966,13 @@ pub const FuncGen = struct {...@@ -10966,13 +10966,13 @@ pub const FuncGen = struct {
1096610966
10967 fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10967 fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10968 const o = self.ng.object;10968 const o = self.ng.object;
10969 const pt = o.pt;10969 const pt = self.ng.pt;
10970 const zcu = pt.zcu;10970 const zcu = pt.zcu;
10971 const ip = &zcu.intern_pool;10971 const ip = &zcu.intern_pool;
10972 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;10972 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
10973 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;10973 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
10974 const union_ty = self.typeOfIndex(inst);10974 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);
10976 const layout = union_ty.unionGetLayout(zcu);10976 const layout = union_ty.unionGetLayout(zcu);
10977 const union_obj = zcu.typeToUnion(union_ty).?;10977 const union_obj = zcu.typeToUnion(union_ty).?;
1097810978
...@@ -11014,10 +11014,10 @@ pub const FuncGen = struct {...@@ -11014,10 +11014,10 @@ pub const FuncGen = struct {
11014 const result_ptr = try self.buildAlloca(union_llvm_ty, alignment);11014 const result_ptr = try self.buildAlloca(union_llvm_ty, alignment);
11015 const llvm_payload = try self.resolveInst(extra.init);11015 const llvm_payload = try self.resolveInst(extra.init);
11016 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);11016 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);
11018 const field_size = field_ty.abiSize(zcu);11018 const field_size = field_ty.abiSize(zcu);
11019 const field_align = union_ty.fieldAlignment(extra.field_index, zcu);11019 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);
11021 const usize_zero = try o.builder.intValue(llvm_usize, 0);11021 const usize_zero = try o.builder.intValue(llvm_usize, 0);
1102211022
11023 const llvm_union_ty = t: {11023 const llvm_union_ty = t: {
...@@ -11035,7 +11035,7 @@ pub const FuncGen = struct {...@@ -11035,7 +11035,7 @@ pub const FuncGen = struct {
11035 });11035 });
11036 };11036 };
11037 if (layout.tag_size == 0) break :t try o.builder.structType(.normal, &.{payload_ty});11037 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));
11039 var fields: [3]Builder.Type = undefined;11039 var fields: [3]Builder.Type = undefined;
11040 var fields_len: usize = 2;11040 var fields_len: usize = 2;
11041 if (layout.tag_align.compare(.gte, layout.payload_align)) {11041 if (layout.tag_align.compare(.gte, layout.payload_align)) {
...@@ -11076,7 +11076,7 @@ pub const FuncGen = struct {...@@ -11076,7 +11076,7 @@ pub const FuncGen = struct {
11076 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));11076 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
11077 const indices: [2]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, tag_index) };11077 const indices: [2]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, tag_index) };
11078 const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, "");11078 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));
11080 var big_int_space: Value.BigIntSpace = undefined;11080 var big_int_space: Value.BigIntSpace = undefined;
11081 const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu);11081 const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu);
11082 const llvm_tag = try o.builder.bigIntValue(tag_ty, tag_big_int);11082 const llvm_tag = try o.builder.bigIntValue(tag_ty, tag_big_int);
...@@ -11106,7 +11106,7 @@ pub const FuncGen = struct {...@@ -11106,7 +11106,7 @@ pub const FuncGen = struct {
11106 // by the target.11106 // by the target.
11107 // To work around this, don't emit llvm.prefetch in this case.11107 // To work around this, don't emit llvm.prefetch in this case.
11108 // See https://bugs.llvm.org/show_bug.cgi?id=2103711108 // See https://bugs.llvm.org/show_bug.cgi?id=21037
11109 const zcu = o.pt.zcu;11109 const zcu = self.ng.pt.zcu;
11110 const target = zcu.getTarget();11110 const target = zcu.getTarget();
11111 switch (prefetch.cache) {11111 switch (prefetch.cache) {
11112 .instruction => switch (target.cpu.arch) {11112 .instruction => switch (target.cpu.arch) {
...@@ -11139,11 +11139,12 @@ pub const FuncGen = struct {...@@ -11139,11 +11139,12 @@ pub const FuncGen = struct {
1113911139
11140 fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {11140 fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
11141 const o = self.ng.object;11141 const o = self.ng.object;
11142 const pt = self.ng.pt;
11142 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;11143 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
11143 const inst_ty = self.typeOfIndex(inst);11144 const inst_ty = self.typeOfIndex(inst);
11144 const operand = try self.resolveInst(ty_op.operand);11145 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), "");
11147 }11148 }
1114811149
11149 fn workIntrinsic(11150 fn workIntrinsic(
...@@ -11161,8 +11162,7 @@ pub const FuncGen = struct {...@@ -11161,8 +11162,7 @@ pub const FuncGen = struct {
11161 }11162 }
1116211163
11163 fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {11164 fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
11164 const o = self.ng.object;11165 const target = self.ng.pt.zcu.getTarget();
11165 const target = o.pt.zcu.getTarget();
1116611166
11167 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;11167 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
11168 const dimension = pl_op.payload;11168 const dimension = pl_op.payload;
...@@ -11176,7 +11176,8 @@ pub const FuncGen = struct {...@@ -11176,7 +11176,8 @@ pub const FuncGen = struct {
1117611176
11177 fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {11177 fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
11178 const o = self.ng.object;11178 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
11181 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;11182 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
11182 const dimension = pl_op.payload;11183 const dimension = pl_op.payload;
...@@ -11193,7 +11194,7 @@ pub const FuncGen = struct {...@@ -11193,7 +11194,7 @@ pub const FuncGen = struct {
11193 // Load the work_group_* member from the struct as u16.11194 // Load the work_group_* member from the struct as u16.
11194 // Just treat the dispatch pointer as an array of u16 to keep things simple.11195 // Just treat the dispatch pointer as an array of u16 to keep things simple.
11195 const workgroup_size_ptr = try self.wip.gep(.inbounds, .i16, dispatch_ptr, &.{11196 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),
11197 }, "");11198 }, "");
11198 const workgroup_size_alignment = comptime Builder.Alignment.fromByteUnits(2);11199 const workgroup_size_alignment = comptime Builder.Alignment.fromByteUnits(2);
11199 return self.wip.load(.normal, .i16, workgroup_size_ptr, workgroup_size_alignment, "");11200 return self.wip.load(.normal, .i16, workgroup_size_ptr, workgroup_size_alignment, "");
...@@ -11206,8 +11207,7 @@ pub const FuncGen = struct {...@@ -11206,8 +11207,7 @@ pub const FuncGen = struct {
11206 }11207 }
1120711208
11208 fn airWorkGroupId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {11209 fn airWorkGroupId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
11209 const o = self.ng.object;11210 const target = self.ng.pt.zcu.getTarget();
11210 const target = o.pt.zcu.getTarget();
1121111211
11212 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;11212 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
11213 const dimension = pl_op.payload;11213 const dimension = pl_op.payload;
...@@ -11221,7 +11221,7 @@ pub const FuncGen = struct {...@@ -11221,7 +11221,7 @@ pub const FuncGen = struct {
1122111221
11222 fn getErrorNameTable(self: *FuncGen) Allocator.Error!Builder.Variable.Index {11222 fn getErrorNameTable(self: *FuncGen) Allocator.Error!Builder.Variable.Index {
11223 const o = self.ng.object;11223 const o = self.ng.object;
11224 const pt = o.pt;11224 const pt = self.ng.pt;
1122511225
11226 const table = o.error_name_table;11226 const table = o.error_name_table;
11227 if (table != .none) return table;11227 if (table != .none) return table;
...@@ -11271,8 +11271,7 @@ pub const FuncGen = struct {...@@ -11271,8 +11271,7 @@ pub const FuncGen = struct {
11271 opt_ty: Type,11271 opt_ty: Type,
11272 can_elide_load: bool,11272 can_elide_load: bool,
11273 ) !Builder.Value {11273 ) !Builder.Value {
11274 const o = fg.ng.object;11274 const pt = fg.ng.pt;
11275 const pt = o.pt;
11276 const zcu = pt.zcu;11275 const zcu = pt.zcu;
11277 const payload_ty = opt_ty.optionalChild(zcu);11276 const payload_ty = opt_ty.optionalChild(zcu);
1127811277
...@@ -11301,9 +11300,9 @@ pub const FuncGen = struct {...@@ -11301,9 +11300,9 @@ pub const FuncGen = struct {
11301 non_null_bit: Builder.Value,11300 non_null_bit: Builder.Value,
11302 ) !Builder.Value {11301 ) !Builder.Value {
11303 const o = self.ng.object;11302 const o = self.ng.object;
11304 const pt = o.pt;11303 const pt = self.ng.pt;
11305 const zcu = pt.zcu;11304 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);
11307 const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, "");11306 const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, "");
1130811307
11309 if (isByRef(optional_ty, zcu)) {11308 if (isByRef(optional_ty, zcu)) {
...@@ -11334,7 +11333,7 @@ pub const FuncGen = struct {...@@ -11334,7 +11333,7 @@ pub const FuncGen = struct {
11334 field_index: u32,11333 field_index: u32,
11335 ) !Builder.Value {11334 ) !Builder.Value {
11336 const o = self.ng.object;11335 const o = self.ng.object;
11337 const pt = o.pt;11336 const pt = self.ng.pt;
11338 const zcu = pt.zcu;11337 const zcu = pt.zcu;
11339 const struct_ty = struct_ptr_ty.childType(zcu);11338 const struct_ty = struct_ptr_ty.childType(zcu);
11340 switch (struct_ty.zigTypeTag(zcu)) {11339 switch (struct_ty.zigTypeTag(zcu)) {
...@@ -11357,12 +11356,12 @@ pub const FuncGen = struct {...@@ -11357,12 +11356,12 @@ pub const FuncGen = struct {
11357 // Offset our operand pointer by the correct number of bytes.11356 // Offset our operand pointer by the correct number of bytes.
11358 const byte_offset = @divExact(pt.structPackedFieldBitOffset(struct_type, field_index) + struct_ptr_ty_info.packed_offset.bit_offset, 8);11357 const byte_offset = @divExact(pt.structPackedFieldBitOffset(struct_type, field_index) + struct_ptr_ty_info.packed_offset.bit_offset, 8);
11359 if (byte_offset == 0) return struct_ptr;11358 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);
11361 const llvm_index = try o.builder.intValue(usize_ty, byte_offset);11360 const llvm_index = try o.builder.intValue(usize_ty, byte_offset);
11362 return self.wip.gep(.inbounds, .i8, struct_ptr, &.{llvm_index}, "");11361 return self.wip.gep(.inbounds, .i8, struct_ptr, &.{llvm_index}, "");
11363 },11362 },
11364 else => {11363 else => {
11365 const struct_llvm_ty = try o.lowerPtrElemTy(struct_ty);11364 const struct_llvm_ty = try o.lowerPtrElemTy(pt, struct_ty);
1136611365
11367 if (o.llvmFieldIndex(struct_ty, field_index)) |llvm_field_index| {11366 if (o.llvmFieldIndex(struct_ty, field_index)) |llvm_field_index| {
11368 return self.wip.gepStruct(struct_llvm_ty, struct_ptr, llvm_field_index, "");11367 return self.wip.gepStruct(struct_llvm_ty, struct_ptr, llvm_field_index, "");
...@@ -11372,7 +11371,7 @@ pub const FuncGen = struct {...@@ -11372,7 +11371,7 @@ pub const FuncGen = struct {
11372 // the index to the element at index `1` to get a pointer to the end of11371 // the index to the element at index `1` to get a pointer to the end of
11373 // the struct.11372 // the struct.
11374 const llvm_index = try o.builder.intValue(11373 const llvm_index = try o.builder.intValue(
11375 try o.lowerType(Type.usize),11374 try o.lowerType(pt, Type.usize),
11376 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)),11375 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)),
11377 );11376 );
11378 return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, "");11377 return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, "");
...@@ -11383,7 +11382,7 @@ pub const FuncGen = struct {...@@ -11383,7 +11382,7 @@ pub const FuncGen = struct {
11383 const layout = struct_ty.unionGetLayout(zcu);11382 const layout = struct_ty.unionGetLayout(zcu);
11384 if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr;11383 if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr;
11385 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));11384 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);
11387 return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, "");11386 return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, "");
11388 },11387 },
11389 else => unreachable,11388 else => unreachable,
...@@ -11403,9 +11402,9 @@ pub const FuncGen = struct {...@@ -11403,9 +11402,9 @@ pub const FuncGen = struct {
11403 // => so load the byte aligned value and trunc the unwanted bits.11402 // => so load the byte aligned value and trunc the unwanted bits.
1140411403
11405 const o = fg.ng.object;11404 const o = fg.ng.object;
11406 const pt = o.pt;11405 const pt = fg.ng.pt;
11407 const zcu = pt.zcu;11406 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);
11409 const abi_size = payload_ty.abiSize(zcu);11408 const abi_size = payload_ty.abiSize(zcu);
1141011409
11411 // llvm bug workarounds:11410 // llvm bug workarounds:
...@@ -11450,8 +11449,8 @@ pub const FuncGen = struct {...@@ -11450,8 +11449,8 @@ pub const FuncGen = struct {
11450 access_kind: Builder.MemoryAccessKind,11449 access_kind: Builder.MemoryAccessKind,
11451 ) !Builder.Value {11450 ) !Builder.Value {
11452 const o = fg.ng.object;11451 const o = fg.ng.object;
11453 const pt = o.pt;11452 const pt = fg.ng.pt;
11454 const pointee_llvm_ty = try o.lowerType(pointee_type);11453 const pointee_llvm_ty = try o.lowerType(pt, pointee_type);
11455 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment)11454 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment)
11456 .max(pointee_type.abiAlignment(pt.zcu)).toLlvm();11455 .max(pointee_type.abiAlignment(pt.zcu)).toLlvm();
11457 const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align);11456 const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align);
...@@ -11461,7 +11460,7 @@ pub const FuncGen = struct {...@@ -11461,7 +11460,7 @@ pub const FuncGen = struct {
11461 result_align,11460 result_align,
11462 ptr,11461 ptr,
11463 ptr_alignment,11462 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),
11465 access_kind,11464 access_kind,
11466 fg.disable_intrinsics,11465 fg.disable_intrinsics,
11467 );11466 );
...@@ -11473,7 +11472,7 @@ pub const FuncGen = struct {...@@ -11473,7 +11472,7 @@ pub const FuncGen = struct {
11473 /// For isByRef=false types, it creates a load instruction and returns it.11472 /// For isByRef=false types, it creates a load instruction and returns it.
11474 fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value {11473 fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value {
11475 const o = self.ng.object;11474 const o = self.ng.object;
11476 const pt = o.pt;11475 const pt = self.ng.pt;
11477 const zcu = pt.zcu;11476 const zcu = pt.zcu;
11478 const info = ptr_ty.ptrInfo(zcu);11477 const info = ptr_ty.ptrInfo(zcu);
11479 const elem_ty = Type.fromInterned(info.child);11478 const elem_ty = Type.fromInterned(info.child);
...@@ -11490,7 +11489,7 @@ pub const FuncGen = struct {...@@ -11490,7 +11489,7 @@ pub const FuncGen = struct {
11490 assert(info.flags.vector_index != .runtime);11489 assert(info.flags.vector_index != .runtime);
11491 if (info.flags.vector_index != .none) {11490 if (info.flags.vector_index != .none) {
11492 const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index);11491 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);
11494 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);11493 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);
1149511494
11496 const loaded_vector = try self.wip.load(access_kind, vec_ty, ptr, ptr_alignment, "");11495 const loaded_vector = try self.wip.load(access_kind, vec_ty, ptr, ptr_alignment, "");
...@@ -11511,7 +11510,7 @@ pub const FuncGen = struct {...@@ -11511,7 +11510,7 @@ pub const FuncGen = struct {
11511 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);11510 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);
11512 const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset);11511 const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset);
11513 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");11512 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
11516 if (isByRef(elem_ty, zcu)) {11515 if (isByRef(elem_ty, zcu)) {
11517 const result_align = elem_ty.abiAlignment(zcu).toLlvm();11516 const result_align = elem_ty.abiAlignment(zcu).toLlvm();
...@@ -11546,7 +11545,7 @@ pub const FuncGen = struct {...@@ -11546,7 +11545,7 @@ pub const FuncGen = struct {
11546 ordering: Builder.AtomicOrdering,11545 ordering: Builder.AtomicOrdering,
11547 ) !void {11546 ) !void {
11548 const o = self.ng.object;11547 const o = self.ng.object;
11549 const pt = o.pt;11548 const pt = self.ng.pt;
11550 const zcu = pt.zcu;11549 const zcu = pt.zcu;
11551 const info = ptr_ty.ptrInfo(zcu);11550 const info = ptr_ty.ptrInfo(zcu);
11552 const elem_ty = Type.fromInterned(info.child);11551 const elem_ty = Type.fromInterned(info.child);
...@@ -11560,7 +11559,7 @@ pub const FuncGen = struct {...@@ -11560,7 +11559,7 @@ pub const FuncGen = struct {
11560 assert(info.flags.vector_index != .runtime);11559 assert(info.flags.vector_index != .runtime);
11561 if (info.flags.vector_index != .none) {11560 if (info.flags.vector_index != .none) {
11562 const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index);11561 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);
11564 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);11563 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);
1156511564
11566 const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, "");11565 const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, "");
...@@ -11629,7 +11628,7 @@ pub const FuncGen = struct {...@@ -11629,7 +11628,7 @@ pub const FuncGen = struct {
11629 ptr_alignment,11628 ptr_alignment,
11630 elem,11629 elem,
11631 elem_ty.abiAlignment(zcu).toLlvm(),11630 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)),
11633 access_kind,11632 access_kind,
11634 self.disable_intrinsics,11633 self.disable_intrinsics,
11635 );11634 );
...@@ -11638,7 +11637,8 @@ pub const FuncGen = struct {...@@ -11638,7 +11637,8 @@ pub const FuncGen = struct {
11638 fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void {11637 fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void {
11639 const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545;11638 const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545;
11640 const o = fg.ng.object;11639 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);
11642 const zero = try o.builder.intValue(usize_ty, 0);11642 const zero = try o.builder.intValue(usize_ty, 0);
11643 const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED);11643 const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED);
11644 const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, "");11644 const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, "");
...@@ -11656,12 +11656,12 @@ pub const FuncGen = struct {...@@ -11656,12 +11656,12 @@ pub const FuncGen = struct {
11656 a5: Builder.Value,11656 a5: Builder.Value,
11657 ) Allocator.Error!Builder.Value {11657 ) Allocator.Error!Builder.Value {
11658 const o = fg.ng.object;11658 const o = fg.ng.object;
11659 const pt = o.pt;11659 const pt = fg.ng.pt;
11660 const zcu = pt.zcu;11660 const zcu = pt.zcu;
11661 const target = zcu.getTarget();11661 const target = zcu.getTarget();
11662 if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value;11662 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);
11665 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();11665 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();
1166611666
11667 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);11667 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);
...@@ -11787,14 +11787,12 @@ pub const FuncGen = struct {...@@ -11787,14 +11787,12 @@ pub const FuncGen = struct {
11787 }11787 }
1178811788
11789 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {11789 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {
11790 const o = fg.ng.object;11790 const zcu = fg.ng.pt.zcu;
11791 const zcu = o.pt.zcu;
11792 return fg.air.typeOf(inst, &zcu.intern_pool);11791 return fg.air.typeOf(inst, &zcu.intern_pool);
11793 }11792 }
1179411793
11795 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {11794 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {
11796 const o = fg.ng.object;11795 const zcu = fg.ng.pt.zcu;
11797 const zcu = o.pt.zcu;
11798 return fg.air.typeOfIndex(inst, &zcu.intern_pool);11796 return fg.air.typeOfIndex(inst, &zcu.intern_pool);
11799 }11797 }
11800};11798};
...@@ -12152,40 +12150,39 @@ fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: *const std.Target) bool {...@@ -12152,40 +12150,39 @@ fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: *const std.Target) bool {
12152/// In order to support the C calling convention, some return types need to be lowered12150/// In order to support the C calling convention, some return types need to be lowered
12153/// completely differently in the function prototype to honor the C ABI, and then12151/// completely differently in the function prototype to honor the C ABI, and then
12154/// be effectively bitcasted to the actual return type.12152/// be effectively bitcasted to the actual return type.
12155fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {12153fn lowerFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12156 const pt = o.pt;
12157 const zcu = pt.zcu;12154 const zcu = pt.zcu;
12158 const return_type = Type.fromInterned(fn_info.return_type);12155 const return_type = Type.fromInterned(fn_info.return_type);
12159 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {12156 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
12160 // If the return type is an error set or an error union, then we make this12157 // If the return type is an error set or an error union, then we make this
12161 // anyerror return type instead, so that it can be coerced into a function12158 // anyerror return type instead, so that it can be coerced into a function
12162 // pointer type which has anyerror as the return type.12159 // 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;
12164 }12161 }
12165 const target = zcu.getTarget();12162 const target = zcu.getTarget();
12166 switch (fn_info.cc) {12163 switch (fn_info.cc) {
12167 .@"inline" => unreachable,12164 .@"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),12167 .x86_64_sysv => return lowerSystemVFnRetTy(o, pt, fn_info),
12171 .x86_64_win => return lowerWin64FnRetTy(o, fn_info),12168 .x86_64_win => return lowerWin64FnRetTy(o, pt, fn_info),
12172 .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(return_type) else .void,12169 .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(pt, return_type) else .void,
12173 .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(return_type),12170 .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(pt, return_type),
12174 .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win => switch (aarch64_c_abi.classifyType(return_type, zcu)) {12171 .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win => switch (aarch64_c_abi.classifyType(return_type, zcu)) {
12175 .memory => return .void,12172 .memory => return .void,
12176 .float_array => return o.lowerType(return_type),12173 .float_array => return o.lowerType(pt, return_type),
12177 .byval => return o.lowerType(return_type),12174 .byval => return o.lowerType(pt, return_type),
12178 .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))),12175 .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))),
12179 .double_integer => return o.builder.arrayType(2, .i64),12176 .double_integer => return o.builder.arrayType(2, .i64),
12180 },12177 },
12181 .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {12178 .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
12182 .memory, .i64_array => return .void,12179 .memory, .i64_array => return .void,
12183 .i32_array => |len| return if (len == 1) .i32 else .void,12180 .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),
12185 },12182 },
12186 .mips_o32 => switch (mips_c_abi.classifyType(return_type, zcu, .ret)) {12183 .mips_o32 => switch (mips_c_abi.classifyType(return_type, zcu, .ret)) {
12187 .memory, .i32_array => return .void,12184 .memory, .i32_array => return .void,
12188 .byval => return o.lowerType(return_type),12185 .byval => return o.lowerType(pt, return_type),
12189 },12186 },
12190 .riscv64_lp64, .riscv32_ilp32 => switch (riscv_c_abi.classifyType(return_type, zcu)) {12187 .riscv64_lp64, .riscv32_ilp32 => switch (riscv_c_abi.classifyType(return_type, zcu)) {
12191 .memory => return .void,12188 .memory => return .void,
...@@ -12195,53 +12192,52 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu...@@ -12195,53 +12192,52 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
12195 .double_integer => {12192 .double_integer => {
12196 return o.builder.structType(.normal, &.{ .i64, .i64 });12193 return o.builder.structType(.normal, &.{ .i64, .i64 });
12197 },12194 },
12198 .byval => return o.lowerType(return_type),12195 .byval => return o.lowerType(pt, return_type),
12199 .fields => {12196 .fields => {
12200 var types_len: usize = 0;12197 var types_len: usize = 0;
12201 var types: [8]Builder.Type = undefined;12198 var types: [8]Builder.Type = undefined;
12202 for (0..return_type.structFieldCount(zcu)) |field_index| {12199 for (0..return_type.structFieldCount(zcu)) |field_index| {
12203 const field_ty = return_type.fieldType(field_index, zcu);12200 const field_ty = return_type.fieldType(field_index, zcu);
12204 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;12201 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);
12206 types_len += 1;12203 types_len += 1;
12207 }12204 }
12208 return o.builder.structType(.normal, types[0..types_len]);12205 return o.builder.structType(.normal, types[0..types_len]);
12209 },12206 },
12210 },12207 },
12211 .wasm_mvp => switch (wasm_c_abi.classifyType(return_type, zcu)) {12208 .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),
12213 .indirect => return .void,12210 .indirect => return .void,
12214 },12211 },
12215 // TODO investigate other callconvs12212 // TODO investigate other callconvs
12216 else => return o.lowerType(return_type),12213 else => return o.lowerType(pt, return_type),
12217 }12214 }
12218}12215}
1221912216
12220fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {12217fn lowerWin64FnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12221 const zcu = o.pt.zcu;12218 const zcu = pt.zcu;
12222 const return_type = Type.fromInterned(fn_info.return_type);12219 const return_type = Type.fromInterned(fn_info.return_type);
12223 switch (x86_64_abi.classifyWindows(return_type, zcu, zcu.getTarget())) {12220 switch (x86_64_abi.classifyWindows(return_type, zcu, zcu.getTarget())) {
12224 .integer => {12221 .integer => {
12225 if (isScalar(zcu, return_type)) {12222 if (isScalar(zcu, return_type)) {
12226 return o.lowerType(return_type);12223 return o.lowerType(pt, return_type);
12227 } else {12224 } else {
12228 return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8));12225 return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8));
12229 }12226 }
12230 },12227 },
12231 .win_i128 => return o.builder.vectorType(.normal, 2, .i64),12228 .win_i128 => return o.builder.vectorType(.normal, 2, .i64),
12232 .memory => return .void,12229 .memory => return .void,
12233 .sse => return o.lowerType(return_type),12230 .sse => return o.lowerType(pt, return_type),
12234 else => unreachable,12231 else => unreachable,
12235 }12232 }
12236}12233}
1223712234
12238fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {12235fn lowerSystemVFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
12239 const pt = o.pt;
12240 const zcu = pt.zcu;12236 const zcu = pt.zcu;
12241 const ip = &zcu.intern_pool;12237 const ip = &zcu.intern_pool;
12242 const return_type = Type.fromInterned(fn_info.return_type);12238 const return_type = Type.fromInterned(fn_info.return_type);
12243 if (isScalar(zcu, return_type)) {12239 if (isScalar(zcu, return_type)) {
12244 return o.lowerType(return_type);12240 return o.lowerType(pt, return_type);
12245 }12241 }
12246 const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret);12242 const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret);
12247 var types_index: u32 = 0;12243 var types_index: u32 = 0;
...@@ -12305,6 +12301,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E...@@ -12305,6 +12301,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
1230512301
12306const ParamTypeIterator = struct {12302const ParamTypeIterator = struct {
12307 object: *Object,12303 object: *Object,
12304 pt: Zcu.PerThread,
12308 fn_info: InternPool.Key.FuncType,12305 fn_info: InternPool.Key.FuncType,
12309 zig_index: u32,12306 zig_index: u32,
12310 llvm_index: u32,12307 llvm_index: u32,
...@@ -12327,7 +12324,7 @@ const ParamTypeIterator = struct {...@@ -12327,7 +12324,7 @@ const ParamTypeIterator = struct {
1232712324
12328 pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering {12325 pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering {
12329 if (it.zig_index >= it.fn_info.param_types.len) return null;12326 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;
12331 const ty = it.fn_info.param_types.get(ip)[it.zig_index];12328 const ty = it.fn_info.param_types.get(ip)[it.zig_index];
12332 it.byval_attr = false;12329 it.byval_attr = false;
12333 return nextInner(it, Type.fromInterned(ty));12330 return nextInner(it, Type.fromInterned(ty));
...@@ -12335,7 +12332,8 @@ const ParamTypeIterator = struct {...@@ -12335,7 +12332,8 @@ const ParamTypeIterator = struct {
1233512332
12336 /// `airCall` uses this instead of `next` so that it can take into account variadic functions.12333 /// `airCall` uses this instead of `next` so that it can take into account variadic functions.
12337 pub fn nextCall(it: *ParamTypeIterator, fg: *FuncGen, args: []const Air.Inst.Ref) Allocator.Error!?Lowering {12334 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;
12339 if (it.zig_index >= it.fn_info.param_types.len) {12337 if (it.zig_index >= it.fn_info.param_types.len) {
12340 if (it.zig_index >= args.len) {12338 if (it.zig_index >= args.len) {
12341 return null;12339 return null;
...@@ -12348,7 +12346,7 @@ const ParamTypeIterator = struct {...@@ -12348,7 +12346,7 @@ const ParamTypeIterator = struct {
12348 }12346 }
1234912347
12350 fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {12348 fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
12351 const pt = it.object.pt;12349 const pt = it.pt;
12352 const zcu = pt.zcu;12350 const zcu = pt.zcu;
12353 const target = zcu.getTarget();12351 const target = zcu.getTarget();
1235412352
...@@ -12448,7 +12446,7 @@ const ParamTypeIterator = struct {...@@ -12448,7 +12446,7 @@ const ParamTypeIterator = struct {
12448 for (0..ty.structFieldCount(zcu)) |field_index| {12446 for (0..ty.structFieldCount(zcu)) |field_index| {
12449 const field_ty = ty.fieldType(field_index, zcu);12447 const field_ty = ty.fieldType(field_index, zcu);
12450 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;12448 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);
12452 it.types_len += 1;12450 it.types_len += 1;
12453 }12451 }
12454 it.llvm_index += it.types_len - 1;12452 it.llvm_index += it.types_len - 1;
...@@ -12464,7 +12462,7 @@ const ParamTypeIterator = struct {...@@ -12464,7 +12462,7 @@ const ParamTypeIterator = struct {
12464 return .byval;12462 return .byval;
12465 } else {12463 } else {
12466 var types_buffer: [8]Builder.Type = undefined;12464 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);
12468 it.types_buffer = types_buffer;12466 it.types_buffer = types_buffer;
12469 it.types_len = 1;12467 it.types_len = 1;
12470 it.llvm_index += 1;12468 it.llvm_index += 1;
...@@ -12489,7 +12487,7 @@ const ParamTypeIterator = struct {...@@ -12489,7 +12487,7 @@ const ParamTypeIterator = struct {
12489 }12487 }
1249012488
12491 fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering {12489 fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering {
12492 const zcu = it.object.pt.zcu;12490 const zcu = it.pt.zcu;
12493 switch (x86_64_abi.classifyWindows(ty, zcu, zcu.getTarget())) {12491 switch (x86_64_abi.classifyWindows(ty, zcu, zcu.getTarget())) {
12494 .integer => {12492 .integer => {
12495 if (isScalar(zcu, ty)) {12493 if (isScalar(zcu, ty)) {
...@@ -12522,7 +12520,7 @@ const ParamTypeIterator = struct {...@@ -12522,7 +12520,7 @@ const ParamTypeIterator = struct {
12522 }12520 }
1252312521
12524 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {12522 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
12525 const zcu = it.object.pt.zcu;12523 const zcu = it.pt.zcu;
12526 const ip = &zcu.intern_pool;12524 const ip = &zcu.intern_pool;
12527 const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg);12525 const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg);
12528 if (classes[0] == .memory) {12526 if (classes[0] == .memory) {
...@@ -12615,9 +12613,10 @@ const ParamTypeIterator = struct {...@@ -12615,9 +12613,10 @@ const ParamTypeIterator = struct {
12615 }12613 }
12616};12614};
1261712615
12618fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTypeIterator {12616fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) ParamTypeIterator {
12619 return .{12617 return .{
12620 .object = object,12618 .object = object,
12619 .pt = pt,
12621 .fn_info = fn_info,12620 .fn_info = fn_info,
12622 .zig_index = 0,12621 .zig_index = 0,
12623 .llvm_index = 0,12622 .llvm_index = 0,