| ... | @@ -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, |
| 496 | | 496 | |
| 497 | pt: Zcu.PerThread, | | |
| 498 | | | |
| 499 | debug_compile_unit: Builder.Metadata, | 497 | debug_compile_unit: Builder.Metadata, |
| 500 | | 498 | |
| 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 | } |
| 671 | | 665 | |
| 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; |
| 675 | | 669 | |
| 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; |
| 679 | | 672 | |
| ... | @@ -683,8 +676,8 @@ pub const Object = struct { | ... | @@ -683,8 +676,8 @@ pub const Object = struct { |
| 683 | | 676 | |
| 684 | // TODO: Address space | 677 | // 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); |
| 689 | | 682 | |
| 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 | } |
| 723 | | 716 | |
| 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; |
| 729 | | 722 | |
| 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 | // } |
| 741 | | 734 | |
| 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 | } |
| 748 | | 741 | |
| 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 | }; |
| 778 | | 771 | |
| 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; |
| 783 | | 776 | |
| 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); |
| 788 | | 781 | |
| 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]; |
| 808 | | 801 | |
| 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)); |
| 811 | | 804 | |
| 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 | }; |
| 1160 | | 1153 | |
| 1161 | const function_index = try o.resolveLlvmFunction(func.owner_nav); | 1154 | const function_index = try o.resolveLlvmFunction(pt, func.owner_nav); |
| 1162 | | 1155 | |
| 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); |
| 1273 | | 1266 | |
| 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); |
| 1278 | | 1271 | |
| ... | @@ -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); |
| 1295 | | 1288 | |
| 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(); |
| 1305 | | 1298 | |
| ... | @@ -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(); |
| 1320 | | 1313 | |
| ... | @@ -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; |
| 1335 | | 1328 | |
| 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; |
| 1374 | | 1367 | |
| 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; |
| 1408 | | 1401 | |
| ... | @@ -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; |
| 1423 | | 1416 | |
| ... | @@ -1435,11 +1428,11 @@ pub const Object = struct { | ... | @@ -1435,11 +1428,11 @@ pub const Object = struct { |
| 1435 | } | 1428 | } |
| 1436 | | 1429 | |
| 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); |
| 1439 | | 1432 | |
| 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); |
| 1443 | | 1436 | |
| 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 | } |
| 1570 | | 1563 | |
| 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 { |
| 1635 | | 1627 | |
| 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,18 @@ pub const Object = struct { | ... | @@ -1761,14 +1754,18 @@ pub const Object = struct { |
| 1761 | } | 1754 | } |
| 1762 | } | 1755 | } |
| 1763 | | 1756 | |
| 1764 | fn getDebugFile(o: *Object, file_index: Zcu.File.Index) Allocator.Error!Builder.Metadata { | 1757 | pub fn freeDecl(self: *Object, decl_index: InternPool.DeclIndex) void { |
| | 1758 | const global = self.decl_map.get(decl_index) orelse return; |
| | 1759 | global.delete(&self.builder); |
| | 1760 | } |
| | 1761 | |
| | 1762 | fn getDebugFile(o: *Object, pt: Zcu.PerThread, file_index: Zcu.File.Index) Allocator.Error!Builder.Metadata { |
| 1765 | const gpa = o.gpa; | 1763 | const gpa = o.gpa; |
| 1766 | const gop = try o.debug_file_map.getOrPut(gpa, file_index); | 1764 | const gop = try o.debug_file_map.getOrPut(gpa, file_index); |
| 1767 | errdefer assert(o.debug_file_map.remove(file_index)); | 1765 | errdefer assert(o.debug_file_map.remove(file_index)); |
| 1768 | if (gop.found_existing) return gop.value_ptr.*; | 1766 | if (gop.found_existing) return gop.value_ptr.*; |
| 1769 | const zcu = o.pt.zcu; | 1767 | const path = pt.zcu.fileByIndex(file_index).path; |
| 1770 | const path = zcu.fileByIndex(file_index).path; | 1768 | 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); | 1769 | defer gpa.free(abs_path); |
| 1773 | | 1770 | |
| 1774 | gop.value_ptr.* = try o.builder.debugFile( | 1771 | gop.value_ptr.* = try o.builder.debugFile( |
| ... | @@ -1780,13 +1777,13 @@ pub const Object = struct { | ... | @@ -1780,13 +1777,13 @@ pub const Object = struct { |
| 1780 | | 1777 | |
| 1781 | pub fn lowerDebugType( | 1778 | pub fn lowerDebugType( |
| 1782 | o: *Object, | 1779 | o: *Object, |
| | 1780 | pt: Zcu.PerThread, |
| 1783 | ty: Type, | 1781 | ty: Type, |
| 1784 | ) Allocator.Error!Builder.Metadata { | 1782 | ) Allocator.Error!Builder.Metadata { |
| 1785 | assert(!o.builder.strip); | 1783 | assert(!o.builder.strip); |
| 1786 | | 1784 | |
| 1787 | const gpa = o.gpa; | 1785 | const gpa = o.gpa; |
| 1788 | const target = o.target; | 1786 | const target = o.target; |
| 1789 | const pt = o.pt; | | |
| 1790 | const zcu = pt.zcu; | 1787 | const zcu = pt.zcu; |
| 1791 | const ip = &zcu.intern_pool; | 1788 | const ip = &zcu.intern_pool; |
| 1792 | | 1789 | |
| ... | @@ -1806,7 +1803,7 @@ pub const Object = struct { | ... | @@ -1806,7 +1803,7 @@ pub const Object = struct { |
| 1806 | .int => { | 1803 | .int => { |
| 1807 | const info = ty.intInfo(zcu); | 1804 | const info = ty.intInfo(zcu); |
| 1808 | assert(info.bits != 0); | 1805 | assert(info.bits != 0); |
| 1809 | const name = try o.allocTypeName(ty); | 1806 | const name = try o.allocTypeName(pt, ty); |
| 1810 | defer gpa.free(name); | 1807 | defer gpa.free(name); |
| 1811 | const builder_name = try o.builder.metadataString(name); | 1808 | const builder_name = try o.builder.metadataString(name); |
| 1812 | const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types | 1809 | const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types |
| ... | @@ -1819,7 +1816,7 @@ pub const Object = struct { | ... | @@ -1819,7 +1816,7 @@ pub const Object = struct { |
| 1819 | }, | 1816 | }, |
| 1820 | .@"enum" => { | 1817 | .@"enum" => { |
| 1821 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { | 1818 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 1822 | const debug_enum_type = try o.makeEmptyNamespaceDebugType(ty); | 1819 | const debug_enum_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 1823 | try o.debug_type_map.put(gpa, ty, debug_enum_type); | 1820 | try o.debug_type_map.put(gpa, ty, debug_enum_type); |
| 1824 | return debug_enum_type; | 1821 | return debug_enum_type; |
| 1825 | } | 1822 | } |
| ... | @@ -1847,13 +1844,13 @@ pub const Object = struct { | ... | @@ -1847,13 +1844,13 @@ pub const Object = struct { |
| 1847 | ); | 1844 | ); |
| 1848 | } | 1845 | } |
| 1849 | | 1846 | |
| 1850 | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); | 1847 | const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); |
| 1851 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| | 1848 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 1852 | try o.namespaceToDebugScope(parent_namespace) | 1849 | try o.namespaceToDebugScope(pt, parent_namespace) |
| 1853 | else | 1850 | else |
| 1854 | file; | 1851 | file; |
| 1855 | | 1852 | |
| 1856 | const name = try o.allocTypeName(ty); | 1853 | const name = try o.allocTypeName(pt, ty); |
| 1857 | defer gpa.free(name); | 1854 | defer gpa.free(name); |
| 1858 | | 1855 | |
| 1859 | const debug_enum_type = try o.builder.debugEnumerationType( | 1856 | const debug_enum_type = try o.builder.debugEnumerationType( |
| ... | @@ -1861,7 +1858,7 @@ pub const Object = struct { | ... | @@ -1861,7 +1858,7 @@ pub const Object = struct { |
| 1861 | file, | 1858 | file, |
| 1862 | scope, | 1859 | scope, |
| 1863 | ty.typeDeclSrcLine(zcu).? + 1, // Line | 1860 | ty.typeDeclSrcLine(zcu).? + 1, // Line |
| 1864 | try o.lowerDebugType(int_ty), | 1861 | try o.lowerDebugType(pt, int_ty), |
| 1865 | ty.abiSize(zcu) * 8, | 1862 | ty.abiSize(zcu) * 8, |
| 1866 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, | 1863 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 1867 | try o.builder.metadataTuple(enumerators), | 1864 | try o.builder.metadataTuple(enumerators), |
| ... | @@ -1873,7 +1870,7 @@ pub const Object = struct { | ... | @@ -1873,7 +1870,7 @@ pub const Object = struct { |
| 1873 | }, | 1870 | }, |
| 1874 | .float => { | 1871 | .float => { |
| 1875 | const bits = ty.floatBits(target); | 1872 | const bits = ty.floatBits(target); |
| 1876 | const name = try o.allocTypeName(ty); | 1873 | const name = try o.allocTypeName(pt, ty); |
| 1877 | defer gpa.free(name); | 1874 | defer gpa.free(name); |
| 1878 | const debug_float_type = try o.builder.debugFloatType( | 1875 | const debug_float_type = try o.builder.debugFloatType( |
| 1879 | try o.builder.metadataString(name), | 1876 | try o.builder.metadataString(name), |
| ... | @@ -1918,7 +1915,7 @@ pub const Object = struct { | ... | @@ -1918,7 +1915,7 @@ pub const Object = struct { |
| 1918 | }, | 1915 | }, |
| 1919 | }, | 1916 | }, |
| 1920 | }); | 1917 | }); |
| 1921 | const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty); | 1918 | const debug_ptr_type = try o.lowerDebugType(pt, bland_ptr_ty); |
| 1922 | try o.debug_type_map.put(gpa, ty, debug_ptr_type); | 1919 | try o.debug_type_map.put(gpa, ty, debug_ptr_type); |
| 1923 | return debug_ptr_type; | 1920 | return debug_ptr_type; |
| 1924 | } | 1921 | } |
| ... | @@ -1932,7 +1929,7 @@ pub const Object = struct { | ... | @@ -1932,7 +1929,7 @@ pub const Object = struct { |
| 1932 | const ptr_ty = ty.slicePtrFieldType(zcu); | 1929 | const ptr_ty = ty.slicePtrFieldType(zcu); |
| 1933 | const len_ty = Type.usize; | 1930 | const len_ty = Type.usize; |
| 1934 | | 1931 | |
| 1935 | const name = try o.allocTypeName(ty); | 1932 | const name = try o.allocTypeName(pt, ty); |
| 1936 | defer gpa.free(name); | 1933 | defer gpa.free(name); |
| 1937 | const line = 0; | 1934 | const line = 0; |
| 1938 | | 1935 | |
| ... | @@ -1948,7 +1945,7 @@ pub const Object = struct { | ... | @@ -1948,7 +1945,7 @@ pub const Object = struct { |
| 1948 | .none, // File | 1945 | .none, // File |
| 1949 | debug_fwd_ref, | 1946 | debug_fwd_ref, |
| 1950 | 0, // Line | 1947 | 0, // Line |
| 1951 | try o.lowerDebugType(ptr_ty), | 1948 | try o.lowerDebugType(pt, ptr_ty), |
| 1952 | ptr_size * 8, | 1949 | ptr_size * 8, |
| 1953 | (ptr_align.toByteUnits() orelse 0) * 8, | 1950 | (ptr_align.toByteUnits() orelse 0) * 8, |
| 1954 | 0, // Offset | 1951 | 0, // Offset |
| ... | @@ -1959,7 +1956,7 @@ pub const Object = struct { | ... | @@ -1959,7 +1956,7 @@ pub const Object = struct { |
| 1959 | .none, // File | 1956 | .none, // File |
| 1960 | debug_fwd_ref, | 1957 | debug_fwd_ref, |
| 1961 | 0, // Line | 1958 | 0, // Line |
| 1962 | try o.lowerDebugType(len_ty), | 1959 | try o.lowerDebugType(pt, len_ty), |
| 1963 | len_size * 8, | 1960 | len_size * 8, |
| 1964 | (len_align.toByteUnits() orelse 0) * 8, | 1961 | (len_align.toByteUnits() orelse 0) * 8, |
| 1965 | len_offset * 8, | 1962 | len_offset * 8, |
| ... | @@ -1988,9 +1985,9 @@ pub const Object = struct { | ... | @@ -1988,9 +1985,9 @@ pub const Object = struct { |
| 1988 | return debug_slice_type; | 1985 | return debug_slice_type; |
| 1989 | } | 1986 | } |
| 1990 | | 1987 | |
| 1991 | const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child)); | 1988 | const debug_elem_ty = try o.lowerDebugType(pt, Type.fromInterned(ptr_info.child)); |
| 1992 | | 1989 | |
| 1993 | const name = try o.allocTypeName(ty); | 1990 | const name = try o.allocTypeName(pt, ty); |
| 1994 | defer gpa.free(name); | 1991 | defer gpa.free(name); |
| 1995 | | 1992 | |
| 1996 | const debug_ptr_type = try o.builder.debugPointerType( | 1993 | const debug_ptr_type = try o.builder.debugPointerType( |
| ... | @@ -2022,12 +2019,12 @@ pub const Object = struct { | ... | @@ -2022,12 +2019,12 @@ pub const Object = struct { |
| 2022 | return debug_opaque_type; | 2019 | return debug_opaque_type; |
| 2023 | } | 2020 | } |
| 2024 | | 2021 | |
| 2025 | const name = try o.allocTypeName(ty); | 2022 | const name = try o.allocTypeName(pt, ty); |
| 2026 | defer gpa.free(name); | 2023 | defer gpa.free(name); |
| 2027 | | 2024 | |
| 2028 | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); | 2025 | const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); |
| 2029 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| | 2026 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 2030 | try o.namespaceToDebugScope(parent_namespace) | 2027 | try o.namespaceToDebugScope(pt, parent_namespace) |
| 2031 | else | 2028 | else |
| 2032 | file; | 2029 | file; |
| 2033 | | 2030 | |
| ... | @@ -2050,7 +2047,7 @@ pub const Object = struct { | ... | @@ -2050,7 +2047,7 @@ pub const Object = struct { |
| 2050 | .none, // File | 2047 | .none, // File |
| 2051 | .none, // Scope | 2048 | .none, // Scope |
| 2052 | 0, // Line | 2049 | 0, // Line |
| 2053 | try o.lowerDebugType(ty.childType(zcu)), | 2050 | try o.lowerDebugType(pt, ty.childType(zcu)), |
| 2054 | ty.abiSize(zcu) * 8, | 2051 | ty.abiSize(zcu) * 8, |
| 2055 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, | 2052 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2056 | try o.builder.metadataTuple(&.{ | 2053 | try o.builder.metadataTuple(&.{ |
| ... | @@ -2073,7 +2070,7 @@ pub const Object = struct { | ... | @@ -2073,7 +2070,7 @@ pub const Object = struct { |
| 2073 | .int => blk: { | 2070 | .int => blk: { |
| 2074 | const info = elem_ty.intInfo(zcu); | 2071 | const info = elem_ty.intInfo(zcu); |
| 2075 | assert(info.bits != 0); | 2072 | assert(info.bits != 0); |
| 2076 | const name = try o.allocTypeName(ty); | 2073 | const name = try o.allocTypeName(pt, ty); |
| 2077 | defer gpa.free(name); | 2074 | defer gpa.free(name); |
| 2078 | const builder_name = try o.builder.metadataString(name); | 2075 | const builder_name = try o.builder.metadataString(name); |
| 2079 | break :blk switch (info.signedness) { | 2076 | break :blk switch (info.signedness) { |
| ... | @@ -2085,7 +2082,7 @@ pub const Object = struct { | ... | @@ -2085,7 +2082,7 @@ pub const Object = struct { |
| 2085 | try o.builder.metadataString("bool"), | 2082 | try o.builder.metadataString("bool"), |
| 2086 | 1, | 2083 | 1, |
| 2087 | ), | 2084 | ), |
| 2088 | else => try o.lowerDebugType(ty.childType(zcu)), | 2085 | else => try o.lowerDebugType(pt, ty.childType(zcu)), |
| 2089 | }; | 2086 | }; |
| 2090 | | 2087 | |
| 2091 | const debug_vector_type = try o.builder.debugVectorType( | 2088 | const debug_vector_type = try o.builder.debugVectorType( |
| ... | @@ -2108,7 +2105,7 @@ pub const Object = struct { | ... | @@ -2108,7 +2105,7 @@ pub const Object = struct { |
| 2108 | return debug_vector_type; | 2105 | return debug_vector_type; |
| 2109 | }, | 2106 | }, |
| 2110 | .optional => { | 2107 | .optional => { |
| 2111 | const name = try o.allocTypeName(ty); | 2108 | const name = try o.allocTypeName(pt, ty); |
| 2112 | defer gpa.free(name); | 2109 | defer gpa.free(name); |
| 2113 | const child_ty = ty.optionalChild(zcu); | 2110 | const child_ty = ty.optionalChild(zcu); |
| 2114 | if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) { | 2111 | if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| ... | @@ -2126,7 +2123,7 @@ pub const Object = struct { | ... | @@ -2126,7 +2123,7 @@ pub const Object = struct { |
| 2126 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | 2123 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); |
| 2127 | | 2124 | |
| 2128 | if (ty.optionalReprIsPayload(zcu)) { | 2125 | if (ty.optionalReprIsPayload(zcu)) { |
| 2129 | const debug_optional_type = try o.lowerDebugType(child_ty); | 2126 | const debug_optional_type = try o.lowerDebugType(pt, child_ty); |
| 2130 | | 2127 | |
| 2131 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); | 2128 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); |
| 2132 | | 2129 | |
| ... | @@ -2149,7 +2146,7 @@ pub const Object = struct { | ... | @@ -2149,7 +2146,7 @@ pub const Object = struct { |
| 2149 | .none, // File | 2146 | .none, // File |
| 2150 | debug_fwd_ref, | 2147 | debug_fwd_ref, |
| 2151 | 0, // Line | 2148 | 0, // Line |
| 2152 | try o.lowerDebugType(child_ty), | 2149 | try o.lowerDebugType(pt, child_ty), |
| 2153 | payload_size * 8, | 2150 | payload_size * 8, |
| 2154 | (payload_align.toByteUnits() orelse 0) * 8, | 2151 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2155 | 0, // Offset | 2152 | 0, // Offset |
| ... | @@ -2160,7 +2157,7 @@ pub const Object = struct { | ... | @@ -2160,7 +2157,7 @@ pub const Object = struct { |
| 2160 | .none, | 2157 | .none, |
| 2161 | debug_fwd_ref, | 2158 | debug_fwd_ref, |
| 2162 | 0, | 2159 | 0, |
| 2163 | try o.lowerDebugType(non_null_ty), | 2160 | try o.lowerDebugType(pt, non_null_ty), |
| 2164 | non_null_size * 8, | 2161 | non_null_size * 8, |
| 2165 | (non_null_align.toByteUnits() orelse 0) * 8, | 2162 | (non_null_align.toByteUnits() orelse 0) * 8, |
| 2166 | non_null_offset * 8, | 2163 | non_null_offset * 8, |
| ... | @@ -2192,12 +2189,12 @@ pub const Object = struct { | ... | @@ -2192,12 +2189,12 @@ pub const Object = struct { |
| 2192 | const payload_ty = ty.errorUnionPayload(zcu); | 2189 | const payload_ty = ty.errorUnionPayload(zcu); |
| 2193 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { | 2190 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2194 | // TODO: Maybe remove? | 2191 | // TODO: Maybe remove? |
| 2195 | const debug_error_union_type = try o.lowerDebugType(Type.anyerror); | 2192 | const debug_error_union_type = try o.lowerDebugType(pt, Type.anyerror); |
| 2196 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); | 2193 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); |
| 2197 | return debug_error_union_type; | 2194 | return debug_error_union_type; |
| 2198 | } | 2195 | } |
| 2199 | | 2196 | |
| 2200 | const name = try o.allocTypeName(ty); | 2197 | const name = try o.allocTypeName(pt, ty); |
| 2201 | defer gpa.free(name); | 2198 | defer gpa.free(name); |
| 2202 | | 2199 | |
| 2203 | const error_size = Type.anyerror.abiSize(zcu); | 2200 | const error_size = Type.anyerror.abiSize(zcu); |
| ... | @@ -2229,7 +2226,7 @@ pub const Object = struct { | ... | @@ -2229,7 +2226,7 @@ pub const Object = struct { |
| 2229 | .none, // File | 2226 | .none, // File |
| 2230 | debug_fwd_ref, | 2227 | debug_fwd_ref, |
| 2231 | 0, // Line | 2228 | 0, // Line |
| 2232 | try o.lowerDebugType(Type.anyerror), | 2229 | try o.lowerDebugType(pt, Type.anyerror), |
| 2233 | error_size * 8, | 2230 | error_size * 8, |
| 2234 | (error_align.toByteUnits() orelse 0) * 8, | 2231 | (error_align.toByteUnits() orelse 0) * 8, |
| 2235 | error_offset * 8, | 2232 | error_offset * 8, |
| ... | @@ -2239,7 +2236,7 @@ pub const Object = struct { | ... | @@ -2239,7 +2236,7 @@ pub const Object = struct { |
| 2239 | .none, // File | 2236 | .none, // File |
| 2240 | debug_fwd_ref, | 2237 | debug_fwd_ref, |
| 2241 | 0, // Line | 2238 | 0, // Line |
| 2242 | try o.lowerDebugType(payload_ty), | 2239 | try o.lowerDebugType(pt, payload_ty), |
| 2243 | payload_size * 8, | 2240 | payload_size * 8, |
| 2244 | (payload_align.toByteUnits() orelse 0) * 8, | 2241 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2245 | payload_offset * 8, | 2242 | payload_offset * 8, |
| ... | @@ -2270,7 +2267,7 @@ pub const Object = struct { | ... | @@ -2270,7 +2267,7 @@ pub const Object = struct { |
| 2270 | return debug_error_set; | 2267 | return debug_error_set; |
| 2271 | }, | 2268 | }, |
| 2272 | .@"struct" => { | 2269 | .@"struct" => { |
| 2273 | const name = try o.allocTypeName(ty); | 2270 | const name = try o.allocTypeName(pt, ty); |
| 2274 | defer gpa.free(name); | 2271 | defer gpa.free(name); |
| 2275 | | 2272 | |
| 2276 | if (zcu.typeToPackedStruct(ty)) |struct_type| { | 2273 | if (zcu.typeToPackedStruct(ty)) |struct_type| { |
| ... | @@ -2315,7 +2312,7 @@ pub const Object = struct { | ... | @@ -2315,7 +2312,7 @@ pub const Object = struct { |
| 2315 | .none, // File | 2312 | .none, // File |
| 2316 | debug_fwd_ref, | 2313 | debug_fwd_ref, |
| 2317 | 0, | 2314 | 0, |
| 2318 | try o.lowerDebugType(Type.fromInterned(field_ty)), | 2315 | try o.lowerDebugType(pt, Type.fromInterned(field_ty)), |
| 2319 | field_size * 8, | 2316 | field_size * 8, |
| 2320 | (field_align.toByteUnits() orelse 0) * 8, | 2317 | (field_align.toByteUnits() orelse 0) * 8, |
| 2321 | field_offset * 8, | 2318 | field_offset * 8, |
| ... | @@ -2347,7 +2344,7 @@ pub const Object = struct { | ... | @@ -2347,7 +2344,7 @@ pub const Object = struct { |
| 2347 | // into. Therefore we can satisfy this by making an empty namespace, | 2344 | // into. Therefore we can satisfy this by making an empty namespace, |
| 2348 | // rather than changing the frontend to unnecessarily resolve the | 2345 | // rather than changing the frontend to unnecessarily resolve the |
| 2349 | // struct field types. | 2346 | // struct field types. |
| 2350 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty); | 2347 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2351 | try o.debug_type_map.put(gpa, ty, debug_struct_type); | 2348 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2352 | return debug_struct_type; | 2349 | return debug_struct_type; |
| 2353 | } | 2350 | } |
| ... | @@ -2356,7 +2353,7 @@ pub const Object = struct { | ... | @@ -2356,7 +2353,7 @@ pub const Object = struct { |
| 2356 | } | 2353 | } |
| 2357 | | 2354 | |
| 2358 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { | 2355 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2359 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty); | 2356 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2360 | try o.debug_type_map.put(gpa, ty, debug_struct_type); | 2357 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2361 | return debug_struct_type; | 2358 | return debug_struct_type; |
| 2362 | } | 2359 | } |
| ... | @@ -2388,7 +2385,7 @@ pub const Object = struct { | ... | @@ -2388,7 +2385,7 @@ pub const Object = struct { |
| 2388 | .none, // File | 2385 | .none, // File |
| 2389 | debug_fwd_ref, | 2386 | debug_fwd_ref, |
| 2390 | 0, // Line | 2387 | 0, // Line |
| 2391 | try o.lowerDebugType(field_ty), | 2388 | try o.lowerDebugType(pt, field_ty), |
| 2392 | field_size * 8, | 2389 | field_size * 8, |
| 2393 | (field_align.toByteUnits() orelse 0) * 8, | 2390 | (field_align.toByteUnits() orelse 0) * 8, |
| 2394 | field_offset * 8, | 2391 | field_offset * 8, |
| ... | @@ -2415,7 +2412,7 @@ pub const Object = struct { | ... | @@ -2415,7 +2412,7 @@ pub const Object = struct { |
| 2415 | return debug_struct_type; | 2412 | return debug_struct_type; |
| 2416 | }, | 2413 | }, |
| 2417 | .@"union" => { | 2414 | .@"union" => { |
| 2418 | const name = try o.allocTypeName(ty); | 2415 | const name = try o.allocTypeName(pt, ty); |
| 2419 | defer gpa.free(name); | 2416 | defer gpa.free(name); |
| 2420 | | 2417 | |
| 2421 | const union_type = ip.loadUnionType(ty.toIntern()); | 2418 | const union_type = ip.loadUnionType(ty.toIntern()); |
| ... | @@ -2423,7 +2420,7 @@ pub const Object = struct { | ... | @@ -2423,7 +2420,7 @@ pub const Object = struct { |
| 2423 | !ty.hasRuntimeBitsIgnoreComptime(zcu) or | 2420 | !ty.hasRuntimeBitsIgnoreComptime(zcu) or |
| 2424 | !union_type.haveLayout(ip)) | 2421 | !union_type.haveLayout(ip)) |
| 2425 | { | 2422 | { |
| 2426 | const debug_union_type = try o.makeEmptyNamespaceDebugType(ty); | 2423 | const debug_union_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2427 | try o.debug_type_map.put(gpa, ty, debug_union_type); | 2424 | try o.debug_type_map.put(gpa, ty, debug_union_type); |
| 2428 | return debug_union_type; | 2425 | return debug_union_type; |
| 2429 | } | 2426 | } |
| ... | @@ -2445,7 +2442,7 @@ pub const Object = struct { | ... | @@ -2445,7 +2442,7 @@ pub const Object = struct { |
| 2445 | ty.abiSize(zcu) * 8, | 2442 | ty.abiSize(zcu) * 8, |
| 2446 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, | 2443 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2447 | try o.builder.metadataTuple( | 2444 | try o.builder.metadataTuple( |
| 2448 | &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))}, | 2445 | &.{try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty))}, |
| 2449 | ), | 2446 | ), |
| 2450 | ); | 2447 | ); |
| 2451 | | 2448 | |
| ... | @@ -2484,7 +2481,7 @@ pub const Object = struct { | ... | @@ -2484,7 +2481,7 @@ pub const Object = struct { |
| 2484 | .none, // File | 2481 | .none, // File |
| 2485 | debug_union_fwd_ref, | 2482 | debug_union_fwd_ref, |
| 2486 | 0, // Line | 2483 | 0, // Line |
| 2487 | try o.lowerDebugType(Type.fromInterned(field_ty)), | 2484 | try o.lowerDebugType(pt, Type.fromInterned(field_ty)), |
| 2488 | field_size * 8, | 2485 | field_size * 8, |
| 2489 | (field_align.toByteUnits() orelse 0) * 8, | 2486 | (field_align.toByteUnits() orelse 0) * 8, |
| 2490 | 0, // Offset | 2487 | 0, // Offset |
| ... | @@ -2534,7 +2531,7 @@ pub const Object = struct { | ... | @@ -2534,7 +2531,7 @@ pub const Object = struct { |
| 2534 | .none, // File | 2531 | .none, // File |
| 2535 | debug_fwd_ref, | 2532 | debug_fwd_ref, |
| 2536 | 0, // Line | 2533 | 0, // Line |
| 2537 | try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)), | 2534 | try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty)), |
| 2538 | layout.tag_size * 8, | 2535 | layout.tag_size * 8, |
| 2539 | (layout.tag_align.toByteUnits() orelse 0) * 8, | 2536 | (layout.tag_align.toByteUnits() orelse 0) * 8, |
| 2540 | tag_offset * 8, | 2537 | tag_offset * 8, |
| ... | @@ -2588,19 +2585,19 @@ pub const Object = struct { | ... | @@ -2588,19 +2585,19 @@ pub const Object = struct { |
| 2588 | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) { | 2585 | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2589 | const sret = firstParamSRet(fn_info, zcu, target); | 2586 | const sret = firstParamSRet(fn_info, zcu, target); |
| 2590 | const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type); | 2587 | const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type); |
| 2591 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty)); | 2588 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ret_ty)); |
| 2592 | | 2589 | |
| 2593 | if (sret) { | 2590 | if (sret) { |
| 2594 | const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type)); | 2591 | const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type)); |
| 2595 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); | 2592 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty)); |
| 2596 | } | 2593 | } |
| 2597 | } else { | 2594 | } else { |
| 2598 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void)); | 2595 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, Type.void)); |
| 2599 | } | 2596 | } |
| 2600 | | 2597 | |
| 2601 | if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) { | 2598 | if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) { |
| 2602 | const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType()); | 2599 | const ptr_ty = try pt.ptrType(.{ .child = zcu.stack_trace_type }); |
| 2603 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); | 2600 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty)); |
| 2604 | } | 2601 | } |
| 2605 | | 2602 | |
| 2606 | for (0..fn_info.param_types.len) |i| { | 2603 | for (0..fn_info.param_types.len) |i| { |
| ... | @@ -2609,9 +2606,9 @@ pub const Object = struct { | ... | @@ -2609,9 +2606,9 @@ pub const Object = struct { |
| 2609 | | 2606 | |
| 2610 | if (isByRef(param_ty, zcu)) { | 2607 | if (isByRef(param_ty, zcu)) { |
| 2611 | const ptr_ty = try pt.singleMutPtrType(param_ty); | 2608 | const ptr_ty = try pt.singleMutPtrType(param_ty); |
| 2612 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); | 2609 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty)); |
| 2613 | } else { | 2610 | } else { |
| 2614 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty)); | 2611 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, param_ty)); |
| 2615 | } | 2612 | } |
| 2616 | } | 2613 | } |
| 2617 | | 2614 | |
| ... | @@ -2634,10 +2631,10 @@ pub const Object = struct { | ... | @@ -2634,10 +2631,10 @@ pub const Object = struct { |
| 2634 | } | 2631 | } |
| 2635 | } | 2632 | } |
| 2636 | | 2633 | |
| 2637 | fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata { | 2634 | fn namespaceToDebugScope(o: *Object, pt: Zcu.PerThread, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata { |
| 2638 | const zcu = o.pt.zcu; | 2635 | const zcu = pt.zcu; |
| 2639 | const namespace = zcu.namespacePtr(namespace_index); | 2636 | const namespace = zcu.namespacePtr(namespace_index); |
| 2640 | if (namespace.parent == .none) return try o.getDebugFile(namespace.file_scope); | 2637 | if (namespace.parent == .none) return try o.getDebugFile(pt, namespace.file_scope); |
| 2641 | | 2638 | |
| 2642 | const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index); | 2639 | const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index); |
| 2643 | | 2640 | |
| ... | @@ -2646,12 +2643,12 @@ pub const Object = struct { | ... | @@ -2646,12 +2643,12 @@ pub const Object = struct { |
| 2646 | return gop.value_ptr.*; | 2643 | return gop.value_ptr.*; |
| 2647 | } | 2644 | } |
| 2648 | | 2645 | |
| 2649 | fn makeEmptyNamespaceDebugType(o: *Object, ty: Type) !Builder.Metadata { | 2646 | fn makeEmptyNamespaceDebugType(o: *Object, pt: Zcu.PerThread, ty: Type) !Builder.Metadata { |
| 2650 | const zcu = o.pt.zcu; | 2647 | const zcu = pt.zcu; |
| 2651 | const ip = &zcu.intern_pool; | 2648 | const ip = &zcu.intern_pool; |
| 2652 | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); | 2649 | const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); |
| 2653 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| | 2650 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 2654 | try o.namespaceToDebugScope(parent_namespace) | 2651 | try o.namespaceToDebugScope(pt, parent_namespace) |
| 2655 | else | 2652 | else |
| 2656 | file; | 2653 | file; |
| 2657 | return o.builder.debugStructType( | 2654 | return o.builder.debugStructType( |
| ... | @@ -2666,31 +2663,10 @@ pub const Object = struct { | ... | @@ -2666,31 +2663,10 @@ pub const Object = struct { |
| 2666 | ); | 2663 | ); |
| 2667 | } | 2664 | } |
| 2668 | | 2665 | |
| 2669 | fn getStackTraceType(o: *Object) Allocator.Error!Type { | 2666 | 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); | 2667 | var aw: std.io.Writer.Allocating = .init(o.gpa); |
| 2692 | defer aw.deinit(); | 2668 | defer aw.deinit(); |
| 2693 | ty.print(&aw.writer, o.pt) catch |err| switch (err) { | 2669 | ty.print(&aw.writer, pt) catch |err| switch (err) { |
| 2694 | error.WriteFailed => return error.OutOfMemory, | 2670 | error.WriteFailed => return error.OutOfMemory, |
| 2695 | }; | 2671 | }; |
| 2696 | return aw.toOwnedSliceSentinel(0); | 2672 | return aw.toOwnedSliceSentinel(0); |
| ... | @@ -2701,9 +2677,9 @@ pub const Object = struct { | ... | @@ -2701,9 +2677,9 @@ pub const Object = struct { |
| 2701 | /// completed, so if any attributes rely on that, they must be done in updateFunc, not here. | 2677 | /// completed, so if any attributes rely on that, they must be done in updateFunc, not here. |
| 2702 | fn resolveLlvmFunction( | 2678 | fn resolveLlvmFunction( |
| 2703 | o: *Object, | 2679 | o: *Object, |
| | 2680 | pt: Zcu.PerThread, |
| 2704 | nav_index: InternPool.Nav.Index, | 2681 | nav_index: InternPool.Nav.Index, |
| 2705 | ) Allocator.Error!Builder.Function.Index { | 2682 | ) Allocator.Error!Builder.Function.Index { |
| 2706 | const pt = o.pt; | | |
| 2707 | const zcu = pt.zcu; | 2683 | const zcu = pt.zcu; |
| 2708 | const ip = &zcu.intern_pool; | 2684 | const ip = &zcu.intern_pool; |
| 2709 | const gpa = o.gpa; | 2685 | const gpa = o.gpa; |
| ... | @@ -2722,7 +2698,7 @@ pub const Object = struct { | ... | @@ -2722,7 +2698,7 @@ pub const Object = struct { |
| 2722 | else | 2698 | else |
| 2723 | .{ false, .none }; | 2699 | .{ false, .none }; |
| 2724 | const function_index = try o.builder.addFunction( | 2700 | const function_index = try o.builder.addFunction( |
| 2725 | try o.lowerType(ty), | 2701 | try o.lowerType(pt, ty), |
| 2726 | try o.builder.strtabString((if (is_extern) nav.name else nav.fqn).toSlice(ip)), | 2702 | try o.builder.strtabString((if (is_extern) nav.name else nav.fqn).toSlice(ip)), |
| 2727 | toLlvmAddressSpace(nav.getAddrspace(), target), | 2703 | toLlvmAddressSpace(nav.getAddrspace(), target), |
| 2728 | ); | 2704 | ); |
| ... | @@ -2755,7 +2731,7 @@ pub const Object = struct { | ... | @@ -2755,7 +2731,7 @@ pub const Object = struct { |
| 2755 | try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder); | 2731 | try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder); |
| 2756 | try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder); | 2732 | try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder); |
| 2757 | | 2733 | |
| 2758 | const raw_llvm_ret_ty = try o.lowerType(Type.fromInterned(fn_info.return_type)); | 2734 | const raw_llvm_ret_ty = try o.lowerType(pt, Type.fromInterned(fn_info.return_type)); |
| 2759 | try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder); | 2735 | try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder); |
| 2760 | | 2736 | |
| 2761 | llvm_arg_i += 1; | 2737 | llvm_arg_i += 1; |
| ... | @@ -2862,19 +2838,19 @@ pub const Object = struct { | ... | @@ -2862,19 +2838,19 @@ pub const Object = struct { |
| 2862 | // Add parameter attributes. We handle only the case of extern functions (no body) | 2838 | // Add parameter attributes. We handle only the case of extern functions (no body) |
| 2863 | // because functions with bodies are handled in `updateFunc`. | 2839 | // because functions with bodies are handled in `updateFunc`. |
| 2864 | if (is_extern) { | 2840 | if (is_extern) { |
| 2865 | var it = iterateParamTypes(o, fn_info); | 2841 | var it = iterateParamTypes(o, pt, fn_info); |
| 2866 | it.llvm_index = llvm_arg_i; | 2842 | it.llvm_index = llvm_arg_i; |
| 2867 | while (try it.next()) |lowering| switch (lowering) { | 2843 | while (try it.next()) |lowering| switch (lowering) { |
| 2868 | .byval => { | 2844 | .byval => { |
| 2869 | const param_index = it.zig_index - 1; | 2845 | const param_index = it.zig_index - 1; |
| 2870 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); | 2846 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); |
| 2871 | if (!isByRef(param_ty, zcu)) { | 2847 | if (!isByRef(param_ty, zcu)) { |
| 2872 | try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1); | 2848 | try o.addByValParamAttrs(pt, &attributes, param_ty, param_index, fn_info, it.llvm_index - 1); |
| 2873 | } | 2849 | } |
| 2874 | }, | 2850 | }, |
| 2875 | .byref => { | 2851 | .byref => { |
| 2876 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); | 2852 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); |
| 2877 | const param_llvm_ty = try o.lowerType(param_ty); | 2853 | const param_llvm_ty = try o.lowerType(pt, param_ty); |
| 2878 | const alignment = param_ty.abiAlignment(zcu); | 2854 | const alignment = param_ty.abiAlignment(zcu); |
| 2879 | try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty); | 2855 | try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty); |
| 2880 | }, | 2856 | }, |
| ... | @@ -2969,6 +2945,7 @@ pub const Object = struct { | ... | @@ -2969,6 +2945,7 @@ pub const Object = struct { |
| 2969 | | 2945 | |
| 2970 | fn resolveGlobalUav( | 2946 | fn resolveGlobalUav( |
| 2971 | o: *Object, | 2947 | o: *Object, |
| | 2948 | pt: Zcu.PerThread, |
| 2972 | uav: InternPool.Index, | 2949 | uav: InternPool.Index, |
| 2973 | llvm_addr_space: Builder.AddrSpace, | 2950 | llvm_addr_space: Builder.AddrSpace, |
| 2974 | alignment: InternPool.Alignment, | 2951 | alignment: InternPool.Alignment, |
| ... | @@ -2986,17 +2963,17 @@ pub const Object = struct { | ... | @@ -2986,17 +2963,17 @@ pub const Object = struct { |
| 2986 | } | 2963 | } |
| 2987 | errdefer assert(o.uav_map.remove(uav)); | 2964 | errdefer assert(o.uav_map.remove(uav)); |
| 2988 | | 2965 | |
| 2989 | const zcu = o.pt.zcu; | 2966 | const zcu = pt.zcu; |
| 2990 | const decl_ty = zcu.intern_pool.typeOf(uav); | 2967 | const decl_ty = zcu.intern_pool.typeOf(uav); |
| 2991 | | 2968 | |
| 2992 | const variable_index = try o.builder.addVariable( | 2969 | const variable_index = try o.builder.addVariable( |
| 2993 | try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}), | 2970 | try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}), |
| 2994 | try o.lowerType(Type.fromInterned(decl_ty)), | 2971 | try o.lowerType(pt, Type.fromInterned(decl_ty)), |
| 2995 | llvm_addr_space, | 2972 | llvm_addr_space, |
| 2996 | ); | 2973 | ); |
| 2997 | gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; | 2974 | gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; |
| 2998 | | 2975 | |
| 2999 | try variable_index.setInitializer(try o.lowerValue(uav), &o.builder); | 2976 | try variable_index.setInitializer(try o.lowerValue(pt, uav), &o.builder); |
| 3000 | variable_index.setLinkage(.internal, &o.builder); | 2977 | variable_index.setLinkage(.internal, &o.builder); |
| 3001 | variable_index.setMutability(.constant, &o.builder); | 2978 | variable_index.setMutability(.constant, &o.builder); |
| 3002 | variable_index.setUnnamedAddr(.unnamed_addr, &o.builder); | 2979 | variable_index.setUnnamedAddr(.unnamed_addr, &o.builder); |
| ... | @@ -3006,13 +2983,13 @@ pub const Object = struct { | ... | @@ -3006,13 +2983,13 @@ pub const Object = struct { |
| 3006 | | 2983 | |
| 3007 | fn resolveGlobalNav( | 2984 | fn resolveGlobalNav( |
| 3008 | o: *Object, | 2985 | o: *Object, |
| | 2986 | pt: Zcu.PerThread, |
| 3009 | nav_index: InternPool.Nav.Index, | 2987 | nav_index: InternPool.Nav.Index, |
| 3010 | ) Allocator.Error!Builder.Variable.Index { | 2988 | ) Allocator.Error!Builder.Variable.Index { |
| 3011 | const gop = try o.nav_map.getOrPut(o.gpa, nav_index); | 2989 | 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; | 2990 | if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable; |
| 3013 | errdefer assert(o.nav_map.remove(nav_index)); | 2991 | errdefer assert(o.nav_map.remove(nav_index)); |
| 3014 | | 2992 | |
| 3015 | const pt = o.pt; | | |
| 3016 | const zcu = pt.zcu; | 2993 | const zcu = pt.zcu; |
| 3017 | const ip = &zcu.intern_pool; | 2994 | const ip = &zcu.intern_pool; |
| 3018 | const nav = ip.getNav(nav_index); | 2995 | const nav = ip.getNav(nav_index); |
| ... | @@ -3033,7 +3010,7 @@ pub const Object = struct { | ... | @@ -3033,7 +3010,7 @@ pub const Object = struct { |
| 3033 | .strong, .weak => nav.name, | 3010 | .strong, .weak => nav.name, |
| 3034 | .link_once => unreachable, | 3011 | .link_once => unreachable, |
| 3035 | }.toSlice(ip)), | 3012 | }.toSlice(ip)), |
| 3036 | try o.lowerType(Type.fromInterned(nav.typeOf(ip))), | 3013 | try o.lowerType(pt, Type.fromInterned(nav.typeOf(ip))), |
| 3037 | toLlvmGlobalAddressSpace(nav.getAddrspace(), zcu.getTarget()), | 3014 | toLlvmGlobalAddressSpace(nav.getAddrspace(), zcu.getTarget()), |
| 3038 | ); | 3015 | ); |
| 3039 | gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; | 3016 | gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; |
| ... | @@ -3062,12 +3039,11 @@ pub const Object = struct { | ... | @@ -3062,12 +3039,11 @@ pub const Object = struct { |
| 3062 | return variable_index; | 3039 | return variable_index; |
| 3063 | } | 3040 | } |
| 3064 | | 3041 | |
| 3065 | fn errorIntType(o: *Object) Allocator.Error!Builder.Type { | 3042 | fn errorIntType(o: *Object, pt: Zcu.PerThread) Allocator.Error!Builder.Type { |
| 3066 | return o.builder.intType(o.pt.zcu.errorSetBits()); | 3043 | return o.builder.intType(pt.zcu.errorSetBits()); |
| 3067 | } | 3044 | } |
| 3068 | | 3045 | |
| 3069 | fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type { | 3046 | fn lowerType(o: *Object, pt: Zcu.PerThread, t: Type) Allocator.Error!Builder.Type { |
| 3070 | const pt = o.pt; | | |
| 3071 | const zcu = pt.zcu; | 3047 | const zcu = pt.zcu; |
| 3072 | const target = zcu.getTarget(); | 3048 | const target = zcu.getTarget(); |
| 3073 | const ip = &zcu.intern_pool; | 3049 | const ip = &zcu.intern_pool; |
| ... | @@ -3123,7 +3099,7 @@ pub const Object = struct { | ... | @@ -3123,7 +3099,7 @@ pub const Object = struct { |
| 3123 | .bool_type => .i1, | 3099 | .bool_type => .i1, |
| 3124 | .void_type => .void, | 3100 | .void_type => .void, |
| 3125 | .type_type => unreachable, | 3101 | .type_type => unreachable, |
| 3126 | .anyerror_type => try o.errorIntType(), | 3102 | .anyerror_type => try o.errorIntType(pt), |
| 3127 | .comptime_int_type, | 3103 | .comptime_int_type, |
| 3128 | .comptime_float_type, | 3104 | .comptime_float_type, |
| 3129 | .noreturn_type, | 3105 | .noreturn_type, |
| ... | @@ -3141,11 +3117,11 @@ pub const Object = struct { | ... | @@ -3141,11 +3117,11 @@ pub const Object = struct { |
| 3141 | => .ptr, | 3117 | => .ptr, |
| 3142 | .slice_const_u8_type, | 3118 | .slice_const_u8_type, |
| 3143 | .slice_const_u8_sentinel_0_type, | 3119 | .slice_const_u8_sentinel_0_type, |
| 3144 | => try o.builder.structType(.normal, &.{ .ptr, try o.lowerType(Type.usize) }), | 3120 | => try o.builder.structType(.normal, &.{ .ptr, try o.lowerType(pt, Type.usize) }), |
| 3145 | .optional_noreturn_type => unreachable, | 3121 | .optional_noreturn_type => unreachable, |
| 3146 | .anyerror_void_error_union_type, | 3122 | .anyerror_void_error_union_type, |
| 3147 | .adhoc_inferred_error_set_type, | 3123 | .adhoc_inferred_error_set_type, |
| 3148 | => try o.errorIntType(), | 3124 | => try o.errorIntType(pt), |
| 3149 | .generic_poison_type, | 3125 | .generic_poison_type, |
| 3150 | .empty_tuple_type, | 3126 | .empty_tuple_type, |
| 3151 | => unreachable, | 3127 | => unreachable, |
| ... | @@ -3182,24 +3158,24 @@ pub const Object = struct { | ... | @@ -3182,24 +3158,24 @@ pub const Object = struct { |
| 3182 | .one, .many, .c => ptr_ty, | 3158 | .one, .many, .c => ptr_ty, |
| 3183 | .slice => try o.builder.structType(.normal, &.{ | 3159 | .slice => try o.builder.structType(.normal, &.{ |
| 3184 | ptr_ty, | 3160 | ptr_ty, |
| 3185 | try o.lowerType(Type.usize), | 3161 | try o.lowerType(pt, Type.usize), |
| 3186 | }), | 3162 | }), |
| 3187 | }; | 3163 | }; |
| 3188 | }, | 3164 | }, |
| 3189 | .array_type => |array_type| o.builder.arrayType( | 3165 | .array_type => |array_type| o.builder.arrayType( |
| 3190 | array_type.lenIncludingSentinel(), | 3166 | array_type.lenIncludingSentinel(), |
| 3191 | try o.lowerType(Type.fromInterned(array_type.child)), | 3167 | try o.lowerType(pt, Type.fromInterned(array_type.child)), |
| 3192 | ), | 3168 | ), |
| 3193 | .vector_type => |vector_type| o.builder.vectorType( | 3169 | .vector_type => |vector_type| o.builder.vectorType( |
| 3194 | .normal, | 3170 | .normal, |
| 3195 | vector_type.len, | 3171 | vector_type.len, |
| 3196 | try o.lowerType(Type.fromInterned(vector_type.child)), | 3172 | try o.lowerType(pt, Type.fromInterned(vector_type.child)), |
| 3197 | ), | 3173 | ), |
| 3198 | .opt_type => |child_ty| { | 3174 | .opt_type => |child_ty| { |
| 3199 | // Must stay in sync with `opt_payload` logic in `lowerPtr`. | 3175 | // Must stay in sync with `opt_payload` logic in `lowerPtr`. |
| 3200 | if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(zcu)) return .i8; | 3176 | if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(zcu)) return .i8; |
| 3201 | | 3177 | |
| 3202 | const payload_ty = try o.lowerType(Type.fromInterned(child_ty)); | 3178 | const payload_ty = try o.lowerType(pt, Type.fromInterned(child_ty)); |
| 3203 | if (t.optionalReprIsPayload(zcu)) return payload_ty; | 3179 | if (t.optionalReprIsPayload(zcu)) return payload_ty; |
| 3204 | | 3180 | |
| 3205 | comptime assert(optional_layout_version == 3); | 3181 | comptime assert(optional_layout_version == 3); |
| ... | @@ -3218,17 +3194,16 @@ pub const Object = struct { | ... | @@ -3218,17 +3194,16 @@ pub const Object = struct { |
| 3218 | .error_union_type => |error_union_type| { | 3194 | .error_union_type => |error_union_type| { |
| 3219 | // Must stay in sync with `codegen.errUnionPayloadOffset`. | 3195 | // Must stay in sync with `codegen.errUnionPayloadOffset`. |
| 3220 | // See logic in `lowerPtr`. | 3196 | // See logic in `lowerPtr`. |
| 3221 | const error_type = try o.errorIntType(); | 3197 | const error_type = try o.errorIntType(pt); |
| 3222 | if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu)) | 3198 | if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu)) |
| 3223 | return error_type; | 3199 | return error_type; |
| 3224 | const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type)); | 3200 | const payload_type = try o.lowerType(pt, Type.fromInterned(error_union_type.payload_type)); |
| 3225 | const err_int_ty = try o.pt.errorIntType(); | | |
| 3226 | | 3201 | |
| 3227 | const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(zcu); | 3202 | const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(zcu); |
| 3228 | const error_align = err_int_ty.abiAlignment(zcu); | 3203 | const error_align: InternPool.Alignment = .fromByteUnits(std.zig.target.intAlignment(target, zcu.errorSetBits())); |
| 3229 | | 3204 | |
| 3230 | const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(zcu); | 3205 | const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(zcu); |
| 3231 | const error_size = err_int_ty.abiSize(zcu); | 3206 | const error_size = std.zig.target.intByteSize(target, zcu.errorSetBits()); |
| 3232 | | 3207 | |
| 3233 | var fields: [3]Builder.Type = undefined; | 3208 | var fields: [3]Builder.Type = undefined; |
| 3234 | var fields_len: usize = 2; | 3209 | var fields_len: usize = 2; |
| ... | @@ -3262,7 +3237,7 @@ pub const Object = struct { | ... | @@ -3262,7 +3237,7 @@ pub const Object = struct { |
| 3262 | const struct_type = ip.loadStructType(t.toIntern()); | 3237 | const struct_type = ip.loadStructType(t.toIntern()); |
| 3263 | | 3238 | |
| 3264 | if (struct_type.layout == .@"packed") { | 3239 | if (struct_type.layout == .@"packed") { |
| 3265 | const int_ty = try o.lowerType(Type.fromInterned(struct_type.backingIntTypeUnordered(ip))); | 3240 | const int_ty = try o.lowerType(pt, Type.fromInterned(struct_type.backingIntTypeUnordered(ip))); |
| 3266 | try o.type_map.put(o.gpa, t.toIntern(), int_ty); | 3241 | try o.type_map.put(o.gpa, t.toIntern(), int_ty); |
| 3267 | return int_ty; | 3242 | return int_ty; |
| 3268 | } | 3243 | } |
| ... | @@ -3312,7 +3287,7 @@ pub const Object = struct { | ... | @@ -3312,7 +3287,7 @@ pub const Object = struct { |
| 3312 | .struct_ty = t.toIntern(), | 3287 | .struct_ty = t.toIntern(), |
| 3313 | .field_index = field_index, | 3288 | .field_index = field_index, |
| 3314 | }, @intCast(llvm_field_types.items.len)); | 3289 | }, @intCast(llvm_field_types.items.len)); |
| 3315 | try llvm_field_types.append(o.gpa, try o.lowerType(field_ty)); | 3290 | try llvm_field_types.append(o.gpa, try o.lowerType(pt, field_ty)); |
| 3316 | | 3291 | |
| 3317 | offset += field_ty.abiSize(zcu); | 3292 | offset += field_ty.abiSize(zcu); |
| 3318 | } | 3293 | } |
| ... | @@ -3382,7 +3357,7 @@ pub const Object = struct { | ... | @@ -3382,7 +3357,7 @@ pub const Object = struct { |
| 3382 | .struct_ty = t.toIntern(), | 3357 | .struct_ty = t.toIntern(), |
| 3383 | .field_index = @intCast(field_index), | 3358 | .field_index = @intCast(field_index), |
| 3384 | }, @intCast(llvm_field_types.items.len)); | 3359 | }, @intCast(llvm_field_types.items.len)); |
| 3385 | try llvm_field_types.append(o.gpa, try o.lowerType(Type.fromInterned(field_ty))); | 3360 | try llvm_field_types.append(o.gpa, try o.lowerType(pt, Type.fromInterned(field_ty))); |
| 3386 | | 3361 | |
| 3387 | offset += Type.fromInterned(field_ty).abiSize(zcu); | 3362 | offset += Type.fromInterned(field_ty).abiSize(zcu); |
| 3388 | } | 3363 | } |
| ... | @@ -3410,13 +3385,13 @@ pub const Object = struct { | ... | @@ -3410,13 +3385,13 @@ pub const Object = struct { |
| 3410 | } | 3385 | } |
| 3411 | | 3386 | |
| 3412 | if (layout.payload_size == 0) { | 3387 | if (layout.payload_size == 0) { |
| 3413 | const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty)); | 3388 | const enum_tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty)); |
| 3414 | try o.type_map.put(o.gpa, t.toIntern(), enum_tag_ty); | 3389 | try o.type_map.put(o.gpa, t.toIntern(), enum_tag_ty); |
| 3415 | return enum_tag_ty; | 3390 | return enum_tag_ty; |
| 3416 | } | 3391 | } |
| 3417 | | 3392 | |
| 3418 | const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]); | 3393 | const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]); |
| 3419 | const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty); | 3394 | const aligned_field_llvm_ty = try o.lowerType(pt, aligned_field_ty); |
| 3420 | | 3395 | |
| 3421 | const payload_ty = ty: { | 3396 | const payload_ty = ty: { |
| 3422 | if (layout.most_aligned_field_size == layout.payload_size) { | 3397 | if (layout.most_aligned_field_size == layout.payload_size) { |
| ... | @@ -3442,7 +3417,7 @@ pub const Object = struct { | ... | @@ -3442,7 +3417,7 @@ pub const Object = struct { |
| 3442 | ); | 3417 | ); |
| 3443 | return ty; | 3418 | return ty; |
| 3444 | } | 3419 | } |
| 3445 | const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty)); | 3420 | const enum_tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty)); |
| 3446 | | 3421 | |
| 3447 | // Put the tag before or after the payload depending on which one's | 3422 | // Put the tag before or after the payload depending on which one's |
| 3448 | // alignment is greater. | 3423 | // alignment is greater. |
| ... | @@ -3477,9 +3452,9 @@ pub const Object = struct { | ... | @@ -3477,9 +3452,9 @@ pub const Object = struct { |
| 3477 | } | 3452 | } |
| 3478 | return gop.value_ptr.*; | 3453 | return gop.value_ptr.*; |
| 3479 | }, | 3454 | }, |
| 3480 | .enum_type => try o.lowerType(Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)), | 3455 | .enum_type => try o.lowerType(pt, Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)), |
| 3481 | .func_type => |func_type| try o.lowerTypeFn(func_type), | 3456 | .func_type => |func_type| try o.lowerTypeFn(pt, func_type), |
| 3482 | .error_set_type, .inferred_error_set_type => try o.errorIntType(), | 3457 | .error_set_type, .inferred_error_set_type => try o.errorIntType(pt), |
| 3483 | // values, not types | 3458 | // values, not types |
| 3484 | .undef, | 3459 | .undef, |
| 3485 | .simple_value, | 3460 | .simple_value, |
| ... | @@ -3508,8 +3483,7 @@ pub const Object = struct { | ... | @@ -3508,8 +3483,7 @@ pub const Object = struct { |
| 3508 | /// Use this instead of lowerType when you want to handle correctly the case of elem_ty | 3483 | /// 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. | 3484 | /// 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. | 3485 | /// There are other similar cases handled here as well. |
| 3511 | fn lowerPtrElemTy(o: *Object, elem_ty: Type) Allocator.Error!Builder.Type { | 3486 | fn lowerPtrElemTy(o: *Object, pt: Zcu.PerThread, elem_ty: Type) Allocator.Error!Builder.Type { |
| 3512 | const pt = o.pt; | | |
| 3513 | const zcu = pt.zcu; | 3487 | const zcu = pt.zcu; |
| 3514 | const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) { | 3488 | const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) { |
| 3515 | .@"opaque" => true, | 3489 | .@"opaque" => true, |
| ... | @@ -3517,15 +3491,14 @@ pub const Object = struct { | ... | @@ -3517,15 +3491,14 @@ pub const Object = struct { |
| 3517 | .array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu), | 3491 | .array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu), |
| 3518 | else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu), | 3492 | else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu), |
| 3519 | }; | 3493 | }; |
| 3520 | return if (lower_elem_ty) try o.lowerType(elem_ty) else .i8; | 3494 | return if (lower_elem_ty) try o.lowerType(pt, elem_ty) else .i8; |
| 3521 | } | 3495 | } |
| 3522 | | 3496 | |
| 3523 | fn lowerTypeFn(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { | 3497 | 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; | 3498 | const zcu = pt.zcu; |
| 3526 | const ip = &zcu.intern_pool; | 3499 | const ip = &zcu.intern_pool; |
| 3527 | const target = zcu.getTarget(); | 3500 | const target = zcu.getTarget(); |
| 3528 | const ret_ty = try lowerFnRetTy(o, fn_info); | 3501 | const ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 3529 | | 3502 | |
| 3530 | var llvm_params: std.ArrayListUnmanaged(Builder.Type) = .empty; | 3503 | var llvm_params: std.ArrayListUnmanaged(Builder.Type) = .empty; |
| 3531 | defer llvm_params.deinit(o.gpa); | 3504 | defer llvm_params.deinit(o.gpa); |
| ... | @@ -3535,16 +3508,16 @@ pub const Object = struct { | ... | @@ -3535,16 +3508,16 @@ pub const Object = struct { |
| 3535 | } | 3508 | } |
| 3536 | | 3509 | |
| 3537 | if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) { | 3510 | if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) { |
| 3538 | const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType()); | 3511 | const ptr_ty = try pt.ptrType(.{ .child = zcu.stack_trace_type }); |
| 3539 | try llvm_params.append(o.gpa, try o.lowerType(ptr_ty)); | 3512 | try llvm_params.append(o.gpa, try o.lowerType(pt, ptr_ty)); |
| 3540 | } | 3513 | } |
| 3541 | | 3514 | |
| 3542 | var it = iterateParamTypes(o, fn_info); | 3515 | var it = iterateParamTypes(o, pt, fn_info); |
| 3543 | while (try it.next()) |lowering| switch (lowering) { | 3516 | while (try it.next()) |lowering| switch (lowering) { |
| 3544 | .no_bits => continue, | 3517 | .no_bits => continue, |
| 3545 | .byval => { | 3518 | .byval => { |
| 3546 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); | 3519 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); |
| 3547 | try llvm_params.append(o.gpa, try o.lowerType(param_ty)); | 3520 | try llvm_params.append(o.gpa, try o.lowerType(pt, param_ty)); |
| 3548 | }, | 3521 | }, |
| 3549 | .byref, .byref_mut => { | 3522 | .byref, .byref_mut => { |
| 3550 | try llvm_params.append(o.gpa, .ptr); | 3523 | try llvm_params.append(o.gpa, .ptr); |
| ... | @@ -3559,7 +3532,7 @@ pub const Object = struct { | ... | @@ -3559,7 +3532,7 @@ pub const Object = struct { |
| 3559 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); | 3532 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); |
| 3560 | try llvm_params.appendSlice(o.gpa, &.{ | 3533 | try llvm_params.appendSlice(o.gpa, &.{ |
| 3561 | try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(zcu), target)), | 3534 | try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(zcu), target)), |
| 3562 | try o.lowerType(Type.usize), | 3535 | try o.lowerType(pt, Type.usize), |
| 3563 | }); | 3536 | }); |
| 3564 | }, | 3537 | }, |
| 3565 | .multiple_llvm_types => { | 3538 | .multiple_llvm_types => { |
| ... | @@ -3567,7 +3540,7 @@ pub const Object = struct { | ... | @@ -3567,7 +3540,7 @@ pub const Object = struct { |
| 3567 | }, | 3540 | }, |
| 3568 | .float_array => |count| { | 3541 | .float_array => |count| { |
| 3569 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); | 3542 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); |
| 3570 | const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, zcu).?); | 3543 | const float_ty = try o.lowerType(pt, aarch64_c_abi.getFloatArrayType(param_ty, zcu).?); |
| 3571 | try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty)); | 3544 | try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty)); |
| 3572 | }, | 3545 | }, |
| 3573 | .i32_array, .i64_array => |arr_len| { | 3546 | .i32_array, .i64_array => |arr_len| { |
| ... | @@ -3586,8 +3559,7 @@ pub const Object = struct { | ... | @@ -3586,8 +3559,7 @@ pub const Object = struct { |
| 3586 | ); | 3559 | ); |
| 3587 | } | 3560 | } |
| 3588 | | 3561 | |
| 3589 | fn lowerValueToInt(o: *Object, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant { | 3562 | 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; | 3563 | const zcu = pt.zcu; |
| 3592 | const ip = &zcu.intern_pool; | 3564 | const ip = &zcu.intern_pool; |
| 3593 | const target = zcu.getTarget(); | 3565 | const target = zcu.getTarget(); |
| ... | @@ -3600,23 +3572,23 @@ pub const Object = struct { | ... | @@ -3600,23 +3572,23 @@ pub const Object = struct { |
| 3600 | const ty = Type.fromInterned(val_key.typeOf()); | 3572 | const ty = Type.fromInterned(val_key.typeOf()); |
| 3601 | switch (val_key) { | 3573 | switch (val_key) { |
| 3602 | .@"extern" => |@"extern"| { | 3574 | .@"extern" => |@"extern"| { |
| 3603 | const function_index = try o.resolveLlvmFunction(@"extern".owner_nav); | 3575 | const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav); |
| 3604 | const ptr = function_index.ptrConst(&o.builder).global.toConst(); | 3576 | const ptr = function_index.ptrConst(&o.builder).global.toConst(); |
| 3605 | return o.builder.convConst(ptr, llvm_int_ty); | 3577 | return o.builder.convConst(ptr, llvm_int_ty); |
| 3606 | }, | 3578 | }, |
| 3607 | .func => |func| { | 3579 | .func => |func| { |
| 3608 | const function_index = try o.resolveLlvmFunction(func.owner_nav); | 3580 | const function_index = try o.resolveLlvmFunction(pt, func.owner_nav); |
| 3609 | const ptr = function_index.ptrConst(&o.builder).global.toConst(); | 3581 | const ptr = function_index.ptrConst(&o.builder).global.toConst(); |
| 3610 | return o.builder.convConst(ptr, llvm_int_ty); | 3582 | return o.builder.convConst(ptr, llvm_int_ty); |
| 3611 | }, | 3583 | }, |
| 3612 | .ptr => return o.builder.convConst(try o.lowerPtr(arg_val, 0), llvm_int_ty), | 3584 | .ptr => return o.builder.convConst(try o.lowerPtr(pt, arg_val, 0), llvm_int_ty), |
| 3613 | .aggregate => switch (ip.indexToKey(ty.toIntern())) { | 3585 | .aggregate => switch (ip.indexToKey(ty.toIntern())) { |
| 3614 | .struct_type, .vector_type => {}, | 3586 | .struct_type, .vector_type => {}, |
| 3615 | else => unreachable, | 3587 | else => unreachable, |
| 3616 | }, | 3588 | }, |
| 3617 | .un => |un| { | 3589 | .un => |un| { |
| 3618 | const layout = ty.unionGetLayout(zcu); | 3590 | const layout = ty.unionGetLayout(zcu); |
| 3619 | if (layout.payload_size == 0) return o.lowerValue(un.tag); | 3591 | if (layout.payload_size == 0) return o.lowerValue(pt, un.tag); |
| 3620 | | 3592 | |
| 3621 | const union_obj = zcu.typeToUnion(ty).?; | 3593 | const union_obj = zcu.typeToUnion(ty).?; |
| 3622 | const container_layout = union_obj.flagsUnordered(ip).layout; | 3594 | const container_layout = union_obj.flagsUnordered(ip).layout; |
| ... | @@ -3626,7 +3598,7 @@ pub const Object = struct { | ... | @@ -3626,7 +3598,7 @@ pub const Object = struct { |
| 3626 | var need_unnamed = false; | 3598 | var need_unnamed = false; |
| 3627 | if (un.tag == .none) { | 3599 | if (un.tag == .none) { |
| 3628 | assert(layout.tag_size == 0); | 3600 | assert(layout.tag_size == 0); |
| 3629 | const union_val = try o.lowerValueToInt(llvm_int_ty, un.val); | 3601 | const union_val = try o.lowerValueToInt(pt, llvm_int_ty, un.val); |
| 3630 | | 3602 | |
| 3631 | need_unnamed = true; | 3603 | need_unnamed = true; |
| 3632 | return union_val; | 3604 | return union_val; |
| ... | @@ -3634,7 +3606,7 @@ pub const Object = struct { | ... | @@ -3634,7 +3606,7 @@ pub const Object = struct { |
| 3634 | const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?; | 3606 | 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]); | 3607 | 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); | 3608 | if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(llvm_int_ty, 0); |
| 3637 | return o.lowerValueToInt(llvm_int_ty, un.val); | 3609 | return o.lowerValueToInt(pt, llvm_int_ty, un.val); |
| 3638 | }, | 3610 | }, |
| 3639 | .simple_value => |simple_value| switch (simple_value) { | 3611 | .simple_value => |simple_value| switch (simple_value) { |
| 3640 | .false, .true => {}, | 3612 | .false, .true => {}, |
| ... | @@ -3678,8 +3650,7 @@ pub const Object = struct { | ... | @@ -3678,8 +3650,7 @@ pub const Object = struct { |
| 3678 | }); | 3650 | }); |
| 3679 | } | 3651 | } |
| 3680 | | 3652 | |
| 3681 | fn lowerValue(o: *Object, arg_val: InternPool.Index) Error!Builder.Constant { | 3653 | fn lowerValue(o: *Object, pt: Zcu.PerThread, arg_val: InternPool.Index) Error!Builder.Constant { |
| 3682 | const pt = o.pt; | | |
| 3683 | const zcu = pt.zcu; | 3654 | const zcu = pt.zcu; |
| 3684 | const ip = &zcu.intern_pool; | 3655 | const ip = &zcu.intern_pool; |
| 3685 | const target = zcu.getTarget(); | 3656 | const target = zcu.getTarget(); |
| ... | @@ -3688,7 +3659,7 @@ pub const Object = struct { | ... | @@ -3688,7 +3659,7 @@ pub const Object = struct { |
| 3688 | const val_key = ip.indexToKey(val.toIntern()); | 3659 | const val_key = ip.indexToKey(val.toIntern()); |
| 3689 | | 3660 | |
| 3690 | if (val.isUndefDeep(zcu)) { | 3661 | if (val.isUndefDeep(zcu)) { |
| 3691 | return o.builder.undefConst(try o.lowerType(Type.fromInterned(val_key.typeOf()))); | 3662 | return o.builder.undefConst(try o.lowerType(pt, Type.fromInterned(val_key.typeOf()))); |
| 3692 | } | 3663 | } |
| 3693 | | 3664 | |
| 3694 | const ty = Type.fromInterned(val_key.typeOf()); | 3665 | const ty = Type.fromInterned(val_key.typeOf()); |
| ... | @@ -3727,21 +3698,21 @@ pub const Object = struct { | ... | @@ -3727,21 +3698,21 @@ pub const Object = struct { |
| 3727 | .empty_enum_value, | 3698 | .empty_enum_value, |
| 3728 | => unreachable, // non-runtime values | 3699 | => unreachable, // non-runtime values |
| 3729 | .@"extern" => |@"extern"| { | 3700 | .@"extern" => |@"extern"| { |
| 3730 | const function_index = try o.resolveLlvmFunction(@"extern".owner_nav); | 3701 | const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav); |
| 3731 | return function_index.ptrConst(&o.builder).global.toConst(); | 3702 | return function_index.ptrConst(&o.builder).global.toConst(); |
| 3732 | }, | 3703 | }, |
| 3733 | .func => |func| { | 3704 | .func => |func| { |
| 3734 | const function_index = try o.resolveLlvmFunction(func.owner_nav); | 3705 | const function_index = try o.resolveLlvmFunction(pt, func.owner_nav); |
| 3735 | return function_index.ptrConst(&o.builder).global.toConst(); | 3706 | return function_index.ptrConst(&o.builder).global.toConst(); |
| 3736 | }, | 3707 | }, |
| 3737 | .int => { | 3708 | .int => { |
| 3738 | var bigint_space: Value.BigIntSpace = undefined; | 3709 | var bigint_space: Value.BigIntSpace = undefined; |
| 3739 | const bigint = val.toBigInt(&bigint_space, zcu); | 3710 | const bigint = val.toBigInt(&bigint_space, zcu); |
| 3740 | return lowerBigInt(o, ty, bigint); | 3711 | return lowerBigInt(o, pt, ty, bigint); |
| 3741 | }, | 3712 | }, |
| 3742 | .err => |err| { | 3713 | .err => |err| { |
| 3743 | const int = try pt.getErrorValue(err.name); | 3714 | const int = try pt.getErrorValue(err.name); |
| 3744 | const llvm_int = try o.builder.intConst(try o.errorIntType(), int); | 3715 | const llvm_int = try o.builder.intConst(try o.errorIntType(pt), int); |
| 3745 | return llvm_int; | 3716 | return llvm_int; |
| 3746 | }, | 3717 | }, |
| 3747 | .error_union => |error_union| { | 3718 | .error_union => |error_union| { |
| ... | @@ -3756,13 +3727,13 @@ pub const Object = struct { | ... | @@ -3756,13 +3727,13 @@ pub const Object = struct { |
| 3756 | const payload_type = ty.errorUnionPayload(zcu); | 3727 | const payload_type = ty.errorUnionPayload(zcu); |
| 3757 | if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) { | 3728 | if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 3758 | // We use the error type directly as the type. | 3729 | // We use the error type directly as the type. |
| 3759 | return o.lowerValue(err_val); | 3730 | return o.lowerValue(pt, err_val); |
| 3760 | } | 3731 | } |
| 3761 | | 3732 | |
| 3762 | const payload_align = payload_type.abiAlignment(zcu); | 3733 | const payload_align = payload_type.abiAlignment(zcu); |
| 3763 | const error_align = err_int_ty.abiAlignment(zcu); | 3734 | const error_align = err_int_ty.abiAlignment(zcu); |
| 3764 | const llvm_error_value = try o.lowerValue(err_val); | 3735 | const llvm_error_value = try o.lowerValue(pt, err_val); |
| 3765 | const llvm_payload_value = try o.lowerValue(switch (error_union.val) { | 3736 | const llvm_payload_value = try o.lowerValue(pt, switch (error_union.val) { |
| 3766 | .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }), | 3737 | .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }), |
| 3767 | .payload => |payload| payload, | 3738 | .payload => |payload| payload, |
| 3768 | }); | 3739 | }); |
| ... | @@ -3779,7 +3750,7 @@ pub const Object = struct { | ... | @@ -3779,7 +3750,7 @@ pub const Object = struct { |
| 3779 | fields[0] = vals[0].typeOf(&o.builder); | 3750 | fields[0] = vals[0].typeOf(&o.builder); |
| 3780 | fields[1] = vals[1].typeOf(&o.builder); | 3751 | fields[1] = vals[1].typeOf(&o.builder); |
| 3781 | | 3752 | |
| 3782 | const llvm_ty = try o.lowerType(ty); | 3753 | const llvm_ty = try o.lowerType(pt, ty); |
| 3783 | const llvm_ty_fields = llvm_ty.structFields(&o.builder); | 3754 | const llvm_ty_fields = llvm_ty.structFields(&o.builder); |
| 3784 | if (llvm_ty_fields.len > 2) { | 3755 | if (llvm_ty_fields.len > 2) { |
| 3785 | assert(llvm_ty_fields.len == 3); | 3756 | assert(llvm_ty_fields.len == 3); |
| ... | @@ -3791,7 +3762,7 @@ pub const Object = struct { | ... | @@ -3791,7 +3762,7 @@ pub const Object = struct { |
| 3791 | fields[0..llvm_ty_fields.len], | 3762 | fields[0..llvm_ty_fields.len], |
| 3792 | ), vals[0..llvm_ty_fields.len]); | 3763 | ), vals[0..llvm_ty_fields.len]); |
| 3793 | }, | 3764 | }, |
| 3794 | .enum_tag => |enum_tag| o.lowerValue(enum_tag.int), | 3765 | .enum_tag => |enum_tag| o.lowerValue(pt, enum_tag.int), |
| 3795 | .float => switch (ty.floatBits(target)) { | 3766 | .float => switch (ty.floatBits(target)) { |
| 3796 | 16 => if (backendSupportsF16(target)) | 3767 | 16 => if (backendSupportsF16(target)) |
| 3797 | try o.builder.halfConst(val.toFloat(f16, zcu)) | 3768 | try o.builder.halfConst(val.toFloat(f16, zcu)) |
| ... | @@ -3806,10 +3777,10 @@ pub const Object = struct { | ... | @@ -3806,10 +3777,10 @@ pub const Object = struct { |
| 3806 | 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)), | 3777 | 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)), |
| 3807 | else => unreachable, | 3778 | else => unreachable, |
| 3808 | }, | 3779 | }, |
| 3809 | .ptr => try o.lowerPtr(arg_val, 0), | 3780 | .ptr => try o.lowerPtr(pt, arg_val, 0), |
| 3810 | .slice => |slice| return o.builder.structConst(try o.lowerType(ty), &.{ | 3781 | .slice => |slice| return o.builder.structConst(try o.lowerType(pt, ty), &.{ |
| 3811 | try o.lowerValue(slice.ptr), | 3782 | try o.lowerValue(pt, slice.ptr), |
| 3812 | try o.lowerValue(slice.len), | 3783 | try o.lowerValue(pt, slice.len), |
| 3813 | }), | 3784 | }), |
| 3814 | .opt => |opt| { | 3785 | .opt => |opt| { |
| 3815 | comptime assert(optional_layout_version == 3); | 3786 | comptime assert(optional_layout_version == 3); |
| ... | @@ -3819,7 +3790,7 @@ pub const Object = struct { | ... | @@ -3819,7 +3790,7 @@ pub const Object = struct { |
| 3819 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { | 3790 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 3820 | return non_null_bit; | 3791 | return non_null_bit; |
| 3821 | } | 3792 | } |
| 3822 | const llvm_ty = try o.lowerType(ty); | 3793 | const llvm_ty = try o.lowerType(pt, ty); |
| 3823 | if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) { | 3794 | if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) { |
| 3824 | .none => switch (llvm_ty.tag(&o.builder)) { | 3795 | .none => switch (llvm_ty.tag(&o.builder)) { |
| 3825 | .integer => try o.builder.intConst(llvm_ty, 0), | 3796 | .integer => try o.builder.intConst(llvm_ty, 0), |
| ... | @@ -3827,13 +3798,13 @@ pub const Object = struct { | ... | @@ -3827,13 +3798,13 @@ pub const Object = struct { |
| 3827 | .structure => try o.builder.zeroInitConst(llvm_ty), | 3798 | .structure => try o.builder.zeroInitConst(llvm_ty), |
| 3828 | else => unreachable, | 3799 | else => unreachable, |
| 3829 | }, | 3800 | }, |
| 3830 | else => |payload| try o.lowerValue(payload), | 3801 | else => |payload| try o.lowerValue(pt, payload), |
| 3831 | }; | 3802 | }; |
| 3832 | assert(payload_ty.zigTypeTag(zcu) != .@"fn"); | 3803 | assert(payload_ty.zigTypeTag(zcu) != .@"fn"); |
| 3833 | | 3804 | |
| 3834 | var fields: [3]Builder.Type = undefined; | 3805 | var fields: [3]Builder.Type = undefined; |
| 3835 | var vals: [3]Builder.Constant = undefined; | 3806 | var vals: [3]Builder.Constant = undefined; |
| 3836 | vals[0] = try o.lowerValue(switch (opt.val) { | 3807 | vals[0] = try o.lowerValue(pt, switch (opt.val) { |
| 3837 | .none => try pt.intern(.{ .undef = payload_ty.toIntern() }), | 3808 | .none => try pt.intern(.{ .undef = payload_ty.toIntern() }), |
| 3838 | else => |payload| payload, | 3809 | else => |payload| payload, |
| 3839 | }); | 3810 | }); |
| ... | @@ -3858,7 +3829,7 @@ pub const Object = struct { | ... | @@ -3858,7 +3829,7 @@ pub const Object = struct { |
| 3858 | bytes.toSlice(array_type.lenIncludingSentinel(), ip), | 3829 | bytes.toSlice(array_type.lenIncludingSentinel(), ip), |
| 3859 | )), | 3830 | )), |
| 3860 | .elems => |elems| { | 3831 | .elems => |elems| { |
| 3861 | const array_ty = try o.lowerType(ty); | 3832 | const array_ty = try o.lowerType(pt, ty); |
| 3862 | const elem_ty = array_ty.childType(&o.builder); | 3833 | const elem_ty = array_ty.childType(&o.builder); |
| 3863 | assert(elems.len == array_ty.aggregateLen(&o.builder)); | 3834 | assert(elems.len == array_ty.aggregateLen(&o.builder)); |
| 3864 | | 3835 | |
| ... | @@ -3878,7 +3849,7 @@ pub const Object = struct { | ... | @@ -3878,7 +3849,7 @@ pub const Object = struct { |
| 3878 | | 3849 | |
| 3879 | var need_unnamed = false; | 3850 | var need_unnamed = false; |
| 3880 | for (vals, fields, elems) |*result_val, *result_field, elem| { | 3851 | for (vals, fields, elems) |*result_val, *result_field, elem| { |
| 3881 | result_val.* = try o.lowerValue(elem); | 3852 | result_val.* = try o.lowerValue(pt, elem); |
| 3882 | result_field.* = result_val.typeOf(&o.builder); | 3853 | result_field.* = result_val.typeOf(&o.builder); |
| 3883 | if (result_field.* != elem_ty) need_unnamed = true; | 3854 | if (result_field.* != elem_ty) need_unnamed = true; |
| 3884 | } | 3855 | } |
| ... | @@ -3890,7 +3861,7 @@ pub const Object = struct { | ... | @@ -3890,7 +3861,7 @@ pub const Object = struct { |
| 3890 | .repeated_elem => |elem| { | 3861 | .repeated_elem => |elem| { |
| 3891 | const len: usize = @intCast(array_type.len); | 3862 | const len: usize = @intCast(array_type.len); |
| 3892 | const len_including_sentinel: usize = @intCast(array_type.lenIncludingSentinel()); | 3863 | const len_including_sentinel: usize = @intCast(array_type.lenIncludingSentinel()); |
| 3893 | const array_ty = try o.lowerType(ty); | 3864 | const array_ty = try o.lowerType(pt, ty); |
| 3894 | const elem_ty = array_ty.childType(&o.builder); | 3865 | const elem_ty = array_ty.childType(&o.builder); |
| 3895 | | 3866 | |
| 3896 | const ExpectedContents = extern struct { | 3867 | const ExpectedContents = extern struct { |
| ... | @@ -3908,12 +3879,12 @@ pub const Object = struct { | ... | @@ -3908,12 +3879,12 @@ pub const Object = struct { |
| 3908 | defer allocator.free(fields); | 3879 | defer allocator.free(fields); |
| 3909 | | 3880 | |
| 3910 | var need_unnamed = false; | 3881 | var need_unnamed = false; |
| 3911 | @memset(vals[0..len], try o.lowerValue(elem)); | 3882 | @memset(vals[0..len], try o.lowerValue(pt, elem)); |
| 3912 | @memset(fields[0..len], vals[0].typeOf(&o.builder)); | 3883 | @memset(fields[0..len], vals[0].typeOf(&o.builder)); |
| 3913 | if (fields[0] != elem_ty) need_unnamed = true; | 3884 | if (fields[0] != elem_ty) need_unnamed = true; |
| 3914 | | 3885 | |
| 3915 | if (array_type.sentinel != .none) { | 3886 | if (array_type.sentinel != .none) { |
| 3916 | vals[len] = try o.lowerValue(array_type.sentinel); | 3887 | vals[len] = try o.lowerValue(pt, array_type.sentinel); |
| 3917 | fields[len] = vals[len].typeOf(&o.builder); | 3888 | fields[len] = vals[len].typeOf(&o.builder); |
| 3918 | if (fields[len] != elem_ty) need_unnamed = true; | 3889 | if (fields[len] != elem_ty) need_unnamed = true; |
| 3919 | } | 3890 | } |
| ... | @@ -3925,7 +3896,7 @@ pub const Object = struct { | ... | @@ -3925,7 +3896,7 @@ pub const Object = struct { |
| 3925 | }, | 3896 | }, |
| 3926 | }, | 3897 | }, |
| 3927 | .vector_type => |vector_type| { | 3898 | .vector_type => |vector_type| { |
| 3928 | const vector_ty = try o.lowerType(ty); | 3899 | const vector_ty = try o.lowerType(pt, ty); |
| 3929 | switch (aggregate.storage) { | 3900 | switch (aggregate.storage) { |
| 3930 | .bytes, .elems => { | 3901 | .bytes, .elems => { |
| 3931 | const ExpectedContents = [Builder.expected_fields_len]Builder.Constant; | 3902 | const ExpectedContents = [Builder.expected_fields_len]Builder.Constant; |
| ... | @@ -3942,7 +3913,7 @@ pub const Object = struct { | ... | @@ -3942,7 +3913,7 @@ pub const Object = struct { |
| 3942 | result_val.* = try o.builder.intConst(.i8, byte); | 3913 | result_val.* = try o.builder.intConst(.i8, byte); |
| 3943 | }, | 3914 | }, |
| 3944 | .elems => |elems| for (vals, elems) |*result_val, elem| { | 3915 | .elems => |elems| for (vals, elems) |*result_val, elem| { |
| 3945 | result_val.* = try o.lowerValue(elem); | 3916 | result_val.* = try o.lowerValue(pt, elem); |
| 3946 | }, | 3917 | }, |
| 3947 | .repeated_elem => unreachable, | 3918 | .repeated_elem => unreachable, |
| 3948 | } | 3919 | } |
| ... | @@ -3950,12 +3921,12 @@ pub const Object = struct { | ... | @@ -3950,12 +3921,12 @@ pub const Object = struct { |
| 3950 | }, | 3921 | }, |
| 3951 | .repeated_elem => |elem| return o.builder.splatConst( | 3922 | .repeated_elem => |elem| return o.builder.splatConst( |
| 3952 | vector_ty, | 3923 | vector_ty, |
| 3953 | try o.lowerValue(elem), | 3924 | try o.lowerValue(pt, elem), |
| 3954 | ), | 3925 | ), |
| 3955 | } | 3926 | } |
| 3956 | }, | 3927 | }, |
| 3957 | .tuple_type => |tuple| { | 3928 | .tuple_type => |tuple| { |
| 3958 | const struct_ty = try o.lowerType(ty); | 3929 | const struct_ty = try o.lowerType(pt, ty); |
| 3959 | const llvm_len = struct_ty.aggregateLen(&o.builder); | 3930 | const llvm_len = struct_ty.aggregateLen(&o.builder); |
| 3960 | | 3931 | |
| 3961 | const ExpectedContents = extern struct { | 3932 | const ExpectedContents = extern struct { |
| ... | @@ -4001,7 +3972,7 @@ pub const Object = struct { | ... | @@ -4001,7 +3972,7 @@ pub const Object = struct { |
| 4001 | } | 3972 | } |
| 4002 | | 3973 | |
| 4003 | vals[llvm_index] = | 3974 | vals[llvm_index] = |
| 4004 | try o.lowerValue((try val.fieldValue(pt, field_index)).toIntern()); | 3975 | try o.lowerValue(pt, (try val.fieldValue(pt, field_index)).toIntern()); |
| 4005 | fields[llvm_index] = vals[llvm_index].typeOf(&o.builder); | 3976 | fields[llvm_index] = vals[llvm_index].typeOf(&o.builder); |
| 4006 | if (fields[llvm_index] != struct_ty.structFields(&o.builder)[llvm_index]) | 3977 | if (fields[llvm_index] != struct_ty.structFields(&o.builder)[llvm_index]) |
| 4007 | need_unnamed = true; | 3978 | need_unnamed = true; |
| ... | @@ -4030,14 +4001,14 @@ pub const Object = struct { | ... | @@ -4030,14 +4001,14 @@ pub const Object = struct { |
| 4030 | .struct_type => { | 4001 | .struct_type => { |
| 4031 | const struct_type = ip.loadStructType(ty.toIntern()); | 4002 | const struct_type = ip.loadStructType(ty.toIntern()); |
| 4032 | assert(struct_type.haveLayout(ip)); | 4003 | assert(struct_type.haveLayout(ip)); |
| 4033 | const struct_ty = try o.lowerType(ty); | 4004 | const struct_ty = try o.lowerType(pt, ty); |
| 4034 | if (struct_type.layout == .@"packed") { | 4005 | if (struct_type.layout == .@"packed") { |
| 4035 | comptime assert(Type.packed_struct_layout_version == 2); | 4006 | comptime assert(Type.packed_struct_layout_version == 2); |
| 4036 | | 4007 | |
| 4037 | const bits = ty.bitSize(zcu); | 4008 | const bits = ty.bitSize(zcu); |
| 4038 | const llvm_int_ty = try o.builder.intType(@intCast(bits)); | 4009 | const llvm_int_ty = try o.builder.intType(@intCast(bits)); |
| 4039 | | 4010 | |
| 4040 | return o.lowerValueToInt(llvm_int_ty, arg_val); | 4011 | return o.lowerValueToInt(pt, llvm_int_ty, arg_val); |
| 4041 | } | 4012 | } |
| 4042 | const llvm_len = struct_ty.aggregateLen(&o.builder); | 4013 | const llvm_len = struct_ty.aggregateLen(&o.builder); |
| 4043 | | 4014 | |
| ... | @@ -4085,6 +4056,7 @@ pub const Object = struct { | ... | @@ -4085,6 +4056,7 @@ pub const Object = struct { |
| 4085 | } | 4056 | } |
| 4086 | | 4057 | |
| 4087 | vals[llvm_index] = try o.lowerValue( | 4058 | vals[llvm_index] = try o.lowerValue( |
| | 4059 | pt, |
| 4088 | (try val.fieldValue(pt, field_index)).toIntern(), | 4060 | (try val.fieldValue(pt, field_index)).toIntern(), |
| 4089 | ); | 4061 | ); |
| 4090 | fields[llvm_index] = vals[llvm_index].typeOf(&o.builder); | 4062 | fields[llvm_index] = vals[llvm_index].typeOf(&o.builder); |
| ... | @@ -4115,9 +4087,9 @@ pub const Object = struct { | ... | @@ -4115,9 +4087,9 @@ pub const Object = struct { |
| 4115 | else => unreachable, | 4087 | else => unreachable, |
| 4116 | }, | 4088 | }, |
| 4117 | .un => |un| { | 4089 | .un => |un| { |
| 4118 | const union_ty = try o.lowerType(ty); | 4090 | const union_ty = try o.lowerType(pt, ty); |
| 4119 | const layout = ty.unionGetLayout(zcu); | 4091 | const layout = ty.unionGetLayout(zcu); |
| 4120 | if (layout.payload_size == 0) return o.lowerValue(un.tag); | 4092 | if (layout.payload_size == 0) return o.lowerValue(pt, un.tag); |
| 4121 | | 4093 | |
| 4122 | const union_obj = zcu.typeToUnion(ty).?; | 4094 | const union_obj = zcu.typeToUnion(ty).?; |
| 4123 | const container_layout = union_obj.flagsUnordered(ip).layout; | 4095 | const container_layout = union_obj.flagsUnordered(ip).layout; |
| ... | @@ -4131,7 +4103,7 @@ pub const Object = struct { | ... | @@ -4131,7 +4103,7 @@ pub const Object = struct { |
| 4131 | const bits = ty.bitSize(zcu); | 4103 | const bits = ty.bitSize(zcu); |
| 4132 | const llvm_int_ty = try o.builder.intType(@intCast(bits)); | 4104 | const llvm_int_ty = try o.builder.intType(@intCast(bits)); |
| 4133 | | 4105 | |
| 4134 | return o.lowerValueToInt(llvm_int_ty, arg_val); | 4106 | return o.lowerValueToInt(pt, llvm_int_ty, arg_val); |
| 4135 | } | 4107 | } |
| 4136 | | 4108 | |
| 4137 | // Sometimes we must make an unnamed struct because LLVM does | 4109 | // Sometimes we must make an unnamed struct because LLVM does |
| ... | @@ -4144,7 +4116,7 @@ pub const Object = struct { | ... | @@ -4144,7 +4116,7 @@ pub const Object = struct { |
| 4144 | const padding_len = layout.payload_size; | 4116 | const padding_len = layout.payload_size; |
| 4145 | break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8)); | 4117 | break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8)); |
| 4146 | } | 4118 | } |
| 4147 | const payload = try o.lowerValue(un.val); | 4119 | const payload = try o.lowerValue(pt, un.val); |
| 4148 | const payload_ty = payload.typeOf(&o.builder); | 4120 | const payload_ty = payload.typeOf(&o.builder); |
| 4149 | if (payload_ty != union_ty.structFields(&o.builder)[ | 4121 | if (payload_ty != union_ty.structFields(&o.builder)[ |
| 4150 | @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)) | 4122 | @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)) |
| ... | @@ -4163,10 +4135,10 @@ pub const Object = struct { | ... | @@ -4163,10 +4135,10 @@ pub const Object = struct { |
| 4163 | const bits = ty.bitSize(zcu); | 4135 | const bits = ty.bitSize(zcu); |
| 4164 | const llvm_int_ty = try o.builder.intType(@intCast(bits)); | 4136 | const llvm_int_ty = try o.builder.intType(@intCast(bits)); |
| 4165 | | 4137 | |
| 4166 | return o.lowerValueToInt(llvm_int_ty, arg_val); | 4138 | return o.lowerValueToInt(pt, llvm_int_ty, arg_val); |
| 4167 | } | 4139 | } |
| 4168 | | 4140 | |
| 4169 | const union_val = try o.lowerValue(un.val); | 4141 | const union_val = try o.lowerValue(pt, un.val); |
| 4170 | need_unnamed = true; | 4142 | need_unnamed = true; |
| 4171 | break :p union_val; | 4143 | break :p union_val; |
| 4172 | }; | 4144 | }; |
| ... | @@ -4176,7 +4148,7 @@ pub const Object = struct { | ... | @@ -4176,7 +4148,7 @@ pub const Object = struct { |
| 4176 | try o.builder.structType(union_ty.structKind(&o.builder), &.{payload_ty}) | 4148 | try o.builder.structType(union_ty.structKind(&o.builder), &.{payload_ty}) |
| 4177 | else | 4149 | else |
| 4178 | union_ty, &.{payload}); | 4150 | union_ty, &.{payload}); |
| 4179 | const tag = try o.lowerValue(un.tag); | 4151 | const tag = try o.lowerValue(pt, un.tag); |
| 4180 | const tag_ty = tag.typeOf(&o.builder); | 4152 | const tag_ty = tag.typeOf(&o.builder); |
| 4181 | var fields: [3]Builder.Type = undefined; | 4153 | var fields: [3]Builder.Type = undefined; |
| 4182 | var vals: [3]Builder.Constant = undefined; | 4154 | var vals: [3]Builder.Constant = undefined; |
| ... | @@ -4204,48 +4176,50 @@ pub const Object = struct { | ... | @@ -4204,48 +4176,50 @@ pub const Object = struct { |
| 4204 | | 4176 | |
| 4205 | fn lowerBigInt( | 4177 | fn lowerBigInt( |
| 4206 | o: *Object, | 4178 | o: *Object, |
| | 4179 | pt: Zcu.PerThread, |
| 4207 | ty: Type, | 4180 | ty: Type, |
| 4208 | bigint: std.math.big.int.Const, | 4181 | bigint: std.math.big.int.Const, |
| 4209 | ) Allocator.Error!Builder.Constant { | 4182 | ) Allocator.Error!Builder.Constant { |
| 4210 | const zcu = o.pt.zcu; | 4183 | const zcu = pt.zcu; |
| 4211 | return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint); | 4184 | return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint); |
| 4212 | } | 4185 | } |
| 4213 | | 4186 | |
| 4214 | fn lowerPtr( | 4187 | fn lowerPtr( |
| 4215 | o: *Object, | 4188 | o: *Object, |
| | 4189 | pt: Zcu.PerThread, |
| 4216 | ptr_val: InternPool.Index, | 4190 | ptr_val: InternPool.Index, |
| 4217 | prev_offset: u64, | 4191 | prev_offset: u64, |
| 4218 | ) Error!Builder.Constant { | 4192 | ) Error!Builder.Constant { |
| 4219 | const pt = o.pt; | | |
| 4220 | const zcu = pt.zcu; | 4193 | const zcu = pt.zcu; |
| 4221 | const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr; | 4194 | const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr; |
| 4222 | const offset: u64 = prev_offset + ptr.byte_offset; | 4195 | const offset: u64 = prev_offset + ptr.byte_offset; |
| 4223 | return switch (ptr.base_addr) { | 4196 | return switch (ptr.base_addr) { |
| 4224 | .nav => |nav| { | 4197 | .nav => |nav| { |
| 4225 | const base_ptr = try o.lowerNavRefValue(nav); | 4198 | const base_ptr = try o.lowerNavRefValue(pt, nav); |
| 4226 | return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{ | 4199 | return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{ |
| 4227 | try o.builder.intConst(.i64, offset), | 4200 | try o.builder.intConst(.i64, offset), |
| 4228 | }); | 4201 | }); |
| 4229 | }, | 4202 | }, |
| 4230 | .uav => |uav| { | 4203 | .uav => |uav| { |
| 4231 | const base_ptr = try o.lowerUavRef(uav); | 4204 | const base_ptr = try o.lowerUavRef(pt, uav); |
| 4232 | return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{ | 4205 | return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{ |
| 4233 | try o.builder.intConst(.i64, offset), | 4206 | try o.builder.intConst(.i64, offset), |
| 4234 | }); | 4207 | }); |
| 4235 | }, | 4208 | }, |
| 4236 | .int => try o.builder.castConst( | 4209 | .int => try o.builder.castConst( |
| 4237 | .inttoptr, | 4210 | .inttoptr, |
| 4238 | try o.builder.intConst(try o.lowerType(Type.usize), offset), | 4211 | try o.builder.intConst(try o.lowerType(pt, Type.usize), offset), |
| 4239 | try o.lowerType(Type.fromInterned(ptr.ty)), | 4212 | try o.lowerType(pt, Type.fromInterned(ptr.ty)), |
| 4240 | ), | 4213 | ), |
| 4241 | .eu_payload => |eu_ptr| try o.lowerPtr( | 4214 | .eu_payload => |eu_ptr| try o.lowerPtr( |
| | 4215 | pt, |
| 4242 | eu_ptr, | 4216 | eu_ptr, |
| 4243 | offset + @import("../codegen.zig").errUnionPayloadOffset( | 4217 | offset + @import("../codegen.zig").errUnionPayloadOffset( |
| 4244 | Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu), | 4218 | Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu), |
| 4245 | zcu, | 4219 | zcu, |
| 4246 | ), | 4220 | ), |
| 4247 | ), | 4221 | ), |
| 4248 | .opt_payload => |opt_ptr| try o.lowerPtr(opt_ptr, offset), | 4222 | .opt_payload => |opt_ptr| try o.lowerPtr(pt, opt_ptr, offset), |
| 4249 | .field => |field| { | 4223 | .field => |field| { |
| 4250 | const agg_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu); | 4224 | const agg_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu); |
| 4251 | const field_off: u64 = switch (agg_ty.zigTypeTag(zcu)) { | 4225 | const field_off: u64 = switch (agg_ty.zigTypeTag(zcu)) { |
| ... | @@ -4263,7 +4237,7 @@ pub const Object = struct { | ... | @@ -4263,7 +4237,7 @@ pub const Object = struct { |
| 4263 | }, | 4237 | }, |
| 4264 | else => unreachable, | 4238 | else => unreachable, |
| 4265 | }; | 4239 | }; |
| 4266 | return o.lowerPtr(field.base, offset + field_off); | 4240 | return o.lowerPtr(pt, field.base, offset + field_off); |
| 4267 | }, | 4241 | }, |
| 4268 | .arr_elem, .comptime_field, .comptime_alloc => unreachable, | 4242 | .arr_elem, .comptime_field, .comptime_alloc => unreachable, |
| 4269 | }; | 4243 | }; |
| ... | @@ -4273,9 +4247,9 @@ pub const Object = struct { | ... | @@ -4273,9 +4247,9 @@ pub const Object = struct { |
| 4273 | /// Maybe the logic could be unified. | 4247 | /// Maybe the logic could be unified. |
| 4274 | fn lowerUavRef( | 4248 | fn lowerUavRef( |
| 4275 | o: *Object, | 4249 | o: *Object, |
| | 4250 | pt: Zcu.PerThread, |
| 4276 | uav: InternPool.Key.Ptr.BaseAddr.Uav, | 4251 | uav: InternPool.Key.Ptr.BaseAddr.Uav, |
| 4277 | ) Error!Builder.Constant { | 4252 | ) Error!Builder.Constant { |
| 4278 | const pt = o.pt; | | |
| 4279 | const zcu = pt.zcu; | 4253 | const zcu = pt.zcu; |
| 4280 | const ip = &zcu.intern_pool; | 4254 | const ip = &zcu.intern_pool; |
| 4281 | const uav_val = uav.val; | 4255 | const uav_val = uav.val; |
| ... | @@ -4292,25 +4266,24 @@ pub const Object = struct { | ... | @@ -4292,25 +4266,24 @@ pub const Object = struct { |
| 4292 | | 4266 | |
| 4293 | const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn"; | 4267 | const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn"; |
| 4294 | if ((!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) or | 4268 | if ((!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) or |
| 4295 | (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(ptr_ty); | 4269 | (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(pt, ptr_ty); |
| 4296 | | 4270 | |
| 4297 | if (is_fn_body) | 4271 | if (is_fn_body) |
| 4298 | @panic("TODO"); | 4272 | @panic("TODO"); |
| 4299 | | 4273 | |
| 4300 | const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target); | 4274 | const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target); |
| 4301 | const alignment = ptr_ty.ptrAlignment(zcu); | 4275 | const alignment = ptr_ty.ptrAlignment(zcu); |
| 4302 | const llvm_global = (try o.resolveGlobalUav(uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global; | 4276 | const llvm_global = (try o.resolveGlobalUav(pt, uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global; |
| 4303 | | 4277 | |
| 4304 | const llvm_val = try o.builder.convConst( | 4278 | const llvm_val = try o.builder.convConst( |
| 4305 | llvm_global.toConst(), | 4279 | llvm_global.toConst(), |
| 4306 | try o.builder.ptrType(llvm_addr_space), | 4280 | try o.builder.ptrType(llvm_addr_space), |
| 4307 | ); | 4281 | ); |
| 4308 | | 4282 | |
| 4309 | return o.builder.convConst(llvm_val, try o.lowerType(ptr_ty)); | 4283 | return o.builder.convConst(llvm_val, try o.lowerType(pt, ptr_ty)); |
| 4310 | } | 4284 | } |
| 4311 | | 4285 | |
| 4312 | fn lowerNavRefValue(o: *Object, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant { | 4286 | 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; | 4287 | const zcu = pt.zcu; |
| 4315 | const ip = &zcu.intern_pool; | 4288 | const ip = &zcu.intern_pool; |
| 4316 | | 4289 | |
| ... | @@ -4323,24 +4296,24 @@ pub const Object = struct { | ... | @@ -4323,24 +4296,24 @@ pub const Object = struct { |
| 4323 | if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or | 4296 | if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or |
| 4324 | (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic)) | 4297 | (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic)) |
| 4325 | { | 4298 | { |
| 4326 | return o.lowerPtrToVoid(ptr_ty); | 4299 | return o.lowerPtrToVoid(pt, ptr_ty); |
| 4327 | } | 4300 | } |
| 4328 | | 4301 | |
| 4329 | const llvm_global = if (is_fn_body) | 4302 | const llvm_global = if (is_fn_body) |
| 4330 | (try o.resolveLlvmFunction(nav_index)).ptrConst(&o.builder).global | 4303 | (try o.resolveLlvmFunction(pt, nav_index)).ptrConst(&o.builder).global |
| 4331 | else | 4304 | else |
| 4332 | (try o.resolveGlobalNav(nav_index)).ptrConst(&o.builder).global; | 4305 | (try o.resolveGlobalNav(pt, nav_index)).ptrConst(&o.builder).global; |
| 4333 | | 4306 | |
| 4334 | const llvm_val = try o.builder.convConst( | 4307 | const llvm_val = try o.builder.convConst( |
| 4335 | llvm_global.toConst(), | 4308 | llvm_global.toConst(), |
| 4336 | try o.builder.ptrType(toLlvmAddressSpace(nav.getAddrspace(), zcu.getTarget())), | 4309 | try o.builder.ptrType(toLlvmAddressSpace(nav.getAddrspace(), zcu.getTarget())), |
| 4337 | ); | 4310 | ); |
| 4338 | | 4311 | |
| 4339 | return o.builder.convConst(llvm_val, try o.lowerType(ptr_ty)); | 4312 | return o.builder.convConst(llvm_val, try o.lowerType(pt, ptr_ty)); |
| 4340 | } | 4313 | } |
| 4341 | | 4314 | |
| 4342 | fn lowerPtrToVoid(o: *Object, ptr_ty: Type) Allocator.Error!Builder.Constant { | 4315 | fn lowerPtrToVoid(o: *Object, pt: Zcu.PerThread, ptr_ty: Type) Allocator.Error!Builder.Constant { |
| 4343 | const zcu = o.pt.zcu; | 4316 | const zcu = pt.zcu; |
| 4344 | // Even though we are pointing at something which has zero bits (e.g. `void`), | 4317 | // 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. | 4318 | // Pointers are defined to have bits. So we must return something here. |
| 4346 | // The value cannot be undefined, because we use the `nonnull` annotation | 4319 | // The value cannot be undefined, because we use the `nonnull` annotation |
| ... | @@ -4358,8 +4331,8 @@ pub const Object = struct { | ... | @@ -4358,8 +4331,8 @@ pub const Object = struct { |
| 4358 | 64 => 0xaaaaaaaa_aaaaaaaa, | 4331 | 64 => 0xaaaaaaaa_aaaaaaaa, |
| 4359 | else => unreachable, | 4332 | else => unreachable, |
| 4360 | }; | 4333 | }; |
| 4361 | const llvm_usize = try o.lowerType(Type.usize); | 4334 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 4362 | const llvm_ptr_ty = try o.lowerType(ptr_ty); | 4335 | 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); | 4336 | return o.builder.castConst(.inttoptr, try o.builder.intConst(llvm_usize, int), llvm_ptr_ty); |
| 4364 | } | 4337 | } |
| 4365 | | 4338 | |
| ... | @@ -4367,8 +4340,7 @@ pub const Object = struct { | ... | @@ -4367,8 +4340,7 @@ pub const Object = struct { |
| 4367 | /// widen it before using it and then truncate the result. | 4340 | /// widen it before using it and then truncate the result. |
| 4368 | /// RMW exchange of floating-point values is bitcasted to same-sized integer | 4341 | /// RMW exchange of floating-point values is bitcasted to same-sized integer |
| 4369 | /// types to work around a LLVM deficiency when targeting ARM/AArch64. | 4342 | /// 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 { | 4343 | 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; | 4344 | const zcu = pt.zcu; |
| 4373 | const int_ty = switch (ty.zigTypeTag(zcu)) { | 4345 | const int_ty = switch (ty.zigTypeTag(zcu)) { |
| 4374 | .int => ty, | 4346 | .int => ty, |
| ... | @@ -4390,13 +4362,13 @@ pub const Object = struct { | ... | @@ -4390,13 +4362,13 @@ pub const Object = struct { |
| 4390 | | 4362 | |
| 4391 | fn addByValParamAttrs( | 4363 | fn addByValParamAttrs( |
| 4392 | o: *Object, | 4364 | o: *Object, |
| | 4365 | pt: Zcu.PerThread, |
| 4393 | attributes: *Builder.FunctionAttributes.Wip, | 4366 | attributes: *Builder.FunctionAttributes.Wip, |
| 4394 | param_ty: Type, | 4367 | param_ty: Type, |
| 4395 | param_index: u32, | 4368 | param_index: u32, |
| 4396 | fn_info: InternPool.Key.FuncType, | 4369 | fn_info: InternPool.Key.FuncType, |
| 4397 | llvm_arg_i: u32, | 4370 | llvm_arg_i: u32, |
| 4398 | ) Allocator.Error!void { | 4371 | ) Allocator.Error!void { |
| 4399 | const pt = o.pt; | | |
| 4400 | const zcu = pt.zcu; | 4372 | const zcu = pt.zcu; |
| 4401 | if (param_ty.isPtrAtRuntime(zcu)) { | 4373 | if (param_ty.isPtrAtRuntime(zcu)) { |
| 4402 | const ptr_info = param_ty.ptrInfo(zcu); | 4374 | const ptr_info = param_ty.ptrInfo(zcu); |
| ... | @@ -4416,7 +4388,7 @@ pub const Object = struct { | ... | @@ -4416,7 +4388,7 @@ pub const Object = struct { |
| 4416 | .x86_64_interrupt, | 4388 | .x86_64_interrupt, |
| 4417 | .x86_interrupt, | 4389 | .x86_interrupt, |
| 4418 | => { | 4390 | => { |
| 4419 | const child_type = try lowerType(o, Type.fromInterned(ptr_info.child)); | 4391 | const child_type = try lowerType(o, pt, Type.fromInterned(ptr_info.child)); |
| 4420 | try attributes.addParamAttr(llvm_arg_i, .{ .byval = child_type }, &o.builder); | 4392 | try attributes.addParamAttr(llvm_arg_i, .{ .byval = child_type }, &o.builder); |
| 4421 | }, | 4393 | }, |
| 4422 | } | 4394 | } |
| ... | @@ -4455,14 +4427,14 @@ pub const Object = struct { | ... | @@ -4455,14 +4427,14 @@ pub const Object = struct { |
| 4455 | }); | 4427 | }); |
| 4456 | } | 4428 | } |
| 4457 | | 4429 | |
| 4458 | fn getCmpLtErrorsLenFunction(o: *Object) !Builder.Function.Index { | 4430 | fn getCmpLtErrorsLenFunction(o: *Object, pt: Zcu.PerThread) !Builder.Function.Index { |
| 4459 | const name = try o.builder.strtabString(lt_errors_fn_name); | 4431 | 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; | 4432 | if (o.builder.getGlobal(name)) |llvm_fn| return llvm_fn.ptrConst(&o.builder).kind.function; |
| 4461 | | 4433 | |
| 4462 | const zcu = o.pt.zcu; | 4434 | const zcu = pt.zcu; |
| 4463 | const target = &zcu.root_mod.resolved_target.result; | 4435 | const target = &zcu.root_mod.resolved_target.result; |
| 4464 | const function_index = try o.builder.addFunction( | 4436 | const function_index = try o.builder.addFunction( |
| 4465 | try o.builder.fnType(.i1, &.{try o.errorIntType()}, .normal), | 4437 | try o.builder.fnType(.i1, &.{try o.errorIntType(pt)}, .normal), |
| 4466 | name, | 4438 | name, |
| 4467 | toLlvmAddressSpace(.generic, target), | 4439 | toLlvmAddressSpace(.generic, target), |
| 4468 | ); | 4440 | ); |
| ... | @@ -4477,8 +4449,7 @@ pub const Object = struct { | ... | @@ -4477,8 +4449,7 @@ pub const Object = struct { |
| 4477 | return function_index; | 4449 | return function_index; |
| 4478 | } | 4450 | } |
| 4479 | | 4451 | |
| 4480 | fn getEnumTagNameFunction(o: *Object, enum_ty: Type) !Builder.Function.Index { | 4452 | fn getEnumTagNameFunction(o: *Object, pt: Zcu.PerThread, enum_ty: Type) !Builder.Function.Index { |
| 4481 | const pt = o.pt; | | |
| 4482 | const zcu = pt.zcu; | 4453 | const zcu = pt.zcu; |
| 4483 | const ip = &zcu.intern_pool; | 4454 | const ip = &zcu.intern_pool; |
| 4484 | const enum_type = ip.loadEnumType(enum_ty.toIntern()); | 4455 | const enum_type = ip.loadEnumType(enum_ty.toIntern()); |
| ... | @@ -4487,11 +4458,11 @@ pub const Object = struct { | ... | @@ -4487,11 +4458,11 @@ pub const Object = struct { |
| 4487 | if (gop.found_existing) return gop.value_ptr.ptrConst(&o.builder).kind.function; | 4458 | 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())); | 4459 | errdefer assert(o.enum_tag_name_map.remove(enum_ty.toIntern())); |
| 4489 | | 4460 | |
| 4490 | const usize_ty = try o.lowerType(Type.usize); | 4461 | const usize_ty = try o.lowerType(pt, Type.usize); |
| 4491 | const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0); | 4462 | const ret_ty = try o.lowerType(pt, Type.slice_const_u8_sentinel_0); |
| 4492 | const target = &zcu.root_mod.resolved_target.result; | 4463 | const target = &zcu.root_mod.resolved_target.result; |
| 4493 | const function_index = try o.builder.addFunction( | 4464 | const function_index = try o.builder.addFunction( |
| 4494 | try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal), | 4465 | try o.builder.fnType(ret_ty, &.{try o.lowerType(pt, Type.fromInterned(enum_type.tag_ty))}, .normal), |
| 4495 | try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_type.name.fmt(ip)}), | 4466 | try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_type.name.fmt(ip)}), |
| 4496 | toLlvmAddressSpace(.generic, target), | 4467 | toLlvmAddressSpace(.generic, target), |
| 4497 | ); | 4468 | ); |
| ... | @@ -4536,6 +4507,7 @@ pub const Object = struct { | ... | @@ -4536,6 +4507,7 @@ pub const Object = struct { |
| 4536 | | 4507 | |
| 4537 | const return_block = try wip.block(1, "Name"); | 4508 | const return_block = try wip.block(1, "Name"); |
| 4538 | const this_tag_int_value = try o.lowerValue( | 4509 | const this_tag_int_value = try o.lowerValue( |
| | 4510 | pt, |
| 4539 | (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(), | 4511 | (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(), |
| 4540 | ); | 4512 | ); |
| 4541 | try wip_switch.addCase(this_tag_int_value, return_block, &wip); | 4513 | try wip_switch.addCase(this_tag_int_value, return_block, &wip); |
| ... | @@ -4555,10 +4527,11 @@ pub const Object = struct { | ... | @@ -4555,10 +4527,11 @@ pub const Object = struct { |
| 4555 | pub const NavGen = struct { | 4527 | pub const NavGen = struct { |
| 4556 | object: *Object, | 4528 | object: *Object, |
| 4557 | nav_index: InternPool.Nav.Index, | 4529 | nav_index: InternPool.Nav.Index, |
| | 4530 | pt: Zcu.PerThread, |
| 4558 | err_msg: ?*Zcu.ErrorMsg, | 4531 | err_msg: ?*Zcu.ErrorMsg, |
| 4559 | | 4532 | |
| 4560 | fn ownerModule(ng: NavGen) *Package.Module { | 4533 | fn ownerModule(ng: NavGen) *Package.Module { |
| 4561 | return ng.object.pt.zcu.navFileScope(ng.nav_index).mod.?; | 4534 | return ng.pt.zcu.navFileScope(ng.nav_index).mod.?; |
| 4562 | } | 4535 | } |
| 4563 | | 4536 | |
| 4564 | fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error { | 4537 | fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error { |
| ... | @@ -4566,14 +4539,14 @@ pub const NavGen = struct { | ... | @@ -4566,14 +4539,14 @@ pub const NavGen = struct { |
| 4566 | assert(ng.err_msg == null); | 4539 | assert(ng.err_msg == null); |
| 4567 | const o = ng.object; | 4540 | const o = ng.object; |
| 4568 | const gpa = o.gpa; | 4541 | const gpa = o.gpa; |
| 4569 | const src_loc = o.pt.zcu.navSrcLoc(ng.nav_index); | 4542 | const src_loc = ng.pt.zcu.navSrcLoc(ng.nav_index); |
| 4570 | ng.err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args); | 4543 | ng.err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args); |
| 4571 | return error.CodegenFail; | 4544 | return error.CodegenFail; |
| 4572 | } | 4545 | } |
| 4573 | | 4546 | |
| 4574 | fn genDecl(ng: *NavGen) !void { | 4547 | fn genDecl(ng: *NavGen) !void { |
| 4575 | const o = ng.object; | 4548 | const o = ng.object; |
| 4576 | const pt = o.pt; | 4549 | const pt = ng.pt; |
| 4577 | const zcu = pt.zcu; | 4550 | const zcu = pt.zcu; |
| 4578 | const ip = &zcu.intern_pool; | 4551 | const ip = &zcu.intern_pool; |
| 4579 | const nav_index = ng.nav_index; | 4552 | const nav_index = ng.nav_index; |
| ... | @@ -4588,16 +4561,16 @@ pub const NavGen = struct { | ... | @@ -4588,16 +4561,16 @@ pub const NavGen = struct { |
| 4588 | const ty = Type.fromInterned(nav.typeOf(ip)); | 4561 | const ty = Type.fromInterned(nav.typeOf(ip)); |
| 4589 | | 4562 | |
| 4590 | if (linkage != .internal and ip.isFunctionType(ty.toIntern())) { | 4563 | if (linkage != .internal and ip.isFunctionType(ty.toIntern())) { |
| 4591 | _ = try o.resolveLlvmFunction(owner_nav); | 4564 | _ = try o.resolveLlvmFunction(pt, owner_nav); |
| 4592 | } else { | 4565 | } else { |
| 4593 | const variable_index = try o.resolveGlobalNav(nav_index); | 4566 | const variable_index = try o.resolveGlobalNav(pt, nav_index); |
| 4594 | variable_index.setAlignment(pt.navAlignment(nav_index).toLlvm(), &o.builder); | 4567 | variable_index.setAlignment(pt.navAlignment(nav_index).toLlvm(), &o.builder); |
| 4595 | if (resolved.@"linksection".toSlice(ip)) |section| | 4568 | if (resolved.@"linksection".toSlice(ip)) |section| |
| 4596 | variable_index.setSection(try o.builder.string(section), &o.builder); | 4569 | variable_index.setSection(try o.builder.string(section), &o.builder); |
| 4597 | if (is_const) variable_index.setMutability(.constant, &o.builder); | 4570 | if (is_const) variable_index.setMutability(.constant, &o.builder); |
| 4598 | try variable_index.setInitializer(switch (init_val) { | 4571 | try variable_index.setInitializer(switch (init_val) { |
| 4599 | .none => .no_init, | 4572 | .none => .no_init, |
| 4600 | else => try o.lowerValue(init_val), | 4573 | else => try o.lowerValue(pt, init_val), |
| 4601 | }, &o.builder); | 4574 | }, &o.builder); |
| 4602 | variable_index.setVisibility(visibility, &o.builder); | 4575 | variable_index.setVisibility(visibility, &o.builder); |
| 4603 | | 4576 | |
| ... | @@ -4609,7 +4582,7 @@ pub const NavGen = struct { | ... | @@ -4609,7 +4582,7 @@ pub const NavGen = struct { |
| 4609 | const line_number = zcu.navSrcLine(nav_index) + 1; | 4582 | const line_number = zcu.navSrcLine(nav_index) + 1; |
| 4610 | | 4583 | |
| 4611 | if (!mod.strip) { | 4584 | if (!mod.strip) { |
| 4612 | const debug_file = try o.getDebugFile(file_scope); | 4585 | const debug_file = try o.getDebugFile(pt, file_scope); |
| 4613 | | 4586 | |
| 4614 | const debug_global_var = try o.builder.debugGlobalVar( | 4587 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4615 | try o.builder.metadataString(nav.name.toSlice(ip)), // Name | 4588 | try o.builder.metadataString(nav.name.toSlice(ip)), // Name |
| ... | @@ -4617,7 +4590,7 @@ pub const NavGen = struct { | ... | @@ -4617,7 +4590,7 @@ pub const NavGen = struct { |
| 4617 | debug_file, // File | 4590 | debug_file, // File |
| 4618 | debug_file, // Scope | 4591 | debug_file, // Scope |
| 4619 | line_number, | 4592 | line_number, |
| 4620 | try o.lowerDebugType(ty), | 4593 | try o.lowerDebugType(pt, ty), |
| 4621 | variable_index, | 4594 | variable_index, |
| 4622 | .{ .local = linkage == .internal }, | 4595 | .{ .local = linkage == .internal }, |
| 4623 | ); | 4596 | ); |
| ... | @@ -4814,16 +4787,17 @@ pub const FuncGen = struct { | ... | @@ -4814,16 +4787,17 @@ pub const FuncGen = struct { |
| 4814 | const gop = try self.func_inst_table.getOrPut(gpa, inst); | 4787 | const gop = try self.func_inst_table.getOrPut(gpa, inst); |
| 4815 | if (gop.found_existing) return gop.value_ptr.*; | 4788 | if (gop.found_existing) return gop.value_ptr.*; |
| 4816 | | 4789 | |
| 4817 | const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.object.pt)).?); | 4790 | const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.pt)).?); |
| 4818 | gop.value_ptr.* = llvm_val.toValue(); | 4791 | gop.value_ptr.* = llvm_val.toValue(); |
| 4819 | return llvm_val.toValue(); | 4792 | return llvm_val.toValue(); |
| 4820 | } | 4793 | } |
| 4821 | | 4794 | |
| 4822 | fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant { | 4795 | fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant { |
| 4823 | const o = self.ng.object; | 4796 | const o = self.ng.object; |
| 4824 | const zcu = o.pt.zcu; | 4797 | const pt = self.ng.pt; |
| | 4798 | const zcu = pt.zcu; |
| 4825 | const ty = val.typeOf(zcu); | 4799 | const ty = val.typeOf(zcu); |
| 4826 | const llvm_val = try o.lowerValue(val.toIntern()); | 4800 | const llvm_val = try o.lowerValue(pt, val.toIntern()); |
| 4827 | if (!isByRef(ty, zcu)) return llvm_val; | 4801 | if (!isByRef(ty, zcu)) return llvm_val; |
| 4828 | | 4802 | |
| 4829 | // We have an LLVM value but we need to create a global constant and | 4803 | // We have an LLVM value but we need to create a global constant and |
| ... | @@ -4847,7 +4821,7 @@ pub const FuncGen = struct { | ... | @@ -4847,7 +4821,7 @@ pub const FuncGen = struct { |
| 4847 | | 4821 | |
| 4848 | fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) Error!void { | 4822 | fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) Error!void { |
| 4849 | const o = self.ng.object; | 4823 | const o = self.ng.object; |
| 4850 | const zcu = o.pt.zcu; | 4824 | const zcu = self.ng.pt.zcu; |
| 4851 | const ip = &zcu.intern_pool; | 4825 | const ip = &zcu.intern_pool; |
| 4852 | const air_tags = self.air.instructions.items(.tag); | 4826 | const air_tags = self.air.instructions.items(.tag); |
| 4853 | switch (coverage_point) { | 4827 | switch (coverage_point) { |
| ... | @@ -5173,7 +5147,7 @@ pub const FuncGen = struct { | ... | @@ -5173,7 +5147,7 @@ pub const FuncGen = struct { |
| 5173 | | 5147 | |
| 5174 | if (maybe_inline_func) |inline_func| { | 5148 | if (maybe_inline_func) |inline_func| { |
| 5175 | const o = self.ng.object; | 5149 | const o = self.ng.object; |
| 5176 | const pt = o.pt; | 5150 | const pt = self.ng.pt; |
| 5177 | const zcu = pt.zcu; | 5151 | const zcu = pt.zcu; |
| 5178 | const ip = &zcu.intern_pool; | 5152 | const ip = &zcu.intern_pool; |
| 5179 | | 5153 | |
| ... | @@ -5182,7 +5156,7 @@ pub const FuncGen = struct { | ... | @@ -5182,7 +5156,7 @@ pub const FuncGen = struct { |
| 5182 | const file_scope = zcu.navFileScopeIndex(func.owner_nav); | 5156 | const file_scope = zcu.navFileScopeIndex(func.owner_nav); |
| 5183 | const mod = zcu.fileByIndex(file_scope).mod.?; | 5157 | const mod = zcu.fileByIndex(file_scope).mod.?; |
| 5184 | | 5158 | |
| 5185 | self.file = try o.getDebugFile(file_scope); | 5159 | self.file = try o.getDebugFile(pt, file_scope); |
| 5186 | | 5160 | |
| 5187 | const line_number = zcu.navSrcLine(func.owner_nav) + 1; | 5161 | const line_number = zcu.navSrcLine(func.owner_nav) + 1; |
| 5188 | self.inlined = self.wip.debug_location; | 5162 | self.inlined = self.wip.debug_location; |
| ... | @@ -5198,7 +5172,7 @@ pub const FuncGen = struct { | ... | @@ -5198,7 +5172,7 @@ pub const FuncGen = struct { |
| 5198 | try o.builder.metadataString(nav.fqn.toSlice(&zcu.intern_pool)), | 5172 | try o.builder.metadataString(nav.fqn.toSlice(&zcu.intern_pool)), |
| 5199 | line_number, | 5173 | line_number, |
| 5200 | line_number + func.lbrace_line, | 5174 | line_number + func.lbrace_line, |
| 5201 | try o.lowerDebugType(fn_ty), | 5175 | try o.lowerDebugType(pt, fn_ty), |
| 5202 | .{ | 5176 | .{ |
| 5203 | .di_flags = .{ .StaticMember = true }, | 5177 | .di_flags = .{ .StaticMember = true }, |
| 5204 | .sp_flags = .{ | 5178 | .sp_flags = .{ |
| ... | @@ -5255,7 +5229,7 @@ pub const FuncGen = struct { | ... | @@ -5255,7 +5229,7 @@ pub const FuncGen = struct { |
| 5255 | const extra = self.air.extraData(Air.Call, pl_op.payload); | 5229 | 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]); | 5230 | const args: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[extra.end..][0..extra.data.args_len]); |
| 5257 | const o = self.ng.object; | 5231 | const o = self.ng.object; |
| 5258 | const pt = o.pt; | 5232 | const pt = self.ng.pt; |
| 5259 | const zcu = pt.zcu; | 5233 | const zcu = pt.zcu; |
| 5260 | const ip = &zcu.intern_pool; | 5234 | const ip = &zcu.intern_pool; |
| 5261 | const callee_ty = self.typeOf(pl_op.operand); | 5235 | const callee_ty = self.typeOf(pl_op.operand); |
| ... | @@ -5287,7 +5261,7 @@ pub const FuncGen = struct { | ... | @@ -5287,7 +5261,7 @@ pub const FuncGen = struct { |
| 5287 | } | 5261 | } |
| 5288 | | 5262 | |
| 5289 | const ret_ptr = if (!sret) null else blk: { | 5263 | const ret_ptr = if (!sret) null else blk: { |
| 5290 | const llvm_ret_ty = try o.lowerType(return_type); | 5264 | const llvm_ret_ty = try o.lowerType(pt, return_type); |
| 5291 | try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder); | 5265 | try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder); |
| 5292 | | 5266 | |
| 5293 | const alignment = return_type.abiAlignment(zcu).toLlvm(); | 5267 | const alignment = return_type.abiAlignment(zcu).toLlvm(); |
| ... | @@ -5302,14 +5276,14 @@ pub const FuncGen = struct { | ... | @@ -5302,14 +5276,14 @@ pub const FuncGen = struct { |
| 5302 | try llvm_args.append(self.err_ret_trace); | 5276 | try llvm_args.append(self.err_ret_trace); |
| 5303 | } | 5277 | } |
| 5304 | | 5278 | |
| 5305 | var it = iterateParamTypes(o, fn_info); | 5279 | var it = iterateParamTypes(o, pt, fn_info); |
| 5306 | while (try it.nextCall(self, args)) |lowering| switch (lowering) { | 5280 | while (try it.nextCall(self, args)) |lowering| switch (lowering) { |
| 5307 | .no_bits => continue, | 5281 | .no_bits => continue, |
| 5308 | .byval => { | 5282 | .byval => { |
| 5309 | const arg = args[it.zig_index - 1]; | 5283 | const arg = args[it.zig_index - 1]; |
| 5310 | const param_ty = self.typeOf(arg); | 5284 | const param_ty = self.typeOf(arg); |
| 5311 | const llvm_arg = try self.resolveInst(arg); | 5285 | const llvm_arg = try self.resolveInst(arg); |
| 5312 | const llvm_param_ty = try o.lowerType(param_ty); | 5286 | const llvm_param_ty = try o.lowerType(pt, param_ty); |
| 5313 | if (isByRef(param_ty, zcu)) { | 5287 | if (isByRef(param_ty, zcu)) { |
| 5314 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); | 5288 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 5315 | const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, ""); | 5289 | const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, ""); |
| ... | @@ -5338,7 +5312,7 @@ pub const FuncGen = struct { | ... | @@ -5338,7 +5312,7 @@ pub const FuncGen = struct { |
| 5338 | const llvm_arg = try self.resolveInst(arg); | 5312 | const llvm_arg = try self.resolveInst(arg); |
| 5339 | | 5313 | |
| 5340 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); | 5314 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 5341 | const param_llvm_ty = try o.lowerType(param_ty); | 5315 | const param_llvm_ty = try o.lowerType(pt, param_ty); |
| 5342 | const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment); | 5316 | const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment); |
| 5343 | if (isByRef(param_ty, zcu)) { | 5317 | if (isByRef(param_ty, zcu)) { |
| 5344 | const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, ""); | 5318 | const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, ""); |
| ... | @@ -5409,7 +5383,7 @@ pub const FuncGen = struct { | ... | @@ -5409,7 +5383,7 @@ pub const FuncGen = struct { |
| 5409 | llvm_arg = ptr; | 5383 | llvm_arg = ptr; |
| 5410 | } | 5384 | } |
| 5411 | | 5385 | |
| 5412 | const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?); | 5386 | const float_ty = try o.lowerType(pt, aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?); |
| 5413 | const array_ty = try o.builder.arrayType(count, float_ty); | 5387 | const array_ty = try o.builder.arrayType(count, float_ty); |
| 5414 | | 5388 | |
| 5415 | const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, ""); | 5389 | const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, ""); |
| ... | @@ -5436,7 +5410,7 @@ pub const FuncGen = struct { | ... | @@ -5436,7 +5410,7 @@ pub const FuncGen = struct { |
| 5436 | | 5410 | |
| 5437 | { | 5411 | { |
| 5438 | // Add argument attributes. | 5412 | // Add argument attributes. |
| 5439 | it = iterateParamTypes(o, fn_info); | 5413 | it = iterateParamTypes(o, pt, fn_info); |
| 5440 | it.llvm_index += @intFromBool(sret); | 5414 | it.llvm_index += @intFromBool(sret); |
| 5441 | it.llvm_index += @intFromBool(err_return_tracing); | 5415 | it.llvm_index += @intFromBool(err_return_tracing); |
| 5442 | while (try it.next()) |lowering| switch (lowering) { | 5416 | while (try it.next()) |lowering| switch (lowering) { |
| ... | @@ -5444,13 +5418,13 @@ pub const FuncGen = struct { | ... | @@ -5444,13 +5418,13 @@ pub const FuncGen = struct { |
| 5444 | const param_index = it.zig_index - 1; | 5418 | const param_index = it.zig_index - 1; |
| 5445 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); | 5419 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); |
| 5446 | if (!isByRef(param_ty, zcu)) { | 5420 | if (!isByRef(param_ty, zcu)) { |
| 5447 | try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1); | 5421 | try o.addByValParamAttrs(pt, &attributes, param_ty, param_index, fn_info, it.llvm_index - 1); |
| 5448 | } | 5422 | } |
| 5449 | }, | 5423 | }, |
| 5450 | .byref => { | 5424 | .byref => { |
| 5451 | const param_index = it.zig_index - 1; | 5425 | const param_index = it.zig_index - 1; |
| 5452 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); | 5426 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); |
| 5453 | const param_llvm_ty = try o.lowerType(param_ty); | 5427 | const param_llvm_ty = try o.lowerType(pt, param_ty); |
| 5454 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); | 5428 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 5455 | try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty); | 5429 | try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty); |
| 5456 | }, | 5430 | }, |
| ... | @@ -5502,7 +5476,7 @@ pub const FuncGen = struct { | ... | @@ -5502,7 +5476,7 @@ pub const FuncGen = struct { |
| 5502 | }, | 5476 | }, |
| 5503 | toLlvmCallConvTag(fn_info.cc, target).?, | 5477 | toLlvmCallConvTag(fn_info.cc, target).?, |
| 5504 | try attributes.finish(&o.builder), | 5478 | try attributes.finish(&o.builder), |
| 5505 | try o.lowerType(zig_fn_ty), | 5479 | try o.lowerType(pt, zig_fn_ty), |
| 5506 | llvm_fn, | 5480 | llvm_fn, |
| 5507 | llvm_args.items, | 5481 | llvm_args.items, |
| 5508 | "", | 5482 | "", |
| ... | @@ -5516,7 +5490,7 @@ pub const FuncGen = struct { | ... | @@ -5516,7 +5490,7 @@ pub const FuncGen = struct { |
| 5516 | return .none; | 5490 | return .none; |
| 5517 | } | 5491 | } |
| 5518 | | 5492 | |
| 5519 | const llvm_ret_ty = try o.lowerType(return_type); | 5493 | const llvm_ret_ty = try o.lowerType(pt, return_type); |
| 5520 | if (ret_ptr) |rp| { | 5494 | if (ret_ptr) |rp| { |
| 5521 | if (isByRef(return_type, zcu)) { | 5495 | if (isByRef(return_type, zcu)) { |
| 5522 | return rp; | 5496 | return rp; |
| ... | @@ -5527,7 +5501,7 @@ pub const FuncGen = struct { | ... | @@ -5527,7 +5501,7 @@ pub const FuncGen = struct { |
| 5527 | } | 5501 | } |
| 5528 | } | 5502 | } |
| 5529 | | 5503 | |
| 5530 | const abi_ret_ty = try lowerFnRetTy(o, fn_info); | 5504 | const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 5531 | | 5505 | |
| 5532 | if (abi_ret_ty != llvm_ret_ty) { | 5506 | if (abi_ret_ty != llvm_ret_ty) { |
| 5533 | // In this case the function return type is honoring the calling convention by having | 5507 | // In this case the function return type is honoring the calling convention by having |
| ... | @@ -5556,11 +5530,12 @@ pub const FuncGen = struct { | ... | @@ -5556,11 +5530,12 @@ pub const FuncGen = struct { |
| 5556 | | 5530 | |
| 5557 | fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) !void { | 5531 | fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) !void { |
| 5558 | const o = fg.ng.object; | 5532 | const o = fg.ng.object; |
| 5559 | const zcu = o.pt.zcu; | 5533 | const pt = fg.ng.pt; |
| | 5534 | const zcu = pt.zcu; |
| 5560 | const target = zcu.getTarget(); | 5535 | const target = zcu.getTarget(); |
| 5561 | const panic_func = zcu.funcInfo(zcu.builtin_decl_values.get(panic_id.toBuiltin())); | 5536 | const panic_func = zcu.funcInfo(zcu.builtin_decl_values.get(panic_id.toBuiltin())); |
| 5562 | const fn_info = zcu.typeToFunc(.fromInterned(panic_func.ty)).?; | 5537 | const fn_info = zcu.typeToFunc(.fromInterned(panic_func.ty)).?; |
| 5563 | const panic_global = try o.resolveLlvmFunction(panic_func.owner_nav); | 5538 | const panic_global = try o.resolveLlvmFunction(pt, panic_func.owner_nav); |
| 5564 | | 5539 | |
| 5565 | const has_err_trace = zcu.comp.config.any_error_tracing and fn_info.cc == .auto; | 5540 | 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); | 5541 | if (has_err_trace) assert(fg.err_ret_trace != .none); |
| ... | @@ -5579,7 +5554,7 @@ pub const FuncGen = struct { | ... | @@ -5579,7 +5554,7 @@ pub const FuncGen = struct { |
| 5579 | | 5554 | |
| 5580 | fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !void { | 5555 | fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !void { |
| 5581 | const o = self.ng.object; | 5556 | const o = self.ng.object; |
| 5582 | const pt = o.pt; | 5557 | const pt = self.ng.pt; |
| 5583 | const zcu = pt.zcu; | 5558 | const zcu = pt.zcu; |
| 5584 | const ip = &zcu.intern_pool; | 5559 | const ip = &zcu.intern_pool; |
| 5585 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | 5560 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| ... | @@ -5599,7 +5574,7 @@ pub const FuncGen = struct { | ... | @@ -5599,7 +5574,7 @@ pub const FuncGen = struct { |
| 5599 | // https://github.com/ziglang/zig/issues/15337 | 5574 | // https://github.com/ziglang/zig/issues/15337 |
| 5600 | break :undef; | 5575 | break :undef; |
| 5601 | } | 5576 | } |
| 5602 | const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu)); | 5577 | const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), ret_ty.abiSize(zcu)); |
| 5603 | _ = try self.wip.callMemSet( | 5578 | _ = try self.wip.callMemSet( |
| 5604 | self.ret_ptr, | 5579 | self.ret_ptr, |
| 5605 | ptr_ty.ptrAlignment(zcu).toLlvm(), | 5580 | ptr_ty.ptrAlignment(zcu).toLlvm(), |
| ... | @@ -5635,14 +5610,14 @@ pub const FuncGen = struct { | ... | @@ -5635,14 +5610,14 @@ pub const FuncGen = struct { |
| 5635 | // Functions with an empty error set are emitted with an error code | 5610 | // Functions with an empty error set are emitted with an error code |
| 5636 | // return type and return zero so they can be function pointers coerced | 5611 | // return type and return zero so they can be function pointers coerced |
| 5637 | // to functions that return anyerror. | 5612 | // to functions that return anyerror. |
| 5638 | _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(), 0)); | 5613 | _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(pt), 0)); |
| 5639 | } else { | 5614 | } else { |
| 5640 | _ = try self.wip.retVoid(); | 5615 | _ = try self.wip.retVoid(); |
| 5641 | } | 5616 | } |
| 5642 | return; | 5617 | return; |
| 5643 | } | 5618 | } |
| 5644 | | 5619 | |
| 5645 | const abi_ret_ty = try lowerFnRetTy(o, fn_info); | 5620 | const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 5646 | const operand = try self.resolveInst(un_op); | 5621 | 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; | 5622 | 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(); | 5623 | const alignment = ret_ty.abiAlignment(zcu).toLlvm(); |
| ... | @@ -5650,7 +5625,7 @@ pub const FuncGen = struct { | ... | @@ -5650,7 +5625,7 @@ pub const FuncGen = struct { |
| 5650 | if (val_is_undef and safety) { | 5625 | if (val_is_undef and safety) { |
| 5651 | const llvm_ret_ty = operand.typeOfWip(&self.wip); | 5626 | const llvm_ret_ty = operand.typeOfWip(&self.wip); |
| 5652 | const rp = try self.buildAlloca(llvm_ret_ty, alignment); | 5627 | const rp = try self.buildAlloca(llvm_ret_ty, alignment); |
| 5653 | const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu)); | 5628 | const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), ret_ty.abiSize(zcu)); |
| 5654 | _ = try self.wip.callMemSet( | 5629 | _ = try self.wip.callMemSet( |
| 5655 | rp, | 5630 | rp, |
| 5656 | alignment, | 5631 | alignment, |
| ... | @@ -5688,7 +5663,7 @@ pub const FuncGen = struct { | ... | @@ -5688,7 +5663,7 @@ pub const FuncGen = struct { |
| 5688 | | 5663 | |
| 5689 | fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !void { | 5664 | fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !void { |
| 5690 | const o = self.ng.object; | 5665 | const o = self.ng.object; |
| 5691 | const pt = o.pt; | 5666 | const pt = self.ng.pt; |
| 5692 | const zcu = pt.zcu; | 5667 | const zcu = pt.zcu; |
| 5693 | const ip = &zcu.intern_pool; | 5668 | const ip = &zcu.intern_pool; |
| 5694 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | 5669 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| ... | @@ -5700,7 +5675,7 @@ pub const FuncGen = struct { | ... | @@ -5700,7 +5675,7 @@ pub const FuncGen = struct { |
| 5700 | // Functions with an empty error set are emitted with an error code | 5675 | // Functions with an empty error set are emitted with an error code |
| 5701 | // return type and return zero so they can be function pointers coerced | 5676 | // return type and return zero so they can be function pointers coerced |
| 5702 | // to functions that return anyerror. | 5677 | // to functions that return anyerror. |
| 5703 | _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(), 0)); | 5678 | _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(pt), 0)); |
| 5704 | } else { | 5679 | } else { |
| 5705 | _ = try self.wip.retVoid(); | 5680 | _ = try self.wip.retVoid(); |
| 5706 | } | 5681 | } |
| ... | @@ -5711,7 +5686,7 @@ pub const FuncGen = struct { | ... | @@ -5711,7 +5686,7 @@ pub const FuncGen = struct { |
| 5711 | return; | 5686 | return; |
| 5712 | } | 5687 | } |
| 5713 | const ptr = try self.resolveInst(un_op); | 5688 | const ptr = try self.resolveInst(un_op); |
| 5714 | const abi_ret_ty = try lowerFnRetTy(o, fn_info); | 5689 | const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 5715 | const alignment = ret_ty.abiAlignment(zcu).toLlvm(); | 5690 | const alignment = ret_ty.abiAlignment(zcu).toLlvm(); |
| 5716 | _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, "")); | 5691 | _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, "")); |
| 5717 | return; | 5692 | return; |
| ... | @@ -5719,22 +5694,23 @@ pub const FuncGen = struct { | ... | @@ -5719,22 +5694,23 @@ pub const FuncGen = struct { |
| 5719 | | 5694 | |
| 5720 | fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 5695 | fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5721 | const o = self.ng.object; | 5696 | const o = self.ng.object; |
| | 5697 | const pt = self.ng.pt; |
| 5722 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 5698 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5723 | const list = try self.resolveInst(ty_op.operand); | 5699 | const list = try self.resolveInst(ty_op.operand); |
| 5724 | const arg_ty = ty_op.ty.toType(); | 5700 | const arg_ty = ty_op.ty.toType(); |
| 5725 | const llvm_arg_ty = try o.lowerType(arg_ty); | 5701 | const llvm_arg_ty = try o.lowerType(pt, arg_ty); |
| 5726 | | 5702 | |
| 5727 | return self.wip.vaArg(list, llvm_arg_ty, ""); | 5703 | return self.wip.vaArg(list, llvm_arg_ty, ""); |
| 5728 | } | 5704 | } |
| 5729 | | 5705 | |
| 5730 | fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 5706 | fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5731 | const o = self.ng.object; | 5707 | const o = self.ng.object; |
| 5732 | const pt = o.pt; | 5708 | const pt = self.ng.pt; |
| 5733 | const zcu = pt.zcu; | 5709 | const zcu = pt.zcu; |
| 5734 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 5710 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5735 | const src_list = try self.resolveInst(ty_op.operand); | 5711 | const src_list = try self.resolveInst(ty_op.operand); |
| 5736 | const va_list_ty = ty_op.ty.toType(); | 5712 | const va_list_ty = ty_op.ty.toType(); |
| 5737 | const llvm_va_list_ty = try o.lowerType(va_list_ty); | 5713 | const llvm_va_list_ty = try o.lowerType(pt, va_list_ty); |
| 5738 | | 5714 | |
| 5739 | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); | 5715 | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); |
| 5740 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); | 5716 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| ... | @@ -5756,10 +5732,10 @@ pub const FuncGen = struct { | ... | @@ -5756,10 +5732,10 @@ pub const FuncGen = struct { |
| 5756 | | 5732 | |
| 5757 | fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 5733 | fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5758 | const o = self.ng.object; | 5734 | const o = self.ng.object; |
| 5759 | const pt = o.pt; | 5735 | const pt = self.ng.pt; |
| 5760 | const zcu = pt.zcu; | 5736 | const zcu = pt.zcu; |
| 5761 | const va_list_ty = self.typeOfIndex(inst); | 5737 | const va_list_ty = self.typeOfIndex(inst); |
| 5762 | const llvm_va_list_ty = try o.lowerType(va_list_ty); | 5738 | const llvm_va_list_ty = try o.lowerType(pt, va_list_ty); |
| 5763 | | 5739 | |
| 5764 | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); | 5740 | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); |
| 5765 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); | 5741 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| ... | @@ -5799,9 +5775,10 @@ pub const FuncGen = struct { | ... | @@ -5799,9 +5775,10 @@ pub const FuncGen = struct { |
| 5799 | | 5775 | |
| 5800 | fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 5776 | fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5801 | const o = self.ng.object; | 5777 | const o = self.ng.object; |
| | 5778 | const pt = self.ng.pt; |
| 5802 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | 5779 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5803 | const operand = try self.resolveInst(un_op); | 5780 | const operand = try self.resolveInst(un_op); |
| 5804 | const llvm_fn = try o.getCmpLtErrorsLenFunction(); | 5781 | const llvm_fn = try o.getCmpLtErrorsLenFunction(pt); |
| 5805 | return self.wip.call( | 5782 | return self.wip.call( |
| 5806 | .normal, | 5783 | .normal, |
| 5807 | .fastcc, | 5784 | .fastcc, |
| ... | @@ -5822,7 +5799,7 @@ pub const FuncGen = struct { | ... | @@ -5822,7 +5799,7 @@ pub const FuncGen = struct { |
| 5822 | rhs: Builder.Value, | 5799 | rhs: Builder.Value, |
| 5823 | ) Allocator.Error!Builder.Value { | 5800 | ) Allocator.Error!Builder.Value { |
| 5824 | const o = self.ng.object; | 5801 | const o = self.ng.object; |
| 5825 | const pt = o.pt; | 5802 | const pt = self.ng.pt; |
| 5826 | const zcu = pt.zcu; | 5803 | const zcu = pt.zcu; |
| 5827 | const ip = &zcu.intern_pool; | 5804 | const ip = &zcu.intern_pool; |
| 5828 | const scalar_ty = operand_ty.scalarType(zcu); | 5805 | const scalar_ty = operand_ty.scalarType(zcu); |
| ... | @@ -5839,7 +5816,7 @@ pub const FuncGen = struct { | ... | @@ -5839,7 +5816,7 @@ pub const FuncGen = struct { |
| 5839 | // We need to emit instructions to check for equality/inequality | 5816 | // We need to emit instructions to check for equality/inequality |
| 5840 | // of optionals that are not pointers. | 5817 | // of optionals that are not pointers. |
| 5841 | const is_by_ref = isByRef(scalar_ty, zcu); | 5818 | const is_by_ref = isByRef(scalar_ty, zcu); |
| 5842 | const opt_llvm_ty = try o.lowerType(scalar_ty); | 5819 | const opt_llvm_ty = try o.lowerType(pt, scalar_ty); |
| 5843 | const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref, .normal); | 5820 | 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); | 5821 | 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); | 5822 | const llvm_i2 = try o.builder.intType(2); |
| ... | @@ -5936,7 +5913,7 @@ pub const FuncGen = struct { | ... | @@ -5936,7 +5913,7 @@ pub const FuncGen = struct { |
| 5936 | body: []const Air.Inst.Index, | 5913 | body: []const Air.Inst.Index, |
| 5937 | ) !Builder.Value { | 5914 | ) !Builder.Value { |
| 5938 | const o = self.ng.object; | 5915 | const o = self.ng.object; |
| 5939 | const pt = o.pt; | 5916 | const pt = self.ng.pt; |
| 5940 | const zcu = pt.zcu; | 5917 | const zcu = pt.zcu; |
| 5941 | const inst_ty = self.typeOfIndex(inst); | 5918 | const inst_ty = self.typeOfIndex(inst); |
| 5942 | | 5919 | |
| ... | @@ -5963,7 +5940,7 @@ pub const FuncGen = struct { | ... | @@ -5963,7 +5940,7 @@ pub const FuncGen = struct { |
| 5963 | | 5940 | |
| 5964 | // Create a phi node only if the block returns a value. | 5941 | // Create a phi node only if the block returns a value. |
| 5965 | if (have_block_result) { | 5942 | if (have_block_result) { |
| 5966 | const raw_llvm_ty = try o.lowerType(inst_ty); | 5943 | const raw_llvm_ty = try o.lowerType(pt, inst_ty); |
| 5967 | const llvm_ty: Builder.Type = ty: { | 5944 | const llvm_ty: Builder.Type = ty: { |
| 5968 | // If the zig tag type is a function, this represents an actual function body; not | 5945 | // 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 instead | 5946 | // a pointer to it. LLVM IR allows the call instruction to use function bodies instead |
| ... | @@ -5986,8 +5963,7 @@ pub const FuncGen = struct { | ... | @@ -5986,8 +5963,7 @@ pub const FuncGen = struct { |
| 5986 | } | 5963 | } |
| 5987 | | 5964 | |
| 5988 | fn airBr(self: *FuncGen, inst: Air.Inst.Index) !void { | 5965 | fn airBr(self: *FuncGen, inst: Air.Inst.Index) !void { |
| 5989 | const o = self.ng.object; | 5966 | const zcu = self.ng.pt.zcu; |
| 5990 | const zcu = o.pt.zcu; | | |
| 5991 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; | 5967 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; |
| 5992 | const block = self.blocks.get(branch.block_inst).?; | 5968 | const block = self.blocks.get(branch.block_inst).?; |
| 5993 | | 5969 | |
| ... | @@ -6017,7 +5993,7 @@ pub const FuncGen = struct { | ... | @@ -6017,7 +5993,7 @@ pub const FuncGen = struct { |
| 6017 | dispatch_info: SwitchDispatchInfo, | 5993 | dispatch_info: SwitchDispatchInfo, |
| 6018 | ) !void { | 5994 | ) !void { |
| 6019 | const o = self.ng.object; | 5995 | const o = self.ng.object; |
| 6020 | const pt = o.pt; | 5996 | const pt = self.ng.pt; |
| 6021 | const zcu = pt.zcu; | 5997 | const zcu = pt.zcu; |
| 6022 | const cond_ty = self.typeOf(cond_ref); | 5998 | const cond_ty = self.typeOf(cond_ref); |
| 6023 | const switch_br = self.air.unwrapSwitch(switch_inst); | 5999 | const switch_br = self.air.unwrapSwitch(switch_inst); |
| ... | @@ -6081,7 +6057,7 @@ pub const FuncGen = struct { | ... | @@ -6081,7 +6057,7 @@ pub const FuncGen = struct { |
| 6081 | const table_index = try self.wip.cast( | 6057 | const table_index = try self.wip.cast( |
| 6082 | .zext, | 6058 | .zext, |
| 6083 | try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""), | 6059 | try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""), |
| 6084 | try o.lowerType(Type.usize), | 6060 | try o.lowerType(pt, Type.usize), |
| 6085 | "", | 6061 | "", |
| 6086 | ); | 6062 | ); |
| 6087 | const target_ptr_ptr = try self.wip.gep( | 6063 | const target_ptr_ptr = try self.wip.gep( |
| ... | @@ -6108,7 +6084,7 @@ pub const FuncGen = struct { | ... | @@ -6108,7 +6084,7 @@ pub const FuncGen = struct { |
| 6108 | // The switch prongs will correspond to our scalar cases. Ranges will | 6084 | // The switch prongs will correspond to our scalar cases. Ranges will |
| 6109 | // be handled by conditional branches in the `else` prong. | 6085 | // be handled by conditional branches in the `else` prong. |
| 6110 | | 6086 | |
| 6111 | const llvm_usize = try o.lowerType(Type.usize); | 6087 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 6112 | const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder)) | 6088 | const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder)) |
| 6113 | try self.wip.cast(.ptrtoint, cond, llvm_usize, "") | 6089 | try self.wip.cast(.ptrtoint, cond, llvm_usize, "") |
| 6114 | else | 6090 | else |
| ... | @@ -6268,8 +6244,7 @@ pub const FuncGen = struct { | ... | @@ -6268,8 +6244,7 @@ pub const FuncGen = struct { |
| 6268 | } | 6244 | } |
| 6269 | | 6245 | |
| 6270 | fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index, err_cold: bool) !Builder.Value { | 6246 | fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index, err_cold: bool) !Builder.Value { |
| 6271 | const o = self.ng.object; | 6247 | const pt = self.ng.pt; |
| 6272 | const pt = o.pt; | | |
| 6273 | const zcu = pt.zcu; | 6248 | const zcu = pt.zcu; |
| 6274 | const inst = body_tail[0]; | 6249 | const inst = body_tail[0]; |
| 6275 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 6250 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| ... | @@ -6284,8 +6259,7 @@ pub const FuncGen = struct { | ... | @@ -6284,8 +6259,7 @@ pub const FuncGen = struct { |
| 6284 | } | 6259 | } |
| 6285 | | 6260 | |
| 6286 | fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) !Builder.Value { | 6261 | fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) !Builder.Value { |
| 6287 | const o = self.ng.object; | 6262 | 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; | 6263 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 6290 | const extra = self.air.extraData(Air.TryPtr, ty_pl.payload); | 6264 | const extra = self.air.extraData(Air.TryPtr, ty_pl.payload); |
| 6291 | const err_union_ptr = try self.resolveInst(extra.data.ptr); | 6265 | const err_union_ptr = try self.resolveInst(extra.data.ptr); |
| ... | @@ -6309,12 +6283,12 @@ pub const FuncGen = struct { | ... | @@ -6309,12 +6283,12 @@ pub const FuncGen = struct { |
| 6309 | err_cold: bool, | 6283 | err_cold: bool, |
| 6310 | ) !Builder.Value { | 6284 | ) !Builder.Value { |
| 6311 | const o = fg.ng.object; | 6285 | const o = fg.ng.object; |
| 6312 | const pt = o.pt; | 6286 | const pt = fg.ng.pt; |
| 6313 | const zcu = pt.zcu; | 6287 | const zcu = pt.zcu; |
| 6314 | const payload_ty = err_union_ty.errorUnionPayload(zcu); | 6288 | const payload_ty = err_union_ty.errorUnionPayload(zcu); |
| 6315 | const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu); | 6289 | const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu); |
| 6316 | const err_union_llvm_ty = try o.lowerType(err_union_ty); | 6290 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 6317 | const error_type = try o.errorIntType(); | 6291 | const error_type = try o.errorIntType(pt); |
| 6318 | | 6292 | |
| 6319 | if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) { | 6293 | if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) { |
| 6320 | const loaded = loaded: { | 6294 | const loaded = loaded: { |
| ... | @@ -6378,7 +6352,8 @@ pub const FuncGen = struct { | ... | @@ -6378,7 +6352,8 @@ pub const FuncGen = struct { |
| 6378 | | 6352 | |
| 6379 | fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) !void { | 6353 | fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) !void { |
| 6380 | const o = self.ng.object; | 6354 | const o = self.ng.object; |
| 6381 | const zcu = o.pt.zcu; | 6355 | const pt = self.ng.pt; |
| | 6356 | const zcu = pt.zcu; |
| 6382 | | 6357 | |
| 6383 | const switch_br = self.air.unwrapSwitch(inst); | 6358 | const switch_br = self.air.unwrapSwitch(inst); |
| 6384 | | 6359 | |
| ... | @@ -6483,8 +6458,8 @@ pub const FuncGen = struct { | ... | @@ -6483,8 +6458,8 @@ pub const FuncGen = struct { |
| 6483 | const table_includes_else = item_count != table_len; | 6458 | const table_includes_else = item_count != table_len; |
| 6484 | | 6459 | |
| 6485 | break :jmp_table .{ | 6460 | break :jmp_table .{ |
| 6486 | .min = try o.lowerValue(min.toIntern()), | 6461 | .min = try o.lowerValue(pt, min.toIntern()), |
| 6487 | .max = try o.lowerValue(max.toIntern()), | 6462 | .max = try o.lowerValue(pt, max.toIntern()), |
| 6488 | .in_bounds_hint = if (table_includes_else) .none else switch (switch_br.getElseHint()) { | 6463 | .in_bounds_hint = if (table_includes_else) .none else switch (switch_br.getElseHint()) { |
| 6489 | .none, .cold => .none, | 6464 | .none, .cold => .none, |
| 6490 | .unpredictable => .unpredictable, | 6465 | .unpredictable => .unpredictable, |
| ... | @@ -6591,7 +6566,7 @@ pub const FuncGen = struct { | ... | @@ -6591,7 +6566,7 @@ pub const FuncGen = struct { |
| 6591 | } | 6566 | } |
| 6592 | | 6567 | |
| 6593 | fn switchCaseItemRange(self: *FuncGen, switch_br: Air.UnwrappedSwitch) [2]Value { | 6568 | fn switchCaseItemRange(self: *FuncGen, switch_br: Air.UnwrappedSwitch) [2]Value { |
| 6594 | const zcu = self.ng.object.pt.zcu; | 6569 | const zcu = self.ng.pt.zcu; |
| 6595 | var it = switch_br.iterateCases(); | 6570 | var it = switch_br.iterateCases(); |
| 6596 | var min: ?Value = null; | 6571 | var min: ?Value = null; |
| 6597 | var max: ?Value = null; | 6572 | var max: ?Value = null; |
| ... | @@ -6633,18 +6608,18 @@ pub const FuncGen = struct { | ... | @@ -6633,18 +6608,18 @@ pub const FuncGen = struct { |
| 6633 | | 6608 | |
| 6634 | fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6609 | fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6635 | const o = self.ng.object; | 6610 | const o = self.ng.object; |
| 6636 | const pt = o.pt; | 6611 | const pt = self.ng.pt; |
| 6637 | const zcu = pt.zcu; | 6612 | const zcu = pt.zcu; |
| 6638 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 6613 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6639 | const operand_ty = self.typeOf(ty_op.operand); | 6614 | const operand_ty = self.typeOf(ty_op.operand); |
| 6640 | const array_ty = operand_ty.childType(zcu); | 6615 | const array_ty = operand_ty.childType(zcu); |
| 6641 | const llvm_usize = try o.lowerType(Type.usize); | 6616 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 6642 | const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu)); | 6617 | const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu)); |
| 6643 | const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst)); | 6618 | const slice_llvm_ty = try o.lowerType(pt, self.typeOfIndex(inst)); |
| 6644 | const operand = try self.resolveInst(ty_op.operand); | 6619 | const operand = try self.resolveInst(ty_op.operand); |
| 6645 | if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu)) | 6620 | if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu)) |
| 6646 | return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, ""); | 6621 | return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, ""); |
| 6647 | const ptr = try self.wip.gep(.inbounds, try o.lowerType(array_ty), operand, &.{ | 6622 | const ptr = try self.wip.gep(.inbounds, try o.lowerType(pt, array_ty), operand, &.{ |
| 6648 | try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0), | 6623 | try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0), |
| 6649 | }, ""); | 6624 | }, ""); |
| 6650 | return self.wip.buildAggregate(slice_llvm_ty, &.{ ptr, len }, ""); | 6625 | return self.wip.buildAggregate(slice_llvm_ty, &.{ ptr, len }, ""); |
| ... | @@ -6652,7 +6627,7 @@ pub const FuncGen = struct { | ... | @@ -6652,7 +6627,7 @@ pub const FuncGen = struct { |
| 6652 | | 6627 | |
| 6653 | fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6628 | fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6654 | const o = self.ng.object; | 6629 | const o = self.ng.object; |
| 6655 | const pt = o.pt; | 6630 | const pt = self.ng.pt; |
| 6656 | const zcu = pt.zcu; | 6631 | const zcu = pt.zcu; |
| 6657 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 6632 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6658 | | 6633 | |
| ... | @@ -6663,7 +6638,7 @@ pub const FuncGen = struct { | ... | @@ -6663,7 +6638,7 @@ pub const FuncGen = struct { |
| 6663 | | 6638 | |
| 6664 | const dest_ty = self.typeOfIndex(inst); | 6639 | const dest_ty = self.typeOfIndex(inst); |
| 6665 | const dest_scalar_ty = dest_ty.scalarType(zcu); | 6640 | const dest_scalar_ty = dest_ty.scalarType(zcu); |
| 6666 | const dest_llvm_ty = try o.lowerType(dest_ty); | 6641 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 6667 | const target = zcu.getTarget(); | 6642 | const target = zcu.getTarget(); |
| 6668 | | 6643 | |
| 6669 | if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv( | 6644 | if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv( |
| ... | @@ -6719,7 +6694,7 @@ pub const FuncGen = struct { | ... | @@ -6719,7 +6694,7 @@ pub const FuncGen = struct { |
| 6719 | _ = fast; | 6694 | _ = fast; |
| 6720 | | 6695 | |
| 6721 | const o = self.ng.object; | 6696 | const o = self.ng.object; |
| 6722 | const pt = o.pt; | 6697 | const pt = self.ng.pt; |
| 6723 | const zcu = pt.zcu; | 6698 | const zcu = pt.zcu; |
| 6724 | const target = zcu.getTarget(); | 6699 | const target = zcu.getTarget(); |
| 6725 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 6700 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | @@ -6730,7 +6705,7 @@ pub const FuncGen = struct { | ... | @@ -6730,7 +6705,7 @@ pub const FuncGen = struct { |
| 6730 | | 6705 | |
| 6731 | const dest_ty = self.typeOfIndex(inst); | 6706 | const dest_ty = self.typeOfIndex(inst); |
| 6732 | const dest_scalar_ty = dest_ty.scalarType(zcu); | 6707 | const dest_scalar_ty = dest_ty.scalarType(zcu); |
| 6733 | const dest_llvm_ty = try o.lowerType(dest_ty); | 6708 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 6734 | | 6709 | |
| 6735 | if (intrinsicsAllowed(operand_scalar_ty, target)) { | 6710 | if (intrinsicsAllowed(operand_scalar_ty, target)) { |
| 6736 | // TODO set fast math flag | 6711 | // TODO set fast math flag |
| ... | @@ -6762,7 +6737,7 @@ pub const FuncGen = struct { | ... | @@ -6762,7 +6737,7 @@ pub const FuncGen = struct { |
| 6762 | compiler_rt_dest_abbrev, | 6737 | compiler_rt_dest_abbrev, |
| 6763 | }); | 6738 | }); |
| 6764 | | 6739 | |
| 6765 | const operand_llvm_ty = try o.lowerType(operand_ty); | 6740 | 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); | 6741 | const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty); |
| 6767 | var result = try self.wip.call( | 6742 | var result = try self.wip.call( |
| 6768 | .normal, | 6743 | .normal, |
| ... | @@ -6780,16 +6755,15 @@ pub const FuncGen = struct { | ... | @@ -6780,16 +6755,15 @@ pub const FuncGen = struct { |
| 6780 | } | 6755 | } |
| 6781 | | 6756 | |
| 6782 | fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { | 6757 | fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { |
| 6783 | const o = fg.ng.object; | 6758 | 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; | 6759 | return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr; |
| 6786 | } | 6760 | } |
| 6787 | | 6761 | |
| 6788 | fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { | 6762 | fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { |
| 6789 | const o = fg.ng.object; | 6763 | const o = fg.ng.object; |
| 6790 | const pt = o.pt; | 6764 | const pt = fg.ng.pt; |
| 6791 | const zcu = pt.zcu; | 6765 | const zcu = pt.zcu; |
| 6792 | const llvm_usize = try o.lowerType(Type.usize); | 6766 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 6793 | switch (ty.ptrSize(zcu)) { | 6767 | switch (ty.ptrSize(zcu)) { |
| 6794 | .slice => { | 6768 | .slice => { |
| 6795 | const len = try fg.wip.extractValue(ptr, &.{1}, ""); | 6769 | const len = try fg.wip.extractValue(ptr, &.{1}, ""); |
| ... | @@ -6817,18 +6791,19 @@ pub const FuncGen = struct { | ... | @@ -6817,18 +6791,19 @@ pub const FuncGen = struct { |
| 6817 | | 6791 | |
| 6818 | fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value { | 6792 | fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value { |
| 6819 | const o = self.ng.object; | 6793 | const o = self.ng.object; |
| 6820 | const zcu = o.pt.zcu; | 6794 | const pt = self.ng.pt; |
| | 6795 | const zcu = pt.zcu; |
| 6821 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 6796 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6822 | const slice_ptr = try self.resolveInst(ty_op.operand); | 6797 | const slice_ptr = try self.resolveInst(ty_op.operand); |
| 6823 | const slice_ptr_ty = self.typeOf(ty_op.operand); | 6798 | const slice_ptr_ty = self.typeOf(ty_op.operand); |
| 6824 | const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(zcu)); | 6799 | const slice_llvm_ty = try o.lowerPtrElemTy(pt, slice_ptr_ty.childType(zcu)); |
| 6825 | | 6800 | |
| 6826 | return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, ""); | 6801 | return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, ""); |
| 6827 | } | 6802 | } |
| 6828 | | 6803 | |
| 6829 | fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { | 6804 | fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6830 | const o = self.ng.object; | 6805 | const o = self.ng.object; |
| 6831 | const pt = o.pt; | 6806 | const pt = self.ng.pt; |
| 6832 | const zcu = pt.zcu; | 6807 | const zcu = pt.zcu; |
| 6833 | const inst = body_tail[0]; | 6808 | const inst = body_tail[0]; |
| 6834 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 6809 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| ... | @@ -6836,7 +6811,7 @@ pub const FuncGen = struct { | ... | @@ -6836,7 +6811,7 @@ pub const FuncGen = struct { |
| 6836 | const slice = try self.resolveInst(bin_op.lhs); | 6811 | const slice = try self.resolveInst(bin_op.lhs); |
| 6837 | const index = try self.resolveInst(bin_op.rhs); | 6812 | const index = try self.resolveInst(bin_op.rhs); |
| 6838 | const elem_ty = slice_ty.childType(zcu); | 6813 | const elem_ty = slice_ty.childType(zcu); |
| 6839 | const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty); | 6814 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty); |
| 6840 | const base_ptr = try self.wip.extractValue(slice, &.{0}, ""); | 6815 | const base_ptr = try self.wip.extractValue(slice, &.{0}, ""); |
| 6841 | const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, ""); | 6816 | const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, ""); |
| 6842 | if (isByRef(elem_ty, zcu)) { | 6817 | if (isByRef(elem_ty, zcu)) { |
| ... | @@ -6856,21 +6831,22 @@ pub const FuncGen = struct { | ... | @@ -6856,21 +6831,22 @@ pub const FuncGen = struct { |
| 6856 | | 6831 | |
| 6857 | fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6832 | fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6858 | const o = self.ng.object; | 6833 | const o = self.ng.object; |
| 6859 | const zcu = o.pt.zcu; | 6834 | const pt = self.ng.pt; |
| | 6835 | const zcu = pt.zcu; |
| 6860 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 6836 | 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; | 6837 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6862 | const slice_ty = self.typeOf(bin_op.lhs); | 6838 | const slice_ty = self.typeOf(bin_op.lhs); |
| 6863 | | 6839 | |
| 6864 | const slice = try self.resolveInst(bin_op.lhs); | 6840 | const slice = try self.resolveInst(bin_op.lhs); |
| 6865 | const index = try self.resolveInst(bin_op.rhs); | 6841 | const index = try self.resolveInst(bin_op.rhs); |
| 6866 | const llvm_elem_ty = try o.lowerPtrElemTy(slice_ty.childType(zcu)); | 6842 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, slice_ty.childType(zcu)); |
| 6867 | const base_ptr = try self.wip.extractValue(slice, &.{0}, ""); | 6843 | const base_ptr = try self.wip.extractValue(slice, &.{0}, ""); |
| 6868 | return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, ""); | 6844 | return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, ""); |
| 6869 | } | 6845 | } |
| 6870 | | 6846 | |
| 6871 | fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { | 6847 | fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6872 | const o = self.ng.object; | 6848 | const o = self.ng.object; |
| 6873 | const pt = o.pt; | 6849 | const pt = self.ng.pt; |
| 6874 | const zcu = pt.zcu; | 6850 | const zcu = pt.zcu; |
| 6875 | const inst = body_tail[0]; | 6851 | const inst = body_tail[0]; |
| 6876 | | 6852 | |
| ... | @@ -6878,11 +6854,11 @@ pub const FuncGen = struct { | ... | @@ -6878,11 +6854,11 @@ pub const FuncGen = struct { |
| 6878 | const array_ty = self.typeOf(bin_op.lhs); | 6854 | const array_ty = self.typeOf(bin_op.lhs); |
| 6879 | const array_llvm_val = try self.resolveInst(bin_op.lhs); | 6855 | const array_llvm_val = try self.resolveInst(bin_op.lhs); |
| 6880 | const rhs = try self.resolveInst(bin_op.rhs); | 6856 | const rhs = try self.resolveInst(bin_op.rhs); |
| 6881 | const array_llvm_ty = try o.lowerType(array_ty); | 6857 | const array_llvm_ty = try o.lowerType(pt, array_ty); |
| 6882 | const elem_ty = array_ty.childType(zcu); | 6858 | const elem_ty = array_ty.childType(zcu); |
| 6883 | if (isByRef(array_ty, zcu)) { | 6859 | if (isByRef(array_ty, zcu)) { |
| 6884 | const indices: [2]Builder.Value = .{ | 6860 | const indices: [2]Builder.Value = .{ |
| 6885 | try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs, | 6861 | try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs, |
| 6886 | }; | 6862 | }; |
| 6887 | if (isByRef(elem_ty, zcu)) { | 6863 | if (isByRef(elem_ty, zcu)) { |
| 6888 | const elem_ptr = | 6864 | const elem_ptr = |
| ... | @@ -6903,19 +6879,19 @@ pub const FuncGen = struct { | ... | @@ -6903,19 +6879,19 @@ pub const FuncGen = struct { |
| 6903 | | 6879 | |
| 6904 | fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { | 6880 | fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6905 | const o = self.ng.object; | 6881 | const o = self.ng.object; |
| 6906 | const pt = o.pt; | 6882 | const pt = self.ng.pt; |
| 6907 | const zcu = pt.zcu; | 6883 | const zcu = pt.zcu; |
| 6908 | const inst = body_tail[0]; | 6884 | const inst = body_tail[0]; |
| 6909 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 6885 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 6910 | const ptr_ty = self.typeOf(bin_op.lhs); | 6886 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 6911 | const elem_ty = ptr_ty.childType(zcu); | 6887 | const elem_ty = ptr_ty.childType(zcu); |
| 6912 | const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty); | 6888 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty); |
| 6913 | const base_ptr = try self.resolveInst(bin_op.lhs); | 6889 | const base_ptr = try self.resolveInst(bin_op.lhs); |
| 6914 | const rhs = try self.resolveInst(bin_op.rhs); | 6890 | const rhs = try self.resolveInst(bin_op.rhs); |
| 6915 | // TODO: when we go fully opaque pointers in LLVM 16 we can remove this branch | 6891 | // 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)) | 6892 | 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. | 6893 | // If this is a single-item pointer to an array, we need another index in the GEP. |
| 6918 | &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs } | 6894 | &.{ try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs } |
| 6919 | else | 6895 | else |
| 6920 | &.{rhs}, ""); | 6896 | &.{rhs}, ""); |
| 6921 | if (isByRef(elem_ty, zcu)) { | 6897 | if (isByRef(elem_ty, zcu)) { |
| ... | @@ -6934,7 +6910,7 @@ pub const FuncGen = struct { | ... | @@ -6934,7 +6910,7 @@ pub const FuncGen = struct { |
| 6934 | | 6910 | |
| 6935 | fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6911 | fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6936 | const o = self.ng.object; | 6912 | const o = self.ng.object; |
| 6937 | const pt = o.pt; | 6913 | const pt = self.ng.pt; |
| 6938 | const zcu = pt.zcu; | 6914 | const zcu = pt.zcu; |
| 6939 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 6915 | 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; | 6916 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | @@ -6948,10 +6924,10 @@ pub const FuncGen = struct { | ... | @@ -6948,10 +6924,10 @@ pub const FuncGen = struct { |
| 6948 | const elem_ptr = ty_pl.ty.toType(); | 6924 | const elem_ptr = ty_pl.ty.toType(); |
| 6949 | if (elem_ptr.ptrInfo(zcu).flags.vector_index != .none) return base_ptr; | 6925 | if (elem_ptr.ptrInfo(zcu).flags.vector_index != .none) return base_ptr; |
| 6950 | | 6926 | |
| 6951 | const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty); | 6927 | 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)) | 6928 | 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. | 6929 | // If this is a single-item pointer to an array, we need another index in the GEP. |
| 6954 | &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs } | 6930 | &.{ try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs } |
| 6955 | else | 6931 | else |
| 6956 | &.{rhs}, ""); | 6932 | &.{rhs}, ""); |
| 6957 | } | 6933 | } |
| ... | @@ -6977,7 +6953,7 @@ pub const FuncGen = struct { | ... | @@ -6977,7 +6953,7 @@ pub const FuncGen = struct { |
| 6977 | | 6953 | |
| 6978 | fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { | 6954 | fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6979 | const o = self.ng.object; | 6955 | const o = self.ng.object; |
| 6980 | const pt = o.pt; | 6956 | const pt = self.ng.pt; |
| 6981 | const zcu = pt.zcu; | 6957 | const zcu = pt.zcu; |
| 6982 | const inst = body_tail[0]; | 6958 | const inst = body_tail[0]; |
| 6983 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 6959 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| ... | @@ -6999,7 +6975,7 @@ pub const FuncGen = struct { | ... | @@ -6999,7 +6975,7 @@ pub const FuncGen = struct { |
| 6999 | const shift_amt = | 6975 | const shift_amt = |
| 7000 | try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset); | 6976 | try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset); |
| 7001 | const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, ""); | 6977 | const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, ""); |
| 7002 | const elem_llvm_ty = try o.lowerType(field_ty); | 6978 | const elem_llvm_ty = try o.lowerType(pt, field_ty); |
| 7003 | if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) { | 6979 | 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))); | 6980 | const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu))); |
| 7005 | const truncated_int = | 6981 | const truncated_int = |
| ... | @@ -7021,7 +6997,7 @@ pub const FuncGen = struct { | ... | @@ -7021,7 +6997,7 @@ pub const FuncGen = struct { |
| 7021 | .@"union" => { | 6997 | .@"union" => { |
| 7022 | assert(struct_ty.containerLayout(zcu) == .@"packed"); | 6998 | assert(struct_ty.containerLayout(zcu) == .@"packed"); |
| 7023 | const containing_int = struct_llvm_val; | 6999 | const containing_int = struct_llvm_val; |
| 7024 | const elem_llvm_ty = try o.lowerType(field_ty); | 7000 | const elem_llvm_ty = try o.lowerType(pt, field_ty); |
| 7025 | if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) { | 7001 | 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))); | 7002 | const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu))); |
| 7027 | const truncated_int = | 7003 | const truncated_int = |
| ... | @@ -7043,7 +7019,7 @@ pub const FuncGen = struct { | ... | @@ -7043,7 +7019,7 @@ pub const FuncGen = struct { |
| 7043 | .@"struct" => { | 7019 | .@"struct" => { |
| 7044 | const layout = struct_ty.containerLayout(zcu); | 7020 | const layout = struct_ty.containerLayout(zcu); |
| 7045 | assert(layout != .@"packed"); | 7021 | assert(layout != .@"packed"); |
| 7046 | const struct_llvm_ty = try o.lowerType(struct_ty); | 7022 | const struct_llvm_ty = try o.lowerType(pt, struct_ty); |
| 7047 | const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?; | 7023 | const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?; |
| 7048 | const field_ptr = | 7024 | const field_ptr = |
| 7049 | try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, ""); | 7025 | try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, ""); |
| ... | @@ -7064,7 +7040,7 @@ pub const FuncGen = struct { | ... | @@ -7064,7 +7040,7 @@ pub const FuncGen = struct { |
| 7064 | } | 7040 | } |
| 7065 | }, | 7041 | }, |
| 7066 | .@"union" => { | 7042 | .@"union" => { |
| 7067 | const union_llvm_ty = try o.lowerType(struct_ty); | 7043 | const union_llvm_ty = try o.lowerType(pt, struct_ty); |
| 7068 | const layout = struct_ty.unionGetLayout(zcu); | 7044 | const layout = struct_ty.unionGetLayout(zcu); |
| 7069 | const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)); | 7045 | const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)); |
| 7070 | const field_ptr = | 7046 | const field_ptr = |
| ... | @@ -7083,7 +7059,7 @@ pub const FuncGen = struct { | ... | @@ -7083,7 +7059,7 @@ pub const FuncGen = struct { |
| 7083 | | 7059 | |
| 7084 | fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 7060 | fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7085 | const o = self.ng.object; | 7061 | const o = self.ng.object; |
| 7086 | const pt = o.pt; | 7062 | const pt = self.ng.pt; |
| 7087 | const zcu = pt.zcu; | 7063 | const zcu = pt.zcu; |
| 7088 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 7064 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 7089 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; | 7065 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| ... | @@ -7094,8 +7070,8 @@ pub const FuncGen = struct { | ... | @@ -7094,8 +7070,8 @@ pub const FuncGen = struct { |
| 7094 | const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu); | 7070 | const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu); |
| 7095 | if (field_offset == 0) return field_ptr; | 7071 | if (field_offset == 0) return field_ptr; |
| 7096 | | 7072 | |
| 7097 | const res_ty = try o.lowerType(ty_pl.ty.toType()); | 7073 | const res_ty = try o.lowerType(pt, ty_pl.ty.toType()); |
| 7098 | const llvm_usize = try o.lowerType(Type.usize); | 7074 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 7099 | | 7075 | |
| 7100 | const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, ""); | 7076 | const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, ""); |
| 7101 | const base_ptr_int = try self.wip.bin( | 7077 | const base_ptr_int = try self.wip.bin( |
| ... | @@ -7151,7 +7127,8 @@ pub const FuncGen = struct { | ... | @@ -7151,7 +7127,8 @@ pub const FuncGen = struct { |
| 7151 | | 7127 | |
| 7152 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 7128 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7153 | const o = self.ng.object; | 7129 | const o = self.ng.object; |
| 7154 | const zcu = o.pt.zcu; | 7130 | const pt = self.ng.pt; |
| | 7131 | const zcu = pt.zcu; |
| 7155 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 7132 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 7156 | const operand = try self.resolveInst(pl_op.operand); | 7133 | const operand = try self.resolveInst(pl_op.operand); |
| 7157 | const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload); | 7134 | const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload); |
| ... | @@ -7162,7 +7139,7 @@ pub const FuncGen = struct { | ... | @@ -7162,7 +7139,7 @@ pub const FuncGen = struct { |
| 7162 | self.file, | 7139 | self.file, |
| 7163 | self.scope, | 7140 | self.scope, |
| 7164 | self.prev_dbg_line, | 7141 | self.prev_dbg_line, |
| 7165 | try o.lowerDebugType(ptr_ty.childType(zcu)), | 7142 | try o.lowerDebugType(pt, ptr_ty.childType(zcu)), |
| 7166 | ); | 7143 | ); |
| 7167 | | 7144 | |
| 7168 | _ = try self.wip.callIntrinsic( | 7145 | _ = try self.wip.callIntrinsic( |
| ... | @@ -7183,6 +7160,7 @@ pub const FuncGen = struct { | ... | @@ -7183,6 +7160,7 @@ pub const FuncGen = struct { |
| 7183 | | 7160 | |
| 7184 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index, is_arg: bool) !Builder.Value { | 7161 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index, is_arg: bool) !Builder.Value { |
| 7185 | const o = self.ng.object; | 7162 | const o = self.ng.object; |
| | 7163 | const pt = self.ng.pt; |
| 7186 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 7164 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 7187 | const operand = try self.resolveInst(pl_op.operand); | 7165 | const operand = try self.resolveInst(pl_op.operand); |
| 7188 | const operand_ty = self.typeOf(pl_op.operand); | 7166 | const operand_ty = self.typeOf(pl_op.operand); |
| ... | @@ -7193,7 +7171,7 @@ pub const FuncGen = struct { | ... | @@ -7193,7 +7171,7 @@ pub const FuncGen = struct { |
| 7193 | self.file, | 7171 | self.file, |
| 7194 | self.scope, | 7172 | self.scope, |
| 7195 | self.prev_dbg_line, | 7173 | self.prev_dbg_line, |
| 7196 | try o.lowerDebugType(operand_ty), | 7174 | try o.lowerDebugType(pt, operand_ty), |
| 7197 | arg_no: { | 7175 | arg_no: { |
| 7198 | self.arg_inline_index += 1; | 7176 | self.arg_inline_index += 1; |
| 7199 | break :arg_no self.arg_inline_index; | 7177 | break :arg_no self.arg_inline_index; |
| ... | @@ -7203,10 +7181,10 @@ pub const FuncGen = struct { | ... | @@ -7203,10 +7181,10 @@ pub const FuncGen = struct { |
| 7203 | self.file, | 7181 | self.file, |
| 7204 | self.scope, | 7182 | self.scope, |
| 7205 | self.prev_dbg_line, | 7183 | self.prev_dbg_line, |
| 7206 | try o.lowerDebugType(operand_ty), | 7184 | try o.lowerDebugType(pt, operand_ty), |
| 7207 | ); | 7185 | ); |
| 7208 | | 7186 | |
| 7209 | const zcu = o.pt.zcu; | 7187 | const zcu = pt.zcu; |
| 7210 | const owner_mod = self.ng.ownerModule(); | 7188 | const owner_mod = self.ng.ownerModule(); |
| 7211 | if (isByRef(operand_ty, zcu)) { | 7189 | if (isByRef(operand_ty, zcu)) { |
| 7212 | _ = try self.wip.callIntrinsic( | 7190 | _ = try self.wip.callIntrinsic( |
| ... | @@ -7296,7 +7274,7 @@ pub const FuncGen = struct { | ... | @@ -7296,7 +7274,7 @@ pub const FuncGen = struct { |
| 7296 | // This stores whether we need to add an elementtype attribute and | 7274 | // This stores whether we need to add an elementtype attribute and |
| 7297 | // if so, the element type itself. | 7275 | // if so, the element type itself. |
| 7298 | const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count); | 7276 | const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count); |
| 7299 | const pt = o.pt; | 7277 | const pt = self.ng.pt; |
| 7300 | const zcu = pt.zcu; | 7278 | const zcu = pt.zcu; |
| 7301 | const target = zcu.getTarget(); | 7279 | const target = zcu.getTarget(); |
| 7302 | | 7280 | |
| ... | @@ -7326,7 +7304,7 @@ pub const FuncGen = struct { | ... | @@ -7326,7 +7304,7 @@ pub const FuncGen = struct { |
| 7326 | const output_inst = try self.resolveInst(output); | 7304 | const output_inst = try self.resolveInst(output); |
| 7327 | const output_ty = self.typeOf(output); | 7305 | const output_ty = self.typeOf(output); |
| 7328 | assert(output_ty.zigTypeTag(zcu) == .pointer); | 7306 | assert(output_ty.zigTypeTag(zcu) == .pointer); |
| 7329 | const elem_llvm_ty = try o.lowerPtrElemTy(output_ty.childType(zcu)); | 7307 | const elem_llvm_ty = try o.lowerPtrElemTy(pt, output_ty.childType(zcu)); |
| 7330 | | 7308 | |
| 7331 | switch (constraint[0]) { | 7309 | switch (constraint[0]) { |
| 7332 | '=' => {}, | 7310 | '=' => {}, |
| ... | @@ -7364,7 +7342,7 @@ pub const FuncGen = struct { | ... | @@ -7364,7 +7342,7 @@ pub const FuncGen = struct { |
| 7364 | is_indirect.* = false; | 7342 | is_indirect.* = false; |
| 7365 | | 7343 | |
| 7366 | const ret_ty = self.typeOfIndex(inst); | 7344 | const ret_ty = self.typeOfIndex(inst); |
| 7367 | llvm_ret_types[llvm_ret_i] = try o.lowerType(ret_ty); | 7345 | llvm_ret_types[llvm_ret_i] = try o.lowerType(pt, ret_ty); |
| 7368 | llvm_ret_i += 1; | 7346 | llvm_ret_i += 1; |
| 7369 | } | 7347 | } |
| 7370 | | 7348 | |
| ... | @@ -7406,7 +7384,7 @@ pub const FuncGen = struct { | ... | @@ -7406,7 +7384,7 @@ pub const FuncGen = struct { |
| 7406 | llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip); | 7384 | llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip); |
| 7407 | } else { | 7385 | } else { |
| 7408 | const alignment = arg_ty.abiAlignment(zcu).toLlvm(); | 7386 | const alignment = arg_ty.abiAlignment(zcu).toLlvm(); |
| 7409 | const arg_llvm_ty = try o.lowerType(arg_ty); | 7387 | const arg_llvm_ty = try o.lowerType(pt, arg_ty); |
| 7410 | const load_inst = | 7388 | const load_inst = |
| 7411 | try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, ""); | 7389 | try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, ""); |
| 7412 | llvm_param_values[llvm_param_i] = load_inst; | 7390 | llvm_param_values[llvm_param_i] = load_inst; |
| ... | @@ -7447,7 +7425,7 @@ pub const FuncGen = struct { | ... | @@ -7447,7 +7425,7 @@ pub const FuncGen = struct { |
| 7447 | llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: { | 7425 | llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: { |
| 7448 | if (!is_by_ref) self.maybeMarkAllowZeroAccess(arg_ty.ptrInfo(zcu)); | 7426 | if (!is_by_ref) self.maybeMarkAllowZeroAccess(arg_ty.ptrInfo(zcu)); |
| 7449 | | 7427 | |
| 7450 | break :blk try o.lowerPtrElemTy(if (is_by_ref) arg_ty else arg_ty.childType(zcu)); | 7428 | break :blk try o.lowerPtrElemTy(pt, if (is_by_ref) arg_ty else arg_ty.childType(zcu)); |
| 7451 | } else .none; | 7429 | } else .none; |
| 7452 | | 7430 | |
| 7453 | llvm_param_i += 1; | 7431 | llvm_param_i += 1; |
| ... | @@ -7465,7 +7443,7 @@ pub const FuncGen = struct { | ... | @@ -7465,7 +7443,7 @@ pub const FuncGen = struct { |
| 7465 | if (constraint[0] != '+') continue; | 7443 | if (constraint[0] != '+') continue; |
| 7466 | | 7444 | |
| 7467 | const rw_ty = self.typeOf(output); | 7445 | const rw_ty = self.typeOf(output); |
| 7468 | const llvm_elem_ty = try o.lowerPtrElemTy(rw_ty.childType(zcu)); | 7446 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, rw_ty.childType(zcu)); |
| 7469 | if (is_indirect) { | 7447 | if (is_indirect) { |
| 7470 | llvm_param_values[llvm_param_i] = llvm_rw_val; | 7448 | llvm_param_values[llvm_param_i] = llvm_rw_val; |
| 7471 | llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip); | 7449 | llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip); |
| ... | @@ -7663,13 +7641,13 @@ pub const FuncGen = struct { | ... | @@ -7663,13 +7641,13 @@ pub const FuncGen = struct { |
| 7663 | cond: Builder.IntegerCondition, | 7641 | cond: Builder.IntegerCondition, |
| 7664 | ) !Builder.Value { | 7642 | ) !Builder.Value { |
| 7665 | const o = self.ng.object; | 7643 | const o = self.ng.object; |
| 7666 | const pt = o.pt; | 7644 | const pt = self.ng.pt; |
| 7667 | const zcu = pt.zcu; | 7645 | const zcu = pt.zcu; |
| 7668 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | 7646 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 7669 | const operand = try self.resolveInst(un_op); | 7647 | const operand = try self.resolveInst(un_op); |
| 7670 | const operand_ty = self.typeOf(un_op); | 7648 | const operand_ty = self.typeOf(un_op); |
| 7671 | const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; | 7649 | const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; |
| 7672 | const optional_llvm_ty = try o.lowerType(optional_ty); | 7650 | const optional_llvm_ty = try o.lowerType(pt, optional_ty); |
| 7673 | const payload_ty = optional_ty.optionalChild(zcu); | 7651 | const payload_ty = optional_ty.optionalChild(zcu); |
| 7674 | | 7652 | |
| 7675 | const access_kind: Builder.MemoryAccessKind = | 7653 | const access_kind: Builder.MemoryAccessKind = |
| ... | @@ -7714,14 +7692,14 @@ pub const FuncGen = struct { | ... | @@ -7714,14 +7692,14 @@ pub const FuncGen = struct { |
| 7714 | operand_is_ptr: bool, | 7692 | operand_is_ptr: bool, |
| 7715 | ) !Builder.Value { | 7693 | ) !Builder.Value { |
| 7716 | const o = self.ng.object; | 7694 | const o = self.ng.object; |
| 7717 | const pt = o.pt; | 7695 | const pt = self.ng.pt; |
| 7718 | const zcu = pt.zcu; | 7696 | const zcu = pt.zcu; |
| 7719 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | 7697 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 7720 | const operand = try self.resolveInst(un_op); | 7698 | const operand = try self.resolveInst(un_op); |
| 7721 | const operand_ty = self.typeOf(un_op); | 7699 | const operand_ty = self.typeOf(un_op); |
| 7722 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; | 7700 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; |
| 7723 | const payload_ty = err_union_ty.errorUnionPayload(zcu); | 7701 | const payload_ty = err_union_ty.errorUnionPayload(zcu); |
| 7724 | const error_type = try o.errorIntType(); | 7702 | const error_type = try o.errorIntType(pt); |
| 7725 | const zero = try o.builder.intValue(error_type, 0); | 7703 | const zero = try o.builder.intValue(error_type, 0); |
| 7726 | | 7704 | |
| 7727 | const access_kind: Builder.MemoryAccessKind = | 7705 | const access_kind: Builder.MemoryAccessKind = |
| ... | @@ -7740,7 +7718,7 @@ pub const FuncGen = struct { | ... | @@ -7740,7 +7718,7 @@ pub const FuncGen = struct { |
| 7740 | | 7718 | |
| 7741 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { | 7719 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 7742 | const loaded = if (operand_is_ptr) | 7720 | const loaded = if (operand_is_ptr) |
| 7743 | try self.wip.load(access_kind, try o.lowerType(err_union_ty), operand, .default, "") | 7721 | try self.wip.load(access_kind, try o.lowerType(pt, err_union_ty), operand, .default, "") |
| 7744 | else | 7722 | else |
| 7745 | operand; | 7723 | operand; |
| 7746 | return self.wip.icmp(cond, loaded, zero, ""); | 7724 | return self.wip.icmp(cond, loaded, zero, ""); |
| ... | @@ -7749,7 +7727,7 @@ pub const FuncGen = struct { | ... | @@ -7749,7 +7727,7 @@ pub const FuncGen = struct { |
| 7749 | const err_field_index = try errUnionErrorOffset(payload_ty, pt); | 7727 | const err_field_index = try errUnionErrorOffset(payload_ty, pt); |
| 7750 | | 7728 | |
| 7751 | const loaded = if (operand_is_ptr or isByRef(err_union_ty, zcu)) loaded: { | 7729 | const loaded = if (operand_is_ptr or isByRef(err_union_ty, zcu)) loaded: { |
| 7752 | const err_union_llvm_ty = try o.lowerType(err_union_ty); | 7730 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 7753 | const err_field_ptr = | 7731 | const err_field_ptr = |
| 7754 | try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, ""); | 7732 | 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, ""); | 7733 | break :loaded try self.wip.load(access_kind, error_type, err_field_ptr, .default, ""); |
| ... | @@ -7759,7 +7737,7 @@ pub const FuncGen = struct { | ... | @@ -7759,7 +7737,7 @@ pub const FuncGen = struct { |
| 7759 | | 7737 | |
| 7760 | fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 7738 | fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7761 | const o = self.ng.object; | 7739 | const o = self.ng.object; |
| 7762 | const pt = o.pt; | 7740 | const pt = self.ng.pt; |
| 7763 | const zcu = pt.zcu; | 7741 | const zcu = pt.zcu; |
| 7764 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 7742 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7765 | const operand = try self.resolveInst(ty_op.operand); | 7743 | const operand = try self.resolveInst(ty_op.operand); |
| ... | @@ -7774,14 +7752,14 @@ pub const FuncGen = struct { | ... | @@ -7774,14 +7752,14 @@ pub const FuncGen = struct { |
| 7774 | // The payload and the optional are the same value. | 7752 | // The payload and the optional are the same value. |
| 7775 | return operand; | 7753 | return operand; |
| 7776 | } | 7754 | } |
| 7777 | return self.wip.gepStruct(try o.lowerType(optional_ty), operand, 0, ""); | 7755 | return self.wip.gepStruct(try o.lowerType(pt, optional_ty), operand, 0, ""); |
| 7778 | } | 7756 | } |
| 7779 | | 7757 | |
| 7780 | fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 7758 | fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7781 | comptime assert(optional_layout_version == 3); | 7759 | comptime assert(optional_layout_version == 3); |
| 7782 | | 7760 | |
| 7783 | const o = self.ng.object; | 7761 | const o = self.ng.object; |
| 7784 | const pt = o.pt; | 7762 | const pt = self.ng.pt; |
| 7785 | const zcu = pt.zcu; | 7763 | const zcu = pt.zcu; |
| 7786 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 7764 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7787 | const operand = try self.resolveInst(ty_op.operand); | 7765 | const operand = try self.resolveInst(ty_op.operand); |
| ... | @@ -7807,7 +7785,7 @@ pub const FuncGen = struct { | ... | @@ -7807,7 +7785,7 @@ pub const FuncGen = struct { |
| 7807 | } | 7785 | } |
| 7808 | | 7786 | |
| 7809 | // First set the non-null bit. | 7787 | // First set the non-null bit. |
| 7810 | const optional_llvm_ty = try o.lowerType(optional_ty); | 7788 | const optional_llvm_ty = try o.lowerType(pt, optional_ty); |
| 7811 | const non_null_ptr = try self.wip.gepStruct(optional_llvm_ty, operand, 1, ""); | 7789 | const non_null_ptr = try self.wip.gepStruct(optional_llvm_ty, operand, 1, ""); |
| 7812 | | 7790 | |
| 7813 | self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu)); | 7791 | self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu)); |
| ... | @@ -7823,7 +7801,7 @@ pub const FuncGen = struct { | ... | @@ -7823,7 +7801,7 @@ pub const FuncGen = struct { |
| 7823 | | 7801 | |
| 7824 | fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { | 7802 | fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 7825 | const o = self.ng.object; | 7803 | const o = self.ng.object; |
| 7826 | const pt = o.pt; | 7804 | const pt = self.ng.pt; |
| 7827 | const zcu = pt.zcu; | 7805 | const zcu = pt.zcu; |
| 7828 | const inst = body_tail[0]; | 7806 | const inst = body_tail[0]; |
| 7829 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 7807 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | @@ -7837,7 +7815,7 @@ pub const FuncGen = struct { | ... | @@ -7837,7 +7815,7 @@ pub const FuncGen = struct { |
| 7837 | return operand; | 7815 | return operand; |
| 7838 | } | 7816 | } |
| 7839 | | 7817 | |
| 7840 | const opt_llvm_ty = try o.lowerType(optional_ty); | 7818 | 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; | 7819 | 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); | 7820 | return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load); |
| 7843 | } | 7821 | } |
| ... | @@ -7848,7 +7826,7 @@ pub const FuncGen = struct { | ... | @@ -7848,7 +7826,7 @@ pub const FuncGen = struct { |
| 7848 | operand_is_ptr: bool, | 7826 | operand_is_ptr: bool, |
| 7849 | ) !Builder.Value { | 7827 | ) !Builder.Value { |
| 7850 | const o = self.ng.object; | 7828 | const o = self.ng.object; |
| 7851 | const pt = o.pt; | 7829 | const pt = self.ng.pt; |
| 7852 | const zcu = pt.zcu; | 7830 | const zcu = pt.zcu; |
| 7853 | const inst = body_tail[0]; | 7831 | const inst = body_tail[0]; |
| 7854 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 7832 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | @@ -7862,7 +7840,7 @@ pub const FuncGen = struct { | ... | @@ -7862,7 +7840,7 @@ pub const FuncGen = struct { |
| 7862 | return if (operand_is_ptr) operand else .none; | 7840 | return if (operand_is_ptr) operand else .none; |
| 7863 | } | 7841 | } |
| 7864 | const offset = try errUnionPayloadOffset(payload_ty, pt); | 7842 | const offset = try errUnionPayloadOffset(payload_ty, pt); |
| 7865 | const err_union_llvm_ty = try o.lowerType(err_union_ty); | 7843 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 7866 | if (operand_is_ptr) { | 7844 | if (operand_is_ptr) { |
| 7867 | return self.wip.gepStruct(err_union_llvm_ty, operand, offset, ""); | 7845 | return self.wip.gepStruct(err_union_llvm_ty, operand, offset, ""); |
| 7868 | } else if (isByRef(err_union_ty, zcu)) { | 7846 | } else if (isByRef(err_union_ty, zcu)) { |
| ... | @@ -7884,12 +7862,12 @@ pub const FuncGen = struct { | ... | @@ -7884,12 +7862,12 @@ pub const FuncGen = struct { |
| 7884 | operand_is_ptr: bool, | 7862 | operand_is_ptr: bool, |
| 7885 | ) !Builder.Value { | 7863 | ) !Builder.Value { |
| 7886 | const o = self.ng.object; | 7864 | const o = self.ng.object; |
| 7887 | const pt = o.pt; | 7865 | const pt = self.ng.pt; |
| 7888 | const zcu = pt.zcu; | 7866 | const zcu = pt.zcu; |
| 7889 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 7867 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7890 | const operand = try self.resolveInst(ty_op.operand); | 7868 | const operand = try self.resolveInst(ty_op.operand); |
| 7891 | const operand_ty = self.typeOf(ty_op.operand); | 7869 | const operand_ty = self.typeOf(ty_op.operand); |
| 7892 | const error_type = try o.errorIntType(); | 7870 | const error_type = try o.errorIntType(pt); |
| 7893 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; | 7871 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; |
| 7894 | if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) { | 7872 | if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) { |
| 7895 | if (operand_is_ptr) { | 7873 | if (operand_is_ptr) { |
| ... | @@ -7916,7 +7894,7 @@ pub const FuncGen = struct { | ... | @@ -7916,7 +7894,7 @@ pub const FuncGen = struct { |
| 7916 | if (operand_is_ptr or isByRef(err_union_ty, zcu)) { | 7894 | if (operand_is_ptr or isByRef(err_union_ty, zcu)) { |
| 7917 | if (operand_is_ptr) self.maybeMarkAllowZeroAccess(operand_ty.ptrInfo(zcu)); | 7895 | if (operand_is_ptr) self.maybeMarkAllowZeroAccess(operand_ty.ptrInfo(zcu)); |
| 7918 | | 7896 | |
| 7919 | const err_union_llvm_ty = try o.lowerType(err_union_ty); | 7897 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 7920 | const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, ""); | 7898 | 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, ""); | 7899 | return self.wip.load(access_kind, error_type, err_field_ptr, .default, ""); |
| 7922 | } | 7900 | } |
| ... | @@ -7926,7 +7904,7 @@ pub const FuncGen = struct { | ... | @@ -7926,7 +7904,7 @@ pub const FuncGen = struct { |
| 7926 | | 7904 | |
| 7927 | fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 7905 | fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7928 | const o = self.ng.object; | 7906 | const o = self.ng.object; |
| 7929 | const pt = o.pt; | 7907 | const pt = self.ng.pt; |
| 7930 | const zcu = pt.zcu; | 7908 | const zcu = pt.zcu; |
| 7931 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 7909 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7932 | const operand = try self.resolveInst(ty_op.operand); | 7910 | const operand = try self.resolveInst(ty_op.operand); |
| ... | @@ -7934,7 +7912,7 @@ pub const FuncGen = struct { | ... | @@ -7934,7 +7912,7 @@ pub const FuncGen = struct { |
| 7934 | const err_union_ty = err_union_ptr_ty.childType(zcu); | 7912 | const err_union_ty = err_union_ptr_ty.childType(zcu); |
| 7935 | | 7913 | |
| 7936 | const payload_ty = err_union_ty.errorUnionPayload(zcu); | 7914 | const payload_ty = err_union_ty.errorUnionPayload(zcu); |
| 7937 | const non_error_val = try o.builder.intValue(try o.errorIntType(), 0); | 7915 | const non_error_val = try o.builder.intValue(try o.errorIntType(pt), 0); |
| 7938 | | 7916 | |
| 7939 | const access_kind: Builder.MemoryAccessKind = | 7917 | const access_kind: Builder.MemoryAccessKind = |
| 7940 | if (err_union_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; | 7918 | if (err_union_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; |
| ... | @@ -7945,7 +7923,7 @@ pub const FuncGen = struct { | ... | @@ -7945,7 +7923,7 @@ pub const FuncGen = struct { |
| 7945 | _ = try self.wip.store(access_kind, non_error_val, operand, .default); | 7923 | _ = try self.wip.store(access_kind, non_error_val, operand, .default); |
| 7946 | return operand; | 7924 | return operand; |
| 7947 | } | 7925 | } |
| 7948 | const err_union_llvm_ty = try o.lowerType(err_union_ty); | 7926 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 7949 | { | 7927 | { |
| 7950 | self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu)); | 7928 | self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu)); |
| 7951 | | 7929 | |
| ... | @@ -7976,14 +7954,14 @@ pub const FuncGen = struct { | ... | @@ -7976,14 +7954,14 @@ pub const FuncGen = struct { |
| 7976 | | 7954 | |
| 7977 | fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 7955 | fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7978 | const o = self.ng.object; | 7956 | const o = self.ng.object; |
| 7979 | const pt = o.pt; | 7957 | const pt = self.ng.pt; |
| 7980 | const zcu = pt.zcu; | 7958 | const zcu = pt.zcu; |
| 7981 | | 7959 | |
| 7982 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 7960 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 7983 | const struct_ty = ty_pl.ty.toType(); | 7961 | const struct_ty = ty_pl.ty.toType(); |
| 7984 | const field_index = ty_pl.payload; | 7962 | const field_index = ty_pl.payload; |
| 7985 | | 7963 | |
| 7986 | const struct_llvm_ty = try o.lowerType(struct_ty); | 7964 | const struct_llvm_ty = try o.lowerType(pt, struct_ty); |
| 7987 | const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?; | 7965 | const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?; |
| 7988 | assert(self.err_ret_trace != .none); | 7966 | assert(self.err_ret_trace != .none); |
| 7989 | const field_ptr = | 7967 | const field_ptr = |
| ... | @@ -8022,7 +8000,7 @@ pub const FuncGen = struct { | ... | @@ -8022,7 +8000,7 @@ pub const FuncGen = struct { |
| 8022 | | 8000 | |
| 8023 | fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { | 8001 | fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 8024 | const o = self.ng.object; | 8002 | const o = self.ng.object; |
| 8025 | const pt = o.pt; | 8003 | const pt = self.ng.pt; |
| 8026 | const zcu = pt.zcu; | 8004 | const zcu = pt.zcu; |
| 8027 | const inst = body_tail[0]; | 8005 | const inst = body_tail[0]; |
| 8028 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 8006 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | @@ -8033,7 +8011,7 @@ pub const FuncGen = struct { | ... | @@ -8033,7 +8011,7 @@ pub const FuncGen = struct { |
| 8033 | const operand = try self.resolveInst(ty_op.operand); | 8011 | const operand = try self.resolveInst(ty_op.operand); |
| 8034 | const optional_ty = self.typeOfIndex(inst); | 8012 | const optional_ty = self.typeOfIndex(inst); |
| 8035 | if (optional_ty.optionalReprIsPayload(zcu)) return operand; | 8013 | if (optional_ty.optionalReprIsPayload(zcu)) return operand; |
| 8036 | const llvm_optional_ty = try o.lowerType(optional_ty); | 8014 | const llvm_optional_ty = try o.lowerType(pt, optional_ty); |
| 8037 | if (isByRef(optional_ty, zcu)) { | 8015 | if (isByRef(optional_ty, zcu)) { |
| 8038 | const directReturn = self.isNextRet(body_tail); | 8016 | const directReturn = self.isNextRet(body_tail); |
| 8039 | const optional_ptr = if (directReturn) | 8017 | const optional_ptr = if (directReturn) |
| ... | @@ -8056,7 +8034,7 @@ pub const FuncGen = struct { | ... | @@ -8056,7 +8034,7 @@ pub const FuncGen = struct { |
| 8056 | | 8034 | |
| 8057 | fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { | 8035 | fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 8058 | const o = self.ng.object; | 8036 | const o = self.ng.object; |
| 8059 | const pt = o.pt; | 8037 | const pt = self.ng.pt; |
| 8060 | const zcu = pt.zcu; | 8038 | const zcu = pt.zcu; |
| 8061 | const inst = body_tail[0]; | 8039 | const inst = body_tail[0]; |
| 8062 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 8040 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | @@ -8066,8 +8044,8 @@ pub const FuncGen = struct { | ... | @@ -8066,8 +8044,8 @@ pub const FuncGen = struct { |
| 8066 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { | 8044 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 8067 | return operand; | 8045 | return operand; |
| 8068 | } | 8046 | } |
| 8069 | const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0); | 8047 | 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); | 8048 | const err_un_llvm_ty = try o.lowerType(pt, err_un_ty); |
| 8071 | | 8049 | |
| 8072 | const payload_offset = try errUnionPayloadOffset(payload_ty, pt); | 8050 | const payload_offset = try errUnionPayloadOffset(payload_ty, pt); |
| 8073 | const error_offset = try errUnionErrorOffset(payload_ty, pt); | 8051 | const error_offset = try errUnionErrorOffset(payload_ty, pt); |
| ... | @@ -8098,7 +8076,7 @@ pub const FuncGen = struct { | ... | @@ -8098,7 +8076,7 @@ pub const FuncGen = struct { |
| 8098 | | 8076 | |
| 8099 | fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { | 8077 | fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 8100 | const o = self.ng.object; | 8078 | const o = self.ng.object; |
| 8101 | const pt = o.pt; | 8079 | const pt = self.ng.pt; |
| 8102 | const zcu = pt.zcu; | 8080 | const zcu = pt.zcu; |
| 8103 | const inst = body_tail[0]; | 8081 | const inst = body_tail[0]; |
| 8104 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 8082 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | @@ -8106,7 +8084,7 @@ pub const FuncGen = struct { | ... | @@ -8106,7 +8084,7 @@ pub const FuncGen = struct { |
| 8106 | const payload_ty = err_un_ty.errorUnionPayload(zcu); | 8084 | const payload_ty = err_un_ty.errorUnionPayload(zcu); |
| 8107 | const operand = try self.resolveInst(ty_op.operand); | 8085 | const operand = try self.resolveInst(ty_op.operand); |
| 8108 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return operand; | 8086 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return operand; |
| 8109 | const err_un_llvm_ty = try o.lowerType(err_un_ty); | 8087 | const err_un_llvm_ty = try o.lowerType(pt, err_un_ty); |
| 8110 | | 8088 | |
| 8111 | const payload_offset = try errUnionPayloadOffset(payload_ty, pt); | 8089 | const payload_offset = try errUnionPayloadOffset(payload_ty, pt); |
| 8112 | const error_offset = try errUnionErrorOffset(payload_ty, pt); | 8090 | const error_offset = try errUnionErrorOffset(payload_ty, pt); |
| ... | @@ -8139,9 +8117,10 @@ pub const FuncGen = struct { | ... | @@ -8139,9 +8117,10 @@ pub const FuncGen = struct { |
| 8139 | | 8117 | |
| 8140 | fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8118 | fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8141 | const o = self.ng.object; | 8119 | const o = self.ng.object; |
| | 8120 | const pt = self.ng.pt; |
| 8142 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 8121 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 8143 | const index = pl_op.payload; | 8122 | const index = pl_op.payload; |
| 8144 | const llvm_usize = try o.lowerType(Type.usize); | 8123 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 8145 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{ | 8124 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{ |
| 8146 | try o.builder.intValue(.i32, index), | 8125 | try o.builder.intValue(.i32, index), |
| 8147 | }, ""); | 8126 | }, ""); |
| ... | @@ -8149,9 +8128,10 @@ pub const FuncGen = struct { | ... | @@ -8149,9 +8128,10 @@ pub const FuncGen = struct { |
| 8149 | | 8128 | |
| 8150 | fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8129 | fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8151 | const o = self.ng.object; | 8130 | const o = self.ng.object; |
| | 8131 | const pt = self.ng.pt; |
| 8152 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 8132 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 8153 | const index = pl_op.payload; | 8133 | const index = pl_op.payload; |
| 8154 | const llvm_isize = try o.lowerType(Type.isize); | 8134 | const llvm_isize = try o.lowerType(pt, Type.isize); |
| 8155 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{ | 8135 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{ |
| 8156 | try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand), | 8136 | try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand), |
| 8157 | }, ""); | 8137 | }, ""); |
| ... | @@ -8159,7 +8139,7 @@ pub const FuncGen = struct { | ... | @@ -8159,7 +8139,7 @@ pub const FuncGen = struct { |
| 8159 | | 8139 | |
| 8160 | fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8140 | fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8161 | const o = self.ng.object; | 8141 | const o = self.ng.object; |
| 8162 | const pt = o.pt; | 8142 | const pt = self.ng.pt; |
| 8163 | const zcu = pt.zcu; | 8143 | const zcu = pt.zcu; |
| 8164 | const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem; | 8144 | const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem; |
| 8165 | const extra = self.air.extraData(Air.Bin, data.payload).data; | 8145 | const extra = self.air.extraData(Air.Bin, data.payload).data; |
| ... | @@ -8175,7 +8155,7 @@ pub const FuncGen = struct { | ... | @@ -8175,7 +8155,7 @@ pub const FuncGen = struct { |
| 8175 | // https://github.com/ziglang/zig/issues/18652#issuecomment-2452844908 | 8155 | // https://github.com/ziglang/zig/issues/18652#issuecomment-2452844908 |
| 8176 | const access_kind: Builder.MemoryAccessKind = | 8156 | const access_kind: Builder.MemoryAccessKind = |
| 8177 | if (vector_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; | 8157 | if (vector_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; |
| 8178 | const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(zcu)); | 8158 | const elem_llvm_ty = try o.lowerType(pt, vector_ptr_ty.childType(zcu)); |
| 8179 | const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm(); | 8159 | const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 8180 | const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, ""); | 8160 | const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, ""); |
| 8181 | | 8161 | |
| ... | @@ -8186,14 +8166,16 @@ pub const FuncGen = struct { | ... | @@ -8186,14 +8166,16 @@ pub const FuncGen = struct { |
| 8186 | | 8166 | |
| 8187 | fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8167 | fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8188 | const o = fg.ng.object; | 8168 | const o = fg.ng.object; |
| | 8169 | const pt = fg.ng.pt; |
| 8189 | const ty_nav = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav; | 8170 | const ty_nav = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav; |
| 8190 | const llvm_ptr_const = try o.lowerNavRefValue(ty_nav.nav); | 8171 | const llvm_ptr_const = try o.lowerNavRefValue(pt, ty_nav.nav); |
| 8191 | return llvm_ptr_const.toValue(); | 8172 | return llvm_ptr_const.toValue(); |
| 8192 | } | 8173 | } |
| 8193 | | 8174 | |
| 8194 | fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8175 | fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8195 | const o = self.ng.object; | 8176 | const o = self.ng.object; |
| 8196 | const zcu = o.pt.zcu; | 8177 | const pt = self.ng.pt; |
| | 8178 | const zcu = pt.zcu; |
| 8197 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 8179 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8198 | const lhs = try self.resolveInst(bin_op.lhs); | 8180 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8199 | const rhs = try self.resolveInst(bin_op.rhs); | 8181 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8205,7 +8187,7 @@ pub const FuncGen = struct { | ... | @@ -8205,7 +8187,7 @@ pub const FuncGen = struct { |
| 8205 | .normal, | 8187 | .normal, |
| 8206 | .none, | 8188 | .none, |
| 8207 | if (scalar_ty.isSignedInt(zcu)) .smin else .umin, | 8189 | if (scalar_ty.isSignedInt(zcu)) .smin else .umin, |
| 8208 | &.{try o.lowerType(inst_ty)}, | 8190 | &.{try o.lowerType(pt, inst_ty)}, |
| 8209 | &.{ lhs, rhs }, | 8191 | &.{ lhs, rhs }, |
| 8210 | "", | 8192 | "", |
| 8211 | ); | 8193 | ); |
| ... | @@ -8213,7 +8195,8 @@ pub const FuncGen = struct { | ... | @@ -8213,7 +8195,8 @@ pub const FuncGen = struct { |
| 8213 | | 8195 | |
| 8214 | fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8196 | fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8215 | const o = self.ng.object; | 8197 | const o = self.ng.object; |
| 8216 | const zcu = o.pt.zcu; | 8198 | const pt = self.ng.pt; |
| | 8199 | const zcu = pt.zcu; |
| 8217 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 8200 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8218 | const lhs = try self.resolveInst(bin_op.lhs); | 8201 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8219 | const rhs = try self.resolveInst(bin_op.rhs); | 8202 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8225,7 +8208,7 @@ pub const FuncGen = struct { | ... | @@ -8225,7 +8208,7 @@ pub const FuncGen = struct { |
| 8225 | .normal, | 8208 | .normal, |
| 8226 | .none, | 8209 | .none, |
| 8227 | if (scalar_ty.isSignedInt(zcu)) .smax else .umax, | 8210 | if (scalar_ty.isSignedInt(zcu)) .smax else .umax, |
| 8228 | &.{try o.lowerType(inst_ty)}, | 8211 | &.{try o.lowerType(pt, inst_ty)}, |
| 8229 | &.{ lhs, rhs }, | 8212 | &.{ lhs, rhs }, |
| 8230 | "", | 8213 | "", |
| 8231 | ); | 8214 | ); |
| ... | @@ -8233,17 +8216,17 @@ pub const FuncGen = struct { | ... | @@ -8233,17 +8216,17 @@ pub const FuncGen = struct { |
| 8233 | | 8216 | |
| 8234 | fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8217 | fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8235 | const o = self.ng.object; | 8218 | const o = self.ng.object; |
| | 8219 | const pt = self.ng.pt; |
| 8236 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 8220 | 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; | 8221 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8238 | const ptr = try self.resolveInst(bin_op.lhs); | 8222 | const ptr = try self.resolveInst(bin_op.lhs); |
| 8239 | const len = try self.resolveInst(bin_op.rhs); | 8223 | const len = try self.resolveInst(bin_op.rhs); |
| 8240 | const inst_ty = self.typeOfIndex(inst); | 8224 | const inst_ty = self.typeOfIndex(inst); |
| 8241 | return self.wip.buildAggregate(try o.lowerType(inst_ty), &.{ ptr, len }, ""); | 8225 | return self.wip.buildAggregate(try o.lowerType(pt, inst_ty), &.{ ptr, len }, ""); |
| 8242 | } | 8226 | } |
| 8243 | | 8227 | |
| 8244 | fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { | 8228 | fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8245 | const o = self.ng.object; | 8229 | 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; | 8230 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8248 | const lhs = try self.resolveInst(bin_op.lhs); | 8231 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8249 | const rhs = try self.resolveInst(bin_op.rhs); | 8232 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8261,7 +8244,8 @@ pub const FuncGen = struct { | ... | @@ -8261,7 +8244,8 @@ pub const FuncGen = struct { |
| 8261 | unsigned_intrinsic: Builder.Intrinsic, | 8244 | unsigned_intrinsic: Builder.Intrinsic, |
| 8262 | ) !Builder.Value { | 8245 | ) !Builder.Value { |
| 8263 | const o = fg.ng.object; | 8246 | const o = fg.ng.object; |
| 8264 | const zcu = o.pt.zcu; | 8247 | const pt = fg.ng.pt; |
| | 8248 | const zcu = pt.zcu; |
| 8265 | | 8249 | |
| 8266 | const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 8250 | const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8267 | const lhs = try fg.resolveInst(bin_op.lhs); | 8251 | const lhs = try fg.resolveInst(bin_op.lhs); |
| ... | @@ -8270,7 +8254,7 @@ pub const FuncGen = struct { | ... | @@ -8270,7 +8254,7 @@ pub const FuncGen = struct { |
| 8270 | const scalar_ty = inst_ty.scalarType(zcu); | 8254 | const scalar_ty = inst_ty.scalarType(zcu); |
| 8271 | | 8255 | |
| 8272 | const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic; | 8256 | const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic; |
| 8273 | const llvm_inst_ty = try o.lowerType(inst_ty); | 8257 | const llvm_inst_ty = try o.lowerType(pt, inst_ty); |
| 8274 | const results = | 8258 | const results = |
| 8275 | try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, ""); | 8259 | try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, ""); |
| 8276 | | 8260 | |
| ... | @@ -8309,7 +8293,8 @@ pub const FuncGen = struct { | ... | @@ -8309,7 +8293,8 @@ pub const FuncGen = struct { |
| 8309 | | 8293 | |
| 8310 | fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8294 | fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8311 | const o = self.ng.object; | 8295 | const o = self.ng.object; |
| 8312 | const zcu = o.pt.zcu; | 8296 | const pt = self.ng.pt; |
| | 8297 | const zcu = pt.zcu; |
| 8313 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 8298 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8314 | const lhs = try self.resolveInst(bin_op.lhs); | 8299 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8315 | const rhs = try self.resolveInst(bin_op.rhs); | 8300 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8321,15 +8306,14 @@ pub const FuncGen = struct { | ... | @@ -8321,15 +8306,14 @@ pub const FuncGen = struct { |
| 8321 | .normal, | 8306 | .normal, |
| 8322 | .none, | 8307 | .none, |
| 8323 | if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat", | 8308 | if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat", |
| 8324 | &.{try o.lowerType(inst_ty)}, | 8309 | &.{try o.lowerType(pt, inst_ty)}, |
| 8325 | &.{ lhs, rhs }, | 8310 | &.{ lhs, rhs }, |
| 8326 | "", | 8311 | "", |
| 8327 | ); | 8312 | ); |
| 8328 | } | 8313 | } |
| 8329 | | 8314 | |
| 8330 | fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { | 8315 | fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8331 | const o = self.ng.object; | 8316 | 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; | 8317 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8334 | const lhs = try self.resolveInst(bin_op.lhs); | 8318 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8335 | const rhs = try self.resolveInst(bin_op.rhs); | 8319 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8350,7 +8334,8 @@ pub const FuncGen = struct { | ... | @@ -8350,7 +8334,8 @@ pub const FuncGen = struct { |
| 8350 | | 8334 | |
| 8351 | fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8335 | fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8352 | const o = self.ng.object; | 8336 | const o = self.ng.object; |
| 8353 | const zcu = o.pt.zcu; | 8337 | const pt = self.ng.pt; |
| | 8338 | const zcu = pt.zcu; |
| 8354 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 8339 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8355 | const lhs = try self.resolveInst(bin_op.lhs); | 8340 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8356 | const rhs = try self.resolveInst(bin_op.rhs); | 8341 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8362,15 +8347,14 @@ pub const FuncGen = struct { | ... | @@ -8362,15 +8347,14 @@ pub const FuncGen = struct { |
| 8362 | .normal, | 8347 | .normal, |
| 8363 | .none, | 8348 | .none, |
| 8364 | if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat", | 8349 | if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat", |
| 8365 | &.{try o.lowerType(inst_ty)}, | 8350 | &.{try o.lowerType(pt, inst_ty)}, |
| 8366 | &.{ lhs, rhs }, | 8351 | &.{ lhs, rhs }, |
| 8367 | "", | 8352 | "", |
| 8368 | ); | 8353 | ); |
| 8369 | } | 8354 | } |
| 8370 | | 8355 | |
| 8371 | fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { | 8356 | fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8372 | const o = self.ng.object; | 8357 | 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; | 8358 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8375 | const lhs = try self.resolveInst(bin_op.lhs); | 8359 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8376 | const rhs = try self.resolveInst(bin_op.rhs); | 8360 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8391,7 +8375,8 @@ pub const FuncGen = struct { | ... | @@ -8391,7 +8375,8 @@ pub const FuncGen = struct { |
| 8391 | | 8375 | |
| 8392 | fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8376 | fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8393 | const o = self.ng.object; | 8377 | const o = self.ng.object; |
| 8394 | const zcu = o.pt.zcu; | 8378 | const pt = self.ng.pt; |
| | 8379 | const zcu = pt.zcu; |
| 8395 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 8380 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8396 | const lhs = try self.resolveInst(bin_op.lhs); | 8381 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8397 | const rhs = try self.resolveInst(bin_op.rhs); | 8382 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8403,7 +8388,7 @@ pub const FuncGen = struct { | ... | @@ -8403,7 +8388,7 @@ pub const FuncGen = struct { |
| 8403 | .normal, | 8388 | .normal, |
| 8404 | .none, | 8389 | .none, |
| 8405 | if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat", | 8390 | if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat", |
| 8406 | &.{try o.lowerType(inst_ty)}, | 8391 | &.{try o.lowerType(pt, inst_ty)}, |
| 8407 | &.{ lhs, rhs, .@"0" }, | 8392 | &.{ lhs, rhs, .@"0" }, |
| 8408 | "", | 8393 | "", |
| 8409 | ); | 8394 | ); |
| ... | @@ -8419,8 +8404,7 @@ pub const FuncGen = struct { | ... | @@ -8419,8 +8404,7 @@ pub const FuncGen = struct { |
| 8419 | } | 8404 | } |
| 8420 | | 8405 | |
| 8421 | fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { | 8406 | fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8422 | const o = self.ng.object; | 8407 | 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; | 8408 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8425 | const lhs = try self.resolveInst(bin_op.lhs); | 8409 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8426 | const rhs = try self.resolveInst(bin_op.rhs); | 8410 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8436,7 +8420,8 @@ pub const FuncGen = struct { | ... | @@ -8436,7 +8420,8 @@ pub const FuncGen = struct { |
| 8436 | | 8420 | |
| 8437 | fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { | 8421 | fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8438 | const o = self.ng.object; | 8422 | const o = self.ng.object; |
| 8439 | const zcu = o.pt.zcu; | 8423 | const pt = self.ng.pt; |
| | 8424 | const zcu = pt.zcu; |
| 8440 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 8425 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8441 | const lhs = try self.resolveInst(bin_op.lhs); | 8426 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8442 | const rhs = try self.resolveInst(bin_op.rhs); | 8427 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8448,7 +8433,7 @@ pub const FuncGen = struct { | ... | @@ -8448,7 +8433,7 @@ pub const FuncGen = struct { |
| 8448 | return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result}); | 8433 | return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result}); |
| 8449 | } | 8434 | } |
| 8450 | if (scalar_ty.isSignedInt(zcu)) { | 8435 | if (scalar_ty.isSignedInt(zcu)) { |
| 8451 | const inst_llvm_ty = try o.lowerType(inst_ty); | 8436 | const inst_llvm_ty = try o.lowerType(pt, inst_ty); |
| 8452 | | 8437 | |
| 8453 | const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb; | 8438 | const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb; |
| 8454 | var stack align(@max( | 8439 | var stack align(@max( |
| ... | @@ -8485,8 +8470,7 @@ pub const FuncGen = struct { | ... | @@ -8485,8 +8470,7 @@ pub const FuncGen = struct { |
| 8485 | } | 8470 | } |
| 8486 | | 8471 | |
| 8487 | fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { | 8472 | fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8488 | const o = self.ng.object; | 8473 | 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; | 8474 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8491 | const lhs = try self.resolveInst(bin_op.lhs); | 8475 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8492 | const rhs = try self.resolveInst(bin_op.rhs); | 8476 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8503,8 +8487,7 @@ pub const FuncGen = struct { | ... | @@ -8503,8 +8487,7 @@ pub const FuncGen = struct { |
| 8503 | } | 8487 | } |
| 8504 | | 8488 | |
| 8505 | fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { | 8489 | fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8506 | const o = self.ng.object; | 8490 | 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; | 8491 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8509 | const lhs = try self.resolveInst(bin_op.lhs); | 8492 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8510 | const rhs = try self.resolveInst(bin_op.rhs); | 8493 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | @@ -8521,12 +8504,13 @@ pub const FuncGen = struct { | ... | @@ -8521,12 +8504,13 @@ pub const FuncGen = struct { |
| 8521 | | 8504 | |
| 8522 | fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { | 8505 | fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8523 | const o = self.ng.object; | 8506 | const o = self.ng.object; |
| 8524 | const zcu = o.pt.zcu; | 8507 | const pt = self.ng.pt; |
| | 8508 | const zcu = pt.zcu; |
| 8525 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 8509 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8526 | const lhs = try self.resolveInst(bin_op.lhs); | 8510 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8527 | const rhs = try self.resolveInst(bin_op.rhs); | 8511 | const rhs = try self.resolveInst(bin_op.rhs); |
| 8528 | const inst_ty = self.typeOfIndex(inst); | 8512 | const inst_ty = self.typeOfIndex(inst); |
| 8529 | const inst_llvm_ty = try o.lowerType(inst_ty); | 8513 | const inst_llvm_ty = try o.lowerType(pt, inst_ty); |
| 8530 | const scalar_ty = inst_ty.scalarType(zcu); | 8514 | const scalar_ty = inst_ty.scalarType(zcu); |
| 8531 | | 8515 | |
| 8532 | if (scalar_ty.isRuntimeFloat()) { | 8516 | if (scalar_ty.isRuntimeFloat()) { |
| ... | @@ -8574,17 +8558,18 @@ pub const FuncGen = struct { | ... | @@ -8574,17 +8558,18 @@ pub const FuncGen = struct { |
| 8574 | | 8558 | |
| 8575 | fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8559 | fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8576 | const o = self.ng.object; | 8560 | const o = self.ng.object; |
| 8577 | const zcu = o.pt.zcu; | 8561 | const pt = self.ng.pt; |
| | 8562 | const zcu = pt.zcu; |
| 8578 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 8563 | 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; | 8564 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8580 | const ptr = try self.resolveInst(bin_op.lhs); | 8565 | const ptr = try self.resolveInst(bin_op.lhs); |
| 8581 | const offset = try self.resolveInst(bin_op.rhs); | 8566 | const offset = try self.resolveInst(bin_op.rhs); |
| 8582 | const ptr_ty = self.typeOf(bin_op.lhs); | 8567 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 8583 | const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu)); | 8568 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, ptr_ty.childType(zcu)); |
| 8584 | switch (ptr_ty.ptrSize(zcu)) { | 8569 | switch (ptr_ty.ptrSize(zcu)) { |
| 8585 | // It's a pointer to an array, so according to LLVM we need an extra GEP index. | 8570 | // 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, &.{ | 8571 | .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{ |
| 8587 | try o.builder.intValue(try o.lowerType(Type.usize), 0), offset, | 8572 | try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), offset, |
| 8588 | }, ""), | 8573 | }, ""), |
| 8589 | .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""), | 8574 | .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""), |
| 8590 | .slice => { | 8575 | .slice => { |
| ... | @@ -8596,18 +8581,19 @@ pub const FuncGen = struct { | ... | @@ -8596,18 +8581,19 @@ pub const FuncGen = struct { |
| 8596 | | 8581 | |
| 8597 | fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8582 | fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8598 | const o = self.ng.object; | 8583 | const o = self.ng.object; |
| 8599 | const zcu = o.pt.zcu; | 8584 | const pt = self.ng.pt; |
| | 8585 | const zcu = pt.zcu; |
| 8600 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 8586 | 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; | 8587 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8602 | const ptr = try self.resolveInst(bin_op.lhs); | 8588 | const ptr = try self.resolveInst(bin_op.lhs); |
| 8603 | const offset = try self.resolveInst(bin_op.rhs); | 8589 | const offset = try self.resolveInst(bin_op.rhs); |
| 8604 | const negative_offset = try self.wip.neg(offset, ""); | 8590 | const negative_offset = try self.wip.neg(offset, ""); |
| 8605 | const ptr_ty = self.typeOf(bin_op.lhs); | 8591 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 8606 | const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu)); | 8592 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, ptr_ty.childType(zcu)); |
| 8607 | switch (ptr_ty.ptrSize(zcu)) { | 8593 | switch (ptr_ty.ptrSize(zcu)) { |
| 8608 | // It's a pointer to an array, so according to LLVM we need an extra GEP index. | 8594 | // 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, &.{ | 8595 | .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{ |
| 8610 | try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset, | 8596 | try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), negative_offset, |
| 8611 | }, ""), | 8597 | }, ""), |
| 8612 | .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""), | 8598 | .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""), |
| 8613 | .slice => { | 8599 | .slice => { |
| ... | @@ -8624,7 +8610,7 @@ pub const FuncGen = struct { | ... | @@ -8624,7 +8610,7 @@ pub const FuncGen = struct { |
| 8624 | unsigned_intrinsic: Builder.Intrinsic, | 8610 | unsigned_intrinsic: Builder.Intrinsic, |
| 8625 | ) !Builder.Value { | 8611 | ) !Builder.Value { |
| 8626 | const o = self.ng.object; | 8612 | const o = self.ng.object; |
| 8627 | const pt = o.pt; | 8613 | const pt = self.ng.pt; |
| 8628 | const zcu = pt.zcu; | 8614 | const zcu = pt.zcu; |
| 8629 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 8615 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8630 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; | 8616 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | @@ -8637,8 +8623,8 @@ pub const FuncGen = struct { | ... | @@ -8637,8 +8623,8 @@ pub const FuncGen = struct { |
| 8637 | const inst_ty = self.typeOfIndex(inst); | 8623 | const inst_ty = self.typeOfIndex(inst); |
| 8638 | | 8624 | |
| 8639 | const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic; | 8625 | const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic; |
| 8640 | const llvm_inst_ty = try o.lowerType(inst_ty); | 8626 | const llvm_inst_ty = try o.lowerType(pt, inst_ty); |
| 8641 | const llvm_lhs_ty = try o.lowerType(lhs_ty); | 8627 | const llvm_lhs_ty = try o.lowerType(pt, lhs_ty); |
| 8642 | const results = | 8628 | const results = |
| 8643 | try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, ""); | 8629 | try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, ""); |
| 8644 | | 8630 | |
| ... | @@ -8718,7 +8704,7 @@ pub const FuncGen = struct { | ... | @@ -8718,7 +8704,7 @@ pub const FuncGen = struct { |
| 8718 | return o.builder.addFunction( | 8704 | return o.builder.addFunction( |
| 8719 | try o.builder.fnType(return_type, param_types, .normal), | 8705 | try o.builder.fnType(return_type, param_types, .normal), |
| 8720 | fn_name, | 8706 | fn_name, |
| 8721 | toLlvmAddressSpace(.generic, o.pt.zcu.getTarget()), | 8707 | toLlvmAddressSpace(.generic, self.ng.pt.zcu.getTarget()), |
| 8722 | ); | 8708 | ); |
| 8723 | } | 8709 | } |
| 8724 | | 8710 | |
| ... | @@ -8732,10 +8718,11 @@ pub const FuncGen = struct { | ... | @@ -8732,10 +8718,11 @@ pub const FuncGen = struct { |
| 8732 | params: [2]Builder.Value, | 8718 | params: [2]Builder.Value, |
| 8733 | ) !Builder.Value { | 8719 | ) !Builder.Value { |
| 8734 | const o = self.ng.object; | 8720 | const o = self.ng.object; |
| 8735 | const zcu = o.pt.zcu; | 8721 | const pt = self.ng.pt; |
| | 8722 | const zcu = pt.zcu; |
| 8736 | const target = zcu.getTarget(); | 8723 | const target = zcu.getTarget(); |
| 8737 | const scalar_ty = ty.scalarType(zcu); | 8724 | const scalar_ty = ty.scalarType(zcu); |
| 8738 | const scalar_llvm_ty = try o.lowerType(scalar_ty); | 8725 | const scalar_llvm_ty = try o.lowerType(pt, scalar_ty); |
| 8739 | | 8726 | |
| 8740 | if (intrinsicsAllowed(scalar_ty, target)) { | 8727 | if (intrinsicsAllowed(scalar_ty, target)) { |
| 8741 | const cond: Builder.FloatCondition = switch (pred) { | 8728 | const cond: Builder.FloatCondition = switch (pred) { |
| ... | @@ -8838,10 +8825,11 @@ pub const FuncGen = struct { | ... | @@ -8838,10 +8825,11 @@ pub const FuncGen = struct { |
| 8838 | params: [params_len]Builder.Value, | 8825 | params: [params_len]Builder.Value, |
| 8839 | ) !Builder.Value { | 8826 | ) !Builder.Value { |
| 8840 | const o = self.ng.object; | 8827 | const o = self.ng.object; |
| 8841 | const zcu = o.pt.zcu; | 8828 | const pt = self.ng.pt; |
| | 8829 | const zcu = pt.zcu; |
| 8842 | const target = zcu.getTarget(); | 8830 | const target = zcu.getTarget(); |
| 8843 | const scalar_ty = ty.scalarType(zcu); | 8831 | const scalar_ty = ty.scalarType(zcu); |
| 8844 | const llvm_ty = try o.lowerType(ty); | 8832 | const llvm_ty = try o.lowerType(pt, ty); |
| 8845 | | 8833 | |
| 8846 | if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) { | 8834 | if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) { |
| 8847 | // Some operations are dedicated LLVM instructions, not available as intrinsics | 8835 | // Some operations are dedicated LLVM instructions, not available as intrinsics |
| ... | @@ -8979,7 +8967,7 @@ pub const FuncGen = struct { | ... | @@ -8979,7 +8967,7 @@ pub const FuncGen = struct { |
| 8979 | | 8967 | |
| 8980 | fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 8968 | fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8981 | const o = self.ng.object; | 8969 | const o = self.ng.object; |
| 8982 | const pt = o.pt; | 8970 | const pt = self.ng.pt; |
| 8983 | const zcu = pt.zcu; | 8971 | const zcu = pt.zcu; |
| 8984 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 8972 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8985 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; | 8973 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | @@ -8993,9 +8981,9 @@ pub const FuncGen = struct { | ... | @@ -8993,9 +8981,9 @@ pub const FuncGen = struct { |
| 8993 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); | 8981 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); |
| 8994 | | 8982 | |
| 8995 | const dest_ty = self.typeOfIndex(inst); | 8983 | const dest_ty = self.typeOfIndex(inst); |
| 8996 | const llvm_dest_ty = try o.lowerType(dest_ty); | 8984 | const llvm_dest_ty = try o.lowerType(pt, dest_ty); |
| 8997 | | 8985 | |
| 8998 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); | 8986 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), ""); |
| 8999 | | 8987 | |
| 9000 | const result = try self.wip.bin(.shl, lhs, casted_rhs, ""); | 8988 | const result = try self.wip.bin(.shl, lhs, casted_rhs, ""); |
| 9001 | const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) | 8989 | const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) |
| ... | @@ -9052,7 +9040,8 @@ pub const FuncGen = struct { | ... | @@ -9052,7 +9040,8 @@ pub const FuncGen = struct { |
| 9052 | | 9040 | |
| 9053 | fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9041 | fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9054 | const o = self.ng.object; | 9042 | const o = self.ng.object; |
| 9055 | const zcu = o.pt.zcu; | 9043 | const pt = self.ng.pt; |
| | 9044 | const zcu = pt.zcu; |
| 9056 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 9045 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9057 | | 9046 | |
| 9058 | const lhs = try self.resolveInst(bin_op.lhs); | 9047 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | @@ -9063,7 +9052,7 @@ pub const FuncGen = struct { | ... | @@ -9063,7 +9052,7 @@ pub const FuncGen = struct { |
| 9063 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); | 9052 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9064 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); | 9053 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); |
| 9065 | | 9054 | |
| 9066 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); | 9055 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), ""); |
| 9067 | return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) | 9056 | return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) |
| 9068 | .@"shl nsw" | 9057 | .@"shl nsw" |
| 9069 | else | 9058 | else |
| ... | @@ -9072,7 +9061,8 @@ pub const FuncGen = struct { | ... | @@ -9072,7 +9061,8 @@ pub const FuncGen = struct { |
| 9072 | | 9061 | |
| 9073 | fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9062 | fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9074 | const o = self.ng.object; | 9063 | const o = self.ng.object; |
| 9075 | const zcu = o.pt.zcu; | 9064 | const pt = self.ng.pt; |
| | 9065 | const zcu = pt.zcu; |
| 9076 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 9066 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9077 | | 9067 | |
| 9078 | const lhs = try self.resolveInst(bin_op.lhs); | 9068 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | @@ -9082,13 +9072,13 @@ pub const FuncGen = struct { | ... | @@ -9082,13 +9072,13 @@ pub const FuncGen = struct { |
| 9082 | if (lhs_ty.isVector(zcu) and !self.typeOf(bin_op.rhs).isVector(zcu)) | 9072 | if (lhs_ty.isVector(zcu) and !self.typeOf(bin_op.rhs).isVector(zcu)) |
| 9083 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); | 9073 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9084 | | 9074 | |
| 9085 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); | 9075 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), ""); |
| 9086 | return self.wip.bin(.shl, lhs, casted_rhs, ""); | 9076 | return self.wip.bin(.shl, lhs, casted_rhs, ""); |
| 9087 | } | 9077 | } |
| 9088 | | 9078 | |
| 9089 | fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9079 | fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9090 | const o = self.ng.object; | 9080 | const o = self.ng.object; |
| 9091 | const pt = o.pt; | 9081 | const pt = self.ng.pt; |
| 9092 | const zcu = pt.zcu; | 9082 | const zcu = pt.zcu; |
| 9093 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 9083 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9094 | | 9084 | |
| ... | @@ -9097,7 +9087,7 @@ pub const FuncGen = struct { | ... | @@ -9097,7 +9087,7 @@ pub const FuncGen = struct { |
| 9097 | | 9087 | |
| 9098 | const lhs_ty = self.typeOf(bin_op.lhs); | 9088 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 9099 | const lhs_info = lhs_ty.intInfo(zcu); | 9089 | const lhs_info = lhs_ty.intInfo(zcu); |
| 9100 | const llvm_lhs_ty = try o.lowerType(lhs_ty); | 9090 | const llvm_lhs_ty = try o.lowerType(pt, lhs_ty); |
| 9101 | const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder); | 9091 | const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder); |
| 9102 | | 9092 | |
| 9103 | const rhs_ty = self.typeOf(bin_op.rhs); | 9093 | const rhs_ty = self.typeOf(bin_op.rhs); |
| ... | @@ -9105,7 +9095,7 @@ pub const FuncGen = struct { | ... | @@ -9105,7 +9095,7 @@ pub const FuncGen = struct { |
| 9105 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); | 9095 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9106 | const rhs_info = rhs_ty.intInfo(zcu); | 9096 | const rhs_info = rhs_ty.intInfo(zcu); |
| 9107 | assert(rhs_info.signedness == .unsigned); | 9097 | assert(rhs_info.signedness == .unsigned); |
| 9108 | const llvm_rhs_ty = try o.lowerType(rhs_ty); | 9098 | const llvm_rhs_ty = try o.lowerType(pt, rhs_ty); |
| 9109 | const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder); | 9099 | const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder); |
| 9110 | | 9100 | |
| 9111 | const result = try self.wip.callIntrinsic( | 9101 | const result = try self.wip.callIntrinsic( |
| ... | @@ -9168,7 +9158,8 @@ pub const FuncGen = struct { | ... | @@ -9168,7 +9158,8 @@ pub const FuncGen = struct { |
| 9168 | | 9158 | |
| 9169 | fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value { | 9159 | fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value { |
| 9170 | const o = self.ng.object; | 9160 | const o = self.ng.object; |
| 9171 | const zcu = o.pt.zcu; | 9161 | const pt = self.ng.pt; |
| | 9162 | const zcu = pt.zcu; |
| 9172 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 9163 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9173 | | 9164 | |
| 9174 | const lhs = try self.resolveInst(bin_op.lhs); | 9165 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | @@ -9179,7 +9170,7 @@ pub const FuncGen = struct { | ... | @@ -9179,7 +9170,7 @@ pub const FuncGen = struct { |
| 9179 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); | 9170 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9180 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); | 9171 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); |
| 9181 | | 9172 | |
| 9182 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); | 9173 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), ""); |
| 9183 | const is_signed_int = lhs_scalar_ty.isSignedInt(zcu); | 9174 | const is_signed_int = lhs_scalar_ty.isSignedInt(zcu); |
| 9184 | | 9175 | |
| 9185 | return self.wip.bin(if (is_exact) | 9176 | return self.wip.bin(if (is_exact) |
| ... | @@ -9189,7 +9180,8 @@ pub const FuncGen = struct { | ... | @@ -9189,7 +9180,8 @@ pub const FuncGen = struct { |
| 9189 | | 9180 | |
| 9190 | fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9181 | fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9191 | const o = self.ng.object; | 9182 | const o = self.ng.object; |
| 9192 | const zcu = o.pt.zcu; | 9183 | const pt = self.ng.pt; |
| | 9184 | const zcu = pt.zcu; |
| 9193 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 9185 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9194 | const operand = try self.resolveInst(ty_op.operand); | 9186 | const operand = try self.resolveInst(ty_op.operand); |
| 9195 | const operand_ty = self.typeOf(ty_op.operand); | 9187 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | @@ -9200,7 +9192,7 @@ pub const FuncGen = struct { | ... | @@ -9200,7 +9192,7 @@ pub const FuncGen = struct { |
| 9200 | .normal, | 9192 | .normal, |
| 9201 | .none, | 9193 | .none, |
| 9202 | .abs, | 9194 | .abs, |
| 9203 | &.{try o.lowerType(operand_ty)}, | 9195 | &.{try o.lowerType(pt, operand_ty)}, |
| 9204 | &.{ operand, try o.builder.intValue(.i1, 0) }, | 9196 | &.{ operand, try o.builder.intValue(.i1, 0) }, |
| 9205 | "", | 9197 | "", |
| 9206 | ), | 9198 | ), |
| ... | @@ -9211,10 +9203,11 @@ pub const FuncGen = struct { | ... | @@ -9211,10 +9203,11 @@ pub const FuncGen = struct { |
| 9211 | | 9203 | |
| 9212 | fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { | 9204 | fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9213 | const o = fg.ng.object; | 9205 | const o = fg.ng.object; |
| 9214 | const zcu = o.pt.zcu; | 9206 | const pt = fg.ng.pt; |
| | 9207 | const zcu = pt.zcu; |
| 9215 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 9208 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9216 | const dest_ty = fg.typeOfIndex(inst); | 9209 | const dest_ty = fg.typeOfIndex(inst); |
| 9217 | const dest_llvm_ty = try o.lowerType(dest_ty); | 9210 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 9218 | const operand = try fg.resolveInst(ty_op.operand); | 9211 | const operand = try fg.resolveInst(ty_op.operand); |
| 9219 | const operand_ty = fg.typeOf(ty_op.operand); | 9212 | const operand_ty = fg.typeOf(ty_op.operand); |
| 9220 | const operand_info = operand_ty.intInfo(zcu); | 9213 | const operand_info = operand_ty.intInfo(zcu); |
| ... | @@ -9243,8 +9236,8 @@ pub const FuncGen = struct { | ... | @@ -9243,8 +9236,8 @@ pub const FuncGen = struct { |
| 9243 | | 9236 | |
| 9244 | if (!have_min_check and !have_max_check) break :safety; | 9237 | if (!have_min_check and !have_max_check) break :safety; |
| 9245 | | 9238 | |
| 9246 | const operand_llvm_ty = try o.lowerType(operand_ty); | 9239 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9247 | const operand_scalar_llvm_ty = try o.lowerType(operand_scalar); | 9240 | const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar); |
| 9248 | | 9241 | |
| 9249 | const is_vector = operand_ty.zigTypeTag(zcu) == .vector; | 9242 | const is_vector = operand_ty.zigTypeTag(zcu) == .vector; |
| 9250 | assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector)); | 9243 | assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector)); |
| ... | @@ -9313,15 +9306,17 @@ pub const FuncGen = struct { | ... | @@ -9313,15 +9306,17 @@ pub const FuncGen = struct { |
| 9313 | | 9306 | |
| 9314 | fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9307 | fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9315 | const o = self.ng.object; | 9308 | const o = self.ng.object; |
| | 9309 | const pt = self.ng.pt; |
| 9316 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 9310 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9317 | const operand = try self.resolveInst(ty_op.operand); | 9311 | const operand = try self.resolveInst(ty_op.operand); |
| 9318 | const dest_llvm_ty = try o.lowerType(self.typeOfIndex(inst)); | 9312 | const dest_llvm_ty = try o.lowerType(pt, self.typeOfIndex(inst)); |
| 9319 | return self.wip.cast(.trunc, operand, dest_llvm_ty, ""); | 9313 | return self.wip.cast(.trunc, operand, dest_llvm_ty, ""); |
| 9320 | } | 9314 | } |
| 9321 | | 9315 | |
| 9322 | fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9316 | fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9323 | const o = self.ng.object; | 9317 | const o = self.ng.object; |
| 9324 | const zcu = o.pt.zcu; | 9318 | const pt = self.ng.pt; |
| | 9319 | const zcu = pt.zcu; |
| 9325 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 9320 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9326 | const operand = try self.resolveInst(ty_op.operand); | 9321 | const operand = try self.resolveInst(ty_op.operand); |
| 9327 | const operand_ty = self.typeOf(ty_op.operand); | 9322 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | @@ -9329,10 +9324,10 @@ pub const FuncGen = struct { | ... | @@ -9329,10 +9324,10 @@ pub const FuncGen = struct { |
| 9329 | const target = zcu.getTarget(); | 9324 | const target = zcu.getTarget(); |
| 9330 | | 9325 | |
| 9331 | if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) { | 9326 | if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) { |
| 9332 | return self.wip.cast(.fptrunc, operand, try o.lowerType(dest_ty), ""); | 9327 | return self.wip.cast(.fptrunc, operand, try o.lowerType(pt, dest_ty), ""); |
| 9333 | } else { | 9328 | } else { |
| 9334 | const operand_llvm_ty = try o.lowerType(operand_ty); | 9329 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9335 | const dest_llvm_ty = try o.lowerType(dest_ty); | 9330 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 9336 | | 9331 | |
| 9337 | const dest_bits = dest_ty.floatBits(target); | 9332 | const dest_bits = dest_ty.floatBits(target); |
| 9338 | const src_bits = operand_ty.floatBits(target); | 9333 | const src_bits = operand_ty.floatBits(target); |
| ... | @@ -9355,7 +9350,8 @@ pub const FuncGen = struct { | ... | @@ -9355,7 +9350,8 @@ pub const FuncGen = struct { |
| 9355 | | 9350 | |
| 9356 | fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9351 | fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9357 | const o = self.ng.object; | 9352 | const o = self.ng.object; |
| 9358 | const zcu = o.pt.zcu; | 9353 | const pt = self.ng.pt; |
| | 9354 | const zcu = pt.zcu; |
| 9359 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 9355 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9360 | const operand = try self.resolveInst(ty_op.operand); | 9356 | const operand = try self.resolveInst(ty_op.operand); |
| 9361 | const operand_ty = self.typeOf(ty_op.operand); | 9357 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | @@ -9363,10 +9359,10 @@ pub const FuncGen = struct { | ... | @@ -9363,10 +9359,10 @@ pub const FuncGen = struct { |
| 9363 | const target = zcu.getTarget(); | 9359 | const target = zcu.getTarget(); |
| 9364 | | 9360 | |
| 9365 | if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) { | 9361 | if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) { |
| 9366 | return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), ""); | 9362 | return self.wip.cast(.fpext, operand, try o.lowerType(pt, dest_ty), ""); |
| 9367 | } else { | 9363 | } else { |
| 9368 | const operand_llvm_ty = try o.lowerType(operand_ty); | 9364 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9369 | const dest_llvm_ty = try o.lowerType(dest_ty); | 9365 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 9370 | | 9366 | |
| 9371 | const dest_bits = dest_ty.scalarType(zcu).floatBits(target); | 9367 | const dest_bits = dest_ty.scalarType(zcu).floatBits(target); |
| 9372 | const src_bits = operand_ty.scalarType(zcu).floatBits(target); | 9368 | const src_bits = operand_ty.scalarType(zcu).floatBits(target); |
| ... | @@ -9403,11 +9399,11 @@ pub const FuncGen = struct { | ... | @@ -9403,11 +9399,11 @@ pub const FuncGen = struct { |
| 9403 | | 9399 | |
| 9404 | fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value { | 9400 | fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value { |
| 9405 | const o = self.ng.object; | 9401 | const o = self.ng.object; |
| 9406 | const pt = o.pt; | 9402 | const pt = self.ng.pt; |
| 9407 | const zcu = pt.zcu; | 9403 | const zcu = pt.zcu; |
| 9408 | const operand_is_ref = isByRef(operand_ty, zcu); | 9404 | const operand_is_ref = isByRef(operand_ty, zcu); |
| 9409 | const result_is_ref = isByRef(inst_ty, zcu); | 9405 | const result_is_ref = isByRef(inst_ty, zcu); |
| 9410 | const llvm_dest_ty = try o.lowerType(inst_ty); | 9406 | const llvm_dest_ty = try o.lowerType(pt, inst_ty); |
| 9411 | | 9407 | |
| 9412 | if (operand_is_ref and result_is_ref) { | 9408 | if (operand_is_ref and result_is_ref) { |
| 9413 | // They are both pointers, so just return the same opaque pointer :) | 9409 | // They are both pointers, so just return the same opaque pointer :) |
| ... | @@ -9442,7 +9438,7 @@ pub const FuncGen = struct { | ... | @@ -9442,7 +9438,7 @@ pub const FuncGen = struct { |
| 9442 | } else { | 9438 | } else { |
| 9443 | // If the ABI size of the element type is not evenly divisible by size in bits; | 9439 | // 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. | 9440 | // a simple bitcast will not work, and we fall back to extractelement. |
| 9445 | const llvm_usize = try o.lowerType(Type.usize); | 9441 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 9446 | const usize_zero = try o.builder.intValue(llvm_usize, 0); | 9442 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 9447 | const vector_len = operand_ty.arrayLen(zcu); | 9443 | const vector_len = operand_ty.arrayLen(zcu); |
| 9448 | var i: u64 = 0; | 9444 | var i: u64 = 0; |
| ... | @@ -9458,7 +9454,7 @@ pub const FuncGen = struct { | ... | @@ -9458,7 +9454,7 @@ pub const FuncGen = struct { |
| 9458 | return array_ptr; | 9454 | return array_ptr; |
| 9459 | } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) { | 9455 | } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) { |
| 9460 | const elem_ty = operand_ty.childType(zcu); | 9456 | const elem_ty = operand_ty.childType(zcu); |
| 9461 | const llvm_vector_ty = try o.lowerType(inst_ty); | 9457 | const llvm_vector_ty = try o.lowerType(pt, inst_ty); |
| 9462 | if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{}); | 9458 | if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{}); |
| 9463 | | 9459 | |
| 9464 | const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8; | 9460 | const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8; |
| ... | @@ -9470,9 +9466,9 @@ pub const FuncGen = struct { | ... | @@ -9470,9 +9466,9 @@ pub const FuncGen = struct { |
| 9470 | } else { | 9466 | } else { |
| 9471 | // If the ABI size of the element type is not evenly divisible by size in bits; | 9467 | // 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. | 9468 | // a simple bitcast will not work, and we fall back to extractelement. |
| 9473 | const array_llvm_ty = try o.lowerType(operand_ty); | 9469 | const array_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9474 | const elem_llvm_ty = try o.lowerType(elem_ty); | 9470 | const elem_llvm_ty = try o.lowerType(pt, elem_ty); |
| 9475 | const llvm_usize = try o.lowerType(Type.usize); | 9471 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 9476 | const usize_zero = try o.builder.intValue(llvm_usize, 0); | 9472 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 9477 | const vector_len = operand_ty.arrayLen(zcu); | 9473 | const vector_len = operand_ty.arrayLen(zcu); |
| 9478 | var vector = try o.builder.poisonValue(llvm_vector_ty); | 9474 | var vector = try o.builder.poisonValue(llvm_vector_ty); |
| ... | @@ -9519,7 +9515,7 @@ pub const FuncGen = struct { | ... | @@ -9519,7 +9515,7 @@ pub const FuncGen = struct { |
| 9519 | | 9515 | |
| 9520 | fn airArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9516 | fn airArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9521 | const o = self.ng.object; | 9517 | const o = self.ng.object; |
| 9522 | const pt = o.pt; | 9518 | const pt = self.ng.pt; |
| 9523 | const zcu = pt.zcu; | 9519 | const zcu = pt.zcu; |
| 9524 | const arg_val = self.args[self.arg_index]; | 9520 | const arg_val = self.args[self.arg_index]; |
| 9525 | self.arg_index += 1; | 9521 | self.arg_index += 1; |
| ... | @@ -9547,7 +9543,7 @@ pub const FuncGen = struct { | ... | @@ -9547,7 +9543,7 @@ pub const FuncGen = struct { |
| 9547 | self.file, | 9543 | self.file, |
| 9548 | self.scope, | 9544 | self.scope, |
| 9549 | lbrace_line, | 9545 | lbrace_line, |
| 9550 | try o.lowerDebugType(inst_ty), | 9546 | try o.lowerDebugType(pt, inst_ty), |
| 9551 | self.arg_index, | 9547 | self.arg_index, |
| 9552 | ); | 9548 | ); |
| 9553 | | 9549 | |
| ... | @@ -9611,28 +9607,28 @@ pub const FuncGen = struct { | ... | @@ -9611,28 +9607,28 @@ pub const FuncGen = struct { |
| 9611 | | 9607 | |
| 9612 | fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9608 | fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9613 | const o = self.ng.object; | 9609 | const o = self.ng.object; |
| 9614 | const pt = o.pt; | 9610 | const pt = self.ng.pt; |
| 9615 | const zcu = pt.zcu; | 9611 | const zcu = pt.zcu; |
| 9616 | const ptr_ty = self.typeOfIndex(inst); | 9612 | const ptr_ty = self.typeOfIndex(inst); |
| 9617 | const pointee_type = ptr_ty.childType(zcu); | 9613 | const pointee_type = ptr_ty.childType(zcu); |
| 9618 | if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) | 9614 | if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) |
| 9619 | return (try o.lowerPtrToVoid(ptr_ty)).toValue(); | 9615 | return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue(); |
| 9620 | | 9616 | |
| 9621 | const pointee_llvm_ty = try o.lowerType(pointee_type); | 9617 | const pointee_llvm_ty = try o.lowerType(pt, pointee_type); |
| 9622 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); | 9618 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 9623 | return self.buildAlloca(pointee_llvm_ty, alignment); | 9619 | return self.buildAlloca(pointee_llvm_ty, alignment); |
| 9624 | } | 9620 | } |
| 9625 | | 9621 | |
| 9626 | fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9622 | fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9627 | const o = self.ng.object; | 9623 | const o = self.ng.object; |
| 9628 | const pt = o.pt; | 9624 | const pt = self.ng.pt; |
| 9629 | const zcu = pt.zcu; | 9625 | const zcu = pt.zcu; |
| 9630 | const ptr_ty = self.typeOfIndex(inst); | 9626 | const ptr_ty = self.typeOfIndex(inst); |
| 9631 | const ret_ty = ptr_ty.childType(zcu); | 9627 | const ret_ty = ptr_ty.childType(zcu); |
| 9632 | if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) | 9628 | if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) |
| 9633 | return (try o.lowerPtrToVoid(ptr_ty)).toValue(); | 9629 | return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue(); |
| 9634 | if (self.ret_ptr != .none) return self.ret_ptr; | 9630 | if (self.ret_ptr != .none) return self.ret_ptr; |
| 9635 | const ret_llvm_ty = try o.lowerType(ret_ty); | 9631 | const ret_llvm_ty = try o.lowerType(pt, ret_ty); |
| 9636 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); | 9632 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 9637 | return self.buildAlloca(ret_llvm_ty, alignment); | 9633 | return self.buildAlloca(ret_llvm_ty, alignment); |
| 9638 | } | 9634 | } |
| ... | @@ -9644,13 +9640,13 @@ pub const FuncGen = struct { | ... | @@ -9644,13 +9640,13 @@ pub const FuncGen = struct { |
| 9644 | llvm_ty: Builder.Type, | 9640 | llvm_ty: Builder.Type, |
| 9645 | alignment: Builder.Alignment, | 9641 | alignment: Builder.Alignment, |
| 9646 | ) Allocator.Error!Builder.Value { | 9642 | ) Allocator.Error!Builder.Value { |
| 9647 | const target = self.ng.object.pt.zcu.getTarget(); | 9643 | const target = self.ng.pt.zcu.getTarget(); |
| 9648 | return buildAllocaInner(&self.wip, llvm_ty, alignment, target); | 9644 | return buildAllocaInner(&self.wip, llvm_ty, alignment, target); |
| 9649 | } | 9645 | } |
| 9650 | | 9646 | |
| 9651 | fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { | 9647 | fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9652 | const o = self.ng.object; | 9648 | const o = self.ng.object; |
| 9653 | const pt = o.pt; | 9649 | const pt = self.ng.pt; |
| 9654 | const zcu = pt.zcu; | 9650 | const zcu = pt.zcu; |
| 9655 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 9651 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9656 | const dest_ptr = try self.resolveInst(bin_op.lhs); | 9652 | const dest_ptr = try self.resolveInst(bin_op.lhs); |
| ... | @@ -9685,7 +9681,7 @@ pub const FuncGen = struct { | ... | @@ -9685,7 +9681,7 @@ pub const FuncGen = struct { |
| 9685 | | 9681 | |
| 9686 | self.maybeMarkAllowZeroAccess(ptr_info); | 9682 | self.maybeMarkAllowZeroAccess(ptr_info); |
| 9687 | | 9683 | |
| 9688 | const len = try o.builder.intValue(try o.lowerType(Type.usize), operand_ty.abiSize(zcu)); | 9684 | const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), operand_ty.abiSize(zcu)); |
| 9689 | _ = try self.wip.callMemSet( | 9685 | _ = try self.wip.callMemSet( |
| 9690 | dest_ptr, | 9686 | dest_ptr, |
| 9691 | ptr_ty.ptrAlignment(zcu).toLlvm(), | 9687 | ptr_ty.ptrAlignment(zcu).toLlvm(), |
| ... | @@ -9714,8 +9710,7 @@ pub const FuncGen = struct { | ... | @@ -9714,8 +9710,7 @@ pub const FuncGen = struct { |
| 9714 | /// | 9710 | /// |
| 9715 | /// The first instruction of `body_tail` is the one whose copy we want to elide. | 9711 | /// 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 { | 9712 | fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool { |
| 9717 | const o = fg.ng.object; | 9713 | const zcu = fg.ng.pt.zcu; |
| 9718 | const zcu = o.pt.zcu; | | |
| 9719 | const ip = &zcu.intern_pool; | 9714 | const ip = &zcu.intern_pool; |
| 9720 | for (body_tail[1..]) |body_inst| { | 9715 | for (body_tail[1..]) |body_inst| { |
| 9721 | switch (fg.liveness.categorizeOperand(fg.air, zcu, body_inst, body_tail[0], ip)) { | 9716 | switch (fg.liveness.categorizeOperand(fg.air, zcu, body_inst, body_tail[0], ip)) { |
| ... | @@ -9730,8 +9725,7 @@ pub const FuncGen = struct { | ... | @@ -9730,8 +9725,7 @@ pub const FuncGen = struct { |
| 9730 | } | 9725 | } |
| 9731 | | 9726 | |
| 9732 | fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { | 9727 | fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 9733 | const o = fg.ng.object; | 9728 | const pt = fg.ng.pt; |
| 9734 | const pt = o.pt; | | |
| 9735 | const zcu = pt.zcu; | 9729 | const zcu = pt.zcu; |
| 9736 | const inst = body_tail[0]; | 9730 | const inst = body_tail[0]; |
| 9737 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 9731 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | @@ -9765,8 +9759,9 @@ pub const FuncGen = struct { | ... | @@ -9765,8 +9759,9 @@ pub const FuncGen = struct { |
| 9765 | fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9759 | fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9766 | _ = inst; | 9760 | _ = inst; |
| 9767 | const o = self.ng.object; | 9761 | const o = self.ng.object; |
| 9768 | const llvm_usize = try o.lowerType(Type.usize); | 9762 | const pt = self.ng.pt; |
| 9769 | if (!target_util.supportsReturnAddress(o.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) { | 9763 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| | 9764 | if (!target_util.supportsReturnAddress(self.ng.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) { |
| 9770 | // https://github.com/ziglang/zig/issues/11946 | 9765 | // https://github.com/ziglang/zig/issues/11946 |
| 9771 | return o.builder.intValue(llvm_usize, 0); | 9766 | return o.builder.intValue(llvm_usize, 0); |
| 9772 | } | 9767 | } |
| ... | @@ -9777,8 +9772,9 @@ pub const FuncGen = struct { | ... | @@ -9777,8 +9772,9 @@ pub const FuncGen = struct { |
| 9777 | fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9772 | fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9778 | _ = inst; | 9773 | _ = inst; |
| 9779 | const o = self.ng.object; | 9774 | const o = self.ng.object; |
| | 9775 | const pt = self.ng.pt; |
| 9780 | const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, ""); | 9776 | const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, ""); |
| 9781 | return self.wip.cast(.ptrtoint, result, try o.lowerType(Type.usize), ""); | 9777 | return self.wip.cast(.ptrtoint, result, try o.lowerType(pt, Type.usize), ""); |
| 9782 | } | 9778 | } |
| 9783 | | 9779 | |
| 9784 | fn airCmpxchg( | 9780 | fn airCmpxchg( |
| ... | @@ -9787,7 +9783,7 @@ pub const FuncGen = struct { | ... | @@ -9787,7 +9783,7 @@ pub const FuncGen = struct { |
| 9787 | kind: Builder.Function.Instruction.CmpXchg.Kind, | 9783 | kind: Builder.Function.Instruction.CmpXchg.Kind, |
| 9788 | ) !Builder.Value { | 9784 | ) !Builder.Value { |
| 9789 | const o = self.ng.object; | 9785 | const o = self.ng.object; |
| 9790 | const pt = o.pt; | 9786 | const pt = self.ng.pt; |
| 9791 | const zcu = pt.zcu; | 9787 | const zcu = pt.zcu; |
| 9792 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 9788 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 9793 | const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data; | 9789 | const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| ... | @@ -9796,8 +9792,8 @@ pub const FuncGen = struct { | ... | @@ -9796,8 +9792,8 @@ pub const FuncGen = struct { |
| 9796 | var expected_value = try self.resolveInst(extra.expected_value); | 9792 | var expected_value = try self.resolveInst(extra.expected_value); |
| 9797 | var new_value = try self.resolveInst(extra.new_value); | 9793 | var new_value = try self.resolveInst(extra.new_value); |
| 9798 | const operand_ty = ptr_ty.childType(zcu); | 9794 | const operand_ty = ptr_ty.childType(zcu); |
| 9799 | const llvm_operand_ty = try o.lowerType(operand_ty); | 9795 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 9800 | const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false); | 9796 | const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false); |
| 9801 | if (llvm_abi_ty != .none) { | 9797 | if (llvm_abi_ty != .none) { |
| 9802 | // operand needs widening and truncating | 9798 | // operand needs widening and truncating |
| 9803 | const signedness: Builder.Function.Instruction.Cast.Signedness = | 9799 | const signedness: Builder.Function.Instruction.Cast.Signedness = |
| ... | @@ -9840,7 +9836,7 @@ pub const FuncGen = struct { | ... | @@ -9840,7 +9836,7 @@ pub const FuncGen = struct { |
| 9840 | | 9836 | |
| 9841 | fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9837 | fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9842 | const o = self.ng.object; | 9838 | const o = self.ng.object; |
| 9843 | const pt = o.pt; | 9839 | const pt = self.ng.pt; |
| 9844 | const zcu = pt.zcu; | 9840 | const zcu = pt.zcu; |
| 9845 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 9841 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 9846 | const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data; | 9842 | const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| ... | @@ -9852,8 +9848,8 @@ pub const FuncGen = struct { | ... | @@ -9852,8 +9848,8 @@ pub const FuncGen = struct { |
| 9852 | const is_float = operand_ty.isRuntimeFloat(); | 9848 | const is_float = operand_ty.isRuntimeFloat(); |
| 9853 | const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float); | 9849 | const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float); |
| 9854 | const ordering = toLlvmAtomicOrdering(extra.ordering()); | 9850 | const ordering = toLlvmAtomicOrdering(extra.ordering()); |
| 9855 | const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, op == .xchg); | 9851 | const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, op == .xchg); |
| 9856 | const llvm_operand_ty = try o.lowerType(operand_ty); | 9852 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 9857 | | 9853 | |
| 9858 | const access_kind: Builder.MemoryAccessKind = | 9854 | const access_kind: Builder.MemoryAccessKind = |
| 9859 | if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; | 9855 | if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; |
| ... | @@ -9896,7 +9892,7 @@ pub const FuncGen = struct { | ... | @@ -9896,7 +9892,7 @@ pub const FuncGen = struct { |
| 9896 | access_kind, | 9892 | access_kind, |
| 9897 | op, | 9893 | op, |
| 9898 | ptr, | 9894 | ptr, |
| 9899 | try self.wip.cast(.ptrtoint, operand, try o.lowerType(Type.usize), ""), | 9895 | try self.wip.cast(.ptrtoint, operand, try o.lowerType(pt, Type.usize), ""), |
| 9900 | self.sync_scope, | 9896 | self.sync_scope, |
| 9901 | ordering, | 9897 | ordering, |
| 9902 | ptr_alignment, | 9898 | ptr_alignment, |
| ... | @@ -9906,7 +9902,7 @@ pub const FuncGen = struct { | ... | @@ -9906,7 +9902,7 @@ pub const FuncGen = struct { |
| 9906 | | 9902 | |
| 9907 | fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9903 | fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9908 | const o = self.ng.object; | 9904 | const o = self.ng.object; |
| 9909 | const pt = o.pt; | 9905 | const pt = self.ng.pt; |
| 9910 | const zcu = pt.zcu; | 9906 | const zcu = pt.zcu; |
| 9911 | const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; | 9907 | const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; |
| 9912 | const ptr = try self.resolveInst(atomic_load.ptr); | 9908 | const ptr = try self.resolveInst(atomic_load.ptr); |
| ... | @@ -9915,14 +9911,14 @@ pub const FuncGen = struct { | ... | @@ -9915,14 +9911,14 @@ pub const FuncGen = struct { |
| 9915 | const elem_ty = Type.fromInterned(info.child); | 9911 | const elem_ty = Type.fromInterned(info.child); |
| 9916 | if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none; | 9912 | if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none; |
| 9917 | const ordering = toLlvmAtomicOrdering(atomic_load.order); | 9913 | const ordering = toLlvmAtomicOrdering(atomic_load.order); |
| 9918 | const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false); | 9914 | const llvm_abi_ty = try o.getAtomicAbiType(pt, elem_ty, false); |
| 9919 | const ptr_alignment = (if (info.flags.alignment != .none) | 9915 | const ptr_alignment = (if (info.flags.alignment != .none) |
| 9920 | @as(InternPool.Alignment, info.flags.alignment) | 9916 | @as(InternPool.Alignment, info.flags.alignment) |
| 9921 | else | 9917 | else |
| 9922 | Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm(); | 9918 | Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm(); |
| 9923 | const access_kind: Builder.MemoryAccessKind = | 9919 | const access_kind: Builder.MemoryAccessKind = |
| 9924 | if (info.flags.is_volatile) .@"volatile" else .normal; | 9920 | if (info.flags.is_volatile) .@"volatile" else .normal; |
| 9925 | const elem_llvm_ty = try o.lowerType(elem_ty); | 9921 | const elem_llvm_ty = try o.lowerType(pt, elem_ty); |
| 9926 | | 9922 | |
| 9927 | self.maybeMarkAllowZeroAccess(info); | 9923 | self.maybeMarkAllowZeroAccess(info); |
| 9928 | | 9924 | |
| ... | @@ -9956,7 +9952,7 @@ pub const FuncGen = struct { | ... | @@ -9956,7 +9952,7 @@ pub const FuncGen = struct { |
| 9956 | ordering: Builder.AtomicOrdering, | 9952 | ordering: Builder.AtomicOrdering, |
| 9957 | ) !Builder.Value { | 9953 | ) !Builder.Value { |
| 9958 | const o = self.ng.object; | 9954 | const o = self.ng.object; |
| 9959 | const pt = o.pt; | 9955 | const pt = self.ng.pt; |
| 9960 | const zcu = pt.zcu; | 9956 | const zcu = pt.zcu; |
| 9961 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 9957 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9962 | const ptr_ty = self.typeOf(bin_op.lhs); | 9958 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | @@ -9964,7 +9960,7 @@ pub const FuncGen = struct { | ... | @@ -9964,7 +9960,7 @@ pub const FuncGen = struct { |
| 9964 | if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none; | 9960 | if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none; |
| 9965 | const ptr = try self.resolveInst(bin_op.lhs); | 9961 | const ptr = try self.resolveInst(bin_op.lhs); |
| 9966 | var element = try self.resolveInst(bin_op.rhs); | 9962 | var element = try self.resolveInst(bin_op.rhs); |
| 9967 | const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false); | 9963 | const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false); |
| 9968 | | 9964 | |
| 9969 | if (llvm_abi_ty != .none) { | 9965 | if (llvm_abi_ty != .none) { |
| 9970 | // operand needs widening | 9966 | // operand needs widening |
| ... | @@ -9984,7 +9980,7 @@ pub const FuncGen = struct { | ... | @@ -9984,7 +9980,7 @@ pub const FuncGen = struct { |
| 9984 | | 9980 | |
| 9985 | fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { | 9981 | fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9986 | const o = self.ng.object; | 9982 | const o = self.ng.object; |
| 9987 | const pt = o.pt; | 9983 | const pt = self.ng.pt; |
| 9988 | const zcu = pt.zcu; | 9984 | const zcu = pt.zcu; |
| 9989 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 9985 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9990 | const dest_slice = try self.resolveInst(bin_op.lhs); | 9986 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| ... | @@ -10081,13 +10077,13 @@ pub const FuncGen = struct { | ... | @@ -10081,13 +10077,13 @@ pub const FuncGen = struct { |
| 10081 | const body_block = try self.wip.block(1, "InlineMemsetBody"); | 10077 | const body_block = try self.wip.block(1, "InlineMemsetBody"); |
| 10082 | const end_block = try self.wip.block(1, "InlineMemsetEnd"); | 10078 | const end_block = try self.wip.block(1, "InlineMemsetEnd"); |
| 10083 | | 10079 | |
| 10084 | const llvm_usize_ty = try o.lowerType(Type.usize); | 10080 | const llvm_usize_ty = try o.lowerType(pt, Type.usize); |
| 10085 | const len = switch (ptr_ty.ptrSize(zcu)) { | 10081 | const len = switch (ptr_ty.ptrSize(zcu)) { |
| 10086 | .slice => try self.wip.extractValue(dest_slice, &.{1}, ""), | 10082 | .slice => try self.wip.extractValue(dest_slice, &.{1}, ""), |
| 10087 | .one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)), | 10083 | .one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)), |
| 10088 | .many, .c => unreachable, | 10084 | .many, .c => unreachable, |
| 10089 | }; | 10085 | }; |
| 10090 | const elem_llvm_ty = try o.lowerType(elem_ty); | 10086 | 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}, ""); | 10087 | const end_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, dest_ptr, &.{len}, ""); |
| 10092 | _ = try self.wip.br(loop_block); | 10088 | _ = try self.wip.br(loop_block); |
| 10093 | | 10089 | |
| ... | @@ -10121,8 +10117,7 @@ pub const FuncGen = struct { | ... | @@ -10121,8 +10117,7 @@ pub const FuncGen = struct { |
| 10121 | } | 10117 | } |
| 10122 | | 10118 | |
| 10123 | fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10119 | fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10124 | const o = self.ng.object; | 10120 | const pt = self.ng.pt; |
| 10125 | const pt = o.pt; | | |
| 10126 | const zcu = pt.zcu; | 10121 | const zcu = pt.zcu; |
| 10127 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 10122 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 10128 | const dest_slice = try self.resolveInst(bin_op.lhs); | 10123 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| ... | @@ -10151,8 +10146,7 @@ pub const FuncGen = struct { | ... | @@ -10151,8 +10146,7 @@ pub const FuncGen = struct { |
| 10151 | } | 10146 | } |
| 10152 | | 10147 | |
| 10153 | fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10148 | fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10154 | const o = self.ng.object; | 10149 | const pt = self.ng.pt; |
| 10155 | const pt = o.pt; | | |
| 10156 | const zcu = pt.zcu; | 10150 | const zcu = pt.zcu; |
| 10157 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 10151 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 10158 | const dest_slice = try self.resolveInst(bin_op.lhs); | 10152 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| ... | @@ -10178,7 +10172,7 @@ pub const FuncGen = struct { | ... | @@ -10178,7 +10172,7 @@ pub const FuncGen = struct { |
| 10178 | | 10172 | |
| 10179 | fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10173 | fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10180 | const o = self.ng.object; | 10174 | const o = self.ng.object; |
| 10181 | const pt = o.pt; | 10175 | const pt = self.ng.pt; |
| 10182 | const zcu = pt.zcu; | 10176 | const zcu = pt.zcu; |
| 10183 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; | 10177 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 10184 | const un_ptr_ty = self.typeOf(bin_op.lhs); | 10178 | const un_ptr_ty = self.typeOf(bin_op.lhs); |
| ... | @@ -10199,7 +10193,7 @@ pub const FuncGen = struct { | ... | @@ -10199,7 +10193,7 @@ pub const FuncGen = struct { |
| 10199 | return .none; | 10193 | return .none; |
| 10200 | } | 10194 | } |
| 10201 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); | 10195 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| 10202 | const tag_field_ptr = try self.wip.gepStruct(try o.lowerType(un_ty), union_ptr, tag_index, ""); | 10196 | const tag_field_ptr = try self.wip.gepStruct(try o.lowerType(pt, un_ty), union_ptr, tag_index, ""); |
| 10203 | // TODO alignment on this store | 10197 | // TODO alignment on this store |
| 10204 | _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, .default); | 10198 | _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, .default); |
| 10205 | return .none; | 10199 | return .none; |
| ... | @@ -10207,7 +10201,7 @@ pub const FuncGen = struct { | ... | @@ -10207,7 +10201,7 @@ pub const FuncGen = struct { |
| 10207 | | 10201 | |
| 10208 | fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10202 | fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10209 | const o = self.ng.object; | 10203 | const o = self.ng.object; |
| 10210 | const pt = o.pt; | 10204 | const pt = self.ng.pt; |
| 10211 | const zcu = pt.zcu; | 10205 | const zcu = pt.zcu; |
| 10212 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 10206 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10213 | const un_ty = self.typeOf(ty_op.operand); | 10207 | const un_ty = self.typeOf(ty_op.operand); |
| ... | @@ -10215,7 +10209,7 @@ pub const FuncGen = struct { | ... | @@ -10215,7 +10209,7 @@ pub const FuncGen = struct { |
| 10215 | if (layout.tag_size == 0) return .none; | 10209 | if (layout.tag_size == 0) return .none; |
| 10216 | const union_handle = try self.resolveInst(ty_op.operand); | 10210 | const union_handle = try self.resolveInst(ty_op.operand); |
| 10217 | if (isByRef(un_ty, zcu)) { | 10211 | if (isByRef(un_ty, zcu)) { |
| 10218 | const llvm_un_ty = try o.lowerType(un_ty); | 10212 | const llvm_un_ty = try o.lowerType(pt, un_ty); |
| 10219 | if (layout.payload_size == 0) | 10213 | if (layout.payload_size == 0) |
| 10220 | return self.wip.load(.normal, llvm_un_ty, union_handle, .default, ""); | 10214 | return self.wip.load(.normal, llvm_un_ty, union_handle, .default, ""); |
| 10221 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); | 10215 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| ... | @@ -10247,6 +10241,7 @@ pub const FuncGen = struct { | ... | @@ -10247,6 +10241,7 @@ pub const FuncGen = struct { |
| 10247 | | 10241 | |
| 10248 | fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { | 10242 | fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { |
| 10249 | const o = self.ng.object; | 10243 | const o = self.ng.object; |
| | 10244 | const pt = self.ng.pt; |
| 10250 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 10245 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10251 | const inst_ty = self.typeOfIndex(inst); | 10246 | const inst_ty = self.typeOfIndex(inst); |
| 10252 | const operand_ty = self.typeOf(ty_op.operand); | 10247 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | @@ -10256,15 +10251,16 @@ pub const FuncGen = struct { | ... | @@ -10256,15 +10251,16 @@ pub const FuncGen = struct { |
| 10256 | .normal, | 10251 | .normal, |
| 10257 | .none, | 10252 | .none, |
| 10258 | intrinsic, | 10253 | intrinsic, |
| 10259 | &.{try o.lowerType(operand_ty)}, | 10254 | &.{try o.lowerType(pt, operand_ty)}, |
| 10260 | &.{ operand, .false }, | 10255 | &.{ operand, .false }, |
| 10261 | "", | 10256 | "", |
| 10262 | ); | 10257 | ); |
| 10263 | return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), ""); | 10258 | return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), ""); |
| 10264 | } | 10259 | } |
| 10265 | | 10260 | |
| 10266 | fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { | 10261 | fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { |
| 10267 | const o = self.ng.object; | 10262 | const o = self.ng.object; |
| | 10263 | const pt = self.ng.pt; |
| 10268 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 10264 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10269 | const inst_ty = self.typeOfIndex(inst); | 10265 | const inst_ty = self.typeOfIndex(inst); |
| 10270 | const operand_ty = self.typeOf(ty_op.operand); | 10266 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | @@ -10274,16 +10270,17 @@ pub const FuncGen = struct { | ... | @@ -10274,16 +10270,17 @@ pub const FuncGen = struct { |
| 10274 | .normal, | 10270 | .normal, |
| 10275 | .none, | 10271 | .none, |
| 10276 | intrinsic, | 10272 | intrinsic, |
| 10277 | &.{try o.lowerType(operand_ty)}, | 10273 | &.{try o.lowerType(pt, operand_ty)}, |
| 10278 | &.{operand}, | 10274 | &.{operand}, |
| 10279 | "", | 10275 | "", |
| 10280 | ); | 10276 | ); |
| 10281 | return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), ""); | 10277 | return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), ""); |
| 10282 | } | 10278 | } |
| 10283 | | 10279 | |
| 10284 | fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10280 | fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10285 | const o = self.ng.object; | 10281 | const o = self.ng.object; |
| 10286 | const zcu = o.pt.zcu; | 10282 | const pt = self.ng.pt; |
| | 10283 | const zcu = pt.zcu; |
| 10287 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 10284 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10288 | const operand_ty = self.typeOf(ty_op.operand); | 10285 | const operand_ty = self.typeOf(ty_op.operand); |
| 10289 | var bits = operand_ty.intInfo(zcu).bits; | 10286 | var bits = operand_ty.intInfo(zcu).bits; |
| ... | @@ -10291,7 +10288,7 @@ pub const FuncGen = struct { | ... | @@ -10291,7 +10288,7 @@ pub const FuncGen = struct { |
| 10291 | | 10288 | |
| 10292 | const inst_ty = self.typeOfIndex(inst); | 10289 | const inst_ty = self.typeOfIndex(inst); |
| 10293 | var operand = try self.resolveInst(ty_op.operand); | 10290 | var operand = try self.resolveInst(ty_op.operand); |
| 10294 | var llvm_operand_ty = try o.lowerType(operand_ty); | 10291 | var llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 10295 | | 10292 | |
| 10296 | if (bits % 16 == 8) { | 10293 | if (bits % 16 == 8) { |
| 10297 | // If not an even byte-multiple, we need zero-extend + shift-left 1 byte | 10294 | // If not an even byte-multiple, we need zero-extend + shift-left 1 byte |
| ... | @@ -10312,12 +10309,13 @@ pub const FuncGen = struct { | ... | @@ -10312,12 +10309,13 @@ pub const FuncGen = struct { |
| 10312 | | 10309 | |
| 10313 | const result = | 10310 | const result = |
| 10314 | try self.wip.callIntrinsic(.normal, .none, .bswap, &.{llvm_operand_ty}, &.{operand}, ""); | 10311 | try self.wip.callIntrinsic(.normal, .none, .bswap, &.{llvm_operand_ty}, &.{operand}, ""); |
| 10315 | return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), ""); | 10312 | return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), ""); |
| 10316 | } | 10313 | } |
| 10317 | | 10314 | |
| 10318 | fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10315 | fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10319 | const o = self.ng.object; | 10316 | const o = self.ng.object; |
| 10320 | const zcu = o.pt.zcu; | 10317 | const pt = self.ng.pt; |
| | 10318 | const zcu = pt.zcu; |
| 10321 | const ip = &zcu.intern_pool; | 10319 | const ip = &zcu.intern_pool; |
| 10322 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 10320 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10323 | const operand = try self.resolveInst(ty_op.operand); | 10321 | const operand = try self.resolveInst(ty_op.operand); |
| ... | @@ -10332,7 +10330,7 @@ pub const FuncGen = struct { | ... | @@ -10332,7 +10330,7 @@ pub const FuncGen = struct { |
| 10332 | | 10330 | |
| 10333 | for (0..names.len) |name_index| { | 10331 | for (0..names.len) |name_index| { |
| 10334 | const err_int = ip.getErrorValueIfExists(names.get(ip)[name_index]).?; | 10332 | const err_int = ip.getErrorValueIfExists(names.get(ip)[name_index]).?; |
| 10335 | const this_tag_int_value = try o.builder.intConst(try o.errorIntType(), err_int); | 10333 | const this_tag_int_value = try o.builder.intConst(try o.errorIntType(pt), err_int); |
| 10336 | try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip); | 10334 | try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip); |
| 10337 | } | 10335 | } |
| 10338 | self.wip.cursor = .{ .block = valid_block }; | 10336 | self.wip.cursor = .{ .block = valid_block }; |
| ... | @@ -10367,7 +10365,7 @@ pub const FuncGen = struct { | ... | @@ -10367,7 +10365,7 @@ pub const FuncGen = struct { |
| 10367 | | 10365 | |
| 10368 | fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !Builder.Function.Index { | 10366 | fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !Builder.Function.Index { |
| 10369 | const o = self.ng.object; | 10367 | const o = self.ng.object; |
| 10370 | const pt = o.pt; | 10368 | const pt = self.ng.pt; |
| 10371 | const zcu = pt.zcu; | 10369 | const zcu = pt.zcu; |
| 10372 | const ip = &zcu.intern_pool; | 10370 | const ip = &zcu.intern_pool; |
| 10373 | const enum_type = ip.loadEnumType(enum_ty.toIntern()); | 10371 | const enum_type = ip.loadEnumType(enum_ty.toIntern()); |
| ... | @@ -10379,7 +10377,7 @@ pub const FuncGen = struct { | ... | @@ -10379,7 +10377,7 @@ pub const FuncGen = struct { |
| 10379 | | 10377 | |
| 10380 | const target = &zcu.root_mod.resolved_target.result; | 10378 | const target = &zcu.root_mod.resolved_target.result; |
| 10381 | const function_index = try o.builder.addFunction( | 10379 | const function_index = try o.builder.addFunction( |
| 10382 | try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal), | 10380 | try o.builder.fnType(.i1, &.{try o.lowerType(pt, Type.fromInterned(enum_type.tag_ty))}, .normal), |
| 10383 | try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_type.name.fmt(ip)}), | 10381 | try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_type.name.fmt(ip)}), |
| 10384 | toLlvmAddressSpace(.generic, target), | 10382 | toLlvmAddressSpace(.generic, target), |
| 10385 | ); | 10383 | ); |
| ... | @@ -10408,6 +10406,7 @@ pub const FuncGen = struct { | ... | @@ -10408,6 +10406,7 @@ pub const FuncGen = struct { |
| 10408 | | 10406 | |
| 10409 | for (0..enum_type.names.len) |field_index| { | 10407 | for (0..enum_type.names.len) |field_index| { |
| 10410 | const this_tag_int_value = try o.lowerValue( | 10408 | const this_tag_int_value = try o.lowerValue( |
| | 10409 | pt, |
| 10411 | (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(), | 10410 | (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(), |
| 10412 | ); | 10411 | ); |
| 10413 | try wip_switch.addCase(this_tag_int_value, named_block, &wip); | 10412 | try wip_switch.addCase(this_tag_int_value, named_block, &wip); |
| ... | @@ -10424,11 +10423,12 @@ pub const FuncGen = struct { | ... | @@ -10424,11 +10423,12 @@ pub const FuncGen = struct { |
| 10424 | | 10423 | |
| 10425 | fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10424 | fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10426 | const o = self.ng.object; | 10425 | const o = self.ng.object; |
| | 10426 | const pt = self.ng.pt; |
| 10427 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | 10427 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 10428 | const operand = try self.resolveInst(un_op); | 10428 | const operand = try self.resolveInst(un_op); |
| 10429 | const enum_ty = self.typeOf(un_op); | 10429 | const enum_ty = self.typeOf(un_op); |
| 10430 | | 10430 | |
| 10431 | const llvm_fn = try o.getEnumTagNameFunction(enum_ty); | 10431 | const llvm_fn = try o.getEnumTagNameFunction(pt, enum_ty); |
| 10432 | return self.wip.call( | 10432 | return self.wip.call( |
| 10433 | .normal, | 10433 | .normal, |
| 10434 | .fastcc, | 10434 | .fastcc, |
| ... | @@ -10442,10 +10442,11 @@ pub const FuncGen = struct { | ... | @@ -10442,10 +10442,11 @@ pub const FuncGen = struct { |
| 10442 | | 10442 | |
| 10443 | fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10443 | fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10444 | const o = self.ng.object; | 10444 | const o = self.ng.object; |
| | 10445 | const pt = self.ng.pt; |
| 10445 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; | 10446 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 10446 | const operand = try self.resolveInst(un_op); | 10447 | const operand = try self.resolveInst(un_op); |
| 10447 | const slice_ty = self.typeOfIndex(inst); | 10448 | const slice_ty = self.typeOfIndex(inst); |
| 10448 | const slice_llvm_ty = try o.lowerType(slice_ty); | 10449 | const slice_llvm_ty = try o.lowerType(pt, slice_ty); |
| 10449 | | 10450 | |
| 10450 | const error_name_table_ptr = try self.getErrorNameTable(); | 10451 | const error_name_table_ptr = try self.getErrorNameTable(); |
| 10451 | const error_name_table = | 10452 | const error_name_table = |
| ... | @@ -10457,10 +10458,11 @@ pub const FuncGen = struct { | ... | @@ -10457,10 +10458,11 @@ pub const FuncGen = struct { |
| 10457 | | 10458 | |
| 10458 | fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10459 | fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10459 | const o = self.ng.object; | 10460 | const o = self.ng.object; |
| | 10461 | const pt = self.ng.pt; |
| 10460 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 10462 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10461 | const scalar = try self.resolveInst(ty_op.operand); | 10463 | const scalar = try self.resolveInst(ty_op.operand); |
| 10462 | const vector_ty = self.typeOfIndex(inst); | 10464 | const vector_ty = self.typeOfIndex(inst); |
| 10463 | return self.wip.splatVector(try o.lowerType(vector_ty), scalar, ""); | 10465 | return self.wip.splatVector(try o.lowerType(pt, vector_ty), scalar, ""); |
| 10464 | } | 10466 | } |
| 10465 | | 10467 | |
| 10466 | fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10468 | fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| ... | @@ -10475,7 +10477,7 @@ pub const FuncGen = struct { | ... | @@ -10475,7 +10477,7 @@ pub const FuncGen = struct { |
| 10475 | | 10477 | |
| 10476 | fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10478 | fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10477 | const o = fg.ng.object; | 10479 | const o = fg.ng.object; |
| 10478 | const pt = o.pt; | 10480 | const pt = fg.ng.pt; |
| 10479 | const zcu = pt.zcu; | 10481 | const zcu = pt.zcu; |
| 10480 | const gpa = zcu.gpa; | 10482 | const gpa = zcu.gpa; |
| 10481 | | 10483 | |
| ... | @@ -10484,9 +10486,9 @@ pub const FuncGen = struct { | ... | @@ -10484,9 +10486,9 @@ pub const FuncGen = struct { |
| 10484 | const operand = try fg.resolveInst(unwrapped.operand); | 10486 | const operand = try fg.resolveInst(unwrapped.operand); |
| 10485 | const mask = unwrapped.mask; | 10487 | const mask = unwrapped.mask; |
| 10486 | const operand_ty = fg.typeOf(unwrapped.operand); | 10488 | const operand_ty = fg.typeOf(unwrapped.operand); |
| 10487 | const llvm_operand_ty = try o.lowerType(operand_ty); | 10489 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 10488 | const llvm_result_ty = try o.lowerType(unwrapped.result_ty); | 10490 | const llvm_result_ty = try o.lowerType(pt, unwrapped.result_ty); |
| 10489 | const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu)); | 10491 | 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); | 10492 | const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty); |
| 10491 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); | 10493 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); |
| 10492 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); | 10494 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); |
| ... | @@ -10516,7 +10518,7 @@ pub const FuncGen = struct { | ... | @@ -10516,7 +10518,7 @@ pub const FuncGen = struct { |
| 10516 | .elem => llvm_poison_elem, | 10518 | .elem => llvm_poison_elem, |
| 10517 | .value => |val| if (!Value.fromInterned(val).isUndef(zcu)) elem: { | 10519 | .value => |val| if (!Value.fromInterned(val).isUndef(zcu)) elem: { |
| 10518 | any_defined_comptime_value = true; | 10520 | any_defined_comptime_value = true; |
| 10519 | break :elem try o.lowerValue(val); | 10521 | break :elem try o.lowerValue(pt, val); |
| 10520 | } else llvm_poison_elem, | 10522 | } else llvm_poison_elem, |
| 10521 | }; | 10523 | }; |
| 10522 | } | 10524 | } |
| ... | @@ -10582,14 +10584,14 @@ pub const FuncGen = struct { | ... | @@ -10582,14 +10584,14 @@ pub const FuncGen = struct { |
| 10582 | | 10584 | |
| 10583 | fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10585 | fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10584 | const o = fg.ng.object; | 10586 | const o = fg.ng.object; |
| 10585 | const pt = o.pt; | 10587 | const pt = fg.ng.pt; |
| 10586 | const zcu = pt.zcu; | 10588 | const zcu = pt.zcu; |
| 10587 | const gpa = zcu.gpa; | 10589 | const gpa = zcu.gpa; |
| 10588 | | 10590 | |
| 10589 | const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst); | 10591 | const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst); |
| 10590 | | 10592 | |
| 10591 | const mask = unwrapped.mask; | 10593 | const mask = unwrapped.mask; |
| 10592 | const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu)); | 10594 | const llvm_elem_ty = try o.lowerType(pt, unwrapped.result_ty.childType(zcu)); |
| 10593 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); | 10595 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); |
| 10594 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); | 10596 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); |
| 10595 | | 10597 | |
| ... | @@ -10681,7 +10683,8 @@ pub const FuncGen = struct { | ... | @@ -10681,7 +10683,8 @@ pub const FuncGen = struct { |
| 10681 | accum_init: Builder.Value, | 10683 | accum_init: Builder.Value, |
| 10682 | ) !Builder.Value { | 10684 | ) !Builder.Value { |
| 10683 | const o = self.ng.object; | 10685 | const o = self.ng.object; |
| 10684 | const usize_ty = try o.lowerType(Type.usize); | 10686 | const pt = self.ng.pt; |
| | 10687 | const usize_ty = try o.lowerType(pt, Type.usize); |
| 10685 | const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len); | 10688 | const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len); |
| 10686 | const llvm_result_ty = accum_init.typeOfWip(&self.wip); | 10689 | const llvm_result_ty = accum_init.typeOfWip(&self.wip); |
| 10687 | | 10690 | |
| ... | @@ -10735,15 +10738,16 @@ pub const FuncGen = struct { | ... | @@ -10735,15 +10738,16 @@ pub const FuncGen = struct { |
| 10735 | | 10738 | |
| 10736 | fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { | 10739 | fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 10737 | const o = self.ng.object; | 10740 | const o = self.ng.object; |
| 10738 | const zcu = o.pt.zcu; | 10741 | const pt = self.ng.pt; |
| | 10742 | const zcu = pt.zcu; |
| 10739 | const target = zcu.getTarget(); | 10743 | const target = zcu.getTarget(); |
| 10740 | | 10744 | |
| 10741 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; | 10745 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; |
| 10742 | const operand = try self.resolveInst(reduce.operand); | 10746 | const operand = try self.resolveInst(reduce.operand); |
| 10743 | const operand_ty = self.typeOf(reduce.operand); | 10747 | const operand_ty = self.typeOf(reduce.operand); |
| 10744 | const llvm_operand_ty = try o.lowerType(operand_ty); | 10748 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 10745 | const scalar_ty = self.typeOfIndex(inst); | 10749 | const scalar_ty = self.typeOfIndex(inst); |
| 10746 | const llvm_scalar_ty = try o.lowerType(scalar_ty); | 10750 | const llvm_scalar_ty = try o.lowerType(pt, scalar_ty); |
| 10747 | | 10751 | |
| 10748 | switch (reduce.operation) { | 10752 | switch (reduce.operation) { |
| 10749 | .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) { | 10753 | .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) { |
| ... | @@ -10845,14 +10849,14 @@ pub const FuncGen = struct { | ... | @@ -10845,14 +10849,14 @@ pub const FuncGen = struct { |
| 10845 | | 10849 | |
| 10846 | fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10850 | fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10847 | const o = self.ng.object; | 10851 | const o = self.ng.object; |
| 10848 | const pt = o.pt; | 10852 | const pt = self.ng.pt; |
| 10849 | const zcu = pt.zcu; | 10853 | const zcu = pt.zcu; |
| 10850 | const ip = &zcu.intern_pool; | 10854 | const ip = &zcu.intern_pool; |
| 10851 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 10855 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 10852 | const result_ty = self.typeOfIndex(inst); | 10856 | const result_ty = self.typeOfIndex(inst); |
| 10853 | const len: usize = @intCast(result_ty.arrayLen(zcu)); | 10857 | 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]); | 10858 | const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[ty_pl.payload..][0..len]); |
| 10855 | const llvm_result_ty = try o.lowerType(result_ty); | 10859 | const llvm_result_ty = try o.lowerType(pt, result_ty); |
| 10856 | | 10860 | |
| 10857 | switch (result_ty.zigTypeTag(zcu)) { | 10861 | switch (result_ty.zigTypeTag(zcu)) { |
| 10858 | .vector => { | 10862 | .vector => { |
| ... | @@ -10933,7 +10937,7 @@ pub const FuncGen = struct { | ... | @@ -10933,7 +10937,7 @@ pub const FuncGen = struct { |
| 10933 | .array => { | 10937 | .array => { |
| 10934 | assert(isByRef(result_ty, zcu)); | 10938 | assert(isByRef(result_ty, zcu)); |
| 10935 | | 10939 | |
| 10936 | const llvm_usize = try o.lowerType(Type.usize); | 10940 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 10937 | const usize_zero = try o.builder.intValue(llvm_usize, 0); | 10941 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 10938 | const alignment = result_ty.abiAlignment(zcu).toLlvm(); | 10942 | const alignment = result_ty.abiAlignment(zcu).toLlvm(); |
| 10939 | const alloca_inst = try self.buildAlloca(llvm_result_ty, alignment); | 10943 | const alloca_inst = try self.buildAlloca(llvm_result_ty, alignment); |
| ... | @@ -10966,13 +10970,13 @@ pub const FuncGen = struct { | ... | @@ -10966,13 +10970,13 @@ pub const FuncGen = struct { |
| 10966 | | 10970 | |
| 10967 | fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 10971 | fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10968 | const o = self.ng.object; | 10972 | const o = self.ng.object; |
| 10969 | const pt = o.pt; | 10973 | const pt = self.ng.pt; |
| 10970 | const zcu = pt.zcu; | 10974 | const zcu = pt.zcu; |
| 10971 | const ip = &zcu.intern_pool; | 10975 | const ip = &zcu.intern_pool; |
| 10972 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; | 10976 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 10973 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; | 10977 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 10974 | const union_ty = self.typeOfIndex(inst); | 10978 | const union_ty = self.typeOfIndex(inst); |
| 10975 | const union_llvm_ty = try o.lowerType(union_ty); | 10979 | const union_llvm_ty = try o.lowerType(pt, union_ty); |
| 10976 | const layout = union_ty.unionGetLayout(zcu); | 10980 | const layout = union_ty.unionGetLayout(zcu); |
| 10977 | const union_obj = zcu.typeToUnion(union_ty).?; | 10981 | const union_obj = zcu.typeToUnion(union_ty).?; |
| 10978 | | 10982 | |
| ... | @@ -11014,10 +11018,10 @@ pub const FuncGen = struct { | ... | @@ -11014,10 +11018,10 @@ pub const FuncGen = struct { |
| 11014 | const result_ptr = try self.buildAlloca(union_llvm_ty, alignment); | 11018 | const result_ptr = try self.buildAlloca(union_llvm_ty, alignment); |
| 11015 | const llvm_payload = try self.resolveInst(extra.init); | 11019 | const llvm_payload = try self.resolveInst(extra.init); |
| 11016 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]); | 11020 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]); |
| 11017 | const field_llvm_ty = try o.lowerType(field_ty); | 11021 | const field_llvm_ty = try o.lowerType(pt, field_ty); |
| 11018 | const field_size = field_ty.abiSize(zcu); | 11022 | const field_size = field_ty.abiSize(zcu); |
| 11019 | const field_align = union_ty.fieldAlignment(extra.field_index, zcu); | 11023 | const field_align = union_ty.fieldAlignment(extra.field_index, zcu); |
| 11020 | const llvm_usize = try o.lowerType(Type.usize); | 11024 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 11021 | const usize_zero = try o.builder.intValue(llvm_usize, 0); | 11025 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 11022 | | 11026 | |
| 11023 | const llvm_union_ty = t: { | 11027 | const llvm_union_ty = t: { |
| ... | @@ -11035,7 +11039,7 @@ pub const FuncGen = struct { | ... | @@ -11035,7 +11039,7 @@ pub const FuncGen = struct { |
| 11035 | }); | 11039 | }); |
| 11036 | }; | 11040 | }; |
| 11037 | if (layout.tag_size == 0) break :t try o.builder.structType(.normal, &.{payload_ty}); | 11041 | if (layout.tag_size == 0) break :t try o.builder.structType(.normal, &.{payload_ty}); |
| 11038 | const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty)); | 11042 | const tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty)); |
| 11039 | var fields: [3]Builder.Type = undefined; | 11043 | var fields: [3]Builder.Type = undefined; |
| 11040 | var fields_len: usize = 2; | 11044 | var fields_len: usize = 2; |
| 11041 | if (layout.tag_align.compare(.gte, layout.payload_align)) { | 11045 | if (layout.tag_align.compare(.gte, layout.payload_align)) { |
| ... | @@ -11076,7 +11080,7 @@ pub const FuncGen = struct { | ... | @@ -11076,7 +11080,7 @@ pub const FuncGen = struct { |
| 11076 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); | 11080 | 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) }; | 11081 | 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, ""); | 11082 | const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, ""); |
| 11079 | const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty)); | 11083 | const tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty)); |
| 11080 | var big_int_space: Value.BigIntSpace = undefined; | 11084 | var big_int_space: Value.BigIntSpace = undefined; |
| 11081 | const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu); | 11085 | 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); | 11086 | const llvm_tag = try o.builder.bigIntValue(tag_ty, tag_big_int); |
| ... | @@ -11106,7 +11110,7 @@ pub const FuncGen = struct { | ... | @@ -11106,7 +11110,7 @@ pub const FuncGen = struct { |
| 11106 | // by the target. | 11110 | // by the target. |
| 11107 | // To work around this, don't emit llvm.prefetch in this case. | 11111 | // To work around this, don't emit llvm.prefetch in this case. |
| 11108 | // See https://bugs.llvm.org/show_bug.cgi?id=21037 | 11112 | // See https://bugs.llvm.org/show_bug.cgi?id=21037 |
| 11109 | const zcu = o.pt.zcu; | 11113 | const zcu = self.ng.pt.zcu; |
| 11110 | const target = zcu.getTarget(); | 11114 | const target = zcu.getTarget(); |
| 11111 | switch (prefetch.cache) { | 11115 | switch (prefetch.cache) { |
| 11112 | .instruction => switch (target.cpu.arch) { | 11116 | .instruction => switch (target.cpu.arch) { |
| ... | @@ -11139,11 +11143,12 @@ pub const FuncGen = struct { | ... | @@ -11139,11 +11143,12 @@ pub const FuncGen = struct { |
| 11139 | | 11143 | |
| 11140 | fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 11144 | fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11141 | const o = self.ng.object; | 11145 | const o = self.ng.object; |
| | 11146 | const pt = self.ng.pt; |
| 11142 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 11147 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 11143 | const inst_ty = self.typeOfIndex(inst); | 11148 | const inst_ty = self.typeOfIndex(inst); |
| 11144 | const operand = try self.resolveInst(ty_op.operand); | 11149 | const operand = try self.resolveInst(ty_op.operand); |
| 11145 | | 11150 | |
| 11146 | return self.wip.cast(.addrspacecast, operand, try o.lowerType(inst_ty), ""); | 11151 | return self.wip.cast(.addrspacecast, operand, try o.lowerType(pt, inst_ty), ""); |
| 11147 | } | 11152 | } |
| 11148 | | 11153 | |
| 11149 | fn workIntrinsic( | 11154 | fn workIntrinsic( |
| ... | @@ -11161,8 +11166,7 @@ pub const FuncGen = struct { | ... | @@ -11161,8 +11166,7 @@ pub const FuncGen = struct { |
| 11161 | } | 11166 | } |
| 11162 | | 11167 | |
| 11163 | fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 11168 | fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11164 | const o = self.ng.object; | 11169 | const target = self.ng.pt.zcu.getTarget(); |
| 11165 | const target = o.pt.zcu.getTarget(); | | |
| 11166 | | 11170 | |
| 11167 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 11171 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 11168 | const dimension = pl_op.payload; | 11172 | const dimension = pl_op.payload; |
| ... | @@ -11176,7 +11180,8 @@ pub const FuncGen = struct { | ... | @@ -11176,7 +11180,8 @@ pub const FuncGen = struct { |
| 11176 | | 11180 | |
| 11177 | fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 11181 | fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11178 | const o = self.ng.object; | 11182 | const o = self.ng.object; |
| 11179 | const target = o.pt.zcu.getTarget(); | 11183 | const pt = self.ng.pt; |
| | 11184 | const target = pt.zcu.getTarget(); |
| 11180 | | 11185 | |
| 11181 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 11186 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 11182 | const dimension = pl_op.payload; | 11187 | const dimension = pl_op.payload; |
| ... | @@ -11193,7 +11198,7 @@ pub const FuncGen = struct { | ... | @@ -11193,7 +11198,7 @@ pub const FuncGen = struct { |
| 11193 | // Load the work_group_* member from the struct as u16. | 11198 | // 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. | 11199 | // 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, &.{ | 11200 | const workgroup_size_ptr = try self.wip.gep(.inbounds, .i16, dispatch_ptr, &.{ |
| 11196 | try o.builder.intValue(try o.lowerType(Type.usize), 2 + dimension), | 11201 | try o.builder.intValue(try o.lowerType(pt, Type.usize), 2 + dimension), |
| 11197 | }, ""); | 11202 | }, ""); |
| 11198 | const workgroup_size_alignment = comptime Builder.Alignment.fromByteUnits(2); | 11203 | const workgroup_size_alignment = comptime Builder.Alignment.fromByteUnits(2); |
| 11199 | return self.wip.load(.normal, .i16, workgroup_size_ptr, workgroup_size_alignment, ""); | 11204 | return self.wip.load(.normal, .i16, workgroup_size_ptr, workgroup_size_alignment, ""); |
| ... | @@ -11206,8 +11211,7 @@ pub const FuncGen = struct { | ... | @@ -11206,8 +11211,7 @@ pub const FuncGen = struct { |
| 11206 | } | 11211 | } |
| 11207 | | 11212 | |
| 11208 | fn airWorkGroupId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 11213 | fn airWorkGroupId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11209 | const o = self.ng.object; | 11214 | const target = self.ng.pt.zcu.getTarget(); |
| 11210 | const target = o.pt.zcu.getTarget(); | | |
| 11211 | | 11215 | |
| 11212 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 11216 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 11213 | const dimension = pl_op.payload; | 11217 | const dimension = pl_op.payload; |
| ... | @@ -11221,7 +11225,7 @@ pub const FuncGen = struct { | ... | @@ -11221,7 +11225,7 @@ pub const FuncGen = struct { |
| 11221 | | 11225 | |
| 11222 | fn getErrorNameTable(self: *FuncGen) Allocator.Error!Builder.Variable.Index { | 11226 | fn getErrorNameTable(self: *FuncGen) Allocator.Error!Builder.Variable.Index { |
| 11223 | const o = self.ng.object; | 11227 | const o = self.ng.object; |
| 11224 | const pt = o.pt; | 11228 | const pt = self.ng.pt; |
| 11225 | | 11229 | |
| 11226 | const table = o.error_name_table; | 11230 | const table = o.error_name_table; |
| 11227 | if (table != .none) return table; | 11231 | if (table != .none) return table; |
| ... | @@ -11271,8 +11275,7 @@ pub const FuncGen = struct { | ... | @@ -11271,8 +11275,7 @@ pub const FuncGen = struct { |
| 11271 | opt_ty: Type, | 11275 | opt_ty: Type, |
| 11272 | can_elide_load: bool, | 11276 | can_elide_load: bool, |
| 11273 | ) !Builder.Value { | 11277 | ) !Builder.Value { |
| 11274 | const o = fg.ng.object; | 11278 | const pt = fg.ng.pt; |
| 11275 | const pt = o.pt; | | |
| 11276 | const zcu = pt.zcu; | 11279 | const zcu = pt.zcu; |
| 11277 | const payload_ty = opt_ty.optionalChild(zcu); | 11280 | const payload_ty = opt_ty.optionalChild(zcu); |
| 11278 | | 11281 | |
| ... | @@ -11301,9 +11304,9 @@ pub const FuncGen = struct { | ... | @@ -11301,9 +11304,9 @@ pub const FuncGen = struct { |
| 11301 | non_null_bit: Builder.Value, | 11304 | non_null_bit: Builder.Value, |
| 11302 | ) !Builder.Value { | 11305 | ) !Builder.Value { |
| 11303 | const o = self.ng.object; | 11306 | const o = self.ng.object; |
| 11304 | const pt = o.pt; | 11307 | const pt = self.ng.pt; |
| 11305 | const zcu = pt.zcu; | 11308 | const zcu = pt.zcu; |
| 11306 | const optional_llvm_ty = try o.lowerType(optional_ty); | 11309 | const optional_llvm_ty = try o.lowerType(pt, optional_ty); |
| 11307 | const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, ""); | 11310 | const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, ""); |
| 11308 | | 11311 | |
| 11309 | if (isByRef(optional_ty, zcu)) { | 11312 | if (isByRef(optional_ty, zcu)) { |
| ... | @@ -11334,7 +11337,7 @@ pub const FuncGen = struct { | ... | @@ -11334,7 +11337,7 @@ pub const FuncGen = struct { |
| 11334 | field_index: u32, | 11337 | field_index: u32, |
| 11335 | ) !Builder.Value { | 11338 | ) !Builder.Value { |
| 11336 | const o = self.ng.object; | 11339 | const o = self.ng.object; |
| 11337 | const pt = o.pt; | 11340 | const pt = self.ng.pt; |
| 11338 | const zcu = pt.zcu; | 11341 | const zcu = pt.zcu; |
| 11339 | const struct_ty = struct_ptr_ty.childType(zcu); | 11342 | const struct_ty = struct_ptr_ty.childType(zcu); |
| 11340 | switch (struct_ty.zigTypeTag(zcu)) { | 11343 | switch (struct_ty.zigTypeTag(zcu)) { |
| ... | @@ -11357,12 +11360,12 @@ pub const FuncGen = struct { | ... | @@ -11357,12 +11360,12 @@ pub const FuncGen = struct { |
| 11357 | // Offset our operand pointer by the correct number of bytes. | 11360 | // 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); | 11361 | 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; | 11362 | if (byte_offset == 0) return struct_ptr; |
| 11360 | const usize_ty = try o.lowerType(Type.usize); | 11363 | const usize_ty = try o.lowerType(pt, Type.usize); |
| 11361 | const llvm_index = try o.builder.intValue(usize_ty, byte_offset); | 11364 | const llvm_index = try o.builder.intValue(usize_ty, byte_offset); |
| 11362 | return self.wip.gep(.inbounds, .i8, struct_ptr, &.{llvm_index}, ""); | 11365 | return self.wip.gep(.inbounds, .i8, struct_ptr, &.{llvm_index}, ""); |
| 11363 | }, | 11366 | }, |
| 11364 | else => { | 11367 | else => { |
| 11365 | const struct_llvm_ty = try o.lowerPtrElemTy(struct_ty); | 11368 | const struct_llvm_ty = try o.lowerPtrElemTy(pt, struct_ty); |
| 11366 | | 11369 | |
| 11367 | if (o.llvmFieldIndex(struct_ty, field_index)) |llvm_field_index| { | 11370 | if (o.llvmFieldIndex(struct_ty, field_index)) |llvm_field_index| { |
| 11368 | return self.wip.gepStruct(struct_llvm_ty, struct_ptr, llvm_field_index, ""); | 11371 | return self.wip.gepStruct(struct_llvm_ty, struct_ptr, llvm_field_index, ""); |
| ... | @@ -11372,7 +11375,7 @@ pub const FuncGen = struct { | ... | @@ -11372,7 +11375,7 @@ pub const FuncGen = struct { |
| 11372 | // the index to the element at index `1` to get a pointer to the end of | 11375 | // the index to the element at index `1` to get a pointer to the end of |
| 11373 | // the struct. | 11376 | // the struct. |
| 11374 | const llvm_index = try o.builder.intValue( | 11377 | const llvm_index = try o.builder.intValue( |
| 11375 | try o.lowerType(Type.usize), | 11378 | try o.lowerType(pt, Type.usize), |
| 11376 | @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)), | 11379 | @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)), |
| 11377 | ); | 11380 | ); |
| 11378 | return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, ""); | 11381 | return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, ""); |
| ... | @@ -11383,7 +11386,7 @@ pub const FuncGen = struct { | ... | @@ -11383,7 +11386,7 @@ pub const FuncGen = struct { |
| 11383 | const layout = struct_ty.unionGetLayout(zcu); | 11386 | const layout = struct_ty.unionGetLayout(zcu); |
| 11384 | if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr; | 11387 | 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)); | 11388 | const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)); |
| 11386 | const union_llvm_ty = try o.lowerType(struct_ty); | 11389 | const union_llvm_ty = try o.lowerType(pt, struct_ty); |
| 11387 | return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, ""); | 11390 | return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, ""); |
| 11388 | }, | 11391 | }, |
| 11389 | else => unreachable, | 11392 | else => unreachable, |
| ... | @@ -11403,9 +11406,9 @@ pub const FuncGen = struct { | ... | @@ -11403,9 +11406,9 @@ pub const FuncGen = struct { |
| 11403 | // => so load the byte aligned value and trunc the unwanted bits. | 11406 | // => so load the byte aligned value and trunc the unwanted bits. |
| 11404 | | 11407 | |
| 11405 | const o = fg.ng.object; | 11408 | const o = fg.ng.object; |
| 11406 | const pt = o.pt; | 11409 | const pt = fg.ng.pt; |
| 11407 | const zcu = pt.zcu; | 11410 | const zcu = pt.zcu; |
| 11408 | const payload_llvm_ty = try o.lowerType(payload_ty); | 11411 | const payload_llvm_ty = try o.lowerType(pt, payload_ty); |
| 11409 | const abi_size = payload_ty.abiSize(zcu); | 11412 | const abi_size = payload_ty.abiSize(zcu); |
| 11410 | | 11413 | |
| 11411 | // llvm bug workarounds: | 11414 | // llvm bug workarounds: |
| ... | @@ -11450,8 +11453,8 @@ pub const FuncGen = struct { | ... | @@ -11450,8 +11453,8 @@ pub const FuncGen = struct { |
| 11450 | access_kind: Builder.MemoryAccessKind, | 11453 | access_kind: Builder.MemoryAccessKind, |
| 11451 | ) !Builder.Value { | 11454 | ) !Builder.Value { |
| 11452 | const o = fg.ng.object; | 11455 | const o = fg.ng.object; |
| 11453 | const pt = o.pt; | 11456 | const pt = fg.ng.pt; |
| 11454 | const pointee_llvm_ty = try o.lowerType(pointee_type); | 11457 | const pointee_llvm_ty = try o.lowerType(pt, pointee_type); |
| 11455 | const result_align = InternPool.Alignment.fromLlvm(ptr_alignment) | 11458 | const result_align = InternPool.Alignment.fromLlvm(ptr_alignment) |
| 11456 | .max(pointee_type.abiAlignment(pt.zcu)).toLlvm(); | 11459 | .max(pointee_type.abiAlignment(pt.zcu)).toLlvm(); |
| 11457 | const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align); | 11460 | const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align); |
| ... | @@ -11461,7 +11464,7 @@ pub const FuncGen = struct { | ... | @@ -11461,7 +11464,7 @@ pub const FuncGen = struct { |
| 11461 | result_align, | 11464 | result_align, |
| 11462 | ptr, | 11465 | ptr, |
| 11463 | ptr_alignment, | 11466 | ptr_alignment, |
| 11464 | try o.builder.intValue(try o.lowerType(Type.usize), size_bytes), | 11467 | try o.builder.intValue(try o.lowerType(pt, Type.usize), size_bytes), |
| 11465 | access_kind, | 11468 | access_kind, |
| 11466 | fg.disable_intrinsics, | 11469 | fg.disable_intrinsics, |
| 11467 | ); | 11470 | ); |
| ... | @@ -11473,7 +11476,7 @@ pub const FuncGen = struct { | ... | @@ -11473,7 +11476,7 @@ pub const FuncGen = struct { |
| 11473 | /// For isByRef=false types, it creates a load instruction and returns it. | 11476 | /// 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 { | 11477 | fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value { |
| 11475 | const o = self.ng.object; | 11478 | const o = self.ng.object; |
| 11476 | const pt = o.pt; | 11479 | const pt = self.ng.pt; |
| 11477 | const zcu = pt.zcu; | 11480 | const zcu = pt.zcu; |
| 11478 | const info = ptr_ty.ptrInfo(zcu); | 11481 | const info = ptr_ty.ptrInfo(zcu); |
| 11479 | const elem_ty = Type.fromInterned(info.child); | 11482 | const elem_ty = Type.fromInterned(info.child); |
| ... | @@ -11490,7 +11493,7 @@ pub const FuncGen = struct { | ... | @@ -11490,7 +11493,7 @@ pub const FuncGen = struct { |
| 11490 | assert(info.flags.vector_index != .runtime); | 11493 | assert(info.flags.vector_index != .runtime); |
| 11491 | if (info.flags.vector_index != .none) { | 11494 | if (info.flags.vector_index != .none) { |
| 11492 | const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index); | 11495 | const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index); |
| 11493 | const vec_elem_ty = try o.lowerType(elem_ty); | 11496 | const vec_elem_ty = try o.lowerType(pt, elem_ty); |
| 11494 | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); | 11497 | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); |
| 11495 | | 11498 | |
| 11496 | const loaded_vector = try self.wip.load(access_kind, vec_ty, ptr, ptr_alignment, ""); | 11499 | const loaded_vector = try self.wip.load(access_kind, vec_ty, ptr, ptr_alignment, ""); |
| ... | @@ -11511,7 +11514,7 @@ pub const FuncGen = struct { | ... | @@ -11511,7 +11514,7 @@ pub const FuncGen = struct { |
| 11511 | const elem_bits = ptr_ty.childType(zcu).bitSize(zcu); | 11514 | 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); | 11515 | 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, ""); | 11516 | const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, ""); |
| 11514 | const elem_llvm_ty = try o.lowerType(elem_ty); | 11517 | const elem_llvm_ty = try o.lowerType(pt, elem_ty); |
| 11515 | | 11518 | |
| 11516 | if (isByRef(elem_ty, zcu)) { | 11519 | if (isByRef(elem_ty, zcu)) { |
| 11517 | const result_align = elem_ty.abiAlignment(zcu).toLlvm(); | 11520 | const result_align = elem_ty.abiAlignment(zcu).toLlvm(); |
| ... | @@ -11546,7 +11549,7 @@ pub const FuncGen = struct { | ... | @@ -11546,7 +11549,7 @@ pub const FuncGen = struct { |
| 11546 | ordering: Builder.AtomicOrdering, | 11549 | ordering: Builder.AtomicOrdering, |
| 11547 | ) !void { | 11550 | ) !void { |
| 11548 | const o = self.ng.object; | 11551 | const o = self.ng.object; |
| 11549 | const pt = o.pt; | 11552 | const pt = self.ng.pt; |
| 11550 | const zcu = pt.zcu; | 11553 | const zcu = pt.zcu; |
| 11551 | const info = ptr_ty.ptrInfo(zcu); | 11554 | const info = ptr_ty.ptrInfo(zcu); |
| 11552 | const elem_ty = Type.fromInterned(info.child); | 11555 | const elem_ty = Type.fromInterned(info.child); |
| ... | @@ -11560,7 +11563,7 @@ pub const FuncGen = struct { | ... | @@ -11560,7 +11563,7 @@ pub const FuncGen = struct { |
| 11560 | assert(info.flags.vector_index != .runtime); | 11563 | assert(info.flags.vector_index != .runtime); |
| 11561 | if (info.flags.vector_index != .none) { | 11564 | if (info.flags.vector_index != .none) { |
| 11562 | const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index); | 11565 | const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index); |
| 11563 | const vec_elem_ty = try o.lowerType(elem_ty); | 11566 | const vec_elem_ty = try o.lowerType(pt, elem_ty); |
| 11564 | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); | 11567 | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); |
| 11565 | | 11568 | |
| 11566 | const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, ""); | 11569 | const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, ""); |
| ... | @@ -11629,7 +11632,7 @@ pub const FuncGen = struct { | ... | @@ -11629,7 +11632,7 @@ pub const FuncGen = struct { |
| 11629 | ptr_alignment, | 11632 | ptr_alignment, |
| 11630 | elem, | 11633 | elem, |
| 11631 | elem_ty.abiAlignment(zcu).toLlvm(), | 11634 | elem_ty.abiAlignment(zcu).toLlvm(), |
| 11632 | try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(zcu)), | 11635 | try o.builder.intValue(try o.lowerType(pt, Type.usize), elem_ty.abiSize(zcu)), |
| 11633 | access_kind, | 11636 | access_kind, |
| 11634 | self.disable_intrinsics, | 11637 | self.disable_intrinsics, |
| 11635 | ); | 11638 | ); |
| ... | @@ -11638,7 +11641,8 @@ pub const FuncGen = struct { | ... | @@ -11638,7 +11641,8 @@ pub const FuncGen = struct { |
| 11638 | fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void { | 11641 | fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void { |
| 11639 | const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545; | 11642 | const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545; |
| 11640 | const o = fg.ng.object; | 11643 | const o = fg.ng.object; |
| 11641 | const usize_ty = try o.lowerType(Type.usize); | 11644 | const pt = fg.ng.pt; |
| | 11645 | const usize_ty = try o.lowerType(pt, Type.usize); |
| 11642 | const zero = try o.builder.intValue(usize_ty, 0); | 11646 | const zero = try o.builder.intValue(usize_ty, 0); |
| 11643 | const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED); | 11647 | 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, ""); | 11648 | const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, ""); |
| ... | @@ -11656,12 +11660,12 @@ pub const FuncGen = struct { | ... | @@ -11656,12 +11660,12 @@ pub const FuncGen = struct { |
| 11656 | a5: Builder.Value, | 11660 | a5: Builder.Value, |
| 11657 | ) Allocator.Error!Builder.Value { | 11661 | ) Allocator.Error!Builder.Value { |
| 11658 | const o = fg.ng.object; | 11662 | const o = fg.ng.object; |
| 11659 | const pt = o.pt; | 11663 | const pt = fg.ng.pt; |
| 11660 | const zcu = pt.zcu; | 11664 | const zcu = pt.zcu; |
| 11661 | const target = zcu.getTarget(); | 11665 | const target = zcu.getTarget(); |
| 11662 | if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value; | 11666 | if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value; |
| 11663 | | 11667 | |
| 11664 | const llvm_usize = try o.lowerType(Type.usize); | 11668 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 11665 | const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm(); | 11669 | const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm(); |
| 11666 | | 11670 | |
| 11667 | const array_llvm_ty = try o.builder.arrayType(6, llvm_usize); | 11671 | const array_llvm_ty = try o.builder.arrayType(6, llvm_usize); |
| ... | @@ -11787,14 +11791,12 @@ pub const FuncGen = struct { | ... | @@ -11787,14 +11791,12 @@ pub const FuncGen = struct { |
| 11787 | } | 11791 | } |
| 11788 | | 11792 | |
| 11789 | fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type { | 11793 | fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type { |
| 11790 | const o = fg.ng.object; | 11794 | const zcu = fg.ng.pt.zcu; |
| 11791 | const zcu = o.pt.zcu; | | |
| 11792 | return fg.air.typeOf(inst, &zcu.intern_pool); | 11795 | return fg.air.typeOf(inst, &zcu.intern_pool); |
| 11793 | } | 11796 | } |
| 11794 | | 11797 | |
| 11795 | fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type { | 11798 | fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type { |
| 11796 | const o = fg.ng.object; | 11799 | const zcu = fg.ng.pt.zcu; |
| 11797 | const zcu = o.pt.zcu; | | |
| 11798 | return fg.air.typeOfIndex(inst, &zcu.intern_pool); | 11800 | return fg.air.typeOfIndex(inst, &zcu.intern_pool); |
| 11799 | } | 11801 | } |
| 11800 | }; | 11802 | }; |
| ... | @@ -12152,40 +12154,39 @@ fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: *const std.Target) bool { | ... | @@ -12152,40 +12154,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 lowered | 12154 | /// 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 then | 12155 | /// completely differently in the function prototype to honor the C ABI, and then |
| 12154 | /// be effectively bitcasted to the actual return type. | 12156 | /// be effectively bitcasted to the actual return type. |
| 12155 | fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { | 12157 | fn 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; | 12158 | const zcu = pt.zcu; |
| 12158 | const return_type = Type.fromInterned(fn_info.return_type); | 12159 | const return_type = Type.fromInterned(fn_info.return_type); |
| 12159 | if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) { | 12160 | if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 12160 | // If the return type is an error set or an error union, then we make this | 12161 | // 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 function | 12162 | // anyerror return type instead, so that it can be coerced into a function |
| 12162 | // pointer type which has anyerror as the return type. | 12163 | // pointer type which has anyerror as the return type. |
| 12163 | return if (return_type.isError(zcu)) try o.errorIntType() else .void; | 12164 | return if (return_type.isError(zcu)) try o.errorIntType(pt) else .void; |
| 12164 | } | 12165 | } |
| 12165 | const target = zcu.getTarget(); | 12166 | const target = zcu.getTarget(); |
| 12166 | switch (fn_info.cc) { | 12167 | switch (fn_info.cc) { |
| 12167 | .@"inline" => unreachable, | 12168 | .@"inline" => unreachable, |
| 12168 | .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(return_type), | 12169 | .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(pt, return_type), |
| 12169 | | 12170 | |
| 12170 | .x86_64_sysv => return lowerSystemVFnRetTy(o, fn_info), | 12171 | .x86_64_sysv => return lowerSystemVFnRetTy(o, pt, fn_info), |
| 12171 | .x86_64_win => return lowerWin64FnRetTy(o, fn_info), | 12172 | .x86_64_win => return lowerWin64FnRetTy(o, pt, fn_info), |
| 12172 | .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(return_type) else .void, | 12173 | .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), | 12174 | .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)) { | 12175 | .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win => switch (aarch64_c_abi.classifyType(return_type, zcu)) { |
| 12175 | .memory => return .void, | 12176 | .memory => return .void, |
| 12176 | .float_array => return o.lowerType(return_type), | 12177 | .float_array => return o.lowerType(pt, return_type), |
| 12177 | .byval => return o.lowerType(return_type), | 12178 | .byval => return o.lowerType(pt, return_type), |
| 12178 | .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))), | 12179 | .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))), |
| 12179 | .double_integer => return o.builder.arrayType(2, .i64), | 12180 | .double_integer => return o.builder.arrayType(2, .i64), |
| 12180 | }, | 12181 | }, |
| 12181 | .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) { | 12182 | .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) { |
| 12182 | .memory, .i64_array => return .void, | 12183 | .memory, .i64_array => return .void, |
| 12183 | .i32_array => |len| return if (len == 1) .i32 else .void, | 12184 | .i32_array => |len| return if (len == 1) .i32 else .void, |
| 12184 | .byval => return o.lowerType(return_type), | 12185 | .byval => return o.lowerType(pt, return_type), |
| 12185 | }, | 12186 | }, |
| 12186 | .mips_o32 => switch (mips_c_abi.classifyType(return_type, zcu, .ret)) { | 12187 | .mips_o32 => switch (mips_c_abi.classifyType(return_type, zcu, .ret)) { |
| 12187 | .memory, .i32_array => return .void, | 12188 | .memory, .i32_array => return .void, |
| 12188 | .byval => return o.lowerType(return_type), | 12189 | .byval => return o.lowerType(pt, return_type), |
| 12189 | }, | 12190 | }, |
| 12190 | .riscv64_lp64, .riscv32_ilp32 => switch (riscv_c_abi.classifyType(return_type, zcu)) { | 12191 | .riscv64_lp64, .riscv32_ilp32 => switch (riscv_c_abi.classifyType(return_type, zcu)) { |
| 12191 | .memory => return .void, | 12192 | .memory => return .void, |
| ... | @@ -12195,53 +12196,52 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu | ... | @@ -12195,53 +12196,52 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu |
| 12195 | .double_integer => { | 12196 | .double_integer => { |
| 12196 | return o.builder.structType(.normal, &.{ .i64, .i64 }); | 12197 | return o.builder.structType(.normal, &.{ .i64, .i64 }); |
| 12197 | }, | 12198 | }, |
| 12198 | .byval => return o.lowerType(return_type), | 12199 | .byval => return o.lowerType(pt, return_type), |
| 12199 | .fields => { | 12200 | .fields => { |
| 12200 | var types_len: usize = 0; | 12201 | var types_len: usize = 0; |
| 12201 | var types: [8]Builder.Type = undefined; | 12202 | var types: [8]Builder.Type = undefined; |
| 12202 | for (0..return_type.structFieldCount(zcu)) |field_index| { | 12203 | for (0..return_type.structFieldCount(zcu)) |field_index| { |
| 12203 | const field_ty = return_type.fieldType(field_index, zcu); | 12204 | const field_ty = return_type.fieldType(field_index, zcu); |
| 12204 | if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue; | 12205 | if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue; |
| 12205 | types[types_len] = try o.lowerType(field_ty); | 12206 | types[types_len] = try o.lowerType(pt, field_ty); |
| 12206 | types_len += 1; | 12207 | types_len += 1; |
| 12207 | } | 12208 | } |
| 12208 | return o.builder.structType(.normal, types[0..types_len]); | 12209 | return o.builder.structType(.normal, types[0..types_len]); |
| 12209 | }, | 12210 | }, |
| 12210 | }, | 12211 | }, |
| 12211 | .wasm_mvp => switch (wasm_c_abi.classifyType(return_type, zcu)) { | 12212 | .wasm_mvp => switch (wasm_c_abi.classifyType(return_type, zcu)) { |
| 12212 | .direct => |scalar_ty| return o.lowerType(scalar_ty), | 12213 | .direct => |scalar_ty| return o.lowerType(pt, scalar_ty), |
| 12213 | .indirect => return .void, | 12214 | .indirect => return .void, |
| 12214 | }, | 12215 | }, |
| 12215 | // TODO investigate other callconvs | 12216 | // TODO investigate other callconvs |
| 12216 | else => return o.lowerType(return_type), | 12217 | else => return o.lowerType(pt, return_type), |
| 12217 | } | 12218 | } |
| 12218 | } | 12219 | } |
| 12219 | | 12220 | |
| 12220 | fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { | 12221 | fn lowerWin64FnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12221 | const zcu = o.pt.zcu; | 12222 | const zcu = pt.zcu; |
| 12222 | const return_type = Type.fromInterned(fn_info.return_type); | 12223 | const return_type = Type.fromInterned(fn_info.return_type); |
| 12223 | switch (x86_64_abi.classifyWindows(return_type, zcu, zcu.getTarget())) { | 12224 | switch (x86_64_abi.classifyWindows(return_type, zcu, zcu.getTarget())) { |
| 12224 | .integer => { | 12225 | .integer => { |
| 12225 | if (isScalar(zcu, return_type)) { | 12226 | if (isScalar(zcu, return_type)) { |
| 12226 | return o.lowerType(return_type); | 12227 | return o.lowerType(pt, return_type); |
| 12227 | } else { | 12228 | } else { |
| 12228 | return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8)); | 12229 | return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8)); |
| 12229 | } | 12230 | } |
| 12230 | }, | 12231 | }, |
| 12231 | .win_i128 => return o.builder.vectorType(.normal, 2, .i64), | 12232 | .win_i128 => return o.builder.vectorType(.normal, 2, .i64), |
| 12232 | .memory => return .void, | 12233 | .memory => return .void, |
| 12233 | .sse => return o.lowerType(return_type), | 12234 | .sse => return o.lowerType(pt, return_type), |
| 12234 | else => unreachable, | 12235 | else => unreachable, |
| 12235 | } | 12236 | } |
| 12236 | } | 12237 | } |
| 12237 | | 12238 | |
| 12238 | fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { | 12239 | fn 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; | 12240 | const zcu = pt.zcu; |
| 12241 | const ip = &zcu.intern_pool; | 12241 | const ip = &zcu.intern_pool; |
| 12242 | const return_type = Type.fromInterned(fn_info.return_type); | 12242 | const return_type = Type.fromInterned(fn_info.return_type); |
| 12243 | if (isScalar(zcu, return_type)) { | 12243 | if (isScalar(zcu, return_type)) { |
| 12244 | return o.lowerType(return_type); | 12244 | return o.lowerType(pt, return_type); |
| 12245 | } | 12245 | } |
| 12246 | const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret); | 12246 | const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret); |
| 12247 | var types_index: u32 = 0; | 12247 | var types_index: u32 = 0; |
| ... | @@ -12305,6 +12305,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E | ... | @@ -12305,6 +12305,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E |
| 12305 | | 12305 | |
| 12306 | const ParamTypeIterator = struct { | 12306 | const ParamTypeIterator = struct { |
| 12307 | object: *Object, | 12307 | object: *Object, |
| | 12308 | pt: Zcu.PerThread, |
| 12308 | fn_info: InternPool.Key.FuncType, | 12309 | fn_info: InternPool.Key.FuncType, |
| 12309 | zig_index: u32, | 12310 | zig_index: u32, |
| 12310 | llvm_index: u32, | 12311 | llvm_index: u32, |
| ... | @@ -12327,7 +12328,7 @@ const ParamTypeIterator = struct { | ... | @@ -12327,7 +12328,7 @@ const ParamTypeIterator = struct { |
| 12327 | | 12328 | |
| 12328 | pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering { | 12329 | pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering { |
| 12329 | if (it.zig_index >= it.fn_info.param_types.len) return null; | 12330 | if (it.zig_index >= it.fn_info.param_types.len) return null; |
| 12330 | const ip = &it.object.pt.zcu.intern_pool; | 12331 | const ip = &it.pt.zcu.intern_pool; |
| 12331 | const ty = it.fn_info.param_types.get(ip)[it.zig_index]; | 12332 | const ty = it.fn_info.param_types.get(ip)[it.zig_index]; |
| 12332 | it.byval_attr = false; | 12333 | it.byval_attr = false; |
| 12333 | return nextInner(it, Type.fromInterned(ty)); | 12334 | return nextInner(it, Type.fromInterned(ty)); |
| ... | @@ -12335,7 +12336,8 @@ const ParamTypeIterator = struct { | ... | @@ -12335,7 +12336,8 @@ const ParamTypeIterator = struct { |
| 12335 | | 12336 | |
| 12336 | /// `airCall` uses this instead of `next` so that it can take into account variadic functions. | 12337 | /// `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 { | 12338 | pub fn nextCall(it: *ParamTypeIterator, fg: *FuncGen, args: []const Air.Inst.Ref) Allocator.Error!?Lowering { |
| 12338 | const ip = &it.object.pt.zcu.intern_pool; | 12339 | assert(std.meta.eql(it.pt, fg.ng.pt)); |
| | 12340 | const ip = &it.pt.zcu.intern_pool; |
| 12339 | if (it.zig_index >= it.fn_info.param_types.len) { | 12341 | if (it.zig_index >= it.fn_info.param_types.len) { |
| 12340 | if (it.zig_index >= args.len) { | 12342 | if (it.zig_index >= args.len) { |
| 12341 | return null; | 12343 | return null; |
| ... | @@ -12348,7 +12350,7 @@ const ParamTypeIterator = struct { | ... | @@ -12348,7 +12350,7 @@ const ParamTypeIterator = struct { |
| 12348 | } | 12350 | } |
| 12349 | | 12351 | |
| 12350 | fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { | 12352 | fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { |
| 12351 | const pt = it.object.pt; | 12353 | const pt = it.pt; |
| 12352 | const zcu = pt.zcu; | 12354 | const zcu = pt.zcu; |
| 12353 | const target = zcu.getTarget(); | 12355 | const target = zcu.getTarget(); |
| 12354 | | 12356 | |
| ... | @@ -12448,7 +12450,7 @@ const ParamTypeIterator = struct { | ... | @@ -12448,7 +12450,7 @@ const ParamTypeIterator = struct { |
| 12448 | for (0..ty.structFieldCount(zcu)) |field_index| { | 12450 | for (0..ty.structFieldCount(zcu)) |field_index| { |
| 12449 | const field_ty = ty.fieldType(field_index, zcu); | 12451 | const field_ty = ty.fieldType(field_index, zcu); |
| 12450 | if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue; | 12452 | if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue; |
| 12451 | it.types_buffer[it.types_len] = try it.object.lowerType(field_ty); | 12453 | it.types_buffer[it.types_len] = try it.object.lowerType(pt, field_ty); |
| 12452 | it.types_len += 1; | 12454 | it.types_len += 1; |
| 12453 | } | 12455 | } |
| 12454 | it.llvm_index += it.types_len - 1; | 12456 | it.llvm_index += it.types_len - 1; |
| ... | @@ -12464,7 +12466,7 @@ const ParamTypeIterator = struct { | ... | @@ -12464,7 +12466,7 @@ const ParamTypeIterator = struct { |
| 12464 | return .byval; | 12466 | return .byval; |
| 12465 | } else { | 12467 | } else { |
| 12466 | var types_buffer: [8]Builder.Type = undefined; | 12468 | var types_buffer: [8]Builder.Type = undefined; |
| 12467 | types_buffer[0] = try it.object.lowerType(scalar_ty); | 12469 | types_buffer[0] = try it.object.lowerType(pt, scalar_ty); |
| 12468 | it.types_buffer = types_buffer; | 12470 | it.types_buffer = types_buffer; |
| 12469 | it.types_len = 1; | 12471 | it.types_len = 1; |
| 12470 | it.llvm_index += 1; | 12472 | it.llvm_index += 1; |
| ... | @@ -12489,7 +12491,7 @@ const ParamTypeIterator = struct { | ... | @@ -12489,7 +12491,7 @@ const ParamTypeIterator = struct { |
| 12489 | } | 12491 | } |
| 12490 | | 12492 | |
| 12491 | fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering { | 12493 | fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering { |
| 12492 | const zcu = it.object.pt.zcu; | 12494 | const zcu = it.pt.zcu; |
| 12493 | switch (x86_64_abi.classifyWindows(ty, zcu, zcu.getTarget())) { | 12495 | switch (x86_64_abi.classifyWindows(ty, zcu, zcu.getTarget())) { |
| 12494 | .integer => { | 12496 | .integer => { |
| 12495 | if (isScalar(zcu, ty)) { | 12497 | if (isScalar(zcu, ty)) { |
| ... | @@ -12522,7 +12524,7 @@ const ParamTypeIterator = struct { | ... | @@ -12522,7 +12524,7 @@ const ParamTypeIterator = struct { |
| 12522 | } | 12524 | } |
| 12523 | | 12525 | |
| 12524 | fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { | 12526 | fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { |
| 12525 | const zcu = it.object.pt.zcu; | 12527 | const zcu = it.pt.zcu; |
| 12526 | const ip = &zcu.intern_pool; | 12528 | const ip = &zcu.intern_pool; |
| 12527 | const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg); | 12529 | const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg); |
| 12528 | if (classes[0] == .memory) { | 12530 | if (classes[0] == .memory) { |
| ... | @@ -12615,9 +12617,10 @@ const ParamTypeIterator = struct { | ... | @@ -12615,9 +12617,10 @@ const ParamTypeIterator = struct { |
| 12615 | } | 12617 | } |
| 12616 | }; | 12618 | }; |
| 12617 | | 12619 | |
| 12618 | fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTypeIterator { | 12620 | fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) ParamTypeIterator { |
| 12619 | return .{ | 12621 | return .{ |
| 12620 | .object = object, | 12622 | .object = object, |
| | 12623 | .pt = pt, |
| 12621 | .fn_info = fn_info, | 12624 | .fn_info = fn_info, |
| 12622 | .zig_index = 0, | 12625 | .zig_index = 0, |
| 12623 | .llvm_index = 0, | 12626 | .llvm_index = 0, |
| ... | @@ -12896,6 +12899,26 @@ fn compilerRtIntBits(bits: u16) u16 { | ... | @@ -12896,6 +12899,26 @@ fn compilerRtIntBits(bits: u16) u16 { |
| 12896 | return bits; | 12899 | return bits; |
| 12897 | } | 12900 | } |
| 12898 | | 12901 | |
| | 12902 | fn getStackTraceType(pt: Zcu.PerThread) Allocator.Error!Type { |
| | 12903 | const zcu = pt.zcu; |
| | 12904 | const ip = &zcu.intern_pool; |
| | 12905 | |
| | 12906 | const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?; |
| | 12907 | const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls); |
| | 12908 | const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_index)); |
| | 12909 | const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu)); |
| | 12910 | const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; |
| | 12911 | |
| | 12912 | const stack_trace_str = try ip.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls); |
| | 12913 | // buffer is only used for int_type, `builtin` is a struct. |
| | 12914 | const builtin_ty = zcu.navValue(builtin_nav).toType(); |
| | 12915 | const builtin_namespace = zcu.namespacePtr(builtin_ty.getNamespaceIndex(zcu)); |
| | 12916 | const stack_trace_nav = builtin_namespace.pub_decls.getKeyAdapted(stack_trace_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; |
| | 12917 | |
| | 12918 | // Sema should have ensured that StackTrace was analyzed. |
| | 12919 | return zcu.navValue(stack_trace_nav).toType(); |
| | 12920 | } |
| | 12921 | |
| 12899 | fn buildAllocaInner( | 12922 | fn buildAllocaInner( |
| 12900 | wip: *Builder.WipFunction, | 12923 | wip: *Builder.WipFunction, |
| 12901 | llvm_ty: Builder.Type, | 12924 | llvm_ty: Builder.Type, |