From a3143f206440f9c1ea163b61ae1b796d5b0bc048 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andreas=20Sch=C3=B6sser?= Date: Wed, 14 Jan 2004 17:45:26 +0000 Subject: [PATCH] Wrote dumper for standalone loop trees [r2294] --- ir/ana/irscc.c | 27 ++++++++++++----- ir/ir/irdump.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++- ir/ir/irdump.h | 9 ++++++ 3 files changed, 109 insertions(+), 9 deletions(-) diff --git a/ir/ana/irscc.c b/ir/ana/irscc.c index 4de5d139b..4fb7adafb 100644 --- a/ir/ana/irscc.c +++ b/ir/ana/irscc.c @@ -209,6 +209,7 @@ static INLINE void pop_scc_to_loop (ir_node *n) { ir_node *m; + int i = 0; /*for (;;) {*/ do @@ -218,8 +219,12 @@ pop_scc_to_loop (ir_node *n) set_irn_dfn(m, loop_node_cnt); add_loop_node(current_loop, m); set_irn_loop(m, current_loop); + i++; /* if (m==n) break;*/ } while(m != n); + + if(i > 1) + printf("Mehr als eine Iteration!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); } /* GL ??? my last son is my grandson??? Removes loops with no @@ -630,12 +635,13 @@ INLINE static bool is_possible_loop_head(ir_node *n) { /* Returns true 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. */ + of the loop. + @arg root: only needed for assertion. */ static bool is_head (ir_node *n, ir_node *root) { int i; - int some_outof_loop = 0, some_in_loop = 0; + int some_outof_loop = 0, some_in_loop = 0; /* Test for legal loop header: Block, Phi, ... */ if (!is_possible_loop_head(n)) @@ -669,8 +675,7 @@ smallest_dfn_pred (ir_node *n, int limit) ir_node *pred = get_irn_n(n, i); 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)) { + if (get_irn_dfn(pred) >= limit && (min == -1 || get_irn_dfn(pred) < min)) { index = i; min = get_irn_dfn(pred); } @@ -761,6 +766,10 @@ static void scc (ir_node *n) { push(n); + /* AS: get_start_index might return -1 for Control Flow Nodes, and thus a negative + array index would be passed to is_backedge(). But CFG Nodes dont't have a backedge array, + so is_backedge does not access array[-1] but correctly returns false! */ + if (!is_outermost_Start(n)) { for (i = get_start_index(n); i < get_irn_arity(n); i++) { ir_node *m; @@ -779,11 +788,13 @@ static void scc (ir_node *n) { } } } + if (get_irn_dfn(n) == get_irn_uplink(n)) { - /* This condition holds for the node with the incoming backedge. */ + /* This condition holds for the node with the incoming backedge. + AS: That is: For the loop head. */ ir_node *tail = find_tail(n); if (tail) { - /* We found a new loop! */ + /* We found a new inner loop! */ ir_loop *l = new_loop(); /* Remove the loop from the stack ... */ @@ -797,9 +808,9 @@ static void scc (ir_node *n) { assert (irn_visited(n)); close_loop(l); - - /* current_loop = l; AS: This is done close_loop */ } else { + /* AS: No inner loop was found. Pop all nodes from the stack + to the current loop. */ pop_scc_to_loop(n); } } diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index 2805c5db8..3ec2f5687 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -42,7 +42,7 @@ # include "exc.h" -/*define HEAPANAL */ +#define HEAPANAL #ifdef HEAPANAL void dump_chi_term(FILE *FL, ir_node *n); void dump_state(FILE *FL, ir_node *n); @@ -1756,3 +1756,83 @@ void dump_all_ir_graphs (dump_graph_func *dmp_grph) { dmp_grph(get_irp_irg(i)); } } + + +/********************************************************************************** + * Dumps a stand alone loop graph with firm nodes which belong to one loop nodes * + * packed together in one subgraph * + **********************************************************************************/ + + + +void dump_loops_standalone (ir_loop *loop) { + int i, loop_node_started = 0, son_number = 0, chunk_nr = 0; + loop_element le; + + /* Start a new loop node */ + fprintf (F, "node: {title: \"%p\" color: yellow label: \"loop %d, %d sons, %d nodes\" }\n", + (void*)loop, get_loop_depth(loop), get_loop_n_sons(loop), get_loop_n_nodes(loop)); + + for(i = 0; i < get_loop_n_elements(loop); i++) + { + le = get_loop_element(loop, i); + + ir_loop *son = le.son; + if (get_kind(son) == k_ir_loop) + { + /* We are a loop son -> Recurse */ + + if(loop_node_started) /* Close the "firm-nodes" node first if we started one. */ + { + fprintf(F, "\" }"); + loop_node_started = 0; + } + dump_loops_standalone(son); + dump_loop_son_edge(loop, son_number++); + } + else + { + /* We are a loop node -> Collect firm nodes */ + + ir_node *n = le.node; + + if(!loop_node_started) + { + /* Start a new node which contains all firm nodes of the current loop */ + + fprintf (F, "edge: {sourcename: \"%p\" targetname: \"%p-%d-nodes\" color: darkgreen}\n", + (void *)loop, (void *)loop, chunk_nr); + + fprintf (F, "node: { title: \"%p-%d-nodes\" color: red label: \"", loop, chunk_nr++); + loop_node_started = 1; + } + + dump_node_opcode(n); + dump_node_mode (n); + dump_node_typeinfo(n); + fprintf (F, " "); + dump_node_nodeattr(n); + fprintf (F, " %ld\n", get_irn_node_nr(n)); + } + } + + if(loop_node_started) + { + fprintf(F, "\" }"); + loop_node_started = 0; + } +} + +void dump_standalone_loop_tree(ir_graph *irg) +{ + ir_graph *rem = current_ir_graph; + current_ir_graph = irg; + + vcg_open(irg, "-standalone-looptree", ""); + + if (get_irg_loop(irg)) dump_loops_standalone(get_irg_loop(irg)); + + vcg_close(); + + current_ir_graph = rem; +} diff --git a/ir/ir/irdump.h b/ir/ir/irdump.h index f5341b1c7..0a2df6460 100644 --- a/ir/ir/irdump.h +++ b/ir/ir/irdump.h @@ -297,4 +297,13 @@ void dump_analysed_type_info(bool b); * vcg graphs -- these will differ in the pointer values! */ void dump_pointer_values_to_info(bool b); + + +/** + * Dump a standalone loop tree, which contains the loop nodes and the firm nodes + * belonging to one loop packed together in one subgraph. + */ + +void dump_standalone_loop_tree(ir_graph *irg); + # endif /* _IRDUMP_H_ */ -- 2.20.1