Mercurial > hg > truffle
changeset 9955:de73bbbde021
Removed the probability fix temporarily.
author | Christian Haeubl <haeubl@ssw.jku.at> |
---|---|
date | Mon, 10 Jun 2013 08:44:03 +0200 |
parents | fd0e5587a07d |
children | 8ad4e90fc5d7 |
files | graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ComputeProbabilityClosure.java |
diffstat | 1 files changed, 0 insertions(+), 92 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ComputeProbabilityClosure.java Fri Jun 07 17:53:08 2013 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ComputeProbabilityClosure.java Mon Jun 10 08:44:03 2013 +0200 @@ -64,104 +64,12 @@ } public NodesToDoubles apply() { - adjustControlSplitProbabilities(); new PropagateProbability(graph.start()).apply(); computeLoopFactors(); new PropagateLoopFrequency(graph.start()).apply(); - assert verifyProbabilities(); return nodeProbabilities; } - /** - * Assume that paths with a DeoptimizeNode at their end are taken infrequently. - */ - private void adjustControlSplitProbabilities() { - HashSet<ControlSplitNode> result = new HashSet<>(); - NodeBitMap visitedNodes = new NodeBitMap(graph); - for (DeoptimizeNode n : graph.getNodes(DeoptimizeNode.class)) { - if (n.action().doesInvalidateCompilation()) { - findParentControlSplitNodes(result, n, visitedNodes); - } - } - - for (ControlSplitNode n : result) { - if (!allSuxVisited(n, visitedNodes)) { - modifyProbabilities(n, visitedNodes); - } - } - } - - private static void findParentControlSplitNodes(HashSet<ControlSplitNode> result, DeoptimizeNode n, NodeBitMap visitedNodes) { - ArrayDeque<FixedNode> nodes = new ArrayDeque<>(); - nodes.push(n); - - Node currentNode; - do { - currentNode = nodes.pop(); - visitedNodes.mark(currentNode); - - for (Node pred : currentNode.cfgPredecessors()) { - FixedNode fixedPred = (FixedNode) pred; - if (allSuxVisited(fixedPred, visitedNodes) || fixedPred instanceof InvokeWithExceptionNode) { - nodes.push(fixedPred); - } else { - assert fixedPred instanceof ControlSplitNode : "only control splits can have more than one sux"; - result.add((ControlSplitNode) fixedPred); - } - } - } while (!nodes.isEmpty()); - } - - private static void modifyProbabilities(ControlSplitNode node, NodeBitMap visitedNodes) { - if (node instanceof IfNode) { - IfNode ifNode = (IfNode) node; - assert visitedNodes.isMarked(ifNode.falseSuccessor()) ^ visitedNodes.isMarked(ifNode.trueSuccessor()); - - if (visitedNodes.isMarked(ifNode.trueSuccessor())) { - if (ifNode.probability(ifNode.trueSuccessor()) > 0) { - ifNode.setTrueSuccessorProbability(0); - } - } else { - if (ifNode.probability(ifNode.trueSuccessor()) < 1) { - ifNode.setTrueSuccessorProbability(1); - } - } - } else if (node instanceof SwitchNode) { - SwitchNode switchNode = (SwitchNode) node; - for (Node sux : switchNode.successors()) { - if (visitedNodes.isMarked(sux)) { - switchNode.setProbability(sux, 0); - } - } - } else { - GraalInternalError.shouldNotReachHere(); - } - } - - private static boolean allSuxVisited(FixedNode fixedPred, NodeBitMap visitedNodes) { - for (Node sux : fixedPred.successors()) { - if (!visitedNodes.contains(sux)) { - return false; - } - } - return true; - } - - private boolean verifyProbabilities() { - if (doesNotAlwaysDeopt(graph)) { - for (DeoptimizeNode n : graph.getNodes(DeoptimizeNode.class)) { - if (n.action().doesInvalidateCompilation() && nodeProbabilities.get(n) > 0.01) { - throw new AssertionError(String.format("%s with reason %s and probability %f in graph %s", n, n.reason(), nodeProbabilities.get(n), graph)); - } - } - } - return true; - } - - private static boolean doesNotAlwaysDeopt(StructuredGraph graph) { - return graph.getNodes(ReturnNode.class).iterator().hasNext(); - } - private void computeLoopFactors() { for (LoopInfo info : loopInfos) { double frequency = info.loopFrequency(nodeProbabilities);