From 30abccc0868ac7a535746a06ec8c082cd5cd1a3c Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Thu, 11 Feb 2010 14:54:29 +0000 Subject: [PATCH] Add pass creating for loop inversion, unrolling, peeling and mux lowering. [r27123] --- include/libfirm/iroptimize.h | 27 +++++++++++++++++++++++++++ include/libfirm/lowering.h | 11 +++++++++++ ir/lower/lower_mux.c | 25 +++++++++++++++++++++++++ ir/opt/loop.c | 13 +++++++++++++ 4 files changed, 76 insertions(+) diff --git a/include/libfirm/iroptimize.h b/include/libfirm/iroptimize.h index 6c22a46e9..cbb3ccdc8 100644 --- a/include/libfirm/iroptimize.h +++ b/include/libfirm/iroptimize.h @@ -918,6 +918,33 @@ void do_loop_unrolling(ir_graph *irg); */ void do_loop_peeling(ir_graph *irg); +/** + * Creates an ir_graph pass for loop inversion. + * + * @param name the name of this pass or NULL + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *loop_inversion_pass(const char *name); + +/** + * Creates an ir_graph pass for loop unrolling. + * + * @param name the name of this pass or NULL + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *loop_unroll_pass(const char *name); + +/** + * Creates an ir_graph pass for loop peeling. + * + * @param name the name of this pass or NULL + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *loop_peeling_pass(const char *name); + typedef ir_type *(*get_Alloc_func)(ir_node *n); /** Set a new get_Alloc_func and returns the old one. */ get_Alloc_func firm_set_Alloc_func(get_Alloc_func newf); diff --git a/include/libfirm/lowering.h b/include/libfirm/lowering.h index 9f0c62373..f54ce72c0 100644 --- a/include/libfirm/lowering.h +++ b/include/libfirm/lowering.h @@ -325,6 +325,17 @@ typedef int lower_mux_callback(ir_node* mux); */ void lower_mux(ir_graph *irg, lower_mux_callback *cb_func); +/** + * Creates an ir_graph pass for lower_mux(). + * + * @param name the name of this pass or NULL + * @param cb_func The callback function for mux selection. Can be NULL, + * to lower all mux nodes. + * + * @return the newly created ir_graph pass + */ +ir_graph_pass_t *lower_mux_pass(const char *name, lower_mux_callback *cb_func); + /** * An intrinsic mapper function. * diff --git a/ir/lower/lower_mux.c b/ir/lower/lower_mux.c index 1a676b6a5..076d974ab 100644 --- a/ir/lower/lower_mux.c +++ b/ir/lower/lower_mux.c @@ -35,6 +35,7 @@ #include "irgmod.h" #include "ircons.h" #include "irvrfy.h" +#include "irpass_t.h" typedef struct walk_env { lower_mux_callback *cb_func; @@ -144,3 +145,27 @@ void lower_mux(ir_graph *irg, lower_mux_callback *cb_func) } DEL_ARR_F(env.muxes); } + +struct pass_t { + ir_graph_pass_t pass; + lower_mux_callback *cb_func; +}; + +/** + * Wrapper to run ir_lower_mux() as an ir_graph pass + */ +static int pass_wrapper(ir_graph *irg, void *context) +{ + struct pass_t *pass = context; + + lower_mux(irg, pass->cb_func); + return 0; +} + +ir_graph_pass_t *lower_mux_pass(const char *name, lower_mux_callback *cb_func) { + struct pass_t *pass = XMALLOCZ(struct pass_t); + + pass->cb_func = cb_func; + return def_graph_pass_constructor( + &pass->pass, name ? name : "lower_mux", pass_wrapper); +} diff --git a/ir/opt/loop.c b/ir/opt/loop.c index 7aceb2dc2..74ac01b1d 100644 --- a/ir/opt/loop.c +++ b/ir/opt/loop.c @@ -39,6 +39,7 @@ #include "array_t.h" /* automatic array */ #include "beutil.h" /* get_block */ #include "irloop_t.h" /* set_irn_loop*/ +#include "irpass.h" #if 0 #include "irdump_t.h" @@ -1581,6 +1582,18 @@ void do_loop_peeling(ir_graph *irg) } +ir_graph_pass_t *loop_inversion_pass(const char *name) { + return def_graph_pass(name ? name : "loop_inversion", do_loop_inversion); +} + +ir_graph_pass_t *loop_unroll_pass(const char *name) { + return def_graph_pass(name ? name : "loop_unroll", do_loop_unrolling); +} + +ir_graph_pass_t *loop_peeling_pass(const char *name) { + return def_graph_pass(name ? name : "loop_peeling", do_loop_peeling); +} + void firm_init_loop_opt(void) { FIRM_DBG_REGISTER(dbg, "firm.opt.loop"); -- 2.20.1