changeset 21597:c0f9aa6dc4cd

Introduce StackStoreOp.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 28 May 2015 13:06:01 +0200
parents 47a3d4b3ccb3
children 05ecef0a6a24
files graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java
diffstat 3 files changed, 70 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- 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<LIRInstruction> instructions = lir.getLIRforBlock(lir.getControlFlowGraph().getStartBlock());
-            instructions.remove(null);
-        }
     }
 
     public void emitPushInterpreterFrame(Value frameSize, Value framePc, Value senderSp, Value initialInfo) {
--- 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<StoreRbpOp> 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<UncompressPointer> TYPE = LIRInstructionClass.create(UncompressPointer.class);
 
--- 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}.
      */