43972
|
1 |
/*
|
55509
|
2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.phases.common;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.graph.Graph.NodeEvent.NODE_ADDED;
|
|
28 |
import static org.graalvm.compiler.graph.Graph.NodeEvent.ZERO_USAGES;
|
49873
|
29 |
import static jdk.internal.vm.compiler.word.LocationIdentity.any;
|
43972
|
30 |
|
|
31 |
import java.util.EnumSet;
|
|
32 |
import java.util.Iterator;
|
|
33 |
import java.util.List;
|
|
34 |
|
49873
|
35 |
import jdk.internal.vm.compiler.collections.EconomicMap;
|
|
36 |
import jdk.internal.vm.compiler.collections.EconomicSet;
|
|
37 |
import jdk.internal.vm.compiler.collections.Equivalence;
|
|
38 |
import jdk.internal.vm.compiler.collections.UnmodifiableMapCursor;
|
43972
|
39 |
import org.graalvm.compiler.core.common.cfg.Loop;
|
|
40 |
import org.graalvm.compiler.debug.DebugCloseable;
|
|
41 |
import org.graalvm.compiler.graph.Graph.NodeEventScope;
|
|
42 |
import org.graalvm.compiler.graph.Node;
|
|
43 |
import org.graalvm.compiler.nodes.AbstractBeginNode;
|
|
44 |
import org.graalvm.compiler.nodes.AbstractMergeNode;
|
|
45 |
import org.graalvm.compiler.nodes.FixedNode;
|
|
46 |
import org.graalvm.compiler.nodes.InvokeWithExceptionNode;
|
|
47 |
import org.graalvm.compiler.nodes.LoopBeginNode;
|
|
48 |
import org.graalvm.compiler.nodes.LoopEndNode;
|
|
49 |
import org.graalvm.compiler.nodes.LoopExitNode;
|
|
50 |
import org.graalvm.compiler.nodes.PhiNode;
|
58877
|
51 |
import org.graalvm.compiler.nodes.ProxyNode;
|
43972
|
52 |
import org.graalvm.compiler.nodes.ReturnNode;
|
|
53 |
import org.graalvm.compiler.nodes.StartNode;
|
|
54 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
55 |
import org.graalvm.compiler.nodes.ValueNodeUtil;
|
|
56 |
import org.graalvm.compiler.nodes.calc.FloatingNode;
|
|
57 |
import org.graalvm.compiler.nodes.cfg.Block;
|
|
58 |
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
|
|
59 |
import org.graalvm.compiler.nodes.cfg.HIRLoop;
|
|
60 |
import org.graalvm.compiler.nodes.memory.FloatableAccessNode;
|
|
61 |
import org.graalvm.compiler.nodes.memory.FloatingAccessNode;
|
|
62 |
import org.graalvm.compiler.nodes.memory.FloatingReadNode;
|
|
63 |
import org.graalvm.compiler.nodes.memory.MemoryAccess;
|
|
64 |
import org.graalvm.compiler.nodes.memory.MemoryAnchorNode;
|
|
65 |
import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
|
|
66 |
import org.graalvm.compiler.nodes.memory.MemoryMap;
|
|
67 |
import org.graalvm.compiler.nodes.memory.MemoryMapNode;
|
|
68 |
import org.graalvm.compiler.nodes.memory.MemoryNode;
|
|
69 |
import org.graalvm.compiler.nodes.memory.MemoryPhiNode;
|
|
70 |
import org.graalvm.compiler.nodes.memory.ReadNode;
|
|
71 |
import org.graalvm.compiler.nodes.util.GraphUtil;
|
|
72 |
import org.graalvm.compiler.phases.Phase;
|
52578
|
73 |
import org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener;
|
43972
|
74 |
import org.graalvm.compiler.phases.graph.ReentrantNodeIterator;
|
|
75 |
import org.graalvm.compiler.phases.graph.ReentrantNodeIterator.LoopInfo;
|
|
76 |
import org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure;
|
49873
|
77 |
import jdk.internal.vm.compiler.word.LocationIdentity;
|
43972
|
78 |
|
|
79 |
public class FloatingReadPhase extends Phase {
|
|
80 |
|
|
81 |
private boolean createFloatingReads;
|
|
82 |
private boolean createMemoryMapNodes;
|
|
83 |
|
|
84 |
public static class MemoryMapImpl implements MemoryMap {
|
|
85 |
|
46344
|
86 |
private final EconomicMap<LocationIdentity, MemoryNode> lastMemorySnapshot;
|
43972
|
87 |
|
|
88 |
public MemoryMapImpl(MemoryMapImpl memoryMap) {
|
46344
|
89 |
lastMemorySnapshot = EconomicMap.create(Equivalence.DEFAULT, memoryMap.lastMemorySnapshot);
|
43972
|
90 |
}
|
|
91 |
|
|
92 |
public MemoryMapImpl(StartNode start) {
|
46344
|
93 |
this();
|
43972
|
94 |
lastMemorySnapshot.put(any(), start);
|
|
95 |
}
|
|
96 |
|
|
97 |
public MemoryMapImpl() {
|
46344
|
98 |
lastMemorySnapshot = EconomicMap.create(Equivalence.DEFAULT);
|
43972
|
99 |
}
|
|
100 |
|
|
101 |
@Override
|
|
102 |
public MemoryNode getLastLocationAccess(LocationIdentity locationIdentity) {
|
|
103 |
MemoryNode lastLocationAccess;
|
|
104 |
if (locationIdentity.isImmutable()) {
|
|
105 |
return null;
|
|
106 |
} else {
|
|
107 |
lastLocationAccess = lastMemorySnapshot.get(locationIdentity);
|
|
108 |
if (lastLocationAccess == null) {
|
|
109 |
lastLocationAccess = lastMemorySnapshot.get(any());
|
|
110 |
assert lastLocationAccess != null;
|
|
111 |
}
|
|
112 |
return lastLocationAccess;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
@Override
|
46344
|
117 |
public Iterable<LocationIdentity> getLocations() {
|
|
118 |
return lastMemorySnapshot.getKeys();
|
43972
|
119 |
}
|
|
120 |
|
46344
|
121 |
public EconomicMap<LocationIdentity, MemoryNode> getMap() {
|
43972
|
122 |
return lastMemorySnapshot;
|
|
123 |
}
|
|
124 |
}
|
|
125 |
|
|
126 |
public FloatingReadPhase() {
|
|
127 |
this(true, false);
|
|
128 |
}
|
|
129 |
|
|
130 |
/**
|
|
131 |
* @param createFloatingReads specifies whether {@link FloatableAccessNode}s like
|
|
132 |
* {@link ReadNode} should be converted into floating nodes (e.g.,
|
|
133 |
* {@link FloatingReadNode}s) where possible
|
|
134 |
* @param createMemoryMapNodes a {@link MemoryMapNode} will be created for each return if this
|
|
135 |
* is true
|
|
136 |
*/
|
|
137 |
public FloatingReadPhase(boolean createFloatingReads, boolean createMemoryMapNodes) {
|
|
138 |
this.createFloatingReads = createFloatingReads;
|
|
139 |
this.createMemoryMapNodes = createMemoryMapNodes;
|
|
140 |
}
|
|
141 |
|
|
142 |
@Override
|
|
143 |
public float codeSizeIncrease() {
|
|
144 |
return 1.25f;
|
|
145 |
}
|
|
146 |
|
|
147 |
/**
|
|
148 |
* Removes nodes from a given set that (transitively) have a usage outside the set.
|
|
149 |
*/
|
46344
|
150 |
private static EconomicSet<Node> removeExternallyUsedNodes(EconomicSet<Node> set) {
|
43972
|
151 |
boolean change;
|
|
152 |
do {
|
|
153 |
change = false;
|
|
154 |
for (Iterator<Node> iter = set.iterator(); iter.hasNext();) {
|
|
155 |
Node node = iter.next();
|
|
156 |
for (Node usage : node.usages()) {
|
|
157 |
if (!set.contains(usage)) {
|
|
158 |
change = true;
|
|
159 |
iter.remove();
|
|
160 |
break;
|
|
161 |
}
|
|
162 |
}
|
|
163 |
}
|
|
164 |
} while (change);
|
|
165 |
return set;
|
|
166 |
}
|
|
167 |
|
46344
|
168 |
protected void processNode(FixedNode node, EconomicSet<LocationIdentity> currentState) {
|
43972
|
169 |
if (node instanceof MemoryCheckpoint.Single) {
|
58877
|
170 |
processIdentity(currentState, ((MemoryCheckpoint.Single) node).getKilledLocationIdentity());
|
43972
|
171 |
} else if (node instanceof MemoryCheckpoint.Multi) {
|
58877
|
172 |
for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getKilledLocationIdentities()) {
|
46344
|
173 |
processIdentity(currentState, identity);
|
43972
|
174 |
}
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
46344
|
178 |
private static void processIdentity(EconomicSet<LocationIdentity> currentState, LocationIdentity identity) {
|
|
179 |
if (identity.isMutable()) {
|
|
180 |
currentState.add(identity);
|
|
181 |
}
|
|
182 |
}
|
|
183 |
|
|
184 |
protected void processBlock(Block b, EconomicSet<LocationIdentity> currentState) {
|
43972
|
185 |
for (FixedNode n : b.getNodes()) {
|
|
186 |
processNode(n, currentState);
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
46344
|
190 |
private EconomicSet<LocationIdentity> processLoop(HIRLoop loop, EconomicMap<LoopBeginNode, EconomicSet<LocationIdentity>> modifiedInLoops) {
|
43972
|
191 |
LoopBeginNode loopBegin = (LoopBeginNode) loop.getHeader().getBeginNode();
|
46344
|
192 |
EconomicSet<LocationIdentity> result = modifiedInLoops.get(loopBegin);
|
43972
|
193 |
if (result != null) {
|
|
194 |
return result;
|
|
195 |
}
|
|
196 |
|
46344
|
197 |
result = EconomicSet.create(Equivalence.DEFAULT);
|
43972
|
198 |
for (Loop<Block> inner : loop.getChildren()) {
|
|
199 |
result.addAll(processLoop((HIRLoop) inner, modifiedInLoops));
|
|
200 |
}
|
|
201 |
|
|
202 |
for (Block b : loop.getBlocks()) {
|
|
203 |
if (b.getLoop() == loop) {
|
|
204 |
processBlock(b, result);
|
|
205 |
}
|
|
206 |
}
|
|
207 |
|
|
208 |
modifiedInLoops.put(loopBegin, result);
|
|
209 |
return result;
|
|
210 |
}
|
|
211 |
|
|
212 |
@Override
|
|
213 |
@SuppressWarnings("try")
|
|
214 |
protected void run(StructuredGraph graph) {
|
46344
|
215 |
EconomicMap<LoopBeginNode, EconomicSet<LocationIdentity>> modifiedInLoops = null;
|
43972
|
216 |
if (graph.hasLoops()) {
|
46344
|
217 |
modifiedInLoops = EconomicMap.create(Equivalence.IDENTITY);
|
43972
|
218 |
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
|
|
219 |
for (Loop<?> l : cfg.getLoops()) {
|
|
220 |
HIRLoop loop = (HIRLoop) l;
|
|
221 |
processLoop(loop, modifiedInLoops);
|
|
222 |
}
|
|
223 |
}
|
|
224 |
|
52578
|
225 |
EconomicSetNodeEventListener listener = new EconomicSetNodeEventListener(EnumSet.of(NODE_ADDED, ZERO_USAGES));
|
43972
|
226 |
try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
|
|
227 |
ReentrantNodeIterator.apply(new FloatingReadClosure(modifiedInLoops, createFloatingReads, createMemoryMapNodes), graph.start(), new MemoryMapImpl(graph.start()));
|
|
228 |
}
|
|
229 |
|
|
230 |
for (Node n : removeExternallyUsedNodes(listener.getNodes())) {
|
|
231 |
if (n.isAlive() && n instanceof FloatingNode) {
|
|
232 |
n.replaceAtUsages(null);
|
|
233 |
GraphUtil.killWithUnusedFloatingInputs(n);
|
|
234 |
}
|
|
235 |
}
|
|
236 |
if (createFloatingReads) {
|
|
237 |
assert !graph.isAfterFloatingReadPhase();
|
|
238 |
graph.setAfterFloatingReadPhase(true);
|
|
239 |
}
|
|
240 |
}
|
|
241 |
|
|
242 |
public static MemoryMapImpl mergeMemoryMaps(AbstractMergeNode merge, List<? extends MemoryMap> states) {
|
|
243 |
MemoryMapImpl newState = new MemoryMapImpl();
|
|
244 |
|
46344
|
245 |
EconomicSet<LocationIdentity> keys = EconomicSet.create(Equivalence.DEFAULT);
|
43972
|
246 |
for (MemoryMap other : states) {
|
|
247 |
keys.addAll(other.getLocations());
|
|
248 |
}
|
|
249 |
assert checkNoImmutableLocations(keys);
|
|
250 |
|
|
251 |
for (LocationIdentity key : keys) {
|
|
252 |
int mergedStatesCount = 0;
|
|
253 |
boolean isPhi = false;
|
|
254 |
MemoryNode merged = null;
|
|
255 |
for (MemoryMap state : states) {
|
|
256 |
MemoryNode last = state.getLastLocationAccess(key);
|
|
257 |
if (isPhi) {
|
54601
|
258 |
// Fortify: Suppress Null Deference false positive (`isPhi == true` implies
|
|
259 |
// `merged != null`)
|
43972
|
260 |
((MemoryPhiNode) merged).addInput(ValueNodeUtil.asNode(last));
|
|
261 |
} else {
|
|
262 |
if (merged == last) {
|
|
263 |
// nothing to do
|
|
264 |
} else if (merged == null) {
|
|
265 |
merged = last;
|
|
266 |
} else {
|
|
267 |
MemoryPhiNode phi = merge.graph().addWithoutUnique(new MemoryPhiNode(merge, key));
|
|
268 |
for (int j = 0; j < mergedStatesCount; j++) {
|
|
269 |
phi.addInput(ValueNodeUtil.asNode(merged));
|
|
270 |
}
|
|
271 |
phi.addInput(ValueNodeUtil.asNode(last));
|
|
272 |
merged = phi;
|
|
273 |
isPhi = true;
|
|
274 |
}
|
|
275 |
}
|
|
276 |
mergedStatesCount++;
|
|
277 |
}
|
58877
|
278 |
newState.getMap().put(key, merged);
|
43972
|
279 |
}
|
|
280 |
return newState;
|
|
281 |
|
|
282 |
}
|
|
283 |
|
46344
|
284 |
private static boolean checkNoImmutableLocations(EconomicSet<LocationIdentity> keys) {
|
43972
|
285 |
keys.forEach(t -> {
|
46344
|
286 |
assert t.isMutable();
|
43972
|
287 |
});
|
|
288 |
return true;
|
|
289 |
}
|
|
290 |
|
|
291 |
public static class FloatingReadClosure extends NodeIteratorClosure<MemoryMapImpl> {
|
|
292 |
|
46344
|
293 |
private final EconomicMap<LoopBeginNode, EconomicSet<LocationIdentity>> modifiedInLoops;
|
43972
|
294 |
private boolean createFloatingReads;
|
|
295 |
private boolean createMemoryMapNodes;
|
|
296 |
|
46344
|
297 |
public FloatingReadClosure(EconomicMap<LoopBeginNode, EconomicSet<LocationIdentity>> modifiedInLoops, boolean createFloatingReads, boolean createMemoryMapNodes) {
|
43972
|
298 |
this.modifiedInLoops = modifiedInLoops;
|
|
299 |
this.createFloatingReads = createFloatingReads;
|
|
300 |
this.createMemoryMapNodes = createMemoryMapNodes;
|
|
301 |
}
|
|
302 |
|
|
303 |
@Override
|
|
304 |
protected MemoryMapImpl processNode(FixedNode node, MemoryMapImpl state) {
|
58877
|
305 |
|
|
306 |
if (node instanceof LoopExitNode) {
|
|
307 |
final LoopExitNode loopExitNode = (LoopExitNode) node;
|
|
308 |
final EconomicSet<LocationIdentity> modifiedInLoop = modifiedInLoops.get(loopExitNode.loopBegin());
|
|
309 |
final boolean anyModified = modifiedInLoop.contains(LocationIdentity.any());
|
|
310 |
state.getMap().replaceAll((locationIdentity, memoryNode) -> (anyModified || modifiedInLoop.contains(locationIdentity))
|
|
311 |
? ProxyNode.forMemory(memoryNode, loopExitNode, locationIdentity)
|
|
312 |
: memoryNode);
|
|
313 |
}
|
|
314 |
|
43972
|
315 |
if (node instanceof MemoryAnchorNode) {
|
|
316 |
processAnchor((MemoryAnchorNode) node, state);
|
|
317 |
return state;
|
|
318 |
}
|
|
319 |
|
|
320 |
if (node instanceof MemoryAccess) {
|
|
321 |
processAccess((MemoryAccess) node, state);
|
|
322 |
}
|
|
323 |
|
51436
|
324 |
if (createFloatingReads && node instanceof FloatableAccessNode) {
|
43972
|
325 |
processFloatable((FloatableAccessNode) node, state);
|
58877
|
326 |
}
|
|
327 |
if (node instanceof MemoryCheckpoint.Single) {
|
43972
|
328 |
processCheckpoint((MemoryCheckpoint.Single) node, state);
|
|
329 |
} else if (node instanceof MemoryCheckpoint.Multi) {
|
|
330 |
processCheckpoint((MemoryCheckpoint.Multi) node, state);
|
|
331 |
}
|
|
332 |
assert MemoryCheckpoint.TypeAssertion.correctType(node) : node;
|
|
333 |
|
|
334 |
if (createMemoryMapNodes && node instanceof ReturnNode) {
|
58877
|
335 |
((ReturnNode) node).setMemoryMap(node.graph().unique(new MemoryMapNode(state.getMap())));
|
43972
|
336 |
}
|
|
337 |
return state;
|
|
338 |
}
|
|
339 |
|
|
340 |
/**
|
|
341 |
* Improve the memory graph by re-wiring all usages of a {@link MemoryAnchorNode} to the
|
|
342 |
* real last access location.
|
|
343 |
*/
|
|
344 |
private static void processAnchor(MemoryAnchorNode anchor, MemoryMapImpl state) {
|
|
345 |
for (Node node : anchor.usages().snapshot()) {
|
|
346 |
if (node instanceof MemoryAccess) {
|
|
347 |
MemoryAccess access = (MemoryAccess) node;
|
|
348 |
if (access.getLastLocationAccess() == anchor) {
|
|
349 |
MemoryNode lastLocationAccess = state.getLastLocationAccess(access.getLocationIdentity());
|
|
350 |
assert lastLocationAccess != null;
|
|
351 |
access.setLastLocationAccess(lastLocationAccess);
|
|
352 |
}
|
|
353 |
}
|
|
354 |
}
|
|
355 |
|
|
356 |
if (anchor.hasNoUsages()) {
|
|
357 |
anchor.graph().removeFixed(anchor);
|
|
358 |
}
|
|
359 |
}
|
|
360 |
|
|
361 |
private static void processAccess(MemoryAccess access, MemoryMapImpl state) {
|
|
362 |
LocationIdentity locationIdentity = access.getLocationIdentity();
|
|
363 |
if (!locationIdentity.equals(LocationIdentity.any())) {
|
|
364 |
MemoryNode lastLocationAccess = state.getLastLocationAccess(locationIdentity);
|
|
365 |
access.setLastLocationAccess(lastLocationAccess);
|
|
366 |
}
|
|
367 |
}
|
|
368 |
|
|
369 |
private static void processCheckpoint(MemoryCheckpoint.Single checkpoint, MemoryMapImpl state) {
|
58877
|
370 |
processIdentity(checkpoint.getKilledLocationIdentity(), checkpoint, state);
|
43972
|
371 |
}
|
|
372 |
|
|
373 |
private static void processCheckpoint(MemoryCheckpoint.Multi checkpoint, MemoryMapImpl state) {
|
58877
|
374 |
for (LocationIdentity identity : checkpoint.getKilledLocationIdentities()) {
|
43972
|
375 |
processIdentity(identity, checkpoint, state);
|
|
376 |
}
|
|
377 |
}
|
|
378 |
|
|
379 |
private static void processIdentity(LocationIdentity identity, MemoryCheckpoint checkpoint, MemoryMapImpl state) {
|
|
380 |
if (identity.isAny()) {
|
58877
|
381 |
state.getMap().clear();
|
43972
|
382 |
}
|
46344
|
383 |
if (identity.isMutable()) {
|
58877
|
384 |
state.getMap().put(identity, checkpoint);
|
46344
|
385 |
}
|
43972
|
386 |
}
|
|
387 |
|
|
388 |
@SuppressWarnings("try")
|
|
389 |
private static void processFloatable(FloatableAccessNode accessNode, MemoryMapImpl state) {
|
|
390 |
StructuredGraph graph = accessNode.graph();
|
|
391 |
LocationIdentity locationIdentity = accessNode.getLocationIdentity();
|
|
392 |
if (accessNode.canFloat()) {
|
|
393 |
assert accessNode.getNullCheck() == false;
|
|
394 |
MemoryNode lastLocationAccess = state.getLastLocationAccess(locationIdentity);
|
|
395 |
try (DebugCloseable position = accessNode.withNodeSourcePosition()) {
|
55509
|
396 |
FloatingAccessNode floatingNode = accessNode.asFloatingNode();
|
|
397 |
assert floatingNode.getLastLocationAccess() == lastLocationAccess;
|
43972
|
398 |
graph.replaceFixedWithFloating(accessNode, floatingNode);
|
|
399 |
}
|
|
400 |
}
|
|
401 |
}
|
|
402 |
|
|
403 |
@Override
|
|
404 |
protected MemoryMapImpl merge(AbstractMergeNode merge, List<MemoryMapImpl> states) {
|
|
405 |
return mergeMemoryMaps(merge, states);
|
|
406 |
}
|
|
407 |
|
|
408 |
@Override
|
|
409 |
protected MemoryMapImpl afterSplit(AbstractBeginNode node, MemoryMapImpl oldState) {
|
|
410 |
MemoryMapImpl result = new MemoryMapImpl(oldState);
|
|
411 |
if (node.predecessor() instanceof InvokeWithExceptionNode) {
|
|
412 |
/*
|
|
413 |
* InvokeWithException cannot be the lastLocationAccess for a FloatingReadNode.
|
|
414 |
* Since it is both the invoke and a control flow split, the scheduler cannot
|
|
415 |
* schedule anything immediately after the invoke. It can only schedule in the
|
|
416 |
* normal or exceptional successor - and we have to tell the scheduler here which
|
|
417 |
* side it needs to choose by putting in the location identity on both successors.
|
|
418 |
*/
|
|
419 |
InvokeWithExceptionNode invoke = (InvokeWithExceptionNode) node.predecessor();
|
58877
|
420 |
result.getMap().put(invoke.getKilledLocationIdentity(), (MemoryCheckpoint) node);
|
43972
|
421 |
}
|
|
422 |
return result;
|
|
423 |
}
|
|
424 |
|
|
425 |
@Override
|
46344
|
426 |
protected EconomicMap<LoopExitNode, MemoryMapImpl> processLoop(LoopBeginNode loop, MemoryMapImpl initialState) {
|
|
427 |
EconomicSet<LocationIdentity> modifiedLocations = modifiedInLoops.get(loop);
|
|
428 |
EconomicMap<LocationIdentity, MemoryPhiNode> phis = EconomicMap.create(Equivalence.DEFAULT);
|
43972
|
429 |
if (modifiedLocations.contains(LocationIdentity.any())) {
|
|
430 |
// create phis for all locations if ANY is modified in the loop
|
46344
|
431 |
modifiedLocations = EconomicSet.create(Equivalence.DEFAULT, modifiedLocations);
|
58877
|
432 |
modifiedLocations.addAll(initialState.getMap().getKeys());
|
43972
|
433 |
}
|
|
434 |
|
|
435 |
for (LocationIdentity location : modifiedLocations) {
|
|
436 |
createMemoryPhi(loop, initialState, phis, location);
|
|
437 |
}
|
58877
|
438 |
initialState.getMap().putAll(phis);
|
43972
|
439 |
|
|
440 |
LoopInfo<MemoryMapImpl> loopInfo = ReentrantNodeIterator.processLoop(this, loop, initialState);
|
|
441 |
|
46344
|
442 |
UnmodifiableMapCursor<LoopEndNode, MemoryMapImpl> endStateCursor = loopInfo.endStates.getEntries();
|
|
443 |
while (endStateCursor.advance()) {
|
|
444 |
int endIndex = loop.phiPredecessorIndex(endStateCursor.getKey());
|
|
445 |
UnmodifiableMapCursor<LocationIdentity, MemoryPhiNode> phiCursor = phis.getEntries();
|
|
446 |
while (phiCursor.advance()) {
|
|
447 |
LocationIdentity key = phiCursor.getKey();
|
|
448 |
PhiNode phi = phiCursor.getValue();
|
|
449 |
phi.initializeValueAt(endIndex, ValueNodeUtil.asNode(endStateCursor.getValue().getLastLocationAccess(key)));
|
43972
|
450 |
}
|
|
451 |
}
|
|
452 |
return loopInfo.exitStates;
|
|
453 |
}
|
|
454 |
|
46344
|
455 |
private static void createMemoryPhi(LoopBeginNode loop, MemoryMapImpl initialState, EconomicMap<LocationIdentity, MemoryPhiNode> phis, LocationIdentity location) {
|
43972
|
456 |
MemoryPhiNode phi = loop.graph().addWithoutUnique(new MemoryPhiNode(loop, location));
|
|
457 |
phi.addInput(ValueNodeUtil.asNode(initialState.getLastLocationAccess(location)));
|
|
458 |
phis.put(location, phi);
|
|
459 |
}
|
|
460 |
}
|
|
461 |
}
|