changeset 19123:0f3c0639dc3f

LSStackSlotAllocator: record use positions globally.
author Josef Eisl <josef.eisl@jku.at>
date Wed, 04 Feb 2015 11:31:26 +0100
parents d4b0e2e9b945
children a5f47cb74b1b
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/FixPointIntervalBuilder.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java
diffstat 2 files changed, 24 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/FixPointIntervalBuilder.java	Tue Feb 03 13:46:33 2015 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/FixPointIntervalBuilder.java	Wed Feb 04 11:31:26 2015 +0100
@@ -43,6 +43,7 @@
     private final LIR lir;
     private final int maxOpId;
     private final StackInterval[] stackSlotMap;
+    private final HashSet<Integer> usePos;
 
     /**
      * The number of allocated stack slots.
@@ -55,9 +56,15 @@
         this.maxOpId = maxOpId;
         liveInMap = new BlockMap<>(lir.getControlFlowGraph());
         liveOutMap = new BlockMap<>(lir.getControlFlowGraph());
+        this.usePos = new HashSet<>();
     }
 
-    void build() {
+    /**
+     * Builds the lifetime intervals for {@link VirtualStackSlot virtual stack slots}, sets up
+     * {@link #stackSlotMap} and returns a set of use positions, i.e. ids for instructions that
+     * contain virtual stack slots.
+     */
+    Set<Integer> build() {
         Deque<AbstractBlock<?>> worklist = new ArrayDeque<>();
         for (int i = lir.getControlFlowGraph().getBlocks().size() - 1; i >= 0; i--) {
             worklist.add(lir.getControlFlowGraph().getBlocks().get(i));
@@ -69,6 +76,7 @@
             AbstractBlock<?> block = worklist.poll();
             processBlock(block, worklist);
         }
+        return usePos;
     }
 
     /**
@@ -188,6 +196,7 @@
             if (isVirtualStackSlot(operand)) {
                 VirtualStackSlot vslot = asVirtualStackSlot(operand);
                 addUse(vslot, inst, flags);
+                usePos.add(inst.id());
                 Debug.log("set operand: %s", operand);
                 currentSet.set(vslot.getId());
             }
@@ -206,6 +215,7 @@
             if (isVirtualStackSlot(operand)) {
                 VirtualStackSlot vslot = asVirtualStackSlot(operand);
                 addDef(vslot, inst);
+                usePos.add(inst.id());
                 Debug.log("clear operand: %s", operand);
                 currentSet.clear(vslot.getId());
             }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java	Tue Feb 03 13:46:33 2015 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java	Wed Feb 04 11:31:26 2015 +0100
@@ -102,9 +102,10 @@
             Debug.dump(lir, "After StackSlot numbering");
 
             long currentFrameSize = Debug.isMeterEnabled() ? frameMapBuilder.getFrameMap().currentFrameSize() : 0;
+            Set<Integer> usePos;
             // step 2: build intervals
             try (Scope s = Debug.scope("StackSlotAllocationBuildIntervals"); Indent indent = Debug.logAndIndent("BuildIntervals"); TimerCloseable t = BuildIntervalsTimer.start()) {
-                buildIntervals();
+                usePos = buildIntervals();
             }
             // step 3: verify intervals
             if (Debug.isEnabled()) {
@@ -125,7 +126,7 @@
 
             // step 5: assign stack slots
             try (TimerCloseable t = AssignSlotsTimer.start()) {
-                assignStackSlots();
+                assignStackSlots(usePos);
             }
             Debug.dump(lir, "After StackSlot assignment");
             if (Debug.isMeterEnabled()) {
@@ -137,8 +138,8 @@
         // step 2: build intervals
         // ====================
 
-        private void buildIntervals() {
-            new FixPointIntervalBuilder(lir, stackSlotMap, maxOpId()).build();
+        private Set<Integer> buildIntervals() {
+            return new FixPointIntervalBuilder(lir, stackSlotMap, maxOpId()).build();
         }
 
         // ====================
@@ -324,16 +325,15 @@
         // step 5: assign stack slots
         // ====================
 
-        private void assignStackSlots() {
-            for (AbstractBlock<?> block : sortedBlocks) {
-                lir.getLIRforBlock(block).forEach(op -> {
-                    op.forEachInput(this::assignSlot);
-                    op.forEachAlive(this::assignSlot);
-                    op.forEachState(this::assignSlot);
+        private void assignStackSlots(Set<Integer> usePos) {
+            for (int opId : usePos) {
+                LIRInstruction op = instructionForId(opId);
+                op.forEachInput(this::assignSlot);
+                op.forEachAlive(this::assignSlot);
+                op.forEachState(this::assignSlot);
 
-                    op.forEachTemp(this::assignSlot);
-                    op.forEachOutput(this::assignSlot);
-                });
+                op.forEachTemp(this::assignSlot);
+                op.forEachOutput(this::assignSlot);
             }
         }