| ... | ... | @@ -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,13 @@ 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 | fn getDebugFile(o: *Object, pt: Zcu.PerThread, file_index: Zcu.File.Index) Allocator.Error!Builder.Metadata { |
| 1765 | 1758 | const gpa = o.gpa; |
| 1766 | 1759 | const gop = try o.debug_file_map.getOrPut(gpa, file_index); |
| 1767 | 1760 | errdefer assert(o.debug_file_map.remove(file_index)); |
| 1768 | 1761 | if (gop.found_existing) return gop.value_ptr.*; |
| 1769 | | const zcu = o.pt.zcu; |
| 1770 | | const path = zcu.fileByIndex(file_index).path; |
| 1771 | | const abs_path = try path.toAbsolute(zcu.comp.dirs, gpa); |
| 1762 | const path = pt.zcu.fileByIndex(file_index).path; |
| 1763 | const abs_path = try path.toAbsolute(pt.zcu.comp.dirs, gpa); |
| 1772 | 1764 | defer gpa.free(abs_path); |
| 1773 | 1765 | |
| 1774 | 1766 | gop.value_ptr.* = try o.builder.debugFile( |
| ... | ... | @@ -1780,13 +1772,13 @@ pub const Object = struct { |
| 1780 | 1772 | |
| 1781 | 1773 | pub fn lowerDebugType( |
| 1782 | 1774 | o: *Object, |
| 1775 | pt: Zcu.PerThread, |
| 1783 | 1776 | ty: Type, |
| 1784 | 1777 | ) Allocator.Error!Builder.Metadata { |
| 1785 | 1778 | assert(!o.builder.strip); |
| 1786 | 1779 | |
| 1787 | 1780 | const gpa = o.gpa; |
| 1788 | 1781 | const target = o.target; |
| 1789 | | const pt = o.pt; |
| 1790 | 1782 | const zcu = pt.zcu; |
| 1791 | 1783 | const ip = &zcu.intern_pool; |
| 1792 | 1784 | |
| ... | ... | @@ -1806,7 +1798,7 @@ pub const Object = struct { |
| 1806 | 1798 | .int => { |
| 1807 | 1799 | const info = ty.intInfo(zcu); |
| 1808 | 1800 | assert(info.bits != 0); |
| 1809 | | const name = try o.allocTypeName(ty); |
| 1801 | const name = try o.allocTypeName(pt, ty); |
| 1810 | 1802 | defer gpa.free(name); |
| 1811 | 1803 | const builder_name = try o.builder.metadataString(name); |
| 1812 | 1804 | const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types |
| ... | ... | @@ -1819,7 +1811,7 @@ pub const Object = struct { |
| 1819 | 1811 | }, |
| 1820 | 1812 | .@"enum" => { |
| 1821 | 1813 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 1822 | | const debug_enum_type = try o.makeEmptyNamespaceDebugType(ty); |
| 1814 | const debug_enum_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 1823 | 1815 | try o.debug_type_map.put(gpa, ty, debug_enum_type); |
| 1824 | 1816 | return debug_enum_type; |
| 1825 | 1817 | } |
| ... | ... | @@ -1847,13 +1839,13 @@ pub const Object = struct { |
| 1847 | 1839 | ); |
| 1848 | 1840 | } |
| 1849 | 1841 | |
| 1850 | | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); |
| 1842 | const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); |
| 1851 | 1843 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 1852 | | try o.namespaceToDebugScope(parent_namespace) |
| 1844 | try o.namespaceToDebugScope(pt, parent_namespace) |
| 1853 | 1845 | else |
| 1854 | 1846 | file; |
| 1855 | 1847 | |
| 1856 | | const name = try o.allocTypeName(ty); |
| 1848 | const name = try o.allocTypeName(pt, ty); |
| 1857 | 1849 | defer gpa.free(name); |
| 1858 | 1850 | |
| 1859 | 1851 | const debug_enum_type = try o.builder.debugEnumerationType( |
| ... | ... | @@ -1861,7 +1853,7 @@ pub const Object = struct { |
| 1861 | 1853 | file, |
| 1862 | 1854 | scope, |
| 1863 | 1855 | ty.typeDeclSrcLine(zcu).? + 1, // Line |
| 1864 | | try o.lowerDebugType(int_ty), |
| 1856 | try o.lowerDebugType(pt, int_ty), |
| 1865 | 1857 | ty.abiSize(zcu) * 8, |
| 1866 | 1858 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 1867 | 1859 | try o.builder.metadataTuple(enumerators), |
| ... | ... | @@ -1873,7 +1865,7 @@ pub const Object = struct { |
| 1873 | 1865 | }, |
| 1874 | 1866 | .float => { |
| 1875 | 1867 | const bits = ty.floatBits(target); |
| 1876 | | const name = try o.allocTypeName(ty); |
| 1868 | const name = try o.allocTypeName(pt, ty); |
| 1877 | 1869 | defer gpa.free(name); |
| 1878 | 1870 | const debug_float_type = try o.builder.debugFloatType( |
| 1879 | 1871 | try o.builder.metadataString(name), |
| ... | ... | @@ -1918,7 +1910,7 @@ pub const Object = struct { |
| 1918 | 1910 | }, |
| 1919 | 1911 | }, |
| 1920 | 1912 | }); |
| 1921 | | const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty); |
| 1913 | const debug_ptr_type = try o.lowerDebugType(pt, bland_ptr_ty); |
| 1922 | 1914 | try o.debug_type_map.put(gpa, ty, debug_ptr_type); |
| 1923 | 1915 | return debug_ptr_type; |
| 1924 | 1916 | } |
| ... | ... | @@ -1932,7 +1924,7 @@ pub const Object = struct { |
| 1932 | 1924 | const ptr_ty = ty.slicePtrFieldType(zcu); |
| 1933 | 1925 | const len_ty = Type.usize; |
| 1934 | 1926 | |
| 1935 | | const name = try o.allocTypeName(ty); |
| 1927 | const name = try o.allocTypeName(pt, ty); |
| 1936 | 1928 | defer gpa.free(name); |
| 1937 | 1929 | const line = 0; |
| 1938 | 1930 | |
| ... | ... | @@ -1948,7 +1940,7 @@ pub const Object = struct { |
| 1948 | 1940 | .none, // File |
| 1949 | 1941 | debug_fwd_ref, |
| 1950 | 1942 | 0, // Line |
| 1951 | | try o.lowerDebugType(ptr_ty), |
| 1943 | try o.lowerDebugType(pt, ptr_ty), |
| 1952 | 1944 | ptr_size * 8, |
| 1953 | 1945 | (ptr_align.toByteUnits() orelse 0) * 8, |
| 1954 | 1946 | 0, // Offset |
| ... | ... | @@ -1959,7 +1951,7 @@ pub const Object = struct { |
| 1959 | 1951 | .none, // File |
| 1960 | 1952 | debug_fwd_ref, |
| 1961 | 1953 | 0, // Line |
| 1962 | | try o.lowerDebugType(len_ty), |
| 1954 | try o.lowerDebugType(pt, len_ty), |
| 1963 | 1955 | len_size * 8, |
| 1964 | 1956 | (len_align.toByteUnits() orelse 0) * 8, |
| 1965 | 1957 | len_offset * 8, |
| ... | ... | @@ -1988,9 +1980,9 @@ pub const Object = struct { |
| 1988 | 1980 | return debug_slice_type; |
| 1989 | 1981 | } |
| 1990 | 1982 | |
| 1991 | | const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child)); |
| 1983 | const debug_elem_ty = try o.lowerDebugType(pt, Type.fromInterned(ptr_info.child)); |
| 1992 | 1984 | |
| 1993 | | const name = try o.allocTypeName(ty); |
| 1985 | const name = try o.allocTypeName(pt, ty); |
| 1994 | 1986 | defer gpa.free(name); |
| 1995 | 1987 | |
| 1996 | 1988 | const debug_ptr_type = try o.builder.debugPointerType( |
| ... | ... | @@ -2022,12 +2014,12 @@ pub const Object = struct { |
| 2022 | 2014 | return debug_opaque_type; |
| 2023 | 2015 | } |
| 2024 | 2016 | |
| 2025 | | const name = try o.allocTypeName(ty); |
| 2017 | const name = try o.allocTypeName(pt, ty); |
| 2026 | 2018 | defer gpa.free(name); |
| 2027 | 2019 | |
| 2028 | | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); |
| 2020 | const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); |
| 2029 | 2021 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 2030 | | try o.namespaceToDebugScope(parent_namespace) |
| 2022 | try o.namespaceToDebugScope(pt, parent_namespace) |
| 2031 | 2023 | else |
| 2032 | 2024 | file; |
| 2033 | 2025 | |
| ... | ... | @@ -2050,7 +2042,7 @@ pub const Object = struct { |
| 2050 | 2042 | .none, // File |
| 2051 | 2043 | .none, // Scope |
| 2052 | 2044 | 0, // Line |
| 2053 | | try o.lowerDebugType(ty.childType(zcu)), |
| 2045 | try o.lowerDebugType(pt, ty.childType(zcu)), |
| 2054 | 2046 | ty.abiSize(zcu) * 8, |
| 2055 | 2047 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2056 | 2048 | try o.builder.metadataTuple(&.{ |
| ... | ... | @@ -2073,7 +2065,7 @@ pub const Object = struct { |
| 2073 | 2065 | .int => blk: { |
| 2074 | 2066 | const info = elem_ty.intInfo(zcu); |
| 2075 | 2067 | assert(info.bits != 0); |
| 2076 | | const name = try o.allocTypeName(ty); |
| 2068 | const name = try o.allocTypeName(pt, ty); |
| 2077 | 2069 | defer gpa.free(name); |
| 2078 | 2070 | const builder_name = try o.builder.metadataString(name); |
| 2079 | 2071 | break :blk switch (info.signedness) { |
| ... | ... | @@ -2085,7 +2077,7 @@ pub const Object = struct { |
| 2085 | 2077 | try o.builder.metadataString("bool"), |
| 2086 | 2078 | 1, |
| 2087 | 2079 | ), |
| 2088 | | else => try o.lowerDebugType(ty.childType(zcu)), |
| 2080 | else => try o.lowerDebugType(pt, ty.childType(zcu)), |
| 2089 | 2081 | }; |
| 2090 | 2082 | |
| 2091 | 2083 | const debug_vector_type = try o.builder.debugVectorType( |
| ... | ... | @@ -2108,7 +2100,7 @@ pub const Object = struct { |
| 2108 | 2100 | return debug_vector_type; |
| 2109 | 2101 | }, |
| 2110 | 2102 | .optional => { |
| 2111 | | const name = try o.allocTypeName(ty); |
| 2103 | const name = try o.allocTypeName(pt, ty); |
| 2112 | 2104 | defer gpa.free(name); |
| 2113 | 2105 | const child_ty = ty.optionalChild(zcu); |
| 2114 | 2106 | if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| ... | ... | @@ -2126,7 +2118,7 @@ pub const Object = struct { |
| 2126 | 2118 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); |
| 2127 | 2119 | |
| 2128 | 2120 | if (ty.optionalReprIsPayload(zcu)) { |
| 2129 | | const debug_optional_type = try o.lowerDebugType(child_ty); |
| 2121 | const debug_optional_type = try o.lowerDebugType(pt, child_ty); |
| 2130 | 2122 | |
| 2131 | 2123 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); |
| 2132 | 2124 | |
| ... | ... | @@ -2149,7 +2141,7 @@ pub const Object = struct { |
| 2149 | 2141 | .none, // File |
| 2150 | 2142 | debug_fwd_ref, |
| 2151 | 2143 | 0, // Line |
| 2152 | | try o.lowerDebugType(child_ty), |
| 2144 | try o.lowerDebugType(pt, child_ty), |
| 2153 | 2145 | payload_size * 8, |
| 2154 | 2146 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2155 | 2147 | 0, // Offset |
| ... | ... | @@ -2160,7 +2152,7 @@ pub const Object = struct { |
| 2160 | 2152 | .none, |
| 2161 | 2153 | debug_fwd_ref, |
| 2162 | 2154 | 0, |
| 2163 | | try o.lowerDebugType(non_null_ty), |
| 2155 | try o.lowerDebugType(pt, non_null_ty), |
| 2164 | 2156 | non_null_size * 8, |
| 2165 | 2157 | (non_null_align.toByteUnits() orelse 0) * 8, |
| 2166 | 2158 | non_null_offset * 8, |
| ... | ... | @@ -2192,12 +2184,12 @@ pub const Object = struct { |
| 2192 | 2184 | const payload_ty = ty.errorUnionPayload(zcu); |
| 2193 | 2185 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2194 | 2186 | // TODO: Maybe remove? |
| 2195 | | const debug_error_union_type = try o.lowerDebugType(Type.anyerror); |
| 2187 | const debug_error_union_type = try o.lowerDebugType(pt, Type.anyerror); |
| 2196 | 2188 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); |
| 2197 | 2189 | return debug_error_union_type; |
| 2198 | 2190 | } |
| 2199 | 2191 | |
| 2200 | | const name = try o.allocTypeName(ty); |
| 2192 | const name = try o.allocTypeName(pt, ty); |
| 2201 | 2193 | defer gpa.free(name); |
| 2202 | 2194 | |
| 2203 | 2195 | const error_size = Type.anyerror.abiSize(zcu); |
| ... | ... | @@ -2229,7 +2221,7 @@ pub const Object = struct { |
| 2229 | 2221 | .none, // File |
| 2230 | 2222 | debug_fwd_ref, |
| 2231 | 2223 | 0, // Line |
| 2232 | | try o.lowerDebugType(Type.anyerror), |
| 2224 | try o.lowerDebugType(pt, Type.anyerror), |
| 2233 | 2225 | error_size * 8, |
| 2234 | 2226 | (error_align.toByteUnits() orelse 0) * 8, |
| 2235 | 2227 | error_offset * 8, |
| ... | ... | @@ -2239,7 +2231,7 @@ pub const Object = struct { |
| 2239 | 2231 | .none, // File |
| 2240 | 2232 | debug_fwd_ref, |
| 2241 | 2233 | 0, // Line |
| 2242 | | try o.lowerDebugType(payload_ty), |
| 2234 | try o.lowerDebugType(pt, payload_ty), |
| 2243 | 2235 | payload_size * 8, |
| 2244 | 2236 | (payload_align.toByteUnits() orelse 0) * 8, |
| 2245 | 2237 | payload_offset * 8, |
| ... | ... | @@ -2270,7 +2262,7 @@ pub const Object = struct { |
| 2270 | 2262 | return debug_error_set; |
| 2271 | 2263 | }, |
| 2272 | 2264 | .@"struct" => { |
| 2273 | | const name = try o.allocTypeName(ty); |
| 2265 | const name = try o.allocTypeName(pt, ty); |
| 2274 | 2266 | defer gpa.free(name); |
| 2275 | 2267 | |
| 2276 | 2268 | if (zcu.typeToPackedStruct(ty)) |struct_type| { |
| ... | ... | @@ -2315,7 +2307,7 @@ pub const Object = struct { |
| 2315 | 2307 | .none, // File |
| 2316 | 2308 | debug_fwd_ref, |
| 2317 | 2309 | 0, |
| 2318 | | try o.lowerDebugType(Type.fromInterned(field_ty)), |
| 2310 | try o.lowerDebugType(pt, Type.fromInterned(field_ty)), |
| 2319 | 2311 | field_size * 8, |
| 2320 | 2312 | (field_align.toByteUnits() orelse 0) * 8, |
| 2321 | 2313 | field_offset * 8, |
| ... | ... | @@ -2347,7 +2339,7 @@ pub const Object = struct { |
| 2347 | 2339 | // into. Therefore we can satisfy this by making an empty namespace, |
| 2348 | 2340 | // rather than changing the frontend to unnecessarily resolve the |
| 2349 | 2341 | // struct field types. |
| 2350 | | const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty); |
| 2342 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2351 | 2343 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2352 | 2344 | return debug_struct_type; |
| 2353 | 2345 | } |
| ... | ... | @@ -2356,7 +2348,7 @@ pub const Object = struct { |
| 2356 | 2348 | } |
| 2357 | 2349 | |
| 2358 | 2350 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2359 | | const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty); |
| 2351 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2360 | 2352 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2361 | 2353 | return debug_struct_type; |
| 2362 | 2354 | } |
| ... | ... | @@ -2388,7 +2380,7 @@ pub const Object = struct { |
| 2388 | 2380 | .none, // File |
| 2389 | 2381 | debug_fwd_ref, |
| 2390 | 2382 | 0, // Line |
| 2391 | | try o.lowerDebugType(field_ty), |
| 2383 | try o.lowerDebugType(pt, field_ty), |
| 2392 | 2384 | field_size * 8, |
| 2393 | 2385 | (field_align.toByteUnits() orelse 0) * 8, |
| 2394 | 2386 | field_offset * 8, |
| ... | ... | @@ -2415,7 +2407,7 @@ pub const Object = struct { |
| 2415 | 2407 | return debug_struct_type; |
| 2416 | 2408 | }, |
| 2417 | 2409 | .@"union" => { |
| 2418 | | const name = try o.allocTypeName(ty); |
| 2410 | const name = try o.allocTypeName(pt, ty); |
| 2419 | 2411 | defer gpa.free(name); |
| 2420 | 2412 | |
| 2421 | 2413 | const union_type = ip.loadUnionType(ty.toIntern()); |
| ... | ... | @@ -2423,7 +2415,7 @@ pub const Object = struct { |
| 2423 | 2415 | !ty.hasRuntimeBitsIgnoreComptime(zcu) or |
| 2424 | 2416 | !union_type.haveLayout(ip)) |
| 2425 | 2417 | { |
| 2426 | | const debug_union_type = try o.makeEmptyNamespaceDebugType(ty); |
| 2418 | const debug_union_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2427 | 2419 | try o.debug_type_map.put(gpa, ty, debug_union_type); |
| 2428 | 2420 | return debug_union_type; |
| 2429 | 2421 | } |
| ... | ... | @@ -2445,7 +2437,7 @@ pub const Object = struct { |
| 2445 | 2437 | ty.abiSize(zcu) * 8, |
| 2446 | 2438 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2447 | 2439 | try o.builder.metadataTuple( |
| 2448 | | &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))}, |
| 2440 | &.{try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty))}, |
| 2449 | 2441 | ), |
| 2450 | 2442 | ); |
| 2451 | 2443 | |
| ... | ... | @@ -2484,7 +2476,7 @@ pub const Object = struct { |
| 2484 | 2476 | .none, // File |
| 2485 | 2477 | debug_union_fwd_ref, |
| 2486 | 2478 | 0, // Line |
| 2487 | | try o.lowerDebugType(Type.fromInterned(field_ty)), |
| 2479 | try o.lowerDebugType(pt, Type.fromInterned(field_ty)), |
| 2488 | 2480 | field_size * 8, |
| 2489 | 2481 | (field_align.toByteUnits() orelse 0) * 8, |
| 2490 | 2482 | 0, // Offset |
| ... | ... | @@ -2534,7 +2526,7 @@ pub const Object = struct { |
| 2534 | 2526 | .none, // File |
| 2535 | 2527 | debug_fwd_ref, |
| 2536 | 2528 | 0, // Line |
| 2537 | | try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)), |
| 2529 | try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty)), |
| 2538 | 2530 | layout.tag_size * 8, |
| 2539 | 2531 | (layout.tag_align.toByteUnits() orelse 0) * 8, |
| 2540 | 2532 | tag_offset * 8, |
| ... | ... | @@ -2588,19 +2580,19 @@ pub const Object = struct { |
| 2588 | 2580 | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2589 | 2581 | const sret = firstParamSRet(fn_info, zcu, target); |
| 2590 | 2582 | const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type); |
| 2591 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty)); |
| 2583 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ret_ty)); |
| 2592 | 2584 | |
| 2593 | 2585 | if (sret) { |
| 2594 | 2586 | const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type)); |
| 2595 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2587 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty)); |
| 2596 | 2588 | } |
| 2597 | 2589 | } else { |
| 2598 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void)); |
| 2590 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, Type.void)); |
| 2599 | 2591 | } |
| 2600 | 2592 | |
| 2601 | 2593 | if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) { |
| 2602 | | const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType()); |
| 2603 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2594 | // Stack trace pointer. |
| 2595 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, .fromInterned(.ptr_usize_type))); |
| 2604 | 2596 | } |
| 2605 | 2597 | |
| 2606 | 2598 | for (0..fn_info.param_types.len) |i| { |
| ... | ... | @@ -2609,9 +2601,9 @@ pub const Object = struct { |
| 2609 | 2601 | |
| 2610 | 2602 | if (isByRef(param_ty, zcu)) { |
| 2611 | 2603 | const ptr_ty = try pt.singleMutPtrType(param_ty); |
| 2612 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2604 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty)); |
| 2613 | 2605 | } else { |
| 2614 | | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty)); |
| 2606 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, param_ty)); |
| 2615 | 2607 | } |
| 2616 | 2608 | } |
| 2617 | 2609 | |
| ... | ... | @@ -2634,10 +2626,10 @@ pub const Object = struct { |
| 2634 | 2626 | } |
| 2635 | 2627 | } |
| 2636 | 2628 | |
| 2637 | | fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata { |
| 2638 | | const zcu = o.pt.zcu; |
| 2629 | fn namespaceToDebugScope(o: *Object, pt: Zcu.PerThread, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata { |
| 2630 | const zcu = pt.zcu; |
| 2639 | 2631 | const namespace = zcu.namespacePtr(namespace_index); |
| 2640 | | if (namespace.parent == .none) return try o.getDebugFile(namespace.file_scope); |
| 2632 | if (namespace.parent == .none) return try o.getDebugFile(pt, namespace.file_scope); |
| 2641 | 2633 | |
| 2642 | 2634 | const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index); |
| 2643 | 2635 | |
| ... | ... | @@ -2646,12 +2638,12 @@ pub const Object = struct { |
| 2646 | 2638 | return gop.value_ptr.*; |
| 2647 | 2639 | } |
| 2648 | 2640 | |
| 2649 | | fn makeEmptyNamespaceDebugType(o: *Object, ty: Type) !Builder.Metadata { |
| 2650 | | const zcu = o.pt.zcu; |
| 2641 | fn makeEmptyNamespaceDebugType(o: *Object, pt: Zcu.PerThread, ty: Type) !Builder.Metadata { |
| 2642 | const zcu = pt.zcu; |
| 2651 | 2643 | const ip = &zcu.intern_pool; |
| 2652 | | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); |
| 2644 | const file = try o.getDebugFile(pt, ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip)); |
| 2653 | 2645 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 2654 | | try o.namespaceToDebugScope(parent_namespace) |
| 2646 | try o.namespaceToDebugScope(pt, parent_namespace) |
| 2655 | 2647 | else |
| 2656 | 2648 | file; |
| 2657 | 2649 | return o.builder.debugStructType( |
| ... | ... | @@ -2666,31 +2658,10 @@ pub const Object = struct { |
| 2666 | 2658 | ); |
| 2667 | 2659 | } |
| 2668 | 2660 | |
| 2669 | | fn getStackTraceType(o: *Object) Allocator.Error!Type { |
| 2670 | | const pt = o.pt; |
| 2671 | | const zcu = pt.zcu; |
| 2672 | | const ip = &zcu.intern_pool; |
| 2673 | | |
| 2674 | | const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?; |
| 2675 | | const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls); |
| 2676 | | const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_index)); |
| 2677 | | const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu)); |
| 2678 | | const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; |
| 2679 | | |
| 2680 | | const stack_trace_str = try ip.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls); |
| 2681 | | // buffer is only used for int_type, `builtin` is a struct. |
| 2682 | | const builtin_ty = zcu.navValue(builtin_nav).toType(); |
| 2683 | | const builtin_namespace = zcu.namespacePtr(builtin_ty.getNamespaceIndex(zcu)); |
| 2684 | | const stack_trace_nav = builtin_namespace.pub_decls.getKeyAdapted(stack_trace_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; |
| 2685 | | |
| 2686 | | // Sema should have ensured that StackTrace was analyzed. |
| 2687 | | return zcu.navValue(stack_trace_nav).toType(); |
| 2688 | | } |
| 2689 | | |
| 2690 | | fn allocTypeName(o: *Object, ty: Type) Allocator.Error![:0]const u8 { |
| 2661 | fn allocTypeName(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error![:0]const u8 { |
| 2691 | 2662 | var aw: std.io.Writer.Allocating = .init(o.gpa); |
| 2692 | 2663 | defer aw.deinit(); |
| 2693 | | ty.print(&aw.writer, o.pt) catch |err| switch (err) { |
| 2664 | ty.print(&aw.writer, pt) catch |err| switch (err) { |
| 2694 | 2665 | error.WriteFailed => return error.OutOfMemory, |
| 2695 | 2666 | }; |
| 2696 | 2667 | return aw.toOwnedSliceSentinel(0); |
| ... | ... | @@ -2701,9 +2672,9 @@ pub const Object = struct { |
| 2701 | 2672 | /// completed, so if any attributes rely on that, they must be done in updateFunc, not here. |
| 2702 | 2673 | fn resolveLlvmFunction( |
| 2703 | 2674 | o: *Object, |
| 2675 | pt: Zcu.PerThread, |
| 2704 | 2676 | nav_index: InternPool.Nav.Index, |
| 2705 | 2677 | ) Allocator.Error!Builder.Function.Index { |
| 2706 | | const pt = o.pt; |
| 2707 | 2678 | const zcu = pt.zcu; |
| 2708 | 2679 | const ip = &zcu.intern_pool; |
| 2709 | 2680 | const gpa = o.gpa; |
| ... | ... | @@ -2722,7 +2693,7 @@ pub const Object = struct { |
| 2722 | 2693 | else |
| 2723 | 2694 | .{ false, .none }; |
| 2724 | 2695 | const function_index = try o.builder.addFunction( |
| 2725 | | try o.lowerType(ty), |
| 2696 | try o.lowerType(pt, ty), |
| 2726 | 2697 | try o.builder.strtabString((if (is_extern) nav.name else nav.fqn).toSlice(ip)), |
| 2727 | 2698 | toLlvmAddressSpace(nav.getAddrspace(), target), |
| 2728 | 2699 | ); |
| ... | ... | @@ -2755,7 +2726,7 @@ pub const Object = struct { |
| 2755 | 2726 | try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder); |
| 2756 | 2727 | try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder); |
| 2757 | 2728 | |
| 2758 | | const raw_llvm_ret_ty = try o.lowerType(Type.fromInterned(fn_info.return_type)); |
| 2729 | const raw_llvm_ret_ty = try o.lowerType(pt, Type.fromInterned(fn_info.return_type)); |
| 2759 | 2730 | try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder); |
| 2760 | 2731 | |
| 2761 | 2732 | llvm_arg_i += 1; |
| ... | ... | @@ -2862,19 +2833,19 @@ pub const Object = struct { |
| 2862 | 2833 | // Add parameter attributes. We handle only the case of extern functions (no body) |
| 2863 | 2834 | // because functions with bodies are handled in `updateFunc`. |
| 2864 | 2835 | if (is_extern) { |
| 2865 | | var it = iterateParamTypes(o, fn_info); |
| 2836 | var it = iterateParamTypes(o, pt, fn_info); |
| 2866 | 2837 | it.llvm_index = llvm_arg_i; |
| 2867 | 2838 | while (try it.next()) |lowering| switch (lowering) { |
| 2868 | 2839 | .byval => { |
| 2869 | 2840 | const param_index = it.zig_index - 1; |
| 2870 | 2841 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); |
| 2871 | 2842 | if (!isByRef(param_ty, zcu)) { |
| 2872 | | try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1); |
| 2843 | try o.addByValParamAttrs(pt, &attributes, param_ty, param_index, fn_info, it.llvm_index - 1); |
| 2873 | 2844 | } |
| 2874 | 2845 | }, |
| 2875 | 2846 | .byref => { |
| 2876 | 2847 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); |
| 2877 | | const param_llvm_ty = try o.lowerType(param_ty); |
| 2848 | const param_llvm_ty = try o.lowerType(pt, param_ty); |
| 2878 | 2849 | const alignment = param_ty.abiAlignment(zcu); |
| 2879 | 2850 | try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty); |
| 2880 | 2851 | }, |
| ... | ... | @@ -2969,6 +2940,7 @@ pub const Object = struct { |
| 2969 | 2940 | |
| 2970 | 2941 | fn resolveGlobalUav( |
| 2971 | 2942 | o: *Object, |
| 2943 | pt: Zcu.PerThread, |
| 2972 | 2944 | uav: InternPool.Index, |
| 2973 | 2945 | llvm_addr_space: Builder.AddrSpace, |
| 2974 | 2946 | alignment: InternPool.Alignment, |
| ... | ... | @@ -2986,17 +2958,17 @@ pub const Object = struct { |
| 2986 | 2958 | } |
| 2987 | 2959 | errdefer assert(o.uav_map.remove(uav)); |
| 2988 | 2960 | |
| 2989 | | const zcu = o.pt.zcu; |
| 2961 | const zcu = pt.zcu; |
| 2990 | 2962 | const decl_ty = zcu.intern_pool.typeOf(uav); |
| 2991 | 2963 | |
| 2992 | 2964 | const variable_index = try o.builder.addVariable( |
| 2993 | 2965 | try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}), |
| 2994 | | try o.lowerType(Type.fromInterned(decl_ty)), |
| 2966 | try o.lowerType(pt, Type.fromInterned(decl_ty)), |
| 2995 | 2967 | llvm_addr_space, |
| 2996 | 2968 | ); |
| 2997 | 2969 | gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; |
| 2998 | 2970 | |
| 2999 | | try variable_index.setInitializer(try o.lowerValue(uav), &o.builder); |
| 2971 | try variable_index.setInitializer(try o.lowerValue(pt, uav), &o.builder); |
| 3000 | 2972 | variable_index.setLinkage(.internal, &o.builder); |
| 3001 | 2973 | variable_index.setMutability(.constant, &o.builder); |
| 3002 | 2974 | variable_index.setUnnamedAddr(.unnamed_addr, &o.builder); |
| ... | ... | @@ -3006,13 +2978,13 @@ pub const Object = struct { |
| 3006 | 2978 | |
| 3007 | 2979 | fn resolveGlobalNav( |
| 3008 | 2980 | o: *Object, |
| 2981 | pt: Zcu.PerThread, |
| 3009 | 2982 | nav_index: InternPool.Nav.Index, |
| 3010 | 2983 | ) Allocator.Error!Builder.Variable.Index { |
| 3011 | 2984 | const gop = try o.nav_map.getOrPut(o.gpa, nav_index); |
| 3012 | 2985 | if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable; |
| 3013 | 2986 | errdefer assert(o.nav_map.remove(nav_index)); |
| 3014 | 2987 | |
| 3015 | | const pt = o.pt; |
| 3016 | 2988 | const zcu = pt.zcu; |
| 3017 | 2989 | const ip = &zcu.intern_pool; |
| 3018 | 2990 | const nav = ip.getNav(nav_index); |
| ... | ... | @@ -3033,7 +3005,7 @@ pub const Object = struct { |
| 3033 | 3005 | .strong, .weak => nav.name, |
| 3034 | 3006 | .link_once => unreachable, |
| 3035 | 3007 | }.toSlice(ip)), |
| 3036 | | try o.lowerType(Type.fromInterned(nav.typeOf(ip))), |
| 3008 | try o.lowerType(pt, Type.fromInterned(nav.typeOf(ip))), |
| 3037 | 3009 | toLlvmGlobalAddressSpace(nav.getAddrspace(), zcu.getTarget()), |
| 3038 | 3010 | ); |
| 3039 | 3011 | gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; |
| ... | ... | @@ -3062,12 +3034,11 @@ pub const Object = struct { |
| 3062 | 3034 | return variable_index; |
| 3063 | 3035 | } |
| 3064 | 3036 | |
| 3065 | | fn errorIntType(o: *Object) Allocator.Error!Builder.Type { |
| 3066 | | return o.builder.intType(o.pt.zcu.errorSetBits()); |
| 3037 | fn errorIntType(o: *Object, pt: Zcu.PerThread) Allocator.Error!Builder.Type { |
| 3038 | return o.builder.intType(pt.zcu.errorSetBits()); |
| 3067 | 3039 | } |
| 3068 | 3040 | |
| 3069 | | fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type { |
| 3070 | | const pt = o.pt; |
| 3041 | fn lowerType(o: *Object, pt: Zcu.PerThread, t: Type) Allocator.Error!Builder.Type { |
| 3071 | 3042 | const zcu = pt.zcu; |
| 3072 | 3043 | const target = zcu.getTarget(); |
| 3073 | 3044 | const ip = &zcu.intern_pool; |
| ... | ... | @@ -3123,7 +3094,7 @@ pub const Object = struct { |
| 3123 | 3094 | .bool_type => .i1, |
| 3124 | 3095 | .void_type => .void, |
| 3125 | 3096 | .type_type => unreachable, |
| 3126 | | .anyerror_type => try o.errorIntType(), |
| 3097 | .anyerror_type => try o.errorIntType(pt), |
| 3127 | 3098 | .comptime_int_type, |
| 3128 | 3099 | .comptime_float_type, |
| 3129 | 3100 | .noreturn_type, |
| ... | ... | @@ -3141,11 +3112,11 @@ pub const Object = struct { |
| 3141 | 3112 | => .ptr, |
| 3142 | 3113 | .slice_const_u8_type, |
| 3143 | 3114 | .slice_const_u8_sentinel_0_type, |
| 3144 | | => try o.builder.structType(.normal, &.{ .ptr, try o.lowerType(Type.usize) }), |
| 3115 | => try o.builder.structType(.normal, &.{ .ptr, try o.lowerType(pt, Type.usize) }), |
| 3145 | 3116 | .optional_noreturn_type => unreachable, |
| 3146 | 3117 | .anyerror_void_error_union_type, |
| 3147 | 3118 | .adhoc_inferred_error_set_type, |
| 3148 | | => try o.errorIntType(), |
| 3119 | => try o.errorIntType(pt), |
| 3149 | 3120 | .generic_poison_type, |
| 3150 | 3121 | .empty_tuple_type, |
| 3151 | 3122 | => unreachable, |
| ... | ... | @@ -3182,24 +3153,24 @@ pub const Object = struct { |
| 3182 | 3153 | .one, .many, .c => ptr_ty, |
| 3183 | 3154 | .slice => try o.builder.structType(.normal, &.{ |
| 3184 | 3155 | ptr_ty, |
| 3185 | | try o.lowerType(Type.usize), |
| 3156 | try o.lowerType(pt, Type.usize), |
| 3186 | 3157 | }), |
| 3187 | 3158 | }; |
| 3188 | 3159 | }, |
| 3189 | 3160 | .array_type => |array_type| o.builder.arrayType( |
| 3190 | 3161 | array_type.lenIncludingSentinel(), |
| 3191 | | try o.lowerType(Type.fromInterned(array_type.child)), |
| 3162 | try o.lowerType(pt, Type.fromInterned(array_type.child)), |
| 3192 | 3163 | ), |
| 3193 | 3164 | .vector_type => |vector_type| o.builder.vectorType( |
| 3194 | 3165 | .normal, |
| 3195 | 3166 | vector_type.len, |
| 3196 | | try o.lowerType(Type.fromInterned(vector_type.child)), |
| 3167 | try o.lowerType(pt, Type.fromInterned(vector_type.child)), |
| 3197 | 3168 | ), |
| 3198 | 3169 | .opt_type => |child_ty| { |
| 3199 | 3170 | // Must stay in sync with `opt_payload` logic in `lowerPtr`. |
| 3200 | 3171 | if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(zcu)) return .i8; |
| 3201 | 3172 | |
| 3202 | | const payload_ty = try o.lowerType(Type.fromInterned(child_ty)); |
| 3173 | const payload_ty = try o.lowerType(pt, Type.fromInterned(child_ty)); |
| 3203 | 3174 | if (t.optionalReprIsPayload(zcu)) return payload_ty; |
| 3204 | 3175 | |
| 3205 | 3176 | comptime assert(optional_layout_version == 3); |
| ... | ... | @@ -3218,17 +3189,16 @@ pub const Object = struct { |
| 3218 | 3189 | .error_union_type => |error_union_type| { |
| 3219 | 3190 | // Must stay in sync with `codegen.errUnionPayloadOffset`. |
| 3220 | 3191 | // See logic in `lowerPtr`. |
| 3221 | | const error_type = try o.errorIntType(); |
| 3192 | const error_type = try o.errorIntType(pt); |
| 3222 | 3193 | if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu)) |
| 3223 | 3194 | return error_type; |
| 3224 | | const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type)); |
| 3225 | | const err_int_ty = try o.pt.errorIntType(); |
| 3195 | const payload_type = try o.lowerType(pt, Type.fromInterned(error_union_type.payload_type)); |
| 3226 | 3196 | |
| 3227 | 3197 | const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(zcu); |
| 3228 | | const error_align = err_int_ty.abiAlignment(zcu); |
| 3198 | const error_align: InternPool.Alignment = .fromByteUnits(std.zig.target.intAlignment(target, zcu.errorSetBits())); |
| 3229 | 3199 | |
| 3230 | 3200 | const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(zcu); |
| 3231 | | const error_size = err_int_ty.abiSize(zcu); |
| 3201 | const error_size = std.zig.target.intByteSize(target, zcu.errorSetBits()); |
| 3232 | 3202 | |
| 3233 | 3203 | var fields: [3]Builder.Type = undefined; |
| 3234 | 3204 | var fields_len: usize = 2; |
| ... | ... | @@ -3262,7 +3232,7 @@ pub const Object = struct { |
| 3262 | 3232 | const struct_type = ip.loadStructType(t.toIntern()); |
| 3263 | 3233 | |
| 3264 | 3234 | if (struct_type.layout == .@"packed") { |
| 3265 | | const int_ty = try o.lowerType(Type.fromInterned(struct_type.backingIntTypeUnordered(ip))); |
| 3235 | const int_ty = try o.lowerType(pt, Type.fromInterned(struct_type.backingIntTypeUnordered(ip))); |
| 3266 | 3236 | try o.type_map.put(o.gpa, t.toIntern(), int_ty); |
| 3267 | 3237 | return int_ty; |
| 3268 | 3238 | } |
| ... | ... | @@ -3312,7 +3282,7 @@ pub const Object = struct { |
| 3312 | 3282 | .struct_ty = t.toIntern(), |
| 3313 | 3283 | .field_index = field_index, |
| 3314 | 3284 | }, @intCast(llvm_field_types.items.len)); |
| 3315 | | try llvm_field_types.append(o.gpa, try o.lowerType(field_ty)); |
| 3285 | try llvm_field_types.append(o.gpa, try o.lowerType(pt, field_ty)); |
| 3316 | 3286 | |
| 3317 | 3287 | offset += field_ty.abiSize(zcu); |
| 3318 | 3288 | } |
| ... | ... | @@ -3382,7 +3352,7 @@ pub const Object = struct { |
| 3382 | 3352 | .struct_ty = t.toIntern(), |
| 3383 | 3353 | .field_index = @intCast(field_index), |
| 3384 | 3354 | }, @intCast(llvm_field_types.items.len)); |
| 3385 | | try llvm_field_types.append(o.gpa, try o.lowerType(Type.fromInterned(field_ty))); |
| 3355 | try llvm_field_types.append(o.gpa, try o.lowerType(pt, Type.fromInterned(field_ty))); |
| 3386 | 3356 | |
| 3387 | 3357 | offset += Type.fromInterned(field_ty).abiSize(zcu); |
| 3388 | 3358 | } |
| ... | ... | @@ -3410,13 +3380,13 @@ pub const Object = struct { |
| 3410 | 3380 | } |
| 3411 | 3381 | |
| 3412 | 3382 | if (layout.payload_size == 0) { |
| 3413 | | const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty)); |
| 3383 | const enum_tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty)); |
| 3414 | 3384 | try o.type_map.put(o.gpa, t.toIntern(), enum_tag_ty); |
| 3415 | 3385 | return enum_tag_ty; |
| 3416 | 3386 | } |
| 3417 | 3387 | |
| 3418 | 3388 | const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]); |
| 3419 | | const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty); |
| 3389 | const aligned_field_llvm_ty = try o.lowerType(pt, aligned_field_ty); |
| 3420 | 3390 | |
| 3421 | 3391 | const payload_ty = ty: { |
| 3422 | 3392 | if (layout.most_aligned_field_size == layout.payload_size) { |
| ... | ... | @@ -3442,7 +3412,7 @@ pub const Object = struct { |
| 3442 | 3412 | ); |
| 3443 | 3413 | return ty; |
| 3444 | 3414 | } |
| 3445 | | const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty)); |
| 3415 | const enum_tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty)); |
| 3446 | 3416 | |
| 3447 | 3417 | // Put the tag before or after the payload depending on which one's |
| 3448 | 3418 | // alignment is greater. |
| ... | ... | @@ -3477,9 +3447,9 @@ pub const Object = struct { |
| 3477 | 3447 | } |
| 3478 | 3448 | return gop.value_ptr.*; |
| 3479 | 3449 | }, |
| 3480 | | .enum_type => try o.lowerType(Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)), |
| 3481 | | .func_type => |func_type| try o.lowerTypeFn(func_type), |
| 3482 | | .error_set_type, .inferred_error_set_type => try o.errorIntType(), |
| 3450 | .enum_type => try o.lowerType(pt, Type.fromInterned(ip.loadEnumType(t.toIntern()).tag_ty)), |
| 3451 | .func_type => |func_type| try o.lowerTypeFn(pt, func_type), |
| 3452 | .error_set_type, .inferred_error_set_type => try o.errorIntType(pt), |
| 3483 | 3453 | // values, not types |
| 3484 | 3454 | .undef, |
| 3485 | 3455 | .simple_value, |
| ... | ... | @@ -3508,8 +3478,7 @@ pub const Object = struct { |
| 3508 | 3478 | /// Use this instead of lowerType when you want to handle correctly the case of elem_ty |
| 3509 | 3479 | /// being a zero bit type, but it should still be lowered as an i8 in such case. |
| 3510 | 3480 | /// There are other similar cases handled here as well. |
| 3511 | | fn lowerPtrElemTy(o: *Object, elem_ty: Type) Allocator.Error!Builder.Type { |
| 3512 | | const pt = o.pt; |
| 3481 | fn lowerPtrElemTy(o: *Object, pt: Zcu.PerThread, elem_ty: Type) Allocator.Error!Builder.Type { |
| 3513 | 3482 | const zcu = pt.zcu; |
| 3514 | 3483 | const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) { |
| 3515 | 3484 | .@"opaque" => true, |
| ... | ... | @@ -3517,15 +3486,14 @@ pub const Object = struct { |
| 3517 | 3486 | .array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu), |
| 3518 | 3487 | else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu), |
| 3519 | 3488 | }; |
| 3520 | | return if (lower_elem_ty) try o.lowerType(elem_ty) else .i8; |
| 3489 | return if (lower_elem_ty) try o.lowerType(pt, elem_ty) else .i8; |
| 3521 | 3490 | } |
| 3522 | 3491 | |
| 3523 | | fn lowerTypeFn(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 3524 | | const pt = o.pt; |
| 3492 | fn lowerTypeFn(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 3525 | 3493 | const zcu = pt.zcu; |
| 3526 | 3494 | const ip = &zcu.intern_pool; |
| 3527 | 3495 | const target = zcu.getTarget(); |
| 3528 | | const ret_ty = try lowerFnRetTy(o, fn_info); |
| 3496 | const ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 3529 | 3497 | |
| 3530 | 3498 | var llvm_params: std.ArrayListUnmanaged(Builder.Type) = .empty; |
| 3531 | 3499 | defer llvm_params.deinit(o.gpa); |
| ... | ... | @@ -3535,16 +3503,17 @@ pub const Object = struct { |
| 3535 | 3503 | } |
| 3536 | 3504 | |
| 3537 | 3505 | if (fn_info.cc == .auto and zcu.comp.config.any_error_tracing) { |
| 3538 | | const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType()); |
| 3539 | | try llvm_params.append(o.gpa, try o.lowerType(ptr_ty)); |
| 3506 | const stack_trace_ty = zcu.builtin_decl_values.get(.StackTrace); |
| 3507 | const ptr_ty = try pt.ptrType(.{ .child = stack_trace_ty }); |
| 3508 | try llvm_params.append(o.gpa, try o.lowerType(pt, ptr_ty)); |
| 3540 | 3509 | } |
| 3541 | 3510 | |
| 3542 | | var it = iterateParamTypes(o, fn_info); |
| 3511 | var it = iterateParamTypes(o, pt, fn_info); |
| 3543 | 3512 | while (try it.next()) |lowering| switch (lowering) { |
| 3544 | 3513 | .no_bits => continue, |
| 3545 | 3514 | .byval => { |
| 3546 | 3515 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); |
| 3547 | | try llvm_params.append(o.gpa, try o.lowerType(param_ty)); |
| 3516 | try llvm_params.append(o.gpa, try o.lowerType(pt, param_ty)); |
| 3548 | 3517 | }, |
| 3549 | 3518 | .byref, .byref_mut => { |
| 3550 | 3519 | try llvm_params.append(o.gpa, .ptr); |
| ... | ... | @@ -3559,7 +3528,7 @@ pub const Object = struct { |
| 3559 | 3528 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); |
| 3560 | 3529 | try llvm_params.appendSlice(o.gpa, &.{ |
| 3561 | 3530 | try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(zcu), target)), |
| 3562 | | try o.lowerType(Type.usize), |
| 3531 | try o.lowerType(pt, Type.usize), |
| 3563 | 3532 | }); |
| 3564 | 3533 | }, |
| 3565 | 3534 | .multiple_llvm_types => { |
| ... | ... | @@ -3567,7 +3536,7 @@ pub const Object = struct { |
| 3567 | 3536 | }, |
| 3568 | 3537 | .float_array => |count| { |
| 3569 | 3538 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]); |
| 3570 | | const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, zcu).?); |
| 3539 | const float_ty = try o.lowerType(pt, aarch64_c_abi.getFloatArrayType(param_ty, zcu).?); |
| 3571 | 3540 | try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty)); |
| 3572 | 3541 | }, |
| 3573 | 3542 | .i32_array, .i64_array => |arr_len| { |
| ... | ... | @@ -3586,8 +3555,7 @@ pub const Object = struct { |
| 3586 | 3555 | ); |
| 3587 | 3556 | } |
| 3588 | 3557 | |
| 3589 | | fn lowerValueToInt(o: *Object, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant { |
| 3590 | | const pt = o.pt; |
| 3558 | fn lowerValueToInt(o: *Object, pt: Zcu.PerThread, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant { |
| 3591 | 3559 | const zcu = pt.zcu; |
| 3592 | 3560 | const ip = &zcu.intern_pool; |
| 3593 | 3561 | const target = zcu.getTarget(); |
| ... | ... | @@ -3600,23 +3568,23 @@ pub const Object = struct { |
| 3600 | 3568 | const ty = Type.fromInterned(val_key.typeOf()); |
| 3601 | 3569 | switch (val_key) { |
| 3602 | 3570 | .@"extern" => |@"extern"| { |
| 3603 | | const function_index = try o.resolveLlvmFunction(@"extern".owner_nav); |
| 3571 | const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav); |
| 3604 | 3572 | const ptr = function_index.ptrConst(&o.builder).global.toConst(); |
| 3605 | 3573 | return o.builder.convConst(ptr, llvm_int_ty); |
| 3606 | 3574 | }, |
| 3607 | 3575 | .func => |func| { |
| 3608 | | const function_index = try o.resolveLlvmFunction(func.owner_nav); |
| 3576 | const function_index = try o.resolveLlvmFunction(pt, func.owner_nav); |
| 3609 | 3577 | const ptr = function_index.ptrConst(&o.builder).global.toConst(); |
| 3610 | 3578 | return o.builder.convConst(ptr, llvm_int_ty); |
| 3611 | 3579 | }, |
| 3612 | | .ptr => return o.builder.convConst(try o.lowerPtr(arg_val, 0), llvm_int_ty), |
| 3580 | .ptr => return o.builder.convConst(try o.lowerPtr(pt, arg_val, 0), llvm_int_ty), |
| 3613 | 3581 | .aggregate => switch (ip.indexToKey(ty.toIntern())) { |
| 3614 | 3582 | .struct_type, .vector_type => {}, |
| 3615 | 3583 | else => unreachable, |
| 3616 | 3584 | }, |
| 3617 | 3585 | .un => |un| { |
| 3618 | 3586 | const layout = ty.unionGetLayout(zcu); |
| 3619 | | if (layout.payload_size == 0) return o.lowerValue(un.tag); |
| 3587 | if (layout.payload_size == 0) return o.lowerValue(pt, un.tag); |
| 3620 | 3588 | |
| 3621 | 3589 | const union_obj = zcu.typeToUnion(ty).?; |
| 3622 | 3590 | const container_layout = union_obj.flagsUnordered(ip).layout; |
| ... | ... | @@ -3626,7 +3594,7 @@ pub const Object = struct { |
| 3626 | 3594 | var need_unnamed = false; |
| 3627 | 3595 | if (un.tag == .none) { |
| 3628 | 3596 | assert(layout.tag_size == 0); |
| 3629 | | const union_val = try o.lowerValueToInt(llvm_int_ty, un.val); |
| 3597 | const union_val = try o.lowerValueToInt(pt, llvm_int_ty, un.val); |
| 3630 | 3598 | |
| 3631 | 3599 | need_unnamed = true; |
| 3632 | 3600 | return union_val; |
| ... | ... | @@ -3634,7 +3602,7 @@ pub const Object = struct { |
| 3634 | 3602 | const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?; |
| 3635 | 3603 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]); |
| 3636 | 3604 | if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(llvm_int_ty, 0); |
| 3637 | | return o.lowerValueToInt(llvm_int_ty, un.val); |
| 3605 | return o.lowerValueToInt(pt, llvm_int_ty, un.val); |
| 3638 | 3606 | }, |
| 3639 | 3607 | .simple_value => |simple_value| switch (simple_value) { |
| 3640 | 3608 | .false, .true => {}, |
| ... | ... | @@ -3678,8 +3646,7 @@ pub const Object = struct { |
| 3678 | 3646 | }); |
| 3679 | 3647 | } |
| 3680 | 3648 | |
| 3681 | | fn lowerValue(o: *Object, arg_val: InternPool.Index) Error!Builder.Constant { |
| 3682 | | const pt = o.pt; |
| 3649 | fn lowerValue(o: *Object, pt: Zcu.PerThread, arg_val: InternPool.Index) Error!Builder.Constant { |
| 3683 | 3650 | const zcu = pt.zcu; |
| 3684 | 3651 | const ip = &zcu.intern_pool; |
| 3685 | 3652 | const target = zcu.getTarget(); |
| ... | ... | @@ -3688,7 +3655,7 @@ pub const Object = struct { |
| 3688 | 3655 | const val_key = ip.indexToKey(val.toIntern()); |
| 3689 | 3656 | |
| 3690 | 3657 | if (val.isUndefDeep(zcu)) { |
| 3691 | | return o.builder.undefConst(try o.lowerType(Type.fromInterned(val_key.typeOf()))); |
| 3658 | return o.builder.undefConst(try o.lowerType(pt, Type.fromInterned(val_key.typeOf()))); |
| 3692 | 3659 | } |
| 3693 | 3660 | |
| 3694 | 3661 | const ty = Type.fromInterned(val_key.typeOf()); |
| ... | ... | @@ -3727,21 +3694,21 @@ pub const Object = struct { |
| 3727 | 3694 | .empty_enum_value, |
| 3728 | 3695 | => unreachable, // non-runtime values |
| 3729 | 3696 | .@"extern" => |@"extern"| { |
| 3730 | | const function_index = try o.resolveLlvmFunction(@"extern".owner_nav); |
| 3697 | const function_index = try o.resolveLlvmFunction(pt, @"extern".owner_nav); |
| 3731 | 3698 | return function_index.ptrConst(&o.builder).global.toConst(); |
| 3732 | 3699 | }, |
| 3733 | 3700 | .func => |func| { |
| 3734 | | const function_index = try o.resolveLlvmFunction(func.owner_nav); |
| 3701 | const function_index = try o.resolveLlvmFunction(pt, func.owner_nav); |
| 3735 | 3702 | return function_index.ptrConst(&o.builder).global.toConst(); |
| 3736 | 3703 | }, |
| 3737 | 3704 | .int => { |
| 3738 | 3705 | var bigint_space: Value.BigIntSpace = undefined; |
| 3739 | 3706 | const bigint = val.toBigInt(&bigint_space, zcu); |
| 3740 | | return lowerBigInt(o, ty, bigint); |
| 3707 | return lowerBigInt(o, pt, ty, bigint); |
| 3741 | 3708 | }, |
| 3742 | 3709 | .err => |err| { |
| 3743 | 3710 | const int = try pt.getErrorValue(err.name); |
| 3744 | | const llvm_int = try o.builder.intConst(try o.errorIntType(), int); |
| 3711 | const llvm_int = try o.builder.intConst(try o.errorIntType(pt), int); |
| 3745 | 3712 | return llvm_int; |
| 3746 | 3713 | }, |
| 3747 | 3714 | .error_union => |error_union| { |
| ... | ... | @@ -3756,13 +3723,13 @@ pub const Object = struct { |
| 3756 | 3723 | const payload_type = ty.errorUnionPayload(zcu); |
| 3757 | 3724 | if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 3758 | 3725 | // We use the error type directly as the type. |
| 3759 | | return o.lowerValue(err_val); |
| 3726 | return o.lowerValue(pt, err_val); |
| 3760 | 3727 | } |
| 3761 | 3728 | |
| 3762 | 3729 | const payload_align = payload_type.abiAlignment(zcu); |
| 3763 | 3730 | const error_align = err_int_ty.abiAlignment(zcu); |
| 3764 | | const llvm_error_value = try o.lowerValue(err_val); |
| 3765 | | const llvm_payload_value = try o.lowerValue(switch (error_union.val) { |
| 3731 | const llvm_error_value = try o.lowerValue(pt, err_val); |
| 3732 | const llvm_payload_value = try o.lowerValue(pt, switch (error_union.val) { |
| 3766 | 3733 | .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }), |
| 3767 | 3734 | .payload => |payload| payload, |
| 3768 | 3735 | }); |
| ... | ... | @@ -3779,7 +3746,7 @@ pub const Object = struct { |
| 3779 | 3746 | fields[0] = vals[0].typeOf(&o.builder); |
| 3780 | 3747 | fields[1] = vals[1].typeOf(&o.builder); |
| 3781 | 3748 | |
| 3782 | | const llvm_ty = try o.lowerType(ty); |
| 3749 | const llvm_ty = try o.lowerType(pt, ty); |
| 3783 | 3750 | const llvm_ty_fields = llvm_ty.structFields(&o.builder); |
| 3784 | 3751 | if (llvm_ty_fields.len > 2) { |
| 3785 | 3752 | assert(llvm_ty_fields.len == 3); |
| ... | ... | @@ -3791,7 +3758,7 @@ pub const Object = struct { |
| 3791 | 3758 | fields[0..llvm_ty_fields.len], |
| 3792 | 3759 | ), vals[0..llvm_ty_fields.len]); |
| 3793 | 3760 | }, |
| 3794 | | .enum_tag => |enum_tag| o.lowerValue(enum_tag.int), |
| 3761 | .enum_tag => |enum_tag| o.lowerValue(pt, enum_tag.int), |
| 3795 | 3762 | .float => switch (ty.floatBits(target)) { |
| 3796 | 3763 | 16 => if (backendSupportsF16(target)) |
| 3797 | 3764 | try o.builder.halfConst(val.toFloat(f16, zcu)) |
| ... | ... | @@ -3806,10 +3773,10 @@ pub const Object = struct { |
| 3806 | 3773 | 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)), |
| 3807 | 3774 | else => unreachable, |
| 3808 | 3775 | }, |
| 3809 | | .ptr => try o.lowerPtr(arg_val, 0), |
| 3810 | | .slice => |slice| return o.builder.structConst(try o.lowerType(ty), &.{ |
| 3811 | | try o.lowerValue(slice.ptr), |
| 3812 | | try o.lowerValue(slice.len), |
| 3776 | .ptr => try o.lowerPtr(pt, arg_val, 0), |
| 3777 | .slice => |slice| return o.builder.structConst(try o.lowerType(pt, ty), &.{ |
| 3778 | try o.lowerValue(pt, slice.ptr), |
| 3779 | try o.lowerValue(pt, slice.len), |
| 3813 | 3780 | }), |
| 3814 | 3781 | .opt => |opt| { |
| 3815 | 3782 | comptime assert(optional_layout_version == 3); |
| ... | ... | @@ -3819,7 +3786,7 @@ pub const Object = struct { |
| 3819 | 3786 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 3820 | 3787 | return non_null_bit; |
| 3821 | 3788 | } |
| 3822 | | const llvm_ty = try o.lowerType(ty); |
| 3789 | const llvm_ty = try o.lowerType(pt, ty); |
| 3823 | 3790 | if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) { |
| 3824 | 3791 | .none => switch (llvm_ty.tag(&o.builder)) { |
| 3825 | 3792 | .integer => try o.builder.intConst(llvm_ty, 0), |
| ... | ... | @@ -3827,13 +3794,13 @@ pub const Object = struct { |
| 3827 | 3794 | .structure => try o.builder.zeroInitConst(llvm_ty), |
| 3828 | 3795 | else => unreachable, |
| 3829 | 3796 | }, |
| 3830 | | else => |payload| try o.lowerValue(payload), |
| 3797 | else => |payload| try o.lowerValue(pt, payload), |
| 3831 | 3798 | }; |
| 3832 | 3799 | assert(payload_ty.zigTypeTag(zcu) != .@"fn"); |
| 3833 | 3800 | |
| 3834 | 3801 | var fields: [3]Builder.Type = undefined; |
| 3835 | 3802 | var vals: [3]Builder.Constant = undefined; |
| 3836 | | vals[0] = try o.lowerValue(switch (opt.val) { |
| 3803 | vals[0] = try o.lowerValue(pt, switch (opt.val) { |
| 3837 | 3804 | .none => try pt.intern(.{ .undef = payload_ty.toIntern() }), |
| 3838 | 3805 | else => |payload| payload, |
| 3839 | 3806 | }); |
| ... | ... | @@ -3858,7 +3825,7 @@ pub const Object = struct { |
| 3858 | 3825 | bytes.toSlice(array_type.lenIncludingSentinel(), ip), |
| 3859 | 3826 | )), |
| 3860 | 3827 | .elems => |elems| { |
| 3861 | | const array_ty = try o.lowerType(ty); |
| 3828 | const array_ty = try o.lowerType(pt, ty); |
| 3862 | 3829 | const elem_ty = array_ty.childType(&o.builder); |
| 3863 | 3830 | assert(elems.len == array_ty.aggregateLen(&o.builder)); |
| 3864 | 3831 | |
| ... | ... | @@ -3878,7 +3845,7 @@ pub const Object = struct { |
| 3878 | 3845 | |
| 3879 | 3846 | var need_unnamed = false; |
| 3880 | 3847 | for (vals, fields, elems) |*result_val, *result_field, elem| { |
| 3881 | | result_val.* = try o.lowerValue(elem); |
| 3848 | result_val.* = try o.lowerValue(pt, elem); |
| 3882 | 3849 | result_field.* = result_val.typeOf(&o.builder); |
| 3883 | 3850 | if (result_field.* != elem_ty) need_unnamed = true; |
| 3884 | 3851 | } |
| ... | ... | @@ -3890,7 +3857,7 @@ pub const Object = struct { |
| 3890 | 3857 | .repeated_elem => |elem| { |
| 3891 | 3858 | const len: usize = @intCast(array_type.len); |
| 3892 | 3859 | const len_including_sentinel: usize = @intCast(array_type.lenIncludingSentinel()); |
| 3893 | | const array_ty = try o.lowerType(ty); |
| 3860 | const array_ty = try o.lowerType(pt, ty); |
| 3894 | 3861 | const elem_ty = array_ty.childType(&o.builder); |
| 3895 | 3862 | |
| 3896 | 3863 | const ExpectedContents = extern struct { |
| ... | ... | @@ -3908,12 +3875,12 @@ pub const Object = struct { |
| 3908 | 3875 | defer allocator.free(fields); |
| 3909 | 3876 | |
| 3910 | 3877 | var need_unnamed = false; |
| 3911 | | @memset(vals[0..len], try o.lowerValue(elem)); |
| 3878 | @memset(vals[0..len], try o.lowerValue(pt, elem)); |
| 3912 | 3879 | @memset(fields[0..len], vals[0].typeOf(&o.builder)); |
| 3913 | 3880 | if (fields[0] != elem_ty) need_unnamed = true; |
| 3914 | 3881 | |
| 3915 | 3882 | if (array_type.sentinel != .none) { |
| 3916 | | vals[len] = try o.lowerValue(array_type.sentinel); |
| 3883 | vals[len] = try o.lowerValue(pt, array_type.sentinel); |
| 3917 | 3884 | fields[len] = vals[len].typeOf(&o.builder); |
| 3918 | 3885 | if (fields[len] != elem_ty) need_unnamed = true; |
| 3919 | 3886 | } |
| ... | ... | @@ -3925,7 +3892,7 @@ pub const Object = struct { |
| 3925 | 3892 | }, |
| 3926 | 3893 | }, |
| 3927 | 3894 | .vector_type => |vector_type| { |
| 3928 | | const vector_ty = try o.lowerType(ty); |
| 3895 | const vector_ty = try o.lowerType(pt, ty); |
| 3929 | 3896 | switch (aggregate.storage) { |
| 3930 | 3897 | .bytes, .elems => { |
| 3931 | 3898 | const ExpectedContents = [Builder.expected_fields_len]Builder.Constant; |
| ... | ... | @@ -3942,7 +3909,7 @@ pub const Object = struct { |
| 3942 | 3909 | result_val.* = try o.builder.intConst(.i8, byte); |
| 3943 | 3910 | }, |
| 3944 | 3911 | .elems => |elems| for (vals, elems) |*result_val, elem| { |
| 3945 | | result_val.* = try o.lowerValue(elem); |
| 3912 | result_val.* = try o.lowerValue(pt, elem); |
| 3946 | 3913 | }, |
| 3947 | 3914 | .repeated_elem => unreachable, |
| 3948 | 3915 | } |
| ... | ... | @@ -3950,12 +3917,12 @@ pub const Object = struct { |
| 3950 | 3917 | }, |
| 3951 | 3918 | .repeated_elem => |elem| return o.builder.splatConst( |
| 3952 | 3919 | vector_ty, |
| 3953 | | try o.lowerValue(elem), |
| 3920 | try o.lowerValue(pt, elem), |
| 3954 | 3921 | ), |
| 3955 | 3922 | } |
| 3956 | 3923 | }, |
| 3957 | 3924 | .tuple_type => |tuple| { |
| 3958 | | const struct_ty = try o.lowerType(ty); |
| 3925 | const struct_ty = try o.lowerType(pt, ty); |
| 3959 | 3926 | const llvm_len = struct_ty.aggregateLen(&o.builder); |
| 3960 | 3927 | |
| 3961 | 3928 | const ExpectedContents = extern struct { |
| ... | ... | @@ -4001,7 +3968,7 @@ pub const Object = struct { |
| 4001 | 3968 | } |
| 4002 | 3969 | |
| 4003 | 3970 | vals[llvm_index] = |
| 4004 | | try o.lowerValue((try val.fieldValue(pt, field_index)).toIntern()); |
| 3971 | try o.lowerValue(pt, (try val.fieldValue(pt, field_index)).toIntern()); |
| 4005 | 3972 | fields[llvm_index] = vals[llvm_index].typeOf(&o.builder); |
| 4006 | 3973 | if (fields[llvm_index] != struct_ty.structFields(&o.builder)[llvm_index]) |
| 4007 | 3974 | need_unnamed = true; |
| ... | ... | @@ -4030,14 +3997,14 @@ pub const Object = struct { |
| 4030 | 3997 | .struct_type => { |
| 4031 | 3998 | const struct_type = ip.loadStructType(ty.toIntern()); |
| 4032 | 3999 | assert(struct_type.haveLayout(ip)); |
| 4033 | | const struct_ty = try o.lowerType(ty); |
| 4000 | const struct_ty = try o.lowerType(pt, ty); |
| 4034 | 4001 | if (struct_type.layout == .@"packed") { |
| 4035 | 4002 | comptime assert(Type.packed_struct_layout_version == 2); |
| 4036 | 4003 | |
| 4037 | 4004 | const bits = ty.bitSize(zcu); |
| 4038 | 4005 | const llvm_int_ty = try o.builder.intType(@intCast(bits)); |
| 4039 | 4006 | |
| 4040 | | return o.lowerValueToInt(llvm_int_ty, arg_val); |
| 4007 | return o.lowerValueToInt(pt, llvm_int_ty, arg_val); |
| 4041 | 4008 | } |
| 4042 | 4009 | const llvm_len = struct_ty.aggregateLen(&o.builder); |
| 4043 | 4010 | |
| ... | ... | @@ -4085,6 +4052,7 @@ pub const Object = struct { |
| 4085 | 4052 | } |
| 4086 | 4053 | |
| 4087 | 4054 | vals[llvm_index] = try o.lowerValue( |
| 4055 | pt, |
| 4088 | 4056 | (try val.fieldValue(pt, field_index)).toIntern(), |
| 4089 | 4057 | ); |
| 4090 | 4058 | fields[llvm_index] = vals[llvm_index].typeOf(&o.builder); |
| ... | ... | @@ -4115,9 +4083,9 @@ pub const Object = struct { |
| 4115 | 4083 | else => unreachable, |
| 4116 | 4084 | }, |
| 4117 | 4085 | .un => |un| { |
| 4118 | | const union_ty = try o.lowerType(ty); |
| 4086 | const union_ty = try o.lowerType(pt, ty); |
| 4119 | 4087 | const layout = ty.unionGetLayout(zcu); |
| 4120 | | if (layout.payload_size == 0) return o.lowerValue(un.tag); |
| 4088 | if (layout.payload_size == 0) return o.lowerValue(pt, un.tag); |
| 4121 | 4089 | |
| 4122 | 4090 | const union_obj = zcu.typeToUnion(ty).?; |
| 4123 | 4091 | const container_layout = union_obj.flagsUnordered(ip).layout; |
| ... | ... | @@ -4131,7 +4099,7 @@ pub const Object = struct { |
| 4131 | 4099 | const bits = ty.bitSize(zcu); |
| 4132 | 4100 | const llvm_int_ty = try o.builder.intType(@intCast(bits)); |
| 4133 | 4101 | |
| 4134 | | return o.lowerValueToInt(llvm_int_ty, arg_val); |
| 4102 | return o.lowerValueToInt(pt, llvm_int_ty, arg_val); |
| 4135 | 4103 | } |
| 4136 | 4104 | |
| 4137 | 4105 | // Sometimes we must make an unnamed struct because LLVM does |
| ... | ... | @@ -4144,7 +4112,7 @@ pub const Object = struct { |
| 4144 | 4112 | const padding_len = layout.payload_size; |
| 4145 | 4113 | break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8)); |
| 4146 | 4114 | } |
| 4147 | | const payload = try o.lowerValue(un.val); |
| 4115 | const payload = try o.lowerValue(pt, un.val); |
| 4148 | 4116 | const payload_ty = payload.typeOf(&o.builder); |
| 4149 | 4117 | if (payload_ty != union_ty.structFields(&o.builder)[ |
| 4150 | 4118 | @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)) |
| ... | ... | @@ -4163,10 +4131,10 @@ pub const Object = struct { |
| 4163 | 4131 | const bits = ty.bitSize(zcu); |
| 4164 | 4132 | const llvm_int_ty = try o.builder.intType(@intCast(bits)); |
| 4165 | 4133 | |
| 4166 | | return o.lowerValueToInt(llvm_int_ty, arg_val); |
| 4134 | return o.lowerValueToInt(pt, llvm_int_ty, arg_val); |
| 4167 | 4135 | } |
| 4168 | 4136 | |
| 4169 | | const union_val = try o.lowerValue(un.val); |
| 4137 | const union_val = try o.lowerValue(pt, un.val); |
| 4170 | 4138 | need_unnamed = true; |
| 4171 | 4139 | break :p union_val; |
| 4172 | 4140 | }; |
| ... | ... | @@ -4176,7 +4144,7 @@ pub const Object = struct { |
| 4176 | 4144 | try o.builder.structType(union_ty.structKind(&o.builder), &.{payload_ty}) |
| 4177 | 4145 | else |
| 4178 | 4146 | union_ty, &.{payload}); |
| 4179 | | const tag = try o.lowerValue(un.tag); |
| 4147 | const tag = try o.lowerValue(pt, un.tag); |
| 4180 | 4148 | const tag_ty = tag.typeOf(&o.builder); |
| 4181 | 4149 | var fields: [3]Builder.Type = undefined; |
| 4182 | 4150 | var vals: [3]Builder.Constant = undefined; |
| ... | ... | @@ -4204,48 +4172,50 @@ pub const Object = struct { |
| 4204 | 4172 | |
| 4205 | 4173 | fn lowerBigInt( |
| 4206 | 4174 | o: *Object, |
| 4175 | pt: Zcu.PerThread, |
| 4207 | 4176 | ty: Type, |
| 4208 | 4177 | bigint: std.math.big.int.Const, |
| 4209 | 4178 | ) Allocator.Error!Builder.Constant { |
| 4210 | | const zcu = o.pt.zcu; |
| 4179 | const zcu = pt.zcu; |
| 4211 | 4180 | return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint); |
| 4212 | 4181 | } |
| 4213 | 4182 | |
| 4214 | 4183 | fn lowerPtr( |
| 4215 | 4184 | o: *Object, |
| 4185 | pt: Zcu.PerThread, |
| 4216 | 4186 | ptr_val: InternPool.Index, |
| 4217 | 4187 | prev_offset: u64, |
| 4218 | 4188 | ) Error!Builder.Constant { |
| 4219 | | const pt = o.pt; |
| 4220 | 4189 | const zcu = pt.zcu; |
| 4221 | 4190 | const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr; |
| 4222 | 4191 | const offset: u64 = prev_offset + ptr.byte_offset; |
| 4223 | 4192 | return switch (ptr.base_addr) { |
| 4224 | 4193 | .nav => |nav| { |
| 4225 | | const base_ptr = try o.lowerNavRefValue(nav); |
| 4194 | const base_ptr = try o.lowerNavRefValue(pt, nav); |
| 4226 | 4195 | return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{ |
| 4227 | 4196 | try o.builder.intConst(.i64, offset), |
| 4228 | 4197 | }); |
| 4229 | 4198 | }, |
| 4230 | 4199 | .uav => |uav| { |
| 4231 | | const base_ptr = try o.lowerUavRef(uav); |
| 4200 | const base_ptr = try o.lowerUavRef(pt, uav); |
| 4232 | 4201 | return o.builder.gepConst(.inbounds, .i8, base_ptr, null, &.{ |
| 4233 | 4202 | try o.builder.intConst(.i64, offset), |
| 4234 | 4203 | }); |
| 4235 | 4204 | }, |
| 4236 | 4205 | .int => try o.builder.castConst( |
| 4237 | 4206 | .inttoptr, |
| 4238 | | try o.builder.intConst(try o.lowerType(Type.usize), offset), |
| 4239 | | try o.lowerType(Type.fromInterned(ptr.ty)), |
| 4207 | try o.builder.intConst(try o.lowerType(pt, Type.usize), offset), |
| 4208 | try o.lowerType(pt, Type.fromInterned(ptr.ty)), |
| 4240 | 4209 | ), |
| 4241 | 4210 | .eu_payload => |eu_ptr| try o.lowerPtr( |
| 4211 | pt, |
| 4242 | 4212 | eu_ptr, |
| 4243 | 4213 | offset + @import("../codegen.zig").errUnionPayloadOffset( |
| 4244 | 4214 | Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu), |
| 4245 | 4215 | zcu, |
| 4246 | 4216 | ), |
| 4247 | 4217 | ), |
| 4248 | | .opt_payload => |opt_ptr| try o.lowerPtr(opt_ptr, offset), |
| 4218 | .opt_payload => |opt_ptr| try o.lowerPtr(pt, opt_ptr, offset), |
| 4249 | 4219 | .field => |field| { |
| 4250 | 4220 | const agg_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu); |
| 4251 | 4221 | const field_off: u64 = switch (agg_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -4263,7 +4233,7 @@ pub const Object = struct { |
| 4263 | 4233 | }, |
| 4264 | 4234 | else => unreachable, |
| 4265 | 4235 | }; |
| 4266 | | return o.lowerPtr(field.base, offset + field_off); |
| 4236 | return o.lowerPtr(pt, field.base, offset + field_off); |
| 4267 | 4237 | }, |
| 4268 | 4238 | .arr_elem, .comptime_field, .comptime_alloc => unreachable, |
| 4269 | 4239 | }; |
| ... | ... | @@ -4273,9 +4243,9 @@ pub const Object = struct { |
| 4273 | 4243 | /// Maybe the logic could be unified. |
| 4274 | 4244 | fn lowerUavRef( |
| 4275 | 4245 | o: *Object, |
| 4246 | pt: Zcu.PerThread, |
| 4276 | 4247 | uav: InternPool.Key.Ptr.BaseAddr.Uav, |
| 4277 | 4248 | ) Error!Builder.Constant { |
| 4278 | | const pt = o.pt; |
| 4279 | 4249 | const zcu = pt.zcu; |
| 4280 | 4250 | const ip = &zcu.intern_pool; |
| 4281 | 4251 | const uav_val = uav.val; |
| ... | ... | @@ -4292,25 +4262,24 @@ pub const Object = struct { |
| 4292 | 4262 | |
| 4293 | 4263 | const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn"; |
| 4294 | 4264 | if ((!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) or |
| 4295 | | (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(ptr_ty); |
| 4265 | (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(pt, ptr_ty); |
| 4296 | 4266 | |
| 4297 | 4267 | if (is_fn_body) |
| 4298 | 4268 | @panic("TODO"); |
| 4299 | 4269 | |
| 4300 | 4270 | const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target); |
| 4301 | 4271 | const alignment = ptr_ty.ptrAlignment(zcu); |
| 4302 | | const llvm_global = (try o.resolveGlobalUav(uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global; |
| 4272 | const llvm_global = (try o.resolveGlobalUav(pt, uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global; |
| 4303 | 4273 | |
| 4304 | 4274 | const llvm_val = try o.builder.convConst( |
| 4305 | 4275 | llvm_global.toConst(), |
| 4306 | 4276 | try o.builder.ptrType(llvm_addr_space), |
| 4307 | 4277 | ); |
| 4308 | 4278 | |
| 4309 | | return o.builder.convConst(llvm_val, try o.lowerType(ptr_ty)); |
| 4279 | return o.builder.convConst(llvm_val, try o.lowerType(pt, ptr_ty)); |
| 4310 | 4280 | } |
| 4311 | 4281 | |
| 4312 | | fn lowerNavRefValue(o: *Object, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant { |
| 4313 | | const pt = o.pt; |
| 4282 | fn lowerNavRefValue(o: *Object, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) Allocator.Error!Builder.Constant { |
| 4314 | 4283 | const zcu = pt.zcu; |
| 4315 | 4284 | const ip = &zcu.intern_pool; |
| 4316 | 4285 | |
| ... | ... | @@ -4323,24 +4292,24 @@ pub const Object = struct { |
| 4323 | 4292 | if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or |
| 4324 | 4293 | (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic)) |
| 4325 | 4294 | { |
| 4326 | | return o.lowerPtrToVoid(ptr_ty); |
| 4295 | return o.lowerPtrToVoid(pt, ptr_ty); |
| 4327 | 4296 | } |
| 4328 | 4297 | |
| 4329 | 4298 | const llvm_global = if (is_fn_body) |
| 4330 | | (try o.resolveLlvmFunction(nav_index)).ptrConst(&o.builder).global |
| 4299 | (try o.resolveLlvmFunction(pt, nav_index)).ptrConst(&o.builder).global |
| 4331 | 4300 | else |
| 4332 | | (try o.resolveGlobalNav(nav_index)).ptrConst(&o.builder).global; |
| 4301 | (try o.resolveGlobalNav(pt, nav_index)).ptrConst(&o.builder).global; |
| 4333 | 4302 | |
| 4334 | 4303 | const llvm_val = try o.builder.convConst( |
| 4335 | 4304 | llvm_global.toConst(), |
| 4336 | 4305 | try o.builder.ptrType(toLlvmAddressSpace(nav.getAddrspace(), zcu.getTarget())), |
| 4337 | 4306 | ); |
| 4338 | 4307 | |
| 4339 | | return o.builder.convConst(llvm_val, try o.lowerType(ptr_ty)); |
| 4308 | return o.builder.convConst(llvm_val, try o.lowerType(pt, ptr_ty)); |
| 4340 | 4309 | } |
| 4341 | 4310 | |
| 4342 | | fn lowerPtrToVoid(o: *Object, ptr_ty: Type) Allocator.Error!Builder.Constant { |
| 4343 | | const zcu = o.pt.zcu; |
| 4311 | fn lowerPtrToVoid(o: *Object, pt: Zcu.PerThread, ptr_ty: Type) Allocator.Error!Builder.Constant { |
| 4312 | const zcu = pt.zcu; |
| 4344 | 4313 | // Even though we are pointing at something which has zero bits (e.g. `void`), |
| 4345 | 4314 | // Pointers are defined to have bits. So we must return something here. |
| 4346 | 4315 | // The value cannot be undefined, because we use the `nonnull` annotation |
| ... | ... | @@ -4358,8 +4327,8 @@ pub const Object = struct { |
| 4358 | 4327 | 64 => 0xaaaaaaaa_aaaaaaaa, |
| 4359 | 4328 | else => unreachable, |
| 4360 | 4329 | }; |
| 4361 | | const llvm_usize = try o.lowerType(Type.usize); |
| 4362 | | const llvm_ptr_ty = try o.lowerType(ptr_ty); |
| 4330 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 4331 | const llvm_ptr_ty = try o.lowerType(pt, ptr_ty); |
| 4363 | 4332 | return o.builder.castConst(.inttoptr, try o.builder.intConst(llvm_usize, int), llvm_ptr_ty); |
| 4364 | 4333 | } |
| 4365 | 4334 | |
| ... | ... | @@ -4367,8 +4336,7 @@ pub const Object = struct { |
| 4367 | 4336 | /// widen it before using it and then truncate the result. |
| 4368 | 4337 | /// RMW exchange of floating-point values is bitcasted to same-sized integer |
| 4369 | 4338 | /// types to work around a LLVM deficiency when targeting ARM/AArch64. |
| 4370 | | fn getAtomicAbiType(o: *Object, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type { |
| 4371 | | const pt = o.pt; |
| 4339 | fn getAtomicAbiType(o: *Object, pt: Zcu.PerThread, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type { |
| 4372 | 4340 | const zcu = pt.zcu; |
| 4373 | 4341 | const int_ty = switch (ty.zigTypeTag(zcu)) { |
| 4374 | 4342 | .int => ty, |
| ... | ... | @@ -4390,13 +4358,13 @@ pub const Object = struct { |
| 4390 | 4358 | |
| 4391 | 4359 | fn addByValParamAttrs( |
| 4392 | 4360 | o: *Object, |
| 4361 | pt: Zcu.PerThread, |
| 4393 | 4362 | attributes: *Builder.FunctionAttributes.Wip, |
| 4394 | 4363 | param_ty: Type, |
| 4395 | 4364 | param_index: u32, |
| 4396 | 4365 | fn_info: InternPool.Key.FuncType, |
| 4397 | 4366 | llvm_arg_i: u32, |
| 4398 | 4367 | ) Allocator.Error!void { |
| 4399 | | const pt = o.pt; |
| 4400 | 4368 | const zcu = pt.zcu; |
| 4401 | 4369 | if (param_ty.isPtrAtRuntime(zcu)) { |
| 4402 | 4370 | const ptr_info = param_ty.ptrInfo(zcu); |
| ... | ... | @@ -4416,7 +4384,7 @@ pub const Object = struct { |
| 4416 | 4384 | .x86_64_interrupt, |
| 4417 | 4385 | .x86_interrupt, |
| 4418 | 4386 | => { |
| 4419 | | const child_type = try lowerType(o, Type.fromInterned(ptr_info.child)); |
| 4387 | const child_type = try lowerType(o, pt, Type.fromInterned(ptr_info.child)); |
| 4420 | 4388 | try attributes.addParamAttr(llvm_arg_i, .{ .byval = child_type }, &o.builder); |
| 4421 | 4389 | }, |
| 4422 | 4390 | } |
| ... | ... | @@ -4455,14 +4423,14 @@ pub const Object = struct { |
| 4455 | 4423 | }); |
| 4456 | 4424 | } |
| 4457 | 4425 | |
| 4458 | | fn getCmpLtErrorsLenFunction(o: *Object) !Builder.Function.Index { |
| 4426 | fn getCmpLtErrorsLenFunction(o: *Object, pt: Zcu.PerThread) !Builder.Function.Index { |
| 4459 | 4427 | const name = try o.builder.strtabString(lt_errors_fn_name); |
| 4460 | 4428 | if (o.builder.getGlobal(name)) |llvm_fn| return llvm_fn.ptrConst(&o.builder).kind.function; |
| 4461 | 4429 | |
| 4462 | | const zcu = o.pt.zcu; |
| 4430 | const zcu = pt.zcu; |
| 4463 | 4431 | const target = &zcu.root_mod.resolved_target.result; |
| 4464 | 4432 | const function_index = try o.builder.addFunction( |
| 4465 | | try o.builder.fnType(.i1, &.{try o.errorIntType()}, .normal), |
| 4433 | try o.builder.fnType(.i1, &.{try o.errorIntType(pt)}, .normal), |
| 4466 | 4434 | name, |
| 4467 | 4435 | toLlvmAddressSpace(.generic, target), |
| 4468 | 4436 | ); |
| ... | ... | @@ -4477,8 +4445,7 @@ pub const Object = struct { |
| 4477 | 4445 | return function_index; |
| 4478 | 4446 | } |
| 4479 | 4447 | |
| 4480 | | fn getEnumTagNameFunction(o: *Object, enum_ty: Type) !Builder.Function.Index { |
| 4481 | | const pt = o.pt; |
| 4448 | fn getEnumTagNameFunction(o: *Object, pt: Zcu.PerThread, enum_ty: Type) !Builder.Function.Index { |
| 4482 | 4449 | const zcu = pt.zcu; |
| 4483 | 4450 | const ip = &zcu.intern_pool; |
| 4484 | 4451 | const enum_type = ip.loadEnumType(enum_ty.toIntern()); |
| ... | ... | @@ -4487,11 +4454,11 @@ pub const Object = struct { |
| 4487 | 4454 | if (gop.found_existing) return gop.value_ptr.ptrConst(&o.builder).kind.function; |
| 4488 | 4455 | errdefer assert(o.enum_tag_name_map.remove(enum_ty.toIntern())); |
| 4489 | 4456 | |
| 4490 | | const usize_ty = try o.lowerType(Type.usize); |
| 4491 | | const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0); |
| 4457 | const usize_ty = try o.lowerType(pt, Type.usize); |
| 4458 | const ret_ty = try o.lowerType(pt, Type.slice_const_u8_sentinel_0); |
| 4492 | 4459 | const target = &zcu.root_mod.resolved_target.result; |
| 4493 | 4460 | const function_index = try o.builder.addFunction( |
| 4494 | | try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal), |
| 4461 | try o.builder.fnType(ret_ty, &.{try o.lowerType(pt, Type.fromInterned(enum_type.tag_ty))}, .normal), |
| 4495 | 4462 | try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_type.name.fmt(ip)}), |
| 4496 | 4463 | toLlvmAddressSpace(.generic, target), |
| 4497 | 4464 | ); |
| ... | ... | @@ -4536,6 +4503,7 @@ pub const Object = struct { |
| 4536 | 4503 | |
| 4537 | 4504 | const return_block = try wip.block(1, "Name"); |
| 4538 | 4505 | const this_tag_int_value = try o.lowerValue( |
| 4506 | pt, |
| 4539 | 4507 | (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(), |
| 4540 | 4508 | ); |
| 4541 | 4509 | try wip_switch.addCase(this_tag_int_value, return_block, &wip); |
| ... | ... | @@ -4555,10 +4523,11 @@ pub const Object = struct { |
| 4555 | 4523 | pub const NavGen = struct { |
| 4556 | 4524 | object: *Object, |
| 4557 | 4525 | nav_index: InternPool.Nav.Index, |
| 4526 | pt: Zcu.PerThread, |
| 4558 | 4527 | err_msg: ?*Zcu.ErrorMsg, |
| 4559 | 4528 | |
| 4560 | 4529 | fn ownerModule(ng: NavGen) *Package.Module { |
| 4561 | | return ng.object.pt.zcu.navFileScope(ng.nav_index).mod.?; |
| 4530 | return ng.pt.zcu.navFileScope(ng.nav_index).mod.?; |
| 4562 | 4531 | } |
| 4563 | 4532 | |
| 4564 | 4533 | fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error { |
| ... | ... | @@ -4566,14 +4535,14 @@ pub const NavGen = struct { |
| 4566 | 4535 | assert(ng.err_msg == null); |
| 4567 | 4536 | const o = ng.object; |
| 4568 | 4537 | const gpa = o.gpa; |
| 4569 | | const src_loc = o.pt.zcu.navSrcLoc(ng.nav_index); |
| 4538 | const src_loc = ng.pt.zcu.navSrcLoc(ng.nav_index); |
| 4570 | 4539 | ng.err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args); |
| 4571 | 4540 | return error.CodegenFail; |
| 4572 | 4541 | } |
| 4573 | 4542 | |
| 4574 | 4543 | fn genDecl(ng: *NavGen) !void { |
| 4575 | 4544 | const o = ng.object; |
| 4576 | | const pt = o.pt; |
| 4545 | const pt = ng.pt; |
| 4577 | 4546 | const zcu = pt.zcu; |
| 4578 | 4547 | const ip = &zcu.intern_pool; |
| 4579 | 4548 | const nav_index = ng.nav_index; |
| ... | ... | @@ -4588,16 +4557,16 @@ pub const NavGen = struct { |
| 4588 | 4557 | const ty = Type.fromInterned(nav.typeOf(ip)); |
| 4589 | 4558 | |
| 4590 | 4559 | if (linkage != .internal and ip.isFunctionType(ty.toIntern())) { |
| 4591 | | _ = try o.resolveLlvmFunction(owner_nav); |
| 4560 | _ = try o.resolveLlvmFunction(pt, owner_nav); |
| 4592 | 4561 | } else { |
| 4593 | | const variable_index = try o.resolveGlobalNav(nav_index); |
| 4562 | const variable_index = try o.resolveGlobalNav(pt, nav_index); |
| 4594 | 4563 | variable_index.setAlignment(pt.navAlignment(nav_index).toLlvm(), &o.builder); |
| 4595 | 4564 | if (resolved.@"linksection".toSlice(ip)) |section| |
| 4596 | 4565 | variable_index.setSection(try o.builder.string(section), &o.builder); |
| 4597 | 4566 | if (is_const) variable_index.setMutability(.constant, &o.builder); |
| 4598 | 4567 | try variable_index.setInitializer(switch (init_val) { |
| 4599 | 4568 | .none => .no_init, |
| 4600 | | else => try o.lowerValue(init_val), |
| 4569 | else => try o.lowerValue(pt, init_val), |
| 4601 | 4570 | }, &o.builder); |
| 4602 | 4571 | variable_index.setVisibility(visibility, &o.builder); |
| 4603 | 4572 | |
| ... | ... | @@ -4609,7 +4578,7 @@ pub const NavGen = struct { |
| 4609 | 4578 | const line_number = zcu.navSrcLine(nav_index) + 1; |
| 4610 | 4579 | |
| 4611 | 4580 | if (!mod.strip) { |
| 4612 | | const debug_file = try o.getDebugFile(file_scope); |
| 4581 | const debug_file = try o.getDebugFile(pt, file_scope); |
| 4613 | 4582 | |
| 4614 | 4583 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4615 | 4584 | try o.builder.metadataString(nav.name.toSlice(ip)), // Name |
| ... | ... | @@ -4617,7 +4586,7 @@ pub const NavGen = struct { |
| 4617 | 4586 | debug_file, // File |
| 4618 | 4587 | debug_file, // Scope |
| 4619 | 4588 | line_number, |
| 4620 | | try o.lowerDebugType(ty), |
| 4589 | try o.lowerDebugType(pt, ty), |
| 4621 | 4590 | variable_index, |
| 4622 | 4591 | .{ .local = linkage == .internal }, |
| 4623 | 4592 | ); |
| ... | ... | @@ -4814,16 +4783,17 @@ pub const FuncGen = struct { |
| 4814 | 4783 | const gop = try self.func_inst_table.getOrPut(gpa, inst); |
| 4815 | 4784 | if (gop.found_existing) return gop.value_ptr.*; |
| 4816 | 4785 | |
| 4817 | | const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.object.pt)).?); |
| 4786 | const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.pt)).?); |
| 4818 | 4787 | gop.value_ptr.* = llvm_val.toValue(); |
| 4819 | 4788 | return llvm_val.toValue(); |
| 4820 | 4789 | } |
| 4821 | 4790 | |
| 4822 | 4791 | fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant { |
| 4823 | 4792 | const o = self.ng.object; |
| 4824 | | const zcu = o.pt.zcu; |
| 4793 | const pt = self.ng.pt; |
| 4794 | const zcu = pt.zcu; |
| 4825 | 4795 | const ty = val.typeOf(zcu); |
| 4826 | | const llvm_val = try o.lowerValue(val.toIntern()); |
| 4796 | const llvm_val = try o.lowerValue(pt, val.toIntern()); |
| 4827 | 4797 | if (!isByRef(ty, zcu)) return llvm_val; |
| 4828 | 4798 | |
| 4829 | 4799 | // We have an LLVM value but we need to create a global constant and |
| ... | ... | @@ -4847,7 +4817,7 @@ pub const FuncGen = struct { |
| 4847 | 4817 | |
| 4848 | 4818 | fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) Error!void { |
| 4849 | 4819 | const o = self.ng.object; |
| 4850 | | const zcu = o.pt.zcu; |
| 4820 | const zcu = self.ng.pt.zcu; |
| 4851 | 4821 | const ip = &zcu.intern_pool; |
| 4852 | 4822 | const air_tags = self.air.instructions.items(.tag); |
| 4853 | 4823 | switch (coverage_point) { |
| ... | ... | @@ -5173,7 +5143,7 @@ pub const FuncGen = struct { |
| 5173 | 5143 | |
| 5174 | 5144 | if (maybe_inline_func) |inline_func| { |
| 5175 | 5145 | const o = self.ng.object; |
| 5176 | | const pt = o.pt; |
| 5146 | const pt = self.ng.pt; |
| 5177 | 5147 | const zcu = pt.zcu; |
| 5178 | 5148 | const ip = &zcu.intern_pool; |
| 5179 | 5149 | |
| ... | ... | @@ -5182,7 +5152,7 @@ pub const FuncGen = struct { |
| 5182 | 5152 | const file_scope = zcu.navFileScopeIndex(func.owner_nav); |
| 5183 | 5153 | const mod = zcu.fileByIndex(file_scope).mod.?; |
| 5184 | 5154 | |
| 5185 | | self.file = try o.getDebugFile(file_scope); |
| 5155 | self.file = try o.getDebugFile(pt, file_scope); |
| 5186 | 5156 | |
| 5187 | 5157 | const line_number = zcu.navSrcLine(func.owner_nav) + 1; |
| 5188 | 5158 | self.inlined = self.wip.debug_location; |
| ... | ... | @@ -5198,7 +5168,7 @@ pub const FuncGen = struct { |
| 5198 | 5168 | try o.builder.metadataString(nav.fqn.toSlice(&zcu.intern_pool)), |
| 5199 | 5169 | line_number, |
| 5200 | 5170 | line_number + func.lbrace_line, |
| 5201 | | try o.lowerDebugType(fn_ty), |
| 5171 | try o.lowerDebugType(pt, fn_ty), |
| 5202 | 5172 | .{ |
| 5203 | 5173 | .di_flags = .{ .StaticMember = true }, |
| 5204 | 5174 | .sp_flags = .{ |
| ... | ... | @@ -5255,7 +5225,7 @@ pub const FuncGen = struct { |
| 5255 | 5225 | const extra = self.air.extraData(Air.Call, pl_op.payload); |
| 5256 | 5226 | const args: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[extra.end..][0..extra.data.args_len]); |
| 5257 | 5227 | const o = self.ng.object; |
| 5258 | | const pt = o.pt; |
| 5228 | const pt = self.ng.pt; |
| 5259 | 5229 | const zcu = pt.zcu; |
| 5260 | 5230 | const ip = &zcu.intern_pool; |
| 5261 | 5231 | const callee_ty = self.typeOf(pl_op.operand); |
| ... | ... | @@ -5287,7 +5257,7 @@ pub const FuncGen = struct { |
| 5287 | 5257 | } |
| 5288 | 5258 | |
| 5289 | 5259 | const ret_ptr = if (!sret) null else blk: { |
| 5290 | | const llvm_ret_ty = try o.lowerType(return_type); |
| 5260 | const llvm_ret_ty = try o.lowerType(pt, return_type); |
| 5291 | 5261 | try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder); |
| 5292 | 5262 | |
| 5293 | 5263 | const alignment = return_type.abiAlignment(zcu).toLlvm(); |
| ... | ... | @@ -5302,14 +5272,14 @@ pub const FuncGen = struct { |
| 5302 | 5272 | try llvm_args.append(self.err_ret_trace); |
| 5303 | 5273 | } |
| 5304 | 5274 | |
| 5305 | | var it = iterateParamTypes(o, fn_info); |
| 5275 | var it = iterateParamTypes(o, pt, fn_info); |
| 5306 | 5276 | while (try it.nextCall(self, args)) |lowering| switch (lowering) { |
| 5307 | 5277 | .no_bits => continue, |
| 5308 | 5278 | .byval => { |
| 5309 | 5279 | const arg = args[it.zig_index - 1]; |
| 5310 | 5280 | const param_ty = self.typeOf(arg); |
| 5311 | 5281 | const llvm_arg = try self.resolveInst(arg); |
| 5312 | | const llvm_param_ty = try o.lowerType(param_ty); |
| 5282 | const llvm_param_ty = try o.lowerType(pt, param_ty); |
| 5313 | 5283 | if (isByRef(param_ty, zcu)) { |
| 5314 | 5284 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 5315 | 5285 | const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, ""); |
| ... | ... | @@ -5338,7 +5308,7 @@ pub const FuncGen = struct { |
| 5338 | 5308 | const llvm_arg = try self.resolveInst(arg); |
| 5339 | 5309 | |
| 5340 | 5310 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 5341 | | const param_llvm_ty = try o.lowerType(param_ty); |
| 5311 | const param_llvm_ty = try o.lowerType(pt, param_ty); |
| 5342 | 5312 | const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment); |
| 5343 | 5313 | if (isByRef(param_ty, zcu)) { |
| 5344 | 5314 | const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, ""); |
| ... | ... | @@ -5409,7 +5379,7 @@ pub const FuncGen = struct { |
| 5409 | 5379 | llvm_arg = ptr; |
| 5410 | 5380 | } |
| 5411 | 5381 | |
| 5412 | | const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?); |
| 5382 | const float_ty = try o.lowerType(pt, aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?); |
| 5413 | 5383 | const array_ty = try o.builder.arrayType(count, float_ty); |
| 5414 | 5384 | |
| 5415 | 5385 | const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, ""); |
| ... | ... | @@ -5436,7 +5406,7 @@ pub const FuncGen = struct { |
| 5436 | 5406 | |
| 5437 | 5407 | { |
| 5438 | 5408 | // Add argument attributes. |
| 5439 | | it = iterateParamTypes(o, fn_info); |
| 5409 | it = iterateParamTypes(o, pt, fn_info); |
| 5440 | 5410 | it.llvm_index += @intFromBool(sret); |
| 5441 | 5411 | it.llvm_index += @intFromBool(err_return_tracing); |
| 5442 | 5412 | while (try it.next()) |lowering| switch (lowering) { |
| ... | ... | @@ -5444,13 +5414,13 @@ pub const FuncGen = struct { |
| 5444 | 5414 | const param_index = it.zig_index - 1; |
| 5445 | 5415 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); |
| 5446 | 5416 | if (!isByRef(param_ty, zcu)) { |
| 5447 | | try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1); |
| 5417 | try o.addByValParamAttrs(pt, &attributes, param_ty, param_index, fn_info, it.llvm_index - 1); |
| 5448 | 5418 | } |
| 5449 | 5419 | }, |
| 5450 | 5420 | .byref => { |
| 5451 | 5421 | const param_index = it.zig_index - 1; |
| 5452 | 5422 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); |
| 5453 | | const param_llvm_ty = try o.lowerType(param_ty); |
| 5423 | const param_llvm_ty = try o.lowerType(pt, param_ty); |
| 5454 | 5424 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 5455 | 5425 | try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty); |
| 5456 | 5426 | }, |
| ... | ... | @@ -5502,7 +5472,7 @@ pub const FuncGen = struct { |
| 5502 | 5472 | }, |
| 5503 | 5473 | toLlvmCallConvTag(fn_info.cc, target).?, |
| 5504 | 5474 | try attributes.finish(&o.builder), |
| 5505 | | try o.lowerType(zig_fn_ty), |
| 5475 | try o.lowerType(pt, zig_fn_ty), |
| 5506 | 5476 | llvm_fn, |
| 5507 | 5477 | llvm_args.items, |
| 5508 | 5478 | "", |
| ... | ... | @@ -5516,7 +5486,7 @@ pub const FuncGen = struct { |
| 5516 | 5486 | return .none; |
| 5517 | 5487 | } |
| 5518 | 5488 | |
| 5519 | | const llvm_ret_ty = try o.lowerType(return_type); |
| 5489 | const llvm_ret_ty = try o.lowerType(pt, return_type); |
| 5520 | 5490 | if (ret_ptr) |rp| { |
| 5521 | 5491 | if (isByRef(return_type, zcu)) { |
| 5522 | 5492 | return rp; |
| ... | ... | @@ -5527,7 +5497,7 @@ pub const FuncGen = struct { |
| 5527 | 5497 | } |
| 5528 | 5498 | } |
| 5529 | 5499 | |
| 5530 | | const abi_ret_ty = try lowerFnRetTy(o, fn_info); |
| 5500 | const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 5531 | 5501 | |
| 5532 | 5502 | if (abi_ret_ty != llvm_ret_ty) { |
| 5533 | 5503 | // In this case the function return type is honoring the calling convention by having |
| ... | ... | @@ -5556,11 +5526,12 @@ pub const FuncGen = struct { |
| 5556 | 5526 | |
| 5557 | 5527 | fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) !void { |
| 5558 | 5528 | const o = fg.ng.object; |
| 5559 | | const zcu = o.pt.zcu; |
| 5529 | const pt = fg.ng.pt; |
| 5530 | const zcu = pt.zcu; |
| 5560 | 5531 | const target = zcu.getTarget(); |
| 5561 | 5532 | const panic_func = zcu.funcInfo(zcu.builtin_decl_values.get(panic_id.toBuiltin())); |
| 5562 | 5533 | const fn_info = zcu.typeToFunc(.fromInterned(panic_func.ty)).?; |
| 5563 | | const panic_global = try o.resolveLlvmFunction(panic_func.owner_nav); |
| 5534 | const panic_global = try o.resolveLlvmFunction(pt, panic_func.owner_nav); |
| 5564 | 5535 | |
| 5565 | 5536 | const has_err_trace = zcu.comp.config.any_error_tracing and fn_info.cc == .auto; |
| 5566 | 5537 | if (has_err_trace) assert(fg.err_ret_trace != .none); |
| ... | ... | @@ -5579,7 +5550,7 @@ pub const FuncGen = struct { |
| 5579 | 5550 | |
| 5580 | 5551 | fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !void { |
| 5581 | 5552 | const o = self.ng.object; |
| 5582 | | const pt = o.pt; |
| 5553 | const pt = self.ng.pt; |
| 5583 | 5554 | const zcu = pt.zcu; |
| 5584 | 5555 | const ip = &zcu.intern_pool; |
| 5585 | 5556 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| ... | ... | @@ -5599,7 +5570,7 @@ pub const FuncGen = struct { |
| 5599 | 5570 | // https://github.com/ziglang/zig/issues/15337 |
| 5600 | 5571 | break :undef; |
| 5601 | 5572 | } |
| 5602 | | const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu)); |
| 5573 | const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), ret_ty.abiSize(zcu)); |
| 5603 | 5574 | _ = try self.wip.callMemSet( |
| 5604 | 5575 | self.ret_ptr, |
| 5605 | 5576 | ptr_ty.ptrAlignment(zcu).toLlvm(), |
| ... | ... | @@ -5635,14 +5606,14 @@ pub const FuncGen = struct { |
| 5635 | 5606 | // Functions with an empty error set are emitted with an error code |
| 5636 | 5607 | // return type and return zero so they can be function pointers coerced |
| 5637 | 5608 | // to functions that return anyerror. |
| 5638 | | _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(), 0)); |
| 5609 | _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(pt), 0)); |
| 5639 | 5610 | } else { |
| 5640 | 5611 | _ = try self.wip.retVoid(); |
| 5641 | 5612 | } |
| 5642 | 5613 | return; |
| 5643 | 5614 | } |
| 5644 | 5615 | |
| 5645 | | const abi_ret_ty = try lowerFnRetTy(o, fn_info); |
| 5616 | const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 5646 | 5617 | const operand = try self.resolveInst(un_op); |
| 5647 | 5618 | const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false; |
| 5648 | 5619 | const alignment = ret_ty.abiAlignment(zcu).toLlvm(); |
| ... | ... | @@ -5650,7 +5621,7 @@ pub const FuncGen = struct { |
| 5650 | 5621 | if (val_is_undef and safety) { |
| 5651 | 5622 | const llvm_ret_ty = operand.typeOfWip(&self.wip); |
| 5652 | 5623 | const rp = try self.buildAlloca(llvm_ret_ty, alignment); |
| 5653 | | const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu)); |
| 5624 | const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), ret_ty.abiSize(zcu)); |
| 5654 | 5625 | _ = try self.wip.callMemSet( |
| 5655 | 5626 | rp, |
| 5656 | 5627 | alignment, |
| ... | ... | @@ -5688,7 +5659,7 @@ pub const FuncGen = struct { |
| 5688 | 5659 | |
| 5689 | 5660 | fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !void { |
| 5690 | 5661 | const o = self.ng.object; |
| 5691 | | const pt = o.pt; |
| 5662 | const pt = self.ng.pt; |
| 5692 | 5663 | const zcu = pt.zcu; |
| 5693 | 5664 | const ip = &zcu.intern_pool; |
| 5694 | 5665 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| ... | ... | @@ -5700,7 +5671,7 @@ pub const FuncGen = struct { |
| 5700 | 5671 | // Functions with an empty error set are emitted with an error code |
| 5701 | 5672 | // return type and return zero so they can be function pointers coerced |
| 5702 | 5673 | // to functions that return anyerror. |
| 5703 | | _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(), 0)); |
| 5674 | _ = try self.wip.ret(try o.builder.intValue(try o.errorIntType(pt), 0)); |
| 5704 | 5675 | } else { |
| 5705 | 5676 | _ = try self.wip.retVoid(); |
| 5706 | 5677 | } |
| ... | ... | @@ -5711,7 +5682,7 @@ pub const FuncGen = struct { |
| 5711 | 5682 | return; |
| 5712 | 5683 | } |
| 5713 | 5684 | const ptr = try self.resolveInst(un_op); |
| 5714 | | const abi_ret_ty = try lowerFnRetTy(o, fn_info); |
| 5685 | const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 5715 | 5686 | const alignment = ret_ty.abiAlignment(zcu).toLlvm(); |
| 5716 | 5687 | _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, "")); |
| 5717 | 5688 | return; |
| ... | ... | @@ -5719,22 +5690,23 @@ pub const FuncGen = struct { |
| 5719 | 5690 | |
| 5720 | 5691 | fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5721 | 5692 | const o = self.ng.object; |
| 5693 | const pt = self.ng.pt; |
| 5722 | 5694 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5723 | 5695 | const list = try self.resolveInst(ty_op.operand); |
| 5724 | 5696 | const arg_ty = ty_op.ty.toType(); |
| 5725 | | const llvm_arg_ty = try o.lowerType(arg_ty); |
| 5697 | const llvm_arg_ty = try o.lowerType(pt, arg_ty); |
| 5726 | 5698 | |
| 5727 | 5699 | return self.wip.vaArg(list, llvm_arg_ty, ""); |
| 5728 | 5700 | } |
| 5729 | 5701 | |
| 5730 | 5702 | fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5731 | 5703 | const o = self.ng.object; |
| 5732 | | const pt = o.pt; |
| 5704 | const pt = self.ng.pt; |
| 5733 | 5705 | const zcu = pt.zcu; |
| 5734 | 5706 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5735 | 5707 | const src_list = try self.resolveInst(ty_op.operand); |
| 5736 | 5708 | const va_list_ty = ty_op.ty.toType(); |
| 5737 | | const llvm_va_list_ty = try o.lowerType(va_list_ty); |
| 5709 | const llvm_va_list_ty = try o.lowerType(pt, va_list_ty); |
| 5738 | 5710 | |
| 5739 | 5711 | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); |
| 5740 | 5712 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| ... | ... | @@ -5756,10 +5728,10 @@ pub const FuncGen = struct { |
| 5756 | 5728 | |
| 5757 | 5729 | fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5758 | 5730 | const o = self.ng.object; |
| 5759 | | const pt = o.pt; |
| 5731 | const pt = self.ng.pt; |
| 5760 | 5732 | const zcu = pt.zcu; |
| 5761 | 5733 | const va_list_ty = self.typeOfIndex(inst); |
| 5762 | | const llvm_va_list_ty = try o.lowerType(va_list_ty); |
| 5734 | const llvm_va_list_ty = try o.lowerType(pt, va_list_ty); |
| 5763 | 5735 | |
| 5764 | 5736 | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); |
| 5765 | 5737 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| ... | ... | @@ -5799,9 +5771,10 @@ pub const FuncGen = struct { |
| 5799 | 5771 | |
| 5800 | 5772 | fn airCmpLtErrorsLen(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 5801 | 5773 | const o = self.ng.object; |
| 5774 | const pt = self.ng.pt; |
| 5802 | 5775 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5803 | 5776 | const operand = try self.resolveInst(un_op); |
| 5804 | | const llvm_fn = try o.getCmpLtErrorsLenFunction(); |
| 5777 | const llvm_fn = try o.getCmpLtErrorsLenFunction(pt); |
| 5805 | 5778 | return self.wip.call( |
| 5806 | 5779 | .normal, |
| 5807 | 5780 | .fastcc, |
| ... | ... | @@ -5822,7 +5795,7 @@ pub const FuncGen = struct { |
| 5822 | 5795 | rhs: Builder.Value, |
| 5823 | 5796 | ) Allocator.Error!Builder.Value { |
| 5824 | 5797 | const o = self.ng.object; |
| 5825 | | const pt = o.pt; |
| 5798 | const pt = self.ng.pt; |
| 5826 | 5799 | const zcu = pt.zcu; |
| 5827 | 5800 | const ip = &zcu.intern_pool; |
| 5828 | 5801 | const scalar_ty = operand_ty.scalarType(zcu); |
| ... | ... | @@ -5839,7 +5812,7 @@ pub const FuncGen = struct { |
| 5839 | 5812 | // We need to emit instructions to check for equality/inequality |
| 5840 | 5813 | // of optionals that are not pointers. |
| 5841 | 5814 | const is_by_ref = isByRef(scalar_ty, zcu); |
| 5842 | | const opt_llvm_ty = try o.lowerType(scalar_ty); |
| 5815 | const opt_llvm_ty = try o.lowerType(pt, scalar_ty); |
| 5843 | 5816 | const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref, .normal); |
| 5844 | 5817 | const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref, .normal); |
| 5845 | 5818 | const llvm_i2 = try o.builder.intType(2); |
| ... | ... | @@ -5936,7 +5909,7 @@ pub const FuncGen = struct { |
| 5936 | 5909 | body: []const Air.Inst.Index, |
| 5937 | 5910 | ) !Builder.Value { |
| 5938 | 5911 | const o = self.ng.object; |
| 5939 | | const pt = o.pt; |
| 5912 | const pt = self.ng.pt; |
| 5940 | 5913 | const zcu = pt.zcu; |
| 5941 | 5914 | const inst_ty = self.typeOfIndex(inst); |
| 5942 | 5915 | |
| ... | ... | @@ -5963,7 +5936,7 @@ pub const FuncGen = struct { |
| 5963 | 5936 | |
| 5964 | 5937 | // Create a phi node only if the block returns a value. |
| 5965 | 5938 | if (have_block_result) { |
| 5966 | | const raw_llvm_ty = try o.lowerType(inst_ty); |
| 5939 | const raw_llvm_ty = try o.lowerType(pt, inst_ty); |
| 5967 | 5940 | const llvm_ty: Builder.Type = ty: { |
| 5968 | 5941 | // If the zig tag type is a function, this represents an actual function body; not |
| 5969 | 5942 | // a pointer to it. LLVM IR allows the call instruction to use function bodies instead |
| ... | ... | @@ -5986,8 +5959,7 @@ pub const FuncGen = struct { |
| 5986 | 5959 | } |
| 5987 | 5960 | |
| 5988 | 5961 | fn airBr(self: *FuncGen, inst: Air.Inst.Index) !void { |
| 5989 | | const o = self.ng.object; |
| 5990 | | const zcu = o.pt.zcu; |
| 5962 | const zcu = self.ng.pt.zcu; |
| 5991 | 5963 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; |
| 5992 | 5964 | const block = self.blocks.get(branch.block_inst).?; |
| 5993 | 5965 | |
| ... | ... | @@ -6017,7 +5989,7 @@ pub const FuncGen = struct { |
| 6017 | 5989 | dispatch_info: SwitchDispatchInfo, |
| 6018 | 5990 | ) !void { |
| 6019 | 5991 | const o = self.ng.object; |
| 6020 | | const pt = o.pt; |
| 5992 | const pt = self.ng.pt; |
| 6021 | 5993 | const zcu = pt.zcu; |
| 6022 | 5994 | const cond_ty = self.typeOf(cond_ref); |
| 6023 | 5995 | const switch_br = self.air.unwrapSwitch(switch_inst); |
| ... | ... | @@ -6081,7 +6053,7 @@ pub const FuncGen = struct { |
| 6081 | 6053 | const table_index = try self.wip.cast( |
| 6082 | 6054 | .zext, |
| 6083 | 6055 | try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""), |
| 6084 | | try o.lowerType(Type.usize), |
| 6056 | try o.lowerType(pt, Type.usize), |
| 6085 | 6057 | "", |
| 6086 | 6058 | ); |
| 6087 | 6059 | const target_ptr_ptr = try self.wip.gep( |
| ... | ... | @@ -6108,7 +6080,7 @@ pub const FuncGen = struct { |
| 6108 | 6080 | // The switch prongs will correspond to our scalar cases. Ranges will |
| 6109 | 6081 | // be handled by conditional branches in the `else` prong. |
| 6110 | 6082 | |
| 6111 | | const llvm_usize = try o.lowerType(Type.usize); |
| 6083 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 6112 | 6084 | const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder)) |
| 6113 | 6085 | try self.wip.cast(.ptrtoint, cond, llvm_usize, "") |
| 6114 | 6086 | else |
| ... | ... | @@ -6268,8 +6240,7 @@ pub const FuncGen = struct { |
| 6268 | 6240 | } |
| 6269 | 6241 | |
| 6270 | 6242 | fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index, err_cold: bool) !Builder.Value { |
| 6271 | | const o = self.ng.object; |
| 6272 | | const pt = o.pt; |
| 6243 | const pt = self.ng.pt; |
| 6273 | 6244 | const zcu = pt.zcu; |
| 6274 | 6245 | const inst = body_tail[0]; |
| 6275 | 6246 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| ... | ... | @@ -6284,8 +6255,7 @@ pub const FuncGen = struct { |
| 6284 | 6255 | } |
| 6285 | 6256 | |
| 6286 | 6257 | fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) !Builder.Value { |
| 6287 | | const o = self.ng.object; |
| 6288 | | const zcu = o.pt.zcu; |
| 6258 | const zcu = self.ng.pt.zcu; |
| 6289 | 6259 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 6290 | 6260 | const extra = self.air.extraData(Air.TryPtr, ty_pl.payload); |
| 6291 | 6261 | const err_union_ptr = try self.resolveInst(extra.data.ptr); |
| ... | ... | @@ -6309,12 +6279,12 @@ pub const FuncGen = struct { |
| 6309 | 6279 | err_cold: bool, |
| 6310 | 6280 | ) !Builder.Value { |
| 6311 | 6281 | const o = fg.ng.object; |
| 6312 | | const pt = o.pt; |
| 6282 | const pt = fg.ng.pt; |
| 6313 | 6283 | const zcu = pt.zcu; |
| 6314 | 6284 | const payload_ty = err_union_ty.errorUnionPayload(zcu); |
| 6315 | 6285 | const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu); |
| 6316 | | const err_union_llvm_ty = try o.lowerType(err_union_ty); |
| 6317 | | const error_type = try o.errorIntType(); |
| 6286 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 6287 | const error_type = try o.errorIntType(pt); |
| 6318 | 6288 | |
| 6319 | 6289 | if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) { |
| 6320 | 6290 | const loaded = loaded: { |
| ... | ... | @@ -6378,7 +6348,8 @@ pub const FuncGen = struct { |
| 6378 | 6348 | |
| 6379 | 6349 | fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) !void { |
| 6380 | 6350 | const o = self.ng.object; |
| 6381 | | const zcu = o.pt.zcu; |
| 6351 | const pt = self.ng.pt; |
| 6352 | const zcu = pt.zcu; |
| 6382 | 6353 | |
| 6383 | 6354 | const switch_br = self.air.unwrapSwitch(inst); |
| 6384 | 6355 | |
| ... | ... | @@ -6483,8 +6454,8 @@ pub const FuncGen = struct { |
| 6483 | 6454 | const table_includes_else = item_count != table_len; |
| 6484 | 6455 | |
| 6485 | 6456 | break :jmp_table .{ |
| 6486 | | .min = try o.lowerValue(min.toIntern()), |
| 6487 | | .max = try o.lowerValue(max.toIntern()), |
| 6457 | .min = try o.lowerValue(pt, min.toIntern()), |
| 6458 | .max = try o.lowerValue(pt, max.toIntern()), |
| 6488 | 6459 | .in_bounds_hint = if (table_includes_else) .none else switch (switch_br.getElseHint()) { |
| 6489 | 6460 | .none, .cold => .none, |
| 6490 | 6461 | .unpredictable => .unpredictable, |
| ... | ... | @@ -6591,7 +6562,7 @@ pub const FuncGen = struct { |
| 6591 | 6562 | } |
| 6592 | 6563 | |
| 6593 | 6564 | fn switchCaseItemRange(self: *FuncGen, switch_br: Air.UnwrappedSwitch) [2]Value { |
| 6594 | | const zcu = self.ng.object.pt.zcu; |
| 6565 | const zcu = self.ng.pt.zcu; |
| 6595 | 6566 | var it = switch_br.iterateCases(); |
| 6596 | 6567 | var min: ?Value = null; |
| 6597 | 6568 | var max: ?Value = null; |
| ... | ... | @@ -6633,18 +6604,18 @@ pub const FuncGen = struct { |
| 6633 | 6604 | |
| 6634 | 6605 | fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6635 | 6606 | const o = self.ng.object; |
| 6636 | | const pt = o.pt; |
| 6607 | const pt = self.ng.pt; |
| 6637 | 6608 | const zcu = pt.zcu; |
| 6638 | 6609 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6639 | 6610 | const operand_ty = self.typeOf(ty_op.operand); |
| 6640 | 6611 | const array_ty = operand_ty.childType(zcu); |
| 6641 | | const llvm_usize = try o.lowerType(Type.usize); |
| 6612 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 6642 | 6613 | const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu)); |
| 6643 | | const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst)); |
| 6614 | const slice_llvm_ty = try o.lowerType(pt, self.typeOfIndex(inst)); |
| 6644 | 6615 | const operand = try self.resolveInst(ty_op.operand); |
| 6645 | 6616 | if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu)) |
| 6646 | 6617 | return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, ""); |
| 6647 | | const ptr = try self.wip.gep(.inbounds, try o.lowerType(array_ty), operand, &.{ |
| 6618 | const ptr = try self.wip.gep(.inbounds, try o.lowerType(pt, array_ty), operand, &.{ |
| 6648 | 6619 | try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0), |
| 6649 | 6620 | }, ""); |
| 6650 | 6621 | return self.wip.buildAggregate(slice_llvm_ty, &.{ ptr, len }, ""); |
| ... | ... | @@ -6652,7 +6623,7 @@ pub const FuncGen = struct { |
| 6652 | 6623 | |
| 6653 | 6624 | fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6654 | 6625 | const o = self.ng.object; |
| 6655 | | const pt = o.pt; |
| 6626 | const pt = self.ng.pt; |
| 6656 | 6627 | const zcu = pt.zcu; |
| 6657 | 6628 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6658 | 6629 | |
| ... | ... | @@ -6663,7 +6634,7 @@ pub const FuncGen = struct { |
| 6663 | 6634 | |
| 6664 | 6635 | const dest_ty = self.typeOfIndex(inst); |
| 6665 | 6636 | const dest_scalar_ty = dest_ty.scalarType(zcu); |
| 6666 | | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 6637 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 6667 | 6638 | const target = zcu.getTarget(); |
| 6668 | 6639 | |
| 6669 | 6640 | if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv( |
| ... | ... | @@ -6719,7 +6690,7 @@ pub const FuncGen = struct { |
| 6719 | 6690 | _ = fast; |
| 6720 | 6691 | |
| 6721 | 6692 | const o = self.ng.object; |
| 6722 | | const pt = o.pt; |
| 6693 | const pt = self.ng.pt; |
| 6723 | 6694 | const zcu = pt.zcu; |
| 6724 | 6695 | const target = zcu.getTarget(); |
| 6725 | 6696 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -6730,7 +6701,7 @@ pub const FuncGen = struct { |
| 6730 | 6701 | |
| 6731 | 6702 | const dest_ty = self.typeOfIndex(inst); |
| 6732 | 6703 | const dest_scalar_ty = dest_ty.scalarType(zcu); |
| 6733 | | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 6704 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 6734 | 6705 | |
| 6735 | 6706 | if (intrinsicsAllowed(operand_scalar_ty, target)) { |
| 6736 | 6707 | // TODO set fast math flag |
| ... | ... | @@ -6762,7 +6733,7 @@ pub const FuncGen = struct { |
| 6762 | 6733 | compiler_rt_dest_abbrev, |
| 6763 | 6734 | }); |
| 6764 | 6735 | |
| 6765 | | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 6736 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 6766 | 6737 | const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty); |
| 6767 | 6738 | var result = try self.wip.call( |
| 6768 | 6739 | .normal, |
| ... | ... | @@ -6780,16 +6751,15 @@ pub const FuncGen = struct { |
| 6780 | 6751 | } |
| 6781 | 6752 | |
| 6782 | 6753 | fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { |
| 6783 | | const o = fg.ng.object; |
| 6784 | | const zcu = o.pt.zcu; |
| 6754 | const zcu = fg.ng.pt.zcu; |
| 6785 | 6755 | return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr; |
| 6786 | 6756 | } |
| 6787 | 6757 | |
| 6788 | 6758 | fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { |
| 6789 | 6759 | const o = fg.ng.object; |
| 6790 | | const pt = o.pt; |
| 6760 | const pt = fg.ng.pt; |
| 6791 | 6761 | const zcu = pt.zcu; |
| 6792 | | const llvm_usize = try o.lowerType(Type.usize); |
| 6762 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 6793 | 6763 | switch (ty.ptrSize(zcu)) { |
| 6794 | 6764 | .slice => { |
| 6795 | 6765 | const len = try fg.wip.extractValue(ptr, &.{1}, ""); |
| ... | ... | @@ -6817,18 +6787,19 @@ pub const FuncGen = struct { |
| 6817 | 6787 | |
| 6818 | 6788 | fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value { |
| 6819 | 6789 | const o = self.ng.object; |
| 6820 | | const zcu = o.pt.zcu; |
| 6790 | const pt = self.ng.pt; |
| 6791 | const zcu = pt.zcu; |
| 6821 | 6792 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6822 | 6793 | const slice_ptr = try self.resolveInst(ty_op.operand); |
| 6823 | 6794 | const slice_ptr_ty = self.typeOf(ty_op.operand); |
| 6824 | | const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(zcu)); |
| 6795 | const slice_llvm_ty = try o.lowerPtrElemTy(pt, slice_ptr_ty.childType(zcu)); |
| 6825 | 6796 | |
| 6826 | 6797 | return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, ""); |
| 6827 | 6798 | } |
| 6828 | 6799 | |
| 6829 | 6800 | fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6830 | 6801 | const o = self.ng.object; |
| 6831 | | const pt = o.pt; |
| 6802 | const pt = self.ng.pt; |
| 6832 | 6803 | const zcu = pt.zcu; |
| 6833 | 6804 | const inst = body_tail[0]; |
| 6834 | 6805 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| ... | ... | @@ -6836,7 +6807,7 @@ pub const FuncGen = struct { |
| 6836 | 6807 | const slice = try self.resolveInst(bin_op.lhs); |
| 6837 | 6808 | const index = try self.resolveInst(bin_op.rhs); |
| 6838 | 6809 | const elem_ty = slice_ty.childType(zcu); |
| 6839 | | const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty); |
| 6810 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty); |
| 6840 | 6811 | const base_ptr = try self.wip.extractValue(slice, &.{0}, ""); |
| 6841 | 6812 | const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, ""); |
| 6842 | 6813 | if (isByRef(elem_ty, zcu)) { |
| ... | ... | @@ -6856,21 +6827,22 @@ pub const FuncGen = struct { |
| 6856 | 6827 | |
| 6857 | 6828 | fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6858 | 6829 | const o = self.ng.object; |
| 6859 | | const zcu = o.pt.zcu; |
| 6830 | const pt = self.ng.pt; |
| 6831 | const zcu = pt.zcu; |
| 6860 | 6832 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 6861 | 6833 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6862 | 6834 | const slice_ty = self.typeOf(bin_op.lhs); |
| 6863 | 6835 | |
| 6864 | 6836 | const slice = try self.resolveInst(bin_op.lhs); |
| 6865 | 6837 | const index = try self.resolveInst(bin_op.rhs); |
| 6866 | | const llvm_elem_ty = try o.lowerPtrElemTy(slice_ty.childType(zcu)); |
| 6838 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, slice_ty.childType(zcu)); |
| 6867 | 6839 | const base_ptr = try self.wip.extractValue(slice, &.{0}, ""); |
| 6868 | 6840 | return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, ""); |
| 6869 | 6841 | } |
| 6870 | 6842 | |
| 6871 | 6843 | fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6872 | 6844 | const o = self.ng.object; |
| 6873 | | const pt = o.pt; |
| 6845 | const pt = self.ng.pt; |
| 6874 | 6846 | const zcu = pt.zcu; |
| 6875 | 6847 | const inst = body_tail[0]; |
| 6876 | 6848 | |
| ... | ... | @@ -6878,11 +6850,11 @@ pub const FuncGen = struct { |
| 6878 | 6850 | const array_ty = self.typeOf(bin_op.lhs); |
| 6879 | 6851 | const array_llvm_val = try self.resolveInst(bin_op.lhs); |
| 6880 | 6852 | const rhs = try self.resolveInst(bin_op.rhs); |
| 6881 | | const array_llvm_ty = try o.lowerType(array_ty); |
| 6853 | const array_llvm_ty = try o.lowerType(pt, array_ty); |
| 6882 | 6854 | const elem_ty = array_ty.childType(zcu); |
| 6883 | 6855 | if (isByRef(array_ty, zcu)) { |
| 6884 | 6856 | const indices: [2]Builder.Value = .{ |
| 6885 | | try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs, |
| 6857 | try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs, |
| 6886 | 6858 | }; |
| 6887 | 6859 | if (isByRef(elem_ty, zcu)) { |
| 6888 | 6860 | const elem_ptr = |
| ... | ... | @@ -6903,19 +6875,19 @@ pub const FuncGen = struct { |
| 6903 | 6875 | |
| 6904 | 6876 | fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6905 | 6877 | const o = self.ng.object; |
| 6906 | | const pt = o.pt; |
| 6878 | const pt = self.ng.pt; |
| 6907 | 6879 | const zcu = pt.zcu; |
| 6908 | 6880 | const inst = body_tail[0]; |
| 6909 | 6881 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 6910 | 6882 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 6911 | 6883 | const elem_ty = ptr_ty.childType(zcu); |
| 6912 | | const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty); |
| 6884 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty); |
| 6913 | 6885 | const base_ptr = try self.resolveInst(bin_op.lhs); |
| 6914 | 6886 | const rhs = try self.resolveInst(bin_op.rhs); |
| 6915 | 6887 | // TODO: when we go fully opaque pointers in LLVM 16 we can remove this branch |
| 6916 | 6888 | const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu)) |
| 6917 | 6889 | // If this is a single-item pointer to an array, we need another index in the GEP. |
| 6918 | | &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs } |
| 6890 | &.{ try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs } |
| 6919 | 6891 | else |
| 6920 | 6892 | &.{rhs}, ""); |
| 6921 | 6893 | if (isByRef(elem_ty, zcu)) { |
| ... | ... | @@ -6934,7 +6906,7 @@ pub const FuncGen = struct { |
| 6934 | 6906 | |
| 6935 | 6907 | fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6936 | 6908 | const o = self.ng.object; |
| 6937 | | const pt = o.pt; |
| 6909 | const pt = self.ng.pt; |
| 6938 | 6910 | const zcu = pt.zcu; |
| 6939 | 6911 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 6940 | 6912 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | ... | @@ -6948,10 +6920,10 @@ pub const FuncGen = struct { |
| 6948 | 6920 | const elem_ptr = ty_pl.ty.toType(); |
| 6949 | 6921 | if (elem_ptr.ptrInfo(zcu).flags.vector_index != .none) return base_ptr; |
| 6950 | 6922 | |
| 6951 | | const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty); |
| 6923 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, elem_ty); |
| 6952 | 6924 | return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu)) |
| 6953 | 6925 | // If this is a single-item pointer to an array, we need another index in the GEP. |
| 6954 | | &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs } |
| 6926 | &.{ try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), rhs } |
| 6955 | 6927 | else |
| 6956 | 6928 | &.{rhs}, ""); |
| 6957 | 6929 | } |
| ... | ... | @@ -6977,7 +6949,7 @@ pub const FuncGen = struct { |
| 6977 | 6949 | |
| 6978 | 6950 | fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 6979 | 6951 | const o = self.ng.object; |
| 6980 | | const pt = o.pt; |
| 6952 | const pt = self.ng.pt; |
| 6981 | 6953 | const zcu = pt.zcu; |
| 6982 | 6954 | const inst = body_tail[0]; |
| 6983 | 6955 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| ... | ... | @@ -6999,7 +6971,7 @@ pub const FuncGen = struct { |
| 6999 | 6971 | const shift_amt = |
| 7000 | 6972 | try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset); |
| 7001 | 6973 | const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, ""); |
| 7002 | | const elem_llvm_ty = try o.lowerType(field_ty); |
| 6974 | const elem_llvm_ty = try o.lowerType(pt, field_ty); |
| 7003 | 6975 | if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) { |
| 7004 | 6976 | const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu))); |
| 7005 | 6977 | const truncated_int = |
| ... | ... | @@ -7021,7 +6993,7 @@ pub const FuncGen = struct { |
| 7021 | 6993 | .@"union" => { |
| 7022 | 6994 | assert(struct_ty.containerLayout(zcu) == .@"packed"); |
| 7023 | 6995 | const containing_int = struct_llvm_val; |
| 7024 | | const elem_llvm_ty = try o.lowerType(field_ty); |
| 6996 | const elem_llvm_ty = try o.lowerType(pt, field_ty); |
| 7025 | 6997 | if (field_ty.zigTypeTag(zcu) == .float or field_ty.zigTypeTag(zcu) == .vector) { |
| 7026 | 6998 | const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu))); |
| 7027 | 6999 | const truncated_int = |
| ... | ... | @@ -7043,7 +7015,7 @@ pub const FuncGen = struct { |
| 7043 | 7015 | .@"struct" => { |
| 7044 | 7016 | const layout = struct_ty.containerLayout(zcu); |
| 7045 | 7017 | assert(layout != .@"packed"); |
| 7046 | | const struct_llvm_ty = try o.lowerType(struct_ty); |
| 7018 | const struct_llvm_ty = try o.lowerType(pt, struct_ty); |
| 7047 | 7019 | const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?; |
| 7048 | 7020 | const field_ptr = |
| 7049 | 7021 | try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, ""); |
| ... | ... | @@ -7064,7 +7036,7 @@ pub const FuncGen = struct { |
| 7064 | 7036 | } |
| 7065 | 7037 | }, |
| 7066 | 7038 | .@"union" => { |
| 7067 | | const union_llvm_ty = try o.lowerType(struct_ty); |
| 7039 | const union_llvm_ty = try o.lowerType(pt, struct_ty); |
| 7068 | 7040 | const layout = struct_ty.unionGetLayout(zcu); |
| 7069 | 7041 | const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)); |
| 7070 | 7042 | const field_ptr = |
| ... | ... | @@ -7083,7 +7055,7 @@ pub const FuncGen = struct { |
| 7083 | 7055 | |
| 7084 | 7056 | fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7085 | 7057 | const o = self.ng.object; |
| 7086 | | const pt = o.pt; |
| 7058 | const pt = self.ng.pt; |
| 7087 | 7059 | const zcu = pt.zcu; |
| 7088 | 7060 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 7089 | 7061 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| ... | ... | @@ -7094,8 +7066,8 @@ pub const FuncGen = struct { |
| 7094 | 7066 | const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu); |
| 7095 | 7067 | if (field_offset == 0) return field_ptr; |
| 7096 | 7068 | |
| 7097 | | const res_ty = try o.lowerType(ty_pl.ty.toType()); |
| 7098 | | const llvm_usize = try o.lowerType(Type.usize); |
| 7069 | const res_ty = try o.lowerType(pt, ty_pl.ty.toType()); |
| 7070 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 7099 | 7071 | |
| 7100 | 7072 | const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, ""); |
| 7101 | 7073 | const base_ptr_int = try self.wip.bin( |
| ... | ... | @@ -7151,7 +7123,8 @@ pub const FuncGen = struct { |
| 7151 | 7123 | |
| 7152 | 7124 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7153 | 7125 | const o = self.ng.object; |
| 7154 | | const zcu = o.pt.zcu; |
| 7126 | const pt = self.ng.pt; |
| 7127 | const zcu = pt.zcu; |
| 7155 | 7128 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 7156 | 7129 | const operand = try self.resolveInst(pl_op.operand); |
| 7157 | 7130 | const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload); |
| ... | ... | @@ -7162,7 +7135,7 @@ pub const FuncGen = struct { |
| 7162 | 7135 | self.file, |
| 7163 | 7136 | self.scope, |
| 7164 | 7137 | self.prev_dbg_line, |
| 7165 | | try o.lowerDebugType(ptr_ty.childType(zcu)), |
| 7138 | try o.lowerDebugType(pt, ptr_ty.childType(zcu)), |
| 7166 | 7139 | ); |
| 7167 | 7140 | |
| 7168 | 7141 | _ = try self.wip.callIntrinsic( |
| ... | ... | @@ -7183,6 +7156,7 @@ pub const FuncGen = struct { |
| 7183 | 7156 | |
| 7184 | 7157 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index, is_arg: bool) !Builder.Value { |
| 7185 | 7158 | const o = self.ng.object; |
| 7159 | const pt = self.ng.pt; |
| 7186 | 7160 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 7187 | 7161 | const operand = try self.resolveInst(pl_op.operand); |
| 7188 | 7162 | const operand_ty = self.typeOf(pl_op.operand); |
| ... | ... | @@ -7193,7 +7167,7 @@ pub const FuncGen = struct { |
| 7193 | 7167 | self.file, |
| 7194 | 7168 | self.scope, |
| 7195 | 7169 | self.prev_dbg_line, |
| 7196 | | try o.lowerDebugType(operand_ty), |
| 7170 | try o.lowerDebugType(pt, operand_ty), |
| 7197 | 7171 | arg_no: { |
| 7198 | 7172 | self.arg_inline_index += 1; |
| 7199 | 7173 | break :arg_no self.arg_inline_index; |
| ... | ... | @@ -7203,10 +7177,10 @@ pub const FuncGen = struct { |
| 7203 | 7177 | self.file, |
| 7204 | 7178 | self.scope, |
| 7205 | 7179 | self.prev_dbg_line, |
| 7206 | | try o.lowerDebugType(operand_ty), |
| 7180 | try o.lowerDebugType(pt, operand_ty), |
| 7207 | 7181 | ); |
| 7208 | 7182 | |
| 7209 | | const zcu = o.pt.zcu; |
| 7183 | const zcu = pt.zcu; |
| 7210 | 7184 | const owner_mod = self.ng.ownerModule(); |
| 7211 | 7185 | if (isByRef(operand_ty, zcu)) { |
| 7212 | 7186 | _ = try self.wip.callIntrinsic( |
| ... | ... | @@ -7296,7 +7270,7 @@ pub const FuncGen = struct { |
| 7296 | 7270 | // This stores whether we need to add an elementtype attribute and |
| 7297 | 7271 | // if so, the element type itself. |
| 7298 | 7272 | const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count); |
| 7299 | | const pt = o.pt; |
| 7273 | const pt = self.ng.pt; |
| 7300 | 7274 | const zcu = pt.zcu; |
| 7301 | 7275 | const target = zcu.getTarget(); |
| 7302 | 7276 | |
| ... | ... | @@ -7326,7 +7300,7 @@ pub const FuncGen = struct { |
| 7326 | 7300 | const output_inst = try self.resolveInst(output); |
| 7327 | 7301 | const output_ty = self.typeOf(output); |
| 7328 | 7302 | assert(output_ty.zigTypeTag(zcu) == .pointer); |
| 7329 | | const elem_llvm_ty = try o.lowerPtrElemTy(output_ty.childType(zcu)); |
| 7303 | const elem_llvm_ty = try o.lowerPtrElemTy(pt, output_ty.childType(zcu)); |
| 7330 | 7304 | |
| 7331 | 7305 | switch (constraint[0]) { |
| 7332 | 7306 | '=' => {}, |
| ... | ... | @@ -7364,7 +7338,7 @@ pub const FuncGen = struct { |
| 7364 | 7338 | is_indirect.* = false; |
| 7365 | 7339 | |
| 7366 | 7340 | const ret_ty = self.typeOfIndex(inst); |
| 7367 | | llvm_ret_types[llvm_ret_i] = try o.lowerType(ret_ty); |
| 7341 | llvm_ret_types[llvm_ret_i] = try o.lowerType(pt, ret_ty); |
| 7368 | 7342 | llvm_ret_i += 1; |
| 7369 | 7343 | } |
| 7370 | 7344 | |
| ... | ... | @@ -7406,7 +7380,7 @@ pub const FuncGen = struct { |
| 7406 | 7380 | llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip); |
| 7407 | 7381 | } else { |
| 7408 | 7382 | const alignment = arg_ty.abiAlignment(zcu).toLlvm(); |
| 7409 | | const arg_llvm_ty = try o.lowerType(arg_ty); |
| 7383 | const arg_llvm_ty = try o.lowerType(pt, arg_ty); |
| 7410 | 7384 | const load_inst = |
| 7411 | 7385 | try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, ""); |
| 7412 | 7386 | llvm_param_values[llvm_param_i] = load_inst; |
| ... | ... | @@ -7447,7 +7421,7 @@ pub const FuncGen = struct { |
| 7447 | 7421 | llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: { |
| 7448 | 7422 | if (!is_by_ref) self.maybeMarkAllowZeroAccess(arg_ty.ptrInfo(zcu)); |
| 7449 | 7423 | |
| 7450 | | break :blk try o.lowerPtrElemTy(if (is_by_ref) arg_ty else arg_ty.childType(zcu)); |
| 7424 | break :blk try o.lowerPtrElemTy(pt, if (is_by_ref) arg_ty else arg_ty.childType(zcu)); |
| 7451 | 7425 | } else .none; |
| 7452 | 7426 | |
| 7453 | 7427 | llvm_param_i += 1; |
| ... | ... | @@ -7465,7 +7439,7 @@ pub const FuncGen = struct { |
| 7465 | 7439 | if (constraint[0] != '+') continue; |
| 7466 | 7440 | |
| 7467 | 7441 | const rw_ty = self.typeOf(output); |
| 7468 | | const llvm_elem_ty = try o.lowerPtrElemTy(rw_ty.childType(zcu)); |
| 7442 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, rw_ty.childType(zcu)); |
| 7469 | 7443 | if (is_indirect) { |
| 7470 | 7444 | llvm_param_values[llvm_param_i] = llvm_rw_val; |
| 7471 | 7445 | llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip); |
| ... | ... | @@ -7663,13 +7637,13 @@ pub const FuncGen = struct { |
| 7663 | 7637 | cond: Builder.IntegerCondition, |
| 7664 | 7638 | ) !Builder.Value { |
| 7665 | 7639 | const o = self.ng.object; |
| 7666 | | const pt = o.pt; |
| 7640 | const pt = self.ng.pt; |
| 7667 | 7641 | const zcu = pt.zcu; |
| 7668 | 7642 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 7669 | 7643 | const operand = try self.resolveInst(un_op); |
| 7670 | 7644 | const operand_ty = self.typeOf(un_op); |
| 7671 | 7645 | const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; |
| 7672 | | const optional_llvm_ty = try o.lowerType(optional_ty); |
| 7646 | const optional_llvm_ty = try o.lowerType(pt, optional_ty); |
| 7673 | 7647 | const payload_ty = optional_ty.optionalChild(zcu); |
| 7674 | 7648 | |
| 7675 | 7649 | const access_kind: Builder.MemoryAccessKind = |
| ... | ... | @@ -7714,14 +7688,14 @@ pub const FuncGen = struct { |
| 7714 | 7688 | operand_is_ptr: bool, |
| 7715 | 7689 | ) !Builder.Value { |
| 7716 | 7690 | const o = self.ng.object; |
| 7717 | | const pt = o.pt; |
| 7691 | const pt = self.ng.pt; |
| 7718 | 7692 | const zcu = pt.zcu; |
| 7719 | 7693 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 7720 | 7694 | const operand = try self.resolveInst(un_op); |
| 7721 | 7695 | const operand_ty = self.typeOf(un_op); |
| 7722 | 7696 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; |
| 7723 | 7697 | const payload_ty = err_union_ty.errorUnionPayload(zcu); |
| 7724 | | const error_type = try o.errorIntType(); |
| 7698 | const error_type = try o.errorIntType(pt); |
| 7725 | 7699 | const zero = try o.builder.intValue(error_type, 0); |
| 7726 | 7700 | |
| 7727 | 7701 | const access_kind: Builder.MemoryAccessKind = |
| ... | ... | @@ -7740,7 +7714,7 @@ pub const FuncGen = struct { |
| 7740 | 7714 | |
| 7741 | 7715 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 7742 | 7716 | const loaded = if (operand_is_ptr) |
| 7743 | | try self.wip.load(access_kind, try o.lowerType(err_union_ty), operand, .default, "") |
| 7717 | try self.wip.load(access_kind, try o.lowerType(pt, err_union_ty), operand, .default, "") |
| 7744 | 7718 | else |
| 7745 | 7719 | operand; |
| 7746 | 7720 | return self.wip.icmp(cond, loaded, zero, ""); |
| ... | ... | @@ -7749,7 +7723,7 @@ pub const FuncGen = struct { |
| 7749 | 7723 | const err_field_index = try errUnionErrorOffset(payload_ty, pt); |
| 7750 | 7724 | |
| 7751 | 7725 | const loaded = if (operand_is_ptr or isByRef(err_union_ty, zcu)) loaded: { |
| 7752 | | const err_union_llvm_ty = try o.lowerType(err_union_ty); |
| 7726 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 7753 | 7727 | const err_field_ptr = |
| 7754 | 7728 | try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, ""); |
| 7755 | 7729 | break :loaded try self.wip.load(access_kind, error_type, err_field_ptr, .default, ""); |
| ... | ... | @@ -7759,7 +7733,7 @@ pub const FuncGen = struct { |
| 7759 | 7733 | |
| 7760 | 7734 | fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7761 | 7735 | const o = self.ng.object; |
| 7762 | | const pt = o.pt; |
| 7736 | const pt = self.ng.pt; |
| 7763 | 7737 | const zcu = pt.zcu; |
| 7764 | 7738 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7765 | 7739 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -7774,14 +7748,14 @@ pub const FuncGen = struct { |
| 7774 | 7748 | // The payload and the optional are the same value. |
| 7775 | 7749 | return operand; |
| 7776 | 7750 | } |
| 7777 | | return self.wip.gepStruct(try o.lowerType(optional_ty), operand, 0, ""); |
| 7751 | return self.wip.gepStruct(try o.lowerType(pt, optional_ty), operand, 0, ""); |
| 7778 | 7752 | } |
| 7779 | 7753 | |
| 7780 | 7754 | fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7781 | 7755 | comptime assert(optional_layout_version == 3); |
| 7782 | 7756 | |
| 7783 | 7757 | const o = self.ng.object; |
| 7784 | | const pt = o.pt; |
| 7758 | const pt = self.ng.pt; |
| 7785 | 7759 | const zcu = pt.zcu; |
| 7786 | 7760 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7787 | 7761 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -7807,7 +7781,7 @@ pub const FuncGen = struct { |
| 7807 | 7781 | } |
| 7808 | 7782 | |
| 7809 | 7783 | // First set the non-null bit. |
| 7810 | | const optional_llvm_ty = try o.lowerType(optional_ty); |
| 7784 | const optional_llvm_ty = try o.lowerType(pt, optional_ty); |
| 7811 | 7785 | const non_null_ptr = try self.wip.gepStruct(optional_llvm_ty, operand, 1, ""); |
| 7812 | 7786 | |
| 7813 | 7787 | self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu)); |
| ... | ... | @@ -7823,7 +7797,7 @@ pub const FuncGen = struct { |
| 7823 | 7797 | |
| 7824 | 7798 | fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 7825 | 7799 | const o = self.ng.object; |
| 7826 | | const pt = o.pt; |
| 7800 | const pt = self.ng.pt; |
| 7827 | 7801 | const zcu = pt.zcu; |
| 7828 | 7802 | const inst = body_tail[0]; |
| 7829 | 7803 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -7837,7 +7811,7 @@ pub const FuncGen = struct { |
| 7837 | 7811 | return operand; |
| 7838 | 7812 | } |
| 7839 | 7813 | |
| 7840 | | const opt_llvm_ty = try o.lowerType(optional_ty); |
| 7814 | const opt_llvm_ty = try o.lowerType(pt, optional_ty); |
| 7841 | 7815 | const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false; |
| 7842 | 7816 | return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load); |
| 7843 | 7817 | } |
| ... | ... | @@ -7848,7 +7822,7 @@ pub const FuncGen = struct { |
| 7848 | 7822 | operand_is_ptr: bool, |
| 7849 | 7823 | ) !Builder.Value { |
| 7850 | 7824 | const o = self.ng.object; |
| 7851 | | const pt = o.pt; |
| 7825 | const pt = self.ng.pt; |
| 7852 | 7826 | const zcu = pt.zcu; |
| 7853 | 7827 | const inst = body_tail[0]; |
| 7854 | 7828 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -7862,7 +7836,7 @@ pub const FuncGen = struct { |
| 7862 | 7836 | return if (operand_is_ptr) operand else .none; |
| 7863 | 7837 | } |
| 7864 | 7838 | const offset = try errUnionPayloadOffset(payload_ty, pt); |
| 7865 | | const err_union_llvm_ty = try o.lowerType(err_union_ty); |
| 7839 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 7866 | 7840 | if (operand_is_ptr) { |
| 7867 | 7841 | return self.wip.gepStruct(err_union_llvm_ty, operand, offset, ""); |
| 7868 | 7842 | } else if (isByRef(err_union_ty, zcu)) { |
| ... | ... | @@ -7884,12 +7858,12 @@ pub const FuncGen = struct { |
| 7884 | 7858 | operand_is_ptr: bool, |
| 7885 | 7859 | ) !Builder.Value { |
| 7886 | 7860 | const o = self.ng.object; |
| 7887 | | const pt = o.pt; |
| 7861 | const pt = self.ng.pt; |
| 7888 | 7862 | const zcu = pt.zcu; |
| 7889 | 7863 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7890 | 7864 | const operand = try self.resolveInst(ty_op.operand); |
| 7891 | 7865 | const operand_ty = self.typeOf(ty_op.operand); |
| 7892 | | const error_type = try o.errorIntType(); |
| 7866 | const error_type = try o.errorIntType(pt); |
| 7893 | 7867 | const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; |
| 7894 | 7868 | if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) { |
| 7895 | 7869 | if (operand_is_ptr) { |
| ... | ... | @@ -7916,7 +7890,7 @@ pub const FuncGen = struct { |
| 7916 | 7890 | if (operand_is_ptr or isByRef(err_union_ty, zcu)) { |
| 7917 | 7891 | if (operand_is_ptr) self.maybeMarkAllowZeroAccess(operand_ty.ptrInfo(zcu)); |
| 7918 | 7892 | |
| 7919 | | const err_union_llvm_ty = try o.lowerType(err_union_ty); |
| 7893 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 7920 | 7894 | const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, ""); |
| 7921 | 7895 | return self.wip.load(access_kind, error_type, err_field_ptr, .default, ""); |
| 7922 | 7896 | } |
| ... | ... | @@ -7926,7 +7900,7 @@ pub const FuncGen = struct { |
| 7926 | 7900 | |
| 7927 | 7901 | fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7928 | 7902 | const o = self.ng.object; |
| 7929 | | const pt = o.pt; |
| 7903 | const pt = self.ng.pt; |
| 7930 | 7904 | const zcu = pt.zcu; |
| 7931 | 7905 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7932 | 7906 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -7934,7 +7908,7 @@ pub const FuncGen = struct { |
| 7934 | 7908 | const err_union_ty = err_union_ptr_ty.childType(zcu); |
| 7935 | 7909 | |
| 7936 | 7910 | const payload_ty = err_union_ty.errorUnionPayload(zcu); |
| 7937 | | const non_error_val = try o.builder.intValue(try o.errorIntType(), 0); |
| 7911 | const non_error_val = try o.builder.intValue(try o.errorIntType(pt), 0); |
| 7938 | 7912 | |
| 7939 | 7913 | const access_kind: Builder.MemoryAccessKind = |
| 7940 | 7914 | if (err_union_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; |
| ... | ... | @@ -7945,7 +7919,7 @@ pub const FuncGen = struct { |
| 7945 | 7919 | _ = try self.wip.store(access_kind, non_error_val, operand, .default); |
| 7946 | 7920 | return operand; |
| 7947 | 7921 | } |
| 7948 | | const err_union_llvm_ty = try o.lowerType(err_union_ty); |
| 7922 | const err_union_llvm_ty = try o.lowerType(pt, err_union_ty); |
| 7949 | 7923 | { |
| 7950 | 7924 | self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu)); |
| 7951 | 7925 | |
| ... | ... | @@ -7976,14 +7950,14 @@ pub const FuncGen = struct { |
| 7976 | 7950 | |
| 7977 | 7951 | fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 7978 | 7952 | const o = self.ng.object; |
| 7979 | | const pt = o.pt; |
| 7953 | const pt = self.ng.pt; |
| 7980 | 7954 | const zcu = pt.zcu; |
| 7981 | 7955 | |
| 7982 | 7956 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 7983 | 7957 | const struct_ty = ty_pl.ty.toType(); |
| 7984 | 7958 | const field_index = ty_pl.payload; |
| 7985 | 7959 | |
| 7986 | | const struct_llvm_ty = try o.lowerType(struct_ty); |
| 7960 | const struct_llvm_ty = try o.lowerType(pt, struct_ty); |
| 7987 | 7961 | const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?; |
| 7988 | 7962 | assert(self.err_ret_trace != .none); |
| 7989 | 7963 | const field_ptr = |
| ... | ... | @@ -8022,7 +7996,7 @@ pub const FuncGen = struct { |
| 8022 | 7996 | |
| 8023 | 7997 | fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 8024 | 7998 | const o = self.ng.object; |
| 8025 | | const pt = o.pt; |
| 7999 | const pt = self.ng.pt; |
| 8026 | 8000 | const zcu = pt.zcu; |
| 8027 | 8001 | const inst = body_tail[0]; |
| 8028 | 8002 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -8033,7 +8007,7 @@ pub const FuncGen = struct { |
| 8033 | 8007 | const operand = try self.resolveInst(ty_op.operand); |
| 8034 | 8008 | const optional_ty = self.typeOfIndex(inst); |
| 8035 | 8009 | if (optional_ty.optionalReprIsPayload(zcu)) return operand; |
| 8036 | | const llvm_optional_ty = try o.lowerType(optional_ty); |
| 8010 | const llvm_optional_ty = try o.lowerType(pt, optional_ty); |
| 8037 | 8011 | if (isByRef(optional_ty, zcu)) { |
| 8038 | 8012 | const directReturn = self.isNextRet(body_tail); |
| 8039 | 8013 | const optional_ptr = if (directReturn) |
| ... | ... | @@ -8056,7 +8030,7 @@ pub const FuncGen = struct { |
| 8056 | 8030 | |
| 8057 | 8031 | fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 8058 | 8032 | const o = self.ng.object; |
| 8059 | | const pt = o.pt; |
| 8033 | const pt = self.ng.pt; |
| 8060 | 8034 | const zcu = pt.zcu; |
| 8061 | 8035 | const inst = body_tail[0]; |
| 8062 | 8036 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -8066,8 +8040,8 @@ pub const FuncGen = struct { |
| 8066 | 8040 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 8067 | 8041 | return operand; |
| 8068 | 8042 | } |
| 8069 | | const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0); |
| 8070 | | const err_un_llvm_ty = try o.lowerType(err_un_ty); |
| 8043 | const ok_err_code = try o.builder.intValue(try o.errorIntType(pt), 0); |
| 8044 | const err_un_llvm_ty = try o.lowerType(pt, err_un_ty); |
| 8071 | 8045 | |
| 8072 | 8046 | const payload_offset = try errUnionPayloadOffset(payload_ty, pt); |
| 8073 | 8047 | const error_offset = try errUnionErrorOffset(payload_ty, pt); |
| ... | ... | @@ -8098,7 +8072,7 @@ pub const FuncGen = struct { |
| 8098 | 8072 | |
| 8099 | 8073 | fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 8100 | 8074 | const o = self.ng.object; |
| 8101 | | const pt = o.pt; |
| 8075 | const pt = self.ng.pt; |
| 8102 | 8076 | const zcu = pt.zcu; |
| 8103 | 8077 | const inst = body_tail[0]; |
| 8104 | 8078 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -8106,7 +8080,7 @@ pub const FuncGen = struct { |
| 8106 | 8080 | const payload_ty = err_un_ty.errorUnionPayload(zcu); |
| 8107 | 8081 | const operand = try self.resolveInst(ty_op.operand); |
| 8108 | 8082 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return operand; |
| 8109 | | const err_un_llvm_ty = try o.lowerType(err_un_ty); |
| 8083 | const err_un_llvm_ty = try o.lowerType(pt, err_un_ty); |
| 8110 | 8084 | |
| 8111 | 8085 | const payload_offset = try errUnionPayloadOffset(payload_ty, pt); |
| 8112 | 8086 | const error_offset = try errUnionErrorOffset(payload_ty, pt); |
| ... | ... | @@ -8139,9 +8113,10 @@ pub const FuncGen = struct { |
| 8139 | 8113 | |
| 8140 | 8114 | fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8141 | 8115 | const o = self.ng.object; |
| 8116 | const pt = self.ng.pt; |
| 8142 | 8117 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 8143 | 8118 | const index = pl_op.payload; |
| 8144 | | const llvm_usize = try o.lowerType(Type.usize); |
| 8119 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 8145 | 8120 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{ |
| 8146 | 8121 | try o.builder.intValue(.i32, index), |
| 8147 | 8122 | }, ""); |
| ... | ... | @@ -8149,9 +8124,10 @@ pub const FuncGen = struct { |
| 8149 | 8124 | |
| 8150 | 8125 | fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8151 | 8126 | const o = self.ng.object; |
| 8127 | const pt = self.ng.pt; |
| 8152 | 8128 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 8153 | 8129 | const index = pl_op.payload; |
| 8154 | | const llvm_isize = try o.lowerType(Type.isize); |
| 8130 | const llvm_isize = try o.lowerType(pt, Type.isize); |
| 8155 | 8131 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{ |
| 8156 | 8132 | try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand), |
| 8157 | 8133 | }, ""); |
| ... | ... | @@ -8159,7 +8135,7 @@ pub const FuncGen = struct { |
| 8159 | 8135 | |
| 8160 | 8136 | fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8161 | 8137 | const o = self.ng.object; |
| 8162 | | const pt = o.pt; |
| 8138 | const pt = self.ng.pt; |
| 8163 | 8139 | const zcu = pt.zcu; |
| 8164 | 8140 | const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem; |
| 8165 | 8141 | const extra = self.air.extraData(Air.Bin, data.payload).data; |
| ... | ... | @@ -8175,7 +8151,7 @@ pub const FuncGen = struct { |
| 8175 | 8151 | // https://github.com/ziglang/zig/issues/18652#issuecomment-2452844908 |
| 8176 | 8152 | const access_kind: Builder.MemoryAccessKind = |
| 8177 | 8153 | if (vector_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; |
| 8178 | | const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(zcu)); |
| 8154 | const elem_llvm_ty = try o.lowerType(pt, vector_ptr_ty.childType(zcu)); |
| 8179 | 8155 | const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 8180 | 8156 | const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, ""); |
| 8181 | 8157 | |
| ... | ... | @@ -8186,14 +8162,16 @@ pub const FuncGen = struct { |
| 8186 | 8162 | |
| 8187 | 8163 | fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8188 | 8164 | const o = fg.ng.object; |
| 8165 | const pt = fg.ng.pt; |
| 8189 | 8166 | const ty_nav = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav; |
| 8190 | | const llvm_ptr_const = try o.lowerNavRefValue(ty_nav.nav); |
| 8167 | const llvm_ptr_const = try o.lowerNavRefValue(pt, ty_nav.nav); |
| 8191 | 8168 | return llvm_ptr_const.toValue(); |
| 8192 | 8169 | } |
| 8193 | 8170 | |
| 8194 | 8171 | fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8195 | 8172 | const o = self.ng.object; |
| 8196 | | const zcu = o.pt.zcu; |
| 8173 | const pt = self.ng.pt; |
| 8174 | const zcu = pt.zcu; |
| 8197 | 8175 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8198 | 8176 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8199 | 8177 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8205,7 +8183,7 @@ pub const FuncGen = struct { |
| 8205 | 8183 | .normal, |
| 8206 | 8184 | .none, |
| 8207 | 8185 | if (scalar_ty.isSignedInt(zcu)) .smin else .umin, |
| 8208 | | &.{try o.lowerType(inst_ty)}, |
| 8186 | &.{try o.lowerType(pt, inst_ty)}, |
| 8209 | 8187 | &.{ lhs, rhs }, |
| 8210 | 8188 | "", |
| 8211 | 8189 | ); |
| ... | ... | @@ -8213,7 +8191,8 @@ pub const FuncGen = struct { |
| 8213 | 8191 | |
| 8214 | 8192 | fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8215 | 8193 | const o = self.ng.object; |
| 8216 | | const zcu = o.pt.zcu; |
| 8194 | const pt = self.ng.pt; |
| 8195 | const zcu = pt.zcu; |
| 8217 | 8196 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8218 | 8197 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8219 | 8198 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8225,7 +8204,7 @@ pub const FuncGen = struct { |
| 8225 | 8204 | .normal, |
| 8226 | 8205 | .none, |
| 8227 | 8206 | if (scalar_ty.isSignedInt(zcu)) .smax else .umax, |
| 8228 | | &.{try o.lowerType(inst_ty)}, |
| 8207 | &.{try o.lowerType(pt, inst_ty)}, |
| 8229 | 8208 | &.{ lhs, rhs }, |
| 8230 | 8209 | "", |
| 8231 | 8210 | ); |
| ... | ... | @@ -8233,17 +8212,17 @@ pub const FuncGen = struct { |
| 8233 | 8212 | |
| 8234 | 8213 | fn airSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8235 | 8214 | const o = self.ng.object; |
| 8215 | const pt = self.ng.pt; |
| 8236 | 8216 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8237 | 8217 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8238 | 8218 | const ptr = try self.resolveInst(bin_op.lhs); |
| 8239 | 8219 | const len = try self.resolveInst(bin_op.rhs); |
| 8240 | 8220 | const inst_ty = self.typeOfIndex(inst); |
| 8241 | | return self.wip.buildAggregate(try o.lowerType(inst_ty), &.{ ptr, len }, ""); |
| 8221 | return self.wip.buildAggregate(try o.lowerType(pt, inst_ty), &.{ ptr, len }, ""); |
| 8242 | 8222 | } |
| 8243 | 8223 | |
| 8244 | 8224 | fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8245 | | const o = self.ng.object; |
| 8246 | | const zcu = o.pt.zcu; |
| 8225 | const zcu = self.ng.pt.zcu; |
| 8247 | 8226 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8248 | 8227 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8249 | 8228 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8261,7 +8240,8 @@ pub const FuncGen = struct { |
| 8261 | 8240 | unsigned_intrinsic: Builder.Intrinsic, |
| 8262 | 8241 | ) !Builder.Value { |
| 8263 | 8242 | const o = fg.ng.object; |
| 8264 | | const zcu = o.pt.zcu; |
| 8243 | const pt = fg.ng.pt; |
| 8244 | const zcu = pt.zcu; |
| 8265 | 8245 | |
| 8266 | 8246 | const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8267 | 8247 | const lhs = try fg.resolveInst(bin_op.lhs); |
| ... | ... | @@ -8270,7 +8250,7 @@ pub const FuncGen = struct { |
| 8270 | 8250 | const scalar_ty = inst_ty.scalarType(zcu); |
| 8271 | 8251 | |
| 8272 | 8252 | const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic; |
| 8273 | | const llvm_inst_ty = try o.lowerType(inst_ty); |
| 8253 | const llvm_inst_ty = try o.lowerType(pt, inst_ty); |
| 8274 | 8254 | const results = |
| 8275 | 8255 | try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, ""); |
| 8276 | 8256 | |
| ... | ... | @@ -8309,7 +8289,8 @@ pub const FuncGen = struct { |
| 8309 | 8289 | |
| 8310 | 8290 | fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8311 | 8291 | const o = self.ng.object; |
| 8312 | | const zcu = o.pt.zcu; |
| 8292 | const pt = self.ng.pt; |
| 8293 | const zcu = pt.zcu; |
| 8313 | 8294 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8314 | 8295 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8315 | 8296 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8321,15 +8302,14 @@ pub const FuncGen = struct { |
| 8321 | 8302 | .normal, |
| 8322 | 8303 | .none, |
| 8323 | 8304 | if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat", |
| 8324 | | &.{try o.lowerType(inst_ty)}, |
| 8305 | &.{try o.lowerType(pt, inst_ty)}, |
| 8325 | 8306 | &.{ lhs, rhs }, |
| 8326 | 8307 | "", |
| 8327 | 8308 | ); |
| 8328 | 8309 | } |
| 8329 | 8310 | |
| 8330 | 8311 | fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8331 | | const o = self.ng.object; |
| 8332 | | const zcu = o.pt.zcu; |
| 8312 | const zcu = self.ng.pt.zcu; |
| 8333 | 8313 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8334 | 8314 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8335 | 8315 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8350,7 +8330,8 @@ pub const FuncGen = struct { |
| 8350 | 8330 | |
| 8351 | 8331 | fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8352 | 8332 | const o = self.ng.object; |
| 8353 | | const zcu = o.pt.zcu; |
| 8333 | const pt = self.ng.pt; |
| 8334 | const zcu = pt.zcu; |
| 8354 | 8335 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8355 | 8336 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8356 | 8337 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8362,15 +8343,14 @@ pub const FuncGen = struct { |
| 8362 | 8343 | .normal, |
| 8363 | 8344 | .none, |
| 8364 | 8345 | if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat", |
| 8365 | | &.{try o.lowerType(inst_ty)}, |
| 8346 | &.{try o.lowerType(pt, inst_ty)}, |
| 8366 | 8347 | &.{ lhs, rhs }, |
| 8367 | 8348 | "", |
| 8368 | 8349 | ); |
| 8369 | 8350 | } |
| 8370 | 8351 | |
| 8371 | 8352 | fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8372 | | const o = self.ng.object; |
| 8373 | | const zcu = o.pt.zcu; |
| 8353 | const zcu = self.ng.pt.zcu; |
| 8374 | 8354 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8375 | 8355 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8376 | 8356 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8391,7 +8371,8 @@ pub const FuncGen = struct { |
| 8391 | 8371 | |
| 8392 | 8372 | fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8393 | 8373 | const o = self.ng.object; |
| 8394 | | const zcu = o.pt.zcu; |
| 8374 | const pt = self.ng.pt; |
| 8375 | const zcu = pt.zcu; |
| 8395 | 8376 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8396 | 8377 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8397 | 8378 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8403,7 +8384,7 @@ pub const FuncGen = struct { |
| 8403 | 8384 | .normal, |
| 8404 | 8385 | .none, |
| 8405 | 8386 | if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat", |
| 8406 | | &.{try o.lowerType(inst_ty)}, |
| 8387 | &.{try o.lowerType(pt, inst_ty)}, |
| 8407 | 8388 | &.{ lhs, rhs, .@"0" }, |
| 8408 | 8389 | "", |
| 8409 | 8390 | ); |
| ... | ... | @@ -8419,8 +8400,7 @@ pub const FuncGen = struct { |
| 8419 | 8400 | } |
| 8420 | 8401 | |
| 8421 | 8402 | fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8422 | | const o = self.ng.object; |
| 8423 | | const zcu = o.pt.zcu; |
| 8403 | const zcu = self.ng.pt.zcu; |
| 8424 | 8404 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8425 | 8405 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8426 | 8406 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8436,7 +8416,8 @@ pub const FuncGen = struct { |
| 8436 | 8416 | |
| 8437 | 8417 | fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8438 | 8418 | const o = self.ng.object; |
| 8439 | | const zcu = o.pt.zcu; |
| 8419 | const pt = self.ng.pt; |
| 8420 | const zcu = pt.zcu; |
| 8440 | 8421 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8441 | 8422 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8442 | 8423 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8448,7 +8429,7 @@ pub const FuncGen = struct { |
| 8448 | 8429 | return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result}); |
| 8449 | 8430 | } |
| 8450 | 8431 | if (scalar_ty.isSignedInt(zcu)) { |
| 8451 | | const inst_llvm_ty = try o.lowerType(inst_ty); |
| 8432 | const inst_llvm_ty = try o.lowerType(pt, inst_ty); |
| 8452 | 8433 | |
| 8453 | 8434 | const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb; |
| 8454 | 8435 | var stack align(@max( |
| ... | ... | @@ -8485,8 +8466,7 @@ pub const FuncGen = struct { |
| 8485 | 8466 | } |
| 8486 | 8467 | |
| 8487 | 8468 | fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8488 | | const o = self.ng.object; |
| 8489 | | const zcu = o.pt.zcu; |
| 8469 | const zcu = self.ng.pt.zcu; |
| 8490 | 8470 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8491 | 8471 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8492 | 8472 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8503,8 +8483,7 @@ pub const FuncGen = struct { |
| 8503 | 8483 | } |
| 8504 | 8484 | |
| 8505 | 8485 | fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8506 | | const o = self.ng.object; |
| 8507 | | const zcu = o.pt.zcu; |
| 8486 | const zcu = self.ng.pt.zcu; |
| 8508 | 8487 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8509 | 8488 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8510 | 8489 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -8521,12 +8500,13 @@ pub const FuncGen = struct { |
| 8521 | 8500 | |
| 8522 | 8501 | fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 8523 | 8502 | const o = self.ng.object; |
| 8524 | | const zcu = o.pt.zcu; |
| 8503 | const pt = self.ng.pt; |
| 8504 | const zcu = pt.zcu; |
| 8525 | 8505 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 8526 | 8506 | const lhs = try self.resolveInst(bin_op.lhs); |
| 8527 | 8507 | const rhs = try self.resolveInst(bin_op.rhs); |
| 8528 | 8508 | const inst_ty = self.typeOfIndex(inst); |
| 8529 | | const inst_llvm_ty = try o.lowerType(inst_ty); |
| 8509 | const inst_llvm_ty = try o.lowerType(pt, inst_ty); |
| 8530 | 8510 | const scalar_ty = inst_ty.scalarType(zcu); |
| 8531 | 8511 | |
| 8532 | 8512 | if (scalar_ty.isRuntimeFloat()) { |
| ... | ... | @@ -8574,17 +8554,18 @@ pub const FuncGen = struct { |
| 8574 | 8554 | |
| 8575 | 8555 | fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8576 | 8556 | const o = self.ng.object; |
| 8577 | | const zcu = o.pt.zcu; |
| 8557 | const pt = self.ng.pt; |
| 8558 | const zcu = pt.zcu; |
| 8578 | 8559 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8579 | 8560 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8580 | 8561 | const ptr = try self.resolveInst(bin_op.lhs); |
| 8581 | 8562 | const offset = try self.resolveInst(bin_op.rhs); |
| 8582 | 8563 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 8583 | | const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu)); |
| 8564 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, ptr_ty.childType(zcu)); |
| 8584 | 8565 | switch (ptr_ty.ptrSize(zcu)) { |
| 8585 | 8566 | // It's a pointer to an array, so according to LLVM we need an extra GEP index. |
| 8586 | 8567 | .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{ |
| 8587 | | try o.builder.intValue(try o.lowerType(Type.usize), 0), offset, |
| 8568 | try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), offset, |
| 8588 | 8569 | }, ""), |
| 8589 | 8570 | .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""), |
| 8590 | 8571 | .slice => { |
| ... | ... | @@ -8596,18 +8577,19 @@ pub const FuncGen = struct { |
| 8596 | 8577 | |
| 8597 | 8578 | fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8598 | 8579 | const o = self.ng.object; |
| 8599 | | const zcu = o.pt.zcu; |
| 8580 | const pt = self.ng.pt; |
| 8581 | const zcu = pt.zcu; |
| 8600 | 8582 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8601 | 8583 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 8602 | 8584 | const ptr = try self.resolveInst(bin_op.lhs); |
| 8603 | 8585 | const offset = try self.resolveInst(bin_op.rhs); |
| 8604 | 8586 | const negative_offset = try self.wip.neg(offset, ""); |
| 8605 | 8587 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 8606 | | const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu)); |
| 8588 | const llvm_elem_ty = try o.lowerPtrElemTy(pt, ptr_ty.childType(zcu)); |
| 8607 | 8589 | switch (ptr_ty.ptrSize(zcu)) { |
| 8608 | 8590 | // It's a pointer to an array, so according to LLVM we need an extra GEP index. |
| 8609 | 8591 | .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{ |
| 8610 | | try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset, |
| 8592 | try o.builder.intValue(try o.lowerType(pt, Type.usize), 0), negative_offset, |
| 8611 | 8593 | }, ""), |
| 8612 | 8594 | .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""), |
| 8613 | 8595 | .slice => { |
| ... | ... | @@ -8624,7 +8606,7 @@ pub const FuncGen = struct { |
| 8624 | 8606 | unsigned_intrinsic: Builder.Intrinsic, |
| 8625 | 8607 | ) !Builder.Value { |
| 8626 | 8608 | const o = self.ng.object; |
| 8627 | | const pt = o.pt; |
| 8609 | const pt = self.ng.pt; |
| 8628 | 8610 | const zcu = pt.zcu; |
| 8629 | 8611 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8630 | 8612 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | ... | @@ -8637,8 +8619,8 @@ pub const FuncGen = struct { |
| 8637 | 8619 | const inst_ty = self.typeOfIndex(inst); |
| 8638 | 8620 | |
| 8639 | 8621 | const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic; |
| 8640 | | const llvm_inst_ty = try o.lowerType(inst_ty); |
| 8641 | | const llvm_lhs_ty = try o.lowerType(lhs_ty); |
| 8622 | const llvm_inst_ty = try o.lowerType(pt, inst_ty); |
| 8623 | const llvm_lhs_ty = try o.lowerType(pt, lhs_ty); |
| 8642 | 8624 | const results = |
| 8643 | 8625 | try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, ""); |
| 8644 | 8626 | |
| ... | ... | @@ -8718,7 +8700,7 @@ pub const FuncGen = struct { |
| 8718 | 8700 | return o.builder.addFunction( |
| 8719 | 8701 | try o.builder.fnType(return_type, param_types, .normal), |
| 8720 | 8702 | fn_name, |
| 8721 | | toLlvmAddressSpace(.generic, o.pt.zcu.getTarget()), |
| 8703 | toLlvmAddressSpace(.generic, self.ng.pt.zcu.getTarget()), |
| 8722 | 8704 | ); |
| 8723 | 8705 | } |
| 8724 | 8706 | |
| ... | ... | @@ -8732,10 +8714,11 @@ pub const FuncGen = struct { |
| 8732 | 8714 | params: [2]Builder.Value, |
| 8733 | 8715 | ) !Builder.Value { |
| 8734 | 8716 | const o = self.ng.object; |
| 8735 | | const zcu = o.pt.zcu; |
| 8717 | const pt = self.ng.pt; |
| 8718 | const zcu = pt.zcu; |
| 8736 | 8719 | const target = zcu.getTarget(); |
| 8737 | 8720 | const scalar_ty = ty.scalarType(zcu); |
| 8738 | | const scalar_llvm_ty = try o.lowerType(scalar_ty); |
| 8721 | const scalar_llvm_ty = try o.lowerType(pt, scalar_ty); |
| 8739 | 8722 | |
| 8740 | 8723 | if (intrinsicsAllowed(scalar_ty, target)) { |
| 8741 | 8724 | const cond: Builder.FloatCondition = switch (pred) { |
| ... | ... | @@ -8838,10 +8821,11 @@ pub const FuncGen = struct { |
| 8838 | 8821 | params: [params_len]Builder.Value, |
| 8839 | 8822 | ) !Builder.Value { |
| 8840 | 8823 | const o = self.ng.object; |
| 8841 | | const zcu = o.pt.zcu; |
| 8824 | const pt = self.ng.pt; |
| 8825 | const zcu = pt.zcu; |
| 8842 | 8826 | const target = zcu.getTarget(); |
| 8843 | 8827 | const scalar_ty = ty.scalarType(zcu); |
| 8844 | | const llvm_ty = try o.lowerType(ty); |
| 8828 | const llvm_ty = try o.lowerType(pt, ty); |
| 8845 | 8829 | |
| 8846 | 8830 | if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) { |
| 8847 | 8831 | // Some operations are dedicated LLVM instructions, not available as intrinsics |
| ... | ... | @@ -8979,7 +8963,7 @@ pub const FuncGen = struct { |
| 8979 | 8963 | |
| 8980 | 8964 | fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 8981 | 8965 | const o = self.ng.object; |
| 8982 | | const pt = o.pt; |
| 8966 | const pt = self.ng.pt; |
| 8983 | 8967 | const zcu = pt.zcu; |
| 8984 | 8968 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 8985 | 8969 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | ... | @@ -8993,9 +8977,9 @@ pub const FuncGen = struct { |
| 8993 | 8977 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); |
| 8994 | 8978 | |
| 8995 | 8979 | const dest_ty = self.typeOfIndex(inst); |
| 8996 | | const llvm_dest_ty = try o.lowerType(dest_ty); |
| 8980 | const llvm_dest_ty = try o.lowerType(pt, dest_ty); |
| 8997 | 8981 | |
| 8998 | | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); |
| 8982 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), ""); |
| 8999 | 8983 | |
| 9000 | 8984 | const result = try self.wip.bin(.shl, lhs, casted_rhs, ""); |
| 9001 | 8985 | const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) |
| ... | ... | @@ -9052,7 +9036,8 @@ pub const FuncGen = struct { |
| 9052 | 9036 | |
| 9053 | 9037 | fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9054 | 9038 | const o = self.ng.object; |
| 9055 | | const zcu = o.pt.zcu; |
| 9039 | const pt = self.ng.pt; |
| 9040 | const zcu = pt.zcu; |
| 9056 | 9041 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9057 | 9042 | |
| 9058 | 9043 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -9063,7 +9048,7 @@ pub const FuncGen = struct { |
| 9063 | 9048 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9064 | 9049 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); |
| 9065 | 9050 | |
| 9066 | | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); |
| 9051 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), ""); |
| 9067 | 9052 | return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) |
| 9068 | 9053 | .@"shl nsw" |
| 9069 | 9054 | else |
| ... | ... | @@ -9072,7 +9057,8 @@ pub const FuncGen = struct { |
| 9072 | 9057 | |
| 9073 | 9058 | fn airShl(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9074 | 9059 | const o = self.ng.object; |
| 9075 | | const zcu = o.pt.zcu; |
| 9060 | const pt = self.ng.pt; |
| 9061 | const zcu = pt.zcu; |
| 9076 | 9062 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9077 | 9063 | |
| 9078 | 9064 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -9082,13 +9068,13 @@ pub const FuncGen = struct { |
| 9082 | 9068 | if (lhs_ty.isVector(zcu) and !self.typeOf(bin_op.rhs).isVector(zcu)) |
| 9083 | 9069 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9084 | 9070 | |
| 9085 | | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); |
| 9071 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), ""); |
| 9086 | 9072 | return self.wip.bin(.shl, lhs, casted_rhs, ""); |
| 9087 | 9073 | } |
| 9088 | 9074 | |
| 9089 | 9075 | fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9090 | 9076 | const o = self.ng.object; |
| 9091 | | const pt = o.pt; |
| 9077 | const pt = self.ng.pt; |
| 9092 | 9078 | const zcu = pt.zcu; |
| 9093 | 9079 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9094 | 9080 | |
| ... | ... | @@ -9097,7 +9083,7 @@ pub const FuncGen = struct { |
| 9097 | 9083 | |
| 9098 | 9084 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 9099 | 9085 | const lhs_info = lhs_ty.intInfo(zcu); |
| 9100 | | const llvm_lhs_ty = try o.lowerType(lhs_ty); |
| 9086 | const llvm_lhs_ty = try o.lowerType(pt, lhs_ty); |
| 9101 | 9087 | const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder); |
| 9102 | 9088 | |
| 9103 | 9089 | const rhs_ty = self.typeOf(bin_op.rhs); |
| ... | ... | @@ -9105,7 +9091,7 @@ pub const FuncGen = struct { |
| 9105 | 9091 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9106 | 9092 | const rhs_info = rhs_ty.intInfo(zcu); |
| 9107 | 9093 | assert(rhs_info.signedness == .unsigned); |
| 9108 | | const llvm_rhs_ty = try o.lowerType(rhs_ty); |
| 9094 | const llvm_rhs_ty = try o.lowerType(pt, rhs_ty); |
| 9109 | 9095 | const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder); |
| 9110 | 9096 | |
| 9111 | 9097 | const result = try self.wip.callIntrinsic( |
| ... | ... | @@ -9168,7 +9154,8 @@ pub const FuncGen = struct { |
| 9168 | 9154 | |
| 9169 | 9155 | fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value { |
| 9170 | 9156 | const o = self.ng.object; |
| 9171 | | const zcu = o.pt.zcu; |
| 9157 | const pt = self.ng.pt; |
| 9158 | const zcu = pt.zcu; |
| 9172 | 9159 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9173 | 9160 | |
| 9174 | 9161 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -9179,7 +9166,7 @@ pub const FuncGen = struct { |
| 9179 | 9166 | return self.ng.todo("implement vector shifts with scalar rhs", .{}); |
| 9180 | 9167 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); |
| 9181 | 9168 | |
| 9182 | | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); |
| 9169 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(pt, lhs_ty), ""); |
| 9183 | 9170 | const is_signed_int = lhs_scalar_ty.isSignedInt(zcu); |
| 9184 | 9171 | |
| 9185 | 9172 | return self.wip.bin(if (is_exact) |
| ... | ... | @@ -9189,7 +9176,8 @@ pub const FuncGen = struct { |
| 9189 | 9176 | |
| 9190 | 9177 | fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9191 | 9178 | const o = self.ng.object; |
| 9192 | | const zcu = o.pt.zcu; |
| 9179 | const pt = self.ng.pt; |
| 9180 | const zcu = pt.zcu; |
| 9193 | 9181 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9194 | 9182 | const operand = try self.resolveInst(ty_op.operand); |
| 9195 | 9183 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -9200,7 +9188,7 @@ pub const FuncGen = struct { |
| 9200 | 9188 | .normal, |
| 9201 | 9189 | .none, |
| 9202 | 9190 | .abs, |
| 9203 | | &.{try o.lowerType(operand_ty)}, |
| 9191 | &.{try o.lowerType(pt, operand_ty)}, |
| 9204 | 9192 | &.{ operand, try o.builder.intValue(.i1, 0) }, |
| 9205 | 9193 | "", |
| 9206 | 9194 | ), |
| ... | ... | @@ -9211,10 +9199,11 @@ pub const FuncGen = struct { |
| 9211 | 9199 | |
| 9212 | 9200 | fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9213 | 9201 | const o = fg.ng.object; |
| 9214 | | const zcu = o.pt.zcu; |
| 9202 | const pt = fg.ng.pt; |
| 9203 | const zcu = pt.zcu; |
| 9215 | 9204 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9216 | 9205 | const dest_ty = fg.typeOfIndex(inst); |
| 9217 | | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 9206 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 9218 | 9207 | const operand = try fg.resolveInst(ty_op.operand); |
| 9219 | 9208 | const operand_ty = fg.typeOf(ty_op.operand); |
| 9220 | 9209 | const operand_info = operand_ty.intInfo(zcu); |
| ... | ... | @@ -9243,8 +9232,8 @@ pub const FuncGen = struct { |
| 9243 | 9232 | |
| 9244 | 9233 | if (!have_min_check and !have_max_check) break :safety; |
| 9245 | 9234 | |
| 9246 | | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 9247 | | const operand_scalar_llvm_ty = try o.lowerType(operand_scalar); |
| 9235 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9236 | const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar); |
| 9248 | 9237 | |
| 9249 | 9238 | const is_vector = operand_ty.zigTypeTag(zcu) == .vector; |
| 9250 | 9239 | assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector)); |
| ... | ... | @@ -9313,15 +9302,17 @@ pub const FuncGen = struct { |
| 9313 | 9302 | |
| 9314 | 9303 | fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9315 | 9304 | const o = self.ng.object; |
| 9305 | const pt = self.ng.pt; |
| 9316 | 9306 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9317 | 9307 | const operand = try self.resolveInst(ty_op.operand); |
| 9318 | | const dest_llvm_ty = try o.lowerType(self.typeOfIndex(inst)); |
| 9308 | const dest_llvm_ty = try o.lowerType(pt, self.typeOfIndex(inst)); |
| 9319 | 9309 | return self.wip.cast(.trunc, operand, dest_llvm_ty, ""); |
| 9320 | 9310 | } |
| 9321 | 9311 | |
| 9322 | 9312 | fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9323 | 9313 | const o = self.ng.object; |
| 9324 | | const zcu = o.pt.zcu; |
| 9314 | const pt = self.ng.pt; |
| 9315 | const zcu = pt.zcu; |
| 9325 | 9316 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9326 | 9317 | const operand = try self.resolveInst(ty_op.operand); |
| 9327 | 9318 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -9329,10 +9320,10 @@ pub const FuncGen = struct { |
| 9329 | 9320 | const target = zcu.getTarget(); |
| 9330 | 9321 | |
| 9331 | 9322 | if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) { |
| 9332 | | return self.wip.cast(.fptrunc, operand, try o.lowerType(dest_ty), ""); |
| 9323 | return self.wip.cast(.fptrunc, operand, try o.lowerType(pt, dest_ty), ""); |
| 9333 | 9324 | } else { |
| 9334 | | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 9335 | | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 9325 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9326 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 9336 | 9327 | |
| 9337 | 9328 | const dest_bits = dest_ty.floatBits(target); |
| 9338 | 9329 | const src_bits = operand_ty.floatBits(target); |
| ... | ... | @@ -9355,7 +9346,8 @@ pub const FuncGen = struct { |
| 9355 | 9346 | |
| 9356 | 9347 | fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9357 | 9348 | const o = self.ng.object; |
| 9358 | | const zcu = o.pt.zcu; |
| 9349 | const pt = self.ng.pt; |
| 9350 | const zcu = pt.zcu; |
| 9359 | 9351 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9360 | 9352 | const operand = try self.resolveInst(ty_op.operand); |
| 9361 | 9353 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -9363,10 +9355,10 @@ pub const FuncGen = struct { |
| 9363 | 9355 | const target = zcu.getTarget(); |
| 9364 | 9356 | |
| 9365 | 9357 | if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) { |
| 9366 | | return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), ""); |
| 9358 | return self.wip.cast(.fpext, operand, try o.lowerType(pt, dest_ty), ""); |
| 9367 | 9359 | } else { |
| 9368 | | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 9369 | | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 9360 | const operand_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9361 | const dest_llvm_ty = try o.lowerType(pt, dest_ty); |
| 9370 | 9362 | |
| 9371 | 9363 | const dest_bits = dest_ty.scalarType(zcu).floatBits(target); |
| 9372 | 9364 | const src_bits = operand_ty.scalarType(zcu).floatBits(target); |
| ... | ... | @@ -9403,11 +9395,11 @@ pub const FuncGen = struct { |
| 9403 | 9395 | |
| 9404 | 9396 | fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value { |
| 9405 | 9397 | const o = self.ng.object; |
| 9406 | | const pt = o.pt; |
| 9398 | const pt = self.ng.pt; |
| 9407 | 9399 | const zcu = pt.zcu; |
| 9408 | 9400 | const operand_is_ref = isByRef(operand_ty, zcu); |
| 9409 | 9401 | const result_is_ref = isByRef(inst_ty, zcu); |
| 9410 | | const llvm_dest_ty = try o.lowerType(inst_ty); |
| 9402 | const llvm_dest_ty = try o.lowerType(pt, inst_ty); |
| 9411 | 9403 | |
| 9412 | 9404 | if (operand_is_ref and result_is_ref) { |
| 9413 | 9405 | // They are both pointers, so just return the same opaque pointer :) |
| ... | ... | @@ -9442,7 +9434,7 @@ pub const FuncGen = struct { |
| 9442 | 9434 | } else { |
| 9443 | 9435 | // If the ABI size of the element type is not evenly divisible by size in bits; |
| 9444 | 9436 | // a simple bitcast will not work, and we fall back to extractelement. |
| 9445 | | const llvm_usize = try o.lowerType(Type.usize); |
| 9437 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 9446 | 9438 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 9447 | 9439 | const vector_len = operand_ty.arrayLen(zcu); |
| 9448 | 9440 | var i: u64 = 0; |
| ... | ... | @@ -9458,7 +9450,7 @@ pub const FuncGen = struct { |
| 9458 | 9450 | return array_ptr; |
| 9459 | 9451 | } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) { |
| 9460 | 9452 | const elem_ty = operand_ty.childType(zcu); |
| 9461 | | const llvm_vector_ty = try o.lowerType(inst_ty); |
| 9453 | const llvm_vector_ty = try o.lowerType(pt, inst_ty); |
| 9462 | 9454 | if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{}); |
| 9463 | 9455 | |
| 9464 | 9456 | const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8; |
| ... | ... | @@ -9470,9 +9462,9 @@ pub const FuncGen = struct { |
| 9470 | 9462 | } else { |
| 9471 | 9463 | // If the ABI size of the element type is not evenly divisible by size in bits; |
| 9472 | 9464 | // a simple bitcast will not work, and we fall back to extractelement. |
| 9473 | | const array_llvm_ty = try o.lowerType(operand_ty); |
| 9474 | | const elem_llvm_ty = try o.lowerType(elem_ty); |
| 9475 | | const llvm_usize = try o.lowerType(Type.usize); |
| 9465 | const array_llvm_ty = try o.lowerType(pt, operand_ty); |
| 9466 | const elem_llvm_ty = try o.lowerType(pt, elem_ty); |
| 9467 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 9476 | 9468 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 9477 | 9469 | const vector_len = operand_ty.arrayLen(zcu); |
| 9478 | 9470 | var vector = try o.builder.poisonValue(llvm_vector_ty); |
| ... | ... | @@ -9519,7 +9511,7 @@ pub const FuncGen = struct { |
| 9519 | 9511 | |
| 9520 | 9512 | fn airArg(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9521 | 9513 | const o = self.ng.object; |
| 9522 | | const pt = o.pt; |
| 9514 | const pt = self.ng.pt; |
| 9523 | 9515 | const zcu = pt.zcu; |
| 9524 | 9516 | const arg_val = self.args[self.arg_index]; |
| 9525 | 9517 | self.arg_index += 1; |
| ... | ... | @@ -9547,7 +9539,7 @@ pub const FuncGen = struct { |
| 9547 | 9539 | self.file, |
| 9548 | 9540 | self.scope, |
| 9549 | 9541 | lbrace_line, |
| 9550 | | try o.lowerDebugType(inst_ty), |
| 9542 | try o.lowerDebugType(pt, inst_ty), |
| 9551 | 9543 | self.arg_index, |
| 9552 | 9544 | ); |
| 9553 | 9545 | |
| ... | ... | @@ -9611,28 +9603,28 @@ pub const FuncGen = struct { |
| 9611 | 9603 | |
| 9612 | 9604 | fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9613 | 9605 | const o = self.ng.object; |
| 9614 | | const pt = o.pt; |
| 9606 | const pt = self.ng.pt; |
| 9615 | 9607 | const zcu = pt.zcu; |
| 9616 | 9608 | const ptr_ty = self.typeOfIndex(inst); |
| 9617 | 9609 | const pointee_type = ptr_ty.childType(zcu); |
| 9618 | 9610 | if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) |
| 9619 | | return (try o.lowerPtrToVoid(ptr_ty)).toValue(); |
| 9611 | return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue(); |
| 9620 | 9612 | |
| 9621 | | const pointee_llvm_ty = try o.lowerType(pointee_type); |
| 9613 | const pointee_llvm_ty = try o.lowerType(pt, pointee_type); |
| 9622 | 9614 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 9623 | 9615 | return self.buildAlloca(pointee_llvm_ty, alignment); |
| 9624 | 9616 | } |
| 9625 | 9617 | |
| 9626 | 9618 | fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9627 | 9619 | const o = self.ng.object; |
| 9628 | | const pt = o.pt; |
| 9620 | const pt = self.ng.pt; |
| 9629 | 9621 | const zcu = pt.zcu; |
| 9630 | 9622 | const ptr_ty = self.typeOfIndex(inst); |
| 9631 | 9623 | const ret_ty = ptr_ty.childType(zcu); |
| 9632 | 9624 | if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) |
| 9633 | | return (try o.lowerPtrToVoid(ptr_ty)).toValue(); |
| 9625 | return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue(); |
| 9634 | 9626 | if (self.ret_ptr != .none) return self.ret_ptr; |
| 9635 | | const ret_llvm_ty = try o.lowerType(ret_ty); |
| 9627 | const ret_llvm_ty = try o.lowerType(pt, ret_ty); |
| 9636 | 9628 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 9637 | 9629 | return self.buildAlloca(ret_llvm_ty, alignment); |
| 9638 | 9630 | } |
| ... | ... | @@ -9644,13 +9636,13 @@ pub const FuncGen = struct { |
| 9644 | 9636 | llvm_ty: Builder.Type, |
| 9645 | 9637 | alignment: Builder.Alignment, |
| 9646 | 9638 | ) Allocator.Error!Builder.Value { |
| 9647 | | const target = self.ng.object.pt.zcu.getTarget(); |
| 9639 | const target = self.ng.pt.zcu.getTarget(); |
| 9648 | 9640 | return buildAllocaInner(&self.wip, llvm_ty, alignment, target); |
| 9649 | 9641 | } |
| 9650 | 9642 | |
| 9651 | 9643 | fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9652 | 9644 | const o = self.ng.object; |
| 9653 | | const pt = o.pt; |
| 9645 | const pt = self.ng.pt; |
| 9654 | 9646 | const zcu = pt.zcu; |
| 9655 | 9647 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9656 | 9648 | const dest_ptr = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -9685,7 +9677,7 @@ pub const FuncGen = struct { |
| 9685 | 9677 | |
| 9686 | 9678 | self.maybeMarkAllowZeroAccess(ptr_info); |
| 9687 | 9679 | |
| 9688 | | const len = try o.builder.intValue(try o.lowerType(Type.usize), operand_ty.abiSize(zcu)); |
| 9680 | const len = try o.builder.intValue(try o.lowerType(pt, Type.usize), operand_ty.abiSize(zcu)); |
| 9689 | 9681 | _ = try self.wip.callMemSet( |
| 9690 | 9682 | dest_ptr, |
| 9691 | 9683 | ptr_ty.ptrAlignment(zcu).toLlvm(), |
| ... | ... | @@ -9714,8 +9706,7 @@ pub const FuncGen = struct { |
| 9714 | 9706 | /// |
| 9715 | 9707 | /// The first instruction of `body_tail` is the one whose copy we want to elide. |
| 9716 | 9708 | fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool { |
| 9717 | | const o = fg.ng.object; |
| 9718 | | const zcu = o.pt.zcu; |
| 9709 | const zcu = fg.ng.pt.zcu; |
| 9719 | 9710 | const ip = &zcu.intern_pool; |
| 9720 | 9711 | for (body_tail[1..]) |body_inst| { |
| 9721 | 9712 | switch (fg.liveness.categorizeOperand(fg.air, zcu, body_inst, body_tail[0], ip)) { |
| ... | ... | @@ -9730,8 +9721,7 @@ pub const FuncGen = struct { |
| 9730 | 9721 | } |
| 9731 | 9722 | |
| 9732 | 9723 | fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value { |
| 9733 | | const o = fg.ng.object; |
| 9734 | | const pt = o.pt; |
| 9724 | const pt = fg.ng.pt; |
| 9735 | 9725 | const zcu = pt.zcu; |
| 9736 | 9726 | const inst = body_tail[0]; |
| 9737 | 9727 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| ... | ... | @@ -9765,8 +9755,9 @@ pub const FuncGen = struct { |
| 9765 | 9755 | fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9766 | 9756 | _ = inst; |
| 9767 | 9757 | const o = self.ng.object; |
| 9768 | | const llvm_usize = try o.lowerType(Type.usize); |
| 9769 | | if (!target_util.supportsReturnAddress(o.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) { |
| 9758 | const pt = self.ng.pt; |
| 9759 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 9760 | if (!target_util.supportsReturnAddress(self.ng.pt.zcu.getTarget(), self.ng.ownerModule().optimize_mode)) { |
| 9770 | 9761 | // https://github.com/ziglang/zig/issues/11946 |
| 9771 | 9762 | return o.builder.intValue(llvm_usize, 0); |
| 9772 | 9763 | } |
| ... | ... | @@ -9777,8 +9768,9 @@ pub const FuncGen = struct { |
| 9777 | 9768 | fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9778 | 9769 | _ = inst; |
| 9779 | 9770 | const o = self.ng.object; |
| 9771 | const pt = self.ng.pt; |
| 9780 | 9772 | const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, ""); |
| 9781 | | return self.wip.cast(.ptrtoint, result, try o.lowerType(Type.usize), ""); |
| 9773 | return self.wip.cast(.ptrtoint, result, try o.lowerType(pt, Type.usize), ""); |
| 9782 | 9774 | } |
| 9783 | 9775 | |
| 9784 | 9776 | fn airCmpxchg( |
| ... | ... | @@ -9787,7 +9779,7 @@ pub const FuncGen = struct { |
| 9787 | 9779 | kind: Builder.Function.Instruction.CmpXchg.Kind, |
| 9788 | 9780 | ) !Builder.Value { |
| 9789 | 9781 | const o = self.ng.object; |
| 9790 | | const pt = o.pt; |
| 9782 | const pt = self.ng.pt; |
| 9791 | 9783 | const zcu = pt.zcu; |
| 9792 | 9784 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 9793 | 9785 | const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| ... | ... | @@ -9796,8 +9788,8 @@ pub const FuncGen = struct { |
| 9796 | 9788 | var expected_value = try self.resolveInst(extra.expected_value); |
| 9797 | 9789 | var new_value = try self.resolveInst(extra.new_value); |
| 9798 | 9790 | const operand_ty = ptr_ty.childType(zcu); |
| 9799 | | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 9800 | | const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false); |
| 9791 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 9792 | const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false); |
| 9801 | 9793 | if (llvm_abi_ty != .none) { |
| 9802 | 9794 | // operand needs widening and truncating |
| 9803 | 9795 | const signedness: Builder.Function.Instruction.Cast.Signedness = |
| ... | ... | @@ -9840,7 +9832,7 @@ pub const FuncGen = struct { |
| 9840 | 9832 | |
| 9841 | 9833 | fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9842 | 9834 | const o = self.ng.object; |
| 9843 | | const pt = o.pt; |
| 9835 | const pt = self.ng.pt; |
| 9844 | 9836 | const zcu = pt.zcu; |
| 9845 | 9837 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 9846 | 9838 | const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| ... | ... | @@ -9852,8 +9844,8 @@ pub const FuncGen = struct { |
| 9852 | 9844 | const is_float = operand_ty.isRuntimeFloat(); |
| 9853 | 9845 | const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float); |
| 9854 | 9846 | const ordering = toLlvmAtomicOrdering(extra.ordering()); |
| 9855 | | const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, op == .xchg); |
| 9856 | | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 9847 | const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, op == .xchg); |
| 9848 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 9857 | 9849 | |
| 9858 | 9850 | const access_kind: Builder.MemoryAccessKind = |
| 9859 | 9851 | if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; |
| ... | ... | @@ -9896,7 +9888,7 @@ pub const FuncGen = struct { |
| 9896 | 9888 | access_kind, |
| 9897 | 9889 | op, |
| 9898 | 9890 | ptr, |
| 9899 | | try self.wip.cast(.ptrtoint, operand, try o.lowerType(Type.usize), ""), |
| 9891 | try self.wip.cast(.ptrtoint, operand, try o.lowerType(pt, Type.usize), ""), |
| 9900 | 9892 | self.sync_scope, |
| 9901 | 9893 | ordering, |
| 9902 | 9894 | ptr_alignment, |
| ... | ... | @@ -9906,7 +9898,7 @@ pub const FuncGen = struct { |
| 9906 | 9898 | |
| 9907 | 9899 | fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9908 | 9900 | const o = self.ng.object; |
| 9909 | | const pt = o.pt; |
| 9901 | const pt = self.ng.pt; |
| 9910 | 9902 | const zcu = pt.zcu; |
| 9911 | 9903 | const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; |
| 9912 | 9904 | const ptr = try self.resolveInst(atomic_load.ptr); |
| ... | ... | @@ -9915,14 +9907,14 @@ pub const FuncGen = struct { |
| 9915 | 9907 | const elem_ty = Type.fromInterned(info.child); |
| 9916 | 9908 | if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none; |
| 9917 | 9909 | const ordering = toLlvmAtomicOrdering(atomic_load.order); |
| 9918 | | const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false); |
| 9910 | const llvm_abi_ty = try o.getAtomicAbiType(pt, elem_ty, false); |
| 9919 | 9911 | const ptr_alignment = (if (info.flags.alignment != .none) |
| 9920 | 9912 | @as(InternPool.Alignment, info.flags.alignment) |
| 9921 | 9913 | else |
| 9922 | 9914 | Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm(); |
| 9923 | 9915 | const access_kind: Builder.MemoryAccessKind = |
| 9924 | 9916 | if (info.flags.is_volatile) .@"volatile" else .normal; |
| 9925 | | const elem_llvm_ty = try o.lowerType(elem_ty); |
| 9917 | const elem_llvm_ty = try o.lowerType(pt, elem_ty); |
| 9926 | 9918 | |
| 9927 | 9919 | self.maybeMarkAllowZeroAccess(info); |
| 9928 | 9920 | |
| ... | ... | @@ -9956,7 +9948,7 @@ pub const FuncGen = struct { |
| 9956 | 9948 | ordering: Builder.AtomicOrdering, |
| 9957 | 9949 | ) !Builder.Value { |
| 9958 | 9950 | const o = self.ng.object; |
| 9959 | | const pt = o.pt; |
| 9951 | const pt = self.ng.pt; |
| 9960 | 9952 | const zcu = pt.zcu; |
| 9961 | 9953 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9962 | 9954 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -9964,7 +9956,7 @@ pub const FuncGen = struct { |
| 9964 | 9956 | if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none; |
| 9965 | 9957 | const ptr = try self.resolveInst(bin_op.lhs); |
| 9966 | 9958 | var element = try self.resolveInst(bin_op.rhs); |
| 9967 | | const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false); |
| 9959 | const llvm_abi_ty = try o.getAtomicAbiType(pt, operand_ty, false); |
| 9968 | 9960 | |
| 9969 | 9961 | if (llvm_abi_ty != .none) { |
| 9970 | 9962 | // operand needs widening |
| ... | ... | @@ -9984,7 +9976,7 @@ pub const FuncGen = struct { |
| 9984 | 9976 | |
| 9985 | 9977 | fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value { |
| 9986 | 9978 | const o = self.ng.object; |
| 9987 | | const pt = o.pt; |
| 9979 | const pt = self.ng.pt; |
| 9988 | 9980 | const zcu = pt.zcu; |
| 9989 | 9981 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 9990 | 9982 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -10081,13 +10073,13 @@ pub const FuncGen = struct { |
| 10081 | 10073 | const body_block = try self.wip.block(1, "InlineMemsetBody"); |
| 10082 | 10074 | const end_block = try self.wip.block(1, "InlineMemsetEnd"); |
| 10083 | 10075 | |
| 10084 | | const llvm_usize_ty = try o.lowerType(Type.usize); |
| 10076 | const llvm_usize_ty = try o.lowerType(pt, Type.usize); |
| 10085 | 10077 | const len = switch (ptr_ty.ptrSize(zcu)) { |
| 10086 | 10078 | .slice => try self.wip.extractValue(dest_slice, &.{1}, ""), |
| 10087 | 10079 | .one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)), |
| 10088 | 10080 | .many, .c => unreachable, |
| 10089 | 10081 | }; |
| 10090 | | const elem_llvm_ty = try o.lowerType(elem_ty); |
| 10082 | const elem_llvm_ty = try o.lowerType(pt, elem_ty); |
| 10091 | 10083 | const end_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, dest_ptr, &.{len}, ""); |
| 10092 | 10084 | _ = try self.wip.br(loop_block); |
| 10093 | 10085 | |
| ... | ... | @@ -10121,8 +10113,7 @@ pub const FuncGen = struct { |
| 10121 | 10113 | } |
| 10122 | 10114 | |
| 10123 | 10115 | fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10124 | | const o = self.ng.object; |
| 10125 | | const pt = o.pt; |
| 10116 | const pt = self.ng.pt; |
| 10126 | 10117 | const zcu = pt.zcu; |
| 10127 | 10118 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 10128 | 10119 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -10151,8 +10142,7 @@ pub const FuncGen = struct { |
| 10151 | 10142 | } |
| 10152 | 10143 | |
| 10153 | 10144 | fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10154 | | const o = self.ng.object; |
| 10155 | | const pt = o.pt; |
| 10145 | const pt = self.ng.pt; |
| 10156 | 10146 | const zcu = pt.zcu; |
| 10157 | 10147 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 10158 | 10148 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -10178,7 +10168,7 @@ pub const FuncGen = struct { |
| 10178 | 10168 | |
| 10179 | 10169 | fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10180 | 10170 | const o = self.ng.object; |
| 10181 | | const pt = o.pt; |
| 10171 | const pt = self.ng.pt; |
| 10182 | 10172 | const zcu = pt.zcu; |
| 10183 | 10173 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 10184 | 10174 | const un_ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -10199,7 +10189,7 @@ pub const FuncGen = struct { |
| 10199 | 10189 | return .none; |
| 10200 | 10190 | } |
| 10201 | 10191 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| 10202 | | const tag_field_ptr = try self.wip.gepStruct(try o.lowerType(un_ty), union_ptr, tag_index, ""); |
| 10192 | const tag_field_ptr = try self.wip.gepStruct(try o.lowerType(pt, un_ty), union_ptr, tag_index, ""); |
| 10203 | 10193 | // TODO alignment on this store |
| 10204 | 10194 | _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, .default); |
| 10205 | 10195 | return .none; |
| ... | ... | @@ -10207,7 +10197,7 @@ pub const FuncGen = struct { |
| 10207 | 10197 | |
| 10208 | 10198 | fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10209 | 10199 | const o = self.ng.object; |
| 10210 | | const pt = o.pt; |
| 10200 | const pt = self.ng.pt; |
| 10211 | 10201 | const zcu = pt.zcu; |
| 10212 | 10202 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10213 | 10203 | const un_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -10215,7 +10205,7 @@ pub const FuncGen = struct { |
| 10215 | 10205 | if (layout.tag_size == 0) return .none; |
| 10216 | 10206 | const union_handle = try self.resolveInst(ty_op.operand); |
| 10217 | 10207 | if (isByRef(un_ty, zcu)) { |
| 10218 | | const llvm_un_ty = try o.lowerType(un_ty); |
| 10208 | const llvm_un_ty = try o.lowerType(pt, un_ty); |
| 10219 | 10209 | if (layout.payload_size == 0) |
| 10220 | 10210 | return self.wip.load(.normal, llvm_un_ty, union_handle, .default, ""); |
| 10221 | 10211 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| ... | ... | @@ -10247,6 +10237,7 @@ pub const FuncGen = struct { |
| 10247 | 10237 | |
| 10248 | 10238 | fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { |
| 10249 | 10239 | const o = self.ng.object; |
| 10240 | const pt = self.ng.pt; |
| 10250 | 10241 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10251 | 10242 | const inst_ty = self.typeOfIndex(inst); |
| 10252 | 10243 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -10256,15 +10247,16 @@ pub const FuncGen = struct { |
| 10256 | 10247 | .normal, |
| 10257 | 10248 | .none, |
| 10258 | 10249 | intrinsic, |
| 10259 | | &.{try o.lowerType(operand_ty)}, |
| 10250 | &.{try o.lowerType(pt, operand_ty)}, |
| 10260 | 10251 | &.{ operand, .false }, |
| 10261 | 10252 | "", |
| 10262 | 10253 | ); |
| 10263 | | return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), ""); |
| 10254 | return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), ""); |
| 10264 | 10255 | } |
| 10265 | 10256 | |
| 10266 | 10257 | fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) !Builder.Value { |
| 10267 | 10258 | const o = self.ng.object; |
| 10259 | const pt = self.ng.pt; |
| 10268 | 10260 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10269 | 10261 | const inst_ty = self.typeOfIndex(inst); |
| 10270 | 10262 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -10274,16 +10266,17 @@ pub const FuncGen = struct { |
| 10274 | 10266 | .normal, |
| 10275 | 10267 | .none, |
| 10276 | 10268 | intrinsic, |
| 10277 | | &.{try o.lowerType(operand_ty)}, |
| 10269 | &.{try o.lowerType(pt, operand_ty)}, |
| 10278 | 10270 | &.{operand}, |
| 10279 | 10271 | "", |
| 10280 | 10272 | ); |
| 10281 | | return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), ""); |
| 10273 | return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), ""); |
| 10282 | 10274 | } |
| 10283 | 10275 | |
| 10284 | 10276 | fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10285 | 10277 | const o = self.ng.object; |
| 10286 | | const zcu = o.pt.zcu; |
| 10278 | const pt = self.ng.pt; |
| 10279 | const zcu = pt.zcu; |
| 10287 | 10280 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10288 | 10281 | const operand_ty = self.typeOf(ty_op.operand); |
| 10289 | 10282 | var bits = operand_ty.intInfo(zcu).bits; |
| ... | ... | @@ -10291,7 +10284,7 @@ pub const FuncGen = struct { |
| 10291 | 10284 | |
| 10292 | 10285 | const inst_ty = self.typeOfIndex(inst); |
| 10293 | 10286 | var operand = try self.resolveInst(ty_op.operand); |
| 10294 | | var llvm_operand_ty = try o.lowerType(operand_ty); |
| 10287 | var llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 10295 | 10288 | |
| 10296 | 10289 | if (bits % 16 == 8) { |
| 10297 | 10290 | // If not an even byte-multiple, we need zero-extend + shift-left 1 byte |
| ... | ... | @@ -10312,12 +10305,13 @@ pub const FuncGen = struct { |
| 10312 | 10305 | |
| 10313 | 10306 | const result = |
| 10314 | 10307 | try self.wip.callIntrinsic(.normal, .none, .bswap, &.{llvm_operand_ty}, &.{operand}, ""); |
| 10315 | | return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), ""); |
| 10308 | return self.wip.conv(.unsigned, result, try o.lowerType(pt, inst_ty), ""); |
| 10316 | 10309 | } |
| 10317 | 10310 | |
| 10318 | 10311 | fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10319 | 10312 | const o = self.ng.object; |
| 10320 | | const zcu = o.pt.zcu; |
| 10313 | const pt = self.ng.pt; |
| 10314 | const zcu = pt.zcu; |
| 10321 | 10315 | const ip = &zcu.intern_pool; |
| 10322 | 10316 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10323 | 10317 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -10332,7 +10326,7 @@ pub const FuncGen = struct { |
| 10332 | 10326 | |
| 10333 | 10327 | for (0..names.len) |name_index| { |
| 10334 | 10328 | const err_int = ip.getErrorValueIfExists(names.get(ip)[name_index]).?; |
| 10335 | | const this_tag_int_value = try o.builder.intConst(try o.errorIntType(), err_int); |
| 10329 | const this_tag_int_value = try o.builder.intConst(try o.errorIntType(pt), err_int); |
| 10336 | 10330 | try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip); |
| 10337 | 10331 | } |
| 10338 | 10332 | self.wip.cursor = .{ .block = valid_block }; |
| ... | ... | @@ -10367,7 +10361,7 @@ pub const FuncGen = struct { |
| 10367 | 10361 | |
| 10368 | 10362 | fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !Builder.Function.Index { |
| 10369 | 10363 | const o = self.ng.object; |
| 10370 | | const pt = o.pt; |
| 10364 | const pt = self.ng.pt; |
| 10371 | 10365 | const zcu = pt.zcu; |
| 10372 | 10366 | const ip = &zcu.intern_pool; |
| 10373 | 10367 | const enum_type = ip.loadEnumType(enum_ty.toIntern()); |
| ... | ... | @@ -10379,7 +10373,7 @@ pub const FuncGen = struct { |
| 10379 | 10373 | |
| 10380 | 10374 | const target = &zcu.root_mod.resolved_target.result; |
| 10381 | 10375 | const function_index = try o.builder.addFunction( |
| 10382 | | try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal), |
| 10376 | try o.builder.fnType(.i1, &.{try o.lowerType(pt, Type.fromInterned(enum_type.tag_ty))}, .normal), |
| 10383 | 10377 | try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_type.name.fmt(ip)}), |
| 10384 | 10378 | toLlvmAddressSpace(.generic, target), |
| 10385 | 10379 | ); |
| ... | ... | @@ -10408,6 +10402,7 @@ pub const FuncGen = struct { |
| 10408 | 10402 | |
| 10409 | 10403 | for (0..enum_type.names.len) |field_index| { |
| 10410 | 10404 | const this_tag_int_value = try o.lowerValue( |
| 10405 | pt, |
| 10411 | 10406 | (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(), |
| 10412 | 10407 | ); |
| 10413 | 10408 | try wip_switch.addCase(this_tag_int_value, named_block, &wip); |
| ... | ... | @@ -10424,11 +10419,12 @@ pub const FuncGen = struct { |
| 10424 | 10419 | |
| 10425 | 10420 | fn airTagName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10426 | 10421 | const o = self.ng.object; |
| 10422 | const pt = self.ng.pt; |
| 10427 | 10423 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 10428 | 10424 | const operand = try self.resolveInst(un_op); |
| 10429 | 10425 | const enum_ty = self.typeOf(un_op); |
| 10430 | 10426 | |
| 10431 | | const llvm_fn = try o.getEnumTagNameFunction(enum_ty); |
| 10427 | const llvm_fn = try o.getEnumTagNameFunction(pt, enum_ty); |
| 10432 | 10428 | return self.wip.call( |
| 10433 | 10429 | .normal, |
| 10434 | 10430 | .fastcc, |
| ... | ... | @@ -10442,10 +10438,11 @@ pub const FuncGen = struct { |
| 10442 | 10438 | |
| 10443 | 10439 | fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10444 | 10440 | const o = self.ng.object; |
| 10441 | const pt = self.ng.pt; |
| 10445 | 10442 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 10446 | 10443 | const operand = try self.resolveInst(un_op); |
| 10447 | 10444 | const slice_ty = self.typeOfIndex(inst); |
| 10448 | | const slice_llvm_ty = try o.lowerType(slice_ty); |
| 10445 | const slice_llvm_ty = try o.lowerType(pt, slice_ty); |
| 10449 | 10446 | |
| 10450 | 10447 | const error_name_table_ptr = try self.getErrorNameTable(); |
| 10451 | 10448 | const error_name_table = |
| ... | ... | @@ -10457,10 +10454,11 @@ pub const FuncGen = struct { |
| 10457 | 10454 | |
| 10458 | 10455 | fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10459 | 10456 | const o = self.ng.object; |
| 10457 | const pt = self.ng.pt; |
| 10460 | 10458 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 10461 | 10459 | const scalar = try self.resolveInst(ty_op.operand); |
| 10462 | 10460 | const vector_ty = self.typeOfIndex(inst); |
| 10463 | | return self.wip.splatVector(try o.lowerType(vector_ty), scalar, ""); |
| 10461 | return self.wip.splatVector(try o.lowerType(pt, vector_ty), scalar, ""); |
| 10464 | 10462 | } |
| 10465 | 10463 | |
| 10466 | 10464 | fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| ... | ... | @@ -10475,7 +10473,7 @@ pub const FuncGen = struct { |
| 10475 | 10473 | |
| 10476 | 10474 | fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10477 | 10475 | const o = fg.ng.object; |
| 10478 | | const pt = o.pt; |
| 10476 | const pt = fg.ng.pt; |
| 10479 | 10477 | const zcu = pt.zcu; |
| 10480 | 10478 | const gpa = zcu.gpa; |
| 10481 | 10479 | |
| ... | ... | @@ -10484,9 +10482,9 @@ pub const FuncGen = struct { |
| 10484 | 10482 | const operand = try fg.resolveInst(unwrapped.operand); |
| 10485 | 10483 | const mask = unwrapped.mask; |
| 10486 | 10484 | const operand_ty = fg.typeOf(unwrapped.operand); |
| 10487 | | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 10488 | | const llvm_result_ty = try o.lowerType(unwrapped.result_ty); |
| 10489 | | const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu)); |
| 10485 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 10486 | const llvm_result_ty = try o.lowerType(pt, unwrapped.result_ty); |
| 10487 | const llvm_elem_ty = try o.lowerType(pt, unwrapped.result_ty.childType(zcu)); |
| 10490 | 10488 | const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty); |
| 10491 | 10489 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); |
| 10492 | 10490 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); |
| ... | ... | @@ -10516,7 +10514,7 @@ pub const FuncGen = struct { |
| 10516 | 10514 | .elem => llvm_poison_elem, |
| 10517 | 10515 | .value => |val| if (!Value.fromInterned(val).isUndef(zcu)) elem: { |
| 10518 | 10516 | any_defined_comptime_value = true; |
| 10519 | | break :elem try o.lowerValue(val); |
| 10517 | break :elem try o.lowerValue(pt, val); |
| 10520 | 10518 | } else llvm_poison_elem, |
| 10521 | 10519 | }; |
| 10522 | 10520 | } |
| ... | ... | @@ -10582,14 +10580,14 @@ pub const FuncGen = struct { |
| 10582 | 10580 | |
| 10583 | 10581 | fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10584 | 10582 | const o = fg.ng.object; |
| 10585 | | const pt = o.pt; |
| 10583 | const pt = fg.ng.pt; |
| 10586 | 10584 | const zcu = pt.zcu; |
| 10587 | 10585 | const gpa = zcu.gpa; |
| 10588 | 10586 | |
| 10589 | 10587 | const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst); |
| 10590 | 10588 | |
| 10591 | 10589 | const mask = unwrapped.mask; |
| 10592 | | const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu)); |
| 10590 | const llvm_elem_ty = try o.lowerType(pt, unwrapped.result_ty.childType(zcu)); |
| 10593 | 10591 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); |
| 10594 | 10592 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); |
| 10595 | 10593 | |
| ... | ... | @@ -10681,7 +10679,8 @@ pub const FuncGen = struct { |
| 10681 | 10679 | accum_init: Builder.Value, |
| 10682 | 10680 | ) !Builder.Value { |
| 10683 | 10681 | const o = self.ng.object; |
| 10684 | | const usize_ty = try o.lowerType(Type.usize); |
| 10682 | const pt = self.ng.pt; |
| 10683 | const usize_ty = try o.lowerType(pt, Type.usize); |
| 10685 | 10684 | const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len); |
| 10686 | 10685 | const llvm_result_ty = accum_init.typeOfWip(&self.wip); |
| 10687 | 10686 | |
| ... | ... | @@ -10735,15 +10734,16 @@ pub const FuncGen = struct { |
| 10735 | 10734 | |
| 10736 | 10735 | fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value { |
| 10737 | 10736 | const o = self.ng.object; |
| 10738 | | const zcu = o.pt.zcu; |
| 10737 | const pt = self.ng.pt; |
| 10738 | const zcu = pt.zcu; |
| 10739 | 10739 | const target = zcu.getTarget(); |
| 10740 | 10740 | |
| 10741 | 10741 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; |
| 10742 | 10742 | const operand = try self.resolveInst(reduce.operand); |
| 10743 | 10743 | const operand_ty = self.typeOf(reduce.operand); |
| 10744 | | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 10744 | const llvm_operand_ty = try o.lowerType(pt, operand_ty); |
| 10745 | 10745 | const scalar_ty = self.typeOfIndex(inst); |
| 10746 | | const llvm_scalar_ty = try o.lowerType(scalar_ty); |
| 10746 | const llvm_scalar_ty = try o.lowerType(pt, scalar_ty); |
| 10747 | 10747 | |
| 10748 | 10748 | switch (reduce.operation) { |
| 10749 | 10749 | .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) { |
| ... | ... | @@ -10845,14 +10845,14 @@ pub const FuncGen = struct { |
| 10845 | 10845 | |
| 10846 | 10846 | fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10847 | 10847 | const o = self.ng.object; |
| 10848 | | const pt = o.pt; |
| 10848 | const pt = self.ng.pt; |
| 10849 | 10849 | const zcu = pt.zcu; |
| 10850 | 10850 | const ip = &zcu.intern_pool; |
| 10851 | 10851 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 10852 | 10852 | const result_ty = self.typeOfIndex(inst); |
| 10853 | 10853 | const len: usize = @intCast(result_ty.arrayLen(zcu)); |
| 10854 | 10854 | const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[ty_pl.payload..][0..len]); |
| 10855 | | const llvm_result_ty = try o.lowerType(result_ty); |
| 10855 | const llvm_result_ty = try o.lowerType(pt, result_ty); |
| 10856 | 10856 | |
| 10857 | 10857 | switch (result_ty.zigTypeTag(zcu)) { |
| 10858 | 10858 | .vector => { |
| ... | ... | @@ -10933,7 +10933,7 @@ pub const FuncGen = struct { |
| 10933 | 10933 | .array => { |
| 10934 | 10934 | assert(isByRef(result_ty, zcu)); |
| 10935 | 10935 | |
| 10936 | | const llvm_usize = try o.lowerType(Type.usize); |
| 10936 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 10937 | 10937 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 10938 | 10938 | const alignment = result_ty.abiAlignment(zcu).toLlvm(); |
| 10939 | 10939 | const alloca_inst = try self.buildAlloca(llvm_result_ty, alignment); |
| ... | ... | @@ -10966,13 +10966,13 @@ pub const FuncGen = struct { |
| 10966 | 10966 | |
| 10967 | 10967 | fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 10968 | 10968 | const o = self.ng.object; |
| 10969 | | const pt = o.pt; |
| 10969 | const pt = self.ng.pt; |
| 10970 | 10970 | const zcu = pt.zcu; |
| 10971 | 10971 | const ip = &zcu.intern_pool; |
| 10972 | 10972 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 10973 | 10973 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 10974 | 10974 | const union_ty = self.typeOfIndex(inst); |
| 10975 | | const union_llvm_ty = try o.lowerType(union_ty); |
| 10975 | const union_llvm_ty = try o.lowerType(pt, union_ty); |
| 10976 | 10976 | const layout = union_ty.unionGetLayout(zcu); |
| 10977 | 10977 | const union_obj = zcu.typeToUnion(union_ty).?; |
| 10978 | 10978 | |
| ... | ... | @@ -11014,10 +11014,10 @@ pub const FuncGen = struct { |
| 11014 | 11014 | const result_ptr = try self.buildAlloca(union_llvm_ty, alignment); |
| 11015 | 11015 | const llvm_payload = try self.resolveInst(extra.init); |
| 11016 | 11016 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]); |
| 11017 | | const field_llvm_ty = try o.lowerType(field_ty); |
| 11017 | const field_llvm_ty = try o.lowerType(pt, field_ty); |
| 11018 | 11018 | const field_size = field_ty.abiSize(zcu); |
| 11019 | 11019 | const field_align = union_ty.fieldAlignment(extra.field_index, zcu); |
| 11020 | | const llvm_usize = try o.lowerType(Type.usize); |
| 11020 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 11021 | 11021 | const usize_zero = try o.builder.intValue(llvm_usize, 0); |
| 11022 | 11022 | |
| 11023 | 11023 | const llvm_union_ty = t: { |
| ... | ... | @@ -11035,7 +11035,7 @@ pub const FuncGen = struct { |
| 11035 | 11035 | }); |
| 11036 | 11036 | }; |
| 11037 | 11037 | if (layout.tag_size == 0) break :t try o.builder.structType(.normal, &.{payload_ty}); |
| 11038 | | const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty)); |
| 11038 | const tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty)); |
| 11039 | 11039 | var fields: [3]Builder.Type = undefined; |
| 11040 | 11040 | var fields_len: usize = 2; |
| 11041 | 11041 | if (layout.tag_align.compare(.gte, layout.payload_align)) { |
| ... | ... | @@ -11076,7 +11076,7 @@ pub const FuncGen = struct { |
| 11076 | 11076 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| 11077 | 11077 | const indices: [2]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, tag_index) }; |
| 11078 | 11078 | const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, ""); |
| 11079 | | const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty)); |
| 11079 | const tag_ty = try o.lowerType(pt, Type.fromInterned(union_obj.enum_tag_ty)); |
| 11080 | 11080 | var big_int_space: Value.BigIntSpace = undefined; |
| 11081 | 11081 | const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu); |
| 11082 | 11082 | const llvm_tag = try o.builder.bigIntValue(tag_ty, tag_big_int); |
| ... | ... | @@ -11106,7 +11106,7 @@ pub const FuncGen = struct { |
| 11106 | 11106 | // by the target. |
| 11107 | 11107 | // To work around this, don't emit llvm.prefetch in this case. |
| 11108 | 11108 | // See https://bugs.llvm.org/show_bug.cgi?id=21037 |
| 11109 | | const zcu = o.pt.zcu; |
| 11109 | const zcu = self.ng.pt.zcu; |
| 11110 | 11110 | const target = zcu.getTarget(); |
| 11111 | 11111 | switch (prefetch.cache) { |
| 11112 | 11112 | .instruction => switch (target.cpu.arch) { |
| ... | ... | @@ -11139,11 +11139,12 @@ pub const FuncGen = struct { |
| 11139 | 11139 | |
| 11140 | 11140 | fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11141 | 11141 | const o = self.ng.object; |
| 11142 | const pt = self.ng.pt; |
| 11142 | 11143 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 11143 | 11144 | const inst_ty = self.typeOfIndex(inst); |
| 11144 | 11145 | const operand = try self.resolveInst(ty_op.operand); |
| 11145 | 11146 | |
| 11146 | | return self.wip.cast(.addrspacecast, operand, try o.lowerType(inst_ty), ""); |
| 11147 | return self.wip.cast(.addrspacecast, operand, try o.lowerType(pt, inst_ty), ""); |
| 11147 | 11148 | } |
| 11148 | 11149 | |
| 11149 | 11150 | fn workIntrinsic( |
| ... | ... | @@ -11161,8 +11162,7 @@ pub const FuncGen = struct { |
| 11161 | 11162 | } |
| 11162 | 11163 | |
| 11163 | 11164 | fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11164 | | const o = self.ng.object; |
| 11165 | | const target = o.pt.zcu.getTarget(); |
| 11165 | const target = self.ng.pt.zcu.getTarget(); |
| 11166 | 11166 | |
| 11167 | 11167 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 11168 | 11168 | const dimension = pl_op.payload; |
| ... | ... | @@ -11176,7 +11176,8 @@ pub const FuncGen = struct { |
| 11176 | 11176 | |
| 11177 | 11177 | fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11178 | 11178 | const o = self.ng.object; |
| 11179 | | const target = o.pt.zcu.getTarget(); |
| 11179 | const pt = self.ng.pt; |
| 11180 | const target = pt.zcu.getTarget(); |
| 11180 | 11181 | |
| 11181 | 11182 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 11182 | 11183 | const dimension = pl_op.payload; |
| ... | ... | @@ -11193,7 +11194,7 @@ pub const FuncGen = struct { |
| 11193 | 11194 | // Load the work_group_* member from the struct as u16. |
| 11194 | 11195 | // Just treat the dispatch pointer as an array of u16 to keep things simple. |
| 11195 | 11196 | const workgroup_size_ptr = try self.wip.gep(.inbounds, .i16, dispatch_ptr, &.{ |
| 11196 | | try o.builder.intValue(try o.lowerType(Type.usize), 2 + dimension), |
| 11197 | try o.builder.intValue(try o.lowerType(pt, Type.usize), 2 + dimension), |
| 11197 | 11198 | }, ""); |
| 11198 | 11199 | const workgroup_size_alignment = comptime Builder.Alignment.fromByteUnits(2); |
| 11199 | 11200 | return self.wip.load(.normal, .i16, workgroup_size_ptr, workgroup_size_alignment, ""); |
| ... | ... | @@ -11206,8 +11207,7 @@ pub const FuncGen = struct { |
| 11206 | 11207 | } |
| 11207 | 11208 | |
| 11208 | 11209 | fn airWorkGroupId(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 11209 | | const o = self.ng.object; |
| 11210 | | const target = o.pt.zcu.getTarget(); |
| 11210 | const target = self.ng.pt.zcu.getTarget(); |
| 11211 | 11211 | |
| 11212 | 11212 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 11213 | 11213 | const dimension = pl_op.payload; |
| ... | ... | @@ -11221,7 +11221,7 @@ pub const FuncGen = struct { |
| 11221 | 11221 | |
| 11222 | 11222 | fn getErrorNameTable(self: *FuncGen) Allocator.Error!Builder.Variable.Index { |
| 11223 | 11223 | const o = self.ng.object; |
| 11224 | | const pt = o.pt; |
| 11224 | const pt = self.ng.pt; |
| 11225 | 11225 | |
| 11226 | 11226 | const table = o.error_name_table; |
| 11227 | 11227 | if (table != .none) return table; |
| ... | ... | @@ -11271,8 +11271,7 @@ pub const FuncGen = struct { |
| 11271 | 11271 | opt_ty: Type, |
| 11272 | 11272 | can_elide_load: bool, |
| 11273 | 11273 | ) !Builder.Value { |
| 11274 | | const o = fg.ng.object; |
| 11275 | | const pt = o.pt; |
| 11274 | const pt = fg.ng.pt; |
| 11276 | 11275 | const zcu = pt.zcu; |
| 11277 | 11276 | const payload_ty = opt_ty.optionalChild(zcu); |
| 11278 | 11277 | |
| ... | ... | @@ -11301,9 +11300,9 @@ pub const FuncGen = struct { |
| 11301 | 11300 | non_null_bit: Builder.Value, |
| 11302 | 11301 | ) !Builder.Value { |
| 11303 | 11302 | const o = self.ng.object; |
| 11304 | | const pt = o.pt; |
| 11303 | const pt = self.ng.pt; |
| 11305 | 11304 | const zcu = pt.zcu; |
| 11306 | | const optional_llvm_ty = try o.lowerType(optional_ty); |
| 11305 | const optional_llvm_ty = try o.lowerType(pt, optional_ty); |
| 11307 | 11306 | const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, ""); |
| 11308 | 11307 | |
| 11309 | 11308 | if (isByRef(optional_ty, zcu)) { |
| ... | ... | @@ -11334,7 +11333,7 @@ pub const FuncGen = struct { |
| 11334 | 11333 | field_index: u32, |
| 11335 | 11334 | ) !Builder.Value { |
| 11336 | 11335 | const o = self.ng.object; |
| 11337 | | const pt = o.pt; |
| 11336 | const pt = self.ng.pt; |
| 11338 | 11337 | const zcu = pt.zcu; |
| 11339 | 11338 | const struct_ty = struct_ptr_ty.childType(zcu); |
| 11340 | 11339 | switch (struct_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -11357,12 +11356,12 @@ pub const FuncGen = struct { |
| 11357 | 11356 | // Offset our operand pointer by the correct number of bytes. |
| 11358 | 11357 | const byte_offset = @divExact(pt.structPackedFieldBitOffset(struct_type, field_index) + struct_ptr_ty_info.packed_offset.bit_offset, 8); |
| 11359 | 11358 | if (byte_offset == 0) return struct_ptr; |
| 11360 | | const usize_ty = try o.lowerType(Type.usize); |
| 11359 | const usize_ty = try o.lowerType(pt, Type.usize); |
| 11361 | 11360 | const llvm_index = try o.builder.intValue(usize_ty, byte_offset); |
| 11362 | 11361 | return self.wip.gep(.inbounds, .i8, struct_ptr, &.{llvm_index}, ""); |
| 11363 | 11362 | }, |
| 11364 | 11363 | else => { |
| 11365 | | const struct_llvm_ty = try o.lowerPtrElemTy(struct_ty); |
| 11364 | const struct_llvm_ty = try o.lowerPtrElemTy(pt, struct_ty); |
| 11366 | 11365 | |
| 11367 | 11366 | if (o.llvmFieldIndex(struct_ty, field_index)) |llvm_field_index| { |
| 11368 | 11367 | return self.wip.gepStruct(struct_llvm_ty, struct_ptr, llvm_field_index, ""); |
| ... | ... | @@ -11372,7 +11371,7 @@ pub const FuncGen = struct { |
| 11372 | 11371 | // the index to the element at index `1` to get a pointer to the end of |
| 11373 | 11372 | // the struct. |
| 11374 | 11373 | const llvm_index = try o.builder.intValue( |
| 11375 | | try o.lowerType(Type.usize), |
| 11374 | try o.lowerType(pt, Type.usize), |
| 11376 | 11375 | @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)), |
| 11377 | 11376 | ); |
| 11378 | 11377 | return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, ""); |
| ... | ... | @@ -11383,7 +11382,7 @@ pub const FuncGen = struct { |
| 11383 | 11382 | const layout = struct_ty.unionGetLayout(zcu); |
| 11384 | 11383 | if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr; |
| 11385 | 11384 | const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align)); |
| 11386 | | const union_llvm_ty = try o.lowerType(struct_ty); |
| 11385 | const union_llvm_ty = try o.lowerType(pt, struct_ty); |
| 11387 | 11386 | return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, ""); |
| 11388 | 11387 | }, |
| 11389 | 11388 | else => unreachable, |
| ... | ... | @@ -11403,9 +11402,9 @@ pub const FuncGen = struct { |
| 11403 | 11402 | // => so load the byte aligned value and trunc the unwanted bits. |
| 11404 | 11403 | |
| 11405 | 11404 | const o = fg.ng.object; |
| 11406 | | const pt = o.pt; |
| 11405 | const pt = fg.ng.pt; |
| 11407 | 11406 | const zcu = pt.zcu; |
| 11408 | | const payload_llvm_ty = try o.lowerType(payload_ty); |
| 11407 | const payload_llvm_ty = try o.lowerType(pt, payload_ty); |
| 11409 | 11408 | const abi_size = payload_ty.abiSize(zcu); |
| 11410 | 11409 | |
| 11411 | 11410 | // llvm bug workarounds: |
| ... | ... | @@ -11450,8 +11449,8 @@ pub const FuncGen = struct { |
| 11450 | 11449 | access_kind: Builder.MemoryAccessKind, |
| 11451 | 11450 | ) !Builder.Value { |
| 11452 | 11451 | const o = fg.ng.object; |
| 11453 | | const pt = o.pt; |
| 11454 | | const pointee_llvm_ty = try o.lowerType(pointee_type); |
| 11452 | const pt = fg.ng.pt; |
| 11453 | const pointee_llvm_ty = try o.lowerType(pt, pointee_type); |
| 11455 | 11454 | const result_align = InternPool.Alignment.fromLlvm(ptr_alignment) |
| 11456 | 11455 | .max(pointee_type.abiAlignment(pt.zcu)).toLlvm(); |
| 11457 | 11456 | const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align); |
| ... | ... | @@ -11461,7 +11460,7 @@ pub const FuncGen = struct { |
| 11461 | 11460 | result_align, |
| 11462 | 11461 | ptr, |
| 11463 | 11462 | ptr_alignment, |
| 11464 | | try o.builder.intValue(try o.lowerType(Type.usize), size_bytes), |
| 11463 | try o.builder.intValue(try o.lowerType(pt, Type.usize), size_bytes), |
| 11465 | 11464 | access_kind, |
| 11466 | 11465 | fg.disable_intrinsics, |
| 11467 | 11466 | ); |
| ... | ... | @@ -11473,7 +11472,7 @@ pub const FuncGen = struct { |
| 11473 | 11472 | /// For isByRef=false types, it creates a load instruction and returns it. |
| 11474 | 11473 | fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value { |
| 11475 | 11474 | const o = self.ng.object; |
| 11476 | | const pt = o.pt; |
| 11475 | const pt = self.ng.pt; |
| 11477 | 11476 | const zcu = pt.zcu; |
| 11478 | 11477 | const info = ptr_ty.ptrInfo(zcu); |
| 11479 | 11478 | const elem_ty = Type.fromInterned(info.child); |
| ... | ... | @@ -11490,7 +11489,7 @@ pub const FuncGen = struct { |
| 11490 | 11489 | assert(info.flags.vector_index != .runtime); |
| 11491 | 11490 | if (info.flags.vector_index != .none) { |
| 11492 | 11491 | const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index); |
| 11493 | | const vec_elem_ty = try o.lowerType(elem_ty); |
| 11492 | const vec_elem_ty = try o.lowerType(pt, elem_ty); |
| 11494 | 11493 | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); |
| 11495 | 11494 | |
| 11496 | 11495 | const loaded_vector = try self.wip.load(access_kind, vec_ty, ptr, ptr_alignment, ""); |
| ... | ... | @@ -11511,7 +11510,7 @@ pub const FuncGen = struct { |
| 11511 | 11510 | const elem_bits = ptr_ty.childType(zcu).bitSize(zcu); |
| 11512 | 11511 | const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset); |
| 11513 | 11512 | const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, ""); |
| 11514 | | const elem_llvm_ty = try o.lowerType(elem_ty); |
| 11513 | const elem_llvm_ty = try o.lowerType(pt, elem_ty); |
| 11515 | 11514 | |
| 11516 | 11515 | if (isByRef(elem_ty, zcu)) { |
| 11517 | 11516 | const result_align = elem_ty.abiAlignment(zcu).toLlvm(); |
| ... | ... | @@ -11546,7 +11545,7 @@ pub const FuncGen = struct { |
| 11546 | 11545 | ordering: Builder.AtomicOrdering, |
| 11547 | 11546 | ) !void { |
| 11548 | 11547 | const o = self.ng.object; |
| 11549 | | const pt = o.pt; |
| 11548 | const pt = self.ng.pt; |
| 11550 | 11549 | const zcu = pt.zcu; |
| 11551 | 11550 | const info = ptr_ty.ptrInfo(zcu); |
| 11552 | 11551 | const elem_ty = Type.fromInterned(info.child); |
| ... | ... | @@ -11560,7 +11559,7 @@ pub const FuncGen = struct { |
| 11560 | 11559 | assert(info.flags.vector_index != .runtime); |
| 11561 | 11560 | if (info.flags.vector_index != .none) { |
| 11562 | 11561 | const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index); |
| 11563 | | const vec_elem_ty = try o.lowerType(elem_ty); |
| 11562 | const vec_elem_ty = try o.lowerType(pt, elem_ty); |
| 11564 | 11563 | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); |
| 11565 | 11564 | |
| 11566 | 11565 | const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, ""); |
| ... | ... | @@ -11629,7 +11628,7 @@ pub const FuncGen = struct { |
| 11629 | 11628 | ptr_alignment, |
| 11630 | 11629 | elem, |
| 11631 | 11630 | elem_ty.abiAlignment(zcu).toLlvm(), |
| 11632 | | try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(zcu)), |
| 11631 | try o.builder.intValue(try o.lowerType(pt, Type.usize), elem_ty.abiSize(zcu)), |
| 11633 | 11632 | access_kind, |
| 11634 | 11633 | self.disable_intrinsics, |
| 11635 | 11634 | ); |
| ... | ... | @@ -11638,7 +11637,8 @@ pub const FuncGen = struct { |
| 11638 | 11637 | fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void { |
| 11639 | 11638 | const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545; |
| 11640 | 11639 | const o = fg.ng.object; |
| 11641 | | const usize_ty = try o.lowerType(Type.usize); |
| 11640 | const pt = fg.ng.pt; |
| 11641 | const usize_ty = try o.lowerType(pt, Type.usize); |
| 11642 | 11642 | const zero = try o.builder.intValue(usize_ty, 0); |
| 11643 | 11643 | const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED); |
| 11644 | 11644 | const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, ""); |
| ... | ... | @@ -11656,12 +11656,12 @@ pub const FuncGen = struct { |
| 11656 | 11656 | a5: Builder.Value, |
| 11657 | 11657 | ) Allocator.Error!Builder.Value { |
| 11658 | 11658 | const o = fg.ng.object; |
| 11659 | | const pt = o.pt; |
| 11659 | const pt = fg.ng.pt; |
| 11660 | 11660 | const zcu = pt.zcu; |
| 11661 | 11661 | const target = zcu.getTarget(); |
| 11662 | 11662 | if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value; |
| 11663 | 11663 | |
| 11664 | | const llvm_usize = try o.lowerType(Type.usize); |
| 11664 | const llvm_usize = try o.lowerType(pt, Type.usize); |
| 11665 | 11665 | const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm(); |
| 11666 | 11666 | |
| 11667 | 11667 | const array_llvm_ty = try o.builder.arrayType(6, llvm_usize); |
| ... | ... | @@ -11787,14 +11787,12 @@ pub const FuncGen = struct { |
| 11787 | 11787 | } |
| 11788 | 11788 | |
| 11789 | 11789 | fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type { |
| 11790 | | const o = fg.ng.object; |
| 11791 | | const zcu = o.pt.zcu; |
| 11790 | const zcu = fg.ng.pt.zcu; |
| 11792 | 11791 | return fg.air.typeOf(inst, &zcu.intern_pool); |
| 11793 | 11792 | } |
| 11794 | 11793 | |
| 11795 | 11794 | fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type { |
| 11796 | | const o = fg.ng.object; |
| 11797 | | const zcu = o.pt.zcu; |
| 11795 | const zcu = fg.ng.pt.zcu; |
| 11798 | 11796 | return fg.air.typeOfIndex(inst, &zcu.intern_pool); |
| 11799 | 11797 | } |
| 11800 | 11798 | }; |
| ... | ... | @@ -12152,40 +12150,39 @@ fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: *const std.Target) bool { |
| 12152 | 12150 | /// In order to support the C calling convention, some return types need to be lowered |
| 12153 | 12151 | /// completely differently in the function prototype to honor the C ABI, and then |
| 12154 | 12152 | /// 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; |
| 12153 | fn lowerFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12157 | 12154 | const zcu = pt.zcu; |
| 12158 | 12155 | const return_type = Type.fromInterned(fn_info.return_type); |
| 12159 | 12156 | if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 12160 | 12157 | // If the return type is an error set or an error union, then we make this |
| 12161 | 12158 | // anyerror return type instead, so that it can be coerced into a function |
| 12162 | 12159 | // pointer type which has anyerror as the return type. |
| 12163 | | return if (return_type.isError(zcu)) try o.errorIntType() else .void; |
| 12160 | return if (return_type.isError(zcu)) try o.errorIntType(pt) else .void; |
| 12164 | 12161 | } |
| 12165 | 12162 | const target = zcu.getTarget(); |
| 12166 | 12163 | switch (fn_info.cc) { |
| 12167 | 12164 | .@"inline" => unreachable, |
| 12168 | | .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(return_type), |
| 12165 | .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(pt, return_type), |
| 12169 | 12166 | |
| 12170 | | .x86_64_sysv => return lowerSystemVFnRetTy(o, fn_info), |
| 12171 | | .x86_64_win => return lowerWin64FnRetTy(o, fn_info), |
| 12172 | | .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(return_type) else .void, |
| 12173 | | .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(return_type), |
| 12167 | .x86_64_sysv => return lowerSystemVFnRetTy(o, pt, fn_info), |
| 12168 | .x86_64_win => return lowerWin64FnRetTy(o, pt, fn_info), |
| 12169 | .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(pt, return_type) else .void, |
| 12170 | .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(pt, return_type), |
| 12174 | 12171 | .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win => switch (aarch64_c_abi.classifyType(return_type, zcu)) { |
| 12175 | 12172 | .memory => return .void, |
| 12176 | | .float_array => return o.lowerType(return_type), |
| 12177 | | .byval => return o.lowerType(return_type), |
| 12173 | .float_array => return o.lowerType(pt, return_type), |
| 12174 | .byval => return o.lowerType(pt, return_type), |
| 12178 | 12175 | .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))), |
| 12179 | 12176 | .double_integer => return o.builder.arrayType(2, .i64), |
| 12180 | 12177 | }, |
| 12181 | 12178 | .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) { |
| 12182 | 12179 | .memory, .i64_array => return .void, |
| 12183 | 12180 | .i32_array => |len| return if (len == 1) .i32 else .void, |
| 12184 | | .byval => return o.lowerType(return_type), |
| 12181 | .byval => return o.lowerType(pt, return_type), |
| 12185 | 12182 | }, |
| 12186 | 12183 | .mips_o32 => switch (mips_c_abi.classifyType(return_type, zcu, .ret)) { |
| 12187 | 12184 | .memory, .i32_array => return .void, |
| 12188 | | .byval => return o.lowerType(return_type), |
| 12185 | .byval => return o.lowerType(pt, return_type), |
| 12189 | 12186 | }, |
| 12190 | 12187 | .riscv64_lp64, .riscv32_ilp32 => switch (riscv_c_abi.classifyType(return_type, zcu)) { |
| 12191 | 12188 | .memory => return .void, |
| ... | ... | @@ -12195,53 +12192,52 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu |
| 12195 | 12192 | .double_integer => { |
| 12196 | 12193 | return o.builder.structType(.normal, &.{ .i64, .i64 }); |
| 12197 | 12194 | }, |
| 12198 | | .byval => return o.lowerType(return_type), |
| 12195 | .byval => return o.lowerType(pt, return_type), |
| 12199 | 12196 | .fields => { |
| 12200 | 12197 | var types_len: usize = 0; |
| 12201 | 12198 | var types: [8]Builder.Type = undefined; |
| 12202 | 12199 | for (0..return_type.structFieldCount(zcu)) |field_index| { |
| 12203 | 12200 | const field_ty = return_type.fieldType(field_index, zcu); |
| 12204 | 12201 | if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue; |
| 12205 | | types[types_len] = try o.lowerType(field_ty); |
| 12202 | types[types_len] = try o.lowerType(pt, field_ty); |
| 12206 | 12203 | types_len += 1; |
| 12207 | 12204 | } |
| 12208 | 12205 | return o.builder.structType(.normal, types[0..types_len]); |
| 12209 | 12206 | }, |
| 12210 | 12207 | }, |
| 12211 | 12208 | .wasm_mvp => switch (wasm_c_abi.classifyType(return_type, zcu)) { |
| 12212 | | .direct => |scalar_ty| return o.lowerType(scalar_ty), |
| 12209 | .direct => |scalar_ty| return o.lowerType(pt, scalar_ty), |
| 12213 | 12210 | .indirect => return .void, |
| 12214 | 12211 | }, |
| 12215 | 12212 | // TODO investigate other callconvs |
| 12216 | | else => return o.lowerType(return_type), |
| 12213 | else => return o.lowerType(pt, return_type), |
| 12217 | 12214 | } |
| 12218 | 12215 | } |
| 12219 | 12216 | |
| 12220 | | fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12221 | | const zcu = o.pt.zcu; |
| 12217 | fn lowerWin64FnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12218 | const zcu = pt.zcu; |
| 12222 | 12219 | const return_type = Type.fromInterned(fn_info.return_type); |
| 12223 | 12220 | switch (x86_64_abi.classifyWindows(return_type, zcu, zcu.getTarget())) { |
| 12224 | 12221 | .integer => { |
| 12225 | 12222 | if (isScalar(zcu, return_type)) { |
| 12226 | | return o.lowerType(return_type); |
| 12223 | return o.lowerType(pt, return_type); |
| 12227 | 12224 | } else { |
| 12228 | 12225 | return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8)); |
| 12229 | 12226 | } |
| 12230 | 12227 | }, |
| 12231 | 12228 | .win_i128 => return o.builder.vectorType(.normal, 2, .i64), |
| 12232 | 12229 | .memory => return .void, |
| 12233 | | .sse => return o.lowerType(return_type), |
| 12230 | .sse => return o.lowerType(pt, return_type), |
| 12234 | 12231 | else => unreachable, |
| 12235 | 12232 | } |
| 12236 | 12233 | } |
| 12237 | 12234 | |
| 12238 | | fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12239 | | const pt = o.pt; |
| 12235 | fn lowerSystemVFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 12240 | 12236 | const zcu = pt.zcu; |
| 12241 | 12237 | const ip = &zcu.intern_pool; |
| 12242 | 12238 | const return_type = Type.fromInterned(fn_info.return_type); |
| 12243 | 12239 | if (isScalar(zcu, return_type)) { |
| 12244 | | return o.lowerType(return_type); |
| 12240 | return o.lowerType(pt, return_type); |
| 12245 | 12241 | } |
| 12246 | 12242 | const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret); |
| 12247 | 12243 | var types_index: u32 = 0; |
| ... | ... | @@ -12305,6 +12301,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E |
| 12305 | 12301 | |
| 12306 | 12302 | const ParamTypeIterator = struct { |
| 12307 | 12303 | object: *Object, |
| 12304 | pt: Zcu.PerThread, |
| 12308 | 12305 | fn_info: InternPool.Key.FuncType, |
| 12309 | 12306 | zig_index: u32, |
| 12310 | 12307 | llvm_index: u32, |
| ... | ... | @@ -12327,7 +12324,7 @@ const ParamTypeIterator = struct { |
| 12327 | 12324 | |
| 12328 | 12325 | pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering { |
| 12329 | 12326 | if (it.zig_index >= it.fn_info.param_types.len) return null; |
| 12330 | | const ip = &it.object.pt.zcu.intern_pool; |
| 12327 | const ip = &it.pt.zcu.intern_pool; |
| 12331 | 12328 | const ty = it.fn_info.param_types.get(ip)[it.zig_index]; |
| 12332 | 12329 | it.byval_attr = false; |
| 12333 | 12330 | return nextInner(it, Type.fromInterned(ty)); |
| ... | ... | @@ -12335,7 +12332,8 @@ const ParamTypeIterator = struct { |
| 12335 | 12332 | |
| 12336 | 12333 | /// `airCall` uses this instead of `next` so that it can take into account variadic functions. |
| 12337 | 12334 | pub fn nextCall(it: *ParamTypeIterator, fg: *FuncGen, args: []const Air.Inst.Ref) Allocator.Error!?Lowering { |
| 12338 | | const ip = &it.object.pt.zcu.intern_pool; |
| 12335 | assert(std.meta.eql(it.pt, fg.ng.pt)); |
| 12336 | const ip = &it.pt.zcu.intern_pool; |
| 12339 | 12337 | if (it.zig_index >= it.fn_info.param_types.len) { |
| 12340 | 12338 | if (it.zig_index >= args.len) { |
| 12341 | 12339 | return null; |
| ... | ... | @@ -12348,7 +12346,7 @@ const ParamTypeIterator = struct { |
| 12348 | 12346 | } |
| 12349 | 12347 | |
| 12350 | 12348 | fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { |
| 12351 | | const pt = it.object.pt; |
| 12349 | const pt = it.pt; |
| 12352 | 12350 | const zcu = pt.zcu; |
| 12353 | 12351 | const target = zcu.getTarget(); |
| 12354 | 12352 | |
| ... | ... | @@ -12448,7 +12446,7 @@ const ParamTypeIterator = struct { |
| 12448 | 12446 | for (0..ty.structFieldCount(zcu)) |field_index| { |
| 12449 | 12447 | const field_ty = ty.fieldType(field_index, zcu); |
| 12450 | 12448 | if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue; |
| 12451 | | it.types_buffer[it.types_len] = try it.object.lowerType(field_ty); |
| 12449 | it.types_buffer[it.types_len] = try it.object.lowerType(pt, field_ty); |
| 12452 | 12450 | it.types_len += 1; |
| 12453 | 12451 | } |
| 12454 | 12452 | it.llvm_index += it.types_len - 1; |
| ... | ... | @@ -12464,7 +12462,7 @@ const ParamTypeIterator = struct { |
| 12464 | 12462 | return .byval; |
| 12465 | 12463 | } else { |
| 12466 | 12464 | var types_buffer: [8]Builder.Type = undefined; |
| 12467 | | types_buffer[0] = try it.object.lowerType(scalar_ty); |
| 12465 | types_buffer[0] = try it.object.lowerType(pt, scalar_ty); |
| 12468 | 12466 | it.types_buffer = types_buffer; |
| 12469 | 12467 | it.types_len = 1; |
| 12470 | 12468 | it.llvm_index += 1; |
| ... | ... | @@ -12489,7 +12487,7 @@ const ParamTypeIterator = struct { |
| 12489 | 12487 | } |
| 12490 | 12488 | |
| 12491 | 12489 | fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering { |
| 12492 | | const zcu = it.object.pt.zcu; |
| 12490 | const zcu = it.pt.zcu; |
| 12493 | 12491 | switch (x86_64_abi.classifyWindows(ty, zcu, zcu.getTarget())) { |
| 12494 | 12492 | .integer => { |
| 12495 | 12493 | if (isScalar(zcu, ty)) { |
| ... | ... | @@ -12522,7 +12520,7 @@ const ParamTypeIterator = struct { |
| 12522 | 12520 | } |
| 12523 | 12521 | |
| 12524 | 12522 | fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { |
| 12525 | | const zcu = it.object.pt.zcu; |
| 12523 | const zcu = it.pt.zcu; |
| 12526 | 12524 | const ip = &zcu.intern_pool; |
| 12527 | 12525 | const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg); |
| 12528 | 12526 | if (classes[0] == .memory) { |
| ... | ... | @@ -12615,9 +12613,10 @@ const ParamTypeIterator = struct { |
| 12615 | 12613 | } |
| 12616 | 12614 | }; |
| 12617 | 12615 | |
| 12618 | | fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTypeIterator { |
| 12616 | fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) ParamTypeIterator { |
| 12619 | 12617 | return .{ |
| 12620 | 12618 | .object = object, |
| 12619 | .pt = pt, |
| 12621 | 12620 | .fn_info = fn_info, |
| 12622 | 12621 | .zig_index = 0, |
| 12623 | 12622 | .llvm_index = 0, |