| ... | ... | @@ -494,8 +494,6 @@ pub const Object = struct { |
| 494 | 494 | gpa: Allocator, |
| 495 | 495 | builder: Builder, |
| 496 | 496 | |
| 497 | | pt: Zcu.PerThread, |
| 498 | | |
| 499 | 497 | debug_compile_unit: Builder.Metadata, |
| 500 | 498 | |
| 501 | 499 | debug_enums_fwd_ref: Builder.Metadata, |
| ... | ... | @@ -626,10 +624,6 @@ pub const Object = struct { |
| 626 | 624 | obj.* = .{ |
| 627 | 625 | .gpa = gpa, |
| 628 | 626 | .builder = builder, |
| 629 | | .pt = .{ |
| 630 | | .zcu = comp.zcu.?, |
| 631 | | .tid = .main, |
| 632 | | }, |
| 633 | 627 | .debug_compile_unit = debug_compile_unit, |
| 634 | 628 | .debug_enums_fwd_ref = debug_enums_fwd_ref, |
| 635 | 629 | .debug_globals_fwd_ref = debug_globals_fwd_ref, |
| ... | ... | @@ -669,11 +663,10 @@ pub const Object = struct { |
| 669 | 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 | 667 | // If o.error_name_table is null, then it was not referenced by any instructions. |
| 674 | 668 | if (o.error_name_table == .none) return; |
| 675 | 669 | |
| 676 | | const pt = o.pt; |
| 677 | 670 | const zcu = pt.zcu; |
| 678 | 671 | const ip = &zcu.intern_pool; |
| 679 | 672 | |
| ... | ... | @@ -683,8 +676,8 @@ pub const Object = struct { |
| 683 | 676 | |
| 684 | 677 | // TODO: Address space |
| 685 | 678 | const slice_ty = Type.slice_const_u8_sentinel_0; |
| 686 | | const llvm_usize_ty = try o.lowerType(Type.usize); |
| 687 | | const llvm_slice_ty = try o.lowerType(slice_ty); |
| 679 | const llvm_usize_ty = try o.lowerType(pt, Type.usize); |
| 680 | const llvm_slice_ty = try o.lowerType(pt, slice_ty); |
| 688 | 681 | const llvm_table_ty = try o.builder.arrayType(1 + error_name_list.len, llvm_slice_ty); |
| 689 | 682 | |
| 690 | 683 | llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty); |
| ... | ... | @@ -721,11 +714,11 @@ pub const Object = struct { |
| 721 | 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 | 718 | // If there is no such function in the module, it means the source code does not need it. |
| 726 | 719 | const name = o.builder.strtabStringIfExists(lt_errors_fn_name) orelse return; |
| 727 | 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 | 723 | var wip = try Builder.WipFunction.init(&o.builder, .{ |
| 731 | 724 | .function = llvm_fn.ptrConst(&o.builder).kind.function, |
| ... | ... | @@ -740,17 +733,17 @@ pub const Object = struct { |
| 740 | 733 | // } |
| 741 | 734 | |
| 742 | 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 | 737 | const is_lt = try wip.icmp(.ule, lhs, rhs, ""); |
| 745 | 738 | _ = try wip.ret(is_lt); |
| 746 | 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 | 743 | const b = &object.builder; |
| 751 | 744 | const gpa = b.gpa; |
| 752 | 745 | b.module_asm.clearRetainingCapacity(); |
| 753 | | for (object.pt.zcu.global_assembly.values()) |assembly| { |
| 746 | for (pt.zcu.global_assembly.values()) |assembly| { |
| 754 | 747 | try b.module_asm.ensureUnusedCapacity(gpa, assembly.len + 1); |
| 755 | 748 | b.module_asm.appendSliceAssumeCapacity(assembly); |
| 756 | 749 | b.module_asm.appendAssumeCapacity('\n'); |
| ... | ... | @@ -776,15 +769,15 @@ pub const Object = struct { |
| 776 | 769 | lto: std.zig.LtoMode, |
| 777 | 770 | }; |
| 778 | 771 | |
| 779 | | pub fn emit(o: *Object, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void { |
| 780 | | const zcu = o.pt.zcu; |
| 772 | pub fn emit(o: *Object, pt: Zcu.PerThread, options: EmitOptions) error{ LinkFailure, OutOfMemory }!void { |
| 773 | const zcu = pt.zcu; |
| 781 | 774 | const comp = zcu.comp; |
| 782 | 775 | const diags = &comp.link_diags; |
| 783 | 776 | |
| 784 | 777 | { |
| 785 | | try o.genErrorNameTable(); |
| 786 | | try o.genCmpLtErrorsLenFunction(); |
| 787 | | try o.genModuleLevelAssembly(); |
| 778 | try o.genErrorNameTable(pt); |
| 779 | try o.genCmpLtErrorsLenFunction(pt); |
| 780 | try o.genModuleLevelAssembly(pt); |
| 788 | 781 | |
| 789 | 782 | if (o.used.items.len > 0) { |
| 790 | 783 | const array_llvm_ty = try o.builder.arrayType(o.used.items.len, .ptr); |
| ... | ... | @@ -807,7 +800,7 @@ pub const Object = struct { |
| 807 | 800 | const fwd_ref = o.debug_unresolved_namespace_scopes.values()[i]; |
| 808 | 801 | |
| 809 | 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 | 805 | o.builder.debugForwardReferenceSetType(fwd_ref, debug_type); |
| 813 | 806 | } |
| ... | ... | @@ -1140,7 +1133,6 @@ pub const Object = struct { |
| 1140 | 1133 | air: *const Air, |
| 1141 | 1134 | liveness: *const Air.Liveness, |
| 1142 | 1135 | ) !void { |
| 1143 | | assert(std.meta.eql(pt, o.pt)); |
| 1144 | 1136 | const zcu = pt.zcu; |
| 1145 | 1137 | const comp = zcu.comp; |
| 1146 | 1138 | const ip = &zcu.intern_pool; |
| ... | ... | @@ -1155,10 +1147,11 @@ pub const Object = struct { |
| 1155 | 1147 | var ng: NavGen = .{ |
| 1156 | 1148 | .object = o, |
| 1157 | 1149 | .nav_index = func.owner_nav, |
| 1150 | .pt = pt, |
| 1158 | 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 | 1156 | var attributes = try function_index.ptrConst(&o.builder).attributes.toWip(&o.builder); |
| 1164 | 1157 | defer attributes.deinit(&o.builder); |
| ... | ... | @@ -1272,7 +1265,7 @@ pub const Object = struct { |
| 1272 | 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 | 1269 | while (try it.next()) |lowering| { |
| 1277 | 1270 | try args.ensureUnusedCapacity(gpa, 1); |
| 1278 | 1271 | |
| ... | ... | @@ -1293,13 +1286,13 @@ pub const Object = struct { |
| 1293 | 1286 | } else { |
| 1294 | 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 | 1291 | llvm_arg_i += 1; |
| 1299 | 1292 | }, |
| 1300 | 1293 | .byref => { |
| 1301 | 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 | 1296 | const param = wip.arg(llvm_arg_i); |
| 1304 | 1297 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 1305 | 1298 | |
| ... | ... | @@ -1314,7 +1307,7 @@ pub const Object = struct { |
| 1314 | 1307 | }, |
| 1315 | 1308 | .byref_mut => { |
| 1316 | 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 | 1311 | const param = wip.arg(llvm_arg_i); |
| 1319 | 1312 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 1320 | 1313 | |
| ... | ... | @@ -1333,7 +1326,7 @@ pub const Object = struct { |
| 1333 | 1326 | const param = wip.arg(llvm_arg_i); |
| 1334 | 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 | 1330 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 1338 | 1331 | const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target); |
| 1339 | 1332 | _ = try wip.store(.normal, param, arg_ptr, alignment); |
| ... | ... | @@ -1372,7 +1365,7 @@ pub const Object = struct { |
| 1372 | 1365 | const len_param = wip.arg(llvm_arg_i); |
| 1373 | 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 | 1369 | args.appendAssumeCapacity( |
| 1377 | 1370 | try wip.buildAggregate(slice_llvm_ty, &.{ ptr_param, len_param }, ""), |
| 1378 | 1371 | ); |
| ... | ... | @@ -1381,7 +1374,7 @@ pub const Object = struct { |
| 1381 | 1374 | assert(!it.byval_attr); |
| 1382 | 1375 | const field_types = it.types_buffer[0..it.types_len]; |
| 1383 | 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 | 1378 | const param_alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 1386 | 1379 | const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, param_alignment, target); |
| 1387 | 1380 | const llvm_ty = try o.builder.structType(.normal, field_types); |
| ... | ... | @@ -1402,7 +1395,7 @@ pub const Object = struct { |
| 1402 | 1395 | }, |
| 1403 | 1396 | .float_array => { |
| 1404 | 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 | 1399 | const param = wip.arg(llvm_arg_i); |
| 1407 | 1400 | llvm_arg_i += 1; |
| 1408 | 1401 | |
| ... | ... | @@ -1417,7 +1410,7 @@ pub const Object = struct { |
| 1417 | 1410 | }, |
| 1418 | 1411 | .i32_array, .i64_array => { |
| 1419 | 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 | 1414 | const param = wip.arg(llvm_arg_i); |
| 1422 | 1415 | llvm_arg_i += 1; |
| 1423 | 1416 | |
| ... | ... | @@ -1435,11 +1428,11 @@ pub const Object = struct { |
| 1435 | 1428 | } |
| 1436 | 1429 | |
| 1437 | 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 | 1433 | const line_number = zcu.navSrcLine(func.owner_nav) + 1; |
| 1441 | 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 | 1437 | const subprogram = try o.builder.debugSubprogram( |
| 1445 | 1438 | file, |
| ... | ... | @@ -1569,10 +1562,10 @@ pub const Object = struct { |
| 1569 | 1562 | } |
| 1570 | 1563 | |
| 1571 | 1564 | pub fn updateNav(self: *Object, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !void { |
| 1572 | | assert(std.meta.eql(pt, self.pt)); |
| 1573 | 1565 | var ng: NavGen = .{ |
| 1574 | 1566 | .object = self, |
| 1575 | 1567 | .nav_index = nav_index, |
| 1568 | .pt = pt, |
| 1576 | 1569 | .err_msg = null, |
| 1577 | 1570 | }; |
| 1578 | 1571 | ng.genDecl() catch |err| switch (err) { |
| ... | ... | @@ -1590,11 +1583,10 @@ pub const Object = struct { |
| 1590 | 1583 | exported: Zcu.Exported, |
| 1591 | 1584 | export_indices: []const Zcu.Export.Index, |
| 1592 | 1585 | ) link.File.UpdateExportsError!void { |
| 1593 | | assert(std.meta.eql(pt, self.pt)); |
| 1594 | 1586 | const zcu = pt.zcu; |
| 1595 | 1587 | const nav_index = switch (exported) { |
| 1596 | 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 | 1591 | const ip = &zcu.intern_pool; |
| 1600 | 1592 | const global_index = self.nav_map.get(nav_index).?; |
| ... | ... | @@ -1635,10 +1627,11 @@ pub const Object = struct { |
| 1635 | 1627 | |
| 1636 | 1628 | fn updateExportedValue( |
| 1637 | 1629 | o: *Object, |
| 1638 | | zcu: *Zcu, |
| 1630 | pt: Zcu.PerThread, |
| 1639 | 1631 | exported_value: InternPool.Index, |
| 1640 | 1632 | export_indices: []const Zcu.Export.Index, |
| 1641 | 1633 | ) link.File.UpdateExportsError!void { |
| 1634 | const zcu = pt.zcu; |
| 1642 | 1635 | const gpa = zcu.gpa; |
| 1643 | 1636 | const ip = &zcu.intern_pool; |
| 1644 | 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 | 1645 | const llvm_addr_space = toLlvmAddressSpace(.generic, o.target); |
| 1653 | 1646 | const variable_index = try o.builder.addVariable( |
| 1654 | 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 | 1649 | llvm_addr_space, |
| 1657 | 1650 | ); |
| 1658 | 1651 | const global_index = variable_index.ptrConst(&o.builder).global; |
| 1659 | 1652 | gop.value_ptr.* = global_index; |
| 1660 | 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 | 1655 | error.OutOfMemory => return error.OutOfMemory, |
| 1663 | 1656 | error.CodegenFail => return error.AnalysisFail, |
| 1664 | 1657 | }; |
| ... | ... | @@ -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 | 1763 | const gpa = o.gpa; |
| 1766 | 1764 | const gop = try o.debug_file_map.getOrPut(gpa, file_index); |
| 1767 | 1765 | errdefer assert(o.debug_file_map.remove(file_index)); |
| 1768 | 1766 | if (gop.found_existing) return gop.value_ptr.*; |
| 1769 | | const zcu = o.pt.zcu; |
| 1770 | | const path = zcu.fileByIndex(file_index).path; |
| 1771 | | const abs_path = try path.toAbsolute(zcu.comp.dirs, gpa); |
| 1767 | const path = pt.zcu.fileByIndex(file_index).path; |
| 1768 | const abs_path = try path.toAbsolute(pt.zcu.comp.dirs, gpa); |
| 1772 | 1769 | defer gpa.free(abs_path); |
| 1773 | 1770 | |
| 1774 | 1771 | gop.value_ptr.* = try o.builder.debugFile( |
| ... | ... | @@ -1780,13 +1777,13 @@ pub const Object = struct { |
| 1780 | 1777 | |
| 1781 | 1778 | pub fn lowerDebugType( |
| 1782 | 1779 | o: *Object, |
| 1780 | pt: Zcu.PerThread, |
| 1783 | 1781 | ty: Type, |
| 1784 | 1782 | ) Allocator.Error!Builder.Metadata { |
| 1785 | 1783 | assert(!o.builder.strip); |
| 1786 | 1784 | |
| 1787 | 1785 | const gpa = o.gpa; |
| 1788 | 1786 | const target = o.target; |
| 1789 | | const pt = o.pt; |
| 1790 | 1787 | const zcu = pt.zcu; |
| 1791 | 1788 | const ip = &zcu.intern_pool; |
| 1792 | 1789 | |
| ... | ... | @@ -1806,7 +1803,7 @@ pub const Object = struct { |
| 1806 | 1803 | .int => { |
| 1807 | 1804 | const info = ty.intInfo(zcu); |
| 1808 | 1805 | assert(info.bits != 0); |
| 1809 | | const name = try o.allocTypeName(ty); |
| 1806 | const name = try o.allocTypeName(pt, ty); |
| 1810 | 1807 | defer gpa.free(name); |
| 1811 | 1808 | const builder_name = try o.builder.metadataString(name); |
| 1812 | 1809 | const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types |
| ... | ... | @@ -1819,7 +1816,7 @@ pub const Object = struct { |
| 1819 | 1816 | }, |
| 1820 | 1817 | .@"enum" => { |
| 1821 | 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 | 1820 | try o.debug_type_map.put(gpa, ty, debug_enum_type); |
| 1824 | 1821 | return debug_enum_type; |
| 1825 | 1822 | } |
| ... | ... | @@ -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 | 1848 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 1852 | | try o.namespaceToDebugScope(parent_namespace) |
| 1849 | try o.namespaceToDebugScope(pt, parent_namespace) |
| 1853 | 1850 | else |
| 1854 | 1851 | file; |
| 1855 | 1852 | |
| 1856 | | const name = try o.allocTypeName(ty); |
| 1853 | const name = try o.allocTypeName(pt, ty); |
| 1857 | 1854 | defer gpa.free(name); |
| 1858 | 1855 | |
| 1859 | 1856 | const debug_enum_type = try o.builder.debugEnumerationType( |
| ... | ... | @@ -1861,7 +1858,7 @@ pub const Object = struct { |
| 1861 | 1858 | file, |
| 1862 | 1859 | scope, |
| 1863 | 1860 | ty.typeDeclSrcLine(zcu).? + 1, // Line |
| 1864 | | try o.lowerDebugType(int_ty), |
| 1861 | try o.lowerDebugType(pt, int_ty), |
| 1865 | 1862 | ty.abiSize(zcu) * 8, |
| 1866 | 1863 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 1867 | 1864 | try o.builder.metadataTuple(enumerators), |
| ... | ... | @@ -1873,7 +1870,7 @@ pub const Object = struct { |
| 1873 | 1870 | }, |
| 1874 | 1871 | .float => { |
| 1875 | 1872 | const bits = ty.floatBits(target); |
| 1876 | | const name = try o.allocTypeName(ty); |
| 1873 | const name = try o.allocTypeName(pt, ty); |
| 1877 | 1874 | defer gpa.free(name); |
| 1878 | 1875 | const debug_float_type = try o.builder.debugFloatType( |
| 1879 | 1876 | try o.builder.metadataString(name), |
| ... | ... | @@ -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 | 1919 | try o.debug_type_map.put(gpa, ty, debug_ptr_type); |
| 1923 | 1920 | return debug_ptr_type; |
| 1924 | 1921 | } |
| ... | ... | @@ -1932,7 +1929,7 @@ pub const Object = struct { |
| 1932 | 1929 | const ptr_ty = ty.slicePtrFieldType(zcu); |
| 1933 | 1930 | const len_ty = Type.usize; |
| 1934 | 1931 | |
| 1935 | | const name = try o.allocTypeName(ty); |
| 1932 | const name = try o.allocTypeName(pt, ty); |
| 1936 | 1933 | defer gpa.free(name); |
| 1937 | 1934 | const line = 0; |
| 1938 | 1935 | |
| ... | ... | @@ -1948,7 +1945,7 @@ pub const Object = struct { |
| 1948 | 1945 | .none, // File |
| 1949 | 1946 | debug_fwd_ref, |
| 1950 | 1947 | 0, // Line |
| 1951 | | try o.lowerDebugType(ptr_ty), |
| 1948 | try o.lowerDebugType(pt, ptr_ty), |
| 1952 | 1949 | ptr_size * 8, |
| 1953 | 1950 | (ptr_align.toByteUnits() orelse 0) * 8, |
| 1954 | 1951 | 0, // Offset |
| ... | ... | @@ -1959,7 +1956,7 @@ pub const Object = struct { |
| 1959 | 1956 | .none, // File |
| 1960 | 1957 | debug_fwd_ref, |
| 1961 | 1958 | 0, // Line |
| 1962 | | try o.lowerDebugType(len_ty), |
| 1959 | try o.lowerDebugType(pt, len_ty), |
| 1963 | 1960 | len_size * 8, |
| 1964 | 1961 | (len_align.toByteUnits() orelse 0) * 8, |
| 1965 | 1962 | len_offset * 8, |
| ... | ... | @@ -1988,9 +1985,9 @@ pub const Object = struct { |
| 1988 | 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 | 1991 | defer gpa.free(name); |
| 1995 | 1992 | |
| 1996 | 1993 | const debug_ptr_type = try o.builder.debugPointerType( |
| ... | ... | @@ -2022,12 +2019,12 @@ pub const Object = struct { |
| 2022 | 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 | 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 | 2026 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 2030 | | try o.namespaceToDebugScope(parent_namespace) |
| 2027 | try o.namespaceToDebugScope(pt, parent_namespace) |
| 2031 | 2028 | else |
| 2032 | 2029 | file; |
| 2033 | 2030 | |
| ... | ... | @@ -2050,7 +2047,7 @@ pub const Object = struct { |
| 2050 | 2047 | .none, // File |
| 2051 | 2048 | .none, // Scope |
| 2052 | 2049 | 0, // Line |
| 2053 | | try o.lowerDebugType(ty.childType(zcu)), |
| 2050 | try o.lowerDebugType(pt, ty.childType(zcu)), |
| 2054 | 2051 | ty.abiSize(zcu) * 8, |
| 2055 | 2052 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2056 | 2053 | try o.builder.metadataTuple(&.{ |
| ... | ... | @@ -2073,7 +2070,7 @@ pub const Object = struct { |
| 2073 | 2070 | .int => blk: { |
| 2074 | 2071 | const info = elem_ty.intInfo(zcu); |
| 2075 | 2072 | assert(info.bits != 0); |
| 2076 | | const name = try o.allocTypeName(ty); |
| 2073 | const name = try o.allocTypeName(pt, ty); |
| 2077 | 2074 | defer gpa.free(name); |
| 2078 | 2075 | const builder_name = try o.builder.metadataString(name); |
| 2079 | 2076 | break :blk switch (info.signedness) { |
| ... | ... | @@ -2085,7 +2082,7 @@ pub const Object = struct { |
| 2085 | 2082 | try o.builder.metadataString("bool"), |
| 2086 | 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 | 2088 | const debug_vector_type = try o.builder.debugVectorType( |
| ... | ... | @@ -2108,7 +2105,7 @@ pub const Object = struct { |
| 2108 | 2105 | return debug_vector_type; |
| 2109 | 2106 | }, |
| 2110 | 2107 | .optional => { |
| 2111 | | const name = try o.allocTypeName(ty); |
| 2108 | const name = try o.allocTypeName(pt, ty); |
| 2112 | 2109 | defer gpa.free(name); |
| 2113 | 2110 | const child_ty = ty.optionalChild(zcu); |
| 2114 | 2111 | if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| ... | ... | @@ -2126,7 +2123,7 @@ pub const Object = struct { |
| 2126 | 2123 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); |
| 2127 | 2124 | |
| 2128 | 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 | 2128 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); |
| 2132 | 2129 | |
| ... | ... | @@ -2149,7 +2146,7 @@ pub const Object = struct { |
| 2149 | 2146 | .none, // File |
| 2150 | 2147 | debug_fwd_ref, |
| 2151 | 2148 | 0, // Line |
| 2152 | | try o.lowerDebugType(child_ty), |
| 2149 | try o.lowerDebugType(pt, child_ty), |
| 2153 | 2150 | payload_size * 8, |
| 2154 | 2151 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2155 | 2152 | 0, // Offset |
| ... | ... | @@ -2160,7 +2157,7 @@ pub const Object = struct { |
| 2160 | 2157 | .none, |
| 2161 | 2158 | debug_fwd_ref, |
| 2162 | 2159 | 0, |
| 2163 | | try o.lowerDebugType(non_null_ty), |
| 2160 | try o.lowerDebugType(pt, non_null_ty), |
| 2164 | 2161 | non_null_size * 8, |
| 2165 | 2162 | (non_null_align.toByteUnits() orelse 0) * 8, |
| 2166 | 2163 | non_null_offset * 8, |
| ... | ... | @@ -2192,12 +2189,12 @@ pub const Object = struct { |
| 2192 | 2189 | const payload_ty = ty.errorUnionPayload(zcu); |
| 2193 | 2190 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2194 | 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 | 2193 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); |
| 2197 | 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 | 2198 | defer gpa.free(name); |
| 2202 | 2199 | |
| 2203 | 2200 | const error_size = Type.anyerror.abiSize(zcu); |
| ... | ... | @@ -2229,7 +2226,7 @@ pub const Object = struct { |
| 2229 | 2226 | .none, // File |
| 2230 | 2227 | debug_fwd_ref, |
| 2231 | 2228 | 0, // Line |
| 2232 | | try o.lowerDebugType(Type.anyerror), |
| 2229 | try o.lowerDebugType(pt, Type.anyerror), |
| 2233 | 2230 | error_size * 8, |
| 2234 | 2231 | (error_align.toByteUnits() orelse 0) * 8, |
| 2235 | 2232 | error_offset * 8, |
| ... | ... | @@ -2239,7 +2236,7 @@ pub const Object = struct { |
| 2239 | 2236 | .none, // File |
| 2240 | 2237 | debug_fwd_ref, |
| 2241 | 2238 | 0, // Line |
| 2242 | | try o.lowerDebugType(payload_ty), |
| 2239 | try o.lowerDebugType(pt, payload_ty), |
| 2243 | 2240 | payload_size * 8, |
| 2244 | 2241 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2245 | 2242 | payload_offset * 8, |
| ... | ... | @@ -2270,7 +2267,7 @@ pub const Object = struct { |
| 2270 | 2267 | return debug_error_set; |
| 2271 | 2268 | }, |
| 2272 | 2269 | .@"struct" => { |
| 2273 | | const name = try o.allocTypeName(ty); |
| 2270 | const name = try o.allocTypeName(pt, ty); |
| 2274 | 2271 | defer gpa.free(name); |
| 2275 | 2272 | |
| 2276 | 2273 | if (zcu.typeToPackedStruct(ty)) |struct_type| { |
| ... | ... | @@ -2315,7 +2312,7 @@ pub const Object = struct { |
| 2315 | 2312 | .none, // File |
| 2316 | 2313 | debug_fwd_ref, |
| 2317 | 2314 | 0, |
| 2318 | | try o.lowerDebugType(Type.fromInterned(field_ty)), |
| 2315 | try o.lowerDebugType(pt, Type.fromInterned(field_ty)), |
| 2319 | 2316 | field_size * 8, |
| 2320 | 2317 | (field_align.toByteUnits() orelse 0) * 8, |
| 2321 | 2318 | field_offset * 8, |
| ... | ... | @@ -2347,7 +2344,7 @@ pub const Object = struct { |
| 2347 | 2344 | // into. Therefore we can satisfy this by making an empty namespace, |
| 2348 | 2345 | // rather than changing the frontend to unnecessarily resolve the |
| 2349 | 2346 | // struct field types. |
| 2350 | | const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty); |
| 2347 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2351 | 2348 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2352 | 2349 | return debug_struct_type; |
| 2353 | 2350 | } |
| ... | ... | @@ -2356,7 +2353,7 @@ pub const Object = struct { |
| 2356 | 2353 | } |
| 2357 | 2354 | |
| 2358 | 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 | 2357 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2361 | 2358 | return debug_struct_type; |
| 2362 | 2359 | } |
| ... | ... | @@ -2388,7 +2385,7 @@ pub const Object = struct { |
| 2388 | 2385 | .none, // File |
| 2389 | 2386 | debug_fwd_ref, |
| 2390 | 2387 | 0, // Line |
| 2391 | | try o.lowerDebugType(field_ty), |
| 2388 | try o.lowerDebugType(pt, field_ty), |
| 2392 | 2389 | field_size * 8, |
| 2393 | 2390 | (field_align.toByteUnits() orelse 0) * 8, |
| 2394 | 2391 | field_offset * 8, |
| ... | ... | @@ -2415,7 +2412,7 @@ pub const Object = struct { |
| 2415 | 2412 | return debug_struct_type; |
| 2416 | 2413 | }, |
| 2417 | 2414 | .@"union" => { |
| 2418 | | const name = try o.allocTypeName(ty); |
| 2415 | const name = try o.allocTypeName(pt, ty); |
| 2419 | 2416 | defer gpa.free(name); |
| 2420 | 2417 | |
| 2421 | 2418 | const union_type = ip.loadUnionType(ty.toIntern()); |
| ... | ... | @@ -2423,7 +2420,7 @@ pub const Object = struct { |
| 2423 | 2420 | !ty.hasRuntimeBitsIgnoreComptime(zcu) or |
| 2424 | 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 | 2424 | try o.debug_type_map.put(gpa, ty, debug_union_type); |
| 2428 | 2425 | return debug_union_type; |
| 2429 | 2426 | } |
| ... | ... | @@ -2445,7 +2442,7 @@ pub const Object = struct { |
| 2445 | 2442 | ty.abiSize(zcu) * 8, |
| 2446 | 2443 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2447 | 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 | 2481 | .none, // File |
| 2485 | 2482 | debug_union_fwd_ref, |
| 2486 | 2483 | 0, // Line |
| 2487 | | try o.lowerDebugType(Type.fromInterned(field_ty)), |
| 2484 | try o.lowerDebugType(pt, Type.fromInterned(field_ty)), |
| 2488 | 2485 | field_size * 8, |
| 2489 | 2486 | (field_align.toByteUnits() orelse 0) * 8, |
| 2490 | 2487 | 0, // Offset |
| ... | ... | @@ -2534,7 +2531,7 @@ pub const Object = struct { |
| 2534 | 2531 | .none, // File |
| 2535 | 2532 | debug_fwd_ref, |
| 2536 | 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 | 2535 | layout.tag_size * 8, |
| 2539 | 2536 | (layout.tag_align.toByteUnits() orelse 0) * 8, |
| 2540 | 2537 | tag_offset * 8, |
| ... | ... | @@ -2588,19 +2585,19 @@ pub const Object = struct { |
| 2588 | 2585 | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2589 | 2586 | const sret = firstParamSRet(fn_info, zcu, target); |
| 2590 | 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 | 2590 | if (sret) { |
| 2594 | 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 | 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 | 2598 | if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) { |
| 2602 | | const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType()); |
| 2603 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2599 | const ptr_ty = try pt.ptrType(.{ .child = zcu.stack_trace_type }); |
| 2600 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty)); |
| 2604 | 2601 | } |
| 2605 | 2602 | |
| 2606 | 2603 | for (0..fn_info.param_types.len) |i| { |
| ... | ... | @@ -2609,9 +2606,9 @@ pub const Object = struct { |
| 2609 | 2606 | |
| 2610 | 2607 | if (isByRef(param_ty, zcu)) { |
| 2611 | 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 | 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 | 2631 | } |
| 2635 | 2632 | } |
| 2636 | 2633 | |
| 2637 | | fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata { |
| 2638 | | const zcu = o.pt.zcu; |
| 2634 | fn namespaceToDebugScope(o: *Object, pt: Zcu.PerThread, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata { |
| 2635 | const zcu = pt.zcu; |
| 2639 | 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 | 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 | 2643 | return gop.value_ptr.*; |
| 2647 | 2644 | } |
| 2648 | 2645 | |
| 2649 | | fn makeEmptyNamespaceDebugType(o: *Object, ty: Type) !Builder.Metadata { |
| 2650 | | const zcu = o.pt.zcu; |
| 2646 | fn makeEmptyNamespaceDebugType(o: *Object, pt: Zcu.PerThread, ty: Type) !Builder.Metadata { |
| 2647 | const zcu = pt.zcu; |
| 2651 | 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 | 2650 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 2654 | | try o.namespaceToDebugScope(parent_namespace) |
| 2651 | try o.namespaceToDebugScope(pt, parent_namespace) |
| 2655 | 2652 | else |
| 2656 | 2653 | file; |
| 2657 | 2654 | return o.builder.debugStructType( |
| ... | ... | @@ -2666,31 +2663,10 @@ pub const Object = struct { |
| 2666 | 2663 | ); |
| 2667 | 2664 | } |
| 2668 | 2665 | |
| 2669 | | fn getStackTraceType(o: *Object) Allocator.Error!Type { |
| 2670 | | const pt = o.pt; |
| 2671 | | const zcu = pt.zcu; |
| 2672 | | const ip = &zcu.intern_pool; |
| 2673 | | |
| 2674 | | const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?; |
| 2675 | | const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls); |
| 2676 | | const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_index)); |
| 2677 | | const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu)); |
| 2678 | | const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; |
| 2679 | | |
| 2680 | | const stack_trace_str = try ip.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls); |
| 2681 | | // buffer is only used for int_type, `builtin` is a struct. |
| 2682 | | const builtin_ty = zcu.navValue(builtin_nav).toType(); |
| 2683 | | const builtin_namespace = zcu.namespacePtr(builtin_ty.getNamespaceIndex(zcu)); |
| 2684 | | const stack_trace_nav = builtin_namespace.pub_decls.getKeyAdapted(stack_trace_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; |
| 2685 | | |
| 2686 | | // Sema should have ensured that StackTrace was analyzed. |
| 2687 | | return zcu.navValue(stack_trace_nav).toType(); |
| 2688 | | } |
| 2689 | | |
| 2690 | | fn allocTypeName(o: *Object, ty: Type) Allocator.Error![:0]const u8 { |
| 2666 | fn allocTypeName(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error![:0]const u8 { |
| 2691 | 2667 | var aw: std.io.Writer.Allocating = .init(o.gpa); |
| 2692 | 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 | 2670 | error.WriteFailed => return error.OutOfMemory, |
| 2695 | 2671 | }; |
| 2696 | 2672 | return aw.toOwnedSliceSentinel(0); |
| ... | ... | @@ -2701,9 +2677,9 @@ pub const Object = struct { |
| 2701 | 2677 | /// completed, so if any attributes rely on that, they must be done in updateFunc, not here. |
| 2702 | 2678 | fn resolveLlvmFunction( |
| 2703 | 2679 | o: *Object, |
| 2680 | pt: Zcu.PerThread, |
| 2704 | 2681 | nav_index: InternPool.Nav.Index, |
| 2705 | 2682 | ) Allocator.Error!Builder.Function.Index { |
| 2706 | | const pt = o.pt; |
| 2707 | 2683 | const zcu = pt.zcu; |
| 2708 | 2684 | const ip = &zcu.intern_pool; |
| 2709 | 2685 | const gpa = o.gpa; |
| ... | ... | @@ -2722,7 +2698,7 @@ pub const Object = struct { |
| 2722 | 2698 | else |
| 2723 | 2699 | .{ false, .none }; |
| 2724 | 2700 | const function_index = try o.builder.addFunction( |
| 2725 | | try o.lowerType(ty), |
| 2701 | try o.lowerType(pt, ty), |
| 2726 | 2702 | try o.builder.strtabString((if (is_extern) nav.name else nav.fqn).toSlice(ip)), |
| 2727 | 2703 | toLlvmAddressSpace(nav.getAddrspace(), target), |
| 2728 | 2704 | ); |
| ... | ... | @@ -2755,7 +2731,7 @@ pub const Object = struct { |
| 2755 | 2731 | try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder); |
| 2756 | 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 | 2735 | try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder); |
| 2760 | 2736 | |
| 2761 | 2737 | llvm_arg_i += 1; |
| ... | ... | @@ -2862,19 +2838,19 @@ pub const Object = struct { |
| 2862 | 2838 | // Add parameter attributes. We handle only the case of extern functions (no body) |
| 2863 | 2839 | // because functions with bodies are handled in `updateFunc`. |
| 2864 | 2840 | if (is_extern) { |
| 2865 | | var it = iterateParamTypes(o, fn_info); |
| 2841 | var it = iterateParamTypes(o, pt, fn_info); |
| 2866 | 2842 | it.llvm_index = llvm_arg_i; |
| 2867 | 2843 | while (try it.next()) |lowering| switch (lowering) { |
| 2868 | 2844 | .byval => { |
| 2869 | 2845 | const param_index = it.zig_index - 1; |
| 2870 | 2846 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); |
| 2871 | 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 | 2851 | .byref => { |
| 2876 | 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 | 2854 | const alignment = param_ty.abiAlignment(zcu); |
| 2879 | 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 | 2945 | |
| 2970 | 2946 | fn resolveGlobalUav( |
| 2971 | 2947 | o: *Object, |
| 2948 | pt: Zcu.PerThread, |
| 2972 | 2949 | uav: InternPool.Index, |
| 2973 | 2950 | llvm_addr_space: Builder.AddrSpace, |
| 2974 | 2951 | alignment: InternPool.Alignment, |
| ... | ... | @@ -2986,17 +2963,17 @@ pub const Object = struct { |
| 2986 | 2963 | } |
| 2987 | 2964 | errdefer assert(o.uav_map.remove(uav)); |
| 2988 | 2965 | |
| 2989 | | const zcu = o.pt.zcu; |
| 2966 | const zcu = pt.zcu; |
| 2990 | 2967 | const decl_ty = zcu.intern_pool.typeOf(uav); |
| 2991 | 2968 | |
| 2992 | 2969 | const variable_index = try o.builder.addVariable( |
| 2993 | 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 | 2972 | llvm_addr_space, |
| 2996 | 2973 | ); |
| 2997 | 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 | 2977 | variable_index.setLinkage(.internal, &o.builder); |
| 3001 | 2978 | variable_index.setMutability(.constant, &o.builder); |
| 3002 | 2979 | variable_index.setUnnamedAddr(.unnamed_addr, &o.builder); |
| ... | ... | @@ -3006,13 +2983,13 @@ pub const Object = struct { |
| 3006 | 2983 | |
| 3007 | 2984 | fn resolveGlobalNav( |
| 3008 | 2985 | o: *Object, |
| 2986 | pt: Zcu.PerThread, |
| 3009 | 2987 | nav_index: InternPool.Nav.Index, |
| 3010 | 2988 | ) Allocator.Error!Builder.Variable.Index { |
| 3011 | 2989 | const gop = try o.nav_map.getOrPut(o.gpa, nav_index); |
| 3012 | 2990 | if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable; |
| 3013 | 2991 | errdefer assert(o.nav_map.remove(nav_index)); |
| 3014 | 2992 | |
| 3015 | | const pt = o.pt; |
| 3016 | 2993 | const zcu = pt.zcu; |
| 3017 | 2994 | const ip = &zcu.intern_pool; |
| 3018 | 2995 | const nav = ip.getNav(nav_index); |
| ... | ... | @@ -3033,7 +3010,7 @@ pub const Object = struct { |
| 3033 | 3010 | .strong, .weak => nav.name, |
| 3034 | 3011 | .link_once => unreachable, |
| 3035 | 3012 | }.toSlice(ip)), |
| 3036 | | try o.lowerType(Type.fromInterned(nav.typeOf(ip))), |
| 3013 | try o.lowerType(pt, Type.fromInterned(nav.typeOf(ip))), |
| 3037 | 3014 | toLlvmGlobalAddressSpace(nav.getAddrspace(), zcu.getTarget()), |
| 3038 | 3015 | ); |
| 3039 | 3016 | gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; |
| ... | ... | @@ -3062,12 +3039,11 @@ pub const Object = struct { |
| 3062 | 3039 | return variable_index; |
| 3063 | 3040 | } |
| 3064 | 3041 | |
| 3065 | | fn errorIntType(o: *Object) Allocator.Error!Builder.Type { |
| 3066 | | return o.builder.intType(o.pt.zcu.errorSetBits()); |
| 3042 | fn errorIntType(o: *Object, pt: Zcu.PerThread) Allocator.Error!Builder.Type { |
| 3043 | return o.builder.intType(pt.zcu.errorSetBits()); |
| 3067 | 3044 | } |
| 3068 | 3045 | |
| 3069 | | fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type { |
| 3070 | | const pt = o.pt; |
| 3046 | fn lowerType(o: *Object, pt: Zcu.PerThread, t: Type) Allocator.Error!Builder.Type { |
| 3071 | 3047 | const zcu = pt.zcu; |
| 3072 | 3048 | const target = zcu.getTarget(); |
| 3073 | 3049 | const ip = &zcu.intern_pool; |
| ... | ... | @@ -3123,7 +3099,7 @@ pub const Object = struct { |
| 3123 | 3099 | .bool_type => .i1, |
| 3124 | 3100 | .void_type => .void, |
| 3125 | 3101 | .type_type => unreachable, |
| 3126 | | .anyerror_type => try o.errorIntType(), |
| 3102 | .anyerror_type => try o.errorIntType(pt), |
| 3127 | 3103 | .comptime_int_type, |
| 3128 | 3104 | .comptime_float_type, |
| 3129 | 3105 | .noreturn_type, |
| ... | ... | @@ -3141,11 +3117,11 @@ pub const Object = struct { |
| 3141 | 3117 | => .ptr, |
| 3142 | 3118 | .slice_const_u8_type, |
| 3143 | 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 | 3121 | .optional_noreturn_type => unreachable, |
| 3146 | 3122 | .anyerror_void_error_union_type, |
| 3147 | 3123 | .adhoc_inferred_error_set_type, |
| 3148 | | => try o.errorIntType(), |
| 3124 | => try o.errorIntType(pt), |
| 3149 | 3125 | .generic_poison_type, |
| 3150 | 3126 | .empty_tuple_type, |
| 3151 | 3127 | => unreachable, |
| ... | ... | @@ -3182,24 +3158,24 @@ pub const Object = struct { |
| 3182 | 3158 | .one, .many, .c => ptr_ty, |
| 3183 | 3159 | .slice => try o.builder.structType(.normal, &.{ |
| 3184 | 3160 | ptr_ty, |
| 3185 | | try o.lowerType(Type.usize), |
| 3161 | try o.lowerType(pt, Type.usize), |
| 3186 | 3162 | }), |
| 3187 | 3163 | }; |
| 3188 | 3164 | }, |
| 3189 | 3165 | .array_type => |array_type| o.builder.arrayType( |
| 3190 | 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 | 3169 | .vector_type => |vector_type| o.builder.vectorType( |
| 3194 | 3170 | .normal, |
| 3195 | 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 | 3174 | .opt_type => |child_ty| { |
| 3199 | 3175 | // Must stay in sync with `opt_payload` logic in `lowerPtr`. |
| 3200 | 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 | 3179 | if (t.optionalReprIsPayload(zcu)) return payload_ty; |
| 3204 | 3180 | |
| 3205 | 3181 | comptime assert(optional_layout_version == 3); |
| ... | ... | @@ -3218,17 +3194,16 @@ pub const Object = struct { |
| 3218 | 3194 | .error_union_type => |error_union_type| { |
| 3219 | 3195 | // Must stay in sync with `codegen.errUnionPayloadOffset`. |
| 3220 | 3196 | // See logic in `lowerPtr`. |
| 3221 | | const error_type = try o.errorIntType(); |
| 3197 | const error_type = try o.errorIntType(pt); |
| 3222 | 3198 | if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu)) |
| 3223 | 3199 | return error_type; |
| 3224 | | const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type)); |
| 3225 | | const err_int_ty = try o.pt.errorIntType(); |
| 3200 | const payload_type = try o.lowerType(pt, Type.fromInterned(error_union_type.payload_type)); |
| 3226 | 3201 | |
| 3227 | 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 | 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 | 3208 | var fields: [3]Builder.Type = undefined; |
| 3234 | 3209 | var fields_len: usize = 2; |
| ... | ... | @@ -3262,7 +3237,7 @@ pub const Object = struct { |
| 3262 | 3237 | const struct_type = ip.loadStructType(t.toIntern()); |
| 3263 | 3238 | |
| 3264 | 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 | 3241 | try o.type_map.put(o.gpa, t.toIntern(), int_ty); |
| 3267 | 3242 | return int_ty; |
| 3268 | 3243 | } |
| ... | ... | @@ -3312,7 +3287,7 @@ pub const Object = struct { |
| 3312 | 3287 | .struct_ty = t.toIntern(), |
| 3313 | 3288 | .field_index = field_index, |
| 3314 | 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 | 3292 | offset += field_ty.abiSize(zcu); |
| 3318 | 3293 | } |
| ... | ... | @@ -3382,7 +3357,7 @@ pub const Object = struct { |
| 3382 | 3357 | .struct_ty = t.toIntern(), |
| 3383 | 3358 | .field_index = @intCast(field_index), |
| 3384 | 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 | 3362 | offset += Type.fromInterned(field_ty).abiSize(zcu); |
| 3388 | 3363 | } |
| ... | ... | @@ -3410,13 +3385,13 @@ pub const Object = struct { |
| 3410 | 3385 | } |
| 3411 | 3386 | |
| 3412 | 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 | 3389 | try o.type_map.put(o.gpa, t.toIntern(), enum_tag_ty); |
| 3415 | 3390 | return enum_tag_ty; |
| 3416 | 3391 | } |
| 3417 | 3392 | |
| 3418 | 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 | 3396 | const payload_ty = ty: { |
| 3422 | 3397 | if (layout.most_aligned_field_size == layout.payload_size) { |
| ... | ... | @@ -3442,7 +3417,7 @@ pub const Object = struct { |
| 3442 | 3417 | ); |
| 3443 | 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 | 3422 | // Put the tag before or after the payload depending on which one's |
| 3448 | 3423 | // alignment is greater. |
| ... | ... | @@ -3477,9 +3452,9 @@ pub const Object = struct { |
| 3477 | 3452 | } |
| 3478 | 3453 | return gop.value_ptr.*; |
| 3479 | 3454 | }, |
| 3480 | | .enum_type => try o.lowerType(Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)), |
| 3481 | | .func_type => |func_type| try o.lowerTypeFn(func_type), |
| 3482 | | .error_set_type, .inferred_error_set_type => try o.errorIntType(), |
| 3455 | .enum_type => try o.lowerType(pt, Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)), |
| 3456 | .func_type => |func_type| try o.lowerTypeFn(pt, func_type), |
| 3457 | .error_set_type, .inferred_error_set_type => try o.errorIntType(pt), |
| 3483 | 3458 | // values, not types |
| 3484 | 3459 | .undef, |
| 3485 | 3460 | .simple_value, |
| ... | ... | @@ -3508,8 +3483,7 @@ pub const Object = struct { |
| 3508 | 3483 | /// Use this instead of lowerType when you want to handle correctly the case of elem_ty |
| 3509 | 3484 | /// being a zero bit type, but it should still be lowered as an i8 in such case. |
| 3510 | 3485 | /// There are other similar cases handled here as well. |
| 3511 | | fn lowerPtrElemTy(o: *Object, elem_ty: Type) Allocator.Error!Builder.Type { |
| 3512 | | const pt = o.pt; |
| 3486 | fn lowerPtrElemTy(o: *Object, pt: Zcu.PerThread, elem_ty: Type) Allocator.Error!Builder.Type { |
| 3513 | 3487 | const zcu = pt.zcu; |
| 3514 | 3488 | const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) { |
| 3515 | 3489 | .@"opaque" => true, |
| ... | ... | @@ -3517,15 +3491,14 @@ pub const Object = struct { |
| 3517 | 3491 | .array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu), |
| 3518 | 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 { |
| 3524 | | const pt = o.pt; |
| 3497 | fn lowerTypeFn(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 3525 | 3498 | const zcu = pt.zcu; |
| 3526 | 3499 | const ip = &zcu.intern_pool; |
| 3527 | 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 | 3503 | var llvm_params: std.ArrayListUnmanaged(Builder.Type) = .empty; |
| 3531 | 3504 | defer llvm_params.deinit(o.gpa); |
| ... | ... | @@ -3535,16 +3508,16 @@ pub const Object = struct { |
| 3535 | 3508 | } |
| 3536 | 3509 | |
| 3537 | 3510 | if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) { |
| 3538 | | const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType()); |
| 3539 | | try llvm_params.append(o.gpa, try o.lowerType(ptr_ty)); |
| 3511 | const ptr_ty = try pt.ptrType(.{ .child = zcu.stack_trace_type }); |
| 3512 | try llvm_params.append(o.gpa, try o.lowerType(pt, ptr_ty)); |
| 3540 | 3513 | } |
| 3541 | 3514 | |
| 3542 | | var it = iterateParamTypes(o, fn_info); |
| 3515 | var it = iterateParamTypes(o, pt, fn_info); |
| 3543 | 3516 | while (try it.next()) |lowering| switch (lowering) { |
| 3544 | 3517 | .no_bits => continue, |
| 3545 | 3518 | .byval => { |
| 3546 | 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 | 3522 | .byref, .byref_mut => { |
| 3550 | 3523 | try llvm_params.append(o.gpa, .ptr); |
| ... | ... | @@ -3559,7 +3532,7 @@ pub const Object = struct { |
| 3559 | 3532 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); |
| 3560 | 3533 | try llvm_params.appendSlice(o.gpa, &.{ |
| 3561 | 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 | 3538 | .multiple_llvm_types => { |
| ... | ... | @@ -3567,7 +3540,7 @@ pub const Object = struct { |
| 3567 | 3540 | }, |
| 3568 | 3541 | .float_array => |count| { |
| 3569 | 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 | 3544 | try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty)); |
| 3572 | 3545 | }, |
| 3573 | 3546 | .i32_array, .i64_array => |arr_len| { |
| ... | ... | @@ -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 { |
| 3590 | | const pt = o.pt; |
| 3562 | fn lowerValueToInt(o: *Object, pt: Zcu.PerThread, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant { |
| 3591 | 3563 | const zcu = pt.zcu; |
| 3592 | 3564 | const ip = &zcu.intern_pool; |
| 3593 | 3565 | const target = zcu.getTarget(); |
| ... | ... | @@ -3600,23 +3572,23 @@ pub const Object = struct { |
| 3600 | 3572 | const ty = Type.fromInterned(val_key.typeOf()); |
| 3601 | 3573 | switch (val_key) { |
| 3602 | 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 | 3576 | const ptr = function_index.ptrConst(&o.builder).global.toConst(); |
| 3605 | 3577 | return o.builder.convConst(ptr, llvm_int_ty); |
| 3606 | 3578 | }, |
| 3607 | 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 | 3581 | const ptr = function_index.ptrConst(&o.builder).global.toConst(); |
| 3610 | 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 | 3585 | .aggregate => switch (ip.indexToKey(ty.toIntern())) { |
| 3614 | 3586 | .struct_type, .vector_type => {}, |
| 3615 | 3587 | else => unreachable, |
| 3616 | 3588 | }, |
| 3617 | 3589 | .un => |un| { |
| 3618 | 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 | 3593 | const union_obj = zcu.typeToUnion(ty).?; |
| 3622 | 3594 | const container_layout = union_obj.flagsUnordered(ip).layout; |
| ... | ... | @@ -3626,7 +3598,7 @@ pub const Object = struct { |
| 3626 | 3598 | var need_unnamed = false; |
| 3627 | 3599 | if (un.tag == .none) { |
| 3628 | 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 | 3603 | need_unnamed = true; |
| 3632 | 3604 | return union_val; |
| ... | ... | @@ -3634,7 +3606,7 @@ pub const Object = struct { |
| 3634 | 3606 | const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?; |
| 3635 | 3607 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]); |
| 3636 | 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 | 3611 | .simple_value => |simple_value| switch (simple_value) { |
| 3640 | 3612 | .false, .true => {}, |
| ... | ... | @@ -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 { |
| 3682 | | const pt = o.pt; |
| 3653 | fn lowerValue(o: *Object, pt: Zcu.PerThread, arg_val: InternPool.Index) Error!Builder.Constant { |
| 3683 | 3654 | const zcu = pt.zcu; |
| 3684 | 3655 | const ip = &zcu.intern_pool; |
| 3685 | 3656 | const target = zcu.getTarget(); |
| ... | ... | @@ -3688,7 +3659,7 @@ pub const Object = struct { |
| 3688 | 3659 | const val_key = ip.indexToKey(val.toIntern()); |
| 3689 | 3660 | |
| 3690 | 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 | 3665 | const ty = Type.fromInterned(val_key.typeOf()); |
| ... | ... | @@ -3727,21 +3698,21 @@ pub const Object = struct { |
| 3727 | 3698 | .empty_enum_value, |
| 3728 | 3699 | => unreachable, // non-runtime values |
| 3729 | 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 | 3702 | return function_index.ptrConst(&o.builder).global.toConst(); |
| 3732 | 3703 | }, |
| 3733 | 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 | 3706 | return function_index.ptrConst(&o.builder).global.toConst(); |
| 3736 | 3707 | }, |
| 3737 | 3708 | .int => { |
| 3738 | 3709 | var bigint_space: Value.BigIntSpace = undefined; |
| 3739 | 3710 | const bigint = val.toBigInt(&bigint_space, zcu); |
| 3740 | | return lowerBigInt(o, ty, bigint); |
| 3711 | return lowerBigInt(o, pt, ty, bigint); |
| 3741 | 3712 | }, |
| 3742 | 3713 | .err => |err| { |
| 3743 | 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 | 3716 | return llvm_int; |
| 3746 | 3717 | }, |
| 3747 | 3718 | .error_union => |error_union| { |
| ... | ... | @@ -3756,13 +3727,13 @@ pub const Object = struct { |
| 3756 | 3727 | const payload_type = ty.errorUnionPayload(zcu); |
| 3757 | 3728 | if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 3758 | 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 | 3733 | const payload_align = payload_type.abiAlignment(zcu); |
| 3763 | 3734 | const error_align = err_int_ty.abiAlignment(zcu); |
| 3764 | | const llvm_error_value = try o.lowerValue(err_val); |
| 3765 | | const llvm_payload_value = try o.lowerValue(switch (error_union.val) { |
| 3735 | const llvm_error_value = try o.lowerValue(pt, err_val); |
| 3736 | const llvm_payload_value = try o.lowerValue(pt, switch (error_union.val) { |
| 3766 | 3737 | .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }), |
| 3767 | 3738 | .payload => |payload| payload, |
| 3768 | 3739 | }); |
| ... | ... | @@ -3779,7 +3750,7 @@ pub const Object = struct { |
| 3779 | 3750 | fields[0] = vals[0].typeOf(&o.builder); |
| 3780 | 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 | 3754 | const llvm_ty_fields = llvm_ty.structFields(&o.builder); |
| 3784 | 3755 | if (llvm_ty_fields.len > 2) { |
| 3785 | 3756 | assert(llvm_ty_fields.len == 3); |
| ... | ... | @@ -3791,7 +3762,7 @@ pub const Object = struct { |
| 3791 | 3762 | fields[0..llvm_ty_fields.len], |
| 3792 | 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 | 3766 | .float => switch (ty.floatBits(target)) { |
| 3796 | 3767 | 16 => if (backendSupportsF16(target)) |
| 3797 | 3768 | try o.builder.halfConst(val.toFloat(f16, zcu)) |
| ... | ... | @@ -3806,10 +3777,10 @@ pub const Object = struct { |
| 3806 | 3777 | 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)), |
| 3807 | 3778 | else => unreachable, |
| 3808 | 3779 | }, |
| 3809 | | .ptr => try o.lowerPtr(arg_val, 0), |
| 3810 | | .slice => |slice| return o.builder.structConst(try o.lowerType(ty), &.{ |
| 3811 | | try o.lowerValue(slice.ptr), |
| 3812 | | try o.lowerValue(slice.len), |
| 3780 | .ptr => try o.lowerPtr(pt, arg_val, 0), |
| 3781 | .slice => |slice| return o.builder.structConst(try o.lowerType(pt, ty), &.{ |
| 3782 | try o.lowerValue(pt, slice.ptr), |
| 3783 | try o.lowerValue(pt, slice.len), |
| 3813 | 3784 | }), |
| 3814 | 3785 | .opt => |opt| { |
| 3815 | 3786 | comptime assert(optional_layout_version == 3); |
| ... | ... | @@ -3819,7 +3790,7 @@ pub const Object = struct { |
| 3819 | 3790 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 3820 | 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 | 3794 | if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) { |
| 3824 | 3795 | .none => switch (llvm_ty.tag(&o.builder)) { |
| 3825 | 3796 | .integer => try o.builder.intConst(llvm_ty, 0), |
| ... | ... | @@ -3827,13 +3798,13 @@ pub const Object = struct { |
| 3827 | 3798 | .structure => try o.builder.zeroInitConst(llvm_ty), |
| 3828 | 3799 | else => unreachable, |
| 3829 | 3800 | }, |
| 3830 | | else => |payload| try o.lowerValue(payload), |
| 3801 | else => |payload| try o.lowerValue(pt, payload), |
| 3831 | 3802 | }; |
| 3832 | 3803 | assert(payload_ty.zigTypeTag(zcu) != .@"fn"); |
| 3833 | 3804 | |
| 3834 | 3805 | var fields: [3]Builder.Type = undefined; |
| 3835 | 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 | 3808 | .none => try pt.intern(.{ .undef = payload_ty.toIntern() }), |
| 3838 | 3809 | else => |payload| payload, |
| 3839 | 3810 | }); |
| ... | ... | @@ -3858,7 +3829,7 @@ pub const Object = struct { |
| 3858 | 3829 | bytes.toSlice(array_type.lenIncludingSentinel(), ip), |
| 3859 | 3830 | )), |
| 3860 | 3831 | .elems => |elems| { |
| 3861 | | const array_ty = try o.lowerType(ty); |
| 3832 | const array_ty = try o.lowerType(pt, ty); |
| 3862 | 3833 | const elem_ty = array_ty.childType(&o.builder); |
| 3863 | 3834 | assert(elems.len == array_ty.aggregateLen(&o.builder)); |
| 3864 | 3835 | |
| ... | ... | @@ -3878,7 +3849,7 @@ pub const Object = struct { |
| 3878 | 3849 | |
| 3879 | 3850 | var need_unnamed = false; |
| 3880 | 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 | 3853 | result_field.* = result_val.typeOf(&o.builder); |
| 3883 | 3854 | if (result_field.* != elem_ty) need_unnamed = true; |
| 3884 | 3855 | } |
| ... | ... | @@ -3890,7 +3861,7 @@ pub const Object = struct { |
| 3890 | 3861 | .repeated_elem => |elem| { |
| 3891 | 3862 | const len: usize = @intCast(array_type.len); |
| 3892 | 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 | 3865 | const elem_ty = array_ty.childType(&o.builder); |
| 3895 | 3866 | |
| 3896 | 3867 | const ExpectedContents = extern struct { |
| ... | ... | @@ -3908,12 +3879,12 @@ pub const Object = struct { |
| 3908 | 3879 | defer allocator.free(fields); |
| 3909 | 3880 | |
| 3910 | 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 | 3883 | @memset(fields[0..len], vals[0].typeOf(&o.builder)); |
| 3913 | 3884 | if (fields[0] != elem_ty) need_unnamed = true; |
| 3914 | 3885 | |
| 3915 | 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 | 3888 | fields[len] = vals[len].typeOf(&o.builder); |
| 3918 | 3889 | if (fields[len] != elem_ty) need_unnamed = true; |
| 3919 | 3890 | } |
| ... | ... | @@ -3925,7 +3896,7 @@ pub const Object = struct { |
| 3925 | 3896 | }, |
| 3926 | 3897 | }, |
| 3927 | 3898 | .vector_type => |vector_type| { |
| 3928 | | const vector_ty = try o.lowerType(ty); |
| 3899 | const vector_ty = try o.lowerType(pt, ty); |
| 3929 | 3900 | switch (aggregate.storage) { |
| 3930 | 3901 | .bytes, .elems => { |
| 3931 | 3902 | const ExpectedContents = [Builder.expected_fields_len]Builder.Constant; |
| ... | ... | @@ -3942,7 +3913,7 @@ pub const Object = struct { |
| 3942 | 3913 | result_val.* = try o.builder.intConst(.i8, byte); |
| 3943 | 3914 | }, |
| 3944 | 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 | 3918 | .repeated_elem => unreachable, |
| 3948 | 3919 | } |
| ... | ... | @@ -3950,12 +3921,12 @@ pub const Object = struct { |
| 3950 | 3921 | }, |
| 3951 | 3922 | .repeated_elem => |elem| return o.builder.splatConst( |
| 3952 | 3923 | vector_ty, |
| 3953 | | try o.lowerValue(elem), |
| 3924 | try o.lowerValue(pt, elem), |
| 3954 | 3925 | ), |
| 3955 | 3926 | } |
| 3956 | 3927 | }, |
| 3957 | 3928 | .tuple_type => |tuple| { |
| 3958 | | const struct_ty = try o.lowerType(ty); |
| 3929 | const struct_ty = try o.lowerType(pt, ty); |
| 3959 | 3930 | const llvm_len = struct_ty.aggregateLen(&o.builder); |
| 3960 | 3931 | |
| 3961 | 3932 | const ExpectedContents = extern struct { |
| ... | ... | @@ -4001,7 +3972,7 @@ pub const Object = struct { |
| 4001 | 3972 | } |
| 4002 | 3973 | |
| 4003 | 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 | 3976 | fields[llvm_index] = vals[llvm_index].typeOf(&o.builder); |
| 4006 | 3977 | if (fields[llvm_index] != struct_ty.structFields(&o.builder)[llvm_index]) |
| 4007 | 3978 | need_unnamed = true; |
| ... | ... | @@ -4030,14 +4001,14 @@ pub const Object = struct { |
| 4030 | 4001 | .struct_type => { |
| 4031 | 4002 | const struct_type = ip.loadStructType(ty.toIntern()); |
| 4032 | 4003 | assert(struct_type.haveLayout(ip)); |
| 4033 | | const struct_ty = try o.lowerType(ty); |
| 4004 | const struct_ty = try o.lowerType(pt, ty); |
| 4034 | 4005 | if (struct_type.layout == .@"packed") { |
| 4035 | 4006 | comptime assert(Type.packed_struct_layout_version == 2); |
| 4036 | 4007 | |
| 4037 | 4008 | const bits = ty.bitSize(zcu); |
| 4038 | 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 | 4013 | const llvm_len = struct_ty.aggregateLen(&o.builder); |
| 4043 | 4014 | |
| ... | ... | @@ -4085,6 +4056,7 @@ pub const Object = struct { |
| 4085 | 4056 | } |
| 4086 | 4057 | |
| 4087 | 4058 | vals[llvm_index] = try o.lowerValue( |
| 4059 | pt, |
| 4088 | 4060 | (try val.fieldValue(pt, field_index)).toIntern(), |
| 4089 | 4061 | ); |
| 4090 | 4062 | fields[llvm_index] = vals[llvm_index].typeOf(&o.builder); |
| ... | ... | @@ -4115,9 +4087,9 @@ pub const Object = struct { |
| 4115 | 4087 | else => unreachable, |
| 4116 | 4088 | }, |
| 4117 | 4089 | .un => |un| { |
| 4118 | | const union_ty = try o.lowerType(ty); |
| 4090 | const union_ty = try o.lowerType(pt, ty); |
| 4119 | 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 | 4094 | const union_obj = zcu.typeToUnion(ty).?; |
| 4123 | 4095 | const container_layout = union_obj.flagsUnordered(ip).layout; |
| ... | ... | @@ -4131,7 +4103,7 @@ pub const Object = struct { |
| 4131 | 4103 | const bits = ty.bitSize(zcu); |
| 4132 | 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 | 4109 | // Sometimes we must make an unnamed struct because LLVM does |
| ... | ... | @@ -4144,7 +4116,7 @@ pub const Object = struct { |
| 4144 | 4116 | const padding_len = layout.payload_size; |
| 4145 | 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 | 4120 | const payload_ty = payload.typeOf(&o.builder); |
| 4149 | 4121 | if (payload_ty != union_ty.structFields(&o.builder)[ |
| 4150 | 4122 | @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)) |
| ... | ... | @@ -4163,10 +4135,10 @@ pub const Object = struct { |
| 4163 | 4135 | const bits = ty.bitSize(zcu); |
| 4164 | 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 | 4142 | need_unnamed = true; |
| 4171 | 4143 | break :p union_val; |
| 4172 | 4144 | }; |
| ... | ... | @@ -4176,7 +4148,7 @@ pub const Object = struct { |
| 4176 | 4148 | try o.builder.structType(union_ty.structKind(&o.builder), &.{payload_ty}) |
| 4177 | 4149 | else |
| 4178 | 4150 | union_ty, &.{payload}); |
| 4179 | | const tag = try o.lowerValue(un.tag); |
| 4151 | const tag = try o.lowerValue(pt, un.tag); |
| 4180 | 4152 | const tag_ty = tag.typeOf(&o.builder); |
| 4181 | 4153 | var fields: [3]Builder.Type = undefined; |
| 4182 | 4154 | var vals: [3]Builder.Constant = undefined; |
| ... | ... | @@ -4204,48 +4176,50 @@ pub const Object = struct { |
| 4204 | 4176 | |
| 4205 | 4177 | fn lowerBigInt( |
| 4206 | 4178 | o: *Object, |
| 4179 | pt: Zcu.PerThread, |
| 4207 | 4180 | ty: Type, |
| 4208 | 4181 | bigint: std.math.big.int.Const, |
| 4209 | 4182 | ) Allocator.Error!Builder.Constant { |
| 4210 | | const zcu = o.pt.zcu; |
| 4183 | const zcu = pt.zcu; |
| 4211 | 4184 | return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint); |
| 4212 | 4185 | } |
| 4213 | 4186 | |
| 4214 | 4187 | fn lowerPtr( |
| 4215 | 4188 | o: *Object, |
| 4189 | pt: Zcu.PerThread, |
| 4216 | 4190 | ptr_val: InternPool.Index, |
| 4217 | 4191 | prev_offset: u64, |
| 4218 | 4192 | ) Error!Builder.Constant { |
| 4219 | | const pt = o.pt; |
| 4220 | 4193 | const zcu = pt.zcu; |
| 4221 | 4194 | const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr; |
| 4222 | 4195 | const offset: u64 = prev_offset + ptr.byte_offset; |
| 4223 | 4196 | return switch (ptr.base_addr) { |
| 4224 | 4197 | .nav => |nav| { |
| 4225 | | const base_ptr = try o.lowerNavRefValue(nav); |
| 4198 | const base_ptr = try o.lowerNavRefValue(pt, nav); |
| 4226 | 4199 | return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{ |
| 4227 | 4200 | try o.builder.intConst(.i64, offset), |
| 4228 | 4201 | }); |
| 4229 | 4202 | }, |
| 4230 | 4203 | .uav => |uav| { |
| 4231 | | const base_ptr = try o.lowerUavRef(uav); |
| 4204 | const base_ptr = try o.lowerUavRef(pt, uav); |
| 4232 | 4205 | return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{ |
| 4233 | 4206 | try o.builder.intConst(.i64, offset), |
| 4234 | 4207 | }); |
| 4235 | 4208 | }, |
| 4236 | 4209 | .int => try o.builder.castConst( |
| 4237 | 4210 | .inttoptr, |
| 4238 | | try o.builder.intConst(try o.lowerType(Type.usize), offset), |
| 4239 | | try o.lowerType(Type.fromInterned(ptr.ty)), |
| 4211 | try o.builder.intConst(try o.lowerType(pt, Type.usize), offset), |
| 4212 | try o.lowerType(pt, Type.fromInterned(ptr.ty)), |
| 4240 | 4213 | ), |
| 4241 | 4214 | .eu_payload => |eu_ptr| try o.lowerPtr( |
| 4215 | pt, |
| 4242 | 4216 | eu_ptr, |
| 4243 | 4217 | offset + @import("../codegen.zig").errUnionPayloadOffset( |
| 4244 | 4218 | Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu), |
| 4245 | 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 | 4223 | .field => |field| { |
| 4250 | 4224 | const agg_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu); |
| 4251 | 4225 | const field_off: u64 = switch (agg_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -4263,7 +4237,7 @@ pub const Object = struct { |
| 4263 | 4237 | }, |
| 4264 | 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 | 4242 | .arr_elem, .comptime_field, .comptime_alloc => unreachable, |
| 4269 | 4243 | }; |
| ... | ... | @@ -4273,9 +4247,9 @@ pub const Object = struct { |
| 4273 | 4247 | /// Maybe the logic could be unified. |
| 4274 | 4248 | fn lowerUavRef( |
| 4275 | 4249 | o: *Object, |
| 4250 | pt: Zcu.PerThread, |
| 4276 | 4251 | uav: InternPool.Key.Ptr.BaseAddr.Uav, |
| 4277 | 4252 | ) Error!Builder.Constant { |
| 4278 | | const pt = o.pt; |
| 4279 | 4253 | const zcu = pt.zcu; |
| 4280 | 4254 | const ip = &zcu.intern_pool; |
| 4281 | 4255 | const uav_val = uav.val; |
| ... | ... | @@ -4292,25 +4266,24 @@ pub const Object = struct { |
| 4292 | 4266 | |
| 4293 | 4267 | const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn"; |
| 4294 | 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 | 4271 | if (is_fn_body) |
| 4298 | 4272 | @panic("TODO"); |
| 4299 | 4273 | |
| 4300 | 4274 | const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target); |
| 4301 | 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 | 4278 | const llvm_val = try o.builder.convConst( |
| 4305 | 4279 | llvm_global.toConst(), |
| 4306 | 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 { |
| 4313 | | const pt = o.pt; |
| 4286 | fn lowerNavRefValue(o: *Object, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant { |
| 4314 | 4287 | const zcu = pt.zcu; |
| 4315 | 4288 | const ip = &zcu.intern_pool; |
| 4316 | 4289 | |
| ... | ... | @@ -4323,24 +4296,24 @@ pub const Object = struct { |
| 4323 | 4296 | if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or |
| 4324 | 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 | 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 | 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 | 4307 | const llvm_val = try o.builder.convConst( |
| 4335 | 4308 | llvm_global.toConst(), |
| 4336 | 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 { |
| 4343 | | const zcu = o.pt.zcu; |
| 4315 | fn lowerPtrToVoid(o: *Object, pt: Zcu.PerThread, ptr_ty: Type) Allocator.Error!Builder.Constant { |
| 4316 | const zcu = pt.zcu; |
| 4344 | 4317 | // Even though we are pointing at something which has zero bits (e.g. `void`), |
| 4345 | 4318 | // Pointers are defined to have bits. So we must return something here. |
| 4346 | 4319 | // The value cannot be undefined, because we use the `nonnull` annotation |
| ... | ... | @@ -4358,8 +4331,8 @@ pub const Object = struct { |
| 4358 | 4331 | 64 => 0xaaaaaaaa_aaaaaaaa, |
| 4359 | 4332 | else => unreachable, |
| 4360 | 4333 | }; |
| 4361 | | const llvm_usize = try o.lowerType(Type.usize); |
| 4362 | | const llvm_ptr_ty = try o.lowerType(ptr_ty); |
| 4334 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 4335 | const llvm_ptr_ty = try o.lowerType(pt, ptr_ty); |
| 4363 | 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 | 4340 | /// widen it before using it and then truncate the result. |
| 4368 | 4341 | /// RMW exchange of floating-point values is bitcasted to same-sized integer |
| 4369 | 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 { |
| 4371 | | const pt = o.pt; |
| 4343 | fn getAtomicAbiType(o: *Object, pt: Zcu.PerThread, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type { |
| 4372 | 4344 | const zcu = pt.zcu; |
| 4373 | 4345 | const int_ty = switch (ty.zigTypeTag(zcu)) { |
| 4374 | 4346 | .int => ty, |
| ... | ... | @@ -4390,13 +4362,13 @@ pub const Object = struct { |
| 4390 | 4362 | |
| 4391 | 4363 | fn addByValParamAttrs( |
| 4392 | 4364 | o: *Object, |
| 4365 | pt: Zcu.PerThread, |
| 4393 | 4366 | attributes: *Builder.FunctionAttributes.Wip, |
| 4394 | 4367 | param_ty: Type, |
| 4395 | 4368 | param_index: u32, |
| 4396 | 4369 | fn_info: InternPool.Key.FuncType, |
| 4397 | 4370 | llvm_arg_i: u32, |
| 4398 | 4371 | ) Allocator.Error!void { |
| 4399 | | const pt = o.pt; |
| 4400 | 4372 | const zcu = pt.zcu; |
| 4401 | 4373 | if (param_ty.isPtrAtRuntime(zcu)) { |
| 4402 | 4374 | const ptr_info = param_ty.ptrInfo(zcu); |
| ... | ... | @@ -4416,7 +4388,7 @@ pub const Object = struct { |
| 4416 | 4388 | .x86_64_interrupt, |
| 4417 | 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 | 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 | 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 | 4431 | const name = try o.builder.strtabString(lt_errors_fn_name); |
| 4460 | 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 | 4435 | const target = &zcu.root_mod.resolved_target.result; |
| 4464 | 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 | 4438 | name, |
| 4467 | 4439 | toLlvmAddressSpace(.generic, target), |
| 4468 | 4440 | ); |
| ... | ... | @@ -4477,8 +4449,7 @@ pub const Object = struct { |
| 4477 | 4449 | return function_index; |
| 4478 | 4450 | } |
| 4479 | 4451 | |
| 4480 | | fn getEnumTagNameFunction(o: *Object, enum_ty: Type) !Builder.Function.Index { |
| 4481 | | const pt = o.pt; |
| 4452 | fn getEnumTagNameFunction(o: *Object, pt: Zcu.PerThread, enum_ty: Type) !Builder.Function.Index { |
| 4482 | 4453 | const zcu = pt.zcu; |
| 4483 | 4454 | const ip = &zcu.intern_pool; |
| 4484 | 4455 | const enum_type = ip.loadEnumType(enum_ty.toIntern()); |
| ... | ... | @@ -4487,11 +4458,11 @@ pub const Object = struct { |
| 4487 | 4458 | if (gop.found_existing) return gop.value_ptr.ptrConst(&o.builder).kind.function; |
| 4488 | 4459 | errdefer assert(o.enum_tag_name_map.remove(enum_ty.toIntern())); |
| 4489 | 4460 | |
| 4490 | | const usize_ty = try o.lowerType(Type.usize); |
| 4491 | | const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0); |
| 4461 | const usize_ty = try o.lowerType(pt, Type.usize); |
| 4462 | const ret_ty = try o.lowerType(pt, Type.slice_const_u8_sentinel_0); |
| 4492 | 4463 | const target = &zcu.root_mod.resolved_target.result; |
| 4493 | 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 | 4466 | try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_type.name.fmt(ip)}), |
| 4496 | 4467 | toLlvmAddressSpace(.generic, target), |
| 4497 | 4468 | ); |
| ... | ... | @@ -4536,6 +4507,7 @@ pub const Object = struct { |
| 4536 | 4507 | |
| 4537 | 4508 | const return_block = try wip.block(1, "Name"); |
| 4538 | 4509 | const this_tag_int_value = try o.lowerValue( |
| 4510 | pt, |
| 4539 | 4511 | (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(), |
| 4540 | 4512 | ); |
| 4541 | 4513 | try wip_switch.addCase(this_tag_int_value, return_block, &wip); |
| ... | ... | @@ -4555,10 +4527,11 @@ pub const Object = struct { |
| 4555 | 4527 | pub const NavGen = struct { |
| 4556 | 4528 | object: *Object, |
| 4557 | 4529 | nav_index: InternPool.Nav.Index, |
| 4530 | pt: Zcu.PerThread, |
| 4558 | 4531 | err_msg: ?*Zcu.ErrorMsg, |
| 4559 | 4532 | |
| 4560 | 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 | 4537 | fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error { |
| ... | ... | @@ -4566,14 +4539,14 @@ pub const NavGen = struct { |
| 4566 | 4539 | assert(ng.err_msg == null); |
| 4567 | 4540 | const o = ng.object; |
| 4568 | 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 | 4543 | ng.err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args); |
| 4571 | 4544 | return error.CodegenFail; |
| 4572 | 4545 | } |
| 4573 | 4546 | |
| 4574 | 4547 | fn genDecl(ng: *NavGen) !void { |
| 4575 | 4548 | const o = ng.object; |
| 4576 | | const pt = o.pt; |
| 4549 | const pt = ng.pt; |
| 4577 | 4550 | const zcu = pt.zcu; |
| 4578 | 4551 | const ip = &zcu.intern_pool; |
| 4579 | 4552 | const nav_index = ng.nav_index; |
| ... | ... | @@ -4588,16 +4561,16 @@ pub const NavGen = struct { |
| 4588 | 4561 | const ty = Type.fromInterned(nav.typeOf(ip)); |
| 4589 | 4562 | |
| 4590 | 4563 | if (linkage != .internal and ip.isFunctionType(ty.toIntern())) { |
| 4591 | | _ = try o.resolveLlvmFunction(owner_nav); |
| 4564 | _ = try o.resolveLlvmFunction(pt, owner_nav); |
| 4592 | 4565 | } else { |
| 4593 | | const variable_index = try o.resolveGlobalNav(nav_index); |
| 4566 | const variable_index = try o.resolveGlobalNav(pt, nav_index); |
| 4594 | 4567 | variable_index.setAlignment(pt.navAlignment(nav_index).toLlvm(), &o.builder); |
| 4595 | 4568 | if (resolved.@"linksection".toSlice(ip)) |section| |
| 4596 | 4569 | variable_index.setSection(try o.builder.string(section), &o.builder); |
| 4597 | 4570 | if (is_const) variable_index.setMutability(.constant, &o.builder); |
| 4598 | 4571 | try variable_index.setInitializer(switch (init_val) { |
| 4599 | 4572 | .none => .no_init, |
| 4600 | | else => try o.lowerValue(init_val), |
| 4573 | else => try o.lowerValue(pt, init_val), |
| 4601 | 4574 | }, &o.builder); |
| 4602 | 4575 | variable_index.setVisibility(visibility, &o.builder); |
| 4603 | 4576 | |
| ... | ... | @@ -4609,7 +4582,7 @@ pub const NavGen = struct { |
| 4609 | 4582 | const line_number = zcu.navSrcLine(nav_index) + 1; |
| 4610 | 4583 | |
| 4611 | 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 | 4587 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4615 | 4588 | try o.builder.metadataString(nav.name.toSlice(ip)), // Name |
| ... | ... | @@ -4617,7 +4590,7 @@ pub const NavGen = struct { |
| 4617 | 4590 | debug_file, // File |
| 4618 | 4591 | debug_file, // Scope |
| 4619 | 4592 | line_number, |
| 4620 | | try o.lowerDebugType(ty), |
| 4593 | try o.lowerDebugType(pt, ty), |
| 4621 | 4594 | variable_index, |
| 4622 | 4595 | .{ .local = linkage == .internal }, |
| 4623 | 4596 | ); |
| ... | ... | @@ -4814,16 +4787,17 @@ pub const FuncGen = struct { |
| 4814 | 4787 | const gop = try self.func_inst_table.getOrPut(gpa, inst); |
| 4815 | 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 | 4791 | gop.value_ptr.* = llvm_val.toValue(); |
| 4819 | 4792 | return llvm_val.toValue(); |
| 4820 | 4793 | } |
| 4821 | 4794 | |
| 4822 | 4795 | fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant { |
| 4823 | 4796 | const o = self.ng.object; |
| 4824 | | const zcu = o.pt.zcu; |
| 4797 | const pt = self.ng.pt; |
| 4798 | const zcu = pt.zcu; |
| 4825 | 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 | 4801 | if (!isByRef(ty, zcu)) return llvm_val; |
| 4828 | 4802 | |
| 4829 | 4803 | // We have an LLVM value but we need to create a global constant and |
| ... | ... | @@ -4847,7 +4821,7 @@ pub const FuncGen = struct { |
| 4847 | 4821 | |
| 4848 | 4822 | fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) Error!void { |
| 4849 | 4823 | const o = self.ng.object; |
| 4850 | | const zcu = o.pt.zcu; |
| 4824 | const zcu = self.ng.pt.zcu; |
| 4851 | 4825 | const ip = &zcu.intern_pool; |
| 4852 | 4826 | const air_tags = self.air.instructions.items(.tag); |
| 4853 | 4827 | switch (coverage_point) { |
| ... | ... | @@ -5173,7 +5147,7 @@ pub const FuncGen = struct { |
| 5173 | 5147 | |
| 5174 | 5148 | if (maybe_inline_func) |inline_func| { |
| 5175 | 5149 | const o = self.ng.object; |
| 5176 | | const pt = o.pt; |
| 5150 | const pt = self.ng.pt; |
| 5177 | 5151 | const zcu = pt.zcu; |
| 5178 | 5152 | const ip = &zcu.intern_pool; |
| 5179 | 5153 | |
| ... | ... | @@ -5182,7 +5156,7 @@ pub const FuncGen = struct { |
| 5182 | 5156 | const file_scope = zcu.navFileScopeIndex(func.owner_nav); |
| 5183 | 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 | 5161 | const line_number = zcu.navSrcLine(func.owner_nav) + 1; |
| 5188 | 5162 | self.inlined = self.wip.debug_location; |
| ... | ... | @@ -5198,7 +5172,7 @@ pub const FuncGen = struct { |
| 5198 | 5172 | try o.builder.metadataString(nav.fqn.toSlice(&zcu.intern_pool)), |
| 5199 | 5173 | line_number, |
| 5200 | 5174 | line_number + func.lbrace_line, |
| 5201 | | try o.lowerDebugType(fn_ty), |
| 5175 | try o.lowerDebugType(pt, fn_ty), |
| 5202 | 5176 | .{ |
| 5203 | 5177 | .di_flags = .{ .StaticMember = true }, |
| 5204 | 5178 | .sp_flags = .{ |
| ... | ... | @@ -5255,7 +5229,7 @@ pub const FuncGen = struct { |
| 5255 | 5229 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 5256 | 5230 | const args: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[extra.end..][0..extra.data.args_len]); |
| 5257 | 5231 | const o = self.ng.object; |
| 5258 | | const pt = o.pt; |
| 5232 | const pt = self.ng.pt; |
| 5259 | 5233 | const zcu = pt.zcu; |
| 5260 | 5234 | const ip = &zcu.intern_pool; |
| 5261 | 5235 | const callee_ty = self.typeOf(pl_op.operand); |
| ... | ... | @@ -5287,7 +5261,7 @@ pub const FuncGen = struct { |
| 5287 | 5261 | } |
| 5288 | 5262 | |
| 5289 | 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 | 5265 | try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder); |
| 5292 | 5266 | |
| 5293 | 5267 | const alignment = return_type.abiAlignment(zcu).toLlvm(); |
| ... | ... | @@ -5302,14 +5276,14 @@ pub const FuncGen = struct { |
| 5302 | 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 | 5280 | while (try it.nextCall(self, args)) |lowering| switch (lowering) { |
| 5307 | 5281 | .no_bits => continue, |
| 5308 | 5282 | .byval => { |
| 5309 | 5283 | const arg = args[it.zig_index - 1]; |
| 5310 | 5284 | const param_ty = self.typeOf(arg); |
| 5311 | 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 | 5287 | if (isByRef(param_ty, zcu)) { |
| 5314 | 5288 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 5315 | 5289 | const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, ""); |
| ... | ... | @@ -5338,7 +5312,7 @@ pub const FuncGen = struct { |
| 5338 | 5312 | const llvm_arg = try self.resolveInst(arg); |
| 5339 | 5313 | |
| 5340 | 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 | 5316 | const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment); |
| 5343 | 5317 | if (isByRef(param_ty, zcu)) { |
| 5344 | 5318 | const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, ""); |
| ... | ... | @@ -5409,7 +5383,7 @@ pub const FuncGen = struct { |
| 5409 | 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 | 5387 | const array_ty = try o.builder.arrayType(count, float_ty); |
| 5414 | 5388 | |
| 5415 | 5389 | const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, ""); |
| ... | ... | @@ -5436,7 +5410,7 @@ pub const FuncGen = struct { |
| 5436 | 5410 | |
| 5437 | 5411 | { |
| 5438 | 5412 | // Add argument attributes. |
| 5439 | | it = iterateParamTypes(o, fn_info); |
| 5413 | it = iterateParamTypes(o, pt, fn_info); |
| 5440 | 5414 | it.llvm_index += @intFromBool(sret); |
| 5441 | 5415 | it.llvm_index += @intFromBool(err_return_tracing); |
| 5442 | 5416 | while (try it.next()) |lowering| switch (lowering) { |
| ... | ... | @@ -5444,13 +5418,13 @@ pub const FuncGen = struct { |
| 5444 | 5418 | const param_index = it.zig_index - 1; |
| 5445 | 5419 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); |
| 5446 | 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 | 5424 | .byref => { |
| 5451 | 5425 | const param_index = it.zig_index - 1; |
| 5452 | 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 | 5428 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 5455 | 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 | 5476 | }, |
| 5503 | 5477 | toLlvmCallConvTag(fn_info.cc, target).?, |
| 5504 | 5478 | try attributes.finish(&o.builder), |
| 5505 | | try o.lowerType(zig_fn_ty), |
| 5479 | try o.lowerType(pt, zig_fn_ty), |
| 5506 | 5480 | llvm_fn, |
| 5507 | 5481 | llvm_args.items, |
| 5508 | 5482 | "", |
| ... | ... | @@ -5516,7 +5490,7 @@ pub const FuncGen = struct { |
| 5516 | 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 | 5494 | if (ret_ptr) |rp| { |
| 5521 | 5495 | if (isByRef(return_type, zcu)) { |
| 5522 | 5496 | return rp; |
| ... | ... | @@ -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 | 5506 | if (abi_ret_ty != llvm_ret_ty) { |
| 5533 | 5507 | // In this case the function return type is honoring the calling convention by having |
| ... | ... | @@ -5556,11 +5530,12 @@ pub const FuncGen = struct { |
| 5556 | 5530 | |
| 5557 | 5531 | fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) !void { |
| 5558 | 5532 | const o = fg.ng.object; |
| 5559 | | const zcu = o.pt.zcu; |
| 5533 | const pt = fg.ng.pt; |
| 5534 | const zcu = pt.zcu; |
| 5560 | 5535 | const target = zcu.getTarget(); |
| 5561 | 5536 | const panic_func = zcu.funcInfo(zcu.builtin_decl_values.get(panic_id.toBuiltin())); |
| 5562 | 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 | 5540 | const has_err_trace = zcu.comp.config.any_error_tracing and fn_info.cc == .auto; |
| 5566 | 5541 | if (has_err_trace) assert(fg.err_ret_trace != .none); |
| ... | ... | @@ -5579,7 +5554,7 @@ pub const FuncGen = struct { |
| 5579 | 5554 | |
| 5580 | 5555 | fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !void { |
| 5581 | 5556 | const o = self.ng.object; |
| 5582 | | const pt = o.pt; |
| 5557 | const pt = self.ng.pt; |
| 5583 | 5558 | const zcu = pt.zcu; |
| 5584 | 5559 | const ip = &zcu.intern_pool; |
| 5585 | 5560 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| ... | ... | @@ -5599,7 +5574,7 @@ pub const FuncGen = struct { |
| 5599 | 5574 | // https://github.com/ziglang/zig/issues/15337 |
| 5600 | 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 | 5578 | _ = try self.wip.callMemSet( |
| 5604 | 5579 | self.ret_ptr, |
| 5605 | 5580 | ptr_ty.ptrAlignment(zcu).toLlvm(), |
| ... | ... | @@ -5635,14 +5610,14 @@ pub const FuncGen = struct { |
| 5635 | 5610 | // Functions with an empty error set are emitted with an error code |
| 5636 | 5611 | // return type and return zero so they can be function pointers coerced |
| 5637 | 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 | 5614 | } else { |
| 5640 | 5615 | _ = try self.wip.retVoid(); |
| 5641 | 5616 | } |
| 5642 | 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 | 5621 | const operand = try self.resolveInst(un_op); |
| 5647 | 5622 | const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false; |
| 5648 | 5623 | const alignment = ret_ty.abiAlignment(zcu).toLlvm(); |
| ... | ... | @@ -5650,7 +5625,7 @@ pub const FuncGen = struct { |
| 5650 | 5625 | if (val_is_undef and safety) { |
| 5651 | 5626 | const llvm_ret_ty = operand.typeOfWip(&self.wip); |
| 5652 | 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 | 5629 | _ = try self.wip.callMemSet( |
| 5655 | 5630 | rp, |
| 5656 | 5631 | alignment, |
| ... | ... | @@ -5688,7 +5663,7 @@ pub const FuncGen = struct { |
| 5688 | 5663 | |
| 5689 | 5664 | fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !void { |
| 5690 | 5665 | const o = self.ng.object; |
| 5691 | | const pt = o.pt; |
| 5666 | const pt = self.ng.pt; |
| 5692 | 5667 | const zcu = pt.zcu; |
| 5693 | 5668 | const ip = &zcu.intern_pool; |
| 5694 | 5669 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| ... | ... | @@ -5700,7 +5675,7 @@ pub const FuncGen = struct { |
| 5700 | 5675 | // Functions with an empty error set are emitted with an error code |
| 5701 | 5676 | // return type and return zero so they can be function pointers coerced |
| 5702 | 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 | 5679 | } else { |
| 5705 | 5680 | _ = try self.wip.retVoid(); |
| 5706 | 5681 | } |
| ... | ... | @@ -5711,7 +5686,7 @@ pub const FuncGen = struct { |
| 5711 | 5686 | return; |
| 5712 | 5687 | } |
| 5713 | 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 | 5690 | const alignment = ret_ty.abiAlignment(zcu).toLlvm(); |
| 5716 | 5691 | _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, "")); |
| 5717 | 5692 | return; |
| ... | ... | @@ -5719,22 +5694,23 @@ pub const FuncGen = struct { |
| 5719 | 5694 | |
| 5720 | 5695 | fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5721 | 5696 | const o = self.ng.object; |
| 5697 | const pt = self.ng.pt; |
| 5722 | 5698 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5723 | 5699 | const list = try self.resolveInst(ty_op.operand); |
| 5724 | 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 | 5703 | return self.wip.vaArg(list, llvm_arg_ty, ""); |
| 5728 | 5704 | } |
| 5729 | 5705 | |
| 5730 | 5706 | fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5731 | 5707 | const o = self.ng.object; |
| 5732 | | const pt = o.pt; |
| 5708 | const pt = self.ng.pt; |
| 5733 | 5709 | const zcu = pt.zcu; |
| 5734 | 5710 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5735 | 5711 | const src_list = try self.resolveInst(ty_op.operand); |
| 5736 | 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 | 5715 | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); |
| 5740 | 5716 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| ... | ... | @@ -5756,10 +5732,10 @@ pub const FuncGen = struct { |
| 5756 | 5732 | |
| 5757 | 5733 | fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5758 | 5734 | const o = self.ng.object; |
| 5759 | | const pt = o.pt; |
| 5735 | const pt = self.ng.pt; |
| 5760 | 5736 | const zcu = pt.zcu; |
| 5761 | 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 | 5740 | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); |
| 5765 | 5741 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| ... | ... | @@ -5799,9 +5775,10 @@ pub const FuncGen = struct { |
| 5799 | 5775 | |
| 5800 | 5776 | fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5801 | 5777 | const o = self.ng.object; |
| 5778 | const pt = self.ng.pt; |
| 5802 | 5779 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5803 | 5780 | const operand = try self.resolveInst(un_op); |
| 5804 | | const llvm_fn = try o.getCmpLtErrorsLenFunction(); |
| 5781 | const llvm_fn = try o.getCmpLtErrorsLenFunction(pt); |
| 5805 | 5782 | return self.wip.call( |
| 5806 | 5783 | .normal, |
| 5807 | 5784 | .fastcc, |
| ... | ... | @@ -5822,7 +5799,7 @@ pub const FuncGen = struct { |
| 5822 | 5799 | rhs: Builder.Value, |
| 5823 | 5800 | ) Allocator.Error!Builder.Value { |
| 5824 | 5801 | const o = self.ng.object; |
| 5825 | | const pt = o.pt; |
| 5802 | const pt = self.ng.pt; |
| 5826 | 5803 | const zcu = pt.zcu; |
| 5827 | 5804 | const ip = &zcu.intern_pool; |
| 5828 | 5805 | const scalar_ty = operand_ty.scalarType(zcu); |
| ... | ... | @@ -5839,7 +5816,7 @@ pub const FuncGen = struct { |
| 5839 | 5816 | // We need to emit instructions to check for equality/inequality |
| 5840 | 5817 | // of optionals that are not pointers. |
| 5841 | 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 | 5820 | const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref, .normal); |
| 5844 | 5821 | const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref, .normal); |
| 5845 | 5822 | const llvm_i2 = try o.builder.intType(2); |
| ... | ... | @@ -5936,7 +5913,7 @@ pub const FuncGen = struct { |
| 5936 | 5913 | body: []const Air.Inst.Index, |
| 5937 | 5914 | ) !Builder.Value { |
| 5938 | 5915 | const o = self.ng.object; |
| 5939 | | const pt = o.pt; |
| 5916 | const pt = self.ng.pt; |
| 5940 | 5917 | const zcu = pt.zcu; |
| 5941 | 5918 | const inst_ty = self.typeOfIndex(inst); |
| 5942 | 5919 | |
| ... | ... | @@ -5963,7 +5940,7 @@ pub const FuncGen = struct { |
| 5963 | 5940 | |
| 5964 | 5941 | // Create a phi node only if the block returns a value. |
| 5965 | 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 | 5944 | const llvm_ty: Builder.Type = ty: { |
| 5968 | 5945 | // If the zig tag type is a function, this represents an actual function body; not |
| 5969 | 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 | 5963 | } |
| 5987 | 5964 | |
| 5988 | 5965 | fn airBr(self: *FuncGen, inst: Air.Inst.Index) !void { |
| 5989 | | const o = self.ng.object; |
| 5990 | | const zcu = o.pt.zcu; |
| 5966 | const zcu = self.ng.pt.zcu; |
| 5991 | 5967 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; |
| 5992 | 5968 | const block = self.blocks.get(branch.block_inst).?; |
| 5993 | 5969 | |
| ... | ... | @@ -6017,7 +5993,7 @@ pub const FuncGen = struct { |
| 6017 | 5993 | dispatch_info: SwitchDispatchInfo, |
| 6018 | 5994 | ) !void { |
| 6019 | 5995 | const o = self.ng.object; |
| 6020 | | const pt = o.pt; |
| 5996 | const pt = self.ng.pt; |
| 6021 | 5997 | const zcu = pt.zcu; |
| 6022 | 5998 | const cond_ty = self.typeOf(cond_ref); |
| 6023 | 5999 | const switch_br = self.air.unwrapSwitch(switch_inst); |
| ... | ... | @@ -6081,7 +6057,7 @@ pub const FuncGen = struct { |
| 6081 | 6057 | const table_index = try self.wip.cast( |
| 6082 | 6058 | .zext, |
| 6083 | 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 | 6063 | const target_ptr_ptr = try self.wip.gep( |
| ... | ... | @@ -6108,7 +6084,7 @@ pub const FuncGen = struct { |
| 6108 | 6084 | // The switch prongs will correspond to our scalar cases. Ranges will |
| 6109 | 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 | 6088 | const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder)) |
| 6113 | 6089 | try self.wip.cast(.ptrtoint, cond, llvm_usize, "") |
| 6114 | 6090 | else |
| ... | ... | @@ -6268,8 +6244,7 @@ pub const FuncGen = struct { |
| 6268 | 6244 | } |
| 6269 | 6245 | |
| 6270 | 6246 | fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index, err_cold: bool) !Builder.Value { |
| 6271 | | const o = self.ng.object; |
| 6272 | | const pt = o.pt; |
| 6247 | const pt = self.ng.pt; |
| 6273 | 6248 | const zcu = pt.zcu; |
| 6274 | 6249 | const inst = body_tail[0]; |
| 6275 | 6250 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| ... | ... | @@ -6284,8 +6259,7 @@ pub const FuncGen = struct { |
| 6284 | 6259 | } |
| 6285 | 6260 | |
| 6286 | 6261 | fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) !Builder.Value { |
| 6287 | | const o = self.ng.object; |
| 6288 | | const zcu = o.pt.zcu; |
| 6262 | const zcu = self.ng.pt.zcu; |
| 6289 | 6263 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 6290 | 6264 | const extra = self.air.extraData(Air.TryPtr, ty_pl.payload); |
| 6291 | 6265 | const err_union_ptr = try self.resolveInst(extra.data.ptr); |
| ... | ... | @@ -6309,12 +6283,12 @@ pub const FuncGen = struct { |
| 6309 | 6283 | err_cold: bool, |
| 6310 | 6284 | ) !Builder.Value { |
| 6311 | 6285 | const o = fg.ng.object; |
| 6312 | | const pt = o.pt; |
| 6286 | const pt = fg.ng.pt; |
| 6313 | 6287 | const zcu = pt.zcu; |
| 6314 | 6288 | const payload_ty = err_union_ty.errorUnionPayload(zcu); |
| 6315 | 6289 | const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu); |
| 6316 | | const err_union_llvm_ty = try o.lowerType(err_union_ty); |
| 6317 | | const error_type = try o.errorIntType(); |
| 6290 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 6291 | const error_type = try o.errorIntType(pt); |
| 6318 | 6292 | |
| 6319 | 6293 | if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) { |
| 6320 | 6294 | const loaded = loaded: { |
| ... | ... | @@ -6378,7 +6352,8 @@ pub const FuncGen = struct { |
| 6378 | 6352 | |
| 6379 | 6353 | fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) !void { |
| 6380 | 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 | 6358 | const switch_br = self.air.unwrapSwitch(inst); |
| 6384 | 6359 | |
| ... | ... | @@ -6483,8 +6458,8 @@ pub const FuncGen = struct { |
| 6483 | 6458 | const table_includes_else = item_count != table_len; |
| 6484 | 6459 | |
| 6485 | 6460 | break :jmp_table .{ |
| 6486 | | .min = try o.lowerValue(min.toIntern()), |
| 6487 | | .max = try o.lowerValue(max.toIntern()), |
| 6461 | .min = try o.lowerValue(pt, min.toIntern()), |
| 6462 | .max = try o.lowerValue(pt, max.toIntern()), |
| 6488 | 6463 | .in_bounds_hint = if (table_includes_else) .none else switch (switch_br.getElseHint()) { |
| 6489 | 6464 | .none, .cold => .none, |
| 6490 | 6465 | .unpredictable => .unpredictable, |
| ... | ... | @@ -6591,7 +6566,7 @@ pub const FuncGen = struct { |
| 6591 | 6566 | } |
| 6592 | 6567 | |
| 6593 | 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 | 6570 | var it = switch_br.iterateCases(); |
| 6596 | 6571 | var min: ?Value = null; |
| 6597 | 6572 | var max: ?Value = null; |
| ... | ... | @@ -6633,18 +6608,18 @@ pub const FuncGen = struct { |
| 6633 | 6608 | |
| 6634 | 6609 | fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6635 | 6610 | const o = self.ng.object; |
| 6636 | | const pt = o.pt; |
| 6611 | const pt = self.ng.pt; |
| 6637 | 6612 | const zcu = pt.zcu; |
| 6638 | 6613 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6639 | 6614 | const operand_ty = self.typeOf(ty_op.operand); |
| 6640 | 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 | 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 | 6619 | const operand = try self.resolveInst(ty_op.operand); |
| 6645 | 6620 | if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu)) |
| 6646 | 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 | 6623 | try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0), |
| 6649 | 6624 | }, ""); |
| 6650 | 6625 | return self.wip.buildAggregate(slice_llvm_ty, &.{ ptr, len }, ""); |
| ... | ... | @@ -6652,7 +6627,7 @@ pub const FuncGen = struct { |
| 6652 | 6627 | |
| 6653 | 6628 | fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6654 | 6629 | const o = self.ng.object; |
| 6655 | | const pt = o.pt; |
| 6630 | const pt = self.ng.pt; |
| 6656 | 6631 | const zcu = pt.zcu; |
| 6657 | 6632 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6658 | 6633 | |
| ... | ... | @@ -6663,7 +6638,7 @@ pub const FuncGen = struct { |
| 6663 | 6638 | |
| 6664 | 6639 | const dest_ty = self.typeOfIndex(inst); |
| 6665 | 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 | 6642 | const target = zcu.getTarget(); |
| 6668 | 6643 | |
| 6669 | 6644 | if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv( |
| ... | ... | @@ -6719,7 +6694,7 @@ pub const FuncGen = struct { |
| 6719 | 6694 | _ = fast; |
| 6720 | 6695 | |
| 6721 | 6696 | const o = self.ng.object; |
| 6722 | | const pt = o.pt; |
| 6697 | const pt = self.ng.pt; |
| 6723 | 6698 | const zcu = pt.zcu; |
| 6724 | 6699 | const target = zcu.getTarget(); |
| 6725 | 6700 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -6730,7 +6705,7 @@ pub const FuncGen = struct { |
| 6730 | 6705 | |
| 6731 | 6706 | const dest_ty = self.typeOfIndex(inst); |
| 6732 | 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 | 6710 | if (intrinsicsAllowed(operand_scalar_ty, target)) { |
| 6736 | 6711 | // TODO set fast math flag |
| ... | ... | @@ -6762,7 +6737,7 @@ pub const FuncGen = struct { |
| 6762 | 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 | 6741 | const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty); |
| 6767 | 6742 | var result = try self.wip.call( |
| 6768 | 6743 | .normal, |
| ... | ... | @@ -6780,16 +6755,15 @@ pub const FuncGen = struct { |
| 6780 | 6755 | } |
| 6781 | 6756 | |
| 6782 | 6757 | fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { |
| 6783 | | const o = fg.ng.object; |
| 6784 | | const zcu = o.pt.zcu; |
| 6758 | const zcu = fg.ng.pt.zcu; |
| 6785 | 6759 | return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr; |
| 6786 | 6760 | } |
| 6787 | 6761 | |
| 6788 | 6762 | fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { |
| 6789 | 6763 | const o = fg.ng.object; |
| 6790 | | const pt = o.pt; |
| 6764 | const pt = fg.ng.pt; |
| 6791 | 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 | 6767 | switch (ty.ptrSize(zcu)) { |
| 6794 | 6768 | .slice => { |
| 6795 | 6769 | const len = try fg.wip.extractValue(ptr, &.{1}, ""); |
| ... | ... | @@ -6817,18 +6791,19 @@ pub const FuncGen = struct { |
| 6817 | 6791 | |
| 6818 | 6792 | fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value { |
| 6819 | 6793 | const o = self.ng.object; |
| 6820 | | const zcu = o.pt.zcu; |
| 6794 | const pt = self.ng.pt; |
| 6795 | const zcu = pt.zcu; |
| 6821 | 6796 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6822 | 6797 | const slice_ptr = try self.resolveInst(ty_op.operand); |
| 6823 | 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 | 6801 | return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, ""); |
| 6827 | 6802 | } |
| 6828 | 6803 | |
| 6829 | 6804 | fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6830 | 6805 | const o = self.ng.object; |
| 6831 | | const pt = o.pt; |
| 6806 | const pt = self.ng.pt; |
| 6832 | 6807 | const zcu = pt.zcu; |
| 6833 | 6808 | const inst = body_tail[0]; |
| 6834 | 6809 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| ... | ... | @@ -6836,7 +6811,7 @@ pub const FuncGen = struct { |
| 6836 | 6811 | const slice = try self.resolveInst(bin_op.lhs); |
| 6837 | 6812 | const index = try self.resolveInst(bin_op.rhs); |
| 6838 | 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 | 6815 | const base_ptr = try self.wip.extractValue(slice, &.{0}, ""); |
| 6841 | 6816 | const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, ""); |
| 6842 | 6817 | if (isByRef(elem_ty, zcu)) { |
| ... | ... | @@ -6856,21 +6831,22 @@ pub const FuncGen = struct { |
| 6856 | 6831 | |
| 6857 | 6832 | fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6858 | 6833 | const o = self.ng.object; |
| 6859 | | const zcu = o.pt.zcu; |
| 6834 | const pt = self.ng.pt; |
| 6835 | const zcu = pt.zcu; |
| 6860 | 6836 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 6861 | 6837 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6862 | 6838 | const slice_ty = self.typeOf(bin_op.lhs); |
| 6863 | 6839 | |
| 6864 | 6840 | const slice = try self.resolveInst(bin_op.lhs); |
| 6865 | 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 | 6843 | const base_ptr = try self.wip.extractValue(slice, &.{0}, ""); |
| 6868 | 6844 | return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, ""); |
| 6869 | 6845 | } |
| 6870 | 6846 | |
| 6871 | 6847 | fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6872 | 6848 | const o = self.ng.object; |
| 6873 | | const pt = o.pt; |
| 6849 | const pt = self.ng.pt; |
| 6874 | 6850 | const zcu = pt.zcu; |
| 6875 | 6851 | const inst = body_tail[0]; |
| 6876 | 6852 | |
| ... | ... | @@ -6878,11 +6854,11 @@ pub const FuncGen = struct { |
| 6878 | 6854 | const array_ty = self.typeOf(bin_op.lhs); |
| 6879 | 6855 | const array_llvm_val = try self.resolveInst(bin_op.lhs); |
| 6880 | 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 | 6858 | const elem_ty = array_ty.childType(zcu); |
| 6883 | 6859 | if (isByRef(array_ty, zcu)) { |
| 6884 | 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 | 6863 | if (isByRef(elem_ty, zcu)) { |
| 6888 | 6864 | const elem_ptr = |
| ... | ... | @@ -6903,19 +6879,19 @@ pub const FuncGen = struct { |
| 6903 | 6879 | |
| 6904 | 6880 | fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6905 | 6881 | const o = self.ng.object; |
| 6906 | | const pt = o.pt; |
| 6882 | const pt = self.ng.pt; |
| 6907 | 6883 | const zcu = pt.zcu; |
| 6908 | 6884 | const inst = body_tail[0]; |
| 6909 | 6885 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 6910 | 6886 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 6911 | 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 | 6889 | const base_ptr = try self.resolveInst(bin_op.lhs); |
| 6914 | 6890 | const rhs = try self.resolveInst(bin_op.rhs); |
| 6915 | 6891 | // TODO: when we go fully opaque pointers in LLVM 16 we can remove this branch |
| 6916 | 6892 | const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu)) |
| 6917 | 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 | 6895 | else |
| 6920 | 6896 | &.{rhs}, ""); |
| 6921 | 6897 | if (isByRef(elem_ty, zcu)) { |
| ... | ... | @@ -6934,7 +6910,7 @@ pub const FuncGen = struct { |
| 6934 | 6910 | |
| 6935 | 6911 | fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6936 | 6912 | const o = self.ng.object; |
| 6937 | | const pt = o.pt; |
| 6913 | const pt = self.ng.pt; |
| 6938 | 6914 | const zcu = pt.zcu; |
| 6939 | 6915 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 6940 | 6916 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | ... | @@ -6948,10 +6924,10 @@ pub const FuncGen = struct { |
| 6948 | 6924 | const elem_ptr = ty_pl.ty.toType(); |
| 6949 | 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 | 6928 | return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu)) |
| 6953 | 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 | 6931 | else |
| 6956 | 6932 | &.{rhs}, ""); |
| 6957 | 6933 | } |
| ... | ... | @@ -6977,7 +6953,7 @@ pub const FuncGen = struct { |
| 6977 | 6953 | |
| 6978 | 6954 | fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6979 | 6955 | const o = self.ng.object; |
| 6980 | | const pt = o.pt; |
| 6956 | const pt = self.ng.pt; |
| 6981 | 6957 | const zcu = pt.zcu; |
| 6982 | 6958 | const inst = body_tail[0]; |
| 6983 | 6959 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| ... | ... | @@ -6999,7 +6975,7 @@ pub const FuncGen = struct { |
| 6999 | 6975 | const shift_amt = |
| 7000 | 6976 | try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset); |
| 7001 | 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 | 6979 | if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) { |
| 7004 | 6980 | const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu))); |
| 7005 | 6981 | const truncated_int = |
| ... | ... | @@ -7021,7 +6997,7 @@ pub const FuncGen = struct { |
| 7021 | 6997 | .@"union" => { |
| 7022 | 6998 | assert(struct_ty.containerLayout(zcu) == .@"packed"); |
| 7023 | 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 | 7001 | if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) { |
| 7026 | 7002 | const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu))); |
| 7027 | 7003 | const truncated_int = |
| ... | ... | @@ -7043,7 +7019,7 @@ pub const FuncGen = struct { |
| 7043 | 7019 | .@"struct" => { |
| 7044 | 7020 | const layout = struct_ty.containerLayout(zcu); |
| 7045 | 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 | 7023 | const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?; |
| 7048 | 7024 | const field_ptr = |
| 7049 | 7025 | try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, ""); |
| ... | ... | @@ -7064,7 +7040,7 @@ pub const FuncGen = struct { |
| 7064 | 7040 | } |
| 7065 | 7041 | }, |
| 7066 | 7042 | .@"union" => { |
| 7067 | | const union_llvm_ty = try o.lowerType(struct_ty); |
| 7043 | const union_llvm_ty = try o.lowerType(pt, struct_ty); |
| 7068 | 7044 | const layout = struct_ty.unionGetLayout(zcu); |
| 7069 | 7045 | const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)); |
| 7070 | 7046 | const field_ptr = |
| ... | ... | @@ -7083,7 +7059,7 @@ pub const FuncGen = struct { |
| 7083 | 7059 | |
| 7084 | 7060 | fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7085 | 7061 | const o = self.ng.object; |
| 7086 | | const pt = o.pt; |
| 7062 | const pt = self.ng.pt; |
| 7087 | 7063 | const zcu = pt.zcu; |
| 7088 | 7064 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 7089 | 7065 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| ... | ... | @@ -7094,8 +7070,8 @@ pub const FuncGen = struct { |
| 7094 | 7070 | const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu); |
| 7095 | 7071 | if (field_offset == 0) return field_ptr; |
| 7096 | 7072 | |
| 7097 | | const res_ty = try o.lowerType(ty_pl.ty.toType()); |
| 7098 | | const llvm_usize = try o.lowerType(Type.usize); |
| 7073 | const res_ty = try o.lowerType(pt, ty_pl.ty.toType()); |
| 7074 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 7099 | 7075 | |
| 7100 | 7076 | const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, ""); |
| 7101 | 7077 | const base_ptr_int = try self.wip.bin( |
| ... | ... | @@ -7151,7 +7127,8 @@ pub const FuncGen = struct { |
| 7151 | 7127 | |
| 7152 | 7128 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7153 | 7129 | const o = self.ng.object; |
| 7154 | | const zcu = o.pt.zcu; |
| 7130 | const pt = self.ng.pt; |
| 7131 | const zcu = pt.zcu; |
| 7155 | 7132 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 7156 | 7133 | const operand = try self.resolveInst(pl_op.operand); |
| 7157 | 7134 | const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload); |
| ... | ... | @@ -7162,7 +7139,7 @@ pub const FuncGen = struct { |
| 7162 | 7139 | self.file, |
| 7163 | 7140 | self.scope, |
| 7164 | 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 | 7145 | _ = try self.wip.callIntrinsic( |
| ... | ... | @@ -7183,6 +7160,7 @@ pub const FuncGen = struct { |
| 7183 | 7160 | |
| 7184 | 7161 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index, is_arg: bool) !Builder.Value { |
| 7185 | 7162 | const o = self.ng.object; |
| 7163 | const pt = self.ng.pt; |
| 7186 | 7164 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 7187 | 7165 | const operand = try self.resolveInst(pl_op.operand); |
| 7188 | 7166 | const operand_ty = self.typeOf(pl_op.operand); |
| ... | ... | @@ -7193,7 +7171,7 @@ pub const FuncGen = struct { |
| 7193 | 7171 | self.file, |
| 7194 | 7172 | self.scope, |
| 7195 | 7173 | self.prev_dbg_line, |
| 7196 | | try o.lowerDebugType(operand_ty), |
| 7174 | try o.lowerDebugType(pt, operand_ty), |
| 7197 | 7175 | arg_no: { |
| 7198 | 7176 | self.arg_inline_index += 1; |
| 7199 | 7177 | break :arg_no self.arg_inline_index; |
| ... | ... | @@ -7203,10 +7181,10 @@ pub const FuncGen = struct { |
| 7203 | 7181 | self.file, |
| 7204 | 7182 | self.scope, |
| 7205 | 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 | 7188 | const owner_mod = self.ng.ownerModule(); |
| 7211 | 7189 | if (isByRef(operand_ty, zcu)) { |
| 7212 | 7190 | _ = try self.wip.callIntrinsic( |
| ... | ... | @@ -7296,7 +7274,7 @@ pub const FuncGen = struct { |
| 7296 | 7274 | // This stores whether we need to add an elementtype attribute and |
| 7297 | 7275 | // if so, the element type itself. |
| 7298 | 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 | 7278 | const zcu = pt.zcu; |
| 7301 | 7279 | const target = zcu.getTarget(); |
| 7302 | 7280 | |
| ... | ... | @@ -7326,7 +7304,7 @@ pub const FuncGen = struct { |
| 7326 | 7304 | const output_inst = try self.resolveInst(output); |
| 7327 | 7305 | const output_ty = self.typeOf(output); |
| 7328 | 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 | 7309 | switch (constraint[0]) { |
| 7332 | 7310 | '=' => {}, |
| ... | ... | @@ -7364,7 +7342,7 @@ pub const FuncGen = struct { |
| 7364 | 7342 | is_indirect.* = false; |
| 7365 | 7343 | |
| 7366 | 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 | 7346 | llvm_ret_i += 1; |
| 7369 | 7347 | } |
| 7370 | 7348 | |
| ... | ... | @@ -7406,7 +7384,7 @@ pub const FuncGen = struct { |
| 7406 | 7384 | llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip); |
| 7407 | 7385 | } else { |
| 7408 | 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 | 7388 | const load_inst = |
| 7411 | 7389 | try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, ""); |
| 7412 | 7390 | llvm_param_values[llvm_param_i] = load_inst; |
| ... | ... | @@ -7447,7 +7425,7 @@ pub const FuncGen = struct { |
| 7447 | 7425 | llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: { |
| 7448 | 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 | 7429 | } else .none; |
| 7452 | 7430 | |
| 7453 | 7431 | llvm_param_i += 1; |
| ... | ... | @@ -7465,7 +7443,7 @@ pub const FuncGen = struct { |
| 7465 | 7443 | if (constraint[0] != '+') continue; |
| 7466 | 7444 | |
| 7467 | 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 | 7447 | if (is_indirect) { |
| 7470 | 7448 | llvm_param_values[llvm_param_i] = llvm_rw_val; |
| 7471 | 7449 | llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip); |
| ... | ... | @@ -7663,13 +7641,13 @@ pub const FuncGen = struct { |
| 7663 | 7641 | cond: Builder.IntegerCondition, |
| 7664 | 7642 | ) !Builder.Value { |
| 7665 | 7643 | const o = self.ng.object; |
| 7666 | | const pt = o.pt; |
| 7644 | const pt = self.ng.pt; |
| 7667 | 7645 | const zcu = pt.zcu; |
| 7668 | 7646 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 7669 | 7647 | const operand = try self.resolveInst(un_op); |
| 7670 | 7648 | const operand_ty = self.typeOf(un_op); |
| 7671 | 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 | 7651 | const payload_ty = optional_ty.optionalChild(zcu); |
| 7674 | 7652 | |
| 7675 | 7653 | const access_kind: Builder.MemoryAccessKind = |
| ... | ... | @@ -7714,14 +7692,14 @@ pub const FuncGen = struct { |
| 7714 | 7692 | operand_is_ptr: bool, |
| 7715 | 7693 | ) !Builder.Value { |
| 7716 | 7694 | const o = self.ng.object; |
| 7717 | | const pt = o.pt; |
| 7695 | const pt = self.ng.pt; |
| 7718 | 7696 | const zcu = pt.zcu; |
| 7719 | 7697 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 7720 | 7698 | const operand = try self.resolveInst(un_op); |
| 7721 | 7699 | const operand_ty = self.typeOf(un_op); |
| 7722 | 7700 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; |
| 7723 | 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 | 7703 | const zero = try o.builder.intValue(error_type, 0); |
| 7726 | 7704 | |
| 7727 | 7705 | const access_kind: Builder.MemoryAccessKind = |
| ... | ... | @@ -7740,7 +7718,7 @@ pub const FuncGen = struct { |
| 7740 | 7718 | |
| 7741 | 7719 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 7742 | 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 | 7722 | else |
| 7745 | 7723 | operand; |
| 7746 | 7724 | return self.wip.icmp(cond, loaded, zero, ""); |
| ... | ... | @@ -7749,7 +7727,7 @@ pub const FuncGen = struct { |
| 7749 | 7727 | const err_field_index = try errUnionErrorOffset(payload_ty, pt); |
| 7750 | 7728 | |
| 7751 | 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 | 7731 | const err_field_ptr = |
| 7754 | 7732 | try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, ""); |
| 7755 | 7733 | break :loaded try self.wip.load(access_kind, error_type, err_field_ptr, .default, ""); |
| ... | ... | @@ -7759,7 +7737,7 @@ pub const FuncGen = struct { |
| 7759 | 7737 | |
| 7760 | 7738 | fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7761 | 7739 | const o = self.ng.object; |
| 7762 | | const pt = o.pt; |
| 7740 | const pt = self.ng.pt; |
| 7763 | 7741 | const zcu = pt.zcu; |
| 7764 | 7742 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7765 | 7743 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -7774,14 +7752,14 @@ pub const FuncGen = struct { |
| 7774 | 7752 | // The payload and the optional are the same value. |
| 7775 | 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 | 7758 | fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7781 | 7759 | comptime assert(optional_layout_version == 3); |
| 7782 | 7760 | |
| 7783 | 7761 | const o = self.ng.object; |
| 7784 | | const pt = o.pt; |
| 7762 | const pt = self.ng.pt; |
| 7785 | 7763 | const zcu = pt.zcu; |
| 7786 | 7764 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7787 | 7765 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -7807,7 +7785,7 @@ pub const FuncGen = struct { |
| 7807 | 7785 | } |
| 7808 | 7786 | |
| 7809 | 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 | 7789 | const non_null_ptr = try self.wip.gepStruct(optional_llvm_ty, operand, 1, ""); |
| 7812 | 7790 | |
| 7813 | 7791 | self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu)); |
| ... | ... | @@ -7823,7 +7801,7 @@ pub const FuncGen = struct { |
| 7823 | 7801 | |
| 7824 | 7802 | fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 7825 | 7803 | const o = self.ng.object; |
| 7826 | | const pt = o.pt; |
| 7804 | const pt = self.ng.pt; |
| 7827 | 7805 | const zcu = pt.zcu; |
| 7828 | 7806 | const inst = body_tail[0]; |
| 7829 | 7807 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -7837,7 +7815,7 @@ pub const FuncGen = struct { |
| 7837 | 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 | 7819 | const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false; |
| 7842 | 7820 | return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load); |
| 7843 | 7821 | } |
| ... | ... | @@ -7848,7 +7826,7 @@ pub const FuncGen = struct { |
| 7848 | 7826 | operand_is_ptr: bool, |
| 7849 | 7827 | ) !Builder.Value { |
| 7850 | 7828 | const o = self.ng.object; |
| 7851 | | const pt = o.pt; |
| 7829 | const pt = self.ng.pt; |
| 7852 | 7830 | const zcu = pt.zcu; |
| 7853 | 7831 | const inst = body_tail[0]; |
| 7854 | 7832 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -7862,7 +7840,7 @@ pub const FuncGen = struct { |
| 7862 | 7840 | return if (operand_is_ptr) operand else .none; |
| 7863 | 7841 | } |
| 7864 | 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 | 7844 | if (operand_is_ptr) { |
| 7867 | 7845 | return self.wip.gepStruct(err_union_llvm_ty, operand, offset, ""); |
| 7868 | 7846 | } else if (isByRef(err_union_ty, zcu)) { |
| ... | ... | @@ -7884,12 +7862,12 @@ pub const FuncGen = struct { |
| 7884 | 7862 | operand_is_ptr: bool, |
| 7885 | 7863 | ) !Builder.Value { |
| 7886 | 7864 | const o = self.ng.object; |
| 7887 | | const pt = o.pt; |
| 7865 | const pt = self.ng.pt; |
| 7888 | 7866 | const zcu = pt.zcu; |
| 7889 | 7867 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7890 | 7868 | const operand = try self.resolveInst(ty_op.operand); |
| 7891 | 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 | 7871 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; |
| 7894 | 7872 | if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) { |
| 7895 | 7873 | if (operand_is_ptr) { |
| ... | ... | @@ -7916,7 +7894,7 @@ pub const FuncGen = struct { |
| 7916 | 7894 | if (operand_is_ptr or isByRef(err_union_ty, zcu)) { |
| 7917 | 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 | 7898 | const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, ""); |
| 7921 | 7899 | return self.wip.load(access_kind, error_type, err_field_ptr, .default, ""); |
| 7922 | 7900 | } |
| ... | ... | @@ -7926,7 +7904,7 @@ pub const FuncGen = struct { |
| 7926 | 7904 | |
| 7927 | 7905 | fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7928 | 7906 | const o = self.ng.object; |
| 7929 | | const pt = o.pt; |
| 7907 | const pt = self.ng.pt; |
| 7930 | 7908 | const zcu = pt.zcu; |
| 7931 | 7909 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7932 | 7910 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -7934,7 +7912,7 @@ pub const FuncGen = struct { |
| 7934 | 7912 | const err_union_ty = err_union_ptr_ty.childType(zcu); |
| 7935 | 7913 | |
| 7936 | 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 | 7917 | const access_kind: Builder.MemoryAccessKind = |
| 7940 | 7918 | if (err_union_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; |
| ... | ... | @@ -7945,7 +7923,7 @@ pub const FuncGen = struct { |
| 7945 | 7923 | _ = try self.wip.store(access_kind, non_error_val, operand, .default); |
| 7946 | 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 | 7928 | self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu)); |
| 7951 | 7929 | |
| ... | ... | @@ -7976,14 +7954,14 @@ pub const FuncGen = struct { |
| 7976 | 7954 | |
| 7977 | 7955 | fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7978 | 7956 | const o = self.ng.object; |
| 7979 | | const pt = o.pt; |
| 7957 | const pt = self.ng.pt; |
| 7980 | 7958 | const zcu = pt.zcu; |
| 7981 | 7959 | |
| 7982 | 7960 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 7983 | 7961 | const struct_ty = ty_pl.ty.toType(); |
| 7984 | 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 | 7965 | const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?; |
| 7988 | 7966 | assert(self.err_ret_trace != .none); |
| 7989 | 7967 | const field_ptr = |
| ... | ... | @@ -8022,7 +8000,7 @@ pub const FuncGen = struct { |
| 8022 | 8000 | |
| 8023 | 8001 | fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 8024 | 8002 | const o = self.ng.object; |
| 8025 | | const pt = o.pt; |
| 8003 | const pt = self.ng.pt; |
| 8026 | 8004 | const zcu = pt.zcu; |
| 8027 | 8005 | const inst = body_tail[0]; |
| 8028 | 8006 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -8033,7 +8011,7 @@ pub const FuncGen = struct { |
| 8033 | 8011 | const operand = try self.resolveInst(ty_op.operand); |
| 8034 | 8012 | const optional_ty = self.typeOfIndex(inst); |
| 8035 | 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 | 8015 | if (isByRef(optional_ty, zcu)) { |
| 8038 | 8016 | const directReturn = self.isNextRet(body_tail); |
| 8039 | 8017 | const optional_ptr = if (directReturn) |
| ... | ... | @@ -8056,7 +8034,7 @@ pub const FuncGen = struct { |
| 8056 | 8034 | |
| 8057 | 8035 | fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 8058 | 8036 | const o = self.ng.object; |
| 8059 | | const pt = o.pt; |
| 8037 | const pt = self.ng.pt; |
| 8060 | 8038 | const zcu = pt.zcu; |
| 8061 | 8039 | const inst = body_tail[0]; |
| 8062 | 8040 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -8066,8 +8044,8 @@ pub const FuncGen = struct { |
| 8066 | 8044 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 8067 | 8045 | return operand; |
| 8068 | 8046 | } |
| 8069 | | const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0); |
| 8070 | | const err_un_llvm_ty = try o.lowerType(err_un_ty); |
| 8047 | const ok_err_code = try o.builder.intValue(try o.errorIntType(pt), 0); |
| 8048 | const err_un_llvm_ty = try o.lowerType(pt, err_un_ty); |
| 8071 | 8049 | |
| 8072 | 8050 | const payload_offset = try errUnionPayloadOffset(payload_ty, pt); |
| 8073 | 8051 | const error_offset = try errUnionErrorOffset(payload_ty, pt); |
| ... | ... | @@ -8098,7 +8076,7 @@ pub const FuncGen = struct { |
| 8098 | 8076 | |
| 8099 | 8077 | fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 8100 | 8078 | const o = self.ng.object; |
| 8101 | | const pt = o.pt; |
| 8079 | const pt = self.ng.pt; |
| 8102 | 8080 | const zcu = pt.zcu; |
| 8103 | 8081 | const inst = body_tail[0]; |
| 8104 | 8082 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -8106,7 +8084,7 @@ pub const FuncGen = struct { |
| 8106 | 8084 | const payload_ty = err_un_ty.errorUnionPayload(zcu); |
| 8107 | 8085 | const operand = try self.resolveInst(ty_op.operand); |
| 8108 | 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 | 8089 | const payload_offset = try errUnionPayloadOffset(payload_ty, pt); |
| 8112 | 8090 | const error_offset = try errUnionErrorOffset(payload_ty, pt); |
| ... | ... | @@ -8139,9 +8117,10 @@ pub const FuncGen = struct { |
| 8139 | 8117 | |
| 8140 | 8118 | fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8141 | 8119 | const o = self.ng.object; |
| 8120 | const pt = self.ng.pt; |
| 8142 | 8121 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 8143 | 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 | 8124 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{ |
| 8146 | 8125 | try o.builder.intValue(.i32, index), |
| 8147 | 8126 | }, ""); |
| ... | ... | @@ -8149,9 +8128,10 @@ pub const FuncGen = struct { |
| 8149 | 8128 | |
| 8150 | 8129 | fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8151 | 8130 | const o = self.ng.object; |
| 8131 | const pt = self.ng.pt; |
| 8152 | 8132 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 8153 | 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 | 8135 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{ |
| 8156 | 8136 | try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand), |
| 8157 | 8137 | }, ""); |
| ... | ... | @@ -8159,7 +8139,7 @@ pub const FuncGen = struct { |
| 8159 | 8139 | |
| 8160 | 8140 | fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8161 | 8141 | const o = self.ng.object; |
| 8162 | | const pt = o.pt; |
| 8142 | const pt = self.ng.pt; |
| 8163 | 8143 | const zcu = pt.zcu; |
| 8164 | 8144 | const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem; |
| 8165 | 8145 | const extra = self.air.extraData(Air.Bin, data.payload).data; |
| ... | ... | @@ -8175,7 +8155,7 @@ pub const FuncGen = struct { |
| 8175 | 8155 | // https://github.com/ziglang/zig/issues/18652#issuecomment-2452844908 |
| 8176 | 8156 | const access_kind: Builder.MemoryAccessKind = |
| 8177 | 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 | 8159 | const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 8180 | 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 | 8166 | |
| 8187 | 8167 | fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8188 | 8168 | const o = fg.ng.object; |
| 8169 | const pt = fg.ng.pt; |
| 8189 | 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 | 8172 | return llvm_ptr_const.toValue(); |
| 8192 | 8173 | } |
| 8193 | 8174 | |
| 8194 | 8175 | fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8195 | 8176 | const o = self.ng.object; |
| 8196 | | const zcu = o.pt.zcu; |
| 8177 | const pt = self.ng.pt; |
| 8178 | const zcu = pt.zcu; |
| 8197 | 8179 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8198 | 8180 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8199 | 8181 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8205,7 +8187,7 @@ pub const FuncGen = struct { |
| 8205 | 8187 | .normal, |
| 8206 | 8188 | .none, |
| 8207 | 8189 | if (scalar_ty.isSignedInt(zcu)) .smin else .umin, |
| 8208 | | &.{try o.lowerType(inst_ty)}, |
| 8190 | &.{try o.lowerType(pt, inst_ty)}, |
| 8209 | 8191 | &.{ lhs, rhs }, |
| 8210 | 8192 | "", |
| 8211 | 8193 | ); |
| ... | ... | @@ -8213,7 +8195,8 @@ pub const FuncGen = struct { |
| 8213 | 8195 | |
| 8214 | 8196 | fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8215 | 8197 | const o = self.ng.object; |
| 8216 | | const zcu = o.pt.zcu; |
| 8198 | const pt = self.ng.pt; |
| 8199 | const zcu = pt.zcu; |
| 8217 | 8200 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8218 | 8201 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8219 | 8202 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8225,7 +8208,7 @@ pub const FuncGen = struct { |
| 8225 | 8208 | .normal, |
| 8226 | 8209 | .none, |
| 8227 | 8210 | if (scalar_ty.isSignedInt(zcu)) .smax else .umax, |
| 8228 | | &.{try o.lowerType(inst_ty)}, |
| 8211 | &.{try o.lowerType(pt, inst_ty)}, |
| 8229 | 8212 | &.{ lhs, rhs }, |
| 8230 | 8213 | "", |
| 8231 | 8214 | ); |
| ... | ... | @@ -8233,17 +8216,17 @@ pub const FuncGen = struct { |
| 8233 | 8216 | |
| 8234 | 8217 | fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8235 | 8218 | const o = self.ng.object; |
| 8219 | const pt = self.ng.pt; |
| 8236 | 8220 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8237 | 8221 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8238 | 8222 | const ptr = try self.resolveInst(bin_op.lhs); |
| 8239 | 8223 | const len = try self.resolveInst(bin_op.rhs); |
| 8240 | 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 | 8228 | fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8245 | | const o = self.ng.object; |
| 8246 | | const zcu = o.pt.zcu; |
| 8229 | const zcu = self.ng.pt.zcu; |
| 8247 | 8230 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8248 | 8231 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8249 | 8232 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8261,7 +8244,8 @@ pub const FuncGen = struct { |
| 8261 | 8244 | unsigned_intrinsic: Builder.Intrinsic, |
| 8262 | 8245 | ) !Builder.Value { |
| 8263 | 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 | 8250 | const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8267 | 8251 | const lhs = try fg.resolveInst(bin_op.lhs); |
| ... | ... | @@ -8270,7 +8254,7 @@ pub const FuncGen = struct { |
| 8270 | 8254 | const scalar_ty = inst_ty.scalarType(zcu); |
| 8271 | 8255 | |
| 8272 | 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 | 8258 | const results = |
| 8275 | 8259 | try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, ""); |
| 8276 | 8260 | |
| ... | ... | @@ -8309,7 +8293,8 @@ pub const FuncGen = struct { |
| 8309 | 8293 | |
| 8310 | 8294 | fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8311 | 8295 | const o = self.ng.object; |
| 8312 | | const zcu = o.pt.zcu; |
| 8296 | const pt = self.ng.pt; |
| 8297 | const zcu = pt.zcu; |
| 8313 | 8298 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8314 | 8299 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8315 | 8300 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8321,15 +8306,14 @@ pub const FuncGen = struct { |
| 8321 | 8306 | .normal, |
| 8322 | 8307 | .none, |
| 8323 | 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 | 8310 | &.{ lhs, rhs }, |
| 8326 | 8311 | "", |
| 8327 | 8312 | ); |
| 8328 | 8313 | } |
| 8329 | 8314 | |
| 8330 | 8315 | fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8331 | | const o = self.ng.object; |
| 8332 | | const zcu = o.pt.zcu; |
| 8316 | const zcu = self.ng.pt.zcu; |
| 8333 | 8317 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8334 | 8318 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8335 | 8319 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8350,7 +8334,8 @@ pub const FuncGen = struct { |
| 8350 | 8334 | |
| 8351 | 8335 | fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8352 | 8336 | const o = self.ng.object; |
| 8353 | | const zcu = o.pt.zcu; |
| 8337 | const pt = self.ng.pt; |
| 8338 | const zcu = pt.zcu; |
| 8354 | 8339 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8355 | 8340 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8356 | 8341 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8362,15 +8347,14 @@ pub const FuncGen = struct { |
| 8362 | 8347 | .normal, |
| 8363 | 8348 | .none, |
| 8364 | 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 | 8351 | &.{ lhs, rhs }, |
| 8367 | 8352 | "", |
| 8368 | 8353 | ); |
| 8369 | 8354 | } |
| 8370 | 8355 | |
| 8371 | 8356 | fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8372 | | const o = self.ng.object; |
| 8373 | | const zcu = o.pt.zcu; |
| 8357 | const zcu = self.ng.pt.zcu; |
| 8374 | 8358 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8375 | 8359 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8376 | 8360 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8391,7 +8375,8 @@ pub const FuncGen = struct { |
| 8391 | 8375 | |
| 8392 | 8376 | fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8393 | 8377 | const o = self.ng.object; |
| 8394 | | const zcu = o.pt.zcu; |
| 8378 | const pt = self.ng.pt; |
| 8379 | const zcu = pt.zcu; |
| 8395 | 8380 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8396 | 8381 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8397 | 8382 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8403,7 +8388,7 @@ pub const FuncGen = struct { |
| 8403 | 8388 | .normal, |
| 8404 | 8389 | .none, |
| 8405 | 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 | 8392 | &.{ lhs, rhs, .@"0" }, |
| 8408 | 8393 | "", |
| 8409 | 8394 | ); |
| ... | ... | @@ -8419,8 +8404,7 @@ pub const FuncGen = struct { |
| 8419 | 8404 | } |
| 8420 | 8405 | |
| 8421 | 8406 | fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8422 | | const o = self.ng.object; |
| 8423 | | const zcu = o.pt.zcu; |
| 8407 | const zcu = self.ng.pt.zcu; |
| 8424 | 8408 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8425 | 8409 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8426 | 8410 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8436,7 +8420,8 @@ pub const FuncGen = struct { |
| 8436 | 8420 | |
| 8437 | 8421 | fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8438 | 8422 | const o = self.ng.object; |
| 8439 | | const zcu = o.pt.zcu; |
| 8423 | const pt = self.ng.pt; |
| 8424 | const zcu = pt.zcu; |
| 8440 | 8425 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8441 | 8426 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8442 | 8427 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8448,7 +8433,7 @@ pub const FuncGen = struct { |
| 8448 | 8433 | return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result}); |
| 8449 | 8434 | } |
| 8450 | 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 | 8438 | const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb; |
| 8454 | 8439 | var stack align(@max( |
| ... | ... | @@ -8485,8 +8470,7 @@ pub const FuncGen = struct { |
| 8485 | 8470 | } |
| 8486 | 8471 | |
| 8487 | 8472 | fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8488 | | const o = self.ng.object; |
| 8489 | | const zcu = o.pt.zcu; |
| 8473 | const zcu = self.ng.pt.zcu; |
| 8490 | 8474 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8491 | 8475 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8492 | 8476 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8503,8 +8487,7 @@ pub const FuncGen = struct { |
| 8503 | 8487 | } |
| 8504 | 8488 | |
| 8505 | 8489 | fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8506 | | const o = self.ng.object; |
| 8507 | | const zcu = o.pt.zcu; |
| 8490 | const zcu = self.ng.pt.zcu; |
| 8508 | 8491 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8509 | 8492 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8510 | 8493 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8521,12 +8504,13 @@ pub const FuncGen = struct { |
| 8521 | 8504 | |
| 8522 | 8505 | fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8523 | 8506 | const o = self.ng.object; |
| 8524 | | const zcu = o.pt.zcu; |
| 8507 | const pt = self.ng.pt; |
| 8508 | const zcu = pt.zcu; |
| 8525 | 8509 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8526 | 8510 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8527 | 8511 | const rhs = try self.resolveInst(bin_op.rhs); |
| 8528 | 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 | 8514 | const scalar_ty = inst_ty.scalarType(zcu); |
| 8531 | 8515 | |
| 8532 | 8516 | if (scalar_ty.isRuntimeFloat()) { |
| ... | ... | @@ -8574,17 +8558,18 @@ pub const FuncGen = struct { |
| 8574 | 8558 | |
| 8575 | 8559 | fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8576 | 8560 | const o = self.ng.object; |
| 8577 | | const zcu = o.pt.zcu; |
| 8561 | const pt = self.ng.pt; |
| 8562 | const zcu = pt.zcu; |
| 8578 | 8563 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8579 | 8564 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8580 | 8565 | const ptr = try self.resolveInst(bin_op.lhs); |
| 8581 | 8566 | const offset = try self.resolveInst(bin_op.rhs); |
| 8582 | 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 | 8569 | switch (ptr_ty.ptrSize(zcu)) { |
| 8585 | 8570 | // It's a pointer to an array, so according to LLVM we need an extra GEP index. |
| 8586 | 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 | 8574 | .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""), |
| 8590 | 8575 | .slice => { |
| ... | ... | @@ -8596,18 +8581,19 @@ pub const FuncGen = struct { |
| 8596 | 8581 | |
| 8597 | 8582 | fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8598 | 8583 | const o = self.ng.object; |
| 8599 | | const zcu = o.pt.zcu; |
| 8584 | const pt = self.ng.pt; |
| 8585 | const zcu = pt.zcu; |
| 8600 | 8586 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8601 | 8587 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8602 | 8588 | const ptr = try self.resolveInst(bin_op.lhs); |
| 8603 | 8589 | const offset = try self.resolveInst(bin_op.rhs); |
| 8604 | 8590 | const negative_offset = try self.wip.neg(offset, ""); |
| 8605 | 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 | 8593 | switch (ptr_ty.ptrSize(zcu)) { |
| 8608 | 8594 | // It's a pointer to an array, so according to LLVM we need an extra GEP index. |
| 8609 | 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 | 8598 | .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""), |
| 8613 | 8599 | .slice => { |
| ... | ... | @@ -8624,7 +8610,7 @@ pub const FuncGen = struct { |
| 8624 | 8610 | unsigned_intrinsic: Builder.Intrinsic, |
| 8625 | 8611 | ) !Builder.Value { |
| 8626 | 8612 | const o = self.ng.object; |
| 8627 | | const pt = o.pt; |
| 8613 | const pt = self.ng.pt; |
| 8628 | 8614 | const zcu = pt.zcu; |
| 8629 | 8615 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8630 | 8616 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | ... | @@ -8637,8 +8623,8 @@ pub const FuncGen = struct { |
| 8637 | 8623 | const inst_ty = self.typeOfIndex(inst); |
| 8638 | 8624 | |
| 8639 | 8625 | const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic; |
| 8640 | | const llvm_inst_ty = try o.lowerType(inst_ty); |
| 8641 | | const llvm_lhs_ty = try o.lowerType(lhs_ty); |
| 8626 | const llvm_inst_ty = try o.lowerType(pt, inst_ty); |
| 8627 | const llvm_lhs_ty = try o.lowerType(pt, lhs_ty); |
| 8642 | 8628 | const results = |
| 8643 | 8629 | try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, ""); |
| 8644 | 8630 | |
| ... | ... | @@ -8718,7 +8704,7 @@ pub const FuncGen = struct { |
| 8718 | 8704 | return o.builder.addFunction( |
| 8719 | 8705 | try o.builder.fnType(return_type, param_types, .normal), |
| 8720 | 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 | 8718 | params: [2]Builder.Value, |
| 8733 | 8719 | ) !Builder.Value { |
| 8734 | 8720 | const o = self.ng.object; |
| 8735 | | const zcu = o.pt.zcu; |
| 8721 | const pt = self.ng.pt; |
| 8722 | const zcu = pt.zcu; |
| 8736 | 8723 | const target = zcu.getTarget(); |
| 8737 | 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 | 8727 | if (intrinsicsAllowed(scalar_ty, target)) { |
| 8741 | 8728 | const cond: Builder.FloatCondition = switch (pred) { |
| ... | ... | @@ -8838,10 +8825,11 @@ pub const FuncGen = struct { |
| 8838 | 8825 | params: [params_len]Builder.Value, |
| 8839 | 8826 | ) !Builder.Value { |
| 8840 | 8827 | const o = self.ng.object; |
| 8841 | | const zcu = o.pt.zcu; |
| 8828 | const pt = self.ng.pt; |
| 8829 | const zcu = pt.zcu; |
| 8842 | 8830 | const target = zcu.getTarget(); |
| 8843 | 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 | 8834 | if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) { |
| 8847 | 8835 | // Some operations are dedicated LLVM instructions, not available as intrinsics |
| ... | ... | @@ -8979,7 +8967,7 @@ pub const FuncGen = struct { |
| 8979 | 8967 | |
| 8980 | 8968 | fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8981 | 8969 | const o = self.ng.object; |
| 8982 | | const pt = o.pt; |
| 8970 | const pt = self.ng.pt; |
| 8983 | 8971 | const zcu = pt.zcu; |
| 8984 | 8972 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8985 | 8973 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | ... | @@ -8993,9 +8981,9 @@ pub const FuncGen = struct { |
| 8993 | 8981 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); |
| 8994 | 8982 | |
| 8995 | 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 | 8988 | const result = try self.wip.bin(.shl, lhs, casted_rhs, ""); |
| 9001 | 8989 | const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) |
| ... | ... | @@ -9052,7 +9040,8 @@ pub const FuncGen = struct { |
| 9052 | 9040 | |
| 9053 | 9041 | fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9054 | 9042 | const o = self.ng.object; |
| 9055 | | const zcu = o.pt.zcu; |
| 9043 | const pt = self.ng.pt; |
| 9044 | const zcu = pt.zcu; |
| 9056 | 9045 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9057 | 9046 | |
| 9058 | 9047 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -9063,7 +9052,7 @@ pub const FuncGen = struct { |
| 9063 | 9052 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9064 | 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 | 9056 | return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) |
| 9068 | 9057 | .@"shl nsw" |
| 9069 | 9058 | else |
| ... | ... | @@ -9072,7 +9061,8 @@ pub const FuncGen = struct { |
| 9072 | 9061 | |
| 9073 | 9062 | fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9074 | 9063 | const o = self.ng.object; |
| 9075 | | const zcu = o.pt.zcu; |
| 9064 | const pt = self.ng.pt; |
| 9065 | const zcu = pt.zcu; |
| 9076 | 9066 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9077 | 9067 | |
| 9078 | 9068 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -9082,13 +9072,13 @@ pub const FuncGen = struct { |
| 9082 | 9072 | if (lhs_ty.isVector(zcu) and !self.typeOf(bin_op.rhs).isVector(zcu)) |
| 9083 | 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 | 9076 | return self.wip.bin(.shl, lhs, casted_rhs, ""); |
| 9087 | 9077 | } |
| 9088 | 9078 | |
| 9089 | 9079 | fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9090 | 9080 | const o = self.ng.object; |
| 9091 | | const pt = o.pt; |
| 9081 | const pt = self.ng.pt; |
| 9092 | 9082 | const zcu = pt.zcu; |
| 9093 | 9083 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9094 | 9084 | |
| ... | ... | @@ -9097,7 +9087,7 @@ pub const FuncGen = struct { |
| 9097 | 9087 | |
| 9098 | 9088 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 9099 | 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 | 9091 | const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder); |
| 9102 | 9092 | |
| 9103 | 9093 | const rhs_ty = self.typeOf(bin_op.rhs); |
| ... | ... | @@ -9105,7 +9095,7 @@ pub const FuncGen = struct { |
| 9105 | 9095 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9106 | 9096 | const rhs_info = rhs_ty.intInfo(zcu); |
| 9107 | 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 | 9099 | const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder); |
| 9110 | 9100 | |
| 9111 | 9101 | const result = try self.wip.callIntrinsic( |
| ... | ... | @@ -9168,7 +9158,8 @@ pub const FuncGen = struct { |
| 9168 | 9158 | |
| 9169 | 9159 | fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value { |
| 9170 | 9160 | const o = self.ng.object; |
| 9171 | | const zcu = o.pt.zcu; |
| 9161 | const pt = self.ng.pt; |
| 9162 | const zcu = pt.zcu; |
| 9172 | 9163 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9173 | 9164 | |
| 9174 | 9165 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -9179,7 +9170,7 @@ pub const FuncGen = struct { |
| 9179 | 9170 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9180 | 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 | 9174 | const is_signed_int = lhs_scalar_ty.isSignedInt(zcu); |
| 9184 | 9175 | |
| 9185 | 9176 | return self.wip.bin(if (is_exact) |
| ... | ... | @@ -9189,7 +9180,8 @@ pub const FuncGen = struct { |
| 9189 | 9180 | |
| 9190 | 9181 | fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9191 | 9182 | const o = self.ng.object; |
| 9192 | | const zcu = o.pt.zcu; |
| 9183 | const pt = self.ng.pt; |
| 9184 | const zcu = pt.zcu; |
| 9193 | 9185 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9194 | 9186 | const operand = try self.resolveInst(ty_op.operand); |
| 9195 | 9187 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -9200,7 +9192,7 @@ pub const FuncGen = struct { |
| 9200 | 9192 | .normal, |
| 9201 | 9193 | .none, |
| 9202 | 9194 | .abs, |
| 9203 | | &.{try o.lowerType(operand_ty)}, |
| 9195 | &.{try o.lowerType(pt, operand_ty)}, |
| 9204 | 9196 | &.{ operand, try o.builder.intValue(.i1, 0) }, |
| 9205 | 9197 | "", |
| 9206 | 9198 | ), |
| ... | ... | @@ -9211,10 +9203,11 @@ pub const FuncGen = struct { |
| 9211 | 9203 | |
| 9212 | 9204 | fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9213 | 9205 | const o = fg.ng.object; |
| 9214 | | const zcu = o.pt.zcu; |
| 9206 | const pt = fg.ng.pt; |
| 9207 | const zcu = pt.zcu; |
| 9215 | 9208 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9216 | 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 | 9211 | const operand = try fg.resolveInst(ty_op.operand); |
| 9219 | 9212 | const operand_ty = fg.typeOf(ty_op.operand); |
| 9220 | 9213 | const operand_info = operand_ty.intInfo(zcu); |
| ... | ... | @@ -9243,8 +9236,8 @@ pub const FuncGen = struct { |
| 9243 | 9236 | |
| 9244 | 9237 | if (!have_min_check and !have_max_check) break :safety; |
| 9245 | 9238 | |
| 9246 | | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 9247 | | const operand_scalar_llvm_ty = try o.lowerType(operand_scalar); |
| 9239 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9240 | const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar); |
| 9248 | 9241 | |
| 9249 | 9242 | const is_vector = operand_ty.zigTypeTag(zcu) == .vector; |
| 9250 | 9243 | assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector)); |
| ... | ... | @@ -9313,15 +9306,17 @@ pub const FuncGen = struct { |
| 9313 | 9306 | |
| 9314 | 9307 | fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9315 | 9308 | const o = self.ng.object; |
| 9309 | const pt = self.ng.pt; |
| 9316 | 9310 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9317 | 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 | 9313 | return self.wip.cast(.trunc, operand, dest_llvm_ty, ""); |
| 9320 | 9314 | } |
| 9321 | 9315 | |
| 9322 | 9316 | fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9323 | 9317 | const o = self.ng.object; |
| 9324 | | const zcu = o.pt.zcu; |
| 9318 | const pt = self.ng.pt; |
| 9319 | const zcu = pt.zcu; |
| 9325 | 9320 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9326 | 9321 | const operand = try self.resolveInst(ty_op.operand); |
| 9327 | 9322 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -9329,10 +9324,10 @@ pub const FuncGen = struct { |
| 9329 | 9324 | const target = zcu.getTarget(); |
| 9330 | 9325 | |
| 9331 | 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 | 9328 | } else { |
| 9334 | | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 9335 | | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 9329 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9330 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 9336 | 9331 | |
| 9337 | 9332 | const dest_bits = dest_ty.floatBits(target); |
| 9338 | 9333 | const src_bits = operand_ty.floatBits(target); |
| ... | ... | @@ -9355,7 +9350,8 @@ pub const FuncGen = struct { |
| 9355 | 9350 | |
| 9356 | 9351 | fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9357 | 9352 | const o = self.ng.object; |
| 9358 | | const zcu = o.pt.zcu; |
| 9353 | const pt = self.ng.pt; |
| 9354 | const zcu = pt.zcu; |
| 9359 | 9355 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9360 | 9356 | const operand = try self.resolveInst(ty_op.operand); |
| 9361 | 9357 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -9363,10 +9359,10 @@ pub const FuncGen = struct { |
| 9363 | 9359 | const target = zcu.getTarget(); |
| 9364 | 9360 | |
| 9365 | 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 | 9363 | } else { |
| 9368 | | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 9369 | | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 9364 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9365 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 9370 | 9366 | |
| 9371 | 9367 | const dest_bits = dest_ty.scalarType(zcu).floatBits(target); |
| 9372 | 9368 | const src_bits = operand_ty.scalarType(zcu).floatBits(target); |
| ... | ... | @@ -9403,11 +9399,11 @@ pub const FuncGen = struct { |
| 9403 | 9399 | |
| 9404 | 9400 | fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value { |
| 9405 | 9401 | const o = self.ng.object; |
| 9406 | | const pt = o.pt; |
| 9402 | const pt = self.ng.pt; |
| 9407 | 9403 | const zcu = pt.zcu; |
| 9408 | 9404 | const operand_is_ref = isByRef(operand_ty, zcu); |
| 9409 | 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 | 9408 | if (operand_is_ref and result_is_ref) { |
| 9413 | 9409 | // They are both pointers, so just return the same opaque pointer :) |
| ... | ... | @@ -9442,7 +9438,7 @@ pub const FuncGen = struct { |
| 9442 | 9438 | } else { |
| 9443 | 9439 | // If the ABI size of the element type is not evenly divisible by size in bits; |
| 9444 | 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 | 9442 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 9447 | 9443 | const vector_len = operand_ty.arrayLen(zcu); |
| 9448 | 9444 | var i: u64 = 0; |
| ... | ... | @@ -9458,7 +9454,7 @@ pub const FuncGen = struct { |
| 9458 | 9454 | return array_ptr; |
| 9459 | 9455 | } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) { |
| 9460 | 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 | 9458 | if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{}); |
| 9463 | 9459 | |
| 9464 | 9460 | const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8; |
| ... | ... | @@ -9470,9 +9466,9 @@ pub const FuncGen = struct { |
| 9470 | 9466 | } else { |
| 9471 | 9467 | // If the ABI size of the element type is not evenly divisible by size in bits; |
| 9472 | 9468 | // a simple bitcast will not work, and we fall back to extractelement. |
| 9473 | | const array_llvm_ty = try o.lowerType(operand_ty); |
| 9474 | | const elem_llvm_ty = try o.lowerType(elem_ty); |
| 9475 | | const llvm_usize = try o.lowerType(Type.usize); |
| 9469 | const array_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9470 | const elem_llvm_ty = try o.lowerType(pt, elem_ty); |
| 9471 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 9476 | 9472 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 9477 | 9473 | const vector_len = operand_ty.arrayLen(zcu); |
| 9478 | 9474 | var vector = try o.builder.poisonValue(llvm_vector_ty); |
| ... | ... | @@ -9519,7 +9515,7 @@ pub const FuncGen = struct { |
| 9519 | 9515 | |
| 9520 | 9516 | fn airArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9521 | 9517 | const o = self.ng.object; |
| 9522 | | const pt = o.pt; |
| 9518 | const pt = self.ng.pt; |
| 9523 | 9519 | const zcu = pt.zcu; |
| 9524 | 9520 | const arg_val = self.args[self.arg_index]; |
| 9525 | 9521 | self.arg_index += 1; |
| ... | ... | @@ -9547,7 +9543,7 @@ pub const FuncGen = struct { |
| 9547 | 9543 | self.file, |
| 9548 | 9544 | self.scope, |
| 9549 | 9545 | lbrace_line, |
| 9550 | | try o.lowerDebugType(inst_ty), |
| 9546 | try o.lowerDebugType(pt, inst_ty), |
| 9551 | 9547 | self.arg_index, |
| 9552 | 9548 | ); |
| 9553 | 9549 | |
| ... | ... | @@ -9611,28 +9607,28 @@ pub const FuncGen = struct { |
| 9611 | 9607 | |
| 9612 | 9608 | fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9613 | 9609 | const o = self.ng.object; |
| 9614 | | const pt = o.pt; |
| 9610 | const pt = self.ng.pt; |
| 9615 | 9611 | const zcu = pt.zcu; |
| 9616 | 9612 | const ptr_ty = self.typeOfIndex(inst); |
| 9617 | 9613 | const pointee_type = ptr_ty.childType(zcu); |
| 9618 | 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 | 9618 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 9623 | 9619 | return self.buildAlloca(pointee_llvm_ty, alignment); |
| 9624 | 9620 | } |
| 9625 | 9621 | |
| 9626 | 9622 | fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9627 | 9623 | const o = self.ng.object; |
| 9628 | | const pt = o.pt; |
| 9624 | const pt = self.ng.pt; |
| 9629 | 9625 | const zcu = pt.zcu; |
| 9630 | 9626 | const ptr_ty = self.typeOfIndex(inst); |
| 9631 | 9627 | const ret_ty = ptr_ty.childType(zcu); |
| 9632 | 9628 | if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) |
| 9633 | | return (try o.lowerPtrToVoid(ptr_ty)).toValue(); |
| 9629 | return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue(); |
| 9634 | 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 | 9632 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 9637 | 9633 | return self.buildAlloca(ret_llvm_ty, alignment); |
| 9638 | 9634 | } |
| ... | ... | @@ -9644,13 +9640,13 @@ pub const FuncGen = struct { |
| 9644 | 9640 | llvm_ty: Builder.Type, |
| 9645 | 9641 | alignment: Builder.Alignment, |
| 9646 | 9642 | ) Allocator.Error!Builder.Value { |
| 9647 | | const target = self.ng.object.pt.zcu.getTarget(); |
| 9643 | const target = self.ng.pt.zcu.getTarget(); |
| 9648 | 9644 | return buildAllocaInner(&self.wip, llvm_ty, alignment, target); |
| 9649 | 9645 | } |
| 9650 | 9646 | |
| 9651 | 9647 | fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9652 | 9648 | const o = self.ng.object; |
| 9653 | | const pt = o.pt; |
| 9649 | const pt = self.ng.pt; |
| 9654 | 9650 | const zcu = pt.zcu; |
| 9655 | 9651 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9656 | 9652 | const dest_ptr = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -9685,7 +9681,7 @@ pub const FuncGen = struct { |
| 9685 | 9681 | |
| 9686 | 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 | 9685 | _ = try self.wip.callMemSet( |
| 9690 | 9686 | dest_ptr, |
| 9691 | 9687 | ptr_ty.ptrAlignment(zcu).toLlvm(), |
| ... | ... | @@ -9714,8 +9710,7 @@ pub const FuncGen = struct { |
| 9714 | 9710 | /// |
| 9715 | 9711 | /// The first instruction of `body_tail` is the one whose copy we want to elide. |
| 9716 | 9712 | fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool { |
| 9717 | | const o = fg.ng.object; |
| 9718 | | const zcu = o.pt.zcu; |
| 9713 | const zcu = fg.ng.pt.zcu; |
| 9719 | 9714 | const ip = &zcu.intern_pool; |
| 9720 | 9715 | for (body_tail[1..]) |body_inst| { |
| 9721 | 9716 | switch (fg.liveness.categorizeOperand(fg.air, zcu, body_inst, body_tail[0], ip)) { |
| ... | ... | @@ -9730,8 +9725,7 @@ pub const FuncGen = struct { |
| 9730 | 9725 | } |
| 9731 | 9726 | |
| 9732 | 9727 | fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 9733 | | const o = fg.ng.object; |
| 9734 | | const pt = o.pt; |
| 9728 | const pt = fg.ng.pt; |
| 9735 | 9729 | const zcu = pt.zcu; |
| 9736 | 9730 | const inst = body_tail[0]; |
| 9737 | 9731 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -9765,8 +9759,9 @@ pub const FuncGen = struct { |
| 9765 | 9759 | fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9766 | 9760 | _ = inst; |
| 9767 | 9761 | const o = self.ng.object; |
| 9768 | | const llvm_usize = try o.lowerType(Type.usize); |
| 9769 | | if (!target_util.supportsReturnAddress(o.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) { |
| 9762 | const pt = self.ng.pt; |
| 9763 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 9764 | if (!target_util.supportsReturnAddress(self.ng.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) { |
| 9770 | 9765 | // https://github.com/ziglang/zig/issues/11946 |
| 9771 | 9766 | return o.builder.intValue(llvm_usize, 0); |
| 9772 | 9767 | } |
| ... | ... | @@ -9777,8 +9772,9 @@ pub const FuncGen = struct { |
| 9777 | 9772 | fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9778 | 9773 | _ = inst; |
| 9779 | 9774 | const o = self.ng.object; |
| 9775 | const pt = self.ng.pt; |
| 9780 | 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 | 9780 | fn airCmpxchg( |
| ... | ... | @@ -9787,7 +9783,7 @@ pub const FuncGen = struct { |
| 9787 | 9783 | kind: Builder.Function.Instruction.CmpXchg.Kind, |
| 9788 | 9784 | ) !Builder.Value { |
| 9789 | 9785 | const o = self.ng.object; |
| 9790 | | const pt = o.pt; |
| 9786 | const pt = self.ng.pt; |
| 9791 | 9787 | const zcu = pt.zcu; |
| 9792 | 9788 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 9793 | 9789 | const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| ... | ... | @@ -9796,8 +9792,8 @@ pub const FuncGen = struct { |
| 9796 | 9792 | var expected_value = try self.resolveInst(extra.expected_value); |
| 9797 | 9793 | var new_value = try self.resolveInst(extra.new_value); |
| 9798 | 9794 | const operand_ty = ptr_ty.childType(zcu); |
| 9799 | | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 9800 | | const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false); |
| 9795 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 9796 | const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false); |
| 9801 | 9797 | if (llvm_abi_ty != .none) { |
| 9802 | 9798 | // operand needs widening and truncating |
| 9803 | 9799 | const signedness: Builder.Function.Instruction.Cast.Signedness = |
| ... | ... | @@ -9840,7 +9836,7 @@ pub const FuncGen = struct { |
| 9840 | 9836 | |
| 9841 | 9837 | fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9842 | 9838 | const o = self.ng.object; |
| 9843 | | const pt = o.pt; |
| 9839 | const pt = self.ng.pt; |
| 9844 | 9840 | const zcu = pt.zcu; |
| 9845 | 9841 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 9846 | 9842 | const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| ... | ... | @@ -9852,8 +9848,8 @@ pub const FuncGen = struct { |
| 9852 | 9848 | const is_float = operand_ty.isRuntimeFloat(); |
| 9853 | 9849 | const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float); |
| 9854 | 9850 | const ordering = toLlvmAtomicOrdering(extra.ordering()); |
| 9855 | | const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, op == .xchg); |
| 9856 | | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 9851 | const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, op == .xchg); |
| 9852 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 9857 | 9853 | |
| 9858 | 9854 | const access_kind: Builder.MemoryAccessKind = |
| 9859 | 9855 | if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; |
| ... | ... | @@ -9896,7 +9892,7 @@ pub const FuncGen = struct { |
| 9896 | 9892 | access_kind, |
| 9897 | 9893 | op, |
| 9898 | 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 | 9896 | self.sync_scope, |
| 9901 | 9897 | ordering, |
| 9902 | 9898 | ptr_alignment, |
| ... | ... | @@ -9906,7 +9902,7 @@ pub const FuncGen = struct { |
| 9906 | 9902 | |
| 9907 | 9903 | fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9908 | 9904 | const o = self.ng.object; |
| 9909 | | const pt = o.pt; |
| 9905 | const pt = self.ng.pt; |
| 9910 | 9906 | const zcu = pt.zcu; |
| 9911 | 9907 | const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; |
| 9912 | 9908 | const ptr = try self.resolveInst(atomic_load.ptr); |
| ... | ... | @@ -9915,14 +9911,14 @@ pub const FuncGen = struct { |
| 9915 | 9911 | const elem_ty = Type.fromInterned(info.child); |
| 9916 | 9912 | if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none; |
| 9917 | 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 | 9915 | const ptr_alignment = (if (info.flags.alignment != .none) |
| 9920 | 9916 | @as(InternPool.Alignment, info.flags.alignment) |
| 9921 | 9917 | else |
| 9922 | 9918 | Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm(); |
| 9923 | 9919 | const access_kind: Builder.MemoryAccessKind = |
| 9924 | 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 | 9923 | self.maybeMarkAllowZeroAccess(info); |
| 9928 | 9924 | |
| ... | ... | @@ -9956,7 +9952,7 @@ pub const FuncGen = struct { |
| 9956 | 9952 | ordering: Builder.AtomicOrdering, |
| 9957 | 9953 | ) !Builder.Value { |
| 9958 | 9954 | const o = self.ng.object; |
| 9959 | | const pt = o.pt; |
| 9955 | const pt = self.ng.pt; |
| 9960 | 9956 | const zcu = pt.zcu; |
| 9961 | 9957 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9962 | 9958 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -9964,7 +9960,7 @@ pub const FuncGen = struct { |
| 9964 | 9960 | if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none; |
| 9965 | 9961 | const ptr = try self.resolveInst(bin_op.lhs); |
| 9966 | 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 | 9965 | if (llvm_abi_ty != .none) { |
| 9970 | 9966 | // operand needs widening |
| ... | ... | @@ -9984,7 +9980,7 @@ pub const FuncGen = struct { |
| 9984 | 9980 | |
| 9985 | 9981 | fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9986 | 9982 | const o = self.ng.object; |
| 9987 | | const pt = o.pt; |
| 9983 | const pt = self.ng.pt; |
| 9988 | 9984 | const zcu = pt.zcu; |
| 9989 | 9985 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9990 | 9986 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -10081,13 +10077,13 @@ pub const FuncGen = struct { |
| 10081 | 10077 | const body_block = try self.wip.block(1, "InlineMemsetBody"); |
| 10082 | 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 | 10081 | const len = switch (ptr_ty.ptrSize(zcu)) { |
| 10086 | 10082 | .slice => try self.wip.extractValue(dest_slice, &.{1}, ""), |
| 10087 | 10083 | .one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)), |
| 10088 | 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 | 10087 | const end_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, dest_ptr, &.{len}, ""); |
| 10092 | 10088 | _ = try self.wip.br(loop_block); |
| 10093 | 10089 | |
| ... | ... | @@ -10121,8 +10117,7 @@ pub const FuncGen = struct { |
| 10121 | 10117 | } |
| 10122 | 10118 | |
| 10123 | 10119 | fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10124 | | const o = self.ng.object; |
| 10125 | | const pt = o.pt; |
| 10120 | const pt = self.ng.pt; |
| 10126 | 10121 | const zcu = pt.zcu; |
| 10127 | 10122 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 10128 | 10123 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -10151,8 +10146,7 @@ pub const FuncGen = struct { |
| 10151 | 10146 | } |
| 10152 | 10147 | |
| 10153 | 10148 | fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10154 | | const o = self.ng.object; |
| 10155 | | const pt = o.pt; |
| 10149 | const pt = self.ng.pt; |
| 10156 | 10150 | const zcu = pt.zcu; |
| 10157 | 10151 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 10158 | 10152 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -10178,7 +10172,7 @@ pub const FuncGen = struct { |
| 10178 | 10172 | |
| 10179 | 10173 | fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10180 | 10174 | const o = self.ng.object; |
| 10181 | | const pt = o.pt; |
| 10175 | const pt = self.ng.pt; |
| 10182 | 10176 | const zcu = pt.zcu; |
| 10183 | 10177 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 10184 | 10178 | const un_ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -10199,7 +10193,7 @@ pub const FuncGen = struct { |
| 10199 | 10193 | return .none; |
| 10200 | 10194 | } |
| 10201 | 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 | 10197 | // TODO alignment on this store |
| 10204 | 10198 | _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, .default); |
| 10205 | 10199 | return .none; |
| ... | ... | @@ -10207,7 +10201,7 @@ pub const FuncGen = struct { |
| 10207 | 10201 | |
| 10208 | 10202 | fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10209 | 10203 | const o = self.ng.object; |
| 10210 | | const pt = o.pt; |
| 10204 | const pt = self.ng.pt; |
| 10211 | 10205 | const zcu = pt.zcu; |
| 10212 | 10206 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10213 | 10207 | const un_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -10215,7 +10209,7 @@ pub const FuncGen = struct { |
| 10215 | 10209 | if (layout.tag_size == 0) return .none; |
| 10216 | 10210 | const union_handle = try self.resolveInst(ty_op.operand); |
| 10217 | 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 | 10213 | if (layout.payload_size == 0) |
| 10220 | 10214 | return self.wip.load(.normal, llvm_un_ty, union_handle, .default, ""); |
| 10221 | 10215 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| ... | ... | @@ -10247,6 +10241,7 @@ pub const FuncGen = struct { |
| 10247 | 10241 | |
| 10248 | 10242 | fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { |
| 10249 | 10243 | const o = self.ng.object; |
| 10244 | const pt = self.ng.pt; |
| 10250 | 10245 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10251 | 10246 | const inst_ty = self.typeOfIndex(inst); |
| 10252 | 10247 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -10256,15 +10251,16 @@ pub const FuncGen = struct { |
| 10256 | 10251 | .normal, |
| 10257 | 10252 | .none, |
| 10258 | 10253 | intrinsic, |
| 10259 | | &.{try o.lowerType(operand_ty)}, |
| 10254 | &.{try o.lowerType(pt, operand_ty)}, |
| 10260 | 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 | 10261 | fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { |
| 10267 | 10262 | const o = self.ng.object; |
| 10263 | const pt = self.ng.pt; |
| 10268 | 10264 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10269 | 10265 | const inst_ty = self.typeOfIndex(inst); |
| 10270 | 10266 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -10274,16 +10270,17 @@ pub const FuncGen = struct { |
| 10274 | 10270 | .normal, |
| 10275 | 10271 | .none, |
| 10276 | 10272 | intrinsic, |
| 10277 | | &.{try o.lowerType(operand_ty)}, |
| 10273 | &.{try o.lowerType(pt, operand_ty)}, |
| 10278 | 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 | 10280 | fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10285 | 10281 | const o = self.ng.object; |
| 10286 | | const zcu = o.pt.zcu; |
| 10282 | const pt = self.ng.pt; |
| 10283 | const zcu = pt.zcu; |
| 10287 | 10284 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10288 | 10285 | const operand_ty = self.typeOf(ty_op.operand); |
| 10289 | 10286 | var bits = operand_ty.intInfo(zcu).bits; |
| ... | ... | @@ -10291,7 +10288,7 @@ pub const FuncGen = struct { |
| 10291 | 10288 | |
| 10292 | 10289 | const inst_ty = self.typeOfIndex(inst); |
| 10293 | 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 | 10293 | if (bits % 16 == 8) { |
| 10297 | 10294 | // If not an even byte-multiple, we need zero-extend + shift-left 1 byte |
| ... | ... | @@ -10312,12 +10309,13 @@ pub const FuncGen = struct { |
| 10312 | 10309 | |
| 10313 | 10310 | const result = |
| 10314 | 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 | 10315 | fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10319 | 10316 | const o = self.ng.object; |
| 10320 | | const zcu = o.pt.zcu; |
| 10317 | const pt = self.ng.pt; |
| 10318 | const zcu = pt.zcu; |
| 10321 | 10319 | const ip = &zcu.intern_pool; |
| 10322 | 10320 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10323 | 10321 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -10332,7 +10330,7 @@ pub const FuncGen = struct { |
| 10332 | 10330 | |
| 10333 | 10331 | for (0..names.len) |name_index| { |
| 10334 | 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 | 10334 | try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip); |
| 10337 | 10335 | } |
| 10338 | 10336 | self.wip.cursor = .{ .block = valid_block }; |
| ... | ... | @@ -10367,7 +10365,7 @@ pub const FuncGen = struct { |
| 10367 | 10365 | |
| 10368 | 10366 | fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !Builder.Function.Index { |
| 10369 | 10367 | const o = self.ng.object; |
| 10370 | | const pt = o.pt; |
| 10368 | const pt = self.ng.pt; |
| 10371 | 10369 | const zcu = pt.zcu; |
| 10372 | 10370 | const ip = &zcu.intern_pool; |
| 10373 | 10371 | const enum_type = ip.loadEnumType(enum_ty.toIntern()); |
| ... | ... | @@ -10379,7 +10377,7 @@ pub const FuncGen = struct { |
| 10379 | 10377 | |
| 10380 | 10378 | const target = &zcu.root_mod.resolved_target.result; |
| 10381 | 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 | 10381 | try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_type.name.fmt(ip)}), |
| 10384 | 10382 | toLlvmAddressSpace(.generic, target), |
| 10385 | 10383 | ); |
| ... | ... | @@ -10408,6 +10406,7 @@ pub const FuncGen = struct { |
| 10408 | 10406 | |
| 10409 | 10407 | for (0..enum_type.names.len) |field_index| { |
| 10410 | 10408 | const this_tag_int_value = try o.lowerValue( |
| 10409 | pt, |
| 10411 | 10410 | (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(), |
| 10412 | 10411 | ); |
| 10413 | 10412 | try wip_switch.addCase(this_tag_int_value, named_block, &wip); |
| ... | ... | @@ -10424,11 +10423,12 @@ pub const FuncGen = struct { |
| 10424 | 10423 | |
| 10425 | 10424 | fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10426 | 10425 | const o = self.ng.object; |
| 10426 | const pt = self.ng.pt; |
| 10427 | 10427 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 10428 | 10428 | const operand = try self.resolveInst(un_op); |
| 10429 | 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 | 10432 | return self.wip.call( |
| 10433 | 10433 | .normal, |
| 10434 | 10434 | .fastcc, |
| ... | ... | @@ -10442,10 +10442,11 @@ pub const FuncGen = struct { |
| 10442 | 10442 | |
| 10443 | 10443 | fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10444 | 10444 | const o = self.ng.object; |
| 10445 | const pt = self.ng.pt; |
| 10445 | 10446 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 10446 | 10447 | const operand = try self.resolveInst(un_op); |
| 10447 | 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 | 10451 | const error_name_table_ptr = try self.getErrorNameTable(); |
| 10451 | 10452 | const error_name_table = |
| ... | ... | @@ -10457,10 +10458,11 @@ pub const FuncGen = struct { |
| 10457 | 10458 | |
| 10458 | 10459 | fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10459 | 10460 | const o = self.ng.object; |
| 10461 | const pt = self.ng.pt; |
| 10460 | 10462 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10461 | 10463 | const scalar = try self.resolveInst(ty_op.operand); |
| 10462 | 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 | 10468 | fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| ... | ... | @@ -10475,7 +10477,7 @@ pub const FuncGen = struct { |
| 10475 | 10477 | |
| 10476 | 10478 | fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10477 | 10479 | const o = fg.ng.object; |
| 10478 | | const pt = o.pt; |
| 10480 | const pt = fg.ng.pt; |
| 10479 | 10481 | const zcu = pt.zcu; |
| 10480 | 10482 | const gpa = zcu.gpa; |
| 10481 | 10483 | |
| ... | ... | @@ -10484,9 +10486,9 @@ pub const FuncGen = struct { |
| 10484 | 10486 | const operand = try fg.resolveInst(unwrapped.operand); |
| 10485 | 10487 | const mask = unwrapped.mask; |
| 10486 | 10488 | const operand_ty = fg.typeOf(unwrapped.operand); |
| 10487 | | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 10488 | | const llvm_result_ty = try o.lowerType(unwrapped.result_ty); |
| 10489 | | const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu)); |
| 10489 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 10490 | const llvm_result_ty = try o.lowerType(pt, unwrapped.result_ty); |
| 10491 | const llvm_elem_ty = try o.lowerType(pt, unwrapped.result_ty.childType(zcu)); |
| 10490 | 10492 | const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty); |
| 10491 | 10493 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); |
| 10492 | 10494 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); |
| ... | ... | @@ -10516,7 +10518,7 @@ pub const FuncGen = struct { |
| 10516 | 10518 | .elem => llvm_poison_elem, |
| 10517 | 10519 | .value => |val| if (!Value.fromInterned(val).isUndef(zcu)) elem: { |
| 10518 | 10520 | any_defined_comptime_value = true; |
| 10519 | | break :elem try o.lowerValue(val); |
| 10521 | break :elem try o.lowerValue(pt, val); |
| 10520 | 10522 | } else llvm_poison_elem, |
| 10521 | 10523 | }; |
| 10522 | 10524 | } |
| ... | ... | @@ -10582,14 +10584,14 @@ pub const FuncGen = struct { |
| 10582 | 10584 | |
| 10583 | 10585 | fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10584 | 10586 | const o = fg.ng.object; |
| 10585 | | const pt = o.pt; |
| 10587 | const pt = fg.ng.pt; |
| 10586 | 10588 | const zcu = pt.zcu; |
| 10587 | 10589 | const gpa = zcu.gpa; |
| 10588 | 10590 | |
| 10589 | 10591 | const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst); |
| 10590 | 10592 | |
| 10591 | 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 | 10595 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); |
| 10594 | 10596 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); |
| 10595 | 10597 | |
| ... | ... | @@ -10681,7 +10683,8 @@ pub const FuncGen = struct { |
| 10681 | 10683 | accum_init: Builder.Value, |
| 10682 | 10684 | ) !Builder.Value { |
| 10683 | 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 | 10688 | const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len); |
| 10686 | 10689 | const llvm_result_ty = accum_init.typeOfWip(&self.wip); |
| 10687 | 10690 | |
| ... | ... | @@ -10735,15 +10738,16 @@ pub const FuncGen = struct { |
| 10735 | 10738 | |
| 10736 | 10739 | fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 10737 | 10740 | const o = self.ng.object; |
| 10738 | | const zcu = o.pt.zcu; |
| 10741 | const pt = self.ng.pt; |
| 10742 | const zcu = pt.zcu; |
| 10739 | 10743 | const target = zcu.getTarget(); |
| 10740 | 10744 | |
| 10741 | 10745 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; |
| 10742 | 10746 | const operand = try self.resolveInst(reduce.operand); |
| 10743 | 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 | 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 | 10752 | switch (reduce.operation) { |
| 10749 | 10753 | .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) { |
| ... | ... | @@ -10845,14 +10849,14 @@ pub const FuncGen = struct { |
| 10845 | 10849 | |
| 10846 | 10850 | fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10847 | 10851 | const o = self.ng.object; |
| 10848 | | const pt = o.pt; |
| 10852 | const pt = self.ng.pt; |
| 10849 | 10853 | const zcu = pt.zcu; |
| 10850 | 10854 | const ip = &zcu.intern_pool; |
| 10851 | 10855 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 10852 | 10856 | const result_ty = self.typeOfIndex(inst); |
| 10853 | 10857 | const len: usize = @intCast(result_ty.arrayLen(zcu)); |
| 10854 | 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 | 10861 | switch (result_ty.zigTypeTag(zcu)) { |
| 10858 | 10862 | .vector => { |
| ... | ... | @@ -10933,7 +10937,7 @@ pub const FuncGen = struct { |
| 10933 | 10937 | .array => { |
| 10934 | 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 | 10941 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 10938 | 10942 | const alignment = result_ty.abiAlignment(zcu).toLlvm(); |
| 10939 | 10943 | const alloca_inst = try self.buildAlloca(llvm_result_ty, alignment); |
| ... | ... | @@ -10966,13 +10970,13 @@ pub const FuncGen = struct { |
| 10966 | 10970 | |
| 10967 | 10971 | fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10968 | 10972 | const o = self.ng.object; |
| 10969 | | const pt = o.pt; |
| 10973 | const pt = self.ng.pt; |
| 10970 | 10974 | const zcu = pt.zcu; |
| 10971 | 10975 | const ip = &zcu.intern_pool; |
| 10972 | 10976 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 10973 | 10977 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 10974 | 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 | 10980 | const layout = union_ty.unionGetLayout(zcu); |
| 10977 | 10981 | const union_obj = zcu.typeToUnion(union_ty).?; |
| 10978 | 10982 | |
| ... | ... | @@ -11014,10 +11018,10 @@ pub const FuncGen = struct { |
| 11014 | 11018 | const result_ptr = try self.buildAlloca(union_llvm_ty, alignment); |
| 11015 | 11019 | const llvm_payload = try self.resolveInst(extra.init); |
| 11016 | 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 | 11022 | const field_size = field_ty.abiSize(zcu); |
| 11019 | 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 | 11025 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 11022 | 11026 | |
| 11023 | 11027 | const llvm_union_ty = t: { |
| ... | ... | @@ -11035,7 +11039,7 @@ pub const FuncGen = struct { |
| 11035 | 11039 | }); |
| 11036 | 11040 | }; |
| 11037 | 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 | 11043 | var fields: [3]Builder.Type = undefined; |
| 11040 | 11044 | var fields_len: usize = 2; |
| 11041 | 11045 | if (layout.tag_align.compare(.gte, layout.payload_align)) { |
| ... | ... | @@ -11076,7 +11080,7 @@ pub const FuncGen = struct { |
| 11076 | 11080 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| 11077 | 11081 | const indices: [2]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, tag_index) }; |
| 11078 | 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 | 11084 | var big_int_space: Value.BigIntSpace = undefined; |
| 11081 | 11085 | const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu); |
| 11082 | 11086 | const llvm_tag = try o.builder.bigIntValue(tag_ty, tag_big_int); |
| ... | ... | @@ -11106,7 +11110,7 @@ pub const FuncGen = struct { |
| 11106 | 11110 | // by the target. |
| 11107 | 11111 | // To work around this, don't emit llvm.prefetch in this case. |
| 11108 | 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 | 11114 | const target = zcu.getTarget(); |
| 11111 | 11115 | switch (prefetch.cache) { |
| 11112 | 11116 | .instruction => switch (target.cpu.arch) { |
| ... | ... | @@ -11139,11 +11143,12 @@ pub const FuncGen = struct { |
| 11139 | 11143 | |
| 11140 | 11144 | fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11141 | 11145 | const o = self.ng.object; |
| 11146 | const pt = self.ng.pt; |
| 11142 | 11147 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 11143 | 11148 | const inst_ty = self.typeOfIndex(inst); |
| 11144 | 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 | 11154 | fn workIntrinsic( |
| ... | ... | @@ -11161,8 +11166,7 @@ pub const FuncGen = struct { |
| 11161 | 11166 | } |
| 11162 | 11167 | |
| 11163 | 11168 | fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11164 | | const o = self.ng.object; |
| 11165 | | const target = o.pt.zcu.getTarget(); |
| 11169 | const target = self.ng.pt.zcu.getTarget(); |
| 11166 | 11170 | |
| 11167 | 11171 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 11168 | 11172 | const dimension = pl_op.payload; |
| ... | ... | @@ -11176,7 +11180,8 @@ pub const FuncGen = struct { |
| 11176 | 11180 | |
| 11177 | 11181 | fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11178 | 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 | 11186 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 11182 | 11187 | const dimension = pl_op.payload; |
| ... | ... | @@ -11193,7 +11198,7 @@ pub const FuncGen = struct { |
| 11193 | 11198 | // Load the work_group_* member from the struct as u16. |
| 11194 | 11199 | // Just treat the dispatch pointer as an array of u16 to keep things simple. |
| 11195 | 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 | 11203 | const workgroup_size_alignment = comptime Builder.Alignment.fromByteUnits(2); |
| 11199 | 11204 | return self.wip.load(.normal, .i16, workgroup_size_ptr, workgroup_size_alignment, ""); |
| ... | ... | @@ -11206,8 +11211,7 @@ pub const FuncGen = struct { |
| 11206 | 11211 | } |
| 11207 | 11212 | |
| 11208 | 11213 | fn airWorkGroupId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11209 | | const o = self.ng.object; |
| 11210 | | const target = o.pt.zcu.getTarget(); |
| 11214 | const target = self.ng.pt.zcu.getTarget(); |
| 11211 | 11215 | |
| 11212 | 11216 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 11213 | 11217 | const dimension = pl_op.payload; |
| ... | ... | @@ -11221,7 +11225,7 @@ pub const FuncGen = struct { |
| 11221 | 11225 | |
| 11222 | 11226 | fn getErrorNameTable(self: *FuncGen) Allocator.Error!Builder.Variable.Index { |
| 11223 | 11227 | const o = self.ng.object; |
| 11224 | | const pt = o.pt; |
| 11228 | const pt = self.ng.pt; |
| 11225 | 11229 | |
| 11226 | 11230 | const table = o.error_name_table; |
| 11227 | 11231 | if (table != .none) return table; |
| ... | ... | @@ -11271,8 +11275,7 @@ pub const FuncGen = struct { |
| 11271 | 11275 | opt_ty: Type, |
| 11272 | 11276 | can_elide_load: bool, |
| 11273 | 11277 | ) !Builder.Value { |
| 11274 | | const o = fg.ng.object; |
| 11275 | | const pt = o.pt; |
| 11278 | const pt = fg.ng.pt; |
| 11276 | 11279 | const zcu = pt.zcu; |
| 11277 | 11280 | const payload_ty = opt_ty.optionalChild(zcu); |
| 11278 | 11281 | |
| ... | ... | @@ -11301,9 +11304,9 @@ pub const FuncGen = struct { |
| 11301 | 11304 | non_null_bit: Builder.Value, |
| 11302 | 11305 | ) !Builder.Value { |
| 11303 | 11306 | const o = self.ng.object; |
| 11304 | | const pt = o.pt; |
| 11307 | const pt = self.ng.pt; |
| 11305 | 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 | 11310 | const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, ""); |
| 11308 | 11311 | |
| 11309 | 11312 | if (isByRef(optional_ty, zcu)) { |
| ... | ... | @@ -11334,7 +11337,7 @@ pub const FuncGen = struct { |
| 11334 | 11337 | field_index: u32, |
| 11335 | 11338 | ) !Builder.Value { |
| 11336 | 11339 | const o = self.ng.object; |
| 11337 | | const pt = o.pt; |
| 11340 | const pt = self.ng.pt; |
| 11338 | 11341 | const zcu = pt.zcu; |
| 11339 | 11342 | const struct_ty = struct_ptr_ty.childType(zcu); |
| 11340 | 11343 | switch (struct_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -11357,12 +11360,12 @@ pub const FuncGen = struct { |
| 11357 | 11360 | // Offset our operand pointer by the correct number of bytes. |
| 11358 | 11361 | const byte_offset = @divExact(pt.structPackedFieldBitOffset(struct_type, field_index) + struct_ptr_ty_info.packed_offset.bit_offset, 8); |
| 11359 | 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 | 11364 | const llvm_index = try o.builder.intValue(usize_ty, byte_offset); |
| 11362 | 11365 | return self.wip.gep(.inbounds, .i8, struct_ptr, &.{llvm_index}, ""); |
| 11363 | 11366 | }, |
| 11364 | 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 | 11370 | if (o.llvmFieldIndex(struct_ty, field_index)) |llvm_field_index| { |
| 11368 | 11371 | return self.wip.gepStruct(struct_llvm_ty, struct_ptr, llvm_field_index, ""); |
| ... | ... | @@ -11372,7 +11375,7 @@ pub const FuncGen = struct { |
| 11372 | 11375 | // the index to the element at index `1` to get a pointer to the end of |
| 11373 | 11376 | // the struct. |
| 11374 | 11377 | const llvm_index = try o.builder.intValue( |
| 11375 | | try o.lowerType(Type.usize), |
| 11378 | try o.lowerType(pt, Type.usize), |
| 11376 | 11379 | @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)), |
| 11377 | 11380 | ); |
| 11378 | 11381 | return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, ""); |
| ... | ... | @@ -11383,7 +11386,7 @@ pub const FuncGen = struct { |
| 11383 | 11386 | const layout = struct_ty.unionGetLayout(zcu); |
| 11384 | 11387 | if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr; |
| 11385 | 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 | 11390 | return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, ""); |
| 11388 | 11391 | }, |
| 11389 | 11392 | else => unreachable, |
| ... | ... | @@ -11403,9 +11406,9 @@ pub const FuncGen = struct { |
| 11403 | 11406 | // => so load the byte aligned value and trunc the unwanted bits. |
| 11404 | 11407 | |
| 11405 | 11408 | const o = fg.ng.object; |
| 11406 | | const pt = o.pt; |
| 11409 | const pt = fg.ng.pt; |
| 11407 | 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 | 11412 | const abi_size = payload_ty.abiSize(zcu); |
| 11410 | 11413 | |
| 11411 | 11414 | // llvm bug workarounds: |
| ... | ... | @@ -11450,8 +11453,8 @@ pub const FuncGen = struct { |
| 11450 | 11453 | access_kind: Builder.MemoryAccessKind, |
| 11451 | 11454 | ) !Builder.Value { |
| 11452 | 11455 | const o = fg.ng.object; |
| 11453 | | const pt = o.pt; |
| 11454 | | const pointee_llvm_ty = try o.lowerType(pointee_type); |
| 11456 | const pt = fg.ng.pt; |
| 11457 | const pointee_llvm_ty = try o.lowerType(pt, pointee_type); |
| 11455 | 11458 | const result_align = InternPool.Alignment.fromLlvm(ptr_alignment) |
| 11456 | 11459 | .max(pointee_type.abiAlignment(pt.zcu)).toLlvm(); |
| 11457 | 11460 | const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align); |
| ... | ... | @@ -11461,7 +11464,7 @@ pub const FuncGen = struct { |
| 11461 | 11464 | result_align, |
| 11462 | 11465 | ptr, |
| 11463 | 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 | 11468 | access_kind, |
| 11466 | 11469 | fg.disable_intrinsics, |
| 11467 | 11470 | ); |
| ... | ... | @@ -11473,7 +11476,7 @@ pub const FuncGen = struct { |
| 11473 | 11476 | /// For isByRef=false types, it creates a load instruction and returns it. |
| 11474 | 11477 | fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value { |
| 11475 | 11478 | const o = self.ng.object; |
| 11476 | | const pt = o.pt; |
| 11479 | const pt = self.ng.pt; |
| 11477 | 11480 | const zcu = pt.zcu; |
| 11478 | 11481 | const info = ptr_ty.ptrInfo(zcu); |
| 11479 | 11482 | const elem_ty = Type.fromInterned(info.child); |
| ... | ... | @@ -11490,7 +11493,7 @@ pub const FuncGen = struct { |
| 11490 | 11493 | assert(info.flags.vector_index != .runtime); |
| 11491 | 11494 | if (info.flags.vector_index != .none) { |
| 11492 | 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 | 11497 | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); |
| 11495 | 11498 | |
| 11496 | 11499 | const loaded_vector = try self.wip.load(access_kind, vec_ty, ptr, ptr_alignment, ""); |
| ... | ... | @@ -11511,7 +11514,7 @@ pub const FuncGen = struct { |
| 11511 | 11514 | const elem_bits = ptr_ty.childType(zcu).bitSize(zcu); |
| 11512 | 11515 | const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset); |
| 11513 | 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 | 11519 | if (isByRef(elem_ty, zcu)) { |
| 11517 | 11520 | const result_align = elem_ty.abiAlignment(zcu).toLlvm(); |
| ... | ... | @@ -11546,7 +11549,7 @@ pub const FuncGen = struct { |
| 11546 | 11549 | ordering: Builder.AtomicOrdering, |
| 11547 | 11550 | ) !void { |
| 11548 | 11551 | const o = self.ng.object; |
| 11549 | | const pt = o.pt; |
| 11552 | const pt = self.ng.pt; |
| 11550 | 11553 | const zcu = pt.zcu; |
| 11551 | 11554 | const info = ptr_ty.ptrInfo(zcu); |
| 11552 | 11555 | const elem_ty = Type.fromInterned(info.child); |
| ... | ... | @@ -11560,7 +11563,7 @@ pub const FuncGen = struct { |
| 11560 | 11563 | assert(info.flags.vector_index != .runtime); |
| 11561 | 11564 | if (info.flags.vector_index != .none) { |
| 11562 | 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 | 11567 | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); |
| 11565 | 11568 | |
| 11566 | 11569 | const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, ""); |
| ... | ... | @@ -11629,7 +11632,7 @@ pub const FuncGen = struct { |
| 11629 | 11632 | ptr_alignment, |
| 11630 | 11633 | elem, |
| 11631 | 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 | 11636 | access_kind, |
| 11634 | 11637 | self.disable_intrinsics, |
| 11635 | 11638 | ); |
| ... | ... | @@ -11638,7 +11641,8 @@ pub const FuncGen = struct { |
| 11638 | 11641 | fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void { |
| 11639 | 11642 | const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545; |
| 11640 | 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 | 11646 | const zero = try o.builder.intValue(usize_ty, 0); |
| 11643 | 11647 | const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED); |
| 11644 | 11648 | const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, ""); |
| ... | ... | @@ -11656,12 +11660,12 @@ pub const FuncGen = struct { |
| 11656 | 11660 | a5: Builder.Value, |
| 11657 | 11661 | ) Allocator.Error!Builder.Value { |
| 11658 | 11662 | const o = fg.ng.object; |
| 11659 | | const pt = o.pt; |
| 11663 | const pt = fg.ng.pt; |
| 11660 | 11664 | const zcu = pt.zcu; |
| 11661 | 11665 | const target = zcu.getTarget(); |
| 11662 | 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 | 11669 | const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm(); |
| 11666 | 11670 | |
| 11667 | 11671 | const array_llvm_ty = try o.builder.arrayType(6, llvm_usize); |
| ... | ... | @@ -11787,14 +11791,12 @@ pub const FuncGen = struct { |
| 11787 | 11791 | } |
| 11788 | 11792 | |
| 11789 | 11793 | fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type { |
| 11790 | | const o = fg.ng.object; |
| 11791 | | const zcu = o.pt.zcu; |
| 11794 | const zcu = fg.ng.pt.zcu; |
| 11792 | 11795 | return fg.air.typeOf(inst, &zcu.intern_pool); |
| 11793 | 11796 | } |
| 11794 | 11797 | |
| 11795 | 11798 | fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type { |
| 11796 | | const o = fg.ng.object; |
| 11797 | | const zcu = o.pt.zcu; |
| 11799 | const zcu = fg.ng.pt.zcu; |
| 11798 | 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 | 12154 | /// In order to support the C calling convention, some return types need to be lowered |
| 12153 | 12155 | /// completely differently in the function prototype to honor the C ABI, and then |
| 12154 | 12156 | /// be effectively bitcasted to the actual return type. |
| 12155 | | fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12156 | | const pt = o.pt; |
| 12157 | fn lowerFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12157 | 12158 | const zcu = pt.zcu; |
| 12158 | 12159 | const return_type = Type.fromInterned(fn_info.return_type); |
| 12159 | 12160 | if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 12160 | 12161 | // If the return type is an error set or an error union, then we make this |
| 12161 | 12162 | // anyerror return type instead, so that it can be coerced into a function |
| 12162 | 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 | 12166 | const target = zcu.getTarget(); |
| 12166 | 12167 | switch (fn_info.cc) { |
| 12167 | 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_win => return lowerWin64FnRetTy(o, fn_info), |
| 12172 | | .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(return_type) else .void, |
| 12173 | | .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(return_type), |
| 12171 | .x86_64_sysv => return lowerSystemVFnRetTy(o, pt, fn_info), |
| 12172 | .x86_64_win => return lowerWin64FnRetTy(o, pt, fn_info), |
| 12173 | .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(pt, return_type) else .void, |
| 12174 | .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(pt, return_type), |
| 12174 | 12175 | .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win => switch (aarch64_c_abi.classifyType(return_type, zcu)) { |
| 12175 | 12176 | .memory => return .void, |
| 12176 | | .float_array => return o.lowerType(return_type), |
| 12177 | | .byval => return o.lowerType(return_type), |
| 12177 | .float_array => return o.lowerType(pt, return_type), |
| 12178 | .byval => return o.lowerType(pt, return_type), |
| 12178 | 12179 | .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))), |
| 12179 | 12180 | .double_integer => return o.builder.arrayType(2, .i64), |
| 12180 | 12181 | }, |
| 12181 | 12182 | .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) { |
| 12182 | 12183 | .memory, .i64_array => return .void, |
| 12183 | 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 | 12187 | .mips_o32 => switch (mips_c_abi.classifyType(return_type, zcu, .ret)) { |
| 12187 | 12188 | .memory, .i32_array => return .void, |
| 12188 | | .byval => return o.lowerType(return_type), |
| 12189 | .byval => return o.lowerType(pt, return_type), |
| 12189 | 12190 | }, |
| 12190 | 12191 | .riscv64_lp64, .riscv32_ilp32 => switch (riscv_c_abi.classifyType(return_type, zcu)) { |
| 12191 | 12192 | .memory => return .void, |
| ... | ... | @@ -12195,53 +12196,52 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu |
| 12195 | 12196 | .double_integer => { |
| 12196 | 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 | 12200 | .fields => { |
| 12200 | 12201 | var types_len: usize = 0; |
| 12201 | 12202 | var types: [8]Builder.Type = undefined; |
| 12202 | 12203 | for (0..return_type.structFieldCount(zcu)) |field_index| { |
| 12203 | 12204 | const field_ty = return_type.fieldType(field_index, zcu); |
| 12204 | 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 | 12207 | types_len += 1; |
| 12207 | 12208 | } |
| 12208 | 12209 | return o.builder.structType(.normal, types[0..types_len]); |
| 12209 | 12210 | }, |
| 12210 | 12211 | }, |
| 12211 | 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 | 12214 | .indirect => return .void, |
| 12214 | 12215 | }, |
| 12215 | 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 | | const zcu = o.pt.zcu; |
| 12221 | fn lowerWin64FnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12222 | const zcu = pt.zcu; |
| 12222 | 12223 | const return_type = Type.fromInterned(fn_info.return_type); |
| 12223 | 12224 | switch (x86_64_abi.classifyWindows(return_type, zcu, zcu.getTarget())) { |
| 12224 | 12225 | .integer => { |
| 12225 | 12226 | if (isScalar(zcu, return_type)) { |
| 12226 | | return o.lowerType(return_type); |
| 12227 | return o.lowerType(pt, return_type); |
| 12227 | 12228 | } else { |
| 12228 | 12229 | return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8)); |
| 12229 | 12230 | } |
| 12230 | 12231 | }, |
| 12231 | 12232 | .win_i128 => return o.builder.vectorType(.normal, 2, .i64), |
| 12232 | 12233 | .memory => return .void, |
| 12233 | | .sse => return o.lowerType(return_type), |
| 12234 | .sse => return o.lowerType(pt, return_type), |
| 12234 | 12235 | else => unreachable, |
| 12235 | 12236 | } |
| 12236 | 12237 | } |
| 12237 | 12238 | |
| 12238 | | fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12239 | | const pt = o.pt; |
| 12239 | fn lowerSystemVFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12240 | 12240 | const zcu = pt.zcu; |
| 12241 | 12241 | const ip = &zcu.intern_pool; |
| 12242 | 12242 | const return_type = Type.fromInterned(fn_info.return_type); |
| 12243 | 12243 | if (isScalar(zcu, return_type)) { |
| 12244 | | return o.lowerType(return_type); |
| 12244 | return o.lowerType(pt, return_type); |
| 12245 | 12245 | } |
| 12246 | 12246 | const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret); |
| 12247 | 12247 | var types_index: u32 = 0; |
| ... | ... | @@ -12305,6 +12305,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E |
| 12305 | 12305 | |
| 12306 | 12306 | const ParamTypeIterator = struct { |
| 12307 | 12307 | object: *Object, |
| 12308 | pt: Zcu.PerThread, |
| 12308 | 12309 | fn_info: InternPool.Key.FuncType, |
| 12309 | 12310 | zig_index: u32, |
| 12310 | 12311 | llvm_index: u32, |
| ... | ... | @@ -12327,7 +12328,7 @@ const ParamTypeIterator = struct { |
| 12327 | 12328 | |
| 12328 | 12329 | pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering { |
| 12329 | 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 | 12332 | const ty = it.fn_info.param_types.get(ip)[it.zig_index]; |
| 12332 | 12333 | it.byval_attr = false; |
| 12333 | 12334 | return nextInner(it, Type.fromInterned(ty)); |
| ... | ... | @@ -12335,7 +12336,8 @@ const ParamTypeIterator = struct { |
| 12335 | 12336 | |
| 12336 | 12337 | /// `airCall` uses this instead of `next` so that it can take into account variadic functions. |
| 12337 | 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 | 12341 | if (it.zig_index >= it.fn_info.param_types.len) { |
| 12340 | 12342 | if (it.zig_index >= args.len) { |
| 12341 | 12343 | return null; |
| ... | ... | @@ -12348,7 +12350,7 @@ const ParamTypeIterator = struct { |
| 12348 | 12350 | } |
| 12349 | 12351 | |
| 12350 | 12352 | fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { |
| 12351 | | const pt = it.object.pt; |
| 12353 | const pt = it.pt; |
| 12352 | 12354 | const zcu = pt.zcu; |
| 12353 | 12355 | const target = zcu.getTarget(); |
| 12354 | 12356 | |
| ... | ... | @@ -12448,7 +12450,7 @@ const ParamTypeIterator = struct { |
| 12448 | 12450 | for (0..ty.structFieldCount(zcu)) |field_index| { |
| 12449 | 12451 | const field_ty = ty.fieldType(field_index, zcu); |
| 12450 | 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 | 12454 | it.types_len += 1; |
| 12453 | 12455 | } |
| 12454 | 12456 | it.llvm_index += it.types_len - 1; |
| ... | ... | @@ -12464,7 +12466,7 @@ const ParamTypeIterator = struct { |
| 12464 | 12466 | return .byval; |
| 12465 | 12467 | } else { |
| 12466 | 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 | 12470 | it.types_buffer = types_buffer; |
| 12469 | 12471 | it.types_len = 1; |
| 12470 | 12472 | it.llvm_index += 1; |
| ... | ... | @@ -12489,7 +12491,7 @@ const ParamTypeIterator = struct { |
| 12489 | 12491 | } |
| 12490 | 12492 | |
| 12491 | 12493 | fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering { |
| 12492 | | const zcu = it.object.pt.zcu; |
| 12494 | const zcu = it.pt.zcu; |
| 12493 | 12495 | switch (x86_64_abi.classifyWindows(ty, zcu, zcu.getTarget())) { |
| 12494 | 12496 | .integer => { |
| 12495 | 12497 | if (isScalar(zcu, ty)) { |
| ... | ... | @@ -12522,7 +12524,7 @@ const ParamTypeIterator = struct { |
| 12522 | 12524 | } |
| 12523 | 12525 | |
| 12524 | 12526 | fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { |
| 12525 | | const zcu = it.object.pt.zcu; |
| 12527 | const zcu = it.pt.zcu; |
| 12526 | 12528 | const ip = &zcu.intern_pool; |
| 12527 | 12529 | const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg); |
| 12528 | 12530 | if (classes[0] == .memory) { |
| ... | ... | @@ -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 | 12621 | return .{ |
| 12620 | 12622 | .object = object, |
| 12623 | .pt = pt, |
| 12621 | 12624 | .fn_info = fn_info, |
| 12622 | 12625 | .zig_index = 0, |
| 12623 | 12626 | .llvm_index = 0, |
| ... | ... | @@ -12896,6 +12899,26 @@ fn compilerRtIntBits(bits: u16) u16 { |
| 12896 | 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 | 12922 | fn buildAllocaInner( |
| 12900 | 12923 | wip: *Builder.WipFunction, |
| 12901 | 12924 | llvm_ty: Builder.Type, |