X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeabihelper.c;h=75ca7e893b6b5f7f75cad84ad0edad6bae180c2a;hb=199ea1a4479a4d8dcbebfde81820286935e64b0c;hp=62d8591590118caf6362b6d0ff9485cbbda4d834;hpb=1a3b7d363474ab544c13093a2f0b578718d37c7a;p=libfirm diff --git a/ir/be/beabihelper.c b/ir/be/beabihelper.c index 62d859159..75ca7e893 100644 --- a/ir/be/beabihelper.c +++ b/ir/be/beabihelper.c @@ -22,18 +22,19 @@ * @brief Helper functions for handling ABI constraints in the code * selection phase. * @author Matthias Braun - * @version $Id$ */ #include "config.h" #include "beabihelper.h" #include "bearch.h" +#include "beirg.h" #include "benode.h" #include "besched.h" #include "ircons.h" #include "iredges.h" #include "irgwalk.h" -#include "irphase_t.h" +#include "irnodemap.h" +#include "irtools.h" #include "heights.h" /** @@ -65,7 +66,6 @@ struct beabi_helper_env_t { ir_graph *irg; /**< the graph we operate on */ register_state_mapping_t prolog; /**< the register state map for the prolog */ register_state_mapping_t epilog; /**< the register state map for the epilog */ - ir_phase *stack_order; /**< a phase to handle stack dependencies. */ }; /** @@ -165,9 +165,9 @@ static void rsm_clear_regs(register_state_mapping_t *rsm, * Add a register and its constraint flags to a register state map * and return its index inside the map. */ -static int rsm_add_reg(register_state_mapping_t *rsm, - const arch_register_t *reg, - arch_register_req_type_t flags) +static size_t rsm_add_reg(register_state_mapping_t *rsm, + const arch_register_t *reg, + arch_register_req_type_t flags) { size_t input_idx = ARR_LEN(rsm->regs); int cls_idx = reg->reg_class->index; @@ -267,8 +267,6 @@ ir_node *be_prolog_create_start(beabi_helper_env_t *env, dbg_info *dbgi, ir_node *start = be_new_Start(dbgi, block, n_start_outs); int o; - arch_irn_add_flags(start, arch_irn_flags_prolog); - assert(env->prolog.value_map == NULL); env->prolog.value_map = NEW_ARR_F(ir_node*, n_start_outs); @@ -277,12 +275,12 @@ ir_node *be_prolog_create_start(beabi_helper_env_t *env, dbg_info *dbgi, const arch_register_t *reg = regflag->reg; ir_node *proj; if (reg == NULL) { - arch_set_out_register_req(start, o, arch_no_register_req); + arch_set_irn_register_req_out(start, o, arch_no_register_req); proj = new_r_Proj(start, mode_M, o); } else { be_set_constr_single_reg_out(start, o, regflag->reg, regflag->flags); - arch_irn_set_register(start, o, regflag->reg); + arch_set_irn_register_out(start, o, regflag->reg); proj = new_r_Proj(start, reg->reg_class->mode, o); } env->prolog.value_map[o] = proj; @@ -326,7 +324,7 @@ void be_epilog_begin(beabi_helper_env_t *env) void be_epilog_add_reg(beabi_helper_env_t *env, const arch_register_t *reg, arch_register_req_type_t flags, ir_node *value) { - int index = rsm_add_reg(&env->epilog, reg, flags); + size_t index = rsm_add_reg(&env->epilog, reg, flags); rsm_set_value(&env->epilog, index, value); } @@ -366,7 +364,6 @@ ir_node *be_epilog_create_return(beabi_helper_env_t *env, dbg_info *dbgi, ret = be_new_Return(dbgi, get_irn_irg(block), block, n_res, pop, n_return_in, in); - arch_irn_add_flags(ret, arch_irn_flags_epilog); for (i = 0; i < n_return_in; ++i) { const reg_flag_t *regflag = &env->epilog.regs[i]; const arch_register_t *reg = regflag->reg; @@ -387,7 +384,6 @@ ir_node *be_epilog_create_return(beabi_helper_env_t *env, dbg_info *dbgi, */ static bool has_real_user(const ir_node *node) { - const ir_edge_t *edge; foreach_out_edge(node, edge) { ir_node *user = get_edge_src_irn(edge); if (!is_End(user) && !is_Anchor(user)) @@ -399,7 +395,6 @@ static bool has_real_user(const ir_node *node) static ir_node *add_to_keep(ir_node *last_keep, const arch_register_class_t *cls, ir_node *node) { - const ir_node *op; if (last_keep != NULL) { be_Keep_add_node(last_keep, cls, node); } else { @@ -413,25 +408,18 @@ static ir_node *add_to_keep(ir_node *last_keep, sched_add_after(schedpoint, last_keep); } } - op = skip_Proj_const(node); - if (arch_irn_get_flags(op) & arch_irn_flags_prolog) - arch_irn_add_flags(last_keep, arch_irn_flags_prolog); - if (arch_irn_get_flags(op) & arch_irn_flags_epilog) - arch_irn_add_flags(last_keep, arch_irn_flags_epilog); return last_keep; } -static void add_missing_keep_walker(ir_node *node, void *data) +void be_add_missing_keeps_node(ir_node *node) { - int n_outs, i; - unsigned *found_projs; - const ir_edge_t *edge; - ir_mode *mode = get_irn_mode(node); - ir_node *last_keep; - (void) data; + int n_outs, i; + ir_mode *mode = get_irn_mode(node); + ir_node *last_keep; + if (mode != mode_T) { if (!has_real_user(node)) { - const arch_register_req_t *req = arch_get_register_req_out(node); + const arch_register_req_t *req = arch_get_irn_register_req(node); const arch_register_class_t *cls = req->cls; if (cls == NULL || (cls->flags & arch_register_class_flag_manual_ra)) { @@ -443,11 +431,12 @@ static void add_missing_keep_walker(ir_node *node, void *data) return; } - n_outs = arch_irn_get_n_outs(node); + n_outs = arch_get_irn_n_outs(node); if (n_outs <= 0) return; - rbitset_alloca(found_projs, n_outs); + unsigned *const found_projs = rbitset_alloca(n_outs); + ir_node **const existing_projs = ALLOCANZ(ir_node*, n_outs); foreach_out_edge(node, edge) { ir_node *succ = get_edge_src_irn(edge); ir_mode *mode = get_irn_mode(succ); @@ -458,10 +447,11 @@ static void add_missing_keep_walker(ir_node *node, void *data) continue; if (mode == mode_M || mode == mode_X) continue; + pn = get_Proj_proj(succ); + existing_projs[pn] = succ; if (!has_real_user(succ)) continue; - pn = get_Proj_proj(succ); assert(pn < n_outs); rbitset_set(found_projs, pn); } @@ -477,17 +467,25 @@ static void add_missing_keep_walker(ir_node *node, void *data) continue; } - req = arch_get_out_register_req(node, i); + req = arch_get_irn_register_req_out(node, i); cls = req->cls; if (cls == NULL || (cls->flags & arch_register_class_flag_manual_ra)) { continue; } - value = new_r_Proj(node, arch_register_class_mode(cls), i); + value = existing_projs[i]; + if (value == NULL) + value = new_r_Proj(node, arch_register_class_mode(cls), i); last_keep = add_to_keep(last_keep, cls, value); } } +static void add_missing_keep_walker(ir_node *node, void *data) +{ + (void)data; + be_add_missing_keeps_node(node); +} + void be_add_missing_keeps(ir_graph *irg) { irg_walk_graph(irg, add_missing_keep_walker, NULL, NULL); @@ -571,6 +569,7 @@ static int cmp_call_dependency(const void *c1, const void *c2) { const ir_node *n1 = *(const ir_node **) c1; const ir_node *n2 = *(const ir_node **) c2; + unsigned h1, h2; if (dependent_on(n1, n2)) return 1; @@ -579,7 +578,16 @@ static int cmp_call_dependency(const void *c1, const void *c2) return -1; /* The nodes have no depth order, but we need a total order because qsort() - * is not stable. */ + * is not stable. + * + * Additionally, we need to respect transitive dependencies. Consider a + * Call a depending on Call b and an independent Call c. + * We MUST NOT order c > a and b > c. */ + h1 = get_irn_height(heights, n1); + h2 = get_irn_height(heights, n2); + if (h1 < h2) return 1; + if (h1 > h2) return -1; + /* Same height, so use a random (but stable) order */ return get_irn_idx(n2) - get_irn_idx(n1); } @@ -588,11 +596,11 @@ static int cmp_call_dependency(const void *c1, const void *c2) */ static void process_ops_in_block(ir_node *block, void *data) { - ir_phase *phase = (ir_phase*)data; - unsigned n; - unsigned n_nodes; - ir_node *node; - ir_node **nodes; + ir_nodemap *map = (ir_nodemap*)data; + unsigned n; + unsigned n_nodes; + ir_node *node; + ir_node **nodes; n_nodes = 0; for (node = (ir_node*)get_irn_link(block); node != NULL; @@ -619,29 +627,114 @@ static void process_ops_in_block(ir_node *block, void *data) ir_node *node = nodes[n]; ir_node *pred = nodes[n-1]; - phase_set_irn_data(phase, node, pred); + ir_nodemap_insert(map, node, pred); } xfree(nodes); } -void be_collect_stacknodes(beabi_helper_env_t *env) + + +struct be_stackorder_t { + ir_nodemap stack_order; /**< a phase to handle stack dependencies. */ +}; + +be_stackorder_t *be_collect_stacknodes(ir_graph *irg) { - ir_graph *irg = env->irg; + be_stackorder_t *env = XMALLOCZ(be_stackorder_t); + + ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK); /* collect all potential^stack accessing nodes */ irg_walk_graph(irg, firm_clear_link, link_ops_in_block_walker, NULL); - assert(env->stack_order == NULL); - env->stack_order = new_phase(irg, phase_irn_init_default); + ir_nodemap_init(&env->stack_order, irg); /* use heights to create a total order for those nodes: this order is stored * in the created phase */ heights = heights_new(irg); - irg_block_walk_graph(irg, NULL, process_ops_in_block, env->stack_order); + irg_block_walk_graph(irg, NULL, process_ops_in_block, &env->stack_order); heights_free(heights); + + ir_free_resources(irg, IR_RESOURCE_IRN_LINK); + + return env; } -ir_node *be_get_stack_pred(const beabi_helper_env_t *env, const ir_node *node) +ir_node *be_get_stack_pred(const be_stackorder_t *env, const ir_node *node) { - return (ir_node*)phase_get_irn_data(env->stack_order, node); + return ir_nodemap_get(ir_node, &env->stack_order, node); +} + +void be_free_stackorder(be_stackorder_t *env) +{ + ir_nodemap_destroy(&env->stack_order); + free(env); +} + +static void create_stores_for_type(ir_graph *irg, ir_type *type) +{ + size_t n = get_compound_n_members(type); + ir_node *frame = get_irg_frame(irg); + ir_node *initial_mem = get_irg_initial_mem(irg); + ir_node *mem = initial_mem; + ir_node *first_store = NULL; + ir_node *start_block = get_irg_start_block(irg); + ir_node *args = get_irg_args(irg); + size_t i; + + /* all parameter entities left in the frame type require stores. + * (The ones passed on the stack have been moved to the arg type) */ + for (i = 0; i < n; ++i) { + ir_entity *entity = get_compound_member(type, i); + ir_node *addr; + size_t arg; + if (!is_parameter_entity(entity)) + continue; + + arg = get_entity_parameter_number(entity); + if (arg == IR_VA_START_PARAMETER_NUMBER) + continue; + + addr = new_r_Sel(start_block, mem, frame, 0, NULL, entity); + if (entity->attr.parameter.doubleword_low_mode != NULL) { + ir_mode *mode = entity->attr.parameter.doubleword_low_mode; + ir_node *val0 = new_r_Proj(args, mode, arg); + ir_node *val1 = new_r_Proj(args, mode, arg+1); + ir_node *store0 = new_r_Store(start_block, mem, addr, val0, + cons_none); + ir_node *mem0 = new_r_Proj(store0, mode_M, pn_Store_M); + size_t offset = get_mode_size_bits(mode)/8; + ir_mode *addr_mode = get_irn_mode(addr); + ir_node *cnst = new_r_Const_long(irg, addr_mode, offset); + ir_node *next_addr = new_r_Add(start_block, addr, cnst, addr_mode); + ir_node *store1 = new_r_Store(start_block, mem0, next_addr, val1, + cons_none); + mem = new_r_Proj(store1, mode_M, pn_Store_M); + if (first_store == NULL) + first_store = store0; + } else { + ir_type *tp = get_entity_type(entity); + ir_mode *mode = is_compound_type(tp) ? mode_P : get_type_mode(tp); + ir_node *val = new_r_Proj(args, mode, arg); + ir_node *store = new_r_Store(start_block, mem, addr, val, cons_none); + mem = new_r_Proj(store, mode_M, pn_Store_M); + if (first_store == NULL) + first_store = store; + } + } + + if (mem != initial_mem) + edges_reroute_except(initial_mem, mem, first_store); +} + +void be_add_parameter_entity_stores(ir_graph *irg) +{ + ir_type *frame_type = get_irg_frame_type(irg); + be_stack_layout_t *layout = be_get_irg_stack_layout(irg); + ir_type *between_type = layout->between_type; + + create_stores_for_type(irg, frame_type); + if (between_type != NULL) { + create_stores_for_type(irg, between_type); + } }