1 /*
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.phases.common;
26
27 import jdk.internal.vm.compiler.collections.EconomicMap;
28 import jdk.internal.vm.compiler.collections.EconomicSet;
29 import jdk.internal.vm.compiler.collections.MapCursor;
30 import org.graalvm.compiler.graph.NodeStack;
31 import org.graalvm.compiler.nodes.AbstractBeginNode;
32 import org.graalvm.compiler.nodes.AbstractDeoptimizeNode;
33 import org.graalvm.compiler.nodes.AbstractEndNode;
34 import org.graalvm.compiler.nodes.AbstractMergeNode;
35 import org.graalvm.compiler.nodes.ControlSplitNode;
36 import org.graalvm.compiler.nodes.FixedNode;
37 import org.graalvm.compiler.nodes.StructuredGraph;
38 import org.graalvm.compiler.nodes.spi.CoreProviders;
39 import org.graalvm.compiler.phases.BasePhase;
40
41 /**
42 * This phase will make sure that the branch leading towards this deopt has 0.0 probability.
43 *
44 */
45 public class PropagateDeoptimizeProbabilityPhase extends BasePhase<CoreProviders> {
46
47 @Override
48 @SuppressWarnings("try")
49 protected void run(final StructuredGraph graph, CoreProviders context) {
50 assert !graph.hasValueProxies() : "ConvertDeoptimizeToGuardPhase always creates proxies";
51
52 if (graph.hasNode(AbstractDeoptimizeNode.TYPE)) {
53
54 NodeStack stack = new NodeStack();
55 EconomicMap<ControlSplitNode, EconomicSet<AbstractBeginNode>> reachableSplits = EconomicMap.create();
56
57 // Mark all control flow nodes that are post-dominated by a deoptimization.
58 for (AbstractDeoptimizeNode d : graph.getNodes(AbstractDeoptimizeNode.TYPE)) {
59 stack.push(AbstractBeginNode.prevBegin(d));
60 while (!stack.isEmpty()) {
61 AbstractBeginNode beginNode = (AbstractBeginNode) stack.pop();
62 FixedNode fixedNode = (FixedNode) beginNode.predecessor();
63
64 if (fixedNode == null) {
65 // Can happen for start node.
66 } else if (fixedNode instanceof AbstractMergeNode) {
67 AbstractMergeNode mergeNode = (AbstractMergeNode) fixedNode;
68 for (AbstractEndNode end : mergeNode.forwardEnds()) {
69 AbstractBeginNode newBeginNode = AbstractBeginNode.prevBegin(end);
70 stack.push(newBeginNode);
71 }
72 } else if (fixedNode instanceof ControlSplitNode) {
73 ControlSplitNode controlSplitNode = (ControlSplitNode) fixedNode;
74 EconomicSet<AbstractBeginNode> reachableSuccessors = reachableSplits.get(controlSplitNode);
75 if (reachableSuccessors == null) {
|
1 /*
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.phases.common;
26
27 import jdk.internal.vm.compiler.collections.EconomicMap;
28 import jdk.internal.vm.compiler.collections.EconomicSet;
29 import jdk.internal.vm.compiler.collections.Equivalence;
30 import jdk.internal.vm.compiler.collections.MapCursor;
31 import org.graalvm.compiler.graph.NodeStack;
32 import org.graalvm.compiler.nodes.AbstractBeginNode;
33 import org.graalvm.compiler.nodes.AbstractDeoptimizeNode;
34 import org.graalvm.compiler.nodes.AbstractEndNode;
35 import org.graalvm.compiler.nodes.AbstractMergeNode;
36 import org.graalvm.compiler.nodes.ControlSplitNode;
37 import org.graalvm.compiler.nodes.FixedNode;
38 import org.graalvm.compiler.nodes.StructuredGraph;
39 import org.graalvm.compiler.nodes.spi.CoreProviders;
40 import org.graalvm.compiler.phases.BasePhase;
41
42 /**
43 * This phase will make sure that the branch leading towards this deopt has 0.0 probability.
44 *
45 */
46 public class PropagateDeoptimizeProbabilityPhase extends BasePhase<CoreProviders> {
47
48 @Override
49 @SuppressWarnings("try")
50 protected void run(final StructuredGraph graph, CoreProviders context) {
51 assert !graph.hasValueProxies() : "ConvertDeoptimizeToGuardPhase always creates proxies";
52
53 if (graph.hasNode(AbstractDeoptimizeNode.TYPE)) {
54
55 NodeStack stack = new NodeStack();
56 EconomicMap<ControlSplitNode, EconomicSet<AbstractBeginNode>> reachableSplits = EconomicMap.create(Equivalence.IDENTITY);
57
58 // Mark all control flow nodes that are post-dominated by a deoptimization.
59 for (AbstractDeoptimizeNode d : graph.getNodes(AbstractDeoptimizeNode.TYPE)) {
60 stack.push(AbstractBeginNode.prevBegin(d));
61 while (!stack.isEmpty()) {
62 AbstractBeginNode beginNode = (AbstractBeginNode) stack.pop();
63 FixedNode fixedNode = (FixedNode) beginNode.predecessor();
64
65 if (fixedNode == null) {
66 // Can happen for start node.
67 } else if (fixedNode instanceof AbstractMergeNode) {
68 AbstractMergeNode mergeNode = (AbstractMergeNode) fixedNode;
69 for (AbstractEndNode end : mergeNode.forwardEnds()) {
70 AbstractBeginNode newBeginNode = AbstractBeginNode.prevBegin(end);
71 stack.push(newBeginNode);
72 }
73 } else if (fixedNode instanceof ControlSplitNode) {
74 ControlSplitNode controlSplitNode = (ControlSplitNode) fixedNode;
75 EconomicSet<AbstractBeginNode> reachableSuccessors = reachableSplits.get(controlSplitNode);
76 if (reachableSuccessors == null) {
|