# HG changeset patch # User Christian Humer # Date 1395255247 -3600 # Node ID affd2b3b0cbbf061d5d2b37d0bc812b39fd3fdc0 # Parent e845cd0b033f71bd877355c29bfff055eec8e76b Truffle: tuned inlining. diff -r e845cd0b033f -r affd2b3b0cbb graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallNode.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallNode.java Tue Mar 18 20:36:53 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallNode.java Wed Mar 19 19:54:07 2014 +0100 @@ -23,7 +23,6 @@ package com.oracle.graal.truffle; import java.util.*; -import java.util.concurrent.atomic.*; import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; @@ -126,17 +125,11 @@ if (!isSplittable()) { return false; } - int nodeCount = NodeUtil.countNodes(getCallTarget().getRootNode(), null, false); + int nodeCount = NodeUtil.countNodes(getCallTarget().getRootNode(), OptimizedCallNodeProfile.COUNT_FILTER, false); if (nodeCount > TruffleCompilerOptions.TruffleSplittingMaxCalleeSize.getValue()) { return false; } - // // is the only call target -> do not split - // if (getCallTarget().getRootNode().getCachedCallNodes().size() == 1 && - // getCallTarget().getRootNode().getCachedCallNodes().contains(this)) { - // return false; - // } - // disable recursive splitting for now OptimizedCallTarget splitTarget = getCallTarget(); List compilationRoots = OptimizedCallNodeProfile.findCompilationRoots(this); @@ -160,17 +153,11 @@ } private boolean isMaxSingleCall() { - final AtomicInteger count = new AtomicInteger(0); - getCurrentCallTarget().getRootNode().accept(new NodeVisitor() { - - public boolean visit(Node node) { - if (node instanceof CallNode) { - return count.incrementAndGet() > 1; - } - return true; + return NodeUtil.countNodes(getCurrentCallTarget().getRootNode(), new NodeCountFilter() { + public boolean isCounted(Node node) { + return node instanceof CallNode; } - }); - return count.get() <= 1; + }) <= 1; } private int countPolymorphic() { diff -r e845cd0b033f -r affd2b3b0cbb graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallNodeProfile.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallNodeProfile.java Tue Mar 18 20:36:53 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallNodeProfile.java Wed Mar 19 19:54:07 2014 +0100 @@ -27,11 +27,13 @@ import java.util.*; import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.api.nodes.NodeUtil.*; public class OptimizedCallNodeProfile implements TruffleInliningProfile { + static final CountFilter COUNT_FILTER = new CountFilter(); + private static final String REASON_RECURSION = "recursion"; - private static final String REASON_FREQUENCY_CUTOFF = "frequency < " + TruffleInliningMinFrequency.getValue(); private static final String REASON_MAXIMUM_NODE_COUNT = "shallowTargetCount > " + TruffleInliningMaxCalleeSize.getValue(); private static final String REASON_MAXIMUM_TOTAL_NODE_COUNT = "inlinedTotalCount > " + TruffleInliningMaxCallerSize.getValue(); @@ -49,8 +51,8 @@ this.callNode = callNode; RootNode inlineRoot = callNode.getCurrentCallTarget().getRootNode(); this.callTarget = target; - this.targetShallowNodeCount = NodeUtil.countNodes(inlineRoot, null, false); - this.targetDeepNodeCount = NodeUtil.countNodes(inlineRoot, null, true); + this.targetShallowNodeCount = NodeUtil.countNodes(inlineRoot, COUNT_FILTER, false); + this.targetDeepNodeCount = NodeUtil.countNodes(inlineRoot, COUNT_FILTER, true); this.compilationRoots = findCompilationRoots(callNode); this.averageFrequency = calculateFrequency(); this.score = calculateScore(); @@ -84,18 +86,12 @@ } } - // frequency cut-off - if (averageFrequency < TruffleInliningMinFrequency.getValue() && targetDeepNodeCount > TruffleInliningTrivialSize.getValue()) { - reason = REASON_FREQUENCY_CUTOFF; - return false; - } - if (targetShallowNodeCount > TruffleInliningMaxCalleeSize.getValue()) { reason = REASON_MAXIMUM_NODE_COUNT; return false; } - this.targetDeepNodeCount = NodeUtil.countNodes(inlineTarget.getRootNode(), null, true); + this.targetDeepNodeCount = NodeUtil.countNodes(inlineTarget.getRootNode(), COUNT_FILTER, true); // The maximum total node count cannot be cached since it may change during inlining. int nextNodeCount = calculateInlinedTotalNodeCount(getCallNode()); if (nextNodeCount > TruffleInliningMaxCallerSize.getValue()) { @@ -116,6 +112,20 @@ return currentNodeCount; } + static class CountFilter implements NodeCountFilter { + public boolean isCounted(Node node) { + return countNode(node) >= 1; + } + } + + static int countNode(Node node) { + NodeCost cost = node.getCost(); + if (cost != null && cost != NodeCost.NONE && cost != NodeCost.UNINITIALIZED) { + return 1; + } + return 0; + } + private static class TotalNodeCountVisitor implements NodeVisitor { private final OptimizedCallNode inlinedNode; @@ -129,7 +139,7 @@ } public boolean visit(Node node) { - count++; + count += countNode(node); if (node instanceof OptimizedCallNode) { OptimizedCallNode callNode = ((OptimizedCallNode) node); if (callNode == inlinedNode) { diff -r e845cd0b033f -r affd2b3b0cbb graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Tue Mar 18 20:36:53 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Wed Mar 19 19:54:07 2014 +0100 @@ -473,7 +473,7 @@ } }, true); - String value = String.format("%4d (%d/%d)", NodeUtil.countNodes(target.getRootNode(), null, true), // + String value = String.format("%4d (%d/%d)", NodeUtil.countNodes(target.getRootNode(), OptimizedCallNodeProfile.COUNT_FILTER, true), // polymorphicCount, megamorphicCount); // properties.put("ASTSize", value); @@ -533,8 +533,8 @@ continue; } - int nodeCount = NodeUtil.countNodes(callTarget.getRootNode(), null, true); - int inlinedCallSiteCount = countInlinedNodes(callTarget.getRootNode()); + int nodeCount = NodeUtil.countNodes(callTarget.getRootNode(), OptimizedCallNodeProfile.COUNT_FILTER, false); + int inlinedCallSiteCount = NodeUtil.countNodes(callTarget.getRootNode(), OptimizedCallNodeProfile.COUNT_FILTER, true); String comment = callTarget.installedCode == null ? " int" : ""; comment += callTarget.compilationEnabled ? "" : " fail"; OUT.printf("%-50s | %10d | %15d | %10d | %3d%s\n", callTarget.getRootNode(), callTarget.callCount, inlinedCallSiteCount, nodeCount, @@ -548,21 +548,6 @@ OUT.printf("%-50s | %10d | %15d | %10d | %3d\n", "Total", totalCallCount, totalInlinedCallSiteCount, totalNodeCount, totalInvalidationCount); } - private static int countInlinedNodes(Node rootNode) { - List callers = NodeUtil.findAllNodeInstances(rootNode, CallNode.class); - int count = 0; - for (CallNode callNode : callers) { - if (callNode.isInlined()) { - count++; - RootNode root = callNode.getCurrentRootNode(); - if (root != null) { - count += countInlinedNodes(root); - } - } - } - return count; - } - private static void registerCallTarget(OptimizedCallTarget callTarget) { callTargets.put(callTarget, 0); } diff -r e845cd0b033f -r affd2b3b0cbb graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Tue Mar 18 20:36:53 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Wed Mar 19 19:54:07 2014 +0100 @@ -58,7 +58,7 @@ @Option(help = "Stop inlining if caller's cumulative tree size would exceed this limit") public static final OptionValue TruffleInliningMaxCallerSize = new OptionValue<>(2250); @Option(help = "Skip inlining candidate if its tree size exceeds this limit") - public static final OptionValue TruffleInliningMaxCalleeSize = new OptionValue<>(250); + public static final OptionValue TruffleInliningMaxCalleeSize = new OptionValue<>(350); @Option(help = "Call frequency relative to call target") public static final OptionValue TruffleInliningMinFrequency = new OptionValue<>(0.3); @Option(help = "Allow inlining of less hot candidates if tree size is small")