changeset 21326:8cef2c3f389b

LinearScan: encapsulate blockData.
author Josef Eisl <josef.eisl@jku.at>
date Tue, 12 May 2015 11:55:11 +0200
parents e0400193edca
children b8dcf353b822
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/AssignLocations.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LifetimeAnalysis.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java
diffstat 3 files changed, 27 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/AssignLocations.java	Tue May 12 11:17:32 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/AssignLocations.java	Tue May 12 11:55:11 2015 +0200
@@ -76,7 +76,7 @@
                      */
                     LIRInstruction instr = allocator.ir.getLIRforBlock(block).get(allocator.ir.getLIRforBlock(block).size() - 1);
                     if (instr instanceof StandardOp.JumpOp) {
-                        if (allocator.blockData.get(block).liveOut.get(allocator.operandNumber(operand))) {
+                        if (allocator.getBlockData(block).liveOut.get(allocator.operandNumber(operand))) {
                             assert false : String.format(
                                             "can't get split child for the last branch of a block because the information would be incorrect (moves are inserted before the branch in resolveDataFlow) block=%s, instruction=%s, operand=%s",
                                             block, instr, operand);
@@ -119,12 +119,12 @@
              * is a branch, spill moves are inserted before this branch and so the wrong operand
              * would be returned (spill moves at block boundaries are not considered in the live
              * ranges of intervals).
-             *
+             * 
              * Solution: use the first opId of the branch target block instead.
              */
             final LIRInstruction instr = allocator.ir.getLIRforBlock(block).get(allocator.ir.getLIRforBlock(block).size() - 1);
             if (instr instanceof StandardOp.JumpOp) {
-                if (allocator.blockData.get(block).liveOut.get(allocator.operandNumber(operand))) {
+                if (allocator.getBlockData(block).liveOut.get(allocator.operandNumber(operand))) {
                     tempOpId = allocator.getFirstLirInstructionId(block.getSuccessors().iterator().next());
                     mode = OperandMode.DEF;
                 }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LifetimeAnalysis.java	Tue May 12 11:17:32 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LifetimeAnalysis.java	Tue May 12 11:55:11 2015 +0200
@@ -103,7 +103,7 @@
         int opId = 0;
         int index = 0;
         for (AbstractBlockBase<?> block : allocator.sortedBlocks) {
-            allocator.blockData.put(block, new LinearScan.BlockData());
+            allocator.initBlockData(block);
 
             List<LIRInstruction> instructions = allocator.ir.getLIRforBlock(block);
 
@@ -214,7 +214,7 @@
                     }
                 } // end of instruction iteration
 
-                BlockData blockSets = allocator.blockData.get(block);
+                BlockData blockSets = allocator.getBlockData(block);
                 blockSets.liveGen = liveGen;
                 blockSets.liveKill = liveKill;
                 blockSets.liveIn = new BitSet(liveSize);
@@ -278,7 +278,7 @@
                     // iterate all blocks in reverse order
                     for (int i = numBlocks - 1; i >= 0; i--) {
                         AbstractBlockBase<?> block = allocator.blockAt(i);
-                        BlockData blockSets = allocator.blockData.get(block);
+                        BlockData blockSets = allocator.getBlockData(block);
 
                         changeOccurredInBlock = false;
 
@@ -289,7 +289,7 @@
                             // block has successors
                             if (n > 0) {
                                 for (AbstractBlockBase<?> successor : block.getSuccessors()) {
-                                    liveOut.or(allocator.blockData.get(successor).liveIn);
+                                    liveOut.or(allocator.getBlockData(successor).liveIn);
                                 }
                             }
 
@@ -340,12 +340,12 @@
 
             // check that the liveIn set of the first block is empty
             AbstractBlockBase<?> startBlock = allocator.ir.getControlFlowGraph().getStartBlock();
-            if (allocator.blockData.get(startBlock).liveIn.cardinality() != 0) {
+            if (allocator.getBlockData(startBlock).liveIn.cardinality() != 0) {
                 if (DetailedAsserts.getValue()) {
                     reportFailure(numBlocks);
                 }
                 // bailout if this occurs in product mode.
-                throw new GraalInternalError("liveIn set of first block must be empty: " + allocator.blockData.get(startBlock).liveIn);
+                throw new GraalInternalError("liveIn set of first block must be empty: " + allocator.getBlockData(startBlock).liveIn);
             }
         }
     }
@@ -354,7 +354,7 @@
         try (Scope s = Debug.forceLog()) {
             try (Indent indent = Debug.logAndIndent("report failure")) {
 
-                BitSet startBlockLiveIn = allocator.blockData.get(allocator.ir.getControlFlowGraph().getStartBlock()).liveIn;
+                BitSet startBlockLiveIn = allocator.getBlockData(allocator.ir.getControlFlowGraph().getStartBlock()).liveIn;
                 try (Indent indent2 = Debug.logAndIndent("Error: liveIn set of first block must be empty (when this fails, variables are used before they are defined):")) {
                     for (int operandNum = startBlockLiveIn.nextSetBit(0); operandNum >= 0; operandNum = startBlockLiveIn.nextSetBit(operandNum + 1)) {
                         Interval interval = allocator.intervalFor(operandNum);
@@ -381,7 +381,7 @@
                         Deque<AbstractBlockBase<?>> definedIn = new ArrayDeque<>();
                         HashSet<AbstractBlockBase<?>> usedIn = new HashSet<>();
                         for (AbstractBlockBase<?> block : allocator.sortedBlocks) {
-                            if (allocator.blockData.get(block).liveGen.get(operandNum)) {
+                            if (allocator.getBlockData(block).liveGen.get(operandNum)) {
                                 usedIn.add(block);
                                 try (Indent indent3 = Debug.logAndIndent("used in block B%d", block.getId())) {
                                     for (LIRInstruction ins : allocator.ir.getLIRforBlock(block)) {
@@ -394,7 +394,7 @@
                                     }
                                 }
                             }
-                            if (allocator.blockData.get(block).liveKill.get(operandNum)) {
+                            if (allocator.getBlockData(block).liveKill.get(operandNum)) {
                                 definedIn.add(block);
                                 try (Indent indent3 = Debug.logAndIndent("defined in block B%d", block.getId())) {
                                     for (LIRInstruction ins : allocator.ir.getLIRforBlock(block)) {
@@ -441,9 +441,9 @@
          */
         for (AbstractBlockBase<?> block : allocator.sortedBlocks) {
             for (int j = 0; j <= allocator.maxRegisterNumber(); j++) {
-                assert !allocator.blockData.get(block).liveIn.get(j) : "liveIn  set of fixed register must be empty";
-                assert !allocator.blockData.get(block).liveOut.get(j) : "liveOut set of fixed register must be empty";
-                assert !allocator.blockData.get(block).liveGen.get(j) : "liveGen set of fixed register must be empty";
+                assert !allocator.getBlockData(block).liveIn.get(j) : "liveIn  set of fixed register must be empty";
+                assert !allocator.getBlockData(block).liveOut.get(j) : "liveOut set of fixed register must be empty";
+                assert !allocator.getBlockData(block).liveGen.get(j) : "liveGen set of fixed register must be empty";
             }
         }
     }
@@ -643,7 +643,7 @@
                     assert blockTo == instructions.get(instructions.size() - 1).id();
 
                     // Update intervals for operands live at the end of this block;
-                    BitSet live = allocator.blockData.get(block).liveOut;
+                    BitSet live = allocator.getBlockData(block).liveOut;
                     for (int operandNum = live.nextSetBit(0); operandNum >= 0; operandNum = live.nextSetBit(operandNum + 1)) {
                         assert live.get(operandNum) : "should not stop here otherwise";
                         AllocatableValue operand = allocator.intervalFor(operandNum).operand;
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java	Tue May 12 11:17:32 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java	Tue May 12 11:55:11 2015 +0200
@@ -110,7 +110,7 @@
         public BitSet liveKill;
     }
 
-    final BlockMap<BlockData> blockData;
+    private final BlockMap<BlockData> blockData;
 
     /**
      * List of blocks in linear-scan order. This is only correct as long as the CFG does not change.
@@ -233,6 +233,14 @@
         return firstVariableNumber - 1;
     }
 
+    BlockData getBlockData(AbstractBlockBase<?> block) {
+        return blockData.get(block);
+    }
+
+    void initBlockData(AbstractBlockBase<?> block) {
+        blockData.put(block, new BlockData());
+    }
+
     static final IntervalPredicate IS_PRECOLORED_INTERVAL = new IntervalPredicate() {
 
         @Override
@@ -883,12 +891,12 @@
         int toBlockFirstInstructionId = getFirstLirInstructionId(toBlock);
         int fromBlockLastInstructionId = getLastLirInstructionId(fromBlock) + 1;
         int numOperands = operandSize();
-        BitSet liveAtEdge = blockData.get(toBlock).liveIn;
+        BitSet liveAtEdge = getBlockData(toBlock).liveIn;
 
         // visit all variables for which the liveAtEdge bit is set
         for (int operandNum = liveAtEdge.nextSetBit(0); operandNum >= 0; operandNum = liveAtEdge.nextSetBit(operandNum + 1)) {
             assert operandNum < numOperands : "live information set for not exisiting interval";
-            assert blockData.get(fromBlock).liveOut.get(operandNum) && blockData.get(toBlock).liveIn.get(operandNum) : "interval not live at this edge";
+            assert getBlockData(fromBlock).liveOut.get(operandNum) && getBlockData(toBlock).liveIn.get(operandNum) : "interval not live at this edge";
 
             Interval fromInterval = splitChildAtOpId(intervalFor(operandNum), fromBlockLastInstructionId, LIRInstruction.OperandMode.DEF);
             Interval toInterval = splitChildAtOpId(intervalFor(operandNum), toBlockFirstInstructionId, LIRInstruction.OperandMode.DEF);