--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/FloatingReadPhase.java Thu Oct 31 14:23:06 2019 -0700
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/FloatingReadPhase.java Thu Oct 31 16:54:16 2019 -0700
@@ -48,6 +48,7 @@
import org.graalvm.compiler.nodes.LoopEndNode;
import org.graalvm.compiler.nodes.LoopExitNode;
import org.graalvm.compiler.nodes.PhiNode;
+import org.graalvm.compiler.nodes.ProxyNode;
import org.graalvm.compiler.nodes.ReturnNode;
import org.graalvm.compiler.nodes.StartNode;
import org.graalvm.compiler.nodes.StructuredGraph;
@@ -166,9 +167,9 @@
protected void processNode(FixedNode node, EconomicSet<LocationIdentity> currentState) {
if (node instanceof MemoryCheckpoint.Single) {
- processIdentity(currentState, ((MemoryCheckpoint.Single) node).getLocationIdentity());
+ processIdentity(currentState, ((MemoryCheckpoint.Single) node).getKilledLocationIdentity());
} else if (node instanceof MemoryCheckpoint.Multi) {
- for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getLocationIdentities()) {
+ for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getKilledLocationIdentities()) {
processIdentity(currentState, identity);
}
}
@@ -274,7 +275,7 @@
}
mergedStatesCount++;
}
- newState.lastMemorySnapshot.put(key, merged);
+ newState.getMap().put(key, merged);
}
return newState;
@@ -301,6 +302,16 @@
@Override
protected MemoryMapImpl processNode(FixedNode node, MemoryMapImpl state) {
+
+ if (node instanceof LoopExitNode) {
+ final LoopExitNode loopExitNode = (LoopExitNode) node;
+ final EconomicSet<LocationIdentity> modifiedInLoop = modifiedInLoops.get(loopExitNode.loopBegin());
+ final boolean anyModified = modifiedInLoop.contains(LocationIdentity.any());
+ state.getMap().replaceAll((locationIdentity, memoryNode) -> (anyModified || modifiedInLoop.contains(locationIdentity))
+ ? ProxyNode.forMemory(memoryNode, loopExitNode, locationIdentity)
+ : memoryNode);
+ }
+
if (node instanceof MemoryAnchorNode) {
processAnchor((MemoryAnchorNode) node, state);
return state;
@@ -312,7 +323,8 @@
if (createFloatingReads && node instanceof FloatableAccessNode) {
processFloatable((FloatableAccessNode) node, state);
- } else if (node instanceof MemoryCheckpoint.Single) {
+ }
+ if (node instanceof MemoryCheckpoint.Single) {
processCheckpoint((MemoryCheckpoint.Single) node, state);
} else if (node instanceof MemoryCheckpoint.Multi) {
processCheckpoint((MemoryCheckpoint.Multi) node, state);
@@ -320,7 +332,7 @@
assert MemoryCheckpoint.TypeAssertion.correctType(node) : node;
if (createMemoryMapNodes && node instanceof ReturnNode) {
- ((ReturnNode) node).setMemoryMap(node.graph().unique(new MemoryMapNode(state.lastMemorySnapshot)));
+ ((ReturnNode) node).setMemoryMap(node.graph().unique(new MemoryMapNode(state.getMap())));
}
return state;
}
@@ -355,21 +367,21 @@
}
private static void processCheckpoint(MemoryCheckpoint.Single checkpoint, MemoryMapImpl state) {
- processIdentity(checkpoint.getLocationIdentity(), checkpoint, state);
+ processIdentity(checkpoint.getKilledLocationIdentity(), checkpoint, state);
}
private static void processCheckpoint(MemoryCheckpoint.Multi checkpoint, MemoryMapImpl state) {
- for (LocationIdentity identity : checkpoint.getLocationIdentities()) {
+ for (LocationIdentity identity : checkpoint.getKilledLocationIdentities()) {
processIdentity(identity, checkpoint, state);
}
}
private static void processIdentity(LocationIdentity identity, MemoryCheckpoint checkpoint, MemoryMapImpl state) {
if (identity.isAny()) {
- state.lastMemorySnapshot.clear();
+ state.getMap().clear();
}
if (identity.isMutable()) {
- state.lastMemorySnapshot.put(identity, checkpoint);
+ state.getMap().put(identity, checkpoint);
}
}
@@ -405,7 +417,7 @@
* side it needs to choose by putting in the location identity on both successors.
*/
InvokeWithExceptionNode invoke = (InvokeWithExceptionNode) node.predecessor();
- result.lastMemorySnapshot.put(invoke.getLocationIdentity(), (MemoryCheckpoint) node);
+ result.getMap().put(invoke.getKilledLocationIdentity(), (MemoryCheckpoint) node);
}
return result;
}
@@ -417,13 +429,13 @@
if (modifiedLocations.contains(LocationIdentity.any())) {
// create phis for all locations if ANY is modified in the loop
modifiedLocations = EconomicSet.create(Equivalence.DEFAULT, modifiedLocations);
- modifiedLocations.addAll(initialState.lastMemorySnapshot.getKeys());
+ modifiedLocations.addAll(initialState.getMap().getKeys());
}
for (LocationIdentity location : modifiedLocations) {
createMemoryPhi(loop, initialState, phis, location);
}
- initialState.lastMemorySnapshot.putAll(phis);
+ initialState.getMap().putAll(phis);
LoopInfo<MemoryMapImpl> loopInfo = ReentrantNodeIterator.processLoop(this, loop, initialState);