Mercurial > hg > truffle
annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/ConvertDeoptimizeToGuardPhase.java @ 4682:7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Spelling fixes.
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Fri, 24 Feb 2012 13:42:24 +0100 |
parents | f55914bc1d67 |
children |
rev | line source |
---|---|
4548
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.max.graal.compiler.phases; |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 import java.util.*; |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
4682
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
27 import com.oracle.max.graal.debug.*; |
4548
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.max.graal.graph.*; |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.max.graal.nodes.*; |
4682
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
30 import com.oracle.max.graal.nodes.util.*; |
4548
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 public class ConvertDeoptimizeToGuardPhase extends Phase { |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 private static BeginNode findBeginNode(Node startNode) { |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 Node n = startNode; |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 while (true) { |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 if (n instanceof BeginNode) { |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 return (BeginNode) n; |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 } else { |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 n = n.predecessor(); |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 } |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 } |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 } |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 @Override |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 protected void run(final StructuredGraph graph) { |
4682
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
47 if (graph.getNodes(DeoptimizeNode.class).isEmpty()) { |
4548
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 return; |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 } |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 |
4682
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
51 for (DeoptimizeNode d : graph.getNodes(DeoptimizeNode.class)) { |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
52 visitDeoptBranch(findBeginNode(d), d, graph); |
4548
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 } |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 new DeadCodeEliminationPhase().apply(graph); |
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 } |
4682
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
57 |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
58 private void visitDeoptBranch(BeginNode deoptBegin, DeoptimizeNode deopt, StructuredGraph graph) { |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
59 if (deoptBegin instanceof MergeNode) { |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
60 MergeNode mergeNode = (MergeNode) deoptBegin; |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
61 Debug.log("Eliminating %s followed by %s", mergeNode, deopt); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
62 List<EndNode> ends = mergeNode.forwardEnds().snapshot(); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
63 for (EndNode end : ends) { |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
64 if (!end.isDeleted()) { |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
65 BeginNode beginNode = findBeginNode(end); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
66 visitDeoptBranch(beginNode, deopt, graph); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
67 } |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
68 } |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
69 if (!deopt.isDeleted()) { |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
70 visitDeoptBranch(findBeginNode(deopt), deopt, graph); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
71 } |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
72 } else if (deoptBegin.predecessor() instanceof IfNode) { |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
73 IfNode ifNode = (IfNode) deoptBegin.predecessor(); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
74 BeginNode otherBegin = ifNode.trueSuccessor(); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
75 BooleanNode conditionNode = ifNode.compare(); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
76 if (deoptBegin == ifNode.trueSuccessor()) { |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
77 conditionNode = conditionNode.negate(); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
78 otherBegin = ifNode.falseSuccessor(); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
79 } |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
80 BeginNode ifBlockBegin = findBeginNode(ifNode); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
81 Debug.log("Converting %s on %-5s branch of %s to guard for remaining branch %s. IfBegin=%s", deopt, deoptBegin == ifNode.trueSuccessor() ? "true" : "false", ifNode, otherBegin, ifBlockBegin); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
82 FixedGuardNode guard = graph.add(new FixedGuardNode(conditionNode)); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
83 otherBegin.replaceAtUsages(ifBlockBegin); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
84 FixedNode next = otherBegin.next(); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
85 otherBegin.setNext(null); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
86 guard.setNext(next); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
87 ifNode.replaceAtPredecessors(guard); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
88 GraphUtil.killCFG(ifNode); |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
89 } |
7cb57ac24ab8
Better ConvertDeoptimizeToGuardPhase (experimental).
Andreas Woess <andreas.woess@jku.at>
parents:
4548
diff
changeset
|
90 } |
4548
f55914bc1d67
Added experimental ConvertDeoptimizeToGuardPhase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
91 } |