changeset 12722:b87c2f34e0e0

Maintain lastLocationAccess in WriteNode.
author Roland Schatz <roland.schatz@oracle.com>
date Fri, 08 Nov 2013 13:22:03 +0100
parents dac9c1783aed
children bbf6407458ee
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingAccessNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingReadNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/MemoryAccess.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/WriteNode.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ReadEliminationPhase.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java
diffstat 8 files changed, 80 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingAccessNode.java	Fri Nov 08 13:20:34 2013 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingAccessNode.java	Fri Nov 08 13:22:03 2013 +0100
@@ -22,10 +22,11 @@
  */
 package com.oracle.graal.nodes.extended;
 
+import com.oracle.graal.api.meta.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.type.*;
 
-public abstract class FloatingAccessNode extends FloatingGuardedNode implements Access {
+public abstract class FloatingAccessNode extends FloatingGuardedNode implements Access, MemoryAccess {
 
     @Input private ValueNode object;
     @Input private LocationNode location;
@@ -46,6 +47,10 @@
         return location;
     }
 
+    public LocationIdentity getLocationIdentity() {
+        return location.getLocationIdentity();
+    }
+
     public boolean getNullCheck() {
         return nullCheck;
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingReadNode.java	Fri Nov 08 13:20:34 2013 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingReadNode.java	Fri Nov 08 13:22:03 2013 +0100
@@ -51,7 +51,7 @@
         this.lastLocationAccess = lastLocationAccess;
     }
 
-    public Node lastLocationAccess() {
+    public Node getLastLocationAccess() {
         return lastLocationAccess;
     }
 
@@ -90,7 +90,7 @@
 
     @Override
     public boolean verify() {
-        Node lla = lastLocationAccess();
+        Node lla = getLastLocationAccess();
         assert lla == null || isMemoryCheckPoint(lla) || isMemoryPhi(lla) || isMemoryProxy(lla) : "lastLocationAccess of " + this + " should be a MemoryCheckpoint, but is " + lla;
         return super.verify();
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/MemoryAccess.java	Fri Nov 08 13:22:03 2013 +0100
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.nodes.extended;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.graph.*;
+
+/**
+ * This interface marks nodes that access some memory location, and that have an edge to the last
+ * node that kills this location.
+ */
+public interface MemoryAccess {
+
+    LocationIdentity getLocationIdentity();
+
+    Node getLastLocationAccess();
+
+    void setLastLocationAccess(Node lla);
+}
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/WriteNode.java	Fri Nov 08 13:20:34 2013 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/WriteNode.java	Fri Nov 08 13:22:03 2013 +0100
@@ -23,6 +23,7 @@
 package com.oracle.graal.nodes.extended;
 
 import com.oracle.graal.api.meta.*;
+import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.extended.LocationNode.Location;
 import com.oracle.graal.nodes.spi.*;
@@ -32,12 +33,14 @@
 /**
  * Writes a given {@linkplain #value() value} a {@linkplain AccessNode memory location}.
  */
-public final class WriteNode extends AccessNode implements StateSplit, LIRLowerable, MemoryCheckpoint.Single, Virtualizable {
+public final class WriteNode extends AccessNode implements StateSplit, LIRLowerable, MemoryCheckpoint.Single, MemoryAccess, Virtualizable {
 
     @Input private ValueNode value;
     @Input(notDataflow = true) private FrameState stateAfter;
     private final boolean initialization;
 
+    @Input private Node lastLocationAccess;
+
     public FrameState stateAfter() {
         return stateAfter;
     }
@@ -89,6 +92,15 @@
         return location().getLocationIdentity();
     }
 
+    public Node getLastLocationAccess() {
+        return lastLocationAccess;
+    }
+
+    public void setLastLocationAccess(Node lla) {
+        updateUsages(lastLocationAccess, lla);
+        lastLocationAccess = lla;
+    }
+
     @Override
     public void virtualize(VirtualizerTool tool) {
         if (location() instanceof ConstantLocationNode) {
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java	Fri Nov 08 13:20:34 2013 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java	Fri Nov 08 13:22:03 2013 +0100
@@ -176,6 +176,10 @@
 
         @Override
         protected MemoryMapImpl processNode(FixedNode node, MemoryMapImpl state) {
+            if (node instanceof MemoryAccess) {
+                processAccess((MemoryAccess) node, state);
+            }
+
             if (node instanceof FloatableAccessNode && execmode == ExecutionMode.CREATE_FLOATING_READS) {
                 processFloatable((FloatableAccessNode) node, state);
             } else if (node instanceof MemoryCheckpoint.Single) {
@@ -191,6 +195,14 @@
             return state;
         }
 
+        private static void processAccess(MemoryAccess access, MemoryMapImpl state) {
+            LocationIdentity locationIdentity = access.getLocationIdentity();
+            if (locationIdentity != LocationIdentity.ANY_LOCATION) {
+                ValueNode lastLocationAccess = state.getLastLocationAccess(locationIdentity);
+                access.setLastLocationAccess(lastLocationAccess);
+            }
+        }
+
         private static void processCheckpoint(MemoryCheckpoint.Single checkpoint, MemoryMapImpl state) {
             processIdentity(checkpoint.getLocationIdentity(), checkpoint, state);
         }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ReadEliminationPhase.java	Fri Nov 08 13:20:34 2013 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ReadEliminationPhase.java	Fri Nov 08 13:22:03 2013 +0100
@@ -35,7 +35,7 @@
         for (FloatingReadNode n : graph.getNodes(FloatingReadNode.class)) {
             if (isReadEliminable(n)) {
                 NodeMap<ValueNode> nodeMap = n.graph().createNodeMap();
-                ValueNode value = getValue(n, n.lastLocationAccess(), nodeMap);
+                ValueNode value = getValue(n, n.getLastLocationAccess(), nodeMap);
                 Debug.log("Eliminated memory read %1.1s and replaced with node %s", n, value);
                 graph.replaceFloating(n, value);
             }
@@ -43,7 +43,7 @@
     }
 
     private static boolean isReadEliminable(FloatingReadNode n) {
-        return isWrites(n, n.lastLocationAccess(), n.graph().createNodeBitMap());
+        return isWrites(n, n.getLastLocationAccess(), n.graph().createNodeBitMap());
     }
 
     private static boolean isWrites(FloatingReadNode n, Node lastLocationAccess, NodeBitMap visited) {
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Fri Nov 08 13:20:34 2013 +0100
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Fri Nov 08 13:22:03 2013 +0100
@@ -347,7 +347,7 @@
                 if (n.location().getLocationIdentity() == FINAL_LOCATION) {
                     continue;
                 }
-                Node first = n.lastLocationAccess();
+                Node first = n.getLastLocationAccess();
                 assert first != null;
 
                 Map<LocationIdentity, Node> killMap = blockToKillMapInit.get(forKillLocation(first));
@@ -424,7 +424,7 @@
         } else if (n instanceof FloatingReadNode) {
             FloatingReadNode frn = (FloatingReadNode) n;
             Debug.printf(" // from %s", frn.location().getLocationIdentity());
-            Debug.printf(", lastAccess: %s", frn.lastLocationAccess());
+            Debug.printf(", lastAccess: %s", frn.getLastLocationAccess());
             Debug.printf(", object: %s", frn.object());
         } else if (n instanceof GuardNode) {
             Debug.printf(", guard: %s", ((GuardNode) n).getGuard());
@@ -544,7 +544,7 @@
         LocationIdentity locid = n.location().getLocationIdentity();
         assert locid != FINAL_LOCATION;
 
-        Node upperBound = n.lastLocationAccess();
+        Node upperBound = n.getLastLocationAccess();
         Block upperBoundBlock = forKillLocation(upperBound);
         Block earliestBlock = earliestBlock(n);
         assert upperBoundBlock.dominates(earliestBlock) : "upper bound (" + upperBoundBlock + ") should dominate earliest (" + earliestBlock + ")";
@@ -925,7 +925,7 @@
                     FloatingReadNode frn = (FloatingReadNode) i;
                     if (frn.location().getLocationIdentity() != FINAL_LOCATION) {
                         reads.add(frn);
-                        if (nodesFor(b).contains(frn.lastLocationAccess())) {
+                        if (nodesFor(b).contains(frn.getLastLocationAccess())) {
                             assert !beforeLastLocation.isMarked(frn);
                             beforeLastLocation.mark(frn);
                         }
@@ -970,7 +970,7 @@
         for (FloatingReadNode frn : new ArrayList<>(reads)) { // TODO: change to iterator?
             LocationIdentity readLocation = frn.location().getLocationIdentity();
             assert readLocation != FINAL_LOCATION;
-            if (frn.lastLocationAccess() == node) {
+            if (frn.getLastLocationAccess() == node) {
                 assert identity == ANY_LOCATION || readLocation == identity : "location doesn't match: " + readLocation + ", " + identity;
                 beforeLastLocation.clear(frn);
             } else if (!beforeLastLocation.isMarked(frn) && (readLocation == identity || (!(node instanceof StartNode) && ANY_LOCATION == identity))) {
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Fri Nov 08 13:20:34 2013 +0100
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Fri Nov 08 13:22:03 2013 +0100
@@ -824,7 +824,7 @@
                 return;
             }
             for (Node usage : newNode.usages().snapshot()) {
-                if (usage instanceof FloatingReadNode && ((FloatingReadNode) usage).lastLocationAccess() == newNode) {
+                if (usage instanceof FloatingReadNode && ((FloatingReadNode) usage).getLastLocationAccess() == newNode) {
                     assert newNode.graph().isAfterFloatingReadPhase();
 
                     // lastLocationAccess points into the snippet graph. find a proper