# HG changeset patch # User Josef Eisl # Date 1432894134 -7200 # Node ID cc9e15bbbd3cfa3797df28e31c8d8bef5de63c66 # Parent 098cc00fbe93f73ca35bf93ad92002427ce9ea78 SSAMoveResolver: add support for non-virtual stack slots. diff -r 098cc00fbe93 -r cc9e15bbbd3c graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/SSAMoveResolver.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/SSAMoveResolver.java Fri May 29 11:46:51 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/SSAMoveResolver.java Fri May 29 12:08:54 2015 +0200 @@ -29,17 +29,21 @@ import com.oracle.graal.lir.*; import com.oracle.graal.lir.framemap.*; import com.oracle.jvmci.code.*; +import com.oracle.jvmci.common.*; import com.oracle.jvmci.meta.*; final class SSAMoveResolver extends MoveResolver { + private static final int STACK_SLOT_IN_CALLER_FRAME_IDX = -1; private int[] stackBlocked; private final int firstVirtualStackIndex; SSAMoveResolver(LinearScan allocator) { super(allocator); - this.stackBlocked = new int[((FrameMapBuilderTool) allocator.frameMapBuilder).getNumberOfStackSlots()]; - this.firstVirtualStackIndex = 0; + FrameMapBuilderTool frameMapBuilderTool = (FrameMapBuilderTool) allocator.frameMapBuilder; + FrameMap frameMap = frameMapBuilderTool.getFrameMap(); + this.stackBlocked = new int[frameMapBuilderTool.getNumberOfStackSlots()]; + this.firstVirtualStackIndex = !frameMap.frameNeedsAllocating() ? 0 : frameMap.currentFrameSize() + 1; } @Override @@ -76,18 +80,47 @@ return false; } + private int getStackArrayIndex(StackSlotValue stackSlotValue) { + if (isStackSlot(stackSlotValue)) { + return getStackArrayIndex(asStackSlot(stackSlotValue)); + } + if (isVirtualStackSlot(stackSlotValue)) { + return getStackArrayIndex(asVirtualStackSlot(stackSlotValue)); + } + throw JVMCIError.shouldNotReachHere("Unhandled StackSlotValue: " + stackSlotValue); + } + + private int getStackArrayIndex(StackSlot stackSlot) { + int stackIdx; + if (stackSlot.isInCallerFrame()) { + // incoming stack arguments can be ignored + stackIdx = STACK_SLOT_IN_CALLER_FRAME_IDX; + } else { + assert stackSlot.getRawAddFrameSize() : "Unexpected stack slot: " + stackSlot; + int offset = -stackSlot.getRawOffset(); + assert 0 <= offset && offset < firstVirtualStackIndex : String.format("Wrong stack slot offset: %d (first virtual stack slot index: %d", offset, firstVirtualStackIndex); + stackIdx = offset; + } + return stackIdx; + } + + private int getStackArrayIndex(VirtualStackSlot virtualStackSlot) { + return firstVirtualStackIndex + virtualStackSlot.getId(); + } + @Override protected void setValueBlocked(Value location, int direction) { assert direction == 1 || direction == -1 : "out of bounds"; - if (isVirtualStackSlot(location)) { - int stackIdx = getStackArrayIndex(asVirtualStackSlot(location)); + if (isStackSlotValue(location)) { + int stackIdx = getStackArrayIndex(asStackSlotValue(location)); + if (stackIdx == STACK_SLOT_IN_CALLER_FRAME_IDX) { + // incoming stack arguments can be ignored + return; + } if (stackIdx >= stackBlocked.length) { stackBlocked = Arrays.copyOf(stackBlocked, stackIdx + 1); } stackBlocked[stackIdx] += direction; - } else if (isStackSlot(location)) { - assert asStackSlot(location).isInCallerFrame() : "Unexpected stack slot: " + location; - // incoming stack arguments can be ignored } else { super.setValueBlocked(location, direction); } @@ -95,25 +128,20 @@ @Override protected int valueBlocked(Value location) { - if (isVirtualStackSlot(location)) { - int stackIdx = getStackArrayIndex(asVirtualStackSlot(location)); + if (isStackSlotValue(location)) { + int stackIdx = getStackArrayIndex(asStackSlotValue(location)); + if (stackIdx == STACK_SLOT_IN_CALLER_FRAME_IDX) { + // incoming stack arguments are always blocked (aka they can not be written) + return 1; + } if (stackIdx >= stackBlocked.length) { return 0; } return stackBlocked[stackIdx]; } - if (isStackSlot(location)) { - assert asStackSlot(location).isInCallerFrame() : "Unexpected stack slot: " + location; - // incoming stack arguments are always blocked (aka they can not be written) - return 1; - } return super.valueBlocked(location); } - private int getStackArrayIndex(VirtualStackSlot virtualStackSlot) { - return firstVirtualStackIndex + virtualStackSlot.getId(); - } - @Override protected LIRInstruction createMove(AllocatableValue fromOpr, AllocatableValue toOpr, AllocatableValue fromLocation, AllocatableValue toLocation) { if (isStackSlotValue(toLocation) && isStackSlotValue(fromLocation)) {