changeset 8655:ce271e0d0372

PiPushable: implementation for IsNullNode
author Bernhard Urban <bernhard.urban@jku.at>
date Fri, 05 Apr 2013 15:24:22 +0200
parents 3bbad4ec6510
children 369710426f74
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IsNullNode.java
diffstat 2 files changed, 31 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java	Thu Apr 04 16:03:08 2013 +0200
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java	Fri Apr 05 15:24:22 2013 +0200
@@ -29,8 +29,8 @@
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.debug.*;
-import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.calc.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.phases.common.*;
 
@@ -50,39 +50,43 @@
         B b = (B) a;
         long ret = b.x; // this can be moved before the checkcast
         ret += b.y;
+        // the null-check should be canonicalized with the null-check of the checkcast
+        ret += b != null ? 100 : 200;
         return ret;
     }
 
     @Test
     public void test1() {
-        test("test1Snippet");
-    }
-
-    private void test(final String snippet) {
+        final String snippet = "test1Snippet";
         Debug.scope("PushThroughPi", new DebugDumpScope(snippet), new Runnable() {
 
             public void run() {
-                StructuredGraph graph = parse(snippet);
-                new LoweringPhase(null, runtime(), new Assumptions(false)).apply(graph);
-                new CanonicalizerPhase(runtime(), null).apply(graph);
-                new PushNodesThroughPi().apply(graph);
-                new CanonicalizerPhase(runtime(), null).apply(graph);
+                StructuredGraph graph = compileTestSnippet(snippet);
 
-                for (Node n : graph.getNodes()) {
-                    if (n instanceof ReadNode) {
-                        ReadNode rn = (ReadNode) n;
-                        Object locId = rn.location().locationIdentity();
-                        if (locId instanceof ResolvedJavaField) {
-                            ResolvedJavaField field = (ResolvedJavaField) locId;
-                            if (field.getName().equals("x")) {
-                                Assert.assertTrue(rn.object() instanceof LocalNode);
-                            } else {
-                                Assert.assertTrue(rn.object() instanceof UnsafeCastNode);
-                            }
+                for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) {
+                    Object locId = rn.location().locationIdentity();
+                    if (locId instanceof ResolvedJavaField) {
+                        ResolvedJavaField field = (ResolvedJavaField) locId;
+                        if (field.getName().equals("x")) {
+                            Assert.assertTrue(rn.object() instanceof LocalNode);
+                        } else {
+                            Assert.assertTrue(rn.object() instanceof UnsafeCastNode);
                         }
                     }
                 }
+
+                Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1);
             }
         });
     }
+
+    private StructuredGraph compileTestSnippet(final String snippet) {
+        StructuredGraph graph = parse(snippet);
+        new LoweringPhase(null, runtime(), replacements, new Assumptions(false)).apply(graph);
+        new CanonicalizerPhase(runtime(), null).apply(graph);
+        new PushNodesThroughPi().apply(graph);
+        new CanonicalizerPhase(runtime(), null).apply(graph);
+
+        return graph;
+    }
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IsNullNode.java	Thu Apr 04 16:03:08 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IsNullNode.java	Fri Apr 05 15:24:22 2013 +0200
@@ -29,7 +29,7 @@
 /**
  * An IsNullNode will be true if the supplied value is null, and false if it is non-null.
  */
-public final class IsNullNode extends LogicNode implements Canonicalizable, LIRLowerable, Virtualizable {
+public final class IsNullNode extends LogicNode implements Canonicalizable, LIRLowerable, Virtualizable, PiPushable {
 
     @Input private ValueNode object;
 
@@ -78,4 +78,9 @@
             tool.replaceWithValue(LogicConstantNode.contradiction(graph()));
         }
     }
+
+    @Override
+    public void push(PiNode parent) {
+        replaceFirstInput(parent, parent.object());
+    }
 }