X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Fircgopt.c;h=6ce2e42d62f72c5a9624e33a77e3de91d1a2742e;hb=f9d25133f86594ca2b1f33fb0b41a591ecc9b914;hp=cf1bd514ec04d793ab9c5457fafd97ca8c5bd1d9;hpb=1ef847a519fd20484e3a5d3f6f51ed5bbc8d69cc;p=libfirm diff --git a/ir/ir/ircgopt.c b/ir/ir/ircgopt.c index cf1bd514e..6ce2e42d6 100644 --- a/ir/ir/ircgopt.c +++ b/ir/ir/ircgopt.c @@ -16,7 +16,7 @@ * Aufrufrelation bestimmt. */ #ifdef HAVE_CONFIG_H -# include +# include "config.h" #endif #include "ircgopt.h" @@ -26,11 +26,9 @@ #include "irgwalk.h" #include "irloop_t.h" #include "irflag_t.h" - -static void clear_link(ir_node * node, void * env) { - set_irn_link(node, NULL); -} - +#include "ircons.h" +#include "typewalk.h" +#include "irtools.h" /* Call-Operationen an die "link"-Liste von "call_head" anhängen. */ static void collect_call(ir_node * node, ir_node * head) { @@ -40,21 +38,37 @@ static void collect_call(ir_node * node, ir_node * head) { } } +static void make_entity_to_description(type_or_ent *tore, void *env) { + if (get_kind(tore) == k_entity) { + entity *ent = (entity *)tore; + if ((is_Method_type(get_entity_type(ent))) && + (get_entity_peculiarity(ent) != peculiarity_description) && + (get_entity_visibility(ent) != visibility_external_allocated) ) { + 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, entity ** keep_arr) { - void * MARK = &MARK; + void * MARK = &MARK; /* @@@ gefaehrlich!!! Aber wir markieren hoechstens zu viele ... */ int i; if (!get_opt_dead_method_elimination()) return; - /* mark */ + /* Mark entities that are alive. */ if (n_keep > 0) { entity ** marked = NEW_ARR_F(entity *, n_keep); for (i = 0; i < n_keep; ++i) { marked[i] = keep_arr[i]; set_entity_link(marked[i], MARK); + if (get_opt_dead_method_elimination_verbose() && get_firm_verbosity() > 2) { + printf("dead method elimination: method %s kept alive.\n", get_entity_ld_name(marked[i])); + } } for (i = 0; i < ARR_LEN(marked); ++i) { /* check for extern methods, these don't have an IRG */ @@ -62,16 +76,20 @@ void gc_irgs(int n_keep, entity ** keep_arr) { ir_graph * irg = get_entity_irg(marked[i]); ir_node * node = get_irg_end(irg); /* collect calls */ - irg_walk_graph(irg, clear_link, (irg_walk_func *) collect_call, node); + irg_walk_graph(irg, firm_clear_link, (irg_walk_func *) collect_call, node); /* iterate calls */ for (node = get_irn_link(node); node; node = get_irn_link(node)) { int i; assert(get_irn_op(node) == op_Call); for (i = get_Call_n_callees(node) - 1; i >= 0; --i) { entity * ent = get_Call_callee(node, i); - if (ent && get_entity_irg(ent) && get_entity_link(ent) != MARK) { + if (get_entity_irg(ent) && get_entity_link(ent) != MARK) { set_entity_link(ent, MARK); ARR_APP1(entity *, marked, ent); + if (get_opt_dead_method_elimination_verbose() && get_firm_verbosity() > 2) { + printf("dead method elimination: method %s can be called from Call %ld: kept alive.\n", + get_entity_ld_name(ent), get_irn_node_nr(node)); + } } } } @@ -81,18 +99,19 @@ void gc_irgs(int n_keep, entity ** keep_arr) { } /* 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); - entity * ent = get_irg_ent(irg); + 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_link(ent) != MARK) { + if ((get_entity_visibility(ent) == visibility_local) && (get_entity_link(ent) != MARK)) { remove_irp_irg(irg); set_entity_peculiarity(ent, peculiarity_description); - if (get_opt_dead_method_elimination_verbose()) { + if (get_opt_dead_method_elimination_verbose() && get_firm_verbosity() > 1) { printf("dead method elimination: freeing method %s\n", get_entity_ld_name(ent)); } }