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

lower array types as arguments/results like compound types

parent 5995896f
......@@ -604,10 +604,13 @@ static int verify_node_Proj_Proj(const ir_node *p)
ASSERT_AND_RET(
(proj < (int)get_method_n_ress(mt)),
"More Projs for results than results in type.", 0);
if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
/* value result */ break;
ir_type *res_type = get_method_res_type(mt, proj);
/* value result */
if ((mode_is_reference(mode)) &&
(is_compound_type(res_type) || is_Array_type(res_type)))
break;
ASSERT_AND_RET(
ASSERT_AND_RET(
(mode == get_type_mode(get_method_res_type(mt, proj))),
"Mode of Proj from Call doesn't match mode of result type.", 0);
}
......
......@@ -46,6 +46,11 @@
static pmap *pointer_types;
static pmap *lowered_mtps;
static bool needs_lowering(const ir_type *type)
{
return is_compound_type(type) || is_Array_type(type);
}
/**
* Default implementation for finding a pointer type for a given element type.
* Simply create a new one.
......@@ -93,7 +98,7 @@ static void remove_compound_param_entities(ir_graph *irg)
continue;
type = get_entity_type(member);
if (is_compound_type(type)) {
if (needs_lowering(type)) {
free_entity(member);
}
}
......@@ -129,7 +134,7 @@ static ir_type *lower_mtp(compound_call_lowering_flags flags, ir_type *mtp)
n_ress = get_method_n_ress(mtp);
for (i = 0; i < n_ress; ++i) {
ir_type *res_tp = get_method_res_type(mtp, i);
if (is_compound_type(res_tp)) {
if (needs_lowering(res_tp)) {
must_be_lowered = true;
break;
}
......@@ -137,7 +142,7 @@ static ir_type *lower_mtp(compound_call_lowering_flags flags, ir_type *mtp)
if (!must_be_lowered && !(flags & LF_DONT_LOWER_ARGUMENTS)) {
for (i = 0; i < n_params; ++i) {
ir_type *param_type = get_method_param_type(mtp, i);
if (is_compound_type(param_type)) {
if (needs_lowering(param_type)) {
must_be_lowered = true;
break;
}
......@@ -155,7 +160,7 @@ static ir_type *lower_mtp(compound_call_lowering_flags flags, ir_type *mtp)
for (i = 0; i < n_ress; ++i) {
ir_type *res_tp = get_method_res_type(mtp, i);
if (is_compound_type(res_tp)) {
if (needs_lowering(res_tp)) {
/* this compound will be allocated on callers stack and its
address will be transmitted as a hidden parameter. */
ir_type *ptr_tp = get_pointer_type(res_tp);
......@@ -170,8 +175,7 @@ static ir_type *lower_mtp(compound_call_lowering_flags flags, ir_type *mtp)
/* copy over parameter types */
for (i = 0; i < n_params; ++i) {
ir_type *param_type = get_method_param_type(mtp, i);
if (! (flags & LF_DONT_LOWER_ARGUMENTS)
&& is_compound_type(param_type)) {
if (! (flags & LF_DONT_LOWER_ARGUMENTS) && needs_lowering(param_type)) {
/* turn parameter into a pointer type */
param_type = new_type_pointer(param_type);
}
......@@ -370,7 +374,7 @@ static void fix_args_and_collect_calls(ir_node *n, void *ctx)
/* check for compound returns */
for (i = 0; i < n_ress; ++i) {
ir_type *type = get_method_res_type(ctp, i);
if (is_compound_type(type)) {
if (needs_lowering(type)) {
/*
* This is a call with a compound return. As the result
* might be ignored, we must put it in the list.
......@@ -382,7 +386,7 @@ static void fix_args_and_collect_calls(ir_node *n, void *ctx)
}
for (i = 0; i < n_params; ++i) {
ir_type *type = get_method_param_type(ctp, i);
if (is_compound_type(type)) {
if (needs_lowering(type)) {
cl_entry *entry = get_call_entry(n, env);
entry->has_compound_param = true;
break;
......@@ -404,7 +408,7 @@ static void fix_args_and_collect_calls(ir_node *n, void *ctx)
ir_node *call = get_Proj_pred(proj);
if (is_Call(call)) {
ir_type *ctp = get_Call_type(call);
if (is_compound_type(get_method_res_type(ctp, get_Proj_proj(src)))) {
if (needs_lowering(get_method_res_type(ctp, get_Proj_proj(src)))) {
/* found a CopyB from compound Call result */
cl_entry *e = get_call_entry(call, env);
set_irn_link(n, e->copyb);
......@@ -419,7 +423,7 @@ static void fix_args_and_collect_calls(ir_node *n, void *ctx)
ir_entity *entity = get_Sel_entity(n);
ir_type *type = get_entity_type(entity);
if (is_parameter_entity(entity) && is_compound_type(type)) {
if (is_parameter_entity(entity) && needs_lowering(type)) {
if (! (env->flags & LF_DONT_LOWER_ARGUMENTS)) {
/* note that num was already modified by fix_parameter_entities
* so no need to add env->arg_shift again */
......@@ -563,7 +567,7 @@ static void add_hidden_param(ir_graph *irg, size_t n_com, ir_node **ins,
for (j = i = 0; i < get_method_n_ress(ctp); ++i) {
ir_type *rtp = get_method_res_type(ctp, i);
if (is_compound_type(rtp)) {
if (needs_lowering(rtp)) {
if (ins[j] == NULL)
ins[j] = get_dummy_sel(irg, get_nodes_block(entry->call), rtp);
++j;
......@@ -585,7 +589,7 @@ static void fix_compound_ret(cl_entry *entry, ir_type *ctp)
for (i = 0; i < n_res; ++i) {
ir_type *type = get_method_res_type(ctp, i);
if (is_compound_type(type))
if (needs_lowering(type))
++n_com;
}
......@@ -634,7 +638,7 @@ static void fix_compound_params(cl_entry *entry, ir_type *ctp)
ir_node *sel;
ir_node *copyb;
ir_entity *arg_entity;
if (!is_compound_type(type))
if (!needs_lowering(type))
continue;
arg = get_Call_param(call, i);
......@@ -693,12 +697,12 @@ static void transform_irg(compound_call_lowering_flags flags, ir_graph *irg)
size_t n_ret_com = 0;
for (i = 0; i < n_ress; ++i) {
ir_type *type = get_method_res_type(mtp, i);
if (is_compound_type(type))
if (needs_lowering(type))
++n_ret_com;
}
for (i = 0; i < n_params; ++i) {
ir_type *type = get_method_param_type(mtp, i);
if (is_compound_type(type))
if (needs_lowering(type))
++n_param_com;
}
......@@ -778,7 +782,7 @@ static void transform_irg(compound_call_lowering_flags flags, ir_graph *irg)
ir_node *pred = get_Return_res(ret, i);
tp = get_method_res_type(mtp, i);
if (is_compound_type(tp)) {
if (needs_lowering(tp)) {
ir_node *arg = get_irg_args(irg);
arg = new_r_Proj(arg, mode_P_data, k);
++k;
......
Supports Markdown
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