X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firedges.c;h=29a54061deb141cd7ac4f0d7a9ba092045e0e663;hb=1852308bd33b77378f0fca9e5347d4f9082464c4;hp=336c7b881af1fe700a78a44f55a5efb6b297636c;hpb=14a32bf6e4fe7805dd21304e699905430eb5cdb4;p=libfirm diff --git a/ir/ir/iredges.c b/ir/ir/iredges.c index 336c7b881..29a54061d 100644 --- a/ir/ir/iredges.c +++ b/ir/ir/iredges.c @@ -23,7 +23,7 @@ * @author Sebastian Hack, Michael Beck, Andreas Schoesser * @date 14.1.2005 * @version $Id$ - * @summary + * @brief * This are out-edges (also called def-use edges) that are dynamically * updated as the graph changes. */ @@ -40,6 +40,7 @@ #include "set.h" #include "bitset.h" #include "error.h" +#include "irpass_t.h" #include "iredgeset.h" #include "hashptr.h" @@ -75,8 +76,15 @@ */ typedef void (set_edge_func_t)(ir_node *src, int pos, ir_node *tgt); +/** + * A function that returns the "arity" of a given edge kind + * for a node. + */ typedef int (get_edge_src_arity_func_t)(const ir_node *src); +/** + * A function that returns the pos'th edge of a given edge kind for a node. + */ typedef ir_node *(get_edge_src_n_func_t)(const ir_node *src, int pos); /** @@ -93,9 +101,9 @@ typedef struct { /** * Get the predecessor block. */ -static ir_node *get_block_n(const ir_node *irn, int pos) { - if (is_Block(irn)) - return get_Block_cfgpred_block(irn, pos); +static ir_node *get_block_n(const ir_node *block, int pos) { + if (is_Block(block)) + return get_Block_cfgpred_block(block, pos); /* might be a Bad */ return NULL; } @@ -135,6 +143,9 @@ static int edges_dbg = 0; static long last_edge_num = -1; #endif +/** + * Returns an ID for the given edge. + */ static inline long edge_get_id(const ir_edge_t *e) { #ifdef DEBUG_libfirm return e->edge_nr; @@ -163,12 +174,12 @@ int edges_register_private_data(size_t n) { return res; } -/** +/* * Reset the user's private data at offset 'offset' * The user has to remember his offset and the size of his data! * Caution: Using wrong values here can destroy other users private data! */ -void edges_reset_private_data(ir_graph *irg, int offset, size_t size) { +void edges_reset_private_data(ir_graph *irg, int offset, unsigned size) { irg_edge_info_t *info = _get_irg_edge_info(irg, EDGE_KIND_NORMAL); ir_edge_t *edge; ir_edgeset_iterator_t iter; @@ -208,9 +219,10 @@ void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind) { /** * Get the edge object of an outgoing edge at a node. - * @param irg The graph, the node is in. - * @param src The node at which the edge originates. - * @param pos The position of the edge. + * @param irg The graph, the node is in. + * @param src The node at which the edge originates. + * @param pos The position of the edge. + * @param kind The kind of the edge. * @return The corresponding edge object or NULL, * if no such edge exists. */ @@ -584,6 +596,8 @@ void edges_activate_kind(ir_graph *irg, ir_edge_kind_t kind) visit.data = &w; + assert(!info->activated); + info->activated = 1; edges_init_graph_kind(irg, kind); if (kind == EDGE_KIND_DEP) { @@ -868,6 +882,37 @@ int edges_verify(ir_graph *irg) { return problem_found ? 1 : w.problem_found; } +struct pass_t { + ir_graph_pass_t pass; + unsigned assert_on_problem; +}; + +/** + * Wrapper to edges_verify to be run as an ir_graph pass. + */ +static int edges_verify_wrapper(ir_graph *irg, void *context) { + struct pass_t *pass = context; + int problems_found = edges_verify(irg); + /* do NOT rerun the pass if verify is ok :-) */ + assert(problems_found && pass->assert_on_problem); + return 0; +} + +/* Creates an ir_graph pass for edges_verify(). */ +ir_graph_pass_t *irg_verify_edges_pass(const char *name, unsigned assert_on_problem) { + struct pass_t *pass = XMALLOCZ(struct pass_t); + + def_graph_pass_constructor( + &pass->pass, name ? name : "edges_verify", edges_verify_wrapper); + + /* neither dump nor verify */ + pass->pass.dump_irg = (DUMP_ON_IRG_FUNC)ir_prog_no_dump; + pass->pass.verify_irg = (RUN_ON_IRG_FUNC)ir_prog_no_verify; + + pass->assert_on_problem = assert_on_problem; + return &pass->pass; +} + void init_edges(void) { FIRM_DBG_REGISTER(dbg, DBG_EDGES); /* firm_dbg_set_mask(dbg, -1); */ @@ -891,11 +936,20 @@ void edges_deactivate(ir_graph *irg) { edges_deactivate_kind(irg, EDGE_KIND_NORMAL); } -int edges_assure(ir_graph *irg) { - int activated = edges_activated(irg); +int edges_assure(ir_graph *irg) +{ + int activated = 0; - if (!activated) - edges_activate(irg); + if (edges_activated_kind(irg, EDGE_KIND_BLOCK)) { + activated = 1; + } else { + edges_activate_kind(irg, EDGE_KIND_BLOCK); + } + if (edges_activated_kind(irg, EDGE_KIND_NORMAL)) { + activated = 1; + } else { + edges_activate_kind(irg, EDGE_KIND_NORMAL); + } return activated; }