From 8f530048146e640fdfeb16b8ebe8bc997a1c8abe Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Sun, 16 Aug 2009 03:48:44 +0000 Subject: [PATCH] - add more passes [r26351] --- include/libfirm/iroptimize.h | 80 ++++++++++++++++++++++++++++++++++++ ir/opt/ifconv.c | 2 +- ir/opt/ldst2.c | 6 +++ ir/opt/ldstopt.c | 5 +++ ir/opt/opt_frame.c | 6 +++ ir/opt/opt_ldst.c | 6 +++ ir/opt/opt_osr.c | 38 +++++++++++++++++ 7 files changed, 142 insertions(+), 1 deletion(-) diff --git a/include/libfirm/iroptimize.h b/include/libfirm/iroptimize.h index e187217ba..5607b0e62 100644 --- a/include/libfirm/iroptimize.h +++ b/include/libfirm/iroptimize.h @@ -287,6 +287,17 @@ ir_graph_pass_t *opt_if_conv_pass( void opt_sync(ir_graph *irg); +/** + * Creates an ir_graph pass for opt_sync(). + * + * @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_sync_pass(const char *name, int verify, int dump); + /* * Check if we can replace the load by a given const from * the const code irg. @@ -329,6 +340,17 @@ ir_node *can_replace_load_by_const(const ir_node *load, ir_node *c); */ int optimize_load_store(ir_graph *irg); +/** + * Creates an ir_graph pass for optimize_load_store(). + * + * @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_load_store_pass(const char *name, int verify, int dump); + /** * New experimental alternative to optimize_load_store. * Based on a dataflow analysis, so load/stores are moved out of loops @@ -336,11 +358,33 @@ int optimize_load_store(ir_graph *irg); */ int opt_ldst(ir_graph *irg); +/** + * Creates an ir_graph pass for opt_ldst(). + * + * @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_ldst_pass(const char *name, int verify, int dump); + /** * Do Loop unrolling in the given graph. */ void optimize_loop_unrolling(ir_graph *irg); +/** + * Creates an ir_graph pass for optimize_loop_unrolling(). + * + * @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_loop_unrolling_pass(const char *name, int verify, int dump); + /** * Optimize the frame type of an irg by removing * never touched entities. @@ -353,6 +397,17 @@ void optimize_loop_unrolling(ir_graph *irg); */ void opt_frame_irg(ir_graph *irg); +/** + * Creates an ir_graph pass for opt_frame_irg(). + * + * @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_frame_irg_pass(const char *name, int verify, int dump); + /** Possible flags for the Operator Scalar Replacement. */ typedef enum osr_flags { osr_flag_none = 0, /**< no additional flags */ @@ -428,6 +483,18 @@ typedef enum osr_flags { */ void opt_osr(ir_graph *irg, unsigned flags); +/** + * Creates an ir_graph pass for remove_phi_cycles(). + * + * @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 flags set of osr_flags + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *opt_osr_pass(const char *name, int verify, int dump, unsigned flags); + /** * Removes useless Phi cycles, i.e cycles of Phi nodes with only one * non-Phi node. @@ -440,6 +507,19 @@ void opt_osr(ir_graph *irg, unsigned flags); */ void remove_phi_cycles(ir_graph *irg); +/** + * Creates an ir_graph pass for remove_phi_cycles(). + * + * @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 *remove_phi_cycles_pass(const char *name, int verify, int dump); + + /** A default threshold. */ #define DEFAULT_CLONE_THRESHOLD 300 diff --git a/ir/opt/ifconv.c b/ir/opt/ifconv.c index a957cbbdb..6684c66ae 100644 --- a/ir/opt/ifconv.c +++ b/ir/opt/ifconv.c @@ -522,7 +522,7 @@ ir_graph_pass_t *opt_if_conv_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.name = name ? name : "if_conv"; pass->pass.verify = verify != 0; pass->pass.dump = dump != 0; diff --git a/ir/opt/ldst2.c b/ir/opt/ldst2.c index 1c039c69b..0c72988eb 100644 --- a/ir/opt/ldst2.c +++ b/ir/opt/ldst2.c @@ -41,6 +41,7 @@ #include "irdump.h" #include "irflag_t.h" #include "irprintf.h" +#include "irtools.h" #if +0 #define OPTIMISE_LOAD_AFTER_LOAD @@ -845,3 +846,8 @@ void opt_sync(ir_graph *irg) //optimize_graph_df(irg); //irg_walk_graph(irg, NormaliseSync, NULL, NULL); } + +ir_graph_pass_t *opt_sync_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "opt_sync", verify, dump, opt_sync); +} diff --git a/ir/opt/ldstopt.c b/ir/opt/ldstopt.c index ea3b1f181..4b76028a7 100644 --- a/ir/opt/ldstopt.c +++ b/ir/opt/ldstopt.c @@ -2300,3 +2300,8 @@ int optimize_load_store(ir_graph *irg) { } return env.changes != 0; } /* optimize_load_store */ + +ir_graph_pass_t *optimize_load_store_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "ldst", verify, dump, optimize_load_store); +} /* optimize_load_store_pass */ diff --git a/ir/opt/opt_frame.c b/ir/opt/opt_frame.c index a038e093f..3ce925429 100644 --- a/ir/opt/opt_frame.c +++ b/ir/opt/opt_frame.c @@ -33,6 +33,7 @@ #include "type_t.h" #include "irouts.h" #include "iredges.h" +#include "irtools.h" /* * Optimize the frame type of an irg by removing @@ -107,3 +108,8 @@ void opt_frame_irg(ir_graph *irg) { } irp_free_resources(irp, IR_RESOURCE_ENTITY_LINK); } + +ir_graph_pass_t *opt_frame_irg_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "opt_frame_irg", verify, dump, opt_frame_irg); +} diff --git a/ir/opt/opt_ldst.c b/ir/opt/opt_ldst.c index f9e03d9cc..4be415204 100644 --- a/ir/opt/opt_ldst.c +++ b/ir/opt/opt_ldst.c @@ -42,6 +42,7 @@ #include "raw_bitset.h" #include "debug.h" #include "error.h" +#include "irtools.h" /* maximum number of output Proj's */ #define MAX_PROJ (pn_Load_max > pn_Store_max ? pn_Load_max : pn_Store_max) @@ -2405,3 +2406,8 @@ end: current_ir_graph = rem; return env.changed != 0; } /* opt_ldst */ + +ir_graph_pass_t *opt_ldst_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "ldst_df", verify, dump, opt_ldst); +} /* opt_ldst_pass */ diff --git a/ir/opt/opt_osr.c b/ir/opt/opt_osr.c index 6d9981d10..fa320562a 100644 --- a/ir/opt/opt_osr.c +++ b/ir/opt/opt_osr.c @@ -51,6 +51,7 @@ #include "array.h" #include "firmstat.h" #include "error.h" +#include "irpass_t.h" /** The debug handle. */ DEBUG_ONLY(static firm_dbg_module_t *dbg;) @@ -1320,6 +1321,11 @@ void remove_phi_cycles(ir_graph *irg) { current_ir_graph = rem; } /* remove_phi_cycles */ +ir_graph_pass_t *remove_phi_cycles_pass(const char *name, int verify, int dump) +{ + return def_graph_pass(name ? name : "remove_phi_cycles", verify, dump, remove_phi_cycles); +} /* remove_phi_cycles_pass */ + /** * Post-walker: fix Add and Sub nodes that where results of I<->P conversions. */ @@ -1452,3 +1458,35 @@ void opt_osr(ir_graph *irg, unsigned flags) { current_ir_graph = rem; } /* opt_osr */ + +struct pass_t { + ir_graph_pass_t pass; + unsigned flags; +}; + +/** +* Wrapper for running opt_osr() as an ir_graph pass. +*/ +static int pass_wrapper(ir_graph *irg, void *context) { + struct pass_t *pass = context; + opt_osr(irg, pass->flags); + return 0; +} /* pass_wrapper */ + +ir_graph_pass_t *opt_osr_pass(const char *name, int verify, int dump, unsigned flags) +{ + 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 ? name : "osr"; + pass->pass.verify = verify != 0; + pass->pass.dump = dump != 0; + + pass->flags = flags; + + INIT_LIST_HEAD(&pass->pass.list); + + return &pass->pass; +} /* opt_osr_pass */ -- 2.20.1