commit 53bea0f7e44591e741c357297a1f25310d36ca78 (tree)
parent 35cd56a3693d55eedb80e8bd1538420597b05ff5
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date: Tue, 8 Aug 2023 21:32:55 -0400
llvm: remove dependence on llvm data layout alignment
by just using the zig alignment and letting llvm promote it as desired
Diffstat:
1 file changed, 6 insertions(+), 15 deletions(-)
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
@@ -1408,11 +1408,7 @@ pub const Object = struct {
llvm_arg_i += 1;
const param_llvm_ty = try o.lowerType(param_ty);
- const int_llvm_ty = try o.builder.intType(@intCast(param_ty.abiSize(mod) * 8));
- const alignment = Builder.Alignment.fromByteUnits(@max(
- param_ty.abiAlignment(mod),
- o.target_data.abiAlignmentOfType(int_llvm_ty.toLlvm(&o.builder)),
- ));
+ const alignment = Builder.Alignment.fromByteUnits(param_ty.abiAlignment(mod));
const arg_ptr = try buildAllocaInner(&wip, false, param_llvm_ty, alignment, target);
_ = try wip.store(.normal, param, arg_ptr, alignment);
@@ -4938,10 +4934,7 @@ pub const FuncGen = struct {
} else {
// LLVM does not allow bitcasting structs so we must allocate
// a local, store as one type, and then load as another type.
- const alignment = Builder.Alignment.fromByteUnits(@max(
- param_ty.abiAlignment(mod),
- o.target_data.abiAlignmentOfType(int_llvm_ty.toLlvm(&o.builder)),
- ));
+ const alignment = Builder.Alignment.fromByteUnits(param_ty.abiAlignment(mod));
const int_ptr = try self.buildAlloca(int_llvm_ty, alignment);
_ = try self.wip.store(.normal, llvm_arg, int_ptr, alignment);
const loaded = try self.wip.load(.normal, int_llvm_ty, int_ptr, alignment, "");
@@ -5117,12 +5110,10 @@ pub const FuncGen = struct {
// In this case the function return type is honoring the calling convention by having
// a different LLVM type than the usual one. We solve this here at the callsite
// by using our canonical type, then loading it if necessary.
- const alignment = Builder.Alignment.fromByteUnits(@max(
- o.target_data.abiAlignmentOfType(abi_ret_ty.toLlvm(&o.builder)),
- return_type.abiAlignment(mod),
- ));
- assert(o.target_data.abiSizeOfType(abi_ret_ty.toLlvm(&o.builder)) >=
- o.target_data.abiSizeOfType(llvm_ret_ty.toLlvm(&o.builder)));
+ const alignment = Builder.Alignment.fromByteUnits(return_type.abiAlignment(mod));
+ if (o.builder.useLibLlvm())
+ assert(o.target_data.abiSizeOfType(abi_ret_ty.toLlvm(&o.builder)) >=
+ o.target_data.abiSizeOfType(llvm_ret_ty.toLlvm(&o.builder)));
const rp = try self.buildAlloca(abi_ret_ty, alignment);
_ = try self.wip.store(.normal, call, rp, alignment);
return if (isByRef(return_type, mod))