# HG changeset patch # User Thomas Wuerthinger # Date 1306240847 -7200 # Node ID 3e4d992fd31265bb81e932822db1f1da7e2b61af # Parent 398b8fa5dc8136c8f53c2741e66b77c056725b0d towards replacing computelinearscanorder with scheduler. diff -r 398b8fa5dc81 -r 3e4d992fd312 graal/GraalCompiler/src/com/oracle/max/graal/schedule/Block.java --- a/graal/GraalCompiler/src/com/oracle/max/graal/schedule/Block.java Tue May 24 13:55:56 2011 +0200 +++ b/graal/GraalCompiler/src/com/oracle/max/graal/schedule/Block.java Tue May 24 14:40:47 2011 +0200 @@ -24,17 +24,24 @@ import java.util.*; +import com.sun.c1x.ir.*; + public class Block { private int blockID; private final List successors = new ArrayList(); private final List predecessors = new ArrayList(); + private final List instructions = new ArrayList(); public List getSuccessors() { return Collections.unmodifiableList(successors); } + public List getInstructions() { + return instructions; + } + public List getPredecessors() { return Collections.unmodifiableList(predecessors); } diff -r 398b8fa5dc81 -r 3e4d992fd312 graal/GraalCompiler/src/com/oracle/max/graal/schedule/Schedule.java --- a/graal/GraalCompiler/src/com/oracle/max/graal/schedule/Schedule.java Tue May 24 13:55:56 2011 +0200 +++ b/graal/GraalCompiler/src/com/oracle/max/graal/schedule/Schedule.java Tue May 24 14:40:47 2011 +0200 @@ -26,6 +26,7 @@ import com.oracle.graal.graph.*; import com.sun.c1x.debug.*; +import com.sun.c1x.ir.*; public class Schedule { @@ -57,32 +58,43 @@ Block curBlock = nodeToBlock.get(n); if (curBlock == null) { curBlock = createBlock(); - nodeToBlock.set(n, curBlock); + return assignBlock(n, curBlock); } return curBlock; } - private void identifyBlocks() { - // Identify nodes that form the control flow. - final NodeBitMap topDownBitMap = NodeIterator.iterate(EdgeType.SUCCESSORS, graph.start(), null, null); - final NodeBitMap combinedBitMap = NodeIterator.iterate(EdgeType.PREDECESSORS, graph.end(), topDownBitMap, null); + private Block assignBlock(Node n, Block b) { + assert nodeToBlock.get(n) == null; + nodeToBlock.set(n, b); + b.getInstructions().add((Instruction) n); + return b; + } + private boolean isCFG(Node n) { + return n != null && (n instanceof Instruction); + } + + private void identifyBlocks() { // Identify blocks. final ArrayList blockBeginNodes = new ArrayList(); - NodeIterator.iterate(EdgeType.SUCCESSORS, graph.start(), combinedBitMap, new NodeVisitor() { + NodeIterator.iterate(EdgeType.SUCCESSORS, graph.start().successors().get(0), null, new NodeVisitor() { @Override - public void visit(Node n) { + public boolean visit(Node n) { + if (!isCFG(n)) { + return false; + } + Node singlePred = null; for (Node pred : n.predecessors()) { - if (pred != null && combinedBitMap.isMarked(pred)) { + if (isCFG(pred)) { if (singlePred == null) { singlePred = pred; } else { // We have more than one predecessor => we are a merge block. assignBlock(n); blockBeginNodes.add(n); - return; + return true; } } } @@ -95,18 +107,19 @@ // We have a single predecessor => check its successor count. int successorCount = 0; for (Node succ : singlePred.successors()) { - if (succ != null && combinedBitMap.isMarked(succ)) { + if (isCFG(succ)) { successorCount++; if (successorCount > 1) { // Our predecessor is a split => we need a new block. assignBlock(n); blockBeginNodes.add(n); - return; + return true; } } } - nodeToBlock.set(n, nodeToBlock.get(singlePred)); + assignBlock(n, nodeToBlock.get(singlePred)); } + return true; }} ); @@ -114,10 +127,14 @@ for (Node n : blockBeginNodes) { Block block = nodeToBlock.get(n); for (Node pred : n.predecessors()) { - Block predBlock = nodeToBlock.get(pred); - predBlock.addSuccessor(block); + if (isCFG(pred)) { + Block predBlock = nodeToBlock.get(pred); + predBlock.addSuccessor(block); + } } } + + //print(); } private void print() { diff -r 398b8fa5dc81 -r 3e4d992fd312 graal/GraalCompiler/src/com/sun/c1x/graph/IR.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Tue May 24 13:55:56 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Tue May 24 14:40:47 2011 +0200 @@ -80,12 +80,20 @@ C1XTimers.HIR_OPTIMIZE.start(); } + CriticalEdgeFinder finder = new CriticalEdgeFinder(this); + getHIRStartBlock().iteratePreOrder(finder); + finder.splitCriticalEdges(); + Schedule schedule = new Schedule(this.compilation.graph); List blocks = schedule.getBlocks(); NodeMap nodeToBlock = schedule.getNodeToBlock(); + /* orderedBlocks = new ArrayList(); Map map = new HashMap(); for (Block b : blocks) { - map.put(b, new LIRBlock(b.blockID())); + LIRBlock block = new LIRBlock(b.blockID()); + map.put(b, block); + block.setInstructions(b.getInstructions()); + orderedBlocks.add(block); } for (Block b : blocks) { @@ -96,12 +104,25 @@ for (Block pred : b.getPredecessors()) { map.get(b).blockPredecessors().add(map.get(pred)); } - } + }*/ + // TODO(tw): Schedule nodes within a block. - valueToBlock = computeLinearScanOrder(); + + + computeLinearScanOrder(); + + + valueToBlock = new HashMap(); + for (LIRBlock b : orderedBlocks) { + for (Instruction i : b.getInstructions()) { + valueToBlock.put(i, b); + } + } + startBlock = valueToBlock.get(getHIRStartBlock()); + assert startBlock != null; verifyAndPrint("After linear scan order"); if (C1XOptions.PrintTimers) { @@ -125,12 +146,9 @@ private Map makeLinearScanOrder() { - Map valueToBlock = new HashMap(); + if (orderedBlocks == null) { - if (orderedBlocks == null) { - CriticalEdgeFinder finder = new CriticalEdgeFinder(this); - getHIRStartBlock().iteratePreOrder(finder); - finder.splitCriticalEdges(); + Map valueToBlock = new HashMap(); ComputeLinearScanOrder computeLinearScanOrder = new ComputeLinearScanOrder(compilation.stats.blockCount, getHIRStartBlock()); List blocks = computeLinearScanOrder.linearScanOrder(); orderedBlocks = new ArrayList(); @@ -167,9 +185,6 @@ ++z; } - startBlock = valueToBlock.get(getHIRStartBlock()); - assert startBlock != null; - compilation.stats.loopCount = computeLinearScanOrder.numLoops(); } return valueToBlock; } diff -r 398b8fa5dc81 -r 3e4d992fd312 graal/GraalCompiler/src/com/sun/c1x/lir/LIRBlock.java --- a/graal/GraalCompiler/src/com/sun/c1x/lir/LIRBlock.java Tue May 24 13:55:56 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/lir/LIRBlock.java Tue May 24 14:40:47 2011 +0200 @@ -219,4 +219,8 @@ successors.clear(); predecessors.clear(); } + + public void setInstructions(List list) { + instructions = list; + } } diff -r 398b8fa5dc81 -r 3e4d992fd312 graal/GraalGraph/src/com/oracle/graal/graph/NodeIterator.java --- a/graal/GraalGraph/src/com/oracle/graal/graph/NodeIterator.java Tue May 24 13:55:56 2011 +0200 +++ b/graal/GraalGraph/src/com/oracle/graal/graph/NodeIterator.java Tue May 24 14:40:47 2011 +0200 @@ -35,7 +35,10 @@ while (nodes.size() > 0) { Node n = nodes.remove(); if (visitor != null) { - visitor.visit(n); + boolean followEdges = visitor.visit(n); + if (!followEdges) { + continue; + } } switch(e) { case INPUTS: diff -r 398b8fa5dc81 -r 3e4d992fd312 graal/GraalGraph/src/com/oracle/graal/graph/NodeVisitor.java --- a/graal/GraalGraph/src/com/oracle/graal/graph/NodeVisitor.java Tue May 24 13:55:56 2011 +0200 +++ b/graal/GraalGraph/src/com/oracle/graal/graph/NodeVisitor.java Tue May 24 14:40:47 2011 +0200 @@ -24,5 +24,5 @@ public interface NodeVisitor { - void visit(Node n); + boolean visit(Node n); }