annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java @ 19545:10a0f4aef97c

Fix after changes in GraphUtil.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 23 Feb 2015 00:12:52 +0100
parents 353669a84287
children 14a30a0f631c
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
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
27 import com.oracle.graal.api.code.*;
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
28 import com.oracle.graal.api.meta.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.graph.*;
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
30 import com.oracle.graal.graph.iterators.*;
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
31 import com.oracle.graal.graph.spi.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
32 import com.oracle.graal.nodes.*;
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
33 import com.oracle.graal.nodes.java.*;
10762
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
34 import com.oracle.graal.nodes.spi.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 public class GraphUtil {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37
5806
3842904e46c2 Kill unused floating nodes in Canonicalizer
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5693
diff changeset
38 private static final NodePredicate FLOATING = new NodePredicate() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
39
5806
3842904e46c2 Kill unused floating nodes in Canonicalizer
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5693
diff changeset
40 @Override
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
41 public final boolean apply(Node n) {
19541
c66037cb9cd1 Make Node#replaceAndDelete not accept null as an argument.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19524
diff changeset
42 return !(n instanceof FixedNode);
5806
3842904e46c2 Kill unused floating nodes in Canonicalizer
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5693
diff changeset
43 }
3842904e46c2 Kill unused floating nodes in Canonicalizer
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5693
diff changeset
44 };
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
45
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
46 public static void killCFG(Node node, SimplifierTool tool) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 assert node.isAlive();
9434
50f02c7d1cec Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9389
diff changeset
48 if (node instanceof AbstractEndNode) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 // We reached a control flow end.
9434
50f02c7d1cec Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9389
diff changeset
50 AbstractEndNode end = (AbstractEndNode) node;
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
51 killEnd(end, tool);
19543
353669a84287 Utilities Node#acceptInputs and Node#acceptSuccessors.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19542
diff changeset
52 } else if (node instanceof FixedNode) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 // Normal control flow node.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
54 /*
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
55 * We do not take a successor snapshot because this iterator supports concurrent
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
56 * modifications as long as they do not change the size of the successor list. Not
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
57 * taking a snapshot allows us to see modifications to other branches that may happen
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
58 * while processing one branch.
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
59 */
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
60 for (Node successor : node.successors()) {
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
61 killCFG(successor, tool);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 }
19542
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
64 node.replaceAtPredecessor(null);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 propagateKill(node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
68 public static void killCFG(Node node) {
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
69 killCFG(node, null);
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
70 }
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
71
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
72 private static void killEnd(AbstractEndNode end, SimplifierTool tool) {
18995
a2cb19764970 Rename MergeNode to AbstractMergeNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18993
diff changeset
73 AbstractMergeNode 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
74 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
75 merge.removeEnd(end);
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9436
diff changeset
76 StructuredGraph graph = end.graph();
15468
43b3dbfa367d small cosmetic fix in GraphUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15439
diff changeset
77 if (merge instanceof LoopBeginNode && merge.forwardEndCount() == 0) {
43b3dbfa367d small cosmetic fix in GraphUtil
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15439
diff changeset
78 // dead loop
5589
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
79 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
80 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
81 }
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
82 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
83 // 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
84 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
85 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
86 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
87 }
6318
8886fdfde36c Factor out code that kills loop exits
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5811
diff changeset
88 begin.removeExits();
7245
1e099e2c6197 Fix for KillCFG while killing infinite empty loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 6539
diff changeset
89 FixedNode loopBody = begin.next();
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
90 if (loopBody != null) { // for small infinite loops, the body may be killed while
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
91 // killing the loop ends
7245
1e099e2c6197 Fix for KillCFG while killing infinite empty loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 6539
diff changeset
92 killCFG(loopBody);
1e099e2c6197 Fix for KillCFG while killing infinite empty loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 6539
diff changeset
93 }
5589
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
94 begin.safeDelete();
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
95 } else if (merge instanceof LoopBeginNode && ((LoopBeginNode) merge).loopEnds().isEmpty()) {
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
96 // not a loop anymore
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
97 if (tool != null) {
16157
bd1202138e21 add SimplifierTool.addToWorkList for Iterable<Node>
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16099
diff changeset
98 merge.phis().forEach(phi -> tool.addToWorkList(phi.usages()));
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
99 }
5589
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
100 graph.reduceDegenerateLoopBegin((LoopBeginNode) merge);
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
101 } else if (merge.phiPredecessorCount() == 1) {
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
102 // not a merge anymore
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
103 if (tool != null) {
16157
bd1202138e21 add SimplifierTool.addToWorkList for Iterable<Node>
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16099
diff changeset
104 merge.phis().forEach(phi -> tool.addToWorkList(phi.usages()));
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
105 }
5589
728cf399b18d fix NPE when using killCFG to delete an EndNode without a merge
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
106 graph.reduceTrivialMerge(merge);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
111 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
112 return FLOATING;
5203
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
113 }
09e87f5b81e4 Fix potential KillCFG problem
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5101
diff changeset
114
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 public static void propagateKill(Node node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116 if (node != null && node.isAlive()) {
19542
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
117 node.unsafeDelete();
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
118
19543
353669a84287 Utilities Node#acceptInputs and Node#acceptSuccessors.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19542
diff changeset
119 node.acceptInputs(in -> {
19542
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
120 if (in.isAlive() && in.hasNoUsages() && !(in instanceof FixedNode)) {
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
121 killWithUnusedFloatingInputs(in);
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
122 }
19543
353669a84287 Utilities Node#acceptInputs and Node#acceptSuccessors.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19542
diff changeset
123 });
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124
19542
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
125 ArrayList<Node> usageToKill = null;
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
126 for (Node usage : node.usages()) {
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
127 if (usage.isAlive() && !(usage instanceof FixedNode)) {
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
128 if (usageToKill == null) {
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
129 usageToKill = new ArrayList<>();
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
130 }
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
131 usageToKill.add(usage);
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
132 }
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
133 }
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
134 if (usageToKill != null) {
f98e2f0c35d8 Make GraphUtil#propagateKill more efficient.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19541
diff changeset
135 for (Node usage : usageToKill) {
19545
10a0f4aef97c Fix after changes in GraphUtil.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19543
diff changeset
136 if (usage.isAlive()) {
10a0f4aef97c Fix after changes in GraphUtil.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19543
diff changeset
137 if (usage instanceof PhiNode) {
10a0f4aef97c Fix after changes in GraphUtil.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19543
diff changeset
138 usage.replaceFirstInput(node, null);
10a0f4aef97c Fix after changes in GraphUtil.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19543
diff changeset
139 } else {
10a0f4aef97c Fix after changes in GraphUtil.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19543
diff changeset
140 propagateKill(usage);
10a0f4aef97c Fix after changes in GraphUtil.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19543
diff changeset
141 }
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4309
diff changeset
142 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 }
4619
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
147
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
148 public static void killWithUnusedFloatingInputs(Node node) {
17064
3c54a098455f removed Node.recordsUsages()
Doug Simon <doug.simon@oracle.com>
parents: 16588
diff changeset
149 node.safeDelete();
19541
c66037cb9cd1 Make Node#replaceAndDelete not accept null as an argument.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19524
diff changeset
150 for (Node in : node.inputs()) {
c66037cb9cd1 Make Node#replaceAndDelete not accept null as an argument.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19524
diff changeset
151 if (in.isAlive() && in.hasNoUsages() && !(in instanceof FixedNode)) {
17064
3c54a098455f removed Node.recordsUsages()
Doug Simon <doug.simon@oracle.com>
parents: 16588
diff changeset
152 killWithUnusedFloatingInputs(in);
4619
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
153 }
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
154 }
a09b44a28e7f clenup unused floating nodes on killCFG
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4614
diff changeset
155 }
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
156
13794
2eb56f87b01e add GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@jku.at>
parents: 13327
diff changeset
157 public static void removeFixedWithUnusedInputs(FixedWithNextNode fixed) {
15285
d9c64f6a11c7 deal with StateSplits in GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15145
diff changeset
158 if (fixed instanceof StateSplit) {
d9c64f6a11c7 deal with StateSplits in GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15145
diff changeset
159 FrameState stateAfter = ((StateSplit) fixed).stateAfter();
d9c64f6a11c7 deal with StateSplits in GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15145
diff changeset
160 ((StateSplit) fixed).setStateAfter(null);
18937
ff232ff8d028 Add utility Node#hasNoUsages.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18163
diff changeset
161 if (stateAfter.hasNoUsages()) {
15438
34ae63dda6e8 Don't kill FrameState if it still has usages.
Roland Schatz <roland.schatz@oracle.com>
parents: 15285
diff changeset
162 killWithUnusedFloatingInputs(stateAfter);
34ae63dda6e8 Don't kill FrameState if it still has usages.
Roland Schatz <roland.schatz@oracle.com>
parents: 15285
diff changeset
163 }
15285
d9c64f6a11c7 deal with StateSplits in GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15145
diff changeset
164 }
16450
b650d0a98146 new GraphUtil.unlinkFixedNode utility method
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16403
diff changeset
165 unlinkFixedNode(fixed);
b650d0a98146 new GraphUtil.unlinkFixedNode utility method
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16403
diff changeset
166 killWithUnusedFloatingInputs(fixed);
b650d0a98146 new GraphUtil.unlinkFixedNode utility method
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16403
diff changeset
167 }
b650d0a98146 new GraphUtil.unlinkFixedNode utility method
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16403
diff changeset
168
b650d0a98146 new GraphUtil.unlinkFixedNode utility method
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16403
diff changeset
169 public static void unlinkFixedNode(FixedWithNextNode fixed) {
18997
2ccaaf5a6be4 Fix class comparison statements for BeginNode and MergeNode to reflect new class hierarchy.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18995
diff changeset
170 assert fixed.next() != null && fixed.predecessor() != null && fixed.isAlive() : fixed;
13794
2eb56f87b01e add GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@jku.at>
parents: 13327
diff changeset
171 FixedNode next = fixed.next();
2eb56f87b01e add GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@jku.at>
parents: 13327
diff changeset
172 fixed.setNext(null);
2eb56f87b01e add GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@jku.at>
parents: 13327
diff changeset
173 fixed.replaceAtPredecessor(next);
2eb56f87b01e add GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@jku.at>
parents: 13327
diff changeset
174 }
2eb56f87b01e add GraphUtil.removeFixedWithUnusedInputs
Lukas Stadler <lukas.stadler@jku.at>
parents: 13327
diff changeset
175
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
176 public static void checkRedundantPhi(PhiNode phiNode) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
177 if (phiNode.isDeleted() || phiNode.valueCount() == 1) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
178 return;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
179 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
180
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
181 ValueNode singleValue = phiNode.singleValue();
16588
4209ec855c1c cleanups and doc for PhiNode.singleValue
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16496
diff changeset
182 if (singleValue != PhiNode.MULTIPLE_VALUES) {
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
183 Collection<PhiNode> phiUsages = phiNode.usages().filter(PhiNode.class).snapshot();
7897
a58851061377 rename ValueProxyNode to ProxyNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7731
diff changeset
184 Collection<ProxyNode> proxyUsages = phiNode.usages().filter(ProxyNode.class).snapshot();
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9436
diff changeset
185 phiNode.graph().replaceFloating(phiNode, singleValue);
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
186 for (PhiNode phi : phiUsages) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
187 checkRedundantPhi(phi);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
188 }
7897
a58851061377 rename ValueProxyNode to ProxyNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7731
diff changeset
189 for (ProxyNode proxy : proxyUsages) {
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
190 checkRedundantProxy(proxy);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
191 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
192 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
193 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
194
7897
a58851061377 rename ValueProxyNode to ProxyNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7731
diff changeset
195 public static void checkRedundantProxy(ProxyNode vpn) {
16099
0d1f79e8add9 handle deleted proxies in GraphUtil.checkRedundantProxy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15471
diff changeset
196 if (vpn.isDeleted()) {
0d1f79e8add9 handle deleted proxies in GraphUtil.checkRedundantProxy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15471
diff changeset
197 return;
0d1f79e8add9 handle deleted proxies in GraphUtil.checkRedundantProxy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15471
diff changeset
198 }
18993
480bd3b1adcd Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18937
diff changeset
199 AbstractBeginNode proxyPoint = vpn.proxyPoint();
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
200 if (proxyPoint instanceof LoopExitNode) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
201 LoopExitNode exit = (LoopExitNode) proxyPoint;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
202 LoopBeginNode loopBegin = exit.loopBegin();
15009
e49f62425090 introduce non-ValueNode Proxy interface
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15002
diff changeset
203 Node vpnValue = vpn.value();
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
204 for (ValueNode v : loopBegin.stateAfter().values()) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
205 ValueNode v2 = v;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
206 if (loopBegin.isPhiAtMerge(v2)) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
207 v2 = ((PhiNode) v2).valueAt(loopBegin.forwardEnd());
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
208 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
209 if (vpnValue == v2) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
210 Collection<PhiNode> phiUsages = vpn.usages().filter(PhiNode.class).snapshot();
7897
a58851061377 rename ValueProxyNode to ProxyNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7731
diff changeset
211 Collection<ProxyNode> proxyUsages = vpn.usages().filter(ProxyNode.class).snapshot();
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9436
diff changeset
212 vpn.graph().replaceFloating(vpn, vpnValue);
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
213 for (PhiNode phi : phiUsages) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
214 checkRedundantPhi(phi);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
215 }
7897
a58851061377 rename ValueProxyNode to ProxyNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7731
diff changeset
216 for (ProxyNode proxy : proxyUsages) {
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
217 checkRedundantProxy(proxy);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
218 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
219 return;
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
220 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
221 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
222 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
223 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
224
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
225 public static void normalizeLoopBegin(LoopBeginNode begin) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
226 // Delete unnecessary loop phi functions, i.e., phi functions where all inputs are either
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
227 // the same or the phi itself.
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
228 for (PhiNode phi : begin.phis().snapshot()) {
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
229 GraphUtil.checkRedundantPhi(phi);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
230 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
231 for (LoopExitNode exit : begin.loopExits()) {
7897
a58851061377 rename ValueProxyNode to ProxyNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7731
diff changeset
232 for (ProxyNode vpn : exit.proxies().snapshot()) {
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
233 GraphUtil.checkRedundantProxy(vpn);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
234 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
235 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
236 }
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5203
diff changeset
237
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
238 /**
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
239 * Gets an approximate source code location for a node if possible.
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13794
diff changeset
240 *
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
241 * @return the StackTraceElements if an approximate source location is found, null otherwise
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
242 */
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
243 public static StackTraceElement[] approxSourceStackTraceElement(Node node) {
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
244 ArrayList<StackTraceElement> elements = new ArrayList<>();
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
245 Node n = node;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
246 while (n != null) {
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
247 if (n instanceof MethodCallTargetNode) {
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
248 elements.add(((MethodCallTargetNode) n).targetMethod().asStackTraceElement(-1));
9089
5ab06146e985 Rename "node()" methods in interfaces to "asNode"
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7897
diff changeset
249 n = ((MethodCallTargetNode) n).invoke().asNode();
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
250 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
251
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
252 if (n instanceof StateSplit) {
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
253 FrameState state = ((StateSplit) n).stateAfter();
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
254 elements.addAll(Arrays.asList(approxSourceStackTraceElement(state)));
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
255 break;
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
256 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
257 n = n.predecessor();
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
258 }
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
259 return elements.toArray(new StackTraceElement[elements.size()]);
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
260 }
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
261
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
262 /**
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
263 * Gets an approximate source code location for frame state.
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
264 *
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
265 * @return the StackTraceElements if an approximate source location is found, null otherwise
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
266 */
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
267 public static StackTraceElement[] approxSourceStackTraceElement(FrameState frameState) {
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
268 ArrayList<StackTraceElement> elements = new ArrayList<>();
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
269 FrameState state = frameState;
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
270 while (state != null) {
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
271 ResolvedJavaMethod method = state.method();
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
272 if (method != null) {
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
273 elements.add(method.asStackTraceElement(state.bci - 1));
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
274 }
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
275 state = state.outerFrameState();
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
276 }
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
277 return elements.toArray(new StackTraceElement[0]);
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
278 }
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
279
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
280 /**
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
281 * Gets an approximate source code location for a node, encoded as an exception, if possible.
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13794
diff changeset
282 *
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
283 * @return the exception with the location
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
284 */
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
285 public static RuntimeException approxSourceException(Node node, Throwable cause) {
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
286 final StackTraceElement[] elements = approxSourceStackTraceElement(node);
19524
d56b51bbdd98 Small fix in GraphUtil.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19523
diff changeset
287 return createBailoutException(cause == null ? "" : cause.getMessage(), cause, elements);
19521
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
288 }
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
289
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
290 /**
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
291 * Creates a bailout exception with the given stack trace elements and message.
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
292 *
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
293 * @param message the message of the exception
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
294 * @param elements the stack trace elements
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
295 * @return the exception
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
296 */
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
297 public static BailoutException createBailoutException(String message, Throwable cause, StackTraceElement[] elements) {
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
298 @SuppressWarnings("serial")
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
299 BailoutException exception = new BailoutException(cause, message) {
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
300
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
301 @Override
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
302 public final synchronized Throwable fillInStackTrace() {
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
303 setStackTrace(elements);
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
304 return this;
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
305 }
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
306 };
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
307 return exception;
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
308 }
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
309
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
310 /**
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
311 * Creates a runtime exception with the given stack trace elements and message.
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
312 *
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
313 * @param message the message of the exception
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
314 * @param elements the stack trace elements
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
315 * @return the exception
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
316 */
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
317 public static RuntimeException createRuntimeException(String message, Throwable cause, StackTraceElement[] elements) {
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
318 @SuppressWarnings("serial")
9c4168877444 Create CompilerAsserts tests. Add graph builder context on bailout. Consolidate CompilerAsserts Truffle API class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
319 RuntimeException exception = new RuntimeException(message, cause) {
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
320
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
321 @Override
7731
8b7996916df6 Make fillInStackTrace final and non-synchronized in exceptions that do not need stack trace.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
322 public final synchronized Throwable fillInStackTrace() {
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
323 setStackTrace(elements);
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
324 return this;
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
325 }
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
326 };
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
327 return exception;
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
328 }
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
329
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
330 /**
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
331 * Gets an approximate source code location for a node if possible.
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13794
diff changeset
332 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
333 * @return a file name and source line number in stack trace format (e.g. "String.java:32") if
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
334 * an approximate source location is found, null otherwise
7310
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
335 */
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
336 public static String approxSourceLocation(Node node) {
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
337 StackTraceElement[] stackTraceElements = approxSourceStackTraceElement(node);
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
338 if (stackTraceElements != null && stackTraceElements.length > 0) {
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
339 StackTraceElement top = stackTraceElements[0];
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
340 if (top.getFileName() != null && top.getLineNumber() >= 0) {
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
341 return top.getFileName() + ":" + top.getLineNumber();
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
342 }
79a7b761755c Added getLineNumberTable and getFileName capabilities.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7245
diff changeset
343 }
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
344 return null;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
345 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5487
diff changeset
346
5786
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
347 /**
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
348 * Returns a string representation of the given collection of objects.
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13794
diff changeset
349 *
5786
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
350 * @param objects The {@link Iterable} that will be used to iterate over the objects.
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
351 * @return A string of the format "[a, b, ...]".
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
352 */
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
353 public static String toString(Iterable<?> objects) {
5786
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
354 StringBuilder str = new StringBuilder();
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
355 str.append("[");
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
356 for (Object o : objects) {
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
357 str.append(o).append(", ");
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
358 }
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
359 if (str.length() > 1) {
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
360 str.setLength(str.length() - 2);
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
361 }
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
362 str.append("]");
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
363 return str.toString();
f69a406355b2 new tail duplication phase
Lukas Stadler <lukas.stadler@jku.at>
parents: 5693
diff changeset
364 }
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6318
diff changeset
365
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
366 /**
10762
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
367 * Gets the original value by iterating through all {@link ValueProxy ValueProxies}.
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13794
diff changeset
368 *
10762
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
369 * @param value The start value.
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
370 * @return The first non-proxy value encountered.
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
371 */
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
372 public static ValueNode unproxify(ValueNode value) {
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
373 ValueNode result = value;
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
374 while (result instanceof ValueProxy) {
15009
e49f62425090 introduce non-ValueNode Proxy interface
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15002
diff changeset
375 result = ((ValueProxy) result).getOriginalNode();
10762
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
376 }
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
377 return result;
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
378 }
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
379
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
380 /**
17340
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
381 * Looks for an {@link ArrayLengthProvider} while iterating through all {@link ValueProxy
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
382 * ValueProxies}.
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
383 *
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
384 * @param value The start value.
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
385 * @return The array length if one was found, or null otherwise.
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
386 */
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
387 public static ValueNode arrayLength(ValueNode value) {
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
388 ValueNode current = value;
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
389 do {
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
390 if (current instanceof ArrayLengthProvider) {
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
391 ValueNode length = ((ArrayLengthProvider) current).length();
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
392 if (length != null) {
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
393 return length;
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
394 }
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
395 }
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
396 if (current instanceof ValueProxy) {
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
397 current = ((ValueProxy) current).getOriginalNode();
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
398 } else {
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
399 break;
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
400 }
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
401 } while (true);
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
402 return null;
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
403 }
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
404
53e91025205f don't skip ValueProxy nodes while looking for ArrayLengthProviders
Lukas Stadler <lukas.stadler@oracle.com>
parents: 17328
diff changeset
405 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7310
diff changeset
406 * Tries to find an original value of the given node by traversing through proxies and
10762
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
407 * unambiguous phis. Note that this method will perform an exhaustive search through phis. It is
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
408 * intended to be used during graph building, when phi nodes aren't yet canonicalized.
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13794
diff changeset
409 *
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
410 * @param proxy The node whose original value should be determined.
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
411 */
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6318
diff changeset
412 public static ValueNode originalValue(ValueNode proxy) {
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6318
diff changeset
413 ValueNode v = proxy;
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6318
diff changeset
414 do {
17190
9ff6aee72c8b Change class hierarchy of ValueProxy that should only be transparent during graph building
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17064
diff changeset
415 if (v instanceof LimitedValueProxy) {
9ff6aee72c8b Change class hierarchy of ValueProxy that should only be transparent during graph building
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17064
diff changeset
416 v = ((LimitedValueProxy) v).getOriginalNode();
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
417 } else if (v instanceof PhiNode) {
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
418 v = ((PhiNode) v).singleValue();
16588
4209ec855c1c cleanups and doc for PhiNode.singleValue
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16496
diff changeset
419 if (v == PhiNode.MULTIPLE_VALUES) {
16496
b40984b06157 make PhiNode.singleValue behave correctly for null values (in guard phis)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16450
diff changeset
420 v = null;
b40984b06157 make PhiNode.singleValue behave correctly for null values (in guard phis)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16450
diff changeset
421 }
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
422 } else {
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
423 break;
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6318
diff changeset
424 }
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
425 } while (v != null);
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
426
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
427 if (v == null) {
12665
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
428 v = new OriginalValueSearch(proxy).result;
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
429 }
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
430 return v;
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
431 }
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
432
15387
fd435374bb93 moved tryKillUnused to GraphUtil
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15285
diff changeset
433 public static boolean tryKillUnused(Node node) {
18937
ff232ff8d028 Add utility Node#hasNoUsages.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18163
diff changeset
434 if (node.isAlive() && isFloatingNode().apply(node) && node.hasNoUsages()) {
15387
fd435374bb93 moved tryKillUnused to GraphUtil
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15285
diff changeset
435 killWithUnusedFloatingInputs(node);
fd435374bb93 moved tryKillUnused to GraphUtil
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15285
diff changeset
436 return true;
fd435374bb93 moved tryKillUnused to GraphUtil
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15285
diff changeset
437 }
fd435374bb93 moved tryKillUnused to GraphUtil
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15285
diff changeset
438 return false;
fd435374bb93 moved tryKillUnused to GraphUtil
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15285
diff changeset
439 }
fd435374bb93 moved tryKillUnused to GraphUtil
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 15285
diff changeset
440
12665
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
441 /**
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
442 * Exhaustive search for {@link GraphUtil#originalValue(ValueNode)} when a simple search fails.
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
443 * This can happen in the presence of complicated phi/proxy/phi constructs.
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
444 */
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
445 static class OriginalValueSearch {
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
446 ValueNode result;
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
447
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
448 public OriginalValueSearch(ValueNode proxy) {
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
449 NodeWorkList worklist = proxy.graph().createNodeWorkList();
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
450 worklist.add(proxy);
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
451 for (Node node : worklist) {
17190
9ff6aee72c8b Change class hierarchy of ValueProxy that should only be transparent during graph building
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17064
diff changeset
452 if (node instanceof LimitedValueProxy) {
9ff6aee72c8b Change class hierarchy of ValueProxy that should only be transparent during graph building
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17064
diff changeset
453 ValueNode originalValue = ((LimitedValueProxy) node).getOriginalNode();
12665
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
454 if (!process(originalValue, worklist)) {
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
455 return;
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
456 }
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
457 } else if (node instanceof PhiNode) {
12665
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
458 for (Node value : ((PhiNode) node).values()) {
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
459 if (!process((ValueNode) value, worklist)) {
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
460 return;
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
461 }
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
462 }
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
463 } else {
12665
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
464 if (!process((ValueNode) node, null)) {
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
465 return;
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
466 }
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6318
diff changeset
467 }
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6318
diff changeset
468 }
6444
5ebe3e5a892b fix bailouts due to insufficient balanced monitor checks
Lukas Stadler <lukas.stadler@jku.at>
parents: 6436
diff changeset
469 }
12665
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
470
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
471 /**
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
472 * Process a node as part of this search.
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13794
diff changeset
473 *
12665
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
474 * @param node the next node encountered in the search
13327
c258331fdde6 removed support for external nodes (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12665
diff changeset
475 * @param worklist if non-null, {@code node} will be added to this list. Otherwise,
c258331fdde6 removed support for external nodes (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12665
diff changeset
476 * {@code node} is treated as a candidate result.
12665
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
477 * @return true if the search should continue, false if a definitive {@link #result} has
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
478 * been found
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
479 */
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
480 private boolean process(ValueNode node, NodeWorkList worklist) {
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
481 if (node.isAlive()) {
13327
c258331fdde6 removed support for external nodes (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12665
diff changeset
482 if (worklist == null) {
12665
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
483 if (result == null) {
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
484 // Initial candidate result: continue search
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
485 result = node;
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
486 } else if (result != node) {
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
487 // Conflicts with existing candidate: stop search with null result
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
488 result = null;
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
489 return false;
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
490 }
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
491 } else {
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
492 worklist.add(node);
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
493 }
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
494 }
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
495 return true;
9db9e37ee4b8 fixes for regression in Jython performance
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
496 }
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6318
diff changeset
497 }
15471
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
498
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
499 /**
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
500 * Returns an iterator that will return the given node followed by all its predecessors, up
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17340
diff changeset
501 * until the point where {@link Node#predecessor()} returns null.
15471
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
502 *
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
503 * @param start the node at which to start iterating
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
504 */
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
505 public static NodeIterable<FixedNode> predecessorIterable(final FixedNode start) {
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
506 return new NodeIterable<FixedNode>() {
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
507 public Iterator<FixedNode> iterator() {
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
508 return new Iterator<FixedNode>() {
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
509 public FixedNode current = start;
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
510
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
511 public boolean hasNext() {
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
512 return current != null;
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
513 }
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
514
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
515 public FixedNode next() {
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
516 try {
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
517 return current;
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
518 } finally {
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
519 current = (FixedNode) current.predecessor();
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
520 }
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
521 }
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
522 };
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
523 }
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
524 };
ef315dfdda35 new GraphUtil.predecessorIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15468
diff changeset
525 }
16403
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
526
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
527 private static final class DefaultSimplifierTool implements SimplifierTool {
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
528 private final MetaAccessProvider metaAccess;
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
529 private final ConstantReflectionProvider constantReflection;
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
530 private final boolean canonicalizeReads;
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
531
19250
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 18997
diff changeset
532 public DefaultSimplifierTool(MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, boolean canonicalizeReads) {
16403
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
533 this.metaAccess = metaAccess;
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
534 this.constantReflection = constantReflection;
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
535 this.canonicalizeReads = canonicalizeReads;
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
536 }
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
537
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
538 public MetaAccessProvider getMetaAccess() {
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
539 return metaAccess;
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
540 }
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
541
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
542 public ConstantReflectionProvider getConstantReflection() {
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
543 return constantReflection;
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
544 }
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
545
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
546 public boolean canonicalizeReads() {
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
547 return canonicalizeReads;
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
548 }
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
549
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
550 public void deleteBranch(Node branch) {
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
551 branch.predecessor().replaceFirstSuccessor(branch, null);
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
552 GraphUtil.killCFG(branch, this);
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
553 }
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
554
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
555 public void removeIfUnused(Node node) {
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
556 GraphUtil.tryKillUnused(node);
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
557 }
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
558
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
559 public void addToWorkList(Node node) {
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
560 }
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
561
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
562 public void addToWorkList(Iterable<? extends Node> nodes) {
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
563 }
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
564 }
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
565
19250
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 18997
diff changeset
566 public static SimplifierTool getDefaultSimplifier(MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, boolean canonicalizeReads) {
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 18997
diff changeset
567 return new DefaultSimplifierTool(metaAccess, constantReflection, canonicalizeReads);
16403
39f9f052e5a8 Move DefaultCanonicalizerTool to GraphUtil and make it a DefaultSimplifierTool
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16331
diff changeset
568 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
569 }