changeset 11746:661e10237142

FloatingReadPhase: add interface to access memory state
author Bernhard Urban <bernhard.urban@jku.at>
date Thu, 19 Sep 2013 21:53:20 +0200
parents ea4e9cbaa0c9
children a66ecc6a6393
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryMap.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java
diffstat 2 files changed, 65 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryMap.java	Thu Sep 19 21:53:20 2013 +0200
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.graph.*;
+
+public interface MemoryMap {
+
+    Node getLastLocationAccess(LocationIdentity locationIdentity);
+}
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java	Thu Sep 19 21:53:20 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java	Thu Sep 19 21:53:20 2013 +0200
@@ -27,6 +27,7 @@
 import java.util.*;
 
 import com.oracle.graal.api.meta.*;
+import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.PhiNode.PhiType;
 import com.oracle.graal.nodes.extended.*;
@@ -37,24 +38,25 @@
 
 public class FloatingReadPhase extends Phase {
 
-    private static class MemoryMap {
+    public static class MemoryMapImpl implements MemoryMap {
 
         private IdentityHashMap<LocationIdentity, ValueNode> lastMemorySnapshot;
 
-        public MemoryMap(MemoryMap memoryMap) {
+        public MemoryMapImpl(MemoryMapImpl memoryMap) {
             lastMemorySnapshot = new IdentityHashMap<>(memoryMap.lastMemorySnapshot);
         }
 
-        public MemoryMap(StartNode start) {
+        public MemoryMapImpl(StartNode start) {
             this();
             lastMemorySnapshot.put(ANY_LOCATION, start);
         }
 
-        public MemoryMap() {
+        public MemoryMapImpl() {
             lastMemorySnapshot = new IdentityHashMap<>();
         }
 
-        private ValueNode getLastLocationAccess(LocationIdentity locationIdentity) {
+        @Override
+        public ValueNode getLastLocationAccess(LocationIdentity locationIdentity) {
             ValueNode lastLocationAccess;
             if (locationIdentity == FINAL_LOCATION) {
                 return null;
@@ -78,7 +80,7 @@
     protected void run(StructuredGraph graph) {
         Map<LoopBeginNode, Set<LocationIdentity>> modifiedInLoops = new IdentityHashMap<>();
         ReentrantNodeIterator.apply(new CollectMemoryCheckpointsClosure(modifiedInLoops), graph.start(), new HashSet<LocationIdentity>(), null);
-        ReentrantNodeIterator.apply(new FloatingReadClosure(modifiedInLoops), graph.start(), new MemoryMap(graph.start()), null);
+        ReentrantNodeIterator.apply(new FloatingReadClosure(modifiedInLoops), graph.start(), new MemoryMapImpl(graph.start()), null);
     }
 
     private static class CollectMemoryCheckpointsClosure extends NodeIteratorClosure<Set<LocationIdentity>> {
@@ -133,7 +135,7 @@
 
     }
 
-    private static class FloatingReadClosure extends NodeIteratorClosure<MemoryMap> {
+    private static class FloatingReadClosure extends NodeIteratorClosure<MemoryMapImpl> {
 
         private final Map<LoopBeginNode, Set<LocationIdentity>> modifiedInLoops;
 
@@ -142,7 +144,7 @@
         }
 
         @Override
-        protected MemoryMap processNode(FixedNode node, MemoryMap state) {
+        protected MemoryMapImpl processNode(FixedNode node, MemoryMapImpl state) {
             if (node instanceof FloatableAccessNode) {
                 processFloatable((FloatableAccessNode) node, state);
             } else if (node instanceof MemoryCheckpoint.Single) {
@@ -151,27 +153,28 @@
                 processCheckpoint((MemoryCheckpoint.Multi) node, state);
             }
             assert MemoryCheckpoint.TypeAssertion.correctType(node) : node;
+
             return state;
         }
 
-        private static void processCheckpoint(MemoryCheckpoint.Single checkpoint, MemoryMap state) {
-            LocationIdentity identity = checkpoint.getLocationIdentity();
+        private static void processCheckpoint(MemoryCheckpoint.Single checkpoint, MemoryMapImpl state) {
+            processIdentity(checkpoint.getLocationIdentity(), checkpoint, state);
+        }
+
+        private static void processCheckpoint(MemoryCheckpoint.Multi checkpoint, MemoryMapImpl state) {
+            for (LocationIdentity identity : checkpoint.getLocationIdentities()) {
+                processIdentity(identity, checkpoint, state);
+            }
+        }
+
+        private static void processIdentity(LocationIdentity identity, MemoryCheckpoint checkpoint, MemoryMapImpl state) {
             if (identity == ANY_LOCATION) {
                 state.lastMemorySnapshot.clear();
             }
             state.lastMemorySnapshot.put(identity, (ValueNode) checkpoint);
         }
 
-        private static void processCheckpoint(MemoryCheckpoint.Multi checkpoint, MemoryMap state) {
-            for (LocationIdentity identity : checkpoint.getLocationIdentities()) {
-                if (identity == ANY_LOCATION) {
-                    state.lastMemorySnapshot.clear();
-                }
-                state.lastMemorySnapshot.put(identity, (ValueNode) checkpoint);
-            }
-        }
-
-        private static void processFloatable(FloatableAccessNode accessNode, MemoryMap state) {
+        private static void processFloatable(FloatableAccessNode accessNode, MemoryMapImpl state) {
             StructuredGraph graph = accessNode.graph();
             assert accessNode.getNullCheck() == false;
             LocationIdentity locationIdentity = accessNode.location().getLocationIdentity();
@@ -190,11 +193,11 @@
         }
 
         @Override
-        protected MemoryMap merge(MergeNode merge, List<MemoryMap> states) {
-            MemoryMap newState = new MemoryMap();
+        protected MemoryMapImpl merge(MergeNode merge, List<MemoryMapImpl> states) {
+            MemoryMapImpl newState = new MemoryMapImpl();
 
             Set<LocationIdentity> keys = new HashSet<>();
-            for (MemoryMap other : states) {
+            for (MemoryMapImpl other : states) {
                 keys.addAll(other.lastMemorySnapshot.keySet());
             }
             assert !keys.contains(FINAL_LOCATION);
@@ -203,7 +206,7 @@
                 int mergedStatesCount = 0;
                 boolean isPhi = false;
                 ValueNode merged = null;
-                for (MemoryMap state : states) {
+                for (MemoryMapImpl state : states) {
                     ValueNode last = state.getLastLocationAccess(key);
                     if (isPhi) {
                         ((PhiNode) merged).addInput(last);
@@ -230,8 +233,8 @@
         }
 
         @Override
-        protected MemoryMap afterSplit(AbstractBeginNode node, MemoryMap oldState) {
-            MemoryMap result = new MemoryMap(oldState);
+        protected MemoryMapImpl afterSplit(AbstractBeginNode node, MemoryMapImpl oldState) {
+            MemoryMapImpl result = new MemoryMapImpl(oldState);
             if (node.predecessor() instanceof InvokeWithExceptionNode) {
                 /*
                  * InvokeWithException cannot be the lastLocationAccess for a FloatingReadNode.
@@ -247,7 +250,7 @@
         }
 
         @Override
-        protected Map<LoopExitNode, MemoryMap> processLoop(LoopBeginNode loop, MemoryMap initialState) {
+        protected Map<LoopExitNode, MemoryMapImpl> processLoop(LoopBeginNode loop, MemoryMapImpl initialState) {
             Set<LocationIdentity> modifiedLocations = modifiedInLoops.get(loop);
             if (modifiedLocations.contains(ANY_LOCATION)) {
                 // create phis for all locations if ANY is modified in the loop
@@ -263,9 +266,9 @@
                 initialState.lastMemorySnapshot.put(location, phi);
             }
 
-            LoopInfo<MemoryMap> loopInfo = ReentrantNodeIterator.processLoop(this, loop, initialState);
+            LoopInfo<MemoryMapImpl> loopInfo = ReentrantNodeIterator.processLoop(this, loop, initialState);
 
-            for (Map.Entry<LoopEndNode, MemoryMap> entry : loopInfo.endStates.entrySet()) {
+            for (Map.Entry<LoopEndNode, MemoryMapImpl> entry : loopInfo.endStates.entrySet()) {
                 int endIndex = loop.phiPredecessorIndex(entry.getKey());
                 for (Map.Entry<LocationIdentity, PhiNode> phiEntry : phis.entrySet()) {
                     LocationIdentity key = phiEntry.getKey();
@@ -273,9 +276,9 @@
                     phi.initializeValueAt(endIndex, entry.getValue().getLastLocationAccess(key));
                 }
             }
-            for (Map.Entry<LoopExitNode, MemoryMap> entry : loopInfo.exitStates.entrySet()) {
+            for (Map.Entry<LoopExitNode, MemoryMapImpl> entry : loopInfo.exitStates.entrySet()) {
                 LoopExitNode exit = entry.getKey();
-                MemoryMap state = entry.getValue();
+                MemoryMapImpl state = entry.getValue();
                 for (LocationIdentity location : modifiedLocations) {
                     ValueNode lastAccessAtExit = state.lastMemorySnapshot.get(location);
                     if (lastAccessAtExit != null) {