changeset 14931:d45e8c306349

use MemOp as base class for new memory ops
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 01 Apr 2014 15:41:28 -0700
parents 5c7718ae8c86
children 8ce9a950fbe2
files graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Compare.java graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64TestMemoryOp.java
diffstat 5 files changed, 81 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Tue Apr 01 22:48:07 2014 +0200
+++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Tue Apr 01 15:41:28 2014 -0700
@@ -336,40 +336,42 @@
         }
     }
 
-    protected void emitCompareMemoryConOp(Kind kind, AMD64AddressValue left, Value right, LIRFrameState state) {
-        assert kind == right.getKind();
+    protected void emitCompareMemoryConOp(Kind kind, AMD64AddressValue address, Value value, LIRFrameState state) {
+        assert kind == value.getKind();
         switch (kind) {
             case Int:
-                append(new CompareMemoryOp(ICMP, left, right, state));
+                append(new CompareMemoryOp(ICMP, kind, address, value, state));
                 break;
             case Long:
-                append(new CompareMemoryOp(LCMP, left, right, state));
+                append(new CompareMemoryOp(LCMP, kind, address, value, state));
                 break;
             default:
                 throw GraalInternalError.shouldNotReachHere();
         }
     }
 
-    protected void emitCompareRegMemoryOp(Kind kind, Value left, AMD64AddressValue right, LIRFrameState state) {
+    protected void emitCompareRegMemoryOp(Kind kind, Value value, AMD64AddressValue address, LIRFrameState state) {
+        AMD64Compare opcode = null;
         switch (kind) {
             case Int:
-                append(new CompareMemoryOp(ICMP, left, right, state));
+                opcode = ICMP;
                 break;
             case Long:
-                append(new CompareMemoryOp(LCMP, left, right, state));
+                opcode = LCMP;
                 break;
             case Object:
-                append(new CompareMemoryOp(ACMP, left, right, state));
+                opcode = ACMP;
                 break;
             case Float:
-                append(new CompareMemoryOp(FCMP, left, right, state));
+                opcode = FCMP;
                 break;
             case Double:
-                append(new CompareMemoryOp(DCMP, left, right, state));
+                opcode = DCMP;
                 break;
             default:
                 throw GraalInternalError.shouldNotReachHere();
         }
+        append(new CompareMemoryOp(opcode, kind, address, value, state));
     }
 
     /**
@@ -545,7 +547,7 @@
 
     protected Value emitConvert2MemoryOp(PlatformKind kind, AMD64Arithmetic op, AMD64AddressValue address, LIRFrameState state) {
         Variable result = newVariable(kind);
-        append(new Unary2MemoryOp(op, result, address, state));
+        append(new Unary2MemoryOp(op, result, (Kind) null, address, state));
         return result;
     }
 
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java	Tue Apr 01 22:48:07 2014 +0200
+++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java	Tue Apr 01 15:41:28 2014 -0700
@@ -408,10 +408,10 @@
                 return false;
             }
             ensureEvaluated(other);
-            gen.append(new AMD64TestMemoryOp(makeAddress(access), constant, getState(access)));
+            gen.append(new AMD64TestMemoryOp(kind, makeAddress(access), constant, getState(access)));
         } else {
             evaluateDeferred();
-            gen.append(new AMD64TestMemoryOp(makeAddress(access), gen.operand(other), getState(access)));
+            gen.append(new AMD64TestMemoryOp(kind, makeAddress(access), gen.operand(other), getState(access)));
         }
 
         gen.append(new BranchOp(Condition.EQ, trueLabel, falseLabel, trueLabelProbability));
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java	Tue Apr 01 22:48:07 2014 +0200
+++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java	Tue Apr 01 15:41:28 2014 -0700
@@ -32,6 +32,7 @@
 import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.*;
+import com.oracle.graal.lir.amd64.AMD64Move.MemOp;
 import com.oracle.graal.lir.asm.*;
 
 public enum AMD64Arithmetic {
@@ -105,26 +106,20 @@
     /**
      * Unary operation with separate memory source and destination operand.
      */
-    public static class Unary2MemoryOp extends AMD64LIRInstruction {
+    public static class Unary2MemoryOp extends MemOp {
 
         @Opcode private final AMD64Arithmetic opcode;
         @Def({REG}) protected AllocatableValue result;
-        @Use({COMPOSITE}) protected AMD64AddressValue x;
-        @State protected LIRFrameState state;
 
-        public Unary2MemoryOp(AMD64Arithmetic opcode, AllocatableValue result, AMD64AddressValue x, LIRFrameState state) {
+        public Unary2MemoryOp(AMD64Arithmetic opcode, AllocatableValue result, Kind kind, AMD64AddressValue address, LIRFrameState state) {
+            super(kind, address, state);
             this.opcode = opcode;
             this.result = result;
-            this.x = x;
-            this.state = state;
         }
 
         @Override
-        public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
-            if (state != null) {
-                crb.recordImplicitException(masm.position(), state);
-            }
-            emit(crb, masm, opcode, result, x, null);
+        public void emitMemAccess(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
+            emit(crb, masm, opcode, result, address, null);
         }
     }
 
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Compare.java	Tue Apr 01 22:48:07 2014 +0200
+++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Compare.java	Tue Apr 01 15:41:28 2014 -0700
@@ -26,9 +26,11 @@
 import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
 
 import com.oracle.graal.api.meta.*;
+import com.oracle.graal.asm.*;
 import com.oracle.graal.asm.amd64.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.*;
+import com.oracle.graal.lir.amd64.AMD64Move.MemOp;
 import com.oracle.graal.lir.asm.*;
 
 public enum AMD64Compare {
@@ -63,35 +65,63 @@
         }
     }
 
-    public static class CompareMemoryOp extends AMD64LIRInstruction {
+    public static class CompareMemoryOp extends MemOp {
         @Opcode private final AMD64Compare opcode;
-        @Use({REG, COMPOSITE}) protected Value x;
-        @Use({CONST, COMPOSITE}) protected Value y;
-        @State protected LIRFrameState state;
+        @Use({REG, CONST}) protected Value y;
 
         /**
          * Compare memory, constant or register, memory.
          */
-        public CompareMemoryOp(AMD64Compare opcode, Value x, Value y, LIRFrameState state) {
-            assert (x instanceof AMD64AddressValue && y instanceof Constant) || (x instanceof Variable && y instanceof AMD64AddressValue);
+        public CompareMemoryOp(AMD64Compare opcode, Kind kind, AMD64AddressValue address, Value y, LIRFrameState state) {
+            super(kind, address, state);
             this.opcode = opcode;
-            this.x = x;
             this.y = y;
-            this.state = state;
         }
 
         @Override
-        public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
-            if (state != null) {
-                crb.recordImplicitException(masm.position(), state);
+        public void emitMemAccess(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
+            if (isRegister(y)) {
+                switch (opcode) {
+                    case ICMP:
+                        masm.cmpl(asIntReg(y), address.toAddress());
+                        break;
+                    case LCMP:
+                        masm.cmpq(asLongReg(y), address.toAddress());
+                        break;
+                    case ACMP:
+                        masm.cmpptr(asObjectReg(y), address.toAddress());
+                        break;
+                    case FCMP:
+                        masm.ucomiss(asFloatReg(y), address.toAddress());
+                        break;
+                    case DCMP:
+                        masm.ucomisd(asDoubleReg(y), address.toAddress());
+                        break;
+                    default:
+                        throw GraalInternalError.shouldNotReachHere();
+                }
+            } else if (isConstant(y)) {
+                switch (opcode) {
+                    case ICMP:
+                        masm.cmpl(address.toAddress(), crb.asIntConst(y));
+                        break;
+                    case LCMP:
+                        if (NumUtil.isInt(crb.asLongConst(y))) {
+                            masm.cmpq(address.toAddress(), (int) crb.asLongConst(y));
+                        } else {
+                            throw GraalInternalError.shouldNotReachHere();
+                        }
+                        break;
+                    default:
+                        throw GraalInternalError.shouldNotReachHere();
+                }
             }
-            emit(crb, masm, opcode, x, y);
         }
 
         @Override
         protected void verify() {
             super.verify();
-            assert (x instanceof AMD64AddressValue && y instanceof Constant) || (x instanceof Variable && y instanceof AMD64AddressValue);
+            assert y instanceof Variable || y instanceof Constant;
         }
     }
 
@@ -169,41 +199,8 @@
                 default:
                     throw GraalInternalError.shouldNotReachHere();
             }
-        } else if (isRegister(x) && y instanceof AMD64AddressValue) {
-            switch (opcode) {
-                case ICMP:
-                    masm.cmpl(asIntReg(x), ((AMD64AddressValue) y).toAddress());
-                    break;
-                case LCMP:
-                    masm.cmpq(asLongReg(x), ((AMD64AddressValue) y).toAddress());
-                    break;
-                case ACMP:
-                    masm.cmpptr(asObjectReg(x), ((AMD64AddressValue) y).toAddress());
-                    break;
-                case FCMP:
-                    masm.ucomiss(asFloatReg(x), ((AMD64AddressValue) y).toAddress());
-                    break;
-                case DCMP:
-                    masm.ucomisd(asDoubleReg(x), ((AMD64AddressValue) y).toAddress());
-                    break;
-                default:
-                    throw GraalInternalError.shouldNotReachHere();
-            }
-        } else if (x instanceof AMD64AddressValue && isConstant(y)) {
-            switch (opcode) {
-                case ICMP:
-                    masm.cmpl(((AMD64AddressValue) x).toAddress(), crb.asIntConst(y));
-                    break;
-                case LCMP:
-                    if (crb.asLongConst(y) == (int) crb.asLongConst(y)) {
-                        masm.cmpq(((AMD64AddressValue) x).toAddress(), (int) crb.asLongConst(y));
-                    } else {
-                        throw GraalInternalError.shouldNotReachHere();
-                    }
-                    break;
-                default:
-                    throw GraalInternalError.shouldNotReachHere();
-            }
+        } else {
+            throw GraalInternalError.shouldNotReachHere();
         }
     }
 }
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64TestMemoryOp.java	Tue Apr 01 22:48:07 2014 +0200
+++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64TestMemoryOp.java	Tue Apr 01 15:41:28 2014 -0700
@@ -29,43 +29,28 @@
 import com.oracle.graal.asm.amd64.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.*;
+import com.oracle.graal.lir.amd64.AMD64Move.MemOp;
 import com.oracle.graal.lir.asm.*;
 
-public class AMD64TestMemoryOp extends AMD64LIRInstruction {
+public class AMD64TestMemoryOp extends MemOp {
 
-    @Use({COMPOSITE}) protected AMD64AddressValue x;
     @Use({REG, CONST}) protected Value y;
-    @State protected LIRFrameState state;
 
-    public AMD64TestMemoryOp(AMD64AddressValue x, Value y, LIRFrameState state) {
-        this.x = x;
+    public AMD64TestMemoryOp(Kind kind, AMD64AddressValue x, Value y, LIRFrameState state) {
+        super(kind, x, state);
         this.y = y;
         this.state = state;
     }
 
     @Override
-    public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
-        if (state != null) {
-            crb.recordImplicitException(masm.position(), state);
-        }
-        emit(crb, masm, x, y);
-    }
-
-    @Override
-    protected void verify() {
-        super.verify();
-        // Can't check the kind of an address so just check the other input
-        assert (x.getKind() == Kind.Int || x.getKind() == Kind.Long) : x + " " + y;
-    }
-
-    public static void emit(CompilationResultBuilder crb, AMD64MacroAssembler masm, Value x, Value y) {
+    public void emitMemAccess(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
         if (isRegister(y)) {
             switch (y.getKind()) {
                 case Int:
-                    masm.testl(asIntReg(y), ((AMD64AddressValue) x).toAddress());
+                    masm.testl(asIntReg(y), address.toAddress());
                     break;
                 case Long:
-                    masm.testq(asLongReg(y), ((AMD64AddressValue) x).toAddress());
+                    masm.testq(asLongReg(y), address.toAddress());
                     break;
                 default:
                     throw GraalInternalError.shouldNotReachHere();
@@ -73,10 +58,10 @@
         } else if (isConstant(y)) {
             switch (y.getKind()) {
                 case Int:
-                    masm.testl(((AMD64AddressValue) x).toAddress(), crb.asIntConst(y));
+                    masm.testl(address.toAddress(), crb.asIntConst(y));
                     break;
                 case Long:
-                    masm.testq(((AMD64AddressValue) x).toAddress(), crb.asIntConst(y));
+                    masm.testq(address.toAddress(), crb.asIntConst(y));
                     break;
                 default:
                     throw GraalInternalError.shouldNotReachHere();
@@ -85,4 +70,10 @@
             throw GraalInternalError.shouldNotReachHere();
         }
     }
+
+    @Override
+    protected void verify() {
+        super.verify();
+        assert (kind == Kind.Int || kind == Kind.Long) && kind == y.getKind() : address + " " + y;
+    }
 }