diff graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java @ 15002:06e50d290784

isAllowedUsageType on Nodes
author Lukas Stadler <lukas.stadler@oracle.com>
date Mon, 07 Apr 2014 11:32:08 +0200
parents 27c04ee36dcb
children 9a73164832a9
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java	Mon Apr 07 11:32:04 2014 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java	Mon Apr 07 11:32:08 2014 +0200
@@ -136,6 +136,8 @@
     private static final int INLINE_USAGE_COUNT = 2;
     private static final Node[] NO_NODES = {};
 
+    private static final boolean VERIFY_TYPES = true;
+
     /**
      * Head of usage list. The elements of the usage list in order are {@link #usage0},
      * {@link #usage1} and {@link #extraUsages}. The first null entry terminates the list.
@@ -512,6 +514,10 @@
         return NodeClass.get(getClass());
     }
 
+    public boolean isAllowedUsageType(InputType type) {
+        return getNodeClass().getAllowedUsageTypes().contains(type);
+    }
+
     private boolean checkReplaceWith(Node other) {
         assert assertTrue(graph == null || !graph.isFrozen(), "cannot modify frozen graph");
         assert assertFalse(other == this, "cannot replace a node with itself");
@@ -738,6 +744,16 @@
             for (Node usage : usages()) {
                 assertFalse(usage.isDeleted(), "usage %s must never be deleted", usage);
                 assertTrue(usage.inputs().contains(this), "missing input in usage %s", usage);
+                if (VERIFY_TYPES) {
+                    NodeClassIterator iterator = usage.inputs().iterator();
+                    while (iterator.hasNext()) {
+                        Position pos = iterator.nextPosition();
+                        if (pos.get(usage) == this && pos.getInputType(usage) != InputType.Unchecked) {
+                            assert isAllowedUsageType(pos.getInputType(usage)) : "invalid input of type " + pos.getInputType(usage) + " from " + usage + " to " + this + " (" +
+                                            pos.getInputName(usage) + ")";
+                        }
+                    }
+                }
             }
         }
         if (predecessor != null) {