# HG changeset patch # User Josef Eisl # Date 1423045886 -3600 # Node ID 0f3c0639dc3f9679360ad3844600944507cfbb1b # Parent d4b0e2e9b9456c393414c708ba8a0f24f3e9764a LSStackSlotAllocator: record use positions globally. diff -r d4b0e2e9b945 -r 0f3c0639dc3f graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/FixPointIntervalBuilder.java --- 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 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 build() { Deque> 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()); } diff -r d4b0e2e9b945 -r 0f3c0639dc3f graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java --- 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 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 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 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); } }