mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Minor cleanup of ABI code.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include "llvm_codegen_c_abi_internal.h"
|
||||
|
||||
|
||||
ABIArgInfo *abi_arg_new(ABIKind kind)
|
||||
static ABIArgInfo *abi_arg_new(ABIKind kind)
|
||||
{
|
||||
ABIArgInfo *info = CALLOCS(ABIArgInfo);
|
||||
info->kind = kind;
|
||||
@@ -185,6 +185,11 @@ ABIArgInfo *abi_arg_new_direct(void)
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
}
|
||||
|
||||
ABIArgInfo *abi_arg_new_expand(void)
|
||||
{
|
||||
return abi_arg_new(ABI_ARG_EXPAND);
|
||||
}
|
||||
|
||||
ABIArgInfo *abi_arg_new_expand_coerce(AbiType *target_type, unsigned offset)
|
||||
{
|
||||
ABIArgInfo *arg = abi_arg_new(ABI_ARG_EXPAND_COERCE);
|
||||
|
||||
@@ -36,7 +36,7 @@ ABIArgInfo *aarch64_classify_argument_type(Type *type)
|
||||
{
|
||||
return abi_arg_new_direct_int_ext(type);
|
||||
}
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
|
||||
// Is empty
|
||||
@@ -104,7 +104,7 @@ ABIArgInfo *aarch64_classify_return_type(Type *type, bool variadic)
|
||||
{
|
||||
return abi_arg_new_direct_int_ext(type);
|
||||
}
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
|
||||
// Abi aggregate:
|
||||
|
||||
@@ -25,10 +25,10 @@ typedef enum
|
||||
static inline ABIArgInfo *abi_arg_by_reg_attr(ABIArgInfo *info);
|
||||
size_t abi_arg_expanded_size(ABIArgInfo *type_info, Type *type);
|
||||
bool abi_arg_is_indirect(ABIArgInfo *info);
|
||||
ABIArgInfo *abi_arg_new(ABIKind kind);
|
||||
ABIArgInfo *abi_arg_ignore(void);
|
||||
ABIArgInfo *abi_arg_new_direct_pair(AbiType *low_type, AbiType *high_type);
|
||||
ABIArgInfo *abi_arg_new_direct(void);
|
||||
ABIArgInfo *abi_arg_new_expand(void);
|
||||
ABIArgInfo *abi_arg_new_direct_int_ext(Type *type_to_extend);
|
||||
ABIArgInfo *abi_arg_new_direct_coerce(AbiType *target_type);
|
||||
ABIArgInfo *abi_arg_new_expand_coerce(AbiType *target_type, unsigned offset);
|
||||
|
||||
@@ -24,9 +24,9 @@ ABIArgInfo *win64_classify(GenContext *context, Type *type, bool is_return, bool
|
||||
// Direct if return / builtin / vector
|
||||
if (is_return || type_is_builtin(type->type_kind) || type->type_kind == TYPE_VECTOR)
|
||||
{
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
return abi_arg_new(ABI_ARG_EXPAND);
|
||||
return abi_arg_new_expand();
|
||||
}
|
||||
// Otherwise use indirect
|
||||
return abi_arg_new_indirect_not_by_val();
|
||||
@@ -38,14 +38,10 @@ ABIArgInfo *win64_classify(GenContext *context, Type *type, bool is_return, bool
|
||||
(is_return || type_is_builtin(type->type_kind) || type->type_kind == TYPE_VECTOR))
|
||||
{
|
||||
context->abi.sse_registers -= elements;
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
}
|
||||
if (is_return)
|
||||
{
|
||||
return abi_arg_new(ABI_ARG_INDIRECT);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
// HVAs are handled later.
|
||||
if (!type_is_builtin(type->type_kind) && type->type_kind != TYPE_VECTOR)
|
||||
if (is_return || (!type_is_builtin(type->type_kind) && type->type_kind != TYPE_VECTOR))
|
||||
{
|
||||
return abi_arg_new_indirect_not_by_val();
|
||||
}
|
||||
@@ -83,7 +79,7 @@ ABIArgInfo *win64_classify(GenContext *context, Type *type, bool is_return, bool
|
||||
{
|
||||
return abi_arg_new_indirect_not_by_val();
|
||||
}
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
|
||||
ABIArgInfo *win64_reclassify_hva_arg(GenContext *context, Type *type, ABIArgInfo *info)
|
||||
@@ -97,7 +93,7 @@ ABIArgInfo *win64_reclassify_hva_arg(GenContext *context, Type *type, ABIArgInfo
|
||||
if (context->abi.sse_registers >= elements)
|
||||
{
|
||||
context->abi.sse_registers -= elements;
|
||||
ABIArgInfo *new_info = abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
ABIArgInfo *new_info = abi_arg_new_direct();
|
||||
new_info->attributes.by_reg = true;
|
||||
return new_info;
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ ABIArgInfo *x64_indirect_return_result(Type *type)
|
||||
{
|
||||
if (type_is_abi_aggregate(type))
|
||||
{
|
||||
return abi_arg_new(ABI_ARG_INDIRECT);
|
||||
return abi_arg_new_indirect_not_by_val();
|
||||
}
|
||||
type = type_lowering(type);
|
||||
if (type_is_promotable_integer(type))
|
||||
{
|
||||
return abi_arg_new_direct_int_ext(type);
|
||||
}
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
static size_t x64_native_vector_size_for_avx(void)
|
||||
{
|
||||
@@ -102,7 +102,7 @@ ABIArgInfo *x64_indirect_result(Type *type, unsigned free_int_regs)
|
||||
return abi_arg_new_direct_int_ext(type);
|
||||
}
|
||||
// No change, just put it on the stack.
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
|
||||
// The byval alignment
|
||||
@@ -122,7 +122,7 @@ ABIArgInfo *x64_indirect_result(Type *type, unsigned free_int_regs)
|
||||
{
|
||||
return abi_arg_new_indirect_realigned(8);
|
||||
}
|
||||
return abi_arg_new(ABI_ARG_INDIRECT);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ ABIArgInfo *x64_classify_reg_call_struct_type_check(Type *type, Registers *neede
|
||||
if (type->type_kind == TYPE_ERR_UNION || type->type_kind == TYPE_STRING || type->type_kind == TYPE_SUBARRAY)
|
||||
{
|
||||
needed_registers->int_registers += 2;
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
|
||||
// Union, struct, err type handled =>
|
||||
@@ -160,7 +160,7 @@ ABIArgInfo *x64_classify_reg_call_struct_type_check(Type *type, Registers *neede
|
||||
needed_registers->int_registers += temp_needed_registers.int_registers;
|
||||
}
|
||||
// Check this!
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
|
||||
ABIArgInfo *x64_classify_reg_call_struct_type(Type *return_type, Registers *available_registers)
|
||||
|
||||
@@ -81,7 +81,7 @@ static ABIArgInfo *x86_create_indirect_result(GenContext *context, Type *type, B
|
||||
|
||||
ABIArgInfo *create_indirect_return_x86(GenContext *context)
|
||||
{
|
||||
ABIArgInfo *info = abi_arg_new(ABI_ARG_INDIRECT);
|
||||
ABIArgInfo *info = abi_arg_new_indirect_not_by_val();
|
||||
if (!context->abi.int_registers) return info;
|
||||
// Consume a register for the return.
|
||||
context->abi.int_registers--;
|
||||
@@ -163,7 +163,7 @@ ABIArgInfo *x86_classify_return(GenContext *context, Type *type)
|
||||
// Pass in the normal way.
|
||||
if (type_is_homogenous_aggregate(type, &base, &elements))
|
||||
{
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ ABIArgInfo *x86_classify_return(GenContext *context, Type *type)
|
||||
}
|
||||
return create_indirect_return_x86(context);
|
||||
}
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
}
|
||||
|
||||
if (type_is_abi_aggregate(type))
|
||||
@@ -212,11 +212,11 @@ ABIArgInfo *x86_classify_return(GenContext *context, Type *type)
|
||||
{
|
||||
if ((type_is_float(single_element) && !build_target.x86.is_win32_float_struct_abi))
|
||||
{
|
||||
return abi_arg_new(ABI_ARG_EXPAND);
|
||||
return abi_arg_new_expand();
|
||||
}
|
||||
if (type_is_pointer(type))
|
||||
{
|
||||
return abi_arg_new(ABI_ARG_EXPAND);
|
||||
return abi_arg_new_expand();
|
||||
}
|
||||
}
|
||||
// This is not a single element struct, so we wrap it in an int.
|
||||
@@ -235,7 +235,7 @@ ABIArgInfo *x86_classify_return(GenContext *context, Type *type)
|
||||
if (type_is_integer(type) && type_size(type) > 8) return create_indirect_return_x86(context);
|
||||
|
||||
// Otherwise we expect to just pass this nicely in the return.
|
||||
return abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
return abi_arg_new_direct();
|
||||
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ static inline ABIArgInfo *x86_classify_homogenous_aggregate(GenContext *context,
|
||||
// don't flatten.
|
||||
if (is_vec_call)
|
||||
{
|
||||
ABIArgInfo *info = abi_arg_new(ABI_ARG_DIRECT_COERCE);
|
||||
ABIArgInfo *info = abi_arg_new_direct();
|
||||
info->attributes.by_reg = true;
|
||||
return info;
|
||||
}
|
||||
@@ -430,7 +430,7 @@ static inline ABIArgInfo *x86_classify_homogenous_aggregate(GenContext *context,
|
||||
}
|
||||
|
||||
// Otherwise just a normal expand.
|
||||
return abi_arg_new(ABI_ARG_EXPAND);
|
||||
return abi_arg_new_expand();
|
||||
}
|
||||
|
||||
static inline ABIArgInfo *x86_classify_vector(GenContext *context, Type *type)
|
||||
@@ -517,7 +517,7 @@ static inline ABIArgInfo *x86_classify_aggregate(GenContext *context, Type *type
|
||||
if (size <= 16 && (!build_target.x86.is_mcu_api || !context->abi.int_registers) &&
|
||||
x86_can_expand_indirect_aggregate_arg(type))
|
||||
{
|
||||
if (!needs_padding_in_reg) return abi_arg_new(ABI_ARG_EXPAND);
|
||||
if (!needs_padding_in_reg) return abi_arg_new_expand();
|
||||
|
||||
// This is padded expansion
|
||||
ABIArgInfo *info = abi_arg_new_expand_padded(type_int);
|
||||
|
||||
Reference in New Issue
Block a user