From ddc413b98d1065eb05bedb31b32bddb78cb6c508 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Mon, 10 Sep 2001 09:59:32 +0000 Subject: [PATCH] CBugfix: dead node elimination did not replace the hash table for cse VS: ---------------------------------------------------------------------- [r249] --- Changes | 11 ++++++++++- ir/ir/irgopt.c | 41 ++++++++++++++++++++++++++++++++++------- ir/ir/irgraph.c | 6 +++--- ir/ir/iropt.c | 5 +++++ ir/ir/iropt_t.h | 1 + 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/Changes b/Changes index 34baf009e..9492fac71 100644 --- a/Changes +++ b/Changes @@ -1,10 +1,19 @@ + + 10.9.2001 Goetz + Bugfix: dead node elimination did not replace the hash table + for cse. + + 29.8.2001 Goetz + Added routine remove_irp_irg. + Changed comment to free_ir_graph. + 29.8.2001 Goetz Added routine to free irgraphs. 17.7.2001 Goetz Improved add routines to sub, supertype in type.c - 12.r7.2001 Goetz + 12.7.2001 Goetz Added implementation of overwrites stuff. 11.7.2001 Goetz diff --git a/ir/ir/irgopt.c b/ir/ir/irgopt.c index 751ad2aa7..dab16e209 100644 --- a/ir/ir/irgopt.c +++ b/ir/ir/irgopt.c @@ -24,6 +24,14 @@ # include "pset.h" pset *new_identities (void); void del_identities (pset *value_table); +void add_identity (pset *value_table, ir_node *node); + + +/* To fill the hash table */ +void +add_identity (pset *value_table, ir_node *n) { + /* identify_remember (value_table, n);*/ +} /********************************************************************/ /* apply optimizations of iropt to all nodes. */ @@ -79,9 +87,10 @@ get_new_node (ir_node * n) /* We use the block_visited flag to mark that we have computed the number of useful predecessors for this block. - Further we encode the new arity in this flag. Remembering the arity is - useful, as it saves a lot of pointer accesses. This function is called - for all Phi and Block nodes in a Block. */ + Further we encode the new arity in this flag in the old blocks. + Remembering the arity is useful, as it saves a lot of pointer + accesses. This function is called for all Phi and Block nodes + in a Block. */ inline int compute_new_arity(ir_node *b) { int i, res; @@ -160,9 +169,16 @@ copy_preds (ir_node *n, void *env) { /* Local optimization could not merge two subsequent blocks if in array contained Bads. Now it's possible, but don't do it for the end block! */ - if (n != current_ir_graph->end_block) on = optimize_in_place(nn); + /* GL: this is inefficient!! + if (n != current_ir_graph->end_block) on = optimize_in_place(nn); else on = nn; if (nn != on) exchange(nn, on); + better: */ + if (n != current_ir_graph->end_block) { + on = optimize_in_place(nn); + if (nn != on) exchange(nn, on); + nn = on; /* For cse ... */ + } } else if (get_irn_opcode(n) == iro_Phi) { /* Don't copy node if corresponding predecessor in block is Bad. The Block itself should not be Bad. */ @@ -177,11 +193,13 @@ copy_preds (ir_node *n, void *env) { /* Compacting the Phi's ins might generate Phis with only one predecessor. */ if (get_irn_arity(n) == 1) - exchange(n, get_irn_n(n, 0)); + exchange(n, get_irn_n(n, 0)); } else { for (i = -1; i < get_irn_arity(n); i++) set_irn_n (nn, i, get_new_node(get_irn_n(n, i))); } + /* Now the new node is complete. We can add it to the hash table for cse. */ + add_identity (current_ir_graph->value_table, nn); } /* Copies the graph reachable from current_ir_graph->end to the obstack @@ -191,7 +209,7 @@ copy_preds (ir_node *n, void *env) { void copy_graph () { /* Not all nodes remembered in current_ir_graph might be reachable - from the end node. Assure their link is set to NULL so that + from the end node. Assure their link is set to NULL, so that we can test whether new nodes have been computed. */ set_irn_link(get_irg_frame (current_ir_graph), NULL); set_irn_link(get_irg_globals(current_ir_graph), NULL); @@ -225,7 +243,12 @@ copy_graph () { set_irg_bad(current_ir_graph, get_new_node(get_irg_bad(current_ir_graph))); } - +/* Copies all reachable nodes to a new obstack. Removes bad inputs + from block nodes and the corresponding inputs from Phi nodes. + Merges single exit blocks with single entry blocks and removes + 1-input Phis. + Adds all new nodes to a new hash table for cse. Does not + perform cse, so the hash table might contain common subexpressions. */ /* Amroq call this emigrate() */ void dead_node_elimination(ir_graph *irg) { @@ -248,6 +271,10 @@ dead_node_elimination(ir_graph *irg) { current_ir_graph->obst = rebirth_obst; obstack_init (current_ir_graph->obst); + /* We also need a new hash table for cse */ + del_identities (irg->value_table); + irg->value_table = new_identities (); + /* Copy the graph from the old to the new obstack */ copy_graph(); diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index f29aaf780..39de26f6c 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -49,9 +49,9 @@ new_ir_graph (entity *ent, int n_loc) /** Internal information for graph construction either held in the graph or *** initialized for each graph. **/ res->n_loc = n_loc + 1; /* number of local variables that are never - dereferenced in this graph plus one for - the store. This is not the number of parameters - to the procedure! */ + dereferenced in this graph plus one for + the store. This is not the number of parameters + to the procedure! */ res->visited = 0; /* visited flag, for the ir walker */ res->block_visited=0; /* visited flag, for the 'block'-walker */ diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 5aa348dad..e06b9b084 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -855,6 +855,11 @@ del_identities (pset *value_table) del_pset (value_table); } +void +add_identities (pset *value_table, ir_node *node) { + identify_remember (value_table, node); +} + /* Return the canonical node computing the same value as n. Looks up the node in a hash table. */ static inline ir_node * diff --git a/ir/ir/iropt_t.h b/ir/ir/iropt_t.h index 68e479554..fa4858361 100644 --- a/ir/ir/iropt_t.h +++ b/ir/ir/iropt_t.h @@ -14,5 +14,6 @@ pset *new_identities (void); void del_identities (pset *value_table); +void add_identity (pset *value_table, ir_node *node); # endif /* _IROPT_T_H_ */ -- 2.20.1