annotate graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ComputeProbabilityClosure.java @ 9993:053b837d0d7d

Readded the pass that fixes DeoptimizeNode probabilities.
author Christian Haeubl <haeubl@ssw.jku.at>
date Tue, 11 Jun 2013 13:10:25 +0200
parents 1b33ef6544b4
children 5260095a574b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
23 package com.oracle.graal.phases.graph;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
9993
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
27 import com.oracle.graal.debug.internal.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
28 import com.oracle.graal.graph.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.nodes.*;
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
30 import com.oracle.graal.nodes.util.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31
7522
4cc0efe5cffe disabled auto-formatting of manually formatted code
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
32 /**
4cc0efe5cffe disabled auto-formatting of manually formatted code
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
33 * Computes probabilities for nodes in a graph.
4cc0efe5cffe disabled auto-formatting of manually formatted code
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
34 * <p>
4cc0efe5cffe disabled auto-formatting of manually formatted code
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
35 * The computation of absolute probabilities works in three steps:
4cc0efe5cffe disabled auto-formatting of manually formatted code
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
36 * <ol>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
37 * <li>{@link PropagateProbability} traverses the graph in post order (merges after their ends, ...)
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
38 * and keeps track of the "probability state". Whenever it encounters a {@link ControlSplitNode} it
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
39 * uses the split's probability information to divide the probability upon the successors. Whenever
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
40 * it encounters an {@link Invoke} it assumes that the exception edge is unlikely and propagates the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
41 * whole probability to the normal successor. Whenever it encounters a {@link MergeNode} it sums up
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
42 * the probability of all predecessors. It also maintains a set of active loops (whose
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
43 * {@link LoopBeginNode} has been visited) and builds def/use information for step 2.</li>
7522
4cc0efe5cffe disabled auto-formatting of manually formatted code
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
44 * <li></li>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
45 * <li>{@link PropagateLoopFrequency} propagates the loop frequencies and multiplies each
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
46 * {@link FixedNode}'s probability with its loop frequency.</li>
7522
4cc0efe5cffe disabled auto-formatting of manually formatted code
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
47 * </ol>
4cc0efe5cffe disabled auto-formatting of manually formatted code
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
48 * TODO: add exception probability information to Invokes
4cc0efe5cffe disabled auto-formatting of manually formatted code
Doug Simon <doug.simon@oracle.com>
parents: 7392
diff changeset
49 */
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
50 public class ComputeProbabilityClosure {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
51
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 private static final double EPSILON = 1d / Integer.MAX_VALUE;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
54 private final StructuredGraph graph;
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
55 private final NodesToDoubles nodeProbabilities;
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
56 private final Set<LoopInfo> loopInfos;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
57 private final Map<MergeNode, Set<LoopInfo>> mergeLoops;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
58
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
59 public ComputeProbabilityClosure(StructuredGraph graph) {
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
60 this.graph = graph;
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
61 this.nodeProbabilities = new NodesToDoubles(graph.getNodeCount());
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
62 this.loopInfos = new HashSet<>();
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
63 this.mergeLoops = new IdentityHashMap<>();
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
64 }
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
65
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
66 public NodesToDoubles apply() {
9993
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
67 adjustControlSplitProbabilities();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 new PropagateProbability(graph.start()).apply();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 computeLoopFactors();
4638
a9181b59a6bf added another variant for propagating loop frequencies
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4614
diff changeset
70 new PropagateLoopFrequency(graph.start()).apply();
9993
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
71 assert verifyProbabilities();
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
72 return nodeProbabilities;
4706
a59fe7906f0b additional LoopFrequencyPropagationPolicy versions
Lukas Stadler <lukas.stadler@jku.at>
parents: 4638
diff changeset
73 }
a59fe7906f0b additional LoopFrequencyPropagationPolicy versions
Lukas Stadler <lukas.stadler@jku.at>
parents: 4638
diff changeset
74
9993
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
75 /**
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
76 * Assume that paths with a DeoptimizeNode at their end are taken infrequently.
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
77 */
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
78 private void adjustControlSplitProbabilities() {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
79 HashSet<ControlSplitNode> result = new HashSet<>();
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
80 NodeBitMap visitedNodes = new NodeBitMap(graph);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
81 for (DeoptimizeNode n : graph.getNodes(DeoptimizeNode.class)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
82 if (n.action().doesInvalidateCompilation()) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
83 findParentControlSplitNodes(result, n, visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
84 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
85 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
86
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
87 for (ControlSplitNode n : result) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
88 if (!allSuxVisited(n, visitedNodes)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
89 modifyProbabilities(n, visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
90 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
91 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
92 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
93
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
94 private static void findParentControlSplitNodes(HashSet<ControlSplitNode> result, DeoptimizeNode n, NodeBitMap visitedNodes) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
95 ArrayDeque<FixedNode> nodes = new ArrayDeque<>();
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
96 nodes.push(n);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
97
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
98 Node currentNode;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
99 do {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
100 currentNode = nodes.pop();
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
101 visitedNodes.mark(currentNode);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
102
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
103 for (Node pred : currentNode.cfgPredecessors()) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
104 FixedNode fixedPred = (FixedNode) pred;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
105 if (visitedNodes.isMarked(fixedPred) && allPredsVisited(fixedPred, visitedNodes)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
106 DebugScope.dump(n.graph(), "ComputeProbabilityClosure");
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
107 GraalInternalError.shouldNotReachHere(String.format("Endless loop because %s was already visited", fixedPred));
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
108 } else if (allSuxVisited(fixedPred, visitedNodes)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
109 nodes.push(fixedPred);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
110 } else {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
111 assert fixedPred instanceof ControlSplitNode : "only control splits can have more than one sux";
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
112 result.add((ControlSplitNode) fixedPred);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
113 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
114 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
115 } while (!nodes.isEmpty());
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
116 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
117
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
118 private static void modifyProbabilities(ControlSplitNode controlSplit, NodeBitMap visitedNodes) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
119 assert !allSuxVisited(controlSplit, visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
120 for (Node sux : controlSplit.successors()) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
121 if (visitedNodes.isMarked(sux)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
122 controlSplit.setProbability((AbstractBeginNode) sux, 0);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
123 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
124 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
125 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
126
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
127 private static boolean allSuxVisited(FixedNode node, NodeBitMap visitedNodes) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
128 return allVisited(node.successors(), visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
129 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
130
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
131 private static boolean allPredsVisited(FixedNode node, NodeBitMap visitedNodes) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
132 return allVisited(node.cfgPredecessors(), visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
133 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
134
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
135 private static boolean allVisited(Iterable<? extends Node> nodes, NodeBitMap visitedNodes) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
136 for (Node sux : nodes) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
137 if (!visitedNodes.contains(sux)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
138 return false;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
139 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
140 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
141 return true;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
142 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
143
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
144 private boolean verifyProbabilities() {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
145 if (doesNotAlwaysDeopt(graph)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
146 for (DeoptimizeNode n : graph.getNodes(DeoptimizeNode.class)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
147 if (n.action().doesInvalidateCompilation() && nodeProbabilities.get(n) > 0.01) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
148 throw new AssertionError(String.format("%s with reason %s and probability %f in graph %s", n, n.reason(), nodeProbabilities.get(n), graph));
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
149 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
150 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
151 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
152 return true;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
153 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
154
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
155 private static boolean doesNotAlwaysDeopt(StructuredGraph graph) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
156 return graph.getNodes(ReturnNode.class).iterator().hasNext();
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
157 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
158
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 private void computeLoopFactors() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 for (LoopInfo info : loopInfos) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
161 double frequency = info.loopFrequency(nodeProbabilities);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 assert frequency != -1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 public static class LoopInfo {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
167
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 public final LoopBeginNode loopBegin;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
170 public final NodeMap<Set<LoopInfo>> requires;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 private double loopFrequency = -1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 public boolean ended = false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 public LoopInfo(LoopBeginNode loopBegin) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 this.loopBegin = loopBegin;
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
177 this.requires = loopBegin.graph().createNodeMap();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
180 public double loopFrequency(NodesToDoubles nodeProbabilities) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 if (loopFrequency == -1 && ended) {
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
182 double backEdgeProb = 0.0;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
183 for (LoopEndNode le : loopBegin.loopEnds()) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
184 double factor = 1;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
185 Set<LoopInfo> requireds = requires.get(le);
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
186 for (LoopInfo required : requireds) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
187 double t = required.loopFrequency(nodeProbabilities);
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
188 if (t == -1) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
189 return -1;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
190 }
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
191 factor *= t;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
192 }
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
193 backEdgeProb += nodeProbabilities.get(le) * factor;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 }
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
195 double d = nodeProbabilities.get(loopBegin) - backEdgeProb;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 if (d < EPSILON) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 d = EPSILON;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 }
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
199 loopFrequency = nodeProbabilities.get(loopBegin) / d;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
200 loopBegin.setLoopFrequency(loopFrequency);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202 return loopFrequency;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
204 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
205
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 private class Probability implements MergeableState<Probability> {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
207
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
208 public double probability;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209 public HashSet<LoopInfo> loops;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 public LoopInfo loopInfo;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 public Probability(double probability, HashSet<LoopInfo> loops) {
9467
3531cdfddff6 Ensure probabilities are never negative. Add additional assertions.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9436
diff changeset
213 assert probability >= 0.0;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 this.probability = probability;
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
215 this.loops = new HashSet<>(4);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
216 if (loops != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217 this.loops.addAll(loops);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
220
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
222 public Probability clone() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
223 return new Probability(probability, loops);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
224 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
225
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
226 @Override
5074
ad00d1d02ed2 change MergeableState to use List<T> instead of Collection<T>
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
227 public boolean merge(MergeNode merge, List<Probability> withStates) {
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
228 if (merge.forwardEndCount() > 1) {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
229 HashSet<LoopInfo> intersection = new HashSet<>(loops);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
230 for (Probability other : withStates) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
231 intersection.retainAll(other.loops);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
232 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
233 for (LoopInfo info : loops) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
234 if (!intersection.contains(info)) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
235 double loopFrequency = info.loopFrequency(nodeProbabilities);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
236 if (loopFrequency == -1) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
237 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
238 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239 probability *= loopFrequency;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
240 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
241 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
242 for (Probability other : withStates) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
243 double prob = other.probability;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
244 for (LoopInfo info : other.loops) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
245 if (!intersection.contains(info)) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
246 double loopFrequency = info.loopFrequency(nodeProbabilities);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
247 if (loopFrequency == -1) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
248 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
249 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
250 prob *= loopFrequency;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
251 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
252 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
253 probability += prob;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
254 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
255 loops = intersection;
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
256 mergeLoops.put(merge, new HashSet<>(intersection));
9467
3531cdfddff6 Ensure probabilities are never negative. Add additional assertions.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9436
diff changeset
257 probability = Math.max(0.0, probability);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
258 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
259 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
260 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
261
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
262 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
263 public void loopBegin(LoopBeginNode loopBegin) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
264 loopInfo = new LoopInfo(loopBegin);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
265 loopInfos.add(loopInfo);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
266 loops.add(loopInfo);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
267 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
268
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
269 @Override
5074
ad00d1d02ed2 change MergeableState to use List<T> instead of Collection<T>
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
270 public void loopEnds(LoopBeginNode loopBegin, List<Probability> loopEndStates) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
271 assert loopInfo != null;
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
272 List<LoopEndNode> loopEnds = loopBegin.orderedLoopEnds();
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
273 int i = 0;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
274 for (Probability proba : loopEndStates) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
275 LoopEndNode loopEnd = loopEnds.get(i++);
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
276 Set<LoopInfo> requires = loopInfo.requires.get(loopEnd);
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
277 if (requires == null) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
278 requires = new HashSet<>();
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
279 loopInfo.requires.set(loopEnd, requires);
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
280 }
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
281 for (LoopInfo innerLoop : proba.loops) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
282 if (innerLoop != loopInfo && !this.loops.contains(innerLoop)) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
283 requires.add(innerLoop);
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
284 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
285 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
286 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
287 loopInfo.ended = true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
288 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
289
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
290 @Override
9436
ae815a4c112a Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9238
diff changeset
291 public void afterSplit(AbstractBeginNode node) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
292 assert node.predecessor() != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
293 Node pred = node.predecessor();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
294 if (pred instanceof Invoke) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
295 Invoke x = (Invoke) pred;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
296 if (x.next() != node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
297 probability = 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
298 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
299 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
300 assert pred instanceof ControlSplitNode;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
301 ControlSplitNode x = (ControlSplitNode) pred;
9467
3531cdfddff6 Ensure probabilities are never negative. Add additional assertions.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9436
diff changeset
302 double nodeProbability = x.probability(node);
3531cdfddff6 Ensure probabilities are never negative. Add additional assertions.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9436
diff changeset
303 assert nodeProbability >= 0.0 : "Node " + x + " provided negative probability for begin " + node + ": " + nodeProbability;
3531cdfddff6 Ensure probabilities are never negative. Add additional assertions.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9436
diff changeset
304 probability *= nodeProbability;
3531cdfddff6 Ensure probabilities are never negative. Add additional assertions.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9436
diff changeset
305 assert probability >= 0.0;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
306 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
307 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
308 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
309
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
310 private class PropagateProbability extends PostOrderNodeIterator<Probability> {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
311
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
312 public PropagateProbability(FixedNode start) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
313 super(start, new Probability(1d, null));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
314 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
315
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
316 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
317 protected void node(FixedNode node) {
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
318 nodeProbabilities.put(node, state.probability);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
319 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
320 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
321
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
322 private class LoopCount implements MergeableState<LoopCount> {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
323
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
324 public double count;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
325
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
326 public LoopCount(double count) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
327 this.count = count;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
328 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
329
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
330 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
331 public LoopCount clone() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
332 return new LoopCount(count);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
333 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
334
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
335 @Override
5074
ad00d1d02ed2 change MergeableState to use List<T> instead of Collection<T>
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
336 public boolean merge(MergeNode merge, List<LoopCount> withStates) {
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
337 assert merge.forwardEndCount() == withStates.size() + 1;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
338 if (merge.forwardEndCount() > 1) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
339 Set<LoopInfo> loops = mergeLoops.get(merge);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
340 assert loops != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
341 double countProd = 1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
342 for (LoopInfo loop : loops) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
343 countProd *= loop.loopFrequency(nodeProbabilities);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
344 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
345 count = countProd;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
346 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
347 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
348 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
349
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
350 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
351 public void loopBegin(LoopBeginNode loopBegin) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
352 count *= loopBegin.loopFrequency();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
353 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
354
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
355 @Override
5074
ad00d1d02ed2 change MergeableState to use List<T> instead of Collection<T>
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
356 public void loopEnds(LoopBeginNode loopBegin, List<LoopCount> loopEndStates) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
357 // nothing to do...
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
358 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
359
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
360 @Override
9436
ae815a4c112a Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9238
diff changeset
361 public void afterSplit(AbstractBeginNode node) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
362 // nothing to do...
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
363 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
364 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
365
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
366 private class PropagateLoopFrequency extends PostOrderNodeIterator<LoopCount> {
4706
a59fe7906f0b additional LoopFrequencyPropagationPolicy versions
Lukas Stadler <lukas.stadler@jku.at>
parents: 4638
diff changeset
367
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
368 public PropagateLoopFrequency(FixedNode start) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
369 super(start, new LoopCount(1d));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
370 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
371
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
372 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
373 protected void node(FixedNode node) {
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
374 nodeProbabilities.put(node, nodeProbabilities.get(node) * state.count);
4638
a9181b59a6bf added another variant for propagating loop frequencies
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4614
diff changeset
375 }
a9181b59a6bf added another variant for propagating loop frequencies
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4614
diff changeset
376
4706
a59fe7906f0b additional LoopFrequencyPropagationPolicy versions
Lukas Stadler <lukas.stadler@jku.at>
parents: 4638
diff changeset
377 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
378 }