annotate graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ComputeProbabilityClosure.java @ 11399:c8a9914b36e8

Use an EPSILON where 1. / EPSILON is finite.
author Roland Schatz <roland.schatz@oracle.com>
date Fri, 23 Aug 2013 14:03:09 +0200
parents 1a110b7c03e1
children 93c63975217e
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 */
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
49 public class ComputeProbabilityClosure {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
50
11399
c8a9914b36e8 Use an EPSILON where 1. / EPSILON is finite.
Roland Schatz <roland.schatz@oracle.com>
parents: 11375
diff changeset
51 private static final double EPSILON = Double.MIN_NORMAL;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
53 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
54 private final NodesToDoubles nodeProbabilities;
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
55 private final Set<LoopInfo> loopInfos;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
56 private final Map<MergeNode, Set<LoopInfo>> mergeLoops;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
57
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
58 public ComputeProbabilityClosure(StructuredGraph graph) {
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
59 this.graph = graph;
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
60 this.nodeProbabilities = new NodesToDoubles(graph.getNodeCount());
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
61 this.loopInfos = new HashSet<>();
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
62 this.mergeLoops = new IdentityHashMap<>();
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
63 }
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
64
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
65 public NodesToDoubles apply() {
9993
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
66 adjustControlSplitProbabilities();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 new PropagateProbability(graph.start()).apply();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 computeLoopFactors();
4638
a9181b59a6bf added another variant for propagating loop frequencies
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4614
diff changeset
69 new PropagateLoopFrequency(graph.start()).apply();
9993
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
70 assert verifyProbabilities();
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
71 return nodeProbabilities;
4706
a59fe7906f0b additional LoopFrequencyPropagationPolicy versions
Lukas Stadler <lukas.stadler@jku.at>
parents: 4638
diff changeset
72 }
a59fe7906f0b additional LoopFrequencyPropagationPolicy versions
Lukas Stadler <lukas.stadler@jku.at>
parents: 4638
diff changeset
73
9993
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
74 /**
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
75 * 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
76 */
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
77 private void adjustControlSplitProbabilities() {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
78 HashSet<ControlSplitNode> result = new HashSet<>();
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
79 NodeBitMap visitedNodes = new NodeBitMap(graph);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
80 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
81 if (n.action().doesInvalidateCompilation()) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
82 findParentControlSplitNodes(result, n, visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
83 }
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 for (ControlSplitNode n : result) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
87 if (!allSuxVisited(n, visitedNodes)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
88 modifyProbabilities(n, visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
89 }
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 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
94 ArrayDeque<FixedNode> nodes = new ArrayDeque<>();
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
95 nodes.push(n);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
96
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
97 Node currentNode;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
98 do {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
99 currentNode = nodes.pop();
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
100 visitedNodes.mark(currentNode);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
101
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
102 for (Node pred : currentNode.cfgPredecessors()) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
103 FixedNode fixedPred = (FixedNode) pred;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
104 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
105 DebugScope.dump(n.graph(), "ComputeProbabilityClosure");
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
106 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
107 } else if (allSuxVisited(fixedPred, visitedNodes)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
108 nodes.push(fixedPred);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
109 } else {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
110 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
111 result.add((ControlSplitNode) fixedPred);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
112 }
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 } while (!nodes.isEmpty());
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
115 }
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 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
118 assert !allSuxVisited(controlSplit, visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
119 for (Node sux : controlSplit.successors()) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
120 if (visitedNodes.isMarked(sux)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
121 controlSplit.setProbability((AbstractBeginNode) sux, 0);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
122 }
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 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
127 return allVisited(node.successors(), visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
128 }
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 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
131 return allVisited(node.cfgPredecessors(), visitedNodes);
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
132 }
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 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
135 for (Node sux : nodes) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
136 if (!visitedNodes.contains(sux)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
137 return false;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
138 }
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 return true;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
141 }
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 private boolean verifyProbabilities() {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
144 if (doesNotAlwaysDeopt(graph)) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
145 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
146 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
147 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
148 }
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 return true;
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
152 }
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 private static boolean doesNotAlwaysDeopt(StructuredGraph graph) {
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
155 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
156 }
053b837d0d7d Readded the pass that fixes DeoptimizeNode probabilities.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9957
diff changeset
157
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
158 private void computeLoopFactors() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 for (LoopInfo info : loopInfos) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
160 double frequency = info.loopFrequency(nodeProbabilities);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 assert frequency != -1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 }
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 public static class LoopInfo {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
166
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167 public final LoopBeginNode loopBegin;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
169 public final NodeMap<Set<LoopInfo>> requires;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
170
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171 private double loopFrequency = -1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 public boolean ended = false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 public LoopInfo(LoopBeginNode loopBegin) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 this.loopBegin = loopBegin;
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
176 this.requires = loopBegin.graph().createNodeMap();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
179 public double loopFrequency(NodesToDoubles nodeProbabilities) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 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
181 double backEdgeProb = 0.0;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
182 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
183 double factor = 1;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
184 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
185 for (LoopInfo required : requireds) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
186 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
187 if (t == -1) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
188 return -1;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
189 }
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
190 factor *= t;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 }
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
192 backEdgeProb += nodeProbabilities.get(le) * factor;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 }
11375
1a110b7c03e1 Use smaller epsilon in ComputeProbabilityClosure
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10803
diff changeset
194 double entryProb = nodeProbabilities.get(loopBegin);
1a110b7c03e1 Use smaller epsilon in ComputeProbabilityClosure
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10803
diff changeset
195 double d = entryProb - backEdgeProb;
1a110b7c03e1 Use smaller epsilon in ComputeProbabilityClosure
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10803
diff changeset
196 if (d <= EPSILON) {
3733
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 }
11375
1a110b7c03e1 Use smaller epsilon in ComputeProbabilityClosure
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10803
diff changeset
199 loopFrequency = entryProb / 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
10803
4532725151cc make MergeableState an abstract class instead of an interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 10036
diff changeset
206 private class Probability extends 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;
11399
c8a9914b36e8 Use an EPSILON where 1. / EPSILON is finite.
Roland Schatz <roland.schatz@oracle.com>
parents: 11375
diff changeset
240 assert probability >= 0;
3733
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 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
243 for (Probability other : withStates) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
244 double prob = other.probability;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
245 for (LoopInfo info : other.loops) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
246 if (!intersection.contains(info)) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
247 double loopFrequency = info.loopFrequency(nodeProbabilities);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
248 if (loopFrequency == -1) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
249 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
250 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
251 prob *= loopFrequency;
11399
c8a9914b36e8 Use an EPSILON where 1. / EPSILON is finite.
Roland Schatz <roland.schatz@oracle.com>
parents: 11375
diff changeset
252 assert prob >= 0;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
253 }
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 probability += prob;
11399
c8a9914b36e8 Use an EPSILON where 1. / EPSILON is finite.
Roland Schatz <roland.schatz@oracle.com>
parents: 11375
diff changeset
256 assert probability >= 0;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
257 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
258 loops = intersection;
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
259 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
260 probability = Math.max(0.0, probability);
3733
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 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
263 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
264
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
265 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
266 public void loopBegin(LoopBeginNode loopBegin) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
267 loopInfo = new LoopInfo(loopBegin);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
268 loopInfos.add(loopInfo);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
269 loops.add(loopInfo);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
270 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
271
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
272 @Override
5074
ad00d1d02ed2 change MergeableState to use List<T> instead of Collection<T>
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
273 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
274 assert loopInfo != null;
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
275 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
276 int i = 0;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
277 for (Probability proba : loopEndStates) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
278 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
279 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
280 if (requires == null) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
281 requires = new HashSet<>();
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
282 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
283 }
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
284 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
285 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
286 requires.add(innerLoop);
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4569
diff changeset
287 }
3733
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 loopInfo.ended = true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
291 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
292
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
293 @Override
9436
ae815a4c112a Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9238
diff changeset
294 public void afterSplit(AbstractBeginNode node) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
295 assert node.predecessor() != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
296 Node pred = node.predecessor();
10036
5260095a574b Fixed probability computation for invokes with an exception edge.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9993
diff changeset
297 ControlSplitNode x = (ControlSplitNode) pred;
5260095a574b Fixed probability computation for invokes with an exception edge.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9993
diff changeset
298 double nodeProbability = x.probability(node);
5260095a574b Fixed probability computation for invokes with an exception edge.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9993
diff changeset
299 assert nodeProbability >= 0.0 : "Node " + x + " provided negative probability for begin " + node + ": " + nodeProbability;
5260095a574b Fixed probability computation for invokes with an exception edge.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9993
diff changeset
300 probability *= nodeProbability;
5260095a574b Fixed probability computation for invokes with an exception edge.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9993
diff changeset
301 assert probability >= 0.0;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
302 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
303 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
304
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
305 private class PropagateProbability extends PostOrderNodeIterator<Probability> {
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 public PropagateProbability(FixedNode start) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
308 super(start, new Probability(1d, null));
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
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
311 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
312 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
313 nodeProbabilities.put(node, state.probability);
3733
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
10803
4532725151cc make MergeableState an abstract class instead of an interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 10036
diff changeset
317 private class LoopCount extends MergeableState<LoopCount> {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
318
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
319 public double count;
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 public LoopCount(double count) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
322 this.count = count;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
323 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
324
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
325 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
326 public LoopCount clone() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
327 return new LoopCount(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
5074
ad00d1d02ed2 change MergeableState to use List<T> instead of Collection<T>
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
331 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
332 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
333 if (merge.forwardEndCount() > 1) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
334 Set<LoopInfo> loops = mergeLoops.get(merge);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
335 assert loops != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
336 double countProd = 1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
337 for (LoopInfo loop : loops) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9113
diff changeset
338 countProd *= loop.loopFrequency(nodeProbabilities);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
339 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
340 count = countProd;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
341 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
342 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
343 }
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 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
346 public void loopBegin(LoopBeginNode loopBegin) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
347 count *= loopBegin.loopFrequency();
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
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
351 private class PropagateLoopFrequency extends PostOrderNodeIterator<LoopCount> {
4706
a59fe7906f0b additional LoopFrequencyPropagationPolicy versions
Lukas Stadler <lukas.stadler@jku.at>
parents: 4638
diff changeset
352
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
353 public PropagateLoopFrequency(FixedNode start) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
354 super(start, new LoopCount(1d));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
355 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
356
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
357 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
358 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
359 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
360 }
a9181b59a6bf added another variant for propagating loop frequencies
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4614
diff changeset
361
4706
a59fe7906f0b additional LoopFrequencyPropagationPolicy versions
Lukas Stadler <lukas.stadler@jku.at>
parents: 4638
diff changeset
362 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
363 }