X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fircgopt.c;h=2b28f563f32aed59c300154fd8dc9eceaf3eb928;hb=e669cdc1b57e7226b656c1c18816f71c3dc89347;hp=e962a8c04fc8993f238ea9391628ad4675c4a0d5;hpb=e30e5834fd8c1c3a7d28fc66e99b91a84993bde8;p=libfirm diff --git a/ir/opt/ircgopt.c b/ir/opt/ircgopt.c index e962a8c04..2b28f563f 100644 --- a/ir/opt/ircgopt.c +++ b/ir/opt/ircgopt.c @@ -30,9 +30,7 @@ * der nicht erreichbaren Methoden wird aus der Abschätzung der * Aufrufrelation bestimmt. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" #include "ircgopt.h" @@ -43,7 +41,9 @@ #include "irloop_t.h" #include "irflag_t.h" #include "ircons.h" +#include "cgana.h" #include "irtools.h" +#include "irpass.h" DEBUG_ONLY(static firm_dbg_module_t *dbg); @@ -145,11 +145,35 @@ void gc_irgs(int n_keep, ir_entity ** keep_arr) { free_loop_information(irg); } if ((get_entity_visibility(ent) == visibility_local) && (get_entity_link(ent) != MARK)) { - remove_irp_irg(irg); - set_entity_peculiarity(ent, peculiarity_description); DB((dbg, LEVEL_1, " freeing method %+F\n", ent)); + remove_irp_irg(irg); + set_entity_peculiarity(ent, peculiarity_description); } set_entity_link(ent, NULL); } } + +/** + * Wrapper for running gc_irgs() as an ir_prog pass. + */ +static void pass_wrapper(void) +{ + ir_entity **keep_methods; + int arr_len; + + /* Analysis that finds the free methods, + i.e. methods that are dereferenced. + Optimizes polymorphic calls :-). */ + cgana(&arr_len, &keep_methods); + + /* Remove methods that are never called. */ + gc_irgs(arr_len, keep_methods); + + free(keep_methods); +} + +ir_prog_pass_t *gc_irgs_pass(const char *name) +{ + return def_prog_pass(name ? name : "cgana", pass_wrapper); +}