- Put typical case of pass construction into irtools
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sun, 16 Aug 2009 03:20:04 +0000 (03:20 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sun, 16 Aug 2009 03:20:04 +0000 (03:20 +0000)
- add more passes

[r26350]

12 files changed:
include/libfirm/iroptimize.h
ir/common/irtools.c
ir/common/irtools.h
ir/ir/irgopt.c
ir/opt/boolopt.c
ir/opt/cfopt.c
ir/opt/combo.c
ir/opt/convopt.c
ir/opt/funccall.c
ir/opt/gvn_pre.c
ir/opt/ifconv.c
ir/opt/jumpthreading.c

index f4aa87d..e187217 100644 (file)
  */
 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);
 
 /*
index d7dd346..e2e14e2 100644 (file)
@@ -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 */
index ae9ba11..5a8162e 100644 (file)
@@ -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
index acebf48..158520e 100644 (file)
@@ -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 */
index 1de20a5..d3f7ef1 100644 (file)
@@ -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 */
index 5cddcae..df37004 100644 (file)
@@ -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 */
index 081eee9..a8c4ccd 100644 (file)
@@ -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 */
index a6f1612..d8e3e5f 100644 (file)
@@ -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 */
index 0f373f0..5ce0d74 100644 (file)
@@ -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 */
index 9dfe1fa..6ffe65c 100644 (file)
@@ -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 */
index 0108005..a957cbb 100644 (file)
@@ -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;
+}
index 1412eb8..0552820 100644 (file)
@@ -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 */