changeset 19079:613a2b7f88c3

InstructionNumberer: make opIdToInstructionMap and opIdToBlockMap final.
author Josef Eisl <josef.eisl@jku.at>
date Sat, 31 Jan 2015 11:01:26 +0100
parents 5447a27a6fd7
children e22286559a8b
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/InstructionNumberer.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java
diffstat 2 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/InstructionNumberer.java	Fri Jan 30 15:39:59 2015 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/InstructionNumberer.java	Sat Jan 31 11:01:26 2015 +0100
@@ -31,12 +31,24 @@
 
 public class InstructionNumberer {
 
-    private LIRInstruction[] opIdToInstructionMap;
-    private AbstractBlock<?>[] opIdToBlockMap;
+    private final LIRInstruction[] opIdToInstructionMap;
+    private final AbstractBlock<?>[] opIdToBlockMap;
+
+    protected InstructionNumberer(LIR lir) {
+        // Assign IDs to LIR nodes and build a mapping, lirOps, from ID to LIRInstruction node.
+        int numInstructions = 0;
+        for (AbstractBlock<?> block : lir.getControlFlowGraph().getBlocks()) {
+            numInstructions += lir.getLIRforBlock(block).size();
+        }
+
+        // initialize with correct length
+        opIdToInstructionMap = new LIRInstruction[numInstructions];
+        opIdToBlockMap = new AbstractBlock<?>[numInstructions];
+    }
 
     /**
      * Converts an {@linkplain LIRInstruction#id instruction id} to an instruction index. All LIR
-     * instructions in a method have an index one greater than their linear-scan order predecesor
+     * instructions in a method have an index one greater than their linear-scan order predecessor
      * with the first instruction having an index of 0.
      */
     private static int opIdToIndex(int opId) {
@@ -61,16 +73,6 @@
      */
     protected void numberInstructions(LIR lir, List<? extends AbstractBlock<?>> sortedBlocks) {
 
-        // Assign IDs to LIR nodes and build a mapping, lirOps, from ID to LIRInstruction node.
-        int numInstructions = 0;
-        for (AbstractBlock<?> block : sortedBlocks) {
-            numInstructions += lir.getLIRforBlock(block).size();
-        }
-
-        // initialize with correct length
-        opIdToInstructionMap = new LIRInstruction[numInstructions];
-        opIdToBlockMap = new AbstractBlock<?>[numInstructions];
-
         int opId = 0;
         int index = 0;
         for (AbstractBlock<?> block : sortedBlocks) {
@@ -90,8 +92,9 @@
                 opId += 2; // numbering of lirOps by two
             }
         }
-        assert index == numInstructions : "must match";
+        assert index == opIdToBlockMap.length : "must match";
         assert (index << 1) == opId : "must match: " + (index << 1);
+        assert opId - 2 == maxOpId() : "must match";
     }
 
     /**
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java	Fri Jan 30 15:39:59 2015 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java	Sat Jan 31 11:01:26 2015 +0100
@@ -77,6 +77,7 @@
         private List<? extends AbstractBlock<?>> sortedBlocks;
 
         private Allocator(LIR lir, FrameMapBuilderTool frameMapBuilder) {
+            super(lir);
             this.lir = lir;
             this.frameMapBuilder = frameMapBuilder;
             this.stackSlotMap = new StackInterval[frameMapBuilder.getNumberOfStackSlots()];