/*Add a graph pass to a graph pass manager. */
void ir_graph_pass_mgr_add(ir_graph_pass_manager_t *mgr, ir_graph_pass_t *pass)
{
- list_add(&pass->list, &mgr->passes);
+ list_add_tail(&pass->list, &mgr->passes);
++mgr->n_passes;
if (pass->add_to_mgr)
pass->add_to_mgr(pass->context);
/* Add an irprog pass to an irprog pass manager. */
void ir_prog_pass_mgr_add(ir_prog_pass_manager_t *mgr, ir_prog_pass_t *pass)
{
- list_add(&pass->list, &mgr->passes);
+ list_add_tail(&pass->list, &mgr->passes);
++mgr->n_passes;
if (pass->add_to_mgr)
pass->add_to_mgr(pass->context);
return ir_graph_pass_mgr_run(mgr);
}
-/**
- * Ensure that no verifier is run from the wrapper.
- */
-static int no_verify(ir_prog *prog, void *ctx)
+/* Ensure that no verifier is run an ir_prog pass. */
+int ir_prog_no_verify(ir_prog *prog, void *ctx)
{
(void)prog;
(void)ctx;
return 0;
}
-/**
- * Ensure that no dumper is run from the wrapper.
- */
-static void no_dump(ir_prog *prog, void *ctx, unsigned idx)
+/* Ensure that no dumper is run from an ir_prog pass. */
+void ir_prog_no_dump(ir_prog *prog, void *ctx, unsigned idx)
{
(void)prog;
(void)ctx;
}
/**
- * Term warpper for a wrapped ir_graph pass manager.
+ * Term wrapper for a wrapped ir_graph pass manager.
*/
static void term_wrapper(void *context)
{
pass->name = graph_mgr->name;
/* do not verify nor dump: this is handled by the graph manager */
- pass->verify_irprog = no_verify;
- pass->dump_irprog = no_dump;
+ pass->verify_irprog = ir_prog_no_verify;
+ pass->dump_irprog = ir_prog_no_dump;
pass->is_wrapper = 1;
pass->add_to_mgr = NULL;
graph_mgr = wrapper->context;
ir_graph_pass_mgr_add(graph_mgr, pass);
+ ++mgr->n_passes;
return;
}
}
/* not found, create a new wrapper */
- graph_mgr = new_graph_pass_mgr("wrapper", mgr->verify_all, mgr->dump_all);
+ graph_mgr = new_graph_pass_mgr(
+ "graph_pass_wrapper", mgr->verify_all, mgr->dump_all);
+ graph_mgr->run_idx = mgr->run_idx + mgr->n_passes;
+
ir_graph_pass_mgr_add(graph_mgr, pass);
wrapper = create_wrapper_pass(graph_mgr);
/**
* Verify all graphs on the given ir_prog.
*/
-static int irp_verify_irgs(ir_prog *irp, int flags) {
+static int irp_verify_irgs(void)
+{
int i, res = 1;
for (i = get_irp_n_irgs() - 1; i >= 0; --i)
- res &= irg_verify(get_irp_irg(i), flags);
+ res &= irg_verify(get_irp_irg(i), 0);
return res;
}
if (pass->verify_irprog) {
pass->verify_irprog(irp, pass->context);
} else {
- irp_verify_irgs(irp, 0);
+ irp_verify_irgs();
}
}
/* dump */
ir_graph_pass_manager_t *new_graph_pass_mgr(
const char *name, int verify_all, int dump_all)
{
- ir_graph_pass_manager_t *res = xmalloc(sizeof(res));
+ ir_graph_pass_manager_t *res = XMALLOCZ(ir_graph_pass_manager_t);
INIT_LIST_HEAD(&res->passes);
+ res->kind = k_ir_graph_pass_mgr;
res->name = name;
res->run_idx = 0;
res->verify_all = verify_all != 0;
ir_prog_pass_manager_t *new_prog_pass_mgr(
const char *name, int verify_all, int dump_all)
{
- ir_prog_pass_manager_t *res = xmalloc(sizeof(res));
+ ir_prog_pass_manager_t *res = XMALLOCZ(ir_prog_pass_manager_t);
INIT_LIST_HEAD(&res->passes);
+ res->kind = k_ir_prog_pass_mgr;
res->name = name;
res->run_idx = 0;
res->verify_all = verify_all != 0;
* @param mgr the manager
* @param run_idx the index for the first pass of this manager
*/
-void ir_graph_pass_manager_set_run_idx(
+void ir_graph_pass_mgr_set_run_idx(
ir_graph_pass_manager_t *mgr, unsigned run_idx)
{
mgr->run_idx = run_idx;
* @param mgr the manager
* @param run_idx the index for the first pass of this manager
*/
-void ir_prog_pass_manager_set_run_idx(
+void ir_prog_pass_mgr_set_run_idx(
ir_prog_pass_manager_t *mgr, unsigned run_idx)
{
mgr->run_idx = run_idx;
const char *name, int (*function)(ir_graph *irg, void *context)) {
if (pass == NULL)
pass = XMALLOCZ(ir_graph_pass_t);
+ else
+ memset(pass, 0, sizeof(ir_graph_pass_t));
pass->kind = k_ir_graph_pass;
pass->run_on_irg = function;
pass->context = pass;
return pass;
} /* def_graph_pass_constructor */
+/* set the run parallel property */
+void ir_graph_pass_set_parallel(ir_graph_pass_t *pass, int flag) {
+ pass->run_parallel = flag != 0;
+} /* ir_graph_pass_set_parallel */
/**
* Wrapper for running void function(void) as an ir_prog pass.
return pass;
} /* def_prog_pass */
+
+/* Creates an ir_prog pass for running void function(void). */
+ir_prog_pass_t *def_prog_pass_constructor(
+ ir_prog_pass_t *pass,
+ const char *name,
+ int (*function)(ir_prog *irp, void *context))
+{
+ if (pass == NULL)
+ pass = XMALLOCZ(ir_prog_pass_t);
+ else
+ memset(pass, 0, sizeof(ir_prog_pass_t));
+
+ pass->kind = k_ir_prog_pass;
+ pass->run_on_irprog = function;
+ pass->context = pass;
+ pass->name = name;
+
+ INIT_LIST_HEAD(&pass->list);
+
+ return pass;
+} /* def_prog_pass_constructor */
+
+struct pass_t {
+ ir_prog_pass_t pass;
+ void *context;
+ void (*function)(void *context);
+};
+
+/**
+ * Wrapper for the call_function pass.
+ */
+static int call_function_wrapper(ir_prog *irp, void *context) {
+ struct pass_t *pass = context;
+
+ (void)irp;
+ pass->function(pass->context);
+ return 0;
+} /* call_function_wrapper */
+
+ir_prog_pass_t *call_function_pass(
+ const char *name, void (*function)(void *context), void *context) {
+ struct pass_t *pass = XMALLOCZ(struct pass_t);
+
+ def_prog_pass_constructor(
+ &pass->pass, name ? name : "set_function", call_function_wrapper);
+
+ pass->pass.verify_irprog = ir_prog_no_verify;
+ pass->pass.dump_irprog = ir_prog_no_dump;
+ pass->pass.context = pass;
+
+ pass->function = function;
+ pass->context = context;
+
+ return &pass->pass;
+} /* call_function_pass */