X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firvrfy.c;h=146c3eca96ed63bd7e08e89ebd53c965979561f7;hb=f9d25133f86594ca2b1f33fb0b41a591ecc9b914;hp=bd3ce5db8791ca22a0f7216f4737dda6154dedaf;hpb=ef25f3dda4b94c441d39777cd1b80c11acd9fa62;p=libfirm diff --git a/ir/ir/irvrfy.c b/ir/ir/irvrfy.c index bd3ce5db8..146c3eca9 100644 --- a/ir/ir/irvrfy.c +++ b/ir/ir/irvrfy.c @@ -3,10 +3,10 @@ * File name: ir/ir/irvrfy.c * Purpose: Check irnodes for correctness. * Author: Christian Schaefer - * Modified by: Goetz Lindenmaier. Till Riedel + * 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. */ @@ -21,13 +21,13 @@ # include "irvrfy_t.h" # include "irgwalk.h" # include "irdump.h" +# include "irdom_t.h" +# include "irprintf.h" +# include "irouts.h" /** if this flag is set, verify entity types in Load & Store nodes */ static int vrfy_entities = 0; -/* @@@ replace use of array "in" by access functions. */ -ir_node **get_irn_in(ir_node *node); - node_verification_t opt_do_node_verification = NODE_VERIFICATION_ON; const char *firm_vrfy_failure_msg; @@ -390,12 +390,12 @@ static int verify_node_Proj_Call(ir_node *n, ir_node *p) { ); if (proj == pn_Call_X_except) ASSERT_AND_RET( - get_irn_pinned(n) == op_pin_state_pinned, - "Exception Proj from unpinned Call", 0); + get_irn_op(get_Call_mem(n)) != op_NoMem, + "Exception Proj from FunctionCall", 0); else if (proj == pn_Call_M_regular || proj == pn_Call_M_except) ASSERT_AND_RET( - get_irn_pinned(n) == op_pin_state_pinned, - "Memory Proj from unpinned Call", 0); + (get_irn_op(get_Call_mem(n)) != op_NoMem || 1), + "Memory Proj from FunctionCall", 0); return 1; } @@ -786,6 +786,20 @@ static int verify_node_Jmp(ir_node *n, ir_graph *irg) { return 1; } +/** + * verify an IJmp node + */ +static int verify_node_IJmp(ir_node *n, ir_graph *irg) { + ir_mode *mymode = get_irn_mode(n); + ir_mode *op1mode = get_irn_mode(get_IJmp_target(n)); + + ASSERT_AND_RET( + /* IJmp: BB x ref --> X */ + mymode == mode_X && mode_is_reference(op1mode), "IJmp node", 0 + ); + return 1; +} + /** * verify a Break node */ @@ -815,6 +829,14 @@ static int verify_node_Cond(ir_node *n, ir_graph *irg) { mode_is_int(op1mode) ), "Cond node", 0 ); ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0); + + if (op1mode == mode_b && get_irg_outs_state(irg) == outs_consistent && + !is_Block_dead(get_nodes_block(n))) { + /* we have consistent outs, check for the right number of Proj's */ + ASSERT_AND_RET( + get_irn_n_outs(n) == 2, + "Live binary Cond node must have 2 successors", 0); + } return 1; } @@ -969,7 +991,7 @@ static int verify_node_Call(ir_node *n, ir_graph *irg) { /* NoMem nodes are only allowed as memory input if the Call is NOT pinned */ ASSERT_AND_RET( - (get_irn_op(get_Call_mem(n)) == op_NoMem && get_irn_pinned(n) != op_pin_state_pinned) || + (get_irn_op(get_Call_mem(n)) == op_NoMem) || (get_irn_op(get_Call_mem(n)) != op_NoMem && get_irn_pinned(n) == op_pin_state_pinned), "Call node with wrong memory input", 0 ); @@ -1548,14 +1570,89 @@ static int verify_node_Mux(ir_node *n, ir_graph *irg) { return 1; } +/** + * verify a CopyB node + */ +static int verify_node_CopyB(ir_node *n, ir_graph *irg) { + ir_mode *mymode = get_irn_mode(n); + ir_mode *op1mode = get_irn_mode(get_CopyB_mem(n)); + ir_mode *op2mode = get_irn_mode(get_CopyB_dst(n)); + ir_mode *op3mode = get_irn_mode(get_CopyB_src(n)); + type *t = get_CopyB_type(n); + + /* CopyB: BB x M x ref x ref --> M x X */ + ASSERT_AND_RET( + mymode == mode_T && + op1mode == mode_M && + mode_is_reference(op2mode) && + mode_is_reference(op3mode), + "CopyB node", 0 ); /* operand M x ref x ref */ + + ASSERT_AND_RET( + is_compound_type(t), + "CopyB node should copy compound types only", 0 ); + + /* NoMem nodes are only allowed as memory input if the CopyB is NOT pinned. + This should happen RARELY, as CopyB COPIES MEMORY */ + ASSERT_AND_RET( + (get_irn_op(get_CopyB_mem(n)) == op_NoMem) || + (get_irn_op(get_CopyB_mem(n)) != op_NoMem && get_irn_pinned(n) == op_pin_state_pinned), + "CopyB node with wrong memory input", 0 ); + return 1; +} + +/* + * Check dominance. + * For each usage of a node, it is checked, if the block of the + * 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 *use) +{ + /* 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 = 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; + + /* ignore dead definition blocks, will be removed */ + if (is_Block_dead(def_bl) || get_Block_dom_depth(def_bl) == -1) + continue; + + if (is_Phi(use)) + use_bl = get_Block_cfgpred_block(bl, i); + + /* 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; +} + +/* Tests the modes of n and its predecessors. */ int irn_vrfy_irg(ir_node *n, ir_graph *irg) { int i; ir_op *op; - if (!opt_do_node_verification) return 1; + if (!opt_do_node_verification) + return 1; - if (! get_interprocedural_view()) { + if (!get_interprocedural_view()) { /* * do NOT check placement in interprocedural view, as we don't always know * the "right" graph ... @@ -1598,15 +1695,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 dominance info is available. + */ +static void vrfy_wrap_ssa(ir_node *node, void *env) { int *res = env; *res = irn_vrfy(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 @@ -1616,9 +1734,18 @@ int irg_vrfy(ir_graph *irg) current_ir_graph = irg; last_irg_error = NULL; - assert(get_irg_pinned(irg) == op_pin_state_pinned); + assert(get_irg_pinned(irg) == op_pin_state_pinned && "Verification need pinned graph"); - 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; @@ -1630,8 +1757,8 @@ int irg_vrfy(ir_graph *irg) else fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph); } +#endif /* DEBUG_libfirm */ -#endif return res; } @@ -1643,6 +1770,9 @@ int irn_vrfy_irg_dump(ir_node *n, ir_graph *irg, const char **bad_string) firm_vrfy_failure_msg = NULL; opt_do_node_verification = NODE_VERIFICATION_ERROR_ONLY; res = irn_vrfy_irg(n, irg); + if (! res && get_irg_dom_state(irg) == dom_consistent && + get_irg_pinned(irg) == op_pin_state_pinned) + res = check_dominance_for_node(n); opt_do_node_verification = old; *bad_string = firm_vrfy_failure_msg; @@ -1655,6 +1785,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; @@ -1775,6 +1908,7 @@ void firm_set_default_verifyer(ir_op *op) CASE(Block); CASE(Start); CASE(Jmp); + CASE(IJmp); CASE(Break); CASE(Cond); CASE(Return); @@ -1813,6 +1947,7 @@ void firm_set_default_verifyer(ir_op *op) CASE(Sync); CASE(Confirm); CASE(Mux); + CASE(CopyB); default: op->verify_node = NULL; }