Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Improve compliance with AAPCS ABI for ARM32 #4582

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/llvm_abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,15 +1470,30 @@ namespace lbAbiArm32 {
} else {
i64 sz = lb_sizeof(t);
i64 a = lb_alignof(t);

// TODO(tf2spi): Not AAPCS-compliant. Work on fixing the ABI (excruciating...).
LLVMTypeKind tid = LLVMGetTypeKind(t);
if (is_calling_convention_odin(calling_convention) && sz > 8) {
// Minor change to improve performance using the Odin calling conventions
args[i] = lb_arg_type_indirect(t, nullptr);
} else if (a <= 4) {
unsigned n = cast(unsigned)((sz + 3) / 4);
args[i] = lb_arg_type_direct(llvm_array_type(LLVMIntTypeInContext(c, 32), n));

// TODO(tf2spi):
// Works with arrays, not structs which ARM32 also puts in registers
if (tid == LLVMArrayTypeKind && LLVMGetTypeKind(LLVMGetElementType(t)) == LLVMFloatTypeKind)
args[i] = lb_arg_type_direct(llvm_array_type(LLVMFloatTypeInContext(c), n));
else
args[i] = lb_arg_type_direct(llvm_array_type(LLVMIntTypeInContext(c, 32), n));
} else {
unsigned n = cast(unsigned)((sz + 7) / 8);
args[i] = lb_arg_type_direct(llvm_array_type(LLVMIntTypeInContext(c, 64), n));

// TODO(tf2spi):
// Works with arrays, not structs which ARM32 also puts in registers
if (tid == LLVMArrayTypeKind && LLVMGetTypeKind(LLVMGetElementType(t)) == LLVMDoubleTypeKind)
args[i] = lb_arg_type_direct(llvm_array_type(LLVMDoubleTypeInContext(c), n));
else
args[i] = lb_arg_type_direct(llvm_array_type(LLVMIntTypeInContext(c, 64), n));
}
}
}
Expand Down
Loading