changeset 16224:68f16c1057d4

let LogicNegationNode and ShortCircuitNode implement Canonicalizable.Unary/Binary
author Lukas Stadler <lukas.stadler@oracle.com>
date Wed, 25 Jun 2014 16:55:01 +0200
parents 1434b835f0d3
children 69ab53db5080
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LogicNegationNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ShortCircuitOrNode.java
diffstat 2 files changed, 33 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LogicNegationNode.java	Wed Jun 25 16:55:01 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LogicNegationNode.java	Wed Jun 25 16:55:01 2014 +0200
@@ -28,7 +28,7 @@
 /**
  * Logic node that negates its argument.
  */
-public class LogicNegationNode extends LogicNode implements Canonicalizable {
+public class LogicNegationNode extends LogicNode implements Canonicalizable.Unary<LogicNode> {
 
     @Input(InputType.Condition) private LogicNode value;
 
@@ -41,9 +41,9 @@
     }
 
     @Override
-    public Node canonical(CanonicalizerTool tool) {
-        if (value instanceof LogicNegationNode) {
-            return ((LogicNegationNode) value).getValue();
+    public LogicNode canonical(CanonicalizerTool tool, LogicNode forValue) {
+        if (forValue instanceof LogicNegationNode) {
+            return ((LogicNegationNode) forValue).getValue();
         } else {
             return this;
         }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ShortCircuitOrNode.java	Wed Jun 25 16:55:01 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ShortCircuitOrNode.java	Wed Jun 25 16:55:01 2014 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
 import com.oracle.graal.graph.*;
 import com.oracle.graal.graph.spi.*;
 
-public class ShortCircuitOrNode extends LogicNode implements IterableNodeType, Canonicalizable {
+public class ShortCircuitOrNode extends LogicNode implements IterableNodeType, Canonicalizable.Binary<LogicNode> {
 
     @Input(InputType.Condition) private LogicNode x;
     @Input(InputType.Condition) private LogicNode y;
@@ -65,36 +65,40 @@
         return shortCircuitProbability;
     }
 
-    protected ShortCircuitOrNode canonicalizeNegation() {
-        LogicNode xCond = x;
+    protected ShortCircuitOrNode canonicalizeNegation(LogicNode forX, LogicNode forY) {
+        LogicNode xCond = forX;
         boolean xNeg = xNegated;
         while (xCond instanceof LogicNegationNode) {
             xCond = ((LogicNegationNode) xCond).getValue();
             xNeg = !xNeg;
         }
 
-        LogicNode yCond = y;
+        LogicNode yCond = forY;
         boolean yNeg = yNegated;
         while (yCond instanceof LogicNegationNode) {
             yCond = ((LogicNegationNode) yCond).getValue();
             yNeg = !yNeg;
         }
 
-        if (xCond != x || yCond != y) {
-            return graph().unique(new ShortCircuitOrNode(xCond, xNeg, yCond, yNeg, shortCircuitProbability));
+        if (xCond != forX || yCond != forY) {
+            return new ShortCircuitOrNode(xCond, xNeg, yCond, yNeg, shortCircuitProbability);
         } else {
-            return null;
+            return this;
         }
     }
 
     @Override
     public Node canonical(CanonicalizerTool tool) {
-        ShortCircuitOrNode ret = canonicalizeNegation();
-        if (ret != null) {
+        return canonical(tool, getX(), getY());
+    }
+
+    public LogicNode canonical(CanonicalizerTool tool, LogicNode forX, LogicNode forY) {
+        ShortCircuitOrNode ret = canonicalizeNegation(forX, forY);
+        if (ret != this) {
             return ret;
         }
 
-        if (getX() == getY()) {
+        if (forX == forY) {
             // @formatter:off
             //  a ||  a = a
             //  a || !a = true
@@ -104,40 +108,40 @@
             if (isXNegated()) {
                 if (isYNegated()) {
                     // !a || !a = !a
-                    return graph().unique(new LogicNegationNode(getX()));
+                    return new LogicNegationNode(forX);
                 } else {
                     // !a || a = true
-                    return LogicConstantNode.tautology(graph());
+                    return LogicConstantNode.tautology();
                 }
             } else {
                 if (isYNegated()) {
                     // a || !a = true
-                    return LogicConstantNode.tautology(graph());
+                    return LogicConstantNode.tautology();
                 } else {
                     // a || a = a
-                    return getX();
+                    return forX;
                 }
             }
         }
-        if (getX() instanceof LogicConstantNode) {
-            if (((LogicConstantNode) getX()).getValue() ^ isXNegated()) {
-                return LogicConstantNode.tautology(graph());
+        if (forX instanceof LogicConstantNode) {
+            if (((LogicConstantNode) forX).getValue() ^ isXNegated()) {
+                return LogicConstantNode.tautology();
             } else {
                 if (isYNegated()) {
-                    return graph().unique(new LogicNegationNode(getY()));
+                    return new LogicNegationNode(forY);
                 } else {
-                    return getY();
+                    return forY;
                 }
             }
         }
-        if (getY() instanceof LogicConstantNode) {
-            if (((LogicConstantNode) getY()).getValue() ^ isYNegated()) {
-                return LogicConstantNode.tautology(graph());
+        if (forY instanceof LogicConstantNode) {
+            if (((LogicConstantNode) forY).getValue() ^ isYNegated()) {
+                return LogicConstantNode.tautology();
             } else {
                 if (isXNegated()) {
-                    return graph().unique(new LogicNegationNode(getX()));
+                    return new LogicNegationNode(forX);
                 } else {
-                    return getX();
+                    return forX;
                 }
             }
         }