annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DeoptimizationGroupingPhase.java @ 11836:d72c314260dc

Add a DynamicDeoptimizeNode where the action and reason is a input node.
author Gilles Duboscq <duboscq@ssw.jku.at>
date Thu, 26 Sep 2013 17:30:19 +0200
parents 3e4482a06170
children 51d5a22e0ea9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
1 /*
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved.
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
4 *
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
8 *
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
14 *
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
18 *
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
21 * questions.
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
22 */
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
23 package com.oracle.graal.phases.common;
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
24
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
25 import java.util.*;
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
26
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
27 import com.oracle.graal.nodes.*;
11726
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
28 import com.oracle.graal.nodes.cfg.*;
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
29 import com.oracle.graal.phases.*;
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
30
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
31 /**
11836
d72c314260dc Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11726
diff changeset
32 * This phase tries to find {@link AbstractDeoptimizeNode DeoptimizeNodes} which use the same
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
33 * {@link FrameState} and merges them together.
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
34 */
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
35 public class DeoptimizationGroupingPhase extends Phase {
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
36
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
37 @Override
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
38 protected void run(StructuredGraph graph) {
11726
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
39 ControlFlowGraph cfg = null;
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
40 for (FrameState fs : graph.getNodes(FrameState.class)) {
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
41 FixedNode target = null;
11836
d72c314260dc Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11726
diff changeset
42 List<AbstractDeoptimizeNode> obsoletes = null;
d72c314260dc Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11726
diff changeset
43 for (AbstractDeoptimizeNode deopt : fs.usages().filter(AbstractDeoptimizeNode.class)) {
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
44 if (target == null) {
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
45 target = deopt;
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
46 } else {
11726
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
47 if (cfg == null) {
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
48 cfg = ControlFlowGraph.compute(graph, true, true, false, false);
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
49 }
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
50 MergeNode merge;
11836
d72c314260dc Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11726
diff changeset
51 if (target instanceof AbstractDeoptimizeNode) {
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
52 merge = graph.add(new MergeNode());
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
53 EndNode firstEnd = graph.add(new EndNode());
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
54 merge.addForwardEnd(firstEnd);
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
55 target.predecessor().replaceFirstSuccessor(target, firstEnd);
11836
d72c314260dc Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11726
diff changeset
56 exitLoops((AbstractDeoptimizeNode) target, firstEnd, cfg);
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
57 merge.setNext(target);
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
58 obsoletes = new LinkedList<>();
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
59 target = merge;
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
60 } else {
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
61 merge = (MergeNode) target;
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
62 }
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
63 EndNode newEnd = graph.add(new EndNode());
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
64 merge.addForwardEnd(newEnd);
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
65 deopt.predecessor().replaceFirstSuccessor(deopt, newEnd);
11726
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
66 exitLoops(deopt, newEnd, cfg);
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
67 obsoletes.add(deopt);
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
68 }
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
69 }
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
70 if (obsoletes != null) {
11836
d72c314260dc Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11726
diff changeset
71 for (AbstractDeoptimizeNode obsolete : obsoletes) {
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
72 obsolete.safeDelete();
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
73 }
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
74 }
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
75 }
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
76 }
11726
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
77
11836
d72c314260dc Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11726
diff changeset
78 private static void exitLoops(AbstractDeoptimizeNode deopt, EndNode end, ControlFlowGraph cfg) {
11726
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
79 Block block = cfg.blockFor(deopt);
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
80 Loop loop = block.getLoop();
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
81 while (loop != null) {
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
82 end.graph().addBeforeFixed(end, end.graph().add(new LoopExitNode(loop.loopBegin())));
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
83 loop = loop.parent;
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
84 }
3e4482a06170 Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11725
diff changeset
85 }
11725
45570e4fe8a9 Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
86 }