X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fircgopt.c;h=3bded6149acabe68821a0a6f5b83b20a213c1ed1;hb=ce6161a7e42a48f7422b7babcc64d8ace18e2687;hp=27940ab15ab04584cc9f8d8ce2ac7807a206a77f;hpb=ddfcdcb1227bd6fb6720f8485dc62995f7bfd98f;p=libfirm diff --git a/ir/opt/ircgopt.c b/ir/opt/ircgopt.c index 27940ab15..3bded6149 100644 --- a/ir/opt/ircgopt.c +++ b/ir/opt/ircgopt.c @@ -27,7 +27,7 @@ /* * Entfernen von nicht erreichbaren (aufrufbaren) Methoden. Die Menge - * der nicht erreichbaren Methoden wird aus der Abschätzung der + * der nicht erreichbaren Methoden wird aus der Abschätzung der * Aufrufrelation bestimmt. */ #include "config.h" @@ -43,14 +43,16 @@ #include "ircons.h" #include "cgana.h" #include "irtools.h" +#include "irpass.h" DEBUG_ONLY(static firm_dbg_module_t *dbg); /** * Walker: adds Call operations to a head's link list. */ -static void collect_call(ir_node *node, void *env) { - ir_node *head = env; +static void collect_call(ir_node *node, void *env) +{ + ir_node *head = (ir_node*)env; if (is_Call(node)) { set_irn_link(node, get_irn_link(head)); @@ -58,27 +60,9 @@ static void collect_call(ir_node *node, void *env) { } } -/** - * Type walker, set the peculiarity of entities which graphs - * gets removed to peculiarity_description. - */ -static void make_entity_to_description(type_or_ent tore, void *env) { - if (is_entity(tore.ent)) { - ir_entity *ent = tore.ent; - - if ((is_Method_type(get_entity_type(ent))) && - (get_entity_peculiarity(ent) != peculiarity_description) && - (get_entity_visibility(ent) != visibility_external_allocated) ) { - ir_entity *impl = get_SymConst_entity(get_atomic_ent_value(ent)); - if (get_entity_link(impl) != env) { - set_entity_peculiarity(ent, peculiarity_description); - } - } - } -} - /* garbage collect methods: mark and remove */ -void gc_irgs(int n_keep, ir_entity ** keep_arr) { +void gc_irgs(int n_keep, ir_entity ** keep_arr) +{ void * MARK = &MARK; /* @@@ gefaehrlich!!! Aber wir markieren hoechstens zu viele ... */ int i; @@ -97,59 +81,57 @@ void gc_irgs(int n_keep, ir_entity ** keep_arr) { for (i = 0; i < n_keep; ++i) { marked[i] = keep_arr[i]; set_entity_link(marked[i], MARK); - DB((dbg, LEVEL_1, " method %+F kept alive.\n", marked[i])); + DB((dbg, LEVEL_1, " method %+F kept alive.\n", marked[i])); } for (i = 0; i < ARR_LEN(marked); ++i) { - /* check for extern methods, these don't have an IRG */ - if (get_entity_visibility(marked[i]) != visibility_external_allocated) { - ir_graph *irg = get_entity_irg(marked[i]); - ir_node *node = get_irg_end(irg); - - /* collect calls */ - ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK); - irg_walk_graph(irg, firm_clear_link, collect_call, node); - - /* iterate calls */ - for (node = get_irn_link(node); node; node = get_irn_link(node)) { - int i; - assert(is_Call(node)); - - for (i = get_Call_n_callees(node) - 1; i >= 0; --i) { - ir_entity *ent = get_Call_callee(node, i); - - if (get_entity_irg(ent) && get_entity_link(ent) != MARK) { - set_entity_link(ent, MARK); - ARR_APP1(ir_entity *, marked, ent); - - DB((dbg, LEVEL_1, " method %+F can be called from Call %+F: kept alive.\n", - ent, node)); - } + ir_graph *irg = get_entity_irg(marked[i]); + ir_node *node; + + if (irg == NULL) + continue; + + node = get_irg_end(irg); + + /* collect calls */ + ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK); + irg_walk_graph(irg, firm_clear_link, collect_call, node); + + /* iterate calls */ + for (node = (ir_node*)get_irn_link(node); node != NULL; + node = (ir_node*)get_irn_link(node)) { + int i; + assert(is_Call(node)); + + for (i = get_Call_n_callees(node) - 1; i >= 0; --i) { + ir_entity *ent = get_Call_callee(node, i); + + if (get_entity_irg(ent) && get_entity_link(ent) != MARK) { + set_entity_link(ent, MARK); + ARR_APP1(ir_entity *, marked, ent); + + DB((dbg, LEVEL_1, " method %+F can be called from Call %+F: kept alive.\n", + ent, node)); } } - ir_free_resources(irg, IR_RESOURCE_IRN_LINK); } + ir_free_resources(irg, IR_RESOURCE_IRN_LINK); } DEL_ARR_F(marked); } /* clean */ - type_walk(make_entity_to_description, NULL, MARK); for (i = get_irp_n_irgs() - 1; i >= 0; --i) { ir_graph *irg = get_irp_irg(i); ir_entity *ent = get_irg_entity(irg); - /* Removing any graph invalidates all interprocedural loop trees. */ - if (get_irg_loopinfo_state(irg) == loopinfo_ip_consistent || - get_irg_loopinfo_state(irg) == loopinfo_ip_inconsistent) { - free_loop_information(irg); - } - if ((get_entity_visibility(ent) == visibility_local) && (get_entity_link(ent) != MARK)) { - DB((dbg, LEVEL_1, " freeing method %+F\n", ent)); - remove_irp_irg(irg); - set_entity_peculiarity(ent, peculiarity_description); - } - set_entity_link(ent, NULL); + if (get_entity_link(ent) == MARK) + continue; + + DB((dbg, LEVEL_1, " freeing method %+F\n", ent)); + remove_irp_irg(irg); + + free_entity(ent); } }