# HG changeset patch # User Josef Eisl # Date 1432811161 -7200 # Node ID c0f9aa6dc4cd1d2e312517bb90344cab3f528460 # Parent 47a3d4b3ccb345f81fcf3ac44148ae61fa14d7b4 Introduce StackStoreOp. diff -r 47a3d4b3ccb3 -r c0f9aa6dc4cd graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Wed May 27 16:26:10 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu May 28 13:06:01 2015 +0200 @@ -22,23 +22,6 @@ */ package com.oracle.graal.hotspot.amd64; -import com.oracle.jvmci.code.RegisterValue; -import com.oracle.jvmci.code.Register; -import com.oracle.jvmci.code.RegisterConfig; -import com.oracle.jvmci.code.ForeignCallLinkage; -import com.oracle.jvmci.code.CallingConvention; -import com.oracle.jvmci.code.VirtualStackSlot; -import com.oracle.jvmci.code.StackSlotValue; -import com.oracle.jvmci.code.StackSlot; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.LIRKind; -import com.oracle.jvmci.meta.JavaConstant; -import com.oracle.jvmci.meta.DeoptimizationAction; -import com.oracle.jvmci.meta.PlatformKind; -import com.oracle.jvmci.meta.DeoptimizationReason; -import com.oracle.jvmci.meta.PrimitiveConstant; -import com.oracle.jvmci.meta.AllocatableValue; -import com.oracle.jvmci.meta.Kind; import static com.oracle.graal.amd64.AMD64.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.*; import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp.*; @@ -54,6 +37,7 @@ import com.oracle.graal.compiler.common.*; import com.oracle.graal.compiler.common.spi.*; import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.amd64.AMD64HotSpotMove.StoreRbpOp; import com.oracle.graal.hotspot.debug.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.hotspot.stubs.*; @@ -66,10 +50,12 @@ import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.framemap.*; import com.oracle.graal.lir.gen.*; +import com.oracle.jvmci.code.*; import com.oracle.jvmci.common.*; import com.oracle.jvmci.debug.*; import com.oracle.jvmci.hotspot.*; import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; +import com.oracle.jvmci.meta.*; /** * LIR generator specialized for AMD64 HotSpot. @@ -99,8 +85,7 @@ */ class SaveRbp { - private final NoOp placeholder0; - private final NoOp placeholder1; + private final NoOp placeholder; /** * The slot reserved for saving RBP. @@ -113,9 +98,8 @@ */ private final AllocatableValue rescueSlot; - public SaveRbp(NoOp placeholder0, NoOp placeholder1) { - this.placeholder0 = placeholder0; - this.placeholder1 = placeholder1; + public SaveRbp(NoOp placeholder0) { + this.placeholder = placeholder0; AMD64FrameMapBuilder frameMapBuilder = (AMD64FrameMapBuilder) getResult().getFrameMapBuilder(); this.reservedSlot = frameMapBuilder.allocateRBPSpillSlot(); this.rescueSlot = newVariable(LIRKind.value(Kind.Long)); @@ -125,21 +109,17 @@ * Replaces this operation with the appropriate move for saving rbp. * * @param useStack specifies if rbp must be saved to the stack - * @return true if an instruction has been remove (i.e. replace by {@code null}). */ - public boolean finalize(boolean useStack) { - // move to variable - placeholder0.replace(getResult().getLIR(), new MoveFromRegOp(Kind.Long, rescueSlot, rbp.asValue(LIRKind.value(Kind.Long)))); - // move to stack - MoveFromRegOp moveToStack; + public void finalize(boolean useStack) { + RegisterValue rbpValue = rbp.asValue(LIRKind.value(Kind.Long)); + LIRInstruction move; if (useStack) { - moveToStack = new MoveFromRegOp(Kind.Long, reservedSlot, rescueSlot); + move = new StoreRbpOp(rescueSlot, rbpValue, reservedSlot); } else { ((AMD64FrameMapBuilder) getResult().getFrameMapBuilder()).freeRBPSpillSlot(); - moveToStack = null; + move = new MoveFromRegOp(Kind.Long, rescueSlot, rbpValue); } - placeholder1.replace(getResult().getLIR(), moveToStack); - return moveToStack == null; + placeholder.replace(getResult().getLIR(), move); } @@ -151,11 +131,9 @@ private SaveRbp saveRbp; protected void emitSaveRbp() { - NoOp placeholder0 = new NoOp(getCurrentBlock(), getResult().getLIR().getLIRforBlock(getCurrentBlock()).size()); - append(placeholder0); - NoOp placeholder1 = new NoOp(getCurrentBlock(), getResult().getLIR().getLIRforBlock(getCurrentBlock()).size()); - append(placeholder1); - saveRbp = new SaveRbp(placeholder0, placeholder1); + NoOp placeholder = new NoOp(getCurrentBlock(), getResult().getLIR().getLIRforBlock(getCurrentBlock()).size()); + append(placeholder); + saveRbp = new SaveRbp(placeholder); } protected SaveRbp getSaveRbp() { @@ -501,7 +479,7 @@ public void beforeRegisterAllocation() { super.beforeRegisterAllocation(); boolean hasDebugInfo = getResult().getLIR().hasDebugInfo(); - boolean removedInstruction = saveRbp.finalize(hasDebugInfo); + saveRbp.finalize(hasDebugInfo); if (hasDebugInfo) { ((AMD64HotSpotLIRGenerationResult) getResult()).setDeoptimizationRescueSlot(((AMD64FrameMapBuilder) getResult().getFrameMapBuilder()).allocateDeoptimizationRescueSlot()); } @@ -515,12 +493,6 @@ instructions.add(1, op); Debug.dump(lir, "created rescue dummy op"); } - if (removedInstruction) { - // remove null from instruction list - LIR lir = getResult().getLIR(); - List instructions = lir.getLIRforBlock(lir.getControlFlowGraph().getStartBlock()); - instructions.remove(null); - } } public void emitPushInterpreterFrame(Value frameSize, Value framePc, Value senderSp, Value initialInfo) { diff -r 47a3d4b3ccb3 -r c0f9aa6dc4cd graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java Wed May 27 16:26:10 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java Thu May 28 13:06:01 2015 +0200 @@ -22,13 +22,8 @@ */ package com.oracle.graal.hotspot.amd64; -import com.oracle.jvmci.code.Register; -import com.oracle.jvmci.meta.Value; -import com.oracle.jvmci.meta.JavaConstant; -import com.oracle.jvmci.meta.AllocatableValue; -import com.oracle.jvmci.meta.Kind; +import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import static com.oracle.jvmci.code.ValueUtil.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; @@ -37,11 +32,14 @@ import com.oracle.graal.hotspot.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.MoveOp; +import com.oracle.graal.lir.StandardOp.StackStoreOp; import com.oracle.graal.lir.amd64.*; import com.oracle.graal.lir.asm.*; +import com.oracle.jvmci.code.*; import com.oracle.jvmci.common.*; import com.oracle.jvmci.hotspot.*; import com.oracle.jvmci.hotspot.HotSpotVMConfig.CompressEncoding; +import com.oracle.jvmci.meta.*; public class AMD64HotSpotMove { @@ -187,6 +185,43 @@ } } + public static final class StoreRbpOp extends AMD64LIRInstruction implements StackStoreOp { + public static final LIRInstructionClass TYPE = LIRInstructionClass.create(StoreRbpOp.class); + + @Def({REG, HINT}) protected AllocatableValue result; + @Use({REG}) protected AllocatableValue input; + @Def({STACK}) protected StackSlotValue stackSlot; + + protected StoreRbpOp(AllocatableValue result, AllocatableValue input, StackSlotValue stackSlot) { + super(TYPE); + assert result.getLIRKind().equals(input.getLIRKind()) && stackSlot.getLIRKind().equals(input.getLIRKind()) : String.format("result %s, input %s, stackSlot %s", result.getLIRKind(), + input.getLIRKind(), stackSlot.getLIRKind()); + this.result = result; + this.input = input; + this.stackSlot = stackSlot; + } + + public Value getInput() { + return input; + } + + public AllocatableValue getResult() { + return result; + } + + public StackSlotValue getStackSlot() { + return stackSlot; + } + + @Override + public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { + assert result.getPlatformKind() instanceof Kind : "Can only deal with Kind: " + result.getLIRKind(); + Kind kind = (Kind) result.getPlatformKind(); + AMD64Move.move(kind, crb, masm, result, input); + AMD64Move.move(kind, crb, masm, stackSlot, input); + } + } + public static final class UncompressPointer extends AMD64LIRInstruction { public static final LIRInstructionClass TYPE = LIRInstructionClass.create(UncompressPointer.class); diff -r 47a3d4b3ccb3 -r c0f9aa6dc4cd graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Wed May 27 16:26:10 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Thu May 28 13:06:01 2015 +0200 @@ -227,6 +227,19 @@ } /** + * An operation that takes one input and stores it in a stack slot as well as on an ordinary + * variable. + */ + public interface StackStoreOp { + + Value getInput(); + + AllocatableValue getResult(); + + StackSlotValue getStackSlot(); + } + + /** * A LIR operation that does nothing. If the operation records its position, it can be * subsequently {@linkplain #replace(LIR, LIRInstruction) replaced}. */