Mercurial > hg > truffle
annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DeoptimizationGroupingPhase.java @ 11725:45570e4fe8a9
Group Deoptimization which have the same FrameState
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 19 Sep 2013 12:14:56 +0200 |
parents | |
children | 3e4482a06170 |
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.*; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
28 import com.oracle.graal.phases.*; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
29 |
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 * This phase tries to find {@link DeoptimizeNode DeoptimizeNodes} which use the same |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
32 * {@link FrameState} and merges them together. |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
33 */ |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
34 public class DeoptimizationGroupingPhase extends Phase { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
35 |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
36 @Override |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
37 protected void run(StructuredGraph graph) { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
38 for (FrameState fs : graph.getNodes(FrameState.class)) { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
39 FixedNode target = null; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
40 List<DeoptimizeNode> obsoletes = null; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
41 for (DeoptimizeNode deopt : fs.usages().filter(DeoptimizeNode.class)) { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
42 if (target == null) { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
43 target = deopt; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
44 } else { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
45 MergeNode merge; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
46 if (target instanceof DeoptimizeNode) { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
47 merge = graph.add(new MergeNode()); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
48 EndNode firstEnd = graph.add(new EndNode()); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
49 merge.addForwardEnd(firstEnd); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
50 target.predecessor().replaceFirstSuccessor(target, firstEnd); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
51 merge.setNext(target); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
52 obsoletes = new LinkedList<>(); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
53 target = merge; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
54 } else { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
55 merge = (MergeNode) target; |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
56 } |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
57 EndNode newEnd = graph.add(new EndNode()); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
58 merge.addForwardEnd(newEnd); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
59 deopt.predecessor().replaceFirstSuccessor(deopt, newEnd); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
60 obsoletes.add(deopt); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
61 } |
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 if (obsoletes != null) { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
64 for (DeoptimizeNode obsolete : obsoletes) { |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
65 obsolete.safeDelete(); |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
66 } |
45570e4fe8a9
Group Deoptimization which have the same FrameState
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
67 } |
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 } |