| ... | ... | @@ -16,8 +16,8 @@ scope: Builder.Metadata, |
| 16 | 16 | inlined_at: Builder.Metadata.Optional, |
| 17 | 17 | |
| 18 | 18 | base_line: u32, |
| 19 | | prev_dbg_line: c_uint, |
| 20 | | prev_dbg_column: c_uint, |
| 19 | prev_dbg_line: u32, |
| 20 | prev_dbg_column: u32, |
| 21 | 21 | |
| 22 | 22 | /// This stores the LLVM values used in a function, such that they can be referred to |
| 23 | 23 | /// in other instructions. This table is cleared before every function is generated. |
| ... | ... | @@ -815,7 +815,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 815 | 815 | .always_tail => .musttail, |
| 816 | 816 | .no_suspend, .always_inline, .compile_time => unreachable, |
| 817 | 817 | }, |
| 818 | | toLlvmCallConvTag(fn_info.cc, target).?, |
| 818 | llvm.toLlvmCallConvTag(fn_info.cc, target).?, |
| 819 | 819 | try attributes.finish(&o.builder), |
| 820 | 820 | try o.lowerType(zig_fn_ty), |
| 821 | 821 | llvm_fn, |
| ... | ... | @@ -882,7 +882,7 @@ fn buildSimplePanic(fg: *FuncGen, panic_id: Zcu.SimplePanicId) Allocator.Error!v |
| 882 | 882 | _ = try fg.wip.callIntrinsicAssumeCold(); |
| 883 | 883 | _ = try fg.wip.call( |
| 884 | 884 | .normal, |
| 885 | | toLlvmCallConvTag(fn_info.cc, target).?, |
| 885 | llvm.toLlvmCallConvTag(fn_info.cc, target).?, |
| 886 | 886 | .none, |
| 887 | 887 | panic_global.typeOf(&o.builder), |
| 888 | 888 | panic_global.toValue(&o.builder), |
| ... | ... | @@ -1394,7 +1394,7 @@ fn lowerSwitchDispatch( |
| 1394 | 1394 | // be handled by conditional branches in the `else` prong. |
| 1395 | 1395 | |
| 1396 | 1396 | const llvm_usize = try o.lowerType(.usize); |
| 1397 | | const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder)) |
| 1397 | const cond_int = if (cond_ty.zigTypeTag(zcu) == .pointer) |
| 1398 | 1398 | try self.wip.cast(.ptrtoint, cond, llvm_usize, "") |
| 1399 | 1399 | else |
| 1400 | 1400 | cond; |
| ... | ... | @@ -1433,7 +1433,7 @@ fn lowerSwitchDispatch( |
| 1433 | 1433 | |
| 1434 | 1434 | for (case.items) |item| { |
| 1435 | 1435 | const llvm_item = (try self.resolveInst(item)).toConst().?; |
| 1436 | | const llvm_int_item = if (llvm_item.typeOf(&o.builder).isPointer(&o.builder)) |
| 1436 | const llvm_int_item = if (cond_ty.zigTypeTag(zcu) == .pointer) |
| 1437 | 1437 | try o.builder.castConst(.ptrtoint, llvm_item, llvm_usize) |
| 1438 | 1438 | else |
| 1439 | 1439 | llvm_item; |
| ... | ... | @@ -2840,7 +2840,7 @@ fn airIsNonNull( |
| 2840 | 2840 | operand; |
| 2841 | 2841 | if (payload_ty.isSlice(zcu)) { |
| 2842 | 2842 | const slice_ptr = try self.wip.extractValue(loaded, &.{0}, ""); |
| 2843 | | const ptr_ty = try o.builder.ptrType(toLlvmAddressSpace( |
| 2843 | const ptr_ty = try o.builder.ptrType(llvm.toLlvmAddressSpace( |
| 2844 | 2844 | payload_ty.ptrAddressSpace(zcu), |
| 2845 | 2845 | zcu.getTarget(), |
| 2846 | 2846 | )); |
| ... | ... | @@ -3342,17 +3342,17 @@ fn airSafeArithmetic( |
| 3342 | 3342 | |
| 3343 | 3343 | const overflow_bits = try fg.wip.extractValue(results, &.{1}, ""); |
| 3344 | 3344 | const overflow_bits_ty = overflow_bits.typeOfWip(&fg.wip); |
| 3345 | | const overflow_bit = if (overflow_bits_ty.isVector(&o.builder)) |
| 3346 | | try fg.wip.callIntrinsic( |
| 3345 | const overflow_bit = switch (inst_ty.zigTypeTag(zcu)) { |
| 3346 | .vector => try fg.wip.callIntrinsic( |
| 3347 | 3347 | .normal, |
| 3348 | 3348 | .none, |
| 3349 | 3349 | .@"vector.reduce.or", |
| 3350 | 3350 | &.{overflow_bits_ty}, |
| 3351 | 3351 | &.{overflow_bits}, |
| 3352 | 3352 | "", |
| 3353 | | ) |
| 3354 | | else |
| 3355 | | overflow_bits; |
| 3353 | ), |
| 3354 | else => overflow_bits, |
| 3355 | }; |
| 3356 | 3356 | |
| 3357 | 3357 | const fail_block = try fg.wip.block(1, "OverflowFail"); |
| 3358 | 3358 | const ok_block = try fg.wip.block(1, "OverflowOk"); |
| ... | ... | @@ -3508,6 +3508,7 @@ fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) |
| 3508 | 3508 | return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result}); |
| 3509 | 3509 | } |
| 3510 | 3510 | if (scalar_ty.isSignedInt(zcu)) { |
| 3511 | const scalar_llvm_ty = try o.lowerType(scalar_ty); |
| 3511 | 3512 | const inst_llvm_ty = try o.lowerType(inst_ty); |
| 3512 | 3513 | |
| 3513 | 3514 | const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb; |
| ... | ... | @@ -3517,7 +3518,7 @@ fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) |
| 3517 | 3518 | )) = std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa); |
| 3518 | 3519 | const allocator = stack.get(); |
| 3519 | 3520 | |
| 3520 | | const scalar_bits = inst_llvm_ty.scalarBits(&o.builder); |
| 3521 | const scalar_bits = scalar_ty.intInfo(zcu).bits; |
| 3521 | 3522 | var smin_big_int: std.math.big.int.Mutable = .{ |
| 3522 | 3523 | .limbs = try allocator.alloc( |
| 3523 | 3524 | std.math.big.Limb, |
| ... | ... | @@ -3529,7 +3530,7 @@ fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) |
| 3529 | 3530 | defer allocator.free(smin_big_int.limbs); |
| 3530 | 3531 | smin_big_int.setTwosCompIntLimit(.min, .signed, scalar_bits); |
| 3531 | 3532 | const smin = try o.builder.splatValue(inst_llvm_ty, try o.builder.bigIntConst( |
| 3532 | | inst_llvm_ty.scalarType(&o.builder), |
| 3533 | scalar_llvm_ty, |
| 3533 | 3534 | smin_big_int.toConst(), |
| 3534 | 3535 | )); |
| 3535 | 3536 | |
| ... | ... | @@ -3603,7 +3604,7 @@ fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo |
| 3603 | 3604 | )) = std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa); |
| 3604 | 3605 | const allocator = stack.get(); |
| 3605 | 3606 | |
| 3606 | | const scalar_bits = inst_llvm_ty.scalarBits(&o.builder); |
| 3607 | const scalar_bits = scalar_ty.intInfo(zcu).bits; |
| 3607 | 3608 | var smin_big_int: std.math.big.int.Mutable = .{ |
| 3608 | 3609 | .limbs = try allocator.alloc( |
| 3609 | 3610 | std.math.big.Limb, |
| ... | ... | @@ -3615,7 +3616,7 @@ fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo |
| 3615 | 3616 | defer allocator.free(smin_big_int.limbs); |
| 3616 | 3617 | smin_big_int.setTwosCompIntLimit(.min, .signed, scalar_bits); |
| 3617 | 3618 | const smin = try o.builder.splatValue(inst_llvm_ty, try o.builder.bigIntConst( |
| 3618 | | inst_llvm_ty.scalarType(&o.builder), |
| 3619 | try o.lowerType(scalar_ty), |
| 3619 | 3620 | smin_big_int.toConst(), |
| 3620 | 3621 | )); |
| 3621 | 3622 | |
| ... | ... | @@ -3929,7 +3930,10 @@ fn buildFloatOp( |
| 3929 | 3930 | // In this case we can generate a softfloat negation by XORing the |
| 3930 | 3931 | // bits with a constant. |
| 3931 | 3932 | const int_ty = try o.builder.intType(@intCast(float_bits)); |
| 3932 | | const cast_ty = try llvm_ty.changeScalar(int_ty, &o.builder); |
| 3933 | const cast_ty = switch (ty.zigTypeTag(zcu)) { |
| 3934 | .vector => try o.builder.vectorType(.normal, ty.vectorLen(zcu), int_ty), |
| 3935 | else => int_ty, |
| 3936 | }; |
| 3933 | 3937 | const sign_mask = try o.builder.splatValue( |
| 3934 | 3938 | cast_ty, |
| 3935 | 3939 | try o.builder.intConst(int_ty, @as(u128, 1) << @intCast(float_bits - 1)), |
| ... | ... | @@ -3964,7 +3968,7 @@ fn buildFloatOp( |
| 3964 | 3968 | }), |
| 3965 | 3969 | }; |
| 3966 | 3970 | |
| 3967 | | const scalar_llvm_ty = llvm_ty.scalarType(&o.builder); |
| 3971 | const scalar_llvm_ty = try o.lowerType(scalar_ty); |
| 3968 | 3972 | const libc_fn = try o.getLibcFunction( |
| 3969 | 3973 | fn_name, |
| 3970 | 3974 | ([1]Builder.Type{scalar_llvm_ty} ** 3)[0..params.len], |
| ... | ... | @@ -4121,7 +4125,7 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4121 | 4125 | const lhs_ty = self.typeOf(bin_op.lhs); |
| 4122 | 4126 | const lhs_info = lhs_ty.intInfo(zcu); |
| 4123 | 4127 | const llvm_lhs_ty = try o.lowerType(lhs_ty); |
| 4124 | | const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder); |
| 4128 | const llvm_lhs_scalar_ty = try o.lowerType(lhs_ty.scalarType(zcu)); |
| 4125 | 4129 | |
| 4126 | 4130 | const rhs_ty = self.typeOf(bin_op.rhs); |
| 4127 | 4131 | if (lhs_ty.isVector(zcu) and !rhs_ty.isVector(zcu)) { |
| ... | ... | @@ -4132,7 +4136,7 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value |
| 4132 | 4136 | const rhs_info = rhs_ty.intInfo(zcu); |
| 4133 | 4137 | assert(rhs_info.signedness == .unsigned); |
| 4134 | 4138 | const llvm_rhs_ty = try o.lowerType(rhs_ty); |
| 4135 | | const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder); |
| 4139 | const llvm_rhs_scalar_ty = try o.lowerType(rhs_ty.scalarType(zcu)); |
| 4136 | 4140 | |
| 4137 | 4141 | const result = try self.wip.callIntrinsic( |
| 4138 | 4142 | .normal, |
| ... | ... | @@ -4448,9 +4452,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty |
| 4448 | 4452 | return operand; |
| 4449 | 4453 | } |
| 4450 | 4454 | |
| 4451 | | if (llvm_dest_ty.isInteger(&o.builder) and |
| 4452 | | operand.typeOfWip(&self.wip).isInteger(&o.builder)) |
| 4453 | | { |
| 4455 | if (inst_ty.isAbiInt(zcu) and operand_ty.isAbiInt(zcu)) { |
| 4454 | 4456 | return self.wip.conv(.unsigned, operand, llvm_dest_ty, ""); |
| 4455 | 4457 | } |
| 4456 | 4458 | |
| ... | ... | @@ -4524,7 +4526,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty |
| 4524 | 4526 | return result_ptr; |
| 4525 | 4527 | } |
| 4526 | 4528 | |
| 4527 | | if (llvm_dest_ty.isStruct(&o.builder) or |
| 4529 | if (inst_ty.isSliceAtRuntime(zcu) or |
| 4528 | 4530 | ((operand_ty.zigTypeTag(zcu) == .vector or inst_ty.zigTypeTag(zcu) == .vector) and |
| 4529 | 4531 | operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu))) |
| 4530 | 4532 | { |
| ... | ... | @@ -4948,28 +4950,28 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va |
| 4948 | 4950 | ), llvm_operand_ty, ""); |
| 4949 | 4951 | } |
| 4950 | 4952 | |
| 4951 | | if (!llvm_operand_ty.isPointer(&o.builder)) return self.wip.atomicrmw( |
| 4953 | // If we are storing a pointer we need to convert to and from a plain old integer. |
| 4954 | const non_ptr_operand = switch (operand_ty.zigTypeTag(zcu)) { |
| 4955 | .pointer => try self.wip.cast(.ptrtoint, operand, try o.lowerType(.usize), ""), |
| 4956 | else => operand, |
| 4957 | }; |
| 4958 | |
| 4959 | const raw_result = try self.wip.atomicrmw( |
| 4952 | 4960 | access_kind, |
| 4953 | 4961 | op, |
| 4954 | 4962 | ptr, |
| 4955 | | operand, |
| 4963 | non_ptr_operand, |
| 4956 | 4964 | self.sync_scope, |
| 4957 | 4965 | ordering, |
| 4958 | 4966 | ptr_alignment, |
| 4959 | 4967 | "", |
| 4960 | 4968 | ); |
| 4961 | 4969 | |
| 4962 | | // It's a pointer but we need to treat it as an int. |
| 4963 | | return self.wip.cast(.inttoptr, try self.wip.atomicrmw( |
| 4964 | | access_kind, |
| 4965 | | op, |
| 4966 | | ptr, |
| 4967 | | try self.wip.cast(.ptrtoint, operand, try o.lowerType(.usize), ""), |
| 4968 | | self.sync_scope, |
| 4969 | | ordering, |
| 4970 | | ptr_alignment, |
| 4971 | | "", |
| 4972 | | ), llvm_operand_ty, ""); |
| 4970 | // ...and then convert the result back. |
| 4971 | switch (operand_ty.zigTypeTag(zcu)) { |
| 4972 | .pointer => return self.wip.cast(.inttoptr, raw_result, llvm_operand_ty, ""), |
| 4973 | else => return raw_result, |
| 4974 | } |
| 4973 | 4975 | } |
| 4974 | 4976 | |
| 4975 | 4977 | fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| ... | ... | @@ -5274,19 +5276,16 @@ fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder. |
| 5274 | 5276 | const un_ty = self.typeOf(ty_op.operand); |
| 5275 | 5277 | const layout = un_ty.unionGetLayout(zcu); |
| 5276 | 5278 | assert(layout.tag_size != 0); |
| 5277 | | const union_ptr = try self.resolveInst(ty_op.operand); |
| 5279 | const operand = try self.resolveInst(ty_op.operand); |
| 5278 | 5280 | if (isByRef(un_ty, zcu)) { |
| 5279 | | const llvm_un_ty = try o.lowerType(un_ty); |
| 5280 | | if (layout.payload_size == 0) |
| 5281 | | return self.wip.load(.normal, llvm_un_ty, union_ptr, .default, ""); |
| 5282 | | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| 5283 | | const tag_field_ptr = try self.ptraddConst(union_ptr, layout.tagOffset()); |
| 5284 | | const llvm_tag_ty = llvm_un_ty.structFields(&o.builder)[tag_index]; |
| 5281 | const llvm_tag_ty = try o.lowerType(un_ty.unionTagTypeRuntime(zcu).?); |
| 5282 | const tag_field_ptr = try self.ptraddConst(operand, layout.tagOffset()); |
| 5285 | 5283 | return self.wip.load(.normal, llvm_tag_ty, tag_field_ptr, .default, ""); |
| 5286 | 5284 | } else { |
| 5287 | | if (layout.payload_size == 0) return union_ptr; |
| 5288 | | const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align)); |
| 5289 | | return self.wip.extractValue(union_ptr, &.{tag_index}, ""); |
| 5285 | // This is only possible if all fields are zero-bit, in which case `operand` is already an |
| 5286 | // integer value (the union is lowered as its enum tag). |
| 5287 | assert(layout.payload_size == 0); |
| 5288 | return operand; |
| 5290 | 5289 | } |
| 5291 | 5290 | } |
| 5292 | 5291 | |
| ... | ... | @@ -7356,9 +7355,9 @@ fn appendConstraints( |
| 7356 | 7355 | /// may need to manually generate a compiler-rt call. |
| 7357 | 7356 | fn intrinsicsAllowed(scalar_ty: Type, target: *const std.Target) bool { |
| 7358 | 7357 | return switch (scalar_ty.toIntern()) { |
| 7359 | | .f16_type => backendSupportsF16(target), |
| 7360 | | .f80_type => (target.cTypeBitSize(.longdouble) == 80) and backendSupportsF80(target), |
| 7361 | | .f128_type => (target.cTypeBitSize(.longdouble) == 128) and backendSupportsF128(target), |
| 7358 | .f16_type => llvm.backendSupportsF16(target), |
| 7359 | .f80_type => (target.cTypeBitSize(.longdouble) == 80) and llvm.backendSupportsF80(target), |
| 7360 | .f128_type => (target.cTypeBitSize(.longdouble) == 128) and llvm.backendSupportsF128(target), |
| 7362 | 7361 | else => true, |
| 7363 | 7362 | }; |
| 7364 | 7363 | } |
| ... | ... | @@ -7702,9 +7701,4 @@ const compilerRtFloatAbbrev = target_util.compilerRtFloatAbbrev; |
| 7702 | 7701 | |
| 7703 | 7702 | const llvm = @import("../llvm.zig"); |
| 7704 | 7703 | const Object = llvm.Object; |
| 7705 | | const toLlvmCallConvTag = llvm.toLlvmCallConvTag; |
| 7706 | | const toLlvmAddressSpace = llvm.toLlvmAddressSpace; |
| 7707 | 7704 | const optional_layout_version = llvm.optional_layout_version; |
| 7708 | | const backendSupportsF16 = llvm.backendSupportsF16; |
| 7709 | | const backendSupportsF80 = llvm.backendSupportsF80; |
| 7710 | | const backendSupportsF128 = llvm.backendSupportsF128; |