changeset 16237:0e5e4628fca7

let AddLocationNode implement Canonicalizable.Binary
author Lukas Stadler <lukas.stadler@oracle.com>
date Thu, 26 Jun 2014 09:53:59 +0200
parents 197ae7ce6bf8
children db5b41891078
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/AddLocationNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ConstantLocationNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IndexedLocationNode.java
diffstat 3 files changed, 24 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/AddLocationNode.java	Thu Jun 26 09:45:28 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/AddLocationNode.java	Thu Jun 26 09:53:59 2014 +0200
@@ -36,16 +36,16 @@
  * [(base + x) + y] where base is a node and x and y are location nodes.
  */
 @NodeInfo(nameTemplate = "AddLoc {p#locationIdentity/s}")
-public final class AddLocationNode extends LocationNode implements Canonicalizable {
+public final class AddLocationNode extends LocationNode implements Canonicalizable.Binary<LocationNode> {
 
     @Input(InputType.Association) private ValueNode x;
     @Input(InputType.Association) private ValueNode y;
 
-    protected LocationNode getX() {
+    public LocationNode getX() {
         return (LocationNode) x;
     }
 
-    protected LocationNode getY() {
+    public LocationNode getY() {
         return (LocationNode) y;
     }
 
@@ -70,21 +70,20 @@
         return getX().getLocationIdentity();
     }
 
-    @Override
-    public Node canonical(CanonicalizerTool tool) {
-        if (x instanceof ConstantLocationNode) {
-            return canonical((ConstantLocationNode) x, getY());
+    public LocationNode canonical(CanonicalizerTool tool, LocationNode forX, LocationNode forY) {
+        if (forX instanceof ConstantLocationNode) {
+            return canonical((ConstantLocationNode) forX, forY);
         }
-        if (y instanceof ConstantLocationNode) {
-            return canonical((ConstantLocationNode) y, getX());
+        if (forY instanceof ConstantLocationNode) {
+            return canonical((ConstantLocationNode) forY, forX);
         }
-        if (x instanceof IndexedLocationNode && y instanceof IndexedLocationNode) {
-            IndexedLocationNode xIdx = (IndexedLocationNode) x;
-            IndexedLocationNode yIdx = (IndexedLocationNode) y;
+        if (forX instanceof IndexedLocationNode && forY instanceof IndexedLocationNode) {
+            IndexedLocationNode xIdx = (IndexedLocationNode) forX;
+            IndexedLocationNode yIdx = (IndexedLocationNode) forY;
             if (xIdx.getIndexScaling() == yIdx.getIndexScaling()) {
                 long displacement = xIdx.getDisplacement() + yIdx.getDisplacement();
-                ValueNode index = IntegerArithmeticNode.add(graph(), xIdx.getIndex(), yIdx.getIndex());
-                return IndexedLocationNode.create(getLocationIdentity(), getValueKind(), displacement, index, graph(), xIdx.getIndexScaling());
+                ValueNode index = IntegerArithmeticNode.add(xIdx.getIndex(), yIdx.getIndex());
+                return IndexedLocationNode.create(getLocationIdentity(), getValueKind(), displacement, index, xIdx.getIndexScaling());
             }
         }
         return this;
@@ -93,15 +92,15 @@
     private LocationNode canonical(ConstantLocationNode constant, LocationNode other) {
         if (other instanceof ConstantLocationNode) {
             ConstantLocationNode otherConst = (ConstantLocationNode) other;
-            return ConstantLocationNode.create(getLocationIdentity(), getValueKind(), otherConst.getDisplacement() + constant.getDisplacement(), graph());
+            return ConstantLocationNode.create(getLocationIdentity(), getValueKind(), otherConst.getDisplacement() + constant.getDisplacement());
         } else if (other instanceof IndexedLocationNode) {
             IndexedLocationNode otherIdx = (IndexedLocationNode) other;
-            return IndexedLocationNode.create(getLocationIdentity(), getValueKind(), otherIdx.getDisplacement() + constant.getDisplacement(), otherIdx.getIndex(), graph(), otherIdx.getIndexScaling());
+            return IndexedLocationNode.create(getLocationIdentity(), getValueKind(), otherIdx.getDisplacement() + constant.getDisplacement(), otherIdx.getIndex(), otherIdx.getIndexScaling());
         } else if (other instanceof AddLocationNode) {
             AddLocationNode otherAdd = (AddLocationNode) other;
             LocationNode newInner = otherAdd.canonical(constant, otherAdd.getX());
             if (newInner != otherAdd) {
-                return AddLocationNode.create(newInner, otherAdd.getY(), graph());
+                return new AddLocationNode(newInner, otherAdd.getY());
             }
         }
         return this;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ConstantLocationNode.java	Thu Jun 26 09:45:28 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ConstantLocationNode.java	Thu Jun 26 09:53:59 2014 +0200
@@ -43,6 +43,10 @@
         return graph.unique(new ConstantLocationNode(identity, kind, displacement));
     }
 
+    public static ConstantLocationNode create(LocationIdentity identity, Kind kind, long displacement) {
+        return new ConstantLocationNode(identity, kind, displacement);
+    }
+
     private ConstantLocationNode(LocationIdentity identity, Kind kind, long displacement) {
         super(StampFactory.forVoid());
         assert kind != Kind.Illegal && kind != Kind.Void;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IndexedLocationNode.java	Thu Jun 26 09:45:28 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IndexedLocationNode.java	Thu Jun 26 09:53:59 2014 +0200
@@ -66,6 +66,10 @@
         return graph.unique(new IndexedLocationNode(identity, kind, displacement, index, indexScaling));
     }
 
+    public static IndexedLocationNode create(LocationIdentity identity, Kind kind, long displacement, ValueNode index, int indexScaling) {
+        return new IndexedLocationNode(identity, kind, displacement, index, indexScaling);
+    }
+
     public IndexedLocationNode(LocationIdentity identity, Kind kind, long displacement, ValueNode index, int indexScaling) {
         super(StampFactory.forVoid());
         assert kind != Kind.Illegal && kind != Kind.Void;