X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Floop.c;h=39df5e583a2ed10d72f4c522af7844626f34196e;hb=a619ce99e40de4eb4481a590970a881e9f24627a;hp=74ac01b1d18035b1d3354b12e846b16f1f4a3482;hpb=30abccc0868ac7a535746a06ec8c082cd5cd1a3c;p=libfirm diff --git a/ir/opt/loop.c b/ir/opt/loop.c index 74ac01b1d..39df5e583 100644 --- a/ir/opt/loop.c +++ b/ir/opt/loop.c @@ -26,6 +26,8 @@ */ #include "config.h" +#include "iroptimize.h" +#include "opt_init.h" #include "irnode.h" #include "debug.h" @@ -36,16 +38,11 @@ #include "irouts.h" #include "iredges.h" #include "irtools.h" -#include "array_t.h" /* automatic array */ -#include "beutil.h" /* get_block */ -#include "irloop_t.h" /* set_irn_loop*/ +#include "array_t.h" +#include "beutil.h" +#include "irloop_t.h" #include "irpass.h" -#if 0 - #include "irdump_t.h" -#endif - - DEBUG_ONLY(static firm_dbg_module_t *dbg); /** @@ -135,7 +132,8 @@ static unsigned enable_unrolling; /** * Creates object on the heap, and adds it to a linked list to free it later. */ -static node_info *new_node_info(void) { +static node_info *new_node_info(void) +{ node_info *l = XMALLOCZ(node_info); l->freelistnext = link_node_state_list; link_node_state_list = l; @@ -163,7 +161,7 @@ static void free_node_info(void) int a = 0; node_info *n; n = link_node_state_list; - while(n) { + while (n) { node_info *next = n->freelistnext; ++a; xfree(n); @@ -180,7 +178,7 @@ static void reset_node_infos(void) { node_info *next; next = link_node_state_list; - while(next->freelistnext) { + while (next->freelistnext) { node_info *cur = next; next = cur->freelistnext; cur->copy = NULL; @@ -257,14 +255,15 @@ static unsigned is_nodesblock_marked(ir_node* node) } /* Returns the number of blocks in a loop. */ -int get_loop_n_blocks(ir_loop *loop) { +static int get_loop_n_blocks(ir_loop *loop) +{ int elements, e; int blocks = 0; elements = get_loop_n_elements(loop); - for(e=0; ecopy attributes has to be NULL prior to every to every walk. + * All nodes node_info->copy attributes have to be NULL prior to every walk. */ static void copy_walk(ir_node *node, walker_condition *walk_condition, ir_loop *set_loop) { @@ -736,10 +739,10 @@ static void copy_walk(ir_node *node, walker_condition *walk_condition, ir_loop * */ if (get_irn_visited(node) >= get_irg_visited(irg)) { /* Here we rely on nodestate's copy being initialized with NULL */ - DB((dbg, LEVEL_5, "copy_walk: We have already visited %ld\n", get_irn_node_nr(node))); + DB((dbg, LEVEL_5, "copy_walk: We have already visited %N\n", node)); if (node_info->copy == NULL) { cp = rawcopy_node(node); - DB((dbg, LEVEL_5, "The TEMP copy of %ld is created %ld\n", get_irn_node_nr(node), get_irn_node_nr(cp))); + DB((dbg, LEVEL_5, "The TEMP copy of %N is created %N\n", node, cp)); } return; } @@ -750,7 +753,7 @@ static void copy_walk(ir_node *node, walker_condition *walk_condition, ir_loop * if (!is_Block(node)) { ir_node *pred = get_nodes_block(node); if (walk_condition(pred)) - DB((dbg, LEVEL_5, "walk block %ld\n", get_irn_node_nr(pred))); + DB((dbg, LEVEL_5, "walk block %N\n", pred)); copy_walk(pred, walk_condition, set_loop); } @@ -758,15 +761,15 @@ static void copy_walk(ir_node *node, walker_condition *walk_condition, ir_loop * NEW_ARR_A(ir_node *, cpin, arity); - for (i = get_irn_arity(node) - 1; i >= 0; --i) { + for (i = 0; i < arity; ++i) { ir_node *pred = get_irn_n(node, i); if (walk_condition(pred)) { - DB((dbg, LEVEL_5, "walk node %ld\n", get_irn_node_nr(pred))); + DB((dbg, LEVEL_5, "walk node %N\n", pred)); copy_walk(pred, walk_condition, set_loop); cpin[i] = get_copy(pred); - DB((dbg, LEVEL_5, "copy of %ld gets new in %ld which is copy of %ld\n", - get_irn_node_nr(node), get_irn_node_nr(get_copy(pred)), get_irn_node_nr(pred))); + DB((dbg, LEVEL_5, "copy of %N gets new in %N which is copy of %N\n", + node, get_copy(pred), pred)); } else { cpin[i] = pred; } @@ -776,19 +779,18 @@ static void copy_walk(ir_node *node, walker_condition *walk_condition, ir_loop * if (node_info->copy == NULL) { /* No temporary copy existent */ cp = rawcopy_node(node); - DB((dbg, LEVEL_5, "The FINAL copy of %ld is CREATED %ld\n", get_irn_node_nr(node), get_irn_node_nr(cp))); + DB((dbg, LEVEL_5, "The FINAL copy of %N is CREATED %N\n", node, cp)); } else { /* temporary copy is existent but without correct ins */ cp = get_copy(node); - DB((dbg, LEVEL_5, "The FINAL copy of %ld is EXISTENT %ld\n", get_irn_node_nr(node), get_irn_node_nr(cp))); + DB((dbg, LEVEL_5, "The FINAL copy of %N is EXISTENT %N\n", node, cp)); } if (!is_Block(node)) { ir_node *cpblock = get_copy(get_nodes_block(node)); set_nodes_block(cp, cpblock ); - /* fix the phi information in attr.phis */ - if( is_Phi(cp) ) + if (is_Phi(cp)) add_Block_phi(cpblock, cp); } @@ -812,7 +814,7 @@ static void peel(out_edge *loop_outs) /* duplicate loop walk */ inc_irg_visited(current_ir_graph); - for(i = 0; i < ARR_LEN(loop_outs); i++) { + for (i = 0; i < ARR_LEN(loop_outs); i++) { out_edge entry = loop_outs[i]; ir_node *node = entry.node; ir_node *pred = get_irn_n(entry.node, entry.pred_irn_n); @@ -823,11 +825,13 @@ static void peel(out_edge *loop_outs) } else { copy_walk(pred, is_in_loop, NULL); /* leave out keepalives */ - if (!is_End(node)) + if (!is_End(node)) { /* Node is user of a value defined inside the loop. * We'll need a phi since we duplicated the loop. */ /* Cannot construct_ssa here, because it needs another walker. */ - entry_buffer[entry_c++] = pred; + entry_buffer[entry_c] = pred; + ++entry_c; + } } } @@ -838,7 +842,7 @@ static void peel(out_edge *loop_outs) /* Generate phis for values from peeled code and original loop */ construct_ssa_foreach(entry_buffer, entry_c); - /*for(i = 0; i < entry_c; i++) + /*for (i = 0; i < entry_c; i++) { ir_node *cppred, *block, *cpblock, *pred; @@ -861,14 +865,14 @@ static void get_head_outs(ir_node *node, void *env) int arity = get_irn_arity(node); (void) env; - DB((dbg, LEVEL_5, "get head entries %ld \n", get_irn_node_nr(node))); + DB((dbg, LEVEL_5, "get head entries %N \n", node)); - for(i = 0; i < arity; ++i) { + for (i = 0; i < arity; ++i) { /* node is not in the head, but the predecessor is. * (head or loop chain nodes are marked) */ DB((dbg, LEVEL_5, "... ")); - DB((dbg, LEVEL_5, "node %ld marked %d (0) pred %d marked %d (1) \n", + DB((dbg, LEVEL_5, "node %N marked %d (0) pred %d marked %d (1) \n", node->node_nr, is_nodesblock_marked(node),i, is_nodesblock_marked(get_irn_n(node, i)))); if (!is_nodesblock_marked(node) && is_nodesblock_marked(get_irn_n(node, i))) { @@ -876,8 +880,8 @@ static void get_head_outs(ir_node *node, void *env) entry.node = node; entry.pred_irn_n = i; DB((dbg, LEVEL_5, - "Found head chain entry %ld @%d because !inloop %ld and inloop %ld\n", - get_irn_node_nr(node), i, get_irn_node_nr(node), get_irn_node_nr(get_irn_n(node, i)))); + "Found head chain entry %N @%d because !inloop %N and inloop %N\n", + node, i, node, get_irn_n(node, i))); ARR_APP1(out_edge, cur_head_outs, entry); } } @@ -888,12 +892,13 @@ static void get_head_outs(ir_node *node, void *env) * A block belongs to the chain if a condition branches out of the loop. * Returns 1 if the given block belongs to the condition chain. */ -static unsigned find_condition_chains(ir_node *block) { +static unsigned find_condition_chains(ir_node *block) +{ const ir_edge_t *edge; unsigned mark = 0; int nodes_n = 0; - DB((dbg, LEVEL_5, "condition_chains for block %ld\n", get_irn_node_nr(block))); + DB((dbg, LEVEL_5, "condition_chains for block %N\n", block)); /* Collect all outs, including keeps. * (TODO firm function for number of out edges?) */ @@ -935,7 +940,7 @@ static unsigned find_condition_chains(ir_node *block) { } else { set_Block_mark(block, 1); ++head_inversion_block_count; - DB((dbg, LEVEL_5, "block %ld is part of condition chain\n", get_irn_node_nr(block))); + DB((dbg, LEVEL_5, "block %N is part of condition chain\n", block)); head_inversion_node_count += nodes_n; } @@ -951,7 +956,7 @@ static unsigned find_condition_chains(ir_node *block) { } mark_irn_visited(src); - DB((dbg, LEVEL_5, "condition chain walk %ld\n", get_irn_node_nr(src))); + DB((dbg, LEVEL_5, "condition chain walk %N\n", src)); inchain = find_condition_chains(src); /* if successor is not part of chain we need to collect its outs */ @@ -1050,9 +1055,11 @@ static void inversion_walk(out_edge *head_entries) head_phi_assign = NEW_ARR_F(ir_node *, 0); - /* Find assignments in the condition chain, to construct_ssa for them after the loop inversion. */ + /* Find assignments in the condition chain, + * to construct_ssa for them after the loop inversion. */ for_each_phi(loop_cf_head , phi) { - for(i=0; i>>> current loop includes node %ld <<<\n", get_irn_node_nr(get_loop_node(loop, 0)))); + DB((dbg, LEVEL_2, " >>>> current loop includes node %N <<<\n", get_loop_node(loop, 0))); irg_walk_graph(current_ir_graph, get_loop_info, NULL, NULL); @@ -1407,7 +1419,7 @@ static void init_analyze(ir_loop *loop) return; #endif - DB((dbg, LEVEL_2, " <<<< end of loop with node %ld >>>>\n", get_irn_node_nr(get_loop_node(loop, 0)))); + DB((dbg, LEVEL_2, " <<<< end of loop with node %N >>>>\n", get_loop_node(loop, 0))); } /* Find most inner loops and send them to analyze_loop */ @@ -1434,7 +1446,7 @@ static void find_most_inner_loop(ir_loop *loop) } } else { int s; - for(s=0; s>> unrolling (Startnode %ld) <<<\n", - get_irn_node_nr(get_irg_start(irg)))); + DB((dbg, LEVEL_2, " >>> unrolling (Startnode %N) <<<\n", + get_irg_start(irg))); loop_optimization(irg); - DB((dbg, LEVEL_2, " >>> unrolling done (Startnode %ld) <<<\n", - get_irn_node_nr(get_irg_start(irg)))); + DB((dbg, LEVEL_2, " >>> unrolling done (Startnode %N) <<<\n", + get_irg_start(irg))); } void do_loop_inversion(ir_graph *irg) @@ -1557,13 +1569,13 @@ void do_loop_inversion(ir_graph *irg) enable_peeling = 0; enable_inversion = 1; - DB((dbg, LEVEL_2, " >>> inversion (Startnode %ld) <<<\n", - get_irn_node_nr(get_irg_start(irg)))); + DB((dbg, LEVEL_2, " >>> inversion (Startnode %N) <<<\n", + get_irg_start(irg))); loop_optimization(irg); - DB((dbg, LEVEL_2, " >>> inversion done (Startnode %ld) <<<\n", - get_irn_node_nr(get_irg_start(irg)))); + DB((dbg, LEVEL_2, " >>> inversion done (Startnode %N) <<<\n", + get_irg_start(irg))); } void do_loop_peeling(ir_graph *irg) @@ -1572,25 +1584,28 @@ void do_loop_peeling(ir_graph *irg) enable_peeling = 1; enable_inversion = 0; - DB((dbg, LEVEL_2, " >>> peeling (Startnode %ld) <<<\n", - get_irn_node_nr(get_irg_start(irg)))); + DB((dbg, LEVEL_2, " >>> peeling (Startnode %N) <<<\n", + get_irg_start(irg))); loop_optimization(irg); - DB((dbg, LEVEL_2, " >>> peeling done (Startnode %ld) <<<\n", - get_irn_node_nr(get_irg_start(irg)))); + DB((dbg, LEVEL_2, " >>> peeling done (Startnode %N) <<<\n", + get_irg_start(irg))); } -ir_graph_pass_t *loop_inversion_pass(const char *name) { +ir_graph_pass_t *loop_inversion_pass(const char *name) +{ return def_graph_pass(name ? name : "loop_inversion", do_loop_inversion); } -ir_graph_pass_t *loop_unroll_pass(const char *name) { +ir_graph_pass_t *loop_unroll_pass(const char *name) +{ return def_graph_pass(name ? name : "loop_unroll", do_loop_unrolling); } -ir_graph_pass_t *loop_peeling_pass(const char *name) { +ir_graph_pass_t *loop_peeling_pass(const char *name) +{ return def_graph_pass(name ? name : "loop_peeling", do_loop_peeling); }