# HG changeset patch # User Thomas Wuerthinger # Date 1358514467 -3600 # Node ID 799dd373fcb65a979185922149e16b94e7d76b31 # Parent 994f7ed25a46590370be2f4eede7b6f3f1d2452e Remove caching of sorted blocks in LSRA. diff -r 994f7ed25a46 -r 799dd373fcb6 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java Fri Jan 18 12:20:25 2013 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java Fri Jan 18 14:07:47 2013 +0100 @@ -100,7 +100,7 @@ /** * List of blocks in linear-scan order. This is only correct as long as the CFG does not change. */ - final Block[] sortedBlocks; + final List sortedBlocks; /** * Map from {@linkplain #operandNumber(Value) operand numbers} to intervals. @@ -160,7 +160,7 @@ this.ir = ir; this.gen = gen; this.frameMap = frameMap; - this.sortedBlocks = ir.linearScanOrder().toArray(new Block[ir.linearScanOrder().size()]); + this.sortedBlocks = ir.linearScanOrder(); this.registerAttributes = frameMap.registerConfig.getAttributesMap(); this.registers = target.arch.getRegisters(); @@ -313,13 +313,11 @@ // access to block list (sorted in linear scan order) int blockCount() { - assert sortedBlocks.length == ir.linearScanOrder().size() : "invalid cached block list"; - return sortedBlocks.length; + return sortedBlocks.size(); } Block blockAt(int index) { - assert sortedBlocks[index] == ir.linearScanOrder().get(index) : "invalid cached block list"; - return sortedBlocks[index]; + return sortedBlocks.get(index); } /** @@ -503,9 +501,7 @@ } LIRInsertionBuffer insertionBuffer = new LIRInsertionBuffer(); - int numBlocks = blockCount(); - for (int i = 0; i < numBlocks; i++) { - Block block = blockAt(i); + for (Block block : sortedBlocks) { List instructions = ir.lir(block); int numInst = instructions.size(); @@ -610,10 +606,9 @@ }; // Assign IDs to LIR nodes and build a mapping, lirOps, from ID to LIRInstruction node. - int numBlocks = blockCount(); int numInstructions = 0; - for (int i = 0; i < numBlocks; i++) { - numInstructions += ir.lir(blockAt(i)).size(); + for (Block block : sortedBlocks) { + numInstructions += ir.lir(block).size(); } // initialize with correct length @@ -622,9 +617,7 @@ int opId = 0; int index = 0; - - for (int i = 0; i < numBlocks; i++) { - Block block = blockAt(i); + for (Block block : sortedBlocks) { blockData.put(block, new BlockData()); List instructions = ir.lir(block); @@ -666,8 +659,7 @@ intervalInLoop = new BitMap2D(operandSize(), numLoops()); // iterate all blocks - for (int i = 0; i < numBlocks; i++) { - final Block block = blockAt(i); + for (final Block block : sortedBlocks) { final BitSet liveGen = new BitSet(liveSize); final BitSet liveKill = new BitSet(liveSize); @@ -847,7 +839,7 @@ } while (changeOccurred); if (GraalOptions.DetailedAsserts) { - verifyLiveness(numBlocks); + verifyLiveness(); } // check that the liveIn set of the first block is empty @@ -881,8 +873,7 @@ Deque definedIn = new ArrayDeque<>(); HashSet usedIn = new HashSet<>(); - for (int j = 0; j < numBlocks; j++) { - Block block = blockAt(j); + for (Block block : sortedBlocks) { if (blockData.get(block).liveGen.get(operandNum)) { usedIn.add(block); TTY.println(" used in block B%d", block.getId()); @@ -932,11 +923,10 @@ } } - private void verifyLiveness(int numBlocks) { + private void verifyLiveness() { // check that fixed intervals are not live at block boundaries // (live set must be empty at fixed intervals) - for (int i = 0; i < numBlocks; i++) { - Block block = blockAt(i); + for (Block block : sortedBlocks) { for (int j = 0; j <= maxRegisterNumber(); j++) { assert !blockData.get(block).liveIn.get(j) : "liveIn set of fixed register must be empty"; assert !blockData.get(block).liveOut.get(j) : "liveOut set of fixed register must be empty"; @@ -1528,9 +1518,7 @@ BitSet blockCompleted = new BitSet(numBlocks); BitSet alreadyResolved = new BitSet(numBlocks); - int i; - for (i = 0; i < numBlocks; i++) { - Block block = blockAt(i); + for (Block block : sortedBlocks) { // check if block has only one predecessor and only one successor if (block.getPredecessorCount() == 1 && block.getSuccessorCount() == 1) { @@ -1561,13 +1549,11 @@ } } - for (i = 0; i < numBlocks; i++) { - if (!blockCompleted.get(i)) { - Block fromBlock = blockAt(i); + for (Block fromBlock : sortedBlocks) { + if (!blockCompleted.get(fromBlock.getLinearScanNumber())) { alreadyResolved.clear(); alreadyResolved.or(blockCompleted); - int numSux = fromBlock.getSuccessorCount(); for (Block toBlock : fromBlock.getSuccessors()) { // check for duplicate edges between the same blocks (can happen with switch blocks) @@ -2019,9 +2005,7 @@ otherIntervals.addRange(Integer.MAX_VALUE - 2, Integer.MAX_VALUE - 1); IntervalWalker iw = new IntervalWalker(this, fixedIntervals, otherIntervals); - for (int i = 0; i < blockCount(); i++) { - Block block = blockAt(i); - + for (Block block : sortedBlocks) { List instructions = ir.lir(block); for (int j = 0; j < instructions.size(); j++) { @@ -2057,10 +2041,7 @@ } void verifyConstants() { - int numBlocks = blockCount(); - - for (int i = 0; i < numBlocks; i++) { - Block block = blockAt(i); + for (Block block : sortedBlocks) { BitSet liveAtEdge = blockData.get(block).liveIn; // visit all operands where the liveAtEdge bit is set