Commit 4b363c6a authored by Michael Beck's avatar Michael Beck
Browse files

- moved pass constructors from irtools to irpass

- add an irg_verify_pass()

[r26374]
parent 8800cffa
......@@ -55,12 +55,10 @@ void construct_confirms(ir_graph *irg);
* Creates an ir_graph pass for construct_confirms().
*
* @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 *construct_confirms_pass(const char *name, int verify, int dump);
ir_graph_pass_t *construct_confirms_pass(const char *name);
/**
* Remove all Confirm nodes from a graph.
......@@ -74,11 +72,9 @@ void remove_confirms(ir_graph *irg);
* Creates an ir_graph pass for remove_confirms().
*
* @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 *remove_confirms_pass(const char *name, int verify, int dump);
ir_graph_pass_t *remove_confirms_pass(const char *name);
#endif
......@@ -48,8 +48,6 @@ 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
*/
......
......@@ -118,4 +118,58 @@ int ir_prog_pass_mgr_run(ir_prog_pass_manager_t *mgr);
*/
void term_prog_pass_mgr(ir_prog_pass_manager_t *mgr);
/**
* 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 function the function to run
*
* @return the newly created ir_graph pass
*/
ir_graph_pass_t *def_graph_pass(
const char *name, 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 function the function to run
*
* @return the newly created ir_graph pass
*/
ir_graph_pass_t *def_graph_pass_ret(
const char *name, int (*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 memory if non-NULL, an already allocated ir_graph_pass_t
* @param name the name of this pass
* @param function the function to run
*
* @return the newly created ir_graph pass
*/
ir_graph_pass_t *def_graph_pass_constructor(
ir_graph_pass_t *memory,
const char *name, int (*function)(ir_graph *irg, void *context));
/**
* Creates an ir_prog pass for running void function().
* Uses the default verifier and dumper.
* The pass returns always 0.
*
* @param name the name of this pass
* @param function the function to run
*
* @return the newly created ir_graph pass
*/
ir_prog_pass_t *def_prog_pass(
const char *name, void (*function)(void));
#endif
/*
* Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
* Copyright (C) 1995-2009 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
......@@ -58,14 +58,17 @@ int irn_vrfy_irg_dump(ir_node *checknode, ir_graph *irg, const char **bad_string
* Flags for irg_verify().
*/
typedef enum _irg_verify_flags_t {
VRFY_NORMAL = 0, /**< check SSA property only if dominance information is available */
VRFY_ENFORCE_SSA = 1 /**< check SSA property by enforcing the dominance information recalculation */
VRFY_NORMAL = 0, /**< check SSA property only if dominance information is available */
VRFY_ENFORCE_SSA = 1 /**< check SSA property by enforcing the dominance information recalculation */
} irg_verify_flags_t;
/**
* Calls irn_vrfy() for each node in irg.
* Graph must be in state "op_pin_state_pinned".
*
* @param irg the IR-graph t check
* @param flags one of irg_verify_flags_t
*
* @return
* NON-zero on success.
*/
......@@ -76,14 +79,24 @@ int irg_verify(ir_graph *irg, unsigned flags);
*/
#define irg_vrfy(irg) irg_verify(irg, 0)
/**
* Creates an ir_graph pass for irg_verify().
*
* @param name the name of this pass or NULL
* @param flags one of irg_verify_flags_t
*
* @return the newly created ir_graph pass
*/
ir_graph_pass_t *irg_verify_pass(const char *name, unsigned flags);
/**
* Possible flags for irg_vrfy_bads().
*/
enum verify_bad_flags_t {
BAD_CF = 1, /**< Bad nodes are allowed as predecessors of Blocks and Phis. */
BAD_DF = 2, /**< Bad nodes are allowed as dataflow predecessors. */
BAD_BLOCK = 4, /**< Bad nodes are allowed as Block input. */
TUPLE = 8 /**< Tuple nodes are allowed. */
BAD_CF = 1, /**< Bad nodes are allowed as predecessors of Blocks and Phis. */
BAD_DF = 2, /**< Bad nodes are allowed as dataflow predecessors. */
BAD_BLOCK = 4, /**< Bad nodes are allowed as Block input. */
TUPLE = 8 /**< Tuple nodes are allowed. */
};
/**
......
......@@ -35,6 +35,7 @@
#include "irgwalk.h"
#include "irprintf.h"
#include "irgopt.h"
#include "irpass.h"
#include "irtools.h"
#include "array_t.h"
#include "debug.h"
......
......@@ -166,80 +166,3 @@ 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_graph_wrapper(ir_graph *irg, void *context) {
void (*function)(ir_graph *irg) = context;
function(irg);
return 0;
} /* void_graph_wrapper */
/* Creates an ir_graph pass for running void function(ir_graph *irg). */
ir_graph_pass_t *def_graph_pass(
const char *name, void (*function)(ir_graph *irg))
{
struct ir_graph_pass_t *pass = XMALLOCZ(ir_graph_pass_t);
pass->kind = k_ir_graph_pass;
pass->run_on_irg = void_graph_wrapper;
pass->context = function;
pass->name = name;
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_graph_wrapper(ir_graph *irg, void *context) {
int (*function)(ir_graph *irg) = context;
return function(irg);
} /* int_graph_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 (*function)(ir_graph *irg))
{
struct ir_graph_pass_t *pass = XMALLOCZ(ir_graph_pass_t);
pass->kind = k_ir_graph_pass;
pass->run_on_irg = int_graph_wrapper;
pass->context = function;
pass->name = name;
INIT_LIST_HEAD(&pass->list);
return pass;
} /* def_graph_pass_ret */
/**
* Wrapper for running void function(void) as an ir_prog pass.
*/
static int void_prog_wrapper(ir_prog *irp, void *context) {
void (*function)(void) = context;
(void)irp;
function();
return 0;
} /* void_graph_wrapper */
/* Creates an ir_prog pass for running void function(void). */
ir_prog_pass_t *def_prog_pass(
const char *name,
void (*function)(void))
{
struct ir_prog_pass_t *pass = XMALLOCZ(ir_prog_pass_t);
pass->kind = k_ir_prog_pass;
pass->run_on_irprog = void_prog_wrapper;
pass->context = function;
pass->name = name;
INIT_LIST_HEAD(&pass->list);
return pass;
} /* def_prog_pass */
......@@ -105,43 +105,4 @@ 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 function the function to run
*
* @return the newly created ir_graph pass
*/
ir_graph_pass_t *def_graph_pass(
const char *name, 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 function the function to run
*
* @return the newly created ir_graph pass
*/
ir_graph_pass_t *def_graph_pass_ret(
const char *name, int (*function)(ir_graph *irg));
/**
* Creates an ir_prog pass for running void function().
* Uses the default verifier and dumper.
* The pass returns always 0.
*
* @param name the name of this pass
* @param function the function to run
*
* @return the newly created ir_graph pass
*/
ir_prog_pass_t *def_prog_pass(
const char *name, void (*function)(void));
#endif
......@@ -339,3 +339,97 @@ void ir_prog_pass_manager_set_run_idx(
{
mgr->run_idx = run_idx;
}
/**
* Wrapper for running void function(ir_graph *irg) as an ir_graph pass.
*/
static int void_graph_wrapper(ir_graph *irg, void *context) {
void (*function)(ir_graph *irg) = context;
function(irg);
return 0;
} /* void_graph_wrapper */
/* Creates an ir_graph pass for running void function(ir_graph *irg). */
ir_graph_pass_t *def_graph_pass(
const char *name, void (*function)(ir_graph *irg))
{
struct ir_graph_pass_t *pass = XMALLOCZ(ir_graph_pass_t);
pass->kind = k_ir_graph_pass;
pass->run_on_irg = void_graph_wrapper;
pass->context = function;
pass->name = name;
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_graph_wrapper(ir_graph *irg, void *context) {
int (*function)(ir_graph *irg) = context;
return function(irg);
} /* int_graph_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 (*function)(ir_graph *irg))
{
struct ir_graph_pass_t *pass = XMALLOCZ(ir_graph_pass_t);
pass->kind = k_ir_graph_pass;
pass->run_on_irg = int_graph_wrapper;
pass->context = function;
pass->name = name;
INIT_LIST_HEAD(&pass->list);
return pass;
} /* def_graph_pass_ret */
/* constructor for a default graph pass */
ir_graph_pass_t *def_graph_pass_constructor(
ir_graph_pass_t *pass,
const char *name, int (*function)(ir_graph *irg, void *context)) {
if (pass == NULL)
pass = XMALLOCZ(ir_graph_pass_t);
pass->kind = k_ir_graph_pass;
pass->run_on_irg = function;
pass->context = pass;
pass->name = name;
INIT_LIST_HEAD(&pass->list);
return pass;
} /* def_graph_pass_constructor */
/**
* Wrapper for running void function(void) as an ir_prog pass.
*/
static int void_prog_wrapper(ir_prog *irp, void *context) {
void (*function)(void) = context;
(void)irp;
function();
return 0;
} /* void_graph_wrapper */
/* Creates an ir_prog pass for running void function(void). */
ir_prog_pass_t *def_prog_pass(
const char *name,
void (*function)(void))
{
struct ir_prog_pass_t *pass = XMALLOCZ(ir_prog_pass_t);
pass->kind = k_ir_prog_pass;
pass->run_on_irprog = void_prog_wrapper;
pass->context = function;
pass->name = name;
INIT_LIST_HEAD(&pass->list);
return pass;
} /* def_prog_pass */
......@@ -36,6 +36,7 @@
#include "irprintf.h"
#include "irouts.h"
#include "irflag_t.h"
#include "irpass_t.h"
/** if this flag is set, verify entity types in Load & Store nodes */
static int vrfy_entities = 0;
......@@ -2064,6 +2065,30 @@ int irg_verify(ir_graph *irg, unsigned flags) {
return res;
}
struct pass_t {
ir_graph_pass_t pass;
unsigned flags;
};
/**
* Wrapper to irg_verify to be run as an ir_graph pass.
*/
static int irg_verify_wrapper(ir_graph *irg, void *context) {
struct pass_t *pass = context;
irg_verify(irg, pass->flags);
/* do NOT rerun the pass if verify is ok :-) */
return 0;
}
/* Creates an ir_graph pass for irg_verify(). */
ir_graph_pass_t *irg_verify_pass(const char *name, unsigned flags) {
struct pass_t *pass = XMALLOCZ(struct pass_t);
pass->flags = flags;
return def_graph_pass_constructor(
&pass->pass, name ? name : "irg_verify", irg_verify_wrapper);
}
int irn_vrfy_irg_dump(ir_node *n, ir_graph *irg, const char **bad_string) {
int res;
firm_verification_t old = get_node_verification_mode();
......
......@@ -596,16 +596,9 @@ static int lower_highlevel_graph_wrapper(ir_graph *irg, void *context) {
ir_graph_pass_t *lower_highlevel_graph_pass(const char *name, int lower_bitfields) {
struct pass_t *pass = XMALLOCZ(struct pass_t);
pass->pass.kind = k_ir_graph_pass;
pass->pass.run_on_irg = lower_highlevel_graph_wrapper;
pass->pass.context = pass;
pass->pass.name = name;
INIT_LIST_HEAD(&pass->pass.list);
pass->lower_bitfields = lower_bitfields;
return &pass->pass;
return def_graph_pass_constructor(
&pass->pass, name ? name : "lower_hl", lower_highlevel_graph_wrapper);
} /* lower_highlevel_graph_pass */
/*
......
......@@ -35,7 +35,7 @@
#include "irprintf.h"
#include "irnode_t.h"
#include "tv.h"
#include "irtools.h"
#include "irpass.h"
typedef struct cond_pair {
ir_node *cmp_lo;
......
......@@ -50,7 +50,7 @@
#include "irflag_t.h"
#include "firmstat.h"
#include "irtools.h"
#include "irpass.h"
#include "iropt_dbg.h"
......
......@@ -31,7 +31,7 @@
#include "irnode_t.h"
#include "irouts.h"
#include "irgopt.h"
#include "irtools.h"
#include "irpass.h"
/**
* Returns non-zero, is a block is not reachable from Start.
......
......@@ -81,7 +81,7 @@
#include "array_t.h"
#include "error.h"
#include "irnodeset.h"
#include "irtools.h"
#include "irpass.h"
#include "tv_t.h"
#include "irprintf.h"
......
......@@ -49,7 +49,7 @@
#include "iredges_t.h"
#include "irgwalk.h"
#include "irprintf.h"
#include "irtools.h"
#include "irpass.h"
DEBUG_ONLY(static firm_dbg_module_t *dbg);
......
......@@ -40,11 +40,11 @@
#include "iredges.h"
#include "iropt_dbg.h"
#include "debug.h"
#include "irpass.h"
#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 {
......
......@@ -517,16 +517,9 @@ static int pass_wrapper(ir_graph *irg, void *context) {
ir_graph_pass_t *opt_if_conv_pass(
const char *name, 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 ? name : "if_conv";
struct pass_t *pass = XMALLOCZ(struct pass_t);
pass->params = params;
INIT_LIST_HEAD(&pass->pass.list);
return &pass->pass;
return def_graph_pass_constructor(
&pass->pass, name ? name : "ifconv", pass_wrapper);
}
......@@ -43,6 +43,7 @@
#include "ircons.h"
#include "cgana.h"
#include "irtools.h"
#include "irpass.h"
DEBUG_ONLY(static firm_dbg_module_t *dbg);
......
......@@ -44,7 +44,7 @@
#include "tv.h"
#include "opt_confirms.h"
#include "iropt_dbg.h"
#include "irtools.h"
#include "irpass.h"
#undef AVOID_PHIB
......
......@@ -41,7 +41,7 @@
#include "irdump.h"
#include "irflag_t.h"
#include "irprintf.h"
#include "irtools.h"
#include "irpass.h"
#if +0
#define OPTIMISE_LOAD_AFTER_LOAD
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment