annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java @ 5693:0356d95f01ba

While inlining, ensure proper anchoring of things that where anchored to the StartNode Fix killCFG case where some dead nodes would not be removed, leading to later NullPointerExceptions Fix Switch nodes simplification in case the node of the remaining successor changes because of deleting the other branches Fix addDuplicates : do not patch inputs to the outer world if these inputs would point to an other graph
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 26 Jun 2012 16:43:51 +0200
parents a9b615da0cba
children f69a406355b2 3842904e46c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.nodes.util;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
25 import static com.oracle.graal.graph.iterators.NodePredicates.*;
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4309
diff changeset
26
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import java.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
29 import com.oracle.graal.api.meta.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
30 import com.oracle.graal.graph.*;
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
31 import com.oracle.graal.graph.iterators.*;
5305
527ff42e0b26 In canonicalizer, when cleaning node with no usages, use a better definition of 'floating' node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5210
diff changeset
32 import com.oracle.graal.graph.iterators.NodePredicates.PositiveTypePredicate;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
33 import com.oracle.graal.nodes.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
34 import com.oracle.graal.nodes.calc.*;
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
35 import com.oracle.graal.nodes.java.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 public class GraphUtil {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38
5598
a9b615da0cba removed delta-encoding of VirtualObjectState
Lukas Stadler <lukas.stadler@jku.at>
parents: 5589
diff changeset
39 private static final PositiveTypePredicate FLOATING = isA(FloatingNode.class).or(VirtualState.class).or(CallTargetNode.class);
5305
527ff42e0b26 In canonicalizer, when cleaning node with no usages, use a better definition of 'floating' node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5210
diff changeset
40
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 public static void killCFG(FixedNode node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 assert node.isAlive();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 if (node instanceof EndNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 // We reached a control flow end.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 EndNode end = (EndNode) node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 killEnd(end);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 // Normal control flow node.
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
49 /* We do not take a successor snapshot because this iterator supports concurrent modifications
5693
0356d95f01ba While inlining, ensure proper anchoring of things that where anchored to the StartNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5598
diff changeset
50 * as long as they do not change the size of the successor list. Not taking a snapshot allows
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
51 * us to see modifications to other branches that may happen while processing one branch.
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
52 */
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
53 for (Node successor : node.successors()) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 killCFG((FixedNode) successor);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 propagateKill(node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 private static void killEnd(EndNode end) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 MergeNode merge = end.merge();
5589
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
62 if (merge != null) {
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
63 merge.removeEnd(end);
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
64 StructuredGraph graph = (StructuredGraph) end.graph();
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
65 if (merge instanceof LoopBeginNode && merge.forwardEndCount() == 0) { //dead loop
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
66 for (PhiNode phi : merge.phis().snapshot()) {
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
67 propagateKill(phi);
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
68 }
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
69 LoopBeginNode begin = (LoopBeginNode) merge;
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
70 // disconnect and delete loop ends & loop exits
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
71 for (LoopEndNode loopend : begin.loopEnds().snapshot()) {
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
72 loopend.predecessor().replaceFirstSuccessor(loopend, null);
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
73 loopend.safeDelete();
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
74 }
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
75 for (LoopExitNode loopexit : begin.loopExits().snapshot()) {
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
76 for (ValueProxyNode vpn : loopexit.proxies().snapshot()) {
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
77 graph.replaceFloating(vpn, vpn.value());
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
78 }
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
79 graph.replaceFixedWithFixed(loopexit, graph.add(new BeginNode()));
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
80 }
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
81 killCFG(begin.next());
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
82 begin.safeDelete();
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
83 } else if (merge instanceof LoopBeginNode && ((LoopBeginNode) merge).loopEnds().isEmpty()) { // not a loop anymore
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
84 graph.reduceDegenerateLoopBegin((LoopBeginNode) merge);
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
85 } else if (merge.phiPredecessorCount() == 1) { // not a merge anymore
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
86 graph.reduceTrivialMerge(merge);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
91 public static NodePredicate isFloatingNode() {
5305
527ff42e0b26 In canonicalizer, when cleaning node with no usages, use a better definition of 'floating' node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5210
diff changeset
92 return FLOATING;
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
93 }
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
94
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 public static void propagateKill(Node node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 if (node != null && node.isAlive()) {
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
97 List<Node> usagesSnapshot = node.usages().filter(isFloatingNode()).snapshot();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 // null out remaining usages
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 node.replaceAtUsages(null);
5487
9743ae819f73 Move virtual chain help methods from SuperBlock to GraphUtil
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5305
diff changeset
101 node.replaceAtPredecessor(null);
5305
527ff42e0b26 In canonicalizer, when cleaning node with no usages, use a better definition of 'floating' node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5210
diff changeset
102 killWithUnusedFloatingInputs(node);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 for (Node usage : usagesSnapshot) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 if (!usage.isDeleted()) {
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4309
diff changeset
106 if (usage instanceof PhiNode) {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4309
diff changeset
107 usage.replaceFirstInput(node, null);
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4309
diff changeset
108 } else {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4309
diff changeset
109 propagateKill(usage);
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4309
diff changeset
110 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 }
4619
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
115
5305
527ff42e0b26 In canonicalizer, when cleaning node with no usages, use a better definition of 'floating' node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5210
diff changeset
116 public static void killWithUnusedFloatingInputs(Node node) {
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
117 List<Node> floatingInputs = node.inputs().filter(isFloatingNode()).snapshot();
4619
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
118 node.safeDelete();
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
119
4652
bdf2eb70ef3e Kill CallTargetNode and FrameState in killCFG to avoid keeping some invalid nodes alive
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4622
diff changeset
120 for (Node in : floatingInputs) {
4622
00e01f401c03 Add checkcast for type-guarded inlining
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4619
diff changeset
121 if (in.isAlive() && in.usages().isEmpty()) {
5305
527ff42e0b26 In canonicalizer, when cleaning node with no usages, use a better definition of 'floating' node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5210
diff changeset
122 killWithUnusedFloatingInputs(in);
4619
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
123 }
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
124 }
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
125 }
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
126
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
127 public static void checkRedundantPhi(PhiNode phiNode) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
128 if (phiNode.isDeleted() || phiNode.valueCount() == 1) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
129 return;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
130 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
131
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
132 ValueNode singleValue = phiNode.singleValue();
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
133 if (singleValue != null) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
134 Collection<PhiNode> phiUsages = phiNode.usages().filter(PhiNode.class).snapshot();
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
135 Collection<ValueProxyNode> proxyUsages = phiNode.usages().filter(ValueProxyNode.class).snapshot();
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
136 ((StructuredGraph) phiNode.graph()).replaceFloating(phiNode, singleValue);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
137 for (PhiNode phi : phiUsages) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
138 checkRedundantPhi(phi);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
139 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
140 for (ValueProxyNode proxy : proxyUsages) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
141 checkRedundantProxy(proxy);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
142 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
143 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
144 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
145
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
146 public static void checkRedundantProxy(ValueProxyNode vpn) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
147 BeginNode proxyPoint = vpn.proxyPoint();
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
148 if (proxyPoint instanceof LoopExitNode) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
149 LoopExitNode exit = (LoopExitNode) proxyPoint;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
150 LoopBeginNode loopBegin = exit.loopBegin();
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
151 ValueNode vpnValue = vpn.value();
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
152 for (ValueNode v : loopBegin.stateAfter().values()) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
153 ValueNode v2 = v;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
154 if (loopBegin.isPhiAtMerge(v2)) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
155 v2 = ((PhiNode) v2).valueAt(loopBegin.forwardEnd());
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
156 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
157 if (vpnValue == v2) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
158 Collection<PhiNode> phiUsages = vpn.usages().filter(PhiNode.class).snapshot();
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
159 Collection<ValueProxyNode> proxyUsages = vpn.usages().filter(ValueProxyNode.class).snapshot();
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
160 ((StructuredGraph) vpn.graph()).replaceFloating(vpn, vpnValue);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
161 for (PhiNode phi : phiUsages) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
162 checkRedundantPhi(phi);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
163 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
164 for (ValueProxyNode proxy : proxyUsages) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
165 checkRedundantProxy(proxy);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
166 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
167 return;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
168 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
169 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
170 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
171 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
172
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
173 public static void normalizeLoopBegin(LoopBeginNode begin) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
174 // Delete unnecessary loop phi functions, i.e., phi functions where all inputs are either the same or the phi itself.
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
175 for (PhiNode phi : begin.phis().snapshot()) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
176 GraphUtil.checkRedundantPhi(phi);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
177 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
178 for (LoopExitNode exit : begin.loopExits()) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
179 for (ValueProxyNode vpn : exit.proxies().snapshot()) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
180 GraphUtil.checkRedundantProxy(vpn);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
181 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
182 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
183 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
184
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
185 /**
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
186 * Gets an approximate source code location for a node if possible.
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
187 *
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
188 * @return a file name and source line number in stack trace format (e.g. "String.java:32")
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
189 * if an approximate source location is found, null otherwise
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
190 */
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
191 public static String approxSourceLocation(Node node) {
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
192 Node n = node;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
193 while (n != null) {
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
194 if (n instanceof MethodCallTargetNode) {
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
195 n = ((MethodCallTargetNode) n).invoke().node();
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
196 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
197
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
198 if (n instanceof StateSplit) {
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
199 FrameState stateAfter = ((StateSplit) n).stateAfter();
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
200 if (stateAfter != null) {
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
201 ResolvedJavaMethod method = stateAfter.method();
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
202 if (method != null) {
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
203 StackTraceElement stackTraceElement = method.toStackTraceElement(stateAfter.bci);
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
204 if (stackTraceElement.getFileName() != null && stackTraceElement.getLineNumber() >= 0) {
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
205 return stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber();
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
206 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
207 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
208 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
209 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
210 n = n.predecessor();
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
211 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
212 return null;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
213 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
214
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
215 public static ValueNode unProxify(ValueNode proxy) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
216 ValueNode v = proxy;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
217 while (v instanceof ValueProxyNode) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
218 v = ((ValueProxyNode) v).value();
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
219 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
220 return v;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
221 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
222 }