Dump calling conventions for entities
[libfirm] / ir / ir / irvrfy.c
index 5e0f72a..146c3ec 100644 (file)
@@ -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.
  */
 
@@ -22,6 +22,8 @@
 # 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;
@@ -827,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;
 }
 
@@ -1560,40 +1570,83 @@ 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 *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(get_irn_irg(irn))) {
-               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(block_dominates(def_bl, use_bl),
-                                       "the definition of a value used violates the dominance property", 0);
-               }
-       }
+      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;
+}
 
+/* Tests the modes of n and its predecessors. */
 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
 {
   int i;
-       int result = 1;
   ir_op *op;
 
   if (!opt_do_node_verification)
@@ -1616,24 +1669,17 @@ 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;
-               }
-
-       /*
-        * Check, if the dominance property is fulfilled
-        * for all operands of the node.
-        */
-       if(get_irg_dom_state(irg) == dom_consistent)
-               result &= check_dominance_for_node(n);
+  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)
-    result &= op->verify_node(n, irg);
+    return op->verify_node(n, irg);
 
   /* All went ok */
-  return result;
+  return 1;
 }
 
 int irn_vrfy(ir_node *n)
@@ -1649,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
@@ -1667,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;
 
@@ -1681,12 +1757,7 @@ int irg_vrfy(ir_graph *irg)
     else
       fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph);
   }
-
-       if(get_irg_dom_state(irg) == dom_consistent) {
-
-       }
-
-#endif
+#endif /* DEBUG_libfirm */
 
   return res;
 }
@@ -1699,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;
 
@@ -1711,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;
@@ -1870,6 +1947,7 @@ void firm_set_default_verifyer(ir_op *op)
    CASE(Sync);
    CASE(Confirm);
    CASE(Mux);
+   CASE(CopyB);
    default:
      op->verify_node = NULL;
    }