# HG changeset patch # User Thomas Wuerthinger # Date 1422371766 -3600 # Node ID b648ac155f1b09ebbfa3f396c9b0b5656457aa61 # Parent e349dfa54db151b85272ce5a8d1e2b401c4a0d6c Only cache in MergeProcessor of PEA when processing loop begin blocks. diff -r e349dfa54db1 -r b648ac155f1b graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PEReadEliminationClosure.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PEReadEliminationClosure.java Tue Jan 27 16:01:48 2015 +0100 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PEReadEliminationClosure.java Tue Jan 27 16:16:06 2015 +0100 @@ -190,7 +190,7 @@ } } if (phi) { - PhiNode phiNode = getCachedPhi(entry, value.stamp().unrestricted()); + PhiNode phiNode = getPhi(entry, value.stamp().unrestricted()); mergeEffects.addFloatingNode(phiNode, "mergeReadCache"); for (int i = 0; i < states.size(); i++) { afterMergeEffects.addPhiInput(phiNode, states.get(i).getReadCache(key.object, key.identity, PEReadEliminationClosure.this)); @@ -222,7 +222,7 @@ values[i] = value; } - PhiNode phiNode = getCachedPhi(new ReadCacheEntry(identity, phi), values[0].stamp().unrestricted()); + PhiNode phiNode = getPhi(new ReadCacheEntry(identity, phi), values[0].stamp().unrestricted()); mergeEffects.addFloatingNode(phiNode, "mergeReadCachePhi"); for (int i = 0; i < values.length; i++) { afterMergeEffects.addPhiInput(phiNode, values[i]); diff -r e349dfa54db1 -r b648ac155f1b graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java Tue Jan 27 16:01:48 2015 +0100 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java Tue Jan 27 16:16:06 2015 +0100 @@ -313,15 +313,28 @@ protected class MergeProcessor extends EffectsClosure.MergeProcessor { - private final HashMap materializedPhis = CollectionsFactory.newMap(); - private final Map valuePhis = Node.newIdentityMap(); - private final Map valueObjectVirtuals = Node.newIdentityMap(); + private HashMap materializedPhis; + private Map valuePhis; + private Map valueObjectVirtuals; + private final boolean needsCaching; public MergeProcessor(Block mergeBlock) { super(mergeBlock); + needsCaching = mergeBlock.isLoopHeader(); } - protected PhiNode getCachedPhi(T virtual, Stamp stamp) { + protected PhiNode getPhi(T virtual, Stamp stamp) { + if (needsCaching) { + return getPhiCached(virtual, stamp); + } else { + return new ValuePhiNode(stamp, merge); + } + } + + private PhiNode getPhiCached(T virtual, Stamp stamp) { + if (materializedPhis == null) { + materializedPhis = CollectionsFactory.newMap(); + } ValuePhiNode result = materializedPhis.get(virtual); if (result == null) { result = new ValuePhiNode(stamp, merge); @@ -331,6 +344,17 @@ } private PhiNode[] getValuePhis(ValueNode key, int entryCount) { + if (needsCaching) { + return getValuePhisCached(key, entryCount); + } else { + return new ValuePhiNode[entryCount]; + } + } + + private PhiNode[] getValuePhisCached(ValueNode key, int entryCount) { + if (valuePhis == null) { + valuePhis = Node.newIdentityMap(); + } ValuePhiNode[] result = valuePhis.get(key); if (result == null) { result = new ValuePhiNode[entryCount]; @@ -341,6 +365,17 @@ } private VirtualObjectNode getValueObjectVirtual(ValuePhiNode phi, VirtualObjectNode virtual) { + if (needsCaching) { + return getValueObjectVirtualCached(phi, virtual); + } else { + return virtual.duplicate(); + } + } + + private VirtualObjectNode getValueObjectVirtualCached(ValuePhiNode phi, VirtualObjectNode virtual) { + if (valueObjectVirtuals == null) { + valueObjectVirtuals = Node.newIdentityMap(); + } VirtualObjectNode result = valueObjectVirtuals.get(phi); if (result == null) { result = virtual.duplicate(); @@ -395,7 +430,7 @@ if (uniqueMaterializedValue != null) { newState.addObject(object, new ObjectState(object, uniqueMaterializedValue, EscapeState.Materialized, null)); } else { - PhiNode materializedValuePhi = getCachedPhi(object, StampFactory.forKind(Kind.Object)); + PhiNode materializedValuePhi = getPhi(object, StampFactory.forKind(Kind.Object)); mergeEffects.addFloatingNode(materializedValuePhi, "materializedPhi"); for (int i = 0; i < objStates.length; i++) { ObjectState obj = objStates[i]; @@ -538,7 +573,7 @@ return materialized; } else { // not compatible: materialize in all predecessors - PhiNode materializedValuePhi = getCachedPhi(object, StampFactory.forKind(Kind.Object)); + PhiNode materializedValuePhi = getPhi(object, StampFactory.forKind(Kind.Object)); for (int i = 0; i < blockStates.size(); i++) { ObjectState obj = objStates[i]; Block predecessor = mergeBlock.getPredecessors().get(i);