Mercurial > hg > truffle
comparison graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GraphDecoder.java @ 20985:eebb05f2d1e8
Fixes for GraphPE
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Wed, 15 Apr 2015 21:01:33 -0700 |
parents | c7f1ab98d950 |
children | acc86d08e1cc |
comparison
equal
deleted
inserted
replaced
20984:6361fa2e3321 | 20985:eebb05f2d1e8 |
---|---|
250 } | 250 } |
251 | 251 |
252 public final void decode(StructuredGraph graph, EncodedGraph encodedGraph) { | 252 public final void decode(StructuredGraph graph, EncodedGraph encodedGraph) { |
253 MethodScope methodScope = new MethodScope(graph, encodedGraph, LoopExplosionKind.NONE); | 253 MethodScope methodScope = new MethodScope(graph, encodedGraph, LoopExplosionKind.NONE); |
254 decode(methodScope, null); | 254 decode(methodScope, null); |
255 cleanupGraph(methodScope); | 255 cleanupGraph(methodScope, null); |
256 methodScope.graph.verify(); | 256 methodScope.graph.verify(); |
257 } | 257 } |
258 | 258 |
259 protected final void decode(MethodScope methodScope, FixedWithNextNode startNode) { | 259 protected final void decode(MethodScope methodScope, FixedWithNextNode startNode) { |
260 Graph.Mark start = methodScope.graph.getMark(); | |
260 LoopScope loopScope = new LoopScope(methodScope); | 261 LoopScope loopScope = new LoopScope(methodScope); |
261 FixedNode firstNode; | 262 FixedNode firstNode; |
262 if (startNode != null) { | 263 if (startNode != null) { |
263 firstNode = makeStubNode(methodScope, loopScope, GraphEncoder.FIRST_NODE_ORDER_ID); | 264 firstNode = makeStubNode(methodScope, loopScope, GraphEncoder.FIRST_NODE_ORDER_ID); |
264 startNode.setNext(firstNode); | 265 startNode.setNext(firstNode); |
282 loopScope = loopScope.outer; | 283 loopScope = loopScope.outer; |
283 } | 284 } |
284 } | 285 } |
285 | 286 |
286 if (methodScope.loopExplosion == LoopExplosionKind.MERGE_EXPLODE) { | 287 if (methodScope.loopExplosion == LoopExplosionKind.MERGE_EXPLODE) { |
287 cleanupGraph(methodScope); | 288 /* |
289 * The startNode can get deleted during graph cleanup, so we use its predecessor (if | |
290 * available) as the starting point for loop detection. | |
291 */ | |
292 FixedNode detectLoopsStart = startNode.predecessor() != null ? (FixedNode) startNode.predecessor() : startNode; | |
293 cleanupGraph(methodScope, start); | |
288 Debug.dump(methodScope.graph, "Before loop detection"); | 294 Debug.dump(methodScope.graph, "Before loop detection"); |
289 detectLoops(methodScope.graph, firstNode); | 295 detectLoops(methodScope.graph, detectLoopsStart); |
290 } | 296 } |
291 } | 297 } |
292 | 298 |
293 protected LoopScope processNextNode(MethodScope methodScope, LoopScope loopScope) { | 299 protected LoopScope processNextNode(MethodScope methodScope, LoopScope loopScope) { |
294 int nodeOrderId = loopScope.nodesToProcess.nextSetBit(0); | 300 int nodeOrderId = loopScope.nodesToProcess.nextSetBit(0); |
1109 for (LoopBeginNode innerInner : innerLoopsMap.get(inner)) { | 1115 for (LoopBeginNode innerInner : innerLoopsMap.get(inner)) { |
1110 addLoopExits(currentGraph, loopBegin, innerInner, innerLoopsMap, visited); | 1116 addLoopExits(currentGraph, loopBegin, innerInner, innerLoopsMap, visited); |
1111 } | 1117 } |
1112 } | 1118 } |
1113 | 1119 |
1114 protected void cleanupGraph(MethodScope methodScope) { | 1120 protected void cleanupGraph(MethodScope methodScope, Graph.Mark start) { |
1115 assert verifyEdges(methodScope); | 1121 assert verifyEdges(methodScope); |
1116 | 1122 |
1117 Debug.dump(methodScope.graph, "Before removing redundant merges"); | 1123 Debug.dump(methodScope.graph, "Before removing redundant merges"); |
1118 for (MergeNode mergeNode : methodScope.graph.getNodes(MergeNode.TYPE)) { | 1124 for (Node node : methodScope.graph.getNewNodes(start)) { |
1119 if (mergeNode.forwardEndCount() == 1) { | 1125 if (node instanceof MergeNode) { |
1120 methodScope.graph.reduceTrivialMerge(mergeNode); | 1126 MergeNode mergeNode = (MergeNode) node; |
1127 if (mergeNode.forwardEndCount() == 1) { | |
1128 methodScope.graph.reduceTrivialMerge(mergeNode); | |
1129 } | |
1121 } | 1130 } |
1122 } | 1131 } |
1123 | 1132 |
1124 Debug.dump(methodScope.graph, "Before removing redundant begins"); | 1133 Debug.dump(methodScope.graph, "Before removing redundant begins"); |
1125 for (Node node : methodScope.graph.getNodes()) { | 1134 for (Node node : methodScope.graph.getNewNodes(start)) { |
1126 if (node instanceof BeginNode || node instanceof KillingBeginNode) { | 1135 if (node instanceof BeginNode || node instanceof KillingBeginNode) { |
1127 if (!(node.predecessor() instanceof ControlSplitNode) && node.hasNoUsages()) { | 1136 if (!(node.predecessor() instanceof ControlSplitNode) && node.hasNoUsages()) { |
1128 GraphUtil.unlinkFixedNode((AbstractBeginNode) node); | 1137 GraphUtil.unlinkFixedNode((AbstractBeginNode) node); |
1129 node.safeDelete(); | 1138 node.safeDelete(); |
1130 } | 1139 } |
1131 } | 1140 } |
1132 } | 1141 } |
1133 | 1142 |
1134 Debug.dump(methodScope.graph, "Before removing unused non-fixed nodes"); | 1143 Debug.dump(methodScope.graph, "Before removing unused non-fixed nodes"); |
1135 for (Node node : methodScope.graph.getNodes()) { | 1144 for (Node node : methodScope.graph.getNewNodes(start)) { |
1136 if (!(node instanceof FixedNode) && node.hasNoUsages()) { | 1145 if (!(node instanceof FixedNode) && node.hasNoUsages()) { |
1137 GraphUtil.killCFG(node); | 1146 GraphUtil.killCFG(node); |
1138 } | 1147 } |
1139 } | 1148 } |
1140 } | 1149 } |