Commit 3c24cef2 authored by Matthias Braun's avatar Matthias Braun
Browse files

introduce the concept of an aggregate type

This is a type which is aggregated from multiple primtive/simple
elements. In libfirm such a type cannot be represented as a mode.
parent 3de231e2
......@@ -277,8 +277,7 @@ static int verify_node_Proj_Proj_Call(const ir_node *p)
return false;
}
ir_type *type = get_method_res_type(mt, pn);
ir_mode *mode = is_compound_type(type) || is_Array_type(type)
? mode_P : get_type_mode(type);
ir_mode *mode = is_aggregate_type(type) ? mode_P : get_type_mode(type);
return check_mode(p, mode);
}
......
......@@ -32,11 +32,6 @@
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.
......@@ -84,7 +79,7 @@ static void remove_compound_param_entities(ir_graph *irg)
continue;
type = get_entity_type(member);
if (needs_lowering(type)) {
if (is_aggregate_type(type)) {
free_entity(member);
}
}
......@@ -120,7 +115,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 (needs_lowering(res_tp)) {
if (is_aggregate_type(res_tp)) {
must_be_lowered = true;
break;
}
......@@ -128,7 +123,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 (needs_lowering(param_type)) {
if (is_aggregate_type(param_type)) {
must_be_lowered = true;
break;
}
......@@ -146,7 +141,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 (needs_lowering(res_tp)) {
if (is_aggregate_type(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);
......@@ -161,7 +156,8 @@ 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) && needs_lowering(param_type)) {
if (!(flags & LF_DONT_LOWER_ARGUMENTS)
&& is_aggregate_type(param_type)) {
/* turn parameter into a pointer type */
param_type = new_type_pointer(param_type);
}
......@@ -360,7 +356,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 (needs_lowering(type)) {
if (is_aggregate_type(type)) {
/*
* This is a call with a compound return. As the result
* might be ignored, we must put it in the list.
......@@ -372,7 +368,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 (needs_lowering(type)) {
if (is_aggregate_type(type)) {
cl_entry *entry = get_call_entry(n, env);
entry->has_compound_param = true;
break;
......@@ -394,7 +390,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 (needs_lowering(get_method_res_type(ctp, get_Proj_proj(src)))) {
if (is_aggregate_type(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);
......@@ -409,7 +405,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) && needs_lowering(type)) {
if (is_parameter_entity(entity) && is_aggregate_type(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 */
......@@ -540,7 +536,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 (needs_lowering(rtp)) {
if (is_aggregate_type(rtp)) {
if (ins[j] == NULL)
ins[j] = get_dummy_sel(irg, get_nodes_block(entry->call), rtp);
++j;
......@@ -562,7 +558,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 (needs_lowering(type))
if (is_aggregate_type(type))
++n_com;
}
......@@ -611,7 +607,7 @@ static void fix_compound_params(cl_entry *entry, ir_type *ctp)
ir_node *sel;
ir_entity *arg_entity;
bool is_volatile;
if (!needs_lowering(type))
if (!is_aggregate_type(type))
continue;
arg = get_Call_param(call, i);
......@@ -670,12 +666,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 (needs_lowering(type))
if (is_aggregate_type(type))
++n_ret_com;
}
for (i = 0; i < n_params; ++i) {
ir_type *type = get_method_param_type(mtp, i);
if (needs_lowering(type))
if (is_aggregate_type(type))
++n_param_com;
}
......@@ -755,7 +751,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 (needs_lowering(tp)) {
if (is_aggregate_type(tp)) {
ir_node *arg = get_irg_args(irg);
arg = new_r_Proj(arg, mode_P_data, k);
++k;
......
......@@ -317,7 +317,7 @@ static void copy_parameter_entities(ir_node *call, ir_graph *called_graph)
ir_node *nomem = get_irg_no_mem(irg);
ir_node *sel = new_rd_simpleSel(dbgi, block, nomem, frame, new_entity);
ir_node *new_mem;
if (is_compound_type(old_type) || is_Array_type(old_type)) {
if (is_aggregate_type(old_type)) {
/* Copy the compound parameter */
bool is_volatile = is_partly_volatile(param) || is_partly_volatile(sel);
......@@ -424,9 +424,7 @@ static int inline_method(ir_node *const call, ir_graph *called_graph)
ir_type *param_tp = get_method_param_type(mtp, i);
ir_mode *mode = get_type_mode(param_tp);
if (!is_compound_type(param_tp)
&& !is_Array_type(param_tp)
&& mode != get_irn_mode(arg)) {
if (!is_aggregate_type(param_tp) && mode != get_irn_mode(arg)) {
arg = new_r_Conv(block, arg, mode);
}
args_in[i] = arg;
......@@ -550,15 +548,15 @@ static int inline_method(ir_node *const call, ir_graph *called_graph)
ir_node *call_res;
if (n_res > 0) {
for (int j = 0; j < n_res; j++) {
ir_type *res_type = get_method_res_type(ctp, j);
ir_mode *res_mode = get_type_mode(res_type);
int is_compound = is_compound_type(res_type) || is_Array_type(res_type);
ir_type *res_type = get_method_res_type(ctp, j);
ir_mode *res_mode = get_type_mode(res_type);
bool is_aggregate = is_aggregate_type(res_type);
int n_ret = 0;
for (int i = 0; i < arity; i++) {
ir_node *ret = get_Block_cfgpred(end_bl, i);
if (is_Return(ret)) {
ir_node *res = get_Return_res(ret, j);
if (is_compound) {
if (is_aggregate) {
res_mode = get_irn_mode(res);
} else if (get_irn_mode(res) != res_mode) {
ir_node *block = get_nodes_block(res);
......
......@@ -373,8 +373,7 @@ static int find_possible_replacements(ir_graph *irg)
/* we can handle arrays, structs and atomic types yet */
ir_type *ent_type = get_entity_type(ent);
if (is_Array_type(ent_type) || is_Struct_type(ent_type)
|| is_atomic_type(ent_type)) {
if (is_aggregate_type(ent_type) || is_atomic_type(ent_type)) {
if (is_address_taken(succ)) {
/* killing one */
if (get_entity_link(ent))
......@@ -675,7 +674,7 @@ void scalar_replacement_opt(ir_graph *irg)
if (is_Array_type(ent_type)) {
DB((dbg, SET_LEVEL_1, " found array %s\n", get_entity_name(ent)));
} else if (is_Struct_type(ent_type)) {
} else if (is_compound_type(ent_type)) {
DB((dbg, SET_LEVEL_1, " found struct %s\n", get_entity_name(ent)));
} else if (is_atomic_type(ent_type))
DB((dbg, SET_LEVEL_1, " found atomic value %s\n", get_entity_name(ent)));
......
......@@ -584,7 +584,7 @@ static void check_entity_initializer(ir_entity *entity)
ir_type *entity_tp = get_entity_type(entity);
switch (initializer->kind) {
case IR_INITIALIZER_COMPOUND:
assert(is_compound_type(entity_tp) || is_Array_type(entity_tp));
assert(is_aggregate_type(entity_tp));
break;
case IR_INITIALIZER_CONST:
/* methods are initialized by a SymConst */
......
......@@ -553,6 +553,17 @@ static inline void _set_method_calling_convention(ir_type *method, unsigned cc_m
method->attr.ma.irg_calling_conv = cc_mask;
}
/**
* Check if type is a compound or array type.
* This function returns true iff a value of this type cannot be represented by
* a firm mode and need therefore special handling in lower_calls when used as
* a parameter or return type.
*/
static inline bool is_aggregate_type(const ir_type *type)
{
return is_compound_type(type) || is_Array_type(type);
}
ir_type *new_type_segment(ident *name, type_flags flags);
#endif /* FIRM_TR_TYPE_T_H */
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