# HG changeset patch # User Thomas Wuerthinger # Date 1432038287 -7200 # Node ID fdf9166e575fbb2ead422e9af42ca1bfc8ff5496 # Parent 17bbd7cd6e294efd4a57ac64c07f4423f53a3fde Add ability to receive the duplication map via a callback when copying a graph. diff -r 17bbd7cd6e29 -r fdf9166e575f graal/com.oracle.graal.graph/src/com/oracle/graal/graph/CachedGraph.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/CachedGraph.java Tue May 19 14:00:11 2015 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/CachedGraph.java Tue May 19 14:24:47 2015 +0200 @@ -22,6 +22,9 @@ */ package com.oracle.graal.graph; +import java.util.*; +import java.util.function.*; + /** * This class is a container of a graph that needs to be readonly and optionally a lazily created * mutable copy of the graph. @@ -39,9 +42,9 @@ return readonlyCopy; } - public Graph getMutableCopy() { + public Graph getMutableCopy(Consumer> duplicationMapCallback) { if (mutableCopy == null) { - mutableCopy = readonlyCopy.copy(); + mutableCopy = readonlyCopy.copy(duplicationMapCallback); } return mutableCopy; } diff -r 17bbd7cd6e29 -r fdf9166e575f graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Tue May 19 14:00:11 2015 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Tue May 19 14:24:47 2015 +0200 @@ -25,6 +25,7 @@ import static com.oracle.graal.graph.Edges.Type.*; import java.util.*; +import java.util.function.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.debug.*; @@ -220,7 +221,16 @@ * Creates a copy of this graph. */ public Graph copy() { - return copy(name); + return copy(name, null); + } + + /** + * Creates a copy of this graph. + * + * @param duplicationMapCallback consumer of the duplication map created during the copying + */ + public Graph copy(Consumer> duplicationMapCallback) { + return copy(name, duplicationMapCallback); } /** @@ -229,8 +239,21 @@ * @param newName the name of the copy, used for debugging purposes (can be null) */ public Graph copy(String newName) { + return copy(newName, null); + } + + /** + * Creates a copy of this graph. + * + * @param newName the name of the copy, used for debugging purposes (can be null) + * @param duplicationMapCallback consumer of the duplication map created during the copying + */ + public Graph copy(String newName, Consumer> duplicationMapCallback) { Graph copy = new Graph(newName); - copy.addDuplicates(getNodes(), this, this.getNodeCount(), (Map) null); + Map duplicates = copy.addDuplicates(getNodes(), this, this.getNodeCount(), (Map) null); + if (duplicationMapCallback != null) { + duplicationMapCallback.accept(duplicates); + } return copy; }