Add pass creating for loop inversion, unrolling, peeling and mux lowering.
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 11 Feb 2010 14:54:29 +0000 (14:54 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 11 Feb 2010 14:54:29 +0000 (14:54 +0000)
[r27123]

include/libfirm/iroptimize.h
include/libfirm/lowering.h
ir/lower/lower_mux.c
ir/opt/loop.c

index 6c22a46..cbb3ccd 100644 (file)
@@ -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);
index 9f0c623..f54ce72 100644 (file)
@@ -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.
  *
index 1a676b6..076d974 100644 (file)
@@ -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);
+}
index 7aceb2d..74ac01b 100644 (file)
@@ -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");