Commit ec7cfdce authored by Matthias Braun's avatar Matthias Braun
Browse files

Reorganize va_arg handling

Do not put stuff unnecessarily into backend params.
- Pass lower_va_arg directly as a parameter to lower_builtins
- Pass stack_param align directly to be_default_lower_va_arg
parent e05fde26
...@@ -78,20 +78,6 @@ typedef enum { ...@@ -78,20 +78,6 @@ typedef enum {
DW_LANG_Go = 0x0016, DW_LANG_Go = 0x0016,
} dwarf_source_language; } dwarf_source_language;
typedef void(*lower_func)(ir_node*);
/**
* This structure holds the information on how the backend implements
* variadic functions.
*/
typedef struct vararg_params {
/** Which type is to be used for va_list. If this is NULL, the
* backend does not implement variadic functions. */
ir_type *va_list_type;
/** The function to lower a call to the va_arg macro. */
lower_func lower_va_arg;
} vararg_params;
/** /**
* This structure contains parameters that should be * This structure contains parameters that should be
* propagated to the libFirm parameter set. * propagated to the libFirm parameter set.
...@@ -139,14 +125,10 @@ typedef struct backend_params { ...@@ -139,14 +125,10 @@ typedef struct backend_params {
*/ */
ir_type *type_long_double; ir_type *type_long_double;
/** Alignment of stack parameters */
unsigned stack_param_align;
/** Semantic on float->int conversion overflow. */ /** Semantic on float->int conversion overflow. */
float_int_conversion_overflow_style_t float_int_overflow; float_int_conversion_overflow_style_t float_int_overflow;
/** How this backend implements variadic functions. */ ir_type *va_list_type;
vararg_params vararg;
} backend_params; } backend_params;
/** /**
......
...@@ -119,7 +119,7 @@ static void TEMPLATE_finish(void) ...@@ -119,7 +119,7 @@ static void TEMPLATE_finish(void)
static void TEMPLATE_lower_for_target(void) static void TEMPLATE_lower_for_target(void)
{ {
lower_builtins(0, NULL); lower_builtins(0, NULL, NULL);
be_after_irp_transform("lower-builtins"); be_after_irp_transform("lower-builtins");
/* lower compound param handling */ /* lower compound param handling */
...@@ -152,7 +152,6 @@ static const backend_params *TEMPLATE_get_backend_params(void) ...@@ -152,7 +152,6 @@ static const backend_params *TEMPLATE_get_backend_params(void)
.machine_size = 32, .machine_size = 32,
.mode_float_arithmetic = NULL, .mode_float_arithmetic = NULL,
.type_long_double = NULL, .type_long_double = NULL,
.stack_param_align = 4,
.float_int_overflow = ir_overflow_min_max, .float_int_overflow = ir_overflow_min_max,
}; };
return &p; return &p;
......
...@@ -723,7 +723,7 @@ static void amd64_lower_for_target(void) ...@@ -723,7 +723,7 @@ static void amd64_lower_for_target(void)
supported[s++] = ir_bk_va_start; supported[s++] = ir_bk_va_start;
assert(s <= ARRAY_SIZE(supported)); assert(s <= ARRAY_SIZE(supported));
lower_builtins(s, supported); lower_builtins(s, supported, amd64_lower_va_arg);
be_after_irp_transform("lower-builtins"); be_after_irp_transform("lower-builtins");
} }
...@@ -757,12 +757,7 @@ static backend_params amd64_backend_params = { ...@@ -757,12 +757,7 @@ static backend_params amd64_backend_params = {
.machine_size = 64, .machine_size = 64,
.mode_float_arithmetic = NULL, /* will be set later */ .mode_float_arithmetic = NULL, /* will be set later */
.type_long_double = NULL, /* will be set later */ .type_long_double = NULL, /* will be set later */
.stack_param_align = 8,
.float_int_overflow = ir_overflow_indefinite, .float_int_overflow = ir_overflow_indefinite,
.vararg = {
.va_list_type = NULL, /* Will be set later */
.lower_va_arg = amd64_lower_va_arg,
},
}; };
static const backend_params *amd64_get_backend_params(void) { static const backend_params *amd64_get_backend_params(void) {
...@@ -786,7 +781,7 @@ static void amd64_init_types(void) ...@@ -786,7 +781,7 @@ static void amd64_init_types(void)
ir_type *const type_f80 = x86_init_x87_type(); ir_type *const type_f80 = x86_init_x87_type();
amd64_backend_params.type_long_double = type_f80; amd64_backend_params.type_long_double = type_f80;
amd64_backend_params.vararg.va_list_type = amd64_build_va_list_type(); amd64_backend_params.va_list_type = amd64_build_va_list_type();
} }
static void amd64_init(void) static void amd64_init(void)
......
...@@ -238,7 +238,7 @@ static void arm_lower_for_target(void) ...@@ -238,7 +238,7 @@ static void arm_lower_for_target(void)
size_t s = 0; size_t s = 0;
supported[s++] = ir_bk_clz; supported[s++] = ir_bk_clz;
assert(s <= ARRAY_SIZE(supported)); assert(s <= ARRAY_SIZE(supported));
lower_builtins(s, supported); lower_builtins(s, supported, NULL);
be_after_irp_transform("lower-builtins"); be_after_irp_transform("lower-builtins");
foreach_irp_irg(i, irg) { foreach_irp_irg(i, irg) {
...@@ -270,12 +270,7 @@ static backend_params arm_backend_params = { ...@@ -270,12 +270,7 @@ static backend_params arm_backend_params = {
.machine_size = ARM_MACHINE_SIZE, .machine_size = ARM_MACHINE_SIZE,
.mode_float_arithmetic = NULL, .mode_float_arithmetic = NULL,
.type_long_double = NULL, .type_long_double = NULL,
.stack_param_align = 4,
.float_int_overflow = ir_overflow_min_max, .float_int_overflow = ir_overflow_min_max,
.vararg = {
.va_list_type = NULL,
.lower_va_arg = NULL,
},
}; };
static void arm_init_backend_params(void) static void arm_init_backend_params(void)
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#include "irnode_t.h" #include "irnode_t.h"
#include "util.h" #include "util.h"
static void be_default_lower_va_arg(ir_node *const node, bool const compound_is_ptr) void be_default_lower_va_arg(ir_node *const node, bool const compound_is_ptr,
unsigned const stack_param_align)
{ {
ir_node *block = get_nodes_block(node); ir_node *block = get_nodes_block(node);
dbg_info *dbgi = get_irn_dbg_info(node); dbg_info *dbgi = get_irn_dbg_info(node);
...@@ -46,9 +47,8 @@ load:; ...@@ -46,9 +47,8 @@ load:;
new_mem = node_mem; new_mem = node_mem;
} }
backend_params const *const be_params = be_get_backend_param();
unsigned const round_up = round_up2(get_type_size(aptype), unsigned const round_up = round_up2(get_type_size(aptype),
be_params->stack_param_align); stack_param_align);
ir_mode *const offset_mode = get_reference_offset_mode(mode_P); ir_mode *const offset_mode = get_reference_offset_mode(mode_P);
ir_node *const offset = new_r_Const_long(irg, offset_mode, round_up); ir_node *const offset = new_r_Const_long(irg, offset_mode, round_up);
ir_node *const new_ap = new_rd_Add(dbgi, block, ap, offset); ir_node *const new_ap = new_rd_Add(dbgi, block, ap, offset);
...@@ -57,21 +57,6 @@ load:; ...@@ -57,21 +57,6 @@ load:;
turn_into_tuple(node, ARRAY_SIZE(in), in); turn_into_tuple(node, ARRAY_SIZE(in), in);
} }
void be_default_lower_va_arg_compound_ptr(ir_node *const node)
{
be_default_lower_va_arg(node, true);
}
void be_default_lower_va_arg_compound_val(ir_node *const node)
{
be_default_lower_va_arg(node, false);
}
void be_set_va_list_type_pointer(backend_params *const p)
{
p->vararg.va_list_type = new_type_pointer(get_type_for_mode(mode_ANY));
}
ir_entity *be_make_va_start_entity(ir_type *const frame_type, int const offset) ir_entity *be_make_va_start_entity(ir_type *const frame_type, int const offset)
{ {
ident *const id = new_id_from_str("$va_start"); ident *const id = new_id_from_str("$va_start");
......
...@@ -14,28 +14,24 @@ ...@@ -14,28 +14,24 @@
#include "be.h" #include "be.h"
#include "firm_types.h" #include "firm_types.h"
#include <stdbool.h>
/** /**
* Default implementation to lower a va_arg node. * Default implementation to lower a va_arg node.
* *
* This implementation assumes that all arguments except compound types are * If \p compound_is_ptr is true, then this implementation assumes that all
* stored on the stack and that the va_list value points to the next variadic * arguments except compound types are stored on the stack and that the va_list
* argument. For compound types a pointer to the object is stored on the stack. * value points to the next variadic argument. For compound types a pointer to
* the object is stored on the stack.
* *
* @param node A Builtin node with kind ir_bk_va_arg to be lowered * If \p compound_is_ptr is false, then this implementation assumes that all
*/ * arguments are stored on the stack and that the va_list value points to the
void be_default_lower_va_arg_compound_ptr(ir_node *node); * next variadic argument.
/**
* Default implementation to lower a va_arg node.
*
* This implementation assumes that all arguments are stored on the
* stack and that the va_list value points to the next variadic
* argument.
* *
* @param node A Builtin node with kind ir_bk_va_arg to be lowered * @param node A Builtin node with kind ir_bk_va_arg to be lowered
*/ */
void be_default_lower_va_arg_compound_val(ir_node *node); void be_default_lower_va_arg(ir_node *node, bool compound_is_ptr,
unsigned stack_param_align);
void be_set_va_list_type_pointer(backend_params *p); void be_set_va_list_type_pointer(backend_params *p);
......
...@@ -1359,12 +1359,8 @@ static backend_params ia32_backend_params = { ...@@ -1359,12 +1359,8 @@ static backend_params ia32_backend_params = {
.machine_size = 32, .machine_size = 32,
.mode_float_arithmetic = NULL, /* will be set later */ .mode_float_arithmetic = NULL, /* will be set later */
.type_long_double = NULL, /* will be set later */ .type_long_double = NULL, /* will be set later */
.stack_param_align = 4,
.float_int_overflow = ir_overflow_indefinite, .float_int_overflow = ir_overflow_indefinite,
.vararg = { .va_list_type = NULL, /* will be set later */
.va_list_type = NULL, /* will be set later */
.lower_va_arg = be_default_lower_va_arg_compound_val,
},
}; };
/** /**
...@@ -1388,7 +1384,9 @@ static void ia32_init(void) ...@@ -1388,7 +1384,9 @@ static void ia32_init(void)
ia32_mode_float32 = new_float_mode("fp32", irma_ieee754, 8, 23, ia32_mode_float32 = new_float_mode("fp32", irma_ieee754, 8, 23,
ir_overflow_indefinite); ir_overflow_indefinite);
be_set_va_list_type_pointer(&ia32_backend_params); // va_list is a void pointer
ir_type *type_va_list = new_type_pointer(get_type_for_mode(mode_ANY));
ia32_backend_params.va_list_type = type_va_list;
if (ia32_cg_config.use_sse2 || ia32_cg_config.use_softfloat) { if (ia32_cg_config.use_sse2 || ia32_cg_config.use_softfloat) {
ia32_backend_params.mode_float_arithmetic = NULL; ia32_backend_params.mode_float_arithmetic = NULL;
...@@ -1583,6 +1581,11 @@ static aggregate_spec_t const *decide_compound_ret(ir_type const *type) ...@@ -1583,6 +1581,11 @@ static aggregate_spec_t const *decide_compound_ret(ir_type const *type)
return &no_values_aggregate_spec; return &no_values_aggregate_spec;
} }
static void ia32_lower_va_arg(ir_node *node)
{
be_default_lower_va_arg(node, false, 4);
}
static void ia32_lower_for_target(void) static void ia32_lower_for_target(void)
{ {
ir_mode *mode_gp = ia32_reg_classes[CLASS_ia32_gp].mode; ir_mode *mode_gp = ia32_reg_classes[CLASS_ia32_gp].mode;
...@@ -1626,7 +1629,7 @@ static void ia32_lower_for_target(void) ...@@ -1626,7 +1629,7 @@ static void ia32_lower_for_target(void)
if (ia32_cg_config.use_cmpxchg) if (ia32_cg_config.use_cmpxchg)
supported[s++] = ir_bk_compare_swap; supported[s++] = ir_bk_compare_swap;
assert(s < ARRAY_SIZE(supported)); assert(s < ARRAY_SIZE(supported));
lower_builtins(s, supported); lower_builtins(s, supported, ia32_lower_va_arg);
be_after_irp_transform("lower-builtins"); be_after_irp_transform("lower-builtins");
foreach_irp_irg(i, irg) { foreach_irp_irg(i, irg) {
......
...@@ -55,7 +55,6 @@ static backend_params mips_backend_params = { ...@@ -55,7 +55,6 @@ static backend_params mips_backend_params = {
.machine_size = MIPS_MACHINE_SIZE, .machine_size = MIPS_MACHINE_SIZE,
.mode_float_arithmetic = NULL, /* will be set later */ // TODO .mode_float_arithmetic = NULL, /* will be set later */ // TODO
.type_long_double = NULL, /* will be set later */ // TODO .type_long_double = NULL, /* will be set later */ // TODO
.stack_param_align = 4,
.float_int_overflow = ir_overflow_indefinite, .float_int_overflow = ir_overflow_indefinite,
}; };
...@@ -282,10 +281,10 @@ static void mips_lower_for_target(void) ...@@ -282,10 +281,10 @@ static void mips_lower_for_target(void)
be_after_transform(irg, "lower-copyb"); be_after_transform(irg, "lower-copyb");
} }
ir_builtin_kind const supported[] = { static ir_builtin_kind const supported[] = {
ir_bk_saturating_increment, ir_bk_saturating_increment,
}; };
lower_builtins(ARRAY_SIZE(supported), supported); lower_builtins(ARRAY_SIZE(supported), supported, NULL);
ir_mode *const mode_gp = mips_reg_classes[CLASS_mips_gp].mode; ir_mode *const mode_gp = mips_reg_classes[CLASS_mips_gp].mode;
foreach_irp_irg(i, irg) { foreach_irp_irg(i, irg) {
......
...@@ -469,6 +469,11 @@ static void sparc_generate_code(FILE *output, const char *cup_name) ...@@ -469,6 +469,11 @@ static void sparc_generate_code(FILE *output, const char *cup_name)
pmap_destroy(sparc_constants); pmap_destroy(sparc_constants);
} }
static void sparc_lower_va_arg(ir_node *node)
{
be_default_lower_va_arg(node, true, 4);
}
static void sparc_lower_for_target(void) static void sparc_lower_for_target(void)
{ {
lower_calls_with_compounds(LF_RETURN_HIDDEN, NULL); lower_calls_with_compounds(LF_RETURN_HIDDEN, NULL);
...@@ -493,7 +498,7 @@ static void sparc_lower_for_target(void) ...@@ -493,7 +498,7 @@ static void sparc_lower_for_target(void)
supported[s++] = ir_bk_compare_swap; supported[s++] = ir_bk_compare_swap;
supported[s++] = ir_bk_va_start; supported[s++] = ir_bk_va_start;
assert(s < ARRAY_SIZE(supported)); assert(s < ARRAY_SIZE(supported));
lower_builtins(s, supported); lower_builtins(s, supported, sparc_lower_va_arg);
be_after_irp_transform("lower-builtins"); be_after_irp_transform("lower-builtins");
ir_mode *mode_gp = sparc_reg_classes[CLASS_sparc_gp].mode; ir_mode *mode_gp = sparc_reg_classes[CLASS_sparc_gp].mode;
...@@ -544,15 +549,10 @@ static const backend_params *sparc_get_backend_params(void) ...@@ -544,15 +549,10 @@ static const backend_params *sparc_get_backend_params(void)
.machine_size = 32, .machine_size = 32,
.mode_float_arithmetic = NULL, /* will be set later */ .mode_float_arithmetic = NULL, /* will be set later */
.type_long_double = NULL, /* will be set later */ .type_long_double = NULL, /* will be set later */
.stack_param_align = 4,
.float_int_overflow = ir_overflow_min_max, .float_int_overflow = ir_overflow_min_max,
.vararg = {
.va_list_type = NULL, /* will be set later */
.lower_va_arg = be_default_lower_va_arg_compound_ptr,
},
}; };
be_set_va_list_type_pointer(&p); p.va_list_type = new_type_pointer(get_type_for_mode(mode_ANY));
sparc_mode_Q sparc_mode_Q
= new_float_mode("Q", irma_ieee754, 15, 112, ir_overflow_min_max); = new_float_mode("Q", irma_ieee754, 15, 112, ir_overflow_min_max);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "util.h" #include "util.h"
static bool dont_lower[ir_bk_last + 1]; static bool dont_lower[ir_bk_last + 1];
static lower_func lower_va_arg;
static const char *get_builtin_name(ir_builtin_kind kind) static const char *get_builtin_name(ir_builtin_kind kind)
{ {
...@@ -191,7 +192,7 @@ changed: ...@@ -191,7 +192,7 @@ changed:
return; return;
case ir_bk_va_arg: case ir_bk_va_arg:
be_get_backend_param()->vararg.lower_va_arg(node); lower_va_arg(node);
return; return;
case ir_bk_trap: case ir_bk_trap:
...@@ -210,8 +211,11 @@ changed: ...@@ -210,8 +211,11 @@ changed:
panic("unexpected builtin %+F", node); panic("unexpected builtin %+F", node);
} }
void lower_builtins(size_t const n_exceptions, ir_builtin_kind const *const exceptions) void lower_builtins(size_t n_exceptions,
ir_builtin_kind const *const exceptions,
lower_func new_lower_va_arg)
{ {
lower_va_arg = new_lower_va_arg;
memset(dont_lower, 0, sizeof(dont_lower)); memset(dont_lower, 0, sizeof(dont_lower));
for (size_t i = 0; i < n_exceptions; ++i) { for (size_t i = 0; i < n_exceptions; ++i) {
dont_lower[exceptions[i]] = true; dont_lower[exceptions[i]] = true;
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#include "firm_types.h" #include "firm_types.h"
#include <stddef.h> #include <stddef.h>
void lower_builtins(size_t n_exceptions, ir_builtin_kind const *exceptions); typedef void(*lower_func)(ir_node*);
void lower_builtins(size_t n_exceptions, ir_builtin_kind const *exceptions,
lower_func lower_va_arg);
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment