Mercurial > hg > truffle
annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DeoptimizationGroupingPhase.java @ 11959:23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 10 Oct 2013 16:14:55 +0200 |
parents | 51d5a22e0ea9 |
children | 5a9afbf72714 |
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 |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
27 import com.oracle.graal.api.meta.*; |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
28 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
|
29 import com.oracle.graal.nodes.cfg.*; |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.phases.*; |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
31 import com.oracle.graal.phases.tiers.*; |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
32 |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
33 /** |
11836
d72c314260dc
Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11726
diff
changeset
|
34 * 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
|
35 * {@link FrameState} and merges them together. |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
36 */ |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
37 public class DeoptimizationGroupingPhase extends BasePhase<MidTierContext> { |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
38 |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
39 @Override |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
40 protected void run(StructuredGraph graph, MidTierContext context) { |
11726
3e4482a06170
Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11725
diff
changeset
|
41 ControlFlowGraph cfg = null; |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
42 for (FrameState fs : graph.getNodes(FrameState.class)) { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
43 FixedNode target = null; |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
44 PhiNode phi = 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
|
45 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
|
46 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
|
47 if (target == null) { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
48 target = deopt; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
49 } else { |
11726
3e4482a06170
Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11725
diff
changeset
|
50 if (cfg == null) { |
3e4482a06170
Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11725
diff
changeset
|
51 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
|
52 } |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
53 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
|
54 if (target instanceof AbstractDeoptimizeNode) { |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
55 merge = graph.add(new MergeNode()); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
56 EndNode firstEnd = graph.add(new EndNode()); |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
57 phi = graph.addWithoutUnique(new PhiNode(Kind.Int, merge)); |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
58 merge.addForwardEnd(firstEnd); |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11840
diff
changeset
|
59 phi.addInput(((AbstractDeoptimizeNode) target).getActionAndReason(context.getMetaAccess())); |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
60 target.predecessor().replaceFirstSuccessor(target, firstEnd); |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
61 |
11836
d72c314260dc
Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11726
diff
changeset
|
62 exitLoops((AbstractDeoptimizeNode) target, firstEnd, cfg); |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
63 |
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
64 merge.setNext(graph.add(new DynamicDeoptimizeNode(phi))); |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
65 obsoletes = new LinkedList<>(); |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
66 obsoletes.add((AbstractDeoptimizeNode) target); |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
67 target = merge; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
68 } else { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
69 merge = (MergeNode) target; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
70 } |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
71 EndNode newEnd = graph.add(new EndNode()); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
72 merge.addForwardEnd(newEnd); |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11840
diff
changeset
|
73 phi.addInput(deopt.getActionAndReason(context.getMetaAccess())); |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
74 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
|
75 exitLoops(deopt, newEnd, cfg); |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
76 obsoletes.add(deopt); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
77 } |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
78 } |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
79 if (obsoletes != null) { |
11840
51d5a22e0ea9
Keep the correct Deoptimization reason and action while grouping Deoptimizations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11836
diff
changeset
|
80 ((DynamicDeoptimizeNode) ((MergeNode) target).next()).setDeoptimizationState(fs); |
11836
d72c314260dc
Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11726
diff
changeset
|
81 for (AbstractDeoptimizeNode obsolete : obsoletes) { |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
82 obsolete.safeDelete(); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
83 } |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
84 } |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
85 } |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
86 } |
11726
3e4482a06170
Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11725
diff
changeset
|
87 |
11836
d72c314260dc
Add a DynamicDeoptimizeNode where the action and reason is a input node.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11726
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 while (loop != null) { |
3e4482a06170
Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11725
diff
changeset
|
92 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
|
93 loop = loop.parent; |
3e4482a06170
Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11725
diff
changeset
|
94 } |
3e4482a06170
Exit loops for deopts that miss loop exits in DeoptimizationGroupingPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11725
diff
changeset
|
95 } |
11725
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
96 } |