Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractBeginNode.java @ 9646:183d33c76419
Removed ValueNode.dependencies
Introduced GuardedNode and GuardingNode interfaces
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 10 May 2013 18:28:30 +0200 |
parents | 19c5a07c7843 |
children | 81ebb0719dc5 |
rev | line source |
---|---|
9437
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
9442 | 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
9437
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.nodes; |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
9442 | 25 import static com.oracle.graal.graph.iterators.NodePredicates.*; |
26 | |
27 import java.util.*; | |
28 | |
29 import com.oracle.graal.graph.*; | |
30 import com.oracle.graal.graph.iterators.*; | |
9646
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
31 import com.oracle.graal.nodes.extended.*; |
9442 | 32 import com.oracle.graal.nodes.spi.*; |
9437
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.graal.nodes.type.*; |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 |
9646
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
35 public abstract class AbstractBeginNode extends FixedWithNextNode implements StateSplit, LIRLowerable, Simplifiable, Node.IterableNodeType, GuardingNode { |
9442 | 36 |
37 @Input(notDataflow = true) private FrameState stateAfter; | |
38 | |
39 public FrameState stateAfter() { | |
40 return stateAfter; | |
41 } | |
9437
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 |
9442 | 43 public void setStateAfter(FrameState x) { |
44 assert x == null || x.isAlive() : "frame state must be in a graph"; | |
45 updateUsages(stateAfter, x); | |
46 stateAfter = x; | |
47 } | |
48 | |
49 public boolean hasSideEffect() { | |
50 return false; | |
51 } | |
52 | |
53 protected AbstractBeginNode() { | |
9437
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 super(StampFactory.dependency()); |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 } |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 |
9442 | 57 protected AbstractBeginNode(Stamp stamp) { |
9437
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 super(stamp); |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 } |
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 |
9442 | 61 public static AbstractBeginNode begin(FixedNode with) { |
62 if (with instanceof AbstractBeginNode) { | |
63 return (AbstractBeginNode) with; | |
64 } | |
65 AbstractBeginNode begin = with.graph().add(new BeginNode()); | |
66 begin.setNext(with); | |
67 return begin; | |
68 } | |
69 | |
70 @Override | |
71 public void simplify(SimplifierTool tool) { | |
72 FixedNode prev = (FixedNode) this.predecessor(); | |
73 if (prev == null) { | |
74 // This is the start node. | |
75 } else if (prev instanceof ControlSplitNode) { | |
76 // This begin node is necessary. | |
77 } else { | |
78 // This begin node can be removed and all guards moved up to the preceding begin node. | |
79 prepareDelete(); | |
80 tool.addToWorkList(next()); | |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9442
diff
changeset
|
81 graph().removeFixed(this); |
9442 | 82 } |
83 } | |
84 | |
85 public static AbstractBeginNode prevBegin(FixedNode from) { | |
86 Node prevBegin = from; | |
87 while (prevBegin != null) { | |
88 if (prevBegin instanceof AbstractBeginNode) { | |
89 return (AbstractBeginNode) prevBegin; | |
90 } | |
91 prevBegin = prevBegin.predecessor(); | |
92 } | |
93 return null; | |
94 } | |
95 | |
96 private void evacuateGuards(FixedNode evacuateFrom) { | |
97 if (!usages().isEmpty()) { | |
98 AbstractBeginNode prevBegin = prevBegin(evacuateFrom); | |
99 assert prevBegin != null; | |
100 for (Node anchored : anchored().snapshot()) { | |
101 anchored.replaceFirstInput(this, prevBegin); | |
102 } | |
103 } | |
104 } | |
105 | |
106 public void prepareDelete() { | |
107 prepareDelete((FixedNode) predecessor()); | |
108 } | |
109 | |
110 public void prepareDelete(FixedNode evacuateFrom) { | |
111 removeProxies(); | |
112 evacuateGuards(evacuateFrom); | |
113 } | |
114 | |
115 public void removeProxies() { | |
116 for (ProxyNode vpn : proxies().snapshot()) { | |
117 // can not use graph.replaceFloating because vpn.value may be null during killCFG | |
118 vpn.replaceAtUsages(vpn.value()); | |
119 vpn.safeDelete(); | |
120 } | |
121 } | |
122 | |
123 @Override | |
124 public boolean verify() { | |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9442
diff
changeset
|
125 assertTrue(predecessor() != null || this == graph().start() || this instanceof MergeNode, "begin nodes must be connected"); |
9442 | 126 return super.verify(); |
127 } | |
128 | |
129 @Override | |
130 public void generate(LIRGeneratorTool gen) { | |
131 // nop | |
132 } | |
133 | |
134 public NodeIterable<GuardNode> guards() { | |
135 return usages().filter(GuardNode.class); | |
136 } | |
137 | |
138 public NodeIterable<Node> anchored() { | |
139 return usages().filter(isNotA(ProxyNode.class)); | |
140 } | |
141 | |
142 public NodeIterable<ProxyNode> proxies() { | |
143 return usages().filter(ProxyNode.class); | |
144 } | |
145 | |
146 public NodeIterable<FixedNode> getBlockNodes() { | |
147 return new AbstractNodeIterable<FixedNode>() { | |
148 | |
149 @Override | |
150 public Iterator<FixedNode> iterator() { | |
151 return new BlockNodeIterator(AbstractBeginNode.this); | |
152 } | |
153 }; | |
154 } | |
155 | |
156 private class BlockNodeIterator implements Iterator<FixedNode> { | |
157 | |
158 private FixedNode current; | |
159 | |
160 public BlockNodeIterator(FixedNode next) { | |
161 this.current = next; | |
162 } | |
163 | |
164 @Override | |
165 public boolean hasNext() { | |
166 return current != null; | |
167 } | |
168 | |
169 @Override | |
170 public FixedNode next() { | |
171 FixedNode ret = current; | |
172 if (ret == null) { | |
173 throw new NoSuchElementException(); | |
174 } | |
175 if (!(current instanceof FixedWithNextNode) || (current instanceof AbstractBeginNode && current != AbstractBeginNode.this)) { | |
176 current = null; | |
177 } else { | |
178 current = ((FixedWithNextNode) current).next(); | |
179 } | |
180 return ret; | |
181 } | |
182 | |
183 @Override | |
184 public void remove() { | |
185 throw new UnsupportedOperationException(); | |
186 } | |
187 } | |
9646
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
188 |
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
189 @Override |
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
190 public AbstractBeginNode asNode() { |
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
191 return this; |
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
192 } |
9437
7c23515c3e82
Add missing file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
193 } |