changeset 19090:d367ad9138f8

LSStackSlotAllocator: clean up comments and sort methods.
author Josef Eisl <josef.eisl@jku.at>
date Sat, 31 Jan 2015 15:05:26 +0100
parents 5b61f60e458f
children 684612ee6abb
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java
diffstat 1 files changed, 52 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java	Sat Jan 31 14:48:27 2015 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java	Sat Jan 31 15:05:26 2015 +0100
@@ -82,7 +82,7 @@
             // insert by to
             this.active = new PriorityQueue<>((a, b) -> a.to() - b.to());
 
-            // number instructions
+            // step 1: number instructions
             this.maxOpId = numberInstructions(lir, sortedBlocks);
         }
 
@@ -90,24 +90,24 @@
             Debug.dump(lir, "After StackSlot numbering");
 
             long currentFrameSize = Debug.isMeterEnabled() ? frameMapBuilder.getFrameMap().currentFrameSize() : 0;
-            // build intervals
+            // step 2: build intervals
             try (Scope s = Debug.scope("StackSlotAllocationBuildIntervals"); Indent indent = Debug.logAndIndent("BuildIntervals")) {
                 buildIntervals();
             }
-            // verify intervals
+            // step 3: verify intervals
             if (Debug.isEnabled()) {
                 verifyIntervals();
             }
             if (Debug.isDumpEnabled()) {
                 dumpIntervals("Before stack slot allocation");
             }
-            // allocate stack slots
+            // step 4: allocate stack slots
             allocateStackSlots();
             if (Debug.isDumpEnabled()) {
                 dumpIntervals("After stack slot allocation");
             }
 
-            // assign stack slots
+            // step 5: assign stack slots
             assignStackSlots();
             Debug.dump(lir, "After StackSlot assignment");
             if (Debug.isMeterEnabled()) {
@@ -115,6 +115,10 @@
             }
         }
 
+        // ====================
+        // step 1: number instructions
+        // ====================
+
         /**
          * Numbers all instructions in all blocks.
          *
@@ -140,20 +144,17 @@
             return opId - 2;
         }
 
-        /**
-         * Gets the highest instruction id allocated by this object.
-         */
-        private int maxOpId() {
-            return maxOpId;
-        }
+        // ====================
+        // step 2: build intervals
+        // ====================
 
         private void buildIntervals() {
             new FixPointIntervalBuilder(lir, stackSlotMap, maxOpId()).build();
         }
 
-        private StackInterval get(VirtualStackSlot stackSlot) {
-            return stackSlotMap[stackSlot.getId()];
-        }
+        // ====================
+        // step 3: verify intervals
+        // ====================
 
         private void verifyIntervals() {
             forEachInterval(interval -> {
@@ -161,27 +162,13 @@
             });
         }
 
-        private void forEachInterval(Consumer<StackInterval> proc) {
-            for (StackInterval interval : stackSlotMap) {
-                if (interval != null) {
-                    proc.accept(interval);
-                }
-            }
-        }
-
-        private void dumpIntervals(String label) {
-            Debug.dump(stackSlotMap, label);
-        }
-
-        private void createUnhandled() {
-
-            // add all intervals to unhandled list
-            forEachInterval(unhandled::add);
-        }
+        // ====================
+        // step 4: allocate stack slots
+        // ====================
 
         private void allocateStackSlots() {
-            // create interval lists
-            createUnhandled();
+            // create unhandled lists
+            forEachInterval(unhandled::add);
 
             for (StackInterval current = activateNext(); current != null; current = activateNext()) {
                 try (Indent indent = Debug.logAndIndent("allocate %s", current)) {
@@ -298,6 +285,10 @@
             freeSlot(location);
         }
 
+        // ====================
+        // step 5: assign stack slots
+        // ====================
+
         private void assignStackSlots() {
             for (AbstractBlock<?> block : sortedBlocks) {
                 lir.getLIRforBlock(block).forEach(op -> {
@@ -326,5 +317,33 @@
             }
             return value;
         }
+
+        // ====================
+        //
+        // ====================
+
+        /**
+         * Gets the highest instruction id allocated by this object.
+         */
+        private int maxOpId() {
+            return maxOpId;
+        }
+
+        private StackInterval get(VirtualStackSlot stackSlot) {
+            return stackSlotMap[stackSlot.getId()];
+        }
+
+        private void forEachInterval(Consumer<StackInterval> proc) {
+            for (StackInterval interval : stackSlotMap) {
+                if (interval != null) {
+                    proc.accept(interval);
+                }
+            }
+        }
+
+        private void dumpIntervals(String label) {
+            Debug.dump(stackSlotMap, label);
+        }
+
     }
 }