X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana%2Firscc.c;h=e4a7595e39fc8d1aa4bf27819bb45db0347c8bcb;hb=58e533a640ff427362877a3d2f1a5142c96391e1;hp=d33c8f6fbc113a8ab9415128fe407d31fa5ac38b;hpb=5037b56eddcf063cf18a0574422fb15c4fafb156;p=libfirm diff --git a/ir/ana/irscc.c b/ir/ana/irscc.c index d33c8f6fb..e4a7595e3 100644 --- a/ir/ana/irscc.c +++ b/ir/ana/irscc.c @@ -14,14 +14,15 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #ifdef HAVE_STRING_H -#include +# include +#endif +#ifdef HAVE_STDLIB_H +# include #endif - -#include #include "irloop_t.h" @@ -38,11 +39,6 @@ This reduces the depth of the loop tree. */ #define NO_LOOPS_WITHOUT_HEAD 1 - -INLINE void add_loop_son(ir_loop *loop, ir_loop *son); - -INLINE void add_loop_node(ir_loop *loop, ir_node *n); - static ir_graph *outermost_ir_graph; /* The outermost graph the scc is computed for */ static ir_loop *current_loop; /* Current loop construction is working @@ -68,9 +64,9 @@ ir_node *get_projx_link(ir_node *cb_projx); /**********************************************************************/ typedef struct scc_info { - bool in_stack; /* Marks whether node is on the stack. */ - int dfn; /* Depth first search number. */ - int uplink; /* dfn number of ancestor. */ + int in_stack; /**< Marks whether node is on the stack. */ + int dfn; /**< Depth first search number. */ + int uplink; /**< dfn number of ancestor. */ /* ir_loop *loop; *//* Refers to the containing loop. */ /* struct section *section; @@ -89,17 +85,17 @@ static INLINE void mark_irn_in_stack (ir_node *n) { scc_info *scc = get_irn_link(n); assert(scc); - scc->in_stack = true; + scc->in_stack = 1; } static INLINE void mark_irn_not_in_stack (ir_node *n) { scc_info *scc = get_irn_link(n); assert(scc); - scc->in_stack = false; + scc->in_stack = 0; } -static INLINE bool +static INLINE int irn_is_in_stack (ir_node *n) { scc_info *scc = get_irn_link(n); assert(scc); @@ -113,7 +109,7 @@ set_irn_uplink (ir_node *n, int uplink) { scc->uplink = uplink; } -INLINE int +int get_irn_uplink (ir_node *n) { scc_info *scc = get_irn_link(n); assert(scc); @@ -127,7 +123,7 @@ set_irn_dfn (ir_node *n, int dfn) { scc->dfn = dfn; } -INLINE int +int get_irn_dfn (ir_node *n) { scc_info *scc = get_irn_link(n); assert(scc); @@ -135,13 +131,13 @@ get_irn_dfn (ir_node *n) { } -INLINE void +void set_irn_loop (ir_node *n, ir_loop *loop) { n->loop = loop; } /* Uses temporary information to get the loop */ -INLINE ir_loop * +ir_loop * get_irn_loop (ir_node *n) { return n->loop; } @@ -374,7 +370,7 @@ int get_loop_n_sons (ir_loop *loop) { /* Returns the pos`th loop_node-child * * TODO: This method isn`t very efficient ! * - * Returns NULL if there isnt`t a pos`th loop_node */ + * Returns NULL if there isn`t a pos`th loop_node */ ir_loop *get_loop_son (ir_loop *loop, int pos) { int child_nr = 0, loop_nr = -1; @@ -393,7 +389,7 @@ ir_loop *get_loop_son (ir_loop *loop, int pos) { /* Use EXCLUSIVELY this function to add sons, otherwise the loop->n_sons is invalid! */ -INLINE void +void add_loop_son(ir_loop *loop, ir_loop *son) { loop_element lson; lson.son = son; @@ -412,7 +408,7 @@ int get_loop_n_nodes (ir_loop *loop) { /* Returns the pos`th ir_node-child * * TODO: This method isn`t very efficient ! * - * Returns NULL if there isnt`t a pos`th ir_node */ + * Returns NULL if there isn`t a pos`th ir_node */ ir_node *get_loop_node (ir_loop *loop, int pos) { int child_nr, node_nr = -1; @@ -434,7 +430,7 @@ ir_node *get_loop_node (ir_loop *loop, int pos) { /* Use EXCLUSIVELY this function to add nodes, otherwise the loop->n_nodes is invalid! */ -INLINE void +void add_loop_node(ir_loop *loop, ir_node *n) { loop_element ln; ln.node = n; @@ -454,7 +450,7 @@ int get_loop_n_elements (ir_loop *loop) { Returns the pos`th loop element. This may be a loop_node or a ir_node. The caller of this function has to check the *(loop_element.kind) field for "k_ir_node" or "k_ir_loop" - and then select the apropriate "loop_element.node" or "loop_element.son". + and then select the appropriate "loop_element.node" or "loop_element.son". */ loop_element get_loop_element (ir_loop *loop, int pos) { @@ -499,18 +495,18 @@ void *get_loop_link (const ir_loop *loop) { #endif } -int is_ir_loop(const void *thing) { - return (get_kind(thing) == k_ir_loop); +int (is_ir_loop)(const void *thing) { + return _is_ir_loop(thing); } /* The outermost loop is remarked in the surrounding graph. */ -void set_irg_loop(ir_graph *irg, ir_loop *loop) { - assert(irg); - irg->loop = loop; +void (set_irg_loop)(ir_graph *irg, ir_loop *loop) { + _set_irg_loop(irg, loop); } -ir_loop *get_irg_loop(ir_graph *irg) { - assert(irg); - return irg->loop; + +/* Returns the root loop info (if exists) for an irg. */ +ir_loop *(get_irg_loop)(ir_graph *irg) { + return _get_irg_loop(irg); } @@ -553,14 +549,14 @@ init_ip_scc (void) { } /* Condition for breaking the recursion. */ -static bool is_outermost_Start(ir_node *n) { +static int is_outermost_Start(ir_node *n) { /* Test whether this is the outermost Start node. If so recursion must end. */ if ((get_irn_op(n) == op_Block) && (get_Block_n_cfgpreds(n) == 1) && (get_irn_op(skip_Proj(get_Block_cfgpred(n, 0))) == op_Start) && (get_nodes_block(skip_Proj(get_Block_cfgpred(n, 0))) == n)) { - return true; + return 1; } #if 0 /* @@@ Bad condition: @@ -571,10 +567,10 @@ static bool is_outermost_Start(ir_node *n) { (n == get_irg_start_block(current_ir_graph))) { if ((!get_interprocedural_view()) || (current_ir_graph == outermost_ir_graph)) - return true; + return 1; } #endif - return false; + return 0; } /* When to walk from nodes to blocks. Only for Control flow operations? */ @@ -636,18 +632,18 @@ static void test(ir_node *pred, ir_node *root, ir_node *this) { #endif /* Test for legal loop header: Block, Phi, ... */ -INLINE static bool is_possible_loop_head(ir_node *n) { +static INLINE int is_possible_loop_head(ir_node *n) { ir_op *op = get_irn_op(n); return ((op == op_Block) || - (op == op_Phi) || - ((op == op_Filter) && get_interprocedural_view())); + (op == op_Phi) || + ((op == op_Filter) && get_interprocedural_view())); } -/* Returns true if n is a loop header, i.e., it is a Block, Phi +/* Returns non-zero if n is a loop header, i.e., it is a Block, Phi or Filter node and has predecessors within the loop and out of the loop. @arg root: only needed for assertion. */ -static bool +static int is_head (ir_node *n, ir_node *root) { int i, arity; @@ -655,7 +651,7 @@ is_head (ir_node *n, ir_node *root) /* Test for legal loop header: Block, Phi, ... */ if (!is_possible_loop_head(n)) - return false; + return 0; if (!is_outermost_Start(n)) { arity = get_irn_arity(n); @@ -664,24 +660,26 @@ is_head (ir_node *n, ir_node *root) assert(pred); if (is_backedge(n, i)) continue; if (!irn_is_in_stack(pred)) { - some_outof_loop = 1; + some_outof_loop = 1; } else { - if(get_irn_uplink(pred) < get_irn_uplink(root)) { - DDMN(n); DDMN(pred); DDMN(root); - assert(get_irn_uplink(pred) >= get_irn_uplink(root)); - } - some_in_loop = 1; + if(get_irn_uplink(pred) < get_irn_uplink(root)) { + DDMN(n); DDMN(pred); DDMN(root); + assert(get_irn_uplink(pred) >= get_irn_uplink(root)); + } + some_in_loop = 1; } } } return some_outof_loop && some_in_loop; } -/* Returns true if n is possible loop head of an endless loop. - I.e., it is a Block, Phi or Filter node and has only predecessors - within the loop. - @arg root: only needed for assertion. */ -static bool +/** + * Returns non-zero if n is possible loop head of an endless loop. + * I.e., it is a Block, Phi or Filter node and has only predecessors + * within the loop. + * @param root: only needed for assertion. + */ +static int is_endless_head (ir_node *n, ir_node *root) { int i, arity; @@ -689,7 +687,7 @@ is_endless_head (ir_node *n, ir_node *root) /* Test for legal loop header: Block, Phi, ... */ if (!is_possible_loop_head(n)) - return false; + return 0; if (!is_outermost_Start(n)) { arity = get_irn_arity(n); @@ -698,13 +696,13 @@ is_endless_head (ir_node *n, ir_node *root) assert(pred); if (is_backedge(n, i)) { continue; } if (!irn_is_in_stack(pred)) { - some_outof_loop = 1; //printf(" some out of loop "); + some_outof_loop = 1; //printf(" some out of loop "); } else { - if(get_irn_uplink(pred) < get_irn_uplink(root)) { - DDMN(pred); DDMN(root); - assert(get_irn_uplink(pred) >= get_irn_uplink(root)); - } - some_in_loop = 1; + if(get_irn_uplink(pred) < get_irn_uplink(root)) { + DDMN(pred); DDMN(root); + assert(get_irn_uplink(pred) >= get_irn_uplink(root)); + } + some_in_loop = 1; } } } @@ -725,8 +723,8 @@ smallest_dfn_pred (ir_node *n, int limit) assert(pred); if (is_backedge(n, i) || !irn_is_in_stack(pred)) continue; if (get_irn_dfn(pred) >= limit && (min == -1 || get_irn_dfn(pred) < min)) { - index = i; - min = get_irn_dfn(pred); + index = i; + min = get_irn_dfn(pred); } } } @@ -745,8 +743,8 @@ largest_dfn_pred (ir_node *n) ir_node *pred = get_irn_n(n, i); if (is_backedge (n, i) || !irn_is_in_stack(pred)) continue; if (get_irn_dfn(pred) > max) { - index = i; - max = get_irn_dfn(pred); + index = i; + max = get_irn_dfn(pred); } } } @@ -782,21 +780,21 @@ find_tail (ir_node *n) { m = stack[i]; if (is_head (m, n)) { - res_index = smallest_dfn_pred (m, get_irn_dfn(m) + 1); - if (res_index == -2) /* no smallest dfn pred found. */ - res_index = largest_dfn_pred (m); - - if ((m == n) && (res_index == -2)) { /* dont walk past loop head. */ - i = -1; - } - break; + res_index = smallest_dfn_pred (m, get_irn_dfn(m) + 1); + if (res_index == -2) /* no smallest dfn pred found. */ + res_index = largest_dfn_pred (m); + + if ((m == n) && (res_index == -2)) { /* dont walk past loop head. */ + i = -1; + } + break; } /* We should not walk past our selves on the stack: The upcoming nodes - are not in this loop. We assume a loop not reachable from Start. */ + are not in this loop. We assume a loop not reachable from Start. */ if (m == n) { - i = -1; - break; + i = -1; + break; } } @@ -804,14 +802,14 @@ find_tail (ir_node *n) { if (i < 0) { /* A dead loop not reachable from Start. */ for (i = tos-2; i >= 0; --i) { - m = stack[i]; - if (is_endless_head (m, n)) { - res_index = smallest_dfn_pred (m, get_irn_dfn(m) + 1); - if (res_index == -2) /* no smallest dfn pred found. */ - res_index = largest_dfn_pred (m); - break; - } - if (m == n) { break; } /* It's not an unreachable loop, either. */ + m = stack[i]; + if (is_endless_head (m, n)) { + res_index = smallest_dfn_pred (m, get_irn_dfn(m) + 1); + if (res_index == -2) /* no smallest dfn pred found. */ + res_index = largest_dfn_pred (m); + break; + } + if (m == n) { break; } /* It's not an unreachable loop, either. */ } //assert(0 && "no head found on stack"); } @@ -837,7 +835,7 @@ find_tail (ir_node *n) { #if EXPERIMENTAL_LOOP_TREE /* ---------------------------------------------------------------- - AS: This is experimantal code to build loop trees suitable for + AS: This is experimental code to build loop trees suitable for the heap analysis. Does not work correctly right now... :-( @@ -854,28 +852,28 @@ int search_endproj_in_stack(ir_node *start_block) int i, j; assert(is_Block(start_block)); for(i = tos - 1; i >= 0; --i) + { + DDMN(stack[i]); + if(get_irn_op(stack[i]) == op_Proj && get_irn_mode(stack[i]) == mode_X && + get_irn_op(get_irn_n(stack[i], 0)) == op_EndReg) { - DDMN(stack[i]); - if(get_irn_op(stack[i]) == op_Proj && get_irn_mode(stack[i]) == mode_X && - get_irn_op(get_irn_n(stack[i], 0)) == op_EndReg) - { - printf("FOUND PROJ!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); - ir_node *end_projx = stack[i]; - - int arity = get_irn_arity(start_block); - for(j = 0; j < arity; j++) - { - ir_node *begin_projx = get_Block_cfgpred(get_irg_start_block(get_irn_irg(end_projx)), - get_Proj_proj(end_projx)); - DDMN(begin_projx); - if(get_irn_n(start_block, j) == begin_projx) - { - printf("FOUND IT!!!!!!!!!!!!!!!!!!\n"); - return(j); - } - } - } + printf("FOUND PROJ!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + ir_node *end_projx = stack[i]; + + int arity = get_irn_arity(start_block); + for(j = 0; j < arity; j++) + { + ir_node *begin_projx = get_Block_cfgpred(get_irg_start_block(get_irn_irg(end_projx)), + get_Proj_proj(end_projx)); + DDMN(begin_projx); + if(get_irn_n(start_block, j) == begin_projx) + { + printf("FOUND IT!!!!!!!!!!!!!!!!!!\n"); + return(j); + } + } } + } return(-1); } @@ -889,7 +887,7 @@ void link_to_reg_end (ir_node *n, void *env) { /* Reg End Projx -> Find the CallBegin Projx and hash it */ ir_node *end_projx = n; ir_node *begin_projx = get_Block_cfgpred(get_irg_start_block(get_irn_irg(end_projx)), - get_Proj_proj(end_projx)); + get_Proj_proj(end_projx)); printf("Linked the following ProjxNodes:\n"); DDMN(begin_projx); DDMN(end_projx); @@ -911,7 +909,7 @@ ir_node *get_projx_link(ir_node *cb_projx) #endif -INLINE static int +static INLINE int is_outermost_loop(ir_loop *l) { return l == get_loop_outer_loop(l); } @@ -921,7 +919,6 @@ is_outermost_loop(ir_loop *l) { * The core algorithm. * *-----------------------------------------------------------*/ - static void scc (ir_node *n) { int i; if (irn_visited(n)) return; @@ -948,10 +945,10 @@ static void scc (ir_node *n) { /* if ((!m) || (get_irn_op(m) == op_Unknown)) continue; */ scc (m); if (irn_is_in_stack(m)) { - /* Uplink of m is smaller if n->m is a backedge. - Propagate the uplink to mark the loop. */ - if (get_irn_uplink(m) < get_irn_uplink(n)) - set_irn_uplink(n, get_irn_uplink(m)); + /* Uplink of m is smaller if n->m is a backedge. + Propagate the uplink to mark the loop. */ + if (get_irn_uplink(m) < get_irn_uplink(n)) + set_irn_uplink(n, get_irn_uplink(m)); } } } @@ -971,9 +968,9 @@ static void scc (ir_node *n) { ir_node *tail = find_tail(n); if (tail) { /* We have a loop, that is no straight line code, - because we found a loop head! - Next actions: Open a new loop on the loop tree and - try to find inner loops */ + because we found a loop head! + Next actions: Open a new loop on the loop tree and + try to find inner loops */ #if NO_LOOPS_WITHOUT_HEAD /* This is an adaption of the algorithm from fiasco / optscc to @@ -989,11 +986,11 @@ static void scc (ir_node *n) { ir_loop *l; int close; if ((get_loop_n_elements(current_loop) > 0) || (is_outermost_loop(current_loop))) { - l = new_loop(); - close = 1; + l = new_loop(); + close = 1; } else { - l = current_loop; - close = 0; + l = current_loop; + close = 0; } #else ir_loop *l = new_loop(); @@ -1003,21 +1000,21 @@ static void scc (ir_node *n) { pop_scc_unmark_visit (n); /* The current backedge has been marked, that is temporarily eliminated, - by find tail. Start the scc algorithm - anew on the subgraph thats left (the current loop without the backedge) - in order to find more inner loops. */ + by find tail. Start the scc algorithm + anew on the subgraph that is left (the current loop without the backedge) + in order to find more inner loops. */ scc (tail); assert (irn_visited(n)); #if NO_LOOPS_WITHOUT_HEAD if (close) #endif - close_loop(l); + close_loop(l); } else - { - /* No loop head was found, that is we have straightline code. - Pop all nodes from the stack to the current loop. */ + { + /* No loop head was found, that is we have straightline code. + Pop all nodes from the stack to the current loop. */ pop_scc_to_loop(n); } } @@ -1049,10 +1046,10 @@ static void my_scc (ir_node *n) { /* if ((!m) || (get_irn_op(m) == op_Unknown)) continue; */ my_scc (m); if (irn_is_in_stack(m)) { - /* Uplink of m is smaller if n->m is a backedge. - Propagate the uplink to mark the loop. */ - if (get_irn_uplink(m) < get_irn_uplink(n)) - set_irn_uplink(n, get_irn_uplink(m)); + /* Uplink of m is smaller if n->m is a backedge. + Propagate the uplink to mark the loop. */ + if (get_irn_uplink(m) < get_irn_uplink(n)) + set_irn_uplink(n, get_irn_uplink(m)); } } } @@ -1072,9 +1069,9 @@ static void my_scc (ir_node *n) { ir_node *tail = find_tail(n); if (tail) { /* We have a loop, that is no straight line code, - because we found a loop head! - Next actions: Open a new loop on the loop tree and - try to find inner loops */ + because we found a loop head! + Next actions: Open a new loop on the loop tree and + try to find inner loops */ #if NO_LOOPS_WITHOUT_HEAD /* This is an adaption of the algorithm from fiasco / optscc to @@ -1087,11 +1084,11 @@ static void my_scc (ir_node *n) { ir_loop *l; int close; if ((get_loop_n_elements(current_loop) > 0) || (is_outermost_loop(current_loop))) { - l = new_loop(); - close = 1; + l = new_loop(); + close = 1; } else { - l = current_loop; - close = 0; + l = current_loop; + close = 0; } #else ir_loop *l = new_loop(); @@ -1101,21 +1098,21 @@ static void my_scc (ir_node *n) { pop_scc_unmark_visit (n); /* The current backedge has been marked, that is temporarily eliminated, - by find tail. Start the scc algorithm - anew on the subgraph thats left (the current loop without the backedge) - in order to find more inner loops. */ + by find tail. Start the scc algorithm + anew on the subgraph that is left (the current loop without the backedge) + in order to find more inner loops. */ my_scc (tail); assert (irn_visited(n)); #if NO_LOOPS_WITHOUT_HEAD if (close) #endif - close_loop(l); + close_loop(l); } else - { - /* No loop head was found, that is we have straightline code. - Pop all nodes from the stack to the current loop. */ + { + /* No loop head was found, that is we have straightline code. + Pop all nodes from the stack to the current loop. */ pop_scc_to_loop(n); } } @@ -1177,7 +1174,7 @@ int construct_ip_backedges (void) { current_loop = NULL; new_loop(); /* sets current_loop */ - set_interprocedural_view(true); + set_interprocedural_view(1); inc_max_irg_visited(); for (i = 0; i < get_irp_n_irgs(); i++) @@ -1246,7 +1243,7 @@ void my_construct_ip_backedges (void) { current_loop = NULL; new_loop(); /* sets current_loop */ - set_interprocedural_view(true); + set_interprocedural_view(1); inc_max_irg_visited(); for (i = 0; i < get_irp_n_irgs(); i++) @@ -1305,9 +1302,9 @@ static void reset_backedges(ir_node *n) { if (is_possible_loop_head(n)) { int rem = get_interprocedural_view(); - set_interprocedural_view(true); + set_interprocedural_view(1); clear_backedges(n); - set_interprocedural_view(true); + set_interprocedural_view(1); clear_backedges(n); set_interprocedural_view(rem); } @@ -1350,7 +1347,7 @@ void free_loop_information(ir_graph *irg) { void free_all_loop_information (void) { int i; int rem = get_interprocedural_view(); - set_interprocedural_view(true); /* To visit all filter nodes */ + set_interprocedural_view(1); /* To visit all filter nodes */ for (i = 0; i < get_irp_n_irgs(); i++) { free_loop_information(get_irp_irg(i)); } @@ -1439,17 +1436,17 @@ void find_strange_loop_nodes(ir_loop *l) { int is_loop_variant(ir_loop *l, ir_loop *b) { int i, n_elems; - if (l == b) return true; + if (l == b) return 1; n_elems = get_loop_n_elements(l); for (i = 0; i < n_elems; ++i) { loop_element e = get_loop_element(l, i); if (is_ir_loop(e.kind)) if (is_loop_variant(e.son, b)) - return true; + return 1; } - return false; + return 0; } /* Test whether a value is loop invariant. @@ -1458,8 +1455,8 @@ int is_loop_variant(ir_loop *l, ir_loop *b) { * @param block A block node. We pass the block, not the loop as we must * start off with a block loop to find all proper uses. * - * Returns true, if the node n is not changed in the loop block - * belongs to or in inner loops of this block. */ + * Returns non-zero, if the node n is not changed in the loop block + * belongs to or in inner loops of this blocks loop. */ int is_loop_invariant(ir_node *n, ir_node *block) { ir_loop *l = get_irn_loop(block); ir_node *b = (is_Block(n)) ? n : get_nodes_block(n);