# HG changeset patch # User Doug Simon # Date 1338395891 -7200 # Node ID 87dfecd51e712c995dc924311112387058b50cc9 # Parent a5e43a18ac524da94baff202fc7e50b1caa9e463# Parent 071f24ba116e67a64a80754f10f3e816e5126a5f Merge. diff -r a5e43a18ac52 -r 87dfecd51e71 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopTransformUtil.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopTransformUtil.java Wed May 30 18:34:11 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopTransformUtil.java Wed May 30 18:38:11 2012 +0200 @@ -35,7 +35,7 @@ } public static void peel(Loop loop, SuperBlock wholeLoop) { - SuperBlock peel = wholeLoop.duplicate(); // duplicates the nodes, merges early exits + SuperBlock peel = wholeLoop.duplicate(true); // duplicates the nodes, merges early exits peel.insertBefore(loop.loopBegin().forwardEnd()); // connects peeled part's CFG @@ -43,7 +43,7 @@ resolver.wholeLoop(wholeLoop).peeled(peel); // block (comming from the loop) was peeled into peel resolver.resolve(); - peel.finish(); + peel.finishDuplication(); } public static SuperBlock wholeLoop(Loop loop) { diff -r a5e43a18ac52 -r 87dfecd51e71 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/SuperBlock.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/SuperBlock.java Wed May 30 18:34:11 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/SuperBlock.java Wed May 30 18:38:11 2012 +0200 @@ -38,7 +38,8 @@ protected List earlyExits; protected Map duplicationMapping; protected SuperBlock original; - protected NodeBitMap loopNodes; + protected NodeBitMap allNodes; + protected NodeBitMap allNodesExcludeLoopPhi; public SuperBlock(BeginNode entry, BeginNode exit, List blocks, List earlyExits) { this.entry = entry; @@ -57,31 +58,45 @@ return entry; } - public NodeBitMap loopNodes() { - if (loopNodes == null) { - loopNodes = computeNodes(); + public NodeBitMap nodes() { + if (allNodes == null) { + allNodes = computeNodes(); } - return loopNodes; + return allNodes; + } + + private NodeBitMap nodesExcludeLoopPhi() { + if (allNodesExcludeLoopPhi == null) { + allNodesExcludeLoopPhi = nodes().copy(); + if (entry instanceof LoopBeginNode) { + for (PhiNode phi : ((LoopBeginNode) entry).phis()) { + allNodesExcludeLoopPhi.clear(phi); + } + } + } + return allNodesExcludeLoopPhi; } public SuperBlock duplicate() { - NodeBitMap nodes = loopNodes(); + return duplicate(false); + } + + public SuperBlock duplicate(boolean excludeLoop) { + NodeBitMap nodes = nodes(); Map replacements = new HashMap<>(); StructuredGraph graph = (StructuredGraph) entry.graph(); - BeginNode newEntry = graph.add(new BeginNode()); - BeginNode newExit = null; + if (excludeLoop || (entry instanceof MergeNode && !(entry instanceof LoopBeginNode))) { + replacements.put(entry, graph.add(new BeginNode())); // no merge/loop begin + } List newEarlyExits = new ArrayList<>(earlyExits.size()); - if (!(exit instanceof MergeNode)) { - newExit = graph.add(new BeginNode()); - replacements.put(exit, newExit); - } - replacements.put(entry, newEntry); // no merge/loop begin for (BeginNode earlyExit : earlyExits) { BeginNode newEarlyExit = graph.add(new BeginNode()); newEarlyExits.add(newEarlyExit); replacements.put(earlyExit, newEarlyExit); } - if (exit instanceof LoopBeginNode) { + if (exit instanceof LoopBeginNode && excludeLoop) { + assert entry == exit; + nodes = nodesExcludeLoopPhi(); for (LoopEndNode end : ((LoopBeginNode) exit).loopEnds()) { if (nodes.isMarked(end)) { replacements.put(end, graph.add(new EndNode())); @@ -89,8 +104,14 @@ } } Map duplicates = graph.addDuplicates(nodes, replacements); - if (exit instanceof MergeNode) { + BeginNode newExit; + if (excludeLoop || (exit instanceof MergeNode && !(exit instanceof LoopBeginNode))) { newExit = mergeExits(replacements, duplicates); + } else if (exit != entry) { + newExit = graph.add(new BeginNode()); + replacements.put(exit, newExit); + } else { + newExit = (BeginNode) duplicates.get(exit); } List newBlocks = new ArrayList<>(blocks.size()); @@ -105,7 +126,7 @@ for (Entry e : replacements.entrySet()) { duplicates.put(e.getKey(), e.getValue()); } - SuperBlock superBlock = new SuperBlock(newEntry, newExit, newBlocks, newEarlyExits); + SuperBlock superBlock = new SuperBlock((BeginNode) duplicates.get(entry), newExit, newBlocks, newEarlyExits); superBlock.duplicationMapping = duplicates; superBlock.original = this; return superBlock; @@ -163,7 +184,7 @@ return newExit; } - public void finish() { + public void finishDuplication() { if (original != null) { mergeEarlyExits((StructuredGraph) entry.graph(), original.earlyExits, duplicationMapping); } @@ -376,12 +397,6 @@ } } - if (entry instanceof LoopBeginNode) { - for (PhiNode phi : ((LoopBeginNode) entry).phis()) { - nodes.clear(phi); - } - } - return nodes; } diff -r a5e43a18ac52 -r 87dfecd51e71 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeBitMap.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeBitMap.java Wed May 30 18:34:11 2012 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeBitMap.java Wed May 30 18:38:11 2012 +0200 @@ -36,9 +36,13 @@ } public NodeBitMap(Graph graph, boolean autoGrow) { + this(graph, autoGrow, new BitMap(graph.nodeIdCount())); + } + + private NodeBitMap(Graph graph, boolean autoGrow, BitMap bits) { this.graph = graph; this.autoGrow = autoGrow; - bitMap = new BitMap(graph.nodeIdCount()); + bitMap = bits; } public Graph graph() { @@ -178,4 +182,8 @@ public int cardinality() { return bitMap.cardinality(); } + + public NodeBitMap copy() { + return new NodeBitMap(graph, autoGrow, bitMap.copy()); + } } diff -r a5e43a18ac52 -r 87dfecd51e71 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java Wed May 30 18:34:11 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java Wed May 30 18:38:11 2012 +0200 @@ -460,7 +460,7 @@ StructuredGraph graph = new StructuredGraph(); LocalNode receiver = graph.unique(new LocalNode(0, StampFactory.objectNonNull())); SafeReadNode klassOop = safeReadHub(graph, receiver, StructuredGraph.INVALID_GRAPH_ID); - Stamp resultStamp = StampFactory.declared(getType(Class.class)); + Stamp resultStamp = StampFactory.declaredNonNull(getType(Class.class)); FloatingReadNode result = graph.unique(new FloatingReadNode(klassOop, LocationNode.create(LocationNode.FINAL_LOCATION, CiKind.Object, config.classMirrorOffset, graph), null, resultStamp)); ReturnNode ret = graph.add(new ReturnNode(result)); graph.start().setNext(klassOop);