X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbechordal_main.c;h=c17ed38d95476926dd3e43468878107bab9d0f43;hb=0b1140d1887f497ef413709e5cda2608f2cd1017;hp=3922b8f653fca0c87a92f2bdd02e5e30a9b60d82;hpb=ad49038075a82cd445fafb530453bc767abf9f2d;p=libfirm diff --git a/ir/be/bechordal_main.c b/ir/be/bechordal_main.c index 3922b8f65..c17ed38d9 100644 --- a/ir/be/bechordal_main.c +++ b/ir/be/bechordal_main.c @@ -222,100 +222,8 @@ static INLINE void check_for_memory_operands(be_chordal_env_t *chordal_env) { irg_walk_graph(chordal_env->irg, NULL, memory_operand_walker, chordal_env); } -/** - * Sorry for doing stats again... - */ -typedef struct _node_stat_t { - unsigned int n_phis; /**< Phis of the current register class. */ - unsigned int n_mem_phis; /**< Memory Phis (Phis with spill operands). */ - unsigned int n_copies; /**< Copies */ - unsigned int n_perms; /**< Perms */ - unsigned int n_spills; /**< Spill nodes */ - unsigned int n_reloads; /**< Reloads */ -} node_stat_t; - -struct node_stat_walker { - node_stat_t *stat; - const arch_env_t *arch_env; - bitset_t *mem_phis; - const arch_register_class_t *cls; -}; - -static void node_stat_walker(ir_node *irn, void *data) -{ - struct node_stat_walker *env = data; - const arch_env_t *aenv = env->arch_env; - - if (arch_irn_consider_in_reg_alloc(aenv, env->cls, irn)) { - - /* if the node is a normal phi */ - if(is_Phi(irn)) - env->stat->n_phis++; - - else { - arch_irn_class_t classify = arch_irn_classify(aenv, irn); - - if(classify & arch_irn_class_spill) - ++env->stat->n_spills; - if(classify & arch_irn_class_reload) - ++env->stat->n_reloads; - if(classify & arch_irn_class_copy) - ++env->stat->n_copies; - if(classify & arch_irn_class_perm) - ++env->stat->n_perms; - } - } - - /* a mem phi is a PhiM with a mem phi operand or a Spill operand */ - /*else*/ if(is_Phi(irn) && get_irn_mode(irn) == mode_M) { - int i; - - for(i = get_irn_arity(irn) - 1; i >= 0; --i) { - ir_node *op = get_irn_n(irn, i); - - if((is_Phi(op) && bitset_contains_irn(env->mem_phis, op)) || (arch_irn_classify(aenv, op) & arch_irn_class_spill)) { - bitset_add_irn(env->mem_phis, irn); - env->stat->n_mem_phis++; - break; - } - } - } -} - -static void node_stats(be_irg_t *birg, const arch_register_class_t *cls, node_stat_t *stat) -{ - struct node_stat_walker env; - - memset(stat, 0, sizeof(stat[0])); - env.arch_env = birg->main_env->arch_env; - env.mem_phis = bitset_irg_malloc(birg->irg); - env.stat = stat; - env.cls = cls; - irg_walk_graph(birg->irg, NULL, node_stat_walker, &env); - bitset_free(env.mem_phis); -} - -static void insn_count_walker(ir_node *irn, void *data) -{ - int *cnt = data; - - switch(get_irn_opcode(irn)) { - case iro_Proj: - case iro_Phi: - case iro_Start: - case iro_End: - break; - default: - (*cnt)++; - } -} -static unsigned int count_insns(ir_graph *irg) -{ - int cnt = 0; - irg_walk_graph(irg, insn_count_walker, NULL, &cnt); - return cnt; -} +static be_node_stats_t last_node_stats; /** * Perform things which need to be done per register class before spilling. @@ -326,7 +234,6 @@ static void pre_spill(post_spill_env_t *pse, const arch_register_class_t *cls) be_irg_t *birg = pse->birg; ir_graph *irg = be_get_birg_irg(birg); const be_main_env_t *main_env = birg->main_env; - node_stat_t node_stat; pse->cls = cls; chordal_env->cls = cls; @@ -336,10 +243,7 @@ static void pre_spill(post_spill_env_t *pse, const arch_register_class_t *cls) be_assure_liveness(birg); be_liveness_assure_chk(be_get_birg_liveness(birg)); - stat_ev_ctx_push_str("bechordal_cls", pse->cls->name); - stat_ev_do(node_stats(birg, pse->cls, &node_stat)); stat_ev_do(pse->pre_spill_cost = be_estimate_irg_costs(irg, main_env->arch_env, birg->exec_freq)); - stat_ev_dbl("phis_before_spill", node_stat.n_phis); /* put all ignore registers into the ignore register set. */ be_put_ignore_regs(birg, pse->cls, chordal_env->ignore_colors); @@ -349,8 +253,6 @@ static void pre_spill(post_spill_env_t *pse, const arch_register_class_t *cls) BE_TIMER_POP(t_ra_constr); dump(BE_CH_DUMP_CONSTR, birg->irg, pse->cls, "-constr-pre", dump_ir_block_graph_sched); - - stat_ev_ctx_pop("bechordal_cls"); } /** @@ -361,32 +263,24 @@ static void post_spill(post_spill_env_t *pse, int iteration) { be_irg_t *birg = pse->birg; ir_graph *irg = birg->irg; const be_main_env_t *main_env = birg->main_env; - node_stat_t node_stat; int colors_n = arch_register_class_n_regs(chordal_env->cls); int allocatable_regs = colors_n - be_put_ignore_regs(birg, chordal_env->cls, NULL); /* some special classes contain only ignore regs, no work to be done */ if (allocatable_regs > 0) { - - stat_ev_ctx_push_str("bechordal_cls", pse->cls->name); - stat_ev_do(node_stats(birg, pse->cls, &node_stat)); - stat_ev_dbl("phis_after_spill", node_stat.n_phis); - stat_ev_dbl("mem_phis", node_stat.n_mem_phis); - stat_ev_dbl("reloads", node_stat.n_reloads); - stat_ev_dbl("spills", node_stat.n_spills); - stat_ev_dbl("spillcosts", be_estimate_irg_costs(irg, main_env->arch_env, birg->exec_freq) - pse->pre_spill_cost); + stat_ev_dbl("bechordal_spillcosts", be_estimate_irg_costs(irg, main_env->arch_env, birg->exec_freq) - pse->pre_spill_cost); /* If we have a backend provided spiller, post spill is called in a loop after spilling for each register class. But we only need to fix stack nodes once in this case. */ - BE_TIMER_PUSH(t_ra_spill); + BE_TIMER_PUSH(t_ra_spill_apply); check_for_memory_operands(chordal_env); if (iteration == 0) { be_abi_fix_stack_nodes(birg->abi); } - BE_TIMER_POP(t_ra_spill); + BE_TIMER_POP(t_ra_spill_apply); BE_TIMER_PUSH(t_verify); @@ -413,17 +307,22 @@ static void post_spill(post_spill_env_t *pse, int iteration) { chordal_env->ifg = be_create_ifg(chordal_env); BE_TIMER_POP(t_ra_ifg); - { - be_ifg_stat_t stat; + stat_ev_if { + be_ifg_stat_t stat; + be_node_stats_t node_stats; - stat_ev_do(be_ifg_stat(birg, chordal_env->ifg, &stat)); - stat_ev_dbl("ifg_nodes", stat.n_nodes); - stat_ev_dbl("ifg_edges", stat.n_edges); - stat_ev_dbl("ifg_comps", stat.n_comps); + be_ifg_stat(birg, chordal_env->ifg, &stat); + stat_ev_dbl("bechordal_ifg_nodes", stat.n_nodes); + stat_ev_dbl("bechordal_ifg_edges", stat.n_edges); + stat_ev_dbl("bechordal_ifg_comps", stat.n_comps); - stat_ev_do(node_stats(birg, pse->cls, &node_stat)); - stat_ev_dbl("perms_before_coal", node_stat.n_perms); - stat_ev_dbl("copies_before_coal", node_stat.n_copies); + be_collect_node_stats(&node_stats, birg); + be_subtract_node_stats(&node_stats, &last_node_stats); + + stat_ev_dbl("bechordal_perms_before_coal", + node_stats[BE_STAT_PERMS]); + stat_ev_dbl("bechordal_copies_before_coal", + node_stats[BE_STAT_COPIES]); } /* copy minimization */ @@ -436,9 +335,7 @@ static void post_spill(post_spill_env_t *pse, int iteration) { /* ssa destruction */ BE_TIMER_PUSH(t_ra_ssa); - stat_ev_ctx_push_str("berachordal_phase", "ssadestr"); be_ssa_destruction(chordal_env); - stat_ev_ctx_pop("berachordal_phase"); BE_TIMER_POP(t_ra_ssa); dump(BE_CH_DUMP_SSADESTR, irg, pse->cls, "-ssadestr", dump_ir_block_graph_sched); @@ -449,11 +346,6 @@ static void post_spill(post_spill_env_t *pse, int iteration) { BE_TIMER_POP(t_verify); } - stat_ev_do(node_stats(birg, pse->cls, &node_stat)); - stat_ev_dbl("perms_after_coal", node_stat.n_perms); - stat_ev_dbl("copies_after_coal", node_stat.n_copies); - stat_ev_ctx_pop("bechordal_cls"); - /* the ifg exists only if there are allocatable regs */ be_ifg_free(chordal_env->ifg); } @@ -499,7 +391,7 @@ static void be_ra_chordal_main(be_irg_t *birg) BE_TIMER_POP(t_ra_prolog); stat_ev_if { - be_stat_ev("insns_before", count_insns(irg)); + be_collect_node_stats(&last_node_stats, birg); } if (! arch_code_generator_has_spiller(birg->cg)) { @@ -515,6 +407,12 @@ static void be_ra_chordal_main(be_irg_t *birg) continue; + stat_ev_ctx_push_str("bechordal_cls", cls->name); + + stat_ev_if { + be_do_stat_reg_pressure(birg, cls); + } + memcpy(&pse.cenv, &chordal_env, sizeof(chordal_env)); pse.birg = birg; pre_spill(&pse, cls); @@ -527,6 +425,17 @@ static void be_ra_chordal_main(be_irg_t *birg) dump_ir_block_graph_sched); post_spill(&pse, 0); + + stat_ev_if { + be_node_stats_t node_stats; + + be_collect_node_stats(&node_stats, birg); + be_subtract_node_stats(&node_stats, &last_node_stats); + be_emit_node_stats(&node_stats, "bechordal_"); + + be_copy_node_stats(&last_node_stats, &node_stats); + stat_ev_ctx_pop("bechordal_cls"); + } } } else { post_spill_env_t *pse; @@ -565,10 +474,6 @@ static void be_ra_chordal_main(be_irg_t *birg) BE_TIMER_POP(t_ra_epilog); BE_TIMER_POP(t_ra_other); - - stat_ev_if { - be_stat_ev("insns_after", count_insns(irg)); - } } static be_ra_t be_ra_chordal_allocator = {