X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbepeephole.c;h=c2d4d1615e8242c47976e8bfe1462b8d6b73786a;hb=d081119723f6f0fdff8c0a6ca93492c1a7ed6a6f;hp=c9bb6e3069e770c0ae4c5cbe49e56ef148ad9c59;hpb=0fbcef83aa6060534172bb13e71cdadb04428806;p=libfirm diff --git a/ir/be/bepeephole.c b/ir/be/bepeephole.c index c9bb6e306..c2d4d1615 100644 --- a/ir/be/bepeephole.c +++ b/ir/be/bepeephole.c @@ -34,11 +34,11 @@ #include "irgmod.h" #include "error.h" -#include "beirg_t.h" +#include "beirg.h" #include "belive_t.h" -#include "bearch_t.h" -#include "benode_t.h" -#include "besched_t.h" +#include "bearch.h" +#include "benode.h" +#include "besched.h" #include "bemodule.h" DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;) @@ -265,8 +265,14 @@ static void skip_barrier(ir_node *ret_blk, ir_graph *irg) { foreach_out_edge_safe(irn, edge, next) { ir_node *proj = get_edge_src_irn(edge); - int pn = (int)get_Proj_proj(proj); - ir_node *pred = get_irn_n(irn, pn); + int pn; + ir_node *pred; + + if (is_Anchor(proj)) + continue; + + pn = (int) get_Proj_proj(proj); + pred = get_irn_n(irn, pn); edges_reroute_kind(proj, pred, EDGE_KIND_NORMAL, irg); edges_reroute_kind(proj, pred, EDGE_KIND_DEP, irg); @@ -298,8 +304,31 @@ static void kill_barriers(ir_graph *irg) { skip_barrier(start_blk, irg); } +/** + * Check whether the node has only one user. Explicitly ignore the anchor. + */ +static int has_only_one_user(ir_node *node) +{ + int n = get_irn_n_edges(node); + const ir_edge_t *edge; + + if (n <= 1) + return 1; + + if (n > 2) + return 0; + + foreach_out_edge(node, edge) { + ir_node *src = get_edge_src_irn(edge); + if (is_Anchor(src)) + return 1; + } + + return 0; +} + /* - * Tries to optimize a beIncSp node with it's previous IncSP node. + * Tries to optimize a beIncSP node with its previous IncSP node. * Must be run from a be_peephole_opt() context. */ ir_node *be_peephole_IncSP_IncSP(ir_node *node) @@ -312,7 +341,7 @@ ir_node *be_peephole_IncSP_IncSP(ir_node *node) if (!be_is_IncSP(pred)) return node; - if (get_irn_n_edges(pred) > 1) + if (!has_only_one_user(pred)) return node; pred_offs = be_get_IncSP_offset(pred); @@ -361,11 +390,11 @@ void be_peephole_opt(be_irg_t *birg) lv = be_get_birg_liveness(birg); n_classes = arch_env_get_n_reg_class(arch_env); - register_values = alloca(sizeof(register_values[0]) * n_classes); + register_values = ALLOCAN(ir_node**, n_classes); for(i = 0; i < n_classes; ++i) { const arch_register_class_t *cls = arch_env_get_reg_class(arch_env, i); unsigned n_regs = arch_register_class_n_regs(cls); - register_values[i] = alloca(sizeof(ir_node*) * n_regs); + register_values[i] = ALLOCAN(ir_node*, n_regs); } irg_block_walk_graph(irg, process_block, NULL, NULL);