| ... | ... | @@ -73,7 +73,7 @@ const TodoError = Zcu.CodegenFailError; |
| 73 | 73 | /// Avoid introducing new calls to this function---see documentation comment on `TodoError`. |
| 74 | 74 | fn todo(fg: *FuncGen, comptime format: []const u8, args: anytype) TodoError { |
| 75 | 75 | @branchHint(.cold); |
| 76 | | return fg.pt.zcu.codegenFail( |
| 76 | return fg.object.zcu.codegenFail( |
| 77 | 77 | fg.nav_index, |
| 78 | 78 | "TODO (LLVM): " ++ format, |
| 79 | 79 | args, |
| ... | ... | @@ -81,7 +81,7 @@ fn todo(fg: *FuncGen, comptime format: []const u8, args: anytype) TodoError { |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | fn ownerModule(fg: *const FuncGen) *Package.Module { |
| 84 | | return fg.pt.zcu.navFileScope(fg.nav_index).mod.?; |
| 84 | return fg.object.zcu.navFileScope(fg.nav_index).mod.?; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | fn maybeMarkAllowZeroAccess(self: *FuncGen, info: InternPool.Key.PtrType) void { |
| ... | ... | @@ -154,34 +154,35 @@ fn resolveInst(self: *FuncGen, inst: Air.Inst.Ref) Allocator.Error!Builder.Value |
| 154 | 154 | const gop = try self.func_inst_table.getOrPut(gpa, inst); |
| 155 | 155 | if (gop.found_existing) return gop.value_ptr.*; |
| 156 | 156 | |
| 157 | | const llvm_val = try self.resolveValue((try self.air.value(inst, self.pt)).?); |
| 157 | const llvm_val = try self.resolveValue(.fromInterned(inst.toInterned().?)); |
| 158 | 158 | gop.value_ptr.* = llvm_val.toValue(); |
| 159 | 159 | return llvm_val.toValue(); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | fn resolveValue(self: *FuncGen, val: Value) Allocator.Error!Builder.Constant { |
| 163 | 163 | const o = self.object; |
| 164 | | const pt = self.pt; |
| 165 | | const zcu = pt.zcu; |
| 164 | const zcu = o.zcu; |
| 166 | 165 | const ty = val.typeOf(zcu); |
| 167 | 166 | if (!isByRef(ty, zcu)) { |
| 168 | | return o.lowerValue(pt, val.toIntern()); |
| 167 | return o.lowerValue(val.toIntern()); |
| 169 | 168 | } else { |
| 170 | 169 | // We need a pointer to a global constant, i.e. a UAV. |
| 171 | | return o.lowerUavRef(pt, .{ |
| 172 | | .val = val.toIntern(), |
| 173 | | .orig_ty = (try pt.singleConstPtrType(ty)).toIntern(), |
| 174 | | }); |
| 170 | return o.lowerUavRef( |
| 171 | val.toIntern(), |
| 172 | ty.abiAlignment(zcu), |
| 173 | target_util.defaultAddressSpace(zcu.getTarget(), .global_constant), |
| 174 | ); |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | /// MLUGG TODO okay yeah prolly delete this again |
| 178 | 179 | fn lowerType(fg: *const FuncGen, ty: Type) Allocator.Error!Builder.Type { |
| 179 | | return fg.object.lowerType(fg.pt, ty); |
| 180 | return fg.object.lowerType(ty); |
| 180 | 181 | } |
| 181 | 182 | |
| 182 | 183 | pub fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) TodoError!void { |
| 183 | 184 | const o = self.object; |
| 184 | | const zcu = self.pt.zcu; |
| 185 | const zcu = self.object.zcu; |
| 185 | 186 | const ip = &zcu.intern_pool; |
| 186 | 187 | const air_tags = self.air.instructions.items(.tag); |
| 187 | 188 | switch (coverage_point) { |
| ... | ... | @@ -514,8 +515,7 @@ fn genBodyDebugScope( |
| 514 | 515 | defer self.scope = old_scope; |
| 515 | 516 | |
| 516 | 517 | if (maybe_inline_func) |inline_func| { |
| 517 | | const pt = self.pt; |
| 518 | | const zcu = pt.zcu; |
| 518 | const zcu = o.zcu; |
| 519 | 519 | const ip = &zcu.intern_pool; |
| 520 | 520 | |
| 521 | 521 | const func = zcu.funcInfo(inline_func); |
| ... | ... | @@ -529,18 +529,13 @@ fn genBodyDebugScope( |
| 529 | 529 | const line_number = self.base_line + 1; |
| 530 | 530 | self.inlined_at = try self.wip.debug_location.toMetadata(&o.builder); |
| 531 | 531 | |
| 532 | | const fn_ty = try pt.funcType(.{ |
| 533 | | .param_types = &.{}, |
| 534 | | .return_type = .void_type, |
| 535 | | }); |
| 536 | | |
| 537 | 532 | self.scope = try o.builder.debugSubprogram( |
| 538 | 533 | self.file, |
| 539 | 534 | try o.builder.metadataString(nav.name.toSlice(&zcu.intern_pool)), |
| 540 | 535 | try o.builder.metadataString(nav.fqn.toSlice(&zcu.intern_pool)), |
| 541 | 536 | line_number, |
| 542 | 537 | line_number + func.lbrace_line, |
| 543 | | try o.getDebugType(pt, fn_ty), |
| 538 | try o.builder.debugSubroutineType(null), |
| 544 | 539 | .{ |
| 545 | 540 | .di_flags = .{ .StaticMember = true }, |
| 546 | 541 | .sp_flags = .{ |
| ... | ... | @@ -582,7 +577,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 582 | 577 | const args = air_call.args; |
| 583 | 578 | const o = self.object; |
| 584 | 579 | const pt = self.pt; |
| 585 | | const zcu = pt.zcu; |
| 580 | const zcu = o.zcu; |
| 586 | 581 | const ip = &zcu.intern_pool; |
| 587 | 582 | const callee_ty = self.typeOf(air_call.callee); |
| 588 | 583 | const zig_fn_ty = switch (callee_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -628,7 +623,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 628 | 623 | try llvm_args.append(self.err_ret_trace); |
| 629 | 624 | } |
| 630 | 625 | |
| 631 | | var it = iterateParamTypes(o, pt, fn_info); |
| 626 | var it = iterateParamTypes(o, fn_info); |
| 632 | 627 | while (try it.nextCall(self, args)) |lowering| switch (lowering) { |
| 633 | 628 | .no_bits => continue, |
| 634 | 629 | .byval => { |
| ... | ... | @@ -761,7 +756,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 761 | 756 | |
| 762 | 757 | { |
| 763 | 758 | // Add argument attributes. |
| 764 | | it = iterateParamTypes(o, pt, fn_info); |
| 759 | it = iterateParamTypes(o, fn_info); |
| 765 | 760 | it.llvm_index += @intFromBool(sret); |
| 766 | 761 | it.llvm_index += @intFromBool(err_return_tracing); |
| 767 | 762 | while (try it.next()) |lowering| switch (lowering) { |
| ... | ... | @@ -852,7 +847,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 852 | 847 | } |
| 853 | 848 | } |
| 854 | 849 | |
| 855 | | const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 850 | const abi_ret_ty = try lowerFnRetTy(o, fn_info); |
| 856 | 851 | |
| 857 | 852 | if (abi_ret_ty != llvm_ret_ty) { |
| 858 | 853 | // In this case the function return type is honoring the calling convention by having |
| ... | ... | @@ -881,12 +876,11 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 881 | 876 | |
| 882 | 877 | fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) Allocator.Error!void { |
| 883 | 878 | const o = fg.object; |
| 884 | | const pt = fg.pt; |
| 885 | | const zcu = pt.zcu; |
| 879 | const zcu = o.zcu; |
| 886 | 880 | const target = zcu.getTarget(); |
| 887 | 881 | const panic_func = zcu.funcInfo(zcu.builtin_decl_values.get(panic_id.toBuiltin())); |
| 888 | 882 | const fn_info = zcu.typeToFunc(.fromInterned(panic_func.ty)).?; |
| 889 | | const panic_global = try o.resolveLlvmFunction(pt, panic_func.owner_nav); |
| 883 | const panic_global = try o.resolveLlvmFunction(panic_func.owner_nav); |
| 890 | 884 | |
| 891 | 885 | const has_err_trace = zcu.comp.config.any_error_tracing and fn_info.cc == .auto; |
| 892 | 886 | if (has_err_trace) assert(fg.err_ret_trace != .none); |
| ... | ... | @@ -905,30 +899,19 @@ fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) Allocator.Error!v |
| 905 | 899 | |
| 906 | 900 | fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!void { |
| 907 | 901 | const o = self.object; |
| 908 | | const pt = self.pt; |
| 909 | | const zcu = pt.zcu; |
| 902 | const zcu = o.zcu; |
| 910 | 903 | const ip = &zcu.intern_pool; |
| 911 | 904 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 912 | 905 | const ret_ty = self.typeOf(un_op); |
| 913 | 906 | |
| 914 | 907 | if (self.ret_ptr != .none) { |
| 915 | | const ptr_ty = try pt.singleMutPtrType(ret_ty); |
| 916 | | |
| 917 | 908 | const operand = try self.resolveInst(un_op); |
| 918 | | const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndef(zcu) else false; |
| 919 | | if (val_is_undef and safety) undef: { |
| 920 | | const ptr_info = ptr_ty.ptrInfo(zcu); |
| 921 | | const needs_bitmask = (ptr_info.packed_offset.host_size != 0); |
| 922 | | if (needs_bitmask) { |
| 923 | | // TODO: only some bits are to be undef, we cannot write with a simple memset. |
| 924 | | // meanwhile, ignore the write rather than stomping over valid bits. |
| 925 | | // https://github.com/ziglang/zig/issues/15337 |
| 926 | | break :undef; |
| 927 | | } |
| 909 | const val_is_undef = if (un_op.toInterned()) |i| Value.fromInterned(i).isUndef(zcu) else false; |
| 910 | if (val_is_undef and safety) { |
| 928 | 911 | const len = try o.builder.intValue(try self.lowerType(.usize), ret_ty.abiSize(zcu)); |
| 929 | 912 | _ = try self.wip.callMemSet( |
| 930 | 913 | self.ret_ptr, |
| 931 | | ptr_ty.ptrAlignment(zcu).toLlvm(), |
| 914 | ret_ty.abiAlignment(zcu).toLlvm(), |
| 932 | 915 | try o.builder.intValue(.i8, 0xaa), |
| 933 | 916 | len, |
| 934 | 917 | .normal, |
| ... | ... | @@ -951,7 +934,12 @@ fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!vo |
| 951 | 934 | return; |
| 952 | 935 | } |
| 953 | 936 | |
| 954 | | try self.store(self.ret_ptr, ptr_ty, operand, .none); |
| 937 | try self.store( |
| 938 | self.ret_ptr, |
| 939 | .none, |
| 940 | operand, |
| 941 | ret_ty, |
| 942 | ); |
| 955 | 943 | _ = try self.wip.retVoid(); |
| 956 | 944 | return; |
| 957 | 945 | } |
| ... | ... | @@ -968,15 +956,15 @@ fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!vo |
| 968 | 956 | return; |
| 969 | 957 | } |
| 970 | 958 | |
| 971 | | const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 959 | const abi_ret_ty = try lowerFnRetTy(o, fn_info); |
| 972 | 960 | const operand = try self.resolveInst(un_op); |
| 973 | | const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndef(zcu) else false; |
| 961 | const val_is_undef = if (un_op.toInterned()) |i| Value.fromInterned(i).isUndef(zcu) else false; |
| 974 | 962 | const alignment = ret_ty.abiAlignment(zcu).toLlvm(); |
| 975 | 963 | |
| 976 | 964 | if (val_is_undef and safety) { |
| 977 | 965 | const llvm_ret_ty = operand.typeOfWip(&self.wip); |
| 978 | 966 | const rp = try self.buildAlloca(llvm_ret_ty, alignment); |
| 979 | | const len = try o.builder.intValue(try self.lowerType(Type.usize), ret_ty.abiSize(zcu)); |
| 967 | const len = try o.builder.intValue(try self.lowerType(.usize), ret_ty.abiSize(zcu)); |
| 980 | 968 | _ = try self.wip.callMemSet( |
| 981 | 969 | rp, |
| 982 | 970 | alignment, |
| ... | ... | @@ -1014,8 +1002,7 @@ fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!vo |
| 1014 | 1002 | |
| 1015 | 1003 | fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!void { |
| 1016 | 1004 | const o = self.object; |
| 1017 | | const pt = self.pt; |
| 1018 | | const zcu = pt.zcu; |
| 1005 | const zcu = o.zcu; |
| 1019 | 1006 | const ip = &zcu.intern_pool; |
| 1020 | 1007 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 1021 | 1008 | const ptr_ty = self.typeOf(un_op); |
| ... | ... | @@ -1037,7 +1024,7 @@ fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!void { |
| 1037 | 1024 | return; |
| 1038 | 1025 | } |
| 1039 | 1026 | const ptr = try self.resolveInst(un_op); |
| 1040 | | const abi_ret_ty = try lowerFnRetTy(o, pt, fn_info); |
| 1027 | const abi_ret_ty = try lowerFnRetTy(o, fn_info); |
| 1041 | 1028 | const alignment = ret_ty.abiAlignment(zcu).toLlvm(); |
| 1042 | 1029 | _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, "")); |
| 1043 | 1030 | return; |
| ... | ... | @@ -1053,14 +1040,13 @@ fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 1053 | 1040 | } |
| 1054 | 1041 | |
| 1055 | 1042 | fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 1056 | | const pt = self.pt; |
| 1057 | | const zcu = pt.zcu; |
| 1043 | const zcu = self.object.zcu; |
| 1058 | 1044 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 1059 | 1045 | const src_list = try self.resolveInst(ty_op.operand); |
| 1060 | 1046 | const va_list_ty = ty_op.ty.toType(); |
| 1061 | 1047 | const llvm_va_list_ty = try self.lowerType(va_list_ty); |
| 1062 | 1048 | |
| 1063 | | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); |
| 1049 | const result_alignment = va_list_ty.abiAlignment(zcu).toLlvm(); |
| 1064 | 1050 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| 1065 | 1051 | |
| 1066 | 1052 | _ = try self.wip.callIntrinsic(.normal, .none, .va_copy, &.{dest_list.typeOfWip(&self.wip)}, &.{ dest_list, src_list }, ""); |
| ... | ... | @@ -1079,12 +1065,11 @@ fn airCVaEnd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 1079 | 1065 | } |
| 1080 | 1066 | |
| 1081 | 1067 | fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 1082 | | const pt = self.pt; |
| 1083 | | const zcu = pt.zcu; |
| 1068 | const zcu = self.object.zcu; |
| 1084 | 1069 | const va_list_ty = self.typeOfIndex(inst); |
| 1085 | 1070 | const llvm_va_list_ty = try self.lowerType(va_list_ty); |
| 1086 | 1071 | |
| 1087 | | const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm(); |
| 1072 | const result_alignment = va_list_ty.abiAlignment(zcu).toLlvm(); |
| 1088 | 1073 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| 1089 | 1074 | |
| 1090 | 1075 | _ = try self.wip.callIntrinsic(.normal, .none, .va_start, &.{dest_list.typeOfWip(&self.wip)}, &.{dest_list}, ""); |
| ... | ... | @@ -1145,8 +1130,7 @@ fn cmp( |
| 1145 | 1130 | rhs: Builder.Value, |
| 1146 | 1131 | ) Allocator.Error!Builder.Value { |
| 1147 | 1132 | const o = self.object; |
| 1148 | | const pt = self.pt; |
| 1149 | | const zcu = pt.zcu; |
| 1133 | const zcu = o.zcu; |
| 1150 | 1134 | const scalar_ty = operand_ty.scalarType(zcu); |
| 1151 | 1135 | const int_ty = switch (scalar_ty.zigTypeTag(zcu)) { |
| 1152 | 1136 | .@"enum" => scalar_ty.intTagType(zcu), |
| ... | ... | @@ -1244,8 +1228,7 @@ fn lowerBlock( |
| 1244 | 1228 | maybe_inline_func: ?InternPool.Index, |
| 1245 | 1229 | body: []const Air.Inst.Index, |
| 1246 | 1230 | ) TodoError!Builder.Value { |
| 1247 | | const pt = self.pt; |
| 1248 | | const zcu = pt.zcu; |
| 1231 | const zcu = self.object.zcu; |
| 1249 | 1232 | const inst_ty = self.typeOfIndex(inst); |
| 1250 | 1233 | |
| 1251 | 1234 | if (inst_ty.isNoReturn(zcu)) { |
| ... | ... | @@ -1294,7 +1277,7 @@ fn lowerBlock( |
| 1294 | 1277 | } |
| 1295 | 1278 | |
| 1296 | 1279 | fn airBr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!void { |
| 1297 | | const zcu = self.pt.zcu; |
| 1280 | const zcu = self.object.zcu; |
| 1298 | 1281 | const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br; |
| 1299 | 1282 | const block = self.blocks.get(branch.block_inst).?; |
| 1300 | 1283 | |
| ... | ... | @@ -1324,12 +1307,12 @@ fn lowerSwitchDispatch( |
| 1324 | 1307 | dispatch_info: SwitchDispatchInfo, |
| 1325 | 1308 | ) Allocator.Error!void { |
| 1326 | 1309 | const o = self.object; |
| 1327 | | const pt = self.pt; |
| 1328 | | const zcu = pt.zcu; |
| 1310 | const zcu = o.zcu; |
| 1329 | 1311 | const cond_ty = self.typeOf(cond_ref); |
| 1330 | 1312 | const switch_br = self.air.unwrapSwitch(switch_inst); |
| 1331 | 1313 | |
| 1332 | | if (try self.air.value(cond_ref, pt)) |cond_val| { |
| 1314 | if (cond_ref.toInterned()) |cond_ip_index| { |
| 1315 | const cond_val: Value = .fromInterned(cond_ip_index); |
| 1333 | 1316 | // Comptime-known dispatch. Iterate the cases to find the correct |
| 1334 | 1317 | // one, and branch to the corresponding element of `case_blocks`. |
| 1335 | 1318 | var it = switch_br.iterateCases(); |
| ... | ... | @@ -1413,7 +1396,7 @@ fn lowerSwitchDispatch( |
| 1413 | 1396 | // The switch prongs will correspond to our scalar cases. Ranges will |
| 1414 | 1397 | // be handled by conditional branches in the `else` prong. |
| 1415 | 1398 | |
| 1416 | | const llvm_usize = try self.lowerType(Type.usize); |
| 1399 | const llvm_usize = try self.lowerType(.usize); |
| 1417 | 1400 | const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder)) |
| 1418 | 1401 | try self.wip.cast(.ptrtoint, cond, llvm_usize, "") |
| 1419 | 1402 | else |
| ... | ... | @@ -1581,7 +1564,7 @@ fn airTry(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) TodoError!Builde |
| 1581 | 1564 | } |
| 1582 | 1565 | |
| 1583 | 1566 | fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) TodoError!Builder.Value { |
| 1584 | | const zcu = self.pt.zcu; |
| 1567 | const zcu = self.object.zcu; |
| 1585 | 1568 | const unwrapped_try = self.air.unwrapTryPtr(inst); |
| 1586 | 1569 | const err_union_ptr = try self.resolveInst(unwrapped_try.error_union_ptr); |
| 1587 | 1570 | const body = unwrapped_try.else_body; |
| ... | ... | @@ -1605,8 +1588,7 @@ fn lowerTry( |
| 1605 | 1588 | err_cold: bool, |
| 1606 | 1589 | ) TodoError!Builder.Value { |
| 1607 | 1590 | const o = fg.object; |
| 1608 | | const pt = fg.pt; |
| 1609 | | const zcu = pt.zcu; |
| 1591 | const zcu = o.zcu; |
| 1610 | 1592 | const payload_ty = err_union_ty.errorUnionPayload(zcu); |
| 1611 | 1593 | const payload_has_bits = payload_ty.hasRuntimeBits(zcu); |
| 1612 | 1594 | const error_type = try o.errorIntType(); |
| ... | ... | @@ -1667,8 +1649,7 @@ fn lowerTry( |
| 1667 | 1649 | |
| 1668 | 1650 | fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) TodoError!void { |
| 1669 | 1651 | const o = self.object; |
| 1670 | | const pt = self.pt; |
| 1671 | | const zcu = pt.zcu; |
| 1652 | const zcu = o.zcu; |
| 1672 | 1653 | |
| 1673 | 1654 | const switch_br = self.air.unwrapSwitch(inst); |
| 1674 | 1655 | |
| ... | ... | @@ -1773,8 +1754,8 @@ fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) Tod |
| 1773 | 1754 | const table_includes_else = item_count != table_len; |
| 1774 | 1755 | |
| 1775 | 1756 | break :jmp_table .{ |
| 1776 | | .min = try o.lowerValue(pt, min.toIntern()), |
| 1777 | | .max = try o.lowerValue(pt, max.toIntern()), |
| 1757 | .min = try o.lowerValue(min.toIntern()), |
| 1758 | .max = try o.lowerValue(max.toIntern()), |
| 1778 | 1759 | .in_bounds_hint = if (table_includes_else) .none else switch (switch_br.getElseHint()) { |
| 1779 | 1760 | .none, .cold => .none, |
| 1780 | 1761 | .unpredictable => .unpredictable, |
| ... | ... | @@ -1883,7 +1864,7 @@ fn airSwitchBr(self: *FuncGen, inst: Air.Inst.Index, is_dispatch_loop: bool) Tod |
| 1883 | 1864 | } |
| 1884 | 1865 | |
| 1885 | 1866 | fn switchCaseItemRange(self: *FuncGen, switch_br: Air.UnwrappedSwitch) ?[2]Value { |
| 1886 | | const zcu = self.pt.zcu; |
| 1867 | const zcu = self.object.zcu; |
| 1887 | 1868 | var it = switch_br.iterateCases(); |
| 1888 | 1869 | var min: ?Value = null; |
| 1889 | 1870 | var max: ?Value = null; |
| ... | ... | @@ -1928,8 +1909,7 @@ fn airLoop(self: *FuncGen, inst: Air.Inst.Index) TodoError!void { |
| 1928 | 1909 | |
| 1929 | 1910 | fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 1930 | 1911 | const o = self.object; |
| 1931 | | const pt = self.pt; |
| 1932 | | const zcu = pt.zcu; |
| 1912 | const zcu = o.zcu; |
| 1933 | 1913 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 1934 | 1914 | const operand_ty = self.typeOf(ty_op.operand); |
| 1935 | 1915 | const array_ty = operand_ty.childType(zcu); |
| ... | ... | @@ -1942,8 +1922,7 @@ fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder |
| 1942 | 1922 | |
| 1943 | 1923 | fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value { |
| 1944 | 1924 | const o = self.object; |
| 1945 | | const pt = self.pt; |
| 1946 | | const zcu = pt.zcu; |
| 1925 | const zcu = o.zcu; |
| 1947 | 1926 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 1948 | 1927 | |
| 1949 | 1928 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -1964,7 +1943,7 @@ fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value |
| 1964 | 1943 | ); |
| 1965 | 1944 | |
| 1966 | 1945 | const rt_int_bits = compilerRtIntBits(@intCast(operand_scalar_ty.bitSize(zcu))) orelse { |
| 1967 | | return self.todo("float_from_int from '{f}' without intrinsics", .{operand_scalar_ty.fmt(pt)}); |
| 1946 | return self.todo("float_from_int on {d} bit integer", .{operand_scalar_ty.bitSize(zcu)}); |
| 1968 | 1947 | }; |
| 1969 | 1948 | const rt_int_ty = try o.builder.intType(rt_int_bits); |
| 1970 | 1949 | var extended = try self.wip.conv( |
| ... | ... | @@ -2011,8 +1990,7 @@ fn airIntFromFloat( |
| 2011 | 1990 | _ = fast; |
| 2012 | 1991 | |
| 2013 | 1992 | const o = self.object; |
| 2014 | | const pt = self.pt; |
| 2015 | | const zcu = pt.zcu; |
| 1993 | const zcu = o.zcu; |
| 2016 | 1994 | const target = zcu.getTarget(); |
| 2017 | 1995 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 2018 | 1996 | |
| ... | ... | @@ -2035,7 +2013,7 @@ fn airIntFromFloat( |
| 2035 | 2013 | } |
| 2036 | 2014 | |
| 2037 | 2015 | const rt_int_bits = compilerRtIntBits(@intCast(dest_scalar_ty.bitSize(zcu))) orelse { |
| 2038 | | return self.todo("int_from_float to '{f}' without intrinsics", .{dest_scalar_ty.fmt(pt)}); |
| 2016 | return self.todo("int_from_float to {d} bit integer", .{dest_scalar_ty.bitSize(zcu)}); |
| 2039 | 2017 | }; |
| 2040 | 2018 | const ret_ty = try o.builder.intType(rt_int_bits); |
| 2041 | 2019 | const libc_ret_ty = if (rt_int_bits == 128 and (target.os.tag == .windows and target.cpu.arch == .x86_64)) b: { |
| ... | ... | @@ -2074,14 +2052,13 @@ fn airIntFromFloat( |
| 2074 | 2052 | } |
| 2075 | 2053 | |
| 2076 | 2054 | fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { |
| 2077 | | const zcu = fg.pt.zcu; |
| 2055 | const zcu = fg.object.zcu; |
| 2078 | 2056 | return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr; |
| 2079 | 2057 | } |
| 2080 | 2058 | |
| 2081 | 2059 | fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { |
| 2082 | 2060 | const o = fg.object; |
| 2083 | | const pt = fg.pt; |
| 2084 | | const zcu = pt.zcu; |
| 2061 | const zcu = o.zcu; |
| 2085 | 2062 | const llvm_usize = try fg.lowerType(.usize); |
| 2086 | 2063 | switch (ty.ptrSize(zcu)) { |
| 2087 | 2064 | .slice => { |
| ... | ... | @@ -2109,15 +2086,14 @@ fn airSliceField(self: *FuncGen, inst: Air.Inst.Index, index: u32) Allocator.Err |
| 2109 | 2086 | } |
| 2110 | 2087 | |
| 2111 | 2088 | fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: u1) Allocator.Error!Builder.Value { |
| 2112 | | const zcu = self.pt.zcu; |
| 2089 | const zcu = self.object.zcu; |
| 2113 | 2090 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 2114 | 2091 | const slice_ptr = try self.resolveInst(ty_op.operand); |
| 2115 | 2092 | return self.ptraddConst(slice_ptr, index * Type.usize.abiSize(zcu)); |
| 2116 | 2093 | } |
| 2117 | 2094 | |
| 2118 | 2095 | fn airSliceElemVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 2119 | | const pt = self.pt; |
| 2120 | | const zcu = pt.zcu; |
| 2096 | const zcu = self.object.zcu; |
| 2121 | 2097 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 2122 | 2098 | const slice_ty = self.typeOf(bin_op.lhs); |
| 2123 | 2099 | const slice = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -2138,8 +2114,7 @@ fn airSliceElemVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder |
| 2138 | 2114 | } |
| 2139 | 2115 | |
| 2140 | 2116 | fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 2141 | | const pt = self.pt; |
| 2142 | | const zcu = pt.zcu; |
| 2117 | const zcu = self.object.zcu; |
| 2143 | 2118 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 2144 | 2119 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2145 | 2120 | const slice_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2151,8 +2126,7 @@ fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder |
| 2151 | 2126 | } |
| 2152 | 2127 | |
| 2153 | 2128 | fn airArrayElemVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 2154 | | const pt = self.pt; |
| 2155 | | const zcu = pt.zcu; |
| 2129 | const zcu = self.object.zcu; |
| 2156 | 2130 | |
| 2157 | 2131 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 2158 | 2132 | const array_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2174,28 +2148,25 @@ fn airArrayElemVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder |
| 2174 | 2148 | } |
| 2175 | 2149 | |
| 2176 | 2150 | fn airPtrElemVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 2177 | | const pt = self.pt; |
| 2178 | | const zcu = pt.zcu; |
| 2151 | const zcu = self.object.zcu; |
| 2179 | 2152 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 2180 | 2153 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 2181 | 2154 | const elem_ty = ptr_ty.indexableElem(zcu); |
| 2182 | 2155 | const base_ptr = try self.resolveInst(bin_op.lhs); |
| 2183 | 2156 | const rhs = try self.resolveInst(bin_op.rhs); |
| 2184 | | const ptr = try self.ptraddScaled(base_ptr, rhs, elem_ty.abiSize(zcu)); |
| 2185 | | if (isByRef(elem_ty, zcu)) { |
| 2186 | | self.maybeMarkAllowZeroAccess(ptr_ty.ptrInfo(zcu)); |
| 2187 | | const ptr_align = (ptr_ty.ptrAlignment(zcu).min(elem_ty.abiAlignment(zcu))).toLlvm(); |
| 2188 | | return self.loadByRef(ptr, elem_ty, ptr_align, if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal); |
| 2189 | | } |
| 2190 | 2157 | |
| 2191 | 2158 | self.maybeMarkAllowZeroAccess(ptr_ty.ptrInfo(zcu)); |
| 2192 | 2159 | |
| 2193 | | return self.load(ptr, ptr_ty); |
| 2160 | return self.load( |
| 2161 | try self.ptraddScaled(base_ptr, rhs, elem_ty.abiSize(zcu)), |
| 2162 | elem_ty, |
| 2163 | ptr_ty.ptrAlignment(zcu).min(elem_ty.abiAlignment(zcu)).toLlvm(), |
| 2164 | if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal, |
| 2165 | ); |
| 2194 | 2166 | } |
| 2195 | 2167 | |
| 2196 | 2168 | fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 2197 | | const pt = self.pt; |
| 2198 | | const zcu = pt.zcu; |
| 2169 | const zcu = self.object.zcu; |
| 2199 | 2170 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 2200 | 2171 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2201 | 2172 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -2232,8 +2203,7 @@ fn airStructFieldPtrIndex( |
| 2232 | 2203 | |
| 2233 | 2204 | fn airStructFieldVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 2234 | 2205 | const o = self.object; |
| 2235 | | const pt = self.pt; |
| 2236 | | const zcu = pt.zcu; |
| 2206 | const zcu = o.zcu; |
| 2237 | 2207 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 2238 | 2208 | const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data; |
| 2239 | 2209 | const struct_ty = self.typeOf(struct_field.struct_operand); |
| ... | ... | @@ -2298,8 +2268,7 @@ fn airStructFieldVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build |
| 2298 | 2268 | |
| 2299 | 2269 | fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 2300 | 2270 | const o = self.object; |
| 2301 | | const pt = self.pt; |
| 2302 | | const zcu = pt.zcu; |
| 2271 | const zcu = o.zcu; |
| 2303 | 2272 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 2304 | 2273 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 2305 | 2274 | |
| ... | ... | @@ -2310,7 +2279,7 @@ fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build |
| 2310 | 2279 | if (field_offset == 0) return field_ptr; |
| 2311 | 2280 | |
| 2312 | 2281 | const res_ty = try self.lowerType(ty_pl.ty.toType()); |
| 2313 | | const llvm_usize = try self.lowerType(Type.usize); |
| 2282 | const llvm_usize = try self.lowerType(.usize); |
| 2314 | 2283 | |
| 2315 | 2284 | const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, ""); |
| 2316 | 2285 | const base_ptr_int = try self.wip.bin( |
| ... | ... | @@ -2358,7 +2327,7 @@ fn airDbgEmptyStmt(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder |
| 2358 | 2327 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 2359 | 2328 | const o = self.object; |
| 2360 | 2329 | const pt = self.pt; |
| 2361 | | const zcu = pt.zcu; |
| 2330 | const zcu = o.zcu; |
| 2362 | 2331 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 2363 | 2332 | const operand = try self.resolveInst(pl_op.operand); |
| 2364 | 2333 | const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload); |
| ... | ... | @@ -2415,7 +2384,7 @@ fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index, is_arg: bool) Allocator.Er |
| 2415 | 2384 | try o.getDebugType(pt, operand_ty), |
| 2416 | 2385 | ); |
| 2417 | 2386 | |
| 2418 | | const zcu = pt.zcu; |
| 2387 | const zcu = o.zcu; |
| 2419 | 2388 | const owner_mod = self.ownerModule(); |
| 2420 | 2389 | if (isByRef(operand_ty, zcu)) { |
| 2421 | 2390 | _ = try self.wip.callIntrinsic( |
| ... | ... | @@ -2501,8 +2470,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value { |
| 2501 | 2470 | // This stores whether we need to add an elementtype attribute and |
| 2502 | 2471 | // if so, the element type itself. |
| 2503 | 2472 | const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count); |
| 2504 | | const pt = self.pt; |
| 2505 | | const zcu = pt.zcu; |
| 2473 | const zcu = o.zcu; |
| 2506 | 2474 | const ip = &zcu.intern_pool; |
| 2507 | 2475 | const target = zcu.getTarget(); |
| 2508 | 2476 | |
| ... | ... | @@ -2855,8 +2823,7 @@ fn airIsNonNull( |
| 2855 | 2823 | cond: Builder.IntegerCondition, |
| 2856 | 2824 | ) Allocator.Error!Builder.Value { |
| 2857 | 2825 | const o = self.object; |
| 2858 | | const pt = self.pt; |
| 2859 | | const zcu = pt.zcu; |
| 2826 | const zcu = o.zcu; |
| 2860 | 2827 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 2861 | 2828 | const operand = try self.resolveInst(un_op); |
| 2862 | 2829 | const operand_ty = self.typeOf(un_op); |
| ... | ... | @@ -2905,8 +2872,7 @@ fn airIsErr( |
| 2905 | 2872 | operand_is_ptr: bool, |
| 2906 | 2873 | ) Allocator.Error!Builder.Value { |
| 2907 | 2874 | const o = self.object; |
| 2908 | | const pt = self.pt; |
| 2909 | | const zcu = pt.zcu; |
| 2875 | const zcu = o.zcu; |
| 2910 | 2876 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 2911 | 2877 | const operand = try self.resolveInst(un_op); |
| 2912 | 2878 | const operand_ty = self.typeOf(un_op); |
| ... | ... | @@ -2959,8 +2925,7 @@ fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) Allocator.Erro |
| 2959 | 2925 | comptime assert(optional_layout_version == 3); |
| 2960 | 2926 | |
| 2961 | 2927 | const o = self.object; |
| 2962 | | const pt = self.pt; |
| 2963 | | const zcu = pt.zcu; |
| 2928 | const zcu = o.zcu; |
| 2964 | 2929 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 2965 | 2930 | const operand = try self.resolveInst(ty_op.operand); |
| 2966 | 2931 | const optional_ptr_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -3001,8 +2966,7 @@ fn airOptionalPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) Allocator.Erro |
| 3001 | 2966 | } |
| 3002 | 2967 | |
| 3003 | 2968 | fn airOptionalPayload(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3004 | | const pt = self.pt; |
| 3005 | | const zcu = pt.zcu; |
| 2969 | const zcu = self.object.zcu; |
| 3006 | 2970 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3007 | 2971 | const operand = try self.resolveInst(ty_op.operand); |
| 3008 | 2972 | const optional_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -3018,8 +2982,7 @@ fn airOptionalPayload(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Buil |
| 3018 | 2982 | } |
| 3019 | 2983 | |
| 3020 | 2984 | fn airErrUnionPayload(self: *FuncGen, inst: Air.Inst.Index, operand_is_ptr: bool) Allocator.Error!Builder.Value { |
| 3021 | | const pt = self.pt; |
| 3022 | | const zcu = pt.zcu; |
| 2985 | const zcu = self.object.zcu; |
| 3023 | 2986 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3024 | 2987 | const operand = try self.resolveInst(ty_op.operand); |
| 3025 | 2988 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -3050,8 +3013,7 @@ fn airErrUnionErr( |
| 3050 | 3013 | operand_is_ptr: bool, |
| 3051 | 3014 | ) Allocator.Error!Builder.Value { |
| 3052 | 3015 | const o = self.object; |
| 3053 | | const pt = self.pt; |
| 3054 | | const zcu = pt.zcu; |
| 3016 | const zcu = o.zcu; |
| 3055 | 3017 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3056 | 3018 | const operand = try self.resolveInst(ty_op.operand); |
| 3057 | 3019 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -3093,8 +3055,7 @@ fn airErrUnionErr( |
| 3093 | 3055 | |
| 3094 | 3056 | fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3095 | 3057 | const o = self.object; |
| 3096 | | const pt = self.pt; |
| 3097 | | const zcu = pt.zcu; |
| 3058 | const zcu = o.zcu; |
| 3098 | 3059 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3099 | 3060 | const operand = try self.resolveInst(ty_op.operand); |
| 3100 | 3061 | const err_union_ptr_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -3133,8 +3094,7 @@ fn airSetErrReturnTrace(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Bu |
| 3133 | 3094 | } |
| 3134 | 3095 | |
| 3135 | 3096 | fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3136 | | const pt = self.pt; |
| 3137 | | const zcu = pt.zcu; |
| 3097 | const zcu = self.object.zcu; |
| 3138 | 3098 | |
| 3139 | 3099 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 3140 | 3100 | const struct_ty = ty_pl.ty.toType(); |
| ... | ... | @@ -3150,12 +3110,7 @@ fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) Allocator.Er |
| 3150 | 3110 | }; |
| 3151 | 3111 | |
| 3152 | 3112 | const field_ptr = try self.ptraddConst(self.err_ret_trace, field_offset); |
| 3153 | | |
| 3154 | | const field_ptr_ty = try pt.ptrType(.{ |
| 3155 | | .child = field_ty.toIntern(), |
| 3156 | | .flags = .{ .alignment = field_align }, |
| 3157 | | }); |
| 3158 | | return self.load(field_ptr, field_ptr_ty); |
| 3113 | return self.load(field_ptr, field_ty, field_align.toLlvm(), .normal); |
| 3159 | 3114 | } |
| 3160 | 3115 | |
| 3161 | 3116 | /// As an optimization, we want to avoid unnecessary copies of |
| ... | ... | @@ -3183,8 +3138,7 @@ fn isNextRet( |
| 3183 | 3138 | |
| 3184 | 3139 | fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3185 | 3140 | const o = self.object; |
| 3186 | | const pt = self.pt; |
| 3187 | | const zcu = pt.zcu; |
| 3141 | const zcu = o.zcu; |
| 3188 | 3142 | const inst = body_tail[0]; |
| 3189 | 3143 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3190 | 3144 | const payload_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -3205,8 +3159,12 @@ fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator. |
| 3205 | 3159 | }; |
| 3206 | 3160 | |
| 3207 | 3161 | const payload_ptr = optional_ptr; // payload always at offset 0 |
| 3208 | | const payload_ptr_ty = try pt.singleMutPtrType(payload_ty); |
| 3209 | | try self.store(payload_ptr, payload_ptr_ty, operand, .none); |
| 3162 | try self.store( |
| 3163 | payload_ptr, |
| 3164 | .none, |
| 3165 | operand, |
| 3166 | payload_ty, |
| 3167 | ); |
| 3210 | 3168 | // Non-null bit immediately after payload (no padding because the bit has alignment 1). |
| 3211 | 3169 | const non_null_ptr = try self.ptraddConst(optional_ptr, payload_ty.abiSize(zcu)); |
| 3212 | 3170 | _ = try self.wip.store(.normal, non_null_bit, non_null_ptr, .default); |
| ... | ... | @@ -3215,8 +3173,7 @@ fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator. |
| 3215 | 3173 | |
| 3216 | 3174 | fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3217 | 3175 | const o = self.object; |
| 3218 | | const pt = self.pt; |
| 3219 | | const zcu = pt.zcu; |
| 3176 | const zcu = o.zcu; |
| 3220 | 3177 | const inst = body_tail[0]; |
| 3221 | 3178 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3222 | 3179 | const err_un_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -3230,23 +3187,26 @@ fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) All |
| 3230 | 3187 | const result_ptr = if (self.isNextRet(body_tail)) |
| 3231 | 3188 | self.ret_ptr |
| 3232 | 3189 | else brk: { |
| 3233 | | const alignment = err_un_ty.abiAlignment(pt.zcu).toLlvm(); |
| 3190 | const alignment = err_un_ty.abiAlignment(o.zcu).toLlvm(); |
| 3234 | 3191 | const result_ptr = try self.buildAlloca(err_un_llvm_ty, alignment); |
| 3235 | 3192 | break :brk result_ptr; |
| 3236 | 3193 | }; |
| 3237 | 3194 | |
| 3238 | 3195 | const err_ptr = try self.ptraddConst(result_ptr, codegen.errUnionErrorOffset(payload_ty, zcu)); |
| 3239 | | const error_alignment = Type.anyerror.abiAlignment(pt.zcu).toLlvm(); |
| 3196 | const error_alignment = Type.anyerror.abiAlignment(o.zcu).toLlvm(); |
| 3240 | 3197 | _ = try self.wip.store(.normal, ok_err_code, err_ptr, error_alignment); |
| 3241 | 3198 | const payload_ptr = try self.ptraddConst(result_ptr, codegen.errUnionPayloadOffset(payload_ty, zcu)); |
| 3242 | | const payload_ptr_ty = try pt.singleMutPtrType(payload_ty); |
| 3243 | | try self.store(payload_ptr, payload_ptr_ty, operand, .none); |
| 3199 | try self.store( |
| 3200 | payload_ptr, |
| 3201 | .none, |
| 3202 | operand, |
| 3203 | payload_ty, |
| 3204 | ); |
| 3244 | 3205 | return result_ptr; |
| 3245 | 3206 | } |
| 3246 | 3207 | |
| 3247 | 3208 | fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3248 | | const pt = self.pt; |
| 3249 | | const zcu = pt.zcu; |
| 3209 | const zcu = self.object.zcu; |
| 3250 | 3210 | const inst = body_tail[0]; |
| 3251 | 3211 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3252 | 3212 | const err_un_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -3268,10 +3228,8 @@ fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocat |
| 3268 | 3228 | const error_alignment = Type.anyerror.abiAlignment(zcu).toLlvm(); |
| 3269 | 3229 | _ = try self.wip.store(.normal, operand, err_ptr, error_alignment); |
| 3270 | 3230 | const payload_ptr = try self.ptraddConst(result_ptr, codegen.errUnionPayloadOffset(payload_ty, zcu)); |
| 3271 | | const payload_ptr_ty = try pt.singleMutPtrType(payload_ty); |
| 3272 | 3231 | // TODO store undef to payload_ptr |
| 3273 | 3232 | _ = payload_ptr; |
| 3274 | | _ = payload_ptr_ty; |
| 3275 | 3233 | return result_ptr; |
| 3276 | 3234 | } |
| 3277 | 3235 | |
| ... | ... | @@ -3279,7 +3237,7 @@ fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build |
| 3279 | 3237 | const o = self.object; |
| 3280 | 3238 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 3281 | 3239 | const index = pl_op.payload; |
| 3282 | | const llvm_usize = try self.lowerType(Type.usize); |
| 3240 | const llvm_usize = try self.lowerType(.usize); |
| 3283 | 3241 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{ |
| 3284 | 3242 | try o.builder.intValue(.i32, index), |
| 3285 | 3243 | }, ""); |
| ... | ... | @@ -3289,7 +3247,7 @@ fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build |
| 3289 | 3247 | const o = self.object; |
| 3290 | 3248 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 3291 | 3249 | const index = pl_op.payload; |
| 3292 | | const llvm_isize = try self.lowerType(Type.isize); |
| 3250 | const llvm_isize = try self.lowerType(.isize); |
| 3293 | 3251 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{ |
| 3294 | 3252 | try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand), |
| 3295 | 3253 | }, ""); |
| ... | ... | @@ -3297,15 +3255,13 @@ fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build |
| 3297 | 3255 | |
| 3298 | 3256 | fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3299 | 3257 | const o = fg.object; |
| 3300 | | const pt = fg.pt; |
| 3301 | 3258 | const ty_nav = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav; |
| 3302 | | const llvm_ptr_const = try o.lowerNavRefValue(pt, ty_nav.nav); |
| 3259 | const llvm_ptr_const = try o.lowerNavRefValue(ty_nav.nav); |
| 3303 | 3260 | return llvm_ptr_const.toValue(); |
| 3304 | 3261 | } |
| 3305 | 3262 | |
| 3306 | 3263 | fn airMin(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3307 | | const pt = self.pt; |
| 3308 | | const zcu = pt.zcu; |
| 3264 | const zcu = self.object.zcu; |
| 3309 | 3265 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3310 | 3266 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3311 | 3267 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3324,8 +3280,7 @@ fn airMin(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3324 | 3280 | } |
| 3325 | 3281 | |
| 3326 | 3282 | fn airMax(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3327 | | const pt = self.pt; |
| 3328 | | const zcu = pt.zcu; |
| 3283 | const zcu = self.object.zcu; |
| 3329 | 3284 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3330 | 3285 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3331 | 3286 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3353,7 +3308,7 @@ fn airSlice(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3353 | 3308 | } |
| 3354 | 3309 | |
| 3355 | 3310 | fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| 3356 | | const zcu = self.pt.zcu; |
| 3311 | const zcu = self.object.zcu; |
| 3357 | 3312 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3358 | 3313 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3359 | 3314 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3371,8 +3326,7 @@ fn airSafeArithmetic( |
| 3371 | 3326 | unsigned_intrinsic: Builder.Intrinsic, |
| 3372 | 3327 | ) Allocator.Error!Builder.Value { |
| 3373 | 3328 | const o = fg.object; |
| 3374 | | const pt = fg.pt; |
| 3375 | | const zcu = pt.zcu; |
| 3329 | const zcu = o.zcu; |
| 3376 | 3330 | |
| 3377 | 3331 | const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3378 | 3332 | const lhs = try fg.resolveInst(bin_op.lhs); |
| ... | ... | @@ -3419,8 +3373,7 @@ fn airAddWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 3419 | 3373 | } |
| 3420 | 3374 | |
| 3421 | 3375 | fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3422 | | const pt = self.pt; |
| 3423 | | const zcu = pt.zcu; |
| 3376 | const zcu = self.object.zcu; |
| 3424 | 3377 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3425 | 3378 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3426 | 3379 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3438,7 +3391,7 @@ fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3438 | 3391 | } |
| 3439 | 3392 | |
| 3440 | 3393 | fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| 3441 | | const zcu = self.pt.zcu; |
| 3394 | const zcu = self.object.zcu; |
| 3442 | 3395 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3443 | 3396 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3444 | 3397 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3458,8 +3411,7 @@ fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 3458 | 3411 | } |
| 3459 | 3412 | |
| 3460 | 3413 | fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3461 | | const pt = self.pt; |
| 3462 | | const zcu = pt.zcu; |
| 3414 | const zcu = self.object.zcu; |
| 3463 | 3415 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3464 | 3416 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3465 | 3417 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3477,7 +3429,7 @@ fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3477 | 3429 | } |
| 3478 | 3430 | |
| 3479 | 3431 | fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| 3480 | | const zcu = self.pt.zcu; |
| 3432 | const zcu = self.object.zcu; |
| 3481 | 3433 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3482 | 3434 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3483 | 3435 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3497,8 +3449,7 @@ fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 3497 | 3449 | } |
| 3498 | 3450 | |
| 3499 | 3451 | fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3500 | | const pt = self.pt; |
| 3501 | | const zcu = pt.zcu; |
| 3452 | const zcu = self.object.zcu; |
| 3502 | 3453 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3503 | 3454 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3504 | 3455 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3525,7 +3476,7 @@ fn airDivFloat(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) |
| 3525 | 3476 | } |
| 3526 | 3477 | |
| 3527 | 3478 | fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| 3528 | | const zcu = self.pt.zcu; |
| 3479 | const zcu = self.object.zcu; |
| 3529 | 3480 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3530 | 3481 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3531 | 3482 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3541,8 +3492,7 @@ fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) |
| 3541 | 3492 | |
| 3542 | 3493 | fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| 3543 | 3494 | const o = self.object; |
| 3544 | | const pt = self.pt; |
| 3545 | | const zcu = pt.zcu; |
| 3495 | const zcu = o.zcu; |
| 3546 | 3496 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3547 | 3497 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3548 | 3498 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3591,7 +3541,7 @@ fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) |
| 3591 | 3541 | } |
| 3592 | 3542 | |
| 3593 | 3543 | fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| 3594 | | const zcu = self.pt.zcu; |
| 3544 | const zcu = self.object.zcu; |
| 3595 | 3545 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3596 | 3546 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3597 | 3547 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3608,7 +3558,7 @@ fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) |
| 3608 | 3558 | } |
| 3609 | 3559 | |
| 3610 | 3560 | fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| 3611 | | const zcu = self.pt.zcu; |
| 3561 | const zcu = self.object.zcu; |
| 3612 | 3562 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3613 | 3563 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3614 | 3564 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3625,8 +3575,7 @@ fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo |
| 3625 | 3575 | |
| 3626 | 3576 | fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| 3627 | 3577 | const o = self.object; |
| 3628 | | const pt = self.pt; |
| 3629 | | const zcu = pt.zcu; |
| 3578 | const zcu = o.zcu; |
| 3630 | 3579 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3631 | 3580 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3632 | 3581 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3678,7 +3627,7 @@ fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo |
| 3678 | 3627 | } |
| 3679 | 3628 | |
| 3680 | 3629 | fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3681 | | const zcu = self.pt.zcu; |
| 3630 | const zcu = self.object.zcu; |
| 3682 | 3631 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 3683 | 3632 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3684 | 3633 | const ptr_or_slice = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -3694,8 +3643,7 @@ fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3694 | 3643 | |
| 3695 | 3644 | fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3696 | 3645 | const o = self.object; |
| 3697 | | const pt = self.pt; |
| 3698 | | const zcu = pt.zcu; |
| 3646 | const zcu = o.zcu; |
| 3699 | 3647 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 3700 | 3648 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3701 | 3649 | const ptr_or_slice = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -3718,8 +3666,7 @@ fn airOverflow( |
| 3718 | 3666 | signed_intrinsic: Builder.Intrinsic, |
| 3719 | 3667 | unsigned_intrinsic: Builder.Intrinsic, |
| 3720 | 3668 | ) Allocator.Error!Builder.Value { |
| 3721 | | const pt = self.pt; |
| 3722 | | const zcu = pt.zcu; |
| 3669 | const zcu = self.object.zcu; |
| 3723 | 3670 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 3724 | 3671 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3725 | 3672 | |
| ... | ... | @@ -3801,8 +3748,7 @@ fn buildFloatCmp( |
| 3801 | 3748 | params: [2]Builder.Value, |
| 3802 | 3749 | ) Allocator.Error!Builder.Value { |
| 3803 | 3750 | const o = self.object; |
| 3804 | | const pt = self.pt; |
| 3805 | | const zcu = pt.zcu; |
| 3751 | const zcu = o.zcu; |
| 3806 | 3752 | const target = zcu.getTarget(); |
| 3807 | 3753 | const scalar_ty = ty.scalarType(zcu); |
| 3808 | 3754 | const scalar_llvm_ty = try self.lowerType(scalar_ty); |
| ... | ... | @@ -3908,8 +3854,7 @@ fn buildFloatOp( |
| 3908 | 3854 | params: [params_len]Builder.Value, |
| 3909 | 3855 | ) Allocator.Error!Builder.Value { |
| 3910 | 3856 | const o = self.object; |
| 3911 | | const pt = self.pt; |
| 3912 | | const zcu = pt.zcu; |
| 3857 | const zcu = o.zcu; |
| 3913 | 3858 | const target = zcu.getTarget(); |
| 3914 | 3859 | const scalar_ty = ty.scalarType(zcu); |
| 3915 | 3860 | const llvm_ty = try self.lowerType(ty); |
| ... | ... | @@ -4049,8 +3994,7 @@ fn airMulAdd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4049 | 3994 | } |
| 4050 | 3995 | |
| 4051 | 3996 | fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4052 | | const pt = self.pt; |
| 4053 | | const zcu = pt.zcu; |
| 3997 | const zcu = self.object.zcu; |
| 4054 | 3998 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4055 | 3999 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4056 | 4000 | |
| ... | ... | @@ -4120,8 +4064,7 @@ fn airXor(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4120 | 4064 | } |
| 4121 | 4065 | |
| 4122 | 4066 | fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4123 | | const pt = self.pt; |
| 4124 | | const zcu = pt.zcu; |
| 4067 | const zcu = self.object.zcu; |
| 4125 | 4068 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4126 | 4069 | |
| 4127 | 4070 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4143,8 +4086,7 @@ fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 4143 | 4086 | } |
| 4144 | 4087 | |
| 4145 | 4088 | fn airShl(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4146 | | const pt = self.pt; |
| 4147 | | const zcu = pt.zcu; |
| 4089 | const zcu = self.object.zcu; |
| 4148 | 4090 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4149 | 4091 | |
| 4150 | 4092 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4162,8 +4104,7 @@ fn airShl(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4162 | 4104 | |
| 4163 | 4105 | fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4164 | 4106 | const o = self.object; |
| 4165 | | const pt = self.pt; |
| 4166 | | const zcu = pt.zcu; |
| 4107 | const zcu = o.zcu; |
| 4167 | 4108 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4168 | 4109 | |
| 4169 | 4110 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4244,8 +4185,7 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4244 | 4185 | } |
| 4245 | 4186 | |
| 4246 | 4187 | fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) Allocator.Error!Builder.Value { |
| 4247 | | const pt = self.pt; |
| 4248 | | const zcu = pt.zcu; |
| 4188 | const zcu = self.object.zcu; |
| 4249 | 4189 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4250 | 4190 | |
| 4251 | 4191 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4269,8 +4209,7 @@ fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) Allocator.Error! |
| 4269 | 4209 | |
| 4270 | 4210 | fn airAbs(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4271 | 4211 | const o = self.object; |
| 4272 | | const pt = self.pt; |
| 4273 | | const zcu = pt.zcu; |
| 4212 | const zcu = o.zcu; |
| 4274 | 4213 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4275 | 4214 | const operand = try self.resolveInst(ty_op.operand); |
| 4276 | 4215 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -4292,8 +4231,7 @@ fn airAbs(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4292 | 4231 | |
| 4293 | 4232 | fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!Builder.Value { |
| 4294 | 4233 | const o = fg.object; |
| 4295 | | const pt = fg.pt; |
| 4296 | | const zcu = pt.zcu; |
| 4234 | const zcu = o.zcu; |
| 4297 | 4235 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4298 | 4236 | const dest_ty = fg.typeOfIndex(inst); |
| 4299 | 4237 | const dest_llvm_ty = try fg.lowerType(dest_ty); |
| ... | ... | @@ -4379,7 +4317,7 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error! |
| 4379 | 4317 | }, operand, dest_llvm_ty, ""); |
| 4380 | 4318 | |
| 4381 | 4319 | if (safety and dest_is_enum and !dest_ty.isNonexhaustiveEnum(zcu)) { |
| 4382 | | const llvm_fn = try o.getIsNamedEnumValueFunction(pt, dest_ty); |
| 4320 | const llvm_fn = try o.getIsNamedEnumValueFunction(dest_ty); |
| 4383 | 4321 | const is_valid_enum_val = try fg.wip.call( |
| 4384 | 4322 | .normal, |
| 4385 | 4323 | .fastcc, |
| ... | ... | @@ -4409,8 +4347,7 @@ fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4409 | 4347 | |
| 4410 | 4348 | fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4411 | 4349 | const o = self.object; |
| 4412 | | const pt = self.pt; |
| 4413 | | const zcu = pt.zcu; |
| 4350 | const zcu = o.zcu; |
| 4414 | 4351 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4415 | 4352 | const operand = try self.resolveInst(ty_op.operand); |
| 4416 | 4353 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -4444,8 +4381,7 @@ fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 4444 | 4381 | |
| 4445 | 4382 | fn airFpext(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4446 | 4383 | const o = self.object; |
| 4447 | | const pt = self.pt; |
| 4448 | | const zcu = pt.zcu; |
| 4384 | const zcu = o.zcu; |
| 4449 | 4385 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4450 | 4386 | const operand = try self.resolveInst(ty_op.operand); |
| 4451 | 4387 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -4493,8 +4429,7 @@ fn airBitCast(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 4493 | 4429 | |
| 4494 | 4430 | fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) Allocator.Error!Builder.Value { |
| 4495 | 4431 | const o = self.object; |
| 4496 | | const pt = self.pt; |
| 4497 | | const zcu = pt.zcu; |
| 4432 | const zcu = o.zcu; |
| 4498 | 4433 | const operand_is_ref = isByRef(operand_ty, zcu); |
| 4499 | 4434 | const result_is_ref = isByRef(inst_ty, zcu); |
| 4500 | 4435 | const llvm_dest_ty = try self.lowerType(inst_ty); |
| ... | ... | @@ -4599,7 +4534,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty |
| 4599 | 4534 | fn airArg(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4600 | 4535 | const o = self.object; |
| 4601 | 4536 | const pt = self.pt; |
| 4602 | | const zcu = pt.zcu; |
| 4537 | const zcu = o.zcu; |
| 4603 | 4538 | const arg_val = self.args[self.arg_index]; |
| 4604 | 4539 | self.arg_index += 1; |
| 4605 | 4540 | |
| ... | ... | @@ -4688,13 +4623,13 @@ fn airArg(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4688 | 4623 | |
| 4689 | 4624 | fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4690 | 4625 | const o = self.object; |
| 4691 | | const pt = self.pt; |
| 4692 | | const zcu = pt.zcu; |
| 4626 | const zcu = o.zcu; |
| 4693 | 4627 | const ptr_ty = self.typeOfIndex(inst); |
| 4694 | 4628 | const pointee_type = ptr_ty.childType(zcu); |
| 4695 | | if (!pointee_type.hasRuntimeBits(zcu)) |
| 4696 | | return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue(); |
| 4697 | | |
| 4629 | if (!pointee_type.hasRuntimeBits(zcu)) { |
| 4630 | const ptr_info = ptr_ty.ptrInfo(zcu); |
| 4631 | return (try o.lowerPtrToVoid(ptr_info.flags.alignment, ptr_info.flags.address_space)).toValue(); |
| 4632 | } |
| 4698 | 4633 | const pointee_llvm_ty = try self.lowerType(pointee_type); |
| 4699 | 4634 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 4700 | 4635 | return self.buildAlloca(pointee_llvm_ty, alignment); |
| ... | ... | @@ -4702,12 +4637,13 @@ fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4702 | 4637 | |
| 4703 | 4638 | fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4704 | 4639 | const o = self.object; |
| 4705 | | const pt = self.pt; |
| 4706 | | const zcu = pt.zcu; |
| 4640 | const zcu = o.zcu; |
| 4707 | 4641 | const ptr_ty = self.typeOfIndex(inst); |
| 4708 | 4642 | const ret_ty = ptr_ty.childType(zcu); |
| 4709 | | if (!ret_ty.hasRuntimeBits(zcu)) |
| 4710 | | return (try o.lowerPtrToVoid(pt, ptr_ty)).toValue(); |
| 4643 | if (!ret_ty.hasRuntimeBits(zcu)) { |
| 4644 | const ptr_info = ptr_ty.ptrInfo(zcu); |
| 4645 | return (try o.lowerPtrToVoid(ptr_info.flags.alignment, ptr_info.flags.address_space)).toValue(); |
| 4646 | } |
| 4711 | 4647 | if (self.ret_ptr != .none) return self.ret_ptr; |
| 4712 | 4648 | const ret_llvm_ty = try self.lowerType(ret_ty); |
| 4713 | 4649 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| ... | ... | @@ -4721,20 +4657,19 @@ fn buildAlloca( |
| 4721 | 4657 | llvm_ty: Builder.Type, |
| 4722 | 4658 | alignment: Builder.Alignment, |
| 4723 | 4659 | ) Allocator.Error!Builder.Value { |
| 4724 | | const target = self.pt.zcu.getTarget(); |
| 4660 | const target = self.object.zcu.getTarget(); |
| 4725 | 4661 | return buildAllocaInner(&self.wip, llvm_ty, alignment, target); |
| 4726 | 4662 | } |
| 4727 | 4663 | |
| 4728 | 4664 | fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!Builder.Value { |
| 4729 | 4665 | const o = self.object; |
| 4730 | | const pt = self.pt; |
| 4731 | | const zcu = pt.zcu; |
| 4666 | const zcu = o.zcu; |
| 4732 | 4667 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4733 | 4668 | const dest_ptr = try self.resolveInst(bin_op.lhs); |
| 4734 | 4669 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 4735 | 4670 | const operand_ty = ptr_ty.childType(zcu); |
| 4736 | 4671 | |
| 4737 | | const val_is_undef = if (try self.air.value(bin_op.rhs, pt)) |val| val.isUndef(zcu) else false; |
| 4672 | const val_is_undef = if (bin_op.rhs.toInterned()) |i| Value.fromInterned(i).isUndef(zcu) else false; |
| 4738 | 4673 | if (val_is_undef) { |
| 4739 | 4674 | const owner_mod = self.ownerModule(); |
| 4740 | 4675 | |
| ... | ... | @@ -4762,7 +4697,7 @@ fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error! |
| 4762 | 4697 | |
| 4763 | 4698 | self.maybeMarkAllowZeroAccess(ptr_info); |
| 4764 | 4699 | |
| 4765 | | const len = try o.builder.intValue(try self.lowerType(Type.usize), operand_ty.abiSize(zcu)); |
| 4700 | const len = try o.builder.intValue(try self.lowerType(.usize), operand_ty.abiSize(zcu)); |
| 4766 | 4701 | _ = try self.wip.callMemSet( |
| 4767 | 4702 | dest_ptr, |
| 4768 | 4703 | ptr_ty.ptrAlignment(zcu).toLlvm(), |
| ... | ... | @@ -4780,24 +4715,75 @@ fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error! |
| 4780 | 4715 | self.maybeMarkAllowZeroAccess(ptr_ty.ptrInfo(zcu)); |
| 4781 | 4716 | |
| 4782 | 4717 | const src_operand = try self.resolveInst(bin_op.rhs); |
| 4783 | | try self.store(dest_ptr, ptr_ty, src_operand, .none); |
| 4718 | try self.storeFull(dest_ptr, ptr_ty, src_operand, .none); |
| 4784 | 4719 | return .none; |
| 4785 | 4720 | } |
| 4786 | 4721 | |
| 4787 | 4722 | fn airLoad(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4788 | | const pt = fg.pt; |
| 4789 | | const zcu = pt.zcu; |
| 4723 | const o = fg.object; |
| 4724 | const zcu = o.zcu; |
| 4790 | 4725 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4791 | 4726 | const ptr_ty = fg.typeOf(ty_op.operand); |
| 4792 | 4727 | const ptr_info = ptr_ty.ptrInfo(zcu); |
| 4793 | 4728 | const ptr = try fg.resolveInst(ty_op.operand); |
| 4729 | const elem_ty = ptr_ty.childType(zcu); |
| 4730 | const llvm_ptr_align = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 4731 | |
| 4794 | 4732 | fg.maybeMarkAllowZeroAccess(ptr_info); |
| 4795 | | return fg.load(ptr, ptr_ty); |
| 4733 | |
| 4734 | const access_kind: Builder.MemoryAccessKind = |
| 4735 | if (ptr_info.flags.is_volatile) .@"volatile" else .normal; |
| 4736 | |
| 4737 | if (ptr_info.flags.vector_index != .none) { |
| 4738 | const index_u32 = try o.builder.intValue(.i32, ptr_info.flags.vector_index); |
| 4739 | const vec_elem_ty = try fg.lowerType(elem_ty); |
| 4740 | const vec_ty = try o.builder.vectorType(.normal, ptr_info.packed_offset.host_size, vec_elem_ty); |
| 4741 | |
| 4742 | const loaded_vector = try fg.wip.load(access_kind, vec_ty, ptr, llvm_ptr_align, ""); |
| 4743 | return fg.wip.extractElement(loaded_vector, index_u32, ""); |
| 4744 | } |
| 4745 | |
| 4746 | if (ptr_info.packed_offset.host_size == 0) { |
| 4747 | return fg.load(ptr, elem_ty, llvm_ptr_align, access_kind); |
| 4748 | } |
| 4749 | |
| 4750 | const containing_int_ty = try o.builder.intType(@intCast(ptr_info.packed_offset.host_size * 8)); |
| 4751 | const containing_int = |
| 4752 | try fg.wip.load(access_kind, containing_int_ty, ptr, llvm_ptr_align, ""); |
| 4753 | |
| 4754 | const elem_bits = ptr_ty.childType(zcu).bitSize(zcu); |
| 4755 | const shift_amt = try o.builder.intValue(containing_int_ty, ptr_info.packed_offset.bit_offset); |
| 4756 | const shifted_value = try fg.wip.bin(.lshr, containing_int, shift_amt, ""); |
| 4757 | const elem_llvm_ty = try fg.lowerType(elem_ty); |
| 4758 | |
| 4759 | if (isByRef(elem_ty, zcu)) { |
| 4760 | const result_align = elem_ty.abiAlignment(zcu).toLlvm(); |
| 4761 | const result_ptr = try fg.buildAlloca(elem_llvm_ty, result_align); |
| 4762 | |
| 4763 | const same_size_int = try o.builder.intType(@intCast(elem_bits)); |
| 4764 | const truncated_int = try fg.wip.cast(.trunc, shifted_value, same_size_int, ""); |
| 4765 | _ = try fg.wip.store(.normal, truncated_int, result_ptr, result_align); |
| 4766 | return result_ptr; |
| 4767 | } |
| 4768 | |
| 4769 | if (elem_ty.zigTypeTag(zcu) == .float or elem_ty.zigTypeTag(zcu) == .vector) { |
| 4770 | const same_size_int = try o.builder.intType(@intCast(elem_bits)); |
| 4771 | const truncated_int = try fg.wip.cast(.trunc, shifted_value, same_size_int, ""); |
| 4772 | return fg.wip.cast(.bitcast, truncated_int, elem_llvm_ty, ""); |
| 4773 | } |
| 4774 | |
| 4775 | if (elem_ty.isPtrAtRuntime(zcu)) { |
| 4776 | const same_size_int = try o.builder.intType(@intCast(elem_bits)); |
| 4777 | const truncated_int = try fg.wip.cast(.trunc, shifted_value, same_size_int, ""); |
| 4778 | return fg.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, ""); |
| 4779 | } |
| 4780 | |
| 4781 | return fg.wip.cast(.trunc, shifted_value, elem_llvm_ty, ""); |
| 4796 | 4782 | } |
| 4797 | 4783 | |
| 4798 | 4784 | fn airTrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!void { |
| 4799 | 4785 | _ = inst; |
| 4800 | | const target = self.pt.zcu.getTarget(); |
| 4786 | const target = self.object.zcu.getTarget(); |
| 4801 | 4787 | if ((target.cpu.arch == .mips or target.cpu.arch == .mipsel) and |
| 4802 | 4788 | target.cpu.has(.mips, .notraps)) |
| 4803 | 4789 | { |
| ... | ... | @@ -4828,8 +4814,8 @@ fn airBreakpoint(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.V |
| 4828 | 4814 | fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4829 | 4815 | _ = inst; |
| 4830 | 4816 | const o = self.object; |
| 4831 | | const llvm_usize = try self.lowerType(Type.usize); |
| 4832 | | if (!target_util.supportsReturnAddress(self.pt.zcu.getTarget(), self.ownerModule().optimize_mode)) { |
| 4817 | const llvm_usize = try self.lowerType(.usize); |
| 4818 | if (!target_util.supportsReturnAddress(self.object.zcu.getTarget(), self.ownerModule().optimize_mode)) { |
| 4833 | 4819 | // https://github.com/ziglang/zig/issues/11946 |
| 4834 | 4820 | return o.builder.intValue(llvm_usize, 0); |
| 4835 | 4821 | } |
| ... | ... | @@ -4840,7 +4826,7 @@ fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 4840 | 4826 | fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4841 | 4827 | _ = inst; |
| 4842 | 4828 | const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, ""); |
| 4843 | | return self.wip.cast(.ptrtoint, result, try self.lowerType(Type.usize), ""); |
| 4829 | return self.wip.cast(.ptrtoint, result, try self.lowerType(.usize), ""); |
| 4844 | 4830 | } |
| 4845 | 4831 | |
| 4846 | 4832 | fn airCmpxchg( |
| ... | ... | @@ -4849,8 +4835,7 @@ fn airCmpxchg( |
| 4849 | 4835 | kind: Builder.Function.Instruction.CmpXchg.Kind, |
| 4850 | 4836 | ) Allocator.Error!Builder.Value { |
| 4851 | 4837 | const o = self.object; |
| 4852 | | const pt = self.pt; |
| 4853 | | const zcu = pt.zcu; |
| 4838 | const zcu = o.zcu; |
| 4854 | 4839 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4855 | 4840 | const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 4856 | 4841 | const ptr = try self.resolveInst(extra.ptr); |
| ... | ... | @@ -4915,8 +4900,7 @@ fn airCmpxchg( |
| 4915 | 4900 | |
| 4916 | 4901 | fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4917 | 4902 | const o = self.object; |
| 4918 | | const pt = self.pt; |
| 4919 | | const zcu = pt.zcu; |
| 4903 | const zcu = o.zcu; |
| 4920 | 4904 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 4921 | 4905 | const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 4922 | 4906 | const ptr = try self.resolveInst(pl_op.operand); |
| ... | ... | @@ -4971,7 +4955,7 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va |
| 4971 | 4955 | access_kind, |
| 4972 | 4956 | op, |
| 4973 | 4957 | ptr, |
| 4974 | | try self.wip.cast(.ptrtoint, operand, try self.lowerType(Type.usize), ""), |
| 4958 | try self.wip.cast(.ptrtoint, operand, try self.lowerType(.usize), ""), |
| 4975 | 4959 | self.sync_scope, |
| 4976 | 4960 | ordering, |
| 4977 | 4961 | ptr_alignment, |
| ... | ... | @@ -4980,8 +4964,7 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va |
| 4980 | 4964 | } |
| 4981 | 4965 | |
| 4982 | 4966 | fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4983 | | const pt = self.pt; |
| 4984 | | const zcu = pt.zcu; |
| 4967 | const zcu = self.object.zcu; |
| 4985 | 4968 | const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; |
| 4986 | 4969 | const ptr = try self.resolveInst(atomic_load.ptr); |
| 4987 | 4970 | const ptr_ty = self.typeOf(atomic_load.ptr); |
| ... | ... | @@ -5029,8 +5012,7 @@ fn airAtomicStore( |
| 5029 | 5012 | inst: Air.Inst.Index, |
| 5030 | 5013 | ordering: Builder.AtomicOrdering, |
| 5031 | 5014 | ) Allocator.Error!Builder.Value { |
| 5032 | | const pt = self.pt; |
| 5033 | | const zcu = pt.zcu; |
| 5015 | const zcu = self.object.zcu; |
| 5034 | 5016 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 5035 | 5017 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 5036 | 5018 | const operand_ty = ptr_ty.childType(zcu); |
| ... | ... | @@ -5051,14 +5033,13 @@ fn airAtomicStore( |
| 5051 | 5033 | |
| 5052 | 5034 | self.maybeMarkAllowZeroAccess(ptr_ty.ptrInfo(zcu)); |
| 5053 | 5035 | |
| 5054 | | try self.store(ptr, ptr_ty, element, ordering); |
| 5036 | try self.storeFull(ptr, ptr_ty, element, ordering); |
| 5055 | 5037 | return .none; |
| 5056 | 5038 | } |
| 5057 | 5039 | |
| 5058 | 5040 | fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!Builder.Value { |
| 5059 | 5041 | const o = self.object; |
| 5060 | | const pt = self.pt; |
| 5061 | | const zcu = pt.zcu; |
| 5042 | const zcu = o.zcu; |
| 5062 | 5043 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 5063 | 5044 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| 5064 | 5045 | const ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -5070,7 +5051,8 @@ fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error |
| 5070 | 5051 | |
| 5071 | 5052 | self.maybeMarkAllowZeroAccess(ptr_ty.ptrInfo(zcu)); |
| 5072 | 5053 | |
| 5073 | | if (try self.air.value(bin_op.rhs, pt)) |elem_val| { |
| 5054 | if (bin_op.rhs.toInterned()) |elem_ip_index| { |
| 5055 | const elem_val: Value = .fromInterned(elem_ip_index); |
| 5074 | 5056 | if (elem_val.isUndef(zcu)) { |
| 5075 | 5057 | // Even if safety is disabled, we still emit a memset to undefined since it conveys |
| 5076 | 5058 | // extra information to LLVM. However, safety makes the difference between using |
| ... | ... | @@ -5099,7 +5081,7 @@ fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error |
| 5099 | 5081 | // repeating byte pattern, for example, `@as(u64, 0)` has a |
| 5100 | 5082 | // repeating byte pattern of 0 bytes. In such case, the memset |
| 5101 | 5083 | // intrinsic can be used. |
| 5102 | | if (try elem_val.hasRepeatedByteRepr(pt)) |byte_val| { |
| 5084 | if (try elem_val.hasRepeatedByteRepr(zcu)) |byte_val| { |
| 5103 | 5085 | const fill_byte = try o.builder.intValue(.i8, byte_val); |
| 5104 | 5086 | const len = try self.sliceOrArrayLenInBytes(dest_slice, ptr_ty); |
| 5105 | 5087 | _ = try self.wip.callMemSet( |
| ... | ... | @@ -5154,7 +5136,7 @@ fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error |
| 5154 | 5136 | const body_block = try self.wip.block(1, "InlineMemsetBody"); |
| 5155 | 5137 | const end_block = try self.wip.block(1, "InlineMemsetEnd"); |
| 5156 | 5138 | |
| 5157 | | const llvm_usize_ty = try self.lowerType(Type.usize); |
| 5139 | const llvm_usize_ty = try self.lowerType(.usize); |
| 5158 | 5140 | const end_ptr = switch (ptr_ty.ptrSize(zcu)) { |
| 5159 | 5141 | .slice => try self.ptraddScaled( |
| 5160 | 5142 | dest_ptr, |
| ... | ... | @@ -5194,8 +5176,7 @@ fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error |
| 5194 | 5176 | } |
| 5195 | 5177 | |
| 5196 | 5178 | fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5197 | | const pt = self.pt; |
| 5198 | | const zcu = pt.zcu; |
| 5179 | const zcu = self.object.zcu; |
| 5199 | 5180 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 5200 | 5181 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| 5201 | 5182 | const dest_ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -5223,8 +5204,7 @@ fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 5223 | 5204 | } |
| 5224 | 5205 | |
| 5225 | 5206 | fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5226 | | const pt = self.pt; |
| 5227 | | const zcu = pt.zcu; |
| 5207 | const zcu = self.object.zcu; |
| 5228 | 5208 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 5229 | 5209 | const dest_slice = try self.resolveInst(bin_op.lhs); |
| 5230 | 5210 | const dest_ptr_ty = self.typeOf(bin_op.lhs); |
| ... | ... | @@ -5248,8 +5228,7 @@ fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 5248 | 5228 | } |
| 5249 | 5229 | |
| 5250 | 5230 | fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5251 | | const pt = self.pt; |
| 5252 | | const zcu = pt.zcu; |
| 5231 | const zcu = self.object.zcu; |
| 5253 | 5232 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 5254 | 5233 | const un_ptr_ty = self.typeOf(bin_op.lhs); |
| 5255 | 5234 | const un_ty = un_ptr_ty.childType(zcu); |
| ... | ... | @@ -5280,8 +5259,7 @@ fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder. |
| 5280 | 5259 | |
| 5281 | 5260 | fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5282 | 5261 | const o = self.object; |
| 5283 | | const pt = self.pt; |
| 5284 | | const zcu = pt.zcu; |
| 5262 | const zcu = o.zcu; |
| 5285 | 5263 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5286 | 5264 | const un_ty = self.typeOf(ty_op.operand); |
| 5287 | 5265 | const layout = un_ty.unionGetLayout(zcu); |
| ... | ... | @@ -5354,8 +5332,7 @@ fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) |
| 5354 | 5332 | |
| 5355 | 5333 | fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5356 | 5334 | const o = self.object; |
| 5357 | | const pt = self.pt; |
| 5358 | | const zcu = pt.zcu; |
| 5335 | const zcu = o.zcu; |
| 5359 | 5336 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5360 | 5337 | const operand_ty = self.typeOf(ty_op.operand); |
| 5361 | 5338 | var bits = operand_ty.intInfo(zcu).bits; |
| ... | ... | @@ -5389,8 +5366,7 @@ fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 5389 | 5366 | |
| 5390 | 5367 | fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5391 | 5368 | const o = self.object; |
| 5392 | | const pt = self.pt; |
| 5393 | | const zcu = pt.zcu; |
| 5369 | const zcu = o.zcu; |
| 5394 | 5370 | const ip = &zcu.intern_pool; |
| 5395 | 5371 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5396 | 5372 | const operand = try self.resolveInst(ty_op.operand); |
| ... | ... | @@ -5426,7 +5402,7 @@ fn airIsNamedEnumValue(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Bui |
| 5426 | 5402 | const operand = try self.resolveInst(un_op); |
| 5427 | 5403 | const enum_ty = self.typeOf(un_op); |
| 5428 | 5404 | |
| 5429 | | const llvm_fn = try o.getIsNamedEnumValueFunction(self.pt, enum_ty); |
| 5405 | const llvm_fn = try o.getIsNamedEnumValueFunction(enum_ty); |
| 5430 | 5406 | return self.wip.call( |
| 5431 | 5407 | .normal, |
| 5432 | 5408 | .fastcc, |
| ... | ... | @@ -5440,12 +5416,11 @@ fn airIsNamedEnumValue(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Bui |
| 5440 | 5416 | |
| 5441 | 5417 | fn airTagName(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5442 | 5418 | const o = self.object; |
| 5443 | | const pt = self.pt; |
| 5444 | 5419 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5445 | 5420 | const operand = try self.resolveInst(un_op); |
| 5446 | 5421 | const enum_ty = self.typeOf(un_op); |
| 5447 | 5422 | |
| 5448 | | const llvm_fn = try o.getEnumTagNameFunction(pt, enum_ty); |
| 5423 | const llvm_fn = try o.getEnumTagNameFunction(enum_ty); |
| 5449 | 5424 | return self.wip.call( |
| 5450 | 5425 | .normal, |
| 5451 | 5426 | .fastcc, |
| ... | ... | @@ -5459,8 +5434,7 @@ fn airTagName(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 5459 | 5434 | |
| 5460 | 5435 | fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5461 | 5436 | const o = self.object; |
| 5462 | | const pt = self.pt; |
| 5463 | | const zcu = pt.zcu; |
| 5437 | const zcu = o.zcu; |
| 5464 | 5438 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5465 | 5439 | const operand = try self.resolveInst(un_op); |
| 5466 | 5440 | const slice_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -5493,8 +5467,7 @@ fn airSelect(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 5493 | 5467 | |
| 5494 | 5468 | fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5495 | 5469 | const o = fg.object; |
| 5496 | | const pt = fg.pt; |
| 5497 | | const zcu = pt.zcu; |
| 5470 | const zcu = o.zcu; |
| 5498 | 5471 | const gpa = zcu.gpa; |
| 5499 | 5472 | |
| 5500 | 5473 | const unwrapped = fg.air.unwrapShuffleOne(zcu, inst); |
| ... | ... | @@ -5534,7 +5507,7 @@ fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 5534 | 5507 | .elem => llvm_poison_elem, |
| 5535 | 5508 | .value => |val| if (!Value.fromInterned(val).isUndef(zcu)) elem: { |
| 5536 | 5509 | any_defined_comptime_value = true; |
| 5537 | | break :elem try o.lowerValue(pt, val); |
| 5510 | break :elem try o.lowerValue(val); |
| 5538 | 5511 | } else llvm_poison_elem, |
| 5539 | 5512 | }; |
| 5540 | 5513 | } |
| ... | ... | @@ -5600,8 +5573,7 @@ fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 5600 | 5573 | |
| 5601 | 5574 | fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5602 | 5575 | const o = fg.object; |
| 5603 | | const pt = fg.pt; |
| 5604 | | const zcu = pt.zcu; |
| 5576 | const zcu = o.zcu; |
| 5605 | 5577 | const gpa = zcu.gpa; |
| 5606 | 5578 | |
| 5607 | 5579 | const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst); |
| ... | ... | @@ -5699,7 +5671,7 @@ fn buildReducedCall( |
| 5699 | 5671 | accum_init: Builder.Value, |
| 5700 | 5672 | ) Allocator.Error!Builder.Value { |
| 5701 | 5673 | const o = self.object; |
| 5702 | | const usize_ty = try self.lowerType(Type.usize); |
| 5674 | const usize_ty = try self.lowerType(.usize); |
| 5703 | 5675 | const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len); |
| 5704 | 5676 | const llvm_result_ty = accum_init.typeOfWip(&self.wip); |
| 5705 | 5677 | |
| ... | ... | @@ -5753,8 +5725,7 @@ fn buildReducedCall( |
| 5753 | 5725 | |
| 5754 | 5726 | fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| 5755 | 5727 | const o = self.object; |
| 5756 | | const pt = self.pt; |
| 5757 | | const zcu = pt.zcu; |
| 5728 | const zcu = o.zcu; |
| 5758 | 5729 | const target = zcu.getTarget(); |
| 5759 | 5730 | |
| 5760 | 5731 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; |
| ... | ... | @@ -5863,8 +5834,7 @@ fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) A |
| 5863 | 5834 | |
| 5864 | 5835 | fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5865 | 5836 | const o = self.object; |
| 5866 | | const pt = self.pt; |
| 5867 | | const zcu = pt.zcu; |
| 5837 | const zcu = o.zcu; |
| 5868 | 5838 | const ip = &zcu.intern_pool; |
| 5869 | 5839 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 5870 | 5840 | const result_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -5960,19 +5930,18 @@ fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde |
| 5960 | 5930 | const alloca_inst = try self.buildAlloca(llvm_result_ty, alignment); |
| 5961 | 5931 | |
| 5962 | 5932 | const array_info = result_ty.arrayInfo(zcu); |
| 5963 | | const elem_ptr_ty = try pt.singleConstPtrType(array_info.elem_type); |
| 5964 | 5933 | |
| 5965 | 5934 | const elem_size = array_info.elem_type.abiSize(zcu); |
| 5966 | 5935 | |
| 5967 | 5936 | for (elements, 0..) |elem, i| { |
| 5968 | 5937 | const elem_ptr = try self.ptraddConst(alloca_inst, elem_size * i); |
| 5969 | 5938 | const llvm_elem = try self.resolveInst(elem); |
| 5970 | | try self.store(elem_ptr, elem_ptr_ty, llvm_elem, .none); |
| 5939 | try self.store(elem_ptr, .none, llvm_elem, array_info.elem_type); |
| 5971 | 5940 | } |
| 5972 | 5941 | if (array_info.sentinel) |sent_val| { |
| 5973 | 5942 | const elem_ptr = try self.ptraddConst(alloca_inst, elem_size * array_info.len); |
| 5974 | 5943 | const llvm_elem = try self.resolveValue(sent_val); |
| 5975 | | try self.store(elem_ptr, elem_ptr_ty, llvm_elem.toValue(), .none); |
| 5944 | try self.store(elem_ptr, .none, llvm_elem.toValue(), array_info.elem_type); |
| 5976 | 5945 | } |
| 5977 | 5946 | |
| 5978 | 5947 | return alloca_inst; |
| ... | ... | @@ -5983,8 +5952,7 @@ fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde |
| 5983 | 5952 | |
| 5984 | 5953 | fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 5985 | 5954 | const o = self.object; |
| 5986 | | const pt = self.pt; |
| 5987 | | const zcu = pt.zcu; |
| 5955 | const zcu = o.zcu; |
| 5988 | 5956 | const ip = &zcu.intern_pool; |
| 5989 | 5957 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 5990 | 5958 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| ... | ... | @@ -6006,18 +5974,19 @@ fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va |
| 6006 | 5974 | assert(field_ty.hasRuntimeBits(zcu)); |
| 6007 | 5975 | |
| 6008 | 5976 | { |
| 6009 | | const payload_ptr_ty = try pt.ptrType(.{ |
| 6010 | | .child = field_ty.toIntern(), |
| 6011 | | .flags = .{ .alignment = layout.payload_align }, |
| 6012 | | }); |
| 6013 | 5977 | const payload_ptr = try self.ptraddConst(result_ptr, layout.payloadOffset()); |
| 6014 | | try self.store(payload_ptr, payload_ptr_ty, llvm_payload, .none); |
| 5978 | try self.store(payload_ptr, layout.payload_align, llvm_payload, field_ty); |
| 6015 | 5979 | } |
| 6016 | 5980 | |
| 6017 | 5981 | if (layout.tag_size != 0) { |
| 6018 | | const tag_ty: Type = .fromInterned(union_obj.enum_tag_type); |
| 6019 | | const tag_val = try pt.enumValueFieldIndex(tag_ty, extra.field_index); |
| 6020 | | const llvm_tag_val = try o.lowerValue(pt, tag_val.toIntern()); |
| 5982 | const loaded_enum = ip.loadEnumType(union_obj.enum_tag_type); |
| 5983 | const llvm_tag_val = switch (loaded_enum.field_values.getOrNone(ip, extra.field_index)) { |
| 5984 | .none => try o.builder.intConst( |
| 5985 | try o.lowerType(.fromInterned(union_obj.enum_tag_type)), |
| 5986 | extra.field_index, // auto-numbered |
| 5987 | ), |
| 5988 | else => |tag_val_ip| try o.lowerValue(tag_val_ip), |
| 5989 | }; |
| 6021 | 5990 | const tag_ptr = try self.ptraddConst(result_ptr, layout.tagOffset()); |
| 6022 | 5991 | _ = try self.wip.store(.normal, llvm_tag_val.toValue(), tag_ptr, layout.tag_align.toLlvm()); |
| 6023 | 5992 | } |
| ... | ... | @@ -6043,7 +6012,7 @@ fn airPrefetch(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 6043 | 6012 | // by the target. |
| 6044 | 6013 | // To work around this, don't emit llvm.prefetch in this case. |
| 6045 | 6014 | // See https://bugs.llvm.org/show_bug.cgi?id=21037 |
| 6046 | | const zcu = self.pt.zcu; |
| 6015 | const zcu = self.object.zcu; |
| 6047 | 6016 | const target = zcu.getTarget(); |
| 6048 | 6017 | switch (prefetch.cache) { |
| 6049 | 6018 | .instruction => switch (target.cpu.arch) { |
| ... | ... | @@ -6097,7 +6066,7 @@ fn workIntrinsic( |
| 6097 | 6066 | } |
| 6098 | 6067 | |
| 6099 | 6068 | fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 6100 | | const target = self.pt.zcu.getTarget(); |
| 6069 | const target = self.object.zcu.getTarget(); |
| 6101 | 6070 | |
| 6102 | 6071 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 6103 | 6072 | const dimension = pl_op.payload; |
| ... | ... | @@ -6110,8 +6079,7 @@ fn airWorkItemId(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.V |
| 6110 | 6079 | } |
| 6111 | 6080 | |
| 6112 | 6081 | fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 6113 | | const pt = self.pt; |
| 6114 | | const target = pt.zcu.getTarget(); |
| 6082 | const target = self.object.zcu.getTarget(); |
| 6115 | 6083 | |
| 6116 | 6084 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 6117 | 6085 | const dimension = pl_op.payload; |
| ... | ... | @@ -6138,7 +6106,7 @@ fn airWorkGroupSize(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde |
| 6138 | 6106 | } |
| 6139 | 6107 | |
| 6140 | 6108 | fn airWorkGroupId(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 6141 | | const target = self.pt.zcu.getTarget(); |
| 6109 | const target = self.object.zcu.getTarget(); |
| 6142 | 6110 | |
| 6143 | 6111 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 6144 | 6112 | const dimension = pl_op.payload; |
| ... | ... | @@ -6158,7 +6126,7 @@ fn optCmpNull( |
| 6158 | 6126 | opt_ptr: Builder.Value, |
| 6159 | 6127 | access_kind: Builder.MemoryAccessKind, |
| 6160 | 6128 | ) Allocator.Error!Builder.Value { |
| 6161 | | const zcu = self.pt.zcu; |
| 6129 | const zcu = self.object.zcu; |
| 6162 | 6130 | assert(isByRef(opt_ty, zcu)); |
| 6163 | 6131 | comptime assert(optional_layout_version == 3); |
| 6164 | 6132 | // Non-null bit is always after the payload, with no padding because it has alignment 1. |
| ... | ... | @@ -6174,8 +6142,7 @@ fn optPayloadHandle( |
| 6174 | 6142 | opt_ty: Type, |
| 6175 | 6143 | can_elide_load: bool, |
| 6176 | 6144 | ) Allocator.Error!Builder.Value { |
| 6177 | | const pt = fg.pt; |
| 6178 | | const zcu = pt.zcu; |
| 6145 | const zcu = fg.object.zcu; |
| 6179 | 6146 | assert(isByRef(opt_ty, zcu)); |
| 6180 | 6147 | const payload_ty = opt_ty.optionalChild(zcu); |
| 6181 | 6148 | |
| ... | ... | @@ -6197,8 +6164,7 @@ fn fieldPtr( |
| 6197 | 6164 | aggregate_ptr_ty: Type, |
| 6198 | 6165 | field_index: u32, |
| 6199 | 6166 | ) Allocator.Error!Builder.Value { |
| 6200 | | const pt = self.pt; |
| 6201 | | const zcu = pt.zcu; |
| 6167 | const zcu = self.object.zcu; |
| 6202 | 6168 | const aggregate_ty = aggregate_ptr_ty.childType(zcu); |
| 6203 | 6169 | if (aggregate_ty.containerLayout(zcu) == .@"packed") { |
| 6204 | 6170 | // A pointer to a bitpack field is equivalent to a pointer to the whole bitpack; the |
| ... | ... | @@ -6226,8 +6192,7 @@ fn loadTruncate( |
| 6226 | 6192 | // => so load the byte aligned value and trunc the unwanted bits. |
| 6227 | 6193 | |
| 6228 | 6194 | const o = fg.object; |
| 6229 | | const pt = fg.pt; |
| 6230 | | const zcu = pt.zcu; |
| 6195 | const zcu = o.zcu; |
| 6231 | 6196 | const payload_llvm_ty = try fg.lowerType(payload_ty); |
| 6232 | 6197 | const abi_size = payload_ty.abiSize(zcu); |
| 6233 | 6198 | |
| ... | ... | @@ -6256,12 +6221,11 @@ fn loadByRef( |
| 6256 | 6221 | access_kind: Builder.MemoryAccessKind, |
| 6257 | 6222 | ) Allocator.Error!Builder.Value { |
| 6258 | 6223 | const o = fg.object; |
| 6259 | | const pt = fg.pt; |
| 6260 | 6224 | const pointee_llvm_ty = try fg.lowerType(pointee_type); |
| 6261 | 6225 | const result_align = InternPool.Alignment.fromLlvm(ptr_alignment) |
| 6262 | | .max(pointee_type.abiAlignment(pt.zcu)).toLlvm(); |
| 6226 | .max(pointee_type.abiAlignment(o.zcu)).toLlvm(); |
| 6263 | 6227 | const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align); |
| 6264 | | const size_bytes = pointee_type.abiSize(pt.zcu); |
| 6228 | const size_bytes = pointee_type.abiSize(o.zcu); |
| 6265 | 6229 | _ = try fg.wip.callMemCpy( |
| 6266 | 6230 | result_ptr, |
| 6267 | 6231 | result_align, |
| ... | ... | @@ -6274,76 +6238,24 @@ fn loadByRef( |
| 6274 | 6238 | return result_ptr; |
| 6275 | 6239 | } |
| 6276 | 6240 | |
| 6277 | | /// This function always performs a copy. For isByRef=true types, it creates a new |
| 6278 | | /// alloca and copies the value into it, then returns the alloca instruction. |
| 6279 | | /// For isByRef=false types, it creates a load instruction and returns it. |
| 6280 | | fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) Allocator.Error!Builder.Value { |
| 6281 | | const o = self.object; |
| 6282 | | const pt = self.pt; |
| 6283 | | const zcu = pt.zcu; |
| 6284 | | const info = ptr_ty.ptrInfo(zcu); |
| 6285 | | const elem_ty = Type.fromInterned(info.child); |
| 6286 | | if (!elem_ty.hasRuntimeBits(zcu)) return .none; |
| 6287 | | |
| 6288 | | const ptr_alignment = (if (info.flags.alignment != .none) |
| 6289 | | @as(InternPool.Alignment, info.flags.alignment) |
| 6290 | | else |
| 6291 | | elem_ty.abiAlignment(zcu)).toLlvm(); |
| 6292 | | |
| 6293 | | const access_kind: Builder.MemoryAccessKind = |
| 6294 | | if (info.flags.is_volatile) .@"volatile" else .normal; |
| 6295 | | |
| 6296 | | if (info.flags.vector_index != .none) { |
| 6297 | | const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index); |
| 6298 | | const vec_elem_ty = try self.lowerType(elem_ty); |
| 6299 | | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); |
| 6300 | | |
| 6301 | | const loaded_vector = try self.wip.load(access_kind, vec_ty, ptr, ptr_alignment, ""); |
| 6302 | | return self.wip.extractElement(loaded_vector, index_u32, ""); |
| 6303 | | } |
| 6304 | | |
| 6305 | | if (info.packed_offset.host_size == 0) { |
| 6306 | | if (isByRef(elem_ty, zcu)) { |
| 6307 | | return self.loadByRef(ptr, elem_ty, ptr_alignment, access_kind); |
| 6308 | | } |
| 6309 | | return self.loadTruncate(access_kind, elem_ty, ptr, ptr_alignment); |
| 6310 | | } |
| 6311 | | |
| 6312 | | const containing_int_ty = try o.builder.intType(@intCast(info.packed_offset.host_size * 8)); |
| 6313 | | const containing_int = |
| 6314 | | try self.wip.load(access_kind, containing_int_ty, ptr, ptr_alignment, ""); |
| 6315 | | |
| 6316 | | const elem_bits = ptr_ty.childType(zcu).bitSize(zcu); |
| 6317 | | const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset); |
| 6318 | | const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, ""); |
| 6319 | | const elem_llvm_ty = try self.lowerType(elem_ty); |
| 6320 | | |
| 6241 | /// If `isByRef` returns `true` for `elem_ty`, this still performs a copy by memcpy'ing the value |
| 6242 | /// into a new alloca. |
| 6243 | fn load( |
| 6244 | fg: *FuncGen, |
| 6245 | ptr: Builder.Value, |
| 6246 | elem_ty: Type, |
| 6247 | ptr_alignment: Builder.Alignment, |
| 6248 | access_kind: Builder.MemoryAccessKind, |
| 6249 | ) Allocator.Error!Builder.Value { |
| 6250 | const zcu = fg.object.zcu; |
| 6321 | 6251 | if (isByRef(elem_ty, zcu)) { |
| 6322 | | const result_align = elem_ty.abiAlignment(zcu).toLlvm(); |
| 6323 | | const result_ptr = try self.buildAlloca(elem_llvm_ty, result_align); |
| 6324 | | |
| 6325 | | const same_size_int = try o.builder.intType(@intCast(elem_bits)); |
| 6326 | | const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, ""); |
| 6327 | | _ = try self.wip.store(.normal, truncated_int, result_ptr, result_align); |
| 6328 | | return result_ptr; |
| 6329 | | } |
| 6330 | | |
| 6331 | | if (elem_ty.zigTypeTag(zcu) == .float or elem_ty.zigTypeTag(zcu) == .vector) { |
| 6332 | | const same_size_int = try o.builder.intType(@intCast(elem_bits)); |
| 6333 | | const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, ""); |
| 6334 | | return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, ""); |
| 6335 | | } |
| 6336 | | |
| 6337 | | if (elem_ty.isPtrAtRuntime(zcu)) { |
| 6338 | | const same_size_int = try o.builder.intType(@intCast(elem_bits)); |
| 6339 | | const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, ""); |
| 6340 | | return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, ""); |
| 6252 | return fg.loadByRef(ptr, elem_ty, ptr_alignment, access_kind); |
| 6253 | } else { |
| 6254 | return fg.loadTruncate(access_kind, elem_ty, ptr, ptr_alignment); |
| 6341 | 6255 | } |
| 6342 | | |
| 6343 | | return self.wip.cast(.trunc, shifted_value, elem_llvm_ty, ""); |
| 6344 | 6256 | } |
| 6345 | 6257 | |
| 6346 | | fn store( |
| 6258 | fn storeFull( |
| 6347 | 6259 | self: *FuncGen, |
| 6348 | 6260 | ptr: Builder.Value, |
| 6349 | 6261 | ptr_ty: Type, |
| ... | ... | @@ -6351,8 +6263,7 @@ fn store( |
| 6351 | 6263 | ordering: Builder.AtomicOrdering, |
| 6352 | 6264 | ) Allocator.Error!void { |
| 6353 | 6265 | const o = self.object; |
| 6354 | | const pt = self.pt; |
| 6355 | | const zcu = pt.zcu; |
| 6266 | const zcu = o.zcu; |
| 6356 | 6267 | const info = ptr_ty.ptrInfo(zcu); |
| 6357 | 6268 | const elem_ty = Type.fromInterned(info.child); |
| 6358 | 6269 | if (!elem_ty.hasRuntimeBits(zcu)) { |
| ... | ... | @@ -6433,12 +6344,51 @@ fn store( |
| 6433 | 6344 | ptr_alignment, |
| 6434 | 6345 | elem, |
| 6435 | 6346 | elem_ty.abiAlignment(zcu).toLlvm(), |
| 6436 | | try o.builder.intValue(try self.lowerType(Type.usize), elem_ty.abiSize(zcu)), |
| 6347 | try o.builder.intValue(try self.lowerType(.usize), elem_ty.abiSize(zcu)), |
| 6437 | 6348 | access_kind, |
| 6438 | 6349 | self.disable_intrinsics, |
| 6439 | 6350 | ); |
| 6440 | 6351 | } |
| 6441 | 6352 | |
| 6353 | /// Non-atomic, non-volatile, non-packed store. |
| 6354 | fn store( |
| 6355 | fg: *FuncGen, |
| 6356 | ptr: Builder.Value, |
| 6357 | ptr_align: InternPool.Alignment, |
| 6358 | elem: Builder.Value, |
| 6359 | elem_ty: Type, |
| 6360 | ) Allocator.Error!void { |
| 6361 | const o = fg.object; |
| 6362 | const zcu = o.zcu; |
| 6363 | const llvm_ptr_align = switch (ptr_align) { |
| 6364 | .none => elem_ty.abiAlignment(zcu).toLlvm(), |
| 6365 | else => ptr_align.toLlvm(), |
| 6366 | }; |
| 6367 | if (isByRef(elem_ty, zcu)) { |
| 6368 | _ = try fg.wip.callMemCpy( |
| 6369 | ptr, |
| 6370 | llvm_ptr_align, |
| 6371 | elem, |
| 6372 | elem_ty.abiAlignment(zcu).toLlvm(), |
| 6373 | try o.builder.intValue( |
| 6374 | try fg.lowerType(.usize), |
| 6375 | elem_ty.abiSize(zcu), |
| 6376 | ), |
| 6377 | .normal, |
| 6378 | fg.disable_intrinsics, |
| 6379 | ); |
| 6380 | } else { |
| 6381 | _ = try fg.wip.storeAtomic( |
| 6382 | .normal, |
| 6383 | elem, |
| 6384 | ptr, |
| 6385 | fg.sync_scope, |
| 6386 | .none, |
| 6387 | llvm_ptr_align, |
| 6388 | ); |
| 6389 | } |
| 6390 | } |
| 6391 | |
| 6442 | 6392 | fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void { |
| 6443 | 6393 | const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545; |
| 6444 | 6394 | const o = fg.object; |
| ... | ... | @@ -6460,8 +6410,7 @@ fn valgrindClientRequest( |
| 6460 | 6410 | a5: Builder.Value, |
| 6461 | 6411 | ) Allocator.Error!Builder.Value { |
| 6462 | 6412 | const o = fg.object; |
| 6463 | | const pt = fg.pt; |
| 6464 | | const zcu = pt.zcu; |
| 6413 | const zcu = o.zcu; |
| 6465 | 6414 | const target = zcu.getTarget(); |
| 6466 | 6415 | if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value; |
| 6467 | 6416 | |
| ... | ... | @@ -6588,18 +6537,17 @@ fn valgrindClientRequest( |
| 6588 | 6537 | } |
| 6589 | 6538 | |
| 6590 | 6539 | fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type { |
| 6591 | | const zcu = fg.pt.zcu; |
| 6540 | const zcu = fg.object.zcu; |
| 6592 | 6541 | return fg.air.typeOf(inst, &zcu.intern_pool); |
| 6593 | 6542 | } |
| 6594 | 6543 | |
| 6595 | 6544 | fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type { |
| 6596 | | const zcu = fg.pt.zcu; |
| 6545 | const zcu = fg.object.zcu; |
| 6597 | 6546 | return fg.air.typeOfIndex(inst, &zcu.intern_pool); |
| 6598 | 6547 | } |
| 6599 | 6548 | |
| 6600 | 6549 | const ParamTypeIterator = struct { |
| 6601 | 6550 | object: *Object, |
| 6602 | | pt: Zcu.PerThread, |
| 6603 | 6551 | fn_info: InternPool.Key.FuncType, |
| 6604 | 6552 | zig_index: u32, |
| 6605 | 6553 | llvm_index: u32, |
| ... | ... | @@ -6622,7 +6570,7 @@ const ParamTypeIterator = struct { |
| 6622 | 6570 | |
| 6623 | 6571 | pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering { |
| 6624 | 6572 | if (it.zig_index >= it.fn_info.param_types.len) return null; |
| 6625 | | const ip = &it.pt.zcu.intern_pool; |
| 6573 | const ip = &it.object.zcu.intern_pool; |
| 6626 | 6574 | const ty = it.fn_info.param_types.get(ip)[it.zig_index]; |
| 6627 | 6575 | it.byval_attr = false; |
| 6628 | 6576 | return nextInner(it, Type.fromInterned(ty)); |
| ... | ... | @@ -6630,8 +6578,7 @@ const ParamTypeIterator = struct { |
| 6630 | 6578 | |
| 6631 | 6579 | /// `airCall` uses this instead of `next` so that it can take into account variadic functions. |
| 6632 | 6580 | fn nextCall(it: *ParamTypeIterator, fg: *FuncGen, args: []const Air.Inst.Ref) Allocator.Error!?Lowering { |
| 6633 | | assert(std.meta.eql(it.pt, fg.pt)); |
| 6634 | | const ip = &it.pt.zcu.intern_pool; |
| 6581 | const ip = &it.object.zcu.intern_pool; |
| 6635 | 6582 | if (it.zig_index >= it.fn_info.param_types.len) { |
| 6636 | 6583 | if (it.zig_index >= args.len) { |
| 6637 | 6584 | return null; |
| ... | ... | @@ -6644,8 +6591,7 @@ const ParamTypeIterator = struct { |
| 6644 | 6591 | } |
| 6645 | 6592 | |
| 6646 | 6593 | fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { |
| 6647 | | const pt = it.pt; |
| 6648 | | const zcu = pt.zcu; |
| 6594 | const zcu = it.object.zcu; |
| 6649 | 6595 | const target = zcu.getTarget(); |
| 6650 | 6596 | |
| 6651 | 6597 | if (!ty.hasRuntimeBits(zcu)) { |
| ... | ... | @@ -6744,7 +6690,7 @@ const ParamTypeIterator = struct { |
| 6744 | 6690 | for (0..ty.structFieldCount(zcu)) |field_index| { |
| 6745 | 6691 | const field_ty = ty.fieldType(field_index, zcu); |
| 6746 | 6692 | if (!field_ty.hasRuntimeBits(zcu)) continue; |
| 6747 | | it.types_buffer[it.types_len] = try it.object.lowerType(pt, field_ty); |
| 6693 | it.types_buffer[it.types_len] = try it.object.lowerType(field_ty); |
| 6748 | 6694 | it.types_len += 1; |
| 6749 | 6695 | } |
| 6750 | 6696 | it.llvm_index += it.types_len - 1; |
| ... | ... | @@ -6760,7 +6706,7 @@ const ParamTypeIterator = struct { |
| 6760 | 6706 | return .byval; |
| 6761 | 6707 | } else { |
| 6762 | 6708 | var types_buffer: [8]Builder.Type = undefined; |
| 6763 | | types_buffer[0] = try it.object.lowerType(pt, scalar_ty); |
| 6709 | types_buffer[0] = try it.object.lowerType(scalar_ty); |
| 6764 | 6710 | it.types_buffer = types_buffer; |
| 6765 | 6711 | it.types_len = 1; |
| 6766 | 6712 | it.llvm_index += 1; |
| ... | ... | @@ -6785,7 +6731,7 @@ const ParamTypeIterator = struct { |
| 6785 | 6731 | } |
| 6786 | 6732 | |
| 6787 | 6733 | fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering { |
| 6788 | | const zcu = it.pt.zcu; |
| 6734 | const zcu = it.object.zcu; |
| 6789 | 6735 | switch (x86_64_abi.classifyWindows(ty, zcu, zcu.getTarget(), .arg)) { |
| 6790 | 6736 | .integer => { |
| 6791 | 6737 | if (isScalar(zcu, ty)) { |
| ... | ... | @@ -6818,7 +6764,7 @@ const ParamTypeIterator = struct { |
| 6818 | 6764 | } |
| 6819 | 6765 | |
| 6820 | 6766 | fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering { |
| 6821 | | const zcu = it.pt.zcu; |
| 6767 | const zcu = it.object.zcu; |
| 6822 | 6768 | const ip = &zcu.intern_pool; |
| 6823 | 6769 | ty.assertHasLayout(zcu); |
| 6824 | 6770 | const classes = x86_64_abi.classifySystemV(ty, zcu, zcu.getTarget(), .arg); |
| ... | ... | @@ -6909,10 +6855,9 @@ const ParamTypeIterator = struct { |
| 6909 | 6855 | return .multiple_llvm_types; |
| 6910 | 6856 | } |
| 6911 | 6857 | }; |
| 6912 | | pub fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) ParamTypeIterator { |
| 6858 | pub fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTypeIterator { |
| 6913 | 6859 | return .{ |
| 6914 | 6860 | .object = object, |
| 6915 | | .pt = pt, |
| 6916 | 6861 | .fn_info = fn_info, |
| 6917 | 6862 | .zig_index = 0, |
| 6918 | 6863 | .llvm_index = 0, |
| ... | ... | @@ -6976,8 +6921,8 @@ fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: *const std.Target) bool { |
| 6976 | 6921 | /// In order to support the C calling convention, some return types need to be lowered |
| 6977 | 6922 | /// completely differently in the function prototype to honor the C ABI, and then |
| 6978 | 6923 | /// be effectively bitcasted to the actual return type. |
| 6979 | | pub fn lowerFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 6980 | | const zcu = pt.zcu; |
| 6924 | pub fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 6925 | const zcu = o.zcu; |
| 6981 | 6926 | const return_type = Type.fromInterned(fn_info.return_type); |
| 6982 | 6927 | if (!return_type.hasRuntimeBits(zcu)) { |
| 6983 | 6928 | assert(!return_type.isError(zcu)); |
| ... | ... | @@ -6986,27 +6931,27 @@ pub fn lowerFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncT |
| 6986 | 6931 | const target = zcu.getTarget(); |
| 6987 | 6932 | switch (fn_info.cc) { |
| 6988 | 6933 | .@"inline" => unreachable, |
| 6989 | | .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(pt, return_type), |
| 6934 | .auto => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(return_type), |
| 6990 | 6935 | |
| 6991 | | .x86_64_sysv => return lowerSystemVFnRetTy(o, pt, fn_info), |
| 6992 | | .x86_64_win => return lowerWin64FnRetTy(o, pt, fn_info), |
| 6993 | | .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(pt, return_type) else .void, |
| 6994 | | .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(pt, return_type), |
| 6936 | .x86_64_sysv => return lowerSystemVFnRetTy(o, fn_info), |
| 6937 | .x86_64_win => return lowerWin64FnRetTy(o, fn_info), |
| 6938 | .x86_stdcall => return if (isScalar(zcu, return_type)) o.lowerType(return_type) else .void, |
| 6939 | .x86_sysv, .x86_win => return if (isByRef(return_type, zcu)) .void else o.lowerType(return_type), |
| 6995 | 6940 | .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win => switch (aarch64_c_abi.classifyType(return_type, zcu)) { |
| 6996 | 6941 | .memory => return .void, |
| 6997 | | .float_array => return o.lowerType(pt, return_type), |
| 6998 | | .byval => return o.lowerType(pt, return_type), |
| 6942 | .float_array => return o.lowerType(return_type), |
| 6943 | .byval => return o.lowerType(return_type), |
| 6999 | 6944 | .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))), |
| 7000 | 6945 | .double_integer => return o.builder.arrayType(2, .i64), |
| 7001 | 6946 | }, |
| 7002 | 6947 | .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) { |
| 7003 | 6948 | .memory, .i64_array => return .void, |
| 7004 | 6949 | .i32_array => |len| return if (len == 1) .i32 else .void, |
| 7005 | | .byval => return o.lowerType(pt, return_type), |
| 6950 | .byval => return o.lowerType(return_type), |
| 7006 | 6951 | }, |
| 7007 | 6952 | .mips_o32 => switch (mips_c_abi.classifyType(return_type, zcu, .ret)) { |
| 7008 | 6953 | .memory, .i32_array => return .void, |
| 7009 | | .byval => return o.lowerType(pt, return_type), |
| 6954 | .byval => return o.lowerType(return_type), |
| 7010 | 6955 | }, |
| 7011 | 6956 | .riscv64_lp64, .riscv32_ilp32 => switch (riscv_c_abi.classifyType(return_type, zcu)) { |
| 7012 | 6957 | .memory => return .void, |
| ... | ... | @@ -7019,53 +6964,53 @@ pub fn lowerFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncT |
| 7019 | 6964 | }; |
| 7020 | 6965 | return o.builder.structType(.normal, &.{ integer, integer }); |
| 7021 | 6966 | }, |
| 7022 | | .byval => return o.lowerType(pt, return_type), |
| 6967 | .byval => return o.lowerType(return_type), |
| 7023 | 6968 | .fields => { |
| 7024 | 6969 | var types_len: usize = 0; |
| 7025 | 6970 | var types: [8]Builder.Type = undefined; |
| 7026 | 6971 | for (0..return_type.structFieldCount(zcu)) |field_index| { |
| 7027 | 6972 | const field_ty = return_type.fieldType(field_index, zcu); |
| 7028 | 6973 | if (!field_ty.hasRuntimeBits(zcu)) continue; |
| 7029 | | types[types_len] = try o.lowerType(pt, field_ty); |
| 6974 | types[types_len] = try o.lowerType(field_ty); |
| 7030 | 6975 | types_len += 1; |
| 7031 | 6976 | } |
| 7032 | 6977 | return o.builder.structType(.normal, types[0..types_len]); |
| 7033 | 6978 | }, |
| 7034 | 6979 | }, |
| 7035 | 6980 | .wasm_mvp => switch (wasm_c_abi.classifyType(return_type, zcu)) { |
| 7036 | | .direct => |scalar_ty| return o.lowerType(pt, scalar_ty), |
| 6981 | .direct => |scalar_ty| return o.lowerType(scalar_ty), |
| 7037 | 6982 | .indirect => return .void, |
| 7038 | 6983 | }, |
| 7039 | 6984 | // TODO investigate other callconvs |
| 7040 | | else => return o.lowerType(pt, return_type), |
| 6985 | else => return o.lowerType(return_type), |
| 7041 | 6986 | } |
| 7042 | 6987 | } |
| 7043 | 6988 | |
| 7044 | | fn lowerWin64FnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 7045 | | const zcu = pt.zcu; |
| 6989 | fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 6990 | const zcu = o.zcu; |
| 7046 | 6991 | const return_type = Type.fromInterned(fn_info.return_type); |
| 7047 | 6992 | switch (x86_64_abi.classifyWindows(return_type, zcu, zcu.getTarget(), .ret)) { |
| 7048 | 6993 | .integer => { |
| 7049 | 6994 | if (isScalar(zcu, return_type)) { |
| 7050 | | return o.lowerType(pt, return_type); |
| 6995 | return o.lowerType(return_type); |
| 7051 | 6996 | } else { |
| 7052 | 6997 | return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8)); |
| 7053 | 6998 | } |
| 7054 | 6999 | }, |
| 7055 | 7000 | .win_i128 => return o.builder.vectorType(.normal, 2, .i64), |
| 7056 | 7001 | .memory => return .void, |
| 7057 | | .sse => return o.lowerType(pt, return_type), |
| 7002 | .sse => return o.lowerType(return_type), |
| 7058 | 7003 | else => unreachable, |
| 7059 | 7004 | } |
| 7060 | 7005 | } |
| 7061 | 7006 | |
| 7062 | | fn lowerSystemVFnRetTy(o: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 7063 | | const zcu = pt.zcu; |
| 7007 | fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type { |
| 7008 | const zcu = o.zcu; |
| 7064 | 7009 | const ip = &zcu.intern_pool; |
| 7065 | 7010 | const return_type = Type.fromInterned(fn_info.return_type); |
| 7066 | 7011 | return_type.assertHasLayout(zcu); |
| 7067 | 7012 | if (isScalar(zcu, return_type)) { |
| 7068 | | return o.lowerType(pt, return_type); |
| 7013 | return o.lowerType(return_type); |
| 7069 | 7014 | } |
| 7070 | 7015 | const classes = x86_64_abi.classifySystemV(return_type, zcu, zcu.getTarget(), .ret); |
| 7071 | 7016 | var types_index: u32 = 0; |
| ... | ... | @@ -7297,7 +7242,7 @@ pub fn isByRef(ty: Type, zcu: *const Zcu) bool { |
| 7297 | 7242 | /// RMW exchange of floating-point values is bitcasted to same-sized integer |
| 7298 | 7243 | /// types to work around a LLVM deficiency when targeting ARM/AArch64. |
| 7299 | 7244 | fn getAtomicAbiType(fg: *const FuncGen, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type { |
| 7300 | | const zcu = fg.pt.zcu; |
| 7245 | const zcu = fg.object.zcu; |
| 7301 | 7246 | switch (ty.zigTypeTag(zcu)) { |
| 7302 | 7247 | .int, .@"enum", .@"struct", .@"union" => {}, |
| 7303 | 7248 | .float => { |