Mercurial > hg > graal-compiler
changeset 5380:8be0c73cf118
made graph marking stateless (in the graph) to ensure recursive marking is safe
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 11 May 2012 14:11:56 +0200 |
parents | c862951e769d |
children | 3f9895797ff4 |
files | graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/InliningPhase.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java |
diffstat | 5 files changed, 34 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Fri May 11 14:11:56 2012 +0200 @@ -168,9 +168,9 @@ new GlobalValueNumberingPhase().apply(graph); } - graph.mark(); + int mark = graph.getMark(); new LoweringPhase(runtime, assumptions).apply(graph); - new CanonicalizerPhase(target, runtime, assumptions, true, null).apply(graph); + new CanonicalizerPhase(target, runtime, assumptions, mark, null).apply(graph); if (GraalOptions.Lower) { new FloatingReadPhase().apply(graph);
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java Fri May 11 14:11:56 2012 +0200 @@ -37,18 +37,22 @@ private static final DebugMetric METRIC_CANONICALIZATION_CONSIDERED_NODES = Debug.metric("CanonicalizationConsideredNodes"); private static final DebugMetric METRIC_SIMPLIFICATION_CONSIDERED_NODES = Debug.metric("SimplificationConsideredNodes"); - private boolean newNodes; + private int newNodesMark; private final CiTarget target; private final CiAssumptions assumptions; private final RiRuntime runtime; private final IsImmutablePredicate immutabilityPredicate; public CanonicalizerPhase(CiTarget target, RiRuntime runtime, CiAssumptions assumptions) { - this(target, runtime, assumptions, false, null); + this(target, runtime, assumptions, -1, null); } - public CanonicalizerPhase(CiTarget target, RiRuntime runtime, CiAssumptions assumptions, boolean newNodes, IsImmutablePredicate immutabilityPredicate) { - this.newNodes = newNodes; + /** + * @param newNodesMark if non-negative, then only the {@linkplain Graph#getNewNodes(int) new nodes} specified by + * this mark are processed otherwise all nodes in the graph are processed + */ + public CanonicalizerPhase(CiTarget target, RiRuntime runtime, CiAssumptions assumptions, int newNodesMark, IsImmutablePredicate immutabilityPredicate) { + this.newNodesMark = newNodesMark; this.target = target; this.assumptions = assumptions; this.runtime = runtime; @@ -57,9 +61,10 @@ @Override protected void run(StructuredGraph graph) { + boolean newNodes = newNodesMark >= 0; NodeWorkList nodeWorkList = graph.createNodeWorkList(!newNodes, MAX_ITERATION_PER_NODE); if (newNodes) { - nodeWorkList.addAll(graph.getNewNodes()); + nodeWorkList.addAll(graph.getNewNodes(newNodesMark)); } canonicalize(graph, nodeWorkList, runtime, target, assumptions, immutabilityPredicate); @@ -80,7 +85,7 @@ METRIC_PROCESSED_NODES.increment(); if (node instanceof Canonicalizable) { METRIC_CANONICALIZATION_CONSIDERED_NODES.increment(); - graph.mark(); + int mark = graph.getMark(); ValueNode canonical = ((Canonicalizable) node).canonical(tool); // cases: original node: // |Floating|Fixed-unconnected|Fixed-connected| @@ -132,7 +137,7 @@ } } } - nodeWorkList.addAll(graph.getNewNodes()); + nodeWorkList.addAll(graph.getNewNodes(mark)); } } else if (node instanceof Simplifiable) { Debug.log("Canonicalizer: simplifying %s", node);
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/InliningPhase.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/InliningPhase.java Fri May 11 14:11:56 2012 +0200 @@ -84,10 +84,10 @@ graph.createNodeMap(); if (hints != null) { - scanInvokes((Iterable<? extends Node>) Util.uncheckedCast(this.hints), -1, graph); + scanInvokes((Iterable<? extends Node>) Util.uncheckedCast(this.hints), -1); } else { - scanInvokes(graph.getNodes(InvokeNode.class), 0, graph); - scanInvokes(graph.getNodes(InvokeWithExceptionNode.class), 0, graph); + scanInvokes(graph.getNodes(InvokeNode.class), 0); + scanInvokes(graph.getNodes(InvokeWithExceptionNode.class), 0); } while (!inlineCandidates.isEmpty() && graph.getNodeCount() < GraalOptions.MaximumDesiredSize) { @@ -101,14 +101,14 @@ }); if (inline) { + int mark = graph.getMark(); Iterable<Node> newNodes = null; try { info.inline(graph, runtime, this); Debug.dump(graph, "after %s", info); - // get the new nodes here, the canonicalizer phase will reset the mark - newNodes = graph.getNewNodes(); + newNodes = graph.getNewNodes(mark); if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(target, runtime, assumptions, true, null).apply(graph); + new CanonicalizerPhase(target, runtime, assumptions, mark, null).apply(graph); } // if (GraalOptions.Intrinsify) { // new IntrinsificationPhase(runtime).apply(graph); @@ -126,7 +126,7 @@ } if (newNodes != null && info.level < GraalOptions.MaximumInlineLevel) { - scanInvokes(newNodes, info.level + 1, graph); + scanInvokes(newNodes, info.level + 1); } } } @@ -144,11 +144,10 @@ } } - private void scanInvokes(final Iterable<? extends Node> newNodes, final int level, final StructuredGraph graph) { + private void scanInvokes(final Iterable<? extends Node> nodes, final int level) { Debug.scope("InliningDecisions", new Runnable() { public void run() { - graph.mark(); - for (Node node : newNodes) { + for (Node node : nodes) { if (node != null) { if (node instanceof Invoke) { Invoke invoke = (Invoke) node;
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java Fri May 11 14:11:56 2012 +0200 @@ -962,7 +962,7 @@ assert localCount == args.length : "snippet argument count mismatch"; snippetCopy.addDuplicates(snippetGraph.getNodes(), replacements); if (!replacements.isEmpty()) { - new CanonicalizerPhase(null, runtime, null, false, immutabilityPredicate).apply(snippetCopy); + new CanonicalizerPhase(null, runtime, null, -1, immutabilityPredicate).apply(snippetCopy); } // Explode all loops in the snippet if requested @@ -974,10 +974,10 @@ Debug.dump(snippetCopy, "Before exploding loop %s", loopBegin); int peel = 0; while (!loopBegin.isDeleted()) { - snippetCopy.mark(); + int mark = snippetCopy.getMark(); LoopTransformUtil.peel(loop, wholeLoop); Debug.dump(snippetCopy, "After peel %d", peel); - new CanonicalizerPhase(null, runtime, null, true, immutabilityPredicate).apply(snippetCopy); + new CanonicalizerPhase(null, runtime, null, mark, immutabilityPredicate).apply(snippetCopy); peel++; } Debug.dump(snippetCopy, "After exploding loop %s", loopBegin); @@ -1012,7 +1012,7 @@ // Inline the gathered snippet nodes StructuredGraph graph = (StructuredGraph) replacee.graph(); - graph.mark(); + int mark = graph.getMark(); Map<Node, Node> duplicates = graph.addDuplicates(nodes, replacements); Debug.dump(graph, "After inlining snippet %s", snippetCopy.method()); @@ -1032,7 +1032,7 @@ } } - for (Node node : graph.getNewNodes()) { + for (Node node : graph.getNewNodes(mark)) { if (node instanceof StateSplit) { StateSplit stateSplit = (StateSplit) node; FrameState frameState = stateSplit.stateAfter();
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Fri May 11 14:11:56 2012 +0200 @@ -45,7 +45,6 @@ private final ArrayList<Node> nodeCacheFirst; private final ArrayList<Node> nodeCacheLast; private int deletedNodeCount; - private int mark; private GraphEventLog eventLog; ArrayList<Node> usagesDropped = new ArrayList<>(); @@ -221,10 +220,10 @@ } /** - * @see #getNewNodes() + * Gets a mark that can be used with {@link #getNewNodes()}. */ - public void mark() { - this.mark = nodeIdCount(); + public int getMark() { + return nodeIdCount(); } private class NodeIterator implements Iterator<Node> { @@ -277,11 +276,10 @@ } /** - * Returns an {@link Iterable} providing all nodes added since the last {@link Graph#mark() mark}. - * @return an {@link Iterable} providing the new nodes + * Returns an {@link Iterable} providing all nodes added since the last {@link Graph#getMark() mark}. */ - public NodeIterable<Node> getNewNodes() { - final int index = this.mark; + public NodeIterable<Node> getNewNodes(int mark) { + final int index = mark; return new NodeIterable<Node>() { @Override public Iterator<Node> iterator() {