| ... | ... | @@ -175,11 +175,6 @@ fn resolveValue(self: *FuncGen, val: Value) Allocator.Error!Builder.Constant { |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | | /// MLUGG TODO okay yeah prolly delete this again |
| 179 | | fn lowerType(fg: *const FuncGen, ty: Type) Allocator.Error!Builder.Type { |
| 180 | | return fg.object.lowerType(ty); |
| 181 | | } |
| 182 | | |
| 183 | 178 | pub fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) TodoError!void { |
| 184 | 179 | const o = self.object; |
| 185 | 180 | const zcu = self.object.zcu; |
| ... | ... | @@ -608,7 +603,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 608 | 603 | } |
| 609 | 604 | |
| 610 | 605 | const ret_ptr = if (!sret) null else blk: { |
| 611 | | const llvm_ret_ty = try self.lowerType(return_type); |
| 606 | const llvm_ret_ty = try o.lowerType(return_type); |
| 612 | 607 | try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder); |
| 613 | 608 | |
| 614 | 609 | const alignment = return_type.abiAlignment(zcu).toLlvm(); |
| ... | ... | @@ -630,7 +625,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 630 | 625 | const arg = args[it.zig_index - 1]; |
| 631 | 626 | const param_ty = self.typeOf(arg); |
| 632 | 627 | const llvm_arg = try self.resolveInst(arg); |
| 633 | | const llvm_param_ty = try self.lowerType(param_ty); |
| 628 | const llvm_param_ty = try o.lowerType(param_ty); |
| 634 | 629 | if (isByRef(param_ty, zcu)) { |
| 635 | 630 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 636 | 631 | const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, ""); |
| ... | ... | @@ -659,7 +654,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 659 | 654 | const llvm_arg = try self.resolveInst(arg); |
| 660 | 655 | |
| 661 | 656 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 662 | | const param_llvm_ty = try self.lowerType(param_ty); |
| 657 | const param_llvm_ty = try o.lowerType(param_ty); |
| 663 | 658 | const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment); |
| 664 | 659 | if (isByRef(param_ty, zcu)) { |
| 665 | 660 | const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, ""); |
| ... | ... | @@ -729,7 +724,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 729 | 724 | llvm_arg = ptr; |
| 730 | 725 | } |
| 731 | 726 | |
| 732 | | const float_ty = try self.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?); |
| 727 | const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?); |
| 733 | 728 | const array_ty = try o.builder.arrayType(count, float_ty); |
| 734 | 729 | |
| 735 | 730 | const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, ""); |
| ... | ... | @@ -770,7 +765,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 770 | 765 | .byref => { |
| 771 | 766 | const param_index = it.zig_index - 1; |
| 772 | 767 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]); |
| 773 | | const param_llvm_ty = try self.lowerType(param_ty); |
| 768 | const param_llvm_ty = try o.lowerType(param_ty); |
| 774 | 769 | const alignment = param_ty.abiAlignment(zcu).toLlvm(); |
| 775 | 770 | try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty); |
| 776 | 771 | }, |
| ... | ... | @@ -822,7 +817,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 822 | 817 | }, |
| 823 | 818 | toLlvmCallConvTag(fn_info.cc, target).?, |
| 824 | 819 | try attributes.finish(&o.builder), |
| 825 | | try self.lowerType(zig_fn_ty), |
| 820 | try o.lowerType(zig_fn_ty), |
| 826 | 821 | llvm_fn, |
| 827 | 822 | llvm_args.items, |
| 828 | 823 | "", |
| ... | ... | @@ -836,7 +831,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 836 | 831 | return .none; |
| 837 | 832 | } |
| 838 | 833 | |
| 839 | | const llvm_ret_ty = try self.lowerType(return_type); |
| 834 | const llvm_ret_ty = try o.lowerType(return_type); |
| 840 | 835 | if (ret_ptr) |rp| { |
| 841 | 836 | if (isByRef(return_type, zcu)) { |
| 842 | 837 | return rp; |
| ... | ... | @@ -908,7 +903,7 @@ fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!vo |
| 908 | 903 | const operand = try self.resolveInst(un_op); |
| 909 | 904 | const val_is_undef = if (un_op.toInterned()) |i| Value.fromInterned(i).isUndef(zcu) else false; |
| 910 | 905 | if (val_is_undef and safety) { |
| 911 | | const len = try o.builder.intValue(try self.lowerType(.usize), ret_ty.abiSize(zcu)); |
| 906 | const len = try o.builder.intValue(try o.lowerType(.usize), ret_ty.abiSize(zcu)); |
| 912 | 907 | _ = try self.wip.callMemSet( |
| 913 | 908 | self.ret_ptr, |
| 914 | 909 | ret_ty.abiAlignment(zcu).toLlvm(), |
| ... | ... | @@ -964,7 +959,7 @@ fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!vo |
| 964 | 959 | if (val_is_undef and safety) { |
| 965 | 960 | const llvm_ret_ty = operand.typeOfWip(&self.wip); |
| 966 | 961 | const rp = try self.buildAlloca(llvm_ret_ty, alignment); |
| 967 | | const len = try o.builder.intValue(try self.lowerType(.usize), ret_ty.abiSize(zcu)); |
| 962 | const len = try o.builder.intValue(try o.lowerType(.usize), ret_ty.abiSize(zcu)); |
| 968 | 963 | _ = try self.wip.callMemSet( |
| 969 | 964 | rp, |
| 970 | 965 | alignment, |
| ... | ... | @@ -1034,17 +1029,18 @@ fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 1034 | 1029 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 1035 | 1030 | const list = try self.resolveInst(ty_op.operand); |
| 1036 | 1031 | const arg_ty = ty_op.ty.toType(); |
| 1037 | | const llvm_arg_ty = try self.lowerType(arg_ty); |
| 1032 | const llvm_arg_ty = try self.object.lowerType(arg_ty); |
| 1038 | 1033 | |
| 1039 | 1034 | return self.wip.vaArg(list, llvm_arg_ty, ""); |
| 1040 | 1035 | } |
| 1041 | 1036 | |
| 1042 | 1037 | fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 1043 | | const zcu = self.object.zcu; |
| 1038 | const o = self.object; |
| 1039 | const zcu = o.zcu; |
| 1044 | 1040 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 1045 | 1041 | const src_list = try self.resolveInst(ty_op.operand); |
| 1046 | 1042 | const va_list_ty = ty_op.ty.toType(); |
| 1047 | | const llvm_va_list_ty = try self.lowerType(va_list_ty); |
| 1043 | const llvm_va_list_ty = try o.lowerType(va_list_ty); |
| 1048 | 1044 | |
| 1049 | 1045 | const result_alignment = va_list_ty.abiAlignment(zcu).toLlvm(); |
| 1050 | 1046 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| ... | ... | @@ -1065,9 +1061,10 @@ fn airCVaEnd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 1065 | 1061 | } |
| 1066 | 1062 | |
| 1067 | 1063 | fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 1068 | | const zcu = self.object.zcu; |
| 1064 | const o = self.object; |
| 1065 | const zcu = o.zcu; |
| 1069 | 1066 | const va_list_ty = self.typeOfIndex(inst); |
| 1070 | | const llvm_va_list_ty = try self.lowerType(va_list_ty); |
| 1067 | const llvm_va_list_ty = try o.lowerType(va_list_ty); |
| 1071 | 1068 | |
| 1072 | 1069 | const result_alignment = va_list_ty.abiAlignment(zcu).toLlvm(); |
| 1073 | 1070 | const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment); |
| ... | ... | @@ -1227,7 +1224,8 @@ fn lowerBlock( |
| 1227 | 1224 | maybe_inline_func: ?InternPool.Index, |
| 1228 | 1225 | body: []const Air.Inst.Index, |
| 1229 | 1226 | ) TodoError!Builder.Value { |
| 1230 | | const zcu = self.object.zcu; |
| 1227 | const o = self.object; |
| 1228 | const zcu = o.zcu; |
| 1231 | 1229 | const inst_ty = self.typeOfIndex(inst); |
| 1232 | 1230 | |
| 1233 | 1231 | if (inst_ty.isNoReturn(zcu)) { |
| ... | ... | @@ -1253,7 +1251,7 @@ fn lowerBlock( |
| 1253 | 1251 | |
| 1254 | 1252 | // Create a phi node only if the block returns a value. |
| 1255 | 1253 | if (have_block_result) { |
| 1256 | | const raw_llvm_ty = try self.lowerType(inst_ty); |
| 1254 | const raw_llvm_ty = try o.lowerType(inst_ty); |
| 1257 | 1255 | const llvm_ty: Builder.Type = ty: { |
| 1258 | 1256 | // If the zig tag type is a function, this represents an actual function body; not |
| 1259 | 1257 | // a pointer to it. LLVM IR allows the call instruction to use function bodies instead |
| ... | ... | @@ -1370,7 +1368,7 @@ fn lowerSwitchDispatch( |
| 1370 | 1368 | const table_index = try self.wip.conv( |
| 1371 | 1369 | .unsigned, |
| 1372 | 1370 | try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""), |
| 1373 | | try self.lowerType(.usize), |
| 1371 | try o.lowerType(.usize), |
| 1374 | 1372 | "", |
| 1375 | 1373 | ); |
| 1376 | 1374 | const target_ptr_ptr = try self.ptraddScaled( |
| ... | ... | @@ -1395,7 +1393,7 @@ fn lowerSwitchDispatch( |
| 1395 | 1393 | // The switch prongs will correspond to our scalar cases. Ranges will |
| 1396 | 1394 | // be handled by conditional branches in the `else` prong. |
| 1397 | 1395 | |
| 1398 | | const llvm_usize = try self.lowerType(.usize); |
| 1396 | const llvm_usize = try o.lowerType(.usize); |
| 1399 | 1397 | const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder)) |
| 1400 | 1398 | try self.wip.cast(.ptrtoint, cond, llvm_usize, "") |
| 1401 | 1399 | else |
| ... | ... | @@ -1642,7 +1640,7 @@ fn lowerTry( |
| 1642 | 1640 | } else if (isByRef(payload_ty, zcu)) { |
| 1643 | 1641 | return fg.loadByRef(payload_ptr, payload_ty, payload_align.toLlvm(), .normal); |
| 1644 | 1642 | } else { |
| 1645 | | return fg.wip.load(.normal, try fg.lowerType(payload_ty), payload_ptr, payload_align.toLlvm(), ""); |
| 1643 | return fg.wip.load(.normal, try o.lowerType(payload_ty), payload_ptr, payload_align.toLlvm(), ""); |
| 1646 | 1644 | } |
| 1647 | 1645 | } |
| 1648 | 1646 | |
| ... | ... | @@ -1912,9 +1910,9 @@ fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder |
| 1912 | 1910 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 1913 | 1911 | const operand_ty = self.typeOf(ty_op.operand); |
| 1914 | 1912 | const array_ty = operand_ty.childType(zcu); |
| 1915 | | const llvm_usize = try self.lowerType(.usize); |
| 1913 | const llvm_usize = try o.lowerType(.usize); |
| 1916 | 1914 | const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu)); |
| 1917 | | const slice_llvm_ty = try self.lowerType(self.typeOfIndex(inst)); |
| 1915 | const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst)); |
| 1918 | 1916 | const operand = try self.resolveInst(ty_op.operand); |
| 1919 | 1917 | return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, ""); |
| 1920 | 1918 | } |
| ... | ... | @@ -1931,7 +1929,7 @@ fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value |
| 1931 | 1929 | |
| 1932 | 1930 | const dest_ty = self.typeOfIndex(inst); |
| 1933 | 1931 | const dest_scalar_ty = dest_ty.scalarType(zcu); |
| 1934 | | const dest_llvm_ty = try self.lowerType(dest_ty); |
| 1932 | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 1935 | 1933 | const target = zcu.getTarget(); |
| 1936 | 1934 | |
| 1937 | 1935 | if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv( |
| ... | ... | @@ -1999,7 +1997,7 @@ fn airIntFromFloat( |
| 1999 | 1997 | |
| 2000 | 1998 | const dest_ty = self.typeOfIndex(inst); |
| 2001 | 1999 | const dest_scalar_ty = dest_ty.scalarType(zcu); |
| 2002 | | const dest_llvm_ty = try self.lowerType(dest_ty); |
| 2000 | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 2003 | 2001 | |
| 2004 | 2002 | if (intrinsicsAllowed(operand_scalar_ty, target)) { |
| 2005 | 2003 | // TODO set fast math flag |
| ... | ... | @@ -2033,7 +2031,7 @@ fn airIntFromFloat( |
| 2033 | 2031 | compiler_rt_dest_abbrev, |
| 2034 | 2032 | }); |
| 2035 | 2033 | |
| 2036 | | const operand_llvm_ty = try self.lowerType(operand_ty); |
| 2034 | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 2037 | 2035 | const libc_fn = try o.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty); |
| 2038 | 2036 | var result = try self.wip.call( |
| 2039 | 2037 | .normal, |
| ... | ... | @@ -2058,7 +2056,7 @@ fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!B |
| 2058 | 2056 | fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value { |
| 2059 | 2057 | const o = fg.object; |
| 2060 | 2058 | const zcu = o.zcu; |
| 2061 | | const llvm_usize = try fg.lowerType(.usize); |
| 2059 | const llvm_usize = try o.lowerType(.usize); |
| 2062 | 2060 | switch (ty.ptrSize(zcu)) { |
| 2063 | 2061 | .slice => { |
| 2064 | 2062 | const len = try fg.wip.extractValue(ptr, &.{1}, ""); |
| ... | ... | @@ -2240,7 +2238,7 @@ fn airStructFieldVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build |
| 2240 | 2238 | }, |
| 2241 | 2239 | .float => { |
| 2242 | 2240 | // bitcast int->float |
| 2243 | | return self.wip.cast(.bitcast, field_int_val, try self.lowerType(field_ty), ""); |
| 2241 | return self.wip.cast(.bitcast, field_int_val, try o.lowerType(field_ty), ""); |
| 2244 | 2242 | }, |
| 2245 | 2243 | } |
| 2246 | 2244 | } |
| ... | ... | @@ -2277,8 +2275,8 @@ fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build |
| 2277 | 2275 | const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu); |
| 2278 | 2276 | if (field_offset == 0) return field_ptr; |
| 2279 | 2277 | |
| 2280 | | const res_ty = try self.lowerType(ty_pl.ty.toType()); |
| 2281 | | const llvm_usize = try self.lowerType(.usize); |
| 2278 | const res_ty = try o.lowerType(ty_pl.ty.toType()); |
| 2279 | const llvm_usize = try o.lowerType(.usize); |
| 2282 | 2280 | |
| 2283 | 2281 | const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, ""); |
| 2284 | 2282 | const base_ptr_int = try self.wip.bin( |
| ... | ... | @@ -2495,7 +2493,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value { |
| 2495 | 2493 | const output_inst = try self.resolveInst(output.operand); |
| 2496 | 2494 | const output_ty = self.typeOf(output.operand); |
| 2497 | 2495 | assert(output_ty.zigTypeTag(zcu) == .pointer); |
| 2498 | | const elem_llvm_ty = try self.lowerType(output_ty.childType(zcu)); |
| 2496 | const elem_llvm_ty = try o.lowerType(output_ty.childType(zcu)); |
| 2499 | 2497 | |
| 2500 | 2498 | switch (constraint[0]) { |
| 2501 | 2499 | '=' => {}, |
| ... | ... | @@ -2533,7 +2531,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value { |
| 2533 | 2531 | llvm_ret_indirect[output.index] = false; |
| 2534 | 2532 | |
| 2535 | 2533 | const ret_ty = self.typeOfIndex(inst); |
| 2536 | | llvm_ret_types[llvm_ret_i] = try self.lowerType(ret_ty); |
| 2534 | llvm_ret_types[llvm_ret_i] = try o.lowerType(ret_ty); |
| 2537 | 2535 | llvm_ret_i += 1; |
| 2538 | 2536 | } |
| 2539 | 2537 | |
| ... | ... | @@ -2572,7 +2570,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value { |
| 2572 | 2570 | llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip); |
| 2573 | 2571 | } else { |
| 2574 | 2572 | const alignment = arg_ty.abiAlignment(zcu).toLlvm(); |
| 2575 | | const arg_llvm_ty = try self.lowerType(arg_ty); |
| 2573 | const arg_llvm_ty = try o.lowerType(arg_ty); |
| 2576 | 2574 | const load_inst = |
| 2577 | 2575 | try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, ""); |
| 2578 | 2576 | llvm_param_values[llvm_param_i] = load_inst; |
| ... | ... | @@ -2613,7 +2611,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value { |
| 2613 | 2611 | llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: { |
| 2614 | 2612 | if (!is_by_ref) self.maybeMarkAllowZeroAccess(arg_ty.ptrInfo(zcu)); |
| 2615 | 2613 | |
| 2616 | | break :blk try self.lowerType(if (is_by_ref) arg_ty else arg_ty.childType(zcu)); |
| 2614 | break :blk try o.lowerType(if (is_by_ref) arg_ty else arg_ty.childType(zcu)); |
| 2617 | 2615 | } else .none; |
| 2618 | 2616 | |
| 2619 | 2617 | llvm_param_i += 1; |
| ... | ... | @@ -2627,7 +2625,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value { |
| 2627 | 2625 | if (constraint[0] != '+') continue; |
| 2628 | 2626 | |
| 2629 | 2627 | const rw_ty = self.typeOf(output.operand); |
| 2630 | | const llvm_elem_ty = try self.lowerType(rw_ty.childType(zcu)); |
| 2628 | const llvm_elem_ty = try o.lowerType(rw_ty.childType(zcu)); |
| 2631 | 2629 | if (llvm_ret_indirect[output.index]) { |
| 2632 | 2630 | llvm_param_values[llvm_param_i] = llvm_rw_vals[output.index]; |
| 2633 | 2631 | llvm_param_types[llvm_param_i] = llvm_rw_vals[output.index].typeOfWip(&self.wip); |
| ... | ... | @@ -2827,7 +2825,7 @@ fn airIsNonNull( |
| 2827 | 2825 | const operand = try self.resolveInst(un_op); |
| 2828 | 2826 | const operand_ty = self.typeOf(un_op); |
| 2829 | 2827 | const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty; |
| 2830 | | const optional_llvm_ty = try self.lowerType(optional_ty); |
| 2828 | const optional_llvm_ty = try o.lowerType(optional_ty); |
| 2831 | 2829 | const payload_ty = optional_ty.optionalChild(zcu); |
| 2832 | 2830 | |
| 2833 | 2831 | const access_kind: Builder.MemoryAccessKind = |
| ... | ... | @@ -2896,7 +2894,7 @@ fn airIsErr( |
| 2896 | 2894 | |
| 2897 | 2895 | if (!payload_ty.hasRuntimeBits(zcu)) { |
| 2898 | 2896 | const loaded = if (operand_is_ptr) |
| 2899 | | try self.wip.load(access_kind, try self.lowerType(err_union_ty), operand, operand_ty.ptrAlignment(zcu).toLlvm(), "") |
| 2897 | try self.wip.load(access_kind, try o.lowerType(err_union_ty), operand, operand_ty.ptrAlignment(zcu).toLlvm(), "") |
| 2900 | 2898 | else |
| 2901 | 2899 | operand; |
| 2902 | 2900 | return self.wip.icmp(cond, loaded, zero, ""); |
| ... | ... | @@ -2981,7 +2979,8 @@ fn airOptionalPayload(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Buil |
| 2981 | 2979 | } |
| 2982 | 2980 | |
| 2983 | 2981 | fn airErrUnionPayload(self: *FuncGen, inst: Air.Inst.Index, operand_is_ptr: bool) Allocator.Error!Builder.Value { |
| 2984 | | const zcu = self.object.zcu; |
| 2982 | const o = self.object; |
| 2983 | const zcu = o.zcu; |
| 2985 | 2984 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 2986 | 2985 | const operand = try self.resolveInst(ty_op.operand); |
| 2987 | 2986 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -3001,7 +3000,7 @@ fn airErrUnionPayload(self: *FuncGen, inst: Air.Inst.Index, operand_is_ptr: bool |
| 3001 | 3000 | if (isByRef(payload_ty, zcu)) { |
| 3002 | 3001 | return self.loadByRef(payload_ptr, payload_ty, payload_alignment, .normal); |
| 3003 | 3002 | } else { |
| 3004 | | const payload_llvm_ty = try self.lowerType(payload_ty); |
| 3003 | const payload_llvm_ty = try o.lowerType(payload_ty); |
| 3005 | 3004 | return self.wip.load(.normal, payload_llvm_ty, payload_ptr, payload_alignment, ""); |
| 3006 | 3005 | } |
| 3007 | 3006 | } |
| ... | ... | @@ -3148,7 +3147,7 @@ fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator. |
| 3148 | 3147 | const optional_ty = self.typeOfIndex(inst); |
| 3149 | 3148 | if (optional_ty.optionalReprIsPayload(zcu)) return operand; |
| 3150 | 3149 | assert(isByRef(optional_ty, zcu)); // optionals with runtime bits are by-ref unless `optionalReprIsPayload` |
| 3151 | | const llvm_optional_ty = try self.lowerType(optional_ty); |
| 3150 | const llvm_optional_ty = try o.lowerType(optional_ty); |
| 3152 | 3151 | const optional_ptr = if (self.isNextRet(body_tail)) |
| 3153 | 3152 | self.ret_ptr |
| 3154 | 3153 | else brk: { |
| ... | ... | @@ -3181,7 +3180,7 @@ fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) All |
| 3181 | 3180 | assert(payload_ty.hasRuntimeBits(zcu)); |
| 3182 | 3181 | assert(isByRef(err_un_ty, zcu)); // error unions with runtime bits are always by-ref |
| 3183 | 3182 | const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0); |
| 3184 | | const err_un_llvm_ty = try self.lowerType(err_un_ty); |
| 3183 | const err_un_llvm_ty = try o.lowerType(err_un_ty); |
| 3185 | 3184 | |
| 3186 | 3185 | const result_ptr = if (self.isNextRet(body_tail)) |
| 3187 | 3186 | self.ret_ptr |
| ... | ... | @@ -3205,7 +3204,8 @@ fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) All |
| 3205 | 3204 | } |
| 3206 | 3205 | |
| 3207 | 3206 | fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3208 | | const zcu = self.object.zcu; |
| 3207 | const o = self.object; |
| 3208 | const zcu = o.zcu; |
| 3209 | 3209 | const inst = body_tail[0]; |
| 3210 | 3210 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3211 | 3211 | const err_un_ty = self.typeOfIndex(inst); |
| ... | ... | @@ -3213,7 +3213,7 @@ fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocat |
| 3213 | 3213 | const operand = try self.resolveInst(ty_op.operand); |
| 3214 | 3214 | if (!payload_ty.hasRuntimeBits(zcu)) return operand; |
| 3215 | 3215 | assert(isByRef(err_un_ty, zcu)); // error unions with runtime bits are always by-ref |
| 3216 | | const err_un_llvm_ty = try self.lowerType(err_un_ty); |
| 3216 | const err_un_llvm_ty = try o.lowerType(err_un_ty); |
| 3217 | 3217 | |
| 3218 | 3218 | const result_ptr = if (self.isNextRet(body_tail)) |
| 3219 | 3219 | self.ret_ptr |
| ... | ... | @@ -3236,7 +3236,7 @@ fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build |
| 3236 | 3236 | const o = self.object; |
| 3237 | 3237 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 3238 | 3238 | const index = pl_op.payload; |
| 3239 | | const llvm_usize = try self.lowerType(.usize); |
| 3239 | const llvm_usize = try o.lowerType(.usize); |
| 3240 | 3240 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{ |
| 3241 | 3241 | try o.builder.intValue(.i32, index), |
| 3242 | 3242 | }, ""); |
| ... | ... | @@ -3246,7 +3246,7 @@ fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build |
| 3246 | 3246 | const o = self.object; |
| 3247 | 3247 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 3248 | 3248 | const index = pl_op.payload; |
| 3249 | | const llvm_isize = try self.lowerType(.isize); |
| 3249 | const llvm_isize = try o.lowerType(.isize); |
| 3250 | 3250 | return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{ |
| 3251 | 3251 | try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand), |
| 3252 | 3252 | }, ""); |
| ... | ... | @@ -3260,7 +3260,8 @@ fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder. |
| 3260 | 3260 | } |
| 3261 | 3261 | |
| 3262 | 3262 | fn airMin(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3263 | | const zcu = self.object.zcu; |
| 3263 | const o = self.object; |
| 3264 | const zcu = o.zcu; |
| 3264 | 3265 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3265 | 3266 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3266 | 3267 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3272,14 +3273,15 @@ fn airMin(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3272 | 3273 | .normal, |
| 3273 | 3274 | .none, |
| 3274 | 3275 | if (scalar_ty.isSignedInt(zcu)) .smin else .umin, |
| 3275 | | &.{try self.lowerType(inst_ty)}, |
| 3276 | &.{try o.lowerType(inst_ty)}, |
| 3276 | 3277 | &.{ lhs, rhs }, |
| 3277 | 3278 | "", |
| 3278 | 3279 | ); |
| 3279 | 3280 | } |
| 3280 | 3281 | |
| 3281 | 3282 | fn airMax(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3282 | | const zcu = self.object.zcu; |
| 3283 | const o = self.object; |
| 3284 | const zcu = o.zcu; |
| 3283 | 3285 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3284 | 3286 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3285 | 3287 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3291,7 +3293,7 @@ fn airMax(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3291 | 3293 | .normal, |
| 3292 | 3294 | .none, |
| 3293 | 3295 | if (scalar_ty.isSignedInt(zcu)) .smax else .umax, |
| 3294 | | &.{try self.lowerType(inst_ty)}, |
| 3296 | &.{try o.lowerType(inst_ty)}, |
| 3295 | 3297 | &.{ lhs, rhs }, |
| 3296 | 3298 | "", |
| 3297 | 3299 | ); |
| ... | ... | @@ -3303,7 +3305,7 @@ fn airSlice(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3303 | 3305 | const ptr = try self.resolveInst(bin_op.lhs); |
| 3304 | 3306 | const len = try self.resolveInst(bin_op.rhs); |
| 3305 | 3307 | const inst_ty = self.typeOfIndex(inst); |
| 3306 | | return self.wip.buildAggregate(try self.lowerType(inst_ty), &.{ ptr, len }, ""); |
| 3308 | return self.wip.buildAggregate(try self.object.lowerType(inst_ty), &.{ ptr, len }, ""); |
| 3307 | 3309 | } |
| 3308 | 3310 | |
| 3309 | 3311 | fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value { |
| ... | ... | @@ -3334,7 +3336,7 @@ fn airSafeArithmetic( |
| 3334 | 3336 | const scalar_ty = inst_ty.scalarType(zcu); |
| 3335 | 3337 | |
| 3336 | 3338 | const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic; |
| 3337 | | const llvm_inst_ty = try fg.lowerType(inst_ty); |
| 3339 | const llvm_inst_ty = try o.lowerType(inst_ty); |
| 3338 | 3340 | const results = |
| 3339 | 3341 | try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, ""); |
| 3340 | 3342 | |
| ... | ... | @@ -3372,7 +3374,8 @@ fn airAddWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 3372 | 3374 | } |
| 3373 | 3375 | |
| 3374 | 3376 | fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3375 | | const zcu = self.object.zcu; |
| 3377 | const o = self.object; |
| 3378 | const zcu = o.zcu; |
| 3376 | 3379 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3377 | 3380 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3378 | 3381 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3383,7 +3386,7 @@ fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3383 | 3386 | .normal, |
| 3384 | 3387 | .none, |
| 3385 | 3388 | if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat", |
| 3386 | | &.{try self.lowerType(inst_ty)}, |
| 3389 | &.{try o.lowerType(inst_ty)}, |
| 3387 | 3390 | &.{ lhs, rhs }, |
| 3388 | 3391 | "", |
| 3389 | 3392 | ); |
| ... | ... | @@ -3410,7 +3413,8 @@ fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 3410 | 3413 | } |
| 3411 | 3414 | |
| 3412 | 3415 | fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3413 | | const zcu = self.object.zcu; |
| 3416 | const o = self.object; |
| 3417 | const zcu = o.zcu; |
| 3414 | 3418 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3415 | 3419 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3416 | 3420 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3421,7 +3425,7 @@ fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3421 | 3425 | .normal, |
| 3422 | 3426 | .none, |
| 3423 | 3427 | if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat", |
| 3424 | | &.{try self.lowerType(inst_ty)}, |
| 3428 | &.{try o.lowerType(inst_ty)}, |
| 3425 | 3429 | &.{ lhs, rhs }, |
| 3426 | 3430 | "", |
| 3427 | 3431 | ); |
| ... | ... | @@ -3448,7 +3452,8 @@ fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 3448 | 3452 | } |
| 3449 | 3453 | |
| 3450 | 3454 | fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3451 | | const zcu = self.object.zcu; |
| 3455 | const o = self.object; |
| 3456 | const zcu = o.zcu; |
| 3452 | 3457 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 3453 | 3458 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3454 | 3459 | const rhs = try self.resolveInst(bin_op.rhs); |
| ... | ... | @@ -3459,7 +3464,7 @@ fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3459 | 3464 | .normal, |
| 3460 | 3465 | .none, |
| 3461 | 3466 | if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat", |
| 3462 | | &.{try self.lowerType(inst_ty)}, |
| 3467 | &.{try o.lowerType(inst_ty)}, |
| 3463 | 3468 | &.{ lhs, rhs, .@"0" }, |
| 3464 | 3469 | "", |
| 3465 | 3470 | ); |
| ... | ... | @@ -3503,7 +3508,7 @@ fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) |
| 3503 | 3508 | return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result}); |
| 3504 | 3509 | } |
| 3505 | 3510 | if (scalar_ty.isSignedInt(zcu)) { |
| 3506 | | const inst_llvm_ty = try self.lowerType(inst_ty); |
| 3511 | const inst_llvm_ty = try o.lowerType(inst_ty); |
| 3507 | 3512 | |
| 3508 | 3513 | const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb; |
| 3509 | 3514 | var stack align(@max( |
| ... | ... | @@ -3579,7 +3584,7 @@ fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo |
| 3579 | 3584 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3580 | 3585 | const rhs = try self.resolveInst(bin_op.rhs); |
| 3581 | 3586 | const inst_ty = self.typeOfIndex(inst); |
| 3582 | | const inst_llvm_ty = try self.lowerType(inst_ty); |
| 3587 | const inst_llvm_ty = try o.lowerType(inst_ty); |
| 3583 | 3588 | const scalar_ty = inst_ty.scalarType(zcu); |
| 3584 | 3589 | |
| 3585 | 3590 | if (scalar_ty.isRuntimeFloat()) { |
| ... | ... | @@ -3646,7 +3651,7 @@ fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3646 | 3651 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 3647 | 3652 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3648 | 3653 | const ptr_or_slice = try self.resolveInst(bin_op.lhs); |
| 3649 | | const llvm_usize_ty = try self.lowerType(.usize); |
| 3654 | const llvm_usize_ty = try o.lowerType(.usize); |
| 3650 | 3655 | const ptr_ty = self.typeOf(bin_op.lhs); |
| 3651 | 3656 | const elem_ty = ptr_ty.indexableElem(zcu); |
| 3652 | 3657 | const ptr = switch (ptr_ty.ptrSize(zcu)) { |
| ... | ... | @@ -3665,7 +3670,8 @@ fn airOverflow( |
| 3665 | 3670 | signed_intrinsic: Builder.Intrinsic, |
| 3666 | 3671 | unsigned_intrinsic: Builder.Intrinsic, |
| 3667 | 3672 | ) Allocator.Error!Builder.Value { |
| 3668 | | const zcu = self.object.zcu; |
| 3673 | const o = self.object; |
| 3674 | const zcu = o.zcu; |
| 3669 | 3675 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 3670 | 3676 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3671 | 3677 | |
| ... | ... | @@ -3678,8 +3684,8 @@ fn airOverflow( |
| 3678 | 3684 | assert(isByRef(inst_ty, zcu)); // auto structs are by-ref |
| 3679 | 3685 | |
| 3680 | 3686 | const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic; |
| 3681 | | const llvm_inst_ty = try self.lowerType(inst_ty); |
| 3682 | | const llvm_lhs_ty = try self.lowerType(lhs_ty); |
| 3687 | const llvm_inst_ty = try o.lowerType(inst_ty); |
| 3688 | const llvm_lhs_ty = try o.lowerType(lhs_ty); |
| 3683 | 3689 | const results = |
| 3684 | 3690 | try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, ""); |
| 3685 | 3691 | |
| ... | ... | @@ -3750,7 +3756,7 @@ fn buildFloatCmp( |
| 3750 | 3756 | const zcu = o.zcu; |
| 3751 | 3757 | const target = zcu.getTarget(); |
| 3752 | 3758 | const scalar_ty = ty.scalarType(zcu); |
| 3753 | | const scalar_llvm_ty = try self.lowerType(scalar_ty); |
| 3759 | const scalar_llvm_ty = try o.lowerType(scalar_ty); |
| 3754 | 3760 | |
| 3755 | 3761 | if (intrinsicsAllowed(scalar_ty, target)) { |
| 3756 | 3762 | const cond: Builder.FloatCondition = switch (pred) { |
| ... | ... | @@ -3856,7 +3862,7 @@ fn buildFloatOp( |
| 3856 | 3862 | const zcu = o.zcu; |
| 3857 | 3863 | const target = zcu.getTarget(); |
| 3858 | 3864 | const scalar_ty = ty.scalarType(zcu); |
| 3859 | | const llvm_ty = try self.lowerType(ty); |
| 3865 | const llvm_ty = try o.lowerType(ty); |
| 3860 | 3866 | |
| 3861 | 3867 | if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) { |
| 3862 | 3868 | // Some operations are dedicated LLVM instructions, not available as intrinsics |
| ... | ... | @@ -3993,7 +3999,8 @@ fn airMulAdd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 3993 | 3999 | } |
| 3994 | 4000 | |
| 3995 | 4001 | fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 3996 | | const zcu = self.object.zcu; |
| 4002 | const o = self.object; |
| 4003 | const zcu = o.zcu; |
| 3997 | 4004 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 3998 | 4005 | const extra = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3999 | 4006 | |
| ... | ... | @@ -4011,9 +4018,9 @@ fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Buil |
| 4011 | 4018 | |
| 4012 | 4019 | const dest_ty = self.typeOfIndex(inst); |
| 4013 | 4020 | assert(isByRef(dest_ty, zcu)); // auto structs are by-ref |
| 4014 | | const llvm_dest_ty = try self.lowerType(dest_ty); |
| 4021 | const llvm_dest_ty = try o.lowerType(dest_ty); |
| 4015 | 4022 | |
| 4016 | | const casted_rhs = try self.wip.conv(.unsigned, rhs, try self.lowerType(lhs_ty), ""); |
| 4023 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); |
| 4017 | 4024 | |
| 4018 | 4025 | const result = try self.wip.bin(.shl, lhs, casted_rhs, ""); |
| 4019 | 4026 | const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) |
| ... | ... | @@ -4063,7 +4070,8 @@ fn airXor(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4063 | 4070 | } |
| 4064 | 4071 | |
| 4065 | 4072 | fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4066 | | const zcu = self.object.zcu; |
| 4073 | const o = self.object; |
| 4074 | const zcu = o.zcu; |
| 4067 | 4075 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4068 | 4076 | |
| 4069 | 4077 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4077,7 +4085,7 @@ fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 4077 | 4085 | } |
| 4078 | 4086 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); |
| 4079 | 4087 | |
| 4080 | | const casted_rhs = try self.wip.conv(.unsigned, rhs, try self.lowerType(lhs_ty), ""); |
| 4088 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); |
| 4081 | 4089 | return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu)) |
| 4082 | 4090 | .@"shl nsw" |
| 4083 | 4091 | else |
| ... | ... | @@ -4085,7 +4093,8 @@ fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 4085 | 4093 | } |
| 4086 | 4094 | |
| 4087 | 4095 | fn airShl(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4088 | | const zcu = self.object.zcu; |
| 4096 | const o = self.object; |
| 4097 | const zcu = o.zcu; |
| 4089 | 4098 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4090 | 4099 | |
| 4091 | 4100 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4097,7 +4106,7 @@ fn airShl(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4097 | 4106 | // features which we do not use. Therefore this branch is currently impossible. |
| 4098 | 4107 | unreachable; |
| 4099 | 4108 | } |
| 4100 | | const casted_rhs = try self.wip.conv(.unsigned, rhs, try self.lowerType(lhs_ty), ""); |
| 4109 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); |
| 4101 | 4110 | return self.wip.bin(.shl, lhs, casted_rhs, ""); |
| 4102 | 4111 | } |
| 4103 | 4112 | |
| ... | ... | @@ -4111,7 +4120,7 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4111 | 4120 | |
| 4112 | 4121 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 4113 | 4122 | const lhs_info = lhs_ty.intInfo(zcu); |
| 4114 | | const llvm_lhs_ty = try self.lowerType(lhs_ty); |
| 4123 | const llvm_lhs_ty = try o.lowerType(lhs_ty); |
| 4115 | 4124 | const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder); |
| 4116 | 4125 | |
| 4117 | 4126 | const rhs_ty = self.typeOf(bin_op.rhs); |
| ... | ... | @@ -4122,7 +4131,7 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4122 | 4131 | } |
| 4123 | 4132 | const rhs_info = rhs_ty.intInfo(zcu); |
| 4124 | 4133 | assert(rhs_info.signedness == .unsigned); |
| 4125 | | const llvm_rhs_ty = try self.lowerType(rhs_ty); |
| 4134 | const llvm_rhs_ty = try o.lowerType(rhs_ty); |
| 4126 | 4135 | const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder); |
| 4127 | 4136 | |
| 4128 | 4137 | const result = try self.wip.callIntrinsic( |
| ... | ... | @@ -4184,7 +4193,8 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4184 | 4193 | } |
| 4185 | 4194 | |
| 4186 | 4195 | fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) Allocator.Error!Builder.Value { |
| 4187 | | const zcu = self.object.zcu; |
| 4196 | const o = self.object; |
| 4197 | const zcu = o.zcu; |
| 4188 | 4198 | const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4189 | 4199 | |
| 4190 | 4200 | const lhs = try self.resolveInst(bin_op.lhs); |
| ... | ... | @@ -4198,7 +4208,7 @@ fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) Allocator.Error! |
| 4198 | 4208 | } |
| 4199 | 4209 | const lhs_scalar_ty = lhs_ty.scalarType(zcu); |
| 4200 | 4210 | |
| 4201 | | const casted_rhs = try self.wip.conv(.unsigned, rhs, try self.lowerType(lhs_ty), ""); |
| 4211 | const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), ""); |
| 4202 | 4212 | const is_signed_int = lhs_scalar_ty.isSignedInt(zcu); |
| 4203 | 4213 | |
| 4204 | 4214 | return self.wip.bin(if (is_exact) |
| ... | ... | @@ -4219,7 +4229,7 @@ fn airAbs(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4219 | 4229 | .normal, |
| 4220 | 4230 | .none, |
| 4221 | 4231 | .abs, |
| 4222 | | &.{try self.lowerType(operand_ty)}, |
| 4232 | &.{try o.lowerType(operand_ty)}, |
| 4223 | 4233 | &.{ operand, try o.builder.intValue(.i1, 0) }, |
| 4224 | 4234 | "", |
| 4225 | 4235 | ), |
| ... | ... | @@ -4233,7 +4243,7 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error! |
| 4233 | 4243 | const zcu = o.zcu; |
| 4234 | 4244 | const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4235 | 4245 | const dest_ty = fg.typeOfIndex(inst); |
| 4236 | | const dest_llvm_ty = try fg.lowerType(dest_ty); |
| 4246 | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 4237 | 4247 | const operand = try fg.resolveInst(ty_op.operand); |
| 4238 | 4248 | const operand_ty = fg.typeOf(ty_op.operand); |
| 4239 | 4249 | const operand_info = operand_ty.intInfo(zcu); |
| ... | ... | @@ -4261,8 +4271,8 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error! |
| 4261 | 4271 | |
| 4262 | 4272 | if (!have_min_check and !have_max_check) break :bounds_check; |
| 4263 | 4273 | |
| 4264 | | const operand_llvm_ty = try fg.lowerType(operand_ty); |
| 4265 | | const operand_scalar_llvm_ty = try fg.lowerType(operand_scalar); |
| 4274 | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 4275 | const operand_scalar_llvm_ty = try o.lowerType(operand_scalar); |
| 4266 | 4276 | |
| 4267 | 4277 | const is_vector = operand_ty.zigTypeTag(zcu) == .vector; |
| 4268 | 4278 | assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector)); |
| ... | ... | @@ -4340,7 +4350,7 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error! |
| 4340 | 4350 | fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4341 | 4351 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4342 | 4352 | const operand = try self.resolveInst(ty_op.operand); |
| 4343 | | const dest_llvm_ty = try self.lowerType(self.typeOfIndex(inst)); |
| 4353 | const dest_llvm_ty = try self.object.lowerType(self.typeOfIndex(inst)); |
| 4344 | 4354 | return self.wip.cast(.trunc, operand, dest_llvm_ty, ""); |
| 4345 | 4355 | } |
| 4346 | 4356 | |
| ... | ... | @@ -4354,10 +4364,10 @@ fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 4354 | 4364 | const target = zcu.getTarget(); |
| 4355 | 4365 | |
| 4356 | 4366 | if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) { |
| 4357 | | return self.wip.cast(.fptrunc, operand, try self.lowerType(dest_ty), ""); |
| 4367 | return self.wip.cast(.fptrunc, operand, try o.lowerType(dest_ty), ""); |
| 4358 | 4368 | } else { |
| 4359 | | const operand_llvm_ty = try self.lowerType(operand_ty); |
| 4360 | | const dest_llvm_ty = try self.lowerType(dest_ty); |
| 4369 | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 4370 | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 4361 | 4371 | |
| 4362 | 4372 | const dest_bits = dest_ty.floatBits(target); |
| 4363 | 4373 | const src_bits = operand_ty.floatBits(target); |
| ... | ... | @@ -4388,10 +4398,10 @@ fn airFpext(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4388 | 4398 | const target = zcu.getTarget(); |
| 4389 | 4399 | |
| 4390 | 4400 | if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) { |
| 4391 | | return self.wip.cast(.fpext, operand, try self.lowerType(dest_ty), ""); |
| 4401 | return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), ""); |
| 4392 | 4402 | } else { |
| 4393 | | const operand_llvm_ty = try self.lowerType(operand_ty); |
| 4394 | | const dest_llvm_ty = try self.lowerType(dest_ty); |
| 4403 | const operand_llvm_ty = try o.lowerType(operand_ty); |
| 4404 | const dest_llvm_ty = try o.lowerType(dest_ty); |
| 4395 | 4405 | |
| 4396 | 4406 | const dest_bits = dest_ty.scalarType(zcu).floatBits(target); |
| 4397 | 4407 | const src_bits = operand_ty.scalarType(zcu).floatBits(target); |
| ... | ... | @@ -4431,7 +4441,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty |
| 4431 | 4441 | const zcu = o.zcu; |
| 4432 | 4442 | const operand_is_ref = isByRef(operand_ty, zcu); |
| 4433 | 4443 | const result_is_ref = isByRef(inst_ty, zcu); |
| 4434 | | const llvm_dest_ty = try self.lowerType(inst_ty); |
| 4444 | const llvm_dest_ty = try o.lowerType(inst_ty); |
| 4435 | 4445 | |
| 4436 | 4446 | if (operand_is_ref and result_is_ref) { |
| 4437 | 4447 | // They are both pointers, so just return the same opaque pointer :) |
| ... | ... | @@ -4477,7 +4487,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty |
| 4477 | 4487 | } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) { |
| 4478 | 4488 | const elem_ty = operand_ty.childType(zcu); |
| 4479 | 4489 | assert(operand_is_ref); // arrays are always by-ref provided they have runtime bits |
| 4480 | | const llvm_vector_ty = try self.lowerType(inst_ty); |
| 4490 | const llvm_vector_ty = try o.lowerType(inst_ty); |
| 4481 | 4491 | |
| 4482 | 4492 | const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8; |
| 4483 | 4493 | if (bitcast_ok) { |
| ... | ... | @@ -4488,7 +4498,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty |
| 4488 | 4498 | } else { |
| 4489 | 4499 | // If the ABI size of the element type is not evenly divisible by size in bits; |
| 4490 | 4500 | // a simple bitcast will not work, and we fall back to extractelement. |
| 4491 | | const elem_llvm_ty = try self.lowerType(elem_ty); |
| 4501 | const elem_llvm_ty = try o.lowerType(elem_ty); |
| 4492 | 4502 | const elem_size = elem_ty.abiSize(zcu); |
| 4493 | 4503 | const vector_len = operand_ty.arrayLen(zcu); |
| 4494 | 4504 | var vector = try o.builder.poisonValue(llvm_vector_ty); |
| ... | ... | @@ -4629,7 +4639,7 @@ fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4629 | 4639 | const ptr_info = ptr_ty.ptrInfo(zcu); |
| 4630 | 4640 | return (try o.lowerPtrToVoid(ptr_info.flags.alignment, ptr_info.flags.address_space)).toValue(); |
| 4631 | 4641 | } |
| 4632 | | const pointee_llvm_ty = try self.lowerType(pointee_type); |
| 4642 | const pointee_llvm_ty = try o.lowerType(pointee_type); |
| 4633 | 4643 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 4634 | 4644 | return self.buildAlloca(pointee_llvm_ty, alignment); |
| 4635 | 4645 | } |
| ... | ... | @@ -4644,7 +4654,7 @@ fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4644 | 4654 | return (try o.lowerPtrToVoid(ptr_info.flags.alignment, ptr_info.flags.address_space)).toValue(); |
| 4645 | 4655 | } |
| 4646 | 4656 | if (self.ret_ptr != .none) return self.ret_ptr; |
| 4647 | | const ret_llvm_ty = try self.lowerType(ret_ty); |
| 4657 | const ret_llvm_ty = try o.lowerType(ret_ty); |
| 4648 | 4658 | const alignment = ptr_ty.ptrAlignment(zcu).toLlvm(); |
| 4649 | 4659 | return self.buildAlloca(ret_llvm_ty, alignment); |
| 4650 | 4660 | } |
| ... | ... | @@ -4696,7 +4706,7 @@ fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error! |
| 4696 | 4706 | |
| 4697 | 4707 | self.maybeMarkAllowZeroAccess(ptr_info); |
| 4698 | 4708 | |
| 4699 | | const len = try o.builder.intValue(try self.lowerType(.usize), operand_ty.abiSize(zcu)); |
| 4709 | const len = try o.builder.intValue(try o.lowerType(.usize), operand_ty.abiSize(zcu)); |
| 4700 | 4710 | _ = try self.wip.callMemSet( |
| 4701 | 4711 | dest_ptr, |
| 4702 | 4712 | ptr_ty.ptrAlignment(zcu).toLlvm(), |
| ... | ... | @@ -4735,7 +4745,7 @@ fn airLoad(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4735 | 4745 | |
| 4736 | 4746 | if (ptr_info.flags.vector_index != .none) { |
| 4737 | 4747 | const index_u32 = try o.builder.intValue(.i32, ptr_info.flags.vector_index); |
| 4738 | | const vec_elem_ty = try fg.lowerType(elem_ty); |
| 4748 | const vec_elem_ty = try o.lowerType(elem_ty); |
| 4739 | 4749 | const vec_ty = try o.builder.vectorType(.normal, ptr_info.packed_offset.host_size, vec_elem_ty); |
| 4740 | 4750 | |
| 4741 | 4751 | const loaded_vector = try fg.wip.load(access_kind, vec_ty, ptr, llvm_ptr_align, ""); |
| ... | ... | @@ -4753,7 +4763,7 @@ fn airLoad(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4753 | 4763 | const elem_bits = ptr_ty.childType(zcu).bitSize(zcu); |
| 4754 | 4764 | const shift_amt = try o.builder.intValue(containing_int_ty, ptr_info.packed_offset.bit_offset); |
| 4755 | 4765 | const shifted_value = try fg.wip.bin(.lshr, containing_int, shift_amt, ""); |
| 4756 | | const elem_llvm_ty = try fg.lowerType(elem_ty); |
| 4766 | const elem_llvm_ty = try o.lowerType(elem_ty); |
| 4757 | 4767 | |
| 4758 | 4768 | if (isByRef(elem_ty, zcu)) { |
| 4759 | 4769 | const result_align = elem_ty.abiAlignment(zcu).toLlvm(); |
| ... | ... | @@ -4813,7 +4823,7 @@ fn airBreakpoint(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.V |
| 4813 | 4823 | fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4814 | 4824 | _ = inst; |
| 4815 | 4825 | const o = self.object; |
| 4816 | | const llvm_usize = try self.lowerType(.usize); |
| 4826 | const llvm_usize = try o.lowerType(.usize); |
| 4817 | 4827 | if (!target_util.supportsReturnAddress(self.object.zcu.getTarget(), self.ownerModule().optimize_mode)) { |
| 4818 | 4828 | // https://github.com/ziglang/zig/issues/11946 |
| 4819 | 4829 | return o.builder.intValue(llvm_usize, 0); |
| ... | ... | @@ -4825,7 +4835,7 @@ fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu |
| 4825 | 4835 | fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4826 | 4836 | _ = inst; |
| 4827 | 4837 | const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, ""); |
| 4828 | | return self.wip.cast(.ptrtoint, result, try self.lowerType(.usize), ""); |
| 4838 | return self.wip.cast(.ptrtoint, result, try self.object.lowerType(.usize), ""); |
| 4829 | 4839 | } |
| 4830 | 4840 | |
| 4831 | 4841 | fn airCmpxchg( |
| ... | ... | @@ -4842,7 +4852,7 @@ fn airCmpxchg( |
| 4842 | 4852 | var expected_value = try self.resolveInst(extra.expected_value); |
| 4843 | 4853 | var new_value = try self.resolveInst(extra.new_value); |
| 4844 | 4854 | const operand_ty = ptr_ty.childType(zcu); |
| 4845 | | const llvm_operand_ty = try self.lowerType(operand_ty); |
| 4855 | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 4846 | 4856 | const llvm_abi_ty = try self.getAtomicAbiType(operand_ty, false); |
| 4847 | 4857 | if (llvm_abi_ty != .none) { |
| 4848 | 4858 | // operand needs widening and truncating |
| ... | ... | @@ -4885,7 +4895,7 @@ fn airCmpxchg( |
| 4885 | 4895 | const non_null_bit = try self.wip.not(success_bit, ""); |
| 4886 | 4896 | |
| 4887 | 4897 | const payload_align = operand_ty.abiAlignment(zcu).toLlvm(); |
| 4888 | | const alloca_inst = try self.buildAlloca(try self.lowerType(optional_ty), payload_align); |
| 4898 | const alloca_inst = try self.buildAlloca(try o.lowerType(optional_ty), payload_align); |
| 4889 | 4899 | |
| 4890 | 4900 | // Payload is always the first field at offset 0, so address is `alloca_inst` |
| 4891 | 4901 | _ = try self.wip.store(.normal, payload, alloca_inst, payload_align); |
| ... | ... | @@ -4911,7 +4921,7 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va |
| 4911 | 4921 | const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float); |
| 4912 | 4922 | const ordering = toLlvmAtomicOrdering(extra.ordering()); |
| 4913 | 4923 | const llvm_abi_ty = try self.getAtomicAbiType(operand_ty, op == .xchg); |
| 4914 | | const llvm_operand_ty = try self.lowerType(operand_ty); |
| 4924 | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 4915 | 4925 | |
| 4916 | 4926 | const access_kind: Builder.MemoryAccessKind = |
| 4917 | 4927 | if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; |
| ... | ... | @@ -4954,7 +4964,7 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va |
| 4954 | 4964 | access_kind, |
| 4955 | 4965 | op, |
| 4956 | 4966 | ptr, |
| 4957 | | try self.wip.cast(.ptrtoint, operand, try self.lowerType(.usize), ""), |
| 4967 | try self.wip.cast(.ptrtoint, operand, try o.lowerType(.usize), ""), |
| 4958 | 4968 | self.sync_scope, |
| 4959 | 4969 | ordering, |
| 4960 | 4970 | ptr_alignment, |
| ... | ... | @@ -4963,7 +4973,8 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va |
| 4963 | 4973 | } |
| 4964 | 4974 | |
| 4965 | 4975 | fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 4966 | | const zcu = self.object.zcu; |
| 4976 | const o = self.object; |
| 4977 | const zcu = o.zcu; |
| 4967 | 4978 | const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; |
| 4968 | 4979 | const ptr = try self.resolveInst(atomic_load.ptr); |
| 4969 | 4980 | const ptr_ty = self.typeOf(atomic_load.ptr); |
| ... | ... | @@ -4978,7 +4989,7 @@ fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.V |
| 4978 | 4989 | Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm(); |
| 4979 | 4990 | const access_kind: Builder.MemoryAccessKind = |
| 4980 | 4991 | if (info.flags.is_volatile) .@"volatile" else .normal; |
| 4981 | | const elem_llvm_ty = try self.lowerType(elem_ty); |
| 4992 | const elem_llvm_ty = try o.lowerType(elem_ty); |
| 4982 | 4993 | |
| 4983 | 4994 | self.maybeMarkAllowZeroAccess(info); |
| 4984 | 4995 | |
| ... | ... | @@ -5135,7 +5146,7 @@ fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error |
| 5135 | 5146 | const body_block = try self.wip.block(1, "InlineMemsetBody"); |
| 5136 | 5147 | const end_block = try self.wip.block(1, "InlineMemsetEnd"); |
| 5137 | 5148 | |
| 5138 | | const llvm_usize_ty = try self.lowerType(.usize); |
| 5149 | const llvm_usize_ty = try o.lowerType(.usize); |
| 5139 | 5150 | const end_ptr = switch (ptr_ty.ptrSize(zcu)) { |
| 5140 | 5151 | .slice => try self.ptraddScaled( |
| 5141 | 5152 | dest_ptr, |
| ... | ... | @@ -5265,7 +5276,7 @@ fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder. |
| 5265 | 5276 | assert(layout.tag_size != 0); |
| 5266 | 5277 | const union_ptr = try self.resolveInst(ty_op.operand); |
| 5267 | 5278 | if (isByRef(un_ty, zcu)) { |
| 5268 | | const llvm_un_ty = try self.lowerType(un_ty); |
| 5279 | const llvm_un_ty = try o.lowerType(un_ty); |
| 5269 | 5280 | if (layout.payload_size == 0) |
| 5270 | 5281 | return self.wip.load(.normal, llvm_un_ty, union_ptr, .default, ""); |
| 5271 | 5282 | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| ... | ... | @@ -5296,6 +5307,7 @@ fn airNeg(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo |
| 5296 | 5307 | } |
| 5297 | 5308 | |
| 5298 | 5309 | fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) Allocator.Error!Builder.Value { |
| 5310 | const o = self.object; |
| 5299 | 5311 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5300 | 5312 | const inst_ty = self.typeOfIndex(inst); |
| 5301 | 5313 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -5305,14 +5317,15 @@ fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) |
| 5305 | 5317 | .normal, |
| 5306 | 5318 | .none, |
| 5307 | 5319 | intrinsic, |
| 5308 | | &.{try self.lowerType(operand_ty)}, |
| 5320 | &.{try o.lowerType(operand_ty)}, |
| 5309 | 5321 | &.{ operand, .false }, |
| 5310 | 5322 | "", |
| 5311 | 5323 | ); |
| 5312 | | return self.wip.conv(.unsigned, result, try self.lowerType(inst_ty), ""); |
| 5324 | return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), ""); |
| 5313 | 5325 | } |
| 5314 | 5326 | |
| 5315 | 5327 | fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) Allocator.Error!Builder.Value { |
| 5328 | const o = self.object; |
| 5316 | 5329 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5317 | 5330 | const inst_ty = self.typeOfIndex(inst); |
| 5318 | 5331 | const operand_ty = self.typeOf(ty_op.operand); |
| ... | ... | @@ -5322,11 +5335,11 @@ fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) |
| 5322 | 5335 | .normal, |
| 5323 | 5336 | .none, |
| 5324 | 5337 | intrinsic, |
| 5325 | | &.{try self.lowerType(operand_ty)}, |
| 5338 | &.{try o.lowerType(operand_ty)}, |
| 5326 | 5339 | &.{operand}, |
| 5327 | 5340 | "", |
| 5328 | 5341 | ); |
| 5329 | | return self.wip.conv(.unsigned, result, try self.lowerType(inst_ty), ""); |
| 5342 | return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), ""); |
| 5330 | 5343 | } |
| 5331 | 5344 | |
| 5332 | 5345 | fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| ... | ... | @@ -5339,7 +5352,7 @@ fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 5339 | 5352 | |
| 5340 | 5353 | const inst_ty = self.typeOfIndex(inst); |
| 5341 | 5354 | var operand = try self.resolveInst(ty_op.operand); |
| 5342 | | var llvm_operand_ty = try self.lowerType(operand_ty); |
| 5355 | var llvm_operand_ty = try o.lowerType(operand_ty); |
| 5343 | 5356 | |
| 5344 | 5357 | if (bits % 16 == 8) { |
| 5345 | 5358 | // If not an even byte-multiple, we need zero-extend + shift-left 1 byte |
| ... | ... | @@ -5360,7 +5373,7 @@ fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 5360 | 5373 | |
| 5361 | 5374 | const result = |
| 5362 | 5375 | try self.wip.callIntrinsic(.normal, .none, .bswap, &.{llvm_operand_ty}, &.{operand}, ""); |
| 5363 | | return self.wip.conv(.unsigned, result, try self.lowerType(inst_ty), ""); |
| 5376 | return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), ""); |
| 5364 | 5377 | } |
| 5365 | 5378 | |
| 5366 | 5379 | fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| ... | ... | @@ -5437,10 +5450,10 @@ fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va |
| 5437 | 5450 | const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 5438 | 5451 | const operand = try self.resolveInst(un_op); |
| 5439 | 5452 | const slice_ty = self.typeOfIndex(inst); |
| 5440 | | const slice_llvm_ty = try self.lowerType(slice_ty); |
| 5453 | const slice_llvm_ty = try o.lowerType(slice_ty); |
| 5441 | 5454 | |
| 5442 | 5455 | // If operand is small (e.g. `u8`), then signedness becomes a problem -- GEP always treats the index as signed. |
| 5443 | | const operand_usize = try self.wip.conv(.unsigned, operand, try self.lowerType(.usize), ""); |
| 5456 | const operand_usize = try self.wip.conv(.unsigned, operand, try o.lowerType(.usize), ""); |
| 5444 | 5457 | |
| 5445 | 5458 | const error_name_table_ptr = try o.getErrorNameTable(); |
| 5446 | 5459 | const error_name_ptr = try self.ptraddScaled(error_name_table_ptr.toValue(&o.builder), operand_usize, slice_ty.abiSize(zcu)); |
| ... | ... | @@ -5451,7 +5464,7 @@ fn airSplat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 5451 | 5464 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5452 | 5465 | const scalar = try self.resolveInst(ty_op.operand); |
| 5453 | 5466 | const vector_ty = self.typeOfIndex(inst); |
| 5454 | | return self.wip.splatVector(try self.lowerType(vector_ty), scalar, ""); |
| 5467 | return self.wip.splatVector(try self.object.lowerType(vector_ty), scalar, ""); |
| 5455 | 5468 | } |
| 5456 | 5469 | |
| 5457 | 5470 | fn airSelect(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| ... | ... | @@ -5474,9 +5487,9 @@ fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 5474 | 5487 | const operand = try fg.resolveInst(unwrapped.operand); |
| 5475 | 5488 | const mask = unwrapped.mask; |
| 5476 | 5489 | const operand_ty = fg.typeOf(unwrapped.operand); |
| 5477 | | const llvm_operand_ty = try fg.lowerType(operand_ty); |
| 5478 | | const llvm_result_ty = try fg.lowerType(unwrapped.result_ty); |
| 5479 | | const llvm_elem_ty = try fg.lowerType(unwrapped.result_ty.childType(zcu)); |
| 5490 | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 5491 | const llvm_result_ty = try o.lowerType(unwrapped.result_ty); |
| 5492 | const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu)); |
| 5480 | 5493 | const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty); |
| 5481 | 5494 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); |
| 5482 | 5495 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); |
| ... | ... | @@ -5578,7 +5591,7 @@ fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val |
| 5578 | 5591 | const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst); |
| 5579 | 5592 | |
| 5580 | 5593 | const mask = unwrapped.mask; |
| 5581 | | const llvm_elem_ty = try fg.lowerType(unwrapped.result_ty.childType(zcu)); |
| 5594 | const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu)); |
| 5582 | 5595 | const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32); |
| 5583 | 5596 | const llvm_poison_mask_elem = try o.builder.poisonConst(.i32); |
| 5584 | 5597 | |
| ... | ... | @@ -5670,7 +5683,7 @@ fn buildReducedCall( |
| 5670 | 5683 | accum_init: Builder.Value, |
| 5671 | 5684 | ) Allocator.Error!Builder.Value { |
| 5672 | 5685 | const o = self.object; |
| 5673 | | const usize_ty = try self.lowerType(.usize); |
| 5686 | const usize_ty = try o.lowerType(.usize); |
| 5674 | 5687 | const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len); |
| 5675 | 5688 | const llvm_result_ty = accum_init.typeOfWip(&self.wip); |
| 5676 | 5689 | |
| ... | ... | @@ -5730,9 +5743,9 @@ fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) A |
| 5730 | 5743 | const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce; |
| 5731 | 5744 | const operand = try self.resolveInst(reduce.operand); |
| 5732 | 5745 | const operand_ty = self.typeOf(reduce.operand); |
| 5733 | | const llvm_operand_ty = try self.lowerType(operand_ty); |
| 5746 | const llvm_operand_ty = try o.lowerType(operand_ty); |
| 5734 | 5747 | const scalar_ty = self.typeOfIndex(inst); |
| 5735 | | const llvm_scalar_ty = try self.lowerType(scalar_ty); |
| 5748 | const llvm_scalar_ty = try o.lowerType(scalar_ty); |
| 5736 | 5749 | |
| 5737 | 5750 | switch (reduce.operation) { |
| 5738 | 5751 | .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) { |
| ... | ... | @@ -5839,7 +5852,7 @@ fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde |
| 5839 | 5852 | const result_ty = self.typeOfIndex(inst); |
| 5840 | 5853 | const len: usize = @intCast(result_ty.arrayLen(zcu)); |
| 5841 | 5854 | const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[ty_pl.payload..][0..len]); |
| 5842 | | const llvm_result_ty = try self.lowerType(result_ty); |
| 5855 | const llvm_result_ty = try o.lowerType(result_ty); |
| 5843 | 5856 | |
| 5844 | 5857 | switch (result_ty.zigTypeTag(zcu)) { |
| 5845 | 5858 | .vector => { |
| ... | ... | @@ -5905,7 +5918,7 @@ fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde |
| 5905 | 5918 | field_ptr_align.toLlvm(), |
| 5906 | 5919 | llvm_field_val, |
| 5907 | 5920 | field_ty.abiAlignment(zcu).toLlvm(), |
| 5908 | | try o.builder.intValue(try self.lowerType(.usize), field_ty.abiSize(zcu)), |
| 5921 | try o.builder.intValue(try o.lowerType(.usize), field_ty.abiSize(zcu)), |
| 5909 | 5922 | .normal, |
| 5910 | 5923 | self.disable_intrinsics, |
| 5911 | 5924 | ); |
| ... | ... | @@ -5956,7 +5969,7 @@ fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va |
| 5956 | 5969 | const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 5957 | 5970 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 5958 | 5971 | const union_ty = self.typeOfIndex(inst); |
| 5959 | | const union_llvm_ty = try self.lowerType(union_ty); |
| 5972 | const union_llvm_ty = try o.lowerType(union_ty); |
| 5960 | 5973 | const union_obj = zcu.typeToUnion(union_ty).?; |
| 5961 | 5974 | |
| 5962 | 5975 | assert(union_obj.layout != .@"packed"); |
| ... | ... | @@ -6046,8 +6059,7 @@ fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde |
| 6046 | 6059 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6047 | 6060 | const inst_ty = self.typeOfIndex(inst); |
| 6048 | 6061 | const operand = try self.resolveInst(ty_op.operand); |
| 6049 | | |
| 6050 | | return self.wip.cast(.addrspacecast, operand, try self.lowerType(inst_ty), ""); |
| 6062 | return self.wip.cast(.addrspacecast, operand, try self.object.lowerType(inst_ty), ""); |
| 6051 | 6063 | } |
| 6052 | 6064 | |
| 6053 | 6065 | fn workIntrinsic( |
| ... | ... | @@ -6192,7 +6204,7 @@ fn loadTruncate( |
| 6192 | 6204 | |
| 6193 | 6205 | const o = fg.object; |
| 6194 | 6206 | const zcu = o.zcu; |
| 6195 | | const payload_llvm_ty = try fg.lowerType(payload_ty); |
| 6207 | const payload_llvm_ty = try o.lowerType(payload_ty); |
| 6196 | 6208 | const abi_size = payload_ty.abiSize(zcu); |
| 6197 | 6209 | |
| 6198 | 6210 | const load_llvm_ty = if (payload_ty.isAbiInt(zcu)) |
| ... | ... | @@ -6220,7 +6232,7 @@ fn loadByRef( |
| 6220 | 6232 | access_kind: Builder.MemoryAccessKind, |
| 6221 | 6233 | ) Allocator.Error!Builder.Value { |
| 6222 | 6234 | const o = fg.object; |
| 6223 | | const pointee_llvm_ty = try fg.lowerType(pointee_type); |
| 6235 | const pointee_llvm_ty = try o.lowerType(pointee_type); |
| 6224 | 6236 | const result_align = InternPool.Alignment.fromLlvm(ptr_alignment) |
| 6225 | 6237 | .max(pointee_type.abiAlignment(o.zcu)).toLlvm(); |
| 6226 | 6238 | const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align); |
| ... | ... | @@ -6230,7 +6242,7 @@ fn loadByRef( |
| 6230 | 6242 | result_align, |
| 6231 | 6243 | ptr, |
| 6232 | 6244 | ptr_alignment, |
| 6233 | | try o.builder.intValue(try fg.lowerType(.usize), size_bytes), |
| 6245 | try o.builder.intValue(try o.lowerType(.usize), size_bytes), |
| 6234 | 6246 | access_kind, |
| 6235 | 6247 | fg.disable_intrinsics, |
| 6236 | 6248 | ); |
| ... | ... | @@ -6274,7 +6286,7 @@ fn storeFull( |
| 6274 | 6286 | |
| 6275 | 6287 | if (info.flags.vector_index != .none) { |
| 6276 | 6288 | const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index); |
| 6277 | | const vec_elem_ty = try self.lowerType(elem_ty); |
| 6289 | const vec_elem_ty = try o.lowerType(elem_ty); |
| 6278 | 6290 | const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty); |
| 6279 | 6291 | |
| 6280 | 6292 | const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, ""); |
| ... | ... | @@ -6343,7 +6355,7 @@ fn storeFull( |
| 6343 | 6355 | ptr_alignment, |
| 6344 | 6356 | elem, |
| 6345 | 6357 | elem_ty.abiAlignment(zcu).toLlvm(), |
| 6346 | | try o.builder.intValue(try self.lowerType(.usize), elem_ty.abiSize(zcu)), |
| 6358 | try o.builder.intValue(try o.lowerType(.usize), elem_ty.abiSize(zcu)), |
| 6347 | 6359 | access_kind, |
| 6348 | 6360 | self.disable_intrinsics, |
| 6349 | 6361 | ); |
| ... | ... | @@ -6370,7 +6382,7 @@ fn store( |
| 6370 | 6382 | elem, |
| 6371 | 6383 | elem_ty.abiAlignment(zcu).toLlvm(), |
| 6372 | 6384 | try o.builder.intValue( |
| 6373 | | try fg.lowerType(.usize), |
| 6385 | try o.lowerType(.usize), |
| 6374 | 6386 | elem_ty.abiSize(zcu), |
| 6375 | 6387 | ), |
| 6376 | 6388 | .normal, |
| ... | ... | @@ -6391,7 +6403,7 @@ fn store( |
| 6391 | 6403 | fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void { |
| 6392 | 6404 | const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545; |
| 6393 | 6405 | const o = fg.object; |
| 6394 | | const usize_ty = try fg.lowerType(.usize); |
| 6406 | const usize_ty = try o.lowerType(.usize); |
| 6395 | 6407 | const zero = try o.builder.intValue(usize_ty, 0); |
| 6396 | 6408 | const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED); |
| 6397 | 6409 | const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, ""); |
| ... | ... | @@ -6413,7 +6425,7 @@ fn valgrindClientRequest( |
| 6413 | 6425 | const target = zcu.getTarget(); |
| 6414 | 6426 | if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value; |
| 6415 | 6427 | |
| 6416 | | const llvm_usize = try fg.lowerType(.usize); |
| 6428 | const llvm_usize = try o.lowerType(.usize); |
| 6417 | 6429 | const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm(); |
| 6418 | 6430 | |
| 6419 | 6431 | const array_llvm_ty = try o.builder.arrayType(6, llvm_usize); |
| ... | ... | @@ -7261,8 +7273,9 @@ fn getAtomicAbiType(fg: *const FuncGen, ty: Type, is_rmw_xchg: bool) Allocator.E |
| 7261 | 7273 | |
| 7262 | 7274 | fn ptraddConst(fg: *FuncGen, ptr: Builder.Value, offset: u64) Allocator.Error!Builder.Value { |
| 7263 | 7275 | if (offset == 0) return ptr; |
| 7264 | | const llvm_usize_ty = try fg.lowerType(.usize); |
| 7265 | | const offset_val = try fg.object.builder.intValue(llvm_usize_ty, offset); |
| 7276 | const o = fg.object; |
| 7277 | const llvm_usize_ty = try o.lowerType(.usize); |
| 7278 | const offset_val = try o.builder.intValue(llvm_usize_ty, offset); |
| 7266 | 7279 | return fg.wip.gep(.inbounds, .i8, ptr, &.{offset_val}, ""); |
| 7267 | 7280 | } |
| 7268 | 7281 | fn ptraddScaled(fg: *FuncGen, ptr: Builder.Value, index: Builder.Value, scale: u64) Allocator.Error!Builder.Value { |