From 67499260e61f041dc855885ce8ded6ef213760d7 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Tue, 6 Sep 2005 11:56:26 +0000 Subject: [PATCH] fixed SH's dominance checker, can now handle dead blocks ir_vrfy() renamed to ir_verify() with new flag argument: dominance checking can now be enforced [r6579] --- ir/ir/irvrfy.c | 110 +++++++++++++++++++++++++++++++---------------- ir/ir/irvrfy.h | 17 +++++++- ir/ir/irvrfy_t.h | 2 +- 3 files changed, 90 insertions(+), 39 deletions(-) diff --git a/ir/ir/irvrfy.c b/ir/ir/irvrfy.c index 98e49892b..bb70390a2 100644 --- a/ir/ir/irvrfy.c +++ b/ir/ir/irvrfy.c @@ -6,7 +6,7 @@ * Modified by: Goetz Lindenmaier. Till Riedel. Michael Beck. * Created: * CVS-ID: $Id$ - * Copyright: (c) 1998-2003 Universit�t Karlsruhe + * Copyright: (c) 1998-2003 Universität Karlsruhe * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. */ @@ -1567,32 +1567,41 @@ static int verify_node_Mux(ir_node *n, ir_graph *irg) { * node dominates the block of the usage (for phis: the predecessor * block of the phi for the corresponding edge). */ -static int check_dominance_for_node(ir_node *irn) +static int check_dominance_for_node(ir_node *use) { - /* This won't work for blocks and the end node */ - if(!is_Block(irn) && irn != get_irg_end(current_ir_graph)) { - int i, n; - ir_node *bl = get_nodes_block(irn); + /* This won't work for blocks and the end node */ + if (!is_Block(use) && use != get_irg_end(current_ir_graph)) { + int i; + ir_node *bl = get_nodes_block(use); - for(i = 0, n = get_irn_arity(irn); i < n; ++i) { - ir_node *op = get_irn_n(irn, i); - ir_node *def_bl = get_nodes_block(op); - ir_node *use_bl = bl; + for (i = get_irn_arity(use) - 1; i >= 0; --i) { + ir_node *def = get_irn_n(use, i); + ir_node *def_bl = get_nodes_block(def); + ir_node *use_bl = bl; - if(is_Phi(irn)) - use_bl = get_Block_cfgpred_block(bl, i); + /* ignore dead definition blocks, will be removed */ + if (is_Block_dead(def_bl) || get_Block_dom_depth(def_bl) == -1) + continue; - ASSERT_AND_RET_DBG(block_dominates(def_bl, use_bl), - "the definition of a value used violates the dominance property", 0, - ir_fprintf(stderr, - "graph %+F: %+F in %+F must dominate user %+F in %+F\n", - current_ir_graph, op, def_bl, irn, use_bl);); - } - } + if (is_Phi(use)) + use_bl = get_Block_cfgpred_block(bl, i); - return 1; -} + /* ignore dead use blocks, will be removed */ + if (is_Block_dead(use_bl) || get_Block_dom_depth(use_bl) == -1) + continue; + ASSERT_AND_RET_DBG( + block_dominates(def_bl, use_bl), + "the definition of a value used violates the dominance property", 0, + ir_fprintf(stderr, + "graph %+F: %+F of %+F must dominate %+F of user %+F input %d\n", + current_ir_graph, def_bl, def, use_bl, use, i + ); + ); + } + } + return 1; +} int irn_vrfy_irg(ir_node *n, ir_graph *irg) { @@ -1619,11 +1628,11 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg) /* We don't want to test nodes whose predecessors are Bad, as we would have to special case that for each operation. */ - if (op != op_Phi && op != op_Block) - for (i = get_irn_arity(n) - 1; i >= 0; --i) { - if (is_Bad(get_irn_n(n, i))) - return 1; - } + if (op != op_Phi && op != op_Block) + for (i = get_irn_arity(n) - 1; i >= 0; --i) { + if (is_Bad(get_irn_n(n, i))) + return 1; + } if (op->verify_node) return op->verify_node(n, irg); @@ -1645,18 +1654,36 @@ int irn_vrfy(ir_node *n) /* Verify the whole graph. */ /*-----------------------------------------------------------------*/ -/* This *is* used, except gcc doesn't notice that */ -static void vrfy_wrap(ir_node *node, void *env) +#ifdef DEBUG_libfirm +/** + * Walker to check every node + */ +static void vrfy_wrap(ir_node *node, void *env) { + int *res = env; + *res = irn_vrfy(node); +} + +/** + * Walker to check every node including SSA property. + * Only called if domonance info is available. + */ +static void vrfy_wrap_ssa(ir_node *node, void *env) { int *res = env; *res = irn_vrfy(node); - -// if(*res && get_irg_dom_state(current_ir_graph) == dom_consistent) -// *res = check_dominance_for_node(node); + if (*res) + *res = check_dominance_for_node(node); } -int irg_vrfy(ir_graph *irg) +#endif /* DEBUG_libfirm */ + +/* + * Calls irn_vrfy for each node in irg. + * Graph must be in state "op_pin_state_pinned". + * If dominance info is available, check the SSA property. + */ +int irg_verify(ir_graph *irg, unsigned flags) { int res = 1; #ifdef DEBUG_libfirm @@ -1667,7 +1694,17 @@ int irg_vrfy(ir_graph *irg) last_irg_error = NULL; assert(get_irg_pinned(irg) == op_pin_state_pinned); - irg_walk_graph(irg, vrfy_wrap, NULL, &res); + + if (flags & VRFY_ENFORCE_SSA) + compute_doms(irg); + + irg_walk_graph( + irg, + get_irg_dom_state(irg) == dom_consistent && + get_irg_pinned(irg) == op_pin_state_pinned ? + vrfy_wrap_ssa : vrfy_wrap, + NULL, &res + ); current_ir_graph = rem; @@ -1679,9 +1716,7 @@ int irg_vrfy(ir_graph *irg) else fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph); } - - -#endif +#endif /* DEBUG_libfirm */ return res; } @@ -1706,6 +1741,9 @@ typedef struct _vrfy_bad_env_t { int res; } vrfy_bad_env_t; +/** + * Pre-Walker: check Bad predecessors of node. + */ static void check_bads(ir_node *node, void *env) { vrfy_bad_env_t *venv = env; diff --git a/ir/ir/irvrfy.h b/ir/ir/irvrfy.h index 4bacb198d..7be8878d1 100644 --- a/ir/ir/irvrfy.h +++ b/ir/ir/irvrfy.h @@ -65,13 +65,26 @@ int irn_vrfy_irg(struct ir_node *checknode, ir_graph *irg); int irn_vrfy_irg_dump(struct ir_node *checknode, ir_graph *irg, const char **bad_string); /** - * Calls irn_vrfy for each node in irg. + * Flags for irg_verify(). + */ +enum irg_verify_flags { + 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 */ +}; + +/** + * Calls irn_vrfy() for each node in irg. * Graph must be in state "op_pin_state_pinned". * * \return * NON-zero on success. */ -int irg_vrfy(ir_graph *irg); +int irg_verify(ir_graph *irg, unsigned flags); + +/** + * Compatibility macro. Deprecated soon. + */ +#define irg_vrfy(irg) irg_verify(irg, 0) /** * Possible flags for irg_vrfy_bads(). diff --git a/ir/ir/irvrfy_t.h b/ir/ir/irvrfy_t.h index 6025cfea8..10249ddc6 100644 --- a/ir/ir/irvrfy_t.h +++ b/ir/ir/irvrfy_t.h @@ -35,7 +35,7 @@ extern const char *firm_vrfy_failure_msg; do { \ if (opt_do_node_verification == NODE_VERIFICATION_ON) {\ if (!(expr) && current_ir_graph != get_const_code_irg()) \ - dump_ir_block_graph(current_ir_graph, "-assert"); \ + dump_ir_block_graph(current_ir_graph, "-assert"); \ assert((expr) && string); } \ if (!(expr)) { \ if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \ -- 2.20.1