From f8b8a445d2c65da173ad640978a5687761a3a620 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Sun, 16 Aug 2009 03:20:04 +0000 Subject: [PATCH] - Put typical case of pass construction into irtools - add more passes [r26350] --- include/libfirm/iroptimize.h | 87 ++++++++++++++++++++++++++++++++++++ ir/common/irtools.c | 56 +++++++++++++++++++++++ ir/common/irtools.h | 32 +++++++++++++ ir/ir/irgopt.c | 26 ++--------- ir/opt/boolopt.c | 7 +++ ir/opt/cfopt.c | 7 +++ ir/opt/combo.c | 29 ++---------- ir/opt/convopt.c | 7 +++ ir/opt/funccall.c | 38 ++++++++++++++++ ir/opt/gvn_pre.c | 7 +++ ir/opt/ifconv.c | 34 ++++++++++++++ ir/opt/jumpthreading.c | 7 +++ 12 files changed, 290 insertions(+), 47 deletions(-) diff --git a/include/libfirm/iroptimize.h b/include/libfirm/iroptimize.h index f4aa87db2..e187217ba 100644 --- a/include/libfirm/iroptimize.h +++ b/include/libfirm/iroptimize.h @@ -44,6 +44,17 @@ */ void optimize_cf(ir_graph *irg); +/** + * Creates an ir_graph pass for optimize_cf(). + * + * @param name the name of this pass or NULL + * @param verify should this pass be verified? + * @param dump should this pass result be dumped? + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *optimize_cf_pass(const char *name, int verify, int dump); + /** * Perform path-sensitive jump threading on the given graph. * @@ -51,6 +62,17 @@ void optimize_cf(ir_graph *irg); */ void opt_jumpthreading(ir_graph* irg); +/** + * Creates an ir_graph pass for opt_jumpthreading(). + * + * @param name the name of this pass or NULL + * @param verify should this pass be verified? + * @param dump should this pass result be dumped? + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *opt_jumpthreading_pass(const char *name, int verify, int dump); + /** * Try to simplify boolean expression in the given ir graph. * eg. x < 5 && x < 6 becomes x < 5 @@ -59,6 +81,17 @@ void opt_jumpthreading(ir_graph* irg); */ void opt_bool(ir_graph *irg); +/** + * Creates an ir_graph pass for opt_bool(). + * + * @param name the name of this pass or NULL + * @param verify should this pass be verified? + * @param dump should this pass result be dumped? + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *opt_bool_pass(const char *name, int verify, int dump); + /** * Try to reduce the number of conv nodes in the given ir graph. * @@ -68,6 +101,17 @@ void opt_bool(ir_graph *irg); */ int conv_opt(ir_graph *irg); +/** + * Creates an ir_graph pass for conv_opt(). + * + * @param name the name of this pass or NULL + * @param verify should this pass be verified? + * @param dump should this pass result be dumped? + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *conv_opt_pass(const char *name, int verify, int dump); + /** * Do the scalar replacement optimization. * Make a date flow analyze and split the @@ -153,6 +197,25 @@ void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback); */ void optimize_funccalls(int force_run, check_alloc_entity_func callback); +/** + * Creates an ir_prog pass for optimize_funccalls(). + * + * @param name the name of this pass or NULL + * @param verify should this pass be verified? + * @param dump should this pass result be dumped? + * @param force_run if non-zero, an optimization run is started even + * if no const function graph was detected. + * Else calls are only optimized if at least one + * const function graph was detected. + * @param callback a callback function to check whether a + * given entity is a allocation call + * + * @return the newly created ir_prog pass + */ +ir_prog_pass_t *optimize_funccalls_pass( + const char *name, int verify, int dump, + int force_run, check_alloc_entity_func callback); + /** * Does Partial Redundancy Elimination combined with * Global Value Numbering. @@ -164,6 +227,17 @@ void optimize_funccalls(int force_run, check_alloc_entity_func callback); */ void do_gvn_pre(ir_graph *irg); +/** + * Creates an ir_graph pass for do_gvn_pre(). + * + * @param name the name of this pass or NULL + * @param verify should this pass be verified? + * @param dump should this pass result be dumped? + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *do_gvn_pre_pass(const char *name, int verify, int dump); + /** * This function is called to evaluate, if a mux can build * of the current architecture. @@ -198,6 +272,19 @@ struct ir_settings_if_conv_t { */ void opt_if_conv(ir_graph *irg, const ir_settings_if_conv_t *params); +/** + * Creates an ir_graph pass for opt_if_conv(). + * + * @param name the name of this pass or NULL + * @param verify should this pass be verified? + * @param dump should this pass result be dumped? + * @param params The parameters for the if conversion. + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *opt_if_conv_pass( + const char *name, int verify, int dump, const ir_settings_if_conv_t *params); + void opt_sync(ir_graph *irg); /* diff --git a/ir/common/irtools.c b/ir/common/irtools.c index d7dd346fb..e2e14e2c2 100644 --- a/ir/common/irtools.c +++ b/ir/common/irtools.c @@ -32,6 +32,7 @@ #include "irbackedge_t.h" #include "irtools.h" #include "irprintf.h" +#include "irpass_t.h" /* the famous clear_link implementation. */ void firm_clear_link(ir_node *n, void *env) { @@ -165,3 +166,58 @@ void firm_pset_dump(pset *set) { ir_fprintf(stderr, "%+F\n", obj); } } + +/** + * Wrapper for running void function(ir_graph *irg) as an ir_graph pass. + */ +static int void_pass_wrapper(ir_graph *irg, void *context) { + void (*function)(ir_graph *irg) = context; + function(irg); + return 0; +} /* void_pass_wrapper */ + +/* Creates an ir_graph pass for running void function(ir_graph *irg). */ +ir_graph_pass_t *def_graph_pass( + const char *name, int verify, int dump, + void (*function)(ir_graph *irg)) +{ + struct ir_graph_pass_t *pass = XMALLOCZ(ir_graph_pass_t); + + pass->kind = k_ir_prog_pass; + pass->run_on_irg = void_pass_wrapper; + pass->context = function; + pass->name = name; + pass->verify = verify != 0; + pass->dump = dump != 0; + + INIT_LIST_HEAD(&pass->list); + + return pass; +} /* def_graph_pass */ + +/** + * Wrapper for running void function(ir_graph *irg) as an ir_graph pass. + */ +static int int_pass_wrapper(ir_graph *irg, void *context) { + int (*function)(ir_graph *irg) = context; + return function(irg); +} /* int_pass_wrapper */ + +/* Creates an ir_graph pass for running void function(ir_graph *irg). */ +ir_graph_pass_t *def_graph_pass_ret( + const char *name, int verify, int dump, + int (*function)(ir_graph *irg)) +{ + struct ir_graph_pass_t *pass = XMALLOCZ(ir_graph_pass_t); + + pass->kind = k_ir_prog_pass; + pass->run_on_irg = int_pass_wrapper; + pass->context = function; + pass->name = name; + pass->verify = verify != 0; + pass->dump = dump != 0; + + INIT_LIST_HEAD(&pass->list); + + return pass; +} /* def_graph_pass_ret */ diff --git a/ir/common/irtools.h b/ir/common/irtools.h index ae9ba1152..5a8162eaf 100644 --- a/ir/common/irtools.h +++ b/ir/common/irtools.h @@ -105,4 +105,36 @@ void copy_irn_to_irg(ir_node *n, ir_graph *irg); */ ir_node *exact_copy(const ir_node *n); +/** + * Creates an ir_graph pass for running void function(ir_graph *irg). + * Uses the default verifier and dumper. + * The pass returns always 0. + * + * @param name the name of this pass + * @param verify should this pass be verified? + * @param dump should this pass result be dumped? + * @param params The parameters for the if conversion. + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *def_graph_pass( + const char *name, int verify, int dump, + void (*function)(ir_graph *irg)); + +/** + * Creates an ir_graph pass for running int function(ir_graph *irg). + * Uses the default verifier and dumper. + * The pass returns the return value of function. + * + * @param name the name of this pass + * @param verify should this pass be verified? + * @param dump should this pass result be dumped? + * @param params The parameters for the if conversion. + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *def_graph_pass_ret( + const char *name, int verify, int dump, + int (*function)(ir_graph *irg)); + #endif diff --git a/ir/ir/irgopt.c b/ir/ir/irgopt.c index acebf48ba..158520e68 100644 --- a/ir/ir/irgopt.c +++ b/ir/ir/irgopt.c @@ -222,26 +222,8 @@ int optimize_graph_df(ir_graph *irg) { return changed; } -/** - * Wrapper for running optimize_graph_df() as an ir_graph pass. - */ -static int pass_wrapper(ir_graph *irg, void *context) { - (void)context; - return optimize_graph_df(irg); -} /* pass_wrapper */ - /* Creates an ir_graph pass for optimize_graph_df. */ -ir_graph_pass_t *optimize_graph_df_pass(const char *name, int verify, int dump) { - struct ir_graph_pass_t *pass = XMALLOCZ(ir_graph_pass_t); - - pass->kind = k_ir_prog_pass; - pass->run_on_irg = pass_wrapper; - pass->context = pass; - pass->name = name ? name : "optimize_graph_df"; - pass->verify = verify != 0; - pass->dump = dump != 0; - - INIT_LIST_HEAD(&pass->list); - - return pass; -} /* combo_pass */ +ir_graph_pass_t *optimize_graph_df_pass(const char *name, int verify, int dump) +{ + return def_graph_pass_ret(name ? name : "optimize_graph_df", verify, dump, optimize_graph_df); +} /* optimize_graph_df_pass */ diff --git a/ir/opt/boolopt.c b/ir/opt/boolopt.c index 1de20a5c1..d3f7ef185 100644 --- a/ir/opt/boolopt.c +++ b/ir/opt/boolopt.c @@ -35,6 +35,7 @@ #include "irprintf.h" #include "irnode_t.h" #include "tv.h" +#include "irtools.h" typedef struct cond_pair { ir_node *cmp_lo; @@ -455,3 +456,9 @@ void opt_bool(ir_graph *const irg) ir_free_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_PHI_LIST); } + +/* Creates an ir_graph pass for opt_bool. */ +ir_graph_pass_t *opt_bool_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "opt_bool", verify, dump, opt_bool); +} /* opt_bool_pass */ diff --git a/ir/opt/cfopt.c b/ir/opt/cfopt.c index 5cddcae65..df3700402 100644 --- a/ir/opt/cfopt.c +++ b/ir/opt/cfopt.c @@ -50,6 +50,7 @@ #include "irflag_t.h" #include "firmstat.h" +#include "irtools.h" #include "iropt_dbg.h" @@ -873,3 +874,9 @@ restart: current_ir_graph = rem; } + +/* Creates an ir_graph pass for optimize_cf. */ +ir_graph_pass_t *optimize_cf_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "optimize_cf", verify, dump, optimize_cf); +} /* optimize_cf_pass */ diff --git a/ir/opt/combo.c b/ir/opt/combo.c index 081eee94b..a8c4ccdf4 100644 --- a/ir/opt/combo.c +++ b/ir/opt/combo.c @@ -72,7 +72,6 @@ #include "irgraph_t.h" #include "irnode_t.h" #include "iropt_t.h" -#include "irpass_t.h" #include "irgwalk.h" #include "irop.h" #include "irouts.h" @@ -82,7 +81,7 @@ #include "array_t.h" #include "error.h" #include "irnodeset.h" - +#include "irtools.h" #include "tv_t.h" #include "irprintf.h" @@ -3569,28 +3568,8 @@ void combo(ir_graph *irg) { current_ir_graph = rem; } /* combo */ -/** - * Wrapper for running combo() as an ir_graph pass. - */ -static int pass_wrapper(ir_graph *irg, void *context) { - (void)context; - combo(irg); - /* combo is a fix-point iteration */ - return 0; -} /* pass_wrapper */ - /* Creates an ir_graph pass for combo. */ -ir_graph_pass_t *combo_pass(const char *name, int verify, int dump) { - struct ir_graph_pass_t *pass = XMALLOCZ(ir_graph_pass_t); - - pass->kind = k_ir_prog_pass; - pass->run_on_irg = pass_wrapper; - pass->context = pass; - pass->name = name ? name : "combo"; - pass->verify = verify != 0; - pass->dump = dump != 0; - - INIT_LIST_HEAD(&pass->list); - - return pass; +ir_graph_pass_t *combo_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "combo", verify, dump, combo); } /* combo_pass */ diff --git a/ir/opt/convopt.c b/ir/opt/convopt.c index a6f1612e3..d8e3e5f71 100644 --- a/ir/opt/convopt.c +++ b/ir/opt/convopt.c @@ -49,6 +49,7 @@ #include "iredges_t.h" #include "irgwalk.h" #include "irprintf.h" +#include "irtools.h" DEBUG_ONLY(static firm_dbg_module_t *dbg); @@ -300,3 +301,9 @@ int conv_opt(ir_graph *irg) } return invalidate; } + +/* Creates an ir_graph pass for conv_opt. */ +ir_graph_pass_t *conv_opt_pass(const char *name, int verify, int dump) +{ + return def_graph_pass_ret(name ? name : "conv_opt", verify, dump, conv_opt); +} /* conv_opt_pass */ diff --git a/ir/opt/funccall.c b/ir/opt/funccall.c index 0f373f0ee..5ce0d7413 100644 --- a/ir/opt/funccall.c +++ b/ir/opt/funccall.c @@ -39,6 +39,7 @@ #include "irloop_t.h" #include "ircons.h" #include "iredges_t.h" +#include "irpass_t.h" #include "analyze_irg_args.h" #include "irhooks.h" #include "debug.h" @@ -1073,3 +1074,40 @@ void optimize_funccalls(int force_run, check_alloc_entity_func callback) void firm_init_funccalls(void) { FIRM_DBG_REGISTER(dbg, "firm.opt.funccalls"); } /* firm_init_funccalls */ + +struct pass_t { + ir_prog_pass_t pass; + int force_run; + check_alloc_entity_func callback; +}; + +/** + * Wrapper for running optimize_funccalls() as an ir_prog pass. + */ +static int pass_wrapper(ir_graph *irg, void *context) { + struct pass_t *pass = context; + optimize_funccalls(pass->force_run, pass->callback); + return 0; +} /* pass_wrapper */ + +/* Creates an ir_prog pass for optimize_funccalls. */ +ir_prog_pass_t *optimize_funccalls_pass( + const char *name, int verify, int dump, + int force_run, check_alloc_entity_func callback) +{ + struct pass_t *pass = xmalloc(sizeof(*pass)); + + pass->pass.kind = k_ir_prog_pass; + pass->pass.run_on_irprog = pass_wrapper; + pass->pass.context = pass; + pass->pass.name = name ? name : "funccalls"; + pass->pass.verify = verify != 0; + pass->pass.dump = dump != 0; + + INIT_LIST_HEAD(&pass->pass.list); + + pass->force_run = force_run; + pass->callback = callback; + + return &pass->pass; +} /* optimize_funccalls_pass */ diff --git a/ir/opt/gvn_pre.c b/ir/opt/gvn_pre.c index 9dfe1faa3..6ffe65ca1 100644 --- a/ir/opt/gvn_pre.c +++ b/ir/opt/gvn_pre.c @@ -44,6 +44,7 @@ #include "irgraph_t.h" #include "irnode_t.h" #include "iropt_t.h" +#include "irtools.h" /** Additional info we need for every block. */ typedef struct block_info { @@ -894,3 +895,9 @@ void do_gvn_pre(ir_graph *irg) set_irg_loopinfo_inconsistent(irg); } } /* do_gvn_pre */ + +/* Creates an ir_graph pass for do_gvn_pre. */ +ir_graph_pass_t *do_gvn_pre_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "gvn_pre", verify, dump, do_gvn_pre); +} /* do_gvn_pre_pass */ diff --git a/ir/opt/ifconv.c b/ir/opt/ifconv.c index 0108005a6..a957cbbdb 100644 --- a/ir/opt/ifconv.c +++ b/ir/opt/ifconv.c @@ -37,6 +37,7 @@ #include "irgwalk.h" #include "irtools.h" #include "array_t.h" +#include "irpass_t.h" // debug #include "irdump.h" @@ -498,3 +499,36 @@ void opt_if_conv(ir_graph *irg, const ir_settings_if_conv_t *params) free_cdep(irg); } + +struct pass_t { + ir_graph_pass_t pass; + const ir_settings_if_conv_t *params; +}; + +/** + * Wrapper for running opt_if_conv() as an ir_graph pass. + */ +static int pass_wrapper(ir_graph *irg, void *context) { + struct pass_t *pass = context; + opt_if_conv(irg, pass->params); + return 0; +} /* pass_wrapper */ + +ir_graph_pass_t *opt_if_conv_pass( + const char *name, int verify, int dump, const ir_settings_if_conv_t *params) +{ + struct pass_t *pass = xmalloc(sizeof(*pass)); + + pass->pass.kind = k_ir_prog_pass; + pass->pass.run_on_irg = pass_wrapper; + pass->pass.context = pass; + pass->pass.name = name; + pass->pass.verify = verify != 0; + pass->pass.dump = dump != 0; + + pass->params = params; + + INIT_LIST_HEAD(&pass->pass.list); + + return &pass->pass; +} diff --git a/ir/opt/jumpthreading.c b/ir/opt/jumpthreading.c index 1412eb8af..055282095 100644 --- a/ir/opt/jumpthreading.c +++ b/ir/opt/jumpthreading.c @@ -44,6 +44,7 @@ #include "tv.h" #include "opt_confirms.h" #include "iropt_dbg.h" +#include "irtools.h" #undef AVOID_PHIB @@ -741,3 +742,9 @@ void opt_jumpthreading(ir_graph* irg) optimize_cf(irg); } } + +/* Creates an ir_graph pass for opt_jumpthreading. */ +ir_graph_pass_t *opt_jumpthreading_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "jumpthreading", verify, dump, opt_jumpthreading); +} /* opt_jumpthreading_pass */ -- 2.20.1